source: Daodan/MSVC/Flatline.c@ 568

Last change on this file since 568 was 568, checked in by gumby, 15 years ago

Updates

File size: 27.5 KB
Line 
1#include "Flatline.h"
2#include "Oni_Character.h"
3#include "Flatline_Server.h"
4//#include <sys/time.h>
5#include <time.h>
6uint32_t last1 = 0; uint32_t last2 = 0;
7player_info Players[MAX_PLAYERS] = {{0}, {0}, {0}, {0}};
8player_info * PlayerList[MAX_CONNECTIONS] = {0};
9const char * Rejection_Messages[][255] = {
10 {"Server is full"},
11 {"-2"},
12 {"-3"},
13 {"-4"},
14 {"-5"},
15};
16
17#define BETTER_SYNC
18
19void 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
41bool FLrServer_PacketCallback(char* data, int datalen, int from)
42{
43 int i, j;
44 bool found_player = 0;
45 flatline_packet * packet = (flatline_packet*)data;
46 static int recieved = 0;
47 sockaddr_in sender;
48 sender.sin_family = AF_INET;
49 sender.sin_port = htons(27777);
50 sender.sin_addr = *((struct in_addr*)(int*)&from);
51
52
53 //packet->data[datalen] = '\0';
54
55 //DDrConsole_PrintF("Packet \r%d recieved from %i", ++recieved, from);
56
57
58
59 //if data[0] != CONNECT_SEND, search in playerlist for ip address
60
61
62
63
64 switch(packet->id) {
65 flatline_packet connect_recv;
66 player_info * playah;
67 //rewrite this when we get TCP support.
68 //rewrite this before we get TCP support*
69 //the way of seeing if there is room for players sucks.
70 case CONNECT_SEND:
71 ;
72
73 connect_recv.id = CONNECT_REPLY;
74
75 //if(Players[i].ip == sender.sin_addr.S_un.S_addr) break; //needs to send an error message
76 sender.sin_addr.S_un.S_addr = htonl(sender.sin_addr.S_un.S_addr);
77 playah = FLrServer_AddPlayer(from,packet->connect_send.name, 0);
78 DDrConsole_PrintF("%s connected from %s", packet->connect_send.name, inet_ntoa(sender.sin_addr ) );
79 if(!((int)playah > -5 && (int)playah <= 0)) {
80 flatline_packet new_char = {0};
81 CharacterObject* Char;
82 connect_recv.connect_reply.goodtogo = 1;
83 connect_recv.connect_reply.player_slot = playah->list_slot;
84 DDrConsole_PrintF("Slot: %i", playah->list_slot);
85
86 //sending this several times to make sure it gets through. Really need to make up some form of packet tracking.
87 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER);
88 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER);
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 Sleep(100);
93
94 new_char.id = NEW_PLAYER;
95 Char = &new_char.new_player.Character;
96 memset(Char, 0, sizeof(CharacterObject));
97 Char->Header.Type = 'CHAR';
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;
102 sprintf(Char->OSD.Name,"%s",PlayerList[j]->name);
103
104 sprintf(Char->OSD.Class, "%s", TMrInstance_GetInstanceName(PlayerList[j]->Chr->ONCC));
105 DDrConsole_PrintF("Class %s", Char->OSD.Class );
106
107 sprintf(Char->OSD.Class, "konoko_generic");
108 NetTCPServer_Send((sockaddr *) &sender, (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER );
109 }
110
111 }
112 }
113 else {
114 //fix the error messages...
115 DDrConsole_PrintF("Server is full. :(");
116 connect_recv.connect_reply.goodtogo = 0;
117 sender.sin_addr.S_un.S_addr = htonl(sender.sin_addr.S_un.S_addr);
118 memcpy(&connect_recv.connect_reply.message,"Server is full.", sizeof("Server is full."));
119 NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(bool)*2 + FLATLINE_HEADER + sizeof("Server is full."));
120
121 }
122
123
124 break;
125 case CONNECT_REPLY:
126 break; //do nothing...a server shouldn't recieve this type of packet.
127 case MESSAGE:
128 for(i = 0; i < MAX_PLAYERS; i++) {
129 //DDrConsole_PrintF("%i : %i | %s : %s", from, Players[i].ip, inet_ntoa(*(struct in_addr*)&from), inet_ntoa(*(struct in_addr*)&(Players[i].ip)));
130 if(Players[i].ip == sender.sin_addr.S_un.S_addr) {
131 found_player = 1;
132 break;
133 }
134 }
135 if(found_player == 0) return true;
136 else {
137 char message_buffer[512] = {0};
138 flatline_packet message;
139 int message_size;
140 data[datalen] = 0;
141
142 DDrConsole_PrintF("%s: %s", Players[i].name, packet->data);
143 sprintf(message_buffer, "%s: %s", Players[i].name, packet->data);
144
145 message.id = MESSAGE;
146 message_size = sprintf(message.data, "%s", message_buffer);
147 COrMessage_Print(message_buffer, "chat", 0);
148 UDPServer_SendToAll(&message, message_size + 1 + FLATLINE_HEADER);
149 break;
150 }
151 case CHANGE_NAME:
152 ; //wtf, needed or i get an error.
153 DDrConsole_PrintF("Changing Name to: %s", packet->data);
154 for(i = 0; i < MAX_PLAYERS; i++) {
155 if(Players[i].ip == sender.sin_addr.S_un.S_addr) {
156 found_player = 1;
157 break;
158 }
159 }
160 if(found_player == 0) return true;
161 else {
162 bool name_exists = 0;
163 for(j = 0; j < MAX_PLAYERS; j++) {
164 if(!strcmp(packet->data, Players[j].name)) {
165 name_exists = 1;
166 break;
167 }
168 }
169 if(!name_exists) {
170 char message_buffer[1024];
171 sprintf(message_buffer,"%s changed their name to %s", Players[i].name, packet->data);
172 COrMessage_Print(message_buffer, "name_change", 0);
173 memcpy(Players[i].name, packet->data, 256);
174
175 }
176 break;
177 }
178 case PLAYER_INPUT:
179
180 for(i = 0; i < max_connections; i++) {
181 if(PlayerList[i] != 0 && PlayerList[i]->ip == sender.sin_addr.S_un.S_addr) {
182 found_player = 1;
183 break;
184 }
185 }
186
187 if(found_player == 0) return true;
188 else {
189 input_struct * packet_input = &packet->input_struct;
190
191
192 PlayerList[i]->Actions1 = packet_input->Actions1;
193 PlayerList[i]->Actions2 = packet_input->Actions2;
194 PlayerList[i]->MouseDeltaX = packet_input->MouseDeltaX;
195 PlayerList[i]->MouseDeltaY = packet_input->MouseDeltaY;
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;
206 }
207 return true;
208}
209
210bool FLrServer_Run()
211{
212 // Get the local hostname
213 char szHostName[255];
214 struct hostent *host_entry;
215 gethostname(szHostName, 255);
216
217 host_entry=gethostbyname(szHostName);
218 DDrConsole_PrintF("Server started at %s...", inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list));
219 return NetUDPServer_Listen(27777, FLrServer_PacketCallback);
220}
221
222 RGBA green = {0, 0xFF, 0, 0};
223 RGBA red = {0, 0, 0xFF, 0};
224 RGBA grey = {0x80,0x80,0x80,0x80};
225
226//FLrClient_Run
227//Looping function that waits for packets from the server.
228//TODO: Convert connection packet stuff to TCP
229int client_slot = 0;
230bool FLrClient_Run(flatline_packet* packet)
231{
232
233 char data[1400];
234 uint16_t len;
235 int j;
236 int sent_bytes;
237 client_connected = 0;
238
239
240 //starts the connection
241 DDrConsole_PrintF("Connecting to server %s on socket %i", inet_ntoa(address.sin_addr), client_sock);
242 sent_bytes = NetUDPSocket_Send(client_sock, (sockaddr*)&address, (char*)packet, 255);
243 if(sent_bytes == SOCKET_ERROR) {
244 NetCatchError();
245 }
246 //loops once per second waiting for a reply.
247 for(j = 0; j < CONNECTION_TIMEOUT; j++) {
248 while(NetUDPSocket_Recieve(client_sock, (sockaddr_storage *) &client_address, data, &len)){
249 packet = (flatline_packet*)data;
250 if(packet->id == CONNECT_REPLY) {
251 if(packet->connect_reply.goodtogo){
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;
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 }
267 else {
268 DDrConsole_PrintF("Connection rejected: %s", ((connect_reply*)packet->data)->message);
269 return false;
270 break;
271 }
272 }
273 }
274 if(client_connected) break;
275 DDrConsole_PrintF("Connection timing out in %i seconds...", CONNECTION_TIMEOUT - j);
276 Sleep(1000);
277 }
278 //the client timed out without recieving an error message.
279 if(!client_connected) {
280 DDrConsole_PrintColored("Connection timed out.",0,red, grey);
281 return false;
282 }
283 else
284 {
285 ActiveCharacter * Active;
286 flatline_packet packet;
287//#define SPAM_INPUT
288#ifdef SPAM_INPUT
289 struct timeval lasttime;
290 struct timeval thistime;
291 gettimeofday(&lasttime, 0);
292#endif
293 while(1) {
294#ifdef SPAM_INPUT
295 gettimeofday(&thistime, 0);
296
297 //DDrConsole_PrintF("%i.%i | %i.%i | %i.%i",lasttime.tv_sec, lasttime.tv_usec, thistime.tv_sec, thistime.tv_usec,
298 // thistime.tv_sec - lasttime.tv_sec, thistime.tv_usec - lasttime.tv_usec);
299 //checks to see if enough time has passed since the last input update (by default once every 10ms)
300 if(
301 ((thistime.tv_sec > lasttime.tv_sec) && ((thistime.tv_usec + 1000000 - lasttime.tv_usec ) > update_rate * 1000) )
302 || ((thistime.tv_sec == lasttime.tv_sec) && ((thistime.tv_usec - lasttime.tv_usec ) > update_rate * 1000))
303 ) {
304
305 flatline_packet input_packet;
306 lasttime.tv_usec = ++thistime.tv_usec; //in case recieving packets takes less than 1 ms.
307
308 input_packet.id = PLAYER_INPUT;
309
310 if( ((GameState*)(ONgGameState))->Input.Current.Actions1 != last1 || ((GameState*)(ONgGameState))->Input.Current.Actions2 != last2) {
311 last1 =((GameState*)(ONgGameState))->Input.Current.Actions1;
312 last2 =((GameState*)(ONgGameState))->Input.Current.Actions2;
313 }
314
315 ((input_struct*)(void*)(input_packet.data))->Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1;
316 ((input_struct*)(void*)(input_packet.data))->Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2;
317 ((input_struct*)(void*)(input_packet.data))->MouseDeltaX = ((GameState*)(ONgGameState))->Input.MouseDeltaX;
318 ((input_struct*)(void*)(input_packet.data))->MouseDeltaY = ((GameState*)(ONgGameState))->Input.MouseDeltaY;
319 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&input_packet, sizeof(input_struct) + FLATLINE_HEADER);
320 //if(sent_bytes == SOCKET_ERROR) NetCatchError();
321 }
322#endif
323 if(NetUDPSocket_Recieve(client_sock, (sockaddr_storage *) &client_address, &packet, &len)) {
324 //packet = (flatline_packet*)data;
325 //DDrConsole_PrintF("Data recieved, length %i, type %i", len, ((flatline_packet*)data)->id);
326 switch(packet.id) {
327 case MESSAGE:
328 COrMessage_Print(packet.data, "chat", 0);
329 break;
330 case CONNECT_SEND:
331 ;if(1) {
332 flatline_packet connect_recv;
333 memcpy(&connect_recv.connect_reply.message,"This isn't a server!", sizeof("This isn't a server!"));
334 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&connect_recv, sizeof(bool) + FLATLINE_HEADER + sizeof("This isn't a server!"));
335 }
336 case CONNECT_REPLY:
337 break; //extra packet or something.
338 case NEW_PLAYER:
339 ;if(1) { //haxhaxhax
340 CharacterObject* Char = &(packet.new_player.Character);
341 uint32_t chr_index = 0;
342 Character* PC;
343 DDrConsole_PrintF("%i | %i", packet.new_player.Playernumber ,client_slot);
344 //Char->OSD.Options = 0;
345 if(packet.new_player.Playernumber == client_slot) {
346 PlayerList[packet.new_player.Playernumber] = &Players[0];
347 PC = (ONgGameState->PlayerCharacter);
348 Players[0].Chr = PC;
349
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);
361 break;
362 }
363 case PLAYER_DATA:
364 if(1) { //haxhaxhax
365 player_data* data = &packet.player_data;
366 uint16_t i = data->PlayerNum;
367 GameInput * Active_Input;
368 data = (void*)packet.data;
369
370 //DDrConsole_PrintF("Got data for Player %i, %x", i, PlayerList[i]);
371 if (i > max_connections) break;
372 if( !PlayerList[i] ) break;
373 //PlayerList[i]->Chr = ((GameState *)ONgGameState)->CharacterStorage;
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;
378 PlayerList[i]->Chr->Location = data->Location;
379 PlayerList[i]->Chr->LastPosition = data->LastPosition;
380 PlayerList[i]->Chr->Facing = data->Facing;
381 PlayerList[i]->Chr->DesiredFacing = data->DesiredFacing;
382 PlayerList[i]->Chr->CosmeticFacing = data->CosmeticFacing;
383 PlayerList[i]->Actions1 = data->Inputs.Actions1;
384 PlayerList[i]->Actions2 = data->Inputs.Actions2;
385 PlayerList[i]->MouseDeltaX = data->Inputs.MouseDeltaX;
386 PlayerList[i]->MouseDeltaY = data->Inputs.MouseDeltaY;
387
388 Active = ((ActiveCharacter*)(ONrGetActiveCharacter(PlayerList[i]->Chr)));
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);
412 Active->AnimationFromState = data->AnimationFromState;
413 Active->AnimationToState = data->AnimationToState;
414 Active->AnimationType = data->AnimationType;
415 Active->NextAnimationType = data->NextAnimationType;
416 Active->Frame = data->Frame;
417 Active->InterpolationCurrentFrame = data->InterpolationCurrentFrame;
418 Active->InterpolationFromState = data->InterpolationFromState;
419 Active->InterpolationLength = data->InterpolationLength;
420 memcpy(Active->InterpolationStartRotations, data->InterpolationStartRotations,
421 sizeof(Quaternion) * 19);
422 memcpy(Active->BoneMatrices, data->BoneMatrices,
423 sizeof(Quaternion) * 19);
424 Active->Stitch = data->Stitch;
425 Active->StitchHeight = data->StitchHeight;
426 Active->StitchVelocity = data->StitchVelocity;
427
428 Active->Overlay = data->Overlay;
429 memcpy(Active->OverlayRotations, data->OverlayRotations,
430 sizeof(Quaternion) * 19);
431#endif
432 //Active->animationtype2 = data->AnimationType2;
433 /*
434 if((int)*((char*)(Active + 0x1AF8) + 0x166) > data->Frame + 1)
435 *(uint16_t *)((char*)Active + 0x1C88) = data->Frame + 1;
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;
476 }
477 }
478 else {
479 Sleep(1);
480 }
481 }
482 }
483 return true;
484}
485
486//wtf, this needs cleaned up...
487player_info *FLr_FindEmptySlot() {
488 int j;
489 for(j = 0; j < MAX_PLAYERS; j++) {
490 if (Players[j].ip == 0) {
491 return &Players[j];
492 }
493 }
494 return 0;
495}
496
497extern uint16_t max_connections;
498uint16_t FLr_FindEmptyListSlot() {
499 int j;
500 for(j = 0; j < max_connections; j++) {
501 if (PlayerList[j] == 0) {
502 return j;
503 }
504 }
505 return -1;
506}
507
508static flatline_packet cache_input = {0};
509extern void* TSrTest;
510void * ONICALL FLrInput_Update_Keys(void)
511{
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 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;
539 input_packet.input_struct.MouseDeltaY = ((GameState*)(ONgGameState))->Input.MouseDeltaY;
540
541 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&input_packet, sizeof(input_struct) + FLATLINE_HEADER);
542
543 //return ONgGameState;
544 }
545#endif
546 //Testing drawing text to the screen...this failed. Will need to get it working eventually.
547 if( TSrTest )
548 {
549 OniRectangle TextRect = { 20, 20, 50, 50 };
550 TSrContext_DrawText(TSrTest, "Testing woohoo", 0xFF, 0, &TextRect);
551 }
552 if(!(server_started || client_connected)) return ONgGameState;
553
554 for(i = 0; i < max_connections; i++) {
555 ActiveCharacter * Active_Player;
556 GameInput * Active_Input;
557 if(PlayerList[i] == 0) continue;
558
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);
564 if(server_started) {
565 player_data * data;
566 flatline_packet data_out = {0};
567 data_out.id = PLAYER_DATA;
568 data = (void*)&(data_out.data);
569 data->PlayerNum = i;
570 data->Health = PlayerList[i]->Chr->Health;
571 data->MaxHealth = PlayerList[i]->Chr->MaxHealth;
572 data->Position = PlayerList[i]->Chr->Position;
573 data->Location = PlayerList[i]->Chr->Location;
574 data->LastPosition = PlayerList[i]->Chr->LastPosition;
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;
592 memcpy(data->Animation, TMrInstance_GetInstanceName(Active_Player->Animation), 32);
593 data->AnimationToState = Active_Player->AnimationToState;
594 data->AnimationFromState = Active_Player->AnimationFromState;
595 data->AnimationType = Active_Player->AnimationType;
596 data->NextAnimationType = Active_Player->NextAnimationType;
597 data->InterpolationCurrentFrame = Active_Player->InterpolationCurrentFrame;
598 data->InterpolationFromState = Active_Player->InterpolationFromState;
599 data->InterpolationLength = Active_Player->InterpolationLength;
600 memcpy(data->InterpolationStartRotations, Active_Player->InterpolationStartRotations,
601 sizeof(Quaternion) * 19);
602 // data->InterpolationStartRotations = Active_Player->InterpolationStartRotations;
603 memcpy(data->BoneMatrices, Active_Player->BoneMatrices,
604 sizeof(Quaternion) * 19);
605 data->Stitch = Active_Player->Stitch;
606 data->StitchHeight = Active_Player->StitchHeight;
607 data->StitchVelocity = Active_Player->StitchVelocity;
608
609 data->Overlay = Active_Player->Overlay;
610 memcpy( data->OverlayRotations, Active_Player->OverlayRotations
611 ,sizeof(Quaternion) * 19);
612#endif
613 if(i == 0) {
614 data->Inputs.Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1;
615 data->Inputs.Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2;
616 }
617 else{
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*/) )
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}
Note: See TracBrowser for help on using the repository browser.