6d1f430e5509196b9212f1535b1baedf3658e8af
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;
434 //WeaponSelect: 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 SetWeapon(M
.ReadByte());
458 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
459 if Direction
<> TDirection(Dir
) then
460 JustTeleported
:= False;
462 SetDirection(TDirection(Dir
));
463 ReleaseKeysNoWeapon();
465 if kByte
= NET_KEY_CHAT
then
467 PressKey(KEY_CHAT
, 10000);
471 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
472 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
473 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
474 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
475 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
476 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
477 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
478 //if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
479 //if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
484 if (WeaponSelect and Word(1 shl i)) <> 0 then
486 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
487 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
519 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
527 TmpName
:= M
.ReadString();
528 TmpModel
:= M
.ReadString();
529 TmpColor
.R
:= M
.ReadByte();
530 TmpColor
.G
:= M
.ReadByte();
531 TmpColor
.B
:= M
.ReadByte();
532 TmpTeam
:= M
.ReadByte();
534 Pl
:= g_Player_Get(C
^.Player
);
535 if Pl
= nil then Exit
;
537 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
540 Pl
.SetColor(TmpColor
);
542 if Pl
.Name
<> TmpName
then
544 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
548 if TmpModel
<> Pl
.Model
.Name
then
549 Pl
.SetModel(TmpModel
);
551 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
556 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
560 Pwd
:= M
.ReadString();
561 if not NetAllowRCON
then Exit
;
562 if Pwd
= NetRCONPassword
then
565 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
568 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
571 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
575 Cmd
:= M
.ReadString();
576 if not NetAllowRCON
then Exit
;
577 if not C
^.RCONAuth
then
579 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
582 g_Console_Process(Cmd
);
587 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
590 Name
, Command
: string;
594 Start
:= M
.ReadByte() <> 0;
595 Command
:= M
.ReadString();
597 Pl
:= g_Player_Get(C
^.Player
);
598 if Pl
= nil then Exit
;
603 if not g_Console_CommandBlacklisted(Command
) then
604 g_Game_StartVote(Command
, Name
);
606 else if gVoteInProgress
then
608 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
609 Need
:= Floor((NetClientCount
+1)/2.0) + 1
611 Need
:= Floor(NetClientCount
/2.0) + 1;
616 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
617 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
623 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
624 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
632 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
634 function sendItemRespawn (it
: PItem
): Boolean;
636 result
:= false; // don't stop
637 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
640 function sendMonSpawn (mon
: TMonster
): Boolean;
642 result
:= false; // don't stop
643 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
646 function sendPanelState (pan
: TPanel
): Boolean;
648 result
:= false; // don't stop
649 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
650 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
656 if gPlayers
<> nil then
658 for I
:= Low(gPlayers
) to High(gPlayers
) do
660 if gPlayers
[I
] <> nil then
662 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
663 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
664 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
666 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
668 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
674 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
675 g_Mons_ForEach(sendMonSpawn
);
676 g_Map_ForEachPanel(sendPanelState
);
678 if gTriggers
<> nil then
680 for I
:= Low(gTriggers
) to High(gTriggers
) do
682 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
684 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
691 for I
:= Low(Shots
) to High(Shots
) do
693 if Shots
[i
].ShotType
in [6, 7, 8] then
695 MH_SEND_CreateShot(i
, ID
);
700 MH_SEND_TriggerMusic(ID
);
702 MH_SEND_GameStats(ID
);
703 MH_SEND_CoopStats(ID
);
705 if gGameSettings
.GameMode
= GM_CTF
then
707 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
708 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
711 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
713 if gLMSRespawn
> LMS_RESPAWN_NONE
then
715 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
719 procedure MH_SEND_Info(ID
: Byte);
723 Map
:= g_ExtractFileName(gMapInfo
.Map
);
727 NetOut
.Write(Byte(NET_MSG_INFO
));
729 NetOut
.Write(NetClients
[ID
].Player
);
730 NetOut
.Write(gGameSettings
.WAD
);
732 NetOut
.Write(gWADHash
);
733 NetOut
.Write(gGameSettings
.GameMode
);
734 NetOut
.Write(gGameSettings
.GoalLimit
);
735 NetOut
.Write(gGameSettings
.TimeLimit
);
736 NetOut
.Write(gGameSettings
.MaxLives
);
737 NetOut
.Write(gGameSettings
.Options
);
740 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
743 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
749 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
750 Mode
:= NET_CHAT_PLAYER
;
753 if (Mode
= NET_CHAT_TEAM
) then
755 for i
:= Low(gPlayers
) to High(gPlayers
) do
756 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
757 (gPlayers
[i
].Team
= ID
) then
759 NetOut
.Write(Byte(NET_MSG_CHAT
));
762 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
769 NetOut
.Write(Byte(NET_MSG_CHAT
));
772 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
775 if Mode
= NET_CHAT_SYSTEM
then
778 if ID
= NET_EVERYONE
then
780 if Mode
= NET_CHAT_PLAYER
then
782 g_Console_Add(Txt
, True);
783 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
784 g_Game_ChatSound(b_Text_Unformat(Txt
));
787 if Mode
= NET_CHAT_TEAM
then
788 if gPlayer1
<> nil then
790 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
792 g_Console_Add(#18'[Team] '#2 + Txt
, True);
793 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
794 g_Game_ChatSound(b_Text_Unformat(Txt
));
796 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
798 g_Console_Add(#20'[Team] '#2 + Txt
, True);
799 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
800 g_Game_ChatSound(b_Text_Unformat(Txt
));
806 Name
:= g_Net_ClientName_ByID(ID
);
807 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
808 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
809 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
813 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
815 NetOut
.Write(Byte(NET_MSG_GFX
));
821 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
824 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
826 NetOut
.Write(Byte(NET_MSG_SND
));
830 NetOut
.Write(Byte(1));
835 NetOut
.Write(Byte(0));
837 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
840 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
842 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
844 NetOut
.Write(Byte(NET_MSG_SHADD
));
846 NetOut
.Write(Shots
[Proj
].ShotType
);
847 NetOut
.Write(Shots
[Proj
].Target
);
848 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
849 NetOut
.Write(Shots
[Proj
].Timeout
);
850 NetOut
.Write(Shots
[Proj
].Obj
.X
);
851 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
852 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
853 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
855 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
858 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
860 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
862 NetOut
.Write(Byte(NET_MSG_SHPOS
));
864 NetOut
.Write(Shots
[Proj
].Obj
.X
);
865 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
866 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
867 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
869 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
872 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
874 NetOut
.Write(Byte(NET_MSG_SHDEL
));
876 NetOut
.Write(Byte(Loud
));
880 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
883 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
885 NetOut
.Write(Byte(NET_MSG_SCORE
));
886 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
888 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
889 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
892 if gGameSettings
.GameMode
= GM_COOP
then
894 NetOut
.Write(gCoopMonstersKilled
);
895 NetOut
.Write(gCoopSecretsFound
);
898 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
901 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
903 NetOut
.Write(Byte(NET_MSG_COOP
));
904 NetOut
.Write(gTotalMonsters
);
905 NetOut
.Write(gSecretsCount
);
906 NetOut
.Write(gCoopTotalMonstersKilled
);
907 NetOut
.Write(gCoopTotalSecretsFound
);
908 NetOut
.Write(gCoopTotalMonsters
);
909 NetOut
.Write(gCoopTotalSecrets
);
912 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
914 NetOut
.Write(Byte(NET_MSG_GEVENT
));
915 NetOut
.Write(EvType
);
918 NetOut
.Write(Byte(gLastMap
));
920 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
922 NetOut
.Write(Byte(1));
923 NetOut
.Write(gWADHash
);
925 NetOut
.Write(Byte(0));
927 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
930 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
932 NetOut
.Write(Byte(NET_MSG_FLAG
));
933 NetOut
.Write(EvType
);
935 NetOut
.Write(Byte(Quiet
));
937 NetOut
.Write(gFlags
[Flag
].State
);
938 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
939 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
940 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
941 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
942 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
944 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
947 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
949 NetOut
.Write(Byte(NET_MSG_GSET
));
950 NetOut
.Write(gGameSettings
.GameMode
);
951 NetOut
.Write(gGameSettings
.GoalLimit
);
952 NetOut
.Write(gGameSettings
.TimeLimit
);
953 NetOut
.Write(gGameSettings
.MaxLives
);
954 NetOut
.Write(gGameSettings
.Options
);
956 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
961 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
965 P
:= g_Player_Get(PID
);
966 if P
= nil then Exit
;
968 NetOut
.Write(Byte(NET_MSG_PLR
));
970 NetOut
.Write(P
.Name
);
972 NetOut
.Write(P
.FActualModelName
);
973 NetOut
.Write(P
.FColor
.R
);
974 NetOut
.Write(P
.FColor
.G
);
975 NetOut
.Write(P
.FColor
.B
);
976 NetOut
.Write(P
.Team
);
978 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
981 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
986 Pl
:= g_Player_Get(PID
);
987 if Pl
= nil then Exit
;
988 if Pl
.FDummy
then Exit
;
990 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1000 if IsKeyPressed(KEY_CHAT
) then
1001 kByte
:= NET_KEY_CHAT
1004 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1005 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1006 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1007 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1008 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1009 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1012 NetOut
.Write(kByte
);
1013 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1014 NetOut
.Write(GameX
);
1015 NetOut
.Write(GameY
);
1016 NetOut
.Write(GameVelX
);
1017 NetOut
.Write(GameVelY
);
1018 NetOut
.Write(GameAccelX
);
1019 NetOut
.Write(GameAccelY
);
1022 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1025 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1031 P
:= g_Player_Get(PID
);
1032 if P
= nil then Exit
;
1034 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1039 NetOut
.Write(Byte(alive
));
1040 NetOut
.Write(Byte(GodMode
));
1041 NetOut
.Write(Health
);
1042 NetOut
.Write(Armor
);
1044 NetOut
.Write(JetFuel
);
1045 NetOut
.Write(Lives
);
1048 // collect all weapons in one word
1050 for I
:= WP_FIRST
to WP_LAST
do if (FWeapon
[I
]) then ww
:= ww
or (1 shl (i
-WP_FIRST
));
1051 NetOut
.Write(Word(ww
));
1053 for I
:= A_BULLETS
to A_HIGH
do
1054 NetOut
.Write(FAmmo
[I
]);
1056 for I
:= A_BULLETS
to A_HIGH
do
1057 NetOut
.Write(FMaxAmmo
[I
]);
1059 for I
:= MR_SUIT
to MR_MAX
do
1060 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1062 // collect all special flags in one byte
1064 if (R_ITEM_BACKPACK
in FRulez
) then ww
:= ww
or $01;
1065 if (R_KEY_RED
in FRulez
) then ww
:= ww
or $02;
1066 if (R_KEY_GREEN
in FRulez
) then ww
:= ww
or $04;
1067 if (R_KEY_BLUE
in FRulez
) then ww
:= ww
or $08;
1068 if (R_BERSERK
in FRulez
) then ww
:= ww
or $10;
1069 NetOut
.Write(Byte(ww
));
1071 NetOut
.Write(Frags
);
1072 NetOut
.Write(Death
);
1074 NetOut
.Write(CurrWeap
);
1078 if (FSpectator
) then ww
:= ww
or $01;
1079 if (FGhost
) then ww
:= ww
or $02;
1080 if (FPhysics
) then ww
:= ww
or $04;
1081 if (FNoRespawn
) then ww
:= ww
or $08;
1082 if (FJetpack
) then ww
:= ww
or $10;
1083 NetOut
.Write(Byte(ww
));
1085 NetOut
.Write(FFireTime
);
1088 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1091 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1093 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1096 NetOut
.Write(Attacker
);
1097 NetOut
.Write(Value
);
1101 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1104 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1106 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1108 NetOut
.Write(KillType
);
1109 NetOut
.Write(DeathType
);
1110 NetOut
.Write(Attacker
);
1112 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1115 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1117 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1119 NetOut
.Write(Weapon
);
1124 NetOut
.Write(ShotID
);
1126 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1129 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1131 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1134 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1137 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1141 Pl
:= g_Player_Get(PID
);
1142 if Pl
= nil then Exit
;
1144 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1146 NetOut
.Write(Pl
.Name
);
1148 NetOut
.Write(Pl
.Model
.Name
)
1151 NetOut
.Write(Pl
.FColor
.R
);
1152 NetOut
.Write(Pl
.FColor
.G
);
1153 NetOut
.Write(Pl
.FColor
.B
);
1154 NetOut
.Write(Pl
.Team
);
1156 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1161 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1166 it
:= g_Items_ByIdx(IID
);
1168 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1170 NetOut
.Write(Byte(Quiet
));
1172 if it
.dropped
then tt
:= tt
or $80;
1174 NetOut
.Write(Byte(it
.Fall
));
1175 NetOut
.Write(Byte(it
.Respawnable
));
1176 NetOut
.Write(it
.Obj
.X
);
1177 NetOut
.Write(it
.Obj
.Y
);
1178 NetOut
.Write(it
.Obj
.Vel
.X
);
1179 NetOut
.Write(it
.Obj
.Vel
.Y
);
1181 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1184 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1186 NetOut
.Write(Byte(NET_MSG_IDEL
));
1188 NetOut
.Write(Byte(Quiet
));
1190 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1195 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1199 TP
:= g_Map_PanelByGUID(PGUID
);
1200 if (TP
= nil) then exit
;
1204 NetOut
.Write(Byte(NET_MSG_PTEX
));
1205 NetOut
.Write(LongWord(PGUID
));
1206 NetOut
.Write(FCurTexture
);
1207 NetOut
.Write(FCurFrame
);
1208 NetOut
.Write(FCurFrameCount
);
1209 NetOut
.Write(AnimLoop
);
1212 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1215 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1220 TP
:= g_Map_PanelByGUID(PGUID
);
1221 if (TP
= nil) then exit
;
1223 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1224 NetOut
.Write(LongWord(PGUID
));
1225 NetOut
.Write(Byte(TP
.Enabled
));
1226 NetOut
.Write(TP
.LiftType
);
1229 NetOut
.Write(Word(TP
.Width
));
1230 NetOut
.Write(Word(TP
.Height
));
1232 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1233 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1234 NetOut
.Write(LongInt(TP
.movingStartX
));
1235 NetOut
.Write(LongInt(TP
.movingStartY
));
1236 NetOut
.Write(LongInt(TP
.movingEndX
));
1237 NetOut
.Write(LongInt(TP
.movingEndY
));
1238 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1239 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1240 NetOut
.Write(LongInt(TP
.sizeEndX
));
1241 NetOut
.Write(LongInt(TP
.sizeEndY
));
1242 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1243 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1244 NetOut
.Write(Byte(mpflags
));
1246 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1251 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1253 if gTriggers
= nil then Exit
;
1254 if T
.Sound
= nil then Exit
;
1256 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1257 NetOut
.Write(T
.ClientID
);
1258 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1259 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1260 NetOut
.Write(T
.SoundPlayCount
);
1262 g_Net_Host_Send(ID
, True);
1265 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1267 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1268 NetOut
.Write(gMusic
.Name
);
1269 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1270 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1271 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1273 g_Net_Host_Send(ID
, True);
1278 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1282 M
:= g_Monsters_ByUID(UID
);
1288 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1290 NetOut
.Write(MonsterType
);
1291 NetOut
.Write(MonsterState
);
1292 NetOut
.Write(MonsterAnim
);
1293 NetOut
.Write(MonsterTargetUID
);
1294 NetOut
.Write(MonsterTargetTime
);
1295 NetOut
.Write(MonsterBehaviour
);
1296 NetOut
.Write(MonsterSleep
);
1297 NetOut
.Write(MonsterHealth
);
1298 NetOut
.Write(MonsterAmmo
);
1299 NetOut
.Write(GameX
);
1300 NetOut
.Write(GameY
);
1301 NetOut
.Write(GameVelX
);
1302 NetOut
.Write(GameVelY
);
1303 NetOut
.Write(Byte(GameDirection
));
1306 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1309 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1313 M
:= g_Monsters_ByUID(UID
);
1314 if M
= nil then Exit
;
1316 NetOut
.Write(Byte(NET_MSG_MPOS
));
1321 NetOut
.Write(GameX
);
1322 NetOut
.Write(GameY
);
1323 NetOut
.Write(GameVelX
);
1324 NetOut
.Write(GameVelY
);
1325 NetOut
.Write(Byte(GameDirection
));
1328 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1331 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1335 M
:= g_Monsters_ByUID(UID
);
1336 if M
= nil then Exit
;
1338 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1343 NetOut
.Write(MonsterState
);
1344 NetOut
.Write(ForcedAnim
);
1345 NetOut
.Write(MonsterTargetUID
);
1346 NetOut
.Write(MonsterTargetTime
);
1347 NetOut
.Write(MonsterSleep
);
1348 NetOut
.Write(MonsterHealth
);
1349 NetOut
.Write(MonsterAmmo
);
1350 NetOut
.Write(MonsterPain
);
1351 NetOut
.Write(Byte(AnimIsReverse
));
1352 NetOut
.Write(FFireTime
);
1355 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1358 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1360 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1367 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1370 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1374 M
:= g_Monsters_ByUID(UID
);
1375 if M
= nil then Exit
;
1377 NetOut
.Write(Byte(NET_MSG_MDEL
));
1380 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1385 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1387 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1390 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1393 procedure MH_SEND_VoteEvent(EvType
: Byte;
1394 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1395 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1396 ID
: Integer = NET_EVERYONE
);
1398 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1399 NetOut
.Write(EvType
);
1400 NetOut
.Write(IntArg1
);
1401 NetOut
.Write(IntArg2
);
1402 NetOut
.Write(StrArg1
);
1403 NetOut
.Write(StrArg2
);
1405 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1408 // CLIENT MESSAGES //
1412 procedure MC_RECV_Chat(var M
: TMsg
);
1417 Txt
:= M
.ReadString();
1418 Mode
:= M
.ReadByte();
1420 if Mode
<> NET_CHAT_SYSTEM
then
1422 if Mode
= NET_CHAT_PLAYER
then
1424 g_Console_Add(Txt
, True);
1425 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1426 g_Game_ChatSound(b_Text_Unformat(Txt
));
1428 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1430 if gPlayer1
.Team
= TEAM_RED
then
1431 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1432 if gPlayer1
.Team
= TEAM_BLUE
then
1433 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1434 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1435 g_Game_ChatSound(b_Text_Unformat(Txt
));
1438 g_Console_Add(Txt
, True);
1441 procedure MC_RECV_Effect(var M
: TMsg
);
1449 if not gGameOn
then Exit
;
1450 Kind
:= M
.ReadByte();
1451 X
:= M
.ReadLongInt();
1452 Y
:= M
.ReadLongInt();
1453 Ang
:= M
.ReadSmallInt();
1457 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1461 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1463 Anim
:= TAnimation
.Create(ID
, False, 3);
1464 g_GFX_OnceAnim(X
, Y
, Anim
);
1468 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1473 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') 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_EXPLODEROCKET', X
, Y
);
1486 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1488 Anim
:= TAnimation
.Create(ID
, False, 6);
1489 Anim
.Blending
:= False;
1490 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1494 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1499 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1501 Anim
:= TAnimation
.Create(ID
, False, 4);
1502 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1509 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1511 Anim
:= TAnimation
.Create(ID
, False, 4);
1512 g_GFX_OnceAnim(X
, Y
, Anim
);
1516 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1521 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1523 Anim
:= TAnimation
.Create(ID
, False, 4);
1524 g_GFX_OnceAnim(X
, Y
, Anim
);
1528 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1532 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1535 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1539 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1540 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1545 procedure MC_RECV_Sound(var M
: TMsg
);
1551 Name
:= M
.ReadString();
1552 Pos
:= M
.ReadByte() <> 0;
1555 X
:= M
.ReadLongInt();
1556 Y
:= M
.ReadLongInt();
1557 g_Sound_PlayExAt(Name
, X
, Y
);
1560 g_Sound_PlayEx(Name
);
1563 procedure MC_RECV_CreateShot(var M
: TMsg
);
1565 I
, X
, Y
, XV
, YV
: Integer;
1567 Target
, Spawner
: Word;
1570 I
:= M
.ReadLongInt();
1571 ShType
:= M
.ReadByte();
1572 Target
:= M
.ReadWord();
1573 Spawner
:= M
.ReadWord();
1574 Timeout
:= M
.ReadLongWord();
1575 X
:= M
.ReadLongInt();
1576 Y
:= M
.ReadLongInt();
1577 XV
:= M
.ReadLongInt();
1578 YV
:= M
.ReadLongInt();
1580 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1581 if (Shots
<> nil) and (I
<= High(Shots
)) then
1583 Shots
[I
].Timeout
:= Timeout
;
1584 //Shots[I].Target := Target; // TODO: find a use for Target later
1588 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1590 I
, TX
, TY
, TXV
, TYV
: Integer;
1592 I
:= M
.ReadLongInt();
1593 TX
:= M
.ReadLongInt();
1594 TY
:= M
.ReadLongInt();
1595 TXV
:= M
.ReadLongInt();
1596 TYV
:= M
.ReadLongInt();
1598 if (Shots
<> nil) and (I
<= High(Shots
)) then
1608 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1613 if not gGameOn
then Exit
;
1614 I
:= M
.ReadLongInt();
1615 L
:= (M
.ReadByte() <> 0);
1616 X
:= M
.ReadLongInt();
1617 Y
:= M
.ReadLongInt();
1619 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1622 procedure MC_RECV_GameStats(var M
: TMsg
);
1624 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1626 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1627 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1630 if gGameSettings
.GameMode
= GM_COOP
then
1632 gCoopMonstersKilled
:= M
.ReadWord();
1633 gCoopSecretsFound
:= M
.ReadWord();
1637 procedure MC_RECV_CoopStats(var M
: TMsg
);
1639 gTotalMonsters
:= M
.ReadLongInt();
1640 gSecretsCount
:= M
.ReadLongInt();
1641 gCoopTotalMonstersKilled
:= M
.ReadWord();
1642 gCoopTotalSecretsFound
:= M
.ReadWord();
1643 gCoopTotalMonsters
:= M
.ReadWord();
1644 gCoopTotalSecrets
:= M
.ReadWord();
1647 procedure MC_RECV_GameEvent(var M
: TMsg
);
1656 i1
, i2
: TStrings_Locale
;
1660 FillChar(EvHash
, Sizeof(EvHash
), 0);
1661 EvType
:= M
.ReadByte();
1662 EvNum
:= M
.ReadLongInt();
1663 EvStr
:= M
.ReadString();
1664 gLastMap
:= M
.ReadByte() <> 0;
1665 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1666 gStatsPressed
:= True;
1667 EvTime
:= M
.ReadLongWord();
1668 BHash
:= M
.ReadByte() <> 0;
1670 EvHash
:= M
.ReadMD5();
1678 g_Game_ClearLoading();
1679 g_Game_StopAllSounds(True);
1681 gSwitchGameMode
:= Byte(EvNum
);
1682 gGameSettings
.GameMode
:= gSwitchGameMode
;
1685 if not g_Game_StartMap(EvStr
, True) then
1687 if not isWadPath(EvStr
) then
1688 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1690 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1694 MC_SEND_FullStateRequest
;
1699 gMissionFailed
:= EvNum
<> 0;
1700 gExit
:= EXIT_ENDLEVELCUSTOM
;
1707 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1709 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1711 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1717 if EvNum
= TEAM_RED
then
1718 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1719 if EvNum
= TEAM_BLUE
then
1720 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1724 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1727 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1730 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1732 NET_EV_LMS_SURVIVOR
:
1733 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1736 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1740 pl
:= g_Player_Get(EvNum
and $FFFF);
1745 cnt
:= (EvNum
shr 16) and $FF;
1746 if Pos('w', EvStr
) = 0 then
1749 if Pos('t', EvStr
) = 0 then
1752 if Pos('-', EvStr
) = 0 then
1754 if Pos('e', EvStr
) = 0 then
1755 i1
:= I_PLAYER_SCORE_ADD_OWN
1757 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1760 if Pos('e', EvStr
) = 0 then
1761 i1
:= I_PLAYER_SCORE_SUB_OWN
1763 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1766 if Pos('r', EvStr
) > 0 then
1767 i2
:= I_PLAYER_SCORE_TO_RED
1769 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1770 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1774 if Pos('-', EvStr
) = 0 then
1775 i1
:= I_PLAYER_SCORE_ADD_TEAM
1777 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1779 if Pos('r', EvStr
) > 0 then
1780 i2
:= I_PLAYER_SCORE_RED
1782 i2
:= I_PLAYER_SCORE_BLUE
;
1783 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1788 if Pos('e', EvStr
) = 0 then
1789 i1
:= I_PLAYER_SCORE_WIN_OWN
1791 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1793 if Pos('r', EvStr
) > 0 then
1794 i2
:= I_PLAYER_SCORE_TO_RED
1796 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1797 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1803 if EvNum
= TEAM_RED
then
1804 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1805 if EvNum
= TEAM_BLUE
then
1806 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1807 if EvNum
= -TEAM_RED
then
1808 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1809 if EvNum
= -TEAM_BLUE
then
1810 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1815 g_Player_RemoveAllCorpses
;
1816 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1820 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1824 if EvNum
= TEAM_RED
then
1825 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1826 if EvNum
= TEAM_BLUE
then
1827 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1831 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1834 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1837 g_Game_Announce_KillCombo(EvNum
);
1839 NET_EV_PLAYER_TOUCH
:
1841 pl
:= g_Player_Get(EvNum
);
1849 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1858 EvType
:= M
.ReadByte();
1861 if Fl
= FLAG_NONE
then Exit
;
1863 Quiet
:= (M
.ReadByte() <> 0);
1864 PID
:= M
.ReadWord();
1866 gFlags
[Fl
].State
:= M
.ReadByte();
1867 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1868 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1869 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1870 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1871 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1873 Pl
:= g_Player_Get(PID
);
1875 (EvType
<> FLAG_STATE_NORMAL
) and
1876 (EvType
<> FLAG_STATE_DROPPED
) and
1877 (EvType
<> FLAG_STATE_RETURNED
) then
1883 if Quiet
or (Pl
= nil) then Exit
;
1885 if Fl
= FLAG_RED
then
1886 s
:= _lc
[I_PLAYER_FLAG_RED
]
1888 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1890 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1893 FLAG_STATE_CAPTURED
:
1895 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1899 if Fl
= FLAG_RED
then
1900 s
:= _lc
[I_PLAYER_FLAG_RED
]
1902 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1904 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1905 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1910 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1912 if Quiet
or (Pl
= nil) then Exit
;
1914 if Fl
= FLAG_RED
then
1915 s
:= _lc
[I_PLAYER_FLAG_RED
]
1917 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1919 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1920 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1925 g_Map_ResetFlag(FLAG_RED
);
1926 g_Map_ResetFlag(FLAG_BLUE
);
1927 if Quiet
or (Pl
= nil) then Exit
;
1928 Pl
.SetFlag(FLAG_NONE
);
1930 if Fl
= FLAG_RED
then
1931 s
:= _lc
[I_PLAYER_FLAG_RED
]
1933 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1935 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1936 Insert('.', ts
, Length(ts
) + 1 - 3);
1937 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1938 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1941 FLAG_STATE_RETURNED
:
1943 g_Map_ResetFlag(Fl
);
1946 if Fl
= FLAG_RED
then
1947 s
:= _lc
[I_PLAYER_FLAG_RED
]
1949 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1951 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1956 procedure MC_RECV_GameSettings(var M
: TMsg
);
1958 gGameSettings
.GameMode
:= M
.ReadByte();
1959 gGameSettings
.GoalLimit
:= M
.ReadWord();
1960 gGameSettings
.TimeLimit
:= M
.ReadWord();
1961 gGameSettings
.MaxLives
:= M
.ReadByte();
1962 gGameSettings
.Options
:= M
.ReadLongWord();
1967 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
1970 PName
, Model
: string;
1975 PID
:= M
.ReadWord();
1976 Pl
:= g_Player_Get(PID
);
1978 PName
:= M
.ReadString();
1979 Model
:= M
.ReadString();
1980 Color
.R
:= M
.ReadByte();
1981 Color
.G
:= M
.ReadByte();
1982 Color
.B
:= M
.ReadByte();
1986 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
1988 if (Pl
<> nil) then Exit
;
1989 DID
:= g_Player_Create(Model
, Color
, T
, False);
1990 with g_Player_Get(DID
) do
1999 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2000 gPlayer1
.UID
:= PID
;
2001 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2002 gPlayer1
.ChangeTeam(T
);
2004 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2005 gPlayer2
.UID
:= PID
;
2006 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2007 gPlayer2
.ChangeTeam(T
);
2011 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2012 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2016 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2023 TmpX
, TmpY
: Integer;
2027 GT
:= M
.ReadLongWord();
2028 if GT
< gTime
- NET_MAX_DIFFTIME
then
2035 PID
:= M
.ReadWord();
2036 Pl
:= g_Player_Get(PID
);
2038 if Pl
= nil then Exit
;
2044 FPing
:= M
.ReadWord();
2045 FLoss
:= M
.ReadByte();
2046 kByte
:= M
.ReadWord();
2047 Dir
:= M
.ReadByte();
2049 TmpX
:= M
.ReadLongInt();
2050 TmpY
:= M
.ReadLongInt();
2052 ReleaseKeysNoWeapon
;
2054 if (kByte
= NET_KEY_CHAT
) then
2055 PressKey(KEY_CHAT
, 10000)
2058 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2059 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2060 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2061 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2062 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2065 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2066 SetDirection(TDirection(Dir
));
2068 GameVelX
:= M
.ReadLongInt();
2069 GameVelY
:= M
.ReadLongInt();
2070 GameAccelX
:= M
.ReadLongInt();
2071 GameAccelY
:= M
.ReadLongInt();
2072 SetLerp(TmpX
, TmpY
);
2073 if NetForcePlayerUpdate
then Update();
2077 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2086 PID
:= M
.ReadWord();
2087 Pl
:= g_Player_Get(PID
);
2094 alive
:= (M
.ReadByte() <> 0);
2095 GodMode
:= (M
.ReadByte() <> 0);
2096 Health
:= M
.ReadLongInt();
2097 Armor
:= M
.ReadLongInt();
2098 Air
:= M
.ReadLongInt();
2099 JetFuel
:= M
.ReadLongInt();
2100 Lives
:= M
.ReadByte();
2101 NewTeam
:= M
.ReadByte();
2104 for I
:= WP_FIRST
to WP_LAST
do
2106 FWeapon
[I
] := ((ww
and $01) <> 0);
2110 for I
:= A_BULLETS
to A_HIGH
do
2111 FAmmo
[I
] := M
.ReadWord();
2113 for I
:= A_BULLETS
to A_HIGH
do
2114 FMaxAmmo
[I
] := M
.ReadWord();
2116 for I
:= MR_SUIT
to MR_MAX
do
2117 FMegaRulez
[I
] := M
.ReadLongWord();
2120 // unpack special flags
2122 if ((ww
and $01) <> 0) then FRulez
:= FRulez
+[R_ITEM_BACKPACK
];
2123 if ((ww
and $02) <> 0) then FRulez
:= FRulez
+[R_KEY_RED
];
2124 if ((ww
and $04) <> 0) then FRulez
:= FRulez
+[R_KEY_GREEN
];
2125 if ((ww
and $08) <> 0) then FRulez
:= FRulez
+[R_KEY_BLUE
];
2126 if ((ww
and $10) <> 0) then FRulez
:= FRulez
+[R_BERSERK
];
2128 Frags
:= M
.ReadLongInt();
2129 Death
:= M
.ReadLongInt();
2131 SetWeapon(M
.ReadByte());
2136 FSpectator
:= ((ww
and $01) <> 0);
2139 if Pl
= gPlayer1
then
2144 if Pl
= gPlayer2
then
2152 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2153 gPlayer1
:= g_Player_Get(gLMSPID1
);
2154 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2155 gPlayer2
:= g_Player_Get(gLMSPID2
);
2158 FGhost
:= ((ww
and $02) <> 0);
2159 FPhysics
:= ((ww
and $04) <> 0);
2160 FNoRespawn
:= ((ww
and $08) <> 0);
2162 FJetpack
:= ((ww
and $10) <> 0);
2163 FFireTime
:= M
.ReadLongInt();
2164 if OldJet
and not FJetpack
then
2166 else if not OldJet
and FJetpack
then
2168 if Team
<> NewTeam
then
2169 Pl
.ChangeTeam(NewTeam
);
2175 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2180 Attacker
, Value
: Word;
2184 if not gGameOn
then Exit
;
2185 PID
:= M
.ReadWord();
2186 Pl
:= g_Player_Get(PID
);
2187 if Pl
= nil then Exit
;
2189 Kind
:= M
.ReadByte();
2190 Attacker
:= M
.ReadWord();
2191 Value
:= M
.ReadWord();
2196 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2201 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2205 KillType
, DeathType
: Byte;
2209 if not gGameOn
then Exit
;
2210 PID
:= M
.ReadWord();
2211 Pl
:= g_Player_Get(PID
);
2212 if Pl
= nil then Exit
;
2214 KillType
:= M
.ReadByte();
2215 DeathType
:= M
.ReadByte();
2216 Attacker
:= M
.ReadWord();
2220 Kill(KillType
, Attacker
, DeathType
);
2225 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2230 PID
:= M
.ReadWord();
2231 Pl
:= g_Player_Get(PID
);
2233 if Pl
= nil then Exit
;
2235 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2236 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2238 g_Player_Remove(PID
);
2243 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2248 X
, Y
, AX
, AY
: Integer;
2252 if not gGameOn
then Exit
;
2253 PID
:= M
.ReadWord();
2254 Pl
:= g_Player_Get(PID
);
2255 if Pl
= nil then Exit
;
2257 Weap
:= M
.ReadByte();
2258 X
:= M
.ReadLongInt();
2259 Y
:= M
.ReadLongInt();
2260 AX
:= M
.ReadLongInt();
2261 AY
:= M
.ReadLongInt();
2262 SHID
:= M
.ReadLongInt();
2265 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2268 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2277 PID
:= M
.ReadWord();
2278 Pl
:= g_Player_Get(PID
);
2279 if Pl
= nil then Exit
;
2281 TmpName
:= M
.ReadString();
2282 TmpModel
:= M
.ReadString();
2283 TmpColor
.R
:= M
.ReadByte();
2284 TmpColor
.G
:= M
.ReadByte();
2285 TmpColor
.B
:= M
.ReadByte();
2286 TmpTeam
:= M
.ReadByte();
2288 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2290 Pl
.ChangeTeam(TmpTeam
);
2291 if gPlayer1
= Pl
then
2292 gPlayer1Settings
.Team
:= TmpTeam
;
2293 if gPlayer2
= Pl
then
2294 gPlayer2Settings
.Team
:= TmpTeam
;
2296 Pl
.SetColor(TmpColor
);
2298 if Pl
.Name
<> TmpName
then
2300 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2304 if TmpModel
<> Pl
.Model
.Name
then
2305 Pl
.SetModel(TmpModel
);
2310 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2314 X
, Y
, VX
, VY
: Integer;
2316 Quiet
, Fall
{, Resp}: Boolean;
2320 if not gGameOn
then Exit
;
2322 Quiet
:= M
.ReadByte() <> 0;
2324 Fall
:= M
.ReadByte() <> 0;
2325 {Resp :=} M
.ReadByte();
2326 X
:= M
.ReadLongInt();
2327 Y
:= M
.ReadLongInt();
2328 VX
:= M
.ReadLongInt();
2329 VY
:= M
.ReadLongInt();
2331 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2332 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2334 it
:= g_Items_ByIdx(ID
);
2340 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2341 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2343 Anim
:= TAnimation
.Create(AID
, False, 4);
2344 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2350 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2355 if not gGameOn
then Exit
;
2357 Quiet
:= M
.ReadByte() <> 0;
2359 if not g_Items_ValidId(ID
) then exit
;
2361 if not Quiet
then g_Items_EmitPickupSound(ID
);
2368 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2375 if not gGameOn
then Exit
;
2377 PGUID
:= Integer(M
.ReadLongWord());
2378 Tex
:= M
.ReadLongInt();
2379 Fr
:= M
.ReadLongInt();
2380 Cnt
:= M
.ReadByte();
2381 Loop
:= M
.ReadByte();
2383 TP
:= g_Map_PanelByGUID(PGUID
);
2387 TP
.SetTexture(Tex
, Loop
);
2388 TP
.SetFrame(Fr
, Cnt
);
2392 procedure MC_RECV_PanelState(var M
: TMsg
);
2397 X
, Y
, W
, H
: Integer;
2399 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2400 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2403 if not gGameOn
then Exit
;
2405 PGUID
:= Integer(M
.ReadLongWord());
2406 E
:= (M
.ReadByte() <> 0);
2407 Lift
:= M
.ReadByte();
2408 X
:= M
.ReadLongInt();
2409 Y
:= M
.ReadLongInt();
2413 speedX
:= M
.ReadLongInt();
2414 speedY
:= M
.ReadLongInt();
2415 startX
:= M
.ReadLongInt();
2416 startY
:= M
.ReadLongInt();
2417 endX
:= M
.ReadLongInt();
2418 endY
:= M
.ReadLongInt();
2419 sizeSpX
:= M
.ReadLongInt();
2420 sizeSpY
:= M
.ReadLongInt();
2421 sizeEX
:= M
.ReadLongInt();
2422 sizeEY
:= M
.ReadLongInt();
2423 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2425 TP
:= g_Map_PanelByGUID(PGUID
);
2426 if (TP
= nil) then exit
;
2428 // update lifts state
2429 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2431 // update enabled/disabled state for all panels
2432 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2434 // update panel position, as it can be moved (mplat)
2439 // update mplat state
2440 TP
.movingSpeedX
:= speedX
;
2441 TP
.movingSpeedY
:= speedY
;
2442 TP
.movingStartX
:= startX
;
2443 TP
.movingStartY
:= startY
;
2444 TP
.movingEndX
:= endX
;
2445 TP
.movingEndY
:= endY
;
2446 TP
.sizeSpeedX
:= sizeSpX
;
2447 TP
.sizeSpeedY
:= sizeSpY
;
2448 TP
.sizeEndX
:= sizeEX
;
2449 TP
.sizeEndY
:= sizeEY
;
2450 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2451 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2452 // notify panel of it's position/size change, so it can fix other internal structures
2453 TP
.positionChanged();
2458 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2461 SPos
, SID
: LongWord;
2465 if not gGameOn
then Exit
;
2466 if gTriggers
= nil then Exit
;
2468 SID
:= M
.ReadLongWord();
2469 SPlaying
:= M
.ReadByte() <> 0;
2470 SPos
:= M
.ReadLongWord();
2471 SCount
:= M
.ReadLongInt();
2473 for I
:= Low(gTriggers
) to High(gTriggers
) do
2474 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2475 if gTriggers
[I
].ClientID
= SID
then
2476 with gTriggers
[I
] do
2478 if Sound
<> nil then
2483 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2485 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2486 Sound
.SetPosition(SPos
);
2489 if Sound
.IsPlaying
then Sound
.Stop
;
2492 SoundPlayCount
:= SCount
;
2496 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2503 if not gGameOn
then Exit
;
2505 MName
:= M
.ReadString();
2506 MPlaying
:= M
.ReadByte() <> 0;
2507 MPos
:= M
.ReadLongWord();
2508 MPaused
:= M
.ReadByte() <> 0;
2512 gMusic
.SetByName(MName
);
2514 gMusic
.SetPosition(MPos
);
2515 gMusic
.SpecPause
:= MPaused
;
2518 if gMusic
.IsPlaying
then gMusic
.Stop
;
2523 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2526 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2527 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2532 Mon
:= g_Monsters_ByUID(ID
);
2536 MType
:= M
.ReadByte();
2537 MState
:= M
.ReadByte();
2538 MAnim
:= M
.ReadByte();
2539 MTarg
:= M
.ReadWord();
2540 MTargTime
:= M
.ReadLongInt();
2541 MBehav
:= M
.ReadByte();
2542 MSleep
:= M
.ReadLongInt();
2543 MHealth
:= M
.ReadLongInt();
2544 MAmmo
:= M
.ReadLongInt();
2546 X
:= M
.ReadLongInt();
2547 Y
:= M
.ReadLongInt();
2548 VX
:= M
.ReadLongInt();
2549 VY
:= M
.ReadLongInt();
2550 MDir
:= M
.ReadByte();
2552 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2553 Mon
:= g_Monsters_ByUID(ID
);
2560 MonsterAnim
:= MAnim
;
2561 MonsterTargetUID
:= MTarg
;
2562 MonsterTargetTime
:= MTargTime
;
2563 MonsterBehaviour
:= MBehav
;
2564 MonsterSleep
:= MSleep
;
2565 MonsterAmmo
:= MAmmo
;
2570 setPosition(X
, Y
); // this will call positionChanged();
2576 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2583 Mon
:= g_Monsters_ByUID(ID
);
2589 X
:= M
.ReadLongInt();
2590 Y
:= M
.ReadLongInt();
2591 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2592 GameVelX
:= M
.ReadLongInt();
2593 GameVelY
:= M
.ReadLongInt();
2594 GameDirection
:= TDirection(M
.ReadByte());
2598 procedure MC_RECV_MonsterState(var M
: TMsg
);
2601 MState
, MFAnm
: Byte;
2603 AnimRevert
: Boolean;
2606 Mon
:= g_Monsters_ByUID(ID
);
2607 if Mon
= nil then Exit
;
2609 MState
:= M
.ReadByte();
2610 MFAnm
:= M
.ReadByte();
2614 MonsterTargetUID
:= M
.ReadWord();
2615 MonsterTargetTime
:= M
.ReadLongInt();
2616 MonsterSleep
:= M
.ReadLongInt();
2617 MonsterHealth
:= M
.ReadLongInt();
2618 MonsterAmmo
:= M
.ReadLongInt();
2619 MonsterPain
:= M
.ReadLongInt();
2620 AnimRevert
:= M
.ReadByte() <> 0;
2621 FFireTime
:= M
.ReadLongInt();
2622 RevertAnim(AnimRevert
);
2624 if MonsterState
<> MState
then
2626 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2627 if (MState
= MONSTATE_DIE
) then DieSound();
2628 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2629 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2630 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2632 SetState(MState
, MFAnm
);
2637 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2641 X
, Y
, VX
, VY
: Integer;
2645 Mon
:= g_Monsters_ByUID(ID
);
2646 if Mon
= nil then Exit
;
2648 X
:= M
.ReadLongInt();
2649 Y
:= M
.ReadLongInt();
2650 VX
:= M
.ReadLongInt();
2651 VY
:= M
.ReadLongInt();
2653 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2656 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2662 Mon
:= g_Monsters_ByUID(ID
);
2663 if Mon
= nil then Exit
;
2665 Mon
.MonsterRemoved
:= True;
2668 procedure MC_RECV_TimeSync(var M
: TMsg
);
2672 Time
:= M
.ReadLongWord();
2674 if gState
= STATE_INTERCUSTOM
then
2675 gServInterTime
:= Min(Time
, 255);
2678 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2682 Int1
, Int2
: SmallInt;
2684 EvID
:= M
.ReadByte();
2685 Int1
:= M
.ReadSmallInt();
2686 Int2
:= M
.ReadSmallInt();
2687 Str1
:= M
.ReadString();
2688 Str2
:= M
.ReadString();
2692 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2694 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2696 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2698 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2700 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2706 procedure MC_SEND_Info(Password
: string);
2710 NetOut
.Write(Byte(NET_MSG_INFO
));
2711 NetOut
.Write(GAME_VERSION
);
2712 NetOut
.Write(Password
);
2713 NetOut
.Write(gPlayer1Settings
.Name
);
2714 NetOut
.Write(gPlayer1Settings
.Model
);
2715 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2716 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2717 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2718 NetOut
.Write(gPlayer1Settings
.Team
);
2720 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2723 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2725 NetOut
.Write(Byte(NET_MSG_CHAT
));
2729 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2732 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
2734 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
2735 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
2739 procedure MC_SEND_PlayerPos();
2744 //WeaponSelect: Word = 0;
2747 if not gGameOn
then Exit
;
2748 if gPlayers
= nil then Exit
;
2749 if gPlayer1
= nil then Exit
;
2752 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2754 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2756 strafeDir
:= P1MoveButton
shr 4;
2757 P1MoveButton
:= P1MoveButton
and $0F;
2758 with gGameControls
.P1Control
do
2760 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 1
2761 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then P1MoveButton
:= 2
2762 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 0;
2765 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
2767 // new strafe mechanics
2768 if (strafeDir
= 0) then strafeDir
:= P1MoveButton
; // start strafing
2769 // now set direction according to strafe (reversed)
2770 if (strafeDir
= 2) then gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2771 else if (strafeDir
= 1) then gPlayer1
.SetDirection(TDirection
.D_RIGHT
);
2775 if (P1MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2776 else if (P1MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2777 else if P1MoveButton
<> 0 then gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2780 gPlayer1
.ReleaseKeys
;
2781 gPlayer1
.weaponSwitchKeysStateChange(-1, isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
));
2782 gPlayer1
.weaponSwitchKeysStateChange(-2, isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
));
2784 if P1MoveButton
= 1 then
2786 kByte
:= kByte
or NET_KEY_LEFT
;
2787 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2789 if P1MoveButton
= 2 then
2791 kByte
:= kByte
or NET_KEY_RIGHT
;
2792 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2794 if isKeyPressed(KeyUp
, KeyUp2
) then
2796 kByte
:= kByte
or NET_KEY_UP
;
2797 gPlayer1
.PressKey(KEY_UP
, 10000);
2799 if isKeyPressed(KeyDown
, KeyDown2
) then
2801 kByte
:= kByte
or NET_KEY_DOWN
;
2802 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2804 if isKeyPressed(KeyJump
, KeyJump2
) then
2806 kByte
:= kByte
or NET_KEY_JUMP
;
2807 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2809 if isKeyPressed(KeyFire
, KeyFire2
) then kByte
:= kByte
or NET_KEY_FIRE
;
2810 if isKeyPressed(KeyOpen
, KeyOpen2
) then kByte
:= kByte
or NET_KEY_OPEN
;
2811 // do not send weapon switch keys, `MH_SEND_PlayerStats()` will send changed weapon anyway
2812 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) and gPlayer1
.isWeaponSwitchKeyReleased(-1) then gPlayer1
.PressKey(KEY_NEXTWEAPON
); //kByte := kByte or NET_KEY_NW;
2813 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) and gPlayer1
.isWeaponSwitchKeyReleased(-2) then gPlayer1
.PressKey(KEY_PREVWEAPON
); //kByte := kByte or NET_KEY_PW;
2814 for I
:= 0 to High(KeyWeapon
) do
2816 if isKeyPressed(KeyWeapon
[I
], KeyWeapon2
[I
]) then
2818 gPlayer1
.weaponSwitchKeysStateChange(i
, true);
2819 if gPlayer1
.isWeaponSwitchKeyReleased(i
) then
2821 gPlayer1
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
2822 //WeaponSelect := WeaponSelect or Word(1 shl I);
2827 gPlayer1
.weaponSwitchKeysStateChange(i
, false);
2831 // fix movebutton state
2832 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2835 kByte
:= NET_KEY_CHAT
;
2837 gPlayer1
.weaponSwitchKeysShiftNewStates();
2839 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2840 NetOut
.Write(gTime
);
2841 NetOut
.Write(kByte
);
2842 NetOut
.Write(Byte(gPlayer1
.Direction
));
2843 NetOut
.Write(Byte(gPlayer1
.CurrWeap
));
2844 //NetOut.Write(WeaponSelect);
2845 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2846 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2848 //kBytePrev := kByte;
2849 //kDirPrev := gPlayer1.Direction;
2852 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2854 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2855 NetOut
.Write(Byte(Start
));
2856 NetOut
.Write(Command
);
2857 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2860 procedure MC_SEND_PlayerSettings();
2862 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2863 NetOut
.Write(gPlayer1Settings
.Name
);
2864 NetOut
.Write(gPlayer1Settings
.Model
);
2865 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2866 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2867 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2868 NetOut
.Write(gPlayer1Settings
.Team
);
2870 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2873 procedure MC_SEND_FullStateRequest();
2875 NetOut
.Write(Byte(NET_MSG_REQFST
));
2877 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2880 procedure MC_SEND_CheatRequest(Kind
: Byte);
2882 NetOut
.Write(Byte(NET_MSG_CHEAT
));
2885 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2887 procedure MC_SEND_RCONPassword(Password
: string);
2889 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
2890 NetOut
.Write(Password
);
2892 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2894 procedure MC_SEND_RCONCommand(Cmd
: string);
2896 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
2899 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2902 // i have no idea why all this stuff is in here
2904 function ReadFile(const FileName
: TFileName
): AByte
;
2906 FileStream
: TStream
;
2909 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), TMsgType
.Notify
);
2910 fname
:= findDiskWad(FileName
);
2911 if length(fname
) = 0 then
2913 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), TMsgType
.Fatal
);
2914 SetLength(Result
, 0);
2917 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), TMsgType
.Notify
);
2919 FileStream
:= openDiskFileRO(fname
);
2921 if FileStream
.Size
> 0 then
2923 SetLength(Result
, FileStream
.Size
);
2924 FileStream
.Read(Result
[0], FileStream
.Size
);
2931 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
2935 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
2936 Result
.FileData
:= ReadFile(FileName
);
2937 Result
.FileSize
:= Length(Result
.FileData
);
2939 SetLength(Result
.ExternalResources
, ResList
.Count
);
2940 for i
:=0 to ResList
.Count
-1 do
2942 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
2943 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
2947 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
2949 ResultStream
: TMemoryStream
;
2951 ResultStream
:= TMemoryStream
.Create
;
2953 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
2954 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
2955 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
2957 SetLength(bytes
, ResultStream
.Size
);
2958 ResultStream
.Seek(0, soFromBeginning
);
2959 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2964 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
2966 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
2967 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
2968 SetLength(Result
.FileData
, Result
.FileSize
);
2969 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
2972 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
2974 ResultStream
: TMemoryStream
;
2977 resCount
:= Length(MapDataMsg
.ExternalResources
);
2979 ResultStream
:= TMemoryStream
.Create
;
2981 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
2982 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
2983 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
2985 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
2986 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
2988 SetLength(bytes
, ResultStream
.Size
);
2989 ResultStream
.Seek(0, soFromBeginning
);
2990 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2995 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
2999 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3000 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3002 SetLength(Result
.FileData
, Result
.FileSize
);
3003 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3005 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3006 SetLength(Result
.ExternalResources
, resCount
);
3008 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3011 function IsValidFileName(const S
: String): Boolean;
3013 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3018 for I
:= 1 to Length(S
) do
3019 Result
:= Result
and (not(S
[I
] in Forbidden
));
3022 function IsValidFilePath(const S
: String): Boolean;
3027 if not IsValidFileName(S
) then exit
;
3028 if FileExists(S
) then exit
;
3029 I
:= LastDelimiter('\/', S
);
3031 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3036 procedure MC_SEND_MapRequest();
3038 NetOut
.Write(Byte(NET_MSG_MAP_REQUEST
));
3039 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3042 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3044 NetOut
.Write(Byte(NET_MSG_RES_REQUEST
));
3045 NetOut
.Write(resName
);
3046 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3049 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
3053 mapDataMsg
: TMapDataMsg
;
3055 e_WriteLog('NET: Received map request from ' +
3056 DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3058 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3059 peer
:= NetClients
[C
^.ID
].Peer
;
3061 MapDataMsgToBytes(payload
, mapDataMsg
);
3062 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3065 mapDataMsg
.FileData
:= nil;
3066 mapDataMsg
.ExternalResources
:= nil;
3069 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
3074 resDataMsg
: TResDataMsg
;
3076 FileName
:= ExtractFileName(M
.ReadString());
3077 e_WriteLog('NET: Received res request: ' + FileName
+
3078 ' from ' + DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3080 if not IsValidFilePath(FileName
) then
3082 e_WriteLog('Invalid filename: ' + FileName
, TMsgType
.Warning
);
3086 peer
:= NetClients
[C
^.ID
].Peer
;
3088 if gExternalResources
.IndexOf(FileName
) > -1 then
3090 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3091 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3092 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3094 ResDataMsgToBytes(payload
, resDataMsg
);
3095 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);