Changeset 580
- Timestamp:
- Jan 14, 2011, 8:39:14 AM (14 years ago)
- Location:
- Daodan/MSVC
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Daodan/MSVC/Flatline.c
r579 r580 9 9 player_info Players[MAX_PLAYERS] = {{0}, {0}, {0}, {0}}; 10 10 player_info * PlayerList[MAX_CONNECTIONS] = {0}; 11 12 unsigned int lastPingTime; 13 11 14 const char * Rejection_Messages[][255] = { 12 15 {"Server is full"}, … … 24 27 25 28 if (Player > max_connections || !PlayerList[ Player ] ) return; 26 27 28 // DDrConsole_PrintF( "Sending sync data for player %i, new index %u", Player, PlayerList[ Player ]->rare_sync_index);29 30 31 // DDrConsole_PrintF( "Sending sync data for player %i, new index %u", Player, PlayerList[ Player ]->rare_sync_index); 29 32 sender->sin_addr.S_un.S_addr = htonl(sender->sin_addr.S_un.S_addr); 30 33 sync.id = RARE_SYNC_DATA; … … 51 54 sender.sin_port = htons(27777); 52 55 sender.sin_addr = *((struct in_addr*)(int*)&from); 53 56 54 57 55 58 //packet->data[datalen] = '\0'; 56 59 57 60 //DDrConsole_PrintF("Packet \r%d recieved from %i", ++recieved, from); 58 61 59 60 62 63 61 64 //if data[0] != CONNECT_SEND, search in playerlist for ip address 62 63 64 65 65 66 67 68 66 69 switch(packet->id) { 67 70 flatline_packet connect_recv; … … 70 73 //rewrite this before we get TCP support* 71 74 //the way of seeing if there is room for players sucks. 72 case CONNECT_SEND: 73 ; 74 75 connect_recv.id = CONNECT_REPLY; 76 77 //if(Players[i].ip == sender.sin_addr.S_un.S_addr) break; //needs to send an error message 75 case CONNECT_SEND: 76 ; 77 78 connect_recv.id = CONNECT_REPLY; 79 80 //if(Players[i].ip == sender.sin_addr.S_un.S_addr) break; //needs to send an error message 81 sender.sin_addr.S_un.S_addr = htonl(sender.sin_addr.S_un.S_addr); 82 playah = FLrServer_AddPlayer(from,packet->connect_send.name, 0, 0); 83 DDrConsole_PrintF("%s connected from %s", packet->connect_send.name, inet_ntoa(sender.sin_addr ) ); 84 if(!((int)playah > -5 && (int)playah <= 0)) { 85 flatline_packet new_char = {0}; 86 CharacterObject* Char; 87 connect_recv.connect_reply.goodtogo = 1; 88 connect_recv.connect_reply.player_slot = playah->list_slot; 89 DDrConsole_PrintF("Slot: %i", playah->list_slot); 90 91 //sending this several times to make sure it gets through. Really need to make up some form of packet tracking. 92 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 93 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 94 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 95 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 96 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 97 Sleep(100); 98 99 new_char.id = NEW_PLAYER; 100 Char = &new_char.new_player.Character; 101 memset(Char, 0, sizeof(CharacterObject)); 102 Char->Header.Type = 'CHAR'; 103 Char->OSD.Options = chr_dontaim; 104 for(j = 0; j < max_connections; j++) { 105 if(PlayerList[j] != 0) { 106 new_char.new_player.Playernumber = j; 107 sprintf(Char->OSD.Name,"%s",PlayerList[j]->name); 108 109 sprintf(Char->OSD.Class, "%s", TMrInstance_GetInstanceName(PlayerList[j]->Chr->ONCC)); 110 DDrConsole_PrintF("Class %s", Char->OSD.Class ); 111 112 sprintf(Char->OSD.Class, "konoko_generic"); 113 NetTCPServer_Send((sockaddr *) &sender, (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER ); 114 } 115 116 } 117 } 118 else { 119 //fix the error messages... 120 DDrConsole_PrintF("Server is full. :("); 121 connect_recv.connect_reply.goodtogo = 0; 78 122 sender.sin_addr.S_un.S_addr = htonl(sender.sin_addr.S_un.S_addr); 79 playah = FLrServer_AddPlayer(from,packet->connect_send.name, 0, 0); 80 DDrConsole_PrintF("%s connected from %s", packet->connect_send.name, inet_ntoa(sender.sin_addr ) ); 81 if(!((int)playah > -5 && (int)playah <= 0)) { 82 flatline_packet new_char = {0}; 83 CharacterObject* Char; 84 connect_recv.connect_reply.goodtogo = 1; 85 connect_recv.connect_reply.player_slot = playah->list_slot; 86 DDrConsole_PrintF("Slot: %i", playah->list_slot); 87 88 //sending this several times to make sure it gets through. Really need to make up some form of packet tracking. 89 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 90 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 91 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 92 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 93 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 94 Sleep(100); 95 96 new_char.id = NEW_PLAYER; 97 Char = &new_char.new_player.Character; 98 memset(Char, 0, sizeof(CharacterObject)); 99 Char->Header.Type = 'CHAR'; 100 Char->OSD.Options = chr_dontaim; 101 for(j = 0; j < max_connections; j++) { 102 if(PlayerList[j] != 0) { 103 new_char.new_player.Playernumber = j; 104 sprintf(Char->OSD.Name,"%s",PlayerList[j]->name); 105 106 sprintf(Char->OSD.Class, "%s", TMrInstance_GetInstanceName(PlayerList[j]->Chr->ONCC)); 107 DDrConsole_PrintF("Class %s", Char->OSD.Class ); 108 109 sprintf(Char->OSD.Class, "konoko_generic"); 110 NetTCPServer_Send((sockaddr *) &sender, (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER ); 111 } 112 113 } 114 } 115 else { 116 //fix the error messages... 117 DDrConsole_PrintF("Server is full. :("); 118 connect_recv.connect_reply.goodtogo = 0; 119 sender.sin_addr.S_un.S_addr = htonl(sender.sin_addr.S_un.S_addr); 120 memcpy(&connect_recv.connect_reply.message,"Server is full.", sizeof("Server is full.")); 121 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(bool)*2 + FLATLINE_HEADER + sizeof("Server is full.")); 122 123 } 124 125 123 memcpy(&connect_recv.connect_reply.message,"Server is full.", sizeof("Server is full.")); 124 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(bool)*2 + FLATLINE_HEADER + sizeof("Server is full.")); 125 126 } 127 128 129 break; 130 case CONNECT_REPLY: 131 break; //do nothing...a server shouldn't recieve this type of packet. 132 case MESSAGE: 133 for(i = 0; i < MAX_PLAYERS; i++) { 134 //DDrConsole_PrintF("%i : %i | %s : %s", from, Players[i].ip, inet_ntoa(*(struct in_addr*)&from), inet_ntoa(*(struct in_addr*)&(Players[i].ip))); 135 if(Players[i].ip == sender.sin_addr.S_un.S_addr) { 136 found_player = 1; 137 break; 138 } 139 } 140 if(found_player == 0) return true; 141 else { 142 char message_buffer[512] = {0}; 143 flatline_packet message; 144 int message_size; 145 data[datalen] = 0; 146 147 DDrConsole_PrintF("%s: %s", Players[i].name, packet->data); 148 sprintf(message_buffer, "%s: %s", Players[i].name, packet->data); 149 150 message.id = MESSAGE; 151 message_size = sprintf(message.data, "%s", message_buffer); 152 COrMessage_Print(message_buffer, "chat", 0); 153 UDPServer_SendToAll(&message, message_size + 1 + FLATLINE_HEADER); 126 154 break; 127 case CONNECT_REPLY: 128 break; //do nothing...a server shouldn't recieve this type of packet. 129 case MESSAGE: 130 for(i = 0; i < MAX_PLAYERS; i++) { 131 //DDrConsole_PrintF("%i : %i | %s : %s", from, Players[i].ip, inet_ntoa(*(struct in_addr*)&from), inet_ntoa(*(struct in_addr*)&(Players[i].ip))); 132 if(Players[i].ip == sender.sin_addr.S_un.S_addr) { 133 found_player = 1; 155 } 156 case CHANGE_NAME: 157 ; //wtf, needed or i get an error. 158 DDrConsole_PrintF("Changing Name to: %s", packet->data); 159 for(i = 0; i < MAX_PLAYERS; i++) { 160 if(Players[i].ip == sender.sin_addr.S_un.S_addr) { 161 found_player = 1; 162 break; 163 } 164 } 165 if(found_player == 0) return true; 166 else { 167 bool name_exists = 0; 168 for(j = 0; j < MAX_PLAYERS; j++) { 169 if(!strcmp(packet->data, Players[j].name)) { 170 name_exists = 1; 134 171 break; 135 } 136 } 137 if( found_player == 0) return true;138 else {139 char message_buffer[512] = {0};140 flatline_packet message;141 int message_size;142 data[datalen] = 0; 143 144 DDrConsole_PrintF("%s: %s", Players[i].name, packet->data);145 sprintf(message_buffer, "%s: %s", Players[i].name, packet->data);146 147 message.id = MESSAGE; 148 message_size = sprintf(message.data, "%s", message_buffer);149 COrMessage_Print(message_buffer, "chat", 0);150 UDPServer_SendToAll(&message, message_size + 1 + FLATLINE_HEADER);172 } 173 } 174 if(!name_exists) { 175 char message_buffer[1024]; 176 sprintf(message_buffer,"%s changed their name to %s", Players[i].name, packet->data); 177 COrMessage_Print(message_buffer, "name_change", 0); 178 memcpy(Players[i].name, packet->data, 256); 179 180 } 181 break; 182 } 183 case PLAYER_INPUT: 184 185 for(i = 0; i < max_connections; i++) { 186 if(PlayerList[i] != 0 && PlayerList[i]->ip == sender.sin_addr.S_un.S_addr) { 187 found_player = 1; 151 188 break; 152 } 153 case CHANGE_NAME: 154 ; //wtf, needed or i get an error. 155 DDrConsole_PrintF("Changing Name to: %s", packet->data); 156 for(i = 0; i < MAX_PLAYERS; i++) { 157 if(Players[i].ip == sender.sin_addr.S_un.S_addr) { 158 found_player = 1; 159 break; 160 } 161 } 162 if(found_player == 0) return true; 163 else { 164 bool name_exists = 0; 165 for(j = 0; j < MAX_PLAYERS; j++) { 166 if(!strcmp(packet->data, Players[j].name)) { 167 name_exists = 1; 168 break; 169 } 170 } 171 if(!name_exists) { 172 char message_buffer[1024]; 173 sprintf(message_buffer,"%s changed their name to %s", Players[i].name, packet->data); 174 COrMessage_Print(message_buffer, "name_change", 0); 175 memcpy(Players[i].name, packet->data, 256); 176 177 } 189 } 190 } 191 192 if(found_player == 0) return true; 193 else { 194 input_struct * packet_input = &packet->input_struct; 195 196 197 PlayerList[i]->Actions1 = packet_input->Actions1; 198 PlayerList[i]->Actions2 = packet_input->Actions2; 199 PlayerList[i]->MouseDeltaX = packet_input->MouseDeltaX; 200 PlayerList[i]->MouseDeltaY = packet_input->MouseDeltaY; 201 PlayerList[i]->LastInputTime = packet_input->Time; 202 203 break; 204 } 205 case RARE_SYNC_DATA_REQUEST: 206 DoRareSync( packet->sync_request , &sender); 207 break; 208 case PK_PONG: 209 for(i = 0; i < max_connections; i++) { 210 if(PlayerList[i] != 0 && PlayerList[i]->ip == sender.sin_addr.S_un.S_addr) { 211 found_player = 1; 178 212 break; 179 } 180 case PLAYER_INPUT: 181 182 for(i = 0; i < max_connections; i++) { 183 if(PlayerList[i] != 0 && PlayerList[i]->ip == sender.sin_addr.S_un.S_addr) { 184 found_player = 1; 185 break; 186 } 187 } 188 189 if(found_player == 0) return true; 190 else { 191 input_struct * packet_input = &packet->input_struct; 192 193 194 PlayerList[i]->Actions1 = packet_input->Actions1; 195 PlayerList[i]->Actions2 = packet_input->Actions2; 196 PlayerList[i]->MouseDeltaX = packet_input->MouseDeltaX; 197 PlayerList[i]->MouseDeltaY = packet_input->MouseDeltaY; 198 PlayerList[i]->LastInputTime = packet_input->Time; 199 200 break; 201 } 202 case RARE_SYNC_DATA_REQUEST: 203 DoRareSync( packet->sync_request , &sender); 204 break; 205 default: 206 DDrConsole_PrintF("Warning, recieved badly formed packet!"); 207 break; 213 } 214 } 215 216 if(found_player == 0) return true; 217 if(packet->ping != lastPingTime) 218 { 219 PlayerList[i]->Ping = 999; 220 } 221 else 222 { 223 PlayerList[i]->Ping = (ONgGameState->GameTime - packet->ping) * 1000 / 60; 224 } 225 break; 226 default: 227 DDrConsole_PrintF("Warning, recieved badly formed packet!"); 228 break; 208 229 } 209 230 return true; … … 214 235 // Get the local hostname 215 236 char szHostName[255]; 216 237 struct hostent *host_entry; 217 238 gethostname(szHostName, 255); 218 239 … … 228 249 229 250 void ONrCharacter_SetAnimationInternal(Character* Char, ActiveCharacter* AChar, 230 251 short inFromState, short inNextAnimType, const void *TRAM) 231 252 { 232 253 ONCC *ONCC = Char->ONCC; … … 236 257 237 258 if (TRAM == 0) return; 238 259 239 260 animType = TRrAnimation_GetType(TRAM); 240 261 241 262 AChar->Animation = TRAM; 242 263 AChar->Frame = 0; 243 264 AChar->AnimationFromState = inFromState; 244 265 AChar->AnimationType = animType; 245 266 246 267 AChar->NextAnimationType= inNextAnimType; 247 268 AChar->AnimationToState = TRrAnimation_GetTo(TRAM); … … 251 272 252 273 253 254 255 256 274 RGBA green = {0, 0xFF, 0, 0}; 275 RGBA red = {0, 0, 0xFF, 0}; 276 RGBA grey = {0x80,0x80,0x80,0x80}; 277 257 278 //FLrClient_Run 258 279 //Looping function that waits for packets from the server. … … 267 288 int sent_bytes; 268 289 client_connected = 0; 269 290 270 291 271 292 //starts the connection … … 289 310 290 311 DDrConsole_PrintColored("Connection successful!",0,green, grey); 291 312 292 313 //disable local input. 293 314 DDrPatch_NOOP(0x004FA929, 5 + 6 + 5); 294 315 295 316 //DDrConsole_PrintF("Slot %i", ((connect_reply*)packet)->player_slot); 296 317 break; … … 316 337 ActiveCharacter * Active; 317 338 flatline_packet packet; 318 //#define SPAM_INPUT339 //#define SPAM_INPUT 319 340 #ifdef SPAM_INPUT 320 341 struct timeval lasttime; … … 325 346 #ifdef SPAM_INPUT 326 347 gettimeofday(&thistime, 0); 327 348 328 349 //DDrConsole_PrintF("%i.%i | %i.%i | %i.%i",lasttime.tv_sec, lasttime.tv_usec, thistime.tv_sec, thistime.tv_usec, 329 350 // thistime.tv_sec - lasttime.tv_sec, thistime.tv_usec - lasttime.tv_usec); … … 332 353 ((thistime.tv_sec > lasttime.tv_sec) && ((thistime.tv_usec + 1000000 - lasttime.tv_usec ) > update_rate * 1000) ) 333 354 || ((thistime.tv_sec == lasttime.tv_sec) && ((thistime.tv_usec - lasttime.tv_usec ) > update_rate * 1000)) 334 ) {335 336 flatline_packet input_packet;337 lasttime.tv_usec = ++thistime.tv_usec; //in case recieving packets takes less than 1 ms.338 339 input_packet.id = PLAYER_INPUT;340 341 if( ((GameState*)(ONgGameState))->Input.Current.Actions1 != last1 || ((GameState*)(ONgGameState))->Input.Current.Actions2 != last2) {342 last1 =((GameState*)(ONgGameState))->Input.Current.Actions1;343 last2 =((GameState*)(ONgGameState))->Input.Current.Actions2;344 }345 346 ((input_struct*)(void*)(input_packet.data))->Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1;347 ((input_struct*)(void*)(input_packet.data))->Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2;348 ((input_struct*)(void*)(input_packet.data))->MouseDeltaX = ((GameState*)(ONgGameState))->Input.MouseDeltaX;349 ((input_struct*)(void*)(input_packet.data))->MouseDeltaY = ((GameState*)(ONgGameState))->Input.MouseDeltaY;350 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&input_packet, sizeof(input_struct) + FLATLINE_HEADER);351 //if(sent_bytes == SOCKET_ERROR) NetCatchError();355 ) { 356 357 flatline_packet input_packet; 358 lasttime.tv_usec = ++thistime.tv_usec; //in case recieving packets takes less than 1 ms. 359 360 input_packet.id = PLAYER_INPUT; 361 362 if( ((GameState*)(ONgGameState))->Input.Current.Actions1 != last1 || ((GameState*)(ONgGameState))->Input.Current.Actions2 != last2) { 363 last1 =((GameState*)(ONgGameState))->Input.Current.Actions1; 364 last2 =((GameState*)(ONgGameState))->Input.Current.Actions2; 365 } 366 367 ((input_struct*)(void*)(input_packet.data))->Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1; 368 ((input_struct*)(void*)(input_packet.data))->Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2; 369 ((input_struct*)(void*)(input_packet.data))->MouseDeltaX = ((GameState*)(ONgGameState))->Input.MouseDeltaX; 370 ((input_struct*)(void*)(input_packet.data))->MouseDeltaY = ((GameState*)(ONgGameState))->Input.MouseDeltaY; 371 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&input_packet, sizeof(input_struct) + FLATLINE_HEADER); 372 //if(sent_bytes == SOCKET_ERROR) NetCatchError(); 352 373 } 353 374 #endif … … 356 377 //DDrConsole_PrintF("Data recieved, length %i, type %i", len, ((flatline_packet*)data)->id); 357 378 switch(packet.id) { 358 case MESSAGE: 359 COrMessage_Print(packet.data, "chat", 0); 360 break; 361 case CONNECT_SEND: 362 ;if(1) { 363 flatline_packet connect_recv; 364 memcpy(&connect_recv.connect_reply.message,"This isn't a server!", sizeof("This isn't a server!")); 365 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&connect_recv, sizeof(bool) + FLATLINE_HEADER + sizeof("This isn't a server!")); 366 } 367 case CONNECT_REPLY: 368 break; //extra packet or something. 369 case NEW_PLAYER: 370 ;if(1) { //haxhaxhax 371 CharacterObject* Char = &(packet.new_player.Character); 372 uint32_t chr_index = 0; 373 Character* PC; 374 DDrConsole_PrintF("%i | %i", packet.new_player.Playernumber ,client_slot); 375 //Char->OSD.Options = 0; 376 if(packet.new_player.Playernumber == client_slot) { 377 PlayerList[packet.new_player.Playernumber] = &Players[0]; 378 PC = (ONgGameState->PlayerCharacter); 379 Players[0].Chr = PC; 380 381 } 382 else { 383 ONrGameState_NewCharacter(Char, NULL, NULL, &chr_index); 384 ONgGameState->CharacterStorage[chr_index].charType = 0; 385 PlayerList[packet.new_player.Playernumber] = &Players[chr_index]; 386 Players[chr_index].Chr = &(ONgGameState->CharacterStorage[chr_index]); 387 Players[chr_index].Chr->Flags &= 0xFFBFFFFF; 388 Players[chr_index].spawnnumber = chr_index; 389 DDrConsole_PrintF("Spawning player %s, class %s, slot %i", ((new_player*)(packet.data))->Character.OSD.Name, ((new_player*)(packet.data))->Character.OSD.Class,chr_index) ; 390 } 391 //Players[((new_player*)(packet.data))->Playernumber].spawnnumber = ONrGameState_NewCharacter(&(((new_player*)(packet.data))->Character), NULL, NULL, 0); 392 break; 393 } 394 case PLAYER_DATA: 395 if(1) { //haxhaxhax 396 player_data* pd = &packet.player_data; 397 uint16_t i = pd->PlayerNum; 398 GameInput * Active_Input; 399 pd = (void*)packet.data; 400 401 //DDrConsole_PrintF("Got data for Player %i, %x", i, PlayerList[i]); 402 if (i > max_connections) break; 403 if( !PlayerList[i] ) break; 404 //PlayerList[i]->Chr = ((GameState *)ONgGameState)->CharacterStorage; 405 406 PlayerList[i]->Actions1 = pd->Inputs.Actions1; 407 PlayerList[i]->Actions2 = pd->Inputs.Actions2; 408 PlayerList[i]->MouseDeltaX = pd->Inputs.MouseDeltaX; 409 PlayerList[i]->MouseDeltaY = pd->Inputs.MouseDeltaY; 410 memcpy( &(PlayerList[i]->player_data), pd, sizeof(player_data) ); 411 412 if( !server_started && pd->rare_sync_index > PlayerList[i]->rare_sync_index ) 413 { 414 int sent_bytes; 415 flatline_packet sync_request = {0}; 416 sync_request.id = RARE_SYNC_DATA_REQUEST; 417 sync_request.sync_request = i; 418 DDrConsole_PrintF( "Requesting sync data for player %i, old index %u", i, PlayerList[i]->rare_sync_index); 419 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&sync_request, FLATLINE_HEADER + sizeof(int) ); 420 } 421 422 423 424 425 break; 426 } 427 case RARE_SYNC_DATA: 428 if(1) { 429 sl_arg hax[2]; 430 int dontuse; 431 uint16_t i = packet.rare_sync_data.PlayerNum; 432 433 if (i > max_connections) break; 434 if( !PlayerList[i] ) break; 435 436 //WEAPONS ARE DISABLED. Why? Pain in the arse to sync. 437 packet.rare_sync_data.Inventory.Weapons[0] = NULL; 438 packet.rare_sync_data.Inventory.Weapons[1] = NULL; 439 packet.rare_sync_data.Inventory.Weapons[2] = NULL; 440 // TMrInstance_GetDataPtr( 'ONCC', packet.rare_sync_data.Class, PlayerList[ i ]->Chr->ONCC ); 441 442 //add the target character 443 hax[0].type = sl_int32; 444 hax[0].value_int32 = PlayerList[ packet.rare_sync_data.PlayerNum ]->spawnnumber; 445 446 //add the new class 447 //fix this later so we cant buffer overflow :O 448 hax[1].type = sl_str32; 449 hax[1].value_str32 = packet.rare_sync_data.Class; 450 451 //we are directly calling a bsl function instead of using the normal method for two reasons 452 //1. it has all the checking built in 453 iSetCharacterClass( 0, 2, hax, &dontuse, &dontuse, hax ); 454 //DDrConsole_PrintF( "Recieved sync data for player %i, class %s, old index %u, new index %u", i, packet.rare_sync_data.Class, PlayerList[i]->rare_sync_index, packet.rare_sync_data.index); 455 memcpy( &(PlayerList[ i ]->Chr->Inventory), &(packet.rare_sync_data.Inventory), sizeof(Inventory )); 456 457 PlayerList[i]->rare_sync_index = packet.rare_sync_data.index; 458 } 459 break; 460 case FLATLINE_EVENT: 461 FLcEventHandler( packet.flatline_event.event_index, packet.flatline_event.intArray ); 462 break; 463 default: 464 DDrConsole_PrintF("Warning, recieved badly formed packet!"); 465 break; 379 case MESSAGE: 380 COrMessage_Print(packet.data, "chat", 0); 381 break; 382 case CONNECT_SEND: 383 ;if(1) { 384 flatline_packet connect_recv; 385 memcpy(&connect_recv.connect_reply.message,"This isn't a server!", sizeof("This isn't a server!")); 386 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&connect_recv, sizeof(bool) + FLATLINE_HEADER + sizeof("This isn't a server!")); 387 } 388 case CONNECT_REPLY: 389 break; //extra packet or something. 390 case NEW_PLAYER: 391 ;if(1) { //haxhaxhax 392 CharacterObject* Char = &(packet.new_player.Character); 393 uint32_t chr_index = 0; 394 Character* PC; 395 DDrConsole_PrintF("%i | %i", packet.new_player.Playernumber ,client_slot); 396 //Char->OSD.Options = 0; 397 if(packet.new_player.Playernumber == client_slot) { 398 PlayerList[packet.new_player.Playernumber] = &Players[0]; 399 PC = (ONgGameState->PlayerCharacter); 400 Players[0].Chr = PC; 401 402 } 403 else { 404 ONrGameState_NewCharacter(Char, NULL, NULL, &chr_index); 405 ONgGameState->CharacterStorage[chr_index].charType = 0; 406 PlayerList[packet.new_player.Playernumber] = &Players[chr_index]; 407 Players[chr_index].Chr = &(ONgGameState->CharacterStorage[chr_index]); 408 Players[chr_index].Chr->Flags &= 0xFFBFFFFF; 409 Players[chr_index].spawnnumber = chr_index; 410 DDrConsole_PrintF("Spawning player %s, class %s, slot %i", ((new_player*)(packet.data))->Character.OSD.Name, ((new_player*)(packet.data))->Character.OSD.Class,chr_index) ; 411 } 412 //Players[((new_player*)(packet.data))->Playernumber].spawnnumber = ONrGameState_NewCharacter(&(((new_player*)(packet.data))->Character), NULL, NULL, 0); 413 break; 414 } 415 case PLAYER_DATA: 416 if(1) { //haxhaxhax 417 player_data* pd = &packet.player_data; 418 uint16_t i = pd->PlayerNum; 419 GameInput * Active_Input; 420 pd = (void*)packet.data; 421 422 //DDrConsole_PrintF("Got data for Player %i, %x", i, PlayerList[i]); 423 if (i > max_connections) break; 424 if( !PlayerList[i] ) break; 425 //PlayerList[i]->Chr = ((GameState *)ONgGameState)->CharacterStorage; 426 427 PlayerList[i]->Actions1 = pd->Inputs.Actions1; 428 PlayerList[i]->Actions2 = pd->Inputs.Actions2; 429 PlayerList[i]->MouseDeltaX = pd->Inputs.MouseDeltaX; 430 PlayerList[i]->MouseDeltaY = pd->Inputs.MouseDeltaY; 431 memcpy( &(PlayerList[i]->player_data), pd, sizeof(player_data) ); 432 433 if( !server_started && pd->rare_sync_index > PlayerList[i]->rare_sync_index ) 434 { 435 int sent_bytes; 436 flatline_packet sync_request = {0}; 437 sync_request.id = RARE_SYNC_DATA_REQUEST; 438 sync_request.sync_request = i; 439 DDrConsole_PrintF( "Requesting sync data for player %i, old index %u", i, PlayerList[i]->rare_sync_index); 440 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&sync_request, FLATLINE_HEADER + sizeof(int) ); 441 } 442 443 PlayerList[i]->DataApplied = 0; 444 445 446 break; 447 } 448 case RARE_SYNC_DATA: 449 if(1) { 450 sl_arg hax[2]; 451 int dontuse; 452 uint16_t i = packet.rare_sync_data.PlayerNum; 453 454 if (i > max_connections) break; 455 if( !PlayerList[i] ) break; 456 457 //WEAPONS ARE DISABLED. Why? Pain in the arse to sync. 458 packet.rare_sync_data.Inventory.Weapons[0] = NULL; 459 packet.rare_sync_data.Inventory.Weapons[1] = NULL; 460 packet.rare_sync_data.Inventory.Weapons[2] = NULL; 461 // TMrInstance_GetDataPtr( 'ONCC', packet.rare_sync_data.Class, PlayerList[ i ]->Chr->ONCC ); 462 463 //add the target character 464 hax[0].type = sl_int32; 465 hax[0].value_int32 = PlayerList[ packet.rare_sync_data.PlayerNum ]->spawnnumber; 466 467 //add the new class 468 //fix this later so we cant buffer overflow :O 469 hax[1].type = sl_str32; 470 hax[1].value_str32 = packet.rare_sync_data.Class; 471 472 //we are directly calling a bsl function instead of using the normal method for two reasons 473 //1. it has all the checking built in 474 iSetCharacterClass( 0, 2, hax, &dontuse, &dontuse, hax ); 475 //DDrConsole_PrintF( "Recieved sync data for player %i, class %s, old index %u, new index %u", i, packet.rare_sync_data.Class, PlayerList[i]->rare_sync_index, packet.rare_sync_data.index); 476 memcpy( &(PlayerList[ i ]->Chr->Inventory), &(packet.rare_sync_data.Inventory), sizeof(Inventory )); 477 478 PlayerList[i]->rare_sync_index = packet.rare_sync_data.index; 479 } 480 break; 481 case FLATLINE_EVENT: 482 FLcEventHandler( packet.flatline_event.event_index, packet.flatline_event.intArray ); 483 break; 484 case PK_PING: 485 packet.id = PK_PONG; 486 487 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&packet, FLATLINE_HEADER + 4); 488 break; 489 default: 490 DDrConsole_PrintF("Warning, recieved badly formed packet!"); 491 break; 466 492 } 467 493 } … … 495 521 return -1; 496 522 } 497 498 499 500 501 502 523 typedef struct 524 { 525 uint16_t x; 526 uint16_t y; 527 528 } IMtPoint2D; 503 529 static flatline_packet cache_input = {0}; 504 530 extern void* TSrTest; … … 522 548 input_packet.input_struct.MouseDeltaX = ((GameState*)(ONgGameState))->Input.MouseDeltaX; 523 549 input_packet.input_struct.MouseDeltaY = ((GameState*)(ONgGameState))->Input.MouseDeltaY; 524 550 525 551 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&input_packet, sizeof(input_struct) + FLATLINE_HEADER); 526 552 527 553 //return ONgGameState; 528 554 } … … 530 556 531 557 if(!(server_started || client_connected)) return ONgGameState; 558 559 if(server_started && ONgGameState->GameTime % 120 == 0) 560 { 561 FLsPingAll(); 562 } 532 563 533 564 for(i = 0; i < max_connections; i++) { … … 536 567 GameInput * Active_Input; 537 568 if(PlayerList[i] == 0) continue; 538 539 569 570 540 571 Player = PlayerList[i]->Chr; 541 572 if( Player->Health == 0) … … 575 606 } 576 607 continue; 577 578 608 609 579 610 } 580 611 581 612 Active_Player = ONrGetActiveCharacter( PlayerList[i]->Chr); 582 613 583 614 if(Active_Player == 0) continue; 584 615 Active_Input = &(Active_Player->Input); … … 587 618 flatline_packet data_out = {0}; 588 619 589 620 if(!strcmp(PlayerList[i]->player_data.Animation, TMrInstance_GetInstanceName(Active_Player->Animation))) 621 continue; 590 622 591 623 data_out.id = PLAYER_DATA; … … 600 632 memcpy(data->Animation, TMrInstance_GetInstanceName(Active_Player->Animation), 31); 601 633 data->Frame = Active_Player->Frame; 602 634 603 635 if(Active_Player->targetThrow) 604 636 { … … 607 639 data->throw_data.throwFrame = ONrGetActiveCharacter(Active_Player->targetThrow)->Frame; 608 640 } 609 610 641 642 611 643 if( PlayerList[i]->OldClass != PlayerList[i]->Chr->ONCC || memcmp( &(PlayerList[i]->Inventory), &(PlayerList[i]->Chr->Inventory), sizeof(Inventory) ) ) 612 644 { … … 616 648 617 649 } 618 650 619 651 data->rare_sync_index = PlayerList[i]->rare_sync_index; 620 652 621 653 622 654 if(i == 0) { … … 632 664 data->Inputs.MouseDeltaY = PlayerList[i]->MouseDeltaY; 633 665 } 666 data->Ping = PlayerList[i]->Ping; 634 667 memcpy( &(PlayerList[i]->player_data), data, sizeof(player_data) ); 635 668 636 669 UDPServer_SendToAll(&data_out, sizeof(player_data) + FLATLINE_HEADER); 637 670 } 638 671 639 672 if( (server_started && i !=0) || (!server_started/* && i != client_slot*/) ) 640 673 { … … 643 676 Active_Input->Start.Actions1 = ~Active_Input->Current.Actions1 & PlayerList[i]->Actions1; 644 677 Active_Input->Start.Actions2 = ~Active_Input->Current.Actions2 & PlayerList[i]->Actions2; 645 678 646 679 Active_Input->Current.Actions1 = PlayerList[i]->Actions1; 647 680 Active_Input->Current.Actions2 = PlayerList[i]->Actions2; … … 656 689 void* Animation; 657 690 player_data* pd = &PlayerList[i]->player_data; 691 692 if(PlayerList[i]->DataApplied) continue; 693 658 694 Player->Health = PlayerList[i]->player_data.Health; 659 695 PlayerList[i]->Chr->MaxHealth = PlayerList[i]->player_data.MaxHealth; … … 668 704 Active_Player->PhyContext->Position = PlayerList[i]->player_data.Position; 669 705 OldAnimation = Active_Player->Animation; 670 706 671 707 if (!(Player->Flags & ONcCharacterFlag_BeingThrown) && 672 708 (pd->Animation != 0)) 673 709 { 674 710 // get a pointer to the animation 675 676 711 712 TMrInstance_GetDataPtr( 677 713 'TRAM', 678 714 pd->Animation, 679 715 &Animation); 680 716 if (Animation != OldAnimation) 681 717 { 682 718 short num_frames; … … 684 720 685 721 // if the character is dead, make sure this animation is appropriate for death 686 /*722 /* 687 723 if (Player->Flags & ONcCharacterFlag_Dead) 688 724 { 689 690 691 692 693 694 695 696 697 698 725 short curToState = TRrAnimation_GetTo(Active_Player->Animation); 726 short newToState = TRrAnimation_GetTo(animation); 727 728 // if we are currently heading towards fallen and the new animation would not 729 // then this is a better animation to run when we are dead 730 if ((ONrAnimState_IsFallen(curToState)) && 731 (!ONrAnimState_IsFallen(newToState))) 732 { 733 updateAnimation = false; 734 } 699 735 } 700 736 */ … … 713 749 { 714 750 // set the characters animation 715 /* ONrCharacter_SetAnimationInternal(Player,716 717 718 719 720 ONrCharacter_NewAnimationHook(Player, Active_Player);*/721 //Player->Flags |= 0x00000010;751 /* ONrCharacter_SetAnimationInternal(Player, 752 Active_Player, 753 Active_Player->AnimationToState, 754 0, 755 Animation); 756 ONrCharacter_NewAnimationHook(Player, Active_Player);*/ 757 //Player->Flags |= 0x00000010; 722 758 ONrCharacter_SetAnimationExternal(Player, TRrAnimation_GetFrom(Animation), Animation, 0); 723 759 } … … 739 775 if (PlayerList[i]->player_data.throw_data.throwName[0] != 0) 740 776 { 741 pd->throw_data.throwing= PlayerList[pd->throw_data.throwing]->spawnnumber;742 if (( pd->throw_data.throwing!= Active_Player->throwing) &&777 short throwTarget = PlayerList[pd->throw_data.throwing]->spawnnumber; 778 if ((throwTarget != Active_Player->throwing) && 743 779 (pd->throw_data.throwFrame < 10)) 744 780 { … … 754 790 755 791 // set the throw target 756 Active_Player->ThrowTargetCharacter = &ONgGameState->CharacterStorage[ pd->throw_data.throwing];792 Active_Player->ThrowTargetCharacter = &ONgGameState->CharacterStorage[throwTarget]; 757 793 Target = ONrGetActiveCharacter(Active_Player->ThrowTargetCharacter); 758 794 if ((Target->Animation != throw_animation) && … … 762 798 // set the throw variables 763 799 Active_Player->targetThrow = throw_animation; 764 Active_Player->throwing = pd->throw_data.throwing;800 Active_Player->throwing = throwTarget; 765 801 766 802 // run the throw 767 803 ONrCharacter_NewAnimationHook(Player, Active_Player); 768 804 769 805 if (Active_Player->ThrowTargetCharacter) 770 806 { … … 775 811 } 776 812 } 813 PlayerList[i]->DataApplied = 1; 777 814 778 815 } … … 791 828 //Kill off the character in another function, please 792 829 //ONrCharacter_SetHitPoints( PlayerList[Player]->Chr, 0); 793 830 794 831 memset(PlayerList[Player], 0, sizeof(player_info)); 795 832 PlayerList[Player] = 0; 796 833 797 834 798 835 … … 832 869 DrawLocation.x += 150; 833 870 TSrContext_DrawText(ScoreboardInstance, "Score", 255, 0, &DrawLocation); 871 DrawLocation.x += 50; 872 TSrContext_DrawText(ScoreboardInstance, "Ping", 255, 0, &DrawLocation); 834 873 for(i = 0; i <MAX_PLAYERS; i++) 835 874 { 836 if(PlayerList[i] == 0 ) continue;875 if(PlayerList[i] == 0 || PlayerList[i]->Chr == 0) continue; 837 876 838 877 DrawLocation.x = 20; 839 878 DrawLocation.y += LineHeight; 840 841 if(PlayerList[i]->Chr ->Health == 0)879 880 if(PlayerList[i]->Chr && PlayerList[i]->Chr->Health == 0) 842 881 { 843 882 TSrContext_SetShade(ScoreboardInstance, red); … … 852 891 sprintf(DrawString, "%i", PlayerList[i]->Chr->Damage); 853 892 TSrContext_DrawText(ScoreboardInstance, DrawString, 255, 0, &DrawLocation); 854 855 } 856 } 857 } 858 } 893 DrawLocation.x += 50; 894 sprintf(DrawString, "%i", PlayerList[i]->player_data.Ping); 895 TSrContext_DrawText(ScoreboardInstance, DrawString, 255, 0, &DrawLocation); 896 } 897 } 898 } 899 } -
Daodan/MSVC/Flatline.h
r579 r580 129 129 int Damage; 130 130 int Deaths; 131 131 uint16_t Ping; 132 132 } player_data; 133 133 … … 162 162 uint16_t sync_request; 163 163 flatline_event flatline_event; 164 uint32_t ping; 164 165 }; 165 166 } flatline_packet; … … 187 188 RARE_SYNC_DATA_REQUEST, 188 189 FLATLINE_EVENT, 190 PK_PING, 191 PK_PONG, 189 192 }; 190 193 … … 228 231 int flags; 229 232 int DeathTime; 233 uint32_t Ping; 234 bool DataApplied; 230 235 } player_info; 231 236 … … 235 240 236 241 void NetCatchError(); 237 #define MAX_PLAYERS 128242 #define MAX_PLAYERS 32 238 243 #define CONNECTION_TIMEOUT 15 239 244 #define MAX_CONNECTIONS 32 … … 246 251 extern player_info Players[]; 247 252 extern player_info * PlayerList[]; 253 248 254 int UDPServer_SendToAll(void* packet, int size); 255 249 256 extern bool client_connected; 250 257 extern bool server_started; 251 258 extern char player_name[]; 259 252 260 void FLrRun_Scores(); 253 261 void FLrPlayerDisconnect( int Player ); 254 262 void FLrPlayerRespawn( int Player ); 255 263 int FLrEvent_GetNumArgs( int eventIndex ); 264 265 extern unsigned int lastPingTime; 256 266 #endif -
Daodan/MSVC/Flatline_BSL.c
r579 r580 32 32 uint16_t ONICALL change_name(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) 33 33 { 34 34 35 35 //should also return your name... 36 36 sprintf(player_name, "%.31s", args[0].value_str32); … … 73 73 { 74 74 if( NetPlatform_Initalize()) { 75 static flatline_packet packet;76 sock = NetUDPSocket_Create(27777);77 address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr(args[0].value_str32 );78 //address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr("192.168.0.1");79 80 packet.id = CONNECT_SEND;81 memcpy(((connect_send*)(packet.data))->country , player_country, 2);82 memcpy(((connect_send*)(packet.data))->name, player_name, 256);83 DDrConsole_PrintF("%s", ((connect_send*)(packet.data))->name);84 CreateThread(NULL, 0, StartClient, &packet, 0, 0);75 static flatline_packet packet; 76 sock = NetUDPSocket_Create(27777); 77 address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr(args[0].value_str32 ); 78 //address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr("192.168.0.1"); 79 80 packet.id = CONNECT_SEND; 81 memcpy(((connect_send*)(packet.data))->country , player_country, 2); 82 memcpy(((connect_send*)(packet.data))->name, player_name, 256); 83 DDrConsole_PrintF("%s", ((connect_send*)(packet.data))->name); 84 CreateThread(NULL, 0, StartClient, &packet, 0, 0); 85 85 86 86 } … … 111 111 PlayerList[j]->name, 112 112 PlayerList[j]->Chr 113 );113 ); 114 114 } 115 115 } … … 130 130 FLrPlayerDisconnect(args[0].value_int32 - 1); 131 131 FLsPublic_Event(EV_DISCONNECT, &args[0].value_int32); 132 return 0; 133 } 134 135 uint16_t ONICALL ping(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) 136 { 137 if(server_started) 138 { 139 FLsPingAll(); 140 } 132 141 return 0; 133 142 } … … 160 169 new_char.id = NEW_PLAYER; 161 170 OBJrObjectType_EnumerateObjects('CHAR',BINACHARCallback, (int)args[0].value_str32); 162 // while(!spawnObject);171 // while(!spawnObject); 163 172 if(spawnObject) 164 173 { … … 179 188 } 180 189 } 181 182 190 191 return 0; 183 192 } 184 193 … … 193 202 } 194 203 } 195 return 0;204 return 0; 196 205 } 197 206 uint16_t ONICALL con(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) … … 201 210 } 202 211 203 204 void SLrFlatline_Initialize() { 205 212 213 void SLrFlatline_Initialize() 214 { 215 206 216 DDrPatch_MakeCall(0x004FA88B, FLrInput_Update_Keys); 207 217 FLrInput_Update_Keys(); … … 217 227 SLrScript_Command_Register_Void("con", "Activates a console", "con:int", con); 218 228 //SLrScript_Command_Register_ReturnType("ai2_spawn","creates and starts an AI from a character object","ai_name:string [force_spawn:string{\"force\"} | ]", sl_void, spawnAI); 219 } 229 SLrScript_Command_Register_Void("ping", "pong!", "", ping); 230 } -
Daodan/MSVC/Flatline_Server.c
r579 r580 126 126 //FLsPublic_Event 127 127 //Sends an event (door opening, player disconnecting, etc) to all players 128 //Always make sure you send a pointer to this, even if it is just one arg. ;) 129 //Returns 0 because mixing C and assembly is stupid. 128 //Always make sure you send a pointer to this, even if it is just one arg. ;). 130 129 //If it is void the double door in State crashes. Probably stack corruption, 131 130 //I'm not sure exactly why. 131 //So we return 0 to stop that. 132 132 int FLsPublic_Event( const unsigned int eventIndex, const int * args ) 133 133 { … … 142 142 } 143 143 144 void FLsPingAll() 145 { 146 flatline_packet ping; 147 ping.id = PK_PING; 148 lastPingTime = ping.ping = ONgGameState->GameTime; 149 UDPServer_SendToAll(&ping, FLATLINE_HEADER + 4); 150 } -
Daodan/MSVC/Flatline_Server.h
r579 r580 12 12 13 13 void FLrServer_Initialize(); 14 void FLsPingAll(); 14 15 #endif
Note:
See TracChangeset
for help on using the changeset viewer.