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
;
64 NET_MSG_RCON_AUTH
= 191;
65 NET_MSG_RCON_CMD
= 192;
66 NET_MSG_TIME_SYNC
= 194;
67 NET_MSG_VOTE_EVENT
= 195;
70 NET_MSG_MAP_REQUEST = 201;
71 NET_MSG_MAP_RESPONSE = 202;
72 NET_MSG_RES_REQUEST = 203;
73 NET_MSG_RES_RESPONSE = 204;
97 NET_EV_CHANGE_TEAM
= 3;
98 NET_EV_PLAYER_KICK
= 4;
99 NET_EV_PLAYER_BAN
= 5;
100 NET_EV_LMS_WARMUP
= 6;
101 NET_EV_LMS_SURVIVOR
= 7;
105 NET_EV_SCORE_MSG
= 11;
106 NET_EV_LMS_START
= 12;
108 NET_EV_TLMS_WIN
= 14;
109 NET_EV_LMS_LOSE
= 15;
110 NET_EV_LMS_DRAW
= 16;
111 NET_EV_KILLCOMBO
= 17;
112 NET_EV_PLAYER_TOUCH
= 18;
114 NET_EV_INTER_READY
= 20;
115 NET_EV_LMS_NOSPAWN
= 21;
122 NET_VE_INPROGRESS
= 6;
129 NET_CHEAT_SUICIDE
= 1;
130 NET_CHEAT_SPECTATE
= 2;
133 NET_MAX_DIFFTIME
= 5000 div 36;
137 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
139 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
140 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
141 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
142 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
143 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
146 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
147 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
148 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
149 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
152 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
153 procedure MH_SEND_Info(ID
: Byte);
154 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
170 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
190 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
191 procedure MH_SEND_VoteEvent(EvType
: Byte;
192 StrArg1
: string = 'a'; StrArg2
: string = 'b';
193 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
194 ID
: Integer = NET_EVERYONE
);
196 // CLIENT MESSAGES //
199 procedure MC_RECV_Chat(var M
: TMsg
);
200 procedure MC_RECV_Effect(var M
: TMsg
);
201 procedure MC_RECV_Sound(var M
: TMsg
);
202 procedure MC_RECV_GameStats(var M
: TMsg
);
203 procedure MC_RECV_CoopStats(var M
: TMsg
);
204 procedure MC_RECV_GameEvent(var M
: TMsg
);
205 procedure MC_RECV_FlagEvent(var M
: TMsg
);
206 procedure MC_RECV_GameSettings(var M
: TMsg
);
208 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
209 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
210 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
211 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
212 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
213 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
214 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
215 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
217 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
218 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
220 procedure MC_RECV_PanelTexture(var M
: TMsg
);
221 procedure MC_RECV_PanelState(var M
: TMsg
);
223 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
224 procedure MC_RECV_MonsterPos(var M
: TMsg
);
225 procedure MC_RECV_MonsterState(var M
: TMsg
);
226 procedure MC_RECV_MonsterShot(var M
: TMsg
);
227 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
229 procedure MC_RECV_CreateShot(var M
: TMsg
);
230 procedure MC_RECV_UpdateShot(var M
: TMsg
);
231 procedure MC_RECV_DeleteShot(var M
: TMsg
);
233 procedure MC_RECV_TriggerSound(var M
: TMsg
);
234 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
236 procedure MC_RECV_TimeSync(var M
: TMsg
);
237 procedure MC_RECV_VoteEvent(var M
: TMsg
);
239 procedure MC_SEND_Info(Password
: string);
240 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
241 procedure MC_SEND_PlayerPos();
242 procedure MC_SEND_FullStateRequest();
243 procedure MC_SEND_PlayerSettings();
244 procedure MC_SEND_CheatRequest(Kind
: Byte);
245 procedure MC_SEND_RCONPassword(Password
: string);
246 procedure MC_SEND_RCONCommand(Cmd
: string);
247 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
249 //procedure MC_SEND_MapRequest();
250 //procedure MC_SEND_ResRequest(const resName: AnsiString);
254 TExternalResourceInfo
= record
269 ExternalResources
: array of TExternalResourceInfo
;
272 function IsValidFileName(const S
: String): Boolean;
273 function IsValidFilePath(const S
: String): Boolean;
279 Math
, ENet
, e_input
, e_graphics
, e_log
,
280 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
281 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
282 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
295 NET_KEY_FORCEDIR
= 4096;
298 //kBytePrev: Word = 0;
299 //kDirPrev: TDirection = D_LEFT;
300 //HostGameTime: Word = 0;
303 function IsValidFileName(const S
: String): Boolean;
305 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
310 for I
:= 1 to Length(S
) do
311 Result
:= Result
and (not(S
[I
] in Forbidden
));
314 function IsValidFilePath(const S
: String): Boolean;
319 if not IsValidFileName(S
) then exit
;
320 if FileExists(S
) then exit
;
321 I
:= LastDelimiter('\/', S
);
323 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
334 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
342 Pl
:= g_Player_Get(PID
);
344 Txt
:= M
.ReadString();
345 Mode
:= M
.ReadByte();
346 if (Mode
= NET_CHAT_SYSTEM
) then
347 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
348 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
349 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
352 MH_SEND_Chat(Txt
, Mode
)
354 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
357 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
359 Ver
, PName
, Model
, Pw
: string;
365 Ver
:= M
.ReadString();
366 Pw
:= M
.ReadString();
367 PName
:= M
.ReadString();
368 Model
:= M
.ReadString();
374 if Ver
<> GAME_VERSION
then
376 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
377 _lc
[I_NET_DISC_VERSION
]);
378 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
382 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
384 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
386 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
387 _lc
[I_NET_DISC_BAN
]);
388 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
392 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
393 _lc
[I_NET_DISC_BAN
]);
394 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
399 if NetPassword
<> '' then
400 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
402 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
403 _lc
[I_NET_DISC_PASSWORD
]);
404 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
412 PID
:= g_Player_Create(Model
, Color
, T
, False);
413 with g_Player_Get(PID
) do
420 C
^.WaitForFirstSpawn
:= false;
422 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
423 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
424 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
428 with g_Player_Get(PID
) do
432 // round in progress, don't spawn
433 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
434 //e_LogWritefln('spawning player with pid #%u...', [PID]);
435 //Respawn(gGameSettings.GameType = GT_SINGLE);
436 //k8: no, do not spawn a player yet, wait for "request full state" packet
440 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
441 // that is, if we'll set it to `true`, the player can be spawned after
442 // warmup time ran out, for example, regardless of the real player state.
443 // also, this seems to work only for the initial connection. further
444 // map changes could initiate resource downloading, but the player will
445 // be spawned immediately.
446 // the proper solution will require another player state, "ephemeral".
447 // the player should start any map in "ephemeral" state, and turned into
448 // real mobj only when they sent a special "i am ready" packet. this packet
449 // must be sent after receiving the full state, so the player will get a full
450 // map view before going into game.
451 FWantsInGame
:= false;
452 C
^.WaitForFirstSpawn
:= true;
455 //if not C^.WaitForFirstSpawn then
457 for I
:= Low(NetClients
) to High(NetClients
) do
459 if NetClients
[I
].ID
= C
^.ID
then Continue
;
460 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
461 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
462 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
466 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
467 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
471 //g_Net_Slist_Update;
477 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
481 if not C
.WaitForFirstSpawn
then exit
;
482 plr
:= g_Player_Get(C
^.Player
);
483 if not assigned(plr
) then exit
;
484 g_Net_Slist_ServerPlayerComes();
485 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
486 C
.WaitForFirstSpawn
:= false;
487 plr
.FNoRespawn
:= false;
488 plr
.FWantsInGame
:= true; // TODO: look into this later
490 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
493 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
498 if gLMSRespawn
> LMS_RESPAWN_NONE
then
499 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
504 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
506 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
509 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
513 C
^.RequestedFullUpdate
:= True;
519 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
529 if not gGameOn
then Exit
;
531 GT
:= M
.ReadLongWord();
533 Pl
:= g_Player_Get(PID
);
537 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
542 kByte
:= M
.ReadWord();
544 WeaponSelect
:= M
.ReadWord();
545 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
546 if Direction
<> TDirection(Dir
) then
547 JustTeleported
:= False;
549 SetDirection(TDirection(Dir
));
552 if kByte
= NET_KEY_CHAT
then
554 PressKey(KEY_CHAT
, 10000);
558 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
559 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
560 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
561 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
562 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
563 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
564 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
565 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
566 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
570 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
572 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
573 QueueWeaponSwitch(i
);
578 // MH_SEND_PlayerPos(False, PID, C^.ID);
581 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
586 Pl
:= g_Player_Get(C
^.Player
);
587 if Pl
= nil then Exit
;
589 CheatKind
:= M
.ReadByte();
593 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
596 if Pl
.FSpectator
then
598 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
601 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
608 if gState
<> STATE_INTERCUSTOM
then Exit
;
609 Pl
.FReady
:= not Pl
.FReady
;
612 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
613 Inc(gInterReadyCount
);
617 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
618 Dec(gInterReadyCount
);
624 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
632 TmpName
:= M
.ReadString();
633 TmpModel
:= M
.ReadString();
634 TmpColor
.R
:= M
.ReadByte();
635 TmpColor
.G
:= M
.ReadByte();
636 TmpColor
.B
:= M
.ReadByte();
637 TmpTeam
:= M
.ReadByte();
639 Pl
:= g_Player_Get(C
^.Player
);
640 if Pl
= nil then Exit
;
642 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
645 Pl
.SetColor(TmpColor
);
647 if Pl
.Name
<> TmpName
then
649 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
653 if TmpModel
<> Pl
.Model
.Name
then
654 Pl
.SetModel(TmpModel
);
656 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
661 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
665 Pwd
:= M
.ReadString();
666 if not NetAllowRCON
then Exit
;
667 if Pwd
= NetRCONPassword
then
670 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
673 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
676 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
680 Cmd
:= M
.ReadString();
681 if not NetAllowRCON
then Exit
;
682 if not C
^.RCONAuth
then
684 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
687 g_Console_Process(Cmd
);
692 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
695 Name
, Command
: string;
699 Start
:= M
.ReadByte() <> 0;
700 Command
:= M
.ReadString();
702 Pl
:= g_Player_Get(C
^.Player
);
703 if Pl
= nil then Exit
;
708 if not g_Console_CommandBlacklisted(Command
) then
709 g_Game_StartVote(Command
, Name
);
711 else if gVoteInProgress
then
713 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
714 Need
:= Floor((NetClientCount
+1)/2.0) + 1
716 Need
:= Floor(NetClientCount
/2.0) + 1;
721 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
722 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
728 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
729 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
737 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
739 function sendItemRespawn (it
: PItem
): Boolean;
741 result
:= false; // don't stop
742 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
745 function sendMonSpawn (mon
: TMonster
): Boolean;
747 result
:= false; // don't stop
748 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
751 function sendPanelState (pan
: TPanel
): Boolean;
753 result
:= false; // don't stop
754 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
755 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
761 if (ID
>= 0) and (ID
< length(NetClients
)) then
763 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
764 MH_ProcessFirstSpawn(@NetClients
[ID
]);
767 if gPlayers
<> nil then
769 for I
:= Low(gPlayers
) to High(gPlayers
) do
771 if gPlayers
[I
] <> nil then
773 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
774 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
775 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
777 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
779 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
785 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
786 g_Mons_ForEach(sendMonSpawn
);
787 g_Map_ForEachPanel(sendPanelState
);
789 if gTriggers
<> nil then
791 for I
:= Low(gTriggers
) to High(gTriggers
) do
793 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
795 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
802 for I
:= Low(Shots
) to High(Shots
) do
804 if Shots
[i
].ShotType
in [6, 7, 8] then
806 MH_SEND_CreateShot(i
, ID
);
811 MH_SEND_TriggerMusic(ID
);
813 MH_SEND_GameStats(ID
);
814 MH_SEND_CoopStats(ID
);
816 if gGameSettings
.GameMode
= GM_CTF
then
818 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
819 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
822 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
827 procedure MH_SEND_Info(ID
: Byte);
831 NetOut
.Write(Byte(NET_MSG_INFO
));
833 NetOut
.Write(NetClients
[ID
].Player
);
834 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
835 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
836 NetOut
.Write(gWADHash
);
837 NetOut
.Write(gGameSettings
.GameMode
);
838 NetOut
.Write(gGameSettings
.GoalLimit
);
839 NetOut
.Write(gGameSettings
.TimeLimit
);
840 NetOut
.Write(gGameSettings
.MaxLives
);
841 NetOut
.Write(gGameSettings
.Options
);
844 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
847 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
853 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
854 Mode
:= NET_CHAT_PLAYER
;
857 if (Mode
= NET_CHAT_TEAM
) then
859 for i
:= Low(gPlayers
) to High(gPlayers
) do
860 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
861 (gPlayers
[i
].Team
= ID
) then
863 NetOut
.Write(Byte(NET_MSG_CHAT
));
866 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
873 NetOut
.Write(Byte(NET_MSG_CHAT
));
876 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
879 if Mode
= NET_CHAT_SYSTEM
then
882 if ID
= NET_EVERYONE
then
884 if Mode
= NET_CHAT_PLAYER
then
886 g_Console_Add(Txt
, True);
887 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
888 g_Game_ChatSound(b_Text_Unformat(Txt
));
891 if Mode
= NET_CHAT_TEAM
then
892 if gPlayer1
<> nil then
894 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
896 g_Console_Add(#18'[Team] '#2 + Txt
, True);
897 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
898 g_Game_ChatSound(b_Text_Unformat(Txt
));
900 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
902 g_Console_Add(#20'[Team] '#2 + Txt
, True);
903 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
904 g_Game_ChatSound(b_Text_Unformat(Txt
));
910 Name
:= g_Net_ClientName_ByID(ID
);
911 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
912 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
913 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
917 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
919 NetOut
.Write(Byte(NET_MSG_GFX
));
925 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
928 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
930 NetOut
.Write(Byte(NET_MSG_SND
));
934 NetOut
.Write(Byte(1));
939 NetOut
.Write(Byte(0));
941 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
944 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
946 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
948 NetOut
.Write(Byte(NET_MSG_SHADD
));
950 NetOut
.Write(Shots
[Proj
].ShotType
);
951 NetOut
.Write(Shots
[Proj
].Target
);
952 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
953 NetOut
.Write(Shots
[Proj
].Timeout
);
954 NetOut
.Write(Shots
[Proj
].Obj
.X
);
955 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
956 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
957 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
959 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
962 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
964 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
966 NetOut
.Write(Byte(NET_MSG_SHPOS
));
968 NetOut
.Write(Shots
[Proj
].Obj
.X
);
969 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
970 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
971 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
973 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
976 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
978 NetOut
.Write(Byte(NET_MSG_SHDEL
));
980 NetOut
.Write(Byte(Loud
));
984 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
987 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
989 NetOut
.Write(Byte(NET_MSG_SCORE
));
990 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
992 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
993 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
996 if gGameSettings
.GameMode
= GM_COOP
then
998 NetOut
.Write(gCoopMonstersKilled
);
999 NetOut
.Write(gCoopSecretsFound
);
1002 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1005 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1007 NetOut
.Write(Byte(NET_MSG_COOP
));
1008 NetOut
.Write(gTotalMonsters
);
1009 NetOut
.Write(gSecretsCount
);
1010 NetOut
.Write(gCoopTotalMonstersKilled
);
1011 NetOut
.Write(gCoopTotalSecretsFound
);
1012 NetOut
.Write(gCoopTotalMonsters
);
1013 NetOut
.Write(gCoopTotalSecrets
);
1016 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1018 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1019 NetOut
.Write(EvType
);
1020 NetOut
.Write(EvNum
);
1021 NetOut
.Write(EvStr
);
1022 NetOut
.Write(Byte(gLastMap
));
1023 NetOut
.Write(gTime
);
1024 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1026 NetOut
.Write(Byte(1));
1027 NetOut
.Write(gWADHash
);
1029 NetOut
.Write(Byte(0));
1031 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1034 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1036 NetOut
.Write(Byte(NET_MSG_FLAG
));
1037 NetOut
.Write(EvType
);
1039 NetOut
.Write(Byte(Quiet
));
1041 NetOut
.Write(gFlags
[Flag
].State
);
1042 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1043 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1044 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1045 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1046 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1048 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1051 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1053 NetOut
.Write(Byte(NET_MSG_GSET
));
1054 NetOut
.Write(gGameSettings
.GameMode
);
1055 NetOut
.Write(gGameSettings
.GoalLimit
);
1056 NetOut
.Write(gGameSettings
.TimeLimit
);
1057 NetOut
.Write(gGameSettings
.MaxLives
);
1058 NetOut
.Write(gGameSettings
.Options
);
1060 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1065 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1069 P
:= g_Player_Get(PID
);
1070 if P
= nil then Exit
;
1072 NetOut
.Write(Byte(NET_MSG_PLR
));
1074 NetOut
.Write(P
.Name
);
1076 NetOut
.Write(P
.FActualModelName
);
1077 NetOut
.Write(P
.FColor
.R
);
1078 NetOut
.Write(P
.FColor
.G
);
1079 NetOut
.Write(P
.FColor
.B
);
1080 NetOut
.Write(P
.Team
);
1082 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1085 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1090 Pl
:= g_Player_Get(PID
);
1091 if Pl
= nil then Exit
;
1092 if Pl
.FDummy
then Exit
;
1094 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1095 NetOut
.Write(gTime
);
1102 NetOut
.Write(FPing
);
1103 NetOut
.Write(FLoss
);
1104 if IsKeyPressed(KEY_CHAT
) then
1105 kByte
:= NET_KEY_CHAT
1108 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1109 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1110 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1111 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1112 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1115 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1117 NetOut
.Write(kByte
);
1118 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1119 NetOut
.Write(GameX
);
1120 NetOut
.Write(GameY
);
1121 NetOut
.Write(GameVelX
);
1122 NetOut
.Write(GameVelY
);
1123 NetOut
.Write(GameAccelX
);
1124 NetOut
.Write(GameAccelY
);
1127 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1130 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1135 P
:= g_Player_Get(PID
);
1136 if P
= nil then Exit
;
1138 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1143 NetOut
.Write(Byte(alive
));
1144 NetOut
.Write(Byte(GodMode
));
1145 NetOut
.Write(Health
);
1146 NetOut
.Write(Armor
);
1148 NetOut
.Write(JetFuel
);
1149 NetOut
.Write(Lives
);
1152 for I
:= WP_FIRST
to WP_LAST
do
1153 NetOut
.Write(Byte(FWeapon
[I
]));
1155 for I
:= A_BULLETS
to A_HIGH
do
1156 NetOut
.Write(FAmmo
[I
]);
1158 for I
:= A_BULLETS
to A_HIGH
do
1159 NetOut
.Write(FMaxAmmo
[I
]);
1161 for I
:= MR_SUIT
to MR_MAX
do
1162 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1164 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1165 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1166 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1167 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1168 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1170 NetOut
.Write(Frags
);
1171 NetOut
.Write(Death
);
1173 NetOut
.Write(CurrWeap
);
1175 NetOut
.Write(Byte(FSpectator
));
1176 NetOut
.Write(Byte(FGhost
));
1177 NetOut
.Write(Byte(FPhysics
));
1178 NetOut
.Write(Byte(FNoRespawn
));
1179 NetOut
.Write(Byte(FJetpack
));
1180 NetOut
.Write(FFireTime
);
1181 NetOut
.Write(Byte(FFlaming
));
1182 NetOut
.Write(FSpawnInvul
);
1185 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1188 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1190 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1193 NetOut
.Write(Attacker
);
1194 NetOut
.Write(Value
);
1198 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1201 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1203 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1205 NetOut
.Write(KillType
);
1206 NetOut
.Write(DeathType
);
1207 NetOut
.Write(Attacker
);
1209 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1212 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1214 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1216 NetOut
.Write(Weapon
);
1221 NetOut
.Write(ShotID
);
1223 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1226 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1228 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1231 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1234 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1238 Pl
:= g_Player_Get(PID
);
1239 if Pl
= nil then Exit
;
1241 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1243 NetOut
.Write(Pl
.Name
);
1245 NetOut
.Write(Pl
.Model
.Name
)
1248 NetOut
.Write(Pl
.FColor
.R
);
1249 NetOut
.Write(Pl
.FColor
.G
);
1250 NetOut
.Write(Pl
.FColor
.B
);
1251 NetOut
.Write(Pl
.Team
);
1253 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1258 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1263 it
:= g_Items_ByIdx(IID
);
1265 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1267 NetOut
.Write(Byte(Quiet
));
1269 if it
.dropped
then tt
:= tt
or $80;
1271 NetOut
.Write(Byte(it
.Fall
));
1272 NetOut
.Write(Byte(it
.Respawnable
));
1273 NetOut
.Write(it
.Obj
.X
);
1274 NetOut
.Write(it
.Obj
.Y
);
1275 NetOut
.Write(it
.Obj
.Vel
.X
);
1276 NetOut
.Write(it
.Obj
.Vel
.Y
);
1278 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1281 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1283 NetOut
.Write(Byte(NET_MSG_IDEL
));
1285 NetOut
.Write(Byte(Quiet
));
1287 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1292 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1296 TP
:= g_Map_PanelByGUID(PGUID
);
1297 if (TP
= nil) then exit
;
1301 NetOut
.Write(Byte(NET_MSG_PTEX
));
1302 NetOut
.Write(LongWord(PGUID
));
1303 NetOut
.Write(FCurTexture
);
1304 NetOut
.Write(FCurFrame
);
1305 NetOut
.Write(FCurFrameCount
);
1306 NetOut
.Write(AnimLoop
);
1309 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1312 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1317 TP
:= g_Map_PanelByGUID(PGUID
);
1318 if (TP
= nil) then exit
;
1320 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1321 NetOut
.Write(LongWord(PGUID
));
1322 NetOut
.Write(Byte(TP
.Enabled
));
1323 NetOut
.Write(TP
.LiftType
);
1326 NetOut
.Write(Word(TP
.Width
));
1327 NetOut
.Write(Word(TP
.Height
));
1329 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1330 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1331 NetOut
.Write(LongInt(TP
.movingStartX
));
1332 NetOut
.Write(LongInt(TP
.movingStartY
));
1333 NetOut
.Write(LongInt(TP
.movingEndX
));
1334 NetOut
.Write(LongInt(TP
.movingEndY
));
1335 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1336 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1337 NetOut
.Write(LongInt(TP
.sizeEndX
));
1338 NetOut
.Write(LongInt(TP
.sizeEndY
));
1339 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1340 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1341 NetOut
.Write(Byte(mpflags
));
1343 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1348 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1350 if gTriggers
= nil then Exit
;
1351 if T
.Sound
= nil then Exit
;
1353 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1354 NetOut
.Write(T
.ClientID
);
1355 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1356 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1357 NetOut
.Write(T
.SoundPlayCount
);
1359 g_Net_Host_Send(ID
, True);
1362 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1364 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1365 NetOut
.Write(gMusic
.Name
);
1366 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1367 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1368 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1370 g_Net_Host_Send(ID
, True);
1375 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1379 M
:= g_Monsters_ByUID(UID
);
1385 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1387 NetOut
.Write(MonsterType
);
1388 NetOut
.Write(MonsterState
);
1389 NetOut
.Write(MonsterAnim
);
1390 NetOut
.Write(MonsterTargetUID
);
1391 NetOut
.Write(MonsterTargetTime
);
1392 NetOut
.Write(MonsterBehaviour
);
1393 NetOut
.Write(MonsterSleep
);
1394 NetOut
.Write(MonsterHealth
);
1395 NetOut
.Write(MonsterAmmo
);
1396 NetOut
.Write(GameX
);
1397 NetOut
.Write(GameY
);
1398 NetOut
.Write(GameVelX
);
1399 NetOut
.Write(GameVelY
);
1400 NetOut
.Write(Byte(GameDirection
));
1403 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1406 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1410 M
:= g_Monsters_ByUID(UID
);
1411 if M
= nil then Exit
;
1413 NetOut
.Write(Byte(NET_MSG_MPOS
));
1418 NetOut
.Write(GameX
);
1419 NetOut
.Write(GameY
);
1420 NetOut
.Write(GameVelX
);
1421 NetOut
.Write(GameVelY
);
1422 NetOut
.Write(Byte(GameDirection
));
1425 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1428 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1432 M
:= g_Monsters_ByUID(UID
);
1433 if M
= nil then Exit
;
1435 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1440 NetOut
.Write(MonsterState
);
1441 NetOut
.Write(ForcedAnim
);
1442 NetOut
.Write(MonsterTargetUID
);
1443 NetOut
.Write(MonsterTargetTime
);
1444 NetOut
.Write(MonsterSleep
);
1445 NetOut
.Write(MonsterHealth
);
1446 NetOut
.Write(MonsterAmmo
);
1447 NetOut
.Write(MonsterPain
);
1448 NetOut
.Write(Byte(AnimIsReverse
));
1449 NetOut
.Write(FFireTime
);
1452 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1455 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1457 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1464 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1467 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1471 M
:= g_Monsters_ByUID(UID
);
1472 if M
= nil then Exit
;
1474 NetOut
.Write(Byte(NET_MSG_MDEL
));
1477 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1482 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1484 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1487 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1490 procedure MH_SEND_VoteEvent(EvType
: Byte;
1491 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1492 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1493 ID
: Integer = NET_EVERYONE
);
1495 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1496 NetOut
.Write(EvType
);
1497 NetOut
.Write(IntArg1
);
1498 NetOut
.Write(IntArg2
);
1499 NetOut
.Write(StrArg1
);
1500 NetOut
.Write(StrArg2
);
1502 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1505 // CLIENT MESSAGES //
1509 procedure MC_RECV_Chat(var M
: TMsg
);
1514 Txt
:= M
.ReadString();
1515 Mode
:= M
.ReadByte();
1517 if Mode
<> NET_CHAT_SYSTEM
then
1519 if NetDeafLevel
= 0 then
1521 if Mode
= NET_CHAT_PLAYER
then
1523 g_Console_Add(Txt
, True);
1524 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1525 g_Game_ChatSound(b_Text_Unformat(Txt
));
1527 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1529 if gPlayer1
.Team
= TEAM_RED
then
1530 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1531 if gPlayer1
.Team
= TEAM_BLUE
then
1532 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1533 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1534 g_Game_ChatSound(b_Text_Unformat(Txt
));
1537 end else if (NetDeafLevel
< 2) then
1538 g_Console_Add(Txt
, True);
1541 procedure MC_RECV_Effect(var M
: TMsg
);
1549 if not gGameOn
then Exit
;
1550 Kind
:= M
.ReadByte();
1551 X
:= M
.ReadLongInt();
1552 Y
:= M
.ReadLongInt();
1553 Ang
:= M
.ReadSmallInt();
1557 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1561 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1563 Anim
:= TAnimation
.Create(ID
, False, 3);
1564 g_GFX_OnceAnim(X
, Y
, Anim
);
1568 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1573 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1575 Anim
:= TAnimation
.Create(ID
, False, 6);
1576 Anim
.Blending
:= False;
1577 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1581 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1586 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1588 Anim
:= TAnimation
.Create(ID
, False, 6);
1589 Anim
.Blending
:= False;
1590 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1594 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1599 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1601 Anim
:= TAnimation
.Create(ID
, False, 4);
1602 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1609 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1611 Anim
:= TAnimation
.Create(ID
, False, 4);
1612 g_GFX_OnceAnim(X
, Y
, Anim
);
1616 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1621 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1623 Anim
:= TAnimation
.Create(ID
, False, 4);
1624 g_GFX_OnceAnim(X
, Y
, Anim
);
1628 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1632 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1635 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1639 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1640 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1645 procedure MC_RECV_Sound(var M
: TMsg
);
1651 Name
:= M
.ReadString();
1652 Pos
:= M
.ReadByte() <> 0;
1655 X
:= M
.ReadLongInt();
1656 Y
:= M
.ReadLongInt();
1657 g_Sound_PlayExAt(Name
, X
, Y
);
1660 g_Sound_PlayEx(Name
);
1663 procedure MC_RECV_CreateShot(var M
: TMsg
);
1665 I
, X
, Y
, XV
, YV
: Integer;
1667 Target
, Spawner
: Word;
1670 I
:= M
.ReadLongInt();
1671 ShType
:= M
.ReadByte();
1672 Target
:= M
.ReadWord();
1673 Spawner
:= M
.ReadWord();
1674 Timeout
:= M
.ReadLongWord();
1675 X
:= M
.ReadLongInt();
1676 Y
:= M
.ReadLongInt();
1677 XV
:= M
.ReadLongInt();
1678 YV
:= M
.ReadLongInt();
1680 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1681 if (Shots
<> nil) and (I
<= High(Shots
)) then
1683 Shots
[I
].Timeout
:= Timeout
;
1684 //Shots[I].Target := Target; // TODO: find a use for Target later
1688 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1690 I
, TX
, TY
, TXV
, TYV
: Integer;
1692 I
:= M
.ReadLongInt();
1693 TX
:= M
.ReadLongInt();
1694 TY
:= M
.ReadLongInt();
1695 TXV
:= M
.ReadLongInt();
1696 TYV
:= M
.ReadLongInt();
1698 if (Shots
<> nil) and (I
<= High(Shots
)) then
1708 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1713 if not gGameOn
then Exit
;
1714 I
:= M
.ReadLongInt();
1715 L
:= (M
.ReadByte() <> 0);
1716 X
:= M
.ReadLongInt();
1717 Y
:= M
.ReadLongInt();
1719 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1722 procedure MC_RECV_GameStats(var M
: TMsg
);
1724 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1726 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1727 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1730 if gGameSettings
.GameMode
= GM_COOP
then
1732 gCoopMonstersKilled
:= M
.ReadWord();
1733 gCoopSecretsFound
:= M
.ReadWord();
1737 procedure MC_RECV_CoopStats(var M
: TMsg
);
1739 gTotalMonsters
:= M
.ReadLongInt();
1740 gSecretsCount
:= M
.ReadLongInt();
1741 gCoopTotalMonstersKilled
:= M
.ReadWord();
1742 gCoopTotalSecretsFound
:= M
.ReadWord();
1743 gCoopTotalMonsters
:= M
.ReadWord();
1744 gCoopTotalSecrets
:= M
.ReadWord();
1747 procedure MC_RECV_GameEvent(var M
: TMsg
);
1756 i1
, i2
: TStrings_Locale
;
1759 goodCmd
: Boolean = true;
1761 FillChar(EvHash
, Sizeof(EvHash
), 0);
1762 EvType
:= M
.ReadByte();
1763 EvNum
:= M
.ReadLongInt();
1764 EvStr
:= M
.ReadString();
1765 gLastMap
:= M
.ReadByte() <> 0;
1766 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1767 gStatsPressed
:= True;
1768 EvTime
:= M
.ReadLongWord();
1769 BHash
:= M
.ReadByte() <> 0;
1771 EvHash
:= M
.ReadMD5();
1775 if (g_Res_received_map_start
<> 0) then
1777 if (g_Res_received_map_start
< 0) then exit
;
1780 NET_EV_MAPSTART
: goodCmd
:= true;
1781 NET_EV_MAPEND
: goodCmd
:= true;
1782 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1783 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1784 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1786 if not goodCmd
then exit
;
1792 if (g_Res_received_map_start
<> 0) then
1794 g_Res_received_map_start
:= -1;
1799 g_Game_ClearLoading();
1800 g_Game_StopAllSounds(True);
1802 gSwitchGameMode
:= Byte(EvNum
);
1803 gGameSettings
.GameMode
:= gSwitchGameMode
;
1806 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1808 if not isWadPath(EvStr
) then
1809 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1811 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1815 MC_SEND_FullStateRequest
;
1821 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1822 gLMSRespawnTime
:= 0;
1823 if (g_Res_received_map_start
<> 0) then
1825 g_Res_received_map_start
:= -1;
1829 gMissionFailed
:= EvNum
<> 0;
1830 gExit
:= EXIT_ENDLEVELCUSTOM
;
1838 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1840 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1842 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1848 if NetDeafLevel
< 2 then
1850 if EvNum
= TEAM_RED
then
1851 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1852 if EvNum
= TEAM_BLUE
then
1853 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1859 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1860 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1865 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1866 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1873 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
1874 gLMSRespawnTime
:= gTime
+ EvNum
;
1875 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
1877 else if gPlayer1
= nil then
1879 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1883 NET_EV_LMS_SURVIVOR
:
1884 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1887 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1891 pl
:= g_Player_Get(EvNum
and $FFFF);
1896 cnt
:= (EvNum
shr 16) and $FF;
1897 if Pos('w', EvStr
) = 0 then
1900 if Pos('t', EvStr
) = 0 then
1903 if Pos('-', EvStr
) = 0 then
1905 if Pos('e', EvStr
) = 0 then
1906 i1
:= I_PLAYER_SCORE_ADD_OWN
1908 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1911 if Pos('e', EvStr
) = 0 then
1912 i1
:= I_PLAYER_SCORE_SUB_OWN
1914 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1917 if Pos('r', EvStr
) > 0 then
1918 i2
:= I_PLAYER_SCORE_TO_RED
1920 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1921 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1925 if Pos('-', EvStr
) = 0 then
1926 i1
:= I_PLAYER_SCORE_ADD_TEAM
1928 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1930 if Pos('r', EvStr
) > 0 then
1931 i2
:= I_PLAYER_SCORE_RED
1933 i2
:= I_PLAYER_SCORE_BLUE
;
1934 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1939 if Pos('e', EvStr
) = 0 then
1940 i1
:= I_PLAYER_SCORE_WIN_OWN
1942 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1944 if Pos('r', EvStr
) > 0 then
1945 i2
:= I_PLAYER_SCORE_TO_RED
1947 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1948 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1954 if EvNum
= TEAM_RED
then
1955 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1956 if EvNum
= TEAM_BLUE
then
1957 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1958 if EvNum
= -TEAM_RED
then
1959 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1960 if EvNum
= -TEAM_BLUE
then
1961 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1966 g_Player_RemoveAllCorpses
;
1967 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1968 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1972 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1976 if EvNum
= TEAM_RED
then
1977 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1978 if EvNum
= TEAM_BLUE
then
1979 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1983 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1986 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1989 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1992 g_Game_Announce_KillCombo(EvNum
);
1994 NET_EV_PLAYER_TOUCH
:
1996 pl
:= g_Player_Get(EvNum
);
2003 pl
:= g_Player_Get(EvNum
);
2006 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2007 g_Sound_PlayEx('SOUND_GAME_SECRET');
2013 pl
:= g_Player_Get(EvNum
);
2014 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2019 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2028 EvType
:= M
.ReadByte();
2031 if Fl
= FLAG_NONE
then Exit
;
2033 Quiet
:= (M
.ReadByte() <> 0);
2034 PID
:= M
.ReadWord();
2036 gFlags
[Fl
].State
:= M
.ReadByte();
2037 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2038 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2039 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2040 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2041 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2043 Pl
:= g_Player_Get(PID
);
2045 (EvType
<> FLAG_STATE_NORMAL
) and
2046 (EvType
<> FLAG_STATE_DROPPED
) and
2047 (EvType
<> FLAG_STATE_RETURNED
) then
2053 if Quiet
or (Pl
= nil) then Exit
;
2055 if Fl
= FLAG_RED
then
2056 s
:= _lc
[I_PLAYER_FLAG_RED
]
2058 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2060 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2062 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2063 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2064 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2069 if not sound_ret_flag
[a
].IsPlaying() then
2070 sound_ret_flag
[a
].Play();
2073 FLAG_STATE_CAPTURED
:
2075 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2079 if Fl
= FLAG_RED
then
2080 s
:= _lc
[I_PLAYER_FLAG_RED
]
2082 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2084 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2085 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2087 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2088 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2089 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2094 if not sound_get_flag
[a
].IsPlaying() then
2095 sound_get_flag
[a
].Play();
2100 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2102 if Quiet
or (Pl
= nil) then Exit
;
2104 if Fl
= FLAG_RED
then
2105 s
:= _lc
[I_PLAYER_FLAG_RED
]
2107 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2109 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2110 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2112 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2113 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2114 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2119 if not sound_lost_flag
[a
].IsPlaying() then
2120 sound_lost_flag
[a
].Play();
2125 g_Map_ResetFlag(FLAG_RED
);
2126 g_Map_ResetFlag(FLAG_BLUE
);
2127 if Quiet
or (Pl
= nil) then Exit
;
2128 Pl
.SetFlag(FLAG_NONE
);
2130 if Fl
= FLAG_RED
then
2131 s
:= _lc
[I_PLAYER_FLAG_RED
]
2133 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2135 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2136 Insert('.', ts
, Length(ts
) + 1 - 3);
2137 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2138 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2140 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2141 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2142 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2147 if not sound_cap_flag
[a
].IsPlaying() then
2148 sound_cap_flag
[a
].Play();
2151 FLAG_STATE_RETURNED
:
2153 g_Map_ResetFlag(Fl
);
2156 if Fl
= FLAG_RED
then
2157 s
:= _lc
[I_PLAYER_FLAG_RED
]
2159 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2161 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2163 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2164 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2165 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2170 if not sound_ret_flag
[a
].IsPlaying() then
2171 sound_ret_flag
[a
].Play();
2176 procedure MC_RECV_GameSettings(var M
: TMsg
);
2178 gGameSettings
.GameMode
:= M
.ReadByte();
2179 gGameSettings
.GoalLimit
:= M
.ReadWord();
2180 gGameSettings
.TimeLimit
:= M
.ReadWord();
2181 gGameSettings
.MaxLives
:= M
.ReadByte();
2182 gGameSettings
.Options
:= M
.ReadLongWord();
2187 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2190 PName
, Model
: string;
2195 PID
:= M
.ReadWord();
2196 Pl
:= g_Player_Get(PID
);
2198 PName
:= M
.ReadString();
2199 Model
:= M
.ReadString();
2200 Color
.R
:= M
.ReadByte();
2201 Color
.G
:= M
.ReadByte();
2202 Color
.B
:= M
.ReadByte();
2206 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2208 if (Pl
<> nil) then Exit
;
2209 DID
:= g_Player_Create(Model
, Color
, T
, False);
2210 with g_Player_Get(DID
) do
2219 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2220 gPlayer1
.UID
:= PID
;
2221 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2222 gPlayer1
.ChangeTeam(T
);
2224 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2225 gPlayer2
.UID
:= PID
;
2226 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2227 gPlayer2
.ChangeTeam(T
);
2231 if NetDeafLevel
< 3 then
2232 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2233 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2237 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2244 TmpX
, TmpY
: Integer;
2248 GT
:= M
.ReadLongWord();
2249 if GT
< gTime
- NET_MAX_DIFFTIME
then
2256 PID
:= M
.ReadWord();
2257 Pl
:= g_Player_Get(PID
);
2259 if Pl
= nil then Exit
;
2265 FPing
:= M
.ReadWord();
2266 FLoss
:= M
.ReadByte();
2267 kByte
:= M
.ReadWord();
2268 Dir
:= M
.ReadByte();
2270 TmpX
:= M
.ReadLongInt();
2271 TmpY
:= M
.ReadLongInt();
2275 if LongBool(kByte
and NET_KEY_CHAT
) then
2276 PressKey(KEY_CHAT
, 10000)
2279 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2280 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2281 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2282 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2283 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2286 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2288 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2289 SetDirection(TDirection(Dir
));
2291 GameVelX
:= M
.ReadLongInt();
2292 GameVelY
:= M
.ReadLongInt();
2293 GameAccelX
:= M
.ReadLongInt();
2294 GameAccelY
:= M
.ReadLongInt();
2295 SetLerp(TmpX
, TmpY
);
2296 if NetForcePlayerUpdate
then Update();
2300 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2304 I
, OldFire
: Integer;
2305 OldJet
, Flam
: Boolean;
2308 PID
:= M
.ReadWord();
2309 Pl
:= g_Player_Get(PID
);
2316 alive
:= (M
.ReadByte() <> 0);
2317 GodMode
:= (M
.ReadByte() <> 0);
2318 Health
:= M
.ReadLongInt();
2319 Armor
:= M
.ReadLongInt();
2320 Air
:= M
.ReadLongInt();
2321 JetFuel
:= M
.ReadLongInt();
2322 Lives
:= M
.ReadByte();
2323 NewTeam
:= M
.ReadByte();
2325 for I
:= WP_FIRST
to WP_LAST
do
2326 FWeapon
[I
] := (M
.ReadByte() <> 0);
2328 for I
:= A_BULLETS
to A_HIGH
do
2329 FAmmo
[I
] := M
.ReadWord();
2331 for I
:= A_BULLETS
to A_HIGH
do
2332 FMaxAmmo
[I
] := M
.ReadWord();
2334 for I
:= MR_SUIT
to MR_MAX
do
2335 FMegaRulez
[I
] := M
.ReadLongWord();
2338 if (M
.ReadByte() <> 0) then
2339 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2340 if (M
.ReadByte() <> 0) then
2341 FRulez
:= FRulez
+ [R_KEY_RED
];
2342 if (M
.ReadByte() <> 0) then
2343 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2344 if (M
.ReadByte() <> 0) then
2345 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2346 if (M
.ReadByte() <> 0) then
2347 FRulez
:= FRulez
+ [R_BERSERK
];
2349 Frags
:= M
.ReadLongInt();
2350 Death
:= M
.ReadLongInt();
2352 SetWeapon(M
.ReadByte());
2354 FSpectator
:= M
.ReadByte() <> 0;
2357 if UID
= NetPlrUID1
then
2359 gSpectLatchPID1
:= UID
;
2362 if UID
= NetPlrUID2
then
2364 gSpectLatchPID2
:= UID
;
2370 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2373 gSpectLatchPID1
:= 0;
2375 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2378 gSpectLatchPID2
:= 0;
2381 FGhost
:= M
.ReadByte() <> 0;
2382 FPhysics
:= M
.ReadByte() <> 0;
2383 FNoRespawn
:= M
.ReadByte() <> 0;
2385 FJetpack
:= M
.ReadByte() <> 0;
2386 OldFire
:= FFireTime
;
2387 FFireTime
:= M
.ReadLongInt();
2388 if (OldFire
<= 0) and (FFireTime
> 0) then
2389 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2390 Flam
:= M
.ReadByte() <> 0;
2391 FSpawnInvul
:= M
.ReadLongInt();
2392 if OldJet
and not FJetpack
then
2394 else if not OldJet
and FJetpack
then
2396 if FFlaming
and not Flam
then
2398 if Team
<> NewTeam
then
2399 Pl
.ChangeTeam(NewTeam
);
2405 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2410 Attacker
, Value
: Word;
2414 if not gGameOn
then Exit
;
2415 PID
:= M
.ReadWord();
2416 Pl
:= g_Player_Get(PID
);
2417 if Pl
= nil then Exit
;
2419 Kind
:= M
.ReadByte();
2420 Attacker
:= M
.ReadWord();
2421 Value
:= M
.ReadWord();
2426 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2431 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2435 KillType
, DeathType
: Byte;
2439 if not gGameOn
then Exit
;
2440 PID
:= M
.ReadWord();
2441 Pl
:= g_Player_Get(PID
);
2442 if Pl
= nil then Exit
;
2444 KillType
:= M
.ReadByte();
2445 DeathType
:= M
.ReadByte();
2446 Attacker
:= M
.ReadWord();
2450 Kill(KillType
, Attacker
, DeathType
);
2455 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2460 PID
:= M
.ReadWord();
2461 Pl
:= g_Player_Get(PID
);
2463 if Pl
= nil then Exit
;
2465 if NetDeafLevel
< 3 then
2466 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2467 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2469 g_Player_Remove(PID
);
2474 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2479 X
, Y
, AX
, AY
: Integer;
2483 if not gGameOn
then Exit
;
2484 PID
:= M
.ReadWord();
2485 Pl
:= g_Player_Get(PID
);
2486 if Pl
= nil then Exit
;
2488 Weap
:= M
.ReadByte();
2489 X
:= M
.ReadLongInt();
2490 Y
:= M
.ReadLongInt();
2491 AX
:= M
.ReadLongInt();
2492 AY
:= M
.ReadLongInt();
2493 SHID
:= M
.ReadLongInt();
2496 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2499 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2508 PID
:= M
.ReadWord();
2509 Pl
:= g_Player_Get(PID
);
2510 if Pl
= nil then Exit
;
2512 TmpName
:= M
.ReadString();
2513 TmpModel
:= M
.ReadString();
2514 TmpColor
.R
:= M
.ReadByte();
2515 TmpColor
.G
:= M
.ReadByte();
2516 TmpColor
.B
:= M
.ReadByte();
2517 TmpTeam
:= M
.ReadByte();
2519 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2521 Pl
.ChangeTeam(TmpTeam
);
2522 if gPlayer1
= Pl
then
2523 gPlayer1Settings
.Team
:= TmpTeam
;
2524 if gPlayer2
= Pl
then
2525 gPlayer2Settings
.Team
:= TmpTeam
;
2527 Pl
.SetColor(TmpColor
);
2529 if Pl
.Name
<> TmpName
then
2531 if NetDeafLevel
< 3 then
2532 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2536 if TmpModel
<> Pl
.Model
.Name
then
2537 Pl
.SetModel(TmpModel
);
2542 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2546 X
, Y
, VX
, VY
: Integer;
2548 Quiet
, Fall
{, Resp}: Boolean;
2552 if not gGameOn
then Exit
;
2554 Quiet
:= M
.ReadByte() <> 0;
2556 Fall
:= M
.ReadByte() <> 0;
2557 {Resp :=} M
.ReadByte();
2558 X
:= M
.ReadLongInt();
2559 Y
:= M
.ReadLongInt();
2560 VX
:= M
.ReadLongInt();
2561 VY
:= M
.ReadLongInt();
2563 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2564 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2566 it
:= g_Items_ByIdx(ID
);
2572 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2573 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2575 Anim
:= TAnimation
.Create(AID
, False, 4);
2576 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2582 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2587 if not gGameOn
then Exit
;
2589 Quiet
:= M
.ReadByte() <> 0;
2591 if not g_Items_ValidId(ID
) then exit
;
2593 if not Quiet
then g_Items_EmitPickupSound(ID
);
2600 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2607 if not gGameOn
then Exit
;
2609 PGUID
:= Integer(M
.ReadLongWord());
2610 Tex
:= M
.ReadLongInt();
2611 Fr
:= M
.ReadLongInt();
2612 Cnt
:= M
.ReadByte();
2613 Loop
:= M
.ReadByte();
2615 TP
:= g_Map_PanelByGUID(PGUID
);
2619 TP
.SetTexture(Tex
, Loop
);
2620 TP
.SetFrame(Fr
, Cnt
);
2624 procedure MC_RECV_PanelState(var M
: TMsg
);
2629 X
, Y
, W
, H
: Integer;
2631 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2632 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2635 if not gGameOn
then Exit
;
2637 PGUID
:= Integer(M
.ReadLongWord());
2638 E
:= (M
.ReadByte() <> 0);
2639 Lift
:= M
.ReadByte();
2640 X
:= M
.ReadLongInt();
2641 Y
:= M
.ReadLongInt();
2645 speedX
:= M
.ReadLongInt();
2646 speedY
:= M
.ReadLongInt();
2647 startX
:= M
.ReadLongInt();
2648 startY
:= M
.ReadLongInt();
2649 endX
:= M
.ReadLongInt();
2650 endY
:= M
.ReadLongInt();
2651 sizeSpX
:= M
.ReadLongInt();
2652 sizeSpY
:= M
.ReadLongInt();
2653 sizeEX
:= M
.ReadLongInt();
2654 sizeEY
:= M
.ReadLongInt();
2655 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2657 TP
:= g_Map_PanelByGUID(PGUID
);
2658 if (TP
= nil) then exit
;
2660 // update lifts state
2661 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2663 // update enabled/disabled state for all panels
2664 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2666 // update panel position, as it can be moved (mplat)
2671 // update mplat state
2672 TP
.movingSpeedX
:= speedX
;
2673 TP
.movingSpeedY
:= speedY
;
2674 TP
.movingStartX
:= startX
;
2675 TP
.movingStartY
:= startY
;
2676 TP
.movingEndX
:= endX
;
2677 TP
.movingEndY
:= endY
;
2678 TP
.sizeSpeedX
:= sizeSpX
;
2679 TP
.sizeSpeedY
:= sizeSpY
;
2680 TP
.sizeEndX
:= sizeEX
;
2681 TP
.sizeEndY
:= sizeEY
;
2682 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2683 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2684 // notify panel of it's position/size change, so it can fix other internal structures
2685 TP
.positionChanged();
2690 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2693 SPos
, SID
: LongWord;
2697 if not gGameOn
then Exit
;
2698 if gTriggers
= nil then Exit
;
2700 SID
:= M
.ReadLongWord();
2701 SPlaying
:= M
.ReadByte() <> 0;
2702 SPos
:= M
.ReadLongWord();
2703 SCount
:= M
.ReadLongInt();
2705 for I
:= Low(gTriggers
) to High(gTriggers
) do
2706 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2707 if gTriggers
[I
].ClientID
= SID
then
2708 with gTriggers
[I
] do
2710 if Sound
<> nil then
2715 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2717 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2718 Sound
.SetPosition(SPos
);
2721 if Sound
.IsPlaying
then Sound
.Stop
;
2724 SoundPlayCount
:= SCount
;
2728 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2735 if not gGameOn
then Exit
;
2737 MName
:= M
.ReadString();
2738 MPlaying
:= M
.ReadByte() <> 0;
2739 MPos
:= M
.ReadLongWord();
2740 MPaused
:= M
.ReadByte() <> 0;
2741 MPos
:= MPos
+1; //k8: stfu, fpc!
2745 gMusic
.SetByName(MName
);
2747 // gMusic.SetPosition(MPos);
2748 gMusic
.SpecPause
:= MPaused
;
2751 if gMusic
.IsPlaying
then gMusic
.Stop
;
2756 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2759 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2760 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2765 Mon
:= g_Monsters_ByUID(ID
);
2769 MType
:= M
.ReadByte();
2770 MState
:= M
.ReadByte();
2771 MAnim
:= M
.ReadByte();
2772 MTarg
:= M
.ReadWord();
2773 MTargTime
:= M
.ReadLongInt();
2774 MBehav
:= M
.ReadByte();
2775 MSleep
:= M
.ReadLongInt();
2776 MHealth
:= M
.ReadLongInt();
2777 MAmmo
:= M
.ReadLongInt();
2779 X
:= M
.ReadLongInt();
2780 Y
:= M
.ReadLongInt();
2781 VX
:= M
.ReadLongInt();
2782 VY
:= M
.ReadLongInt();
2783 MDir
:= M
.ReadByte();
2785 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2786 Mon
:= g_Monsters_ByUID(ID
);
2793 MonsterAnim
:= MAnim
;
2794 MonsterTargetUID
:= MTarg
;
2795 MonsterTargetTime
:= MTargTime
;
2796 MonsterBehaviour
:= MBehav
;
2797 MonsterSleep
:= MSleep
;
2798 MonsterAmmo
:= MAmmo
;
2803 setPosition(X
, Y
); // this will call positionChanged();
2809 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2816 Mon
:= g_Monsters_ByUID(ID
);
2822 X
:= M
.ReadLongInt();
2823 Y
:= M
.ReadLongInt();
2824 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2825 GameVelX
:= M
.ReadLongInt();
2826 GameVelY
:= M
.ReadLongInt();
2827 GameDirection
:= TDirection(M
.ReadByte());
2831 procedure MC_RECV_MonsterState(var M
: TMsg
);
2833 ID
, OldFire
: Integer;
2834 MState
, MFAnm
: Byte;
2836 AnimRevert
: Boolean;
2839 Mon
:= g_Monsters_ByUID(ID
);
2840 if Mon
= nil then Exit
;
2842 MState
:= M
.ReadByte();
2843 MFAnm
:= M
.ReadByte();
2847 MonsterTargetUID
:= M
.ReadWord();
2848 MonsterTargetTime
:= M
.ReadLongInt();
2849 MonsterSleep
:= M
.ReadLongInt();
2850 MonsterHealth
:= M
.ReadLongInt();
2851 MonsterAmmo
:= M
.ReadLongInt();
2852 MonsterPain
:= M
.ReadLongInt();
2853 AnimRevert
:= M
.ReadByte() <> 0;
2854 OldFire
:= FFireTime
;
2855 FFireTime
:= M
.ReadLongInt();
2856 if (OldFire
<= 0) and (FFireTime
> 0) then
2857 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2858 RevertAnim(AnimRevert
);
2860 if MonsterState
<> MState
then
2862 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2863 if (MState
= MONSTATE_DIE
) then DieSound();
2864 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2865 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2866 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2868 SetState(MState
, MFAnm
);
2873 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2877 X
, Y
, VX
, VY
: Integer;
2881 Mon
:= g_Monsters_ByUID(ID
);
2882 if Mon
= nil then Exit
;
2884 X
:= M
.ReadLongInt();
2885 Y
:= M
.ReadLongInt();
2886 VX
:= M
.ReadLongInt();
2887 VY
:= M
.ReadLongInt();
2889 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2892 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2898 Mon
:= g_Monsters_ByUID(ID
);
2899 if Mon
= nil then Exit
;
2901 Mon
.MonsterRemoved
:= True;
2904 procedure MC_RECV_TimeSync(var M
: TMsg
);
2908 Time
:= M
.ReadLongWord();
2910 if gState
= STATE_INTERCUSTOM
then
2911 gServInterTime
:= Min(Time
, 255);
2914 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2918 Int1
, Int2
: SmallInt;
2920 EvID
:= M
.ReadByte();
2921 Int1
:= M
.ReadSmallInt();
2922 Int2
:= M
.ReadSmallInt();
2923 Str1
:= M
.ReadString();
2924 Str2
:= M
.ReadString();
2926 if NetDeafLevel
< 2 then
2929 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2931 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2933 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2935 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2937 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2943 procedure MC_SEND_Info(Password
: string);
2947 NetOut
.Write(Byte(NET_MSG_INFO
));
2948 NetOut
.Write(GAME_VERSION
);
2949 NetOut
.Write(Password
);
2950 NetOut
.Write(gPlayer1Settings
.Name
);
2951 NetOut
.Write(gPlayer1Settings
.Model
);
2952 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2953 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2954 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2955 NetOut
.Write(gPlayer1Settings
.Team
);
2957 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2960 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2962 NetOut
.Write(Byte(NET_MSG_CHAT
));
2966 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2969 procedure MC_SEND_PlayerPos();
2974 WeaponSelect
: Word = 0;
2977 if not gGameOn
then Exit
;
2978 if gPlayers
= nil then Exit
;
2979 if gPlayer1
= nil then Exit
;
2982 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2984 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2986 strafeDir
:= P1MoveButton
shr 4;
2987 P1MoveButton
:= P1MoveButton
and $0F;
2989 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2991 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2993 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2997 if gPlayerAction
[0, ACTION_STRAFE
] then
2999 // new strafe mechanics
3000 if (strafeDir
= 0) then
3001 strafeDir
:= P1MoveButton
; // start strafing
3002 // now set direction according to strafe (reversed)
3003 if (strafeDir
= 2) then
3004 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3005 else if (strafeDir
= 1) then
3006 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3010 strafeDir
:= 0; // not strafing anymore
3011 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3012 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3013 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3014 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3015 else if P1MoveButton
<> 0 then
3016 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3019 gPlayer1
.ReleaseKeys
;
3020 if P1MoveButton
= 1 then
3022 kByte
:= kByte
or NET_KEY_LEFT
;
3023 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3025 if P1MoveButton
= 2 then
3027 kByte
:= kByte
or NET_KEY_RIGHT
;
3028 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3030 if gPlayerAction
[0, ACTION_LOOKUP
] then
3032 kByte
:= kByte
or NET_KEY_UP
;
3033 gPlayer1
.PressKey(KEY_UP
, 10000);
3035 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3037 kByte
:= kByte
or NET_KEY_DOWN
;
3038 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3040 if gPlayerAction
[0, ACTION_JUMP
] then
3042 kByte
:= kByte
or NET_KEY_JUMP
;
3043 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3045 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3046 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3047 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
3048 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
3050 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3051 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3053 for i
:= WP_FIRST
to WP_LAST
do
3055 if gSelectWeapon
[0, i
] then
3057 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3058 gSelectWeapon
[0, i
] := False
3062 // fix movebutton state
3063 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3066 kByte
:= NET_KEY_CHAT
;
3068 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3069 NetOut
.Write(gTime
);
3070 NetOut
.Write(kByte
);
3071 NetOut
.Write(Byte(gPlayer1
.Direction
));
3072 NetOut
.Write(WeaponSelect
);
3073 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3074 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3076 //kBytePrev := kByte;
3077 //kDirPrev := gPlayer1.Direction;
3080 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3082 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3083 NetOut
.Write(Byte(Start
));
3084 NetOut
.Write(Command
);
3085 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3088 procedure MC_SEND_PlayerSettings();
3090 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3091 NetOut
.Write(gPlayer1Settings
.Name
);
3092 NetOut
.Write(gPlayer1Settings
.Model
);
3093 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3094 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3095 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3096 NetOut
.Write(gPlayer1Settings
.Team
);
3098 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3101 procedure MC_SEND_FullStateRequest();
3103 NetOut
.Write(Byte(NET_MSG_REQFST
));
3105 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3108 procedure MC_SEND_CheatRequest(Kind
: Byte);
3110 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3113 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3115 procedure MC_SEND_RCONPassword(Password
: string);
3117 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3118 NetOut
.Write(Password
);
3120 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3122 procedure MC_SEND_RCONCommand(Cmd
: string);
3124 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3127 g_Net_Client_Send(True, NET_CHAN_SERVICE
);