6 uses g_net
, g_triggers
, Classes
, SysUtils
, md5
;
50 NET_MSG_RCON_AUTH
= 191;
51 NET_MSG_RCON_CMD
= 192;
52 NET_MSG_TIME_SYNC
= 194;
53 NET_MSG_VOTE_EVENT
= 195;
55 NET_MSG_MAP_REQUEST
= 201;
56 NET_MSG_MAP_RESPONSE
= 202;
57 NET_MSG_RES_REQUEST
= 203;
58 NET_MSG_RES_RESPONSE
= 204;
81 NET_EV_CHANGE_TEAM
= 3;
82 NET_EV_PLAYER_KICK
= 4;
83 NET_EV_PLAYER_BAN
= 5;
84 NET_EV_LMS_WARMUP
= 6;
85 NET_EV_LMS_SURVIVOR
= 7;
89 NET_EV_SCORE_MSG
= 11;
90 NET_EV_LMS_START
= 12;
95 NET_EV_KILLCOMBO
= 17;
96 NET_EV_PLAYER_TOUCH
= 18;
103 NET_VE_INPROGRESS
= 6;
110 NET_CHEAT_SUICIDE
= 1;
111 NET_CHEAT_SPECTATE
= 2;
113 NET_MAX_DIFFTIME
= 5000 div 36;
117 procedure MH_RECV_Info(C
: pTNetClient
; P
: Pointer);
118 procedure MH_RECV_Chat(C
: pTNetClient
; P
: Pointer);
119 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; P
: Pointer);
120 function MH_RECV_PlayerPos(C
: pTNetClient
; P
: Pointer): Word;
121 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; P
: Pointer);
122 procedure MH_RECV_CheatRequest(C
: pTNetClient
; P
: Pointer);
123 procedure MH_RECV_RCONPassword(C
: pTNetClient
; P
: Pointer);
124 procedure MH_RECV_RCONCommand(C
: pTNetClient
; P
: Pointer);
125 procedure MH_RECV_MapRequest(C
: pTNetClient
; P
: Pointer);
126 procedure MH_RECV_ResRequest(C
: pTNetClient
; P
: Pointer);
127 procedure MH_RECV_Vote(C
: pTNetClient
; P
: Pointer);
130 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
131 procedure MH_SEND_Info(ID
: Byte);
132 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
133 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
134 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; ID
: Integer = NET_EVERYONE
);
135 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
136 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
137 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
138 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
139 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
140 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
141 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
142 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
144 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
145 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
146 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
147 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
148 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
149 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
150 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
151 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
153 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
154 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_PanelTexture(PType
: Word; PID
: LongWord; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_PanelState(PType
: Word; PID
: LongWord; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_VoteEvent(EvType
: Byte;
170 StrArg1
: string = 'a'; StrArg2
: string = 'b';
171 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
172 ID
: Integer = NET_EVERYONE
);
174 // CLIENT MESSAGES //
177 procedure MC_RECV_Chat(P
: Pointer);
178 procedure MC_RECV_Effect(P
: Pointer);
179 procedure MC_RECV_Sound(P
: Pointer);
180 procedure MC_RECV_GameStats(P
: Pointer);
181 procedure MC_RECV_CoopStats(P
: Pointer);
182 procedure MC_RECV_GameEvent(P
: Pointer);
183 procedure MC_RECV_FlagEvent(P
: Pointer);
184 procedure MC_RECV_GameSettings(P
: Pointer);
186 function MC_RECV_PlayerCreate(P
: Pointer): Word;
187 function MC_RECV_PlayerPos(P
: Pointer): Word;
188 function MC_RECV_PlayerStats(P
: Pointer): Word;
189 function MC_RECV_PlayerDelete(P
: Pointer): Word;
190 function MC_RECV_PlayerDamage(P
: Pointer): Word;
191 function MC_RECV_PlayerDeath(P
: Pointer): Word;
192 function MC_RECV_PlayerFire(P
: Pointer): Word;
193 procedure MC_RECV_PlayerSettings(P
: Pointer);
195 procedure MC_RECV_ItemSpawn(P
: Pointer);
196 procedure MC_RECV_ItemDestroy(P
: Pointer);
198 procedure MC_RECV_PanelTexture(P
: Pointer);
199 procedure MC_RECV_PanelState(P
: Pointer);
201 procedure MC_RECV_MonsterSpawn(P
: Pointer);
202 procedure MC_RECV_MonsterPos(P
: Pointer);
203 procedure MC_RECV_MonsterState(P
: Pointer);
204 procedure MC_RECV_MonsterShot(P
: Pointer);
205 procedure MC_RECV_MonsterDelete(P
: Pointer);
207 procedure MC_RECV_CreateShot(P
: Pointer);
208 procedure MC_RECV_UpdateShot(P
: Pointer);
209 procedure MC_RECV_DeleteShot(P
: Pointer);
211 procedure MC_RECV_TriggerSound(P
: Pointer);
212 procedure MC_RECV_TriggerMusic(P
: Pointer);
214 procedure MC_RECV_TimeSync(P
: Pointer);
215 procedure MC_RECV_VoteEvent(P
: Pointer);
217 procedure MC_SEND_Info(Password
: string);
218 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
219 procedure MC_SEND_PlayerPos();
220 procedure MC_SEND_FullStateRequest();
221 procedure MC_SEND_PlayerSettings();
222 procedure MC_SEND_CheatRequest(Kind
: Byte);
223 procedure MC_SEND_RCONPassword(Password
: string);
224 procedure MC_SEND_RCONCommand(Cmd
: string);
225 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
227 procedure MC_SEND_MapRequest();
228 procedure MC_SEND_ResRequest(const resName
: AnsiString);
231 TExternalResourceInfo
= record
246 ExternalResources
: array of TExternalResourceInfo
;
249 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
250 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
255 Math
, ENet
, e_input
, e_fixedbuffer
, e_graphics
, e_log
,
256 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
257 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
258 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
271 NET_KEY_FORCEDIR
= 4096;
274 //kBytePrev: Word = 0;
275 //kDirPrev: TDirection = D_LEFT;
276 //HostGameTime: Word = 0;
283 procedure MH_RECV_Chat(C
: pTNetClient
; P
: Pointer);
291 Pl
:= g_Player_Get(PID
);
293 Txt
:= e_Raw_Read_String(P
);
294 Mode
:= e_Raw_Read_Byte(P
);
295 if (Mode
= NET_CHAT_SYSTEM
) then
296 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
297 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
298 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
301 MH_SEND_Chat(Txt
, Mode
)
303 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
306 procedure MH_RECV_Info(C
: pTNetClient
; P
: Pointer);
308 Ver
, PName
, Model
, Pw
: string;
314 Ver
:= e_Raw_Read_String(P
);
315 Pw
:= e_Raw_Read_String(P
);
316 PName
:= e_Raw_Read_String(P
);
317 Model
:= e_Raw_Read_String(P
);
318 R
:= e_Raw_Read_Byte(P
);
319 G
:= e_Raw_Read_Byte(P
);
320 B
:= e_Raw_Read_Byte(P
);
321 T
:= e_Raw_Read_Byte(P
);
323 if Ver
<> GAME_VERSION
then
325 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
326 _lc
[I_NET_DISC_VERSION
]);
327 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
331 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
333 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
335 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
336 _lc
[I_NET_DISC_BAN
]);
337 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
341 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
342 _lc
[I_NET_DISC_BAN
]);
343 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
348 if NetPassword
<> '' then
349 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
351 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
352 _lc
[I_NET_DISC_PASSWORD
]);
353 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
361 PID
:= g_Player_Create(Model
, Color
, T
, False);
362 with g_Player_Get(PID
) do
370 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
371 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
372 '] connected. Assigned player #' + IntToStr(PID
) + '.', MSG_NOTIFY
);
376 with g_Player_Get(PID
) do
380 // round in progress, don't spawn
381 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
386 FWantsInGame
:= True; // TODO: look into this later
389 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
392 for I
:= Low(NetClients
) to High(NetClients
) do
394 if NetClients
[I
].ID
= C
^.ID
then Continue
;
395 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
396 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
397 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
400 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
401 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
403 if NetUseMaster
then g_Net_Slist_Update
;
406 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; P
: Pointer);
409 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
411 C
^.RequestedFullUpdate
:= True;
416 function MH_RECV_PlayerPos(C
: pTNetClient
; P
: Pointer): Word;
425 if not gGameOn
then Exit
;
427 GT
:= e_Raw_Read_LongWord(P
);
429 Pl
:= g_Player_Get(PID
);
433 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
438 kByte
:= e_Raw_Read_Word(P
);
439 Dir
:= e_Raw_Read_Byte(P
);
440 if Direction
<> TDirection(Dir
) then
441 JustTeleported
:= False;
442 SetDirection(TDirection(Dir
));
445 if kByte
= NET_KEY_CHAT
then
447 PressKey(KEY_CHAT
, 10000);
451 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
452 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
453 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
454 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
455 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
456 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
457 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
458 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
459 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
462 // MH_SEND_PlayerPos(False, PID, C^.ID);
465 procedure MH_RECV_CheatRequest(C
: pTNetClient
; P
: Pointer);
470 Pl
:= g_Player_Get(C
^.Player
);
471 if Pl
= nil then Exit
;
473 CheatKind
:= e_Raw_Read_Byte(P
);
477 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
480 if Pl
.FSpectator
then
488 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; P
: Pointer);
496 TmpName
:= e_Raw_Read_String(P
);
497 TmpModel
:= e_Raw_Read_String(P
);
498 TmpColor
.R
:= e_Raw_Read_Byte(P
);
499 TmpColor
.G
:= e_Raw_Read_Byte(P
);
500 TmpColor
.B
:= e_Raw_Read_Byte(P
);
501 TmpTeam
:= e_Raw_Read_Byte(P
);
503 Pl
:= g_Player_Get(C
^.Player
);
504 if Pl
= nil then Exit
;
506 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
509 Pl
.SetColor(TmpColor
);
511 if Pl
.Name
<> TmpName
then
513 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
517 if TmpModel
<> Pl
.Model
.Name
then
518 Pl
.SetModel(TmpModel
);
520 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
525 procedure MH_RECV_RCONPassword(C
: pTNetClient
; P
: Pointer);
529 Pwd
:= e_Raw_Read_String(P
);
530 if not NetAllowRCON
then Exit
;
531 if Pwd
= NetRCONPassword
then
534 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
537 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
540 procedure MH_RECV_RCONCommand(C
: pTNetClient
; P
: Pointer);
544 Cmd
:= e_Raw_Read_String(P
);
545 if not NetAllowRCON
then Exit
;
546 if not C
^.RCONAuth
then
548 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
551 g_Console_Process(Cmd
);
556 procedure MH_RECV_Vote(C
: pTNetClient
; P
: Pointer);
559 Name
, Command
: string;
563 Start
:= e_Raw_Read_Byte(P
) <> 0;
564 Command
:= e_Raw_Read_String(P
);
566 Pl
:= g_Player_Get(C
^.Player
);
567 if Pl
= nil then Exit
;
572 if not g_Console_CommandBlacklisted(Command
) then
573 g_Game_StartVote(Command
, Name
);
575 else if gVoteInProgress
then
577 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
578 Need
:= Floor((NetClientCount
+1)/2.0) + 1
580 Need
:= Floor(NetClientCount
/2.0) + 1;
585 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
586 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
592 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
593 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
601 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
605 if gPlayers
<> nil then
606 for I
:= Low(gPlayers
) to High(gPlayers
) do
607 if gPlayers
[I
] <> nil then
609 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
610 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
611 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
613 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
614 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
617 if gItems
<> nil then
619 for I
:= High(gItems
) downto Low(gItems
) do
620 if gItems
[I
].Live
then
621 MH_SEND_ItemSpawn(True, I
, ID
);
624 if gMonsters
<> nil then
625 for I
:= 0 to High(gMonsters
) do
626 if gMonsters
[I
] <> nil then
627 MH_SEND_MonsterSpawn(gMonsters
[I
].UID
, ID
);
629 if gWalls
<> nil then
630 for I
:= Low(gWalls
) to High(gWalls
) do
631 if gWalls
[I
] <> nil then
635 MH_SEND_PanelState(PanelType
, I
, ID
);
637 if GetTextureCount
> 1 then
638 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
641 if gLifts
<> nil then
642 for I
:= Low(gLifts
) to High(gLifts
) do
643 if gLifts
[I
] <> nil then
645 MH_SEND_PanelState(PanelType
, I
, ID
);
647 if gRenderForegrounds
<> nil then
648 for I
:= Low(gRenderForegrounds
) to High(gRenderForegrounds
) do
649 if gRenderForegrounds
[I
] <> nil then
650 with gRenderForegrounds
[I
] do
651 if (GetTextureCount
> 1) then
652 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
653 if gRenderBackgrounds
<> nil then
654 for I
:= Low(gRenderBackgrounds
) to High(gRenderBackgrounds
) do
655 if gRenderBackgrounds
[I
] <> nil then
656 with gRenderBackgrounds
[I
] do
657 if GetTextureCount
> 1 then
658 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
659 if gWater
<> nil then
660 for I
:= Low(gWater
) to High(gWater
) do
661 if gWater
[I
] <> nil then
663 if GetTextureCount
> 1 then
664 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
665 if gAcid1
<> nil then
666 for I
:= Low(gAcid1
) to High(gAcid1
) do
667 if gAcid1
[I
] <> nil then
669 if GetTextureCount
> 1 then
670 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
671 if gAcid2
<> nil then
672 for I
:= Low(gAcid2
) to High(gAcid2
) do
673 if gAcid2
[I
] <> nil then
675 if GetTextureCount
> 1 then
676 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
677 if gSteps
<> nil then
678 for I
:= Low(gSteps
) to High(gSteps
) do
679 if gSteps
[I
] <> nil then
681 if GetTextureCount
> 1 then
682 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
684 if gTriggers
<> nil then
685 for I
:= Low(gTriggers
) to High(gTriggers
) do
686 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
687 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
690 for I
:= Low(Shots
) to High(Shots
) do
691 if Shots
[i
].ShotType
in [6, 7, 8] then
692 MH_SEND_CreateShot(i
, ID
);
694 MH_SEND_TriggerMusic(ID
);
696 MH_SEND_GameStats(ID
);
697 MH_SEND_CoopStats(ID
);
699 if gGameSettings
.GameMode
= GM_CTF
then
701 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then
702 MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
703 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then
704 MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
707 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
709 if gLMSRespawn
> LMS_RESPAWN_NONE
then
710 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
713 procedure MH_SEND_Info(ID
: Byte);
717 g_ProcessResourceStr(gMapInfo
.Map
, nil, nil, @Map
);
719 e_Buffer_Clear(@NetOut
);
721 e_Buffer_Write(@NetOut
, Byte(NET_MSG_INFO
));
722 e_Buffer_Write(@NetOut
, ID
);
723 e_Buffer_Write(@NetOut
, NetClients
[ID
].Player
);
724 e_Buffer_Write(@NetOut
, gGameSettings
.WAD
);
725 e_Buffer_Write(@NetOut
, Map
);
726 e_Buffer_Write(@NetOut
, gWADHash
);
727 e_Buffer_Write(@NetOut
, gGameSettings
.GameMode
);
728 e_Buffer_Write(@NetOut
, gGameSettings
.GoalLimit
);
729 e_Buffer_Write(@NetOut
, gGameSettings
.TimeLimit
);
730 e_Buffer_Write(@NetOut
, gGameSettings
.MaxLives
);
731 e_Buffer_Write(@NetOut
, gGameSettings
.Options
);
732 e_Buffer_Write(@NetOut
, gTime
);
734 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
737 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
743 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
744 Mode
:= NET_CHAT_PLAYER
;
747 if (Mode
= NET_CHAT_TEAM
) then
749 for i
:= Low(gPlayers
) to High(gPlayers
) do
750 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
751 (gPlayers
[i
].Team
= ID
) then
753 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
754 e_Buffer_Write(@NetOut
, Txt
);
755 e_Buffer_Write(@NetOut
, Mode
);
756 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
763 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
764 e_Buffer_Write(@NetOut
, Txt
);
765 e_Buffer_Write(@NetOut
, Mode
);
766 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
769 if Mode
= NET_CHAT_SYSTEM
then
772 if ID
= NET_EVERYONE
then
774 if Mode
= NET_CHAT_PLAYER
then
776 g_Console_Add(Txt
, True);
777 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
778 g_Sound_PlayEx('SOUND_GAME_RADIO');
781 if Mode
= NET_CHAT_TEAM
then
782 if gPlayer1
<> nil then
784 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
786 g_Console_Add(#18'[Team] '#2 + Txt
, True);
787 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
788 g_Sound_PlayEx('SOUND_GAME_RADIO');
790 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
792 g_Console_Add(#20'[Team] '#2 + Txt
, True);
793 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
794 g_Sound_PlayEx('SOUND_GAME_RADIO');
800 Name
:= g_Net_ClientName_ByID(ID
);
801 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
802 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
803 g_Sound_PlayEx('SOUND_GAME_RADIO');
807 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
809 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GFX
));
810 e_Buffer_Write(@NetOut
, Kind
);
811 e_Buffer_Write(@NetOut
, X
);
812 e_Buffer_Write(@NetOut
, Y
);
813 e_Buffer_Write(@NetOut
, Ang
);
815 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
818 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; ID
: Integer = NET_EVERYONE
);
820 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SND
));
821 e_Buffer_Write(@NetOut
, Name
);
822 e_Buffer_Write(@NetOut
, X
);
823 e_Buffer_Write(@NetOut
, Y
);
825 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
828 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
830 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
832 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHADD
));
833 e_Buffer_Write(@NetOut
, Proj
);
834 e_Buffer_Write(@NetOut
, Shots
[Proj
].ShotType
);
835 e_Buffer_Write(@NetOut
, Shots
[Proj
].Target
);
836 e_Buffer_Write(@NetOut
, Shots
[Proj
].SpawnerUID
);
837 e_Buffer_Write(@NetOut
, Shots
[Proj
].Timeout
);
838 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.X
);
839 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Y
);
840 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.X
);
841 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.Y
);
843 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
846 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
848 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
850 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHPOS
));
851 e_Buffer_Write(@NetOut
, Proj
);
852 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.X
);
853 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Y
);
854 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.X
);
855 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.Y
);
857 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
860 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
862 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHDEL
));
863 e_Buffer_Write(@NetOut
, Proj
);
864 e_Buffer_Write(@NetOut
, Byte(Loud
));
865 e_Buffer_Write(@NetOut
, X
);
866 e_Buffer_Write(@NetOut
, Y
);
868 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
871 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
873 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SCORE
));
874 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
876 e_Buffer_Write(@NetOut
, gTeamStat
[TEAM_RED
].Goals
);
877 e_Buffer_Write(@NetOut
, gTeamStat
[TEAM_BLUE
].Goals
);
880 if gGameSettings
.GameMode
= GM_COOP
then
882 e_Buffer_Write(@NetOut
, gCoopMonstersKilled
);
883 e_Buffer_Write(@NetOut
, gCoopSecretsFound
);
886 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
889 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
891 e_Buffer_Write(@NetOut
, Byte(NET_MSG_COOP
));
892 e_Buffer_Write(@NetOut
, gTotalMonsters
);
893 e_Buffer_Write(@NetOut
, gSecretsCount
);
894 e_Buffer_Write(@NetOut
, gCoopTotalMonstersKilled
);
895 e_Buffer_Write(@NetOut
, gCoopTotalSecretsFound
);
896 e_Buffer_Write(@NetOut
, gCoopTotalMonsters
);
897 e_Buffer_Write(@NetOut
, gCoopTotalSecrets
);
900 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
902 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GEVENT
));
903 e_Buffer_Write(@NetOut
, EvType
);
904 e_Buffer_Write(@NetOut
, EvNum
);
905 e_Buffer_Write(@NetOut
, EvStr
);
906 e_Buffer_Write(@NetOut
, Byte(gLastMap
));
907 e_Buffer_Write(@NetOut
, gTime
);
908 if (EvType
= NET_EV_MAPSTART
) and (Pos(':\', EvStr
) > 0) then
910 e_Buffer_Write(@NetOut
, Byte(1));
911 e_Buffer_Write(@NetOut
, gWADHash
);
913 e_Buffer_Write(@NetOut
, Byte(0));
915 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
918 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
920 e_Buffer_Write(@NetOut
, Byte(NET_MSG_FLAG
));
921 e_Buffer_Write(@NetOut
, EvType
);
922 e_Buffer_Write(@NetOut
, Flag
);
923 e_Buffer_Write(@NetOut
, Byte(Quiet
));
924 e_Buffer_Write(@NetOut
, PID
);
925 e_Buffer_Write(@NetOut
, gFlags
[Flag
].State
);
926 e_Buffer_Write(@NetOut
, gFlags
[Flag
].CaptureTime
);
927 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.X
);
928 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Y
);
929 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Vel
.X
);
930 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Vel
.Y
);
932 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
935 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
937 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GSET
));
938 e_Buffer_Write(@NetOut
, gGameSettings
.GameMode
);
939 e_Buffer_Write(@NetOut
, gGameSettings
.GoalLimit
);
940 e_Buffer_Write(@NetOut
, gGameSettings
.TimeLimit
);
941 e_Buffer_Write(@NetOut
, gGameSettings
.MaxLives
);
942 e_Buffer_Write(@NetOut
, gGameSettings
.Options
);
944 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
949 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
953 P
:= g_Player_Get(PID
);
954 if P
= nil then Exit
;
956 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLR
));
957 e_Buffer_Write(@NetOut
, PID
);
958 e_Buffer_Write(@NetOut
, P
.Name
);
960 e_Buffer_Write(@NetOut
, P
.FActualModelName
);
961 e_Buffer_Write(@NetOut
, P
.FColor
.R
);
962 e_Buffer_Write(@NetOut
, P
.FColor
.G
);
963 e_Buffer_Write(@NetOut
, P
.FColor
.B
);
964 e_Buffer_Write(@NetOut
, P
.Team
);
966 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
969 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
974 Pl
:= g_Player_Get(PID
);
975 if Pl
= nil then Exit
;
976 if Pl
.FDummy
then Exit
;
978 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRPOS
));
979 e_Buffer_Write(@NetOut
, gTime
);
980 e_Buffer_Write(@NetOut
, PID
);
986 e_Buffer_Write(@NetOut
, FPing
);
987 e_Buffer_Write(@NetOut
, FLoss
);
988 if IsKeyPressed(KEY_CHAT
) then
989 kByte
:= NET_KEY_CHAT
992 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
993 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
994 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
995 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
996 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
997 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1000 e_Buffer_Write(@NetOut
, kByte
);
1001 if Direction
= D_LEFT
then e_Buffer_Write(@NetOut
, Byte(0)) else e_Buffer_Write(@NetOut
, Byte(1));
1002 e_Buffer_Write(@NetOut
, GameX
);
1003 e_Buffer_Write(@NetOut
, GameY
);
1004 e_Buffer_Write(@NetOut
, GameVelX
);
1005 e_Buffer_Write(@NetOut
, GameVelY
);
1006 e_Buffer_Write(@NetOut
, GameAccelX
);
1007 e_Buffer_Write(@NetOut
, GameAccelY
);
1010 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1013 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1018 P
:= g_Player_Get(PID
);
1019 if P
= nil then Exit
;
1021 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSTA
));
1022 e_Buffer_Write(@NetOut
, PID
);
1026 e_Buffer_Write(@NetOut
, Byte(Live
));
1027 e_Buffer_Write(@NetOut
, Byte(GodMode
));
1028 e_Buffer_Write(@NetOut
, Health
);
1029 e_Buffer_Write(@NetOut
, Armor
);
1030 e_Buffer_Write(@NetOut
, Air
);
1031 e_Buffer_Write(@NetOut
, JetFuel
);
1032 e_Buffer_Write(@NetOut
, Lives
);
1033 e_Buffer_Write(@NetOut
, Team
);
1035 for I
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1036 e_Buffer_Write(@NetOut
, Byte(FWeapon
[I
]));
1038 for I
:= A_BULLETS
to A_CELLS
do
1039 e_Buffer_Write(@NetOut
, FAmmo
[I
]);
1041 for I
:= A_BULLETS
to A_CELLS
do
1042 e_Buffer_Write(@NetOut
, FMaxAmmo
[I
]);
1044 for I
:= MR_SUIT
to MR_MAX
do
1045 e_Buffer_Write(@NetOut
, LongWord(FMegaRulez
[I
]));
1047 e_Buffer_Write(@NetOut
, Byte(R_ITEM_BACKPACK
in FRulez
));
1048 e_Buffer_Write(@NetOut
, Byte(R_KEY_RED
in FRulez
));
1049 e_Buffer_Write(@NetOut
, Byte(R_KEY_GREEN
in FRulez
));
1050 e_Buffer_Write(@NetOut
, Byte(R_KEY_BLUE
in FRulez
));
1051 e_Buffer_Write(@NetOut
, Byte(R_BERSERK
in FRulez
));
1053 e_Buffer_Write(@NetOut
, Frags
);
1054 e_Buffer_Write(@NetOut
, Death
);
1056 e_Buffer_Write(@NetOut
, CurrWeap
);
1058 e_Buffer_Write(@NetOut
, Byte(FSpectator
));
1059 e_Buffer_Write(@NetOut
, Byte(FGhost
));
1060 e_Buffer_Write(@NetOut
, Byte(FPhysics
));
1061 e_Buffer_Write(@NetOut
, Byte(FNoRespawn
));
1062 e_Buffer_Write(@NetOut
, Byte(FJetpack
));
1065 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1068 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1070 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDMG
));
1071 e_Buffer_Write(@NetOut
, PID
);
1072 e_Buffer_Write(@NetOut
, Kind
);
1073 e_Buffer_Write(@NetOut
, Attacker
);
1074 e_Buffer_Write(@NetOut
, Value
);
1075 e_Buffer_Write(@NetOut
, VX
);
1076 e_Buffer_Write(@NetOut
, VY
);
1078 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1081 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1083 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDIE
));
1084 e_Buffer_Write(@NetOut
, PID
);
1085 e_Buffer_Write(@NetOut
, KillType
);
1086 e_Buffer_Write(@NetOut
, DeathType
);
1087 e_Buffer_Write(@NetOut
, Attacker
);
1089 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1092 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1094 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRFIRE
));
1095 e_Buffer_Write(@NetOut
, PID
);
1096 e_Buffer_Write(@NetOut
, Weapon
);
1097 e_Buffer_Write(@NetOut
, X
);
1098 e_Buffer_Write(@NetOut
, Y
);
1099 e_Buffer_Write(@NetOut
, AX
);
1100 e_Buffer_Write(@NetOut
, AY
);
1101 e_Buffer_Write(@NetOut
, ShotID
);
1103 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1106 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1108 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDEL
));
1109 e_Buffer_Write(@NetOut
, PID
);
1111 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1114 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1118 Pl
:= g_Player_Get(PID
);
1119 if Pl
= nil then Exit
;
1121 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSET
));
1122 e_Buffer_Write(@NetOut
, PID
);
1123 e_Buffer_Write(@NetOut
, Pl
.Name
);
1125 e_Buffer_Write(@NetOut
, Pl
.Model
.Name
)
1127 e_Buffer_Write(@NetOut
, Mdl
);
1128 e_Buffer_Write(@NetOut
, Pl
.FColor
.R
);
1129 e_Buffer_Write(@NetOut
, Pl
.FColor
.G
);
1130 e_Buffer_Write(@NetOut
, Pl
.FColor
.B
);
1131 e_Buffer_Write(@NetOut
, Pl
.Team
);
1133 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1138 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1140 e_Buffer_Write(@NetOut
, Byte(NET_MSG_ISPAWN
));
1141 e_Buffer_Write(@NetOut
, IID
);
1142 e_Buffer_Write(@NetOut
, Byte(Quiet
));
1143 e_Buffer_Write(@NetOut
, gItems
[IID
].ItemType
);
1144 e_Buffer_Write(@NetOut
, Byte(gItems
[IID
].Fall
));
1145 e_Buffer_Write(@NetOut
, Byte(gItems
[IID
].Respawnable
));
1146 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.X
);
1147 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.Y
);
1148 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.Vel
.X
);
1149 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.Vel
.Y
);
1151 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1154 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1156 e_Buffer_Write(@NetOut
, Byte(NET_MSG_IDEL
));
1157 e_Buffer_Write(@NetOut
, IID
);
1158 e_Buffer_Write(@NetOut
, Byte(Quiet
));
1160 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1165 procedure MH_SEND_PanelTexture(PType
: Word; PID
: LongWord; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1170 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1173 TP
:= gRenderForegrounds
[PID
];
1175 TP
:= gRenderBackgrounds
[PID
];
1190 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PTEX
));
1191 e_Buffer_Write(@NetOut
, PType
);
1192 e_Buffer_Write(@NetOut
, PID
);
1193 e_Buffer_Write(@NetOut
, FCurTexture
);
1194 e_Buffer_Write(@NetOut
, FCurFrame
);
1195 e_Buffer_Write(@NetOut
, FCurFrameCount
);
1196 e_Buffer_Write(@NetOut
, AnimLoop
);
1199 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1202 procedure MH_SEND_PanelState(PType
: Word; PID
: LongWord; ID
: Integer = NET_EVERYONE
);
1207 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1209 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
1215 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PSTATE
));
1216 e_Buffer_Write(@NetOut
, PType
);
1217 e_Buffer_Write(@NetOut
, PID
);
1218 e_Buffer_Write(@NetOut
, Byte(TP
.Enabled
));
1219 e_Buffer_Write(@NetOut
, TP
.LiftType
);
1221 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1226 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1228 if gTriggers
= nil then Exit
;
1229 if T
.Sound
= nil then Exit
;
1231 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TSOUND
));
1232 e_Buffer_Write(@NetOut
, T
.ClientID
);
1233 e_Buffer_Write(@NetOut
, Byte(T
.Sound
.IsPlaying
));
1234 e_Buffer_Write(@NetOut
, LongWord(T
.Sound
.GetPosition
));
1235 e_Buffer_Write(@NetOut
, T
.SoundPlayCount
);
1237 g_Net_Host_Send(ID
, True);
1240 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1242 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TMUSIC
));
1243 e_Buffer_Write(@NetOut
, gMusic
.Name
);
1244 e_Buffer_Write(@NetOut
, Byte(gMusic
.IsPlaying
));
1245 e_Buffer_Write(@NetOut
, LongWord(gMusic
.GetPosition
));
1246 e_Buffer_Write(@NetOut
, Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1248 g_Net_Host_Send(ID
, True);
1253 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1257 M
:= g_Monsters_Get(UID
);
1263 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSPAWN
));
1264 e_Buffer_Write(@NetOut
, UID
);
1265 e_Buffer_Write(@NetOut
, MonsterType
);
1266 e_Buffer_Write(@NetOut
, MonsterState
);
1267 e_Buffer_Write(@NetOut
, MonsterAnim
);
1268 e_Buffer_Write(@NetOut
, MonsterTargetUID
);
1269 e_Buffer_Write(@NetOut
, MonsterTargetTime
);
1270 e_Buffer_Write(@NetOut
, MonsterBehaviour
);
1271 e_Buffer_Write(@NetOut
, MonsterSleep
);
1272 e_Buffer_Write(@NetOut
, MonsterHealth
);
1273 e_Buffer_Write(@NetOut
, MonsterAmmo
);
1274 e_Buffer_Write(@NetOut
, GameX
);
1275 e_Buffer_Write(@NetOut
, GameY
);
1276 e_Buffer_Write(@NetOut
, GameVelX
);
1277 e_Buffer_Write(@NetOut
, GameVelY
);
1278 e_Buffer_Write(@NetOut
, Byte(GameDirection
));
1281 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1284 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1288 M
:= g_Monsters_Get(UID
);
1289 if M
= nil then Exit
;
1291 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MPOS
));
1292 e_Buffer_Write(@NetOut
, UID
);
1296 e_Buffer_Write(@NetOut
, GameX
);
1297 e_Buffer_Write(@NetOut
, GameY
);
1298 e_Buffer_Write(@NetOut
, GameVelX
);
1299 e_Buffer_Write(@NetOut
, GameVelY
);
1300 e_Buffer_Write(@NetOut
, Byte(GameDirection
));
1303 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1306 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1310 M
:= g_Monsters_Get(UID
);
1311 if M
= nil then Exit
;
1313 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSTATE
));
1314 e_Buffer_Write(@NetOut
, UID
);
1318 e_Buffer_Write(@NetOut
, MonsterState
);
1319 e_Buffer_Write(@NetOut
, ForcedAnim
);
1320 e_Buffer_Write(@NetOut
, MonsterTargetUID
);
1321 e_Buffer_Write(@NetOut
, MonsterTargetTime
);
1322 e_Buffer_Write(@NetOut
, MonsterSleep
);
1323 e_Buffer_Write(@NetOut
, MonsterHealth
);
1324 e_Buffer_Write(@NetOut
, MonsterAmmo
);
1325 e_Buffer_Write(@NetOut
, MonsterPain
);
1326 e_Buffer_Write(@NetOut
, Byte(AnimIsReverse
));
1329 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1332 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1334 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSHOT
));
1335 e_Buffer_Write(@NetOut
, UID
);
1336 e_Buffer_Write(@NetOut
, X
);
1337 e_Buffer_Write(@NetOut
, Y
);
1338 e_Buffer_Write(@NetOut
, VX
);
1339 e_Buffer_Write(@NetOut
, VY
);
1341 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1344 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1348 M
:= g_Monsters_Get(UID
);
1349 if M
= nil then Exit
;
1351 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MDEL
));
1352 e_Buffer_Write(@NetOut
, UID
);
1354 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1359 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1361 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TIME_SYNC
));
1362 e_Buffer_Write(@NetOut
, Time
);
1364 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1367 procedure MH_SEND_VoteEvent(EvType
: Byte;
1368 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1369 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1370 ID
: Integer = NET_EVERYONE
);
1372 e_Buffer_Write(@NetOut
, Byte(NET_MSG_VOTE_EVENT
));
1373 e_Buffer_Write(@NetOut
, EvType
);
1374 e_Buffer_Write(@NetOut
, IntArg1
);
1375 e_Buffer_Write(@NetOut
, IntArg2
);
1376 e_Buffer_Write(@NetOut
, StrArg1
);
1377 e_Buffer_Write(@NetOut
, StrArg2
);
1379 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1382 // CLIENT MESSAGES //
1386 procedure MC_RECV_Chat(P
: Pointer);
1391 Txt
:= e_Raw_Read_String(P
);
1392 Mode
:= e_Raw_Read_Byte(P
);
1394 if Mode
<> NET_CHAT_SYSTEM
then
1396 if Mode
= NET_CHAT_PLAYER
then
1398 g_Console_Add(Txt
, True);
1399 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1400 g_Sound_PlayEx('SOUND_GAME_RADIO');
1402 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1404 if gPlayer1
.Team
= TEAM_RED
then
1405 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1406 if gPlayer1
.Team
= TEAM_BLUE
then
1407 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1408 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1409 g_Sound_PlayEx('SOUND_GAME_RADIO');
1412 g_Console_Add(Txt
, True);
1415 procedure MC_RECV_Effect(P
: Pointer);
1423 if not gGameOn
then Exit
;
1424 Kind
:= e_Raw_Read_Byte(P
);
1425 X
:= e_Raw_Read_LongInt(P
);
1426 Y
:= e_Raw_Read_LongInt(P
);
1427 Ang
:= e_Raw_Read_SmallInt(P
);
1431 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1435 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1437 Anim
:= TAnimation
.Create(ID
, False, 3);
1438 g_GFX_OnceAnim(X
, Y
, Anim
);
1442 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1447 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1449 Anim
:= TAnimation
.Create(ID
, False, 6);
1450 Anim
.Blending
:= False;
1451 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1455 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1460 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1462 Anim
:= TAnimation
.Create(ID
, False, 6);
1463 Anim
.Blending
:= False;
1464 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1468 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1473 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1475 Anim
:= TAnimation
.Create(ID
, False, 4);
1476 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1483 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1485 Anim
:= TAnimation
.Create(ID
, False, 4);
1486 g_GFX_OnceAnim(X
, Y
, Anim
);
1490 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1495 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1497 Anim
:= TAnimation
.Create(ID
, False, 4);
1498 g_GFX_OnceAnim(X
, Y
, Anim
);
1502 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1506 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1509 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1513 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1514 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1519 procedure MC_RECV_Sound(P
: Pointer);
1524 Name
:= e_Raw_Read_String(P
);
1525 X
:= e_Raw_Read_LongInt(P
);
1526 Y
:= e_Raw_Read_LongInt(P
);
1527 g_Sound_PlayExAt(Name
, X
, Y
);
1530 procedure MC_RECV_CreateShot(P
: Pointer);
1532 I
, X
, Y
, XV
, YV
: Integer;
1534 Target
, Spawner
: Word;
1537 I
:= e_Raw_Read_LongInt(P
);
1538 ShType
:= e_Raw_Read_Byte(P
);
1539 Target
:= e_Raw_Read_Word(P
);
1540 Spawner
:= e_Raw_Read_Word(P
);
1541 Timeout
:= e_Raw_Read_LongWord(P
);
1542 X
:= e_Raw_Read_LongInt(P
);
1543 Y
:= e_Raw_Read_LongInt(P
);
1544 XV
:= e_Raw_Read_LongInt(P
);
1545 YV
:= e_Raw_Read_LongInt(P
);
1547 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1548 if (Shots
<> nil) and (I
<= High(Shots
)) then
1550 Shots
[I
].Timeout
:= Timeout
;
1551 //Shots[I].Target := Target; // TODO: find a use for Target later
1555 procedure MC_RECV_UpdateShot(P
: Pointer);
1557 I
, TX
, TY
, TXV
, TYV
: Integer;
1559 I
:= e_Raw_Read_LongInt(P
);
1560 TX
:= e_Raw_Read_LongInt(P
);
1561 TY
:= e_Raw_Read_LongInt(P
);
1562 TXV
:= e_Raw_Read_LongInt(P
);
1563 TYV
:= e_Raw_Read_LongInt(P
);
1565 if (Shots
<> nil) and (I
<= High(Shots
)) then
1575 procedure MC_RECV_DeleteShot(P
: Pointer);
1580 if not gGameOn
then Exit
;
1581 I
:= e_Raw_Read_LongInt(P
);
1582 L
:= (e_Raw_Read_Byte(P
) <> 0);
1583 X
:= e_Raw_Read_LongInt(P
);
1584 Y
:= e_Raw_Read_LongInt(P
);
1586 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1589 procedure MC_RECV_GameStats(P
: Pointer);
1591 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1593 gTeamStat
[TEAM_RED
].Goals
:= e_Raw_Read_SmallInt(P
);
1594 gTeamStat
[TEAM_BLUE
].Goals
:= e_Raw_Read_SmallInt(P
);
1597 if gGameSettings
.GameMode
= GM_COOP
then
1599 gCoopMonstersKilled
:= e_Raw_Read_Word(P
);
1600 gCoopSecretsFound
:= e_Raw_Read_Word(P
);
1604 procedure MC_RECV_CoopStats(P
: Pointer);
1606 gTotalMonsters
:= e_Raw_Read_LongInt(P
);
1607 gSecretsCount
:= e_Raw_Read_LongInt(P
);
1608 gCoopTotalMonstersKilled
:= e_Raw_Read_Word(P
);
1609 gCoopTotalSecretsFound
:= e_Raw_Read_Word(P
);
1610 gCoopTotalMonsters
:= e_Raw_Read_Word(P
);
1611 gCoopTotalSecrets
:= e_Raw_Read_Word(P
);
1614 procedure MC_RECV_GameEvent(P
: Pointer);
1623 i1
, i2
: TStrings_Locale
;
1627 FillChar(EvHash
, Sizeof(EvHash
), 0);
1628 EvType
:= e_Raw_Read_Byte(P
);
1629 EvNum
:= e_Raw_Read_LongInt(P
);
1630 EvStr
:= e_Raw_Read_String(P
);
1631 gLastMap
:= e_Raw_Read_Byte(P
) <> 0;
1632 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1633 gStatsPressed
:= True;
1634 EvTime
:= e_Raw_Read_LongWord(P
);
1635 BHash
:= e_Raw_Read_Byte(P
) <> 0;
1637 EvHash
:= e_Raw_Read_MD5(P
);
1645 g_Game_ClearLoading();
1646 g_Game_StopAllSounds(True);
1648 gSwitchGameMode
:= Byte(EvNum
);
1649 gGameSettings
.GameMode
:= gSwitchGameMode
;
1652 if not g_Game_StartMap(EvStr
, True) then
1654 if Pos(':\', EvStr
) = 0 then
1655 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1657 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1661 MC_SEND_FullStateRequest
;
1666 gMissionFailed
:= EvNum
<> 0;
1667 gExit
:= EXIT_ENDLEVELCUSTOM
;
1674 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1676 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1678 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1684 if EvNum
= TEAM_RED
then
1685 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1686 if EvNum
= TEAM_BLUE
then
1687 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1691 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1694 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1697 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1699 NET_EV_LMS_SURVIVOR
:
1700 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1703 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1707 pl
:= g_Player_Get(EvNum
and $FFFF);
1712 cnt
:= (EvNum
shr 16) and $FF;
1713 if Pos('w', EvStr
) = 0 then
1716 if Pos('t', EvStr
) = 0 then
1719 if Pos('-', EvStr
) = 0 then
1721 if Pos('e', EvStr
) = 0 then
1722 i1
:= I_PLAYER_SCORE_ADD_OWN
1724 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1727 if Pos('e', EvStr
) = 0 then
1728 i1
:= I_PLAYER_SCORE_SUB_OWN
1730 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1733 if Pos('r', EvStr
) > 0 then
1734 i2
:= I_PLAYER_SCORE_TO_RED
1736 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1737 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1741 if Pos('-', EvStr
) = 0 then
1742 i1
:= I_PLAYER_SCORE_ADD_TEAM
1744 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1746 if Pos('r', EvStr
) > 0 then
1747 i2
:= I_PLAYER_SCORE_RED
1749 i2
:= I_PLAYER_SCORE_BLUE
;
1750 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1755 if Pos('e', EvStr
) = 0 then
1756 i1
:= I_PLAYER_SCORE_WIN_OWN
1758 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1760 if Pos('r', EvStr
) > 0 then
1761 i2
:= I_PLAYER_SCORE_TO_RED
1763 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1764 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1770 if EvNum
= TEAM_RED
then
1771 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1772 if EvNum
= TEAM_BLUE
then
1773 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1774 if EvNum
= -TEAM_RED
then
1775 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1776 if EvNum
= -TEAM_BLUE
then
1777 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1782 g_Player_RemoveAllCorpses
;
1783 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1787 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1791 if EvNum
= TEAM_RED
then
1792 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1793 if EvNum
= TEAM_BLUE
then
1794 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1798 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1801 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1804 g_Game_Announce_KillCombo(EvNum
);
1806 NET_EV_PLAYER_TOUCH
:
1808 pl
:= g_Player_Get(EvNum
);
1816 procedure MC_RECV_FlagEvent(P
: Pointer);
1825 EvType
:= e_Raw_Read_Byte(P
);
1826 Fl
:= e_Raw_Read_Byte(P
);
1828 if Fl
= FLAG_NONE
then Exit
;
1830 Quiet
:= (e_Raw_Read_Byte(P
) <> 0);
1831 PID
:= e_Raw_Read_Word(P
);
1833 gFlags
[Fl
].State
:= e_Raw_Read_Byte(P
);
1834 gFlags
[Fl
].CaptureTime
:= e_Raw_Read_LongWord(P
);
1835 gFlags
[Fl
].Obj
.X
:= e_Raw_Read_LongInt(P
);
1836 gFlags
[Fl
].Obj
.Y
:= e_Raw_Read_LongInt(P
);
1837 gFlags
[Fl
].Obj
.Vel
.X
:= e_Raw_Read_LongInt(P
);
1838 gFlags
[Fl
].Obj
.Vel
.Y
:= e_Raw_Read_LongInt(P
);
1840 Pl
:= g_Player_Get(PID
);
1842 (EvType
<> FLAG_STATE_NORMAL
) and
1843 (EvType
<> FLAG_STATE_DROPPED
) and
1844 (EvType
<> FLAG_STATE_RETURNED
) then
1850 if Quiet
or (Pl
= nil) then Exit
;
1852 if Fl
= FLAG_RED
then
1853 s
:= _lc
[I_PLAYER_FLAG_RED
]
1855 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1857 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1860 FLAG_STATE_CAPTURED
:
1862 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1866 if Fl
= FLAG_RED
then
1867 s
:= _lc
[I_PLAYER_FLAG_RED
]
1869 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1871 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1872 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1877 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1879 if Quiet
or (Pl
= nil) then Exit
;
1881 if Fl
= FLAG_RED
then
1882 s
:= _lc
[I_PLAYER_FLAG_RED
]
1884 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1886 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1887 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1892 g_Map_ResetFlag(FLAG_RED
);
1893 g_Map_ResetFlag(FLAG_BLUE
);
1894 if Quiet
or (Pl
= nil) then Exit
;
1895 Pl
.SetFlag(FLAG_NONE
);
1897 if Fl
= FLAG_RED
then
1898 s
:= _lc
[I_PLAYER_FLAG_RED
]
1900 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1902 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1903 Insert('.', ts
, Length(ts
) + 1 - 3);
1904 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1905 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1908 FLAG_STATE_RETURNED
:
1910 g_Map_ResetFlag(Fl
);
1913 if Fl
= FLAG_RED
then
1914 s
:= _lc
[I_PLAYER_FLAG_RED
]
1916 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1918 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1923 procedure MC_RECV_GameSettings(P
: Pointer);
1925 gGameSettings
.GameMode
:= e_Raw_Read_Byte(P
);
1926 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(P
);
1927 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(P
);
1928 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(P
);
1929 gGameSettings
.Options
:= e_Raw_Read_LongWord(P
);
1934 function MC_RECV_PlayerCreate(P
: Pointer): Word;
1937 PName
, Model
: string;
1942 PID
:= e_Raw_Read_Word(P
);
1943 Pl
:= g_Player_Get(PID
);
1945 PName
:= e_Raw_Read_String(P
);
1946 Model
:= e_Raw_Read_String(P
);
1947 Color
.R
:= e_Raw_Read_Byte(P
);
1948 Color
.G
:= e_Raw_Read_Byte(P
);
1949 Color
.B
:= e_Raw_Read_Byte(P
);
1950 T
:= e_Raw_Read_Byte(P
);
1953 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
1955 if (Pl
<> nil) then Exit
;
1956 DID
:= g_Player_Create(Model
, Color
, T
, False);
1957 with g_Player_Get(DID
) do
1966 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
1967 gPlayer1
.UID
:= PID
;
1968 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
1969 gPlayer1
.ChangeTeam(T
);
1971 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
1972 gPlayer2
.UID
:= PID
;
1973 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
1974 gPlayer2
.ChangeTeam(T
);
1978 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
1979 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', MSG_NOTIFY
);
1983 function MC_RECV_PlayerPos(P
: Pointer): Word;
1990 TmpX
, TmpY
: Integer;
1994 GT
:= e_Raw_Read_LongWord(P
);
1995 if GT
< gTime
- NET_MAX_DIFFTIME
then
2002 PID
:= e_Raw_Read_Word(P
);
2003 Pl
:= g_Player_Get(PID
);
2005 if Pl
= nil then Exit
;
2011 FPing
:= e_Raw_Read_Word(P
);
2012 FLoss
:= e_Raw_Read_Byte(P
);
2013 kByte
:= e_Raw_Read_Word(P
);
2014 Dir
:= e_Raw_Read_Byte(P
);
2016 TmpX
:= e_Raw_Read_LongInt(P
);
2017 TmpY
:= e_Raw_Read_LongInt(P
);
2021 if (kByte
= NET_KEY_CHAT
) then
2022 PressKey(KEY_CHAT
, 10000)
2025 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2026 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2027 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2028 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2029 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2032 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2033 SetDirection(TDirection(Dir
));
2035 GameVelX
:= e_Raw_Read_LongInt(P
);
2036 GameVelY
:= e_Raw_Read_LongInt(P
);
2037 GameAccelX
:= e_Raw_Read_LongInt(P
);
2038 GameAccelY
:= e_Raw_Read_LongInt(P
);
2039 SetLerp(TmpX
, TmpY
);
2040 if NetForcePlayerUpdate
then Update();
2044 function MC_RECV_PlayerStats(P
: Pointer): Word;
2052 PID
:= e_Raw_Read_Word(P
);
2053 Pl
:= g_Player_Get(PID
);
2060 Live
:= (e_Raw_Read_Byte(P
) <> 0);
2061 GodMode
:= (e_Raw_Read_Byte(P
) <> 0);
2062 Health
:= e_Raw_Read_LongInt(P
);
2063 Armor
:= e_Raw_Read_LongInt(P
);
2064 Air
:= e_Raw_Read_LongInt(P
);
2065 JetFuel
:= e_Raw_Read_LongInt(P
);
2066 Lives
:= e_Raw_Read_Byte(P
);
2067 NewTeam
:= e_Raw_Read_Byte(P
);
2069 for I
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
2070 FWeapon
[I
] := (e_Raw_Read_Byte(P
) <> 0);
2072 for I
:= A_BULLETS
to A_CELLS
do
2073 FAmmo
[I
] := e_Raw_Read_Word(P
);
2075 for I
:= A_BULLETS
to A_CELLS
do
2076 FMaxAmmo
[I
] := e_Raw_Read_Word(P
);
2078 for I
:= MR_SUIT
to MR_MAX
do
2079 FMegaRulez
[I
] := e_Raw_Read_LongWord(P
);
2082 if (e_Raw_Read_Byte(P
) <> 0) then
2083 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2084 if (e_Raw_Read_Byte(P
) <> 0) then
2085 FRulez
:= FRulez
+ [R_KEY_RED
];
2086 if (e_Raw_Read_Byte(P
) <> 0) then
2087 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2088 if (e_Raw_Read_Byte(P
) <> 0) then
2089 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2090 if (e_Raw_Read_Byte(P
) <> 0) then
2091 FRulez
:= FRulez
+ [R_BERSERK
];
2093 Frags
:= e_Raw_Read_LongInt(P
);
2094 Death
:= e_Raw_Read_LongInt(P
);
2096 SetWeapon(e_Raw_Read_Byte(P
));
2098 FSpectator
:= e_Raw_Read_Byte(P
) <> 0;
2101 if Pl
= gPlayer1
then
2106 if Pl
= gPlayer2
then
2114 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2115 gPlayer1
:= g_Player_Get(gLMSPID1
);
2116 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2117 gPlayer2
:= g_Player_Get(gLMSPID2
);
2119 FGhost
:= e_Raw_Read_Byte(P
) <> 0;
2120 FPhysics
:= e_Raw_Read_Byte(P
) <> 0;
2121 FNoRespawn
:= e_Raw_Read_Byte(P
) <> 0;
2123 FJetpack
:= e_Raw_Read_Byte(P
) <> 0;
2124 if OldJet
and not FJetpack
then
2126 else if not OldJet
and FJetpack
then
2128 if Team
<> NewTeam
then
2129 Pl
.ChangeTeam(NewTeam
);
2135 function MC_RECV_PlayerDamage(P
: Pointer): Word;
2140 Attacker
, Value
: Word;
2144 if not gGameOn
then Exit
;
2145 PID
:= e_Raw_Read_Word(P
);
2146 Pl
:= g_Player_Get(PID
);
2147 if Pl
= nil then Exit
;
2149 Kind
:= e_Raw_Read_Byte(P
);
2150 Attacker
:= e_Raw_Read_Word(P
);
2151 Value
:= e_Raw_Read_Word(P
);
2152 VX
:= e_Raw_Read_Word(P
);
2153 VY
:= e_Raw_Read_Word(P
);
2156 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2161 function MC_RECV_PlayerDeath(P
: Pointer): Word;
2165 KillType
, DeathType
: Byte;
2169 if not gGameOn
then Exit
;
2170 PID
:= e_Raw_Read_Word(P
);
2171 Pl
:= g_Player_Get(PID
);
2172 if Pl
= nil then Exit
;
2174 KillType
:= e_Raw_Read_Byte(P
);
2175 DeathType
:= e_Raw_Read_Byte(P
);
2176 Attacker
:= e_Raw_Read_Word(P
);
2180 Kill(KillType
, Attacker
, DeathType
);
2185 function MC_RECV_PlayerDelete(P
: Pointer): Word;
2190 PID
:= e_Raw_Read_Word(P
);
2191 Pl
:= g_Player_Get(PID
);
2193 if Pl
= nil then Exit
;
2195 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2196 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', MSG_NOTIFY
);
2198 g_Player_Remove(PID
);
2203 function MC_RECV_PlayerFire(P
: Pointer): Word;
2208 X
, Y
, AX
, AY
: Integer;
2212 if not gGameOn
then Exit
;
2213 PID
:= e_Raw_Read_Word(P
);
2214 Pl
:= g_Player_Get(PID
);
2215 if Pl
= nil then Exit
;
2217 Weap
:= e_Raw_Read_Byte(P
);
2218 X
:= e_Raw_Read_LongInt(P
);
2219 Y
:= e_Raw_Read_LongInt(P
);
2220 AX
:= e_Raw_Read_LongInt(P
);
2221 AY
:= e_Raw_Read_LongInt(P
);
2222 SHID
:= e_Raw_Read_LongInt(P
);
2225 if Live
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2228 procedure MC_RECV_PlayerSettings(P
: Pointer);
2237 PID
:= e_Raw_Read_Word(P
);
2238 Pl
:= g_Player_Get(PID
);
2239 if Pl
= nil then Exit
;
2241 TmpName
:= e_Raw_Read_String(P
);
2242 TmpModel
:= e_Raw_Read_String(P
);
2243 TmpColor
.R
:= e_Raw_Read_Byte(P
);
2244 TmpColor
.G
:= e_Raw_Read_Byte(P
);
2245 TmpColor
.B
:= e_Raw_Read_Byte(P
);
2246 TmpTeam
:= e_Raw_Read_Byte(P
);
2248 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2250 Pl
.ChangeTeam(TmpTeam
);
2251 if gPlayer1
= Pl
then
2252 gPlayer1Settings
.Team
:= TmpTeam
;
2253 if gPlayer2
= Pl
then
2254 gPlayer2Settings
.Team
:= TmpTeam
;
2256 Pl
.SetColor(TmpColor
);
2258 if Pl
.Name
<> TmpName
then
2260 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2264 if TmpModel
<> Pl
.Model
.Name
then
2265 Pl
.SetModel(TmpModel
);
2270 procedure MC_RECV_ItemSpawn(P
: Pointer);
2274 X
, Y
, VX
, VY
: Integer;
2276 Quiet
, Fall
{, Resp}: Boolean;
2279 if not gGameOn
then Exit
;
2280 ID
:= e_Raw_Read_Word(P
);
2281 Quiet
:= e_Raw_Read_Byte(P
) <> 0;
2282 T
:= e_Raw_Read_Byte(P
);
2283 Fall
:= e_Raw_Read_Byte(P
) <> 0;
2284 {Resp :=} e_Raw_Read_Byte(P
);
2285 X
:= e_Raw_Read_LongInt(P
);
2286 Y
:= e_Raw_Read_LongInt(P
);
2287 VX
:= e_Raw_Read_LongInt(P
);
2288 VY
:= e_Raw_Read_LongInt(P
);
2290 g_Items_Create(X
, Y
, T
, Fall
, False, False, ID
);
2291 gItems
[ID
].Obj
.Vel
.X
:= VX
;
2292 gItems
[ID
].Obj
.Vel
.Y
:= VY
;
2296 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2297 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2299 Anim
:= TAnimation
.Create(AID
, False, 4);
2300 g_GFX_OnceAnim(X
+(gItems
[ID
].Obj
.Rect
.Width
div 2)-16, Y
+(gItems
[ID
].Obj
.Rect
.Height
div 2)-16, Anim
);
2306 procedure MC_RECV_ItemDestroy(P
: Pointer);
2311 if not gGameOn
then Exit
;
2312 ID
:= e_Raw_Read_Word(P
);
2313 Quiet
:= e_Raw_Read_Byte(P
) <> 0;
2314 if gItems
= nil then Exit
;
2315 if (ID
> High(gItems
)) then Exit
;
2318 if gSoundEffectsDF
then
2320 if gItems
[ID
].ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_INVUL
,
2321 ITEM_INVIS
, ITEM_MEDKIT_BLACK
, ITEM_JETPACK
] then
2322 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2323 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2325 if gItems
[ID
].ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
2326 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
2327 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
, ITEM_AMMO_BACKPACK
] then
2328 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2329 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2331 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2332 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
);
2336 if gItems
[ID
].ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_SUIT
,
2337 ITEM_MEDKIT_BLACK
, ITEM_INVUL
, ITEM_INVIS
, ITEM_JETPACK
] then
2338 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2339 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2341 if gItems
[ID
].ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
2342 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
2343 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
] then
2344 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2345 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2347 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2348 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
);
2356 procedure MC_RECV_PanelTexture(P
: Pointer);
2364 if not gGameOn
then Exit
;
2365 PType
:= e_Raw_Read_Word(P
);
2366 ID
:= e_Raw_Read_LongWord(P
);
2367 Tex
:= e_Raw_Read_LongInt(P
);
2368 Fr
:= e_Raw_Read_LongInt(P
);
2369 Cnt
:= e_Raw_Read_Byte(P
);
2370 Loop
:= e_Raw_Read_Byte(P
);
2375 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2376 if gWalls
<> nil then
2379 if gRenderForegrounds
<> nil then
2380 TP
:= gRenderForegrounds
[ID
];
2382 if gRenderBackgrounds
<> nil then
2383 TP
:= gRenderBackgrounds
[ID
];
2385 if gWater
<> nil then
2388 if gAcid1
<> nil then
2391 if gAcid2
<> nil then
2394 if gSteps
<> nil then
2402 begin // switch texture
2403 TP
.SetTexture(Tex
, Loop
);
2404 TP
.SetFrame(Fr
, Cnt
);
2405 end else // looped or non-looped animation
2406 TP
.NextTexture(Loop
);
2409 procedure MC_RECV_PanelState(P
: Pointer);
2416 if not gGameOn
then Exit
;
2417 PType
:= e_Raw_Read_Word(P
);
2418 ID
:= e_Raw_Read_LongWord(P
);
2419 E
:= (e_Raw_Read_Byte(P
) <> 0);
2420 Lift
:= e_Raw_Read_Byte(P
);
2423 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2425 g_Map_EnableWall(ID
)
2427 g_Map_DisableWall(ID
);
2429 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
2430 g_Map_SetLift(ID
, Lift
);
2436 procedure MC_RECV_TriggerSound(P
: Pointer);
2439 SPos
, SID
: LongWord;
2443 if not gGameOn
then Exit
;
2444 if gTriggers
= nil then Exit
;
2446 SID
:= e_Raw_Read_LongWord(P
);
2447 SPlaying
:= e_Raw_Read_Byte(P
) <> 0;
2448 SPos
:= e_Raw_Read_LongWord(P
);
2449 SCount
:= e_Raw_Read_LongInt(P
);
2451 for I
:= Low(gTriggers
) to High(gTriggers
) do
2452 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2453 if gTriggers
[I
].ClientID
= SID
then
2454 with gTriggers
[I
] do
2459 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0)
2461 Sound
.PlayPanVolume((Data
.Pan
-127.0)/128.0, Data
.Volume
/255.0);
2462 Sound
.SetPosition(SPos
);
2465 if Sound
.IsPlaying
then Sound
.Stop
;
2467 SoundPlayCount
:= SCount
;
2471 procedure MC_RECV_TriggerMusic(P
: Pointer);
2478 if not gGameOn
then Exit
;
2480 MName
:= e_Raw_Read_String(P
);
2481 MPlaying
:= e_Raw_Read_Byte(P
) <> 0;
2482 MPos
:= e_Raw_Read_LongWord(P
);
2483 MPaused
:= e_Raw_Read_Byte(P
) <> 0;
2487 gMusic
.SetByName(MName
);
2489 gMusic
.SetPosition(MPos
);
2490 gMusic
.SpecPause
:= MPaused
;
2493 if gMusic
.IsPlaying
then gMusic
.Stop
;
2498 procedure MC_RECV_MonsterSpawn(P
: Pointer);
2501 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2502 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2506 ID
:= e_Raw_Read_Word(P
);
2507 M
:= g_Monsters_Get(ID
);
2511 MType
:= e_Raw_Read_Byte(P
);
2512 MState
:= e_Raw_Read_Byte(P
);
2513 MAnim
:= e_Raw_Read_Byte(P
);
2514 MTarg
:= e_Raw_Read_Word(P
);
2515 MTargTime
:= e_Raw_Read_LongInt(P
);
2516 MBehav
:= e_Raw_Read_Byte(P
);
2517 MSleep
:= e_Raw_Read_LongInt(P
);
2518 MHealth
:= e_Raw_Read_LongInt(P
);
2519 MAmmo
:= e_Raw_Read_LongInt(P
);
2521 X
:= e_Raw_Read_LongInt(P
);
2522 Y
:= e_Raw_Read_LongInt(P
);
2523 VX
:= e_Raw_Read_LongInt(P
);
2524 VY
:= e_Raw_Read_LongInt(P
);
2525 MDir
:= e_Raw_Read_Byte(P
);
2527 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2528 M
:= g_Monsters_Get(ID
);
2539 MonsterAnim
:= MAnim
;
2540 MonsterTargetUID
:= MTarg
;
2541 MonsterTargetTime
:= MTargTime
;
2542 MonsterBehaviour
:= MBehav
;
2543 MonsterSleep
:= MSleep
;
2544 MonsterAmmo
:= MAmmo
;
2551 procedure MC_RECV_MonsterPos(P
: Pointer);
2556 ID
:= e_Raw_Read_Word(P
);
2557 M
:= g_Monsters_Get(ID
);
2563 GameX
:= e_Raw_Read_LongInt(P
);
2564 GameY
:= e_Raw_Read_LongInt(P
);
2565 GameVelX
:= e_Raw_Read_LongInt(P
);
2566 GameVelY
:= e_Raw_Read_LongInt(P
);
2567 GameDirection
:= TDirection(e_Raw_Read_Byte(P
));
2571 procedure MC_RECV_MonsterState(P
: Pointer);
2574 MState
, MFAnm
: Byte;
2576 AnimRevert
: Boolean;
2578 ID
:= e_Raw_Read_Word(P
);
2579 M
:= g_Monsters_Get(ID
);
2580 if M
= nil then Exit
;
2582 MState
:= e_Raw_Read_Byte(P
);
2583 MFAnm
:= e_Raw_Read_Byte(P
);
2587 MonsterTargetUID
:= e_Raw_Read_Word(P
);
2588 MonsterTargetTime
:= e_Raw_Read_LongInt(P
);
2589 MonsterSleep
:= e_Raw_Read_LongInt(P
);
2590 MonsterHealth
:= e_Raw_Read_LongInt(P
);
2591 MonsterAmmo
:= e_Raw_Read_LongInt(P
);
2592 MonsterPain
:= e_Raw_Read_LongInt(P
);
2593 AnimRevert
:= e_Raw_Read_Byte(P
) <> 0;
2594 RevertAnim(AnimRevert
);
2596 if MonsterState
<> MState
then
2598 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then
2600 if (MState
= MONSTATE_DIE
) then
2602 if (MState
= MONSTATE_PAIN
) then
2603 MakeBloodSimple(Min(200, MonsterPain
));
2604 if (MState
= MONSTATE_ATTACK
) then
2606 if (MState
= MONSTATE_DEAD
) then
2609 SetState(MState
, MFAnm
);
2614 procedure MC_RECV_MonsterShot(P
: Pointer);
2618 X
, Y
, VX
, VY
: Integer;
2620 ID
:= e_Raw_Read_Word(P
);
2622 M
:= g_Monsters_Get(ID
);
2623 if M
= nil then Exit
;
2625 X
:= e_Raw_Read_LongInt(P
);
2626 Y
:= e_Raw_Read_LongInt(P
);
2627 VX
:= e_Raw_Read_LongInt(P
);
2628 VY
:= e_Raw_Read_LongInt(P
);
2630 M
.ClientAttack(X
, Y
, VX
, VY
);
2633 procedure MC_RECV_MonsterDelete(P
: Pointer);
2638 ID
:= e_Raw_Read_Word(P
);
2639 M
:= g_Monsters_Get(ID
);
2640 if M
= nil then Exit
;
2642 gMonsters
[ID
].SetState(5);
2643 gMonsters
[ID
].MonsterRemoved
:= True;
2646 procedure MC_RECV_TimeSync(P
: Pointer);
2650 Time
:= e_Raw_Read_LongWord(P
);
2652 if gState
= STATE_INTERCUSTOM
then
2653 gServInterTime
:= Min(Time
, 255);
2656 procedure MC_RECV_VoteEvent(P
: Pointer);
2660 Int1
, Int2
: SmallInt;
2662 EvID
:= e_Raw_Read_Byte(P
);
2663 Int1
:= e_Raw_Read_SmallInt(P
);
2664 Int2
:= e_Raw_Read_SmallInt(P
);
2665 Str1
:= e_Raw_Read_String(P
);
2666 Str2
:= e_Raw_Read_String(P
);
2670 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2672 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2674 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2676 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2678 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2684 procedure MC_SEND_Info(Password
: string);
2686 e_Buffer_Clear(@NetOut
);
2688 e_Buffer_Write(@NetOut
, Byte(NET_MSG_INFO
));
2689 e_Buffer_Write(@NetOut
, GAME_VERSION
);
2690 e_Buffer_Write(@NetOut
, Password
);
2691 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Name
);
2692 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Model
);
2693 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.R
);
2694 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.G
);
2695 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.B
);
2696 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Team
);
2698 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2701 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2703 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
2704 e_Buffer_Write(@NetOut
, Txt
);
2705 e_Buffer_Write(@NetOut
, Mode
);
2707 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2710 procedure MC_SEND_PlayerPos();
2715 if not gGameOn
then Exit
;
2716 if gPlayers
= nil then Exit
;
2717 if gPlayer1
= nil then Exit
;
2720 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2722 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2723 with gGameControls
.P1Control
do
2725 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
2728 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
2731 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
2734 if (P1MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
2735 gPlayer1
.SetDirection(D_LEFT
)
2737 if (P1MoveButton
= 1) and e_KeyPressed(KeyRight
) then
2738 gPlayer1
.SetDirection(D_RIGHT
)
2740 if P1MoveButton
<> 0 then
2741 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2743 gPlayer1
.ReleaseKeys
;
2744 if P1MoveButton
= 1 then
2746 kByte
:= kByte
or NET_KEY_LEFT
;
2747 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2749 if P1MoveButton
= 2 then
2751 kByte
:= kByte
or NET_KEY_RIGHT
;
2752 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2754 if e_KeyPressed(KeyUp
) then
2756 kByte
:= kByte
or NET_KEY_UP
;
2757 gPlayer1
.PressKey(KEY_UP
, 10000);
2759 if e_KeyPressed(KeyDown
) then
2761 kByte
:= kByte
or NET_KEY_DOWN
;
2762 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2764 if e_KeyPressed(KeyJump
) then
2766 kByte
:= kByte
or NET_KEY_JUMP
;
2767 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2769 if e_KeyPressed(KeyFire
) then kByte
:= kByte
or NET_KEY_FIRE
;
2770 if e_KeyPressed(KeyOpen
) then kByte
:= kByte
or NET_KEY_OPEN
;
2771 if e_KeyPressed(KeyNextWeapon
) then kByte
:= kByte
or NET_KEY_NW
;
2772 if e_KeyPressed(KeyPrevWeapon
) then kByte
:= kByte
or NET_KEY_PW
;
2775 kByte
:= NET_KEY_CHAT
;
2777 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRPOS
));
2778 e_Buffer_Write(@NetOut
, gTime
);
2779 e_Buffer_Write(@NetOut
, kByte
);
2780 e_Buffer_Write(@NetOut
, Byte(gPlayer1
.Direction
));
2781 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2783 //kBytePrev := kByte;
2784 //kDirPrev := gPlayer1.Direction;
2787 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2789 e_Buffer_Write(@NetOut
, Byte(NET_MSG_VOTE_EVENT
));
2790 e_Buffer_Write(@NetOut
, Byte(Start
));
2791 e_Buffer_Write(@NetOut
, Command
);
2792 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2795 procedure MC_SEND_PlayerSettings();
2797 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSET
));
2798 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Name
);
2799 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Model
);
2800 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.R
);
2801 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.G
);
2802 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.B
);
2803 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Team
);
2805 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2808 procedure MC_SEND_FullStateRequest();
2810 e_Buffer_Write(@NetOut
, Byte(NET_MSG_REQFST
));
2812 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2815 procedure MC_SEND_CheatRequest(Kind
: Byte);
2817 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHEAT
));
2818 e_Buffer_Write(@NetOut
, Kind
);
2820 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2822 procedure MC_SEND_RCONPassword(Password
: string);
2824 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RCON_AUTH
));
2825 e_Buffer_Write(@NetOut
, Password
);
2827 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2829 procedure MC_SEND_RCONCommand(Cmd
: string);
2831 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RCON_CMD
));
2832 e_Buffer_Write(@NetOut
, Cmd
);
2834 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2837 // i have no idea why all this stuff is in here
2839 function ReadFile(const FileName
: TFileName
): AByte
;
2841 FileStream
: TStream
;
2844 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), MSG_NOTIFY
);
2845 fname
:= findDiskWad(FileName
);
2846 if length(fname
) = 0 then
2848 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), MSG_FATALERROR
);
2849 SetLength(Result
, 0);
2852 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), MSG_NOTIFY
);
2854 FileStream
:= openDiskFileRO(fname
);
2856 if FileStream
.Size
> 0 then
2858 SetLength(Result
, FileStream
.Size
);
2859 FileStream
.Read(Result
[0], FileStream
.Size
);
2866 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
2870 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
2871 Result
.FileData
:= ReadFile(FileName
);
2872 Result
.FileSize
:= Length(Result
.FileData
);
2874 SetLength(Result
.ExternalResources
, ResList
.Count
);
2875 for i
:=0 to ResList
.Count
-1 do
2877 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
2878 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
2882 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
2884 ResultStream
: TMemoryStream
;
2886 ResultStream
:= TMemoryStream
.Create
;
2888 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
2889 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
2890 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
2892 SetLength(bytes
, ResultStream
.Size
);
2893 ResultStream
.Seek(0, soFromBeginning
);
2894 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2899 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
2901 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
2902 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
2903 SetLength(Result
.FileData
, Result
.FileSize
);
2904 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
2907 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
2909 ResultStream
: TMemoryStream
;
2912 resCount
:= Length(MapDataMsg
.ExternalResources
);
2914 ResultStream
:= TMemoryStream
.Create
;
2916 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
2917 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
2918 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
2920 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
2921 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
2923 SetLength(bytes
, ResultStream
.Size
);
2924 ResultStream
.Seek(0, soFromBeginning
);
2925 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2930 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
2934 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
2935 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
2937 SetLength(Result
.FileData
, Result
.FileSize
);
2938 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
2940 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
2941 SetLength(Result
.ExternalResources
, resCount
);
2943 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
2946 function IsValidFileName(const S
: String): Boolean;
2948 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
2953 for I
:= 1 to Length(S
) do
2954 Result
:= Result
and (not(S
[I
] in Forbidden
));
2957 function IsValidFilePath(const S
: String): Boolean;
2962 if not IsValidFileName(S
) then exit
;
2963 if FileExists(S
) then exit
;
2964 I
:= LastDelimiter('\/', S
);
2966 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
2971 procedure MC_SEND_MapRequest();
2973 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MAP_REQUEST
));
2974 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2977 procedure MC_SEND_ResRequest(const resName
: AnsiString);
2979 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RES_REQUEST
));
2980 e_Buffer_Write(@NetOut
, resName
);
2981 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2984 procedure MH_RECV_MapRequest(C
: pTNetClient
; P
: Pointer);
2988 mapDataMsg
: TMapDataMsg
;
2990 e_WriteLog('NET: Received map request from ' +
2991 DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
2993 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
2994 peer
:= NetClients
[C
.ID
].Peer
;
2996 MapDataMsgToBytes(payload
, mapDataMsg
);
2997 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3000 mapDataMsg
.FileData
:= nil;
3001 mapDataMsg
.ExternalResources
:= nil;
3004 procedure MH_RECV_ResRequest(C
: pTNetClient
; P
: Pointer);
3009 resDataMsg
: TResDataMsg
;
3011 FileName
:= ExtractFileName(e_Raw_Read_String(P
));
3012 e_WriteLog('NET: Received res request: ' + FileName
+
3013 ' from ' + DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3015 if not IsValidFilePath(FileName
) then
3017 e_WriteLog('Invalid filename: ' + FileName
, MSG_WARNING
);
3021 peer
:= NetClients
[C
.ID
].Peer
;
3023 if gExternalResources
.IndexOf(FileName
) > -1 then
3025 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3026 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3027 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3029 ResDataMsgToBytes(payload
, resDataMsg
);
3030 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);