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;
285 Math
, ENet
, e_input
, e_log
, g_base
, g_basic
,
286 g_textures
, g_sound
, g_console
, g_options
,
287 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
,
288 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
302 NET_KEY_FORCEDIR
= 4096;
305 //kBytePrev: Word = 0;
306 //kDirPrev: TDirection = D_LEFT;
307 //HostGameTime: Word = 0;
310 function IsValidFileName(const S
: String): Boolean;
312 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
317 for I
:= 1 to Length(S
) do
318 Result
:= Result
and (not(S
[I
] in Forbidden
));
321 function IsValidFilePath(const S
: String): Boolean;
326 if not IsValidFileName(S
) then exit
;
327 if FileExists(S
) then exit
;
328 I
:= LastDelimiter('\/', S
);
330 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
341 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
349 Pl
:= g_Player_Get(PID
);
351 Txt
:= M
.ReadString();
352 Mode
:= M
.ReadByte();
353 if (Mode
= NET_CHAT_SYSTEM
) then
354 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
355 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
356 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
359 MH_SEND_Chat(Txt
, Mode
)
361 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
364 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
366 Ver
, PName
, Model
, Pw
: string;
372 Ver
:= M
.ReadString();
373 Pw
:= M
.ReadString();
374 PName
:= M
.ReadString();
375 Model
:= M
.ReadString();
381 if Ver
<> GAME_VERSION
then
383 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
384 _lc
[I_NET_DISC_VERSION
]);
385 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
389 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
391 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
393 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
394 _lc
[I_NET_DISC_BAN
]);
395 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
399 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
400 _lc
[I_NET_DISC_BAN
]);
401 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
406 if NetPassword
<> '' then
407 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
409 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
410 _lc
[I_NET_DISC_PASSWORD
]);
411 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
419 PID
:= g_Player_Create(Model
, Color
, T
, False);
420 with g_Player_Get(PID
) do
427 C
^.WaitForFirstSpawn
:= false;
429 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
430 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
431 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
435 with g_Player_Get(PID
) do
439 // round in progress, don't spawn
440 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
441 //e_LogWritefln('spawning player with pid #%u...', [PID]);
442 //Respawn(gGameSettings.GameType = GT_SINGLE);
443 //k8: no, do not spawn a player yet, wait for "request full state" packet
447 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
448 // that is, if we'll set it to `true`, the player can be spawned after
449 // warmup time ran out, for example, regardless of the real player state.
450 // also, this seems to work only for the initial connection. further
451 // map changes could initiate resource downloading, but the player will
452 // be spawned immediately.
453 // the proper solution will require another player state, "ephemeral".
454 // the player should start any map in "ephemeral" state, and turned into
455 // real mobj only when they sent a special "i am ready" packet. this packet
456 // must be sent after receiving the full state, so the player will get a full
457 // map view before going into game.
458 FWantsInGame
:= false;
459 C
^.WaitForFirstSpawn
:= true;
462 //if not C^.WaitForFirstSpawn then
464 for I
:= Low(NetClients
) to High(NetClients
) do
466 if NetClients
[I
].ID
= C
^.ID
then Continue
;
467 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
468 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
469 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
473 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
474 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
478 //g_Net_Slist_Update;
484 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
488 if not C
.WaitForFirstSpawn
then exit
;
489 plr
:= g_Player_Get(C
^.Player
);
490 if not assigned(plr
) then exit
;
491 g_Net_Slist_ServerPlayerComes();
492 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
493 C
.WaitForFirstSpawn
:= false;
494 plr
.FNoRespawn
:= false;
495 plr
.FWantsInGame
:= true; // TODO: look into this later
497 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
500 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
505 if gLMSRespawn
> LMS_RESPAWN_NONE
then
506 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
511 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
513 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
516 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
520 C
^.RequestedFullUpdate
:= True;
526 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
536 if not gGameOn
then Exit
;
538 GT
:= M
.ReadLongWord();
540 Pl
:= g_Player_Get(PID
);
544 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
549 kByte
:= M
.ReadWord();
551 WeaponSelect
:= M
.ReadWord();
552 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
553 if Direction
<> TDirection(Dir
) then
554 JustTeleported
:= False;
556 SetDirection(TDirection(Dir
));
559 if kByte
= NET_KEY_CHAT
then
561 PressKey(KEY_CHAT
, 10000);
565 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
566 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
567 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
568 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
569 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
570 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
571 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
572 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
573 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
577 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
579 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
580 QueueWeaponSwitch(i
);
585 // MH_SEND_PlayerPos(False, PID, C^.ID);
588 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
593 Pl
:= g_Player_Get(C
^.Player
);
594 if Pl
= nil then Exit
;
596 CheatKind
:= M
.ReadByte();
600 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
603 if Pl
.FSpectator
then
605 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
608 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
615 if gState
<> STATE_INTERCUSTOM
then Exit
;
616 Pl
.FReady
:= not Pl
.FReady
;
619 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
620 Inc(gInterReadyCount
);
624 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
625 Dec(gInterReadyCount
);
631 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
639 TmpName
:= M
.ReadString();
640 TmpModel
:= M
.ReadString();
641 TmpColor
.R
:= M
.ReadByte();
642 TmpColor
.G
:= M
.ReadByte();
643 TmpColor
.B
:= M
.ReadByte();
644 TmpTeam
:= M
.ReadByte();
646 Pl
:= g_Player_Get(C
^.Player
);
647 if Pl
= nil then Exit
;
649 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
652 Pl
.SetColor(TmpColor
);
654 if Pl
.Name
<> TmpName
then
656 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
660 if TmpModel
<> Pl
.Model
.GetName() then
661 Pl
.SetModel(TmpModel
);
663 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
668 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
672 Pwd
:= M
.ReadString();
673 if not NetAllowRCON
then Exit
;
674 if Pwd
= NetRCONPassword
then
677 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
680 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
683 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
687 Cmd
:= M
.ReadString();
688 if not NetAllowRCON
then Exit
;
689 if not C
^.RCONAuth
then
691 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
694 g_Console_Process(Cmd
);
699 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
702 Name
, Command
: string;
706 Start
:= M
.ReadByte() <> 0;
707 Command
:= M
.ReadString();
709 Pl
:= g_Player_Get(C
^.Player
);
710 if Pl
= nil then Exit
;
715 if not g_Console_CommandBlacklisted(Command
) then
716 g_Game_StartVote(Command
, Name
);
718 else if gVoteInProgress
then
720 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
721 Need
:= Floor((NetClientCount
+1)/2.0) + 1
723 Need
:= Floor(NetClientCount
/2.0) + 1;
728 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
729 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
735 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
736 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
744 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
746 function sendItemRespawn (it
: PItem
): Boolean;
748 result
:= false; // don't stop
749 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
752 function sendMonSpawn (mon
: TMonster
): Boolean;
754 result
:= false; // don't stop
755 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
758 function sendPanelState (pan
: TPanel
): Boolean;
760 result
:= false; // don't stop
761 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
762 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
768 if (ID
>= 0) and (ID
< length(NetClients
)) then
770 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
771 MH_ProcessFirstSpawn(@NetClients
[ID
]);
774 if gPlayers
<> nil then
776 for I
:= Low(gPlayers
) to High(gPlayers
) do
778 if gPlayers
[I
] <> nil then
780 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
781 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
782 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
784 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
786 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
792 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
793 g_Mons_ForEach(sendMonSpawn
);
794 g_Map_ForEachPanel(sendPanelState
);
796 if gTriggers
<> nil then
798 for I
:= Low(gTriggers
) to High(gTriggers
) do
800 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
802 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
809 for I
:= Low(Shots
) to High(Shots
) do
811 if Shots
[i
].ShotType
in [6, 7, 8] then
813 MH_SEND_CreateShot(i
, ID
);
818 MH_SEND_TriggerMusic(ID
);
820 MH_SEND_GameStats(ID
);
821 MH_SEND_CoopStats(ID
);
823 if gGameSettings
.GameMode
= GM_CTF
then
825 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
826 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
829 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
834 procedure MH_SEND_Info(ID
: Byte);
838 NetOut
.Write(Byte(NET_MSG_INFO
));
840 NetOut
.Write(NetClients
[ID
].Player
);
841 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
842 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
843 NetOut
.Write(gWADHash
);
844 NetOut
.Write(gGameSettings
.GameMode
);
845 NetOut
.Write(gGameSettings
.GoalLimit
);
846 NetOut
.Write(gGameSettings
.TimeLimit
);
847 NetOut
.Write(gGameSettings
.MaxLives
);
848 NetOut
.Write(gGameSettings
.Options
);
851 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
854 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
860 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
861 Mode
:= NET_CHAT_PLAYER
;
864 if (Mode
= NET_CHAT_TEAM
) then
866 for i
:= Low(gPlayers
) to High(gPlayers
) do
867 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
868 (gPlayers
[i
].Team
= ID
) then
870 NetOut
.Write(Byte(NET_MSG_CHAT
));
873 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
880 NetOut
.Write(Byte(NET_MSG_CHAT
));
883 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
886 if Mode
= NET_CHAT_SYSTEM
then
889 if ID
= NET_EVERYONE
then
891 if Mode
= NET_CHAT_PLAYER
then
893 g_Console_Add(Txt
, True);
894 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
895 g_Game_ChatSound(b_Text_Unformat(Txt
));
898 if Mode
= NET_CHAT_TEAM
then
899 if gPlayer1
<> nil then
901 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
903 g_Console_Add(#18'[Team] '#2 + Txt
, True);
904 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
905 g_Game_ChatSound(b_Text_Unformat(Txt
));
907 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
909 g_Console_Add(#20'[Team] '#2 + Txt
, True);
910 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
911 g_Game_ChatSound(b_Text_Unformat(Txt
));
917 Name
:= g_Net_ClientName_ByID(ID
);
918 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
919 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
920 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
924 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
926 NetOut
.Write(Byte(NET_MSG_GFX
));
932 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
935 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
937 NetOut
.Write(Byte(NET_MSG_SND
));
941 NetOut
.Write(Byte(1));
946 NetOut
.Write(Byte(0));
948 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
951 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
953 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
955 NetOut
.Write(Byte(NET_MSG_SHADD
));
957 NetOut
.Write(Shots
[Proj
].ShotType
);
958 NetOut
.Write(Shots
[Proj
].Target
);
959 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
960 NetOut
.Write(Shots
[Proj
].Timeout
);
961 NetOut
.Write(Shots
[Proj
].Obj
.X
);
962 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
963 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
964 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
966 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
969 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
971 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
973 NetOut
.Write(Byte(NET_MSG_SHPOS
));
975 NetOut
.Write(Shots
[Proj
].Obj
.X
);
976 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
977 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
978 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
980 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
983 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
985 NetOut
.Write(Byte(NET_MSG_SHDEL
));
987 NetOut
.Write(Byte(Loud
));
991 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
994 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
996 NetOut
.Write(Byte(NET_MSG_SCORE
));
997 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
999 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1000 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1003 if gGameSettings
.GameMode
= GM_COOP
then
1005 NetOut
.Write(gCoopMonstersKilled
);
1006 NetOut
.Write(gCoopSecretsFound
);
1009 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1012 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1014 NetOut
.Write(Byte(NET_MSG_COOP
));
1015 NetOut
.Write(gTotalMonsters
);
1016 NetOut
.Write(gSecretsCount
);
1017 NetOut
.Write(gCoopTotalMonstersKilled
);
1018 NetOut
.Write(gCoopTotalSecretsFound
);
1019 NetOut
.Write(gCoopTotalMonsters
);
1020 NetOut
.Write(gCoopTotalSecrets
);
1023 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1025 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1026 NetOut
.Write(EvType
);
1027 NetOut
.Write(EvNum
);
1028 NetOut
.Write(EvStr
);
1029 NetOut
.Write(Byte(gLastMap
));
1030 NetOut
.Write(gTime
);
1031 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1033 NetOut
.Write(Byte(1));
1034 NetOut
.Write(gWADHash
);
1036 NetOut
.Write(Byte(0));
1038 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1041 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1043 NetOut
.Write(Byte(NET_MSG_FLAG
));
1044 NetOut
.Write(EvType
);
1046 NetOut
.Write(Byte(Quiet
));
1048 NetOut
.Write(gFlags
[Flag
].State
);
1049 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1050 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1051 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1052 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1053 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1055 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1058 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1060 NetOut
.Write(Byte(NET_MSG_GSET
));
1061 NetOut
.Write(gGameSettings
.GameMode
);
1062 NetOut
.Write(gGameSettings
.GoalLimit
);
1063 NetOut
.Write(gGameSettings
.TimeLimit
);
1064 NetOut
.Write(gGameSettings
.MaxLives
);
1065 NetOut
.Write(gGameSettings
.Options
);
1067 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1072 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1076 P
:= g_Player_Get(PID
);
1077 if P
= nil then Exit
;
1079 NetOut
.Write(Byte(NET_MSG_PLR
));
1081 NetOut
.Write(P
.Name
);
1083 NetOut
.Write(P
.FActualModelName
);
1084 NetOut
.Write(P
.FColor
.R
);
1085 NetOut
.Write(P
.FColor
.G
);
1086 NetOut
.Write(P
.FColor
.B
);
1087 NetOut
.Write(P
.Team
);
1089 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1092 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1097 Pl
:= g_Player_Get(PID
);
1098 if Pl
= nil then Exit
;
1099 if Pl
.FDummy
then Exit
;
1101 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1102 NetOut
.Write(gTime
);
1109 NetOut
.Write(FPing
);
1110 NetOut
.Write(FLoss
);
1111 if IsKeyPressed(KEY_CHAT
) then
1112 kByte
:= NET_KEY_CHAT
1115 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1116 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1117 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1118 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1119 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1122 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1124 NetOut
.Write(kByte
);
1125 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1126 NetOut
.Write(GameX
);
1127 NetOut
.Write(GameY
);
1128 NetOut
.Write(GameVelX
);
1129 NetOut
.Write(GameVelY
);
1130 NetOut
.Write(GameAccelX
);
1131 NetOut
.Write(GameAccelY
);
1134 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1137 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1142 P
:= g_Player_Get(PID
);
1143 if P
= nil then Exit
;
1145 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1150 NetOut
.Write(Byte(alive
));
1151 NetOut
.Write(Byte(GodMode
));
1152 NetOut
.Write(Health
);
1153 NetOut
.Write(Armor
);
1155 NetOut
.Write(JetFuel
);
1156 NetOut
.Write(Lives
);
1159 for I
:= WP_FIRST
to WP_LAST
do
1160 NetOut
.Write(Byte(FWeapon
[I
]));
1162 for I
:= A_BULLETS
to A_HIGH
do
1163 NetOut
.Write(FAmmo
[I
]);
1165 for I
:= A_BULLETS
to A_HIGH
do
1166 NetOut
.Write(FMaxAmmo
[I
]);
1168 for I
:= MR_SUIT
to MR_MAX
do
1169 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1171 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1172 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1173 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1174 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1175 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1177 NetOut
.Write(Frags
);
1178 NetOut
.Write(Death
);
1180 NetOut
.Write(CurrWeap
);
1182 NetOut
.Write(Byte(FSpectator
));
1183 NetOut
.Write(Byte(FGhost
));
1184 NetOut
.Write(Byte(FPhysics
));
1185 NetOut
.Write(Byte(FNoRespawn
));
1186 NetOut
.Write(Byte(FJetpack
));
1187 NetOut
.Write(FFireTime
);
1188 NetOut
.Write(Byte(FFlaming
));
1189 NetOut
.Write(FSpawnInvul
);
1192 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1195 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1197 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1200 NetOut
.Write(Attacker
);
1201 NetOut
.Write(Value
);
1205 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1208 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1210 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1212 NetOut
.Write(KillType
);
1213 NetOut
.Write(DeathType
);
1214 NetOut
.Write(Attacker
);
1216 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1219 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1221 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1223 NetOut
.Write(Weapon
);
1228 NetOut
.Write(ShotID
);
1230 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1233 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1235 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1238 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1241 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1245 Pl
:= g_Player_Get(PID
);
1246 if Pl
= nil then Exit
;
1248 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1250 NetOut
.Write(Pl
.Name
);
1252 NetOut
.Write(Pl
.Model
.GetName())
1255 NetOut
.Write(Pl
.FColor
.R
);
1256 NetOut
.Write(Pl
.FColor
.G
);
1257 NetOut
.Write(Pl
.FColor
.B
);
1258 NetOut
.Write(Pl
.Team
);
1260 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1265 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1270 it
:= g_Items_ByIdx(IID
);
1272 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1274 NetOut
.Write(Byte(Quiet
));
1276 if it
.dropped
then tt
:= tt
or $80;
1278 NetOut
.Write(Byte(it
.Fall
));
1279 NetOut
.Write(Byte(it
.Respawnable
));
1280 NetOut
.Write(it
.Obj
.X
);
1281 NetOut
.Write(it
.Obj
.Y
);
1282 NetOut
.Write(it
.Obj
.Vel
.X
);
1283 NetOut
.Write(it
.Obj
.Vel
.Y
);
1285 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1288 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1290 NetOut
.Write(Byte(NET_MSG_IDEL
));
1292 NetOut
.Write(Byte(Quiet
));
1294 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1299 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1303 TP
:= g_Map_PanelByGUID(PGUID
);
1304 if (TP
= nil) then exit
;
1308 NetOut
.Write(Byte(NET_MSG_PTEX
));
1309 NetOut
.Write(LongWord(PGUID
));
1310 NetOut
.Write(FCurTexture
);
1311 NetOut
.Write(FCurFrame
);
1312 NetOut
.Write(FCurFrameCount
);
1313 NetOut
.Write(AnimLoop
);
1316 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1319 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1324 TP
:= g_Map_PanelByGUID(PGUID
);
1325 if (TP
= nil) then exit
;
1327 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1328 NetOut
.Write(LongWord(PGUID
));
1329 NetOut
.Write(Byte(TP
.Enabled
));
1330 NetOut
.Write(TP
.LiftType
);
1333 NetOut
.Write(Word(TP
.Width
));
1334 NetOut
.Write(Word(TP
.Height
));
1336 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1337 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1338 NetOut
.Write(LongInt(TP
.movingStartX
));
1339 NetOut
.Write(LongInt(TP
.movingStartY
));
1340 NetOut
.Write(LongInt(TP
.movingEndX
));
1341 NetOut
.Write(LongInt(TP
.movingEndY
));
1342 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1343 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1344 NetOut
.Write(LongInt(TP
.sizeEndX
));
1345 NetOut
.Write(LongInt(TP
.sizeEndY
));
1346 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1347 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1348 NetOut
.Write(Byte(mpflags
));
1350 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1355 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1357 if gTriggers
= nil then Exit
;
1358 if T
.Sound
= nil then Exit
;
1360 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1361 NetOut
.Write(T
.ClientID
);
1362 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1363 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1364 NetOut
.Write(T
.SoundPlayCount
);
1366 g_Net_Host_Send(ID
, True);
1369 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1371 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1372 NetOut
.Write(gMusic
.Name
);
1373 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1374 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1375 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1377 g_Net_Host_Send(ID
, True);
1382 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1386 M
:= g_Monsters_ByUID(UID
);
1392 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1394 NetOut
.Write(MonsterType
);
1395 NetOut
.Write(MonsterState
);
1396 NetOut
.Write(MonsterAnim
);
1397 NetOut
.Write(MonsterTargetUID
);
1398 NetOut
.Write(MonsterTargetTime
);
1399 NetOut
.Write(MonsterBehaviour
);
1400 NetOut
.Write(MonsterSleep
);
1401 NetOut
.Write(MonsterHealth
);
1402 NetOut
.Write(MonsterAmmo
);
1403 NetOut
.Write(GameX
);
1404 NetOut
.Write(GameY
);
1405 NetOut
.Write(GameVelX
);
1406 NetOut
.Write(GameVelY
);
1407 NetOut
.Write(Byte(GameDirection
));
1410 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1413 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1417 M
:= g_Monsters_ByUID(UID
);
1418 if M
= nil then Exit
;
1420 NetOut
.Write(Byte(NET_MSG_MPOS
));
1425 NetOut
.Write(GameX
);
1426 NetOut
.Write(GameY
);
1427 NetOut
.Write(GameVelX
);
1428 NetOut
.Write(GameVelY
);
1429 NetOut
.Write(Byte(GameDirection
));
1432 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1435 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1439 M
:= g_Monsters_ByUID(UID
);
1440 if M
= nil then Exit
;
1442 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1447 NetOut
.Write(MonsterState
);
1448 NetOut
.Write(ForcedAnim
);
1449 NetOut
.Write(MonsterTargetUID
);
1450 NetOut
.Write(MonsterTargetTime
);
1451 NetOut
.Write(MonsterSleep
);
1452 NetOut
.Write(MonsterHealth
);
1453 NetOut
.Write(MonsterAmmo
);
1454 NetOut
.Write(MonsterPain
);
1455 NetOut
.Write(Byte(AnimIsReverse
));
1456 NetOut
.Write(FFireTime
);
1459 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1462 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1464 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1471 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1474 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1478 M
:= g_Monsters_ByUID(UID
);
1479 if M
= nil then Exit
;
1481 NetOut
.Write(Byte(NET_MSG_MDEL
));
1484 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1489 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1491 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1494 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1497 procedure MH_SEND_VoteEvent(EvType
: Byte;
1498 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1499 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1500 ID
: Integer = NET_EVERYONE
);
1502 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1503 NetOut
.Write(EvType
);
1504 NetOut
.Write(IntArg1
);
1505 NetOut
.Write(IntArg2
);
1506 NetOut
.Write(StrArg1
);
1507 NetOut
.Write(StrArg2
);
1509 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1512 // CLIENT MESSAGES //
1516 procedure MC_RECV_Chat(var M
: TMsg
);
1521 Txt
:= M
.ReadString();
1522 Mode
:= M
.ReadByte();
1524 if Mode
<> NET_CHAT_SYSTEM
then
1526 if NetDeafLevel
= 0 then
1528 if Mode
= NET_CHAT_PLAYER
then
1530 g_Console_Add(Txt
, True);
1531 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1532 g_Game_ChatSound(b_Text_Unformat(Txt
));
1534 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1536 if gPlayer1
.Team
= TEAM_RED
then
1537 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1538 if gPlayer1
.Team
= TEAM_BLUE
then
1539 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1540 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1541 g_Game_ChatSound(b_Text_Unformat(Txt
));
1544 end else if (NetDeafLevel
< 2) then
1545 g_Console_Add(Txt
, True);
1548 procedure MC_RECV_Effect(var M
: TMsg
);
1554 if not gGameOn
then Exit
;
1555 Kind
:= M
.ReadByte();
1556 X
:= M
.ReadLongInt();
1557 Y
:= M
.ReadLongInt();
1558 Ang
:= M
.ReadSmallInt();
1564 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1570 g_GFX_QueueEffect(R_GFX_TELEPORT_FAST
, X
, Y
);
1573 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1578 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, X
- 64, Y
- 64);
1581 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1586 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, X
- 64, Y
- 64);
1589 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1594 g_GFX_QueueEffect(R_GFX_BFG_HIT
, X
- 32, Y
- 32);
1600 g_GFX_QueueEffect(R_GFX_FIRE
, X
, Y
);
1603 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1608 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
, Y
);
1611 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1615 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1619 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1623 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1624 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1629 procedure MC_RECV_Sound(var M
: TMsg
);
1635 Name
:= M
.ReadString();
1636 Pos
:= M
.ReadByte() <> 0;
1639 X
:= M
.ReadLongInt();
1640 Y
:= M
.ReadLongInt();
1641 g_Sound_PlayExAt(Name
, X
, Y
);
1644 g_Sound_PlayEx(Name
);
1647 procedure MC_RECV_CreateShot(var M
: TMsg
);
1649 I
, X
, Y
, XV
, YV
: Integer;
1651 Target
, Spawner
: Word;
1654 I
:= M
.ReadLongInt();
1655 ShType
:= M
.ReadByte();
1656 Target
:= M
.ReadWord();
1657 Spawner
:= M
.ReadWord();
1658 Timeout
:= M
.ReadLongWord();
1659 X
:= M
.ReadLongInt();
1660 Y
:= M
.ReadLongInt();
1661 XV
:= M
.ReadLongInt();
1662 YV
:= M
.ReadLongInt();
1664 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1665 if (Shots
<> nil) and (I
<= High(Shots
)) then
1667 Shots
[I
].Timeout
:= Timeout
;
1668 //Shots[I].Target := Target; // TODO: find a use for Target later
1672 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1674 I
, TX
, TY
, TXV
, TYV
: Integer;
1676 I
:= M
.ReadLongInt();
1677 TX
:= M
.ReadLongInt();
1678 TY
:= M
.ReadLongInt();
1679 TXV
:= M
.ReadLongInt();
1680 TYV
:= M
.ReadLongInt();
1682 if (Shots
<> nil) and (I
<= High(Shots
)) then
1692 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1697 if not gGameOn
then Exit
;
1698 I
:= M
.ReadLongInt();
1699 L
:= (M
.ReadByte() <> 0);
1700 X
:= M
.ReadLongInt();
1701 Y
:= M
.ReadLongInt();
1703 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1706 procedure MC_RECV_GameStats(var M
: TMsg
);
1708 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1710 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1711 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1714 if gGameSettings
.GameMode
= GM_COOP
then
1716 gCoopMonstersKilled
:= M
.ReadWord();
1717 gCoopSecretsFound
:= M
.ReadWord();
1721 procedure MC_RECV_CoopStats(var M
: TMsg
);
1723 gTotalMonsters
:= M
.ReadLongInt();
1724 gSecretsCount
:= M
.ReadLongInt();
1725 gCoopTotalMonstersKilled
:= M
.ReadWord();
1726 gCoopTotalSecretsFound
:= M
.ReadWord();
1727 gCoopTotalMonsters
:= M
.ReadWord();
1728 gCoopTotalSecrets
:= M
.ReadWord();
1731 procedure MC_RECV_GameEvent(var M
: TMsg
);
1740 i1
, i2
: TStrings_Locale
;
1743 goodCmd
: Boolean = true;
1745 FillChar(EvHash
, Sizeof(EvHash
), 0);
1746 EvType
:= M
.ReadByte();
1747 EvNum
:= M
.ReadLongInt();
1748 EvStr
:= M
.ReadString();
1749 gLastMap
:= M
.ReadByte() <> 0;
1750 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1751 gStatsPressed
:= True;
1752 EvTime
:= M
.ReadLongWord();
1753 BHash
:= M
.ReadByte() <> 0;
1755 EvHash
:= M
.ReadMD5();
1759 if (g_Res_received_map_start
<> 0) then
1761 if (g_Res_received_map_start
< 0) then exit
;
1764 NET_EV_MAPSTART
: goodCmd
:= true;
1765 NET_EV_MAPEND
: goodCmd
:= true;
1766 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1767 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1768 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1770 if not goodCmd
then exit
;
1776 if (g_Res_received_map_start
<> 0) then
1778 g_Res_received_map_start
:= -1;
1783 g_Game_ClearLoading();
1784 g_Game_StopAllSounds(True);
1786 gSwitchGameMode
:= Byte(EvNum
);
1787 gGameSettings
.GameMode
:= gSwitchGameMode
;
1790 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1792 if not isWadPath(EvStr
) then
1793 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1795 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1799 MC_SEND_FullStateRequest
;
1805 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1806 gLMSRespawnTime
:= 0;
1807 if (g_Res_received_map_start
<> 0) then
1809 g_Res_received_map_start
:= -1;
1813 gMissionFailed
:= EvNum
<> 0;
1814 gExit
:= EXIT_ENDLEVELCUSTOM
;
1822 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1824 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1826 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1832 if NetDeafLevel
< 2 then
1834 if EvNum
= TEAM_RED
then
1835 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1836 if EvNum
= TEAM_BLUE
then
1837 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1843 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1844 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1849 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1850 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1857 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
1858 gLMSRespawnTime
:= gTime
+ EvNum
;
1859 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
1861 else if gPlayer1
= nil then
1863 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1867 NET_EV_LMS_SURVIVOR
:
1868 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1871 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1875 pl
:= g_Player_Get(EvNum
and $FFFF);
1880 cnt
:= (EvNum
shr 16) and $FF;
1881 if Pos('w', EvStr
) = 0 then
1884 if Pos('t', EvStr
) = 0 then
1887 if Pos('-', EvStr
) = 0 then
1889 if Pos('e', EvStr
) = 0 then
1890 i1
:= I_PLAYER_SCORE_ADD_OWN
1892 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1895 if Pos('e', EvStr
) = 0 then
1896 i1
:= I_PLAYER_SCORE_SUB_OWN
1898 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1901 if Pos('r', EvStr
) > 0 then
1902 i2
:= I_PLAYER_SCORE_TO_RED
1904 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1905 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1909 if Pos('-', EvStr
) = 0 then
1910 i1
:= I_PLAYER_SCORE_ADD_TEAM
1912 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1914 if Pos('r', EvStr
) > 0 then
1915 i2
:= I_PLAYER_SCORE_RED
1917 i2
:= I_PLAYER_SCORE_BLUE
;
1918 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1923 if Pos('e', EvStr
) = 0 then
1924 i1
:= I_PLAYER_SCORE_WIN_OWN
1926 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1928 if Pos('r', EvStr
) > 0 then
1929 i2
:= I_PLAYER_SCORE_TO_RED
1931 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1932 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1938 if EvNum
= TEAM_RED
then
1939 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1940 if EvNum
= TEAM_BLUE
then
1941 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1942 if EvNum
= -TEAM_RED
then
1943 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1944 if EvNum
= -TEAM_BLUE
then
1945 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1950 g_Player_RemoveAllCorpses
;
1951 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1952 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1956 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1960 if EvNum
= TEAM_RED
then
1961 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1962 if EvNum
= TEAM_BLUE
then
1963 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1967 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1970 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1973 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1976 g_Game_Announce_KillCombo(EvNum
);
1978 NET_EV_PLAYER_TOUCH
:
1980 pl
:= g_Player_Get(EvNum
);
1987 pl
:= g_Player_Get(EvNum
);
1990 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
1991 g_Sound_PlayEx('SOUND_GAME_SECRET');
1997 pl
:= g_Player_Get(EvNum
);
1998 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2003 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2012 EvType
:= M
.ReadByte();
2015 if Fl
= FLAG_NONE
then Exit
;
2017 Quiet
:= (M
.ReadByte() <> 0);
2018 PID
:= M
.ReadWord();
2020 gFlags
[Fl
].State
:= M
.ReadByte();
2021 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2022 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2023 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2024 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2025 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2027 Pl
:= g_Player_Get(PID
);
2029 (EvType
<> FLAG_STATE_NORMAL
) and
2030 (EvType
<> FLAG_STATE_DROPPED
) and
2031 (EvType
<> FLAG_STATE_RETURNED
) then
2037 if Quiet
or (Pl
= nil) then Exit
;
2039 if Fl
= FLAG_RED
then
2040 s
:= _lc
[I_PLAYER_FLAG_RED
]
2042 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2044 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2046 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2047 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2048 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2053 if not sound_ret_flag
[a
].IsPlaying() then
2054 sound_ret_flag
[a
].Play();
2057 FLAG_STATE_CAPTURED
:
2059 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2063 if Fl
= FLAG_RED
then
2064 s
:= _lc
[I_PLAYER_FLAG_RED
]
2066 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2068 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2069 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2071 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2072 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2073 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2078 if not sound_get_flag
[a
].IsPlaying() then
2079 sound_get_flag
[a
].Play();
2084 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2086 if Quiet
or (Pl
= nil) then Exit
;
2088 if Fl
= FLAG_RED
then
2089 s
:= _lc
[I_PLAYER_FLAG_RED
]
2091 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2093 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2094 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2096 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2097 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2098 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2103 if not sound_lost_flag
[a
].IsPlaying() then
2104 sound_lost_flag
[a
].Play();
2109 g_Map_ResetFlag(FLAG_RED
);
2110 g_Map_ResetFlag(FLAG_BLUE
);
2111 if Quiet
or (Pl
= nil) then Exit
;
2112 Pl
.SetFlag(FLAG_NONE
);
2114 if Fl
= FLAG_RED
then
2115 s
:= _lc
[I_PLAYER_FLAG_RED
]
2117 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2119 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2120 Insert('.', ts
, Length(ts
) + 1 - 3);
2121 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2122 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2124 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2125 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2126 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2131 if not sound_cap_flag
[a
].IsPlaying() then
2132 sound_cap_flag
[a
].Play();
2135 FLAG_STATE_RETURNED
:
2137 g_Map_ResetFlag(Fl
);
2140 if Fl
= FLAG_RED
then
2141 s
:= _lc
[I_PLAYER_FLAG_RED
]
2143 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2145 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2147 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2148 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2149 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2154 if not sound_ret_flag
[a
].IsPlaying() then
2155 sound_ret_flag
[a
].Play();
2160 procedure MC_RECV_GameSettings(var M
: TMsg
);
2162 gGameSettings
.GameMode
:= M
.ReadByte();
2163 gGameSettings
.GoalLimit
:= M
.ReadWord();
2164 gGameSettings
.TimeLimit
:= M
.ReadWord();
2165 gGameSettings
.MaxLives
:= M
.ReadByte();
2166 gGameSettings
.Options
:= M
.ReadLongWord();
2171 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2174 PName
, Model
: string;
2179 PID
:= M
.ReadWord();
2180 Pl
:= g_Player_Get(PID
);
2182 PName
:= M
.ReadString();
2183 Model
:= M
.ReadString();
2184 Color
.R
:= M
.ReadByte();
2185 Color
.G
:= M
.ReadByte();
2186 Color
.B
:= M
.ReadByte();
2190 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2192 if (Pl
<> nil) then Exit
;
2193 DID
:= g_Player_Create(Model
, Color
, T
, False);
2194 with g_Player_Get(DID
) do
2203 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2204 gPlayer1
.UID
:= PID
;
2205 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2206 gPlayer1
.ChangeTeam(T
);
2208 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2209 gPlayer2
.UID
:= PID
;
2210 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2211 gPlayer2
.ChangeTeam(T
);
2215 if NetDeafLevel
< 3 then
2216 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2217 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2221 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2228 TmpX
, TmpY
: Integer;
2232 GT
:= M
.ReadLongWord();
2233 if GT
< gTime
- NET_MAX_DIFFTIME
then
2240 PID
:= M
.ReadWord();
2241 Pl
:= g_Player_Get(PID
);
2243 if Pl
= nil then Exit
;
2249 FPing
:= M
.ReadWord();
2250 FLoss
:= M
.ReadByte();
2251 kByte
:= M
.ReadWord();
2252 Dir
:= M
.ReadByte();
2254 TmpX
:= M
.ReadLongInt();
2255 TmpY
:= M
.ReadLongInt();
2259 if LongBool(kByte
and NET_KEY_CHAT
) then
2260 PressKey(KEY_CHAT
, 10000)
2263 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2264 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2265 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2266 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2267 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2270 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2272 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2273 SetDirection(TDirection(Dir
));
2275 GameVelX
:= M
.ReadLongInt();
2276 GameVelY
:= M
.ReadLongInt();
2277 GameAccelX
:= M
.ReadLongInt();
2278 GameAccelY
:= M
.ReadLongInt();
2279 SetLerp(TmpX
, TmpY
);
2280 if NetForcePlayerUpdate
then Update();
2284 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2288 I
, OldFire
: Integer;
2289 OldJet
, Flam
: Boolean;
2292 PID
:= M
.ReadWord();
2293 Pl
:= g_Player_Get(PID
);
2300 alive
:= (M
.ReadByte() <> 0);
2301 GodMode
:= (M
.ReadByte() <> 0);
2302 Health
:= M
.ReadLongInt();
2303 Armor
:= M
.ReadLongInt();
2304 Air
:= M
.ReadLongInt();
2305 JetFuel
:= M
.ReadLongInt();
2306 Lives
:= M
.ReadByte();
2307 NewTeam
:= M
.ReadByte();
2309 for I
:= WP_FIRST
to WP_LAST
do
2310 FWeapon
[I
] := (M
.ReadByte() <> 0);
2312 for I
:= A_BULLETS
to A_HIGH
do
2313 FAmmo
[I
] := M
.ReadWord();
2315 for I
:= A_BULLETS
to A_HIGH
do
2316 FMaxAmmo
[I
] := M
.ReadWord();
2318 for I
:= MR_SUIT
to MR_MAX
do
2319 FMegaRulez
[I
] := M
.ReadLongWord();
2322 if (M
.ReadByte() <> 0) then
2323 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2324 if (M
.ReadByte() <> 0) then
2325 FRulez
:= FRulez
+ [R_KEY_RED
];
2326 if (M
.ReadByte() <> 0) then
2327 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2328 if (M
.ReadByte() <> 0) then
2329 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2330 if (M
.ReadByte() <> 0) then
2331 FRulez
:= FRulez
+ [R_BERSERK
];
2333 Frags
:= M
.ReadLongInt();
2334 Death
:= M
.ReadLongInt();
2336 SetWeapon(M
.ReadByte());
2338 FSpectator
:= M
.ReadByte() <> 0;
2341 if UID
= NetPlrUID1
then
2343 gSpectLatchPID1
:= UID
;
2346 if UID
= NetPlrUID2
then
2348 gSpectLatchPID2
:= UID
;
2354 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2357 gSpectLatchPID1
:= 0;
2359 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2362 gSpectLatchPID2
:= 0;
2365 FGhost
:= M
.ReadByte() <> 0;
2366 FPhysics
:= M
.ReadByte() <> 0;
2367 FNoRespawn
:= M
.ReadByte() <> 0;
2369 FJetpack
:= M
.ReadByte() <> 0;
2370 OldFire
:= FFireTime
;
2371 FFireTime
:= M
.ReadLongInt();
2372 if (OldFire
<= 0) and (FFireTime
> 0) then
2373 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2374 Flam
:= M
.ReadByte() <> 0;
2375 FSpawnInvul
:= M
.ReadLongInt();
2376 if OldJet
and not FJetpack
then
2378 else if not OldJet
and FJetpack
then
2380 if FFlaming
and not Flam
then
2382 if Team
<> NewTeam
then
2383 Pl
.ChangeTeam(NewTeam
);
2389 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2394 Attacker
, Value
: Word;
2398 if not gGameOn
then Exit
;
2399 PID
:= M
.ReadWord();
2400 Pl
:= g_Player_Get(PID
);
2401 if Pl
= nil then Exit
;
2403 Kind
:= M
.ReadByte();
2404 Attacker
:= M
.ReadWord();
2405 Value
:= M
.ReadWord();
2410 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2415 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2419 KillType
, DeathType
: Byte;
2423 if not gGameOn
then Exit
;
2424 PID
:= M
.ReadWord();
2425 Pl
:= g_Player_Get(PID
);
2426 if Pl
= nil then Exit
;
2428 KillType
:= M
.ReadByte();
2429 DeathType
:= M
.ReadByte();
2430 Attacker
:= M
.ReadWord();
2434 Kill(KillType
, Attacker
, DeathType
);
2439 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2444 PID
:= M
.ReadWord();
2445 Pl
:= g_Player_Get(PID
);
2447 if Pl
= nil then Exit
;
2449 if NetDeafLevel
< 3 then
2450 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2451 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2453 g_Player_Remove(PID
);
2458 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2463 X
, Y
, AX
, AY
: Integer;
2467 if not gGameOn
then Exit
;
2468 PID
:= M
.ReadWord();
2469 Pl
:= g_Player_Get(PID
);
2470 if Pl
= nil then Exit
;
2472 Weap
:= M
.ReadByte();
2473 X
:= M
.ReadLongInt();
2474 Y
:= M
.ReadLongInt();
2475 AX
:= M
.ReadLongInt();
2476 AY
:= M
.ReadLongInt();
2477 SHID
:= M
.ReadLongInt();
2480 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2483 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2492 PID
:= M
.ReadWord();
2493 Pl
:= g_Player_Get(PID
);
2494 if Pl
= nil then Exit
;
2496 TmpName
:= M
.ReadString();
2497 TmpModel
:= M
.ReadString();
2498 TmpColor
.R
:= M
.ReadByte();
2499 TmpColor
.G
:= M
.ReadByte();
2500 TmpColor
.B
:= M
.ReadByte();
2501 TmpTeam
:= M
.ReadByte();
2503 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2505 Pl
.ChangeTeam(TmpTeam
);
2506 if gPlayer1
= Pl
then
2507 gPlayer1Settings
.Team
:= TmpTeam
;
2508 if gPlayer2
= Pl
then
2509 gPlayer2Settings
.Team
:= TmpTeam
;
2511 Pl
.SetColor(TmpColor
);
2513 if Pl
.Name
<> TmpName
then
2515 if NetDeafLevel
< 3 then
2516 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2520 if TmpModel
<> Pl
.Model
.GetName() then
2521 Pl
.SetModel(TmpModel
);
2526 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2529 X
, Y
, VX
, VY
: Integer;
2531 Quiet
, Fall
{, Resp}: Boolean;
2534 if not gGameOn
then Exit
;
2536 Quiet
:= M
.ReadByte() <> 0;
2538 Fall
:= M
.ReadByte() <> 0;
2539 {Resp :=} M
.ReadByte();
2540 X
:= M
.ReadLongInt();
2541 Y
:= M
.ReadLongInt();
2542 VX
:= M
.ReadLongInt();
2543 VY
:= M
.ReadLongInt();
2545 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2546 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2548 it
:= g_Items_ByIdx(ID
);
2554 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2556 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16);
2561 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2566 if not gGameOn
then Exit
;
2568 Quiet
:= M
.ReadByte() <> 0;
2570 if not g_Items_ValidId(ID
) then exit
;
2572 if not Quiet
then g_Items_EmitPickupSound(ID
);
2579 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2586 if not gGameOn
then Exit
;
2588 PGUID
:= Integer(M
.ReadLongWord());
2589 Tex
:= M
.ReadLongInt();
2590 Fr
:= M
.ReadLongInt();
2591 Cnt
:= M
.ReadByte();
2592 Loop
:= M
.ReadByte();
2594 TP
:= g_Map_PanelByGUID(PGUID
);
2598 TP
.SetTexture(Tex
, Loop
);
2599 TP
.SetFrame(Fr
, Cnt
);
2603 procedure MC_RECV_PanelState(var M
: TMsg
);
2608 X
, Y
, W
, H
: Integer;
2610 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2611 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2614 if not gGameOn
then Exit
;
2616 PGUID
:= Integer(M
.ReadLongWord());
2617 E
:= (M
.ReadByte() <> 0);
2618 Lift
:= M
.ReadByte();
2619 X
:= M
.ReadLongInt();
2620 Y
:= M
.ReadLongInt();
2624 speedX
:= M
.ReadLongInt();
2625 speedY
:= M
.ReadLongInt();
2626 startX
:= M
.ReadLongInt();
2627 startY
:= M
.ReadLongInt();
2628 endX
:= M
.ReadLongInt();
2629 endY
:= M
.ReadLongInt();
2630 sizeSpX
:= M
.ReadLongInt();
2631 sizeSpY
:= M
.ReadLongInt();
2632 sizeEX
:= M
.ReadLongInt();
2633 sizeEY
:= M
.ReadLongInt();
2634 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2636 TP
:= g_Map_PanelByGUID(PGUID
);
2637 if (TP
= nil) then exit
;
2639 // update lifts state
2640 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2642 // update enabled/disabled state for all panels
2643 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2645 // update panel position, as it can be moved (mplat)
2650 // update mplat state
2651 TP
.movingSpeedX
:= speedX
;
2652 TP
.movingSpeedY
:= speedY
;
2653 TP
.movingStartX
:= startX
;
2654 TP
.movingStartY
:= startY
;
2655 TP
.movingEndX
:= endX
;
2656 TP
.movingEndY
:= endY
;
2657 TP
.sizeSpeedX
:= sizeSpX
;
2658 TP
.sizeSpeedY
:= sizeSpY
;
2659 TP
.sizeEndX
:= sizeEX
;
2660 TP
.sizeEndY
:= sizeEY
;
2661 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2662 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2663 // notify panel of it's position/size change, so it can fix other internal structures
2664 TP
.positionChanged();
2669 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2672 SPos
, SID
: LongWord;
2676 if not gGameOn
then Exit
;
2677 if gTriggers
= nil then Exit
;
2679 SID
:= M
.ReadLongWord();
2680 SPlaying
:= M
.ReadByte() <> 0;
2681 SPos
:= M
.ReadLongWord();
2682 SCount
:= M
.ReadLongInt();
2684 for I
:= Low(gTriggers
) to High(gTriggers
) do
2685 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2686 if gTriggers
[I
].ClientID
= SID
then
2687 with gTriggers
[I
] do
2689 if Sound
<> nil then
2694 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2696 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2697 Sound
.SetPosition(SPos
);
2700 if Sound
.IsPlaying
then Sound
.Stop
;
2703 SoundPlayCount
:= SCount
;
2707 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2714 if not gGameOn
then Exit
;
2716 MName
:= M
.ReadString();
2717 MPlaying
:= M
.ReadByte() <> 0;
2718 MPos
:= M
.ReadLongWord();
2719 MPaused
:= M
.ReadByte() <> 0;
2720 MPos
:= MPos
+1; //k8: stfu, fpc!
2724 gMusic
.SetByName(MName
);
2726 // gMusic.SetPosition(MPos);
2727 gMusic
.SpecPause
:= MPaused
;
2730 if gMusic
.IsPlaying
then gMusic
.Stop
;
2735 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2738 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2739 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2744 Mon
:= g_Monsters_ByUID(ID
);
2748 MType
:= M
.ReadByte();
2749 MState
:= M
.ReadByte();
2750 MAnim
:= M
.ReadByte();
2751 MTarg
:= M
.ReadWord();
2752 MTargTime
:= M
.ReadLongInt();
2753 MBehav
:= M
.ReadByte();
2754 MSleep
:= M
.ReadLongInt();
2755 MHealth
:= M
.ReadLongInt();
2756 MAmmo
:= M
.ReadLongInt();
2758 X
:= M
.ReadLongInt();
2759 Y
:= M
.ReadLongInt();
2760 VX
:= M
.ReadLongInt();
2761 VY
:= M
.ReadLongInt();
2762 MDir
:= M
.ReadByte();
2764 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2765 Mon
:= g_Monsters_ByUID(ID
);
2772 MonsterAnim
:= MAnim
;
2773 MonsterTargetUID
:= MTarg
;
2774 MonsterTargetTime
:= MTargTime
;
2775 MonsterBehaviour
:= MBehav
;
2776 MonsterSleep
:= MSleep
;
2777 MonsterAmmo
:= MAmmo
;
2782 setPosition(X
, Y
); // this will call positionChanged();
2788 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2795 Mon
:= g_Monsters_ByUID(ID
);
2801 X
:= M
.ReadLongInt();
2802 Y
:= M
.ReadLongInt();
2803 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2804 GameVelX
:= M
.ReadLongInt();
2805 GameVelY
:= M
.ReadLongInt();
2806 GameDirection
:= TDirection(M
.ReadByte());
2810 procedure MC_RECV_MonsterState(var M
: TMsg
);
2812 ID
, OldFire
: Integer;
2813 MState
, MFAnm
: Byte;
2815 AnimRevert
: Boolean;
2818 Mon
:= g_Monsters_ByUID(ID
);
2819 if Mon
= nil then Exit
;
2821 MState
:= M
.ReadByte();
2822 MFAnm
:= M
.ReadByte();
2826 MonsterTargetUID
:= M
.ReadWord();
2827 MonsterTargetTime
:= M
.ReadLongInt();
2828 MonsterSleep
:= M
.ReadLongInt();
2829 MonsterHealth
:= M
.ReadLongInt();
2830 MonsterAmmo
:= M
.ReadLongInt();
2831 MonsterPain
:= M
.ReadLongInt();
2832 AnimRevert
:= M
.ReadByte() <> 0;
2833 OldFire
:= FFireTime
;
2834 FFireTime
:= M
.ReadLongInt();
2835 if (OldFire
<= 0) and (FFireTime
> 0) then
2836 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2837 RevertAnim(AnimRevert
);
2839 if MonsterState
<> MState
then
2841 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2842 if (MState
= MONSTATE_DIE
) then DieSound();
2843 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2844 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2845 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2847 SetState(MState
, MFAnm
);
2852 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2856 X
, Y
, VX
, VY
: Integer;
2860 Mon
:= g_Monsters_ByUID(ID
);
2861 if Mon
= nil then Exit
;
2863 X
:= M
.ReadLongInt();
2864 Y
:= M
.ReadLongInt();
2865 VX
:= M
.ReadLongInt();
2866 VY
:= M
.ReadLongInt();
2868 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2871 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2877 Mon
:= g_Monsters_ByUID(ID
);
2878 if Mon
= nil then Exit
;
2880 Mon
.MonsterRemoved
:= True;
2883 procedure MC_RECV_TimeSync(var M
: TMsg
);
2887 Time
:= M
.ReadLongWord();
2889 if gState
= STATE_INTERCUSTOM
then
2890 gServInterTime
:= Min(Time
, 255);
2893 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2897 Int1
, Int2
: SmallInt;
2899 EvID
:= M
.ReadByte();
2900 Int1
:= M
.ReadSmallInt();
2901 Int2
:= M
.ReadSmallInt();
2902 Str1
:= M
.ReadString();
2903 Str2
:= M
.ReadString();
2905 if NetDeafLevel
< 2 then
2908 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2910 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2912 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2914 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2916 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2922 procedure MC_SEND_Info(Password
: string);
2926 NetOut
.Write(Byte(NET_MSG_INFO
));
2927 NetOut
.Write(GAME_VERSION
);
2928 NetOut
.Write(Password
);
2929 NetOut
.Write(gPlayer1Settings
.Name
);
2930 NetOut
.Write(gPlayer1Settings
.Model
);
2931 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2932 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2933 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2934 NetOut
.Write(gPlayer1Settings
.Team
);
2936 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2939 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2941 NetOut
.Write(Byte(NET_MSG_CHAT
));
2945 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2948 procedure MC_SEND_PlayerPos();
2953 WeaponSelect
: Word = 0;
2956 if not gGameOn
then Exit
;
2957 if gPlayers
= nil then Exit
;
2958 if gPlayer1
= nil then Exit
;
2961 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2963 {$IFDEF DISABLE_MENU}
2964 if (not gConsoleShow
) and (not gChatShow
) then
2966 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2969 strafeDir
:= P1MoveButton
shr 4;
2970 P1MoveButton
:= P1MoveButton
and $0F;
2972 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2974 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2976 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2980 if gPlayerAction
[0, ACTION_STRAFE
] then
2982 // new strafe mechanics
2983 if (strafeDir
= 0) then
2984 strafeDir
:= P1MoveButton
; // start strafing
2985 // now set direction according to strafe (reversed)
2986 if (strafeDir
= 2) then
2987 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2988 else if (strafeDir
= 1) then
2989 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2993 strafeDir
:= 0; // not strafing anymore
2994 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
2995 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2996 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2997 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2998 else if P1MoveButton
<> 0 then
2999 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3002 gPlayer1
.ReleaseKeys
;
3003 if P1MoveButton
= 1 then
3005 kByte
:= kByte
or NET_KEY_LEFT
;
3006 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3008 if P1MoveButton
= 2 then
3010 kByte
:= kByte
or NET_KEY_RIGHT
;
3011 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3013 if gPlayerAction
[0, ACTION_LOOKUP
] then
3015 kByte
:= kByte
or NET_KEY_UP
;
3016 gPlayer1
.PressKey(KEY_UP
, 10000);
3018 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3020 kByte
:= kByte
or NET_KEY_DOWN
;
3021 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3023 if gPlayerAction
[0, ACTION_JUMP
] then
3025 kByte
:= kByte
or NET_KEY_JUMP
;
3026 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3028 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3029 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3030 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
3031 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
3033 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3034 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3036 for i
:= WP_FIRST
to WP_LAST
do
3038 if gSelectWeapon
[0, i
] then
3040 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3041 gSelectWeapon
[0, i
] := False
3045 // fix movebutton state
3046 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3049 kByte
:= NET_KEY_CHAT
;
3051 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3052 NetOut
.Write(gTime
);
3053 NetOut
.Write(kByte
);
3054 NetOut
.Write(Byte(gPlayer1
.Direction
));
3055 NetOut
.Write(WeaponSelect
);
3056 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3057 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3059 //kBytePrev := kByte;
3060 //kDirPrev := gPlayer1.Direction;
3063 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3065 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3066 NetOut
.Write(Byte(Start
));
3067 NetOut
.Write(Command
);
3068 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3071 procedure MC_SEND_PlayerSettings();
3073 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3074 NetOut
.Write(gPlayer1Settings
.Name
);
3075 NetOut
.Write(gPlayer1Settings
.Model
);
3076 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3077 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3078 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3079 NetOut
.Write(gPlayer1Settings
.Team
);
3081 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3084 procedure MC_SEND_FullStateRequest();
3086 NetOut
.Write(Byte(NET_MSG_REQFST
));
3088 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3091 procedure MC_SEND_CheatRequest(Kind
: Byte);
3093 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3096 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3098 procedure MC_SEND_RCONPassword(Password
: string);
3100 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3101 NetOut
.Write(Password
);
3103 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3105 procedure MC_SEND_RCONCommand(Cmd
: string);
3107 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3110 g_Net_Client_Send(True, NET_CHAN_SERVICE
);