1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
20 uses e_msg
, g_net
, g_triggers
, Classes
, SysUtils
, md5
;
66 NET_MSG_RCON_AUTH
= 191;
67 NET_MSG_RCON_CMD
= 192;
68 NET_MSG_TIME_SYNC
= 194;
69 NET_MSG_VOTE_EVENT
= 195;
72 NET_MSG_MAP_REQUEST = 201;
73 NET_MSG_MAP_RESPONSE = 202;
74 NET_MSG_RES_REQUEST = 203;
75 NET_MSG_RES_RESPONSE = 204;
99 NET_EV_CHANGE_TEAM
= 3;
100 NET_EV_PLAYER_KICK
= 4;
101 NET_EV_PLAYER_BAN
= 5;
102 NET_EV_LMS_WARMUP
= 6;
103 NET_EV_LMS_SURVIVOR
= 7;
107 NET_EV_SCORE_MSG
= 11;
108 NET_EV_LMS_START
= 12;
110 NET_EV_TLMS_WIN
= 14;
111 NET_EV_LMS_LOSE
= 15;
112 NET_EV_LMS_DRAW
= 16;
113 NET_EV_KILLCOMBO
= 17;
114 NET_EV_PLAYER_TOUCH
= 18;
116 NET_EV_INTER_READY
= 20;
117 NET_EV_LMS_NOSPAWN
= 21;
124 NET_VE_INPROGRESS
= 6;
131 NET_CHEAT_SUICIDE
= 1;
132 NET_CHEAT_SPECTATE
= 2;
134 NET_CHEAT_DROPFLAG
= 4;
136 NET_MAX_DIFFTIME
= 5000 div 36;
140 procedure MH_MalformedPacket(C
: pTNetClient
);
141 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
143 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
146 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
147 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
148 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
149 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
150 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
151 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
152 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
153 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
156 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
157 procedure MH_SEND_Info(ID
: Byte);
158 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
189 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
190 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
191 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
193 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
194 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
196 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
197 procedure MH_SEND_VoteEvent(EvType
: Byte;
198 StrArg1
: string = 'a'; StrArg2
: string = 'b';
199 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
200 ID
: Integer = NET_EVERYONE
);
202 // CLIENT MESSAGES //
205 procedure MC_RECV_Chat(var M
: TMsg
);
206 procedure MC_RECV_Effect(var M
: TMsg
);
207 procedure MC_RECV_Sound(var M
: TMsg
);
208 procedure MC_RECV_GameStats(var M
: TMsg
);
209 procedure MC_RECV_CoopStats(var M
: TMsg
);
210 procedure MC_RECV_GameEvent(var M
: TMsg
);
211 procedure MC_RECV_FlagEvent(var M
: TMsg
);
212 procedure MC_RECV_FlagPos(var M
: TMsg
);
213 procedure MC_RECV_GameSettings(var M
: TMsg
);
215 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
216 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
217 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
218 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
219 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
220 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
221 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
222 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
224 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
225 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
226 procedure MC_RECV_ItemPos(var M
: TMsg
);
228 procedure MC_RECV_PanelTexture(var M
: TMsg
);
229 procedure MC_RECV_PanelState(var M
: TMsg
);
231 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
232 procedure MC_RECV_MonsterPos(var M
: TMsg
);
233 procedure MC_RECV_MonsterState(var M
: TMsg
);
234 procedure MC_RECV_MonsterShot(var M
: TMsg
);
235 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
237 procedure MC_RECV_CreateShot(var M
: TMsg
);
238 procedure MC_RECV_UpdateShot(var M
: TMsg
);
239 procedure MC_RECV_DeleteShot(var M
: TMsg
);
241 procedure MC_RECV_TriggerSound(var M
: TMsg
);
242 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
244 procedure MC_RECV_TimeSync(var M
: TMsg
);
245 procedure MC_RECV_VoteEvent(var M
: TMsg
);
247 procedure MC_SEND_Info(Password
: string);
248 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
249 procedure MC_SEND_PlayerPos();
250 procedure MC_SEND_FullStateRequest();
251 procedure MC_SEND_PlayerSettings();
252 procedure MC_SEND_CheatRequest(Kind
: Byte);
253 procedure MC_SEND_RCONPassword(Password
: string);
254 procedure MC_SEND_RCONCommand(Cmd
: string);
255 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
257 //procedure MC_SEND_MapRequest();
258 //procedure MC_SEND_ResRequest(const resName: AnsiString);
262 TExternalResourceInfo
= record
277 ExternalResources
: array of TExternalResourceInfo
;
280 function IsValidFileName(const S
: String): Boolean;
281 function IsValidFilePath(const S
: String): Boolean;
287 Math
, ENet
, e_input
, e_graphics
, e_log
,
288 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
289 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
290 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
293 NET_KEY_LEFT
= 1 shl 0;
294 NET_KEY_RIGHT
= 1 shl 1;
295 NET_KEY_UP
= 1 shl 2;
296 NET_KEY_DOWN
= 1 shl 3;
297 NET_KEY_JUMP
= 1 shl 4;
298 NET_KEY_FIRE
= 1 shl 5;
299 NET_KEY_OPEN
= 1 shl 6;
300 NET_KEY_CHAT
= 1 shl 7;
301 NET_KEY_FORCEDIR
= 1 shl 8;
304 //kBytePrev: Word = 0;
305 //kDirPrev: TDirection = D_LEFT;
306 //HostGameTime: Word = 0;
309 function IsValidFileName(const S
: String): Boolean;
311 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
316 for I
:= 1 to Length(S
) do
317 Result
:= Result
and (not(S
[I
] in Forbidden
));
320 function IsValidFilePath(const S
: String): Boolean;
325 if not IsValidFileName(S
) then exit
;
326 if FileExists(S
) then exit
;
327 I
:= LastDelimiter('\/', S
);
329 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
340 procedure MH_MalformedPacket(C
: pTNetClient
);
342 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
343 _lc
[I_NET_DISC_PROTOCOL
]);
344 enet_peer_disconnect(C
^.Peer
, NET_DISC_PROTOCOL
);
347 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
356 Pl
:= g_Player_Get(PID
);
360 Txt
:= M
.ReadString();
361 Mode
:= M
.ReadByte();
366 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
368 if (Mode
= NET_CHAT_SYSTEM
) then
369 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
370 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
371 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
374 MH_SEND_Chat(Txt
, Mode
)
376 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
379 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
381 Ver
, PName
, Model
, Pw
: string;
390 Ver
:= M
.ReadString();
391 Pw
:= M
.ReadString();
392 PName
:= M
.ReadString();
393 Model
:= M
.ReadString();
402 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
404 if Ver
<> GAME_VERSION
then
406 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
407 _lc
[I_NET_DISC_VERSION
]);
408 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
412 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
414 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
416 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
417 _lc
[I_NET_DISC_BAN
]);
418 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
422 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
423 _lc
[I_NET_DISC_BAN
]);
424 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
429 if NetPassword
<> '' then
430 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
432 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
433 _lc
[I_NET_DISC_PASSWORD
]);
434 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
438 if (C
^.Player
<> 0) then
440 // already received info
441 g_Net_Penalize(C
, 'client info spam');
449 PID
:= g_Player_Create(Model
, Color
, T
, False);
450 with g_Player_Get(PID
) do
457 C
^.WaitForFirstSpawn
:= false;
460 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
461 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
462 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
466 with g_Player_Get(PID
) do
470 // round in progress, don't spawn
471 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
472 //e_LogWritefln('spawning player with pid #%u...', [PID]);
473 //Respawn(gGameSettings.GameType = GT_SINGLE);
474 //k8: no, do not spawn a player yet, wait for "request full state" packet
478 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
479 // that is, if we'll set it to `true`, the player can be spawned after
480 // warmup time ran out, for example, regardless of the real player state.
481 // also, this seems to work only for the initial connection. further
482 // map changes could initiate resource downloading, but the player will
483 // be spawned immediately.
484 // the proper solution will require another player state, "ephemeral".
485 // the player should start any map in "ephemeral" state, and turned into
486 // real mobj only when they sent a special "i am ready" packet. this packet
487 // must be sent after receiving the full state, so the player will get a full
488 // map view before going into game.
489 FWantsInGame
:= false;
490 C
^.WaitForFirstSpawn
:= true;
493 //if not C^.WaitForFirstSpawn then
495 for I
:= Low(NetClients
) to High(NetClients
) do
497 if NetClients
[I
].ID
= C
^.ID
then Continue
;
498 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
499 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
500 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
504 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
505 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
509 //g_Net_Slist_Update;
515 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
519 if not C
.WaitForFirstSpawn
then exit
;
520 plr
:= g_Player_Get(C
^.Player
);
521 if not assigned(plr
) then exit
;
522 g_Net_Slist_ServerPlayerComes();
523 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
524 C
.WaitForFirstSpawn
:= false;
525 plr
.FNoRespawn
:= false;
526 plr
.FWantsInGame
:= true; // TODO: look into this later
528 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
531 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
536 if gLMSRespawn
> LMS_RESPAWN_NONE
then
537 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
542 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
544 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
547 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
551 C
^.RequestedFullUpdate
:= True;
557 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
570 if not gGameOn
then Exit
;
573 GT
:= M
.ReadLongWord();
578 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
581 Pl
:= g_Player_Get(PID
);
585 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
591 kByte
:= M
.ReadWord();
593 WeaponAct
:= M
.ReadByte();
594 WeaponSelect
:= M
.ReadWord();
599 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
601 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
602 if Direction
<> TDirection(Dir
) then
603 JustTeleported
:= False;
605 SetDirection(TDirection(Dir
));
608 if kByte
= NET_KEY_CHAT
then
610 PressKey(KEY_CHAT
, 10000);
614 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
615 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
616 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
617 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
618 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
619 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
620 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
624 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
626 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
627 ProcessWeaponAction(i
);
633 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
635 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
636 QueueWeaponSwitch(i
);
641 // MH_SEND_PlayerPos(False, PID, C^.ID);
644 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
651 Pl
:= g_Player_Get(C
^.Player
);
652 if Pl
= nil then Exit
;
655 CheatKind
:= M
.ReadByte();
660 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
664 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
667 if Pl
.FSpectator
then
669 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
672 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
679 if gState
<> STATE_INTERCUSTOM
then Exit
;
680 Pl
.FReady
:= not Pl
.FReady
;
683 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
684 Inc(gInterReadyCount
);
688 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
689 Dec(gInterReadyCount
);
697 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
708 TmpName
:= M
.ReadString();
709 TmpModel
:= M
.ReadString();
710 TmpColor
.R
:= M
.ReadByte();
711 TmpColor
.G
:= M
.ReadByte();
712 TmpColor
.B
:= M
.ReadByte();
713 TmpTeam
:= M
.ReadByte();
718 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
720 Pl
:= g_Player_Get(C
^.Player
);
721 if Pl
= nil then Exit
;
723 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
726 Pl
.SetColor(TmpColor
);
728 if Pl
.Name
<> TmpName
then
730 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
734 if TmpModel
<> Pl
.Model
.Name
then
735 Pl
.SetModel(TmpModel
);
737 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
742 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
749 Pwd
:= M
.ReadString();
753 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
754 if not NetAllowRCON
then Exit
;
755 if Pwd
= NetRCONPassword
then
758 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
761 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
764 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
771 Cmd
:= M
.ReadString();
775 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
776 if not NetAllowRCON
then Exit
;
777 if not C
^.RCONAuth
then
779 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
782 g_Console_Process(Cmd
);
787 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
790 Name
, Command
: string;
797 Start
:= M
.ReadByte() <> 0;
798 Command
:= M
.ReadString();
803 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
805 Pl
:= g_Player_Get(C
^.Player
);
806 if Pl
= nil then Exit
;
811 if not g_Console_CommandBlacklisted(Command
) then
812 g_Game_StartVote(Command
, Name
);
814 else if gVoteInProgress
then
816 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
817 Need
:= Floor((NetClientCount
+1)/2.0) + 1
819 Need
:= Floor(NetClientCount
/2.0) + 1;
824 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
825 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
831 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
832 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
840 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
842 function sendItemRespawn (it
: PItem
): Boolean;
844 result
:= false; // don't stop
845 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
848 function sendMonSpawn (mon
: TMonster
): Boolean;
850 result
:= false; // don't stop
851 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
854 function sendPanelState (pan
: TPanel
): Boolean;
856 result
:= false; // don't stop
857 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
858 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
864 if (ID
>= 0) and (ID
< length(NetClients
)) then
866 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
867 MH_ProcessFirstSpawn(@NetClients
[ID
]);
870 if gPlayers
<> nil then
872 for I
:= Low(gPlayers
) to High(gPlayers
) do
874 if gPlayers
[I
] <> nil then
876 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
877 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
878 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
880 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
882 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
888 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
889 g_Mons_ForEach(sendMonSpawn
);
890 g_Map_ForEachPanel(sendPanelState
);
892 if gTriggers
<> nil then
894 for I
:= Low(gTriggers
) to High(gTriggers
) do
896 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
898 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
905 for I
:= Low(Shots
) to High(Shots
) do
907 if Shots
[i
].ShotType
in [6, 7, 8] then
909 MH_SEND_CreateShot(i
, ID
);
914 MH_SEND_TriggerMusic(ID
);
916 MH_SEND_GameStats(ID
);
917 MH_SEND_CoopStats(ID
);
919 if gGameSettings
.GameMode
= GM_CTF
then
921 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
922 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
925 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
930 procedure MH_SEND_Info(ID
: Byte);
934 NetOut
.Write(Byte(NET_MSG_INFO
));
936 NetOut
.Write(NetClients
[ID
].Player
);
937 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
938 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
939 NetOut
.Write(gWADHash
);
940 NetOut
.Write(gGameSettings
.GameMode
);
941 NetOut
.Write(gGameSettings
.GoalLimit
);
942 NetOut
.Write(gGameSettings
.TimeLimit
);
943 NetOut
.Write(gGameSettings
.MaxLives
);
944 NetOut
.Write(gGameSettings
.Options
);
947 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
950 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
956 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
957 Mode
:= NET_CHAT_PLAYER
;
960 if (Mode
= NET_CHAT_TEAM
) then
962 for i
:= Low(gPlayers
) to High(gPlayers
) do
963 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
964 (gPlayers
[i
].Team
= ID
) then
966 NetOut
.Write(Byte(NET_MSG_CHAT
));
969 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
976 NetOut
.Write(Byte(NET_MSG_CHAT
));
979 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
982 if Mode
= NET_CHAT_SYSTEM
then
985 if ID
= NET_EVERYONE
then
987 if Mode
= NET_CHAT_PLAYER
then
989 g_Console_Add(Txt
, True);
990 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
991 g_Game_ChatSound(b_Text_Unformat(Txt
));
994 if Mode
= NET_CHAT_TEAM
then
995 if gPlayer1
<> nil then
997 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
999 g_Console_Add(#18'[Team] '#2 + Txt
, True);
1000 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1001 g_Game_ChatSound(b_Text_Unformat(Txt
));
1003 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
1005 g_Console_Add(#20'[Team] '#2 + Txt
, True);
1006 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1007 g_Game_ChatSound(b_Text_Unformat(Txt
));
1013 Name
:= g_Net_ClientName_ByID(ID
);
1014 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1015 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1016 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1020 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1022 NetOut
.Write(Byte(NET_MSG_GFX
));
1028 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1031 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1033 NetOut
.Write(Byte(NET_MSG_SND
));
1037 NetOut
.Write(Byte(1));
1042 NetOut
.Write(Byte(0));
1044 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1047 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1049 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1051 NetOut
.Write(Byte(NET_MSG_SHADD
));
1053 NetOut
.Write(Shots
[Proj
].ShotType
);
1054 NetOut
.Write(Shots
[Proj
].Target
);
1055 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1056 NetOut
.Write(Shots
[Proj
].Timeout
);
1057 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1058 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1059 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1060 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1062 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1065 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1067 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1069 NetOut
.Write(Byte(NET_MSG_SHPOS
));
1071 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1072 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1073 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1074 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1076 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
1079 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1081 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1083 NetOut
.Write(Byte(Loud
));
1087 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1090 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1092 NetOut
.Write(Byte(NET_MSG_SCORE
));
1093 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1095 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1096 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1099 if gGameSettings
.GameMode
= GM_COOP
then
1101 NetOut
.Write(gCoopMonstersKilled
);
1102 NetOut
.Write(gCoopSecretsFound
);
1105 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1108 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1110 NetOut
.Write(Byte(NET_MSG_COOP
));
1111 NetOut
.Write(gTotalMonsters
);
1112 NetOut
.Write(gSecretsCount
);
1113 NetOut
.Write(gCoopTotalMonstersKilled
);
1114 NetOut
.Write(gCoopTotalSecretsFound
);
1115 NetOut
.Write(gCoopTotalMonsters
);
1116 NetOut
.Write(gCoopTotalSecrets
);
1119 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1121 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1122 NetOut
.Write(EvType
);
1123 NetOut
.Write(EvNum
);
1124 NetOut
.Write(EvStr
);
1125 NetOut
.Write(Byte(gLastMap
));
1126 NetOut
.Write(gTime
);
1127 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1129 NetOut
.Write(Byte(1));
1130 NetOut
.Write(gWADHash
);
1132 NetOut
.Write(Byte(0));
1134 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1137 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1139 NetOut
.Write(Byte(NET_MSG_FLAG
));
1140 NetOut
.Write(EvType
);
1142 NetOut
.Write(Byte(Quiet
));
1144 NetOut
.Write(gFlags
[Flag
].State
);
1145 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1146 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1147 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1148 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1149 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1150 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1152 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1155 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1157 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1159 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1160 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1161 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1162 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1164 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1167 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1169 NetOut
.Write(Byte(NET_MSG_GSET
));
1170 NetOut
.Write(gGameSettings
.GameMode
);
1171 NetOut
.Write(gGameSettings
.GoalLimit
);
1172 NetOut
.Write(gGameSettings
.TimeLimit
);
1173 NetOut
.Write(gGameSettings
.MaxLives
);
1174 NetOut
.Write(gGameSettings
.Options
);
1176 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1181 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1185 P
:= g_Player_Get(PID
);
1186 if P
= nil then Exit
;
1188 NetOut
.Write(Byte(NET_MSG_PLR
));
1190 NetOut
.Write(P
.Name
);
1192 NetOut
.Write(P
.FActualModelName
);
1193 NetOut
.Write(P
.FColor
.R
);
1194 NetOut
.Write(P
.FColor
.G
);
1195 NetOut
.Write(P
.FColor
.B
);
1196 NetOut
.Write(P
.Team
);
1198 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1201 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1206 Pl
:= g_Player_Get(PID
);
1207 if Pl
= nil then Exit
;
1208 if Pl
.FDummy
then Exit
;
1210 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1211 NetOut
.Write(gTime
);
1218 NetOut
.Write(FPing
);
1219 NetOut
.Write(FLoss
);
1220 if IsKeyPressed(KEY_CHAT
) then
1221 kByte
:= NET_KEY_CHAT
1224 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1225 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1226 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1227 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1228 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1231 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1233 NetOut
.Write(kByte
);
1234 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1235 NetOut
.Write(GameX
);
1236 NetOut
.Write(GameY
);
1237 NetOut
.Write(GameVelX
);
1238 NetOut
.Write(GameVelY
);
1239 NetOut
.Write(GameAccelX
);
1240 NetOut
.Write(GameAccelY
);
1243 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1246 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1251 P
:= g_Player_Get(PID
);
1252 if P
= nil then Exit
;
1254 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1259 NetOut
.Write(Byte(alive
));
1260 NetOut
.Write(Byte(GodMode
));
1261 NetOut
.Write(Health
);
1262 NetOut
.Write(Armor
);
1264 NetOut
.Write(JetFuel
);
1265 NetOut
.Write(Lives
);
1268 for I
:= WP_FIRST
to WP_LAST
do
1269 NetOut
.Write(Byte(FWeapon
[I
]));
1271 for I
:= A_BULLETS
to A_HIGH
do
1272 NetOut
.Write(FAmmo
[I
]);
1274 for I
:= A_BULLETS
to A_HIGH
do
1275 NetOut
.Write(FMaxAmmo
[I
]);
1277 for I
:= MR_SUIT
to MR_MAX
do
1278 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1280 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1281 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1282 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1283 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1284 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1286 NetOut
.Write(Frags
);
1287 NetOut
.Write(Death
);
1289 NetOut
.Write(CurrWeap
);
1291 NetOut
.Write(Byte(FSpectator
));
1292 NetOut
.Write(Byte(FGhost
));
1293 NetOut
.Write(Byte(FPhysics
));
1294 NetOut
.Write(Byte(FNoRespawn
));
1295 NetOut
.Write(Byte(FJetpack
));
1296 NetOut
.Write(FFireTime
);
1297 NetOut
.Write(Byte(FFlaming
));
1298 NetOut
.Write(FSpawnInvul
);
1301 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1304 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1306 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1309 NetOut
.Write(Attacker
);
1310 NetOut
.Write(Value
);
1314 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1317 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1319 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1321 NetOut
.Write(KillType
);
1322 NetOut
.Write(DeathType
);
1323 NetOut
.Write(Attacker
);
1325 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1328 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1330 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1332 NetOut
.Write(Weapon
);
1337 NetOut
.Write(ShotID
);
1339 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1342 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1344 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1347 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1350 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1354 Pl
:= g_Player_Get(PID
);
1355 if Pl
= nil then Exit
;
1357 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1359 NetOut
.Write(Pl
.Name
);
1361 NetOut
.Write(Pl
.Model
.Name
)
1364 NetOut
.Write(Pl
.FColor
.R
);
1365 NetOut
.Write(Pl
.FColor
.G
);
1366 NetOut
.Write(Pl
.FColor
.B
);
1367 NetOut
.Write(Pl
.Team
);
1369 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1374 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1379 it
:= g_Items_ByIdx(IID
);
1381 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1383 NetOut
.Write(Byte(Quiet
));
1385 if it
.dropped
then tt
:= tt
or $80;
1387 NetOut
.Write(Byte(it
.Fall
));
1388 NetOut
.Write(Byte(it
.Respawnable
));
1389 NetOut
.Write(it
.Obj
.X
);
1390 NetOut
.Write(it
.Obj
.Y
);
1391 NetOut
.Write(it
.Obj
.Vel
.X
);
1392 NetOut
.Write(it
.Obj
.Vel
.Y
);
1394 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1397 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1399 NetOut
.Write(Byte(NET_MSG_IDEL
));
1401 NetOut
.Write(Byte(Quiet
));
1403 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1406 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1410 it
:= g_Items_ByIdx(IID
);
1412 NetOut
.Write(Byte(NET_MSG_IPOS
));
1414 NetOut
.Write(it
.Obj
.X
);
1415 NetOut
.Write(it
.Obj
.Y
);
1416 NetOut
.Write(it
.Obj
.Vel
.X
);
1417 NetOut
.Write(it
.Obj
.Vel
.Y
);
1419 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1424 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1428 TP
:= g_Map_PanelByGUID(PGUID
);
1429 if (TP
= nil) then exit
;
1433 NetOut
.Write(Byte(NET_MSG_PTEX
));
1434 NetOut
.Write(LongWord(PGUID
));
1435 NetOut
.Write(FCurTexture
);
1436 NetOut
.Write(FCurFrame
);
1437 NetOut
.Write(FCurFrameCount
);
1438 NetOut
.Write(AnimLoop
);
1441 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1444 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1449 TP
:= g_Map_PanelByGUID(PGUID
);
1450 if (TP
= nil) then exit
;
1452 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1453 NetOut
.Write(LongWord(PGUID
));
1454 NetOut
.Write(Byte(TP
.Enabled
));
1455 NetOut
.Write(TP
.LiftType
);
1458 NetOut
.Write(Word(TP
.Width
));
1459 NetOut
.Write(Word(TP
.Height
));
1461 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1462 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1463 NetOut
.Write(LongInt(TP
.movingStartX
));
1464 NetOut
.Write(LongInt(TP
.movingStartY
));
1465 NetOut
.Write(LongInt(TP
.movingEndX
));
1466 NetOut
.Write(LongInt(TP
.movingEndY
));
1467 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1468 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1469 NetOut
.Write(LongInt(TP
.sizeEndX
));
1470 NetOut
.Write(LongInt(TP
.sizeEndY
));
1471 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1472 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1473 NetOut
.Write(Byte(mpflags
));
1475 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1480 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1482 if gTriggers
= nil then Exit
;
1483 if T
.Sound
= nil then Exit
;
1485 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1486 NetOut
.Write(T
.ClientID
);
1487 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1488 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1489 NetOut
.Write(T
.SoundPlayCount
);
1491 g_Net_Host_Send(ID
, True);
1494 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1496 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1497 NetOut
.Write(gMusic
.Name
);
1498 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1499 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1500 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1502 g_Net_Host_Send(ID
, True);
1507 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1511 M
:= g_Monsters_ByUID(UID
);
1517 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1519 NetOut
.Write(MonsterType
);
1520 NetOut
.Write(MonsterState
);
1521 NetOut
.Write(MonsterAnim
);
1522 NetOut
.Write(MonsterTargetUID
);
1523 NetOut
.Write(MonsterTargetTime
);
1524 NetOut
.Write(MonsterBehaviour
);
1525 NetOut
.Write(MonsterSleep
);
1526 NetOut
.Write(MonsterHealth
);
1527 NetOut
.Write(MonsterAmmo
);
1528 NetOut
.Write(GameX
);
1529 NetOut
.Write(GameY
);
1530 NetOut
.Write(GameVelX
);
1531 NetOut
.Write(GameVelY
);
1532 NetOut
.Write(Byte(GameDirection
));
1535 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1538 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1542 M
:= g_Monsters_ByUID(UID
);
1543 if M
= nil then Exit
;
1545 NetOut
.Write(Byte(NET_MSG_MPOS
));
1550 NetOut
.Write(GameX
);
1551 NetOut
.Write(GameY
);
1552 NetOut
.Write(GameVelX
);
1553 NetOut
.Write(GameVelY
);
1554 NetOut
.Write(Byte(GameDirection
));
1557 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1560 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1564 M
:= g_Monsters_ByUID(UID
);
1565 if M
= nil then Exit
;
1567 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1572 NetOut
.Write(MonsterState
);
1573 NetOut
.Write(ForcedAnim
);
1574 NetOut
.Write(MonsterTargetUID
);
1575 NetOut
.Write(MonsterTargetTime
);
1576 NetOut
.Write(MonsterSleep
);
1577 NetOut
.Write(MonsterHealth
);
1578 NetOut
.Write(MonsterAmmo
);
1579 NetOut
.Write(MonsterPain
);
1580 NetOut
.Write(Byte(AnimIsReverse
));
1581 NetOut
.Write(FFireTime
);
1584 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1587 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1589 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1596 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1599 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1603 M
:= g_Monsters_ByUID(UID
);
1604 if M
= nil then Exit
;
1606 NetOut
.Write(Byte(NET_MSG_MDEL
));
1609 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1614 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1616 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1619 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1622 procedure MH_SEND_VoteEvent(EvType
: Byte;
1623 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1624 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1625 ID
: Integer = NET_EVERYONE
);
1627 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1628 NetOut
.Write(EvType
);
1629 NetOut
.Write(IntArg1
);
1630 NetOut
.Write(IntArg2
);
1631 NetOut
.Write(StrArg1
);
1632 NetOut
.Write(StrArg2
);
1634 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1637 // CLIENT MESSAGES //
1641 procedure MC_RECV_Chat(var M
: TMsg
);
1646 Txt
:= M
.ReadString();
1647 Mode
:= M
.ReadByte();
1649 if Mode
<> NET_CHAT_SYSTEM
then
1651 if NetDeafLevel
= 0 then
1653 if Mode
= NET_CHAT_PLAYER
then
1655 g_Console_Add(Txt
, True);
1656 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1657 g_Game_ChatSound(b_Text_Unformat(Txt
));
1659 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1661 if gPlayer1
.Team
= TEAM_RED
then
1662 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1663 if gPlayer1
.Team
= TEAM_BLUE
then
1664 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1665 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1666 g_Game_ChatSound(b_Text_Unformat(Txt
));
1669 end else if (NetDeafLevel
< 2) then
1670 g_Console_Add(Txt
, True);
1673 procedure MC_RECV_Effect(var M
: TMsg
);
1681 if not gGameOn
then Exit
;
1682 Kind
:= M
.ReadByte();
1683 X
:= M
.ReadLongInt();
1684 Y
:= M
.ReadLongInt();
1685 Ang
:= M
.ReadSmallInt();
1689 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1693 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1695 Anim
:= TAnimation
.Create(ID
, False, 3);
1696 g_GFX_OnceAnim(X
, Y
, Anim
);
1700 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1705 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1707 Anim
:= TAnimation
.Create(ID
, False, 6);
1708 Anim
.Blending
:= False;
1709 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1713 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1718 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1720 Anim
:= TAnimation
.Create(ID
, False, 6);
1721 Anim
.Blending
:= False;
1722 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1726 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1731 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1733 Anim
:= TAnimation
.Create(ID
, False, 4);
1734 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1741 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1743 Anim
:= TAnimation
.Create(ID
, False, 4);
1744 g_GFX_OnceAnim(X
, Y
, Anim
);
1748 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1753 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1755 Anim
:= TAnimation
.Create(ID
, False, 4);
1756 g_GFX_OnceAnim(X
, Y
, Anim
);
1760 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1764 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1767 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1771 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1772 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1777 procedure MC_RECV_Sound(var M
: TMsg
);
1783 Name
:= M
.ReadString();
1784 Pos
:= M
.ReadByte() <> 0;
1787 X
:= M
.ReadLongInt();
1788 Y
:= M
.ReadLongInt();
1789 g_Sound_PlayExAt(Name
, X
, Y
);
1792 g_Sound_PlayEx(Name
);
1795 procedure MC_RECV_CreateShot(var M
: TMsg
);
1797 I
, X
, Y
, XV
, YV
: Integer;
1799 Target
, Spawner
: Word;
1802 I
:= M
.ReadLongInt();
1803 ShType
:= M
.ReadByte();
1804 Target
:= M
.ReadWord();
1805 Spawner
:= M
.ReadWord();
1806 Timeout
:= M
.ReadLongWord();
1807 X
:= M
.ReadLongInt();
1808 Y
:= M
.ReadLongInt();
1809 XV
:= M
.ReadLongInt();
1810 YV
:= M
.ReadLongInt();
1812 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1813 if (Shots
<> nil) and (I
<= High(Shots
)) then
1815 Shots
[I
].Timeout
:= Timeout
;
1816 //Shots[I].Target := Target; // TODO: find a use for Target later
1820 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1822 I
, TX
, TY
, TXV
, TYV
: Integer;
1824 I
:= M
.ReadLongInt();
1825 TX
:= M
.ReadLongInt();
1826 TY
:= M
.ReadLongInt();
1827 TXV
:= M
.ReadLongInt();
1828 TYV
:= M
.ReadLongInt();
1830 if (Shots
<> nil) and (I
<= High(Shots
)) then
1840 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1845 if not gGameOn
then Exit
;
1846 I
:= M
.ReadLongInt();
1847 L
:= (M
.ReadByte() <> 0);
1848 X
:= M
.ReadLongInt();
1849 Y
:= M
.ReadLongInt();
1851 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1854 procedure MC_RECV_GameStats(var M
: TMsg
);
1856 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1858 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1859 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1862 if gGameSettings
.GameMode
= GM_COOP
then
1864 gCoopMonstersKilled
:= M
.ReadWord();
1865 gCoopSecretsFound
:= M
.ReadWord();
1869 procedure MC_RECV_CoopStats(var M
: TMsg
);
1871 gTotalMonsters
:= M
.ReadLongInt();
1872 gSecretsCount
:= M
.ReadLongInt();
1873 gCoopTotalMonstersKilled
:= M
.ReadWord();
1874 gCoopTotalSecretsFound
:= M
.ReadWord();
1875 gCoopTotalMonsters
:= M
.ReadWord();
1876 gCoopTotalSecrets
:= M
.ReadWord();
1879 procedure MC_RECV_GameEvent(var M
: TMsg
);
1888 i1
, i2
: TStrings_Locale
;
1891 goodCmd
: Boolean = true;
1893 FillChar(EvHash
, Sizeof(EvHash
), 0);
1894 EvType
:= M
.ReadByte();
1895 EvNum
:= M
.ReadLongInt();
1896 EvStr
:= M
.ReadString();
1897 gLastMap
:= M
.ReadByte() <> 0;
1898 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1899 gStatsPressed
:= True;
1900 EvTime
:= M
.ReadLongWord();
1901 BHash
:= M
.ReadByte() <> 0;
1903 EvHash
:= M
.ReadMD5();
1907 if (g_Res_received_map_start
<> 0) then
1909 if (g_Res_received_map_start
< 0) then exit
;
1912 NET_EV_MAPSTART
: goodCmd
:= true;
1913 NET_EV_MAPEND
: goodCmd
:= true;
1914 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1915 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1916 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1918 if not goodCmd
then exit
;
1924 if (g_Res_received_map_start
<> 0) then
1926 g_Res_received_map_start
:= -1;
1931 g_Game_ClearLoading();
1932 g_Game_StopAllSounds(True);
1934 gSwitchGameMode
:= Byte(EvNum
);
1935 gGameSettings
.GameMode
:= gSwitchGameMode
;
1938 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1940 if not isWadPath(EvStr
) then
1941 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1943 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1947 MC_SEND_FullStateRequest
;
1953 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1954 gLMSRespawnTime
:= 0;
1955 if (g_Res_received_map_start
<> 0) then
1957 g_Res_received_map_start
:= -1;
1961 gMissionFailed
:= EvNum
<> 0;
1962 gExit
:= EXIT_ENDLEVELCUSTOM
;
1970 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1972 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1974 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1980 if NetDeafLevel
< 2 then
1982 if EvNum
= TEAM_RED
then
1983 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1984 if EvNum
= TEAM_BLUE
then
1985 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1991 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1992 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1997 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1998 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2005 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
2006 gLMSRespawnTime
:= gTime
+ EvNum
;
2007 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2009 else if gPlayer1
= nil then
2011 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2015 NET_EV_LMS_SURVIVOR
:
2016 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2019 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2023 pl
:= g_Player_Get(EvNum
and $FFFF);
2028 cnt
:= (EvNum
shr 16) and $FF;
2029 if Pos('w', EvStr
) = 0 then
2032 if Pos('t', EvStr
) = 0 then
2035 if Pos('-', EvStr
) = 0 then
2037 if Pos('e', EvStr
) = 0 then
2038 i1
:= I_PLAYER_SCORE_ADD_OWN
2040 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2043 if Pos('e', EvStr
) = 0 then
2044 i1
:= I_PLAYER_SCORE_SUB_OWN
2046 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2049 if Pos('r', EvStr
) > 0 then
2050 i2
:= I_PLAYER_SCORE_TO_RED
2052 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2053 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2057 if Pos('-', EvStr
) = 0 then
2058 i1
:= I_PLAYER_SCORE_ADD_TEAM
2060 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2062 if Pos('r', EvStr
) > 0 then
2063 i2
:= I_PLAYER_SCORE_RED
2065 i2
:= I_PLAYER_SCORE_BLUE
;
2066 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2071 if Pos('e', EvStr
) = 0 then
2072 i1
:= I_PLAYER_SCORE_WIN_OWN
2074 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
2076 if Pos('r', EvStr
) > 0 then
2077 i2
:= I_PLAYER_SCORE_TO_RED
2079 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2080 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
2086 if EvNum
= TEAM_RED
then
2087 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2088 if EvNum
= TEAM_BLUE
then
2089 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2090 if EvNum
= -TEAM_RED
then
2091 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2092 if EvNum
= -TEAM_BLUE
then
2093 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2098 g_Player_RemoveAllCorpses
;
2099 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2100 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2104 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2108 if EvNum
= TEAM_RED
then
2109 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2110 if EvNum
= TEAM_BLUE
then
2111 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2115 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2118 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2121 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2124 g_Game_Announce_KillCombo(EvNum
);
2126 NET_EV_PLAYER_TOUCH
:
2128 pl
:= g_Player_Get(EvNum
);
2135 pl
:= g_Player_Get(EvNum
);
2138 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2139 g_Sound_PlayEx('SOUND_GAME_SECRET');
2145 pl
:= g_Player_Get(EvNum
);
2146 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2151 procedure MC_RECV_FlagPos(var M
: TMsg
);
2156 if Fl
= FLAG_NONE
then Exit
;
2157 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2158 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2159 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2160 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2163 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2172 EvType
:= M
.ReadByte();
2175 if Fl
= FLAG_NONE
then Exit
;
2177 Quiet
:= (M
.ReadByte() <> 0);
2178 PID
:= M
.ReadWord();
2180 gFlags
[Fl
].State
:= M
.ReadByte();
2181 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2182 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2183 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2184 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2185 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2186 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2188 Pl
:= g_Player_Get(PID
);
2190 (EvType
<> FLAG_STATE_NORMAL
) and
2191 (EvType
<> FLAG_STATE_DROPPED
) and
2192 (EvType
<> FLAG_STATE_RETURNED
) then
2198 if Quiet
or (Pl
= nil) then Exit
;
2200 if Fl
= FLAG_RED
then
2201 s
:= _lc
[I_PLAYER_FLAG_RED
]
2203 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2205 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2207 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2208 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2209 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2214 if not sound_ret_flag
[a
].IsPlaying() then
2215 sound_ret_flag
[a
].Play();
2218 FLAG_STATE_CAPTURED
:
2220 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2224 if Fl
= FLAG_RED
then
2225 s
:= _lc
[I_PLAYER_FLAG_RED
]
2227 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2229 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2230 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2232 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2233 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2234 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2239 if not sound_get_flag
[a
].IsPlaying() then
2240 sound_get_flag
[a
].Play();
2245 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2247 if Quiet
or (Pl
= nil) then Exit
;
2249 if Fl
= FLAG_RED
then
2250 s
:= _lc
[I_PLAYER_FLAG_RED
]
2252 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2254 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2255 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2257 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2258 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2259 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2264 if not sound_lost_flag
[a
].IsPlaying() then
2265 sound_lost_flag
[a
].Play();
2270 g_Map_ResetFlag(FLAG_RED
);
2271 g_Map_ResetFlag(FLAG_BLUE
);
2272 if Quiet
or (Pl
= nil) then Exit
;
2273 Pl
.SetFlag(FLAG_NONE
);
2275 if Fl
= FLAG_RED
then
2276 s
:= _lc
[I_PLAYER_FLAG_RED
]
2278 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2280 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2281 Insert('.', ts
, Length(ts
) + 1 - 3);
2282 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2283 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2285 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2286 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2287 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2292 if not sound_cap_flag
[a
].IsPlaying() then
2293 sound_cap_flag
[a
].Play();
2296 FLAG_STATE_RETURNED
:
2298 g_Map_ResetFlag(Fl
);
2301 if Fl
= FLAG_RED
then
2302 s
:= _lc
[I_PLAYER_FLAG_RED
]
2304 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2306 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2308 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2309 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2310 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2315 if not sound_ret_flag
[a
].IsPlaying() then
2316 sound_ret_flag
[a
].Play();
2321 procedure MC_RECV_GameSettings(var M
: TMsg
);
2323 gGameSettings
.GameMode
:= M
.ReadByte();
2324 gGameSettings
.GoalLimit
:= M
.ReadWord();
2325 gGameSettings
.TimeLimit
:= M
.ReadWord();
2326 gGameSettings
.MaxLives
:= M
.ReadByte();
2327 gGameSettings
.Options
:= M
.ReadLongWord();
2332 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2335 PName
, Model
: string;
2340 PID
:= M
.ReadWord();
2341 Pl
:= g_Player_Get(PID
);
2343 PName
:= M
.ReadString();
2344 Model
:= M
.ReadString();
2345 Color
.R
:= M
.ReadByte();
2346 Color
.G
:= M
.ReadByte();
2347 Color
.B
:= M
.ReadByte();
2351 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2353 if (Pl
<> nil) then Exit
;
2354 DID
:= g_Player_Create(Model
, Color
, T
, False);
2355 with g_Player_Get(DID
) do
2364 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2365 gPlayer1
.UID
:= PID
;
2366 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2367 gPlayer1
.ChangeTeam(T
);
2369 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2370 gPlayer2
.UID
:= PID
;
2371 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2372 gPlayer2
.ChangeTeam(T
);
2376 if NetDeafLevel
< 3 then
2377 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2378 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2382 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2389 TmpX
, TmpY
: Integer;
2393 GT
:= M
.ReadLongWord();
2394 if GT
< gTime
- NET_MAX_DIFFTIME
then
2401 PID
:= M
.ReadWord();
2402 Pl
:= g_Player_Get(PID
);
2404 if Pl
= nil then Exit
;
2410 FPing
:= M
.ReadWord();
2411 FLoss
:= M
.ReadByte();
2412 kByte
:= M
.ReadWord();
2413 Dir
:= M
.ReadByte();
2415 TmpX
:= M
.ReadLongInt();
2416 TmpY
:= M
.ReadLongInt();
2420 if LongBool(kByte
and NET_KEY_CHAT
) then
2421 PressKey(KEY_CHAT
, 10000)
2424 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2425 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2426 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2427 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2428 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2431 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2433 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2434 SetDirection(TDirection(Dir
));
2436 GameVelX
:= M
.ReadLongInt();
2437 GameVelY
:= M
.ReadLongInt();
2438 GameAccelX
:= M
.ReadLongInt();
2439 GameAccelY
:= M
.ReadLongInt();
2440 SetLerp(TmpX
, TmpY
);
2441 if NetForcePlayerUpdate
then Update();
2445 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2449 I
, OldFire
: Integer;
2450 OldJet
, Flam
: Boolean;
2453 PID
:= M
.ReadWord();
2454 Pl
:= g_Player_Get(PID
);
2461 alive
:= (M
.ReadByte() <> 0);
2462 GodMode
:= (M
.ReadByte() <> 0);
2463 Health
:= M
.ReadLongInt();
2464 Armor
:= M
.ReadLongInt();
2465 Air
:= M
.ReadLongInt();
2466 JetFuel
:= M
.ReadLongInt();
2467 Lives
:= M
.ReadByte();
2468 NewTeam
:= M
.ReadByte();
2470 for I
:= WP_FIRST
to WP_LAST
do
2471 FWeapon
[I
] := (M
.ReadByte() <> 0);
2473 for I
:= A_BULLETS
to A_HIGH
do
2474 FAmmo
[I
] := M
.ReadWord();
2476 for I
:= A_BULLETS
to A_HIGH
do
2477 FMaxAmmo
[I
] := M
.ReadWord();
2479 for I
:= MR_SUIT
to MR_MAX
do
2480 FMegaRulez
[I
] := M
.ReadLongWord();
2483 if (M
.ReadByte() <> 0) then
2484 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2485 if (M
.ReadByte() <> 0) then
2486 FRulez
:= FRulez
+ [R_KEY_RED
];
2487 if (M
.ReadByte() <> 0) then
2488 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2489 if (M
.ReadByte() <> 0) then
2490 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2491 if (M
.ReadByte() <> 0) then
2492 FRulez
:= FRulez
+ [R_BERSERK
];
2494 Frags
:= M
.ReadLongInt();
2495 Death
:= M
.ReadLongInt();
2497 SetWeapon(M
.ReadByte());
2499 FSpectator
:= M
.ReadByte() <> 0;
2502 if UID
= NetPlrUID1
then
2504 gSpectLatchPID1
:= UID
;
2507 if UID
= NetPlrUID2
then
2509 gSpectLatchPID2
:= UID
;
2515 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2518 gSpectLatchPID1
:= 0;
2520 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2523 gSpectLatchPID2
:= 0;
2526 FGhost
:= M
.ReadByte() <> 0;
2527 FPhysics
:= M
.ReadByte() <> 0;
2528 FNoRespawn
:= M
.ReadByte() <> 0;
2530 FJetpack
:= M
.ReadByte() <> 0;
2531 OldFire
:= FFireTime
;
2532 FFireTime
:= M
.ReadLongInt();
2533 if (OldFire
<= 0) and (FFireTime
> 0) then
2534 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2535 Flam
:= M
.ReadByte() <> 0;
2536 FSpawnInvul
:= M
.ReadLongInt();
2537 if OldJet
and not FJetpack
then
2539 else if not OldJet
and FJetpack
then
2541 if FFlaming
and not Flam
then
2543 if Team
<> NewTeam
then
2544 Pl
.ChangeTeam(NewTeam
);
2550 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2555 Attacker
, Value
: Word;
2559 if not gGameOn
then Exit
;
2560 PID
:= M
.ReadWord();
2561 Pl
:= g_Player_Get(PID
);
2562 if Pl
= nil then Exit
;
2564 Kind
:= M
.ReadByte();
2565 Attacker
:= M
.ReadWord();
2566 Value
:= M
.ReadWord();
2571 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2576 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2580 KillType
, DeathType
: Byte;
2584 if not gGameOn
then Exit
;
2585 PID
:= M
.ReadWord();
2586 Pl
:= g_Player_Get(PID
);
2587 if Pl
= nil then Exit
;
2589 KillType
:= M
.ReadByte();
2590 DeathType
:= M
.ReadByte();
2591 Attacker
:= M
.ReadWord();
2595 Kill(KillType
, Attacker
, DeathType
);
2600 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2605 PID
:= M
.ReadWord();
2606 Pl
:= g_Player_Get(PID
);
2608 if Pl
= nil then Exit
;
2610 if NetDeafLevel
< 3 then
2611 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2612 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2614 g_Player_Remove(PID
);
2619 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2624 X
, Y
, AX
, AY
: Integer;
2628 if not gGameOn
then Exit
;
2629 PID
:= M
.ReadWord();
2630 Pl
:= g_Player_Get(PID
);
2631 if Pl
= nil then Exit
;
2633 Weap
:= M
.ReadByte();
2634 X
:= M
.ReadLongInt();
2635 Y
:= M
.ReadLongInt();
2636 AX
:= M
.ReadLongInt();
2637 AY
:= M
.ReadLongInt();
2638 SHID
:= M
.ReadLongInt();
2641 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2644 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2653 PID
:= M
.ReadWord();
2654 Pl
:= g_Player_Get(PID
);
2655 if Pl
= nil then Exit
;
2657 TmpName
:= M
.ReadString();
2658 TmpModel
:= M
.ReadString();
2659 TmpColor
.R
:= M
.ReadByte();
2660 TmpColor
.G
:= M
.ReadByte();
2661 TmpColor
.B
:= M
.ReadByte();
2662 TmpTeam
:= M
.ReadByte();
2664 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2666 Pl
.ChangeTeam(TmpTeam
);
2667 if gPlayer1
= Pl
then
2668 gPlayer1Settings
.Team
:= TmpTeam
;
2669 if gPlayer2
= Pl
then
2670 gPlayer2Settings
.Team
:= TmpTeam
;
2672 Pl
.SetColor(TmpColor
);
2674 if Pl
.Name
<> TmpName
then
2676 if NetDeafLevel
< 3 then
2677 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2681 if TmpModel
<> Pl
.Model
.Name
then
2682 Pl
.SetModel(TmpModel
);
2687 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2691 X
, Y
, VX
, VY
: Integer;
2693 Quiet
, Fall
{, Resp}: Boolean;
2697 if not gGameOn
then Exit
;
2699 Quiet
:= M
.ReadByte() <> 0;
2701 Fall
:= M
.ReadByte() <> 0;
2702 {Resp :=} M
.ReadByte();
2703 X
:= M
.ReadLongInt();
2704 Y
:= M
.ReadLongInt();
2705 VX
:= M
.ReadLongInt();
2706 VY
:= M
.ReadLongInt();
2708 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2709 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2711 it
:= g_Items_ByIdx(ID
);
2717 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2718 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2720 Anim
:= TAnimation
.Create(AID
, False, 4);
2721 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2727 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2732 if not gGameOn
then Exit
;
2734 Quiet
:= M
.ReadByte() <> 0;
2736 if not g_Items_ValidId(ID
) then exit
;
2738 if not Quiet
then g_Items_EmitPickupSound(ID
);
2743 procedure MC_RECV_ItemPos(var M
: TMsg
);
2746 X
, Y
, VX
, VY
: Integer;
2749 if not gGameOn
then Exit
;
2752 X
:= M
.ReadLongInt();
2753 Y
:= M
.ReadLongInt();
2754 VX
:= M
.ReadLongInt();
2755 VY
:= M
.ReadLongInt();
2757 if g_Items_ValidId(ID
) then
2759 it
:= g_Items_ByIdx(ID
);
2764 it
.positionChanged();
2770 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2777 if not gGameOn
then Exit
;
2779 PGUID
:= Integer(M
.ReadLongWord());
2780 Tex
:= M
.ReadLongInt();
2781 Fr
:= M
.ReadLongInt();
2782 Cnt
:= M
.ReadByte();
2783 Loop
:= M
.ReadByte();
2785 TP
:= g_Map_PanelByGUID(PGUID
);
2789 TP
.SetTexture(Tex
, Loop
);
2790 TP
.SetFrame(Fr
, Cnt
);
2794 procedure MC_RECV_PanelState(var M
: TMsg
);
2799 X
, Y
, W
, H
: Integer;
2801 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2802 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2805 if not gGameOn
then Exit
;
2807 PGUID
:= Integer(M
.ReadLongWord());
2808 E
:= (M
.ReadByte() <> 0);
2809 Lift
:= M
.ReadByte();
2810 X
:= M
.ReadLongInt();
2811 Y
:= M
.ReadLongInt();
2815 speedX
:= M
.ReadLongInt();
2816 speedY
:= M
.ReadLongInt();
2817 startX
:= M
.ReadLongInt();
2818 startY
:= M
.ReadLongInt();
2819 endX
:= M
.ReadLongInt();
2820 endY
:= M
.ReadLongInt();
2821 sizeSpX
:= M
.ReadLongInt();
2822 sizeSpY
:= M
.ReadLongInt();
2823 sizeEX
:= M
.ReadLongInt();
2824 sizeEY
:= M
.ReadLongInt();
2825 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2827 TP
:= g_Map_PanelByGUID(PGUID
);
2828 if (TP
= nil) then exit
;
2830 // update lifts state
2831 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2833 // update enabled/disabled state for all panels
2834 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2836 // update panel position, as it can be moved (mplat)
2841 // update mplat state
2842 TP
.movingSpeedX
:= speedX
;
2843 TP
.movingSpeedY
:= speedY
;
2844 TP
.movingStartX
:= startX
;
2845 TP
.movingStartY
:= startY
;
2846 TP
.movingEndX
:= endX
;
2847 TP
.movingEndY
:= endY
;
2848 TP
.sizeSpeedX
:= sizeSpX
;
2849 TP
.sizeSpeedY
:= sizeSpY
;
2850 TP
.sizeEndX
:= sizeEX
;
2851 TP
.sizeEndY
:= sizeEY
;
2852 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2853 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2854 // notify panel of it's position/size change, so it can fix other internal structures
2855 TP
.positionChanged();
2860 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2863 SPos
, SID
: LongWord;
2867 if not gGameOn
then Exit
;
2868 if gTriggers
= nil then Exit
;
2870 SID
:= M
.ReadLongWord();
2871 SPlaying
:= M
.ReadByte() <> 0;
2872 SPos
:= M
.ReadLongWord();
2873 SCount
:= M
.ReadLongInt();
2875 for I
:= Low(gTriggers
) to High(gTriggers
) do
2876 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2877 if gTriggers
[I
].ClientID
= SID
then
2878 with gTriggers
[I
] do
2880 if Sound
<> nil then
2885 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2887 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2888 Sound
.SetPosition(SPos
);
2891 if Sound
.IsPlaying
then Sound
.Stop
;
2894 SoundPlayCount
:= SCount
;
2898 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2905 if not gGameOn
then Exit
;
2907 MName
:= M
.ReadString();
2908 MPlaying
:= M
.ReadByte() <> 0;
2909 MPos
:= M
.ReadLongWord();
2910 MPaused
:= M
.ReadByte() <> 0;
2911 MPos
:= MPos
+1; //k8: stfu, fpc!
2915 gMusic
.SetByName(MName
);
2917 // gMusic.SetPosition(MPos);
2918 gMusic
.SpecPause
:= MPaused
;
2921 if gMusic
.IsPlaying
then gMusic
.Stop
;
2926 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2929 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2930 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2935 Mon
:= g_Monsters_ByUID(ID
);
2939 MType
:= M
.ReadByte();
2940 MState
:= M
.ReadByte();
2941 MAnim
:= M
.ReadByte();
2942 MTarg
:= M
.ReadWord();
2943 MTargTime
:= M
.ReadLongInt();
2944 MBehav
:= M
.ReadByte();
2945 MSleep
:= M
.ReadLongInt();
2946 MHealth
:= M
.ReadLongInt();
2947 MAmmo
:= M
.ReadLongInt();
2949 X
:= M
.ReadLongInt();
2950 Y
:= M
.ReadLongInt();
2951 VX
:= M
.ReadLongInt();
2952 VY
:= M
.ReadLongInt();
2953 MDir
:= M
.ReadByte();
2955 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2956 Mon
:= g_Monsters_ByUID(ID
);
2963 MonsterAnim
:= MAnim
;
2964 MonsterTargetUID
:= MTarg
;
2965 MonsterTargetTime
:= MTargTime
;
2966 MonsterBehaviour
:= MBehav
;
2967 MonsterSleep
:= MSleep
;
2968 MonsterAmmo
:= MAmmo
;
2973 setPosition(X
, Y
); // this will call positionChanged();
2979 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2986 Mon
:= g_Monsters_ByUID(ID
);
2992 X
:= M
.ReadLongInt();
2993 Y
:= M
.ReadLongInt();
2994 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2995 GameVelX
:= M
.ReadLongInt();
2996 GameVelY
:= M
.ReadLongInt();
2997 GameDirection
:= TDirection(M
.ReadByte());
3001 procedure MC_RECV_MonsterState(var M
: TMsg
);
3003 ID
, OldFire
: Integer;
3004 MState
, MFAnm
: Byte;
3006 AnimRevert
: Boolean;
3009 Mon
:= g_Monsters_ByUID(ID
);
3010 if Mon
= nil then Exit
;
3012 MState
:= M
.ReadByte();
3013 MFAnm
:= M
.ReadByte();
3017 MonsterTargetUID
:= M
.ReadWord();
3018 MonsterTargetTime
:= M
.ReadLongInt();
3019 MonsterSleep
:= M
.ReadLongInt();
3020 MonsterHealth
:= M
.ReadLongInt();
3021 MonsterAmmo
:= M
.ReadLongInt();
3022 MonsterPain
:= M
.ReadLongInt();
3023 AnimRevert
:= M
.ReadByte() <> 0;
3024 OldFire
:= FFireTime
;
3025 FFireTime
:= M
.ReadLongInt();
3026 if (OldFire
<= 0) and (FFireTime
> 0) then
3027 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3028 RevertAnim(AnimRevert
);
3030 if MonsterState
<> MState
then
3032 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3033 if (MState
= MONSTATE_DIE
) then DieSound();
3034 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3035 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3036 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3038 SetState(MState
, MFAnm
);
3043 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3047 X
, Y
, VX
, VY
: Integer;
3051 Mon
:= g_Monsters_ByUID(ID
);
3052 if Mon
= nil then Exit
;
3054 X
:= M
.ReadLongInt();
3055 Y
:= M
.ReadLongInt();
3056 VX
:= M
.ReadLongInt();
3057 VY
:= M
.ReadLongInt();
3059 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3062 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3068 Mon
:= g_Monsters_ByUID(ID
);
3069 if Mon
= nil then Exit
;
3071 Mon
.MonsterRemoved
:= True;
3074 procedure MC_RECV_TimeSync(var M
: TMsg
);
3078 Time
:= M
.ReadLongWord();
3080 if gState
= STATE_INTERCUSTOM
then
3081 gServInterTime
:= Min(Time
, 255);
3084 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3088 Int1
, Int2
: SmallInt;
3090 EvID
:= M
.ReadByte();
3091 Int1
:= M
.ReadSmallInt();
3092 Int2
:= M
.ReadSmallInt();
3093 Str1
:= M
.ReadString();
3094 Str2
:= M
.ReadString();
3096 if NetDeafLevel
< 2 then
3099 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3101 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3103 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3105 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3107 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3113 procedure MC_SEND_Info(Password
: string);
3117 NetOut
.Write(Byte(NET_MSG_INFO
));
3118 NetOut
.Write(GAME_VERSION
);
3119 NetOut
.Write(Password
);
3120 NetOut
.Write(gPlayer1Settings
.Name
);
3121 NetOut
.Write(gPlayer1Settings
.Model
);
3122 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3123 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3124 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3125 NetOut
.Write(gPlayer1Settings
.Team
);
3127 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3130 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3132 NetOut
.Write(Byte(NET_MSG_CHAT
));
3136 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3139 procedure MC_SEND_PlayerPos();
3144 WeaponAct
: Byte = 0;
3145 WeaponSelect
: Word = 0;
3148 if not gGameOn
then Exit
;
3149 if gPlayers
= nil then Exit
;
3150 if gPlayer1
= nil then Exit
;
3153 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3155 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3157 strafeDir
:= P1MoveButton
shr 4;
3158 P1MoveButton
:= P1MoveButton
and $0F;
3160 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3162 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3164 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3168 if gPlayerAction
[0, ACTION_STRAFE
] then
3170 // new strafe mechanics
3171 if (strafeDir
= 0) then
3172 strafeDir
:= P1MoveButton
; // start strafing
3173 // now set direction according to strafe (reversed)
3174 if (strafeDir
= 2) then
3175 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3176 else if (strafeDir
= 1) then
3177 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3181 strafeDir
:= 0; // not strafing anymore
3182 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3183 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3184 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3185 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3186 else if P1MoveButton
<> 0 then
3187 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3190 gPlayer1
.ReleaseKeys
;
3191 if P1MoveButton
= 1 then
3193 kByte
:= kByte
or NET_KEY_LEFT
;
3194 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3196 if P1MoveButton
= 2 then
3198 kByte
:= kByte
or NET_KEY_RIGHT
;
3199 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3201 if gPlayerAction
[0, ACTION_LOOKUP
] then
3203 kByte
:= kByte
or NET_KEY_UP
;
3204 gPlayer1
.PressKey(KEY_UP
, 10000);
3206 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3208 kByte
:= kByte
or NET_KEY_DOWN
;
3209 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3211 if gPlayerAction
[0, ACTION_JUMP
] then
3213 kByte
:= kByte
or NET_KEY_JUMP
;
3214 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3216 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3217 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3219 for i
:= WP_FACT
to WP_LACT
do
3221 if gWeaponAction
[0, i
] then
3223 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3224 gWeaponAction
[0, i
] := False
3228 for i
:= WP_FIRST
to WP_LAST
do
3230 if gSelectWeapon
[0, i
] then
3232 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3233 gSelectWeapon
[0, i
] := False
3237 // fix movebutton state
3238 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3241 kByte
:= NET_KEY_CHAT
;
3243 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3244 NetOut
.Write(gTime
);
3245 NetOut
.Write(kByte
);
3246 NetOut
.Write(Byte(gPlayer1
.Direction
));
3247 NetOut
.Write(WeaponAct
);
3248 NetOut
.Write(WeaponSelect
);
3249 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3250 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3252 //kBytePrev := kByte;
3253 //kDirPrev := gPlayer1.Direction;
3256 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3258 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3259 NetOut
.Write(Byte(Start
));
3260 NetOut
.Write(Command
);
3261 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3264 procedure MC_SEND_PlayerSettings();
3266 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3267 NetOut
.Write(gPlayer1Settings
.Name
);
3268 NetOut
.Write(gPlayer1Settings
.Model
);
3269 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3270 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3271 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3272 NetOut
.Write(gPlayer1Settings
.Team
);
3274 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3277 procedure MC_SEND_FullStateRequest();
3279 NetOut
.Write(Byte(NET_MSG_REQFST
));
3281 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3284 procedure MC_SEND_CheatRequest(Kind
: Byte);
3286 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3289 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3291 procedure MC_SEND_RCONPassword(Password
: string);
3293 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3294 NetOut
.Write(Password
);
3296 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3298 procedure MC_SEND_RCONCommand(Cmd
: string);
3300 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3303 g_Net_Client_Send(True, NET_CHAN_SERVICE
);