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 {$IFDEF ENABLE_SHELLS}
288 Math
, ENet
, e_input
, e_log
, g_base
, g_basic
,
289 g_textures
, g_sound
, g_console
, g_options
,
290 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
,
291 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
305 NET_KEY_FORCEDIR
= 4096;
308 //kBytePrev: Word = 0;
309 //kDirPrev: TDirection = D_LEFT;
310 //HostGameTime: Word = 0;
313 function IsValidFileName(const S
: String): Boolean;
315 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
320 for I
:= 1 to Length(S
) do
321 Result
:= Result
and (not(S
[I
] in Forbidden
));
324 function IsValidFilePath(const S
: String): Boolean;
329 if not IsValidFileName(S
) then exit
;
330 if FileExists(S
) then exit
;
331 I
:= LastDelimiter('\/', S
);
333 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
344 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
352 Pl
:= g_Player_Get(PID
);
354 Txt
:= M
.ReadString();
355 Mode
:= M
.ReadByte();
356 if (Mode
= NET_CHAT_SYSTEM
) then
357 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
358 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
359 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
362 MH_SEND_Chat(Txt
, Mode
)
364 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
367 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
369 Ver
, PName
, Model
, Pw
: string;
375 Ver
:= M
.ReadString();
376 Pw
:= M
.ReadString();
377 PName
:= M
.ReadString();
378 Model
:= M
.ReadString();
384 if Ver
<> GAME_VERSION
then
386 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
387 _lc
[I_NET_DISC_VERSION
]);
388 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
392 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
394 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
396 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
397 _lc
[I_NET_DISC_BAN
]);
398 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
402 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
403 _lc
[I_NET_DISC_BAN
]);
404 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
409 if NetPassword
<> '' then
410 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
412 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
413 _lc
[I_NET_DISC_PASSWORD
]);
414 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
422 PID
:= g_Player_Create(Model
, Color
, T
, False);
423 with g_Player_Get(PID
) do
430 C
^.WaitForFirstSpawn
:= false;
432 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
433 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
434 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
438 with g_Player_Get(PID
) do
442 // round in progress, don't spawn
443 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
444 //e_LogWritefln('spawning player with pid #%u...', [PID]);
445 //Respawn(gGameSettings.GameType = GT_SINGLE);
446 //k8: no, do not spawn a player yet, wait for "request full state" packet
450 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
451 // that is, if we'll set it to `true`, the player can be spawned after
452 // warmup time ran out, for example, regardless of the real player state.
453 // also, this seems to work only for the initial connection. further
454 // map changes could initiate resource downloading, but the player will
455 // be spawned immediately.
456 // the proper solution will require another player state, "ephemeral".
457 // the player should start any map in "ephemeral" state, and turned into
458 // real mobj only when they sent a special "i am ready" packet. this packet
459 // must be sent after receiving the full state, so the player will get a full
460 // map view before going into game.
461 FWantsInGame
:= false;
462 C
^.WaitForFirstSpawn
:= true;
465 //if not C^.WaitForFirstSpawn then
467 for I
:= Low(NetClients
) to High(NetClients
) do
469 if NetClients
[I
].ID
= C
^.ID
then Continue
;
470 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
471 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
472 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
476 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
477 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
481 //g_Net_Slist_Update;
487 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
491 if not C
.WaitForFirstSpawn
then exit
;
492 plr
:= g_Player_Get(C
^.Player
);
493 if not assigned(plr
) then exit
;
494 g_Net_Slist_ServerPlayerComes();
495 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
496 C
.WaitForFirstSpawn
:= false;
497 plr
.FNoRespawn
:= false;
498 plr
.FWantsInGame
:= true; // TODO: look into this later
500 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
503 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
508 if gLMSRespawn
> LMS_RESPAWN_NONE
then
509 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
514 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
516 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
519 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
523 C
^.RequestedFullUpdate
:= True;
529 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
539 if not gGameOn
then Exit
;
541 GT
:= M
.ReadLongWord();
543 Pl
:= g_Player_Get(PID
);
547 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
552 kByte
:= M
.ReadWord();
554 WeaponSelect
:= M
.ReadWord();
555 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
556 if Direction
<> TDirection(Dir
) then
557 JustTeleported
:= False;
559 SetDirection(TDirection(Dir
));
562 if kByte
= NET_KEY_CHAT
then
564 PressKey(KEY_CHAT
, 10000);
568 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
569 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
570 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
571 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
572 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
573 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
574 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
575 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
576 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
580 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
582 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
583 QueueWeaponSwitch(i
);
588 // MH_SEND_PlayerPos(False, PID, C^.ID);
591 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
596 Pl
:= g_Player_Get(C
^.Player
);
597 if Pl
= nil then Exit
;
599 CheatKind
:= M
.ReadByte();
603 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
606 if Pl
.FSpectator
then
608 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
611 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
618 if gState
<> STATE_INTERCUSTOM
then Exit
;
619 Pl
.FReady
:= not Pl
.FReady
;
622 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
623 Inc(gInterReadyCount
);
627 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
628 Dec(gInterReadyCount
);
634 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
642 TmpName
:= M
.ReadString();
643 TmpModel
:= M
.ReadString();
644 TmpColor
.R
:= M
.ReadByte();
645 TmpColor
.G
:= M
.ReadByte();
646 TmpColor
.B
:= M
.ReadByte();
647 TmpTeam
:= M
.ReadByte();
649 Pl
:= g_Player_Get(C
^.Player
);
650 if Pl
= nil then Exit
;
652 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
655 Pl
.SetColor(TmpColor
);
657 if Pl
.Name
<> TmpName
then
659 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
663 if TmpModel
<> Pl
.Model
.GetName() then
664 Pl
.SetModel(TmpModel
);
666 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
671 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
675 Pwd
:= M
.ReadString();
676 if not NetAllowRCON
then Exit
;
677 if Pwd
= NetRCONPassword
then
680 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
683 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
686 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
690 Cmd
:= M
.ReadString();
691 if not NetAllowRCON
then Exit
;
692 if not C
^.RCONAuth
then
694 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
697 g_Console_Process(Cmd
);
702 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
705 Name
, Command
: string;
709 Start
:= M
.ReadByte() <> 0;
710 Command
:= M
.ReadString();
712 Pl
:= g_Player_Get(C
^.Player
);
713 if Pl
= nil then Exit
;
718 if not g_Console_CommandBlacklisted(Command
) then
719 g_Game_StartVote(Command
, Name
);
721 else if gVoteInProgress
then
723 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
724 Need
:= Floor((NetClientCount
+1)/2.0) + 1
726 Need
:= Floor(NetClientCount
/2.0) + 1;
731 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
732 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
738 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
739 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
747 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
749 function sendItemRespawn (it
: PItem
): Boolean;
751 result
:= false; // don't stop
752 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
755 function sendMonSpawn (mon
: TMonster
): Boolean;
757 result
:= false; // don't stop
758 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
761 function sendPanelState (pan
: TPanel
): Boolean;
763 result
:= false; // don't stop
764 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
765 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
771 if (ID
>= 0) and (ID
< length(NetClients
)) then
773 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
774 MH_ProcessFirstSpawn(@NetClients
[ID
]);
777 if gPlayers
<> nil then
779 for I
:= Low(gPlayers
) to High(gPlayers
) do
781 if gPlayers
[I
] <> nil then
783 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
784 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
785 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
787 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
789 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
795 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
796 g_Mons_ForEach(sendMonSpawn
);
797 g_Map_ForEachPanel(sendPanelState
);
799 if gTriggers
<> nil then
801 for I
:= Low(gTriggers
) to High(gTriggers
) do
803 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
805 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
812 for I
:= Low(Shots
) to High(Shots
) do
814 if Shots
[i
].ShotType
in [6, 7, 8] then
816 MH_SEND_CreateShot(i
, ID
);
821 MH_SEND_TriggerMusic(ID
);
823 MH_SEND_GameStats(ID
);
824 MH_SEND_CoopStats(ID
);
826 if gGameSettings
.GameMode
= GM_CTF
then
828 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
829 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
832 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
837 procedure MH_SEND_Info(ID
: Byte);
841 NetOut
.Write(Byte(NET_MSG_INFO
));
843 NetOut
.Write(NetClients
[ID
].Player
);
844 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
845 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
846 NetOut
.Write(gWADHash
);
847 NetOut
.Write(gGameSettings
.GameMode
);
848 NetOut
.Write(gGameSettings
.GoalLimit
);
849 NetOut
.Write(gGameSettings
.TimeLimit
);
850 NetOut
.Write(gGameSettings
.MaxLives
);
851 NetOut
.Write(gGameSettings
.Options
);
854 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
857 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
863 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
864 Mode
:= NET_CHAT_PLAYER
;
867 if (Mode
= NET_CHAT_TEAM
) then
869 for i
:= Low(gPlayers
) to High(gPlayers
) do
870 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
871 (gPlayers
[i
].Team
= ID
) then
873 NetOut
.Write(Byte(NET_MSG_CHAT
));
876 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
883 NetOut
.Write(Byte(NET_MSG_CHAT
));
886 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
889 if Mode
= NET_CHAT_SYSTEM
then
892 if ID
= NET_EVERYONE
then
894 if Mode
= NET_CHAT_PLAYER
then
896 g_Console_Add(Txt
, True);
897 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
898 g_Game_ChatSound(b_Text_Unformat(Txt
));
901 if Mode
= NET_CHAT_TEAM
then
902 if gPlayer1
<> nil then
904 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
906 g_Console_Add(#18'[Team] '#2 + Txt
, True);
907 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
908 g_Game_ChatSound(b_Text_Unformat(Txt
));
910 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
912 g_Console_Add(#20'[Team] '#2 + Txt
, True);
913 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
914 g_Game_ChatSound(b_Text_Unformat(Txt
));
920 Name
:= g_Net_ClientName_ByID(ID
);
921 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
922 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
923 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
927 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
929 NetOut
.Write(Byte(NET_MSG_GFX
));
935 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
938 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
940 NetOut
.Write(Byte(NET_MSG_SND
));
944 NetOut
.Write(Byte(1));
949 NetOut
.Write(Byte(0));
951 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
954 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
956 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
958 NetOut
.Write(Byte(NET_MSG_SHADD
));
960 NetOut
.Write(Shots
[Proj
].ShotType
);
961 NetOut
.Write(Shots
[Proj
].Target
);
962 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
963 NetOut
.Write(Shots
[Proj
].Timeout
);
964 NetOut
.Write(Shots
[Proj
].Obj
.X
);
965 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
966 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
967 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
969 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
972 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
974 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
976 NetOut
.Write(Byte(NET_MSG_SHPOS
));
978 NetOut
.Write(Shots
[Proj
].Obj
.X
);
979 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
980 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
981 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
983 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
986 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
988 NetOut
.Write(Byte(NET_MSG_SHDEL
));
990 NetOut
.Write(Byte(Loud
));
994 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
997 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
999 NetOut
.Write(Byte(NET_MSG_SCORE
));
1000 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1002 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1003 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1006 if gGameSettings
.GameMode
= GM_COOP
then
1008 NetOut
.Write(gCoopMonstersKilled
);
1009 NetOut
.Write(gCoopSecretsFound
);
1012 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1015 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1017 NetOut
.Write(Byte(NET_MSG_COOP
));
1018 NetOut
.Write(gTotalMonsters
);
1019 NetOut
.Write(gSecretsCount
);
1020 NetOut
.Write(gCoopTotalMonstersKilled
);
1021 NetOut
.Write(gCoopTotalSecretsFound
);
1022 NetOut
.Write(gCoopTotalMonsters
);
1023 NetOut
.Write(gCoopTotalSecrets
);
1026 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1028 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1029 NetOut
.Write(EvType
);
1030 NetOut
.Write(EvNum
);
1031 NetOut
.Write(EvStr
);
1032 NetOut
.Write(Byte(gLastMap
));
1033 NetOut
.Write(gTime
);
1034 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1036 NetOut
.Write(Byte(1));
1037 NetOut
.Write(gWADHash
);
1039 NetOut
.Write(Byte(0));
1041 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1044 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1046 NetOut
.Write(Byte(NET_MSG_FLAG
));
1047 NetOut
.Write(EvType
);
1049 NetOut
.Write(Byte(Quiet
));
1051 NetOut
.Write(gFlags
[Flag
].State
);
1052 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1053 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1054 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1055 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1056 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1058 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1061 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1063 NetOut
.Write(Byte(NET_MSG_GSET
));
1064 NetOut
.Write(gGameSettings
.GameMode
);
1065 NetOut
.Write(gGameSettings
.GoalLimit
);
1066 NetOut
.Write(gGameSettings
.TimeLimit
);
1067 NetOut
.Write(gGameSettings
.MaxLives
);
1068 NetOut
.Write(gGameSettings
.Options
);
1070 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1075 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1079 P
:= g_Player_Get(PID
);
1080 if P
= nil then Exit
;
1082 NetOut
.Write(Byte(NET_MSG_PLR
));
1084 NetOut
.Write(P
.Name
);
1086 NetOut
.Write(P
.FActualModelName
);
1087 NetOut
.Write(P
.FColor
.R
);
1088 NetOut
.Write(P
.FColor
.G
);
1089 NetOut
.Write(P
.FColor
.B
);
1090 NetOut
.Write(P
.Team
);
1092 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1095 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1100 Pl
:= g_Player_Get(PID
);
1101 if Pl
= nil then Exit
;
1102 if Pl
.FDummy
then Exit
;
1104 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1105 NetOut
.Write(gTime
);
1112 NetOut
.Write(FPing
);
1113 NetOut
.Write(FLoss
);
1114 if IsKeyPressed(KEY_CHAT
) then
1115 kByte
:= NET_KEY_CHAT
1118 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1119 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1120 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1121 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1122 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1125 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1127 NetOut
.Write(kByte
);
1128 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1129 NetOut
.Write(GameX
);
1130 NetOut
.Write(GameY
);
1131 NetOut
.Write(GameVelX
);
1132 NetOut
.Write(GameVelY
);
1133 NetOut
.Write(GameAccelX
);
1134 NetOut
.Write(GameAccelY
);
1137 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1140 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1145 P
:= g_Player_Get(PID
);
1146 if P
= nil then Exit
;
1148 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1153 NetOut
.Write(Byte(alive
));
1154 NetOut
.Write(Byte(GodMode
));
1155 NetOut
.Write(Health
);
1156 NetOut
.Write(Armor
);
1158 NetOut
.Write(JetFuel
);
1159 NetOut
.Write(Lives
);
1162 for I
:= WP_FIRST
to WP_LAST
do
1163 NetOut
.Write(Byte(FWeapon
[I
]));
1165 for I
:= A_BULLETS
to A_HIGH
do
1166 NetOut
.Write(FAmmo
[I
]);
1168 for I
:= A_BULLETS
to A_HIGH
do
1169 NetOut
.Write(FMaxAmmo
[I
]);
1171 for I
:= MR_SUIT
to MR_MAX
do
1172 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1174 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1175 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1176 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1177 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1178 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1180 NetOut
.Write(Frags
);
1181 NetOut
.Write(Death
);
1183 NetOut
.Write(CurrWeap
);
1185 NetOut
.Write(Byte(FSpectator
));
1186 NetOut
.Write(Byte(FGhost
));
1187 NetOut
.Write(Byte(FPhysics
));
1188 NetOut
.Write(Byte(FNoRespawn
));
1189 NetOut
.Write(Byte(FJetpack
));
1190 NetOut
.Write(FFireTime
);
1191 NetOut
.Write(Byte(FFlaming
));
1192 NetOut
.Write(FSpawnInvul
);
1195 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1198 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1200 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1203 NetOut
.Write(Attacker
);
1204 NetOut
.Write(Value
);
1208 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1211 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1213 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1215 NetOut
.Write(KillType
);
1216 NetOut
.Write(DeathType
);
1217 NetOut
.Write(Attacker
);
1219 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1222 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1224 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1226 NetOut
.Write(Weapon
);
1231 NetOut
.Write(ShotID
);
1233 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1236 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1238 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1241 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1244 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1248 Pl
:= g_Player_Get(PID
);
1249 if Pl
= nil then Exit
;
1251 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1253 NetOut
.Write(Pl
.Name
);
1255 NetOut
.Write(Pl
.Model
.GetName())
1258 NetOut
.Write(Pl
.FColor
.R
);
1259 NetOut
.Write(Pl
.FColor
.G
);
1260 NetOut
.Write(Pl
.FColor
.B
);
1261 NetOut
.Write(Pl
.Team
);
1263 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1268 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1273 it
:= g_Items_ByIdx(IID
);
1275 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1277 NetOut
.Write(Byte(Quiet
));
1279 if it
.dropped
then tt
:= tt
or $80;
1281 NetOut
.Write(Byte(it
.Fall
));
1282 NetOut
.Write(Byte(it
.Respawnable
));
1283 NetOut
.Write(it
.Obj
.X
);
1284 NetOut
.Write(it
.Obj
.Y
);
1285 NetOut
.Write(it
.Obj
.Vel
.X
);
1286 NetOut
.Write(it
.Obj
.Vel
.Y
);
1288 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1291 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1293 NetOut
.Write(Byte(NET_MSG_IDEL
));
1295 NetOut
.Write(Byte(Quiet
));
1297 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1302 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1306 TP
:= g_Map_PanelByGUID(PGUID
);
1307 if (TP
= nil) then exit
;
1311 NetOut
.Write(Byte(NET_MSG_PTEX
));
1312 NetOut
.Write(LongWord(PGUID
));
1313 NetOut
.Write(FCurTexture
);
1314 NetOut
.Write(FCurFrame
);
1315 NetOut
.Write(FCurFrameCount
);
1316 NetOut
.Write(AnimLoop
);
1319 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1322 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1327 TP
:= g_Map_PanelByGUID(PGUID
);
1328 if (TP
= nil) then exit
;
1330 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1331 NetOut
.Write(LongWord(PGUID
));
1332 NetOut
.Write(Byte(TP
.Enabled
));
1333 NetOut
.Write(TP
.LiftType
);
1336 NetOut
.Write(Word(TP
.Width
));
1337 NetOut
.Write(Word(TP
.Height
));
1339 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1340 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1341 NetOut
.Write(LongInt(TP
.movingStartX
));
1342 NetOut
.Write(LongInt(TP
.movingStartY
));
1343 NetOut
.Write(LongInt(TP
.movingEndX
));
1344 NetOut
.Write(LongInt(TP
.movingEndY
));
1345 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1346 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1347 NetOut
.Write(LongInt(TP
.sizeEndX
));
1348 NetOut
.Write(LongInt(TP
.sizeEndY
));
1349 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1350 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1351 NetOut
.Write(Byte(mpflags
));
1353 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1358 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1360 if gTriggers
= nil then Exit
;
1361 if T
.Sound
= nil then Exit
;
1363 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1364 NetOut
.Write(T
.ClientID
);
1365 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1366 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1367 NetOut
.Write(T
.SoundPlayCount
);
1369 g_Net_Host_Send(ID
, True);
1372 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1374 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1375 NetOut
.Write(gMusic
.Name
);
1376 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1377 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1378 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1380 g_Net_Host_Send(ID
, True);
1385 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1389 M
:= g_Monsters_ByUID(UID
);
1395 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1397 NetOut
.Write(MonsterType
);
1398 NetOut
.Write(MonsterState
);
1399 NetOut
.Write(MonsterAnim
);
1400 NetOut
.Write(MonsterTargetUID
);
1401 NetOut
.Write(MonsterTargetTime
);
1402 NetOut
.Write(MonsterBehaviour
);
1403 NetOut
.Write(MonsterSleep
);
1404 NetOut
.Write(MonsterHealth
);
1405 NetOut
.Write(MonsterAmmo
);
1406 NetOut
.Write(GameX
);
1407 NetOut
.Write(GameY
);
1408 NetOut
.Write(GameVelX
);
1409 NetOut
.Write(GameVelY
);
1410 NetOut
.Write(Byte(GameDirection
));
1413 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1416 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1420 M
:= g_Monsters_ByUID(UID
);
1421 if M
= nil then Exit
;
1423 NetOut
.Write(Byte(NET_MSG_MPOS
));
1428 NetOut
.Write(GameX
);
1429 NetOut
.Write(GameY
);
1430 NetOut
.Write(GameVelX
);
1431 NetOut
.Write(GameVelY
);
1432 NetOut
.Write(Byte(GameDirection
));
1435 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1438 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1442 M
:= g_Monsters_ByUID(UID
);
1443 if M
= nil then Exit
;
1445 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1450 NetOut
.Write(MonsterState
);
1451 NetOut
.Write(ForcedAnim
);
1452 NetOut
.Write(MonsterTargetUID
);
1453 NetOut
.Write(MonsterTargetTime
);
1454 NetOut
.Write(MonsterSleep
);
1455 NetOut
.Write(MonsterHealth
);
1456 NetOut
.Write(MonsterAmmo
);
1457 NetOut
.Write(MonsterPain
);
1458 NetOut
.Write(Byte(AnimIsReverse
));
1459 NetOut
.Write(FFireTime
);
1462 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1465 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1467 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1474 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1477 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1481 M
:= g_Monsters_ByUID(UID
);
1482 if M
= nil then Exit
;
1484 NetOut
.Write(Byte(NET_MSG_MDEL
));
1487 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1492 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1494 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1497 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1500 procedure MH_SEND_VoteEvent(EvType
: Byte;
1501 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1502 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1503 ID
: Integer = NET_EVERYONE
);
1505 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1506 NetOut
.Write(EvType
);
1507 NetOut
.Write(IntArg1
);
1508 NetOut
.Write(IntArg2
);
1509 NetOut
.Write(StrArg1
);
1510 NetOut
.Write(StrArg2
);
1512 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1515 // CLIENT MESSAGES //
1519 procedure MC_RECV_Chat(var M
: TMsg
);
1524 Txt
:= M
.ReadString();
1525 Mode
:= M
.ReadByte();
1527 if Mode
<> NET_CHAT_SYSTEM
then
1529 if NetDeafLevel
= 0 then
1531 if Mode
= NET_CHAT_PLAYER
then
1533 g_Console_Add(Txt
, True);
1534 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1535 g_Game_ChatSound(b_Text_Unformat(Txt
));
1537 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1539 if gPlayer1
.Team
= TEAM_RED
then
1540 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1541 if gPlayer1
.Team
= TEAM_BLUE
then
1542 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1543 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1544 g_Game_ChatSound(b_Text_Unformat(Txt
));
1547 end else if (NetDeafLevel
< 2) then
1548 g_Console_Add(Txt
, True);
1551 procedure MC_RECV_Effect(var M
: TMsg
);
1557 if not gGameOn
then Exit
;
1558 Kind
:= M
.ReadByte();
1559 X
:= M
.ReadLongInt();
1560 Y
:= M
.ReadLongInt();
1561 Ang
:= M
.ReadSmallInt();
1567 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1573 g_GFX_QueueEffect(R_GFX_TELEPORT_FAST
, X
, Y
);
1576 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1581 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET
, X
- 64, Y
- 64);
1584 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1589 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG
, X
- 64, Y
- 64);
1592 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1597 g_GFX_QueueEffect(R_GFX_BFG_HIT
, X
- 32, Y
- 32);
1603 g_GFX_QueueEffect(R_GFX_FIRE
, X
, Y
);
1606 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1611 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
, Y
);
1614 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1618 {$IFDEF ENABLE_SHELLS}
1619 g_Shells_Create(X
, Y
, 0, -2, SHELL_BULLET
);
1624 {$IFDEF ENABLE_SHELLS}
1625 g_Shells_Create(X
, Y
, 0, -2, SHELL_SHELL
);
1630 {$IFDEF ENABLE_SHELLS}
1631 g_Shells_Create(X
, Y
, 0, -2, SHELL_SHELL
);
1632 g_Shells_Create(X
, Y
, 0, -2, SHELL_SHELL
);
1638 procedure MC_RECV_Sound(var M
: TMsg
);
1644 Name
:= M
.ReadString();
1645 Pos
:= M
.ReadByte() <> 0;
1648 X
:= M
.ReadLongInt();
1649 Y
:= M
.ReadLongInt();
1650 g_Sound_PlayExAt(Name
, X
, Y
);
1653 g_Sound_PlayEx(Name
);
1656 procedure MC_RECV_CreateShot(var M
: TMsg
);
1658 I
, X
, Y
, XV
, YV
: Integer;
1660 Target
, Spawner
: Word;
1663 I
:= M
.ReadLongInt();
1664 ShType
:= M
.ReadByte();
1665 Target
:= M
.ReadWord();
1666 Spawner
:= M
.ReadWord();
1667 Timeout
:= M
.ReadLongWord();
1668 X
:= M
.ReadLongInt();
1669 Y
:= M
.ReadLongInt();
1670 XV
:= M
.ReadLongInt();
1671 YV
:= M
.ReadLongInt();
1673 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1674 if (Shots
<> nil) and (I
<= High(Shots
)) then
1676 Shots
[I
].Timeout
:= Timeout
;
1677 //Shots[I].Target := Target; // TODO: find a use for Target later
1681 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1683 I
, TX
, TY
, TXV
, TYV
: Integer;
1685 I
:= M
.ReadLongInt();
1686 TX
:= M
.ReadLongInt();
1687 TY
:= M
.ReadLongInt();
1688 TXV
:= M
.ReadLongInt();
1689 TYV
:= M
.ReadLongInt();
1691 if (Shots
<> nil) and (I
<= High(Shots
)) then
1701 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1706 if not gGameOn
then Exit
;
1707 I
:= M
.ReadLongInt();
1708 L
:= (M
.ReadByte() <> 0);
1709 X
:= M
.ReadLongInt();
1710 Y
:= M
.ReadLongInt();
1712 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1715 procedure MC_RECV_GameStats(var M
: TMsg
);
1717 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1719 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1720 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1723 if gGameSettings
.GameMode
= GM_COOP
then
1725 gCoopMonstersKilled
:= M
.ReadWord();
1726 gCoopSecretsFound
:= M
.ReadWord();
1730 procedure MC_RECV_CoopStats(var M
: TMsg
);
1732 gTotalMonsters
:= M
.ReadLongInt();
1733 gSecretsCount
:= M
.ReadLongInt();
1734 gCoopTotalMonstersKilled
:= M
.ReadWord();
1735 gCoopTotalSecretsFound
:= M
.ReadWord();
1736 gCoopTotalMonsters
:= M
.ReadWord();
1737 gCoopTotalSecrets
:= M
.ReadWord();
1740 procedure MC_RECV_GameEvent(var M
: TMsg
);
1749 i1
, i2
: TStrings_Locale
;
1752 goodCmd
: Boolean = true;
1754 FillChar(EvHash
, Sizeof(EvHash
), 0);
1755 EvType
:= M
.ReadByte();
1756 EvNum
:= M
.ReadLongInt();
1757 EvStr
:= M
.ReadString();
1758 gLastMap
:= M
.ReadByte() <> 0;
1759 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1760 gStatsPressed
:= True;
1761 EvTime
:= M
.ReadLongWord();
1762 BHash
:= M
.ReadByte() <> 0;
1764 EvHash
:= M
.ReadMD5();
1768 if (g_Res_received_map_start
<> 0) then
1770 if (g_Res_received_map_start
< 0) then exit
;
1773 NET_EV_MAPSTART
: goodCmd
:= true;
1774 NET_EV_MAPEND
: goodCmd
:= true;
1775 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1776 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1777 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1779 if not goodCmd
then exit
;
1785 if (g_Res_received_map_start
<> 0) then
1787 g_Res_received_map_start
:= -1;
1792 g_Game_ClearLoading();
1793 g_Game_StopAllSounds(True);
1795 gSwitchGameMode
:= Byte(EvNum
);
1796 gGameSettings
.GameMode
:= gSwitchGameMode
;
1799 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1801 if not isWadPath(EvStr
) then
1802 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1804 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1808 MC_SEND_FullStateRequest
;
1814 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1815 gLMSRespawnTime
:= 0;
1816 if (g_Res_received_map_start
<> 0) then
1818 g_Res_received_map_start
:= -1;
1822 gMissionFailed
:= EvNum
<> 0;
1823 gExit
:= EXIT_ENDLEVELCUSTOM
;
1831 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1833 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1835 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1841 if NetDeafLevel
< 2 then
1843 if EvNum
= TEAM_RED
then
1844 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1845 if EvNum
= TEAM_BLUE
then
1846 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1852 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1853 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1858 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1859 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1866 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
1867 gLMSRespawnTime
:= gTime
+ EvNum
;
1868 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
1870 else if gPlayer1
= nil then
1872 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1876 NET_EV_LMS_SURVIVOR
:
1877 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1880 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1884 pl
:= g_Player_Get(EvNum
and $FFFF);
1889 cnt
:= (EvNum
shr 16) and $FF;
1890 if Pos('w', EvStr
) = 0 then
1893 if Pos('t', EvStr
) = 0 then
1896 if Pos('-', EvStr
) = 0 then
1898 if Pos('e', EvStr
) = 0 then
1899 i1
:= I_PLAYER_SCORE_ADD_OWN
1901 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1904 if Pos('e', EvStr
) = 0 then
1905 i1
:= I_PLAYER_SCORE_SUB_OWN
1907 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1910 if Pos('r', EvStr
) > 0 then
1911 i2
:= I_PLAYER_SCORE_TO_RED
1913 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1914 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1918 if Pos('-', EvStr
) = 0 then
1919 i1
:= I_PLAYER_SCORE_ADD_TEAM
1921 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1923 if Pos('r', EvStr
) > 0 then
1924 i2
:= I_PLAYER_SCORE_RED
1926 i2
:= I_PLAYER_SCORE_BLUE
;
1927 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1932 if Pos('e', EvStr
) = 0 then
1933 i1
:= I_PLAYER_SCORE_WIN_OWN
1935 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1937 if Pos('r', EvStr
) > 0 then
1938 i2
:= I_PLAYER_SCORE_TO_RED
1940 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1941 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1947 if EvNum
= TEAM_RED
then
1948 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1949 if EvNum
= TEAM_BLUE
then
1950 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1951 if EvNum
= -TEAM_RED
then
1952 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1953 if EvNum
= -TEAM_BLUE
then
1954 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1959 g_Player_RemoveAllCorpses
;
1960 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1961 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1965 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1969 if EvNum
= TEAM_RED
then
1970 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1971 if EvNum
= TEAM_BLUE
then
1972 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1976 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1979 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1982 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1985 g_Game_Announce_KillCombo(EvNum
);
1987 NET_EV_PLAYER_TOUCH
:
1989 pl
:= g_Player_Get(EvNum
);
1996 pl
:= g_Player_Get(EvNum
);
1999 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2000 g_Sound_PlayEx('SOUND_GAME_SECRET');
2006 pl
:= g_Player_Get(EvNum
);
2007 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2012 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2021 EvType
:= M
.ReadByte();
2024 if Fl
= FLAG_NONE
then Exit
;
2026 Quiet
:= (M
.ReadByte() <> 0);
2027 PID
:= M
.ReadWord();
2029 gFlags
[Fl
].State
:= M
.ReadByte();
2030 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2031 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2032 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2033 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2034 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2036 Pl
:= g_Player_Get(PID
);
2038 (EvType
<> FLAG_STATE_NORMAL
) and
2039 (EvType
<> FLAG_STATE_DROPPED
) and
2040 (EvType
<> FLAG_STATE_RETURNED
) then
2046 if Quiet
or (Pl
= nil) then Exit
;
2048 if Fl
= FLAG_RED
then
2049 s
:= _lc
[I_PLAYER_FLAG_RED
]
2051 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2053 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2055 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2056 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2057 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2062 if not sound_ret_flag
[a
].IsPlaying() then
2063 sound_ret_flag
[a
].Play();
2066 FLAG_STATE_CAPTURED
:
2068 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2072 if Fl
= FLAG_RED
then
2073 s
:= _lc
[I_PLAYER_FLAG_RED
]
2075 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2077 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2078 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2080 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2081 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2082 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2087 if not sound_get_flag
[a
].IsPlaying() then
2088 sound_get_flag
[a
].Play();
2093 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2095 if Quiet
or (Pl
= nil) then Exit
;
2097 if Fl
= FLAG_RED
then
2098 s
:= _lc
[I_PLAYER_FLAG_RED
]
2100 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2102 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2103 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2105 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2106 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2107 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2112 if not sound_lost_flag
[a
].IsPlaying() then
2113 sound_lost_flag
[a
].Play();
2118 g_Map_ResetFlag(FLAG_RED
);
2119 g_Map_ResetFlag(FLAG_BLUE
);
2120 if Quiet
or (Pl
= nil) then Exit
;
2121 Pl
.SetFlag(FLAG_NONE
);
2123 if Fl
= FLAG_RED
then
2124 s
:= _lc
[I_PLAYER_FLAG_RED
]
2126 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2128 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2129 Insert('.', ts
, Length(ts
) + 1 - 3);
2130 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2131 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2133 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2134 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2135 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2140 if not sound_cap_flag
[a
].IsPlaying() then
2141 sound_cap_flag
[a
].Play();
2144 FLAG_STATE_RETURNED
:
2146 g_Map_ResetFlag(Fl
);
2149 if Fl
= FLAG_RED
then
2150 s
:= _lc
[I_PLAYER_FLAG_RED
]
2152 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2154 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2156 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2157 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2158 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2163 if not sound_ret_flag
[a
].IsPlaying() then
2164 sound_ret_flag
[a
].Play();
2169 procedure MC_RECV_GameSettings(var M
: TMsg
);
2171 gGameSettings
.GameMode
:= M
.ReadByte();
2172 gGameSettings
.GoalLimit
:= M
.ReadWord();
2173 gGameSettings
.TimeLimit
:= M
.ReadWord();
2174 gGameSettings
.MaxLives
:= M
.ReadByte();
2175 gGameSettings
.Options
:= M
.ReadLongWord();
2180 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2183 PName
, Model
: string;
2188 PID
:= M
.ReadWord();
2189 Pl
:= g_Player_Get(PID
);
2191 PName
:= M
.ReadString();
2192 Model
:= M
.ReadString();
2193 Color
.R
:= M
.ReadByte();
2194 Color
.G
:= M
.ReadByte();
2195 Color
.B
:= M
.ReadByte();
2199 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2201 if (Pl
<> nil) then Exit
;
2202 DID
:= g_Player_Create(Model
, Color
, T
, False);
2203 with g_Player_Get(DID
) do
2212 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2213 gPlayer1
.UID
:= PID
;
2214 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2215 gPlayer1
.ChangeTeam(T
);
2217 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2218 gPlayer2
.UID
:= PID
;
2219 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2220 gPlayer2
.ChangeTeam(T
);
2224 if NetDeafLevel
< 3 then
2225 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2226 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2230 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2237 TmpX
, TmpY
: Integer;
2241 GT
:= M
.ReadLongWord();
2242 if GT
< gTime
- NET_MAX_DIFFTIME
then
2249 PID
:= M
.ReadWord();
2250 Pl
:= g_Player_Get(PID
);
2252 if Pl
= nil then Exit
;
2258 FPing
:= M
.ReadWord();
2259 FLoss
:= M
.ReadByte();
2260 kByte
:= M
.ReadWord();
2261 Dir
:= M
.ReadByte();
2263 TmpX
:= M
.ReadLongInt();
2264 TmpY
:= M
.ReadLongInt();
2268 if LongBool(kByte
and NET_KEY_CHAT
) then
2269 PressKey(KEY_CHAT
, 10000)
2272 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2273 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2274 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2275 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2276 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2279 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2281 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2282 SetDirection(TDirection(Dir
));
2284 GameVelX
:= M
.ReadLongInt();
2285 GameVelY
:= M
.ReadLongInt();
2286 GameAccelX
:= M
.ReadLongInt();
2287 GameAccelY
:= M
.ReadLongInt();
2288 SetLerp(TmpX
, TmpY
);
2289 if NetForcePlayerUpdate
then Update();
2293 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2297 I
, OldFire
: Integer;
2298 OldJet
, Flam
: Boolean;
2301 PID
:= M
.ReadWord();
2302 Pl
:= g_Player_Get(PID
);
2309 alive
:= (M
.ReadByte() <> 0);
2310 GodMode
:= (M
.ReadByte() <> 0);
2311 Health
:= M
.ReadLongInt();
2312 Armor
:= M
.ReadLongInt();
2313 Air
:= M
.ReadLongInt();
2314 JetFuel
:= M
.ReadLongInt();
2315 Lives
:= M
.ReadByte();
2316 NewTeam
:= M
.ReadByte();
2318 for I
:= WP_FIRST
to WP_LAST
do
2319 FWeapon
[I
] := (M
.ReadByte() <> 0);
2321 for I
:= A_BULLETS
to A_HIGH
do
2322 FAmmo
[I
] := M
.ReadWord();
2324 for I
:= A_BULLETS
to A_HIGH
do
2325 FMaxAmmo
[I
] := M
.ReadWord();
2327 for I
:= MR_SUIT
to MR_MAX
do
2328 FMegaRulez
[I
] := M
.ReadLongWord();
2331 if (M
.ReadByte() <> 0) then
2332 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2333 if (M
.ReadByte() <> 0) then
2334 FRulez
:= FRulez
+ [R_KEY_RED
];
2335 if (M
.ReadByte() <> 0) then
2336 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2337 if (M
.ReadByte() <> 0) then
2338 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2339 if (M
.ReadByte() <> 0) then
2340 FRulez
:= FRulez
+ [R_BERSERK
];
2342 Frags
:= M
.ReadLongInt();
2343 Death
:= M
.ReadLongInt();
2345 SetWeapon(M
.ReadByte());
2347 FSpectator
:= M
.ReadByte() <> 0;
2350 if UID
= NetPlrUID1
then
2352 gSpectLatchPID1
:= UID
;
2355 if UID
= NetPlrUID2
then
2357 gSpectLatchPID2
:= UID
;
2363 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2366 gSpectLatchPID1
:= 0;
2368 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2371 gSpectLatchPID2
:= 0;
2374 FGhost
:= M
.ReadByte() <> 0;
2375 FPhysics
:= M
.ReadByte() <> 0;
2376 FNoRespawn
:= M
.ReadByte() <> 0;
2378 FJetpack
:= M
.ReadByte() <> 0;
2379 OldFire
:= FFireTime
;
2380 FFireTime
:= M
.ReadLongInt();
2381 if (OldFire
<= 0) and (FFireTime
> 0) then
2382 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2383 Flam
:= M
.ReadByte() <> 0;
2384 FSpawnInvul
:= M
.ReadLongInt();
2385 if OldJet
and not FJetpack
then
2387 else if not OldJet
and FJetpack
then
2389 if FFlaming
and not Flam
then
2391 if Team
<> NewTeam
then
2392 Pl
.ChangeTeam(NewTeam
);
2398 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2403 Attacker
, Value
: Word;
2407 if not gGameOn
then Exit
;
2408 PID
:= M
.ReadWord();
2409 Pl
:= g_Player_Get(PID
);
2410 if Pl
= nil then Exit
;
2412 Kind
:= M
.ReadByte();
2413 Attacker
:= M
.ReadWord();
2414 Value
:= M
.ReadWord();
2419 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2424 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2428 KillType
, DeathType
: Byte;
2432 if not gGameOn
then Exit
;
2433 PID
:= M
.ReadWord();
2434 Pl
:= g_Player_Get(PID
);
2435 if Pl
= nil then Exit
;
2437 KillType
:= M
.ReadByte();
2438 DeathType
:= M
.ReadByte();
2439 Attacker
:= M
.ReadWord();
2443 Kill(KillType
, Attacker
, DeathType
);
2448 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2453 PID
:= M
.ReadWord();
2454 Pl
:= g_Player_Get(PID
);
2456 if Pl
= nil then Exit
;
2458 if NetDeafLevel
< 3 then
2459 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2460 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2462 g_Player_Remove(PID
);
2467 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2472 X
, Y
, AX
, AY
: Integer;
2476 if not gGameOn
then Exit
;
2477 PID
:= M
.ReadWord();
2478 Pl
:= g_Player_Get(PID
);
2479 if Pl
= nil then Exit
;
2481 Weap
:= M
.ReadByte();
2482 X
:= M
.ReadLongInt();
2483 Y
:= M
.ReadLongInt();
2484 AX
:= M
.ReadLongInt();
2485 AY
:= M
.ReadLongInt();
2486 SHID
:= M
.ReadLongInt();
2489 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2492 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2501 PID
:= M
.ReadWord();
2502 Pl
:= g_Player_Get(PID
);
2503 if Pl
= nil then Exit
;
2505 TmpName
:= M
.ReadString();
2506 TmpModel
:= M
.ReadString();
2507 TmpColor
.R
:= M
.ReadByte();
2508 TmpColor
.G
:= M
.ReadByte();
2509 TmpColor
.B
:= M
.ReadByte();
2510 TmpTeam
:= M
.ReadByte();
2512 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2514 Pl
.ChangeTeam(TmpTeam
);
2515 if gPlayer1
= Pl
then
2516 gPlayer1Settings
.Team
:= TmpTeam
;
2517 if gPlayer2
= Pl
then
2518 gPlayer2Settings
.Team
:= TmpTeam
;
2520 Pl
.SetColor(TmpColor
);
2522 if Pl
.Name
<> TmpName
then
2524 if NetDeafLevel
< 3 then
2525 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2529 if TmpModel
<> Pl
.Model
.GetName() then
2530 Pl
.SetModel(TmpModel
);
2535 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2538 X
, Y
, VX
, VY
: Integer;
2540 Quiet
, Fall
{, Resp}: Boolean;
2543 if not gGameOn
then Exit
;
2545 Quiet
:= M
.ReadByte() <> 0;
2547 Fall
:= M
.ReadByte() <> 0;
2548 {Resp :=} M
.ReadByte();
2549 X
:= M
.ReadLongInt();
2550 Y
:= M
.ReadLongInt();
2551 VX
:= M
.ReadLongInt();
2552 VY
:= M
.ReadLongInt();
2554 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2555 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2557 it
:= g_Items_ByIdx(ID
);
2563 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2565 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN
, X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16);
2570 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2575 if not gGameOn
then Exit
;
2577 Quiet
:= M
.ReadByte() <> 0;
2579 if not g_Items_ValidId(ID
) then exit
;
2581 if not Quiet
then g_Items_EmitPickupSound(ID
);
2588 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2595 if not gGameOn
then Exit
;
2597 PGUID
:= Integer(M
.ReadLongWord());
2598 Tex
:= M
.ReadLongInt();
2599 Fr
:= M
.ReadLongInt();
2600 Cnt
:= M
.ReadByte();
2601 Loop
:= M
.ReadByte();
2603 TP
:= g_Map_PanelByGUID(PGUID
);
2607 TP
.SetTexture(Tex
, Loop
);
2608 TP
.SetFrame(Fr
, Cnt
);
2612 procedure MC_RECV_PanelState(var M
: TMsg
);
2617 X
, Y
, W
, H
: Integer;
2619 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2620 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2623 if not gGameOn
then Exit
;
2625 PGUID
:= Integer(M
.ReadLongWord());
2626 E
:= (M
.ReadByte() <> 0);
2627 Lift
:= M
.ReadByte();
2628 X
:= M
.ReadLongInt();
2629 Y
:= M
.ReadLongInt();
2633 speedX
:= M
.ReadLongInt();
2634 speedY
:= M
.ReadLongInt();
2635 startX
:= M
.ReadLongInt();
2636 startY
:= M
.ReadLongInt();
2637 endX
:= M
.ReadLongInt();
2638 endY
:= M
.ReadLongInt();
2639 sizeSpX
:= M
.ReadLongInt();
2640 sizeSpY
:= M
.ReadLongInt();
2641 sizeEX
:= M
.ReadLongInt();
2642 sizeEY
:= M
.ReadLongInt();
2643 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2645 TP
:= g_Map_PanelByGUID(PGUID
);
2646 if (TP
= nil) then exit
;
2648 // update lifts state
2649 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2651 // update enabled/disabled state for all panels
2652 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2654 // update panel position, as it can be moved (mplat)
2659 // update mplat state
2660 TP
.movingSpeedX
:= speedX
;
2661 TP
.movingSpeedY
:= speedY
;
2662 TP
.movingStartX
:= startX
;
2663 TP
.movingStartY
:= startY
;
2664 TP
.movingEndX
:= endX
;
2665 TP
.movingEndY
:= endY
;
2666 TP
.sizeSpeedX
:= sizeSpX
;
2667 TP
.sizeSpeedY
:= sizeSpY
;
2668 TP
.sizeEndX
:= sizeEX
;
2669 TP
.sizeEndY
:= sizeEY
;
2670 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2671 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2672 // notify panel of it's position/size change, so it can fix other internal structures
2673 TP
.positionChanged();
2678 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2681 SPos
, SID
: LongWord;
2685 if not gGameOn
then Exit
;
2686 if gTriggers
= nil then Exit
;
2688 SID
:= M
.ReadLongWord();
2689 SPlaying
:= M
.ReadByte() <> 0;
2690 SPos
:= M
.ReadLongWord();
2691 SCount
:= M
.ReadLongInt();
2693 for I
:= Low(gTriggers
) to High(gTriggers
) do
2694 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2695 if gTriggers
[I
].ClientID
= SID
then
2696 with gTriggers
[I
] do
2698 if Sound
<> nil then
2703 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2705 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2706 Sound
.SetPosition(SPos
);
2709 if Sound
.IsPlaying
then Sound
.Stop
;
2712 SoundPlayCount
:= SCount
;
2716 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2723 if not gGameOn
then Exit
;
2725 MName
:= M
.ReadString();
2726 MPlaying
:= M
.ReadByte() <> 0;
2727 MPos
:= M
.ReadLongWord();
2728 MPaused
:= M
.ReadByte() <> 0;
2729 MPos
:= MPos
+1; //k8: stfu, fpc!
2733 gMusic
.SetByName(MName
);
2735 // gMusic.SetPosition(MPos);
2736 gMusic
.SpecPause
:= MPaused
;
2739 if gMusic
.IsPlaying
then gMusic
.Stop
;
2744 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2747 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2748 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2753 Mon
:= g_Monsters_ByUID(ID
);
2757 MType
:= M
.ReadByte();
2758 MState
:= M
.ReadByte();
2759 MAnim
:= M
.ReadByte();
2760 MTarg
:= M
.ReadWord();
2761 MTargTime
:= M
.ReadLongInt();
2762 MBehav
:= M
.ReadByte();
2763 MSleep
:= M
.ReadLongInt();
2764 MHealth
:= M
.ReadLongInt();
2765 MAmmo
:= M
.ReadLongInt();
2767 X
:= M
.ReadLongInt();
2768 Y
:= M
.ReadLongInt();
2769 VX
:= M
.ReadLongInt();
2770 VY
:= M
.ReadLongInt();
2771 MDir
:= M
.ReadByte();
2773 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2774 Mon
:= g_Monsters_ByUID(ID
);
2781 MonsterAnim
:= MAnim
;
2782 MonsterTargetUID
:= MTarg
;
2783 MonsterTargetTime
:= MTargTime
;
2784 MonsterBehaviour
:= MBehav
;
2785 MonsterSleep
:= MSleep
;
2786 MonsterAmmo
:= MAmmo
;
2791 setPosition(X
, Y
); // this will call positionChanged();
2797 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2804 Mon
:= g_Monsters_ByUID(ID
);
2810 X
:= M
.ReadLongInt();
2811 Y
:= M
.ReadLongInt();
2812 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2813 GameVelX
:= M
.ReadLongInt();
2814 GameVelY
:= M
.ReadLongInt();
2815 GameDirection
:= TDirection(M
.ReadByte());
2819 procedure MC_RECV_MonsterState(var M
: TMsg
);
2821 ID
, OldFire
: Integer;
2822 MState
, MFAnm
: Byte;
2824 AnimRevert
: Boolean;
2827 Mon
:= g_Monsters_ByUID(ID
);
2828 if Mon
= nil then Exit
;
2830 MState
:= M
.ReadByte();
2831 MFAnm
:= M
.ReadByte();
2835 MonsterTargetUID
:= M
.ReadWord();
2836 MonsterTargetTime
:= M
.ReadLongInt();
2837 MonsterSleep
:= M
.ReadLongInt();
2838 MonsterHealth
:= M
.ReadLongInt();
2839 MonsterAmmo
:= M
.ReadLongInt();
2840 MonsterPain
:= M
.ReadLongInt();
2841 AnimRevert
:= M
.ReadByte() <> 0;
2842 OldFire
:= FFireTime
;
2843 FFireTime
:= M
.ReadLongInt();
2844 if (OldFire
<= 0) and (FFireTime
> 0) then
2845 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2846 RevertAnim(AnimRevert
);
2848 if MonsterState
<> MState
then
2850 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2851 if (MState
= MONSTATE_DIE
) then DieSound();
2852 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2853 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2854 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2856 SetState(MState
, MFAnm
);
2861 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2865 X
, Y
, VX
, VY
: Integer;
2869 Mon
:= g_Monsters_ByUID(ID
);
2870 if Mon
= nil then Exit
;
2872 X
:= M
.ReadLongInt();
2873 Y
:= M
.ReadLongInt();
2874 VX
:= M
.ReadLongInt();
2875 VY
:= M
.ReadLongInt();
2877 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2880 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2886 Mon
:= g_Monsters_ByUID(ID
);
2887 if Mon
= nil then Exit
;
2889 Mon
.MonsterRemoved
:= True;
2892 procedure MC_RECV_TimeSync(var M
: TMsg
);
2896 Time
:= M
.ReadLongWord();
2898 if gState
= STATE_INTERCUSTOM
then
2899 gServInterTime
:= Min(Time
, 255);
2902 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2906 Int1
, Int2
: SmallInt;
2908 EvID
:= M
.ReadByte();
2909 Int1
:= M
.ReadSmallInt();
2910 Int2
:= M
.ReadSmallInt();
2911 Str1
:= M
.ReadString();
2912 Str2
:= M
.ReadString();
2914 if NetDeafLevel
< 2 then
2917 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2919 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2921 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2923 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2925 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2931 procedure MC_SEND_Info(Password
: string);
2935 NetOut
.Write(Byte(NET_MSG_INFO
));
2936 NetOut
.Write(GAME_VERSION
);
2937 NetOut
.Write(Password
);
2938 NetOut
.Write(gPlayer1Settings
.Name
);
2939 NetOut
.Write(gPlayer1Settings
.Model
);
2940 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2941 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2942 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2943 NetOut
.Write(gPlayer1Settings
.Team
);
2945 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2948 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2950 NetOut
.Write(Byte(NET_MSG_CHAT
));
2954 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2957 procedure MC_SEND_PlayerPos();
2962 WeaponSelect
: Word = 0;
2965 if not gGameOn
then Exit
;
2966 if gPlayers
= nil then Exit
;
2967 if gPlayer1
= nil then Exit
;
2970 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2972 {$IFDEF DISABLE_MENU}
2973 if (not gConsoleShow
) and (not gChatShow
) then
2975 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2978 strafeDir
:= P1MoveButton
shr 4;
2979 P1MoveButton
:= P1MoveButton
and $0F;
2981 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2983 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2985 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2989 if gPlayerAction
[0, ACTION_STRAFE
] then
2991 // new strafe mechanics
2992 if (strafeDir
= 0) then
2993 strafeDir
:= P1MoveButton
; // start strafing
2994 // now set direction according to strafe (reversed)
2995 if (strafeDir
= 2) then
2996 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2997 else if (strafeDir
= 1) then
2998 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3002 strafeDir
:= 0; // not strafing anymore
3003 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3004 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3005 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3006 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3007 else if P1MoveButton
<> 0 then
3008 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3011 gPlayer1
.ReleaseKeys
;
3012 if P1MoveButton
= 1 then
3014 kByte
:= kByte
or NET_KEY_LEFT
;
3015 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3017 if P1MoveButton
= 2 then
3019 kByte
:= kByte
or NET_KEY_RIGHT
;
3020 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3022 if gPlayerAction
[0, ACTION_LOOKUP
] then
3024 kByte
:= kByte
or NET_KEY_UP
;
3025 gPlayer1
.PressKey(KEY_UP
, 10000);
3027 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3029 kByte
:= kByte
or NET_KEY_DOWN
;
3030 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3032 if gPlayerAction
[0, ACTION_JUMP
] then
3034 kByte
:= kByte
or NET_KEY_JUMP
;
3035 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3037 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3038 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3039 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
3040 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
3042 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3043 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3045 for i
:= WP_FIRST
to WP_LAST
do
3047 if gSelectWeapon
[0, i
] then
3049 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3050 gSelectWeapon
[0, i
] := False
3054 // fix movebutton state
3055 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3058 kByte
:= NET_KEY_CHAT
;
3060 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3061 NetOut
.Write(gTime
);
3062 NetOut
.Write(kByte
);
3063 NetOut
.Write(Byte(gPlayer1
.Direction
));
3064 NetOut
.Write(WeaponSelect
);
3065 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3066 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3068 //kBytePrev := kByte;
3069 //kDirPrev := gPlayer1.Direction;
3072 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3074 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3075 NetOut
.Write(Byte(Start
));
3076 NetOut
.Write(Command
);
3077 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3080 procedure MC_SEND_PlayerSettings();
3082 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3083 NetOut
.Write(gPlayer1Settings
.Name
);
3084 NetOut
.Write(gPlayer1Settings
.Model
);
3085 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3086 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3087 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3088 NetOut
.Write(gPlayer1Settings
.Team
);
3090 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3093 procedure MC_SEND_FullStateRequest();
3095 NetOut
.Write(Byte(NET_MSG_REQFST
));
3097 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3100 procedure MC_SEND_CheatRequest(Kind
: Byte);
3102 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3105 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3107 procedure MC_SEND_RCONPassword(Password
: string);
3109 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3110 NetOut
.Write(Password
);
3112 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3114 procedure MC_SEND_RCONCommand(Cmd
: string);
3116 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3119 g_Net_Client_Send(True, NET_CHAN_SERVICE
);