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 g_amodes.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
);
633 if gPlayers
<> nil then
634 for I
:= Low(gPlayers
) to High(gPlayers
) do
635 if gPlayers
[I
] <> nil then
637 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
638 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
639 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
641 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
642 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
645 if gItems
<> nil then
647 for I
:= High(gItems
) downto Low(gItems
) do
648 if gItems
[I
].Live
then
649 MH_SEND_ItemSpawn(True, I
, ID
);
652 if gMonsters
<> nil then
653 for I
:= 0 to High(gMonsters
) do
654 if gMonsters
[I
] <> nil then
655 MH_SEND_MonsterSpawn(gMonsters
[I
].UID
, ID
);
657 if gWalls
<> nil then
658 for I
:= Low(gWalls
) to High(gWalls
) do
659 if gWalls
[I
] <> nil then
663 MH_SEND_PanelState(PanelType
, I
, ID
);
665 if GetTextureCount
> 1 then
666 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
669 if gLifts
<> nil then
670 for I
:= Low(gLifts
) to High(gLifts
) do
671 if gLifts
[I
] <> nil then
673 MH_SEND_PanelState(PanelType
, I
, ID
);
675 if gRenderForegrounds
<> nil then
676 for I
:= Low(gRenderForegrounds
) to High(gRenderForegrounds
) do
677 if gRenderForegrounds
[I
] <> nil then
678 with gRenderForegrounds
[I
] do
680 if (GetTextureCount
> 1) then
681 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
683 MH_SEND_PanelState(PanelType
, I
, ID
);
685 if gRenderBackgrounds
<> nil then
686 for I
:= Low(gRenderBackgrounds
) to High(gRenderBackgrounds
) do
687 if gRenderBackgrounds
[I
] <> nil then
688 with gRenderBackgrounds
[I
] do
690 if (GetTextureCount
> 1) then
691 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
693 MH_SEND_PanelState(PanelType
, I
, ID
);
695 if gWater
<> nil then
696 for I
:= Low(gWater
) to High(gWater
) do
697 if gWater
[I
] <> nil then
699 if GetTextureCount
> 1 then
700 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
701 if gAcid1
<> nil then
702 for I
:= Low(gAcid1
) to High(gAcid1
) do
703 if gAcid1
[I
] <> nil then
705 if GetTextureCount
> 1 then
706 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
707 if gAcid2
<> nil then
708 for I
:= Low(gAcid2
) to High(gAcid2
) do
709 if gAcid2
[I
] <> nil then
711 if GetTextureCount
> 1 then
712 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
713 if gSteps
<> nil then
714 for I
:= Low(gSteps
) to High(gSteps
) do
715 if gSteps
[I
] <> nil then
717 if GetTextureCount
> 1 then
718 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
720 if gTriggers
<> nil then
721 for I
:= Low(gTriggers
) to High(gTriggers
) do
722 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
723 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
726 for I
:= Low(Shots
) to High(Shots
) do
727 if Shots
[i
].ShotType
in [6, 7, 8] then
728 MH_SEND_CreateShot(i
, ID
);
730 MH_SEND_TriggerMusic(ID
);
732 MH_SEND_GameStats(ID
);
733 MH_SEND_CoopStats(ID
);
735 if gGameSettings
.GameMode
= GM_CTF
then
737 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then
738 MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
739 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then
740 MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
743 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
745 if gLMSRespawn
> LMS_RESPAWN_NONE
then
746 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
749 procedure MH_SEND_Info(ID
: Byte);
753 Map
:= g_ExtractFileName(gMapInfo
.Map
);
755 e_Buffer_Clear(@NetOut
);
757 e_Buffer_Write(@NetOut
, Byte(NET_MSG_INFO
));
758 e_Buffer_Write(@NetOut
, ID
);
759 e_Buffer_Write(@NetOut
, NetClients
[ID
].Player
);
760 e_Buffer_Write(@NetOut
, gGameSettings
.WAD
);
761 e_Buffer_Write(@NetOut
, Map
);
762 e_Buffer_Write(@NetOut
, gWADHash
);
763 e_Buffer_Write(@NetOut
, gGameSettings
.GameMode
);
764 e_Buffer_Write(@NetOut
, gGameSettings
.GoalLimit
);
765 e_Buffer_Write(@NetOut
, gGameSettings
.TimeLimit
);
766 e_Buffer_Write(@NetOut
, gGameSettings
.MaxLives
);
767 e_Buffer_Write(@NetOut
, gGameSettings
.Options
);
768 e_Buffer_Write(@NetOut
, gTime
);
770 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
773 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
779 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
780 Mode
:= NET_CHAT_PLAYER
;
783 if (Mode
= NET_CHAT_TEAM
) then
785 for i
:= Low(gPlayers
) to High(gPlayers
) do
786 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
787 (gPlayers
[i
].Team
= ID
) then
789 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
790 e_Buffer_Write(@NetOut
, Txt
);
791 e_Buffer_Write(@NetOut
, Mode
);
792 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
799 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
800 e_Buffer_Write(@NetOut
, Txt
);
801 e_Buffer_Write(@NetOut
, Mode
);
802 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
805 if Mode
= NET_CHAT_SYSTEM
then
808 if ID
= NET_EVERYONE
then
810 if Mode
= NET_CHAT_PLAYER
then
812 g_Console_Add(Txt
, True);
813 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
814 g_Sound_PlayEx('SOUND_GAME_RADIO');
817 if Mode
= NET_CHAT_TEAM
then
818 if gPlayer1
<> nil then
820 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
822 g_Console_Add(#18'[Team] '#2 + Txt
, True);
823 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
824 g_Sound_PlayEx('SOUND_GAME_RADIO');
826 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
828 g_Console_Add(#20'[Team] '#2 + Txt
, True);
829 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
830 g_Sound_PlayEx('SOUND_GAME_RADIO');
836 Name
:= g_Net_ClientName_ByID(ID
);
837 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
838 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
839 g_Sound_PlayEx('SOUND_GAME_RADIO');
843 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
845 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GFX
));
846 e_Buffer_Write(@NetOut
, Kind
);
847 e_Buffer_Write(@NetOut
, X
);
848 e_Buffer_Write(@NetOut
, Y
);
849 e_Buffer_Write(@NetOut
, Ang
);
851 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
854 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
856 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SND
));
857 e_Buffer_Write(@NetOut
, Name
);
860 e_Buffer_Write(@NetOut
, Byte(1));
861 e_Buffer_Write(@NetOut
, X
);
862 e_Buffer_Write(@NetOut
, Y
);
865 e_Buffer_Write(@NetOut
, Byte(0));
867 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
870 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
872 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
874 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHADD
));
875 e_Buffer_Write(@NetOut
, Proj
);
876 e_Buffer_Write(@NetOut
, Shots
[Proj
].ShotType
);
877 e_Buffer_Write(@NetOut
, Shots
[Proj
].Target
);
878 e_Buffer_Write(@NetOut
, Shots
[Proj
].SpawnerUID
);
879 e_Buffer_Write(@NetOut
, Shots
[Proj
].Timeout
);
880 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.X
);
881 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Y
);
882 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.X
);
883 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.Y
);
885 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
888 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
890 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
892 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHPOS
));
893 e_Buffer_Write(@NetOut
, Proj
);
894 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.X
);
895 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Y
);
896 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.X
);
897 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.Y
);
899 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
902 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
904 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHDEL
));
905 e_Buffer_Write(@NetOut
, Proj
);
906 e_Buffer_Write(@NetOut
, Byte(Loud
));
907 e_Buffer_Write(@NetOut
, X
);
908 e_Buffer_Write(@NetOut
, Y
);
910 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
913 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
915 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SCORE
));
916 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
918 e_Buffer_Write(@NetOut
, gTeamStat
[TEAM_RED
].Goals
);
919 e_Buffer_Write(@NetOut
, gTeamStat
[TEAM_BLUE
].Goals
);
922 if gGameSettings
.GameMode
= GM_COOP
then
924 e_Buffer_Write(@NetOut
, gCoopMonstersKilled
);
925 e_Buffer_Write(@NetOut
, gCoopSecretsFound
);
928 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
931 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
933 e_Buffer_Write(@NetOut
, Byte(NET_MSG_COOP
));
934 e_Buffer_Write(@NetOut
, gTotalMonsters
);
935 e_Buffer_Write(@NetOut
, gSecretsCount
);
936 e_Buffer_Write(@NetOut
, gCoopTotalMonstersKilled
);
937 e_Buffer_Write(@NetOut
, gCoopTotalSecretsFound
);
938 e_Buffer_Write(@NetOut
, gCoopTotalMonsters
);
939 e_Buffer_Write(@NetOut
, gCoopTotalSecrets
);
942 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
944 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GEVENT
));
945 e_Buffer_Write(@NetOut
, EvType
);
946 e_Buffer_Write(@NetOut
, EvNum
);
947 e_Buffer_Write(@NetOut
, EvStr
);
948 e_Buffer_Write(@NetOut
, Byte(gLastMap
));
949 e_Buffer_Write(@NetOut
, gTime
);
950 if (EvType
= NET_EV_MAPSTART
) and (Pos(':\', EvStr
) > 0) then
952 e_Buffer_Write(@NetOut
, Byte(1));
953 e_Buffer_Write(@NetOut
, gWADHash
);
955 e_Buffer_Write(@NetOut
, Byte(0));
957 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
960 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
962 e_Buffer_Write(@NetOut
, Byte(NET_MSG_FLAG
));
963 e_Buffer_Write(@NetOut
, EvType
);
964 e_Buffer_Write(@NetOut
, Flag
);
965 e_Buffer_Write(@NetOut
, Byte(Quiet
));
966 e_Buffer_Write(@NetOut
, PID
);
967 e_Buffer_Write(@NetOut
, gFlags
[Flag
].State
);
968 e_Buffer_Write(@NetOut
, gFlags
[Flag
].CaptureTime
);
969 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.X
);
970 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Y
);
971 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Vel
.X
);
972 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Vel
.Y
);
974 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
977 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
979 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GSET
));
980 e_Buffer_Write(@NetOut
, gGameSettings
.GameMode
);
981 e_Buffer_Write(@NetOut
, gGameSettings
.GoalLimit
);
982 e_Buffer_Write(@NetOut
, gGameSettings
.TimeLimit
);
983 e_Buffer_Write(@NetOut
, gGameSettings
.MaxLives
);
984 e_Buffer_Write(@NetOut
, gGameSettings
.Options
);
986 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
991 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
995 P
:= g_Player_Get(PID
);
996 if P
= nil then Exit
;
998 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLR
));
999 e_Buffer_Write(@NetOut
, PID
);
1000 e_Buffer_Write(@NetOut
, P
.Name
);
1002 e_Buffer_Write(@NetOut
, P
.FActualModelName
);
1003 e_Buffer_Write(@NetOut
, P
.FColor
.R
);
1004 e_Buffer_Write(@NetOut
, P
.FColor
.G
);
1005 e_Buffer_Write(@NetOut
, P
.FColor
.B
);
1006 e_Buffer_Write(@NetOut
, P
.Team
);
1008 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1011 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1016 Pl
:= g_Player_Get(PID
);
1017 if Pl
= nil then Exit
;
1018 if Pl
.FDummy
then Exit
;
1020 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRPOS
));
1021 e_Buffer_Write(@NetOut
, gTime
);
1022 e_Buffer_Write(@NetOut
, PID
);
1028 e_Buffer_Write(@NetOut
, FPing
);
1029 e_Buffer_Write(@NetOut
, FLoss
);
1030 if IsKeyPressed(KEY_CHAT
) then
1031 kByte
:= NET_KEY_CHAT
1034 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1035 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1036 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1037 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1038 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1039 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1042 e_Buffer_Write(@NetOut
, kByte
);
1043 if Direction
= D_LEFT
then e_Buffer_Write(@NetOut
, Byte(0)) else e_Buffer_Write(@NetOut
, Byte(1));
1044 e_Buffer_Write(@NetOut
, GameX
);
1045 e_Buffer_Write(@NetOut
, GameY
);
1046 e_Buffer_Write(@NetOut
, GameVelX
);
1047 e_Buffer_Write(@NetOut
, GameVelY
);
1048 e_Buffer_Write(@NetOut
, GameAccelX
);
1049 e_Buffer_Write(@NetOut
, GameAccelY
);
1052 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1055 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1060 P
:= g_Player_Get(PID
);
1061 if P
= nil then Exit
;
1063 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSTA
));
1064 e_Buffer_Write(@NetOut
, PID
);
1068 e_Buffer_Write(@NetOut
, Byte(Live
));
1069 e_Buffer_Write(@NetOut
, Byte(GodMode
));
1070 e_Buffer_Write(@NetOut
, Health
);
1071 e_Buffer_Write(@NetOut
, Armor
);
1072 e_Buffer_Write(@NetOut
, Air
);
1073 e_Buffer_Write(@NetOut
, JetFuel
);
1074 e_Buffer_Write(@NetOut
, Lives
);
1075 e_Buffer_Write(@NetOut
, Team
);
1077 for I
:= WP_FIRST
to WP_LAST
do
1078 e_Buffer_Write(@NetOut
, Byte(FWeapon
[I
]));
1080 for I
:= A_BULLETS
to A_HIGH
do
1081 e_Buffer_Write(@NetOut
, FAmmo
[I
]);
1083 for I
:= A_BULLETS
to A_HIGH
do
1084 e_Buffer_Write(@NetOut
, FMaxAmmo
[I
]);
1086 for I
:= MR_SUIT
to MR_MAX
do
1087 e_Buffer_Write(@NetOut
, LongWord(FMegaRulez
[I
]));
1089 e_Buffer_Write(@NetOut
, Byte(R_ITEM_BACKPACK
in FRulez
));
1090 e_Buffer_Write(@NetOut
, Byte(R_KEY_RED
in FRulez
));
1091 e_Buffer_Write(@NetOut
, Byte(R_KEY_GREEN
in FRulez
));
1092 e_Buffer_Write(@NetOut
, Byte(R_KEY_BLUE
in FRulez
));
1093 e_Buffer_Write(@NetOut
, Byte(R_BERSERK
in FRulez
));
1095 e_Buffer_Write(@NetOut
, Frags
);
1096 e_Buffer_Write(@NetOut
, Death
);
1098 e_Buffer_Write(@NetOut
, CurrWeap
);
1100 e_Buffer_Write(@NetOut
, Byte(FSpectator
));
1101 e_Buffer_Write(@NetOut
, Byte(FGhost
));
1102 e_Buffer_Write(@NetOut
, Byte(FPhysics
));
1103 e_Buffer_Write(@NetOut
, Byte(FNoRespawn
));
1104 e_Buffer_Write(@NetOut
, Byte(FJetpack
));
1105 e_Buffer_Write(@NetOut
, FFireTime
);
1108 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1111 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1113 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDMG
));
1114 e_Buffer_Write(@NetOut
, PID
);
1115 e_Buffer_Write(@NetOut
, Kind
);
1116 e_Buffer_Write(@NetOut
, Attacker
);
1117 e_Buffer_Write(@NetOut
, Value
);
1118 e_Buffer_Write(@NetOut
, VX
);
1119 e_Buffer_Write(@NetOut
, VY
);
1121 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1124 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1126 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDIE
));
1127 e_Buffer_Write(@NetOut
, PID
);
1128 e_Buffer_Write(@NetOut
, KillType
);
1129 e_Buffer_Write(@NetOut
, DeathType
);
1130 e_Buffer_Write(@NetOut
, Attacker
);
1132 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1135 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1137 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRFIRE
));
1138 e_Buffer_Write(@NetOut
, PID
);
1139 e_Buffer_Write(@NetOut
, Weapon
);
1140 e_Buffer_Write(@NetOut
, X
);
1141 e_Buffer_Write(@NetOut
, Y
);
1142 e_Buffer_Write(@NetOut
, AX
);
1143 e_Buffer_Write(@NetOut
, AY
);
1144 e_Buffer_Write(@NetOut
, ShotID
);
1146 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1149 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1151 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDEL
));
1152 e_Buffer_Write(@NetOut
, PID
);
1154 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1157 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1161 Pl
:= g_Player_Get(PID
);
1162 if Pl
= nil then Exit
;
1164 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSET
));
1165 e_Buffer_Write(@NetOut
, PID
);
1166 e_Buffer_Write(@NetOut
, Pl
.Name
);
1168 e_Buffer_Write(@NetOut
, Pl
.Model
.Name
)
1170 e_Buffer_Write(@NetOut
, Mdl
);
1171 e_Buffer_Write(@NetOut
, Pl
.FColor
.R
);
1172 e_Buffer_Write(@NetOut
, Pl
.FColor
.G
);
1173 e_Buffer_Write(@NetOut
, Pl
.FColor
.B
);
1174 e_Buffer_Write(@NetOut
, Pl
.Team
);
1176 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1181 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1183 e_Buffer_Write(@NetOut
, Byte(NET_MSG_ISPAWN
));
1184 e_Buffer_Write(@NetOut
, IID
);
1185 e_Buffer_Write(@NetOut
, Byte(Quiet
));
1186 e_Buffer_Write(@NetOut
, gItems
[IID
].ItemType
);
1187 e_Buffer_Write(@NetOut
, Byte(gItems
[IID
].Fall
));
1188 e_Buffer_Write(@NetOut
, Byte(gItems
[IID
].Respawnable
));
1189 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.X
);
1190 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.Y
);
1191 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.Vel
.X
);
1192 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.Vel
.Y
);
1194 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1197 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1199 e_Buffer_Write(@NetOut
, Byte(NET_MSG_IDEL
));
1200 e_Buffer_Write(@NetOut
, IID
);
1201 e_Buffer_Write(@NetOut
, Byte(Quiet
));
1203 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1208 procedure MH_SEND_PanelTexture(PType
: Word; PID
: LongWord; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1213 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1216 TP
:= gRenderForegrounds
[PID
];
1218 TP
:= gRenderBackgrounds
[PID
];
1233 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PTEX
));
1234 e_Buffer_Write(@NetOut
, PType
);
1235 e_Buffer_Write(@NetOut
, PID
);
1236 e_Buffer_Write(@NetOut
, FCurTexture
);
1237 e_Buffer_Write(@NetOut
, FCurFrame
);
1238 e_Buffer_Write(@NetOut
, FCurFrameCount
);
1239 e_Buffer_Write(@NetOut
, AnimLoop
);
1242 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1245 procedure MH_SEND_PanelState(PType
: Word; PID
: LongWord; ID
: Integer = NET_EVERYONE
);
1250 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1252 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
1256 TP
:= gRenderBackgrounds
[PID
];
1261 TP
:= gRenderForegrounds
[PID
];
1268 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PSTATE
));
1269 e_Buffer_Write(@NetOut
, PType
);
1270 e_Buffer_Write(@NetOut
, PID
);
1271 e_Buffer_Write(@NetOut
, Byte(TP
.Enabled
));
1272 e_Buffer_Write(@NetOut
, TP
.LiftType
);
1273 e_Buffer_Write(@NetOut
, TP
.X
);
1274 e_Buffer_Write(@NetOut
, TP
.Y
);
1276 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1281 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1283 if gTriggers
= nil then Exit
;
1284 if T
.Sound
= nil then Exit
;
1286 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TSOUND
));
1287 e_Buffer_Write(@NetOut
, T
.ClientID
);
1288 e_Buffer_Write(@NetOut
, Byte(T
.Sound
.IsPlaying
));
1289 e_Buffer_Write(@NetOut
, LongWord(T
.Sound
.GetPosition
));
1290 e_Buffer_Write(@NetOut
, T
.SoundPlayCount
);
1292 g_Net_Host_Send(ID
, True);
1295 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1297 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TMUSIC
));
1298 e_Buffer_Write(@NetOut
, gMusic
.Name
);
1299 e_Buffer_Write(@NetOut
, Byte(gMusic
.IsPlaying
));
1300 e_Buffer_Write(@NetOut
, LongWord(gMusic
.GetPosition
));
1301 e_Buffer_Write(@NetOut
, Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1303 g_Net_Host_Send(ID
, True);
1308 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1312 M
:= g_Monsters_Get(UID
);
1318 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSPAWN
));
1319 e_Buffer_Write(@NetOut
, UID
);
1320 e_Buffer_Write(@NetOut
, MonsterType
);
1321 e_Buffer_Write(@NetOut
, MonsterState
);
1322 e_Buffer_Write(@NetOut
, MonsterAnim
);
1323 e_Buffer_Write(@NetOut
, MonsterTargetUID
);
1324 e_Buffer_Write(@NetOut
, MonsterTargetTime
);
1325 e_Buffer_Write(@NetOut
, MonsterBehaviour
);
1326 e_Buffer_Write(@NetOut
, MonsterSleep
);
1327 e_Buffer_Write(@NetOut
, MonsterHealth
);
1328 e_Buffer_Write(@NetOut
, MonsterAmmo
);
1329 e_Buffer_Write(@NetOut
, GameX
);
1330 e_Buffer_Write(@NetOut
, GameY
);
1331 e_Buffer_Write(@NetOut
, GameVelX
);
1332 e_Buffer_Write(@NetOut
, GameVelY
);
1333 e_Buffer_Write(@NetOut
, Byte(GameDirection
));
1336 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1339 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1343 M
:= g_Monsters_Get(UID
);
1344 if M
= nil then Exit
;
1346 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MPOS
));
1347 e_Buffer_Write(@NetOut
, UID
);
1351 e_Buffer_Write(@NetOut
, GameX
);
1352 e_Buffer_Write(@NetOut
, GameY
);
1353 e_Buffer_Write(@NetOut
, GameVelX
);
1354 e_Buffer_Write(@NetOut
, GameVelY
);
1355 e_Buffer_Write(@NetOut
, Byte(GameDirection
));
1358 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1361 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1365 M
:= g_Monsters_Get(UID
);
1366 if M
= nil then Exit
;
1368 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSTATE
));
1369 e_Buffer_Write(@NetOut
, UID
);
1373 e_Buffer_Write(@NetOut
, MonsterState
);
1374 e_Buffer_Write(@NetOut
, ForcedAnim
);
1375 e_Buffer_Write(@NetOut
, MonsterTargetUID
);
1376 e_Buffer_Write(@NetOut
, MonsterTargetTime
);
1377 e_Buffer_Write(@NetOut
, MonsterSleep
);
1378 e_Buffer_Write(@NetOut
, MonsterHealth
);
1379 e_Buffer_Write(@NetOut
, MonsterAmmo
);
1380 e_Buffer_Write(@NetOut
, MonsterPain
);
1381 e_Buffer_Write(@NetOut
, Byte(AnimIsReverse
));
1382 e_Buffer_Write(@NetOut
, FFireTime
);
1385 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1388 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1390 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSHOT
));
1391 e_Buffer_Write(@NetOut
, UID
);
1392 e_Buffer_Write(@NetOut
, X
);
1393 e_Buffer_Write(@NetOut
, Y
);
1394 e_Buffer_Write(@NetOut
, VX
);
1395 e_Buffer_Write(@NetOut
, VY
);
1397 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1400 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1404 M
:= g_Monsters_Get(UID
);
1405 if M
= nil then Exit
;
1407 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MDEL
));
1408 e_Buffer_Write(@NetOut
, UID
);
1410 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1415 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1417 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TIME_SYNC
));
1418 e_Buffer_Write(@NetOut
, Time
);
1420 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1423 procedure MH_SEND_VoteEvent(EvType
: Byte;
1424 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1425 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1426 ID
: Integer = NET_EVERYONE
);
1428 e_Buffer_Write(@NetOut
, Byte(NET_MSG_VOTE_EVENT
));
1429 e_Buffer_Write(@NetOut
, EvType
);
1430 e_Buffer_Write(@NetOut
, IntArg1
);
1431 e_Buffer_Write(@NetOut
, IntArg2
);
1432 e_Buffer_Write(@NetOut
, StrArg1
);
1433 e_Buffer_Write(@NetOut
, StrArg2
);
1435 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1438 // CLIENT MESSAGES //
1442 procedure MC_RECV_Chat(P
: Pointer);
1447 Txt
:= e_Raw_Read_String(P
);
1448 Mode
:= e_Raw_Read_Byte(P
);
1450 if Mode
<> NET_CHAT_SYSTEM
then
1452 if Mode
= NET_CHAT_PLAYER
then
1454 g_Console_Add(Txt
, True);
1455 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1456 g_Sound_PlayEx('SOUND_GAME_RADIO');
1458 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1460 if gPlayer1
.Team
= TEAM_RED
then
1461 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1462 if gPlayer1
.Team
= TEAM_BLUE
then
1463 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1464 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1465 g_Sound_PlayEx('SOUND_GAME_RADIO');
1468 g_Console_Add(Txt
, True);
1471 procedure MC_RECV_Effect(P
: Pointer);
1479 if not gGameOn
then Exit
;
1480 Kind
:= e_Raw_Read_Byte(P
);
1481 X
:= e_Raw_Read_LongInt(P
);
1482 Y
:= e_Raw_Read_LongInt(P
);
1483 Ang
:= e_Raw_Read_SmallInt(P
);
1487 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1491 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1493 Anim
:= TAnimation
.Create(ID
, False, 3);
1494 g_GFX_OnceAnim(X
, Y
, Anim
);
1498 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1503 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1505 Anim
:= TAnimation
.Create(ID
, False, 6);
1506 Anim
.Blending
:= False;
1507 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1511 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1516 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1518 Anim
:= TAnimation
.Create(ID
, False, 6);
1519 Anim
.Blending
:= False;
1520 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1524 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1529 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1531 Anim
:= TAnimation
.Create(ID
, False, 4);
1532 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1539 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1541 Anim
:= TAnimation
.Create(ID
, False, 4);
1542 g_GFX_OnceAnim(X
, Y
, Anim
);
1546 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1551 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1553 Anim
:= TAnimation
.Create(ID
, False, 4);
1554 g_GFX_OnceAnim(X
, Y
, Anim
);
1558 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1562 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1565 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1569 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1570 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1575 procedure MC_RECV_Sound(P
: Pointer);
1581 Name
:= e_Raw_Read_String(P
);
1582 Pos
:= e_Raw_Read_Byte(P
) <> 0;
1585 X
:= e_Raw_Read_LongInt(P
);
1586 Y
:= e_Raw_Read_LongInt(P
);
1587 g_Sound_PlayExAt(Name
, X
, Y
);
1590 g_Sound_PlayEx(Name
);
1593 procedure MC_RECV_CreateShot(P
: Pointer);
1595 I
, X
, Y
, XV
, YV
: Integer;
1597 Target
, Spawner
: Word;
1600 I
:= e_Raw_Read_LongInt(P
);
1601 ShType
:= e_Raw_Read_Byte(P
);
1602 Target
:= e_Raw_Read_Word(P
);
1603 Spawner
:= e_Raw_Read_Word(P
);
1604 Timeout
:= e_Raw_Read_LongWord(P
);
1605 X
:= e_Raw_Read_LongInt(P
);
1606 Y
:= e_Raw_Read_LongInt(P
);
1607 XV
:= e_Raw_Read_LongInt(P
);
1608 YV
:= e_Raw_Read_LongInt(P
);
1610 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1611 if (Shots
<> nil) and (I
<= High(Shots
)) then
1613 Shots
[I
].Timeout
:= Timeout
;
1614 //Shots[I].Target := Target; // TODO: find a use for Target later
1618 procedure MC_RECV_UpdateShot(P
: Pointer);
1620 I
, TX
, TY
, TXV
, TYV
: Integer;
1622 I
:= e_Raw_Read_LongInt(P
);
1623 TX
:= e_Raw_Read_LongInt(P
);
1624 TY
:= e_Raw_Read_LongInt(P
);
1625 TXV
:= e_Raw_Read_LongInt(P
);
1626 TYV
:= e_Raw_Read_LongInt(P
);
1628 if (Shots
<> nil) and (I
<= High(Shots
)) then
1638 procedure MC_RECV_DeleteShot(P
: Pointer);
1643 if not gGameOn
then Exit
;
1644 I
:= e_Raw_Read_LongInt(P
);
1645 L
:= (e_Raw_Read_Byte(P
) <> 0);
1646 X
:= e_Raw_Read_LongInt(P
);
1647 Y
:= e_Raw_Read_LongInt(P
);
1649 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1652 procedure MC_RECV_GameStats(P
: Pointer);
1654 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1656 gTeamStat
[TEAM_RED
].Goals
:= e_Raw_Read_SmallInt(P
);
1657 gTeamStat
[TEAM_BLUE
].Goals
:= e_Raw_Read_SmallInt(P
);
1660 if gGameSettings
.GameMode
= GM_COOP
then
1662 gCoopMonstersKilled
:= e_Raw_Read_Word(P
);
1663 gCoopSecretsFound
:= e_Raw_Read_Word(P
);
1667 procedure MC_RECV_CoopStats(P
: Pointer);
1669 gTotalMonsters
:= e_Raw_Read_LongInt(P
);
1670 gSecretsCount
:= e_Raw_Read_LongInt(P
);
1671 gCoopTotalMonstersKilled
:= e_Raw_Read_Word(P
);
1672 gCoopTotalSecretsFound
:= e_Raw_Read_Word(P
);
1673 gCoopTotalMonsters
:= e_Raw_Read_Word(P
);
1674 gCoopTotalSecrets
:= e_Raw_Read_Word(P
);
1677 procedure MC_RECV_GameEvent(P
: Pointer);
1686 i1
, i2
: TStrings_Locale
;
1690 FillChar(EvHash
, Sizeof(EvHash
), 0);
1691 EvType
:= e_Raw_Read_Byte(P
);
1692 EvNum
:= e_Raw_Read_LongInt(P
);
1693 EvStr
:= e_Raw_Read_String(P
);
1694 gLastMap
:= e_Raw_Read_Byte(P
) <> 0;
1695 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1696 gStatsPressed
:= True;
1697 EvTime
:= e_Raw_Read_LongWord(P
);
1698 BHash
:= e_Raw_Read_Byte(P
) <> 0;
1700 EvHash
:= e_Raw_Read_MD5(P
);
1708 g_Game_ClearLoading();
1709 g_Game_StopAllSounds(True);
1711 gSwitchGameMode
:= Byte(EvNum
);
1712 gGameSettings
.GameMode
:= gSwitchGameMode
;
1715 if not g_Game_StartMap(EvStr
, True) then
1717 if Pos(':\', EvStr
) = 0 then
1718 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1720 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1724 MC_SEND_FullStateRequest
;
1729 gMissionFailed
:= EvNum
<> 0;
1730 gExit
:= EXIT_ENDLEVELCUSTOM
;
1737 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1739 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1741 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1747 if EvNum
= TEAM_RED
then
1748 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1749 if EvNum
= TEAM_BLUE
then
1750 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1754 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1757 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1760 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1762 NET_EV_LMS_SURVIVOR
:
1763 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1766 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1770 pl
:= g_Player_Get(EvNum
and $FFFF);
1775 cnt
:= (EvNum
shr 16) and $FF;
1776 if Pos('w', EvStr
) = 0 then
1779 if Pos('t', EvStr
) = 0 then
1782 if Pos('-', EvStr
) = 0 then
1784 if Pos('e', EvStr
) = 0 then
1785 i1
:= I_PLAYER_SCORE_ADD_OWN
1787 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1790 if Pos('e', EvStr
) = 0 then
1791 i1
:= I_PLAYER_SCORE_SUB_OWN
1793 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1796 if Pos('r', EvStr
) > 0 then
1797 i2
:= I_PLAYER_SCORE_TO_RED
1799 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1800 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1804 if Pos('-', EvStr
) = 0 then
1805 i1
:= I_PLAYER_SCORE_ADD_TEAM
1807 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1809 if Pos('r', EvStr
) > 0 then
1810 i2
:= I_PLAYER_SCORE_RED
1812 i2
:= I_PLAYER_SCORE_BLUE
;
1813 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1818 if Pos('e', EvStr
) = 0 then
1819 i1
:= I_PLAYER_SCORE_WIN_OWN
1821 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1823 if Pos('r', EvStr
) > 0 then
1824 i2
:= I_PLAYER_SCORE_TO_RED
1826 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1827 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1833 if EvNum
= TEAM_RED
then
1834 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1835 if EvNum
= TEAM_BLUE
then
1836 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1837 if EvNum
= -TEAM_RED
then
1838 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1839 if EvNum
= -TEAM_BLUE
then
1840 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1845 g_Player_RemoveAllCorpses
;
1846 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1850 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1854 if EvNum
= TEAM_RED
then
1855 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1856 if EvNum
= TEAM_BLUE
then
1857 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1861 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1864 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1867 g_Game_Announce_KillCombo(EvNum
);
1869 NET_EV_PLAYER_TOUCH
:
1871 pl
:= g_Player_Get(EvNum
);
1879 procedure MC_RECV_FlagEvent(P
: Pointer);
1888 EvType
:= e_Raw_Read_Byte(P
);
1889 Fl
:= e_Raw_Read_Byte(P
);
1891 if Fl
= FLAG_NONE
then Exit
;
1893 Quiet
:= (e_Raw_Read_Byte(P
) <> 0);
1894 PID
:= e_Raw_Read_Word(P
);
1896 gFlags
[Fl
].State
:= e_Raw_Read_Byte(P
);
1897 gFlags
[Fl
].CaptureTime
:= e_Raw_Read_LongWord(P
);
1898 gFlags
[Fl
].Obj
.X
:= e_Raw_Read_LongInt(P
);
1899 gFlags
[Fl
].Obj
.Y
:= e_Raw_Read_LongInt(P
);
1900 gFlags
[Fl
].Obj
.Vel
.X
:= e_Raw_Read_LongInt(P
);
1901 gFlags
[Fl
].Obj
.Vel
.Y
:= e_Raw_Read_LongInt(P
);
1903 Pl
:= g_Player_Get(PID
);
1905 (EvType
<> FLAG_STATE_NORMAL
) and
1906 (EvType
<> FLAG_STATE_DROPPED
) and
1907 (EvType
<> FLAG_STATE_RETURNED
) then
1913 if Quiet
or (Pl
= nil) then Exit
;
1915 if Fl
= FLAG_RED
then
1916 s
:= _lc
[I_PLAYER_FLAG_RED
]
1918 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1920 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1923 FLAG_STATE_CAPTURED
:
1925 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1929 if Fl
= FLAG_RED
then
1930 s
:= _lc
[I_PLAYER_FLAG_RED
]
1932 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1934 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1935 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1940 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1942 if Quiet
or (Pl
= nil) then Exit
;
1944 if Fl
= FLAG_RED
then
1945 s
:= _lc
[I_PLAYER_FLAG_RED
]
1947 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1949 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1950 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1955 g_Map_ResetFlag(FLAG_RED
);
1956 g_Map_ResetFlag(FLAG_BLUE
);
1957 if Quiet
or (Pl
= nil) then Exit
;
1958 Pl
.SetFlag(FLAG_NONE
);
1960 if Fl
= FLAG_RED
then
1961 s
:= _lc
[I_PLAYER_FLAG_RED
]
1963 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1965 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1966 Insert('.', ts
, Length(ts
) + 1 - 3);
1967 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1968 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1971 FLAG_STATE_RETURNED
:
1973 g_Map_ResetFlag(Fl
);
1976 if Fl
= FLAG_RED
then
1977 s
:= _lc
[I_PLAYER_FLAG_RED
]
1979 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1981 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1986 procedure MC_RECV_GameSettings(P
: Pointer);
1988 gGameSettings
.GameMode
:= e_Raw_Read_Byte(P
);
1989 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(P
);
1990 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(P
);
1991 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(P
);
1992 gGameSettings
.Options
:= e_Raw_Read_LongWord(P
);
1997 function MC_RECV_PlayerCreate(P
: Pointer): Word;
2000 PName
, Model
: string;
2005 PID
:= e_Raw_Read_Word(P
);
2006 Pl
:= g_Player_Get(PID
);
2008 PName
:= e_Raw_Read_String(P
);
2009 Model
:= e_Raw_Read_String(P
);
2010 Color
.R
:= e_Raw_Read_Byte(P
);
2011 Color
.G
:= e_Raw_Read_Byte(P
);
2012 Color
.B
:= e_Raw_Read_Byte(P
);
2013 T
:= e_Raw_Read_Byte(P
);
2016 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2018 if (Pl
<> nil) then Exit
;
2019 DID
:= g_Player_Create(Model
, Color
, T
, False);
2020 with g_Player_Get(DID
) do
2029 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2030 gPlayer1
.UID
:= PID
;
2031 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2032 gPlayer1
.ChangeTeam(T
);
2034 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2035 gPlayer2
.UID
:= PID
;
2036 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2037 gPlayer2
.ChangeTeam(T
);
2041 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2042 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', MSG_NOTIFY
);
2046 function MC_RECV_PlayerPos(P
: Pointer): Word;
2053 TmpX
, TmpY
: Integer;
2057 GT
:= e_Raw_Read_LongWord(P
);
2058 if GT
< gTime
- NET_MAX_DIFFTIME
then
2065 PID
:= e_Raw_Read_Word(P
);
2066 Pl
:= g_Player_Get(PID
);
2068 if Pl
= nil then Exit
;
2074 FPing
:= e_Raw_Read_Word(P
);
2075 FLoss
:= e_Raw_Read_Byte(P
);
2076 kByte
:= e_Raw_Read_Word(P
);
2077 Dir
:= e_Raw_Read_Byte(P
);
2079 TmpX
:= e_Raw_Read_LongInt(P
);
2080 TmpY
:= e_Raw_Read_LongInt(P
);
2084 if (kByte
= NET_KEY_CHAT
) then
2085 PressKey(KEY_CHAT
, 10000)
2088 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2089 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2090 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2091 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2092 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2095 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2096 SetDirection(TDirection(Dir
));
2098 GameVelX
:= e_Raw_Read_LongInt(P
);
2099 GameVelY
:= e_Raw_Read_LongInt(P
);
2100 GameAccelX
:= e_Raw_Read_LongInt(P
);
2101 GameAccelY
:= e_Raw_Read_LongInt(P
);
2102 SetLerp(TmpX
, TmpY
);
2103 if NetForcePlayerUpdate
then Update();
2107 function MC_RECV_PlayerStats(P
: Pointer): Word;
2115 PID
:= e_Raw_Read_Word(P
);
2116 Pl
:= g_Player_Get(PID
);
2123 Live
:= (e_Raw_Read_Byte(P
) <> 0);
2124 GodMode
:= (e_Raw_Read_Byte(P
) <> 0);
2125 Health
:= e_Raw_Read_LongInt(P
);
2126 Armor
:= e_Raw_Read_LongInt(P
);
2127 Air
:= e_Raw_Read_LongInt(P
);
2128 JetFuel
:= e_Raw_Read_LongInt(P
);
2129 Lives
:= e_Raw_Read_Byte(P
);
2130 NewTeam
:= e_Raw_Read_Byte(P
);
2132 for I
:= WP_FIRST
to WP_LAST
do
2133 FWeapon
[I
] := (e_Raw_Read_Byte(P
) <> 0);
2135 for I
:= A_BULLETS
to A_HIGH
do
2136 FAmmo
[I
] := e_Raw_Read_Word(P
);
2138 for I
:= A_BULLETS
to A_HIGH
do
2139 FMaxAmmo
[I
] := e_Raw_Read_Word(P
);
2141 for I
:= MR_SUIT
to MR_MAX
do
2142 FMegaRulez
[I
] := e_Raw_Read_LongWord(P
);
2145 if (e_Raw_Read_Byte(P
) <> 0) then
2146 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2147 if (e_Raw_Read_Byte(P
) <> 0) then
2148 FRulez
:= FRulez
+ [R_KEY_RED
];
2149 if (e_Raw_Read_Byte(P
) <> 0) then
2150 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2151 if (e_Raw_Read_Byte(P
) <> 0) then
2152 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2153 if (e_Raw_Read_Byte(P
) <> 0) then
2154 FRulez
:= FRulez
+ [R_BERSERK
];
2156 Frags
:= e_Raw_Read_LongInt(P
);
2157 Death
:= e_Raw_Read_LongInt(P
);
2159 SetWeapon(e_Raw_Read_Byte(P
));
2161 FSpectator
:= e_Raw_Read_Byte(P
) <> 0;
2164 if Pl
= gPlayer1
then
2169 if Pl
= gPlayer2
then
2177 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2178 gPlayer1
:= g_Player_Get(gLMSPID1
);
2179 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2180 gPlayer2
:= g_Player_Get(gLMSPID2
);
2182 FGhost
:= e_Raw_Read_Byte(P
) <> 0;
2183 FPhysics
:= e_Raw_Read_Byte(P
) <> 0;
2184 FNoRespawn
:= e_Raw_Read_Byte(P
) <> 0;
2186 FJetpack
:= e_Raw_Read_Byte(P
) <> 0;
2187 FFireTime
:= e_Raw_Read_LongInt(P
);
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(P
: Pointer): Word;
2204 Attacker
, Value
: Word;
2208 if not gGameOn
then Exit
;
2209 PID
:= e_Raw_Read_Word(P
);
2210 Pl
:= g_Player_Get(PID
);
2211 if Pl
= nil then Exit
;
2213 Kind
:= e_Raw_Read_Byte(P
);
2214 Attacker
:= e_Raw_Read_Word(P
);
2215 Value
:= e_Raw_Read_Word(P
);
2216 VX
:= e_Raw_Read_Word(P
);
2217 VY
:= e_Raw_Read_Word(P
);
2220 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2225 function MC_RECV_PlayerDeath(P
: Pointer): Word;
2229 KillType
, DeathType
: Byte;
2233 if not gGameOn
then Exit
;
2234 PID
:= e_Raw_Read_Word(P
);
2235 Pl
:= g_Player_Get(PID
);
2236 if Pl
= nil then Exit
;
2238 KillType
:= e_Raw_Read_Byte(P
);
2239 DeathType
:= e_Raw_Read_Byte(P
);
2240 Attacker
:= e_Raw_Read_Word(P
);
2244 Kill(KillType
, Attacker
, DeathType
);
2249 function MC_RECV_PlayerDelete(P
: Pointer): Word;
2254 PID
:= e_Raw_Read_Word(P
);
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.', MSG_NOTIFY
);
2262 g_Player_Remove(PID
);
2267 function MC_RECV_PlayerFire(P
: Pointer): Word;
2272 X
, Y
, AX
, AY
: Integer;
2276 if not gGameOn
then Exit
;
2277 PID
:= e_Raw_Read_Word(P
);
2278 Pl
:= g_Player_Get(PID
);
2279 if Pl
= nil then Exit
;
2281 Weap
:= e_Raw_Read_Byte(P
);
2282 X
:= e_Raw_Read_LongInt(P
);
2283 Y
:= e_Raw_Read_LongInt(P
);
2284 AX
:= e_Raw_Read_LongInt(P
);
2285 AY
:= e_Raw_Read_LongInt(P
);
2286 SHID
:= e_Raw_Read_LongInt(P
);
2289 if Live
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2292 procedure MC_RECV_PlayerSettings(P
: Pointer);
2301 PID
:= e_Raw_Read_Word(P
);
2302 Pl
:= g_Player_Get(PID
);
2303 if Pl
= nil then Exit
;
2305 TmpName
:= e_Raw_Read_String(P
);
2306 TmpModel
:= e_Raw_Read_String(P
);
2307 TmpColor
.R
:= e_Raw_Read_Byte(P
);
2308 TmpColor
.G
:= e_Raw_Read_Byte(P
);
2309 TmpColor
.B
:= e_Raw_Read_Byte(P
);
2310 TmpTeam
:= e_Raw_Read_Byte(P
);
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(P
: Pointer);
2338 X
, Y
, VX
, VY
: Integer;
2340 Quiet
, Fall
{, Resp}: Boolean;
2343 if not gGameOn
then Exit
;
2344 ID
:= e_Raw_Read_Word(P
);
2345 Quiet
:= e_Raw_Read_Byte(P
) <> 0;
2346 T
:= e_Raw_Read_Byte(P
);
2347 Fall
:= e_Raw_Read_Byte(P
) <> 0;
2348 {Resp :=} e_Raw_Read_Byte(P
);
2349 X
:= e_Raw_Read_LongInt(P
);
2350 Y
:= e_Raw_Read_LongInt(P
);
2351 VX
:= e_Raw_Read_LongInt(P
);
2352 VY
:= e_Raw_Read_LongInt(P
);
2354 g_Items_Create(X
, Y
, T
, Fall
, False, False, ID
);
2355 gItems
[ID
].Obj
.Vel
.X
:= VX
;
2356 gItems
[ID
].Obj
.Vel
.Y
:= VY
;
2360 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2361 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2363 Anim
:= TAnimation
.Create(AID
, False, 4);
2364 g_GFX_OnceAnim(X
+(gItems
[ID
].Obj
.Rect
.Width
div 2)-16, Y
+(gItems
[ID
].Obj
.Rect
.Height
div 2)-16, Anim
);
2370 procedure MC_RECV_ItemDestroy(P
: Pointer);
2375 if not gGameOn
then Exit
;
2376 ID
:= e_Raw_Read_Word(P
);
2377 Quiet
:= e_Raw_Read_Byte(P
) <> 0;
2378 if gItems
= nil then Exit
;
2379 if (ID
> High(gItems
)) then Exit
;
2382 if gSoundEffectsDF
then
2384 if gItems
[ID
].ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_INVUL
,
2385 ITEM_INVIS
, ITEM_MEDKIT_BLACK
, ITEM_JETPACK
] then
2386 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2387 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2389 if gItems
[ID
].ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
2390 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
2391 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
, ITEM_WEAPON_FLAMETHROWER
,
2392 ITEM_AMMO_BACKPACK
] then
2393 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2394 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2396 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2397 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
);
2401 if gItems
[ID
].ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_SUIT
,
2402 ITEM_MEDKIT_BLACK
, ITEM_INVUL
, ITEM_INVIS
, ITEM_JETPACK
] then
2403 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2404 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2406 if gItems
[ID
].ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
2407 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
2408 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
, ITEM_WEAPON_FLAMETHROWER
] then
2409 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2410 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2412 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2413 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
);
2421 procedure MC_RECV_PanelTexture(P
: Pointer);
2429 if not gGameOn
then Exit
;
2430 PType
:= e_Raw_Read_Word(P
);
2431 ID
:= e_Raw_Read_LongWord(P
);
2432 Tex
:= e_Raw_Read_LongInt(P
);
2433 Fr
:= e_Raw_Read_LongInt(P
);
2434 Cnt
:= e_Raw_Read_Byte(P
);
2435 Loop
:= e_Raw_Read_Byte(P
);
2440 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2441 if gWalls
<> nil then
2444 if gRenderForegrounds
<> nil then
2445 TP
:= gRenderForegrounds
[ID
];
2447 if gRenderBackgrounds
<> nil then
2448 TP
:= gRenderBackgrounds
[ID
];
2450 if gWater
<> nil then
2453 if gAcid1
<> nil then
2456 if gAcid2
<> nil then
2459 if gSteps
<> nil then
2467 begin // switch texture
2468 TP
.SetTexture(Tex
, Loop
);
2469 TP
.SetFrame(Fr
, Cnt
);
2470 end else // looped or non-looped animation
2471 TP
.NextTexture(Loop
);
2474 procedure MC_RECV_PanelState(P
: Pointer);
2482 if not gGameOn
then Exit
;
2483 PType
:= e_Raw_Read_Word(P
);
2484 ID
:= e_Raw_Read_LongWord(P
);
2485 E
:= (e_Raw_Read_Byte(P
) <> 0);
2486 Lift
:= e_Raw_Read_Byte(P
);
2487 X
:= e_Raw_Read_LongInt(P
);
2488 Y
:= e_Raw_Read_LongInt(P
);
2491 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2493 g_Map_EnableWall(ID
)
2495 g_Map_DisableWall(ID
);
2497 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
2498 g_Map_SetLift(ID
, Lift
);
2502 gRenderBackgrounds
[ID
].X
:= X
;
2503 gRenderBackgrounds
[ID
].Y
:= Y
;
2508 gRenderForegrounds
[ID
].X
:= X
;
2509 gRenderForegrounds
[ID
].Y
:= Y
;
2516 procedure MC_RECV_TriggerSound(P
: Pointer);
2519 SPos
, SID
: LongWord;
2523 if not gGameOn
then Exit
;
2524 if gTriggers
= nil then Exit
;
2526 SID
:= e_Raw_Read_LongWord(P
);
2527 SPlaying
:= e_Raw_Read_Byte(P
) <> 0;
2528 SPos
:= e_Raw_Read_LongWord(P
);
2529 SCount
:= e_Raw_Read_LongInt(P
);
2531 for I
:= Low(gTriggers
) to High(gTriggers
) do
2532 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2533 if gTriggers
[I
].ClientID
= SID
then
2534 with gTriggers
[I
] do
2539 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0)
2541 Sound
.PlayPanVolume((Data
.Pan
-127.0)/128.0, Data
.Volume
/255.0);
2542 Sound
.SetPosition(SPos
);
2545 if Sound
.IsPlaying
then Sound
.Stop
;
2547 SoundPlayCount
:= SCount
;
2551 procedure MC_RECV_TriggerMusic(P
: Pointer);
2558 if not gGameOn
then Exit
;
2560 MName
:= e_Raw_Read_String(P
);
2561 MPlaying
:= e_Raw_Read_Byte(P
) <> 0;
2562 MPos
:= e_Raw_Read_LongWord(P
);
2563 MPaused
:= e_Raw_Read_Byte(P
) <> 0;
2567 gMusic
.SetByName(MName
);
2569 gMusic
.SetPosition(MPos
);
2570 gMusic
.SpecPause
:= MPaused
;
2573 if gMusic
.IsPlaying
then gMusic
.Stop
;
2578 procedure MC_RECV_MonsterSpawn(P
: Pointer);
2581 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2582 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2586 ID
:= e_Raw_Read_Word(P
);
2587 M
:= g_Monsters_Get(ID
);
2591 MType
:= e_Raw_Read_Byte(P
);
2592 MState
:= e_Raw_Read_Byte(P
);
2593 MAnim
:= e_Raw_Read_Byte(P
);
2594 MTarg
:= e_Raw_Read_Word(P
);
2595 MTargTime
:= e_Raw_Read_LongInt(P
);
2596 MBehav
:= e_Raw_Read_Byte(P
);
2597 MSleep
:= e_Raw_Read_LongInt(P
);
2598 MHealth
:= e_Raw_Read_LongInt(P
);
2599 MAmmo
:= e_Raw_Read_LongInt(P
);
2601 X
:= e_Raw_Read_LongInt(P
);
2602 Y
:= e_Raw_Read_LongInt(P
);
2603 VX
:= e_Raw_Read_LongInt(P
);
2604 VY
:= e_Raw_Read_LongInt(P
);
2605 MDir
:= e_Raw_Read_Byte(P
);
2607 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2608 M
:= g_Monsters_Get(ID
);
2619 MonsterAnim
:= MAnim
;
2620 MonsterTargetUID
:= MTarg
;
2621 MonsterTargetTime
:= MTargTime
;
2622 MonsterBehaviour
:= MBehav
;
2623 MonsterSleep
:= MSleep
;
2624 MonsterAmmo
:= MAmmo
;
2631 procedure MC_RECV_MonsterPos(P
: Pointer);
2636 ID
:= e_Raw_Read_Word(P
);
2637 M
:= g_Monsters_Get(ID
);
2643 GameX
:= e_Raw_Read_LongInt(P
);
2644 GameY
:= e_Raw_Read_LongInt(P
);
2645 GameVelX
:= e_Raw_Read_LongInt(P
);
2646 GameVelY
:= e_Raw_Read_LongInt(P
);
2647 GameDirection
:= TDirection(e_Raw_Read_Byte(P
));
2651 procedure MC_RECV_MonsterState(P
: Pointer);
2654 MState
, MFAnm
: Byte;
2656 AnimRevert
: Boolean;
2658 ID
:= e_Raw_Read_Word(P
);
2659 M
:= g_Monsters_Get(ID
);
2660 if M
= nil then Exit
;
2662 MState
:= e_Raw_Read_Byte(P
);
2663 MFAnm
:= e_Raw_Read_Byte(P
);
2667 MonsterTargetUID
:= e_Raw_Read_Word(P
);
2668 MonsterTargetTime
:= e_Raw_Read_LongInt(P
);
2669 MonsterSleep
:= e_Raw_Read_LongInt(P
);
2670 MonsterHealth
:= e_Raw_Read_LongInt(P
);
2671 MonsterAmmo
:= e_Raw_Read_LongInt(P
);
2672 MonsterPain
:= e_Raw_Read_LongInt(P
);
2673 AnimRevert
:= e_Raw_Read_Byte(P
) <> 0;
2674 FFireTime
:= e_Raw_Read_LongInt(P
);
2675 RevertAnim(AnimRevert
);
2677 if MonsterState
<> MState
then
2679 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then
2681 if (MState
= MONSTATE_DIE
) then
2683 if (MState
= MONSTATE_PAIN
) then
2684 MakeBloodSimple(Min(200, MonsterPain
));
2685 if (MState
= MONSTATE_ATTACK
) then
2687 if (MState
= MONSTATE_DEAD
) then
2690 SetState(MState
, MFAnm
);
2695 procedure MC_RECV_MonsterShot(P
: Pointer);
2699 X
, Y
, VX
, VY
: Integer;
2701 ID
:= e_Raw_Read_Word(P
);
2703 M
:= g_Monsters_Get(ID
);
2704 if M
= nil then Exit
;
2706 X
:= e_Raw_Read_LongInt(P
);
2707 Y
:= e_Raw_Read_LongInt(P
);
2708 VX
:= e_Raw_Read_LongInt(P
);
2709 VY
:= e_Raw_Read_LongInt(P
);
2711 M
.ClientAttack(X
, Y
, VX
, VY
);
2714 procedure MC_RECV_MonsterDelete(P
: Pointer);
2719 ID
:= e_Raw_Read_Word(P
);
2720 M
:= g_Monsters_Get(ID
);
2721 if M
= nil then Exit
;
2723 gMonsters
[ID
].SetState(5);
2724 gMonsters
[ID
].MonsterRemoved
:= True;
2727 procedure MC_RECV_TimeSync(P
: Pointer);
2731 Time
:= e_Raw_Read_LongWord(P
);
2733 if gState
= STATE_INTERCUSTOM
then
2734 gServInterTime
:= Min(Time
, 255);
2737 procedure MC_RECV_VoteEvent(P
: Pointer);
2741 Int1
, Int2
: SmallInt;
2743 EvID
:= e_Raw_Read_Byte(P
);
2744 Int1
:= e_Raw_Read_SmallInt(P
);
2745 Int2
:= e_Raw_Read_SmallInt(P
);
2746 Str1
:= e_Raw_Read_String(P
);
2747 Str2
:= e_Raw_Read_String(P
);
2751 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2753 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2755 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2757 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2759 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2765 procedure MC_SEND_Info(Password
: string);
2767 e_Buffer_Clear(@NetOut
);
2769 e_Buffer_Write(@NetOut
, Byte(NET_MSG_INFO
));
2770 e_Buffer_Write(@NetOut
, GAME_VERSION
);
2771 e_Buffer_Write(@NetOut
, Password
);
2772 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Name
);
2773 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Model
);
2774 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.R
);
2775 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.G
);
2776 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.B
);
2777 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Team
);
2779 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2780 g_Net_Flush(); // send immediately, there's no frames yet
2783 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2785 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
2786 e_Buffer_Write(@NetOut
, Txt
);
2787 e_Buffer_Write(@NetOut
, Mode
);
2789 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2792 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
2794 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
2795 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
2799 procedure MC_SEND_PlayerPos();
2804 WeaponSelect
: Word = 0;
2807 if not gGameOn
then Exit
;
2808 if gPlayers
= nil then Exit
;
2809 if gPlayer1
= nil then Exit
;
2812 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2814 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2816 strafeDir
:= P1MoveButton
shr 4;
2817 P1MoveButton
:= P1MoveButton
and $0F;
2818 with gGameControls
.P1Control
do
2820 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 1
2821 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then P1MoveButton
:= 2
2822 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then P1MoveButton
:= 0;
2825 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
2827 // new strafe mechanics
2828 if (strafeDir
= 0) then strafeDir
:= P1MoveButton
; // start strafing
2829 // now set direction according to strafe (reversed)
2830 if (strafeDir
= 2) then gPlayer1
.SetDirection(D_LEFT
)
2831 else if (strafeDir
= 1) then gPlayer1
.SetDirection(D_RIGHT
);
2835 if (P1MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then gPlayer1
.SetDirection(D_LEFT
)
2836 else if (P1MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then gPlayer1
.SetDirection(D_RIGHT
)
2837 else if P1MoveButton
<> 0 then gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2840 gPlayer1
.ReleaseKeys
;
2841 if P1MoveButton
= 1 then
2843 kByte
:= kByte
or NET_KEY_LEFT
;
2844 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2846 if P1MoveButton
= 2 then
2848 kByte
:= kByte
or NET_KEY_RIGHT
;
2849 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2851 if isKeyPressed(KeyUp
, KeyUp2
) then
2853 kByte
:= kByte
or NET_KEY_UP
;
2854 gPlayer1
.PressKey(KEY_UP
, 10000);
2856 if isKeyPressed(KeyDown
, KeyDown2
) then
2858 kByte
:= kByte
or NET_KEY_DOWN
;
2859 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2861 if isKeyPressed(KeyJump
, KeyJump2
) then
2863 kByte
:= kByte
or NET_KEY_JUMP
;
2864 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2866 if isKeyPressed(KeyFire
, KeyFire2
) then kByte
:= kByte
or NET_KEY_FIRE
;
2867 if isKeyPressed(KeyOpen
, KeyOpen2
) then kByte
:= kByte
or NET_KEY_OPEN
;
2868 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then kByte
:= kByte
or NET_KEY_NW
;
2869 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then kByte
:= kByte
or NET_KEY_PW
;
2870 for I
:= 0 to High(KeyWeapon
) do
2871 if isKeyPressed(KeyWeapon
[I
], KeyWeapon2
[I
]) then
2872 WeaponSelect
:= WeaponSelect
or Word(1 shl I
);
2874 // fix movebutton state
2875 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2878 kByte
:= NET_KEY_CHAT
;
2880 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRPOS
));
2881 e_Buffer_Write(@NetOut
, gTime
);
2882 e_Buffer_Write(@NetOut
, kByte
);
2883 e_Buffer_Write(@NetOut
, Byte(gPlayer1
.Direction
));
2884 e_Buffer_Write(@NetOut
, WeaponSelect
);
2885 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2886 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2888 //kBytePrev := kByte;
2889 //kDirPrev := gPlayer1.Direction;
2892 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2894 e_Buffer_Write(@NetOut
, Byte(NET_MSG_VOTE_EVENT
));
2895 e_Buffer_Write(@NetOut
, Byte(Start
));
2896 e_Buffer_Write(@NetOut
, Command
);
2897 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2900 procedure MC_SEND_PlayerSettings();
2902 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSET
));
2903 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Name
);
2904 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Model
);
2905 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.R
);
2906 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.G
);
2907 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.B
);
2908 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Team
);
2910 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2913 procedure MC_SEND_FullStateRequest();
2915 e_Buffer_Write(@NetOut
, Byte(NET_MSG_REQFST
));
2917 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2918 g_Net_Flush(); // send immediately, because loading
2921 procedure MC_SEND_CheatRequest(Kind
: Byte);
2923 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHEAT
));
2924 e_Buffer_Write(@NetOut
, Kind
);
2926 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2928 procedure MC_SEND_RCONPassword(Password
: string);
2930 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RCON_AUTH
));
2931 e_Buffer_Write(@NetOut
, Password
);
2933 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2935 procedure MC_SEND_RCONCommand(Cmd
: string);
2937 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RCON_CMD
));
2938 e_Buffer_Write(@NetOut
, Cmd
);
2940 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2943 // i have no idea why all this stuff is in here
2945 function ReadFile(const FileName
: TFileName
): AByte
;
2947 FileStream
: TStream
;
2950 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), MSG_NOTIFY
);
2951 fname
:= findDiskWad(FileName
);
2952 if length(fname
) = 0 then
2954 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), MSG_FATALERROR
);
2955 SetLength(Result
, 0);
2958 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), MSG_NOTIFY
);
2960 FileStream
:= openDiskFileRO(fname
);
2962 if FileStream
.Size
> 0 then
2964 SetLength(Result
, FileStream
.Size
);
2965 FileStream
.Read(Result
[0], FileStream
.Size
);
2972 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
2976 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
2977 Result
.FileData
:= ReadFile(FileName
);
2978 Result
.FileSize
:= Length(Result
.FileData
);
2980 SetLength(Result
.ExternalResources
, ResList
.Count
);
2981 for i
:=0 to ResList
.Count
-1 do
2983 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
2984 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
2988 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
2990 ResultStream
: TMemoryStream
;
2991 dummy
: Word = $FFFE;
2993 ResultStream
:= TMemoryStream
.Create
;
2995 ResultStream
.WriteBuffer(dummy
, 2); //dummy length
2996 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
2997 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
2998 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
3000 SetLength(bytes
, ResultStream
.Size
);
3001 ResultStream
.Seek(0, soFromBeginning
);
3002 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3007 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
3009 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3010 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
3011 SetLength(Result
.FileData
, Result
.FileSize
);
3012 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
3015 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
3017 ResultStream
: TMemoryStream
;
3019 dummy
: Word = $FFFF;
3021 resCount
:= Length(MapDataMsg
.ExternalResources
);
3023 ResultStream
:= TMemoryStream
.Create
;
3025 ResultStream
.WriteBuffer(dummy
, 2); //dummy length
3026 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
3027 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
3028 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
3030 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
3031 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
3033 SetLength(bytes
, ResultStream
.Size
);
3034 ResultStream
.Seek(0, soFromBeginning
);
3035 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3040 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
3044 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3045 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3047 SetLength(Result
.FileData
, Result
.FileSize
);
3048 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3050 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3051 SetLength(Result
.ExternalResources
, resCount
);
3053 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3056 function IsValidFileName(const S
: String): Boolean;
3058 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3063 for I
:= 1 to Length(S
) do
3064 Result
:= Result
and (not(S
[I
] in Forbidden
));
3067 function IsValidFilePath(const S
: String): Boolean;
3072 if not IsValidFileName(S
) then exit
;
3073 if FileExists(S
) then exit
;
3074 I
:= LastDelimiter('\/', S
);
3076 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3081 procedure MC_SEND_MapRequest();
3083 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MAP_REQUEST
));
3084 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3087 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3089 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RES_REQUEST
));
3090 e_Buffer_Write(@NetOut
, resName
);
3091 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3094 procedure MH_RECV_MapRequest(C
: pTNetClient
; P
: Pointer);
3098 mapDataMsg
: TMapDataMsg
;
3100 e_WriteLog('NET: Received map request from ' +
3101 DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3103 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3104 peer
:= NetClients
[C
.ID
].Peer
;
3106 MapDataMsgToBytes(payload
, mapDataMsg
);
3107 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3110 mapDataMsg
.FileData
:= nil;
3111 mapDataMsg
.ExternalResources
:= nil;
3114 procedure MH_RECV_ResRequest(C
: pTNetClient
; P
: Pointer);
3119 resDataMsg
: TResDataMsg
;
3121 FileName
:= ExtractFileName(e_Raw_Read_String(P
));
3122 e_WriteLog('NET: Received res request: ' + FileName
+
3123 ' from ' + DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3125 if not IsValidFilePath(FileName
) then
3127 e_WriteLog('Invalid filename: ' + FileName
, MSG_WARNING
);
3131 peer
:= NetClients
[C
.ID
].Peer
;
3133 if gExternalResources
.IndexOf(FileName
) > -1 then
3135 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3136 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3137 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3139 ResDataMsgToBytes(payload
, resDataMsg
);
3140 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);