source: Daodan/MSVC/Flatline_Server.c@ 567

Last change on this file since 567 was 567, checked in by gumby, 15 years ago

Daodan MSVC

File size: 2.3 KB
Line 
1#include "Flatline.h"
2#include "Flatline_Server.h"
3
4int total_players = 0;
5uint16_t max_connections = MAX_CONNECTIONS;
6
7player_info* FLrServer_AddPlayer(int ip, char* name, bool is_server) {
8 flatline_packet new_char = {0};
9 CharacterObject* Char;
10 uint32_t player_slot = 0;
11 int playerlist_slot = 0;
12 if(is_server) goto server;
13 if(total_players < max_connections) {
14 char* zero = strchr(name, 0);
15 int i = 0;
16 int k = 0;
17 playerlist_slot = FLr_FindEmptyListSlot();
18
19
20 total_players++;
21
22 //send new player packet to all players
23 //char tempname[32] = {0};
24
25 //checks to see if a name exists or not
26 //then appends [#] on the end of it if it does
27
28 if(zero - name > 28) zero = name + 28;
29 for(i = 0; i < max_connections; i++) {
30 if(PlayerList[i] != 0 && !strcmp(name, PlayerList[i]->name)) {
31 k++;
32 sprintf(zero, "[%i]", k);
33 i = 0;
34 }
35 }
36
37server: ;
38 //memset( new_char, 0, sizeof(new_char);
39 //new_char = {0};
40 Char = &new_char.new_player.Character;
41 memset(Char, 0, sizeof(CharacterObject));
42 Char->Header.Type = 'CHAR';
43 //Char->OSD.Options = char_dontaim;
44 sprintf(Char->OSD.Name,"%s",name);
45 sprintf(Char->OSD.Class, "%s", "konoko_generic");
46
47
48
49 //TMrInstance_GetDataPtr('ONCC', "striker_easy_1", PlayerList[playerlist_slot]->Chr->ONCC);
50
51
52 new_char.id = NEW_PLAYER;
53 if(!is_server) {
54 ONrGameState_NewCharacter(Char, NULL, NULL, &(player_slot));
55 PlayerList[playerlist_slot] = Players+player_slot;
56 PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot];
57 PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF
58 sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name);
59 UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER );
60
61 }
62 else {
63 PlayerList[0] = Players;
64 PlayerList[0]->Chr = (Character *)(((GameState * )(ONgGameState))->CharacterStorage);
65 }
66
67 //add player to list
68
69 PlayerList[playerlist_slot]->ip = ip;
70 PlayerList[playerlist_slot]->list_slot = playerlist_slot;
71 sprintf(PlayerList[playerlist_slot]->name,"%.31s",name);
72
73 return &Players[player_slot];
74 }
75 return (player_info*)(-1);
76}
77
78void FLrServer_Initialize(){
79 FLrServer_AddPlayer(inet_addr("127.0.0.1"), "host", 1);
80
81
82}
Note: See TracBrowser for help on using the repository browser.