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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
21 uses e_msg
, g_net
, g_triggers
, Classes
, SysUtils
, md5
;
65 NET_MSG_RCON_AUTH
= 191;
66 NET_MSG_RCON_CMD
= 192;
67 NET_MSG_TIME_SYNC
= 194;
68 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;
96 NET_EV_CHANGE_TEAM
= 3;
97 NET_EV_PLAYER_KICK
= 4;
98 NET_EV_PLAYER_BAN
= 5;
99 NET_EV_LMS_WARMUP
= 6;
100 NET_EV_LMS_SURVIVOR
= 7;
104 NET_EV_SCORE_MSG
= 11;
105 NET_EV_LMS_START
= 12;
107 NET_EV_TLMS_WIN
= 14;
108 NET_EV_LMS_LOSE
= 15;
109 NET_EV_LMS_DRAW
= 16;
110 NET_EV_KILLCOMBO
= 17;
111 NET_EV_PLAYER_TOUCH
= 18;
113 NET_EV_INTER_READY
= 20;
120 NET_VE_INPROGRESS
= 6;
127 NET_CHEAT_SUICIDE
= 1;
128 NET_CHEAT_SPECTATE
= 2;
131 NET_MAX_DIFFTIME
= 5000 div 36;
135 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
136 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
137 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
138 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
139 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
140 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
141 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
142 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
143 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
148 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
149 procedure MH_SEND_Info(ID
: Byte);
150 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
151 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
152 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
153 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
154 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
186 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_VoteEvent(EvType
: Byte;
188 StrArg1
: string = 'a'; StrArg2
: string = 'b';
189 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
190 ID
: Integer = NET_EVERYONE
);
192 // CLIENT MESSAGES //
195 procedure MC_RECV_Chat(var M
: TMsg
);
196 procedure MC_RECV_Effect(var M
: TMsg
);
197 procedure MC_RECV_Sound(var M
: TMsg
);
198 procedure MC_RECV_GameStats(var M
: TMsg
);
199 procedure MC_RECV_CoopStats(var M
: TMsg
);
200 procedure MC_RECV_GameEvent(var M
: TMsg
);
201 procedure MC_RECV_FlagEvent(var M
: TMsg
);
202 procedure MC_RECV_GameSettings(var M
: TMsg
);
204 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
205 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
206 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
207 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
208 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
209 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
210 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
211 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
213 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
214 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
216 procedure MC_RECV_PanelTexture(var M
: TMsg
);
217 procedure MC_RECV_PanelState(var M
: TMsg
);
219 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
220 procedure MC_RECV_MonsterPos(var M
: TMsg
);
221 procedure MC_RECV_MonsterState(var M
: TMsg
);
222 procedure MC_RECV_MonsterShot(var M
: TMsg
);
223 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
225 procedure MC_RECV_CreateShot(var M
: TMsg
);
226 procedure MC_RECV_UpdateShot(var M
: TMsg
);
227 procedure MC_RECV_DeleteShot(var M
: TMsg
);
229 procedure MC_RECV_TriggerSound(var M
: TMsg
);
230 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
232 procedure MC_RECV_TimeSync(var M
: TMsg
);
233 procedure MC_RECV_VoteEvent(var M
: TMsg
);
235 procedure MC_SEND_Info(Password
: string);
236 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
237 procedure MC_SEND_PlayerPos();
238 procedure MC_SEND_FullStateRequest();
239 procedure MC_SEND_PlayerSettings();
240 procedure MC_SEND_CheatRequest(Kind
: Byte);
241 procedure MC_SEND_RCONPassword(Password
: string);
242 procedure MC_SEND_RCONCommand(Cmd
: string);
243 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
245 procedure MC_SEND_MapRequest();
246 procedure MC_SEND_ResRequest(const resName
: AnsiString);
249 TExternalResourceInfo
= record
264 ExternalResources
: array of TExternalResourceInfo
;
267 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
268 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
273 Math
, ENet
, e_input
, e_graphics
, e_log
,
274 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
275 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
276 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
289 NET_KEY_FORCEDIR
= 4096;
292 //kBytePrev: Word = 0;
293 //kDirPrev: TDirection = D_LEFT;
294 //HostGameTime: Word = 0;
301 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
309 Pl
:= g_Player_Get(PID
);
311 Txt
:= M
.ReadString();
312 Mode
:= M
.ReadByte();
313 if (Mode
= NET_CHAT_SYSTEM
) then
314 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
315 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
316 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
319 MH_SEND_Chat(Txt
, Mode
)
321 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
324 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
326 Ver
, PName
, Model
, Pw
: string;
332 Ver
:= M
.ReadString();
333 Pw
:= M
.ReadString();
334 PName
:= M
.ReadString();
335 Model
:= M
.ReadString();
341 if Ver
<> GAME_VERSION
then
343 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
344 _lc
[I_NET_DISC_VERSION
]);
345 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
349 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
351 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
353 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
354 _lc
[I_NET_DISC_BAN
]);
355 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
359 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
360 _lc
[I_NET_DISC_BAN
]);
361 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
366 if NetPassword
<> '' then
367 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
369 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
370 _lc
[I_NET_DISC_PASSWORD
]);
371 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
379 PID
:= g_Player_Create(Model
, Color
, T
, False);
380 with g_Player_Get(PID
) do
388 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
389 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
390 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
394 with g_Player_Get(PID
) do
398 // round in progress, don't spawn
399 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
404 FWantsInGame
:= True; // TODO: look into this later
407 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
410 for I
:= Low(NetClients
) to High(NetClients
) do
412 if NetClients
[I
].ID
= C
^.ID
then Continue
;
413 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
414 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
415 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
418 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
419 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
421 if NetUseMaster
then g_Net_Slist_Update
;
424 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
427 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
429 C
^.RequestedFullUpdate
:= True;
434 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
444 if not gGameOn
then Exit
;
446 GT
:= M
.ReadLongWord();
448 Pl
:= g_Player_Get(PID
);
452 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
457 kByte
:= M
.ReadWord();
459 WeaponSelect
:= M
.ReadWord();
460 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
461 if Direction
<> TDirection(Dir
) then
462 JustTeleported
:= False;
464 SetDirection(TDirection(Dir
));
467 if kByte
= NET_KEY_CHAT
then
469 PressKey(KEY_CHAT
, 10000);
473 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
474 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
475 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
476 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
477 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
478 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
479 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
480 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
481 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
485 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
487 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
488 QueueWeaponSwitch(i
);
493 // MH_SEND_PlayerPos(False, PID, C^.ID);
496 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
501 Pl
:= g_Player_Get(C
^.Player
);
502 if Pl
= nil then Exit
;
504 CheatKind
:= M
.ReadByte();
508 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
511 if Pl
.FSpectator
then
518 if gState
<> STATE_INTERCUSTOM
then Exit
;
519 Pl
.FReady
:= not Pl
.FReady
;
522 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
523 Inc(gInterReadyCount
);
527 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
528 Dec(gInterReadyCount
);
534 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
542 TmpName
:= M
.ReadString();
543 TmpModel
:= M
.ReadString();
544 TmpColor
.R
:= M
.ReadByte();
545 TmpColor
.G
:= M
.ReadByte();
546 TmpColor
.B
:= M
.ReadByte();
547 TmpTeam
:= M
.ReadByte();
549 Pl
:= g_Player_Get(C
^.Player
);
550 if Pl
= nil then Exit
;
552 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
555 Pl
.SetColor(TmpColor
);
557 if Pl
.Name
<> TmpName
then
559 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
563 if TmpModel
<> Pl
.Model
.Name
then
564 Pl
.SetModel(TmpModel
);
566 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
571 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
575 Pwd
:= M
.ReadString();
576 if not NetAllowRCON
then Exit
;
577 if Pwd
= NetRCONPassword
then
580 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
583 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
586 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
590 Cmd
:= M
.ReadString();
591 if not NetAllowRCON
then Exit
;
592 if not C
^.RCONAuth
then
594 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
597 g_Console_Process(Cmd
);
602 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
605 Name
, Command
: string;
609 Start
:= M
.ReadByte() <> 0;
610 Command
:= M
.ReadString();
612 Pl
:= g_Player_Get(C
^.Player
);
613 if Pl
= nil then Exit
;
618 if not g_Console_CommandBlacklisted(Command
) then
619 g_Game_StartVote(Command
, Name
);
621 else if gVoteInProgress
then
623 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
624 Need
:= Floor((NetClientCount
+1)/2.0) + 1
626 Need
:= Floor(NetClientCount
/2.0) + 1;
631 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
632 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
638 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
639 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
647 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
649 function sendItemRespawn (it
: PItem
): Boolean;
651 result
:= false; // don't stop
652 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
655 function sendMonSpawn (mon
: TMonster
): Boolean;
657 result
:= false; // don't stop
658 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
661 function sendPanelState (pan
: TPanel
): Boolean;
663 result
:= false; // don't stop
664 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
665 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
671 if gPlayers
<> nil then
673 for I
:= Low(gPlayers
) to High(gPlayers
) do
675 if gPlayers
[I
] <> nil then
677 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
678 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
679 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
681 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
683 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
689 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
690 g_Mons_ForEach(sendMonSpawn
);
691 g_Map_ForEachPanel(sendPanelState
);
693 if gTriggers
<> nil then
695 for I
:= Low(gTriggers
) to High(gTriggers
) do
697 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
699 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
706 for I
:= Low(Shots
) to High(Shots
) do
708 if Shots
[i
].ShotType
in [6, 7, 8] then
710 MH_SEND_CreateShot(i
, ID
);
715 MH_SEND_TriggerMusic(ID
);
717 MH_SEND_GameStats(ID
);
718 MH_SEND_CoopStats(ID
);
720 if gGameSettings
.GameMode
= GM_CTF
then
722 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
723 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
726 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
728 if gLMSRespawn
> LMS_RESPAWN_NONE
then
730 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
736 procedure MH_SEND_Info(ID
: Byte);
740 Map
:= g_ExtractFileName(gMapInfo
.Map
);
744 NetOut
.Write(Byte(NET_MSG_INFO
));
746 NetOut
.Write(NetClients
[ID
].Player
);
747 NetOut
.Write(gGameSettings
.WAD
);
749 NetOut
.Write(gWADHash
);
750 NetOut
.Write(gGameSettings
.GameMode
);
751 NetOut
.Write(gGameSettings
.GoalLimit
);
752 NetOut
.Write(gGameSettings
.TimeLimit
);
753 NetOut
.Write(gGameSettings
.MaxLives
);
754 NetOut
.Write(gGameSettings
.Options
);
757 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
760 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
766 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
767 Mode
:= NET_CHAT_PLAYER
;
770 if (Mode
= NET_CHAT_TEAM
) then
772 for i
:= Low(gPlayers
) to High(gPlayers
) do
773 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
774 (gPlayers
[i
].Team
= ID
) then
776 NetOut
.Write(Byte(NET_MSG_CHAT
));
779 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
786 NetOut
.Write(Byte(NET_MSG_CHAT
));
789 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
792 if Mode
= NET_CHAT_SYSTEM
then
795 if ID
= NET_EVERYONE
then
797 if Mode
= NET_CHAT_PLAYER
then
799 g_Console_Add(Txt
, True);
800 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
801 g_Game_ChatSound(b_Text_Unformat(Txt
));
804 if Mode
= NET_CHAT_TEAM
then
805 if gPlayer1
<> nil then
807 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
809 g_Console_Add(#18'[Team] '#2 + Txt
, True);
810 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
811 g_Game_ChatSound(b_Text_Unformat(Txt
));
813 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
815 g_Console_Add(#20'[Team] '#2 + Txt
, True);
816 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
817 g_Game_ChatSound(b_Text_Unformat(Txt
));
823 Name
:= g_Net_ClientName_ByID(ID
);
824 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
825 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
826 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
830 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
832 NetOut
.Write(Byte(NET_MSG_GFX
));
838 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
841 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
843 NetOut
.Write(Byte(NET_MSG_SND
));
847 NetOut
.Write(Byte(1));
852 NetOut
.Write(Byte(0));
854 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
857 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
859 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
861 NetOut
.Write(Byte(NET_MSG_SHADD
));
863 NetOut
.Write(Shots
[Proj
].ShotType
);
864 NetOut
.Write(Shots
[Proj
].Target
);
865 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
866 NetOut
.Write(Shots
[Proj
].Timeout
);
867 NetOut
.Write(Shots
[Proj
].Obj
.X
);
868 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
869 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
870 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
872 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
875 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
877 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
879 NetOut
.Write(Byte(NET_MSG_SHPOS
));
881 NetOut
.Write(Shots
[Proj
].Obj
.X
);
882 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
883 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
884 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
886 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
889 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
891 NetOut
.Write(Byte(NET_MSG_SHDEL
));
893 NetOut
.Write(Byte(Loud
));
897 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
900 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
902 NetOut
.Write(Byte(NET_MSG_SCORE
));
903 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
905 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
906 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
909 if gGameSettings
.GameMode
= GM_COOP
then
911 NetOut
.Write(gCoopMonstersKilled
);
912 NetOut
.Write(gCoopSecretsFound
);
915 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
918 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
920 NetOut
.Write(Byte(NET_MSG_COOP
));
921 NetOut
.Write(gTotalMonsters
);
922 NetOut
.Write(gSecretsCount
);
923 NetOut
.Write(gCoopTotalMonstersKilled
);
924 NetOut
.Write(gCoopTotalSecretsFound
);
925 NetOut
.Write(gCoopTotalMonsters
);
926 NetOut
.Write(gCoopTotalSecrets
);
929 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
931 NetOut
.Write(Byte(NET_MSG_GEVENT
));
932 NetOut
.Write(EvType
);
935 NetOut
.Write(Byte(gLastMap
));
937 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
939 NetOut
.Write(Byte(1));
940 NetOut
.Write(gWADHash
);
942 NetOut
.Write(Byte(0));
944 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
947 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
949 NetOut
.Write(Byte(NET_MSG_FLAG
));
950 NetOut
.Write(EvType
);
952 NetOut
.Write(Byte(Quiet
));
954 NetOut
.Write(gFlags
[Flag
].State
);
955 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
956 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
957 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
958 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
959 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
961 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
964 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
966 NetOut
.Write(Byte(NET_MSG_GSET
));
967 NetOut
.Write(gGameSettings
.GameMode
);
968 NetOut
.Write(gGameSettings
.GoalLimit
);
969 NetOut
.Write(gGameSettings
.TimeLimit
);
970 NetOut
.Write(gGameSettings
.MaxLives
);
971 NetOut
.Write(gGameSettings
.Options
);
973 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
978 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
982 P
:= g_Player_Get(PID
);
983 if P
= nil then Exit
;
985 NetOut
.Write(Byte(NET_MSG_PLR
));
987 NetOut
.Write(P
.Name
);
989 NetOut
.Write(P
.FActualModelName
);
990 NetOut
.Write(P
.FColor
.R
);
991 NetOut
.Write(P
.FColor
.G
);
992 NetOut
.Write(P
.FColor
.B
);
993 NetOut
.Write(P
.Team
);
995 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
998 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1003 Pl
:= g_Player_Get(PID
);
1004 if Pl
= nil then Exit
;
1005 if Pl
.FDummy
then Exit
;
1007 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1008 NetOut
.Write(gTime
);
1015 NetOut
.Write(FPing
);
1016 NetOut
.Write(FLoss
);
1017 if IsKeyPressed(KEY_CHAT
) then
1018 kByte
:= NET_KEY_CHAT
1021 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1022 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1023 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1024 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1025 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1026 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1029 NetOut
.Write(kByte
);
1030 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1031 NetOut
.Write(GameX
);
1032 NetOut
.Write(GameY
);
1033 NetOut
.Write(GameVelX
);
1034 NetOut
.Write(GameVelY
);
1035 NetOut
.Write(GameAccelX
);
1036 NetOut
.Write(GameAccelY
);
1039 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1042 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1047 P
:= g_Player_Get(PID
);
1048 if P
= nil then Exit
;
1050 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1055 NetOut
.Write(Byte(alive
));
1056 NetOut
.Write(Byte(GodMode
));
1057 NetOut
.Write(Health
);
1058 NetOut
.Write(Armor
);
1060 NetOut
.Write(JetFuel
);
1061 NetOut
.Write(Lives
);
1064 for I
:= WP_FIRST
to WP_LAST
do
1065 NetOut
.Write(Byte(FWeapon
[I
]));
1067 for I
:= A_BULLETS
to A_HIGH
do
1068 NetOut
.Write(FAmmo
[I
]);
1070 for I
:= A_BULLETS
to A_HIGH
do
1071 NetOut
.Write(FMaxAmmo
[I
]);
1073 for I
:= MR_SUIT
to MR_MAX
do
1074 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1076 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1077 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1078 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1079 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1080 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1082 NetOut
.Write(Frags
);
1083 NetOut
.Write(Death
);
1085 NetOut
.Write(CurrWeap
);
1087 NetOut
.Write(Byte(FSpectator
));
1088 NetOut
.Write(Byte(FGhost
));
1089 NetOut
.Write(Byte(FPhysics
));
1090 NetOut
.Write(Byte(FNoRespawn
));
1091 NetOut
.Write(Byte(FJetpack
));
1092 NetOut
.Write(FFireTime
);
1093 NetOut
.Write(Byte(FFlaming
));
1096 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1099 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1101 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1104 NetOut
.Write(Attacker
);
1105 NetOut
.Write(Value
);
1109 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1112 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1114 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1116 NetOut
.Write(KillType
);
1117 NetOut
.Write(DeathType
);
1118 NetOut
.Write(Attacker
);
1120 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1123 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1125 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1127 NetOut
.Write(Weapon
);
1132 NetOut
.Write(ShotID
);
1134 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1137 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1139 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1142 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1145 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1149 Pl
:= g_Player_Get(PID
);
1150 if Pl
= nil then Exit
;
1152 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1154 NetOut
.Write(Pl
.Name
);
1156 NetOut
.Write(Pl
.Model
.Name
)
1159 NetOut
.Write(Pl
.FColor
.R
);
1160 NetOut
.Write(Pl
.FColor
.G
);
1161 NetOut
.Write(Pl
.FColor
.B
);
1162 NetOut
.Write(Pl
.Team
);
1164 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1169 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1174 it
:= g_Items_ByIdx(IID
);
1176 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1178 NetOut
.Write(Byte(Quiet
));
1180 if it
.dropped
then tt
:= tt
or $80;
1182 NetOut
.Write(Byte(it
.Fall
));
1183 NetOut
.Write(Byte(it
.Respawnable
));
1184 NetOut
.Write(it
.Obj
.X
);
1185 NetOut
.Write(it
.Obj
.Y
);
1186 NetOut
.Write(it
.Obj
.Vel
.X
);
1187 NetOut
.Write(it
.Obj
.Vel
.Y
);
1189 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1192 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1194 NetOut
.Write(Byte(NET_MSG_IDEL
));
1196 NetOut
.Write(Byte(Quiet
));
1198 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1203 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1207 TP
:= g_Map_PanelByGUID(PGUID
);
1208 if (TP
= nil) then exit
;
1212 NetOut
.Write(Byte(NET_MSG_PTEX
));
1213 NetOut
.Write(LongWord(PGUID
));
1214 NetOut
.Write(FCurTexture
);
1215 NetOut
.Write(FCurFrame
);
1216 NetOut
.Write(FCurFrameCount
);
1217 NetOut
.Write(AnimLoop
);
1220 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1223 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1228 TP
:= g_Map_PanelByGUID(PGUID
);
1229 if (TP
= nil) then exit
;
1231 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1232 NetOut
.Write(LongWord(PGUID
));
1233 NetOut
.Write(Byte(TP
.Enabled
));
1234 NetOut
.Write(TP
.LiftType
);
1237 NetOut
.Write(Word(TP
.Width
));
1238 NetOut
.Write(Word(TP
.Height
));
1240 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1241 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1242 NetOut
.Write(LongInt(TP
.movingStartX
));
1243 NetOut
.Write(LongInt(TP
.movingStartY
));
1244 NetOut
.Write(LongInt(TP
.movingEndX
));
1245 NetOut
.Write(LongInt(TP
.movingEndY
));
1246 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1247 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1248 NetOut
.Write(LongInt(TP
.sizeEndX
));
1249 NetOut
.Write(LongInt(TP
.sizeEndY
));
1250 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1251 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1252 NetOut
.Write(Byte(mpflags
));
1254 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1259 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1261 if gTriggers
= nil then Exit
;
1262 if T
.Sound
= nil then Exit
;
1264 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1265 NetOut
.Write(T
.ClientID
);
1266 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1267 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1268 NetOut
.Write(T
.SoundPlayCount
);
1270 g_Net_Host_Send(ID
, True);
1273 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1275 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1276 NetOut
.Write(gMusic
.Name
);
1277 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1278 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1279 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1281 g_Net_Host_Send(ID
, True);
1286 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1290 M
:= g_Monsters_ByUID(UID
);
1296 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1298 NetOut
.Write(MonsterType
);
1299 NetOut
.Write(MonsterState
);
1300 NetOut
.Write(MonsterAnim
);
1301 NetOut
.Write(MonsterTargetUID
);
1302 NetOut
.Write(MonsterTargetTime
);
1303 NetOut
.Write(MonsterBehaviour
);
1304 NetOut
.Write(MonsterSleep
);
1305 NetOut
.Write(MonsterHealth
);
1306 NetOut
.Write(MonsterAmmo
);
1307 NetOut
.Write(GameX
);
1308 NetOut
.Write(GameY
);
1309 NetOut
.Write(GameVelX
);
1310 NetOut
.Write(GameVelY
);
1311 NetOut
.Write(Byte(GameDirection
));
1314 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1317 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1321 M
:= g_Monsters_ByUID(UID
);
1322 if M
= nil then Exit
;
1324 NetOut
.Write(Byte(NET_MSG_MPOS
));
1329 NetOut
.Write(GameX
);
1330 NetOut
.Write(GameY
);
1331 NetOut
.Write(GameVelX
);
1332 NetOut
.Write(GameVelY
);
1333 NetOut
.Write(Byte(GameDirection
));
1336 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1339 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1343 M
:= g_Monsters_ByUID(UID
);
1344 if M
= nil then Exit
;
1346 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1351 NetOut
.Write(MonsterState
);
1352 NetOut
.Write(ForcedAnim
);
1353 NetOut
.Write(MonsterTargetUID
);
1354 NetOut
.Write(MonsterTargetTime
);
1355 NetOut
.Write(MonsterSleep
);
1356 NetOut
.Write(MonsterHealth
);
1357 NetOut
.Write(MonsterAmmo
);
1358 NetOut
.Write(MonsterPain
);
1359 NetOut
.Write(Byte(AnimIsReverse
));
1360 NetOut
.Write(FFireTime
);
1363 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1366 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1368 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1375 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1378 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1382 M
:= g_Monsters_ByUID(UID
);
1383 if M
= nil then Exit
;
1385 NetOut
.Write(Byte(NET_MSG_MDEL
));
1388 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1393 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1395 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1398 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1401 procedure MH_SEND_VoteEvent(EvType
: Byte;
1402 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1403 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1404 ID
: Integer = NET_EVERYONE
);
1406 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1407 NetOut
.Write(EvType
);
1408 NetOut
.Write(IntArg1
);
1409 NetOut
.Write(IntArg2
);
1410 NetOut
.Write(StrArg1
);
1411 NetOut
.Write(StrArg2
);
1413 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1416 // CLIENT MESSAGES //
1420 procedure MC_RECV_Chat(var M
: TMsg
);
1425 Txt
:= M
.ReadString();
1426 Mode
:= M
.ReadByte();
1428 if Mode
<> NET_CHAT_SYSTEM
then
1430 if Mode
= NET_CHAT_PLAYER
then
1432 g_Console_Add(Txt
, True);
1433 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1434 g_Game_ChatSound(b_Text_Unformat(Txt
));
1436 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1438 if gPlayer1
.Team
= TEAM_RED
then
1439 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1440 if gPlayer1
.Team
= TEAM_BLUE
then
1441 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1442 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1443 g_Game_ChatSound(b_Text_Unformat(Txt
));
1446 g_Console_Add(Txt
, True);
1449 procedure MC_RECV_Effect(var M
: TMsg
);
1457 if not gGameOn
then Exit
;
1458 Kind
:= M
.ReadByte();
1459 X
:= M
.ReadLongInt();
1460 Y
:= M
.ReadLongInt();
1461 Ang
:= M
.ReadSmallInt();
1465 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1469 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1471 Anim
:= TAnimation
.Create(ID
, False, 3);
1472 g_GFX_OnceAnim(X
, Y
, Anim
);
1476 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1481 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1483 Anim
:= TAnimation
.Create(ID
, False, 6);
1484 Anim
.Blending
:= False;
1485 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1489 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1494 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1496 Anim
:= TAnimation
.Create(ID
, False, 6);
1497 Anim
.Blending
:= False;
1498 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1502 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1507 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1509 Anim
:= TAnimation
.Create(ID
, False, 4);
1510 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1517 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1519 Anim
:= TAnimation
.Create(ID
, False, 4);
1520 g_GFX_OnceAnim(X
, Y
, Anim
);
1524 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1529 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1531 Anim
:= TAnimation
.Create(ID
, False, 4);
1532 g_GFX_OnceAnim(X
, Y
, Anim
);
1536 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1540 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1543 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1547 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1548 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1553 procedure MC_RECV_Sound(var M
: TMsg
);
1559 Name
:= M
.ReadString();
1560 Pos
:= M
.ReadByte() <> 0;
1563 X
:= M
.ReadLongInt();
1564 Y
:= M
.ReadLongInt();
1565 g_Sound_PlayExAt(Name
, X
, Y
);
1568 g_Sound_PlayEx(Name
);
1571 procedure MC_RECV_CreateShot(var M
: TMsg
);
1573 I
, X
, Y
, XV
, YV
: Integer;
1575 Target
, Spawner
: Word;
1578 I
:= M
.ReadLongInt();
1579 ShType
:= M
.ReadByte();
1580 Target
:= M
.ReadWord();
1581 Spawner
:= M
.ReadWord();
1582 Timeout
:= M
.ReadLongWord();
1583 X
:= M
.ReadLongInt();
1584 Y
:= M
.ReadLongInt();
1585 XV
:= M
.ReadLongInt();
1586 YV
:= M
.ReadLongInt();
1588 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1589 if (Shots
<> nil) and (I
<= High(Shots
)) then
1591 Shots
[I
].Timeout
:= Timeout
;
1592 //Shots[I].Target := Target; // TODO: find a use for Target later
1596 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1598 I
, TX
, TY
, TXV
, TYV
: Integer;
1600 I
:= M
.ReadLongInt();
1601 TX
:= M
.ReadLongInt();
1602 TY
:= M
.ReadLongInt();
1603 TXV
:= M
.ReadLongInt();
1604 TYV
:= M
.ReadLongInt();
1606 if (Shots
<> nil) and (I
<= High(Shots
)) then
1616 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1621 if not gGameOn
then Exit
;
1622 I
:= M
.ReadLongInt();
1623 L
:= (M
.ReadByte() <> 0);
1624 X
:= M
.ReadLongInt();
1625 Y
:= M
.ReadLongInt();
1627 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1630 procedure MC_RECV_GameStats(var M
: TMsg
);
1632 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1634 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1635 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1638 if gGameSettings
.GameMode
= GM_COOP
then
1640 gCoopMonstersKilled
:= M
.ReadWord();
1641 gCoopSecretsFound
:= M
.ReadWord();
1645 procedure MC_RECV_CoopStats(var M
: TMsg
);
1647 gTotalMonsters
:= M
.ReadLongInt();
1648 gSecretsCount
:= M
.ReadLongInt();
1649 gCoopTotalMonstersKilled
:= M
.ReadWord();
1650 gCoopTotalSecretsFound
:= M
.ReadWord();
1651 gCoopTotalMonsters
:= M
.ReadWord();
1652 gCoopTotalSecrets
:= M
.ReadWord();
1655 procedure MC_RECV_GameEvent(var M
: TMsg
);
1664 i1
, i2
: TStrings_Locale
;
1668 FillChar(EvHash
, Sizeof(EvHash
), 0);
1669 EvType
:= M
.ReadByte();
1670 EvNum
:= M
.ReadLongInt();
1671 EvStr
:= M
.ReadString();
1672 gLastMap
:= M
.ReadByte() <> 0;
1673 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1674 gStatsPressed
:= True;
1675 EvTime
:= M
.ReadLongWord();
1676 BHash
:= M
.ReadByte() <> 0;
1678 EvHash
:= M
.ReadMD5();
1686 g_Game_ClearLoading();
1687 g_Game_StopAllSounds(True);
1689 gSwitchGameMode
:= Byte(EvNum
);
1690 gGameSettings
.GameMode
:= gSwitchGameMode
;
1693 if not g_Game_StartMap(EvStr
, True) then
1695 if not isWadPath(EvStr
) then
1696 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1698 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1702 MC_SEND_FullStateRequest
;
1707 gMissionFailed
:= EvNum
<> 0;
1708 gExit
:= EXIT_ENDLEVELCUSTOM
;
1715 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1717 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1719 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1725 if EvNum
= TEAM_RED
then
1726 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1727 if EvNum
= TEAM_BLUE
then
1728 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1732 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1735 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1738 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1740 NET_EV_LMS_SURVIVOR
:
1741 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1744 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1748 pl
:= g_Player_Get(EvNum
and $FFFF);
1753 cnt
:= (EvNum
shr 16) and $FF;
1754 if Pos('w', EvStr
) = 0 then
1757 if Pos('t', EvStr
) = 0 then
1760 if Pos('-', EvStr
) = 0 then
1762 if Pos('e', EvStr
) = 0 then
1763 i1
:= I_PLAYER_SCORE_ADD_OWN
1765 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1768 if Pos('e', EvStr
) = 0 then
1769 i1
:= I_PLAYER_SCORE_SUB_OWN
1771 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1774 if Pos('r', EvStr
) > 0 then
1775 i2
:= I_PLAYER_SCORE_TO_RED
1777 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1778 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1782 if Pos('-', EvStr
) = 0 then
1783 i1
:= I_PLAYER_SCORE_ADD_TEAM
1785 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1787 if Pos('r', EvStr
) > 0 then
1788 i2
:= I_PLAYER_SCORE_RED
1790 i2
:= I_PLAYER_SCORE_BLUE
;
1791 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1796 if Pos('e', EvStr
) = 0 then
1797 i1
:= I_PLAYER_SCORE_WIN_OWN
1799 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1801 if Pos('r', EvStr
) > 0 then
1802 i2
:= I_PLAYER_SCORE_TO_RED
1804 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1805 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1811 if EvNum
= TEAM_RED
then
1812 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1813 if EvNum
= TEAM_BLUE
then
1814 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1815 if EvNum
= -TEAM_RED
then
1816 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1817 if EvNum
= -TEAM_BLUE
then
1818 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1823 g_Player_RemoveAllCorpses
;
1824 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1828 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1832 if EvNum
= TEAM_RED
then
1833 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1834 if EvNum
= TEAM_BLUE
then
1835 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1839 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1842 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1845 g_Game_Announce_KillCombo(EvNum
);
1847 NET_EV_PLAYER_TOUCH
:
1849 pl
:= g_Player_Get(EvNum
);
1856 pl
:= g_Player_Get(EvNum
);
1859 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
1860 g_Sound_PlayEx('SOUND_GAME_SECRET');
1866 pl
:= g_Player_Get(EvNum
);
1867 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
1872 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1881 EvType
:= M
.ReadByte();
1884 if Fl
= FLAG_NONE
then Exit
;
1886 Quiet
:= (M
.ReadByte() <> 0);
1887 PID
:= M
.ReadWord();
1889 gFlags
[Fl
].State
:= M
.ReadByte();
1890 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1891 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1892 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1893 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1894 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1896 Pl
:= g_Player_Get(PID
);
1898 (EvType
<> FLAG_STATE_NORMAL
) and
1899 (EvType
<> FLAG_STATE_DROPPED
) and
1900 (EvType
<> FLAG_STATE_RETURNED
) then
1906 if Quiet
or (Pl
= nil) then Exit
;
1908 if Fl
= FLAG_RED
then
1909 s
:= _lc
[I_PLAYER_FLAG_RED
]
1911 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1913 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1915 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1916 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1917 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1922 if not sound_ret_flag
[a
].IsPlaying() then
1923 sound_ret_flag
[a
].Play();
1926 FLAG_STATE_CAPTURED
:
1928 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1932 if Fl
= FLAG_RED
then
1933 s
:= _lc
[I_PLAYER_FLAG_RED
]
1935 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1937 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1938 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1940 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1941 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1942 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1947 if not sound_get_flag
[a
].IsPlaying() then
1948 sound_get_flag
[a
].Play();
1953 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1955 if Quiet
or (Pl
= nil) then Exit
;
1957 if Fl
= FLAG_RED
then
1958 s
:= _lc
[I_PLAYER_FLAG_RED
]
1960 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1962 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1963 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1965 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1966 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1967 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1972 if not sound_lost_flag
[a
].IsPlaying() then
1973 sound_lost_flag
[a
].Play();
1978 g_Map_ResetFlag(FLAG_RED
);
1979 g_Map_ResetFlag(FLAG_BLUE
);
1980 if Quiet
or (Pl
= nil) then Exit
;
1981 Pl
.SetFlag(FLAG_NONE
);
1983 if Fl
= FLAG_RED
then
1984 s
:= _lc
[I_PLAYER_FLAG_RED
]
1986 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1988 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1989 Insert('.', ts
, Length(ts
) + 1 - 3);
1990 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1991 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1993 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1994 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1995 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2000 if not sound_cap_flag
[a
].IsPlaying() then
2001 sound_cap_flag
[a
].Play();
2004 FLAG_STATE_RETURNED
:
2006 g_Map_ResetFlag(Fl
);
2009 if Fl
= FLAG_RED
then
2010 s
:= _lc
[I_PLAYER_FLAG_RED
]
2012 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2014 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2016 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2017 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2018 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2023 if not sound_ret_flag
[a
].IsPlaying() then
2024 sound_ret_flag
[a
].Play();
2029 procedure MC_RECV_GameSettings(var M
: TMsg
);
2031 gGameSettings
.GameMode
:= M
.ReadByte();
2032 gGameSettings
.GoalLimit
:= M
.ReadWord();
2033 gGameSettings
.TimeLimit
:= M
.ReadWord();
2034 gGameSettings
.MaxLives
:= M
.ReadByte();
2035 gGameSettings
.Options
:= M
.ReadLongWord();
2040 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2043 PName
, Model
: string;
2048 PID
:= M
.ReadWord();
2049 Pl
:= g_Player_Get(PID
);
2051 PName
:= M
.ReadString();
2052 Model
:= M
.ReadString();
2053 Color
.R
:= M
.ReadByte();
2054 Color
.G
:= M
.ReadByte();
2055 Color
.B
:= M
.ReadByte();
2059 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2061 if (Pl
<> nil) then Exit
;
2062 DID
:= g_Player_Create(Model
, Color
, T
, False);
2063 with g_Player_Get(DID
) do
2072 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2073 gPlayer1
.UID
:= PID
;
2074 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2075 gPlayer1
.ChangeTeam(T
);
2077 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2078 gPlayer2
.UID
:= PID
;
2079 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2080 gPlayer2
.ChangeTeam(T
);
2084 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2085 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2089 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2096 TmpX
, TmpY
: Integer;
2100 GT
:= M
.ReadLongWord();
2101 if GT
< gTime
- NET_MAX_DIFFTIME
then
2108 PID
:= M
.ReadWord();
2109 Pl
:= g_Player_Get(PID
);
2111 if Pl
= nil then Exit
;
2117 FPing
:= M
.ReadWord();
2118 FLoss
:= M
.ReadByte();
2119 kByte
:= M
.ReadWord();
2120 Dir
:= M
.ReadByte();
2122 TmpX
:= M
.ReadLongInt();
2123 TmpY
:= M
.ReadLongInt();
2127 if (kByte
= NET_KEY_CHAT
) then
2128 PressKey(KEY_CHAT
, 10000)
2131 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2132 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2133 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2134 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2135 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2138 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2139 SetDirection(TDirection(Dir
));
2141 GameVelX
:= M
.ReadLongInt();
2142 GameVelY
:= M
.ReadLongInt();
2143 GameAccelX
:= M
.ReadLongInt();
2144 GameAccelY
:= M
.ReadLongInt();
2145 SetLerp(TmpX
, TmpY
);
2146 if NetForcePlayerUpdate
then Update();
2150 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2154 I
, OldFire
: Integer;
2155 OldJet
, Flam
: Boolean;
2158 PID
:= M
.ReadWord();
2159 Pl
:= g_Player_Get(PID
);
2166 alive
:= (M
.ReadByte() <> 0);
2167 GodMode
:= (M
.ReadByte() <> 0);
2168 Health
:= M
.ReadLongInt();
2169 Armor
:= M
.ReadLongInt();
2170 Air
:= M
.ReadLongInt();
2171 JetFuel
:= M
.ReadLongInt();
2172 Lives
:= M
.ReadByte();
2173 NewTeam
:= M
.ReadByte();
2175 for I
:= WP_FIRST
to WP_LAST
do
2176 FWeapon
[I
] := (M
.ReadByte() <> 0);
2178 for I
:= A_BULLETS
to A_HIGH
do
2179 FAmmo
[I
] := M
.ReadWord();
2181 for I
:= A_BULLETS
to A_HIGH
do
2182 FMaxAmmo
[I
] := M
.ReadWord();
2184 for I
:= MR_SUIT
to MR_MAX
do
2185 FMegaRulez
[I
] := M
.ReadLongWord();
2188 if (M
.ReadByte() <> 0) then
2189 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2190 if (M
.ReadByte() <> 0) then
2191 FRulez
:= FRulez
+ [R_KEY_RED
];
2192 if (M
.ReadByte() <> 0) then
2193 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2194 if (M
.ReadByte() <> 0) then
2195 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2196 if (M
.ReadByte() <> 0) then
2197 FRulez
:= FRulez
+ [R_BERSERK
];
2199 Frags
:= M
.ReadLongInt();
2200 Death
:= M
.ReadLongInt();
2202 SetWeapon(M
.ReadByte());
2204 FSpectator
:= M
.ReadByte() <> 0;
2207 if Pl
= gPlayer1
then
2212 if Pl
= gPlayer2
then
2220 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2221 gPlayer1
:= g_Player_Get(gLMSPID1
);
2222 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2223 gPlayer2
:= g_Player_Get(gLMSPID2
);
2225 FGhost
:= M
.ReadByte() <> 0;
2226 FPhysics
:= M
.ReadByte() <> 0;
2227 FNoRespawn
:= M
.ReadByte() <> 0;
2229 FJetpack
:= M
.ReadByte() <> 0;
2230 OldFire
:= FFireTime
;
2231 FFireTime
:= M
.ReadLongInt();
2232 if (OldFire
<= 0) and (FFireTime
> 0) then
2233 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2234 Flam
:= M
.ReadByte() <> 0;
2235 if OldJet
and not FJetpack
then
2237 else if not OldJet
and FJetpack
then
2239 if FFlaming
and not Flam
then
2241 if Team
<> NewTeam
then
2242 Pl
.ChangeTeam(NewTeam
);
2248 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2253 Attacker
, Value
: Word;
2257 if not gGameOn
then Exit
;
2258 PID
:= M
.ReadWord();
2259 Pl
:= g_Player_Get(PID
);
2260 if Pl
= nil then Exit
;
2262 Kind
:= M
.ReadByte();
2263 Attacker
:= M
.ReadWord();
2264 Value
:= M
.ReadWord();
2269 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2274 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2278 KillType
, DeathType
: Byte;
2282 if not gGameOn
then Exit
;
2283 PID
:= M
.ReadWord();
2284 Pl
:= g_Player_Get(PID
);
2285 if Pl
= nil then Exit
;
2287 KillType
:= M
.ReadByte();
2288 DeathType
:= M
.ReadByte();
2289 Attacker
:= M
.ReadWord();
2293 Kill(KillType
, Attacker
, DeathType
);
2298 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2303 PID
:= M
.ReadWord();
2304 Pl
:= g_Player_Get(PID
);
2306 if Pl
= nil then Exit
;
2308 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2309 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2311 g_Player_Remove(PID
);
2316 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2321 X
, Y
, AX
, AY
: Integer;
2325 if not gGameOn
then Exit
;
2326 PID
:= M
.ReadWord();
2327 Pl
:= g_Player_Get(PID
);
2328 if Pl
= nil then Exit
;
2330 Weap
:= M
.ReadByte();
2331 X
:= M
.ReadLongInt();
2332 Y
:= M
.ReadLongInt();
2333 AX
:= M
.ReadLongInt();
2334 AY
:= M
.ReadLongInt();
2335 SHID
:= M
.ReadLongInt();
2338 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2341 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2350 PID
:= M
.ReadWord();
2351 Pl
:= g_Player_Get(PID
);
2352 if Pl
= nil then Exit
;
2354 TmpName
:= M
.ReadString();
2355 TmpModel
:= M
.ReadString();
2356 TmpColor
.R
:= M
.ReadByte();
2357 TmpColor
.G
:= M
.ReadByte();
2358 TmpColor
.B
:= M
.ReadByte();
2359 TmpTeam
:= M
.ReadByte();
2361 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2363 Pl
.ChangeTeam(TmpTeam
);
2364 if gPlayer1
= Pl
then
2365 gPlayer1Settings
.Team
:= TmpTeam
;
2366 if gPlayer2
= Pl
then
2367 gPlayer2Settings
.Team
:= TmpTeam
;
2369 Pl
.SetColor(TmpColor
);
2371 if Pl
.Name
<> TmpName
then
2373 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2377 if TmpModel
<> Pl
.Model
.Name
then
2378 Pl
.SetModel(TmpModel
);
2383 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2387 X
, Y
, VX
, VY
: Integer;
2389 Quiet
, Fall
{, Resp}: Boolean;
2393 if not gGameOn
then Exit
;
2395 Quiet
:= M
.ReadByte() <> 0;
2397 Fall
:= M
.ReadByte() <> 0;
2398 {Resp :=} M
.ReadByte();
2399 X
:= M
.ReadLongInt();
2400 Y
:= M
.ReadLongInt();
2401 VX
:= M
.ReadLongInt();
2402 VY
:= M
.ReadLongInt();
2404 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2405 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2407 it
:= g_Items_ByIdx(ID
);
2413 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2414 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2416 Anim
:= TAnimation
.Create(AID
, False, 4);
2417 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2423 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2428 if not gGameOn
then Exit
;
2430 Quiet
:= M
.ReadByte() <> 0;
2432 if not g_Items_ValidId(ID
) then exit
;
2434 if not Quiet
then g_Items_EmitPickupSound(ID
);
2441 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2448 if not gGameOn
then Exit
;
2450 PGUID
:= Integer(M
.ReadLongWord());
2451 Tex
:= M
.ReadLongInt();
2452 Fr
:= M
.ReadLongInt();
2453 Cnt
:= M
.ReadByte();
2454 Loop
:= M
.ReadByte();
2456 TP
:= g_Map_PanelByGUID(PGUID
);
2460 TP
.SetTexture(Tex
, Loop
);
2461 TP
.SetFrame(Fr
, Cnt
);
2465 procedure MC_RECV_PanelState(var M
: TMsg
);
2470 X
, Y
, W
, H
: Integer;
2472 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2473 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2476 if not gGameOn
then Exit
;
2478 PGUID
:= Integer(M
.ReadLongWord());
2479 E
:= (M
.ReadByte() <> 0);
2480 Lift
:= M
.ReadByte();
2481 X
:= M
.ReadLongInt();
2482 Y
:= M
.ReadLongInt();
2486 speedX
:= M
.ReadLongInt();
2487 speedY
:= M
.ReadLongInt();
2488 startX
:= M
.ReadLongInt();
2489 startY
:= M
.ReadLongInt();
2490 endX
:= M
.ReadLongInt();
2491 endY
:= M
.ReadLongInt();
2492 sizeSpX
:= M
.ReadLongInt();
2493 sizeSpY
:= M
.ReadLongInt();
2494 sizeEX
:= M
.ReadLongInt();
2495 sizeEY
:= M
.ReadLongInt();
2496 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2498 TP
:= g_Map_PanelByGUID(PGUID
);
2499 if (TP
= nil) then exit
;
2501 // update lifts state
2502 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2504 // update enabled/disabled state for all panels
2505 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2507 // update panel position, as it can be moved (mplat)
2512 // update mplat state
2513 TP
.movingSpeedX
:= speedX
;
2514 TP
.movingSpeedY
:= speedY
;
2515 TP
.movingStartX
:= startX
;
2516 TP
.movingStartY
:= startY
;
2517 TP
.movingEndX
:= endX
;
2518 TP
.movingEndY
:= endY
;
2519 TP
.sizeSpeedX
:= sizeSpX
;
2520 TP
.sizeSpeedY
:= sizeSpY
;
2521 TP
.sizeEndX
:= sizeEX
;
2522 TP
.sizeEndY
:= sizeEY
;
2523 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2524 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2525 // notify panel of it's position/size change, so it can fix other internal structures
2526 TP
.positionChanged();
2531 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2534 SPos
, SID
: LongWord;
2538 if not gGameOn
then Exit
;
2539 if gTriggers
= nil then Exit
;
2541 SID
:= M
.ReadLongWord();
2542 SPlaying
:= M
.ReadByte() <> 0;
2543 SPos
:= M
.ReadLongWord();
2544 SCount
:= M
.ReadLongInt();
2546 for I
:= Low(gTriggers
) to High(gTriggers
) do
2547 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2548 if gTriggers
[I
].ClientID
= SID
then
2549 with gTriggers
[I
] do
2551 if Sound
<> nil then
2556 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2558 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2559 Sound
.SetPosition(SPos
);
2562 if Sound
.IsPlaying
then Sound
.Stop
;
2565 SoundPlayCount
:= SCount
;
2569 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2576 if not gGameOn
then Exit
;
2578 MName
:= M
.ReadString();
2579 MPlaying
:= M
.ReadByte() <> 0;
2580 MPos
:= M
.ReadLongWord();
2581 MPaused
:= M
.ReadByte() <> 0;
2585 gMusic
.SetByName(MName
);
2587 // gMusic.SetPosition(MPos);
2588 gMusic
.SpecPause
:= MPaused
;
2591 if gMusic
.IsPlaying
then gMusic
.Stop
;
2596 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2599 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2600 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2605 Mon
:= g_Monsters_ByUID(ID
);
2609 MType
:= M
.ReadByte();
2610 MState
:= M
.ReadByte();
2611 MAnim
:= M
.ReadByte();
2612 MTarg
:= M
.ReadWord();
2613 MTargTime
:= M
.ReadLongInt();
2614 MBehav
:= M
.ReadByte();
2615 MSleep
:= M
.ReadLongInt();
2616 MHealth
:= M
.ReadLongInt();
2617 MAmmo
:= M
.ReadLongInt();
2619 X
:= M
.ReadLongInt();
2620 Y
:= M
.ReadLongInt();
2621 VX
:= M
.ReadLongInt();
2622 VY
:= M
.ReadLongInt();
2623 MDir
:= M
.ReadByte();
2625 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2626 Mon
:= g_Monsters_ByUID(ID
);
2633 MonsterAnim
:= MAnim
;
2634 MonsterTargetUID
:= MTarg
;
2635 MonsterTargetTime
:= MTargTime
;
2636 MonsterBehaviour
:= MBehav
;
2637 MonsterSleep
:= MSleep
;
2638 MonsterAmmo
:= MAmmo
;
2643 setPosition(X
, Y
); // this will call positionChanged();
2649 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2656 Mon
:= g_Monsters_ByUID(ID
);
2662 X
:= M
.ReadLongInt();
2663 Y
:= M
.ReadLongInt();
2664 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2665 GameVelX
:= M
.ReadLongInt();
2666 GameVelY
:= M
.ReadLongInt();
2667 GameDirection
:= TDirection(M
.ReadByte());
2671 procedure MC_RECV_MonsterState(var M
: TMsg
);
2673 ID
, OldFire
: Integer;
2674 MState
, MFAnm
: Byte;
2676 AnimRevert
: Boolean;
2679 Mon
:= g_Monsters_ByUID(ID
);
2680 if Mon
= nil then Exit
;
2682 MState
:= M
.ReadByte();
2683 MFAnm
:= M
.ReadByte();
2687 MonsterTargetUID
:= M
.ReadWord();
2688 MonsterTargetTime
:= M
.ReadLongInt();
2689 MonsterSleep
:= M
.ReadLongInt();
2690 MonsterHealth
:= M
.ReadLongInt();
2691 MonsterAmmo
:= M
.ReadLongInt();
2692 MonsterPain
:= M
.ReadLongInt();
2693 AnimRevert
:= M
.ReadByte() <> 0;
2694 OldFire
:= FFireTime
;
2695 FFireTime
:= M
.ReadLongInt();
2696 if (OldFire
<= 0) and (FFireTime
> 0) then
2697 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2698 RevertAnim(AnimRevert
);
2700 if MonsterState
<> MState
then
2702 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2703 if (MState
= MONSTATE_DIE
) then DieSound();
2704 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2705 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2706 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2708 SetState(MState
, MFAnm
);
2713 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2717 X
, Y
, VX
, VY
: Integer;
2721 Mon
:= g_Monsters_ByUID(ID
);
2722 if Mon
= nil then Exit
;
2724 X
:= M
.ReadLongInt();
2725 Y
:= M
.ReadLongInt();
2726 VX
:= M
.ReadLongInt();
2727 VY
:= M
.ReadLongInt();
2729 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2732 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2738 Mon
:= g_Monsters_ByUID(ID
);
2739 if Mon
= nil then Exit
;
2741 Mon
.MonsterRemoved
:= True;
2744 procedure MC_RECV_TimeSync(var M
: TMsg
);
2748 Time
:= M
.ReadLongWord();
2750 if gState
= STATE_INTERCUSTOM
then
2751 gServInterTime
:= Min(Time
, 255);
2754 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2758 Int1
, Int2
: SmallInt;
2760 EvID
:= M
.ReadByte();
2761 Int1
:= M
.ReadSmallInt();
2762 Int2
:= M
.ReadSmallInt();
2763 Str1
:= M
.ReadString();
2764 Str2
:= M
.ReadString();
2768 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2770 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2772 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2774 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2776 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2782 procedure MC_SEND_Info(Password
: string);
2786 NetOut
.Write(Byte(NET_MSG_INFO
));
2787 NetOut
.Write(GAME_VERSION
);
2788 NetOut
.Write(Password
);
2789 NetOut
.Write(gPlayer1Settings
.Name
);
2790 NetOut
.Write(gPlayer1Settings
.Model
);
2791 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2792 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2793 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2794 NetOut
.Write(gPlayer1Settings
.Team
);
2796 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2799 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2801 NetOut
.Write(Byte(NET_MSG_CHAT
));
2805 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2808 procedure MC_SEND_PlayerPos();
2813 WeaponSelect
: Word = 0;
2816 if not gGameOn
then Exit
;
2817 if gPlayers
= nil then Exit
;
2818 if gPlayer1
= nil then Exit
;
2821 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2823 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2825 strafeDir
:= P1MoveButton
shr 4;
2826 P1MoveButton
:= P1MoveButton
and $0F;
2828 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2830 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2832 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2836 if gPlayerAction
[0, ACTION_STRAFE
] then
2838 // new strafe mechanics
2839 if (strafeDir
= 0) then
2840 strafeDir
:= P1MoveButton
; // start strafing
2841 // now set direction according to strafe (reversed)
2842 if (strafeDir
= 2) then
2843 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2844 else if (strafeDir
= 1) then
2845 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2849 strafeDir
:= 0; // not strafing anymore
2850 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
2851 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2852 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2853 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2854 else if P1MoveButton
<> 0 then
2855 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2858 gPlayer1
.ReleaseKeys
;
2859 if P1MoveButton
= 1 then
2861 kByte
:= kByte
or NET_KEY_LEFT
;
2862 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2864 if P1MoveButton
= 2 then
2866 kByte
:= kByte
or NET_KEY_RIGHT
;
2867 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2869 if gPlayerAction
[0, ACTION_LOOKUP
] then
2871 kByte
:= kByte
or NET_KEY_UP
;
2872 gPlayer1
.PressKey(KEY_UP
, 10000);
2874 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2876 kByte
:= kByte
or NET_KEY_DOWN
;
2877 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2879 if gPlayerAction
[0, ACTION_JUMP
] then
2881 kByte
:= kByte
or NET_KEY_JUMP
;
2882 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2884 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
2885 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
2886 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
2887 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
2889 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2890 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2892 for i
:= WP_FIRST
to WP_LAST
do
2894 if gSelectWeapon
[0, i
] then
2896 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
2897 gSelectWeapon
[0, i
] := False
2901 // fix movebutton state
2902 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2905 kByte
:= NET_KEY_CHAT
;
2907 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2908 NetOut
.Write(gTime
);
2909 NetOut
.Write(kByte
);
2910 NetOut
.Write(Byte(gPlayer1
.Direction
));
2911 NetOut
.Write(WeaponSelect
);
2912 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2913 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2915 //kBytePrev := kByte;
2916 //kDirPrev := gPlayer1.Direction;
2919 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2921 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2922 NetOut
.Write(Byte(Start
));
2923 NetOut
.Write(Command
);
2924 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2927 procedure MC_SEND_PlayerSettings();
2929 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2930 NetOut
.Write(gPlayer1Settings
.Name
);
2931 NetOut
.Write(gPlayer1Settings
.Model
);
2932 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2933 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2934 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2935 NetOut
.Write(gPlayer1Settings
.Team
);
2937 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2940 procedure MC_SEND_FullStateRequest();
2942 NetOut
.Write(Byte(NET_MSG_REQFST
));
2944 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2947 procedure MC_SEND_CheatRequest(Kind
: Byte);
2949 NetOut
.Write(Byte(NET_MSG_CHEAT
));
2952 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2954 procedure MC_SEND_RCONPassword(Password
: string);
2956 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
2957 NetOut
.Write(Password
);
2959 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2961 procedure MC_SEND_RCONCommand(Cmd
: string);
2963 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
2966 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2969 // i have no idea why all this stuff is in here
2971 function ReadFile(const FileName
: TFileName
): AByte
;
2973 FileStream
: TStream
;
2976 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), TMsgType
.Notify
);
2977 fname
:= findDiskWad(FileName
);
2978 if length(fname
) = 0 then
2980 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), TMsgType
.Fatal
);
2981 SetLength(Result
, 0);
2984 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), TMsgType
.Notify
);
2986 FileStream
:= openDiskFileRO(fname
);
2988 if FileStream
.Size
> 0 then
2990 SetLength(Result
, FileStream
.Size
);
2991 FileStream
.Read(Result
[0], FileStream
.Size
);
2998 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
3002 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
3003 Result
.FileData
:= ReadFile(FileName
);
3004 Result
.FileSize
:= Length(Result
.FileData
);
3006 SetLength(Result
.ExternalResources
, ResList
.Count
);
3007 for i
:=0 to ResList
.Count
-1 do
3009 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
3010 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
3014 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
3016 ResultStream
: TMemoryStream
;
3018 ResultStream
:= TMemoryStream
.Create
;
3020 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
3021 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
3022 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
3024 SetLength(bytes
, ResultStream
.Size
);
3025 ResultStream
.Seek(0, soFromBeginning
);
3026 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3031 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
3033 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3034 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
3035 SetLength(Result
.FileData
, Result
.FileSize
);
3036 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
3039 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
3041 ResultStream
: TMemoryStream
;
3044 resCount
:= Length(MapDataMsg
.ExternalResources
);
3046 ResultStream
:= TMemoryStream
.Create
;
3048 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
3049 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
3050 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
3052 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
3053 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
3055 SetLength(bytes
, ResultStream
.Size
);
3056 ResultStream
.Seek(0, soFromBeginning
);
3057 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3062 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
3066 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3067 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3069 SetLength(Result
.FileData
, Result
.FileSize
);
3070 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3072 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3073 SetLength(Result
.ExternalResources
, resCount
);
3075 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3078 function IsValidFileName(const S
: String): Boolean;
3080 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3085 for I
:= 1 to Length(S
) do
3086 Result
:= Result
and (not(S
[I
] in Forbidden
));
3089 function IsValidFilePath(const S
: String): Boolean;
3094 if not IsValidFileName(S
) then exit
;
3095 if FileExists(S
) then exit
;
3096 I
:= LastDelimiter('\/', S
);
3098 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3103 procedure MC_SEND_MapRequest();
3105 NetOut
.Write(Byte(NET_MSG_MAP_REQUEST
));
3106 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3109 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3111 NetOut
.Write(Byte(NET_MSG_RES_REQUEST
));
3112 NetOut
.Write(resName
);
3113 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3116 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
3120 mapDataMsg
: TMapDataMsg
;
3122 e_WriteLog('NET: Received map request from ' +
3123 DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3125 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3126 peer
:= NetClients
[C
^.ID
].Peer
;
3128 MapDataMsgToBytes(payload
, mapDataMsg
);
3129 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3132 mapDataMsg
.FileData
:= nil;
3133 mapDataMsg
.ExternalResources
:= nil;
3136 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
3141 resDataMsg
: TResDataMsg
;
3143 FileName
:= ExtractFileName(M
.ReadString());
3144 e_WriteLog('NET: Received res request: ' + FileName
+
3145 ' from ' + DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3147 if not IsValidFilePath(FileName
) then
3149 e_WriteLog('Invalid filename: ' + FileName
, TMsgType
.Warning
);
3153 peer
:= NetClients
[C
^.ID
].Peer
;
3155 if gExternalResources
.IndexOf(FileName
) > -1 then
3157 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3158 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3159 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3161 ResDataMsgToBytes(payload
, resDataMsg
);
3162 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);