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 a 'i am ready' packet
449 FWantsInGame
:= false; // TODO: look into this later
450 C
^.WaitForFirstSpawn
:= true;
454 //if not C^.WaitForFirstSpawn then
456 for I
:= Low(NetClients
) to High(NetClients
) do
458 if NetClients
[I
].ID
= C
^.ID
then Continue
;
459 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
460 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
461 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
465 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
466 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
468 if NetUseMaster
then g_Net_Slist_Update
;
472 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
476 if not C
.WaitForFirstSpawn
then exit
;
477 plr
:= g_Player_Get(C
^.Player
);
478 if not assigned(plr
) then exit
;
479 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
480 C
.WaitForFirstSpawn
:= false;
481 plr
.FNoRespawn
:= false;
482 plr
.FWantsInGame
:= true; // TODO: look into this later
487 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
489 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
492 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
496 C
^.RequestedFullUpdate
:= True;
502 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
512 if not gGameOn
then Exit
;
514 GT
:= M
.ReadLongWord();
516 Pl
:= g_Player_Get(PID
);
520 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
525 kByte
:= M
.ReadWord();
527 WeaponSelect
:= M
.ReadWord();
528 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
529 if Direction
<> TDirection(Dir
) then
530 JustTeleported
:= False;
532 SetDirection(TDirection(Dir
));
535 if kByte
= NET_KEY_CHAT
then
537 PressKey(KEY_CHAT
, 10000);
541 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
542 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
543 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
544 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
545 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
546 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
547 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
548 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
549 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
553 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
555 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
556 QueueWeaponSwitch(i
);
561 // MH_SEND_PlayerPos(False, PID, C^.ID);
564 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
569 Pl
:= g_Player_Get(C
^.Player
);
570 if Pl
= nil then Exit
;
572 CheatKind
:= M
.ReadByte();
576 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
579 if Pl
.FSpectator
then
586 if gState
<> STATE_INTERCUSTOM
then Exit
;
587 Pl
.FReady
:= not Pl
.FReady
;
590 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
591 Inc(gInterReadyCount
);
595 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
596 Dec(gInterReadyCount
);
602 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
610 TmpName
:= M
.ReadString();
611 TmpModel
:= M
.ReadString();
612 TmpColor
.R
:= M
.ReadByte();
613 TmpColor
.G
:= M
.ReadByte();
614 TmpColor
.B
:= M
.ReadByte();
615 TmpTeam
:= M
.ReadByte();
617 Pl
:= g_Player_Get(C
^.Player
);
618 if Pl
= nil then Exit
;
620 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
623 Pl
.SetColor(TmpColor
);
625 if Pl
.Name
<> TmpName
then
627 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
631 if TmpModel
<> Pl
.Model
.Name
then
632 Pl
.SetModel(TmpModel
);
634 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
639 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
643 Pwd
:= M
.ReadString();
644 if not NetAllowRCON
then Exit
;
645 if Pwd
= NetRCONPassword
then
648 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
651 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
654 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
658 Cmd
:= M
.ReadString();
659 if not NetAllowRCON
then Exit
;
660 if not C
^.RCONAuth
then
662 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
665 g_Console_Process(Cmd
);
670 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
673 Name
, Command
: string;
677 Start
:= M
.ReadByte() <> 0;
678 Command
:= M
.ReadString();
680 Pl
:= g_Player_Get(C
^.Player
);
681 if Pl
= nil then Exit
;
686 if not g_Console_CommandBlacklisted(Command
) then
687 g_Game_StartVote(Command
, Name
);
689 else if gVoteInProgress
then
691 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
692 Need
:= Floor((NetClientCount
+1)/2.0) + 1
694 Need
:= Floor(NetClientCount
/2.0) + 1;
699 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
700 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
706 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
707 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
715 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
717 function sendItemRespawn (it
: PItem
): Boolean;
719 result
:= false; // don't stop
720 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
723 function sendMonSpawn (mon
: TMonster
): Boolean;
725 result
:= false; // don't stop
726 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
729 function sendPanelState (pan
: TPanel
): Boolean;
731 result
:= false; // don't stop
732 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
733 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
739 if (ID
>= 0) and (ID
< length(NetClients
)) then
741 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
742 MH_ProcessFirstSpawn(@NetClients
[ID
]);
745 if gPlayers
<> nil then
747 for I
:= Low(gPlayers
) to High(gPlayers
) do
749 if gPlayers
[I
] <> nil then
751 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
752 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
753 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
755 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
757 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
763 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
764 g_Mons_ForEach(sendMonSpawn
);
765 g_Map_ForEachPanel(sendPanelState
);
767 if gTriggers
<> nil then
769 for I
:= Low(gTriggers
) to High(gTriggers
) do
771 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
773 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
780 for I
:= Low(Shots
) to High(Shots
) do
782 if Shots
[i
].ShotType
in [6, 7, 8] then
784 MH_SEND_CreateShot(i
, ID
);
789 MH_SEND_TriggerMusic(ID
);
791 MH_SEND_GameStats(ID
);
792 MH_SEND_CoopStats(ID
);
794 if gGameSettings
.GameMode
= GM_CTF
then
796 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
797 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
800 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
802 if gLMSRespawn
> LMS_RESPAWN_NONE
then
804 e_LogWritefln('*** client #%u (cid #%u) WARMUP', [ID
, NetClients
[ID
].Player
]);
805 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
811 procedure MH_SEND_Info(ID
: Byte);
815 Map
:= g_ExtractFileName(gMapInfo
.Map
);
819 NetOut
.Write(Byte(NET_MSG_INFO
));
821 NetOut
.Write(NetClients
[ID
].Player
);
822 NetOut
.Write(gGameSettings
.WAD
);
824 NetOut
.Write(gWADHash
);
825 NetOut
.Write(gGameSettings
.GameMode
);
826 NetOut
.Write(gGameSettings
.GoalLimit
);
827 NetOut
.Write(gGameSettings
.TimeLimit
);
828 NetOut
.Write(gGameSettings
.MaxLives
);
829 NetOut
.Write(gGameSettings
.Options
);
832 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
835 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
841 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
842 Mode
:= NET_CHAT_PLAYER
;
845 if (Mode
= NET_CHAT_TEAM
) then
847 for i
:= Low(gPlayers
) to High(gPlayers
) do
848 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
849 (gPlayers
[i
].Team
= ID
) then
851 NetOut
.Write(Byte(NET_MSG_CHAT
));
854 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
861 NetOut
.Write(Byte(NET_MSG_CHAT
));
864 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
867 if Mode
= NET_CHAT_SYSTEM
then
870 if ID
= NET_EVERYONE
then
872 if Mode
= NET_CHAT_PLAYER
then
874 g_Console_Add(Txt
, True);
875 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
876 g_Game_ChatSound(b_Text_Unformat(Txt
));
879 if Mode
= NET_CHAT_TEAM
then
880 if gPlayer1
<> nil then
882 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
884 g_Console_Add(#18'[Team] '#2 + Txt
, True);
885 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
886 g_Game_ChatSound(b_Text_Unformat(Txt
));
888 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
890 g_Console_Add(#20'[Team] '#2 + Txt
, True);
891 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
892 g_Game_ChatSound(b_Text_Unformat(Txt
));
898 Name
:= g_Net_ClientName_ByID(ID
);
899 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
900 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
901 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
905 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
907 NetOut
.Write(Byte(NET_MSG_GFX
));
913 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
916 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
918 NetOut
.Write(Byte(NET_MSG_SND
));
922 NetOut
.Write(Byte(1));
927 NetOut
.Write(Byte(0));
929 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
932 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
934 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
936 NetOut
.Write(Byte(NET_MSG_SHADD
));
938 NetOut
.Write(Shots
[Proj
].ShotType
);
939 NetOut
.Write(Shots
[Proj
].Target
);
940 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
941 NetOut
.Write(Shots
[Proj
].Timeout
);
942 NetOut
.Write(Shots
[Proj
].Obj
.X
);
943 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
944 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
945 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
947 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
950 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
952 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
954 NetOut
.Write(Byte(NET_MSG_SHPOS
));
956 NetOut
.Write(Shots
[Proj
].Obj
.X
);
957 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
958 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
959 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
961 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
964 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
966 NetOut
.Write(Byte(NET_MSG_SHDEL
));
968 NetOut
.Write(Byte(Loud
));
972 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
975 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
977 NetOut
.Write(Byte(NET_MSG_SCORE
));
978 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
980 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
981 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
984 if gGameSettings
.GameMode
= GM_COOP
then
986 NetOut
.Write(gCoopMonstersKilled
);
987 NetOut
.Write(gCoopSecretsFound
);
990 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
993 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
995 NetOut
.Write(Byte(NET_MSG_COOP
));
996 NetOut
.Write(gTotalMonsters
);
997 NetOut
.Write(gSecretsCount
);
998 NetOut
.Write(gCoopTotalMonstersKilled
);
999 NetOut
.Write(gCoopTotalSecretsFound
);
1000 NetOut
.Write(gCoopTotalMonsters
);
1001 NetOut
.Write(gCoopTotalSecrets
);
1004 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1006 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1007 NetOut
.Write(EvType
);
1008 NetOut
.Write(EvNum
);
1009 NetOut
.Write(EvStr
);
1010 NetOut
.Write(Byte(gLastMap
));
1011 NetOut
.Write(gTime
);
1012 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1014 NetOut
.Write(Byte(1));
1015 NetOut
.Write(gWADHash
);
1017 NetOut
.Write(Byte(0));
1019 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1022 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1024 NetOut
.Write(Byte(NET_MSG_FLAG
));
1025 NetOut
.Write(EvType
);
1027 NetOut
.Write(Byte(Quiet
));
1029 NetOut
.Write(gFlags
[Flag
].State
);
1030 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1031 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1032 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1033 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1034 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1036 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1039 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1041 NetOut
.Write(Byte(NET_MSG_GSET
));
1042 NetOut
.Write(gGameSettings
.GameMode
);
1043 NetOut
.Write(gGameSettings
.GoalLimit
);
1044 NetOut
.Write(gGameSettings
.TimeLimit
);
1045 NetOut
.Write(gGameSettings
.MaxLives
);
1046 NetOut
.Write(gGameSettings
.Options
);
1048 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1053 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1057 P
:= g_Player_Get(PID
);
1058 if P
= nil then Exit
;
1060 NetOut
.Write(Byte(NET_MSG_PLR
));
1062 NetOut
.Write(P
.Name
);
1064 NetOut
.Write(P
.FActualModelName
);
1065 NetOut
.Write(P
.FColor
.R
);
1066 NetOut
.Write(P
.FColor
.G
);
1067 NetOut
.Write(P
.FColor
.B
);
1068 NetOut
.Write(P
.Team
);
1070 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1073 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1078 Pl
:= g_Player_Get(PID
);
1079 if Pl
= nil then Exit
;
1080 if Pl
.FDummy
then Exit
;
1082 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1083 NetOut
.Write(gTime
);
1090 NetOut
.Write(FPing
);
1091 NetOut
.Write(FLoss
);
1092 if IsKeyPressed(KEY_CHAT
) then
1093 kByte
:= NET_KEY_CHAT
1096 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1097 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1098 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1099 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1100 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1101 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1104 NetOut
.Write(kByte
);
1105 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1106 NetOut
.Write(GameX
);
1107 NetOut
.Write(GameY
);
1108 NetOut
.Write(GameVelX
);
1109 NetOut
.Write(GameVelY
);
1110 NetOut
.Write(GameAccelX
);
1111 NetOut
.Write(GameAccelY
);
1114 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1117 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1122 P
:= g_Player_Get(PID
);
1123 if P
= nil then Exit
;
1125 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1130 NetOut
.Write(Byte(alive
));
1131 NetOut
.Write(Byte(GodMode
));
1132 NetOut
.Write(Health
);
1133 NetOut
.Write(Armor
);
1135 NetOut
.Write(JetFuel
);
1136 NetOut
.Write(Lives
);
1139 for I
:= WP_FIRST
to WP_LAST
do
1140 NetOut
.Write(Byte(FWeapon
[I
]));
1142 for I
:= A_BULLETS
to A_HIGH
do
1143 NetOut
.Write(FAmmo
[I
]);
1145 for I
:= A_BULLETS
to A_HIGH
do
1146 NetOut
.Write(FMaxAmmo
[I
]);
1148 for I
:= MR_SUIT
to MR_MAX
do
1149 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1151 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1152 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1153 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1154 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1155 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1157 NetOut
.Write(Frags
);
1158 NetOut
.Write(Death
);
1160 NetOut
.Write(CurrWeap
);
1162 NetOut
.Write(Byte(FSpectator
));
1163 NetOut
.Write(Byte(FGhost
));
1164 NetOut
.Write(Byte(FPhysics
));
1165 NetOut
.Write(Byte(FNoRespawn
));
1166 NetOut
.Write(Byte(FJetpack
));
1167 NetOut
.Write(FFireTime
);
1168 NetOut
.Write(Byte(FFlaming
));
1171 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1174 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1176 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1179 NetOut
.Write(Attacker
);
1180 NetOut
.Write(Value
);
1184 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1187 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1189 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1191 NetOut
.Write(KillType
);
1192 NetOut
.Write(DeathType
);
1193 NetOut
.Write(Attacker
);
1195 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1198 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1200 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1202 NetOut
.Write(Weapon
);
1207 NetOut
.Write(ShotID
);
1209 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1212 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1214 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1217 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1220 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1224 Pl
:= g_Player_Get(PID
);
1225 if Pl
= nil then Exit
;
1227 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1229 NetOut
.Write(Pl
.Name
);
1231 NetOut
.Write(Pl
.Model
.Name
)
1234 NetOut
.Write(Pl
.FColor
.R
);
1235 NetOut
.Write(Pl
.FColor
.G
);
1236 NetOut
.Write(Pl
.FColor
.B
);
1237 NetOut
.Write(Pl
.Team
);
1239 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1244 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1249 it
:= g_Items_ByIdx(IID
);
1251 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1253 NetOut
.Write(Byte(Quiet
));
1255 if it
.dropped
then tt
:= tt
or $80;
1257 NetOut
.Write(Byte(it
.Fall
));
1258 NetOut
.Write(Byte(it
.Respawnable
));
1259 NetOut
.Write(it
.Obj
.X
);
1260 NetOut
.Write(it
.Obj
.Y
);
1261 NetOut
.Write(it
.Obj
.Vel
.X
);
1262 NetOut
.Write(it
.Obj
.Vel
.Y
);
1264 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1267 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1269 NetOut
.Write(Byte(NET_MSG_IDEL
));
1271 NetOut
.Write(Byte(Quiet
));
1273 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1278 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1282 TP
:= g_Map_PanelByGUID(PGUID
);
1283 if (TP
= nil) then exit
;
1287 NetOut
.Write(Byte(NET_MSG_PTEX
));
1288 NetOut
.Write(LongWord(PGUID
));
1289 NetOut
.Write(FCurTexture
);
1290 NetOut
.Write(FCurFrame
);
1291 NetOut
.Write(FCurFrameCount
);
1292 NetOut
.Write(AnimLoop
);
1295 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1298 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1303 TP
:= g_Map_PanelByGUID(PGUID
);
1304 if (TP
= nil) then exit
;
1306 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1307 NetOut
.Write(LongWord(PGUID
));
1308 NetOut
.Write(Byte(TP
.Enabled
));
1309 NetOut
.Write(TP
.LiftType
);
1312 NetOut
.Write(Word(TP
.Width
));
1313 NetOut
.Write(Word(TP
.Height
));
1315 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1316 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1317 NetOut
.Write(LongInt(TP
.movingStartX
));
1318 NetOut
.Write(LongInt(TP
.movingStartY
));
1319 NetOut
.Write(LongInt(TP
.movingEndX
));
1320 NetOut
.Write(LongInt(TP
.movingEndY
));
1321 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1322 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1323 NetOut
.Write(LongInt(TP
.sizeEndX
));
1324 NetOut
.Write(LongInt(TP
.sizeEndY
));
1325 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1326 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1327 NetOut
.Write(Byte(mpflags
));
1329 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1334 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1336 if gTriggers
= nil then Exit
;
1337 if T
.Sound
= nil then Exit
;
1339 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1340 NetOut
.Write(T
.ClientID
);
1341 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1342 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1343 NetOut
.Write(T
.SoundPlayCount
);
1345 g_Net_Host_Send(ID
, True);
1348 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1350 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1351 NetOut
.Write(gMusic
.Name
);
1352 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1353 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1354 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1356 g_Net_Host_Send(ID
, True);
1361 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1365 M
:= g_Monsters_ByUID(UID
);
1371 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1373 NetOut
.Write(MonsterType
);
1374 NetOut
.Write(MonsterState
);
1375 NetOut
.Write(MonsterAnim
);
1376 NetOut
.Write(MonsterTargetUID
);
1377 NetOut
.Write(MonsterTargetTime
);
1378 NetOut
.Write(MonsterBehaviour
);
1379 NetOut
.Write(MonsterSleep
);
1380 NetOut
.Write(MonsterHealth
);
1381 NetOut
.Write(MonsterAmmo
);
1382 NetOut
.Write(GameX
);
1383 NetOut
.Write(GameY
);
1384 NetOut
.Write(GameVelX
);
1385 NetOut
.Write(GameVelY
);
1386 NetOut
.Write(Byte(GameDirection
));
1389 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1392 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1396 M
:= g_Monsters_ByUID(UID
);
1397 if M
= nil then Exit
;
1399 NetOut
.Write(Byte(NET_MSG_MPOS
));
1404 NetOut
.Write(GameX
);
1405 NetOut
.Write(GameY
);
1406 NetOut
.Write(GameVelX
);
1407 NetOut
.Write(GameVelY
);
1408 NetOut
.Write(Byte(GameDirection
));
1411 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1414 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1418 M
:= g_Monsters_ByUID(UID
);
1419 if M
= nil then Exit
;
1421 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1426 NetOut
.Write(MonsterState
);
1427 NetOut
.Write(ForcedAnim
);
1428 NetOut
.Write(MonsterTargetUID
);
1429 NetOut
.Write(MonsterTargetTime
);
1430 NetOut
.Write(MonsterSleep
);
1431 NetOut
.Write(MonsterHealth
);
1432 NetOut
.Write(MonsterAmmo
);
1433 NetOut
.Write(MonsterPain
);
1434 NetOut
.Write(Byte(AnimIsReverse
));
1435 NetOut
.Write(FFireTime
);
1438 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1441 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1443 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1450 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1453 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1457 M
:= g_Monsters_ByUID(UID
);
1458 if M
= nil then Exit
;
1460 NetOut
.Write(Byte(NET_MSG_MDEL
));
1463 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1468 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1470 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1473 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1476 procedure MH_SEND_VoteEvent(EvType
: Byte;
1477 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1478 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1479 ID
: Integer = NET_EVERYONE
);
1481 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1482 NetOut
.Write(EvType
);
1483 NetOut
.Write(IntArg1
);
1484 NetOut
.Write(IntArg2
);
1485 NetOut
.Write(StrArg1
);
1486 NetOut
.Write(StrArg2
);
1488 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1491 // CLIENT MESSAGES //
1495 procedure MC_RECV_Chat(var M
: TMsg
);
1500 Txt
:= M
.ReadString();
1501 Mode
:= M
.ReadByte();
1503 if Mode
<> NET_CHAT_SYSTEM
then
1505 if Mode
= NET_CHAT_PLAYER
then
1507 g_Console_Add(Txt
, True);
1508 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1509 g_Game_ChatSound(b_Text_Unformat(Txt
));
1511 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1513 if gPlayer1
.Team
= TEAM_RED
then
1514 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1515 if gPlayer1
.Team
= TEAM_BLUE
then
1516 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1517 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1518 g_Game_ChatSound(b_Text_Unformat(Txt
));
1521 g_Console_Add(Txt
, True);
1524 procedure MC_RECV_Effect(var M
: TMsg
);
1532 if not gGameOn
then Exit
;
1533 Kind
:= M
.ReadByte();
1534 X
:= M
.ReadLongInt();
1535 Y
:= M
.ReadLongInt();
1536 Ang
:= M
.ReadSmallInt();
1540 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1544 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1546 Anim
:= TAnimation
.Create(ID
, False, 3);
1547 g_GFX_OnceAnim(X
, Y
, Anim
);
1551 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1556 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1558 Anim
:= TAnimation
.Create(ID
, False, 6);
1559 Anim
.Blending
:= False;
1560 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1564 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1569 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1571 Anim
:= TAnimation
.Create(ID
, False, 6);
1572 Anim
.Blending
:= False;
1573 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1577 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1582 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1584 Anim
:= TAnimation
.Create(ID
, False, 4);
1585 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1592 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1594 Anim
:= TAnimation
.Create(ID
, False, 4);
1595 g_GFX_OnceAnim(X
, Y
, Anim
);
1599 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1604 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1606 Anim
:= TAnimation
.Create(ID
, False, 4);
1607 g_GFX_OnceAnim(X
, Y
, Anim
);
1611 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1615 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1618 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1622 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1623 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1628 procedure MC_RECV_Sound(var M
: TMsg
);
1634 Name
:= M
.ReadString();
1635 Pos
:= M
.ReadByte() <> 0;
1638 X
:= M
.ReadLongInt();
1639 Y
:= M
.ReadLongInt();
1640 g_Sound_PlayExAt(Name
, X
, Y
);
1643 g_Sound_PlayEx(Name
);
1646 procedure MC_RECV_CreateShot(var M
: TMsg
);
1648 I
, X
, Y
, XV
, YV
: Integer;
1650 Target
, Spawner
: Word;
1653 I
:= M
.ReadLongInt();
1654 ShType
:= M
.ReadByte();
1655 Target
:= M
.ReadWord();
1656 Spawner
:= M
.ReadWord();
1657 Timeout
:= M
.ReadLongWord();
1658 X
:= M
.ReadLongInt();
1659 Y
:= M
.ReadLongInt();
1660 XV
:= M
.ReadLongInt();
1661 YV
:= M
.ReadLongInt();
1663 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1664 if (Shots
<> nil) and (I
<= High(Shots
)) then
1666 Shots
[I
].Timeout
:= Timeout
;
1667 //Shots[I].Target := Target; // TODO: find a use for Target later
1671 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1673 I
, TX
, TY
, TXV
, TYV
: Integer;
1675 I
:= M
.ReadLongInt();
1676 TX
:= M
.ReadLongInt();
1677 TY
:= M
.ReadLongInt();
1678 TXV
:= M
.ReadLongInt();
1679 TYV
:= M
.ReadLongInt();
1681 if (Shots
<> nil) and (I
<= High(Shots
)) then
1691 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1696 if not gGameOn
then Exit
;
1697 I
:= M
.ReadLongInt();
1698 L
:= (M
.ReadByte() <> 0);
1699 X
:= M
.ReadLongInt();
1700 Y
:= M
.ReadLongInt();
1702 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1705 procedure MC_RECV_GameStats(var M
: TMsg
);
1707 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1709 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1710 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1713 if gGameSettings
.GameMode
= GM_COOP
then
1715 gCoopMonstersKilled
:= M
.ReadWord();
1716 gCoopSecretsFound
:= M
.ReadWord();
1720 procedure MC_RECV_CoopStats(var M
: TMsg
);
1722 gTotalMonsters
:= M
.ReadLongInt();
1723 gSecretsCount
:= M
.ReadLongInt();
1724 gCoopTotalMonstersKilled
:= M
.ReadWord();
1725 gCoopTotalSecretsFound
:= M
.ReadWord();
1726 gCoopTotalMonsters
:= M
.ReadWord();
1727 gCoopTotalSecrets
:= M
.ReadWord();
1730 procedure MC_RECV_GameEvent(var M
: TMsg
);
1739 i1
, i2
: TStrings_Locale
;
1742 goodCmd
: Boolean = true;
1744 FillChar(EvHash
, Sizeof(EvHash
), 0);
1745 EvType
:= M
.ReadByte();
1746 EvNum
:= M
.ReadLongInt();
1747 EvStr
:= M
.ReadString();
1748 gLastMap
:= M
.ReadByte() <> 0;
1749 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1750 gStatsPressed
:= True;
1751 EvTime
:= M
.ReadLongWord();
1752 BHash
:= M
.ReadByte() <> 0;
1754 EvHash
:= M
.ReadMD5();
1758 if (g_Res_received_map_start
<> 0) then
1760 if (g_Res_received_map_start
< 0) then exit
;
1763 NET_EV_MAPSTART
: goodCmd
:= true;
1764 NET_EV_MAPEND
: goodCmd
:= true;
1765 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1766 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1768 if not goodCmd
then exit
;
1774 if (g_Res_received_map_start
<> 0) then
1776 g_Res_received_map_start
:= -1;
1781 g_Game_ClearLoading();
1782 g_Game_StopAllSounds(True);
1784 gSwitchGameMode
:= Byte(EvNum
);
1785 gGameSettings
.GameMode
:= gSwitchGameMode
;
1788 if not g_Game_StartMap(EvStr
, True) then
1790 if not isWadPath(EvStr
) then
1791 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1793 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1797 MC_SEND_FullStateRequest
;
1803 if (g_Res_received_map_start
<> 0) then
1805 g_Res_received_map_start
:= -1;
1809 gMissionFailed
:= EvNum
<> 0;
1810 gExit
:= EXIT_ENDLEVELCUSTOM
;
1818 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1820 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1822 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1828 if EvNum
= TEAM_RED
then
1829 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1830 if EvNum
= TEAM_BLUE
then
1831 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1836 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1837 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1842 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1843 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1847 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1849 NET_EV_LMS_SURVIVOR
:
1850 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1853 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1857 pl
:= g_Player_Get(EvNum
and $FFFF);
1862 cnt
:= (EvNum
shr 16) and $FF;
1863 if Pos('w', EvStr
) = 0 then
1866 if Pos('t', EvStr
) = 0 then
1869 if Pos('-', EvStr
) = 0 then
1871 if Pos('e', EvStr
) = 0 then
1872 i1
:= I_PLAYER_SCORE_ADD_OWN
1874 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1877 if Pos('e', EvStr
) = 0 then
1878 i1
:= I_PLAYER_SCORE_SUB_OWN
1880 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1883 if Pos('r', EvStr
) > 0 then
1884 i2
:= I_PLAYER_SCORE_TO_RED
1886 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1887 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1891 if Pos('-', EvStr
) = 0 then
1892 i1
:= I_PLAYER_SCORE_ADD_TEAM
1894 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1896 if Pos('r', EvStr
) > 0 then
1897 i2
:= I_PLAYER_SCORE_RED
1899 i2
:= I_PLAYER_SCORE_BLUE
;
1900 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1905 if Pos('e', EvStr
) = 0 then
1906 i1
:= I_PLAYER_SCORE_WIN_OWN
1908 i1
:= I_PLAYER_SCORE_WIN_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
, _lc
[i2
]]), True);
1920 if EvNum
= TEAM_RED
then
1921 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1922 if EvNum
= TEAM_BLUE
then
1923 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1924 if EvNum
= -TEAM_RED
then
1925 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1926 if EvNum
= -TEAM_BLUE
then
1927 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1932 g_Player_RemoveAllCorpses
;
1933 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1937 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1941 if EvNum
= TEAM_RED
then
1942 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1943 if EvNum
= TEAM_BLUE
then
1944 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1948 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1951 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1954 g_Game_Announce_KillCombo(EvNum
);
1956 NET_EV_PLAYER_TOUCH
:
1958 pl
:= g_Player_Get(EvNum
);
1965 pl
:= g_Player_Get(EvNum
);
1968 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
1969 g_Sound_PlayEx('SOUND_GAME_SECRET');
1975 pl
:= g_Player_Get(EvNum
);
1976 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
1981 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1990 EvType
:= M
.ReadByte();
1993 if Fl
= FLAG_NONE
then Exit
;
1995 Quiet
:= (M
.ReadByte() <> 0);
1996 PID
:= M
.ReadWord();
1998 gFlags
[Fl
].State
:= M
.ReadByte();
1999 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2000 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2001 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2002 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2003 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2005 Pl
:= g_Player_Get(PID
);
2007 (EvType
<> FLAG_STATE_NORMAL
) and
2008 (EvType
<> FLAG_STATE_DROPPED
) and
2009 (EvType
<> FLAG_STATE_RETURNED
) then
2015 if Quiet
or (Pl
= nil) then Exit
;
2017 if Fl
= FLAG_RED
then
2018 s
:= _lc
[I_PLAYER_FLAG_RED
]
2020 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2022 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2024 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2025 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2026 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2031 if not sound_ret_flag
[a
].IsPlaying() then
2032 sound_ret_flag
[a
].Play();
2035 FLAG_STATE_CAPTURED
:
2037 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2041 if Fl
= FLAG_RED
then
2042 s
:= _lc
[I_PLAYER_FLAG_RED
]
2044 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2046 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2047 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2049 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2050 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2051 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2056 if not sound_get_flag
[a
].IsPlaying() then
2057 sound_get_flag
[a
].Play();
2062 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2064 if Quiet
or (Pl
= nil) then Exit
;
2066 if Fl
= FLAG_RED
then
2067 s
:= _lc
[I_PLAYER_FLAG_RED
]
2069 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2071 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2072 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2074 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2075 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2076 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2081 if not sound_lost_flag
[a
].IsPlaying() then
2082 sound_lost_flag
[a
].Play();
2087 g_Map_ResetFlag(FLAG_RED
);
2088 g_Map_ResetFlag(FLAG_BLUE
);
2089 if Quiet
or (Pl
= nil) then Exit
;
2090 Pl
.SetFlag(FLAG_NONE
);
2092 if Fl
= FLAG_RED
then
2093 s
:= _lc
[I_PLAYER_FLAG_RED
]
2095 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2097 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2098 Insert('.', ts
, Length(ts
) + 1 - 3);
2099 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2100 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2102 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2103 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2104 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2109 if not sound_cap_flag
[a
].IsPlaying() then
2110 sound_cap_flag
[a
].Play();
2113 FLAG_STATE_RETURNED
:
2115 g_Map_ResetFlag(Fl
);
2118 if Fl
= FLAG_RED
then
2119 s
:= _lc
[I_PLAYER_FLAG_RED
]
2121 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2123 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2125 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2126 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2127 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2132 if not sound_ret_flag
[a
].IsPlaying() then
2133 sound_ret_flag
[a
].Play();
2138 procedure MC_RECV_GameSettings(var M
: TMsg
);
2140 gGameSettings
.GameMode
:= M
.ReadByte();
2141 gGameSettings
.GoalLimit
:= M
.ReadWord();
2142 gGameSettings
.TimeLimit
:= M
.ReadWord();
2143 gGameSettings
.MaxLives
:= M
.ReadByte();
2144 gGameSettings
.Options
:= M
.ReadLongWord();
2149 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2152 PName
, Model
: string;
2157 PID
:= M
.ReadWord();
2158 Pl
:= g_Player_Get(PID
);
2160 PName
:= M
.ReadString();
2161 Model
:= M
.ReadString();
2162 Color
.R
:= M
.ReadByte();
2163 Color
.G
:= M
.ReadByte();
2164 Color
.B
:= M
.ReadByte();
2168 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2170 if (Pl
<> nil) then Exit
;
2171 DID
:= g_Player_Create(Model
, Color
, T
, False);
2172 with g_Player_Get(DID
) do
2181 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2182 gPlayer1
.UID
:= PID
;
2183 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2184 gPlayer1
.ChangeTeam(T
);
2186 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2187 gPlayer2
.UID
:= PID
;
2188 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2189 gPlayer2
.ChangeTeam(T
);
2193 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2194 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2198 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2205 TmpX
, TmpY
: Integer;
2209 GT
:= M
.ReadLongWord();
2210 if GT
< gTime
- NET_MAX_DIFFTIME
then
2217 PID
:= M
.ReadWord();
2218 Pl
:= g_Player_Get(PID
);
2220 if Pl
= nil then Exit
;
2226 FPing
:= M
.ReadWord();
2227 FLoss
:= M
.ReadByte();
2228 kByte
:= M
.ReadWord();
2229 Dir
:= M
.ReadByte();
2231 TmpX
:= M
.ReadLongInt();
2232 TmpY
:= M
.ReadLongInt();
2236 if (kByte
= NET_KEY_CHAT
) then
2237 PressKey(KEY_CHAT
, 10000)
2240 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2241 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2242 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2243 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2244 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2247 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2248 SetDirection(TDirection(Dir
));
2250 GameVelX
:= M
.ReadLongInt();
2251 GameVelY
:= M
.ReadLongInt();
2252 GameAccelX
:= M
.ReadLongInt();
2253 GameAccelY
:= M
.ReadLongInt();
2254 SetLerp(TmpX
, TmpY
);
2255 if NetForcePlayerUpdate
then Update();
2259 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2263 I
, OldFire
: Integer;
2264 OldJet
, Flam
: Boolean;
2267 PID
:= M
.ReadWord();
2268 Pl
:= g_Player_Get(PID
);
2275 alive
:= (M
.ReadByte() <> 0);
2276 GodMode
:= (M
.ReadByte() <> 0);
2277 Health
:= M
.ReadLongInt();
2278 Armor
:= M
.ReadLongInt();
2279 Air
:= M
.ReadLongInt();
2280 JetFuel
:= M
.ReadLongInt();
2281 Lives
:= M
.ReadByte();
2282 NewTeam
:= M
.ReadByte();
2284 for I
:= WP_FIRST
to WP_LAST
do
2285 FWeapon
[I
] := (M
.ReadByte() <> 0);
2287 for I
:= A_BULLETS
to A_HIGH
do
2288 FAmmo
[I
] := M
.ReadWord();
2290 for I
:= A_BULLETS
to A_HIGH
do
2291 FMaxAmmo
[I
] := M
.ReadWord();
2293 for I
:= MR_SUIT
to MR_MAX
do
2294 FMegaRulez
[I
] := M
.ReadLongWord();
2297 if (M
.ReadByte() <> 0) then
2298 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2299 if (M
.ReadByte() <> 0) then
2300 FRulez
:= FRulez
+ [R_KEY_RED
];
2301 if (M
.ReadByte() <> 0) then
2302 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2303 if (M
.ReadByte() <> 0) then
2304 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2305 if (M
.ReadByte() <> 0) then
2306 FRulez
:= FRulez
+ [R_BERSERK
];
2308 Frags
:= M
.ReadLongInt();
2309 Death
:= M
.ReadLongInt();
2311 SetWeapon(M
.ReadByte());
2313 FSpectator
:= M
.ReadByte() <> 0;
2316 if Pl
= gPlayer1
then
2321 if Pl
= gPlayer2
then
2329 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2330 gPlayer1
:= g_Player_Get(gLMSPID1
);
2331 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2332 gPlayer2
:= g_Player_Get(gLMSPID2
);
2334 FGhost
:= M
.ReadByte() <> 0;
2335 FPhysics
:= M
.ReadByte() <> 0;
2336 FNoRespawn
:= M
.ReadByte() <> 0;
2338 FJetpack
:= M
.ReadByte() <> 0;
2339 OldFire
:= FFireTime
;
2340 FFireTime
:= M
.ReadLongInt();
2341 if (OldFire
<= 0) and (FFireTime
> 0) then
2342 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2343 Flam
:= M
.ReadByte() <> 0;
2344 if OldJet
and not FJetpack
then
2346 else if not OldJet
and FJetpack
then
2348 if FFlaming
and not Flam
then
2350 if Team
<> NewTeam
then
2351 Pl
.ChangeTeam(NewTeam
);
2357 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2362 Attacker
, Value
: Word;
2366 if not gGameOn
then Exit
;
2367 PID
:= M
.ReadWord();
2368 Pl
:= g_Player_Get(PID
);
2369 if Pl
= nil then Exit
;
2371 Kind
:= M
.ReadByte();
2372 Attacker
:= M
.ReadWord();
2373 Value
:= M
.ReadWord();
2378 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2383 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2387 KillType
, DeathType
: Byte;
2391 if not gGameOn
then Exit
;
2392 PID
:= M
.ReadWord();
2393 Pl
:= g_Player_Get(PID
);
2394 if Pl
= nil then Exit
;
2396 KillType
:= M
.ReadByte();
2397 DeathType
:= M
.ReadByte();
2398 Attacker
:= M
.ReadWord();
2402 Kill(KillType
, Attacker
, DeathType
);
2407 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2412 PID
:= M
.ReadWord();
2413 Pl
:= g_Player_Get(PID
);
2415 if Pl
= nil then Exit
;
2417 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2418 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2420 g_Player_Remove(PID
);
2425 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2430 X
, Y
, AX
, AY
: Integer;
2434 if not gGameOn
then Exit
;
2435 PID
:= M
.ReadWord();
2436 Pl
:= g_Player_Get(PID
);
2437 if Pl
= nil then Exit
;
2439 Weap
:= M
.ReadByte();
2440 X
:= M
.ReadLongInt();
2441 Y
:= M
.ReadLongInt();
2442 AX
:= M
.ReadLongInt();
2443 AY
:= M
.ReadLongInt();
2444 SHID
:= M
.ReadLongInt();
2447 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2450 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2459 PID
:= M
.ReadWord();
2460 Pl
:= g_Player_Get(PID
);
2461 if Pl
= nil then Exit
;
2463 TmpName
:= M
.ReadString();
2464 TmpModel
:= M
.ReadString();
2465 TmpColor
.R
:= M
.ReadByte();
2466 TmpColor
.G
:= M
.ReadByte();
2467 TmpColor
.B
:= M
.ReadByte();
2468 TmpTeam
:= M
.ReadByte();
2470 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2472 Pl
.ChangeTeam(TmpTeam
);
2473 if gPlayer1
= Pl
then
2474 gPlayer1Settings
.Team
:= TmpTeam
;
2475 if gPlayer2
= Pl
then
2476 gPlayer2Settings
.Team
:= TmpTeam
;
2478 Pl
.SetColor(TmpColor
);
2480 if Pl
.Name
<> TmpName
then
2482 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2486 if TmpModel
<> Pl
.Model
.Name
then
2487 Pl
.SetModel(TmpModel
);
2492 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2496 X
, Y
, VX
, VY
: Integer;
2498 Quiet
, Fall
{, Resp}: Boolean;
2502 if not gGameOn
then Exit
;
2504 Quiet
:= M
.ReadByte() <> 0;
2506 Fall
:= M
.ReadByte() <> 0;
2507 {Resp :=} M
.ReadByte();
2508 X
:= M
.ReadLongInt();
2509 Y
:= M
.ReadLongInt();
2510 VX
:= M
.ReadLongInt();
2511 VY
:= M
.ReadLongInt();
2513 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2514 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2516 it
:= g_Items_ByIdx(ID
);
2522 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2523 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2525 Anim
:= TAnimation
.Create(AID
, False, 4);
2526 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2532 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2537 if not gGameOn
then Exit
;
2539 Quiet
:= M
.ReadByte() <> 0;
2541 if not g_Items_ValidId(ID
) then exit
;
2543 if not Quiet
then g_Items_EmitPickupSound(ID
);
2550 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2557 if not gGameOn
then Exit
;
2559 PGUID
:= Integer(M
.ReadLongWord());
2560 Tex
:= M
.ReadLongInt();
2561 Fr
:= M
.ReadLongInt();
2562 Cnt
:= M
.ReadByte();
2563 Loop
:= M
.ReadByte();
2565 TP
:= g_Map_PanelByGUID(PGUID
);
2569 TP
.SetTexture(Tex
, Loop
);
2570 TP
.SetFrame(Fr
, Cnt
);
2574 procedure MC_RECV_PanelState(var M
: TMsg
);
2579 X
, Y
, W
, H
: Integer;
2581 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2582 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2585 if not gGameOn
then Exit
;
2587 PGUID
:= Integer(M
.ReadLongWord());
2588 E
:= (M
.ReadByte() <> 0);
2589 Lift
:= M
.ReadByte();
2590 X
:= M
.ReadLongInt();
2591 Y
:= M
.ReadLongInt();
2595 speedX
:= M
.ReadLongInt();
2596 speedY
:= M
.ReadLongInt();
2597 startX
:= M
.ReadLongInt();
2598 startY
:= M
.ReadLongInt();
2599 endX
:= M
.ReadLongInt();
2600 endY
:= M
.ReadLongInt();
2601 sizeSpX
:= M
.ReadLongInt();
2602 sizeSpY
:= M
.ReadLongInt();
2603 sizeEX
:= M
.ReadLongInt();
2604 sizeEY
:= M
.ReadLongInt();
2605 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2607 TP
:= g_Map_PanelByGUID(PGUID
);
2608 if (TP
= nil) then exit
;
2610 // update lifts state
2611 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2613 // update enabled/disabled state for all panels
2614 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2616 // update panel position, as it can be moved (mplat)
2621 // update mplat state
2622 TP
.movingSpeedX
:= speedX
;
2623 TP
.movingSpeedY
:= speedY
;
2624 TP
.movingStartX
:= startX
;
2625 TP
.movingStartY
:= startY
;
2626 TP
.movingEndX
:= endX
;
2627 TP
.movingEndY
:= endY
;
2628 TP
.sizeSpeedX
:= sizeSpX
;
2629 TP
.sizeSpeedY
:= sizeSpY
;
2630 TP
.sizeEndX
:= sizeEX
;
2631 TP
.sizeEndY
:= sizeEY
;
2632 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2633 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2634 // notify panel of it's position/size change, so it can fix other internal structures
2635 TP
.positionChanged();
2640 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2643 SPos
, SID
: LongWord;
2647 if not gGameOn
then Exit
;
2648 if gTriggers
= nil then Exit
;
2650 SID
:= M
.ReadLongWord();
2651 SPlaying
:= M
.ReadByte() <> 0;
2652 SPos
:= M
.ReadLongWord();
2653 SCount
:= M
.ReadLongInt();
2655 for I
:= Low(gTriggers
) to High(gTriggers
) do
2656 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2657 if gTriggers
[I
].ClientID
= SID
then
2658 with gTriggers
[I
] do
2660 if Sound
<> nil then
2665 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2667 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2668 Sound
.SetPosition(SPos
);
2671 if Sound
.IsPlaying
then Sound
.Stop
;
2674 SoundPlayCount
:= SCount
;
2678 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2685 if not gGameOn
then Exit
;
2687 MName
:= M
.ReadString();
2688 MPlaying
:= M
.ReadByte() <> 0;
2689 MPos
:= M
.ReadLongWord();
2690 MPaused
:= M
.ReadByte() <> 0;
2691 MPos
:= MPos
+1; //k8: stfu, fpc!
2695 gMusic
.SetByName(MName
);
2697 // gMusic.SetPosition(MPos);
2698 gMusic
.SpecPause
:= MPaused
;
2701 if gMusic
.IsPlaying
then gMusic
.Stop
;
2706 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2709 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2710 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2715 Mon
:= g_Monsters_ByUID(ID
);
2719 MType
:= M
.ReadByte();
2720 MState
:= M
.ReadByte();
2721 MAnim
:= M
.ReadByte();
2722 MTarg
:= M
.ReadWord();
2723 MTargTime
:= M
.ReadLongInt();
2724 MBehav
:= M
.ReadByte();
2725 MSleep
:= M
.ReadLongInt();
2726 MHealth
:= M
.ReadLongInt();
2727 MAmmo
:= M
.ReadLongInt();
2729 X
:= M
.ReadLongInt();
2730 Y
:= M
.ReadLongInt();
2731 VX
:= M
.ReadLongInt();
2732 VY
:= M
.ReadLongInt();
2733 MDir
:= M
.ReadByte();
2735 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2736 Mon
:= g_Monsters_ByUID(ID
);
2743 MonsterAnim
:= MAnim
;
2744 MonsterTargetUID
:= MTarg
;
2745 MonsterTargetTime
:= MTargTime
;
2746 MonsterBehaviour
:= MBehav
;
2747 MonsterSleep
:= MSleep
;
2748 MonsterAmmo
:= MAmmo
;
2753 setPosition(X
, Y
); // this will call positionChanged();
2759 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2766 Mon
:= g_Monsters_ByUID(ID
);
2772 X
:= M
.ReadLongInt();
2773 Y
:= M
.ReadLongInt();
2774 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2775 GameVelX
:= M
.ReadLongInt();
2776 GameVelY
:= M
.ReadLongInt();
2777 GameDirection
:= TDirection(M
.ReadByte());
2781 procedure MC_RECV_MonsterState(var M
: TMsg
);
2783 ID
, OldFire
: Integer;
2784 MState
, MFAnm
: Byte;
2786 AnimRevert
: Boolean;
2789 Mon
:= g_Monsters_ByUID(ID
);
2790 if Mon
= nil then Exit
;
2792 MState
:= M
.ReadByte();
2793 MFAnm
:= M
.ReadByte();
2797 MonsterTargetUID
:= M
.ReadWord();
2798 MonsterTargetTime
:= M
.ReadLongInt();
2799 MonsterSleep
:= M
.ReadLongInt();
2800 MonsterHealth
:= M
.ReadLongInt();
2801 MonsterAmmo
:= M
.ReadLongInt();
2802 MonsterPain
:= M
.ReadLongInt();
2803 AnimRevert
:= M
.ReadByte() <> 0;
2804 OldFire
:= FFireTime
;
2805 FFireTime
:= M
.ReadLongInt();
2806 if (OldFire
<= 0) and (FFireTime
> 0) then
2807 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2808 RevertAnim(AnimRevert
);
2810 if MonsterState
<> MState
then
2812 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2813 if (MState
= MONSTATE_DIE
) then DieSound();
2814 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2815 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2816 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2818 SetState(MState
, MFAnm
);
2823 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2827 X
, Y
, VX
, VY
: Integer;
2831 Mon
:= g_Monsters_ByUID(ID
);
2832 if Mon
= nil then Exit
;
2834 X
:= M
.ReadLongInt();
2835 Y
:= M
.ReadLongInt();
2836 VX
:= M
.ReadLongInt();
2837 VY
:= M
.ReadLongInt();
2839 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2842 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2848 Mon
:= g_Monsters_ByUID(ID
);
2849 if Mon
= nil then Exit
;
2851 Mon
.MonsterRemoved
:= True;
2854 procedure MC_RECV_TimeSync(var M
: TMsg
);
2858 Time
:= M
.ReadLongWord();
2860 if gState
= STATE_INTERCUSTOM
then
2861 gServInterTime
:= Min(Time
, 255);
2864 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2868 Int1
, Int2
: SmallInt;
2870 EvID
:= M
.ReadByte();
2871 Int1
:= M
.ReadSmallInt();
2872 Int2
:= M
.ReadSmallInt();
2873 Str1
:= M
.ReadString();
2874 Str2
:= M
.ReadString();
2878 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2880 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2882 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2884 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2886 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2892 procedure MC_SEND_Info(Password
: string);
2896 NetOut
.Write(Byte(NET_MSG_INFO
));
2897 NetOut
.Write(GAME_VERSION
);
2898 NetOut
.Write(Password
);
2899 NetOut
.Write(gPlayer1Settings
.Name
);
2900 NetOut
.Write(gPlayer1Settings
.Model
);
2901 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2902 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2903 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2904 NetOut
.Write(gPlayer1Settings
.Team
);
2906 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2909 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2911 NetOut
.Write(Byte(NET_MSG_CHAT
));
2915 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2918 procedure MC_SEND_PlayerPos();
2923 WeaponSelect
: Word = 0;
2926 if not gGameOn
then Exit
;
2927 if gPlayers
= nil then Exit
;
2928 if gPlayer1
= nil then Exit
;
2931 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2933 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2935 strafeDir
:= P1MoveButton
shr 4;
2936 P1MoveButton
:= P1MoveButton
and $0F;
2938 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2940 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2942 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2946 if gPlayerAction
[0, ACTION_STRAFE
] then
2948 // new strafe mechanics
2949 if (strafeDir
= 0) then
2950 strafeDir
:= P1MoveButton
; // start strafing
2951 // now set direction according to strafe (reversed)
2952 if (strafeDir
= 2) then
2953 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2954 else if (strafeDir
= 1) then
2955 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2959 strafeDir
:= 0; // not strafing anymore
2960 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
2961 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2962 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2963 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2964 else if P1MoveButton
<> 0 then
2965 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2968 gPlayer1
.ReleaseKeys
;
2969 if P1MoveButton
= 1 then
2971 kByte
:= kByte
or NET_KEY_LEFT
;
2972 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2974 if P1MoveButton
= 2 then
2976 kByte
:= kByte
or NET_KEY_RIGHT
;
2977 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2979 if gPlayerAction
[0, ACTION_LOOKUP
] then
2981 kByte
:= kByte
or NET_KEY_UP
;
2982 gPlayer1
.PressKey(KEY_UP
, 10000);
2984 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2986 kByte
:= kByte
or NET_KEY_DOWN
;
2987 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2989 if gPlayerAction
[0, ACTION_JUMP
] then
2991 kByte
:= kByte
or NET_KEY_JUMP
;
2992 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2994 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
2995 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
2996 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
2997 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
2999 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3000 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
3002 for i
:= WP_FIRST
to WP_LAST
do
3004 if gSelectWeapon
[0, i
] then
3006 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3007 gSelectWeapon
[0, i
] := False
3011 // fix movebutton state
3012 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3015 kByte
:= NET_KEY_CHAT
;
3017 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3018 NetOut
.Write(gTime
);
3019 NetOut
.Write(kByte
);
3020 NetOut
.Write(Byte(gPlayer1
.Direction
));
3021 NetOut
.Write(WeaponSelect
);
3022 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3023 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3025 //kBytePrev := kByte;
3026 //kDirPrev := gPlayer1.Direction;
3029 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3031 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3032 NetOut
.Write(Byte(Start
));
3033 NetOut
.Write(Command
);
3034 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3037 procedure MC_SEND_PlayerSettings();
3039 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3040 NetOut
.Write(gPlayer1Settings
.Name
);
3041 NetOut
.Write(gPlayer1Settings
.Model
);
3042 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3043 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3044 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3045 NetOut
.Write(gPlayer1Settings
.Team
);
3047 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3050 procedure MC_SEND_FullStateRequest();
3052 NetOut
.Write(Byte(NET_MSG_REQFST
));
3054 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3057 procedure MC_SEND_CheatRequest(Kind
: Byte);
3059 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3062 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3064 procedure MC_SEND_RCONPassword(Password
: string);
3066 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3067 NetOut
.Write(Password
);
3069 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3071 procedure MC_SEND_RCONCommand(Cmd
: string);
3073 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3076 g_Net_Client_Send(True, NET_CHAN_SERVICE
);