bd32f68095a8d15b13a788babc2188afc70dee20
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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
20 uses e_msg
, g_net
, g_triggers
, Classes
, SysUtils
, md5
;
64 NET_MSG_RCON_AUTH
= 191;
65 NET_MSG_RCON_CMD
= 192;
66 NET_MSG_TIME_SYNC
= 194;
67 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;
97 NET_EV_CHANGE_TEAM
= 3;
98 NET_EV_PLAYER_KICK
= 4;
99 NET_EV_PLAYER_BAN
= 5;
100 NET_EV_LMS_WARMUP
= 6;
101 NET_EV_LMS_SURVIVOR
= 7;
105 NET_EV_SCORE_MSG
= 11;
106 NET_EV_LMS_START
= 12;
108 NET_EV_TLMS_WIN
= 14;
109 NET_EV_LMS_LOSE
= 15;
110 NET_EV_LMS_DRAW
= 16;
111 NET_EV_KILLCOMBO
= 17;
112 NET_EV_PLAYER_TOUCH
= 18;
114 NET_EV_INTER_READY
= 20;
121 NET_VE_INPROGRESS
= 6;
128 NET_CHEAT_SUICIDE
= 1;
129 NET_CHEAT_SPECTATE
= 2;
132 NET_MAX_DIFFTIME
= 5000 div 36;
136 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
137 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
138 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
139 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
140 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
141 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
142 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
143 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
144 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
145 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
146 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
149 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
150 procedure MH_SEND_Info(ID
: Byte);
151 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
152 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
153 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
154 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
170 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_VoteEvent(EvType
: Byte;
189 StrArg1
: string = 'a'; StrArg2
: string = 'b';
190 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
191 ID
: Integer = NET_EVERYONE
);
193 // CLIENT MESSAGES //
196 procedure MC_RECV_Chat(var M
: TMsg
);
197 procedure MC_RECV_Effect(var M
: TMsg
);
198 procedure MC_RECV_Sound(var M
: TMsg
);
199 procedure MC_RECV_GameStats(var M
: TMsg
);
200 procedure MC_RECV_CoopStats(var M
: TMsg
);
201 procedure MC_RECV_GameEvent(var M
: TMsg
);
202 procedure MC_RECV_FlagEvent(var M
: TMsg
);
203 procedure MC_RECV_GameSettings(var M
: TMsg
);
205 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
206 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
207 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
208 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
209 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
210 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
211 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
212 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
214 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
215 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
217 procedure MC_RECV_PanelTexture(var M
: TMsg
);
218 procedure MC_RECV_PanelState(var M
: TMsg
);
220 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
221 procedure MC_RECV_MonsterPos(var M
: TMsg
);
222 procedure MC_RECV_MonsterState(var M
: TMsg
);
223 procedure MC_RECV_MonsterShot(var M
: TMsg
);
224 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
226 procedure MC_RECV_CreateShot(var M
: TMsg
);
227 procedure MC_RECV_UpdateShot(var M
: TMsg
);
228 procedure MC_RECV_DeleteShot(var M
: TMsg
);
230 procedure MC_RECV_TriggerSound(var M
: TMsg
);
231 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
233 procedure MC_RECV_TimeSync(var M
: TMsg
);
234 procedure MC_RECV_VoteEvent(var M
: TMsg
);
236 procedure MC_SEND_Info(Password
: string);
237 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
238 procedure MC_SEND_PlayerPos();
239 procedure MC_SEND_FullStateRequest();
240 procedure MC_SEND_PlayerSettings();
241 procedure MC_SEND_CheatRequest(Kind
: Byte);
242 procedure MC_SEND_RCONPassword(Password
: string);
243 procedure MC_SEND_RCONCommand(Cmd
: string);
244 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
246 //procedure MC_SEND_MapRequest();
247 //procedure MC_SEND_ResRequest(const resName: AnsiString);
251 TExternalResourceInfo
= record
266 ExternalResources
: array of TExternalResourceInfo
;
269 function IsValidFileName(const S
: String): Boolean;
270 function IsValidFilePath(const S
: String): Boolean;
275 Math
, ENet
, e_input
, e_graphics
, e_log
,
276 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
277 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
278 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
291 NET_KEY_FORCEDIR
= 4096;
294 //kBytePrev: Word = 0;
295 //kDirPrev: TDirection = D_LEFT;
296 //HostGameTime: Word = 0;
303 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
311 Pl
:= g_Player_Get(PID
);
313 Txt
:= M
.ReadString();
314 Mode
:= M
.ReadByte();
315 if (Mode
= NET_CHAT_SYSTEM
) then
316 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
317 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
318 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
321 MH_SEND_Chat(Txt
, Mode
)
323 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
326 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
328 Ver
, PName
, Model
, Pw
: string;
334 Ver
:= M
.ReadString();
335 Pw
:= M
.ReadString();
336 PName
:= M
.ReadString();
337 Model
:= M
.ReadString();
343 if Ver
<> GAME_VERSION
then
345 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
346 _lc
[I_NET_DISC_VERSION
]);
347 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
351 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
353 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
355 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
356 _lc
[I_NET_DISC_BAN
]);
357 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
361 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
362 _lc
[I_NET_DISC_BAN
]);
363 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
368 if NetPassword
<> '' then
369 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
371 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
372 _lc
[I_NET_DISC_PASSWORD
]);
373 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
381 PID
:= g_Player_Create(Model
, Color
, T
, False);
382 with g_Player_Get(PID
) do
390 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
391 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
392 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
396 with g_Player_Get(PID
) do
400 // round in progress, don't spawn
401 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
406 FWantsInGame
:= True; // TODO: look into this later
409 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
412 for I
:= Low(NetClients
) to High(NetClients
) do
414 if NetClients
[I
].ID
= C
^.ID
then Continue
;
415 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
416 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
417 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
420 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
421 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
423 if NetUseMaster
then g_Net_Slist_Update
;
426 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
429 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
431 C
^.RequestedFullUpdate
:= True;
436 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
446 if not gGameOn
then Exit
;
448 GT
:= M
.ReadLongWord();
450 Pl
:= g_Player_Get(PID
);
454 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
459 kByte
:= M
.ReadWord();
461 WeaponSelect
:= M
.ReadWord();
462 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
463 if Direction
<> TDirection(Dir
) then
464 JustTeleported
:= False;
466 SetDirection(TDirection(Dir
));
469 if kByte
= NET_KEY_CHAT
then
471 PressKey(KEY_CHAT
, 10000);
475 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
476 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
477 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
478 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
479 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
480 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
481 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
482 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
483 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
487 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
489 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
490 QueueWeaponSwitch(i
);
495 // MH_SEND_PlayerPos(False, PID, C^.ID);
498 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
503 Pl
:= g_Player_Get(C
^.Player
);
504 if Pl
= nil then Exit
;
506 CheatKind
:= M
.ReadByte();
510 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
513 if Pl
.FSpectator
then
520 if gState
<> STATE_INTERCUSTOM
then Exit
;
521 Pl
.FReady
:= not Pl
.FReady
;
524 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
525 Inc(gInterReadyCount
);
529 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
530 Dec(gInterReadyCount
);
536 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
544 TmpName
:= M
.ReadString();
545 TmpModel
:= M
.ReadString();
546 TmpColor
.R
:= M
.ReadByte();
547 TmpColor
.G
:= M
.ReadByte();
548 TmpColor
.B
:= M
.ReadByte();
549 TmpTeam
:= M
.ReadByte();
551 Pl
:= g_Player_Get(C
^.Player
);
552 if Pl
= nil then Exit
;
554 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
557 Pl
.SetColor(TmpColor
);
559 if Pl
.Name
<> TmpName
then
561 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
565 if TmpModel
<> Pl
.Model
.Name
then
566 Pl
.SetModel(TmpModel
);
568 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
573 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
577 Pwd
:= M
.ReadString();
578 if not NetAllowRCON
then Exit
;
579 if Pwd
= NetRCONPassword
then
582 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
585 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
588 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
592 Cmd
:= M
.ReadString();
593 if not NetAllowRCON
then Exit
;
594 if not C
^.RCONAuth
then
596 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
599 g_Console_Process(Cmd
);
604 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
607 Name
, Command
: string;
611 Start
:= M
.ReadByte() <> 0;
612 Command
:= M
.ReadString();
614 Pl
:= g_Player_Get(C
^.Player
);
615 if Pl
= nil then Exit
;
620 if not g_Console_CommandBlacklisted(Command
) then
621 g_Game_StartVote(Command
, Name
);
623 else if gVoteInProgress
then
625 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
626 Need
:= Floor((NetClientCount
+1)/2.0) + 1
628 Need
:= Floor(NetClientCount
/2.0) + 1;
633 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
634 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
640 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
641 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
649 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
651 function sendItemRespawn (it
: PItem
): Boolean;
653 result
:= false; // don't stop
654 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
657 function sendMonSpawn (mon
: TMonster
): Boolean;
659 result
:= false; // don't stop
660 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
663 function sendPanelState (pan
: TPanel
): Boolean;
665 result
:= false; // don't stop
666 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
667 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
673 if gPlayers
<> nil then
675 for I
:= Low(gPlayers
) to High(gPlayers
) do
677 if gPlayers
[I
] <> nil then
679 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
680 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
681 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
683 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
685 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
691 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
692 g_Mons_ForEach(sendMonSpawn
);
693 g_Map_ForEachPanel(sendPanelState
);
695 if gTriggers
<> nil then
697 for I
:= Low(gTriggers
) to High(gTriggers
) do
699 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
701 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
708 for I
:= Low(Shots
) to High(Shots
) do
710 if Shots
[i
].ShotType
in [6, 7, 8] then
712 MH_SEND_CreateShot(i
, ID
);
717 MH_SEND_TriggerMusic(ID
);
719 MH_SEND_GameStats(ID
);
720 MH_SEND_CoopStats(ID
);
722 if gGameSettings
.GameMode
= GM_CTF
then
724 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
725 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
728 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
730 if gLMSRespawn
> LMS_RESPAWN_NONE
then
732 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
738 procedure MH_SEND_Info(ID
: Byte);
742 Map
:= g_ExtractFileName(gMapInfo
.Map
);
746 NetOut
.Write(Byte(NET_MSG_INFO
));
748 NetOut
.Write(NetClients
[ID
].Player
);
749 NetOut
.Write(gGameSettings
.WAD
);
751 NetOut
.Write(gWADHash
);
752 NetOut
.Write(gGameSettings
.GameMode
);
753 NetOut
.Write(gGameSettings
.GoalLimit
);
754 NetOut
.Write(gGameSettings
.TimeLimit
);
755 NetOut
.Write(gGameSettings
.MaxLives
);
756 NetOut
.Write(gGameSettings
.Options
);
759 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
762 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
768 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
769 Mode
:= NET_CHAT_PLAYER
;
772 if (Mode
= NET_CHAT_TEAM
) then
774 for i
:= Low(gPlayers
) to High(gPlayers
) do
775 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
776 (gPlayers
[i
].Team
= ID
) then
778 NetOut
.Write(Byte(NET_MSG_CHAT
));
781 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
788 NetOut
.Write(Byte(NET_MSG_CHAT
));
791 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
794 if Mode
= NET_CHAT_SYSTEM
then
797 if ID
= NET_EVERYONE
then
799 if Mode
= NET_CHAT_PLAYER
then
801 g_Console_Add(Txt
, True);
802 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
803 g_Game_ChatSound(b_Text_Unformat(Txt
));
806 if Mode
= NET_CHAT_TEAM
then
807 if gPlayer1
<> nil then
809 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
811 g_Console_Add(#18'[Team] '#2 + Txt
, True);
812 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
813 g_Game_ChatSound(b_Text_Unformat(Txt
));
815 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
817 g_Console_Add(#20'[Team] '#2 + Txt
, True);
818 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
819 g_Game_ChatSound(b_Text_Unformat(Txt
));
825 Name
:= g_Net_ClientName_ByID(ID
);
826 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
827 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
828 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
832 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
834 NetOut
.Write(Byte(NET_MSG_GFX
));
840 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
843 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
845 NetOut
.Write(Byte(NET_MSG_SND
));
849 NetOut
.Write(Byte(1));
854 NetOut
.Write(Byte(0));
856 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
859 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
861 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
863 NetOut
.Write(Byte(NET_MSG_SHADD
));
865 NetOut
.Write(Shots
[Proj
].ShotType
);
866 NetOut
.Write(Shots
[Proj
].Target
);
867 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
868 NetOut
.Write(Shots
[Proj
].Timeout
);
869 NetOut
.Write(Shots
[Proj
].Obj
.X
);
870 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
871 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
872 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
874 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
877 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
879 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
881 NetOut
.Write(Byte(NET_MSG_SHPOS
));
883 NetOut
.Write(Shots
[Proj
].Obj
.X
);
884 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
885 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
886 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
888 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
891 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
893 NetOut
.Write(Byte(NET_MSG_SHDEL
));
895 NetOut
.Write(Byte(Loud
));
899 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
902 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
904 NetOut
.Write(Byte(NET_MSG_SCORE
));
905 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
907 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
908 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
911 if gGameSettings
.GameMode
= GM_COOP
then
913 NetOut
.Write(gCoopMonstersKilled
);
914 NetOut
.Write(gCoopSecretsFound
);
917 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
920 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
922 NetOut
.Write(Byte(NET_MSG_COOP
));
923 NetOut
.Write(gTotalMonsters
);
924 NetOut
.Write(gSecretsCount
);
925 NetOut
.Write(gCoopTotalMonstersKilled
);
926 NetOut
.Write(gCoopTotalSecretsFound
);
927 NetOut
.Write(gCoopTotalMonsters
);
928 NetOut
.Write(gCoopTotalSecrets
);
931 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
933 NetOut
.Write(Byte(NET_MSG_GEVENT
));
934 NetOut
.Write(EvType
);
937 NetOut
.Write(Byte(gLastMap
));
939 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
941 NetOut
.Write(Byte(1));
942 NetOut
.Write(gWADHash
);
944 NetOut
.Write(Byte(0));
946 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
949 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
951 NetOut
.Write(Byte(NET_MSG_FLAG
));
952 NetOut
.Write(EvType
);
954 NetOut
.Write(Byte(Quiet
));
956 NetOut
.Write(gFlags
[Flag
].State
);
957 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
958 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
959 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
960 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
961 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
963 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
966 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
968 NetOut
.Write(Byte(NET_MSG_GSET
));
969 NetOut
.Write(gGameSettings
.GameMode
);
970 NetOut
.Write(gGameSettings
.GoalLimit
);
971 NetOut
.Write(gGameSettings
.TimeLimit
);
972 NetOut
.Write(gGameSettings
.MaxLives
);
973 NetOut
.Write(gGameSettings
.Options
);
975 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
980 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
984 P
:= g_Player_Get(PID
);
985 if P
= nil then Exit
;
987 NetOut
.Write(Byte(NET_MSG_PLR
));
989 NetOut
.Write(P
.Name
);
991 NetOut
.Write(P
.FActualModelName
);
992 NetOut
.Write(P
.FColor
.R
);
993 NetOut
.Write(P
.FColor
.G
);
994 NetOut
.Write(P
.FColor
.B
);
995 NetOut
.Write(P
.Team
);
997 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1000 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1005 Pl
:= g_Player_Get(PID
);
1006 if Pl
= nil then Exit
;
1007 if Pl
.FDummy
then Exit
;
1009 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1010 NetOut
.Write(gTime
);
1017 NetOut
.Write(FPing
);
1018 NetOut
.Write(FLoss
);
1019 if IsKeyPressed(KEY_CHAT
) then
1020 kByte
:= NET_KEY_CHAT
1023 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1024 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1025 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1026 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1027 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1028 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1031 NetOut
.Write(kByte
);
1032 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1033 NetOut
.Write(GameX
);
1034 NetOut
.Write(GameY
);
1035 NetOut
.Write(GameVelX
);
1036 NetOut
.Write(GameVelY
);
1037 NetOut
.Write(GameAccelX
);
1038 NetOut
.Write(GameAccelY
);
1041 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1044 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1049 P
:= g_Player_Get(PID
);
1050 if P
= nil then Exit
;
1052 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1057 NetOut
.Write(Byte(alive
));
1058 NetOut
.Write(Byte(GodMode
));
1059 NetOut
.Write(Health
);
1060 NetOut
.Write(Armor
);
1062 NetOut
.Write(JetFuel
);
1063 NetOut
.Write(Lives
);
1066 for I
:= WP_FIRST
to WP_LAST
do
1067 NetOut
.Write(Byte(FWeapon
[I
]));
1069 for I
:= A_BULLETS
to A_HIGH
do
1070 NetOut
.Write(FAmmo
[I
]);
1072 for I
:= A_BULLETS
to A_HIGH
do
1073 NetOut
.Write(FMaxAmmo
[I
]);
1075 for I
:= MR_SUIT
to MR_MAX
do
1076 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1078 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1079 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1080 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1081 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1082 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1084 NetOut
.Write(Frags
);
1085 NetOut
.Write(Death
);
1087 NetOut
.Write(CurrWeap
);
1089 NetOut
.Write(Byte(FSpectator
));
1090 NetOut
.Write(Byte(FGhost
));
1091 NetOut
.Write(Byte(FPhysics
));
1092 NetOut
.Write(Byte(FNoRespawn
));
1093 NetOut
.Write(Byte(FJetpack
));
1094 NetOut
.Write(FFireTime
);
1095 NetOut
.Write(Byte(FFlaming
));
1098 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1101 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1103 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1106 NetOut
.Write(Attacker
);
1107 NetOut
.Write(Value
);
1111 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1114 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1116 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1118 NetOut
.Write(KillType
);
1119 NetOut
.Write(DeathType
);
1120 NetOut
.Write(Attacker
);
1122 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1125 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1127 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1129 NetOut
.Write(Weapon
);
1134 NetOut
.Write(ShotID
);
1136 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1139 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1141 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1144 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1147 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1151 Pl
:= g_Player_Get(PID
);
1152 if Pl
= nil then Exit
;
1154 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1156 NetOut
.Write(Pl
.Name
);
1158 NetOut
.Write(Pl
.Model
.Name
)
1161 NetOut
.Write(Pl
.FColor
.R
);
1162 NetOut
.Write(Pl
.FColor
.G
);
1163 NetOut
.Write(Pl
.FColor
.B
);
1164 NetOut
.Write(Pl
.Team
);
1166 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1171 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1176 it
:= g_Items_ByIdx(IID
);
1178 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1180 NetOut
.Write(Byte(Quiet
));
1182 if it
.dropped
then tt
:= tt
or $80;
1184 NetOut
.Write(Byte(it
.Fall
));
1185 NetOut
.Write(Byte(it
.Respawnable
));
1186 NetOut
.Write(it
.Obj
.X
);
1187 NetOut
.Write(it
.Obj
.Y
);
1188 NetOut
.Write(it
.Obj
.Vel
.X
);
1189 NetOut
.Write(it
.Obj
.Vel
.Y
);
1191 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1194 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1196 NetOut
.Write(Byte(NET_MSG_IDEL
));
1198 NetOut
.Write(Byte(Quiet
));
1200 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1205 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1209 TP
:= g_Map_PanelByGUID(PGUID
);
1210 if (TP
= nil) then exit
;
1214 NetOut
.Write(Byte(NET_MSG_PTEX
));
1215 NetOut
.Write(LongWord(PGUID
));
1216 NetOut
.Write(FCurTexture
);
1217 NetOut
.Write(FCurFrame
);
1218 NetOut
.Write(FCurFrameCount
);
1219 NetOut
.Write(AnimLoop
);
1222 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1225 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1230 TP
:= g_Map_PanelByGUID(PGUID
);
1231 if (TP
= nil) then exit
;
1233 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1234 NetOut
.Write(LongWord(PGUID
));
1235 NetOut
.Write(Byte(TP
.Enabled
));
1236 NetOut
.Write(TP
.LiftType
);
1239 NetOut
.Write(Word(TP
.Width
));
1240 NetOut
.Write(Word(TP
.Height
));
1242 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1243 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1244 NetOut
.Write(LongInt(TP
.movingStartX
));
1245 NetOut
.Write(LongInt(TP
.movingStartY
));
1246 NetOut
.Write(LongInt(TP
.movingEndX
));
1247 NetOut
.Write(LongInt(TP
.movingEndY
));
1248 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1249 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1250 NetOut
.Write(LongInt(TP
.sizeEndX
));
1251 NetOut
.Write(LongInt(TP
.sizeEndY
));
1252 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1253 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1254 NetOut
.Write(Byte(mpflags
));
1256 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1261 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1263 if gTriggers
= nil then Exit
;
1264 if T
.Sound
= nil then Exit
;
1266 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1267 NetOut
.Write(T
.ClientID
);
1268 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1269 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1270 NetOut
.Write(T
.SoundPlayCount
);
1272 g_Net_Host_Send(ID
, True);
1275 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1277 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1278 NetOut
.Write(gMusic
.Name
);
1279 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1280 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1281 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1283 g_Net_Host_Send(ID
, True);
1288 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1292 M
:= g_Monsters_ByUID(UID
);
1298 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1300 NetOut
.Write(MonsterType
);
1301 NetOut
.Write(MonsterState
);
1302 NetOut
.Write(MonsterAnim
);
1303 NetOut
.Write(MonsterTargetUID
);
1304 NetOut
.Write(MonsterTargetTime
);
1305 NetOut
.Write(MonsterBehaviour
);
1306 NetOut
.Write(MonsterSleep
);
1307 NetOut
.Write(MonsterHealth
);
1308 NetOut
.Write(MonsterAmmo
);
1309 NetOut
.Write(GameX
);
1310 NetOut
.Write(GameY
);
1311 NetOut
.Write(GameVelX
);
1312 NetOut
.Write(GameVelY
);
1313 NetOut
.Write(Byte(GameDirection
));
1316 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1319 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1323 M
:= g_Monsters_ByUID(UID
);
1324 if M
= nil then Exit
;
1326 NetOut
.Write(Byte(NET_MSG_MPOS
));
1331 NetOut
.Write(GameX
);
1332 NetOut
.Write(GameY
);
1333 NetOut
.Write(GameVelX
);
1334 NetOut
.Write(GameVelY
);
1335 NetOut
.Write(Byte(GameDirection
));
1338 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1341 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1345 M
:= g_Monsters_ByUID(UID
);
1346 if M
= nil then Exit
;
1348 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1353 NetOut
.Write(MonsterState
);
1354 NetOut
.Write(ForcedAnim
);
1355 NetOut
.Write(MonsterTargetUID
);
1356 NetOut
.Write(MonsterTargetTime
);
1357 NetOut
.Write(MonsterSleep
);
1358 NetOut
.Write(MonsterHealth
);
1359 NetOut
.Write(MonsterAmmo
);
1360 NetOut
.Write(MonsterPain
);
1361 NetOut
.Write(Byte(AnimIsReverse
));
1362 NetOut
.Write(FFireTime
);
1365 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1368 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1370 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1377 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1380 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1384 M
:= g_Monsters_ByUID(UID
);
1385 if M
= nil then Exit
;
1387 NetOut
.Write(Byte(NET_MSG_MDEL
));
1390 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1395 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1397 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1400 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1403 procedure MH_SEND_VoteEvent(EvType
: Byte;
1404 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1405 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1406 ID
: Integer = NET_EVERYONE
);
1408 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1409 NetOut
.Write(EvType
);
1410 NetOut
.Write(IntArg1
);
1411 NetOut
.Write(IntArg2
);
1412 NetOut
.Write(StrArg1
);
1413 NetOut
.Write(StrArg2
);
1415 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1418 // CLIENT MESSAGES //
1422 procedure MC_RECV_Chat(var M
: TMsg
);
1427 Txt
:= M
.ReadString();
1428 Mode
:= M
.ReadByte();
1430 if Mode
<> NET_CHAT_SYSTEM
then
1432 if Mode
= NET_CHAT_PLAYER
then
1434 g_Console_Add(Txt
, True);
1435 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1436 g_Game_ChatSound(b_Text_Unformat(Txt
));
1438 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1440 if gPlayer1
.Team
= TEAM_RED
then
1441 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1442 if gPlayer1
.Team
= TEAM_BLUE
then
1443 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1444 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1445 g_Game_ChatSound(b_Text_Unformat(Txt
));
1448 g_Console_Add(Txt
, True);
1451 procedure MC_RECV_Effect(var M
: TMsg
);
1459 if not gGameOn
then Exit
;
1460 Kind
:= M
.ReadByte();
1461 X
:= M
.ReadLongInt();
1462 Y
:= M
.ReadLongInt();
1463 Ang
:= M
.ReadSmallInt();
1467 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1471 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1473 Anim
:= TAnimation
.Create(ID
, False, 3);
1474 g_GFX_OnceAnim(X
, Y
, Anim
);
1478 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1483 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1485 Anim
:= TAnimation
.Create(ID
, False, 6);
1486 Anim
.Blending
:= False;
1487 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1491 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1496 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1498 Anim
:= TAnimation
.Create(ID
, False, 6);
1499 Anim
.Blending
:= False;
1500 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1504 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1509 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1511 Anim
:= TAnimation
.Create(ID
, False, 4);
1512 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1519 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1521 Anim
:= TAnimation
.Create(ID
, False, 4);
1522 g_GFX_OnceAnim(X
, Y
, Anim
);
1526 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1531 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1533 Anim
:= TAnimation
.Create(ID
, False, 4);
1534 g_GFX_OnceAnim(X
, Y
, Anim
);
1538 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1542 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1545 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1549 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1550 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1555 procedure MC_RECV_Sound(var M
: TMsg
);
1561 Name
:= M
.ReadString();
1562 Pos
:= M
.ReadByte() <> 0;
1565 X
:= M
.ReadLongInt();
1566 Y
:= M
.ReadLongInt();
1567 g_Sound_PlayExAt(Name
, X
, Y
);
1570 g_Sound_PlayEx(Name
);
1573 procedure MC_RECV_CreateShot(var M
: TMsg
);
1575 I
, X
, Y
, XV
, YV
: Integer;
1577 Target
, Spawner
: Word;
1580 I
:= M
.ReadLongInt();
1581 ShType
:= M
.ReadByte();
1582 Target
:= M
.ReadWord();
1583 Spawner
:= M
.ReadWord();
1584 Timeout
:= M
.ReadLongWord();
1585 X
:= M
.ReadLongInt();
1586 Y
:= M
.ReadLongInt();
1587 XV
:= M
.ReadLongInt();
1588 YV
:= M
.ReadLongInt();
1590 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1591 if (Shots
<> nil) and (I
<= High(Shots
)) then
1593 Shots
[I
].Timeout
:= Timeout
;
1594 //Shots[I].Target := Target; // TODO: find a use for Target later
1598 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1600 I
, TX
, TY
, TXV
, TYV
: Integer;
1602 I
:= M
.ReadLongInt();
1603 TX
:= M
.ReadLongInt();
1604 TY
:= M
.ReadLongInt();
1605 TXV
:= M
.ReadLongInt();
1606 TYV
:= M
.ReadLongInt();
1608 if (Shots
<> nil) and (I
<= High(Shots
)) then
1618 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1623 if not gGameOn
then Exit
;
1624 I
:= M
.ReadLongInt();
1625 L
:= (M
.ReadByte() <> 0);
1626 X
:= M
.ReadLongInt();
1627 Y
:= M
.ReadLongInt();
1629 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1632 procedure MC_RECV_GameStats(var M
: TMsg
);
1634 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1636 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1637 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1640 if gGameSettings
.GameMode
= GM_COOP
then
1642 gCoopMonstersKilled
:= M
.ReadWord();
1643 gCoopSecretsFound
:= M
.ReadWord();
1647 procedure MC_RECV_CoopStats(var M
: TMsg
);
1649 gTotalMonsters
:= M
.ReadLongInt();
1650 gSecretsCount
:= M
.ReadLongInt();
1651 gCoopTotalMonstersKilled
:= M
.ReadWord();
1652 gCoopTotalSecretsFound
:= M
.ReadWord();
1653 gCoopTotalMonsters
:= M
.ReadWord();
1654 gCoopTotalSecrets
:= M
.ReadWord();
1657 procedure MC_RECV_GameEvent(var M
: TMsg
);
1666 i1
, i2
: TStrings_Locale
;
1669 goodCmd
: Boolean = true;
1671 FillChar(EvHash
, Sizeof(EvHash
), 0);
1672 EvType
:= M
.ReadByte();
1673 EvNum
:= M
.ReadLongInt();
1674 EvStr
:= M
.ReadString();
1675 gLastMap
:= M
.ReadByte() <> 0;
1676 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1677 gStatsPressed
:= True;
1678 EvTime
:= M
.ReadLongWord();
1679 BHash
:= M
.ReadByte() <> 0;
1681 EvHash
:= M
.ReadMD5();
1685 if (g_Res_received_map_start
<> 0) then
1687 if (g_Res_received_map_start
< 0) then exit
;
1690 NET_EV_MAPSTART
: goodCmd
:= true;
1691 NET_EV_MAPEND
: goodCmd
:= true;
1692 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1693 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1695 if not goodCmd
then exit
;
1701 if (g_Res_received_map_start
<> 0) then
1703 g_Res_received_map_start
:= -1;
1708 g_Game_ClearLoading();
1709 g_Game_StopAllSounds(True);
1711 gSwitchGameMode
:= Byte(EvNum
);
1712 gGameSettings
.GameMode
:= gSwitchGameMode
;
1715 if not g_Game_StartMap(EvStr
, True) then
1717 if not isWadPath(EvStr
) then
1718 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1720 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1724 MC_SEND_FullStateRequest
;
1730 if (g_Res_received_map_start
<> 0) then
1732 g_Res_received_map_start
:= -1;
1736 gMissionFailed
:= EvNum
<> 0;
1737 gExit
:= EXIT_ENDLEVELCUSTOM
;
1745 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1747 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1749 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1755 if EvNum
= TEAM_RED
then
1756 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1757 if EvNum
= TEAM_BLUE
then
1758 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1763 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1764 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1769 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1770 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1774 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1776 NET_EV_LMS_SURVIVOR
:
1777 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1780 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1784 pl
:= g_Player_Get(EvNum
and $FFFF);
1789 cnt
:= (EvNum
shr 16) and $FF;
1790 if Pos('w', EvStr
) = 0 then
1793 if Pos('t', EvStr
) = 0 then
1796 if Pos('-', EvStr
) = 0 then
1798 if Pos('e', EvStr
) = 0 then
1799 i1
:= I_PLAYER_SCORE_ADD_OWN
1801 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1804 if Pos('e', EvStr
) = 0 then
1805 i1
:= I_PLAYER_SCORE_SUB_OWN
1807 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1810 if Pos('r', EvStr
) > 0 then
1811 i2
:= I_PLAYER_SCORE_TO_RED
1813 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1814 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1818 if Pos('-', EvStr
) = 0 then
1819 i1
:= I_PLAYER_SCORE_ADD_TEAM
1821 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1823 if Pos('r', EvStr
) > 0 then
1824 i2
:= I_PLAYER_SCORE_RED
1826 i2
:= I_PLAYER_SCORE_BLUE
;
1827 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1832 if Pos('e', EvStr
) = 0 then
1833 i1
:= I_PLAYER_SCORE_WIN_OWN
1835 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1837 if Pos('r', EvStr
) > 0 then
1838 i2
:= I_PLAYER_SCORE_TO_RED
1840 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1841 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1847 if EvNum
= TEAM_RED
then
1848 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1849 if EvNum
= TEAM_BLUE
then
1850 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1851 if EvNum
= -TEAM_RED
then
1852 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1853 if EvNum
= -TEAM_BLUE
then
1854 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1859 g_Player_RemoveAllCorpses
;
1860 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1864 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1868 if EvNum
= TEAM_RED
then
1869 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1870 if EvNum
= TEAM_BLUE
then
1871 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1875 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1878 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1881 g_Game_Announce_KillCombo(EvNum
);
1883 NET_EV_PLAYER_TOUCH
:
1885 pl
:= g_Player_Get(EvNum
);
1892 pl
:= g_Player_Get(EvNum
);
1895 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
1896 g_Sound_PlayEx('SOUND_GAME_SECRET');
1902 pl
:= g_Player_Get(EvNum
);
1903 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
1908 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1917 EvType
:= M
.ReadByte();
1920 if Fl
= FLAG_NONE
then Exit
;
1922 Quiet
:= (M
.ReadByte() <> 0);
1923 PID
:= M
.ReadWord();
1925 gFlags
[Fl
].State
:= M
.ReadByte();
1926 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1927 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1928 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1929 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1930 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1932 Pl
:= g_Player_Get(PID
);
1934 (EvType
<> FLAG_STATE_NORMAL
) and
1935 (EvType
<> FLAG_STATE_DROPPED
) and
1936 (EvType
<> FLAG_STATE_RETURNED
) then
1942 if Quiet
or (Pl
= nil) then Exit
;
1944 if Fl
= FLAG_RED
then
1945 s
:= _lc
[I_PLAYER_FLAG_RED
]
1947 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1949 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1951 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1952 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1953 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1958 if not sound_ret_flag
[a
].IsPlaying() then
1959 sound_ret_flag
[a
].Play();
1962 FLAG_STATE_CAPTURED
:
1964 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1968 if Fl
= FLAG_RED
then
1969 s
:= _lc
[I_PLAYER_FLAG_RED
]
1971 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1973 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1974 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1976 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1977 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1978 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1983 if not sound_get_flag
[a
].IsPlaying() then
1984 sound_get_flag
[a
].Play();
1989 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1991 if Quiet
or (Pl
= nil) then Exit
;
1993 if Fl
= FLAG_RED
then
1994 s
:= _lc
[I_PLAYER_FLAG_RED
]
1996 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1998 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1999 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2001 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2002 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2003 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2008 if not sound_lost_flag
[a
].IsPlaying() then
2009 sound_lost_flag
[a
].Play();
2014 g_Map_ResetFlag(FLAG_RED
);
2015 g_Map_ResetFlag(FLAG_BLUE
);
2016 if Quiet
or (Pl
= nil) then Exit
;
2017 Pl
.SetFlag(FLAG_NONE
);
2019 if Fl
= FLAG_RED
then
2020 s
:= _lc
[I_PLAYER_FLAG_RED
]
2022 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2024 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2025 Insert('.', ts
, Length(ts
) + 1 - 3);
2026 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2027 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2029 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2030 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2031 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2036 if not sound_cap_flag
[a
].IsPlaying() then
2037 sound_cap_flag
[a
].Play();
2040 FLAG_STATE_RETURNED
:
2042 g_Map_ResetFlag(Fl
);
2045 if Fl
= FLAG_RED
then
2046 s
:= _lc
[I_PLAYER_FLAG_RED
]
2048 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2050 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2052 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2053 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2054 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2059 if not sound_ret_flag
[a
].IsPlaying() then
2060 sound_ret_flag
[a
].Play();
2065 procedure MC_RECV_GameSettings(var M
: TMsg
);
2067 gGameSettings
.GameMode
:= M
.ReadByte();
2068 gGameSettings
.GoalLimit
:= M
.ReadWord();
2069 gGameSettings
.TimeLimit
:= M
.ReadWord();
2070 gGameSettings
.MaxLives
:= M
.ReadByte();
2071 gGameSettings
.Options
:= M
.ReadLongWord();
2076 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2079 PName
, Model
: string;
2084 PID
:= M
.ReadWord();
2085 Pl
:= g_Player_Get(PID
);
2087 PName
:= M
.ReadString();
2088 Model
:= M
.ReadString();
2089 Color
.R
:= M
.ReadByte();
2090 Color
.G
:= M
.ReadByte();
2091 Color
.B
:= M
.ReadByte();
2095 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2097 if (Pl
<> nil) then Exit
;
2098 DID
:= g_Player_Create(Model
, Color
, T
, False);
2099 with g_Player_Get(DID
) do
2108 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2109 gPlayer1
.UID
:= PID
;
2110 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2111 gPlayer1
.ChangeTeam(T
);
2113 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2114 gPlayer2
.UID
:= PID
;
2115 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2116 gPlayer2
.ChangeTeam(T
);
2120 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2121 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2125 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2132 TmpX
, TmpY
: Integer;
2136 GT
:= M
.ReadLongWord();
2137 if GT
< gTime
- NET_MAX_DIFFTIME
then
2144 PID
:= M
.ReadWord();
2145 Pl
:= g_Player_Get(PID
);
2147 if Pl
= nil then Exit
;
2153 FPing
:= M
.ReadWord();
2154 FLoss
:= M
.ReadByte();
2155 kByte
:= M
.ReadWord();
2156 Dir
:= M
.ReadByte();
2158 TmpX
:= M
.ReadLongInt();
2159 TmpY
:= M
.ReadLongInt();
2163 if (kByte
= NET_KEY_CHAT
) then
2164 PressKey(KEY_CHAT
, 10000)
2167 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2168 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2169 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2170 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2171 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2174 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2175 SetDirection(TDirection(Dir
));
2177 GameVelX
:= M
.ReadLongInt();
2178 GameVelY
:= M
.ReadLongInt();
2179 GameAccelX
:= M
.ReadLongInt();
2180 GameAccelY
:= M
.ReadLongInt();
2181 SetLerp(TmpX
, TmpY
);
2182 if NetForcePlayerUpdate
then Update();
2186 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2190 I
, OldFire
: Integer;
2191 OldJet
, Flam
: Boolean;
2194 PID
:= M
.ReadWord();
2195 Pl
:= g_Player_Get(PID
);
2202 alive
:= (M
.ReadByte() <> 0);
2203 GodMode
:= (M
.ReadByte() <> 0);
2204 Health
:= M
.ReadLongInt();
2205 Armor
:= M
.ReadLongInt();
2206 Air
:= M
.ReadLongInt();
2207 JetFuel
:= M
.ReadLongInt();
2208 Lives
:= M
.ReadByte();
2209 NewTeam
:= M
.ReadByte();
2211 for I
:= WP_FIRST
to WP_LAST
do
2212 FWeapon
[I
] := (M
.ReadByte() <> 0);
2214 for I
:= A_BULLETS
to A_HIGH
do
2215 FAmmo
[I
] := M
.ReadWord();
2217 for I
:= A_BULLETS
to A_HIGH
do
2218 FMaxAmmo
[I
] := M
.ReadWord();
2220 for I
:= MR_SUIT
to MR_MAX
do
2221 FMegaRulez
[I
] := M
.ReadLongWord();
2224 if (M
.ReadByte() <> 0) then
2225 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2226 if (M
.ReadByte() <> 0) then
2227 FRulez
:= FRulez
+ [R_KEY_RED
];
2228 if (M
.ReadByte() <> 0) then
2229 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2230 if (M
.ReadByte() <> 0) then
2231 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2232 if (M
.ReadByte() <> 0) then
2233 FRulez
:= FRulez
+ [R_BERSERK
];
2235 Frags
:= M
.ReadLongInt();
2236 Death
:= M
.ReadLongInt();
2238 SetWeapon(M
.ReadByte());
2240 FSpectator
:= M
.ReadByte() <> 0;
2243 if Pl
= gPlayer1
then
2248 if Pl
= gPlayer2
then
2256 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2257 gPlayer1
:= g_Player_Get(gLMSPID1
);
2258 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2259 gPlayer2
:= g_Player_Get(gLMSPID2
);
2261 FGhost
:= M
.ReadByte() <> 0;
2262 FPhysics
:= M
.ReadByte() <> 0;
2263 FNoRespawn
:= M
.ReadByte() <> 0;
2265 FJetpack
:= M
.ReadByte() <> 0;
2266 OldFire
:= FFireTime
;
2267 FFireTime
:= M
.ReadLongInt();
2268 if (OldFire
<= 0) and (FFireTime
> 0) then
2269 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2270 Flam
:= M
.ReadByte() <> 0;
2271 if OldJet
and not FJetpack
then
2273 else if not OldJet
and FJetpack
then
2275 if FFlaming
and not Flam
then
2277 if Team
<> NewTeam
then
2278 Pl
.ChangeTeam(NewTeam
);
2284 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2289 Attacker
, Value
: Word;
2293 if not gGameOn
then Exit
;
2294 PID
:= M
.ReadWord();
2295 Pl
:= g_Player_Get(PID
);
2296 if Pl
= nil then Exit
;
2298 Kind
:= M
.ReadByte();
2299 Attacker
:= M
.ReadWord();
2300 Value
:= M
.ReadWord();
2305 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2310 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2314 KillType
, DeathType
: Byte;
2318 if not gGameOn
then Exit
;
2319 PID
:= M
.ReadWord();
2320 Pl
:= g_Player_Get(PID
);
2321 if Pl
= nil then Exit
;
2323 KillType
:= M
.ReadByte();
2324 DeathType
:= M
.ReadByte();
2325 Attacker
:= M
.ReadWord();
2329 Kill(KillType
, Attacker
, DeathType
);
2334 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2339 PID
:= M
.ReadWord();
2340 Pl
:= g_Player_Get(PID
);
2342 if Pl
= nil then Exit
;
2344 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2345 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2347 g_Player_Remove(PID
);
2352 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2357 X
, Y
, AX
, AY
: Integer;
2361 if not gGameOn
then Exit
;
2362 PID
:= M
.ReadWord();
2363 Pl
:= g_Player_Get(PID
);
2364 if Pl
= nil then Exit
;
2366 Weap
:= M
.ReadByte();
2367 X
:= M
.ReadLongInt();
2368 Y
:= M
.ReadLongInt();
2369 AX
:= M
.ReadLongInt();
2370 AY
:= M
.ReadLongInt();
2371 SHID
:= M
.ReadLongInt();
2374 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2377 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2386 PID
:= M
.ReadWord();
2387 Pl
:= g_Player_Get(PID
);
2388 if Pl
= nil then Exit
;
2390 TmpName
:= M
.ReadString();
2391 TmpModel
:= M
.ReadString();
2392 TmpColor
.R
:= M
.ReadByte();
2393 TmpColor
.G
:= M
.ReadByte();
2394 TmpColor
.B
:= M
.ReadByte();
2395 TmpTeam
:= M
.ReadByte();
2397 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2399 Pl
.ChangeTeam(TmpTeam
);
2400 if gPlayer1
= Pl
then
2401 gPlayer1Settings
.Team
:= TmpTeam
;
2402 if gPlayer2
= Pl
then
2403 gPlayer2Settings
.Team
:= TmpTeam
;
2405 Pl
.SetColor(TmpColor
);
2407 if Pl
.Name
<> TmpName
then
2409 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2413 if TmpModel
<> Pl
.Model
.Name
then
2414 Pl
.SetModel(TmpModel
);
2419 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2423 X
, Y
, VX
, VY
: Integer;
2425 Quiet
, Fall
{, Resp}: Boolean;
2429 if not gGameOn
then Exit
;
2431 Quiet
:= M
.ReadByte() <> 0;
2433 Fall
:= M
.ReadByte() <> 0;
2434 {Resp :=} M
.ReadByte();
2435 X
:= M
.ReadLongInt();
2436 Y
:= M
.ReadLongInt();
2437 VX
:= M
.ReadLongInt();
2438 VY
:= M
.ReadLongInt();
2440 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2441 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2443 it
:= g_Items_ByIdx(ID
);
2449 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2450 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2452 Anim
:= TAnimation
.Create(AID
, False, 4);
2453 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2459 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2464 if not gGameOn
then Exit
;
2466 Quiet
:= M
.ReadByte() <> 0;
2468 if not g_Items_ValidId(ID
) then exit
;
2470 if not Quiet
then g_Items_EmitPickupSound(ID
);
2477 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2484 if not gGameOn
then Exit
;
2486 PGUID
:= Integer(M
.ReadLongWord());
2487 Tex
:= M
.ReadLongInt();
2488 Fr
:= M
.ReadLongInt();
2489 Cnt
:= M
.ReadByte();
2490 Loop
:= M
.ReadByte();
2492 TP
:= g_Map_PanelByGUID(PGUID
);
2496 TP
.SetTexture(Tex
, Loop
);
2497 TP
.SetFrame(Fr
, Cnt
);
2501 procedure MC_RECV_PanelState(var M
: TMsg
);
2506 X
, Y
, W
, H
: Integer;
2508 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2509 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2512 if not gGameOn
then Exit
;
2514 PGUID
:= Integer(M
.ReadLongWord());
2515 E
:= (M
.ReadByte() <> 0);
2516 Lift
:= M
.ReadByte();
2517 X
:= M
.ReadLongInt();
2518 Y
:= M
.ReadLongInt();
2522 speedX
:= M
.ReadLongInt();
2523 speedY
:= M
.ReadLongInt();
2524 startX
:= M
.ReadLongInt();
2525 startY
:= M
.ReadLongInt();
2526 endX
:= M
.ReadLongInt();
2527 endY
:= M
.ReadLongInt();
2528 sizeSpX
:= M
.ReadLongInt();
2529 sizeSpY
:= M
.ReadLongInt();
2530 sizeEX
:= M
.ReadLongInt();
2531 sizeEY
:= M
.ReadLongInt();
2532 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2534 TP
:= g_Map_PanelByGUID(PGUID
);
2535 if (TP
= nil) then exit
;
2537 // update lifts state
2538 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2540 // update enabled/disabled state for all panels
2541 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2543 // update panel position, as it can be moved (mplat)
2548 // update mplat state
2549 TP
.movingSpeedX
:= speedX
;
2550 TP
.movingSpeedY
:= speedY
;
2551 TP
.movingStartX
:= startX
;
2552 TP
.movingStartY
:= startY
;
2553 TP
.movingEndX
:= endX
;
2554 TP
.movingEndY
:= endY
;
2555 TP
.sizeSpeedX
:= sizeSpX
;
2556 TP
.sizeSpeedY
:= sizeSpY
;
2557 TP
.sizeEndX
:= sizeEX
;
2558 TP
.sizeEndY
:= sizeEY
;
2559 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2560 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2561 // notify panel of it's position/size change, so it can fix other internal structures
2562 TP
.positionChanged();
2567 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2570 SPos
, SID
: LongWord;
2574 if not gGameOn
then Exit
;
2575 if gTriggers
= nil then Exit
;
2577 SID
:= M
.ReadLongWord();
2578 SPlaying
:= M
.ReadByte() <> 0;
2579 SPos
:= M
.ReadLongWord();
2580 SCount
:= M
.ReadLongInt();
2582 for I
:= Low(gTriggers
) to High(gTriggers
) do
2583 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2584 if gTriggers
[I
].ClientID
= SID
then
2585 with gTriggers
[I
] do
2587 if Sound
<> nil then
2592 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2594 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2595 Sound
.SetPosition(SPos
);
2598 if Sound
.IsPlaying
then Sound
.Stop
;
2601 SoundPlayCount
:= SCount
;
2605 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2612 if not gGameOn
then Exit
;
2614 MName
:= M
.ReadString();
2615 MPlaying
:= M
.ReadByte() <> 0;
2616 MPos
:= M
.ReadLongWord();
2617 MPaused
:= M
.ReadByte() <> 0;
2618 MPos
:= MPos
+1; //k8: stfu, fpc!
2622 gMusic
.SetByName(MName
);
2624 // gMusic.SetPosition(MPos);
2625 gMusic
.SpecPause
:= MPaused
;
2628 if gMusic
.IsPlaying
then gMusic
.Stop
;
2633 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2636 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2637 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2642 Mon
:= g_Monsters_ByUID(ID
);
2646 MType
:= M
.ReadByte();
2647 MState
:= M
.ReadByte();
2648 MAnim
:= M
.ReadByte();
2649 MTarg
:= M
.ReadWord();
2650 MTargTime
:= M
.ReadLongInt();
2651 MBehav
:= M
.ReadByte();
2652 MSleep
:= M
.ReadLongInt();
2653 MHealth
:= M
.ReadLongInt();
2654 MAmmo
:= M
.ReadLongInt();
2656 X
:= M
.ReadLongInt();
2657 Y
:= M
.ReadLongInt();
2658 VX
:= M
.ReadLongInt();
2659 VY
:= M
.ReadLongInt();
2660 MDir
:= M
.ReadByte();
2662 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2663 Mon
:= g_Monsters_ByUID(ID
);
2670 MonsterAnim
:= MAnim
;
2671 MonsterTargetUID
:= MTarg
;
2672 MonsterTargetTime
:= MTargTime
;
2673 MonsterBehaviour
:= MBehav
;
2674 MonsterSleep
:= MSleep
;
2675 MonsterAmmo
:= MAmmo
;
2680 setPosition(X
, Y
); // this will call positionChanged();
2686 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2693 Mon
:= g_Monsters_ByUID(ID
);
2699 X
:= M
.ReadLongInt();
2700 Y
:= M
.ReadLongInt();
2701 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2702 GameVelX
:= M
.ReadLongInt();
2703 GameVelY
:= M
.ReadLongInt();
2704 GameDirection
:= TDirection(M
.ReadByte());
2708 procedure MC_RECV_MonsterState(var M
: TMsg
);
2710 ID
, OldFire
: Integer;
2711 MState
, MFAnm
: Byte;
2713 AnimRevert
: Boolean;
2716 Mon
:= g_Monsters_ByUID(ID
);
2717 if Mon
= nil then Exit
;
2719 MState
:= M
.ReadByte();
2720 MFAnm
:= M
.ReadByte();
2724 MonsterTargetUID
:= M
.ReadWord();
2725 MonsterTargetTime
:= M
.ReadLongInt();
2726 MonsterSleep
:= M
.ReadLongInt();
2727 MonsterHealth
:= M
.ReadLongInt();
2728 MonsterAmmo
:= M
.ReadLongInt();
2729 MonsterPain
:= M
.ReadLongInt();
2730 AnimRevert
:= M
.ReadByte() <> 0;
2731 OldFire
:= FFireTime
;
2732 FFireTime
:= M
.ReadLongInt();
2733 if (OldFire
<= 0) and (FFireTime
> 0) then
2734 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2735 RevertAnim(AnimRevert
);
2737 if MonsterState
<> MState
then
2739 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2740 if (MState
= MONSTATE_DIE
) then DieSound();
2741 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2742 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2743 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2745 SetState(MState
, MFAnm
);
2750 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2754 X
, Y
, VX
, VY
: Integer;
2758 Mon
:= g_Monsters_ByUID(ID
);
2759 if Mon
= nil then Exit
;
2761 X
:= M
.ReadLongInt();
2762 Y
:= M
.ReadLongInt();
2763 VX
:= M
.ReadLongInt();
2764 VY
:= M
.ReadLongInt();
2766 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2769 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2775 Mon
:= g_Monsters_ByUID(ID
);
2776 if Mon
= nil then Exit
;
2778 Mon
.MonsterRemoved
:= True;
2781 procedure MC_RECV_TimeSync(var M
: TMsg
);
2785 Time
:= M
.ReadLongWord();
2787 if gState
= STATE_INTERCUSTOM
then
2788 gServInterTime
:= Min(Time
, 255);
2791 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2795 Int1
, Int2
: SmallInt;
2797 EvID
:= M
.ReadByte();
2798 Int1
:= M
.ReadSmallInt();
2799 Int2
:= M
.ReadSmallInt();
2800 Str1
:= M
.ReadString();
2801 Str2
:= M
.ReadString();
2805 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2807 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2809 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2811 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2813 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2819 procedure MC_SEND_Info(Password
: string);
2823 NetOut
.Write(Byte(NET_MSG_INFO
));
2824 NetOut
.Write(GAME_VERSION
);
2825 NetOut
.Write(Password
);
2826 NetOut
.Write(gPlayer1Settings
.Name
);
2827 NetOut
.Write(gPlayer1Settings
.Model
);
2828 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2829 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2830 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2831 NetOut
.Write(gPlayer1Settings
.Team
);
2833 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2836 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2838 NetOut
.Write(Byte(NET_MSG_CHAT
));
2842 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2845 procedure MC_SEND_PlayerPos();
2850 WeaponSelect
: Word = 0;
2853 if not gGameOn
then Exit
;
2854 if gPlayers
= nil then Exit
;
2855 if gPlayer1
= nil then Exit
;
2858 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2860 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2862 strafeDir
:= P1MoveButton
shr 4;
2863 P1MoveButton
:= P1MoveButton
and $0F;
2865 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2867 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2869 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2873 if gPlayerAction
[0, ACTION_STRAFE
] then
2875 // new strafe mechanics
2876 if (strafeDir
= 0) then
2877 strafeDir
:= P1MoveButton
; // start strafing
2878 // now set direction according to strafe (reversed)
2879 if (strafeDir
= 2) then
2880 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2881 else if (strafeDir
= 1) then
2882 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2886 strafeDir
:= 0; // not strafing anymore
2887 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
2888 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2889 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2890 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2891 else if P1MoveButton
<> 0 then
2892 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2895 gPlayer1
.ReleaseKeys
;
2896 if P1MoveButton
= 1 then
2898 kByte
:= kByte
or NET_KEY_LEFT
;
2899 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2901 if P1MoveButton
= 2 then
2903 kByte
:= kByte
or NET_KEY_RIGHT
;
2904 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2906 if gPlayerAction
[0, ACTION_LOOKUP
] then
2908 kByte
:= kByte
or NET_KEY_UP
;
2909 gPlayer1
.PressKey(KEY_UP
, 10000);
2911 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2913 kByte
:= kByte
or NET_KEY_DOWN
;
2914 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2916 if gPlayerAction
[0, ACTION_JUMP
] then
2918 kByte
:= kByte
or NET_KEY_JUMP
;
2919 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2921 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
2922 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
2923 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
2924 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
2926 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2927 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2929 for i
:= WP_FIRST
to WP_LAST
do
2931 if gSelectWeapon
[0, i
] then
2933 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
2934 gSelectWeapon
[0, i
] := False
2938 // fix movebutton state
2939 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2942 kByte
:= NET_KEY_CHAT
;
2944 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2945 NetOut
.Write(gTime
);
2946 NetOut
.Write(kByte
);
2947 NetOut
.Write(Byte(gPlayer1
.Direction
));
2948 NetOut
.Write(WeaponSelect
);
2949 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2950 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2952 //kBytePrev := kByte;
2953 //kDirPrev := gPlayer1.Direction;
2956 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2958 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2959 NetOut
.Write(Byte(Start
));
2960 NetOut
.Write(Command
);
2961 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2964 procedure MC_SEND_PlayerSettings();
2966 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2967 NetOut
.Write(gPlayer1Settings
.Name
);
2968 NetOut
.Write(gPlayer1Settings
.Model
);
2969 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2970 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2971 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2972 NetOut
.Write(gPlayer1Settings
.Team
);
2974 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2977 procedure MC_SEND_FullStateRequest();
2979 NetOut
.Write(Byte(NET_MSG_REQFST
));
2981 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2984 procedure MC_SEND_CheatRequest(Kind
: Byte);
2986 NetOut
.Write(Byte(NET_MSG_CHEAT
));
2989 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2991 procedure MC_SEND_RCONPassword(Password
: string);
2993 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
2994 NetOut
.Write(Password
);
2996 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2998 procedure MC_SEND_RCONCommand(Cmd
: string);
3000 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3003 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3006 // i have no idea why all this stuff is in here
3008 function ReadFile(const FileName
: TFileName
): AByte
;
3010 FileStream
: TStream
;
3013 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), TMsgType
.Notify
);
3014 fname
:= findDiskWad(FileName
);
3015 if length(fname
) = 0 then
3017 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), TMsgType
.Fatal
);
3018 SetLength(Result
, 0);
3021 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), TMsgType
.Notify
);
3023 FileStream
:= openDiskFileRO(fname
);
3025 if FileStream
.Size
> 0 then
3027 SetLength(Result
, FileStream
.Size
);
3028 FileStream
.Read(Result
[0], FileStream
.Size
);
3036 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
3040 Result.MsgId := NET_MSG_MAP_RESPONSE;
3041 Result.FileData := ReadFile(FileName);
3042 Result.FileSize := Length(Result.FileData);
3044 SetLength(Result.ExternalResources, ResList.Count);
3045 for i:=0 to ResList.Count-1 do
3047 Result.ExternalResources[i].Name := ResList.Strings[i];
3048 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
3052 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
3054 ResultStream: TMemoryStream;
3056 ResultStream := TMemoryStream.Create;
3058 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
3059 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
3060 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
3062 SetLength(bytes, ResultStream.Size);
3063 ResultStream.Seek(0, soFromBeginning);
3064 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
3069 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
3071 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3072 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
3073 SetLength(Result.FileData, Result.FileSize);
3074 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
3077 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
3079 ResultStream: TMemoryStream;
3082 resCount := Length(MapDataMsg.ExternalResources);
3084 ResultStream := TMemoryStream.Create;
3086 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
3087 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
3088 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
3090 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
3091 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
3093 SetLength(bytes, ResultStream.Size);
3094 ResultStream.Seek(0, soFromBeginning);
3095 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
3100 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
3104 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3105 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
3107 SetLength(Result.FileData, Result.FileSize);
3108 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
3110 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
3111 SetLength(Result.ExternalResources, resCount);
3113 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3117 function IsValidFileName(const S
: String): Boolean;
3119 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3124 for I
:= 1 to Length(S
) do
3125 Result
:= Result
and (not(S
[I
] in Forbidden
));
3128 function IsValidFilePath(const S
: String): Boolean;
3133 if not IsValidFileName(S
) then exit
;
3134 if FileExists(S
) then exit
;
3135 I
:= LastDelimiter('\/', S
);
3137 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3143 procedure MC_SEND_MapRequest();
3145 NetOut.Write(Byte(NET_MSG_MAP_REQUEST));
3146 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3149 procedure MC_SEND_ResRequest(const resName: AnsiString);
3151 NetOut.Write(Byte(NET_MSG_RES_REQUEST));
3152 NetOut.Write(resName);
3153 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3156 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
3160 mapDataMsg: TMapDataMsg;
3162 e_WriteLog('NET: Received map request from ' +
3163 DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3165 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3166 peer := NetClients[C^.ID].Peer;
3168 MapDataMsgToBytes(payload, mapDataMsg);
3169 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3172 mapDataMsg.FileData := nil;
3173 mapDataMsg.ExternalResources := nil;
3176 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
3181 resDataMsg: TResDataMsg;
3183 FileName := ExtractFileName(M.ReadString());
3184 e_WriteLog('NET: Received res request: ' + FileName +
3185 ' from ' + DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3187 if not IsValidFilePath(FileName) then
3189 e_WriteLog('Invalid filename: ' + FileName, TMsgType.Warning);
3193 peer := NetClients[C^.ID].Peer;
3195 if gExternalResources.IndexOf(FileName) > -1 then
3197 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3198 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3199 resDataMsg.FileSize := Length(resDataMsg.FileData);
3201 ResDataMsgToBytes(payload, resDataMsg);
3202 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);