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;
113 NET_EV_INTER_READY
= 20;
120 NET_VE_INPROGRESS
= 6;
127 NET_CHEAT_SUICIDE
= 1;
128 NET_CHEAT_SPECTATE
= 2;
131 NET_MAX_DIFFTIME
= 5000 div 36;
135 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
136 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
137 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
138 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
139 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
140 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
141 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
142 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
143 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
148 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
149 procedure MH_SEND_Info(ID
: Byte);
150 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
151 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
152 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
153 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
154 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
186 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_VoteEvent(EvType
: Byte;
188 StrArg1
: string = 'a'; StrArg2
: string = 'b';
189 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
190 ID
: Integer = NET_EVERYONE
);
192 // CLIENT MESSAGES //
195 procedure MC_RECV_Chat(var M
: TMsg
);
196 procedure MC_RECV_Effect(var M
: TMsg
);
197 procedure MC_RECV_Sound(var M
: TMsg
);
198 procedure MC_RECV_GameStats(var M
: TMsg
);
199 procedure MC_RECV_CoopStats(var M
: TMsg
);
200 procedure MC_RECV_GameEvent(var M
: TMsg
);
201 procedure MC_RECV_FlagEvent(var M
: TMsg
);
202 procedure MC_RECV_GameSettings(var M
: TMsg
);
204 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
205 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
206 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
207 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
208 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
209 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
210 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
211 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
213 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
214 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
216 procedure MC_RECV_PanelTexture(var M
: TMsg
);
217 procedure MC_RECV_PanelState(var M
: TMsg
);
219 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
220 procedure MC_RECV_MonsterPos(var M
: TMsg
);
221 procedure MC_RECV_MonsterState(var M
: TMsg
);
222 procedure MC_RECV_MonsterShot(var M
: TMsg
);
223 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
225 procedure MC_RECV_CreateShot(var M
: TMsg
);
226 procedure MC_RECV_UpdateShot(var M
: TMsg
);
227 procedure MC_RECV_DeleteShot(var M
: TMsg
);
229 procedure MC_RECV_TriggerSound(var M
: TMsg
);
230 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
232 procedure MC_RECV_TimeSync(var M
: TMsg
);
233 procedure MC_RECV_VoteEvent(var M
: TMsg
);
235 procedure MC_SEND_Info(Password
: string);
236 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
237 procedure MC_SEND_PlayerPos();
238 procedure MC_SEND_FullStateRequest();
239 procedure MC_SEND_PlayerSettings();
240 procedure MC_SEND_CheatRequest(Kind
: Byte);
241 procedure MC_SEND_RCONPassword(Password
: string);
242 procedure MC_SEND_RCONCommand(Cmd
: string);
243 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
245 procedure MC_SEND_MapRequest();
246 procedure MC_SEND_ResRequest(const resName
: AnsiString);
249 TExternalResourceInfo
= record
264 ExternalResources
: array of TExternalResourceInfo
;
267 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
268 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
273 Math
, ENet
, e_input
, e_graphics
, e_log
,
274 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
275 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
276 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
289 NET_KEY_FORCEDIR
= 4096;
292 //kBytePrev: Word = 0;
293 //kDirPrev: TDirection = D_LEFT;
294 //HostGameTime: Word = 0;
301 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
309 Pl
:= g_Player_Get(PID
);
311 Txt
:= M
.ReadString();
312 Mode
:= M
.ReadByte();
313 if (Mode
= NET_CHAT_SYSTEM
) then
314 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
315 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
316 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
319 MH_SEND_Chat(Txt
, Mode
)
321 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
324 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
326 Ver
, PName
, Model
, Pw
: string;
332 Ver
:= M
.ReadString();
333 Pw
:= M
.ReadString();
334 PName
:= M
.ReadString();
335 Model
:= M
.ReadString();
341 if Ver
<> GAME_VERSION
then
343 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
344 _lc
[I_NET_DISC_VERSION
]);
345 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
349 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
351 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
353 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
354 _lc
[I_NET_DISC_BAN
]);
355 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
359 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
360 _lc
[I_NET_DISC_BAN
]);
361 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
366 if NetPassword
<> '' then
367 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
369 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
370 _lc
[I_NET_DISC_PASSWORD
]);
371 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
379 PID
:= g_Player_Create(Model
, Color
, T
, False);
380 with g_Player_Get(PID
) do
388 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
389 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
390 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
394 with g_Player_Get(PID
) do
398 // round in progress, don't spawn
399 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
404 FWantsInGame
:= True; // TODO: look into this later
407 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
410 for I
:= Low(NetClients
) to High(NetClients
) do
412 if NetClients
[I
].ID
= C
^.ID
then Continue
;
413 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
414 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
415 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
418 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
419 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
421 if NetUseMaster
then g_Net_Slist_Update
;
424 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
427 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
429 C
^.RequestedFullUpdate
:= True;
434 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
444 if not gGameOn
then Exit
;
446 GT
:= M
.ReadLongWord();
448 Pl
:= g_Player_Get(PID
);
452 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
457 kByte
:= M
.ReadWord();
459 WeaponSelect
:= M
.ReadWord();
460 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
461 if Direction
<> TDirection(Dir
) then
462 JustTeleported
:= False;
464 SetDirection(TDirection(Dir
));
467 if kByte
= NET_KEY_CHAT
then
469 PressKey(KEY_CHAT
, 10000);
473 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
474 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
475 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
476 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
477 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
478 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
479 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
480 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
481 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
485 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
487 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
488 QueueWeaponSwitch(i
);
493 // MH_SEND_PlayerPos(False, PID, C^.ID);
496 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
501 Pl
:= g_Player_Get(C
^.Player
);
502 if Pl
= nil then Exit
;
504 CheatKind
:= M
.ReadByte();
508 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
511 if Pl
.FSpectator
then
518 if gState
<> STATE_INTERCUSTOM
then Exit
;
519 Pl
.FReady
:= not Pl
.FReady
;
522 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
523 Inc(gInterReadyCount
);
527 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
528 Dec(gInterReadyCount
);
534 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
542 TmpName
:= M
.ReadString();
543 TmpModel
:= M
.ReadString();
544 TmpColor
.R
:= M
.ReadByte();
545 TmpColor
.G
:= M
.ReadByte();
546 TmpColor
.B
:= M
.ReadByte();
547 TmpTeam
:= M
.ReadByte();
549 Pl
:= g_Player_Get(C
^.Player
);
550 if Pl
= nil then Exit
;
552 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
555 Pl
.SetColor(TmpColor
);
557 if Pl
.Name
<> TmpName
then
559 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
563 if TmpModel
<> Pl
.Model
.Name
then
564 Pl
.SetModel(TmpModel
);
566 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
571 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
575 Pwd
:= M
.ReadString();
576 if not NetAllowRCON
then Exit
;
577 if Pwd
= NetRCONPassword
then
580 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
583 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
586 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
590 Cmd
:= M
.ReadString();
591 if not NetAllowRCON
then Exit
;
592 if not C
^.RCONAuth
then
594 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
597 g_Console_Process(Cmd
);
602 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
605 Name
, Command
: string;
609 Start
:= M
.ReadByte() <> 0;
610 Command
:= M
.ReadString();
612 Pl
:= g_Player_Get(C
^.Player
);
613 if Pl
= nil then Exit
;
618 if not g_Console_CommandBlacklisted(Command
) then
619 g_Game_StartVote(Command
, Name
);
621 else if gVoteInProgress
then
623 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
624 Need
:= Floor((NetClientCount
+1)/2.0) + 1
626 Need
:= Floor(NetClientCount
/2.0) + 1;
631 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
632 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
638 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
639 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
647 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
649 function sendItemRespawn (it
: PItem
): Boolean;
651 result
:= false; // don't stop
652 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
655 function sendMonSpawn (mon
: TMonster
): Boolean;
657 result
:= false; // don't stop
658 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
661 function sendPanelState (pan
: TPanel
): Boolean;
663 result
:= false; // don't stop
664 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
665 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
671 if gPlayers
<> nil then
673 for I
:= Low(gPlayers
) to High(gPlayers
) do
675 if gPlayers
[I
] <> nil then
677 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
678 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
679 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
681 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
683 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
689 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
690 g_Mons_ForEach(sendMonSpawn
);
691 g_Map_ForEachPanel(sendPanelState
);
693 if gTriggers
<> nil then
695 for I
:= Low(gTriggers
) to High(gTriggers
) do
697 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
699 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
706 for I
:= Low(Shots
) to High(Shots
) do
708 if Shots
[i
].ShotType
in [6, 7, 8] then
710 MH_SEND_CreateShot(i
, ID
);
715 MH_SEND_TriggerMusic(ID
);
717 MH_SEND_GameStats(ID
);
718 MH_SEND_CoopStats(ID
);
720 if gGameSettings
.GameMode
= GM_CTF
then
722 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
723 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
726 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
728 if gLMSRespawn
> LMS_RESPAWN_NONE
then
730 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
734 procedure MH_SEND_Info(ID
: Byte);
738 Map
:= g_ExtractFileName(gMapInfo
.Map
);
742 NetOut
.Write(Byte(NET_MSG_INFO
));
744 NetOut
.Write(NetClients
[ID
].Player
);
745 NetOut
.Write(gGameSettings
.WAD
);
747 NetOut
.Write(gWADHash
);
748 NetOut
.Write(gGameSettings
.GameMode
);
749 NetOut
.Write(gGameSettings
.GoalLimit
);
750 NetOut
.Write(gGameSettings
.TimeLimit
);
751 NetOut
.Write(gGameSettings
.MaxLives
);
752 NetOut
.Write(gGameSettings
.Options
);
755 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
758 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
764 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
765 Mode
:= NET_CHAT_PLAYER
;
768 if (Mode
= NET_CHAT_TEAM
) then
770 for i
:= Low(gPlayers
) to High(gPlayers
) do
771 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
772 (gPlayers
[i
].Team
= ID
) then
774 NetOut
.Write(Byte(NET_MSG_CHAT
));
777 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
784 NetOut
.Write(Byte(NET_MSG_CHAT
));
787 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
790 if Mode
= NET_CHAT_SYSTEM
then
793 if ID
= NET_EVERYONE
then
795 if Mode
= NET_CHAT_PLAYER
then
797 g_Console_Add(Txt
, True);
798 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
799 g_Game_ChatSound(b_Text_Unformat(Txt
));
802 if Mode
= NET_CHAT_TEAM
then
803 if gPlayer1
<> nil then
805 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
807 g_Console_Add(#18'[Team] '#2 + Txt
, True);
808 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
809 g_Game_ChatSound(b_Text_Unformat(Txt
));
811 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
813 g_Console_Add(#20'[Team] '#2 + Txt
, True);
814 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
815 g_Game_ChatSound(b_Text_Unformat(Txt
));
821 Name
:= g_Net_ClientName_ByID(ID
);
822 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
823 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
824 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
828 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
830 NetOut
.Write(Byte(NET_MSG_GFX
));
836 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
839 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
841 NetOut
.Write(Byte(NET_MSG_SND
));
845 NetOut
.Write(Byte(1));
850 NetOut
.Write(Byte(0));
852 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
855 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
857 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
859 NetOut
.Write(Byte(NET_MSG_SHADD
));
861 NetOut
.Write(Shots
[Proj
].ShotType
);
862 NetOut
.Write(Shots
[Proj
].Target
);
863 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
864 NetOut
.Write(Shots
[Proj
].Timeout
);
865 NetOut
.Write(Shots
[Proj
].Obj
.X
);
866 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
867 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
868 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
870 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
873 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
875 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
877 NetOut
.Write(Byte(NET_MSG_SHPOS
));
879 NetOut
.Write(Shots
[Proj
].Obj
.X
);
880 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
881 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
882 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
884 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
887 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
889 NetOut
.Write(Byte(NET_MSG_SHDEL
));
891 NetOut
.Write(Byte(Loud
));
895 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
898 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
900 NetOut
.Write(Byte(NET_MSG_SCORE
));
901 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
903 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
904 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
907 if gGameSettings
.GameMode
= GM_COOP
then
909 NetOut
.Write(gCoopMonstersKilled
);
910 NetOut
.Write(gCoopSecretsFound
);
913 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
916 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
918 NetOut
.Write(Byte(NET_MSG_COOP
));
919 NetOut
.Write(gTotalMonsters
);
920 NetOut
.Write(gSecretsCount
);
921 NetOut
.Write(gCoopTotalMonstersKilled
);
922 NetOut
.Write(gCoopTotalSecretsFound
);
923 NetOut
.Write(gCoopTotalMonsters
);
924 NetOut
.Write(gCoopTotalSecrets
);
927 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
929 NetOut
.Write(Byte(NET_MSG_GEVENT
));
930 NetOut
.Write(EvType
);
933 NetOut
.Write(Byte(gLastMap
));
935 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
937 NetOut
.Write(Byte(1));
938 NetOut
.Write(gWADHash
);
940 NetOut
.Write(Byte(0));
942 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
945 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
947 NetOut
.Write(Byte(NET_MSG_FLAG
));
948 NetOut
.Write(EvType
);
950 NetOut
.Write(Byte(Quiet
));
952 NetOut
.Write(gFlags
[Flag
].State
);
953 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
954 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
955 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
956 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
957 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
959 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
962 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
964 NetOut
.Write(Byte(NET_MSG_GSET
));
965 NetOut
.Write(gGameSettings
.GameMode
);
966 NetOut
.Write(gGameSettings
.GoalLimit
);
967 NetOut
.Write(gGameSettings
.TimeLimit
);
968 NetOut
.Write(gGameSettings
.MaxLives
);
969 NetOut
.Write(gGameSettings
.Options
);
971 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
976 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
980 P
:= g_Player_Get(PID
);
981 if P
= nil then Exit
;
983 NetOut
.Write(Byte(NET_MSG_PLR
));
985 NetOut
.Write(P
.Name
);
987 NetOut
.Write(P
.FActualModelName
);
988 NetOut
.Write(P
.FColor
.R
);
989 NetOut
.Write(P
.FColor
.G
);
990 NetOut
.Write(P
.FColor
.B
);
991 NetOut
.Write(P
.Team
);
993 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
996 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1001 Pl
:= g_Player_Get(PID
);
1002 if Pl
= nil then Exit
;
1003 if Pl
.FDummy
then Exit
;
1005 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1006 NetOut
.Write(gTime
);
1013 NetOut
.Write(FPing
);
1014 NetOut
.Write(FLoss
);
1015 if IsKeyPressed(KEY_CHAT
) then
1016 kByte
:= NET_KEY_CHAT
1019 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1020 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1021 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1022 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1023 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1024 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1027 NetOut
.Write(kByte
);
1028 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1029 NetOut
.Write(GameX
);
1030 NetOut
.Write(GameY
);
1031 NetOut
.Write(GameVelX
);
1032 NetOut
.Write(GameVelY
);
1033 NetOut
.Write(GameAccelX
);
1034 NetOut
.Write(GameAccelY
);
1037 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1040 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1045 P
:= g_Player_Get(PID
);
1046 if P
= nil then Exit
;
1048 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1053 NetOut
.Write(Byte(alive
));
1054 NetOut
.Write(Byte(GodMode
));
1055 NetOut
.Write(Health
);
1056 NetOut
.Write(Armor
);
1058 NetOut
.Write(JetFuel
);
1059 NetOut
.Write(Lives
);
1062 for I
:= WP_FIRST
to WP_LAST
do
1063 NetOut
.Write(Byte(FWeapon
[I
]));
1065 for I
:= A_BULLETS
to A_HIGH
do
1066 NetOut
.Write(FAmmo
[I
]);
1068 for I
:= A_BULLETS
to A_HIGH
do
1069 NetOut
.Write(FMaxAmmo
[I
]);
1071 for I
:= MR_SUIT
to MR_MAX
do
1072 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1074 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1075 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1076 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1077 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1078 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1080 NetOut
.Write(Frags
);
1081 NetOut
.Write(Death
);
1083 NetOut
.Write(CurrWeap
);
1085 NetOut
.Write(Byte(FSpectator
));
1086 NetOut
.Write(Byte(FGhost
));
1087 NetOut
.Write(Byte(FPhysics
));
1088 NetOut
.Write(Byte(FNoRespawn
));
1089 NetOut
.Write(Byte(FJetpack
));
1090 NetOut
.Write(FFireTime
);
1091 NetOut
.Write(Byte(FFlaming
));
1094 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1097 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1099 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1102 NetOut
.Write(Attacker
);
1103 NetOut
.Write(Value
);
1107 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1110 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1112 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1114 NetOut
.Write(KillType
);
1115 NetOut
.Write(DeathType
);
1116 NetOut
.Write(Attacker
);
1118 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1121 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1123 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1125 NetOut
.Write(Weapon
);
1130 NetOut
.Write(ShotID
);
1132 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1135 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1137 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1140 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1143 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1147 Pl
:= g_Player_Get(PID
);
1148 if Pl
= nil then Exit
;
1150 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1152 NetOut
.Write(Pl
.Name
);
1154 NetOut
.Write(Pl
.Model
.Name
)
1157 NetOut
.Write(Pl
.FColor
.R
);
1158 NetOut
.Write(Pl
.FColor
.G
);
1159 NetOut
.Write(Pl
.FColor
.B
);
1160 NetOut
.Write(Pl
.Team
);
1162 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1167 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1172 it
:= g_Items_ByIdx(IID
);
1174 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1176 NetOut
.Write(Byte(Quiet
));
1178 if it
.dropped
then tt
:= tt
or $80;
1180 NetOut
.Write(Byte(it
.Fall
));
1181 NetOut
.Write(Byte(it
.Respawnable
));
1182 NetOut
.Write(it
.Obj
.X
);
1183 NetOut
.Write(it
.Obj
.Y
);
1184 NetOut
.Write(it
.Obj
.Vel
.X
);
1185 NetOut
.Write(it
.Obj
.Vel
.Y
);
1187 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1190 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1192 NetOut
.Write(Byte(NET_MSG_IDEL
));
1194 NetOut
.Write(Byte(Quiet
));
1196 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1201 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1205 TP
:= g_Map_PanelByGUID(PGUID
);
1206 if (TP
= nil) then exit
;
1210 NetOut
.Write(Byte(NET_MSG_PTEX
));
1211 NetOut
.Write(LongWord(PGUID
));
1212 NetOut
.Write(FCurTexture
);
1213 NetOut
.Write(FCurFrame
);
1214 NetOut
.Write(FCurFrameCount
);
1215 NetOut
.Write(AnimLoop
);
1218 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1221 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1226 TP
:= g_Map_PanelByGUID(PGUID
);
1227 if (TP
= nil) then exit
;
1229 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1230 NetOut
.Write(LongWord(PGUID
));
1231 NetOut
.Write(Byte(TP
.Enabled
));
1232 NetOut
.Write(TP
.LiftType
);
1235 NetOut
.Write(Word(TP
.Width
));
1236 NetOut
.Write(Word(TP
.Height
));
1238 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1239 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1240 NetOut
.Write(LongInt(TP
.movingStartX
));
1241 NetOut
.Write(LongInt(TP
.movingStartY
));
1242 NetOut
.Write(LongInt(TP
.movingEndX
));
1243 NetOut
.Write(LongInt(TP
.movingEndY
));
1244 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1245 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1246 NetOut
.Write(LongInt(TP
.sizeEndX
));
1247 NetOut
.Write(LongInt(TP
.sizeEndY
));
1248 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1249 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1250 NetOut
.Write(Byte(mpflags
));
1252 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1257 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1259 if gTriggers
= nil then Exit
;
1260 if T
.Sound
= nil then Exit
;
1262 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1263 NetOut
.Write(T
.ClientID
);
1264 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1265 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1266 NetOut
.Write(T
.SoundPlayCount
);
1268 g_Net_Host_Send(ID
, True);
1271 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1273 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1274 NetOut
.Write(gMusic
.Name
);
1275 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1276 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1277 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1279 g_Net_Host_Send(ID
, True);
1284 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1288 M
:= g_Monsters_ByUID(UID
);
1294 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1296 NetOut
.Write(MonsterType
);
1297 NetOut
.Write(MonsterState
);
1298 NetOut
.Write(MonsterAnim
);
1299 NetOut
.Write(MonsterTargetUID
);
1300 NetOut
.Write(MonsterTargetTime
);
1301 NetOut
.Write(MonsterBehaviour
);
1302 NetOut
.Write(MonsterSleep
);
1303 NetOut
.Write(MonsterHealth
);
1304 NetOut
.Write(MonsterAmmo
);
1305 NetOut
.Write(GameX
);
1306 NetOut
.Write(GameY
);
1307 NetOut
.Write(GameVelX
);
1308 NetOut
.Write(GameVelY
);
1309 NetOut
.Write(Byte(GameDirection
));
1312 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1315 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1319 M
:= g_Monsters_ByUID(UID
);
1320 if M
= nil then Exit
;
1322 NetOut
.Write(Byte(NET_MSG_MPOS
));
1327 NetOut
.Write(GameX
);
1328 NetOut
.Write(GameY
);
1329 NetOut
.Write(GameVelX
);
1330 NetOut
.Write(GameVelY
);
1331 NetOut
.Write(Byte(GameDirection
));
1334 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1337 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1341 M
:= g_Monsters_ByUID(UID
);
1342 if M
= nil then Exit
;
1344 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1349 NetOut
.Write(MonsterState
);
1350 NetOut
.Write(ForcedAnim
);
1351 NetOut
.Write(MonsterTargetUID
);
1352 NetOut
.Write(MonsterTargetTime
);
1353 NetOut
.Write(MonsterSleep
);
1354 NetOut
.Write(MonsterHealth
);
1355 NetOut
.Write(MonsterAmmo
);
1356 NetOut
.Write(MonsterPain
);
1357 NetOut
.Write(Byte(AnimIsReverse
));
1358 NetOut
.Write(FFireTime
);
1361 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1364 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1366 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1373 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1376 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1380 M
:= g_Monsters_ByUID(UID
);
1381 if M
= nil then Exit
;
1383 NetOut
.Write(Byte(NET_MSG_MDEL
));
1386 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1391 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1393 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1396 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1399 procedure MH_SEND_VoteEvent(EvType
: Byte;
1400 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1401 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1402 ID
: Integer = NET_EVERYONE
);
1404 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1405 NetOut
.Write(EvType
);
1406 NetOut
.Write(IntArg1
);
1407 NetOut
.Write(IntArg2
);
1408 NetOut
.Write(StrArg1
);
1409 NetOut
.Write(StrArg2
);
1411 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1414 // CLIENT MESSAGES //
1418 procedure MC_RECV_Chat(var M
: TMsg
);
1423 Txt
:= M
.ReadString();
1424 Mode
:= M
.ReadByte();
1426 if Mode
<> NET_CHAT_SYSTEM
then
1428 if Mode
= NET_CHAT_PLAYER
then
1430 g_Console_Add(Txt
, True);
1431 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1432 g_Game_ChatSound(b_Text_Unformat(Txt
));
1434 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1436 if gPlayer1
.Team
= TEAM_RED
then
1437 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1438 if gPlayer1
.Team
= TEAM_BLUE
then
1439 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1440 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1441 g_Game_ChatSound(b_Text_Unformat(Txt
));
1444 g_Console_Add(Txt
, True);
1447 procedure MC_RECV_Effect(var M
: TMsg
);
1455 if not gGameOn
then Exit
;
1456 Kind
:= M
.ReadByte();
1457 X
:= M
.ReadLongInt();
1458 Y
:= M
.ReadLongInt();
1459 Ang
:= M
.ReadSmallInt();
1463 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1467 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1469 Anim
:= TAnimation
.Create(ID
, False, 3);
1470 g_GFX_OnceAnim(X
, Y
, Anim
);
1474 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1479 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1481 Anim
:= TAnimation
.Create(ID
, False, 6);
1482 Anim
.Blending
:= False;
1483 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1487 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1492 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1494 Anim
:= TAnimation
.Create(ID
, False, 6);
1495 Anim
.Blending
:= False;
1496 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1500 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1505 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1507 Anim
:= TAnimation
.Create(ID
, False, 4);
1508 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1515 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1517 Anim
:= TAnimation
.Create(ID
, False, 4);
1518 g_GFX_OnceAnim(X
, Y
, Anim
);
1522 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1527 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1529 Anim
:= TAnimation
.Create(ID
, False, 4);
1530 g_GFX_OnceAnim(X
, Y
, Anim
);
1534 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1538 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1541 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1545 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1546 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1551 procedure MC_RECV_Sound(var M
: TMsg
);
1557 Name
:= M
.ReadString();
1558 Pos
:= M
.ReadByte() <> 0;
1561 X
:= M
.ReadLongInt();
1562 Y
:= M
.ReadLongInt();
1563 g_Sound_PlayExAt(Name
, X
, Y
);
1566 g_Sound_PlayEx(Name
);
1569 procedure MC_RECV_CreateShot(var M
: TMsg
);
1571 I
, X
, Y
, XV
, YV
: Integer;
1573 Target
, Spawner
: Word;
1576 I
:= M
.ReadLongInt();
1577 ShType
:= M
.ReadByte();
1578 Target
:= M
.ReadWord();
1579 Spawner
:= M
.ReadWord();
1580 Timeout
:= M
.ReadLongWord();
1581 X
:= M
.ReadLongInt();
1582 Y
:= M
.ReadLongInt();
1583 XV
:= M
.ReadLongInt();
1584 YV
:= M
.ReadLongInt();
1586 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1587 if (Shots
<> nil) and (I
<= High(Shots
)) then
1589 Shots
[I
].Timeout
:= Timeout
;
1590 //Shots[I].Target := Target; // TODO: find a use for Target later
1594 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1596 I
, TX
, TY
, TXV
, TYV
: Integer;
1598 I
:= M
.ReadLongInt();
1599 TX
:= M
.ReadLongInt();
1600 TY
:= M
.ReadLongInt();
1601 TXV
:= M
.ReadLongInt();
1602 TYV
:= M
.ReadLongInt();
1604 if (Shots
<> nil) and (I
<= High(Shots
)) then
1614 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1619 if not gGameOn
then Exit
;
1620 I
:= M
.ReadLongInt();
1621 L
:= (M
.ReadByte() <> 0);
1622 X
:= M
.ReadLongInt();
1623 Y
:= M
.ReadLongInt();
1625 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1628 procedure MC_RECV_GameStats(var M
: TMsg
);
1630 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1632 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1633 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1636 if gGameSettings
.GameMode
= GM_COOP
then
1638 gCoopMonstersKilled
:= M
.ReadWord();
1639 gCoopSecretsFound
:= M
.ReadWord();
1643 procedure MC_RECV_CoopStats(var M
: TMsg
);
1645 gTotalMonsters
:= M
.ReadLongInt();
1646 gSecretsCount
:= M
.ReadLongInt();
1647 gCoopTotalMonstersKilled
:= M
.ReadWord();
1648 gCoopTotalSecretsFound
:= M
.ReadWord();
1649 gCoopTotalMonsters
:= M
.ReadWord();
1650 gCoopTotalSecrets
:= M
.ReadWord();
1653 procedure MC_RECV_GameEvent(var M
: TMsg
);
1662 i1
, i2
: TStrings_Locale
;
1666 FillChar(EvHash
, Sizeof(EvHash
), 0);
1667 EvType
:= M
.ReadByte();
1668 EvNum
:= M
.ReadLongInt();
1669 EvStr
:= M
.ReadString();
1670 gLastMap
:= M
.ReadByte() <> 0;
1671 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1672 gStatsPressed
:= True;
1673 EvTime
:= M
.ReadLongWord();
1674 BHash
:= M
.ReadByte() <> 0;
1676 EvHash
:= M
.ReadMD5();
1684 g_Game_ClearLoading();
1685 g_Game_StopAllSounds(True);
1687 gSwitchGameMode
:= Byte(EvNum
);
1688 gGameSettings
.GameMode
:= gSwitchGameMode
;
1691 if not g_Game_StartMap(EvStr
, True) then
1693 if not isWadPath(EvStr
) then
1694 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1696 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1700 MC_SEND_FullStateRequest
;
1705 gMissionFailed
:= EvNum
<> 0;
1706 gExit
:= EXIT_ENDLEVELCUSTOM
;
1713 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1715 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1717 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1723 if EvNum
= TEAM_RED
then
1724 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1725 if EvNum
= TEAM_BLUE
then
1726 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1730 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1733 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1736 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1738 NET_EV_LMS_SURVIVOR
:
1739 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1742 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1746 pl
:= g_Player_Get(EvNum
and $FFFF);
1751 cnt
:= (EvNum
shr 16) and $FF;
1752 if Pos('w', EvStr
) = 0 then
1755 if Pos('t', EvStr
) = 0 then
1758 if Pos('-', EvStr
) = 0 then
1760 if Pos('e', EvStr
) = 0 then
1761 i1
:= I_PLAYER_SCORE_ADD_OWN
1763 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1766 if Pos('e', EvStr
) = 0 then
1767 i1
:= I_PLAYER_SCORE_SUB_OWN
1769 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1772 if Pos('r', EvStr
) > 0 then
1773 i2
:= I_PLAYER_SCORE_TO_RED
1775 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1776 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1780 if Pos('-', EvStr
) = 0 then
1781 i1
:= I_PLAYER_SCORE_ADD_TEAM
1783 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1785 if Pos('r', EvStr
) > 0 then
1786 i2
:= I_PLAYER_SCORE_RED
1788 i2
:= I_PLAYER_SCORE_BLUE
;
1789 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1794 if Pos('e', EvStr
) = 0 then
1795 i1
:= I_PLAYER_SCORE_WIN_OWN
1797 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1799 if Pos('r', EvStr
) > 0 then
1800 i2
:= I_PLAYER_SCORE_TO_RED
1802 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1803 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1809 if EvNum
= TEAM_RED
then
1810 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1811 if EvNum
= TEAM_BLUE
then
1812 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1813 if EvNum
= -TEAM_RED
then
1814 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1815 if EvNum
= -TEAM_BLUE
then
1816 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1821 g_Player_RemoveAllCorpses
;
1822 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1826 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1830 if EvNum
= TEAM_RED
then
1831 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1832 if EvNum
= TEAM_BLUE
then
1833 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1837 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1840 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1843 g_Game_Announce_KillCombo(EvNum
);
1845 NET_EV_PLAYER_TOUCH
:
1847 pl
:= g_Player_Get(EvNum
);
1854 pl
:= g_Player_Get(EvNum
);
1857 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
1858 g_Sound_PlayEx('SOUND_GAME_SECRET');
1864 pl
:= g_Player_Get(EvNum
);
1865 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
1870 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1879 EvType
:= M
.ReadByte();
1882 if Fl
= FLAG_NONE
then Exit
;
1884 Quiet
:= (M
.ReadByte() <> 0);
1885 PID
:= M
.ReadWord();
1887 gFlags
[Fl
].State
:= M
.ReadByte();
1888 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1889 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1890 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1891 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1892 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1894 Pl
:= g_Player_Get(PID
);
1896 (EvType
<> FLAG_STATE_NORMAL
) and
1897 (EvType
<> FLAG_STATE_DROPPED
) and
1898 (EvType
<> FLAG_STATE_RETURNED
) then
1904 if Quiet
or (Pl
= nil) then Exit
;
1906 if Fl
= FLAG_RED
then
1907 s
:= _lc
[I_PLAYER_FLAG_RED
]
1909 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1911 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1913 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1914 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1915 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1920 if not sound_ret_flag
[a
].IsPlaying() then
1921 sound_ret_flag
[a
].Play();
1924 FLAG_STATE_CAPTURED
:
1926 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1930 if Fl
= FLAG_RED
then
1931 s
:= _lc
[I_PLAYER_FLAG_RED
]
1933 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1935 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1936 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1938 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1939 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1940 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1945 if not sound_get_flag
[a
].IsPlaying() then
1946 sound_get_flag
[a
].Play();
1951 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1953 if Quiet
or (Pl
= nil) then Exit
;
1955 if Fl
= FLAG_RED
then
1956 s
:= _lc
[I_PLAYER_FLAG_RED
]
1958 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1960 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1961 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1963 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1964 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1965 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1970 if not sound_lost_flag
[a
].IsPlaying() then
1971 sound_lost_flag
[a
].Play();
1976 g_Map_ResetFlag(FLAG_RED
);
1977 g_Map_ResetFlag(FLAG_BLUE
);
1978 if Quiet
or (Pl
= nil) then Exit
;
1979 Pl
.SetFlag(FLAG_NONE
);
1981 if Fl
= FLAG_RED
then
1982 s
:= _lc
[I_PLAYER_FLAG_RED
]
1984 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1986 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1987 Insert('.', ts
, Length(ts
) + 1 - 3);
1988 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1989 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1991 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1992 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1993 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1998 if not sound_cap_flag
[a
].IsPlaying() then
1999 sound_cap_flag
[a
].Play();
2002 FLAG_STATE_RETURNED
:
2004 g_Map_ResetFlag(Fl
);
2007 if Fl
= FLAG_RED
then
2008 s
:= _lc
[I_PLAYER_FLAG_RED
]
2010 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2012 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2014 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2015 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2016 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2021 if not sound_ret_flag
[a
].IsPlaying() then
2022 sound_ret_flag
[a
].Play();
2027 procedure MC_RECV_GameSettings(var M
: TMsg
);
2029 gGameSettings
.GameMode
:= M
.ReadByte();
2030 gGameSettings
.GoalLimit
:= M
.ReadWord();
2031 gGameSettings
.TimeLimit
:= M
.ReadWord();
2032 gGameSettings
.MaxLives
:= M
.ReadByte();
2033 gGameSettings
.Options
:= M
.ReadLongWord();
2038 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2041 PName
, Model
: string;
2046 PID
:= M
.ReadWord();
2047 Pl
:= g_Player_Get(PID
);
2049 PName
:= M
.ReadString();
2050 Model
:= M
.ReadString();
2051 Color
.R
:= M
.ReadByte();
2052 Color
.G
:= M
.ReadByte();
2053 Color
.B
:= M
.ReadByte();
2057 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2059 if (Pl
<> nil) then Exit
;
2060 DID
:= g_Player_Create(Model
, Color
, T
, False);
2061 with g_Player_Get(DID
) do
2070 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2071 gPlayer1
.UID
:= PID
;
2072 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2073 gPlayer1
.ChangeTeam(T
);
2075 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2076 gPlayer2
.UID
:= PID
;
2077 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2078 gPlayer2
.ChangeTeam(T
);
2082 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2083 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2087 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2094 TmpX
, TmpY
: Integer;
2098 GT
:= M
.ReadLongWord();
2099 if GT
< gTime
- NET_MAX_DIFFTIME
then
2106 PID
:= M
.ReadWord();
2107 Pl
:= g_Player_Get(PID
);
2109 if Pl
= nil then Exit
;
2115 FPing
:= M
.ReadWord();
2116 FLoss
:= M
.ReadByte();
2117 kByte
:= M
.ReadWord();
2118 Dir
:= M
.ReadByte();
2120 TmpX
:= M
.ReadLongInt();
2121 TmpY
:= M
.ReadLongInt();
2125 if (kByte
= NET_KEY_CHAT
) then
2126 PressKey(KEY_CHAT
, 10000)
2129 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2130 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2131 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2132 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2133 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2136 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2137 SetDirection(TDirection(Dir
));
2139 GameVelX
:= M
.ReadLongInt();
2140 GameVelY
:= M
.ReadLongInt();
2141 GameAccelX
:= M
.ReadLongInt();
2142 GameAccelY
:= M
.ReadLongInt();
2143 SetLerp(TmpX
, TmpY
);
2144 if NetForcePlayerUpdate
then Update();
2148 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2152 I
, OldFire
: Integer;
2153 OldJet
, Flam
: Boolean;
2156 PID
:= M
.ReadWord();
2157 Pl
:= g_Player_Get(PID
);
2164 alive
:= (M
.ReadByte() <> 0);
2165 GodMode
:= (M
.ReadByte() <> 0);
2166 Health
:= M
.ReadLongInt();
2167 Armor
:= M
.ReadLongInt();
2168 Air
:= M
.ReadLongInt();
2169 JetFuel
:= M
.ReadLongInt();
2170 Lives
:= M
.ReadByte();
2171 NewTeam
:= M
.ReadByte();
2173 for I
:= WP_FIRST
to WP_LAST
do
2174 FWeapon
[I
] := (M
.ReadByte() <> 0);
2176 for I
:= A_BULLETS
to A_HIGH
do
2177 FAmmo
[I
] := M
.ReadWord();
2179 for I
:= A_BULLETS
to A_HIGH
do
2180 FMaxAmmo
[I
] := M
.ReadWord();
2182 for I
:= MR_SUIT
to MR_MAX
do
2183 FMegaRulez
[I
] := M
.ReadLongWord();
2186 if (M
.ReadByte() <> 0) then
2187 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2188 if (M
.ReadByte() <> 0) then
2189 FRulez
:= FRulez
+ [R_KEY_RED
];
2190 if (M
.ReadByte() <> 0) then
2191 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2192 if (M
.ReadByte() <> 0) then
2193 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2194 if (M
.ReadByte() <> 0) then
2195 FRulez
:= FRulez
+ [R_BERSERK
];
2197 Frags
:= M
.ReadLongInt();
2198 Death
:= M
.ReadLongInt();
2200 SetWeapon(M
.ReadByte());
2202 FSpectator
:= M
.ReadByte() <> 0;
2205 if Pl
= gPlayer1
then
2210 if Pl
= gPlayer2
then
2218 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2219 gPlayer1
:= g_Player_Get(gLMSPID1
);
2220 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2221 gPlayer2
:= g_Player_Get(gLMSPID2
);
2223 FGhost
:= M
.ReadByte() <> 0;
2224 FPhysics
:= M
.ReadByte() <> 0;
2225 FNoRespawn
:= M
.ReadByte() <> 0;
2227 FJetpack
:= M
.ReadByte() <> 0;
2228 OldFire
:= FFireTime
;
2229 FFireTime
:= M
.ReadLongInt();
2230 if (OldFire
<= 0) and (FFireTime
> 0) then
2231 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2232 Flam
:= M
.ReadByte() <> 0;
2233 if OldJet
and not FJetpack
then
2235 else if not OldJet
and FJetpack
then
2237 if FFlaming
and not Flam
then
2239 if Team
<> NewTeam
then
2240 Pl
.ChangeTeam(NewTeam
);
2246 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2251 Attacker
, Value
: Word;
2255 if not gGameOn
then Exit
;
2256 PID
:= M
.ReadWord();
2257 Pl
:= g_Player_Get(PID
);
2258 if Pl
= nil then Exit
;
2260 Kind
:= M
.ReadByte();
2261 Attacker
:= M
.ReadWord();
2262 Value
:= M
.ReadWord();
2267 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2272 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2276 KillType
, DeathType
: Byte;
2280 if not gGameOn
then Exit
;
2281 PID
:= M
.ReadWord();
2282 Pl
:= g_Player_Get(PID
);
2283 if Pl
= nil then Exit
;
2285 KillType
:= M
.ReadByte();
2286 DeathType
:= M
.ReadByte();
2287 Attacker
:= M
.ReadWord();
2291 Kill(KillType
, Attacker
, DeathType
);
2296 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2301 PID
:= M
.ReadWord();
2302 Pl
:= g_Player_Get(PID
);
2304 if Pl
= nil then Exit
;
2306 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2307 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2309 g_Player_Remove(PID
);
2314 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2319 X
, Y
, AX
, AY
: Integer;
2323 if not gGameOn
then Exit
;
2324 PID
:= M
.ReadWord();
2325 Pl
:= g_Player_Get(PID
);
2326 if Pl
= nil then Exit
;
2328 Weap
:= M
.ReadByte();
2329 X
:= M
.ReadLongInt();
2330 Y
:= M
.ReadLongInt();
2331 AX
:= M
.ReadLongInt();
2332 AY
:= M
.ReadLongInt();
2333 SHID
:= M
.ReadLongInt();
2336 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2339 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2348 PID
:= M
.ReadWord();
2349 Pl
:= g_Player_Get(PID
);
2350 if Pl
= nil then Exit
;
2352 TmpName
:= M
.ReadString();
2353 TmpModel
:= M
.ReadString();
2354 TmpColor
.R
:= M
.ReadByte();
2355 TmpColor
.G
:= M
.ReadByte();
2356 TmpColor
.B
:= M
.ReadByte();
2357 TmpTeam
:= M
.ReadByte();
2359 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2361 Pl
.ChangeTeam(TmpTeam
);
2362 if gPlayer1
= Pl
then
2363 gPlayer1Settings
.Team
:= TmpTeam
;
2364 if gPlayer2
= Pl
then
2365 gPlayer2Settings
.Team
:= TmpTeam
;
2367 Pl
.SetColor(TmpColor
);
2369 if Pl
.Name
<> TmpName
then
2371 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2375 if TmpModel
<> Pl
.Model
.Name
then
2376 Pl
.SetModel(TmpModel
);
2381 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2385 X
, Y
, VX
, VY
: Integer;
2387 Quiet
, Fall
{, Resp}: Boolean;
2391 if not gGameOn
then Exit
;
2393 Quiet
:= M
.ReadByte() <> 0;
2395 Fall
:= M
.ReadByte() <> 0;
2396 {Resp :=} M
.ReadByte();
2397 X
:= M
.ReadLongInt();
2398 Y
:= M
.ReadLongInt();
2399 VX
:= M
.ReadLongInt();
2400 VY
:= M
.ReadLongInt();
2402 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2403 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2405 it
:= g_Items_ByIdx(ID
);
2411 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2412 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2414 Anim
:= TAnimation
.Create(AID
, False, 4);
2415 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2421 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2426 if not gGameOn
then Exit
;
2428 Quiet
:= M
.ReadByte() <> 0;
2430 if not g_Items_ValidId(ID
) then exit
;
2432 if not Quiet
then g_Items_EmitPickupSound(ID
);
2439 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2446 if not gGameOn
then Exit
;
2448 PGUID
:= Integer(M
.ReadLongWord());
2449 Tex
:= M
.ReadLongInt();
2450 Fr
:= M
.ReadLongInt();
2451 Cnt
:= M
.ReadByte();
2452 Loop
:= M
.ReadByte();
2454 TP
:= g_Map_PanelByGUID(PGUID
);
2458 TP
.SetTexture(Tex
, Loop
);
2459 TP
.SetFrame(Fr
, Cnt
);
2463 procedure MC_RECV_PanelState(var M
: TMsg
);
2468 X
, Y
, W
, H
: Integer;
2470 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2471 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2474 if not gGameOn
then Exit
;
2476 PGUID
:= Integer(M
.ReadLongWord());
2477 E
:= (M
.ReadByte() <> 0);
2478 Lift
:= M
.ReadByte();
2479 X
:= M
.ReadLongInt();
2480 Y
:= M
.ReadLongInt();
2484 speedX
:= M
.ReadLongInt();
2485 speedY
:= M
.ReadLongInt();
2486 startX
:= M
.ReadLongInt();
2487 startY
:= M
.ReadLongInt();
2488 endX
:= M
.ReadLongInt();
2489 endY
:= M
.ReadLongInt();
2490 sizeSpX
:= M
.ReadLongInt();
2491 sizeSpY
:= M
.ReadLongInt();
2492 sizeEX
:= M
.ReadLongInt();
2493 sizeEY
:= M
.ReadLongInt();
2494 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2496 TP
:= g_Map_PanelByGUID(PGUID
);
2497 if (TP
= nil) then exit
;
2499 // update lifts state
2500 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2502 // update enabled/disabled state for all panels
2503 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2505 // update panel position, as it can be moved (mplat)
2510 // update mplat state
2511 TP
.movingSpeedX
:= speedX
;
2512 TP
.movingSpeedY
:= speedY
;
2513 TP
.movingStartX
:= startX
;
2514 TP
.movingStartY
:= startY
;
2515 TP
.movingEndX
:= endX
;
2516 TP
.movingEndY
:= endY
;
2517 TP
.sizeSpeedX
:= sizeSpX
;
2518 TP
.sizeSpeedY
:= sizeSpY
;
2519 TP
.sizeEndX
:= sizeEX
;
2520 TP
.sizeEndY
:= sizeEY
;
2521 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2522 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2523 // notify panel of it's position/size change, so it can fix other internal structures
2524 TP
.positionChanged();
2529 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2532 SPos
, SID
: LongWord;
2536 if not gGameOn
then Exit
;
2537 if gTriggers
= nil then Exit
;
2539 SID
:= M
.ReadLongWord();
2540 SPlaying
:= M
.ReadByte() <> 0;
2541 SPos
:= M
.ReadLongWord();
2542 SCount
:= M
.ReadLongInt();
2544 for I
:= Low(gTriggers
) to High(gTriggers
) do
2545 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2546 if gTriggers
[I
].ClientID
= SID
then
2547 with gTriggers
[I
] do
2549 if Sound
<> nil then
2554 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2556 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2557 Sound
.SetPosition(SPos
);
2560 if Sound
.IsPlaying
then Sound
.Stop
;
2563 SoundPlayCount
:= SCount
;
2567 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2574 if not gGameOn
then Exit
;
2576 MName
:= M
.ReadString();
2577 MPlaying
:= M
.ReadByte() <> 0;
2578 MPos
:= M
.ReadLongWord();
2579 MPaused
:= M
.ReadByte() <> 0;
2583 gMusic
.SetByName(MName
);
2585 gMusic
.SetPosition(MPos
);
2586 gMusic
.SpecPause
:= MPaused
;
2589 if gMusic
.IsPlaying
then gMusic
.Stop
;
2594 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2597 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2598 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2603 Mon
:= g_Monsters_ByUID(ID
);
2607 MType
:= M
.ReadByte();
2608 MState
:= M
.ReadByte();
2609 MAnim
:= M
.ReadByte();
2610 MTarg
:= M
.ReadWord();
2611 MTargTime
:= M
.ReadLongInt();
2612 MBehav
:= M
.ReadByte();
2613 MSleep
:= M
.ReadLongInt();
2614 MHealth
:= M
.ReadLongInt();
2615 MAmmo
:= M
.ReadLongInt();
2617 X
:= M
.ReadLongInt();
2618 Y
:= M
.ReadLongInt();
2619 VX
:= M
.ReadLongInt();
2620 VY
:= M
.ReadLongInt();
2621 MDir
:= M
.ReadByte();
2623 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2624 Mon
:= g_Monsters_ByUID(ID
);
2631 MonsterAnim
:= MAnim
;
2632 MonsterTargetUID
:= MTarg
;
2633 MonsterTargetTime
:= MTargTime
;
2634 MonsterBehaviour
:= MBehav
;
2635 MonsterSleep
:= MSleep
;
2636 MonsterAmmo
:= MAmmo
;
2641 setPosition(X
, Y
); // this will call positionChanged();
2647 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2654 Mon
:= g_Monsters_ByUID(ID
);
2660 X
:= M
.ReadLongInt();
2661 Y
:= M
.ReadLongInt();
2662 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2663 GameVelX
:= M
.ReadLongInt();
2664 GameVelY
:= M
.ReadLongInt();
2665 GameDirection
:= TDirection(M
.ReadByte());
2669 procedure MC_RECV_MonsterState(var M
: TMsg
);
2671 ID
, OldFire
: Integer;
2672 MState
, MFAnm
: Byte;
2674 AnimRevert
: Boolean;
2677 Mon
:= g_Monsters_ByUID(ID
);
2678 if Mon
= nil then Exit
;
2680 MState
:= M
.ReadByte();
2681 MFAnm
:= M
.ReadByte();
2685 MonsterTargetUID
:= M
.ReadWord();
2686 MonsterTargetTime
:= M
.ReadLongInt();
2687 MonsterSleep
:= M
.ReadLongInt();
2688 MonsterHealth
:= M
.ReadLongInt();
2689 MonsterAmmo
:= M
.ReadLongInt();
2690 MonsterPain
:= M
.ReadLongInt();
2691 AnimRevert
:= M
.ReadByte() <> 0;
2692 OldFire
:= FFireTime
;
2693 FFireTime
:= M
.ReadLongInt();
2694 if (OldFire
<= 0) and (FFireTime
> 0) then
2695 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2696 RevertAnim(AnimRevert
);
2698 if MonsterState
<> MState
then
2700 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2701 if (MState
= MONSTATE_DIE
) then DieSound();
2702 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2703 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2704 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2706 SetState(MState
, MFAnm
);
2711 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2715 X
, Y
, VX
, VY
: Integer;
2719 Mon
:= g_Monsters_ByUID(ID
);
2720 if Mon
= nil then Exit
;
2722 X
:= M
.ReadLongInt();
2723 Y
:= M
.ReadLongInt();
2724 VX
:= M
.ReadLongInt();
2725 VY
:= M
.ReadLongInt();
2727 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2730 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2736 Mon
:= g_Monsters_ByUID(ID
);
2737 if Mon
= nil then Exit
;
2739 Mon
.MonsterRemoved
:= True;
2742 procedure MC_RECV_TimeSync(var M
: TMsg
);
2746 Time
:= M
.ReadLongWord();
2748 if gState
= STATE_INTERCUSTOM
then
2749 gServInterTime
:= Min(Time
, 255);
2752 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2756 Int1
, Int2
: SmallInt;
2758 EvID
:= M
.ReadByte();
2759 Int1
:= M
.ReadSmallInt();
2760 Int2
:= M
.ReadSmallInt();
2761 Str1
:= M
.ReadString();
2762 Str2
:= M
.ReadString();
2766 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2768 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2770 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2772 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2774 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2780 procedure MC_SEND_Info(Password
: string);
2784 NetOut
.Write(Byte(NET_MSG_INFO
));
2785 NetOut
.Write(GAME_VERSION
);
2786 NetOut
.Write(Password
);
2787 NetOut
.Write(gPlayer1Settings
.Name
);
2788 NetOut
.Write(gPlayer1Settings
.Model
);
2789 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2790 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2791 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2792 NetOut
.Write(gPlayer1Settings
.Team
);
2794 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2797 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2799 NetOut
.Write(Byte(NET_MSG_CHAT
));
2803 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2806 procedure MC_SEND_PlayerPos();
2811 WeaponSelect
: Word = 0;
2814 if not gGameOn
then Exit
;
2815 if gPlayers
= nil then Exit
;
2816 if gPlayer1
= nil then Exit
;
2819 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2821 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2823 strafeDir
:= P1MoveButton
shr 4;
2824 P1MoveButton
:= P1MoveButton
and $0F;
2826 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2828 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2830 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2834 if gPlayerAction
[0, ACTION_STRAFE
] then
2836 // new strafe mechanics
2837 if (strafeDir
= 0) then
2838 strafeDir
:= P1MoveButton
; // start strafing
2839 // now set direction according to strafe (reversed)
2840 if (strafeDir
= 2) then
2841 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2842 else if (strafeDir
= 1) then
2843 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2847 strafeDir
:= 0; // not strafing anymore
2848 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
2849 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2850 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2851 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2852 else if P1MoveButton
<> 0 then
2853 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2856 gPlayer1
.ReleaseKeys
;
2857 if P1MoveButton
= 1 then
2859 kByte
:= kByte
or NET_KEY_LEFT
;
2860 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2862 if P1MoveButton
= 2 then
2864 kByte
:= kByte
or NET_KEY_RIGHT
;
2865 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2867 if gPlayerAction
[0, ACTION_LOOKUP
] then
2869 kByte
:= kByte
or NET_KEY_UP
;
2870 gPlayer1
.PressKey(KEY_UP
, 10000);
2872 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2874 kByte
:= kByte
or NET_KEY_DOWN
;
2875 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2877 if gPlayerAction
[0, ACTION_JUMP
] then
2879 kByte
:= kByte
or NET_KEY_JUMP
;
2880 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2882 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
2883 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
2884 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
2885 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
2887 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2888 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2890 for i
:= WP_FIRST
to WP_LAST
do
2892 if gSelectWeapon
[0, i
] then
2894 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
2895 gSelectWeapon
[0, i
] := False
2899 // fix movebutton state
2900 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2903 kByte
:= NET_KEY_CHAT
;
2905 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2906 NetOut
.Write(gTime
);
2907 NetOut
.Write(kByte
);
2908 NetOut
.Write(Byte(gPlayer1
.Direction
));
2909 NetOut
.Write(WeaponSelect
);
2910 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2911 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2913 //kBytePrev := kByte;
2914 //kDirPrev := gPlayer1.Direction;
2917 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2919 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2920 NetOut
.Write(Byte(Start
));
2921 NetOut
.Write(Command
);
2922 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2925 procedure MC_SEND_PlayerSettings();
2927 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2928 NetOut
.Write(gPlayer1Settings
.Name
);
2929 NetOut
.Write(gPlayer1Settings
.Model
);
2930 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2931 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2932 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2933 NetOut
.Write(gPlayer1Settings
.Team
);
2935 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2938 procedure MC_SEND_FullStateRequest();
2940 NetOut
.Write(Byte(NET_MSG_REQFST
));
2942 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2945 procedure MC_SEND_CheatRequest(Kind
: Byte);
2947 NetOut
.Write(Byte(NET_MSG_CHEAT
));
2950 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2952 procedure MC_SEND_RCONPassword(Password
: string);
2954 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
2955 NetOut
.Write(Password
);
2957 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2959 procedure MC_SEND_RCONCommand(Cmd
: string);
2961 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
2964 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2967 // i have no idea why all this stuff is in here
2969 function ReadFile(const FileName
: TFileName
): AByte
;
2971 FileStream
: TStream
;
2974 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), TMsgType
.Notify
);
2975 fname
:= findDiskWad(FileName
);
2976 if length(fname
) = 0 then
2978 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), TMsgType
.Fatal
);
2979 SetLength(Result
, 0);
2982 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), TMsgType
.Notify
);
2984 FileStream
:= openDiskFileRO(fname
);
2986 if FileStream
.Size
> 0 then
2988 SetLength(Result
, FileStream
.Size
);
2989 FileStream
.Read(Result
[0], FileStream
.Size
);
2996 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
3000 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
3001 Result
.FileData
:= ReadFile(FileName
);
3002 Result
.FileSize
:= Length(Result
.FileData
);
3004 SetLength(Result
.ExternalResources
, ResList
.Count
);
3005 for i
:=0 to ResList
.Count
-1 do
3007 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
3008 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
3012 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
3014 ResultStream
: TMemoryStream
;
3016 ResultStream
:= TMemoryStream
.Create
;
3018 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
3019 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
3020 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
3022 SetLength(bytes
, ResultStream
.Size
);
3023 ResultStream
.Seek(0, soFromBeginning
);
3024 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3029 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
3031 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3032 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
3033 SetLength(Result
.FileData
, Result
.FileSize
);
3034 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
3037 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
3039 ResultStream
: TMemoryStream
;
3042 resCount
:= Length(MapDataMsg
.ExternalResources
);
3044 ResultStream
:= TMemoryStream
.Create
;
3046 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
3047 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
3048 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
3050 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
3051 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
3053 SetLength(bytes
, ResultStream
.Size
);
3054 ResultStream
.Seek(0, soFromBeginning
);
3055 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3060 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
3064 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3065 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3067 SetLength(Result
.FileData
, Result
.FileSize
);
3068 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3070 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3071 SetLength(Result
.ExternalResources
, resCount
);
3073 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3076 function IsValidFileName(const S
: String): Boolean;
3078 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3083 for I
:= 1 to Length(S
) do
3084 Result
:= Result
and (not(S
[I
] in Forbidden
));
3087 function IsValidFilePath(const S
: String): Boolean;
3092 if not IsValidFileName(S
) then exit
;
3093 if FileExists(S
) then exit
;
3094 I
:= LastDelimiter('\/', S
);
3096 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3101 procedure MC_SEND_MapRequest();
3103 NetOut
.Write(Byte(NET_MSG_MAP_REQUEST
));
3104 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3107 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3109 NetOut
.Write(Byte(NET_MSG_RES_REQUEST
));
3110 NetOut
.Write(resName
);
3111 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3114 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
3118 mapDataMsg
: TMapDataMsg
;
3120 e_WriteLog('NET: Received map request from ' +
3121 DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3123 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3124 peer
:= NetClients
[C
^.ID
].Peer
;
3126 MapDataMsgToBytes(payload
, mapDataMsg
);
3127 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3130 mapDataMsg
.FileData
:= nil;
3131 mapDataMsg
.ExternalResources
:= nil;
3134 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
3139 resDataMsg
: TResDataMsg
;
3141 FileName
:= ExtractFileName(M
.ReadString());
3142 e_WriteLog('NET: Received res request: ' + FileName
+
3143 ' from ' + DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3145 if not IsValidFilePath(FileName
) then
3147 e_WriteLog('Invalid filename: ' + FileName
, TMsgType
.Warning
);
3151 peer
:= NetClients
[C
^.ID
].Peer
;
3153 if gExternalResources
.IndexOf(FileName
) > -1 then
3155 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3156 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3157 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3159 ResDataMsgToBytes(payload
, resDataMsg
);
3160 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);