0483bea1651608dc407895e67f6125f568f932f1
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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
20 uses e_msg
, g_net
, g_triggers
, Classes
, SysUtils
, md5
;
64 NET_MSG_RCON_AUTH
= 191;
65 NET_MSG_RCON_CMD
= 192;
66 NET_MSG_TIME_SYNC
= 194;
67 NET_MSG_VOTE_EVENT
= 195;
69 NET_MSG_MAP_REQUEST
= 201;
70 NET_MSG_MAP_RESPONSE
= 202;
71 NET_MSG_RES_REQUEST
= 203;
72 NET_MSG_RES_RESPONSE
= 204;
74 // chunked file transfers
76 // client requests file (FILE_REQUEST)
77 // server sends file header info (FILE_HEADER)
78 // client acks chunk -1 (CHUNK_ACK) to initiate transfer, or cancels (FILE_CANCEL)
79 // server start sending data chunks (one at a time, waiting for an ACK for each one)
80 // when client acks the last chunk, transfer is complete
81 // this scheme sux, of course; we can do better by spamming with unreliable unsequenced packets,
82 // and use client acks to drive server sends, but meh... let's do it this way first, and
83 // we can improve it later.
85 // client: request a file
86 NET_MSG_FILE_REQUEST
= 210;
87 // server: file info response
88 NET_MSG_FILE_HEADER
= 211;
89 // client: request transfer cancellation
90 // server: something went wrong, transfer cancelled, bomb out
91 NET_MSG_FILE_CANCEL
= 212;
92 // server: file chunk data
93 NET_MSG_FILE_CHUNK_DATA
= 213;
94 // client: file chunk ack
95 NET_MSG_FILE_CHUNK_ACK
= 214;
119 NET_EV_CHANGE_TEAM
= 3;
120 NET_EV_PLAYER_KICK
= 4;
121 NET_EV_PLAYER_BAN
= 5;
122 NET_EV_LMS_WARMUP
= 6;
123 NET_EV_LMS_SURVIVOR
= 7;
127 NET_EV_SCORE_MSG
= 11;
128 NET_EV_LMS_START
= 12;
130 NET_EV_TLMS_WIN
= 14;
131 NET_EV_LMS_LOSE
= 15;
132 NET_EV_LMS_DRAW
= 16;
133 NET_EV_KILLCOMBO
= 17;
134 NET_EV_PLAYER_TOUCH
= 18;
136 NET_EV_INTER_READY
= 20;
143 NET_VE_INPROGRESS
= 6;
150 NET_CHEAT_SUICIDE
= 1;
151 NET_CHEAT_SPECTATE
= 2;
154 NET_MAX_DIFFTIME
= 5000 div 36;
158 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
159 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
160 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
161 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
162 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
163 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
164 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
165 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
166 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
167 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
168 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
171 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_Info(ID
: Byte);
173 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
186 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
189 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
190 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
191 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
192 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
194 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
195 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
197 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
198 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
200 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
201 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
202 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
203 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
204 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
206 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
207 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
209 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
210 procedure MH_SEND_VoteEvent(EvType
: Byte;
211 StrArg1
: string = 'a'; StrArg2
: string = 'b';
212 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
213 ID
: Integer = NET_EVERYONE
);
215 // CLIENT MESSAGES //
218 procedure MC_RECV_Chat(var M
: TMsg
);
219 procedure MC_RECV_Effect(var M
: TMsg
);
220 procedure MC_RECV_Sound(var M
: TMsg
);
221 procedure MC_RECV_GameStats(var M
: TMsg
);
222 procedure MC_RECV_CoopStats(var M
: TMsg
);
223 procedure MC_RECV_GameEvent(var M
: TMsg
);
224 procedure MC_RECV_FlagEvent(var M
: TMsg
);
225 procedure MC_RECV_GameSettings(var M
: TMsg
);
227 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
228 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
229 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
230 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
231 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
232 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
233 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
234 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
236 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
237 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
239 procedure MC_RECV_PanelTexture(var M
: TMsg
);
240 procedure MC_RECV_PanelState(var M
: TMsg
);
242 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
243 procedure MC_RECV_MonsterPos(var M
: TMsg
);
244 procedure MC_RECV_MonsterState(var M
: TMsg
);
245 procedure MC_RECV_MonsterShot(var M
: TMsg
);
246 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
248 procedure MC_RECV_CreateShot(var M
: TMsg
);
249 procedure MC_RECV_UpdateShot(var M
: TMsg
);
250 procedure MC_RECV_DeleteShot(var M
: TMsg
);
252 procedure MC_RECV_TriggerSound(var M
: TMsg
);
253 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
255 procedure MC_RECV_TimeSync(var M
: TMsg
);
256 procedure MC_RECV_VoteEvent(var M
: TMsg
);
258 procedure MC_SEND_Info(Password
: string);
259 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
260 procedure MC_SEND_PlayerPos();
261 procedure MC_SEND_FullStateRequest();
262 procedure MC_SEND_PlayerSettings();
263 procedure MC_SEND_CheatRequest(Kind
: Byte);
264 procedure MC_SEND_RCONPassword(Password
: string);
265 procedure MC_SEND_RCONCommand(Cmd
: string);
266 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
268 procedure MC_SEND_MapRequest();
269 procedure MC_SEND_ResRequest(const resName
: AnsiString);
273 TExternalResourceInfo
= record
288 ExternalResources
: array of TExternalResourceInfo
;
291 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
292 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
294 function IsValidFileName(const S
: String): Boolean;
295 function IsValidFilePath(const S
: String): Boolean;
300 Math
, ENet
, e_input
, e_graphics
, e_log
,
301 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
302 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
303 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
316 NET_KEY_FORCEDIR
= 4096;
319 //kBytePrev: Word = 0;
320 //kDirPrev: TDirection = D_LEFT;
321 //HostGameTime: Word = 0;
328 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
336 Pl
:= g_Player_Get(PID
);
338 Txt
:= M
.ReadString();
339 Mode
:= M
.ReadByte();
340 if (Mode
= NET_CHAT_SYSTEM
) then
341 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
342 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
343 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
346 MH_SEND_Chat(Txt
, Mode
)
348 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
351 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
353 Ver
, PName
, Model
, Pw
: string;
359 Ver
:= M
.ReadString();
360 Pw
:= M
.ReadString();
361 PName
:= M
.ReadString();
362 Model
:= M
.ReadString();
368 if Ver
<> GAME_VERSION
then
370 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
371 _lc
[I_NET_DISC_VERSION
]);
372 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
376 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
378 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
380 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
381 _lc
[I_NET_DISC_BAN
]);
382 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
386 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
387 _lc
[I_NET_DISC_BAN
]);
388 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
393 if NetPassword
<> '' then
394 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
396 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
397 _lc
[I_NET_DISC_PASSWORD
]);
398 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
406 PID
:= g_Player_Create(Model
, Color
, T
, False);
407 with g_Player_Get(PID
) do
415 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
416 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
417 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
421 with g_Player_Get(PID
) do
425 // round in progress, don't spawn
426 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
431 FWantsInGame
:= True; // TODO: look into this later
434 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
437 for I
:= Low(NetClients
) to High(NetClients
) do
439 if NetClients
[I
].ID
= C
^.ID
then Continue
;
440 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
441 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
442 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
445 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
446 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
448 if NetUseMaster
then g_Net_Slist_Update
;
451 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
454 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
456 C
^.RequestedFullUpdate
:= True;
461 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
471 if not gGameOn
then Exit
;
473 GT
:= M
.ReadLongWord();
475 Pl
:= g_Player_Get(PID
);
479 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
484 kByte
:= M
.ReadWord();
486 WeaponSelect
:= M
.ReadWord();
487 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
488 if Direction
<> TDirection(Dir
) then
489 JustTeleported
:= False;
491 SetDirection(TDirection(Dir
));
494 if kByte
= NET_KEY_CHAT
then
496 PressKey(KEY_CHAT
, 10000);
500 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
501 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
502 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
503 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
504 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
505 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
506 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
507 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
508 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
512 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
514 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
515 QueueWeaponSwitch(i
);
520 // MH_SEND_PlayerPos(False, PID, C^.ID);
523 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
528 Pl
:= g_Player_Get(C
^.Player
);
529 if Pl
= nil then Exit
;
531 CheatKind
:= M
.ReadByte();
535 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
538 if Pl
.FSpectator
then
545 if gState
<> STATE_INTERCUSTOM
then Exit
;
546 Pl
.FReady
:= not Pl
.FReady
;
549 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
550 Inc(gInterReadyCount
);
554 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
555 Dec(gInterReadyCount
);
561 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
569 TmpName
:= M
.ReadString();
570 TmpModel
:= M
.ReadString();
571 TmpColor
.R
:= M
.ReadByte();
572 TmpColor
.G
:= M
.ReadByte();
573 TmpColor
.B
:= M
.ReadByte();
574 TmpTeam
:= M
.ReadByte();
576 Pl
:= g_Player_Get(C
^.Player
);
577 if Pl
= nil then Exit
;
579 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
582 Pl
.SetColor(TmpColor
);
584 if Pl
.Name
<> TmpName
then
586 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
590 if TmpModel
<> Pl
.Model
.Name
then
591 Pl
.SetModel(TmpModel
);
593 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
598 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
602 Pwd
:= M
.ReadString();
603 if not NetAllowRCON
then Exit
;
604 if Pwd
= NetRCONPassword
then
607 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
610 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
613 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
617 Cmd
:= M
.ReadString();
618 if not NetAllowRCON
then Exit
;
619 if not C
^.RCONAuth
then
621 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
624 g_Console_Process(Cmd
);
629 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
632 Name
, Command
: string;
636 Start
:= M
.ReadByte() <> 0;
637 Command
:= M
.ReadString();
639 Pl
:= g_Player_Get(C
^.Player
);
640 if Pl
= nil then Exit
;
645 if not g_Console_CommandBlacklisted(Command
) then
646 g_Game_StartVote(Command
, Name
);
648 else if gVoteInProgress
then
650 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
651 Need
:= Floor((NetClientCount
+1)/2.0) + 1
653 Need
:= Floor(NetClientCount
/2.0) + 1;
658 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
659 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
665 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
666 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
674 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
676 function sendItemRespawn (it
: PItem
): Boolean;
678 result
:= false; // don't stop
679 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
682 function sendMonSpawn (mon
: TMonster
): Boolean;
684 result
:= false; // don't stop
685 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
688 function sendPanelState (pan
: TPanel
): Boolean;
690 result
:= false; // don't stop
691 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
692 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
698 if gPlayers
<> nil then
700 for I
:= Low(gPlayers
) to High(gPlayers
) do
702 if gPlayers
[I
] <> nil then
704 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
705 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
706 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
708 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
710 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
716 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
717 g_Mons_ForEach(sendMonSpawn
);
718 g_Map_ForEachPanel(sendPanelState
);
720 if gTriggers
<> nil then
722 for I
:= Low(gTriggers
) to High(gTriggers
) do
724 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
726 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
733 for I
:= Low(Shots
) to High(Shots
) do
735 if Shots
[i
].ShotType
in [6, 7, 8] then
737 MH_SEND_CreateShot(i
, ID
);
742 MH_SEND_TriggerMusic(ID
);
744 MH_SEND_GameStats(ID
);
745 MH_SEND_CoopStats(ID
);
747 if gGameSettings
.GameMode
= GM_CTF
then
749 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
750 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
753 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
755 if gLMSRespawn
> LMS_RESPAWN_NONE
then
757 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
763 procedure MH_SEND_Info(ID
: Byte);
767 Map
:= g_ExtractFileName(gMapInfo
.Map
);
771 NetOut
.Write(Byte(NET_MSG_INFO
));
773 NetOut
.Write(NetClients
[ID
].Player
);
774 NetOut
.Write(gGameSettings
.WAD
);
776 NetOut
.Write(gWADHash
);
777 NetOut
.Write(gGameSettings
.GameMode
);
778 NetOut
.Write(gGameSettings
.GoalLimit
);
779 NetOut
.Write(gGameSettings
.TimeLimit
);
780 NetOut
.Write(gGameSettings
.MaxLives
);
781 NetOut
.Write(gGameSettings
.Options
);
784 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
787 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
793 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
794 Mode
:= NET_CHAT_PLAYER
;
797 if (Mode
= NET_CHAT_TEAM
) then
799 for i
:= Low(gPlayers
) to High(gPlayers
) do
800 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
801 (gPlayers
[i
].Team
= ID
) then
803 NetOut
.Write(Byte(NET_MSG_CHAT
));
806 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
813 NetOut
.Write(Byte(NET_MSG_CHAT
));
816 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
819 if Mode
= NET_CHAT_SYSTEM
then
822 if ID
= NET_EVERYONE
then
824 if Mode
= NET_CHAT_PLAYER
then
826 g_Console_Add(Txt
, True);
827 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
828 g_Game_ChatSound(b_Text_Unformat(Txt
));
831 if Mode
= NET_CHAT_TEAM
then
832 if gPlayer1
<> nil then
834 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
836 g_Console_Add(#18'[Team] '#2 + Txt
, True);
837 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
838 g_Game_ChatSound(b_Text_Unformat(Txt
));
840 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
842 g_Console_Add(#20'[Team] '#2 + Txt
, True);
843 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
844 g_Game_ChatSound(b_Text_Unformat(Txt
));
850 Name
:= g_Net_ClientName_ByID(ID
);
851 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
852 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
853 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
857 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
859 NetOut
.Write(Byte(NET_MSG_GFX
));
865 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
868 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
870 NetOut
.Write(Byte(NET_MSG_SND
));
874 NetOut
.Write(Byte(1));
879 NetOut
.Write(Byte(0));
881 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
884 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
886 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
888 NetOut
.Write(Byte(NET_MSG_SHADD
));
890 NetOut
.Write(Shots
[Proj
].ShotType
);
891 NetOut
.Write(Shots
[Proj
].Target
);
892 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
893 NetOut
.Write(Shots
[Proj
].Timeout
);
894 NetOut
.Write(Shots
[Proj
].Obj
.X
);
895 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
896 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
897 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
899 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
902 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
904 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
906 NetOut
.Write(Byte(NET_MSG_SHPOS
));
908 NetOut
.Write(Shots
[Proj
].Obj
.X
);
909 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
910 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
911 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
913 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
916 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
918 NetOut
.Write(Byte(NET_MSG_SHDEL
));
920 NetOut
.Write(Byte(Loud
));
924 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
927 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
929 NetOut
.Write(Byte(NET_MSG_SCORE
));
930 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
932 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
933 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
936 if gGameSettings
.GameMode
= GM_COOP
then
938 NetOut
.Write(gCoopMonstersKilled
);
939 NetOut
.Write(gCoopSecretsFound
);
942 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
945 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
947 NetOut
.Write(Byte(NET_MSG_COOP
));
948 NetOut
.Write(gTotalMonsters
);
949 NetOut
.Write(gSecretsCount
);
950 NetOut
.Write(gCoopTotalMonstersKilled
);
951 NetOut
.Write(gCoopTotalSecretsFound
);
952 NetOut
.Write(gCoopTotalMonsters
);
953 NetOut
.Write(gCoopTotalSecrets
);
956 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
958 NetOut
.Write(Byte(NET_MSG_GEVENT
));
959 NetOut
.Write(EvType
);
962 NetOut
.Write(Byte(gLastMap
));
964 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
966 NetOut
.Write(Byte(1));
967 NetOut
.Write(gWADHash
);
969 NetOut
.Write(Byte(0));
971 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
974 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
976 NetOut
.Write(Byte(NET_MSG_FLAG
));
977 NetOut
.Write(EvType
);
979 NetOut
.Write(Byte(Quiet
));
981 NetOut
.Write(gFlags
[Flag
].State
);
982 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
983 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
984 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
985 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
986 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
988 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
991 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
993 NetOut
.Write(Byte(NET_MSG_GSET
));
994 NetOut
.Write(gGameSettings
.GameMode
);
995 NetOut
.Write(gGameSettings
.GoalLimit
);
996 NetOut
.Write(gGameSettings
.TimeLimit
);
997 NetOut
.Write(gGameSettings
.MaxLives
);
998 NetOut
.Write(gGameSettings
.Options
);
1000 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1005 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1009 P
:= g_Player_Get(PID
);
1010 if P
= nil then Exit
;
1012 NetOut
.Write(Byte(NET_MSG_PLR
));
1014 NetOut
.Write(P
.Name
);
1016 NetOut
.Write(P
.FActualModelName
);
1017 NetOut
.Write(P
.FColor
.R
);
1018 NetOut
.Write(P
.FColor
.G
);
1019 NetOut
.Write(P
.FColor
.B
);
1020 NetOut
.Write(P
.Team
);
1022 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1025 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1030 Pl
:= g_Player_Get(PID
);
1031 if Pl
= nil then Exit
;
1032 if Pl
.FDummy
then Exit
;
1034 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1035 NetOut
.Write(gTime
);
1042 NetOut
.Write(FPing
);
1043 NetOut
.Write(FLoss
);
1044 if IsKeyPressed(KEY_CHAT
) then
1045 kByte
:= NET_KEY_CHAT
1048 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1049 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1050 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1051 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1052 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1053 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1056 NetOut
.Write(kByte
);
1057 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1058 NetOut
.Write(GameX
);
1059 NetOut
.Write(GameY
);
1060 NetOut
.Write(GameVelX
);
1061 NetOut
.Write(GameVelY
);
1062 NetOut
.Write(GameAccelX
);
1063 NetOut
.Write(GameAccelY
);
1066 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1069 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1074 P
:= g_Player_Get(PID
);
1075 if P
= nil then Exit
;
1077 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1082 NetOut
.Write(Byte(alive
));
1083 NetOut
.Write(Byte(GodMode
));
1084 NetOut
.Write(Health
);
1085 NetOut
.Write(Armor
);
1087 NetOut
.Write(JetFuel
);
1088 NetOut
.Write(Lives
);
1091 for I
:= WP_FIRST
to WP_LAST
do
1092 NetOut
.Write(Byte(FWeapon
[I
]));
1094 for I
:= A_BULLETS
to A_HIGH
do
1095 NetOut
.Write(FAmmo
[I
]);
1097 for I
:= A_BULLETS
to A_HIGH
do
1098 NetOut
.Write(FMaxAmmo
[I
]);
1100 for I
:= MR_SUIT
to MR_MAX
do
1101 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1103 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1104 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1105 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1106 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1107 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1109 NetOut
.Write(Frags
);
1110 NetOut
.Write(Death
);
1112 NetOut
.Write(CurrWeap
);
1114 NetOut
.Write(Byte(FSpectator
));
1115 NetOut
.Write(Byte(FGhost
));
1116 NetOut
.Write(Byte(FPhysics
));
1117 NetOut
.Write(Byte(FNoRespawn
));
1118 NetOut
.Write(Byte(FJetpack
));
1119 NetOut
.Write(FFireTime
);
1120 NetOut
.Write(Byte(FFlaming
));
1123 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1126 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1128 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1131 NetOut
.Write(Attacker
);
1132 NetOut
.Write(Value
);
1136 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1139 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1141 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1143 NetOut
.Write(KillType
);
1144 NetOut
.Write(DeathType
);
1145 NetOut
.Write(Attacker
);
1147 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1150 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1152 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1154 NetOut
.Write(Weapon
);
1159 NetOut
.Write(ShotID
);
1161 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1164 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1166 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1169 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1172 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1176 Pl
:= g_Player_Get(PID
);
1177 if Pl
= nil then Exit
;
1179 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1181 NetOut
.Write(Pl
.Name
);
1183 NetOut
.Write(Pl
.Model
.Name
)
1186 NetOut
.Write(Pl
.FColor
.R
);
1187 NetOut
.Write(Pl
.FColor
.G
);
1188 NetOut
.Write(Pl
.FColor
.B
);
1189 NetOut
.Write(Pl
.Team
);
1191 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1196 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1201 it
:= g_Items_ByIdx(IID
);
1203 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1205 NetOut
.Write(Byte(Quiet
));
1207 if it
.dropped
then tt
:= tt
or $80;
1209 NetOut
.Write(Byte(it
.Fall
));
1210 NetOut
.Write(Byte(it
.Respawnable
));
1211 NetOut
.Write(it
.Obj
.X
);
1212 NetOut
.Write(it
.Obj
.Y
);
1213 NetOut
.Write(it
.Obj
.Vel
.X
);
1214 NetOut
.Write(it
.Obj
.Vel
.Y
);
1216 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1219 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1221 NetOut
.Write(Byte(NET_MSG_IDEL
));
1223 NetOut
.Write(Byte(Quiet
));
1225 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1230 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1234 TP
:= g_Map_PanelByGUID(PGUID
);
1235 if (TP
= nil) then exit
;
1239 NetOut
.Write(Byte(NET_MSG_PTEX
));
1240 NetOut
.Write(LongWord(PGUID
));
1241 NetOut
.Write(FCurTexture
);
1242 NetOut
.Write(FCurFrame
);
1243 NetOut
.Write(FCurFrameCount
);
1244 NetOut
.Write(AnimLoop
);
1247 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1250 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1255 TP
:= g_Map_PanelByGUID(PGUID
);
1256 if (TP
= nil) then exit
;
1258 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1259 NetOut
.Write(LongWord(PGUID
));
1260 NetOut
.Write(Byte(TP
.Enabled
));
1261 NetOut
.Write(TP
.LiftType
);
1264 NetOut
.Write(Word(TP
.Width
));
1265 NetOut
.Write(Word(TP
.Height
));
1267 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1268 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1269 NetOut
.Write(LongInt(TP
.movingStartX
));
1270 NetOut
.Write(LongInt(TP
.movingStartY
));
1271 NetOut
.Write(LongInt(TP
.movingEndX
));
1272 NetOut
.Write(LongInt(TP
.movingEndY
));
1273 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1274 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1275 NetOut
.Write(LongInt(TP
.sizeEndX
));
1276 NetOut
.Write(LongInt(TP
.sizeEndY
));
1277 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1278 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1279 NetOut
.Write(Byte(mpflags
));
1281 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1286 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1288 if gTriggers
= nil then Exit
;
1289 if T
.Sound
= nil then Exit
;
1291 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1292 NetOut
.Write(T
.ClientID
);
1293 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1294 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1295 NetOut
.Write(T
.SoundPlayCount
);
1297 g_Net_Host_Send(ID
, True);
1300 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1302 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1303 NetOut
.Write(gMusic
.Name
);
1304 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1305 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1306 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1308 g_Net_Host_Send(ID
, True);
1313 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1317 M
:= g_Monsters_ByUID(UID
);
1323 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1325 NetOut
.Write(MonsterType
);
1326 NetOut
.Write(MonsterState
);
1327 NetOut
.Write(MonsterAnim
);
1328 NetOut
.Write(MonsterTargetUID
);
1329 NetOut
.Write(MonsterTargetTime
);
1330 NetOut
.Write(MonsterBehaviour
);
1331 NetOut
.Write(MonsterSleep
);
1332 NetOut
.Write(MonsterHealth
);
1333 NetOut
.Write(MonsterAmmo
);
1334 NetOut
.Write(GameX
);
1335 NetOut
.Write(GameY
);
1336 NetOut
.Write(GameVelX
);
1337 NetOut
.Write(GameVelY
);
1338 NetOut
.Write(Byte(GameDirection
));
1341 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1344 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1348 M
:= g_Monsters_ByUID(UID
);
1349 if M
= nil then Exit
;
1351 NetOut
.Write(Byte(NET_MSG_MPOS
));
1356 NetOut
.Write(GameX
);
1357 NetOut
.Write(GameY
);
1358 NetOut
.Write(GameVelX
);
1359 NetOut
.Write(GameVelY
);
1360 NetOut
.Write(Byte(GameDirection
));
1363 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1366 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1370 M
:= g_Monsters_ByUID(UID
);
1371 if M
= nil then Exit
;
1373 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1378 NetOut
.Write(MonsterState
);
1379 NetOut
.Write(ForcedAnim
);
1380 NetOut
.Write(MonsterTargetUID
);
1381 NetOut
.Write(MonsterTargetTime
);
1382 NetOut
.Write(MonsterSleep
);
1383 NetOut
.Write(MonsterHealth
);
1384 NetOut
.Write(MonsterAmmo
);
1385 NetOut
.Write(MonsterPain
);
1386 NetOut
.Write(Byte(AnimIsReverse
));
1387 NetOut
.Write(FFireTime
);
1390 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1393 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1395 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1402 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1405 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1409 M
:= g_Monsters_ByUID(UID
);
1410 if M
= nil then Exit
;
1412 NetOut
.Write(Byte(NET_MSG_MDEL
));
1415 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1420 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1422 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1425 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1428 procedure MH_SEND_VoteEvent(EvType
: Byte;
1429 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1430 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1431 ID
: Integer = NET_EVERYONE
);
1433 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1434 NetOut
.Write(EvType
);
1435 NetOut
.Write(IntArg1
);
1436 NetOut
.Write(IntArg2
);
1437 NetOut
.Write(StrArg1
);
1438 NetOut
.Write(StrArg2
);
1440 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1443 // CLIENT MESSAGES //
1447 procedure MC_RECV_Chat(var M
: TMsg
);
1452 Txt
:= M
.ReadString();
1453 Mode
:= M
.ReadByte();
1455 if Mode
<> NET_CHAT_SYSTEM
then
1457 if Mode
= NET_CHAT_PLAYER
then
1459 g_Console_Add(Txt
, True);
1460 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1461 g_Game_ChatSound(b_Text_Unformat(Txt
));
1463 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1465 if gPlayer1
.Team
= TEAM_RED
then
1466 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1467 if gPlayer1
.Team
= TEAM_BLUE
then
1468 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1469 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1470 g_Game_ChatSound(b_Text_Unformat(Txt
));
1473 g_Console_Add(Txt
, True);
1476 procedure MC_RECV_Effect(var M
: TMsg
);
1484 if not gGameOn
then Exit
;
1485 Kind
:= M
.ReadByte();
1486 X
:= M
.ReadLongInt();
1487 Y
:= M
.ReadLongInt();
1488 Ang
:= M
.ReadSmallInt();
1492 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1496 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1498 Anim
:= TAnimation
.Create(ID
, False, 3);
1499 g_GFX_OnceAnim(X
, Y
, Anim
);
1503 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1508 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1510 Anim
:= TAnimation
.Create(ID
, False, 6);
1511 Anim
.Blending
:= False;
1512 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1516 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1521 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1523 Anim
:= TAnimation
.Create(ID
, False, 6);
1524 Anim
.Blending
:= False;
1525 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1529 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1534 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1536 Anim
:= TAnimation
.Create(ID
, False, 4);
1537 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1544 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1546 Anim
:= TAnimation
.Create(ID
, False, 4);
1547 g_GFX_OnceAnim(X
, Y
, Anim
);
1551 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1556 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1558 Anim
:= TAnimation
.Create(ID
, False, 4);
1559 g_GFX_OnceAnim(X
, Y
, Anim
);
1563 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1567 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1570 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1574 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1575 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1580 procedure MC_RECV_Sound(var M
: TMsg
);
1586 Name
:= M
.ReadString();
1587 Pos
:= M
.ReadByte() <> 0;
1590 X
:= M
.ReadLongInt();
1591 Y
:= M
.ReadLongInt();
1592 g_Sound_PlayExAt(Name
, X
, Y
);
1595 g_Sound_PlayEx(Name
);
1598 procedure MC_RECV_CreateShot(var M
: TMsg
);
1600 I
, X
, Y
, XV
, YV
: Integer;
1602 Target
, Spawner
: Word;
1605 I
:= M
.ReadLongInt();
1606 ShType
:= M
.ReadByte();
1607 Target
:= M
.ReadWord();
1608 Spawner
:= M
.ReadWord();
1609 Timeout
:= M
.ReadLongWord();
1610 X
:= M
.ReadLongInt();
1611 Y
:= M
.ReadLongInt();
1612 XV
:= M
.ReadLongInt();
1613 YV
:= M
.ReadLongInt();
1615 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1616 if (Shots
<> nil) and (I
<= High(Shots
)) then
1618 Shots
[I
].Timeout
:= Timeout
;
1619 //Shots[I].Target := Target; // TODO: find a use for Target later
1623 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1625 I
, TX
, TY
, TXV
, TYV
: Integer;
1627 I
:= M
.ReadLongInt();
1628 TX
:= M
.ReadLongInt();
1629 TY
:= M
.ReadLongInt();
1630 TXV
:= M
.ReadLongInt();
1631 TYV
:= M
.ReadLongInt();
1633 if (Shots
<> nil) and (I
<= High(Shots
)) then
1643 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1648 if not gGameOn
then Exit
;
1649 I
:= M
.ReadLongInt();
1650 L
:= (M
.ReadByte() <> 0);
1651 X
:= M
.ReadLongInt();
1652 Y
:= M
.ReadLongInt();
1654 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1657 procedure MC_RECV_GameStats(var M
: TMsg
);
1659 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1661 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1662 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1665 if gGameSettings
.GameMode
= GM_COOP
then
1667 gCoopMonstersKilled
:= M
.ReadWord();
1668 gCoopSecretsFound
:= M
.ReadWord();
1672 procedure MC_RECV_CoopStats(var M
: TMsg
);
1674 gTotalMonsters
:= M
.ReadLongInt();
1675 gSecretsCount
:= M
.ReadLongInt();
1676 gCoopTotalMonstersKilled
:= M
.ReadWord();
1677 gCoopTotalSecretsFound
:= M
.ReadWord();
1678 gCoopTotalMonsters
:= M
.ReadWord();
1679 gCoopTotalSecrets
:= M
.ReadWord();
1682 procedure MC_RECV_GameEvent(var M
: TMsg
);
1691 i1
, i2
: TStrings_Locale
;
1695 FillChar(EvHash
, Sizeof(EvHash
), 0);
1696 EvType
:= M
.ReadByte();
1697 EvNum
:= M
.ReadLongInt();
1698 EvStr
:= M
.ReadString();
1699 gLastMap
:= M
.ReadByte() <> 0;
1700 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1701 gStatsPressed
:= True;
1702 EvTime
:= M
.ReadLongWord();
1703 BHash
:= M
.ReadByte() <> 0;
1705 EvHash
:= M
.ReadMD5();
1712 g_Res_received_map_start
:= true;
1714 g_Game_ClearLoading();
1715 g_Game_StopAllSounds(True);
1717 gSwitchGameMode
:= Byte(EvNum
);
1718 gGameSettings
.GameMode
:= gSwitchGameMode
;
1721 if not g_Game_StartMap(EvStr
, True) then
1723 if not isWadPath(EvStr
) then
1724 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1726 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1730 MC_SEND_FullStateRequest
;
1735 g_Res_received_map_start
:= true;
1736 gMissionFailed
:= EvNum
<> 0;
1737 gExit
:= EXIT_ENDLEVELCUSTOM
;
1744 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1746 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1748 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1754 if EvNum
= TEAM_RED
then
1755 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1756 if EvNum
= TEAM_BLUE
then
1757 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1761 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1764 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1767 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1769 NET_EV_LMS_SURVIVOR
:
1770 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1773 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1777 pl
:= g_Player_Get(EvNum
and $FFFF);
1782 cnt
:= (EvNum
shr 16) and $FF;
1783 if Pos('w', EvStr
) = 0 then
1786 if Pos('t', EvStr
) = 0 then
1789 if Pos('-', EvStr
) = 0 then
1791 if Pos('e', EvStr
) = 0 then
1792 i1
:= I_PLAYER_SCORE_ADD_OWN
1794 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1797 if Pos('e', EvStr
) = 0 then
1798 i1
:= I_PLAYER_SCORE_SUB_OWN
1800 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1803 if Pos('r', EvStr
) > 0 then
1804 i2
:= I_PLAYER_SCORE_TO_RED
1806 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1807 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1811 if Pos('-', EvStr
) = 0 then
1812 i1
:= I_PLAYER_SCORE_ADD_TEAM
1814 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1816 if Pos('r', EvStr
) > 0 then
1817 i2
:= I_PLAYER_SCORE_RED
1819 i2
:= I_PLAYER_SCORE_BLUE
;
1820 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1825 if Pos('e', EvStr
) = 0 then
1826 i1
:= I_PLAYER_SCORE_WIN_OWN
1828 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1830 if Pos('r', EvStr
) > 0 then
1831 i2
:= I_PLAYER_SCORE_TO_RED
1833 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1834 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1840 if EvNum
= TEAM_RED
then
1841 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1842 if EvNum
= TEAM_BLUE
then
1843 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1844 if EvNum
= -TEAM_RED
then
1845 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1846 if EvNum
= -TEAM_BLUE
then
1847 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1852 g_Player_RemoveAllCorpses
;
1853 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1857 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1861 if EvNum
= TEAM_RED
then
1862 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1863 if EvNum
= TEAM_BLUE
then
1864 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1868 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1871 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1874 g_Game_Announce_KillCombo(EvNum
);
1876 NET_EV_PLAYER_TOUCH
:
1878 pl
:= g_Player_Get(EvNum
);
1885 pl
:= g_Player_Get(EvNum
);
1888 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
1889 g_Sound_PlayEx('SOUND_GAME_SECRET');
1895 pl
:= g_Player_Get(EvNum
);
1896 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
1901 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1910 EvType
:= M
.ReadByte();
1913 if Fl
= FLAG_NONE
then Exit
;
1915 Quiet
:= (M
.ReadByte() <> 0);
1916 PID
:= M
.ReadWord();
1918 gFlags
[Fl
].State
:= M
.ReadByte();
1919 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1920 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1921 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1922 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1923 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1925 Pl
:= g_Player_Get(PID
);
1927 (EvType
<> FLAG_STATE_NORMAL
) and
1928 (EvType
<> FLAG_STATE_DROPPED
) and
1929 (EvType
<> FLAG_STATE_RETURNED
) then
1935 if Quiet
or (Pl
= nil) then Exit
;
1937 if Fl
= FLAG_RED
then
1938 s
:= _lc
[I_PLAYER_FLAG_RED
]
1940 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1942 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1944 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1945 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1946 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1951 if not sound_ret_flag
[a
].IsPlaying() then
1952 sound_ret_flag
[a
].Play();
1955 FLAG_STATE_CAPTURED
:
1957 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1961 if Fl
= FLAG_RED
then
1962 s
:= _lc
[I_PLAYER_FLAG_RED
]
1964 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1966 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
1967 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
1969 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1970 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1971 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1976 if not sound_get_flag
[a
].IsPlaying() then
1977 sound_get_flag
[a
].Play();
1982 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
1984 if Quiet
or (Pl
= nil) then Exit
;
1986 if Fl
= FLAG_RED
then
1987 s
:= _lc
[I_PLAYER_FLAG_RED
]
1989 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1991 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
1992 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
1994 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1995 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1996 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2001 if not sound_lost_flag
[a
].IsPlaying() then
2002 sound_lost_flag
[a
].Play();
2007 g_Map_ResetFlag(FLAG_RED
);
2008 g_Map_ResetFlag(FLAG_BLUE
);
2009 if Quiet
or (Pl
= nil) then Exit
;
2010 Pl
.SetFlag(FLAG_NONE
);
2012 if Fl
= FLAG_RED
then
2013 s
:= _lc
[I_PLAYER_FLAG_RED
]
2015 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2017 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2018 Insert('.', ts
, Length(ts
) + 1 - 3);
2019 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2020 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2022 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2023 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2024 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2029 if not sound_cap_flag
[a
].IsPlaying() then
2030 sound_cap_flag
[a
].Play();
2033 FLAG_STATE_RETURNED
:
2035 g_Map_ResetFlag(Fl
);
2038 if Fl
= FLAG_RED
then
2039 s
:= _lc
[I_PLAYER_FLAG_RED
]
2041 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2043 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2045 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2046 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2047 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2052 if not sound_ret_flag
[a
].IsPlaying() then
2053 sound_ret_flag
[a
].Play();
2058 procedure MC_RECV_GameSettings(var M
: TMsg
);
2060 gGameSettings
.GameMode
:= M
.ReadByte();
2061 gGameSettings
.GoalLimit
:= M
.ReadWord();
2062 gGameSettings
.TimeLimit
:= M
.ReadWord();
2063 gGameSettings
.MaxLives
:= M
.ReadByte();
2064 gGameSettings
.Options
:= M
.ReadLongWord();
2069 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2072 PName
, Model
: string;
2077 PID
:= M
.ReadWord();
2078 Pl
:= g_Player_Get(PID
);
2080 PName
:= M
.ReadString();
2081 Model
:= M
.ReadString();
2082 Color
.R
:= M
.ReadByte();
2083 Color
.G
:= M
.ReadByte();
2084 Color
.B
:= M
.ReadByte();
2088 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2090 if (Pl
<> nil) then Exit
;
2091 DID
:= g_Player_Create(Model
, Color
, T
, False);
2092 with g_Player_Get(DID
) do
2101 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2102 gPlayer1
.UID
:= PID
;
2103 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2104 gPlayer1
.ChangeTeam(T
);
2106 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2107 gPlayer2
.UID
:= PID
;
2108 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2109 gPlayer2
.ChangeTeam(T
);
2113 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2114 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2118 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2125 TmpX
, TmpY
: Integer;
2129 GT
:= M
.ReadLongWord();
2130 if GT
< gTime
- NET_MAX_DIFFTIME
then
2137 PID
:= M
.ReadWord();
2138 Pl
:= g_Player_Get(PID
);
2140 if Pl
= nil then Exit
;
2146 FPing
:= M
.ReadWord();
2147 FLoss
:= M
.ReadByte();
2148 kByte
:= M
.ReadWord();
2149 Dir
:= M
.ReadByte();
2151 TmpX
:= M
.ReadLongInt();
2152 TmpY
:= M
.ReadLongInt();
2156 if (kByte
= NET_KEY_CHAT
) then
2157 PressKey(KEY_CHAT
, 10000)
2160 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2161 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2162 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2163 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2164 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2167 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2168 SetDirection(TDirection(Dir
));
2170 GameVelX
:= M
.ReadLongInt();
2171 GameVelY
:= M
.ReadLongInt();
2172 GameAccelX
:= M
.ReadLongInt();
2173 GameAccelY
:= M
.ReadLongInt();
2174 SetLerp(TmpX
, TmpY
);
2175 if NetForcePlayerUpdate
then Update();
2179 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2183 I
, OldFire
: Integer;
2184 OldJet
, Flam
: Boolean;
2187 PID
:= M
.ReadWord();
2188 Pl
:= g_Player_Get(PID
);
2195 alive
:= (M
.ReadByte() <> 0);
2196 GodMode
:= (M
.ReadByte() <> 0);
2197 Health
:= M
.ReadLongInt();
2198 Armor
:= M
.ReadLongInt();
2199 Air
:= M
.ReadLongInt();
2200 JetFuel
:= M
.ReadLongInt();
2201 Lives
:= M
.ReadByte();
2202 NewTeam
:= M
.ReadByte();
2204 for I
:= WP_FIRST
to WP_LAST
do
2205 FWeapon
[I
] := (M
.ReadByte() <> 0);
2207 for I
:= A_BULLETS
to A_HIGH
do
2208 FAmmo
[I
] := M
.ReadWord();
2210 for I
:= A_BULLETS
to A_HIGH
do
2211 FMaxAmmo
[I
] := M
.ReadWord();
2213 for I
:= MR_SUIT
to MR_MAX
do
2214 FMegaRulez
[I
] := M
.ReadLongWord();
2217 if (M
.ReadByte() <> 0) then
2218 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2219 if (M
.ReadByte() <> 0) then
2220 FRulez
:= FRulez
+ [R_KEY_RED
];
2221 if (M
.ReadByte() <> 0) then
2222 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2223 if (M
.ReadByte() <> 0) then
2224 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2225 if (M
.ReadByte() <> 0) then
2226 FRulez
:= FRulez
+ [R_BERSERK
];
2228 Frags
:= M
.ReadLongInt();
2229 Death
:= M
.ReadLongInt();
2231 SetWeapon(M
.ReadByte());
2233 FSpectator
:= M
.ReadByte() <> 0;
2236 if Pl
= gPlayer1
then
2241 if Pl
= gPlayer2
then
2249 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2250 gPlayer1
:= g_Player_Get(gLMSPID1
);
2251 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2252 gPlayer2
:= g_Player_Get(gLMSPID2
);
2254 FGhost
:= M
.ReadByte() <> 0;
2255 FPhysics
:= M
.ReadByte() <> 0;
2256 FNoRespawn
:= M
.ReadByte() <> 0;
2258 FJetpack
:= M
.ReadByte() <> 0;
2259 OldFire
:= FFireTime
;
2260 FFireTime
:= M
.ReadLongInt();
2261 if (OldFire
<= 0) and (FFireTime
> 0) then
2262 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2263 Flam
:= M
.ReadByte() <> 0;
2264 if OldJet
and not FJetpack
then
2266 else if not OldJet
and FJetpack
then
2268 if FFlaming
and not Flam
then
2270 if Team
<> NewTeam
then
2271 Pl
.ChangeTeam(NewTeam
);
2277 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2282 Attacker
, Value
: Word;
2286 if not gGameOn
then Exit
;
2287 PID
:= M
.ReadWord();
2288 Pl
:= g_Player_Get(PID
);
2289 if Pl
= nil then Exit
;
2291 Kind
:= M
.ReadByte();
2292 Attacker
:= M
.ReadWord();
2293 Value
:= M
.ReadWord();
2298 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2303 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2307 KillType
, DeathType
: Byte;
2311 if not gGameOn
then Exit
;
2312 PID
:= M
.ReadWord();
2313 Pl
:= g_Player_Get(PID
);
2314 if Pl
= nil then Exit
;
2316 KillType
:= M
.ReadByte();
2317 DeathType
:= M
.ReadByte();
2318 Attacker
:= M
.ReadWord();
2322 Kill(KillType
, Attacker
, DeathType
);
2327 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2332 PID
:= M
.ReadWord();
2333 Pl
:= g_Player_Get(PID
);
2335 if Pl
= nil then Exit
;
2337 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2338 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2340 g_Player_Remove(PID
);
2345 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2350 X
, Y
, AX
, AY
: Integer;
2354 if not gGameOn
then Exit
;
2355 PID
:= M
.ReadWord();
2356 Pl
:= g_Player_Get(PID
);
2357 if Pl
= nil then Exit
;
2359 Weap
:= M
.ReadByte();
2360 X
:= M
.ReadLongInt();
2361 Y
:= M
.ReadLongInt();
2362 AX
:= M
.ReadLongInt();
2363 AY
:= M
.ReadLongInt();
2364 SHID
:= M
.ReadLongInt();
2367 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2370 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2379 PID
:= M
.ReadWord();
2380 Pl
:= g_Player_Get(PID
);
2381 if Pl
= nil then Exit
;
2383 TmpName
:= M
.ReadString();
2384 TmpModel
:= M
.ReadString();
2385 TmpColor
.R
:= M
.ReadByte();
2386 TmpColor
.G
:= M
.ReadByte();
2387 TmpColor
.B
:= M
.ReadByte();
2388 TmpTeam
:= M
.ReadByte();
2390 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2392 Pl
.ChangeTeam(TmpTeam
);
2393 if gPlayer1
= Pl
then
2394 gPlayer1Settings
.Team
:= TmpTeam
;
2395 if gPlayer2
= Pl
then
2396 gPlayer2Settings
.Team
:= TmpTeam
;
2398 Pl
.SetColor(TmpColor
);
2400 if Pl
.Name
<> TmpName
then
2402 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2406 if TmpModel
<> Pl
.Model
.Name
then
2407 Pl
.SetModel(TmpModel
);
2412 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2416 X
, Y
, VX
, VY
: Integer;
2418 Quiet
, Fall
{, Resp}: Boolean;
2422 if not gGameOn
then Exit
;
2424 Quiet
:= M
.ReadByte() <> 0;
2426 Fall
:= M
.ReadByte() <> 0;
2427 {Resp :=} M
.ReadByte();
2428 X
:= M
.ReadLongInt();
2429 Y
:= M
.ReadLongInt();
2430 VX
:= M
.ReadLongInt();
2431 VY
:= M
.ReadLongInt();
2433 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2434 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2436 it
:= g_Items_ByIdx(ID
);
2442 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2443 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2445 Anim
:= TAnimation
.Create(AID
, False, 4);
2446 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2452 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2457 if not gGameOn
then Exit
;
2459 Quiet
:= M
.ReadByte() <> 0;
2461 if not g_Items_ValidId(ID
) then exit
;
2463 if not Quiet
then g_Items_EmitPickupSound(ID
);
2470 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2477 if not gGameOn
then Exit
;
2479 PGUID
:= Integer(M
.ReadLongWord());
2480 Tex
:= M
.ReadLongInt();
2481 Fr
:= M
.ReadLongInt();
2482 Cnt
:= M
.ReadByte();
2483 Loop
:= M
.ReadByte();
2485 TP
:= g_Map_PanelByGUID(PGUID
);
2489 TP
.SetTexture(Tex
, Loop
);
2490 TP
.SetFrame(Fr
, Cnt
);
2494 procedure MC_RECV_PanelState(var M
: TMsg
);
2499 X
, Y
, W
, H
: Integer;
2501 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2502 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2505 if not gGameOn
then Exit
;
2507 PGUID
:= Integer(M
.ReadLongWord());
2508 E
:= (M
.ReadByte() <> 0);
2509 Lift
:= M
.ReadByte();
2510 X
:= M
.ReadLongInt();
2511 Y
:= M
.ReadLongInt();
2515 speedX
:= M
.ReadLongInt();
2516 speedY
:= M
.ReadLongInt();
2517 startX
:= M
.ReadLongInt();
2518 startY
:= M
.ReadLongInt();
2519 endX
:= M
.ReadLongInt();
2520 endY
:= M
.ReadLongInt();
2521 sizeSpX
:= M
.ReadLongInt();
2522 sizeSpY
:= M
.ReadLongInt();
2523 sizeEX
:= M
.ReadLongInt();
2524 sizeEY
:= M
.ReadLongInt();
2525 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2527 TP
:= g_Map_PanelByGUID(PGUID
);
2528 if (TP
= nil) then exit
;
2530 // update lifts state
2531 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2533 // update enabled/disabled state for all panels
2534 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2536 // update panel position, as it can be moved (mplat)
2541 // update mplat state
2542 TP
.movingSpeedX
:= speedX
;
2543 TP
.movingSpeedY
:= speedY
;
2544 TP
.movingStartX
:= startX
;
2545 TP
.movingStartY
:= startY
;
2546 TP
.movingEndX
:= endX
;
2547 TP
.movingEndY
:= endY
;
2548 TP
.sizeSpeedX
:= sizeSpX
;
2549 TP
.sizeSpeedY
:= sizeSpY
;
2550 TP
.sizeEndX
:= sizeEX
;
2551 TP
.sizeEndY
:= sizeEY
;
2552 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2553 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2554 // notify panel of it's position/size change, so it can fix other internal structures
2555 TP
.positionChanged();
2560 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2563 SPos
, SID
: LongWord;
2567 if not gGameOn
then Exit
;
2568 if gTriggers
= nil then Exit
;
2570 SID
:= M
.ReadLongWord();
2571 SPlaying
:= M
.ReadByte() <> 0;
2572 SPos
:= M
.ReadLongWord();
2573 SCount
:= M
.ReadLongInt();
2575 for I
:= Low(gTriggers
) to High(gTriggers
) do
2576 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2577 if gTriggers
[I
].ClientID
= SID
then
2578 with gTriggers
[I
] do
2580 if Sound
<> nil then
2585 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2587 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2588 Sound
.SetPosition(SPos
);
2591 if Sound
.IsPlaying
then Sound
.Stop
;
2594 SoundPlayCount
:= SCount
;
2598 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2605 if not gGameOn
then Exit
;
2607 MName
:= M
.ReadString();
2608 MPlaying
:= M
.ReadByte() <> 0;
2609 MPos
:= M
.ReadLongWord();
2610 MPaused
:= M
.ReadByte() <> 0;
2611 MPos
:= MPos
+1; //k8: stfu, fpc!
2615 gMusic
.SetByName(MName
);
2617 // gMusic.SetPosition(MPos);
2618 gMusic
.SpecPause
:= MPaused
;
2621 if gMusic
.IsPlaying
then gMusic
.Stop
;
2626 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2629 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2630 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2635 Mon
:= g_Monsters_ByUID(ID
);
2639 MType
:= M
.ReadByte();
2640 MState
:= M
.ReadByte();
2641 MAnim
:= M
.ReadByte();
2642 MTarg
:= M
.ReadWord();
2643 MTargTime
:= M
.ReadLongInt();
2644 MBehav
:= M
.ReadByte();
2645 MSleep
:= M
.ReadLongInt();
2646 MHealth
:= M
.ReadLongInt();
2647 MAmmo
:= M
.ReadLongInt();
2649 X
:= M
.ReadLongInt();
2650 Y
:= M
.ReadLongInt();
2651 VX
:= M
.ReadLongInt();
2652 VY
:= M
.ReadLongInt();
2653 MDir
:= M
.ReadByte();
2655 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2656 Mon
:= g_Monsters_ByUID(ID
);
2663 MonsterAnim
:= MAnim
;
2664 MonsterTargetUID
:= MTarg
;
2665 MonsterTargetTime
:= MTargTime
;
2666 MonsterBehaviour
:= MBehav
;
2667 MonsterSleep
:= MSleep
;
2668 MonsterAmmo
:= MAmmo
;
2673 setPosition(X
, Y
); // this will call positionChanged();
2679 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2686 Mon
:= g_Monsters_ByUID(ID
);
2692 X
:= M
.ReadLongInt();
2693 Y
:= M
.ReadLongInt();
2694 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2695 GameVelX
:= M
.ReadLongInt();
2696 GameVelY
:= M
.ReadLongInt();
2697 GameDirection
:= TDirection(M
.ReadByte());
2701 procedure MC_RECV_MonsterState(var M
: TMsg
);
2703 ID
, OldFire
: Integer;
2704 MState
, MFAnm
: Byte;
2706 AnimRevert
: Boolean;
2709 Mon
:= g_Monsters_ByUID(ID
);
2710 if Mon
= nil then Exit
;
2712 MState
:= M
.ReadByte();
2713 MFAnm
:= M
.ReadByte();
2717 MonsterTargetUID
:= M
.ReadWord();
2718 MonsterTargetTime
:= M
.ReadLongInt();
2719 MonsterSleep
:= M
.ReadLongInt();
2720 MonsterHealth
:= M
.ReadLongInt();
2721 MonsterAmmo
:= M
.ReadLongInt();
2722 MonsterPain
:= M
.ReadLongInt();
2723 AnimRevert
:= M
.ReadByte() <> 0;
2724 OldFire
:= FFireTime
;
2725 FFireTime
:= M
.ReadLongInt();
2726 if (OldFire
<= 0) and (FFireTime
> 0) then
2727 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2728 RevertAnim(AnimRevert
);
2730 if MonsterState
<> MState
then
2732 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2733 if (MState
= MONSTATE_DIE
) then DieSound();
2734 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2735 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2736 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2738 SetState(MState
, MFAnm
);
2743 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2747 X
, Y
, VX
, VY
: Integer;
2751 Mon
:= g_Monsters_ByUID(ID
);
2752 if Mon
= nil then Exit
;
2754 X
:= M
.ReadLongInt();
2755 Y
:= M
.ReadLongInt();
2756 VX
:= M
.ReadLongInt();
2757 VY
:= M
.ReadLongInt();
2759 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2762 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2768 Mon
:= g_Monsters_ByUID(ID
);
2769 if Mon
= nil then Exit
;
2771 Mon
.MonsterRemoved
:= True;
2774 procedure MC_RECV_TimeSync(var M
: TMsg
);
2778 Time
:= M
.ReadLongWord();
2780 if gState
= STATE_INTERCUSTOM
then
2781 gServInterTime
:= Min(Time
, 255);
2784 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2788 Int1
, Int2
: SmallInt;
2790 EvID
:= M
.ReadByte();
2791 Int1
:= M
.ReadSmallInt();
2792 Int2
:= M
.ReadSmallInt();
2793 Str1
:= M
.ReadString();
2794 Str2
:= M
.ReadString();
2798 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2800 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2802 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2804 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2806 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2812 procedure MC_SEND_Info(Password
: string);
2816 NetOut
.Write(Byte(NET_MSG_INFO
));
2817 NetOut
.Write(GAME_VERSION
);
2818 NetOut
.Write(Password
);
2819 NetOut
.Write(gPlayer1Settings
.Name
);
2820 NetOut
.Write(gPlayer1Settings
.Model
);
2821 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2822 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2823 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2824 NetOut
.Write(gPlayer1Settings
.Team
);
2826 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2829 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2831 NetOut
.Write(Byte(NET_MSG_CHAT
));
2835 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2838 procedure MC_SEND_PlayerPos();
2843 WeaponSelect
: Word = 0;
2846 if not gGameOn
then Exit
;
2847 if gPlayers
= nil then Exit
;
2848 if gPlayer1
= nil then Exit
;
2851 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2853 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2855 strafeDir
:= P1MoveButton
shr 4;
2856 P1MoveButton
:= P1MoveButton
and $0F;
2858 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2860 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2862 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2866 if gPlayerAction
[0, ACTION_STRAFE
] then
2868 // new strafe mechanics
2869 if (strafeDir
= 0) then
2870 strafeDir
:= P1MoveButton
; // start strafing
2871 // now set direction according to strafe (reversed)
2872 if (strafeDir
= 2) then
2873 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2874 else if (strafeDir
= 1) then
2875 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2879 strafeDir
:= 0; // not strafing anymore
2880 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
2881 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2882 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2883 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2884 else if P1MoveButton
<> 0 then
2885 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2888 gPlayer1
.ReleaseKeys
;
2889 if P1MoveButton
= 1 then
2891 kByte
:= kByte
or NET_KEY_LEFT
;
2892 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2894 if P1MoveButton
= 2 then
2896 kByte
:= kByte
or NET_KEY_RIGHT
;
2897 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2899 if gPlayerAction
[0, ACTION_LOOKUP
] then
2901 kByte
:= kByte
or NET_KEY_UP
;
2902 gPlayer1
.PressKey(KEY_UP
, 10000);
2904 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2906 kByte
:= kByte
or NET_KEY_DOWN
;
2907 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2909 if gPlayerAction
[0, ACTION_JUMP
] then
2911 kByte
:= kByte
or NET_KEY_JUMP
;
2912 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2914 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
2915 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
2916 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
2917 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
2919 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2920 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2922 for i
:= WP_FIRST
to WP_LAST
do
2924 if gSelectWeapon
[0, i
] then
2926 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
2927 gSelectWeapon
[0, i
] := False
2931 // fix movebutton state
2932 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2935 kByte
:= NET_KEY_CHAT
;
2937 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2938 NetOut
.Write(gTime
);
2939 NetOut
.Write(kByte
);
2940 NetOut
.Write(Byte(gPlayer1
.Direction
));
2941 NetOut
.Write(WeaponSelect
);
2942 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2943 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2945 //kBytePrev := kByte;
2946 //kDirPrev := gPlayer1.Direction;
2949 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2951 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2952 NetOut
.Write(Byte(Start
));
2953 NetOut
.Write(Command
);
2954 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2957 procedure MC_SEND_PlayerSettings();
2959 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2960 NetOut
.Write(gPlayer1Settings
.Name
);
2961 NetOut
.Write(gPlayer1Settings
.Model
);
2962 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2963 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2964 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2965 NetOut
.Write(gPlayer1Settings
.Team
);
2967 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2970 procedure MC_SEND_FullStateRequest();
2972 NetOut
.Write(Byte(NET_MSG_REQFST
));
2974 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2977 procedure MC_SEND_CheatRequest(Kind
: Byte);
2979 NetOut
.Write(Byte(NET_MSG_CHEAT
));
2982 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2984 procedure MC_SEND_RCONPassword(Password
: string);
2986 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
2987 NetOut
.Write(Password
);
2989 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2991 procedure MC_SEND_RCONCommand(Cmd
: string);
2993 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
2996 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2999 // i have no idea why all this stuff is in here
3001 function ReadFile(const FileName
: TFileName
): AByte
;
3003 FileStream
: TStream
;
3006 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName
]), TMsgType
.Notify
);
3007 fname
:= findDiskWad(FileName
);
3008 if length(fname
) = 0 then
3010 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName
]), TMsgType
.Fatal
);
3011 SetLength(Result
, 0);
3014 e_WriteLog(Format('NETWORK: found file "%s"', [fname
]), TMsgType
.Notify
);
3016 FileStream
:= openDiskFileRO(fname
);
3018 if FileStream
.Size
> 0 then
3020 SetLength(Result
, FileStream
.Size
);
3021 FileStream
.Read(Result
[0], FileStream
.Size
);
3028 function CreateMapDataMsg(const FileName
: TFileName
; ResList
: TStringList
): TMapDataMsg
;
3032 Result
.MsgId
:= NET_MSG_MAP_RESPONSE
;
3033 Result
.FileData
:= ReadFile(FileName
);
3034 Result
.FileSize
:= Length(Result
.FileData
);
3036 SetLength(Result
.ExternalResources
, ResList
.Count
);
3037 for i
:=0 to ResList
.Count
-1 do
3039 Result
.ExternalResources
[i
].Name
:= ResList
.Strings
[i
];
3040 Result
.ExternalResources
[i
].md5
:= MD5File(GameDir
+'/wads/'+ResList
.Strings
[i
]);
3044 procedure ResDataMsgToBytes(var bytes
: AByte
; const ResData
: TResDataMsg
);
3046 ResultStream
: TMemoryStream
;
3048 ResultStream
:= TMemoryStream
.Create
;
3050 ResultStream
.WriteBuffer(ResData
.MsgId
, SizeOf(ResData
.MsgId
)); //msgId
3051 ResultStream
.WriteBuffer(ResData
.FileSize
, SizeOf(ResData
.FileSize
)); //file size
3052 ResultStream
.WriteBuffer(ResData
.FileData
[0], ResData
.FileSize
); //file data
3054 SetLength(bytes
, ResultStream
.Size
);
3055 ResultStream
.Seek(0, soFromBeginning
);
3056 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3061 function ResDataFromMsgStream(msgStream
: TMemoryStream
):TResDataMsg
;
3063 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3064 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
));
3065 SetLength(Result
.FileData
, Result
.FileSize
);
3066 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
);
3069 procedure MapDataMsgToBytes(var bytes
: AByte
; const MapDataMsg
: TMapDataMsg
);
3071 ResultStream
: TMemoryStream
;
3074 resCount
:= Length(MapDataMsg
.ExternalResources
);
3076 ResultStream
:= TMemoryStream
.Create
;
3078 ResultStream
.WriteBuffer(MapDataMsg
.MsgId
, SizeOf(MapDataMsg
.MsgId
)); //msgId
3079 ResultStream
.WriteBuffer(MapDataMsg
.FileSize
, SizeOf(MapDataMsg
.FileSize
)); //file size
3080 ResultStream
.WriteBuffer(MapDataMsg
.FileData
[0], MapDataMsg
.FileSize
); //file data
3082 ResultStream
.WriteBuffer(resCount
, SizeOf(resCount
)); //res count
3083 ResultStream
.WriteBuffer(MapDataMsg
.ExternalResources
[0], resCount
*SizeOf(TExternalResourceInfo
)); //res data
3085 SetLength(bytes
, ResultStream
.Size
);
3086 ResultStream
.Seek(0, soFromBeginning
);
3087 ResultStream
.ReadBuffer(bytes
[0], ResultStream
.Size
);
3092 function MapDataFromMsgStream(msgStream
: TMemoryStream
):TMapDataMsg
;
3096 msgStream
.ReadBuffer(Result
.MsgId
, SizeOf(Result
.MsgId
));
3097 msgStream
.ReadBuffer(Result
.FileSize
, SizeOf(Result
.FileSize
)); //file size
3099 SetLength(Result
.FileData
, Result
.FileSize
);
3100 msgStream
.ReadBuffer(Result
.FileData
[0], Result
.FileSize
); //file data
3102 msgStream
.ReadBuffer(resCount
, SizeOf(resCount
)); //res count
3103 SetLength(Result
.ExternalResources
, resCount
);
3105 msgStream
.ReadBuffer(Result
.ExternalResources
[0], resCount
* SizeOf(TExternalResourceInfo
)); //res data
3108 function IsValidFileName(const S
: String): Boolean;
3110 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3115 for I
:= 1 to Length(S
) do
3116 Result
:= Result
and (not(S
[I
] in Forbidden
));
3119 function IsValidFilePath(const S
: String): Boolean;
3124 if not IsValidFileName(S
) then exit
;
3125 if FileExists(S
) then exit
;
3126 I
:= LastDelimiter('\/', S
);
3128 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
3133 procedure MC_SEND_MapRequest();
3135 NetOut
.Write(Byte(NET_MSG_MAP_REQUEST
));
3136 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3139 procedure MC_SEND_ResRequest(const resName
: AnsiString);
3141 NetOut
.Write(Byte(NET_MSG_RES_REQUEST
));
3142 NetOut
.Write(resName
);
3143 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3146 procedure MH_RECV_MapRequest(C
: pTNetClient
; var M
: TMsg
);
3150 mapDataMsg
: TMapDataMsg
;
3152 e_WriteLog('NET: Received map request from ' +
3153 DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3156 omsg.Alloc(NET_BUFSIZE);
3159 dfn := findDiskWad(MapsDir+gGameSettings.WAD);
3160 if (dfn = '') then dfn := '!wad_not_found!.wad'; //FIXME
3161 md5 := MD5File(dfn);
3162 st := openDiskFileRO(dfn);
3163 if not assigned(st) then exit; //wtf?!
3167 omsg.Write(Byte({NTF_SERVER_MAP_INFO}NET_MSG_MAP_RESPONSE));
3169 omsg.Write(gGameSettings.WAD);
3174 // number of external resources for map
3175 omsg.Write(LongInt(gExternalResources.Count));
3176 // external resource names
3177 for f := 0 to gExternalResources.Count-1 do
3179 omsg.Write(ExtractFileName(gExternalResources[f])); // GameDir+'/wads/'+ResList.Strings[i]
3182 pkt := enet_packet_create(omsg.Data, omsg.CurSize, ENET_PACKET_FLAG_RELIABLE);
3183 if not Assigned(pkt) then exit;
3184 peer := NetClients[C^.ID].Peer;
3185 if (enet_peer_send(Peer, NET_CHAN_DOWNLOAD_EX, pkt) <> 0) then exit;
3190 mapDataMsg
:= CreateMapDataMsg(MapsDir
+ gGameSettings
.WAD
, gExternalResources
);
3191 peer
:= NetClients
[C
^.ID
].Peer
;
3193 MapDataMsgToBytes(payload
, mapDataMsg
);
3194 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);
3197 mapDataMsg
.FileData
:= nil;
3198 mapDataMsg
.ExternalResources
:= nil;
3201 procedure MH_RECV_ResRequest(C
: pTNetClient
; var M
: TMsg
);
3206 resDataMsg
: TResDataMsg
;
3208 FileName
:= ExtractFileName(M
.ReadString());
3209 e_WriteLog('NET: Received res request: ' + FileName
+
3210 ' from ' + DecodeIPV4(C
^.Peer
.address
.host
), TMsgType
.Notify
);
3212 if not IsValidFilePath(FileName
) then
3214 e_WriteLog('Invalid filename: ' + FileName
, TMsgType
.Warning
);
3218 peer
:= NetClients
[C
^.ID
].Peer
;
3220 if gExternalResources
.IndexOf(FileName
) > -1 then
3222 resDataMsg
.MsgId
:= NET_MSG_RES_RESPONSE
;
3223 resDataMsg
.FileData
:= ReadFile(GameDir
+'/wads/'+FileName
);
3224 resDataMsg
.FileSize
:= Length(resDataMsg
.FileData
);
3226 ResDataMsgToBytes(payload
, resDataMsg
);
3227 g_Net_SendData(payload
, peer
, True, NET_CHAN_DOWNLOAD
);