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

Comparing Daodan/MSVC/Flatline.c (file contents):
Revision 567 by gumby, Fri Jun 25 03:52:34 2010 UTC vs.
Revision 568 by gumby, Wed Jun 30 04:25:00 2010 UTC

# Line 14 | Line 14 | const char * Rejection_Messages[][255] =
14          {"-5"},
15   };
16  
17 + #define BETTER_SYNC
18 +
19 + void DoRareSync( short Player, sockaddr_in * sender )
20 + {
21 +        flatline_packet sync = {0};    
22 +
23 +        if (Player > max_connections || !PlayerList[ Player ] ) return;
24 +        
25 +                        
26 + //      DDrConsole_PrintF( "Sending sync data for player %i, new index %u", Player, PlayerList[ Player ]->rare_sync_index);
27 +        sender->sin_addr.S_un.S_addr = htonl(sender->sin_addr.S_un.S_addr);
28 +        sync.id = RARE_SYNC_DATA;
29 +        sprintf( sync.rare_sync_data.Class, TMrInstance_GetInstanceName( PlayerList[ Player ]->Chr->ONCC ) );
30 +        //using ->Inventory instead of ->Chr->Inventory to keep the index and Inventory in sync, just in case.
31 +        memcpy( &(sync.rare_sync_data.Inventory), &(PlayerList[ Player ]->Inventory), sizeof(Inventory) );
32 +        //WEAPONS ARE DISABLED. Why? Pain in the arse to sync.
33 +        sync.rare_sync_data.Inventory.Weapons[0] = NULL;
34 +        sync.rare_sync_data.Inventory.Weapons[1] = NULL;
35 +        sync.rare_sync_data.Inventory.Weapons[2] = NULL;
36 +        sync.rare_sync_data.PlayerNum = Player;
37 +        sync.rare_sync_data.index = PlayerList[ Player ]->rare_sync_index;
38 +        NetTCPServer_Send( sender, (char*)&sync, sizeof(rare_sync_data) + FLATLINE_HEADER );
39 + }
40 +
41   bool FLrServer_PacketCallback(char* data, int datalen, int from)
42   {
43          int i, j;
# Line 71 | Line 95 | bool FLrServer_PacketCallback(char* data
95                                  Char = &new_char.new_player.Character;
96                                  memset(Char, 0, sizeof(CharacterObject));
97                                  Char->Header.Type = 'CHAR';
98 <                                Char->OSD.Options = chr_dontaim | chr_unkillable;
98 >                                Char->OSD.Options = chr_dontaim;
99                                  for(j = 0; j < max_connections; j++) {
100                                          if(PlayerList[j] != 0) {
101                                                  new_char.new_player.Playernumber = j;
# Line 169 | Line 193 | bool FLrServer_PacketCallback(char* data
193                                  PlayerList[i]->Actions2 = packet_input->Actions2;
194                                  PlayerList[i]->MouseDeltaX = packet_input->MouseDeltaX;
195                                  PlayerList[i]->MouseDeltaY = packet_input->MouseDeltaY;
196 <
196 >                                PlayerList[i]->LastInputTime = packet_input->Time;
197  
198                                  break;
199                          }
200 +                case RARE_SYNC_DATA_REQUEST:
201 +                        DoRareSync( packet->sync_request , &sender);
202 +                        break;
203                  default:
204                          DDrConsole_PrintF("Warning, recieved badly formed packet!");
205                          break;
# Line 225 | Line 252 | bool FLrClient_Run(flatline_packet* pack
252                                          client_connected = 1;
253  
254                                          client_slot = ((connect_reply*)packet->data)->player_slot;
255 <                                        
256 <                        PlayerList[client_slot] = Players+client_slot;
257 <                        PlayerList[client_slot]->Chr = ONgGameState->PlayerCharacter;
231 <                        
232 <                        
255 >
256 >                                        PlayerList[client_slot] = Players+client_slot;
257 >                                        PlayerList[client_slot]->Chr = ONgGameState->PlayerCharacter;
258  
259                                          DDrConsole_PrintColored("Connection successful!",0,green, grey);
260 +                                        
261 +                                        //disable local input.
262 +                                        DDrPatch_NOOP(0x004FA929, 5 + 6 + 5);
263 +                                        
264                                          //DDrConsole_PrintF("Slot %i",  ((connect_reply*)packet)->player_slot);
265                                          break;
266                                  }
# Line 321 | Line 350 | bool FLrClient_Run(flatline_packet* pack
350                          }
351                          else {
352                                  ONrGameState_NewCharacter(Char, NULL, NULL, &chr_index);
353 +                                ONgGameState->CharacterStorage[chr_index].field_1E8 = 0;
354                                  PlayerList[packet.new_player.Playernumber] = &Players[chr_index];
355                                  Players[chr_index].Chr = &(ONgGameState->CharacterStorage[chr_index]);
356                                  Players[chr_index].Chr->Flags &= 0xFFBFFFFF;
357 +                                Players[chr_index].spawnnumber = chr_index;
358                                  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) ;
359                          }
360                          //Players[((new_player*)(packet.data))->Playernumber].spawnnumber = ONrGameState_NewCharacter(&(((new_player*)(packet.data))->Character), NULL, NULL, 0);
# Line 340 | Line 371 | bool FLrClient_Run(flatline_packet* pack
371                          if (i > max_connections) break;
372                          if( !PlayerList[i] ) break;
373                          //PlayerList[i]->Chr = ((GameState *)ONgGameState)->CharacterStorage;
374 <                        
374 > #ifndef BETTER_SYNC
375                          PlayerList[i]->Chr->Health = data->Health;
376                          PlayerList[i]->Chr->MaxHealth = data->MaxHealth;
377                          PlayerList[i]->Chr->Position = data->Position;
# Line 358 | Line 389 | bool FLrClient_Run(flatline_packet* pack
389                          if(!Active) break;
390  
391                          Active->PhyContext->Position = data->Position;
392 + #else
393 +                        PlayerList[i]->Actions1 = data->Inputs.Actions1;
394 +                        PlayerList[i]->Actions2 = data->Inputs.Actions2;
395 +                        PlayerList[i]->MouseDeltaX = data->Inputs.MouseDeltaX;
396 +                        PlayerList[i]->MouseDeltaY = data->Inputs.MouseDeltaY;
397 +                        memcpy( &(PlayerList[i]->player_data), data, sizeof(player_data) );
398 + #endif
399 +                        if( !server_started && data->rare_sync_index > PlayerList[i]->rare_sync_index )
400 +                        {
401 +                                        int sent_bytes;
402 +                                        flatline_packet sync_request = {0};
403 +                                        sync_request.id = RARE_SYNC_DATA_REQUEST;
404 +                                        sync_request.sync_request = i;
405 +                                        DDrConsole_PrintF( "Requesting sync data for player %i, old index %u", i, PlayerList[i]->rare_sync_index);
406 +                                        sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&sync_request, FLATLINE_HEADER + sizeof(int) );
407 +                        }
408 +
409  
410   #if 0          
411                          TMrInstance_GetDataPtr('TRAM',data->Animation,Active->Animation);
# Line 388 | Line 436 | bool FLrClient_Run(flatline_packet* pack
436   */
437                          break;
438                          }
439 +                case RARE_SYNC_DATA:
440 +                        if(1) {
441 +                        sl_arg hax[2];
442 +                        int dontuse;
443 +                        uint16_t i = packet.rare_sync_data.PlayerNum;
444 +                                                
445 +                        if (i > max_connections) break;
446 +                        if( !PlayerList[i] ) break;
447 +
448 +                        //WEAPONS ARE DISABLED. Why? Pain in the arse to sync.
449 +                        packet.rare_sync_data.Inventory.Weapons[0] = NULL;
450 +                        packet.rare_sync_data.Inventory.Weapons[1] = NULL;
451 +                        packet.rare_sync_data.Inventory.Weapons[2] = NULL;
452 + //                      TMrInstance_GetDataPtr( 'ONCC', packet.rare_sync_data.Class, PlayerList[ i ]->Chr->ONCC );
453 +                        
454 +                        //add the target character
455 +                        hax[0].type = sl_int32;
456 +                        hax[0].value_int32 = PlayerList[ packet.rare_sync_data.PlayerNum ]->spawnnumber;
457 +
458 +                        //add the new class
459 +                        //fix this later so we cant buffer overflow :O
460 +                        hax[1].type = sl_str32;
461 +                        hax[1].value_str32 = packet.rare_sync_data.Class;
462 +                        
463 +                        //we are directly calling a bsl function instead of using the normal method for two reasons
464 +                        //1. it has all the checking built in
465 +                        iSetCharacterClass( 0, 2, hax, &dontuse, &dontuse, hax );
466 +                        //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);
467 +                        memcpy( &(PlayerList[ i ]->Chr->Inventory), &(packet.rare_sync_data.Inventory), sizeof(Inventory ));
468 +
469 +                        PlayerList[i]->rare_sync_index = packet.rare_sync_data.index;
470 +                        }
471 +                        break;
472 +                        
473                  default:
474                          DDrConsole_PrintF("Warning, recieved badly formed packet!");
475                          break;
# Line 401 | Line 483 | bool FLrClient_Run(flatline_packet* pack
483          return true;
484   }
485  
486 < //UDPServer_SendToAll
405 < //Sends a packet to all the clients currently connected.
406 < //Returns the number of players sent to.
407 < int UDPServer_SendToAll(void* packet, int size) {
408 <        int j;
409 <        int players = 0;
410 <        sockaddr_in address;
411 <        memset(&address, 0, sizeof(sockaddr_in));
412 <        address.sin_family = AF_INET;
413 <        address.sin_addr.s_addr = htonl(INADDR_ANY);
414 <        address.sin_port = htons(27777);
415 <        for(j = 0; j < max_connections; j++) {
416 <                if (PlayerList[j] != 0 && PlayerList[j]->ip && (PlayerList[j]->ip != inet_addr("127.0.0.1"))) {
417 <                        int sent_bytes;
418 <                        address.sin_addr.s_addr = htonl(PlayerList[j]->ip);//*((struct in_addr*)(int*)&(Players[j].ip));                
419 <                        sent_bytes = NetUDPServer_Send((sockaddr *) &address, (char*)packet, size);
420 <                        if(sent_bytes == SOCKET_ERROR) NetCatchError();
421 <                        else players++;
422 <                }
423 <        }
424 <        return players;
425 < }
426 <
486 > //wtf, this needs cleaned up...
487   player_info *FLr_FindEmptySlot() {
488          int j;
489          for(j = 0; j < MAX_PLAYERS; j++) {
# Line 449 | Line 509 | static flatline_packet cache_input = {0}
509   extern void* TSrTest;
510   void * ONICALL FLrInput_Update_Keys(void)
511   {
512 <                uint16_t i;
512 >        uint16_t i;
513 >        /*DDrConsole_PrintF("Current: %x %x | Start: %x %x | Stop: %x %x | Stopped %x %x",
514 >                ONgGameState->Input.Current.Actions1, ONgGameState->Input.Current.Actions2,
515 >                ONgGameState->Input.Start.Actions1,ONgGameState->Input.Start.Actions2,
516 >                ONgGameState->Input.Stop.Actions1, ONgGameState->Input.Stop.Actions2,
517 >                ONgGameState->Input.Stopped.Actions2, ONgGameState->Input.Stopped.Actions2
518 >                );
519 >        */      
520 >        ActiveCharacter * Active_Player = ONgGameState->ActiveCharacters;
521 >        
522 >        //if sprint timer is equal to 0, display 0
523 >        //else if sprint timer is equal to -1, display -1
524 >        //else display difference
525 >        //good thing this is just quick an dirty debug stuff :)
526 >
527 >        //basically it seems that if the difference is bigger than 15 frames, you cant dash. : /
528 >        
529   #ifndef SPAM_INPUT
530          if(client_connected)
531          {
532                  int sent_bytes;
533                  flatline_packet input_packet = {0};
534                  input_packet.id = PLAYER_INPUT;
535 <                
535 >                input_packet.input_struct.Time = ONgGameState->GameTime;
536                  input_packet.input_struct.Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1;
537                  input_packet.input_struct.Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2;
538                  input_packet.input_struct.MouseDeltaX = ((GameState*)(ONgGameState))->Input.MouseDeltaX;
# Line 468 | Line 544 | void * ONICALL FLrInput_Update_Keys(void
544          }
545   #endif
546          //Testing drawing text to the screen...this failed. Will need to get it working eventually.
547 <        if( TSrTest )
547 >        if( TSrTest )
548          {
549          OniRectangle TextRect = { 20, 20, 50, 50 };
550                  TSrContext_DrawText(TSrTest, "Testing woohoo", 0xFF, 0, &TextRect);
# Line 480 | Line 556 | void * ONICALL FLrInput_Update_Keys(void
556                  GameInput * Active_Input;
557                  if(PlayerList[i] == 0) continue;
558                  
559 <                Active_Player = (void*)ONrGetActiveCharacter(PlayerList[i]->Chr);
559 >                //is this right?
560 >                Active_Player = (void*)ONrGetActiveCharacter( PlayerList[i]->Chr);
561          
562                  if(Active_Player == 0) continue;
563                  Active_Input = &(Active_Player->Input);
# Line 498 | Line 575 | void * ONICALL FLrInput_Update_Keys(void
575                          data->Facing = PlayerList[i]->Chr->Facing;
576                          data->DesiredFacing = PlayerList[i]->Chr->DesiredFacing;
577                          data->CosmeticFacing = PlayerList[i]->Chr->CosmeticFacing;
578 +                        data->Position = Active_Player->PhyContext->Position;
579 +                        
580 +                        if( PlayerList[i]->OldClass != PlayerList[i]->Chr->ONCC || memcmp( &(PlayerList[i]->Inventory), &(PlayerList[i]->Chr->Inventory), sizeof(Inventory) ) )
581 +                        {
582 +                                PlayerList[i]->OldClass = PlayerList[i]->Chr->ONCC;
583 +                                memcpy( &(PlayerList[i]->Inventory), &(PlayerList[i]->Chr->Inventory), sizeof(Inventory) );
584 +                                PlayerList[i]->rare_sync_index++;
585 +
586 +                        }
587 +                        
588 +                        data->rare_sync_index = PlayerList[i]->rare_sync_index;
589                          
590   #if 0
591                          data->Frame = Active_Player->Frame;    
# Line 530 | Line 618 | void * ONICALL FLrInput_Update_Keys(void
618                                  data->Inputs.Actions1 = PlayerList[i]->Actions1;
619                                  data->Inputs.Actions2 = PlayerList[i]->Actions2;
620                          }
621 +                        memcpy( &(PlayerList[i]->player_data), data, sizeof(player_data) );
622 +                        
623                          UDPServer_SendToAll(&data_out, sizeof(player_data) + FLATLINE_HEADER);
624                  }
625                  
626 <                if( (server_started && i !=0) || (!server_started && i != client_slot)) {
626 >                if( (server_started && i !=0)  || (!server_started/* && i != client_slot*/) )
627 >                {
628 >                        //this just made sync even worse....maybe keystrokes are actually _behind_
629 >                        //
630 >                        //
631 > #ifdef JITTER_FIX
632 >                        input_struct * New_Input = &PlayerList[i]->MouseDeltaX;
633 >                        input_struct * Cache_Input = &PlayerList[i]->CacheInput;
634 >                        Active_Input->Stop.Actions1 = ~Cache_Input->Actions1 & Active_Input->Current.Actions1;
635 >                        Active_Input->Stop.Actions2 = ~Cache_Input->Actions2 & Active_Input->Current.Actions2;
636 >                        Active_Input->Start.Actions1 = ~Active_Input->Current.Actions1 & Cache_Input->Actions1;
637 >                        Active_Input->Start.Actions2 = ~Active_Input->Current.Actions2 & Cache_Input->Actions2;
638 >                        Active_Input->Current.Actions1 = Cache_Input->Actions1;
639 >                        Active_Input->Current.Actions2 = Cache_Input->Actions2;
640 >                        Active_Input->Stopped.Actions1 = ~Active_Input->Current.Actions1;
641 >                        Active_Input->Stopped.Actions2 = ~Active_Input->Current.Actions2;
642 >                        Active_Input->MouseDeltaX = Cache_Input->MouseDeltaX;
643 >                        Active_Input->MouseDeltaY = Cache_Input->MouseDeltaY;
644 >                        memcpy( Cache_Input, New_Input, sizeof(input_struct));
645 > #else
646 >        
647                          Active_Input->Stop.Actions1 = ~PlayerList[i]->Actions1 & Active_Input->Current.Actions1;
648                          Active_Input->Stop.Actions2 = ~PlayerList[i]->Actions2 & Active_Input->Current.Actions2;
649                          Active_Input->Start.Actions1 = ~Active_Input->Current.Actions1 & PlayerList[i]->Actions1;
650                          Active_Input->Start.Actions2 = ~Active_Input->Current.Actions2 & PlayerList[i]->Actions2;
651 +                        
652                          Active_Input->Current.Actions1 = PlayerList[i]->Actions1;
653                          Active_Input->Current.Actions2 = PlayerList[i]->Actions2;
654                          Active_Input->Stopped.Actions1 = ~Active_Input->Current.Actions1;
655                          Active_Input->Stopped.Actions2 = ~Active_Input->Current.Actions2;
656                          Active_Input->MouseDeltaX = PlayerList[i]->MouseDeltaX;
657                          Active_Input->MouseDeltaY = PlayerList[i]->MouseDeltaY;
658 +                        DDrConsole_PrintF("Timer: %i", (Active_Player->SprintTimer != 0) ? (Active_Player->SprintTimer == -1) ? -1 : (ONgGameState->GameTime - Active_Player->SprintTimer) : 0);
659 +
660 +                        //DDrConsole_PrintF("1E8 %u", ONgGameState->PlayerCharacter->field_1E8);
661 + /*
662 +                        DDrConsole_PrintF("T %u | Current: %x %x | Start: %x %x | Stop: %x %x | Stopped %x %x",
663 +                                PlayerList[i]->LastInputTime,
664 +                                Active_Input->Current.Actions1, Active_Input->Current.Actions2,
665 +                                Active_Input->Start.Actions1,Active_Input->Start.Actions2,
666 +                                Active_Input->Stop.Actions1, Active_Input->Stop.Actions2,
667 +                                Active_Input->Stopped.Actions1, Active_Input->Stopped.Actions2
668 +                );
669 +                */
670 +                        
671 +                
672 + #endif
673 +
674 + #ifdef BETTER_SYNC
675 +                        if( !server_started && PlayerList[i]->player_data.Health != 0) {
676 +                                PlayerList[i]->Chr->Health = PlayerList[i]->player_data.Health;
677 +                                PlayerList[i]->Chr->MaxHealth = PlayerList[i]->player_data.MaxHealth;
678 +                                PlayerList[i]->Chr->Position = PlayerList[i]->player_data.Position;
679 +                                PlayerList[i]->Chr->Location = PlayerList[i]->player_data.Location;
680 +                                PlayerList[i]->Chr->LastPosition = PlayerList[i]->player_data.LastPosition;
681 +                                PlayerList[i]->Chr->Facing = PlayerList[i]->player_data.Facing;
682 +                                PlayerList[i]->Chr->DesiredFacing = PlayerList[i]->player_data.DesiredFacing;
683 +                                PlayerList[i]->Chr->CosmeticFacing = PlayerList[i]->player_data.CosmeticFacing;
684 +                                PlayerList[i]->Actions1 = PlayerList[i]->player_data.Inputs.Actions1;
685 +                                PlayerList[i]->Actions2 = PlayerList[i]->player_data.Inputs.Actions2;
686 +                                PlayerList[i]->MouseDeltaX = PlayerList[i]->player_data.Inputs.MouseDeltaX;
687 +                                PlayerList[i]->MouseDeltaY = PlayerList[i]->player_data.Inputs.MouseDeltaY;
688 +                                Active_Player->PhyContext->Position = PlayerList[i]->player_data.Position;
689 +                        }
690 + #endif
691 +
692                  }
693          }
694 +
695 +        //Make the current controls match the sent controls, now that we have sent them off and everything is synced.
696 +        //No, don't do it to the direct input, it breaks stuff.
697 +        //Need to disable the function that puts game input onto characters because we are doing it directly.
698 +        /*
699 +        if( !server_started )
700 +        {
701 +                ONgGameState->Input.MouseDeltaX = PlayerList[client_slot]->MouseDeltaX;
702 +                ONgGameState->Input.MouseDeltaY = PlayerList[client_slot]->MouseDeltaY;
703 +                ONgGameState->Input.Current.Actions1 = PlayerList[client_slot]->Actions1;
704 +                ONgGameState->Input.Current.Actions2 = PlayerList[client_slot]->Actions2;
705 +        }
706 +        */
707 +        
708          return ONgGameState;
709   }

Diff Legend

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