1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
20 uses e_msg
, g_net
, g_triggers
, Classes
, SysUtils
, md5
;
66 NET_MSG_RCON_AUTH
= 191;
67 NET_MSG_RCON_CMD
= 192;
68 NET_MSG_TIME_SYNC
= 194;
69 NET_MSG_VOTE_EVENT
= 195;
72 NET_MSG_MAP_REQUEST = 201;
73 NET_MSG_MAP_RESPONSE = 202;
74 NET_MSG_RES_REQUEST = 203;
75 NET_MSG_RES_RESPONSE = 204;
99 NET_EV_CHANGE_TEAM
= 3;
100 NET_EV_PLAYER_KICK
= 4;
101 NET_EV_PLAYER_BAN
= 5;
102 NET_EV_LMS_WARMUP
= 6;
103 NET_EV_LMS_SURVIVOR
= 7;
107 NET_EV_SCORE_MSG
= 11;
108 NET_EV_LMS_START
= 12;
110 NET_EV_TLMS_WIN
= 14;
111 NET_EV_LMS_LOSE
= 15;
112 NET_EV_LMS_DRAW
= 16;
113 NET_EV_KILLCOMBO
= 17;
114 NET_EV_PLAYER_TOUCH
= 18;
116 NET_EV_INTER_READY
= 20;
117 NET_EV_LMS_NOSPAWN
= 21;
124 NET_VE_INPROGRESS
= 6;
131 NET_CHEAT_SUICIDE
= 1;
132 NET_CHEAT_SPECTATE
= 2;
134 NET_CHEAT_DROPFLAG
= 4;
136 NET_MAX_DIFFTIME
= 5000 div 36;
140 procedure MH_MalformedPacket(C
: pTNetClient
);
141 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
143 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
146 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
147 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
148 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
149 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
150 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
151 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
152 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
153 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
156 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
157 procedure MH_SEND_Info(ID
: Byte);
158 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
189 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
190 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
191 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
193 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
194 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
196 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
197 procedure MH_SEND_VoteEvent(EvType
: Byte;
198 StrArg1
: string = 'a'; StrArg2
: string = 'b';
199 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
200 ID
: Integer = NET_EVERYONE
);
202 // CLIENT MESSAGES //
205 procedure MC_RECV_Chat(var M
: TMsg
);
206 procedure MC_RECV_Effect(var M
: TMsg
);
207 procedure MC_RECV_Sound(var M
: TMsg
);
208 procedure MC_RECV_GameStats(var M
: TMsg
);
209 procedure MC_RECV_CoopStats(var M
: TMsg
);
210 procedure MC_RECV_GameEvent(var M
: TMsg
);
211 procedure MC_RECV_FlagEvent(var M
: TMsg
);
212 procedure MC_RECV_FlagPos(var M
: TMsg
);
213 procedure MC_RECV_GameSettings(var M
: TMsg
);
215 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
216 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
217 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
218 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
219 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
220 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
221 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
222 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
224 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
225 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
226 procedure MC_RECV_ItemPos(var M
: TMsg
);
228 procedure MC_RECV_PanelTexture(var M
: TMsg
);
229 procedure MC_RECV_PanelState(var M
: TMsg
);
231 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
232 procedure MC_RECV_MonsterPos(var M
: TMsg
);
233 procedure MC_RECV_MonsterState(var M
: TMsg
);
234 procedure MC_RECV_MonsterShot(var M
: TMsg
);
235 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
237 procedure MC_RECV_CreateShot(var M
: TMsg
);
238 procedure MC_RECV_UpdateShot(var M
: TMsg
);
239 procedure MC_RECV_DeleteShot(var M
: TMsg
);
241 procedure MC_RECV_TriggerSound(var M
: TMsg
);
242 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
244 procedure MC_RECV_TimeSync(var M
: TMsg
);
245 procedure MC_RECV_VoteEvent(var M
: TMsg
);
247 procedure MC_SEND_Info(Password
: string);
248 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
249 procedure MC_SEND_PlayerPos();
250 procedure MC_SEND_FullStateRequest();
251 procedure MC_SEND_PlayerSettings();
252 procedure MC_SEND_CheatRequest(Kind
: Byte);
253 procedure MC_SEND_RCONPassword(Password
: string);
254 procedure MC_SEND_RCONCommand(Cmd
: string);
255 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
257 //procedure MC_SEND_MapRequest();
258 //procedure MC_SEND_ResRequest(const resName: AnsiString);
262 TExternalResourceInfo
= record
277 ExternalResources
: array of TExternalResourceInfo
;
280 function IsValidFileName(const S
: String): Boolean;
281 function IsValidFilePath(const S
: String): Boolean;
287 Math
, ENet
, e_input
, e_graphics
, e_log
,
288 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
289 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
290 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
293 NET_KEY_LEFT
= 1 shl 0;
294 NET_KEY_RIGHT
= 1 shl 1;
295 NET_KEY_UP
= 1 shl 2;
296 NET_KEY_DOWN
= 1 shl 3;
297 NET_KEY_JUMP
= 1 shl 4;
298 NET_KEY_FIRE
= 1 shl 5;
299 NET_KEY_OPEN
= 1 shl 6;
300 NET_KEY_CHAT
= 1 shl 7;
301 NET_KEY_FORCEDIR
= 1 shl 8;
304 //kBytePrev: Word = 0;
305 //kDirPrev: TDirection = D_LEFT;
306 //HostGameTime: Word = 0;
309 function IsValidFileName(const S
: String): Boolean;
311 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
316 for I
:= 1 to Length(S
) do
317 Result
:= Result
and (not(S
[I
] in Forbidden
));
320 function IsValidFilePath(const S
: String): Boolean;
325 if not IsValidFileName(S
) then exit
;
326 if FileExists(S
) then exit
;
327 I
:= LastDelimiter('\/', S
);
329 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
340 procedure MH_MalformedPacket(C
: pTNetClient
);
342 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
343 _lc
[I_NET_DISC_PROTOCOL
]);
344 enet_peer_disconnect(C
^.Peer
, NET_DISC_PROTOCOL
);
347 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
356 Pl
:= g_Player_Get(PID
);
360 Txt
:= M
.ReadString();
361 Mode
:= M
.ReadByte();
366 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
368 if (Mode
= NET_CHAT_SYSTEM
) then
369 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
370 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
371 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
374 MH_SEND_Chat(Txt
, Mode
)
376 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
379 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
381 Ver
, PName
, Model
, Pw
: string;
384 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
393 Ver
:= M
.ReadString();
394 Pw
:= M
.ReadString();
395 PName
:= M
.ReadString();
396 Model
:= M
.ReadString();
401 WeapSwitch
:= M
.ReadByte();
402 if (WeapSwitch
= 2) then
403 for I
:= WP_FIRST
to WP_LAST
+ 1 do
404 TmpPrefArray
[I
] := M
.ReadByte();
405 SwitchEmpty
:= M
.ReadByte();
410 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
412 if Ver
<> GAME_VERSION
then
414 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
415 _lc
[I_NET_DISC_VERSION
]);
416 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
420 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
422 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
424 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
425 _lc
[I_NET_DISC_BAN
]);
426 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
430 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
431 _lc
[I_NET_DISC_BAN
]);
432 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
437 if NetPassword
<> '' then
438 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
440 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
441 _lc
[I_NET_DISC_PASSWORD
]);
442 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
446 if (C
^.Player
<> 0) then
448 // already received info
449 g_Net_Penalize(C
, 'client info spam');
457 PID
:= g_Player_Create(Model
, Color
, T
, False);
458 with g_Player_Get(PID
) do
461 WeapSwitchMode
:= WeapSwitch
;
462 if (WeapSwitch
= 2) then
463 SetWeaponPrefs(TmpPrefArray
);
464 SwitchToEmpty
:= SwitchEmpty
;
469 C
^.WaitForFirstSpawn
:= false;
472 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
473 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
474 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
478 with g_Player_Get(PID
) do
482 // round in progress, don't spawn
483 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
484 //e_LogWritefln('spawning player with pid #%u...', [PID]);
485 //Respawn(gGameSettings.GameType = GT_SINGLE);
486 //k8: no, do not spawn a player yet, wait for "request full state" packet
490 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
491 // that is, if we'll set it to `true`, the player can be spawned after
492 // warmup time ran out, for example, regardless of the real player state.
493 // also, this seems to work only for the initial connection. further
494 // map changes could initiate resource downloading, but the player will
495 // be spawned immediately.
496 // the proper solution will require another player state, "ephemeral".
497 // the player should start any map in "ephemeral" state, and turned into
498 // real mobj only when they sent a special "i am ready" packet. this packet
499 // must be sent after receiving the full state, so the player will get a full
500 // map view before going into game.
501 FWantsInGame
:= false;
502 C
^.WaitForFirstSpawn
:= true;
505 //if not C^.WaitForFirstSpawn then
507 for I
:= Low(NetClients
) to High(NetClients
) do
509 if NetClients
[I
].ID
= C
^.ID
then Continue
;
510 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
511 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
512 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
516 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
517 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
521 //g_Net_Slist_Update;
527 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
531 if not C
.WaitForFirstSpawn
then exit
;
532 plr
:= g_Player_Get(C
^.Player
);
533 if not assigned(plr
) then exit
;
534 g_Net_Slist_ServerPlayerComes();
535 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
536 C
.WaitForFirstSpawn
:= false;
537 plr
.FNoRespawn
:= false;
538 plr
.FWantsInGame
:= true; // TODO: look into this later
540 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
543 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
548 if gLMSRespawn
> LMS_RESPAWN_NONE
then
549 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
554 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
556 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
559 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
563 C
^.RequestedFullUpdate
:= True;
569 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
582 if not gGameOn
then Exit
;
585 GT
:= M
.ReadLongWord();
590 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
593 Pl
:= g_Player_Get(PID
);
597 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
603 kByte
:= M
.ReadWord();
605 WeaponAct
:= M
.ReadByte();
606 WeaponSelect
:= M
.ReadWord();
611 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
613 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
614 if Direction
<> TDirection(Dir
) then
615 JustTeleported
:= False;
617 SetDirection(TDirection(Dir
));
620 if kByte
= NET_KEY_CHAT
then
622 PressKey(KEY_CHAT
, 10000);
626 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
627 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
628 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
629 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
630 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
631 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
632 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
636 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
638 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
639 ProcessWeaponAction(i
);
645 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
647 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
648 QueueWeaponSwitch(i
);
653 // MH_SEND_PlayerPos(False, PID, C^.ID);
656 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
663 Pl
:= g_Player_Get(C
^.Player
);
664 if Pl
= nil then Exit
;
667 CheatKind
:= M
.ReadByte();
672 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
676 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
679 if Pl
.FSpectator
then
681 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
684 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
691 if gState
<> STATE_INTERCUSTOM
then Exit
;
692 Pl
.FReady
:= not Pl
.FReady
;
695 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
696 Inc(gInterReadyCount
);
700 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
701 Dec(gInterReadyCount
);
709 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
716 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
724 TmpName
:= M
.ReadString();
725 TmpModel
:= M
.ReadString();
726 TmpColor
.R
:= M
.ReadByte();
727 TmpColor
.G
:= M
.ReadByte();
728 TmpColor
.B
:= M
.ReadByte();
729 TmpTeam
:= M
.ReadByte();
730 TmpWeapSwitch
:= M
.ReadByte();
731 if (TmpWeapSwitch
= 2) then
732 for I
:= WP_FIRST
to WP_LAST
+ 1 do
733 TmpPrefArray
[I
] := M
.ReadByte();
734 TmpSwEmpty
:= M
.ReadByte();
739 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
741 Pl
:= g_Player_Get(C
^.Player
);
742 if Pl
= nil then Exit
;
744 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
747 Pl
.SetColor(TmpColor
);
749 if Pl
.Name
<> TmpName
then
751 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
755 if TmpModel
<> Pl
.Model
.Name
then
756 Pl
.SetModel(TmpModel
);
758 if (TmpWeapSwitch
<> Pl
.WeapSwitchMode
) then
759 Pl
.WeapSwitchMode
:= TmpWeapSwitch
;
761 if (TmpWeapSwitch
= 2) then
762 Pl
.SetWeaponPrefs(TmpPrefArray
);
764 if (TmpSwEmpty
<> Pl
.SwitchToEmpty
) then
765 Pl
.SwitchToEmpty
:= TmpSwEmpty
;
766 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
771 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
778 Pwd
:= M
.ReadString();
782 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
783 if not NetAllowRCON
then Exit
;
784 if Pwd
= NetRCONPassword
then
787 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
790 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
793 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
800 Cmd
:= M
.ReadString();
804 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
805 if not NetAllowRCON
then Exit
;
806 if not C
^.RCONAuth
then
808 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
811 g_Console_Process(Cmd
);
816 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
819 Name
, Command
: string;
826 Start
:= M
.ReadByte() <> 0;
827 Command
:= M
.ReadString();
832 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
834 Pl
:= g_Player_Get(C
^.Player
);
835 if Pl
= nil then Exit
;
840 if not g_Console_CommandBlacklisted(Command
) then
841 g_Game_StartVote(Command
, Name
);
843 else if gVoteInProgress
then
845 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
846 Need
:= Floor((NetClientCount
+1)/2.0) + 1
848 Need
:= Floor(NetClientCount
/2.0) + 1;
853 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
854 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
860 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
861 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
869 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
871 function sendItemRespawn (it
: PItem
): Boolean;
873 result
:= false; // don't stop
874 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
877 function sendMonSpawn (mon
: TMonster
): Boolean;
879 result
:= false; // don't stop
880 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
883 function sendPanelState (pan
: TPanel
): Boolean;
885 result
:= false; // don't stop
886 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
887 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
893 if (ID
>= 0) and (ID
< length(NetClients
)) then
895 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
896 MH_ProcessFirstSpawn(@NetClients
[ID
]);
899 if gPlayers
<> nil then
901 for I
:= Low(gPlayers
) to High(gPlayers
) do
903 if gPlayers
[I
] <> nil then
905 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
906 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
907 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
909 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
911 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
917 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
918 g_Mons_ForEach(sendMonSpawn
);
919 g_Map_ForEachPanel(sendPanelState
);
921 if gTriggers
<> nil then
923 for I
:= Low(gTriggers
) to High(gTriggers
) do
925 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
927 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
934 for I
:= Low(Shots
) to High(Shots
) do
936 if Shots
[i
].ShotType
in [6, 7, 8] then
938 MH_SEND_CreateShot(i
, ID
);
943 MH_SEND_TriggerMusic(ID
);
945 MH_SEND_GameStats(ID
);
946 MH_SEND_CoopStats(ID
);
948 if gGameSettings
.GameMode
= GM_CTF
then
950 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
951 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
954 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
959 procedure MH_SEND_Info(ID
: Byte);
963 NetOut
.Write(Byte(NET_MSG_INFO
));
965 NetOut
.Write(NetClients
[ID
].Player
);
966 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
967 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
968 NetOut
.Write(gWADHash
);
969 NetOut
.Write(gGameSettings
.GameMode
);
970 NetOut
.Write(gGameSettings
.GoalLimit
);
971 NetOut
.Write(gGameSettings
.TimeLimit
);
972 NetOut
.Write(gGameSettings
.MaxLives
);
973 NetOut
.Write(gGameSettings
.Options
);
976 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
979 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
985 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
986 Mode
:= NET_CHAT_PLAYER
;
989 if (Mode
= NET_CHAT_TEAM
) then
991 for i
:= Low(gPlayers
) to High(gPlayers
) do
992 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
993 (gPlayers
[i
].Team
= ID
) then
995 NetOut
.Write(Byte(NET_MSG_CHAT
));
998 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
1005 NetOut
.Write(Byte(NET_MSG_CHAT
));
1008 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
1011 if Mode
= NET_CHAT_SYSTEM
then
1014 if ID
= NET_EVERYONE
then
1016 if Mode
= NET_CHAT_PLAYER
then
1018 g_Console_Add(Txt
, True);
1019 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1020 g_Game_ChatSound(b_Text_Unformat(Txt
));
1023 if Mode
= NET_CHAT_TEAM
then
1024 if gPlayer1
<> nil then
1026 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
1028 g_Console_Add(#18'[Team] '#2 + Txt
, True);
1029 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1030 g_Game_ChatSound(b_Text_Unformat(Txt
));
1032 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
1034 g_Console_Add(#20'[Team] '#2 + Txt
, True);
1035 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1036 g_Game_ChatSound(b_Text_Unformat(Txt
));
1042 Name
:= g_Net_ClientName_ByID(ID
);
1043 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1044 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1045 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1049 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1051 NetOut
.Write(Byte(NET_MSG_GFX
));
1057 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1060 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1062 NetOut
.Write(Byte(NET_MSG_SND
));
1066 NetOut
.Write(Byte(1));
1071 NetOut
.Write(Byte(0));
1073 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1076 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1078 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1080 NetOut
.Write(Byte(NET_MSG_SHADD
));
1082 NetOut
.Write(Shots
[Proj
].ShotType
);
1083 NetOut
.Write(Shots
[Proj
].Target
);
1084 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1085 NetOut
.Write(Shots
[Proj
].Timeout
);
1086 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1087 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1088 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1089 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1091 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1094 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1096 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1098 NetOut
.Write(Byte(NET_MSG_SHPOS
));
1100 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1101 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1102 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1103 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1105 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
1108 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1110 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1112 NetOut
.Write(Byte(Loud
));
1116 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1119 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1121 NetOut
.Write(Byte(NET_MSG_SCORE
));
1122 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1124 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1125 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1128 if gGameSettings
.GameMode
= GM_COOP
then
1130 NetOut
.Write(gCoopMonstersKilled
);
1131 NetOut
.Write(gCoopSecretsFound
);
1134 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1137 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1139 NetOut
.Write(Byte(NET_MSG_COOP
));
1140 NetOut
.Write(gTotalMonsters
);
1141 NetOut
.Write(gSecretsCount
);
1142 NetOut
.Write(gCoopTotalMonstersKilled
);
1143 NetOut
.Write(gCoopTotalSecretsFound
);
1144 NetOut
.Write(gCoopTotalMonsters
);
1145 NetOut
.Write(gCoopTotalSecrets
);
1148 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1150 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1151 NetOut
.Write(EvType
);
1152 NetOut
.Write(EvNum
);
1153 NetOut
.Write(EvStr
);
1154 NetOut
.Write(Byte(gLastMap
));
1155 NetOut
.Write(gTime
);
1156 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1158 NetOut
.Write(Byte(1));
1159 NetOut
.Write(gWADHash
);
1161 NetOut
.Write(Byte(0));
1163 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1166 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1168 NetOut
.Write(Byte(NET_MSG_FLAG
));
1169 NetOut
.Write(EvType
);
1171 NetOut
.Write(Byte(Quiet
));
1173 NetOut
.Write(gFlags
[Flag
].State
);
1174 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1175 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1176 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1177 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1178 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1179 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1181 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1184 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1186 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1188 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1189 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1190 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1191 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1193 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1196 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1198 NetOut
.Write(Byte(NET_MSG_GSET
));
1199 NetOut
.Write(gGameSettings
.GameMode
);
1200 NetOut
.Write(gGameSettings
.GoalLimit
);
1201 NetOut
.Write(gGameSettings
.TimeLimit
);
1202 NetOut
.Write(gGameSettings
.MaxLives
);
1203 NetOut
.Write(gGameSettings
.Options
);
1205 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1210 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1214 P
:= g_Player_Get(PID
);
1215 if P
= nil then Exit
;
1217 NetOut
.Write(Byte(NET_MSG_PLR
));
1219 NetOut
.Write(P
.Name
);
1221 NetOut
.Write(P
.FActualModelName
);
1222 NetOut
.Write(P
.FColor
.R
);
1223 NetOut
.Write(P
.FColor
.G
);
1224 NetOut
.Write(P
.FColor
.B
);
1225 NetOut
.Write(P
.Team
);
1227 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1230 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1235 Pl
:= g_Player_Get(PID
);
1236 if Pl
= nil then Exit
;
1237 if Pl
.FDummy
then Exit
;
1239 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1240 NetOut
.Write(gTime
);
1247 NetOut
.Write(FPing
);
1248 NetOut
.Write(FLoss
);
1249 if IsKeyPressed(KEY_CHAT
) then
1250 kByte
:= NET_KEY_CHAT
1253 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1254 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1255 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1256 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1257 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1260 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1262 NetOut
.Write(kByte
);
1263 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1264 NetOut
.Write(GameX
);
1265 NetOut
.Write(GameY
);
1266 NetOut
.Write(GameVelX
);
1267 NetOut
.Write(GameVelY
);
1268 NetOut
.Write(GameAccelX
);
1269 NetOut
.Write(GameAccelY
);
1272 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1275 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1280 P
:= g_Player_Get(PID
);
1281 if P
= nil then Exit
;
1283 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1288 NetOut
.Write(Byte(alive
));
1289 NetOut
.Write(Byte(GodMode
));
1290 NetOut
.Write(Health
);
1291 NetOut
.Write(Armor
);
1293 NetOut
.Write(JetFuel
);
1294 NetOut
.Write(Lives
);
1297 for I
:= WP_FIRST
to WP_LAST
do
1298 NetOut
.Write(Byte(FWeapon
[I
]));
1300 for I
:= A_BULLETS
to A_HIGH
do
1301 NetOut
.Write(FAmmo
[I
]);
1303 for I
:= A_BULLETS
to A_HIGH
do
1304 NetOut
.Write(FMaxAmmo
[I
]);
1306 for I
:= MR_SUIT
to MR_MAX
do
1307 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1309 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1310 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1311 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1312 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1313 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1315 NetOut
.Write(Frags
);
1316 NetOut
.Write(Death
);
1318 NetOut
.Write(CurrWeap
);
1320 NetOut
.Write(Byte(FSpectator
));
1321 NetOut
.Write(Byte(FGhost
));
1322 NetOut
.Write(Byte(FPhysics
));
1323 NetOut
.Write(Byte(FNoRespawn
));
1324 NetOut
.Write(Byte(FJetpack
));
1325 NetOut
.Write(FFireTime
);
1326 NetOut
.Write(Byte(FFlaming
));
1327 NetOut
.Write(FSpawnInvul
);
1330 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1333 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1335 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1338 NetOut
.Write(Attacker
);
1339 NetOut
.Write(Value
);
1343 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1346 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1348 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1350 NetOut
.Write(KillType
);
1351 NetOut
.Write(DeathType
);
1352 NetOut
.Write(Attacker
);
1354 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1357 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1359 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1361 NetOut
.Write(Weapon
);
1366 NetOut
.Write(ShotID
);
1368 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1371 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1373 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1376 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1379 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1383 Pl
:= g_Player_Get(PID
);
1384 if Pl
= nil then Exit
;
1386 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1388 NetOut
.Write(Pl
.Name
);
1390 NetOut
.Write(Pl
.Model
.Name
)
1393 NetOut
.Write(Pl
.FColor
.R
);
1394 NetOut
.Write(Pl
.FColor
.G
);
1395 NetOut
.Write(Pl
.FColor
.B
);
1396 NetOut
.Write(Pl
.Team
);
1398 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1403 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1408 it
:= g_Items_ByIdx(IID
);
1410 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1412 NetOut
.Write(Byte(Quiet
));
1414 if it
.dropped
then tt
:= tt
or $80;
1416 NetOut
.Write(Byte(it
.Fall
));
1417 NetOut
.Write(Byte(it
.Respawnable
));
1418 NetOut
.Write(it
.Obj
.X
);
1419 NetOut
.Write(it
.Obj
.Y
);
1420 NetOut
.Write(it
.Obj
.Vel
.X
);
1421 NetOut
.Write(it
.Obj
.Vel
.Y
);
1423 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1426 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1428 NetOut
.Write(Byte(NET_MSG_IDEL
));
1430 NetOut
.Write(Byte(Quiet
));
1432 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1435 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1439 it
:= g_Items_ByIdx(IID
);
1441 NetOut
.Write(Byte(NET_MSG_IPOS
));
1443 NetOut
.Write(it
.Obj
.X
);
1444 NetOut
.Write(it
.Obj
.Y
);
1445 NetOut
.Write(it
.Obj
.Vel
.X
);
1446 NetOut
.Write(it
.Obj
.Vel
.Y
);
1448 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1453 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1457 TP
:= g_Map_PanelByGUID(PGUID
);
1458 if (TP
= nil) then exit
;
1462 NetOut
.Write(Byte(NET_MSG_PTEX
));
1463 NetOut
.Write(LongWord(PGUID
));
1464 NetOut
.Write(FCurTexture
);
1465 NetOut
.Write(FCurFrame
);
1466 NetOut
.Write(FCurFrameCount
);
1467 NetOut
.Write(AnimLoop
);
1470 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1473 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1478 TP
:= g_Map_PanelByGUID(PGUID
);
1479 if (TP
= nil) then exit
;
1481 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1482 NetOut
.Write(LongWord(PGUID
));
1483 NetOut
.Write(Byte(TP
.Enabled
));
1484 NetOut
.Write(TP
.LiftType
);
1487 NetOut
.Write(Word(TP
.Width
));
1488 NetOut
.Write(Word(TP
.Height
));
1490 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1491 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1492 NetOut
.Write(LongInt(TP
.movingStartX
));
1493 NetOut
.Write(LongInt(TP
.movingStartY
));
1494 NetOut
.Write(LongInt(TP
.movingEndX
));
1495 NetOut
.Write(LongInt(TP
.movingEndY
));
1496 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1497 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1498 NetOut
.Write(LongInt(TP
.sizeEndX
));
1499 NetOut
.Write(LongInt(TP
.sizeEndY
));
1500 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1501 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1502 NetOut
.Write(Byte(mpflags
));
1504 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1509 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1511 if gTriggers
= nil then Exit
;
1512 if T
.Sound
= nil then Exit
;
1514 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1515 NetOut
.Write(T
.ClientID
);
1516 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1517 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1518 NetOut
.Write(T
.SoundPlayCount
);
1520 g_Net_Host_Send(ID
, True);
1523 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1525 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1526 NetOut
.Write(gMusic
.Name
);
1527 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1528 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1529 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1531 g_Net_Host_Send(ID
, True);
1536 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1540 M
:= g_Monsters_ByUID(UID
);
1546 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1548 NetOut
.Write(MonsterType
);
1549 NetOut
.Write(MonsterState
);
1550 NetOut
.Write(MonsterAnim
);
1551 NetOut
.Write(MonsterTargetUID
);
1552 NetOut
.Write(MonsterTargetTime
);
1553 NetOut
.Write(MonsterBehaviour
);
1554 NetOut
.Write(MonsterSleep
);
1555 NetOut
.Write(MonsterHealth
);
1556 NetOut
.Write(MonsterAmmo
);
1557 NetOut
.Write(GameX
);
1558 NetOut
.Write(GameY
);
1559 NetOut
.Write(GameVelX
);
1560 NetOut
.Write(GameVelY
);
1561 NetOut
.Write(Byte(GameDirection
));
1564 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1567 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1571 M
:= g_Monsters_ByUID(UID
);
1572 if M
= nil then Exit
;
1574 NetOut
.Write(Byte(NET_MSG_MPOS
));
1579 NetOut
.Write(GameX
);
1580 NetOut
.Write(GameY
);
1581 NetOut
.Write(GameVelX
);
1582 NetOut
.Write(GameVelY
);
1583 NetOut
.Write(Byte(GameDirection
));
1586 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1589 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1593 M
:= g_Monsters_ByUID(UID
);
1594 if M
= nil then Exit
;
1596 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1601 NetOut
.Write(MonsterState
);
1602 NetOut
.Write(ForcedAnim
);
1603 NetOut
.Write(MonsterTargetUID
);
1604 NetOut
.Write(MonsterTargetTime
);
1605 NetOut
.Write(MonsterSleep
);
1606 NetOut
.Write(MonsterHealth
);
1607 NetOut
.Write(MonsterAmmo
);
1608 NetOut
.Write(MonsterPain
);
1609 NetOut
.Write(Byte(AnimIsReverse
));
1610 NetOut
.Write(FFireTime
);
1613 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1616 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1618 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1625 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1628 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1632 M
:= g_Monsters_ByUID(UID
);
1633 if M
= nil then Exit
;
1635 NetOut
.Write(Byte(NET_MSG_MDEL
));
1638 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1643 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1645 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1648 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1651 procedure MH_SEND_VoteEvent(EvType
: Byte;
1652 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1653 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1654 ID
: Integer = NET_EVERYONE
);
1656 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1657 NetOut
.Write(EvType
);
1658 NetOut
.Write(IntArg1
);
1659 NetOut
.Write(IntArg2
);
1660 NetOut
.Write(StrArg1
);
1661 NetOut
.Write(StrArg2
);
1663 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1666 // CLIENT MESSAGES //
1670 procedure MC_RECV_Chat(var M
: TMsg
);
1675 Txt
:= M
.ReadString();
1676 Mode
:= M
.ReadByte();
1678 if Mode
<> NET_CHAT_SYSTEM
then
1680 if NetDeafLevel
= 0 then
1682 if Mode
= NET_CHAT_PLAYER
then
1684 g_Console_Add(Txt
, True);
1685 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1686 g_Game_ChatSound(b_Text_Unformat(Txt
));
1688 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1690 if gPlayer1
.Team
= TEAM_RED
then
1691 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1692 if gPlayer1
.Team
= TEAM_BLUE
then
1693 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1694 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1695 g_Game_ChatSound(b_Text_Unformat(Txt
));
1698 end else if (NetDeafLevel
< 2) then
1699 g_Console_Add(Txt
, True);
1702 procedure MC_RECV_Effect(var M
: TMsg
);
1710 if not gGameOn
then Exit
;
1711 Kind
:= M
.ReadByte();
1712 X
:= M
.ReadLongInt();
1713 Y
:= M
.ReadLongInt();
1714 Ang
:= M
.ReadSmallInt();
1718 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1722 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1724 Anim
:= TAnimation
.Create(ID
, False, 3);
1725 g_GFX_OnceAnim(X
, Y
, Anim
);
1729 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1734 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1736 Anim
:= TAnimation
.Create(ID
, False, 6);
1737 Anim
.Blending
:= False;
1738 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1742 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1747 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1749 Anim
:= TAnimation
.Create(ID
, False, 6);
1750 Anim
.Blending
:= False;
1751 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1755 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1760 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1762 Anim
:= TAnimation
.Create(ID
, False, 4);
1763 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1770 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1772 Anim
:= TAnimation
.Create(ID
, False, 4);
1773 g_GFX_OnceAnim(X
, Y
, Anim
);
1777 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1782 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1784 Anim
:= TAnimation
.Create(ID
, False, 4);
1785 g_GFX_OnceAnim(X
, Y
, Anim
);
1789 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1793 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1796 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1800 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1801 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1806 procedure MC_RECV_Sound(var M
: TMsg
);
1812 Name
:= M
.ReadString();
1813 Pos
:= M
.ReadByte() <> 0;
1816 X
:= M
.ReadLongInt();
1817 Y
:= M
.ReadLongInt();
1818 g_Sound_PlayExAt(Name
, X
, Y
);
1821 g_Sound_PlayEx(Name
);
1824 procedure MC_RECV_CreateShot(var M
: TMsg
);
1826 I
, X
, Y
, XV
, YV
: Integer;
1828 Target
, Spawner
: Word;
1831 I
:= M
.ReadLongInt();
1832 ShType
:= M
.ReadByte();
1833 Target
:= M
.ReadWord();
1834 Spawner
:= M
.ReadWord();
1835 Timeout
:= M
.ReadLongWord();
1836 X
:= M
.ReadLongInt();
1837 Y
:= M
.ReadLongInt();
1838 XV
:= M
.ReadLongInt();
1839 YV
:= M
.ReadLongInt();
1841 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1842 if (Shots
<> nil) and (I
<= High(Shots
)) then
1844 Shots
[I
].Timeout
:= Timeout
;
1845 //Shots[I].Target := Target; // TODO: find a use for Target later
1849 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1851 I
, TX
, TY
, TXV
, TYV
: Integer;
1853 I
:= M
.ReadLongInt();
1854 TX
:= M
.ReadLongInt();
1855 TY
:= M
.ReadLongInt();
1856 TXV
:= M
.ReadLongInt();
1857 TYV
:= M
.ReadLongInt();
1859 if (Shots
<> nil) and (I
<= High(Shots
)) then
1869 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1874 if not gGameOn
then Exit
;
1875 I
:= M
.ReadLongInt();
1876 L
:= (M
.ReadByte() <> 0);
1877 X
:= M
.ReadLongInt();
1878 Y
:= M
.ReadLongInt();
1880 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1883 procedure MC_RECV_GameStats(var M
: TMsg
);
1885 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1887 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1888 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1891 if gGameSettings
.GameMode
= GM_COOP
then
1893 gCoopMonstersKilled
:= M
.ReadWord();
1894 gCoopSecretsFound
:= M
.ReadWord();
1898 procedure MC_RECV_CoopStats(var M
: TMsg
);
1900 gTotalMonsters
:= M
.ReadLongInt();
1901 gSecretsCount
:= M
.ReadLongInt();
1902 gCoopTotalMonstersKilled
:= M
.ReadWord();
1903 gCoopTotalSecretsFound
:= M
.ReadWord();
1904 gCoopTotalMonsters
:= M
.ReadWord();
1905 gCoopTotalSecrets
:= M
.ReadWord();
1908 procedure MC_RECV_GameEvent(var M
: TMsg
);
1917 i1
, i2
: TStrings_Locale
;
1920 goodCmd
: Boolean = true;
1922 FillChar(EvHash
, Sizeof(EvHash
), 0);
1923 EvType
:= M
.ReadByte();
1924 EvNum
:= M
.ReadLongInt();
1925 EvStr
:= M
.ReadString();
1926 gLastMap
:= M
.ReadByte() <> 0;
1927 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1928 gStatsPressed
:= True;
1929 EvTime
:= M
.ReadLongWord();
1930 BHash
:= M
.ReadByte() <> 0;
1932 EvHash
:= M
.ReadMD5();
1936 if (g_Res_received_map_start
<> 0) then
1938 if (g_Res_received_map_start
< 0) then exit
;
1941 NET_EV_MAPSTART
: goodCmd
:= true;
1942 NET_EV_MAPEND
: goodCmd
:= true;
1943 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1944 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1945 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1947 if not goodCmd
then exit
;
1953 if (g_Res_received_map_start
<> 0) then
1955 g_Res_received_map_start
:= -1;
1960 g_Game_ClearLoading();
1961 g_Game_StopAllSounds(True);
1963 gSwitchGameMode
:= Byte(EvNum
);
1964 gGameSettings
.GameMode
:= gSwitchGameMode
;
1967 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1969 if not isWadPath(EvStr
) then
1970 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1972 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1976 MC_SEND_FullStateRequest
;
1982 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1983 gLMSRespawnTime
:= 0;
1984 if (g_Res_received_map_start
<> 0) then
1986 g_Res_received_map_start
:= -1;
1990 gMissionFailed
:= EvNum
<> 0;
1991 gExit
:= EXIT_ENDLEVELCUSTOM
;
1999 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
2001 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
2003 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
2009 if NetDeafLevel
< 2 then
2011 if EvNum
= TEAM_RED
then
2012 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
2013 if EvNum
= TEAM_BLUE
then
2014 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
2020 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
2021 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2026 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
2027 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2034 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
2035 gLMSRespawnTime
:= gTime
+ EvNum
;
2036 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2038 else if gPlayer1
= nil then
2040 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2044 NET_EV_LMS_SURVIVOR
:
2045 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2048 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2052 pl
:= g_Player_Get(EvNum
and $FFFF);
2057 cnt
:= (EvNum
shr 16) and $FF;
2058 if Pos('w', EvStr
) = 0 then
2061 if Pos('t', EvStr
) = 0 then
2064 if Pos('-', EvStr
) = 0 then
2066 if Pos('e', EvStr
) = 0 then
2067 i1
:= I_PLAYER_SCORE_ADD_OWN
2069 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2072 if Pos('e', EvStr
) = 0 then
2073 i1
:= I_PLAYER_SCORE_SUB_OWN
2075 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2078 if Pos('r', EvStr
) > 0 then
2079 i2
:= I_PLAYER_SCORE_TO_RED
2081 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2082 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2086 if Pos('-', EvStr
) = 0 then
2087 i1
:= I_PLAYER_SCORE_ADD_TEAM
2089 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2091 if Pos('r', EvStr
) > 0 then
2092 i2
:= I_PLAYER_SCORE_RED
2094 i2
:= I_PLAYER_SCORE_BLUE
;
2095 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2100 if Pos('e', EvStr
) = 0 then
2101 i1
:= I_PLAYER_SCORE_WIN_OWN
2103 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
2105 if Pos('r', EvStr
) > 0 then
2106 i2
:= I_PLAYER_SCORE_TO_RED
2108 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2109 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
2115 if EvNum
= TEAM_RED
then
2116 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2117 if EvNum
= TEAM_BLUE
then
2118 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2119 if EvNum
= -TEAM_RED
then
2120 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2121 if EvNum
= -TEAM_BLUE
then
2122 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2127 g_Player_RemoveAllCorpses
;
2128 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2129 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2133 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2137 if EvNum
= TEAM_RED
then
2138 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2139 if EvNum
= TEAM_BLUE
then
2140 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2144 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2147 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2150 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2153 g_Game_Announce_KillCombo(EvNum
);
2155 NET_EV_PLAYER_TOUCH
:
2157 pl
:= g_Player_Get(EvNum
);
2164 pl
:= g_Player_Get(EvNum
);
2167 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2168 g_Sound_PlayEx('SOUND_GAME_SECRET');
2174 pl
:= g_Player_Get(EvNum
);
2175 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2180 procedure MC_RECV_FlagPos(var M
: TMsg
);
2185 if Fl
= FLAG_NONE
then Exit
;
2186 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2187 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2188 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2189 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2192 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2201 EvType
:= M
.ReadByte();
2204 if Fl
= FLAG_NONE
then Exit
;
2206 Quiet
:= (M
.ReadByte() <> 0);
2207 PID
:= M
.ReadWord();
2209 gFlags
[Fl
].State
:= M
.ReadByte();
2210 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2211 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2212 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2213 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2214 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2215 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2217 Pl
:= g_Player_Get(PID
);
2219 (EvType
<> FLAG_STATE_NORMAL
) and
2220 (EvType
<> FLAG_STATE_DROPPED
) and
2221 (EvType
<> FLAG_STATE_RETURNED
) then
2227 if Quiet
or (Pl
= nil) then Exit
;
2229 if Fl
= FLAG_RED
then
2230 s
:= _lc
[I_PLAYER_FLAG_RED
]
2232 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2234 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2236 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2237 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2238 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2243 if not sound_ret_flag
[a
].IsPlaying() then
2244 sound_ret_flag
[a
].Play();
2247 FLAG_STATE_CAPTURED
:
2249 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2253 if Fl
= FLAG_RED
then
2254 s
:= _lc
[I_PLAYER_FLAG_RED
]
2256 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2258 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2259 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2261 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2262 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2263 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2268 if not sound_get_flag
[a
].IsPlaying() then
2269 sound_get_flag
[a
].Play();
2274 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2276 if Quiet
or (Pl
= nil) then Exit
;
2278 if Fl
= FLAG_RED
then
2279 s
:= _lc
[I_PLAYER_FLAG_RED
]
2281 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2283 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2284 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2286 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2287 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2288 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2293 if not sound_lost_flag
[a
].IsPlaying() then
2294 sound_lost_flag
[a
].Play();
2299 g_Map_ResetFlag(FLAG_RED
);
2300 g_Map_ResetFlag(FLAG_BLUE
);
2301 if Quiet
or (Pl
= nil) then Exit
;
2302 Pl
.SetFlag(FLAG_NONE
);
2304 if Fl
= FLAG_RED
then
2305 s
:= _lc
[I_PLAYER_FLAG_RED
]
2307 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2309 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2310 Insert('.', ts
, Length(ts
) + 1 - 3);
2311 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2312 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2314 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2315 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2316 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2321 if not sound_cap_flag
[a
].IsPlaying() then
2322 sound_cap_flag
[a
].Play();
2325 FLAG_STATE_RETURNED
:
2327 g_Map_ResetFlag(Fl
);
2330 if Fl
= FLAG_RED
then
2331 s
:= _lc
[I_PLAYER_FLAG_RED
]
2333 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2335 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2337 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2338 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2339 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2344 if not sound_ret_flag
[a
].IsPlaying() then
2345 sound_ret_flag
[a
].Play();
2350 procedure MC_RECV_GameSettings(var M
: TMsg
);
2352 gGameSettings
.GameMode
:= M
.ReadByte();
2353 gGameSettings
.GoalLimit
:= M
.ReadWord();
2354 gGameSettings
.TimeLimit
:= M
.ReadWord();
2355 gGameSettings
.MaxLives
:= M
.ReadByte();
2356 gGameSettings
.Options
:= M
.ReadLongWord();
2361 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2364 PName
, Model
: string;
2369 PID
:= M
.ReadWord();
2370 Pl
:= g_Player_Get(PID
);
2372 PName
:= M
.ReadString();
2373 Model
:= M
.ReadString();
2374 Color
.R
:= M
.ReadByte();
2375 Color
.G
:= M
.ReadByte();
2376 Color
.B
:= M
.ReadByte();
2380 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2382 if (Pl
<> nil) then Exit
;
2383 DID
:= g_Player_Create(Model
, Color
, T
, False);
2384 with g_Player_Get(DID
) do
2393 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2394 gPlayer1
.UID
:= PID
;
2395 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2396 gPlayer1
.ChangeTeam(T
);
2398 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2399 gPlayer2
.UID
:= PID
;
2400 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2401 gPlayer2
.ChangeTeam(T
);
2405 if NetDeafLevel
< 3 then
2406 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2407 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2411 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2418 TmpX
, TmpY
: Integer;
2422 GT
:= M
.ReadLongWord();
2423 if GT
< gTime
- NET_MAX_DIFFTIME
then
2430 PID
:= M
.ReadWord();
2431 Pl
:= g_Player_Get(PID
);
2433 if Pl
= nil then Exit
;
2439 FPing
:= M
.ReadWord();
2440 FLoss
:= M
.ReadByte();
2441 kByte
:= M
.ReadWord();
2442 Dir
:= M
.ReadByte();
2444 TmpX
:= M
.ReadLongInt();
2445 TmpY
:= M
.ReadLongInt();
2449 if LongBool(kByte
and NET_KEY_CHAT
) then
2450 PressKey(KEY_CHAT
, 10000)
2453 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2454 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2455 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2456 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2457 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2460 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2462 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2463 SetDirection(TDirection(Dir
));
2465 GameVelX
:= M
.ReadLongInt();
2466 GameVelY
:= M
.ReadLongInt();
2467 GameAccelX
:= M
.ReadLongInt();
2468 GameAccelY
:= M
.ReadLongInt();
2469 SetLerp(TmpX
, TmpY
);
2470 if NetForcePlayerUpdate
then Update();
2474 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2478 I
, OldFire
: Integer;
2479 OldJet
, Flam
: Boolean;
2482 PID
:= M
.ReadWord();
2483 Pl
:= g_Player_Get(PID
);
2490 alive
:= (M
.ReadByte() <> 0);
2491 GodMode
:= (M
.ReadByte() <> 0);
2492 Health
:= M
.ReadLongInt();
2493 Armor
:= M
.ReadLongInt();
2494 Air
:= M
.ReadLongInt();
2495 JetFuel
:= M
.ReadLongInt();
2496 Lives
:= M
.ReadByte();
2497 NewTeam
:= M
.ReadByte();
2499 for I
:= WP_FIRST
to WP_LAST
do
2500 FWeapon
[I
] := (M
.ReadByte() <> 0);
2502 for I
:= A_BULLETS
to A_HIGH
do
2503 FAmmo
[I
] := M
.ReadWord();
2505 for I
:= A_BULLETS
to A_HIGH
do
2506 FMaxAmmo
[I
] := M
.ReadWord();
2508 for I
:= MR_SUIT
to MR_MAX
do
2509 FMegaRulez
[I
] := M
.ReadLongWord();
2512 if (M
.ReadByte() <> 0) then
2513 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2514 if (M
.ReadByte() <> 0) then
2515 FRulez
:= FRulez
+ [R_KEY_RED
];
2516 if (M
.ReadByte() <> 0) then
2517 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2518 if (M
.ReadByte() <> 0) then
2519 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2520 if (M
.ReadByte() <> 0) then
2521 FRulez
:= FRulez
+ [R_BERSERK
];
2523 Frags
:= M
.ReadLongInt();
2524 Death
:= M
.ReadLongInt();
2526 SetWeapon(M
.ReadByte());
2528 FSpectator
:= M
.ReadByte() <> 0;
2531 if UID
= NetPlrUID1
then
2533 gSpectLatchPID1
:= UID
;
2536 if UID
= NetPlrUID2
then
2538 gSpectLatchPID2
:= UID
;
2544 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2547 gSpectLatchPID1
:= 0;
2549 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2552 gSpectLatchPID2
:= 0;
2555 FGhost
:= M
.ReadByte() <> 0;
2556 FPhysics
:= M
.ReadByte() <> 0;
2557 FNoRespawn
:= M
.ReadByte() <> 0;
2559 FJetpack
:= M
.ReadByte() <> 0;
2560 OldFire
:= FFireTime
;
2561 FFireTime
:= M
.ReadLongInt();
2562 if (OldFire
<= 0) and (FFireTime
> 0) then
2563 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2564 Flam
:= M
.ReadByte() <> 0;
2565 FSpawnInvul
:= M
.ReadLongInt();
2566 if OldJet
and not FJetpack
then
2568 else if not OldJet
and FJetpack
then
2570 if FFlaming
and not Flam
then
2572 if Team
<> NewTeam
then
2573 Pl
.ChangeTeam(NewTeam
);
2579 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2584 Attacker
, Value
: Word;
2588 if not gGameOn
then Exit
;
2589 PID
:= M
.ReadWord();
2590 Pl
:= g_Player_Get(PID
);
2591 if Pl
= nil then Exit
;
2593 Kind
:= M
.ReadByte();
2594 Attacker
:= M
.ReadWord();
2595 Value
:= M
.ReadWord();
2600 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2605 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2609 KillType
, DeathType
: Byte;
2613 if not gGameOn
then Exit
;
2614 PID
:= M
.ReadWord();
2615 Pl
:= g_Player_Get(PID
);
2616 if Pl
= nil then Exit
;
2618 KillType
:= M
.ReadByte();
2619 DeathType
:= M
.ReadByte();
2620 Attacker
:= M
.ReadWord();
2624 Kill(KillType
, Attacker
, DeathType
);
2629 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2634 PID
:= M
.ReadWord();
2635 Pl
:= g_Player_Get(PID
);
2637 if Pl
= nil then Exit
;
2639 if NetDeafLevel
< 3 then
2640 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2641 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2643 g_Player_Remove(PID
);
2648 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2653 X
, Y
, AX
, AY
: Integer;
2657 if not gGameOn
then Exit
;
2658 PID
:= M
.ReadWord();
2659 Pl
:= g_Player_Get(PID
);
2660 if Pl
= nil then Exit
;
2662 Weap
:= M
.ReadByte();
2663 X
:= M
.ReadLongInt();
2664 Y
:= M
.ReadLongInt();
2665 AX
:= M
.ReadLongInt();
2666 AY
:= M
.ReadLongInt();
2667 SHID
:= M
.ReadLongInt();
2670 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2673 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2683 PID
:= M
.ReadWord();
2684 Pl
:= g_Player_Get(PID
);
2685 if Pl
= nil then Exit
;
2687 TmpName
:= M
.ReadString();
2688 TmpModel
:= M
.ReadString();
2689 TmpColor
.R
:= M
.ReadByte();
2690 TmpColor
.G
:= M
.ReadByte();
2691 TmpColor
.B
:= M
.ReadByte();
2692 TmpTeam
:= M
.ReadByte();
2694 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2696 Pl
.ChangeTeam(TmpTeam
);
2697 if gPlayer1
= Pl
then
2698 gPlayer1Settings
.Team
:= TmpTeam
;
2699 if gPlayer2
= Pl
then
2700 gPlayer2Settings
.Team
:= TmpTeam
;
2702 Pl
.SetColor(TmpColor
);
2704 if Pl
.Name
<> TmpName
then
2706 if NetDeafLevel
< 3 then
2707 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2711 if TmpModel
<> Pl
.Model
.Name
then
2712 Pl
.SetModel(TmpModel
);
2717 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2721 X
, Y
, VX
, VY
: Integer;
2723 Quiet
, Fall
{, Resp}: Boolean;
2727 if not gGameOn
then Exit
;
2729 Quiet
:= M
.ReadByte() <> 0;
2731 Fall
:= M
.ReadByte() <> 0;
2732 {Resp :=} M
.ReadByte();
2733 X
:= M
.ReadLongInt();
2734 Y
:= M
.ReadLongInt();
2735 VX
:= M
.ReadLongInt();
2736 VY
:= M
.ReadLongInt();
2738 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2739 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2741 it
:= g_Items_ByIdx(ID
);
2747 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2748 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2750 Anim
:= TAnimation
.Create(AID
, False, 4);
2751 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2757 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2762 if not gGameOn
then Exit
;
2764 Quiet
:= M
.ReadByte() <> 0;
2766 if not g_Items_ValidId(ID
) then exit
;
2768 if not Quiet
then g_Items_EmitPickupSound(ID
);
2773 procedure MC_RECV_ItemPos(var M
: TMsg
);
2776 X
, Y
, VX
, VY
: Integer;
2779 if not gGameOn
then Exit
;
2782 X
:= M
.ReadLongInt();
2783 Y
:= M
.ReadLongInt();
2784 VX
:= M
.ReadLongInt();
2785 VY
:= M
.ReadLongInt();
2787 if g_Items_ValidId(ID
) then
2789 it
:= g_Items_ByIdx(ID
);
2794 it
.positionChanged();
2800 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2807 if not gGameOn
then Exit
;
2809 PGUID
:= Integer(M
.ReadLongWord());
2810 Tex
:= M
.ReadLongInt();
2811 Fr
:= M
.ReadLongInt();
2812 Cnt
:= M
.ReadByte();
2813 Loop
:= M
.ReadByte();
2815 TP
:= g_Map_PanelByGUID(PGUID
);
2819 TP
.SetTexture(Tex
, Loop
);
2820 TP
.SetFrame(Fr
, Cnt
);
2824 procedure MC_RECV_PanelState(var M
: TMsg
);
2829 X
, Y
, W
, H
: Integer;
2831 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2832 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2835 if not gGameOn
then Exit
;
2837 PGUID
:= Integer(M
.ReadLongWord());
2838 E
:= (M
.ReadByte() <> 0);
2839 Lift
:= M
.ReadByte();
2840 X
:= M
.ReadLongInt();
2841 Y
:= M
.ReadLongInt();
2845 speedX
:= M
.ReadLongInt();
2846 speedY
:= M
.ReadLongInt();
2847 startX
:= M
.ReadLongInt();
2848 startY
:= M
.ReadLongInt();
2849 endX
:= M
.ReadLongInt();
2850 endY
:= M
.ReadLongInt();
2851 sizeSpX
:= M
.ReadLongInt();
2852 sizeSpY
:= M
.ReadLongInt();
2853 sizeEX
:= M
.ReadLongInt();
2854 sizeEY
:= M
.ReadLongInt();
2855 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2857 TP
:= g_Map_PanelByGUID(PGUID
);
2858 if (TP
= nil) then exit
;
2860 // update lifts state
2861 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2863 // update enabled/disabled state for all panels
2864 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2866 // update panel position, as it can be moved (mplat)
2871 // update mplat state
2872 TP
.movingSpeedX
:= speedX
;
2873 TP
.movingSpeedY
:= speedY
;
2874 TP
.movingStartX
:= startX
;
2875 TP
.movingStartY
:= startY
;
2876 TP
.movingEndX
:= endX
;
2877 TP
.movingEndY
:= endY
;
2878 TP
.sizeSpeedX
:= sizeSpX
;
2879 TP
.sizeSpeedY
:= sizeSpY
;
2880 TP
.sizeEndX
:= sizeEX
;
2881 TP
.sizeEndY
:= sizeEY
;
2882 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2883 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2884 // notify panel of it's position/size change, so it can fix other internal structures
2885 TP
.positionChanged();
2890 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2893 SPos
, SID
: LongWord;
2897 if not gGameOn
then Exit
;
2898 if gTriggers
= nil then Exit
;
2900 SID
:= M
.ReadLongWord();
2901 SPlaying
:= M
.ReadByte() <> 0;
2902 SPos
:= M
.ReadLongWord();
2903 SCount
:= M
.ReadLongInt();
2905 for I
:= Low(gTriggers
) to High(gTriggers
) do
2906 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2907 if gTriggers
[I
].ClientID
= SID
then
2908 with gTriggers
[I
] do
2910 if Sound
<> nil then
2915 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2917 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2918 Sound
.SetPosition(SPos
);
2921 if Sound
.IsPlaying
then Sound
.Stop
;
2924 SoundPlayCount
:= SCount
;
2928 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2935 if not gGameOn
then Exit
;
2937 MName
:= M
.ReadString();
2938 MPlaying
:= M
.ReadByte() <> 0;
2939 MPos
:= M
.ReadLongWord();
2940 MPaused
:= M
.ReadByte() <> 0;
2941 MPos
:= MPos
+1; //k8: stfu, fpc!
2945 gMusic
.SetByName(MName
);
2947 // gMusic.SetPosition(MPos);
2948 gMusic
.SpecPause
:= MPaused
;
2951 if gMusic
.IsPlaying
then gMusic
.Stop
;
2956 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2959 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2960 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2965 Mon
:= g_Monsters_ByUID(ID
);
2969 MType
:= M
.ReadByte();
2970 MState
:= M
.ReadByte();
2971 MAnim
:= M
.ReadByte();
2972 MTarg
:= M
.ReadWord();
2973 MTargTime
:= M
.ReadLongInt();
2974 MBehav
:= M
.ReadByte();
2975 MSleep
:= M
.ReadLongInt();
2976 MHealth
:= M
.ReadLongInt();
2977 MAmmo
:= M
.ReadLongInt();
2979 X
:= M
.ReadLongInt();
2980 Y
:= M
.ReadLongInt();
2981 VX
:= M
.ReadLongInt();
2982 VY
:= M
.ReadLongInt();
2983 MDir
:= M
.ReadByte();
2985 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2986 Mon
:= g_Monsters_ByUID(ID
);
2993 MonsterAnim
:= MAnim
;
2994 MonsterTargetUID
:= MTarg
;
2995 MonsterTargetTime
:= MTargTime
;
2996 MonsterBehaviour
:= MBehav
;
2997 MonsterSleep
:= MSleep
;
2998 MonsterAmmo
:= MAmmo
;
3003 setPosition(X
, Y
); // this will call positionChanged();
3009 procedure MC_RECV_MonsterPos(var M
: TMsg
);
3016 Mon
:= g_Monsters_ByUID(ID
);
3022 X
:= M
.ReadLongInt();
3023 Y
:= M
.ReadLongInt();
3024 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
3025 GameVelX
:= M
.ReadLongInt();
3026 GameVelY
:= M
.ReadLongInt();
3027 GameDirection
:= TDirection(M
.ReadByte());
3031 procedure MC_RECV_MonsterState(var M
: TMsg
);
3033 ID
, OldFire
: Integer;
3034 MState
, MFAnm
: Byte;
3036 AnimRevert
: Boolean;
3039 Mon
:= g_Monsters_ByUID(ID
);
3040 if Mon
= nil then Exit
;
3042 MState
:= M
.ReadByte();
3043 MFAnm
:= M
.ReadByte();
3047 MonsterTargetUID
:= M
.ReadWord();
3048 MonsterTargetTime
:= M
.ReadLongInt();
3049 MonsterSleep
:= M
.ReadLongInt();
3050 MonsterHealth
:= M
.ReadLongInt();
3051 MonsterAmmo
:= M
.ReadLongInt();
3052 MonsterPain
:= M
.ReadLongInt();
3053 AnimRevert
:= M
.ReadByte() <> 0;
3054 OldFire
:= FFireTime
;
3055 FFireTime
:= M
.ReadLongInt();
3056 if (OldFire
<= 0) and (FFireTime
> 0) then
3057 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3058 RevertAnim(AnimRevert
);
3060 if MonsterState
<> MState
then
3062 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3063 if (MState
= MONSTATE_DIE
) then DieSound();
3064 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3065 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3066 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3068 SetState(MState
, MFAnm
);
3073 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3077 X
, Y
, VX
, VY
: Integer;
3081 Mon
:= g_Monsters_ByUID(ID
);
3082 if Mon
= nil then Exit
;
3084 X
:= M
.ReadLongInt();
3085 Y
:= M
.ReadLongInt();
3086 VX
:= M
.ReadLongInt();
3087 VY
:= M
.ReadLongInt();
3089 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3092 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3098 Mon
:= g_Monsters_ByUID(ID
);
3099 if Mon
= nil then Exit
;
3101 Mon
.MonsterRemoved
:= True;
3104 procedure MC_RECV_TimeSync(var M
: TMsg
);
3108 Time
:= M
.ReadLongWord();
3110 if gState
= STATE_INTERCUSTOM
then
3111 gServInterTime
:= Min(Time
, 255);
3114 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3118 Int1
, Int2
: SmallInt;
3120 EvID
:= M
.ReadByte();
3121 Int1
:= M
.ReadSmallInt();
3122 Int2
:= M
.ReadSmallInt();
3123 Str1
:= M
.ReadString();
3124 Str2
:= M
.ReadString();
3126 if NetDeafLevel
< 2 then
3129 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3131 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3133 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3135 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3137 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3143 procedure MC_SEND_Info(Password
: string);
3148 NetOut
.Write(Byte(NET_MSG_INFO
));
3149 NetOut
.Write(GAME_VERSION
);
3150 NetOut
.Write(Password
);
3151 NetOut
.Write(gPlayer1Settings
.Name
);
3152 NetOut
.Write(gPlayer1Settings
.Model
);
3153 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3154 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3155 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3156 NetOut
.Write(gPlayer1Settings
.Team
);
3157 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3158 if (gPlayer1Settings
.WeaponSwitch
= 2) then
3159 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3160 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3161 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3163 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3166 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3168 NetOut
.Write(Byte(NET_MSG_CHAT
));
3172 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3175 procedure MC_SEND_PlayerPos();
3180 WeaponAct
: Byte = 0;
3181 WeaponSelect
: Word = 0;
3184 if not gGameOn
then Exit
;
3185 if gPlayers
= nil then Exit
;
3186 if gPlayer1
= nil then Exit
;
3189 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3191 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3193 strafeDir
:= P1MoveButton
shr 4;
3194 P1MoveButton
:= P1MoveButton
and $0F;
3196 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3198 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3200 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3204 if gPlayerAction
[0, ACTION_STRAFE
] then
3206 // new strafe mechanics
3207 if (strafeDir
= 0) then
3208 strafeDir
:= P1MoveButton
; // start strafing
3209 // now set direction according to strafe (reversed)
3210 if (strafeDir
= 2) then
3211 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3212 else if (strafeDir
= 1) then
3213 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3217 strafeDir
:= 0; // not strafing anymore
3218 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3219 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3220 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3221 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3222 else if P1MoveButton
<> 0 then
3223 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3226 gPlayer1
.ReleaseKeys
;
3227 if P1MoveButton
= 1 then
3229 kByte
:= kByte
or NET_KEY_LEFT
;
3230 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3232 if P1MoveButton
= 2 then
3234 kByte
:= kByte
or NET_KEY_RIGHT
;
3235 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3237 if gPlayerAction
[0, ACTION_LOOKUP
] then
3239 kByte
:= kByte
or NET_KEY_UP
;
3240 gPlayer1
.PressKey(KEY_UP
, 10000);
3242 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3244 kByte
:= kByte
or NET_KEY_DOWN
;
3245 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3247 if gPlayerAction
[0, ACTION_JUMP
] then
3249 kByte
:= kByte
or NET_KEY_JUMP
;
3250 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3252 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3253 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3255 for i
:= WP_FACT
to WP_LACT
do
3257 if gWeaponAction
[0, i
] then
3259 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3260 gWeaponAction
[0, i
] := False
3264 for i
:= WP_FIRST
to WP_LAST
do
3266 if gSelectWeapon
[0, i
] then
3268 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3269 gSelectWeapon
[0, i
] := False
3273 // fix movebutton state
3274 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3277 kByte
:= NET_KEY_CHAT
;
3279 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3280 NetOut
.Write(gTime
);
3281 NetOut
.Write(kByte
);
3282 NetOut
.Write(Byte(gPlayer1
.Direction
));
3283 NetOut
.Write(WeaponAct
);
3284 NetOut
.Write(WeaponSelect
);
3285 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3286 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3288 //kBytePrev := kByte;
3289 //kDirPrev := gPlayer1.Direction;
3292 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3294 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3295 NetOut
.Write(Byte(Start
));
3296 NetOut
.Write(Command
);
3297 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3300 procedure MC_SEND_PlayerSettings();
3303 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3304 NetOut
.Write(gPlayer1Settings
.Name
);
3305 NetOut
.Write(gPlayer1Settings
.Model
);
3306 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3307 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3308 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3309 NetOut
.Write(gPlayer1Settings
.Team
);
3310 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3311 if (gPlayer1Settings
.WeaponSwitch
= 2) then
3312 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3313 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3314 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3315 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3318 procedure MC_SEND_FullStateRequest();
3320 NetOut
.Write(Byte(NET_MSG_REQFST
));
3322 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3325 procedure MC_SEND_CheatRequest(Kind
: Byte);
3327 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3330 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3332 procedure MC_SEND_RCONPassword(Password
: string);
3334 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3335 NetOut
.Write(Password
);
3337 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3339 procedure MC_SEND_RCONCommand(Cmd
: string);
3341 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3344 g_Net_Client_Send(True, NET_CHAN_SERVICE
);