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;
282 Math
, ENet
, e_input
, e_log
, g_base
, g_basic
,
283 g_textures
, g_gfx
, g_sound
, g_console
, g_options
,
284 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
,
285 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
298 NET_KEY_FORCEDIR
= 4096;
301 //kBytePrev: Word = 0;
302 //kDirPrev: TDirection = D_LEFT;
303 //HostGameTime: Word = 0;
306 function IsValidFileName(const S
: String): Boolean;
308 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
313 for I
:= 1 to Length(S
) do
314 Result
:= Result
and (not(S
[I
] in Forbidden
));
317 function IsValidFilePath(const S
: String): Boolean;
322 if not IsValidFileName(S
) then exit
;
323 if FileExists(S
) then exit
;
324 I
:= LastDelimiter('\/', S
);
326 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
337 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
345 Pl
:= g_Player_Get(PID
);
347 Txt
:= M
.ReadString();
348 Mode
:= M
.ReadByte();
349 if (Mode
= NET_CHAT_SYSTEM
) then
350 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
351 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
352 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
355 MH_SEND_Chat(Txt
, Mode
)
357 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
360 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
362 Ver
, PName
, Model
, Pw
: string;
368 Ver
:= M
.ReadString();
369 Pw
:= M
.ReadString();
370 PName
:= M
.ReadString();
371 Model
:= M
.ReadString();
377 if Ver
<> GAME_VERSION
then
379 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
380 _lc
[I_NET_DISC_VERSION
]);
381 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
385 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
387 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
389 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
390 _lc
[I_NET_DISC_BAN
]);
391 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
395 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
396 _lc
[I_NET_DISC_BAN
]);
397 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
402 if NetPassword
<> '' then
403 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
405 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
406 _lc
[I_NET_DISC_PASSWORD
]);
407 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
415 PID
:= g_Player_Create(Model
, Color
, T
, False);
416 with g_Player_Get(PID
) do
423 C
^.WaitForFirstSpawn
:= false;
425 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
426 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
427 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
431 with g_Player_Get(PID
) do
435 // round in progress, don't spawn
436 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
437 //e_LogWritefln('spawning player with pid #%u...', [PID]);
438 //Respawn(gGameSettings.GameType = GT_SINGLE);
439 //k8: no, do not spawn a player yet, wait for "request full state" packet
443 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
444 // that is, if we'll set it to `true`, the player can be spawned after
445 // warmup time ran out, for example, regardless of the real player state.
446 // also, this seems to work only for the initial connection. further
447 // map changes could initiate resource downloading, but the player will
448 // be spawned immediately.
449 // the proper solution will require another player state, "ephemeral".
450 // the player should start any map in "ephemeral" state, and turned into
451 // real mobj only when they sent a special "i am ready" packet. this packet
452 // must be sent after receiving the full state, so the player will get a full
453 // map view before going into game.
454 FWantsInGame
:= false;
455 C
^.WaitForFirstSpawn
:= true;
458 //if not C^.WaitForFirstSpawn then
460 for I
:= Low(NetClients
) to High(NetClients
) do
462 if NetClients
[I
].ID
= C
^.ID
then Continue
;
463 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
464 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
465 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
469 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
470 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
474 //g_Net_Slist_Update;
480 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
484 if not C
.WaitForFirstSpawn
then exit
;
485 plr
:= g_Player_Get(C
^.Player
);
486 if not assigned(plr
) then exit
;
487 g_Net_Slist_ServerPlayerComes();
488 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
489 C
.WaitForFirstSpawn
:= false;
490 plr
.FNoRespawn
:= false;
491 plr
.FWantsInGame
:= true; // TODO: look into this later
493 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
496 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
501 if gLMSRespawn
> LMS_RESPAWN_NONE
then
502 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
507 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
509 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
512 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
516 C
^.RequestedFullUpdate
:= True;
522 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
532 if not gGameOn
then Exit
;
534 GT
:= M
.ReadLongWord();
536 Pl
:= g_Player_Get(PID
);
540 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
545 kByte
:= M
.ReadWord();
547 WeaponSelect
:= M
.ReadWord();
548 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
549 if Direction
<> TDirection(Dir
) then
550 JustTeleported
:= False;
552 SetDirection(TDirection(Dir
));
555 if kByte
= NET_KEY_CHAT
then
557 PressKey(KEY_CHAT
, 10000);
561 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
562 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
563 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
564 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
565 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
566 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
567 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
568 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
569 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
573 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
575 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
576 QueueWeaponSwitch(i
);
581 // MH_SEND_PlayerPos(False, PID, C^.ID);
584 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
589 Pl
:= g_Player_Get(C
^.Player
);
590 if Pl
= nil then Exit
;
592 CheatKind
:= M
.ReadByte();
596 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
599 if Pl
.FSpectator
then
601 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
604 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
611 if gState
<> STATE_INTERCUSTOM
then Exit
;
612 Pl
.FReady
:= not Pl
.FReady
;
615 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
616 Inc(gInterReadyCount
);
620 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
621 Dec(gInterReadyCount
);
627 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
635 TmpName
:= M
.ReadString();
636 TmpModel
:= M
.ReadString();
637 TmpColor
.R
:= M
.ReadByte();
638 TmpColor
.G
:= M
.ReadByte();
639 TmpColor
.B
:= M
.ReadByte();
640 TmpTeam
:= M
.ReadByte();
642 Pl
:= g_Player_Get(C
^.Player
);
643 if Pl
= nil then Exit
;
645 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
648 Pl
.SetColor(TmpColor
);
650 if Pl
.Name
<> TmpName
then
652 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
656 if TmpModel
<> Pl
.Model
.GetName() then
657 Pl
.SetModel(TmpModel
);
659 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
664 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
668 Pwd
:= M
.ReadString();
669 if not NetAllowRCON
then Exit
;
670 if Pwd
= NetRCONPassword
then
673 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
676 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
679 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
683 Cmd
:= M
.ReadString();
684 if not NetAllowRCON
then Exit
;
685 if not C
^.RCONAuth
then
687 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
690 g_Console_Process(Cmd
);
695 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
698 Name
, Command
: string;
702 Start
:= M
.ReadByte() <> 0;
703 Command
:= M
.ReadString();
705 Pl
:= g_Player_Get(C
^.Player
);
706 if Pl
= nil then Exit
;
711 if not g_Console_CommandBlacklisted(Command
) then
712 g_Game_StartVote(Command
, Name
);
714 else if gVoteInProgress
then
716 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
717 Need
:= Floor((NetClientCount
+1)/2.0) + 1
719 Need
:= Floor(NetClientCount
/2.0) + 1;
724 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
725 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
731 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
732 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
740 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
742 function sendItemRespawn (it
: PItem
): Boolean;
744 result
:= false; // don't stop
745 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
748 function sendMonSpawn (mon
: TMonster
): Boolean;
750 result
:= false; // don't stop
751 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
754 function sendPanelState (pan
: TPanel
): Boolean;
756 result
:= false; // don't stop
757 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
758 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
764 if (ID
>= 0) and (ID
< length(NetClients
)) then
766 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
767 MH_ProcessFirstSpawn(@NetClients
[ID
]);
770 if gPlayers
<> nil then
772 for I
:= Low(gPlayers
) to High(gPlayers
) do
774 if gPlayers
[I
] <> nil then
776 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
777 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
778 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
780 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
782 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
788 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
789 g_Mons_ForEach(sendMonSpawn
);
790 g_Map_ForEachPanel(sendPanelState
);
792 if gTriggers
<> nil then
794 for I
:= Low(gTriggers
) to High(gTriggers
) do
796 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
798 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
805 for I
:= Low(Shots
) to High(Shots
) do
807 if Shots
[i
].ShotType
in [6, 7, 8] then
809 MH_SEND_CreateShot(i
, ID
);
814 MH_SEND_TriggerMusic(ID
);
816 MH_SEND_GameStats(ID
);
817 MH_SEND_CoopStats(ID
);
819 if gGameSettings
.GameMode
= GM_CTF
then
821 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
822 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
825 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
830 procedure MH_SEND_Info(ID
: Byte);
834 NetOut
.Write(Byte(NET_MSG_INFO
));
836 NetOut
.Write(NetClients
[ID
].Player
);
837 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
838 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
839 NetOut
.Write(gWADHash
);
840 NetOut
.Write(gGameSettings
.GameMode
);
841 NetOut
.Write(gGameSettings
.GoalLimit
);
842 NetOut
.Write(gGameSettings
.TimeLimit
);
843 NetOut
.Write(gGameSettings
.MaxLives
);
844 NetOut
.Write(gGameSettings
.Options
);
847 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
850 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
856 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
857 Mode
:= NET_CHAT_PLAYER
;
860 if (Mode
= NET_CHAT_TEAM
) then
862 for i
:= Low(gPlayers
) to High(gPlayers
) do
863 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
864 (gPlayers
[i
].Team
= ID
) then
866 NetOut
.Write(Byte(NET_MSG_CHAT
));
869 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
876 NetOut
.Write(Byte(NET_MSG_CHAT
));
879 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
882 if Mode
= NET_CHAT_SYSTEM
then
885 if ID
= NET_EVERYONE
then
887 if Mode
= NET_CHAT_PLAYER
then
889 g_Console_Add(Txt
, True);
890 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
891 g_Game_ChatSound(b_Text_Unformat(Txt
));
894 if Mode
= NET_CHAT_TEAM
then
895 if gPlayer1
<> nil then
897 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
899 g_Console_Add(#18'[Team] '#2 + Txt
, True);
900 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
901 g_Game_ChatSound(b_Text_Unformat(Txt
));
903 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
905 g_Console_Add(#20'[Team] '#2 + Txt
, True);
906 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
907 g_Game_ChatSound(b_Text_Unformat(Txt
));
913 Name
:= g_Net_ClientName_ByID(ID
);
914 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
915 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
916 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
920 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
922 NetOut
.Write(Byte(NET_MSG_GFX
));
928 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
931 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
933 NetOut
.Write(Byte(NET_MSG_SND
));
937 NetOut
.Write(Byte(1));
942 NetOut
.Write(Byte(0));
944 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
947 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
949 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
951 NetOut
.Write(Byte(NET_MSG_SHADD
));
953 NetOut
.Write(Shots
[Proj
].ShotType
);
954 NetOut
.Write(Shots
[Proj
].Target
);
955 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
956 NetOut
.Write(Shots
[Proj
].Timeout
);
957 NetOut
.Write(Shots
[Proj
].Obj
.X
);
958 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
959 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
960 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
962 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
965 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
967 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
969 NetOut
.Write(Byte(NET_MSG_SHPOS
));
971 NetOut
.Write(Shots
[Proj
].Obj
.X
);
972 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
973 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
974 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
976 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
979 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
981 NetOut
.Write(Byte(NET_MSG_SHDEL
));
983 NetOut
.Write(Byte(Loud
));
987 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
990 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
992 NetOut
.Write(Byte(NET_MSG_SCORE
));
993 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
995 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
996 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
999 if gGameSettings
.GameMode
= GM_COOP
then
1001 NetOut
.Write(gCoopMonstersKilled
);
1002 NetOut
.Write(gCoopSecretsFound
);
1005 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1008 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1010 NetOut
.Write(Byte(NET_MSG_COOP
));
1011 NetOut
.Write(gTotalMonsters
);
1012 NetOut
.Write(gSecretsCount
);
1013 NetOut
.Write(gCoopTotalMonstersKilled
);
1014 NetOut
.Write(gCoopTotalSecretsFound
);
1015 NetOut
.Write(gCoopTotalMonsters
);
1016 NetOut
.Write(gCoopTotalSecrets
);
1019 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1021 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1022 NetOut
.Write(EvType
);
1023 NetOut
.Write(EvNum
);
1024 NetOut
.Write(EvStr
);
1025 NetOut
.Write(Byte(gLastMap
));
1026 NetOut
.Write(gTime
);
1027 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1029 NetOut
.Write(Byte(1));
1030 NetOut
.Write(gWADHash
);
1032 NetOut
.Write(Byte(0));
1034 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1037 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1039 NetOut
.Write(Byte(NET_MSG_FLAG
));
1040 NetOut
.Write(EvType
);
1042 NetOut
.Write(Byte(Quiet
));
1044 NetOut
.Write(gFlags
[Flag
].State
);
1045 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1046 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1047 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1048 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1049 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1051 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1054 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1056 NetOut
.Write(Byte(NET_MSG_GSET
));
1057 NetOut
.Write(gGameSettings
.GameMode
);
1058 NetOut
.Write(gGameSettings
.GoalLimit
);
1059 NetOut
.Write(gGameSettings
.TimeLimit
);
1060 NetOut
.Write(gGameSettings
.MaxLives
);
1061 NetOut
.Write(gGameSettings
.Options
);
1063 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1068 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1072 P
:= g_Player_Get(PID
);
1073 if P
= nil then Exit
;
1075 NetOut
.Write(Byte(NET_MSG_PLR
));
1077 NetOut
.Write(P
.Name
);
1079 NetOut
.Write(P
.FActualModelName
);
1080 NetOut
.Write(P
.FColor
.R
);
1081 NetOut
.Write(P
.FColor
.G
);
1082 NetOut
.Write(P
.FColor
.B
);
1083 NetOut
.Write(P
.Team
);
1085 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1088 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1093 Pl
:= g_Player_Get(PID
);
1094 if Pl
= nil then Exit
;
1095 if Pl
.FDummy
then Exit
;
1097 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1098 NetOut
.Write(gTime
);
1105 NetOut
.Write(FPing
);
1106 NetOut
.Write(FLoss
);
1107 if IsKeyPressed(KEY_CHAT
) then
1108 kByte
:= NET_KEY_CHAT
1111 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1112 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1113 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1114 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1115 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1118 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1120 NetOut
.Write(kByte
);
1121 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1122 NetOut
.Write(GameX
);
1123 NetOut
.Write(GameY
);
1124 NetOut
.Write(GameVelX
);
1125 NetOut
.Write(GameVelY
);
1126 NetOut
.Write(GameAccelX
);
1127 NetOut
.Write(GameAccelY
);
1130 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1133 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1138 P
:= g_Player_Get(PID
);
1139 if P
= nil then Exit
;
1141 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1146 NetOut
.Write(Byte(alive
));
1147 NetOut
.Write(Byte(GodMode
));
1148 NetOut
.Write(Health
);
1149 NetOut
.Write(Armor
);
1151 NetOut
.Write(JetFuel
);
1152 NetOut
.Write(Lives
);
1155 for I
:= WP_FIRST
to WP_LAST
do
1156 NetOut
.Write(Byte(FWeapon
[I
]));
1158 for I
:= A_BULLETS
to A_HIGH
do
1159 NetOut
.Write(FAmmo
[I
]);
1161 for I
:= A_BULLETS
to A_HIGH
do
1162 NetOut
.Write(FMaxAmmo
[I
]);
1164 for I
:= MR_SUIT
to MR_MAX
do
1165 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1167 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1168 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1169 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1170 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1171 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1173 NetOut
.Write(Frags
);
1174 NetOut
.Write(Death
);
1176 NetOut
.Write(CurrWeap
);
1178 NetOut
.Write(Byte(FSpectator
));
1179 NetOut
.Write(Byte(FGhost
));
1180 NetOut
.Write(Byte(FPhysics
));
1181 NetOut
.Write(Byte(FNoRespawn
));
1182 NetOut
.Write(Byte(FJetpack
));
1183 NetOut
.Write(FFireTime
);
1184 NetOut
.Write(Byte(FFlaming
));
1185 NetOut
.Write(FSpawnInvul
);
1188 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1191 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1193 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1196 NetOut
.Write(Attacker
);
1197 NetOut
.Write(Value
);
1201 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1204 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1206 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1208 NetOut
.Write(KillType
);
1209 NetOut
.Write(DeathType
);
1210 NetOut
.Write(Attacker
);
1212 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1215 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1217 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1219 NetOut
.Write(Weapon
);
1224 NetOut
.Write(ShotID
);
1226 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1229 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1231 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1234 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1237 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1241 Pl
:= g_Player_Get(PID
);
1242 if Pl
= nil then Exit
;
1244 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1246 NetOut
.Write(Pl
.Name
);
1248 NetOut
.Write(Pl
.Model
.GetName())
1251 NetOut
.Write(Pl
.FColor
.R
);
1252 NetOut
.Write(Pl
.FColor
.G
);
1253 NetOut
.Write(Pl
.FColor
.B
);
1254 NetOut
.Write(Pl
.Team
);
1256 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1261 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1266 it
:= g_Items_ByIdx(IID
);
1268 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1270 NetOut
.Write(Byte(Quiet
));
1272 if it
.dropped
then tt
:= tt
or $80;
1274 NetOut
.Write(Byte(it
.Fall
));
1275 NetOut
.Write(Byte(it
.Respawnable
));
1276 NetOut
.Write(it
.Obj
.X
);
1277 NetOut
.Write(it
.Obj
.Y
);
1278 NetOut
.Write(it
.Obj
.Vel
.X
);
1279 NetOut
.Write(it
.Obj
.Vel
.Y
);
1281 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1284 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1286 NetOut
.Write(Byte(NET_MSG_IDEL
));
1288 NetOut
.Write(Byte(Quiet
));
1290 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1295 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1299 TP
:= g_Map_PanelByGUID(PGUID
);
1300 if (TP
= nil) then exit
;
1304 NetOut
.Write(Byte(NET_MSG_PTEX
));
1305 NetOut
.Write(LongWord(PGUID
));
1306 NetOut
.Write(FCurTexture
);
1307 NetOut
.Write(FCurFrame
);
1308 NetOut
.Write(FCurFrameCount
);
1309 NetOut
.Write(AnimLoop
);
1312 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1315 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1320 TP
:= g_Map_PanelByGUID(PGUID
);
1321 if (TP
= nil) then exit
;
1323 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1324 NetOut
.Write(LongWord(PGUID
));
1325 NetOut
.Write(Byte(TP
.Enabled
));
1326 NetOut
.Write(TP
.LiftType
);
1329 NetOut
.Write(Word(TP
.Width
));
1330 NetOut
.Write(Word(TP
.Height
));
1332 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1333 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1334 NetOut
.Write(LongInt(TP
.movingStartX
));
1335 NetOut
.Write(LongInt(TP
.movingStartY
));
1336 NetOut
.Write(LongInt(TP
.movingEndX
));
1337 NetOut
.Write(LongInt(TP
.movingEndY
));
1338 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1339 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1340 NetOut
.Write(LongInt(TP
.sizeEndX
));
1341 NetOut
.Write(LongInt(TP
.sizeEndY
));
1342 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1343 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1344 NetOut
.Write(Byte(mpflags
));
1346 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1351 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1353 if gTriggers
= nil then Exit
;
1354 if T
.Sound
= nil then Exit
;
1356 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1357 NetOut
.Write(T
.ClientID
);
1358 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1359 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1360 NetOut
.Write(T
.SoundPlayCount
);
1362 g_Net_Host_Send(ID
, True);
1365 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1367 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1368 NetOut
.Write(gMusic
.Name
);
1369 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1370 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1371 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1373 g_Net_Host_Send(ID
, True);
1378 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1382 M
:= g_Monsters_ByUID(UID
);
1388 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1390 NetOut
.Write(MonsterType
);
1391 NetOut
.Write(MonsterState
);
1392 NetOut
.Write(MonsterAnim
);
1393 NetOut
.Write(MonsterTargetUID
);
1394 NetOut
.Write(MonsterTargetTime
);
1395 NetOut
.Write(MonsterBehaviour
);
1396 NetOut
.Write(MonsterSleep
);
1397 NetOut
.Write(MonsterHealth
);
1398 NetOut
.Write(MonsterAmmo
);
1399 NetOut
.Write(GameX
);
1400 NetOut
.Write(GameY
);
1401 NetOut
.Write(GameVelX
);
1402 NetOut
.Write(GameVelY
);
1403 NetOut
.Write(Byte(GameDirection
));
1406 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1409 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1413 M
:= g_Monsters_ByUID(UID
);
1414 if M
= nil then Exit
;
1416 NetOut
.Write(Byte(NET_MSG_MPOS
));
1421 NetOut
.Write(GameX
);
1422 NetOut
.Write(GameY
);
1423 NetOut
.Write(GameVelX
);
1424 NetOut
.Write(GameVelY
);
1425 NetOut
.Write(Byte(GameDirection
));
1428 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1431 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1435 M
:= g_Monsters_ByUID(UID
);
1436 if M
= nil then Exit
;
1438 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1443 NetOut
.Write(MonsterState
);
1444 NetOut
.Write(ForcedAnim
);
1445 NetOut
.Write(MonsterTargetUID
);
1446 NetOut
.Write(MonsterTargetTime
);
1447 NetOut
.Write(MonsterSleep
);
1448 NetOut
.Write(MonsterHealth
);
1449 NetOut
.Write(MonsterAmmo
);
1450 NetOut
.Write(MonsterPain
);
1451 NetOut
.Write(Byte(AnimIsReverse
));
1452 NetOut
.Write(FFireTime
);
1455 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1458 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1460 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1467 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1470 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1474 M
:= g_Monsters_ByUID(UID
);
1475 if M
= nil then Exit
;
1477 NetOut
.Write(Byte(NET_MSG_MDEL
));
1480 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1485 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1487 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1490 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1493 procedure MH_SEND_VoteEvent(EvType
: Byte;
1494 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1495 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1496 ID
: Integer = NET_EVERYONE
);
1498 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1499 NetOut
.Write(EvType
);
1500 NetOut
.Write(IntArg1
);
1501 NetOut
.Write(IntArg2
);
1502 NetOut
.Write(StrArg1
);
1503 NetOut
.Write(StrArg2
);
1505 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1508 // CLIENT MESSAGES //
1512 procedure MC_RECV_Chat(var M
: TMsg
);
1517 Txt
:= M
.ReadString();
1518 Mode
:= M
.ReadByte();
1520 if Mode
<> NET_CHAT_SYSTEM
then
1522 if NetDeafLevel
= 0 then
1524 if Mode
= NET_CHAT_PLAYER
then
1526 g_Console_Add(Txt
, True);
1527 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1528 g_Game_ChatSound(b_Text_Unformat(Txt
));
1530 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1532 if gPlayer1
.Team
= TEAM_RED
then
1533 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1534 if gPlayer1
.Team
= TEAM_BLUE
then
1535 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1536 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1537 g_Game_ChatSound(b_Text_Unformat(Txt
));
1540 end else if (NetDeafLevel
< 2) then
1541 g_Console_Add(Txt
, True);
1544 procedure MC_RECV_Effect(var M
: TMsg
);
1550 if not gGameOn
then Exit
;
1551 Kind
:= M
.ReadByte();
1552 X
:= M
.ReadLongInt();
1553 Y
:= M
.ReadLongInt();
1554 Ang
:= M
.ReadSmallInt();
1558 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1562 g_GFX_QueueEffect(R_GFX_TELEPORT_FAST
, X
, Y
);
1564 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1569 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, X
- 64, Y
- 64);
1571 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1576 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, X
- 64, Y
- 64);
1578 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1583 g_GFX_QueueEffect(R_GFX_BFG_HIT
, X
- 32, Y
- 32);
1588 g_GFX_QueueEffect(R_GFX_FIRE
, X
, Y
);
1590 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1595 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
, Y
);
1597 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1601 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1604 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1608 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1609 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1614 procedure MC_RECV_Sound(var M
: TMsg
);
1620 Name
:= M
.ReadString();
1621 Pos
:= M
.ReadByte() <> 0;
1624 X
:= M
.ReadLongInt();
1625 Y
:= M
.ReadLongInt();
1626 g_Sound_PlayExAt(Name
, X
, Y
);
1629 g_Sound_PlayEx(Name
);
1632 procedure MC_RECV_CreateShot(var M
: TMsg
);
1634 I
, X
, Y
, XV
, YV
: Integer;
1636 Target
, Spawner
: Word;
1639 I
:= M
.ReadLongInt();
1640 ShType
:= M
.ReadByte();
1641 Target
:= M
.ReadWord();
1642 Spawner
:= M
.ReadWord();
1643 Timeout
:= M
.ReadLongWord();
1644 X
:= M
.ReadLongInt();
1645 Y
:= M
.ReadLongInt();
1646 XV
:= M
.ReadLongInt();
1647 YV
:= M
.ReadLongInt();
1649 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1650 if (Shots
<> nil) and (I
<= High(Shots
)) then
1652 Shots
[I
].Timeout
:= Timeout
;
1653 //Shots[I].Target := Target; // TODO: find a use for Target later
1657 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1659 I
, TX
, TY
, TXV
, TYV
: Integer;
1661 I
:= M
.ReadLongInt();
1662 TX
:= M
.ReadLongInt();
1663 TY
:= M
.ReadLongInt();
1664 TXV
:= M
.ReadLongInt();
1665 TYV
:= M
.ReadLongInt();
1667 if (Shots
<> nil) and (I
<= High(Shots
)) then
1677 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1682 if not gGameOn
then Exit
;
1683 I
:= M
.ReadLongInt();
1684 L
:= (M
.ReadByte() <> 0);
1685 X
:= M
.ReadLongInt();
1686 Y
:= M
.ReadLongInt();
1688 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1691 procedure MC_RECV_GameStats(var M
: TMsg
);
1693 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1695 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1696 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1699 if gGameSettings
.GameMode
= GM_COOP
then
1701 gCoopMonstersKilled
:= M
.ReadWord();
1702 gCoopSecretsFound
:= M
.ReadWord();
1706 procedure MC_RECV_CoopStats(var M
: TMsg
);
1708 gTotalMonsters
:= M
.ReadLongInt();
1709 gSecretsCount
:= M
.ReadLongInt();
1710 gCoopTotalMonstersKilled
:= M
.ReadWord();
1711 gCoopTotalSecretsFound
:= M
.ReadWord();
1712 gCoopTotalMonsters
:= M
.ReadWord();
1713 gCoopTotalSecrets
:= M
.ReadWord();
1716 procedure MC_RECV_GameEvent(var M
: TMsg
);
1725 i1
, i2
: TStrings_Locale
;
1728 goodCmd
: Boolean = true;
1730 FillChar(EvHash
, Sizeof(EvHash
), 0);
1731 EvType
:= M
.ReadByte();
1732 EvNum
:= M
.ReadLongInt();
1733 EvStr
:= M
.ReadString();
1734 gLastMap
:= M
.ReadByte() <> 0;
1735 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1736 gStatsPressed
:= True;
1737 EvTime
:= M
.ReadLongWord();
1738 BHash
:= M
.ReadByte() <> 0;
1740 EvHash
:= M
.ReadMD5();
1744 if (g_Res_received_map_start
<> 0) then
1746 if (g_Res_received_map_start
< 0) then exit
;
1749 NET_EV_MAPSTART
: goodCmd
:= true;
1750 NET_EV_MAPEND
: goodCmd
:= true;
1751 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1752 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1753 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1755 if not goodCmd
then exit
;
1761 if (g_Res_received_map_start
<> 0) then
1763 g_Res_received_map_start
:= -1;
1768 g_Game_ClearLoading();
1769 g_Game_StopAllSounds(True);
1771 gSwitchGameMode
:= Byte(EvNum
);
1772 gGameSettings
.GameMode
:= gSwitchGameMode
;
1775 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1777 if not isWadPath(EvStr
) then
1778 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1780 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1784 MC_SEND_FullStateRequest
;
1790 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1791 gLMSRespawnTime
:= 0;
1792 if (g_Res_received_map_start
<> 0) then
1794 g_Res_received_map_start
:= -1;
1798 gMissionFailed
:= EvNum
<> 0;
1799 gExit
:= EXIT_ENDLEVELCUSTOM
;
1807 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1809 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1811 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1817 if NetDeafLevel
< 2 then
1819 if EvNum
= TEAM_RED
then
1820 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1821 if EvNum
= TEAM_BLUE
then
1822 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1828 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1829 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1834 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1835 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1842 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
1843 gLMSRespawnTime
:= gTime
+ EvNum
;
1844 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
1846 else if gPlayer1
= nil then
1848 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1852 NET_EV_LMS_SURVIVOR
:
1853 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1856 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1860 pl
:= g_Player_Get(EvNum
and $FFFF);
1865 cnt
:= (EvNum
shr 16) and $FF;
1866 if Pos('w', EvStr
) = 0 then
1869 if Pos('t', EvStr
) = 0 then
1872 if Pos('-', EvStr
) = 0 then
1874 if Pos('e', EvStr
) = 0 then
1875 i1
:= I_PLAYER_SCORE_ADD_OWN
1877 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1880 if Pos('e', EvStr
) = 0 then
1881 i1
:= I_PLAYER_SCORE_SUB_OWN
1883 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1886 if Pos('r', EvStr
) > 0 then
1887 i2
:= I_PLAYER_SCORE_TO_RED
1889 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1890 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1894 if Pos('-', EvStr
) = 0 then
1895 i1
:= I_PLAYER_SCORE_ADD_TEAM
1897 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1899 if Pos('r', EvStr
) > 0 then
1900 i2
:= I_PLAYER_SCORE_RED
1902 i2
:= I_PLAYER_SCORE_BLUE
;
1903 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1908 if Pos('e', EvStr
) = 0 then
1909 i1
:= I_PLAYER_SCORE_WIN_OWN
1911 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1913 if Pos('r', EvStr
) > 0 then
1914 i2
:= I_PLAYER_SCORE_TO_RED
1916 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1917 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1923 if EvNum
= TEAM_RED
then
1924 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1925 if EvNum
= TEAM_BLUE
then
1926 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1927 if EvNum
= -TEAM_RED
then
1928 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1929 if EvNum
= -TEAM_BLUE
then
1930 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1935 g_Player_RemoveAllCorpses
;
1936 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1937 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1941 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1945 if EvNum
= TEAM_RED
then
1946 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1947 if EvNum
= TEAM_BLUE
then
1948 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1952 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1955 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1958 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1961 g_Game_Announce_KillCombo(EvNum
);
1963 NET_EV_PLAYER_TOUCH
:
1965 pl
:= g_Player_Get(EvNum
);
1972 pl
:= g_Player_Get(EvNum
);
1975 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
1976 g_Sound_PlayEx('SOUND_GAME_SECRET');
1982 pl
:= g_Player_Get(EvNum
);
1983 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
1988 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1997 EvType
:= M
.ReadByte();
2000 if Fl
= FLAG_NONE
then Exit
;
2002 Quiet
:= (M
.ReadByte() <> 0);
2003 PID
:= M
.ReadWord();
2005 gFlags
[Fl
].State
:= M
.ReadByte();
2006 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2007 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2008 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2009 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2010 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2012 Pl
:= g_Player_Get(PID
);
2014 (EvType
<> FLAG_STATE_NORMAL
) and
2015 (EvType
<> FLAG_STATE_DROPPED
) and
2016 (EvType
<> FLAG_STATE_RETURNED
) then
2022 if Quiet
or (Pl
= nil) then Exit
;
2024 if Fl
= FLAG_RED
then
2025 s
:= _lc
[I_PLAYER_FLAG_RED
]
2027 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2029 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2031 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2032 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2033 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2038 if not sound_ret_flag
[a
].IsPlaying() then
2039 sound_ret_flag
[a
].Play();
2042 FLAG_STATE_CAPTURED
:
2044 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2048 if Fl
= FLAG_RED
then
2049 s
:= _lc
[I_PLAYER_FLAG_RED
]
2051 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2053 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2054 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2056 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2057 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2058 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2063 if not sound_get_flag
[a
].IsPlaying() then
2064 sound_get_flag
[a
].Play();
2069 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2071 if Quiet
or (Pl
= nil) then Exit
;
2073 if Fl
= FLAG_RED
then
2074 s
:= _lc
[I_PLAYER_FLAG_RED
]
2076 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2078 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2079 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2081 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2082 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2083 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2088 if not sound_lost_flag
[a
].IsPlaying() then
2089 sound_lost_flag
[a
].Play();
2094 g_Map_ResetFlag(FLAG_RED
);
2095 g_Map_ResetFlag(FLAG_BLUE
);
2096 if Quiet
or (Pl
= nil) then Exit
;
2097 Pl
.SetFlag(FLAG_NONE
);
2099 if Fl
= FLAG_RED
then
2100 s
:= _lc
[I_PLAYER_FLAG_RED
]
2102 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2104 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2105 Insert('.', ts
, Length(ts
) + 1 - 3);
2106 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2107 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2109 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2110 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2111 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2116 if not sound_cap_flag
[a
].IsPlaying() then
2117 sound_cap_flag
[a
].Play();
2120 FLAG_STATE_RETURNED
:
2122 g_Map_ResetFlag(Fl
);
2125 if Fl
= FLAG_RED
then
2126 s
:= _lc
[I_PLAYER_FLAG_RED
]
2128 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2130 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2132 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2133 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2134 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2139 if not sound_ret_flag
[a
].IsPlaying() then
2140 sound_ret_flag
[a
].Play();
2145 procedure MC_RECV_GameSettings(var M
: TMsg
);
2147 gGameSettings
.GameMode
:= M
.ReadByte();
2148 gGameSettings
.GoalLimit
:= M
.ReadWord();
2149 gGameSettings
.TimeLimit
:= M
.ReadWord();
2150 gGameSettings
.MaxLives
:= M
.ReadByte();
2151 gGameSettings
.Options
:= M
.ReadLongWord();
2156 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2159 PName
, Model
: string;
2164 PID
:= M
.ReadWord();
2165 Pl
:= g_Player_Get(PID
);
2167 PName
:= M
.ReadString();
2168 Model
:= M
.ReadString();
2169 Color
.R
:= M
.ReadByte();
2170 Color
.G
:= M
.ReadByte();
2171 Color
.B
:= M
.ReadByte();
2175 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2177 if (Pl
<> nil) then Exit
;
2178 DID
:= g_Player_Create(Model
, Color
, T
, False);
2179 with g_Player_Get(DID
) do
2188 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2189 gPlayer1
.UID
:= PID
;
2190 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2191 gPlayer1
.ChangeTeam(T
);
2193 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2194 gPlayer2
.UID
:= PID
;
2195 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2196 gPlayer2
.ChangeTeam(T
);
2200 if NetDeafLevel
< 3 then
2201 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2202 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2206 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2213 TmpX
, TmpY
: Integer;
2217 GT
:= M
.ReadLongWord();
2218 if GT
< gTime
- NET_MAX_DIFFTIME
then
2225 PID
:= M
.ReadWord();
2226 Pl
:= g_Player_Get(PID
);
2228 if Pl
= nil then Exit
;
2234 FPing
:= M
.ReadWord();
2235 FLoss
:= M
.ReadByte();
2236 kByte
:= M
.ReadWord();
2237 Dir
:= M
.ReadByte();
2239 TmpX
:= M
.ReadLongInt();
2240 TmpY
:= M
.ReadLongInt();
2244 if LongBool(kByte
and NET_KEY_CHAT
) then
2245 PressKey(KEY_CHAT
, 10000)
2248 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2249 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2250 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2251 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2252 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2255 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2257 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2258 SetDirection(TDirection(Dir
));
2260 GameVelX
:= M
.ReadLongInt();
2261 GameVelY
:= M
.ReadLongInt();
2262 GameAccelX
:= M
.ReadLongInt();
2263 GameAccelY
:= M
.ReadLongInt();
2264 SetLerp(TmpX
, TmpY
);
2265 if NetForcePlayerUpdate
then Update();
2269 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2273 I
, OldFire
: Integer;
2274 OldJet
, Flam
: Boolean;
2277 PID
:= M
.ReadWord();
2278 Pl
:= g_Player_Get(PID
);
2285 alive
:= (M
.ReadByte() <> 0);
2286 GodMode
:= (M
.ReadByte() <> 0);
2287 Health
:= M
.ReadLongInt();
2288 Armor
:= M
.ReadLongInt();
2289 Air
:= M
.ReadLongInt();
2290 JetFuel
:= M
.ReadLongInt();
2291 Lives
:= M
.ReadByte();
2292 NewTeam
:= M
.ReadByte();
2294 for I
:= WP_FIRST
to WP_LAST
do
2295 FWeapon
[I
] := (M
.ReadByte() <> 0);
2297 for I
:= A_BULLETS
to A_HIGH
do
2298 FAmmo
[I
] := M
.ReadWord();
2300 for I
:= A_BULLETS
to A_HIGH
do
2301 FMaxAmmo
[I
] := M
.ReadWord();
2303 for I
:= MR_SUIT
to MR_MAX
do
2304 FMegaRulez
[I
] := M
.ReadLongWord();
2307 if (M
.ReadByte() <> 0) then
2308 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2309 if (M
.ReadByte() <> 0) then
2310 FRulez
:= FRulez
+ [R_KEY_RED
];
2311 if (M
.ReadByte() <> 0) then
2312 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2313 if (M
.ReadByte() <> 0) then
2314 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2315 if (M
.ReadByte() <> 0) then
2316 FRulez
:= FRulez
+ [R_BERSERK
];
2318 Frags
:= M
.ReadLongInt();
2319 Death
:= M
.ReadLongInt();
2321 SetWeapon(M
.ReadByte());
2323 FSpectator
:= M
.ReadByte() <> 0;
2326 if UID
= NetPlrUID1
then
2328 gSpectLatchPID1
:= UID
;
2331 if UID
= NetPlrUID2
then
2333 gSpectLatchPID2
:= UID
;
2339 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2342 gSpectLatchPID1
:= 0;
2344 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2347 gSpectLatchPID2
:= 0;
2350 FGhost
:= M
.ReadByte() <> 0;
2351 FPhysics
:= M
.ReadByte() <> 0;
2352 FNoRespawn
:= M
.ReadByte() <> 0;
2354 FJetpack
:= M
.ReadByte() <> 0;
2355 OldFire
:= FFireTime
;
2356 FFireTime
:= M
.ReadLongInt();
2357 if (OldFire
<= 0) and (FFireTime
> 0) then
2358 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2359 Flam
:= M
.ReadByte() <> 0;
2360 FSpawnInvul
:= M
.ReadLongInt();
2361 if OldJet
and not FJetpack
then
2363 else if not OldJet
and FJetpack
then
2365 if FFlaming
and not Flam
then
2367 if Team
<> NewTeam
then
2368 Pl
.ChangeTeam(NewTeam
);
2374 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2379 Attacker
, Value
: Word;
2383 if not gGameOn
then Exit
;
2384 PID
:= M
.ReadWord();
2385 Pl
:= g_Player_Get(PID
);
2386 if Pl
= nil then Exit
;
2388 Kind
:= M
.ReadByte();
2389 Attacker
:= M
.ReadWord();
2390 Value
:= M
.ReadWord();
2395 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2400 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2404 KillType
, DeathType
: Byte;
2408 if not gGameOn
then Exit
;
2409 PID
:= M
.ReadWord();
2410 Pl
:= g_Player_Get(PID
);
2411 if Pl
= nil then Exit
;
2413 KillType
:= M
.ReadByte();
2414 DeathType
:= M
.ReadByte();
2415 Attacker
:= M
.ReadWord();
2419 Kill(KillType
, Attacker
, DeathType
);
2424 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2429 PID
:= M
.ReadWord();
2430 Pl
:= g_Player_Get(PID
);
2432 if Pl
= nil then Exit
;
2434 if NetDeafLevel
< 3 then
2435 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2436 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2438 g_Player_Remove(PID
);
2443 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2448 X
, Y
, AX
, AY
: Integer;
2452 if not gGameOn
then Exit
;
2453 PID
:= M
.ReadWord();
2454 Pl
:= g_Player_Get(PID
);
2455 if Pl
= nil then Exit
;
2457 Weap
:= M
.ReadByte();
2458 X
:= M
.ReadLongInt();
2459 Y
:= M
.ReadLongInt();
2460 AX
:= M
.ReadLongInt();
2461 AY
:= M
.ReadLongInt();
2462 SHID
:= M
.ReadLongInt();
2465 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2468 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2477 PID
:= M
.ReadWord();
2478 Pl
:= g_Player_Get(PID
);
2479 if Pl
= nil then Exit
;
2481 TmpName
:= M
.ReadString();
2482 TmpModel
:= M
.ReadString();
2483 TmpColor
.R
:= M
.ReadByte();
2484 TmpColor
.G
:= M
.ReadByte();
2485 TmpColor
.B
:= M
.ReadByte();
2486 TmpTeam
:= M
.ReadByte();
2488 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2490 Pl
.ChangeTeam(TmpTeam
);
2491 if gPlayer1
= Pl
then
2492 gPlayer1Settings
.Team
:= TmpTeam
;
2493 if gPlayer2
= Pl
then
2494 gPlayer2Settings
.Team
:= TmpTeam
;
2496 Pl
.SetColor(TmpColor
);
2498 if Pl
.Name
<> TmpName
then
2500 if NetDeafLevel
< 3 then
2501 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2505 if TmpModel
<> Pl
.Model
.GetName() then
2506 Pl
.SetModel(TmpModel
);
2511 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2514 X
, Y
, VX
, VY
: Integer;
2516 Quiet
, Fall
{, Resp}: Boolean;
2519 if not gGameOn
then Exit
;
2521 Quiet
:= M
.ReadByte() <> 0;
2523 Fall
:= M
.ReadByte() <> 0;
2524 {Resp :=} M
.ReadByte();
2525 X
:= M
.ReadLongInt();
2526 Y
:= M
.ReadLongInt();
2527 VX
:= M
.ReadLongInt();
2528 VY
:= M
.ReadLongInt();
2530 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2531 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2533 it
:= g_Items_ByIdx(ID
);
2539 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2540 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16);
2544 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2549 if not gGameOn
then Exit
;
2551 Quiet
:= M
.ReadByte() <> 0;
2553 if not g_Items_ValidId(ID
) then exit
;
2555 if not Quiet
then g_Items_EmitPickupSound(ID
);
2562 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2569 if not gGameOn
then Exit
;
2571 PGUID
:= Integer(M
.ReadLongWord());
2572 Tex
:= M
.ReadLongInt();
2573 Fr
:= M
.ReadLongInt();
2574 Cnt
:= M
.ReadByte();
2575 Loop
:= M
.ReadByte();
2577 TP
:= g_Map_PanelByGUID(PGUID
);
2581 TP
.SetTexture(Tex
, Loop
);
2582 TP
.SetFrame(Fr
, Cnt
);
2586 procedure MC_RECV_PanelState(var M
: TMsg
);
2591 X
, Y
, W
, H
: Integer;
2593 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2594 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2597 if not gGameOn
then Exit
;
2599 PGUID
:= Integer(M
.ReadLongWord());
2600 E
:= (M
.ReadByte() <> 0);
2601 Lift
:= M
.ReadByte();
2602 X
:= M
.ReadLongInt();
2603 Y
:= M
.ReadLongInt();
2607 speedX
:= M
.ReadLongInt();
2608 speedY
:= M
.ReadLongInt();
2609 startX
:= M
.ReadLongInt();
2610 startY
:= M
.ReadLongInt();
2611 endX
:= M
.ReadLongInt();
2612 endY
:= M
.ReadLongInt();
2613 sizeSpX
:= M
.ReadLongInt();
2614 sizeSpY
:= M
.ReadLongInt();
2615 sizeEX
:= M
.ReadLongInt();
2616 sizeEY
:= M
.ReadLongInt();
2617 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2619 TP
:= g_Map_PanelByGUID(PGUID
);
2620 if (TP
= nil) then exit
;
2622 // update lifts state
2623 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2625 // update enabled/disabled state for all panels
2626 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2628 // update panel position, as it can be moved (mplat)
2633 // update mplat state
2634 TP
.movingSpeedX
:= speedX
;
2635 TP
.movingSpeedY
:= speedY
;
2636 TP
.movingStartX
:= startX
;
2637 TP
.movingStartY
:= startY
;
2638 TP
.movingEndX
:= endX
;
2639 TP
.movingEndY
:= endY
;
2640 TP
.sizeSpeedX
:= sizeSpX
;
2641 TP
.sizeSpeedY
:= sizeSpY
;
2642 TP
.sizeEndX
:= sizeEX
;
2643 TP
.sizeEndY
:= sizeEY
;
2644 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2645 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2646 // notify panel of it's position/size change, so it can fix other internal structures
2647 TP
.positionChanged();
2652 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2655 SPos
, SID
: LongWord;
2659 if not gGameOn
then Exit
;
2660 if gTriggers
= nil then Exit
;
2662 SID
:= M
.ReadLongWord();
2663 SPlaying
:= M
.ReadByte() <> 0;
2664 SPos
:= M
.ReadLongWord();
2665 SCount
:= M
.ReadLongInt();
2667 for I
:= Low(gTriggers
) to High(gTriggers
) do
2668 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2669 if gTriggers
[I
].ClientID
= SID
then
2670 with gTriggers
[I
] do
2672 if Sound
<> nil then
2677 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2679 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2680 Sound
.SetPosition(SPos
);
2683 if Sound
.IsPlaying
then Sound
.Stop
;
2686 SoundPlayCount
:= SCount
;
2690 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2697 if not gGameOn
then Exit
;
2699 MName
:= M
.ReadString();
2700 MPlaying
:= M
.ReadByte() <> 0;
2701 MPos
:= M
.ReadLongWord();
2702 MPaused
:= M
.ReadByte() <> 0;
2703 MPos
:= MPos
+1; //k8: stfu, fpc!
2707 gMusic
.SetByName(MName
);
2709 // gMusic.SetPosition(MPos);
2710 gMusic
.SpecPause
:= MPaused
;
2713 if gMusic
.IsPlaying
then gMusic
.Stop
;
2718 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2721 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2722 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2727 Mon
:= g_Monsters_ByUID(ID
);
2731 MType
:= M
.ReadByte();
2732 MState
:= M
.ReadByte();
2733 MAnim
:= M
.ReadByte();
2734 MTarg
:= M
.ReadWord();
2735 MTargTime
:= M
.ReadLongInt();
2736 MBehav
:= M
.ReadByte();
2737 MSleep
:= M
.ReadLongInt();
2738 MHealth
:= M
.ReadLongInt();
2739 MAmmo
:= M
.ReadLongInt();
2741 X
:= M
.ReadLongInt();
2742 Y
:= M
.ReadLongInt();
2743 VX
:= M
.ReadLongInt();
2744 VY
:= M
.ReadLongInt();
2745 MDir
:= M
.ReadByte();
2747 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2748 Mon
:= g_Monsters_ByUID(ID
);
2755 MonsterAnim
:= MAnim
;
2756 MonsterTargetUID
:= MTarg
;
2757 MonsterTargetTime
:= MTargTime
;
2758 MonsterBehaviour
:= MBehav
;
2759 MonsterSleep
:= MSleep
;
2760 MonsterAmmo
:= MAmmo
;
2765 setPosition(X
, Y
); // this will call positionChanged();
2771 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2778 Mon
:= g_Monsters_ByUID(ID
);
2784 X
:= M
.ReadLongInt();
2785 Y
:= M
.ReadLongInt();
2786 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2787 GameVelX
:= M
.ReadLongInt();
2788 GameVelY
:= M
.ReadLongInt();
2789 GameDirection
:= TDirection(M
.ReadByte());
2793 procedure MC_RECV_MonsterState(var M
: TMsg
);
2795 ID
, OldFire
: Integer;
2796 MState
, MFAnm
: Byte;
2798 AnimRevert
: Boolean;
2801 Mon
:= g_Monsters_ByUID(ID
);
2802 if Mon
= nil then Exit
;
2804 MState
:= M
.ReadByte();
2805 MFAnm
:= M
.ReadByte();
2809 MonsterTargetUID
:= M
.ReadWord();
2810 MonsterTargetTime
:= M
.ReadLongInt();
2811 MonsterSleep
:= M
.ReadLongInt();
2812 MonsterHealth
:= M
.ReadLongInt();
2813 MonsterAmmo
:= M
.ReadLongInt();
2814 MonsterPain
:= M
.ReadLongInt();
2815 AnimRevert
:= M
.ReadByte() <> 0;
2816 OldFire
:= FFireTime
;
2817 FFireTime
:= M
.ReadLongInt();
2818 if (OldFire
<= 0) and (FFireTime
> 0) then
2819 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2820 RevertAnim(AnimRevert
);
2822 if MonsterState
<> MState
then
2824 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2825 if (MState
= MONSTATE_DIE
) then DieSound();
2826 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2827 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2828 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2830 SetState(MState
, MFAnm
);
2835 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2839 X
, Y
, VX
, VY
: Integer;
2843 Mon
:= g_Monsters_ByUID(ID
);
2844 if Mon
= nil then Exit
;
2846 X
:= M
.ReadLongInt();
2847 Y
:= M
.ReadLongInt();
2848 VX
:= M
.ReadLongInt();
2849 VY
:= M
.ReadLongInt();
2851 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2854 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2860 Mon
:= g_Monsters_ByUID(ID
);
2861 if Mon
= nil then Exit
;
2863 Mon
.MonsterRemoved
:= True;
2866 procedure MC_RECV_TimeSync(var M
: TMsg
);
2870 Time
:= M
.ReadLongWord();
2872 if gState
= STATE_INTERCUSTOM
then
2873 gServInterTime
:= Min(Time
, 255);
2876 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2880 Int1
, Int2
: SmallInt;
2882 EvID
:= M
.ReadByte();
2883 Int1
:= M
.ReadSmallInt();
2884 Int2
:= M
.ReadSmallInt();
2885 Str1
:= M
.ReadString();
2886 Str2
:= M
.ReadString();
2888 if NetDeafLevel
< 2 then
2891 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2893 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2895 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2897 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2899 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2905 procedure MC_SEND_Info(Password
: string);
2909 NetOut
.Write(Byte(NET_MSG_INFO
));
2910 NetOut
.Write(GAME_VERSION
);
2911 NetOut
.Write(Password
);
2912 NetOut
.Write(gPlayer1Settings
.Name
);
2913 NetOut
.Write(gPlayer1Settings
.Model
);
2914 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2915 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2916 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2917 NetOut
.Write(gPlayer1Settings
.Team
);
2919 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2922 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2924 NetOut
.Write(Byte(NET_MSG_CHAT
));
2928 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2931 procedure MC_SEND_PlayerPos();
2936 WeaponSelect
: Word = 0;
2939 if not gGameOn
then Exit
;
2940 if gPlayers
= nil then Exit
;
2941 if gPlayer1
= nil then Exit
;
2944 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2947 if (not gConsoleShow
) and (not gChatShow
) then
2949 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2952 strafeDir
:= P1MoveButton
shr 4;
2953 P1MoveButton
:= P1MoveButton
and $0F;
2955 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2957 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2959 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2963 if gPlayerAction
[0, ACTION_STRAFE
] then
2965 // new strafe mechanics
2966 if (strafeDir
= 0) then
2967 strafeDir
:= P1MoveButton
; // start strafing
2968 // now set direction according to strafe (reversed)
2969 if (strafeDir
= 2) then
2970 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2971 else if (strafeDir
= 1) then
2972 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2976 strafeDir
:= 0; // not strafing anymore
2977 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
2978 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2979 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2980 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2981 else if P1MoveButton
<> 0 then
2982 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2985 gPlayer1
.ReleaseKeys
;
2986 if P1MoveButton
= 1 then
2988 kByte
:= kByte
or NET_KEY_LEFT
;
2989 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2991 if P1MoveButton
= 2 then
2993 kByte
:= kByte
or NET_KEY_RIGHT
;
2994 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2996 if gPlayerAction
[0, ACTION_LOOKUP
] then
2998 kByte
:= kByte
or NET_KEY_UP
;
2999 gPlayer1
.PressKey(KEY_UP
, 10000);
3001 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3003 kByte
:= kByte
or NET_KEY_DOWN
;
3004 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3006 if gPlayerAction
[0, ACTION_JUMP
] then
3008 kByte
:= kByte
or NET_KEY_JUMP
;
3009 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3011 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3012 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3013 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
3014 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
3016 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3017 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3019 for i
:= WP_FIRST
to WP_LAST
do
3021 if gSelectWeapon
[0, i
] then
3023 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3024 gSelectWeapon
[0, i
] := False
3028 // fix movebutton state
3029 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3032 kByte
:= NET_KEY_CHAT
;
3034 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3035 NetOut
.Write(gTime
);
3036 NetOut
.Write(kByte
);
3037 NetOut
.Write(Byte(gPlayer1
.Direction
));
3038 NetOut
.Write(WeaponSelect
);
3039 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3040 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3042 //kBytePrev := kByte;
3043 //kDirPrev := gPlayer1.Direction;
3046 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3048 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3049 NetOut
.Write(Byte(Start
));
3050 NetOut
.Write(Command
);
3051 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3054 procedure MC_SEND_PlayerSettings();
3056 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3057 NetOut
.Write(gPlayer1Settings
.Name
);
3058 NetOut
.Write(gPlayer1Settings
.Model
);
3059 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3060 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3061 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3062 NetOut
.Write(gPlayer1Settings
.Team
);
3064 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3067 procedure MC_SEND_FullStateRequest();
3069 NetOut
.Write(Byte(NET_MSG_REQFST
));
3071 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3074 procedure MC_SEND_CheatRequest(Kind
: Byte);
3076 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3079 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3081 procedure MC_SEND_RCONPassword(Password
: string);
3083 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3084 NetOut
.Write(Password
);
3086 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3088 procedure MC_SEND_RCONCommand(Cmd
: string);
3090 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3093 g_Net_Client_Send(True, NET_CHAN_SERVICE
);