#include "Flatline.h" #include "Oni_Character.h" #include "Flatline_Server.h" //#include #include uint32_t last1 = 0; uint32_t last2 = 0; player_info Players[MAX_PLAYERS] = {{0}, {0}, {0}, {0}}; player_info * PlayerList[MAX_CONNECTIONS] = {0}; const char * Rejection_Messages[][255] = { {"Server is full"}, {"-2"}, {"-3"}, {"-4"}, {"-5"}, }; #define BETTER_SYNC void DoRareSync( short Player, sockaddr_in * sender ) { flatline_packet sync = {0}; if (Player > max_connections || !PlayerList[ Player ] ) return; // DDrConsole_PrintF( "Sending sync data for player %i, new index %u", Player, PlayerList[ Player ]->rare_sync_index); sender->sin_addr.S_un.S_addr = htonl(sender->sin_addr.S_un.S_addr); sync.id = RARE_SYNC_DATA; sprintf( sync.rare_sync_data.Class, TMrInstance_GetInstanceName( PlayerList[ Player ]->Chr->ONCC ) ); //using ->Inventory instead of ->Chr->Inventory to keep the index and Inventory in sync, just in case. memcpy( &(sync.rare_sync_data.Inventory), &(PlayerList[ Player ]->Inventory), sizeof(Inventory) ); //WEAPONS ARE DISABLED. Why? Pain in the arse to sync. sync.rare_sync_data.Inventory.Weapons[0] = NULL; sync.rare_sync_data.Inventory.Weapons[1] = NULL; sync.rare_sync_data.Inventory.Weapons[2] = NULL; sync.rare_sync_data.PlayerNum = Player; sync.rare_sync_data.index = PlayerList[ Player ]->rare_sync_index; NetTCPServer_Send( sender, (char*)&sync, sizeof(rare_sync_data) + FLATLINE_HEADER ); } bool FLrServer_PacketCallback(char* data, int datalen, int from) { int i, j; bool found_player = 0; flatline_packet * packet = (flatline_packet*)data; static int recieved = 0; sockaddr_in sender; sender.sin_family = AF_INET; sender.sin_port = htons(27777); sender.sin_addr = *((struct in_addr*)(int*)&from); //packet->data[datalen] = '\0'; //DDrConsole_PrintF("Packet \r%d recieved from %i", ++recieved, from); //if data[0] != CONNECT_SEND, search in playerlist for ip address switch(packet->id) { flatline_packet connect_recv; player_info * playah; //rewrite this when we get TCP support. //rewrite this before we get TCP support* //the way of seeing if there is room for players sucks. case CONNECT_SEND: ; connect_recv.id = CONNECT_REPLY; //if(Players[i].ip == sender.sin_addr.S_un.S_addr) break; //needs to send an error message sender.sin_addr.S_un.S_addr = htonl(sender.sin_addr.S_un.S_addr); playah = FLrServer_AddPlayer(from,packet->connect_send.name, 0); DDrConsole_PrintF("%s connected from %s", packet->connect_send.name, inet_ntoa(sender.sin_addr ) ); if(!((int)playah > -5 && (int)playah <= 0)) { flatline_packet new_char = {0}; CharacterObject* Char; connect_recv.connect_reply.goodtogo = 1; connect_recv.connect_reply.player_slot = playah->list_slot; DDrConsole_PrintF("Slot: %i", playah->list_slot); //sending this several times to make sure it gets through. Really need to make up some form of packet tracking. NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); Sleep(100); new_char.id = NEW_PLAYER; Char = &new_char.new_player.Character; memset(Char, 0, sizeof(CharacterObject)); Char->Header.Type = 'CHAR'; Char->OSD.Options = chr_dontaim; for(j = 0; j < max_connections; j++) { if(PlayerList[j] != 0) { new_char.new_player.Playernumber = j; sprintf(Char->OSD.Name,"%s",PlayerList[j]->name); sprintf(Char->OSD.Class, "%s", TMrInstance_GetInstanceName(PlayerList[j]->Chr->ONCC)); DDrConsole_PrintF("Class %s", Char->OSD.Class ); sprintf(Char->OSD.Class, "konoko_generic"); NetTCPServer_Send((sockaddr *) &sender, (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER ); } } } else { //fix the error messages... DDrConsole_PrintF("Server is full. :("); connect_recv.connect_reply.goodtogo = 0; sender.sin_addr.S_un.S_addr = htonl(sender.sin_addr.S_un.S_addr); memcpy(&connect_recv.connect_reply.message,"Server is full.", sizeof("Server is full.")); NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(bool)*2 + FLATLINE_HEADER + sizeof("Server is full.")); } break; case CONNECT_REPLY: break; //do nothing...a server shouldn't recieve this type of packet. case MESSAGE: for(i = 0; i < MAX_PLAYERS; i++) { //DDrConsole_PrintF("%i : %i | %s : %s", from, Players[i].ip, inet_ntoa(*(struct in_addr*)&from), inet_ntoa(*(struct in_addr*)&(Players[i].ip))); if(Players[i].ip == sender.sin_addr.S_un.S_addr) { found_player = 1; break; } } if(found_player == 0) return true; else { char message_buffer[512] = {0}; flatline_packet message; int message_size; data[datalen] = 0; DDrConsole_PrintF("%s: %s", Players[i].name, packet->data); sprintf(message_buffer, "%s: %s", Players[i].name, packet->data); message.id = MESSAGE; message_size = sprintf(message.data, "%s", message_buffer); COrMessage_Print(message_buffer, "chat", 0); UDPServer_SendToAll(&message, message_size + 1 + FLATLINE_HEADER); break; } case CHANGE_NAME: ; //wtf, needed or i get an error. DDrConsole_PrintF("Changing Name to: %s", packet->data); for(i = 0; i < MAX_PLAYERS; i++) { if(Players[i].ip == sender.sin_addr.S_un.S_addr) { found_player = 1; break; } } if(found_player == 0) return true; else { bool name_exists = 0; for(j = 0; j < MAX_PLAYERS; j++) { if(!strcmp(packet->data, Players[j].name)) { name_exists = 1; break; } } if(!name_exists) { char message_buffer[1024]; sprintf(message_buffer,"%s changed their name to %s", Players[i].name, packet->data); COrMessage_Print(message_buffer, "name_change", 0); memcpy(Players[i].name, packet->data, 256); } break; } case PLAYER_INPUT: for(i = 0; i < max_connections; i++) { if(PlayerList[i] != 0 && PlayerList[i]->ip == sender.sin_addr.S_un.S_addr) { found_player = 1; break; } } if(found_player == 0) return true; else { input_struct * packet_input = &packet->input_struct; PlayerList[i]->Actions1 = packet_input->Actions1; PlayerList[i]->Actions2 = packet_input->Actions2; PlayerList[i]->MouseDeltaX = packet_input->MouseDeltaX; PlayerList[i]->MouseDeltaY = packet_input->MouseDeltaY; PlayerList[i]->LastInputTime = packet_input->Time; break; } case RARE_SYNC_DATA_REQUEST: DoRareSync( packet->sync_request , &sender); break; default: DDrConsole_PrintF("Warning, recieved badly formed packet!"); break; } return true; } bool FLrServer_Run() { // Get the local hostname char szHostName[255]; struct hostent *host_entry; gethostname(szHostName, 255); host_entry=gethostbyname(szHostName); DDrConsole_PrintF("Server started at %s...", inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list)); return NetUDPServer_Listen(27777, FLrServer_PacketCallback); } RGBA green = {0, 0xFF, 0, 0}; RGBA red = {0, 0, 0xFF, 0}; RGBA grey = {0x80,0x80,0x80,0x80}; //FLrClient_Run //Looping function that waits for packets from the server. //TODO: Convert connection packet stuff to TCP int client_slot = 0; bool FLrClient_Run(flatline_packet* packet) { char data[1400]; uint16_t len; int j; int sent_bytes; client_connected = 0; //starts the connection DDrConsole_PrintF("Connecting to server %s on socket %i", inet_ntoa(address.sin_addr), client_sock); sent_bytes = NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)packet, 255); if(sent_bytes == SOCKET_ERROR) { NetCatchError(); } //loops once per second waiting for a reply. for(j = 0; j < CONNECTION_TIMEOUT; j++) { while(NetUDPSocket_Recieve(client_sock, (sockaddr_storage *) &client_address, data, &len)){ packet = (flatline_packet*)data; if(packet->id == CONNECT_REPLY) { if(packet->connect_reply.goodtogo){ client_connected = 1; client_slot = ((connect_reply*)packet->data)->player_slot; PlayerList[client_slot] = Players+client_slot; PlayerList[client_slot]->Chr = ONgGameState->PlayerCharacter; DDrConsole_PrintColored("Connection successful!",0,green, grey); //disable local input. DDrPatch_NOOP(0x004FA929, 5 + 6 + 5); //DDrConsole_PrintF("Slot %i", ((connect_reply*)packet)->player_slot); break; } else { DDrConsole_PrintF("Connection rejected: %s", ((connect_reply*)packet->data)->message); return false; break; } } } if(client_connected) break; DDrConsole_PrintF("Connection timing out in %i seconds...", CONNECTION_TIMEOUT - j); Sleep(1000); } //the client timed out without recieving an error message. if(!client_connected) { DDrConsole_PrintColored("Connection timed out.",0,red, grey); return false; } else { ActiveCharacter * Active; flatline_packet packet; //#define SPAM_INPUT #ifdef SPAM_INPUT struct timeval lasttime; struct timeval thistime; gettimeofday(&lasttime, 0); #endif while(1) { #ifdef SPAM_INPUT gettimeofday(&thistime, 0); //DDrConsole_PrintF("%i.%i | %i.%i | %i.%i",lasttime.tv_sec, lasttime.tv_usec, thistime.tv_sec, thistime.tv_usec, // thistime.tv_sec - lasttime.tv_sec, thistime.tv_usec - lasttime.tv_usec); //checks to see if enough time has passed since the last input update (by default once every 10ms) if( ((thistime.tv_sec > lasttime.tv_sec) && ((thistime.tv_usec + 1000000 - lasttime.tv_usec ) > update_rate * 1000) ) || ((thistime.tv_sec == lasttime.tv_sec) && ((thistime.tv_usec - lasttime.tv_usec ) > update_rate * 1000)) ) { flatline_packet input_packet; lasttime.tv_usec = ++thistime.tv_usec; //in case recieving packets takes less than 1 ms. input_packet.id = PLAYER_INPUT; if( ((GameState*)(ONgGameState))->Input.Current.Actions1 != last1 || ((GameState*)(ONgGameState))->Input.Current.Actions2 != last2) { last1 =((GameState*)(ONgGameState))->Input.Current.Actions1; last2 =((GameState*)(ONgGameState))->Input.Current.Actions2; } ((input_struct*)(void*)(input_packet.data))->Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1; ((input_struct*)(void*)(input_packet.data))->Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2; ((input_struct*)(void*)(input_packet.data))->MouseDeltaX = ((GameState*)(ONgGameState))->Input.MouseDeltaX; ((input_struct*)(void*)(input_packet.data))->MouseDeltaY = ((GameState*)(ONgGameState))->Input.MouseDeltaY; sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&input_packet, sizeof(input_struct) + FLATLINE_HEADER); //if(sent_bytes == SOCKET_ERROR) NetCatchError(); } #endif if(NetUDPSocket_Recieve(client_sock, (sockaddr_storage *) &client_address, &packet, &len)) { //packet = (flatline_packet*)data; //DDrConsole_PrintF("Data recieved, length %i, type %i", len, ((flatline_packet*)data)->id); switch(packet.id) { case MESSAGE: COrMessage_Print(packet.data, "chat", 0); break; case CONNECT_SEND: ;if(1) { flatline_packet connect_recv; memcpy(&connect_recv.connect_reply.message,"This isn't a server!", sizeof("This isn't a server!")); NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&connect_recv, sizeof(bool) + FLATLINE_HEADER + sizeof("This isn't a server!")); } case CONNECT_REPLY: break; //extra packet or something. case NEW_PLAYER: ;if(1) { //haxhaxhax CharacterObject* Char = &(packet.new_player.Character); uint32_t chr_index = 0; Character* PC; DDrConsole_PrintF("%i | %i", packet.new_player.Playernumber ,client_slot); //Char->OSD.Options = 0; if(packet.new_player.Playernumber == client_slot) { PlayerList[packet.new_player.Playernumber] = &Players[0]; PC = (ONgGameState->PlayerCharacter); Players[0].Chr = PC; } else { ONrGameState_NewCharacter(Char, NULL, NULL, &chr_index); ONgGameState->CharacterStorage[chr_index].field_1E8 = 0; PlayerList[packet.new_player.Playernumber] = &Players[chr_index]; Players[chr_index].Chr = &(ONgGameState->CharacterStorage[chr_index]); Players[chr_index].Chr->Flags &= 0xFFBFFFFF; Players[chr_index].spawnnumber = chr_index; 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) ; } //Players[((new_player*)(packet.data))->Playernumber].spawnnumber = ONrGameState_NewCharacter(&(((new_player*)(packet.data))->Character), NULL, NULL, 0); break; } case PLAYER_DATA: if(1) { //haxhaxhax player_data* data = &packet.player_data; uint16_t i = data->PlayerNum; GameInput * Active_Input; data = (void*)packet.data; //DDrConsole_PrintF("Got data for Player %i, %x", i, PlayerList[i]); if (i > max_connections) break; if( !PlayerList[i] ) break; //PlayerList[i]->Chr = ((GameState *)ONgGameState)->CharacterStorage; #ifndef BETTER_SYNC PlayerList[i]->Chr->Health = data->Health; PlayerList[i]->Chr->MaxHealth = data->MaxHealth; PlayerList[i]->Chr->Position = data->Position; PlayerList[i]->Chr->Location = data->Location; PlayerList[i]->Chr->LastPosition = data->LastPosition; PlayerList[i]->Chr->Facing = data->Facing; PlayerList[i]->Chr->DesiredFacing = data->DesiredFacing; PlayerList[i]->Chr->CosmeticFacing = data->CosmeticFacing; PlayerList[i]->Actions1 = data->Inputs.Actions1; PlayerList[i]->Actions2 = data->Inputs.Actions2; PlayerList[i]->MouseDeltaX = data->Inputs.MouseDeltaX; PlayerList[i]->MouseDeltaY = data->Inputs.MouseDeltaY; Active = ((ActiveCharacter*)(ONrGetActiveCharacter(PlayerList[i]->Chr))); if(!Active) break; Active->PhyContext->Position = data->Position; #else PlayerList[i]->Actions1 = data->Inputs.Actions1; PlayerList[i]->Actions2 = data->Inputs.Actions2; PlayerList[i]->MouseDeltaX = data->Inputs.MouseDeltaX; PlayerList[i]->MouseDeltaY = data->Inputs.MouseDeltaY; memcpy( &(PlayerList[i]->player_data), data, sizeof(player_data) ); #endif if( !server_started && data->rare_sync_index > PlayerList[i]->rare_sync_index ) { int sent_bytes; flatline_packet sync_request = {0}; sync_request.id = RARE_SYNC_DATA_REQUEST; sync_request.sync_request = i; DDrConsole_PrintF( "Requesting sync data for player %i, old index %u", i, PlayerList[i]->rare_sync_index); sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&sync_request, FLATLINE_HEADER + sizeof(int) ); } #if 0 TMrInstance_GetDataPtr('TRAM',data->Animation,Active->Animation); Active->AnimationFromState = data->AnimationFromState; Active->AnimationToState = data->AnimationToState; Active->AnimationType = data->AnimationType; Active->NextAnimationType = data->NextAnimationType; Active->Frame = data->Frame; Active->InterpolationCurrentFrame = data->InterpolationCurrentFrame; Active->InterpolationFromState = data->InterpolationFromState; Active->InterpolationLength = data->InterpolationLength; memcpy(Active->InterpolationStartRotations, data->InterpolationStartRotations, sizeof(Quaternion) * 19); memcpy(Active->BoneMatrices, data->BoneMatrices, sizeof(Quaternion) * 19); Active->Stitch = data->Stitch; Active->StitchHeight = data->StitchHeight; Active->StitchVelocity = data->StitchVelocity; Active->Overlay = data->Overlay; memcpy(Active->OverlayRotations, data->OverlayRotations, sizeof(Quaternion) * 19); #endif //Active->animationtype2 = data->AnimationType2; /* if((int)*((char*)(Active + 0x1AF8) + 0x166) > data->Frame + 1) *(uint16_t *)((char*)Active + 0x1C88) = data->Frame + 1; */ break; } case RARE_SYNC_DATA: if(1) { sl_arg hax[2]; int dontuse; uint16_t i = packet.rare_sync_data.PlayerNum; if (i > max_connections) break; if( !PlayerList[i] ) break; //WEAPONS ARE DISABLED. Why? Pain in the arse to sync. packet.rare_sync_data.Inventory.Weapons[0] = NULL; packet.rare_sync_data.Inventory.Weapons[1] = NULL; packet.rare_sync_data.Inventory.Weapons[2] = NULL; // TMrInstance_GetDataPtr( 'ONCC', packet.rare_sync_data.Class, PlayerList[ i ]->Chr->ONCC ); //add the target character hax[0].type = sl_int32; hax[0].value_int32 = PlayerList[ packet.rare_sync_data.PlayerNum ]->spawnnumber; //add the new class //fix this later so we cant buffer overflow :O hax[1].type = sl_str32; hax[1].value_str32 = packet.rare_sync_data.Class; //we are directly calling a bsl function instead of using the normal method for two reasons //1. it has all the checking built in iSetCharacterClass( 0, 2, hax, &dontuse, &dontuse, hax ); //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); memcpy( &(PlayerList[ i ]->Chr->Inventory), &(packet.rare_sync_data.Inventory), sizeof(Inventory )); PlayerList[i]->rare_sync_index = packet.rare_sync_data.index; } break; default: DDrConsole_PrintF("Warning, recieved badly formed packet!"); break; } } else { Sleep(1); } } } return true; } //wtf, this needs cleaned up... player_info *FLr_FindEmptySlot() { int j; for(j = 0; j < MAX_PLAYERS; j++) { if (Players[j].ip == 0) { return &Players[j]; } } return 0; } extern uint16_t max_connections; uint16_t FLr_FindEmptyListSlot() { int j; for(j = 0; j < max_connections; j++) { if (PlayerList[j] == 0) { return j; } } return -1; } typedef struct { uint16_t x; uint16_t y; } IMtPoint2D; static flatline_packet cache_input = {0}; extern void* TSrTest; void * ONICALL FLrInput_Update_Keys(void) { uint16_t i; /*DDrConsole_PrintF("Current: %x %x | Start: %x %x | Stop: %x %x | Stopped %x %x", ONgGameState->Input.Current.Actions1, ONgGameState->Input.Current.Actions2, ONgGameState->Input.Start.Actions1,ONgGameState->Input.Start.Actions2, ONgGameState->Input.Stop.Actions1, ONgGameState->Input.Stop.Actions2, ONgGameState->Input.Stopped.Actions2, ONgGameState->Input.Stopped.Actions2 ); */ ActiveCharacter * Active_Player = ONgGameState->ActiveCharacters; Active_Player->PhyContext->Rotation; Active_Player->PhyContext->Position; ONgGameState->PlayerCharacter->Position; /* if( ONgGameState->Input.MouseDeltaX != 0 || ONgGameState->Input.MouseDeltaY != 0 || ONgGameState->Input.field_8 != 0 || ONgGameState->Input.field_C != 0 ) DDrConsole_PrintF("%f %f | %f %f", ONgGameState->Input.MouseDeltaX , ONgGameState->Input.MouseDeltaY, ONgGameState->Input.field_8, ONgGameState->Input.field_C); */ //if sprint timer is equal to 0, display 0 //else if sprint timer is equal to -1, display -1 //else display difference //good thing this is just quick an dirty debug stuff :) //basically it seems that if the difference is bigger than 15 frames, you cant dash. : / #ifndef SPAM_INPUT if(client_connected) { int sent_bytes; flatline_packet input_packet = {0}; input_packet.id = PLAYER_INPUT; input_packet.input_struct.Time = ONgGameState->GameTime; input_packet.input_struct.Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1; input_packet.input_struct.Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2; input_packet.input_struct.MouseDeltaX = ((GameState*)(ONgGameState))->Input.MouseDeltaX; input_packet.input_struct.MouseDeltaY = ((GameState*)(ONgGameState))->Input.MouseDeltaY; sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&input_packet, sizeof(input_struct) + FLATLINE_HEADER); //return ONgGameState; } #endif //Testing drawing text to the screen...this failed. Will need to get it working eventually. if( TSrTest ) { // OniRectangle TextRect = { 128, 128, 256, 256 }; IMtPoint2D Point = {50, 50}; //TSrContext_DrawText(TSrTest, "Testing woohoo", 255, 0, &Point); TSrContext_DrawText(TSrTest, "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", 255, 0, &Point); } if(!(server_started || client_connected)) return ONgGameState; for(i = 0; i < max_connections; i++) { ActiveCharacter * Active_Player; GameInput * Active_Input; if(PlayerList[i] == 0) continue; //is this right? Active_Player = (void*)ONrGetActiveCharacter( PlayerList[i]->Chr); if(Active_Player == 0) continue; Active_Input = &(Active_Player->Input); if(server_started) { player_data * data; flatline_packet data_out = {0}; //if( PlayerList[i]->Chr->Health == 0) PlayerList[i]->Chr->Health = PlayerList[i]->Chr->MaxHealth; data_out.id = PLAYER_DATA; data = (void*)&(data_out.data); data->PlayerNum = i; data->Health = PlayerList[i]->Chr->Health; data->MaxHealth = PlayerList[i]->Chr->MaxHealth; data->Position = PlayerList[i]->Chr->Position; data->Location = PlayerList[i]->Chr->Location; data->LastPosition = PlayerList[i]->Chr->LastPosition; data->Facing = PlayerList[i]->Chr->Facing; data->DesiredFacing = PlayerList[i]->Chr->DesiredFacing; data->CosmeticFacing = PlayerList[i]->Chr->CosmeticFacing; data->Position = Active_Player->PhyContext->Position; if( PlayerList[i]->OldClass != PlayerList[i]->Chr->ONCC || memcmp( &(PlayerList[i]->Inventory), &(PlayerList[i]->Chr->Inventory), sizeof(Inventory) ) ) { PlayerList[i]->OldClass = PlayerList[i]->Chr->ONCC; memcpy( &(PlayerList[i]->Inventory), &(PlayerList[i]->Chr->Inventory), sizeof(Inventory) ); PlayerList[i]->rare_sync_index++; } data->rare_sync_index = PlayerList[i]->rare_sync_index; #if 0 data->Frame = Active_Player->Frame; memcpy(data->Animation, TMrInstance_GetInstanceName(Active_Player->Animation), 32); data->AnimationToState = Active_Player->AnimationToState; data->AnimationFromState = Active_Player->AnimationFromState; data->AnimationType = Active_Player->AnimationType; data->NextAnimationType = Active_Player->NextAnimationType; data->InterpolationCurrentFrame = Active_Player->InterpolationCurrentFrame; data->InterpolationFromState = Active_Player->InterpolationFromState; data->InterpolationLength = Active_Player->InterpolationLength; memcpy(data->InterpolationStartRotations, Active_Player->InterpolationStartRotations, sizeof(Quaternion) * 19); // data->InterpolationStartRotations = Active_Player->InterpolationStartRotations; memcpy(data->BoneMatrices, Active_Player->BoneMatrices, sizeof(Quaternion) * 19); data->Stitch = Active_Player->Stitch; data->StitchHeight = Active_Player->StitchHeight; data->StitchVelocity = Active_Player->StitchVelocity; data->Overlay = Active_Player->Overlay; memcpy( data->OverlayRotations, Active_Player->OverlayRotations ,sizeof(Quaternion) * 19); #endif if(i == 0) { data->Inputs.Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1; data->Inputs.Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2; data->Inputs.MouseDeltaX = ONgGameState->Input.MouseDeltaX; data->Inputs.MouseDeltaY = ONgGameState->Input.MouseDeltaY; } else{ data->Inputs.Actions1 = PlayerList[i]->Actions1; data->Inputs.Actions2 = PlayerList[i]->Actions2; data->Inputs.MouseDeltaX = PlayerList[i]->MouseDeltaX; data->Inputs.MouseDeltaY = PlayerList[i]->MouseDeltaY; } memcpy( &(PlayerList[i]->player_data), data, sizeof(player_data) ); UDPServer_SendToAll(&data_out, sizeof(player_data) + FLATLINE_HEADER); } if( (server_started && i !=0) || (!server_started/* && i != client_slot*/) ) { //this just made sync even worse... #ifdef JITTER_FIX input_struct * New_Input = &PlayerList[i]->MouseDeltaX; input_struct * Cache_Input = &PlayerList[i]->CacheInput; Active_Input->Stop.Actions1 = ~Cache_Input->Actions1 & Active_Input->Current.Actions1; Active_Input->Stop.Actions2 = ~Cache_Input->Actions2 & Active_Input->Current.Actions2; Active_Input->Start.Actions1 = ~Active_Input->Current.Actions1 & Cache_Input->Actions1; Active_Input->Start.Actions2 = ~Active_Input->Current.Actions2 & Cache_Input->Actions2; Active_Input->Current.Actions1 = Cache_Input->Actions1; Active_Input->Current.Actions2 = Cache_Input->Actions2; Active_Input->Stopped.Actions1 = ~Active_Input->Current.Actions1; Active_Input->Stopped.Actions2 = ~Active_Input->Current.Actions2; Active_Input->MouseDeltaX = Cache_Input->MouseDeltaX; Active_Input->MouseDeltaY = Cache_Input->MouseDeltaY; memcpy( Cache_Input, New_Input, sizeof(input_struct)); #else Active_Input->Stop.Actions1 = ~PlayerList[i]->Actions1 & Active_Input->Current.Actions1; Active_Input->Stop.Actions2 = ~PlayerList[i]->Actions2 & Active_Input->Current.Actions2; Active_Input->Start.Actions1 = ~Active_Input->Current.Actions1 & PlayerList[i]->Actions1; Active_Input->Start.Actions2 = ~Active_Input->Current.Actions2 & PlayerList[i]->Actions2; Active_Input->Current.Actions1 = PlayerList[i]->Actions1; Active_Input->Current.Actions2 = PlayerList[i]->Actions2; Active_Input->Stopped.Actions1 = ~Active_Input->Current.Actions1; Active_Input->Stopped.Actions2 = ~Active_Input->Current.Actions2; Active_Input->MouseDeltaX = PlayerList[i]->MouseDeltaX; Active_Input->MouseDeltaY = PlayerList[i]->MouseDeltaY; //DDrConsole_PrintF("Timer: %i", (Active_Player->SprintTimer != 0) ? (Active_Player->SprintTimer == -1) ? -1 : (ONgGameState->GameTime - Active_Player->SprintTimer) : 0); //DDrConsole_PrintF("1E8 %u", ONgGameState->PlayerCharacter->field_1E8); /* DDrConsole_PrintF("T %u | Current: %x %x | Start: %x %x | Stop: %x %x | Stopped %x %x", PlayerList[i]->LastInputTime, Active_Input->Current.Actions1, Active_Input->Current.Actions2, Active_Input->Start.Actions1,Active_Input->Start.Actions2, Active_Input->Stop.Actions1, Active_Input->Stop.Actions2, Active_Input->Stopped.Actions1, Active_Input->Stopped.Actions2 ); */ #endif #ifdef BETTER_SYNC if( !server_started && PlayerList[i]->player_data.Health != 0) { PlayerList[i]->Chr->Health = PlayerList[i]->player_data.Health; PlayerList[i]->Chr->MaxHealth = PlayerList[i]->player_data.MaxHealth; PlayerList[i]->Chr->Position = PlayerList[i]->player_data.Position; PlayerList[i]->Chr->Location = PlayerList[i]->player_data.Location; PlayerList[i]->Chr->LastPosition = PlayerList[i]->player_data.LastPosition; PlayerList[i]->Chr->Facing = PlayerList[i]->player_data.Facing; PlayerList[i]->Chr->DesiredFacing = PlayerList[i]->player_data.DesiredFacing; PlayerList[i]->Chr->CosmeticFacing = PlayerList[i]->player_data.CosmeticFacing; PlayerList[i]->Actions1 = PlayerList[i]->player_data.Inputs.Actions1; PlayerList[i]->Actions2 = PlayerList[i]->player_data.Inputs.Actions2; PlayerList[i]->MouseDeltaX = PlayerList[i]->player_data.Inputs.MouseDeltaX; PlayerList[i]->MouseDeltaY = PlayerList[i]->player_data.Inputs.MouseDeltaY; Active_Player->PhyContext->Position = PlayerList[i]->player_data.Position; } #endif } } return ONgGameState; }