6 uses g_net
, g_triggers
, Classes
, SysUtils
, md5
;
52 NET_MSG_RCON_AUTH
= 191;
53 NET_MSG_RCON_CMD
= 192;
54 NET_MSG_TIME_SYNC
= 194;
55 NET_MSG_VOTE_EVENT
= 195;
57 NET_MSG_MAP_REQUEST
= 201;
58 NET_MSG_MAP_RESPONSE
= 202;
59 NET_MSG_RES_REQUEST
= 203;
60 NET_MSG_RES_RESPONSE
= 204;
83 NET_EV_CHANGE_TEAM
= 3;
84 NET_EV_PLAYER_KICK
= 4;
85 NET_EV_PLAYER_BAN
= 5;
86 NET_EV_LMS_WARMUP
= 6;
87 NET_EV_LMS_SURVIVOR
= 7;
91 NET_EV_SCORE_MSG
= 11;
92 NET_EV_LMS_START
= 12;
97 NET_EV_KILLCOMBO
= 17;
98 NET_EV_PLAYER_TOUCH
= 18;
105 NET_VE_INPROGRESS
= 6;
112 NET_CHEAT_SUICIDE
= 1;
113 NET_CHEAT_SPECTATE
= 2;
115 NET_MAX_DIFFTIME
= 5000 div 36;
119 procedure MH_RECV_Info(C
: pTNetClient
; P
: Pointer);
120 procedure MH_RECV_Chat(C
: pTNetClient
; P
: Pointer);
121 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; P
: Pointer);
122 function MH_RECV_PlayerPos(C
: pTNetClient
; P
: Pointer): Word;
123 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; P
: Pointer);
124 procedure MH_RECV_CheatRequest(C
: pTNetClient
; P
: Pointer);
125 procedure MH_RECV_RCONPassword(C
: pTNetClient
; P
: Pointer);
126 procedure MH_RECV_RCONCommand(C
: pTNetClient
; P
: Pointer);
127 procedure MH_RECV_MapRequest(C
: pTNetClient
; P
: Pointer);
128 procedure MH_RECV_ResRequest(C
: pTNetClient
; P
: Pointer);
129 procedure MH_RECV_Vote(C
: pTNetClient
; P
: Pointer);
132 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
133 procedure MH_SEND_Info(ID
: Byte);
134 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
135 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
136 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; ID
: Integer = NET_EVERYONE
);
137 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
138 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
139 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
140 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
141 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
142 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
143 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
144 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
146 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
147 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
148 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
149 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
150 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
151 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
152 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
153 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_PanelTexture(PType
: Word; PID
: LongWord; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_PanelState(PType
: Word; PID
: LongWord; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
170 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_VoteEvent(EvType
: Byte;
172 StrArg1
: string = 'a'; StrArg2
: string = 'b';
173 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
174 ID
: Integer = NET_EVERYONE
);
176 // CLIENT MESSAGES //
179 procedure MC_RECV_Chat(P
: Pointer);
180 procedure MC_RECV_Effect(P
: Pointer);
181 procedure MC_RECV_Sound(P
: Pointer);
182 procedure MC_RECV_GameStats(P
: Pointer);
183 procedure MC_RECV_CoopStats(P
: Pointer);
184 procedure MC_RECV_GameEvent(P
: Pointer);
185 procedure MC_RECV_FlagEvent(P
: Pointer);
186 procedure MC_RECV_GameSettings(P
: Pointer);
188 function MC_RECV_PlayerCreate(P
: Pointer): Word;
189 function MC_RECV_PlayerPos(P
: Pointer): Word;
190 function MC_RECV_PlayerStats(P
: Pointer): Word;
191 function MC_RECV_PlayerDelete(P
: Pointer): Word;
192 function MC_RECV_PlayerDamage(P
: Pointer): Word;
193 function MC_RECV_PlayerDeath(P
: Pointer): Word;
194 function MC_RECV_PlayerFire(P
: Pointer): Word;
195 procedure MC_RECV_PlayerSettings(P
: Pointer);
197 procedure MC_RECV_ItemSpawn(P
: Pointer);
198 procedure MC_RECV_ItemDestroy(P
: Pointer);
200 procedure MC_RECV_PanelTexture(P
: Pointer);
201 procedure MC_RECV_PanelState(P
: Pointer);
203 procedure MC_RECV_MonsterSpawn(P
: Pointer);
204 procedure MC_RECV_MonsterPos(P
: Pointer);
205 procedure MC_RECV_MonsterState(P
: Pointer);
206 procedure MC_RECV_MonsterShot(P
: Pointer);
207 procedure MC_RECV_MonsterDelete(P
: Pointer);
209 procedure MC_RECV_CreateShot(P
: Pointer);
210 procedure MC_RECV_UpdateShot(P
: Pointer);
211 procedure MC_RECV_DeleteShot(P
: Pointer);
213 procedure MC_RECV_TriggerSound(P
: Pointer);
214 procedure MC_RECV_TriggerMusic(P
: Pointer);
216 procedure MC_RECV_TimeSync(P
: Pointer);
217 procedure MC_RECV_VoteEvent(P
: Pointer);
219 procedure MC_SEND_Info(Password
: string);
220 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
221 procedure MC_SEND_PlayerPos();
222 procedure MC_SEND_FullStateRequest();
223 procedure MC_SEND_PlayerSettings();
224 procedure MC_SEND_CheatRequest(Kind
: Byte);
225 procedure MC_SEND_RCONPassword(Password
: string);
226 procedure MC_SEND_RCONCommand(Cmd
: string);
227 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
229 procedure MC_SEND_MapRequest();
230 procedure MC_SEND_ResRequest(const resName
: AnsiString);
233 TExternalResourceInfo
= record
248 ExternalResources
: array of TExternalResourceInfo
;
251 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
252 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
257 Math
, ENet
, e_input
, e_fixedbuffer
, e_graphics
, e_log
,
258 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
259 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
260 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
273 NET_KEY_FORCEDIR
= 4096;
276 //kBytePrev: Word = 0;
277 //kDirPrev: TDirection = D_LEFT;
278 //HostGameTime: Word = 0;
285 procedure MH_RECV_Chat(C
: pTNetClient
; P
: Pointer);
293 Pl
:= g_Player_Get(PID
);
295 Txt
:= e_Raw_Read_String(P
);
296 Mode
:= e_Raw_Read_Byte(P
);
297 if (Mode
= NET_CHAT_SYSTEM
) then
298 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
299 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
300 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
303 MH_SEND_Chat(Txt
, Mode
)
305 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
308 procedure MH_RECV_Info(C
: pTNetClient
; P
: Pointer);
310 Ver
, PName
, Model
, Pw
: string;
315 ProtoVer
, Zero
: Byte;
317 Zero
:= e_Raw_Read_Byte(P
);
318 ProtoVer
:= e_Raw_Read_Byte(P
);
319 Ver
:= e_Raw_Read_String(P
);
320 Pw
:= e_Raw_Read_String(P
);
321 PName
:= e_Raw_Read_String(P
);
322 Model
:= e_Raw_Read_String(P
);
323 R
:= e_Raw_Read_Byte(P
);
324 G
:= e_Raw_Read_Byte(P
);
325 B
:= e_Raw_Read_Byte(P
);
326 T
:= e_Raw_Read_Byte(P
);
328 if (Ver
<> GAME_VERSION
) or (ProtoVer
<> NET_PROTO_VERSION
) or (Zero
<> 0) then
330 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
331 _lc
[I_NET_DISC_VERSION
]);
332 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
336 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
338 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
340 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
341 _lc
[I_NET_DISC_BAN
]);
342 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
346 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
347 _lc
[I_NET_DISC_BAN
]);
348 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
353 if NetPassword
<> '' then
354 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
356 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
357 _lc
[I_NET_DISC_PASSWORD
]);
358 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
366 PID
:= g_Player_Create(Model
, Color
, T
, False);
367 with g_Player_Get(PID
) do
375 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
376 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
377 '] connected. Assigned player #' + IntToStr(PID
) + '.', MSG_NOTIFY
);
381 with g_Player_Get(PID
) do
385 // round in progress, don't spawn
386 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
391 FWantsInGame
:= True; // TODO: look into this later
394 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
397 for I
:= Low(NetClients
) to High(NetClients
) do
399 if NetClients
[I
].ID
= C
^.ID
then Continue
;
400 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
401 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
402 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
405 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
406 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
408 if NetUseMaster
then g_Net_Slist_Update
;
411 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; P
: Pointer);
414 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
416 C
^.RequestedFullUpdate
:= True;
421 function MH_RECV_PlayerPos(C
: pTNetClient
; P
: Pointer): Word;
430 if not gGameOn
then Exit
;
432 GT
:= e_Raw_Read_LongWord(P
);
434 Pl
:= g_Player_Get(PID
);
438 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
443 kByte
:= e_Raw_Read_Word(P
);
444 Dir
:= e_Raw_Read_Byte(P
);
445 if Direction
<> TDirection(Dir
) then
446 JustTeleported
:= False;
447 SetDirection(TDirection(Dir
));
450 if kByte
= NET_KEY_CHAT
then
452 PressKey(KEY_CHAT
, 10000);
456 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
457 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
458 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
459 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
460 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
461 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
462 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
463 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
464 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
467 // MH_SEND_PlayerPos(False, PID, C^.ID);
470 procedure MH_RECV_CheatRequest(C
: pTNetClient
; P
: Pointer);
475 Pl
:= g_Player_Get(C
^.Player
);
476 if Pl
= nil then Exit
;
478 CheatKind
:= e_Raw_Read_Byte(P
);
482 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
485 if Pl
.FSpectator
then
493 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; P
: Pointer);
501 TmpName
:= e_Raw_Read_String(P
);
502 TmpModel
:= e_Raw_Read_String(P
);
503 TmpColor
.R
:= e_Raw_Read_Byte(P
);
504 TmpColor
.G
:= e_Raw_Read_Byte(P
);
505 TmpColor
.B
:= e_Raw_Read_Byte(P
);
506 TmpTeam
:= e_Raw_Read_Byte(P
);
508 Pl
:= g_Player_Get(C
^.Player
);
509 if Pl
= nil then Exit
;
511 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
514 Pl
.SetColor(TmpColor
);
516 if Pl
.Name
<> TmpName
then
518 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
522 if TmpModel
<> Pl
.Model
.Name
then
523 Pl
.SetModel(TmpModel
);
525 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
530 procedure MH_RECV_RCONPassword(C
: pTNetClient
; P
: Pointer);
534 Pwd
:= e_Raw_Read_String(P
);
535 if not NetAllowRCON
then Exit
;
536 if Pwd
= NetRCONPassword
then
539 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
542 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
545 procedure MH_RECV_RCONCommand(C
: pTNetClient
; P
: Pointer);
549 Cmd
:= e_Raw_Read_String(P
);
550 if not NetAllowRCON
then Exit
;
551 if not C
^.RCONAuth
then
553 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
556 g_Console_Process(Cmd
);
561 procedure MH_RECV_Vote(C
: pTNetClient
; P
: Pointer);
564 Name
, Command
: string;
568 Start
:= e_Raw_Read_Byte(P
) <> 0;
569 Command
:= e_Raw_Read_String(P
);
571 Pl
:= g_Player_Get(C
^.Player
);
572 if Pl
= nil then Exit
;
577 if not g_Console_CommandBlacklisted(Command
) then
578 g_Game_StartVote(Command
, Name
);
580 else if gVoteInProgress
then
582 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
583 Need
:= Floor((NetClientCount
+1)/2.0) + 1
585 Need
:= Floor(NetClientCount
/2.0) + 1;
590 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
591 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
597 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
598 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
606 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
610 if gPlayers
<> nil then
611 for I
:= Low(gPlayers
) to High(gPlayers
) do
612 if gPlayers
[I
] <> nil then
614 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
615 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
616 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
618 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
619 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
622 if gItems
<> nil then
624 for I
:= High(gItems
) downto Low(gItems
) do
625 if gItems
[I
].Live
then
626 MH_SEND_ItemSpawn(True, I
, ID
);
629 if gMonsters
<> nil then
630 for I
:= 0 to High(gMonsters
) do
631 if gMonsters
[I
] <> nil then
632 MH_SEND_MonsterSpawn(gMonsters
[I
].UID
, ID
);
634 if gWalls
<> nil then
635 for I
:= Low(gWalls
) to High(gWalls
) do
636 if gWalls
[I
] <> nil then
640 MH_SEND_PanelState(PanelType
, I
, ID
);
642 if GetTextureCount
> 1 then
643 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
646 if gLifts
<> nil then
647 for I
:= Low(gLifts
) to High(gLifts
) do
648 if gLifts
[I
] <> nil then
650 MH_SEND_PanelState(PanelType
, I
, ID
);
652 if gRenderForegrounds
<> nil then
653 for I
:= Low(gRenderForegrounds
) to High(gRenderForegrounds
) do
654 if gRenderForegrounds
[I
] <> nil then
655 with gRenderForegrounds
[I
] do
656 if (GetTextureCount
> 1) then
657 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
658 if gRenderBackgrounds
<> nil then
659 for I
:= Low(gRenderBackgrounds
) to High(gRenderBackgrounds
) do
660 if gRenderBackgrounds
[I
] <> nil then
661 with gRenderBackgrounds
[I
] do
662 if GetTextureCount
> 1 then
663 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
664 if gWater
<> nil then
665 for I
:= Low(gWater
) to High(gWater
) do
666 if gWater
[I
] <> nil then
668 if GetTextureCount
> 1 then
669 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
670 if gAcid1
<> nil then
671 for I
:= Low(gAcid1
) to High(gAcid1
) do
672 if gAcid1
[I
] <> nil then
674 if GetTextureCount
> 1 then
675 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
676 if gAcid2
<> nil then
677 for I
:= Low(gAcid2
) to High(gAcid2
) do
678 if gAcid2
[I
] <> nil then
680 if GetTextureCount
> 1 then
681 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
682 if gSteps
<> nil then
683 for I
:= Low(gSteps
) to High(gSteps
) do
684 if gSteps
[I
] <> nil then
686 if GetTextureCount
> 1 then
687 MH_SEND_PanelTexture(PanelType
, I
, LastAnimLoop
, ID
);
689 if gTriggers
<> nil then
690 for I
:= Low(gTriggers
) to High(gTriggers
) do
691 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
692 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
695 for I
:= Low(Shots
) to High(Shots
) do
696 if Shots
[i
].ShotType
in [6, 7, 8] then
697 MH_SEND_CreateShot(i
, ID
);
699 MH_SEND_TriggerMusic(ID
);
701 MH_SEND_GameStats(ID
);
702 MH_SEND_CoopStats(ID
);
704 if gGameSettings
.GameMode
= GM_CTF
then
706 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then
707 MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
708 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then
709 MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
712 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
714 if gLMSRespawn
> LMS_RESPAWN_NONE
then
715 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
718 procedure MH_SEND_Info(ID
: Byte);
722 g_ProcessResourceStr(gMapInfo
.Map
, nil, nil, @Map
);
724 e_Buffer_Clear(@NetOut
);
726 e_Buffer_Write(@NetOut
, Byte(NET_MSG_INFO
));
727 e_Buffer_Write(@NetOut
, ID
);
728 e_Buffer_Write(@NetOut
, NetClients
[ID
].Player
);
729 e_Buffer_Write(@NetOut
, gGameSettings
.WAD
);
730 e_Buffer_Write(@NetOut
, Map
);
731 e_Buffer_Write(@NetOut
, gWADHash
);
732 e_Buffer_Write(@NetOut
, gGameSettings
.GameMode
);
733 e_Buffer_Write(@NetOut
, gGameSettings
.GoalLimit
);
734 e_Buffer_Write(@NetOut
, gGameSettings
.TimeLimit
);
735 e_Buffer_Write(@NetOut
, gGameSettings
.MaxLives
);
736 e_Buffer_Write(@NetOut
, gGameSettings
.Options
);
737 e_Buffer_Write(@NetOut
, gTime
);
739 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
742 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
748 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
749 Mode
:= NET_CHAT_PLAYER
;
752 if (Mode
= NET_CHAT_TEAM
) then
754 for i
:= Low(gPlayers
) to High(gPlayers
) do
755 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
756 (gPlayers
[i
].Team
= ID
) then
758 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
759 e_Buffer_Write(@NetOut
, Txt
);
760 e_Buffer_Write(@NetOut
, Mode
);
761 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
768 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
769 e_Buffer_Write(@NetOut
, Txt
);
770 e_Buffer_Write(@NetOut
, Mode
);
771 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
774 if Mode
= NET_CHAT_SYSTEM
then
777 if ID
= NET_EVERYONE
then
779 if Mode
= NET_CHAT_PLAYER
then
781 g_Console_Add(Txt
, True);
782 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
783 g_Sound_PlayEx('SOUND_GAME_RADIO');
786 if Mode
= NET_CHAT_TEAM
then
787 if gPlayer1
<> nil then
789 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
791 g_Console_Add(#18'[Team] '#2 + Txt
, True);
792 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
793 g_Sound_PlayEx('SOUND_GAME_RADIO');
795 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
797 g_Console_Add(#20'[Team] '#2 + Txt
, True);
798 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
799 g_Sound_PlayEx('SOUND_GAME_RADIO');
805 Name
:= g_Net_ClientName_ByID(ID
);
806 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
807 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
808 g_Sound_PlayEx('SOUND_GAME_RADIO');
812 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
814 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GFX
));
815 e_Buffer_Write(@NetOut
, Kind
);
816 e_Buffer_Write(@NetOut
, X
);
817 e_Buffer_Write(@NetOut
, Y
);
818 e_Buffer_Write(@NetOut
, Ang
);
820 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
823 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; ID
: Integer = NET_EVERYONE
);
825 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SND
));
826 e_Buffer_Write(@NetOut
, Name
);
827 e_Buffer_Write(@NetOut
, X
);
828 e_Buffer_Write(@NetOut
, Y
);
830 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
833 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
835 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
837 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHADD
));
838 e_Buffer_Write(@NetOut
, Proj
);
839 e_Buffer_Write(@NetOut
, Shots
[Proj
].ShotType
);
840 e_Buffer_Write(@NetOut
, Shots
[Proj
].Target
);
841 e_Buffer_Write(@NetOut
, Shots
[Proj
].SpawnerUID
);
842 e_Buffer_Write(@NetOut
, Shots
[Proj
].Timeout
);
843 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.X
);
844 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Y
);
845 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.X
);
846 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.Y
);
848 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
851 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
853 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
855 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHPOS
));
856 e_Buffer_Write(@NetOut
, Proj
);
857 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.X
);
858 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Y
);
859 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.X
);
860 e_Buffer_Write(@NetOut
, Shots
[Proj
].Obj
.Vel
.Y
);
862 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
865 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
867 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SHDEL
));
868 e_Buffer_Write(@NetOut
, Proj
);
869 e_Buffer_Write(@NetOut
, Byte(Loud
));
870 e_Buffer_Write(@NetOut
, X
);
871 e_Buffer_Write(@NetOut
, Y
);
873 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
876 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
878 e_Buffer_Write(@NetOut
, Byte(NET_MSG_SCORE
));
879 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
881 e_Buffer_Write(@NetOut
, gTeamStat
[TEAM_RED
].Goals
);
882 e_Buffer_Write(@NetOut
, gTeamStat
[TEAM_BLUE
].Goals
);
885 if gGameSettings
.GameMode
= GM_COOP
then
887 e_Buffer_Write(@NetOut
, gCoopMonstersKilled
);
888 e_Buffer_Write(@NetOut
, gCoopSecretsFound
);
891 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
894 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
896 e_Buffer_Write(@NetOut
, Byte(NET_MSG_COOP
));
897 e_Buffer_Write(@NetOut
, gTotalMonsters
);
898 e_Buffer_Write(@NetOut
, gSecretsCount
);
899 e_Buffer_Write(@NetOut
, gCoopTotalMonstersKilled
);
900 e_Buffer_Write(@NetOut
, gCoopTotalSecretsFound
);
901 e_Buffer_Write(@NetOut
, gCoopTotalMonsters
);
902 e_Buffer_Write(@NetOut
, gCoopTotalSecrets
);
905 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
907 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GEVENT
));
908 e_Buffer_Write(@NetOut
, EvType
);
909 e_Buffer_Write(@NetOut
, EvNum
);
910 e_Buffer_Write(@NetOut
, EvStr
);
911 e_Buffer_Write(@NetOut
, Byte(gLastMap
));
912 e_Buffer_Write(@NetOut
, gTime
);
913 if (EvType
= NET_EV_MAPSTART
) and (Pos(':\', EvStr
) > 0) then
915 e_Buffer_Write(@NetOut
, Byte(1));
916 e_Buffer_Write(@NetOut
, gWADHash
);
918 e_Buffer_Write(@NetOut
, Byte(0));
920 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
923 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
925 e_Buffer_Write(@NetOut
, Byte(NET_MSG_FLAG
));
926 e_Buffer_Write(@NetOut
, EvType
);
927 e_Buffer_Write(@NetOut
, Flag
);
928 e_Buffer_Write(@NetOut
, Byte(Quiet
));
929 e_Buffer_Write(@NetOut
, PID
);
930 e_Buffer_Write(@NetOut
, gFlags
[Flag
].State
);
931 e_Buffer_Write(@NetOut
, gFlags
[Flag
].CaptureTime
);
932 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.X
);
933 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Y
);
934 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Vel
.X
);
935 e_Buffer_Write(@NetOut
, gFlags
[Flag
].Obj
.Vel
.Y
);
937 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
940 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
942 e_Buffer_Write(@NetOut
, Byte(NET_MSG_GSET
));
943 e_Buffer_Write(@NetOut
, gGameSettings
.GameMode
);
944 e_Buffer_Write(@NetOut
, gGameSettings
.GoalLimit
);
945 e_Buffer_Write(@NetOut
, gGameSettings
.TimeLimit
);
946 e_Buffer_Write(@NetOut
, gGameSettings
.MaxLives
);
947 e_Buffer_Write(@NetOut
, gGameSettings
.Options
);
949 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
954 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
958 P
:= g_Player_Get(PID
);
959 if P
= nil then Exit
;
961 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLR
));
962 e_Buffer_Write(@NetOut
, PID
);
963 e_Buffer_Write(@NetOut
, P
.Name
);
965 e_Buffer_Write(@NetOut
, P
.FActualModelName
);
966 e_Buffer_Write(@NetOut
, P
.FColor
.R
);
967 e_Buffer_Write(@NetOut
, P
.FColor
.G
);
968 e_Buffer_Write(@NetOut
, P
.FColor
.B
);
969 e_Buffer_Write(@NetOut
, P
.Team
);
971 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
974 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
979 Pl
:= g_Player_Get(PID
);
980 if Pl
= nil then Exit
;
981 if Pl
.FDummy
then Exit
;
983 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRPOS
));
984 e_Buffer_Write(@NetOut
, gTime
);
985 e_Buffer_Write(@NetOut
, PID
);
991 e_Buffer_Write(@NetOut
, FPing
);
992 e_Buffer_Write(@NetOut
, FLoss
);
993 if IsKeyPressed(KEY_CHAT
) then
994 kByte
:= NET_KEY_CHAT
997 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
998 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
999 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1000 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1001 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1002 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1005 e_Buffer_Write(@NetOut
, kByte
);
1006 if Direction
= D_LEFT
then e_Buffer_Write(@NetOut
, Byte(0)) else e_Buffer_Write(@NetOut
, Byte(1));
1007 e_Buffer_Write(@NetOut
, GameX
);
1008 e_Buffer_Write(@NetOut
, GameY
);
1009 e_Buffer_Write(@NetOut
, GameVelX
);
1010 e_Buffer_Write(@NetOut
, GameVelY
);
1011 e_Buffer_Write(@NetOut
, GameAccelX
);
1012 e_Buffer_Write(@NetOut
, GameAccelY
);
1015 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1018 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1023 P
:= g_Player_Get(PID
);
1024 if P
= nil then Exit
;
1026 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSTA
));
1027 e_Buffer_Write(@NetOut
, PID
);
1031 e_Buffer_Write(@NetOut
, Byte(Live
));
1032 e_Buffer_Write(@NetOut
, Byte(GodMode
));
1033 e_Buffer_Write(@NetOut
, Health
);
1034 e_Buffer_Write(@NetOut
, Armor
);
1035 e_Buffer_Write(@NetOut
, Air
);
1036 e_Buffer_Write(@NetOut
, JetFuel
);
1037 e_Buffer_Write(@NetOut
, Lives
);
1038 e_Buffer_Write(@NetOut
, Team
);
1040 for I
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1041 e_Buffer_Write(@NetOut
, Byte(FWeapon
[I
]));
1043 for I
:= A_BULLETS
to A_CELLS
do
1044 e_Buffer_Write(@NetOut
, FAmmo
[I
]);
1046 for I
:= A_BULLETS
to A_CELLS
do
1047 e_Buffer_Write(@NetOut
, FMaxAmmo
[I
]);
1049 for I
:= MR_SUIT
to MR_MAX
do
1050 e_Buffer_Write(@NetOut
, LongWord(FMegaRulez
[I
]));
1052 e_Buffer_Write(@NetOut
, Byte(R_ITEM_BACKPACK
in FRulez
));
1053 e_Buffer_Write(@NetOut
, Byte(R_KEY_RED
in FRulez
));
1054 e_Buffer_Write(@NetOut
, Byte(R_KEY_GREEN
in FRulez
));
1055 e_Buffer_Write(@NetOut
, Byte(R_KEY_BLUE
in FRulez
));
1056 e_Buffer_Write(@NetOut
, Byte(R_BERSERK
in FRulez
));
1058 e_Buffer_Write(@NetOut
, Frags
);
1059 e_Buffer_Write(@NetOut
, Death
);
1061 e_Buffer_Write(@NetOut
, CurrWeap
);
1063 e_Buffer_Write(@NetOut
, Byte(FSpectator
));
1064 e_Buffer_Write(@NetOut
, Byte(FGhost
));
1065 e_Buffer_Write(@NetOut
, Byte(FPhysics
));
1066 e_Buffer_Write(@NetOut
, Byte(FNoRespawn
));
1067 e_Buffer_Write(@NetOut
, Byte(FJetpack
));
1070 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1073 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1075 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDMG
));
1076 e_Buffer_Write(@NetOut
, PID
);
1077 e_Buffer_Write(@NetOut
, Kind
);
1078 e_Buffer_Write(@NetOut
, Attacker
);
1079 e_Buffer_Write(@NetOut
, Value
);
1080 e_Buffer_Write(@NetOut
, VX
);
1081 e_Buffer_Write(@NetOut
, VY
);
1083 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1086 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1088 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDIE
));
1089 e_Buffer_Write(@NetOut
, PID
);
1090 e_Buffer_Write(@NetOut
, KillType
);
1091 e_Buffer_Write(@NetOut
, DeathType
);
1092 e_Buffer_Write(@NetOut
, Attacker
);
1094 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1097 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1099 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRFIRE
));
1100 e_Buffer_Write(@NetOut
, PID
);
1101 e_Buffer_Write(@NetOut
, Weapon
);
1102 e_Buffer_Write(@NetOut
, X
);
1103 e_Buffer_Write(@NetOut
, Y
);
1104 e_Buffer_Write(@NetOut
, AX
);
1105 e_Buffer_Write(@NetOut
, AY
);
1106 e_Buffer_Write(@NetOut
, ShotID
);
1108 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1111 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1113 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRDEL
));
1114 e_Buffer_Write(@NetOut
, PID
);
1116 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1119 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1123 Pl
:= g_Player_Get(PID
);
1124 if Pl
= nil then Exit
;
1126 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSET
));
1127 e_Buffer_Write(@NetOut
, PID
);
1128 e_Buffer_Write(@NetOut
, Pl
.Name
);
1130 e_Buffer_Write(@NetOut
, Pl
.Model
.Name
)
1132 e_Buffer_Write(@NetOut
, Mdl
);
1133 e_Buffer_Write(@NetOut
, Pl
.FColor
.R
);
1134 e_Buffer_Write(@NetOut
, Pl
.FColor
.G
);
1135 e_Buffer_Write(@NetOut
, Pl
.FColor
.B
);
1136 e_Buffer_Write(@NetOut
, Pl
.Team
);
1138 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1143 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1145 e_Buffer_Write(@NetOut
, Byte(NET_MSG_ISPAWN
));
1146 e_Buffer_Write(@NetOut
, IID
);
1147 e_Buffer_Write(@NetOut
, Byte(Quiet
));
1148 e_Buffer_Write(@NetOut
, gItems
[IID
].ItemType
);
1149 e_Buffer_Write(@NetOut
, Byte(gItems
[IID
].Fall
));
1150 e_Buffer_Write(@NetOut
, Byte(gItems
[IID
].Respawnable
));
1151 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.X
);
1152 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.Y
);
1153 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.Vel
.X
);
1154 e_Buffer_Write(@NetOut
, gItems
[IID
].Obj
.Vel
.Y
);
1156 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1159 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1161 e_Buffer_Write(@NetOut
, Byte(NET_MSG_IDEL
));
1162 e_Buffer_Write(@NetOut
, IID
);
1163 e_Buffer_Write(@NetOut
, Byte(Quiet
));
1165 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1170 procedure MH_SEND_PanelTexture(PType
: Word; PID
: LongWord; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1175 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1178 TP
:= gRenderForegrounds
[PID
];
1180 TP
:= gRenderBackgrounds
[PID
];
1195 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PTEX
));
1196 e_Buffer_Write(@NetOut
, PType
);
1197 e_Buffer_Write(@NetOut
, PID
);
1198 e_Buffer_Write(@NetOut
, FCurTexture
);
1199 e_Buffer_Write(@NetOut
, FCurFrame
);
1200 e_Buffer_Write(@NetOut
, FCurFrameCount
);
1201 e_Buffer_Write(@NetOut
, AnimLoop
);
1204 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1207 procedure MH_SEND_PanelState(PType
: Word; PID
: LongWord; ID
: Integer = NET_EVERYONE
);
1212 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1214 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
1220 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PSTATE
));
1221 e_Buffer_Write(@NetOut
, PType
);
1222 e_Buffer_Write(@NetOut
, PID
);
1223 e_Buffer_Write(@NetOut
, Byte(TP
.Enabled
));
1224 e_Buffer_Write(@NetOut
, TP
.LiftType
);
1226 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1231 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1233 if gTriggers
= nil then Exit
;
1234 if T
.Sound
= nil then Exit
;
1236 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TSOUND
));
1237 e_Buffer_Write(@NetOut
, T
.ClientID
);
1238 e_Buffer_Write(@NetOut
, Byte(T
.Sound
.IsPlaying
));
1239 e_Buffer_Write(@NetOut
, LongWord(T
.Sound
.GetPosition
));
1240 e_Buffer_Write(@NetOut
, T
.SoundPlayCount
);
1242 g_Net_Host_Send(ID
, True);
1245 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1247 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TMUSIC
));
1248 e_Buffer_Write(@NetOut
, gMusic
.Name
);
1249 e_Buffer_Write(@NetOut
, Byte(gMusic
.IsPlaying
));
1250 e_Buffer_Write(@NetOut
, LongWord(gMusic
.GetPosition
));
1251 e_Buffer_Write(@NetOut
, Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1253 g_Net_Host_Send(ID
, True);
1258 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1262 M
:= g_Monsters_Get(UID
);
1268 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSPAWN
));
1269 e_Buffer_Write(@NetOut
, UID
);
1270 e_Buffer_Write(@NetOut
, MonsterType
);
1271 e_Buffer_Write(@NetOut
, MonsterState
);
1272 e_Buffer_Write(@NetOut
, MonsterAnim
);
1273 e_Buffer_Write(@NetOut
, MonsterTargetUID
);
1274 e_Buffer_Write(@NetOut
, MonsterTargetTime
);
1275 e_Buffer_Write(@NetOut
, MonsterBehaviour
);
1276 e_Buffer_Write(@NetOut
, MonsterSleep
);
1277 e_Buffer_Write(@NetOut
, MonsterHealth
);
1278 e_Buffer_Write(@NetOut
, MonsterAmmo
);
1279 e_Buffer_Write(@NetOut
, GameX
);
1280 e_Buffer_Write(@NetOut
, GameY
);
1281 e_Buffer_Write(@NetOut
, GameVelX
);
1282 e_Buffer_Write(@NetOut
, GameVelY
);
1283 e_Buffer_Write(@NetOut
, Byte(GameDirection
));
1286 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1289 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1293 M
:= g_Monsters_Get(UID
);
1294 if M
= nil then Exit
;
1296 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MPOS
));
1297 e_Buffer_Write(@NetOut
, UID
);
1301 e_Buffer_Write(@NetOut
, GameX
);
1302 e_Buffer_Write(@NetOut
, GameY
);
1303 e_Buffer_Write(@NetOut
, GameVelX
);
1304 e_Buffer_Write(@NetOut
, GameVelY
);
1305 e_Buffer_Write(@NetOut
, Byte(GameDirection
));
1308 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1311 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1315 M
:= g_Monsters_Get(UID
);
1316 if M
= nil then Exit
;
1318 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSTATE
));
1319 e_Buffer_Write(@NetOut
, UID
);
1323 e_Buffer_Write(@NetOut
, MonsterState
);
1324 e_Buffer_Write(@NetOut
, ForcedAnim
);
1325 e_Buffer_Write(@NetOut
, MonsterTargetUID
);
1326 e_Buffer_Write(@NetOut
, MonsterTargetTime
);
1327 e_Buffer_Write(@NetOut
, MonsterSleep
);
1328 e_Buffer_Write(@NetOut
, MonsterHealth
);
1329 e_Buffer_Write(@NetOut
, MonsterAmmo
);
1330 e_Buffer_Write(@NetOut
, MonsterPain
);
1331 e_Buffer_Write(@NetOut
, Byte(AnimIsReverse
));
1334 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1337 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1339 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MSHOT
));
1340 e_Buffer_Write(@NetOut
, UID
);
1341 e_Buffer_Write(@NetOut
, X
);
1342 e_Buffer_Write(@NetOut
, Y
);
1343 e_Buffer_Write(@NetOut
, VX
);
1344 e_Buffer_Write(@NetOut
, VY
);
1346 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1349 procedure MH_SEND_MonsterDelete(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_MDEL
));
1357 e_Buffer_Write(@NetOut
, UID
);
1359 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1364 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1366 e_Buffer_Write(@NetOut
, Byte(NET_MSG_TIME_SYNC
));
1367 e_Buffer_Write(@NetOut
, Time
);
1369 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1372 procedure MH_SEND_VoteEvent(EvType
: Byte;
1373 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1374 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1375 ID
: Integer = NET_EVERYONE
);
1377 e_Buffer_Write(@NetOut
, Byte(NET_MSG_VOTE_EVENT
));
1378 e_Buffer_Write(@NetOut
, EvType
);
1379 e_Buffer_Write(@NetOut
, IntArg1
);
1380 e_Buffer_Write(@NetOut
, IntArg2
);
1381 e_Buffer_Write(@NetOut
, StrArg1
);
1382 e_Buffer_Write(@NetOut
, StrArg2
);
1384 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1387 // CLIENT MESSAGES //
1391 procedure MC_RECV_Chat(P
: Pointer);
1396 Txt
:= e_Raw_Read_String(P
);
1397 Mode
:= e_Raw_Read_Byte(P
);
1399 if Mode
<> NET_CHAT_SYSTEM
then
1401 if Mode
= NET_CHAT_PLAYER
then
1403 g_Console_Add(Txt
, True);
1404 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1405 g_Sound_PlayEx('SOUND_GAME_RADIO');
1407 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1409 if gPlayer1
.Team
= TEAM_RED
then
1410 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1411 if gPlayer1
.Team
= TEAM_BLUE
then
1412 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1413 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), MSG_NOTIFY
);
1414 g_Sound_PlayEx('SOUND_GAME_RADIO');
1417 g_Console_Add(Txt
, True);
1420 procedure MC_RECV_Effect(P
: Pointer);
1428 if not gGameOn
then Exit
;
1429 Kind
:= e_Raw_Read_Byte(P
);
1430 X
:= e_Raw_Read_LongInt(P
);
1431 Y
:= e_Raw_Read_LongInt(P
);
1432 Ang
:= e_Raw_Read_SmallInt(P
);
1436 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1440 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1442 Anim
:= TAnimation
.Create(ID
, False, 3);
1443 g_GFX_OnceAnim(X
, Y
, Anim
);
1447 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1452 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1454 Anim
:= TAnimation
.Create(ID
, False, 6);
1455 Anim
.Blending
:= False;
1456 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1460 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1465 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1467 Anim
:= TAnimation
.Create(ID
, False, 6);
1468 Anim
.Blending
:= False;
1469 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1473 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1478 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1480 Anim
:= TAnimation
.Create(ID
, False, 4);
1481 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1488 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1490 Anim
:= TAnimation
.Create(ID
, False, 4);
1491 g_GFX_OnceAnim(X
, Y
, Anim
);
1495 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1500 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1502 Anim
:= TAnimation
.Create(ID
, False, 4);
1503 g_GFX_OnceAnim(X
, Y
, Anim
);
1507 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1511 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1514 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1518 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1519 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1524 procedure MC_RECV_Sound(P
: Pointer);
1529 Name
:= e_Raw_Read_String(P
);
1530 X
:= e_Raw_Read_LongInt(P
);
1531 Y
:= e_Raw_Read_LongInt(P
);
1532 g_Sound_PlayExAt(Name
, X
, Y
);
1535 procedure MC_RECV_CreateShot(P
: Pointer);
1537 I
, X
, Y
, XV
, YV
: Integer;
1539 Target
, Spawner
: Word;
1542 I
:= e_Raw_Read_LongInt(P
);
1543 ShType
:= e_Raw_Read_Byte(P
);
1544 Target
:= e_Raw_Read_Word(P
);
1545 Spawner
:= e_Raw_Read_Word(P
);
1546 Timeout
:= e_Raw_Read_LongWord(P
);
1547 X
:= e_Raw_Read_LongInt(P
);
1548 Y
:= e_Raw_Read_LongInt(P
);
1549 XV
:= e_Raw_Read_LongInt(P
);
1550 YV
:= e_Raw_Read_LongInt(P
);
1552 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1553 if (Shots
<> nil) and (I
<= High(Shots
)) then
1555 Shots
[I
].Timeout
:= Timeout
;
1556 //Shots[I].Target := Target; // TODO: find a use for Target later
1560 procedure MC_RECV_UpdateShot(P
: Pointer);
1562 I
, TX
, TY
, TXV
, TYV
: Integer;
1564 I
:= e_Raw_Read_LongInt(P
);
1565 TX
:= e_Raw_Read_LongInt(P
);
1566 TY
:= e_Raw_Read_LongInt(P
);
1567 TXV
:= e_Raw_Read_LongInt(P
);
1568 TYV
:= e_Raw_Read_LongInt(P
);
1570 if (Shots
<> nil) and (I
<= High(Shots
)) then
1580 procedure MC_RECV_DeleteShot(P
: Pointer);
1585 if not gGameOn
then Exit
;
1586 I
:= e_Raw_Read_LongInt(P
);
1587 L
:= (e_Raw_Read_Byte(P
) <> 0);
1588 X
:= e_Raw_Read_LongInt(P
);
1589 Y
:= e_Raw_Read_LongInt(P
);
1591 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1594 procedure MC_RECV_GameStats(P
: Pointer);
1596 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1598 gTeamStat
[TEAM_RED
].Goals
:= e_Raw_Read_SmallInt(P
);
1599 gTeamStat
[TEAM_BLUE
].Goals
:= e_Raw_Read_SmallInt(P
);
1602 if gGameSettings
.GameMode
= GM_COOP
then
1604 gCoopMonstersKilled
:= e_Raw_Read_Word(P
);
1605 gCoopSecretsFound
:= e_Raw_Read_Word(P
);
1609 procedure MC_RECV_CoopStats(P
: Pointer);
1611 gTotalMonsters
:= e_Raw_Read_LongInt(P
);
1612 gSecretsCount
:= e_Raw_Read_LongInt(P
);
1613 gCoopTotalMonstersKilled
:= e_Raw_Read_Word(P
);
1614 gCoopTotalSecretsFound
:= e_Raw_Read_Word(P
);
1615 gCoopTotalMonsters
:= e_Raw_Read_Word(P
);
1616 gCoopTotalSecrets
:= e_Raw_Read_Word(P
);
1619 procedure MC_RECV_GameEvent(P
: Pointer);
1628 i1
, i2
: TStrings_Locale
;
1632 FillChar(EvHash
, Sizeof(EvHash
), 0);
1633 EvType
:= e_Raw_Read_Byte(P
);
1634 EvNum
:= e_Raw_Read_LongInt(P
);
1635 EvStr
:= e_Raw_Read_String(P
);
1636 gLastMap
:= e_Raw_Read_Byte(P
) <> 0;
1637 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1638 gStatsPressed
:= True;
1639 EvTime
:= e_Raw_Read_LongWord(P
);
1640 BHash
:= e_Raw_Read_Byte(P
) <> 0;
1642 EvHash
:= e_Raw_Read_MD5(P
);
1650 g_Game_ClearLoading();
1651 g_Game_StopAllSounds(True);
1653 gSwitchGameMode
:= Byte(EvNum
);
1654 gGameSettings
.GameMode
:= gSwitchGameMode
;
1657 if not g_Game_StartMap(EvStr
, True) then
1659 if Pos(':\', EvStr
) = 0 then
1660 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1662 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1666 MC_SEND_FullStateRequest
;
1671 gMissionFailed
:= EvNum
<> 0;
1672 gExit
:= EXIT_ENDLEVELCUSTOM
;
1679 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1681 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1683 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1689 if EvNum
= TEAM_RED
then
1690 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1691 if EvNum
= TEAM_BLUE
then
1692 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1696 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1699 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1702 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1704 NET_EV_LMS_SURVIVOR
:
1705 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1708 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1712 pl
:= g_Player_Get(EvNum
and $FFFF);
1717 cnt
:= (EvNum
shr 16) and $FF;
1718 if Pos('w', EvStr
) = 0 then
1721 if Pos('t', EvStr
) = 0 then
1724 if Pos('-', EvStr
) = 0 then
1726 if Pos('e', EvStr
) = 0 then
1727 i1
:= I_PLAYER_SCORE_ADD_OWN
1729 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1732 if Pos('e', EvStr
) = 0 then
1733 i1
:= I_PLAYER_SCORE_SUB_OWN
1735 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1738 if Pos('r', EvStr
) > 0 then
1739 i2
:= I_PLAYER_SCORE_TO_RED
1741 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1742 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1746 if Pos('-', EvStr
) = 0 then
1747 i1
:= I_PLAYER_SCORE_ADD_TEAM
1749 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1751 if Pos('r', EvStr
) > 0 then
1752 i2
:= I_PLAYER_SCORE_RED
1754 i2
:= I_PLAYER_SCORE_BLUE
;
1755 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1760 if Pos('e', EvStr
) = 0 then
1761 i1
:= I_PLAYER_SCORE_WIN_OWN
1763 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1765 if Pos('r', EvStr
) > 0 then
1766 i2
:= I_PLAYER_SCORE_TO_RED
1768 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1769 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1775 if EvNum
= TEAM_RED
then
1776 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1777 if EvNum
= TEAM_BLUE
then
1778 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1779 if EvNum
= -TEAM_RED
then
1780 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1781 if EvNum
= -TEAM_BLUE
then
1782 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1787 g_Player_RemoveAllCorpses
;
1788 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1792 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1796 if EvNum
= TEAM_RED
then
1797 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1798 if EvNum
= TEAM_BLUE
then
1799 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1803 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1806 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1809 g_Game_Announce_KillCombo(EvNum
);
1811 NET_EV_PLAYER_TOUCH
:
1813 pl
:= g_Player_Get(EvNum
);
1821 procedure MC_RECV_FlagEvent(P
: Pointer);
1830 EvType
:= e_Raw_Read_Byte(P
);
1831 Fl
:= e_Raw_Read_Byte(P
);
1833 if Fl
= FLAG_NONE
then Exit
;
1835 Quiet
:= (e_Raw_Read_Byte(P
) <> 0);
1836 PID
:= e_Raw_Read_Word(P
);
1838 gFlags
[Fl
].State
:= e_Raw_Read_Byte(P
);
1839 gFlags
[Fl
].CaptureTime
:= e_Raw_Read_LongWord(P
);
1840 gFlags
[Fl
].Obj
.X
:= e_Raw_Read_LongInt(P
);
1841 gFlags
[Fl
].Obj
.Y
:= e_Raw_Read_LongInt(P
);
1842 gFlags
[Fl
].Obj
.Vel
.X
:= e_Raw_Read_LongInt(P
);
1843 gFlags
[Fl
].Obj
.Vel
.Y
:= e_Raw_Read_LongInt(P
);
1845 Pl
:= g_Player_Get(PID
);
1847 (EvType
<> FLAG_STATE_NORMAL
) and
1848 (EvType
<> FLAG_STATE_DROPPED
) and
1849 (EvType
<> FLAG_STATE_RETURNED
) then
1855 if Quiet
or (Pl
= nil) then Exit
;
1857 if Fl
= FLAG_RED
then
1858 s
:= _lc
[I_PLAYER_FLAG_RED
]
1860 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1862 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1865 FLAG_STATE_CAPTURED
:
1867 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1871 if Fl
= FLAG_RED
then
1872 s
:= _lc
[I_PLAYER_FLAG_RED
]
1874 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1876 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1877 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1882 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1884 if Quiet
or (Pl
= nil) then Exit
;
1886 if Fl
= FLAG_RED
then
1887 s
:= _lc
[I_PLAYER_FLAG_RED
]
1889 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1891 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1892 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1897 g_Map_ResetFlag(FLAG_RED
);
1898 g_Map_ResetFlag(FLAG_BLUE
);
1899 if Quiet
or (Pl
= nil) then Exit
;
1900 Pl
.SetFlag(FLAG_NONE
);
1902 if Fl
= FLAG_RED
then
1903 s
:= _lc
[I_PLAYER_FLAG_RED
]
1905 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1907 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
1908 Insert('.', ts
, Length(ts
) + 1 - 3);
1909 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
1910 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
1913 FLAG_STATE_RETURNED
:
1915 g_Map_ResetFlag(Fl
);
1918 if Fl
= FLAG_RED
then
1919 s
:= _lc
[I_PLAYER_FLAG_RED
]
1921 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1923 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1928 procedure MC_RECV_GameSettings(P
: Pointer);
1930 gGameSettings
.GameMode
:= e_Raw_Read_Byte(P
);
1931 gGameSettings
.GoalLimit
:= e_Raw_Read_Word(P
);
1932 gGameSettings
.TimeLimit
:= e_Raw_Read_Word(P
);
1933 gGameSettings
.MaxLives
:= e_Raw_Read_Byte(P
);
1934 gGameSettings
.Options
:= e_Raw_Read_LongWord(P
);
1939 function MC_RECV_PlayerCreate(P
: Pointer): Word;
1942 PName
, Model
: string;
1947 PID
:= e_Raw_Read_Word(P
);
1948 Pl
:= g_Player_Get(PID
);
1950 PName
:= e_Raw_Read_String(P
);
1951 Model
:= e_Raw_Read_String(P
);
1952 Color
.R
:= e_Raw_Read_Byte(P
);
1953 Color
.G
:= e_Raw_Read_Byte(P
);
1954 Color
.B
:= e_Raw_Read_Byte(P
);
1955 T
:= e_Raw_Read_Byte(P
);
1958 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
1960 if (Pl
<> nil) then Exit
;
1961 DID
:= g_Player_Create(Model
, Color
, T
, False);
1962 with g_Player_Get(DID
) do
1971 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
1972 gPlayer1
.UID
:= PID
;
1973 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
1974 gPlayer1
.ChangeTeam(T
);
1976 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
1977 gPlayer2
.UID
:= PID
;
1978 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
1979 gPlayer2
.ChangeTeam(T
);
1983 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
1984 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', MSG_NOTIFY
);
1988 function MC_RECV_PlayerPos(P
: Pointer): Word;
1995 TmpX
, TmpY
: Integer;
1999 GT
:= e_Raw_Read_LongWord(P
);
2000 if GT
< gTime
- NET_MAX_DIFFTIME
then
2007 PID
:= e_Raw_Read_Word(P
);
2008 Pl
:= g_Player_Get(PID
);
2010 if Pl
= nil then Exit
;
2016 FPing
:= e_Raw_Read_Word(P
);
2017 FLoss
:= e_Raw_Read_Byte(P
);
2018 kByte
:= e_Raw_Read_Word(P
);
2019 Dir
:= e_Raw_Read_Byte(P
);
2021 TmpX
:= e_Raw_Read_LongInt(P
);
2022 TmpY
:= e_Raw_Read_LongInt(P
);
2026 if (kByte
= NET_KEY_CHAT
) then
2027 PressKey(KEY_CHAT
, 10000)
2030 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2031 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2032 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2033 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2034 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2037 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2038 SetDirection(TDirection(Dir
));
2040 GameVelX
:= e_Raw_Read_LongInt(P
);
2041 GameVelY
:= e_Raw_Read_LongInt(P
);
2042 GameAccelX
:= e_Raw_Read_LongInt(P
);
2043 GameAccelY
:= e_Raw_Read_LongInt(P
);
2044 SetLerp(TmpX
, TmpY
);
2045 if NetForcePlayerUpdate
then Update();
2049 function MC_RECV_PlayerStats(P
: Pointer): Word;
2057 PID
:= e_Raw_Read_Word(P
);
2058 Pl
:= g_Player_Get(PID
);
2065 Live
:= (e_Raw_Read_Byte(P
) <> 0);
2066 GodMode
:= (e_Raw_Read_Byte(P
) <> 0);
2067 Health
:= e_Raw_Read_LongInt(P
);
2068 Armor
:= e_Raw_Read_LongInt(P
);
2069 Air
:= e_Raw_Read_LongInt(P
);
2070 JetFuel
:= e_Raw_Read_LongInt(P
);
2071 Lives
:= e_Raw_Read_Byte(P
);
2072 NewTeam
:= e_Raw_Read_Byte(P
);
2074 for I
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
2075 FWeapon
[I
] := (e_Raw_Read_Byte(P
) <> 0);
2077 for I
:= A_BULLETS
to A_CELLS
do
2078 FAmmo
[I
] := e_Raw_Read_Word(P
);
2080 for I
:= A_BULLETS
to A_CELLS
do
2081 FMaxAmmo
[I
] := e_Raw_Read_Word(P
);
2083 for I
:= MR_SUIT
to MR_MAX
do
2084 FMegaRulez
[I
] := e_Raw_Read_LongWord(P
);
2087 if (e_Raw_Read_Byte(P
) <> 0) then
2088 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2089 if (e_Raw_Read_Byte(P
) <> 0) then
2090 FRulez
:= FRulez
+ [R_KEY_RED
];
2091 if (e_Raw_Read_Byte(P
) <> 0) then
2092 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2093 if (e_Raw_Read_Byte(P
) <> 0) then
2094 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2095 if (e_Raw_Read_Byte(P
) <> 0) then
2096 FRulez
:= FRulez
+ [R_BERSERK
];
2098 Frags
:= e_Raw_Read_LongInt(P
);
2099 Death
:= e_Raw_Read_LongInt(P
);
2101 SetWeapon(e_Raw_Read_Byte(P
));
2103 FSpectator
:= e_Raw_Read_Byte(P
) <> 0;
2106 if Pl
= gPlayer1
then
2111 if Pl
= gPlayer2
then
2119 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2120 gPlayer1
:= g_Player_Get(gLMSPID1
);
2121 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2122 gPlayer2
:= g_Player_Get(gLMSPID2
);
2124 FGhost
:= e_Raw_Read_Byte(P
) <> 0;
2125 FPhysics
:= e_Raw_Read_Byte(P
) <> 0;
2126 FNoRespawn
:= e_Raw_Read_Byte(P
) <> 0;
2128 FJetpack
:= e_Raw_Read_Byte(P
) <> 0;
2129 if OldJet
and not FJetpack
then
2131 else if not OldJet
and FJetpack
then
2133 if Team
<> NewTeam
then
2134 Pl
.ChangeTeam(NewTeam
);
2140 function MC_RECV_PlayerDamage(P
: Pointer): Word;
2145 Attacker
, Value
: Word;
2149 if not gGameOn
then Exit
;
2150 PID
:= e_Raw_Read_Word(P
);
2151 Pl
:= g_Player_Get(PID
);
2152 if Pl
= nil then Exit
;
2154 Kind
:= e_Raw_Read_Byte(P
);
2155 Attacker
:= e_Raw_Read_Word(P
);
2156 Value
:= e_Raw_Read_Word(P
);
2157 VX
:= e_Raw_Read_Word(P
);
2158 VY
:= e_Raw_Read_Word(P
);
2161 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2166 function MC_RECV_PlayerDeath(P
: Pointer): Word;
2170 KillType
, DeathType
: Byte;
2174 if not gGameOn
then Exit
;
2175 PID
:= e_Raw_Read_Word(P
);
2176 Pl
:= g_Player_Get(PID
);
2177 if Pl
= nil then Exit
;
2179 KillType
:= e_Raw_Read_Byte(P
);
2180 DeathType
:= e_Raw_Read_Byte(P
);
2181 Attacker
:= e_Raw_Read_Word(P
);
2185 Kill(KillType
, Attacker
, DeathType
);
2190 function MC_RECV_PlayerDelete(P
: Pointer): Word;
2195 PID
:= e_Raw_Read_Word(P
);
2196 Pl
:= g_Player_Get(PID
);
2198 if Pl
= nil then Exit
;
2200 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2201 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', MSG_NOTIFY
);
2203 g_Player_Remove(PID
);
2208 function MC_RECV_PlayerFire(P
: Pointer): Word;
2213 X
, Y
, AX
, AY
: Integer;
2217 if not gGameOn
then Exit
;
2218 PID
:= e_Raw_Read_Word(P
);
2219 Pl
:= g_Player_Get(PID
);
2220 if Pl
= nil then Exit
;
2222 Weap
:= e_Raw_Read_Byte(P
);
2223 X
:= e_Raw_Read_LongInt(P
);
2224 Y
:= e_Raw_Read_LongInt(P
);
2225 AX
:= e_Raw_Read_LongInt(P
);
2226 AY
:= e_Raw_Read_LongInt(P
);
2227 SHID
:= e_Raw_Read_LongInt(P
);
2230 if Live
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2233 procedure MC_RECV_PlayerSettings(P
: Pointer);
2242 PID
:= e_Raw_Read_Word(P
);
2243 Pl
:= g_Player_Get(PID
);
2244 if Pl
= nil then Exit
;
2246 TmpName
:= e_Raw_Read_String(P
);
2247 TmpModel
:= e_Raw_Read_String(P
);
2248 TmpColor
.R
:= e_Raw_Read_Byte(P
);
2249 TmpColor
.G
:= e_Raw_Read_Byte(P
);
2250 TmpColor
.B
:= e_Raw_Read_Byte(P
);
2251 TmpTeam
:= e_Raw_Read_Byte(P
);
2253 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2255 Pl
.ChangeTeam(TmpTeam
);
2256 if gPlayer1
= Pl
then
2257 gPlayer1Settings
.Team
:= TmpTeam
;
2258 if gPlayer2
= Pl
then
2259 gPlayer2Settings
.Team
:= TmpTeam
;
2261 Pl
.SetColor(TmpColor
);
2263 if Pl
.Name
<> TmpName
then
2265 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2269 if TmpModel
<> Pl
.Model
.Name
then
2270 Pl
.SetModel(TmpModel
);
2275 procedure MC_RECV_ItemSpawn(P
: Pointer);
2279 X
, Y
, VX
, VY
: Integer;
2281 Quiet
, Fall
{, Resp}: Boolean;
2284 if not gGameOn
then Exit
;
2285 ID
:= e_Raw_Read_Word(P
);
2286 Quiet
:= e_Raw_Read_Byte(P
) <> 0;
2287 T
:= e_Raw_Read_Byte(P
);
2288 Fall
:= e_Raw_Read_Byte(P
) <> 0;
2289 {Resp :=} e_Raw_Read_Byte(P
);
2290 X
:= e_Raw_Read_LongInt(P
);
2291 Y
:= e_Raw_Read_LongInt(P
);
2292 VX
:= e_Raw_Read_LongInt(P
);
2293 VY
:= e_Raw_Read_LongInt(P
);
2295 g_Items_Create(X
, Y
, T
, Fall
, False, False, ID
);
2296 gItems
[ID
].Obj
.Vel
.X
:= VX
;
2297 gItems
[ID
].Obj
.Vel
.Y
:= VY
;
2301 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2302 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2304 Anim
:= TAnimation
.Create(AID
, False, 4);
2305 g_GFX_OnceAnim(X
+(gItems
[ID
].Obj
.Rect
.Width
div 2)-16, Y
+(gItems
[ID
].Obj
.Rect
.Height
div 2)-16, Anim
);
2311 procedure MC_RECV_ItemDestroy(P
: Pointer);
2316 if not gGameOn
then Exit
;
2317 ID
:= e_Raw_Read_Word(P
);
2318 Quiet
:= e_Raw_Read_Byte(P
) <> 0;
2319 if gItems
= nil then Exit
;
2320 if (ID
> High(gItems
)) then Exit
;
2323 if gSoundEffectsDF
then
2325 if gItems
[ID
].ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_INVUL
,
2326 ITEM_INVIS
, ITEM_MEDKIT_BLACK
, ITEM_JETPACK
] then
2327 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2328 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2330 if gItems
[ID
].ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
2331 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
2332 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
, ITEM_AMMO_BACKPACK
] then
2333 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2334 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2336 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2337 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
);
2341 if gItems
[ID
].ItemType
in [ITEM_SPHERE_BLUE
, ITEM_SPHERE_WHITE
, ITEM_SUIT
,
2342 ITEM_MEDKIT_BLACK
, ITEM_INVUL
, ITEM_INVIS
, ITEM_JETPACK
] then
2343 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2344 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2346 if gItems
[ID
].ItemType
in [ITEM_WEAPON_SAW
, ITEM_WEAPON_PISTOL
, ITEM_WEAPON_SHOTGUN1
, ITEM_WEAPON_SHOTGUN2
,
2347 ITEM_WEAPON_CHAINGUN
, ITEM_WEAPON_ROCKETLAUNCHER
, ITEM_WEAPON_PLASMA
,
2348 ITEM_WEAPON_BFG
, ITEM_WEAPON_SUPERPULEMET
] then
2349 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2350 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
)
2352 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2353 gItems
[ID
].Obj
.X
, gItems
[ID
].Obj
.Y
);
2361 procedure MC_RECV_PanelTexture(P
: Pointer);
2369 if not gGameOn
then Exit
;
2370 PType
:= e_Raw_Read_Word(P
);
2371 ID
:= e_Raw_Read_LongWord(P
);
2372 Tex
:= e_Raw_Read_LongInt(P
);
2373 Fr
:= e_Raw_Read_LongInt(P
);
2374 Cnt
:= e_Raw_Read_Byte(P
);
2375 Loop
:= e_Raw_Read_Byte(P
);
2380 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2381 if gWalls
<> nil then
2384 if gRenderForegrounds
<> nil then
2385 TP
:= gRenderForegrounds
[ID
];
2387 if gRenderBackgrounds
<> nil then
2388 TP
:= gRenderBackgrounds
[ID
];
2390 if gWater
<> nil then
2393 if gAcid1
<> nil then
2396 if gAcid2
<> nil then
2399 if gSteps
<> nil then
2407 begin // switch texture
2408 TP
.SetTexture(Tex
, Loop
);
2409 TP
.SetFrame(Fr
, Cnt
);
2410 end else // looped or non-looped animation
2411 TP
.NextTexture(Loop
);
2414 procedure MC_RECV_PanelState(P
: Pointer);
2421 if not gGameOn
then Exit
;
2422 PType
:= e_Raw_Read_Word(P
);
2423 ID
:= e_Raw_Read_LongWord(P
);
2424 E
:= (e_Raw_Read_Byte(P
) <> 0);
2425 Lift
:= e_Raw_Read_Byte(P
);
2428 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2430 g_Map_EnableWall(ID
)
2432 g_Map_DisableWall(ID
);
2434 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
2435 g_Map_SetLift(ID
, Lift
);
2441 procedure MC_RECV_TriggerSound(P
: Pointer);
2444 SPos
, SID
: LongWord;
2448 if not gGameOn
then Exit
;
2449 if gTriggers
= nil then Exit
;
2451 SID
:= e_Raw_Read_LongWord(P
);
2452 SPlaying
:= e_Raw_Read_Byte(P
) <> 0;
2453 SPos
:= e_Raw_Read_LongWord(P
);
2454 SCount
:= e_Raw_Read_LongInt(P
);
2456 for I
:= Low(gTriggers
) to High(gTriggers
) do
2457 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2458 if gTriggers
[I
].ClientID
= SID
then
2459 with gTriggers
[I
] do
2464 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0)
2466 Sound
.PlayPanVolume((Data
.Pan
-127.0)/128.0, Data
.Volume
/255.0);
2467 Sound
.SetPosition(SPos
);
2470 if Sound
.IsPlaying
then Sound
.Stop
;
2472 SoundPlayCount
:= SCount
;
2476 procedure MC_RECV_TriggerMusic(P
: Pointer);
2483 if not gGameOn
then Exit
;
2485 MName
:= e_Raw_Read_String(P
);
2486 MPlaying
:= e_Raw_Read_Byte(P
) <> 0;
2487 MPos
:= e_Raw_Read_LongWord(P
);
2488 MPaused
:= e_Raw_Read_Byte(P
) <> 0;
2492 gMusic
.SetByName(MName
);
2494 gMusic
.SetPosition(MPos
);
2495 gMusic
.SpecPause
:= MPaused
;
2498 if gMusic
.IsPlaying
then gMusic
.Stop
;
2503 procedure MC_RECV_MonsterSpawn(P
: Pointer);
2506 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2507 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2511 ID
:= e_Raw_Read_Word(P
);
2512 M
:= g_Monsters_Get(ID
);
2516 MType
:= e_Raw_Read_Byte(P
);
2517 MState
:= e_Raw_Read_Byte(P
);
2518 MAnim
:= e_Raw_Read_Byte(P
);
2519 MTarg
:= e_Raw_Read_Word(P
);
2520 MTargTime
:= e_Raw_Read_LongInt(P
);
2521 MBehav
:= e_Raw_Read_Byte(P
);
2522 MSleep
:= e_Raw_Read_LongInt(P
);
2523 MHealth
:= e_Raw_Read_LongInt(P
);
2524 MAmmo
:= e_Raw_Read_LongInt(P
);
2526 X
:= e_Raw_Read_LongInt(P
);
2527 Y
:= e_Raw_Read_LongInt(P
);
2528 VX
:= e_Raw_Read_LongInt(P
);
2529 VY
:= e_Raw_Read_LongInt(P
);
2530 MDir
:= e_Raw_Read_Byte(P
);
2532 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2533 M
:= g_Monsters_Get(ID
);
2544 MonsterAnim
:= MAnim
;
2545 MonsterTargetUID
:= MTarg
;
2546 MonsterTargetTime
:= MTargTime
;
2547 MonsterBehaviour
:= MBehav
;
2548 MonsterSleep
:= MSleep
;
2549 MonsterAmmo
:= MAmmo
;
2556 procedure MC_RECV_MonsterPos(P
: Pointer);
2561 ID
:= e_Raw_Read_Word(P
);
2562 M
:= g_Monsters_Get(ID
);
2568 GameX
:= e_Raw_Read_LongInt(P
);
2569 GameY
:= e_Raw_Read_LongInt(P
);
2570 GameVelX
:= e_Raw_Read_LongInt(P
);
2571 GameVelY
:= e_Raw_Read_LongInt(P
);
2572 GameDirection
:= TDirection(e_Raw_Read_Byte(P
));
2576 procedure MC_RECV_MonsterState(P
: Pointer);
2579 MState
, MFAnm
: Byte;
2581 AnimRevert
: Boolean;
2583 ID
:= e_Raw_Read_Word(P
);
2584 M
:= g_Monsters_Get(ID
);
2585 if M
= nil then Exit
;
2587 MState
:= e_Raw_Read_Byte(P
);
2588 MFAnm
:= e_Raw_Read_Byte(P
);
2592 MonsterTargetUID
:= e_Raw_Read_Word(P
);
2593 MonsterTargetTime
:= e_Raw_Read_LongInt(P
);
2594 MonsterSleep
:= e_Raw_Read_LongInt(P
);
2595 MonsterHealth
:= e_Raw_Read_LongInt(P
);
2596 MonsterAmmo
:= e_Raw_Read_LongInt(P
);
2597 MonsterPain
:= e_Raw_Read_LongInt(P
);
2598 AnimRevert
:= e_Raw_Read_Byte(P
) <> 0;
2599 RevertAnim(AnimRevert
);
2601 if MonsterState
<> MState
then
2603 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then
2605 if (MState
= MONSTATE_DIE
) then
2607 if (MState
= MONSTATE_PAIN
) then
2608 MakeBloodSimple(Min(200, MonsterPain
));
2609 if (MState
= MONSTATE_ATTACK
) then
2611 if (MState
= MONSTATE_DEAD
) then
2614 SetState(MState
, MFAnm
);
2619 procedure MC_RECV_MonsterShot(P
: Pointer);
2623 X
, Y
, VX
, VY
: Integer;
2625 ID
:= e_Raw_Read_Word(P
);
2627 M
:= g_Monsters_Get(ID
);
2628 if M
= nil then Exit
;
2630 X
:= e_Raw_Read_LongInt(P
);
2631 Y
:= e_Raw_Read_LongInt(P
);
2632 VX
:= e_Raw_Read_LongInt(P
);
2633 VY
:= e_Raw_Read_LongInt(P
);
2635 M
.ClientAttack(X
, Y
, VX
, VY
);
2638 procedure MC_RECV_MonsterDelete(P
: Pointer);
2643 ID
:= e_Raw_Read_Word(P
);
2644 M
:= g_Monsters_Get(ID
);
2645 if M
= nil then Exit
;
2647 gMonsters
[ID
].SetState(5);
2648 gMonsters
[ID
].MonsterRemoved
:= True;
2651 procedure MC_RECV_TimeSync(P
: Pointer);
2655 Time
:= e_Raw_Read_LongWord(P
);
2657 if gState
= STATE_INTERCUSTOM
then
2658 gServInterTime
:= Min(Time
, 255);
2661 procedure MC_RECV_VoteEvent(P
: Pointer);
2665 Int1
, Int2
: SmallInt;
2667 EvID
:= e_Raw_Read_Byte(P
);
2668 Int1
:= e_Raw_Read_SmallInt(P
);
2669 Int2
:= e_Raw_Read_SmallInt(P
);
2670 Str1
:= e_Raw_Read_String(P
);
2671 Str2
:= e_Raw_Read_String(P
);
2675 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2677 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2679 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2681 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2683 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2689 procedure MC_SEND_Info(Password
: string);
2691 e_Buffer_Clear(@NetOut
);
2693 e_Buffer_Write(@NetOut
, Byte(NET_MSG_INFO
));
2694 e_Buffer_Write(@NetOut
, Byte(0)); // to kill old clients
2695 e_Buffer_Write(@NetOut
, Byte(NET_PROTO_VERSION
));
2696 e_Buffer_Write(@NetOut
, GAME_VERSION
);
2697 e_Buffer_Write(@NetOut
, Password
);
2698 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Name
);
2699 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Model
);
2700 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.R
);
2701 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.G
);
2702 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.B
);
2703 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Team
);
2705 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2708 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2710 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHAT
));
2711 e_Buffer_Write(@NetOut
, Txt
);
2712 e_Buffer_Write(@NetOut
, Mode
);
2714 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2717 procedure MC_SEND_PlayerPos();
2722 if not gGameOn
then Exit
;
2723 if gPlayers
= nil then Exit
;
2724 if gPlayer1
= nil then Exit
;
2727 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2729 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2730 with gGameControls
.P1Control
do
2732 if e_KeyPressed(KeyLeft
) and (not e_KeyPressed(KeyRight
)) then
2735 if (not e_KeyPressed(KeyLeft
)) and e_KeyPressed(KeyRight
) then
2738 if (not e_KeyPressed(KeyLeft
)) and (not e_KeyPressed(KeyRight
)) then
2741 if (P1MoveButton
= 2) and e_KeyPressed(KeyLeft
) then
2742 gPlayer1
.SetDirection(D_LEFT
)
2744 if (P1MoveButton
= 1) and e_KeyPressed(KeyRight
) then
2745 gPlayer1
.SetDirection(D_RIGHT
)
2747 if P1MoveButton
<> 0 then
2748 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2750 gPlayer1
.ReleaseKeys
;
2751 if P1MoveButton
= 1 then
2753 kByte
:= kByte
or NET_KEY_LEFT
;
2754 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2756 if P1MoveButton
= 2 then
2758 kByte
:= kByte
or NET_KEY_RIGHT
;
2759 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2761 if e_KeyPressed(KeyUp
) then
2763 kByte
:= kByte
or NET_KEY_UP
;
2764 gPlayer1
.PressKey(KEY_UP
, 10000);
2766 if e_KeyPressed(KeyDown
) then
2768 kByte
:= kByte
or NET_KEY_DOWN
;
2769 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2771 if e_KeyPressed(KeyJump
) then
2773 kByte
:= kByte
or NET_KEY_JUMP
;
2774 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2776 if e_KeyPressed(KeyFire
) then kByte
:= kByte
or NET_KEY_FIRE
;
2777 if e_KeyPressed(KeyOpen
) then kByte
:= kByte
or NET_KEY_OPEN
;
2778 if e_KeyPressed(KeyNextWeapon
) then kByte
:= kByte
or NET_KEY_NW
;
2779 if e_KeyPressed(KeyPrevWeapon
) then kByte
:= kByte
or NET_KEY_PW
;
2782 kByte
:= NET_KEY_CHAT
;
2784 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRPOS
));
2785 e_Buffer_Write(@NetOut
, gTime
);
2786 e_Buffer_Write(@NetOut
, kByte
);
2787 e_Buffer_Write(@NetOut
, Byte(gPlayer1
.Direction
));
2788 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2790 //kBytePrev := kByte;
2791 //kDirPrev := gPlayer1.Direction;
2794 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2796 e_Buffer_Write(@NetOut
, Byte(NET_MSG_VOTE_EVENT
));
2797 e_Buffer_Write(@NetOut
, Byte(Start
));
2798 e_Buffer_Write(@NetOut
, Command
);
2799 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2802 procedure MC_SEND_PlayerSettings();
2804 e_Buffer_Write(@NetOut
, Byte(NET_MSG_PLRSET
));
2805 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Name
);
2806 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Model
);
2807 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.R
);
2808 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.G
);
2809 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Color
.B
);
2810 e_Buffer_Write(@NetOut
, gPlayer1Settings
.Team
);
2812 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2815 procedure MC_SEND_FullStateRequest();
2817 e_Buffer_Write(@NetOut
, Byte(NET_MSG_REQFST
));
2819 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2822 procedure MC_SEND_CheatRequest(Kind
: Byte);
2824 e_Buffer_Write(@NetOut
, Byte(NET_MSG_CHEAT
));
2825 e_Buffer_Write(@NetOut
, Kind
);
2827 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2829 procedure MC_SEND_RCONPassword(Password
: string);
2831 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RCON_AUTH
));
2832 e_Buffer_Write(@NetOut
, Password
);
2834 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2836 procedure MC_SEND_RCONCommand(Cmd
: string);
2838 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RCON_CMD
));
2839 e_Buffer_Write(@NetOut
, Cmd
);
2841 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2844 // i have no idea why all this stuff is in here
2846 function ReadFile(const FileName
: TFileName
): AByte
;
2848 FileStream
: TStream
;
2851 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), MSG_NOTIFY
);
2852 fname
:= findDiskWad(FileName
);
2853 if length(fname
) = 0 then
2855 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), MSG_FATALERROR
);
2856 SetLength(Result
, 0);
2859 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), MSG_NOTIFY
);
2861 FileStream
:= openDiskFileRO(fname
);
2863 if FileStream
.Size
> 0 then
2865 SetLength(Result
, FileStream
.Size
);
2866 FileStream
.Read(Result
[0], FileStream
.Size
);
2873 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
2877 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
2878 Result
.FileData
:= ReadFile(FileName
);
2879 Result
.FileSize
:= Length(Result
.FileData
);
2881 SetLength(Result
.ExternalResources
, ResList
.Count
);
2882 for i
:=0 to ResList
.Count
-1 do
2884 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
2885 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
2889 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
2891 ResultStream
: TMemoryStream
;
2893 ResultStream
:= TMemoryStream
.Create
;
2895 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
2896 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
2897 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
2899 SetLength(bytes
, ResultStream
.Size
);
2900 ResultStream
.Seek(0, soFromBeginning
);
2901 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2906 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
2908 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
2909 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
2910 SetLength(Result
.FileData
, Result
.FileSize
);
2911 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
2914 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
2916 ResultStream
: TMemoryStream
;
2919 resCount
:= Length(MapDataMsg
.ExternalResources
);
2921 ResultStream
:= TMemoryStream
.Create
;
2923 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
2924 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
2925 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
2927 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
2928 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
2930 SetLength(bytes
, ResultStream
.Size
);
2931 ResultStream
.Seek(0, soFromBeginning
);
2932 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
2937 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
2941 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
2942 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
2944 SetLength(Result
.FileData
, Result
.FileSize
);
2945 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
2947 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
2948 SetLength(Result
.ExternalResources
, resCount
);
2950 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
2953 function IsValidFileName(const S
: String): Boolean;
2955 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
2960 for I
:= 1 to Length(S
) do
2961 Result
:= Result
and (not(S
[I
] in Forbidden
));
2964 function IsValidFilePath(const S
: String): Boolean;
2969 if not IsValidFileName(S
) then exit
;
2970 if FileExists(S
) then exit
;
2971 I
:= LastDelimiter('\/', S
);
2973 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
2978 procedure MC_SEND_MapRequest();
2980 e_Buffer_Write(@NetOut
, Byte(NET_MSG_MAP_REQUEST
));
2981 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2984 procedure MC_SEND_ResRequest(const resName
: AnsiString);
2986 e_Buffer_Write(@NetOut
, Byte(NET_MSG_RES_REQUEST
));
2987 e_Buffer_Write(@NetOut
, resName
);
2988 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2991 procedure MH_RECV_MapRequest(C
: pTNetClient
; P
: Pointer);
2995 mapDataMsg
: TMapDataMsg
;
2997 e_WriteLog('NET: Received map request from ' +
2998 DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3000 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3001 peer
:= NetClients
[C
.ID
].Peer
;
3003 MapDataMsgToBytes(payload
, mapDataMsg
);
3004 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3007 mapDataMsg
.FileData
:= nil;
3008 mapDataMsg
.ExternalResources
:= nil;
3011 procedure MH_RECV_ResRequest(C
: pTNetClient
; P
: Pointer);
3016 resDataMsg
: TResDataMsg
;
3018 FileName
:= ExtractFileName(e_Raw_Read_String(P
));
3019 e_WriteLog('NET: Received res request: ' + FileName
+
3020 ' from ' + DecodeIPV4(C
.Peer
.address
.host
), MSG_NOTIFY
);
3022 if not IsValidFilePath(FileName
) then
3024 e_WriteLog('Invalid filename: ' + FileName
, MSG_WARNING
);
3028 peer
:= NetClients
[C
.ID
].Peer
;
3030 if gExternalResources
.IndexOf(FileName
) > -1 then
3032 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3033 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3034 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3036 ResDataMsgToBytes(payload
, resDataMsg
);
3037 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);