aec47c7ff524d3c16de2bc4da6f2e9ea350f2172
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;
121 NET_VE_INPROGRESS
= 6;
128 NET_CHEAT_SUICIDE
= 1;
129 NET_CHEAT_SPECTATE
= 2;
132 NET_MAX_DIFFTIME
= 5000 div 36;
136 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
138 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
139 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
140 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
141 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
142 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
143 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
146 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
147 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
148 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
151 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
152 procedure MH_SEND_Info(ID
: Byte);
153 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
154 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
170 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
186 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
189 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
190 procedure MH_SEND_VoteEvent(EvType
: Byte;
191 StrArg1
: string = 'a'; StrArg2
: string = 'b';
192 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
193 ID
: Integer = NET_EVERYONE
);
195 // CLIENT MESSAGES //
198 procedure MC_RECV_Chat(var M
: TMsg
);
199 procedure MC_RECV_Effect(var M
: TMsg
);
200 procedure MC_RECV_Sound(var M
: TMsg
);
201 procedure MC_RECV_GameStats(var M
: TMsg
);
202 procedure MC_RECV_CoopStats(var M
: TMsg
);
203 procedure MC_RECV_GameEvent(var M
: TMsg
);
204 procedure MC_RECV_FlagEvent(var M
: TMsg
);
205 procedure MC_RECV_GameSettings(var M
: TMsg
);
207 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
208 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
209 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
210 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
211 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
212 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
213 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
214 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
216 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
217 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
219 procedure MC_RECV_PanelTexture(var M
: TMsg
);
220 procedure MC_RECV_PanelState(var M
: TMsg
);
222 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
223 procedure MC_RECV_MonsterPos(var M
: TMsg
);
224 procedure MC_RECV_MonsterState(var M
: TMsg
);
225 procedure MC_RECV_MonsterShot(var M
: TMsg
);
226 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
228 procedure MC_RECV_CreateShot(var M
: TMsg
);
229 procedure MC_RECV_UpdateShot(var M
: TMsg
);
230 procedure MC_RECV_DeleteShot(var M
: TMsg
);
232 procedure MC_RECV_TriggerSound(var M
: TMsg
);
233 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
235 procedure MC_RECV_TimeSync(var M
: TMsg
);
236 procedure MC_RECV_VoteEvent(var M
: TMsg
);
238 procedure MC_SEND_Info(Password
: string);
239 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
240 procedure MC_SEND_PlayerPos();
241 procedure MC_SEND_FullStateRequest();
242 procedure MC_SEND_PlayerSettings();
243 procedure MC_SEND_CheatRequest(Kind
: Byte);
244 procedure MC_SEND_RCONPassword(Password
: string);
245 procedure MC_SEND_RCONCommand(Cmd
: string);
246 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
248 //procedure MC_SEND_MapRequest();
249 //procedure MC_SEND_ResRequest(const resName: AnsiString);
253 TExternalResourceInfo
= record
268 ExternalResources
: array of TExternalResourceInfo
;
271 function IsValidFileName(const S
: String): Boolean;
272 function IsValidFilePath(const S
: String): Boolean;
278 Math
, ENet
, e_input
, e_graphics
, e_log
,
279 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
280 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
281 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
294 NET_KEY_FORCEDIR
= 4096;
297 //kBytePrev: Word = 0;
298 //kDirPrev: TDirection = D_LEFT;
299 //HostGameTime: Word = 0;
302 function IsValidFileName(const S
: String): Boolean;
304 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
309 for I
:= 1 to Length(S
) do
310 Result
:= Result
and (not(S
[I
] in Forbidden
));
313 function IsValidFilePath(const S
: String): Boolean;
318 if not IsValidFileName(S
) then exit
;
319 if FileExists(S
) then exit
;
320 I
:= LastDelimiter('\/', S
);
322 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
333 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
341 Pl
:= g_Player_Get(PID
);
343 Txt
:= M
.ReadString();
344 Mode
:= M
.ReadByte();
345 if (Mode
= NET_CHAT_SYSTEM
) then
346 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
347 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
348 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
351 MH_SEND_Chat(Txt
, Mode
)
353 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
356 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
358 Ver
, PName
, Model
, Pw
: string;
364 Ver
:= M
.ReadString();
365 Pw
:= M
.ReadString();
366 PName
:= M
.ReadString();
367 Model
:= M
.ReadString();
373 if Ver
<> GAME_VERSION
then
375 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
376 _lc
[I_NET_DISC_VERSION
]);
377 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
381 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
383 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
385 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
386 _lc
[I_NET_DISC_BAN
]);
387 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
391 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
392 _lc
[I_NET_DISC_BAN
]);
393 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
398 if NetPassword
<> '' then
399 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
401 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
402 _lc
[I_NET_DISC_PASSWORD
]);
403 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
411 PID
:= g_Player_Create(Model
, Color
, T
, False);
412 with g_Player_Get(PID
) do
419 C
^.WaitForFirstSpawn
:= false;
421 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
422 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
423 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
427 with g_Player_Get(PID
) do
431 // round in progress, don't spawn
432 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
437 FWantsInGame
:= True; // TODO: look into this later
438 C
^.WaitForFirstSpawn
:= true;
442 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
443 //e_LogWritefln('spawning player with pid #%u...', [PID]);
444 //Respawn(gGameSettings.GameType = GT_SINGLE);
445 //k8: no, do not spawn a player yet, wait for "request full state" packet
449 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
450 // that is, if we'll set it to `true`, the player can be spawned after
451 // warmup time ran out, for example, regardless of the real player state.
452 // also, this seems to work only for the initial connection. further
453 // map changes could initiate resource downloading, but the player will
454 // be spawned immediately.
455 // the proper solution will require another player state, "ephemeral".
456 // the player should start any map in "ephemeral" state, and turned into
457 // real mobj only when they sent a special "i am ready" packet. this packet
458 // must be sent after receiving the full state, so the player will get a full
459 // map view before going into game.
460 FWantsInGame
:= false;
461 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
503 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
505 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
508 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
512 C
^.RequestedFullUpdate
:= True;
518 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 WeaponSelect
:= M
.ReadWord();
544 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
545 if Direction
<> TDirection(Dir
) then
546 JustTeleported
:= False;
548 SetDirection(TDirection(Dir
));
551 if kByte
= NET_KEY_CHAT
then
553 PressKey(KEY_CHAT
, 10000);
557 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
558 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
559 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
560 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
561 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
562 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
563 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
564 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
565 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
569 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
571 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
572 QueueWeaponSwitch(i
);
577 // MH_SEND_PlayerPos(False, PID, C^.ID);
580 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
585 Pl
:= g_Player_Get(C
^.Player
);
586 if Pl
= nil then Exit
;
588 CheatKind
:= M
.ReadByte();
592 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
595 if Pl
.FSpectator
then
602 if gState
<> STATE_INTERCUSTOM
then Exit
;
603 Pl
.FReady
:= not Pl
.FReady
;
606 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
607 Inc(gInterReadyCount
);
611 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
612 Dec(gInterReadyCount
);
618 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
626 TmpName
:= M
.ReadString();
627 TmpModel
:= M
.ReadString();
628 TmpColor
.R
:= M
.ReadByte();
629 TmpColor
.G
:= M
.ReadByte();
630 TmpColor
.B
:= M
.ReadByte();
631 TmpTeam
:= M
.ReadByte();
633 Pl
:= g_Player_Get(C
^.Player
);
634 if Pl
= nil then Exit
;
636 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
639 Pl
.SetColor(TmpColor
);
641 if Pl
.Name
<> TmpName
then
643 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
647 if TmpModel
<> Pl
.Model
.Name
then
648 Pl
.SetModel(TmpModel
);
650 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
655 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
659 Pwd
:= M
.ReadString();
660 if not NetAllowRCON
then Exit
;
661 if Pwd
= NetRCONPassword
then
664 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
667 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
670 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
674 Cmd
:= M
.ReadString();
675 if not NetAllowRCON
then Exit
;
676 if not C
^.RCONAuth
then
678 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
681 g_Console_Process(Cmd
);
686 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
689 Name
, Command
: string;
693 Start
:= M
.ReadByte() <> 0;
694 Command
:= M
.ReadString();
696 Pl
:= g_Player_Get(C
^.Player
);
697 if Pl
= nil then Exit
;
702 if not g_Console_CommandBlacklisted(Command
) then
703 g_Game_StartVote(Command
, Name
);
705 else if gVoteInProgress
then
707 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
708 Need
:= Floor((NetClientCount
+1)/2.0) + 1
710 Need
:= Floor(NetClientCount
/2.0) + 1;
715 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
716 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
722 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
723 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
731 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
733 function sendItemRespawn (it
: PItem
): Boolean;
735 result
:= false; // don't stop
736 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
739 function sendMonSpawn (mon
: TMonster
): Boolean;
741 result
:= false; // don't stop
742 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
745 function sendPanelState (pan
: TPanel
): Boolean;
747 result
:= false; // don't stop
748 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
749 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
755 if (ID
>= 0) and (ID
< length(NetClients
)) then
757 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
758 MH_ProcessFirstSpawn(@NetClients
[ID
]);
761 if gPlayers
<> nil then
763 for I
:= Low(gPlayers
) to High(gPlayers
) do
765 if gPlayers
[I
] <> nil then
767 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
768 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
769 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
771 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
773 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
779 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
780 g_Mons_ForEach(sendMonSpawn
);
781 g_Map_ForEachPanel(sendPanelState
);
783 if gTriggers
<> nil then
785 for I
:= Low(gTriggers
) to High(gTriggers
) do
787 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
789 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
796 for I
:= Low(Shots
) to High(Shots
) do
798 if Shots
[i
].ShotType
in [6, 7, 8] then
800 MH_SEND_CreateShot(i
, ID
);
805 MH_SEND_TriggerMusic(ID
);
807 MH_SEND_GameStats(ID
);
808 MH_SEND_CoopStats(ID
);
810 if gGameSettings
.GameMode
= GM_CTF
then
812 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
813 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
816 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
818 if gLMSRespawn
> LMS_RESPAWN_NONE
then
820 e_LogWritefln('*** client #%u (cid #%u) WARMUP', [ID
, NetClients
[ID
].Player
]);
821 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
827 procedure MH_SEND_Info(ID
: Byte);
831 Map
:= g_ExtractFileName(gMapInfo
.Map
);
835 NetOut
.Write(Byte(NET_MSG_INFO
));
837 NetOut
.Write(NetClients
[ID
].Player
);
838 NetOut
.Write(gGameSettings
.WAD
);
840 NetOut
.Write(gWADHash
);
841 NetOut
.Write(gGameSettings
.GameMode
);
842 NetOut
.Write(gGameSettings
.GoalLimit
);
843 NetOut
.Write(gGameSettings
.TimeLimit
);
844 NetOut
.Write(gGameSettings
.MaxLives
);
845 NetOut
.Write(gGameSettings
.Options
);
848 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
851 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
857 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
858 Mode
:= NET_CHAT_PLAYER
;
861 if (Mode
= NET_CHAT_TEAM
) then
863 for i
:= Low(gPlayers
) to High(gPlayers
) do
864 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
865 (gPlayers
[i
].Team
= ID
) then
867 NetOut
.Write(Byte(NET_MSG_CHAT
));
870 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
877 NetOut
.Write(Byte(NET_MSG_CHAT
));
880 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
883 if Mode
= NET_CHAT_SYSTEM
then
886 if ID
= NET_EVERYONE
then
888 if Mode
= NET_CHAT_PLAYER
then
890 g_Console_Add(Txt
, True);
891 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
892 g_Game_ChatSound(b_Text_Unformat(Txt
));
895 if Mode
= NET_CHAT_TEAM
then
896 if gPlayer1
<> nil then
898 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
900 g_Console_Add(#18'[Team] '#2 + Txt
, True);
901 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
902 g_Game_ChatSound(b_Text_Unformat(Txt
));
904 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
906 g_Console_Add(#20'[Team] '#2 + Txt
, True);
907 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
908 g_Game_ChatSound(b_Text_Unformat(Txt
));
914 Name
:= g_Net_ClientName_ByID(ID
);
915 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
916 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
917 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
921 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
923 NetOut
.Write(Byte(NET_MSG_GFX
));
929 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
932 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
934 NetOut
.Write(Byte(NET_MSG_SND
));
938 NetOut
.Write(Byte(1));
943 NetOut
.Write(Byte(0));
945 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
948 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
950 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
952 NetOut
.Write(Byte(NET_MSG_SHADD
));
954 NetOut
.Write(Shots
[Proj
].ShotType
);
955 NetOut
.Write(Shots
[Proj
].Target
);
956 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
957 NetOut
.Write(Shots
[Proj
].Timeout
);
958 NetOut
.Write(Shots
[Proj
].Obj
.X
);
959 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
960 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
961 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
963 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
966 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
968 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
970 NetOut
.Write(Byte(NET_MSG_SHPOS
));
972 NetOut
.Write(Shots
[Proj
].Obj
.X
);
973 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
974 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
975 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
977 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
980 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
982 NetOut
.Write(Byte(NET_MSG_SHDEL
));
984 NetOut
.Write(Byte(Loud
));
988 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
991 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
993 NetOut
.Write(Byte(NET_MSG_SCORE
));
994 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
996 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
997 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1000 if gGameSettings
.GameMode
= GM_COOP
then
1002 NetOut
.Write(gCoopMonstersKilled
);
1003 NetOut
.Write(gCoopSecretsFound
);
1006 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1009 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1011 NetOut
.Write(Byte(NET_MSG_COOP
));
1012 NetOut
.Write(gTotalMonsters
);
1013 NetOut
.Write(gSecretsCount
);
1014 NetOut
.Write(gCoopTotalMonstersKilled
);
1015 NetOut
.Write(gCoopTotalSecretsFound
);
1016 NetOut
.Write(gCoopTotalMonsters
);
1017 NetOut
.Write(gCoopTotalSecrets
);
1020 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1022 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1023 NetOut
.Write(EvType
);
1024 NetOut
.Write(EvNum
);
1025 NetOut
.Write(EvStr
);
1026 NetOut
.Write(Byte(gLastMap
));
1027 NetOut
.Write(gTime
);
1028 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1030 NetOut
.Write(Byte(1));
1031 NetOut
.Write(gWADHash
);
1033 NetOut
.Write(Byte(0));
1035 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1038 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1040 NetOut
.Write(Byte(NET_MSG_FLAG
));
1041 NetOut
.Write(EvType
);
1043 NetOut
.Write(Byte(Quiet
));
1045 NetOut
.Write(gFlags
[Flag
].State
);
1046 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1047 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1048 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1049 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1050 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1052 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1055 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1057 NetOut
.Write(Byte(NET_MSG_GSET
));
1058 NetOut
.Write(gGameSettings
.GameMode
);
1059 NetOut
.Write(gGameSettings
.GoalLimit
);
1060 NetOut
.Write(gGameSettings
.TimeLimit
);
1061 NetOut
.Write(gGameSettings
.MaxLives
);
1062 NetOut
.Write(gGameSettings
.Options
);
1064 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1069 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1073 P
:= g_Player_Get(PID
);
1074 if P
= nil then Exit
;
1076 NetOut
.Write(Byte(NET_MSG_PLR
));
1078 NetOut
.Write(P
.Name
);
1080 NetOut
.Write(P
.FActualModelName
);
1081 NetOut
.Write(P
.FColor
.R
);
1082 NetOut
.Write(P
.FColor
.G
);
1083 NetOut
.Write(P
.FColor
.B
);
1084 NetOut
.Write(P
.Team
);
1086 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1089 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1094 Pl
:= g_Player_Get(PID
);
1095 if Pl
= nil then Exit
;
1096 if Pl
.FDummy
then Exit
;
1098 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1099 NetOut
.Write(gTime
);
1106 NetOut
.Write(FPing
);
1107 NetOut
.Write(FLoss
);
1108 if IsKeyPressed(KEY_CHAT
) then
1109 kByte
:= NET_KEY_CHAT
1112 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1113 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1114 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1115 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1116 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1117 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1120 NetOut
.Write(kByte
);
1121 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1122 NetOut
.Write(GameX
);
1123 NetOut
.Write(GameY
);
1124 NetOut
.Write(GameVelX
);
1125 NetOut
.Write(GameVelY
);
1126 NetOut
.Write(GameAccelX
);
1127 NetOut
.Write(GameAccelY
);
1130 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1133 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1138 P
:= g_Player_Get(PID
);
1139 if P
= nil then Exit
;
1141 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1146 NetOut
.Write(Byte(alive
));
1147 NetOut
.Write(Byte(GodMode
));
1148 NetOut
.Write(Health
);
1149 NetOut
.Write(Armor
);
1151 NetOut
.Write(JetFuel
);
1152 NetOut
.Write(Lives
);
1155 for I
:= WP_FIRST
to WP_LAST
do
1156 NetOut
.Write(Byte(FWeapon
[I
]));
1158 for I
:= A_BULLETS
to A_HIGH
do
1159 NetOut
.Write(FAmmo
[I
]);
1161 for I
:= A_BULLETS
to A_HIGH
do
1162 NetOut
.Write(FMaxAmmo
[I
]);
1164 for I
:= MR_SUIT
to MR_MAX
do
1165 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1167 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1168 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1169 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1170 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1171 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1173 NetOut
.Write(Frags
);
1174 NetOut
.Write(Death
);
1176 NetOut
.Write(CurrWeap
);
1178 NetOut
.Write(Byte(FSpectator
));
1179 NetOut
.Write(Byte(FGhost
));
1180 NetOut
.Write(Byte(FPhysics
));
1181 NetOut
.Write(Byte(FNoRespawn
));
1182 NetOut
.Write(Byte(FJetpack
));
1183 NetOut
.Write(FFireTime
);
1184 NetOut
.Write(Byte(FFlaming
));
1187 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1190 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1192 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1195 NetOut
.Write(Attacker
);
1196 NetOut
.Write(Value
);
1200 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1203 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1205 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1207 NetOut
.Write(KillType
);
1208 NetOut
.Write(DeathType
);
1209 NetOut
.Write(Attacker
);
1211 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1214 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1216 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1218 NetOut
.Write(Weapon
);
1223 NetOut
.Write(ShotID
);
1225 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1228 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1230 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1233 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1236 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1240 Pl
:= g_Player_Get(PID
);
1241 if Pl
= nil then Exit
;
1243 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1245 NetOut
.Write(Pl
.Name
);
1247 NetOut
.Write(Pl
.Model
.Name
)
1250 NetOut
.Write(Pl
.FColor
.R
);
1251 NetOut
.Write(Pl
.FColor
.G
);
1252 NetOut
.Write(Pl
.FColor
.B
);
1253 NetOut
.Write(Pl
.Team
);
1255 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1260 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1265 it
:= g_Items_ByIdx(IID
);
1267 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1269 NetOut
.Write(Byte(Quiet
));
1271 if it
.dropped
then tt
:= tt
or $80;
1273 NetOut
.Write(Byte(it
.Fall
));
1274 NetOut
.Write(Byte(it
.Respawnable
));
1275 NetOut
.Write(it
.Obj
.X
);
1276 NetOut
.Write(it
.Obj
.Y
);
1277 NetOut
.Write(it
.Obj
.Vel
.X
);
1278 NetOut
.Write(it
.Obj
.Vel
.Y
);
1280 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1283 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1285 NetOut
.Write(Byte(NET_MSG_IDEL
));
1287 NetOut
.Write(Byte(Quiet
));
1289 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1294 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1298 TP
:= g_Map_PanelByGUID(PGUID
);
1299 if (TP
= nil) then exit
;
1303 NetOut
.Write(Byte(NET_MSG_PTEX
));
1304 NetOut
.Write(LongWord(PGUID
));
1305 NetOut
.Write(FCurTexture
);
1306 NetOut
.Write(FCurFrame
);
1307 NetOut
.Write(FCurFrameCount
);
1308 NetOut
.Write(AnimLoop
);
1311 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1314 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1319 TP
:= g_Map_PanelByGUID(PGUID
);
1320 if (TP
= nil) then exit
;
1322 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1323 NetOut
.Write(LongWord(PGUID
));
1324 NetOut
.Write(Byte(TP
.Enabled
));
1325 NetOut
.Write(TP
.LiftType
);
1328 NetOut
.Write(Word(TP
.Width
));
1329 NetOut
.Write(Word(TP
.Height
));
1331 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1332 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1333 NetOut
.Write(LongInt(TP
.movingStartX
));
1334 NetOut
.Write(LongInt(TP
.movingStartY
));
1335 NetOut
.Write(LongInt(TP
.movingEndX
));
1336 NetOut
.Write(LongInt(TP
.movingEndY
));
1337 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1338 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1339 NetOut
.Write(LongInt(TP
.sizeEndX
));
1340 NetOut
.Write(LongInt(TP
.sizeEndY
));
1341 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1342 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1343 NetOut
.Write(Byte(mpflags
));
1345 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1350 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1352 if gTriggers
= nil then Exit
;
1353 if T
.Sound
= nil then Exit
;
1355 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1356 NetOut
.Write(T
.ClientID
);
1357 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1358 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1359 NetOut
.Write(T
.SoundPlayCount
);
1361 g_Net_Host_Send(ID
, True);
1364 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1366 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1367 NetOut
.Write(gMusic
.Name
);
1368 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1369 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1370 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1372 g_Net_Host_Send(ID
, True);
1377 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1381 M
:= g_Monsters_ByUID(UID
);
1387 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1389 NetOut
.Write(MonsterType
);
1390 NetOut
.Write(MonsterState
);
1391 NetOut
.Write(MonsterAnim
);
1392 NetOut
.Write(MonsterTargetUID
);
1393 NetOut
.Write(MonsterTargetTime
);
1394 NetOut
.Write(MonsterBehaviour
);
1395 NetOut
.Write(MonsterSleep
);
1396 NetOut
.Write(MonsterHealth
);
1397 NetOut
.Write(MonsterAmmo
);
1398 NetOut
.Write(GameX
);
1399 NetOut
.Write(GameY
);
1400 NetOut
.Write(GameVelX
);
1401 NetOut
.Write(GameVelY
);
1402 NetOut
.Write(Byte(GameDirection
));
1405 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1408 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1412 M
:= g_Monsters_ByUID(UID
);
1413 if M
= nil then Exit
;
1415 NetOut
.Write(Byte(NET_MSG_MPOS
));
1420 NetOut
.Write(GameX
);
1421 NetOut
.Write(GameY
);
1422 NetOut
.Write(GameVelX
);
1423 NetOut
.Write(GameVelY
);
1424 NetOut
.Write(Byte(GameDirection
));
1427 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1430 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1434 M
:= g_Monsters_ByUID(UID
);
1435 if M
= nil then Exit
;
1437 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1442 NetOut
.Write(MonsterState
);
1443 NetOut
.Write(ForcedAnim
);
1444 NetOut
.Write(MonsterTargetUID
);
1445 NetOut
.Write(MonsterTargetTime
);
1446 NetOut
.Write(MonsterSleep
);
1447 NetOut
.Write(MonsterHealth
);
1448 NetOut
.Write(MonsterAmmo
);
1449 NetOut
.Write(MonsterPain
);
1450 NetOut
.Write(Byte(AnimIsReverse
));
1451 NetOut
.Write(FFireTime
);
1454 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1457 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1459 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1466 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1469 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1473 M
:= g_Monsters_ByUID(UID
);
1474 if M
= nil then Exit
;
1476 NetOut
.Write(Byte(NET_MSG_MDEL
));
1479 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1484 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1486 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1489 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1492 procedure MH_SEND_VoteEvent(EvType
: Byte;
1493 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1494 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1495 ID
: Integer = NET_EVERYONE
);
1497 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1498 NetOut
.Write(EvType
);
1499 NetOut
.Write(IntArg1
);
1500 NetOut
.Write(IntArg2
);
1501 NetOut
.Write(StrArg1
);
1502 NetOut
.Write(StrArg2
);
1504 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1507 // CLIENT MESSAGES //
1511 procedure MC_RECV_Chat(var M
: TMsg
);
1516 Txt
:= M
.ReadString();
1517 Mode
:= M
.ReadByte();
1519 if Mode
<> NET_CHAT_SYSTEM
then
1521 if Mode
= NET_CHAT_PLAYER
then
1523 g_Console_Add(Txt
, True);
1524 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1525 g_Game_ChatSound(b_Text_Unformat(Txt
));
1527 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1529 if gPlayer1
.Team
= TEAM_RED
then
1530 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1531 if gPlayer1
.Team
= TEAM_BLUE
then
1532 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1533 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1534 g_Game_ChatSound(b_Text_Unformat(Txt
));
1537 g_Console_Add(Txt
, True);
1540 procedure MC_RECV_Effect(var M
: TMsg
);
1548 if not gGameOn
then Exit
;
1549 Kind
:= M
.ReadByte();
1550 X
:= M
.ReadLongInt();
1551 Y
:= M
.ReadLongInt();
1552 Ang
:= M
.ReadSmallInt();
1556 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1560 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1562 Anim
:= TAnimation
.Create(ID
, False, 3);
1563 g_GFX_OnceAnim(X
, Y
, Anim
);
1567 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1572 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1574 Anim
:= TAnimation
.Create(ID
, False, 6);
1575 Anim
.Blending
:= False;
1576 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1580 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1585 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1587 Anim
:= TAnimation
.Create(ID
, False, 6);
1588 Anim
.Blending
:= False;
1589 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1593 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1598 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1600 Anim
:= TAnimation
.Create(ID
, False, 4);
1601 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1608 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1610 Anim
:= TAnimation
.Create(ID
, False, 4);
1611 g_GFX_OnceAnim(X
, Y
, Anim
);
1615 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1620 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1622 Anim
:= TAnimation
.Create(ID
, False, 4);
1623 g_GFX_OnceAnim(X
, Y
, Anim
);
1627 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1631 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1634 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1638 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1639 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1644 procedure MC_RECV_Sound(var M
: TMsg
);
1650 Name
:= M
.ReadString();
1651 Pos
:= M
.ReadByte() <> 0;
1654 X
:= M
.ReadLongInt();
1655 Y
:= M
.ReadLongInt();
1656 g_Sound_PlayExAt(Name
, X
, Y
);
1659 g_Sound_PlayEx(Name
);
1662 procedure MC_RECV_CreateShot(var M
: TMsg
);
1664 I
, X
, Y
, XV
, YV
: Integer;
1666 Target
, Spawner
: Word;
1669 I
:= M
.ReadLongInt();
1670 ShType
:= M
.ReadByte();
1671 Target
:= M
.ReadWord();
1672 Spawner
:= M
.ReadWord();
1673 Timeout
:= M
.ReadLongWord();
1674 X
:= M
.ReadLongInt();
1675 Y
:= M
.ReadLongInt();
1676 XV
:= M
.ReadLongInt();
1677 YV
:= M
.ReadLongInt();
1679 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1680 if (Shots
<> nil) and (I
<= High(Shots
)) then
1682 Shots
[I
].Timeout
:= Timeout
;
1683 //Shots[I].Target := Target; // TODO: find a use for Target later
1687 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1689 I
, TX
, TY
, TXV
, TYV
: Integer;
1691 I
:= M
.ReadLongInt();
1692 TX
:= M
.ReadLongInt();
1693 TY
:= M
.ReadLongInt();
1694 TXV
:= M
.ReadLongInt();
1695 TYV
:= M
.ReadLongInt();
1697 if (Shots
<> nil) and (I
<= High(Shots
)) then
1707 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1712 if not gGameOn
then Exit
;
1713 I
:= M
.ReadLongInt();
1714 L
:= (M
.ReadByte() <> 0);
1715 X
:= M
.ReadLongInt();
1716 Y
:= M
.ReadLongInt();
1718 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1721 procedure MC_RECV_GameStats(var M
: TMsg
);
1723 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1725 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1726 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1729 if gGameSettings
.GameMode
= GM_COOP
then
1731 gCoopMonstersKilled
:= M
.ReadWord();
1732 gCoopSecretsFound
:= M
.ReadWord();
1736 procedure MC_RECV_CoopStats(var M
: TMsg
);
1738 gTotalMonsters
:= M
.ReadLongInt();
1739 gSecretsCount
:= M
.ReadLongInt();
1740 gCoopTotalMonstersKilled
:= M
.ReadWord();
1741 gCoopTotalSecretsFound
:= M
.ReadWord();
1742 gCoopTotalMonsters
:= M
.ReadWord();
1743 gCoopTotalSecrets
:= M
.ReadWord();
1746 procedure MC_RECV_GameEvent(var M
: TMsg
);
1755 i1
, i2
: TStrings_Locale
;
1758 goodCmd
: Boolean = true;
1760 FillChar(EvHash
, Sizeof(EvHash
), 0);
1761 EvType
:= M
.ReadByte();
1762 EvNum
:= M
.ReadLongInt();
1763 EvStr
:= M
.ReadString();
1764 gLastMap
:= M
.ReadByte() <> 0;
1765 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1766 gStatsPressed
:= True;
1767 EvTime
:= M
.ReadLongWord();
1768 BHash
:= M
.ReadByte() <> 0;
1770 EvHash
:= M
.ReadMD5();
1774 if (g_Res_received_map_start
<> 0) then
1776 if (g_Res_received_map_start
< 0) then exit
;
1779 NET_EV_MAPSTART
: goodCmd
:= true;
1780 NET_EV_MAPEND
: goodCmd
:= true;
1781 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1782 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1784 if not goodCmd
then exit
;
1790 if (g_Res_received_map_start
<> 0) then
1792 g_Res_received_map_start
:= -1;
1797 g_Game_ClearLoading();
1798 g_Game_StopAllSounds(True);
1800 gSwitchGameMode
:= Byte(EvNum
);
1801 gGameSettings
.GameMode
:= gSwitchGameMode
;
1804 if not g_Game_StartMap(EvStr
, True) then
1806 if not isWadPath(EvStr
) then
1807 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1809 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1813 MC_SEND_FullStateRequest
;
1819 if (g_Res_received_map_start
<> 0) then
1821 g_Res_received_map_start
:= -1;
1825 gMissionFailed
:= EvNum
<> 0;
1826 gExit
:= EXIT_ENDLEVELCUSTOM
;
1834 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1836 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1838 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1844 if EvNum
= TEAM_RED
then
1845 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1846 if EvNum
= TEAM_BLUE
then
1847 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;
1863 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1865 NET_EV_LMS_SURVIVOR
:
1866 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1869 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1873 pl
:= g_Player_Get(EvNum
and $FFFF);
1878 cnt
:= (EvNum
shr 16) and $FF;
1879 if Pos('w', EvStr
) = 0 then
1882 if Pos('t', EvStr
) = 0 then
1885 if Pos('-', EvStr
) = 0 then
1887 if Pos('e', EvStr
) = 0 then
1888 i1
:= I_PLAYER_SCORE_ADD_OWN
1890 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1893 if Pos('e', EvStr
) = 0 then
1894 i1
:= I_PLAYER_SCORE_SUB_OWN
1896 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1899 if Pos('r', EvStr
) > 0 then
1900 i2
:= I_PLAYER_SCORE_TO_RED
1902 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1903 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1907 if Pos('-', EvStr
) = 0 then
1908 i1
:= I_PLAYER_SCORE_ADD_TEAM
1910 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1912 if Pos('r', EvStr
) > 0 then
1913 i2
:= I_PLAYER_SCORE_RED
1915 i2
:= I_PLAYER_SCORE_BLUE
;
1916 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1921 if Pos('e', EvStr
) = 0 then
1922 i1
:= I_PLAYER_SCORE_WIN_OWN
1924 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1926 if Pos('r', EvStr
) > 0 then
1927 i2
:= I_PLAYER_SCORE_TO_RED
1929 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1930 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1936 if EvNum
= TEAM_RED
then
1937 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1938 if EvNum
= TEAM_BLUE
then
1939 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1940 if EvNum
= -TEAM_RED
then
1941 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1942 if EvNum
= -TEAM_BLUE
then
1943 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1948 g_Player_RemoveAllCorpses
;
1949 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1953 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1957 if EvNum
= TEAM_RED
then
1958 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1959 if EvNum
= TEAM_BLUE
then
1960 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1964 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1967 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1970 g_Game_Announce_KillCombo(EvNum
);
1972 NET_EV_PLAYER_TOUCH
:
1974 pl
:= g_Player_Get(EvNum
);
1981 pl
:= g_Player_Get(EvNum
);
1984 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
1985 g_Sound_PlayEx('SOUND_GAME_SECRET');
1991 pl
:= g_Player_Get(EvNum
);
1992 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
1997 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2006 EvType
:= M
.ReadByte();
2009 if Fl
= FLAG_NONE
then Exit
;
2011 Quiet
:= (M
.ReadByte() <> 0);
2012 PID
:= M
.ReadWord();
2014 gFlags
[Fl
].State
:= M
.ReadByte();
2015 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2016 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2017 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2018 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2019 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2021 Pl
:= g_Player_Get(PID
);
2023 (EvType
<> FLAG_STATE_NORMAL
) and
2024 (EvType
<> FLAG_STATE_DROPPED
) and
2025 (EvType
<> FLAG_STATE_RETURNED
) then
2031 if Quiet
or (Pl
= nil) then Exit
;
2033 if Fl
= FLAG_RED
then
2034 s
:= _lc
[I_PLAYER_FLAG_RED
]
2036 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2038 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2040 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2041 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2042 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2047 if not sound_ret_flag
[a
].IsPlaying() then
2048 sound_ret_flag
[a
].Play();
2051 FLAG_STATE_CAPTURED
:
2053 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2057 if Fl
= FLAG_RED
then
2058 s
:= _lc
[I_PLAYER_FLAG_RED
]
2060 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2062 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2063 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2065 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2066 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2067 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2072 if not sound_get_flag
[a
].IsPlaying() then
2073 sound_get_flag
[a
].Play();
2078 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2080 if Quiet
or (Pl
= nil) then Exit
;
2082 if Fl
= FLAG_RED
then
2083 s
:= _lc
[I_PLAYER_FLAG_RED
]
2085 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2087 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2088 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2090 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2091 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2092 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2097 if not sound_lost_flag
[a
].IsPlaying() then
2098 sound_lost_flag
[a
].Play();
2103 g_Map_ResetFlag(FLAG_RED
);
2104 g_Map_ResetFlag(FLAG_BLUE
);
2105 if Quiet
or (Pl
= nil) then Exit
;
2106 Pl
.SetFlag(FLAG_NONE
);
2108 if Fl
= FLAG_RED
then
2109 s
:= _lc
[I_PLAYER_FLAG_RED
]
2111 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2113 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2114 Insert('.', ts
, Length(ts
) + 1 - 3);
2115 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2116 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2118 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2119 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2120 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2125 if not sound_cap_flag
[a
].IsPlaying() then
2126 sound_cap_flag
[a
].Play();
2129 FLAG_STATE_RETURNED
:
2131 g_Map_ResetFlag(Fl
);
2134 if Fl
= FLAG_RED
then
2135 s
:= _lc
[I_PLAYER_FLAG_RED
]
2137 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2139 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2141 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2142 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2143 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2148 if not sound_ret_flag
[a
].IsPlaying() then
2149 sound_ret_flag
[a
].Play();
2154 procedure MC_RECV_GameSettings(var M
: TMsg
);
2156 gGameSettings
.GameMode
:= M
.ReadByte();
2157 gGameSettings
.GoalLimit
:= M
.ReadWord();
2158 gGameSettings
.TimeLimit
:= M
.ReadWord();
2159 gGameSettings
.MaxLives
:= M
.ReadByte();
2160 gGameSettings
.Options
:= M
.ReadLongWord();
2165 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2168 PName
, Model
: string;
2173 PID
:= M
.ReadWord();
2174 Pl
:= g_Player_Get(PID
);
2176 PName
:= M
.ReadString();
2177 Model
:= M
.ReadString();
2178 Color
.R
:= M
.ReadByte();
2179 Color
.G
:= M
.ReadByte();
2180 Color
.B
:= M
.ReadByte();
2184 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2186 if (Pl
<> nil) then Exit
;
2187 DID
:= g_Player_Create(Model
, Color
, T
, False);
2188 with g_Player_Get(DID
) do
2197 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2198 gPlayer1
.UID
:= PID
;
2199 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2200 gPlayer1
.ChangeTeam(T
);
2202 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2203 gPlayer2
.UID
:= PID
;
2204 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2205 gPlayer2
.ChangeTeam(T
);
2209 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2210 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2214 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2221 TmpX
, TmpY
: Integer;
2225 GT
:= M
.ReadLongWord();
2226 if GT
< gTime
- NET_MAX_DIFFTIME
then
2233 PID
:= M
.ReadWord();
2234 Pl
:= g_Player_Get(PID
);
2236 if Pl
= nil then Exit
;
2242 FPing
:= M
.ReadWord();
2243 FLoss
:= M
.ReadByte();
2244 kByte
:= M
.ReadWord();
2245 Dir
:= M
.ReadByte();
2247 TmpX
:= M
.ReadLongInt();
2248 TmpY
:= M
.ReadLongInt();
2252 if (kByte
= NET_KEY_CHAT
) then
2253 PressKey(KEY_CHAT
, 10000)
2256 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2257 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2258 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2259 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2260 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2263 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2264 SetDirection(TDirection(Dir
));
2266 GameVelX
:= M
.ReadLongInt();
2267 GameVelY
:= M
.ReadLongInt();
2268 GameAccelX
:= M
.ReadLongInt();
2269 GameAccelY
:= M
.ReadLongInt();
2270 SetLerp(TmpX
, TmpY
);
2271 if NetForcePlayerUpdate
then Update();
2275 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2279 I
, OldFire
: Integer;
2280 OldJet
, Flam
: Boolean;
2283 PID
:= M
.ReadWord();
2284 Pl
:= g_Player_Get(PID
);
2291 alive
:= (M
.ReadByte() <> 0);
2292 GodMode
:= (M
.ReadByte() <> 0);
2293 Health
:= M
.ReadLongInt();
2294 Armor
:= M
.ReadLongInt();
2295 Air
:= M
.ReadLongInt();
2296 JetFuel
:= M
.ReadLongInt();
2297 Lives
:= M
.ReadByte();
2298 NewTeam
:= M
.ReadByte();
2300 for I
:= WP_FIRST
to WP_LAST
do
2301 FWeapon
[I
] := (M
.ReadByte() <> 0);
2303 for I
:= A_BULLETS
to A_HIGH
do
2304 FAmmo
[I
] := M
.ReadWord();
2306 for I
:= A_BULLETS
to A_HIGH
do
2307 FMaxAmmo
[I
] := M
.ReadWord();
2309 for I
:= MR_SUIT
to MR_MAX
do
2310 FMegaRulez
[I
] := M
.ReadLongWord();
2313 if (M
.ReadByte() <> 0) then
2314 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2315 if (M
.ReadByte() <> 0) then
2316 FRulez
:= FRulez
+ [R_KEY_RED
];
2317 if (M
.ReadByte() <> 0) then
2318 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2319 if (M
.ReadByte() <> 0) then
2320 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2321 if (M
.ReadByte() <> 0) then
2322 FRulez
:= FRulez
+ [R_BERSERK
];
2324 Frags
:= M
.ReadLongInt();
2325 Death
:= M
.ReadLongInt();
2327 SetWeapon(M
.ReadByte());
2329 FSpectator
:= M
.ReadByte() <> 0;
2332 if Pl
= gPlayer1
then
2337 if Pl
= gPlayer2
then
2345 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2346 gPlayer1
:= g_Player_Get(gLMSPID1
);
2347 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2348 gPlayer2
:= g_Player_Get(gLMSPID2
);
2350 FGhost
:= M
.ReadByte() <> 0;
2351 FPhysics
:= M
.ReadByte() <> 0;
2352 FNoRespawn
:= M
.ReadByte() <> 0;
2354 FJetpack
:= M
.ReadByte() <> 0;
2355 OldFire
:= FFireTime
;
2356 FFireTime
:= M
.ReadLongInt();
2357 if (OldFire
<= 0) and (FFireTime
> 0) then
2358 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2359 Flam
:= M
.ReadByte() <> 0;
2360 if OldJet
and not FJetpack
then
2362 else if not OldJet
and FJetpack
then
2364 if FFlaming
and not Flam
then
2366 if Team
<> NewTeam
then
2367 Pl
.ChangeTeam(NewTeam
);
2373 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2378 Attacker
, Value
: Word;
2382 if not gGameOn
then Exit
;
2383 PID
:= M
.ReadWord();
2384 Pl
:= g_Player_Get(PID
);
2385 if Pl
= nil then Exit
;
2387 Kind
:= M
.ReadByte();
2388 Attacker
:= M
.ReadWord();
2389 Value
:= M
.ReadWord();
2394 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2399 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2403 KillType
, DeathType
: Byte;
2407 if not gGameOn
then Exit
;
2408 PID
:= M
.ReadWord();
2409 Pl
:= g_Player_Get(PID
);
2410 if Pl
= nil then Exit
;
2412 KillType
:= M
.ReadByte();
2413 DeathType
:= M
.ReadByte();
2414 Attacker
:= M
.ReadWord();
2418 Kill(KillType
, Attacker
, DeathType
);
2423 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2428 PID
:= M
.ReadWord();
2429 Pl
:= g_Player_Get(PID
);
2431 if Pl
= nil then Exit
;
2433 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2434 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2436 g_Player_Remove(PID
);
2441 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2446 X
, Y
, AX
, AY
: Integer;
2450 if not gGameOn
then Exit
;
2451 PID
:= M
.ReadWord();
2452 Pl
:= g_Player_Get(PID
);
2453 if Pl
= nil then Exit
;
2455 Weap
:= M
.ReadByte();
2456 X
:= M
.ReadLongInt();
2457 Y
:= M
.ReadLongInt();
2458 AX
:= M
.ReadLongInt();
2459 AY
:= M
.ReadLongInt();
2460 SHID
:= M
.ReadLongInt();
2463 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2466 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2475 PID
:= M
.ReadWord();
2476 Pl
:= g_Player_Get(PID
);
2477 if Pl
= nil then Exit
;
2479 TmpName
:= M
.ReadString();
2480 TmpModel
:= M
.ReadString();
2481 TmpColor
.R
:= M
.ReadByte();
2482 TmpColor
.G
:= M
.ReadByte();
2483 TmpColor
.B
:= M
.ReadByte();
2484 TmpTeam
:= M
.ReadByte();
2486 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2488 Pl
.ChangeTeam(TmpTeam
);
2489 if gPlayer1
= Pl
then
2490 gPlayer1Settings
.Team
:= TmpTeam
;
2491 if gPlayer2
= Pl
then
2492 gPlayer2Settings
.Team
:= TmpTeam
;
2494 Pl
.SetColor(TmpColor
);
2496 if Pl
.Name
<> TmpName
then
2498 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2502 if TmpModel
<> Pl
.Model
.Name
then
2503 Pl
.SetModel(TmpModel
);
2508 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2512 X
, Y
, VX
, VY
: Integer;
2514 Quiet
, Fall
{, Resp}: Boolean;
2518 if not gGameOn
then Exit
;
2520 Quiet
:= M
.ReadByte() <> 0;
2522 Fall
:= M
.ReadByte() <> 0;
2523 {Resp :=} M
.ReadByte();
2524 X
:= M
.ReadLongInt();
2525 Y
:= M
.ReadLongInt();
2526 VX
:= M
.ReadLongInt();
2527 VY
:= M
.ReadLongInt();
2529 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2530 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2532 it
:= g_Items_ByIdx(ID
);
2538 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2539 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2541 Anim
:= TAnimation
.Create(AID
, False, 4);
2542 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2548 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2553 if not gGameOn
then Exit
;
2555 Quiet
:= M
.ReadByte() <> 0;
2557 if not g_Items_ValidId(ID
) then exit
;
2559 if not Quiet
then g_Items_EmitPickupSound(ID
);
2566 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2573 if not gGameOn
then Exit
;
2575 PGUID
:= Integer(M
.ReadLongWord());
2576 Tex
:= M
.ReadLongInt();
2577 Fr
:= M
.ReadLongInt();
2578 Cnt
:= M
.ReadByte();
2579 Loop
:= M
.ReadByte();
2581 TP
:= g_Map_PanelByGUID(PGUID
);
2585 TP
.SetTexture(Tex
, Loop
);
2586 TP
.SetFrame(Fr
, Cnt
);
2590 procedure MC_RECV_PanelState(var M
: TMsg
);
2595 X
, Y
, W
, H
: Integer;
2597 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2598 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2601 if not gGameOn
then Exit
;
2603 PGUID
:= Integer(M
.ReadLongWord());
2604 E
:= (M
.ReadByte() <> 0);
2605 Lift
:= M
.ReadByte();
2606 X
:= M
.ReadLongInt();
2607 Y
:= M
.ReadLongInt();
2611 speedX
:= M
.ReadLongInt();
2612 speedY
:= M
.ReadLongInt();
2613 startX
:= M
.ReadLongInt();
2614 startY
:= M
.ReadLongInt();
2615 endX
:= M
.ReadLongInt();
2616 endY
:= M
.ReadLongInt();
2617 sizeSpX
:= M
.ReadLongInt();
2618 sizeSpY
:= M
.ReadLongInt();
2619 sizeEX
:= M
.ReadLongInt();
2620 sizeEY
:= M
.ReadLongInt();
2621 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2623 TP
:= g_Map_PanelByGUID(PGUID
);
2624 if (TP
= nil) then exit
;
2626 // update lifts state
2627 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2629 // update enabled/disabled state for all panels
2630 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2632 // update panel position, as it can be moved (mplat)
2637 // update mplat state
2638 TP
.movingSpeedX
:= speedX
;
2639 TP
.movingSpeedY
:= speedY
;
2640 TP
.movingStartX
:= startX
;
2641 TP
.movingStartY
:= startY
;
2642 TP
.movingEndX
:= endX
;
2643 TP
.movingEndY
:= endY
;
2644 TP
.sizeSpeedX
:= sizeSpX
;
2645 TP
.sizeSpeedY
:= sizeSpY
;
2646 TP
.sizeEndX
:= sizeEX
;
2647 TP
.sizeEndY
:= sizeEY
;
2648 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2649 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2650 // notify panel of it's position/size change, so it can fix other internal structures
2651 TP
.positionChanged();
2656 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2659 SPos
, SID
: LongWord;
2663 if not gGameOn
then Exit
;
2664 if gTriggers
= nil then Exit
;
2666 SID
:= M
.ReadLongWord();
2667 SPlaying
:= M
.ReadByte() <> 0;
2668 SPos
:= M
.ReadLongWord();
2669 SCount
:= M
.ReadLongInt();
2671 for I
:= Low(gTriggers
) to High(gTriggers
) do
2672 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2673 if gTriggers
[I
].ClientID
= SID
then
2674 with gTriggers
[I
] do
2676 if Sound
<> nil then
2681 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2683 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2684 Sound
.SetPosition(SPos
);
2687 if Sound
.IsPlaying
then Sound
.Stop
;
2690 SoundPlayCount
:= SCount
;
2694 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2701 if not gGameOn
then Exit
;
2703 MName
:= M
.ReadString();
2704 MPlaying
:= M
.ReadByte() <> 0;
2705 MPos
:= M
.ReadLongWord();
2706 MPaused
:= M
.ReadByte() <> 0;
2707 MPos
:= MPos
+1; //k8: stfu, fpc!
2711 gMusic
.SetByName(MName
);
2713 // gMusic.SetPosition(MPos);
2714 gMusic
.SpecPause
:= MPaused
;
2717 if gMusic
.IsPlaying
then gMusic
.Stop
;
2722 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2725 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2726 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2731 Mon
:= g_Monsters_ByUID(ID
);
2735 MType
:= M
.ReadByte();
2736 MState
:= M
.ReadByte();
2737 MAnim
:= M
.ReadByte();
2738 MTarg
:= M
.ReadWord();
2739 MTargTime
:= M
.ReadLongInt();
2740 MBehav
:= M
.ReadByte();
2741 MSleep
:= M
.ReadLongInt();
2742 MHealth
:= M
.ReadLongInt();
2743 MAmmo
:= M
.ReadLongInt();
2745 X
:= M
.ReadLongInt();
2746 Y
:= M
.ReadLongInt();
2747 VX
:= M
.ReadLongInt();
2748 VY
:= M
.ReadLongInt();
2749 MDir
:= M
.ReadByte();
2751 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2752 Mon
:= g_Monsters_ByUID(ID
);
2759 MonsterAnim
:= MAnim
;
2760 MonsterTargetUID
:= MTarg
;
2761 MonsterTargetTime
:= MTargTime
;
2762 MonsterBehaviour
:= MBehav
;
2763 MonsterSleep
:= MSleep
;
2764 MonsterAmmo
:= MAmmo
;
2769 setPosition(X
, Y
); // this will call positionChanged();
2775 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2782 Mon
:= g_Monsters_ByUID(ID
);
2788 X
:= M
.ReadLongInt();
2789 Y
:= M
.ReadLongInt();
2790 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2791 GameVelX
:= M
.ReadLongInt();
2792 GameVelY
:= M
.ReadLongInt();
2793 GameDirection
:= TDirection(M
.ReadByte());
2797 procedure MC_RECV_MonsterState(var M
: TMsg
);
2799 ID
, OldFire
: Integer;
2800 MState
, MFAnm
: Byte;
2802 AnimRevert
: Boolean;
2805 Mon
:= g_Monsters_ByUID(ID
);
2806 if Mon
= nil then Exit
;
2808 MState
:= M
.ReadByte();
2809 MFAnm
:= M
.ReadByte();
2813 MonsterTargetUID
:= M
.ReadWord();
2814 MonsterTargetTime
:= M
.ReadLongInt();
2815 MonsterSleep
:= M
.ReadLongInt();
2816 MonsterHealth
:= M
.ReadLongInt();
2817 MonsterAmmo
:= M
.ReadLongInt();
2818 MonsterPain
:= M
.ReadLongInt();
2819 AnimRevert
:= M
.ReadByte() <> 0;
2820 OldFire
:= FFireTime
;
2821 FFireTime
:= M
.ReadLongInt();
2822 if (OldFire
<= 0) and (FFireTime
> 0) then
2823 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2824 RevertAnim(AnimRevert
);
2826 if MonsterState
<> MState
then
2828 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2829 if (MState
= MONSTATE_DIE
) then DieSound();
2830 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2831 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2832 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2834 SetState(MState
, MFAnm
);
2839 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2843 X
, Y
, VX
, VY
: Integer;
2847 Mon
:= g_Monsters_ByUID(ID
);
2848 if Mon
= nil then Exit
;
2850 X
:= M
.ReadLongInt();
2851 Y
:= M
.ReadLongInt();
2852 VX
:= M
.ReadLongInt();
2853 VY
:= M
.ReadLongInt();
2855 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2858 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2864 Mon
:= g_Monsters_ByUID(ID
);
2865 if Mon
= nil then Exit
;
2867 Mon
.MonsterRemoved
:= True;
2870 procedure MC_RECV_TimeSync(var M
: TMsg
);
2874 Time
:= M
.ReadLongWord();
2876 if gState
= STATE_INTERCUSTOM
then
2877 gServInterTime
:= Min(Time
, 255);
2880 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2884 Int1
, Int2
: SmallInt;
2886 EvID
:= M
.ReadByte();
2887 Int1
:= M
.ReadSmallInt();
2888 Int2
:= M
.ReadSmallInt();
2889 Str1
:= M
.ReadString();
2890 Str2
:= M
.ReadString();
2894 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2896 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2898 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2900 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2902 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2908 procedure MC_SEND_Info(Password
: string);
2912 NetOut
.Write(Byte(NET_MSG_INFO
));
2913 NetOut
.Write(GAME_VERSION
);
2914 NetOut
.Write(Password
);
2915 NetOut
.Write(gPlayer1Settings
.Name
);
2916 NetOut
.Write(gPlayer1Settings
.Model
);
2917 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2918 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2919 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2920 NetOut
.Write(gPlayer1Settings
.Team
);
2922 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2925 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2927 NetOut
.Write(Byte(NET_MSG_CHAT
));
2931 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2934 procedure MC_SEND_PlayerPos();
2939 WeaponSelect
: Word = 0;
2942 if not gGameOn
then Exit
;
2943 if gPlayers
= nil then Exit
;
2944 if gPlayer1
= nil then Exit
;
2947 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2949 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2951 strafeDir
:= P1MoveButton
shr 4;
2952 P1MoveButton
:= P1MoveButton
and $0F;
2954 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2956 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2958 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2962 if gPlayerAction
[0, ACTION_STRAFE
] then
2964 // new strafe mechanics
2965 if (strafeDir
= 0) then
2966 strafeDir
:= P1MoveButton
; // start strafing
2967 // now set direction according to strafe (reversed)
2968 if (strafeDir
= 2) then
2969 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2970 else if (strafeDir
= 1) then
2971 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2975 strafeDir
:= 0; // not strafing anymore
2976 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
2977 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2978 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2979 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2980 else if P1MoveButton
<> 0 then
2981 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2984 gPlayer1
.ReleaseKeys
;
2985 if P1MoveButton
= 1 then
2987 kByte
:= kByte
or NET_KEY_LEFT
;
2988 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2990 if P1MoveButton
= 2 then
2992 kByte
:= kByte
or NET_KEY_RIGHT
;
2993 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2995 if gPlayerAction
[0, ACTION_LOOKUP
] then
2997 kByte
:= kByte
or NET_KEY_UP
;
2998 gPlayer1
.PressKey(KEY_UP
, 10000);
3000 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3002 kByte
:= kByte
or NET_KEY_DOWN
;
3003 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3005 if gPlayerAction
[0, ACTION_JUMP
] then
3007 kByte
:= kByte
or NET_KEY_JUMP
;
3008 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3010 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3011 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3012 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
3013 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
3015 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3016 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3018 for i
:= WP_FIRST
to WP_LAST
do
3020 if gSelectWeapon
[0, i
] then
3022 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3023 gSelectWeapon
[0, i
] := False
3027 // fix movebutton state
3028 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3031 kByte
:= NET_KEY_CHAT
;
3033 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3034 NetOut
.Write(gTime
);
3035 NetOut
.Write(kByte
);
3036 NetOut
.Write(Byte(gPlayer1
.Direction
));
3037 NetOut
.Write(WeaponSelect
);
3038 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3039 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3041 //kBytePrev := kByte;
3042 //kDirPrev := gPlayer1.Direction;
3045 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3047 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3048 NetOut
.Write(Byte(Start
));
3049 NetOut
.Write(Command
);
3050 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3053 procedure MC_SEND_PlayerSettings();
3055 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3056 NetOut
.Write(gPlayer1Settings
.Name
);
3057 NetOut
.Write(gPlayer1Settings
.Model
);
3058 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3059 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3060 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3061 NetOut
.Write(gPlayer1Settings
.Team
);
3063 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3066 procedure MC_SEND_FullStateRequest();
3068 NetOut
.Write(Byte(NET_MSG_REQFST
));
3070 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3073 procedure MC_SEND_CheatRequest(Kind
: Byte);
3075 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3078 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3080 procedure MC_SEND_RCONPassword(Password
: string);
3082 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3083 NetOut
.Write(Password
);
3085 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3087 procedure MC_SEND_RCONCommand(Cmd
: string);
3089 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3092 g_Net_Client_Send(True, NET_CHAN_SERVICE
);