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;
70 NET_MSG_MAP_REQUEST = 201;
71 NET_MSG_MAP_RESPONSE = 202;
72 NET_MSG_RES_REQUEST = 203;
73 NET_MSG_RES_RESPONSE = 204;
97 NET_EV_CHANGE_TEAM
= 3;
98 NET_EV_PLAYER_KICK
= 4;
99 NET_EV_PLAYER_BAN
= 5;
100 NET_EV_LMS_WARMUP
= 6;
101 NET_EV_LMS_SURVIVOR
= 7;
105 NET_EV_SCORE_MSG
= 11;
106 NET_EV_LMS_START
= 12;
108 NET_EV_TLMS_WIN
= 14;
109 NET_EV_LMS_LOSE
= 15;
110 NET_EV_LMS_DRAW
= 16;
111 NET_EV_KILLCOMBO
= 17;
112 NET_EV_PLAYER_TOUCH
= 18;
114 NET_EV_INTER_READY
= 20;
121 NET_VE_INPROGRESS
= 6;
128 NET_CHEAT_SUICIDE
= 1;
129 NET_CHEAT_SPECTATE
= 2;
132 NET_MAX_DIFFTIME
= 5000 div 36;
136 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
137 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
138 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
139 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
140 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
141 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
142 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
143 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
144 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
145 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
146 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
149 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
150 procedure MH_SEND_Info(ID
: Byte);
151 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
152 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
153 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
154 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
155 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
166 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
170 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
175 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
178 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
181 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
187 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_VoteEvent(EvType
: Byte;
189 StrArg1
: string = 'a'; StrArg2
: string = 'b';
190 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
191 ID
: Integer = NET_EVERYONE
);
193 // CLIENT MESSAGES //
196 procedure MC_RECV_Chat(var M
: TMsg
);
197 procedure MC_RECV_Effect(var M
: TMsg
);
198 procedure MC_RECV_Sound(var M
: TMsg
);
199 procedure MC_RECV_GameStats(var M
: TMsg
);
200 procedure MC_RECV_CoopStats(var M
: TMsg
);
201 procedure MC_RECV_GameEvent(var M
: TMsg
);
202 procedure MC_RECV_FlagEvent(var M
: TMsg
);
203 procedure MC_RECV_GameSettings(var M
: TMsg
);
205 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
206 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
207 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
208 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
209 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
210 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
211 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
212 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
214 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
215 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
217 procedure MC_RECV_PanelTexture(var M
: TMsg
);
218 procedure MC_RECV_PanelState(var M
: TMsg
);
220 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
221 procedure MC_RECV_MonsterPos(var M
: TMsg
);
222 procedure MC_RECV_MonsterState(var M
: TMsg
);
223 procedure MC_RECV_MonsterShot(var M
: TMsg
);
224 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
226 procedure MC_RECV_CreateShot(var M
: TMsg
);
227 procedure MC_RECV_UpdateShot(var M
: TMsg
);
228 procedure MC_RECV_DeleteShot(var M
: TMsg
);
230 procedure MC_RECV_TriggerSound(var M
: TMsg
);
231 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
233 procedure MC_RECV_TimeSync(var M
: TMsg
);
234 procedure MC_RECV_VoteEvent(var M
: TMsg
);
236 procedure MC_SEND_Info(Password
: string);
237 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
238 procedure MC_SEND_PlayerPos();
239 procedure MC_SEND_FullStateRequest();
240 procedure MC_SEND_PlayerSettings();
241 procedure MC_SEND_CheatRequest(Kind
: Byte);
242 procedure MC_SEND_RCONPassword(Password
: string);
243 procedure MC_SEND_RCONCommand(Cmd
: string);
244 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
246 //procedure MC_SEND_MapRequest();
247 //procedure MC_SEND_ResRequest(const resName: AnsiString);
251 TExternalResourceInfo
= record
266 ExternalResources
: array of TExternalResourceInfo
;
269 function IsValidFileName(const S
: String): Boolean;
270 function IsValidFilePath(const S
: String): Boolean;
276 Math
, ENet
, e_input
, e_graphics
, e_log
,
277 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
278 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
279 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
292 NET_KEY_FORCEDIR
= 4096;
295 //kBytePrev: Word = 0;
296 //kDirPrev: TDirection = D_LEFT;
297 //HostGameTime: Word = 0;
300 function IsValidFileName(const S
: String): Boolean;
302 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
307 for I
:= 1 to Length(S
) do
308 Result
:= Result
and (not(S
[I
] in Forbidden
));
311 function IsValidFilePath(const S
: String): Boolean;
316 if not IsValidFileName(S
) then exit
;
317 if FileExists(S
) then exit
;
318 I
:= LastDelimiter('\/', S
);
320 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
331 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
339 Pl
:= g_Player_Get(PID
);
341 Txt
:= M
.ReadString();
342 Mode
:= M
.ReadByte();
343 if (Mode
= NET_CHAT_SYSTEM
) then
344 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
345 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
346 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
349 MH_SEND_Chat(Txt
, Mode
)
351 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
354 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
356 Ver
, PName
, Model
, Pw
: string;
362 Ver
:= M
.ReadString();
363 Pw
:= M
.ReadString();
364 PName
:= M
.ReadString();
365 Model
:= M
.ReadString();
371 if Ver
<> GAME_VERSION
then
373 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
374 _lc
[I_NET_DISC_VERSION
]);
375 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
379 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
381 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
383 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
384 _lc
[I_NET_DISC_BAN
]);
385 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
389 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
390 _lc
[I_NET_DISC_BAN
]);
391 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
396 if NetPassword
<> '' then
397 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
399 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
400 _lc
[I_NET_DISC_PASSWORD
]);
401 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
409 PID
:= g_Player_Create(Model
, Color
, T
, False);
410 with g_Player_Get(PID
) do
418 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
419 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
420 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
424 with g_Player_Get(PID
) do
428 // round in progress, don't spawn
429 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
434 FWantsInGame
:= True; // TODO: look into this later
437 Respawn(gGameSettings
.GameType
= GT_SINGLE
);
440 for I
:= Low(NetClients
) to High(NetClients
) do
442 if NetClients
[I
].ID
= C
^.ID
then Continue
;
443 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
444 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
445 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
448 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
449 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
451 if NetUseMaster
then g_Net_Slist_Update
;
454 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
457 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
459 C
^.RequestedFullUpdate
:= True;
464 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
474 if not gGameOn
then Exit
;
476 GT
:= M
.ReadLongWord();
478 Pl
:= g_Player_Get(PID
);
482 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
487 kByte
:= M
.ReadWord();
489 WeaponSelect
:= M
.ReadWord();
490 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
491 if Direction
<> TDirection(Dir
) then
492 JustTeleported
:= False;
494 SetDirection(TDirection(Dir
));
497 if kByte
= NET_KEY_CHAT
then
499 PressKey(KEY_CHAT
, 10000);
503 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
504 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
505 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
506 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
507 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
508 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
509 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
510 if LongBool(kByte
and NET_KEY_NW
) then PressKey(KEY_NEXTWEAPON
, 10000);
511 if LongBool(kByte
and NET_KEY_PW
) then PressKey(KEY_PREVWEAPON
, 10000);
515 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
517 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
518 QueueWeaponSwitch(i
);
523 // MH_SEND_PlayerPos(False, PID, C^.ID);
526 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
531 Pl
:= g_Player_Get(C
^.Player
);
532 if Pl
= nil then Exit
;
534 CheatKind
:= M
.ReadByte();
538 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
541 if Pl
.FSpectator
then
548 if gState
<> STATE_INTERCUSTOM
then Exit
;
549 Pl
.FReady
:= not Pl
.FReady
;
552 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
553 Inc(gInterReadyCount
);
557 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
558 Dec(gInterReadyCount
);
564 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
572 TmpName
:= M
.ReadString();
573 TmpModel
:= M
.ReadString();
574 TmpColor
.R
:= M
.ReadByte();
575 TmpColor
.G
:= M
.ReadByte();
576 TmpColor
.B
:= M
.ReadByte();
577 TmpTeam
:= M
.ReadByte();
579 Pl
:= g_Player_Get(C
^.Player
);
580 if Pl
= nil then Exit
;
582 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
585 Pl
.SetColor(TmpColor
);
587 if Pl
.Name
<> TmpName
then
589 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
593 if TmpModel
<> Pl
.Model
.Name
then
594 Pl
.SetModel(TmpModel
);
596 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
601 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
605 Pwd
:= M
.ReadString();
606 if not NetAllowRCON
then Exit
;
607 if Pwd
= NetRCONPassword
then
610 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
613 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
616 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
620 Cmd
:= M
.ReadString();
621 if not NetAllowRCON
then Exit
;
622 if not C
^.RCONAuth
then
624 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
627 g_Console_Process(Cmd
);
632 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
635 Name
, Command
: string;
639 Start
:= M
.ReadByte() <> 0;
640 Command
:= M
.ReadString();
642 Pl
:= g_Player_Get(C
^.Player
);
643 if Pl
= nil then Exit
;
648 if not g_Console_CommandBlacklisted(Command
) then
649 g_Game_StartVote(Command
, Name
);
651 else if gVoteInProgress
then
653 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
654 Need
:= Floor((NetClientCount
+1)/2.0) + 1
656 Need
:= Floor(NetClientCount
/2.0) + 1;
661 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
662 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
668 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
669 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
677 procedure MH_SEND_Everything(CreatePlayers
: Boolean = False; ID
: Integer = NET_EVERYONE
);
679 function sendItemRespawn (it
: PItem
): Boolean;
681 result
:= false; // don't stop
682 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
685 function sendMonSpawn (mon
: TMonster
): Boolean;
687 result
:= false; // don't stop
688 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
691 function sendPanelState (pan
: TPanel
): Boolean;
693 result
:= false; // don't stop
694 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
695 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
701 if gPlayers
<> nil then
703 for I
:= Low(gPlayers
) to High(gPlayers
) do
705 if gPlayers
[I
] <> nil then
707 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
708 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
709 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
711 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
713 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
719 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
720 g_Mons_ForEach(sendMonSpawn
);
721 g_Map_ForEachPanel(sendPanelState
);
723 if gTriggers
<> nil then
725 for I
:= Low(gTriggers
) to High(gTriggers
) do
727 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
729 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
736 for I
:= Low(Shots
) to High(Shots
) do
738 if Shots
[i
].ShotType
in [6, 7, 8] then
740 MH_SEND_CreateShot(i
, ID
);
745 MH_SEND_TriggerMusic(ID
);
747 MH_SEND_GameStats(ID
);
748 MH_SEND_CoopStats(ID
);
750 if gGameSettings
.GameMode
= GM_CTF
then
752 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
753 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
756 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
758 if gLMSRespawn
> LMS_RESPAWN_NONE
then
760 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000, 'N', ID
);
766 procedure MH_SEND_Info(ID
: Byte);
770 Map
:= g_ExtractFileName(gMapInfo
.Map
);
774 NetOut
.Write(Byte(NET_MSG_INFO
));
776 NetOut
.Write(NetClients
[ID
].Player
);
777 NetOut
.Write(gGameSettings
.WAD
);
779 NetOut
.Write(gWADHash
);
780 NetOut
.Write(gGameSettings
.GameMode
);
781 NetOut
.Write(gGameSettings
.GoalLimit
);
782 NetOut
.Write(gGameSettings
.TimeLimit
);
783 NetOut
.Write(gGameSettings
.MaxLives
);
784 NetOut
.Write(gGameSettings
.Options
);
787 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
790 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
796 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
797 Mode
:= NET_CHAT_PLAYER
;
800 if (Mode
= NET_CHAT_TEAM
) then
802 for i
:= Low(gPlayers
) to High(gPlayers
) do
803 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
804 (gPlayers
[i
].Team
= ID
) then
806 NetOut
.Write(Byte(NET_MSG_CHAT
));
809 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
816 NetOut
.Write(Byte(NET_MSG_CHAT
));
819 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
822 if Mode
= NET_CHAT_SYSTEM
then
825 if ID
= NET_EVERYONE
then
827 if Mode
= NET_CHAT_PLAYER
then
829 g_Console_Add(Txt
, True);
830 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
831 g_Game_ChatSound(b_Text_Unformat(Txt
));
834 if Mode
= NET_CHAT_TEAM
then
835 if gPlayer1
<> nil then
837 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
839 g_Console_Add(#18'[Team] '#2 + Txt
, True);
840 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
841 g_Game_ChatSound(b_Text_Unformat(Txt
));
843 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
845 g_Console_Add(#20'[Team] '#2 + Txt
, True);
846 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
847 g_Game_ChatSound(b_Text_Unformat(Txt
));
853 Name
:= g_Net_ClientName_ByID(ID
);
854 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
855 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
856 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
860 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
862 NetOut
.Write(Byte(NET_MSG_GFX
));
868 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
871 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
873 NetOut
.Write(Byte(NET_MSG_SND
));
877 NetOut
.Write(Byte(1));
882 NetOut
.Write(Byte(0));
884 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
887 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
889 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
891 NetOut
.Write(Byte(NET_MSG_SHADD
));
893 NetOut
.Write(Shots
[Proj
].ShotType
);
894 NetOut
.Write(Shots
[Proj
].Target
);
895 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
896 NetOut
.Write(Shots
[Proj
].Timeout
);
897 NetOut
.Write(Shots
[Proj
].Obj
.X
);
898 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
899 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
900 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
902 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
905 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
907 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
909 NetOut
.Write(Byte(NET_MSG_SHPOS
));
911 NetOut
.Write(Shots
[Proj
].Obj
.X
);
912 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
913 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
914 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
916 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
919 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
921 NetOut
.Write(Byte(NET_MSG_SHDEL
));
923 NetOut
.Write(Byte(Loud
));
927 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
930 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
932 NetOut
.Write(Byte(NET_MSG_SCORE
));
933 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
935 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
936 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
939 if gGameSettings
.GameMode
= GM_COOP
then
941 NetOut
.Write(gCoopMonstersKilled
);
942 NetOut
.Write(gCoopSecretsFound
);
945 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
948 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
950 NetOut
.Write(Byte(NET_MSG_COOP
));
951 NetOut
.Write(gTotalMonsters
);
952 NetOut
.Write(gSecretsCount
);
953 NetOut
.Write(gCoopTotalMonstersKilled
);
954 NetOut
.Write(gCoopTotalSecretsFound
);
955 NetOut
.Write(gCoopTotalMonsters
);
956 NetOut
.Write(gCoopTotalSecrets
);
959 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
961 NetOut
.Write(Byte(NET_MSG_GEVENT
));
962 NetOut
.Write(EvType
);
965 NetOut
.Write(Byte(gLastMap
));
967 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
969 NetOut
.Write(Byte(1));
970 NetOut
.Write(gWADHash
);
972 NetOut
.Write(Byte(0));
974 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
977 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
979 NetOut
.Write(Byte(NET_MSG_FLAG
));
980 NetOut
.Write(EvType
);
982 NetOut
.Write(Byte(Quiet
));
984 NetOut
.Write(gFlags
[Flag
].State
);
985 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
986 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
987 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
988 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
989 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
991 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
994 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
996 NetOut
.Write(Byte(NET_MSG_GSET
));
997 NetOut
.Write(gGameSettings
.GameMode
);
998 NetOut
.Write(gGameSettings
.GoalLimit
);
999 NetOut
.Write(gGameSettings
.TimeLimit
);
1000 NetOut
.Write(gGameSettings
.MaxLives
);
1001 NetOut
.Write(gGameSettings
.Options
);
1003 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1008 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1012 P
:= g_Player_Get(PID
);
1013 if P
= nil then Exit
;
1015 NetOut
.Write(Byte(NET_MSG_PLR
));
1017 NetOut
.Write(P
.Name
);
1019 NetOut
.Write(P
.FActualModelName
);
1020 NetOut
.Write(P
.FColor
.R
);
1021 NetOut
.Write(P
.FColor
.G
);
1022 NetOut
.Write(P
.FColor
.B
);
1023 NetOut
.Write(P
.Team
);
1025 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1028 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1033 Pl
:= g_Player_Get(PID
);
1034 if Pl
= nil then Exit
;
1035 if Pl
.FDummy
then Exit
;
1037 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1038 NetOut
.Write(gTime
);
1045 NetOut
.Write(FPing
);
1046 NetOut
.Write(FLoss
);
1047 if IsKeyPressed(KEY_CHAT
) then
1048 kByte
:= NET_KEY_CHAT
1051 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1052 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1053 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1054 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1055 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1056 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1059 NetOut
.Write(kByte
);
1060 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1061 NetOut
.Write(GameX
);
1062 NetOut
.Write(GameY
);
1063 NetOut
.Write(GameVelX
);
1064 NetOut
.Write(GameVelY
);
1065 NetOut
.Write(GameAccelX
);
1066 NetOut
.Write(GameAccelY
);
1069 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1072 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1077 P
:= g_Player_Get(PID
);
1078 if P
= nil then Exit
;
1080 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1085 NetOut
.Write(Byte(alive
));
1086 NetOut
.Write(Byte(GodMode
));
1087 NetOut
.Write(Health
);
1088 NetOut
.Write(Armor
);
1090 NetOut
.Write(JetFuel
);
1091 NetOut
.Write(Lives
);
1094 for I
:= WP_FIRST
to WP_LAST
do
1095 NetOut
.Write(Byte(FWeapon
[I
]));
1097 for I
:= A_BULLETS
to A_HIGH
do
1098 NetOut
.Write(FAmmo
[I
]);
1100 for I
:= A_BULLETS
to A_HIGH
do
1101 NetOut
.Write(FMaxAmmo
[I
]);
1103 for I
:= MR_SUIT
to MR_MAX
do
1104 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1106 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1107 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1108 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1109 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1110 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1112 NetOut
.Write(Frags
);
1113 NetOut
.Write(Death
);
1115 NetOut
.Write(CurrWeap
);
1117 NetOut
.Write(Byte(FSpectator
));
1118 NetOut
.Write(Byte(FGhost
));
1119 NetOut
.Write(Byte(FPhysics
));
1120 NetOut
.Write(Byte(FNoRespawn
));
1121 NetOut
.Write(Byte(FJetpack
));
1122 NetOut
.Write(FFireTime
);
1123 NetOut
.Write(Byte(FFlaming
));
1126 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1129 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1131 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1134 NetOut
.Write(Attacker
);
1135 NetOut
.Write(Value
);
1139 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1142 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1144 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1146 NetOut
.Write(KillType
);
1147 NetOut
.Write(DeathType
);
1148 NetOut
.Write(Attacker
);
1150 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1153 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1155 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1157 NetOut
.Write(Weapon
);
1162 NetOut
.Write(ShotID
);
1164 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1167 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1169 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1172 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1175 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1179 Pl
:= g_Player_Get(PID
);
1180 if Pl
= nil then Exit
;
1182 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1184 NetOut
.Write(Pl
.Name
);
1186 NetOut
.Write(Pl
.Model
.Name
)
1189 NetOut
.Write(Pl
.FColor
.R
);
1190 NetOut
.Write(Pl
.FColor
.G
);
1191 NetOut
.Write(Pl
.FColor
.B
);
1192 NetOut
.Write(Pl
.Team
);
1194 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1199 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1204 it
:= g_Items_ByIdx(IID
);
1206 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1208 NetOut
.Write(Byte(Quiet
));
1210 if it
.dropped
then tt
:= tt
or $80;
1212 NetOut
.Write(Byte(it
.Fall
));
1213 NetOut
.Write(Byte(it
.Respawnable
));
1214 NetOut
.Write(it
.Obj
.X
);
1215 NetOut
.Write(it
.Obj
.Y
);
1216 NetOut
.Write(it
.Obj
.Vel
.X
);
1217 NetOut
.Write(it
.Obj
.Vel
.Y
);
1219 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1222 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1224 NetOut
.Write(Byte(NET_MSG_IDEL
));
1226 NetOut
.Write(Byte(Quiet
));
1228 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1233 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1237 TP
:= g_Map_PanelByGUID(PGUID
);
1238 if (TP
= nil) then exit
;
1242 NetOut
.Write(Byte(NET_MSG_PTEX
));
1243 NetOut
.Write(LongWord(PGUID
));
1244 NetOut
.Write(FCurTexture
);
1245 NetOut
.Write(FCurFrame
);
1246 NetOut
.Write(FCurFrameCount
);
1247 NetOut
.Write(AnimLoop
);
1250 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1253 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1258 TP
:= g_Map_PanelByGUID(PGUID
);
1259 if (TP
= nil) then exit
;
1261 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1262 NetOut
.Write(LongWord(PGUID
));
1263 NetOut
.Write(Byte(TP
.Enabled
));
1264 NetOut
.Write(TP
.LiftType
);
1267 NetOut
.Write(Word(TP
.Width
));
1268 NetOut
.Write(Word(TP
.Height
));
1270 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1271 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1272 NetOut
.Write(LongInt(TP
.movingStartX
));
1273 NetOut
.Write(LongInt(TP
.movingStartY
));
1274 NetOut
.Write(LongInt(TP
.movingEndX
));
1275 NetOut
.Write(LongInt(TP
.movingEndY
));
1276 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1277 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1278 NetOut
.Write(LongInt(TP
.sizeEndX
));
1279 NetOut
.Write(LongInt(TP
.sizeEndY
));
1280 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1281 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1282 NetOut
.Write(Byte(mpflags
));
1284 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1289 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1291 if gTriggers
= nil then Exit
;
1292 if T
.Sound
= nil then Exit
;
1294 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1295 NetOut
.Write(T
.ClientID
);
1296 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1297 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1298 NetOut
.Write(T
.SoundPlayCount
);
1300 g_Net_Host_Send(ID
, True);
1303 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1305 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1306 NetOut
.Write(gMusic
.Name
);
1307 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1308 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1309 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1311 g_Net_Host_Send(ID
, True);
1316 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1320 M
:= g_Monsters_ByUID(UID
);
1326 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1328 NetOut
.Write(MonsterType
);
1329 NetOut
.Write(MonsterState
);
1330 NetOut
.Write(MonsterAnim
);
1331 NetOut
.Write(MonsterTargetUID
);
1332 NetOut
.Write(MonsterTargetTime
);
1333 NetOut
.Write(MonsterBehaviour
);
1334 NetOut
.Write(MonsterSleep
);
1335 NetOut
.Write(MonsterHealth
);
1336 NetOut
.Write(MonsterAmmo
);
1337 NetOut
.Write(GameX
);
1338 NetOut
.Write(GameY
);
1339 NetOut
.Write(GameVelX
);
1340 NetOut
.Write(GameVelY
);
1341 NetOut
.Write(Byte(GameDirection
));
1344 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1347 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1351 M
:= g_Monsters_ByUID(UID
);
1352 if M
= nil then Exit
;
1354 NetOut
.Write(Byte(NET_MSG_MPOS
));
1359 NetOut
.Write(GameX
);
1360 NetOut
.Write(GameY
);
1361 NetOut
.Write(GameVelX
);
1362 NetOut
.Write(GameVelY
);
1363 NetOut
.Write(Byte(GameDirection
));
1366 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1369 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1373 M
:= g_Monsters_ByUID(UID
);
1374 if M
= nil then Exit
;
1376 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1381 NetOut
.Write(MonsterState
);
1382 NetOut
.Write(ForcedAnim
);
1383 NetOut
.Write(MonsterTargetUID
);
1384 NetOut
.Write(MonsterTargetTime
);
1385 NetOut
.Write(MonsterSleep
);
1386 NetOut
.Write(MonsterHealth
);
1387 NetOut
.Write(MonsterAmmo
);
1388 NetOut
.Write(MonsterPain
);
1389 NetOut
.Write(Byte(AnimIsReverse
));
1390 NetOut
.Write(FFireTime
);
1393 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1396 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1398 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1405 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1408 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1412 M
:= g_Monsters_ByUID(UID
);
1413 if M
= nil then Exit
;
1415 NetOut
.Write(Byte(NET_MSG_MDEL
));
1418 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1423 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1425 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1428 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1431 procedure MH_SEND_VoteEvent(EvType
: Byte;
1432 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1433 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1434 ID
: Integer = NET_EVERYONE
);
1436 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1437 NetOut
.Write(EvType
);
1438 NetOut
.Write(IntArg1
);
1439 NetOut
.Write(IntArg2
);
1440 NetOut
.Write(StrArg1
);
1441 NetOut
.Write(StrArg2
);
1443 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1446 // CLIENT MESSAGES //
1450 procedure MC_RECV_Chat(var M
: TMsg
);
1455 Txt
:= M
.ReadString();
1456 Mode
:= M
.ReadByte();
1458 if Mode
<> NET_CHAT_SYSTEM
then
1460 if Mode
= NET_CHAT_PLAYER
then
1462 g_Console_Add(Txt
, True);
1463 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1464 g_Game_ChatSound(b_Text_Unformat(Txt
));
1466 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1468 if gPlayer1
.Team
= TEAM_RED
then
1469 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1470 if gPlayer1
.Team
= TEAM_BLUE
then
1471 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1472 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1473 g_Game_ChatSound(b_Text_Unformat(Txt
));
1476 g_Console_Add(Txt
, True);
1479 procedure MC_RECV_Effect(var M
: TMsg
);
1487 if not gGameOn
then Exit
;
1488 Kind
:= M
.ReadByte();
1489 X
:= M
.ReadLongInt();
1490 Y
:= M
.ReadLongInt();
1491 Ang
:= M
.ReadSmallInt();
1495 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1499 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1501 Anim
:= TAnimation
.Create(ID
, False, 3);
1502 g_GFX_OnceAnim(X
, Y
, Anim
);
1506 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1511 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1513 Anim
:= TAnimation
.Create(ID
, False, 6);
1514 Anim
.Blending
:= False;
1515 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1519 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1524 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1526 Anim
:= TAnimation
.Create(ID
, False, 6);
1527 Anim
.Blending
:= False;
1528 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1532 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1537 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1539 Anim
:= TAnimation
.Create(ID
, False, 4);
1540 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1547 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1549 Anim
:= TAnimation
.Create(ID
, False, 4);
1550 g_GFX_OnceAnim(X
, Y
, Anim
);
1554 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1559 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1561 Anim
:= TAnimation
.Create(ID
, False, 4);
1562 g_GFX_OnceAnim(X
, Y
, Anim
);
1566 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1570 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1573 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1577 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1578 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1583 procedure MC_RECV_Sound(var M
: TMsg
);
1589 Name
:= M
.ReadString();
1590 Pos
:= M
.ReadByte() <> 0;
1593 X
:= M
.ReadLongInt();
1594 Y
:= M
.ReadLongInt();
1595 g_Sound_PlayExAt(Name
, X
, Y
);
1598 g_Sound_PlayEx(Name
);
1601 procedure MC_RECV_CreateShot(var M
: TMsg
);
1603 I
, X
, Y
, XV
, YV
: Integer;
1605 Target
, Spawner
: Word;
1608 I
:= M
.ReadLongInt();
1609 ShType
:= M
.ReadByte();
1610 Target
:= M
.ReadWord();
1611 Spawner
:= M
.ReadWord();
1612 Timeout
:= M
.ReadLongWord();
1613 X
:= M
.ReadLongInt();
1614 Y
:= M
.ReadLongInt();
1615 XV
:= M
.ReadLongInt();
1616 YV
:= M
.ReadLongInt();
1618 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1619 if (Shots
<> nil) and (I
<= High(Shots
)) then
1621 Shots
[I
].Timeout
:= Timeout
;
1622 //Shots[I].Target := Target; // TODO: find a use for Target later
1626 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1628 I
, TX
, TY
, TXV
, TYV
: Integer;
1630 I
:= M
.ReadLongInt();
1631 TX
:= M
.ReadLongInt();
1632 TY
:= M
.ReadLongInt();
1633 TXV
:= M
.ReadLongInt();
1634 TYV
:= M
.ReadLongInt();
1636 if (Shots
<> nil) and (I
<= High(Shots
)) then
1646 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1651 if not gGameOn
then Exit
;
1652 I
:= M
.ReadLongInt();
1653 L
:= (M
.ReadByte() <> 0);
1654 X
:= M
.ReadLongInt();
1655 Y
:= M
.ReadLongInt();
1657 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1660 procedure MC_RECV_GameStats(var M
: TMsg
);
1662 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1664 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1665 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1668 if gGameSettings
.GameMode
= GM_COOP
then
1670 gCoopMonstersKilled
:= M
.ReadWord();
1671 gCoopSecretsFound
:= M
.ReadWord();
1675 procedure MC_RECV_CoopStats(var M
: TMsg
);
1677 gTotalMonsters
:= M
.ReadLongInt();
1678 gSecretsCount
:= M
.ReadLongInt();
1679 gCoopTotalMonstersKilled
:= M
.ReadWord();
1680 gCoopTotalSecretsFound
:= M
.ReadWord();
1681 gCoopTotalMonsters
:= M
.ReadWord();
1682 gCoopTotalSecrets
:= M
.ReadWord();
1685 procedure MC_RECV_GameEvent(var M
: TMsg
);
1694 i1
, i2
: TStrings_Locale
;
1697 goodCmd
: Boolean = true;
1699 FillChar(EvHash
, Sizeof(EvHash
), 0);
1700 EvType
:= M
.ReadByte();
1701 EvNum
:= M
.ReadLongInt();
1702 EvStr
:= M
.ReadString();
1703 gLastMap
:= M
.ReadByte() <> 0;
1704 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1705 gStatsPressed
:= True;
1706 EvTime
:= M
.ReadLongWord();
1707 BHash
:= M
.ReadByte() <> 0;
1709 EvHash
:= M
.ReadMD5();
1713 if (g_Res_received_map_start
<> 0) then
1715 if (g_Res_received_map_start
< 0) then exit
;
1718 NET_EV_MAPSTART
: goodCmd
:= true;
1719 NET_EV_MAPEND
: goodCmd
:= true;
1720 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1721 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1723 if not goodCmd
then exit
;
1729 if (g_Res_received_map_start
<> 0) then
1731 g_Res_received_map_start
:= -1;
1736 g_Game_ClearLoading();
1737 g_Game_StopAllSounds(True);
1739 gSwitchGameMode
:= Byte(EvNum
);
1740 gGameSettings
.GameMode
:= gSwitchGameMode
;
1743 if not g_Game_StartMap(EvStr
, True) then
1745 if not isWadPath(EvStr
) then
1746 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1748 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1752 MC_SEND_FullStateRequest
;
1758 if (g_Res_received_map_start
<> 0) then
1760 g_Res_received_map_start
:= -1;
1764 gMissionFailed
:= EvNum
<> 0;
1765 gExit
:= EXIT_ENDLEVELCUSTOM
;
1773 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1775 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1777 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1783 if EvNum
= TEAM_RED
then
1784 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1785 if EvNum
= TEAM_BLUE
then
1786 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1791 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1792 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1797 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1798 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1802 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
]), True);
1804 NET_EV_LMS_SURVIVOR
:
1805 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1808 g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1812 pl
:= g_Player_Get(EvNum
and $FFFF);
1817 cnt
:= (EvNum
shr 16) and $FF;
1818 if Pos('w', EvStr
) = 0 then
1821 if Pos('t', EvStr
) = 0 then
1824 if Pos('-', EvStr
) = 0 then
1826 if Pos('e', EvStr
) = 0 then
1827 i1
:= I_PLAYER_SCORE_ADD_OWN
1829 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1832 if Pos('e', EvStr
) = 0 then
1833 i1
:= I_PLAYER_SCORE_SUB_OWN
1835 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1838 if Pos('r', EvStr
) > 0 then
1839 i2
:= I_PLAYER_SCORE_TO_RED
1841 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1842 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1846 if Pos('-', EvStr
) = 0 then
1847 i1
:= I_PLAYER_SCORE_ADD_TEAM
1849 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1851 if Pos('r', EvStr
) > 0 then
1852 i2
:= I_PLAYER_SCORE_RED
1854 i2
:= I_PLAYER_SCORE_BLUE
;
1855 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1860 if Pos('e', EvStr
) = 0 then
1861 i1
:= I_PLAYER_SCORE_WIN_OWN
1863 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1865 if Pos('r', EvStr
) > 0 then
1866 i2
:= I_PLAYER_SCORE_TO_RED
1868 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1869 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1875 if EvNum
= TEAM_RED
then
1876 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1877 if EvNum
= TEAM_BLUE
then
1878 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1879 if EvNum
= -TEAM_RED
then
1880 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1881 if EvNum
= -TEAM_BLUE
then
1882 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1887 g_Player_RemoveAllCorpses
;
1888 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1892 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1896 if EvNum
= TEAM_RED
then
1897 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1898 if EvNum
= TEAM_BLUE
then
1899 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1903 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1906 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1909 g_Game_Announce_KillCombo(EvNum
);
1911 NET_EV_PLAYER_TOUCH
:
1913 pl
:= g_Player_Get(EvNum
);
1920 pl
:= g_Player_Get(EvNum
);
1923 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
1924 g_Sound_PlayEx('SOUND_GAME_SECRET');
1930 pl
:= g_Player_Get(EvNum
);
1931 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
1936 procedure MC_RECV_FlagEvent(var M
: TMsg
);
1945 EvType
:= M
.ReadByte();
1948 if Fl
= FLAG_NONE
then Exit
;
1950 Quiet
:= (M
.ReadByte() <> 0);
1951 PID
:= M
.ReadWord();
1953 gFlags
[Fl
].State
:= M
.ReadByte();
1954 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
1955 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
1956 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
1957 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
1958 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
1960 Pl
:= g_Player_Get(PID
);
1962 (EvType
<> FLAG_STATE_NORMAL
) and
1963 (EvType
<> FLAG_STATE_DROPPED
) and
1964 (EvType
<> FLAG_STATE_RETURNED
) then
1970 if Quiet
or (Pl
= nil) then Exit
;
1972 if Fl
= FLAG_RED
then
1973 s
:= _lc
[I_PLAYER_FLAG_RED
]
1975 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1977 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1979 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
1980 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
1981 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
1986 if not sound_ret_flag
[a
].IsPlaying() then
1987 sound_ret_flag
[a
].Play();
1990 FLAG_STATE_CAPTURED
:
1992 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
1996 if Fl
= FLAG_RED
then
1997 s
:= _lc
[I_PLAYER_FLAG_RED
]
1999 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2001 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2002 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2004 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2005 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2006 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2011 if not sound_get_flag
[a
].IsPlaying() then
2012 sound_get_flag
[a
].Play();
2017 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2019 if Quiet
or (Pl
= nil) then Exit
;
2021 if Fl
= FLAG_RED
then
2022 s
:= _lc
[I_PLAYER_FLAG_RED
]
2024 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2026 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2027 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2029 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2030 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2031 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2036 if not sound_lost_flag
[a
].IsPlaying() then
2037 sound_lost_flag
[a
].Play();
2042 g_Map_ResetFlag(FLAG_RED
);
2043 g_Map_ResetFlag(FLAG_BLUE
);
2044 if Quiet
or (Pl
= nil) then Exit
;
2045 Pl
.SetFlag(FLAG_NONE
);
2047 if Fl
= FLAG_RED
then
2048 s
:= _lc
[I_PLAYER_FLAG_RED
]
2050 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2052 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2053 Insert('.', ts
, Length(ts
) + 1 - 3);
2054 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2055 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2057 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2058 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2059 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2064 if not sound_cap_flag
[a
].IsPlaying() then
2065 sound_cap_flag
[a
].Play();
2068 FLAG_STATE_RETURNED
:
2070 g_Map_ResetFlag(Fl
);
2073 if Fl
= FLAG_RED
then
2074 s
:= _lc
[I_PLAYER_FLAG_RED
]
2076 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2078 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2080 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2081 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2082 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2087 if not sound_ret_flag
[a
].IsPlaying() then
2088 sound_ret_flag
[a
].Play();
2093 procedure MC_RECV_GameSettings(var M
: TMsg
);
2095 gGameSettings
.GameMode
:= M
.ReadByte();
2096 gGameSettings
.GoalLimit
:= M
.ReadWord();
2097 gGameSettings
.TimeLimit
:= M
.ReadWord();
2098 gGameSettings
.MaxLives
:= M
.ReadByte();
2099 gGameSettings
.Options
:= M
.ReadLongWord();
2104 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2107 PName
, Model
: string;
2112 PID
:= M
.ReadWord();
2113 Pl
:= g_Player_Get(PID
);
2115 PName
:= M
.ReadString();
2116 Model
:= M
.ReadString();
2117 Color
.R
:= M
.ReadByte();
2118 Color
.G
:= M
.ReadByte();
2119 Color
.B
:= M
.ReadByte();
2123 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2125 if (Pl
<> nil) then Exit
;
2126 DID
:= g_Player_Create(Model
, Color
, T
, False);
2127 with g_Player_Get(DID
) do
2136 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2137 gPlayer1
.UID
:= PID
;
2138 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2139 gPlayer1
.ChangeTeam(T
);
2141 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2142 gPlayer2
.UID
:= PID
;
2143 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2144 gPlayer2
.ChangeTeam(T
);
2148 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2149 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2153 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2160 TmpX
, TmpY
: Integer;
2164 GT
:= M
.ReadLongWord();
2165 if GT
< gTime
- NET_MAX_DIFFTIME
then
2172 PID
:= M
.ReadWord();
2173 Pl
:= g_Player_Get(PID
);
2175 if Pl
= nil then Exit
;
2181 FPing
:= M
.ReadWord();
2182 FLoss
:= M
.ReadByte();
2183 kByte
:= M
.ReadWord();
2184 Dir
:= M
.ReadByte();
2186 TmpX
:= M
.ReadLongInt();
2187 TmpY
:= M
.ReadLongInt();
2191 if (kByte
= NET_KEY_CHAT
) then
2192 PressKey(KEY_CHAT
, 10000)
2195 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2196 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2197 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2198 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2199 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2202 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or LongBool(kByte
and NET_KEY_FORCEDIR
) then
2203 SetDirection(TDirection(Dir
));
2205 GameVelX
:= M
.ReadLongInt();
2206 GameVelY
:= M
.ReadLongInt();
2207 GameAccelX
:= M
.ReadLongInt();
2208 GameAccelY
:= M
.ReadLongInt();
2209 SetLerp(TmpX
, TmpY
);
2210 if NetForcePlayerUpdate
then Update();
2214 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2218 I
, OldFire
: Integer;
2219 OldJet
, Flam
: Boolean;
2222 PID
:= M
.ReadWord();
2223 Pl
:= g_Player_Get(PID
);
2230 alive
:= (M
.ReadByte() <> 0);
2231 GodMode
:= (M
.ReadByte() <> 0);
2232 Health
:= M
.ReadLongInt();
2233 Armor
:= M
.ReadLongInt();
2234 Air
:= M
.ReadLongInt();
2235 JetFuel
:= M
.ReadLongInt();
2236 Lives
:= M
.ReadByte();
2237 NewTeam
:= M
.ReadByte();
2239 for I
:= WP_FIRST
to WP_LAST
do
2240 FWeapon
[I
] := (M
.ReadByte() <> 0);
2242 for I
:= A_BULLETS
to A_HIGH
do
2243 FAmmo
[I
] := M
.ReadWord();
2245 for I
:= A_BULLETS
to A_HIGH
do
2246 FMaxAmmo
[I
] := M
.ReadWord();
2248 for I
:= MR_SUIT
to MR_MAX
do
2249 FMegaRulez
[I
] := M
.ReadLongWord();
2252 if (M
.ReadByte() <> 0) then
2253 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2254 if (M
.ReadByte() <> 0) then
2255 FRulez
:= FRulez
+ [R_KEY_RED
];
2256 if (M
.ReadByte() <> 0) then
2257 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2258 if (M
.ReadByte() <> 0) then
2259 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2260 if (M
.ReadByte() <> 0) then
2261 FRulez
:= FRulez
+ [R_BERSERK
];
2263 Frags
:= M
.ReadLongInt();
2264 Death
:= M
.ReadLongInt();
2266 SetWeapon(M
.ReadByte());
2268 FSpectator
:= M
.ReadByte() <> 0;
2271 if Pl
= gPlayer1
then
2276 if Pl
= gPlayer2
then
2284 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
2285 gPlayer1
:= g_Player_Get(gLMSPID1
);
2286 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
2287 gPlayer2
:= g_Player_Get(gLMSPID2
);
2289 FGhost
:= M
.ReadByte() <> 0;
2290 FPhysics
:= M
.ReadByte() <> 0;
2291 FNoRespawn
:= M
.ReadByte() <> 0;
2293 FJetpack
:= M
.ReadByte() <> 0;
2294 OldFire
:= FFireTime
;
2295 FFireTime
:= M
.ReadLongInt();
2296 if (OldFire
<= 0) and (FFireTime
> 0) then
2297 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2298 Flam
:= M
.ReadByte() <> 0;
2299 if OldJet
and not FJetpack
then
2301 else if not OldJet
and FJetpack
then
2303 if FFlaming
and not Flam
then
2305 if Team
<> NewTeam
then
2306 Pl
.ChangeTeam(NewTeam
);
2312 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2317 Attacker
, Value
: Word;
2321 if not gGameOn
then Exit
;
2322 PID
:= M
.ReadWord();
2323 Pl
:= g_Player_Get(PID
);
2324 if Pl
= nil then Exit
;
2326 Kind
:= M
.ReadByte();
2327 Attacker
:= M
.ReadWord();
2328 Value
:= M
.ReadWord();
2333 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2338 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2342 KillType
, DeathType
: Byte;
2346 if not gGameOn
then Exit
;
2347 PID
:= M
.ReadWord();
2348 Pl
:= g_Player_Get(PID
);
2349 if Pl
= nil then Exit
;
2351 KillType
:= M
.ReadByte();
2352 DeathType
:= M
.ReadByte();
2353 Attacker
:= M
.ReadWord();
2357 Kill(KillType
, Attacker
, DeathType
);
2362 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2367 PID
:= M
.ReadWord();
2368 Pl
:= g_Player_Get(PID
);
2370 if Pl
= nil then Exit
;
2372 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2373 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2375 g_Player_Remove(PID
);
2380 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2385 X
, Y
, AX
, AY
: Integer;
2389 if not gGameOn
then Exit
;
2390 PID
:= M
.ReadWord();
2391 Pl
:= g_Player_Get(PID
);
2392 if Pl
= nil then Exit
;
2394 Weap
:= M
.ReadByte();
2395 X
:= M
.ReadLongInt();
2396 Y
:= M
.ReadLongInt();
2397 AX
:= M
.ReadLongInt();
2398 AY
:= M
.ReadLongInt();
2399 SHID
:= M
.ReadLongInt();
2402 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2405 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2414 PID
:= M
.ReadWord();
2415 Pl
:= g_Player_Get(PID
);
2416 if Pl
= nil then Exit
;
2418 TmpName
:= M
.ReadString();
2419 TmpModel
:= M
.ReadString();
2420 TmpColor
.R
:= M
.ReadByte();
2421 TmpColor
.G
:= M
.ReadByte();
2422 TmpColor
.B
:= M
.ReadByte();
2423 TmpTeam
:= M
.ReadByte();
2425 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2427 Pl
.ChangeTeam(TmpTeam
);
2428 if gPlayer1
= Pl
then
2429 gPlayer1Settings
.Team
:= TmpTeam
;
2430 if gPlayer2
= Pl
then
2431 gPlayer2Settings
.Team
:= TmpTeam
;
2433 Pl
.SetColor(TmpColor
);
2435 if Pl
.Name
<> TmpName
then
2437 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2441 if TmpModel
<> Pl
.Model
.Name
then
2442 Pl
.SetModel(TmpModel
);
2447 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2451 X
, Y
, VX
, VY
: Integer;
2453 Quiet
, Fall
{, Resp}: Boolean;
2457 if not gGameOn
then Exit
;
2459 Quiet
:= M
.ReadByte() <> 0;
2461 Fall
:= M
.ReadByte() <> 0;
2462 {Resp :=} M
.ReadByte();
2463 X
:= M
.ReadLongInt();
2464 Y
:= M
.ReadLongInt();
2465 VX
:= M
.ReadLongInt();
2466 VY
:= M
.ReadLongInt();
2468 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2469 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2471 it
:= g_Items_ByIdx(ID
);
2477 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2478 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2480 Anim
:= TAnimation
.Create(AID
, False, 4);
2481 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2487 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2492 if not gGameOn
then Exit
;
2494 Quiet
:= M
.ReadByte() <> 0;
2496 if not g_Items_ValidId(ID
) then exit
;
2498 if not Quiet
then g_Items_EmitPickupSound(ID
);
2505 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2512 if not gGameOn
then Exit
;
2514 PGUID
:= Integer(M
.ReadLongWord());
2515 Tex
:= M
.ReadLongInt();
2516 Fr
:= M
.ReadLongInt();
2517 Cnt
:= M
.ReadByte();
2518 Loop
:= M
.ReadByte();
2520 TP
:= g_Map_PanelByGUID(PGUID
);
2524 TP
.SetTexture(Tex
, Loop
);
2525 TP
.SetFrame(Fr
, Cnt
);
2529 procedure MC_RECV_PanelState(var M
: TMsg
);
2534 X
, Y
, W
, H
: Integer;
2536 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2537 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2540 if not gGameOn
then Exit
;
2542 PGUID
:= Integer(M
.ReadLongWord());
2543 E
:= (M
.ReadByte() <> 0);
2544 Lift
:= M
.ReadByte();
2545 X
:= M
.ReadLongInt();
2546 Y
:= M
.ReadLongInt();
2550 speedX
:= M
.ReadLongInt();
2551 speedY
:= M
.ReadLongInt();
2552 startX
:= M
.ReadLongInt();
2553 startY
:= M
.ReadLongInt();
2554 endX
:= M
.ReadLongInt();
2555 endY
:= M
.ReadLongInt();
2556 sizeSpX
:= M
.ReadLongInt();
2557 sizeSpY
:= M
.ReadLongInt();
2558 sizeEX
:= M
.ReadLongInt();
2559 sizeEY
:= M
.ReadLongInt();
2560 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2562 TP
:= g_Map_PanelByGUID(PGUID
);
2563 if (TP
= nil) then exit
;
2565 // update lifts state
2566 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2568 // update enabled/disabled state for all panels
2569 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2571 // update panel position, as it can be moved (mplat)
2576 // update mplat state
2577 TP
.movingSpeedX
:= speedX
;
2578 TP
.movingSpeedY
:= speedY
;
2579 TP
.movingStartX
:= startX
;
2580 TP
.movingStartY
:= startY
;
2581 TP
.movingEndX
:= endX
;
2582 TP
.movingEndY
:= endY
;
2583 TP
.sizeSpeedX
:= sizeSpX
;
2584 TP
.sizeSpeedY
:= sizeSpY
;
2585 TP
.sizeEndX
:= sizeEX
;
2586 TP
.sizeEndY
:= sizeEY
;
2587 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2588 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2589 // notify panel of it's position/size change, so it can fix other internal structures
2590 TP
.positionChanged();
2595 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2598 SPos
, SID
: LongWord;
2602 if not gGameOn
then Exit
;
2603 if gTriggers
= nil then Exit
;
2605 SID
:= M
.ReadLongWord();
2606 SPlaying
:= M
.ReadByte() <> 0;
2607 SPos
:= M
.ReadLongWord();
2608 SCount
:= M
.ReadLongInt();
2610 for I
:= Low(gTriggers
) to High(gTriggers
) do
2611 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2612 if gTriggers
[I
].ClientID
= SID
then
2613 with gTriggers
[I
] do
2615 if Sound
<> nil then
2620 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2622 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2623 Sound
.SetPosition(SPos
);
2626 if Sound
.IsPlaying
then Sound
.Stop
;
2629 SoundPlayCount
:= SCount
;
2633 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2640 if not gGameOn
then Exit
;
2642 MName
:= M
.ReadString();
2643 MPlaying
:= M
.ReadByte() <> 0;
2644 MPos
:= M
.ReadLongWord();
2645 MPaused
:= M
.ReadByte() <> 0;
2646 MPos
:= MPos
+1; //k8: stfu, fpc!
2650 gMusic
.SetByName(MName
);
2652 // gMusic.SetPosition(MPos);
2653 gMusic
.SpecPause
:= MPaused
;
2656 if gMusic
.IsPlaying
then gMusic
.Stop
;
2661 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2664 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2665 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2670 Mon
:= g_Monsters_ByUID(ID
);
2674 MType
:= M
.ReadByte();
2675 MState
:= M
.ReadByte();
2676 MAnim
:= M
.ReadByte();
2677 MTarg
:= M
.ReadWord();
2678 MTargTime
:= M
.ReadLongInt();
2679 MBehav
:= M
.ReadByte();
2680 MSleep
:= M
.ReadLongInt();
2681 MHealth
:= M
.ReadLongInt();
2682 MAmmo
:= M
.ReadLongInt();
2684 X
:= M
.ReadLongInt();
2685 Y
:= M
.ReadLongInt();
2686 VX
:= M
.ReadLongInt();
2687 VY
:= M
.ReadLongInt();
2688 MDir
:= M
.ReadByte();
2690 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2691 Mon
:= g_Monsters_ByUID(ID
);
2698 MonsterAnim
:= MAnim
;
2699 MonsterTargetUID
:= MTarg
;
2700 MonsterTargetTime
:= MTargTime
;
2701 MonsterBehaviour
:= MBehav
;
2702 MonsterSleep
:= MSleep
;
2703 MonsterAmmo
:= MAmmo
;
2708 setPosition(X
, Y
); // this will call positionChanged();
2714 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2721 Mon
:= g_Monsters_ByUID(ID
);
2727 X
:= M
.ReadLongInt();
2728 Y
:= M
.ReadLongInt();
2729 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2730 GameVelX
:= M
.ReadLongInt();
2731 GameVelY
:= M
.ReadLongInt();
2732 GameDirection
:= TDirection(M
.ReadByte());
2736 procedure MC_RECV_MonsterState(var M
: TMsg
);
2738 ID
, OldFire
: Integer;
2739 MState
, MFAnm
: Byte;
2741 AnimRevert
: Boolean;
2744 Mon
:= g_Monsters_ByUID(ID
);
2745 if Mon
= nil then Exit
;
2747 MState
:= M
.ReadByte();
2748 MFAnm
:= M
.ReadByte();
2752 MonsterTargetUID
:= M
.ReadWord();
2753 MonsterTargetTime
:= M
.ReadLongInt();
2754 MonsterSleep
:= M
.ReadLongInt();
2755 MonsterHealth
:= M
.ReadLongInt();
2756 MonsterAmmo
:= M
.ReadLongInt();
2757 MonsterPain
:= M
.ReadLongInt();
2758 AnimRevert
:= M
.ReadByte() <> 0;
2759 OldFire
:= FFireTime
;
2760 FFireTime
:= M
.ReadLongInt();
2761 if (OldFire
<= 0) and (FFireTime
> 0) then
2762 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2763 RevertAnim(AnimRevert
);
2765 if MonsterState
<> MState
then
2767 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2768 if (MState
= MONSTATE_DIE
) then DieSound();
2769 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2770 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2771 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2773 SetState(MState
, MFAnm
);
2778 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2782 X
, Y
, VX
, VY
: Integer;
2786 Mon
:= g_Monsters_ByUID(ID
);
2787 if Mon
= nil then Exit
;
2789 X
:= M
.ReadLongInt();
2790 Y
:= M
.ReadLongInt();
2791 VX
:= M
.ReadLongInt();
2792 VY
:= M
.ReadLongInt();
2794 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2797 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2803 Mon
:= g_Monsters_ByUID(ID
);
2804 if Mon
= nil then Exit
;
2806 Mon
.MonsterRemoved
:= True;
2809 procedure MC_RECV_TimeSync(var M
: TMsg
);
2813 Time
:= M
.ReadLongWord();
2815 if gState
= STATE_INTERCUSTOM
then
2816 gServInterTime
:= Min(Time
, 255);
2819 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2823 Int1
, Int2
: SmallInt;
2825 EvID
:= M
.ReadByte();
2826 Int1
:= M
.ReadSmallInt();
2827 Int2
:= M
.ReadSmallInt();
2828 Str1
:= M
.ReadString();
2829 Str2
:= M
.ReadString();
2833 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2835 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2837 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2839 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2841 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2847 procedure MC_SEND_Info(Password
: string);
2851 NetOut
.Write(Byte(NET_MSG_INFO
));
2852 NetOut
.Write(GAME_VERSION
);
2853 NetOut
.Write(Password
);
2854 NetOut
.Write(gPlayer1Settings
.Name
);
2855 NetOut
.Write(gPlayer1Settings
.Model
);
2856 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2857 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2858 NetOut
.Write(gPlayer1Settings
.Color
.B
);
2859 NetOut
.Write(gPlayer1Settings
.Team
);
2861 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
2864 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2866 NetOut
.Write(Byte(NET_MSG_CHAT
));
2870 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2873 procedure MC_SEND_PlayerPos();
2878 WeaponSelect
: Word = 0;
2881 if not gGameOn
then Exit
;
2882 if gPlayers
= nil then Exit
;
2883 if gPlayer1
= nil then Exit
;
2886 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2888 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2890 strafeDir
:= P1MoveButton
shr 4;
2891 P1MoveButton
:= P1MoveButton
and $0F;
2893 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2895 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2897 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
2901 if gPlayerAction
[0, ACTION_STRAFE
] then
2903 // new strafe mechanics
2904 if (strafeDir
= 0) then
2905 strafeDir
:= P1MoveButton
; // start strafing
2906 // now set direction according to strafe (reversed)
2907 if (strafeDir
= 2) then
2908 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2909 else if (strafeDir
= 1) then
2910 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2914 strafeDir
:= 0; // not strafing anymore
2915 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
2916 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
2917 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
2918 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
2919 else if P1MoveButton
<> 0 then
2920 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
2923 gPlayer1
.ReleaseKeys
;
2924 if P1MoveButton
= 1 then
2926 kByte
:= kByte
or NET_KEY_LEFT
;
2927 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
2929 if P1MoveButton
= 2 then
2931 kByte
:= kByte
or NET_KEY_RIGHT
;
2932 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
2934 if gPlayerAction
[0, ACTION_LOOKUP
] then
2936 kByte
:= kByte
or NET_KEY_UP
;
2937 gPlayer1
.PressKey(KEY_UP
, 10000);
2939 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2941 kByte
:= kByte
or NET_KEY_DOWN
;
2942 gPlayer1
.PressKey(KEY_DOWN
, 10000);
2944 if gPlayerAction
[0, ACTION_JUMP
] then
2946 kByte
:= kByte
or NET_KEY_JUMP
;
2947 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2949 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
2950 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
2951 if gPlayerAction
[0, ACTION_WEAPNEXT
] then kByte
:= kByte
or NET_KEY_NW
;
2952 if gPlayerAction
[0, ACTION_WEAPPREV
] then kByte
:= kByte
or NET_KEY_PW
;
2954 gPlayerAction
[0, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2955 gPlayerAction
[0, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
2957 for i
:= WP_FIRST
to WP_LAST
do
2959 if gSelectWeapon
[0, i
] then
2961 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
2962 gSelectWeapon
[0, i
] := False
2966 // fix movebutton state
2967 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
2970 kByte
:= NET_KEY_CHAT
;
2972 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
2973 NetOut
.Write(gTime
);
2974 NetOut
.Write(kByte
);
2975 NetOut
.Write(Byte(gPlayer1
.Direction
));
2976 NetOut
.Write(WeaponSelect
);
2977 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2978 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
2980 //kBytePrev := kByte;
2981 //kDirPrev := gPlayer1.Direction;
2984 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
2986 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
2987 NetOut
.Write(Byte(Start
));
2988 NetOut
.Write(Command
);
2989 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
2992 procedure MC_SEND_PlayerSettings();
2994 NetOut
.Write(Byte(NET_MSG_PLRSET
));
2995 NetOut
.Write(gPlayer1Settings
.Name
);
2996 NetOut
.Write(gPlayer1Settings
.Model
);
2997 NetOut
.Write(gPlayer1Settings
.Color
.R
);
2998 NetOut
.Write(gPlayer1Settings
.Color
.G
);
2999 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3000 NetOut
.Write(gPlayer1Settings
.Team
);
3002 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3005 procedure MC_SEND_FullStateRequest();
3007 NetOut
.Write(Byte(NET_MSG_REQFST
));
3009 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3012 procedure MC_SEND_CheatRequest(Kind
: Byte);
3014 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3017 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3019 procedure MC_SEND_RCONPassword(Password
: string);
3021 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3022 NetOut
.Write(Password
);
3024 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3026 procedure MC_SEND_RCONCommand(Cmd
: string);
3028 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3031 g_Net_Client_Send(True, NET_CHAN_SERVICE
);