84dbeaa360d7b89dcf8babfa9fb8bdeba02131d2
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
);
442 PID
:= g_Player_Create(Model
, Color
, T
, False);
443 with g_Player_Get(PID
) do
450 C
^.WaitForFirstSpawn
:= false;
452 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
453 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
454 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
458 with g_Player_Get(PID
) do
462 // round in progress, don't spawn
463 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
464 //e_LogWritefln('spawning player with pid #%u...', [PID]);
465 //Respawn(gGameSettings.GameType = GT_SINGLE);
466 //k8: no, do not spawn a player yet, wait for "request full state" packet
470 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
471 // that is, if we'll set it to `true`, the player can be spawned after
472 // warmup time ran out, for example, regardless of the real player state.
473 // also, this seems to work only for the initial connection. further
474 // map changes could initiate resource downloading, but the player will
475 // be spawned immediately.
476 // the proper solution will require another player state, "ephemeral".
477 // the player should start any map in "ephemeral" state, and turned into
478 // real mobj only when they sent a special "i am ready" packet. this packet
479 // must be sent after receiving the full state, so the player will get a full
480 // map view before going into game.
481 FWantsInGame
:= false;
482 C
^.WaitForFirstSpawn
:= true;
485 //if not C^.WaitForFirstSpawn then
487 for I
:= Low(NetClients
) to High(NetClients
) do
489 if NetClients
[I
].ID
= C
^.ID
then Continue
;
490 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
491 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
492 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
496 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
497 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
501 //g_Net_Slist_Update;
507 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
511 if not C
.WaitForFirstSpawn
then exit
;
512 plr
:= g_Player_Get(C
^.Player
);
513 if not assigned(plr
) then exit
;
514 g_Net_Slist_ServerPlayerComes();
515 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
516 C
.WaitForFirstSpawn
:= false;
517 plr
.FNoRespawn
:= false;
518 plr
.FWantsInGame
:= true; // TODO: look into this later
520 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
523 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
528 if gLMSRespawn
> LMS_RESPAWN_NONE
then
529 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
534 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
536 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
539 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
543 C
^.RequestedFullUpdate
:= True;
549 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
562 if not gGameOn
then Exit
;
565 GT
:= M
.ReadLongWord();
570 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
573 Pl
:= g_Player_Get(PID
);
577 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
583 kByte
:= M
.ReadWord();
585 WeaponAct
:= M
.ReadByte();
586 WeaponSelect
:= M
.ReadWord();
591 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
593 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
594 if Direction
<> TDirection(Dir
) then
595 JustTeleported
:= False;
597 SetDirection(TDirection(Dir
));
600 if kByte
= NET_KEY_CHAT
then
602 PressKey(KEY_CHAT
, 10000);
606 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
607 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
608 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
609 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
610 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
611 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
612 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
616 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
618 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
619 ProcessWeaponAction(i
);
625 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
627 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
628 QueueWeaponSwitch(i
);
633 // MH_SEND_PlayerPos(False, PID, C^.ID);
636 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
643 Pl
:= g_Player_Get(C
^.Player
);
644 if Pl
= nil then Exit
;
647 CheatKind
:= M
.ReadByte();
652 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
656 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
659 if Pl
.FSpectator
then
661 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
664 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
671 if gState
<> STATE_INTERCUSTOM
then Exit
;
672 Pl
.FReady
:= not Pl
.FReady
;
675 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
676 Inc(gInterReadyCount
);
680 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
681 Dec(gInterReadyCount
);
689 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
700 TmpName
:= M
.ReadString();
701 TmpModel
:= M
.ReadString();
702 TmpColor
.R
:= M
.ReadByte();
703 TmpColor
.G
:= M
.ReadByte();
704 TmpColor
.B
:= M
.ReadByte();
705 TmpTeam
:= M
.ReadByte();
710 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
712 Pl
:= g_Player_Get(C
^.Player
);
713 if Pl
= nil then Exit
;
715 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
718 Pl
.SetColor(TmpColor
);
720 if Pl
.Name
<> TmpName
then
722 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
726 if TmpModel
<> Pl
.Model
.Name
then
727 Pl
.SetModel(TmpModel
);
729 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
734 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
741 Pwd
:= M
.ReadString();
745 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
746 if not NetAllowRCON
then Exit
;
747 if Pwd
= NetRCONPassword
then
750 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
753 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
756 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
763 Cmd
:= M
.ReadString();
767 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
768 if not NetAllowRCON
then Exit
;
769 if not C
^.RCONAuth
then
771 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
774 g_Console_Process(Cmd
);
779 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
782 Name
, Command
: string;
789 Start
:= M
.ReadByte() <> 0;
790 Command
:= M
.ReadString();
795 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
797 Pl
:= g_Player_Get(C
^.Player
);
798 if Pl
= nil then Exit
;
803 if not g_Console_CommandBlacklisted(Command
) then
804 g_Game_StartVote(Command
, Name
);
806 else if gVoteInProgress
then
808 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
809 Need
:= Floor((NetClientCount
+1)/2.0) + 1
811 Need
:= Floor(NetClientCount
/2.0) + 1;
816 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
817 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
823 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
824 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
832 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
834 function sendItemRespawn (it
: PItem
): Boolean;
836 result
:= false; // don't stop
837 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
840 function sendMonSpawn (mon
: TMonster
): Boolean;
842 result
:= false; // don't stop
843 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
846 function sendPanelState (pan
: TPanel
): Boolean;
848 result
:= false; // don't stop
849 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
850 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
856 if (ID
>= 0) and (ID
< length(NetClients
)) then
858 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
859 MH_ProcessFirstSpawn(@NetClients
[ID
]);
862 if gPlayers
<> nil then
864 for I
:= Low(gPlayers
) to High(gPlayers
) do
866 if gPlayers
[I
] <> nil then
868 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
869 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
870 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
872 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
874 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
880 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
881 g_Mons_ForEach(sendMonSpawn
);
882 g_Map_ForEachPanel(sendPanelState
);
884 if gTriggers
<> nil then
886 for I
:= Low(gTriggers
) to High(gTriggers
) do
888 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
890 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
897 for I
:= Low(Shots
) to High(Shots
) do
899 if Shots
[i
].ShotType
in [6, 7, 8] then
901 MH_SEND_CreateShot(i
, ID
);
906 MH_SEND_TriggerMusic(ID
);
908 MH_SEND_GameStats(ID
);
909 MH_SEND_CoopStats(ID
);
911 if gGameSettings
.GameMode
= GM_CTF
then
913 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
914 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
917 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
922 procedure MH_SEND_Info(ID
: Byte);
926 NetOut
.Write(Byte(NET_MSG_INFO
));
928 NetOut
.Write(NetClients
[ID
].Player
);
929 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
930 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
931 NetOut
.Write(gWADHash
);
932 NetOut
.Write(gGameSettings
.GameMode
);
933 NetOut
.Write(gGameSettings
.GoalLimit
);
934 NetOut
.Write(gGameSettings
.TimeLimit
);
935 NetOut
.Write(gGameSettings
.MaxLives
);
936 NetOut
.Write(gGameSettings
.Options
);
939 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
942 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
948 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
949 Mode
:= NET_CHAT_PLAYER
;
952 if (Mode
= NET_CHAT_TEAM
) then
954 for i
:= Low(gPlayers
) to High(gPlayers
) do
955 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
956 (gPlayers
[i
].Team
= ID
) then
958 NetOut
.Write(Byte(NET_MSG_CHAT
));
961 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
968 NetOut
.Write(Byte(NET_MSG_CHAT
));
971 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
974 if Mode
= NET_CHAT_SYSTEM
then
977 if ID
= NET_EVERYONE
then
979 if Mode
= NET_CHAT_PLAYER
then
981 g_Console_Add(Txt
, True);
982 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
983 g_Game_ChatSound(b_Text_Unformat(Txt
));
986 if Mode
= NET_CHAT_TEAM
then
987 if gPlayer1
<> nil then
989 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
991 g_Console_Add(#18'[Team] '#2 + Txt
, True);
992 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
993 g_Game_ChatSound(b_Text_Unformat(Txt
));
995 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
997 g_Console_Add(#20'[Team] '#2 + Txt
, True);
998 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
999 g_Game_ChatSound(b_Text_Unformat(Txt
));
1005 Name
:= g_Net_ClientName_ByID(ID
);
1006 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1007 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1008 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1012 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1014 NetOut
.Write(Byte(NET_MSG_GFX
));
1020 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1023 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1025 NetOut
.Write(Byte(NET_MSG_SND
));
1029 NetOut
.Write(Byte(1));
1034 NetOut
.Write(Byte(0));
1036 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1039 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1041 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1043 NetOut
.Write(Byte(NET_MSG_SHADD
));
1045 NetOut
.Write(Shots
[Proj
].ShotType
);
1046 NetOut
.Write(Shots
[Proj
].Target
);
1047 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1048 NetOut
.Write(Shots
[Proj
].Timeout
);
1049 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1050 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1051 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1052 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1054 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1057 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1059 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1061 NetOut
.Write(Byte(NET_MSG_SHPOS
));
1063 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1064 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1065 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1066 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1068 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
1071 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1073 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1075 NetOut
.Write(Byte(Loud
));
1079 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1082 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1084 NetOut
.Write(Byte(NET_MSG_SCORE
));
1085 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1087 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1088 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1091 if gGameSettings
.GameMode
= GM_COOP
then
1093 NetOut
.Write(gCoopMonstersKilled
);
1094 NetOut
.Write(gCoopSecretsFound
);
1097 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1100 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1102 NetOut
.Write(Byte(NET_MSG_COOP
));
1103 NetOut
.Write(gTotalMonsters
);
1104 NetOut
.Write(gSecretsCount
);
1105 NetOut
.Write(gCoopTotalMonstersKilled
);
1106 NetOut
.Write(gCoopTotalSecretsFound
);
1107 NetOut
.Write(gCoopTotalMonsters
);
1108 NetOut
.Write(gCoopTotalSecrets
);
1111 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1113 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1114 NetOut
.Write(EvType
);
1115 NetOut
.Write(EvNum
);
1116 NetOut
.Write(EvStr
);
1117 NetOut
.Write(Byte(gLastMap
));
1118 NetOut
.Write(gTime
);
1119 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1121 NetOut
.Write(Byte(1));
1122 NetOut
.Write(gWADHash
);
1124 NetOut
.Write(Byte(0));
1126 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1129 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1131 NetOut
.Write(Byte(NET_MSG_FLAG
));
1132 NetOut
.Write(EvType
);
1134 NetOut
.Write(Byte(Quiet
));
1136 NetOut
.Write(gFlags
[Flag
].State
);
1137 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1138 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1139 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1140 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1141 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1142 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1144 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1147 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1149 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1151 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1152 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1153 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1154 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1156 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1159 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1161 NetOut
.Write(Byte(NET_MSG_GSET
));
1162 NetOut
.Write(gGameSettings
.GameMode
);
1163 NetOut
.Write(gGameSettings
.GoalLimit
);
1164 NetOut
.Write(gGameSettings
.TimeLimit
);
1165 NetOut
.Write(gGameSettings
.MaxLives
);
1166 NetOut
.Write(gGameSettings
.Options
);
1168 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1173 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1177 P
:= g_Player_Get(PID
);
1178 if P
= nil then Exit
;
1180 NetOut
.Write(Byte(NET_MSG_PLR
));
1182 NetOut
.Write(P
.Name
);
1184 NetOut
.Write(P
.FActualModelName
);
1185 NetOut
.Write(P
.FColor
.R
);
1186 NetOut
.Write(P
.FColor
.G
);
1187 NetOut
.Write(P
.FColor
.B
);
1188 NetOut
.Write(P
.Team
);
1190 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1193 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1198 Pl
:= g_Player_Get(PID
);
1199 if Pl
= nil then Exit
;
1200 if Pl
.FDummy
then Exit
;
1202 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1203 NetOut
.Write(gTime
);
1210 NetOut
.Write(FPing
);
1211 NetOut
.Write(FLoss
);
1212 if IsKeyPressed(KEY_CHAT
) then
1213 kByte
:= NET_KEY_CHAT
1216 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1217 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1218 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1219 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1220 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1223 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1225 NetOut
.Write(kByte
);
1226 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1227 NetOut
.Write(GameX
);
1228 NetOut
.Write(GameY
);
1229 NetOut
.Write(GameVelX
);
1230 NetOut
.Write(GameVelY
);
1231 NetOut
.Write(GameAccelX
);
1232 NetOut
.Write(GameAccelY
);
1235 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1238 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1243 P
:= g_Player_Get(PID
);
1244 if P
= nil then Exit
;
1246 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1251 NetOut
.Write(Byte(alive
));
1252 NetOut
.Write(Byte(GodMode
));
1253 NetOut
.Write(Health
);
1254 NetOut
.Write(Armor
);
1256 NetOut
.Write(JetFuel
);
1257 NetOut
.Write(Lives
);
1260 for I
:= WP_FIRST
to WP_LAST
do
1261 NetOut
.Write(Byte(FWeapon
[I
]));
1263 for I
:= A_BULLETS
to A_HIGH
do
1264 NetOut
.Write(FAmmo
[I
]);
1266 for I
:= A_BULLETS
to A_HIGH
do
1267 NetOut
.Write(FMaxAmmo
[I
]);
1269 for I
:= MR_SUIT
to MR_MAX
do
1270 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1272 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1273 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1274 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1275 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1276 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1278 NetOut
.Write(Frags
);
1279 NetOut
.Write(Death
);
1281 NetOut
.Write(CurrWeap
);
1283 NetOut
.Write(Byte(FSpectator
));
1284 NetOut
.Write(Byte(FGhost
));
1285 NetOut
.Write(Byte(FPhysics
));
1286 NetOut
.Write(Byte(FNoRespawn
));
1287 NetOut
.Write(Byte(FJetpack
));
1288 NetOut
.Write(FFireTime
);
1289 NetOut
.Write(Byte(FFlaming
));
1290 NetOut
.Write(FSpawnInvul
);
1293 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1296 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1298 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1301 NetOut
.Write(Attacker
);
1302 NetOut
.Write(Value
);
1306 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1309 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1311 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1313 NetOut
.Write(KillType
);
1314 NetOut
.Write(DeathType
);
1315 NetOut
.Write(Attacker
);
1317 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1320 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1322 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1324 NetOut
.Write(Weapon
);
1329 NetOut
.Write(ShotID
);
1331 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1334 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1336 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1339 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1342 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1346 Pl
:= g_Player_Get(PID
);
1347 if Pl
= nil then Exit
;
1349 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1351 NetOut
.Write(Pl
.Name
);
1353 NetOut
.Write(Pl
.Model
.Name
)
1356 NetOut
.Write(Pl
.FColor
.R
);
1357 NetOut
.Write(Pl
.FColor
.G
);
1358 NetOut
.Write(Pl
.FColor
.B
);
1359 NetOut
.Write(Pl
.Team
);
1361 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1366 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1371 it
:= g_Items_ByIdx(IID
);
1373 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1375 NetOut
.Write(Byte(Quiet
));
1377 if it
.dropped
then tt
:= tt
or $80;
1379 NetOut
.Write(Byte(it
.Fall
));
1380 NetOut
.Write(Byte(it
.Respawnable
));
1381 NetOut
.Write(it
.Obj
.X
);
1382 NetOut
.Write(it
.Obj
.Y
);
1383 NetOut
.Write(it
.Obj
.Vel
.X
);
1384 NetOut
.Write(it
.Obj
.Vel
.Y
);
1386 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1389 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1391 NetOut
.Write(Byte(NET_MSG_IDEL
));
1393 NetOut
.Write(Byte(Quiet
));
1395 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1398 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1402 it
:= g_Items_ByIdx(IID
);
1404 NetOut
.Write(Byte(NET_MSG_IPOS
));
1406 NetOut
.Write(it
.Obj
.X
);
1407 NetOut
.Write(it
.Obj
.Y
);
1408 NetOut
.Write(it
.Obj
.Vel
.X
);
1409 NetOut
.Write(it
.Obj
.Vel
.Y
);
1411 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1416 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1420 TP
:= g_Map_PanelByGUID(PGUID
);
1421 if (TP
= nil) then exit
;
1425 NetOut
.Write(Byte(NET_MSG_PTEX
));
1426 NetOut
.Write(LongWord(PGUID
));
1427 NetOut
.Write(FCurTexture
);
1428 NetOut
.Write(FCurFrame
);
1429 NetOut
.Write(FCurFrameCount
);
1430 NetOut
.Write(AnimLoop
);
1433 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1436 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1441 TP
:= g_Map_PanelByGUID(PGUID
);
1442 if (TP
= nil) then exit
;
1444 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1445 NetOut
.Write(LongWord(PGUID
));
1446 NetOut
.Write(Byte(TP
.Enabled
));
1447 NetOut
.Write(TP
.LiftType
);
1450 NetOut
.Write(Word(TP
.Width
));
1451 NetOut
.Write(Word(TP
.Height
));
1453 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1454 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1455 NetOut
.Write(LongInt(TP
.movingStartX
));
1456 NetOut
.Write(LongInt(TP
.movingStartY
));
1457 NetOut
.Write(LongInt(TP
.movingEndX
));
1458 NetOut
.Write(LongInt(TP
.movingEndY
));
1459 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1460 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1461 NetOut
.Write(LongInt(TP
.sizeEndX
));
1462 NetOut
.Write(LongInt(TP
.sizeEndY
));
1463 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1464 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1465 NetOut
.Write(Byte(mpflags
));
1467 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1472 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1474 if gTriggers
= nil then Exit
;
1475 if T
.Sound
= nil then Exit
;
1477 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1478 NetOut
.Write(T
.ClientID
);
1479 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1480 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1481 NetOut
.Write(T
.SoundPlayCount
);
1483 g_Net_Host_Send(ID
, True);
1486 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1488 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1489 NetOut
.Write(gMusic
.Name
);
1490 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1491 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1492 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1494 g_Net_Host_Send(ID
, True);
1499 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1503 M
:= g_Monsters_ByUID(UID
);
1509 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1511 NetOut
.Write(MonsterType
);
1512 NetOut
.Write(MonsterState
);
1513 NetOut
.Write(MonsterAnim
);
1514 NetOut
.Write(MonsterTargetUID
);
1515 NetOut
.Write(MonsterTargetTime
);
1516 NetOut
.Write(MonsterBehaviour
);
1517 NetOut
.Write(MonsterSleep
);
1518 NetOut
.Write(MonsterHealth
);
1519 NetOut
.Write(MonsterAmmo
);
1520 NetOut
.Write(GameX
);
1521 NetOut
.Write(GameY
);
1522 NetOut
.Write(GameVelX
);
1523 NetOut
.Write(GameVelY
);
1524 NetOut
.Write(Byte(GameDirection
));
1527 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1530 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1534 M
:= g_Monsters_ByUID(UID
);
1535 if M
= nil then Exit
;
1537 NetOut
.Write(Byte(NET_MSG_MPOS
));
1542 NetOut
.Write(GameX
);
1543 NetOut
.Write(GameY
);
1544 NetOut
.Write(GameVelX
);
1545 NetOut
.Write(GameVelY
);
1546 NetOut
.Write(Byte(GameDirection
));
1549 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1552 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1556 M
:= g_Monsters_ByUID(UID
);
1557 if M
= nil then Exit
;
1559 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1564 NetOut
.Write(MonsterState
);
1565 NetOut
.Write(ForcedAnim
);
1566 NetOut
.Write(MonsterTargetUID
);
1567 NetOut
.Write(MonsterTargetTime
);
1568 NetOut
.Write(MonsterSleep
);
1569 NetOut
.Write(MonsterHealth
);
1570 NetOut
.Write(MonsterAmmo
);
1571 NetOut
.Write(MonsterPain
);
1572 NetOut
.Write(Byte(AnimIsReverse
));
1573 NetOut
.Write(FFireTime
);
1576 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1579 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1581 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1588 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1591 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1595 M
:= g_Monsters_ByUID(UID
);
1596 if M
= nil then Exit
;
1598 NetOut
.Write(Byte(NET_MSG_MDEL
));
1601 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1606 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1608 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1611 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1614 procedure MH_SEND_VoteEvent(EvType
: Byte;
1615 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1616 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1617 ID
: Integer = NET_EVERYONE
);
1619 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1620 NetOut
.Write(EvType
);
1621 NetOut
.Write(IntArg1
);
1622 NetOut
.Write(IntArg2
);
1623 NetOut
.Write(StrArg1
);
1624 NetOut
.Write(StrArg2
);
1626 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1629 // CLIENT MESSAGES //
1633 procedure MC_RECV_Chat(var M
: TMsg
);
1638 Txt
:= M
.ReadString();
1639 Mode
:= M
.ReadByte();
1641 if Mode
<> NET_CHAT_SYSTEM
then
1643 if NetDeafLevel
= 0 then
1645 if Mode
= NET_CHAT_PLAYER
then
1647 g_Console_Add(Txt
, True);
1648 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1649 g_Game_ChatSound(b_Text_Unformat(Txt
));
1651 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1653 if gPlayer1
.Team
= TEAM_RED
then
1654 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1655 if gPlayer1
.Team
= TEAM_BLUE
then
1656 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1657 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1658 g_Game_ChatSound(b_Text_Unformat(Txt
));
1661 end else if (NetDeafLevel
< 2) then
1662 g_Console_Add(Txt
, True);
1665 procedure MC_RECV_Effect(var M
: TMsg
);
1673 if not gGameOn
then Exit
;
1674 Kind
:= M
.ReadByte();
1675 X
:= M
.ReadLongInt();
1676 Y
:= M
.ReadLongInt();
1677 Ang
:= M
.ReadSmallInt();
1681 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1685 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1687 Anim
:= TAnimation
.Create(ID
, False, 3);
1688 g_GFX_OnceAnim(X
, Y
, Anim
);
1692 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1697 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1699 Anim
:= TAnimation
.Create(ID
, False, 6);
1700 Anim
.Blending
:= False;
1701 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1705 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1710 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1712 Anim
:= TAnimation
.Create(ID
, False, 6);
1713 Anim
.Blending
:= False;
1714 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1718 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1723 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1725 Anim
:= TAnimation
.Create(ID
, False, 4);
1726 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1733 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1735 Anim
:= TAnimation
.Create(ID
, False, 4);
1736 g_GFX_OnceAnim(X
, Y
, Anim
);
1740 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1745 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1747 Anim
:= TAnimation
.Create(ID
, False, 4);
1748 g_GFX_OnceAnim(X
, Y
, Anim
);
1752 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1756 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1759 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1763 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1764 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1769 procedure MC_RECV_Sound(var M
: TMsg
);
1775 Name
:= M
.ReadString();
1776 Pos
:= M
.ReadByte() <> 0;
1779 X
:= M
.ReadLongInt();
1780 Y
:= M
.ReadLongInt();
1781 g_Sound_PlayExAt(Name
, X
, Y
);
1784 g_Sound_PlayEx(Name
);
1787 procedure MC_RECV_CreateShot(var M
: TMsg
);
1789 I
, X
, Y
, XV
, YV
: Integer;
1791 Target
, Spawner
: Word;
1794 I
:= M
.ReadLongInt();
1795 ShType
:= M
.ReadByte();
1796 Target
:= M
.ReadWord();
1797 Spawner
:= M
.ReadWord();
1798 Timeout
:= M
.ReadLongWord();
1799 X
:= M
.ReadLongInt();
1800 Y
:= M
.ReadLongInt();
1801 XV
:= M
.ReadLongInt();
1802 YV
:= M
.ReadLongInt();
1804 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1805 if (Shots
<> nil) and (I
<= High(Shots
)) then
1807 Shots
[I
].Timeout
:= Timeout
;
1808 //Shots[I].Target := Target; // TODO: find a use for Target later
1812 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1814 I
, TX
, TY
, TXV
, TYV
: Integer;
1816 I
:= M
.ReadLongInt();
1817 TX
:= M
.ReadLongInt();
1818 TY
:= M
.ReadLongInt();
1819 TXV
:= M
.ReadLongInt();
1820 TYV
:= M
.ReadLongInt();
1822 if (Shots
<> nil) and (I
<= High(Shots
)) then
1832 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1837 if not gGameOn
then Exit
;
1838 I
:= M
.ReadLongInt();
1839 L
:= (M
.ReadByte() <> 0);
1840 X
:= M
.ReadLongInt();
1841 Y
:= M
.ReadLongInt();
1843 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1846 procedure MC_RECV_GameStats(var M
: TMsg
);
1848 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1850 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1851 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1854 if gGameSettings
.GameMode
= GM_COOP
then
1856 gCoopMonstersKilled
:= M
.ReadWord();
1857 gCoopSecretsFound
:= M
.ReadWord();
1861 procedure MC_RECV_CoopStats(var M
: TMsg
);
1863 gTotalMonsters
:= M
.ReadLongInt();
1864 gSecretsCount
:= M
.ReadLongInt();
1865 gCoopTotalMonstersKilled
:= M
.ReadWord();
1866 gCoopTotalSecretsFound
:= M
.ReadWord();
1867 gCoopTotalMonsters
:= M
.ReadWord();
1868 gCoopTotalSecrets
:= M
.ReadWord();
1871 procedure MC_RECV_GameEvent(var M
: TMsg
);
1880 i1
, i2
: TStrings_Locale
;
1883 goodCmd
: Boolean = true;
1885 FillChar(EvHash
, Sizeof(EvHash
), 0);
1886 EvType
:= M
.ReadByte();
1887 EvNum
:= M
.ReadLongInt();
1888 EvStr
:= M
.ReadString();
1889 gLastMap
:= M
.ReadByte() <> 0;
1890 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1891 gStatsPressed
:= True;
1892 EvTime
:= M
.ReadLongWord();
1893 BHash
:= M
.ReadByte() <> 0;
1895 EvHash
:= M
.ReadMD5();
1899 if (g_Res_received_map_start
<> 0) then
1901 if (g_Res_received_map_start
< 0) then exit
;
1904 NET_EV_MAPSTART
: goodCmd
:= true;
1905 NET_EV_MAPEND
: goodCmd
:= true;
1906 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1907 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1908 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1910 if not goodCmd
then exit
;
1916 if (g_Res_received_map_start
<> 0) then
1918 g_Res_received_map_start
:= -1;
1923 g_Game_ClearLoading();
1924 g_Game_StopAllSounds(True);
1926 gSwitchGameMode
:= Byte(EvNum
);
1927 gGameSettings
.GameMode
:= gSwitchGameMode
;
1930 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1932 if not isWadPath(EvStr
) then
1933 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1935 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1939 MC_SEND_FullStateRequest
;
1945 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1946 gLMSRespawnTime
:= 0;
1947 if (g_Res_received_map_start
<> 0) then
1949 g_Res_received_map_start
:= -1;
1953 gMissionFailed
:= EvNum
<> 0;
1954 gExit
:= EXIT_ENDLEVELCUSTOM
;
1962 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1964 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1966 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1972 if NetDeafLevel
< 2 then
1974 if EvNum
= TEAM_RED
then
1975 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1976 if EvNum
= TEAM_BLUE
then
1977 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1983 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1984 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1989 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1990 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1997 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
1998 gLMSRespawnTime
:= gTime
+ EvNum
;
1999 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2001 else if gPlayer1
= nil then
2003 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2007 NET_EV_LMS_SURVIVOR
:
2008 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2011 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2015 pl
:= g_Player_Get(EvNum
and $FFFF);
2020 cnt
:= (EvNum
shr 16) and $FF;
2021 if Pos('w', EvStr
) = 0 then
2024 if Pos('t', EvStr
) = 0 then
2027 if Pos('-', EvStr
) = 0 then
2029 if Pos('e', EvStr
) = 0 then
2030 i1
:= I_PLAYER_SCORE_ADD_OWN
2032 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2035 if Pos('e', EvStr
) = 0 then
2036 i1
:= I_PLAYER_SCORE_SUB_OWN
2038 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2041 if Pos('r', EvStr
) > 0 then
2042 i2
:= I_PLAYER_SCORE_TO_RED
2044 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2045 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2049 if Pos('-', EvStr
) = 0 then
2050 i1
:= I_PLAYER_SCORE_ADD_TEAM
2052 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2054 if Pos('r', EvStr
) > 0 then
2055 i2
:= I_PLAYER_SCORE_RED
2057 i2
:= I_PLAYER_SCORE_BLUE
;
2058 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2063 if Pos('e', EvStr
) = 0 then
2064 i1
:= I_PLAYER_SCORE_WIN_OWN
2066 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
2068 if Pos('r', EvStr
) > 0 then
2069 i2
:= I_PLAYER_SCORE_TO_RED
2071 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2072 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
2078 if EvNum
= TEAM_RED
then
2079 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2080 if EvNum
= TEAM_BLUE
then
2081 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2082 if EvNum
= -TEAM_RED
then
2083 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2084 if EvNum
= -TEAM_BLUE
then
2085 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2090 g_Player_RemoveAllCorpses
;
2091 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2092 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2096 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2100 if EvNum
= TEAM_RED
then
2101 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2102 if EvNum
= TEAM_BLUE
then
2103 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2107 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2110 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2113 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2116 g_Game_Announce_KillCombo(EvNum
);
2118 NET_EV_PLAYER_TOUCH
:
2120 pl
:= g_Player_Get(EvNum
);
2127 pl
:= g_Player_Get(EvNum
);
2130 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2131 g_Sound_PlayEx('SOUND_GAME_SECRET');
2137 pl
:= g_Player_Get(EvNum
);
2138 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2143 procedure MC_RECV_FlagPos(var M
: TMsg
);
2148 if Fl
= FLAG_NONE
then Exit
;
2149 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2150 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2151 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2152 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2155 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2164 EvType
:= M
.ReadByte();
2167 if Fl
= FLAG_NONE
then Exit
;
2169 Quiet
:= (M
.ReadByte() <> 0);
2170 PID
:= M
.ReadWord();
2172 gFlags
[Fl
].State
:= M
.ReadByte();
2173 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
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();
2178 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2180 Pl
:= g_Player_Get(PID
);
2182 (EvType
<> FLAG_STATE_NORMAL
) and
2183 (EvType
<> FLAG_STATE_DROPPED
) and
2184 (EvType
<> FLAG_STATE_RETURNED
) then
2190 if Quiet
or (Pl
= nil) then Exit
;
2192 if Fl
= FLAG_RED
then
2193 s
:= _lc
[I_PLAYER_FLAG_RED
]
2195 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2197 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2199 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2200 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2201 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2206 if not sound_ret_flag
[a
].IsPlaying() then
2207 sound_ret_flag
[a
].Play();
2210 FLAG_STATE_CAPTURED
:
2212 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2216 if Fl
= FLAG_RED
then
2217 s
:= _lc
[I_PLAYER_FLAG_RED
]
2219 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2221 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2222 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [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_get_flag
[a
].IsPlaying() then
2232 sound_get_flag
[a
].Play();
2237 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2239 if Quiet
or (Pl
= nil) then Exit
;
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_DROP
], [Pl
.Name
, s
]), True);
2247 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [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_lost_flag
[a
].IsPlaying() then
2257 sound_lost_flag
[a
].Play();
2262 g_Map_ResetFlag(FLAG_RED
);
2263 g_Map_ResetFlag(FLAG_BLUE
);
2264 if Quiet
or (Pl
= nil) then Exit
;
2265 Pl
.SetFlag(FLAG_NONE
);
2267 if Fl
= FLAG_RED
then
2268 s
:= _lc
[I_PLAYER_FLAG_RED
]
2270 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2272 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2273 Insert('.', ts
, Length(ts
) + 1 - 3);
2274 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2275 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2277 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2278 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2279 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2284 if not sound_cap_flag
[a
].IsPlaying() then
2285 sound_cap_flag
[a
].Play();
2288 FLAG_STATE_RETURNED
:
2290 g_Map_ResetFlag(Fl
);
2293 if Fl
= FLAG_RED
then
2294 s
:= _lc
[I_PLAYER_FLAG_RED
]
2296 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2298 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2300 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2301 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2302 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2307 if not sound_ret_flag
[a
].IsPlaying() then
2308 sound_ret_flag
[a
].Play();
2313 procedure MC_RECV_GameSettings(var M
: TMsg
);
2315 gGameSettings
.GameMode
:= M
.ReadByte();
2316 gGameSettings
.GoalLimit
:= M
.ReadWord();
2317 gGameSettings
.TimeLimit
:= M
.ReadWord();
2318 gGameSettings
.MaxLives
:= M
.ReadByte();
2319 gGameSettings
.Options
:= M
.ReadLongWord();
2324 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2327 PName
, Model
: string;
2332 PID
:= M
.ReadWord();
2333 Pl
:= g_Player_Get(PID
);
2335 PName
:= M
.ReadString();
2336 Model
:= M
.ReadString();
2337 Color
.R
:= M
.ReadByte();
2338 Color
.G
:= M
.ReadByte();
2339 Color
.B
:= M
.ReadByte();
2343 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2345 if (Pl
<> nil) then Exit
;
2346 DID
:= g_Player_Create(Model
, Color
, T
, False);
2347 with g_Player_Get(DID
) do
2356 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2357 gPlayer1
.UID
:= PID
;
2358 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2359 gPlayer1
.ChangeTeam(T
);
2361 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2362 gPlayer2
.UID
:= PID
;
2363 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2364 gPlayer2
.ChangeTeam(T
);
2368 if NetDeafLevel
< 3 then
2369 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2370 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2374 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2381 TmpX
, TmpY
: Integer;
2385 GT
:= M
.ReadLongWord();
2386 if GT
< gTime
- NET_MAX_DIFFTIME
then
2393 PID
:= M
.ReadWord();
2394 Pl
:= g_Player_Get(PID
);
2396 if Pl
= nil then Exit
;
2402 FPing
:= M
.ReadWord();
2403 FLoss
:= M
.ReadByte();
2404 kByte
:= M
.ReadWord();
2405 Dir
:= M
.ReadByte();
2407 TmpX
:= M
.ReadLongInt();
2408 TmpY
:= M
.ReadLongInt();
2412 if LongBool(kByte
and NET_KEY_CHAT
) then
2413 PressKey(KEY_CHAT
, 10000)
2416 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2417 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2418 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2419 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2420 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2423 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2425 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2426 SetDirection(TDirection(Dir
));
2428 GameVelX
:= M
.ReadLongInt();
2429 GameVelY
:= M
.ReadLongInt();
2430 GameAccelX
:= M
.ReadLongInt();
2431 GameAccelY
:= M
.ReadLongInt();
2432 SetLerp(TmpX
, TmpY
);
2433 if NetForcePlayerUpdate
then Update();
2437 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2441 I
, OldFire
: Integer;
2442 OldJet
, Flam
: Boolean;
2445 PID
:= M
.ReadWord();
2446 Pl
:= g_Player_Get(PID
);
2453 alive
:= (M
.ReadByte() <> 0);
2454 GodMode
:= (M
.ReadByte() <> 0);
2455 Health
:= M
.ReadLongInt();
2456 Armor
:= M
.ReadLongInt();
2457 Air
:= M
.ReadLongInt();
2458 JetFuel
:= M
.ReadLongInt();
2459 Lives
:= M
.ReadByte();
2460 NewTeam
:= M
.ReadByte();
2462 for I
:= WP_FIRST
to WP_LAST
do
2463 FWeapon
[I
] := (M
.ReadByte() <> 0);
2465 for I
:= A_BULLETS
to A_HIGH
do
2466 FAmmo
[I
] := M
.ReadWord();
2468 for I
:= A_BULLETS
to A_HIGH
do
2469 FMaxAmmo
[I
] := M
.ReadWord();
2471 for I
:= MR_SUIT
to MR_MAX
do
2472 FMegaRulez
[I
] := M
.ReadLongWord();
2475 if (M
.ReadByte() <> 0) then
2476 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2477 if (M
.ReadByte() <> 0) then
2478 FRulez
:= FRulez
+ [R_KEY_RED
];
2479 if (M
.ReadByte() <> 0) then
2480 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2481 if (M
.ReadByte() <> 0) then
2482 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2483 if (M
.ReadByte() <> 0) then
2484 FRulez
:= FRulez
+ [R_BERSERK
];
2486 Frags
:= M
.ReadLongInt();
2487 Death
:= M
.ReadLongInt();
2489 SetWeapon(M
.ReadByte());
2491 FSpectator
:= M
.ReadByte() <> 0;
2494 if UID
= NetPlrUID1
then
2496 gSpectLatchPID1
:= UID
;
2499 if UID
= NetPlrUID2
then
2501 gSpectLatchPID2
:= UID
;
2507 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2510 gSpectLatchPID1
:= 0;
2512 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2515 gSpectLatchPID2
:= 0;
2518 FGhost
:= M
.ReadByte() <> 0;
2519 FPhysics
:= M
.ReadByte() <> 0;
2520 FNoRespawn
:= M
.ReadByte() <> 0;
2522 FJetpack
:= M
.ReadByte() <> 0;
2523 OldFire
:= FFireTime
;
2524 FFireTime
:= M
.ReadLongInt();
2525 if (OldFire
<= 0) and (FFireTime
> 0) then
2526 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2527 Flam
:= M
.ReadByte() <> 0;
2528 FSpawnInvul
:= M
.ReadLongInt();
2529 if OldJet
and not FJetpack
then
2531 else if not OldJet
and FJetpack
then
2533 if FFlaming
and not Flam
then
2535 if Team
<> NewTeam
then
2536 Pl
.ChangeTeam(NewTeam
);
2542 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2547 Attacker
, Value
: Word;
2551 if not gGameOn
then Exit
;
2552 PID
:= M
.ReadWord();
2553 Pl
:= g_Player_Get(PID
);
2554 if Pl
= nil then Exit
;
2556 Kind
:= M
.ReadByte();
2557 Attacker
:= M
.ReadWord();
2558 Value
:= M
.ReadWord();
2563 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2568 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2572 KillType
, DeathType
: Byte;
2576 if not gGameOn
then Exit
;
2577 PID
:= M
.ReadWord();
2578 Pl
:= g_Player_Get(PID
);
2579 if Pl
= nil then Exit
;
2581 KillType
:= M
.ReadByte();
2582 DeathType
:= M
.ReadByte();
2583 Attacker
:= M
.ReadWord();
2587 Kill(KillType
, Attacker
, DeathType
);
2592 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2597 PID
:= M
.ReadWord();
2598 Pl
:= g_Player_Get(PID
);
2600 if Pl
= nil then Exit
;
2602 if NetDeafLevel
< 3 then
2603 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2604 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2606 g_Player_Remove(PID
);
2611 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2616 X
, Y
, AX
, AY
: Integer;
2620 if not gGameOn
then Exit
;
2621 PID
:= M
.ReadWord();
2622 Pl
:= g_Player_Get(PID
);
2623 if Pl
= nil then Exit
;
2625 Weap
:= M
.ReadByte();
2626 X
:= M
.ReadLongInt();
2627 Y
:= M
.ReadLongInt();
2628 AX
:= M
.ReadLongInt();
2629 AY
:= M
.ReadLongInt();
2630 SHID
:= M
.ReadLongInt();
2633 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2636 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2645 PID
:= M
.ReadWord();
2646 Pl
:= g_Player_Get(PID
);
2647 if Pl
= nil then Exit
;
2649 TmpName
:= M
.ReadString();
2650 TmpModel
:= M
.ReadString();
2651 TmpColor
.R
:= M
.ReadByte();
2652 TmpColor
.G
:= M
.ReadByte();
2653 TmpColor
.B
:= M
.ReadByte();
2654 TmpTeam
:= M
.ReadByte();
2656 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2658 Pl
.ChangeTeam(TmpTeam
);
2659 if gPlayer1
= Pl
then
2660 gPlayer1Settings
.Team
:= TmpTeam
;
2661 if gPlayer2
= Pl
then
2662 gPlayer2Settings
.Team
:= TmpTeam
;
2664 Pl
.SetColor(TmpColor
);
2666 if Pl
.Name
<> TmpName
then
2668 if NetDeafLevel
< 3 then
2669 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2673 if TmpModel
<> Pl
.Model
.Name
then
2674 Pl
.SetModel(TmpModel
);
2679 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2683 X
, Y
, VX
, VY
: Integer;
2685 Quiet
, Fall
{, Resp}: Boolean;
2689 if not gGameOn
then Exit
;
2691 Quiet
:= M
.ReadByte() <> 0;
2693 Fall
:= M
.ReadByte() <> 0;
2694 {Resp :=} M
.ReadByte();
2695 X
:= M
.ReadLongInt();
2696 Y
:= M
.ReadLongInt();
2697 VX
:= M
.ReadLongInt();
2698 VY
:= M
.ReadLongInt();
2700 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2701 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2703 it
:= g_Items_ByIdx(ID
);
2709 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2710 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2712 Anim
:= TAnimation
.Create(AID
, False, 4);
2713 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2719 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2724 if not gGameOn
then Exit
;
2726 Quiet
:= M
.ReadByte() <> 0;
2728 if not g_Items_ValidId(ID
) then exit
;
2730 if not Quiet
then g_Items_EmitPickupSound(ID
);
2735 procedure MC_RECV_ItemPos(var M
: TMsg
);
2738 X
, Y
, VX
, VY
: Integer;
2741 if not gGameOn
then Exit
;
2744 X
:= M
.ReadLongInt();
2745 Y
:= M
.ReadLongInt();
2746 VX
:= M
.ReadLongInt();
2747 VY
:= M
.ReadLongInt();
2749 if g_Items_ValidId(ID
) then
2751 it
:= g_Items_ByIdx(ID
);
2756 it
.positionChanged();
2762 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2769 if not gGameOn
then Exit
;
2771 PGUID
:= Integer(M
.ReadLongWord());
2772 Tex
:= M
.ReadLongInt();
2773 Fr
:= M
.ReadLongInt();
2774 Cnt
:= M
.ReadByte();
2775 Loop
:= M
.ReadByte();
2777 TP
:= g_Map_PanelByGUID(PGUID
);
2781 TP
.SetTexture(Tex
, Loop
);
2782 TP
.SetFrame(Fr
, Cnt
);
2786 procedure MC_RECV_PanelState(var M
: TMsg
);
2791 X
, Y
, W
, H
: Integer;
2793 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2794 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2797 if not gGameOn
then Exit
;
2799 PGUID
:= Integer(M
.ReadLongWord());
2800 E
:= (M
.ReadByte() <> 0);
2801 Lift
:= M
.ReadByte();
2802 X
:= M
.ReadLongInt();
2803 Y
:= M
.ReadLongInt();
2807 speedX
:= M
.ReadLongInt();
2808 speedY
:= M
.ReadLongInt();
2809 startX
:= M
.ReadLongInt();
2810 startY
:= M
.ReadLongInt();
2811 endX
:= M
.ReadLongInt();
2812 endY
:= M
.ReadLongInt();
2813 sizeSpX
:= M
.ReadLongInt();
2814 sizeSpY
:= M
.ReadLongInt();
2815 sizeEX
:= M
.ReadLongInt();
2816 sizeEY
:= M
.ReadLongInt();
2817 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2819 TP
:= g_Map_PanelByGUID(PGUID
);
2820 if (TP
= nil) then exit
;
2822 // update lifts state
2823 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2825 // update enabled/disabled state for all panels
2826 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2828 // update panel position, as it can be moved (mplat)
2833 // update mplat state
2834 TP
.movingSpeedX
:= speedX
;
2835 TP
.movingSpeedY
:= speedY
;
2836 TP
.movingStartX
:= startX
;
2837 TP
.movingStartY
:= startY
;
2838 TP
.movingEndX
:= endX
;
2839 TP
.movingEndY
:= endY
;
2840 TP
.sizeSpeedX
:= sizeSpX
;
2841 TP
.sizeSpeedY
:= sizeSpY
;
2842 TP
.sizeEndX
:= sizeEX
;
2843 TP
.sizeEndY
:= sizeEY
;
2844 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2845 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2846 // notify panel of it's position/size change, so it can fix other internal structures
2847 TP
.positionChanged();
2852 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2855 SPos
, SID
: LongWord;
2859 if not gGameOn
then Exit
;
2860 if gTriggers
= nil then Exit
;
2862 SID
:= M
.ReadLongWord();
2863 SPlaying
:= M
.ReadByte() <> 0;
2864 SPos
:= M
.ReadLongWord();
2865 SCount
:= M
.ReadLongInt();
2867 for I
:= Low(gTriggers
) to High(gTriggers
) do
2868 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2869 if gTriggers
[I
].ClientID
= SID
then
2870 with gTriggers
[I
] do
2872 if Sound
<> nil then
2877 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2879 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2880 Sound
.SetPosition(SPos
);
2883 if Sound
.IsPlaying
then Sound
.Stop
;
2886 SoundPlayCount
:= SCount
;
2890 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2897 if not gGameOn
then Exit
;
2899 MName
:= M
.ReadString();
2900 MPlaying
:= M
.ReadByte() <> 0;
2901 MPos
:= M
.ReadLongWord();
2902 MPaused
:= M
.ReadByte() <> 0;
2903 MPos
:= MPos
+1; //k8: stfu, fpc!
2907 gMusic
.SetByName(MName
);
2909 // gMusic.SetPosition(MPos);
2910 gMusic
.SpecPause
:= MPaused
;
2913 if gMusic
.IsPlaying
then gMusic
.Stop
;
2918 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2921 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2922 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2927 Mon
:= g_Monsters_ByUID(ID
);
2931 MType
:= M
.ReadByte();
2932 MState
:= M
.ReadByte();
2933 MAnim
:= M
.ReadByte();
2934 MTarg
:= M
.ReadWord();
2935 MTargTime
:= M
.ReadLongInt();
2936 MBehav
:= M
.ReadByte();
2937 MSleep
:= M
.ReadLongInt();
2938 MHealth
:= M
.ReadLongInt();
2939 MAmmo
:= M
.ReadLongInt();
2941 X
:= M
.ReadLongInt();
2942 Y
:= M
.ReadLongInt();
2943 VX
:= M
.ReadLongInt();
2944 VY
:= M
.ReadLongInt();
2945 MDir
:= M
.ReadByte();
2947 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2948 Mon
:= g_Monsters_ByUID(ID
);
2955 MonsterAnim
:= MAnim
;
2956 MonsterTargetUID
:= MTarg
;
2957 MonsterTargetTime
:= MTargTime
;
2958 MonsterBehaviour
:= MBehav
;
2959 MonsterSleep
:= MSleep
;
2960 MonsterAmmo
:= MAmmo
;
2965 setPosition(X
, Y
); // this will call positionChanged();
2971 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2978 Mon
:= g_Monsters_ByUID(ID
);
2984 X
:= M
.ReadLongInt();
2985 Y
:= M
.ReadLongInt();
2986 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2987 GameVelX
:= M
.ReadLongInt();
2988 GameVelY
:= M
.ReadLongInt();
2989 GameDirection
:= TDirection(M
.ReadByte());
2993 procedure MC_RECV_MonsterState(var M
: TMsg
);
2995 ID
, OldFire
: Integer;
2996 MState
, MFAnm
: Byte;
2998 AnimRevert
: Boolean;
3001 Mon
:= g_Monsters_ByUID(ID
);
3002 if Mon
= nil then Exit
;
3004 MState
:= M
.ReadByte();
3005 MFAnm
:= M
.ReadByte();
3009 MonsterTargetUID
:= M
.ReadWord();
3010 MonsterTargetTime
:= M
.ReadLongInt();
3011 MonsterSleep
:= M
.ReadLongInt();
3012 MonsterHealth
:= M
.ReadLongInt();
3013 MonsterAmmo
:= M
.ReadLongInt();
3014 MonsterPain
:= M
.ReadLongInt();
3015 AnimRevert
:= M
.ReadByte() <> 0;
3016 OldFire
:= FFireTime
;
3017 FFireTime
:= M
.ReadLongInt();
3018 if (OldFire
<= 0) and (FFireTime
> 0) then
3019 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3020 RevertAnim(AnimRevert
);
3022 if MonsterState
<> MState
then
3024 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3025 if (MState
= MONSTATE_DIE
) then DieSound();
3026 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3027 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3028 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3030 SetState(MState
, MFAnm
);
3035 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3039 X
, Y
, VX
, VY
: Integer;
3043 Mon
:= g_Monsters_ByUID(ID
);
3044 if Mon
= nil then Exit
;
3046 X
:= M
.ReadLongInt();
3047 Y
:= M
.ReadLongInt();
3048 VX
:= M
.ReadLongInt();
3049 VY
:= M
.ReadLongInt();
3051 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3054 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3060 Mon
:= g_Monsters_ByUID(ID
);
3061 if Mon
= nil then Exit
;
3063 Mon
.MonsterRemoved
:= True;
3066 procedure MC_RECV_TimeSync(var M
: TMsg
);
3070 Time
:= M
.ReadLongWord();
3072 if gState
= STATE_INTERCUSTOM
then
3073 gServInterTime
:= Min(Time
, 255);
3076 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3080 Int1
, Int2
: SmallInt;
3082 EvID
:= M
.ReadByte();
3083 Int1
:= M
.ReadSmallInt();
3084 Int2
:= M
.ReadSmallInt();
3085 Str1
:= M
.ReadString();
3086 Str2
:= M
.ReadString();
3088 if NetDeafLevel
< 2 then
3091 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3093 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3095 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3097 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3099 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3105 procedure MC_SEND_Info(Password
: string);
3109 NetOut
.Write(Byte(NET_MSG_INFO
));
3110 NetOut
.Write(GAME_VERSION
);
3111 NetOut
.Write(Password
);
3112 NetOut
.Write(gPlayer1Settings
.Name
);
3113 NetOut
.Write(gPlayer1Settings
.Model
);
3114 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3115 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3116 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3117 NetOut
.Write(gPlayer1Settings
.Team
);
3119 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3122 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3124 NetOut
.Write(Byte(NET_MSG_CHAT
));
3128 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3131 procedure MC_SEND_PlayerPos();
3136 WeaponAct
: Byte = 0;
3137 WeaponSelect
: Word = 0;
3140 if not gGameOn
then Exit
;
3141 if gPlayers
= nil then Exit
;
3142 if gPlayer1
= nil then Exit
;
3145 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3147 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3149 strafeDir
:= P1MoveButton
shr 4;
3150 P1MoveButton
:= P1MoveButton
and $0F;
3152 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3154 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3156 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3160 if gPlayerAction
[0, ACTION_STRAFE
] then
3162 // new strafe mechanics
3163 if (strafeDir
= 0) then
3164 strafeDir
:= P1MoveButton
; // start strafing
3165 // now set direction according to strafe (reversed)
3166 if (strafeDir
= 2) then
3167 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3168 else if (strafeDir
= 1) then
3169 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3173 strafeDir
:= 0; // not strafing anymore
3174 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3175 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3176 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3177 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3178 else if P1MoveButton
<> 0 then
3179 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3182 gPlayer1
.ReleaseKeys
;
3183 if P1MoveButton
= 1 then
3185 kByte
:= kByte
or NET_KEY_LEFT
;
3186 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3188 if P1MoveButton
= 2 then
3190 kByte
:= kByte
or NET_KEY_RIGHT
;
3191 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3193 if gPlayerAction
[0, ACTION_LOOKUP
] then
3195 kByte
:= kByte
or NET_KEY_UP
;
3196 gPlayer1
.PressKey(KEY_UP
, 10000);
3198 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3200 kByte
:= kByte
or NET_KEY_DOWN
;
3201 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3203 if gPlayerAction
[0, ACTION_JUMP
] then
3205 kByte
:= kByte
or NET_KEY_JUMP
;
3206 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3208 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3209 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3211 for i
:= WP_FACT
to WP_LACT
do
3213 if gWeaponAction
[0, i
] then
3215 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3216 gWeaponAction
[0, i
] := False
3220 for i
:= WP_FIRST
to WP_LAST
do
3222 if gSelectWeapon
[0, i
] then
3224 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3225 gSelectWeapon
[0, i
] := False
3229 // fix movebutton state
3230 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3233 kByte
:= NET_KEY_CHAT
;
3235 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3236 NetOut
.Write(gTime
);
3237 NetOut
.Write(kByte
);
3238 NetOut
.Write(Byte(gPlayer1
.Direction
));
3239 NetOut
.Write(WeaponAct
);
3240 NetOut
.Write(WeaponSelect
);
3241 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3242 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3244 //kBytePrev := kByte;
3245 //kDirPrev := gPlayer1.Direction;
3248 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3250 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3251 NetOut
.Write(Byte(Start
));
3252 NetOut
.Write(Command
);
3253 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3256 procedure MC_SEND_PlayerSettings();
3258 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3259 NetOut
.Write(gPlayer1Settings
.Name
);
3260 NetOut
.Write(gPlayer1Settings
.Model
);
3261 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3262 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3263 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3264 NetOut
.Write(gPlayer1Settings
.Team
);
3266 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3269 procedure MC_SEND_FullStateRequest();
3271 NetOut
.Write(Byte(NET_MSG_REQFST
));
3273 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3276 procedure MC_SEND_CheatRequest(Kind
: Byte);
3278 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3281 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3283 procedure MC_SEND_RCONPassword(Password
: string);
3285 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3286 NetOut
.Write(Password
);
3288 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3290 procedure MC_SEND_RCONCommand(Cmd
: string);
3292 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3295 g_Net_Client_Send(True, NET_CHAN_SERVICE
);