39a4023d68a194a0eb30cc458f9572466a3383ed
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;
293 {$IFDEF ENABLE_SHELLS}
296 Math
, ENet
, e_input
, e_log
, g_base
, g_basic
,
297 g_textures
, g_sound
, g_console
, g_options
,
298 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
,
299 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
303 NET_KEY_LEFT
= 1 shl 0;
304 NET_KEY_RIGHT
= 1 shl 1;
305 NET_KEY_UP
= 1 shl 2;
306 NET_KEY_DOWN
= 1 shl 3;
307 NET_KEY_JUMP
= 1 shl 4;
308 NET_KEY_FIRE
= 1 shl 5;
309 NET_KEY_OPEN
= 1 shl 6;
310 NET_KEY_CHAT
= 1 shl 7;
311 NET_KEY_FORCEDIR
= 1 shl 8;
314 //kBytePrev: Word = 0;
315 //kDirPrev: TDirection = D_LEFT;
316 //HostGameTime: Word = 0;
319 function IsValidFileName(const S
: String): Boolean;
321 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
326 for I
:= 1 to Length(S
) do
327 Result
:= Result
and (not(S
[I
] in Forbidden
));
330 function IsValidFilePath(const S
: String): Boolean;
335 if not IsValidFileName(S
) then exit
;
336 if FileExists(S
) then exit
;
337 I
:= LastDelimiter('\/', S
);
339 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
350 procedure MH_MalformedPacket(C
: pTNetClient
);
352 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
353 _lc
[I_NET_DISC_PROTOCOL
]);
354 g_Net_Host_Kick(C
^.ID
, NET_DISC_PROTOCOL
);
357 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
366 Pl
:= g_Player_Get(PID
);
370 Txt
:= M
.ReadString();
371 Mode
:= M
.ReadByte();
376 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
378 if (Mode
= NET_CHAT_SYSTEM
) then
379 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
380 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
381 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
384 MH_SEND_Chat(Txt
, Mode
)
386 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
389 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
391 Ver
, PName
, Model
, Pw
: string;
394 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
404 Ver
:= M
.ReadString();
405 Pw
:= M
.ReadString();
406 PName
:= M
.ReadString();
407 Model
:= M
.ReadString();
412 WeapSwitch
:= M
.ReadByte();
413 for I
:= WP_FIRST
to WP_LAST
+ 1 do
414 TmpPrefArray
[I
] := M
.ReadByte();
415 SwitchEmpty
:= M
.ReadByte();
416 SkipF
:= M
.ReadByte();
421 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
423 if Ver
<> GAME_VERSION
then
425 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
426 _lc
[I_NET_DISC_VERSION
]);
427 g_Net_Host_Kick(C
^.ID
, NET_DISC_VERSION
);
431 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
433 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
435 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
436 _lc
[I_NET_DISC_BAN
]);
437 g_Net_Host_Kick(C
^.ID
, NET_DISC_BAN
);
441 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
442 _lc
[I_NET_DISC_BAN
]);
443 g_Net_Host_Kick(C
^.ID
, NET_DISC_TEMPBAN
);
448 if NetPassword
<> '' then
449 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
451 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
452 _lc
[I_NET_DISC_PASSWORD
]);
453 g_Net_Host_Kick(C
^.ID
, NET_DISC_PASSWORD
);
457 if (C
^.Player
<> 0) then
459 // already received info
460 g_Net_Penalize(C
, 'client info spam');
468 PID
:= g_Player_Create(Model
, Color
, T
, False);
469 with g_Player_Get(PID
) do
472 WeapSwitchMode
:= WeapSwitch
;
473 SetWeaponPrefs(TmpPrefArray
);
474 SwitchToEmpty
:= SwitchEmpty
;
476 if (g_Force_Model_Get() <> 0) then
477 SetModel(g_Forced_Model_GetName());
482 C
^.WaitForFirstSpawn
:= false;
485 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
486 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
487 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
491 with g_Player_Get(PID
) do
495 // round in progress, don't spawn
496 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
497 //e_LogWritefln('spawning player with pid #%u...', [PID]);
498 //Respawn(gGameSettings.GameType = GT_SINGLE);
499 //k8: no, do not spawn a player yet, wait for "request full state" packet
503 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
504 // that is, if we'll set it to `true`, the player can be spawned after
505 // warmup time ran out, for example, regardless of the real player state.
506 // also, this seems to work only for the initial connection. further
507 // map changes could initiate resource downloading, but the player will
508 // be spawned immediately.
509 // the proper solution will require another player state, "ephemeral".
510 // the player should start any map in "ephemeral" state, and turned into
511 // real mobj only when they sent a special "i am ready" packet. this packet
512 // must be sent after receiving the full state, so the player will get a full
513 // map view before going into game.
514 FWantsInGame
:= false;
515 C
^.WaitForFirstSpawn
:= true;
518 //if not C^.WaitForFirstSpawn then
520 for I
:= Low(NetClients
) to High(NetClients
) do
522 if NetClients
[I
].ID
= C
^.ID
then Continue
;
523 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
524 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
525 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
529 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
530 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
534 //g_Net_Slist_Update;
540 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
544 if not C
.WaitForFirstSpawn
then exit
;
545 plr
:= g_Player_Get(C
^.Player
);
546 if not assigned(plr
) then exit
;
547 g_Net_Slist_ServerPlayerComes();
548 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
549 C
.WaitForFirstSpawn
:= false;
550 plr
.FNoRespawn
:= false;
551 plr
.FWantsInGame
:= true; // TODO: look into this later
553 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
556 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
561 if gLMSRespawn
> LMS_RESPAWN_NONE
then
562 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
567 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
569 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
571 if C
^.FullUpdateSent
then
573 // FullStateRequest spam?
574 g_Net_Penalize(C
, 'duplicate full state request');
580 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
584 C
^.RequestedFullUpdate
:= True;
590 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
603 if not gGameOn
then Exit
;
606 GT
:= M
.ReadLongWord();
611 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
614 Pl
:= g_Player_Get(PID
);
618 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
624 kByte
:= M
.ReadWord();
626 WeaponAct
:= M
.ReadByte();
627 WeaponSelect
:= M
.ReadWord();
632 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
634 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
635 if Direction
<> TDirection(Dir
) then
636 JustTeleported
:= False;
638 SetDirection(TDirection(Dir
));
641 if kByte
= NET_KEY_CHAT
then
643 PressKey(KEY_CHAT
, 10000);
647 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
648 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
649 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
650 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
651 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
652 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
653 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
657 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
659 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
660 ProcessWeaponAction(i
);
666 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
668 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
669 QueueWeaponSwitch(i
);
674 // MH_SEND_PlayerPos(False, PID, C^.ID);
677 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
684 Pl
:= g_Player_Get(C
^.Player
);
685 if Pl
= nil then Exit
;
688 CheatKind
:= M
.ReadByte();
693 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
697 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
700 if Pl
.FSpectator
then
702 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
705 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
712 if gState
<> STATE_INTERCUSTOM
then Exit
;
713 Pl
.FReady
:= not Pl
.FReady
;
716 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
717 Inc(gInterReadyCount
);
721 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
722 Dec(gInterReadyCount
);
730 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
737 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
746 TmpName
:= M
.ReadString();
747 TmpModel
:= M
.ReadString();
748 TmpColor
.R
:= M
.ReadByte();
749 TmpColor
.G
:= M
.ReadByte();
750 TmpColor
.B
:= M
.ReadByte();
751 TmpTeam
:= M
.ReadByte();
752 TmpWeapSwitch
:= M
.ReadByte();
753 for I
:= WP_FIRST
to WP_LAST
+ 1 do
754 TmpPrefArray
[I
] := M
.ReadByte();
755 TmpSwEmpty
:= M
.ReadByte();
756 TmpSkipF
:= M
.ReadByte();
761 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
763 Pl
:= g_Player_Get(C
^.Player
);
764 if Pl
= nil then Exit
;
766 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
769 Pl
.SetColor(TmpColor
);
771 if Pl
.Name
<> TmpName
then
773 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
777 if (g_Force_Model_Get() <> 0) then
778 TmpModel
:= g_Forced_Model_GetName();
779 if TmpModel
<> Pl
.Model
.GetName() then
780 Pl
.SetModel(TmpModel
);
782 if (TmpWeapSwitch
<> Pl
.WeapSwitchMode
) then
783 Pl
.WeapSwitchMode
:= TmpWeapSwitch
;
785 Pl
.SetWeaponPrefs(TmpPrefArray
);
786 if (TmpSwEmpty
<> Pl
.SwitchToEmpty
) then
787 Pl
.SwitchToEmpty
:= TmpSwEmpty
;
789 if (TmpSkipF
<> Pl
.SkipFist
) then
790 Pl
.SkipFist
:= TmpSkipF
;
792 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
797 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
804 Pwd
:= M
.ReadString();
808 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
809 if not NetAllowRCON
then Exit
;
810 if Pwd
= NetRCONPassword
then
813 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
816 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
819 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
826 Cmd
:= M
.ReadString();
830 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
831 if not NetAllowRCON
then Exit
;
832 if not C
^.RCONAuth
then
834 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
837 g_Console_Process(Cmd
);
842 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
845 Name
, Command
: string;
852 Start
:= M
.ReadByte() <> 0;
853 Command
:= M
.ReadString();
858 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
860 Pl
:= g_Player_Get(C
^.Player
);
861 if Pl
= nil then Exit
;
866 if not g_Console_CommandBlacklisted(Command
) then
867 g_Game_StartVote(Command
, Name
);
869 else if gVoteInProgress
then
871 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
872 Need
:= Floor((NetClientCount
+1)/2.0) + 1
874 Need
:= Floor(NetClientCount
/2.0) + 1;
879 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
880 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
886 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
887 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
895 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
897 function sendItemRespawn (it
: PItem
): Boolean;
899 result
:= false; // don't stop
900 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
903 function sendMonSpawn (mon
: TMonster
): Boolean;
905 result
:= false; // don't stop
906 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
909 function sendPanelState (pan
: TPanel
): Boolean;
911 result
:= false; // don't stop
912 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
913 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
919 if (ID
< 0) or (ID
>= Length(NetClients
)) then
920 exit
; // bogus client, this shouldn't happen
922 NetClients
[ID
].FullUpdateSent
:= True;
924 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
926 MH_ProcessFirstSpawn(@NetClients
[ID
]);
928 if gPlayers
<> nil then
930 for I
:= Low(gPlayers
) to High(gPlayers
) do
932 if gPlayers
[I
] <> nil then
934 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
935 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
936 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
938 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
940 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
946 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
947 g_Mons_ForEach(sendMonSpawn
);
948 g_Map_ForEachPanel(sendPanelState
);
950 if gTriggers
<> nil then
952 for I
:= Low(gTriggers
) to High(gTriggers
) do
954 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
956 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
963 for I
:= Low(Shots
) to High(Shots
) do
965 if Shots
[i
].ShotType
in [6, 7, 8] then
967 MH_SEND_CreateShot(i
, ID
);
972 MH_SEND_TriggerMusic(ID
);
974 MH_SEND_GameStats(ID
);
975 MH_SEND_CoopStats(ID
);
977 if gGameSettings
.GameMode
= GM_CTF
then
979 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
980 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
983 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
988 procedure MH_SEND_Info(ID
: Byte);
992 NetOut
.Write(Byte(NET_MSG_INFO
));
994 NetOut
.Write(NetClients
[ID
].Player
);
995 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
996 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
997 NetOut
.Write(gWADHash
);
998 NetOut
.Write(gGameSettings
.GameMode
);
999 NetOut
.Write(gGameSettings
.ScoreLimit
);
1000 NetOut
.Write(gGameSettings
.TimeLimit
);
1001 NetOut
.Write(gGameSettings
.MaxLives
);
1002 NetOut
.Write(gGameSettings
.Options
);
1003 NetOut
.Write(gTime
);
1005 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1008 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
1014 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1015 Mode
:= NET_CHAT_PLAYER
;
1018 if (Mode
= NET_CHAT_TEAM
) then
1020 for i
:= Low(gPlayers
) to High(gPlayers
) do
1021 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
1022 (gPlayers
[i
].Team
= ID
) then
1024 NetOut
.Write(Byte(NET_MSG_CHAT
));
1027 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
1034 NetOut
.Write(Byte(NET_MSG_CHAT
));
1037 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
1040 if Mode
= NET_CHAT_SYSTEM
then
1043 if ID
= NET_EVERYONE
then
1045 if Mode
= NET_CHAT_PLAYER
then
1047 g_Console_Add(Txt
, True);
1048 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1049 g_Game_ChatSound(b_Text_Unformat(Txt
));
1052 if Mode
= NET_CHAT_TEAM
then
1053 if gPlayer1
<> nil then
1055 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
1057 g_Console_Add(#18'[Team] '#2 + Txt
, True);
1058 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1059 g_Game_ChatSound(b_Text_Unformat(Txt
));
1061 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
1063 g_Console_Add(#20'[Team] '#2 + Txt
, True);
1064 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1065 g_Game_ChatSound(b_Text_Unformat(Txt
));
1071 Name
:= g_Net_ClientName_ByID(ID
);
1072 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1073 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1074 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1078 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1080 NetOut
.Write(Byte(NET_MSG_GFX
));
1086 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1089 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1091 NetOut
.Write(Byte(NET_MSG_SND
));
1095 NetOut
.Write(Byte(1));
1100 NetOut
.Write(Byte(0));
1102 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1105 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1107 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1109 NetOut
.Write(Byte(NET_MSG_SHADD
));
1111 NetOut
.Write(Shots
[Proj
].ShotType
);
1112 NetOut
.Write(Shots
[Proj
].Target
);
1113 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1114 NetOut
.Write(Shots
[Proj
].Timeout
);
1115 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1116 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1117 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1118 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1120 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1123 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1125 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1127 NetOut
.Write(Byte(NET_MSG_SHPOS
));
1129 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1130 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1131 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1132 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1134 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
1137 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1139 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1141 NetOut
.Write(Byte(Loud
));
1145 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1148 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1150 NetOut
.Write(Byte(NET_MSG_SCORE
));
1151 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1153 NetOut
.Write(gTeamStat
[TEAM_RED
].Score
);
1154 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Score
);
1157 if gGameSettings
.GameMode
= GM_COOP
then
1159 NetOut
.Write(gCoopMonstersKilled
);
1160 NetOut
.Write(gCoopSecretsFound
);
1163 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1166 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1168 NetOut
.Write(Byte(NET_MSG_COOP
));
1169 NetOut
.Write(gTotalMonsters
);
1170 NetOut
.Write(gSecretsCount
);
1171 NetOut
.Write(gCoopTotalMonstersKilled
);
1172 NetOut
.Write(gCoopTotalSecretsFound
);
1173 NetOut
.Write(gCoopTotalMonsters
);
1174 NetOut
.Write(gCoopTotalSecrets
);
1177 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1179 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1180 NetOut
.Write(EvType
);
1181 NetOut
.Write(EvNum
);
1182 NetOut
.Write(EvStr
);
1183 NetOut
.Write(Byte(gLastMap
));
1184 NetOut
.Write(gTime
);
1185 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1187 NetOut
.Write(Byte(1));
1188 NetOut
.Write(gWADHash
);
1190 NetOut
.Write(Byte(0));
1192 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1195 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1197 NetOut
.Write(Byte(NET_MSG_FLAG
));
1198 NetOut
.Write(EvType
);
1200 NetOut
.Write(Byte(Quiet
));
1202 NetOut
.Write(gFlags
[Flag
].State
);
1203 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1204 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1205 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1206 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1207 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1208 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1210 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1213 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1215 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1217 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1218 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1219 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1220 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1222 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1225 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1227 NetOut
.Write(Byte(NET_MSG_GSET
));
1228 NetOut
.Write(gGameSettings
.GameMode
);
1229 NetOut
.Write(gGameSettings
.ScoreLimit
);
1230 NetOut
.Write(gGameSettings
.TimeLimit
);
1231 NetOut
.Write(gGameSettings
.MaxLives
);
1232 NetOut
.Write(gGameSettings
.Options
);
1234 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1239 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1243 P
:= g_Player_Get(PID
);
1244 if P
= nil then Exit
;
1246 NetOut
.Write(Byte(NET_MSG_PLR
));
1248 NetOut
.Write(P
.Name
);
1250 NetOut
.Write(P
.FActualModelName
);
1251 NetOut
.Write(P
.FColor
.R
);
1252 NetOut
.Write(P
.FColor
.G
);
1253 NetOut
.Write(P
.FColor
.B
);
1254 NetOut
.Write(P
.Team
);
1256 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1259 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1264 Pl
:= g_Player_Get(PID
);
1265 if Pl
= nil then Exit
;
1266 if Pl
.FDummy
then Exit
;
1268 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1269 NetOut
.Write(gTime
);
1276 NetOut
.Write(FPing
);
1277 NetOut
.Write(FLoss
);
1278 if IsKeyPressed(KEY_CHAT
) then
1279 kByte
:= NET_KEY_CHAT
1282 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1283 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1284 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1285 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1286 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1289 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1291 NetOut
.Write(kByte
);
1292 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1293 NetOut
.Write(GameX
);
1294 NetOut
.Write(GameY
);
1295 NetOut
.Write(GameVelX
);
1296 NetOut
.Write(GameVelY
);
1297 NetOut
.Write(GameAccelX
);
1298 NetOut
.Write(GameAccelY
);
1301 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1304 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1309 P
:= g_Player_Get(PID
);
1310 if P
= nil then Exit
;
1312 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1317 NetOut
.Write(Byte(alive
));
1318 NetOut
.Write(Byte(GodMode
));
1319 NetOut
.Write(Health
);
1320 NetOut
.Write(Armor
);
1322 NetOut
.Write(JetFuel
);
1323 NetOut
.Write(Lives
);
1326 for I
:= WP_FIRST
to WP_LAST
do
1327 NetOut
.Write(Byte(FWeapon
[I
]));
1329 for I
:= A_BULLETS
to A_HIGH
do
1330 NetOut
.Write(FAmmo
[I
]);
1332 for I
:= A_BULLETS
to A_HIGH
do
1333 NetOut
.Write(FMaxAmmo
[I
]);
1335 for I
:= MR_SUIT
to MR_MAX
do
1336 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1338 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1339 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1340 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1341 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1342 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1344 NetOut
.Write(Frags
);
1345 NetOut
.Write(Death
);
1347 NetOut
.Write(CurrWeap
);
1349 NetOut
.Write(Byte(FSpectator
));
1350 NetOut
.Write(Byte(FGhost
));
1351 NetOut
.Write(Byte(FPhysics
));
1352 NetOut
.Write(Byte(FNoRespawn
));
1353 NetOut
.Write(Byte(FJetpack
));
1354 NetOut
.Write(FFireTime
);
1355 NetOut
.Write(Byte(FFlaming
));
1356 NetOut
.Write(FSpawnInvul
);
1359 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1362 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1364 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1367 NetOut
.Write(Attacker
);
1368 NetOut
.Write(Value
);
1372 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1375 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1377 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1379 NetOut
.Write(KillType
);
1380 NetOut
.Write(DeathType
);
1381 NetOut
.Write(Attacker
);
1383 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1386 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1388 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1390 NetOut
.Write(Weapon
);
1395 NetOut
.Write(ShotID
);
1397 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1400 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1402 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1405 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1408 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1412 Pl
:= g_Player_Get(PID
);
1413 if Pl
= nil then Exit
;
1415 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1417 NetOut
.Write(Pl
.Name
);
1419 NetOut
.Write(Pl
.Model
.GetName())
1422 NetOut
.Write(Pl
.FColor
.R
);
1423 NetOut
.Write(Pl
.FColor
.G
);
1424 NetOut
.Write(Pl
.FColor
.B
);
1425 NetOut
.Write(Pl
.Team
);
1427 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1432 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1437 it
:= g_Items_ByIdx(IID
);
1439 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1441 NetOut
.Write(Byte(Quiet
));
1443 if it
.dropped
then tt
:= tt
or $80;
1445 NetOut
.Write(Byte(it
.Fall
));
1446 NetOut
.Write(Byte(it
.Respawnable
));
1447 NetOut
.Write(it
.Obj
.X
);
1448 NetOut
.Write(it
.Obj
.Y
);
1449 NetOut
.Write(it
.Obj
.Vel
.X
);
1450 NetOut
.Write(it
.Obj
.Vel
.Y
);
1452 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1455 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1457 NetOut
.Write(Byte(NET_MSG_IDEL
));
1459 NetOut
.Write(Byte(Quiet
));
1461 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1464 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1468 it
:= g_Items_ByIdx(IID
);
1470 NetOut
.Write(Byte(NET_MSG_IPOS
));
1472 NetOut
.Write(it
.Obj
.X
);
1473 NetOut
.Write(it
.Obj
.Y
);
1474 NetOut
.Write(it
.Obj
.Vel
.X
);
1475 NetOut
.Write(it
.Obj
.Vel
.Y
);
1477 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1482 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1486 TP
:= g_Map_PanelByGUID(PGUID
);
1487 if (TP
= nil) then exit
;
1491 NetOut
.Write(Byte(NET_MSG_PTEX
));
1492 NetOut
.Write(LongWord(PGUID
));
1493 NetOut
.Write(FCurTexture
);
1494 NetOut
.Write(FCurFrame
);
1495 NetOut
.Write(FCurFrameCount
);
1496 NetOut
.Write(AnimLoop
);
1499 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1502 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1507 TP
:= g_Map_PanelByGUID(PGUID
);
1508 if (TP
= nil) then exit
;
1510 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1511 NetOut
.Write(LongWord(PGUID
));
1512 NetOut
.Write(Byte(TP
.Enabled
));
1513 NetOut
.Write(TP
.LiftType
);
1516 NetOut
.Write(Word(TP
.Width
));
1517 NetOut
.Write(Word(TP
.Height
));
1519 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1520 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1521 NetOut
.Write(LongInt(TP
.movingStartX
));
1522 NetOut
.Write(LongInt(TP
.movingStartY
));
1523 NetOut
.Write(LongInt(TP
.movingEndX
));
1524 NetOut
.Write(LongInt(TP
.movingEndY
));
1525 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1526 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1527 NetOut
.Write(LongInt(TP
.sizeEndX
));
1528 NetOut
.Write(LongInt(TP
.sizeEndY
));
1529 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1530 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1531 NetOut
.Write(Byte(mpflags
));
1533 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1538 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1540 if gTriggers
= nil then Exit
;
1541 if T
.Sound
= nil then Exit
;
1543 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1544 NetOut
.Write(T
.ClientID
);
1545 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1546 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1547 NetOut
.Write(T
.SoundPlayCount
);
1549 g_Net_Host_Send(ID
, True);
1552 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1554 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1555 NetOut
.Write(gMusic
.Name
);
1556 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1557 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1558 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1560 g_Net_Host_Send(ID
, True);
1565 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1569 M
:= g_Monsters_ByUID(UID
);
1575 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1577 NetOut
.Write(MonsterType
);
1578 NetOut
.Write(MonsterState
);
1579 NetOut
.Write(MonsterAnim
);
1580 NetOut
.Write(MonsterTargetUID
);
1581 NetOut
.Write(MonsterTargetTime
);
1582 NetOut
.Write(MonsterBehaviour
);
1583 NetOut
.Write(MonsterSleep
);
1584 NetOut
.Write(MonsterHealth
);
1585 NetOut
.Write(MonsterAmmo
);
1586 NetOut
.Write(GameX
);
1587 NetOut
.Write(GameY
);
1588 NetOut
.Write(GameVelX
);
1589 NetOut
.Write(GameVelY
);
1590 NetOut
.Write(Byte(GameDirection
));
1593 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1596 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1600 M
:= g_Monsters_ByUID(UID
);
1601 if M
= nil then Exit
;
1603 NetOut
.Write(Byte(NET_MSG_MPOS
));
1608 NetOut
.Write(GameX
);
1609 NetOut
.Write(GameY
);
1610 NetOut
.Write(GameVelX
);
1611 NetOut
.Write(GameVelY
);
1612 NetOut
.Write(Byte(GameDirection
));
1615 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1618 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1622 M
:= g_Monsters_ByUID(UID
);
1623 if M
= nil then Exit
;
1625 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1630 NetOut
.Write(MonsterState
);
1631 NetOut
.Write(ForcedAnim
);
1632 NetOut
.Write(MonsterTargetUID
);
1633 NetOut
.Write(MonsterTargetTime
);
1634 NetOut
.Write(MonsterSleep
);
1635 NetOut
.Write(MonsterHealth
);
1636 NetOut
.Write(MonsterAmmo
);
1637 NetOut
.Write(MonsterPain
);
1638 NetOut
.Write(Byte(AnimIsReverse
));
1639 NetOut
.Write(FFireTime
);
1642 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1645 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1647 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1654 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1657 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1661 M
:= g_Monsters_ByUID(UID
);
1662 if M
= nil then Exit
;
1664 NetOut
.Write(Byte(NET_MSG_MDEL
));
1667 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1672 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1674 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1677 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1680 procedure MH_SEND_VoteEvent(EvType
: Byte;
1681 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1682 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1683 ID
: Integer = NET_EVERYONE
);
1685 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1686 NetOut
.Write(EvType
);
1687 NetOut
.Write(IntArg1
);
1688 NetOut
.Write(IntArg2
);
1689 NetOut
.Write(StrArg1
);
1690 NetOut
.Write(StrArg2
);
1692 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1695 // CLIENT MESSAGES //
1699 procedure MC_RECV_Chat(var M
: TMsg
);
1704 Txt
:= M
.ReadString();
1705 Mode
:= M
.ReadByte();
1707 if Mode
<> NET_CHAT_SYSTEM
then
1709 if NetDeafLevel
= 0 then
1711 if Mode
= NET_CHAT_PLAYER
then
1713 g_Console_Add(Txt
, True);
1714 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1715 g_Game_ChatSound(b_Text_Unformat(Txt
));
1717 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1719 if gPlayer1
.Team
= TEAM_RED
then
1720 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1721 if gPlayer1
.Team
= TEAM_BLUE
then
1722 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1723 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1724 g_Game_ChatSound(b_Text_Unformat(Txt
));
1727 end else if (NetDeafLevel
< 2) then
1728 g_Console_Add(Txt
, True);
1731 procedure MC_RECV_Effect(var M
: TMsg
);
1737 if not gGameOn
then Exit
;
1738 Kind
:= M
.ReadByte();
1739 X
:= M
.ReadLongInt();
1740 Y
:= M
.ReadLongInt();
1741 Ang
:= M
.ReadSmallInt();
1747 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1753 g_GFX_QueueEffect(R_GFX_TELEPORT_FAST
, X
, Y
);
1756 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1761 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, X
- 64, Y
- 64);
1764 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1769 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, X
- 64, Y
- 64);
1772 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1777 g_GFX_QueueEffect(R_GFX_BFG_HIT
, X
- 32, Y
- 32);
1783 g_GFX_QueueEffect(R_GFX_FIRE
, X
, Y
);
1786 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1791 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
, Y
);
1794 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1798 {$IFDEF ENABLE_SHELLS}
1799 g_Shells_Create(X
, Y
, 0, -2, SHELL_BULLET
);
1804 {$IFDEF ENABLE_SHELLS}
1805 g_Shells_Create(X
, Y
, 0, -2, SHELL_SHELL
);
1810 {$IFDEF ENABLE_SHELLS}
1811 g_Shells_Create(X
, Y
, 0, -2, SHELL_SHELL
);
1812 g_Shells_Create(X
, Y
, 0, -2, SHELL_SHELL
);
1818 procedure MC_RECV_Sound(var M
: TMsg
);
1824 Name
:= M
.ReadString();
1825 Pos
:= M
.ReadByte() <> 0;
1828 X
:= M
.ReadLongInt();
1829 Y
:= M
.ReadLongInt();
1830 g_Sound_PlayExAt(Name
, X
, Y
);
1833 g_Sound_PlayEx(Name
);
1836 procedure MC_RECV_CreateShot(var M
: TMsg
);
1838 I
, X
, Y
, XV
, YV
: Integer;
1840 Target
, Spawner
: Word;
1843 I
:= M
.ReadLongInt();
1844 ShType
:= M
.ReadByte();
1845 Target
:= M
.ReadWord();
1846 Spawner
:= M
.ReadWord();
1847 Timeout
:= M
.ReadLongWord();
1848 X
:= M
.ReadLongInt();
1849 Y
:= M
.ReadLongInt();
1850 XV
:= M
.ReadLongInt();
1851 YV
:= M
.ReadLongInt();
1853 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1854 if (Shots
<> nil) and (I
<= High(Shots
)) then
1856 Shots
[I
].Timeout
:= Timeout
;
1857 //Shots[I].Target := Target; // TODO: find a use for Target later
1861 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1863 I
, TX
, TY
, TXV
, TYV
: Integer;
1865 I
:= M
.ReadLongInt();
1866 TX
:= M
.ReadLongInt();
1867 TY
:= M
.ReadLongInt();
1868 TXV
:= M
.ReadLongInt();
1869 TYV
:= M
.ReadLongInt();
1871 if (Shots
<> nil) and (I
<= High(Shots
)) then
1881 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1886 if not gGameOn
then Exit
;
1887 I
:= M
.ReadLongInt();
1888 L
:= (M
.ReadByte() <> 0);
1889 X
:= M
.ReadLongInt();
1890 Y
:= M
.ReadLongInt();
1892 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1895 procedure MC_RECV_GameStats(var M
: TMsg
);
1897 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1899 gTeamStat
[TEAM_RED
].Score
:= M
.ReadSmallInt();
1900 gTeamStat
[TEAM_BLUE
].Score
:= M
.ReadSmallInt();
1903 if gGameSettings
.GameMode
= GM_COOP
then
1905 gCoopMonstersKilled
:= M
.ReadWord();
1906 gCoopSecretsFound
:= M
.ReadWord();
1910 procedure MC_RECV_CoopStats(var M
: TMsg
);
1912 gTotalMonsters
:= M
.ReadLongInt();
1913 gSecretsCount
:= M
.ReadLongInt();
1914 gCoopTotalMonstersKilled
:= M
.ReadWord();
1915 gCoopTotalSecretsFound
:= M
.ReadWord();
1916 gCoopTotalMonsters
:= M
.ReadWord();
1917 gCoopTotalSecrets
:= M
.ReadWord();
1920 procedure MC_RECV_GameEvent(var M
: TMsg
);
1929 i1
, i2
: TStrings_Locale
;
1932 goodCmd
: Boolean = true;
1934 FillChar(EvHash
, Sizeof(EvHash
), 0);
1935 EvType
:= M
.ReadByte();
1936 EvNum
:= M
.ReadLongInt();
1937 EvStr
:= M
.ReadString();
1938 gLastMap
:= M
.ReadByte() <> 0;
1939 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1940 gStatsPressed
:= True;
1941 EvTime
:= M
.ReadLongWord();
1942 BHash
:= M
.ReadByte() <> 0;
1944 EvHash
:= M
.ReadMD5();
1948 if (g_Res_received_map_start
<> 0) then
1950 if (g_Res_received_map_start
< 0) then exit
;
1953 NET_EV_MAPSTART
: goodCmd
:= true;
1954 NET_EV_MAPEND
: goodCmd
:= true;
1955 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1956 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1957 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1959 if not goodCmd
then exit
;
1965 if (g_Res_received_map_start
<> 0) then
1967 g_Res_received_map_start
:= -1;
1972 g_Game_ClearLoading();
1973 g_Game_StopAllSounds(True);
1975 gSwitchGameMode
:= Byte(EvNum
);
1976 gGameSettings
.GameMode
:= gSwitchGameMode
;
1979 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1981 if not isWadPath(EvStr
) then
1982 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1984 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1988 MC_SEND_FullStateRequest
;
1994 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1995 gLMSRespawnTime
:= 0;
1996 if (g_Res_received_map_start
<> 0) then
1998 g_Res_received_map_start
:= -1;
2002 gMissionFailed
:= EvNum
<> 0;
2003 gExit
:= EXIT_ENDLEVELCUSTOM
;
2011 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
2013 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
2015 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
2021 if NetDeafLevel
< 2 then
2023 if EvNum
= TEAM_RED
then
2024 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
2025 if EvNum
= TEAM_BLUE
then
2026 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
2032 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
2033 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2038 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
2039 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2046 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
2047 gLMSRespawnTime
:= gTime
+ EvNum
;
2048 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2050 else if gPlayer1
= nil then
2052 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2056 NET_EV_LMS_SURVIVOR
:
2057 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2060 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2064 pl
:= g_Player_Get(EvNum
and $FFFF);
2069 cnt
:= (EvNum
shr 16) and $FF;
2070 if Pos('w', EvStr
) = 0 then
2073 if Pos('t', EvStr
) = 0 then
2076 if Pos('-', EvStr
) = 0 then
2078 if Pos('e', EvStr
) = 0 then
2079 i1
:= I_PLAYER_SCORE_ADD_OWN
2081 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2084 if Pos('e', EvStr
) = 0 then
2085 i1
:= I_PLAYER_SCORE_SUB_OWN
2087 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2090 if Pos('r', EvStr
) > 0 then
2091 i2
:= I_PLAYER_SCORE_TO_RED
2093 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2094 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2098 if Pos('-', EvStr
) = 0 then
2099 i1
:= I_PLAYER_SCORE_ADD_TEAM
2101 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2103 if Pos('r', EvStr
) > 0 then
2104 i2
:= I_PLAYER_SCORE_RED
2106 i2
:= I_PLAYER_SCORE_BLUE
;
2107 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2112 if Pos('e', EvStr
) = 0 then
2113 i1
:= I_PLAYER_SCORE_WIN_OWN
2115 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
2117 if Pos('r', EvStr
) > 0 then
2118 i2
:= I_PLAYER_SCORE_TO_RED
2120 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2121 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
2127 if EvNum
= TEAM_RED
then
2128 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2129 if EvNum
= TEAM_BLUE
then
2130 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2131 if EvNum
= -TEAM_RED
then
2132 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2133 if EvNum
= -TEAM_BLUE
then
2134 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2139 g_Player_RemoveAllCorpses
;
2140 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2141 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2145 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2149 if EvNum
= TEAM_RED
then
2150 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2151 if EvNum
= TEAM_BLUE
then
2152 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2156 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2159 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2162 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2165 g_Game_Announce_KillCombo(EvNum
);
2167 NET_EV_PLAYER_TOUCH
:
2169 pl
:= g_Player_Get(EvNum
);
2176 pl
:= g_Player_Get(EvNum
);
2179 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2180 g_Sound_PlayEx('SOUND_GAME_SECRET');
2186 pl
:= g_Player_Get(EvNum
);
2187 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2192 procedure MC_RECV_FlagPos(var M
: TMsg
);
2197 if Fl
= FLAG_NONE
then Exit
;
2198 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2199 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2200 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2201 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2204 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2213 EvType
:= M
.ReadByte();
2216 if Fl
= FLAG_NONE
then Exit
;
2218 Quiet
:= (M
.ReadByte() <> 0);
2219 PID
:= M
.ReadWord();
2221 gFlags
[Fl
].State
:= M
.ReadByte();
2222 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2223 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2224 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2225 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2226 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2227 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2229 Pl
:= g_Player_Get(PID
);
2231 (EvType
<> FLAG_STATE_NORMAL
) and
2232 (EvType
<> FLAG_STATE_DROPPED
) and
2233 (EvType
<> FLAG_STATE_RETURNED
) then
2239 if Quiet
or (Pl
= nil) then Exit
;
2241 if Fl
= FLAG_RED
then
2242 s
:= _lc
[I_PLAYER_FLAG_RED
]
2244 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2246 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2248 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2249 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2250 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2255 if not sound_ret_flag
[a
].IsPlaying() then
2256 sound_ret_flag
[a
].Play();
2259 FLAG_STATE_CAPTURED
:
2261 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2265 if Fl
= FLAG_RED
then
2266 s
:= _lc
[I_PLAYER_FLAG_RED
]
2268 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2270 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2271 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2273 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2274 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2275 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2280 if not sound_get_flag
[a
].IsPlaying() then
2281 sound_get_flag
[a
].Play();
2286 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2288 if Quiet
or (Pl
= nil) then Exit
;
2290 if Fl
= FLAG_RED
then
2291 s
:= _lc
[I_PLAYER_FLAG_RED
]
2293 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2295 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2296 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2298 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2299 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2300 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2305 if not sound_lost_flag
[a
].IsPlaying() then
2306 sound_lost_flag
[a
].Play();
2311 g_Map_ResetFlag(FLAG_RED
);
2312 g_Map_ResetFlag(FLAG_BLUE
);
2313 if Quiet
or (Pl
= nil) then Exit
;
2314 Pl
.SetFlag(FLAG_NONE
);
2316 if Fl
= FLAG_RED
then
2317 s
:= _lc
[I_PLAYER_FLAG_RED
]
2319 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2321 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2322 Insert('.', ts
, Length(ts
) + 1 - 3);
2323 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2324 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2326 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2327 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2328 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2333 if not sound_cap_flag
[a
].IsPlaying() then
2334 sound_cap_flag
[a
].Play();
2337 FLAG_STATE_RETURNED
:
2339 g_Map_ResetFlag(Fl
);
2342 if Fl
= FLAG_RED
then
2343 s
:= _lc
[I_PLAYER_FLAG_RED
]
2345 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2347 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2349 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2350 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2351 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2356 if not sound_ret_flag
[a
].IsPlaying() then
2357 sound_ret_flag
[a
].Play();
2362 procedure MC_RECV_GameSettings(var M
: TMsg
);
2364 gGameSettings
.GameMode
:= M
.ReadByte();
2365 gGameSettings
.ScoreLimit
:= M
.ReadWord();
2366 gGameSettings
.TimeLimit
:= M
.ReadWord();
2367 gGameSettings
.MaxLives
:= M
.ReadByte();
2368 gGameSettings
.Options
:= M
.ReadLongWord();
2373 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2376 PName
, Model
: string;
2381 PID
:= M
.ReadWord();
2382 Pl
:= g_Player_Get(PID
);
2384 PName
:= M
.ReadString();
2385 Model
:= M
.ReadString();
2386 Color
.R
:= M
.ReadByte();
2387 Color
.G
:= M
.ReadByte();
2388 Color
.B
:= M
.ReadByte();
2392 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2394 if (Pl
<> nil) then Exit
;
2395 if (g_Force_Model_Get() <> 0) then
2396 Model
:= g_Forced_Model_GetName();
2397 DID
:= g_Player_Create(Model
, Color
, T
, False);
2398 with g_Player_Get(DID
) do
2407 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2408 gPlayer1
.UID
:= PID
;
2409 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2410 gPlayer1
.ChangeTeam(T
);
2412 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2413 gPlayer2
.UID
:= PID
;
2414 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2415 gPlayer2
.ChangeTeam(T
);
2419 if NetDeafLevel
< 3 then
2420 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2421 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2425 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2432 TmpX
, TmpY
: Integer;
2436 GT
:= M
.ReadLongWord();
2437 if GT
< gTime
- NET_MAX_DIFFTIME
then
2444 PID
:= M
.ReadWord();
2445 Pl
:= g_Player_Get(PID
);
2447 if Pl
= nil then Exit
;
2453 FPing
:= M
.ReadWord();
2454 FLoss
:= M
.ReadByte();
2455 kByte
:= M
.ReadWord();
2456 Dir
:= M
.ReadByte();
2458 TmpX
:= M
.ReadLongInt();
2459 TmpY
:= M
.ReadLongInt();
2463 if LongBool(kByte
and NET_KEY_CHAT
) then
2464 PressKey(KEY_CHAT
, 10000)
2467 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2468 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2469 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2470 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2471 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2474 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2476 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2477 SetDirection(TDirection(Dir
));
2479 GameVelX
:= M
.ReadLongInt();
2480 GameVelY
:= M
.ReadLongInt();
2481 GameAccelX
:= M
.ReadLongInt();
2482 GameAccelY
:= M
.ReadLongInt();
2483 SetLerp(TmpX
, TmpY
);
2484 if NetForcePlayerUpdate
then Update();
2488 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2492 I
, OldFire
: Integer;
2493 OldJet
, Flam
: Boolean;
2496 PID
:= M
.ReadWord();
2497 Pl
:= g_Player_Get(PID
);
2504 alive
:= (M
.ReadByte() <> 0);
2505 GodMode
:= (M
.ReadByte() <> 0);
2506 Health
:= M
.ReadLongInt();
2507 Armor
:= M
.ReadLongInt();
2508 Air
:= M
.ReadLongInt();
2509 JetFuel
:= M
.ReadLongInt();
2510 Lives
:= M
.ReadByte();
2511 NewTeam
:= M
.ReadByte();
2513 for I
:= WP_FIRST
to WP_LAST
do
2514 FWeapon
[I
] := (M
.ReadByte() <> 0);
2516 for I
:= A_BULLETS
to A_HIGH
do
2517 FAmmo
[I
] := M
.ReadWord();
2519 for I
:= A_BULLETS
to A_HIGH
do
2520 FMaxAmmo
[I
] := M
.ReadWord();
2522 for I
:= MR_SUIT
to MR_MAX
do
2523 FMegaRulez
[I
] := M
.ReadLongWord();
2526 if (M
.ReadByte() <> 0) then
2527 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2528 if (M
.ReadByte() <> 0) then
2529 FRulez
:= FRulez
+ [R_KEY_RED
];
2530 if (M
.ReadByte() <> 0) then
2531 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2532 if (M
.ReadByte() <> 0) then
2533 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2534 if (M
.ReadByte() <> 0) then
2535 FRulez
:= FRulez
+ [R_BERSERK
];
2537 Frags
:= M
.ReadLongInt();
2538 Death
:= M
.ReadLongInt();
2540 SetWeapon(M
.ReadByte());
2542 FSpectator
:= M
.ReadByte() <> 0;
2545 if UID
= NetPlrUID1
then
2547 gSpectLatchPID1
:= UID
;
2550 if UID
= NetPlrUID2
then
2552 gSpectLatchPID2
:= UID
;
2558 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2561 gSpectLatchPID1
:= 0;
2563 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2566 gSpectLatchPID2
:= 0;
2569 FGhost
:= M
.ReadByte() <> 0;
2570 FPhysics
:= M
.ReadByte() <> 0;
2571 FNoRespawn
:= M
.ReadByte() <> 0;
2573 FJetpack
:= M
.ReadByte() <> 0;
2574 OldFire
:= FFireTime
;
2575 FFireTime
:= M
.ReadLongInt();
2576 if (OldFire
<= 0) and (FFireTime
> 0) then
2577 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2578 Flam
:= M
.ReadByte() <> 0;
2579 FSpawnInvul
:= M
.ReadLongInt();
2580 if OldJet
and not FJetpack
then
2582 else if not OldJet
and FJetpack
then
2584 if FFlaming
and not Flam
then
2586 if Team
<> NewTeam
then
2587 Pl
.ChangeTeam(NewTeam
);
2593 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2598 Attacker
, Value
: Word;
2602 if not gGameOn
then Exit
;
2603 PID
:= M
.ReadWord();
2604 Pl
:= g_Player_Get(PID
);
2605 if Pl
= nil then Exit
;
2607 Kind
:= M
.ReadByte();
2608 Attacker
:= M
.ReadWord();
2609 Value
:= M
.ReadWord();
2614 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2619 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2623 KillType
, DeathType
: Byte;
2627 if not gGameOn
then Exit
;
2628 PID
:= M
.ReadWord();
2629 Pl
:= g_Player_Get(PID
);
2630 if Pl
= nil then Exit
;
2632 KillType
:= M
.ReadByte();
2633 DeathType
:= M
.ReadByte();
2634 Attacker
:= M
.ReadWord();
2638 Kill(KillType
, Attacker
, DeathType
);
2643 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2648 PID
:= M
.ReadWord();
2649 Pl
:= g_Player_Get(PID
);
2651 if Pl
= nil then Exit
;
2653 if NetDeafLevel
< 3 then
2654 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2655 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2657 g_Player_Remove(PID
);
2662 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2667 X
, Y
, AX
, AY
: Integer;
2671 if not gGameOn
then Exit
;
2672 PID
:= M
.ReadWord();
2673 Pl
:= g_Player_Get(PID
);
2674 if Pl
= nil then Exit
;
2676 Weap
:= M
.ReadByte();
2677 X
:= M
.ReadLongInt();
2678 Y
:= M
.ReadLongInt();
2679 AX
:= M
.ReadLongInt();
2680 AY
:= M
.ReadLongInt();
2681 SHID
:= M
.ReadLongInt();
2684 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2687 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2697 PID
:= M
.ReadWord();
2698 Pl
:= g_Player_Get(PID
);
2699 if Pl
= nil then Exit
;
2701 TmpName
:= M
.ReadString();
2702 TmpModel
:= M
.ReadString();
2703 TmpColor
.R
:= M
.ReadByte();
2704 TmpColor
.G
:= M
.ReadByte();
2705 TmpColor
.B
:= M
.ReadByte();
2706 TmpTeam
:= M
.ReadByte();
2708 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2710 Pl
.ChangeTeam(TmpTeam
);
2711 if gPlayer1
= Pl
then
2712 gPlayer1Settings
.Team
:= TmpTeam
;
2713 if gPlayer2
= Pl
then
2714 gPlayer2Settings
.Team
:= TmpTeam
;
2716 Pl
.SetColor(TmpColor
);
2718 if Pl
.Name
<> TmpName
then
2720 if NetDeafLevel
< 3 then
2721 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2725 if (g_Force_Model_Get() <> 0) then
2726 TmpModel
:= g_Forced_Model_GetName();
2727 if TmpModel
<> Pl
.Model
.GetName() then
2728 Pl
.SetModel(TmpModel
);
2733 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2736 X
, Y
, VX
, VY
: Integer;
2738 Quiet
, Fall
{, Resp}: Boolean;
2741 if not gGameOn
then Exit
;
2743 Quiet
:= M
.ReadByte() <> 0;
2745 Fall
:= M
.ReadByte() <> 0;
2746 {Resp :=} M
.ReadByte();
2747 X
:= M
.ReadLongInt();
2748 Y
:= M
.ReadLongInt();
2749 VX
:= M
.ReadLongInt();
2750 VY
:= M
.ReadLongInt();
2752 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2753 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2755 it
:= g_Items_ByIdx(ID
);
2761 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2763 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16);
2768 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2773 if not gGameOn
then Exit
;
2775 Quiet
:= M
.ReadByte() <> 0;
2777 if not g_Items_ValidId(ID
) then exit
;
2779 if not Quiet
then g_Items_EmitPickupSound(ID
);
2784 procedure MC_RECV_ItemPos(var M
: TMsg
);
2787 X
, Y
, VX
, VY
: Integer;
2790 if not gGameOn
then Exit
;
2793 X
:= M
.ReadLongInt();
2794 Y
:= M
.ReadLongInt();
2795 VX
:= M
.ReadLongInt();
2796 VY
:= M
.ReadLongInt();
2798 if g_Items_ValidId(ID
) then
2800 it
:= g_Items_ByIdx(ID
);
2805 it
.positionChanged();
2811 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2818 if not gGameOn
then Exit
;
2820 PGUID
:= Integer(M
.ReadLongWord());
2821 Tex
:= M
.ReadLongInt();
2822 Fr
:= M
.ReadLongInt();
2823 Cnt
:= M
.ReadByte();
2824 Loop
:= M
.ReadByte();
2826 TP
:= g_Map_PanelByGUID(PGUID
);
2830 TP
.SetTexture(Tex
, Loop
);
2831 TP
.SetFrame(Fr
, Cnt
);
2835 procedure MC_RECV_PanelState(var M
: TMsg
);
2840 X
, Y
, W
, H
: Integer;
2842 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2843 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2846 if not gGameOn
then Exit
;
2848 PGUID
:= Integer(M
.ReadLongWord());
2849 E
:= (M
.ReadByte() <> 0);
2850 Lift
:= M
.ReadByte();
2851 X
:= M
.ReadLongInt();
2852 Y
:= M
.ReadLongInt();
2856 speedX
:= M
.ReadLongInt();
2857 speedY
:= M
.ReadLongInt();
2858 startX
:= M
.ReadLongInt();
2859 startY
:= M
.ReadLongInt();
2860 endX
:= M
.ReadLongInt();
2861 endY
:= M
.ReadLongInt();
2862 sizeSpX
:= M
.ReadLongInt();
2863 sizeSpY
:= M
.ReadLongInt();
2864 sizeEX
:= M
.ReadLongInt();
2865 sizeEY
:= M
.ReadLongInt();
2866 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2868 TP
:= g_Map_PanelByGUID(PGUID
);
2869 if (TP
= nil) then exit
;
2871 // update lifts state
2872 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2874 // update enabled/disabled state for all panels
2875 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2877 // update panel position, as it can be moved (mplat)
2882 // update mplat state
2883 TP
.movingSpeedX
:= speedX
;
2884 TP
.movingSpeedY
:= speedY
;
2885 TP
.movingStartX
:= startX
;
2886 TP
.movingStartY
:= startY
;
2887 TP
.movingEndX
:= endX
;
2888 TP
.movingEndY
:= endY
;
2889 TP
.sizeSpeedX
:= sizeSpX
;
2890 TP
.sizeSpeedY
:= sizeSpY
;
2891 TP
.sizeEndX
:= sizeEX
;
2892 TP
.sizeEndY
:= sizeEY
;
2893 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2894 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2895 // notify panel of it's position/size change, so it can fix other internal structures
2896 TP
.positionChanged();
2901 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2904 SPos
, SID
: LongWord;
2908 if not gGameOn
then Exit
;
2909 if gTriggers
= nil then Exit
;
2911 SID
:= M
.ReadLongWord();
2912 SPlaying
:= M
.ReadByte() <> 0;
2913 SPos
:= M
.ReadLongWord();
2914 SCount
:= M
.ReadLongInt();
2916 for I
:= Low(gTriggers
) to High(gTriggers
) do
2917 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2918 if gTriggers
[I
].ClientID
= SID
then
2919 with gTriggers
[I
] do
2921 if Sound
<> nil then
2926 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2928 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2929 Sound
.SetPosition(SPos
);
2932 if Sound
.IsPlaying
then Sound
.Stop
;
2935 SoundPlayCount
:= SCount
;
2939 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2946 if not gGameOn
then Exit
;
2948 MName
:= M
.ReadString();
2949 MPlaying
:= M
.ReadByte() <> 0;
2950 MPos
:= M
.ReadLongWord();
2951 MPaused
:= M
.ReadByte() <> 0;
2952 MPos
:= MPos
+1; //k8: stfu, fpc!
2956 gMusic
.SetByName(MName
);
2958 // gMusic.SetPosition(MPos);
2959 gMusic
.SpecPause
:= MPaused
;
2962 if gMusic
.IsPlaying
then gMusic
.Stop
;
2967 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2970 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2971 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2976 Mon
:= g_Monsters_ByUID(ID
);
2980 MType
:= M
.ReadByte();
2981 MState
:= M
.ReadByte();
2982 MAnim
:= M
.ReadByte();
2983 MTarg
:= M
.ReadWord();
2984 MTargTime
:= M
.ReadLongInt();
2985 MBehav
:= M
.ReadByte();
2986 MSleep
:= M
.ReadLongInt();
2987 MHealth
:= M
.ReadLongInt();
2988 MAmmo
:= M
.ReadLongInt();
2990 X
:= M
.ReadLongInt();
2991 Y
:= M
.ReadLongInt();
2992 VX
:= M
.ReadLongInt();
2993 VY
:= M
.ReadLongInt();
2994 MDir
:= M
.ReadByte();
2996 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2997 Mon
:= g_Monsters_ByUID(ID
);
3004 MonsterAnim
:= MAnim
;
3005 MonsterTargetUID
:= MTarg
;
3006 MonsterTargetTime
:= MTargTime
;
3007 MonsterBehaviour
:= MBehav
;
3008 MonsterSleep
:= MSleep
;
3009 MonsterAmmo
:= MAmmo
;
3014 setPosition(X
, Y
); // this will call positionChanged();
3020 procedure MC_RECV_MonsterPos(var M
: TMsg
);
3027 Mon
:= g_Monsters_ByUID(ID
);
3033 X
:= M
.ReadLongInt();
3034 Y
:= M
.ReadLongInt();
3035 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
3036 GameVelX
:= M
.ReadLongInt();
3037 GameVelY
:= M
.ReadLongInt();
3038 GameDirection
:= TDirection(M
.ReadByte());
3042 procedure MC_RECV_MonsterState(var M
: TMsg
);
3044 ID
, OldFire
: Integer;
3045 MState
, MFAnm
: Byte;
3047 AnimRevert
: Boolean;
3050 Mon
:= g_Monsters_ByUID(ID
);
3051 if Mon
= nil then Exit
;
3053 MState
:= M
.ReadByte();
3054 MFAnm
:= M
.ReadByte();
3058 MonsterTargetUID
:= M
.ReadWord();
3059 MonsterTargetTime
:= M
.ReadLongInt();
3060 MonsterSleep
:= M
.ReadLongInt();
3061 MonsterHealth
:= M
.ReadLongInt();
3062 MonsterAmmo
:= M
.ReadLongInt();
3063 MonsterPain
:= M
.ReadLongInt();
3064 AnimRevert
:= M
.ReadByte() <> 0;
3065 OldFire
:= FFireTime
;
3066 FFireTime
:= M
.ReadLongInt();
3067 if (OldFire
<= 0) and (FFireTime
> 0) then
3068 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3069 RevertAnim(AnimRevert
);
3071 if MonsterState
<> MState
then
3073 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3074 if (MState
= MONSTATE_DIE
) then DieSound();
3075 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3076 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3077 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3079 SetState(MState
, MFAnm
);
3084 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3088 X
, Y
, VX
, VY
: Integer;
3092 Mon
:= g_Monsters_ByUID(ID
);
3093 if Mon
= nil then Exit
;
3095 X
:= M
.ReadLongInt();
3096 Y
:= M
.ReadLongInt();
3097 VX
:= M
.ReadLongInt();
3098 VY
:= M
.ReadLongInt();
3100 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3103 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3109 Mon
:= g_Monsters_ByUID(ID
);
3110 if Mon
= nil then Exit
;
3112 Mon
.MonsterRemoved
:= True;
3115 procedure MC_RECV_TimeSync(var M
: TMsg
);
3119 Time
:= M
.ReadLongWord();
3121 if gState
= STATE_INTERCUSTOM
then
3122 gServInterTime
:= Min(Time
, 255);
3125 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3129 Int1
, Int2
: SmallInt;
3131 EvID
:= M
.ReadByte();
3132 Int1
:= M
.ReadSmallInt();
3133 Int2
:= M
.ReadSmallInt();
3134 Str1
:= M
.ReadString();
3135 Str2
:= M
.ReadString();
3137 if NetDeafLevel
< 2 then
3140 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3142 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3144 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3146 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3148 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3154 procedure MC_SEND_Info(Password
: string);
3159 NetOut
.Write(Byte(NET_MSG_INFO
));
3160 NetOut
.Write(GAME_VERSION
);
3161 NetOut
.Write(Password
);
3162 NetOut
.Write(gPlayer1Settings
.Name
);
3163 NetOut
.Write(gPlayer1Settings
.Model
);
3164 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3165 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3166 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3167 NetOut
.Write(gPlayer1Settings
.Team
);
3168 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3169 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3170 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3171 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3172 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3174 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3177 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3179 NetOut
.Write(Byte(NET_MSG_CHAT
));
3183 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3186 procedure MC_SEND_PlayerPos();
3191 WeaponAct
: Byte = 0;
3192 WeaponSelect
: Word = 0;
3195 if not gGameOn
then Exit
;
3196 if gPlayers
= nil then Exit
;
3197 if gPlayer1
= nil then Exit
;
3200 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3202 {$IFDEF DISABLE_MENU}
3203 if (not gConsoleShow
) and (not gChatShow
) then
3205 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3208 strafeDir
:= P1MoveButton
shr 4;
3209 P1MoveButton
:= P1MoveButton
and $0F;
3211 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3213 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3215 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3219 if gPlayerAction
[0, ACTION_STRAFE
] then
3221 // new strafe mechanics
3222 if (strafeDir
= 0) then
3223 strafeDir
:= P1MoveButton
; // start strafing
3224 // now set direction according to strafe (reversed)
3225 if (strafeDir
= 2) then
3226 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3227 else if (strafeDir
= 1) then
3228 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3232 strafeDir
:= 0; // not strafing anymore
3233 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3234 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3235 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3236 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3237 else if P1MoveButton
<> 0 then
3238 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3241 gPlayer1
.ReleaseKeys
;
3242 if P1MoveButton
= 1 then
3244 kByte
:= kByte
or NET_KEY_LEFT
;
3245 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3247 if P1MoveButton
= 2 then
3249 kByte
:= kByte
or NET_KEY_RIGHT
;
3250 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3252 if gPlayerAction
[0, ACTION_LOOKUP
] then
3254 kByte
:= kByte
or NET_KEY_UP
;
3255 gPlayer1
.PressKey(KEY_UP
, 10000);
3257 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3259 kByte
:= kByte
or NET_KEY_DOWN
;
3260 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3262 if gPlayerAction
[0, ACTION_JUMP
] then
3264 kByte
:= kByte
or NET_KEY_JUMP
;
3265 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3267 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3268 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3270 for i
:= WP_FACT
to WP_LACT
do
3272 if gWeaponAction
[0, i
] then
3274 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3275 gWeaponAction
[0, i
] := False
3279 for i
:= WP_FIRST
to WP_LAST
do
3281 if gSelectWeapon
[0, i
] then
3283 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3284 gSelectWeapon
[0, i
] := False
3288 // fix movebutton state
3289 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3292 kByte
:= NET_KEY_CHAT
;
3294 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3295 NetOut
.Write(gTime
);
3296 NetOut
.Write(kByte
);
3297 NetOut
.Write(Byte(gPlayer1
.Direction
));
3298 NetOut
.Write(WeaponAct
);
3299 NetOut
.Write(WeaponSelect
);
3300 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3301 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3303 //kBytePrev := kByte;
3304 //kDirPrev := gPlayer1.Direction;
3307 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3309 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3310 NetOut
.Write(Byte(Start
));
3311 NetOut
.Write(Command
);
3312 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3315 procedure MC_SEND_PlayerSettings();
3318 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3319 NetOut
.Write(gPlayer1Settings
.Name
);
3320 NetOut
.Write(gPlayer1Settings
.Model
);
3321 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3322 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3323 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3324 NetOut
.Write(gPlayer1Settings
.Team
);
3325 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3326 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3327 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3328 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3329 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3331 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3334 procedure MC_SEND_FullStateRequest();
3336 NetOut
.Write(Byte(NET_MSG_REQFST
));
3338 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3341 procedure MC_SEND_CheatRequest(Kind
: Byte);
3343 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3346 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3348 procedure MC_SEND_RCONPassword(Password
: string);
3350 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3351 NetOut
.Write(Password
);
3353 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3355 procedure MC_SEND_RCONCommand(Cmd
: string);
3357 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3360 g_Net_Client_Send(True, NET_CHAN_SERVICE
);