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}
19 {.$DEFINE K8_XXX_WEAPON_DEBUG}
23 uses e_msg
, g_net
, g_triggers
, Classes
, SysUtils
, md5
;
67 NET_MSG_RCON_AUTH
= 191;
68 NET_MSG_RCON_CMD
= 192;
69 NET_MSG_TIME_SYNC
= 194;
70 NET_MSG_VOTE_EVENT
= 195;
72 NET_MSG_MAP_REQUEST
= 201;
73 NET_MSG_MAP_RESPONSE
= 202;
74 NET_MSG_RES_REQUEST
= 203;
75 NET_MSG_RES_RESPONSE
= 204;
98 NET_EV_CHANGE_TEAM
= 3;
99 NET_EV_PLAYER_KICK
= 4;
100 NET_EV_PLAYER_BAN
= 5;
101 NET_EV_LMS_WARMUP
= 6;
102 NET_EV_LMS_SURVIVOR
= 7;
106 NET_EV_SCORE_MSG
= 11;
107 NET_EV_LMS_START
= 12;
109 NET_EV_TLMS_WIN
= 14;
110 NET_EV_LMS_LOSE
= 15;
111 NET_EV_LMS_DRAW
= 16;
112 NET_EV_KILLCOMBO
= 17;
113 NET_EV_PLAYER_TOUCH
= 18;
120 NET_VE_INPROGRESS
= 6;
127 NET_CHEAT_SUICIDE
= 1;
128 NET_CHEAT_SPECTATE
= 2;
130 NET_MAX_DIFFTIME
= 5000 div 36;
134 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
135 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
136 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
137 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
138 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
139 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
140 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
141 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
142 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
143 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
144 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
147 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
148 procedure MH_SEND_Info(ID
: Byte);
149 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
150 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
151 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
152 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
153 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
154 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
170 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
186 procedure MH_SEND_VoteEvent(EvType
: Byte;
187 StrArg1
: string = 'a'; StrArg2
: string = 'b';
188 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
189 ID
: Integer = NET_EVERYONE
);
191 // CLIENT MESSAGES //
194 procedure MC_RECV_Chat(var M
: TMsg
);
195 procedure MC_RECV_Effect(var M
: TMsg
);
196 procedure MC_RECV_Sound(var M
: TMsg
);
197 procedure MC_RECV_GameStats(var M
: TMsg
);
198 procedure MC_RECV_CoopStats(var M
: TMsg
);
199 procedure MC_RECV_GameEvent(var M
: TMsg
);
200 procedure MC_RECV_FlagEvent(var M
: TMsg
);
201 procedure MC_RECV_GameSettings(var M
: TMsg
);
203 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
204 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
205 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
206 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
207 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
208 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
209 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
210 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
212 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
213 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
215 procedure MC_RECV_PanelTexture(var M
: TMsg
);
216 procedure MC_RECV_PanelState(var M
: TMsg
);
218 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
219 procedure MC_RECV_MonsterPos(var M
: TMsg
);
220 procedure MC_RECV_MonsterState(var M
: TMsg
);
221 procedure MC_RECV_MonsterShot(var M
: TMsg
);
222 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
224 procedure MC_RECV_CreateShot(var M
: TMsg
);
225 procedure MC_RECV_UpdateShot(var M
: TMsg
);
226 procedure MC_RECV_DeleteShot(var M
: TMsg
);
228 procedure MC_RECV_TriggerSound(var M
: TMsg
);
229 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
231 procedure MC_RECV_TimeSync(var M
: TMsg
);
232 procedure MC_RECV_VoteEvent(var M
: TMsg
);
234 procedure MC_SEND_Info(Password
: string);
235 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
236 procedure MC_SEND_PlayerPos();
237 procedure MC_SEND_FullStateRequest();
238 procedure MC_SEND_PlayerSettings();
239 procedure MC_SEND_CheatRequest(Kind
: Byte);
240 procedure MC_SEND_RCONPassword(Password
: string);
241 procedure MC_SEND_RCONCommand(Cmd
: string);
242 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
244 procedure MC_SEND_MapRequest();
245 procedure MC_SEND_ResRequest(const resName
: AnsiString);
248 TExternalResourceInfo
= record
263 ExternalResources
: array of TExternalResourceInfo
;
266 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
267 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
272 Math
, ENet
, e_input
, e_graphics
, e_log
,
273 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
274 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
275 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
288 NET_KEY_FORCEDIR
= 4096;
291 //kBytePrev: Word = 0;
292 //kDirPrev: TDirection = D_LEFT;
293 //HostGameTime: Word = 0;
300 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
308 Pl
:= g_Player_Get(PID
);
310 Txt
:= M
.ReadString();
311 Mode
:= M
.ReadByte();
312 if (Mode
= NET_CHAT_SYSTEM
) then
313 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
314 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
315 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
318 MH_SEND_Chat(Txt
, Mode
)
320 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
323 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
325 Ver
, PName
, Model
, Pw
: string;
331 Ver
:= M
.ReadString();
332 Pw
:= M
.ReadString();
333 PName
:= M
.ReadString();
334 Model
:= M
.ReadString();
340 if Ver
<> GAME_VERSION
then
342 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
343 _lc
[I_NET_DISC_VERSION
]);
344 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
348 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
350 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
352 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
353 _lc
[I_NET_DISC_BAN
]);
354 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
358 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
359 _lc
[I_NET_DISC_BAN
]);
360 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
365 if NetPassword
<> '' then
366 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
368 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
369 _lc
[I_NET_DISC_PASSWORD
]);
370 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
378 PID
:= g_Player_Create(Model
, Color
, T
, False);
379 with g_Player_Get(PID
) do
387 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
388 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
389 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
393 with g_Player_Get(PID
) do
397 // round in progress, don't spawn
398 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
403 FWantsInGame
:= True; // TODO: look into this later
406 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
409 for I
:= Low(NetClients
) to High(NetClients
) do
411 if NetClients
[I
].ID
= C
^.ID
then Continue
;
412 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
413 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
414 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
417 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
418 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
420 if NetUseMaster
then g_Net_Slist_Update
;
423 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
426 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
428 C
^.RequestedFullUpdate
:= True;
433 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
436 //WeaponSelect: 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 wctr
:= M
.ReadLongWord();
460 newweapon
:= M
.ReadByte();
461 if (wctr
> Pl
.NetWeapCtr
) then
463 if (newweapon
<> CurrWeap
) then
465 {$IFDEF K8_XXX_WEAPON_DEBUG}
466 writeln('HOST PLRPOS: got: currweap=', CurrWeap
, '; curfrm=', gTime
, '; netweap=', newweapon
, '; oldweap=', CurrWeap
);
468 SetWeaponHost(newweapon
);
470 Pl
.NetWeapCtr
:= wctr
;
472 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
473 if Direction
<> TDirection(Dir
) then
474 JustTeleported
:= False;
476 SetDirection(TDirection(Dir
));
477 ReleaseKeysNoWeapon();
479 if kByte
= NET_KEY_CHAT
then
481 PressKey(KEY_CHAT
, 10000);
485 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
486 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
487 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
488 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
489 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
490 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
491 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
492 //if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
493 //if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
498 if (WeaponSelect and Word(1 shl i)) <> 0 then
500 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
501 QueueWeaponSwitch(i);
507 // MH_SEND_PlayerPos(False, PID, C^.ID);
510 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
515 Pl
:= g_Player_Get(C
^.Player
);
516 if Pl
= nil then Exit
;
518 CheatKind
:= M
.ReadByte();
522 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
525 if Pl
.FSpectator
then
533 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
541 TmpName
:= M
.ReadString();
542 TmpModel
:= M
.ReadString();
543 TmpColor
.R
:= M
.ReadByte();
544 TmpColor
.G
:= M
.ReadByte();
545 TmpColor
.B
:= M
.ReadByte();
546 TmpTeam
:= M
.ReadByte();
548 Pl
:= g_Player_Get(C
^.Player
);
549 if Pl
= nil then Exit
;
551 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
554 Pl
.SetColor(TmpColor
);
556 if Pl
.Name
<> TmpName
then
558 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
562 if TmpModel
<> Pl
.Model
.Name
then
563 Pl
.SetModel(TmpModel
);
565 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
570 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
574 Pwd
:= M
.ReadString();
575 if not NetAllowRCON
then Exit
;
576 if Pwd
= NetRCONPassword
then
579 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
582 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
585 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
589 Cmd
:= M
.ReadString();
590 if not NetAllowRCON
then Exit
;
591 if not C
^.RCONAuth
then
593 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
596 g_Console_Process(Cmd
);
601 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
604 Name
, Command
: string;
608 Start
:= M
.ReadByte() <> 0;
609 Command
:= M
.ReadString();
611 Pl
:= g_Player_Get(C
^.Player
);
612 if Pl
= nil then Exit
;
617 if not g_Console_CommandBlacklisted(Command
) then
618 g_Game_StartVote(Command
, Name
);
620 else if gVoteInProgress
then
622 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
623 Need
:= Floor((NetClientCount
+1)/2.0) + 1
625 Need
:= Floor(NetClientCount
/2.0) + 1;
630 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
631 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
637 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
638 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
646 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
648 function sendItemRespawn (it
: PItem
): Boolean;
650 result
:= false; // don't stop
651 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
654 function sendMonSpawn (mon
: TMonster
): Boolean;
656 result
:= false; // don't stop
657 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
660 function sendPanelState (pan
: TPanel
): Boolean;
662 result
:= false; // don't stop
663 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
664 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
670 if gPlayers
<> nil then
672 for I
:= Low(gPlayers
) to High(gPlayers
) do
674 if gPlayers
[I
] <> nil then
676 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
677 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
678 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
680 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
682 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
688 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
689 g_Mons_ForEach(sendMonSpawn
);
690 g_Map_ForEachPanel(sendPanelState
);
692 if gTriggers
<> nil then
694 for I
:= Low(gTriggers
) to High(gTriggers
) do
696 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
698 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
705 for I
:= Low(Shots
) to High(Shots
) do
707 if Shots
[i
].ShotType
in [6, 7, 8] then
709 MH_SEND_CreateShot(i
, ID
);
714 MH_SEND_TriggerMusic(ID
);
716 MH_SEND_GameStats(ID
);
717 MH_SEND_CoopStats(ID
);
719 if gGameSettings
.GameMode
= GM_CTF
then
721 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
722 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
725 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
727 if gLMSRespawn
> LMS_RESPAWN_NONE
then
729 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
733 procedure MH_SEND_Info(ID
: Byte);
737 Map
:= g_ExtractFileName(gMapInfo
.Map
);
741 NetOut
.Write(Byte(NET_MSG_INFO
));
743 NetOut
.Write(NetClients
[ID
].Player
);
744 NetOut
.Write(gGameSettings
.WAD
);
746 NetOut
.Write(gWADHash
);
747 NetOut
.Write(gGameSettings
.GameMode
);
748 NetOut
.Write(gGameSettings
.GoalLimit
);
749 NetOut
.Write(gGameSettings
.TimeLimit
);
750 NetOut
.Write(gGameSettings
.MaxLives
);
751 NetOut
.Write(gGameSettings
.Options
);
754 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
757 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
763 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
764 Mode
:= NET_CHAT_PLAYER
;
767 if (Mode
= NET_CHAT_TEAM
) then
769 for i
:= Low(gPlayers
) to High(gPlayers
) do
770 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
771 (gPlayers
[i
].Team
= ID
) then
773 NetOut
.Write(Byte(NET_MSG_CHAT
));
776 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
783 NetOut
.Write(Byte(NET_MSG_CHAT
));
786 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
789 if Mode
= NET_CHAT_SYSTEM
then
792 if ID
= NET_EVERYONE
then
794 if Mode
= NET_CHAT_PLAYER
then
796 g_Console_Add(Txt
, True);
797 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
798 g_Game_ChatSound(b_Text_Unformat(Txt
));
801 if Mode
= NET_CHAT_TEAM
then
802 if gPlayer1
<> nil then
804 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
806 g_Console_Add(#18'[Team] '#2 + Txt
, True);
807 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
808 g_Game_ChatSound(b_Text_Unformat(Txt
));
810 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
812 g_Console_Add(#20'[Team] '#2 + Txt
, True);
813 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
814 g_Game_ChatSound(b_Text_Unformat(Txt
));
820 Name
:= g_Net_ClientName_ByID(ID
);
821 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
822 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
823 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
827 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
829 NetOut
.Write(Byte(NET_MSG_GFX
));
835 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
838 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
840 NetOut
.Write(Byte(NET_MSG_SND
));
844 NetOut
.Write(Byte(1));
849 NetOut
.Write(Byte(0));
851 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
854 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
856 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
858 NetOut
.Write(Byte(NET_MSG_SHADD
));
860 NetOut
.Write(Shots
[Proj
].ShotType
);
861 NetOut
.Write(Shots
[Proj
].Target
);
862 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
863 NetOut
.Write(Shots
[Proj
].Timeout
);
864 NetOut
.Write(Shots
[Proj
].Obj
.X
);
865 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
866 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
867 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
869 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
872 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
874 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
876 NetOut
.Write(Byte(NET_MSG_SHPOS
));
878 NetOut
.Write(Shots
[Proj
].Obj
.X
);
879 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
880 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
881 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
883 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
886 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
888 NetOut
.Write(Byte(NET_MSG_SHDEL
));
890 NetOut
.Write(Byte(Loud
));
894 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
897 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
899 NetOut
.Write(Byte(NET_MSG_SCORE
));
900 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
902 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
903 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
906 if gGameSettings
.GameMode
= GM_COOP
then
908 NetOut
.Write(gCoopMonstersKilled
);
909 NetOut
.Write(gCoopSecretsFound
);
912 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
915 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
917 NetOut
.Write(Byte(NET_MSG_COOP
));
918 NetOut
.Write(gTotalMonsters
);
919 NetOut
.Write(gSecretsCount
);
920 NetOut
.Write(gCoopTotalMonstersKilled
);
921 NetOut
.Write(gCoopTotalSecretsFound
);
922 NetOut
.Write(gCoopTotalMonsters
);
923 NetOut
.Write(gCoopTotalSecrets
);
926 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
928 NetOut
.Write(Byte(NET_MSG_GEVENT
));
929 NetOut
.Write(EvType
);
932 NetOut
.Write(Byte(gLastMap
));
934 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
936 NetOut
.Write(Byte(1));
937 NetOut
.Write(gWADHash
);
939 NetOut
.Write(Byte(0));
941 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
944 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
946 NetOut
.Write(Byte(NET_MSG_FLAG
));
947 NetOut
.Write(EvType
);
949 NetOut
.Write(Byte(Quiet
));
951 NetOut
.Write(gFlags
[Flag
].State
);
952 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
953 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
954 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
955 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
956 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
958 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
961 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
963 NetOut
.Write(Byte(NET_MSG_GSET
));
964 NetOut
.Write(gGameSettings
.GameMode
);
965 NetOut
.Write(gGameSettings
.GoalLimit
);
966 NetOut
.Write(gGameSettings
.TimeLimit
);
967 NetOut
.Write(gGameSettings
.MaxLives
);
968 NetOut
.Write(gGameSettings
.Options
);
970 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
975 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
979 P
:= g_Player_Get(PID
);
980 if P
= nil then Exit
;
982 NetOut
.Write(Byte(NET_MSG_PLR
));
984 NetOut
.Write(P
.Name
);
986 NetOut
.Write(P
.FActualModelName
);
987 NetOut
.Write(P
.FColor
.R
);
988 NetOut
.Write(P
.FColor
.G
);
989 NetOut
.Write(P
.FColor
.B
);
990 NetOut
.Write(P
.Team
);
992 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
995 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1000 Pl
:= g_Player_Get(PID
);
1001 if Pl
= nil then Exit
;
1002 if Pl
.FDummy
then Exit
;
1004 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1005 NetOut
.Write(gTime
);
1012 NetOut
.Write(FPing
);
1013 NetOut
.Write(FLoss
);
1014 if IsKeyPressed(KEY_CHAT
) then
1016 kByte
:= NET_KEY_CHAT
;
1020 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1021 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1022 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1023 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1024 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1025 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1028 NetOut
.Write(kByte
);
1029 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1031 NetOut
.Write(LongWord(Pl
.NetWeapCtr
));
1032 NetOut
.Write(Byte(Pl
.CurrWeap
));
1034 NetOut
.Write(GameX
);
1035 NetOut
.Write(GameY
);
1036 NetOut
.Write(GameVelX
);
1037 NetOut
.Write(GameVelY
);
1038 NetOut
.Write(GameAccelX
);
1039 NetOut
.Write(GameAccelY
);
1042 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1045 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1051 P
:= g_Player_Get(PID
);
1052 if P
= nil then Exit
;
1054 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1059 NetOut
.Write(Byte(alive
));
1060 NetOut
.Write(Byte(GodMode
));
1061 NetOut
.Write(Health
);
1062 NetOut
.Write(Armor
);
1064 NetOut
.Write(JetFuel
);
1065 NetOut
.Write(Lives
);
1068 // collect all weapons in one word
1070 for I
:= WP_FIRST
to WP_LAST
do if (FWeapon
[I
]) then ww
:= ww
or (1 shl (i
-WP_FIRST
));
1071 NetOut
.Write(Word(ww
));
1073 for I
:= A_BULLETS
to A_HIGH
do
1074 NetOut
.Write(FAmmo
[I
]);
1076 for I
:= A_BULLETS
to A_HIGH
do
1077 NetOut
.Write(FMaxAmmo
[I
]);
1079 for I
:= MR_SUIT
to MR_MAX
do
1080 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1082 // collect all special flags in one byte
1084 if (R_ITEM_BACKPACK
in FRulez
) then ww
:= ww
or $01;
1085 if (R_KEY_RED
in FRulez
) then ww
:= ww
or $02;
1086 if (R_KEY_GREEN
in FRulez
) then ww
:= ww
or $04;
1087 if (R_KEY_BLUE
in FRulez
) then ww
:= ww
or $08;
1088 if (R_BERSERK
in FRulez
) then ww
:= ww
or $10;
1089 NetOut
.Write(Byte(ww
));
1091 NetOut
.Write(Frags
);
1092 NetOut
.Write(Death
);
1094 NetOut
.Write(LongWord(NetWeapCtr
));
1095 NetOut
.Write(Byte(CurrWeap
));
1099 if (FSpectator
) then ww
:= ww
or $01;
1100 if (FGhost
) then ww
:= ww
or $02;
1101 if (FPhysics
) then ww
:= ww
or $04;
1102 if (FNoRespawn
) then ww
:= ww
or $08;
1103 if (FJetpack
) then ww
:= ww
or $10;
1104 NetOut
.Write(Byte(ww
));
1106 NetOut
.Write(FFireTime
);
1109 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1112 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1114 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1117 NetOut
.Write(Attacker
);
1118 NetOut
.Write(Value
);
1122 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1125 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1127 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1129 NetOut
.Write(KillType
);
1130 NetOut
.Write(DeathType
);
1131 NetOut
.Write(Attacker
);
1133 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1136 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1138 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1140 NetOut
.Write(Weapon
);
1145 NetOut
.Write(ShotID
);
1147 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1150 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1152 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1155 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1158 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1162 Pl
:= g_Player_Get(PID
);
1163 if Pl
= nil then Exit
;
1165 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1167 NetOut
.Write(Pl
.Name
);
1169 NetOut
.Write(Pl
.Model
.Name
)
1172 NetOut
.Write(Pl
.FColor
.R
);
1173 NetOut
.Write(Pl
.FColor
.G
);
1174 NetOut
.Write(Pl
.FColor
.B
);
1175 NetOut
.Write(Pl
.Team
);
1177 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1182 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1187 it
:= g_Items_ByIdx(IID
);
1189 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1191 NetOut
.Write(Byte(Quiet
));
1193 if it
.dropped
then tt
:= tt
or $80;
1195 NetOut
.Write(Byte(it
.Fall
));
1196 NetOut
.Write(Byte(it
.Respawnable
));
1197 NetOut
.Write(it
.Obj
.X
);
1198 NetOut
.Write(it
.Obj
.Y
);
1199 NetOut
.Write(it
.Obj
.Vel
.X
);
1200 NetOut
.Write(it
.Obj
.Vel
.Y
);
1202 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1205 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1207 NetOut
.Write(Byte(NET_MSG_IDEL
));
1209 NetOut
.Write(Byte(Quiet
));
1211 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1216 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1220 TP
:= g_Map_PanelByGUID(PGUID
);
1221 if (TP
= nil) then exit
;
1225 NetOut
.Write(Byte(NET_MSG_PTEX
));
1226 NetOut
.Write(LongWord(PGUID
));
1227 NetOut
.Write(FCurTexture
);
1228 NetOut
.Write(FCurFrame
);
1229 NetOut
.Write(FCurFrameCount
);
1230 NetOut
.Write(AnimLoop
);
1233 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1236 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1241 TP
:= g_Map_PanelByGUID(PGUID
);
1242 if (TP
= nil) then exit
;
1244 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1245 NetOut
.Write(LongWord(PGUID
));
1246 NetOut
.Write(Byte(TP
.Enabled
));
1247 NetOut
.Write(TP
.LiftType
);
1250 NetOut
.Write(Word(TP
.Width
));
1251 NetOut
.Write(Word(TP
.Height
));
1253 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1254 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1255 NetOut
.Write(LongInt(TP
.movingStartX
));
1256 NetOut
.Write(LongInt(TP
.movingStartY
));
1257 NetOut
.Write(LongInt(TP
.movingEndX
));
1258 NetOut
.Write(LongInt(TP
.movingEndY
));
1259 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1260 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1261 NetOut
.Write(LongInt(TP
.sizeEndX
));
1262 NetOut
.Write(LongInt(TP
.sizeEndY
));
1263 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1264 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1265 NetOut
.Write(Byte(mpflags
));
1267 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1272 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1274 if gTriggers
= nil then Exit
;
1275 if T
.Sound
= nil then Exit
;
1277 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1278 NetOut
.Write(T
.ClientID
);
1279 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1280 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1281 NetOut
.Write(T
.SoundPlayCount
);
1283 g_Net_Host_Send(ID
, True);
1286 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1288 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1289 NetOut
.Write(gMusic
.Name
);
1290 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1291 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1292 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1294 g_Net_Host_Send(ID
, True);
1299 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1303 M
:= g_Monsters_ByUID(UID
);
1309 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1311 NetOut
.Write(MonsterType
);
1312 NetOut
.Write(MonsterState
);
1313 NetOut
.Write(MonsterAnim
);
1314 NetOut
.Write(MonsterTargetUID
);
1315 NetOut
.Write(MonsterTargetTime
);
1316 NetOut
.Write(MonsterBehaviour
);
1317 NetOut
.Write(MonsterSleep
);
1318 NetOut
.Write(MonsterHealth
);
1319 NetOut
.Write(MonsterAmmo
);
1320 NetOut
.Write(GameX
);
1321 NetOut
.Write(GameY
);
1322 NetOut
.Write(GameVelX
);
1323 NetOut
.Write(GameVelY
);
1324 NetOut
.Write(Byte(GameDirection
));
1327 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1330 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1334 M
:= g_Monsters_ByUID(UID
);
1335 if M
= nil then Exit
;
1337 NetOut
.Write(Byte(NET_MSG_MPOS
));
1342 NetOut
.Write(GameX
);
1343 NetOut
.Write(GameY
);
1344 NetOut
.Write(GameVelX
);
1345 NetOut
.Write(GameVelY
);
1346 NetOut
.Write(Byte(GameDirection
));
1349 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1352 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1356 M
:= g_Monsters_ByUID(UID
);
1357 if M
= nil then Exit
;
1359 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1364 NetOut
.Write(MonsterState
);
1365 NetOut
.Write(ForcedAnim
);
1366 NetOut
.Write(MonsterTargetUID
);
1367 NetOut
.Write(MonsterTargetTime
);
1368 NetOut
.Write(MonsterSleep
);
1369 NetOut
.Write(MonsterHealth
);
1370 NetOut
.Write(MonsterAmmo
);
1371 NetOut
.Write(MonsterPain
);
1372 NetOut
.Write(Byte(AnimIsReverse
));
1373 NetOut
.Write(FFireTime
);
1376 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1379 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1381 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1388 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1391 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1395 M
:= g_Monsters_ByUID(UID
);
1396 if M
= nil then Exit
;
1398 NetOut
.Write(Byte(NET_MSG_MDEL
));
1401 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1406 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1408 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1411 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1414 procedure MH_SEND_VoteEvent(EvType
: Byte;
1415 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1416 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1417 ID
: Integer = NET_EVERYONE
);
1419 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1420 NetOut
.Write(EvType
);
1421 NetOut
.Write(IntArg1
);
1422 NetOut
.Write(IntArg2
);
1423 NetOut
.Write(StrArg1
);
1424 NetOut
.Write(StrArg2
);
1426 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1429 // CLIENT MESSAGES //
1433 procedure MC_RECV_Chat(var M
: TMsg
);
1438 Txt
:= M
.ReadString();
1439 Mode
:= M
.ReadByte();
1441 if Mode
<> NET_CHAT_SYSTEM
then
1443 if Mode
= NET_CHAT_PLAYER
then
1445 g_Console_Add(Txt
, True);
1446 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1447 g_Game_ChatSound(b_Text_Unformat(Txt
));
1449 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1451 if gPlayer1
.Team
= TEAM_RED
then
1452 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1453 if gPlayer1
.Team
= TEAM_BLUE
then
1454 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1455 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1456 g_Game_ChatSound(b_Text_Unformat(Txt
));
1459 g_Console_Add(Txt
, True);
1462 procedure MC_RECV_Effect(var M
: TMsg
);
1470 if not gGameOn
then Exit
;
1471 Kind
:= M
.ReadByte();
1472 X
:= M
.ReadLongInt();
1473 Y
:= M
.ReadLongInt();
1474 Ang
:= M
.ReadSmallInt();
1478 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1482 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1484 Anim
:= TAnimation
.Create(ID
, False, 3);
1485 g_GFX_OnceAnim(X
, Y
, Anim
);
1489 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1494 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1496 Anim
:= TAnimation
.Create(ID
, False, 6);
1497 Anim
.Blending
:= False;
1498 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1502 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1507 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1509 Anim
:= TAnimation
.Create(ID
, False, 6);
1510 Anim
.Blending
:= False;
1511 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1515 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1520 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1522 Anim
:= TAnimation
.Create(ID
, False, 4);
1523 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1530 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1532 Anim
:= TAnimation
.Create(ID
, False, 4);
1533 g_GFX_OnceAnim(X
, Y
, Anim
);
1537 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1542 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1544 Anim
:= TAnimation
.Create(ID
, False, 4);
1545 g_GFX_OnceAnim(X
, Y
, Anim
);
1549 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1553 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1556 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1560 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1561 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1566 procedure MC_RECV_Sound(var M
: TMsg
);
1572 Name
:= M
.ReadString();
1573 Pos
:= M
.ReadByte() <> 0;
1576 X
:= M
.ReadLongInt();
1577 Y
:= M
.ReadLongInt();
1578 g_Sound_PlayExAt(Name
, X
, Y
);
1581 g_Sound_PlayEx(Name
);
1584 procedure MC_RECV_CreateShot(var M
: TMsg
);
1586 I
, X
, Y
, XV
, YV
: Integer;
1588 Target
, Spawner
: Word;
1591 I
:= M
.ReadLongInt();
1592 ShType
:= M
.ReadByte();
1593 Target
:= M
.ReadWord();
1594 Spawner
:= M
.ReadWord();
1595 Timeout
:= M
.ReadLongWord();
1596 X
:= M
.ReadLongInt();
1597 Y
:= M
.ReadLongInt();
1598 XV
:= M
.ReadLongInt();
1599 YV
:= M
.ReadLongInt();
1601 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1602 if (Shots
<> nil) and (I
<= High(Shots
)) then
1604 Shots
[I
].Timeout
:= Timeout
;
1605 //Shots[I].Target := Target; // TODO: find a use for Target later
1609 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1611 I
, TX
, TY
, TXV
, TYV
: Integer;
1613 I
:= M
.ReadLongInt();
1614 TX
:= M
.ReadLongInt();
1615 TY
:= M
.ReadLongInt();
1616 TXV
:= M
.ReadLongInt();
1617 TYV
:= M
.ReadLongInt();
1619 if (Shots
<> nil) and (I
<= High(Shots
)) then
1629 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1634 if not gGameOn
then Exit
;
1635 I
:= M
.ReadLongInt();
1636 L
:= (M
.ReadByte() <> 0);
1637 X
:= M
.ReadLongInt();
1638 Y
:= M
.ReadLongInt();
1640 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1643 procedure MC_RECV_GameStats(var M
: TMsg
);
1645 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1647 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1648 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1651 if gGameSettings
.GameMode
= GM_COOP
then
1653 gCoopMonstersKilled
:= M
.ReadWord();
1654 gCoopSecretsFound
:= M
.ReadWord();
1658 procedure MC_RECV_CoopStats(var M
: TMsg
);
1660 gTotalMonsters
:= M
.ReadLongInt();
1661 gSecretsCount
:= M
.ReadLongInt();
1662 gCoopTotalMonstersKilled
:= M
.ReadWord();
1663 gCoopTotalSecretsFound
:= M
.ReadWord();
1664 gCoopTotalMonsters
:= M
.ReadWord();
1665 gCoopTotalSecrets
:= M
.ReadWord();
1668 procedure MC_RECV_GameEvent(var M
: TMsg
);
1677 i1
, i2
: TStrings_Locale
;
1681 FillChar(EvHash
, Sizeof(EvHash
), 0);
1682 EvType
:= M
.ReadByte();
1683 EvNum
:= M
.ReadLongInt();
1684 EvStr
:= M
.ReadString();
1685 gLastMap
:= M
.ReadByte() <> 0;
1686 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1687 gStatsPressed
:= True;
1688 EvTime
:= M
.ReadLongWord();
1689 BHash
:= M
.ReadByte() <> 0;
1691 EvHash
:= M
.ReadMD5();
1699 g_Game_ClearLoading();
1700 g_Game_StopAllSounds(True);
1702 gSwitchGameMode
:= Byte(EvNum
);
1703 gGameSettings
.GameMode
:= gSwitchGameMode
;
1706 if not g_Game_StartMap(EvStr
, True) then
1708 if not isWadPath(EvStr
) then
1709 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1711 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1715 MC_SEND_FullStateRequest
;
1720 gMissionFailed
:= EvNum
<> 0;
1721 gExit
:= EXIT_ENDLEVELCUSTOM
;
1728 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1730 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1732 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1738 if EvNum
= TEAM_RED
then
1739 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1740 if EvNum
= TEAM_BLUE
then
1741 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1745 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1748 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1751 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1753 NET_EV_LMS_SURVIVOR
:
1754 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1757 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1761 pl
:= g_Player_Get(EvNum
and $FFFF);
1766 cnt
:= (EvNum
shr 16) and $FF;
1767 if Pos('w', EvStr
) = 0 then
1770 if Pos('t', EvStr
) = 0 then
1773 if Pos('-', EvStr
) = 0 then
1775 if Pos('e', EvStr
) = 0 then
1776 i1
:= I_PLAYER_SCORE_ADD_OWN
1778 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1781 if Pos('e', EvStr
) = 0 then
1782 i1
:= I_PLAYER_SCORE_SUB_OWN
1784 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1787 if Pos('r', EvStr
) > 0 then
1788 i2
:= I_PLAYER_SCORE_TO_RED
1790 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1791 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1795 if Pos('-', EvStr
) = 0 then
1796 i1
:= I_PLAYER_SCORE_ADD_TEAM
1798 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1800 if Pos('r', EvStr
) > 0 then
1801 i2
:= I_PLAYER_SCORE_RED
1803 i2
:= I_PLAYER_SCORE_BLUE
;
1804 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1809 if Pos('e', EvStr
) = 0 then
1810 i1
:= I_PLAYER_SCORE_WIN_OWN
1812 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1814 if Pos('r', EvStr
) > 0 then
1815 i2
:= I_PLAYER_SCORE_TO_RED
1817 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1818 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1824 if EvNum
= TEAM_RED
then
1825 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1826 if EvNum
= TEAM_BLUE
then
1827 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1828 if EvNum
= -TEAM_RED
then
1829 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1830 if EvNum
= -TEAM_BLUE
then
1831 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1836 g_Player_RemoveAllCorpses
;
1837 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1841 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1845 if EvNum
= TEAM_RED
then
1846 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1847 if EvNum
= TEAM_BLUE
then
1848 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1852 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1855 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1858 g_Game_Announce_KillCombo(EvNum
);
1860 NET_EV_PLAYER_TOUCH
:
1862 pl
:= g_Player_Get(EvNum
);
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);
1914 FLAG_STATE_CAPTURED
:
1916 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1920 if Fl
= FLAG_RED
then
1921 s
:= _lc
[I_PLAYER_FLAG_RED
]
1923 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1925 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1926 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1931 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1933 if Quiet
or (Pl
= nil) then Exit
;
1935 if Fl
= FLAG_RED
then
1936 s
:= _lc
[I_PLAYER_FLAG_RED
]
1938 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1940 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1941 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1946 g_Map_ResetFlag(FLAG_RED
);
1947 g_Map_ResetFlag(FLAG_BLUE
);
1948 if Quiet
or (Pl
= nil) then Exit
;
1949 Pl
.SetFlag(FLAG_NONE
);
1951 if Fl
= FLAG_RED
then
1952 s
:= _lc
[I_PLAYER_FLAG_RED
]
1954 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1956 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1957 Insert('.', ts
, Length(ts
) + 1 - 3);
1958 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1959 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1962 FLAG_STATE_RETURNED
:
1964 g_Map_ResetFlag(Fl
);
1967 if Fl
= FLAG_RED
then
1968 s
:= _lc
[I_PLAYER_FLAG_RED
]
1970 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1972 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1977 procedure MC_RECV_GameSettings(var M
: TMsg
);
1979 gGameSettings
.GameMode
:= M
.ReadByte();
1980 gGameSettings
.GoalLimit
:= M
.ReadWord();
1981 gGameSettings
.TimeLimit
:= M
.ReadWord();
1982 gGameSettings
.MaxLives
:= M
.ReadByte();
1983 gGameSettings
.Options
:= M
.ReadLongWord();
1988 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
1991 PName
, Model
: string;
1996 PID
:= M
.ReadWord();
1997 Pl
:= g_Player_Get(PID
);
1999 PName
:= M
.ReadString();
2000 Model
:= M
.ReadString();
2001 Color
.R
:= M
.ReadByte();
2002 Color
.G
:= M
.ReadByte();
2003 Color
.B
:= M
.ReadByte();
2007 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2009 if (Pl
<> nil) then Exit
;
2010 DID
:= g_Player_Create(Model
, Color
, T
, False);
2011 with g_Player_Get(DID
) do
2020 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2021 gPlayer1
.UID
:= PID
;
2022 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2023 gPlayer1
.ChangeTeam(T
);
2025 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2026 gPlayer2
.UID
:= PID
;
2027 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2028 gPlayer2
.ChangeTeam(T
);
2032 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2033 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2037 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2044 TmpX
, TmpY
: Integer;
2048 GT
:= M
.ReadLongWord();
2049 if GT
< gTime
- NET_MAX_DIFFTIME
then
2056 PID
:= M
.ReadWord();
2057 Pl
:= g_Player_Get(PID
);
2059 if Pl
= nil then Exit
;
2065 FPing
:= M
.ReadWord();
2066 FLoss
:= M
.ReadByte();
2067 kByte
:= M
.ReadWord();
2068 Dir
:= M
.ReadByte();
2070 wctr
:= M
.ReadLongWord();
2071 weapon
:= M
.ReadByte();
2072 // `>=`, so server is still the authority
2073 if (wctr
>= Pl
.NetWeapCtr
) then
2075 Pl
.CurrWeap
:= weapon
;
2076 Pl
.NetWeapCtr
:= wctr
;
2079 TmpX
:= M
.ReadLongInt();
2080 TmpY
:= M
.ReadLongInt();
2082 ReleaseKeysNoWeapon
;
2084 if (kByte
= NET_KEY_CHAT
) then
2086 PressKey(KEY_CHAT
, 10000);
2090 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2091 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2092 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2093 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2094 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2097 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2098 SetDirection(TDirection(Dir
));
2100 GameVelX
:= M
.ReadLongInt();
2101 GameVelY
:= M
.ReadLongInt();
2102 GameAccelX
:= M
.ReadLongInt();
2103 GameAccelY
:= M
.ReadLongInt();
2104 SetLerp(TmpX
, TmpY
);
2105 if NetForcePlayerUpdate
then Update();
2109 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2120 PID
:= M
.ReadWord();
2121 Pl
:= g_Player_Get(PID
);
2128 alive
:= (M
.ReadByte() <> 0);
2129 GodMode
:= (M
.ReadByte() <> 0);
2130 Health
:= M
.ReadLongInt();
2131 Armor
:= M
.ReadLongInt();
2132 Air
:= M
.ReadLongInt();
2133 JetFuel
:= M
.ReadLongInt();
2134 Lives
:= M
.ReadByte();
2135 NewTeam
:= M
.ReadByte();
2138 for I
:= WP_FIRST
to WP_LAST
do
2140 FWeapon
[I
] := ((ww
and $01) <> 0);
2144 for I
:= A_BULLETS
to A_HIGH
do
2145 FAmmo
[I
] := M
.ReadWord();
2147 for I
:= A_BULLETS
to A_HIGH
do
2148 FMaxAmmo
[I
] := M
.ReadWord();
2150 for I
:= MR_SUIT
to MR_MAX
do
2151 FMegaRulez
[I
] := M
.ReadLongWord();
2154 // unpack special flags
2156 if ((ww
and $01) <> 0) then FRulez
:= FRulez
+[R_ITEM_BACKPACK
];
2157 if ((ww
and $02) <> 0) then FRulez
:= FRulez
+[R_KEY_RED
];
2158 if ((ww
and $04) <> 0) then FRulez
:= FRulez
+[R_KEY_GREEN
];
2159 if ((ww
and $08) <> 0) then FRulez
:= FRulez
+[R_KEY_BLUE
];
2160 if ((ww
and $10) <> 0) then FRulez
:= FRulez
+[R_BERSERK
];
2162 Frags
:= M
.ReadLongInt();
2163 Death
:= M
.ReadLongInt();
2165 wctr
:= M
.ReadLongWord();
2166 newweapon
:= M
.ReadByte();
2167 {$IFDEF K8_XXX_WEAPON_DEBUG}
2168 writeln('CLIENT PLRSTATS: got: currweap=', CurrWeap
, '; curfrm=', gTime
, '; netweap=', newweapon
, '; lastnwfrm=', NetForceWeapFIdx
);
2170 // `>=`, so server is still the authority
2171 if (wctr
>= NetWeapCtr
) then
2173 SetWeaponHost(newweapon
);
2180 FSpectator
:= ((ww
and $01) <> 0);
2183 if Pl
= gPlayer1
then
2188 if Pl
= gPlayer2
then
2196 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2197 gPlayer1
:= g_Player_Get(gLMSPID1
);
2198 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2199 gPlayer2
:= g_Player_Get(gLMSPID2
);
2202 FGhost
:= ((ww
and $02) <> 0);
2203 FPhysics
:= ((ww
and $04) <> 0);
2204 FNoRespawn
:= ((ww
and $08) <> 0);
2206 FJetpack
:= ((ww
and $10) <> 0);
2207 FFireTime
:= M
.ReadLongInt();
2208 if OldJet
and not FJetpack
then
2210 else if not OldJet
and FJetpack
then
2212 if Team
<> NewTeam
then
2213 Pl
.ChangeTeam(NewTeam
);
2219 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2224 Attacker
, Value
: Word;
2228 if not gGameOn
then Exit
;
2229 PID
:= M
.ReadWord();
2230 Pl
:= g_Player_Get(PID
);
2231 if Pl
= nil then Exit
;
2233 Kind
:= M
.ReadByte();
2234 Attacker
:= M
.ReadWord();
2235 Value
:= M
.ReadWord();
2240 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2245 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2249 KillType
, DeathType
: Byte;
2253 if not gGameOn
then Exit
;
2254 PID
:= M
.ReadWord();
2255 Pl
:= g_Player_Get(PID
);
2256 if Pl
= nil then Exit
;
2258 KillType
:= M
.ReadByte();
2259 DeathType
:= M
.ReadByte();
2260 Attacker
:= M
.ReadWord();
2264 Kill(KillType
, Attacker
, DeathType
);
2269 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2274 PID
:= M
.ReadWord();
2275 Pl
:= g_Player_Get(PID
);
2277 if Pl
= nil then Exit
;
2279 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2280 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2282 g_Player_Remove(PID
);
2287 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2292 X
, Y
, AX
, AY
: Integer;
2296 if not gGameOn
then Exit
;
2297 PID
:= M
.ReadWord();
2298 Pl
:= g_Player_Get(PID
);
2299 if Pl
= nil then Exit
;
2301 Weap
:= M
.ReadByte();
2302 X
:= M
.ReadLongInt();
2303 Y
:= M
.ReadLongInt();
2304 AX
:= M
.ReadLongInt();
2305 AY
:= M
.ReadLongInt();
2306 SHID
:= M
.ReadLongInt();
2309 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2312 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2321 PID
:= M
.ReadWord();
2322 Pl
:= g_Player_Get(PID
);
2323 if Pl
= nil then Exit
;
2325 TmpName
:= M
.ReadString();
2326 TmpModel
:= M
.ReadString();
2327 TmpColor
.R
:= M
.ReadByte();
2328 TmpColor
.G
:= M
.ReadByte();
2329 TmpColor
.B
:= M
.ReadByte();
2330 TmpTeam
:= M
.ReadByte();
2332 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2334 Pl
.ChangeTeam(TmpTeam
);
2335 if gPlayer1
= Pl
then
2336 gPlayer1Settings
.Team
:= TmpTeam
;
2337 if gPlayer2
= Pl
then
2338 gPlayer2Settings
.Team
:= TmpTeam
;
2340 Pl
.SetColor(TmpColor
);
2342 if Pl
.Name
<> TmpName
then
2344 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2348 if TmpModel
<> Pl
.Model
.Name
then
2349 Pl
.SetModel(TmpModel
);
2354 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2358 X
, Y
, VX
, VY
: Integer;
2360 Quiet
, Fall
{, Resp}: Boolean;
2364 if not gGameOn
then Exit
;
2366 Quiet
:= M
.ReadByte() <> 0;
2368 Fall
:= M
.ReadByte() <> 0;
2369 {Resp :=} M
.ReadByte();
2370 X
:= M
.ReadLongInt();
2371 Y
:= M
.ReadLongInt();
2372 VX
:= M
.ReadLongInt();
2373 VY
:= M
.ReadLongInt();
2375 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2376 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2378 it
:= g_Items_ByIdx(ID
);
2384 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2385 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2387 Anim
:= TAnimation
.Create(AID
, False, 4);
2388 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2394 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2399 if not gGameOn
then Exit
;
2401 Quiet
:= M
.ReadByte() <> 0;
2403 if not g_Items_ValidId(ID
) then exit
;
2405 if not Quiet
then g_Items_EmitPickupSound(ID
);
2412 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2419 if not gGameOn
then Exit
;
2421 PGUID
:= Integer(M
.ReadLongWord());
2422 Tex
:= M
.ReadLongInt();
2423 Fr
:= M
.ReadLongInt();
2424 Cnt
:= M
.ReadByte();
2425 Loop
:= M
.ReadByte();
2427 TP
:= g_Map_PanelByGUID(PGUID
);
2431 TP
.SetTexture(Tex
, Loop
);
2432 TP
.SetFrame(Fr
, Cnt
);
2436 procedure MC_RECV_PanelState(var M
: TMsg
);
2441 X
, Y
, W
, H
: Integer;
2443 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2444 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2447 if not gGameOn
then Exit
;
2449 PGUID
:= Integer(M
.ReadLongWord());
2450 E
:= (M
.ReadByte() <> 0);
2451 Lift
:= M
.ReadByte();
2452 X
:= M
.ReadLongInt();
2453 Y
:= M
.ReadLongInt();
2457 speedX
:= M
.ReadLongInt();
2458 speedY
:= M
.ReadLongInt();
2459 startX
:= M
.ReadLongInt();
2460 startY
:= M
.ReadLongInt();
2461 endX
:= M
.ReadLongInt();
2462 endY
:= M
.ReadLongInt();
2463 sizeSpX
:= M
.ReadLongInt();
2464 sizeSpY
:= M
.ReadLongInt();
2465 sizeEX
:= M
.ReadLongInt();
2466 sizeEY
:= M
.ReadLongInt();
2467 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2469 TP
:= g_Map_PanelByGUID(PGUID
);
2470 if (TP
= nil) then exit
;
2472 // update lifts state
2473 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2475 // update enabled/disabled state for all panels
2476 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2478 // update panel position, as it can be moved (mplat)
2483 // update mplat state
2484 TP
.movingSpeedX
:= speedX
;
2485 TP
.movingSpeedY
:= speedY
;
2486 TP
.movingStartX
:= startX
;
2487 TP
.movingStartY
:= startY
;
2488 TP
.movingEndX
:= endX
;
2489 TP
.movingEndY
:= endY
;
2490 TP
.sizeSpeedX
:= sizeSpX
;
2491 TP
.sizeSpeedY
:= sizeSpY
;
2492 TP
.sizeEndX
:= sizeEX
;
2493 TP
.sizeEndY
:= sizeEY
;
2494 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2495 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2496 // notify panel of it's position/size change, so it can fix other internal structures
2497 TP
.positionChanged();
2502 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2505 SPos
, SID
: LongWord;
2509 if not gGameOn
then Exit
;
2510 if gTriggers
= nil then Exit
;
2512 SID
:= M
.ReadLongWord();
2513 SPlaying
:= M
.ReadByte() <> 0;
2514 SPos
:= M
.ReadLongWord();
2515 SCount
:= M
.ReadLongInt();
2517 for I
:= Low(gTriggers
) to High(gTriggers
) do
2518 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2519 if gTriggers
[I
].ClientID
= SID
then
2520 with gTriggers
[I
] do
2522 if Sound
<> nil then
2527 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2529 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2530 Sound
.SetPosition(SPos
);
2533 if Sound
.IsPlaying
then Sound
.Stop
;
2536 SoundPlayCount
:= SCount
;
2540 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2547 if not gGameOn
then Exit
;
2549 MName
:= M
.ReadString();
2550 MPlaying
:= M
.ReadByte() <> 0;
2551 MPos
:= M
.ReadLongWord();
2552 MPaused
:= M
.ReadByte() <> 0;
2556 gMusic
.SetByName(MName
);
2558 gMusic
.SetPosition(MPos
);
2559 gMusic
.SpecPause
:= MPaused
;
2562 if gMusic
.IsPlaying
then gMusic
.Stop
;
2567 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2570 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2571 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2576 Mon
:= g_Monsters_ByUID(ID
);
2580 MType
:= M
.ReadByte();
2581 MState
:= M
.ReadByte();
2582 MAnim
:= M
.ReadByte();
2583 MTarg
:= M
.ReadWord();
2584 MTargTime
:= M
.ReadLongInt();
2585 MBehav
:= M
.ReadByte();
2586 MSleep
:= M
.ReadLongInt();
2587 MHealth
:= M
.ReadLongInt();
2588 MAmmo
:= M
.ReadLongInt();
2590 X
:= M
.ReadLongInt();
2591 Y
:= M
.ReadLongInt();
2592 VX
:= M
.ReadLongInt();
2593 VY
:= M
.ReadLongInt();
2594 MDir
:= M
.ReadByte();
2596 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2597 Mon
:= g_Monsters_ByUID(ID
);
2604 MonsterAnim
:= MAnim
;
2605 MonsterTargetUID
:= MTarg
;
2606 MonsterTargetTime
:= MTargTime
;
2607 MonsterBehaviour
:= MBehav
;
2608 MonsterSleep
:= MSleep
;
2609 MonsterAmmo
:= MAmmo
;
2614 setPosition(X
, Y
); // this will call positionChanged();
2620 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2627 Mon
:= g_Monsters_ByUID(ID
);
2633 X
:= M
.ReadLongInt();
2634 Y
:= M
.ReadLongInt();
2635 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2636 GameVelX
:= M
.ReadLongInt();
2637 GameVelY
:= M
.ReadLongInt();
2638 GameDirection
:= TDirection(M
.ReadByte());
2642 procedure MC_RECV_MonsterState(var M
: TMsg
);
2645 MState
, MFAnm
: Byte;
2647 AnimRevert
: Boolean;
2650 Mon
:= g_Monsters_ByUID(ID
);
2651 if Mon
= nil then Exit
;
2653 MState
:= M
.ReadByte();
2654 MFAnm
:= M
.ReadByte();
2658 MonsterTargetUID
:= M
.ReadWord();
2659 MonsterTargetTime
:= M
.ReadLongInt();
2660 MonsterSleep
:= M
.ReadLongInt();
2661 MonsterHealth
:= M
.ReadLongInt();
2662 MonsterAmmo
:= M
.ReadLongInt();
2663 MonsterPain
:= M
.ReadLongInt();
2664 AnimRevert
:= M
.ReadByte() <> 0;
2665 FFireTime
:= M
.ReadLongInt();
2666 RevertAnim(AnimRevert
);
2668 if MonsterState
<> MState
then
2670 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2671 if (MState
= MONSTATE_DIE
) then DieSound();
2672 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2673 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2674 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2676 SetState(MState
, MFAnm
);
2681 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2685 X
, Y
, VX
, VY
: Integer;
2689 Mon
:= g_Monsters_ByUID(ID
);
2690 if Mon
= nil then Exit
;
2692 X
:= M
.ReadLongInt();
2693 Y
:= M
.ReadLongInt();
2694 VX
:= M
.ReadLongInt();
2695 VY
:= M
.ReadLongInt();
2697 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2700 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2706 Mon
:= g_Monsters_ByUID(ID
);
2707 if Mon
= nil then Exit
;
2709 Mon
.MonsterRemoved
:= True;
2712 procedure MC_RECV_TimeSync(var M
: TMsg
);
2716 Time
:= M
.ReadLongWord();
2718 if gState
= STATE_INTERCUSTOM
then
2719 gServInterTime
:= Min(Time
, 255);
2722 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2726 Int1
, Int2
: SmallInt;
2728 EvID
:= M
.ReadByte();
2729 Int1
:= M
.ReadSmallInt();
2730 Int2
:= M
.ReadSmallInt();
2731 Str1
:= M
.ReadString();
2732 Str2
:= M
.ReadString();
2736 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2738 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2740 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2742 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2744 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2750 procedure MC_SEND_Info(Password
: string);
2754 NetOut
.Write(Byte(NET_MSG_INFO
));
2755 NetOut
.Write(GAME_VERSION
);
2756 NetOut
.Write(Password
);
2757 NetOut
.Write(gPlayer1Settings
.Name
);
2758 NetOut
.Write(gPlayer1Settings
.Model
);
2759 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2760 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2761 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2762 NetOut
.Write(gPlayer1Settings
.Team
);
2764 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2767 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2769 NetOut
.Write(Byte(NET_MSG_CHAT
));
2773 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2776 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
2778 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
2779 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
2783 procedure MC_SEND_PlayerPos();
2788 //WeaponSelect: Word = 0;
2791 if not gGameOn
then Exit
;
2792 if gPlayers
= nil then Exit
;
2793 if gPlayer1
= nil then Exit
;
2796 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2798 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2800 strafeDir
:= P1MoveButton
shr 4;
2801 P1MoveButton
:= P1MoveButton
and $0F;
2802 with gGameControls
.P1Control
do
2804 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 1
2805 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then P1MoveButton
:= 2
2806 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 0;
2809 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
2811 // new strafe mechanics
2812 if (strafeDir
= 0) then strafeDir
:= P1MoveButton
; // start strafing
2813 // now set direction according to strafe (reversed)
2814 if (strafeDir
= 2) then gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2815 else if (strafeDir
= 1) then gPlayer1
.SetDirection(TDirection
.D_RIGHT
);
2819 if (P1MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2820 else if (P1MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2821 else if P1MoveButton
<> 0 then gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2824 gPlayer1
.ReleaseKeys
;
2825 gPlayer1
.weaponSwitchKeysStateChange(-1, isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
));
2826 gPlayer1
.weaponSwitchKeysStateChange(-2, isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
));
2828 if P1MoveButton
= 1 then
2830 kByte
:= kByte
or NET_KEY_LEFT
;
2831 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2833 if P1MoveButton
= 2 then
2835 kByte
:= kByte
or NET_KEY_RIGHT
;
2836 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2838 if isKeyPressed(KeyUp
, KeyUp2
) then
2840 kByte
:= kByte
or NET_KEY_UP
;
2841 gPlayer1
.PressKey(KEY_UP
, 10000);
2843 if isKeyPressed(KeyDown
, KeyDown2
) then
2845 kByte
:= kByte
or NET_KEY_DOWN
;
2846 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2848 if isKeyPressed(KeyJump
, KeyJump2
) then
2850 kByte
:= kByte
or NET_KEY_JUMP
;
2851 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2853 if isKeyPressed(KeyFire
, KeyFire2
) then kByte
:= kByte
or NET_KEY_FIRE
;
2854 if isKeyPressed(KeyOpen
, KeyOpen2
) then kByte
:= kByte
or NET_KEY_OPEN
;
2855 // do not send weapon switch keys, `MH_SEND_PlayerStats()` will send changed weapon anyway
2856 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) and gPlayer1
.isWeaponSwitchKeyReleased(-1) then gPlayer1
.PressKey(KEY_NEXTWEAPON
); //kByte := kByte or NET_KEY_NW;
2857 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) and gPlayer1
.isWeaponSwitchKeyReleased(-2) then gPlayer1
.PressKey(KEY_PREVWEAPON
); //kByte := kByte or NET_KEY_PW;
2858 for I
:= 0 to High(KeyWeapon
) do
2860 if isKeyPressed(KeyWeapon
[I
], KeyWeapon2
[I
]) then
2862 //writeln('keyweapon #', i, ' is pressed; released=', Integer(gPlayer1.isWeaponSwitchKeyReleased(i)), '; frm=', gPlayer1.NetForceWeapFIdx, '; gTime=', gTime);
2863 gPlayer1
.weaponSwitchKeysStateChange(i
, true);
2864 if gPlayer1
.isWeaponSwitchKeyReleased(i
) then
2866 //writeln('keyweapon #', i, ' is pressed; released=', Integer(gPlayer1.isWeaponSwitchKeyReleased(i)), '; frm=', gPlayer1.NetForceWeapFIdx, '; gTime=', gTime);
2867 gPlayer1
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
2868 //WeaponSelect := WeaponSelect or Word(1 shl I);
2873 gPlayer1
.weaponSwitchKeysStateChange(i
, false);
2877 // fix movebutton state
2878 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2881 kByte
:= NET_KEY_CHAT
;
2883 gPlayer1
.weaponSwitchKeysShiftNewStates();
2885 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2886 NetOut
.Write(gTime
);
2887 NetOut
.Write(kByte
);
2888 NetOut
.Write(Byte(gPlayer1
.Direction
));
2889 NetOut
.Write(LongWord(gPlayer1
.NetWeapCtr
));
2890 NetOut
.Write(Byte(gPlayer1
.CurrWeap
));
2891 {$IFDEF K8_XXX_WEAPON_DEBUG}
2892 if (kByte
and NET_KEY_FIRE
) <> 0 then writeln('FIRE: CurrWeap=', gPlayer1
.CurrWeap
);
2894 //e_WriteLog(Format('S:nwp=%d; nwfidx=%d', [Integer(gPlayer1.NetForceWeap), Integer(gPlayer1.NetForceWeapFIdx)]), TMsgType.Warning);
2895 //NetOut.Write(WeaponSelect);
2896 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2897 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2899 //kBytePrev := kByte;
2900 //kDirPrev := gPlayer1.Direction;
2903 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2905 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2906 NetOut
.Write(Byte(Start
));
2907 NetOut
.Write(Command
);
2908 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2911 procedure MC_SEND_PlayerSettings();
2913 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2914 NetOut
.Write(gPlayer1Settings
.Name
);
2915 NetOut
.Write(gPlayer1Settings
.Model
);
2916 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2917 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2918 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2919 NetOut
.Write(gPlayer1Settings
.Team
);
2921 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2924 procedure MC_SEND_FullStateRequest();
2926 NetOut
.Write(Byte(NET_MSG_REQFST
));
2928 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2931 procedure MC_SEND_CheatRequest(Kind
: Byte);
2933 NetOut
.Write(Byte(NET_MSG_CHEAT
));
2936 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2938 procedure MC_SEND_RCONPassword(Password
: string);
2940 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
2941 NetOut
.Write(Password
);
2943 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2945 procedure MC_SEND_RCONCommand(Cmd
: string);
2947 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
2950 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2953 // i have no idea why all this stuff is in here
2955 function ReadFile(const FileName
: TFileName
): AByte
;
2957 FileStream
: TStream
;
2960 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), TMsgType
.Notify
);
2961 fname
:= findDiskWad(FileName
);
2962 if length(fname
) = 0 then
2964 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), TMsgType
.Fatal
);
2965 SetLength(Result
, 0);
2968 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), TMsgType
.Notify
);
2970 FileStream
:= openDiskFileRO(fname
);
2972 if FileStream
.Size
> 0 then
2974 SetLength(Result
, FileStream
.Size
);
2975 FileStream
.Read(Result
[0], FileStream
.Size
);
2982 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
2986 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
2987 Result
.FileData
:= ReadFile(FileName
);
2988 Result
.FileSize
:= Length(Result
.FileData
);
2990 SetLength(Result
.ExternalResources
, ResList
.Count
);
2991 for i
:=0 to ResList
.Count
-1 do
2993 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
2994 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
2998 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
3000 ResultStream
: TMemoryStream
;
3002 ResultStream
:= TMemoryStream
.Create
;
3004 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
3005 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
3006 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
3008 SetLength(bytes
, ResultStream
.Size
);
3009 ResultStream
.Seek(0, soFromBeginning
);
3010 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3015 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
3017 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3018 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
3019 SetLength(Result
.FileData
, Result
.FileSize
);
3020 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
3023 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
3025 ResultStream
: TMemoryStream
;
3028 resCount
:= Length(MapDataMsg
.ExternalResources
);
3030 ResultStream
:= TMemoryStream
.Create
;
3032 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
3033 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
3034 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
3036 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
3037 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
3039 SetLength(bytes
, ResultStream
.Size
);
3040 ResultStream
.Seek(0, soFromBeginning
);
3041 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3046 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
3050 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3051 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3053 SetLength(Result
.FileData
, Result
.FileSize
);
3054 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3056 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3057 SetLength(Result
.ExternalResources
, resCount
);
3059 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3062 function IsValidFileName(const S
: String): Boolean;
3064 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3069 for I
:= 1 to Length(S
) do
3070 Result
:= Result
and (not(S
[I
] in Forbidden
));
3073 function IsValidFilePath(const S
: String): Boolean;
3078 if not IsValidFileName(S
) then exit
;
3079 if FileExists(S
) then exit
;
3080 I
:= LastDelimiter('\/', S
);
3082 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3087 procedure MC_SEND_MapRequest();
3089 NetOut
.Write(Byte(NET_MSG_MAP_REQUEST
));
3090 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3093 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3095 NetOut
.Write(Byte(NET_MSG_RES_REQUEST
));
3096 NetOut
.Write(resName
);
3097 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3100 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
3104 mapDataMsg
: TMapDataMsg
;
3106 e_WriteLog('NET: Received map request from ' +
3107 DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3109 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3110 peer
:= NetClients
[C
^.ID
].Peer
;
3112 MapDataMsgToBytes(payload
, mapDataMsg
);
3113 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3116 mapDataMsg
.FileData
:= nil;
3117 mapDataMsg
.ExternalResources
:= nil;
3120 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
3125 resDataMsg
: TResDataMsg
;
3127 FileName
:= ExtractFileName(M
.ReadString());
3128 e_WriteLog('NET: Received res request: ' + FileName
+
3129 ' from ' + DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3131 if not IsValidFilePath(FileName
) then
3133 e_WriteLog('Invalid filename: ' + FileName
, TMsgType
.Warning
);
3137 peer
:= NetClients
[C
^.ID
].Peer
;
3139 if gExternalResources
.IndexOf(FileName
) > -1 then
3141 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3142 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3143 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3145 ResDataMsgToBytes(payload
, resDataMsg
);
3146 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);