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;
394 Ver
:= M
.ReadString();
395 Pw
:= M
.ReadString();
396 PName
:= M
.ReadString();
397 Model
:= M
.ReadString();
402 WeapSwitch
:= M
.ReadByte();
403 for I
:= WP_FIRST
to WP_LAST
+ 1 do
404 TmpPrefArray
[I
] := M
.ReadByte();
405 SwitchEmpty
:= M
.ReadByte();
406 SkipF
:= M
.ReadByte();
411 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
413 if Ver
<> GAME_VERSION
then
415 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
416 _lc
[I_NET_DISC_VERSION
]);
417 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
421 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
423 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
425 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
426 _lc
[I_NET_DISC_BAN
]);
427 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
431 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
432 _lc
[I_NET_DISC_BAN
]);
433 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
438 if NetPassword
<> '' then
439 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
441 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
442 _lc
[I_NET_DISC_PASSWORD
]);
443 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
447 if (C
^.Player
<> 0) then
449 // already received info
450 g_Net_Penalize(C
, 'client info spam');
458 PID
:= g_Player_Create(Model
, Color
, T
, False);
459 with g_Player_Get(PID
) do
462 WeapSwitchMode
:= WeapSwitch
;
463 SetWeaponPrefs(TmpPrefArray
);
464 SwitchToEmpty
:= SwitchEmpty
;
466 if (g_Force_Model_Get() <> 0) then
467 SetModel(g_Forced_Model_GetName());
472 C
^.WaitForFirstSpawn
:= false;
475 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
476 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
477 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
481 with g_Player_Get(PID
) do
485 // round in progress, don't spawn
486 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
487 //e_LogWritefln('spawning player with pid #%u...', [PID]);
488 //Respawn(gGameSettings.GameType = GT_SINGLE);
489 //k8: no, do not spawn a player yet, wait for "request full state" packet
493 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
494 // that is, if we'll set it to `true`, the player can be spawned after
495 // warmup time ran out, for example, regardless of the real player state.
496 // also, this seems to work only for the initial connection. further
497 // map changes could initiate resource downloading, but the player will
498 // be spawned immediately.
499 // the proper solution will require another player state, "ephemeral".
500 // the player should start any map in "ephemeral" state, and turned into
501 // real mobj only when they sent a special "i am ready" packet. this packet
502 // must be sent after receiving the full state, so the player will get a full
503 // map view before going into game.
504 FWantsInGame
:= false;
505 C
^.WaitForFirstSpawn
:= true;
508 //if not C^.WaitForFirstSpawn then
510 for I
:= Low(NetClients
) to High(NetClients
) do
512 if NetClients
[I
].ID
= C
^.ID
then Continue
;
513 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
514 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
515 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
519 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
520 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
524 //g_Net_Slist_Update;
530 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
534 if not C
.WaitForFirstSpawn
then exit
;
535 plr
:= g_Player_Get(C
^.Player
);
536 if not assigned(plr
) then exit
;
537 g_Net_Slist_ServerPlayerComes();
538 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
539 C
.WaitForFirstSpawn
:= false;
540 plr
.FNoRespawn
:= false;
541 plr
.FWantsInGame
:= true; // TODO: look into this later
543 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
546 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
551 if gLMSRespawn
> LMS_RESPAWN_NONE
then
552 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
557 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
559 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
561 if C
^.FullUpdateSent
then
563 // FullStateRequest spam?
564 g_Net_Penalize(C
, 'duplicate full state request');
570 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
574 C
^.RequestedFullUpdate
:= True;
580 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
593 if not gGameOn
then Exit
;
596 GT
:= M
.ReadLongWord();
601 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
604 Pl
:= g_Player_Get(PID
);
608 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
614 kByte
:= M
.ReadWord();
616 WeaponAct
:= M
.ReadByte();
617 WeaponSelect
:= M
.ReadWord();
622 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
624 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
625 if Direction
<> TDirection(Dir
) then
626 JustTeleported
:= False;
628 SetDirection(TDirection(Dir
));
631 if kByte
= NET_KEY_CHAT
then
633 PressKey(KEY_CHAT
, 10000);
637 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
638 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
639 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
640 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
641 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
642 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
643 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
647 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
649 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
650 ProcessWeaponAction(i
);
656 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
658 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
659 QueueWeaponSwitch(i
);
664 // MH_SEND_PlayerPos(False, PID, C^.ID);
667 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
674 Pl
:= g_Player_Get(C
^.Player
);
675 if Pl
= nil then Exit
;
678 CheatKind
:= M
.ReadByte();
683 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
687 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
690 if Pl
.FSpectator
then
692 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
695 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
702 if gState
<> STATE_INTERCUSTOM
then Exit
;
703 Pl
.FReady
:= not Pl
.FReady
;
706 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
707 Inc(gInterReadyCount
);
711 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
712 Dec(gInterReadyCount
);
720 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
727 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
736 TmpName
:= M
.ReadString();
737 TmpModel
:= M
.ReadString();
738 TmpColor
.R
:= M
.ReadByte();
739 TmpColor
.G
:= M
.ReadByte();
740 TmpColor
.B
:= M
.ReadByte();
741 TmpTeam
:= M
.ReadByte();
742 TmpWeapSwitch
:= M
.ReadByte();
743 for I
:= WP_FIRST
to WP_LAST
+ 1 do
744 TmpPrefArray
[I
] := M
.ReadByte();
745 TmpSwEmpty
:= M
.ReadByte();
746 TmpSkipF
:= M
.ReadByte();
751 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
753 Pl
:= g_Player_Get(C
^.Player
);
754 if Pl
= nil then Exit
;
756 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
759 Pl
.SetColor(TmpColor
);
761 if Pl
.Name
<> TmpName
then
763 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
767 if (g_Force_Model_Get() <> 0) then
768 TmpModel
:= g_Forced_Model_GetName();
769 if TmpModel
<> Pl
.Model
.Name
then
770 Pl
.SetModel(TmpModel
);
772 if (TmpWeapSwitch
<> Pl
.WeapSwitchMode
) then
773 Pl
.WeapSwitchMode
:= TmpWeapSwitch
;
775 Pl
.SetWeaponPrefs(TmpPrefArray
);
776 if (TmpSwEmpty
<> Pl
.SwitchToEmpty
) then
777 Pl
.SwitchToEmpty
:= TmpSwEmpty
;
779 if (TmpSkipF
<> Pl
.SkipFist
) then
780 Pl
.SkipFist
:= TmpSkipF
;
782 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
787 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
794 Pwd
:= M
.ReadString();
798 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
799 if not NetAllowRCON
then Exit
;
800 if Pwd
= NetRCONPassword
then
803 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
806 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
809 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
816 Cmd
:= M
.ReadString();
820 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
821 if not NetAllowRCON
then Exit
;
822 if not C
^.RCONAuth
then
824 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
827 g_Console_Process(Cmd
);
832 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
835 Name
, Command
: string;
842 Start
:= M
.ReadByte() <> 0;
843 Command
:= M
.ReadString();
848 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
850 Pl
:= g_Player_Get(C
^.Player
);
851 if Pl
= nil then Exit
;
856 if not g_Console_CommandBlacklisted(Command
) then
857 g_Game_StartVote(Command
, Name
);
859 else if gVoteInProgress
then
861 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
862 Need
:= Floor((NetClientCount
+1)/2.0) + 1
864 Need
:= Floor(NetClientCount
/2.0) + 1;
869 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
870 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
876 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
877 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
885 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
887 function sendItemRespawn (it
: PItem
): Boolean;
889 result
:= false; // don't stop
890 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
893 function sendMonSpawn (mon
: TMonster
): Boolean;
895 result
:= false; // don't stop
896 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
899 function sendPanelState (pan
: TPanel
): Boolean;
901 result
:= false; // don't stop
902 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
903 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
909 if (ID
< 0) or (ID
>= Length(NetClients
)) then
910 exit
; // bogus client, this shouldn't happen
912 NetClients
[ID
].FullUpdateSent
:= True;
914 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
916 MH_ProcessFirstSpawn(@NetClients
[ID
]);
918 if gPlayers
<> nil then
920 for I
:= Low(gPlayers
) to High(gPlayers
) do
922 if gPlayers
[I
] <> nil then
924 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
925 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
926 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
928 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
930 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
936 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
937 g_Mons_ForEach(sendMonSpawn
);
938 g_Map_ForEachPanel(sendPanelState
);
940 if gTriggers
<> nil then
942 for I
:= Low(gTriggers
) to High(gTriggers
) do
944 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
946 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
953 for I
:= Low(Shots
) to High(Shots
) do
955 if Shots
[i
].ShotType
in [6, 7, 8] then
957 MH_SEND_CreateShot(i
, ID
);
962 MH_SEND_TriggerMusic(ID
);
964 MH_SEND_GameStats(ID
);
965 MH_SEND_CoopStats(ID
);
967 if gGameSettings
.GameMode
= GM_CTF
then
969 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
970 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
973 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
978 procedure MH_SEND_Info(ID
: Byte);
982 NetOut
.Write(Byte(NET_MSG_INFO
));
984 NetOut
.Write(NetClients
[ID
].Player
);
985 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
986 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
987 NetOut
.Write(gWADHash
);
988 NetOut
.Write(gGameSettings
.GameMode
);
989 NetOut
.Write(gGameSettings
.ScoreLimit
);
990 NetOut
.Write(gGameSettings
.TimeLimit
);
991 NetOut
.Write(gGameSettings
.MaxLives
);
992 NetOut
.Write(gGameSettings
.Options
);
995 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
998 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
1004 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1005 Mode
:= NET_CHAT_PLAYER
;
1008 if (Mode
= NET_CHAT_TEAM
) then
1010 for i
:= Low(gPlayers
) to High(gPlayers
) do
1011 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
1012 (gPlayers
[i
].Team
= ID
) then
1014 NetOut
.Write(Byte(NET_MSG_CHAT
));
1017 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
1024 NetOut
.Write(Byte(NET_MSG_CHAT
));
1027 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
1030 if Mode
= NET_CHAT_SYSTEM
then
1033 if ID
= NET_EVERYONE
then
1035 if Mode
= NET_CHAT_PLAYER
then
1037 g_Console_Add(Txt
, True);
1038 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1039 g_Game_ChatSound(b_Text_Unformat(Txt
));
1042 if Mode
= NET_CHAT_TEAM
then
1043 if gPlayer1
<> nil then
1045 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
1047 g_Console_Add(#18'[Team] '#2 + Txt
, True);
1048 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1049 g_Game_ChatSound(b_Text_Unformat(Txt
));
1051 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
1053 g_Console_Add(#20'[Team] '#2 + Txt
, True);
1054 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1055 g_Game_ChatSound(b_Text_Unformat(Txt
));
1061 Name
:= g_Net_ClientName_ByID(ID
);
1062 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1063 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1064 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1068 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt
; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1070 NetOut
.Write(Byte(NET_MSG_GFX
));
1076 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1079 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1081 NetOut
.Write(Byte(NET_MSG_SND
));
1085 NetOut
.Write(Byte(1));
1090 NetOut
.Write(Byte(0));
1092 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1095 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1097 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1099 NetOut
.Write(Byte(NET_MSG_SHADD
));
1101 NetOut
.Write(Shots
[Proj
].ShotType
);
1102 NetOut
.Write(Shots
[Proj
].Target
);
1103 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1104 NetOut
.Write(Shots
[Proj
].Timeout
);
1105 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1106 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1107 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1108 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1110 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1113 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1115 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1117 NetOut
.Write(Byte(NET_MSG_SHPOS
));
1119 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1120 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1121 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1122 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1124 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
1127 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1129 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1131 NetOut
.Write(Byte(Loud
));
1135 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1138 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1140 NetOut
.Write(Byte(NET_MSG_SCORE
));
1141 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1143 NetOut
.Write(gTeamStat
[TEAM_RED
].Score
);
1144 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Score
);
1147 if gGameSettings
.GameMode
= GM_COOP
then
1149 NetOut
.Write(gCoopMonstersKilled
);
1150 NetOut
.Write(gCoopSecretsFound
);
1153 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1156 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1158 NetOut
.Write(Byte(NET_MSG_COOP
));
1159 NetOut
.Write(gTotalMonsters
);
1160 NetOut
.Write(gSecretsCount
);
1161 NetOut
.Write(gCoopTotalMonstersKilled
);
1162 NetOut
.Write(gCoopTotalSecretsFound
);
1163 NetOut
.Write(gCoopTotalMonsters
);
1164 NetOut
.Write(gCoopTotalSecrets
);
1167 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1169 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1170 NetOut
.Write(EvType
);
1171 NetOut
.Write(EvNum
);
1172 NetOut
.Write(EvStr
);
1173 NetOut
.Write(Byte(gLastMap
));
1174 NetOut
.Write(gTime
);
1175 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1177 NetOut
.Write(Byte(1));
1178 NetOut
.Write(gWADHash
);
1180 NetOut
.Write(Byte(0));
1182 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1185 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1187 NetOut
.Write(Byte(NET_MSG_FLAG
));
1188 NetOut
.Write(EvType
);
1190 NetOut
.Write(Byte(Quiet
));
1192 NetOut
.Write(gFlags
[Flag
].State
);
1193 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1194 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1195 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1196 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1197 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1198 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1200 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1203 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1205 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1207 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1208 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1209 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1210 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1212 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1215 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1217 NetOut
.Write(Byte(NET_MSG_GSET
));
1218 NetOut
.Write(gGameSettings
.GameMode
);
1219 NetOut
.Write(gGameSettings
.ScoreLimit
);
1220 NetOut
.Write(gGameSettings
.TimeLimit
);
1221 NetOut
.Write(gGameSettings
.MaxLives
);
1222 NetOut
.Write(gGameSettings
.Options
);
1224 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1229 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1233 P
:= g_Player_Get(PID
);
1234 if P
= nil then Exit
;
1236 NetOut
.Write(Byte(NET_MSG_PLR
));
1238 NetOut
.Write(P
.Name
);
1240 NetOut
.Write(P
.FActualModelName
);
1241 NetOut
.Write(P
.FColor
.R
);
1242 NetOut
.Write(P
.FColor
.G
);
1243 NetOut
.Write(P
.FColor
.B
);
1244 NetOut
.Write(P
.Team
);
1246 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1249 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1254 Pl
:= g_Player_Get(PID
);
1255 if Pl
= nil then Exit
;
1256 if Pl
.FDummy
then Exit
;
1258 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1259 NetOut
.Write(gTime
);
1266 NetOut
.Write(FPing
);
1267 NetOut
.Write(FLoss
);
1268 if IsKeyPressed(KEY_CHAT
) then
1269 kByte
:= NET_KEY_CHAT
1272 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1273 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1274 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1275 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1276 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1279 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1281 NetOut
.Write(kByte
);
1282 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1283 NetOut
.Write(GameX
);
1284 NetOut
.Write(GameY
);
1285 NetOut
.Write(GameVelX
);
1286 NetOut
.Write(GameVelY
);
1287 NetOut
.Write(GameAccelX
);
1288 NetOut
.Write(GameAccelY
);
1291 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1294 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1299 P
:= g_Player_Get(PID
);
1300 if P
= nil then Exit
;
1302 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1307 NetOut
.Write(Byte(alive
));
1308 NetOut
.Write(Byte(GodMode
));
1309 NetOut
.Write(Health
);
1310 NetOut
.Write(Armor
);
1312 NetOut
.Write(JetFuel
);
1313 NetOut
.Write(Lives
);
1316 for I
:= WP_FIRST
to WP_LAST
do
1317 NetOut
.Write(Byte(FWeapon
[I
]));
1319 for I
:= A_BULLETS
to A_HIGH
do
1320 NetOut
.Write(FAmmo
[I
]);
1322 for I
:= A_BULLETS
to A_HIGH
do
1323 NetOut
.Write(FMaxAmmo
[I
]);
1325 for I
:= MR_SUIT
to MR_MAX
do
1326 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1328 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1329 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1330 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1331 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1332 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1334 NetOut
.Write(Frags
);
1335 NetOut
.Write(Death
);
1337 NetOut
.Write(CurrWeap
);
1339 NetOut
.Write(Byte(FSpectator
));
1340 NetOut
.Write(Byte(FGhost
));
1341 NetOut
.Write(Byte(FPhysics
));
1342 NetOut
.Write(Byte(FNoRespawn
));
1343 NetOut
.Write(Byte(FJetpack
));
1344 NetOut
.Write(FFireTime
);
1345 NetOut
.Write(Byte(FFlaming
));
1346 NetOut
.Write(FSpawnInvul
);
1349 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1352 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1354 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1357 NetOut
.Write(Attacker
);
1358 NetOut
.Write(Value
);
1362 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1365 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1367 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1369 NetOut
.Write(KillType
);
1370 NetOut
.Write(DeathType
);
1371 NetOut
.Write(Attacker
);
1373 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1376 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1378 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1380 NetOut
.Write(Weapon
);
1385 NetOut
.Write(ShotID
);
1387 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1390 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1392 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1395 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1398 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1402 Pl
:= g_Player_Get(PID
);
1403 if Pl
= nil then Exit
;
1405 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1407 NetOut
.Write(Pl
.Name
);
1409 NetOut
.Write(Pl
.Model
.Name
)
1412 NetOut
.Write(Pl
.FColor
.R
);
1413 NetOut
.Write(Pl
.FColor
.G
);
1414 NetOut
.Write(Pl
.FColor
.B
);
1415 NetOut
.Write(Pl
.Team
);
1417 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1422 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1427 it
:= g_Items_ByIdx(IID
);
1429 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1431 NetOut
.Write(Byte(Quiet
));
1433 if it
.dropped
then tt
:= tt
or $80;
1435 NetOut
.Write(Byte(it
.Fall
));
1436 NetOut
.Write(Byte(it
.Respawnable
));
1437 NetOut
.Write(it
.Obj
.X
);
1438 NetOut
.Write(it
.Obj
.Y
);
1439 NetOut
.Write(it
.Obj
.Vel
.X
);
1440 NetOut
.Write(it
.Obj
.Vel
.Y
);
1442 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1445 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1447 NetOut
.Write(Byte(NET_MSG_IDEL
));
1449 NetOut
.Write(Byte(Quiet
));
1451 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1454 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1458 it
:= g_Items_ByIdx(IID
);
1460 NetOut
.Write(Byte(NET_MSG_IPOS
));
1462 NetOut
.Write(it
.Obj
.X
);
1463 NetOut
.Write(it
.Obj
.Y
);
1464 NetOut
.Write(it
.Obj
.Vel
.X
);
1465 NetOut
.Write(it
.Obj
.Vel
.Y
);
1467 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1472 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1476 TP
:= g_Map_PanelByGUID(PGUID
);
1477 if (TP
= nil) then exit
;
1481 NetOut
.Write(Byte(NET_MSG_PTEX
));
1482 NetOut
.Write(LongWord(PGUID
));
1483 NetOut
.Write(FCurTexture
);
1484 NetOut
.Write(FCurFrame
);
1485 NetOut
.Write(FCurFrameCount
);
1486 NetOut
.Write(AnimLoop
);
1489 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1492 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1497 TP
:= g_Map_PanelByGUID(PGUID
);
1498 if (TP
= nil) then exit
;
1500 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1501 NetOut
.Write(LongWord(PGUID
));
1502 NetOut
.Write(Byte(TP
.Enabled
));
1503 NetOut
.Write(TP
.LiftType
);
1506 NetOut
.Write(Word(TP
.Width
));
1507 NetOut
.Write(Word(TP
.Height
));
1509 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1510 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1511 NetOut
.Write(LongInt(TP
.movingStartX
));
1512 NetOut
.Write(LongInt(TP
.movingStartY
));
1513 NetOut
.Write(LongInt(TP
.movingEndX
));
1514 NetOut
.Write(LongInt(TP
.movingEndY
));
1515 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1516 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1517 NetOut
.Write(LongInt(TP
.sizeEndX
));
1518 NetOut
.Write(LongInt(TP
.sizeEndY
));
1519 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1520 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1521 NetOut
.Write(Byte(mpflags
));
1523 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1528 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1530 if gTriggers
= nil then Exit
;
1531 if T
.Sound
= nil then Exit
;
1533 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1534 NetOut
.Write(T
.ClientID
);
1535 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1536 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1537 NetOut
.Write(T
.SoundPlayCount
);
1539 g_Net_Host_Send(ID
, True);
1542 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1544 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1545 NetOut
.Write(gMusic
.Name
);
1546 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1547 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1548 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1550 g_Net_Host_Send(ID
, True);
1555 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1559 M
:= g_Monsters_ByUID(UID
);
1565 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1567 NetOut
.Write(MonsterType
);
1568 NetOut
.Write(MonsterState
);
1569 NetOut
.Write(MonsterAnim
);
1570 NetOut
.Write(MonsterTargetUID
);
1571 NetOut
.Write(MonsterTargetTime
);
1572 NetOut
.Write(MonsterBehaviour
);
1573 NetOut
.Write(MonsterSleep
);
1574 NetOut
.Write(MonsterHealth
);
1575 NetOut
.Write(MonsterAmmo
);
1576 NetOut
.Write(GameX
);
1577 NetOut
.Write(GameY
);
1578 NetOut
.Write(GameVelX
);
1579 NetOut
.Write(GameVelY
);
1580 NetOut
.Write(Byte(GameDirection
));
1583 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1586 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1590 M
:= g_Monsters_ByUID(UID
);
1591 if M
= nil then Exit
;
1593 NetOut
.Write(Byte(NET_MSG_MPOS
));
1598 NetOut
.Write(GameX
);
1599 NetOut
.Write(GameY
);
1600 NetOut
.Write(GameVelX
);
1601 NetOut
.Write(GameVelY
);
1602 NetOut
.Write(Byte(GameDirection
));
1605 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1608 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1612 M
:= g_Monsters_ByUID(UID
);
1613 if M
= nil then Exit
;
1615 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1620 NetOut
.Write(MonsterState
);
1621 NetOut
.Write(ForcedAnim
);
1622 NetOut
.Write(MonsterTargetUID
);
1623 NetOut
.Write(MonsterTargetTime
);
1624 NetOut
.Write(MonsterSleep
);
1625 NetOut
.Write(MonsterHealth
);
1626 NetOut
.Write(MonsterAmmo
);
1627 NetOut
.Write(MonsterPain
);
1628 NetOut
.Write(Byte(AnimIsReverse
));
1629 NetOut
.Write(FFireTime
);
1632 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1635 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1637 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1644 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1647 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1651 M
:= g_Monsters_ByUID(UID
);
1652 if M
= nil then Exit
;
1654 NetOut
.Write(Byte(NET_MSG_MDEL
));
1657 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1662 procedure MH_SEND_TimeSync(Time
: LongWord
; ID
: Integer = NET_EVERYONE
);
1664 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1667 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1670 procedure MH_SEND_VoteEvent(EvType
: Byte;
1671 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1672 IntArg1
: SmallInt
= 0; IntArg2
: SmallInt
= 0;
1673 ID
: Integer = NET_EVERYONE
);
1675 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1676 NetOut
.Write(EvType
);
1677 NetOut
.Write(IntArg1
);
1678 NetOut
.Write(IntArg2
);
1679 NetOut
.Write(StrArg1
);
1680 NetOut
.Write(StrArg2
);
1682 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1685 // CLIENT MESSAGES //
1689 procedure MC_RECV_Chat(var M
: TMsg
);
1694 Txt
:= M
.ReadString();
1695 Mode
:= M
.ReadByte();
1697 if Mode
<> NET_CHAT_SYSTEM
then
1699 if NetDeafLevel
= 0 then
1701 if Mode
= NET_CHAT_PLAYER
then
1703 g_Console_Add(Txt
, True);
1704 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1705 g_Game_ChatSound(b_Text_Unformat(Txt
));
1707 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1709 if gPlayer1
.Team
= TEAM_RED
then
1710 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1711 if gPlayer1
.Team
= TEAM_BLUE
then
1712 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1713 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1714 g_Game_ChatSound(b_Text_Unformat(Txt
));
1717 end else if (NetDeafLevel
< 2) then
1718 g_Console_Add(Txt
, True);
1721 procedure MC_RECV_Effect(var M
: TMsg
);
1729 if not gGameOn
then Exit
;
1730 Kind
:= M
.ReadByte();
1731 X
:= M
.ReadLongInt();
1732 Y
:= M
.ReadLongInt();
1733 Ang
:= M
.ReadSmallInt();
1737 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1741 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1743 Anim
:= TAnimation
.Create(ID
, False, 3);
1744 g_GFX_OnceAnim(X
, Y
, Anim
);
1748 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1753 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1755 Anim
:= TAnimation
.Create(ID
, False, 6);
1756 Anim
.Blending
:= False;
1757 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1761 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1766 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1768 Anim
:= TAnimation
.Create(ID
, False, 6);
1769 Anim
.Blending
:= False;
1770 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1774 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1779 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1781 Anim
:= TAnimation
.Create(ID
, False, 4);
1782 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1789 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1791 Anim
:= TAnimation
.Create(ID
, False, 4);
1792 g_GFX_OnceAnim(X
, Y
, Anim
);
1796 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1801 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1803 Anim
:= TAnimation
.Create(ID
, False, 4);
1804 g_GFX_OnceAnim(X
, Y
, Anim
);
1808 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1812 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1815 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1819 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1820 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1825 procedure MC_RECV_Sound(var M
: TMsg
);
1831 Name
:= M
.ReadString();
1832 Pos
:= M
.ReadByte() <> 0;
1835 X
:= M
.ReadLongInt();
1836 Y
:= M
.ReadLongInt();
1837 g_Sound_PlayExAt(Name
, X
, Y
);
1840 g_Sound_PlayEx(Name
);
1843 procedure MC_RECV_CreateShot(var M
: TMsg
);
1845 I
, X
, Y
, XV
, YV
: Integer;
1847 Target
, Spawner
: Word;
1850 I
:= M
.ReadLongInt();
1851 ShType
:= M
.ReadByte();
1852 Target
:= M
.ReadWord();
1853 Spawner
:= M
.ReadWord();
1854 Timeout
:= M
.ReadLongWord();
1855 X
:= M
.ReadLongInt();
1856 Y
:= M
.ReadLongInt();
1857 XV
:= M
.ReadLongInt();
1858 YV
:= M
.ReadLongInt();
1860 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1861 if (Shots
<> nil) and (I
<= High(Shots
)) then
1863 Shots
[I
].Timeout
:= Timeout
;
1864 //Shots[I].Target := Target; // TODO: find a use for Target later
1868 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1870 I
, TX
, TY
, TXV
, TYV
: Integer;
1872 I
:= M
.ReadLongInt();
1873 TX
:= M
.ReadLongInt();
1874 TY
:= M
.ReadLongInt();
1875 TXV
:= M
.ReadLongInt();
1876 TYV
:= M
.ReadLongInt();
1878 if (Shots
<> nil) and (I
<= High(Shots
)) then
1888 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1893 if not gGameOn
then Exit
;
1894 I
:= M
.ReadLongInt();
1895 L
:= (M
.ReadByte() <> 0);
1896 X
:= M
.ReadLongInt();
1897 Y
:= M
.ReadLongInt();
1899 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1902 procedure MC_RECV_GameStats(var M
: TMsg
);
1904 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1906 gTeamStat
[TEAM_RED
].Score
:= M
.ReadSmallInt();
1907 gTeamStat
[TEAM_BLUE
].Score
:= M
.ReadSmallInt();
1910 if gGameSettings
.GameMode
= GM_COOP
then
1912 gCoopMonstersKilled
:= M
.ReadWord();
1913 gCoopSecretsFound
:= M
.ReadWord();
1917 procedure MC_RECV_CoopStats(var M
: TMsg
);
1919 gTotalMonsters
:= M
.ReadLongInt();
1920 gSecretsCount
:= M
.ReadLongInt();
1921 gCoopTotalMonstersKilled
:= M
.ReadWord();
1922 gCoopTotalSecretsFound
:= M
.ReadWord();
1923 gCoopTotalMonsters
:= M
.ReadWord();
1924 gCoopTotalSecrets
:= M
.ReadWord();
1927 procedure MC_RECV_GameEvent(var M
: TMsg
);
1936 i1
, i2
: TStrings_Locale
;
1939 goodCmd
: Boolean = true;
1941 FillChar(EvHash
, Sizeof(EvHash
), 0);
1942 EvType
:= M
.ReadByte();
1943 EvNum
:= M
.ReadLongInt();
1944 EvStr
:= M
.ReadString();
1945 gLastMap
:= M
.ReadByte() <> 0;
1946 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1947 gStatsPressed
:= True;
1948 EvTime
:= M
.ReadLongWord();
1949 BHash
:= M
.ReadByte() <> 0;
1951 EvHash
:= M
.ReadMD5();
1955 if (g_Res_received_map_start
<> 0) then
1957 if (g_Res_received_map_start
< 0) then exit
;
1960 NET_EV_MAPSTART
: goodCmd
:= true;
1961 NET_EV_MAPEND
: goodCmd
:= true;
1962 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1963 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1964 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1966 if not goodCmd
then exit
;
1972 if (g_Res_received_map_start
<> 0) then
1974 g_Res_received_map_start
:= -1;
1979 g_Game_ClearLoading();
1980 g_Game_StopAllSounds(True);
1982 gSwitchGameMode
:= Byte(EvNum
);
1983 gGameSettings
.GameMode
:= gSwitchGameMode
;
1986 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1988 if not isWadPath(EvStr
) then
1989 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1991 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1995 MC_SEND_FullStateRequest
;
2001 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2002 gLMSRespawnTime
:= 0;
2003 if (g_Res_received_map_start
<> 0) then
2005 g_Res_received_map_start
:= -1;
2009 gMissionFailed
:= EvNum
<> 0;
2010 gExit
:= EXIT_ENDLEVELCUSTOM
;
2018 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
2020 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
2022 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
2028 if NetDeafLevel
< 2 then
2030 if EvNum
= TEAM_RED
then
2031 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
2032 if EvNum
= TEAM_BLUE
then
2033 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
2039 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
2040 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2045 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
2046 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2053 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
2054 gLMSRespawnTime
:= gTime
+ EvNum
;
2055 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2057 else if gPlayer1
= nil then
2059 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2063 NET_EV_LMS_SURVIVOR
:
2064 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2067 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2071 pl
:= g_Player_Get(EvNum
and $FFFF);
2076 cnt
:= (EvNum
shr 16) and $FF;
2077 if Pos('w', EvStr
) = 0 then
2080 if Pos('t', EvStr
) = 0 then
2083 if Pos('-', EvStr
) = 0 then
2085 if Pos('e', EvStr
) = 0 then
2086 i1
:= I_PLAYER_SCORE_ADD_OWN
2088 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2091 if Pos('e', EvStr
) = 0 then
2092 i1
:= I_PLAYER_SCORE_SUB_OWN
2094 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2097 if Pos('r', EvStr
) > 0 then
2098 i2
:= I_PLAYER_SCORE_TO_RED
2100 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2101 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2105 if Pos('-', EvStr
) = 0 then
2106 i1
:= I_PLAYER_SCORE_ADD_TEAM
2108 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2110 if Pos('r', EvStr
) > 0 then
2111 i2
:= I_PLAYER_SCORE_RED
2113 i2
:= I_PLAYER_SCORE_BLUE
;
2114 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2119 if Pos('e', EvStr
) = 0 then
2120 i1
:= I_PLAYER_SCORE_WIN_OWN
2122 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
2124 if Pos('r', EvStr
) > 0 then
2125 i2
:= I_PLAYER_SCORE_TO_RED
2127 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2128 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
2134 if EvNum
= TEAM_RED
then
2135 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2136 if EvNum
= TEAM_BLUE
then
2137 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2138 if EvNum
= -TEAM_RED
then
2139 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2140 if EvNum
= -TEAM_BLUE
then
2141 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2146 g_Player_RemoveAllCorpses
;
2147 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2148 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2152 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2156 if EvNum
= TEAM_RED
then
2157 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2158 if EvNum
= TEAM_BLUE
then
2159 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2163 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2166 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2169 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2172 g_Game_Announce_KillCombo(EvNum
);
2174 NET_EV_PLAYER_TOUCH
:
2176 pl
:= g_Player_Get(EvNum
);
2183 pl
:= g_Player_Get(EvNum
);
2186 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2187 g_Sound_PlayEx('SOUND_GAME_SECRET');
2193 pl
:= g_Player_Get(EvNum
);
2194 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2199 procedure MC_RECV_FlagPos(var M
: TMsg
);
2204 if Fl
= FLAG_NONE
then Exit
;
2205 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2206 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2207 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2208 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2211 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2220 EvType
:= M
.ReadByte();
2223 if Fl
= FLAG_NONE
then Exit
;
2225 Quiet
:= (M
.ReadByte() <> 0);
2226 PID
:= M
.ReadWord();
2228 gFlags
[Fl
].State
:= M
.ReadByte();
2229 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2230 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2231 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2232 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2233 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2234 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2236 Pl
:= g_Player_Get(PID
);
2238 (EvType
<> FLAG_STATE_NORMAL
) and
2239 (EvType
<> FLAG_STATE_DROPPED
) and
2240 (EvType
<> FLAG_STATE_RETURNED
) then
2246 if Quiet
or (Pl
= nil) then Exit
;
2248 if Fl
= FLAG_RED
then
2249 s
:= _lc
[I_PLAYER_FLAG_RED
]
2251 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2253 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2255 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2256 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2257 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2262 if not sound_ret_flag
[a
].IsPlaying() then
2263 sound_ret_flag
[a
].Play();
2266 FLAG_STATE_CAPTURED
:
2268 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2272 if Fl
= FLAG_RED
then
2273 s
:= _lc
[I_PLAYER_FLAG_RED
]
2275 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2277 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2278 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2280 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2281 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2282 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2287 if not sound_get_flag
[a
].IsPlaying() then
2288 sound_get_flag
[a
].Play();
2293 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2295 if Quiet
or (Pl
= nil) then Exit
;
2297 if Fl
= FLAG_RED
then
2298 s
:= _lc
[I_PLAYER_FLAG_RED
]
2300 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2302 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2303 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2305 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2306 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2307 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2312 if not sound_lost_flag
[a
].IsPlaying() then
2313 sound_lost_flag
[a
].Play();
2318 g_Map_ResetFlag(FLAG_RED
);
2319 g_Map_ResetFlag(FLAG_BLUE
);
2320 if Quiet
or (Pl
= nil) then Exit
;
2321 Pl
.SetFlag(FLAG_NONE
);
2323 if Fl
= FLAG_RED
then
2324 s
:= _lc
[I_PLAYER_FLAG_RED
]
2326 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2328 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2329 Insert('.', ts
, Length(ts
) + 1 - 3);
2330 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2331 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2333 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2334 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2335 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2340 if not sound_cap_flag
[a
].IsPlaying() then
2341 sound_cap_flag
[a
].Play();
2344 FLAG_STATE_RETURNED
:
2346 g_Map_ResetFlag(Fl
);
2349 if Fl
= FLAG_RED
then
2350 s
:= _lc
[I_PLAYER_FLAG_RED
]
2352 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2354 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2356 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2357 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2358 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2363 if not sound_ret_flag
[a
].IsPlaying() then
2364 sound_ret_flag
[a
].Play();
2369 procedure MC_RECV_GameSettings(var M
: TMsg
);
2371 gGameSettings
.GameMode
:= M
.ReadByte();
2372 gGameSettings
.ScoreLimit
:= M
.ReadWord();
2373 gGameSettings
.TimeLimit
:= M
.ReadWord();
2374 gGameSettings
.MaxLives
:= M
.ReadByte();
2375 gGameSettings
.Options
:= M
.ReadLongWord();
2380 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2383 PName
, Model
: string;
2388 PID
:= M
.ReadWord();
2389 Pl
:= g_Player_Get(PID
);
2391 PName
:= M
.ReadString();
2392 Model
:= M
.ReadString();
2393 Color
.R
:= M
.ReadByte();
2394 Color
.G
:= M
.ReadByte();
2395 Color
.B
:= M
.ReadByte();
2399 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2401 if (Pl
<> nil) then Exit
;
2402 if (g_Force_Model_Get() <> 0) then
2403 Model
:= g_Forced_Model_GetName();
2404 DID
:= g_Player_Create(Model
, Color
, T
, False);
2405 with g_Player_Get(DID
) do
2414 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2415 gPlayer1
.UID
:= PID
;
2416 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2417 gPlayer1
.ChangeTeam(T
);
2419 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2420 gPlayer2
.UID
:= PID
;
2421 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2422 gPlayer2
.ChangeTeam(T
);
2426 if NetDeafLevel
< 3 then
2427 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2428 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2432 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2439 TmpX
, TmpY
: Integer;
2443 GT
:= M
.ReadLongWord();
2444 if GT
< gTime
- NET_MAX_DIFFTIME
then
2451 PID
:= M
.ReadWord();
2452 Pl
:= g_Player_Get(PID
);
2454 if Pl
= nil then Exit
;
2460 FPing
:= M
.ReadWord();
2461 FLoss
:= M
.ReadByte();
2462 kByte
:= M
.ReadWord();
2463 Dir
:= M
.ReadByte();
2465 TmpX
:= M
.ReadLongInt();
2466 TmpY
:= M
.ReadLongInt();
2470 if LongBool(kByte
and NET_KEY_CHAT
) then
2471 PressKey(KEY_CHAT
, 10000)
2474 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2475 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2476 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2477 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2478 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2481 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2483 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2484 SetDirection(TDirection(Dir
));
2486 GameVelX
:= M
.ReadLongInt();
2487 GameVelY
:= M
.ReadLongInt();
2488 GameAccelX
:= M
.ReadLongInt();
2489 GameAccelY
:= M
.ReadLongInt();
2490 SetLerp(TmpX
, TmpY
);
2491 if NetForcePlayerUpdate
then Update();
2495 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2499 I
, OldFire
: Integer;
2500 OldJet
, Flam
: Boolean;
2503 PID
:= M
.ReadWord();
2504 Pl
:= g_Player_Get(PID
);
2511 alive
:= (M
.ReadByte() <> 0);
2512 GodMode
:= (M
.ReadByte() <> 0);
2513 Health
:= M
.ReadLongInt();
2514 Armor
:= M
.ReadLongInt();
2515 Air
:= M
.ReadLongInt();
2516 JetFuel
:= M
.ReadLongInt();
2517 Lives
:= M
.ReadByte();
2518 NewTeam
:= M
.ReadByte();
2520 for I
:= WP_FIRST
to WP_LAST
do
2521 FWeapon
[I
] := (M
.ReadByte() <> 0);
2523 for I
:= A_BULLETS
to A_HIGH
do
2524 FAmmo
[I
] := M
.ReadWord();
2526 for I
:= A_BULLETS
to A_HIGH
do
2527 FMaxAmmo
[I
] := M
.ReadWord();
2529 for I
:= MR_SUIT
to MR_MAX
do
2530 FMegaRulez
[I
] := M
.ReadLongWord();
2533 if (M
.ReadByte() <> 0) then
2534 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2535 if (M
.ReadByte() <> 0) then
2536 FRulez
:= FRulez
+ [R_KEY_RED
];
2537 if (M
.ReadByte() <> 0) then
2538 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2539 if (M
.ReadByte() <> 0) then
2540 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2541 if (M
.ReadByte() <> 0) then
2542 FRulez
:= FRulez
+ [R_BERSERK
];
2544 Frags
:= M
.ReadLongInt();
2545 Death
:= M
.ReadLongInt();
2547 SetWeapon(M
.ReadByte());
2549 FSpectator
:= M
.ReadByte() <> 0;
2552 if UID
= NetPlrUID1
then
2554 gSpectLatchPID1
:= UID
;
2557 if UID
= NetPlrUID2
then
2559 gSpectLatchPID2
:= UID
;
2565 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2568 gSpectLatchPID1
:= 0;
2570 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2573 gSpectLatchPID2
:= 0;
2576 FGhost
:= M
.ReadByte() <> 0;
2577 FPhysics
:= M
.ReadByte() <> 0;
2578 FNoRespawn
:= M
.ReadByte() <> 0;
2580 FJetpack
:= M
.ReadByte() <> 0;
2581 OldFire
:= FFireTime
;
2582 FFireTime
:= M
.ReadLongInt();
2583 if (OldFire
<= 0) and (FFireTime
> 0) then
2584 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2585 Flam
:= M
.ReadByte() <> 0;
2586 FSpawnInvul
:= M
.ReadLongInt();
2587 if OldJet
and not FJetpack
then
2589 else if not OldJet
and FJetpack
then
2591 if FFlaming
and not Flam
then
2593 if Team
<> NewTeam
then
2594 Pl
.ChangeTeam(NewTeam
);
2600 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2605 Attacker
, Value
: Word;
2609 if not gGameOn
then Exit
;
2610 PID
:= M
.ReadWord();
2611 Pl
:= g_Player_Get(PID
);
2612 if Pl
= nil then Exit
;
2614 Kind
:= M
.ReadByte();
2615 Attacker
:= M
.ReadWord();
2616 Value
:= M
.ReadWord();
2621 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2626 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2630 KillType
, DeathType
: Byte;
2634 if not gGameOn
then Exit
;
2635 PID
:= M
.ReadWord();
2636 Pl
:= g_Player_Get(PID
);
2637 if Pl
= nil then Exit
;
2639 KillType
:= M
.ReadByte();
2640 DeathType
:= M
.ReadByte();
2641 Attacker
:= M
.ReadWord();
2645 Kill(KillType
, Attacker
, DeathType
);
2650 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2655 PID
:= M
.ReadWord();
2656 Pl
:= g_Player_Get(PID
);
2658 if Pl
= nil then Exit
;
2660 if NetDeafLevel
< 3 then
2661 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2662 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2664 g_Player_Remove(PID
);
2669 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2674 X
, Y
, AX
, AY
: Integer;
2678 if not gGameOn
then Exit
;
2679 PID
:= M
.ReadWord();
2680 Pl
:= g_Player_Get(PID
);
2681 if Pl
= nil then Exit
;
2683 Weap
:= M
.ReadByte();
2684 X
:= M
.ReadLongInt();
2685 Y
:= M
.ReadLongInt();
2686 AX
:= M
.ReadLongInt();
2687 AY
:= M
.ReadLongInt();
2688 SHID
:= M
.ReadLongInt();
2691 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2694 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2704 PID
:= M
.ReadWord();
2705 Pl
:= g_Player_Get(PID
);
2706 if Pl
= nil then Exit
;
2708 TmpName
:= M
.ReadString();
2709 TmpModel
:= M
.ReadString();
2710 TmpColor
.R
:= M
.ReadByte();
2711 TmpColor
.G
:= M
.ReadByte();
2712 TmpColor
.B
:= M
.ReadByte();
2713 TmpTeam
:= M
.ReadByte();
2715 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2717 Pl
.ChangeTeam(TmpTeam
);
2718 if gPlayer1
= Pl
then
2719 gPlayer1Settings
.Team
:= TmpTeam
;
2720 if gPlayer2
= Pl
then
2721 gPlayer2Settings
.Team
:= TmpTeam
;
2723 Pl
.SetColor(TmpColor
);
2725 if Pl
.Name
<> TmpName
then
2727 if NetDeafLevel
< 3 then
2728 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2732 if (g_Force_Model_Get() <> 0) then
2733 TmpModel
:= g_Forced_Model_GetName();
2734 if TmpModel
<> Pl
.Model
.Name
then
2735 Pl
.SetModel(TmpModel
);
2740 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2744 X
, Y
, VX
, VY
: Integer;
2746 Quiet
, Fall
{, Resp}: Boolean;
2750 if not gGameOn
then Exit
;
2752 Quiet
:= M
.ReadByte() <> 0;
2754 Fall
:= M
.ReadByte() <> 0;
2755 {Resp :=} M
.ReadByte();
2756 X
:= M
.ReadLongInt();
2757 Y
:= M
.ReadLongInt();
2758 VX
:= M
.ReadLongInt();
2759 VY
:= M
.ReadLongInt();
2761 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2762 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2764 it
:= g_Items_ByIdx(ID
);
2770 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2771 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2773 Anim
:= TAnimation
.Create(AID
, False, 4);
2774 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2780 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2785 if not gGameOn
then Exit
;
2787 Quiet
:= M
.ReadByte() <> 0;
2789 if not g_Items_ValidId(ID
) then exit
;
2791 if not Quiet
then g_Items_EmitPickupSound(ID
);
2796 procedure MC_RECV_ItemPos(var M
: TMsg
);
2799 X
, Y
, VX
, VY
: Integer;
2802 if not gGameOn
then Exit
;
2805 X
:= M
.ReadLongInt();
2806 Y
:= M
.ReadLongInt();
2807 VX
:= M
.ReadLongInt();
2808 VY
:= M
.ReadLongInt();
2810 if g_Items_ValidId(ID
) then
2812 it
:= g_Items_ByIdx(ID
);
2817 it
.positionChanged();
2823 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2830 if not gGameOn
then Exit
;
2832 PGUID
:= Integer(M
.ReadLongWord());
2833 Tex
:= M
.ReadLongInt();
2834 Fr
:= M
.ReadLongInt();
2835 Cnt
:= M
.ReadByte();
2836 Loop
:= M
.ReadByte();
2838 TP
:= g_Map_PanelByGUID(PGUID
);
2842 TP
.SetTexture(Tex
, Loop
);
2843 TP
.SetFrame(Fr
, Cnt
);
2847 procedure MC_RECV_PanelState(var M
: TMsg
);
2852 X
, Y
, W
, H
: Integer;
2854 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2855 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2858 if not gGameOn
then Exit
;
2860 PGUID
:= Integer(M
.ReadLongWord());
2861 E
:= (M
.ReadByte() <> 0);
2862 Lift
:= M
.ReadByte();
2863 X
:= M
.ReadLongInt();
2864 Y
:= M
.ReadLongInt();
2868 speedX
:= M
.ReadLongInt();
2869 speedY
:= M
.ReadLongInt();
2870 startX
:= M
.ReadLongInt();
2871 startY
:= M
.ReadLongInt();
2872 endX
:= M
.ReadLongInt();
2873 endY
:= M
.ReadLongInt();
2874 sizeSpX
:= M
.ReadLongInt();
2875 sizeSpY
:= M
.ReadLongInt();
2876 sizeEX
:= M
.ReadLongInt();
2877 sizeEY
:= M
.ReadLongInt();
2878 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2880 TP
:= g_Map_PanelByGUID(PGUID
);
2881 if (TP
= nil) then exit
;
2883 // update lifts state
2884 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2886 // update enabled/disabled state for all panels
2887 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2889 // update panel position, as it can be moved (mplat)
2894 // update mplat state
2895 TP
.movingSpeedX
:= speedX
;
2896 TP
.movingSpeedY
:= speedY
;
2897 TP
.movingStartX
:= startX
;
2898 TP
.movingStartY
:= startY
;
2899 TP
.movingEndX
:= endX
;
2900 TP
.movingEndY
:= endY
;
2901 TP
.sizeSpeedX
:= sizeSpX
;
2902 TP
.sizeSpeedY
:= sizeSpY
;
2903 TP
.sizeEndX
:= sizeEX
;
2904 TP
.sizeEndY
:= sizeEY
;
2905 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2906 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2907 // notify panel of it's position/size change, so it can fix other internal structures
2908 TP
.positionChanged();
2913 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2916 SPos
, SID
: LongWord
;
2920 if not gGameOn
then Exit
;
2921 if gTriggers
= nil then Exit
;
2923 SID
:= M
.ReadLongWord();
2924 SPlaying
:= M
.ReadByte() <> 0;
2925 SPos
:= M
.ReadLongWord();
2926 SCount
:= M
.ReadLongInt();
2928 for I
:= Low(gTriggers
) to High(gTriggers
) do
2929 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2930 if gTriggers
[I
].ClientID
= SID
then
2931 with gTriggers
[I
] do
2933 if Sound
<> nil then
2938 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2940 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2941 Sound
.SetPosition(SPos
);
2944 if Sound
.IsPlaying
then Sound
.Stop
;
2947 SoundPlayCount
:= SCount
;
2951 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2958 if not gGameOn
then Exit
;
2960 MName
:= M
.ReadString();
2961 MPlaying
:= M
.ReadByte() <> 0;
2962 MPos
:= M
.ReadLongWord();
2963 MPaused
:= M
.ReadByte() <> 0;
2964 MPos
:= MPos
+1; //k8: stfu, fpc!
2968 gMusic
.SetByName(MName
);
2970 // gMusic.SetPosition(MPos);
2971 gMusic
.SpecPause
:= MPaused
;
2974 if gMusic
.IsPlaying
then gMusic
.Stop
;
2979 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2982 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2983 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2988 Mon
:= g_Monsters_ByUID(ID
);
2992 MType
:= M
.ReadByte();
2993 MState
:= M
.ReadByte();
2994 MAnim
:= M
.ReadByte();
2995 MTarg
:= M
.ReadWord();
2996 MTargTime
:= M
.ReadLongInt();
2997 MBehav
:= M
.ReadByte();
2998 MSleep
:= M
.ReadLongInt();
2999 MHealth
:= M
.ReadLongInt();
3000 MAmmo
:= M
.ReadLongInt();
3002 X
:= M
.ReadLongInt();
3003 Y
:= M
.ReadLongInt();
3004 VX
:= M
.ReadLongInt();
3005 VY
:= M
.ReadLongInt();
3006 MDir
:= M
.ReadByte();
3008 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
3009 Mon
:= g_Monsters_ByUID(ID
);
3016 MonsterAnim
:= MAnim
;
3017 MonsterTargetUID
:= MTarg
;
3018 MonsterTargetTime
:= MTargTime
;
3019 MonsterBehaviour
:= MBehav
;
3020 MonsterSleep
:= MSleep
;
3021 MonsterAmmo
:= MAmmo
;
3026 setPosition(X
, Y
); // this will call positionChanged();
3032 procedure MC_RECV_MonsterPos(var M
: TMsg
);
3039 Mon
:= g_Monsters_ByUID(ID
);
3045 X
:= M
.ReadLongInt();
3046 Y
:= M
.ReadLongInt();
3047 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
3048 GameVelX
:= M
.ReadLongInt();
3049 GameVelY
:= M
.ReadLongInt();
3050 GameDirection
:= TDirection(M
.ReadByte());
3054 procedure MC_RECV_MonsterState(var M
: TMsg
);
3056 ID
, OldFire
: Integer;
3057 MState
, MFAnm
: Byte;
3059 AnimRevert
: Boolean;
3062 Mon
:= g_Monsters_ByUID(ID
);
3063 if Mon
= nil then Exit
;
3065 MState
:= M
.ReadByte();
3066 MFAnm
:= M
.ReadByte();
3070 MonsterTargetUID
:= M
.ReadWord();
3071 MonsterTargetTime
:= M
.ReadLongInt();
3072 MonsterSleep
:= M
.ReadLongInt();
3073 MonsterHealth
:= M
.ReadLongInt();
3074 MonsterAmmo
:= M
.ReadLongInt();
3075 MonsterPain
:= M
.ReadLongInt();
3076 AnimRevert
:= M
.ReadByte() <> 0;
3077 OldFire
:= FFireTime
;
3078 FFireTime
:= M
.ReadLongInt();
3079 if (OldFire
<= 0) and (FFireTime
> 0) then
3080 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3081 RevertAnim(AnimRevert
);
3083 if MonsterState
<> MState
then
3085 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3086 if (MState
= MONSTATE_DIE
) then DieSound();
3087 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3088 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3089 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3091 SetState(MState
, MFAnm
);
3096 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3100 X
, Y
, VX
, VY
: Integer;
3104 Mon
:= g_Monsters_ByUID(ID
);
3105 if Mon
= nil then Exit
;
3107 X
:= M
.ReadLongInt();
3108 Y
:= M
.ReadLongInt();
3109 VX
:= M
.ReadLongInt();
3110 VY
:= M
.ReadLongInt();
3112 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3115 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3121 Mon
:= g_Monsters_ByUID(ID
);
3122 if Mon
= nil then Exit
;
3124 Mon
.MonsterRemoved
:= True;
3127 procedure MC_RECV_TimeSync(var M
: TMsg
);
3131 Time
:= M
.ReadLongWord();
3133 if gState
= STATE_INTERCUSTOM
then
3134 gServInterTime
:= Min(Time
, 255);
3137 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3141 Int1
, Int2
: SmallInt
;
3143 EvID
:= M
.ReadByte();
3144 Int1
:= M
.ReadSmallInt();
3145 Int2
:= M
.ReadSmallInt();
3146 Str1
:= M
.ReadString();
3147 Str2
:= M
.ReadString();
3149 if NetDeafLevel
< 2 then
3152 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3154 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3156 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3158 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3160 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3166 procedure MC_SEND_Info(Password
: string);
3171 NetOut
.Write(Byte(NET_MSG_INFO
));
3172 NetOut
.Write(GAME_VERSION
);
3173 NetOut
.Write(Password
);
3174 NetOut
.Write(gPlayer1Settings
.Name
);
3175 NetOut
.Write(gPlayer1Settings
.Model
);
3176 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3177 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3178 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3179 NetOut
.Write(gPlayer1Settings
.Team
);
3180 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3181 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3182 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3183 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3184 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3186 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3189 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3191 NetOut
.Write(Byte(NET_MSG_CHAT
));
3195 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3198 procedure MC_SEND_PlayerPos();
3203 WeaponAct
: Byte = 0;
3204 WeaponSelect
: Word = 0;
3207 if not gGameOn
then Exit
;
3208 if gPlayers
= nil then Exit
;
3209 if gPlayer1
= nil then Exit
;
3212 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3214 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3216 strafeDir
:= P1MoveButton
shr 4;
3217 P1MoveButton
:= P1MoveButton
and $0F;
3219 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3221 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3223 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3227 if gPlayerAction
[0, ACTION_STRAFE
] then
3229 // new strafe mechanics
3230 if (strafeDir
= 0) then
3231 strafeDir
:= P1MoveButton
; // start strafing
3232 // now set direction according to strafe (reversed)
3233 if (strafeDir
= 2) then
3234 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3235 else if (strafeDir
= 1) then
3236 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3240 strafeDir
:= 0; // not strafing anymore
3241 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3242 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3243 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3244 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3245 else if P1MoveButton
<> 0 then
3246 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3249 gPlayer1
.ReleaseKeys
;
3250 if P1MoveButton
= 1 then
3252 kByte
:= kByte
or NET_KEY_LEFT
;
3253 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3255 if P1MoveButton
= 2 then
3257 kByte
:= kByte
or NET_KEY_RIGHT
;
3258 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3260 if gPlayerAction
[0, ACTION_LOOKUP
] then
3262 kByte
:= kByte
or NET_KEY_UP
;
3263 gPlayer1
.PressKey(KEY_UP
, 10000);
3265 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3267 kByte
:= kByte
or NET_KEY_DOWN
;
3268 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3270 if gPlayerAction
[0, ACTION_JUMP
] then
3272 kByte
:= kByte
or NET_KEY_JUMP
;
3273 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3275 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3276 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3278 for i
:= WP_FACT
to WP_LACT
do
3280 if gWeaponAction
[0, i
] then
3282 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3283 gWeaponAction
[0, i
] := False
3287 for i
:= WP_FIRST
to WP_LAST
do
3289 if gSelectWeapon
[0, i
] then
3291 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3292 gSelectWeapon
[0, i
] := False
3296 // fix movebutton state
3297 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3300 kByte
:= NET_KEY_CHAT
;
3302 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3303 NetOut
.Write(gTime
);
3304 NetOut
.Write(kByte
);
3305 NetOut
.Write(Byte(gPlayer1
.Direction
));
3306 NetOut
.Write(WeaponAct
);
3307 NetOut
.Write(WeaponSelect
);
3308 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3309 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3311 //kBytePrev := kByte;
3312 //kDirPrev := gPlayer1.Direction;
3315 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3317 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3318 NetOut
.Write(Byte(Start
));
3319 NetOut
.Write(Command
);
3320 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3323 procedure MC_SEND_PlayerSettings();
3326 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3327 NetOut
.Write(gPlayer1Settings
.Name
);
3328 NetOut
.Write(gPlayer1Settings
.Model
);
3329 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3330 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3331 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3332 NetOut
.Write(gPlayer1Settings
.Team
);
3333 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3334 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3335 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3336 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3337 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3339 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3342 procedure MC_SEND_FullStateRequest();
3344 NetOut
.Write(Byte(NET_MSG_REQFST
));
3346 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3349 procedure MC_SEND_CheatRequest(Kind
: Byte);
3351 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3354 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3356 procedure MC_SEND_RCONPassword(Password
: string);
3358 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3359 NetOut
.Write(Password
);
3361 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3363 procedure MC_SEND_RCONCommand(Cmd
: string);
3365 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3368 g_Net_Client_Send(True, NET_CHAN_SERVICE
);