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;
290 Math
, ENet
, e_input
, e_log
, g_base
, g_basic
,
291 g_textures
, g_gfx
, g_sound
, g_console
, g_options
,
292 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
,
293 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
296 NET_KEY_LEFT
= 1 shl 0;
297 NET_KEY_RIGHT
= 1 shl 1;
298 NET_KEY_UP
= 1 shl 2;
299 NET_KEY_DOWN
= 1 shl 3;
300 NET_KEY_JUMP
= 1 shl 4;
301 NET_KEY_FIRE
= 1 shl 5;
302 NET_KEY_OPEN
= 1 shl 6;
303 NET_KEY_CHAT
= 1 shl 7;
304 NET_KEY_FORCEDIR
= 1 shl 8;
307 //kBytePrev: Word = 0;
308 //kDirPrev: TDirection = D_LEFT;
309 //HostGameTime: Word = 0;
312 function IsValidFileName(const S
: String): Boolean;
314 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
319 for I
:= 1 to Length(S
) do
320 Result
:= Result
and (not(S
[I
] in Forbidden
));
323 function IsValidFilePath(const S
: String): Boolean;
328 if not IsValidFileName(S
) then exit
;
329 if FileExists(S
) then exit
;
330 I
:= LastDelimiter('\/', S
);
332 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
343 procedure MH_MalformedPacket(C
: pTNetClient
);
345 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
346 _lc
[I_NET_DISC_PROTOCOL
]);
347 g_Net_Host_Kick(C
^.ID
, NET_DISC_PROTOCOL
);
350 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
359 Pl
:= g_Player_Get(PID
);
363 Txt
:= M
.ReadString();
364 Mode
:= M
.ReadByte();
369 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
371 if (Mode
= NET_CHAT_SYSTEM
) then
372 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
373 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
374 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
377 MH_SEND_Chat(Txt
, Mode
)
379 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
382 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
384 Ver
, PName
, Model
, Pw
: string;
387 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
397 Ver
:= M
.ReadString();
398 Pw
:= M
.ReadString();
399 PName
:= M
.ReadString();
400 Model
:= M
.ReadString();
405 WeapSwitch
:= M
.ReadByte();
406 for I
:= WP_FIRST
to WP_LAST
+ 1 do
407 TmpPrefArray
[I
] := M
.ReadByte();
408 SwitchEmpty
:= M
.ReadByte();
409 SkipF
:= M
.ReadByte();
414 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
416 if Ver
<> GAME_VERSION
then
418 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
419 _lc
[I_NET_DISC_VERSION
]);
420 g_Net_Host_Kick(C
^.ID
, NET_DISC_VERSION
);
424 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
426 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
428 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
429 _lc
[I_NET_DISC_BAN
]);
430 g_Net_Host_Kick(C
^.ID
, NET_DISC_BAN
);
434 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
435 _lc
[I_NET_DISC_BAN
]);
436 g_Net_Host_Kick(C
^.ID
, NET_DISC_TEMPBAN
);
441 if NetPassword
<> '' then
442 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
444 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
445 _lc
[I_NET_DISC_PASSWORD
]);
446 g_Net_Host_Kick(C
^.ID
, NET_DISC_PASSWORD
);
450 if (C
^.Player
<> 0) then
452 // already received info
453 g_Net_Penalize(C
, 'client info spam');
461 PID
:= g_Player_Create(Model
, Color
, T
, False);
462 with g_Player_Get(PID
) do
465 WeapSwitchMode
:= WeapSwitch
;
466 SetWeaponPrefs(TmpPrefArray
);
467 SwitchToEmpty
:= SwitchEmpty
;
469 if (g_Force_Model_Get() <> 0) then
470 SetModel(g_Forced_Model_GetName());
475 C
^.WaitForFirstSpawn
:= false;
478 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
479 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
480 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
484 with g_Player_Get(PID
) do
488 // round in progress, don't spawn
489 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
490 //e_LogWritefln('spawning player with pid #%u...', [PID]);
491 //Respawn(gGameSettings.GameType = GT_SINGLE);
492 //k8: no, do not spawn a player yet, wait for "request full state" packet
496 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
497 // that is, if we'll set it to `true`, the player can be spawned after
498 // warmup time ran out, for example, regardless of the real player state.
499 // also, this seems to work only for the initial connection. further
500 // map changes could initiate resource downloading, but the player will
501 // be spawned immediately.
502 // the proper solution will require another player state, "ephemeral".
503 // the player should start any map in "ephemeral" state, and turned into
504 // real mobj only when they sent a special "i am ready" packet. this packet
505 // must be sent after receiving the full state, so the player will get a full
506 // map view before going into game.
507 FWantsInGame
:= false;
508 C
^.WaitForFirstSpawn
:= true;
511 //if not C^.WaitForFirstSpawn then
513 for I
:= Low(NetClients
) to High(NetClients
) do
515 if NetClients
[I
].ID
= C
^.ID
then Continue
;
516 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
517 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
518 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
522 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
523 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
527 //g_Net_Slist_Update;
533 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
537 if not C
.WaitForFirstSpawn
then exit
;
538 plr
:= g_Player_Get(C
^.Player
);
539 if not assigned(plr
) then exit
;
540 g_Net_Slist_ServerPlayerComes();
541 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
542 C
.WaitForFirstSpawn
:= false;
543 plr
.FNoRespawn
:= false;
544 plr
.FWantsInGame
:= true; // TODO: look into this later
546 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
549 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
554 if gLMSRespawn
> LMS_RESPAWN_NONE
then
555 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
560 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
562 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
564 if C
^.FullUpdateSent
then
566 // FullStateRequest spam?
567 g_Net_Penalize(C
, 'duplicate full state request');
573 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
577 C
^.RequestedFullUpdate
:= True;
583 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
596 if not gGameOn
then Exit
;
599 GT
:= M
.ReadLongWord();
604 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
607 Pl
:= g_Player_Get(PID
);
611 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
617 kByte
:= M
.ReadWord();
619 WeaponAct
:= M
.ReadByte();
620 WeaponSelect
:= M
.ReadWord();
625 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
627 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
628 if Direction
<> TDirection(Dir
) then
629 JustTeleported
:= False;
631 SetDirection(TDirection(Dir
));
634 if kByte
= NET_KEY_CHAT
then
636 PressKey(KEY_CHAT
, 10000);
640 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
641 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
642 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
643 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
644 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
645 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
646 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
650 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
652 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
653 ProcessWeaponAction(i
);
659 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
661 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
662 QueueWeaponSwitch(i
);
667 // MH_SEND_PlayerPos(False, PID, C^.ID);
670 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
677 Pl
:= g_Player_Get(C
^.Player
);
678 if Pl
= nil then Exit
;
681 CheatKind
:= M
.ReadByte();
686 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
690 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
693 if Pl
.FSpectator
then
695 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
698 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
705 if gState
<> STATE_INTERCUSTOM
then Exit
;
706 Pl
.FReady
:= not Pl
.FReady
;
709 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
710 Inc(gInterReadyCount
);
714 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
715 Dec(gInterReadyCount
);
723 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
730 TmpPrefArray
: Array [WP_FIRST
.. WP_LAST
+ 1] of Byte;
739 TmpName
:= M
.ReadString();
740 TmpModel
:= M
.ReadString();
741 TmpColor
.R
:= M
.ReadByte();
742 TmpColor
.G
:= M
.ReadByte();
743 TmpColor
.B
:= M
.ReadByte();
744 TmpTeam
:= M
.ReadByte();
745 TmpWeapSwitch
:= M
.ReadByte();
746 for I
:= WP_FIRST
to WP_LAST
+ 1 do
747 TmpPrefArray
[I
] := M
.ReadByte();
748 TmpSwEmpty
:= M
.ReadByte();
749 TmpSkipF
:= M
.ReadByte();
754 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
756 Pl
:= g_Player_Get(C
^.Player
);
757 if Pl
= nil then Exit
;
759 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
762 Pl
.SetColor(TmpColor
);
764 if Pl
.Name
<> TmpName
then
766 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
770 if (g_Force_Model_Get() <> 0) then
771 TmpModel
:= g_Forced_Model_GetName();
772 if TmpModel
<> Pl
.Model
.GetName() then
773 Pl
.SetModel(TmpModel
);
775 if (TmpWeapSwitch
<> Pl
.WeapSwitchMode
) then
776 Pl
.WeapSwitchMode
:= TmpWeapSwitch
;
778 Pl
.SetWeaponPrefs(TmpPrefArray
);
779 if (TmpSwEmpty
<> Pl
.SwitchToEmpty
) then
780 Pl
.SwitchToEmpty
:= TmpSwEmpty
;
782 if (TmpSkipF
<> Pl
.SkipFist
) then
783 Pl
.SkipFist
:= TmpSkipF
;
785 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
790 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
797 Pwd
:= M
.ReadString();
801 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
802 if not NetAllowRCON
then Exit
;
803 if Pwd
= NetRCONPassword
then
806 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
809 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
812 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
819 Cmd
:= M
.ReadString();
823 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
824 if not NetAllowRCON
then Exit
;
825 if not C
^.RCONAuth
then
827 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
830 g_Console_Process(Cmd
);
835 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
838 Name
, Command
: string;
845 Start
:= M
.ReadByte() <> 0;
846 Command
:= M
.ReadString();
851 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
853 Pl
:= g_Player_Get(C
^.Player
);
854 if Pl
= nil then Exit
;
859 if not g_Console_CommandBlacklisted(Command
) then
860 g_Game_StartVote(Command
, Name
);
862 else if gVoteInProgress
then
864 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
865 Need
:= Floor((NetClientCount
+1)/2.0) + 1
867 Need
:= Floor(NetClientCount
/2.0) + 1;
872 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
873 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
879 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
880 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
888 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
890 function sendItemRespawn (it
: PItem
): Boolean;
892 result
:= false; // don't stop
893 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
896 function sendMonSpawn (mon
: TMonster
): Boolean;
898 result
:= false; // don't stop
899 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
902 function sendPanelState (pan
: TPanel
): Boolean;
904 result
:= false; // don't stop
905 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
906 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
912 if (ID
< 0) or (ID
>= Length(NetClients
)) then
913 exit
; // bogus client, this shouldn't happen
915 NetClients
[ID
].FullUpdateSent
:= True;
917 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
919 MH_ProcessFirstSpawn(@NetClients
[ID
]);
921 if gPlayers
<> nil then
923 for I
:= Low(gPlayers
) to High(gPlayers
) do
925 if gPlayers
[I
] <> nil then
927 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
928 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
929 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
931 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
933 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
939 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
940 g_Mons_ForEach(sendMonSpawn
);
941 g_Map_ForEachPanel(sendPanelState
);
943 if gTriggers
<> nil then
945 for I
:= Low(gTriggers
) to High(gTriggers
) do
947 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
949 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
956 for I
:= Low(Shots
) to High(Shots
) do
958 if Shots
[i
].ShotType
in [6, 7, 8] then
960 MH_SEND_CreateShot(i
, ID
);
965 MH_SEND_TriggerMusic(ID
);
967 MH_SEND_GameStats(ID
);
968 MH_SEND_CoopStats(ID
);
970 if gGameSettings
.GameMode
= GM_CTF
then
972 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
973 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
976 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
981 procedure MH_SEND_Info(ID
: Byte);
985 NetOut
.Write(Byte(NET_MSG_INFO
));
987 NetOut
.Write(NetClients
[ID
].Player
);
988 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
989 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
990 NetOut
.Write(gWADHash
);
991 NetOut
.Write(gGameSettings
.GameMode
);
992 NetOut
.Write(gGameSettings
.ScoreLimit
);
993 NetOut
.Write(gGameSettings
.TimeLimit
);
994 NetOut
.Write(gGameSettings
.MaxLives
);
995 NetOut
.Write(gGameSettings
.Options
);
998 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1001 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
1007 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1008 Mode
:= NET_CHAT_PLAYER
;
1011 if (Mode
= NET_CHAT_TEAM
) then
1013 for i
:= Low(gPlayers
) to High(gPlayers
) do
1014 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
1015 (gPlayers
[i
].Team
= ID
) then
1017 NetOut
.Write(Byte(NET_MSG_CHAT
));
1020 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
1027 NetOut
.Write(Byte(NET_MSG_CHAT
));
1030 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
1033 if Mode
= NET_CHAT_SYSTEM
then
1036 if ID
= NET_EVERYONE
then
1038 if Mode
= NET_CHAT_PLAYER
then
1040 g_Console_Add(Txt
, True);
1041 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1042 g_Game_ChatSound(b_Text_Unformat(Txt
));
1045 if Mode
= NET_CHAT_TEAM
then
1046 if gPlayer1
<> nil then
1048 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
1050 g_Console_Add(#18'[Team] '#2 + Txt
, True);
1051 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1052 g_Game_ChatSound(b_Text_Unformat(Txt
));
1054 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
1056 g_Console_Add(#20'[Team] '#2 + Txt
, True);
1057 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1058 g_Game_ChatSound(b_Text_Unformat(Txt
));
1064 Name
:= g_Net_ClientName_ByID(ID
);
1065 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1066 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1067 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1071 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1073 NetOut
.Write(Byte(NET_MSG_GFX
));
1079 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1082 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1084 NetOut
.Write(Byte(NET_MSG_SND
));
1088 NetOut
.Write(Byte(1));
1093 NetOut
.Write(Byte(0));
1095 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1098 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1100 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1102 NetOut
.Write(Byte(NET_MSG_SHADD
));
1104 NetOut
.Write(Shots
[Proj
].ShotType
);
1105 NetOut
.Write(Shots
[Proj
].Target
);
1106 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1107 NetOut
.Write(Shots
[Proj
].Timeout
);
1108 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1109 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1110 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1111 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1113 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1116 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1118 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1120 NetOut
.Write(Byte(NET_MSG_SHPOS
));
1122 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1123 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1124 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1125 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1127 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
1130 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1132 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1134 NetOut
.Write(Byte(Loud
));
1138 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1141 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1143 NetOut
.Write(Byte(NET_MSG_SCORE
));
1144 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1146 NetOut
.Write(gTeamStat
[TEAM_RED
].Score
);
1147 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Score
);
1150 if gGameSettings
.GameMode
= GM_COOP
then
1152 NetOut
.Write(gCoopMonstersKilled
);
1153 NetOut
.Write(gCoopSecretsFound
);
1156 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1159 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1161 NetOut
.Write(Byte(NET_MSG_COOP
));
1162 NetOut
.Write(gTotalMonsters
);
1163 NetOut
.Write(gSecretsCount
);
1164 NetOut
.Write(gCoopTotalMonstersKilled
);
1165 NetOut
.Write(gCoopTotalSecretsFound
);
1166 NetOut
.Write(gCoopTotalMonsters
);
1167 NetOut
.Write(gCoopTotalSecrets
);
1170 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1172 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1173 NetOut
.Write(EvType
);
1174 NetOut
.Write(EvNum
);
1175 NetOut
.Write(EvStr
);
1176 NetOut
.Write(Byte(gLastMap
));
1177 NetOut
.Write(gTime
);
1178 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1180 NetOut
.Write(Byte(1));
1181 NetOut
.Write(gWADHash
);
1183 NetOut
.Write(Byte(0));
1185 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1188 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1190 NetOut
.Write(Byte(NET_MSG_FLAG
));
1191 NetOut
.Write(EvType
);
1193 NetOut
.Write(Byte(Quiet
));
1195 NetOut
.Write(gFlags
[Flag
].State
);
1196 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1197 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1198 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1199 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1200 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1201 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1203 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1206 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1208 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1210 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1211 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1212 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1213 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1215 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1218 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1220 NetOut
.Write(Byte(NET_MSG_GSET
));
1221 NetOut
.Write(gGameSettings
.GameMode
);
1222 NetOut
.Write(gGameSettings
.ScoreLimit
);
1223 NetOut
.Write(gGameSettings
.TimeLimit
);
1224 NetOut
.Write(gGameSettings
.MaxLives
);
1225 NetOut
.Write(gGameSettings
.Options
);
1227 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1232 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1236 P
:= g_Player_Get(PID
);
1237 if P
= nil then Exit
;
1239 NetOut
.Write(Byte(NET_MSG_PLR
));
1241 NetOut
.Write(P
.Name
);
1243 NetOut
.Write(P
.FActualModelName
);
1244 NetOut
.Write(P
.FColor
.R
);
1245 NetOut
.Write(P
.FColor
.G
);
1246 NetOut
.Write(P
.FColor
.B
);
1247 NetOut
.Write(P
.Team
);
1249 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1252 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1257 Pl
:= g_Player_Get(PID
);
1258 if Pl
= nil then Exit
;
1259 if Pl
.FDummy
then Exit
;
1261 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1262 NetOut
.Write(gTime
);
1269 NetOut
.Write(FPing
);
1270 NetOut
.Write(FLoss
);
1271 if IsKeyPressed(KEY_CHAT
) then
1272 kByte
:= NET_KEY_CHAT
1275 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1276 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1277 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1278 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1279 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1282 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1284 NetOut
.Write(kByte
);
1285 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1286 NetOut
.Write(GameX
);
1287 NetOut
.Write(GameY
);
1288 NetOut
.Write(GameVelX
);
1289 NetOut
.Write(GameVelY
);
1290 NetOut
.Write(GameAccelX
);
1291 NetOut
.Write(GameAccelY
);
1294 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1297 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1302 P
:= g_Player_Get(PID
);
1303 if P
= nil then Exit
;
1305 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1310 NetOut
.Write(Byte(alive
));
1311 NetOut
.Write(Byte(GodMode
));
1312 NetOut
.Write(Health
);
1313 NetOut
.Write(Armor
);
1315 NetOut
.Write(JetFuel
);
1316 NetOut
.Write(Lives
);
1319 for I
:= WP_FIRST
to WP_LAST
do
1320 NetOut
.Write(Byte(FWeapon
[I
]));
1322 for I
:= A_BULLETS
to A_HIGH
do
1323 NetOut
.Write(FAmmo
[I
]);
1325 for I
:= A_BULLETS
to A_HIGH
do
1326 NetOut
.Write(FMaxAmmo
[I
]);
1328 for I
:= MR_SUIT
to MR_MAX
do
1329 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1331 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1332 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1333 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1334 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1335 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1337 NetOut
.Write(Frags
);
1338 NetOut
.Write(Death
);
1340 NetOut
.Write(CurrWeap
);
1342 NetOut
.Write(Byte(FSpectator
));
1343 NetOut
.Write(Byte(FGhost
));
1344 NetOut
.Write(Byte(FPhysics
));
1345 NetOut
.Write(Byte(FNoRespawn
));
1346 NetOut
.Write(Byte(FJetpack
));
1347 NetOut
.Write(FFireTime
);
1348 NetOut
.Write(Byte(FFlaming
));
1349 NetOut
.Write(FSpawnInvul
);
1352 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1355 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1357 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1360 NetOut
.Write(Attacker
);
1361 NetOut
.Write(Value
);
1365 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1368 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1370 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1372 NetOut
.Write(KillType
);
1373 NetOut
.Write(DeathType
);
1374 NetOut
.Write(Attacker
);
1376 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1379 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1381 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1383 NetOut
.Write(Weapon
);
1388 NetOut
.Write(ShotID
);
1390 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1393 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1395 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1398 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1401 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1405 Pl
:= g_Player_Get(PID
);
1406 if Pl
= nil then Exit
;
1408 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1410 NetOut
.Write(Pl
.Name
);
1412 NetOut
.Write(Pl
.Model
.GetName())
1415 NetOut
.Write(Pl
.FColor
.R
);
1416 NetOut
.Write(Pl
.FColor
.G
);
1417 NetOut
.Write(Pl
.FColor
.B
);
1418 NetOut
.Write(Pl
.Team
);
1420 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1425 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1430 it
:= g_Items_ByIdx(IID
);
1432 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1434 NetOut
.Write(Byte(Quiet
));
1436 if it
.dropped
then tt
:= tt
or $80;
1438 NetOut
.Write(Byte(it
.Fall
));
1439 NetOut
.Write(Byte(it
.Respawnable
));
1440 NetOut
.Write(it
.Obj
.X
);
1441 NetOut
.Write(it
.Obj
.Y
);
1442 NetOut
.Write(it
.Obj
.Vel
.X
);
1443 NetOut
.Write(it
.Obj
.Vel
.Y
);
1445 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1448 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1450 NetOut
.Write(Byte(NET_MSG_IDEL
));
1452 NetOut
.Write(Byte(Quiet
));
1454 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1457 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1461 it
:= g_Items_ByIdx(IID
);
1463 NetOut
.Write(Byte(NET_MSG_IPOS
));
1465 NetOut
.Write(it
.Obj
.X
);
1466 NetOut
.Write(it
.Obj
.Y
);
1467 NetOut
.Write(it
.Obj
.Vel
.X
);
1468 NetOut
.Write(it
.Obj
.Vel
.Y
);
1470 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1475 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1479 TP
:= g_Map_PanelByGUID(PGUID
);
1480 if (TP
= nil) then exit
;
1484 NetOut
.Write(Byte(NET_MSG_PTEX
));
1485 NetOut
.Write(LongWord(PGUID
));
1486 NetOut
.Write(FCurTexture
);
1487 NetOut
.Write(FCurFrame
);
1488 NetOut
.Write(FCurFrameCount
);
1489 NetOut
.Write(AnimLoop
);
1492 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1495 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1500 TP
:= g_Map_PanelByGUID(PGUID
);
1501 if (TP
= nil) then exit
;
1503 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1504 NetOut
.Write(LongWord(PGUID
));
1505 NetOut
.Write(Byte(TP
.Enabled
));
1506 NetOut
.Write(TP
.LiftType
);
1509 NetOut
.Write(Word(TP
.Width
));
1510 NetOut
.Write(Word(TP
.Height
));
1512 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1513 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1514 NetOut
.Write(LongInt(TP
.movingStartX
));
1515 NetOut
.Write(LongInt(TP
.movingStartY
));
1516 NetOut
.Write(LongInt(TP
.movingEndX
));
1517 NetOut
.Write(LongInt(TP
.movingEndY
));
1518 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1519 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1520 NetOut
.Write(LongInt(TP
.sizeEndX
));
1521 NetOut
.Write(LongInt(TP
.sizeEndY
));
1522 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1523 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1524 NetOut
.Write(Byte(mpflags
));
1526 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1531 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1533 if gTriggers
= nil then Exit
;
1534 if T
.Sound
= nil then Exit
;
1536 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1537 NetOut
.Write(T
.ClientID
);
1538 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1539 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1540 NetOut
.Write(T
.SoundPlayCount
);
1542 g_Net_Host_Send(ID
, True);
1545 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1547 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1548 NetOut
.Write(gMusic
.Name
);
1549 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1550 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1551 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1553 g_Net_Host_Send(ID
, True);
1558 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1562 M
:= g_Monsters_ByUID(UID
);
1568 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1570 NetOut
.Write(MonsterType
);
1571 NetOut
.Write(MonsterState
);
1572 NetOut
.Write(MonsterAnim
);
1573 NetOut
.Write(MonsterTargetUID
);
1574 NetOut
.Write(MonsterTargetTime
);
1575 NetOut
.Write(MonsterBehaviour
);
1576 NetOut
.Write(MonsterSleep
);
1577 NetOut
.Write(MonsterHealth
);
1578 NetOut
.Write(MonsterAmmo
);
1579 NetOut
.Write(GameX
);
1580 NetOut
.Write(GameY
);
1581 NetOut
.Write(GameVelX
);
1582 NetOut
.Write(GameVelY
);
1583 NetOut
.Write(Byte(GameDirection
));
1586 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1589 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1593 M
:= g_Monsters_ByUID(UID
);
1594 if M
= nil then Exit
;
1596 NetOut
.Write(Byte(NET_MSG_MPOS
));
1601 NetOut
.Write(GameX
);
1602 NetOut
.Write(GameY
);
1603 NetOut
.Write(GameVelX
);
1604 NetOut
.Write(GameVelY
);
1605 NetOut
.Write(Byte(GameDirection
));
1608 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1611 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1615 M
:= g_Monsters_ByUID(UID
);
1616 if M
= nil then Exit
;
1618 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1623 NetOut
.Write(MonsterState
);
1624 NetOut
.Write(ForcedAnim
);
1625 NetOut
.Write(MonsterTargetUID
);
1626 NetOut
.Write(MonsterTargetTime
);
1627 NetOut
.Write(MonsterSleep
);
1628 NetOut
.Write(MonsterHealth
);
1629 NetOut
.Write(MonsterAmmo
);
1630 NetOut
.Write(MonsterPain
);
1631 NetOut
.Write(Byte(AnimIsReverse
));
1632 NetOut
.Write(FFireTime
);
1635 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1638 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1640 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1647 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1650 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1654 M
:= g_Monsters_ByUID(UID
);
1655 if M
= nil then Exit
;
1657 NetOut
.Write(Byte(NET_MSG_MDEL
));
1660 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1665 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1667 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1670 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1673 procedure MH_SEND_VoteEvent(EvType
: Byte;
1674 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1675 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1676 ID
: Integer = NET_EVERYONE
);
1678 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1679 NetOut
.Write(EvType
);
1680 NetOut
.Write(IntArg1
);
1681 NetOut
.Write(IntArg2
);
1682 NetOut
.Write(StrArg1
);
1683 NetOut
.Write(StrArg2
);
1685 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1688 // CLIENT MESSAGES //
1692 procedure MC_RECV_Chat(var M
: TMsg
);
1697 Txt
:= M
.ReadString();
1698 Mode
:= M
.ReadByte();
1700 if Mode
<> NET_CHAT_SYSTEM
then
1702 if NetDeafLevel
= 0 then
1704 if Mode
= NET_CHAT_PLAYER
then
1706 g_Console_Add(Txt
, True);
1707 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1708 g_Game_ChatSound(b_Text_Unformat(Txt
));
1710 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1712 if gPlayer1
.Team
= TEAM_RED
then
1713 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1714 if gPlayer1
.Team
= TEAM_BLUE
then
1715 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1716 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1717 g_Game_ChatSound(b_Text_Unformat(Txt
));
1720 end else if (NetDeafLevel
< 2) then
1721 g_Console_Add(Txt
, True);
1724 procedure MC_RECV_Effect(var M
: TMsg
);
1730 if not gGameOn
then Exit
;
1731 Kind
:= M
.ReadByte();
1732 X
:= M
.ReadLongInt();
1733 Y
:= M
.ReadLongInt();
1734 Ang
:= M
.ReadSmallInt();
1738 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1742 g_GFX_QueueEffect(R_GFX_TELEPORT_FAST
, X
, Y
);
1744 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1749 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, X
- 64, Y
- 64);
1751 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1756 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, X
- 64, Y
- 64);
1758 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1763 g_GFX_QueueEffect(R_GFX_BFG_HIT
, X
- 32, Y
- 32);
1768 g_GFX_QueueEffect(R_GFX_FIRE
, X
, Y
);
1770 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1775 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
, Y
);
1777 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1781 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1784 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1788 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1789 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1794 procedure MC_RECV_Sound(var M
: TMsg
);
1800 Name
:= M
.ReadString();
1801 Pos
:= M
.ReadByte() <> 0;
1804 X
:= M
.ReadLongInt();
1805 Y
:= M
.ReadLongInt();
1806 g_Sound_PlayExAt(Name
, X
, Y
);
1809 g_Sound_PlayEx(Name
);
1812 procedure MC_RECV_CreateShot(var M
: TMsg
);
1814 I
, X
, Y
, XV
, YV
: Integer;
1816 Target
, Spawner
: Word;
1819 I
:= M
.ReadLongInt();
1820 ShType
:= M
.ReadByte();
1821 Target
:= M
.ReadWord();
1822 Spawner
:= M
.ReadWord();
1823 Timeout
:= M
.ReadLongWord();
1824 X
:= M
.ReadLongInt();
1825 Y
:= M
.ReadLongInt();
1826 XV
:= M
.ReadLongInt();
1827 YV
:= M
.ReadLongInt();
1829 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1830 if (Shots
<> nil) and (I
<= High(Shots
)) then
1832 Shots
[I
].Timeout
:= Timeout
;
1833 //Shots[I].Target := Target; // TODO: find a use for Target later
1837 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1839 I
, TX
, TY
, TXV
, TYV
: Integer;
1841 I
:= M
.ReadLongInt();
1842 TX
:= M
.ReadLongInt();
1843 TY
:= M
.ReadLongInt();
1844 TXV
:= M
.ReadLongInt();
1845 TYV
:= M
.ReadLongInt();
1847 if (Shots
<> nil) and (I
<= High(Shots
)) then
1857 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1862 if not gGameOn
then Exit
;
1863 I
:= M
.ReadLongInt();
1864 L
:= (M
.ReadByte() <> 0);
1865 X
:= M
.ReadLongInt();
1866 Y
:= M
.ReadLongInt();
1868 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1871 procedure MC_RECV_GameStats(var M
: TMsg
);
1873 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1875 gTeamStat
[TEAM_RED
].Score
:= M
.ReadSmallInt();
1876 gTeamStat
[TEAM_BLUE
].Score
:= M
.ReadSmallInt();
1879 if gGameSettings
.GameMode
= GM_COOP
then
1881 gCoopMonstersKilled
:= M
.ReadWord();
1882 gCoopSecretsFound
:= M
.ReadWord();
1886 procedure MC_RECV_CoopStats(var M
: TMsg
);
1888 gTotalMonsters
:= M
.ReadLongInt();
1889 gSecretsCount
:= M
.ReadLongInt();
1890 gCoopTotalMonstersKilled
:= M
.ReadWord();
1891 gCoopTotalSecretsFound
:= M
.ReadWord();
1892 gCoopTotalMonsters
:= M
.ReadWord();
1893 gCoopTotalSecrets
:= M
.ReadWord();
1896 procedure MC_RECV_GameEvent(var M
: TMsg
);
1905 i1
, i2
: TStrings_Locale
;
1908 goodCmd
: Boolean = true;
1910 FillChar(EvHash
, Sizeof(EvHash
), 0);
1911 EvType
:= M
.ReadByte();
1912 EvNum
:= M
.ReadLongInt();
1913 EvStr
:= M
.ReadString();
1914 gLastMap
:= M
.ReadByte() <> 0;
1915 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1916 gStatsPressed
:= True;
1917 EvTime
:= M
.ReadLongWord();
1918 BHash
:= M
.ReadByte() <> 0;
1920 EvHash
:= M
.ReadMD5();
1924 if (g_Res_received_map_start
<> 0) then
1926 if (g_Res_received_map_start
< 0) then exit
;
1929 NET_EV_MAPSTART
: goodCmd
:= true;
1930 NET_EV_MAPEND
: goodCmd
:= true;
1931 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1932 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1933 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1935 if not goodCmd
then exit
;
1941 if (g_Res_received_map_start
<> 0) then
1943 g_Res_received_map_start
:= -1;
1948 g_Game_ClearLoading();
1949 g_Game_StopAllSounds(True);
1951 gSwitchGameMode
:= Byte(EvNum
);
1952 gGameSettings
.GameMode
:= gSwitchGameMode
;
1955 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1957 if not isWadPath(EvStr
) then
1958 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1960 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1964 MC_SEND_FullStateRequest
;
1970 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1971 gLMSRespawnTime
:= 0;
1972 if (g_Res_received_map_start
<> 0) then
1974 g_Res_received_map_start
:= -1;
1978 gMissionFailed
:= EvNum
<> 0;
1979 gExit
:= EXIT_ENDLEVELCUSTOM
;
1987 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1989 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1991 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1997 if NetDeafLevel
< 2 then
1999 if EvNum
= TEAM_RED
then
2000 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
2001 if EvNum
= TEAM_BLUE
then
2002 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
2008 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
2009 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2014 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
2015 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2022 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
2023 gLMSRespawnTime
:= gTime
+ EvNum
;
2024 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2026 else if gPlayer1
= nil then
2028 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2032 NET_EV_LMS_SURVIVOR
:
2033 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2036 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2040 pl
:= g_Player_Get(EvNum
and $FFFF);
2045 cnt
:= (EvNum
shr 16) and $FF;
2046 if Pos('w', EvStr
) = 0 then
2049 if Pos('t', EvStr
) = 0 then
2052 if Pos('-', EvStr
) = 0 then
2054 if Pos('e', EvStr
) = 0 then
2055 i1
:= I_PLAYER_SCORE_ADD_OWN
2057 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2060 if Pos('e', EvStr
) = 0 then
2061 i1
:= I_PLAYER_SCORE_SUB_OWN
2063 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2066 if Pos('r', EvStr
) > 0 then
2067 i2
:= I_PLAYER_SCORE_TO_RED
2069 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2070 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2074 if Pos('-', EvStr
) = 0 then
2075 i1
:= I_PLAYER_SCORE_ADD_TEAM
2077 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2079 if Pos('r', EvStr
) > 0 then
2080 i2
:= I_PLAYER_SCORE_RED
2082 i2
:= I_PLAYER_SCORE_BLUE
;
2083 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2088 if Pos('e', EvStr
) = 0 then
2089 i1
:= I_PLAYER_SCORE_WIN_OWN
2091 i1
:= I_PLAYER_SCORE_WIN_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
, _lc
[i2
]]), True);
2103 if EvNum
= TEAM_RED
then
2104 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2105 if EvNum
= TEAM_BLUE
then
2106 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2107 if EvNum
= -TEAM_RED
then
2108 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2109 if EvNum
= -TEAM_BLUE
then
2110 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2115 g_Player_RemoveAllCorpses
;
2116 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2117 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2121 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2125 if EvNum
= TEAM_RED
then
2126 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2127 if EvNum
= TEAM_BLUE
then
2128 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2132 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2135 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2138 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2141 g_Game_Announce_KillCombo(EvNum
);
2143 NET_EV_PLAYER_TOUCH
:
2145 pl
:= g_Player_Get(EvNum
);
2152 pl
:= g_Player_Get(EvNum
);
2155 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2156 g_Sound_PlayEx('SOUND_GAME_SECRET');
2162 pl
:= g_Player_Get(EvNum
);
2163 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2168 procedure MC_RECV_FlagPos(var M
: TMsg
);
2173 if Fl
= FLAG_NONE
then Exit
;
2174 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2175 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2176 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2177 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2180 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2189 EvType
:= M
.ReadByte();
2192 if Fl
= FLAG_NONE
then Exit
;
2194 Quiet
:= (M
.ReadByte() <> 0);
2195 PID
:= M
.ReadWord();
2197 gFlags
[Fl
].State
:= M
.ReadByte();
2198 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2199 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2200 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2201 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2202 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2203 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2205 Pl
:= g_Player_Get(PID
);
2207 (EvType
<> FLAG_STATE_NORMAL
) and
2208 (EvType
<> FLAG_STATE_DROPPED
) and
2209 (EvType
<> FLAG_STATE_RETURNED
) then
2215 if Quiet
or (Pl
= nil) then Exit
;
2217 if Fl
= FLAG_RED
then
2218 s
:= _lc
[I_PLAYER_FLAG_RED
]
2220 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2222 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2224 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2225 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2226 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2231 if not sound_ret_flag
[a
].IsPlaying() then
2232 sound_ret_flag
[a
].Play();
2235 FLAG_STATE_CAPTURED
:
2237 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2241 if Fl
= FLAG_RED
then
2242 s
:= _lc
[I_PLAYER_FLAG_RED
]
2244 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2246 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2247 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2249 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2250 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2251 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2256 if not sound_get_flag
[a
].IsPlaying() then
2257 sound_get_flag
[a
].Play();
2262 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2264 if Quiet
or (Pl
= nil) then Exit
;
2266 if Fl
= FLAG_RED
then
2267 s
:= _lc
[I_PLAYER_FLAG_RED
]
2269 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2271 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2272 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2274 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2275 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2276 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2281 if not sound_lost_flag
[a
].IsPlaying() then
2282 sound_lost_flag
[a
].Play();
2287 g_Map_ResetFlag(FLAG_RED
);
2288 g_Map_ResetFlag(FLAG_BLUE
);
2289 if Quiet
or (Pl
= nil) then Exit
;
2290 Pl
.SetFlag(FLAG_NONE
);
2292 if Fl
= FLAG_RED
then
2293 s
:= _lc
[I_PLAYER_FLAG_RED
]
2295 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2297 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2298 Insert('.', ts
, Length(ts
) + 1 - 3);
2299 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2300 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2302 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2303 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2304 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2309 if not sound_cap_flag
[a
].IsPlaying() then
2310 sound_cap_flag
[a
].Play();
2313 FLAG_STATE_RETURNED
:
2315 g_Map_ResetFlag(Fl
);
2318 if Fl
= FLAG_RED
then
2319 s
:= _lc
[I_PLAYER_FLAG_RED
]
2321 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2323 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2325 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2326 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2327 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2332 if not sound_ret_flag
[a
].IsPlaying() then
2333 sound_ret_flag
[a
].Play();
2338 procedure MC_RECV_GameSettings(var M
: TMsg
);
2340 gGameSettings
.GameMode
:= M
.ReadByte();
2341 gGameSettings
.ScoreLimit
:= M
.ReadWord();
2342 gGameSettings
.TimeLimit
:= M
.ReadWord();
2343 gGameSettings
.MaxLives
:= M
.ReadByte();
2344 gGameSettings
.Options
:= M
.ReadLongWord();
2349 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2352 PName
, Model
: string;
2357 PID
:= M
.ReadWord();
2358 Pl
:= g_Player_Get(PID
);
2360 PName
:= M
.ReadString();
2361 Model
:= M
.ReadString();
2362 Color
.R
:= M
.ReadByte();
2363 Color
.G
:= M
.ReadByte();
2364 Color
.B
:= M
.ReadByte();
2368 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2370 if (Pl
<> nil) then Exit
;
2371 if (g_Force_Model_Get() <> 0) then
2372 Model
:= g_Forced_Model_GetName();
2373 DID
:= g_Player_Create(Model
, Color
, T
, False);
2374 with g_Player_Get(DID
) do
2383 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2384 gPlayer1
.UID
:= PID
;
2385 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2386 gPlayer1
.ChangeTeam(T
);
2388 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2389 gPlayer2
.UID
:= PID
;
2390 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2391 gPlayer2
.ChangeTeam(T
);
2395 if NetDeafLevel
< 3 then
2396 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2397 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2401 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2408 TmpX
, TmpY
: Integer;
2412 GT
:= M
.ReadLongWord();
2413 if GT
< gTime
- NET_MAX_DIFFTIME
then
2420 PID
:= M
.ReadWord();
2421 Pl
:= g_Player_Get(PID
);
2423 if Pl
= nil then Exit
;
2429 FPing
:= M
.ReadWord();
2430 FLoss
:= M
.ReadByte();
2431 kByte
:= M
.ReadWord();
2432 Dir
:= M
.ReadByte();
2434 TmpX
:= M
.ReadLongInt();
2435 TmpY
:= M
.ReadLongInt();
2439 if LongBool(kByte
and NET_KEY_CHAT
) then
2440 PressKey(KEY_CHAT
, 10000)
2443 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2444 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2445 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2446 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2447 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2450 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2452 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2453 SetDirection(TDirection(Dir
));
2455 GameVelX
:= M
.ReadLongInt();
2456 GameVelY
:= M
.ReadLongInt();
2457 GameAccelX
:= M
.ReadLongInt();
2458 GameAccelY
:= M
.ReadLongInt();
2459 SetLerp(TmpX
, TmpY
);
2460 if NetForcePlayerUpdate
then Update();
2464 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2468 I
, OldFire
: Integer;
2469 OldJet
, Flam
: Boolean;
2472 PID
:= M
.ReadWord();
2473 Pl
:= g_Player_Get(PID
);
2480 alive
:= (M
.ReadByte() <> 0);
2481 GodMode
:= (M
.ReadByte() <> 0);
2482 Health
:= M
.ReadLongInt();
2483 Armor
:= M
.ReadLongInt();
2484 Air
:= M
.ReadLongInt();
2485 JetFuel
:= M
.ReadLongInt();
2486 Lives
:= M
.ReadByte();
2487 NewTeam
:= M
.ReadByte();
2489 for I
:= WP_FIRST
to WP_LAST
do
2490 FWeapon
[I
] := (M
.ReadByte() <> 0);
2492 for I
:= A_BULLETS
to A_HIGH
do
2493 FAmmo
[I
] := M
.ReadWord();
2495 for I
:= A_BULLETS
to A_HIGH
do
2496 FMaxAmmo
[I
] := M
.ReadWord();
2498 for I
:= MR_SUIT
to MR_MAX
do
2499 FMegaRulez
[I
] := M
.ReadLongWord();
2502 if (M
.ReadByte() <> 0) then
2503 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2504 if (M
.ReadByte() <> 0) then
2505 FRulez
:= FRulez
+ [R_KEY_RED
];
2506 if (M
.ReadByte() <> 0) then
2507 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2508 if (M
.ReadByte() <> 0) then
2509 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2510 if (M
.ReadByte() <> 0) then
2511 FRulez
:= FRulez
+ [R_BERSERK
];
2513 Frags
:= M
.ReadLongInt();
2514 Death
:= M
.ReadLongInt();
2516 SetWeapon(M
.ReadByte());
2518 FSpectator
:= M
.ReadByte() <> 0;
2521 if UID
= NetPlrUID1
then
2523 gSpectLatchPID1
:= UID
;
2526 if UID
= NetPlrUID2
then
2528 gSpectLatchPID2
:= UID
;
2534 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2537 gSpectLatchPID1
:= 0;
2539 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2542 gSpectLatchPID2
:= 0;
2545 FGhost
:= M
.ReadByte() <> 0;
2546 FPhysics
:= M
.ReadByte() <> 0;
2547 FNoRespawn
:= M
.ReadByte() <> 0;
2549 FJetpack
:= M
.ReadByte() <> 0;
2550 OldFire
:= FFireTime
;
2551 FFireTime
:= M
.ReadLongInt();
2552 if (OldFire
<= 0) and (FFireTime
> 0) then
2553 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2554 Flam
:= M
.ReadByte() <> 0;
2555 FSpawnInvul
:= M
.ReadLongInt();
2556 if OldJet
and not FJetpack
then
2558 else if not OldJet
and FJetpack
then
2560 if FFlaming
and not Flam
then
2562 if Team
<> NewTeam
then
2563 Pl
.ChangeTeam(NewTeam
);
2569 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2574 Attacker
, Value
: Word;
2578 if not gGameOn
then Exit
;
2579 PID
:= M
.ReadWord();
2580 Pl
:= g_Player_Get(PID
);
2581 if Pl
= nil then Exit
;
2583 Kind
:= M
.ReadByte();
2584 Attacker
:= M
.ReadWord();
2585 Value
:= M
.ReadWord();
2590 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2595 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2599 KillType
, DeathType
: Byte;
2603 if not gGameOn
then Exit
;
2604 PID
:= M
.ReadWord();
2605 Pl
:= g_Player_Get(PID
);
2606 if Pl
= nil then Exit
;
2608 KillType
:= M
.ReadByte();
2609 DeathType
:= M
.ReadByte();
2610 Attacker
:= M
.ReadWord();
2614 Kill(KillType
, Attacker
, DeathType
);
2619 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2624 PID
:= M
.ReadWord();
2625 Pl
:= g_Player_Get(PID
);
2627 if Pl
= nil then Exit
;
2629 if NetDeafLevel
< 3 then
2630 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2631 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2633 g_Player_Remove(PID
);
2638 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2643 X
, Y
, AX
, AY
: Integer;
2647 if not gGameOn
then Exit
;
2648 PID
:= M
.ReadWord();
2649 Pl
:= g_Player_Get(PID
);
2650 if Pl
= nil then Exit
;
2652 Weap
:= M
.ReadByte();
2653 X
:= M
.ReadLongInt();
2654 Y
:= M
.ReadLongInt();
2655 AX
:= M
.ReadLongInt();
2656 AY
:= M
.ReadLongInt();
2657 SHID
:= M
.ReadLongInt();
2660 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2663 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2673 PID
:= M
.ReadWord();
2674 Pl
:= g_Player_Get(PID
);
2675 if Pl
= nil then Exit
;
2677 TmpName
:= M
.ReadString();
2678 TmpModel
:= M
.ReadString();
2679 TmpColor
.R
:= M
.ReadByte();
2680 TmpColor
.G
:= M
.ReadByte();
2681 TmpColor
.B
:= M
.ReadByte();
2682 TmpTeam
:= M
.ReadByte();
2684 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2686 Pl
.ChangeTeam(TmpTeam
);
2687 if gPlayer1
= Pl
then
2688 gPlayer1Settings
.Team
:= TmpTeam
;
2689 if gPlayer2
= Pl
then
2690 gPlayer2Settings
.Team
:= TmpTeam
;
2692 Pl
.SetColor(TmpColor
);
2694 if Pl
.Name
<> TmpName
then
2696 if NetDeafLevel
< 3 then
2697 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2701 if (g_Force_Model_Get() <> 0) then
2702 TmpModel
:= g_Forced_Model_GetName();
2703 if TmpModel
<> Pl
.Model
.GetName() then
2704 Pl
.SetModel(TmpModel
);
2709 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2712 X
, Y
, VX
, VY
: Integer;
2714 Quiet
, Fall
{, Resp}: Boolean;
2717 if not gGameOn
then Exit
;
2719 Quiet
:= M
.ReadByte() <> 0;
2721 Fall
:= M
.ReadByte() <> 0;
2722 {Resp :=} M
.ReadByte();
2723 X
:= M
.ReadLongInt();
2724 Y
:= M
.ReadLongInt();
2725 VX
:= M
.ReadLongInt();
2726 VY
:= M
.ReadLongInt();
2728 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2729 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2731 it
:= g_Items_ByIdx(ID
);
2737 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2738 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16);
2742 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2747 if not gGameOn
then Exit
;
2749 Quiet
:= M
.ReadByte() <> 0;
2751 if not g_Items_ValidId(ID
) then exit
;
2753 if not Quiet
then g_Items_EmitPickupSound(ID
);
2758 procedure MC_RECV_ItemPos(var M
: TMsg
);
2761 X
, Y
, VX
, VY
: Integer;
2764 if not gGameOn
then Exit
;
2767 X
:= M
.ReadLongInt();
2768 Y
:= M
.ReadLongInt();
2769 VX
:= M
.ReadLongInt();
2770 VY
:= M
.ReadLongInt();
2772 if g_Items_ValidId(ID
) then
2774 it
:= g_Items_ByIdx(ID
);
2779 it
.positionChanged();
2785 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2792 if not gGameOn
then Exit
;
2794 PGUID
:= Integer(M
.ReadLongWord());
2795 Tex
:= M
.ReadLongInt();
2796 Fr
:= M
.ReadLongInt();
2797 Cnt
:= M
.ReadByte();
2798 Loop
:= M
.ReadByte();
2800 TP
:= g_Map_PanelByGUID(PGUID
);
2804 TP
.SetTexture(Tex
, Loop
);
2805 TP
.SetFrame(Fr
, Cnt
);
2809 procedure MC_RECV_PanelState(var M
: TMsg
);
2814 X
, Y
, W
, H
: Integer;
2816 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2817 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2820 if not gGameOn
then Exit
;
2822 PGUID
:= Integer(M
.ReadLongWord());
2823 E
:= (M
.ReadByte() <> 0);
2824 Lift
:= M
.ReadByte();
2825 X
:= M
.ReadLongInt();
2826 Y
:= M
.ReadLongInt();
2830 speedX
:= M
.ReadLongInt();
2831 speedY
:= M
.ReadLongInt();
2832 startX
:= M
.ReadLongInt();
2833 startY
:= M
.ReadLongInt();
2834 endX
:= M
.ReadLongInt();
2835 endY
:= M
.ReadLongInt();
2836 sizeSpX
:= M
.ReadLongInt();
2837 sizeSpY
:= M
.ReadLongInt();
2838 sizeEX
:= M
.ReadLongInt();
2839 sizeEY
:= M
.ReadLongInt();
2840 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2842 TP
:= g_Map_PanelByGUID(PGUID
);
2843 if (TP
= nil) then exit
;
2845 // update lifts state
2846 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2848 // update enabled/disabled state for all panels
2849 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2851 // update panel position, as it can be moved (mplat)
2856 // update mplat state
2857 TP
.movingSpeedX
:= speedX
;
2858 TP
.movingSpeedY
:= speedY
;
2859 TP
.movingStartX
:= startX
;
2860 TP
.movingStartY
:= startY
;
2861 TP
.movingEndX
:= endX
;
2862 TP
.movingEndY
:= endY
;
2863 TP
.sizeSpeedX
:= sizeSpX
;
2864 TP
.sizeSpeedY
:= sizeSpY
;
2865 TP
.sizeEndX
:= sizeEX
;
2866 TP
.sizeEndY
:= sizeEY
;
2867 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2868 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2869 // notify panel of it's position/size change, so it can fix other internal structures
2870 TP
.positionChanged();
2875 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2878 SPos
, SID
: LongWord;
2882 if not gGameOn
then Exit
;
2883 if gTriggers
= nil then Exit
;
2885 SID
:= M
.ReadLongWord();
2886 SPlaying
:= M
.ReadByte() <> 0;
2887 SPos
:= M
.ReadLongWord();
2888 SCount
:= M
.ReadLongInt();
2890 for I
:= Low(gTriggers
) to High(gTriggers
) do
2891 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2892 if gTriggers
[I
].ClientID
= SID
then
2893 with gTriggers
[I
] do
2895 if Sound
<> nil then
2900 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2902 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2903 Sound
.SetPosition(SPos
);
2906 if Sound
.IsPlaying
then Sound
.Stop
;
2909 SoundPlayCount
:= SCount
;
2913 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2920 if not gGameOn
then Exit
;
2922 MName
:= M
.ReadString();
2923 MPlaying
:= M
.ReadByte() <> 0;
2924 MPos
:= M
.ReadLongWord();
2925 MPaused
:= M
.ReadByte() <> 0;
2926 MPos
:= MPos
+1; //k8: stfu, fpc!
2930 gMusic
.SetByName(MName
);
2932 // gMusic.SetPosition(MPos);
2933 gMusic
.SpecPause
:= MPaused
;
2936 if gMusic
.IsPlaying
then gMusic
.Stop
;
2941 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2944 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2945 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2950 Mon
:= g_Monsters_ByUID(ID
);
2954 MType
:= M
.ReadByte();
2955 MState
:= M
.ReadByte();
2956 MAnim
:= M
.ReadByte();
2957 MTarg
:= M
.ReadWord();
2958 MTargTime
:= M
.ReadLongInt();
2959 MBehav
:= M
.ReadByte();
2960 MSleep
:= M
.ReadLongInt();
2961 MHealth
:= M
.ReadLongInt();
2962 MAmmo
:= M
.ReadLongInt();
2964 X
:= M
.ReadLongInt();
2965 Y
:= M
.ReadLongInt();
2966 VX
:= M
.ReadLongInt();
2967 VY
:= M
.ReadLongInt();
2968 MDir
:= M
.ReadByte();
2970 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2971 Mon
:= g_Monsters_ByUID(ID
);
2978 MonsterAnim
:= MAnim
;
2979 MonsterTargetUID
:= MTarg
;
2980 MonsterTargetTime
:= MTargTime
;
2981 MonsterBehaviour
:= MBehav
;
2982 MonsterSleep
:= MSleep
;
2983 MonsterAmmo
:= MAmmo
;
2988 setPosition(X
, Y
); // this will call positionChanged();
2994 procedure MC_RECV_MonsterPos(var M
: TMsg
);
3001 Mon
:= g_Monsters_ByUID(ID
);
3007 X
:= M
.ReadLongInt();
3008 Y
:= M
.ReadLongInt();
3009 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
3010 GameVelX
:= M
.ReadLongInt();
3011 GameVelY
:= M
.ReadLongInt();
3012 GameDirection
:= TDirection(M
.ReadByte());
3016 procedure MC_RECV_MonsterState(var M
: TMsg
);
3018 ID
, OldFire
: Integer;
3019 MState
, MFAnm
: Byte;
3021 AnimRevert
: Boolean;
3024 Mon
:= g_Monsters_ByUID(ID
);
3025 if Mon
= nil then Exit
;
3027 MState
:= M
.ReadByte();
3028 MFAnm
:= M
.ReadByte();
3032 MonsterTargetUID
:= M
.ReadWord();
3033 MonsterTargetTime
:= M
.ReadLongInt();
3034 MonsterSleep
:= M
.ReadLongInt();
3035 MonsterHealth
:= M
.ReadLongInt();
3036 MonsterAmmo
:= M
.ReadLongInt();
3037 MonsterPain
:= M
.ReadLongInt();
3038 AnimRevert
:= M
.ReadByte() <> 0;
3039 OldFire
:= FFireTime
;
3040 FFireTime
:= M
.ReadLongInt();
3041 if (OldFire
<= 0) and (FFireTime
> 0) then
3042 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3043 RevertAnim(AnimRevert
);
3045 if MonsterState
<> MState
then
3047 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3048 if (MState
= MONSTATE_DIE
) then DieSound();
3049 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3050 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3051 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3053 SetState(MState
, MFAnm
);
3058 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3062 X
, Y
, VX
, VY
: Integer;
3066 Mon
:= g_Monsters_ByUID(ID
);
3067 if Mon
= nil then Exit
;
3069 X
:= M
.ReadLongInt();
3070 Y
:= M
.ReadLongInt();
3071 VX
:= M
.ReadLongInt();
3072 VY
:= M
.ReadLongInt();
3074 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3077 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3083 Mon
:= g_Monsters_ByUID(ID
);
3084 if Mon
= nil then Exit
;
3086 Mon
.MonsterRemoved
:= True;
3089 procedure MC_RECV_TimeSync(var M
: TMsg
);
3093 Time
:= M
.ReadLongWord();
3095 if gState
= STATE_INTERCUSTOM
then
3096 gServInterTime
:= Min(Time
, 255);
3099 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3103 Int1
, Int2
: SmallInt;
3105 EvID
:= M
.ReadByte();
3106 Int1
:= M
.ReadSmallInt();
3107 Int2
:= M
.ReadSmallInt();
3108 Str1
:= M
.ReadString();
3109 Str2
:= M
.ReadString();
3111 if NetDeafLevel
< 2 then
3114 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3116 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3118 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3120 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3122 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3128 procedure MC_SEND_Info(Password
: string);
3133 NetOut
.Write(Byte(NET_MSG_INFO
));
3134 NetOut
.Write(GAME_VERSION
);
3135 NetOut
.Write(Password
);
3136 NetOut
.Write(gPlayer1Settings
.Name
);
3137 NetOut
.Write(gPlayer1Settings
.Model
);
3138 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3139 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3140 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3141 NetOut
.Write(gPlayer1Settings
.Team
);
3142 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3143 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3144 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3145 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3146 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3148 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3151 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3153 NetOut
.Write(Byte(NET_MSG_CHAT
));
3157 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3160 procedure MC_SEND_PlayerPos();
3165 WeaponAct
: Byte = 0;
3166 WeaponSelect
: Word = 0;
3169 if not gGameOn
then Exit
;
3170 if gPlayers
= nil then Exit
;
3171 if gPlayer1
= nil then Exit
;
3174 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3177 if (not gConsoleShow
) and (not gChatShow
) then
3179 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3182 strafeDir
:= P1MoveButton
shr 4;
3183 P1MoveButton
:= P1MoveButton
and $0F;
3185 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3187 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3189 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3193 if gPlayerAction
[0, ACTION_STRAFE
] then
3195 // new strafe mechanics
3196 if (strafeDir
= 0) then
3197 strafeDir
:= P1MoveButton
; // start strafing
3198 // now set direction according to strafe (reversed)
3199 if (strafeDir
= 2) then
3200 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3201 else if (strafeDir
= 1) then
3202 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3206 strafeDir
:= 0; // not strafing anymore
3207 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3208 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3209 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3210 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3211 else if P1MoveButton
<> 0 then
3212 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3215 gPlayer1
.ReleaseKeys
;
3216 if P1MoveButton
= 1 then
3218 kByte
:= kByte
or NET_KEY_LEFT
;
3219 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3221 if P1MoveButton
= 2 then
3223 kByte
:= kByte
or NET_KEY_RIGHT
;
3224 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3226 if gPlayerAction
[0, ACTION_LOOKUP
] then
3228 kByte
:= kByte
or NET_KEY_UP
;
3229 gPlayer1
.PressKey(KEY_UP
, 10000);
3231 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3233 kByte
:= kByte
or NET_KEY_DOWN
;
3234 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3236 if gPlayerAction
[0, ACTION_JUMP
] then
3238 kByte
:= kByte
or NET_KEY_JUMP
;
3239 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3241 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3242 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3244 for i
:= WP_FACT
to WP_LACT
do
3246 if gWeaponAction
[0, i
] then
3248 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3249 gWeaponAction
[0, i
] := False
3253 for i
:= WP_FIRST
to WP_LAST
do
3255 if gSelectWeapon
[0, i
] then
3257 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3258 gSelectWeapon
[0, i
] := False
3262 // fix movebutton state
3263 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3266 kByte
:= NET_KEY_CHAT
;
3268 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3269 NetOut
.Write(gTime
);
3270 NetOut
.Write(kByte
);
3271 NetOut
.Write(Byte(gPlayer1
.Direction
));
3272 NetOut
.Write(WeaponAct
);
3273 NetOut
.Write(WeaponSelect
);
3274 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3275 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3277 //kBytePrev := kByte;
3278 //kDirPrev := gPlayer1.Direction;
3281 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3283 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3284 NetOut
.Write(Byte(Start
));
3285 NetOut
.Write(Command
);
3286 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3289 procedure MC_SEND_PlayerSettings();
3292 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3293 NetOut
.Write(gPlayer1Settings
.Name
);
3294 NetOut
.Write(gPlayer1Settings
.Model
);
3295 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3296 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3297 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3298 NetOut
.Write(gPlayer1Settings
.Team
);
3299 NetOut
.Write(gPlayer1Settings
.WeaponSwitch
);
3300 for i
:= WP_FIRST
to WP_LAST
+ 1 do
3301 NetOut
.Write(gPlayer1Settings
.WeaponPreferences
[i
]);
3302 NetOut
.Write(gPlayer1Settings
.SwitchToEmpty
);
3303 NetOut
.Write(gPlayer1Settings
.SkipFist
);
3305 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3308 procedure MC_SEND_FullStateRequest();
3310 NetOut
.Write(Byte(NET_MSG_REQFST
));
3312 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3315 procedure MC_SEND_CheatRequest(Kind
: Byte);
3317 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3320 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3322 procedure MC_SEND_RCONPassword(Password
: string);
3324 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3325 NetOut
.Write(Password
);
3327 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3329 procedure MC_SEND_RCONCommand(Cmd
: string);
3331 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3334 g_Net_Client_Send(True, NET_CHAN_SERVICE
);