1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
20 uses e_msg
, g_net
, g_triggers
, Classes
, SysUtils
, md5
;
64 NET_MSG_RCON_AUTH
= 191;
65 NET_MSG_RCON_CMD
= 192;
66 NET_MSG_TIME_SYNC
= 194;
67 NET_MSG_VOTE_EVENT
= 195;
70 NET_MSG_MAP_REQUEST = 201;
71 NET_MSG_MAP_RESPONSE = 202;
72 NET_MSG_RES_REQUEST = 203;
73 NET_MSG_RES_RESPONSE = 204;
97 NET_EV_CHANGE_TEAM
= 3;
98 NET_EV_PLAYER_KICK
= 4;
99 NET_EV_PLAYER_BAN
= 5;
100 NET_EV_LMS_WARMUP
= 6;
101 NET_EV_LMS_SURVIVOR
= 7;
105 NET_EV_SCORE_MSG
= 11;
106 NET_EV_LMS_START
= 12;
108 NET_EV_TLMS_WIN
= 14;
109 NET_EV_LMS_LOSE
= 15;
110 NET_EV_LMS_DRAW
= 16;
111 NET_EV_KILLCOMBO
= 17;
112 NET_EV_PLAYER_TOUCH
= 18;
114 NET_EV_INTER_READY
= 20;
115 NET_EV_LMS_NOSPAWN
= 21;
122 NET_VE_INPROGRESS
= 6;
129 NET_CHEAT_SUICIDE
= 1;
130 NET_CHEAT_SPECTATE
= 2;
133 NET_MAX_DIFFTIME
= 5000 div 36;
137 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
139 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
140 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
141 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
142 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
143 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
146 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
147 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
148 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
149 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
152 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
153 procedure MH_SEND_Info(ID
: Byte);
154 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
170 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
190 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
191 procedure MH_SEND_VoteEvent(EvType
: Byte;
192 StrArg1
: string = 'a'; StrArg2
: string = 'b';
193 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
194 ID
: Integer = NET_EVERYONE
);
196 // CLIENT MESSAGES //
199 procedure MC_RECV_Chat(var M
: TMsg
);
200 procedure MC_RECV_Effect(var M
: TMsg
);
201 procedure MC_RECV_Sound(var M
: TMsg
);
202 procedure MC_RECV_GameStats(var M
: TMsg
);
203 procedure MC_RECV_CoopStats(var M
: TMsg
);
204 procedure MC_RECV_GameEvent(var M
: TMsg
);
205 procedure MC_RECV_FlagEvent(var M
: TMsg
);
206 procedure MC_RECV_GameSettings(var M
: TMsg
);
208 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
209 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
210 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
211 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
212 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
213 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
214 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
215 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
217 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
218 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
220 procedure MC_RECV_PanelTexture(var M
: TMsg
);
221 procedure MC_RECV_PanelState(var M
: TMsg
);
223 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
224 procedure MC_RECV_MonsterPos(var M
: TMsg
);
225 procedure MC_RECV_MonsterState(var M
: TMsg
);
226 procedure MC_RECV_MonsterShot(var M
: TMsg
);
227 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
229 procedure MC_RECV_CreateShot(var M
: TMsg
);
230 procedure MC_RECV_UpdateShot(var M
: TMsg
);
231 procedure MC_RECV_DeleteShot(var M
: TMsg
);
233 procedure MC_RECV_TriggerSound(var M
: TMsg
);
234 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
236 procedure MC_RECV_TimeSync(var M
: TMsg
);
237 procedure MC_RECV_VoteEvent(var M
: TMsg
);
239 procedure MC_SEND_Info(Password
: string);
240 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
241 procedure MC_SEND_PlayerPos();
242 procedure MC_SEND_FullStateRequest();
243 procedure MC_SEND_PlayerSettings();
244 procedure MC_SEND_CheatRequest(Kind
: Byte);
245 procedure MC_SEND_RCONPassword(Password
: string);
246 procedure MC_SEND_RCONCommand(Cmd
: string);
247 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
249 //procedure MC_SEND_MapRequest();
250 //procedure MC_SEND_ResRequest(const resName: AnsiString);
254 TExternalResourceInfo
= record
269 ExternalResources
: array of TExternalResourceInfo
;
272 function IsValidFileName(const S
: String): Boolean;
273 function IsValidFilePath(const S
: String): Boolean;
279 Math
, ENet
, e_input
, e_graphics
, e_log
,
280 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
281 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
282 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
285 NET_KEY_LEFT
= 1 shl 0;
286 NET_KEY_RIGHT
= 1 shl 1;
287 NET_KEY_UP
= 1 shl 2;
288 NET_KEY_DOWN
= 1 shl 3;
289 NET_KEY_JUMP
= 1 shl 4;
290 NET_KEY_FIRE
= 1 shl 5;
291 NET_KEY_OPEN
= 1 shl 6;
292 NET_KEY_CHAT
= 1 shl 7;
293 NET_KEY_FORCEDIR
= 1 shl 8;
296 //kBytePrev: Word = 0;
297 //kDirPrev: TDirection = D_LEFT;
298 //HostGameTime: Word = 0;
301 function IsValidFileName(const S
: String): Boolean;
303 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
308 for I
:= 1 to Length(S
) do
309 Result
:= Result
and (not(S
[I
] in Forbidden
));
312 function IsValidFilePath(const S
: String): Boolean;
317 if not IsValidFileName(S
) then exit
;
318 if FileExists(S
) then exit
;
319 I
:= LastDelimiter('\/', S
);
321 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
332 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
340 Pl
:= g_Player_Get(PID
);
342 Txt
:= M
.ReadString();
343 Mode
:= M
.ReadByte();
344 if (Mode
= NET_CHAT_SYSTEM
) then
345 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
346 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
347 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
350 MH_SEND_Chat(Txt
, Mode
)
352 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
355 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
357 Ver
, PName
, Model
, Pw
: string;
363 Ver
:= M
.ReadString();
364 Pw
:= M
.ReadString();
365 PName
:= M
.ReadString();
366 Model
:= M
.ReadString();
372 if Ver
<> GAME_VERSION
then
374 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
375 _lc
[I_NET_DISC_VERSION
]);
376 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
380 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
382 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
384 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
385 _lc
[I_NET_DISC_BAN
]);
386 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
390 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
391 _lc
[I_NET_DISC_BAN
]);
392 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
397 if NetPassword
<> '' then
398 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
400 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
401 _lc
[I_NET_DISC_PASSWORD
]);
402 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
410 PID
:= g_Player_Create(Model
, Color
, T
, False);
411 with g_Player_Get(PID
) do
418 C
^.WaitForFirstSpawn
:= false;
420 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
421 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
422 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
426 with g_Player_Get(PID
) do
430 // round in progress, don't spawn
431 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
432 //e_LogWritefln('spawning player with pid #%u...', [PID]);
433 //Respawn(gGameSettings.GameType = GT_SINGLE);
434 //k8: no, do not spawn a player yet, wait for "request full state" packet
438 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
439 // that is, if we'll set it to `true`, the player can be spawned after
440 // warmup time ran out, for example, regardless of the real player state.
441 // also, this seems to work only for the initial connection. further
442 // map changes could initiate resource downloading, but the player will
443 // be spawned immediately.
444 // the proper solution will require another player state, "ephemeral".
445 // the player should start any map in "ephemeral" state, and turned into
446 // real mobj only when they sent a special "i am ready" packet. this packet
447 // must be sent after receiving the full state, so the player will get a full
448 // map view before going into game.
449 FWantsInGame
:= false;
450 C
^.WaitForFirstSpawn
:= true;
453 //if not C^.WaitForFirstSpawn then
455 for I
:= Low(NetClients
) to High(NetClients
) do
457 if NetClients
[I
].ID
= C
^.ID
then Continue
;
458 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
459 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
460 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
464 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
465 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
469 //g_Net_Slist_Update;
475 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
479 if not C
.WaitForFirstSpawn
then exit
;
480 plr
:= g_Player_Get(C
^.Player
);
481 if not assigned(plr
) then exit
;
482 g_Net_Slist_ServerPlayerComes();
483 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
484 C
.WaitForFirstSpawn
:= false;
485 plr
.FNoRespawn
:= false;
486 plr
.FWantsInGame
:= true; // TODO: look into this later
488 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
491 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
496 if gLMSRespawn
> LMS_RESPAWN_NONE
then
497 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
502 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
504 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
507 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
511 C
^.RequestedFullUpdate
:= True;
517 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
528 if not gGameOn
then Exit
;
530 GT
:= M
.ReadLongWord();
532 Pl
:= g_Player_Get(PID
);
536 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
541 kByte
:= M
.ReadWord();
543 WeaponAct
:= M
.ReadByte();
544 WeaponSelect
:= M
.ReadWord();
545 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
546 if Direction
<> TDirection(Dir
) then
547 JustTeleported
:= False;
549 SetDirection(TDirection(Dir
));
552 if kByte
= NET_KEY_CHAT
then
554 PressKey(KEY_CHAT
, 10000);
558 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
559 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
560 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
561 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
562 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
563 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
564 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
568 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
570 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
571 ProcessWeaponAction(i
);
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
.Name
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
.Name
)
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
);
1556 if not gGameOn
then Exit
;
1557 Kind
:= M
.ReadByte();
1558 X
:= M
.ReadLongInt();
1559 Y
:= M
.ReadLongInt();
1560 Ang
:= M
.ReadSmallInt();
1564 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1568 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1570 Anim
:= TAnimation
.Create(ID
, False, 3);
1571 g_GFX_OnceAnim(X
, Y
, Anim
);
1575 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1580 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1582 Anim
:= TAnimation
.Create(ID
, False, 6);
1583 Anim
.Blending
:= False;
1584 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1588 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1593 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1595 Anim
:= TAnimation
.Create(ID
, False, 6);
1596 Anim
.Blending
:= False;
1597 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1601 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1606 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1608 Anim
:= TAnimation
.Create(ID
, False, 4);
1609 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1616 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1618 Anim
:= TAnimation
.Create(ID
, False, 4);
1619 g_GFX_OnceAnim(X
, Y
, Anim
);
1623 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1628 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1630 Anim
:= TAnimation
.Create(ID
, False, 4);
1631 g_GFX_OnceAnim(X
, Y
, Anim
);
1635 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1639 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1642 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1646 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1647 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1652 procedure MC_RECV_Sound(var M
: TMsg
);
1658 Name
:= M
.ReadString();
1659 Pos
:= M
.ReadByte() <> 0;
1662 X
:= M
.ReadLongInt();
1663 Y
:= M
.ReadLongInt();
1664 g_Sound_PlayExAt(Name
, X
, Y
);
1667 g_Sound_PlayEx(Name
);
1670 procedure MC_RECV_CreateShot(var M
: TMsg
);
1672 I
, X
, Y
, XV
, YV
: Integer;
1674 Target
, Spawner
: Word;
1677 I
:= M
.ReadLongInt();
1678 ShType
:= M
.ReadByte();
1679 Target
:= M
.ReadWord();
1680 Spawner
:= M
.ReadWord();
1681 Timeout
:= M
.ReadLongWord();
1682 X
:= M
.ReadLongInt();
1683 Y
:= M
.ReadLongInt();
1684 XV
:= M
.ReadLongInt();
1685 YV
:= M
.ReadLongInt();
1687 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1688 if (Shots
<> nil) and (I
<= High(Shots
)) then
1690 Shots
[I
].Timeout
:= Timeout
;
1691 //Shots[I].Target := Target; // TODO: find a use for Target later
1695 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1697 I
, TX
, TY
, TXV
, TYV
: Integer;
1699 I
:= M
.ReadLongInt();
1700 TX
:= M
.ReadLongInt();
1701 TY
:= M
.ReadLongInt();
1702 TXV
:= M
.ReadLongInt();
1703 TYV
:= M
.ReadLongInt();
1705 if (Shots
<> nil) and (I
<= High(Shots
)) then
1715 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1720 if not gGameOn
then Exit
;
1721 I
:= M
.ReadLongInt();
1722 L
:= (M
.ReadByte() <> 0);
1723 X
:= M
.ReadLongInt();
1724 Y
:= M
.ReadLongInt();
1726 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1729 procedure MC_RECV_GameStats(var M
: TMsg
);
1731 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1733 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1734 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1737 if gGameSettings
.GameMode
= GM_COOP
then
1739 gCoopMonstersKilled
:= M
.ReadWord();
1740 gCoopSecretsFound
:= M
.ReadWord();
1744 procedure MC_RECV_CoopStats(var M
: TMsg
);
1746 gTotalMonsters
:= M
.ReadLongInt();
1747 gSecretsCount
:= M
.ReadLongInt();
1748 gCoopTotalMonstersKilled
:= M
.ReadWord();
1749 gCoopTotalSecretsFound
:= M
.ReadWord();
1750 gCoopTotalMonsters
:= M
.ReadWord();
1751 gCoopTotalSecrets
:= M
.ReadWord();
1754 procedure MC_RECV_GameEvent(var M
: TMsg
);
1763 i1
, i2
: TStrings_Locale
;
1766 goodCmd
: Boolean = true;
1768 FillChar(EvHash
, Sizeof(EvHash
), 0);
1769 EvType
:= M
.ReadByte();
1770 EvNum
:= M
.ReadLongInt();
1771 EvStr
:= M
.ReadString();
1772 gLastMap
:= M
.ReadByte() <> 0;
1773 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1774 gStatsPressed
:= True;
1775 EvTime
:= M
.ReadLongWord();
1776 BHash
:= M
.ReadByte() <> 0;
1778 EvHash
:= M
.ReadMD5();
1782 if (g_Res_received_map_start
<> 0) then
1784 if (g_Res_received_map_start
< 0) then exit
;
1787 NET_EV_MAPSTART
: goodCmd
:= true;
1788 NET_EV_MAPEND
: goodCmd
:= true;
1789 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1790 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1791 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1793 if not goodCmd
then exit
;
1799 if (g_Res_received_map_start
<> 0) then
1801 g_Res_received_map_start
:= -1;
1806 g_Game_ClearLoading();
1807 g_Game_StopAllSounds(True);
1809 gSwitchGameMode
:= Byte(EvNum
);
1810 gGameSettings
.GameMode
:= gSwitchGameMode
;
1813 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1815 if not isWadPath(EvStr
) then
1816 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1818 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1822 MC_SEND_FullStateRequest
;
1828 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1829 gLMSRespawnTime
:= 0;
1830 if (g_Res_received_map_start
<> 0) then
1832 g_Res_received_map_start
:= -1;
1836 gMissionFailed
:= EvNum
<> 0;
1837 gExit
:= EXIT_ENDLEVELCUSTOM
;
1845 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1847 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1849 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1855 if NetDeafLevel
< 2 then
1857 if EvNum
= TEAM_RED
then
1858 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1859 if EvNum
= TEAM_BLUE
then
1860 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1866 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1867 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1872 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1873 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1880 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
1881 gLMSRespawnTime
:= gTime
+ EvNum
;
1882 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
1884 else if gPlayer1
= nil then
1886 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1890 NET_EV_LMS_SURVIVOR
:
1891 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1894 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1898 pl
:= g_Player_Get(EvNum
and $FFFF);
1903 cnt
:= (EvNum
shr 16) and $FF;
1904 if Pos('w', EvStr
) = 0 then
1907 if Pos('t', EvStr
) = 0 then
1910 if Pos('-', EvStr
) = 0 then
1912 if Pos('e', EvStr
) = 0 then
1913 i1
:= I_PLAYER_SCORE_ADD_OWN
1915 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1918 if Pos('e', EvStr
) = 0 then
1919 i1
:= I_PLAYER_SCORE_SUB_OWN
1921 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1924 if Pos('r', EvStr
) > 0 then
1925 i2
:= I_PLAYER_SCORE_TO_RED
1927 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1928 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1932 if Pos('-', EvStr
) = 0 then
1933 i1
:= I_PLAYER_SCORE_ADD_TEAM
1935 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1937 if Pos('r', EvStr
) > 0 then
1938 i2
:= I_PLAYER_SCORE_RED
1940 i2
:= I_PLAYER_SCORE_BLUE
;
1941 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1946 if Pos('e', EvStr
) = 0 then
1947 i1
:= I_PLAYER_SCORE_WIN_OWN
1949 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1951 if Pos('r', EvStr
) > 0 then
1952 i2
:= I_PLAYER_SCORE_TO_RED
1954 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1955 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1961 if EvNum
= TEAM_RED
then
1962 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1963 if EvNum
= TEAM_BLUE
then
1964 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1965 if EvNum
= -TEAM_RED
then
1966 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1967 if EvNum
= -TEAM_BLUE
then
1968 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1973 g_Player_RemoveAllCorpses
;
1974 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1975 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1979 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1983 if EvNum
= TEAM_RED
then
1984 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1985 if EvNum
= TEAM_BLUE
then
1986 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1990 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1993 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1996 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1999 g_Game_Announce_KillCombo(EvNum
);
2001 NET_EV_PLAYER_TOUCH
:
2003 pl
:= g_Player_Get(EvNum
);
2010 pl
:= g_Player_Get(EvNum
);
2013 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2014 g_Sound_PlayEx('SOUND_GAME_SECRET');
2020 pl
:= g_Player_Get(EvNum
);
2021 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2026 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2035 EvType
:= M
.ReadByte();
2038 if Fl
= FLAG_NONE
then Exit
;
2040 Quiet
:= (M
.ReadByte() <> 0);
2041 PID
:= M
.ReadWord();
2043 gFlags
[Fl
].State
:= M
.ReadByte();
2044 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2045 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2046 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2047 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2048 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2050 Pl
:= g_Player_Get(PID
);
2052 (EvType
<> FLAG_STATE_NORMAL
) and
2053 (EvType
<> FLAG_STATE_DROPPED
) and
2054 (EvType
<> FLAG_STATE_RETURNED
) then
2060 if Quiet
or (Pl
= nil) then Exit
;
2062 if Fl
= FLAG_RED
then
2063 s
:= _lc
[I_PLAYER_FLAG_RED
]
2065 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2067 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2069 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2070 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2071 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2076 if not sound_ret_flag
[a
].IsPlaying() then
2077 sound_ret_flag
[a
].Play();
2080 FLAG_STATE_CAPTURED
:
2082 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2086 if Fl
= FLAG_RED
then
2087 s
:= _lc
[I_PLAYER_FLAG_RED
]
2089 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2091 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2092 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2094 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2095 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2096 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2101 if not sound_get_flag
[a
].IsPlaying() then
2102 sound_get_flag
[a
].Play();
2107 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2109 if Quiet
or (Pl
= nil) then Exit
;
2111 if Fl
= FLAG_RED
then
2112 s
:= _lc
[I_PLAYER_FLAG_RED
]
2114 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2116 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2117 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2119 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2120 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2121 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2126 if not sound_lost_flag
[a
].IsPlaying() then
2127 sound_lost_flag
[a
].Play();
2132 g_Map_ResetFlag(FLAG_RED
);
2133 g_Map_ResetFlag(FLAG_BLUE
);
2134 if Quiet
or (Pl
= nil) then Exit
;
2135 Pl
.SetFlag(FLAG_NONE
);
2137 if Fl
= FLAG_RED
then
2138 s
:= _lc
[I_PLAYER_FLAG_RED
]
2140 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2142 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2143 Insert('.', ts
, Length(ts
) + 1 - 3);
2144 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2145 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [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_cap_flag
[a
].IsPlaying() then
2155 sound_cap_flag
[a
].Play();
2158 FLAG_STATE_RETURNED
:
2160 g_Map_ResetFlag(Fl
);
2163 if Fl
= FLAG_RED
then
2164 s
:= _lc
[I_PLAYER_FLAG_RED
]
2166 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2168 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2170 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2171 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2172 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2177 if not sound_ret_flag
[a
].IsPlaying() then
2178 sound_ret_flag
[a
].Play();
2183 procedure MC_RECV_GameSettings(var M
: TMsg
);
2185 gGameSettings
.GameMode
:= M
.ReadByte();
2186 gGameSettings
.GoalLimit
:= M
.ReadWord();
2187 gGameSettings
.TimeLimit
:= M
.ReadWord();
2188 gGameSettings
.MaxLives
:= M
.ReadByte();
2189 gGameSettings
.Options
:= M
.ReadLongWord();
2194 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2197 PName
, Model
: string;
2202 PID
:= M
.ReadWord();
2203 Pl
:= g_Player_Get(PID
);
2205 PName
:= M
.ReadString();
2206 Model
:= M
.ReadString();
2207 Color
.R
:= M
.ReadByte();
2208 Color
.G
:= M
.ReadByte();
2209 Color
.B
:= M
.ReadByte();
2213 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2215 if (Pl
<> nil) then Exit
;
2216 DID
:= g_Player_Create(Model
, Color
, T
, False);
2217 with g_Player_Get(DID
) do
2226 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2227 gPlayer1
.UID
:= PID
;
2228 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2229 gPlayer1
.ChangeTeam(T
);
2231 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2232 gPlayer2
.UID
:= PID
;
2233 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2234 gPlayer2
.ChangeTeam(T
);
2238 if NetDeafLevel
< 3 then
2239 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2240 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2244 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2251 TmpX
, TmpY
: Integer;
2255 GT
:= M
.ReadLongWord();
2256 if GT
< gTime
- NET_MAX_DIFFTIME
then
2263 PID
:= M
.ReadWord();
2264 Pl
:= g_Player_Get(PID
);
2266 if Pl
= nil then Exit
;
2272 FPing
:= M
.ReadWord();
2273 FLoss
:= M
.ReadByte();
2274 kByte
:= M
.ReadWord();
2275 Dir
:= M
.ReadByte();
2277 TmpX
:= M
.ReadLongInt();
2278 TmpY
:= M
.ReadLongInt();
2282 if LongBool(kByte
and NET_KEY_CHAT
) then
2283 PressKey(KEY_CHAT
, 10000)
2286 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2287 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2288 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2289 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2290 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2293 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2295 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2296 SetDirection(TDirection(Dir
));
2298 GameVelX
:= M
.ReadLongInt();
2299 GameVelY
:= M
.ReadLongInt();
2300 GameAccelX
:= M
.ReadLongInt();
2301 GameAccelY
:= M
.ReadLongInt();
2302 SetLerp(TmpX
, TmpY
);
2303 if NetForcePlayerUpdate
then Update();
2307 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2311 I
, OldFire
: Integer;
2312 OldJet
, Flam
: Boolean;
2315 PID
:= M
.ReadWord();
2316 Pl
:= g_Player_Get(PID
);
2323 alive
:= (M
.ReadByte() <> 0);
2324 GodMode
:= (M
.ReadByte() <> 0);
2325 Health
:= M
.ReadLongInt();
2326 Armor
:= M
.ReadLongInt();
2327 Air
:= M
.ReadLongInt();
2328 JetFuel
:= M
.ReadLongInt();
2329 Lives
:= M
.ReadByte();
2330 NewTeam
:= M
.ReadByte();
2332 for I
:= WP_FIRST
to WP_LAST
do
2333 FWeapon
[I
] := (M
.ReadByte() <> 0);
2335 for I
:= A_BULLETS
to A_HIGH
do
2336 FAmmo
[I
] := M
.ReadWord();
2338 for I
:= A_BULLETS
to A_HIGH
do
2339 FMaxAmmo
[I
] := M
.ReadWord();
2341 for I
:= MR_SUIT
to MR_MAX
do
2342 FMegaRulez
[I
] := M
.ReadLongWord();
2345 if (M
.ReadByte() <> 0) then
2346 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2347 if (M
.ReadByte() <> 0) then
2348 FRulez
:= FRulez
+ [R_KEY_RED
];
2349 if (M
.ReadByte() <> 0) then
2350 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2351 if (M
.ReadByte() <> 0) then
2352 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2353 if (M
.ReadByte() <> 0) then
2354 FRulez
:= FRulez
+ [R_BERSERK
];
2356 Frags
:= M
.ReadLongInt();
2357 Death
:= M
.ReadLongInt();
2359 SetWeapon(M
.ReadByte());
2361 FSpectator
:= M
.ReadByte() <> 0;
2364 if UID
= NetPlrUID1
then
2366 gSpectLatchPID1
:= UID
;
2369 if UID
= NetPlrUID2
then
2371 gSpectLatchPID2
:= UID
;
2377 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2380 gSpectLatchPID1
:= 0;
2382 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2385 gSpectLatchPID2
:= 0;
2388 FGhost
:= M
.ReadByte() <> 0;
2389 FPhysics
:= M
.ReadByte() <> 0;
2390 FNoRespawn
:= M
.ReadByte() <> 0;
2392 FJetpack
:= M
.ReadByte() <> 0;
2393 OldFire
:= FFireTime
;
2394 FFireTime
:= M
.ReadLongInt();
2395 if (OldFire
<= 0) and (FFireTime
> 0) then
2396 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2397 Flam
:= M
.ReadByte() <> 0;
2398 FSpawnInvul
:= M
.ReadLongInt();
2399 if OldJet
and not FJetpack
then
2401 else if not OldJet
and FJetpack
then
2403 if FFlaming
and not Flam
then
2405 if Team
<> NewTeam
then
2406 Pl
.ChangeTeam(NewTeam
);
2412 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2417 Attacker
, Value
: Word;
2421 if not gGameOn
then Exit
;
2422 PID
:= M
.ReadWord();
2423 Pl
:= g_Player_Get(PID
);
2424 if Pl
= nil then Exit
;
2426 Kind
:= M
.ReadByte();
2427 Attacker
:= M
.ReadWord();
2428 Value
:= M
.ReadWord();
2433 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2438 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2442 KillType
, DeathType
: Byte;
2446 if not gGameOn
then Exit
;
2447 PID
:= M
.ReadWord();
2448 Pl
:= g_Player_Get(PID
);
2449 if Pl
= nil then Exit
;
2451 KillType
:= M
.ReadByte();
2452 DeathType
:= M
.ReadByte();
2453 Attacker
:= M
.ReadWord();
2457 Kill(KillType
, Attacker
, DeathType
);
2462 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2467 PID
:= M
.ReadWord();
2468 Pl
:= g_Player_Get(PID
);
2470 if Pl
= nil then Exit
;
2472 if NetDeafLevel
< 3 then
2473 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2474 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2476 g_Player_Remove(PID
);
2481 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2486 X
, Y
, AX
, AY
: Integer;
2490 if not gGameOn
then Exit
;
2491 PID
:= M
.ReadWord();
2492 Pl
:= g_Player_Get(PID
);
2493 if Pl
= nil then Exit
;
2495 Weap
:= M
.ReadByte();
2496 X
:= M
.ReadLongInt();
2497 Y
:= M
.ReadLongInt();
2498 AX
:= M
.ReadLongInt();
2499 AY
:= M
.ReadLongInt();
2500 SHID
:= M
.ReadLongInt();
2503 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2506 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2515 PID
:= M
.ReadWord();
2516 Pl
:= g_Player_Get(PID
);
2517 if Pl
= nil then Exit
;
2519 TmpName
:= M
.ReadString();
2520 TmpModel
:= M
.ReadString();
2521 TmpColor
.R
:= M
.ReadByte();
2522 TmpColor
.G
:= M
.ReadByte();
2523 TmpColor
.B
:= M
.ReadByte();
2524 TmpTeam
:= M
.ReadByte();
2526 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2528 Pl
.ChangeTeam(TmpTeam
);
2529 if gPlayer1
= Pl
then
2530 gPlayer1Settings
.Team
:= TmpTeam
;
2531 if gPlayer2
= Pl
then
2532 gPlayer2Settings
.Team
:= TmpTeam
;
2534 Pl
.SetColor(TmpColor
);
2536 if Pl
.Name
<> TmpName
then
2538 if NetDeafLevel
< 3 then
2539 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2543 if TmpModel
<> Pl
.Model
.Name
then
2544 Pl
.SetModel(TmpModel
);
2549 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2553 X
, Y
, VX
, VY
: Integer;
2555 Quiet
, Fall
{, Resp}: Boolean;
2559 if not gGameOn
then Exit
;
2561 Quiet
:= M
.ReadByte() <> 0;
2563 Fall
:= M
.ReadByte() <> 0;
2564 {Resp :=} M
.ReadByte();
2565 X
:= M
.ReadLongInt();
2566 Y
:= M
.ReadLongInt();
2567 VX
:= M
.ReadLongInt();
2568 VY
:= M
.ReadLongInt();
2570 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2571 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2573 it
:= g_Items_ByIdx(ID
);
2579 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2580 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2582 Anim
:= TAnimation
.Create(AID
, False, 4);
2583 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2589 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2594 if not gGameOn
then Exit
;
2596 Quiet
:= M
.ReadByte() <> 0;
2598 if not g_Items_ValidId(ID
) then exit
;
2600 if not Quiet
then g_Items_EmitPickupSound(ID
);
2607 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2614 if not gGameOn
then Exit
;
2616 PGUID
:= Integer(M
.ReadLongWord());
2617 Tex
:= M
.ReadLongInt();
2618 Fr
:= M
.ReadLongInt();
2619 Cnt
:= M
.ReadByte();
2620 Loop
:= M
.ReadByte();
2622 TP
:= g_Map_PanelByGUID(PGUID
);
2626 TP
.SetTexture(Tex
, Loop
);
2627 TP
.SetFrame(Fr
, Cnt
);
2631 procedure MC_RECV_PanelState(var M
: TMsg
);
2636 X
, Y
, W
, H
: Integer;
2638 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2639 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2642 if not gGameOn
then Exit
;
2644 PGUID
:= Integer(M
.ReadLongWord());
2645 E
:= (M
.ReadByte() <> 0);
2646 Lift
:= M
.ReadByte();
2647 X
:= M
.ReadLongInt();
2648 Y
:= M
.ReadLongInt();
2652 speedX
:= M
.ReadLongInt();
2653 speedY
:= M
.ReadLongInt();
2654 startX
:= M
.ReadLongInt();
2655 startY
:= M
.ReadLongInt();
2656 endX
:= M
.ReadLongInt();
2657 endY
:= M
.ReadLongInt();
2658 sizeSpX
:= M
.ReadLongInt();
2659 sizeSpY
:= M
.ReadLongInt();
2660 sizeEX
:= M
.ReadLongInt();
2661 sizeEY
:= M
.ReadLongInt();
2662 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2664 TP
:= g_Map_PanelByGUID(PGUID
);
2665 if (TP
= nil) then exit
;
2667 // update lifts state
2668 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2670 // update enabled/disabled state for all panels
2671 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2673 // update panel position, as it can be moved (mplat)
2678 // update mplat state
2679 TP
.movingSpeedX
:= speedX
;
2680 TP
.movingSpeedY
:= speedY
;
2681 TP
.movingStartX
:= startX
;
2682 TP
.movingStartY
:= startY
;
2683 TP
.movingEndX
:= endX
;
2684 TP
.movingEndY
:= endY
;
2685 TP
.sizeSpeedX
:= sizeSpX
;
2686 TP
.sizeSpeedY
:= sizeSpY
;
2687 TP
.sizeEndX
:= sizeEX
;
2688 TP
.sizeEndY
:= sizeEY
;
2689 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2690 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2691 // notify panel of it's position/size change, so it can fix other internal structures
2692 TP
.positionChanged();
2697 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2700 SPos
, SID
: LongWord;
2704 if not gGameOn
then Exit
;
2705 if gTriggers
= nil then Exit
;
2707 SID
:= M
.ReadLongWord();
2708 SPlaying
:= M
.ReadByte() <> 0;
2709 SPos
:= M
.ReadLongWord();
2710 SCount
:= M
.ReadLongInt();
2712 for I
:= Low(gTriggers
) to High(gTriggers
) do
2713 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2714 if gTriggers
[I
].ClientID
= SID
then
2715 with gTriggers
[I
] do
2717 if Sound
<> nil then
2722 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2724 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2725 Sound
.SetPosition(SPos
);
2728 if Sound
.IsPlaying
then Sound
.Stop
;
2731 SoundPlayCount
:= SCount
;
2735 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2742 if not gGameOn
then Exit
;
2744 MName
:= M
.ReadString();
2745 MPlaying
:= M
.ReadByte() <> 0;
2746 MPos
:= M
.ReadLongWord();
2747 MPaused
:= M
.ReadByte() <> 0;
2748 MPos
:= MPos
+1; //k8: stfu, fpc!
2752 gMusic
.SetByName(MName
);
2754 // gMusic.SetPosition(MPos);
2755 gMusic
.SpecPause
:= MPaused
;
2758 if gMusic
.IsPlaying
then gMusic
.Stop
;
2763 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2766 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2767 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2772 Mon
:= g_Monsters_ByUID(ID
);
2776 MType
:= M
.ReadByte();
2777 MState
:= M
.ReadByte();
2778 MAnim
:= M
.ReadByte();
2779 MTarg
:= M
.ReadWord();
2780 MTargTime
:= M
.ReadLongInt();
2781 MBehav
:= M
.ReadByte();
2782 MSleep
:= M
.ReadLongInt();
2783 MHealth
:= M
.ReadLongInt();
2784 MAmmo
:= M
.ReadLongInt();
2786 X
:= M
.ReadLongInt();
2787 Y
:= M
.ReadLongInt();
2788 VX
:= M
.ReadLongInt();
2789 VY
:= M
.ReadLongInt();
2790 MDir
:= M
.ReadByte();
2792 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2793 Mon
:= g_Monsters_ByUID(ID
);
2800 MonsterAnim
:= MAnim
;
2801 MonsterTargetUID
:= MTarg
;
2802 MonsterTargetTime
:= MTargTime
;
2803 MonsterBehaviour
:= MBehav
;
2804 MonsterSleep
:= MSleep
;
2805 MonsterAmmo
:= MAmmo
;
2810 setPosition(X
, Y
); // this will call positionChanged();
2816 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2823 Mon
:= g_Monsters_ByUID(ID
);
2829 X
:= M
.ReadLongInt();
2830 Y
:= M
.ReadLongInt();
2831 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2832 GameVelX
:= M
.ReadLongInt();
2833 GameVelY
:= M
.ReadLongInt();
2834 GameDirection
:= TDirection(M
.ReadByte());
2838 procedure MC_RECV_MonsterState(var M
: TMsg
);
2840 ID
, OldFire
: Integer;
2841 MState
, MFAnm
: Byte;
2843 AnimRevert
: Boolean;
2846 Mon
:= g_Monsters_ByUID(ID
);
2847 if Mon
= nil then Exit
;
2849 MState
:= M
.ReadByte();
2850 MFAnm
:= M
.ReadByte();
2854 MonsterTargetUID
:= M
.ReadWord();
2855 MonsterTargetTime
:= M
.ReadLongInt();
2856 MonsterSleep
:= M
.ReadLongInt();
2857 MonsterHealth
:= M
.ReadLongInt();
2858 MonsterAmmo
:= M
.ReadLongInt();
2859 MonsterPain
:= M
.ReadLongInt();
2860 AnimRevert
:= M
.ReadByte() <> 0;
2861 OldFire
:= FFireTime
;
2862 FFireTime
:= M
.ReadLongInt();
2863 if (OldFire
<= 0) and (FFireTime
> 0) then
2864 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2865 RevertAnim(AnimRevert
);
2867 if MonsterState
<> MState
then
2869 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2870 if (MState
= MONSTATE_DIE
) then DieSound();
2871 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2872 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2873 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2875 SetState(MState
, MFAnm
);
2880 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2884 X
, Y
, VX
, VY
: Integer;
2888 Mon
:= g_Monsters_ByUID(ID
);
2889 if Mon
= nil then Exit
;
2891 X
:= M
.ReadLongInt();
2892 Y
:= M
.ReadLongInt();
2893 VX
:= M
.ReadLongInt();
2894 VY
:= M
.ReadLongInt();
2896 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2899 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2905 Mon
:= g_Monsters_ByUID(ID
);
2906 if Mon
= nil then Exit
;
2908 Mon
.MonsterRemoved
:= True;
2911 procedure MC_RECV_TimeSync(var M
: TMsg
);
2915 Time
:= M
.ReadLongWord();
2917 if gState
= STATE_INTERCUSTOM
then
2918 gServInterTime
:= Min(Time
, 255);
2921 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2925 Int1
, Int2
: SmallInt;
2927 EvID
:= M
.ReadByte();
2928 Int1
:= M
.ReadSmallInt();
2929 Int2
:= M
.ReadSmallInt();
2930 Str1
:= M
.ReadString();
2931 Str2
:= M
.ReadString();
2933 if NetDeafLevel
< 2 then
2936 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2938 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2940 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2942 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2944 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2950 procedure MC_SEND_Info(Password
: string);
2954 NetOut
.Write(Byte(NET_MSG_INFO
));
2955 NetOut
.Write(GAME_VERSION
);
2956 NetOut
.Write(Password
);
2957 NetOut
.Write(gPlayer1Settings
.Name
);
2958 NetOut
.Write(gPlayer1Settings
.Model
);
2959 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2960 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2961 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2962 NetOut
.Write(gPlayer1Settings
.Team
);
2964 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2967 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2969 NetOut
.Write(Byte(NET_MSG_CHAT
));
2973 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2976 procedure MC_SEND_PlayerPos();
2981 WeaponAct
: Byte = 0;
2982 WeaponSelect
: Word = 0;
2985 if not gGameOn
then Exit
;
2986 if gPlayers
= nil then Exit
;
2987 if gPlayer1
= nil then Exit
;
2990 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2992 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2994 strafeDir
:= P1MoveButton
shr 4;
2995 P1MoveButton
:= P1MoveButton
and $0F;
2997 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2999 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3001 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3005 if gPlayerAction
[0, ACTION_STRAFE
] then
3007 // new strafe mechanics
3008 if (strafeDir
= 0) then
3009 strafeDir
:= P1MoveButton
; // start strafing
3010 // now set direction according to strafe (reversed)
3011 if (strafeDir
= 2) then
3012 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3013 else if (strafeDir
= 1) then
3014 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3018 strafeDir
:= 0; // not strafing anymore
3019 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3020 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3021 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3022 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3023 else if P1MoveButton
<> 0 then
3024 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3027 gPlayer1
.ReleaseKeys
;
3028 if P1MoveButton
= 1 then
3030 kByte
:= kByte
or NET_KEY_LEFT
;
3031 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3033 if P1MoveButton
= 2 then
3035 kByte
:= kByte
or NET_KEY_RIGHT
;
3036 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3038 if gPlayerAction
[0, ACTION_LOOKUP
] then
3040 kByte
:= kByte
or NET_KEY_UP
;
3041 gPlayer1
.PressKey(KEY_UP
, 10000);
3043 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3045 kByte
:= kByte
or NET_KEY_DOWN
;
3046 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3048 if gPlayerAction
[0, ACTION_JUMP
] then
3050 kByte
:= kByte
or NET_KEY_JUMP
;
3051 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3053 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3054 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3056 for i
:= WP_FACT
to WP_LACT
do
3058 if gWeaponAction
[0, i
] then
3060 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3061 gWeaponAction
[0, i
] := False
3065 for i
:= WP_FIRST
to WP_LAST
do
3067 if gSelectWeapon
[0, i
] then
3069 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3070 gSelectWeapon
[0, i
] := False
3074 // fix movebutton state
3075 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3078 kByte
:= NET_KEY_CHAT
;
3080 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3081 NetOut
.Write(gTime
);
3082 NetOut
.Write(kByte
);
3083 NetOut
.Write(Byte(gPlayer1
.Direction
));
3084 NetOut
.Write(WeaponAct
);
3085 NetOut
.Write(WeaponSelect
);
3086 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3087 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3089 //kBytePrev := kByte;
3090 //kDirPrev := gPlayer1.Direction;
3093 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3095 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3096 NetOut
.Write(Byte(Start
));
3097 NetOut
.Write(Command
);
3098 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3101 procedure MC_SEND_PlayerSettings();
3103 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3104 NetOut
.Write(gPlayer1Settings
.Name
);
3105 NetOut
.Write(gPlayer1Settings
.Model
);
3106 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3107 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3108 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3109 NetOut
.Write(gPlayer1Settings
.Team
);
3111 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3114 procedure MC_SEND_FullStateRequest();
3116 NetOut
.Write(Byte(NET_MSG_REQFST
));
3118 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3121 procedure MC_SEND_CheatRequest(Kind
: Byte);
3123 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3126 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3128 procedure MC_SEND_RCONPassword(Password
: string);
3130 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3131 NetOut
.Write(Password
);
3133 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3135 procedure MC_SEND_RCONCommand(Cmd
: string);
3137 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3140 g_Net_Client_Send(True, NET_CHAN_SERVICE
);