02b6286b21cf406dab858542c3d73a6e13d0d3f3
1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
20 uses e_msg
, g_net
, g_triggers
, Classes
, SysUtils
, md5
;
66 NET_MSG_RCON_AUTH
= 191;
67 NET_MSG_RCON_CMD
= 192;
68 NET_MSG_TIME_SYNC
= 194;
69 NET_MSG_VOTE_EVENT
= 195;
72 NET_MSG_MAP_REQUEST = 201;
73 NET_MSG_MAP_RESPONSE = 202;
74 NET_MSG_RES_REQUEST = 203;
75 NET_MSG_RES_RESPONSE = 204;
99 NET_EV_CHANGE_TEAM
= 3;
100 NET_EV_PLAYER_KICK
= 4;
101 NET_EV_PLAYER_BAN
= 5;
102 NET_EV_LMS_WARMUP
= 6;
103 NET_EV_LMS_SURVIVOR
= 7;
107 NET_EV_SCORE_MSG
= 11;
108 NET_EV_LMS_START
= 12;
110 NET_EV_TLMS_WIN
= 14;
111 NET_EV_LMS_LOSE
= 15;
112 NET_EV_LMS_DRAW
= 16;
113 NET_EV_KILLCOMBO
= 17;
114 NET_EV_PLAYER_TOUCH
= 18;
116 NET_EV_INTER_READY
= 20;
117 NET_EV_LMS_NOSPAWN
= 21;
124 NET_VE_INPROGRESS
= 6;
131 NET_CHEAT_SUICIDE
= 1;
132 NET_CHEAT_SPECTATE
= 2;
134 NET_CHEAT_DROPFLAG
= 4;
136 NET_MAX_DIFFTIME
= 5000 div 36;
140 procedure MH_MalformedPacket(C
: pTNetClient
);
141 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
143 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
146 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
147 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
148 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
149 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
150 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
151 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
152 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
153 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
156 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
157 procedure MH_SEND_Info(ID
: Byte);
158 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
189 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
190 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
191 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
193 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
194 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
196 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
197 procedure MH_SEND_VoteEvent(EvType
: Byte;
198 StrArg1
: string = 'a'; StrArg2
: string = 'b';
199 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
200 ID
: Integer = NET_EVERYONE
);
202 // CLIENT MESSAGES //
205 procedure MC_RECV_Chat(var M
: TMsg
);
206 procedure MC_RECV_Effect(var M
: TMsg
);
207 procedure MC_RECV_Sound(var M
: TMsg
);
208 procedure MC_RECV_GameStats(var M
: TMsg
);
209 procedure MC_RECV_CoopStats(var M
: TMsg
);
210 procedure MC_RECV_GameEvent(var M
: TMsg
);
211 procedure MC_RECV_FlagEvent(var M
: TMsg
);
212 procedure MC_RECV_FlagPos(var M
: TMsg
);
213 procedure MC_RECV_GameSettings(var M
: TMsg
);
215 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
216 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
217 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
218 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
219 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
220 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
221 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
222 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
224 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
225 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
226 procedure MC_RECV_ItemPos(var M
: TMsg
);
228 procedure MC_RECV_PanelTexture(var M
: TMsg
);
229 procedure MC_RECV_PanelState(var M
: TMsg
);
231 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
232 procedure MC_RECV_MonsterPos(var M
: TMsg
);
233 procedure MC_RECV_MonsterState(var M
: TMsg
);
234 procedure MC_RECV_MonsterShot(var M
: TMsg
);
235 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
237 procedure MC_RECV_CreateShot(var M
: TMsg
);
238 procedure MC_RECV_UpdateShot(var M
: TMsg
);
239 procedure MC_RECV_DeleteShot(var M
: TMsg
);
241 procedure MC_RECV_TriggerSound(var M
: TMsg
);
242 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
244 procedure MC_RECV_TimeSync(var M
: TMsg
);
245 procedure MC_RECV_VoteEvent(var M
: TMsg
);
247 procedure MC_SEND_Info(Password
: string);
248 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
249 procedure MC_SEND_PlayerPos();
250 procedure MC_SEND_FullStateRequest();
251 procedure MC_SEND_PlayerSettings();
252 procedure MC_SEND_CheatRequest(Kind
: Byte);
253 procedure MC_SEND_RCONPassword(Password
: string);
254 procedure MC_SEND_RCONCommand(Cmd
: string);
255 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
257 //procedure MC_SEND_MapRequest();
258 //procedure MC_SEND_ResRequest(const resName: AnsiString);
262 TExternalResourceInfo
= record
277 ExternalResources
: array of TExternalResourceInfo
;
280 function IsValidFileName(const S
: String): Boolean;
281 function IsValidFilePath(const S
: String): Boolean;
293 Math
, ENet
, e_input
, e_log
, g_base
, g_basic
,
294 g_textures
, g_sound
, g_console
, g_options
,
295 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
,
296 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
300 NET_KEY_LEFT
= 1 shl 0;
301 NET_KEY_RIGHT
= 1 shl 1;
302 NET_KEY_UP
= 1 shl 2;
303 NET_KEY_DOWN
= 1 shl 3;
304 NET_KEY_JUMP
= 1 shl 4;
305 NET_KEY_FIRE
= 1 shl 5;
306 NET_KEY_OPEN
= 1 shl 6;
307 NET_KEY_CHAT
= 1 shl 7;
308 NET_KEY_FORCEDIR
= 1 shl 8;
311 //kBytePrev: Word = 0;
312 //kDirPrev: TDirection = D_LEFT;
313 //HostGameTime: Word = 0;
316 function IsValidFileName(const S
: String): Boolean;
318 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
323 for I
:= 1 to Length(S
) do
324 Result
:= Result
and (not(S
[I
] in Forbidden
));
327 function IsValidFilePath(const S
: String): Boolean;
332 if not IsValidFileName(S
) then exit
;
333 if FileExists(S
) then exit
;
334 I
:= LastDelimiter('\/', S
);
336 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
347 procedure MH_MalformedPacket(C
: pTNetClient
);
349 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
350 _lc
[I_NET_DISC_PROTOCOL
]);
351 g_Net_Host_Kick(C
^.ID
, NET_DISC_PROTOCOL
);
354 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
363 Pl
:= g_Player_Get(PID
);
367 Txt
:= M
.ReadString();
368 Mode
:= M
.ReadByte();
373 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
375 if (Mode
= NET_CHAT_SYSTEM
) then
376 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
377 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
378 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
381 MH_SEND_Chat(Txt
, Mode
)
383 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
386 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
388 Ver
, PName
, Model
, Pw
: string;
391 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
401 Ver
:= M
.ReadString();
402 Pw
:= M
.ReadString();
403 PName
:= M
.ReadString();
404 Model
:= M
.ReadString();
409 WeapSwitch
:= M
.ReadByte();
410 for I
:= WP_FIRST
to WP_LAST
+ 1 do
411 TmpPrefArray
[I
] := M
.ReadByte();
412 SwitchEmpty
:= M
.ReadByte();
413 SkipF
:= M
.ReadByte();
418 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
420 if Ver
<> GAME_VERSION
then
422 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
423 _lc
[I_NET_DISC_VERSION
]);
424 g_Net_Host_Kick(C
^.ID
, NET_DISC_VERSION
);
428 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
430 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
432 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
433 _lc
[I_NET_DISC_BAN
]);
434 g_Net_Host_Kick(C
^.ID
, NET_DISC_BAN
);
438 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
439 _lc
[I_NET_DISC_BAN
]);
440 g_Net_Host_Kick(C
^.ID
, NET_DISC_TEMPBAN
);
445 if NetPassword
<> '' then
446 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
448 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
449 _lc
[I_NET_DISC_PASSWORD
]);
450 g_Net_Host_Kick(C
^.ID
, NET_DISC_PASSWORD
);
454 if (C
^.Player
<> 0) then
456 // already received info
457 g_Net_Penalize(C
, 'client info spam');
465 PID
:= g_Player_Create(Model
, Color
, T
, False);
466 with g_Player_Get(PID
) do
469 WeapSwitchMode
:= WeapSwitch
;
470 SetWeaponPrefs(TmpPrefArray
);
471 SwitchToEmpty
:= SwitchEmpty
;
473 if (g_Force_Model_Get() <> 0) then
474 SetModel(g_Forced_Model_GetName());
479 C
^.WaitForFirstSpawn
:= false;
482 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
483 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
484 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
488 with g_Player_Get(PID
) do
492 // round in progress, don't spawn
493 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
494 //e_LogWritefln('spawning player with pid #%u...', [PID]);
495 //Respawn(gGameSettings.GameType = GT_SINGLE);
496 //k8: no, do not spawn a player yet, wait for "request full state" packet
500 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
501 // that is, if we'll set it to `true`, the player can be spawned after
502 // warmup time ran out, for example, regardless of the real player state.
503 // also, this seems to work only for the initial connection. further
504 // map changes could initiate resource downloading, but the player will
505 // be spawned immediately.
506 // the proper solution will require another player state, "ephemeral".
507 // the player should start any map in "ephemeral" state, and turned into
508 // real mobj only when they sent a special "i am ready" packet. this packet
509 // must be sent after receiving the full state, so the player will get a full
510 // map view before going into game.
511 FWantsInGame
:= false;
512 C
^.WaitForFirstSpawn
:= true;
515 //if not C^.WaitForFirstSpawn then
517 for I
:= Low(NetClients
) to High(NetClients
) do
519 if NetClients
[I
].ID
= C
^.ID
then Continue
;
520 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
521 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
522 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
526 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
527 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
531 //g_Net_Slist_Update;
537 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
541 if not C
.WaitForFirstSpawn
then exit
;
542 plr
:= g_Player_Get(C
^.Player
);
543 if not assigned(plr
) then exit
;
544 g_Net_Slist_ServerPlayerComes();
545 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
546 C
.WaitForFirstSpawn
:= false;
547 plr
.FNoRespawn
:= false;
548 plr
.FWantsInGame
:= true; // TODO: look into this later
550 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
553 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
558 if gLMSRespawn
> LMS_RESPAWN_NONE
then
559 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
564 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
566 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
568 if C
^.FullUpdateSent
then
570 // FullStateRequest spam?
571 g_Net_Penalize(C
, 'duplicate full state request');
577 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
581 C
^.RequestedFullUpdate
:= True;
587 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
600 if not gGameOn
then Exit
;
603 GT
:= M
.ReadLongWord();
608 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
611 Pl
:= g_Player_Get(PID
);
615 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
621 kByte
:= M
.ReadWord();
623 WeaponAct
:= M
.ReadByte();
624 WeaponSelect
:= M
.ReadWord();
629 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
631 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
632 if Direction
<> TDirection(Dir
) then
633 JustTeleported
:= False;
635 SetDirection(TDirection(Dir
));
638 if kByte
= NET_KEY_CHAT
then
640 PressKey(KEY_CHAT
, 10000);
644 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
645 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
646 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
647 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
648 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
649 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
650 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
654 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
656 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
657 ProcessWeaponAction(i
);
663 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
665 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
666 QueueWeaponSwitch(i
);
671 // MH_SEND_PlayerPos(False, PID, C^.ID);
674 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
681 Pl
:= g_Player_Get(C
^.Player
);
682 if Pl
= nil then Exit
;
685 CheatKind
:= M
.ReadByte();
690 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
694 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
697 if Pl
.FSpectator
then
699 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
702 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
709 if gState
<> STATE_INTERCUSTOM
then Exit
;
710 Pl
.FReady
:= not Pl
.FReady
;
713 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
714 Inc(gInterReadyCount
);
718 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
719 Dec(gInterReadyCount
);
727 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
734 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
743 TmpName
:= M
.ReadString();
744 TmpModel
:= M
.ReadString();
745 TmpColor
.R
:= M
.ReadByte();
746 TmpColor
.G
:= M
.ReadByte();
747 TmpColor
.B
:= M
.ReadByte();
748 TmpTeam
:= M
.ReadByte();
749 TmpWeapSwitch
:= M
.ReadByte();
750 for I
:= WP_FIRST
to WP_LAST
+ 1 do
751 TmpPrefArray
[I
] := M
.ReadByte();
752 TmpSwEmpty
:= M
.ReadByte();
753 TmpSkipF
:= M
.ReadByte();
758 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
760 Pl
:= g_Player_Get(C
^.Player
);
761 if Pl
= nil then Exit
;
763 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
766 Pl
.SetColor(TmpColor
);
768 if Pl
.Name
<> TmpName
then
770 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
774 if (g_Force_Model_Get() <> 0) then
775 TmpModel
:= g_Forced_Model_GetName();
776 if TmpModel
<> Pl
.Model
.GetName() then
777 Pl
.SetModel(TmpModel
);
779 if (TmpWeapSwitch
<> Pl
.WeapSwitchMode
) then
780 Pl
.WeapSwitchMode
:= TmpWeapSwitch
;
782 Pl
.SetWeaponPrefs(TmpPrefArray
);
783 if (TmpSwEmpty
<> Pl
.SwitchToEmpty
) then
784 Pl
.SwitchToEmpty
:= TmpSwEmpty
;
786 if (TmpSkipF
<> Pl
.SkipFist
) then
787 Pl
.SkipFist
:= TmpSkipF
;
789 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
794 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
801 Pwd
:= M
.ReadString();
805 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
806 if not NetAllowRCON
then Exit
;
807 if Pwd
= NetRCONPassword
then
810 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
813 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
816 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
823 Cmd
:= M
.ReadString();
827 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
828 if not NetAllowRCON
then Exit
;
829 if not C
^.RCONAuth
then
831 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
834 g_Console_Process(Cmd
);
839 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
842 Name
, Command
: string;
849 Start
:= M
.ReadByte() <> 0;
850 Command
:= M
.ReadString();
855 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
857 Pl
:= g_Player_Get(C
^.Player
);
858 if Pl
= nil then Exit
;
863 if not g_Console_CommandBlacklisted(Command
) then
864 g_Game_StartVote(Command
, Name
);
866 else if gVoteInProgress
then
868 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
869 Need
:= Floor((NetClientCount
+1)/2.0) + 1
871 Need
:= Floor(NetClientCount
/2.0) + 1;
876 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
877 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
883 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
884 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
892 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
894 function sendItemRespawn (it
: PItem
): Boolean;
896 result
:= false; // don't stop
897 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
900 function sendMonSpawn (mon
: TMonster
): Boolean;
902 result
:= false; // don't stop
903 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
906 function sendPanelState (pan
: TPanel
): Boolean;
908 result
:= false; // don't stop
909 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
910 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
916 if (ID
< 0) or (ID
>= Length(NetClients
)) then
917 exit
; // bogus client, this shouldn't happen
919 NetClients
[ID
].FullUpdateSent
:= True;
921 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
923 MH_ProcessFirstSpawn(@NetClients
[ID
]);
925 if gPlayers
<> nil then
927 for I
:= Low(gPlayers
) to High(gPlayers
) do
929 if gPlayers
[I
] <> nil then
931 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
932 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
933 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
935 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
937 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
943 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
944 g_Mons_ForEach(sendMonSpawn
);
945 g_Map_ForEachPanel(sendPanelState
);
947 if gTriggers
<> nil then
949 for I
:= Low(gTriggers
) to High(gTriggers
) do
951 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
953 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
960 for I
:= Low(Shots
) to High(Shots
) do
962 if Shots
[i
].ShotType
in [6, 7, 8] then
964 MH_SEND_CreateShot(i
, ID
);
969 MH_SEND_TriggerMusic(ID
);
971 MH_SEND_GameStats(ID
);
972 MH_SEND_CoopStats(ID
);
974 if gGameSettings
.GameMode
= GM_CTF
then
976 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
977 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
980 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
985 procedure MH_SEND_Info(ID
: Byte);
989 NetOut
.Write(Byte(NET_MSG_INFO
));
991 NetOut
.Write(NetClients
[ID
].Player
);
992 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
993 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
994 NetOut
.Write(gWADHash
);
995 NetOut
.Write(gGameSettings
.GameMode
);
996 NetOut
.Write(gGameSettings
.ScoreLimit
);
997 NetOut
.Write(gGameSettings
.TimeLimit
);
998 NetOut
.Write(gGameSettings
.MaxLives
);
999 NetOut
.Write(gGameSettings
.Options
);
1000 NetOut
.Write(gTime
);
1002 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1005 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
1011 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1012 Mode
:= NET_CHAT_PLAYER
;
1015 if (Mode
= NET_CHAT_TEAM
) then
1017 for i
:= Low(gPlayers
) to High(gPlayers
) do
1018 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
1019 (gPlayers
[i
].Team
= ID
) then
1021 NetOut
.Write(Byte(NET_MSG_CHAT
));
1024 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
1031 NetOut
.Write(Byte(NET_MSG_CHAT
));
1034 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
1037 if Mode
= NET_CHAT_SYSTEM
then
1040 if ID
= NET_EVERYONE
then
1042 if Mode
= NET_CHAT_PLAYER
then
1044 g_Console_Add(Txt
, True);
1045 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1046 g_Game_ChatSound(b_Text_Unformat(Txt
));
1049 if Mode
= NET_CHAT_TEAM
then
1050 if gPlayer1
<> nil then
1052 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
1054 g_Console_Add(#18'[Team] '#2 + Txt
, True);
1055 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1056 g_Game_ChatSound(b_Text_Unformat(Txt
));
1058 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
1060 g_Console_Add(#20'[Team] '#2 + Txt
, True);
1061 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1062 g_Game_ChatSound(b_Text_Unformat(Txt
));
1068 Name
:= g_Net_ClientName_ByID(ID
);
1069 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1070 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1071 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1075 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1077 NetOut
.Write(Byte(NET_MSG_GFX
));
1083 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1086 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1088 NetOut
.Write(Byte(NET_MSG_SND
));
1092 NetOut
.Write(Byte(1));
1097 NetOut
.Write(Byte(0));
1099 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1102 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1104 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1106 NetOut
.Write(Byte(NET_MSG_SHADD
));
1108 NetOut
.Write(Shots
[Proj
].ShotType
);
1109 NetOut
.Write(Shots
[Proj
].Target
);
1110 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1111 NetOut
.Write(Shots
[Proj
].Timeout
);
1112 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1113 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1114 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1115 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1117 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1120 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1122 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1124 NetOut
.Write(Byte(NET_MSG_SHPOS
));
1126 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1127 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1128 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1129 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1131 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
1134 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1136 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1138 NetOut
.Write(Byte(Loud
));
1142 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1145 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1147 NetOut
.Write(Byte(NET_MSG_SCORE
));
1148 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1150 NetOut
.Write(gTeamStat
[TEAM_RED
].Score
);
1151 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Score
);
1154 if gGameSettings
.GameMode
= GM_COOP
then
1156 NetOut
.Write(gCoopMonstersKilled
);
1157 NetOut
.Write(gCoopSecretsFound
);
1160 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1163 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1165 NetOut
.Write(Byte(NET_MSG_COOP
));
1166 NetOut
.Write(gTotalMonsters
);
1167 NetOut
.Write(gSecretsCount
);
1168 NetOut
.Write(gCoopTotalMonstersKilled
);
1169 NetOut
.Write(gCoopTotalSecretsFound
);
1170 NetOut
.Write(gCoopTotalMonsters
);
1171 NetOut
.Write(gCoopTotalSecrets
);
1174 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1176 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1177 NetOut
.Write(EvType
);
1178 NetOut
.Write(EvNum
);
1179 NetOut
.Write(EvStr
);
1180 NetOut
.Write(Byte(gLastMap
));
1181 NetOut
.Write(gTime
);
1182 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1184 NetOut
.Write(Byte(1));
1185 NetOut
.Write(gWADHash
);
1187 NetOut
.Write(Byte(0));
1189 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1192 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1194 NetOut
.Write(Byte(NET_MSG_FLAG
));
1195 NetOut
.Write(EvType
);
1197 NetOut
.Write(Byte(Quiet
));
1199 NetOut
.Write(gFlags
[Flag
].State
);
1200 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1201 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1202 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1203 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1204 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1205 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1207 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1210 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1212 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1214 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1215 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1216 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1217 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1219 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1222 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1224 NetOut
.Write(Byte(NET_MSG_GSET
));
1225 NetOut
.Write(gGameSettings
.GameMode
);
1226 NetOut
.Write(gGameSettings
.ScoreLimit
);
1227 NetOut
.Write(gGameSettings
.TimeLimit
);
1228 NetOut
.Write(gGameSettings
.MaxLives
);
1229 NetOut
.Write(gGameSettings
.Options
);
1231 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1236 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1240 P
:= g_Player_Get(PID
);
1241 if P
= nil then Exit
;
1243 NetOut
.Write(Byte(NET_MSG_PLR
));
1245 NetOut
.Write(P
.Name
);
1247 NetOut
.Write(P
.FActualModelName
);
1248 NetOut
.Write(P
.FColor
.R
);
1249 NetOut
.Write(P
.FColor
.G
);
1250 NetOut
.Write(P
.FColor
.B
);
1251 NetOut
.Write(P
.Team
);
1253 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1256 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1261 Pl
:= g_Player_Get(PID
);
1262 if Pl
= nil then Exit
;
1263 if Pl
.FDummy
then Exit
;
1265 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1266 NetOut
.Write(gTime
);
1273 NetOut
.Write(FPing
);
1274 NetOut
.Write(FLoss
);
1275 if IsKeyPressed(KEY_CHAT
) then
1276 kByte
:= NET_KEY_CHAT
1279 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1280 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1281 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1282 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1283 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1286 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1288 NetOut
.Write(kByte
);
1289 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1290 NetOut
.Write(GameX
);
1291 NetOut
.Write(GameY
);
1292 NetOut
.Write(GameVelX
);
1293 NetOut
.Write(GameVelY
);
1294 NetOut
.Write(GameAccelX
);
1295 NetOut
.Write(GameAccelY
);
1298 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1301 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1306 P
:= g_Player_Get(PID
);
1307 if P
= nil then Exit
;
1309 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1314 NetOut
.Write(Byte(alive
));
1315 NetOut
.Write(Byte(GodMode
));
1316 NetOut
.Write(Health
);
1317 NetOut
.Write(Armor
);
1319 NetOut
.Write(JetFuel
);
1320 NetOut
.Write(Lives
);
1323 for I
:= WP_FIRST
to WP_LAST
do
1324 NetOut
.Write(Byte(FWeapon
[I
]));
1326 for I
:= A_BULLETS
to A_HIGH
do
1327 NetOut
.Write(FAmmo
[I
]);
1329 for I
:= A_BULLETS
to A_HIGH
do
1330 NetOut
.Write(FMaxAmmo
[I
]);
1332 for I
:= MR_SUIT
to MR_MAX
do
1333 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1335 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1336 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1337 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1338 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1339 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1341 NetOut
.Write(Frags
);
1342 NetOut
.Write(Death
);
1344 NetOut
.Write(CurrWeap
);
1346 NetOut
.Write(Byte(FSpectator
));
1347 NetOut
.Write(Byte(FGhost
));
1348 NetOut
.Write(Byte(FPhysics
));
1349 NetOut
.Write(Byte(FNoRespawn
));
1350 NetOut
.Write(Byte(FJetpack
));
1351 NetOut
.Write(FFireTime
);
1352 NetOut
.Write(Byte(FFlaming
));
1353 NetOut
.Write(FSpawnInvul
);
1356 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1359 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1361 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1364 NetOut
.Write(Attacker
);
1365 NetOut
.Write(Value
);
1369 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1372 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1374 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1376 NetOut
.Write(KillType
);
1377 NetOut
.Write(DeathType
);
1378 NetOut
.Write(Attacker
);
1380 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1383 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1385 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1387 NetOut
.Write(Weapon
);
1392 NetOut
.Write(ShotID
);
1394 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1397 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1399 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1402 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1405 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1409 Pl
:= g_Player_Get(PID
);
1410 if Pl
= nil then Exit
;
1412 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1414 NetOut
.Write(Pl
.Name
);
1416 NetOut
.Write(Pl
.Model
.GetName())
1419 NetOut
.Write(Pl
.FColor
.R
);
1420 NetOut
.Write(Pl
.FColor
.G
);
1421 NetOut
.Write(Pl
.FColor
.B
);
1422 NetOut
.Write(Pl
.Team
);
1424 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1429 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1434 it
:= g_Items_ByIdx(IID
);
1436 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1438 NetOut
.Write(Byte(Quiet
));
1440 if it
.dropped
then tt
:= tt
or $80;
1442 NetOut
.Write(Byte(it
.Fall
));
1443 NetOut
.Write(Byte(it
.Respawnable
));
1444 NetOut
.Write(it
.Obj
.X
);
1445 NetOut
.Write(it
.Obj
.Y
);
1446 NetOut
.Write(it
.Obj
.Vel
.X
);
1447 NetOut
.Write(it
.Obj
.Vel
.Y
);
1449 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1452 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1454 NetOut
.Write(Byte(NET_MSG_IDEL
));
1456 NetOut
.Write(Byte(Quiet
));
1458 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1461 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1465 it
:= g_Items_ByIdx(IID
);
1467 NetOut
.Write(Byte(NET_MSG_IPOS
));
1469 NetOut
.Write(it
.Obj
.X
);
1470 NetOut
.Write(it
.Obj
.Y
);
1471 NetOut
.Write(it
.Obj
.Vel
.X
);
1472 NetOut
.Write(it
.Obj
.Vel
.Y
);
1474 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1479 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1483 TP
:= g_Map_PanelByGUID(PGUID
);
1484 if (TP
= nil) then exit
;
1488 NetOut
.Write(Byte(NET_MSG_PTEX
));
1489 NetOut
.Write(LongWord(PGUID
));
1490 NetOut
.Write(FCurTexture
);
1491 NetOut
.Write(FCurFrame
);
1492 NetOut
.Write(FCurFrameCount
);
1493 NetOut
.Write(AnimLoop
);
1496 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1499 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1504 TP
:= g_Map_PanelByGUID(PGUID
);
1505 if (TP
= nil) then exit
;
1507 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1508 NetOut
.Write(LongWord(PGUID
));
1509 NetOut
.Write(Byte(TP
.Enabled
));
1510 NetOut
.Write(TP
.LiftType
);
1513 NetOut
.Write(Word(TP
.Width
));
1514 NetOut
.Write(Word(TP
.Height
));
1516 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1517 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1518 NetOut
.Write(LongInt(TP
.movingStartX
));
1519 NetOut
.Write(LongInt(TP
.movingStartY
));
1520 NetOut
.Write(LongInt(TP
.movingEndX
));
1521 NetOut
.Write(LongInt(TP
.movingEndY
));
1522 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1523 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1524 NetOut
.Write(LongInt(TP
.sizeEndX
));
1525 NetOut
.Write(LongInt(TP
.sizeEndY
));
1526 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1527 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1528 NetOut
.Write(Byte(mpflags
));
1530 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1535 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1537 if gTriggers
= nil then Exit
;
1538 if T
.Sound
= nil then Exit
;
1540 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1541 NetOut
.Write(T
.ClientID
);
1542 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1543 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1544 NetOut
.Write(T
.SoundPlayCount
);
1546 g_Net_Host_Send(ID
, True);
1549 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1551 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1552 NetOut
.Write(gMusic
.Name
);
1553 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1554 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1555 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1557 g_Net_Host_Send(ID
, True);
1562 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1566 M
:= g_Monsters_ByUID(UID
);
1572 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1574 NetOut
.Write(MonsterType
);
1575 NetOut
.Write(MonsterState
);
1576 NetOut
.Write(MonsterAnim
);
1577 NetOut
.Write(MonsterTargetUID
);
1578 NetOut
.Write(MonsterTargetTime
);
1579 NetOut
.Write(MonsterBehaviour
);
1580 NetOut
.Write(MonsterSleep
);
1581 NetOut
.Write(MonsterHealth
);
1582 NetOut
.Write(MonsterAmmo
);
1583 NetOut
.Write(GameX
);
1584 NetOut
.Write(GameY
);
1585 NetOut
.Write(GameVelX
);
1586 NetOut
.Write(GameVelY
);
1587 NetOut
.Write(Byte(GameDirection
));
1590 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1593 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1597 M
:= g_Monsters_ByUID(UID
);
1598 if M
= nil then Exit
;
1600 NetOut
.Write(Byte(NET_MSG_MPOS
));
1605 NetOut
.Write(GameX
);
1606 NetOut
.Write(GameY
);
1607 NetOut
.Write(GameVelX
);
1608 NetOut
.Write(GameVelY
);
1609 NetOut
.Write(Byte(GameDirection
));
1612 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1615 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1619 M
:= g_Monsters_ByUID(UID
);
1620 if M
= nil then Exit
;
1622 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1627 NetOut
.Write(MonsterState
);
1628 NetOut
.Write(ForcedAnim
);
1629 NetOut
.Write(MonsterTargetUID
);
1630 NetOut
.Write(MonsterTargetTime
);
1631 NetOut
.Write(MonsterSleep
);
1632 NetOut
.Write(MonsterHealth
);
1633 NetOut
.Write(MonsterAmmo
);
1634 NetOut
.Write(MonsterPain
);
1635 NetOut
.Write(Byte(AnimIsReverse
));
1636 NetOut
.Write(FFireTime
);
1639 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1642 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1644 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1651 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1654 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1658 M
:= g_Monsters_ByUID(UID
);
1659 if M
= nil then Exit
;
1661 NetOut
.Write(Byte(NET_MSG_MDEL
));
1664 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1669 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1671 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1674 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1677 procedure MH_SEND_VoteEvent(EvType
: Byte;
1678 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1679 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1680 ID
: Integer = NET_EVERYONE
);
1682 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1683 NetOut
.Write(EvType
);
1684 NetOut
.Write(IntArg1
);
1685 NetOut
.Write(IntArg2
);
1686 NetOut
.Write(StrArg1
);
1687 NetOut
.Write(StrArg2
);
1689 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1692 // CLIENT MESSAGES //
1696 procedure MC_RECV_Chat(var M
: TMsg
);
1701 Txt
:= M
.ReadString();
1702 Mode
:= M
.ReadByte();
1704 if Mode
<> NET_CHAT_SYSTEM
then
1706 if NetDeafLevel
= 0 then
1708 if Mode
= NET_CHAT_PLAYER
then
1710 g_Console_Add(Txt
, True);
1711 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1712 g_Game_ChatSound(b_Text_Unformat(Txt
));
1714 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1716 if gPlayer1
.Team
= TEAM_RED
then
1717 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1718 if gPlayer1
.Team
= TEAM_BLUE
then
1719 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1720 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1721 g_Game_ChatSound(b_Text_Unformat(Txt
));
1724 end else if (NetDeafLevel
< 2) then
1725 g_Console_Add(Txt
, True);
1728 procedure MC_RECV_Effect(var M
: TMsg
);
1734 if not gGameOn
then Exit
;
1735 Kind
:= M
.ReadByte();
1736 X
:= M
.ReadLongInt();
1737 Y
:= M
.ReadLongInt();
1738 Ang
:= M
.ReadSmallInt();
1744 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1750 g_GFX_QueueEffect(R_GFX_TELEPORT_FAST
, X
, Y
);
1753 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1758 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, X
- 64, Y
- 64);
1761 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1766 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, X
- 64, Y
- 64);
1769 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1774 g_GFX_QueueEffect(R_GFX_BFG_HIT
, X
- 32, Y
- 32);
1780 g_GFX_QueueEffect(R_GFX_FIRE
, X
, Y
);
1783 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1788 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
, Y
);
1791 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1795 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1799 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1803 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1804 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1809 procedure MC_RECV_Sound(var M
: TMsg
);
1815 Name
:= M
.ReadString();
1816 Pos
:= M
.ReadByte() <> 0;
1819 X
:= M
.ReadLongInt();
1820 Y
:= M
.ReadLongInt();
1821 g_Sound_PlayExAt(Name
, X
, Y
);
1824 g_Sound_PlayEx(Name
);
1827 procedure MC_RECV_CreateShot(var M
: TMsg
);
1829 I
, X
, Y
, XV
, YV
: Integer;
1831 Target
, Spawner
: Word;
1834 I
:= M
.ReadLongInt();
1835 ShType
:= M
.ReadByte();
1836 Target
:= M
.ReadWord();
1837 Spawner
:= M
.ReadWord();
1838 Timeout
:= M
.ReadLongWord();
1839 X
:= M
.ReadLongInt();
1840 Y
:= M
.ReadLongInt();
1841 XV
:= M
.ReadLongInt();
1842 YV
:= M
.ReadLongInt();
1844 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1845 if (Shots
<> nil) and (I
<= High(Shots
)) then
1847 Shots
[I
].Timeout
:= Timeout
;
1848 //Shots[I].Target := Target; // TODO: find a use for Target later
1852 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1854 I
, TX
, TY
, TXV
, TYV
: Integer;
1856 I
:= M
.ReadLongInt();
1857 TX
:= M
.ReadLongInt();
1858 TY
:= M
.ReadLongInt();
1859 TXV
:= M
.ReadLongInt();
1860 TYV
:= M
.ReadLongInt();
1862 if (Shots
<> nil) and (I
<= High(Shots
)) then
1872 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1877 if not gGameOn
then Exit
;
1878 I
:= M
.ReadLongInt();
1879 L
:= (M
.ReadByte() <> 0);
1880 X
:= M
.ReadLongInt();
1881 Y
:= M
.ReadLongInt();
1883 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1886 procedure MC_RECV_GameStats(var M
: TMsg
);
1888 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1890 gTeamStat
[TEAM_RED
].Score
:= M
.ReadSmallInt();
1891 gTeamStat
[TEAM_BLUE
].Score
:= M
.ReadSmallInt();
1894 if gGameSettings
.GameMode
= GM_COOP
then
1896 gCoopMonstersKilled
:= M
.ReadWord();
1897 gCoopSecretsFound
:= M
.ReadWord();
1901 procedure MC_RECV_CoopStats(var M
: TMsg
);
1903 gTotalMonsters
:= M
.ReadLongInt();
1904 gSecretsCount
:= M
.ReadLongInt();
1905 gCoopTotalMonstersKilled
:= M
.ReadWord();
1906 gCoopTotalSecretsFound
:= M
.ReadWord();
1907 gCoopTotalMonsters
:= M
.ReadWord();
1908 gCoopTotalSecrets
:= M
.ReadWord();
1911 procedure MC_RECV_GameEvent(var M
: TMsg
);
1920 i1
, i2
: TStrings_Locale
;
1923 goodCmd
: Boolean = true;
1925 FillChar(EvHash
, Sizeof(EvHash
), 0);
1926 EvType
:= M
.ReadByte();
1927 EvNum
:= M
.ReadLongInt();
1928 EvStr
:= M
.ReadString();
1929 gLastMap
:= M
.ReadByte() <> 0;
1930 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1931 gStatsPressed
:= True;
1932 EvTime
:= M
.ReadLongWord();
1933 BHash
:= M
.ReadByte() <> 0;
1935 EvHash
:= M
.ReadMD5();
1939 if (g_Res_received_map_start
<> 0) then
1941 if (g_Res_received_map_start
< 0) then exit
;
1944 NET_EV_MAPSTART
: goodCmd
:= true;
1945 NET_EV_MAPEND
: goodCmd
:= true;
1946 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1947 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1948 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1950 if not goodCmd
then exit
;
1956 if (g_Res_received_map_start
<> 0) then
1958 g_Res_received_map_start
:= -1;
1963 g_Game_ClearLoading();
1964 g_Game_StopAllSounds(True);
1966 gSwitchGameMode
:= Byte(EvNum
);
1967 gGameSettings
.GameMode
:= gSwitchGameMode
;
1970 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1972 if not isWadPath(EvStr
) then
1973 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1975 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1979 MC_SEND_FullStateRequest
;
1985 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1986 gLMSRespawnTime
:= 0;
1987 if (g_Res_received_map_start
<> 0) then
1989 g_Res_received_map_start
:= -1;
1993 gMissionFailed
:= EvNum
<> 0;
1994 gExit
:= EXIT_ENDLEVELCUSTOM
;
2002 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
2004 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
2006 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
2012 if NetDeafLevel
< 2 then
2014 if EvNum
= TEAM_RED
then
2015 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
2016 if EvNum
= TEAM_BLUE
then
2017 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
2023 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
2024 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2029 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
2030 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2037 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
2038 gLMSRespawnTime
:= gTime
+ EvNum
;
2039 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2041 else if gPlayer1
= nil then
2043 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2047 NET_EV_LMS_SURVIVOR
:
2048 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2051 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2055 pl
:= g_Player_Get(EvNum
and $FFFF);
2060 cnt
:= (EvNum
shr 16) and $FF;
2061 if Pos('w', EvStr
) = 0 then
2064 if Pos('t', EvStr
) = 0 then
2067 if Pos('-', EvStr
) = 0 then
2069 if Pos('e', EvStr
) = 0 then
2070 i1
:= I_PLAYER_SCORE_ADD_OWN
2072 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2075 if Pos('e', EvStr
) = 0 then
2076 i1
:= I_PLAYER_SCORE_SUB_OWN
2078 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2081 if Pos('r', EvStr
) > 0 then
2082 i2
:= I_PLAYER_SCORE_TO_RED
2084 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2085 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2089 if Pos('-', EvStr
) = 0 then
2090 i1
:= I_PLAYER_SCORE_ADD_TEAM
2092 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2094 if Pos('r', EvStr
) > 0 then
2095 i2
:= I_PLAYER_SCORE_RED
2097 i2
:= I_PLAYER_SCORE_BLUE
;
2098 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2103 if Pos('e', EvStr
) = 0 then
2104 i1
:= I_PLAYER_SCORE_WIN_OWN
2106 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
2108 if Pos('r', EvStr
) > 0 then
2109 i2
:= I_PLAYER_SCORE_TO_RED
2111 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2112 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
2118 if EvNum
= TEAM_RED
then
2119 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2120 if EvNum
= TEAM_BLUE
then
2121 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2122 if EvNum
= -TEAM_RED
then
2123 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2124 if EvNum
= -TEAM_BLUE
then
2125 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2130 g_Player_RemoveAllCorpses
;
2131 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2132 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2136 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2140 if EvNum
= TEAM_RED
then
2141 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2142 if EvNum
= TEAM_BLUE
then
2143 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2147 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2150 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2153 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2156 g_Game_Announce_KillCombo(EvNum
);
2158 NET_EV_PLAYER_TOUCH
:
2160 pl
:= g_Player_Get(EvNum
);
2167 pl
:= g_Player_Get(EvNum
);
2170 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2171 g_Sound_PlayEx('SOUND_GAME_SECRET');
2177 pl
:= g_Player_Get(EvNum
);
2178 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2183 procedure MC_RECV_FlagPos(var M
: TMsg
);
2188 if Fl
= FLAG_NONE
then Exit
;
2189 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2190 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2191 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2192 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2195 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2204 EvType
:= M
.ReadByte();
2207 if Fl
= FLAG_NONE
then Exit
;
2209 Quiet
:= (M
.ReadByte() <> 0);
2210 PID
:= M
.ReadWord();
2212 gFlags
[Fl
].State
:= M
.ReadByte();
2213 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2214 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2215 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2216 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2217 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2218 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2220 Pl
:= g_Player_Get(PID
);
2222 (EvType
<> FLAG_STATE_NORMAL
) and
2223 (EvType
<> FLAG_STATE_DROPPED
) and
2224 (EvType
<> FLAG_STATE_RETURNED
) then
2230 if Quiet
or (Pl
= nil) then Exit
;
2232 if Fl
= FLAG_RED
then
2233 s
:= _lc
[I_PLAYER_FLAG_RED
]
2235 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2237 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2239 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2240 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2241 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2246 if not sound_ret_flag
[a
].IsPlaying() then
2247 sound_ret_flag
[a
].Play();
2250 FLAG_STATE_CAPTURED
:
2252 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2256 if Fl
= FLAG_RED
then
2257 s
:= _lc
[I_PLAYER_FLAG_RED
]
2259 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2261 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2262 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2264 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2265 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2266 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2271 if not sound_get_flag
[a
].IsPlaying() then
2272 sound_get_flag
[a
].Play();
2277 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2279 if Quiet
or (Pl
= nil) then Exit
;
2281 if Fl
= FLAG_RED
then
2282 s
:= _lc
[I_PLAYER_FLAG_RED
]
2284 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2286 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2287 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2289 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2290 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2291 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2296 if not sound_lost_flag
[a
].IsPlaying() then
2297 sound_lost_flag
[a
].Play();
2302 g_Map_ResetFlag(FLAG_RED
);
2303 g_Map_ResetFlag(FLAG_BLUE
);
2304 if Quiet
or (Pl
= nil) then Exit
;
2305 Pl
.SetFlag(FLAG_NONE
);
2307 if Fl
= FLAG_RED
then
2308 s
:= _lc
[I_PLAYER_FLAG_RED
]
2310 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2312 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2313 Insert('.', ts
, Length(ts
) + 1 - 3);
2314 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2315 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2317 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2318 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2319 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2324 if not sound_cap_flag
[a
].IsPlaying() then
2325 sound_cap_flag
[a
].Play();
2328 FLAG_STATE_RETURNED
:
2330 g_Map_ResetFlag(Fl
);
2333 if Fl
= FLAG_RED
then
2334 s
:= _lc
[I_PLAYER_FLAG_RED
]
2336 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2338 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2340 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2341 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2342 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2347 if not sound_ret_flag
[a
].IsPlaying() then
2348 sound_ret_flag
[a
].Play();
2353 procedure MC_RECV_GameSettings(var M
: TMsg
);
2355 gGameSettings
.GameMode
:= M
.ReadByte();
2356 gGameSettings
.ScoreLimit
:= M
.ReadWord();
2357 gGameSettings
.TimeLimit
:= M
.ReadWord();
2358 gGameSettings
.MaxLives
:= M
.ReadByte();
2359 gGameSettings
.Options
:= M
.ReadLongWord();
2364 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2367 PName
, Model
: string;
2372 PID
:= M
.ReadWord();
2373 Pl
:= g_Player_Get(PID
);
2375 PName
:= M
.ReadString();
2376 Model
:= M
.ReadString();
2377 Color
.R
:= M
.ReadByte();
2378 Color
.G
:= M
.ReadByte();
2379 Color
.B
:= M
.ReadByte();
2383 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2385 if (Pl
<> nil) then Exit
;
2386 if (g_Force_Model_Get() <> 0) then
2387 Model
:= g_Forced_Model_GetName();
2388 DID
:= g_Player_Create(Model
, Color
, T
, False);
2389 with g_Player_Get(DID
) do
2398 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2399 gPlayer1
.UID
:= PID
;
2400 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2401 gPlayer1
.ChangeTeam(T
);
2403 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2404 gPlayer2
.UID
:= PID
;
2405 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2406 gPlayer2
.ChangeTeam(T
);
2410 if NetDeafLevel
< 3 then
2411 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2412 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2416 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2423 TmpX
, TmpY
: Integer;
2427 GT
:= M
.ReadLongWord();
2428 if GT
< gTime
- NET_MAX_DIFFTIME
then
2435 PID
:= M
.ReadWord();
2436 Pl
:= g_Player_Get(PID
);
2438 if Pl
= nil then Exit
;
2444 FPing
:= M
.ReadWord();
2445 FLoss
:= M
.ReadByte();
2446 kByte
:= M
.ReadWord();
2447 Dir
:= M
.ReadByte();
2449 TmpX
:= M
.ReadLongInt();
2450 TmpY
:= M
.ReadLongInt();
2454 if LongBool(kByte
and NET_KEY_CHAT
) then
2455 PressKey(KEY_CHAT
, 10000)
2458 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2459 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2460 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2461 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2462 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2465 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2467 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2468 SetDirection(TDirection(Dir
));
2470 GameVelX
:= M
.ReadLongInt();
2471 GameVelY
:= M
.ReadLongInt();
2472 GameAccelX
:= M
.ReadLongInt();
2473 GameAccelY
:= M
.ReadLongInt();
2474 SetLerp(TmpX
, TmpY
);
2475 if NetForcePlayerUpdate
then Update();
2479 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2483 I
, OldFire
: Integer;
2484 OldJet
, Flam
: Boolean;
2487 PID
:= M
.ReadWord();
2488 Pl
:= g_Player_Get(PID
);
2495 alive
:= (M
.ReadByte() <> 0);
2496 GodMode
:= (M
.ReadByte() <> 0);
2497 Health
:= M
.ReadLongInt();
2498 Armor
:= M
.ReadLongInt();
2499 Air
:= M
.ReadLongInt();
2500 JetFuel
:= M
.ReadLongInt();
2501 Lives
:= M
.ReadByte();
2502 NewTeam
:= M
.ReadByte();
2504 for I
:= WP_FIRST
to WP_LAST
do
2505 FWeapon
[I
] := (M
.ReadByte() <> 0);
2507 for I
:= A_BULLETS
to A_HIGH
do
2508 FAmmo
[I
] := M
.ReadWord();
2510 for I
:= A_BULLETS
to A_HIGH
do
2511 FMaxAmmo
[I
] := M
.ReadWord();
2513 for I
:= MR_SUIT
to MR_MAX
do
2514 FMegaRulez
[I
] := M
.ReadLongWord();
2517 if (M
.ReadByte() <> 0) then
2518 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2519 if (M
.ReadByte() <> 0) then
2520 FRulez
:= FRulez
+ [R_KEY_RED
];
2521 if (M
.ReadByte() <> 0) then
2522 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2523 if (M
.ReadByte() <> 0) then
2524 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2525 if (M
.ReadByte() <> 0) then
2526 FRulez
:= FRulez
+ [R_BERSERK
];
2528 Frags
:= M
.ReadLongInt();
2529 Death
:= M
.ReadLongInt();
2531 SetWeapon(M
.ReadByte());
2533 FSpectator
:= M
.ReadByte() <> 0;
2536 if UID
= NetPlrUID1
then
2538 gSpectLatchPID1
:= UID
;
2541 if UID
= NetPlrUID2
then
2543 gSpectLatchPID2
:= UID
;
2549 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2552 gSpectLatchPID1
:= 0;
2554 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2557 gSpectLatchPID2
:= 0;
2560 FGhost
:= M
.ReadByte() <> 0;
2561 FPhysics
:= M
.ReadByte() <> 0;
2562 FNoRespawn
:= M
.ReadByte() <> 0;
2564 FJetpack
:= M
.ReadByte() <> 0;
2565 OldFire
:= FFireTime
;
2566 FFireTime
:= M
.ReadLongInt();
2567 if (OldFire
<= 0) and (FFireTime
> 0) then
2568 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2569 Flam
:= M
.ReadByte() <> 0;
2570 FSpawnInvul
:= M
.ReadLongInt();
2571 if OldJet
and not FJetpack
then
2573 else if not OldJet
and FJetpack
then
2575 if FFlaming
and not Flam
then
2577 if Team
<> NewTeam
then
2578 Pl
.ChangeTeam(NewTeam
);
2584 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2589 Attacker
, Value
: Word;
2593 if not gGameOn
then Exit
;
2594 PID
:= M
.ReadWord();
2595 Pl
:= g_Player_Get(PID
);
2596 if Pl
= nil then Exit
;
2598 Kind
:= M
.ReadByte();
2599 Attacker
:= M
.ReadWord();
2600 Value
:= M
.ReadWord();
2605 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2610 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2614 KillType
, DeathType
: Byte;
2618 if not gGameOn
then Exit
;
2619 PID
:= M
.ReadWord();
2620 Pl
:= g_Player_Get(PID
);
2621 if Pl
= nil then Exit
;
2623 KillType
:= M
.ReadByte();
2624 DeathType
:= M
.ReadByte();
2625 Attacker
:= M
.ReadWord();
2629 Kill(KillType
, Attacker
, DeathType
);
2634 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2639 PID
:= M
.ReadWord();
2640 Pl
:= g_Player_Get(PID
);
2642 if Pl
= nil then Exit
;
2644 if NetDeafLevel
< 3 then
2645 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2646 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2648 g_Player_Remove(PID
);
2653 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2658 X
, Y
, AX
, AY
: Integer;
2662 if not gGameOn
then Exit
;
2663 PID
:= M
.ReadWord();
2664 Pl
:= g_Player_Get(PID
);
2665 if Pl
= nil then Exit
;
2667 Weap
:= M
.ReadByte();
2668 X
:= M
.ReadLongInt();
2669 Y
:= M
.ReadLongInt();
2670 AX
:= M
.ReadLongInt();
2671 AY
:= M
.ReadLongInt();
2672 SHID
:= M
.ReadLongInt();
2675 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2678 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2688 PID
:= M
.ReadWord();
2689 Pl
:= g_Player_Get(PID
);
2690 if Pl
= nil then Exit
;
2692 TmpName
:= M
.ReadString();
2693 TmpModel
:= M
.ReadString();
2694 TmpColor
.R
:= M
.ReadByte();
2695 TmpColor
.G
:= M
.ReadByte();
2696 TmpColor
.B
:= M
.ReadByte();
2697 TmpTeam
:= M
.ReadByte();
2699 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2701 Pl
.ChangeTeam(TmpTeam
);
2702 if gPlayer1
= Pl
then
2703 gPlayer1Settings
.Team
:= TmpTeam
;
2704 if gPlayer2
= Pl
then
2705 gPlayer2Settings
.Team
:= TmpTeam
;
2707 Pl
.SetColor(TmpColor
);
2709 if Pl
.Name
<> TmpName
then
2711 if NetDeafLevel
< 3 then
2712 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2716 if (g_Force_Model_Get() <> 0) then
2717 TmpModel
:= g_Forced_Model_GetName();
2718 if TmpModel
<> Pl
.Model
.GetName() then
2719 Pl
.SetModel(TmpModel
);
2724 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2727 X
, Y
, VX
, VY
: Integer;
2729 Quiet
, Fall
{, Resp}: Boolean;
2732 if not gGameOn
then Exit
;
2734 Quiet
:= M
.ReadByte() <> 0;
2736 Fall
:= M
.ReadByte() <> 0;
2737 {Resp :=} M
.ReadByte();
2738 X
:= M
.ReadLongInt();
2739 Y
:= M
.ReadLongInt();
2740 VX
:= M
.ReadLongInt();
2741 VY
:= M
.ReadLongInt();
2743 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2744 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2746 it
:= g_Items_ByIdx(ID
);
2752 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2754 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16);
2759 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2764 if not gGameOn
then Exit
;
2766 Quiet
:= M
.ReadByte() <> 0;
2768 if not g_Items_ValidId(ID
) then exit
;
2770 if not Quiet
then g_Items_EmitPickupSound(ID
);
2775 procedure MC_RECV_ItemPos(var M
: TMsg
);
2778 X
, Y
, VX
, VY
: Integer;
2781 if not gGameOn
then Exit
;
2784 X
:= M
.ReadLongInt();
2785 Y
:= M
.ReadLongInt();
2786 VX
:= M
.ReadLongInt();
2787 VY
:= M
.ReadLongInt();
2789 if g_Items_ValidId(ID
) then
2791 it
:= g_Items_ByIdx(ID
);
2796 it
.positionChanged();
2802 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2809 if not gGameOn
then Exit
;
2811 PGUID
:= Integer(M
.ReadLongWord());
2812 Tex
:= M
.ReadLongInt();
2813 Fr
:= M
.ReadLongInt();
2814 Cnt
:= M
.ReadByte();
2815 Loop
:= M
.ReadByte();
2817 TP
:= g_Map_PanelByGUID(PGUID
);
2821 TP
.SetTexture(Tex
, Loop
);
2822 TP
.SetFrame(Fr
, Cnt
);
2826 procedure MC_RECV_PanelState(var M
: TMsg
);
2831 X
, Y
, W
, H
: Integer;
2833 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2834 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2837 if not gGameOn
then Exit
;
2839 PGUID
:= Integer(M
.ReadLongWord());
2840 E
:= (M
.ReadByte() <> 0);
2841 Lift
:= M
.ReadByte();
2842 X
:= M
.ReadLongInt();
2843 Y
:= M
.ReadLongInt();
2847 speedX
:= M
.ReadLongInt();
2848 speedY
:= M
.ReadLongInt();
2849 startX
:= M
.ReadLongInt();
2850 startY
:= M
.ReadLongInt();
2851 endX
:= M
.ReadLongInt();
2852 endY
:= M
.ReadLongInt();
2853 sizeSpX
:= M
.ReadLongInt();
2854 sizeSpY
:= M
.ReadLongInt();
2855 sizeEX
:= M
.ReadLongInt();
2856 sizeEY
:= M
.ReadLongInt();
2857 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2859 TP
:= g_Map_PanelByGUID(PGUID
);
2860 if (TP
= nil) then exit
;
2862 // update lifts state
2863 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2865 // update enabled/disabled state for all panels
2866 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2868 // update panel position, as it can be moved (mplat)
2873 // update mplat state
2874 TP
.movingSpeedX
:= speedX
;
2875 TP
.movingSpeedY
:= speedY
;
2876 TP
.movingStartX
:= startX
;
2877 TP
.movingStartY
:= startY
;
2878 TP
.movingEndX
:= endX
;
2879 TP
.movingEndY
:= endY
;
2880 TP
.sizeSpeedX
:= sizeSpX
;
2881 TP
.sizeSpeedY
:= sizeSpY
;
2882 TP
.sizeEndX
:= sizeEX
;
2883 TP
.sizeEndY
:= sizeEY
;
2884 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2885 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2886 // notify panel of it's position/size change, so it can fix other internal structures
2887 TP
.positionChanged();
2892 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2895 SPos
, SID
: LongWord;
2899 if not gGameOn
then Exit
;
2900 if gTriggers
= nil then Exit
;
2902 SID
:= M
.ReadLongWord();
2903 SPlaying
:= M
.ReadByte() <> 0;
2904 SPos
:= M
.ReadLongWord();
2905 SCount
:= M
.ReadLongInt();
2907 for I
:= Low(gTriggers
) to High(gTriggers
) do
2908 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2909 if gTriggers
[I
].ClientID
= SID
then
2910 with gTriggers
[I
] do
2912 if Sound
<> nil then
2917 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2919 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2920 Sound
.SetPosition(SPos
);
2923 if Sound
.IsPlaying
then Sound
.Stop
;
2926 SoundPlayCount
:= SCount
;
2930 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2937 if not gGameOn
then Exit
;
2939 MName
:= M
.ReadString();
2940 MPlaying
:= M
.ReadByte() <> 0;
2941 MPos
:= M
.ReadLongWord();
2942 MPaused
:= M
.ReadByte() <> 0;
2943 MPos
:= MPos
+1; //k8: stfu, fpc!
2947 gMusic
.SetByName(MName
);
2949 // gMusic.SetPosition(MPos);
2950 gMusic
.SpecPause
:= MPaused
;
2953 if gMusic
.IsPlaying
then gMusic
.Stop
;
2958 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2961 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2962 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2967 Mon
:= g_Monsters_ByUID(ID
);
2971 MType
:= M
.ReadByte();
2972 MState
:= M
.ReadByte();
2973 MAnim
:= M
.ReadByte();
2974 MTarg
:= M
.ReadWord();
2975 MTargTime
:= M
.ReadLongInt();
2976 MBehav
:= M
.ReadByte();
2977 MSleep
:= M
.ReadLongInt();
2978 MHealth
:= M
.ReadLongInt();
2979 MAmmo
:= M
.ReadLongInt();
2981 X
:= M
.ReadLongInt();
2982 Y
:= M
.ReadLongInt();
2983 VX
:= M
.ReadLongInt();
2984 VY
:= M
.ReadLongInt();
2985 MDir
:= M
.ReadByte();
2987 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2988 Mon
:= g_Monsters_ByUID(ID
);
2995 MonsterAnim
:= MAnim
;
2996 MonsterTargetUID
:= MTarg
;
2997 MonsterTargetTime
:= MTargTime
;
2998 MonsterBehaviour
:= MBehav
;
2999 MonsterSleep
:= MSleep
;
3000 MonsterAmmo
:= MAmmo
;
3005 setPosition(X
, Y
); // this will call positionChanged();
3011 procedure MC_RECV_MonsterPos(var M
: TMsg
);
3018 Mon
:= g_Monsters_ByUID(ID
);
3024 X
:= M
.ReadLongInt();
3025 Y
:= M
.ReadLongInt();
3026 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
3027 GameVelX
:= M
.ReadLongInt();
3028 GameVelY
:= M
.ReadLongInt();
3029 GameDirection
:= TDirection(M
.ReadByte());
3033 procedure MC_RECV_MonsterState(var M
: TMsg
);
3035 ID
, OldFire
: Integer;
3036 MState
, MFAnm
: Byte;
3038 AnimRevert
: Boolean;
3041 Mon
:= g_Monsters_ByUID(ID
);
3042 if Mon
= nil then Exit
;
3044 MState
:= M
.ReadByte();
3045 MFAnm
:= M
.ReadByte();
3049 MonsterTargetUID
:= M
.ReadWord();
3050 MonsterTargetTime
:= M
.ReadLongInt();
3051 MonsterSleep
:= M
.ReadLongInt();
3052 MonsterHealth
:= M
.ReadLongInt();
3053 MonsterAmmo
:= M
.ReadLongInt();
3054 MonsterPain
:= M
.ReadLongInt();
3055 AnimRevert
:= M
.ReadByte() <> 0;
3056 OldFire
:= FFireTime
;
3057 FFireTime
:= M
.ReadLongInt();
3058 if (OldFire
<= 0) and (FFireTime
> 0) then
3059 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3060 RevertAnim(AnimRevert
);
3062 if MonsterState
<> MState
then
3064 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3065 if (MState
= MONSTATE_DIE
) then DieSound();
3066 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3067 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3068 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3070 SetState(MState
, MFAnm
);
3075 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3079 X
, Y
, VX
, VY
: Integer;
3083 Mon
:= g_Monsters_ByUID(ID
);
3084 if Mon
= nil then Exit
;
3086 X
:= M
.ReadLongInt();
3087 Y
:= M
.ReadLongInt();
3088 VX
:= M
.ReadLongInt();
3089 VY
:= M
.ReadLongInt();
3091 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3094 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3100 Mon
:= g_Monsters_ByUID(ID
);
3101 if Mon
= nil then Exit
;
3103 Mon
.MonsterRemoved
:= True;
3106 procedure MC_RECV_TimeSync(var M
: TMsg
);
3110 Time
:= M
.ReadLongWord();
3112 if gState
= STATE_INTERCUSTOM
then
3113 gServInterTime
:= Min(Time
, 255);
3116 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3120 Int1
, Int2
: SmallInt;
3122 EvID
:= M
.ReadByte();
3123 Int1
:= M
.ReadSmallInt();
3124 Int2
:= M
.ReadSmallInt();
3125 Str1
:= M
.ReadString();
3126 Str2
:= M
.ReadString();
3128 if NetDeafLevel
< 2 then
3131 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3133 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3135 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3137 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3139 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3145 procedure MC_SEND_Info(Password
: string);
3150 NetOut
.Write(Byte(NET_MSG_INFO
));
3151 NetOut
.Write(GAME_VERSION
);
3152 NetOut
.Write(Password
);
3153 NetOut
.Write(gPlayer1Settings
.Name
);
3154 NetOut
.Write(gPlayer1Settings
.Model
);
3155 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3156 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3157 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3158 NetOut
.Write(gPlayer1Settings
.Team
);
3159 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3160 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3161 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3162 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3163 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3165 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3168 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3170 NetOut
.Write(Byte(NET_MSG_CHAT
));
3174 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3177 procedure MC_SEND_PlayerPos();
3182 WeaponAct
: Byte = 0;
3183 WeaponSelect
: Word = 0;
3186 if not gGameOn
then Exit
;
3187 if gPlayers
= nil then Exit
;
3188 if gPlayer1
= nil then Exit
;
3191 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3193 {$IFDEF DISABLE_MENU}
3194 if (not gConsoleShow
) and (not gChatShow
) then
3196 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3199 strafeDir
:= P1MoveButton
shr 4;
3200 P1MoveButton
:= P1MoveButton
and $0F;
3202 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3204 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3206 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3210 if gPlayerAction
[0, ACTION_STRAFE
] then
3212 // new strafe mechanics
3213 if (strafeDir
= 0) then
3214 strafeDir
:= P1MoveButton
; // start strafing
3215 // now set direction according to strafe (reversed)
3216 if (strafeDir
= 2) then
3217 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3218 else if (strafeDir
= 1) then
3219 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3223 strafeDir
:= 0; // not strafing anymore
3224 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3225 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3226 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3227 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3228 else if P1MoveButton
<> 0 then
3229 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3232 gPlayer1
.ReleaseKeys
;
3233 if P1MoveButton
= 1 then
3235 kByte
:= kByte
or NET_KEY_LEFT
;
3236 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3238 if P1MoveButton
= 2 then
3240 kByte
:= kByte
or NET_KEY_RIGHT
;
3241 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3243 if gPlayerAction
[0, ACTION_LOOKUP
] then
3245 kByte
:= kByte
or NET_KEY_UP
;
3246 gPlayer1
.PressKey(KEY_UP
, 10000);
3248 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3250 kByte
:= kByte
or NET_KEY_DOWN
;
3251 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3253 if gPlayerAction
[0, ACTION_JUMP
] then
3255 kByte
:= kByte
or NET_KEY_JUMP
;
3256 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3258 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3259 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3261 for i
:= WP_FACT
to WP_LACT
do
3263 if gWeaponAction
[0, i
] then
3265 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3266 gWeaponAction
[0, i
] := False
3270 for i
:= WP_FIRST
to WP_LAST
do
3272 if gSelectWeapon
[0, i
] then
3274 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3275 gSelectWeapon
[0, i
] := False
3279 // fix movebutton state
3280 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3283 kByte
:= NET_KEY_CHAT
;
3285 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3286 NetOut
.Write(gTime
);
3287 NetOut
.Write(kByte
);
3288 NetOut
.Write(Byte(gPlayer1
.Direction
));
3289 NetOut
.Write(WeaponAct
);
3290 NetOut
.Write(WeaponSelect
);
3291 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3292 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3294 //kBytePrev := kByte;
3295 //kDirPrev := gPlayer1.Direction;
3298 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3300 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3301 NetOut
.Write(Byte(Start
));
3302 NetOut
.Write(Command
);
3303 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3306 procedure MC_SEND_PlayerSettings();
3309 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3310 NetOut
.Write(gPlayer1Settings
.Name
);
3311 NetOut
.Write(gPlayer1Settings
.Model
);
3312 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3313 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3314 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3315 NetOut
.Write(gPlayer1Settings
.Team
);
3316 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3317 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3318 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3319 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3320 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3322 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3325 procedure MC_SEND_FullStateRequest();
3327 NetOut
.Write(Byte(NET_MSG_REQFST
));
3329 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3332 procedure MC_SEND_CheatRequest(Kind
: Byte);
3334 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3337 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3339 procedure MC_SEND_RCONPassword(Password
: string);
3341 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3342 NetOut
.Write(Password
);
3344 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3346 procedure MC_SEND_RCONCommand(Cmd
: string);
3348 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3351 g_Net_Client_Send(True, NET_CHAN_SERVICE
);