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 |
+ |
|
57 |
|
bool FLrServer_PacketCallback(char* data, int datalen, int from) |
58 |
|
{ |
59 |
|
int i, j; |
166 |
|
} |
167 |
|
case CHANGE_NAME: |
168 |
|
; //wtf, needed or i get an error. |
169 |
< |
DDrConsole_PrintF("Changing Name to: %s", packet->data); |
169 |
> |
// DDrConsole_PrintF("Changing Name to: %s", packet->data); |
170 |
|
for(i = 0; i < MAX_PLAYERS; i++) { |
171 |
< |
if(Players[i].ip == sender.sin_addr.S_un.S_addr) { |
171 |
> |
if(PlayerList[i] && PlayerList[i]->ip == sender.sin_addr.S_un.S_addr) { |
172 |
|
found_player = 1; |
173 |
|
break; |
174 |
|
} |
175 |
|
} |
176 |
< |
if(found_player == 0) return true; |
176 |
> |
if(found_player == 0) break; |
177 |
|
else { |
178 |
|
bool name_exists = 0; |
179 |
|
for(j = 0; j < MAX_PLAYERS; j++) { |
180 |
< |
if(!strcmp(packet->data, Players[j].name)) { |
180 |
> |
if(PlayerList[j] && !strcmp(packet->data, PlayerList[j]->name)) { |
181 |
|
name_exists = 1; |
182 |
|
break; |
183 |
|
} |
184 |
|
} |
185 |
|
if(!name_exists) { |
186 |
< |
char message_buffer[1024]; |
179 |
< |
sprintf(message_buffer,"%s changed their name to %s", Players[i].name, packet->data); |
180 |
< |
COrMessage_Print(message_buffer, "name_change", 0); |
181 |
< |
memcpy(Players[i].name, packet->data, 256); |
182 |
< |
|
186 |
> |
FLsUpdateName( i, packet->data ); |
187 |
|
} |
188 |
|
break; |
189 |
|
} |
196 |
|
} |
197 |
|
} |
198 |
|
|
199 |
< |
if(found_player == 0) return true; |
199 |
> |
if(found_player == 0) break; |
200 |
|
else { |
201 |
|
input_struct * packet_input = &packet->input_struct; |
202 |
|
|
220 |
|
} |
221 |
|
} |
222 |
|
|
223 |
< |
if(found_player == 0) return true; |
223 |
> |
if(found_player == 0) break; |
224 |
|
if(packet->ping != lastPingTime) |
225 |
|
{ |
226 |
|
PlayerList[i]->Ping = 999; |
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; |
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; |
362 |
|
if( !PlayerList[i] ) break; |
363 |
|
|
364 |
|
memcpy( &(PlayerList[i]->player_data), pd, sizeof(player_data) ); |
365 |
< |
|
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; |
376 |
|
sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&sync_request, FLATLINE_HEADER + sizeof(int) ); |
377 |
|
} |
378 |
|
|
379 |
< |
PlayerList[i]->DataApplied = 0; |
379 |
> |
PlayerList[i]->DataApplied = NoPass; |
380 |
|
|
381 |
|
|
382 |
|
break; |
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 |
|
} |
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 |
|
|
549 |
|
|
550 |
|
} IMtPoint2D; |
551 |
|
static flatline_packet cache_input = {0}; |
552 |
< |
enum |
531 |
< |
{ |
532 |
< |
FirstPass, |
533 |
< |
SecondPass, |
534 |
< |
NoPass, |
535 |
< |
}; |
552 |
> |
|
553 |
|
bool ShouldSendUpdate( int i, Character* Player, ActiveCharacter* Active_Player ) |
554 |
|
{ |
555 |
|
return |
561 |
|
|
562 |
|
void * ONICALL FLrInput_Update_Keys(void) |
563 |
|
{ |
564 |
< |
uint16_t i; |
564 |
> |
uint32_t i; |
565 |
|
flatline_packet all_input = {0}; |
566 |
|
int16_t InputIndex = 0; |
550 |
– |
//ActiveCharacter * Active_Player = ONgGameState->ActiveCharacters; |
567 |
|
|
568 |
|
if(client_connected) |
569 |
|
{ |
574 |
|
|
575 |
|
input_packet.id = PLAYER_INPUT; |
576 |
|
input_packet.input_struct.Time = ONgGameState->GameTime; |
561 |
– |
// ((GameState*)(ONgGameState))->Input.Current.Actions1 |= Action_Backward | Action_StepLeft; |
577 |
|
input_packet.input_struct.Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1; |
578 |
|
input_packet.input_struct.Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2; |
579 |
|
input_packet.input_struct.MouseDeltaX = ((GameState*)(ONgGameState))->Input.MouseDeltaX; |
607 |
|
Character* Player; |
608 |
|
GameInput * Active_Input; |
609 |
|
if(PlayerList[i] == 0) continue; |
610 |
+ |
|
611 |
|
Player = PlayerList[i]->Chr; |
612 |
< |
if(server_started) |
612 |
> |
Active_Player = ONrGetActiveCharacter( PlayerList[i]->Chr); |
613 |
> |
|
614 |
> |
if(!Player) |
615 |
> |
{ |
616 |
> |
DDrConsole_Print("Warning, missing Character!"); |
617 |
> |
continue; |
618 |
> |
} |
619 |
> |
if(server_started && PlayerList[i]->Chr->Health > 0 ) |
620 |
|
{ |
621 |
|
|
622 |
|
//Set up input packets |
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 |
|
} |
643 |
|
|
644 |
< |
if( Player->Health == 0) |
644 |
> |
|
645 |
> |
//Set the health properly first. |
646 |
> |
if( client_connected && PlayerList[i]->DataApplied == FirstPass ) |
647 |
> |
{ |
648 |
> |
ONrCharacter_SetHitPoints( PlayerList[i]->Chr, PlayerList[i]->player_data.Health); |
649 |
> |
} |
650 |
> |
//If the player is dead |
651 |
> |
if( PlayerList[i]->Chr->Health == 0 ) |
652 |
> |
|
653 |
|
{ |
618 |
– |
int Actions; |
654 |
|
const short TicksToRespawn = 3 * 60; |
655 |
+ |
|
656 |
+ |
//Permanently kill off dumb AI |
657 |
+ |
if(PlayerList[i]->flags & PF_SCRIPTEDAI) |
658 |
+ |
{ |
659 |
+ |
FLrPlayerDisconnect( i ); |
660 |
+ |
continue; |
661 |
+ |
} |
662 |
+ |
|
663 |
+ |
//Just to know if we have started counting off the respawn |
664 |
|
if(PlayerList[i]->state != STATE_DEAD) |
665 |
|
{ |
666 |
|
PlayerList[i]->state = STATE_DEAD; |
669 |
|
{ |
670 |
|
ONrGameState_Timer_Start( "", TicksToRespawn ); |
671 |
|
} |
628 |
– |
} |
672 |
|
|
673 |
< |
if(server_started && i == 0) |
674 |
< |
{ |
675 |
< |
Actions = ONgGameState->Input.Current.Actions1; |
676 |
< |
} |
677 |
< |
else |
635 |
< |
{ |
636 |
< |
Actions = PlayerList[i]->Actions1; |
673 |
> |
if(server_started) |
674 |
> |
{ |
675 |
> |
FLsPublic_Event( EV_KILLED, &i ); |
676 |
> |
} |
677 |
> |
|
678 |
|
} |
679 |
|
|
680 |
< |
if(PlayerList[i]->flags & PF_SCRIPTEDAI) |
680 |
> |
//Server respawning |
681 |
> |
if(server_started) |
682 |
|
{ |
683 |
< |
FLrPlayerDisconnect( i ); |
683 |
> |
int Actions; |
684 |
> |
if(i == 0) |
685 |
> |
{ |
686 |
> |
Actions = ONgGameState->Input.Current.Actions1; |
687 |
> |
} |
688 |
> |
else |
689 |
> |
{ |
690 |
> |
Actions = PlayerList[i]->Actions1; |
691 |
> |
} |
692 |
> |
|
693 |
> |
if(ONgGameState->GameTime - PlayerList[i]->DeathTime > TicksToRespawn && |
694 |
> |
(Actions & (Action_Punch | Action_Kick)) ) |
695 |
> |
{ |
696 |
> |
FLrPlayerRespawn( i ); |
697 |
> |
|
698 |
> |
FLsPublic_Event( EV_RESPAWN, &i ); |
699 |
> |
} |
700 |
> |
else |
701 |
> |
{ |
702 |
> |
continue; |
703 |
> |
} |
704 |
|
} |
705 |
< |
else if(ONgGameState->GameTime - PlayerList[i]->DeathTime < TicksToRespawn ) |
705 |
> |
else //clients?! |
706 |
|
{ |
707 |
|
continue; |
708 |
|
} |
647 |
– |
else if(Actions & (Action_Punch | Action_Kick)) |
648 |
– |
{ |
649 |
– |
FLrPlayerRespawn( i ); |
650 |
– |
} |
651 |
– |
continue; |
652 |
– |
|
653 |
– |
|
709 |
|
} |
710 |
|
|
711 |
< |
Active_Player = ONrGetActiveCharacter( PlayerList[i]->Chr); |
711 |
> |
PlayerList[i]->state = STATE_ALIVE; |
712 |
> |
|
713 |
> |
|
714 |
|
|
715 |
|
if(Active_Player == 0) continue; |
716 |
|
|
718 |
|
|
719 |
|
//Active_Player->PlayingFilm.Flags = 1; |
720 |
|
Active_Input = &(Active_Player->Input); |
721 |
< |
if(server_started) |
665 |
< |
{ |
666 |
< |
all_input.all_input[InputIndex - 1].Position = Active_Player->PhyContext->Position; |
667 |
< |
} |
721 |
> |
|
722 |
|
if(server_started && |
723 |
|
ShouldSendUpdate( i, PlayerList[i]->Chr, Active_Player) ) |
724 |
|
{ |
781 |
|
Active_Input->MouseDeltaY = PlayerList[i]->MouseDeltaY; |
782 |
|
|
783 |
|
|
784 |
< |
if( !server_started && PlayerList[i]->player_data.Health != 0) { |
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 |
< |
PlayerList[i]->Chr->Facing = PlayerList[i]->Facing; |
790 |
< |
PlayerList[i]->Chr->DesiredFacing = PlayerList[i]->DesiredFacing; |
737 |
< |
|
738 |
< |
if(*(int*)&PlayerList[i]->Chr->Position.X != 0x7f800000) |
739 |
< |
{ |
740 |
< |
Active_Player->PhyContext->Position = PlayerList[i]->Position; |
741 |
< |
} |
742 |
< |
else |
789 |
> |
//This is getting crazy. WTB new packet system |
790 |
> |
if(PlayerList[i]->NeedToSetFP) |
791 |
|
{ |
792 |
< |
int breakfast = 0; |
793 |
< |
} |
794 |
< |
/* |
795 |
< |
if(isnan(Active_Player->PhyContext->Position.Y) || |
796 |
< |
isnan(Active_Player->PhyContext->Position.X) || |
797 |
< |
isnan(Active_Player->PhyContext->Position.Z) ) |
798 |
< |
{ |
799 |
< |
//DDrConsole_PrintF("Player is NAN! %x %x", Active_Player->PhyContext->Position.Y, PlayerList[i]->Height); |
800 |
< |
DDrConsole_PrintF("Player is NAN! %x %x %x", Active_Player->PhyContext->Position.X, Active_Player->PhyContext->Position.Y, Active_Player->PhyContext->Position.Z); |
753 |
< |
//DDrConsole_PrintF("Velocity %x %x %x", Active_Player->PhyContext->Velocity.X, Active_Player->PhyContext->Velocity.Y, Active_Player->PhyContext->Velocity.Z); |
754 |
< |
|
755 |
< |
|
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 |
|
} |
757 |
– |
*/ |
802 |
|
|
803 |
|
if( PlayerList[i]->DataApplied == FirstPass ) |
804 |
|
{ |
805 |
|
PlayerList[i]->DataApplied = SecondPass; |
806 |
|
|
807 |
< |
Player->Health = PlayerList[i]->player_data.Health; |
807 |
> |
//Player->Health = PlayerList[i]->player_data.Health; |
808 |
|
PlayerList[i]->Chr->MaxHealth = PlayerList[i]->player_data.MaxHealth; |
809 |
|
|
810 |
|
} |
887 |
|
|
888 |
|
if (PlayerList[i]->player_data.throw_data.throwName[0] != 0) |
889 |
|
{ |
890 |
< |
short throwTarget = PlayerList[pd->throw_data.throwing]->spawnnumber; |
847 |
< |
if ((throwTarget != Active_Player->throwing) && |
848 |
< |
(pd->throw_data.throwFrame < 10)) |
890 |
> |
if(PlayerList[pd->throw_data.throwing]) |
891 |
|
{ |
892 |
< |
void *throw_animation; |
893 |
< |
ActiveCharacter* Target; |
894 |
< |
// get the animation |
853 |
< |
|
854 |
< |
TMrInstance_GetDataPtr( |
855 |
< |
'TRAM', |
856 |
< |
pd->throw_data.throwName, |
857 |
< |
&throw_animation); |
858 |
< |
//if (error) return; |
859 |
< |
|
860 |
< |
// set the throw target |
861 |
< |
Active_Player->ThrowTargetCharacter = &ONgGameState->CharacterStorage[throwTarget]; |
862 |
< |
Target = ONrGetActiveCharacter(Active_Player->ThrowTargetCharacter); |
863 |
< |
if ((Target->Animation != throw_animation) && |
864 |
< |
(OldAnimation != Animation) && |
865 |
< |
!(Active_Player->ThrowTargetCharacter->Flags & ONcCharacterFlag_BeingThrown)) |
892 |
> |
short throwTarget = PlayerList[pd->throw_data.throwing]->spawnnumber; |
893 |
> |
if ((throwTarget != Active_Player->throwing) && |
894 |
> |
(pd->throw_data.throwFrame < 10)) |
895 |
|
{ |
896 |
< |
// set the throw variables |
897 |
< |
Active_Player->targetThrow = throw_animation; |
898 |
< |
Active_Player->throwing = throwTarget; |
899 |
< |
|
900 |
< |
// run the throw |
901 |
< |
ONrCharacter_NewAnimationHook(Player, Active_Player); |
902 |
< |
|
903 |
< |
if (Active_Player->ThrowTargetCharacter) |
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 |
< |
Target->Frame += 2; |
914 |
< |
Target->thrownBy = Player->Number; |
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 ) |
936 |
|
|
937 |
|
//Check for character switching requests |
938 |
< |
if(server_started && PlayerList[i]->Actions1 & Action_Block && PlayerList[i]->ShapeshiftCooldown < ONgGameState->GameTime) |
938 |
> |
if(server_started && PlayerList[i]->player_data.Health != 0 && PlayerList[i]->Chr->Health != 0 && PlayerList[i]->Actions1 & Action_Block && PlayerList[i]->ShapeshiftCooldown < ONgGameState->GameTime) |
939 |
|
{ |
940 |
|
int error; |
941 |
|
|
1052 |
|
{ |
1053 |
|
TSrContext_SetShade(ScoreboardInstance, green); |
1054 |
|
} |
1055 |
< |
TSrContext_DrawText(ScoreboardInstance, PlayerList[i]->Chr->Name, 255, 0, &DrawLocation); |
1055 |
> |
TSrContext_DrawText(ScoreboardInstance, PlayerList[i]->name, 255, 0, &DrawLocation); |
1056 |
|
TSrContext_SetShade(ScoreboardInstance, white); |
1057 |
|
DrawLocation.x += 150; |
1058 |
|
sprintf(DrawString, "%i", PlayerList[i]->Chr->Damage); |