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 checkWeapon
: Boolean;
2451 OldJet
, Flam
: Boolean;
2454 PID
:= M
.ReadWord();
2455 Pl
:= g_Player_Get(PID
);
2462 alive
:= (M
.ReadByte() <> 0);
2463 GodMode
:= (M
.ReadByte() <> 0);
2464 Health
:= M
.ReadLongInt();
2465 Armor
:= M
.ReadLongInt();
2466 Air
:= M
.ReadLongInt();
2467 JetFuel
:= M
.ReadLongInt();
2468 Lives
:= M
.ReadByte();
2469 NewTeam
:= M
.ReadByte();
2471 for I
:= WP_FIRST
to WP_LAST
do
2473 checkWeapon
:= (M
.ReadByte() <> 0);
2474 if ( (gPlayer1Settings
.WeaponSwitch
= 0) and (gPlayer2Settings
.WeaponSwitch
= 0) ) or ( (I
= WEAPON_KASTET
) or (I
= WEAPON_PISTOL
) or (checkWeapon
= False) or (FWeapon
[I
] = True) ) then
2475 FWeapon
[I
] := checkWeapon
2478 if ((PID
= gPlayer1
.UID
) and (gPlayer1Settings
.WeaponSwitch
<> 0)) or ( (gPlayer2
<> nil) and (PID
= gPlayer2
.UID
) and (gPlayer2Settings
.WeaponSwitch
<> 0) ) then
2481 if (PID
= gPlayer1
.UID
) then
2482 if (gPlayer1Settings
.WeaponSwitch
= 1) or ( (gPlayer1Settings
.WeaponSwitch
= 2) and (gPlayer1Settings
.WeaponPreferences
[I
] > gPlayer1Settings
.WeaponPreferences
[CurrWeap
]) ) then
2484 gSelectWeapon
[0, I
] := True;
2487 if (gPlayer2Settings
.WeaponSwitch
= 1) or ( (gPlayer2Settings
.WeaponSwitch
= 2) and (gPlayer2Settings
.WeaponPreferences
[I
] > gPlayer2Settings
.WeaponPreferences
[CurrWeap
]) ) then
2488 gSelectWeapon
[1, I
] := True;
2491 FWeapon
[I
] := checkWeapon
;
2494 for I
:= A_BULLETS
to A_HIGH
do
2495 FAmmo
[I
] := M
.ReadWord();
2497 for I
:= A_BULLETS
to A_HIGH
do
2498 FMaxAmmo
[I
] := M
.ReadWord();
2500 for I
:= MR_SUIT
to MR_MAX
do
2501 FMegaRulez
[I
] := M
.ReadLongWord();
2504 if (M
.ReadByte() <> 0) then
2505 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2506 if (M
.ReadByte() <> 0) then
2507 FRulez
:= FRulez
+ [R_KEY_RED
];
2508 if (M
.ReadByte() <> 0) then
2509 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2510 if (M
.ReadByte() <> 0) then
2511 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2512 checkWeapon
:= M
.ReadByte() <> 0;
2513 if (checkWeapon
) then
2515 FRulez
:= FRulez
+ [R_BERSERK
];
2516 if ((gPlayer2Settings
.WeaponSwitch
<> 0) and (gPlayer2Settings
.WeaponSwitch
<> 0)) and ((PID
= gPlayer1
.UID
) or ( (gPlayer2
<> nil) and (PID
= gPlayer2
.UID
) )) then
2518 if (PID
= gPlayer1
.UID
) then
2520 if (gPlayer1Settings
.WeaponSwitch
= 1) or ( (gPlayer1Settings
.WeaponSwitch
= 2) and (gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] > gPlayer1Settings
.WeaponPreferences
[CurrWeap
]) ) then
2522 gSelectWeapon
[0, WEAPON_KASTET
] := True;
2527 if (gPlayer2Settings
.WeaponSwitch
= 1) or ( (gPlayer2Settings
.WeaponSwitch
= 2) and (gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] > gPlayer2Settings
.WeaponPreferences
[CurrWeap
]) ) then
2529 gSelectWeapon
[0, WEAPON_KASTET
] := True;
2535 Frags
:= M
.ReadLongInt();
2536 Death
:= M
.ReadLongInt();
2538 SetWeapon(M
.ReadByte());
2540 FSpectator
:= M
.ReadByte() <> 0;
2543 if UID
= NetPlrUID1
then
2545 gSpectLatchPID1
:= UID
;
2548 if UID
= NetPlrUID2
then
2550 gSpectLatchPID2
:= UID
;
2556 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2559 gSpectLatchPID1
:= 0;
2561 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2564 gSpectLatchPID2
:= 0;
2567 FGhost
:= M
.ReadByte() <> 0;
2568 FPhysics
:= M
.ReadByte() <> 0;
2569 FNoRespawn
:= M
.ReadByte() <> 0;
2571 FJetpack
:= M
.ReadByte() <> 0;
2572 OldFire
:= FFireTime
;
2573 FFireTime
:= M
.ReadLongInt();
2574 if (OldFire
<= 0) and (FFireTime
> 0) then
2575 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2576 Flam
:= M
.ReadByte() <> 0;
2577 FSpawnInvul
:= M
.ReadLongInt();
2578 if OldJet
and not FJetpack
then
2580 else if not OldJet
and FJetpack
then
2582 if FFlaming
and not Flam
then
2584 if Team
<> NewTeam
then
2585 Pl
.ChangeTeam(NewTeam
);
2591 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2596 Attacker
, Value
: Word;
2600 if not gGameOn
then Exit
;
2601 PID
:= M
.ReadWord();
2602 Pl
:= g_Player_Get(PID
);
2603 if Pl
= nil then Exit
;
2605 Kind
:= M
.ReadByte();
2606 Attacker
:= M
.ReadWord();
2607 Value
:= M
.ReadWord();
2612 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2617 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2621 KillType
, DeathType
: Byte;
2625 if not gGameOn
then Exit
;
2626 PID
:= M
.ReadWord();
2627 Pl
:= g_Player_Get(PID
);
2628 if Pl
= nil then Exit
;
2630 KillType
:= M
.ReadByte();
2631 DeathType
:= M
.ReadByte();
2632 Attacker
:= M
.ReadWord();
2636 Kill(KillType
, Attacker
, DeathType
);
2641 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2646 PID
:= M
.ReadWord();
2647 Pl
:= g_Player_Get(PID
);
2649 if Pl
= nil then Exit
;
2651 if NetDeafLevel
< 3 then
2652 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2653 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2655 g_Player_Remove(PID
);
2660 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2665 X
, Y
, AX
, AY
: Integer;
2669 if not gGameOn
then Exit
;
2670 PID
:= M
.ReadWord();
2671 Pl
:= g_Player_Get(PID
);
2672 if Pl
= nil then Exit
;
2674 Weap
:= M
.ReadByte();
2675 X
:= M
.ReadLongInt();
2676 Y
:= M
.ReadLongInt();
2677 AX
:= M
.ReadLongInt();
2678 AY
:= M
.ReadLongInt();
2679 SHID
:= M
.ReadLongInt();
2682 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2685 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2694 PID
:= M
.ReadWord();
2695 Pl
:= g_Player_Get(PID
);
2696 if Pl
= nil then Exit
;
2698 TmpName
:= M
.ReadString();
2699 TmpModel
:= M
.ReadString();
2700 TmpColor
.R
:= M
.ReadByte();
2701 TmpColor
.G
:= M
.ReadByte();
2702 TmpColor
.B
:= M
.ReadByte();
2703 TmpTeam
:= M
.ReadByte();
2705 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2707 Pl
.ChangeTeam(TmpTeam
);
2708 if gPlayer1
= Pl
then
2709 gPlayer1Settings
.Team
:= TmpTeam
;
2710 if gPlayer2
= Pl
then
2711 gPlayer2Settings
.Team
:= TmpTeam
;
2713 Pl
.SetColor(TmpColor
);
2715 if Pl
.Name
<> TmpName
then
2717 if NetDeafLevel
< 3 then
2718 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2722 if TmpModel
<> Pl
.Model
.Name
then
2723 Pl
.SetModel(TmpModel
);
2728 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2732 X
, Y
, VX
, VY
: Integer;
2734 Quiet
, Fall
{, Resp}: Boolean;
2738 if not gGameOn
then Exit
;
2740 Quiet
:= M
.ReadByte() <> 0;
2742 Fall
:= M
.ReadByte() <> 0;
2743 {Resp :=} M
.ReadByte();
2744 X
:= M
.ReadLongInt();
2745 Y
:= M
.ReadLongInt();
2746 VX
:= M
.ReadLongInt();
2747 VY
:= M
.ReadLongInt();
2749 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2750 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2752 it
:= g_Items_ByIdx(ID
);
2758 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2759 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2761 Anim
:= TAnimation
.Create(AID
, False, 4);
2762 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2768 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2773 if not gGameOn
then Exit
;
2775 Quiet
:= M
.ReadByte() <> 0;
2777 if not g_Items_ValidId(ID
) then exit
;
2779 if not Quiet
then g_Items_EmitPickupSound(ID
);
2784 procedure MC_RECV_ItemPos(var M
: TMsg
);
2787 X
, Y
, VX
, VY
: Integer;
2790 if not gGameOn
then Exit
;
2793 X
:= M
.ReadLongInt();
2794 Y
:= M
.ReadLongInt();
2795 VX
:= M
.ReadLongInt();
2796 VY
:= M
.ReadLongInt();
2798 if g_Items_ValidId(ID
) then
2800 it
:= g_Items_ByIdx(ID
);
2805 it
.positionChanged();
2811 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2818 if not gGameOn
then Exit
;
2820 PGUID
:= Integer(M
.ReadLongWord());
2821 Tex
:= M
.ReadLongInt();
2822 Fr
:= M
.ReadLongInt();
2823 Cnt
:= M
.ReadByte();
2824 Loop
:= M
.ReadByte();
2826 TP
:= g_Map_PanelByGUID(PGUID
);
2830 TP
.SetTexture(Tex
, Loop
);
2831 TP
.SetFrame(Fr
, Cnt
);
2835 procedure MC_RECV_PanelState(var M
: TMsg
);
2840 X
, Y
, W
, H
: Integer;
2842 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2843 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2846 if not gGameOn
then Exit
;
2848 PGUID
:= Integer(M
.ReadLongWord());
2849 E
:= (M
.ReadByte() <> 0);
2850 Lift
:= M
.ReadByte();
2851 X
:= M
.ReadLongInt();
2852 Y
:= M
.ReadLongInt();
2856 speedX
:= M
.ReadLongInt();
2857 speedY
:= M
.ReadLongInt();
2858 startX
:= M
.ReadLongInt();
2859 startY
:= M
.ReadLongInt();
2860 endX
:= M
.ReadLongInt();
2861 endY
:= M
.ReadLongInt();
2862 sizeSpX
:= M
.ReadLongInt();
2863 sizeSpY
:= M
.ReadLongInt();
2864 sizeEX
:= M
.ReadLongInt();
2865 sizeEY
:= M
.ReadLongInt();
2866 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2868 TP
:= g_Map_PanelByGUID(PGUID
);
2869 if (TP
= nil) then exit
;
2871 // update lifts state
2872 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2874 // update enabled/disabled state for all panels
2875 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2877 // update panel position, as it can be moved (mplat)
2882 // update mplat state
2883 TP
.movingSpeedX
:= speedX
;
2884 TP
.movingSpeedY
:= speedY
;
2885 TP
.movingStartX
:= startX
;
2886 TP
.movingStartY
:= startY
;
2887 TP
.movingEndX
:= endX
;
2888 TP
.movingEndY
:= endY
;
2889 TP
.sizeSpeedX
:= sizeSpX
;
2890 TP
.sizeSpeedY
:= sizeSpY
;
2891 TP
.sizeEndX
:= sizeEX
;
2892 TP
.sizeEndY
:= sizeEY
;
2893 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2894 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2895 // notify panel of it's position/size change, so it can fix other internal structures
2896 TP
.positionChanged();
2901 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2904 SPos
, SID
: LongWord;
2908 if not gGameOn
then Exit
;
2909 if gTriggers
= nil then Exit
;
2911 SID
:= M
.ReadLongWord();
2912 SPlaying
:= M
.ReadByte() <> 0;
2913 SPos
:= M
.ReadLongWord();
2914 SCount
:= M
.ReadLongInt();
2916 for I
:= Low(gTriggers
) to High(gTriggers
) do
2917 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2918 if gTriggers
[I
].ClientID
= SID
then
2919 with gTriggers
[I
] do
2921 if Sound
<> nil then
2926 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2928 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2929 Sound
.SetPosition(SPos
);
2932 if Sound
.IsPlaying
then Sound
.Stop
;
2935 SoundPlayCount
:= SCount
;
2939 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2946 if not gGameOn
then Exit
;
2948 MName
:= M
.ReadString();
2949 MPlaying
:= M
.ReadByte() <> 0;
2950 MPos
:= M
.ReadLongWord();
2951 MPaused
:= M
.ReadByte() <> 0;
2952 MPos
:= MPos
+1; //k8: stfu, fpc!
2956 gMusic
.SetByName(MName
);
2958 // gMusic.SetPosition(MPos);
2959 gMusic
.SpecPause
:= MPaused
;
2962 if gMusic
.IsPlaying
then gMusic
.Stop
;
2967 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2970 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2971 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2976 Mon
:= g_Monsters_ByUID(ID
);
2980 MType
:= M
.ReadByte();
2981 MState
:= M
.ReadByte();
2982 MAnim
:= M
.ReadByte();
2983 MTarg
:= M
.ReadWord();
2984 MTargTime
:= M
.ReadLongInt();
2985 MBehav
:= M
.ReadByte();
2986 MSleep
:= M
.ReadLongInt();
2987 MHealth
:= M
.ReadLongInt();
2988 MAmmo
:= M
.ReadLongInt();
2990 X
:= M
.ReadLongInt();
2991 Y
:= M
.ReadLongInt();
2992 VX
:= M
.ReadLongInt();
2993 VY
:= M
.ReadLongInt();
2994 MDir
:= M
.ReadByte();
2996 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2997 Mon
:= g_Monsters_ByUID(ID
);
3004 MonsterAnim
:= MAnim
;
3005 MonsterTargetUID
:= MTarg
;
3006 MonsterTargetTime
:= MTargTime
;
3007 MonsterBehaviour
:= MBehav
;
3008 MonsterSleep
:= MSleep
;
3009 MonsterAmmo
:= MAmmo
;
3014 setPosition(X
, Y
); // this will call positionChanged();
3020 procedure MC_RECV_MonsterPos(var M
: TMsg
);
3027 Mon
:= g_Monsters_ByUID(ID
);
3033 X
:= M
.ReadLongInt();
3034 Y
:= M
.ReadLongInt();
3035 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
3036 GameVelX
:= M
.ReadLongInt();
3037 GameVelY
:= M
.ReadLongInt();
3038 GameDirection
:= TDirection(M
.ReadByte());
3042 procedure MC_RECV_MonsterState(var M
: TMsg
);
3044 ID
, OldFire
: Integer;
3045 MState
, MFAnm
: Byte;
3047 AnimRevert
: Boolean;
3050 Mon
:= g_Monsters_ByUID(ID
);
3051 if Mon
= nil then Exit
;
3053 MState
:= M
.ReadByte();
3054 MFAnm
:= M
.ReadByte();
3058 MonsterTargetUID
:= M
.ReadWord();
3059 MonsterTargetTime
:= M
.ReadLongInt();
3060 MonsterSleep
:= M
.ReadLongInt();
3061 MonsterHealth
:= M
.ReadLongInt();
3062 MonsterAmmo
:= M
.ReadLongInt();
3063 MonsterPain
:= M
.ReadLongInt();
3064 AnimRevert
:= M
.ReadByte() <> 0;
3065 OldFire
:= FFireTime
;
3066 FFireTime
:= M
.ReadLongInt();
3067 if (OldFire
<= 0) and (FFireTime
> 0) then
3068 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3069 RevertAnim(AnimRevert
);
3071 if MonsterState
<> MState
then
3073 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3074 if (MState
= MONSTATE_DIE
) then DieSound();
3075 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3076 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3077 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3079 SetState(MState
, MFAnm
);
3084 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3088 X
, Y
, VX
, VY
: Integer;
3092 Mon
:= g_Monsters_ByUID(ID
);
3093 if Mon
= nil then Exit
;
3095 X
:= M
.ReadLongInt();
3096 Y
:= M
.ReadLongInt();
3097 VX
:= M
.ReadLongInt();
3098 VY
:= M
.ReadLongInt();
3100 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3103 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3109 Mon
:= g_Monsters_ByUID(ID
);
3110 if Mon
= nil then Exit
;
3112 Mon
.MonsterRemoved
:= True;
3115 procedure MC_RECV_TimeSync(var M
: TMsg
);
3119 Time
:= M
.ReadLongWord();
3121 if gState
= STATE_INTERCUSTOM
then
3122 gServInterTime
:= Min(Time
, 255);
3125 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3129 Int1
, Int2
: SmallInt;
3131 EvID
:= M
.ReadByte();
3132 Int1
:= M
.ReadSmallInt();
3133 Int2
:= M
.ReadSmallInt();
3134 Str1
:= M
.ReadString();
3135 Str2
:= M
.ReadString();
3137 if NetDeafLevel
< 2 then
3140 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3142 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3144 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3146 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3148 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3154 procedure MC_SEND_Info(Password
: string);
3158 NetOut
.Write(Byte(NET_MSG_INFO
));
3159 NetOut
.Write(GAME_VERSION
);
3160 NetOut
.Write(Password
);
3161 NetOut
.Write(gPlayer1Settings
.Name
);
3162 NetOut
.Write(gPlayer1Settings
.Model
);
3163 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3164 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3165 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3166 NetOut
.Write(gPlayer1Settings
.Team
);
3168 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3171 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3173 NetOut
.Write(Byte(NET_MSG_CHAT
));
3177 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3180 procedure MC_SEND_PlayerPos();
3185 WeaponAct
: Byte = 0;
3186 WeaponSelect
: Word = 0;
3189 if not gGameOn
then Exit
;
3190 if gPlayers
= nil then Exit
;
3191 if gPlayer1
= nil then Exit
;
3194 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3196 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3198 strafeDir
:= P1MoveButton
shr 4;
3199 P1MoveButton
:= P1MoveButton
and $0F;
3201 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3203 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3205 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3209 if gPlayerAction
[0, ACTION_STRAFE
] then
3211 // new strafe mechanics
3212 if (strafeDir
= 0) then
3213 strafeDir
:= P1MoveButton
; // start strafing
3214 // now set direction according to strafe (reversed)
3215 if (strafeDir
= 2) then
3216 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3217 else if (strafeDir
= 1) then
3218 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3222 strafeDir
:= 0; // not strafing anymore
3223 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3224 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3225 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3226 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3227 else if P1MoveButton
<> 0 then
3228 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3231 gPlayer1
.ReleaseKeys
;
3232 if P1MoveButton
= 1 then
3234 kByte
:= kByte
or NET_KEY_LEFT
;
3235 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3237 if P1MoveButton
= 2 then
3239 kByte
:= kByte
or NET_KEY_RIGHT
;
3240 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3242 if gPlayerAction
[0, ACTION_LOOKUP
] then
3244 kByte
:= kByte
or NET_KEY_UP
;
3245 gPlayer1
.PressKey(KEY_UP
, 10000);
3247 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3249 kByte
:= kByte
or NET_KEY_DOWN
;
3250 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3252 if gPlayerAction
[0, ACTION_JUMP
] then
3254 kByte
:= kByte
or NET_KEY_JUMP
;
3255 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3257 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3258 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3260 for i
:= WP_FACT
to WP_LACT
do
3262 if gWeaponAction
[0, i
] then
3264 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3265 gWeaponAction
[0, i
] := False
3269 for i
:= WP_FIRST
to WP_LAST
do
3271 if gSelectWeapon
[0, i
] then
3273 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3274 gSelectWeapon
[0, i
] := False
3278 // fix movebutton state
3279 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3282 kByte
:= NET_KEY_CHAT
;
3284 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3285 NetOut
.Write(gTime
);
3286 NetOut
.Write(kByte
);
3287 NetOut
.Write(Byte(gPlayer1
.Direction
));
3288 NetOut
.Write(WeaponAct
);
3289 NetOut
.Write(WeaponSelect
);
3290 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3291 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3293 //kBytePrev := kByte;
3294 //kDirPrev := gPlayer1.Direction;
3297 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3299 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3300 NetOut
.Write(Byte(Start
));
3301 NetOut
.Write(Command
);
3302 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3305 procedure MC_SEND_PlayerSettings();
3307 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3308 NetOut
.Write(gPlayer1Settings
.Name
);
3309 NetOut
.Write(gPlayer1Settings
.Model
);
3310 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3311 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3312 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3313 NetOut
.Write(gPlayer1Settings
.Team
);
3314 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3317 procedure MC_SEND_FullStateRequest();
3319 NetOut
.Write(Byte(NET_MSG_REQFST
));
3321 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3324 procedure MC_SEND_CheatRequest(Kind
: Byte);
3326 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3329 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3331 procedure MC_SEND_RCONPassword(Password
: string);
3333 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3334 NetOut
.Write(Password
);
3336 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3338 procedure MC_SEND_RCONCommand(Cmd
: string);
3340 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3343 g_Net_Client_Send(True, NET_CHAN_SERVICE
);