e9cc68c2ee55ac7fcb0067073ed725ecdedd6e9e
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 //WeaponSelect := M.ReadWord();
460 newweapon
:= M
.ReadByte();
461 if (newweapon
<> CurrWeap
) then
463 {$IFDEF K8_XXX_WEAPON_DEBUG}
464 writeln('HOST PLRPOS: got: currweap=', CurrWeap
, '; curfrm=', gTime
, '; netweap=', newweapon
, '; oldweap=', CurrWeap
);
466 //NetForceWeap := newweapon;
467 SetWeaponHost(newweapon
);
469 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
470 if Direction
<> TDirection(Dir
) then
471 JustTeleported
:= False;
473 SetDirection(TDirection(Dir
));
474 ReleaseKeysNoWeapon();
476 if kByte
= NET_KEY_CHAT
then
478 PressKey(KEY_CHAT
, 10000);
482 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
483 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
484 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
485 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
486 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
487 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
488 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
489 //if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
490 //if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
495 if (WeaponSelect and Word(1 shl i)) <> 0 then
497 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
498 QueueWeaponSwitch(i);
504 // MH_SEND_PlayerPos(False, PID, C^.ID);
507 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
512 Pl
:= g_Player_Get(C
^.Player
);
513 if Pl
= nil then Exit
;
515 CheatKind
:= M
.ReadByte();
519 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
522 if Pl
.FSpectator
then
530 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
538 TmpName
:= M
.ReadString();
539 TmpModel
:= M
.ReadString();
540 TmpColor
.R
:= M
.ReadByte();
541 TmpColor
.G
:= M
.ReadByte();
542 TmpColor
.B
:= M
.ReadByte();
543 TmpTeam
:= M
.ReadByte();
545 Pl
:= g_Player_Get(C
^.Player
);
546 if Pl
= nil then Exit
;
548 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
551 Pl
.SetColor(TmpColor
);
553 if Pl
.Name
<> TmpName
then
555 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
559 if TmpModel
<> Pl
.Model
.Name
then
560 Pl
.SetModel(TmpModel
);
562 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
567 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
571 Pwd
:= M
.ReadString();
572 if not NetAllowRCON
then Exit
;
573 if Pwd
= NetRCONPassword
then
576 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
579 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
582 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
586 Cmd
:= M
.ReadString();
587 if not NetAllowRCON
then Exit
;
588 if not C
^.RCONAuth
then
590 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
593 g_Console_Process(Cmd
);
598 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
601 Name
, Command
: string;
605 Start
:= M
.ReadByte() <> 0;
606 Command
:= M
.ReadString();
608 Pl
:= g_Player_Get(C
^.Player
);
609 if Pl
= nil then Exit
;
614 if not g_Console_CommandBlacklisted(Command
) then
615 g_Game_StartVote(Command
, Name
);
617 else if gVoteInProgress
then
619 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
620 Need
:= Floor((NetClientCount
+1)/2.0) + 1
622 Need
:= Floor(NetClientCount
/2.0) + 1;
627 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
628 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
634 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
635 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
643 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
645 function sendItemRespawn (it
: PItem
): Boolean;
647 result
:= false; // don't stop
648 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
651 function sendMonSpawn (mon
: TMonster
): Boolean;
653 result
:= false; // don't stop
654 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
657 function sendPanelState (pan
: TPanel
): Boolean;
659 result
:= false; // don't stop
660 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
661 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
667 if gPlayers
<> nil then
669 for I
:= Low(gPlayers
) to High(gPlayers
) do
671 if gPlayers
[I
] <> nil then
673 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
674 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
675 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
677 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
679 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
685 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
686 g_Mons_ForEach(sendMonSpawn
);
687 g_Map_ForEachPanel(sendPanelState
);
689 if gTriggers
<> nil then
691 for I
:= Low(gTriggers
) to High(gTriggers
) do
693 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
695 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
702 for I
:= Low(Shots
) to High(Shots
) do
704 if Shots
[i
].ShotType
in [6, 7, 8] then
706 MH_SEND_CreateShot(i
, ID
);
711 MH_SEND_TriggerMusic(ID
);
713 MH_SEND_GameStats(ID
);
714 MH_SEND_CoopStats(ID
);
716 if gGameSettings
.GameMode
= GM_CTF
then
718 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
719 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
722 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
724 if gLMSRespawn
> LMS_RESPAWN_NONE
then
726 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
730 procedure MH_SEND_Info(ID
: Byte);
734 Map
:= g_ExtractFileName(gMapInfo
.Map
);
738 NetOut
.Write(Byte(NET_MSG_INFO
));
740 NetOut
.Write(NetClients
[ID
].Player
);
741 NetOut
.Write(gGameSettings
.WAD
);
743 NetOut
.Write(gWADHash
);
744 NetOut
.Write(gGameSettings
.GameMode
);
745 NetOut
.Write(gGameSettings
.GoalLimit
);
746 NetOut
.Write(gGameSettings
.TimeLimit
);
747 NetOut
.Write(gGameSettings
.MaxLives
);
748 NetOut
.Write(gGameSettings
.Options
);
751 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
754 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
760 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
761 Mode
:= NET_CHAT_PLAYER
;
764 if (Mode
= NET_CHAT_TEAM
) then
766 for i
:= Low(gPlayers
) to High(gPlayers
) do
767 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
768 (gPlayers
[i
].Team
= ID
) then
770 NetOut
.Write(Byte(NET_MSG_CHAT
));
773 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
780 NetOut
.Write(Byte(NET_MSG_CHAT
));
783 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
786 if Mode
= NET_CHAT_SYSTEM
then
789 if ID
= NET_EVERYONE
then
791 if Mode
= NET_CHAT_PLAYER
then
793 g_Console_Add(Txt
, True);
794 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
795 g_Game_ChatSound(b_Text_Unformat(Txt
));
798 if Mode
= NET_CHAT_TEAM
then
799 if gPlayer1
<> nil then
801 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
803 g_Console_Add(#18'[Team] '#2 + Txt
, True);
804 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
805 g_Game_ChatSound(b_Text_Unformat(Txt
));
807 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
809 g_Console_Add(#20'[Team] '#2 + Txt
, True);
810 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
811 g_Game_ChatSound(b_Text_Unformat(Txt
));
817 Name
:= g_Net_ClientName_ByID(ID
);
818 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
819 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
820 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
824 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
826 NetOut
.Write(Byte(NET_MSG_GFX
));
832 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
835 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
837 NetOut
.Write(Byte(NET_MSG_SND
));
841 NetOut
.Write(Byte(1));
846 NetOut
.Write(Byte(0));
848 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
851 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
853 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
855 NetOut
.Write(Byte(NET_MSG_SHADD
));
857 NetOut
.Write(Shots
[Proj
].ShotType
);
858 NetOut
.Write(Shots
[Proj
].Target
);
859 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
860 NetOut
.Write(Shots
[Proj
].Timeout
);
861 NetOut
.Write(Shots
[Proj
].Obj
.X
);
862 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
863 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
864 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
866 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
869 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
871 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
873 NetOut
.Write(Byte(NET_MSG_SHPOS
));
875 NetOut
.Write(Shots
[Proj
].Obj
.X
);
876 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
877 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
878 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
880 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
883 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
885 NetOut
.Write(Byte(NET_MSG_SHDEL
));
887 NetOut
.Write(Byte(Loud
));
891 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
894 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
896 NetOut
.Write(Byte(NET_MSG_SCORE
));
897 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
899 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
900 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
903 if gGameSettings
.GameMode
= GM_COOP
then
905 NetOut
.Write(gCoopMonstersKilled
);
906 NetOut
.Write(gCoopSecretsFound
);
909 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
912 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
914 NetOut
.Write(Byte(NET_MSG_COOP
));
915 NetOut
.Write(gTotalMonsters
);
916 NetOut
.Write(gSecretsCount
);
917 NetOut
.Write(gCoopTotalMonstersKilled
);
918 NetOut
.Write(gCoopTotalSecretsFound
);
919 NetOut
.Write(gCoopTotalMonsters
);
920 NetOut
.Write(gCoopTotalSecrets
);
923 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
925 NetOut
.Write(Byte(NET_MSG_GEVENT
));
926 NetOut
.Write(EvType
);
929 NetOut
.Write(Byte(gLastMap
));
931 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
933 NetOut
.Write(Byte(1));
934 NetOut
.Write(gWADHash
);
936 NetOut
.Write(Byte(0));
938 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
941 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
943 NetOut
.Write(Byte(NET_MSG_FLAG
));
944 NetOut
.Write(EvType
);
946 NetOut
.Write(Byte(Quiet
));
948 NetOut
.Write(gFlags
[Flag
].State
);
949 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
950 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
951 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
952 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
953 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
955 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
958 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
960 NetOut
.Write(Byte(NET_MSG_GSET
));
961 NetOut
.Write(gGameSettings
.GameMode
);
962 NetOut
.Write(gGameSettings
.GoalLimit
);
963 NetOut
.Write(gGameSettings
.TimeLimit
);
964 NetOut
.Write(gGameSettings
.MaxLives
);
965 NetOut
.Write(gGameSettings
.Options
);
967 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
972 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
976 P
:= g_Player_Get(PID
);
977 if P
= nil then Exit
;
979 NetOut
.Write(Byte(NET_MSG_PLR
));
981 NetOut
.Write(P
.Name
);
983 NetOut
.Write(P
.FActualModelName
);
984 NetOut
.Write(P
.FColor
.R
);
985 NetOut
.Write(P
.FColor
.G
);
986 NetOut
.Write(P
.FColor
.B
);
987 NetOut
.Write(P
.Team
);
989 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
992 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
997 Pl
:= g_Player_Get(PID
);
998 if Pl
= nil then Exit
;
999 if Pl
.FDummy
then Exit
;
1001 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1002 NetOut
.Write(gTime
);
1009 NetOut
.Write(FPing
);
1010 NetOut
.Write(FLoss
);
1011 if IsKeyPressed(KEY_CHAT
) then
1012 kByte
:= NET_KEY_CHAT
1015 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1016 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1017 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1018 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1019 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1020 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1023 NetOut
.Write(kByte
);
1024 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1025 NetOut
.Write(GameX
);
1026 NetOut
.Write(GameY
);
1027 NetOut
.Write(GameVelX
);
1028 NetOut
.Write(GameVelY
);
1029 NetOut
.Write(GameAccelX
);
1030 NetOut
.Write(GameAccelY
);
1033 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1036 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1042 P
:= g_Player_Get(PID
);
1043 if P
= nil then Exit
;
1045 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1050 NetOut
.Write(Byte(alive
));
1051 NetOut
.Write(Byte(GodMode
));
1052 NetOut
.Write(Health
);
1053 NetOut
.Write(Armor
);
1055 NetOut
.Write(JetFuel
);
1056 NetOut
.Write(Lives
);
1059 // collect all weapons in one word
1061 for I
:= WP_FIRST
to WP_LAST
do if (FWeapon
[I
]) then ww
:= ww
or (1 shl (i
-WP_FIRST
));
1062 NetOut
.Write(Word(ww
));
1064 for I
:= A_BULLETS
to A_HIGH
do
1065 NetOut
.Write(FAmmo
[I
]);
1067 for I
:= A_BULLETS
to A_HIGH
do
1068 NetOut
.Write(FMaxAmmo
[I
]);
1070 for I
:= MR_SUIT
to MR_MAX
do
1071 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1073 // collect all special flags in one byte
1075 if (R_ITEM_BACKPACK
in FRulez
) then ww
:= ww
or $01;
1076 if (R_KEY_RED
in FRulez
) then ww
:= ww
or $02;
1077 if (R_KEY_GREEN
in FRulez
) then ww
:= ww
or $04;
1078 if (R_KEY_BLUE
in FRulez
) then ww
:= ww
or $08;
1079 if (R_BERSERK
in FRulez
) then ww
:= ww
or $10;
1080 NetOut
.Write(Byte(ww
));
1082 NetOut
.Write(Frags
);
1083 NetOut
.Write(Death
);
1085 //NetOut.Write(CurrWeap);
1086 NetOut
.Write(Byte(CurrWeap
));
1090 if (FSpectator
) then ww
:= ww
or $01;
1091 if (FGhost
) then ww
:= ww
or $02;
1092 if (FPhysics
) then ww
:= ww
or $04;
1093 if (FNoRespawn
) then ww
:= ww
or $08;
1094 if (FJetpack
) then ww
:= ww
or $10;
1095 NetOut
.Write(Byte(ww
));
1097 NetOut
.Write(FFireTime
);
1100 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1103 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1105 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1108 NetOut
.Write(Attacker
);
1109 NetOut
.Write(Value
);
1113 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1116 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1118 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1120 NetOut
.Write(KillType
);
1121 NetOut
.Write(DeathType
);
1122 NetOut
.Write(Attacker
);
1124 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1127 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1129 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1131 NetOut
.Write(Weapon
);
1136 NetOut
.Write(ShotID
);
1138 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1141 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1143 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1146 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1149 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1153 Pl
:= g_Player_Get(PID
);
1154 if Pl
= nil then Exit
;
1156 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1158 NetOut
.Write(Pl
.Name
);
1160 NetOut
.Write(Pl
.Model
.Name
)
1163 NetOut
.Write(Pl
.FColor
.R
);
1164 NetOut
.Write(Pl
.FColor
.G
);
1165 NetOut
.Write(Pl
.FColor
.B
);
1166 NetOut
.Write(Pl
.Team
);
1168 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1173 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1178 it
:= g_Items_ByIdx(IID
);
1180 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1182 NetOut
.Write(Byte(Quiet
));
1184 if it
.dropped
then tt
:= tt
or $80;
1186 NetOut
.Write(Byte(it
.Fall
));
1187 NetOut
.Write(Byte(it
.Respawnable
));
1188 NetOut
.Write(it
.Obj
.X
);
1189 NetOut
.Write(it
.Obj
.Y
);
1190 NetOut
.Write(it
.Obj
.Vel
.X
);
1191 NetOut
.Write(it
.Obj
.Vel
.Y
);
1193 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1196 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1198 NetOut
.Write(Byte(NET_MSG_IDEL
));
1200 NetOut
.Write(Byte(Quiet
));
1202 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1207 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1211 TP
:= g_Map_PanelByGUID(PGUID
);
1212 if (TP
= nil) then exit
;
1216 NetOut
.Write(Byte(NET_MSG_PTEX
));
1217 NetOut
.Write(LongWord(PGUID
));
1218 NetOut
.Write(FCurTexture
);
1219 NetOut
.Write(FCurFrame
);
1220 NetOut
.Write(FCurFrameCount
);
1221 NetOut
.Write(AnimLoop
);
1224 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1227 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1232 TP
:= g_Map_PanelByGUID(PGUID
);
1233 if (TP
= nil) then exit
;
1235 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1236 NetOut
.Write(LongWord(PGUID
));
1237 NetOut
.Write(Byte(TP
.Enabled
));
1238 NetOut
.Write(TP
.LiftType
);
1241 NetOut
.Write(Word(TP
.Width
));
1242 NetOut
.Write(Word(TP
.Height
));
1244 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1245 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1246 NetOut
.Write(LongInt(TP
.movingStartX
));
1247 NetOut
.Write(LongInt(TP
.movingStartY
));
1248 NetOut
.Write(LongInt(TP
.movingEndX
));
1249 NetOut
.Write(LongInt(TP
.movingEndY
));
1250 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1251 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1252 NetOut
.Write(LongInt(TP
.sizeEndX
));
1253 NetOut
.Write(LongInt(TP
.sizeEndY
));
1254 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1255 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1256 NetOut
.Write(Byte(mpflags
));
1258 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1263 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1265 if gTriggers
= nil then Exit
;
1266 if T
.Sound
= nil then Exit
;
1268 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1269 NetOut
.Write(T
.ClientID
);
1270 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1271 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1272 NetOut
.Write(T
.SoundPlayCount
);
1274 g_Net_Host_Send(ID
, True);
1277 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1279 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1280 NetOut
.Write(gMusic
.Name
);
1281 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1282 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1283 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1285 g_Net_Host_Send(ID
, True);
1290 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1294 M
:= g_Monsters_ByUID(UID
);
1300 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1302 NetOut
.Write(MonsterType
);
1303 NetOut
.Write(MonsterState
);
1304 NetOut
.Write(MonsterAnim
);
1305 NetOut
.Write(MonsterTargetUID
);
1306 NetOut
.Write(MonsterTargetTime
);
1307 NetOut
.Write(MonsterBehaviour
);
1308 NetOut
.Write(MonsterSleep
);
1309 NetOut
.Write(MonsterHealth
);
1310 NetOut
.Write(MonsterAmmo
);
1311 NetOut
.Write(GameX
);
1312 NetOut
.Write(GameY
);
1313 NetOut
.Write(GameVelX
);
1314 NetOut
.Write(GameVelY
);
1315 NetOut
.Write(Byte(GameDirection
));
1318 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1321 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1325 M
:= g_Monsters_ByUID(UID
);
1326 if M
= nil then Exit
;
1328 NetOut
.Write(Byte(NET_MSG_MPOS
));
1333 NetOut
.Write(GameX
);
1334 NetOut
.Write(GameY
);
1335 NetOut
.Write(GameVelX
);
1336 NetOut
.Write(GameVelY
);
1337 NetOut
.Write(Byte(GameDirection
));
1340 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1343 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1347 M
:= g_Monsters_ByUID(UID
);
1348 if M
= nil then Exit
;
1350 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1355 NetOut
.Write(MonsterState
);
1356 NetOut
.Write(ForcedAnim
);
1357 NetOut
.Write(MonsterTargetUID
);
1358 NetOut
.Write(MonsterTargetTime
);
1359 NetOut
.Write(MonsterSleep
);
1360 NetOut
.Write(MonsterHealth
);
1361 NetOut
.Write(MonsterAmmo
);
1362 NetOut
.Write(MonsterPain
);
1363 NetOut
.Write(Byte(AnimIsReverse
));
1364 NetOut
.Write(FFireTime
);
1367 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1370 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1372 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1379 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1382 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1386 M
:= g_Monsters_ByUID(UID
);
1387 if M
= nil then Exit
;
1389 NetOut
.Write(Byte(NET_MSG_MDEL
));
1392 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1397 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1399 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1402 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1405 procedure MH_SEND_VoteEvent(EvType
: Byte;
1406 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1407 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1408 ID
: Integer = NET_EVERYONE
);
1410 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1411 NetOut
.Write(EvType
);
1412 NetOut
.Write(IntArg1
);
1413 NetOut
.Write(IntArg2
);
1414 NetOut
.Write(StrArg1
);
1415 NetOut
.Write(StrArg2
);
1417 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1420 // CLIENT MESSAGES //
1424 procedure MC_RECV_Chat(var M
: TMsg
);
1429 Txt
:= M
.ReadString();
1430 Mode
:= M
.ReadByte();
1432 if Mode
<> NET_CHAT_SYSTEM
then
1434 if Mode
= NET_CHAT_PLAYER
then
1436 g_Console_Add(Txt
, True);
1437 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1438 g_Game_ChatSound(b_Text_Unformat(Txt
));
1440 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1442 if gPlayer1
.Team
= TEAM_RED
then
1443 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1444 if gPlayer1
.Team
= TEAM_BLUE
then
1445 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1446 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1447 g_Game_ChatSound(b_Text_Unformat(Txt
));
1450 g_Console_Add(Txt
, True);
1453 procedure MC_RECV_Effect(var M
: TMsg
);
1461 if not gGameOn
then Exit
;
1462 Kind
:= M
.ReadByte();
1463 X
:= M
.ReadLongInt();
1464 Y
:= M
.ReadLongInt();
1465 Ang
:= M
.ReadSmallInt();
1469 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1473 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1475 Anim
:= TAnimation
.Create(ID
, False, 3);
1476 g_GFX_OnceAnim(X
, Y
, Anim
);
1480 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1485 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1487 Anim
:= TAnimation
.Create(ID
, False, 6);
1488 Anim
.Blending
:= False;
1489 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1493 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1498 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1500 Anim
:= TAnimation
.Create(ID
, False, 6);
1501 Anim
.Blending
:= False;
1502 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1506 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1511 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1513 Anim
:= TAnimation
.Create(ID
, False, 4);
1514 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1521 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1523 Anim
:= TAnimation
.Create(ID
, False, 4);
1524 g_GFX_OnceAnim(X
, Y
, Anim
);
1528 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1533 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1535 Anim
:= TAnimation
.Create(ID
, False, 4);
1536 g_GFX_OnceAnim(X
, Y
, Anim
);
1540 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1544 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1547 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1551 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1552 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1557 procedure MC_RECV_Sound(var M
: TMsg
);
1563 Name
:= M
.ReadString();
1564 Pos
:= M
.ReadByte() <> 0;
1567 X
:= M
.ReadLongInt();
1568 Y
:= M
.ReadLongInt();
1569 g_Sound_PlayExAt(Name
, X
, Y
);
1572 g_Sound_PlayEx(Name
);
1575 procedure MC_RECV_CreateShot(var M
: TMsg
);
1577 I
, X
, Y
, XV
, YV
: Integer;
1579 Target
, Spawner
: Word;
1582 I
:= M
.ReadLongInt();
1583 ShType
:= M
.ReadByte();
1584 Target
:= M
.ReadWord();
1585 Spawner
:= M
.ReadWord();
1586 Timeout
:= M
.ReadLongWord();
1587 X
:= M
.ReadLongInt();
1588 Y
:= M
.ReadLongInt();
1589 XV
:= M
.ReadLongInt();
1590 YV
:= M
.ReadLongInt();
1592 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1593 if (Shots
<> nil) and (I
<= High(Shots
)) then
1595 Shots
[I
].Timeout
:= Timeout
;
1596 //Shots[I].Target := Target; // TODO: find a use for Target later
1600 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1602 I
, TX
, TY
, TXV
, TYV
: Integer;
1604 I
:= M
.ReadLongInt();
1605 TX
:= M
.ReadLongInt();
1606 TY
:= M
.ReadLongInt();
1607 TXV
:= M
.ReadLongInt();
1608 TYV
:= M
.ReadLongInt();
1610 if (Shots
<> nil) and (I
<= High(Shots
)) then
1620 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1625 if not gGameOn
then Exit
;
1626 I
:= M
.ReadLongInt();
1627 L
:= (M
.ReadByte() <> 0);
1628 X
:= M
.ReadLongInt();
1629 Y
:= M
.ReadLongInt();
1631 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1634 procedure MC_RECV_GameStats(var M
: TMsg
);
1636 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1638 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1639 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1642 if gGameSettings
.GameMode
= GM_COOP
then
1644 gCoopMonstersKilled
:= M
.ReadWord();
1645 gCoopSecretsFound
:= M
.ReadWord();
1649 procedure MC_RECV_CoopStats(var M
: TMsg
);
1651 gTotalMonsters
:= M
.ReadLongInt();
1652 gSecretsCount
:= M
.ReadLongInt();
1653 gCoopTotalMonstersKilled
:= M
.ReadWord();
1654 gCoopTotalSecretsFound
:= M
.ReadWord();
1655 gCoopTotalMonsters
:= M
.ReadWord();
1656 gCoopTotalSecrets
:= M
.ReadWord();
1659 procedure MC_RECV_GameEvent(var M
: TMsg
);
1668 i1
, i2
: TStrings_Locale
;
1672 FillChar(EvHash
, Sizeof(EvHash
), 0);
1673 EvType
:= M
.ReadByte();
1674 EvNum
:= M
.ReadLongInt();
1675 EvStr
:= M
.ReadString();
1676 gLastMap
:= M
.ReadByte() <> 0;
1677 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1678 gStatsPressed
:= True;
1679 EvTime
:= M
.ReadLongWord();
1680 BHash
:= M
.ReadByte() <> 0;
1682 EvHash
:= M
.ReadMD5();
1690 g_Game_ClearLoading();
1691 g_Game_StopAllSounds(True);
1693 gSwitchGameMode
:= Byte(EvNum
);
1694 gGameSettings
.GameMode
:= gSwitchGameMode
;
1697 if not g_Game_StartMap(EvStr
, True) then
1699 if not isWadPath(EvStr
) then
1700 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1702 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1706 MC_SEND_FullStateRequest
;
1711 gMissionFailed
:= EvNum
<> 0;
1712 gExit
:= EXIT_ENDLEVELCUSTOM
;
1719 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1721 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1723 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1729 if EvNum
= TEAM_RED
then
1730 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1731 if EvNum
= TEAM_BLUE
then
1732 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1736 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1739 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1742 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1744 NET_EV_LMS_SURVIVOR
:
1745 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1748 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1752 pl
:= g_Player_Get(EvNum
and $FFFF);
1757 cnt
:= (EvNum
shr 16) and $FF;
1758 if Pos('w', EvStr
) = 0 then
1761 if Pos('t', EvStr
) = 0 then
1764 if Pos('-', EvStr
) = 0 then
1766 if Pos('e', EvStr
) = 0 then
1767 i1
:= I_PLAYER_SCORE_ADD_OWN
1769 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1772 if Pos('e', EvStr
) = 0 then
1773 i1
:= I_PLAYER_SCORE_SUB_OWN
1775 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1778 if Pos('r', EvStr
) > 0 then
1779 i2
:= I_PLAYER_SCORE_TO_RED
1781 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1782 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1786 if Pos('-', EvStr
) = 0 then
1787 i1
:= I_PLAYER_SCORE_ADD_TEAM
1789 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1791 if Pos('r', EvStr
) > 0 then
1792 i2
:= I_PLAYER_SCORE_RED
1794 i2
:= I_PLAYER_SCORE_BLUE
;
1795 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1800 if Pos('e', EvStr
) = 0 then
1801 i1
:= I_PLAYER_SCORE_WIN_OWN
1803 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1805 if Pos('r', EvStr
) > 0 then
1806 i2
:= I_PLAYER_SCORE_TO_RED
1808 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1809 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1815 if EvNum
= TEAM_RED
then
1816 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1817 if EvNum
= TEAM_BLUE
then
1818 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1819 if EvNum
= -TEAM_RED
then
1820 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1821 if EvNum
= -TEAM_BLUE
then
1822 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1827 g_Player_RemoveAllCorpses
;
1828 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1832 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1836 if EvNum
= TEAM_RED
then
1837 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1838 if EvNum
= TEAM_BLUE
then
1839 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1843 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1846 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1849 g_Game_Announce_KillCombo(EvNum
);
1851 NET_EV_PLAYER_TOUCH
:
1853 pl
:= g_Player_Get(EvNum
);
1861 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1870 EvType
:= M
.ReadByte();
1873 if Fl
= FLAG_NONE
then Exit
;
1875 Quiet
:= (M
.ReadByte() <> 0);
1876 PID
:= M
.ReadWord();
1878 gFlags
[Fl
].State
:= M
.ReadByte();
1879 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1880 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1881 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1882 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1883 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1885 Pl
:= g_Player_Get(PID
);
1887 (EvType
<> FLAG_STATE_NORMAL
) and
1888 (EvType
<> FLAG_STATE_DROPPED
) and
1889 (EvType
<> FLAG_STATE_RETURNED
) then
1895 if Quiet
or (Pl
= nil) then Exit
;
1897 if Fl
= FLAG_RED
then
1898 s
:= _lc
[I_PLAYER_FLAG_RED
]
1900 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1902 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1905 FLAG_STATE_CAPTURED
:
1907 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1911 if Fl
= FLAG_RED
then
1912 s
:= _lc
[I_PLAYER_FLAG_RED
]
1914 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1916 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1917 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1922 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1924 if Quiet
or (Pl
= nil) then Exit
;
1926 if Fl
= FLAG_RED
then
1927 s
:= _lc
[I_PLAYER_FLAG_RED
]
1929 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1931 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1932 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1937 g_Map_ResetFlag(FLAG_RED
);
1938 g_Map_ResetFlag(FLAG_BLUE
);
1939 if Quiet
or (Pl
= nil) then Exit
;
1940 Pl
.SetFlag(FLAG_NONE
);
1942 if Fl
= FLAG_RED
then
1943 s
:= _lc
[I_PLAYER_FLAG_RED
]
1945 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1947 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1948 Insert('.', ts
, Length(ts
) + 1 - 3);
1949 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1950 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1953 FLAG_STATE_RETURNED
:
1955 g_Map_ResetFlag(Fl
);
1958 if Fl
= FLAG_RED
then
1959 s
:= _lc
[I_PLAYER_FLAG_RED
]
1961 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1963 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1968 procedure MC_RECV_GameSettings(var M
: TMsg
);
1970 gGameSettings
.GameMode
:= M
.ReadByte();
1971 gGameSettings
.GoalLimit
:= M
.ReadWord();
1972 gGameSettings
.TimeLimit
:= M
.ReadWord();
1973 gGameSettings
.MaxLives
:= M
.ReadByte();
1974 gGameSettings
.Options
:= M
.ReadLongWord();
1979 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
1982 PName
, Model
: string;
1987 PID
:= M
.ReadWord();
1988 Pl
:= g_Player_Get(PID
);
1990 PName
:= M
.ReadString();
1991 Model
:= M
.ReadString();
1992 Color
.R
:= M
.ReadByte();
1993 Color
.G
:= M
.ReadByte();
1994 Color
.B
:= M
.ReadByte();
1998 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2000 if (Pl
<> nil) then Exit
;
2001 DID
:= g_Player_Create(Model
, Color
, T
, False);
2002 with g_Player_Get(DID
) do
2011 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2012 gPlayer1
.UID
:= PID
;
2013 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2014 gPlayer1
.ChangeTeam(T
);
2016 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2017 gPlayer2
.UID
:= PID
;
2018 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2019 gPlayer2
.ChangeTeam(T
);
2023 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2024 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2028 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2035 TmpX
, TmpY
: Integer;
2039 GT
:= M
.ReadLongWord();
2040 if GT
< gTime
- NET_MAX_DIFFTIME
then
2046 if g_Game_IsClient
and (gPlayer1
<> nil) and (gPlayer1
.NetForceWeapFIdx
>= gTime
+15) then gPlayer1
.NetForceWeapFIdx
:= 0;
2047 if g_Game_IsClient
and (gPlayer2
<> nil) and (gPlayer2
.NetForceWeapFIdx
>= gTime
+15) then gPlayer2
.NetForceWeapFIdx
:= 0;
2049 PID
:= M
.ReadWord();
2050 Pl
:= g_Player_Get(PID
);
2052 if Pl
= nil then Exit
;
2058 FPing
:= M
.ReadWord();
2059 FLoss
:= M
.ReadByte();
2060 kByte
:= M
.ReadWord();
2061 Dir
:= M
.ReadByte();
2063 TmpX
:= M
.ReadLongInt();
2064 TmpY
:= M
.ReadLongInt();
2066 ReleaseKeysNoWeapon
;
2068 if (kByte
= NET_KEY_CHAT
) then
2069 PressKey(KEY_CHAT
, 10000)
2072 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2073 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2074 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2075 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2076 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2079 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2080 SetDirection(TDirection(Dir
));
2082 GameVelX
:= M
.ReadLongInt();
2083 GameVelY
:= M
.ReadLongInt();
2084 GameAccelX
:= M
.ReadLongInt();
2085 GameAccelY
:= M
.ReadLongInt();
2086 SetLerp(TmpX
, TmpY
);
2087 if NetForcePlayerUpdate
then Update();
2091 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2101 PID
:= M
.ReadWord();
2102 Pl
:= g_Player_Get(PID
);
2109 alive
:= (M
.ReadByte() <> 0);
2110 GodMode
:= (M
.ReadByte() <> 0);
2111 Health
:= M
.ReadLongInt();
2112 Armor
:= M
.ReadLongInt();
2113 Air
:= M
.ReadLongInt();
2114 JetFuel
:= M
.ReadLongInt();
2115 Lives
:= M
.ReadByte();
2116 NewTeam
:= M
.ReadByte();
2119 for I
:= WP_FIRST
to WP_LAST
do
2121 FWeapon
[I
] := ((ww
and $01) <> 0);
2125 for I
:= A_BULLETS
to A_HIGH
do
2126 FAmmo
[I
] := M
.ReadWord();
2128 for I
:= A_BULLETS
to A_HIGH
do
2129 FMaxAmmo
[I
] := M
.ReadWord();
2131 for I
:= MR_SUIT
to MR_MAX
do
2132 FMegaRulez
[I
] := M
.ReadLongWord();
2135 // unpack special flags
2137 if ((ww
and $01) <> 0) then FRulez
:= FRulez
+[R_ITEM_BACKPACK
];
2138 if ((ww
and $02) <> 0) then FRulez
:= FRulez
+[R_KEY_RED
];
2139 if ((ww
and $04) <> 0) then FRulez
:= FRulez
+[R_KEY_GREEN
];
2140 if ((ww
and $08) <> 0) then FRulez
:= FRulez
+[R_KEY_BLUE
];
2141 if ((ww
and $10) <> 0) then FRulez
:= FRulez
+[R_BERSERK
];
2143 Frags
:= M
.ReadLongInt();
2144 Death
:= M
.ReadLongInt();
2146 newweapon
:= M
.ReadByte();
2147 {$IFDEF K8_XXX_WEAPON_DEBUG}
2148 writeln('CLIENT PLRSTATS: got: currweap=', CurrWeap
, '; curfrm=', gTime
, '; netweap=', newweapon
, '; lastnwfrm=', NetForceWeapFIdx
);
2150 if (gTime
>= NetForceWeapFIdx
) then
2152 //NetForceWeap := newweapon;
2153 SetWeaponHost(newweapon
);
2155 //SetWeapon(M.ReadByte());
2160 FSpectator
:= ((ww
and $01) <> 0);
2163 if Pl
= gPlayer1
then
2168 if Pl
= gPlayer2
then
2176 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2177 gPlayer1
:= g_Player_Get(gLMSPID1
);
2178 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2179 gPlayer2
:= g_Player_Get(gLMSPID2
);
2182 FGhost
:= ((ww
and $02) <> 0);
2183 FPhysics
:= ((ww
and $04) <> 0);
2184 FNoRespawn
:= ((ww
and $08) <> 0);
2186 FJetpack
:= ((ww
and $10) <> 0);
2187 FFireTime
:= M
.ReadLongInt();
2188 if OldJet
and not FJetpack
then
2190 else if not OldJet
and FJetpack
then
2192 if Team
<> NewTeam
then
2193 Pl
.ChangeTeam(NewTeam
);
2199 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2204 Attacker
, Value
: Word;
2208 if not gGameOn
then Exit
;
2209 PID
:= M
.ReadWord();
2210 Pl
:= g_Player_Get(PID
);
2211 if Pl
= nil then Exit
;
2213 Kind
:= M
.ReadByte();
2214 Attacker
:= M
.ReadWord();
2215 Value
:= M
.ReadWord();
2220 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2225 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2229 KillType
, DeathType
: Byte;
2233 if not gGameOn
then Exit
;
2234 PID
:= M
.ReadWord();
2235 Pl
:= g_Player_Get(PID
);
2236 if Pl
= nil then Exit
;
2238 KillType
:= M
.ReadByte();
2239 DeathType
:= M
.ReadByte();
2240 Attacker
:= M
.ReadWord();
2244 Kill(KillType
, Attacker
, DeathType
);
2249 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2254 PID
:= M
.ReadWord();
2255 Pl
:= g_Player_Get(PID
);
2257 if Pl
= nil then Exit
;
2259 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2260 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2262 g_Player_Remove(PID
);
2267 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2272 X
, Y
, AX
, AY
: Integer;
2276 if not gGameOn
then Exit
;
2277 PID
:= M
.ReadWord();
2278 Pl
:= g_Player_Get(PID
);
2279 if Pl
= nil then Exit
;
2281 Weap
:= M
.ReadByte();
2282 X
:= M
.ReadLongInt();
2283 Y
:= M
.ReadLongInt();
2284 AX
:= M
.ReadLongInt();
2285 AY
:= M
.ReadLongInt();
2286 SHID
:= M
.ReadLongInt();
2289 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2292 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2301 PID
:= M
.ReadWord();
2302 Pl
:= g_Player_Get(PID
);
2303 if Pl
= nil then Exit
;
2305 TmpName
:= M
.ReadString();
2306 TmpModel
:= M
.ReadString();
2307 TmpColor
.R
:= M
.ReadByte();
2308 TmpColor
.G
:= M
.ReadByte();
2309 TmpColor
.B
:= M
.ReadByte();
2310 TmpTeam
:= M
.ReadByte();
2312 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2314 Pl
.ChangeTeam(TmpTeam
);
2315 if gPlayer1
= Pl
then
2316 gPlayer1Settings
.Team
:= TmpTeam
;
2317 if gPlayer2
= Pl
then
2318 gPlayer2Settings
.Team
:= TmpTeam
;
2320 Pl
.SetColor(TmpColor
);
2322 if Pl
.Name
<> TmpName
then
2324 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2328 if TmpModel
<> Pl
.Model
.Name
then
2329 Pl
.SetModel(TmpModel
);
2334 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2338 X
, Y
, VX
, VY
: Integer;
2340 Quiet
, Fall
{, Resp}: Boolean;
2344 if not gGameOn
then Exit
;
2346 Quiet
:= M
.ReadByte() <> 0;
2348 Fall
:= M
.ReadByte() <> 0;
2349 {Resp :=} M
.ReadByte();
2350 X
:= M
.ReadLongInt();
2351 Y
:= M
.ReadLongInt();
2352 VX
:= M
.ReadLongInt();
2353 VY
:= M
.ReadLongInt();
2355 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2356 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2358 it
:= g_Items_ByIdx(ID
);
2364 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2365 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2367 Anim
:= TAnimation
.Create(AID
, False, 4);
2368 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2374 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2379 if not gGameOn
then Exit
;
2381 Quiet
:= M
.ReadByte() <> 0;
2383 if not g_Items_ValidId(ID
) then exit
;
2385 if not Quiet
then g_Items_EmitPickupSound(ID
);
2392 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2399 if not gGameOn
then Exit
;
2401 PGUID
:= Integer(M
.ReadLongWord());
2402 Tex
:= M
.ReadLongInt();
2403 Fr
:= M
.ReadLongInt();
2404 Cnt
:= M
.ReadByte();
2405 Loop
:= M
.ReadByte();
2407 TP
:= g_Map_PanelByGUID(PGUID
);
2411 TP
.SetTexture(Tex
, Loop
);
2412 TP
.SetFrame(Fr
, Cnt
);
2416 procedure MC_RECV_PanelState(var M
: TMsg
);
2421 X
, Y
, W
, H
: Integer;
2423 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2424 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2427 if not gGameOn
then Exit
;
2429 PGUID
:= Integer(M
.ReadLongWord());
2430 E
:= (M
.ReadByte() <> 0);
2431 Lift
:= M
.ReadByte();
2432 X
:= M
.ReadLongInt();
2433 Y
:= M
.ReadLongInt();
2437 speedX
:= M
.ReadLongInt();
2438 speedY
:= M
.ReadLongInt();
2439 startX
:= M
.ReadLongInt();
2440 startY
:= M
.ReadLongInt();
2441 endX
:= M
.ReadLongInt();
2442 endY
:= M
.ReadLongInt();
2443 sizeSpX
:= M
.ReadLongInt();
2444 sizeSpY
:= M
.ReadLongInt();
2445 sizeEX
:= M
.ReadLongInt();
2446 sizeEY
:= M
.ReadLongInt();
2447 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2449 TP
:= g_Map_PanelByGUID(PGUID
);
2450 if (TP
= nil) then exit
;
2452 // update lifts state
2453 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2455 // update enabled/disabled state for all panels
2456 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2458 // update panel position, as it can be moved (mplat)
2463 // update mplat state
2464 TP
.movingSpeedX
:= speedX
;
2465 TP
.movingSpeedY
:= speedY
;
2466 TP
.movingStartX
:= startX
;
2467 TP
.movingStartY
:= startY
;
2468 TP
.movingEndX
:= endX
;
2469 TP
.movingEndY
:= endY
;
2470 TP
.sizeSpeedX
:= sizeSpX
;
2471 TP
.sizeSpeedY
:= sizeSpY
;
2472 TP
.sizeEndX
:= sizeEX
;
2473 TP
.sizeEndY
:= sizeEY
;
2474 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2475 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2476 // notify panel of it's position/size change, so it can fix other internal structures
2477 TP
.positionChanged();
2482 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2485 SPos
, SID
: LongWord;
2489 if not gGameOn
then Exit
;
2490 if gTriggers
= nil then Exit
;
2492 SID
:= M
.ReadLongWord();
2493 SPlaying
:= M
.ReadByte() <> 0;
2494 SPos
:= M
.ReadLongWord();
2495 SCount
:= M
.ReadLongInt();
2497 for I
:= Low(gTriggers
) to High(gTriggers
) do
2498 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2499 if gTriggers
[I
].ClientID
= SID
then
2500 with gTriggers
[I
] do
2502 if Sound
<> nil then
2507 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2509 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2510 Sound
.SetPosition(SPos
);
2513 if Sound
.IsPlaying
then Sound
.Stop
;
2516 SoundPlayCount
:= SCount
;
2520 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2527 if not gGameOn
then Exit
;
2529 MName
:= M
.ReadString();
2530 MPlaying
:= M
.ReadByte() <> 0;
2531 MPos
:= M
.ReadLongWord();
2532 MPaused
:= M
.ReadByte() <> 0;
2536 gMusic
.SetByName(MName
);
2538 gMusic
.SetPosition(MPos
);
2539 gMusic
.SpecPause
:= MPaused
;
2542 if gMusic
.IsPlaying
then gMusic
.Stop
;
2547 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2550 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2551 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2556 Mon
:= g_Monsters_ByUID(ID
);
2560 MType
:= M
.ReadByte();
2561 MState
:= M
.ReadByte();
2562 MAnim
:= M
.ReadByte();
2563 MTarg
:= M
.ReadWord();
2564 MTargTime
:= M
.ReadLongInt();
2565 MBehav
:= M
.ReadByte();
2566 MSleep
:= M
.ReadLongInt();
2567 MHealth
:= M
.ReadLongInt();
2568 MAmmo
:= M
.ReadLongInt();
2570 X
:= M
.ReadLongInt();
2571 Y
:= M
.ReadLongInt();
2572 VX
:= M
.ReadLongInt();
2573 VY
:= M
.ReadLongInt();
2574 MDir
:= M
.ReadByte();
2576 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2577 Mon
:= g_Monsters_ByUID(ID
);
2584 MonsterAnim
:= MAnim
;
2585 MonsterTargetUID
:= MTarg
;
2586 MonsterTargetTime
:= MTargTime
;
2587 MonsterBehaviour
:= MBehav
;
2588 MonsterSleep
:= MSleep
;
2589 MonsterAmmo
:= MAmmo
;
2594 setPosition(X
, Y
); // this will call positionChanged();
2600 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2607 Mon
:= g_Monsters_ByUID(ID
);
2613 X
:= M
.ReadLongInt();
2614 Y
:= M
.ReadLongInt();
2615 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2616 GameVelX
:= M
.ReadLongInt();
2617 GameVelY
:= M
.ReadLongInt();
2618 GameDirection
:= TDirection(M
.ReadByte());
2622 procedure MC_RECV_MonsterState(var M
: TMsg
);
2625 MState
, MFAnm
: Byte;
2627 AnimRevert
: Boolean;
2630 Mon
:= g_Monsters_ByUID(ID
);
2631 if Mon
= nil then Exit
;
2633 MState
:= M
.ReadByte();
2634 MFAnm
:= M
.ReadByte();
2638 MonsterTargetUID
:= M
.ReadWord();
2639 MonsterTargetTime
:= M
.ReadLongInt();
2640 MonsterSleep
:= M
.ReadLongInt();
2641 MonsterHealth
:= M
.ReadLongInt();
2642 MonsterAmmo
:= M
.ReadLongInt();
2643 MonsterPain
:= M
.ReadLongInt();
2644 AnimRevert
:= M
.ReadByte() <> 0;
2645 FFireTime
:= M
.ReadLongInt();
2646 RevertAnim(AnimRevert
);
2648 if MonsterState
<> MState
then
2650 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2651 if (MState
= MONSTATE_DIE
) then DieSound();
2652 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2653 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2654 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2656 SetState(MState
, MFAnm
);
2661 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2665 X
, Y
, VX
, VY
: Integer;
2669 Mon
:= g_Monsters_ByUID(ID
);
2670 if Mon
= nil then Exit
;
2672 X
:= M
.ReadLongInt();
2673 Y
:= M
.ReadLongInt();
2674 VX
:= M
.ReadLongInt();
2675 VY
:= M
.ReadLongInt();
2677 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2680 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2686 Mon
:= g_Monsters_ByUID(ID
);
2687 if Mon
= nil then Exit
;
2689 Mon
.MonsterRemoved
:= True;
2692 procedure MC_RECV_TimeSync(var M
: TMsg
);
2696 Time
:= M
.ReadLongWord();
2698 if gState
= STATE_INTERCUSTOM
then
2699 gServInterTime
:= Min(Time
, 255);
2702 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2706 Int1
, Int2
: SmallInt;
2708 EvID
:= M
.ReadByte();
2709 Int1
:= M
.ReadSmallInt();
2710 Int2
:= M
.ReadSmallInt();
2711 Str1
:= M
.ReadString();
2712 Str2
:= M
.ReadString();
2716 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2718 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2720 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2722 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2724 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2730 procedure MC_SEND_Info(Password
: string);
2734 NetOut
.Write(Byte(NET_MSG_INFO
));
2735 NetOut
.Write(GAME_VERSION
);
2736 NetOut
.Write(Password
);
2737 NetOut
.Write(gPlayer1Settings
.Name
);
2738 NetOut
.Write(gPlayer1Settings
.Model
);
2739 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2740 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2741 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2742 NetOut
.Write(gPlayer1Settings
.Team
);
2744 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2747 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2749 NetOut
.Write(Byte(NET_MSG_CHAT
));
2753 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2756 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
2758 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
2759 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
2763 procedure MC_SEND_PlayerPos();
2768 //WeaponSelect: Word = 0;
2771 if not gGameOn
then Exit
;
2772 if gPlayers
= nil then Exit
;
2773 if gPlayer1
= nil then Exit
;
2776 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2778 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2780 strafeDir
:= P1MoveButton
shr 4;
2781 P1MoveButton
:= P1MoveButton
and $0F;
2782 with gGameControls
.P1Control
do
2784 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 1
2785 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then P1MoveButton
:= 2
2786 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 0;
2789 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
2791 // new strafe mechanics
2792 if (strafeDir
= 0) then strafeDir
:= P1MoveButton
; // start strafing
2793 // now set direction according to strafe (reversed)
2794 if (strafeDir
= 2) then gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2795 else if (strafeDir
= 1) then gPlayer1
.SetDirection(TDirection
.D_RIGHT
);
2799 if (P1MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2800 else if (P1MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2801 else if P1MoveButton
<> 0 then gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2804 gPlayer1
.ReleaseKeys
;
2805 gPlayer1
.weaponSwitchKeysStateChange(-1, isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
));
2806 gPlayer1
.weaponSwitchKeysStateChange(-2, isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
));
2808 if P1MoveButton
= 1 then
2810 kByte
:= kByte
or NET_KEY_LEFT
;
2811 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2813 if P1MoveButton
= 2 then
2815 kByte
:= kByte
or NET_KEY_RIGHT
;
2816 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2818 if isKeyPressed(KeyUp
, KeyUp2
) then
2820 kByte
:= kByte
or NET_KEY_UP
;
2821 gPlayer1
.PressKey(KEY_UP
, 10000);
2823 if isKeyPressed(KeyDown
, KeyDown2
) then
2825 kByte
:= kByte
or NET_KEY_DOWN
;
2826 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2828 if isKeyPressed(KeyJump
, KeyJump2
) then
2830 kByte
:= kByte
or NET_KEY_JUMP
;
2831 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2833 if isKeyPressed(KeyFire
, KeyFire2
) then kByte
:= kByte
or NET_KEY_FIRE
;
2834 if isKeyPressed(KeyOpen
, KeyOpen2
) then kByte
:= kByte
or NET_KEY_OPEN
;
2835 // do not send weapon switch keys, `MH_SEND_PlayerStats()` will send changed weapon anyway
2836 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) and gPlayer1
.isWeaponSwitchKeyReleased(-1) then gPlayer1
.PressKey(KEY_NEXTWEAPON
); //kByte := kByte or NET_KEY_NW;
2837 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) and gPlayer1
.isWeaponSwitchKeyReleased(-2) then gPlayer1
.PressKey(KEY_PREVWEAPON
); //kByte := kByte or NET_KEY_PW;
2838 for I
:= 0 to High(KeyWeapon
) do
2840 if isKeyPressed(KeyWeapon
[I
], KeyWeapon2
[I
]) then
2842 //writeln('keyweapon #', i, ' is pressed; released=', Integer(gPlayer1.isWeaponSwitchKeyReleased(i)), '; frm=', gPlayer1.NetForceWeapFIdx, '; gTime=', gTime);
2843 gPlayer1
.weaponSwitchKeysStateChange(i
, true);
2844 if gPlayer1
.isWeaponSwitchKeyReleased(i
) then
2846 //writeln('keyweapon #', i, ' is pressed; released=', Integer(gPlayer1.isWeaponSwitchKeyReleased(i)), '; frm=', gPlayer1.NetForceWeapFIdx, '; gTime=', gTime);
2847 gPlayer1
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
2848 //WeaponSelect := WeaponSelect or Word(1 shl I);
2853 gPlayer1
.weaponSwitchKeysStateChange(i
, false);
2857 // fix movebutton state
2858 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2861 kByte
:= NET_KEY_CHAT
;
2863 gPlayer1
.weaponSwitchKeysShiftNewStates();
2865 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2866 NetOut
.Write(gTime
);
2867 NetOut
.Write(kByte
);
2868 NetOut
.Write(Byte(gPlayer1
.Direction
));
2869 NetOut
.Write(Byte(gPlayer1
.CurrWeap
));
2870 {$IFDEF K8_XXX_WEAPON_DEBUG}
2871 if (kByte
and NET_KEY_FIRE
) <> 0 then writeln('FIRE: CurrWeap=', gPlayer1
.CurrWeap
);
2873 //e_WriteLog(Format('S:nwp=%d; nwfidx=%d', [Integer(gPlayer1.NetForceWeap), Integer(gPlayer1.NetForceWeapFIdx)]), TMsgType.Warning);
2874 //NetOut.Write(WeaponSelect);
2875 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2876 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2878 // force player weapon
2879 //{if (gPlayer1.NetForceWeapFIdx < gTime) then} gPlayer1.SetWeapon(gPlayer1.NetForceWeap);
2881 //kBytePrev := kByte;
2882 //kDirPrev := gPlayer1.Direction;
2885 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2887 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2888 NetOut
.Write(Byte(Start
));
2889 NetOut
.Write(Command
);
2890 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2893 procedure MC_SEND_PlayerSettings();
2895 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2896 NetOut
.Write(gPlayer1Settings
.Name
);
2897 NetOut
.Write(gPlayer1Settings
.Model
);
2898 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2899 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2900 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2901 NetOut
.Write(gPlayer1Settings
.Team
);
2903 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2906 procedure MC_SEND_FullStateRequest();
2908 NetOut
.Write(Byte(NET_MSG_REQFST
));
2910 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2913 procedure MC_SEND_CheatRequest(Kind
: Byte);
2915 NetOut
.Write(Byte(NET_MSG_CHEAT
));
2918 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2920 procedure MC_SEND_RCONPassword(Password
: string);
2922 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
2923 NetOut
.Write(Password
);
2925 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2927 procedure MC_SEND_RCONCommand(Cmd
: string);
2929 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
2932 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2935 // i have no idea why all this stuff is in here
2937 function ReadFile(const FileName
: TFileName
): AByte
;
2939 FileStream
: TStream
;
2942 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), TMsgType
.Notify
);
2943 fname
:= findDiskWad(FileName
);
2944 if length(fname
) = 0 then
2946 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), TMsgType
.Fatal
);
2947 SetLength(Result
, 0);
2950 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), TMsgType
.Notify
);
2952 FileStream
:= openDiskFileRO(fname
);
2954 if FileStream
.Size
> 0 then
2956 SetLength(Result
, FileStream
.Size
);
2957 FileStream
.Read(Result
[0], FileStream
.Size
);
2964 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
2968 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
2969 Result
.FileData
:= ReadFile(FileName
);
2970 Result
.FileSize
:= Length(Result
.FileData
);
2972 SetLength(Result
.ExternalResources
, ResList
.Count
);
2973 for i
:=0 to ResList
.Count
-1 do
2975 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
2976 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
2980 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
2982 ResultStream
: TMemoryStream
;
2984 ResultStream
:= TMemoryStream
.Create
;
2986 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
2987 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
2988 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
2990 SetLength(bytes
, ResultStream
.Size
);
2991 ResultStream
.Seek(0, soFromBeginning
);
2992 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2997 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
2999 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3000 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
3001 SetLength(Result
.FileData
, Result
.FileSize
);
3002 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
3005 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
3007 ResultStream
: TMemoryStream
;
3010 resCount
:= Length(MapDataMsg
.ExternalResources
);
3012 ResultStream
:= TMemoryStream
.Create
;
3014 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
3015 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
3016 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
3018 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
3019 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
3021 SetLength(bytes
, ResultStream
.Size
);
3022 ResultStream
.Seek(0, soFromBeginning
);
3023 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3028 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
3032 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3033 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3035 SetLength(Result
.FileData
, Result
.FileSize
);
3036 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3038 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3039 SetLength(Result
.ExternalResources
, resCount
);
3041 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3044 function IsValidFileName(const S
: String): Boolean;
3046 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3051 for I
:= 1 to Length(S
) do
3052 Result
:= Result
and (not(S
[I
] in Forbidden
));
3055 function IsValidFilePath(const S
: String): Boolean;
3060 if not IsValidFileName(S
) then exit
;
3061 if FileExists(S
) then exit
;
3062 I
:= LastDelimiter('\/', S
);
3064 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3069 procedure MC_SEND_MapRequest();
3071 NetOut
.Write(Byte(NET_MSG_MAP_REQUEST
));
3072 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3075 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3077 NetOut
.Write(Byte(NET_MSG_RES_REQUEST
));
3078 NetOut
.Write(resName
);
3079 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3082 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
3086 mapDataMsg
: TMapDataMsg
;
3088 e_WriteLog('NET: Received map request from ' +
3089 DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3091 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3092 peer
:= NetClients
[C
^.ID
].Peer
;
3094 MapDataMsgToBytes(payload
, mapDataMsg
);
3095 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3098 mapDataMsg
.FileData
:= nil;
3099 mapDataMsg
.ExternalResources
:= nil;
3102 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
3107 resDataMsg
: TResDataMsg
;
3109 FileName
:= ExtractFileName(M
.ReadString());
3110 e_WriteLog('NET: Received res request: ' + FileName
+
3111 ' from ' + DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3113 if not IsValidFilePath(FileName
) then
3115 e_WriteLog('Invalid filename: ' + FileName
, TMsgType
.Warning
);
3119 peer
:= NetClients
[C
^.ID
].Peer
;
3121 if gExternalResources
.IndexOf(FileName
) > -1 then
3123 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3124 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3125 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3127 ResDataMsgToBytes(payload
, resDataMsg
);
3128 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);