24 |
|
|
25 |
|
#define BETTER_SYNC |
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 |
– |
enum |
50 |
– |
{ |
51 |
– |
JustSpawned, |
52 |
– |
FirstPass, |
53 |
– |
SecondPass, |
54 |
– |
NoPass, |
55 |
– |
}; |
56 |
– |
|
27 |
|
bool FLrServer_PacketCallback(char* data, int datalen, int from) |
28 |
|
{ |
29 |
|
int i, j; |
71 |
|
|
72 |
|
//sending this several times to make sure it gets through. Really need to make up some form of packet tracking. |
73 |
|
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); |
74 |
> |
/* NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); |
75 |
|
NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); |
76 |
|
NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); |
77 |
|
NetTCPServer_Send((sockaddr *) &sender, (char*)&connect_recv, sizeof(connect_reply) + FLATLINE_HEADER); |
78 |
|
Sleep(100); |
79 |
< |
|
79 |
> |
*/ |
80 |
|
new_char.id = NEW_PLAYER; |
81 |
|
Char = &new_char.new_player.Character; |
82 |
|
memset(Char, 0, sizeof(CharacterObject)); |
171 |
|
input_struct * packet_input = &packet->input_struct; |
172 |
|
|
173 |
|
|
174 |
< |
PlayerList[i]->Actions1 = packet_input->Actions1; |
175 |
< |
PlayerList[i]->Actions2 = packet_input->Actions2; |
176 |
< |
PlayerList[i]->MouseDeltaX = packet_input->MouseDeltaX; |
177 |
< |
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; |
178 |
|
PlayerList[i]->LastInputTime = packet_input->Time; |
179 |
|
|
180 |
|
break; |
181 |
|
} |
212 |
– |
case RARE_SYNC_DATA_REQUEST: |
213 |
– |
DoRareSync( packet->sync_request , &sender); |
214 |
– |
break; |
182 |
|
case PK_PONG: |
183 |
|
for(i = 0; i < max_connections; i++) { |
184 |
|
if(PlayerList[i] != 0 && PlayerList[i]->ip == sender.sin_addr.S_un.S_addr) { |
245 |
|
} |
246 |
|
|
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; |
248 |
|
|
249 |
|
|
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 |
– |
} |
250 |
|
|
251 |
|
|
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 |
– |
} |
523 |
– |
|
252 |
|
//wtf, this needs cleaned up... |
253 |
|
player_info *FLr_FindEmptySlot() { |
254 |
|
int j; |
278 |
|
} IMtPoint2D; |
279 |
|
static flatline_packet cache_input = {0}; |
280 |
|
|
553 |
– |
bool ShouldSendUpdate( int i, Character* Player, ActiveCharacter* Active_Player ) |
554 |
– |
{ |
555 |
– |
return |
556 |
– |
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 |
– |
} |
281 |
|
|
282 |
|
void * ONICALL FLrInput_Update_Keys(void) |
283 |
|
{ |
307 |
|
|
308 |
|
if(!(server_started || client_connected)) return ONgGameState; |
309 |
|
|
590 |
– |
all_input.id = PK_ALL_INPUT; |
310 |
|
|
311 |
< |
if(server_started && ONgGameState->GameTime % 120 == 0) |
311 |
> |
if(server_started) |
312 |
|
{ |
313 |
< |
FLsPingAll(); |
314 |
< |
} |
313 |
> |
if(ONgGameState->GameTime % 120 == 0) |
314 |
> |
{ |
315 |
> |
FLsPingAll(); |
316 |
> |
} |
317 |
|
|
318 |
< |
if(server_started && PlayerList[0]) |
319 |
< |
{ |
320 |
< |
PlayerList[0]->Actions1 = ONgGameState->Input.Current.Actions1; |
321 |
< |
PlayerList[0]->Actions2 = ONgGameState->Input.Current.Actions2; |
322 |
< |
PlayerList[0]->MouseDeltaX = ONgGameState->Input.MouseDeltaX; |
323 |
< |
PlayerList[0]->MouseDeltaY = ONgGameState->Input.MouseDeltaY; |
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 |
|
} |
604 |
– |
|
327 |
|
for(i = 0; i < max_connections; i++) { |
328 |
|
ActiveCharacter * Active_Player; |
329 |
|
Character* Player; |
338 |
|
DDrConsole_Print("Warning, missing Character!"); |
339 |
|
continue; |
340 |
|
} |
619 |
– |
if(server_started && PlayerList[i]->Chr->Health > 0 ) |
620 |
– |
{ |
341 |
|
|
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 |
– |
} |
342 |
|
|
343 |
|
|
344 |
|
//Set the health properly first. |
345 |
< |
if( client_connected && PlayerList[i]->DataApplied == FirstPass ) |
345 |
> |
if( client_connected && DoWeUpdateThis( PlayerList[i]->UpdateFlags, PFlag_Health) ) |
346 |
|
{ |
347 |
< |
ONrCharacter_SetHitPoints( PlayerList[i]->Chr, PlayerList[i]->player_data.Health); |
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 ); |
350 |
|
} |
351 |
|
//If the player is dead |
352 |
|
if( PlayerList[i]->Chr->Health == 0 ) |
388 |
|
} |
389 |
|
else |
390 |
|
{ |
391 |
< |
Actions = PlayerList[i]->Actions1; |
391 |
> |
Actions = PlayerList[i]->InputFromClient.Actions1; |
392 |
|
} |
393 |
|
|
394 |
|
if(ONgGameState->GameTime - PlayerList[i]->DeathTime > TicksToRespawn && |
411 |
|
|
412 |
|
PlayerList[i]->state = STATE_ALIVE; |
413 |
|
|
414 |
< |
|
415 |
< |
|
416 |
< |
if(Active_Player == 0) continue; |
417 |
< |
|
418 |
< |
|
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 |
|
|
421 |
< |
//Active_Player->PlayingFilm.Flags = 1; |
720 |
< |
Active_Input = &(Active_Player->Input); |
421 |
> |
if(Active_Player == 0) continue; |
422 |
|
|
423 |
< |
if(server_started && |
723 |
< |
ShouldSendUpdate( i, PlayerList[i]->Chr, Active_Player) ) |
423 |
> |
if( client_connected && DoWeUpdateThis( PlayerList[i]->UpdateFlags, PFlag_Position) ) |
424 |
|
{ |
425 |
< |
player_data * data; |
726 |
< |
flatline_packet data_out = {0}; |
727 |
< |
|
425 |
> |
Active_Player->PhyContext->Position = PlayerList[i]->Position; |
426 |
|
|
427 |
< |
data_out.id = PLAYER_DATA; |
428 |
< |
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; |
427 |
> |
PlayerList[i]->UpdateFlags &= ~( 1 << PFlag_Position ); |
428 |
> |
} |
429 |
|
|
741 |
– |
data->UD = Active_Player->HeadPitch; |
742 |
– |
data->LR = Active_Player->HeadFacing; |
430 |
|
|
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 |
– |
} |
431 |
|
|
432 |
|
|
433 |
< |
if( PlayerList[i]->OldClass != PlayerList[i]->Chr->ONCC || memcmp( &(PlayerList[i]->Inventory), &(PlayerList[i]->Chr->Inventory), sizeof(Inventory) ) ) |
434 |
< |
{ |
435 |
< |
PlayerList[i]->OldClass = PlayerList[i]->Chr->ONCC; |
436 |
< |
memcpy( &(PlayerList[i]->Inventory), &(PlayerList[i]->Chr->Inventory), sizeof(Inventory) ); |
437 |
< |
PlayerList[i]->rare_sync_index++; |
438 |
< |
|
439 |
< |
} |
440 |
< |
|
441 |
< |
data->rare_sync_index = PlayerList[i]->rare_sync_index; |
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 |
< |
data->Ping = PlayerList[i]->Ping; |
487 |
< |
memcpy( &(PlayerList[i]->player_data), data, sizeof(player_data) ); |
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 ); |
536 |
|
|
537 |
< |
UDPServer_SendToAll(&data_out, sizeof(player_data) + FLATLINE_HEADER); |
538 |
< |
} |
537 |
> |
//Active_Player->PlayingFilm.Flags = 1; |
538 |
> |
Active_Input = &(Active_Player->Input); |
539 |
|
|
540 |
|
if( (server_started && i !=0) || !server_started ) |
541 |
|
{ |
542 |
< |
Active_Input->Stop.Actions1 = ~PlayerList[i]->Actions1 & Active_Input->Current.Actions1; |
543 |
< |
Active_Input->Stop.Actions2 = ~PlayerList[i]->Actions2 & Active_Input->Current.Actions2; |
544 |
< |
Active_Input->Start.Actions1 = ~Active_Input->Current.Actions1 & PlayerList[i]->Actions1; |
545 |
< |
Active_Input->Start.Actions2 = ~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]->Actions1; |
548 |
< |
Active_Input->Current.Actions2 = PlayerList[i]->Actions2; |
547 |
> |
Active_Input->Current.Actions1 = PlayerList[i]->Input.Actions1; |
548 |
> |
Active_Input->Current.Actions2 = PlayerList[i]->Input.Actions2; |
549 |
|
Active_Input->Stopped.Actions1 = ~Active_Input->Current.Actions1; |
550 |
|
Active_Input->Stopped.Actions2 = ~Active_Input->Current.Actions2; |
551 |
< |
Active_Input->MouseDeltaX = PlayerList[i]->MouseDeltaX; |
552 |
< |
Active_Input->MouseDeltaY = PlayerList[i]->MouseDeltaY; |
553 |
< |
|
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 |
> |
} |
554 |
|
|
555 |
|
//Check for character switching requests |
556 |
< |
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) |
557 |
|
{ |
558 |
|
int error; |
559 |
|
|
572 |
|
PlayerList[i]->ShapeshiftCooldown = ONgGameState->GameTime + 5; |
573 |
|
} |
574 |
|
*/ |
575 |
< |
if (PlayerList[i]->Actions1 & Action_Crouch) { |
575 |
> |
if (PlayerList[i]->InputFromClient.Actions1 & Action_Crouch) { |
576 |
|
Player->ONCCnumber += numClasses - 1; |
577 |
|
} |
578 |
|
else { |
593 |
|
|
594 |
|
|
595 |
|
} |
596 |
< |
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 |
> |
|
597 |
|
MultiplayerStatus.PleaseUpdateAllPlayers = 0; |
598 |
|
return ONgGameState; |
599 |
|
} |
671 |
|
sprintf(DrawString, "%i", PlayerList[i]->Chr->Damage); |
672 |
|
TSrContext_DrawText(ScoreboardInstance, DrawString, 255, 0, &DrawLocation); |
673 |
|
DrawLocation.x += 50; |
674 |
< |
sprintf(DrawString, "%i", PlayerList[i]->player_data.Ping); |
674 |
> |
sprintf(DrawString, "%i", PlayerList[i]->Ping); |
675 |
|
TSrContext_DrawText(ScoreboardInstance, DrawString, 255, 0, &DrawLocation); |
676 |
|
} |
677 |
|
} |