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 if (WeapSwitch
= 2) then
404 for I
:= WP_FIRST
to WP_LAST
+ 1 do
405 TmpPrefArray
[I
] := M
.ReadByte();
406 SwitchEmpty
:= M
.ReadByte();
407 SkipF
:= M
.ReadByte();
412 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
414 if Ver
<> GAME_VERSION
then
416 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
417 _lc
[I_NET_DISC_VERSION
]);
418 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
422 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
424 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
426 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
427 _lc
[I_NET_DISC_BAN
]);
428 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
432 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
433 _lc
[I_NET_DISC_BAN
]);
434 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
439 if NetPassword
<> '' then
440 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
442 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
443 _lc
[I_NET_DISC_PASSWORD
]);
444 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
448 if (C
^.Player
<> 0) then
450 // already received info
451 g_Net_Penalize(C
, 'client info spam');
459 PID
:= g_Player_Create(Model
, Color
, T
, False);
460 with g_Player_Get(PID
) do
463 WeapSwitchMode
:= WeapSwitch
;
464 if (WeapSwitch
= 2) then
465 SetWeaponPrefs(TmpPrefArray
);
466 SwitchToEmpty
:= SwitchEmpty
;
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]);
562 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
566 C
^.RequestedFullUpdate
:= True;
572 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
585 if not gGameOn
then Exit
;
588 GT
:= M
.ReadLongWord();
593 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
596 Pl
:= g_Player_Get(PID
);
600 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
606 kByte
:= M
.ReadWord();
608 WeaponAct
:= M
.ReadByte();
609 WeaponSelect
:= M
.ReadWord();
614 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
616 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
617 if Direction
<> TDirection(Dir
) then
618 JustTeleported
:= False;
620 SetDirection(TDirection(Dir
));
623 if kByte
= NET_KEY_CHAT
then
625 PressKey(KEY_CHAT
, 10000);
629 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
630 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
631 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
632 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
633 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
634 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
635 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
639 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
641 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
642 ProcessWeaponAction(i
);
648 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
650 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
651 QueueWeaponSwitch(i
);
656 // MH_SEND_PlayerPos(False, PID, C^.ID);
659 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
666 Pl
:= g_Player_Get(C
^.Player
);
667 if Pl
= nil then Exit
;
670 CheatKind
:= M
.ReadByte();
675 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
679 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
682 if Pl
.FSpectator
then
684 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
687 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
694 if gState
<> STATE_INTERCUSTOM
then Exit
;
695 Pl
.FReady
:= not Pl
.FReady
;
698 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
699 Inc(gInterReadyCount
);
703 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
704 Dec(gInterReadyCount
);
712 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
719 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
728 TmpName
:= M
.ReadString();
729 TmpModel
:= M
.ReadString();
730 TmpColor
.R
:= M
.ReadByte();
731 TmpColor
.G
:= M
.ReadByte();
732 TmpColor
.B
:= M
.ReadByte();
733 TmpTeam
:= M
.ReadByte();
734 TmpWeapSwitch
:= M
.ReadByte();
735 if (TmpWeapSwitch
= 2) then
736 for I
:= WP_FIRST
to WP_LAST
+ 1 do
737 TmpPrefArray
[I
] := M
.ReadByte();
738 TmpSwEmpty
:= M
.ReadByte();
739 TmpSkipF
:= M
.ReadByte();
744 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
746 Pl
:= g_Player_Get(C
^.Player
);
747 if Pl
= nil then Exit
;
749 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
752 Pl
.SetColor(TmpColor
);
754 if Pl
.Name
<> TmpName
then
756 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
760 if TmpModel
<> Pl
.Model
.Name
then
761 Pl
.SetModel(TmpModel
);
763 if (TmpWeapSwitch
<> Pl
.WeapSwitchMode
) then
764 Pl
.WeapSwitchMode
:= TmpWeapSwitch
;
766 if (TmpWeapSwitch
= 2) then
767 Pl
.SetWeaponPrefs(TmpPrefArray
);
769 if (TmpSwEmpty
<> Pl
.SwitchToEmpty
) then
770 Pl
.SwitchToEmpty
:= TmpSwEmpty
;
772 if (TmpSkipF
<> Pl
.SkipFist
) then
773 Pl
.SkipFist
:= TmpSkipF
;
775 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
780 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
787 Pwd
:= M
.ReadString();
791 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
792 if not NetAllowRCON
then Exit
;
793 if Pwd
= NetRCONPassword
then
796 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
799 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
802 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
809 Cmd
:= M
.ReadString();
813 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
814 if not NetAllowRCON
then Exit
;
815 if not C
^.RCONAuth
then
817 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
820 g_Console_Process(Cmd
);
825 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
828 Name
, Command
: string;
835 Start
:= M
.ReadByte() <> 0;
836 Command
:= M
.ReadString();
841 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
843 Pl
:= g_Player_Get(C
^.Player
);
844 if Pl
= nil then Exit
;
849 if not g_Console_CommandBlacklisted(Command
) then
850 g_Game_StartVote(Command
, Name
);
852 else if gVoteInProgress
then
854 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
855 Need
:= Floor((NetClientCount
+1)/2.0) + 1
857 Need
:= Floor(NetClientCount
/2.0) + 1;
862 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
863 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
869 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
870 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
878 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
880 function sendItemRespawn (it
: PItem
): Boolean;
882 result
:= false; // don't stop
883 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
886 function sendMonSpawn (mon
: TMonster
): Boolean;
888 result
:= false; // don't stop
889 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
892 function sendPanelState (pan
: TPanel
): Boolean;
894 result
:= false; // don't stop
895 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
896 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
902 if (ID
>= 0) and (ID
< length(NetClients
)) then
904 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
905 MH_ProcessFirstSpawn(@NetClients
[ID
]);
908 if gPlayers
<> nil then
910 for I
:= Low(gPlayers
) to High(gPlayers
) do
912 if gPlayers
[I
] <> nil then
914 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
915 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
916 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
918 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
920 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
926 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
927 g_Mons_ForEach(sendMonSpawn
);
928 g_Map_ForEachPanel(sendPanelState
);
930 if gTriggers
<> nil then
932 for I
:= Low(gTriggers
) to High(gTriggers
) do
934 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
936 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
943 for I
:= Low(Shots
) to High(Shots
) do
945 if Shots
[i
].ShotType
in [6, 7, 8] then
947 MH_SEND_CreateShot(i
, ID
);
952 MH_SEND_TriggerMusic(ID
);
954 MH_SEND_GameStats(ID
);
955 MH_SEND_CoopStats(ID
);
957 if gGameSettings
.GameMode
= GM_CTF
then
959 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
960 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
963 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
968 procedure MH_SEND_Info(ID
: Byte);
972 NetOut
.Write(Byte(NET_MSG_INFO
));
974 NetOut
.Write(NetClients
[ID
].Player
);
975 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
976 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
977 NetOut
.Write(gWADHash
);
978 NetOut
.Write(gGameSettings
.GameMode
);
979 NetOut
.Write(gGameSettings
.GoalLimit
);
980 NetOut
.Write(gGameSettings
.TimeLimit
);
981 NetOut
.Write(gGameSettings
.MaxLives
);
982 NetOut
.Write(gGameSettings
.Options
);
985 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
988 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
994 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
995 Mode
:= NET_CHAT_PLAYER
;
998 if (Mode
= NET_CHAT_TEAM
) then
1000 for i
:= Low(gPlayers
) to High(gPlayers
) do
1001 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
1002 (gPlayers
[i
].Team
= ID
) then
1004 NetOut
.Write(Byte(NET_MSG_CHAT
));
1007 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
1014 NetOut
.Write(Byte(NET_MSG_CHAT
));
1017 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
1020 if Mode
= NET_CHAT_SYSTEM
then
1023 if ID
= NET_EVERYONE
then
1025 if Mode
= NET_CHAT_PLAYER
then
1027 g_Console_Add(Txt
, True);
1028 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1029 g_Game_ChatSound(b_Text_Unformat(Txt
));
1032 if Mode
= NET_CHAT_TEAM
then
1033 if gPlayer1
<> nil then
1035 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
1037 g_Console_Add(#18'[Team] '#2 + Txt
, True);
1038 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1039 g_Game_ChatSound(b_Text_Unformat(Txt
));
1041 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
1043 g_Console_Add(#20'[Team] '#2 + Txt
, True);
1044 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1045 g_Game_ChatSound(b_Text_Unformat(Txt
));
1051 Name
:= g_Net_ClientName_ByID(ID
);
1052 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1053 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1054 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1058 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1060 NetOut
.Write(Byte(NET_MSG_GFX
));
1066 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1069 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1071 NetOut
.Write(Byte(NET_MSG_SND
));
1075 NetOut
.Write(Byte(1));
1080 NetOut
.Write(Byte(0));
1082 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1085 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1087 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1089 NetOut
.Write(Byte(NET_MSG_SHADD
));
1091 NetOut
.Write(Shots
[Proj
].ShotType
);
1092 NetOut
.Write(Shots
[Proj
].Target
);
1093 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1094 NetOut
.Write(Shots
[Proj
].Timeout
);
1095 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1096 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1097 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1098 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1100 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1103 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1105 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1107 NetOut
.Write(Byte(NET_MSG_SHPOS
));
1109 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1110 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1111 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1112 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1114 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
1117 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1119 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1121 NetOut
.Write(Byte(Loud
));
1125 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1128 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1130 NetOut
.Write(Byte(NET_MSG_SCORE
));
1131 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1133 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1134 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1137 if gGameSettings
.GameMode
= GM_COOP
then
1139 NetOut
.Write(gCoopMonstersKilled
);
1140 NetOut
.Write(gCoopSecretsFound
);
1143 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1146 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1148 NetOut
.Write(Byte(NET_MSG_COOP
));
1149 NetOut
.Write(gTotalMonsters
);
1150 NetOut
.Write(gSecretsCount
);
1151 NetOut
.Write(gCoopTotalMonstersKilled
);
1152 NetOut
.Write(gCoopTotalSecretsFound
);
1153 NetOut
.Write(gCoopTotalMonsters
);
1154 NetOut
.Write(gCoopTotalSecrets
);
1157 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1159 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1160 NetOut
.Write(EvType
);
1161 NetOut
.Write(EvNum
);
1162 NetOut
.Write(EvStr
);
1163 NetOut
.Write(Byte(gLastMap
));
1164 NetOut
.Write(gTime
);
1165 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1167 NetOut
.Write(Byte(1));
1168 NetOut
.Write(gWADHash
);
1170 NetOut
.Write(Byte(0));
1172 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1175 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1177 NetOut
.Write(Byte(NET_MSG_FLAG
));
1178 NetOut
.Write(EvType
);
1180 NetOut
.Write(Byte(Quiet
));
1182 NetOut
.Write(gFlags
[Flag
].State
);
1183 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1184 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1185 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1186 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1187 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1188 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1190 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1193 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1195 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1197 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1198 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1199 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1200 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1202 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1205 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1207 NetOut
.Write(Byte(NET_MSG_GSET
));
1208 NetOut
.Write(gGameSettings
.GameMode
);
1209 NetOut
.Write(gGameSettings
.GoalLimit
);
1210 NetOut
.Write(gGameSettings
.TimeLimit
);
1211 NetOut
.Write(gGameSettings
.MaxLives
);
1212 NetOut
.Write(gGameSettings
.Options
);
1214 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1219 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1223 P
:= g_Player_Get(PID
);
1224 if P
= nil then Exit
;
1226 NetOut
.Write(Byte(NET_MSG_PLR
));
1228 NetOut
.Write(P
.Name
);
1230 NetOut
.Write(P
.FActualModelName
);
1231 NetOut
.Write(P
.FColor
.R
);
1232 NetOut
.Write(P
.FColor
.G
);
1233 NetOut
.Write(P
.FColor
.B
);
1234 NetOut
.Write(P
.Team
);
1236 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1239 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1244 Pl
:= g_Player_Get(PID
);
1245 if Pl
= nil then Exit
;
1246 if Pl
.FDummy
then Exit
;
1248 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1249 NetOut
.Write(gTime
);
1256 NetOut
.Write(FPing
);
1257 NetOut
.Write(FLoss
);
1258 if IsKeyPressed(KEY_CHAT
) then
1259 kByte
:= NET_KEY_CHAT
1262 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1263 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1264 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1265 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1266 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1269 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1271 NetOut
.Write(kByte
);
1272 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1273 NetOut
.Write(GameX
);
1274 NetOut
.Write(GameY
);
1275 NetOut
.Write(GameVelX
);
1276 NetOut
.Write(GameVelY
);
1277 NetOut
.Write(GameAccelX
);
1278 NetOut
.Write(GameAccelY
);
1281 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1284 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1289 P
:= g_Player_Get(PID
);
1290 if P
= nil then Exit
;
1292 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1297 NetOut
.Write(Byte(alive
));
1298 NetOut
.Write(Byte(GodMode
));
1299 NetOut
.Write(Health
);
1300 NetOut
.Write(Armor
);
1302 NetOut
.Write(JetFuel
);
1303 NetOut
.Write(Lives
);
1306 for I
:= WP_FIRST
to WP_LAST
do
1307 NetOut
.Write(Byte(FWeapon
[I
]));
1309 for I
:= A_BULLETS
to A_HIGH
do
1310 NetOut
.Write(FAmmo
[I
]);
1312 for I
:= A_BULLETS
to A_HIGH
do
1313 NetOut
.Write(FMaxAmmo
[I
]);
1315 for I
:= MR_SUIT
to MR_MAX
do
1316 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1318 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1319 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1320 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1321 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1322 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1324 NetOut
.Write(Frags
);
1325 NetOut
.Write(Death
);
1327 NetOut
.Write(CurrWeap
);
1329 NetOut
.Write(Byte(FSpectator
));
1330 NetOut
.Write(Byte(FGhost
));
1331 NetOut
.Write(Byte(FPhysics
));
1332 NetOut
.Write(Byte(FNoRespawn
));
1333 NetOut
.Write(Byte(FJetpack
));
1334 NetOut
.Write(FFireTime
);
1335 NetOut
.Write(Byte(FFlaming
));
1336 NetOut
.Write(FSpawnInvul
);
1339 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1342 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1344 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1347 NetOut
.Write(Attacker
);
1348 NetOut
.Write(Value
);
1352 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1355 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1357 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1359 NetOut
.Write(KillType
);
1360 NetOut
.Write(DeathType
);
1361 NetOut
.Write(Attacker
);
1363 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1366 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1368 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1370 NetOut
.Write(Weapon
);
1375 NetOut
.Write(ShotID
);
1377 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1380 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1382 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1385 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1388 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1392 Pl
:= g_Player_Get(PID
);
1393 if Pl
= nil then Exit
;
1395 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1397 NetOut
.Write(Pl
.Name
);
1399 NetOut
.Write(Pl
.Model
.Name
)
1402 NetOut
.Write(Pl
.FColor
.R
);
1403 NetOut
.Write(Pl
.FColor
.G
);
1404 NetOut
.Write(Pl
.FColor
.B
);
1405 NetOut
.Write(Pl
.Team
);
1407 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1412 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1417 it
:= g_Items_ByIdx(IID
);
1419 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1421 NetOut
.Write(Byte(Quiet
));
1423 if it
.dropped
then tt
:= tt
or $80;
1425 NetOut
.Write(Byte(it
.Fall
));
1426 NetOut
.Write(Byte(it
.Respawnable
));
1427 NetOut
.Write(it
.Obj
.X
);
1428 NetOut
.Write(it
.Obj
.Y
);
1429 NetOut
.Write(it
.Obj
.Vel
.X
);
1430 NetOut
.Write(it
.Obj
.Vel
.Y
);
1432 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1435 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1437 NetOut
.Write(Byte(NET_MSG_IDEL
));
1439 NetOut
.Write(Byte(Quiet
));
1441 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1444 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1448 it
:= g_Items_ByIdx(IID
);
1450 NetOut
.Write(Byte(NET_MSG_IPOS
));
1452 NetOut
.Write(it
.Obj
.X
);
1453 NetOut
.Write(it
.Obj
.Y
);
1454 NetOut
.Write(it
.Obj
.Vel
.X
);
1455 NetOut
.Write(it
.Obj
.Vel
.Y
);
1457 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1462 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1466 TP
:= g_Map_PanelByGUID(PGUID
);
1467 if (TP
= nil) then exit
;
1471 NetOut
.Write(Byte(NET_MSG_PTEX
));
1472 NetOut
.Write(LongWord(PGUID
));
1473 NetOut
.Write(FCurTexture
);
1474 NetOut
.Write(FCurFrame
);
1475 NetOut
.Write(FCurFrameCount
);
1476 NetOut
.Write(AnimLoop
);
1479 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1482 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1487 TP
:= g_Map_PanelByGUID(PGUID
);
1488 if (TP
= nil) then exit
;
1490 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1491 NetOut
.Write(LongWord(PGUID
));
1492 NetOut
.Write(Byte(TP
.Enabled
));
1493 NetOut
.Write(TP
.LiftType
);
1496 NetOut
.Write(Word(TP
.Width
));
1497 NetOut
.Write(Word(TP
.Height
));
1499 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1500 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1501 NetOut
.Write(LongInt(TP
.movingStartX
));
1502 NetOut
.Write(LongInt(TP
.movingStartY
));
1503 NetOut
.Write(LongInt(TP
.movingEndX
));
1504 NetOut
.Write(LongInt(TP
.movingEndY
));
1505 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1506 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1507 NetOut
.Write(LongInt(TP
.sizeEndX
));
1508 NetOut
.Write(LongInt(TP
.sizeEndY
));
1509 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1510 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1511 NetOut
.Write(Byte(mpflags
));
1513 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1518 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1520 if gTriggers
= nil then Exit
;
1521 if T
.Sound
= nil then Exit
;
1523 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1524 NetOut
.Write(T
.ClientID
);
1525 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1526 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1527 NetOut
.Write(T
.SoundPlayCount
);
1529 g_Net_Host_Send(ID
, True);
1532 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1534 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1535 NetOut
.Write(gMusic
.Name
);
1536 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1537 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1538 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1540 g_Net_Host_Send(ID
, True);
1545 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1549 M
:= g_Monsters_ByUID(UID
);
1555 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1557 NetOut
.Write(MonsterType
);
1558 NetOut
.Write(MonsterState
);
1559 NetOut
.Write(MonsterAnim
);
1560 NetOut
.Write(MonsterTargetUID
);
1561 NetOut
.Write(MonsterTargetTime
);
1562 NetOut
.Write(MonsterBehaviour
);
1563 NetOut
.Write(MonsterSleep
);
1564 NetOut
.Write(MonsterHealth
);
1565 NetOut
.Write(MonsterAmmo
);
1566 NetOut
.Write(GameX
);
1567 NetOut
.Write(GameY
);
1568 NetOut
.Write(GameVelX
);
1569 NetOut
.Write(GameVelY
);
1570 NetOut
.Write(Byte(GameDirection
));
1573 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1576 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1580 M
:= g_Monsters_ByUID(UID
);
1581 if M
= nil then Exit
;
1583 NetOut
.Write(Byte(NET_MSG_MPOS
));
1588 NetOut
.Write(GameX
);
1589 NetOut
.Write(GameY
);
1590 NetOut
.Write(GameVelX
);
1591 NetOut
.Write(GameVelY
);
1592 NetOut
.Write(Byte(GameDirection
));
1595 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1598 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1602 M
:= g_Monsters_ByUID(UID
);
1603 if M
= nil then Exit
;
1605 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1610 NetOut
.Write(MonsterState
);
1611 NetOut
.Write(ForcedAnim
);
1612 NetOut
.Write(MonsterTargetUID
);
1613 NetOut
.Write(MonsterTargetTime
);
1614 NetOut
.Write(MonsterSleep
);
1615 NetOut
.Write(MonsterHealth
);
1616 NetOut
.Write(MonsterAmmo
);
1617 NetOut
.Write(MonsterPain
);
1618 NetOut
.Write(Byte(AnimIsReverse
));
1619 NetOut
.Write(FFireTime
);
1622 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1625 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1627 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1634 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1637 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1641 M
:= g_Monsters_ByUID(UID
);
1642 if M
= nil then Exit
;
1644 NetOut
.Write(Byte(NET_MSG_MDEL
));
1647 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1652 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1654 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1657 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1660 procedure MH_SEND_VoteEvent(EvType
: Byte;
1661 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1662 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1663 ID
: Integer = NET_EVERYONE
);
1665 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1666 NetOut
.Write(EvType
);
1667 NetOut
.Write(IntArg1
);
1668 NetOut
.Write(IntArg2
);
1669 NetOut
.Write(StrArg1
);
1670 NetOut
.Write(StrArg2
);
1672 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1675 // CLIENT MESSAGES //
1679 procedure MC_RECV_Chat(var M
: TMsg
);
1684 Txt
:= M
.ReadString();
1685 Mode
:= M
.ReadByte();
1687 if Mode
<> NET_CHAT_SYSTEM
then
1689 if NetDeafLevel
= 0 then
1691 if Mode
= NET_CHAT_PLAYER
then
1693 g_Console_Add(Txt
, True);
1694 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1695 g_Game_ChatSound(b_Text_Unformat(Txt
));
1697 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1699 if gPlayer1
.Team
= TEAM_RED
then
1700 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1701 if gPlayer1
.Team
= TEAM_BLUE
then
1702 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1703 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1704 g_Game_ChatSound(b_Text_Unformat(Txt
));
1707 end else if (NetDeafLevel
< 2) then
1708 g_Console_Add(Txt
, True);
1711 procedure MC_RECV_Effect(var M
: TMsg
);
1719 if not gGameOn
then Exit
;
1720 Kind
:= M
.ReadByte();
1721 X
:= M
.ReadLongInt();
1722 Y
:= M
.ReadLongInt();
1723 Ang
:= M
.ReadSmallInt();
1727 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1731 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1733 Anim
:= TAnimation
.Create(ID
, False, 3);
1734 g_GFX_OnceAnim(X
, Y
, Anim
);
1738 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1743 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1745 Anim
:= TAnimation
.Create(ID
, False, 6);
1746 Anim
.Blending
:= False;
1747 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1751 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1756 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1758 Anim
:= TAnimation
.Create(ID
, False, 6);
1759 Anim
.Blending
:= False;
1760 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1764 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1769 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1771 Anim
:= TAnimation
.Create(ID
, False, 4);
1772 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1779 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1781 Anim
:= TAnimation
.Create(ID
, False, 4);
1782 g_GFX_OnceAnim(X
, Y
, Anim
);
1786 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1791 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1793 Anim
:= TAnimation
.Create(ID
, False, 4);
1794 g_GFX_OnceAnim(X
, Y
, Anim
);
1798 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1802 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1805 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1809 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1810 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1815 procedure MC_RECV_Sound(var M
: TMsg
);
1821 Name
:= M
.ReadString();
1822 Pos
:= M
.ReadByte() <> 0;
1825 X
:= M
.ReadLongInt();
1826 Y
:= M
.ReadLongInt();
1827 g_Sound_PlayExAt(Name
, X
, Y
);
1830 g_Sound_PlayEx(Name
);
1833 procedure MC_RECV_CreateShot(var M
: TMsg
);
1835 I
, X
, Y
, XV
, YV
: Integer;
1837 Target
, Spawner
: Word;
1840 I
:= M
.ReadLongInt();
1841 ShType
:= M
.ReadByte();
1842 Target
:= M
.ReadWord();
1843 Spawner
:= M
.ReadWord();
1844 Timeout
:= M
.ReadLongWord();
1845 X
:= M
.ReadLongInt();
1846 Y
:= M
.ReadLongInt();
1847 XV
:= M
.ReadLongInt();
1848 YV
:= M
.ReadLongInt();
1850 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1851 if (Shots
<> nil) and (I
<= High(Shots
)) then
1853 Shots
[I
].Timeout
:= Timeout
;
1854 //Shots[I].Target := Target; // TODO: find a use for Target later
1858 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1860 I
, TX
, TY
, TXV
, TYV
: Integer;
1862 I
:= M
.ReadLongInt();
1863 TX
:= M
.ReadLongInt();
1864 TY
:= M
.ReadLongInt();
1865 TXV
:= M
.ReadLongInt();
1866 TYV
:= M
.ReadLongInt();
1868 if (Shots
<> nil) and (I
<= High(Shots
)) then
1878 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1883 if not gGameOn
then Exit
;
1884 I
:= M
.ReadLongInt();
1885 L
:= (M
.ReadByte() <> 0);
1886 X
:= M
.ReadLongInt();
1887 Y
:= M
.ReadLongInt();
1889 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1892 procedure MC_RECV_GameStats(var M
: TMsg
);
1894 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1896 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1897 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1900 if gGameSettings
.GameMode
= GM_COOP
then
1902 gCoopMonstersKilled
:= M
.ReadWord();
1903 gCoopSecretsFound
:= M
.ReadWord();
1907 procedure MC_RECV_CoopStats(var M
: TMsg
);
1909 gTotalMonsters
:= M
.ReadLongInt();
1910 gSecretsCount
:= M
.ReadLongInt();
1911 gCoopTotalMonstersKilled
:= M
.ReadWord();
1912 gCoopTotalSecretsFound
:= M
.ReadWord();
1913 gCoopTotalMonsters
:= M
.ReadWord();
1914 gCoopTotalSecrets
:= M
.ReadWord();
1917 procedure MC_RECV_GameEvent(var M
: TMsg
);
1926 i1
, i2
: TStrings_Locale
;
1929 goodCmd
: Boolean = true;
1931 FillChar(EvHash
, Sizeof(EvHash
), 0);
1932 EvType
:= M
.ReadByte();
1933 EvNum
:= M
.ReadLongInt();
1934 EvStr
:= M
.ReadString();
1935 gLastMap
:= M
.ReadByte() <> 0;
1936 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1937 gStatsPressed
:= True;
1938 EvTime
:= M
.ReadLongWord();
1939 BHash
:= M
.ReadByte() <> 0;
1941 EvHash
:= M
.ReadMD5();
1945 if (g_Res_received_map_start
<> 0) then
1947 if (g_Res_received_map_start
< 0) then exit
;
1950 NET_EV_MAPSTART
: goodCmd
:= true;
1951 NET_EV_MAPEND
: goodCmd
:= true;
1952 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1953 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1954 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1956 if not goodCmd
then exit
;
1962 if (g_Res_received_map_start
<> 0) then
1964 g_Res_received_map_start
:= -1;
1969 g_Game_ClearLoading();
1970 g_Game_StopAllSounds(True);
1972 gSwitchGameMode
:= Byte(EvNum
);
1973 gGameSettings
.GameMode
:= gSwitchGameMode
;
1976 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1978 if not isWadPath(EvStr
) then
1979 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1981 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1985 MC_SEND_FullStateRequest
;
1991 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1992 gLMSRespawnTime
:= 0;
1993 if (g_Res_received_map_start
<> 0) then
1995 g_Res_received_map_start
:= -1;
1999 gMissionFailed
:= EvNum
<> 0;
2000 gExit
:= EXIT_ENDLEVELCUSTOM
;
2008 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
2010 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
2012 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
2018 if NetDeafLevel
< 2 then
2020 if EvNum
= TEAM_RED
then
2021 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
2022 if EvNum
= TEAM_BLUE
then
2023 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
2029 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
2030 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2035 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
2036 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2043 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
2044 gLMSRespawnTime
:= gTime
+ EvNum
;
2045 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2047 else if gPlayer1
= nil then
2049 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2053 NET_EV_LMS_SURVIVOR
:
2054 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2057 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2061 pl
:= g_Player_Get(EvNum
and $FFFF);
2066 cnt
:= (EvNum
shr 16) and $FF;
2067 if Pos('w', EvStr
) = 0 then
2070 if Pos('t', EvStr
) = 0 then
2073 if Pos('-', EvStr
) = 0 then
2075 if Pos('e', EvStr
) = 0 then
2076 i1
:= I_PLAYER_SCORE_ADD_OWN
2078 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2081 if Pos('e', EvStr
) = 0 then
2082 i1
:= I_PLAYER_SCORE_SUB_OWN
2084 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2087 if Pos('r', EvStr
) > 0 then
2088 i2
:= I_PLAYER_SCORE_TO_RED
2090 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2091 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2095 if Pos('-', EvStr
) = 0 then
2096 i1
:= I_PLAYER_SCORE_ADD_TEAM
2098 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2100 if Pos('r', EvStr
) > 0 then
2101 i2
:= I_PLAYER_SCORE_RED
2103 i2
:= I_PLAYER_SCORE_BLUE
;
2104 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2109 if Pos('e', EvStr
) = 0 then
2110 i1
:= I_PLAYER_SCORE_WIN_OWN
2112 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
2114 if Pos('r', EvStr
) > 0 then
2115 i2
:= I_PLAYER_SCORE_TO_RED
2117 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2118 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
2124 if EvNum
= TEAM_RED
then
2125 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2126 if EvNum
= TEAM_BLUE
then
2127 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2128 if EvNum
= -TEAM_RED
then
2129 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2130 if EvNum
= -TEAM_BLUE
then
2131 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2136 g_Player_RemoveAllCorpses
;
2137 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2138 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2142 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2146 if EvNum
= TEAM_RED
then
2147 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2148 if EvNum
= TEAM_BLUE
then
2149 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2153 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2156 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2159 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2162 g_Game_Announce_KillCombo(EvNum
);
2164 NET_EV_PLAYER_TOUCH
:
2166 pl
:= g_Player_Get(EvNum
);
2173 pl
:= g_Player_Get(EvNum
);
2176 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2177 g_Sound_PlayEx('SOUND_GAME_SECRET');
2183 pl
:= g_Player_Get(EvNum
);
2184 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2189 procedure MC_RECV_FlagPos(var M
: TMsg
);
2194 if Fl
= FLAG_NONE
then Exit
;
2195 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2196 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2197 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2198 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2201 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2210 EvType
:= M
.ReadByte();
2213 if Fl
= FLAG_NONE
then Exit
;
2215 Quiet
:= (M
.ReadByte() <> 0);
2216 PID
:= M
.ReadWord();
2218 gFlags
[Fl
].State
:= M
.ReadByte();
2219 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2220 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2221 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2222 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2223 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2224 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2226 Pl
:= g_Player_Get(PID
);
2228 (EvType
<> FLAG_STATE_NORMAL
) and
2229 (EvType
<> FLAG_STATE_DROPPED
) and
2230 (EvType
<> FLAG_STATE_RETURNED
) then
2236 if Quiet
or (Pl
= nil) then Exit
;
2238 if Fl
= FLAG_RED
then
2239 s
:= _lc
[I_PLAYER_FLAG_RED
]
2241 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2243 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2245 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2246 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2247 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2252 if not sound_ret_flag
[a
].IsPlaying() then
2253 sound_ret_flag
[a
].Play();
2256 FLAG_STATE_CAPTURED
:
2258 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2262 if Fl
= FLAG_RED
then
2263 s
:= _lc
[I_PLAYER_FLAG_RED
]
2265 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2267 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2268 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2270 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2271 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2272 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2277 if not sound_get_flag
[a
].IsPlaying() then
2278 sound_get_flag
[a
].Play();
2283 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2285 if Quiet
or (Pl
= nil) then Exit
;
2287 if Fl
= FLAG_RED
then
2288 s
:= _lc
[I_PLAYER_FLAG_RED
]
2290 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2292 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2293 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2295 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2296 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2297 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2302 if not sound_lost_flag
[a
].IsPlaying() then
2303 sound_lost_flag
[a
].Play();
2308 g_Map_ResetFlag(FLAG_RED
);
2309 g_Map_ResetFlag(FLAG_BLUE
);
2310 if Quiet
or (Pl
= nil) then Exit
;
2311 Pl
.SetFlag(FLAG_NONE
);
2313 if Fl
= FLAG_RED
then
2314 s
:= _lc
[I_PLAYER_FLAG_RED
]
2316 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2318 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2319 Insert('.', ts
, Length(ts
) + 1 - 3);
2320 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2321 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2323 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2324 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2325 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2330 if not sound_cap_flag
[a
].IsPlaying() then
2331 sound_cap_flag
[a
].Play();
2334 FLAG_STATE_RETURNED
:
2336 g_Map_ResetFlag(Fl
);
2339 if Fl
= FLAG_RED
then
2340 s
:= _lc
[I_PLAYER_FLAG_RED
]
2342 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2344 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2346 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2347 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2348 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2353 if not sound_ret_flag
[a
].IsPlaying() then
2354 sound_ret_flag
[a
].Play();
2359 procedure MC_RECV_GameSettings(var M
: TMsg
);
2361 gGameSettings
.GameMode
:= M
.ReadByte();
2362 gGameSettings
.GoalLimit
:= M
.ReadWord();
2363 gGameSettings
.TimeLimit
:= M
.ReadWord();
2364 gGameSettings
.MaxLives
:= M
.ReadByte();
2365 gGameSettings
.Options
:= M
.ReadLongWord();
2370 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2373 PName
, Model
: string;
2378 PID
:= M
.ReadWord();
2379 Pl
:= g_Player_Get(PID
);
2381 PName
:= M
.ReadString();
2382 Model
:= M
.ReadString();
2383 Color
.R
:= M
.ReadByte();
2384 Color
.G
:= M
.ReadByte();
2385 Color
.B
:= M
.ReadByte();
2389 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2391 if (Pl
<> nil) then Exit
;
2392 DID
:= g_Player_Create(Model
, Color
, T
, False);
2393 with g_Player_Get(DID
) do
2402 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2403 gPlayer1
.UID
:= PID
;
2404 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2405 gPlayer1
.ChangeTeam(T
);
2407 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2408 gPlayer2
.UID
:= PID
;
2409 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2410 gPlayer2
.ChangeTeam(T
);
2414 if NetDeafLevel
< 3 then
2415 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2416 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2420 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2427 TmpX
, TmpY
: Integer;
2431 GT
:= M
.ReadLongWord();
2432 if GT
< gTime
- NET_MAX_DIFFTIME
then
2439 PID
:= M
.ReadWord();
2440 Pl
:= g_Player_Get(PID
);
2442 if Pl
= nil then Exit
;
2448 FPing
:= M
.ReadWord();
2449 FLoss
:= M
.ReadByte();
2450 kByte
:= M
.ReadWord();
2451 Dir
:= M
.ReadByte();
2453 TmpX
:= M
.ReadLongInt();
2454 TmpY
:= M
.ReadLongInt();
2458 if LongBool(kByte
and NET_KEY_CHAT
) then
2459 PressKey(KEY_CHAT
, 10000)
2462 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2463 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2464 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2465 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2466 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2469 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2471 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2472 SetDirection(TDirection(Dir
));
2474 GameVelX
:= M
.ReadLongInt();
2475 GameVelY
:= M
.ReadLongInt();
2476 GameAccelX
:= M
.ReadLongInt();
2477 GameAccelY
:= M
.ReadLongInt();
2478 SetLerp(TmpX
, TmpY
);
2479 if NetForcePlayerUpdate
then Update();
2483 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2487 I
, OldFire
: Integer;
2488 OldJet
, Flam
: Boolean;
2491 PID
:= M
.ReadWord();
2492 Pl
:= g_Player_Get(PID
);
2499 alive
:= (M
.ReadByte() <> 0);
2500 GodMode
:= (M
.ReadByte() <> 0);
2501 Health
:= M
.ReadLongInt();
2502 Armor
:= M
.ReadLongInt();
2503 Air
:= M
.ReadLongInt();
2504 JetFuel
:= M
.ReadLongInt();
2505 Lives
:= M
.ReadByte();
2506 NewTeam
:= M
.ReadByte();
2508 for I
:= WP_FIRST
to WP_LAST
do
2509 FWeapon
[I
] := (M
.ReadByte() <> 0);
2511 for I
:= A_BULLETS
to A_HIGH
do
2512 FAmmo
[I
] := M
.ReadWord();
2514 for I
:= A_BULLETS
to A_HIGH
do
2515 FMaxAmmo
[I
] := M
.ReadWord();
2517 for I
:= MR_SUIT
to MR_MAX
do
2518 FMegaRulez
[I
] := M
.ReadLongWord();
2521 if (M
.ReadByte() <> 0) then
2522 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2523 if (M
.ReadByte() <> 0) then
2524 FRulez
:= FRulez
+ [R_KEY_RED
];
2525 if (M
.ReadByte() <> 0) then
2526 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2527 if (M
.ReadByte() <> 0) then
2528 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2529 if (M
.ReadByte() <> 0) then
2530 FRulez
:= FRulez
+ [R_BERSERK
];
2532 Frags
:= M
.ReadLongInt();
2533 Death
:= M
.ReadLongInt();
2535 SetWeapon(M
.ReadByte());
2537 FSpectator
:= M
.ReadByte() <> 0;
2540 if UID
= NetPlrUID1
then
2542 gSpectLatchPID1
:= UID
;
2545 if UID
= NetPlrUID2
then
2547 gSpectLatchPID2
:= UID
;
2553 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2556 gSpectLatchPID1
:= 0;
2558 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2561 gSpectLatchPID2
:= 0;
2564 FGhost
:= M
.ReadByte() <> 0;
2565 FPhysics
:= M
.ReadByte() <> 0;
2566 FNoRespawn
:= M
.ReadByte() <> 0;
2568 FJetpack
:= M
.ReadByte() <> 0;
2569 OldFire
:= FFireTime
;
2570 FFireTime
:= M
.ReadLongInt();
2571 if (OldFire
<= 0) and (FFireTime
> 0) then
2572 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2573 Flam
:= M
.ReadByte() <> 0;
2574 FSpawnInvul
:= M
.ReadLongInt();
2575 if OldJet
and not FJetpack
then
2577 else if not OldJet
and FJetpack
then
2579 if FFlaming
and not Flam
then
2581 if Team
<> NewTeam
then
2582 Pl
.ChangeTeam(NewTeam
);
2588 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2593 Attacker
, Value
: Word;
2597 if not gGameOn
then Exit
;
2598 PID
:= M
.ReadWord();
2599 Pl
:= g_Player_Get(PID
);
2600 if Pl
= nil then Exit
;
2602 Kind
:= M
.ReadByte();
2603 Attacker
:= M
.ReadWord();
2604 Value
:= M
.ReadWord();
2609 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2614 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2618 KillType
, DeathType
: Byte;
2622 if not gGameOn
then Exit
;
2623 PID
:= M
.ReadWord();
2624 Pl
:= g_Player_Get(PID
);
2625 if Pl
= nil then Exit
;
2627 KillType
:= M
.ReadByte();
2628 DeathType
:= M
.ReadByte();
2629 Attacker
:= M
.ReadWord();
2633 Kill(KillType
, Attacker
, DeathType
);
2638 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2643 PID
:= M
.ReadWord();
2644 Pl
:= g_Player_Get(PID
);
2646 if Pl
= nil then Exit
;
2648 if NetDeafLevel
< 3 then
2649 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2650 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2652 g_Player_Remove(PID
);
2657 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2662 X
, Y
, AX
, AY
: Integer;
2666 if not gGameOn
then Exit
;
2667 PID
:= M
.ReadWord();
2668 Pl
:= g_Player_Get(PID
);
2669 if Pl
= nil then Exit
;
2671 Weap
:= M
.ReadByte();
2672 X
:= M
.ReadLongInt();
2673 Y
:= M
.ReadLongInt();
2674 AX
:= M
.ReadLongInt();
2675 AY
:= M
.ReadLongInt();
2676 SHID
:= M
.ReadLongInt();
2679 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2682 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2692 PID
:= M
.ReadWord();
2693 Pl
:= g_Player_Get(PID
);
2694 if Pl
= nil then Exit
;
2696 TmpName
:= M
.ReadString();
2697 TmpModel
:= M
.ReadString();
2698 TmpColor
.R
:= M
.ReadByte();
2699 TmpColor
.G
:= M
.ReadByte();
2700 TmpColor
.B
:= M
.ReadByte();
2701 TmpTeam
:= M
.ReadByte();
2703 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2705 Pl
.ChangeTeam(TmpTeam
);
2706 if gPlayer1
= Pl
then
2707 gPlayer1Settings
.Team
:= TmpTeam
;
2708 if gPlayer2
= Pl
then
2709 gPlayer2Settings
.Team
:= TmpTeam
;
2711 Pl
.SetColor(TmpColor
);
2713 if Pl
.Name
<> TmpName
then
2715 if NetDeafLevel
< 3 then
2716 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2720 if TmpModel
<> Pl
.Model
.Name
then
2721 Pl
.SetModel(TmpModel
);
2726 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2730 X
, Y
, VX
, VY
: Integer;
2732 Quiet
, Fall
{, Resp}: Boolean;
2736 if not gGameOn
then Exit
;
2738 Quiet
:= M
.ReadByte() <> 0;
2740 Fall
:= M
.ReadByte() <> 0;
2741 {Resp :=} M
.ReadByte();
2742 X
:= M
.ReadLongInt();
2743 Y
:= M
.ReadLongInt();
2744 VX
:= M
.ReadLongInt();
2745 VY
:= M
.ReadLongInt();
2747 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2748 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2750 it
:= g_Items_ByIdx(ID
);
2756 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2757 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2759 Anim
:= TAnimation
.Create(AID
, False, 4);
2760 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2766 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2771 if not gGameOn
then Exit
;
2773 Quiet
:= M
.ReadByte() <> 0;
2775 if not g_Items_ValidId(ID
) then exit
;
2777 if not Quiet
then g_Items_EmitPickupSound(ID
);
2782 procedure MC_RECV_ItemPos(var M
: TMsg
);
2785 X
, Y
, VX
, VY
: Integer;
2788 if not gGameOn
then Exit
;
2791 X
:= M
.ReadLongInt();
2792 Y
:= M
.ReadLongInt();
2793 VX
:= M
.ReadLongInt();
2794 VY
:= M
.ReadLongInt();
2796 if g_Items_ValidId(ID
) then
2798 it
:= g_Items_ByIdx(ID
);
2803 it
.positionChanged();
2809 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2816 if not gGameOn
then Exit
;
2818 PGUID
:= Integer(M
.ReadLongWord());
2819 Tex
:= M
.ReadLongInt();
2820 Fr
:= M
.ReadLongInt();
2821 Cnt
:= M
.ReadByte();
2822 Loop
:= M
.ReadByte();
2824 TP
:= g_Map_PanelByGUID(PGUID
);
2828 TP
.SetTexture(Tex
, Loop
);
2829 TP
.SetFrame(Fr
, Cnt
);
2833 procedure MC_RECV_PanelState(var M
: TMsg
);
2838 X
, Y
, W
, H
: Integer;
2840 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2841 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2844 if not gGameOn
then Exit
;
2846 PGUID
:= Integer(M
.ReadLongWord());
2847 E
:= (M
.ReadByte() <> 0);
2848 Lift
:= M
.ReadByte();
2849 X
:= M
.ReadLongInt();
2850 Y
:= M
.ReadLongInt();
2854 speedX
:= M
.ReadLongInt();
2855 speedY
:= M
.ReadLongInt();
2856 startX
:= M
.ReadLongInt();
2857 startY
:= M
.ReadLongInt();
2858 endX
:= M
.ReadLongInt();
2859 endY
:= M
.ReadLongInt();
2860 sizeSpX
:= M
.ReadLongInt();
2861 sizeSpY
:= M
.ReadLongInt();
2862 sizeEX
:= M
.ReadLongInt();
2863 sizeEY
:= M
.ReadLongInt();
2864 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2866 TP
:= g_Map_PanelByGUID(PGUID
);
2867 if (TP
= nil) then exit
;
2869 // update lifts state
2870 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2872 // update enabled/disabled state for all panels
2873 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2875 // update panel position, as it can be moved (mplat)
2880 // update mplat state
2881 TP
.movingSpeedX
:= speedX
;
2882 TP
.movingSpeedY
:= speedY
;
2883 TP
.movingStartX
:= startX
;
2884 TP
.movingStartY
:= startY
;
2885 TP
.movingEndX
:= endX
;
2886 TP
.movingEndY
:= endY
;
2887 TP
.sizeSpeedX
:= sizeSpX
;
2888 TP
.sizeSpeedY
:= sizeSpY
;
2889 TP
.sizeEndX
:= sizeEX
;
2890 TP
.sizeEndY
:= sizeEY
;
2891 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2892 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2893 // notify panel of it's position/size change, so it can fix other internal structures
2894 TP
.positionChanged();
2899 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2902 SPos
, SID
: LongWord;
2906 if not gGameOn
then Exit
;
2907 if gTriggers
= nil then Exit
;
2909 SID
:= M
.ReadLongWord();
2910 SPlaying
:= M
.ReadByte() <> 0;
2911 SPos
:= M
.ReadLongWord();
2912 SCount
:= M
.ReadLongInt();
2914 for I
:= Low(gTriggers
) to High(gTriggers
) do
2915 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2916 if gTriggers
[I
].ClientID
= SID
then
2917 with gTriggers
[I
] do
2919 if Sound
<> nil then
2924 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2926 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2927 Sound
.SetPosition(SPos
);
2930 if Sound
.IsPlaying
then Sound
.Stop
;
2933 SoundPlayCount
:= SCount
;
2937 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2944 if not gGameOn
then Exit
;
2946 MName
:= M
.ReadString();
2947 MPlaying
:= M
.ReadByte() <> 0;
2948 MPos
:= M
.ReadLongWord();
2949 MPaused
:= M
.ReadByte() <> 0;
2950 MPos
:= MPos
+1; //k8: stfu, fpc!
2954 gMusic
.SetByName(MName
);
2956 // gMusic.SetPosition(MPos);
2957 gMusic
.SpecPause
:= MPaused
;
2960 if gMusic
.IsPlaying
then gMusic
.Stop
;
2965 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2968 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2969 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2974 Mon
:= g_Monsters_ByUID(ID
);
2978 MType
:= M
.ReadByte();
2979 MState
:= M
.ReadByte();
2980 MAnim
:= M
.ReadByte();
2981 MTarg
:= M
.ReadWord();
2982 MTargTime
:= M
.ReadLongInt();
2983 MBehav
:= M
.ReadByte();
2984 MSleep
:= M
.ReadLongInt();
2985 MHealth
:= M
.ReadLongInt();
2986 MAmmo
:= M
.ReadLongInt();
2988 X
:= M
.ReadLongInt();
2989 Y
:= M
.ReadLongInt();
2990 VX
:= M
.ReadLongInt();
2991 VY
:= M
.ReadLongInt();
2992 MDir
:= M
.ReadByte();
2994 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2995 Mon
:= g_Monsters_ByUID(ID
);
3002 MonsterAnim
:= MAnim
;
3003 MonsterTargetUID
:= MTarg
;
3004 MonsterTargetTime
:= MTargTime
;
3005 MonsterBehaviour
:= MBehav
;
3006 MonsterSleep
:= MSleep
;
3007 MonsterAmmo
:= MAmmo
;
3012 setPosition(X
, Y
); // this will call positionChanged();
3018 procedure MC_RECV_MonsterPos(var M
: TMsg
);
3025 Mon
:= g_Monsters_ByUID(ID
);
3031 X
:= M
.ReadLongInt();
3032 Y
:= M
.ReadLongInt();
3033 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
3034 GameVelX
:= M
.ReadLongInt();
3035 GameVelY
:= M
.ReadLongInt();
3036 GameDirection
:= TDirection(M
.ReadByte());
3040 procedure MC_RECV_MonsterState(var M
: TMsg
);
3042 ID
, OldFire
: Integer;
3043 MState
, MFAnm
: Byte;
3045 AnimRevert
: Boolean;
3048 Mon
:= g_Monsters_ByUID(ID
);
3049 if Mon
= nil then Exit
;
3051 MState
:= M
.ReadByte();
3052 MFAnm
:= M
.ReadByte();
3056 MonsterTargetUID
:= M
.ReadWord();
3057 MonsterTargetTime
:= M
.ReadLongInt();
3058 MonsterSleep
:= M
.ReadLongInt();
3059 MonsterHealth
:= M
.ReadLongInt();
3060 MonsterAmmo
:= M
.ReadLongInt();
3061 MonsterPain
:= M
.ReadLongInt();
3062 AnimRevert
:= M
.ReadByte() <> 0;
3063 OldFire
:= FFireTime
;
3064 FFireTime
:= M
.ReadLongInt();
3065 if (OldFire
<= 0) and (FFireTime
> 0) then
3066 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3067 RevertAnim(AnimRevert
);
3069 if MonsterState
<> MState
then
3071 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3072 if (MState
= MONSTATE_DIE
) then DieSound();
3073 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3074 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3075 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3077 SetState(MState
, MFAnm
);
3082 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3086 X
, Y
, VX
, VY
: Integer;
3090 Mon
:= g_Monsters_ByUID(ID
);
3091 if Mon
= nil then Exit
;
3093 X
:= M
.ReadLongInt();
3094 Y
:= M
.ReadLongInt();
3095 VX
:= M
.ReadLongInt();
3096 VY
:= M
.ReadLongInt();
3098 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3101 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3107 Mon
:= g_Monsters_ByUID(ID
);
3108 if Mon
= nil then Exit
;
3110 Mon
.MonsterRemoved
:= True;
3113 procedure MC_RECV_TimeSync(var M
: TMsg
);
3117 Time
:= M
.ReadLongWord();
3119 if gState
= STATE_INTERCUSTOM
then
3120 gServInterTime
:= Min(Time
, 255);
3123 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3127 Int1
, Int2
: SmallInt;
3129 EvID
:= M
.ReadByte();
3130 Int1
:= M
.ReadSmallInt();
3131 Int2
:= M
.ReadSmallInt();
3132 Str1
:= M
.ReadString();
3133 Str2
:= M
.ReadString();
3135 if NetDeafLevel
< 2 then
3138 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3140 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3142 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3144 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3146 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3152 procedure MC_SEND_Info(Password
: string);
3157 NetOut
.Write(Byte(NET_MSG_INFO
));
3158 NetOut
.Write(GAME_VERSION
);
3159 NetOut
.Write(Password
);
3160 NetOut
.Write(gPlayer1Settings
.Name
);
3161 NetOut
.Write(gPlayer1Settings
.Model
);
3162 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3163 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3164 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3165 NetOut
.Write(gPlayer1Settings
.Team
);
3166 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3167 if (gPlayer1Settings
.WeaponSwitch
= 2) then
3168 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3169 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3170 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3171 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3173 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3176 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3178 NetOut
.Write(Byte(NET_MSG_CHAT
));
3182 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3185 procedure MC_SEND_PlayerPos();
3190 WeaponAct
: Byte = 0;
3191 WeaponSelect
: Word = 0;
3194 if not gGameOn
then Exit
;
3195 if gPlayers
= nil then Exit
;
3196 if gPlayer1
= nil then Exit
;
3199 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3201 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3203 strafeDir
:= P1MoveButton
shr 4;
3204 P1MoveButton
:= P1MoveButton
and $0F;
3206 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3208 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3210 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3214 if gPlayerAction
[0, ACTION_STRAFE
] then
3216 // new strafe mechanics
3217 if (strafeDir
= 0) then
3218 strafeDir
:= P1MoveButton
; // start strafing
3219 // now set direction according to strafe (reversed)
3220 if (strafeDir
= 2) then
3221 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3222 else if (strafeDir
= 1) then
3223 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3227 strafeDir
:= 0; // not strafing anymore
3228 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3229 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3230 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3231 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3232 else if P1MoveButton
<> 0 then
3233 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3236 gPlayer1
.ReleaseKeys
;
3237 if P1MoveButton
= 1 then
3239 kByte
:= kByte
or NET_KEY_LEFT
;
3240 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3242 if P1MoveButton
= 2 then
3244 kByte
:= kByte
or NET_KEY_RIGHT
;
3245 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3247 if gPlayerAction
[0, ACTION_LOOKUP
] then
3249 kByte
:= kByte
or NET_KEY_UP
;
3250 gPlayer1
.PressKey(KEY_UP
, 10000);
3252 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3254 kByte
:= kByte
or NET_KEY_DOWN
;
3255 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3257 if gPlayerAction
[0, ACTION_JUMP
] then
3259 kByte
:= kByte
or NET_KEY_JUMP
;
3260 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3262 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3263 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3265 for i
:= WP_FACT
to WP_LACT
do
3267 if gWeaponAction
[0, i
] then
3269 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3270 gWeaponAction
[0, i
] := False
3274 for i
:= WP_FIRST
to WP_LAST
do
3276 if gSelectWeapon
[0, i
] then
3278 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3279 gSelectWeapon
[0, i
] := False
3283 // fix movebutton state
3284 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3287 kByte
:= NET_KEY_CHAT
;
3289 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3290 NetOut
.Write(gTime
);
3291 NetOut
.Write(kByte
);
3292 NetOut
.Write(Byte(gPlayer1
.Direction
));
3293 NetOut
.Write(WeaponAct
);
3294 NetOut
.Write(WeaponSelect
);
3295 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3296 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3298 //kBytePrev := kByte;
3299 //kDirPrev := gPlayer1.Direction;
3302 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3304 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3305 NetOut
.Write(Byte(Start
));
3306 NetOut
.Write(Command
);
3307 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3310 procedure MC_SEND_PlayerSettings();
3313 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3314 NetOut
.Write(gPlayer1Settings
.Name
);
3315 NetOut
.Write(gPlayer1Settings
.Model
);
3316 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3317 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3318 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3319 NetOut
.Write(gPlayer1Settings
.Team
);
3320 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3321 if (gPlayer1Settings
.WeaponSwitch
= 2) then
3322 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3323 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3324 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3325 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3327 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3330 procedure MC_SEND_FullStateRequest();
3332 NetOut
.Write(Byte(NET_MSG_REQFST
));
3334 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3337 procedure MC_SEND_CheatRequest(Kind
: Byte);
3339 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3342 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3344 procedure MC_SEND_RCONPassword(Password
: string);
3346 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3347 NetOut
.Write(Password
);
3349 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3351 procedure MC_SEND_RCONCommand(Cmd
: string);
3353 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3356 g_Net_Client_Send(True, NET_CHAN_SERVICE
);