36c0aa15e5e293f5a64713e87706577d27149864
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_ProcessFirstSpawn (C
: pTNetClient
);
142 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
143 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
145 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
146 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
147 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
148 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
149 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
150 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
151 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
152 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
155 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
156 procedure MH_SEND_Info(ID
: Byte);
157 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
170 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
186 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
189 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
190 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
192 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
193 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
195 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
196 procedure MH_SEND_VoteEvent(EvType
: Byte;
197 StrArg1
: string = 'a'; StrArg2
: string = 'b';
198 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
199 ID
: Integer = NET_EVERYONE
);
201 // CLIENT MESSAGES //
204 procedure MC_RECV_Chat(var M
: TMsg
);
205 procedure MC_RECV_Effect(var M
: TMsg
);
206 procedure MC_RECV_Sound(var M
: TMsg
);
207 procedure MC_RECV_GameStats(var M
: TMsg
);
208 procedure MC_RECV_CoopStats(var M
: TMsg
);
209 procedure MC_RECV_GameEvent(var M
: TMsg
);
210 procedure MC_RECV_FlagEvent(var M
: TMsg
);
211 procedure MC_RECV_FlagPos(var M
: TMsg
);
212 procedure MC_RECV_GameSettings(var M
: TMsg
);
214 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
215 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
216 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
217 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
218 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
219 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
220 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
221 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
223 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
224 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
225 procedure MC_RECV_ItemPos(var M
: TMsg
);
227 procedure MC_RECV_PanelTexture(var M
: TMsg
);
228 procedure MC_RECV_PanelState(var M
: TMsg
);
230 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
231 procedure MC_RECV_MonsterPos(var M
: TMsg
);
232 procedure MC_RECV_MonsterState(var M
: TMsg
);
233 procedure MC_RECV_MonsterShot(var M
: TMsg
);
234 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
236 procedure MC_RECV_CreateShot(var M
: TMsg
);
237 procedure MC_RECV_UpdateShot(var M
: TMsg
);
238 procedure MC_RECV_DeleteShot(var M
: TMsg
);
240 procedure MC_RECV_TriggerSound(var M
: TMsg
);
241 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
243 procedure MC_RECV_TimeSync(var M
: TMsg
);
244 procedure MC_RECV_VoteEvent(var M
: TMsg
);
246 procedure MC_SEND_Info(Password
: string);
247 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
248 procedure MC_SEND_PlayerPos();
249 procedure MC_SEND_FullStateRequest();
250 procedure MC_SEND_PlayerSettings();
251 procedure MC_SEND_CheatRequest(Kind
: Byte);
252 procedure MC_SEND_RCONPassword(Password
: string);
253 procedure MC_SEND_RCONCommand(Cmd
: string);
254 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
256 //procedure MC_SEND_MapRequest();
257 //procedure MC_SEND_ResRequest(const resName: AnsiString);
261 TExternalResourceInfo
= record
276 ExternalResources
: array of TExternalResourceInfo
;
279 function IsValidFileName(const S
: String): Boolean;
280 function IsValidFilePath(const S
: String): Boolean;
286 Math
, ENet
, e_input
, e_graphics
, e_log
,
287 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
288 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
289 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
292 NET_KEY_LEFT
= 1 shl 0;
293 NET_KEY_RIGHT
= 1 shl 1;
294 NET_KEY_UP
= 1 shl 2;
295 NET_KEY_DOWN
= 1 shl 3;
296 NET_KEY_JUMP
= 1 shl 4;
297 NET_KEY_FIRE
= 1 shl 5;
298 NET_KEY_OPEN
= 1 shl 6;
299 NET_KEY_CHAT
= 1 shl 7;
300 NET_KEY_FORCEDIR
= 1 shl 8;
303 //kBytePrev: Word = 0;
304 //kDirPrev: TDirection = D_LEFT;
305 //HostGameTime: Word = 0;
308 function IsValidFileName(const S
: String): Boolean;
310 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
315 for I
:= 1 to Length(S
) do
316 Result
:= Result
and (not(S
[I
] in Forbidden
));
319 function IsValidFilePath(const S
: String): Boolean;
324 if not IsValidFileName(S
) then exit
;
325 if FileExists(S
) then exit
;
326 I
:= LastDelimiter('\/', S
);
328 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
339 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
347 Pl
:= g_Player_Get(PID
);
349 Txt
:= M
.ReadString();
350 Mode
:= M
.ReadByte();
351 if (Mode
= NET_CHAT_SYSTEM
) then
352 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
353 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
354 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
357 MH_SEND_Chat(Txt
, Mode
)
359 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
362 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
364 Ver
, PName
, Model
, Pw
: string;
370 Ver
:= M
.ReadString();
371 Pw
:= M
.ReadString();
372 PName
:= M
.ReadString();
373 Model
:= M
.ReadString();
379 if Ver
<> GAME_VERSION
then
381 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
382 _lc
[I_NET_DISC_VERSION
]);
383 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
387 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
389 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
391 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
392 _lc
[I_NET_DISC_BAN
]);
393 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
397 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
398 _lc
[I_NET_DISC_BAN
]);
399 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
404 if NetPassword
<> '' then
405 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
407 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
408 _lc
[I_NET_DISC_PASSWORD
]);
409 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
417 PID
:= g_Player_Create(Model
, Color
, T
, False);
418 with g_Player_Get(PID
) do
425 C
^.WaitForFirstSpawn
:= false;
427 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
428 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
429 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
433 with g_Player_Get(PID
) do
437 // round in progress, don't spawn
438 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
439 //e_LogWritefln('spawning player with pid #%u...', [PID]);
440 //Respawn(gGameSettings.GameType = GT_SINGLE);
441 //k8: no, do not spawn a player yet, wait for "request full state" packet
445 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
446 // that is, if we'll set it to `true`, the player can be spawned after
447 // warmup time ran out, for example, regardless of the real player state.
448 // also, this seems to work only for the initial connection. further
449 // map changes could initiate resource downloading, but the player will
450 // be spawned immediately.
451 // the proper solution will require another player state, "ephemeral".
452 // the player should start any map in "ephemeral" state, and turned into
453 // real mobj only when they sent a special "i am ready" packet. this packet
454 // must be sent after receiving the full state, so the player will get a full
455 // map view before going into game.
456 FWantsInGame
:= false;
457 C
^.WaitForFirstSpawn
:= true;
460 //if not C^.WaitForFirstSpawn then
462 for I
:= Low(NetClients
) to High(NetClients
) do
464 if NetClients
[I
].ID
= C
^.ID
then Continue
;
465 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
466 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
467 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
471 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
472 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
476 //g_Net_Slist_Update;
482 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
486 if not C
.WaitForFirstSpawn
then exit
;
487 plr
:= g_Player_Get(C
^.Player
);
488 if not assigned(plr
) then exit
;
489 g_Net_Slist_ServerPlayerComes();
490 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
491 C
.WaitForFirstSpawn
:= false;
492 plr
.FNoRespawn
:= false;
493 plr
.FWantsInGame
:= true; // TODO: look into this later
495 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
498 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
503 if gLMSRespawn
> LMS_RESPAWN_NONE
then
504 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
509 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
511 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
514 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
518 C
^.RequestedFullUpdate
:= True;
524 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
535 if not gGameOn
then Exit
;
537 GT
:= M
.ReadLongWord();
539 Pl
:= g_Player_Get(PID
);
543 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
548 kByte
:= M
.ReadWord();
550 WeaponAct
:= M
.ReadByte();
551 WeaponSelect
:= M
.ReadWord();
552 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
553 if Direction
<> TDirection(Dir
) then
554 JustTeleported
:= False;
556 SetDirection(TDirection(Dir
));
559 if kByte
= NET_KEY_CHAT
then
561 PressKey(KEY_CHAT
, 10000);
565 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
566 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
567 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
568 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
569 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
570 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
571 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
575 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
577 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
578 ProcessWeaponAction(i
);
584 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
586 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
587 QueueWeaponSwitch(i
);
592 // MH_SEND_PlayerPos(False, PID, C^.ID);
595 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
600 Pl
:= g_Player_Get(C
^.Player
);
601 if Pl
= nil then Exit
;
603 CheatKind
:= M
.ReadByte();
607 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
610 if Pl
.FSpectator
then
612 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
615 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
622 if gState
<> STATE_INTERCUSTOM
then Exit
;
623 Pl
.FReady
:= not Pl
.FReady
;
626 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
627 Inc(gInterReadyCount
);
631 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
632 Dec(gInterReadyCount
);
640 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
648 TmpName
:= M
.ReadString();
649 TmpModel
:= M
.ReadString();
650 TmpColor
.R
:= M
.ReadByte();
651 TmpColor
.G
:= M
.ReadByte();
652 TmpColor
.B
:= M
.ReadByte();
653 TmpTeam
:= M
.ReadByte();
655 Pl
:= g_Player_Get(C
^.Player
);
656 if Pl
= nil then Exit
;
658 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
661 Pl
.SetColor(TmpColor
);
663 if Pl
.Name
<> TmpName
then
665 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
669 if TmpModel
<> Pl
.Model
.Name
then
670 Pl
.SetModel(TmpModel
);
672 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
677 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
681 Pwd
:= M
.ReadString();
682 if not NetAllowRCON
then Exit
;
683 if Pwd
= NetRCONPassword
then
686 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
689 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
692 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
696 Cmd
:= M
.ReadString();
697 if not NetAllowRCON
then Exit
;
698 if not C
^.RCONAuth
then
700 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
703 g_Console_Process(Cmd
);
708 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
711 Name
, Command
: string;
715 Start
:= M
.ReadByte() <> 0;
716 Command
:= M
.ReadString();
718 Pl
:= g_Player_Get(C
^.Player
);
719 if Pl
= nil then Exit
;
724 if not g_Console_CommandBlacklisted(Command
) then
725 g_Game_StartVote(Command
, Name
);
727 else if gVoteInProgress
then
729 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
730 Need
:= Floor((NetClientCount
+1)/2.0) + 1
732 Need
:= Floor(NetClientCount
/2.0) + 1;
737 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
738 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
744 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
745 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
753 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
755 function sendItemRespawn (it
: PItem
): Boolean;
757 result
:= false; // don't stop
758 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
761 function sendMonSpawn (mon
: TMonster
): Boolean;
763 result
:= false; // don't stop
764 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
767 function sendPanelState (pan
: TPanel
): Boolean;
769 result
:= false; // don't stop
770 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
771 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
777 if (ID
>= 0) and (ID
< length(NetClients
)) then
779 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
780 MH_ProcessFirstSpawn(@NetClients
[ID
]);
783 if gPlayers
<> nil then
785 for I
:= Low(gPlayers
) to High(gPlayers
) do
787 if gPlayers
[I
] <> nil then
789 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
790 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
791 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
793 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
795 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
801 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
802 g_Mons_ForEach(sendMonSpawn
);
803 g_Map_ForEachPanel(sendPanelState
);
805 if gTriggers
<> nil then
807 for I
:= Low(gTriggers
) to High(gTriggers
) do
809 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
811 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
818 for I
:= Low(Shots
) to High(Shots
) do
820 if Shots
[i
].ShotType
in [6, 7, 8] then
822 MH_SEND_CreateShot(i
, ID
);
827 MH_SEND_TriggerMusic(ID
);
829 MH_SEND_GameStats(ID
);
830 MH_SEND_CoopStats(ID
);
832 if gGameSettings
.GameMode
= GM_CTF
then
834 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
835 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
838 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
843 procedure MH_SEND_Info(ID
: Byte);
847 NetOut
.Write(Byte(NET_MSG_INFO
));
849 NetOut
.Write(NetClients
[ID
].Player
);
850 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
851 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
852 NetOut
.Write(gWADHash
);
853 NetOut
.Write(gGameSettings
.GameMode
);
854 NetOut
.Write(gGameSettings
.GoalLimit
);
855 NetOut
.Write(gGameSettings
.TimeLimit
);
856 NetOut
.Write(gGameSettings
.MaxLives
);
857 NetOut
.Write(gGameSettings
.Options
);
860 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
863 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
869 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
870 Mode
:= NET_CHAT_PLAYER
;
873 if (Mode
= NET_CHAT_TEAM
) then
875 for i
:= Low(gPlayers
) to High(gPlayers
) do
876 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
877 (gPlayers
[i
].Team
= ID
) then
879 NetOut
.Write(Byte(NET_MSG_CHAT
));
882 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
889 NetOut
.Write(Byte(NET_MSG_CHAT
));
892 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
895 if Mode
= NET_CHAT_SYSTEM
then
898 if ID
= NET_EVERYONE
then
900 if Mode
= NET_CHAT_PLAYER
then
902 g_Console_Add(Txt
, True);
903 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
904 g_Game_ChatSound(b_Text_Unformat(Txt
));
907 if Mode
= NET_CHAT_TEAM
then
908 if gPlayer1
<> nil then
910 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
912 g_Console_Add(#18'[Team] '#2 + Txt
, True);
913 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
914 g_Game_ChatSound(b_Text_Unformat(Txt
));
916 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
918 g_Console_Add(#20'[Team] '#2 + Txt
, True);
919 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
920 g_Game_ChatSound(b_Text_Unformat(Txt
));
926 Name
:= g_Net_ClientName_ByID(ID
);
927 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
928 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
929 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
933 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
935 NetOut
.Write(Byte(NET_MSG_GFX
));
941 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
944 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
946 NetOut
.Write(Byte(NET_MSG_SND
));
950 NetOut
.Write(Byte(1));
955 NetOut
.Write(Byte(0));
957 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
960 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
962 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
964 NetOut
.Write(Byte(NET_MSG_SHADD
));
966 NetOut
.Write(Shots
[Proj
].ShotType
);
967 NetOut
.Write(Shots
[Proj
].Target
);
968 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
969 NetOut
.Write(Shots
[Proj
].Timeout
);
970 NetOut
.Write(Shots
[Proj
].Obj
.X
);
971 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
972 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
973 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
975 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
978 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
980 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
982 NetOut
.Write(Byte(NET_MSG_SHPOS
));
984 NetOut
.Write(Shots
[Proj
].Obj
.X
);
985 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
986 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
987 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
989 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
992 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
994 NetOut
.Write(Byte(NET_MSG_SHDEL
));
996 NetOut
.Write(Byte(Loud
));
1000 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1003 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
1005 NetOut
.Write(Byte(NET_MSG_SCORE
));
1006 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1008 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1009 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1012 if gGameSettings
.GameMode
= GM_COOP
then
1014 NetOut
.Write(gCoopMonstersKilled
);
1015 NetOut
.Write(gCoopSecretsFound
);
1018 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1021 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1023 NetOut
.Write(Byte(NET_MSG_COOP
));
1024 NetOut
.Write(gTotalMonsters
);
1025 NetOut
.Write(gSecretsCount
);
1026 NetOut
.Write(gCoopTotalMonstersKilled
);
1027 NetOut
.Write(gCoopTotalSecretsFound
);
1028 NetOut
.Write(gCoopTotalMonsters
);
1029 NetOut
.Write(gCoopTotalSecrets
);
1032 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1034 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1035 NetOut
.Write(EvType
);
1036 NetOut
.Write(EvNum
);
1037 NetOut
.Write(EvStr
);
1038 NetOut
.Write(Byte(gLastMap
));
1039 NetOut
.Write(gTime
);
1040 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1042 NetOut
.Write(Byte(1));
1043 NetOut
.Write(gWADHash
);
1045 NetOut
.Write(Byte(0));
1047 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1050 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1052 NetOut
.Write(Byte(NET_MSG_FLAG
));
1053 NetOut
.Write(EvType
);
1055 NetOut
.Write(Byte(Quiet
));
1057 NetOut
.Write(gFlags
[Flag
].State
);
1058 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1059 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1060 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1061 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1062 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1063 NetOut
.Write(Byte(gFlags
[Flag
].Direction
));
1065 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1068 procedure MH_SEND_FlagPos(Flag
: Byte; ID
: Integer = NET_EVERYONE
);
1070 NetOut
.Write(Byte(NET_MSG_FLAGPOS
));
1072 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1073 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1074 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1075 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1077 g_Net_Host_Send(ID
, False, NET_CHAN_IMPORTANT
);
1080 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1082 NetOut
.Write(Byte(NET_MSG_GSET
));
1083 NetOut
.Write(gGameSettings
.GameMode
);
1084 NetOut
.Write(gGameSettings
.GoalLimit
);
1085 NetOut
.Write(gGameSettings
.TimeLimit
);
1086 NetOut
.Write(gGameSettings
.MaxLives
);
1087 NetOut
.Write(gGameSettings
.Options
);
1089 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1094 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1098 P
:= g_Player_Get(PID
);
1099 if P
= nil then Exit
;
1101 NetOut
.Write(Byte(NET_MSG_PLR
));
1103 NetOut
.Write(P
.Name
);
1105 NetOut
.Write(P
.FActualModelName
);
1106 NetOut
.Write(P
.FColor
.R
);
1107 NetOut
.Write(P
.FColor
.G
);
1108 NetOut
.Write(P
.FColor
.B
);
1109 NetOut
.Write(P
.Team
);
1111 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1114 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1119 Pl
:= g_Player_Get(PID
);
1120 if Pl
= nil then Exit
;
1121 if Pl
.FDummy
then Exit
;
1123 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1124 NetOut
.Write(gTime
);
1131 NetOut
.Write(FPing
);
1132 NetOut
.Write(FLoss
);
1133 if IsKeyPressed(KEY_CHAT
) then
1134 kByte
:= NET_KEY_CHAT
1137 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1138 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1139 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1140 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1141 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1144 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1146 NetOut
.Write(kByte
);
1147 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1148 NetOut
.Write(GameX
);
1149 NetOut
.Write(GameY
);
1150 NetOut
.Write(GameVelX
);
1151 NetOut
.Write(GameVelY
);
1152 NetOut
.Write(GameAccelX
);
1153 NetOut
.Write(GameAccelY
);
1156 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1159 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1164 P
:= g_Player_Get(PID
);
1165 if P
= nil then Exit
;
1167 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1172 NetOut
.Write(Byte(alive
));
1173 NetOut
.Write(Byte(GodMode
));
1174 NetOut
.Write(Health
);
1175 NetOut
.Write(Armor
);
1177 NetOut
.Write(JetFuel
);
1178 NetOut
.Write(Lives
);
1181 for I
:= WP_FIRST
to WP_LAST
do
1182 NetOut
.Write(Byte(FWeapon
[I
]));
1184 for I
:= A_BULLETS
to A_HIGH
do
1185 NetOut
.Write(FAmmo
[I
]);
1187 for I
:= A_BULLETS
to A_HIGH
do
1188 NetOut
.Write(FMaxAmmo
[I
]);
1190 for I
:= MR_SUIT
to MR_MAX
do
1191 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1193 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1194 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1195 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1196 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1197 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1199 NetOut
.Write(Frags
);
1200 NetOut
.Write(Death
);
1202 NetOut
.Write(CurrWeap
);
1204 NetOut
.Write(Byte(FSpectator
));
1205 NetOut
.Write(Byte(FGhost
));
1206 NetOut
.Write(Byte(FPhysics
));
1207 NetOut
.Write(Byte(FNoRespawn
));
1208 NetOut
.Write(Byte(FJetpack
));
1209 NetOut
.Write(FFireTime
);
1210 NetOut
.Write(Byte(FFlaming
));
1211 NetOut
.Write(FSpawnInvul
);
1214 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1217 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1219 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1222 NetOut
.Write(Attacker
);
1223 NetOut
.Write(Value
);
1227 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1230 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1232 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1234 NetOut
.Write(KillType
);
1235 NetOut
.Write(DeathType
);
1236 NetOut
.Write(Attacker
);
1238 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1241 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1243 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1245 NetOut
.Write(Weapon
);
1250 NetOut
.Write(ShotID
);
1252 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1255 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1257 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1260 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1263 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1267 Pl
:= g_Player_Get(PID
);
1268 if Pl
= nil then Exit
;
1270 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1272 NetOut
.Write(Pl
.Name
);
1274 NetOut
.Write(Pl
.Model
.Name
)
1277 NetOut
.Write(Pl
.FColor
.R
);
1278 NetOut
.Write(Pl
.FColor
.G
);
1279 NetOut
.Write(Pl
.FColor
.B
);
1280 NetOut
.Write(Pl
.Team
);
1282 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1287 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1292 it
:= g_Items_ByIdx(IID
);
1294 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1296 NetOut
.Write(Byte(Quiet
));
1298 if it
.dropped
then tt
:= tt
or $80;
1300 NetOut
.Write(Byte(it
.Fall
));
1301 NetOut
.Write(Byte(it
.Respawnable
));
1302 NetOut
.Write(it
.Obj
.X
);
1303 NetOut
.Write(it
.Obj
.Y
);
1304 NetOut
.Write(it
.Obj
.Vel
.X
);
1305 NetOut
.Write(it
.Obj
.Vel
.Y
);
1307 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1310 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1312 NetOut
.Write(Byte(NET_MSG_IDEL
));
1314 NetOut
.Write(Byte(Quiet
));
1316 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1319 procedure MH_SEND_ItemPos(IID
: Word; ID
: Integer = NET_EVERYONE
);
1323 it
:= g_Items_ByIdx(IID
);
1325 NetOut
.Write(Byte(NET_MSG_IPOS
));
1327 NetOut
.Write(it
.Obj
.X
);
1328 NetOut
.Write(it
.Obj
.Y
);
1329 NetOut
.Write(it
.Obj
.Vel
.X
);
1330 NetOut
.Write(it
.Obj
.Vel
.Y
);
1332 g_Net_Host_Send(ID
, False, NET_CHAN_LARGEDATA
);
1337 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1341 TP
:= g_Map_PanelByGUID(PGUID
);
1342 if (TP
= nil) then exit
;
1346 NetOut
.Write(Byte(NET_MSG_PTEX
));
1347 NetOut
.Write(LongWord(PGUID
));
1348 NetOut
.Write(FCurTexture
);
1349 NetOut
.Write(FCurFrame
);
1350 NetOut
.Write(FCurFrameCount
);
1351 NetOut
.Write(AnimLoop
);
1354 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1357 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1362 TP
:= g_Map_PanelByGUID(PGUID
);
1363 if (TP
= nil) then exit
;
1365 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1366 NetOut
.Write(LongWord(PGUID
));
1367 NetOut
.Write(Byte(TP
.Enabled
));
1368 NetOut
.Write(TP
.LiftType
);
1371 NetOut
.Write(Word(TP
.Width
));
1372 NetOut
.Write(Word(TP
.Height
));
1374 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1375 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1376 NetOut
.Write(LongInt(TP
.movingStartX
));
1377 NetOut
.Write(LongInt(TP
.movingStartY
));
1378 NetOut
.Write(LongInt(TP
.movingEndX
));
1379 NetOut
.Write(LongInt(TP
.movingEndY
));
1380 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1381 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1382 NetOut
.Write(LongInt(TP
.sizeEndX
));
1383 NetOut
.Write(LongInt(TP
.sizeEndY
));
1384 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1385 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1386 NetOut
.Write(Byte(mpflags
));
1388 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1393 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1395 if gTriggers
= nil then Exit
;
1396 if T
.Sound
= nil then Exit
;
1398 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1399 NetOut
.Write(T
.ClientID
);
1400 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1401 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1402 NetOut
.Write(T
.SoundPlayCount
);
1404 g_Net_Host_Send(ID
, True);
1407 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1409 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1410 NetOut
.Write(gMusic
.Name
);
1411 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1412 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1413 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1415 g_Net_Host_Send(ID
, True);
1420 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1424 M
:= g_Monsters_ByUID(UID
);
1430 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1432 NetOut
.Write(MonsterType
);
1433 NetOut
.Write(MonsterState
);
1434 NetOut
.Write(MonsterAnim
);
1435 NetOut
.Write(MonsterTargetUID
);
1436 NetOut
.Write(MonsterTargetTime
);
1437 NetOut
.Write(MonsterBehaviour
);
1438 NetOut
.Write(MonsterSleep
);
1439 NetOut
.Write(MonsterHealth
);
1440 NetOut
.Write(MonsterAmmo
);
1441 NetOut
.Write(GameX
);
1442 NetOut
.Write(GameY
);
1443 NetOut
.Write(GameVelX
);
1444 NetOut
.Write(GameVelY
);
1445 NetOut
.Write(Byte(GameDirection
));
1448 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1451 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1455 M
:= g_Monsters_ByUID(UID
);
1456 if M
= nil then Exit
;
1458 NetOut
.Write(Byte(NET_MSG_MPOS
));
1463 NetOut
.Write(GameX
);
1464 NetOut
.Write(GameY
);
1465 NetOut
.Write(GameVelX
);
1466 NetOut
.Write(GameVelY
);
1467 NetOut
.Write(Byte(GameDirection
));
1470 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1473 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1477 M
:= g_Monsters_ByUID(UID
);
1478 if M
= nil then Exit
;
1480 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1485 NetOut
.Write(MonsterState
);
1486 NetOut
.Write(ForcedAnim
);
1487 NetOut
.Write(MonsterTargetUID
);
1488 NetOut
.Write(MonsterTargetTime
);
1489 NetOut
.Write(MonsterSleep
);
1490 NetOut
.Write(MonsterHealth
);
1491 NetOut
.Write(MonsterAmmo
);
1492 NetOut
.Write(MonsterPain
);
1493 NetOut
.Write(Byte(AnimIsReverse
));
1494 NetOut
.Write(FFireTime
);
1497 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1500 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1502 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1509 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1512 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1516 M
:= g_Monsters_ByUID(UID
);
1517 if M
= nil then Exit
;
1519 NetOut
.Write(Byte(NET_MSG_MDEL
));
1522 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1527 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1529 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1532 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1535 procedure MH_SEND_VoteEvent(EvType
: Byte;
1536 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1537 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1538 ID
: Integer = NET_EVERYONE
);
1540 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1541 NetOut
.Write(EvType
);
1542 NetOut
.Write(IntArg1
);
1543 NetOut
.Write(IntArg2
);
1544 NetOut
.Write(StrArg1
);
1545 NetOut
.Write(StrArg2
);
1547 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1550 // CLIENT MESSAGES //
1554 procedure MC_RECV_Chat(var M
: TMsg
);
1559 Txt
:= M
.ReadString();
1560 Mode
:= M
.ReadByte();
1562 if Mode
<> NET_CHAT_SYSTEM
then
1564 if NetDeafLevel
= 0 then
1566 if Mode
= NET_CHAT_PLAYER
then
1568 g_Console_Add(Txt
, True);
1569 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1570 g_Game_ChatSound(b_Text_Unformat(Txt
));
1572 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1574 if gPlayer1
.Team
= TEAM_RED
then
1575 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1576 if gPlayer1
.Team
= TEAM_BLUE
then
1577 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1578 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1579 g_Game_ChatSound(b_Text_Unformat(Txt
));
1582 end else if (NetDeafLevel
< 2) then
1583 g_Console_Add(Txt
, True);
1586 procedure MC_RECV_Effect(var M
: TMsg
);
1594 if not gGameOn
then Exit
;
1595 Kind
:= M
.ReadByte();
1596 X
:= M
.ReadLongInt();
1597 Y
:= M
.ReadLongInt();
1598 Ang
:= M
.ReadSmallInt();
1602 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1606 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1608 Anim
:= TAnimation
.Create(ID
, False, 3);
1609 g_GFX_OnceAnim(X
, Y
, Anim
);
1613 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1618 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1620 Anim
:= TAnimation
.Create(ID
, False, 6);
1621 Anim
.Blending
:= False;
1622 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1626 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1631 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1633 Anim
:= TAnimation
.Create(ID
, False, 6);
1634 Anim
.Blending
:= False;
1635 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1639 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1644 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1646 Anim
:= TAnimation
.Create(ID
, False, 4);
1647 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1654 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1656 Anim
:= TAnimation
.Create(ID
, False, 4);
1657 g_GFX_OnceAnim(X
, Y
, Anim
);
1661 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1666 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1668 Anim
:= TAnimation
.Create(ID
, False, 4);
1669 g_GFX_OnceAnim(X
, Y
, Anim
);
1673 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1677 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1680 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1684 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1685 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1690 procedure MC_RECV_Sound(var M
: TMsg
);
1696 Name
:= M
.ReadString();
1697 Pos
:= M
.ReadByte() <> 0;
1700 X
:= M
.ReadLongInt();
1701 Y
:= M
.ReadLongInt();
1702 g_Sound_PlayExAt(Name
, X
, Y
);
1705 g_Sound_PlayEx(Name
);
1708 procedure MC_RECV_CreateShot(var M
: TMsg
);
1710 I
, X
, Y
, XV
, YV
: Integer;
1712 Target
, Spawner
: Word;
1715 I
:= M
.ReadLongInt();
1716 ShType
:= M
.ReadByte();
1717 Target
:= M
.ReadWord();
1718 Spawner
:= M
.ReadWord();
1719 Timeout
:= M
.ReadLongWord();
1720 X
:= M
.ReadLongInt();
1721 Y
:= M
.ReadLongInt();
1722 XV
:= M
.ReadLongInt();
1723 YV
:= M
.ReadLongInt();
1725 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1726 if (Shots
<> nil) and (I
<= High(Shots
)) then
1728 Shots
[I
].Timeout
:= Timeout
;
1729 //Shots[I].Target := Target; // TODO: find a use for Target later
1733 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1735 I
, TX
, TY
, TXV
, TYV
: Integer;
1737 I
:= M
.ReadLongInt();
1738 TX
:= M
.ReadLongInt();
1739 TY
:= M
.ReadLongInt();
1740 TXV
:= M
.ReadLongInt();
1741 TYV
:= M
.ReadLongInt();
1743 if (Shots
<> nil) and (I
<= High(Shots
)) then
1753 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1758 if not gGameOn
then Exit
;
1759 I
:= M
.ReadLongInt();
1760 L
:= (M
.ReadByte() <> 0);
1761 X
:= M
.ReadLongInt();
1762 Y
:= M
.ReadLongInt();
1764 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1767 procedure MC_RECV_GameStats(var M
: TMsg
);
1769 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1771 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1772 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1775 if gGameSettings
.GameMode
= GM_COOP
then
1777 gCoopMonstersKilled
:= M
.ReadWord();
1778 gCoopSecretsFound
:= M
.ReadWord();
1782 procedure MC_RECV_CoopStats(var M
: TMsg
);
1784 gTotalMonsters
:= M
.ReadLongInt();
1785 gSecretsCount
:= M
.ReadLongInt();
1786 gCoopTotalMonstersKilled
:= M
.ReadWord();
1787 gCoopTotalSecretsFound
:= M
.ReadWord();
1788 gCoopTotalMonsters
:= M
.ReadWord();
1789 gCoopTotalSecrets
:= M
.ReadWord();
1792 procedure MC_RECV_GameEvent(var M
: TMsg
);
1801 i1
, i2
: TStrings_Locale
;
1804 goodCmd
: Boolean = true;
1806 FillChar(EvHash
, Sizeof(EvHash
), 0);
1807 EvType
:= M
.ReadByte();
1808 EvNum
:= M
.ReadLongInt();
1809 EvStr
:= M
.ReadString();
1810 gLastMap
:= M
.ReadByte() <> 0;
1811 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1812 gStatsPressed
:= True;
1813 EvTime
:= M
.ReadLongWord();
1814 BHash
:= M
.ReadByte() <> 0;
1816 EvHash
:= M
.ReadMD5();
1820 if (g_Res_received_map_start
<> 0) then
1822 if (g_Res_received_map_start
< 0) then exit
;
1825 NET_EV_MAPSTART
: goodCmd
:= true;
1826 NET_EV_MAPEND
: goodCmd
:= true;
1827 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1828 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1829 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1831 if not goodCmd
then exit
;
1837 if (g_Res_received_map_start
<> 0) then
1839 g_Res_received_map_start
:= -1;
1844 g_Game_ClearLoading();
1845 g_Game_StopAllSounds(True);
1847 gSwitchGameMode
:= Byte(EvNum
);
1848 gGameSettings
.GameMode
:= gSwitchGameMode
;
1851 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1853 if not isWadPath(EvStr
) then
1854 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1856 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1860 MC_SEND_FullStateRequest
;
1866 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1867 gLMSRespawnTime
:= 0;
1868 if (g_Res_received_map_start
<> 0) then
1870 g_Res_received_map_start
:= -1;
1874 gMissionFailed
:= EvNum
<> 0;
1875 gExit
:= EXIT_ENDLEVELCUSTOM
;
1883 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1885 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1887 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1893 if NetDeafLevel
< 2 then
1895 if EvNum
= TEAM_RED
then
1896 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1897 if EvNum
= TEAM_BLUE
then
1898 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1904 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1905 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1910 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1911 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1918 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
1919 gLMSRespawnTime
:= gTime
+ EvNum
;
1920 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
1922 else if gPlayer1
= nil then
1924 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1928 NET_EV_LMS_SURVIVOR
:
1929 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1932 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1936 pl
:= g_Player_Get(EvNum
and $FFFF);
1941 cnt
:= (EvNum
shr 16) and $FF;
1942 if Pos('w', EvStr
) = 0 then
1945 if Pos('t', EvStr
) = 0 then
1948 if Pos('-', EvStr
) = 0 then
1950 if Pos('e', EvStr
) = 0 then
1951 i1
:= I_PLAYER_SCORE_ADD_OWN
1953 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1956 if Pos('e', EvStr
) = 0 then
1957 i1
:= I_PLAYER_SCORE_SUB_OWN
1959 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1962 if Pos('r', EvStr
) > 0 then
1963 i2
:= I_PLAYER_SCORE_TO_RED
1965 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1966 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1970 if Pos('-', EvStr
) = 0 then
1971 i1
:= I_PLAYER_SCORE_ADD_TEAM
1973 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1975 if Pos('r', EvStr
) > 0 then
1976 i2
:= I_PLAYER_SCORE_RED
1978 i2
:= I_PLAYER_SCORE_BLUE
;
1979 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1984 if Pos('e', EvStr
) = 0 then
1985 i1
:= I_PLAYER_SCORE_WIN_OWN
1987 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1989 if Pos('r', EvStr
) > 0 then
1990 i2
:= I_PLAYER_SCORE_TO_RED
1992 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1993 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1999 if EvNum
= TEAM_RED
then
2000 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2001 if EvNum
= TEAM_BLUE
then
2002 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2003 if EvNum
= -TEAM_RED
then
2004 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
2005 if EvNum
= -TEAM_BLUE
then
2006 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
2011 g_Player_RemoveAllCorpses
;
2012 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2013 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
2017 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
2021 if EvNum
= TEAM_RED
then
2022 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2023 if EvNum
= TEAM_BLUE
then
2024 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2028 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2031 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2034 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2037 g_Game_Announce_KillCombo(EvNum
);
2039 NET_EV_PLAYER_TOUCH
:
2041 pl
:= g_Player_Get(EvNum
);
2048 pl
:= g_Player_Get(EvNum
);
2051 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2052 g_Sound_PlayEx('SOUND_GAME_SECRET');
2058 pl
:= g_Player_Get(EvNum
);
2059 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2064 procedure MC_RECV_FlagPos(var M
: TMsg
);
2069 if Fl
= FLAG_NONE
then Exit
;
2070 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2071 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2072 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2073 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2076 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2085 EvType
:= M
.ReadByte();
2088 if Fl
= FLAG_NONE
then Exit
;
2090 Quiet
:= (M
.ReadByte() <> 0);
2091 PID
:= M
.ReadWord();
2093 gFlags
[Fl
].State
:= M
.ReadByte();
2094 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2095 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2096 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2097 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2098 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2099 gFlags
[Fl
].Direction
:= TDirection(M
.ReadByte());
2101 Pl
:= g_Player_Get(PID
);
2103 (EvType
<> FLAG_STATE_NORMAL
) and
2104 (EvType
<> FLAG_STATE_DROPPED
) and
2105 (EvType
<> FLAG_STATE_RETURNED
) then
2111 if Quiet
or (Pl
= nil) then Exit
;
2113 if Fl
= FLAG_RED
then
2114 s
:= _lc
[I_PLAYER_FLAG_RED
]
2116 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2118 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2120 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2121 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2122 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2127 if not sound_ret_flag
[a
].IsPlaying() then
2128 sound_ret_flag
[a
].Play();
2131 FLAG_STATE_CAPTURED
:
2133 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2137 if Fl
= FLAG_RED
then
2138 s
:= _lc
[I_PLAYER_FLAG_RED
]
2140 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2142 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2143 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2145 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2146 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2147 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2152 if not sound_get_flag
[a
].IsPlaying() then
2153 sound_get_flag
[a
].Play();
2158 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2160 if Quiet
or (Pl
= nil) then Exit
;
2162 if Fl
= FLAG_RED
then
2163 s
:= _lc
[I_PLAYER_FLAG_RED
]
2165 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2167 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2168 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2170 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2171 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2172 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2177 if not sound_lost_flag
[a
].IsPlaying() then
2178 sound_lost_flag
[a
].Play();
2183 g_Map_ResetFlag(FLAG_RED
);
2184 g_Map_ResetFlag(FLAG_BLUE
);
2185 if Quiet
or (Pl
= nil) then Exit
;
2186 Pl
.SetFlag(FLAG_NONE
);
2188 if Fl
= FLAG_RED
then
2189 s
:= _lc
[I_PLAYER_FLAG_RED
]
2191 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2193 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2194 Insert('.', ts
, Length(ts
) + 1 - 3);
2195 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2196 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2198 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2199 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2200 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2205 if not sound_cap_flag
[a
].IsPlaying() then
2206 sound_cap_flag
[a
].Play();
2209 FLAG_STATE_RETURNED
:
2211 g_Map_ResetFlag(Fl
);
2214 if Fl
= FLAG_RED
then
2215 s
:= _lc
[I_PLAYER_FLAG_RED
]
2217 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2219 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2221 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2222 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2223 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2228 if not sound_ret_flag
[a
].IsPlaying() then
2229 sound_ret_flag
[a
].Play();
2234 procedure MC_RECV_GameSettings(var M
: TMsg
);
2236 gGameSettings
.GameMode
:= M
.ReadByte();
2237 gGameSettings
.GoalLimit
:= M
.ReadWord();
2238 gGameSettings
.TimeLimit
:= M
.ReadWord();
2239 gGameSettings
.MaxLives
:= M
.ReadByte();
2240 gGameSettings
.Options
:= M
.ReadLongWord();
2245 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2248 PName
, Model
: string;
2253 PID
:= M
.ReadWord();
2254 Pl
:= g_Player_Get(PID
);
2256 PName
:= M
.ReadString();
2257 Model
:= M
.ReadString();
2258 Color
.R
:= M
.ReadByte();
2259 Color
.G
:= M
.ReadByte();
2260 Color
.B
:= M
.ReadByte();
2264 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2266 if (Pl
<> nil) then Exit
;
2267 DID
:= g_Player_Create(Model
, Color
, T
, False);
2268 with g_Player_Get(DID
) do
2277 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2278 gPlayer1
.UID
:= PID
;
2279 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2280 gPlayer1
.ChangeTeam(T
);
2282 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2283 gPlayer2
.UID
:= PID
;
2284 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2285 gPlayer2
.ChangeTeam(T
);
2289 if NetDeafLevel
< 3 then
2290 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2291 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2295 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2302 TmpX
, TmpY
: Integer;
2306 GT
:= M
.ReadLongWord();
2307 if GT
< gTime
- NET_MAX_DIFFTIME
then
2314 PID
:= M
.ReadWord();
2315 Pl
:= g_Player_Get(PID
);
2317 if Pl
= nil then Exit
;
2323 FPing
:= M
.ReadWord();
2324 FLoss
:= M
.ReadByte();
2325 kByte
:= M
.ReadWord();
2326 Dir
:= M
.ReadByte();
2328 TmpX
:= M
.ReadLongInt();
2329 TmpY
:= M
.ReadLongInt();
2333 if LongBool(kByte
and NET_KEY_CHAT
) then
2334 PressKey(KEY_CHAT
, 10000)
2337 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2338 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2339 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2340 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2341 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2344 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2346 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2347 SetDirection(TDirection(Dir
));
2349 GameVelX
:= M
.ReadLongInt();
2350 GameVelY
:= M
.ReadLongInt();
2351 GameAccelX
:= M
.ReadLongInt();
2352 GameAccelY
:= M
.ReadLongInt();
2353 SetLerp(TmpX
, TmpY
);
2354 if NetForcePlayerUpdate
then Update();
2358 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2362 I
, OldFire
: Integer;
2363 OldJet
, Flam
: Boolean;
2366 PID
:= M
.ReadWord();
2367 Pl
:= g_Player_Get(PID
);
2374 alive
:= (M
.ReadByte() <> 0);
2375 GodMode
:= (M
.ReadByte() <> 0);
2376 Health
:= M
.ReadLongInt();
2377 Armor
:= M
.ReadLongInt();
2378 Air
:= M
.ReadLongInt();
2379 JetFuel
:= M
.ReadLongInt();
2380 Lives
:= M
.ReadByte();
2381 NewTeam
:= M
.ReadByte();
2383 for I
:= WP_FIRST
to WP_LAST
do
2384 FWeapon
[I
] := (M
.ReadByte() <> 0);
2386 for I
:= A_BULLETS
to A_HIGH
do
2387 FAmmo
[I
] := M
.ReadWord();
2389 for I
:= A_BULLETS
to A_HIGH
do
2390 FMaxAmmo
[I
] := M
.ReadWord();
2392 for I
:= MR_SUIT
to MR_MAX
do
2393 FMegaRulez
[I
] := M
.ReadLongWord();
2396 if (M
.ReadByte() <> 0) then
2397 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2398 if (M
.ReadByte() <> 0) then
2399 FRulez
:= FRulez
+ [R_KEY_RED
];
2400 if (M
.ReadByte() <> 0) then
2401 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2402 if (M
.ReadByte() <> 0) then
2403 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2404 if (M
.ReadByte() <> 0) then
2405 FRulez
:= FRulez
+ [R_BERSERK
];
2407 Frags
:= M
.ReadLongInt();
2408 Death
:= M
.ReadLongInt();
2410 SetWeapon(M
.ReadByte());
2412 FSpectator
:= M
.ReadByte() <> 0;
2415 if UID
= NetPlrUID1
then
2417 gSpectLatchPID1
:= UID
;
2420 if UID
= NetPlrUID2
then
2422 gSpectLatchPID2
:= UID
;
2428 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2431 gSpectLatchPID1
:= 0;
2433 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2436 gSpectLatchPID2
:= 0;
2439 FGhost
:= M
.ReadByte() <> 0;
2440 FPhysics
:= M
.ReadByte() <> 0;
2441 FNoRespawn
:= M
.ReadByte() <> 0;
2443 FJetpack
:= M
.ReadByte() <> 0;
2444 OldFire
:= FFireTime
;
2445 FFireTime
:= M
.ReadLongInt();
2446 if (OldFire
<= 0) and (FFireTime
> 0) then
2447 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2448 Flam
:= M
.ReadByte() <> 0;
2449 FSpawnInvul
:= M
.ReadLongInt();
2450 if OldJet
and not FJetpack
then
2452 else if not OldJet
and FJetpack
then
2454 if FFlaming
and not Flam
then
2456 if Team
<> NewTeam
then
2457 Pl
.ChangeTeam(NewTeam
);
2463 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2468 Attacker
, Value
: Word;
2472 if not gGameOn
then Exit
;
2473 PID
:= M
.ReadWord();
2474 Pl
:= g_Player_Get(PID
);
2475 if Pl
= nil then Exit
;
2477 Kind
:= M
.ReadByte();
2478 Attacker
:= M
.ReadWord();
2479 Value
:= M
.ReadWord();
2484 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2489 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2493 KillType
, DeathType
: Byte;
2497 if not gGameOn
then Exit
;
2498 PID
:= M
.ReadWord();
2499 Pl
:= g_Player_Get(PID
);
2500 if Pl
= nil then Exit
;
2502 KillType
:= M
.ReadByte();
2503 DeathType
:= M
.ReadByte();
2504 Attacker
:= M
.ReadWord();
2508 Kill(KillType
, Attacker
, DeathType
);
2513 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2518 PID
:= M
.ReadWord();
2519 Pl
:= g_Player_Get(PID
);
2521 if Pl
= nil then Exit
;
2523 if NetDeafLevel
< 3 then
2524 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2525 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2527 g_Player_Remove(PID
);
2532 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2537 X
, Y
, AX
, AY
: Integer;
2541 if not gGameOn
then Exit
;
2542 PID
:= M
.ReadWord();
2543 Pl
:= g_Player_Get(PID
);
2544 if Pl
= nil then Exit
;
2546 Weap
:= M
.ReadByte();
2547 X
:= M
.ReadLongInt();
2548 Y
:= M
.ReadLongInt();
2549 AX
:= M
.ReadLongInt();
2550 AY
:= M
.ReadLongInt();
2551 SHID
:= M
.ReadLongInt();
2554 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2557 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2566 PID
:= M
.ReadWord();
2567 Pl
:= g_Player_Get(PID
);
2568 if Pl
= nil then Exit
;
2570 TmpName
:= M
.ReadString();
2571 TmpModel
:= M
.ReadString();
2572 TmpColor
.R
:= M
.ReadByte();
2573 TmpColor
.G
:= M
.ReadByte();
2574 TmpColor
.B
:= M
.ReadByte();
2575 TmpTeam
:= M
.ReadByte();
2577 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2579 Pl
.ChangeTeam(TmpTeam
);
2580 if gPlayer1
= Pl
then
2581 gPlayer1Settings
.Team
:= TmpTeam
;
2582 if gPlayer2
= Pl
then
2583 gPlayer2Settings
.Team
:= TmpTeam
;
2585 Pl
.SetColor(TmpColor
);
2587 if Pl
.Name
<> TmpName
then
2589 if NetDeafLevel
< 3 then
2590 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2594 if TmpModel
<> Pl
.Model
.Name
then
2595 Pl
.SetModel(TmpModel
);
2600 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2604 X
, Y
, VX
, VY
: Integer;
2606 Quiet
, Fall
{, Resp}: Boolean;
2610 if not gGameOn
then Exit
;
2612 Quiet
:= M
.ReadByte() <> 0;
2614 Fall
:= M
.ReadByte() <> 0;
2615 {Resp :=} M
.ReadByte();
2616 X
:= M
.ReadLongInt();
2617 Y
:= M
.ReadLongInt();
2618 VX
:= M
.ReadLongInt();
2619 VY
:= M
.ReadLongInt();
2621 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2622 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2624 it
:= g_Items_ByIdx(ID
);
2630 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2631 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2633 Anim
:= TAnimation
.Create(AID
, False, 4);
2634 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2640 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2645 if not gGameOn
then Exit
;
2647 Quiet
:= M
.ReadByte() <> 0;
2649 if not g_Items_ValidId(ID
) then exit
;
2651 if not Quiet
then g_Items_EmitPickupSound(ID
);
2656 procedure MC_RECV_ItemPos(var M
: TMsg
);
2659 X
, Y
, VX
, VY
: Integer;
2662 if not gGameOn
then Exit
;
2665 X
:= M
.ReadLongInt();
2666 Y
:= M
.ReadLongInt();
2667 VX
:= M
.ReadLongInt();
2668 VY
:= M
.ReadLongInt();
2670 if g_Items_ValidId(ID
) then
2672 it
:= g_Items_ByIdx(ID
);
2677 it
.positionChanged();
2683 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2690 if not gGameOn
then Exit
;
2692 PGUID
:= Integer(M
.ReadLongWord());
2693 Tex
:= M
.ReadLongInt();
2694 Fr
:= M
.ReadLongInt();
2695 Cnt
:= M
.ReadByte();
2696 Loop
:= M
.ReadByte();
2698 TP
:= g_Map_PanelByGUID(PGUID
);
2702 TP
.SetTexture(Tex
, Loop
);
2703 TP
.SetFrame(Fr
, Cnt
);
2707 procedure MC_RECV_PanelState(var M
: TMsg
);
2712 X
, Y
, W
, H
: Integer;
2714 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2715 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2718 if not gGameOn
then Exit
;
2720 PGUID
:= Integer(M
.ReadLongWord());
2721 E
:= (M
.ReadByte() <> 0);
2722 Lift
:= M
.ReadByte();
2723 X
:= M
.ReadLongInt();
2724 Y
:= M
.ReadLongInt();
2728 speedX
:= M
.ReadLongInt();
2729 speedY
:= M
.ReadLongInt();
2730 startX
:= M
.ReadLongInt();
2731 startY
:= M
.ReadLongInt();
2732 endX
:= M
.ReadLongInt();
2733 endY
:= M
.ReadLongInt();
2734 sizeSpX
:= M
.ReadLongInt();
2735 sizeSpY
:= M
.ReadLongInt();
2736 sizeEX
:= M
.ReadLongInt();
2737 sizeEY
:= M
.ReadLongInt();
2738 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2740 TP
:= g_Map_PanelByGUID(PGUID
);
2741 if (TP
= nil) then exit
;
2743 // update lifts state
2744 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2746 // update enabled/disabled state for all panels
2747 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2749 // update panel position, as it can be moved (mplat)
2754 // update mplat state
2755 TP
.movingSpeedX
:= speedX
;
2756 TP
.movingSpeedY
:= speedY
;
2757 TP
.movingStartX
:= startX
;
2758 TP
.movingStartY
:= startY
;
2759 TP
.movingEndX
:= endX
;
2760 TP
.movingEndY
:= endY
;
2761 TP
.sizeSpeedX
:= sizeSpX
;
2762 TP
.sizeSpeedY
:= sizeSpY
;
2763 TP
.sizeEndX
:= sizeEX
;
2764 TP
.sizeEndY
:= sizeEY
;
2765 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2766 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2767 // notify panel of it's position/size change, so it can fix other internal structures
2768 TP
.positionChanged();
2773 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2776 SPos
, SID
: LongWord;
2780 if not gGameOn
then Exit
;
2781 if gTriggers
= nil then Exit
;
2783 SID
:= M
.ReadLongWord();
2784 SPlaying
:= M
.ReadByte() <> 0;
2785 SPos
:= M
.ReadLongWord();
2786 SCount
:= M
.ReadLongInt();
2788 for I
:= Low(gTriggers
) to High(gTriggers
) do
2789 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2790 if gTriggers
[I
].ClientID
= SID
then
2791 with gTriggers
[I
] do
2793 if Sound
<> nil then
2798 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2800 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2801 Sound
.SetPosition(SPos
);
2804 if Sound
.IsPlaying
then Sound
.Stop
;
2807 SoundPlayCount
:= SCount
;
2811 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2818 if not gGameOn
then Exit
;
2820 MName
:= M
.ReadString();
2821 MPlaying
:= M
.ReadByte() <> 0;
2822 MPos
:= M
.ReadLongWord();
2823 MPaused
:= M
.ReadByte() <> 0;
2824 MPos
:= MPos
+1; //k8: stfu, fpc!
2828 gMusic
.SetByName(MName
);
2830 // gMusic.SetPosition(MPos);
2831 gMusic
.SpecPause
:= MPaused
;
2834 if gMusic
.IsPlaying
then gMusic
.Stop
;
2839 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2842 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2843 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2848 Mon
:= g_Monsters_ByUID(ID
);
2852 MType
:= M
.ReadByte();
2853 MState
:= M
.ReadByte();
2854 MAnim
:= M
.ReadByte();
2855 MTarg
:= M
.ReadWord();
2856 MTargTime
:= M
.ReadLongInt();
2857 MBehav
:= M
.ReadByte();
2858 MSleep
:= M
.ReadLongInt();
2859 MHealth
:= M
.ReadLongInt();
2860 MAmmo
:= M
.ReadLongInt();
2862 X
:= M
.ReadLongInt();
2863 Y
:= M
.ReadLongInt();
2864 VX
:= M
.ReadLongInt();
2865 VY
:= M
.ReadLongInt();
2866 MDir
:= M
.ReadByte();
2868 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2869 Mon
:= g_Monsters_ByUID(ID
);
2876 MonsterAnim
:= MAnim
;
2877 MonsterTargetUID
:= MTarg
;
2878 MonsterTargetTime
:= MTargTime
;
2879 MonsterBehaviour
:= MBehav
;
2880 MonsterSleep
:= MSleep
;
2881 MonsterAmmo
:= MAmmo
;
2886 setPosition(X
, Y
); // this will call positionChanged();
2892 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2899 Mon
:= g_Monsters_ByUID(ID
);
2905 X
:= M
.ReadLongInt();
2906 Y
:= M
.ReadLongInt();
2907 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2908 GameVelX
:= M
.ReadLongInt();
2909 GameVelY
:= M
.ReadLongInt();
2910 GameDirection
:= TDirection(M
.ReadByte());
2914 procedure MC_RECV_MonsterState(var M
: TMsg
);
2916 ID
, OldFire
: Integer;
2917 MState
, MFAnm
: Byte;
2919 AnimRevert
: Boolean;
2922 Mon
:= g_Monsters_ByUID(ID
);
2923 if Mon
= nil then Exit
;
2925 MState
:= M
.ReadByte();
2926 MFAnm
:= M
.ReadByte();
2930 MonsterTargetUID
:= M
.ReadWord();
2931 MonsterTargetTime
:= M
.ReadLongInt();
2932 MonsterSleep
:= M
.ReadLongInt();
2933 MonsterHealth
:= M
.ReadLongInt();
2934 MonsterAmmo
:= M
.ReadLongInt();
2935 MonsterPain
:= M
.ReadLongInt();
2936 AnimRevert
:= M
.ReadByte() <> 0;
2937 OldFire
:= FFireTime
;
2938 FFireTime
:= M
.ReadLongInt();
2939 if (OldFire
<= 0) and (FFireTime
> 0) then
2940 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2941 RevertAnim(AnimRevert
);
2943 if MonsterState
<> MState
then
2945 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2946 if (MState
= MONSTATE_DIE
) then DieSound();
2947 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2948 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2949 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2951 SetState(MState
, MFAnm
);
2956 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2960 X
, Y
, VX
, VY
: Integer;
2964 Mon
:= g_Monsters_ByUID(ID
);
2965 if Mon
= nil then Exit
;
2967 X
:= M
.ReadLongInt();
2968 Y
:= M
.ReadLongInt();
2969 VX
:= M
.ReadLongInt();
2970 VY
:= M
.ReadLongInt();
2972 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2975 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2981 Mon
:= g_Monsters_ByUID(ID
);
2982 if Mon
= nil then Exit
;
2984 Mon
.MonsterRemoved
:= True;
2987 procedure MC_RECV_TimeSync(var M
: TMsg
);
2991 Time
:= M
.ReadLongWord();
2993 if gState
= STATE_INTERCUSTOM
then
2994 gServInterTime
:= Min(Time
, 255);
2997 procedure MC_RECV_VoteEvent(var M
: TMsg
);
3001 Int1
, Int2
: SmallInt;
3003 EvID
:= M
.ReadByte();
3004 Int1
:= M
.ReadSmallInt();
3005 Int2
:= M
.ReadSmallInt();
3006 Str1
:= M
.ReadString();
3007 Str2
:= M
.ReadString();
3009 if NetDeafLevel
< 2 then
3012 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
3014 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
3016 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
3018 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
3020 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
3026 procedure MC_SEND_Info(Password
: string);
3030 NetOut
.Write(Byte(NET_MSG_INFO
));
3031 NetOut
.Write(GAME_VERSION
);
3032 NetOut
.Write(Password
);
3033 NetOut
.Write(gPlayer1Settings
.Name
);
3034 NetOut
.Write(gPlayer1Settings
.Model
);
3035 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3036 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3037 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3038 NetOut
.Write(gPlayer1Settings
.Team
);
3040 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3043 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
3045 NetOut
.Write(Byte(NET_MSG_CHAT
));
3049 g_Net_Client_Send(True, NET_CHAN_CHAT
);
3052 procedure MC_SEND_PlayerPos();
3057 WeaponAct
: Byte = 0;
3058 WeaponSelect
: Word = 0;
3061 if not gGameOn
then Exit
;
3062 if gPlayers
= nil then Exit
;
3063 if gPlayer1
= nil then Exit
;
3066 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
3068 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
3070 strafeDir
:= P1MoveButton
shr 4;
3071 P1MoveButton
:= P1MoveButton
and $0F;
3073 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3075 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3077 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3081 if gPlayerAction
[0, ACTION_STRAFE
] then
3083 // new strafe mechanics
3084 if (strafeDir
= 0) then
3085 strafeDir
:= P1MoveButton
; // start strafing
3086 // now set direction according to strafe (reversed)
3087 if (strafeDir
= 2) then
3088 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3089 else if (strafeDir
= 1) then
3090 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3094 strafeDir
:= 0; // not strafing anymore
3095 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3096 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3097 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3098 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3099 else if P1MoveButton
<> 0 then
3100 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3103 gPlayer1
.ReleaseKeys
;
3104 if P1MoveButton
= 1 then
3106 kByte
:= kByte
or NET_KEY_LEFT
;
3107 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3109 if P1MoveButton
= 2 then
3111 kByte
:= kByte
or NET_KEY_RIGHT
;
3112 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3114 if gPlayerAction
[0, ACTION_LOOKUP
] then
3116 kByte
:= kByte
or NET_KEY_UP
;
3117 gPlayer1
.PressKey(KEY_UP
, 10000);
3119 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3121 kByte
:= kByte
or NET_KEY_DOWN
;
3122 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3124 if gPlayerAction
[0, ACTION_JUMP
] then
3126 kByte
:= kByte
or NET_KEY_JUMP
;
3127 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3129 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3130 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3132 for i
:= WP_FACT
to WP_LACT
do
3134 if gWeaponAction
[0, i
] then
3136 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3137 gWeaponAction
[0, i
] := False
3141 for i
:= WP_FIRST
to WP_LAST
do
3143 if gSelectWeapon
[0, i
] then
3145 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3146 gSelectWeapon
[0, i
] := False
3150 // fix movebutton state
3151 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3154 kByte
:= NET_KEY_CHAT
;
3156 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3157 NetOut
.Write(gTime
);
3158 NetOut
.Write(kByte
);
3159 NetOut
.Write(Byte(gPlayer1
.Direction
));
3160 NetOut
.Write(WeaponAct
);
3161 NetOut
.Write(WeaponSelect
);
3162 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3163 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3165 //kBytePrev := kByte;
3166 //kDirPrev := gPlayer1.Direction;
3169 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3171 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3172 NetOut
.Write(Byte(Start
));
3173 NetOut
.Write(Command
);
3174 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3177 procedure MC_SEND_PlayerSettings();
3179 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3180 NetOut
.Write(gPlayer1Settings
.Name
);
3181 NetOut
.Write(gPlayer1Settings
.Model
);
3182 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3183 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3184 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3185 NetOut
.Write(gPlayer1Settings
.Team
);
3187 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3190 procedure MC_SEND_FullStateRequest();
3192 NetOut
.Write(Byte(NET_MSG_REQFST
));
3194 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3197 procedure MC_SEND_CheatRequest(Kind
: Byte);
3199 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3202 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3204 procedure MC_SEND_RCONPassword(Password
: string);
3206 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3207 NetOut
.Write(Password
);
3209 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3211 procedure MC_SEND_RCONCommand(Cmd
: string);
3213 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3216 g_Net_Client_Send(True, NET_CHAN_SERVICE
);