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(PType
: Word; PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PanelState(PType
: Word; 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
) + '.', MSG_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
);
646 if gPlayers
<> nil then
648 for I
:= Low(gPlayers
) to High(gPlayers
) do
650 if gPlayers
[I
] <> nil then
652 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
653 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
654 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
656 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
657 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
662 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
663 g_Mons_ForEach(sendMonSpawn
);
665 if gWalls
<> nil then
666 for I
:= Low(gWalls
) to High(gWalls
) do
667 if gWalls
[I
] <> nil then
671 MH_SEND_PanelState(PanelType
, I
, ID
);
673 if GetTextureCount
> 1 then
674 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
677 if gLifts
<> nil then
678 for I
:= Low(gLifts
) to High(gLifts
) do
679 if gLifts
[I
] <> nil then
681 MH_SEND_PanelState(PanelType
, I
, ID
);
683 if gRenderForegrounds
<> nil then
684 for I
:= Low(gRenderForegrounds
) to High(gRenderForegrounds
) do
685 if gRenderForegrounds
[I
] <> nil then
686 with gRenderForegrounds
[I
] do
688 if (GetTextureCount
> 1) then
689 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
691 MH_SEND_PanelState(PanelType
, I
, ID
);
693 if gRenderBackgrounds
<> nil then
694 for I
:= Low(gRenderBackgrounds
) to High(gRenderBackgrounds
) do
695 if gRenderBackgrounds
[I
] <> nil then
696 with gRenderBackgrounds
[I
] do
698 if (GetTextureCount
> 1) then
699 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
701 MH_SEND_PanelState(PanelType
, I
, ID
);
703 if gWater
<> nil then
704 for I
:= Low(gWater
) to High(gWater
) do
705 if gWater
[I
] <> nil then
707 if GetTextureCount
> 1 then
708 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
709 if gAcid1
<> nil then
710 for I
:= Low(gAcid1
) to High(gAcid1
) do
711 if gAcid1
[I
] <> nil then
713 if GetTextureCount
> 1 then
714 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
715 if gAcid2
<> nil then
716 for I
:= Low(gAcid2
) to High(gAcid2
) do
717 if gAcid2
[I
] <> nil then
719 if GetTextureCount
> 1 then
720 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
721 if gSteps
<> nil then
722 for I
:= Low(gSteps
) to High(gSteps
) do
723 if gSteps
[I
] <> nil then
725 if GetTextureCount
> 1 then
726 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
728 if gTriggers
<> nil then
729 for I
:= Low(gTriggers
) to High(gTriggers
) do
730 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
731 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
734 for I
:= Low(Shots
) to High(Shots
) do
735 if Shots
[i
].ShotType
in [6, 7, 8] then
736 MH_SEND_CreateShot(i
, ID
);
738 MH_SEND_TriggerMusic(ID
);
740 MH_SEND_GameStats(ID
);
741 MH_SEND_CoopStats(ID
);
743 if gGameSettings
.GameMode
= GM_CTF
then
745 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then
746 MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
747 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then
748 MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
751 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
753 if gLMSRespawn
> LMS_RESPAWN_NONE
then
754 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
757 procedure MH_SEND_Info(ID
: Byte);
761 Map
:= g_ExtractFileName(gMapInfo
.Map
);
765 NetOut
.Write(Byte(NET_MSG_INFO
));
767 NetOut
.Write(NetClients
[ID
].Player
);
768 NetOut
.Write(gGameSettings
.WAD
);
770 NetOut
.Write(gWADHash
);
771 NetOut
.Write(gGameSettings
.GameMode
);
772 NetOut
.Write(gGameSettings
.GoalLimit
);
773 NetOut
.Write(gGameSettings
.TimeLimit
);
774 NetOut
.Write(gGameSettings
.MaxLives
);
775 NetOut
.Write(gGameSettings
.Options
);
778 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
781 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
787 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
788 Mode
:= NET_CHAT_PLAYER
;
791 if (Mode
= NET_CHAT_TEAM
) then
793 for i
:= Low(gPlayers
) to High(gPlayers
) do
794 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
795 (gPlayers
[i
].Team
= ID
) then
797 NetOut
.Write(Byte(NET_MSG_CHAT
));
800 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
807 NetOut
.Write(Byte(NET_MSG_CHAT
));
810 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
813 if Mode
= NET_CHAT_SYSTEM
then
816 if ID
= NET_EVERYONE
then
818 if Mode
= NET_CHAT_PLAYER
then
820 g_Console_Add(Txt
, True);
821 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
822 g_Sound_PlayEx('SOUND_GAME_RADIO');
825 if Mode
= NET_CHAT_TEAM
then
826 if gPlayer1
<> nil then
828 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
830 g_Console_Add(#18'[Team] '#2 + Txt
, True);
831 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
832 g_Sound_PlayEx('SOUND_GAME_RADIO');
834 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
836 g_Console_Add(#20'[Team] '#2 + Txt
, True);
837 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
838 g_Sound_PlayEx('SOUND_GAME_RADIO');
844 Name
:= g_Net_ClientName_ByID(ID
);
845 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
846 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
847 g_Sound_PlayEx('SOUND_GAME_RADIO');
851 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
853 NetOut
.Write(Byte(NET_MSG_GFX
));
859 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
862 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
864 NetOut
.Write(Byte(NET_MSG_SND
));
868 NetOut
.Write(Byte(1));
873 NetOut
.Write(Byte(0));
875 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
878 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
880 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
882 NetOut
.Write(Byte(NET_MSG_SHADD
));
884 NetOut
.Write(Shots
[Proj
].ShotType
);
885 NetOut
.Write(Shots
[Proj
].Target
);
886 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
887 NetOut
.Write(Shots
[Proj
].Timeout
);
888 NetOut
.Write(Shots
[Proj
].Obj
.X
);
889 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
890 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
891 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
893 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
896 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
898 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
900 NetOut
.Write(Byte(NET_MSG_SHPOS
));
902 NetOut
.Write(Shots
[Proj
].Obj
.X
);
903 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
904 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
905 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
907 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
910 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
912 NetOut
.Write(Byte(NET_MSG_SHDEL
));
914 NetOut
.Write(Byte(Loud
));
918 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
921 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
923 NetOut
.Write(Byte(NET_MSG_SCORE
));
924 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
926 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
927 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
930 if gGameSettings
.GameMode
= GM_COOP
then
932 NetOut
.Write(gCoopMonstersKilled
);
933 NetOut
.Write(gCoopSecretsFound
);
936 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
939 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
941 NetOut
.Write(Byte(NET_MSG_COOP
));
942 NetOut
.Write(gTotalMonsters
);
943 NetOut
.Write(gSecretsCount
);
944 NetOut
.Write(gCoopTotalMonstersKilled
);
945 NetOut
.Write(gCoopTotalSecretsFound
);
946 NetOut
.Write(gCoopTotalMonsters
);
947 NetOut
.Write(gCoopTotalSecrets
);
950 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
952 NetOut
.Write(Byte(NET_MSG_GEVENT
));
953 NetOut
.Write(EvType
);
956 NetOut
.Write(Byte(gLastMap
));
958 if (EvType
= NET_EV_MAPSTART
) and (Pos(':\', EvStr
) > 0) then
960 NetOut
.Write(Byte(1));
961 NetOut
.Write(gWADHash
);
963 NetOut
.Write(Byte(0));
965 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
968 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
970 NetOut
.Write(Byte(NET_MSG_FLAG
));
971 NetOut
.Write(EvType
);
973 NetOut
.Write(Byte(Quiet
));
975 NetOut
.Write(gFlags
[Flag
].State
);
976 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
977 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
978 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
979 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
980 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
982 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
985 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
987 NetOut
.Write(Byte(NET_MSG_GSET
));
988 NetOut
.Write(gGameSettings
.GameMode
);
989 NetOut
.Write(gGameSettings
.GoalLimit
);
990 NetOut
.Write(gGameSettings
.TimeLimit
);
991 NetOut
.Write(gGameSettings
.MaxLives
);
992 NetOut
.Write(gGameSettings
.Options
);
994 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
999 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1003 P
:= g_Player_Get(PID
);
1004 if P
= nil then Exit
;
1006 NetOut
.Write(Byte(NET_MSG_PLR
));
1008 NetOut
.Write(P
.Name
);
1010 NetOut
.Write(P
.FActualModelName
);
1011 NetOut
.Write(P
.FColor
.R
);
1012 NetOut
.Write(P
.FColor
.G
);
1013 NetOut
.Write(P
.FColor
.B
);
1014 NetOut
.Write(P
.Team
);
1016 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1019 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1024 Pl
:= g_Player_Get(PID
);
1025 if Pl
= nil then Exit
;
1026 if Pl
.FDummy
then Exit
;
1028 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1029 NetOut
.Write(gTime
);
1036 NetOut
.Write(FPing
);
1037 NetOut
.Write(FLoss
);
1038 if IsKeyPressed(KEY_CHAT
) then
1039 kByte
:= NET_KEY_CHAT
1042 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1043 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1044 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1045 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1046 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1047 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1050 NetOut
.Write(kByte
);
1051 if Direction
= D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1052 NetOut
.Write(GameX
);
1053 NetOut
.Write(GameY
);
1054 NetOut
.Write(GameVelX
);
1055 NetOut
.Write(GameVelY
);
1056 NetOut
.Write(GameAccelX
);
1057 NetOut
.Write(GameAccelY
);
1060 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1063 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1068 P
:= g_Player_Get(PID
);
1069 if P
= nil then Exit
;
1071 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1076 NetOut
.Write(Byte(Live
));
1077 NetOut
.Write(Byte(GodMode
));
1078 NetOut
.Write(Health
);
1079 NetOut
.Write(Armor
);
1081 NetOut
.Write(JetFuel
);
1082 NetOut
.Write(Lives
);
1085 for I
:= WP_FIRST
to WP_LAST
do
1086 NetOut
.Write(Byte(FWeapon
[I
]));
1088 for I
:= A_BULLETS
to A_HIGH
do
1089 NetOut
.Write(FAmmo
[I
]);
1091 for I
:= A_BULLETS
to A_HIGH
do
1092 NetOut
.Write(FMaxAmmo
[I
]);
1094 for I
:= MR_SUIT
to MR_MAX
do
1095 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1097 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1098 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1099 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1100 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1101 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1103 NetOut
.Write(Frags
);
1104 NetOut
.Write(Death
);
1106 NetOut
.Write(CurrWeap
);
1108 NetOut
.Write(Byte(FSpectator
));
1109 NetOut
.Write(Byte(FGhost
));
1110 NetOut
.Write(Byte(FPhysics
));
1111 NetOut
.Write(Byte(FNoRespawn
));
1112 NetOut
.Write(Byte(FJetpack
));
1113 NetOut
.Write(FFireTime
);
1116 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1119 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1121 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1124 NetOut
.Write(Attacker
);
1125 NetOut
.Write(Value
);
1129 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1132 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1134 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1136 NetOut
.Write(KillType
);
1137 NetOut
.Write(DeathType
);
1138 NetOut
.Write(Attacker
);
1140 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1143 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1145 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1147 NetOut
.Write(Weapon
);
1152 NetOut
.Write(ShotID
);
1154 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1157 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1159 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1162 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1165 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1169 Pl
:= g_Player_Get(PID
);
1170 if Pl
= nil then Exit
;
1172 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1174 NetOut
.Write(Pl
.Name
);
1176 NetOut
.Write(Pl
.Model
.Name
)
1179 NetOut
.Write(Pl
.FColor
.R
);
1180 NetOut
.Write(Pl
.FColor
.G
);
1181 NetOut
.Write(Pl
.FColor
.B
);
1182 NetOut
.Write(Pl
.Team
);
1184 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1189 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1193 it
:= g_Items_ByIdx(IID
);
1195 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1197 NetOut
.Write(Byte(Quiet
));
1198 NetOut
.Write(it
.ItemType
);
1199 NetOut
.Write(Byte(it
.Fall
));
1200 NetOut
.Write(Byte(it
.Respawnable
));
1201 NetOut
.Write(it
.Obj
.X
);
1202 NetOut
.Write(it
.Obj
.Y
);
1203 NetOut
.Write(it
.Obj
.Vel
.X
);
1204 NetOut
.Write(it
.Obj
.Vel
.Y
);
1206 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1209 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1211 NetOut
.Write(Byte(NET_MSG_IDEL
));
1213 NetOut
.Write(Byte(Quiet
));
1215 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1220 procedure MH_SEND_PanelTexture(PType
: Word; PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1224 TP
:= g_Map_PanelByGUID(PGUID
);
1225 if (TP
= nil) then exit
;
1228 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
1231 TP := gRenderForegrounds[PID];
1233 TP := gRenderBackgrounds[PID];
1249 NetOut
.Write(Byte(NET_MSG_PTEX
));
1250 NetOut
.Write(PType
);
1251 NetOut
.Write(LongWord(PGUID
));
1252 NetOut
.Write(FCurTexture
);
1253 NetOut
.Write(FCurFrame
);
1254 NetOut
.Write(FCurFrameCount
);
1255 NetOut
.Write(AnimLoop
);
1258 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1261 procedure MH_SEND_PanelState(PType
: Word; PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1265 TP
:= g_Map_PanelByGUID(PGUID
);
1266 if (TP
= nil) then exit
;
1269 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: TP := gWalls[PID];
1270 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT: TP := gLifts[PID];
1274 //TP := gRenderBackgrounds[PID];
1279 //TP := gRenderForegrounds[PID];
1288 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1289 NetOut
.Write(PType
);
1290 NetOut
.Write(LongWord(PGUID
));
1291 NetOut
.Write(Byte(TP
.Enabled
));
1292 NetOut
.Write(TP
.LiftType
);
1296 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1301 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1303 if gTriggers
= nil then Exit
;
1304 if T
.Sound
= nil then Exit
;
1306 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1307 NetOut
.Write(T
.ClientID
);
1308 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1309 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1310 NetOut
.Write(T
.SoundPlayCount
);
1312 g_Net_Host_Send(ID
, True);
1315 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1317 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1318 NetOut
.Write(gMusic
.Name
);
1319 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1320 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1321 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1323 g_Net_Host_Send(ID
, True);
1328 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1332 M
:= g_Monsters_ByUID(UID
);
1338 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1340 NetOut
.Write(MonsterType
);
1341 NetOut
.Write(MonsterState
);
1342 NetOut
.Write(MonsterAnim
);
1343 NetOut
.Write(MonsterTargetUID
);
1344 NetOut
.Write(MonsterTargetTime
);
1345 NetOut
.Write(MonsterBehaviour
);
1346 NetOut
.Write(MonsterSleep
);
1347 NetOut
.Write(MonsterHealth
);
1348 NetOut
.Write(MonsterAmmo
);
1349 NetOut
.Write(GameX
);
1350 NetOut
.Write(GameY
);
1351 NetOut
.Write(GameVelX
);
1352 NetOut
.Write(GameVelY
);
1353 NetOut
.Write(Byte(GameDirection
));
1356 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1359 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1363 M
:= g_Monsters_ByUID(UID
);
1364 if M
= nil then Exit
;
1366 NetOut
.Write(Byte(NET_MSG_MPOS
));
1371 NetOut
.Write(GameX
);
1372 NetOut
.Write(GameY
);
1373 NetOut
.Write(GameVelX
);
1374 NetOut
.Write(GameVelY
);
1375 NetOut
.Write(Byte(GameDirection
));
1378 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1381 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1385 M
:= g_Monsters_ByUID(UID
);
1386 if M
= nil then Exit
;
1388 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1393 NetOut
.Write(MonsterState
);
1394 NetOut
.Write(ForcedAnim
);
1395 NetOut
.Write(MonsterTargetUID
);
1396 NetOut
.Write(MonsterTargetTime
);
1397 NetOut
.Write(MonsterSleep
);
1398 NetOut
.Write(MonsterHealth
);
1399 NetOut
.Write(MonsterAmmo
);
1400 NetOut
.Write(MonsterPain
);
1401 NetOut
.Write(Byte(AnimIsReverse
));
1402 NetOut
.Write(FFireTime
);
1405 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1408 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1410 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1417 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1420 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1424 M
:= g_Monsters_ByUID(UID
);
1425 if M
= nil then Exit
;
1427 NetOut
.Write(Byte(NET_MSG_MDEL
));
1430 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1435 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1437 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1440 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1443 procedure MH_SEND_VoteEvent(EvType
: Byte;
1444 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1445 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1446 ID
: Integer = NET_EVERYONE
);
1448 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1449 NetOut
.Write(EvType
);
1450 NetOut
.Write(IntArg1
);
1451 NetOut
.Write(IntArg2
);
1452 NetOut
.Write(StrArg1
);
1453 NetOut
.Write(StrArg2
);
1455 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1458 // CLIENT MESSAGES //
1462 procedure MC_RECV_Chat(var M
: TMsg
);
1467 Txt
:= M
.ReadString();
1468 Mode
:= M
.ReadByte();
1470 if Mode
<> NET_CHAT_SYSTEM
then
1472 if Mode
= NET_CHAT_PLAYER
then
1474 g_Console_Add(Txt
, True);
1475 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1476 g_Sound_PlayEx('SOUND_GAME_RADIO');
1478 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1480 if gPlayer1
.Team
= TEAM_RED
then
1481 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1482 if gPlayer1
.Team
= TEAM_BLUE
then
1483 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1484 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1485 g_Sound_PlayEx('SOUND_GAME_RADIO');
1488 g_Console_Add(Txt
, True);
1491 procedure MC_RECV_Effect(var M
: TMsg
);
1499 if not gGameOn
then Exit
;
1500 Kind
:= M
.ReadByte();
1501 X
:= M
.ReadLongInt();
1502 Y
:= M
.ReadLongInt();
1503 Ang
:= M
.ReadSmallInt();
1507 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1511 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1513 Anim
:= TAnimation
.Create(ID
, False, 3);
1514 g_GFX_OnceAnim(X
, Y
, Anim
);
1518 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1523 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1525 Anim
:= TAnimation
.Create(ID
, False, 6);
1526 Anim
.Blending
:= False;
1527 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1531 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1536 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1538 Anim
:= TAnimation
.Create(ID
, False, 6);
1539 Anim
.Blending
:= False;
1540 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1544 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1549 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1551 Anim
:= TAnimation
.Create(ID
, False, 4);
1552 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1559 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1561 Anim
:= TAnimation
.Create(ID
, False, 4);
1562 g_GFX_OnceAnim(X
, Y
, Anim
);
1566 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1571 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1573 Anim
:= TAnimation
.Create(ID
, False, 4);
1574 g_GFX_OnceAnim(X
, Y
, Anim
);
1578 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1582 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1585 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1589 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1590 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1595 procedure MC_RECV_Sound(var M
: TMsg
);
1601 Name
:= M
.ReadString();
1602 Pos
:= M
.ReadByte() <> 0;
1605 X
:= M
.ReadLongInt();
1606 Y
:= M
.ReadLongInt();
1607 g_Sound_PlayExAt(Name
, X
, Y
);
1610 g_Sound_PlayEx(Name
);
1613 procedure MC_RECV_CreateShot(var M
: TMsg
);
1615 I
, X
, Y
, XV
, YV
: Integer;
1617 Target
, Spawner
: Word;
1620 I
:= M
.ReadLongInt();
1621 ShType
:= M
.ReadByte();
1622 Target
:= M
.ReadWord();
1623 Spawner
:= M
.ReadWord();
1624 Timeout
:= M
.ReadLongWord();
1625 X
:= M
.ReadLongInt();
1626 Y
:= M
.ReadLongInt();
1627 XV
:= M
.ReadLongInt();
1628 YV
:= M
.ReadLongInt();
1630 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1631 if (Shots
<> nil) and (I
<= High(Shots
)) then
1633 Shots
[I
].Timeout
:= Timeout
;
1634 //Shots[I].Target := Target; // TODO: find a use for Target later
1638 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1640 I
, TX
, TY
, TXV
, TYV
: Integer;
1642 I
:= M
.ReadLongInt();
1643 TX
:= M
.ReadLongInt();
1644 TY
:= M
.ReadLongInt();
1645 TXV
:= M
.ReadLongInt();
1646 TYV
:= M
.ReadLongInt();
1648 if (Shots
<> nil) and (I
<= High(Shots
)) then
1658 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1663 if not gGameOn
then Exit
;
1664 I
:= M
.ReadLongInt();
1665 L
:= (M
.ReadByte() <> 0);
1666 X
:= M
.ReadLongInt();
1667 Y
:= M
.ReadLongInt();
1669 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1672 procedure MC_RECV_GameStats(var M
: TMsg
);
1674 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1676 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1677 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1680 if gGameSettings
.GameMode
= GM_COOP
then
1682 gCoopMonstersKilled
:= M
.ReadWord();
1683 gCoopSecretsFound
:= M
.ReadWord();
1687 procedure MC_RECV_CoopStats(var M
: TMsg
);
1689 gTotalMonsters
:= M
.ReadLongInt();
1690 gSecretsCount
:= M
.ReadLongInt();
1691 gCoopTotalMonstersKilled
:= M
.ReadWord();
1692 gCoopTotalSecretsFound
:= M
.ReadWord();
1693 gCoopTotalMonsters
:= M
.ReadWord();
1694 gCoopTotalSecrets
:= M
.ReadWord();
1697 procedure MC_RECV_GameEvent(var M
: TMsg
);
1706 i1
, i2
: TStrings_Locale
;
1710 FillChar(EvHash
, Sizeof(EvHash
), 0);
1711 EvType
:= M
.ReadByte();
1712 EvNum
:= M
.ReadLongInt();
1713 EvStr
:= M
.ReadString();
1714 gLastMap
:= M
.ReadByte() <> 0;
1715 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1716 gStatsPressed
:= True;
1717 EvTime
:= M
.ReadLongWord();
1718 BHash
:= M
.ReadByte() <> 0;
1720 EvHash
:= M
.ReadMD5();
1728 g_Game_ClearLoading();
1729 g_Game_StopAllSounds(True);
1731 gSwitchGameMode
:= Byte(EvNum
);
1732 gGameSettings
.GameMode
:= gSwitchGameMode
;
1735 if not g_Game_StartMap(EvStr
, True) then
1737 if Pos(':\', EvStr
) = 0 then
1738 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1740 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1744 MC_SEND_FullStateRequest
;
1749 gMissionFailed
:= EvNum
<> 0;
1750 gExit
:= EXIT_ENDLEVELCUSTOM
;
1757 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1759 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1761 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1767 if EvNum
= TEAM_RED
then
1768 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1769 if EvNum
= TEAM_BLUE
then
1770 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1774 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1777 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1780 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1782 NET_EV_LMS_SURVIVOR
:
1783 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1786 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1790 pl
:= g_Player_Get(EvNum
and $FFFF);
1795 cnt
:= (EvNum
shr 16) and $FF;
1796 if Pos('w', EvStr
) = 0 then
1799 if Pos('t', EvStr
) = 0 then
1802 if Pos('-', EvStr
) = 0 then
1804 if Pos('e', EvStr
) = 0 then
1805 i1
:= I_PLAYER_SCORE_ADD_OWN
1807 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1810 if Pos('e', EvStr
) = 0 then
1811 i1
:= I_PLAYER_SCORE_SUB_OWN
1813 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1816 if Pos('r', EvStr
) > 0 then
1817 i2
:= I_PLAYER_SCORE_TO_RED
1819 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1820 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1824 if Pos('-', EvStr
) = 0 then
1825 i1
:= I_PLAYER_SCORE_ADD_TEAM
1827 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1829 if Pos('r', EvStr
) > 0 then
1830 i2
:= I_PLAYER_SCORE_RED
1832 i2
:= I_PLAYER_SCORE_BLUE
;
1833 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1838 if Pos('e', EvStr
) = 0 then
1839 i1
:= I_PLAYER_SCORE_WIN_OWN
1841 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1843 if Pos('r', EvStr
) > 0 then
1844 i2
:= I_PLAYER_SCORE_TO_RED
1846 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1847 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1853 if EvNum
= TEAM_RED
then
1854 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1855 if EvNum
= TEAM_BLUE
then
1856 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1857 if EvNum
= -TEAM_RED
then
1858 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1859 if EvNum
= -TEAM_BLUE
then
1860 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1865 g_Player_RemoveAllCorpses
;
1866 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1870 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1874 if EvNum
= TEAM_RED
then
1875 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1876 if EvNum
= TEAM_BLUE
then
1877 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1881 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1884 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1887 g_Game_Announce_KillCombo(EvNum
);
1889 NET_EV_PLAYER_TOUCH
:
1891 pl
:= g_Player_Get(EvNum
);
1899 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1908 EvType
:= M
.ReadByte();
1911 if Fl
= FLAG_NONE
then Exit
;
1913 Quiet
:= (M
.ReadByte() <> 0);
1914 PID
:= M
.ReadWord();
1916 gFlags
[Fl
].State
:= M
.ReadByte();
1917 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1918 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1919 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1920 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1921 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1923 Pl
:= g_Player_Get(PID
);
1925 (EvType
<> FLAG_STATE_NORMAL
) and
1926 (EvType
<> FLAG_STATE_DROPPED
) and
1927 (EvType
<> FLAG_STATE_RETURNED
) then
1933 if Quiet
or (Pl
= nil) then Exit
;
1935 if Fl
= FLAG_RED
then
1936 s
:= _lc
[I_PLAYER_FLAG_RED
]
1938 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1940 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1943 FLAG_STATE_CAPTURED
:
1945 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1949 if Fl
= FLAG_RED
then
1950 s
:= _lc
[I_PLAYER_FLAG_RED
]
1952 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1954 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1955 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1960 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1962 if Quiet
or (Pl
= nil) then Exit
;
1964 if Fl
= FLAG_RED
then
1965 s
:= _lc
[I_PLAYER_FLAG_RED
]
1967 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1969 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1970 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1975 g_Map_ResetFlag(FLAG_RED
);
1976 g_Map_ResetFlag(FLAG_BLUE
);
1977 if Quiet
or (Pl
= nil) then Exit
;
1978 Pl
.SetFlag(FLAG_NONE
);
1980 if Fl
= FLAG_RED
then
1981 s
:= _lc
[I_PLAYER_FLAG_RED
]
1983 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1985 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1986 Insert('.', ts
, Length(ts
) + 1 - 3);
1987 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1988 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1991 FLAG_STATE_RETURNED
:
1993 g_Map_ResetFlag(Fl
);
1996 if Fl
= FLAG_RED
then
1997 s
:= _lc
[I_PLAYER_FLAG_RED
]
1999 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2001 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2006 procedure MC_RECV_GameSettings(var M
: TMsg
);
2008 gGameSettings
.GameMode
:= M
.ReadByte();
2009 gGameSettings
.GoalLimit
:= M
.ReadWord();
2010 gGameSettings
.TimeLimit
:= M
.ReadWord();
2011 gGameSettings
.MaxLives
:= M
.ReadByte();
2012 gGameSettings
.Options
:= M
.ReadLongWord();
2017 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2020 PName
, Model
: string;
2025 PID
:= M
.ReadWord();
2026 Pl
:= g_Player_Get(PID
);
2028 PName
:= M
.ReadString();
2029 Model
:= M
.ReadString();
2030 Color
.R
:= M
.ReadByte();
2031 Color
.G
:= M
.ReadByte();
2032 Color
.B
:= M
.ReadByte();
2036 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2038 if (Pl
<> nil) then Exit
;
2039 DID
:= g_Player_Create(Model
, Color
, T
, False);
2040 with g_Player_Get(DID
) do
2049 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2050 gPlayer1
.UID
:= PID
;
2051 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2052 gPlayer1
.ChangeTeam(T
);
2054 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2055 gPlayer2
.UID
:= PID
;
2056 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2057 gPlayer2
.ChangeTeam(T
);
2061 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2062 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', MSG_NOTIFY
);
2066 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2073 TmpX
, TmpY
: Integer;
2077 GT
:= M
.ReadLongWord();
2078 if GT
< gTime
- NET_MAX_DIFFTIME
then
2085 PID
:= M
.ReadWord();
2086 Pl
:= g_Player_Get(PID
);
2088 if Pl
= nil then Exit
;
2094 FPing
:= M
.ReadWord();
2095 FLoss
:= M
.ReadByte();
2096 kByte
:= M
.ReadWord();
2097 Dir
:= M
.ReadByte();
2099 TmpX
:= M
.ReadLongInt();
2100 TmpY
:= M
.ReadLongInt();
2104 if (kByte
= NET_KEY_CHAT
) then
2105 PressKey(KEY_CHAT
, 10000)
2108 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2109 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2110 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2111 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2112 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2115 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2116 SetDirection(TDirection(Dir
));
2118 GameVelX
:= M
.ReadLongInt();
2119 GameVelY
:= M
.ReadLongInt();
2120 GameAccelX
:= M
.ReadLongInt();
2121 GameAccelY
:= M
.ReadLongInt();
2122 SetLerp(TmpX
, TmpY
);
2123 if NetForcePlayerUpdate
then Update();
2127 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2135 PID
:= M
.ReadWord();
2136 Pl
:= g_Player_Get(PID
);
2143 Live
:= (M
.ReadByte() <> 0);
2144 GodMode
:= (M
.ReadByte() <> 0);
2145 Health
:= M
.ReadLongInt();
2146 Armor
:= M
.ReadLongInt();
2147 Air
:= M
.ReadLongInt();
2148 JetFuel
:= M
.ReadLongInt();
2149 Lives
:= M
.ReadByte();
2150 NewTeam
:= M
.ReadByte();
2152 for I
:= WP_FIRST
to WP_LAST
do
2153 FWeapon
[I
] := (M
.ReadByte() <> 0);
2155 for I
:= A_BULLETS
to A_HIGH
do
2156 FAmmo
[I
] := M
.ReadWord();
2158 for I
:= A_BULLETS
to A_HIGH
do
2159 FMaxAmmo
[I
] := M
.ReadWord();
2161 for I
:= MR_SUIT
to MR_MAX
do
2162 FMegaRulez
[I
] := M
.ReadLongWord();
2165 if (M
.ReadByte() <> 0) then
2166 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2167 if (M
.ReadByte() <> 0) then
2168 FRulez
:= FRulez
+ [R_KEY_RED
];
2169 if (M
.ReadByte() <> 0) then
2170 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2171 if (M
.ReadByte() <> 0) then
2172 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2173 if (M
.ReadByte() <> 0) then
2174 FRulez
:= FRulez
+ [R_BERSERK
];
2176 Frags
:= M
.ReadLongInt();
2177 Death
:= M
.ReadLongInt();
2179 SetWeapon(M
.ReadByte());
2181 FSpectator
:= M
.ReadByte() <> 0;
2184 if Pl
= gPlayer1
then
2189 if Pl
= gPlayer2
then
2197 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2198 gPlayer1
:= g_Player_Get(gLMSPID1
);
2199 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2200 gPlayer2
:= g_Player_Get(gLMSPID2
);
2202 FGhost
:= M
.ReadByte() <> 0;
2203 FPhysics
:= M
.ReadByte() <> 0;
2204 FNoRespawn
:= M
.ReadByte() <> 0;
2206 FJetpack
:= M
.ReadByte() <> 0;
2207 FFireTime
:= M
.ReadLongInt();
2208 if OldJet
and not FJetpack
then
2210 else if not OldJet
and FJetpack
then
2212 if Team
<> NewTeam
then
2213 Pl
.ChangeTeam(NewTeam
);
2219 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2224 Attacker
, Value
: Word;
2228 if not gGameOn
then Exit
;
2229 PID
:= M
.ReadWord();
2230 Pl
:= g_Player_Get(PID
);
2231 if Pl
= nil then Exit
;
2233 Kind
:= M
.ReadByte();
2234 Attacker
:= M
.ReadWord();
2235 Value
:= M
.ReadWord();
2240 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2245 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2249 KillType
, DeathType
: Byte;
2253 if not gGameOn
then Exit
;
2254 PID
:= M
.ReadWord();
2255 Pl
:= g_Player_Get(PID
);
2256 if Pl
= nil then Exit
;
2258 KillType
:= M
.ReadByte();
2259 DeathType
:= M
.ReadByte();
2260 Attacker
:= M
.ReadWord();
2264 Kill(KillType
, Attacker
, DeathType
);
2269 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2274 PID
:= M
.ReadWord();
2275 Pl
:= g_Player_Get(PID
);
2277 if Pl
= nil then Exit
;
2279 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2280 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', MSG_NOTIFY
);
2282 g_Player_Remove(PID
);
2287 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2292 X
, Y
, AX
, AY
: Integer;
2296 if not gGameOn
then Exit
;
2297 PID
:= M
.ReadWord();
2298 Pl
:= g_Player_Get(PID
);
2299 if Pl
= nil then Exit
;
2301 Weap
:= M
.ReadByte();
2302 X
:= M
.ReadLongInt();
2303 Y
:= M
.ReadLongInt();
2304 AX
:= M
.ReadLongInt();
2305 AY
:= M
.ReadLongInt();
2306 SHID
:= M
.ReadLongInt();
2309 if Live
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2312 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2321 PID
:= M
.ReadWord();
2322 Pl
:= g_Player_Get(PID
);
2323 if Pl
= nil then Exit
;
2325 TmpName
:= M
.ReadString();
2326 TmpModel
:= M
.ReadString();
2327 TmpColor
.R
:= M
.ReadByte();
2328 TmpColor
.G
:= M
.ReadByte();
2329 TmpColor
.B
:= M
.ReadByte();
2330 TmpTeam
:= M
.ReadByte();
2332 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2334 Pl
.ChangeTeam(TmpTeam
);
2335 if gPlayer1
= Pl
then
2336 gPlayer1Settings
.Team
:= TmpTeam
;
2337 if gPlayer2
= Pl
then
2338 gPlayer2Settings
.Team
:= TmpTeam
;
2340 Pl
.SetColor(TmpColor
);
2342 if Pl
.Name
<> TmpName
then
2344 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2348 if TmpModel
<> Pl
.Model
.Name
then
2349 Pl
.SetModel(TmpModel
);
2354 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2358 X
, Y
, VX
, VY
: Integer;
2360 Quiet
, Fall
{, Resp}: Boolean;
2364 if not gGameOn
then Exit
;
2366 Quiet
:= M
.ReadByte() <> 0;
2368 Fall
:= M
.ReadByte() <> 0;
2369 {Resp :=} M
.ReadByte();
2370 X
:= M
.ReadLongInt();
2371 Y
:= M
.ReadLongInt();
2372 VX
:= M
.ReadLongInt();
2373 VY
:= M
.ReadLongInt();
2375 g_Items_Create(X
, Y
, T
, Fall
, False, False, ID
);
2377 it
:= g_Items_ByIdx(ID
);
2383 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2384 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2386 Anim
:= TAnimation
.Create(AID
, False, 4);
2387 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2393 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2398 if not gGameOn
then Exit
;
2400 Quiet
:= M
.ReadByte() <> 0;
2402 if not g_Items_ValidId(ID
) then exit
;
2404 if not Quiet
then g_Items_EmitPickupSound(ID
);
2411 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2419 if not gGameOn
then Exit
;
2420 {PType :=} M
.ReadWord();
2421 PGUID
:= Integer(M
.ReadLongWord());
2422 Tex
:= M
.ReadLongInt();
2423 Fr
:= M
.ReadLongInt();
2424 Cnt
:= M
.ReadByte();
2425 Loop
:= M
.ReadByte();
2427 TP
:= g_Map_PanelByGUID(PGUID
);
2431 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: if gWalls <> nil then TP := gWalls[ID];
2432 PANEL_FORE: if gRenderForegrounds <> nil then TP := gRenderForegrounds[ID];
2433 PANEL_BACK: if gRenderBackgrounds <> nil then TP := gRenderBackgrounds[ID];
2434 PANEL_WATER: if gWater <> nil then TP := gWater[ID];
2435 PANEL_ACID1: if gAcid1 <> nil then TP := gAcid1[ID];
2436 PANEL_ACID2: if gAcid2 <> nil then TP := gAcid2[ID];
2437 PANEL_STEP: if gSteps <> nil then TP := gSteps[ID];
2447 TP
.SetTexture(Tex
, Loop
);
2448 TP
.SetFrame(Fr
, Cnt
);
2452 // looped or non-looped animation
2453 TP
.NextTexture(Loop
);
2458 procedure MC_RECV_PanelState(var M
: TMsg
);
2467 if not gGameOn
then Exit
;
2468 PType
:= M
.ReadWord();
2469 PGUID
:= Integer(M
.ReadLongWord());
2470 E
:= (M
.ReadByte() <> 0);
2471 Lift
:= M
.ReadByte();
2472 X
:= M
.ReadLongInt();
2473 Y
:= M
.ReadLongInt();
2476 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2477 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2479 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
2480 g_Map_SetLiftGUID(PGUID
, Lift
);
2486 TP
:= g_Map_PanelByGUID(PGUID
);
2491 TP
.positionChanged();
2493 //gRenderBackgrounds[ID].X := X;
2494 //gRenderBackgrounds[ID].Y := Y;
2500 gRenderForegrounds[ID].X := X;
2501 gRenderForegrounds[ID].Y := Y;
2509 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2512 SPos
, SID
: LongWord;
2516 if not gGameOn
then Exit
;
2517 if gTriggers
= nil then Exit
;
2519 SID
:= M
.ReadLongWord();
2520 SPlaying
:= M
.ReadByte() <> 0;
2521 SPos
:= M
.ReadLongWord();
2522 SCount
:= M
.ReadLongInt();
2524 for I
:= Low(gTriggers
) to High(gTriggers
) do
2525 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2526 if gTriggers
[I
].ClientID
= SID
then
2527 with gTriggers
[I
] do
2531 if trigData
.trigLocal
then
2532 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), trigData
.trigVolume
/255.0)
2534 Sound
.PlayPanVolume((trigData
.trigPan
-127.0)/128.0, trigData
.trigVolume
/255.0);
2535 Sound
.SetPosition(SPos
);
2538 if Sound
.IsPlaying
then Sound
.Stop
;
2540 SoundPlayCount
:= SCount
;
2544 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2551 if not gGameOn
then Exit
;
2553 MName
:= M
.ReadString();
2554 MPlaying
:= M
.ReadByte() <> 0;
2555 MPos
:= M
.ReadLongWord();
2556 MPaused
:= M
.ReadByte() <> 0;
2560 gMusic
.SetByName(MName
);
2562 gMusic
.SetPosition(MPos
);
2563 gMusic
.SpecPause
:= MPaused
;
2566 if gMusic
.IsPlaying
then gMusic
.Stop
;
2571 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2574 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2575 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2580 Mon
:= g_Monsters_ByUID(ID
);
2584 MType
:= M
.ReadByte();
2585 MState
:= M
.ReadByte();
2586 MAnim
:= M
.ReadByte();
2587 MTarg
:= M
.ReadWord();
2588 MTargTime
:= M
.ReadLongInt();
2589 MBehav
:= M
.ReadByte();
2590 MSleep
:= M
.ReadLongInt();
2591 MHealth
:= M
.ReadLongInt();
2592 MAmmo
:= M
.ReadLongInt();
2594 X
:= M
.ReadLongInt();
2595 Y
:= M
.ReadLongInt();
2596 VX
:= M
.ReadLongInt();
2597 VY
:= M
.ReadLongInt();
2598 MDir
:= M
.ReadByte();
2600 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2601 Mon
:= g_Monsters_ByUID(ID
);
2612 MonsterAnim
:= MAnim
;
2613 MonsterTargetUID
:= MTarg
;
2614 MonsterTargetTime
:= MTargTime
;
2615 MonsterBehaviour
:= MBehav
;
2616 MonsterSleep
:= MSleep
;
2617 MonsterAmmo
:= MAmmo
;
2622 positionChanged(); // this updates spatial accelerators
2626 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2632 Mon
:= g_Monsters_ByUID(ID
);
2638 GameX
:= M
.ReadLongInt();
2639 GameY
:= M
.ReadLongInt();
2640 GameVelX
:= M
.ReadLongInt();
2641 GameVelY
:= M
.ReadLongInt();
2642 GameDirection
:= TDirection(M
.ReadByte());
2643 positionChanged(); // this updates spatial accelerators
2647 procedure MC_RECV_MonsterState(var M
: TMsg
);
2650 MState
, MFAnm
: Byte;
2652 AnimRevert
: Boolean;
2655 Mon
:= g_Monsters_ByUID(ID
);
2656 if Mon
= nil then Exit
;
2658 MState
:= M
.ReadByte();
2659 MFAnm
:= M
.ReadByte();
2663 MonsterTargetUID
:= M
.ReadWord();
2664 MonsterTargetTime
:= M
.ReadLongInt();
2665 MonsterSleep
:= M
.ReadLongInt();
2666 MonsterHealth
:= M
.ReadLongInt();
2667 MonsterAmmo
:= M
.ReadLongInt();
2668 MonsterPain
:= M
.ReadLongInt();
2669 AnimRevert
:= M
.ReadByte() <> 0;
2670 FFireTime
:= M
.ReadLongInt();
2671 RevertAnim(AnimRevert
);
2673 if MonsterState
<> MState
then
2675 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then
2677 if (MState
= MONSTATE_DIE
) then
2679 if (MState
= MONSTATE_PAIN
) then
2680 MakeBloodSimple(Min(200, MonsterPain
));
2681 if (MState
= MONSTATE_ATTACK
) then
2683 if (MState
= MONSTATE_DEAD
) then
2686 SetState(MState
, MFAnm
);
2691 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2695 X
, Y
, VX
, VY
: Integer;
2699 Mon
:= g_Monsters_ByUID(ID
);
2700 if Mon
= nil then Exit
;
2702 X
:= M
.ReadLongInt();
2703 Y
:= M
.ReadLongInt();
2704 VX
:= M
.ReadLongInt();
2705 VY
:= M
.ReadLongInt();
2707 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2710 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2716 Mon
:= g_Monsters_ByUID(ID
);
2717 if Mon
= nil then Exit
;
2719 Mon
.MonsterRemoved
:= True;
2722 procedure MC_RECV_TimeSync(var M
: TMsg
);
2726 Time
:= M
.ReadLongWord();
2728 if gState
= STATE_INTERCUSTOM
then
2729 gServInterTime
:= Min(Time
, 255);
2732 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2736 Int1
, Int2
: SmallInt;
2738 EvID
:= M
.ReadByte();
2739 Int1
:= M
.ReadSmallInt();
2740 Int2
:= M
.ReadSmallInt();
2741 Str1
:= M
.ReadString();
2742 Str2
:= M
.ReadString();
2746 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2748 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2750 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2752 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2754 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2760 procedure MC_SEND_Info(Password
: string);
2764 NetOut
.Write(Byte(NET_MSG_INFO
));
2765 NetOut
.Write(GAME_VERSION
);
2766 NetOut
.Write(Password
);
2767 NetOut
.Write(gPlayer1Settings
.Name
);
2768 NetOut
.Write(gPlayer1Settings
.Model
);
2769 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2770 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2771 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2772 NetOut
.Write(gPlayer1Settings
.Team
);
2774 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2777 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2779 NetOut
.Write(Byte(NET_MSG_CHAT
));
2783 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2786 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
2788 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
2789 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
2793 procedure MC_SEND_PlayerPos();
2798 WeaponSelect
: Word = 0;
2801 if not gGameOn
then Exit
;
2802 if gPlayers
= nil then Exit
;
2803 if gPlayer1
= nil then Exit
;
2806 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2808 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2810 strafeDir
:= P1MoveButton
shr 4;
2811 P1MoveButton
:= P1MoveButton
and $0F;
2812 with gGameControls
.P1Control
do
2814 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 1
2815 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then P1MoveButton
:= 2
2816 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 0;
2819 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
2821 // new strafe mechanics
2822 if (strafeDir
= 0) then strafeDir
:= P1MoveButton
; // start strafing
2823 // now set direction according to strafe (reversed)
2824 if (strafeDir
= 2) then gPlayer1
.SetDirection(D_LEFT
)
2825 else if (strafeDir
= 1) then gPlayer1
.SetDirection(D_RIGHT
);
2829 if (P1MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then gPlayer1
.SetDirection(D_LEFT
)
2830 else if (P1MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then gPlayer1
.SetDirection(D_RIGHT
)
2831 else if P1MoveButton
<> 0 then gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2834 gPlayer1
.ReleaseKeys
;
2835 if P1MoveButton
= 1 then
2837 kByte
:= kByte
or NET_KEY_LEFT
;
2838 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2840 if P1MoveButton
= 2 then
2842 kByte
:= kByte
or NET_KEY_RIGHT
;
2843 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2845 if isKeyPressed(KeyUp
, KeyUp2
) then
2847 kByte
:= kByte
or NET_KEY_UP
;
2848 gPlayer1
.PressKey(KEY_UP
, 10000);
2850 if isKeyPressed(KeyDown
, KeyDown2
) then
2852 kByte
:= kByte
or NET_KEY_DOWN
;
2853 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2855 if isKeyPressed(KeyJump
, KeyJump2
) then
2857 kByte
:= kByte
or NET_KEY_JUMP
;
2858 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2860 if isKeyPressed(KeyFire
, KeyFire2
) then kByte
:= kByte
or NET_KEY_FIRE
;
2861 if isKeyPressed(KeyOpen
, KeyOpen2
) then kByte
:= kByte
or NET_KEY_OPEN
;
2862 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then kByte
:= kByte
or NET_KEY_NW
;
2863 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then kByte
:= kByte
or NET_KEY_PW
;
2864 for I
:= 0 to High(KeyWeapon
) do
2865 if isKeyPressed(KeyWeapon
[I
], KeyWeapon2
[I
]) then
2866 WeaponSelect
:= WeaponSelect
or Word(1 shl I
);
2868 // fix movebutton state
2869 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2872 kByte
:= NET_KEY_CHAT
;
2874 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2875 NetOut
.Write(gTime
);
2876 NetOut
.Write(kByte
);
2877 NetOut
.Write(Byte(gPlayer1
.Direction
));
2878 NetOut
.Write(WeaponSelect
);
2879 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2880 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2882 //kBytePrev := kByte;
2883 //kDirPrev := gPlayer1.Direction;
2886 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2888 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2889 NetOut
.Write(Byte(Start
));
2890 NetOut
.Write(Command
);
2891 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2894 procedure MC_SEND_PlayerSettings();
2896 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2897 NetOut
.Write(gPlayer1Settings
.Name
);
2898 NetOut
.Write(gPlayer1Settings
.Model
);
2899 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2900 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2901 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2902 NetOut
.Write(gPlayer1Settings
.Team
);
2904 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2907 procedure MC_SEND_FullStateRequest();
2909 NetOut
.Write(Byte(NET_MSG_REQFST
));
2911 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2914 procedure MC_SEND_CheatRequest(Kind
: Byte);
2916 NetOut
.Write(Byte(NET_MSG_CHEAT
));
2919 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2921 procedure MC_SEND_RCONPassword(Password
: string);
2923 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
2924 NetOut
.Write(Password
);
2926 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2928 procedure MC_SEND_RCONCommand(Cmd
: string);
2930 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
2933 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2936 // i have no idea why all this stuff is in here
2938 function ReadFile(const FileName
: TFileName
): AByte
;
2940 FileStream
: TStream
;
2943 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), MSG_NOTIFY
);
2944 fname
:= findDiskWad(FileName
);
2945 if length(fname
) = 0 then
2947 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), MSG_FATALERROR
);
2948 SetLength(Result
, 0);
2951 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), MSG_NOTIFY
);
2953 FileStream
:= openDiskFileRO(fname
);
2955 if FileStream
.Size
> 0 then
2957 SetLength(Result
, FileStream
.Size
);
2958 FileStream
.Read(Result
[0], FileStream
.Size
);
2965 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
2969 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
2970 Result
.FileData
:= ReadFile(FileName
);
2971 Result
.FileSize
:= Length(Result
.FileData
);
2973 SetLength(Result
.ExternalResources
, ResList
.Count
);
2974 for i
:=0 to ResList
.Count
-1 do
2976 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
2977 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
2981 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
2983 ResultStream
: TMemoryStream
;
2985 ResultStream
:= TMemoryStream
.Create
;
2987 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
2988 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
2989 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
2991 SetLength(bytes
, ResultStream
.Size
);
2992 ResultStream
.Seek(0, soFromBeginning
);
2993 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2998 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
3000 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3001 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
3002 SetLength(Result
.FileData
, Result
.FileSize
);
3003 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
3006 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
3008 ResultStream
: TMemoryStream
;
3011 resCount
:= Length(MapDataMsg
.ExternalResources
);
3013 ResultStream
:= TMemoryStream
.Create
;
3015 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
3016 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
3017 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
3019 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
3020 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
3022 SetLength(bytes
, ResultStream
.Size
);
3023 ResultStream
.Seek(0, soFromBeginning
);
3024 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3029 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
3033 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3034 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3036 SetLength(Result
.FileData
, Result
.FileSize
);
3037 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3039 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3040 SetLength(Result
.ExternalResources
, resCount
);
3042 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3045 function IsValidFileName(const S
: String): Boolean;
3047 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3052 for I
:= 1 to Length(S
) do
3053 Result
:= Result
and (not(S
[I
] in Forbidden
));
3056 function IsValidFilePath(const S
: String): Boolean;
3061 if not IsValidFileName(S
) then exit
;
3062 if FileExists(S
) then exit
;
3063 I
:= LastDelimiter('\/', S
);
3065 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3070 procedure MC_SEND_MapRequest();
3072 NetOut
.Write(Byte(NET_MSG_MAP_REQUEST
));
3073 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3076 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3078 NetOut
.Write(Byte(NET_MSG_RES_REQUEST
));
3079 NetOut
.Write(resName
);
3080 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3083 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
3087 mapDataMsg
: TMapDataMsg
;
3089 e_WriteLog('NET: Received map request from ' +
3090 DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3092 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3093 peer
:= NetClients
[C
.ID
].Peer
;
3095 MapDataMsgToBytes(payload
, mapDataMsg
);
3096 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3099 mapDataMsg
.FileData
:= nil;
3100 mapDataMsg
.ExternalResources
:= nil;
3103 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
3108 resDataMsg
: TResDataMsg
;
3110 FileName
:= ExtractFileName(M
.ReadString());
3111 e_WriteLog('NET: Received res request: ' + FileName
+
3112 ' from ' + DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3114 if not IsValidFilePath(FileName
) then
3116 e_WriteLog('Invalid filename: ' + FileName
, MSG_WARNING
);
3120 peer
:= NetClients
[C
.ID
].Peer
;
3122 if gExternalResources
.IndexOf(FileName
) > -1 then
3124 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3125 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3126 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3128 ResDataMsgToBytes(payload
, resDataMsg
);
3129 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);