Changeset 584
- Timestamp:
- Jan 24, 2011, 7:45:07 AM (14 years ago)
- Location:
- Daodan/MSVC
- Files:
-
- 10 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Daodan/MSVC/Flatline.c
r583 r584 25 25 #define BETTER_SYNC 26 26 27 void DoRareSync( short Player, sockaddr_in * sender )28 {29 flatline_packet sync = {0};30 31 if (Player > max_connections || !PlayerList[ Player ] ) return;32 33 34 // DDrConsole_PrintF( "Sending sync data for player %i, new index %u", Player, PlayerList[ Player ]->rare_sync_index);35 sender->sin_addr.S_un.S_addr = htonl(sender->sin_addr.S_un.S_addr);36 sync.id = RARE_SYNC_DATA;37 sprintf( sync.rare_sync_data.Class, TMrInstance_GetInstanceName( PlayerList[ Player ]->Chr->ONCC ) );38 //using ->Inventory instead of ->Chr->Inventory to keep the index and Inventory in sync, just in case.39 memcpy( &(sync.rare_sync_data.Inventory), &(PlayerList[ Player ]->Inventory), sizeof(Inventory) );40 //WEAPONS ARE DISABLED. Why? Pain in the arse to sync.41 sync.rare_sync_data.Inventory.Weapons[0] = NULL;42 sync.rare_sync_data.Inventory.Weapons[1] = NULL;43 sync.rare_sync_data.Inventory.Weapons[2] = NULL;44 sync.rare_sync_data.PlayerNum = Player;45 sync.rare_sync_data.index = PlayerList[ Player ]->rare_sync_index;46 NetTCPServer_Send( sender, (char*)&sync, sizeof(rare_sync_data) + FLATLINE_HEADER );47 }48 49 enum50 {51 JustSpawned,52 FirstPass,53 SecondPass,54 NoPass,55 };56 57 27 bool FLrServer_PacketCallback(char* data, int datalen, int from) 58 28 { … … 102 72 //sending this several times to make sure it gets through. Really need to make up some form of packet tracking. 103 73 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 104 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER);74 /* NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 105 75 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 106 76 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 107 77 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); 108 78 Sleep(100); 109 79 */ 110 80 new_char.id = NEW_PLAYER; 111 81 Char = &new_char.new_player.Character; … … 202 172 203 173 204 PlayerList[i]-> Actions1 = packet_input->Actions1;205 PlayerList[i]-> Actions2 = packet_input->Actions2;206 PlayerList[i]-> MouseDeltaX = packet_input->MouseDeltaX;207 PlayerList[i]-> MouseDeltaY = packet_input->MouseDeltaY;174 PlayerList[i]->InputFromClient.Actions1 = packet_input->Actions1; 175 PlayerList[i]->InputFromClient.Actions2 = packet_input->Actions2; 176 PlayerList[i]->InputFromClient.MouseDeltaX = packet_input->MouseDeltaX; 177 PlayerList[i]->InputFromClient.MouseDeltaY = packet_input->MouseDeltaY; 208 178 PlayerList[i]->LastInputTime = packet_input->Time; 209 179 210 180 break; 211 181 } 212 case RARE_SYNC_DATA_REQUEST:213 DoRareSync( packet->sync_request , &sender);214 break;215 182 case PK_PONG: 216 183 for(i = 0; i < max_connections; i++) { … … 279 246 280 247 281 RGBA green = {0, 0xFF, 0, 0}; 282 RGBA red = {0, 0, 0xFF, 0}; 283 RGBA grey = {0x80,0x80,0x80,0x80}; 284 285 //FLrClient_Run 286 //Looping function that waits for packets from the server. 287 int client_slot = 0; 288 289 void FLrClient_GetPackets() 290 { 291 flatline_packet packet; 292 uint16_t len; 293 //#define SPAM_INPUT 294 #ifdef SPAM_INPUT 295 struct timeval lasttime; 296 struct timeval thistime; 297 gettimeofday(&lasttime, 0); 298 #endif 299 300 301 while(NetUDPSocket_Recieve(client_sock, (sockaddr_storage *) &client_address, &packet, &len)) { 302 //packet = (flatline_packet*)data; 303 //DDrConsole_PrintF("Data recieved, length %i, type %i", len, ((flatline_packet*)data)->id); 304 switch(packet.id) { 305 case MESSAGE: 306 COrMessage_Print(packet.data, "chat", 0); 307 break; 308 case CHANGE_NAME: 309 if(PlayerList[(char)packet.data[0]]) 310 { 311 char message_buffer[1024]; 312 sprintf(message_buffer,"%s changed their name to %s", PlayerList[(char)packet.data[0]]->name, packet.data + 1); 313 COrMessage_Print(message_buffer, "name_change", 0); 314 315 sprintf_s(PlayerList[packet.data[0]]->name, 32, "%s", packet.data + 1); 316 317 } 318 break; 319 case CONNECT_SEND: 320 ;if(1) { 321 flatline_packet connect_recv; 322 memcpy(&connect_recv.connect_reply.message,"This isn't a server!", sizeof("This isn't a server!")); 323 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&connect_recv, sizeof(bool) + FLATLINE_HEADER + sizeof("This isn't a server!")); 324 } 325 case CONNECT_REPLY: 326 break; //extra packet or something. 327 case NEW_PLAYER: 328 ;if(1) { //haxhaxhax 329 CharacterObject* Char = &(packet.new_player.Character); 330 uint32_t chr_index = 0; 331 Character* PC; 332 DDrConsole_PrintF("%i | %i", packet.new_player.Playernumber ,client_slot); 333 //Char->OSD.Options = 0; 334 if(packet.new_player.Playernumber == client_slot) { 335 PlayerList[packet.new_player.Playernumber] = &Players[0]; 336 PC = (ONgGameState->PlayerCharacter); 337 Players[0].Chr = PC; 338 339 } 340 else { 341 ONrGameState_NewCharacter(Char, NULL, NULL, &chr_index); 342 ONgGameState->CharacterStorage[chr_index].charType = 0; 343 PlayerList[packet.new_player.Playernumber] = &Players[chr_index]; 344 Players[chr_index].Chr = &(ONgGameState->CharacterStorage[chr_index]); 345 Players[chr_index].Chr->Flags &= 0xFFBFFFFF; 346 Players[chr_index].spawnnumber = chr_index; 347 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) ; 348 sprintf_s(Players[chr_index].name, 32, "%s", ((new_player*)(packet.data))->Character.OSD.Name); 349 } 350 //Players[((new_player*)(packet.data))->Playernumber].spawnnumber = ONrGameState_NewCharacter(&(((new_player*)(packet.data))->Character), NULL, NULL, 0); 351 break; 352 } 353 case PLAYER_DATA: 354 if(1) { //haxhaxhax 355 player_data* pd = &packet.player_data; 356 uint16_t i = pd->PlayerNum; 357 358 pd = (void*)packet.data; 359 360 361 if (i > max_connections) break; 362 if( !PlayerList[i] ) break; 363 364 memcpy( &(PlayerList[i]->player_data), pd, sizeof(player_data) ); 365 if(PlayerList[i]->player_data.Health == 0) 366 { 367 short breakfast = 1; 368 } 369 if( !server_started && pd->rare_sync_index > PlayerList[i]->rare_sync_index ) 370 { 371 int sent_bytes; 372 flatline_packet sync_request = {0}; 373 sync_request.id = RARE_SYNC_DATA_REQUEST; 374 sync_request.sync_request = i; 375 DDrConsole_PrintF( "Requesting sync data for player %i, old index %u", i, PlayerList[i]->rare_sync_index); 376 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&sync_request, FLATLINE_HEADER + sizeof(int) ); 377 } 378 379 PlayerList[i]->DataApplied = NoPass; 380 381 382 break; 383 } 384 case RARE_SYNC_DATA: 385 if(1) { 386 sl_arg hax[2]; 387 int dontuse; 388 uint16_t i = packet.rare_sync_data.PlayerNum; 389 390 if (i > max_connections) break; 391 if( !PlayerList[i] ) break; 392 393 //WEAPONS ARE DISABLED. Why? Pain in the arse to sync. 394 packet.rare_sync_data.Inventory.Weapons[0] = NULL; 395 packet.rare_sync_data.Inventory.Weapons[1] = NULL; 396 packet.rare_sync_data.Inventory.Weapons[2] = NULL; 397 // TMrInstance_GetDataPtr( 'ONCC', packet.rare_sync_data.Class, PlayerList[ i ]->Chr->ONCC ); 398 399 //add the target character 400 hax[0].type = sl_int32; 401 hax[0].value_int32 = PlayerList[ packet.rare_sync_data.PlayerNum ]->spawnnumber; 402 403 //add the new class 404 //fix this later so we cant buffer overflow :O 405 hax[1].type = sl_str32; 406 hax[1].value_str32 = packet.rare_sync_data.Class; 407 408 //we are directly calling a bsl function instead of using the normal method for two reasons 409 //1. it has all the checking built in 410 iSetCharacterClass( 0, 2, hax, &dontuse, &dontuse, hax ); 411 //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); 412 memcpy( &(PlayerList[ i ]->Chr->Inventory), &(packet.rare_sync_data.Inventory), sizeof(Inventory )); 413 414 PlayerList[i]->rare_sync_index = packet.rare_sync_data.index; 415 } 416 break; 417 case FLATLINE_EVENT: 418 FLcEventHandler( packet.flatline_event.event_index, packet.flatline_event.intArray ); 419 break; 420 case PK_PING: 421 packet.id = PK_PONG; 422 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&packet, FLATLINE_HEADER + 4); 423 break; 424 case PK_ALL_INPUT: 425 if(1) 426 { 427 int Player, i; 428 for(i = 0; packet.all_input[i].PlayerNum != -1; i++) 429 { 430 Player = packet.all_input[i].PlayerNum; 431 if(PlayerList[Player]) 432 { 433 PlayerList[Player]->Actions1 = packet.all_input[Player].Actions1; 434 PlayerList[Player]->Actions2 = packet.all_input[Player].Actions2; 435 PlayerList[Player]->MouseDeltaX = packet.all_input[Player].MouseDeltaX; 436 PlayerList[Player]->MouseDeltaY = packet.all_input[Player].MouseDeltaY; 437 PlayerList[Player]->Facing = packet.all_input[Player].Facing; 438 PlayerList[Player]->DesiredFacing = packet.all_input[Player].DesiredFacing; 439 PlayerList[Player]->Position = packet.all_input[Player].Position; 440 PlayerList[Player]->NeedToSetFP = 1; 441 } 442 } 443 } 444 break; 445 default: 446 DDrConsole_PrintF("Warning, recieved badly formed packet!"); 447 break; 448 } 449 } 450 } 451 452 453 bool FLrClient_Run(flatline_packet* packet) 454 { 455 456 char data[1400]; 457 uint16_t len; 458 int j; 459 int sent_bytes; 460 client_connected = 0; 461 462 463 //starts the connection 464 DDrConsole_PrintF("Connecting to server %s on socket %i", inet_ntoa(address.sin_addr), client_sock); 465 sent_bytes = NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)packet, 255); 466 if(sent_bytes == SOCKET_ERROR) { 467 NetCatchError(); 468 } 469 //loops once per second waiting for a reply. 470 for(j = 0; j < CONNECTION_TIMEOUT; j++) { 471 while(NetUDPSocket_Recieve(client_sock, (sockaddr_storage *) &client_address, data, &len)){ 472 packet = (flatline_packet*)data; 473 if(packet->id == CONNECT_REPLY) { 474 if(packet->connect_reply.goodtogo){ 475 476 client_connected = 1; 477 478 client_slot = ((connect_reply*)packet->data)->player_slot; 479 480 PlayerList[client_slot] = Players+client_slot; 481 PlayerList[client_slot]->Chr = ONgGameState->PlayerCharacter; 482 483 DDrConsole_PrintColored("Connection successful!",0,green, grey); 484 485 sprintf_s( PlayerList[client_slot]->name, 32, "%s", player_name ); 486 487 //disable local input. 488 DDrPatch_NOOP(0x004FA929, 5 + 6 + 5); 489 490 //Disable local turning 491 //DDrPatch_NOOP(0x004F7EA8, 2); 492 //DDrPatch_Byte( 0x004F7EB1 , 0xE9); 493 //DDrPatch_MakeJump( 0x004F7EB1, 0x004F8030 ); 494 495 496 //DDrPatch_Byte(0x04ED6FB, 0xEB); 497 498 //DDrConsole_PrintF("Slot %i", ((connect_reply*)packet)->player_slot); 499 //DDrPatch_NOOP(0x43B23,0x10); 500 //DDrPatch_NOOP(0x4EC248,(0x5A-0x48)); 501 //DDrPatch_NOOP(0x4EC861, 6); 502 break; 503 } 504 else { 505 DDrConsole_PrintF("Connection rejected: %s", ((connect_reply*)packet->data)->message); 506 return false; 507 break; 508 } 509 } 510 } 511 if(client_connected) break; 512 DDrConsole_PrintF("Connection timing out in %i seconds...", CONNECTION_TIMEOUT - j); 513 Sleep(1000); 514 } 515 //the client timed out without recieving an error message. 516 if(!client_connected) { 517 DDrConsole_PrintColored("Connection timed out.",0,red, grey); 518 return false; 519 } 520 521 return true; 522 } 248 249 250 523 251 524 252 //wtf, this needs cleaned up... … … 551 279 static flatline_packet cache_input = {0}; 552 280 553 bool ShouldSendUpdate( int i, Character* Player, ActiveCharacter* Active_Player )554 {555 return556 MultiplayerStatus.PleaseUpdateAllPlayers ? 1 :557 strcmp(PlayerList[i]->player_data.Animation,558 TMrInstance_GetInstanceName(Active_Player->Animation)) ? 1 :559 PlayerList[i]->player_data.Health != Player->Health ? 1 : 0;560 }561 281 562 282 void * ONICALL FLrInput_Update_Keys(void) … … 588 308 if(!(server_started || client_connected)) return ONgGameState; 589 309 590 all_input.id = PK_ALL_INPUT; 591 592 if(server_started && ONgGameState->GameTime % 120 == 0) 310 311 if(server_started) 593 312 { 594 FLsPingAll(); 595 } 596 597 if(server_started && PlayerList[0]) 598 { 599 PlayerList[0]->Actions1 = ONgGameState->Input.Current.Actions1; 600 PlayerList[0]->Actions2 = ONgGameState->Input.Current.Actions2; 601 PlayerList[0]->MouseDeltaX = ONgGameState->Input.MouseDeltaX; 602 PlayerList[0]->MouseDeltaY = ONgGameState->Input.MouseDeltaY; 603 } 604 313 if(ONgGameState->GameTime % 120 == 0) 314 { 315 FLsPingAll(); 316 } 317 318 if(PlayerList[0]) 319 { 320 PlayerList[0]->InputFromClient.Actions1 = ONgGameState->Input.Current.Actions1; 321 PlayerList[0]->InputFromClient.Actions2 = ONgGameState->Input.Current.Actions2; 322 PlayerList[0]->InputFromClient.MouseDeltaX = ONgGameState->Input.MouseDeltaX; 323 PlayerList[0]->InputFromClient.MouseDeltaY = ONgGameState->Input.MouseDeltaY; 324 } 325 FLsSendPlayerData(); 326 } 605 327 for(i = 0; i < max_connections; i++) { 606 328 ActiveCharacter * Active_Player; … … 617 339 continue; 618 340 } 619 if(server_started && PlayerList[i]->Chr->Health > 0 ) 620 { 621 622 //Set up input packets 623 624 all_input.all_input[InputIndex].Actions1 = PlayerList[i]->Actions1; 625 all_input.all_input[InputIndex].Actions2 = PlayerList[i]->Actions2; 626 all_input.all_input[InputIndex].MouseDeltaX = PlayerList[i]->MouseDeltaX; 627 all_input.all_input[InputIndex].MouseDeltaY = PlayerList[i]->MouseDeltaY; 628 629 all_input.all_input[InputIndex].Facing = Player->Facing; 630 all_input.all_input[InputIndex].DesiredFacing = Player->DesiredFacing; 631 632 //Infinity... 633 *(int *)&all_input.all_input[InputIndex].Position.X = 0x7f800000; 634 if(Active_Player) 635 { 636 all_input.all_input[InputIndex].Position = Active_Player->PhyContext->Position; 637 } 638 639 640 all_input.all_input[InputIndex].PlayerNum = i; 641 InputIndex++; 642 } 341 643 342 644 343 645 344 //Set the health properly first. 646 if( client_connected && PlayerList[i]->DataApplied == FirstPass ) 647 { 648 ONrCharacter_SetHitPoints( PlayerList[i]->Chr, PlayerList[i]->player_data.Health); 345 if( client_connected && DoWeUpdateThis( PlayerList[i]->UpdateFlags, PFlag_Health) ) 346 { 347 PlayerList[i]->Chr->MaxHealth = PlayerList[i]->Health.MaxHealth; 348 ONrCharacter_SetHitPoints( PlayerList[i]->Chr, PlayerList[i]->Health.Health); 349 PlayerList[i]->UpdateFlags &= ~( 1 << PFlag_Health ); 649 350 } 650 351 //If the player is dead … … 688 389 else 689 390 { 690 Actions = PlayerList[i]-> Actions1;391 Actions = PlayerList[i]->InputFromClient.Actions1; 691 392 } 692 393 … … 711 412 PlayerList[i]->state = STATE_ALIVE; 712 413 713 714 414 if( DoWeUpdateThis( PlayerList[i]->UpdateFlags, PFlag_Facing ) ) 415 { 416 PlayerList[i]->Chr->Facing = PlayerList[i]->Facings.Facing; 417 PlayerList[i]->Chr->DesiredFacing = PlayerList[i]->Facings.DesiredFacing; 418 PlayerList[i]->UpdateFlags &= ~( 1 << PFlag_Facing ); 419 } 420 715 421 if(Active_Player == 0) continue; 716 422 717 423 if( client_connected && DoWeUpdateThis( PlayerList[i]->UpdateFlags, PFlag_Position) ) 424 { 425 Active_Player->PhyContext->Position = PlayerList[i]->Position; 426 427 PlayerList[i]->UpdateFlags &= ~( 1 << PFlag_Position ); 428 } 429 430 431 432 433 if (!(Player->Flags & ONcCharacterFlag_BeingThrown) && 434 DoWeUpdateThis( PlayerList[i]->UpdateFlags, PFlag_Animation) && (PlayerList[i]->Animation)) 435 { 436 // get a pointer to the animation 437 438 439 if (PlayerList[i]->Animation != Active_Player->Animation) 440 { 441 442 /////////////////////////////////// 443 //TODO: Check age of animation 444 /////////////////////////////////// 445 446 // set the characters animation 447 /*ONrCharacter_SetAnimationInternal(Player, 448 Active_Player, 449 Active_Player->AnimationToState, 450 0, 451 Animation);*/ 452 //ONrCharacter_NewAnimationHook(Player, Active_Player); 453 ONrCharacter_SetAnimationExternal(Player, TRrAnimation_GetFrom(PlayerList[i]->Animation), PlayerList[i]->Animation, 0); 454 //ONrCharacter_NewAnimationHook(Player, Active_Player); 455 } 456 457 458 } 459 PlayerList[i]->UpdateFlags &= ~( 1 << PFlag_Animation ); 460 461 //Don't update the frame if we are waiting to change the animation 462 if(DoWeUpdateThis( PlayerList[i]->UpdateFlags, PFlag_FramePing) && PlayerList[i]->Frame != -1 463 //&& !DoWeUpdateThis( PlayerList[i]->UpdateFlags, PFlag_Animation) 464 ) 465 { 466 if( abs(PlayerList[i]->Frame - Active_Player->Frame) > 2 ) 467 { 468 short AnimationLength; 469 AnimationLength = TRrAnimation_GetDuration(Active_Player->Animation); 470 if (PlayerList[i]->Frame >= AnimationLength) 471 { 472 Active_Player->Frame = AnimationLength - 1; 473 //Active_Player->Frame = 0; 474 } 475 else 476 { 477 Active_Player->Frame = PlayerList[i]->Frame; 478 } 479 } 480 PlayerList[i]->UpdateFlags &= ~( 1 << PFlag_FramePing ); 481 } 482 483 //Increment frame in case we were waiting 484 PlayerList[i]->Frame++; 485 486 if (DoWeUpdateThis( PlayerList[i]->UpdateFlags, PFlag_Throws) 487 && PlayerList[i]->ThrowData.throwName[0] != 0) 488 { 489 if(PlayerList[PlayerList[i]->ThrowData.throwing]) 490 { 491 short throwTarget = PlayerList[PlayerList[i]->ThrowData.throwing]->spawnnumber; 492 if ((throwTarget != Active_Player->throwing) && 493 (PlayerList[i]->ThrowData.throwFrame < 10)) 494 { 495 void *throw_animation; 496 ActiveCharacter* Target; 497 // get the animation 498 499 TMrInstance_GetDataPtr( 500 'TRAM', 501 PlayerList[i]->ThrowData.throwName, 502 &throw_animation); 503 //if (error) return; 504 505 // set the throw target 506 Active_Player->ThrowTargetCharacter = &ONgGameState->CharacterStorage[throwTarget]; 507 Target = ONrGetActiveCharacter(Active_Player->ThrowTargetCharacter); 508 if ((Target->Animation != throw_animation) && 509 // (OldAnimation != Animation) && 510 !(Active_Player->ThrowTargetCharacter->Flags & ONcCharacterFlag_BeingThrown)) 511 { 512 // set the throw variables 513 Active_Player->targetThrow = throw_animation; 514 Active_Player->throwing = throwTarget; 515 516 // run the throw 517 ONrCharacter_NewAnimationHook(Player, Active_Player); 518 519 if (Active_Player->ThrowTargetCharacter) 520 { 521 Target->Frame += 2; 522 Target->thrownBy = Player->Number; 523 } 524 } 525 } 526 } 527 else 528 { 529 DDrConsole_PrintF("Warning, tried to throw nonexistant player %hi", 530 PlayerList[i]->ThrowData.throwing ); 531 } 532 } 533 534 //Always discard old throw data, even if it isnt applied 535 PlayerList[i]->UpdateFlags &= ~( 1 << PFlag_Throws ); 718 536 719 537 //Active_Player->PlayingFilm.Flags = 1; 720 538 Active_Input = &(Active_Player->Input); 721 539 722 if(server_started &&723 ShouldSendUpdate( i, PlayerList[i]->Chr, Active_Player) )724 {725 player_data * data;726 flatline_packet data_out = {0};727 728 729 data_out.id = PLAYER_DATA;730 data = (void*)&(data_out.data);731 data->PlayerNum = i;732 data->Health = PlayerList[i]->Chr->Health;733 data->MaxHealth = PlayerList[i]->Chr->MaxHealth;734 //data->Position = PlayerList[i]->Chr->Position;735 //data->Facing = PlayerList[i]->Chr->Facing;736 //data->DesiredFacing = PlayerList[i]->Chr->DesiredFacing;737 //data->Position = Active_Player->PhyContext->Position;738 memcpy(data->Animation, TMrInstance_GetInstanceName(Active_Player->Animation), 31);739 data->Frame = Active_Player->Frame;740 741 data->UD = Active_Player->HeadPitch;742 data->LR = Active_Player->HeadFacing;743 744 if(Active_Player->targetThrow)745 {746 data->throw_data.throwing = Players[Active_Player->throwing].list_slot;747 memcpy(data->throw_data.throwName, TMrInstance_GetInstanceName(Active_Player->targetThrow), 31);748 data->throw_data.throwFrame = ONrGetActiveCharacter(Active_Player->targetThrow)->Frame;749 }750 751 752 if( PlayerList[i]->OldClass != PlayerList[i]->Chr->ONCC || memcmp( &(PlayerList[i]->Inventory), &(PlayerList[i]->Chr->Inventory), sizeof(Inventory) ) )753 {754 PlayerList[i]->OldClass = PlayerList[i]->Chr->ONCC;755 memcpy( &(PlayerList[i]->Inventory), &(PlayerList[i]->Chr->Inventory), sizeof(Inventory) );756 PlayerList[i]->rare_sync_index++;757 758 }759 760 data->rare_sync_index = PlayerList[i]->rare_sync_index;761 762 763 data->Ping = PlayerList[i]->Ping;764 memcpy( &(PlayerList[i]->player_data), data, sizeof(player_data) );765 766 UDPServer_SendToAll(&data_out, sizeof(player_data) + FLATLINE_HEADER);767 }768 769 540 if( (server_started && i !=0) || !server_started ) 770 541 { 771 Active_Input->Stop.Actions1 = ~PlayerList[i]-> Actions1 & Active_Input->Current.Actions1;772 Active_Input->Stop.Actions2 = ~PlayerList[i]-> Actions2 & Active_Input->Current.Actions2;773 Active_Input->Start.Actions1 = ~Active_Input->Current.Actions1 & PlayerList[i]-> Actions1;774 Active_Input->Start.Actions2 = ~Active_Input->Current.Actions2 & PlayerList[i]-> Actions2;775 776 Active_Input->Current.Actions1 = PlayerList[i]-> Actions1;777 Active_Input->Current.Actions2 = PlayerList[i]-> Actions2;542 Active_Input->Stop.Actions1 = ~PlayerList[i]->Input.Actions1 & Active_Input->Current.Actions1; 543 Active_Input->Stop.Actions2 = ~PlayerList[i]->Input.Actions2 & Active_Input->Current.Actions2; 544 Active_Input->Start.Actions1 = ~Active_Input->Current.Actions1 & PlayerList[i]->Input.Actions1; 545 Active_Input->Start.Actions2 = ~Active_Input->Current.Actions2 & PlayerList[i]->Input.Actions2; 546 547 Active_Input->Current.Actions1 = PlayerList[i]->Input.Actions1; 548 Active_Input->Current.Actions2 = PlayerList[i]->Input.Actions2; 778 549 Active_Input->Stopped.Actions1 = ~Active_Input->Current.Actions1; 779 550 Active_Input->Stopped.Actions2 = ~Active_Input->Current.Actions2; 780 Active_Input->MouseDeltaX = PlayerList[i]->MouseDeltaX; 781 Active_Input->MouseDeltaY = PlayerList[i]->MouseDeltaY; 782 783 784 if( !server_started && PlayerList[i]->player_data.Health != 0 && PlayerList[i]->Chr->Health != 0) { 785 void* OldAnimation; 786 void* Animation; 787 player_data* pd = &PlayerList[i]->player_data; 788 789 //This is getting crazy. WTB new packet system 790 if(PlayerList[i]->NeedToSetFP) 791 { 792 PlayerList[i]->Chr->Facing = PlayerList[i]->Facing; 793 PlayerList[i]->Chr->DesiredFacing = PlayerList[i]->DesiredFacing; 794 795 if(*(int*)&PlayerList[i]->Chr->Position.X != 0x7f800000) 796 { 797 Active_Player->PhyContext->Position = Player->Location = PlayerList[i]->Position; 798 799 } 800 PlayerList[i]->NeedToSetFP = 0; 801 } 802 803 if( PlayerList[i]->DataApplied == FirstPass ) 804 { 805 PlayerList[i]->DataApplied = SecondPass; 806 807 //Player->Health = PlayerList[i]->player_data.Health; 808 PlayerList[i]->Chr->MaxHealth = PlayerList[i]->player_data.MaxHealth; 809 810 } 811 else if( PlayerList[i]->DataApplied == SecondPass ) 812 { 813 OldAnimation = Active_Player->Animation; 814 815 PlayerList[i]->DataApplied = NoPass; 816 817 PlayerList[i]->player_data.Frame++; 818 819 if (!(Player->Flags & ONcCharacterFlag_BeingThrown) && 820 (pd->Animation[0] != 0)) 821 { 822 // get a pointer to the animation 823 824 TMrInstance_GetDataPtr( 825 'TRAM', 826 pd->Animation, 827 &Animation); 828 if (Animation != OldAnimation) 829 { 830 short num_frames; 831 bool updateAnimation = true; 832 833 // if the character is dead, make sure this animation is appropriate for death 834 /* 835 if (Player->Flags & ONcCharacterFlag_Dead) 836 { 837 short curToState = TRrAnimation_GetTo(Active_Player->Animation); 838 short newToState = TRrAnimation_GetTo(animation); 839 840 // if we are currently heading towards fallen and the new animation would not 841 // then this is a better animation to run when we are dead 842 if ((ONrAnimState_IsFallen(curToState)) && 843 (!ONrAnimState_IsFallen(newToState))) 844 { 845 updateAnimation = false; 846 } 847 } 848 */ 849 if ((updateAnimation) && (Active_Player->Animation == Animation)) 850 { 851 int oldFrame = Active_Player->Frame; 852 int newFrame = pd->Frame; 853 854 if (abs(oldFrame - newFrame) < 2) 855 { 856 updateAnimation = false; 857 } 858 } 859 860 if (updateAnimation) 861 { 862 // set the characters animation 863 /* ONrCharacter_SetAnimationInternal(Player, 864 Active_Player, 865 Active_Player->AnimationToState, 866 0, 867 Animation); 868 ONrCharacter_NewAnimationHook(Player, Active_Player);*/ 869 //Player->Flags |= 0x00000010; 870 ONrCharacter_SetAnimationExternal(Player, TRrAnimation_GetFrom(Animation), Animation, 0); 871 //ONrCharacter_NewAnimationHook(Player, Active_Player); 872 } 873 874 num_frames = TRrAnimation_GetDuration(Active_Player->Animation); 875 876 if (pd->Frame == num_frames) 877 { 878 Active_Player->Frame = num_frames - 1; 879 //Active_Player->Frame = 0; 880 } 881 else 882 { 883 Active_Player->Frame = pd->Frame; 884 } 885 } 886 } //animation check 887 888 if (PlayerList[i]->player_data.throw_data.throwName[0] != 0) 889 { 890 if(PlayerList[pd->throw_data.throwing]) 891 { 892 short throwTarget = PlayerList[pd->throw_data.throwing]->spawnnumber; 893 if ((throwTarget != Active_Player->throwing) && 894 (pd->throw_data.throwFrame < 10)) 895 { 896 void *throw_animation; 897 ActiveCharacter* Target; 898 // get the animation 899 900 TMrInstance_GetDataPtr( 901 'TRAM', 902 pd->throw_data.throwName, 903 &throw_animation); 904 //if (error) return; 905 906 // set the throw target 907 Active_Player->ThrowTargetCharacter = &ONgGameState->CharacterStorage[throwTarget]; 908 Target = ONrGetActiveCharacter(Active_Player->ThrowTargetCharacter); 909 if ((Target->Animation != throw_animation) && 910 (OldAnimation != Animation) && 911 !(Active_Player->ThrowTargetCharacter->Flags & ONcCharacterFlag_BeingThrown)) 912 { 913 // set the throw variables 914 Active_Player->targetThrow = throw_animation; 915 Active_Player->throwing = throwTarget; 916 917 // run the throw 918 ONrCharacter_NewAnimationHook(Player, Active_Player); 919 920 if (Active_Player->ThrowTargetCharacter) 921 { 922 Target->Frame += 2; 923 Target->thrownBy = Player->Number; 924 } 925 } 926 } 927 } 928 else 929 { 930 DDrConsole_PrintF("Warning, tried to throw nonexistant player %hi", pd->throw_data.throwing ); 931 } 932 } //throw check 933 } //second pass 934 } //if not dead 935 } //if( (server_started && i !=0) || !server_started ) 551 Active_Input->MouseDeltaX = PlayerList[i]->Input.MouseDeltaX; 552 Active_Input->MouseDeltaY = PlayerList[i]->Input.MouseDeltaY; 553 } 936 554 937 555 //Check for character switching requests 938 if(server_started && PlayerList[i]-> player_data.Health != 0 && PlayerList[i]->Chr->Health != 0 && PlayerList[i]->Actions1 & Action_Block && PlayerList[i]->ShapeshiftCooldown < ONgGameState->GameTime)556 if(server_started && PlayerList[i]->Chr->Health != 0 && PlayerList[i]->InputFromClient.Actions1 & Action_Block && PlayerList[i]->ShapeshiftCooldown < ONgGameState->GameTime) 939 557 { 940 558 int error; … … 955 573 } 956 574 */ 957 if (PlayerList[i]-> Actions1 & Action_Crouch) {575 if (PlayerList[i]->InputFromClient.Actions1 & Action_Crouch) { 958 576 Player->ONCCnumber += numClasses - 1; 959 577 } … … 976 594 977 595 } 978 if(server_started) 979 { 980 all_input.all_input[InputIndex].PlayerNum = -1; 981 UDPServer_SendToAll(&all_input, 982 FLATLINE_HEADER + sizeof(player_input) * InputIndex + sizeof(int16_t)); 983 } 596 984 597 MultiplayerStatus.PleaseUpdateAllPlayers = 0; 985 598 return ONgGameState; … … 1059 672 TSrContext_DrawText(ScoreboardInstance, DrawString, 255, 0, &DrawLocation); 1060 673 DrawLocation.x += 50; 1061 sprintf(DrawString, "%i", PlayerList[i]-> player_data.Ping);674 sprintf(DrawString, "%i", PlayerList[i]->Ping); 1062 675 TSrContext_DrawText(ScoreboardInstance, DrawString, 255, 0, &DrawLocation); 1063 676 } -
Daodan/MSVC/Flatline.h
r583 r584 36 36 #include "Daodan_Console.h" 37 37 #include "Oni_Character.h" 38 38 #include "Flatline_Packet.h" 39 39 40 40 #define pad1_size (sizeof(int64_t) - sizeof(short)) … … 114 114 char throwName[32]; 115 115 } td; 116 /* 116 117 typedef struct { 117 118 uint16_t PlayerNum; … … 139 140 140 141 //todo, move health in... 141 typedef struct {142 /*typedef struct { 142 143 short unsigned int PlayerNum; 143 144 unsigned int index; … … 145 146 char Class[32]; 146 147 } rare_sync_data; 147 148 */ 148 149 typedef struct { 149 150 unsigned int event_index; 150 151 int intArray[]; 151 152 } flatline_event; 152 153 /* 153 154 typedef struct { 154 155 int16_t PlayerNum; … … 161 162 Vector3 Position; 162 163 } player_input; 163 164 */ 164 165 //used for storing data about each player 165 166 typedef struct { … … 175 176 new_player new_player; 176 177 server_status server_status; 177 player_data player_data;178 rare_sync_data rare_sync_data;178 //player_data player_data; 179 //rare_sync_data rare_sync_data; 179 180 uint16_t sync_request; 180 181 flatline_event flatline_event; 181 182 uint32_t ping; 182 player_input all_input[33];183 //player_input all_input[33]; 183 184 }; 184 185 } flatline_packet; … … 202 203 NEW_PLAYER, 203 204 PLAYER_INPUT, 204 PLAYER_DATA,205 RARE_SYNC_DATA,206 RARE_SYNC_DATA_REQUEST,205 //PLAYER_DATA, 206 //RARE_SYNC_DATA, 207 //RARE_SYNC_DATA_REQUEST, 207 208 FLATLINE_EVENT, 208 209 PK_PING, 209 210 PK_PONG, 210 PK_ALL_INPUT, 211 //PK_ALL_INPUT, 212 PK_PLAYER_DATA, 211 213 }; 212 214 … … 248 250 uint16_t spawnnumber; 249 251 uint16_t list_slot; 250 251 //Todo: move into struct for slightly faster copying 252 float MouseDeltaX; 253 float MouseDeltaY; 254 uint32_t Actions1; 255 uint32_t Actions2; 256 float Facing; 257 float DesiredFacing; 258 //float Height; 252 253 PlayerInput InputFromClient; 254 255 //////////////////////////// 256 //Sync stuff 257 //////////////////////////// 258 uint16_t UpdateFlags; 259 260 PlayerInput Input; 261 PlayerHealth Health; 262 PlayerFacing Facings; 263 PlayerScore Score; 264 void* Animation; 265 uint16_t Frame; 266 PlayerThrowData ThrowData; 267 void* Class; 268 PlayerInventory Inventory; 259 269 Vector3 Position; 270 //////////////////////////// 271 bool HasAppliedThrow; 260 272 261 273 unsigned int LastInputTime; 262 input_struct CacheInput; 263 player_data player_data; 264 unsigned int rare_sync_index; 265 void* OldClass; 266 Inventory Inventory; 274 275 276 267 277 uint16_t state; 268 278 int flags; … … 302 312 int FLrEvent_GetNumArgs( int eventIndex ); 303 313 bool FlatlineInitialize(); 314 315 bool DoWeUpdateThis( uint16_t BitSet, uint16_t Flag ); 316 304 317 extern unsigned int lastPingTime; 305 318 #endif -
Daodan/MSVC/Flatline_Net.c
r582 r584 58 58 { 59 59 //DDrConsole_PrintF("Sending data size %u to %s on socket %i", datalen, inet_ntoa( ((sockaddr_in*)address)->sin_addr ), UDPServer_Socket); 60 data->FLATLINE = *(int*)"FLATLINE";60 //data->FLATLINE = *(int*)"FLATLINE"; 61 61 return NetUDPSocket_Send(UDPServer_Socket, address, data, datalen); 62 62 } … … 149 149 data->packet_index = packet_index; 150 150 #endif 151 data->FLATLINE = *(int*)"FLATLINE";151 //data->FLATLINE = *(int*)"FLATLINE"; 152 152 switch (address->sa_family) 153 153 { -
Daodan/MSVC/Oni_GameState.h
r582 r584 996 996 int field_1668; 997 997 char gap_166c[4]; 998 int Kills;999 int Damage;998 uint32_t Kills; 999 uint32_t Damage; 1000 1000 int field_1678; 1001 1001 int field_167C; … … 1237 1237 __int16 thrownBy; 1238 1238 Character* ThrowTargetCharacter; 1239 inttargetThrow; //animation1239 void* targetThrow; //animation 1240 1240 int field_1EE4; 1241 1241 int field_1EE8; … … 1442 1442 int field_1679DC; 1443 1443 } GameState; 1444 #endif 1444 1445 1445 1446 1446 typedef struct … … 1476 1476 int blah3; 1477 1477 } COtTextArea; 1478 #endif
Note:
See TracChangeset
for help on using the changeset viewer.