ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/MSVC/Flatline_Server.c
(Generate patch)

Comparing Daodan/MSVC/Flatline_Server.c (file contents):
Revision 574 by gumby, Mon Oct 11 08:22:59 2010 UTC vs.
Revision 578 by gumby, Wed Jan 12 18:47:16 2011 UTC

# Line 1 | Line 1
1   #include "Flatline.h"
2   #include "Flatline_Server.h"
3  
4 + //I hereby apologize for the uglyness of the below code.
5 + //It was never intended to be "final" code, much less shared with anyone
6 +
7   int total_players = 0;
8   uint16_t max_connections = MAX_CONNECTIONS;
9  
# Line 9 | Line 12 | player_info* FLrServer_AddPlayer(int ip,
12          CharacterObject* Char;
13          uint32_t player_slot = 0;
14          int playerlist_slot = 0;
15 <        if(is_server) goto server;
16 <        if(total_players < max_connections) {
17 <                char* zero = strchr(name, 0);
15 >        
16 >        if(is_server || total_players < max_connections) {
17 >                
18                  int i = 0;
19                  int k = 0;
17                playerlist_slot = FLr_FindEmptyListSlot();
18                
20  
21 <                total_players++;
21 >                //Skip for the host
22 >                if(!is_server)
23 >                {
24 >                        char* zero = strchr(name, 0);
25 >                        playerlist_slot = FLr_FindEmptyListSlot();
26  
27 <                //send new player packet to all players
23 <                //char tempname[32] = {0};
27 >                        total_players++;
28  
29 <                //checks to see if a name exists or not
30 <                //then appends [#] on the end of it if it does
31 <                
32 <                if(zero - name > 28) zero = name + 28;
33 <                for(i = 0; i < max_connections; i++) {
34 <                        if(PlayerList[i] != 0 && !strcmp(name, PlayerList[i]->name)) {
35 <                                k++;                            
36 <                                sprintf(zero, "[%i]", k);
37 <                                i = 0;
29 >                        //checks to see if a name exists or not
30 >                        //then appends [#] on the end of it if it does
31 >                        //May be buggy, come back to this.
32 >                        if(zero - name > 28) zero = name + 28;
33 >                        for(i = 0; i < max_connections; i++) {
34 >                                if(PlayerList[i] != 0 && !strcmp(name, PlayerList[i]->name)) {
35 >                                        k++;                            
36 >                                        sprintf(zero, "[%i]", k);
37 >                                        i = 0;
38 >                                }
39                          }
40                  }
41 <
37 < server:         ;
38 <                //memset( new_char, 0, sizeof(new_char);
39 <                //new_char = {0};
41 >                
42                  new_char.new_player.Playernumber = playerlist_slot;
43 +
44 +                //Set up a new Character structure to be spawned as the new player.
45 +                //Can this code be surrounded with if(!is_server){}?
46                  Char = &new_char.new_player.Character;
47                  memset(Char, 0, sizeof(CharacterObject));
48                  Char->Header.Type = 'CHAR';
44                //Char->OSD.Options = char_dontaim;
49                  sprintf(Char->OSD.Name,"%s",name);
50                  sprintf(Char->OSD.Class, "%s", "konoko_generic");
51                  if(is_bot) {
# Line 60 | Line 64 | server:                ;
64                  }
65                  
66                  //TMrInstance_GetDataPtr('ONCC', "striker_easy_1", PlayerList[playerlist_slot]->Chr->ONCC);
63                
67  
68                  new_char.id = NEW_PLAYER;
69                  if(!is_server) {
# Line 70 | Line 73 | server:                ;
73  
74                          PlayerList[playerlist_slot] = Players+player_slot;
75                          PlayerList[playerlist_slot]->spawnnumber = player_slot;
76 <                        PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot];
77 < //                      PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF
78 <                        if(!is_bot) PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF
76 >                        PlayerList[playerlist_slot]->Chr = &(ONgGameState->CharacterStorage)[player_slot];
77 >                        //PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF
78 >                        if(!is_bot) PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF, magic number.
79                          sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name);        
80                          UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER );
81                          
# Line 120 | Line 123 | int UDPServer_SendToAll(void* packet, in
123          return players;
124   }
125  
126 + //Sends an event (door opening, player disconnecting, etc) to all players
127   //Always make sure you send a pointer to this, even if it is just one arg. ;)
128   void FLsPublic_Event( unsigned int eventIndex, int * args )
129   {
# Line 131 | Line 135 | void FLsPublic_Event( unsigned int event
135          UDPServer_SendToAll( &eventPacket, sizeof(int) * (numArgs + 1) + FLATLINE_HEADER );
136   }
137  
138 + void PlayerDisconnect( int Player )
139 + {
140 +        FLsPublic_Event(EV_DISCONNECT, &Player );
141 +        memset(PlayerList[Player], 0, sizeof(player_info));
142 +        return;
143 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)