3590bd43add3c68343b3c1535fe6d9b37cc5dee6
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;
459 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
460 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
461 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
465 with g_Player_Get(PID
) do
469 // round in progress, don't spawn
470 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
471 //e_LogWritefln('spawning player with pid #%u...', [PID]);
472 //Respawn(gGameSettings.GameType = GT_SINGLE);
473 //k8: no, do not spawn a player yet, wait for "request full state" packet
477 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
478 // that is, if we'll set it to `true`, the player can be spawned after
479 // warmup time ran out, for example, regardless of the real player state.
480 // also, this seems to work only for the initial connection. further
481 // map changes could initiate resource downloading, but the player will
482 // be spawned immediately.
483 // the proper solution will require another player state, "ephemeral".
484 // the player should start any map in "ephemeral" state, and turned into
485 // real mobj only when they sent a special "i am ready" packet. this packet
486 // must be sent after receiving the full state, so the player will get a full
487 // map view before going into game.
488 FWantsInGame
:= false;
489 C
^.WaitForFirstSpawn
:= true;
492 //if not C^.WaitForFirstSpawn then
494 for I
:= Low(NetClients
) to High(NetClients
) do
496 if NetClients
[I
].ID
= C
^.ID
then Continue
;
497 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
498 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
499 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
503 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
504 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
508 //g_Net_Slist_Update;
514 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
518 if not C
.WaitForFirstSpawn
then exit
;
519 plr
:= g_Player_Get(C
^.Player
);
520 if not assigned(plr
) then exit
;
521 g_Net_Slist_ServerPlayerComes();
522 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
523 C
.WaitForFirstSpawn
:= false;
524 plr
.FNoRespawn
:= false;
525 plr
.FWantsInGame
:= true; // TODO: look into this later
527 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
530 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
535 if gLMSRespawn
> LMS_RESPAWN_NONE
then
536 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
541 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
543 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
546 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
550 C
^.RequestedFullUpdate
:= True;
556 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
569 if not gGameOn
then Exit
;
572 GT
:= M
.ReadLongWord();
577 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
580 Pl
:= g_Player_Get(PID
);
584 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
590 kByte
:= M
.ReadWord();
592 WeaponAct
:= M
.ReadByte();
593 WeaponSelect
:= M
.ReadWord();
598 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
600 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
601 if Direction
<> TDirection(Dir
) then
602 JustTeleported
:= False;
604 SetDirection(TDirection(Dir
));
607 if kByte
= NET_KEY_CHAT
then
609 PressKey(KEY_CHAT
, 10000);
613 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
614 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
615 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
616 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
617 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
618 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
619 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
623 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
625 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
626 ProcessWeaponAction(i
);
632 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
634 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
635 QueueWeaponSwitch(i
);
640 // MH_SEND_PlayerPos(False, PID, C^.ID);
643 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
650 Pl
:= g_Player_Get(C
^.Player
);
651 if Pl
= nil then Exit
;
654 CheatKind
:= M
.ReadByte();
659 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
663 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
666 if Pl
.FSpectator
then
668 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
671 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
678 if gState
<> STATE_INTERCUSTOM
then Exit
;
679 Pl
.FReady
:= not Pl
.FReady
;
682 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
683 Inc(gInterReadyCount
);
687 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
688 Dec(gInterReadyCount
);
696 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
707 TmpName
:= M
.ReadString();
708 TmpModel
:= M
.ReadString();
709 TmpColor
.R
:= M
.ReadByte();
710 TmpColor
.G
:= M
.ReadByte();
711 TmpColor
.B
:= M
.ReadByte();
712 TmpTeam
:= M
.ReadByte();
717 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
719 Pl
:= g_Player_Get(C
^.Player
);
720 if Pl
= nil then Exit
;
722 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
725 Pl
.SetColor(TmpColor
);
727 if Pl
.Name
<> TmpName
then
729 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
733 if TmpModel
<> Pl
.Model
.Name
then
734 Pl
.SetModel(TmpModel
);
736 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
741 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
748 Pwd
:= M
.ReadString();
752 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
753 if not NetAllowRCON
then Exit
;
754 if Pwd
= NetRCONPassword
then
757 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
760 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
763 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
770 Cmd
:= M
.ReadString();
774 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
775 if not NetAllowRCON
then Exit
;
776 if not C
^.RCONAuth
then
778 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
781 g_Console_Process(Cmd
);
786 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
789 Name
, Command
: string;
796 Start
:= M
.ReadByte() <> 0;
797 Command
:= M
.ReadString();
802 if Err
then begin MH_MalformedPacket(C
); Exit
; end;
804 Pl
:= g_Player_Get(C
^.Player
);
805 if Pl
= nil then Exit
;
810 if not g_Console_CommandBlacklisted(Command
) then
811 g_Game_StartVote(Command
, Name
);
813 else if gVoteInProgress
then
815 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
816 Need
:= Floor((NetClientCount
+1)/2.0) + 1
818 Need
:= Floor(NetClientCount
/2.0) + 1;
823 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
824 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
830 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
831 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
839 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
841 function sendItemRespawn (it
: PItem
): Boolean;
843 result
:= false; // don't stop
844 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
847 function sendMonSpawn (mon
: TMonster
): Boolean;
849 result
:= false; // don't stop
850 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
853 function sendPanelState (pan
: TPanel
): Boolean;
855 result
:= false; // don't stop
856 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
857 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
863 if (ID
>= 0) and (ID
< length(NetClients
)) then
865 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
866 MH_ProcessFirstSpawn(@NetClients
[ID
]);
869 if gPlayers
<> nil then
871 for I
:= Low(gPlayers
) to High(gPlayers
) do
873 if gPlayers
[I
] <> nil then
875 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
876 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
877 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
879 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
881 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
887 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
888 g_Mons_ForEach(sendMonSpawn
);
889 g_Map_ForEachPanel(sendPanelState
);
891 if gTriggers
<> nil then
893 for I
:= Low(gTriggers
) to High(gTriggers
) do
895 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
897 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
904 for I
:= Low(Shots
) to High(Shots
) do
906 if Shots
[i
].ShotType
in [6, 7, 8] then
908 MH_SEND_CreateShot(i
, ID
);
913 MH_SEND_TriggerMusic(ID
);
915 MH_SEND_GameStats(ID
);
916 MH_SEND_CoopStats(ID
);
918 if gGameSettings
.GameMode
= GM_CTF
then
920 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
921 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
924 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
929 procedure MH_SEND_Info(ID
: Byte);
933 NetOut
.Write(Byte(NET_MSG_INFO
));
935 NetOut
.Write(NetClients
[ID
].Player
);
936 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
937 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
938 NetOut
.Write(gWADHash
);
939 NetOut
.Write(gGameSettings
.GameMode
);
940 NetOut
.Write(gGameSettings
.GoalLimit
);
941 NetOut
.Write(gGameSettings
.TimeLimit
);
942 NetOut
.Write(gGameSettings
.MaxLives
);
943 NetOut
.Write(gGameSettings
.Options
);
946 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
949 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
955 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
956 Mode
:= NET_CHAT_PLAYER
;
959 if (Mode
= NET_CHAT_TEAM
) then
961 for i
:= Low(gPlayers
) to High(gPlayers
) do
962 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
963 (gPlayers
[i
].Team
= ID
) then
965 NetOut
.Write(Byte(NET_MSG_CHAT
));
968 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
975 NetOut
.Write(Byte(NET_MSG_CHAT
));
978 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
981 if Mode
= NET_CHAT_SYSTEM
then
984 if ID
= NET_EVERYONE
then
986 if Mode
= NET_CHAT_PLAYER
then
988 g_Console_Add(Txt
, True);
989 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
990 g_Game_ChatSound(b_Text_Unformat(Txt
));
993 if Mode
= NET_CHAT_TEAM
then
994 if gPlayer1
<> nil then
996 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
998 g_Console_Add(#18'[Team] '#2 + Txt
, True);
999 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1000 g_Game_ChatSound(b_Text_Unformat(Txt
));
1002 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
1004 g_Console_Add(#20'[Team] '#2 + Txt
, True);
1005 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1006 g_Game_ChatSound(b_Text_Unformat(Txt
));
1012 Name
:= g_Net_ClientName_ByID(ID
);
1013 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
1014 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1015 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
1019 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
1021 NetOut
.Write(Byte(NET_MSG_GFX
));
1027 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1030 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1032 NetOut
.Write(Byte(NET_MSG_SND
));
1036 NetOut
.Write(Byte(1));
1041 NetOut
.Write(Byte(0));
1043 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
1046 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1048 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1050 NetOut
.Write(Byte(NET_MSG_SHADD
));
1052 NetOut
.Write(Shots
[Proj
].ShotType
);
1053 NetOut
.Write(Shots
[Proj
].Target
);
1054 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
1055 NetOut
.Write(Shots
[Proj
].Timeout
);
1056 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1057 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1058 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1059 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1061 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1064 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
1066 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
1068 NetOut
.Write(Byte(NET_MSG_SHPOS
));
1070 NetOut
.Write(Shots
[Proj
].Obj
.X
);
1071 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
1072 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
1073 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
1075 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
1078 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
1080 NetOut
.Write(Byte(NET_MSG_SHDEL
));
1082 NetOut
.Write(Byte(Loud
));
1086 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1089 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1091 NetOut
.Write(Byte(NET_MSG_SCORE
));
1092 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1094 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1095 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1098 if gGameSettings
.GameMode
= GM_COOP
then
1100 NetOut
.Write(gCoopMonstersKilled
);
1101 NetOut
.Write(gCoopSecretsFound
);
1104 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1107 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1109 NetOut
.Write(Byte(NET_MSG_COOP
));
1110 NetOut
.Write(gTotalMonsters
);
1111 NetOut
.Write(gSecretsCount
);
1112 NetOut
.Write(gCoopTotalMonstersKilled
);
1113 NetOut
.Write(gCoopTotalSecretsFound
);
1114 NetOut
.Write(gCoopTotalMonsters
);
1115 NetOut
.Write(gCoopTotalSecrets
);
1118 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1120 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1121 NetOut
.Write(EvType
);
1122 NetOut
.Write(EvNum
);
1123 NetOut
.Write(EvStr
);
1124 NetOut
.Write(Byte(gLastMap
));
1125 NetOut
.Write(gTime
);
1126 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1128 NetOut
.Write(Byte(1));
1129 NetOut
.Write(gWADHash
);
1131 NetOut
.Write(Byte(0));
1133 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1136 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1138 NetOut
.Write(Byte(NET_MSG_FLAG
));
1139 NetOut
.Write(EvType
);
1141 NetOut
.Write(Byte(Quiet
));
1143 NetOut
.Write(gFlags
[Flag
].State
);
1144 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1145 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1146 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1147 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1148 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1149 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1151 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1154 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1156 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1158 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1159 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1160 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1161 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1163 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1166 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1168 NetOut
.Write(Byte(NET_MSG_GSET
));
1169 NetOut
.Write(gGameSettings
.GameMode
);
1170 NetOut
.Write(gGameSettings
.GoalLimit
);
1171 NetOut
.Write(gGameSettings
.TimeLimit
);
1172 NetOut
.Write(gGameSettings
.MaxLives
);
1173 NetOut
.Write(gGameSettings
.Options
);
1175 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1180 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1184 P
:= g_Player_Get(PID
);
1185 if P
= nil then Exit
;
1187 NetOut
.Write(Byte(NET_MSG_PLR
));
1189 NetOut
.Write(P
.Name
);
1191 NetOut
.Write(P
.FActualModelName
);
1192 NetOut
.Write(P
.FColor
.R
);
1193 NetOut
.Write(P
.FColor
.G
);
1194 NetOut
.Write(P
.FColor
.B
);
1195 NetOut
.Write(P
.Team
);
1197 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1200 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1205 Pl
:= g_Player_Get(PID
);
1206 if Pl
= nil then Exit
;
1207 if Pl
.FDummy
then Exit
;
1209 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1210 NetOut
.Write(gTime
);
1217 NetOut
.Write(FPing
);
1218 NetOut
.Write(FLoss
);
1219 if IsKeyPressed(KEY_CHAT
) then
1220 kByte
:= NET_KEY_CHAT
1223 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1224 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1225 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1226 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1227 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1230 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1232 NetOut
.Write(kByte
);
1233 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1234 NetOut
.Write(GameX
);
1235 NetOut
.Write(GameY
);
1236 NetOut
.Write(GameVelX
);
1237 NetOut
.Write(GameVelY
);
1238 NetOut
.Write(GameAccelX
);
1239 NetOut
.Write(GameAccelY
);
1242 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1245 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1250 P
:= g_Player_Get(PID
);
1251 if P
= nil then Exit
;
1253 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1258 NetOut
.Write(Byte(alive
));
1259 NetOut
.Write(Byte(GodMode
));
1260 NetOut
.Write(Health
);
1261 NetOut
.Write(Armor
);
1263 NetOut
.Write(JetFuel
);
1264 NetOut
.Write(Lives
);
1267 for I
:= WP_FIRST
to WP_LAST
do
1268 NetOut
.Write(Byte(FWeapon
[I
]));
1270 for I
:= A_BULLETS
to A_HIGH
do
1271 NetOut
.Write(FAmmo
[I
]);
1273 for I
:= A_BULLETS
to A_HIGH
do
1274 NetOut
.Write(FMaxAmmo
[I
]);
1276 for I
:= MR_SUIT
to MR_MAX
do
1277 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1279 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1280 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1281 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1282 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1283 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1285 NetOut
.Write(Frags
);
1286 NetOut
.Write(Death
);
1288 NetOut
.Write(CurrWeap
);
1290 NetOut
.Write(Byte(FSpectator
));
1291 NetOut
.Write(Byte(FGhost
));
1292 NetOut
.Write(Byte(FPhysics
));
1293 NetOut
.Write(Byte(FNoRespawn
));
1294 NetOut
.Write(Byte(FJetpack
));
1295 NetOut
.Write(FFireTime
);
1296 NetOut
.Write(Byte(FFlaming
));
1297 NetOut
.Write(FSpawnInvul
);
1300 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1303 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1305 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1308 NetOut
.Write(Attacker
);
1309 NetOut
.Write(Value
);
1313 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1316 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1318 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1320 NetOut
.Write(KillType
);
1321 NetOut
.Write(DeathType
);
1322 NetOut
.Write(Attacker
);
1324 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1327 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1329 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1331 NetOut
.Write(Weapon
);
1336 NetOut
.Write(ShotID
);
1338 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1341 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1343 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1346 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1349 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1353 Pl
:= g_Player_Get(PID
);
1354 if Pl
= nil then Exit
;
1356 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1358 NetOut
.Write(Pl
.Name
);
1360 NetOut
.Write(Pl
.Model
.Name
)
1363 NetOut
.Write(Pl
.FColor
.R
);
1364 NetOut
.Write(Pl
.FColor
.G
);
1365 NetOut
.Write(Pl
.FColor
.B
);
1366 NetOut
.Write(Pl
.Team
);
1368 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1373 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1378 it
:= g_Items_ByIdx(IID
);
1380 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1382 NetOut
.Write(Byte(Quiet
));
1384 if it
.dropped
then tt
:= tt
or $80;
1386 NetOut
.Write(Byte(it
.Fall
));
1387 NetOut
.Write(Byte(it
.Respawnable
));
1388 NetOut
.Write(it
.Obj
.X
);
1389 NetOut
.Write(it
.Obj
.Y
);
1390 NetOut
.Write(it
.Obj
.Vel
.X
);
1391 NetOut
.Write(it
.Obj
.Vel
.Y
);
1393 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1396 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1398 NetOut
.Write(Byte(NET_MSG_IDEL
));
1400 NetOut
.Write(Byte(Quiet
));
1402 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1405 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1409 it
:= g_Items_ByIdx(IID
);
1411 NetOut
.Write(Byte(NET_MSG_IPOS
));
1413 NetOut
.Write(it
.Obj
.X
);
1414 NetOut
.Write(it
.Obj
.Y
);
1415 NetOut
.Write(it
.Obj
.Vel
.X
);
1416 NetOut
.Write(it
.Obj
.Vel
.Y
);
1418 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1423 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1427 TP
:= g_Map_PanelByGUID(PGUID
);
1428 if (TP
= nil) then exit
;
1432 NetOut
.Write(Byte(NET_MSG_PTEX
));
1433 NetOut
.Write(LongWord(PGUID
));
1434 NetOut
.Write(FCurTexture
);
1435 NetOut
.Write(FCurFrame
);
1436 NetOut
.Write(FCurFrameCount
);
1437 NetOut
.Write(AnimLoop
);
1440 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1443 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1448 TP
:= g_Map_PanelByGUID(PGUID
);
1449 if (TP
= nil) then exit
;
1451 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1452 NetOut
.Write(LongWord(PGUID
));
1453 NetOut
.Write(Byte(TP
.Enabled
));
1454 NetOut
.Write(TP
.LiftType
);
1457 NetOut
.Write(Word(TP
.Width
));
1458 NetOut
.Write(Word(TP
.Height
));
1460 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1461 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1462 NetOut
.Write(LongInt(TP
.movingStartX
));
1463 NetOut
.Write(LongInt(TP
.movingStartY
));
1464 NetOut
.Write(LongInt(TP
.movingEndX
));
1465 NetOut
.Write(LongInt(TP
.movingEndY
));
1466 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1467 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1468 NetOut
.Write(LongInt(TP
.sizeEndX
));
1469 NetOut
.Write(LongInt(TP
.sizeEndY
));
1470 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1471 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1472 NetOut
.Write(Byte(mpflags
));
1474 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1479 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1481 if gTriggers
= nil then Exit
;
1482 if T
.Sound
= nil then Exit
;
1484 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1485 NetOut
.Write(T
.ClientID
);
1486 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1487 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1488 NetOut
.Write(T
.SoundPlayCount
);
1490 g_Net_Host_Send(ID
, True);
1493 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1495 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1496 NetOut
.Write(gMusic
.Name
);
1497 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1498 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1499 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1501 g_Net_Host_Send(ID
, True);
1506 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1510 M
:= g_Monsters_ByUID(UID
);
1516 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1518 NetOut
.Write(MonsterType
);
1519 NetOut
.Write(MonsterState
);
1520 NetOut
.Write(MonsterAnim
);
1521 NetOut
.Write(MonsterTargetUID
);
1522 NetOut
.Write(MonsterTargetTime
);
1523 NetOut
.Write(MonsterBehaviour
);
1524 NetOut
.Write(MonsterSleep
);
1525 NetOut
.Write(MonsterHealth
);
1526 NetOut
.Write(MonsterAmmo
);
1527 NetOut
.Write(GameX
);
1528 NetOut
.Write(GameY
);
1529 NetOut
.Write(GameVelX
);
1530 NetOut
.Write(GameVelY
);
1531 NetOut
.Write(Byte(GameDirection
));
1534 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1537 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1541 M
:= g_Monsters_ByUID(UID
);
1542 if M
= nil then Exit
;
1544 NetOut
.Write(Byte(NET_MSG_MPOS
));
1549 NetOut
.Write(GameX
);
1550 NetOut
.Write(GameY
);
1551 NetOut
.Write(GameVelX
);
1552 NetOut
.Write(GameVelY
);
1553 NetOut
.Write(Byte(GameDirection
));
1556 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1559 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1563 M
:= g_Monsters_ByUID(UID
);
1564 if M
= nil then Exit
;
1566 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1571 NetOut
.Write(MonsterState
);
1572 NetOut
.Write(ForcedAnim
);
1573 NetOut
.Write(MonsterTargetUID
);
1574 NetOut
.Write(MonsterTargetTime
);
1575 NetOut
.Write(MonsterSleep
);
1576 NetOut
.Write(MonsterHealth
);
1577 NetOut
.Write(MonsterAmmo
);
1578 NetOut
.Write(MonsterPain
);
1579 NetOut
.Write(Byte(AnimIsReverse
));
1580 NetOut
.Write(FFireTime
);
1583 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1586 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1588 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1595 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1598 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1602 M
:= g_Monsters_ByUID(UID
);
1603 if M
= nil then Exit
;
1605 NetOut
.Write(Byte(NET_MSG_MDEL
));
1608 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1613 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1615 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1618 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1621 procedure MH_SEND_VoteEvent(EvType
: Byte;
1622 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1623 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1624 ID
: Integer = NET_EVERYONE
);
1626 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1627 NetOut
.Write(EvType
);
1628 NetOut
.Write(IntArg1
);
1629 NetOut
.Write(IntArg2
);
1630 NetOut
.Write(StrArg1
);
1631 NetOut
.Write(StrArg2
);
1633 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1636 // CLIENT MESSAGES //
1640 procedure MC_RECV_Chat(var M
: TMsg
);
1645 Txt
:= M
.ReadString();
1646 Mode
:= M
.ReadByte();
1648 if Mode
<> NET_CHAT_SYSTEM
then
1650 if NetDeafLevel
= 0 then
1652 if Mode
= NET_CHAT_PLAYER
then
1654 g_Console_Add(Txt
, True);
1655 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1656 g_Game_ChatSound(b_Text_Unformat(Txt
));
1658 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1660 if gPlayer1
.Team
= TEAM_RED
then
1661 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1662 if gPlayer1
.Team
= TEAM_BLUE
then
1663 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1664 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1665 g_Game_ChatSound(b_Text_Unformat(Txt
));
1668 end else if (NetDeafLevel
< 2) then
1669 g_Console_Add(Txt
, True);
1672 procedure MC_RECV_Effect(var M
: TMsg
);
1680 if not gGameOn
then Exit
;
1681 Kind
:= M
.ReadByte();
1682 X
:= M
.ReadLongInt();
1683 Y
:= M
.ReadLongInt();
1684 Ang
:= M
.ReadSmallInt();
1688 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1692 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1694 Anim
:= TAnimation
.Create(ID
, False, 3);
1695 g_GFX_OnceAnim(X
, Y
, Anim
);
1699 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1704 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1706 Anim
:= TAnimation
.Create(ID
, False, 6);
1707 Anim
.Blending
:= False;
1708 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1712 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1717 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1719 Anim
:= TAnimation
.Create(ID
, False, 6);
1720 Anim
.Blending
:= False;
1721 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1725 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1730 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1732 Anim
:= TAnimation
.Create(ID
, False, 4);
1733 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1740 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1742 Anim
:= TAnimation
.Create(ID
, False, 4);
1743 g_GFX_OnceAnim(X
, Y
, Anim
);
1747 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1752 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1754 Anim
:= TAnimation
.Create(ID
, False, 4);
1755 g_GFX_OnceAnim(X
, Y
, Anim
);
1759 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1763 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1766 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1770 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1771 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1776 procedure MC_RECV_Sound(var M
: TMsg
);
1782 Name
:= M
.ReadString();
1783 Pos
:= M
.ReadByte() <> 0;
1786 X
:= M
.ReadLongInt();
1787 Y
:= M
.ReadLongInt();
1788 g_Sound_PlayExAt(Name
, X
, Y
);
1791 g_Sound_PlayEx(Name
);
1794 procedure MC_RECV_CreateShot(var M
: TMsg
);
1796 I
, X
, Y
, XV
, YV
: Integer;
1798 Target
, Spawner
: Word;
1801 I
:= M
.ReadLongInt();
1802 ShType
:= M
.ReadByte();
1803 Target
:= M
.ReadWord();
1804 Spawner
:= M
.ReadWord();
1805 Timeout
:= M
.ReadLongWord();
1806 X
:= M
.ReadLongInt();
1807 Y
:= M
.ReadLongInt();
1808 XV
:= M
.ReadLongInt();
1809 YV
:= M
.ReadLongInt();
1811 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1812 if (Shots
<> nil) and (I
<= High(Shots
)) then
1814 Shots
[I
].Timeout
:= Timeout
;
1815 //Shots[I].Target := Target; // TODO: find a use for Target later
1819 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1821 I
, TX
, TY
, TXV
, TYV
: Integer;
1823 I
:= M
.ReadLongInt();
1824 TX
:= M
.ReadLongInt();
1825 TY
:= M
.ReadLongInt();
1826 TXV
:= M
.ReadLongInt();
1827 TYV
:= M
.ReadLongInt();
1829 if (Shots
<> nil) and (I
<= High(Shots
)) then
1839 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1844 if not gGameOn
then Exit
;
1845 I
:= M
.ReadLongInt();
1846 L
:= (M
.ReadByte() <> 0);
1847 X
:= M
.ReadLongInt();
1848 Y
:= M
.ReadLongInt();
1850 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1853 procedure MC_RECV_GameStats(var M
: TMsg
);
1855 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1857 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1858 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1861 if gGameSettings
.GameMode
= GM_COOP
then
1863 gCoopMonstersKilled
:= M
.ReadWord();
1864 gCoopSecretsFound
:= M
.ReadWord();
1868 procedure MC_RECV_CoopStats(var M
: TMsg
);
1870 gTotalMonsters
:= M
.ReadLongInt();
1871 gSecretsCount
:= M
.ReadLongInt();
1872 gCoopTotalMonstersKilled
:= M
.ReadWord();
1873 gCoopTotalSecretsFound
:= M
.ReadWord();
1874 gCoopTotalMonsters
:= M
.ReadWord();
1875 gCoopTotalSecrets
:= M
.ReadWord();
1878 procedure MC_RECV_GameEvent(var M
: TMsg
);
1887 i1
, i2
: TStrings_Locale
;
1890 goodCmd
: Boolean = true;
1892 FillChar(EvHash
, Sizeof(EvHash
), 0);
1893 EvType
:= M
.ReadByte();
1894 EvNum
:= M
.ReadLongInt();
1895 EvStr
:= M
.ReadString();
1896 gLastMap
:= M
.ReadByte() <> 0;
1897 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1898 gStatsPressed
:= True;
1899 EvTime
:= M
.ReadLongWord();
1900 BHash
:= M
.ReadByte() <> 0;
1902 EvHash
:= M
.ReadMD5();
1906 if (g_Res_received_map_start
<> 0) then
1908 if (g_Res_received_map_start
< 0) then exit
;
1911 NET_EV_MAPSTART
: goodCmd
:= true;
1912 NET_EV_MAPEND
: goodCmd
:= true;
1913 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1914 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1915 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1917 if not goodCmd
then exit
;
1923 if (g_Res_received_map_start
<> 0) then
1925 g_Res_received_map_start
:= -1;
1930 g_Game_ClearLoading();
1931 g_Game_StopAllSounds(True);
1933 gSwitchGameMode
:= Byte(EvNum
);
1934 gGameSettings
.GameMode
:= gSwitchGameMode
;
1937 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1939 if not isWadPath(EvStr
) then
1940 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1942 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1946 MC_SEND_FullStateRequest
;
1952 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1953 gLMSRespawnTime
:= 0;
1954 if (g_Res_received_map_start
<> 0) then
1956 g_Res_received_map_start
:= -1;
1960 gMissionFailed
:= EvNum
<> 0;
1961 gExit
:= EXIT_ENDLEVELCUSTOM
;
1969 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1971 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1973 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1979 if NetDeafLevel
< 2 then
1981 if EvNum
= TEAM_RED
then
1982 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1983 if EvNum
= TEAM_BLUE
then
1984 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1990 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1991 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1996 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1997 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
2004 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
2005 gLMSRespawnTime
:= gTime
+ EvNum
;
2006 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
2008 else if gPlayer1
= nil then
2010 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2014 NET_EV_LMS_SURVIVOR
:
2015 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
2018 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
2022 pl
:= g_Player_Get(EvNum
and $FFFF);
2027 cnt
:= (EvNum
shr 16) and $FF;
2028 if Pos('w', EvStr
) = 0 then
2031 if Pos('t', EvStr
) = 0 then
2034 if Pos('-', EvStr
) = 0 then
2036 if Pos('e', EvStr
) = 0 then
2037 i1
:= I_PLAYER_SCORE_ADD_OWN
2039 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
2042 if Pos('e', EvStr
) = 0 then
2043 i1
:= I_PLAYER_SCORE_SUB_OWN
2045 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
2048 if Pos('r', EvStr
) > 0 then
2049 i2
:= I_PLAYER_SCORE_TO_RED
2051 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2052 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
2056 if Pos('-', EvStr
) = 0 then
2057 i1
:= I_PLAYER_SCORE_ADD_TEAM
2059 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
2061 if Pos('r', EvStr
) > 0 then
2062 i2
:= I_PLAYER_SCORE_RED
2064 i2
:= I_PLAYER_SCORE_BLUE
;
2065 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
2070 if Pos('e', EvStr
) = 0 then
2071 i1
:= I_PLAYER_SCORE_WIN_OWN
2073 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
2075 if Pos('r', EvStr
) > 0 then
2076 i2
:= I_PLAYER_SCORE_TO_RED
2078 i2
:= I_PLAYER_SCORE_TO_BLUE
;
2079 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
2085 if EvNum
= TEAM_RED
then
2086 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2087 if EvNum
= TEAM_BLUE
then
2088 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2089 if EvNum
= -TEAM_RED
then
2090 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2091 if EvNum
= -TEAM_BLUE
then
2092 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2097 g_Player_RemoveAllCorpses
;
2098 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2099 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2103 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2107 if EvNum
= TEAM_RED
then
2108 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2109 if EvNum
= TEAM_BLUE
then
2110 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2114 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2117 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2120 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2123 g_Game_Announce_KillCombo(EvNum
);
2125 NET_EV_PLAYER_TOUCH
:
2127 pl
:= g_Player_Get(EvNum
);
2134 pl
:= g_Player_Get(EvNum
);
2137 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2138 g_Sound_PlayEx('SOUND_GAME_SECRET');
2144 pl
:= g_Player_Get(EvNum
);
2145 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2150 procedure MC_RECV_FlagPos(var M
: TMsg
);
2155 if Fl
= FLAG_NONE
then Exit
;
2156 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2157 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2158 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2159 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2162 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2171 EvType
:= M
.ReadByte();
2174 if Fl
= FLAG_NONE
then Exit
;
2176 Quiet
:= (M
.ReadByte() <> 0);
2177 PID
:= M
.ReadWord();
2179 gFlags
[Fl
].State
:= M
.ReadByte();
2180 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2181 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2182 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2183 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2184 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2185 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2187 Pl
:= g_Player_Get(PID
);
2189 (EvType
<> FLAG_STATE_NORMAL
) and
2190 (EvType
<> FLAG_STATE_DROPPED
) and
2191 (EvType
<> FLAG_STATE_RETURNED
) then
2197 if Quiet
or (Pl
= nil) then Exit
;
2199 if Fl
= FLAG_RED
then
2200 s
:= _lc
[I_PLAYER_FLAG_RED
]
2202 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2204 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2206 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2207 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2208 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2213 if not sound_ret_flag
[a
].IsPlaying() then
2214 sound_ret_flag
[a
].Play();
2217 FLAG_STATE_CAPTURED
:
2219 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2223 if Fl
= FLAG_RED
then
2224 s
:= _lc
[I_PLAYER_FLAG_RED
]
2226 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2228 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2229 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2231 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2232 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2233 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2238 if not sound_get_flag
[a
].IsPlaying() then
2239 sound_get_flag
[a
].Play();
2244 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2246 if Quiet
or (Pl
= nil) then Exit
;
2248 if Fl
= FLAG_RED
then
2249 s
:= _lc
[I_PLAYER_FLAG_RED
]
2251 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2253 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2254 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2256 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2257 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2258 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2263 if not sound_lost_flag
[a
].IsPlaying() then
2264 sound_lost_flag
[a
].Play();
2269 g_Map_ResetFlag(FLAG_RED
);
2270 g_Map_ResetFlag(FLAG_BLUE
);
2271 if Quiet
or (Pl
= nil) then Exit
;
2272 Pl
.SetFlag(FLAG_NONE
);
2274 if Fl
= FLAG_RED
then
2275 s
:= _lc
[I_PLAYER_FLAG_RED
]
2277 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2279 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2280 Insert('.', ts
, Length(ts
) + 1 - 3);
2281 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2282 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2284 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2285 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2286 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2291 if not sound_cap_flag
[a
].IsPlaying() then
2292 sound_cap_flag
[a
].Play();
2295 FLAG_STATE_RETURNED
:
2297 g_Map_ResetFlag(Fl
);
2300 if Fl
= FLAG_RED
then
2301 s
:= _lc
[I_PLAYER_FLAG_RED
]
2303 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2305 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2307 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2308 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2309 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2314 if not sound_ret_flag
[a
].IsPlaying() then
2315 sound_ret_flag
[a
].Play();
2320 procedure MC_RECV_GameSettings(var M
: TMsg
);
2322 gGameSettings
.GameMode
:= M
.ReadByte();
2323 gGameSettings
.GoalLimit
:= M
.ReadWord();
2324 gGameSettings
.TimeLimit
:= M
.ReadWord();
2325 gGameSettings
.MaxLives
:= M
.ReadByte();
2326 gGameSettings
.Options
:= M
.ReadLongWord();
2331 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2334 PName
, Model
: string;
2339 PID
:= M
.ReadWord();
2340 Pl
:= g_Player_Get(PID
);
2342 PName
:= M
.ReadString();
2343 Model
:= M
.ReadString();
2344 Color
.R
:= M
.ReadByte();
2345 Color
.G
:= M
.ReadByte();
2346 Color
.B
:= M
.ReadByte();
2350 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2352 if (Pl
<> nil) then Exit
;
2353 DID
:= g_Player_Create(Model
, Color
, T
, False);
2354 with g_Player_Get(DID
) do
2363 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2364 gPlayer1
.UID
:= PID
;
2365 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2366 gPlayer1
.ChangeTeam(T
);
2368 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2369 gPlayer2
.UID
:= PID
;
2370 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2371 gPlayer2
.ChangeTeam(T
);
2375 if NetDeafLevel
< 3 then
2376 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2377 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2381 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2388 TmpX
, TmpY
: Integer;
2392 GT
:= M
.ReadLongWord();
2393 if GT
< gTime
- NET_MAX_DIFFTIME
then
2400 PID
:= M
.ReadWord();
2401 Pl
:= g_Player_Get(PID
);
2403 if Pl
= nil then Exit
;
2409 FPing
:= M
.ReadWord();
2410 FLoss
:= M
.ReadByte();
2411 kByte
:= M
.ReadWord();
2412 Dir
:= M
.ReadByte();
2414 TmpX
:= M
.ReadLongInt();
2415 TmpY
:= M
.ReadLongInt();
2419 if LongBool(kByte
and NET_KEY_CHAT
) then
2420 PressKey(KEY_CHAT
, 10000)
2423 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2424 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2425 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2426 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2427 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2430 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2432 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2433 SetDirection(TDirection(Dir
));
2435 GameVelX
:= M
.ReadLongInt();
2436 GameVelY
:= M
.ReadLongInt();
2437 GameAccelX
:= M
.ReadLongInt();
2438 GameAccelY
:= M
.ReadLongInt();
2439 SetLerp(TmpX
, TmpY
);
2440 if NetForcePlayerUpdate
then Update();
2444 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2448 I
, OldFire
: Integer;
2449 OldJet
, Flam
: Boolean;
2452 PID
:= M
.ReadWord();
2453 Pl
:= g_Player_Get(PID
);
2460 alive
:= (M
.ReadByte() <> 0);
2461 GodMode
:= (M
.ReadByte() <> 0);
2462 Health
:= M
.ReadLongInt();
2463 Armor
:= M
.ReadLongInt();
2464 Air
:= M
.ReadLongInt();
2465 JetFuel
:= M
.ReadLongInt();
2466 Lives
:= M
.ReadByte();
2467 NewTeam
:= M
.ReadByte();
2469 for I
:= WP_FIRST
to WP_LAST
do
2470 FWeapon
[I
] := (M
.ReadByte() <> 0);
2472 for I
:= A_BULLETS
to A_HIGH
do
2473 FAmmo
[I
] := M
.ReadWord();
2475 for I
:= A_BULLETS
to A_HIGH
do
2476 FMaxAmmo
[I
] := M
.ReadWord();
2478 for I
:= MR_SUIT
to MR_MAX
do
2479 FMegaRulez
[I
] := M
.ReadLongWord();
2482 if (M
.ReadByte() <> 0) then
2483 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2484 if (M
.ReadByte() <> 0) then
2485 FRulez
:= FRulez
+ [R_KEY_RED
];
2486 if (M
.ReadByte() <> 0) then
2487 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2488 if (M
.ReadByte() <> 0) then
2489 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2490 if (M
.ReadByte() <> 0) then
2491 FRulez
:= FRulez
+ [R_BERSERK
];
2493 Frags
:= M
.ReadLongInt();
2494 Death
:= M
.ReadLongInt();
2496 SetWeapon(M
.ReadByte());
2498 FSpectator
:= M
.ReadByte() <> 0;
2501 if UID
= NetPlrUID1
then
2503 gSpectLatchPID1
:= UID
;
2506 if UID
= NetPlrUID2
then
2508 gSpectLatchPID2
:= UID
;
2514 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2517 gSpectLatchPID1
:= 0;
2519 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2522 gSpectLatchPID2
:= 0;
2525 FGhost
:= M
.ReadByte() <> 0;
2526 FPhysics
:= M
.ReadByte() <> 0;
2527 FNoRespawn
:= M
.ReadByte() <> 0;
2529 FJetpack
:= M
.ReadByte() <> 0;
2530 OldFire
:= FFireTime
;
2531 FFireTime
:= M
.ReadLongInt();
2532 if (OldFire
<= 0) and (FFireTime
> 0) then
2533 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2534 Flam
:= M
.ReadByte() <> 0;
2535 FSpawnInvul
:= M
.ReadLongInt();
2536 if OldJet
and not FJetpack
then
2538 else if not OldJet
and FJetpack
then
2540 if FFlaming
and not Flam
then
2542 if Team
<> NewTeam
then
2543 Pl
.ChangeTeam(NewTeam
);
2549 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2554 Attacker
, Value
: Word;
2558 if not gGameOn
then Exit
;
2559 PID
:= M
.ReadWord();
2560 Pl
:= g_Player_Get(PID
);
2561 if Pl
= nil then Exit
;
2563 Kind
:= M
.ReadByte();
2564 Attacker
:= M
.ReadWord();
2565 Value
:= M
.ReadWord();
2570 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2575 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2579 KillType
, DeathType
: Byte;
2583 if not gGameOn
then Exit
;
2584 PID
:= M
.ReadWord();
2585 Pl
:= g_Player_Get(PID
);
2586 if Pl
= nil then Exit
;
2588 KillType
:= M
.ReadByte();
2589 DeathType
:= M
.ReadByte();
2590 Attacker
:= M
.ReadWord();
2594 Kill(KillType
, Attacker
, DeathType
);
2599 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2604 PID
:= M
.ReadWord();
2605 Pl
:= g_Player_Get(PID
);
2607 if Pl
= nil then Exit
;
2609 if NetDeafLevel
< 3 then
2610 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2611 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2613 g_Player_Remove(PID
);
2618 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2623 X
, Y
, AX
, AY
: Integer;
2627 if not gGameOn
then Exit
;
2628 PID
:= M
.ReadWord();
2629 Pl
:= g_Player_Get(PID
);
2630 if Pl
= nil then Exit
;
2632 Weap
:= M
.ReadByte();
2633 X
:= M
.ReadLongInt();
2634 Y
:= M
.ReadLongInt();
2635 AX
:= M
.ReadLongInt();
2636 AY
:= M
.ReadLongInt();
2637 SHID
:= M
.ReadLongInt();
2640 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2643 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2652 PID
:= M
.ReadWord();
2653 Pl
:= g_Player_Get(PID
);
2654 if Pl
= nil then Exit
;
2656 TmpName
:= M
.ReadString();
2657 TmpModel
:= M
.ReadString();
2658 TmpColor
.R
:= M
.ReadByte();
2659 TmpColor
.G
:= M
.ReadByte();
2660 TmpColor
.B
:= M
.ReadByte();
2661 TmpTeam
:= M
.ReadByte();
2663 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2665 Pl
.ChangeTeam(TmpTeam
);
2666 if gPlayer1
= Pl
then
2667 gPlayer1Settings
.Team
:= TmpTeam
;
2668 if gPlayer2
= Pl
then
2669 gPlayer2Settings
.Team
:= TmpTeam
;
2671 Pl
.SetColor(TmpColor
);
2673 if Pl
.Name
<> TmpName
then
2675 if NetDeafLevel
< 3 then
2676 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2680 if TmpModel
<> Pl
.Model
.Name
then
2681 Pl
.SetModel(TmpModel
);
2686 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2690 X
, Y
, VX
, VY
: Integer;
2692 Quiet
, Fall
{, Resp}: Boolean;
2696 if not gGameOn
then Exit
;
2698 Quiet
:= M
.ReadByte() <> 0;
2700 Fall
:= M
.ReadByte() <> 0;
2701 {Resp :=} M
.ReadByte();
2702 X
:= M
.ReadLongInt();
2703 Y
:= M
.ReadLongInt();
2704 VX
:= M
.ReadLongInt();
2705 VY
:= M
.ReadLongInt();
2707 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2708 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2710 it
:= g_Items_ByIdx(ID
);
2716 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2717 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2719 Anim
:= TAnimation
.Create(AID
, False, 4);
2720 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2726 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2731 if not gGameOn
then Exit
;
2733 Quiet
:= M
.ReadByte() <> 0;
2735 if not g_Items_ValidId(ID
) then exit
;
2737 if not Quiet
then g_Items_EmitPickupSound(ID
);
2742 procedure MC_RECV_ItemPos(var M
: TMsg
);
2745 X
, Y
, VX
, VY
: Integer;
2748 if not gGameOn
then Exit
;
2751 X
:= M
.ReadLongInt();
2752 Y
:= M
.ReadLongInt();
2753 VX
:= M
.ReadLongInt();
2754 VY
:= M
.ReadLongInt();
2756 if g_Items_ValidId(ID
) then
2758 it
:= g_Items_ByIdx(ID
);
2763 it
.positionChanged();
2769 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2776 if not gGameOn
then Exit
;
2778 PGUID
:= Integer(M
.ReadLongWord());
2779 Tex
:= M
.ReadLongInt();
2780 Fr
:= M
.ReadLongInt();
2781 Cnt
:= M
.ReadByte();
2782 Loop
:= M
.ReadByte();
2784 TP
:= g_Map_PanelByGUID(PGUID
);
2788 TP
.SetTexture(Tex
, Loop
);
2789 TP
.SetFrame(Fr
, Cnt
);
2793 procedure MC_RECV_PanelState(var M
: TMsg
);
2798 X
, Y
, W
, H
: Integer;
2800 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2801 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2804 if not gGameOn
then Exit
;
2806 PGUID
:= Integer(M
.ReadLongWord());
2807 E
:= (M
.ReadByte() <> 0);
2808 Lift
:= M
.ReadByte();
2809 X
:= M
.ReadLongInt();
2810 Y
:= M
.ReadLongInt();
2814 speedX
:= M
.ReadLongInt();
2815 speedY
:= M
.ReadLongInt();
2816 startX
:= M
.ReadLongInt();
2817 startY
:= M
.ReadLongInt();
2818 endX
:= M
.ReadLongInt();
2819 endY
:= M
.ReadLongInt();
2820 sizeSpX
:= M
.ReadLongInt();
2821 sizeSpY
:= M
.ReadLongInt();
2822 sizeEX
:= M
.ReadLongInt();
2823 sizeEY
:= M
.ReadLongInt();
2824 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2826 TP
:= g_Map_PanelByGUID(PGUID
);
2827 if (TP
= nil) then exit
;
2829 // update lifts state
2830 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2832 // update enabled/disabled state for all panels
2833 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2835 // update panel position, as it can be moved (mplat)
2840 // update mplat state
2841 TP
.movingSpeedX
:= speedX
;
2842 TP
.movingSpeedY
:= speedY
;
2843 TP
.movingStartX
:= startX
;
2844 TP
.movingStartY
:= startY
;
2845 TP
.movingEndX
:= endX
;
2846 TP
.movingEndY
:= endY
;
2847 TP
.sizeSpeedX
:= sizeSpX
;
2848 TP
.sizeSpeedY
:= sizeSpY
;
2849 TP
.sizeEndX
:= sizeEX
;
2850 TP
.sizeEndY
:= sizeEY
;
2851 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2852 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2853 // notify panel of it's position/size change, so it can fix other internal structures
2854 TP
.positionChanged();
2859 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2862 SPos
, SID
: LongWord;
2866 if not gGameOn
then Exit
;
2867 if gTriggers
= nil then Exit
;
2869 SID
:= M
.ReadLongWord();
2870 SPlaying
:= M
.ReadByte() <> 0;
2871 SPos
:= M
.ReadLongWord();
2872 SCount
:= M
.ReadLongInt();
2874 for I
:= Low(gTriggers
) to High(gTriggers
) do
2875 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2876 if gTriggers
[I
].ClientID
= SID
then
2877 with gTriggers
[I
] do
2879 if Sound
<> nil then
2884 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2886 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2887 Sound
.SetPosition(SPos
);
2890 if Sound
.IsPlaying
then Sound
.Stop
;
2893 SoundPlayCount
:= SCount
;
2897 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2904 if not gGameOn
then Exit
;
2906 MName
:= M
.ReadString();
2907 MPlaying
:= M
.ReadByte() <> 0;
2908 MPos
:= M
.ReadLongWord();
2909 MPaused
:= M
.ReadByte() <> 0;
2910 MPos
:= MPos
+1; //k8: stfu, fpc!
2914 gMusic
.SetByName(MName
);
2916 // gMusic.SetPosition(MPos);
2917 gMusic
.SpecPause
:= MPaused
;
2920 if gMusic
.IsPlaying
then gMusic
.Stop
;
2925 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2928 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2929 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2934 Mon
:= g_Monsters_ByUID(ID
);
2938 MType
:= M
.ReadByte();
2939 MState
:= M
.ReadByte();
2940 MAnim
:= M
.ReadByte();
2941 MTarg
:= M
.ReadWord();
2942 MTargTime
:= M
.ReadLongInt();
2943 MBehav
:= M
.ReadByte();
2944 MSleep
:= M
.ReadLongInt();
2945 MHealth
:= M
.ReadLongInt();
2946 MAmmo
:= M
.ReadLongInt();
2948 X
:= M
.ReadLongInt();
2949 Y
:= M
.ReadLongInt();
2950 VX
:= M
.ReadLongInt();
2951 VY
:= M
.ReadLongInt();
2952 MDir
:= M
.ReadByte();
2954 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2955 Mon
:= g_Monsters_ByUID(ID
);
2962 MonsterAnim
:= MAnim
;
2963 MonsterTargetUID
:= MTarg
;
2964 MonsterTargetTime
:= MTargTime
;
2965 MonsterBehaviour
:= MBehav
;
2966 MonsterSleep
:= MSleep
;
2967 MonsterAmmo
:= MAmmo
;
2972 setPosition(X
, Y
); // this will call positionChanged();
2978 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2985 Mon
:= g_Monsters_ByUID(ID
);
2991 X
:= M
.ReadLongInt();
2992 Y
:= M
.ReadLongInt();
2993 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2994 GameVelX
:= M
.ReadLongInt();
2995 GameVelY
:= M
.ReadLongInt();
2996 GameDirection
:= TDirection(M
.ReadByte());
3000 procedure MC_RECV_MonsterState(var M
: TMsg
);
3002 ID
, OldFire
: Integer;
3003 MState
, MFAnm
: Byte;
3005 AnimRevert
: Boolean;
3008 Mon
:= g_Monsters_ByUID(ID
);
3009 if Mon
= nil then Exit
;
3011 MState
:= M
.ReadByte();
3012 MFAnm
:= M
.ReadByte();
3016 MonsterTargetUID
:= M
.ReadWord();
3017 MonsterTargetTime
:= M
.ReadLongInt();
3018 MonsterSleep
:= M
.ReadLongInt();
3019 MonsterHealth
:= M
.ReadLongInt();
3020 MonsterAmmo
:= M
.ReadLongInt();
3021 MonsterPain
:= M
.ReadLongInt();
3022 AnimRevert
:= M
.ReadByte() <> 0;
3023 OldFire
:= FFireTime
;
3024 FFireTime
:= M
.ReadLongInt();
3025 if (OldFire
<= 0) and (FFireTime
> 0) then
3026 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
3027 RevertAnim(AnimRevert
);
3029 if MonsterState
<> MState
then
3031 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
3032 if (MState
= MONSTATE_DIE
) then DieSound();
3033 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
3034 if (MState
= MONSTATE_ATTACK
) then kick(nil);
3035 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
3037 SetState(MState
, MFAnm
);
3042 procedure MC_RECV_MonsterShot(var M
: TMsg
);
3046 X
, Y
, VX
, VY
: Integer;
3050 Mon
:= g_Monsters_ByUID(ID
);
3051 if Mon
= nil then Exit
;
3053 X
:= M
.ReadLongInt();
3054 Y
:= M
.ReadLongInt();
3055 VX
:= M
.ReadLongInt();
3056 VY
:= M
.ReadLongInt();
3058 Mon
.ClientAttack(X
, Y
, VX
, VY
);
3061 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
3067 Mon
:= g_Monsters_ByUID(ID
);
3068 if Mon
= nil then Exit
;
3070 Mon
.MonsterRemoved
:= True;
3073 procedure MC_RECV_TimeSync(var M
: TMsg
);
3077 Time
:= M
.ReadLongWord();
3079 if gState
= STATE_INTERCUSTOM
then
3080 gServInterTime
:= Min(Time
, 255);
3083 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3087 Int1
, Int2
: SmallInt;
3089 EvID
:= M
.ReadByte();
3090 Int1
:= M
.ReadSmallInt();
3091 Int2
:= M
.ReadSmallInt();
3092 Str1
:= M
.ReadString();
3093 Str2
:= M
.ReadString();
3095 if NetDeafLevel
< 2 then
3098 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3100 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3102 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3104 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3106 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3112 procedure MC_SEND_Info(Password
: string);
3116 NetOut
.Write(Byte(NET_MSG_INFO
));
3117 NetOut
.Write(GAME_VERSION
);
3118 NetOut
.Write(Password
);
3119 NetOut
.Write(gPlayer1Settings
.Name
);
3120 NetOut
.Write(gPlayer1Settings
.Model
);
3121 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3122 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3123 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3124 NetOut
.Write(gPlayer1Settings
.Team
);
3126 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3129 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3131 NetOut
.Write(Byte(NET_MSG_CHAT
));
3135 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3138 procedure MC_SEND_PlayerPos();
3143 WeaponAct
: Byte = 0;
3144 WeaponSelect
: Word = 0;
3147 if not gGameOn
then Exit
;
3148 if gPlayers
= nil then Exit
;
3149 if gPlayer1
= nil then Exit
;
3152 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3154 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3156 strafeDir
:= P1MoveButton
shr 4;
3157 P1MoveButton
:= P1MoveButton
and $0F;
3159 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3161 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3163 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3167 if gPlayerAction
[0, ACTION_STRAFE
] then
3169 // new strafe mechanics
3170 if (strafeDir
= 0) then
3171 strafeDir
:= P1MoveButton
; // start strafing
3172 // now set direction according to strafe (reversed)
3173 if (strafeDir
= 2) then
3174 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3175 else if (strafeDir
= 1) then
3176 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3180 strafeDir
:= 0; // not strafing anymore
3181 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3182 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3183 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3184 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3185 else if P1MoveButton
<> 0 then
3186 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3189 gPlayer1
.ReleaseKeys
;
3190 if P1MoveButton
= 1 then
3192 kByte
:= kByte
or NET_KEY_LEFT
;
3193 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3195 if P1MoveButton
= 2 then
3197 kByte
:= kByte
or NET_KEY_RIGHT
;
3198 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3200 if gPlayerAction
[0, ACTION_LOOKUP
] then
3202 kByte
:= kByte
or NET_KEY_UP
;
3203 gPlayer1
.PressKey(KEY_UP
, 10000);
3205 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3207 kByte
:= kByte
or NET_KEY_DOWN
;
3208 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3210 if gPlayerAction
[0, ACTION_JUMP
] then
3212 kByte
:= kByte
or NET_KEY_JUMP
;
3213 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3215 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3216 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3218 for i
:= WP_FACT
to WP_LACT
do
3220 if gWeaponAction
[0, i
] then
3222 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3223 gWeaponAction
[0, i
] := False
3227 for i
:= WP_FIRST
to WP_LAST
do
3229 if gSelectWeapon
[0, i
] then
3231 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3232 gSelectWeapon
[0, i
] := False
3236 // fix movebutton state
3237 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3240 kByte
:= NET_KEY_CHAT
;
3242 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3243 NetOut
.Write(gTime
);
3244 NetOut
.Write(kByte
);
3245 NetOut
.Write(Byte(gPlayer1
.Direction
));
3246 NetOut
.Write(WeaponAct
);
3247 NetOut
.Write(WeaponSelect
);
3248 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3249 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3251 //kBytePrev := kByte;
3252 //kDirPrev := gPlayer1.Direction;
3255 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3257 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3258 NetOut
.Write(Byte(Start
));
3259 NetOut
.Write(Command
);
3260 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3263 procedure MC_SEND_PlayerSettings();
3265 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3266 NetOut
.Write(gPlayer1Settings
.Name
);
3267 NetOut
.Write(gPlayer1Settings
.Model
);
3268 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3269 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3270 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3271 NetOut
.Write(gPlayer1Settings
.Team
);
3273 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3276 procedure MC_SEND_FullStateRequest();
3278 NetOut
.Write(Byte(NET_MSG_REQFST
));
3280 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3283 procedure MC_SEND_CheatRequest(Kind
: Byte);
3285 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3288 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3290 procedure MC_SEND_RCONPassword(Password
: string);
3292 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3293 NetOut
.Write(Password
);
3295 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3297 procedure MC_SEND_RCONCommand(Cmd
: string);
3299 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3302 g_Net_Client_Send(True, NET_CHAN_SERVICE
);