1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
20 uses e_msg
, g_net
, g_triggers
, Classes
, SysUtils
, md5
;
66 NET_MSG_RCON_AUTH
= 191;
67 NET_MSG_RCON_CMD
= 192;
68 NET_MSG_TIME_SYNC
= 194;
69 NET_MSG_VOTE_EVENT
= 195;
72 NET_MSG_MAP_REQUEST = 201;
73 NET_MSG_MAP_RESPONSE = 202;
74 NET_MSG_RES_REQUEST = 203;
75 NET_MSG_RES_RESPONSE = 204;
99 NET_EV_CHANGE_TEAM
= 3;
100 NET_EV_PLAYER_KICK
= 4;
101 NET_EV_PLAYER_BAN
= 5;
102 NET_EV_LMS_WARMUP
= 6;
103 NET_EV_LMS_SURVIVOR
= 7;
107 NET_EV_SCORE_MSG
= 11;
108 NET_EV_LMS_START
= 12;
110 NET_EV_TLMS_WIN
= 14;
111 NET_EV_LMS_LOSE
= 15;
112 NET_EV_LMS_DRAW
= 16;
113 NET_EV_KILLCOMBO
= 17;
114 NET_EV_PLAYER_TOUCH
= 18;
116 NET_EV_INTER_READY
= 20;
117 NET_EV_LMS_NOSPAWN
= 21;
124 NET_VE_INPROGRESS
= 6;
131 NET_CHEAT_SUICIDE
= 1;
132 NET_CHEAT_SPECTATE
= 2;
134 NET_CHEAT_DROPFLAG
= 4;
136 NET_MAX_DIFFTIME
= 5000 div 36;
140 procedure MH_MalformedPacket(C
: pTNetClient
);
141 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
143 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
146 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
147 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
148 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
149 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
150 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
151 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
152 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
153 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
156 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
157 procedure MH_SEND_Info(ID
: Byte);
158 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
189 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
190 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
191 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
193 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
194 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
196 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
197 procedure MH_SEND_VoteEvent(EvType
: Byte;
198 StrArg1
: string = 'a'; StrArg2
: string = 'b';
199 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
200 ID
: Integer = NET_EVERYONE
);
202 // CLIENT MESSAGES //
205 procedure MC_RECV_Chat(var M
: TMsg
);
206 procedure MC_RECV_Effect(var M
: TMsg
);
207 procedure MC_RECV_Sound(var M
: TMsg
);
208 procedure MC_RECV_GameStats(var M
: TMsg
);
209 procedure MC_RECV_CoopStats(var M
: TMsg
);
210 procedure MC_RECV_GameEvent(var M
: TMsg
);
211 procedure MC_RECV_FlagEvent(var M
: TMsg
);
212 procedure MC_RECV_FlagPos(var M
: TMsg
);
213 procedure MC_RECV_GameSettings(var M
: TMsg
);
215 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
216 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
217 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
218 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
219 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
220 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
221 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
222 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
224 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
225 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
226 procedure MC_RECV_ItemPos(var M
: TMsg
);
228 procedure MC_RECV_PanelTexture(var M
: TMsg
);
229 procedure MC_RECV_PanelState(var M
: TMsg
);
231 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
232 procedure MC_RECV_MonsterPos(var M
: TMsg
);
233 procedure MC_RECV_MonsterState(var M
: TMsg
);
234 procedure MC_RECV_MonsterShot(var M
: TMsg
);
235 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
237 procedure MC_RECV_CreateShot(var M
: TMsg
);
238 procedure MC_RECV_UpdateShot(var M
: TMsg
);
239 procedure MC_RECV_DeleteShot(var M
: TMsg
);
241 procedure MC_RECV_TriggerSound(var M
: TMsg
);
242 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
244 procedure MC_RECV_TimeSync(var M
: TMsg
);
245 procedure MC_RECV_VoteEvent(var M
: TMsg
);
247 procedure MC_SEND_Info(Password
: string);
248 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
249 procedure MC_SEND_PlayerPos();
250 procedure MC_SEND_FullStateRequest();
251 procedure MC_SEND_PlayerSettings();
252 procedure MC_SEND_CheatRequest(Kind
: Byte);
253 procedure MC_SEND_RCONPassword(Password
: string);
254 procedure MC_SEND_RCONCommand(Cmd
: string);
255 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
257 //procedure MC_SEND_MapRequest();
258 //procedure MC_SEND_ResRequest(const resName: AnsiString);
262 TExternalResourceInfo
= record
277 ExternalResources
: array of TExternalResourceInfo
;
280 function IsValidFileName(const S
: String): Boolean;
281 function IsValidFilePath(const S
: String): Boolean;
287 Math
, ENet
, e_input
, e_graphics
, e_log
,
288 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
289 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
290 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
293 NET_KEY_LEFT
= 1 shl 0;
294 NET_KEY_RIGHT
= 1 shl 1;
295 NET_KEY_UP
= 1 shl 2;
296 NET_KEY_DOWN
= 1 shl 3;
297 NET_KEY_JUMP
= 1 shl 4;
298 NET_KEY_FIRE
= 1 shl 5;
299 NET_KEY_OPEN
= 1 shl 6;
300 NET_KEY_CHAT
= 1 shl 7;
301 NET_KEY_FORCEDIR
= 1 shl 8;
304 //kBytePrev: Word = 0;
305 //kDirPrev: TDirection = D_LEFT;
306 //HostGameTime: Word = 0;
309 function IsValidFileName(const S
: String): Boolean;
311 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
316 for I
:= 1 to Length(S
) do
317 Result
:= Result
and (not(S
[I
] in Forbidden
));
320 function IsValidFilePath(const S
: String): Boolean;
325 if not IsValidFileName(S
) then exit
;
326 if FileExists(S
) then exit
;
327 I
:= LastDelimiter('\/', S
);
329 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
340 procedure MH_MalformedPacket(C
: pTNetClient
);
342 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
343 _lc
[I_NET_DISC_PROTOCOL
]);
344 enet_peer_disconnect(C
^.Peer
, NET_DISC_PROTOCOL
);
347 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
356 Pl
:= g_Player_Get(PID
);
360 Txt
:= M
.ReadString();
361 Mode
:= M
.ReadByte();
366 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
368 if (Mode
= NET_CHAT_SYSTEM
) then
369 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
370 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
371 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
374 MH_SEND_Chat(Txt
, Mode
)
376 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
379 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
381 Ver
, PName
, Model
, Pw
: string;
384 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
394 Ver
:= M
.ReadString();
395 Pw
:= M
.ReadString();
396 PName
:= M
.ReadString();
397 Model
:= M
.ReadString();
402 WeapSwitch
:= M
.ReadByte();
403 for I
:= WP_FIRST
to WP_LAST
+ 1 do
404 TmpPrefArray
[I
] := M
.ReadByte();
405 SwitchEmpty
:= M
.ReadByte();
406 SkipF
:= M
.ReadByte();
411 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
413 if Ver
<> GAME_VERSION
then
415 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
416 _lc
[I_NET_DISC_VERSION
]);
417 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
421 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
423 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
425 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
426 _lc
[I_NET_DISC_BAN
]);
427 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
431 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
432 _lc
[I_NET_DISC_BAN
]);
433 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
438 if NetPassword
<> '' then
439 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
441 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
442 _lc
[I_NET_DISC_PASSWORD
]);
443 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
447 if (C
^.Player
<> 0) then
449 // already received info
450 g_Net_Penalize(C
, 'client info spam');
458 PID
:= g_Player_Create(Model
, Color
, T
, False);
459 with g_Player_Get(PID
) do
462 WeapSwitchMode
:= WeapSwitch
;
463 SetWeaponPrefs(TmpPrefArray
);
464 SwitchToEmpty
:= SwitchEmpty
;
470 C
^.WaitForFirstSpawn
:= false;
473 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
474 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
475 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
479 with g_Player_Get(PID
) do
483 // round in progress, don't spawn
484 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
485 //e_LogWritefln('spawning player with pid #%u...', [PID]);
486 //Respawn(gGameSettings.GameType = GT_SINGLE);
487 //k8: no, do not spawn a player yet, wait for "request full state" packet
491 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
492 // that is, if we'll set it to `true`, the player can be spawned after
493 // warmup time ran out, for example, regardless of the real player state.
494 // also, this seems to work only for the initial connection. further
495 // map changes could initiate resource downloading, but the player will
496 // be spawned immediately.
497 // the proper solution will require another player state, "ephemeral".
498 // the player should start any map in "ephemeral" state, and turned into
499 // real mobj only when they sent a special "i am ready" packet. this packet
500 // must be sent after receiving the full state, so the player will get a full
501 // map view before going into game.
502 FWantsInGame
:= false;
503 C
^.WaitForFirstSpawn
:= true;
506 //if not C^.WaitForFirstSpawn then
508 for I
:= Low(NetClients
) to High(NetClients
) do
510 if NetClients
[I
].ID
= C
^.ID
then Continue
;
511 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
512 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
513 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
517 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
518 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
522 //g_Net_Slist_Update;
528 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
532 if not C
.WaitForFirstSpawn
then exit
;
533 plr
:= g_Player_Get(C
^.Player
);
534 if not assigned(plr
) then exit
;
535 g_Net_Slist_ServerPlayerComes();
536 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
537 C
.WaitForFirstSpawn
:= false;
538 plr
.FNoRespawn
:= false;
539 plr
.FWantsInGame
:= true; // TODO: look into this later
541 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
544 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
549 if gLMSRespawn
> LMS_RESPAWN_NONE
then
550 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
555 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
557 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
559 if C
^.FullUpdateSent
then
561 // FullStateRequest spam?
562 g_Net_Penalize(C
, 'duplicate full state request');
568 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
572 C
^.RequestedFullUpdate
:= True;
578 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
591 if not gGameOn
then Exit
;
594 GT
:= M
.ReadLongWord();
599 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
602 Pl
:= g_Player_Get(PID
);
606 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
612 kByte
:= M
.ReadWord();
614 WeaponAct
:= M
.ReadByte();
615 WeaponSelect
:= M
.ReadWord();
620 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
622 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
623 if Direction
<> TDirection(Dir
) then
624 JustTeleported
:= False;
626 SetDirection(TDirection(Dir
));
629 if kByte
= NET_KEY_CHAT
then
631 PressKey(KEY_CHAT
, 10000);
635 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
636 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
637 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
638 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
639 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
640 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
641 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
645 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
647 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
648 ProcessWeaponAction(i
);
654 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
656 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
657 QueueWeaponSwitch(i
);
662 // MH_SEND_PlayerPos(False, PID, C^.ID);
665 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
672 Pl
:= g_Player_Get(C
^.Player
);
673 if Pl
= nil then Exit
;
676 CheatKind
:= M
.ReadByte();
681 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
685 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
688 if Pl
.FSpectator
then
690 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
693 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
700 if gState
<> STATE_INTERCUSTOM
then Exit
;
701 Pl
.FReady
:= not Pl
.FReady
;
704 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
705 Inc(gInterReadyCount
);
709 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
710 Dec(gInterReadyCount
);
718 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
725 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
734 TmpName
:= M
.ReadString();
735 TmpModel
:= M
.ReadString();
736 TmpColor
.R
:= M
.ReadByte();
737 TmpColor
.G
:= M
.ReadByte();
738 TmpColor
.B
:= M
.ReadByte();
739 TmpTeam
:= M
.ReadByte();
740 TmpWeapSwitch
:= M
.ReadByte();
741 for I
:= WP_FIRST
to WP_LAST
+ 1 do
742 TmpPrefArray
[I
] := M
.ReadByte();
743 TmpSwEmpty
:= M
.ReadByte();
744 TmpSkipF
:= M
.ReadByte();
749 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
751 Pl
:= g_Player_Get(C
^.Player
);
752 if Pl
= nil then Exit
;
754 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
757 Pl
.SetColor(TmpColor
);
759 if Pl
.Name
<> TmpName
then
761 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
765 if TmpModel
<> Pl
.Model
.Name
then
766 Pl
.SetModel(TmpModel
);
768 if (TmpWeapSwitch
<> Pl
.WeapSwitchMode
) then
769 Pl
.WeapSwitchMode
:= TmpWeapSwitch
;
771 Pl
.SetWeaponPrefs(TmpPrefArray
);
772 if (TmpSwEmpty
<> Pl
.SwitchToEmpty
) then
773 Pl
.SwitchToEmpty
:= TmpSwEmpty
;
775 if (TmpSkipF
<> Pl
.SkipFist
) then
776 Pl
.SkipFist
:= TmpSkipF
;
778 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
783 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
790 Pwd
:= M
.ReadString();
794 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
795 if not NetAllowRCON
then Exit
;
796 if Pwd
= NetRCONPassword
then
799 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
802 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
805 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
812 Cmd
:= M
.ReadString();
816 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
817 if not NetAllowRCON
then Exit
;
818 if not C
^.RCONAuth
then
820 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
823 g_Console_Process(Cmd
);
828 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
831 Name
, Command
: string;
838 Start
:= M
.ReadByte() <> 0;
839 Command
:= M
.ReadString();
844 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
846 Pl
:= g_Player_Get(C
^.Player
);
847 if Pl
= nil then Exit
;
852 if not g_Console_CommandBlacklisted(Command
) then
853 g_Game_StartVote(Command
, Name
);
855 else if gVoteInProgress
then
857 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
858 Need
:= Floor((NetClientCount
+1)/2.0) + 1
860 Need
:= Floor(NetClientCount
/2.0) + 1;
865 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
866 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
872 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
873 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
881 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
883 function sendItemRespawn (it
: PItem
): Boolean;
885 result
:= false; // don't stop
886 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
889 function sendMonSpawn (mon
: TMonster
): Boolean;
891 result
:= false; // don't stop
892 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
895 function sendPanelState (pan
: TPanel
): Boolean;
897 result
:= false; // don't stop
898 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
899 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
905 if (ID
< 0) or (ID
>= Length(NetClients
)) then
906 exit
; // bogus client, this shouldn't happen
908 NetClients
[ID
].FullUpdateSent
:= True;
910 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
912 MH_ProcessFirstSpawn(@NetClients
[ID
]);
914 if gPlayers
<> nil then
916 for I
:= Low(gPlayers
) to High(gPlayers
) do
918 if gPlayers
[I
] <> nil then
920 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
921 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
922 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
924 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
926 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
932 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
933 g_Mons_ForEach(sendMonSpawn
);
934 g_Map_ForEachPanel(sendPanelState
);
936 if gTriggers
<> nil then
938 for I
:= Low(gTriggers
) to High(gTriggers
) do
940 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
942 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
949 for I
:= Low(Shots
) to High(Shots
) do
951 if Shots
[i
].ShotType
in [6, 7, 8] then
953 MH_SEND_CreateShot(i
, ID
);
958 MH_SEND_TriggerMusic(ID
);
960 MH_SEND_GameStats(ID
);
961 MH_SEND_CoopStats(ID
);
963 if gGameSettings
.GameMode
= GM_CTF
then
965 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
966 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
969 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
974 procedure MH_SEND_Info(ID
: Byte);
978 NetOut
.Write(Byte(NET_MSG_INFO
));
980 NetOut
.Write(NetClients
[ID
].Player
);
981 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
982 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
983 NetOut
.Write(gWADHash
);
984 NetOut
.Write(gGameSettings
.GameMode
);
985 NetOut
.Write(gGameSettings
.GoalLimit
);
986 NetOut
.Write(gGameSettings
.TimeLimit
);
987 NetOut
.Write(gGameSettings
.MaxLives
);
988 NetOut
.Write(gGameSettings
.Options
);
991 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
994 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
1000 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1001 Mode
:= NET_CHAT_PLAYER
;
1004 if (Mode
= NET_CHAT_TEAM
) then
1006 for i
:= Low(gPlayers
) to High(gPlayers
) do
1007 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
1008 (gPlayers
[i
].Team
= ID
) then
1010 NetOut
.Write(Byte(NET_MSG_CHAT
));
1013 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
1020 NetOut
.Write(Byte(NET_MSG_CHAT
));
1023 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
1026 if Mode
= NET_CHAT_SYSTEM
then
1029 if ID
= NET_EVERYONE
then
1031 if Mode
= NET_CHAT_PLAYER
then
1033 g_Console_Add(Txt
, True);
1034 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1035 g_Game_ChatSound(b_Text_Unformat(Txt
));
1038 if Mode
= NET_CHAT_TEAM
then
1039 if gPlayer1
<> nil then
1041 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
1043 g_Console_Add(#18'[Team] '#2 + Txt
, True);
1044 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1045 g_Game_ChatSound(b_Text_Unformat(Txt
));
1047 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
1049 g_Console_Add(#20'[Team] '#2 + Txt
, True);
1050 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1051 g_Game_ChatSound(b_Text_Unformat(Txt
));
1057 Name
:= g_Net_ClientName_ByID(ID
);
1058 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1059 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1060 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1064 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1066 NetOut
.Write(Byte(NET_MSG_GFX
));
1072 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1075 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1077 NetOut
.Write(Byte(NET_MSG_SND
));
1081 NetOut
.Write(Byte(1));
1086 NetOut
.Write(Byte(0));
1088 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1091 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1093 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1095 NetOut
.Write(Byte(NET_MSG_SHADD
));
1097 NetOut
.Write(Shots
[Proj
].ShotType
);
1098 NetOut
.Write(Shots
[Proj
].Target
);
1099 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1100 NetOut
.Write(Shots
[Proj
].Timeout
);
1101 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1102 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1103 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1104 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1106 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1109 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1111 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1113 NetOut
.Write(Byte(NET_MSG_SHPOS
));
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
, False, NET_CHAN_SHOTS
);
1123 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1125 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1127 NetOut
.Write(Byte(Loud
));
1131 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1134 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1136 NetOut
.Write(Byte(NET_MSG_SCORE
));
1137 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1139 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1140 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1143 if gGameSettings
.GameMode
= GM_COOP
then
1145 NetOut
.Write(gCoopMonstersKilled
);
1146 NetOut
.Write(gCoopSecretsFound
);
1149 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1152 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1154 NetOut
.Write(Byte(NET_MSG_COOP
));
1155 NetOut
.Write(gTotalMonsters
);
1156 NetOut
.Write(gSecretsCount
);
1157 NetOut
.Write(gCoopTotalMonstersKilled
);
1158 NetOut
.Write(gCoopTotalSecretsFound
);
1159 NetOut
.Write(gCoopTotalMonsters
);
1160 NetOut
.Write(gCoopTotalSecrets
);
1163 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1165 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1166 NetOut
.Write(EvType
);
1167 NetOut
.Write(EvNum
);
1168 NetOut
.Write(EvStr
);
1169 NetOut
.Write(Byte(gLastMap
));
1170 NetOut
.Write(gTime
);
1171 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1173 NetOut
.Write(Byte(1));
1174 NetOut
.Write(gWADHash
);
1176 NetOut
.Write(Byte(0));
1178 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1181 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1183 NetOut
.Write(Byte(NET_MSG_FLAG
));
1184 NetOut
.Write(EvType
);
1186 NetOut
.Write(Byte(Quiet
));
1188 NetOut
.Write(gFlags
[Flag
].State
);
1189 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1190 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1191 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1192 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1193 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1194 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1196 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1199 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1201 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1203 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1204 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1205 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1206 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1208 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1211 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1213 NetOut
.Write(Byte(NET_MSG_GSET
));
1214 NetOut
.Write(gGameSettings
.GameMode
);
1215 NetOut
.Write(gGameSettings
.GoalLimit
);
1216 NetOut
.Write(gGameSettings
.TimeLimit
);
1217 NetOut
.Write(gGameSettings
.MaxLives
);
1218 NetOut
.Write(gGameSettings
.Options
);
1220 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1225 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1229 P
:= g_Player_Get(PID
);
1230 if P
= nil then Exit
;
1232 NetOut
.Write(Byte(NET_MSG_PLR
));
1234 NetOut
.Write(P
.Name
);
1236 NetOut
.Write(P
.FActualModelName
);
1237 NetOut
.Write(P
.FColor
.R
);
1238 NetOut
.Write(P
.FColor
.G
);
1239 NetOut
.Write(P
.FColor
.B
);
1240 NetOut
.Write(P
.Team
);
1242 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1245 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1250 Pl
:= g_Player_Get(PID
);
1251 if Pl
= nil then Exit
;
1252 if Pl
.FDummy
then Exit
;
1254 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1255 NetOut
.Write(gTime
);
1262 NetOut
.Write(FPing
);
1263 NetOut
.Write(FLoss
);
1264 if IsKeyPressed(KEY_CHAT
) then
1265 kByte
:= NET_KEY_CHAT
1268 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1269 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1270 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1271 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1272 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1275 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1277 NetOut
.Write(kByte
);
1278 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1279 NetOut
.Write(GameX
);
1280 NetOut
.Write(GameY
);
1281 NetOut
.Write(GameVelX
);
1282 NetOut
.Write(GameVelY
);
1283 NetOut
.Write(GameAccelX
);
1284 NetOut
.Write(GameAccelY
);
1287 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1290 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1295 P
:= g_Player_Get(PID
);
1296 if P
= nil then Exit
;
1298 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1303 NetOut
.Write(Byte(alive
));
1304 NetOut
.Write(Byte(GodMode
));
1305 NetOut
.Write(Health
);
1306 NetOut
.Write(Armor
);
1308 NetOut
.Write(JetFuel
);
1309 NetOut
.Write(Lives
);
1312 for I
:= WP_FIRST
to WP_LAST
do
1313 NetOut
.Write(Byte(FWeapon
[I
]));
1315 for I
:= A_BULLETS
to A_HIGH
do
1316 NetOut
.Write(FAmmo
[I
]);
1318 for I
:= A_BULLETS
to A_HIGH
do
1319 NetOut
.Write(FMaxAmmo
[I
]);
1321 for I
:= MR_SUIT
to MR_MAX
do
1322 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1324 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1325 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1326 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1327 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1328 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1330 NetOut
.Write(Frags
);
1331 NetOut
.Write(Death
);
1333 NetOut
.Write(CurrWeap
);
1335 NetOut
.Write(Byte(FSpectator
));
1336 NetOut
.Write(Byte(FGhost
));
1337 NetOut
.Write(Byte(FPhysics
));
1338 NetOut
.Write(Byte(FNoRespawn
));
1339 NetOut
.Write(Byte(FJetpack
));
1340 NetOut
.Write(FFireTime
);
1341 NetOut
.Write(Byte(FFlaming
));
1342 NetOut
.Write(FSpawnInvul
);
1345 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1348 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1350 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1353 NetOut
.Write(Attacker
);
1354 NetOut
.Write(Value
);
1358 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1361 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1363 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1365 NetOut
.Write(KillType
);
1366 NetOut
.Write(DeathType
);
1367 NetOut
.Write(Attacker
);
1369 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1372 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1374 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1376 NetOut
.Write(Weapon
);
1381 NetOut
.Write(ShotID
);
1383 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1386 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1388 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1391 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1394 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1398 Pl
:= g_Player_Get(PID
);
1399 if Pl
= nil then Exit
;
1401 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1403 NetOut
.Write(Pl
.Name
);
1405 NetOut
.Write(Pl
.Model
.Name
)
1408 NetOut
.Write(Pl
.FColor
.R
);
1409 NetOut
.Write(Pl
.FColor
.G
);
1410 NetOut
.Write(Pl
.FColor
.B
);
1411 NetOut
.Write(Pl
.Team
);
1413 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1418 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1423 it
:= g_Items_ByIdx(IID
);
1425 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1427 NetOut
.Write(Byte(Quiet
));
1429 if it
.dropped
then tt
:= tt
or $80;
1431 NetOut
.Write(Byte(it
.Fall
));
1432 NetOut
.Write(Byte(it
.Respawnable
));
1433 NetOut
.Write(it
.Obj
.X
);
1434 NetOut
.Write(it
.Obj
.Y
);
1435 NetOut
.Write(it
.Obj
.Vel
.X
);
1436 NetOut
.Write(it
.Obj
.Vel
.Y
);
1438 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1441 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1443 NetOut
.Write(Byte(NET_MSG_IDEL
));
1445 NetOut
.Write(Byte(Quiet
));
1447 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1450 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1454 it
:= g_Items_ByIdx(IID
);
1456 NetOut
.Write(Byte(NET_MSG_IPOS
));
1458 NetOut
.Write(it
.Obj
.X
);
1459 NetOut
.Write(it
.Obj
.Y
);
1460 NetOut
.Write(it
.Obj
.Vel
.X
);
1461 NetOut
.Write(it
.Obj
.Vel
.Y
);
1463 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1468 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1472 TP
:= g_Map_PanelByGUID(PGUID
);
1473 if (TP
= nil) then exit
;
1477 NetOut
.Write(Byte(NET_MSG_PTEX
));
1478 NetOut
.Write(LongWord(PGUID
));
1479 NetOut
.Write(FCurTexture
);
1480 NetOut
.Write(FCurFrame
);
1481 NetOut
.Write(FCurFrameCount
);
1482 NetOut
.Write(AnimLoop
);
1485 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1488 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1493 TP
:= g_Map_PanelByGUID(PGUID
);
1494 if (TP
= nil) then exit
;
1496 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1497 NetOut
.Write(LongWord(PGUID
));
1498 NetOut
.Write(Byte(TP
.Enabled
));
1499 NetOut
.Write(TP
.LiftType
);
1502 NetOut
.Write(Word(TP
.Width
));
1503 NetOut
.Write(Word(TP
.Height
));
1505 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1506 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1507 NetOut
.Write(LongInt(TP
.movingStartX
));
1508 NetOut
.Write(LongInt(TP
.movingStartY
));
1509 NetOut
.Write(LongInt(TP
.movingEndX
));
1510 NetOut
.Write(LongInt(TP
.movingEndY
));
1511 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1512 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1513 NetOut
.Write(LongInt(TP
.sizeEndX
));
1514 NetOut
.Write(LongInt(TP
.sizeEndY
));
1515 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1516 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1517 NetOut
.Write(Byte(mpflags
));
1519 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1524 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1526 if gTriggers
= nil then Exit
;
1527 if T
.Sound
= nil then Exit
;
1529 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1530 NetOut
.Write(T
.ClientID
);
1531 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1532 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1533 NetOut
.Write(T
.SoundPlayCount
);
1535 g_Net_Host_Send(ID
, True);
1538 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1540 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1541 NetOut
.Write(gMusic
.Name
);
1542 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1543 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1544 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1546 g_Net_Host_Send(ID
, True);
1551 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1555 M
:= g_Monsters_ByUID(UID
);
1561 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1563 NetOut
.Write(MonsterType
);
1564 NetOut
.Write(MonsterState
);
1565 NetOut
.Write(MonsterAnim
);
1566 NetOut
.Write(MonsterTargetUID
);
1567 NetOut
.Write(MonsterTargetTime
);
1568 NetOut
.Write(MonsterBehaviour
);
1569 NetOut
.Write(MonsterSleep
);
1570 NetOut
.Write(MonsterHealth
);
1571 NetOut
.Write(MonsterAmmo
);
1572 NetOut
.Write(GameX
);
1573 NetOut
.Write(GameY
);
1574 NetOut
.Write(GameVelX
);
1575 NetOut
.Write(GameVelY
);
1576 NetOut
.Write(Byte(GameDirection
));
1579 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1582 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1586 M
:= g_Monsters_ByUID(UID
);
1587 if M
= nil then Exit
;
1589 NetOut
.Write(Byte(NET_MSG_MPOS
));
1594 NetOut
.Write(GameX
);
1595 NetOut
.Write(GameY
);
1596 NetOut
.Write(GameVelX
);
1597 NetOut
.Write(GameVelY
);
1598 NetOut
.Write(Byte(GameDirection
));
1601 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1604 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1608 M
:= g_Monsters_ByUID(UID
);
1609 if M
= nil then Exit
;
1611 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1616 NetOut
.Write(MonsterState
);
1617 NetOut
.Write(ForcedAnim
);
1618 NetOut
.Write(MonsterTargetUID
);
1619 NetOut
.Write(MonsterTargetTime
);
1620 NetOut
.Write(MonsterSleep
);
1621 NetOut
.Write(MonsterHealth
);
1622 NetOut
.Write(MonsterAmmo
);
1623 NetOut
.Write(MonsterPain
);
1624 NetOut
.Write(Byte(AnimIsReverse
));
1625 NetOut
.Write(FFireTime
);
1628 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1631 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1633 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1640 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1643 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1647 M
:= g_Monsters_ByUID(UID
);
1648 if M
= nil then Exit
;
1650 NetOut
.Write(Byte(NET_MSG_MDEL
));
1653 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1658 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1660 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1663 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1666 procedure MH_SEND_VoteEvent(EvType
: Byte;
1667 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1668 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1669 ID
: Integer = NET_EVERYONE
);
1671 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1672 NetOut
.Write(EvType
);
1673 NetOut
.Write(IntArg1
);
1674 NetOut
.Write(IntArg2
);
1675 NetOut
.Write(StrArg1
);
1676 NetOut
.Write(StrArg2
);
1678 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1681 // CLIENT MESSAGES //
1685 procedure MC_RECV_Chat(var M
: TMsg
);
1690 Txt
:= M
.ReadString();
1691 Mode
:= M
.ReadByte();
1693 if Mode
<> NET_CHAT_SYSTEM
then
1695 if NetDeafLevel
= 0 then
1697 if Mode
= NET_CHAT_PLAYER
then
1699 g_Console_Add(Txt
, True);
1700 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1701 g_Game_ChatSound(b_Text_Unformat(Txt
));
1703 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1705 if gPlayer1
.Team
= TEAM_RED
then
1706 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1707 if gPlayer1
.Team
= TEAM_BLUE
then
1708 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1709 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1710 g_Game_ChatSound(b_Text_Unformat(Txt
));
1713 end else if (NetDeafLevel
< 2) then
1714 g_Console_Add(Txt
, True);
1717 procedure MC_RECV_Effect(var M
: TMsg
);
1725 if not gGameOn
then Exit
;
1726 Kind
:= M
.ReadByte();
1727 X
:= M
.ReadLongInt();
1728 Y
:= M
.ReadLongInt();
1729 Ang
:= M
.ReadSmallInt();
1733 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1737 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1739 Anim
:= TAnimation
.Create(ID
, False, 3);
1740 g_GFX_OnceAnim(X
, Y
, Anim
);
1744 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1749 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1751 Anim
:= TAnimation
.Create(ID
, False, 6);
1752 Anim
.Blending
:= False;
1753 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1757 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1762 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1764 Anim
:= TAnimation
.Create(ID
, False, 6);
1765 Anim
.Blending
:= False;
1766 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1770 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1775 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1777 Anim
:= TAnimation
.Create(ID
, False, 4);
1778 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1785 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1787 Anim
:= TAnimation
.Create(ID
, False, 4);
1788 g_GFX_OnceAnim(X
, Y
, Anim
);
1792 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1797 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1799 Anim
:= TAnimation
.Create(ID
, False, 4);
1800 g_GFX_OnceAnim(X
, Y
, Anim
);
1804 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1808 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1811 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1815 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1816 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1821 procedure MC_RECV_Sound(var M
: TMsg
);
1827 Name
:= M
.ReadString();
1828 Pos
:= M
.ReadByte() <> 0;
1831 X
:= M
.ReadLongInt();
1832 Y
:= M
.ReadLongInt();
1833 g_Sound_PlayExAt(Name
, X
, Y
);
1836 g_Sound_PlayEx(Name
);
1839 procedure MC_RECV_CreateShot(var M
: TMsg
);
1841 I
, X
, Y
, XV
, YV
: Integer;
1843 Target
, Spawner
: Word;
1846 I
:= M
.ReadLongInt();
1847 ShType
:= M
.ReadByte();
1848 Target
:= M
.ReadWord();
1849 Spawner
:= M
.ReadWord();
1850 Timeout
:= M
.ReadLongWord();
1851 X
:= M
.ReadLongInt();
1852 Y
:= M
.ReadLongInt();
1853 XV
:= M
.ReadLongInt();
1854 YV
:= M
.ReadLongInt();
1856 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1857 if (Shots
<> nil) and (I
<= High(Shots
)) then
1859 Shots
[I
].Timeout
:= Timeout
;
1860 //Shots[I].Target := Target; // TODO: find a use for Target later
1864 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1866 I
, TX
, TY
, TXV
, TYV
: Integer;
1868 I
:= M
.ReadLongInt();
1869 TX
:= M
.ReadLongInt();
1870 TY
:= M
.ReadLongInt();
1871 TXV
:= M
.ReadLongInt();
1872 TYV
:= M
.ReadLongInt();
1874 if (Shots
<> nil) and (I
<= High(Shots
)) then
1884 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1889 if not gGameOn
then Exit
;
1890 I
:= M
.ReadLongInt();
1891 L
:= (M
.ReadByte() <> 0);
1892 X
:= M
.ReadLongInt();
1893 Y
:= M
.ReadLongInt();
1895 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1898 procedure MC_RECV_GameStats(var M
: TMsg
);
1900 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1902 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1903 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1906 if gGameSettings
.GameMode
= GM_COOP
then
1908 gCoopMonstersKilled
:= M
.ReadWord();
1909 gCoopSecretsFound
:= M
.ReadWord();
1913 procedure MC_RECV_CoopStats(var M
: TMsg
);
1915 gTotalMonsters
:= M
.ReadLongInt();
1916 gSecretsCount
:= M
.ReadLongInt();
1917 gCoopTotalMonstersKilled
:= M
.ReadWord();
1918 gCoopTotalSecretsFound
:= M
.ReadWord();
1919 gCoopTotalMonsters
:= M
.ReadWord();
1920 gCoopTotalSecrets
:= M
.ReadWord();
1923 procedure MC_RECV_GameEvent(var M
: TMsg
);
1932 i1
, i2
: TStrings_Locale
;
1935 goodCmd
: Boolean = true;
1937 FillChar(EvHash
, Sizeof(EvHash
), 0);
1938 EvType
:= M
.ReadByte();
1939 EvNum
:= M
.ReadLongInt();
1940 EvStr
:= M
.ReadString();
1941 gLastMap
:= M
.ReadByte() <> 0;
1942 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1943 gStatsPressed
:= True;
1944 EvTime
:= M
.ReadLongWord();
1945 BHash
:= M
.ReadByte() <> 0;
1947 EvHash
:= M
.ReadMD5();
1951 if (g_Res_received_map_start
<> 0) then
1953 if (g_Res_received_map_start
< 0) then exit
;
1956 NET_EV_MAPSTART
: goodCmd
:= true;
1957 NET_EV_MAPEND
: goodCmd
:= true;
1958 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1959 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1960 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1962 if not goodCmd
then exit
;
1968 if (g_Res_received_map_start
<> 0) then
1970 g_Res_received_map_start
:= -1;
1975 g_Game_ClearLoading();
1976 g_Game_StopAllSounds(True);
1978 gSwitchGameMode
:= Byte(EvNum
);
1979 gGameSettings
.GameMode
:= gSwitchGameMode
;
1982 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1984 if not isWadPath(EvStr
) then
1985 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1987 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1991 MC_SEND_FullStateRequest
;
1997 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1998 gLMSRespawnTime
:= 0;
1999 if (g_Res_received_map_start
<> 0) then
2001 g_Res_received_map_start
:= -1;
2005 gMissionFailed
:= EvNum
<> 0;
2006 gExit
:= EXIT_ENDLEVELCUSTOM
;
2014 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
2016 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
2018 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
2024 if NetDeafLevel
< 2 then
2026 if EvNum
= TEAM_RED
then
2027 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
2028 if EvNum
= TEAM_BLUE
then
2029 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
2035 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
2036 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2041 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
2042 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2049 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
2050 gLMSRespawnTime
:= gTime
+ EvNum
;
2051 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2053 else if gPlayer1
= nil then
2055 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2059 NET_EV_LMS_SURVIVOR
:
2060 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2063 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2067 pl
:= g_Player_Get(EvNum
and $FFFF);
2072 cnt
:= (EvNum
shr 16) and $FF;
2073 if Pos('w', EvStr
) = 0 then
2076 if Pos('t', EvStr
) = 0 then
2079 if Pos('-', EvStr
) = 0 then
2081 if Pos('e', EvStr
) = 0 then
2082 i1
:= I_PLAYER_SCORE_ADD_OWN
2084 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2087 if Pos('e', EvStr
) = 0 then
2088 i1
:= I_PLAYER_SCORE_SUB_OWN
2090 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2093 if Pos('r', EvStr
) > 0 then
2094 i2
:= I_PLAYER_SCORE_TO_RED
2096 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2097 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2101 if Pos('-', EvStr
) = 0 then
2102 i1
:= I_PLAYER_SCORE_ADD_TEAM
2104 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2106 if Pos('r', EvStr
) > 0 then
2107 i2
:= I_PLAYER_SCORE_RED
2109 i2
:= I_PLAYER_SCORE_BLUE
;
2110 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2115 if Pos('e', EvStr
) = 0 then
2116 i1
:= I_PLAYER_SCORE_WIN_OWN
2118 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
2120 if Pos('r', EvStr
) > 0 then
2121 i2
:= I_PLAYER_SCORE_TO_RED
2123 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2124 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
2130 if EvNum
= TEAM_RED
then
2131 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2132 if EvNum
= TEAM_BLUE
then
2133 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2134 if EvNum
= -TEAM_RED
then
2135 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2136 if EvNum
= -TEAM_BLUE
then
2137 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2142 g_Player_RemoveAllCorpses
;
2143 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2144 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2148 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2152 if EvNum
= TEAM_RED
then
2153 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2154 if EvNum
= TEAM_BLUE
then
2155 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2159 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2162 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2165 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2168 g_Game_Announce_KillCombo(EvNum
);
2170 NET_EV_PLAYER_TOUCH
:
2172 pl
:= g_Player_Get(EvNum
);
2179 pl
:= g_Player_Get(EvNum
);
2182 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2183 g_Sound_PlayEx('SOUND_GAME_SECRET');
2189 pl
:= g_Player_Get(EvNum
);
2190 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2195 procedure MC_RECV_FlagPos(var M
: TMsg
);
2200 if Fl
= FLAG_NONE
then Exit
;
2201 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2202 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2203 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2204 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2207 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2216 EvType
:= M
.ReadByte();
2219 if Fl
= FLAG_NONE
then Exit
;
2221 Quiet
:= (M
.ReadByte() <> 0);
2222 PID
:= M
.ReadWord();
2224 gFlags
[Fl
].State
:= M
.ReadByte();
2225 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2226 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2227 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2228 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2229 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2230 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2232 Pl
:= g_Player_Get(PID
);
2234 (EvType
<> FLAG_STATE_NORMAL
) and
2235 (EvType
<> FLAG_STATE_DROPPED
) and
2236 (EvType
<> FLAG_STATE_RETURNED
) then
2242 if Quiet
or (Pl
= nil) then Exit
;
2244 if Fl
= FLAG_RED
then
2245 s
:= _lc
[I_PLAYER_FLAG_RED
]
2247 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2249 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2251 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2252 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2253 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2258 if not sound_ret_flag
[a
].IsPlaying() then
2259 sound_ret_flag
[a
].Play();
2262 FLAG_STATE_CAPTURED
:
2264 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2268 if Fl
= FLAG_RED
then
2269 s
:= _lc
[I_PLAYER_FLAG_RED
]
2271 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2273 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2274 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2276 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2277 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2278 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2283 if not sound_get_flag
[a
].IsPlaying() then
2284 sound_get_flag
[a
].Play();
2289 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2291 if Quiet
or (Pl
= nil) then Exit
;
2293 if Fl
= FLAG_RED
then
2294 s
:= _lc
[I_PLAYER_FLAG_RED
]
2296 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2298 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2299 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2301 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2302 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2303 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2308 if not sound_lost_flag
[a
].IsPlaying() then
2309 sound_lost_flag
[a
].Play();
2314 g_Map_ResetFlag(FLAG_RED
);
2315 g_Map_ResetFlag(FLAG_BLUE
);
2316 if Quiet
or (Pl
= nil) then Exit
;
2317 Pl
.SetFlag(FLAG_NONE
);
2319 if Fl
= FLAG_RED
then
2320 s
:= _lc
[I_PLAYER_FLAG_RED
]
2322 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2324 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2325 Insert('.', ts
, Length(ts
) + 1 - 3);
2326 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2327 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2329 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2330 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2331 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2336 if not sound_cap_flag
[a
].IsPlaying() then
2337 sound_cap_flag
[a
].Play();
2340 FLAG_STATE_RETURNED
:
2342 g_Map_ResetFlag(Fl
);
2345 if Fl
= FLAG_RED
then
2346 s
:= _lc
[I_PLAYER_FLAG_RED
]
2348 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2350 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2352 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2353 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2354 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2359 if not sound_ret_flag
[a
].IsPlaying() then
2360 sound_ret_flag
[a
].Play();
2365 procedure MC_RECV_GameSettings(var M
: TMsg
);
2367 gGameSettings
.GameMode
:= M
.ReadByte();
2368 gGameSettings
.GoalLimit
:= M
.ReadWord();
2369 gGameSettings
.TimeLimit
:= M
.ReadWord();
2370 gGameSettings
.MaxLives
:= M
.ReadByte();
2371 gGameSettings
.Options
:= M
.ReadLongWord();
2376 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2379 PName
, Model
: string;
2384 PID
:= M
.ReadWord();
2385 Pl
:= g_Player_Get(PID
);
2387 PName
:= M
.ReadString();
2388 Model
:= M
.ReadString();
2389 Color
.R
:= M
.ReadByte();
2390 Color
.G
:= M
.ReadByte();
2391 Color
.B
:= M
.ReadByte();
2395 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2397 if (Pl
<> nil) then Exit
;
2398 DID
:= g_Player_Create(Model
, Color
, T
, False);
2399 with g_Player_Get(DID
) do
2408 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2409 gPlayer1
.UID
:= PID
;
2410 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2411 gPlayer1
.ChangeTeam(T
);
2413 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2414 gPlayer2
.UID
:= PID
;
2415 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2416 gPlayer2
.ChangeTeam(T
);
2420 if NetDeafLevel
< 3 then
2421 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2422 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2426 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2433 TmpX
, TmpY
: Integer;
2437 GT
:= M
.ReadLongWord();
2438 if GT
< gTime
- NET_MAX_DIFFTIME
then
2445 PID
:= M
.ReadWord();
2446 Pl
:= g_Player_Get(PID
);
2448 if Pl
= nil then Exit
;
2454 FPing
:= M
.ReadWord();
2455 FLoss
:= M
.ReadByte();
2456 kByte
:= M
.ReadWord();
2457 Dir
:= M
.ReadByte();
2459 TmpX
:= M
.ReadLongInt();
2460 TmpY
:= M
.ReadLongInt();
2464 if LongBool(kByte
and NET_KEY_CHAT
) then
2465 PressKey(KEY_CHAT
, 10000)
2468 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2469 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2470 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2471 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2472 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2475 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2477 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2478 SetDirection(TDirection(Dir
));
2480 GameVelX
:= M
.ReadLongInt();
2481 GameVelY
:= M
.ReadLongInt();
2482 GameAccelX
:= M
.ReadLongInt();
2483 GameAccelY
:= M
.ReadLongInt();
2484 SetLerp(TmpX
, TmpY
);
2485 if NetForcePlayerUpdate
then Update();
2489 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2493 I
, OldFire
: Integer;
2494 OldJet
, Flam
: Boolean;
2497 PID
:= M
.ReadWord();
2498 Pl
:= g_Player_Get(PID
);
2505 alive
:= (M
.ReadByte() <> 0);
2506 GodMode
:= (M
.ReadByte() <> 0);
2507 Health
:= M
.ReadLongInt();
2508 Armor
:= M
.ReadLongInt();
2509 Air
:= M
.ReadLongInt();
2510 JetFuel
:= M
.ReadLongInt();
2511 Lives
:= M
.ReadByte();
2512 NewTeam
:= M
.ReadByte();
2514 for I
:= WP_FIRST
to WP_LAST
do
2515 FWeapon
[I
] := (M
.ReadByte() <> 0);
2517 for I
:= A_BULLETS
to A_HIGH
do
2518 FAmmo
[I
] := M
.ReadWord();
2520 for I
:= A_BULLETS
to A_HIGH
do
2521 FMaxAmmo
[I
] := M
.ReadWord();
2523 for I
:= MR_SUIT
to MR_MAX
do
2524 FMegaRulez
[I
] := M
.ReadLongWord();
2527 if (M
.ReadByte() <> 0) then
2528 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2529 if (M
.ReadByte() <> 0) then
2530 FRulez
:= FRulez
+ [R_KEY_RED
];
2531 if (M
.ReadByte() <> 0) then
2532 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2533 if (M
.ReadByte() <> 0) then
2534 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2535 if (M
.ReadByte() <> 0) then
2536 FRulez
:= FRulez
+ [R_BERSERK
];
2538 Frags
:= M
.ReadLongInt();
2539 Death
:= M
.ReadLongInt();
2541 SetWeapon(M
.ReadByte());
2543 FSpectator
:= M
.ReadByte() <> 0;
2546 if UID
= NetPlrUID1
then
2548 gSpectLatchPID1
:= UID
;
2551 if UID
= NetPlrUID2
then
2553 gSpectLatchPID2
:= UID
;
2559 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2562 gSpectLatchPID1
:= 0;
2564 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2567 gSpectLatchPID2
:= 0;
2570 FGhost
:= M
.ReadByte() <> 0;
2571 FPhysics
:= M
.ReadByte() <> 0;
2572 FNoRespawn
:= M
.ReadByte() <> 0;
2574 FJetpack
:= M
.ReadByte() <> 0;
2575 OldFire
:= FFireTime
;
2576 FFireTime
:= M
.ReadLongInt();
2577 if (OldFire
<= 0) and (FFireTime
> 0) then
2578 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2579 Flam
:= M
.ReadByte() <> 0;
2580 FSpawnInvul
:= M
.ReadLongInt();
2581 if OldJet
and not FJetpack
then
2583 else if not OldJet
and FJetpack
then
2585 if FFlaming
and not Flam
then
2587 if Team
<> NewTeam
then
2588 Pl
.ChangeTeam(NewTeam
);
2594 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2599 Attacker
, Value
: Word;
2603 if not gGameOn
then Exit
;
2604 PID
:= M
.ReadWord();
2605 Pl
:= g_Player_Get(PID
);
2606 if Pl
= nil then Exit
;
2608 Kind
:= M
.ReadByte();
2609 Attacker
:= M
.ReadWord();
2610 Value
:= M
.ReadWord();
2615 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2620 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2624 KillType
, DeathType
: Byte;
2628 if not gGameOn
then Exit
;
2629 PID
:= M
.ReadWord();
2630 Pl
:= g_Player_Get(PID
);
2631 if Pl
= nil then Exit
;
2633 KillType
:= M
.ReadByte();
2634 DeathType
:= M
.ReadByte();
2635 Attacker
:= M
.ReadWord();
2639 Kill(KillType
, Attacker
, DeathType
);
2644 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2649 PID
:= M
.ReadWord();
2650 Pl
:= g_Player_Get(PID
);
2652 if Pl
= nil then Exit
;
2654 if NetDeafLevel
< 3 then
2655 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2656 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2658 g_Player_Remove(PID
);
2663 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2668 X
, Y
, AX
, AY
: Integer;
2672 if not gGameOn
then Exit
;
2673 PID
:= M
.ReadWord();
2674 Pl
:= g_Player_Get(PID
);
2675 if Pl
= nil then Exit
;
2677 Weap
:= M
.ReadByte();
2678 X
:= M
.ReadLongInt();
2679 Y
:= M
.ReadLongInt();
2680 AX
:= M
.ReadLongInt();
2681 AY
:= M
.ReadLongInt();
2682 SHID
:= M
.ReadLongInt();
2685 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2688 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 TmpModel
<> Pl
.Model
.Name
then
2726 Pl
.SetModel(TmpModel
);
2731 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2735 X
, Y
, VX
, VY
: Integer;
2737 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
);
2762 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2764 Anim
:= TAnimation
.Create(AID
, False, 4);
2765 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2771 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2776 if not gGameOn
then Exit
;
2778 Quiet
:= M
.ReadByte() <> 0;
2780 if not g_Items_ValidId(ID
) then exit
;
2782 if not Quiet
then g_Items_EmitPickupSound(ID
);
2787 procedure MC_RECV_ItemPos(var M
: TMsg
);
2790 X
, Y
, VX
, VY
: Integer;
2793 if not gGameOn
then Exit
;
2796 X
:= M
.ReadLongInt();
2797 Y
:= M
.ReadLongInt();
2798 VX
:= M
.ReadLongInt();
2799 VY
:= M
.ReadLongInt();
2801 if g_Items_ValidId(ID
) then
2803 it
:= g_Items_ByIdx(ID
);
2808 it
.positionChanged();
2814 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2821 if not gGameOn
then Exit
;
2823 PGUID
:= Integer(M
.ReadLongWord());
2824 Tex
:= M
.ReadLongInt();
2825 Fr
:= M
.ReadLongInt();
2826 Cnt
:= M
.ReadByte();
2827 Loop
:= M
.ReadByte();
2829 TP
:= g_Map_PanelByGUID(PGUID
);
2833 TP
.SetTexture(Tex
, Loop
);
2834 TP
.SetFrame(Fr
, Cnt
);
2838 procedure MC_RECV_PanelState(var M
: TMsg
);
2843 X
, Y
, W
, H
: Integer;
2845 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2846 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2849 if not gGameOn
then Exit
;
2851 PGUID
:= Integer(M
.ReadLongWord());
2852 E
:= (M
.ReadByte() <> 0);
2853 Lift
:= M
.ReadByte();
2854 X
:= M
.ReadLongInt();
2855 Y
:= M
.ReadLongInt();
2859 speedX
:= M
.ReadLongInt();
2860 speedY
:= M
.ReadLongInt();
2861 startX
:= M
.ReadLongInt();
2862 startY
:= M
.ReadLongInt();
2863 endX
:= M
.ReadLongInt();
2864 endY
:= M
.ReadLongInt();
2865 sizeSpX
:= M
.ReadLongInt();
2866 sizeSpY
:= M
.ReadLongInt();
2867 sizeEX
:= M
.ReadLongInt();
2868 sizeEY
:= M
.ReadLongInt();
2869 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2871 TP
:= g_Map_PanelByGUID(PGUID
);
2872 if (TP
= nil) then exit
;
2874 // update lifts state
2875 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2877 // update enabled/disabled state for all panels
2878 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2880 // update panel position, as it can be moved (mplat)
2885 // update mplat state
2886 TP
.movingSpeedX
:= speedX
;
2887 TP
.movingSpeedY
:= speedY
;
2888 TP
.movingStartX
:= startX
;
2889 TP
.movingStartY
:= startY
;
2890 TP
.movingEndX
:= endX
;
2891 TP
.movingEndY
:= endY
;
2892 TP
.sizeSpeedX
:= sizeSpX
;
2893 TP
.sizeSpeedY
:= sizeSpY
;
2894 TP
.sizeEndX
:= sizeEX
;
2895 TP
.sizeEndY
:= sizeEY
;
2896 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2897 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2898 // notify panel of it's position/size change, so it can fix other internal structures
2899 TP
.positionChanged();
2904 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2907 SPos
, SID
: LongWord;
2911 if not gGameOn
then Exit
;
2912 if gTriggers
= nil then Exit
;
2914 SID
:= M
.ReadLongWord();
2915 SPlaying
:= M
.ReadByte() <> 0;
2916 SPos
:= M
.ReadLongWord();
2917 SCount
:= M
.ReadLongInt();
2919 for I
:= Low(gTriggers
) to High(gTriggers
) do
2920 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2921 if gTriggers
[I
].ClientID
= SID
then
2922 with gTriggers
[I
] do
2924 if Sound
<> nil then
2929 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2931 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2932 Sound
.SetPosition(SPos
);
2935 if Sound
.IsPlaying
then Sound
.Stop
;
2938 SoundPlayCount
:= SCount
;
2942 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2949 if not gGameOn
then Exit
;
2951 MName
:= M
.ReadString();
2952 MPlaying
:= M
.ReadByte() <> 0;
2953 MPos
:= M
.ReadLongWord();
2954 MPaused
:= M
.ReadByte() <> 0;
2955 MPos
:= MPos
+1; //k8: stfu, fpc!
2959 gMusic
.SetByName(MName
);
2961 // gMusic.SetPosition(MPos);
2962 gMusic
.SpecPause
:= MPaused
;
2965 if gMusic
.IsPlaying
then gMusic
.Stop
;
2970 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2973 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2974 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2979 Mon
:= g_Monsters_ByUID(ID
);
2983 MType
:= M
.ReadByte();
2984 MState
:= M
.ReadByte();
2985 MAnim
:= M
.ReadByte();
2986 MTarg
:= M
.ReadWord();
2987 MTargTime
:= M
.ReadLongInt();
2988 MBehav
:= M
.ReadByte();
2989 MSleep
:= M
.ReadLongInt();
2990 MHealth
:= M
.ReadLongInt();
2991 MAmmo
:= M
.ReadLongInt();
2993 X
:= M
.ReadLongInt();
2994 Y
:= M
.ReadLongInt();
2995 VX
:= M
.ReadLongInt();
2996 VY
:= M
.ReadLongInt();
2997 MDir
:= M
.ReadByte();
2999 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
3000 Mon
:= g_Monsters_ByUID(ID
);
3007 MonsterAnim
:= MAnim
;
3008 MonsterTargetUID
:= MTarg
;
3009 MonsterTargetTime
:= MTargTime
;
3010 MonsterBehaviour
:= MBehav
;
3011 MonsterSleep
:= MSleep
;
3012 MonsterAmmo
:= MAmmo
;
3017 setPosition(X
, Y
); // this will call positionChanged();
3023 procedure MC_RECV_MonsterPos(var M
: TMsg
);
3030 Mon
:= g_Monsters_ByUID(ID
);
3036 X
:= M
.ReadLongInt();
3037 Y
:= M
.ReadLongInt();
3038 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
3039 GameVelX
:= M
.ReadLongInt();
3040 GameVelY
:= M
.ReadLongInt();
3041 GameDirection
:= TDirection(M
.ReadByte());
3045 procedure MC_RECV_MonsterState(var M
: TMsg
);
3047 ID
, OldFire
: Integer;
3048 MState
, MFAnm
: Byte;
3050 AnimRevert
: Boolean;
3053 Mon
:= g_Monsters_ByUID(ID
);
3054 if Mon
= nil then Exit
;
3056 MState
:= M
.ReadByte();
3057 MFAnm
:= M
.ReadByte();
3061 MonsterTargetUID
:= M
.ReadWord();
3062 MonsterTargetTime
:= M
.ReadLongInt();
3063 MonsterSleep
:= M
.ReadLongInt();
3064 MonsterHealth
:= M
.ReadLongInt();
3065 MonsterAmmo
:= M
.ReadLongInt();
3066 MonsterPain
:= M
.ReadLongInt();
3067 AnimRevert
:= M
.ReadByte() <> 0;
3068 OldFire
:= FFireTime
;
3069 FFireTime
:= M
.ReadLongInt();
3070 if (OldFire
<= 0) and (FFireTime
> 0) then
3071 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3072 RevertAnim(AnimRevert
);
3074 if MonsterState
<> MState
then
3076 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3077 if (MState
= MONSTATE_DIE
) then DieSound();
3078 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3079 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3080 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3082 SetState(MState
, MFAnm
);
3087 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3091 X
, Y
, VX
, VY
: Integer;
3095 Mon
:= g_Monsters_ByUID(ID
);
3096 if Mon
= nil then Exit
;
3098 X
:= M
.ReadLongInt();
3099 Y
:= M
.ReadLongInt();
3100 VX
:= M
.ReadLongInt();
3101 VY
:= M
.ReadLongInt();
3103 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3106 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3112 Mon
:= g_Monsters_ByUID(ID
);
3113 if Mon
= nil then Exit
;
3115 Mon
.MonsterRemoved
:= True;
3118 procedure MC_RECV_TimeSync(var M
: TMsg
);
3122 Time
:= M
.ReadLongWord();
3124 if gState
= STATE_INTERCUSTOM
then
3125 gServInterTime
:= Min(Time
, 255);
3128 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3132 Int1
, Int2
: SmallInt;
3134 EvID
:= M
.ReadByte();
3135 Int1
:= M
.ReadSmallInt();
3136 Int2
:= M
.ReadSmallInt();
3137 Str1
:= M
.ReadString();
3138 Str2
:= M
.ReadString();
3140 if NetDeafLevel
< 2 then
3143 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3145 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3147 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3149 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3151 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3157 procedure MC_SEND_Info(Password
: string);
3162 NetOut
.Write(Byte(NET_MSG_INFO
));
3163 NetOut
.Write(GAME_VERSION
);
3164 NetOut
.Write(Password
);
3165 NetOut
.Write(gPlayer1Settings
.Name
);
3166 NetOut
.Write(gPlayer1Settings
.Model
);
3167 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3168 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3169 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3170 NetOut
.Write(gPlayer1Settings
.Team
);
3171 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3172 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3173 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3174 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3175 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3177 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3180 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3182 NetOut
.Write(Byte(NET_MSG_CHAT
));
3186 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3189 procedure MC_SEND_PlayerPos();
3194 WeaponAct
: Byte = 0;
3195 WeaponSelect
: Word = 0;
3198 if not gGameOn
then Exit
;
3199 if gPlayers
= nil then Exit
;
3200 if gPlayer1
= nil then Exit
;
3203 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3205 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3207 strafeDir
:= P1MoveButton
shr 4;
3208 P1MoveButton
:= P1MoveButton
and $0F;
3210 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3212 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3214 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3218 if gPlayerAction
[0, ACTION_STRAFE
] then
3220 // new strafe mechanics
3221 if (strafeDir
= 0) then
3222 strafeDir
:= P1MoveButton
; // start strafing
3223 // now set direction according to strafe (reversed)
3224 if (strafeDir
= 2) then
3225 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3226 else if (strafeDir
= 1) then
3227 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3231 strafeDir
:= 0; // not strafing anymore
3232 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3233 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3234 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3235 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3236 else if P1MoveButton
<> 0 then
3237 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3240 gPlayer1
.ReleaseKeys
;
3241 if P1MoveButton
= 1 then
3243 kByte
:= kByte
or NET_KEY_LEFT
;
3244 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3246 if P1MoveButton
= 2 then
3248 kByte
:= kByte
or NET_KEY_RIGHT
;
3249 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3251 if gPlayerAction
[0, ACTION_LOOKUP
] then
3253 kByte
:= kByte
or NET_KEY_UP
;
3254 gPlayer1
.PressKey(KEY_UP
, 10000);
3256 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3258 kByte
:= kByte
or NET_KEY_DOWN
;
3259 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3261 if gPlayerAction
[0, ACTION_JUMP
] then
3263 kByte
:= kByte
or NET_KEY_JUMP
;
3264 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3266 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3267 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3269 for i
:= WP_FACT
to WP_LACT
do
3271 if gWeaponAction
[0, i
] then
3273 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3274 gWeaponAction
[0, i
] := False
3278 for i
:= WP_FIRST
to WP_LAST
do
3280 if gSelectWeapon
[0, i
] then
3282 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3283 gSelectWeapon
[0, i
] := False
3287 // fix movebutton state
3288 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3291 kByte
:= NET_KEY_CHAT
;
3293 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3294 NetOut
.Write(gTime
);
3295 NetOut
.Write(kByte
);
3296 NetOut
.Write(Byte(gPlayer1
.Direction
));
3297 NetOut
.Write(WeaponAct
);
3298 NetOut
.Write(WeaponSelect
);
3299 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3300 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3302 //kBytePrev := kByte;
3303 //kDirPrev := gPlayer1.Direction;
3306 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3308 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3309 NetOut
.Write(Byte(Start
));
3310 NetOut
.Write(Command
);
3311 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3314 procedure MC_SEND_PlayerSettings();
3317 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3318 NetOut
.Write(gPlayer1Settings
.Name
);
3319 NetOut
.Write(gPlayer1Settings
.Model
);
3320 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3321 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3322 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3323 NetOut
.Write(gPlayer1Settings
.Team
);
3324 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3325 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3326 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3327 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3328 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3330 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3333 procedure MC_SEND_FullStateRequest();
3335 NetOut
.Write(Byte(NET_MSG_REQFST
));
3337 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3340 procedure MC_SEND_CheatRequest(Kind
: Byte);
3342 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3345 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3347 procedure MC_SEND_RCONPassword(Password
: string);
3349 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3350 NetOut
.Write(Password
);
3352 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3354 procedure MC_SEND_RCONCommand(Cmd
: string);
3356 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3359 g_Net_Client_Send(True, NET_CHAN_SERVICE
);