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;
118 NET_VE_INPROGRESS
= 6;
125 NET_CHEAT_SUICIDE
= 1;
126 NET_CHEAT_SPECTATE
= 2;
128 NET_MAX_DIFFTIME
= 5000 div 36;
132 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
133 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
134 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
135 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
136 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
137 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
138 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
139 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
140 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
141 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
142 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
146 procedure MH_SEND_Info(ID
: Byte);
147 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
148 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
149 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
150 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
151 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
152 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
153 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
154 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_VoteEvent(EvType
: Byte;
185 StrArg1
: string = 'a'; StrArg2
: string = 'b';
186 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
187 ID
: Integer = NET_EVERYONE
);
189 // CLIENT MESSAGES //
192 procedure MC_RECV_Chat(var M
: TMsg
);
193 procedure MC_RECV_Effect(var M
: TMsg
);
194 procedure MC_RECV_Sound(var M
: TMsg
);
195 procedure MC_RECV_GameStats(var M
: TMsg
);
196 procedure MC_RECV_CoopStats(var M
: TMsg
);
197 procedure MC_RECV_GameEvent(var M
: TMsg
);
198 procedure MC_RECV_FlagEvent(var M
: TMsg
);
199 procedure MC_RECV_GameSettings(var M
: TMsg
);
201 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
202 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
203 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
204 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
205 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
206 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
207 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
208 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
210 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
211 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
213 procedure MC_RECV_PanelTexture(var M
: TMsg
);
214 procedure MC_RECV_PanelState(var M
: TMsg
);
216 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
217 procedure MC_RECV_MonsterPos(var M
: TMsg
);
218 procedure MC_RECV_MonsterState(var M
: TMsg
);
219 procedure MC_RECV_MonsterShot(var M
: TMsg
);
220 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
222 procedure MC_RECV_CreateShot(var M
: TMsg
);
223 procedure MC_RECV_UpdateShot(var M
: TMsg
);
224 procedure MC_RECV_DeleteShot(var M
: TMsg
);
226 procedure MC_RECV_TriggerSound(var M
: TMsg
);
227 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
229 procedure MC_RECV_TimeSync(var M
: TMsg
);
230 procedure MC_RECV_VoteEvent(var M
: TMsg
);
232 procedure MC_SEND_Info(Password
: string);
233 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
234 procedure MC_SEND_PlayerPos();
235 procedure MC_SEND_FullStateRequest();
236 procedure MC_SEND_PlayerSettings();
237 procedure MC_SEND_CheatRequest(Kind
: Byte);
238 procedure MC_SEND_RCONPassword(Password
: string);
239 procedure MC_SEND_RCONCommand(Cmd
: string);
240 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
242 procedure MC_SEND_MapRequest();
243 procedure MC_SEND_ResRequest(const resName
: AnsiString);
246 TExternalResourceInfo
= record
261 ExternalResources
: array of TExternalResourceInfo
;
264 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
265 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
270 Math
, ENet
, e_input
, e_graphics
, e_log
,
271 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
272 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
273 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
286 NET_KEY_FORCEDIR
= 4096;
289 //kBytePrev: Word = 0;
290 //kDirPrev: TDirection = D_LEFT;
291 //HostGameTime: Word = 0;
298 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
306 Pl
:= g_Player_Get(PID
);
308 Txt
:= M
.ReadString();
309 Mode
:= M
.ReadByte();
310 if (Mode
= NET_CHAT_SYSTEM
) then
311 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
312 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
313 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
316 MH_SEND_Chat(Txt
, Mode
)
318 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
321 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
323 Ver
, PName
, Model
, Pw
: string;
329 Ver
:= M
.ReadString();
330 Pw
:= M
.ReadString();
331 PName
:= M
.ReadString();
332 Model
:= M
.ReadString();
338 if Ver
<> GAME_VERSION
then
340 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
341 _lc
[I_NET_DISC_VERSION
]);
342 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
346 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
348 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
350 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
351 _lc
[I_NET_DISC_BAN
]);
352 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
356 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
357 _lc
[I_NET_DISC_BAN
]);
358 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
363 if NetPassword
<> '' then
364 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
366 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
367 _lc
[I_NET_DISC_PASSWORD
]);
368 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
376 PID
:= g_Player_Create(Model
, Color
, T
, False);
377 with g_Player_Get(PID
) do
385 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
386 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
387 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
391 with g_Player_Get(PID
) do
395 // round in progress, don't spawn
396 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
401 FWantsInGame
:= True; // TODO: look into this later
404 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
407 for I
:= Low(NetClients
) to High(NetClients
) do
409 if NetClients
[I
].ID
= C
^.ID
then Continue
;
410 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
411 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
412 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
415 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
416 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
418 if NetUseMaster
then g_Net_Slist_Update
;
421 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
424 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
426 C
^.RequestedFullUpdate
:= True;
431 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
441 if not gGameOn
then Exit
;
443 GT
:= M
.ReadLongWord();
445 Pl
:= g_Player_Get(PID
);
449 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
454 kByte
:= M
.ReadWord();
456 WeaponSelect
:= M
.ReadWord();
457 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
458 if Direction
<> TDirection(Dir
) then
459 JustTeleported
:= False;
461 SetDirection(TDirection(Dir
));
464 if kByte
= NET_KEY_CHAT
then
466 PressKey(KEY_CHAT
, 10000);
470 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
471 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
472 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
473 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
474 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
475 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
476 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
477 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
478 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
482 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
484 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
485 QueueWeaponSwitch(i
);
490 // MH_SEND_PlayerPos(False, PID, C^.ID);
493 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
498 Pl
:= g_Player_Get(C
^.Player
);
499 if Pl
= nil then Exit
;
501 CheatKind
:= M
.ReadByte();
505 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
508 if Pl
.FSpectator
then
516 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
524 TmpName
:= M
.ReadString();
525 TmpModel
:= M
.ReadString();
526 TmpColor
.R
:= M
.ReadByte();
527 TmpColor
.G
:= M
.ReadByte();
528 TmpColor
.B
:= M
.ReadByte();
529 TmpTeam
:= M
.ReadByte();
531 Pl
:= g_Player_Get(C
^.Player
);
532 if Pl
= nil then Exit
;
534 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
537 Pl
.SetColor(TmpColor
);
539 if Pl
.Name
<> TmpName
then
541 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
545 if TmpModel
<> Pl
.Model
.Name
then
546 Pl
.SetModel(TmpModel
);
548 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
553 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
557 Pwd
:= M
.ReadString();
558 if not NetAllowRCON
then Exit
;
559 if Pwd
= NetRCONPassword
then
562 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
565 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
568 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
572 Cmd
:= M
.ReadString();
573 if not NetAllowRCON
then Exit
;
574 if not C
^.RCONAuth
then
576 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
579 g_Console_Process(Cmd
);
584 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
587 Name
, Command
: string;
591 Start
:= M
.ReadByte() <> 0;
592 Command
:= M
.ReadString();
594 Pl
:= g_Player_Get(C
^.Player
);
595 if Pl
= nil then Exit
;
600 if not g_Console_CommandBlacklisted(Command
) then
601 g_Game_StartVote(Command
, Name
);
603 else if gVoteInProgress
then
605 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
606 Need
:= Floor((NetClientCount
+1)/2.0) + 1
608 Need
:= Floor(NetClientCount
/2.0) + 1;
613 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
614 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
620 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
621 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
629 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
631 function sendItemRespawn (it
: PItem
): Boolean;
633 result
:= false; // don't stop
634 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
637 function sendMonSpawn (mon
: TMonster
): Boolean;
639 result
:= false; // don't stop
640 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
643 function sendPanelState (pan
: TPanel
): Boolean;
645 result
:= false; // don't stop
646 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
647 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
653 if gPlayers
<> nil then
655 for I
:= Low(gPlayers
) to High(gPlayers
) do
657 if gPlayers
[I
] <> nil then
659 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
660 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
661 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
663 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
665 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
671 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
672 g_Mons_ForEach(sendMonSpawn
);
673 g_Map_ForEachPanel(sendPanelState
);
675 if gTriggers
<> nil then
677 for I
:= Low(gTriggers
) to High(gTriggers
) do
679 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
681 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
688 for I
:= Low(Shots
) to High(Shots
) do
690 if Shots
[i
].ShotType
in [6, 7, 8] then
692 MH_SEND_CreateShot(i
, ID
);
697 MH_SEND_TriggerMusic(ID
);
699 MH_SEND_GameStats(ID
);
700 MH_SEND_CoopStats(ID
);
702 if gGameSettings
.GameMode
= GM_CTF
then
704 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
705 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
708 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
710 if gLMSRespawn
> LMS_RESPAWN_NONE
then
712 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
716 procedure MH_SEND_Info(ID
: Byte);
720 Map
:= g_ExtractFileName(gMapInfo
.Map
);
724 NetOut
.Write(Byte(NET_MSG_INFO
));
726 NetOut
.Write(NetClients
[ID
].Player
);
727 NetOut
.Write(gGameSettings
.WAD
);
729 NetOut
.Write(gWADHash
);
730 NetOut
.Write(gGameSettings
.GameMode
);
731 NetOut
.Write(gGameSettings
.GoalLimit
);
732 NetOut
.Write(gGameSettings
.TimeLimit
);
733 NetOut
.Write(gGameSettings
.MaxLives
);
734 NetOut
.Write(gGameSettings
.Options
);
737 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
740 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
746 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
747 Mode
:= NET_CHAT_PLAYER
;
750 if (Mode
= NET_CHAT_TEAM
) then
752 for i
:= Low(gPlayers
) to High(gPlayers
) do
753 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
754 (gPlayers
[i
].Team
= ID
) then
756 NetOut
.Write(Byte(NET_MSG_CHAT
));
759 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
766 NetOut
.Write(Byte(NET_MSG_CHAT
));
769 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
772 if Mode
= NET_CHAT_SYSTEM
then
775 if ID
= NET_EVERYONE
then
777 if Mode
= NET_CHAT_PLAYER
then
779 g_Console_Add(Txt
, True);
780 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
781 g_Game_ChatSound(b_Text_Unformat(Txt
));
784 if Mode
= NET_CHAT_TEAM
then
785 if gPlayer1
<> nil then
787 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
789 g_Console_Add(#18'[Team] '#2 + Txt
, True);
790 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
791 g_Game_ChatSound(b_Text_Unformat(Txt
));
793 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
795 g_Console_Add(#20'[Team] '#2 + Txt
, True);
796 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
797 g_Game_ChatSound(b_Text_Unformat(Txt
));
803 Name
:= g_Net_ClientName_ByID(ID
);
804 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
805 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
806 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
810 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
812 NetOut
.Write(Byte(NET_MSG_GFX
));
818 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
821 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
823 NetOut
.Write(Byte(NET_MSG_SND
));
827 NetOut
.Write(Byte(1));
832 NetOut
.Write(Byte(0));
834 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
837 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
839 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
841 NetOut
.Write(Byte(NET_MSG_SHADD
));
843 NetOut
.Write(Shots
[Proj
].ShotType
);
844 NetOut
.Write(Shots
[Proj
].Target
);
845 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
846 NetOut
.Write(Shots
[Proj
].Timeout
);
847 NetOut
.Write(Shots
[Proj
].Obj
.X
);
848 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
849 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
850 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
852 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
855 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
857 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
859 NetOut
.Write(Byte(NET_MSG_SHPOS
));
861 NetOut
.Write(Shots
[Proj
].Obj
.X
);
862 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
863 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
864 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
866 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
869 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
871 NetOut
.Write(Byte(NET_MSG_SHDEL
));
873 NetOut
.Write(Byte(Loud
));
877 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
880 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
882 NetOut
.Write(Byte(NET_MSG_SCORE
));
883 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
885 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
886 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
889 if gGameSettings
.GameMode
= GM_COOP
then
891 NetOut
.Write(gCoopMonstersKilled
);
892 NetOut
.Write(gCoopSecretsFound
);
895 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
898 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
900 NetOut
.Write(Byte(NET_MSG_COOP
));
901 NetOut
.Write(gTotalMonsters
);
902 NetOut
.Write(gSecretsCount
);
903 NetOut
.Write(gCoopTotalMonstersKilled
);
904 NetOut
.Write(gCoopTotalSecretsFound
);
905 NetOut
.Write(gCoopTotalMonsters
);
906 NetOut
.Write(gCoopTotalSecrets
);
909 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
911 NetOut
.Write(Byte(NET_MSG_GEVENT
));
912 NetOut
.Write(EvType
);
915 NetOut
.Write(Byte(gLastMap
));
917 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
919 NetOut
.Write(Byte(1));
920 NetOut
.Write(gWADHash
);
922 NetOut
.Write(Byte(0));
924 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
927 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
929 NetOut
.Write(Byte(NET_MSG_FLAG
));
930 NetOut
.Write(EvType
);
932 NetOut
.Write(Byte(Quiet
));
934 NetOut
.Write(gFlags
[Flag
].State
);
935 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
936 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
937 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
938 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
939 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
941 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
944 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
946 NetOut
.Write(Byte(NET_MSG_GSET
));
947 NetOut
.Write(gGameSettings
.GameMode
);
948 NetOut
.Write(gGameSettings
.GoalLimit
);
949 NetOut
.Write(gGameSettings
.TimeLimit
);
950 NetOut
.Write(gGameSettings
.MaxLives
);
951 NetOut
.Write(gGameSettings
.Options
);
953 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
958 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
962 P
:= g_Player_Get(PID
);
963 if P
= nil then Exit
;
965 NetOut
.Write(Byte(NET_MSG_PLR
));
967 NetOut
.Write(P
.Name
);
969 NetOut
.Write(P
.FActualModelName
);
970 NetOut
.Write(P
.FColor
.R
);
971 NetOut
.Write(P
.FColor
.G
);
972 NetOut
.Write(P
.FColor
.B
);
973 NetOut
.Write(P
.Team
);
975 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
978 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
983 Pl
:= g_Player_Get(PID
);
984 if Pl
= nil then Exit
;
985 if Pl
.FDummy
then Exit
;
987 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
997 if IsKeyPressed(KEY_CHAT
) then
998 kByte
:= NET_KEY_CHAT
1001 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1002 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1003 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1004 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1005 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1006 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1009 NetOut
.Write(kByte
);
1010 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1011 NetOut
.Write(GameX
);
1012 NetOut
.Write(GameY
);
1013 NetOut
.Write(GameVelX
);
1014 NetOut
.Write(GameVelY
);
1015 NetOut
.Write(GameAccelX
);
1016 NetOut
.Write(GameAccelY
);
1019 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1022 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1027 P
:= g_Player_Get(PID
);
1028 if P
= nil then Exit
;
1030 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1035 NetOut
.Write(Byte(alive
));
1036 NetOut
.Write(Byte(GodMode
));
1037 NetOut
.Write(Health
);
1038 NetOut
.Write(Armor
);
1040 NetOut
.Write(JetFuel
);
1041 NetOut
.Write(Lives
);
1044 for I
:= WP_FIRST
to WP_LAST
do
1045 NetOut
.Write(Byte(FWeapon
[I
]));
1047 for I
:= A_BULLETS
to A_HIGH
do
1048 NetOut
.Write(FAmmo
[I
]);
1050 for I
:= A_BULLETS
to A_HIGH
do
1051 NetOut
.Write(FMaxAmmo
[I
]);
1053 for I
:= MR_SUIT
to MR_MAX
do
1054 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1056 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1057 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1058 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1059 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1060 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1062 NetOut
.Write(Frags
);
1063 NetOut
.Write(Death
);
1065 NetOut
.Write(CurrWeap
);
1067 NetOut
.Write(Byte(FSpectator
));
1068 NetOut
.Write(Byte(FGhost
));
1069 NetOut
.Write(Byte(FPhysics
));
1070 NetOut
.Write(Byte(FNoRespawn
));
1071 NetOut
.Write(Byte(FJetpack
));
1072 NetOut
.Write(FFireTime
);
1075 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1078 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1080 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1083 NetOut
.Write(Attacker
);
1084 NetOut
.Write(Value
);
1088 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1091 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1093 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1095 NetOut
.Write(KillType
);
1096 NetOut
.Write(DeathType
);
1097 NetOut
.Write(Attacker
);
1099 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1102 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1104 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1106 NetOut
.Write(Weapon
);
1111 NetOut
.Write(ShotID
);
1113 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1116 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1118 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1121 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1124 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1128 Pl
:= g_Player_Get(PID
);
1129 if Pl
= nil then Exit
;
1131 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1133 NetOut
.Write(Pl
.Name
);
1135 NetOut
.Write(Pl
.Model
.Name
)
1138 NetOut
.Write(Pl
.FColor
.R
);
1139 NetOut
.Write(Pl
.FColor
.G
);
1140 NetOut
.Write(Pl
.FColor
.B
);
1141 NetOut
.Write(Pl
.Team
);
1143 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1148 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1153 it
:= g_Items_ByIdx(IID
);
1155 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1157 NetOut
.Write(Byte(Quiet
));
1159 if it
.dropped
then tt
:= tt
or $80;
1161 NetOut
.Write(Byte(it
.Fall
));
1162 NetOut
.Write(Byte(it
.Respawnable
));
1163 NetOut
.Write(it
.Obj
.X
);
1164 NetOut
.Write(it
.Obj
.Y
);
1165 NetOut
.Write(it
.Obj
.Vel
.X
);
1166 NetOut
.Write(it
.Obj
.Vel
.Y
);
1168 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1171 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1173 NetOut
.Write(Byte(NET_MSG_IDEL
));
1175 NetOut
.Write(Byte(Quiet
));
1177 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1182 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1186 TP
:= g_Map_PanelByGUID(PGUID
);
1187 if (TP
= nil) then exit
;
1191 NetOut
.Write(Byte(NET_MSG_PTEX
));
1192 NetOut
.Write(LongWord(PGUID
));
1193 NetOut
.Write(FCurTexture
);
1194 NetOut
.Write(FCurFrame
);
1195 NetOut
.Write(FCurFrameCount
);
1196 NetOut
.Write(AnimLoop
);
1199 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1202 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1207 TP
:= g_Map_PanelByGUID(PGUID
);
1208 if (TP
= nil) then exit
;
1210 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1211 NetOut
.Write(LongWord(PGUID
));
1212 NetOut
.Write(Byte(TP
.Enabled
));
1213 NetOut
.Write(TP
.LiftType
);
1216 NetOut
.Write(Word(TP
.Width
));
1217 NetOut
.Write(Word(TP
.Height
));
1219 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1220 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1221 NetOut
.Write(LongInt(TP
.movingStartX
));
1222 NetOut
.Write(LongInt(TP
.movingStartY
));
1223 NetOut
.Write(LongInt(TP
.movingEndX
));
1224 NetOut
.Write(LongInt(TP
.movingEndY
));
1225 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1226 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1227 NetOut
.Write(LongInt(TP
.sizeEndX
));
1228 NetOut
.Write(LongInt(TP
.sizeEndY
));
1229 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1230 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1231 NetOut
.Write(Byte(mpflags
));
1233 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1238 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1240 if gTriggers
= nil then Exit
;
1241 if T
.Sound
= nil then Exit
;
1243 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1244 NetOut
.Write(T
.ClientID
);
1245 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1246 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1247 NetOut
.Write(T
.SoundPlayCount
);
1249 g_Net_Host_Send(ID
, True);
1252 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1254 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1255 NetOut
.Write(gMusic
.Name
);
1256 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1257 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1258 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1260 g_Net_Host_Send(ID
, True);
1265 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1269 M
:= g_Monsters_ByUID(UID
);
1275 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1277 NetOut
.Write(MonsterType
);
1278 NetOut
.Write(MonsterState
);
1279 NetOut
.Write(MonsterAnim
);
1280 NetOut
.Write(MonsterTargetUID
);
1281 NetOut
.Write(MonsterTargetTime
);
1282 NetOut
.Write(MonsterBehaviour
);
1283 NetOut
.Write(MonsterSleep
);
1284 NetOut
.Write(MonsterHealth
);
1285 NetOut
.Write(MonsterAmmo
);
1286 NetOut
.Write(GameX
);
1287 NetOut
.Write(GameY
);
1288 NetOut
.Write(GameVelX
);
1289 NetOut
.Write(GameVelY
);
1290 NetOut
.Write(Byte(GameDirection
));
1293 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1296 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1300 M
:= g_Monsters_ByUID(UID
);
1301 if M
= nil then Exit
;
1303 NetOut
.Write(Byte(NET_MSG_MPOS
));
1308 NetOut
.Write(GameX
);
1309 NetOut
.Write(GameY
);
1310 NetOut
.Write(GameVelX
);
1311 NetOut
.Write(GameVelY
);
1312 NetOut
.Write(Byte(GameDirection
));
1315 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1318 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1322 M
:= g_Monsters_ByUID(UID
);
1323 if M
= nil then Exit
;
1325 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1330 NetOut
.Write(MonsterState
);
1331 NetOut
.Write(ForcedAnim
);
1332 NetOut
.Write(MonsterTargetUID
);
1333 NetOut
.Write(MonsterTargetTime
);
1334 NetOut
.Write(MonsterSleep
);
1335 NetOut
.Write(MonsterHealth
);
1336 NetOut
.Write(MonsterAmmo
);
1337 NetOut
.Write(MonsterPain
);
1338 NetOut
.Write(Byte(AnimIsReverse
));
1339 NetOut
.Write(FFireTime
);
1342 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1345 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1347 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1354 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1357 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1361 M
:= g_Monsters_ByUID(UID
);
1362 if M
= nil then Exit
;
1364 NetOut
.Write(Byte(NET_MSG_MDEL
));
1367 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1372 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1374 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1377 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1380 procedure MH_SEND_VoteEvent(EvType
: Byte;
1381 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1382 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1383 ID
: Integer = NET_EVERYONE
);
1385 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1386 NetOut
.Write(EvType
);
1387 NetOut
.Write(IntArg1
);
1388 NetOut
.Write(IntArg2
);
1389 NetOut
.Write(StrArg1
);
1390 NetOut
.Write(StrArg2
);
1392 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1395 // CLIENT MESSAGES //
1399 procedure MC_RECV_Chat(var M
: TMsg
);
1404 Txt
:= M
.ReadString();
1405 Mode
:= M
.ReadByte();
1407 if Mode
<> NET_CHAT_SYSTEM
then
1409 if Mode
= NET_CHAT_PLAYER
then
1411 g_Console_Add(Txt
, True);
1412 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1413 g_Game_ChatSound(b_Text_Unformat(Txt
));
1415 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1417 if gPlayer1
.Team
= TEAM_RED
then
1418 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1419 if gPlayer1
.Team
= TEAM_BLUE
then
1420 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1421 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1422 g_Game_ChatSound(b_Text_Unformat(Txt
));
1425 g_Console_Add(Txt
, True);
1428 procedure MC_RECV_Effect(var M
: TMsg
);
1436 if not gGameOn
then Exit
;
1437 Kind
:= M
.ReadByte();
1438 X
:= M
.ReadLongInt();
1439 Y
:= M
.ReadLongInt();
1440 Ang
:= M
.ReadSmallInt();
1444 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1448 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1450 Anim
:= TAnimation
.Create(ID
, False, 3);
1451 g_GFX_OnceAnim(X
, Y
, Anim
);
1455 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1460 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1462 Anim
:= TAnimation
.Create(ID
, False, 6);
1463 Anim
.Blending
:= False;
1464 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1468 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1473 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1475 Anim
:= TAnimation
.Create(ID
, False, 6);
1476 Anim
.Blending
:= False;
1477 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1481 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1486 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1488 Anim
:= TAnimation
.Create(ID
, False, 4);
1489 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1496 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1498 Anim
:= TAnimation
.Create(ID
, False, 4);
1499 g_GFX_OnceAnim(X
, Y
, Anim
);
1503 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1508 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1510 Anim
:= TAnimation
.Create(ID
, False, 4);
1511 g_GFX_OnceAnim(X
, Y
, Anim
);
1515 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1519 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1522 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1526 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1527 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1532 procedure MC_RECV_Sound(var M
: TMsg
);
1538 Name
:= M
.ReadString();
1539 Pos
:= M
.ReadByte() <> 0;
1542 X
:= M
.ReadLongInt();
1543 Y
:= M
.ReadLongInt();
1544 g_Sound_PlayExAt(Name
, X
, Y
);
1547 g_Sound_PlayEx(Name
);
1550 procedure MC_RECV_CreateShot(var M
: TMsg
);
1552 I
, X
, Y
, XV
, YV
: Integer;
1554 Target
, Spawner
: Word;
1557 I
:= M
.ReadLongInt();
1558 ShType
:= M
.ReadByte();
1559 Target
:= M
.ReadWord();
1560 Spawner
:= M
.ReadWord();
1561 Timeout
:= M
.ReadLongWord();
1562 X
:= M
.ReadLongInt();
1563 Y
:= M
.ReadLongInt();
1564 XV
:= M
.ReadLongInt();
1565 YV
:= M
.ReadLongInt();
1567 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1568 if (Shots
<> nil) and (I
<= High(Shots
)) then
1570 Shots
[I
].Timeout
:= Timeout
;
1571 //Shots[I].Target := Target; // TODO: find a use for Target later
1575 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1577 I
, TX
, TY
, TXV
, TYV
: Integer;
1579 I
:= M
.ReadLongInt();
1580 TX
:= M
.ReadLongInt();
1581 TY
:= M
.ReadLongInt();
1582 TXV
:= M
.ReadLongInt();
1583 TYV
:= M
.ReadLongInt();
1585 if (Shots
<> nil) and (I
<= High(Shots
)) then
1595 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1600 if not gGameOn
then Exit
;
1601 I
:= M
.ReadLongInt();
1602 L
:= (M
.ReadByte() <> 0);
1603 X
:= M
.ReadLongInt();
1604 Y
:= M
.ReadLongInt();
1606 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1609 procedure MC_RECV_GameStats(var M
: TMsg
);
1611 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1613 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1614 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1617 if gGameSettings
.GameMode
= GM_COOP
then
1619 gCoopMonstersKilled
:= M
.ReadWord();
1620 gCoopSecretsFound
:= M
.ReadWord();
1624 procedure MC_RECV_CoopStats(var M
: TMsg
);
1626 gTotalMonsters
:= M
.ReadLongInt();
1627 gSecretsCount
:= M
.ReadLongInt();
1628 gCoopTotalMonstersKilled
:= M
.ReadWord();
1629 gCoopTotalSecretsFound
:= M
.ReadWord();
1630 gCoopTotalMonsters
:= M
.ReadWord();
1631 gCoopTotalSecrets
:= M
.ReadWord();
1634 procedure MC_RECV_GameEvent(var M
: TMsg
);
1643 i1
, i2
: TStrings_Locale
;
1647 FillChar(EvHash
, Sizeof(EvHash
), 0);
1648 EvType
:= M
.ReadByte();
1649 EvNum
:= M
.ReadLongInt();
1650 EvStr
:= M
.ReadString();
1651 gLastMap
:= M
.ReadByte() <> 0;
1652 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1653 gStatsPressed
:= True;
1654 EvTime
:= M
.ReadLongWord();
1655 BHash
:= M
.ReadByte() <> 0;
1657 EvHash
:= M
.ReadMD5();
1665 g_Game_ClearLoading();
1666 g_Game_StopAllSounds(True);
1668 gSwitchGameMode
:= Byte(EvNum
);
1669 gGameSettings
.GameMode
:= gSwitchGameMode
;
1672 if not g_Game_StartMap(EvStr
, True) then
1674 if not isWadPath(EvStr
) then
1675 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1677 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1681 MC_SEND_FullStateRequest
;
1686 gMissionFailed
:= EvNum
<> 0;
1687 gExit
:= EXIT_ENDLEVELCUSTOM
;
1694 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1696 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1698 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1704 if EvNum
= TEAM_RED
then
1705 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1706 if EvNum
= TEAM_BLUE
then
1707 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1711 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1714 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1717 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1719 NET_EV_LMS_SURVIVOR
:
1720 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1723 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1727 pl
:= g_Player_Get(EvNum
and $FFFF);
1732 cnt
:= (EvNum
shr 16) and $FF;
1733 if Pos('w', EvStr
) = 0 then
1736 if Pos('t', EvStr
) = 0 then
1739 if Pos('-', EvStr
) = 0 then
1741 if Pos('e', EvStr
) = 0 then
1742 i1
:= I_PLAYER_SCORE_ADD_OWN
1744 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1747 if Pos('e', EvStr
) = 0 then
1748 i1
:= I_PLAYER_SCORE_SUB_OWN
1750 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1753 if Pos('r', EvStr
) > 0 then
1754 i2
:= I_PLAYER_SCORE_TO_RED
1756 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1757 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1761 if Pos('-', EvStr
) = 0 then
1762 i1
:= I_PLAYER_SCORE_ADD_TEAM
1764 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1766 if Pos('r', EvStr
) > 0 then
1767 i2
:= I_PLAYER_SCORE_RED
1769 i2
:= I_PLAYER_SCORE_BLUE
;
1770 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1775 if Pos('e', EvStr
) = 0 then
1776 i1
:= I_PLAYER_SCORE_WIN_OWN
1778 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1780 if Pos('r', EvStr
) > 0 then
1781 i2
:= I_PLAYER_SCORE_TO_RED
1783 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1784 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1790 if EvNum
= TEAM_RED
then
1791 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1792 if EvNum
= TEAM_BLUE
then
1793 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1794 if EvNum
= -TEAM_RED
then
1795 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1796 if EvNum
= -TEAM_BLUE
then
1797 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1802 g_Player_RemoveAllCorpses
;
1803 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1807 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1811 if EvNum
= TEAM_RED
then
1812 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1813 if EvNum
= TEAM_BLUE
then
1814 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1818 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1821 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1824 g_Game_Announce_KillCombo(EvNum
);
1826 NET_EV_PLAYER_TOUCH
:
1828 pl
:= g_Player_Get(EvNum
);
1836 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1845 EvType
:= M
.ReadByte();
1848 if Fl
= FLAG_NONE
then Exit
;
1850 Quiet
:= (M
.ReadByte() <> 0);
1851 PID
:= M
.ReadWord();
1853 gFlags
[Fl
].State
:= M
.ReadByte();
1854 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1855 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1856 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1857 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1858 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1860 Pl
:= g_Player_Get(PID
);
1862 (EvType
<> FLAG_STATE_NORMAL
) and
1863 (EvType
<> FLAG_STATE_DROPPED
) and
1864 (EvType
<> FLAG_STATE_RETURNED
) then
1870 if Quiet
or (Pl
= nil) then Exit
;
1872 if Fl
= FLAG_RED
then
1873 s
:= _lc
[I_PLAYER_FLAG_RED
]
1875 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1877 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1880 FLAG_STATE_CAPTURED
:
1882 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1886 if Fl
= FLAG_RED
then
1887 s
:= _lc
[I_PLAYER_FLAG_RED
]
1889 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1891 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1892 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1897 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1899 if Quiet
or (Pl
= nil) then Exit
;
1901 if Fl
= FLAG_RED
then
1902 s
:= _lc
[I_PLAYER_FLAG_RED
]
1904 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1906 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1907 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1912 g_Map_ResetFlag(FLAG_RED
);
1913 g_Map_ResetFlag(FLAG_BLUE
);
1914 if Quiet
or (Pl
= nil) then Exit
;
1915 Pl
.SetFlag(FLAG_NONE
);
1917 if Fl
= FLAG_RED
then
1918 s
:= _lc
[I_PLAYER_FLAG_RED
]
1920 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1922 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1923 Insert('.', ts
, Length(ts
) + 1 - 3);
1924 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1925 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1928 FLAG_STATE_RETURNED
:
1930 g_Map_ResetFlag(Fl
);
1933 if Fl
= FLAG_RED
then
1934 s
:= _lc
[I_PLAYER_FLAG_RED
]
1936 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1938 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1943 procedure MC_RECV_GameSettings(var M
: TMsg
);
1945 gGameSettings
.GameMode
:= M
.ReadByte();
1946 gGameSettings
.GoalLimit
:= M
.ReadWord();
1947 gGameSettings
.TimeLimit
:= M
.ReadWord();
1948 gGameSettings
.MaxLives
:= M
.ReadByte();
1949 gGameSettings
.Options
:= M
.ReadLongWord();
1954 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
1957 PName
, Model
: string;
1962 PID
:= M
.ReadWord();
1963 Pl
:= g_Player_Get(PID
);
1965 PName
:= M
.ReadString();
1966 Model
:= M
.ReadString();
1967 Color
.R
:= M
.ReadByte();
1968 Color
.G
:= M
.ReadByte();
1969 Color
.B
:= M
.ReadByte();
1973 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
1975 if (Pl
<> nil) then Exit
;
1976 DID
:= g_Player_Create(Model
, Color
, T
, False);
1977 with g_Player_Get(DID
) do
1986 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
1987 gPlayer1
.UID
:= PID
;
1988 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
1989 gPlayer1
.ChangeTeam(T
);
1991 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
1992 gPlayer2
.UID
:= PID
;
1993 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
1994 gPlayer2
.ChangeTeam(T
);
1998 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
1999 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2003 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2010 TmpX
, TmpY
: Integer;
2014 GT
:= M
.ReadLongWord();
2015 if GT
< gTime
- NET_MAX_DIFFTIME
then
2022 PID
:= M
.ReadWord();
2023 Pl
:= g_Player_Get(PID
);
2025 if Pl
= nil then Exit
;
2031 FPing
:= M
.ReadWord();
2032 FLoss
:= M
.ReadByte();
2033 kByte
:= M
.ReadWord();
2034 Dir
:= M
.ReadByte();
2036 TmpX
:= M
.ReadLongInt();
2037 TmpY
:= M
.ReadLongInt();
2041 if (kByte
= NET_KEY_CHAT
) then
2042 PressKey(KEY_CHAT
, 10000)
2045 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2046 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2047 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2048 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2049 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2052 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2053 SetDirection(TDirection(Dir
));
2055 GameVelX
:= M
.ReadLongInt();
2056 GameVelY
:= M
.ReadLongInt();
2057 GameAccelX
:= M
.ReadLongInt();
2058 GameAccelY
:= M
.ReadLongInt();
2059 SetLerp(TmpX
, TmpY
);
2060 if NetForcePlayerUpdate
then Update();
2064 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2072 PID
:= M
.ReadWord();
2073 Pl
:= g_Player_Get(PID
);
2080 alive
:= (M
.ReadByte() <> 0);
2081 GodMode
:= (M
.ReadByte() <> 0);
2082 Health
:= M
.ReadLongInt();
2083 Armor
:= M
.ReadLongInt();
2084 Air
:= M
.ReadLongInt();
2085 JetFuel
:= M
.ReadLongInt();
2086 Lives
:= M
.ReadByte();
2087 NewTeam
:= M
.ReadByte();
2089 for I
:= WP_FIRST
to WP_LAST
do
2090 FWeapon
[I
] := (M
.ReadByte() <> 0);
2092 for I
:= A_BULLETS
to A_HIGH
do
2093 FAmmo
[I
] := M
.ReadWord();
2095 for I
:= A_BULLETS
to A_HIGH
do
2096 FMaxAmmo
[I
] := M
.ReadWord();
2098 for I
:= MR_SUIT
to MR_MAX
do
2099 FMegaRulez
[I
] := M
.ReadLongWord();
2102 if (M
.ReadByte() <> 0) then
2103 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2104 if (M
.ReadByte() <> 0) then
2105 FRulez
:= FRulez
+ [R_KEY_RED
];
2106 if (M
.ReadByte() <> 0) then
2107 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2108 if (M
.ReadByte() <> 0) then
2109 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2110 if (M
.ReadByte() <> 0) then
2111 FRulez
:= FRulez
+ [R_BERSERK
];
2113 Frags
:= M
.ReadLongInt();
2114 Death
:= M
.ReadLongInt();
2116 SetWeapon(M
.ReadByte());
2118 FSpectator
:= M
.ReadByte() <> 0;
2121 if Pl
= gPlayer1
then
2126 if Pl
= gPlayer2
then
2134 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2135 gPlayer1
:= g_Player_Get(gLMSPID1
);
2136 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2137 gPlayer2
:= g_Player_Get(gLMSPID2
);
2139 FGhost
:= M
.ReadByte() <> 0;
2140 FPhysics
:= M
.ReadByte() <> 0;
2141 FNoRespawn
:= M
.ReadByte() <> 0;
2143 FJetpack
:= M
.ReadByte() <> 0;
2144 FFireTime
:= M
.ReadLongInt();
2145 if OldJet
and not FJetpack
then
2147 else if not OldJet
and FJetpack
then
2149 if Team
<> NewTeam
then
2150 Pl
.ChangeTeam(NewTeam
);
2156 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2161 Attacker
, Value
: Word;
2165 if not gGameOn
then Exit
;
2166 PID
:= M
.ReadWord();
2167 Pl
:= g_Player_Get(PID
);
2168 if Pl
= nil then Exit
;
2170 Kind
:= M
.ReadByte();
2171 Attacker
:= M
.ReadWord();
2172 Value
:= M
.ReadWord();
2177 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2182 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2186 KillType
, DeathType
: Byte;
2190 if not gGameOn
then Exit
;
2191 PID
:= M
.ReadWord();
2192 Pl
:= g_Player_Get(PID
);
2193 if Pl
= nil then Exit
;
2195 KillType
:= M
.ReadByte();
2196 DeathType
:= M
.ReadByte();
2197 Attacker
:= M
.ReadWord();
2201 Kill(KillType
, Attacker
, DeathType
);
2206 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2211 PID
:= M
.ReadWord();
2212 Pl
:= g_Player_Get(PID
);
2214 if Pl
= nil then Exit
;
2216 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2217 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2219 g_Player_Remove(PID
);
2224 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2229 X
, Y
, AX
, AY
: Integer;
2233 if not gGameOn
then Exit
;
2234 PID
:= M
.ReadWord();
2235 Pl
:= g_Player_Get(PID
);
2236 if Pl
= nil then Exit
;
2238 Weap
:= M
.ReadByte();
2239 X
:= M
.ReadLongInt();
2240 Y
:= M
.ReadLongInt();
2241 AX
:= M
.ReadLongInt();
2242 AY
:= M
.ReadLongInt();
2243 SHID
:= M
.ReadLongInt();
2246 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2249 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2258 PID
:= M
.ReadWord();
2259 Pl
:= g_Player_Get(PID
);
2260 if Pl
= nil then Exit
;
2262 TmpName
:= M
.ReadString();
2263 TmpModel
:= M
.ReadString();
2264 TmpColor
.R
:= M
.ReadByte();
2265 TmpColor
.G
:= M
.ReadByte();
2266 TmpColor
.B
:= M
.ReadByte();
2267 TmpTeam
:= M
.ReadByte();
2269 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2271 Pl
.ChangeTeam(TmpTeam
);
2272 if gPlayer1
= Pl
then
2273 gPlayer1Settings
.Team
:= TmpTeam
;
2274 if gPlayer2
= Pl
then
2275 gPlayer2Settings
.Team
:= TmpTeam
;
2277 Pl
.SetColor(TmpColor
);
2279 if Pl
.Name
<> TmpName
then
2281 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2285 if TmpModel
<> Pl
.Model
.Name
then
2286 Pl
.SetModel(TmpModel
);
2291 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2295 X
, Y
, VX
, VY
: Integer;
2297 Quiet
, Fall
{, Resp}: Boolean;
2301 if not gGameOn
then Exit
;
2303 Quiet
:= M
.ReadByte() <> 0;
2305 Fall
:= M
.ReadByte() <> 0;
2306 {Resp :=} M
.ReadByte();
2307 X
:= M
.ReadLongInt();
2308 Y
:= M
.ReadLongInt();
2309 VX
:= M
.ReadLongInt();
2310 VY
:= M
.ReadLongInt();
2312 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2313 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2315 it
:= g_Items_ByIdx(ID
);
2321 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2322 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2324 Anim
:= TAnimation
.Create(AID
, False, 4);
2325 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2331 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2336 if not gGameOn
then Exit
;
2338 Quiet
:= M
.ReadByte() <> 0;
2340 if not g_Items_ValidId(ID
) then exit
;
2342 if not Quiet
then g_Items_EmitPickupSound(ID
);
2349 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2356 if not gGameOn
then Exit
;
2358 PGUID
:= Integer(M
.ReadLongWord());
2359 Tex
:= M
.ReadLongInt();
2360 Fr
:= M
.ReadLongInt();
2361 Cnt
:= M
.ReadByte();
2362 Loop
:= M
.ReadByte();
2364 TP
:= g_Map_PanelByGUID(PGUID
);
2368 TP
.SetTexture(Tex
, Loop
);
2369 TP
.SetFrame(Fr
, Cnt
);
2373 procedure MC_RECV_PanelState(var M
: TMsg
);
2378 X
, Y
, W
, H
: Integer;
2380 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2381 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2384 if not gGameOn
then Exit
;
2386 PGUID
:= Integer(M
.ReadLongWord());
2387 E
:= (M
.ReadByte() <> 0);
2388 Lift
:= M
.ReadByte();
2389 X
:= M
.ReadLongInt();
2390 Y
:= M
.ReadLongInt();
2394 speedX
:= M
.ReadLongInt();
2395 speedY
:= M
.ReadLongInt();
2396 startX
:= M
.ReadLongInt();
2397 startY
:= M
.ReadLongInt();
2398 endX
:= M
.ReadLongInt();
2399 endY
:= M
.ReadLongInt();
2400 sizeSpX
:= M
.ReadLongInt();
2401 sizeSpY
:= M
.ReadLongInt();
2402 sizeEX
:= M
.ReadLongInt();
2403 sizeEY
:= M
.ReadLongInt();
2404 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2406 TP
:= g_Map_PanelByGUID(PGUID
);
2407 if (TP
= nil) then exit
;
2409 // update lifts state
2410 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2412 // update enabled/disabled state for all panels
2413 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2415 // update panel position, as it can be moved (mplat)
2420 // update mplat state
2421 TP
.movingSpeedX
:= speedX
;
2422 TP
.movingSpeedY
:= speedY
;
2423 TP
.movingStartX
:= startX
;
2424 TP
.movingStartY
:= startY
;
2425 TP
.movingEndX
:= endX
;
2426 TP
.movingEndY
:= endY
;
2427 TP
.sizeSpeedX
:= sizeSpX
;
2428 TP
.sizeSpeedY
:= sizeSpY
;
2429 TP
.sizeEndX
:= sizeEX
;
2430 TP
.sizeEndY
:= sizeEY
;
2431 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2432 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2433 // notify panel of it's position/size change, so it can fix other internal structures
2434 TP
.positionChanged();
2439 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2442 SPos
, SID
: LongWord;
2446 if not gGameOn
then Exit
;
2447 if gTriggers
= nil then Exit
;
2449 SID
:= M
.ReadLongWord();
2450 SPlaying
:= M
.ReadByte() <> 0;
2451 SPos
:= M
.ReadLongWord();
2452 SCount
:= M
.ReadLongInt();
2454 for I
:= Low(gTriggers
) to High(gTriggers
) do
2455 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2456 if gTriggers
[I
].ClientID
= SID
then
2457 with gTriggers
[I
] do
2462 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2464 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2465 Sound
.SetPosition(SPos
);
2468 if Sound
.IsPlaying
then Sound
.Stop
;
2470 SoundPlayCount
:= SCount
;
2474 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2481 if not gGameOn
then Exit
;
2483 MName
:= M
.ReadString();
2484 MPlaying
:= M
.ReadByte() <> 0;
2485 MPos
:= M
.ReadLongWord();
2486 MPaused
:= M
.ReadByte() <> 0;
2490 gMusic
.SetByName(MName
);
2492 gMusic
.SetPosition(MPos
);
2493 gMusic
.SpecPause
:= MPaused
;
2496 if gMusic
.IsPlaying
then gMusic
.Stop
;
2501 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2504 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2505 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2510 Mon
:= g_Monsters_ByUID(ID
);
2514 MType
:= M
.ReadByte();
2515 MState
:= M
.ReadByte();
2516 MAnim
:= M
.ReadByte();
2517 MTarg
:= M
.ReadWord();
2518 MTargTime
:= M
.ReadLongInt();
2519 MBehav
:= M
.ReadByte();
2520 MSleep
:= M
.ReadLongInt();
2521 MHealth
:= M
.ReadLongInt();
2522 MAmmo
:= M
.ReadLongInt();
2524 X
:= M
.ReadLongInt();
2525 Y
:= M
.ReadLongInt();
2526 VX
:= M
.ReadLongInt();
2527 VY
:= M
.ReadLongInt();
2528 MDir
:= M
.ReadByte();
2530 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2531 Mon
:= g_Monsters_ByUID(ID
);
2538 MonsterAnim
:= MAnim
;
2539 MonsterTargetUID
:= MTarg
;
2540 MonsterTargetTime
:= MTargTime
;
2541 MonsterBehaviour
:= MBehav
;
2542 MonsterSleep
:= MSleep
;
2543 MonsterAmmo
:= MAmmo
;
2548 setPosition(X
, Y
); // this will call positionChanged();
2554 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2561 Mon
:= g_Monsters_ByUID(ID
);
2567 X
:= M
.ReadLongInt();
2568 Y
:= M
.ReadLongInt();
2569 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2570 GameVelX
:= M
.ReadLongInt();
2571 GameVelY
:= M
.ReadLongInt();
2572 GameDirection
:= TDirection(M
.ReadByte());
2576 procedure MC_RECV_MonsterState(var M
: TMsg
);
2579 MState
, MFAnm
: Byte;
2581 AnimRevert
: Boolean;
2584 Mon
:= g_Monsters_ByUID(ID
);
2585 if Mon
= nil then Exit
;
2587 MState
:= M
.ReadByte();
2588 MFAnm
:= M
.ReadByte();
2592 MonsterTargetUID
:= M
.ReadWord();
2593 MonsterTargetTime
:= M
.ReadLongInt();
2594 MonsterSleep
:= M
.ReadLongInt();
2595 MonsterHealth
:= M
.ReadLongInt();
2596 MonsterAmmo
:= M
.ReadLongInt();
2597 MonsterPain
:= M
.ReadLongInt();
2598 AnimRevert
:= M
.ReadByte() <> 0;
2599 FFireTime
:= M
.ReadLongInt();
2600 RevertAnim(AnimRevert
);
2602 if MonsterState
<> MState
then
2604 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2605 if (MState
= MONSTATE_DIE
) then DieSound();
2606 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2607 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2608 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2610 SetState(MState
, MFAnm
);
2615 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2619 X
, Y
, VX
, VY
: Integer;
2623 Mon
:= g_Monsters_ByUID(ID
);
2624 if Mon
= nil then Exit
;
2626 X
:= M
.ReadLongInt();
2627 Y
:= M
.ReadLongInt();
2628 VX
:= M
.ReadLongInt();
2629 VY
:= M
.ReadLongInt();
2631 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2634 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2640 Mon
:= g_Monsters_ByUID(ID
);
2641 if Mon
= nil then Exit
;
2643 Mon
.MonsterRemoved
:= True;
2646 procedure MC_RECV_TimeSync(var M
: TMsg
);
2650 Time
:= M
.ReadLongWord();
2652 if gState
= STATE_INTERCUSTOM
then
2653 gServInterTime
:= Min(Time
, 255);
2656 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2660 Int1
, Int2
: SmallInt;
2662 EvID
:= M
.ReadByte();
2663 Int1
:= M
.ReadSmallInt();
2664 Int2
:= M
.ReadSmallInt();
2665 Str1
:= M
.ReadString();
2666 Str2
:= M
.ReadString();
2670 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2672 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2674 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2676 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2678 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2684 procedure MC_SEND_Info(Password
: string);
2688 NetOut
.Write(Byte(NET_MSG_INFO
));
2689 NetOut
.Write(GAME_VERSION
);
2690 NetOut
.Write(Password
);
2691 NetOut
.Write(gPlayer1Settings
.Name
);
2692 NetOut
.Write(gPlayer1Settings
.Model
);
2693 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2694 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2695 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2696 NetOut
.Write(gPlayer1Settings
.Team
);
2698 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2701 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2703 NetOut
.Write(Byte(NET_MSG_CHAT
));
2707 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2710 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
2712 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
2713 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
2717 procedure MC_SEND_PlayerPos();
2722 WeaponSelect
: Word = 0;
2725 if not gGameOn
then Exit
;
2726 if gPlayers
= nil then Exit
;
2727 if gPlayer1
= nil then Exit
;
2730 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2732 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2734 strafeDir
:= P1MoveButton
shr 4;
2735 P1MoveButton
:= P1MoveButton
and $0F;
2736 with gGameControls
.P1Control
do
2738 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 1
2739 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then P1MoveButton
:= 2
2740 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 0;
2743 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
2745 // new strafe mechanics
2746 if (strafeDir
= 0) then strafeDir
:= P1MoveButton
; // start strafing
2747 // now set direction according to strafe (reversed)
2748 if (strafeDir
= 2) then gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2749 else if (strafeDir
= 1) then gPlayer1
.SetDirection(TDirection
.D_RIGHT
);
2753 if (P1MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2754 else if (P1MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2755 else if P1MoveButton
<> 0 then gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2758 gPlayer1
.ReleaseKeys
;
2759 if P1MoveButton
= 1 then
2761 kByte
:= kByte
or NET_KEY_LEFT
;
2762 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2764 if P1MoveButton
= 2 then
2766 kByte
:= kByte
or NET_KEY_RIGHT
;
2767 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2769 if isKeyPressed(KeyUp
, KeyUp2
) then
2771 kByte
:= kByte
or NET_KEY_UP
;
2772 gPlayer1
.PressKey(KEY_UP
, 10000);
2774 if isKeyPressed(KeyDown
, KeyDown2
) then
2776 kByte
:= kByte
or NET_KEY_DOWN
;
2777 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2779 if isKeyPressed(KeyJump
, KeyJump2
) then
2781 kByte
:= kByte
or NET_KEY_JUMP
;
2782 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2784 if isKeyPressed(KeyFire
, KeyFire2
) then kByte
:= kByte
or NET_KEY_FIRE
;
2785 if isKeyPressed(KeyOpen
, KeyOpen2
) then kByte
:= kByte
or NET_KEY_OPEN
;
2786 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then kByte
:= kByte
or NET_KEY_NW
;
2787 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then kByte
:= kByte
or NET_KEY_PW
;
2788 for I
:= 0 to High(KeyWeapon
) do
2789 if isKeyPressed(KeyWeapon
[I
], KeyWeapon2
[I
]) then
2790 WeaponSelect
:= WeaponSelect
or Word(1 shl I
);
2792 // fix movebutton state
2793 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2796 kByte
:= NET_KEY_CHAT
;
2798 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2799 NetOut
.Write(gTime
);
2800 NetOut
.Write(kByte
);
2801 NetOut
.Write(Byte(gPlayer1
.Direction
));
2802 NetOut
.Write(WeaponSelect
);
2803 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2804 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2806 //kBytePrev := kByte;
2807 //kDirPrev := gPlayer1.Direction;
2810 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2812 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2813 NetOut
.Write(Byte(Start
));
2814 NetOut
.Write(Command
);
2815 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2818 procedure MC_SEND_PlayerSettings();
2820 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2821 NetOut
.Write(gPlayer1Settings
.Name
);
2822 NetOut
.Write(gPlayer1Settings
.Model
);
2823 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2824 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2825 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2826 NetOut
.Write(gPlayer1Settings
.Team
);
2828 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2831 procedure MC_SEND_FullStateRequest();
2833 NetOut
.Write(Byte(NET_MSG_REQFST
));
2835 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2838 procedure MC_SEND_CheatRequest(Kind
: Byte);
2840 NetOut
.Write(Byte(NET_MSG_CHEAT
));
2843 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2845 procedure MC_SEND_RCONPassword(Password
: string);
2847 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
2848 NetOut
.Write(Password
);
2850 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2852 procedure MC_SEND_RCONCommand(Cmd
: string);
2854 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
2857 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2860 // i have no idea why all this stuff is in here
2862 function ReadFile(const FileName
: TFileName
): AByte
;
2864 FileStream
: TStream
;
2867 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), TMsgType
.Notify
);
2868 fname
:= findDiskWad(FileName
);
2869 if length(fname
) = 0 then
2871 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), TMsgType
.Fatal
);
2872 SetLength(Result
, 0);
2875 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), TMsgType
.Notify
);
2877 FileStream
:= openDiskFileRO(fname
);
2879 if FileStream
.Size
> 0 then
2881 SetLength(Result
, FileStream
.Size
);
2882 FileStream
.Read(Result
[0], FileStream
.Size
);
2889 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
2893 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
2894 Result
.FileData
:= ReadFile(FileName
);
2895 Result
.FileSize
:= Length(Result
.FileData
);
2897 SetLength(Result
.ExternalResources
, ResList
.Count
);
2898 for i
:=0 to ResList
.Count
-1 do
2900 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
2901 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
2905 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
2907 ResultStream
: TMemoryStream
;
2909 ResultStream
:= TMemoryStream
.Create
;
2911 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
2912 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
2913 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
2915 SetLength(bytes
, ResultStream
.Size
);
2916 ResultStream
.Seek(0, soFromBeginning
);
2917 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2922 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
2924 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
2925 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
2926 SetLength(Result
.FileData
, Result
.FileSize
);
2927 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
2930 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
2932 ResultStream
: TMemoryStream
;
2935 resCount
:= Length(MapDataMsg
.ExternalResources
);
2937 ResultStream
:= TMemoryStream
.Create
;
2939 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
2940 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
2941 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
2943 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
2944 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
2946 SetLength(bytes
, ResultStream
.Size
);
2947 ResultStream
.Seek(0, soFromBeginning
);
2948 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2953 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
2957 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
2958 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
2960 SetLength(Result
.FileData
, Result
.FileSize
);
2961 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
2963 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
2964 SetLength(Result
.ExternalResources
, resCount
);
2966 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
2969 function IsValidFileName(const S
: String): Boolean;
2971 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
2976 for I
:= 1 to Length(S
) do
2977 Result
:= Result
and (not(S
[I
] in Forbidden
));
2980 function IsValidFilePath(const S
: String): Boolean;
2985 if not IsValidFileName(S
) then exit
;
2986 if FileExists(S
) then exit
;
2987 I
:= LastDelimiter('\/', S
);
2989 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
2994 procedure MC_SEND_MapRequest();
2996 NetOut
.Write(Byte(NET_MSG_MAP_REQUEST
));
2997 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3000 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3002 NetOut
.Write(Byte(NET_MSG_RES_REQUEST
));
3003 NetOut
.Write(resName
);
3004 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3007 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
3011 mapDataMsg
: TMapDataMsg
;
3013 e_WriteLog('NET: Received map request from ' +
3014 DecodeIPV4(C
.Peer
.address
.host
), TMsgType
.Notify
);
3016 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3017 peer
:= NetClients
[C
.ID
].Peer
;
3019 MapDataMsgToBytes(payload
, mapDataMsg
);
3020 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3023 mapDataMsg
.FileData
:= nil;
3024 mapDataMsg
.ExternalResources
:= nil;
3027 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
3032 resDataMsg
: TResDataMsg
;
3034 FileName
:= ExtractFileName(M
.ReadString());
3035 e_WriteLog('NET: Received res request: ' + FileName
+
3036 ' from ' + DecodeIPV4(C
.Peer
.address
.host
), TMsgType
.Notify
);
3038 if not IsValidFilePath(FileName
) then
3040 e_WriteLog('Invalid filename: ' + FileName
, TMsgType
.Warning
);
3044 peer
:= NetClients
[C
.ID
].Peer
;
3046 if gExternalResources
.IndexOf(FileName
) > -1 then
3048 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3049 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3050 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3052 ResDataMsgToBytes(payload
, resDataMsg
);
3053 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);