33273f896a9ab3e339d1ca731a0a4ec53a129959
1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
21 uses g_net
, g_triggers
, Classes
, SysUtils
, md5
;
65 NET_MSG_RCON_AUTH
= 191;
66 NET_MSG_RCON_CMD
= 192;
67 NET_MSG_TIME_SYNC
= 194;
68 NET_MSG_VOTE_EVENT
= 195;
70 NET_MSG_MAP_REQUEST
= 201;
71 NET_MSG_MAP_RESPONSE
= 202;
72 NET_MSG_RES_REQUEST
= 203;
73 NET_MSG_RES_RESPONSE
= 204;
96 NET_EV_CHANGE_TEAM
= 3;
97 NET_EV_PLAYER_KICK
= 4;
98 NET_EV_PLAYER_BAN
= 5;
99 NET_EV_LMS_WARMUP
= 6;
100 NET_EV_LMS_SURVIVOR
= 7;
104 NET_EV_SCORE_MSG
= 11;
105 NET_EV_LMS_START
= 12;
107 NET_EV_TLMS_WIN
= 14;
108 NET_EV_LMS_LOSE
= 15;
109 NET_EV_LMS_DRAW
= 16;
110 NET_EV_KILLCOMBO
= 17;
111 NET_EV_PLAYER_TOUCH
= 18;
118 NET_VE_INPROGRESS
= 6;
125 NET_CHEAT_SUICIDE
= 1;
126 NET_CHEAT_SPECTATE
= 2;
128 NET_MAX_DIFFTIME
= 5000 div 36;
132 procedure MH_RECV_Info(C
: pTNetClient
; P
: Pointer);
133 procedure MH_RECV_Chat(C
: pTNetClient
; P
: Pointer);
134 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; P
: Pointer);
135 function MH_RECV_PlayerPos(C
: pTNetClient
; P
: Pointer): Word;
136 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; P
: Pointer);
137 procedure MH_RECV_CheatRequest(C
: pTNetClient
; P
: Pointer);
138 procedure MH_RECV_RCONPassword(C
: pTNetClient
; P
: Pointer);
139 procedure MH_RECV_RCONCommand(C
: pTNetClient
; P
: Pointer);
140 procedure MH_RECV_MapRequest(C
: pTNetClient
; P
: Pointer);
141 procedure MH_RECV_ResRequest(C
: pTNetClient
; P
: Pointer);
142 procedure MH_RECV_Vote(C
: pTNetClient
; P
: Pointer);
145 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
146 procedure MH_SEND_Info(ID
: Byte);
147 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
148 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
149 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
150 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
151 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
152 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
153 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
154 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PanelTexture(PType
: Word; PID
: LongWord; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PanelState(PType
: Word; PID
: LongWord; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_VoteEvent(EvType
: Byte;
185 StrArg1
: string = 'a'; StrArg2
: string = 'b';
186 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
187 ID
: Integer = NET_EVERYONE
);
189 // CLIENT MESSAGES //
192 procedure MC_RECV_Chat(P
: Pointer);
193 procedure MC_RECV_Effect(P
: Pointer);
194 procedure MC_RECV_Sound(P
: Pointer);
195 procedure MC_RECV_GameStats(P
: Pointer);
196 procedure MC_RECV_CoopStats(P
: Pointer);
197 procedure MC_RECV_GameEvent(P
: Pointer);
198 procedure MC_RECV_FlagEvent(P
: Pointer);
199 procedure MC_RECV_GameSettings(P
: Pointer);
201 function MC_RECV_PlayerCreate(P
: Pointer): Word;
202 function MC_RECV_PlayerPos(P
: Pointer): Word;
203 function MC_RECV_PlayerStats(P
: Pointer): Word;
204 function MC_RECV_PlayerDelete(P
: Pointer): Word;
205 function MC_RECV_PlayerDamage(P
: Pointer): Word;
206 function MC_RECV_PlayerDeath(P
: Pointer): Word;
207 function MC_RECV_PlayerFire(P
: Pointer): Word;
208 procedure MC_RECV_PlayerSettings(P
: Pointer);
210 procedure MC_RECV_ItemSpawn(P
: Pointer);
211 procedure MC_RECV_ItemDestroy(P
: Pointer);
213 procedure MC_RECV_PanelTexture(P
: Pointer);
214 procedure MC_RECV_PanelState(P
: Pointer);
216 procedure MC_RECV_MonsterSpawn(P
: Pointer);
217 procedure MC_RECV_MonsterPos(P
: Pointer);
218 procedure MC_RECV_MonsterState(P
: Pointer);
219 procedure MC_RECV_MonsterShot(P
: Pointer);
220 procedure MC_RECV_MonsterDelete(P
: Pointer);
222 procedure MC_RECV_CreateShot(P
: Pointer);
223 procedure MC_RECV_UpdateShot(P
: Pointer);
224 procedure MC_RECV_DeleteShot(P
: Pointer);
226 procedure MC_RECV_TriggerSound(P
: Pointer);
227 procedure MC_RECV_TriggerMusic(P
: Pointer);
229 procedure MC_RECV_TimeSync(P
: Pointer);
230 procedure MC_RECV_VoteEvent(P
: Pointer);
232 procedure MC_SEND_Info(Password
: string);
233 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
234 procedure MC_SEND_PlayerPos();
235 procedure MC_SEND_FullStateRequest();
236 procedure MC_SEND_PlayerSettings();
237 procedure MC_SEND_CheatRequest(Kind
: Byte);
238 procedure MC_SEND_RCONPassword(Password
: string);
239 procedure MC_SEND_RCONCommand(Cmd
: string);
240 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
242 procedure MC_SEND_MapRequest();
243 procedure MC_SEND_ResRequest(const resName
: AnsiString);
246 TExternalResourceInfo
= record
261 ExternalResources
: array of TExternalResourceInfo
;
264 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
265 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
270 Math
, ENet
, e_input
, e_fixedbuffer
, e_graphics
, e_log
,
271 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
272 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
273 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
286 NET_KEY_FORCEDIR
= 4096;
289 //kBytePrev: Word = 0;
290 //kDirPrev: TDirection = D_LEFT;
291 //HostGameTime: Word = 0;
298 procedure MH_RECV_Chat(C
: pTNetClient
; P
: Pointer);
306 Pl
:= g_Player_Get(PID
);
308 Txt
:= e_Raw_Read_String(P
);
309 Mode
:= e_Raw_Read_Byte(P
);
310 if (Mode
= NET_CHAT_SYSTEM
) then
311 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
312 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
313 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
316 MH_SEND_Chat(Txt
, Mode
)
318 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
321 procedure MH_RECV_Info(C
: pTNetClient
; P
: Pointer);
323 Ver
, PName
, Model
, Pw
: string;
329 Ver
:= e_Raw_Read_String(P
);
330 Pw
:= e_Raw_Read_String(P
);
331 PName
:= e_Raw_Read_String(P
);
332 Model
:= e_Raw_Read_String(P
);
333 R
:= e_Raw_Read_Byte(P
);
334 G
:= e_Raw_Read_Byte(P
);
335 B
:= e_Raw_Read_Byte(P
);
336 T
:= e_Raw_Read_Byte(P
);
338 if Ver
<> GAME_VERSION
then
340 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
341 _lc
[I_NET_DISC_VERSION
]);
342 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
346 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
348 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
350 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
351 _lc
[I_NET_DISC_BAN
]);
352 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
356 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
357 _lc
[I_NET_DISC_BAN
]);
358 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
363 if NetPassword
<> '' then
364 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
366 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
367 _lc
[I_NET_DISC_PASSWORD
]);
368 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
376 PID
:= g_Player_Create(Model
, Color
, T
, False);
377 with g_Player_Get(PID
) do
385 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
386 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
387 '] connected. Assigned player #' + IntToStr(PID
) + '.', MSG_NOTIFY
);
391 with g_Player_Get(PID
) do
395 // round in progress, don't spawn
396 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
401 FWantsInGame
:= True; // TODO: look into this later
404 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
407 for I
:= Low(NetClients
) to High(NetClients
) do
409 if NetClients
[I
].ID
= C
^.ID
then Continue
;
410 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
411 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
412 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
415 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
416 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
418 if NetUseMaster
then g_Net_Slist_Update
;
421 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; P
: Pointer);
424 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
426 C
^.RequestedFullUpdate
:= True;
431 function MH_RECV_PlayerPos(C
: pTNetClient
; P
: Pointer): Word;
441 if not gGameOn
then Exit
;
443 GT
:= e_Raw_Read_LongWord(P
);
445 Pl
:= g_Player_Get(PID
);
449 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
454 kByte
:= e_Raw_Read_Word(P
);
455 Dir
:= e_Raw_Read_Byte(P
);
456 WeaponSelect
:= e_Raw_Read_Word(P
);
457 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
458 if Direction
<> TDirection(Dir
) then
459 JustTeleported
:= False;
461 SetDirection(TDirection(Dir
));
464 if kByte
= NET_KEY_CHAT
then
466 PressKey(KEY_CHAT
, 10000);
470 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
471 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
472 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
473 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
474 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
475 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
476 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
477 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
478 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
482 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
484 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
485 QueueWeaponSwitch(i
);
490 // MH_SEND_PlayerPos(False, PID, C^.ID);
493 procedure MH_RECV_CheatRequest(C
: pTNetClient
; P
: Pointer);
498 Pl
:= g_Player_Get(C
^.Player
);
499 if Pl
= nil then Exit
;
501 CheatKind
:= e_Raw_Read_Byte(P
);
505 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
508 if Pl
.FSpectator
then
516 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; P
: Pointer);
524 TmpName
:= e_Raw_Read_String(P
);
525 TmpModel
:= e_Raw_Read_String(P
);
526 TmpColor
.R
:= e_Raw_Read_Byte(P
);
527 TmpColor
.G
:= e_Raw_Read_Byte(P
);
528 TmpColor
.B
:= e_Raw_Read_Byte(P
);
529 TmpTeam
:= e_Raw_Read_Byte(P
);
531 Pl
:= g_Player_Get(C
^.Player
);
532 if Pl
= nil then Exit
;
534 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
537 Pl
.SetColor(TmpColor
);
539 if Pl
.Name
<> TmpName
then
541 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
545 if TmpModel
<> Pl
.Model
.Name
then
546 Pl
.SetModel(TmpModel
);
548 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
553 procedure MH_RECV_RCONPassword(C
: pTNetClient
; P
: Pointer);
557 Pwd
:= e_Raw_Read_String(P
);
558 if not NetAllowRCON
then Exit
;
559 if Pwd
= NetRCONPassword
then
562 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
565 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
568 procedure MH_RECV_RCONCommand(C
: pTNetClient
; P
: Pointer);
572 Cmd
:= e_Raw_Read_String(P
);
573 if not NetAllowRCON
then Exit
;
574 if not C
^.RCONAuth
then
576 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
579 g_Console_Process(Cmd
);
584 procedure MH_RECV_Vote(C
: pTNetClient
; P
: Pointer);
587 Name
, Command
: string;
591 Start
:= e_Raw_Read_Byte(P
) <> 0;
592 Command
:= e_Raw_Read_String(P
);
594 Pl
:= g_Player_Get(C
^.Player
);
595 if Pl
= nil then Exit
;
600 if not g_Console_CommandBlacklisted(Command
) then
601 g_Game_StartVote(Command
, Name
);
603 else if gVoteInProgress
then
605 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
606 Need
:= Floor((NetClientCount
+1)/2.0) + 1
608 Need
:= Floor(NetClientCount
/2.0) + 1;
613 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
614 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
620 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
621 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
629 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
631 function sendItemRespawn (it
: PItem
): Boolean;
633 result
:= false; // don't stop
634 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
640 if gPlayers
<> nil then
642 for I
:= Low(gPlayers
) to High(gPlayers
) do
644 if gPlayers
[I
] <> nil then
646 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
647 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
648 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
650 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
651 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
656 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
658 if gMonsters
<> nil then
659 for I
:= 0 to High(gMonsters
) do
660 if gMonsters
[I
] <> nil then
661 MH_SEND_MonsterSpawn(gMonsters
[I
].UID
, ID
);
663 if gWalls
<> nil then
664 for I
:= Low(gWalls
) to High(gWalls
) do
665 if gWalls
[I
] <> nil then
669 MH_SEND_PanelState(PanelType
, I
, ID
);
671 if GetTextureCount
> 1 then
672 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
675 if gLifts
<> nil then
676 for I
:= Low(gLifts
) to High(gLifts
) do
677 if gLifts
[I
] <> nil then
679 MH_SEND_PanelState(PanelType
, I
, ID
);
681 if gRenderForegrounds
<> nil then
682 for I
:= Low(gRenderForegrounds
) to High(gRenderForegrounds
) do
683 if gRenderForegrounds
[I
] <> nil then
684 with gRenderForegrounds
[I
] do
686 if (GetTextureCount
> 1) then
687 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
689 MH_SEND_PanelState(PanelType
, I
, ID
);
691 if gRenderBackgrounds
<> nil then
692 for I
:= Low(gRenderBackgrounds
) to High(gRenderBackgrounds
) do
693 if gRenderBackgrounds
[I
] <> nil then
694 with gRenderBackgrounds
[I
] do
696 if (GetTextureCount
> 1) then
697 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
699 MH_SEND_PanelState(PanelType
, I
, ID
);
701 if gWater
<> nil then
702 for I
:= Low(gWater
) to High(gWater
) do
703 if gWater
[I
] <> nil then
705 if GetTextureCount
> 1 then
706 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
707 if gAcid1
<> nil then
708 for I
:= Low(gAcid1
) to High(gAcid1
) do
709 if gAcid1
[I
] <> nil then
711 if GetTextureCount
> 1 then
712 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
713 if gAcid2
<> nil then
714 for I
:= Low(gAcid2
) to High(gAcid2
) do
715 if gAcid2
[I
] <> nil then
717 if GetTextureCount
> 1 then
718 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
719 if gSteps
<> nil then
720 for I
:= Low(gSteps
) to High(gSteps
) do
721 if gSteps
[I
] <> nil then
723 if GetTextureCount
> 1 then
724 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
726 if gTriggers
<> nil then
727 for I
:= Low(gTriggers
) to High(gTriggers
) do
728 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
729 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
732 for I
:= Low(Shots
) to High(Shots
) do
733 if Shots
[i
].ShotType
in [6, 7, 8] then
734 MH_SEND_CreateShot(i
, ID
);
736 MH_SEND_TriggerMusic(ID
);
738 MH_SEND_GameStats(ID
);
739 MH_SEND_CoopStats(ID
);
741 if gGameSettings
.GameMode
= GM_CTF
then
743 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then
744 MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
745 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then
746 MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
749 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
751 if gLMSRespawn
> LMS_RESPAWN_NONE
then
752 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
755 procedure MH_SEND_Info(ID
: Byte);
759 Map
:= g_ExtractFileName(gMapInfo
.Map
);
761 e_Buffer_Clear(@NetOut
);
763 e_Buffer_Write(@NetOut
, Byte(NET_MSG_INFO
));
764 e_Buffer_Write(@NetOut
, ID
);
765 e_Buffer_Write(@NetOut
, NetClients
[ID
].Player
);
766 e_Buffer_Write(@NetOut
, gGameSettings
.WAD
);
767 e_Buffer_Write(@NetOut
, Map
);
768 e_Buffer_Write(@NetOut
, gWADHash
);
769 e_Buffer_Write(@NetOut
, gGameSettings
.GameMode
);
770 e_Buffer_Write(@NetOut
, gGameSettings
.GoalLimit
);
771 e_Buffer_Write(@NetOut
, gGameSettings
.TimeLimit
);
772 e_Buffer_Write(@NetOut
, gGameSettings
.MaxLives
);
773 e_Buffer_Write(@NetOut
, gGameSettings
.Options
);
774 e_Buffer_Write(@NetOut
, gTime
);
776 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
779 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
785 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
786 Mode
:= NET_CHAT_PLAYER
;
789 if (Mode
= NET_CHAT_TEAM
) then
791 for i
:= Low(gPlayers
) to High(gPlayers
) do
792 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
793 (gPlayers
[i
].Team
= ID
) then
795 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
796 e_Buffer_Write(@NetOut
, Txt
);
797 e_Buffer_Write(@NetOut
, Mode
);
798 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
805 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
806 e_Buffer_Write(@NetOut
, Txt
);
807 e_Buffer_Write(@NetOut
, Mode
);
808 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
811 if Mode
= NET_CHAT_SYSTEM
then
814 if ID
= NET_EVERYONE
then
816 if Mode
= NET_CHAT_PLAYER
then
818 g_Console_Add(Txt
, True);
819 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
820 g_Sound_PlayEx('SOUND_GAME_RADIO');
823 if Mode
= NET_CHAT_TEAM
then
824 if gPlayer1
<> nil then
826 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
828 g_Console_Add(#18'[Team] '#2 + Txt
, True);
829 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
830 g_Sound_PlayEx('SOUND_GAME_RADIO');
832 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
834 g_Console_Add(#20'[Team] '#2 + Txt
, True);
835 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
836 g_Sound_PlayEx('SOUND_GAME_RADIO');
842 Name
:= g_Net_ClientName_ByID(ID
);
843 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
844 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
845 g_Sound_PlayEx('SOUND_GAME_RADIO');
849 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
851 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GFX
));
852 e_Buffer_Write(@NetOut
, Kind
);
853 e_Buffer_Write(@NetOut
, X
);
854 e_Buffer_Write(@NetOut
, Y
);
855 e_Buffer_Write(@NetOut
, Ang
);
857 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
860 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
862 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SND
));
863 e_Buffer_Write(@NetOut
, Name
);
866 e_Buffer_Write(@NetOut
, Byte(1));
867 e_Buffer_Write(@NetOut
, X
);
868 e_Buffer_Write(@NetOut
, Y
);
871 e_Buffer_Write(@NetOut
, Byte(0));
873 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
876 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
878 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
880 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHADD
));
881 e_Buffer_Write(@NetOut
, Proj
);
882 e_Buffer_Write(@NetOut
, Shots
[Proj
].ShotType
);
883 e_Buffer_Write(@NetOut
, Shots
[Proj
].Target
);
884 e_Buffer_Write(@NetOut
, Shots
[Proj
].SpawnerUID
);
885 e_Buffer_Write(@NetOut
, Shots
[Proj
].Timeout
);
886 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.X
);
887 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Y
);
888 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.X
);
889 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.Y
);
891 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
894 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
896 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
898 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHPOS
));
899 e_Buffer_Write(@NetOut
, Proj
);
900 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.X
);
901 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Y
);
902 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.X
);
903 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.Y
);
905 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
908 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
910 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHDEL
));
911 e_Buffer_Write(@NetOut
, Proj
);
912 e_Buffer_Write(@NetOut
, Byte(Loud
));
913 e_Buffer_Write(@NetOut
, X
);
914 e_Buffer_Write(@NetOut
, Y
);
916 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
919 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
921 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SCORE
));
922 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
924 e_Buffer_Write(@NetOut
, gTeamStat
[TEAM_RED
].Goals
);
925 e_Buffer_Write(@NetOut
, gTeamStat
[TEAM_BLUE
].Goals
);
928 if gGameSettings
.GameMode
= GM_COOP
then
930 e_Buffer_Write(@NetOut
, gCoopMonstersKilled
);
931 e_Buffer_Write(@NetOut
, gCoopSecretsFound
);
934 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
937 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
939 e_Buffer_Write(@NetOut
, Byte(NET_MSG_COOP
));
940 e_Buffer_Write(@NetOut
, gTotalMonsters
);
941 e_Buffer_Write(@NetOut
, gSecretsCount
);
942 e_Buffer_Write(@NetOut
, gCoopTotalMonstersKilled
);
943 e_Buffer_Write(@NetOut
, gCoopTotalSecretsFound
);
944 e_Buffer_Write(@NetOut
, gCoopTotalMonsters
);
945 e_Buffer_Write(@NetOut
, gCoopTotalSecrets
);
948 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
950 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GEVENT
));
951 e_Buffer_Write(@NetOut
, EvType
);
952 e_Buffer_Write(@NetOut
, EvNum
);
953 e_Buffer_Write(@NetOut
, EvStr
);
954 e_Buffer_Write(@NetOut
, Byte(gLastMap
));
955 e_Buffer_Write(@NetOut
, gTime
);
956 if (EvType
= NET_EV_MAPSTART
) and (Pos(':\', EvStr
) > 0) then
958 e_Buffer_Write(@NetOut
, Byte(1));
959 e_Buffer_Write(@NetOut
, gWADHash
);
961 e_Buffer_Write(@NetOut
, Byte(0));
963 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
966 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
968 e_Buffer_Write(@NetOut
, Byte(NET_MSG_FLAG
));
969 e_Buffer_Write(@NetOut
, EvType
);
970 e_Buffer_Write(@NetOut
, Flag
);
971 e_Buffer_Write(@NetOut
, Byte(Quiet
));
972 e_Buffer_Write(@NetOut
, PID
);
973 e_Buffer_Write(@NetOut
, gFlags
[Flag
].State
);
974 e_Buffer_Write(@NetOut
, gFlags
[Flag
].CaptureTime
);
975 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.X
);
976 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Y
);
977 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Vel
.X
);
978 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Vel
.Y
);
980 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
983 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
985 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GSET
));
986 e_Buffer_Write(@NetOut
, gGameSettings
.GameMode
);
987 e_Buffer_Write(@NetOut
, gGameSettings
.GoalLimit
);
988 e_Buffer_Write(@NetOut
, gGameSettings
.TimeLimit
);
989 e_Buffer_Write(@NetOut
, gGameSettings
.MaxLives
);
990 e_Buffer_Write(@NetOut
, gGameSettings
.Options
);
992 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
997 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1001 P
:= g_Player_Get(PID
);
1002 if P
= nil then Exit
;
1004 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLR
));
1005 e_Buffer_Write(@NetOut
, PID
);
1006 e_Buffer_Write(@NetOut
, P
.Name
);
1008 e_Buffer_Write(@NetOut
, P
.FActualModelName
);
1009 e_Buffer_Write(@NetOut
, P
.FColor
.R
);
1010 e_Buffer_Write(@NetOut
, P
.FColor
.G
);
1011 e_Buffer_Write(@NetOut
, P
.FColor
.B
);
1012 e_Buffer_Write(@NetOut
, P
.Team
);
1014 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1017 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1022 Pl
:= g_Player_Get(PID
);
1023 if Pl
= nil then Exit
;
1024 if Pl
.FDummy
then Exit
;
1026 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRPOS
));
1027 e_Buffer_Write(@NetOut
, gTime
);
1028 e_Buffer_Write(@NetOut
, PID
);
1034 e_Buffer_Write(@NetOut
, FPing
);
1035 e_Buffer_Write(@NetOut
, FLoss
);
1036 if IsKeyPressed(KEY_CHAT
) then
1037 kByte
:= NET_KEY_CHAT
1040 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1041 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1042 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1043 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1044 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1045 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1048 e_Buffer_Write(@NetOut
, kByte
);
1049 if Direction
= D_LEFT
then e_Buffer_Write(@NetOut
, Byte(0)) else e_Buffer_Write(@NetOut
, Byte(1));
1050 e_Buffer_Write(@NetOut
, GameX
);
1051 e_Buffer_Write(@NetOut
, GameY
);
1052 e_Buffer_Write(@NetOut
, GameVelX
);
1053 e_Buffer_Write(@NetOut
, GameVelY
);
1054 e_Buffer_Write(@NetOut
, GameAccelX
);
1055 e_Buffer_Write(@NetOut
, GameAccelY
);
1058 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1061 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1066 P
:= g_Player_Get(PID
);
1067 if P
= nil then Exit
;
1069 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSTA
));
1070 e_Buffer_Write(@NetOut
, PID
);
1074 e_Buffer_Write(@NetOut
, Byte(Live
));
1075 e_Buffer_Write(@NetOut
, Byte(GodMode
));
1076 e_Buffer_Write(@NetOut
, Health
);
1077 e_Buffer_Write(@NetOut
, Armor
);
1078 e_Buffer_Write(@NetOut
, Air
);
1079 e_Buffer_Write(@NetOut
, JetFuel
);
1080 e_Buffer_Write(@NetOut
, Lives
);
1081 e_Buffer_Write(@NetOut
, Team
);
1083 for I
:= WP_FIRST
to WP_LAST
do
1084 e_Buffer_Write(@NetOut
, Byte(FWeapon
[I
]));
1086 for I
:= A_BULLETS
to A_HIGH
do
1087 e_Buffer_Write(@NetOut
, FAmmo
[I
]);
1089 for I
:= A_BULLETS
to A_HIGH
do
1090 e_Buffer_Write(@NetOut
, FMaxAmmo
[I
]);
1092 for I
:= MR_SUIT
to MR_MAX
do
1093 e_Buffer_Write(@NetOut
, LongWord(FMegaRulez
[I
]));
1095 e_Buffer_Write(@NetOut
, Byte(R_ITEM_BACKPACK
in FRulez
));
1096 e_Buffer_Write(@NetOut
, Byte(R_KEY_RED
in FRulez
));
1097 e_Buffer_Write(@NetOut
, Byte(R_KEY_GREEN
in FRulez
));
1098 e_Buffer_Write(@NetOut
, Byte(R_KEY_BLUE
in FRulez
));
1099 e_Buffer_Write(@NetOut
, Byte(R_BERSERK
in FRulez
));
1101 e_Buffer_Write(@NetOut
, Frags
);
1102 e_Buffer_Write(@NetOut
, Death
);
1104 e_Buffer_Write(@NetOut
, CurrWeap
);
1106 e_Buffer_Write(@NetOut
, Byte(FSpectator
));
1107 e_Buffer_Write(@NetOut
, Byte(FGhost
));
1108 e_Buffer_Write(@NetOut
, Byte(FPhysics
));
1109 e_Buffer_Write(@NetOut
, Byte(FNoRespawn
));
1110 e_Buffer_Write(@NetOut
, Byte(FJetpack
));
1111 e_Buffer_Write(@NetOut
, FFireTime
);
1114 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1117 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1119 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDMG
));
1120 e_Buffer_Write(@NetOut
, PID
);
1121 e_Buffer_Write(@NetOut
, Kind
);
1122 e_Buffer_Write(@NetOut
, Attacker
);
1123 e_Buffer_Write(@NetOut
, Value
);
1124 e_Buffer_Write(@NetOut
, VX
);
1125 e_Buffer_Write(@NetOut
, VY
);
1127 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1130 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1132 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDIE
));
1133 e_Buffer_Write(@NetOut
, PID
);
1134 e_Buffer_Write(@NetOut
, KillType
);
1135 e_Buffer_Write(@NetOut
, DeathType
);
1136 e_Buffer_Write(@NetOut
, Attacker
);
1138 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1141 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1143 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRFIRE
));
1144 e_Buffer_Write(@NetOut
, PID
);
1145 e_Buffer_Write(@NetOut
, Weapon
);
1146 e_Buffer_Write(@NetOut
, X
);
1147 e_Buffer_Write(@NetOut
, Y
);
1148 e_Buffer_Write(@NetOut
, AX
);
1149 e_Buffer_Write(@NetOut
, AY
);
1150 e_Buffer_Write(@NetOut
, ShotID
);
1152 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1155 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1157 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDEL
));
1158 e_Buffer_Write(@NetOut
, PID
);
1160 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1163 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1167 Pl
:= g_Player_Get(PID
);
1168 if Pl
= nil then Exit
;
1170 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSET
));
1171 e_Buffer_Write(@NetOut
, PID
);
1172 e_Buffer_Write(@NetOut
, Pl
.Name
);
1174 e_Buffer_Write(@NetOut
, Pl
.Model
.Name
)
1176 e_Buffer_Write(@NetOut
, Mdl
);
1177 e_Buffer_Write(@NetOut
, Pl
.FColor
.R
);
1178 e_Buffer_Write(@NetOut
, Pl
.FColor
.G
);
1179 e_Buffer_Write(@NetOut
, Pl
.FColor
.B
);
1180 e_Buffer_Write(@NetOut
, Pl
.Team
);
1182 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1187 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1191 it
:= g_ItemByIdx(IID
);
1193 e_Buffer_Write(@NetOut
, Byte(NET_MSG_ISPAWN
));
1194 e_Buffer_Write(@NetOut
, IID
);
1195 e_Buffer_Write(@NetOut
, Byte(Quiet
));
1196 e_Buffer_Write(@NetOut
, it
.ItemType
);
1197 e_Buffer_Write(@NetOut
, Byte(it
.Fall
));
1198 e_Buffer_Write(@NetOut
, Byte(it
.Respawnable
));
1199 e_Buffer_Write(@NetOut
, it
.Obj
.X
);
1200 e_Buffer_Write(@NetOut
, it
.Obj
.Y
);
1201 e_Buffer_Write(@NetOut
, it
.Obj
.Vel
.X
);
1202 e_Buffer_Write(@NetOut
, it
.Obj
.Vel
.Y
);
1204 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1207 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1209 e_Buffer_Write(@NetOut
, Byte(NET_MSG_IDEL
));
1210 e_Buffer_Write(@NetOut
, IID
);
1211 e_Buffer_Write(@NetOut
, Byte(Quiet
));
1213 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1218 procedure MH_SEND_PanelTexture(PType
: Word; PID
: LongWord; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1223 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1226 TP
:= gRenderForegrounds
[PID
];
1228 TP
:= gRenderBackgrounds
[PID
];
1243 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PTEX
));
1244 e_Buffer_Write(@NetOut
, PType
);
1245 e_Buffer_Write(@NetOut
, PID
);
1246 e_Buffer_Write(@NetOut
, FCurTexture
);
1247 e_Buffer_Write(@NetOut
, FCurFrame
);
1248 e_Buffer_Write(@NetOut
, FCurFrameCount
);
1249 e_Buffer_Write(@NetOut
, AnimLoop
);
1252 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1255 procedure MH_SEND_PanelState(PType
: Word; PID
: LongWord; ID
: Integer = NET_EVERYONE
);
1260 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1262 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
1266 TP
:= gRenderBackgrounds
[PID
];
1271 TP
:= gRenderForegrounds
[PID
];
1278 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PSTATE
));
1279 e_Buffer_Write(@NetOut
, PType
);
1280 e_Buffer_Write(@NetOut
, PID
);
1281 e_Buffer_Write(@NetOut
, Byte(TP
.Enabled
));
1282 e_Buffer_Write(@NetOut
, TP
.LiftType
);
1283 e_Buffer_Write(@NetOut
, TP
.X
);
1284 e_Buffer_Write(@NetOut
, TP
.Y
);
1286 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1291 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1293 if gTriggers
= nil then Exit
;
1294 if T
.Sound
= nil then Exit
;
1296 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TSOUND
));
1297 e_Buffer_Write(@NetOut
, T
.ClientID
);
1298 e_Buffer_Write(@NetOut
, Byte(T
.Sound
.IsPlaying
));
1299 e_Buffer_Write(@NetOut
, LongWord(T
.Sound
.GetPosition
));
1300 e_Buffer_Write(@NetOut
, T
.SoundPlayCount
);
1302 g_Net_Host_Send(ID
, True);
1305 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1307 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TMUSIC
));
1308 e_Buffer_Write(@NetOut
, gMusic
.Name
);
1309 e_Buffer_Write(@NetOut
, Byte(gMusic
.IsPlaying
));
1310 e_Buffer_Write(@NetOut
, LongWord(gMusic
.GetPosition
));
1311 e_Buffer_Write(@NetOut
, Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1313 g_Net_Host_Send(ID
, True);
1318 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1322 M
:= g_Monsters_Get(UID
);
1328 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSPAWN
));
1329 e_Buffer_Write(@NetOut
, UID
);
1330 e_Buffer_Write(@NetOut
, MonsterType
);
1331 e_Buffer_Write(@NetOut
, MonsterState
);
1332 e_Buffer_Write(@NetOut
, MonsterAnim
);
1333 e_Buffer_Write(@NetOut
, MonsterTargetUID
);
1334 e_Buffer_Write(@NetOut
, MonsterTargetTime
);
1335 e_Buffer_Write(@NetOut
, MonsterBehaviour
);
1336 e_Buffer_Write(@NetOut
, MonsterSleep
);
1337 e_Buffer_Write(@NetOut
, MonsterHealth
);
1338 e_Buffer_Write(@NetOut
, MonsterAmmo
);
1339 e_Buffer_Write(@NetOut
, GameX
);
1340 e_Buffer_Write(@NetOut
, GameY
);
1341 e_Buffer_Write(@NetOut
, GameVelX
);
1342 e_Buffer_Write(@NetOut
, GameVelY
);
1343 e_Buffer_Write(@NetOut
, Byte(GameDirection
));
1346 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1349 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1353 M
:= g_Monsters_Get(UID
);
1354 if M
= nil then Exit
;
1356 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MPOS
));
1357 e_Buffer_Write(@NetOut
, UID
);
1361 e_Buffer_Write(@NetOut
, GameX
);
1362 e_Buffer_Write(@NetOut
, GameY
);
1363 e_Buffer_Write(@NetOut
, GameVelX
);
1364 e_Buffer_Write(@NetOut
, GameVelY
);
1365 e_Buffer_Write(@NetOut
, Byte(GameDirection
));
1368 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1371 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1375 M
:= g_Monsters_Get(UID
);
1376 if M
= nil then Exit
;
1378 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSTATE
));
1379 e_Buffer_Write(@NetOut
, UID
);
1383 e_Buffer_Write(@NetOut
, MonsterState
);
1384 e_Buffer_Write(@NetOut
, ForcedAnim
);
1385 e_Buffer_Write(@NetOut
, MonsterTargetUID
);
1386 e_Buffer_Write(@NetOut
, MonsterTargetTime
);
1387 e_Buffer_Write(@NetOut
, MonsterSleep
);
1388 e_Buffer_Write(@NetOut
, MonsterHealth
);
1389 e_Buffer_Write(@NetOut
, MonsterAmmo
);
1390 e_Buffer_Write(@NetOut
, MonsterPain
);
1391 e_Buffer_Write(@NetOut
, Byte(AnimIsReverse
));
1392 e_Buffer_Write(@NetOut
, FFireTime
);
1395 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1398 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1400 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSHOT
));
1401 e_Buffer_Write(@NetOut
, UID
);
1402 e_Buffer_Write(@NetOut
, X
);
1403 e_Buffer_Write(@NetOut
, Y
);
1404 e_Buffer_Write(@NetOut
, VX
);
1405 e_Buffer_Write(@NetOut
, VY
);
1407 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1410 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1414 M
:= g_Monsters_Get(UID
);
1415 if M
= nil then Exit
;
1417 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MDEL
));
1418 e_Buffer_Write(@NetOut
, UID
);
1420 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1425 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1427 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TIME_SYNC
));
1428 e_Buffer_Write(@NetOut
, Time
);
1430 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1433 procedure MH_SEND_VoteEvent(EvType
: Byte;
1434 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1435 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1436 ID
: Integer = NET_EVERYONE
);
1438 e_Buffer_Write(@NetOut
, Byte(NET_MSG_VOTE_EVENT
));
1439 e_Buffer_Write(@NetOut
, EvType
);
1440 e_Buffer_Write(@NetOut
, IntArg1
);
1441 e_Buffer_Write(@NetOut
, IntArg2
);
1442 e_Buffer_Write(@NetOut
, StrArg1
);
1443 e_Buffer_Write(@NetOut
, StrArg2
);
1445 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1448 // CLIENT MESSAGES //
1452 procedure MC_RECV_Chat(P
: Pointer);
1457 Txt
:= e_Raw_Read_String(P
);
1458 Mode
:= e_Raw_Read_Byte(P
);
1460 if Mode
<> NET_CHAT_SYSTEM
then
1462 if Mode
= NET_CHAT_PLAYER
then
1464 g_Console_Add(Txt
, True);
1465 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1466 g_Sound_PlayEx('SOUND_GAME_RADIO');
1468 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1470 if gPlayer1
.Team
= TEAM_RED
then
1471 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1472 if gPlayer1
.Team
= TEAM_BLUE
then
1473 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1474 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1475 g_Sound_PlayEx('SOUND_GAME_RADIO');
1478 g_Console_Add(Txt
, True);
1481 procedure MC_RECV_Effect(P
: Pointer);
1489 if not gGameOn
then Exit
;
1490 Kind
:= e_Raw_Read_Byte(P
);
1491 X
:= e_Raw_Read_LongInt(P
);
1492 Y
:= e_Raw_Read_LongInt(P
);
1493 Ang
:= e_Raw_Read_SmallInt(P
);
1497 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1501 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1503 Anim
:= TAnimation
.Create(ID
, False, 3);
1504 g_GFX_OnceAnim(X
, Y
, Anim
);
1508 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1513 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1515 Anim
:= TAnimation
.Create(ID
, False, 6);
1516 Anim
.Blending
:= False;
1517 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1521 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1526 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1528 Anim
:= TAnimation
.Create(ID
, False, 6);
1529 Anim
.Blending
:= False;
1530 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1534 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1539 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1541 Anim
:= TAnimation
.Create(ID
, False, 4);
1542 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1549 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1551 Anim
:= TAnimation
.Create(ID
, False, 4);
1552 g_GFX_OnceAnim(X
, Y
, Anim
);
1556 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1561 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1563 Anim
:= TAnimation
.Create(ID
, False, 4);
1564 g_GFX_OnceAnim(X
, Y
, Anim
);
1568 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1572 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1575 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1579 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1580 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1585 procedure MC_RECV_Sound(P
: Pointer);
1591 Name
:= e_Raw_Read_String(P
);
1592 Pos
:= e_Raw_Read_Byte(P
) <> 0;
1595 X
:= e_Raw_Read_LongInt(P
);
1596 Y
:= e_Raw_Read_LongInt(P
);
1597 g_Sound_PlayExAt(Name
, X
, Y
);
1600 g_Sound_PlayEx(Name
);
1603 procedure MC_RECV_CreateShot(P
: Pointer);
1605 I
, X
, Y
, XV
, YV
: Integer;
1607 Target
, Spawner
: Word;
1610 I
:= e_Raw_Read_LongInt(P
);
1611 ShType
:= e_Raw_Read_Byte(P
);
1612 Target
:= e_Raw_Read_Word(P
);
1613 Spawner
:= e_Raw_Read_Word(P
);
1614 Timeout
:= e_Raw_Read_LongWord(P
);
1615 X
:= e_Raw_Read_LongInt(P
);
1616 Y
:= e_Raw_Read_LongInt(P
);
1617 XV
:= e_Raw_Read_LongInt(P
);
1618 YV
:= e_Raw_Read_LongInt(P
);
1620 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1621 if (Shots
<> nil) and (I
<= High(Shots
)) then
1623 Shots
[I
].Timeout
:= Timeout
;
1624 //Shots[I].Target := Target; // TODO: find a use for Target later
1628 procedure MC_RECV_UpdateShot(P
: Pointer);
1630 I
, TX
, TY
, TXV
, TYV
: Integer;
1632 I
:= e_Raw_Read_LongInt(P
);
1633 TX
:= e_Raw_Read_LongInt(P
);
1634 TY
:= e_Raw_Read_LongInt(P
);
1635 TXV
:= e_Raw_Read_LongInt(P
);
1636 TYV
:= e_Raw_Read_LongInt(P
);
1638 if (Shots
<> nil) and (I
<= High(Shots
)) then
1648 procedure MC_RECV_DeleteShot(P
: Pointer);
1653 if not gGameOn
then Exit
;
1654 I
:= e_Raw_Read_LongInt(P
);
1655 L
:= (e_Raw_Read_Byte(P
) <> 0);
1656 X
:= e_Raw_Read_LongInt(P
);
1657 Y
:= e_Raw_Read_LongInt(P
);
1659 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1662 procedure MC_RECV_GameStats(P
: Pointer);
1664 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1666 gTeamStat
[TEAM_RED
].Goals
:= e_Raw_Read_SmallInt(P
);
1667 gTeamStat
[TEAM_BLUE
].Goals
:= e_Raw_Read_SmallInt(P
);
1670 if gGameSettings
.GameMode
= GM_COOP
then
1672 gCoopMonstersKilled
:= e_Raw_Read_Word(P
);
1673 gCoopSecretsFound
:= e_Raw_Read_Word(P
);
1677 procedure MC_RECV_CoopStats(P
: Pointer);
1679 gTotalMonsters
:= e_Raw_Read_LongInt(P
);
1680 gSecretsCount
:= e_Raw_Read_LongInt(P
);
1681 gCoopTotalMonstersKilled
:= e_Raw_Read_Word(P
);
1682 gCoopTotalSecretsFound
:= e_Raw_Read_Word(P
);
1683 gCoopTotalMonsters
:= e_Raw_Read_Word(P
);
1684 gCoopTotalSecrets
:= e_Raw_Read_Word(P
);
1687 procedure MC_RECV_GameEvent(P
: Pointer);
1696 i1
, i2
: TStrings_Locale
;
1700 FillChar(EvHash
, Sizeof(EvHash
), 0);
1701 EvType
:= e_Raw_Read_Byte(P
);
1702 EvNum
:= e_Raw_Read_LongInt(P
);
1703 EvStr
:= e_Raw_Read_String(P
);
1704 gLastMap
:= e_Raw_Read_Byte(P
) <> 0;
1705 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1706 gStatsPressed
:= True;
1707 EvTime
:= e_Raw_Read_LongWord(P
);
1708 BHash
:= e_Raw_Read_Byte(P
) <> 0;
1710 EvHash
:= e_Raw_Read_MD5(P
);
1718 g_Game_ClearLoading();
1719 g_Game_StopAllSounds(True);
1721 gSwitchGameMode
:= Byte(EvNum
);
1722 gGameSettings
.GameMode
:= gSwitchGameMode
;
1725 if not g_Game_StartMap(EvStr
, True) then
1727 if Pos(':\', EvStr
) = 0 then
1728 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1730 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1734 MC_SEND_FullStateRequest
;
1739 gMissionFailed
:= EvNum
<> 0;
1740 gExit
:= EXIT_ENDLEVELCUSTOM
;
1747 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1749 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1751 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1757 if EvNum
= TEAM_RED
then
1758 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1759 if EvNum
= TEAM_BLUE
then
1760 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1764 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1767 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1770 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1772 NET_EV_LMS_SURVIVOR
:
1773 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1776 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1780 pl
:= g_Player_Get(EvNum
and $FFFF);
1785 cnt
:= (EvNum
shr 16) and $FF;
1786 if Pos('w', EvStr
) = 0 then
1789 if Pos('t', EvStr
) = 0 then
1792 if Pos('-', EvStr
) = 0 then
1794 if Pos('e', EvStr
) = 0 then
1795 i1
:= I_PLAYER_SCORE_ADD_OWN
1797 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1800 if Pos('e', EvStr
) = 0 then
1801 i1
:= I_PLAYER_SCORE_SUB_OWN
1803 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1806 if Pos('r', EvStr
) > 0 then
1807 i2
:= I_PLAYER_SCORE_TO_RED
1809 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1810 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1814 if Pos('-', EvStr
) = 0 then
1815 i1
:= I_PLAYER_SCORE_ADD_TEAM
1817 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1819 if Pos('r', EvStr
) > 0 then
1820 i2
:= I_PLAYER_SCORE_RED
1822 i2
:= I_PLAYER_SCORE_BLUE
;
1823 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1828 if Pos('e', EvStr
) = 0 then
1829 i1
:= I_PLAYER_SCORE_WIN_OWN
1831 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1833 if Pos('r', EvStr
) > 0 then
1834 i2
:= I_PLAYER_SCORE_TO_RED
1836 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1837 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1843 if EvNum
= TEAM_RED
then
1844 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1845 if EvNum
= TEAM_BLUE
then
1846 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1847 if EvNum
= -TEAM_RED
then
1848 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1849 if EvNum
= -TEAM_BLUE
then
1850 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1855 g_Player_RemoveAllCorpses
;
1856 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1860 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1864 if EvNum
= TEAM_RED
then
1865 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1866 if EvNum
= TEAM_BLUE
then
1867 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1871 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1874 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1877 g_Game_Announce_KillCombo(EvNum
);
1879 NET_EV_PLAYER_TOUCH
:
1881 pl
:= g_Player_Get(EvNum
);
1889 procedure MC_RECV_FlagEvent(P
: Pointer);
1898 EvType
:= e_Raw_Read_Byte(P
);
1899 Fl
:= e_Raw_Read_Byte(P
);
1901 if Fl
= FLAG_NONE
then Exit
;
1903 Quiet
:= (e_Raw_Read_Byte(P
) <> 0);
1904 PID
:= e_Raw_Read_Word(P
);
1906 gFlags
[Fl
].State
:= e_Raw_Read_Byte(P
);
1907 gFlags
[Fl
].CaptureTime
:= e_Raw_Read_LongWord(P
);
1908 gFlags
[Fl
].Obj
.X
:= e_Raw_Read_LongInt(P
);
1909 gFlags
[Fl
].Obj
.Y
:= e_Raw_Read_LongInt(P
);
1910 gFlags
[Fl
].Obj
.Vel
.X
:= e_Raw_Read_LongInt(P
);
1911 gFlags
[Fl
].Obj
.Vel
.Y
:= e_Raw_Read_LongInt(P
);
1913 Pl
:= g_Player_Get(PID
);
1915 (EvType
<> FLAG_STATE_NORMAL
) and
1916 (EvType
<> FLAG_STATE_DROPPED
) and
1917 (EvType
<> FLAG_STATE_RETURNED
) then
1923 if Quiet
or (Pl
= nil) then Exit
;
1925 if Fl
= FLAG_RED
then
1926 s
:= _lc
[I_PLAYER_FLAG_RED
]
1928 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1930 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1933 FLAG_STATE_CAPTURED
:
1935 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1939 if Fl
= FLAG_RED
then
1940 s
:= _lc
[I_PLAYER_FLAG_RED
]
1942 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1944 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1945 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1950 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1952 if Quiet
or (Pl
= nil) then Exit
;
1954 if Fl
= FLAG_RED
then
1955 s
:= _lc
[I_PLAYER_FLAG_RED
]
1957 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1959 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1960 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1965 g_Map_ResetFlag(FLAG_RED
);
1966 g_Map_ResetFlag(FLAG_BLUE
);
1967 if Quiet
or (Pl
= nil) then Exit
;
1968 Pl
.SetFlag(FLAG_NONE
);
1970 if Fl
= FLAG_RED
then
1971 s
:= _lc
[I_PLAYER_FLAG_RED
]
1973 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1975 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1976 Insert('.', ts
, Length(ts
) + 1 - 3);
1977 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1978 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1981 FLAG_STATE_RETURNED
:
1983 g_Map_ResetFlag(Fl
);
1986 if Fl
= FLAG_RED
then
1987 s
:= _lc
[I_PLAYER_FLAG_RED
]
1989 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1991 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1996 procedure MC_RECV_GameSettings(P
: Pointer);
1998 gGameSettings
.GameMode
:= e_Raw_Read_Byte(P
);
1999 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(P
);
2000 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(P
);
2001 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(P
);
2002 gGameSettings
.Options
:= e_Raw_Read_LongWord(P
);
2007 function MC_RECV_PlayerCreate(P
: Pointer): Word;
2010 PName
, Model
: string;
2015 PID
:= e_Raw_Read_Word(P
);
2016 Pl
:= g_Player_Get(PID
);
2018 PName
:= e_Raw_Read_String(P
);
2019 Model
:= e_Raw_Read_String(P
);
2020 Color
.R
:= e_Raw_Read_Byte(P
);
2021 Color
.G
:= e_Raw_Read_Byte(P
);
2022 Color
.B
:= e_Raw_Read_Byte(P
);
2023 T
:= e_Raw_Read_Byte(P
);
2026 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2028 if (Pl
<> nil) then Exit
;
2029 DID
:= g_Player_Create(Model
, Color
, T
, False);
2030 with g_Player_Get(DID
) do
2039 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2040 gPlayer1
.UID
:= PID
;
2041 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2042 gPlayer1
.ChangeTeam(T
);
2044 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2045 gPlayer2
.UID
:= PID
;
2046 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2047 gPlayer2
.ChangeTeam(T
);
2051 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2052 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', MSG_NOTIFY
);
2056 function MC_RECV_PlayerPos(P
: Pointer): Word;
2063 TmpX
, TmpY
: Integer;
2067 GT
:= e_Raw_Read_LongWord(P
);
2068 if GT
< gTime
- NET_MAX_DIFFTIME
then
2075 PID
:= e_Raw_Read_Word(P
);
2076 Pl
:= g_Player_Get(PID
);
2078 if Pl
= nil then Exit
;
2084 FPing
:= e_Raw_Read_Word(P
);
2085 FLoss
:= e_Raw_Read_Byte(P
);
2086 kByte
:= e_Raw_Read_Word(P
);
2087 Dir
:= e_Raw_Read_Byte(P
);
2089 TmpX
:= e_Raw_Read_LongInt(P
);
2090 TmpY
:= e_Raw_Read_LongInt(P
);
2094 if (kByte
= NET_KEY_CHAT
) then
2095 PressKey(KEY_CHAT
, 10000)
2098 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2099 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2100 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2101 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2102 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2105 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2106 SetDirection(TDirection(Dir
));
2108 GameVelX
:= e_Raw_Read_LongInt(P
);
2109 GameVelY
:= e_Raw_Read_LongInt(P
);
2110 GameAccelX
:= e_Raw_Read_LongInt(P
);
2111 GameAccelY
:= e_Raw_Read_LongInt(P
);
2112 SetLerp(TmpX
, TmpY
);
2113 if NetForcePlayerUpdate
then Update();
2117 function MC_RECV_PlayerStats(P
: Pointer): Word;
2125 PID
:= e_Raw_Read_Word(P
);
2126 Pl
:= g_Player_Get(PID
);
2133 Live
:= (e_Raw_Read_Byte(P
) <> 0);
2134 GodMode
:= (e_Raw_Read_Byte(P
) <> 0);
2135 Health
:= e_Raw_Read_LongInt(P
);
2136 Armor
:= e_Raw_Read_LongInt(P
);
2137 Air
:= e_Raw_Read_LongInt(P
);
2138 JetFuel
:= e_Raw_Read_LongInt(P
);
2139 Lives
:= e_Raw_Read_Byte(P
);
2140 NewTeam
:= e_Raw_Read_Byte(P
);
2142 for I
:= WP_FIRST
to WP_LAST
do
2143 FWeapon
[I
] := (e_Raw_Read_Byte(P
) <> 0);
2145 for I
:= A_BULLETS
to A_HIGH
do
2146 FAmmo
[I
] := e_Raw_Read_Word(P
);
2148 for I
:= A_BULLETS
to A_HIGH
do
2149 FMaxAmmo
[I
] := e_Raw_Read_Word(P
);
2151 for I
:= MR_SUIT
to MR_MAX
do
2152 FMegaRulez
[I
] := e_Raw_Read_LongWord(P
);
2155 if (e_Raw_Read_Byte(P
) <> 0) then
2156 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2157 if (e_Raw_Read_Byte(P
) <> 0) then
2158 FRulez
:= FRulez
+ [R_KEY_RED
];
2159 if (e_Raw_Read_Byte(P
) <> 0) then
2160 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2161 if (e_Raw_Read_Byte(P
) <> 0) then
2162 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2163 if (e_Raw_Read_Byte(P
) <> 0) then
2164 FRulez
:= FRulez
+ [R_BERSERK
];
2166 Frags
:= e_Raw_Read_LongInt(P
);
2167 Death
:= e_Raw_Read_LongInt(P
);
2169 SetWeapon(e_Raw_Read_Byte(P
));
2171 FSpectator
:= e_Raw_Read_Byte(P
) <> 0;
2174 if Pl
= gPlayer1
then
2179 if Pl
= gPlayer2
then
2187 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2188 gPlayer1
:= g_Player_Get(gLMSPID1
);
2189 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2190 gPlayer2
:= g_Player_Get(gLMSPID2
);
2192 FGhost
:= e_Raw_Read_Byte(P
) <> 0;
2193 FPhysics
:= e_Raw_Read_Byte(P
) <> 0;
2194 FNoRespawn
:= e_Raw_Read_Byte(P
) <> 0;
2196 FJetpack
:= e_Raw_Read_Byte(P
) <> 0;
2197 FFireTime
:= e_Raw_Read_LongInt(P
);
2198 if OldJet
and not FJetpack
then
2200 else if not OldJet
and FJetpack
then
2202 if Team
<> NewTeam
then
2203 Pl
.ChangeTeam(NewTeam
);
2209 function MC_RECV_PlayerDamage(P
: Pointer): Word;
2214 Attacker
, Value
: Word;
2218 if not gGameOn
then Exit
;
2219 PID
:= e_Raw_Read_Word(P
);
2220 Pl
:= g_Player_Get(PID
);
2221 if Pl
= nil then Exit
;
2223 Kind
:= e_Raw_Read_Byte(P
);
2224 Attacker
:= e_Raw_Read_Word(P
);
2225 Value
:= e_Raw_Read_Word(P
);
2226 VX
:= e_Raw_Read_Word(P
);
2227 VY
:= e_Raw_Read_Word(P
);
2230 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2235 function MC_RECV_PlayerDeath(P
: Pointer): Word;
2239 KillType
, DeathType
: Byte;
2243 if not gGameOn
then Exit
;
2244 PID
:= e_Raw_Read_Word(P
);
2245 Pl
:= g_Player_Get(PID
);
2246 if Pl
= nil then Exit
;
2248 KillType
:= e_Raw_Read_Byte(P
);
2249 DeathType
:= e_Raw_Read_Byte(P
);
2250 Attacker
:= e_Raw_Read_Word(P
);
2254 Kill(KillType
, Attacker
, DeathType
);
2259 function MC_RECV_PlayerDelete(P
: Pointer): Word;
2264 PID
:= e_Raw_Read_Word(P
);
2265 Pl
:= g_Player_Get(PID
);
2267 if Pl
= nil then Exit
;
2269 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2270 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', MSG_NOTIFY
);
2272 g_Player_Remove(PID
);
2277 function MC_RECV_PlayerFire(P
: Pointer): Word;
2282 X
, Y
, AX
, AY
: Integer;
2286 if not gGameOn
then Exit
;
2287 PID
:= e_Raw_Read_Word(P
);
2288 Pl
:= g_Player_Get(PID
);
2289 if Pl
= nil then Exit
;
2291 Weap
:= e_Raw_Read_Byte(P
);
2292 X
:= e_Raw_Read_LongInt(P
);
2293 Y
:= e_Raw_Read_LongInt(P
);
2294 AX
:= e_Raw_Read_LongInt(P
);
2295 AY
:= e_Raw_Read_LongInt(P
);
2296 SHID
:= e_Raw_Read_LongInt(P
);
2299 if Live
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2302 procedure MC_RECV_PlayerSettings(P
: Pointer);
2311 PID
:= e_Raw_Read_Word(P
);
2312 Pl
:= g_Player_Get(PID
);
2313 if Pl
= nil then Exit
;
2315 TmpName
:= e_Raw_Read_String(P
);
2316 TmpModel
:= e_Raw_Read_String(P
);
2317 TmpColor
.R
:= e_Raw_Read_Byte(P
);
2318 TmpColor
.G
:= e_Raw_Read_Byte(P
);
2319 TmpColor
.B
:= e_Raw_Read_Byte(P
);
2320 TmpTeam
:= e_Raw_Read_Byte(P
);
2322 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2324 Pl
.ChangeTeam(TmpTeam
);
2325 if gPlayer1
= Pl
then
2326 gPlayer1Settings
.Team
:= TmpTeam
;
2327 if gPlayer2
= Pl
then
2328 gPlayer2Settings
.Team
:= TmpTeam
;
2330 Pl
.SetColor(TmpColor
);
2332 if Pl
.Name
<> TmpName
then
2334 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2338 if TmpModel
<> Pl
.Model
.Name
then
2339 Pl
.SetModel(TmpModel
);
2344 procedure MC_RECV_ItemSpawn(P
: Pointer);
2348 X
, Y
, VX
, VY
: Integer;
2350 Quiet
, Fall
{, Resp}: Boolean;
2354 if not gGameOn
then Exit
;
2355 ID
:= e_Raw_Read_Word(P
);
2356 Quiet
:= e_Raw_Read_Byte(P
) <> 0;
2357 T
:= e_Raw_Read_Byte(P
);
2358 Fall
:= e_Raw_Read_Byte(P
) <> 0;
2359 {Resp :=} e_Raw_Read_Byte(P
);
2360 X
:= e_Raw_Read_LongInt(P
);
2361 Y
:= e_Raw_Read_LongInt(P
);
2362 VX
:= e_Raw_Read_LongInt(P
);
2363 VY
:= e_Raw_Read_LongInt(P
);
2365 g_Items_Create(X
, Y
, T
, Fall
, False, False, ID
);
2367 it
:= g_ItemByIdx(ID
);
2373 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2374 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2376 Anim
:= TAnimation
.Create(AID
, False, 4);
2377 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2383 procedure MC_RECV_ItemDestroy(P
: Pointer);
2388 if not gGameOn
then Exit
;
2389 ID
:= e_Raw_Read_Word(P
);
2390 Quiet
:= e_Raw_Read_Byte(P
) <> 0;
2392 if not g_ItemValidId(ID
) then exit
;
2394 if not Quiet
then g_Item_EmitPickupSound(ID
);
2401 procedure MC_RECV_PanelTexture(P
: Pointer);
2409 if not gGameOn
then Exit
;
2410 PType
:= e_Raw_Read_Word(P
);
2411 ID
:= e_Raw_Read_LongWord(P
);
2412 Tex
:= e_Raw_Read_LongInt(P
);
2413 Fr
:= e_Raw_Read_LongInt(P
);
2414 Cnt
:= e_Raw_Read_Byte(P
);
2415 Loop
:= e_Raw_Read_Byte(P
);
2420 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2421 if gWalls
<> nil then
2424 if gRenderForegrounds
<> nil then
2425 TP
:= gRenderForegrounds
[ID
];
2427 if gRenderBackgrounds
<> nil then
2428 TP
:= gRenderBackgrounds
[ID
];
2430 if gWater
<> nil then
2433 if gAcid1
<> nil then
2436 if gAcid2
<> nil then
2439 if gSteps
<> nil then
2447 begin // switch texture
2448 TP
.SetTexture(Tex
, Loop
);
2449 TP
.SetFrame(Fr
, Cnt
);
2450 end else // looped or non-looped animation
2451 TP
.NextTexture(Loop
);
2454 procedure MC_RECV_PanelState(P
: Pointer);
2462 if not gGameOn
then Exit
;
2463 PType
:= e_Raw_Read_Word(P
);
2464 ID
:= e_Raw_Read_LongWord(P
);
2465 E
:= (e_Raw_Read_Byte(P
) <> 0);
2466 Lift
:= e_Raw_Read_Byte(P
);
2467 X
:= e_Raw_Read_LongInt(P
);
2468 Y
:= e_Raw_Read_LongInt(P
);
2471 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2473 g_Map_EnableWall(ID
)
2475 g_Map_DisableWall(ID
);
2477 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
2478 g_Map_SetLift(ID
, Lift
);
2482 gRenderBackgrounds
[ID
].X
:= X
;
2483 gRenderBackgrounds
[ID
].Y
:= Y
;
2488 gRenderForegrounds
[ID
].X
:= X
;
2489 gRenderForegrounds
[ID
].Y
:= Y
;
2496 procedure MC_RECV_TriggerSound(P
: Pointer);
2499 SPos
, SID
: LongWord;
2503 if not gGameOn
then Exit
;
2504 if gTriggers
= nil then Exit
;
2506 SID
:= e_Raw_Read_LongWord(P
);
2507 SPlaying
:= e_Raw_Read_Byte(P
) <> 0;
2508 SPos
:= e_Raw_Read_LongWord(P
);
2509 SCount
:= e_Raw_Read_LongInt(P
);
2511 for I
:= Low(gTriggers
) to High(gTriggers
) do
2512 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2513 if gTriggers
[I
].ClientID
= SID
then
2514 with gTriggers
[I
] do
2519 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0)
2521 Sound
.PlayPanVolume((Data
.Pan
-127.0)/128.0, Data
.Volume
/255.0);
2522 Sound
.SetPosition(SPos
);
2525 if Sound
.IsPlaying
then Sound
.Stop
;
2527 SoundPlayCount
:= SCount
;
2531 procedure MC_RECV_TriggerMusic(P
: Pointer);
2538 if not gGameOn
then Exit
;
2540 MName
:= e_Raw_Read_String(P
);
2541 MPlaying
:= e_Raw_Read_Byte(P
) <> 0;
2542 MPos
:= e_Raw_Read_LongWord(P
);
2543 MPaused
:= e_Raw_Read_Byte(P
) <> 0;
2547 gMusic
.SetByName(MName
);
2549 gMusic
.SetPosition(MPos
);
2550 gMusic
.SpecPause
:= MPaused
;
2553 if gMusic
.IsPlaying
then gMusic
.Stop
;
2558 procedure MC_RECV_MonsterSpawn(P
: Pointer);
2561 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2562 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2566 ID
:= e_Raw_Read_Word(P
);
2567 M
:= g_Monsters_Get(ID
);
2571 MType
:= e_Raw_Read_Byte(P
);
2572 MState
:= e_Raw_Read_Byte(P
);
2573 MAnim
:= e_Raw_Read_Byte(P
);
2574 MTarg
:= e_Raw_Read_Word(P
);
2575 MTargTime
:= e_Raw_Read_LongInt(P
);
2576 MBehav
:= e_Raw_Read_Byte(P
);
2577 MSleep
:= e_Raw_Read_LongInt(P
);
2578 MHealth
:= e_Raw_Read_LongInt(P
);
2579 MAmmo
:= e_Raw_Read_LongInt(P
);
2581 X
:= e_Raw_Read_LongInt(P
);
2582 Y
:= e_Raw_Read_LongInt(P
);
2583 VX
:= e_Raw_Read_LongInt(P
);
2584 VY
:= e_Raw_Read_LongInt(P
);
2585 MDir
:= e_Raw_Read_Byte(P
);
2587 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2588 M
:= g_Monsters_Get(ID
);
2599 MonsterAnim
:= MAnim
;
2600 MonsterTargetUID
:= MTarg
;
2601 MonsterTargetTime
:= MTargTime
;
2602 MonsterBehaviour
:= MBehav
;
2603 MonsterSleep
:= MSleep
;
2604 MonsterAmmo
:= MAmmo
;
2609 positionChanged(); // this updates spatial accelerators
2613 procedure MC_RECV_MonsterPos(P
: Pointer);
2618 ID
:= e_Raw_Read_Word(P
);
2619 M
:= g_Monsters_Get(ID
);
2625 GameX
:= e_Raw_Read_LongInt(P
);
2626 GameY
:= e_Raw_Read_LongInt(P
);
2627 GameVelX
:= e_Raw_Read_LongInt(P
);
2628 GameVelY
:= e_Raw_Read_LongInt(P
);
2629 GameDirection
:= TDirection(e_Raw_Read_Byte(P
));
2630 positionChanged(); // this updates spatial accelerators
2634 procedure MC_RECV_MonsterState(P
: Pointer);
2637 MState
, MFAnm
: Byte;
2639 AnimRevert
: Boolean;
2641 ID
:= e_Raw_Read_Word(P
);
2642 M
:= g_Monsters_Get(ID
);
2643 if M
= nil then Exit
;
2645 MState
:= e_Raw_Read_Byte(P
);
2646 MFAnm
:= e_Raw_Read_Byte(P
);
2650 MonsterTargetUID
:= e_Raw_Read_Word(P
);
2651 MonsterTargetTime
:= e_Raw_Read_LongInt(P
);
2652 MonsterSleep
:= e_Raw_Read_LongInt(P
);
2653 MonsterHealth
:= e_Raw_Read_LongInt(P
);
2654 MonsterAmmo
:= e_Raw_Read_LongInt(P
);
2655 MonsterPain
:= e_Raw_Read_LongInt(P
);
2656 AnimRevert
:= e_Raw_Read_Byte(P
) <> 0;
2657 FFireTime
:= e_Raw_Read_LongInt(P
);
2658 RevertAnim(AnimRevert
);
2660 if MonsterState
<> MState
then
2662 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then
2664 if (MState
= MONSTATE_DIE
) then
2666 if (MState
= MONSTATE_PAIN
) then
2667 MakeBloodSimple(Min(200, MonsterPain
));
2668 if (MState
= MONSTATE_ATTACK
) then
2670 if (MState
= MONSTATE_DEAD
) then
2673 SetState(MState
, MFAnm
);
2678 procedure MC_RECV_MonsterShot(P
: Pointer);
2682 X
, Y
, VX
, VY
: Integer;
2684 ID
:= e_Raw_Read_Word(P
);
2686 M
:= g_Monsters_Get(ID
);
2687 if M
= nil then Exit
;
2689 X
:= e_Raw_Read_LongInt(P
);
2690 Y
:= e_Raw_Read_LongInt(P
);
2691 VX
:= e_Raw_Read_LongInt(P
);
2692 VY
:= e_Raw_Read_LongInt(P
);
2694 M
.ClientAttack(X
, Y
, VX
, VY
);
2697 procedure MC_RECV_MonsterDelete(P
: Pointer);
2702 ID
:= e_Raw_Read_Word(P
);
2703 M
:= g_Monsters_Get(ID
);
2704 if M
= nil then Exit
;
2706 gMonsters
[ID
].SetState(5);
2707 gMonsters
[ID
].MonsterRemoved
:= True;
2710 procedure MC_RECV_TimeSync(P
: Pointer);
2714 Time
:= e_Raw_Read_LongWord(P
);
2716 if gState
= STATE_INTERCUSTOM
then
2717 gServInterTime
:= Min(Time
, 255);
2720 procedure MC_RECV_VoteEvent(P
: Pointer);
2724 Int1
, Int2
: SmallInt;
2726 EvID
:= e_Raw_Read_Byte(P
);
2727 Int1
:= e_Raw_Read_SmallInt(P
);
2728 Int2
:= e_Raw_Read_SmallInt(P
);
2729 Str1
:= e_Raw_Read_String(P
);
2730 Str2
:= e_Raw_Read_String(P
);
2734 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2736 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2738 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2740 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2742 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2748 procedure MC_SEND_Info(Password
: string);
2750 e_Buffer_Clear(@NetOut
);
2752 e_Buffer_Write(@NetOut
, Byte(NET_MSG_INFO
));
2753 e_Buffer_Write(@NetOut
, GAME_VERSION
);
2754 e_Buffer_Write(@NetOut
, Password
);
2755 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Name
);
2756 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Model
);
2757 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.R
);
2758 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.G
);
2759 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.B
);
2760 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Team
);
2762 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2765 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2767 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
2768 e_Buffer_Write(@NetOut
, Txt
);
2769 e_Buffer_Write(@NetOut
, Mode
);
2771 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2774 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
2776 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
2777 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
2781 procedure MC_SEND_PlayerPos();
2786 WeaponSelect
: Word = 0;
2789 if not gGameOn
then Exit
;
2790 if gPlayers
= nil then Exit
;
2791 if gPlayer1
= nil then Exit
;
2794 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2796 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2798 strafeDir
:= P1MoveButton
shr 4;
2799 P1MoveButton
:= P1MoveButton
and $0F;
2800 with gGameControls
.P1Control
do
2802 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 1
2803 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then P1MoveButton
:= 2
2804 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 0;
2807 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
2809 // new strafe mechanics
2810 if (strafeDir
= 0) then strafeDir
:= P1MoveButton
; // start strafing
2811 // now set direction according to strafe (reversed)
2812 if (strafeDir
= 2) then gPlayer1
.SetDirection(D_LEFT
)
2813 else if (strafeDir
= 1) then gPlayer1
.SetDirection(D_RIGHT
);
2817 if (P1MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then gPlayer1
.SetDirection(D_LEFT
)
2818 else if (P1MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then gPlayer1
.SetDirection(D_RIGHT
)
2819 else if P1MoveButton
<> 0 then gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2822 gPlayer1
.ReleaseKeys
;
2823 if P1MoveButton
= 1 then
2825 kByte
:= kByte
or NET_KEY_LEFT
;
2826 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2828 if P1MoveButton
= 2 then
2830 kByte
:= kByte
or NET_KEY_RIGHT
;
2831 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2833 if isKeyPressed(KeyUp
, KeyUp2
) then
2835 kByte
:= kByte
or NET_KEY_UP
;
2836 gPlayer1
.PressKey(KEY_UP
, 10000);
2838 if isKeyPressed(KeyDown
, KeyDown2
) then
2840 kByte
:= kByte
or NET_KEY_DOWN
;
2841 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2843 if isKeyPressed(KeyJump
, KeyJump2
) then
2845 kByte
:= kByte
or NET_KEY_JUMP
;
2846 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2848 if isKeyPressed(KeyFire
, KeyFire2
) then kByte
:= kByte
or NET_KEY_FIRE
;
2849 if isKeyPressed(KeyOpen
, KeyOpen2
) then kByte
:= kByte
or NET_KEY_OPEN
;
2850 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then kByte
:= kByte
or NET_KEY_NW
;
2851 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then kByte
:= kByte
or NET_KEY_PW
;
2852 for I
:= 0 to High(KeyWeapon
) do
2853 if isKeyPressed(KeyWeapon
[I
], KeyWeapon2
[I
]) then
2854 WeaponSelect
:= WeaponSelect
or Word(1 shl I
);
2856 // fix movebutton state
2857 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2860 kByte
:= NET_KEY_CHAT
;
2862 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRPOS
));
2863 e_Buffer_Write(@NetOut
, gTime
);
2864 e_Buffer_Write(@NetOut
, kByte
);
2865 e_Buffer_Write(@NetOut
, Byte(gPlayer1
.Direction
));
2866 e_Buffer_Write(@NetOut
, WeaponSelect
);
2867 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2868 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2870 //kBytePrev := kByte;
2871 //kDirPrev := gPlayer1.Direction;
2874 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2876 e_Buffer_Write(@NetOut
, Byte(NET_MSG_VOTE_EVENT
));
2877 e_Buffer_Write(@NetOut
, Byte(Start
));
2878 e_Buffer_Write(@NetOut
, Command
);
2879 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2882 procedure MC_SEND_PlayerSettings();
2884 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSET
));
2885 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Name
);
2886 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Model
);
2887 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.R
);
2888 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.G
);
2889 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.B
);
2890 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Team
);
2892 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2895 procedure MC_SEND_FullStateRequest();
2897 e_Buffer_Write(@NetOut
, Byte(NET_MSG_REQFST
));
2899 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2902 procedure MC_SEND_CheatRequest(Kind
: Byte);
2904 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHEAT
));
2905 e_Buffer_Write(@NetOut
, Kind
);
2907 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2909 procedure MC_SEND_RCONPassword(Password
: string);
2911 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RCON_AUTH
));
2912 e_Buffer_Write(@NetOut
, Password
);
2914 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2916 procedure MC_SEND_RCONCommand(Cmd
: string);
2918 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RCON_CMD
));
2919 e_Buffer_Write(@NetOut
, Cmd
);
2921 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2924 // i have no idea why all this stuff is in here
2926 function ReadFile(const FileName
: TFileName
): AByte
;
2928 FileStream
: TStream
;
2931 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), MSG_NOTIFY
);
2932 fname
:= findDiskWad(FileName
);
2933 if length(fname
) = 0 then
2935 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), MSG_FATALERROR
);
2936 SetLength(Result
, 0);
2939 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), MSG_NOTIFY
);
2941 FileStream
:= openDiskFileRO(fname
);
2943 if FileStream
.Size
> 0 then
2945 SetLength(Result
, FileStream
.Size
);
2946 FileStream
.Read(Result
[0], FileStream
.Size
);
2953 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
2957 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
2958 Result
.FileData
:= ReadFile(FileName
);
2959 Result
.FileSize
:= Length(Result
.FileData
);
2961 SetLength(Result
.ExternalResources
, ResList
.Count
);
2962 for i
:=0 to ResList
.Count
-1 do
2964 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
2965 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
2969 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
2971 ResultStream
: TMemoryStream
;
2973 ResultStream
:= TMemoryStream
.Create
;
2975 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
2976 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
2977 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
2979 SetLength(bytes
, ResultStream
.Size
);
2980 ResultStream
.Seek(0, soFromBeginning
);
2981 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2986 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
2988 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
2989 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
2990 SetLength(Result
.FileData
, Result
.FileSize
);
2991 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
2994 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
2996 ResultStream
: TMemoryStream
;
2999 resCount
:= Length(MapDataMsg
.ExternalResources
);
3001 ResultStream
:= TMemoryStream
.Create
;
3003 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
3004 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
3005 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
3007 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
3008 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
3010 SetLength(bytes
, ResultStream
.Size
);
3011 ResultStream
.Seek(0, soFromBeginning
);
3012 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3017 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
3021 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3022 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3024 SetLength(Result
.FileData
, Result
.FileSize
);
3025 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3027 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3028 SetLength(Result
.ExternalResources
, resCount
);
3030 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3033 function IsValidFileName(const S
: String): Boolean;
3035 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3040 for I
:= 1 to Length(S
) do
3041 Result
:= Result
and (not(S
[I
] in Forbidden
));
3044 function IsValidFilePath(const S
: String): Boolean;
3049 if not IsValidFileName(S
) then exit
;
3050 if FileExists(S
) then exit
;
3051 I
:= LastDelimiter('\/', S
);
3053 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3058 procedure MC_SEND_MapRequest();
3060 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MAP_REQUEST
));
3061 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3064 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3066 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RES_REQUEST
));
3067 e_Buffer_Write(@NetOut
, resName
);
3068 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3071 procedure MH_RECV_MapRequest(C
: pTNetClient
; P
: Pointer);
3075 mapDataMsg
: TMapDataMsg
;
3077 e_WriteLog('NET: Received map request from ' +
3078 DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3080 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3081 peer
:= NetClients
[C
.ID
].Peer
;
3083 MapDataMsgToBytes(payload
, mapDataMsg
);
3084 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3087 mapDataMsg
.FileData
:= nil;
3088 mapDataMsg
.ExternalResources
:= nil;
3091 procedure MH_RECV_ResRequest(C
: pTNetClient
; P
: Pointer);
3096 resDataMsg
: TResDataMsg
;
3098 FileName
:= ExtractFileName(e_Raw_Read_String(P
));
3099 e_WriteLog('NET: Received res request: ' + FileName
+
3100 ' from ' + DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3102 if not IsValidFilePath(FileName
) then
3104 e_WriteLog('Invalid filename: ' + FileName
, MSG_WARNING
);
3108 peer
:= NetClients
[C
.ID
].Peer
;
3110 if gExternalResources
.IndexOf(FileName
) > -1 then
3112 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3113 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3114 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3116 ResDataMsgToBytes(payload
, resDataMsg
);
3117 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);