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
);
643 function sendPanelState (pan
: TPanel
): Boolean;
645 result
:= false; // don't stop
646 MH_SEND_PanelState(pan
.PanelType
, pan
.guid
, ID
); // anyway, to sync mplats
647 if (pan
.GetTextureCount
> 1) then MH_SEND_PanelTexture(pan
.PanelType
, pan
.guid
, pan
.LastAnimLoop
, ID
);
653 if gPlayers
<> nil then
655 for I
:= Low(gPlayers
) to High(gPlayers
) do
657 if gPlayers
[I
] <> nil then
659 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
660 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
661 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
663 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
665 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
671 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
672 g_Mons_ForEach(sendMonSpawn
);
674 g_Map_ForEachPanel(sendPanelState
);
676 (* replaced with the `g_Map_ForEachPanel()` call above
677 if gWalls <> nil then
678 for I := Low(gWalls) to High(gWalls) do
679 if gWalls[I] <> nil then
682 {if Door then} // anyway, to sync mplats
683 MH_SEND_PanelState(PanelType, I, ID);
685 if GetTextureCount > 1 then
686 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
689 if gLifts <> nil then
690 for I := Low(gLifts) to High(gLifts) do
691 if gLifts[I] <> nil then
693 MH_SEND_PanelState(PanelType, I, ID);
695 if gRenderForegrounds <> nil then
696 for I := Low(gRenderForegrounds) to High(gRenderForegrounds) do
697 if gRenderForegrounds[I] <> nil then
698 with gRenderForegrounds[I] do
700 if (GetTextureCount > 1) then
701 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
702 {if Moved then} // anyway, to sync mplats
703 MH_SEND_PanelState(PanelType, I, ID);
705 if gRenderBackgrounds <> nil then
706 for I := Low(gRenderBackgrounds) to High(gRenderBackgrounds) do
707 if gRenderBackgrounds[I] <> nil then
708 with gRenderBackgrounds[I] do
710 if (GetTextureCount > 1) then
711 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
712 {if Moved then} // anyway, to sync mplats
713 MH_SEND_PanelState(PanelType, I, ID);
715 if gWater <> nil then
716 for I := Low(gWater) to High(gWater) do
717 if gWater[I] <> nil then
720 if GetTextureCount > 1 then
721 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
722 {if Moved then} // anyway, to sync mplats
723 MH_SEND_PanelState(PanelType, I, ID);
725 if gAcid1 <> nil then
726 for I := Low(gAcid1) to High(gAcid1) do
727 if gAcid1[I] <> nil then
730 if GetTextureCount > 1 then
731 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
732 {if Moved then} // anyway, to sync mplats
733 MH_SEND_PanelState(PanelType, I, ID);
735 if gAcid2 <> nil then
736 for I := Low(gAcid2) to High(gAcid2) do
737 if gAcid2[I] <> nil then
740 if GetTextureCount > 1 then
741 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
742 {if Moved then} // anyway, to sync mplats
743 MH_SEND_PanelState(PanelType, I, ID);
745 if gSteps <> nil then
746 for I := Low(gSteps) to High(gSteps) do
747 if gSteps[I] <> nil then
750 if GetTextureCount > 1 then
751 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
752 {if Moved then} // anyway, to sync mplats
753 MH_SEND_PanelState(PanelType, I, ID);
757 if gTriggers
<> nil then
758 for I
:= Low(gTriggers
) to High(gTriggers
) do
759 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
760 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
763 for I
:= Low(Shots
) to High(Shots
) do
764 if Shots
[i
].ShotType
in [6, 7, 8] then
765 MH_SEND_CreateShot(i
, ID
);
767 MH_SEND_TriggerMusic(ID
);
769 MH_SEND_GameStats(ID
);
770 MH_SEND_CoopStats(ID
);
772 if gGameSettings
.GameMode
= GM_CTF
then
774 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then
775 MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
776 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then
777 MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
780 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
782 if gLMSRespawn
> LMS_RESPAWN_NONE
then
783 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
786 procedure MH_SEND_Info(ID
: Byte);
790 Map
:= g_ExtractFileName(gMapInfo
.Map
);
794 NetOut
.Write(Byte(NET_MSG_INFO
));
796 NetOut
.Write(NetClients
[ID
].Player
);
797 NetOut
.Write(gGameSettings
.WAD
);
799 NetOut
.Write(gWADHash
);
800 NetOut
.Write(gGameSettings
.GameMode
);
801 NetOut
.Write(gGameSettings
.GoalLimit
);
802 NetOut
.Write(gGameSettings
.TimeLimit
);
803 NetOut
.Write(gGameSettings
.MaxLives
);
804 NetOut
.Write(gGameSettings
.Options
);
807 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
810 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
816 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
817 Mode
:= NET_CHAT_PLAYER
;
820 if (Mode
= NET_CHAT_TEAM
) then
822 for i
:= Low(gPlayers
) to High(gPlayers
) do
823 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
824 (gPlayers
[i
].Team
= ID
) then
826 NetOut
.Write(Byte(NET_MSG_CHAT
));
829 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
836 NetOut
.Write(Byte(NET_MSG_CHAT
));
839 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
842 if Mode
= NET_CHAT_SYSTEM
then
845 if ID
= NET_EVERYONE
then
847 if Mode
= NET_CHAT_PLAYER
then
849 g_Console_Add(Txt
, True);
850 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
851 g_Sound_PlayEx('SOUND_GAME_RADIO');
854 if Mode
= NET_CHAT_TEAM
then
855 if gPlayer1
<> nil then
857 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
859 g_Console_Add(#18'[Team] '#2 + Txt
, True);
860 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
861 g_Sound_PlayEx('SOUND_GAME_RADIO');
863 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
865 g_Console_Add(#20'[Team] '#2 + Txt
, True);
866 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
867 g_Sound_PlayEx('SOUND_GAME_RADIO');
873 Name
:= g_Net_ClientName_ByID(ID
);
874 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
875 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
876 g_Sound_PlayEx('SOUND_GAME_RADIO');
880 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
882 NetOut
.Write(Byte(NET_MSG_GFX
));
888 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
891 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
893 NetOut
.Write(Byte(NET_MSG_SND
));
897 NetOut
.Write(Byte(1));
902 NetOut
.Write(Byte(0));
904 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
907 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
909 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
911 NetOut
.Write(Byte(NET_MSG_SHADD
));
913 NetOut
.Write(Shots
[Proj
].ShotType
);
914 NetOut
.Write(Shots
[Proj
].Target
);
915 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
916 NetOut
.Write(Shots
[Proj
].Timeout
);
917 NetOut
.Write(Shots
[Proj
].Obj
.X
);
918 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
919 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
920 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
922 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
925 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
927 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
929 NetOut
.Write(Byte(NET_MSG_SHPOS
));
931 NetOut
.Write(Shots
[Proj
].Obj
.X
);
932 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
933 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
934 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
936 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
939 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
941 NetOut
.Write(Byte(NET_MSG_SHDEL
));
943 NetOut
.Write(Byte(Loud
));
947 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
950 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
952 NetOut
.Write(Byte(NET_MSG_SCORE
));
953 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
955 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
956 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
959 if gGameSettings
.GameMode
= GM_COOP
then
961 NetOut
.Write(gCoopMonstersKilled
);
962 NetOut
.Write(gCoopSecretsFound
);
965 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
968 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
970 NetOut
.Write(Byte(NET_MSG_COOP
));
971 NetOut
.Write(gTotalMonsters
);
972 NetOut
.Write(gSecretsCount
);
973 NetOut
.Write(gCoopTotalMonstersKilled
);
974 NetOut
.Write(gCoopTotalSecretsFound
);
975 NetOut
.Write(gCoopTotalMonsters
);
976 NetOut
.Write(gCoopTotalSecrets
);
979 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
981 NetOut
.Write(Byte(NET_MSG_GEVENT
));
982 NetOut
.Write(EvType
);
985 NetOut
.Write(Byte(gLastMap
));
987 if (EvType
= NET_EV_MAPSTART
) and (Pos(':\', EvStr
) > 0) then
989 NetOut
.Write(Byte(1));
990 NetOut
.Write(gWADHash
);
992 NetOut
.Write(Byte(0));
994 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
997 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
999 NetOut
.Write(Byte(NET_MSG_FLAG
));
1000 NetOut
.Write(EvType
);
1002 NetOut
.Write(Byte(Quiet
));
1004 NetOut
.Write(gFlags
[Flag
].State
);
1005 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1006 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1007 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1008 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1009 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1011 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1014 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1016 NetOut
.Write(Byte(NET_MSG_GSET
));
1017 NetOut
.Write(gGameSettings
.GameMode
);
1018 NetOut
.Write(gGameSettings
.GoalLimit
);
1019 NetOut
.Write(gGameSettings
.TimeLimit
);
1020 NetOut
.Write(gGameSettings
.MaxLives
);
1021 NetOut
.Write(gGameSettings
.Options
);
1023 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1028 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1032 P
:= g_Player_Get(PID
);
1033 if P
= nil then Exit
;
1035 NetOut
.Write(Byte(NET_MSG_PLR
));
1037 NetOut
.Write(P
.Name
);
1039 NetOut
.Write(P
.FActualModelName
);
1040 NetOut
.Write(P
.FColor
.R
);
1041 NetOut
.Write(P
.FColor
.G
);
1042 NetOut
.Write(P
.FColor
.B
);
1043 NetOut
.Write(P
.Team
);
1045 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1048 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1053 Pl
:= g_Player_Get(PID
);
1054 if Pl
= nil then Exit
;
1055 if Pl
.FDummy
then Exit
;
1057 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1058 NetOut
.Write(gTime
);
1065 NetOut
.Write(FPing
);
1066 NetOut
.Write(FLoss
);
1067 if IsKeyPressed(KEY_CHAT
) then
1068 kByte
:= NET_KEY_CHAT
1071 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1072 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1073 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1074 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1075 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1076 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1079 NetOut
.Write(kByte
);
1080 if Direction
= D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1081 NetOut
.Write(GameX
);
1082 NetOut
.Write(GameY
);
1083 NetOut
.Write(GameVelX
);
1084 NetOut
.Write(GameVelY
);
1085 NetOut
.Write(GameAccelX
);
1086 NetOut
.Write(GameAccelY
);
1089 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1092 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1097 P
:= g_Player_Get(PID
);
1098 if P
= nil then Exit
;
1100 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1105 NetOut
.Write(Byte(alive
));
1106 NetOut
.Write(Byte(GodMode
));
1107 NetOut
.Write(Health
);
1108 NetOut
.Write(Armor
);
1110 NetOut
.Write(JetFuel
);
1111 NetOut
.Write(Lives
);
1114 for I
:= WP_FIRST
to WP_LAST
do
1115 NetOut
.Write(Byte(FWeapon
[I
]));
1117 for I
:= A_BULLETS
to A_HIGH
do
1118 NetOut
.Write(FAmmo
[I
]);
1120 for I
:= A_BULLETS
to A_HIGH
do
1121 NetOut
.Write(FMaxAmmo
[I
]);
1123 for I
:= MR_SUIT
to MR_MAX
do
1124 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1126 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1127 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1128 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1129 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1130 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1132 NetOut
.Write(Frags
);
1133 NetOut
.Write(Death
);
1135 NetOut
.Write(CurrWeap
);
1137 NetOut
.Write(Byte(FSpectator
));
1138 NetOut
.Write(Byte(FGhost
));
1139 NetOut
.Write(Byte(FPhysics
));
1140 NetOut
.Write(Byte(FNoRespawn
));
1141 NetOut
.Write(Byte(FJetpack
));
1142 NetOut
.Write(FFireTime
);
1145 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1148 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1150 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1153 NetOut
.Write(Attacker
);
1154 NetOut
.Write(Value
);
1158 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1161 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1163 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1165 NetOut
.Write(KillType
);
1166 NetOut
.Write(DeathType
);
1167 NetOut
.Write(Attacker
);
1169 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1172 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1174 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1176 NetOut
.Write(Weapon
);
1181 NetOut
.Write(ShotID
);
1183 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1186 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1188 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1191 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1194 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1198 Pl
:= g_Player_Get(PID
);
1199 if Pl
= nil then Exit
;
1201 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1203 NetOut
.Write(Pl
.Name
);
1205 NetOut
.Write(Pl
.Model
.Name
)
1208 NetOut
.Write(Pl
.FColor
.R
);
1209 NetOut
.Write(Pl
.FColor
.G
);
1210 NetOut
.Write(Pl
.FColor
.B
);
1211 NetOut
.Write(Pl
.Team
);
1213 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1218 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1222 it
:= g_Items_ByIdx(IID
);
1224 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1226 NetOut
.Write(Byte(Quiet
));
1227 NetOut
.Write(it
.ItemType
);
1228 NetOut
.Write(Byte(it
.Fall
));
1229 NetOut
.Write(Byte(it
.Respawnable
));
1230 NetOut
.Write(it
.Obj
.X
);
1231 NetOut
.Write(it
.Obj
.Y
);
1232 NetOut
.Write(it
.Obj
.Vel
.X
);
1233 NetOut
.Write(it
.Obj
.Vel
.Y
);
1235 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1238 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1240 NetOut
.Write(Byte(NET_MSG_IDEL
));
1242 NetOut
.Write(Byte(Quiet
));
1244 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1249 procedure MH_SEND_PanelTexture(PType
: Word; PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1253 TP
:= g_Map_PanelByGUID(PGUID
);
1254 if (TP
= nil) then exit
;
1257 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
1260 TP := gRenderForegrounds[PID];
1262 TP := gRenderBackgrounds[PID];
1278 NetOut
.Write(Byte(NET_MSG_PTEX
));
1279 NetOut
.Write(PType
);
1280 NetOut
.Write(LongWord(PGUID
));
1281 NetOut
.Write(FCurTexture
);
1282 NetOut
.Write(FCurFrame
);
1283 NetOut
.Write(FCurFrameCount
);
1284 NetOut
.Write(AnimLoop
);
1287 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1290 procedure MH_SEND_PanelState(PType
: Word; PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1295 TP
:= g_Map_PanelByGUID(PGUID
);
1296 if (TP
= nil) then exit
;
1299 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: TP := gWalls[PID];
1300 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT: TP := gLifts[PID];
1304 //TP := gRenderBackgrounds[PID];
1309 //TP := gRenderForegrounds[PID];
1318 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1319 NetOut
.Write(PType
);
1320 NetOut
.Write(LongWord(PGUID
));
1321 NetOut
.Write(Byte(TP
.Enabled
));
1322 NetOut
.Write(TP
.LiftType
);
1325 NetOut
.Write(Word(TP
.Width
));
1326 NetOut
.Write(Word(TP
.Height
));
1328 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1329 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1330 NetOut
.Write(LongInt(TP
.movingStartX
));
1331 NetOut
.Write(LongInt(TP
.movingStartY
));
1332 NetOut
.Write(LongInt(TP
.movingEndX
));
1333 NetOut
.Write(LongInt(TP
.movingEndY
));
1334 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1335 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1336 NetOut
.Write(LongInt(TP
.sizeEndX
));
1337 NetOut
.Write(LongInt(TP
.sizeEndY
));
1338 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1339 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1340 NetOut
.Write(Byte(mpflags
));
1342 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1347 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1349 if gTriggers
= nil then Exit
;
1350 if T
.Sound
= nil then Exit
;
1352 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1353 NetOut
.Write(T
.ClientID
);
1354 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1355 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1356 NetOut
.Write(T
.SoundPlayCount
);
1358 g_Net_Host_Send(ID
, True);
1361 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1363 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1364 NetOut
.Write(gMusic
.Name
);
1365 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1366 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1367 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1369 g_Net_Host_Send(ID
, True);
1374 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1378 M
:= g_Monsters_ByUID(UID
);
1384 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1386 NetOut
.Write(MonsterType
);
1387 NetOut
.Write(MonsterState
);
1388 NetOut
.Write(MonsterAnim
);
1389 NetOut
.Write(MonsterTargetUID
);
1390 NetOut
.Write(MonsterTargetTime
);
1391 NetOut
.Write(MonsterBehaviour
);
1392 NetOut
.Write(MonsterSleep
);
1393 NetOut
.Write(MonsterHealth
);
1394 NetOut
.Write(MonsterAmmo
);
1395 NetOut
.Write(GameX
);
1396 NetOut
.Write(GameY
);
1397 NetOut
.Write(GameVelX
);
1398 NetOut
.Write(GameVelY
);
1399 NetOut
.Write(Byte(GameDirection
));
1402 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1405 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1409 M
:= g_Monsters_ByUID(UID
);
1410 if M
= nil then Exit
;
1412 NetOut
.Write(Byte(NET_MSG_MPOS
));
1417 NetOut
.Write(GameX
);
1418 NetOut
.Write(GameY
);
1419 NetOut
.Write(GameVelX
);
1420 NetOut
.Write(GameVelY
);
1421 NetOut
.Write(Byte(GameDirection
));
1424 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1427 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1431 M
:= g_Monsters_ByUID(UID
);
1432 if M
= nil then Exit
;
1434 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1439 NetOut
.Write(MonsterState
);
1440 NetOut
.Write(ForcedAnim
);
1441 NetOut
.Write(MonsterTargetUID
);
1442 NetOut
.Write(MonsterTargetTime
);
1443 NetOut
.Write(MonsterSleep
);
1444 NetOut
.Write(MonsterHealth
);
1445 NetOut
.Write(MonsterAmmo
);
1446 NetOut
.Write(MonsterPain
);
1447 NetOut
.Write(Byte(AnimIsReverse
));
1448 NetOut
.Write(FFireTime
);
1451 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1454 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1456 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1463 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1466 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1470 M
:= g_Monsters_ByUID(UID
);
1471 if M
= nil then Exit
;
1473 NetOut
.Write(Byte(NET_MSG_MDEL
));
1476 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1481 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1483 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1486 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1489 procedure MH_SEND_VoteEvent(EvType
: Byte;
1490 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1491 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1492 ID
: Integer = NET_EVERYONE
);
1494 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1495 NetOut
.Write(EvType
);
1496 NetOut
.Write(IntArg1
);
1497 NetOut
.Write(IntArg2
);
1498 NetOut
.Write(StrArg1
);
1499 NetOut
.Write(StrArg2
);
1501 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1504 // CLIENT MESSAGES //
1508 procedure MC_RECV_Chat(var M
: TMsg
);
1513 Txt
:= M
.ReadString();
1514 Mode
:= M
.ReadByte();
1516 if Mode
<> NET_CHAT_SYSTEM
then
1518 if Mode
= NET_CHAT_PLAYER
then
1520 g_Console_Add(Txt
, True);
1521 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1522 g_Sound_PlayEx('SOUND_GAME_RADIO');
1524 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1526 if gPlayer1
.Team
= TEAM_RED
then
1527 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1528 if gPlayer1
.Team
= TEAM_BLUE
then
1529 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1530 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1531 g_Sound_PlayEx('SOUND_GAME_RADIO');
1534 g_Console_Add(Txt
, True);
1537 procedure MC_RECV_Effect(var M
: TMsg
);
1545 if not gGameOn
then Exit
;
1546 Kind
:= M
.ReadByte();
1547 X
:= M
.ReadLongInt();
1548 Y
:= M
.ReadLongInt();
1549 Ang
:= M
.ReadSmallInt();
1553 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1557 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1559 Anim
:= TAnimation
.Create(ID
, False, 3);
1560 g_GFX_OnceAnim(X
, Y
, Anim
);
1564 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1569 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1571 Anim
:= TAnimation
.Create(ID
, False, 6);
1572 Anim
.Blending
:= False;
1573 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1577 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1582 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1584 Anim
:= TAnimation
.Create(ID
, False, 6);
1585 Anim
.Blending
:= False;
1586 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1590 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1595 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1597 Anim
:= TAnimation
.Create(ID
, False, 4);
1598 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1605 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1607 Anim
:= TAnimation
.Create(ID
, False, 4);
1608 g_GFX_OnceAnim(X
, Y
, Anim
);
1612 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1617 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1619 Anim
:= TAnimation
.Create(ID
, False, 4);
1620 g_GFX_OnceAnim(X
, Y
, Anim
);
1624 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1628 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1631 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1635 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1636 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1641 procedure MC_RECV_Sound(var M
: TMsg
);
1647 Name
:= M
.ReadString();
1648 Pos
:= M
.ReadByte() <> 0;
1651 X
:= M
.ReadLongInt();
1652 Y
:= M
.ReadLongInt();
1653 g_Sound_PlayExAt(Name
, X
, Y
);
1656 g_Sound_PlayEx(Name
);
1659 procedure MC_RECV_CreateShot(var M
: TMsg
);
1661 I
, X
, Y
, XV
, YV
: Integer;
1663 Target
, Spawner
: Word;
1666 I
:= M
.ReadLongInt();
1667 ShType
:= M
.ReadByte();
1668 Target
:= M
.ReadWord();
1669 Spawner
:= M
.ReadWord();
1670 Timeout
:= M
.ReadLongWord();
1671 X
:= M
.ReadLongInt();
1672 Y
:= M
.ReadLongInt();
1673 XV
:= M
.ReadLongInt();
1674 YV
:= M
.ReadLongInt();
1676 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1677 if (Shots
<> nil) and (I
<= High(Shots
)) then
1679 Shots
[I
].Timeout
:= Timeout
;
1680 //Shots[I].Target := Target; // TODO: find a use for Target later
1684 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1686 I
, TX
, TY
, TXV
, TYV
: Integer;
1688 I
:= M
.ReadLongInt();
1689 TX
:= M
.ReadLongInt();
1690 TY
:= M
.ReadLongInt();
1691 TXV
:= M
.ReadLongInt();
1692 TYV
:= M
.ReadLongInt();
1694 if (Shots
<> nil) and (I
<= High(Shots
)) then
1704 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1709 if not gGameOn
then Exit
;
1710 I
:= M
.ReadLongInt();
1711 L
:= (M
.ReadByte() <> 0);
1712 X
:= M
.ReadLongInt();
1713 Y
:= M
.ReadLongInt();
1715 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1718 procedure MC_RECV_GameStats(var M
: TMsg
);
1720 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1722 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1723 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1726 if gGameSettings
.GameMode
= GM_COOP
then
1728 gCoopMonstersKilled
:= M
.ReadWord();
1729 gCoopSecretsFound
:= M
.ReadWord();
1733 procedure MC_RECV_CoopStats(var M
: TMsg
);
1735 gTotalMonsters
:= M
.ReadLongInt();
1736 gSecretsCount
:= M
.ReadLongInt();
1737 gCoopTotalMonstersKilled
:= M
.ReadWord();
1738 gCoopTotalSecretsFound
:= M
.ReadWord();
1739 gCoopTotalMonsters
:= M
.ReadWord();
1740 gCoopTotalSecrets
:= M
.ReadWord();
1743 procedure MC_RECV_GameEvent(var M
: TMsg
);
1752 i1
, i2
: TStrings_Locale
;
1756 FillChar(EvHash
, Sizeof(EvHash
), 0);
1757 EvType
:= M
.ReadByte();
1758 EvNum
:= M
.ReadLongInt();
1759 EvStr
:= M
.ReadString();
1760 gLastMap
:= M
.ReadByte() <> 0;
1761 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1762 gStatsPressed
:= True;
1763 EvTime
:= M
.ReadLongWord();
1764 BHash
:= M
.ReadByte() <> 0;
1766 EvHash
:= M
.ReadMD5();
1774 g_Game_ClearLoading();
1775 g_Game_StopAllSounds(True);
1777 gSwitchGameMode
:= Byte(EvNum
);
1778 gGameSettings
.GameMode
:= gSwitchGameMode
;
1781 if not g_Game_StartMap(EvStr
, True) then
1783 if Pos(':\', EvStr
) = 0 then
1784 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1786 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1790 MC_SEND_FullStateRequest
;
1795 gMissionFailed
:= EvNum
<> 0;
1796 gExit
:= EXIT_ENDLEVELCUSTOM
;
1803 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1805 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1807 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1813 if EvNum
= TEAM_RED
then
1814 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1815 if EvNum
= TEAM_BLUE
then
1816 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1820 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1823 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1826 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1828 NET_EV_LMS_SURVIVOR
:
1829 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1832 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1836 pl
:= g_Player_Get(EvNum
and $FFFF);
1841 cnt
:= (EvNum
shr 16) and $FF;
1842 if Pos('w', EvStr
) = 0 then
1845 if Pos('t', EvStr
) = 0 then
1848 if Pos('-', EvStr
) = 0 then
1850 if Pos('e', EvStr
) = 0 then
1851 i1
:= I_PLAYER_SCORE_ADD_OWN
1853 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1856 if Pos('e', EvStr
) = 0 then
1857 i1
:= I_PLAYER_SCORE_SUB_OWN
1859 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1862 if Pos('r', EvStr
) > 0 then
1863 i2
:= I_PLAYER_SCORE_TO_RED
1865 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1866 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1870 if Pos('-', EvStr
) = 0 then
1871 i1
:= I_PLAYER_SCORE_ADD_TEAM
1873 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1875 if Pos('r', EvStr
) > 0 then
1876 i2
:= I_PLAYER_SCORE_RED
1878 i2
:= I_PLAYER_SCORE_BLUE
;
1879 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1884 if Pos('e', EvStr
) = 0 then
1885 i1
:= I_PLAYER_SCORE_WIN_OWN
1887 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1889 if Pos('r', EvStr
) > 0 then
1890 i2
:= I_PLAYER_SCORE_TO_RED
1892 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1893 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1899 if EvNum
= TEAM_RED
then
1900 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1901 if EvNum
= TEAM_BLUE
then
1902 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1903 if EvNum
= -TEAM_RED
then
1904 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1905 if EvNum
= -TEAM_BLUE
then
1906 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1911 g_Player_RemoveAllCorpses
;
1912 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1916 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1920 if EvNum
= TEAM_RED
then
1921 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1922 if EvNum
= TEAM_BLUE
then
1923 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1927 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1930 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1933 g_Game_Announce_KillCombo(EvNum
);
1935 NET_EV_PLAYER_TOUCH
:
1937 pl
:= g_Player_Get(EvNum
);
1945 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1954 EvType
:= M
.ReadByte();
1957 if Fl
= FLAG_NONE
then Exit
;
1959 Quiet
:= (M
.ReadByte() <> 0);
1960 PID
:= M
.ReadWord();
1962 gFlags
[Fl
].State
:= M
.ReadByte();
1963 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1964 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1965 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1966 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1967 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1969 Pl
:= g_Player_Get(PID
);
1971 (EvType
<> FLAG_STATE_NORMAL
) and
1972 (EvType
<> FLAG_STATE_DROPPED
) and
1973 (EvType
<> FLAG_STATE_RETURNED
) then
1979 if Quiet
or (Pl
= nil) then Exit
;
1981 if Fl
= FLAG_RED
then
1982 s
:= _lc
[I_PLAYER_FLAG_RED
]
1984 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1986 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1989 FLAG_STATE_CAPTURED
:
1991 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1995 if Fl
= FLAG_RED
then
1996 s
:= _lc
[I_PLAYER_FLAG_RED
]
1998 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2000 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2001 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2006 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2008 if Quiet
or (Pl
= nil) then Exit
;
2010 if Fl
= FLAG_RED
then
2011 s
:= _lc
[I_PLAYER_FLAG_RED
]
2013 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2015 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2016 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2021 g_Map_ResetFlag(FLAG_RED
);
2022 g_Map_ResetFlag(FLAG_BLUE
);
2023 if Quiet
or (Pl
= nil) then Exit
;
2024 Pl
.SetFlag(FLAG_NONE
);
2026 if Fl
= FLAG_RED
then
2027 s
:= _lc
[I_PLAYER_FLAG_RED
]
2029 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2031 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2032 Insert('.', ts
, Length(ts
) + 1 - 3);
2033 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2034 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2037 FLAG_STATE_RETURNED
:
2039 g_Map_ResetFlag(Fl
);
2042 if Fl
= FLAG_RED
then
2043 s
:= _lc
[I_PLAYER_FLAG_RED
]
2045 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2047 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2052 procedure MC_RECV_GameSettings(var M
: TMsg
);
2054 gGameSettings
.GameMode
:= M
.ReadByte();
2055 gGameSettings
.GoalLimit
:= M
.ReadWord();
2056 gGameSettings
.TimeLimit
:= M
.ReadWord();
2057 gGameSettings
.MaxLives
:= M
.ReadByte();
2058 gGameSettings
.Options
:= M
.ReadLongWord();
2063 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2066 PName
, Model
: string;
2071 PID
:= M
.ReadWord();
2072 Pl
:= g_Player_Get(PID
);
2074 PName
:= M
.ReadString();
2075 Model
:= M
.ReadString();
2076 Color
.R
:= M
.ReadByte();
2077 Color
.G
:= M
.ReadByte();
2078 Color
.B
:= M
.ReadByte();
2082 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2084 if (Pl
<> nil) then Exit
;
2085 DID
:= g_Player_Create(Model
, Color
, T
, False);
2086 with g_Player_Get(DID
) do
2095 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2096 gPlayer1
.UID
:= PID
;
2097 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2098 gPlayer1
.ChangeTeam(T
);
2100 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2101 gPlayer2
.UID
:= PID
;
2102 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2103 gPlayer2
.ChangeTeam(T
);
2107 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2108 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', MSG_NOTIFY
);
2112 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2119 TmpX
, TmpY
: Integer;
2123 GT
:= M
.ReadLongWord();
2124 if GT
< gTime
- NET_MAX_DIFFTIME
then
2131 PID
:= M
.ReadWord();
2132 Pl
:= g_Player_Get(PID
);
2134 if Pl
= nil then Exit
;
2140 FPing
:= M
.ReadWord();
2141 FLoss
:= M
.ReadByte();
2142 kByte
:= M
.ReadWord();
2143 Dir
:= M
.ReadByte();
2145 TmpX
:= M
.ReadLongInt();
2146 TmpY
:= M
.ReadLongInt();
2150 if (kByte
= NET_KEY_CHAT
) then
2151 PressKey(KEY_CHAT
, 10000)
2154 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2155 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2156 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2157 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2158 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2161 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2162 SetDirection(TDirection(Dir
));
2164 GameVelX
:= M
.ReadLongInt();
2165 GameVelY
:= M
.ReadLongInt();
2166 GameAccelX
:= M
.ReadLongInt();
2167 GameAccelY
:= M
.ReadLongInt();
2168 SetLerp(TmpX
, TmpY
);
2169 if NetForcePlayerUpdate
then Update();
2173 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2181 PID
:= M
.ReadWord();
2182 Pl
:= g_Player_Get(PID
);
2189 alive
:= (M
.ReadByte() <> 0);
2190 GodMode
:= (M
.ReadByte() <> 0);
2191 Health
:= M
.ReadLongInt();
2192 Armor
:= M
.ReadLongInt();
2193 Air
:= M
.ReadLongInt();
2194 JetFuel
:= M
.ReadLongInt();
2195 Lives
:= M
.ReadByte();
2196 NewTeam
:= M
.ReadByte();
2198 for I
:= WP_FIRST
to WP_LAST
do
2199 FWeapon
[I
] := (M
.ReadByte() <> 0);
2201 for I
:= A_BULLETS
to A_HIGH
do
2202 FAmmo
[I
] := M
.ReadWord();
2204 for I
:= A_BULLETS
to A_HIGH
do
2205 FMaxAmmo
[I
] := M
.ReadWord();
2207 for I
:= MR_SUIT
to MR_MAX
do
2208 FMegaRulez
[I
] := M
.ReadLongWord();
2211 if (M
.ReadByte() <> 0) then
2212 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2213 if (M
.ReadByte() <> 0) then
2214 FRulez
:= FRulez
+ [R_KEY_RED
];
2215 if (M
.ReadByte() <> 0) then
2216 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2217 if (M
.ReadByte() <> 0) then
2218 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2219 if (M
.ReadByte() <> 0) then
2220 FRulez
:= FRulez
+ [R_BERSERK
];
2222 Frags
:= M
.ReadLongInt();
2223 Death
:= M
.ReadLongInt();
2225 SetWeapon(M
.ReadByte());
2227 FSpectator
:= M
.ReadByte() <> 0;
2230 if Pl
= gPlayer1
then
2235 if Pl
= gPlayer2
then
2243 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2244 gPlayer1
:= g_Player_Get(gLMSPID1
);
2245 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2246 gPlayer2
:= g_Player_Get(gLMSPID2
);
2248 FGhost
:= M
.ReadByte() <> 0;
2249 FPhysics
:= M
.ReadByte() <> 0;
2250 FNoRespawn
:= M
.ReadByte() <> 0;
2252 FJetpack
:= M
.ReadByte() <> 0;
2253 FFireTime
:= M
.ReadLongInt();
2254 if OldJet
and not FJetpack
then
2256 else if not OldJet
and FJetpack
then
2258 if Team
<> NewTeam
then
2259 Pl
.ChangeTeam(NewTeam
);
2265 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2270 Attacker
, Value
: Word;
2274 if not gGameOn
then Exit
;
2275 PID
:= M
.ReadWord();
2276 Pl
:= g_Player_Get(PID
);
2277 if Pl
= nil then Exit
;
2279 Kind
:= M
.ReadByte();
2280 Attacker
:= M
.ReadWord();
2281 Value
:= M
.ReadWord();
2286 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2291 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2295 KillType
, DeathType
: Byte;
2299 if not gGameOn
then Exit
;
2300 PID
:= M
.ReadWord();
2301 Pl
:= g_Player_Get(PID
);
2302 if Pl
= nil then Exit
;
2304 KillType
:= M
.ReadByte();
2305 DeathType
:= M
.ReadByte();
2306 Attacker
:= M
.ReadWord();
2310 Kill(KillType
, Attacker
, DeathType
);
2315 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2320 PID
:= M
.ReadWord();
2321 Pl
:= g_Player_Get(PID
);
2323 if Pl
= nil then Exit
;
2325 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2326 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', MSG_NOTIFY
);
2328 g_Player_Remove(PID
);
2333 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2338 X
, Y
, AX
, AY
: Integer;
2342 if not gGameOn
then Exit
;
2343 PID
:= M
.ReadWord();
2344 Pl
:= g_Player_Get(PID
);
2345 if Pl
= nil then Exit
;
2347 Weap
:= M
.ReadByte();
2348 X
:= M
.ReadLongInt();
2349 Y
:= M
.ReadLongInt();
2350 AX
:= M
.ReadLongInt();
2351 AY
:= M
.ReadLongInt();
2352 SHID
:= M
.ReadLongInt();
2355 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2358 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2367 PID
:= M
.ReadWord();
2368 Pl
:= g_Player_Get(PID
);
2369 if Pl
= nil then Exit
;
2371 TmpName
:= M
.ReadString();
2372 TmpModel
:= M
.ReadString();
2373 TmpColor
.R
:= M
.ReadByte();
2374 TmpColor
.G
:= M
.ReadByte();
2375 TmpColor
.B
:= M
.ReadByte();
2376 TmpTeam
:= M
.ReadByte();
2378 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2380 Pl
.ChangeTeam(TmpTeam
);
2381 if gPlayer1
= Pl
then
2382 gPlayer1Settings
.Team
:= TmpTeam
;
2383 if gPlayer2
= Pl
then
2384 gPlayer2Settings
.Team
:= TmpTeam
;
2386 Pl
.SetColor(TmpColor
);
2388 if Pl
.Name
<> TmpName
then
2390 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2394 if TmpModel
<> Pl
.Model
.Name
then
2395 Pl
.SetModel(TmpModel
);
2400 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2404 X
, Y
, VX
, VY
: Integer;
2406 Quiet
, Fall
{, Resp}: Boolean;
2410 if not gGameOn
then Exit
;
2412 Quiet
:= M
.ReadByte() <> 0;
2414 Fall
:= M
.ReadByte() <> 0;
2415 {Resp :=} M
.ReadByte();
2416 X
:= M
.ReadLongInt();
2417 Y
:= M
.ReadLongInt();
2418 VX
:= M
.ReadLongInt();
2419 VY
:= M
.ReadLongInt();
2421 g_Items_Create(X
, Y
, T
, Fall
, False, False, ID
);
2423 it
:= g_Items_ByIdx(ID
);
2429 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2430 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2432 Anim
:= TAnimation
.Create(AID
, False, 4);
2433 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2439 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2444 if not gGameOn
then Exit
;
2446 Quiet
:= M
.ReadByte() <> 0;
2448 if not g_Items_ValidId(ID
) then exit
;
2450 if not Quiet
then g_Items_EmitPickupSound(ID
);
2457 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2465 if not gGameOn
then Exit
;
2466 {PType :=} M
.ReadWord();
2467 PGUID
:= Integer(M
.ReadLongWord());
2468 Tex
:= M
.ReadLongInt();
2469 Fr
:= M
.ReadLongInt();
2470 Cnt
:= M
.ReadByte();
2471 Loop
:= M
.ReadByte();
2473 TP
:= g_Map_PanelByGUID(PGUID
);
2477 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: if gWalls <> nil then TP := gWalls[ID];
2478 PANEL_FORE: if gRenderForegrounds <> nil then TP := gRenderForegrounds[ID];
2479 PANEL_BACK: if gRenderBackgrounds <> nil then TP := gRenderBackgrounds[ID];
2480 PANEL_WATER: if gWater <> nil then TP := gWater[ID];
2481 PANEL_ACID1: if gAcid1 <> nil then TP := gAcid1[ID];
2482 PANEL_ACID2: if gAcid2 <> nil then TP := gAcid2[ID];
2483 PANEL_STEP: if gSteps <> nil then TP := gSteps[ID];
2493 TP
.SetTexture(Tex
, Loop
);
2494 TP
.SetFrame(Fr
, Cnt
);
2498 // looped or non-looped animation
2499 TP
.NextTexture(Loop
);
2504 procedure MC_RECV_PanelState(var M
: TMsg
);
2510 X
, Y
, W
, H
: Integer;
2512 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2513 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2516 if not gGameOn
then Exit
;
2517 PType
:= M
.ReadWord();
2518 PGUID
:= Integer(M
.ReadLongWord());
2519 E
:= (M
.ReadByte() <> 0);
2520 Lift
:= M
.ReadByte();
2521 X
:= M
.ReadLongInt();
2522 Y
:= M
.ReadLongInt();
2526 speedX
:= M
.ReadLongInt();
2527 speedY
:= M
.ReadLongInt();
2528 startX
:= M
.ReadLongInt();
2529 startY
:= M
.ReadLongInt();
2530 endX
:= M
.ReadLongInt();
2531 endY
:= M
.ReadLongInt();
2532 sizeSpX
:= M
.ReadLongInt();
2533 sizeSpY
:= M
.ReadLongInt();
2534 sizeEX
:= M
.ReadLongInt();
2535 sizeEY
:= M
.ReadLongInt();
2536 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2539 {PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2540 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);}
2542 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
2543 g_Map_SetLiftGUID(PGUID
, Lift
);
2550 TP := g_Map_PanelByGUID(PGUID);
2555 TP.positionChanged();
2557 //gRenderBackgrounds[ID].X := X;
2558 //gRenderBackgrounds[ID].Y := Y;
2565 gRenderForegrounds[ID].X := X;
2566 gRenderForegrounds[ID].Y := Y;
2571 // update enabled/disabled state for all panels
2572 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2574 // update panel position, as it can be moved
2575 TP
:= g_Map_PanelByGUID(PGUID
);
2579 TP
.movingSpeedX
:= speedX
;
2580 TP
.movingSpeedY
:= speedY
;
2581 TP
.movingStartX
:= startX
;
2582 TP
.movingStartY
:= startY
;
2583 TP
.movingEndX
:= endX
;
2584 TP
.movingEndY
:= endY
;
2585 TP
.sizeSpeedX
:= sizeSpX
;
2586 TP
.sizeSpeedY
:= sizeSpY
;
2587 TP
.sizeEndX
:= sizeEX
;
2588 TP
.sizeEndY
:= sizeEY
;
2589 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2590 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2596 TP
.positionChanged();
2602 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2605 SPos
, SID
: LongWord;
2609 if not gGameOn
then Exit
;
2610 if gTriggers
= nil then Exit
;
2612 SID
:= M
.ReadLongWord();
2613 SPlaying
:= M
.ReadByte() <> 0;
2614 SPos
:= M
.ReadLongWord();
2615 SCount
:= M
.ReadLongInt();
2617 for I
:= Low(gTriggers
) to High(gTriggers
) do
2618 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2619 if gTriggers
[I
].ClientID
= SID
then
2620 with gTriggers
[I
] do
2624 if trigData
.trigLocal
then
2625 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), trigData
.trigVolume
/255.0)
2627 Sound
.PlayPanVolume((trigData
.trigPan
-127.0)/128.0, trigData
.trigVolume
/255.0);
2628 Sound
.SetPosition(SPos
);
2631 if Sound
.IsPlaying
then Sound
.Stop
;
2633 SoundPlayCount
:= SCount
;
2637 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2644 if not gGameOn
then Exit
;
2646 MName
:= M
.ReadString();
2647 MPlaying
:= M
.ReadByte() <> 0;
2648 MPos
:= M
.ReadLongWord();
2649 MPaused
:= M
.ReadByte() <> 0;
2653 gMusic
.SetByName(MName
);
2655 gMusic
.SetPosition(MPos
);
2656 gMusic
.SpecPause
:= MPaused
;
2659 if gMusic
.IsPlaying
then gMusic
.Stop
;
2664 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2667 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2668 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2673 Mon
:= g_Monsters_ByUID(ID
);
2677 MType
:= M
.ReadByte();
2678 MState
:= M
.ReadByte();
2679 MAnim
:= M
.ReadByte();
2680 MTarg
:= M
.ReadWord();
2681 MTargTime
:= M
.ReadLongInt();
2682 MBehav
:= M
.ReadByte();
2683 MSleep
:= M
.ReadLongInt();
2684 MHealth
:= M
.ReadLongInt();
2685 MAmmo
:= M
.ReadLongInt();
2687 X
:= M
.ReadLongInt();
2688 Y
:= M
.ReadLongInt();
2689 VX
:= M
.ReadLongInt();
2690 VY
:= M
.ReadLongInt();
2691 MDir
:= M
.ReadByte();
2693 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2694 Mon
:= g_Monsters_ByUID(ID
);
2701 MonsterAnim
:= MAnim
;
2702 MonsterTargetUID
:= MTarg
;
2703 MonsterTargetTime
:= MTargTime
;
2704 MonsterBehaviour
:= MBehav
;
2705 MonsterSleep
:= MSleep
;
2706 MonsterAmmo
:= MAmmo
;
2711 setPosition(X
, Y
); // this will call positionChanged();
2714 //positionChanged(); // this updates spatial accelerators
2718 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2725 Mon
:= g_Monsters_ByUID(ID
);
2731 X
:= M
.ReadLongInt();
2732 Y
:= M
.ReadLongInt();
2733 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2734 GameVelX
:= M
.ReadLongInt();
2735 GameVelY
:= M
.ReadLongInt();
2736 GameDirection
:= TDirection(M
.ReadByte());
2737 //positionChanged(); // this updates spatial accelerators
2741 procedure MC_RECV_MonsterState(var M
: TMsg
);
2744 MState
, MFAnm
: Byte;
2746 AnimRevert
: Boolean;
2749 Mon
:= g_Monsters_ByUID(ID
);
2750 if Mon
= nil then Exit
;
2752 MState
:= M
.ReadByte();
2753 MFAnm
:= M
.ReadByte();
2757 MonsterTargetUID
:= M
.ReadWord();
2758 MonsterTargetTime
:= M
.ReadLongInt();
2759 MonsterSleep
:= M
.ReadLongInt();
2760 MonsterHealth
:= M
.ReadLongInt();
2761 MonsterAmmo
:= M
.ReadLongInt();
2762 MonsterPain
:= M
.ReadLongInt();
2763 AnimRevert
:= M
.ReadByte() <> 0;
2764 FFireTime
:= M
.ReadLongInt();
2765 RevertAnim(AnimRevert
);
2767 if MonsterState
<> MState
then
2769 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then
2771 if (MState
= MONSTATE_DIE
) then
2773 if (MState
= MONSTATE_PAIN
) then
2774 MakeBloodSimple(Min(200, MonsterPain
));
2775 if (MState
= MONSTATE_ATTACK
) then
2777 if (MState
= MONSTATE_DEAD
) then
2780 SetState(MState
, MFAnm
);
2785 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2789 X
, Y
, VX
, VY
: Integer;
2793 Mon
:= g_Monsters_ByUID(ID
);
2794 if Mon
= nil then Exit
;
2796 X
:= M
.ReadLongInt();
2797 Y
:= M
.ReadLongInt();
2798 VX
:= M
.ReadLongInt();
2799 VY
:= M
.ReadLongInt();
2801 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2804 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2810 Mon
:= g_Monsters_ByUID(ID
);
2811 if Mon
= nil then Exit
;
2813 Mon
.MonsterRemoved
:= True;
2816 procedure MC_RECV_TimeSync(var M
: TMsg
);
2820 Time
:= M
.ReadLongWord();
2822 if gState
= STATE_INTERCUSTOM
then
2823 gServInterTime
:= Min(Time
, 255);
2826 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2830 Int1
, Int2
: SmallInt;
2832 EvID
:= M
.ReadByte();
2833 Int1
:= M
.ReadSmallInt();
2834 Int2
:= M
.ReadSmallInt();
2835 Str1
:= M
.ReadString();
2836 Str2
:= M
.ReadString();
2840 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2842 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2844 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2846 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2848 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2854 procedure MC_SEND_Info(Password
: string);
2858 NetOut
.Write(Byte(NET_MSG_INFO
));
2859 NetOut
.Write(GAME_VERSION
);
2860 NetOut
.Write(Password
);
2861 NetOut
.Write(gPlayer1Settings
.Name
);
2862 NetOut
.Write(gPlayer1Settings
.Model
);
2863 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2864 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2865 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2866 NetOut
.Write(gPlayer1Settings
.Team
);
2868 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2871 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2873 NetOut
.Write(Byte(NET_MSG_CHAT
));
2877 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2880 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
2882 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
2883 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
2887 procedure MC_SEND_PlayerPos();
2892 WeaponSelect
: Word = 0;
2895 if not gGameOn
then Exit
;
2896 if gPlayers
= nil then Exit
;
2897 if gPlayer1
= nil then Exit
;
2900 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2902 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2904 strafeDir
:= P1MoveButton
shr 4;
2905 P1MoveButton
:= P1MoveButton
and $0F;
2906 with gGameControls
.P1Control
do
2908 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 1
2909 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then P1MoveButton
:= 2
2910 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 0;
2913 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
2915 // new strafe mechanics
2916 if (strafeDir
= 0) then strafeDir
:= P1MoveButton
; // start strafing
2917 // now set direction according to strafe (reversed)
2918 if (strafeDir
= 2) then gPlayer1
.SetDirection(D_LEFT
)
2919 else if (strafeDir
= 1) then gPlayer1
.SetDirection(D_RIGHT
);
2923 if (P1MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then gPlayer1
.SetDirection(D_LEFT
)
2924 else if (P1MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then gPlayer1
.SetDirection(D_RIGHT
)
2925 else if P1MoveButton
<> 0 then gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2928 gPlayer1
.ReleaseKeys
;
2929 if P1MoveButton
= 1 then
2931 kByte
:= kByte
or NET_KEY_LEFT
;
2932 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2934 if P1MoveButton
= 2 then
2936 kByte
:= kByte
or NET_KEY_RIGHT
;
2937 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2939 if isKeyPressed(KeyUp
, KeyUp2
) then
2941 kByte
:= kByte
or NET_KEY_UP
;
2942 gPlayer1
.PressKey(KEY_UP
, 10000);
2944 if isKeyPressed(KeyDown
, KeyDown2
) then
2946 kByte
:= kByte
or NET_KEY_DOWN
;
2947 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2949 if isKeyPressed(KeyJump
, KeyJump2
) then
2951 kByte
:= kByte
or NET_KEY_JUMP
;
2952 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2954 if isKeyPressed(KeyFire
, KeyFire2
) then kByte
:= kByte
or NET_KEY_FIRE
;
2955 if isKeyPressed(KeyOpen
, KeyOpen2
) then kByte
:= kByte
or NET_KEY_OPEN
;
2956 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then kByte
:= kByte
or NET_KEY_NW
;
2957 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then kByte
:= kByte
or NET_KEY_PW
;
2958 for I
:= 0 to High(KeyWeapon
) do
2959 if isKeyPressed(KeyWeapon
[I
], KeyWeapon2
[I
]) then
2960 WeaponSelect
:= WeaponSelect
or Word(1 shl I
);
2962 // fix movebutton state
2963 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2966 kByte
:= NET_KEY_CHAT
;
2968 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2969 NetOut
.Write(gTime
);
2970 NetOut
.Write(kByte
);
2971 NetOut
.Write(Byte(gPlayer1
.Direction
));
2972 NetOut
.Write(WeaponSelect
);
2973 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2974 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2976 //kBytePrev := kByte;
2977 //kDirPrev := gPlayer1.Direction;
2980 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2982 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2983 NetOut
.Write(Byte(Start
));
2984 NetOut
.Write(Command
);
2985 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2988 procedure MC_SEND_PlayerSettings();
2990 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2991 NetOut
.Write(gPlayer1Settings
.Name
);
2992 NetOut
.Write(gPlayer1Settings
.Model
);
2993 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2994 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2995 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2996 NetOut
.Write(gPlayer1Settings
.Team
);
2998 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3001 procedure MC_SEND_FullStateRequest();
3003 NetOut
.Write(Byte(NET_MSG_REQFST
));
3005 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3008 procedure MC_SEND_CheatRequest(Kind
: Byte);
3010 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3013 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3015 procedure MC_SEND_RCONPassword(Password
: string);
3017 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3018 NetOut
.Write(Password
);
3020 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3022 procedure MC_SEND_RCONCommand(Cmd
: string);
3024 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3027 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3030 // i have no idea why all this stuff is in here
3032 function ReadFile(const FileName
: TFileName
): AByte
;
3034 FileStream
: TStream
;
3037 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), MSG_NOTIFY
);
3038 fname
:= findDiskWad(FileName
);
3039 if length(fname
) = 0 then
3041 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), MSG_FATALERROR
);
3042 SetLength(Result
, 0);
3045 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), MSG_NOTIFY
);
3047 FileStream
:= openDiskFileRO(fname
);
3049 if FileStream
.Size
> 0 then
3051 SetLength(Result
, FileStream
.Size
);
3052 FileStream
.Read(Result
[0], FileStream
.Size
);
3059 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
3063 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
3064 Result
.FileData
:= ReadFile(FileName
);
3065 Result
.FileSize
:= Length(Result
.FileData
);
3067 SetLength(Result
.ExternalResources
, ResList
.Count
);
3068 for i
:=0 to ResList
.Count
-1 do
3070 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
3071 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
3075 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
3077 ResultStream
: TMemoryStream
;
3079 ResultStream
:= TMemoryStream
.Create
;
3081 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
3082 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
3083 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
3085 SetLength(bytes
, ResultStream
.Size
);
3086 ResultStream
.Seek(0, soFromBeginning
);
3087 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3092 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
3094 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3095 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
3096 SetLength(Result
.FileData
, Result
.FileSize
);
3097 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
3100 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
3102 ResultStream
: TMemoryStream
;
3105 resCount
:= Length(MapDataMsg
.ExternalResources
);
3107 ResultStream
:= TMemoryStream
.Create
;
3109 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
3110 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
3111 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
3113 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
3114 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
3116 SetLength(bytes
, ResultStream
.Size
);
3117 ResultStream
.Seek(0, soFromBeginning
);
3118 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3123 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
3127 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3128 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3130 SetLength(Result
.FileData
, Result
.FileSize
);
3131 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3133 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3134 SetLength(Result
.ExternalResources
, resCount
);
3136 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3139 function IsValidFileName(const S
: String): Boolean;
3141 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3146 for I
:= 1 to Length(S
) do
3147 Result
:= Result
and (not(S
[I
] in Forbidden
));
3150 function IsValidFilePath(const S
: String): Boolean;
3155 if not IsValidFileName(S
) then exit
;
3156 if FileExists(S
) then exit
;
3157 I
:= LastDelimiter('\/', S
);
3159 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3164 procedure MC_SEND_MapRequest();
3166 NetOut
.Write(Byte(NET_MSG_MAP_REQUEST
));
3167 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3170 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3172 NetOut
.Write(Byte(NET_MSG_RES_REQUEST
));
3173 NetOut
.Write(resName
);
3174 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3177 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
3181 mapDataMsg
: TMapDataMsg
;
3183 e_WriteLog('NET: Received map request from ' +
3184 DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3186 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3187 peer
:= NetClients
[C
.ID
].Peer
;
3189 MapDataMsgToBytes(payload
, mapDataMsg
);
3190 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3193 mapDataMsg
.FileData
:= nil;
3194 mapDataMsg
.ExternalResources
:= nil;
3197 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
3202 resDataMsg
: TResDataMsg
;
3204 FileName
:= ExtractFileName(M
.ReadString());
3205 e_WriteLog('NET: Received res request: ' + FileName
+
3206 ' from ' + DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3208 if not IsValidFilePath(FileName
) then
3210 e_WriteLog('Invalid filename: ' + FileName
, MSG_WARNING
);
3214 peer
:= NetClients
[C
.ID
].Peer
;
3216 if gExternalResources
.IndexOf(FileName
) > -1 then
3218 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3219 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3220 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3222 ResDataMsgToBytes(payload
, resDataMsg
);
3223 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);