0a4facfdbdc7a0fe1c91cd362962b5fc7e3dadc1
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;
115 NET_EV_LMS_NOSPAWN
= 21;
122 NET_VE_INPROGRESS
= 6;
129 NET_CHEAT_SUICIDE
= 1;
130 NET_CHEAT_SPECTATE
= 2;
132 NET_CHEAT_DROPFLAG
= 4;
134 NET_MAX_DIFFTIME
= 5000 div 36;
138 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
140 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
141 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
142 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
143 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
144 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
145 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
146 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
147 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
148 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
149 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
150 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
153 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
154 procedure MH_SEND_Info(ID
: Byte);
155 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
156 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
157 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
158 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
159 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
160 procedure MH_SEND_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
161 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
162 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
163 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
164 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
165 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
167 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
168 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
169 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
170 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
171 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
172 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
173 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
174 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
176 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
177 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
179 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
180 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
182 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
183 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
184 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
185 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
186 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
188 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
189 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
191 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
192 procedure MH_SEND_VoteEvent(EvType
: Byte;
193 StrArg1
: string = 'a'; StrArg2
: string = 'b';
194 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
195 ID
: Integer = NET_EVERYONE
);
197 // CLIENT MESSAGES //
200 procedure MC_RECV_Chat(var M
: TMsg
);
201 procedure MC_RECV_Effect(var M
: TMsg
);
202 procedure MC_RECV_Sound(var M
: TMsg
);
203 procedure MC_RECV_GameStats(var M
: TMsg
);
204 procedure MC_RECV_CoopStats(var M
: TMsg
);
205 procedure MC_RECV_GameEvent(var M
: TMsg
);
206 procedure MC_RECV_FlagEvent(var M
: TMsg
);
207 procedure MC_RECV_GameSettings(var M
: TMsg
);
209 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
210 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
211 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
212 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
213 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
214 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
215 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
216 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
218 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
219 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
221 procedure MC_RECV_PanelTexture(var M
: TMsg
);
222 procedure MC_RECV_PanelState(var M
: TMsg
);
224 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
225 procedure MC_RECV_MonsterPos(var M
: TMsg
);
226 procedure MC_RECV_MonsterState(var M
: TMsg
);
227 procedure MC_RECV_MonsterShot(var M
: TMsg
);
228 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
230 procedure MC_RECV_CreateShot(var M
: TMsg
);
231 procedure MC_RECV_UpdateShot(var M
: TMsg
);
232 procedure MC_RECV_DeleteShot(var M
: TMsg
);
234 procedure MC_RECV_TriggerSound(var M
: TMsg
);
235 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
237 procedure MC_RECV_TimeSync(var M
: TMsg
);
238 procedure MC_RECV_VoteEvent(var M
: TMsg
);
240 procedure MC_SEND_Info(Password
: string);
241 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
242 procedure MC_SEND_PlayerPos();
243 procedure MC_SEND_FullStateRequest();
244 procedure MC_SEND_PlayerSettings();
245 procedure MC_SEND_CheatRequest(Kind
: Byte);
246 procedure MC_SEND_RCONPassword(Password
: string);
247 procedure MC_SEND_RCONCommand(Cmd
: string);
248 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
250 //procedure MC_SEND_MapRequest();
251 //procedure MC_SEND_ResRequest(const resName: AnsiString);
255 TExternalResourceInfo
= record
270 ExternalResources
: array of TExternalResourceInfo
;
273 function IsValidFileName(const S
: String): Boolean;
274 function IsValidFilePath(const S
: String): Boolean;
280 Math
, ENet
, e_input
, e_graphics
, e_log
,
281 g_textures
, g_gfx
, g_sound
, g_console
, g_basic
, g_options
, g_main
,
282 g_game
, g_player
, g_map
, g_panel
, g_items
, g_weapons
, g_phys
, g_gui
,
283 g_language
, g_monsters
, g_netmaster
, utils
, wadreader
, MAPDEF
;
286 NET_KEY_LEFT
= 1 shl 0;
287 NET_KEY_RIGHT
= 1 shl 1;
288 NET_KEY_UP
= 1 shl 2;
289 NET_KEY_DOWN
= 1 shl 3;
290 NET_KEY_JUMP
= 1 shl 4;
291 NET_KEY_FIRE
= 1 shl 5;
292 NET_KEY_OPEN
= 1 shl 6;
293 NET_KEY_CHAT
= 1 shl 7;
294 NET_KEY_FORCEDIR
= 1 shl 8;
297 //kBytePrev: Word = 0;
298 //kDirPrev: TDirection = D_LEFT;
299 //HostGameTime: Word = 0;
302 function IsValidFileName(const S
: String): Boolean;
304 Forbidden
: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
309 for I
:= 1 to Length(S
) do
310 Result
:= Result
and (not(S
[I
] in Forbidden
));
313 function IsValidFilePath(const S
: String): Boolean;
318 if not IsValidFileName(S
) then exit
;
319 if FileExists(S
) then exit
;
320 I
:= LastDelimiter('\/', S
);
322 if (not DirectoryExists(Copy(S
, 1, I
-1))) then
333 procedure MH_RECV_Chat(C
: pTNetClient
; var M
: TMsg
);
341 Pl
:= g_Player_Get(PID
);
343 Txt
:= M
.ReadString();
344 Mode
:= M
.ReadByte();
345 if (Mode
= NET_CHAT_SYSTEM
) then
346 Mode
:= NET_CHAT_PLAYER
; // prevent sending system messages from clients
347 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
348 Mode
:= NET_CHAT_PLAYER
; // revert to player chat in non-team game
351 MH_SEND_Chat(Txt
, Mode
)
353 MH_SEND_Chat(Pl
.Name
+ ': ' + Txt
, Mode
, IfThen(Mode
= NET_CHAT_TEAM
, Pl
.Team
, NET_EVERYONE
));
356 procedure MH_RECV_Info(C
: pTNetClient
; var M
: TMsg
);
358 Ver
, PName
, Model
, Pw
: string;
364 Ver
:= M
.ReadString();
365 Pw
:= M
.ReadString();
366 PName
:= M
.ReadString();
367 Model
:= M
.ReadString();
373 if Ver
<> GAME_VERSION
then
375 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
376 _lc
[I_NET_DISC_VERSION
]);
377 enet_peer_disconnect(C
^.Peer
, NET_DISC_VERSION
);
381 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
) then
383 if g_Net_IsHostBanned(C
^.Peer
^.address
.host
, True) then
385 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
386 _lc
[I_NET_DISC_BAN
]);
387 enet_peer_disconnect(C
^.Peer
, NET_DISC_BAN
);
391 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
392 _lc
[I_NET_DISC_BAN
]);
393 enet_peer_disconnect(C
^.Peer
, NET_DISC_TEMPBAN
);
398 if NetPassword
<> '' then
399 if AnsiLowerCase(NetPassword
) <> AnsiLowerCase(Pw
) then
401 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_MSG_HOST_REJECT
] +
402 _lc
[I_NET_DISC_PASSWORD
]);
403 enet_peer_disconnect(C
^.Peer
, NET_DISC_PASSWORD
);
411 PID
:= g_Player_Create(Model
, Color
, T
, False);
412 with g_Player_Get(PID
) do
419 C
^.WaitForFirstSpawn
:= false;
421 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
422 e_WriteLog('NET: Client ' + PName
+ ' [' + IntToStr(C
^.ID
) +
423 '] connected. Assigned player #' + IntToStr(PID
) + '.', TMsgType
.Notify
);
427 with g_Player_Get(PID
) do
431 // round in progress, don't spawn
432 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C
.ID
, C
.Player
]);
433 //e_LogWritefln('spawning player with pid #%u...', [PID]);
434 //Respawn(gGameSettings.GameType = GT_SINGLE);
435 //k8: no, do not spawn a player yet, wait for "request full state" packet
439 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
440 // that is, if we'll set it to `true`, the player can be spawned after
441 // warmup time ran out, for example, regardless of the real player state.
442 // also, this seems to work only for the initial connection. further
443 // map changes could initiate resource downloading, but the player will
444 // be spawned immediately.
445 // the proper solution will require another player state, "ephemeral".
446 // the player should start any map in "ephemeral" state, and turned into
447 // real mobj only when they sent a special "i am ready" packet. this packet
448 // must be sent after receiving the full state, so the player will get a full
449 // map view before going into game.
450 FWantsInGame
:= false;
451 C
^.WaitForFirstSpawn
:= true;
454 //if not C^.WaitForFirstSpawn then
456 for I
:= Low(NetClients
) to High(NetClients
) do
458 if NetClients
[I
].ID
= C
^.ID
then Continue
;
459 MH_SEND_PlayerCreate(PID
, NetClients
[I
].ID
);
460 MH_SEND_PlayerPos(True, PID
, NetClients
[I
].ID
);
461 MH_SEND_PlayerStats(PID
, NetClients
[I
].ID
);
465 if gState
in [STATE_INTERCUSTOM
, STATE_FOLD
] then
466 MH_SEND_GameEvent(NET_EV_MAPEND
, 0, 'N', C
^.ID
);
470 //g_Net_Slist_Update;
476 procedure MH_ProcessFirstSpawn (C
: pTNetClient
);
480 if not C
.WaitForFirstSpawn
then exit
;
481 plr
:= g_Player_Get(C
^.Player
);
482 if not assigned(plr
) then exit
;
483 g_Net_Slist_ServerPlayerComes();
484 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C
.ID
, C
.Player
]);
485 C
.WaitForFirstSpawn
:= false;
486 plr
.FNoRespawn
:= false;
487 plr
.FWantsInGame
:= true; // TODO: look into this later
489 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
492 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, 0, 'N', C
.ID
);
497 if gLMSRespawn
> LMS_RESPAWN_NONE
then
498 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
, 'N', C
.ID
);
503 procedure MH_RECV_FullStateRequest(C
: pTNetClient
; var M
: TMsg
);
505 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
508 MH_SEND_Everything((C
^.State
= NET_STATE_AUTH
), C
^.ID
)
512 C
^.RequestedFullUpdate
:= True;
518 function MH_RECV_PlayerPos(C
: pTNetClient
; var M
: TMsg
): Word;
529 if not gGameOn
then Exit
;
531 GT
:= M
.ReadLongWord();
533 Pl
:= g_Player_Get(PID
);
537 if (GT
> gTime
+ NET_MAX_DIFFTIME
) or (GT
< Pl
.NetTime
) then Exit
;
542 kByte
:= M
.ReadWord();
544 WeaponAct
:= M
.ReadByte();
545 WeaponSelect
:= M
.ReadWord();
546 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
547 if Direction
<> TDirection(Dir
) then
548 JustTeleported
:= False;
550 SetDirection(TDirection(Dir
));
553 if kByte
= NET_KEY_CHAT
then
555 PressKey(KEY_CHAT
, 10000);
559 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
560 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
561 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
562 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
563 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
564 if LongBool(kByte
and NET_KEY_FIRE
) then PressKey(KEY_FIRE
, 10000);
565 if LongBool(kByte
and NET_KEY_OPEN
) then PressKey(KEY_OPEN
, 10000);
569 if (WeaponAct
and Byte(1 shl i
)) <> 0 then
571 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
572 ProcessWeaponAction(i
);
578 if (WeaponSelect
and Word(1 shl i
)) <> 0 then
580 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
581 QueueWeaponSwitch(i
);
586 // MH_SEND_PlayerPos(False, PID, C^.ID);
589 procedure MH_RECV_CheatRequest(C
: pTNetClient
; var M
: TMsg
);
594 Pl
:= g_Player_Get(C
^.Player
);
595 if Pl
= nil then Exit
;
597 CheatKind
:= M
.ReadByte();
601 Pl
.Damage(SUICIDE_DAMAGE
, Pl
.UID
, 0, 0, HIT_SELF
);
604 if Pl
.FSpectator
then
606 if (gGameSettings
.MaxLives
= 0) or (gLMSRespawn
> LMS_RESPAWN_NONE
) then
609 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN
, Pl
.UID
);
616 if gState
<> STATE_INTERCUSTOM
then Exit
;
617 Pl
.FReady
:= not Pl
.FReady
;
620 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'Y');
621 Inc(gInterReadyCount
);
625 MH_SEND_GameEvent(NET_EV_INTER_READY
, Pl
.UID
, 'N');
626 Dec(gInterReadyCount
);
634 procedure MH_RECV_PlayerSettings(C
: pTNetClient
; var M
: TMsg
);
642 TmpName
:= M
.ReadString();
643 TmpModel
:= M
.ReadString();
644 TmpColor
.R
:= M
.ReadByte();
645 TmpColor
.G
:= M
.ReadByte();
646 TmpColor
.B
:= M
.ReadByte();
647 TmpTeam
:= M
.ReadByte();
649 Pl
:= g_Player_Get(C
^.Player
);
650 if Pl
= nil then Exit
;
652 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
655 Pl
.SetColor(TmpColor
);
657 if Pl
.Name
<> TmpName
then
659 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
663 if TmpModel
<> Pl
.Model
.Name
then
664 Pl
.SetModel(TmpModel
);
666 MH_SEND_PlayerSettings(Pl
.UID
, TmpModel
);
671 procedure MH_RECV_RCONPassword(C
: pTNetClient
; var M
: TMsg
);
675 Pwd
:= M
.ReadString();
676 if not NetAllowRCON
then Exit
;
677 if Pwd
= NetRCONPassword
then
680 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWGOOD
, 'N', C
^.ID
);
683 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_PWBAD
, 'N', C
^.ID
);
686 procedure MH_RECV_RCONCommand(C
: pTNetClient
; var M
: TMsg
);
690 Cmd
:= M
.ReadString();
691 if not NetAllowRCON
then Exit
;
692 if not C
^.RCONAuth
then
694 MH_SEND_GameEvent(NET_EV_RCON
, NET_RCON_NOAUTH
, 'N', C
^.ID
);
697 g_Console_Process(Cmd
);
702 procedure MH_RECV_Vote(C
: pTNetClient
; var M
: TMsg
);
705 Name
, Command
: string;
709 Start
:= M
.ReadByte() <> 0;
710 Command
:= M
.ReadString();
712 Pl
:= g_Player_Get(C
^.Player
);
713 if Pl
= nil then Exit
;
718 if not g_Console_CommandBlacklisted(Command
) then
719 g_Game_StartVote(Command
, Name
);
721 else if gVoteInProgress
then
723 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
724 Need
:= Floor((NetClientCount
+1)/2.0) + 1
726 Need
:= Floor(NetClientCount
/2.0) + 1;
731 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [Name
, gVoteCount
, Need
]), True);
732 MH_SEND_VoteEvent(NET_VE_REVOKE
, Name
, 'a', gVoteCount
, Need
);
738 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Name
, gVoteCount
, Need
]), True);
739 MH_SEND_VoteEvent(NET_VE_VOTE
, Name
, 'a', gVoteCount
, Need
);
747 procedure MH_SEND_Everything(CreatePlayers
: Boolean {= False}; ID
: Integer {= NET_EVERYONE});
749 function sendItemRespawn (it
: PItem
): Boolean;
751 result
:= false; // don't stop
752 MH_SEND_ItemSpawn(True, it
.myid
, ID
);
755 function sendMonSpawn (mon
: TMonster
): Boolean;
757 result
:= false; // don't stop
758 MH_SEND_MonsterSpawn(mon
.UID
, ID
);
761 function sendPanelState (pan
: TPanel
): Boolean;
763 result
:= false; // don't stop
764 MH_SEND_PanelState(pan
.guid
, ID
); // anyway, to sync mplats
765 if (pan
.CanChangeTexture
) then MH_SEND_PanelTexture(pan
.guid
, pan
.LastAnimLoop
, ID
);
771 if (ID
>= 0) and (ID
< length(NetClients
)) then
773 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID
, NetClients
[ID
].Player
]);
774 MH_ProcessFirstSpawn(@NetClients
[ID
]);
777 if gPlayers
<> nil then
779 for I
:= Low(gPlayers
) to High(gPlayers
) do
781 if gPlayers
[I
] <> nil then
783 if CreatePlayers
then MH_SEND_PlayerCreate(gPlayers
[I
].UID
, ID
);
784 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
, ID
);
785 MH_SEND_PlayerStats(gPlayers
[I
].UID
, ID
);
787 if (gPlayers
[I
].Flag
<> FLAG_NONE
) and (gGameSettings
.GameMode
= GM_CTF
) then
789 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED
, gPlayers
[I
].Flag
, gPlayers
[I
].UID
, True, ID
);
795 g_Items_ForEachAlive(sendItemRespawn
, true); // backwards
796 g_Mons_ForEach(sendMonSpawn
);
797 g_Map_ForEachPanel(sendPanelState
);
799 if gTriggers
<> nil then
801 for I
:= Low(gTriggers
) to High(gTriggers
) do
803 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
805 MH_SEND_TriggerSound(gTriggers
[I
], ID
);
812 for I
:= Low(Shots
) to High(Shots
) do
814 if Shots
[i
].ShotType
in [6, 7, 8] then
816 MH_SEND_CreateShot(i
, ID
);
821 MH_SEND_TriggerMusic(ID
);
823 MH_SEND_GameStats(ID
);
824 MH_SEND_CoopStats(ID
);
826 if gGameSettings
.GameMode
= GM_CTF
then
828 if gFlags
[FLAG_RED
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_RED
].State
, FLAG_RED
, 0, True, ID
);
829 if gFlags
[FLAG_BLUE
].State
<> FLAG_STATE_CAPTURED
then MH_SEND_FlagEvent(gFlags
[FLAG_BLUE
].State
, FLAG_BLUE
, 0, True, ID
);
832 if CreatePlayers
and (ID
>= 0) then NetClients
[ID
].State
:= NET_STATE_GAME
;
837 procedure MH_SEND_Info(ID
: Byte);
841 NetOut
.Write(Byte(NET_MSG_INFO
));
843 NetOut
.Write(NetClients
[ID
].Player
);
844 NetOut
.Write(ExtractFileName(gGameSettings
.WAD
));
845 NetOut
.Write(g_ExtractFileName(gMapInfo
.Map
));
846 NetOut
.Write(gWADHash
);
847 NetOut
.Write(gGameSettings
.GameMode
);
848 NetOut
.Write(gGameSettings
.GoalLimit
);
849 NetOut
.Write(gGameSettings
.TimeLimit
);
850 NetOut
.Write(gGameSettings
.MaxLives
);
851 NetOut
.Write(gGameSettings
.Options
);
854 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
857 procedure MH_SEND_Chat(Txt
: string; Mode
: Byte; ID
: Integer = NET_EVERYONE
);
863 if (Mode
= NET_CHAT_TEAM
) and (not gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
864 Mode
:= NET_CHAT_PLAYER
;
867 if (Mode
= NET_CHAT_TEAM
) then
869 for i
:= Low(gPlayers
) to High(gPlayers
) do
870 if (gPlayers
[i
] <> nil) and (gPlayers
[i
].FClientID
>= 0) and
871 (gPlayers
[i
].Team
= ID
) then
873 NetOut
.Write(Byte(NET_MSG_CHAT
));
876 g_Net_Host_Send(gPlayers
[i
].FClientID
, True, NET_CHAN_CHAT
);
883 NetOut
.Write(Byte(NET_MSG_CHAT
));
886 g_Net_Host_Send(ID
, True, NET_CHAN_CHAT
);
889 if Mode
= NET_CHAT_SYSTEM
then
892 if ID
= NET_EVERYONE
then
894 if Mode
= NET_CHAT_PLAYER
then
896 g_Console_Add(Txt
, True);
897 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
898 g_Game_ChatSound(b_Text_Unformat(Txt
));
901 if Mode
= NET_CHAT_TEAM
then
902 if gPlayer1
<> nil then
904 if (gPlayer1
.Team
= TEAM_RED
) and (Team
= TEAM_RED
) then
906 g_Console_Add(#18'[Team] '#2 + Txt
, True);
907 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
908 g_Game_ChatSound(b_Text_Unformat(Txt
));
910 else if (gPlayer1
.Team
= TEAM_BLUE
) and (Team
= TEAM_BLUE
) then
912 g_Console_Add(#20'[Team] '#2 + Txt
, True);
913 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
914 g_Game_ChatSound(b_Text_Unformat(Txt
));
920 Name
:= g_Net_ClientName_ByID(ID
);
921 g_Console_Add('-> ' + Name
+ ': ' + Txt
, True);
922 e_WriteLog('[Tell ' + Name
+ '] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
923 g_Game_ChatSound(b_Text_Unformat(Txt
), False);
927 procedure MH_SEND_Effect(X
, Y
: Integer; Ang
: SmallInt; Kind
: Byte; ID
: Integer = NET_EVERYONE
);
929 NetOut
.Write(Byte(NET_MSG_GFX
));
935 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
938 procedure MH_SEND_Sound(X
, Y
: Integer; Name
: string; Pos
: Boolean = True; ID
: Integer = NET_EVERYONE
);
940 NetOut
.Write(Byte(NET_MSG_SND
));
944 NetOut
.Write(Byte(1));
949 NetOut
.Write(Byte(0));
951 g_Net_Host_Send(ID
, False, NET_CHAN_GAME
);
954 procedure MH_SEND_CreateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
956 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
958 NetOut
.Write(Byte(NET_MSG_SHADD
));
960 NetOut
.Write(Shots
[Proj
].ShotType
);
961 NetOut
.Write(Shots
[Proj
].Target
);
962 NetOut
.Write(Shots
[Proj
].SpawnerUID
);
963 NetOut
.Write(Shots
[Proj
].Timeout
);
964 NetOut
.Write(Shots
[Proj
].Obj
.X
);
965 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
966 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
967 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
969 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
972 procedure MH_SEND_UpdateShot(Proj
: LongInt; ID
: Integer = NET_EVERYONE
);
974 if (Shots
= nil) or (Proj
< 0) or (Proj
> High(Shots
)) then Exit
;
976 NetOut
.Write(Byte(NET_MSG_SHPOS
));
978 NetOut
.Write(Shots
[Proj
].Obj
.X
);
979 NetOut
.Write(Shots
[Proj
].Obj
.Y
);
980 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.X
);
981 NetOut
.Write(Shots
[Proj
].Obj
.Vel
.Y
);
983 g_Net_Host_Send(ID
, False, NET_CHAN_SHOTS
);
986 procedure MH_Send_DeleteShot(Proj
: LongInt; X
, Y
: LongInt; Loud
: Boolean = True; ID
: Integer = NET_EVERYONE
);
988 NetOut
.Write(Byte(NET_MSG_SHDEL
));
990 NetOut
.Write(Byte(Loud
));
994 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
997 procedure MH_SEND_GameStats(ID
: Integer = NET_EVERYONE
);
999 NetOut
.Write(Byte(NET_MSG_SCORE
));
1000 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1002 NetOut
.Write(gTeamStat
[TEAM_RED
].Goals
);
1003 NetOut
.Write(gTeamStat
[TEAM_BLUE
].Goals
);
1006 if gGameSettings
.GameMode
= GM_COOP
then
1008 NetOut
.Write(gCoopMonstersKilled
);
1009 NetOut
.Write(gCoopSecretsFound
);
1012 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1015 procedure MH_SEND_CoopStats(ID
: Integer = NET_EVERYONE
);
1017 NetOut
.Write(Byte(NET_MSG_COOP
));
1018 NetOut
.Write(gTotalMonsters
);
1019 NetOut
.Write(gSecretsCount
);
1020 NetOut
.Write(gCoopTotalMonstersKilled
);
1021 NetOut
.Write(gCoopTotalSecretsFound
);
1022 NetOut
.Write(gCoopTotalMonsters
);
1023 NetOut
.Write(gCoopTotalSecrets
);
1026 procedure MH_SEND_GameEvent(EvType
: Byte; EvNum
: Integer = 0; EvStr
: string = 'N'; ID
: Integer = NET_EVERYONE
);
1028 NetOut
.Write(Byte(NET_MSG_GEVENT
));
1029 NetOut
.Write(EvType
);
1030 NetOut
.Write(EvNum
);
1031 NetOut
.Write(EvStr
);
1032 NetOut
.Write(Byte(gLastMap
));
1033 NetOut
.Write(gTime
);
1034 if (EvType
= NET_EV_MAPSTART
) and isWadPath(EvStr
) then
1036 NetOut
.Write(Byte(1));
1037 NetOut
.Write(gWADHash
);
1039 NetOut
.Write(Byte(0));
1041 g_Net_Host_Send(ID
, True, NET_CHAN_SERVICE
);
1044 procedure MH_SEND_FlagEvent(EvType
: Byte; Flag
: Byte; PID
: Word; Quiet
: Boolean = False; ID
: Integer = NET_EVERYONE
);
1046 NetOut
.Write(Byte(NET_MSG_FLAG
));
1047 NetOut
.Write(EvType
);
1049 NetOut
.Write(Byte(Quiet
));
1051 NetOut
.Write(gFlags
[Flag
].State
);
1052 NetOut
.Write(gFlags
[Flag
].CaptureTime
);
1053 NetOut
.Write(gFlags
[Flag
].Obj
.X
);
1054 NetOut
.Write(gFlags
[Flag
].Obj
.Y
);
1055 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.X
);
1056 NetOut
.Write(gFlags
[Flag
].Obj
.Vel
.Y
);
1058 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1061 procedure MH_SEND_GameSettings(ID
: Integer = NET_EVERYONE
);
1063 NetOut
.Write(Byte(NET_MSG_GSET
));
1064 NetOut
.Write(gGameSettings
.GameMode
);
1065 NetOut
.Write(gGameSettings
.GoalLimit
);
1066 NetOut
.Write(gGameSettings
.TimeLimit
);
1067 NetOut
.Write(gGameSettings
.MaxLives
);
1068 NetOut
.Write(gGameSettings
.Options
);
1070 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1075 procedure MH_SEND_PlayerCreate(PID
: Word; ID
: Integer = NET_EVERYONE
);
1079 P
:= g_Player_Get(PID
);
1080 if P
= nil then Exit
;
1082 NetOut
.Write(Byte(NET_MSG_PLR
));
1084 NetOut
.Write(P
.Name
);
1086 NetOut
.Write(P
.FActualModelName
);
1087 NetOut
.Write(P
.FColor
.R
);
1088 NetOut
.Write(P
.FColor
.G
);
1089 NetOut
.Write(P
.FColor
.B
);
1090 NetOut
.Write(P
.Team
);
1092 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
)
1095 procedure MH_SEND_PlayerPos(Reliable
: Boolean; PID
: Word; ID
: Integer = NET_EVERYONE
);
1100 Pl
:= g_Player_Get(PID
);
1101 if Pl
= nil then Exit
;
1102 if Pl
.FDummy
then Exit
;
1104 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
1105 NetOut
.Write(gTime
);
1112 NetOut
.Write(FPing
);
1113 NetOut
.Write(FLoss
);
1114 if IsKeyPressed(KEY_CHAT
) then
1115 kByte
:= NET_KEY_CHAT
1118 if IsKeyPressed(KEY_LEFT
) then kByte
:= kByte
or NET_KEY_LEFT
;
1119 if IsKeyPressed(KEY_RIGHT
) then kByte
:= kByte
or NET_KEY_RIGHT
;
1120 if IsKeyPressed(KEY_UP
) then kByte
:= kByte
or NET_KEY_UP
;
1121 if IsKeyPressed(KEY_DOWN
) then kByte
:= kByte
or NET_KEY_DOWN
;
1122 if IsKeyPressed(KEY_JUMP
) then kByte
:= kByte
or NET_KEY_JUMP
;
1125 if JustTeleported
then kByte
:= kByte
or NET_KEY_FORCEDIR
;
1127 NetOut
.Write(kByte
);
1128 if Direction
= TDirection
.D_LEFT
then NetOut
.Write(Byte(0)) else NetOut
.Write(Byte(1));
1129 NetOut
.Write(GameX
);
1130 NetOut
.Write(GameY
);
1131 NetOut
.Write(GameVelX
);
1132 NetOut
.Write(GameVelY
);
1133 NetOut
.Write(GameAccelX
);
1134 NetOut
.Write(GameAccelY
);
1137 g_Net_Host_Send(ID
, Reliable
, NET_CHAN_PLAYERPOS
);
1140 procedure MH_SEND_PlayerStats(PID
: Word; ID
: Integer = NET_EVERYONE
);
1145 P
:= g_Player_Get(PID
);
1146 if P
= nil then Exit
;
1148 NetOut
.Write(Byte(NET_MSG_PLRSTA
));
1153 NetOut
.Write(Byte(alive
));
1154 NetOut
.Write(Byte(GodMode
));
1155 NetOut
.Write(Health
);
1156 NetOut
.Write(Armor
);
1158 NetOut
.Write(JetFuel
);
1159 NetOut
.Write(Lives
);
1162 for I
:= WP_FIRST
to WP_LAST
do
1163 NetOut
.Write(Byte(FWeapon
[I
]));
1165 for I
:= A_BULLETS
to A_HIGH
do
1166 NetOut
.Write(FAmmo
[I
]);
1168 for I
:= A_BULLETS
to A_HIGH
do
1169 NetOut
.Write(FMaxAmmo
[I
]);
1171 for I
:= MR_SUIT
to MR_MAX
do
1172 NetOut
.Write(LongWord(FMegaRulez
[I
]));
1174 NetOut
.Write(Byte(R_ITEM_BACKPACK
in FRulez
));
1175 NetOut
.Write(Byte(R_KEY_RED
in FRulez
));
1176 NetOut
.Write(Byte(R_KEY_GREEN
in FRulez
));
1177 NetOut
.Write(Byte(R_KEY_BLUE
in FRulez
));
1178 NetOut
.Write(Byte(R_BERSERK
in FRulez
));
1180 NetOut
.Write(Frags
);
1181 NetOut
.Write(Death
);
1183 NetOut
.Write(CurrWeap
);
1185 NetOut
.Write(Byte(FSpectator
));
1186 NetOut
.Write(Byte(FGhost
));
1187 NetOut
.Write(Byte(FPhysics
));
1188 NetOut
.Write(Byte(FNoRespawn
));
1189 NetOut
.Write(Byte(FJetpack
));
1190 NetOut
.Write(FFireTime
);
1191 NetOut
.Write(Byte(FFlaming
));
1192 NetOut
.Write(FSpawnInvul
);
1195 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1198 procedure MH_SEND_PlayerDamage(PID
: Word; Kind
: Byte; Attacker
, Value
: Word; VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1200 NetOut
.Write(Byte(NET_MSG_PLRDMG
));
1203 NetOut
.Write(Attacker
);
1204 NetOut
.Write(Value
);
1208 g_Net_Host_Send(ID
, False, NET_CHAN_PLAYER
);
1211 procedure MH_SEND_PlayerDeath(PID
: Word; KillType
, DeathType
: Byte; Attacker
: Word; ID
: Integer = NET_EVERYONE
);
1213 NetOut
.Write(Byte(NET_MSG_PLRDIE
));
1215 NetOut
.Write(KillType
);
1216 NetOut
.Write(DeathType
);
1217 NetOut
.Write(Attacker
);
1219 g_Net_Host_Send(ID
, True, NET_CHAN_PLAYER
);
1222 procedure MH_SEND_PlayerFire(PID
: Word; Weapon
: Byte; X
, Y
, AX
, AY
: Integer; ShotID
: Integer = -1; ID
: Integer = NET_EVERYONE
);
1224 NetOut
.Write(Byte(NET_MSG_PLRFIRE
));
1226 NetOut
.Write(Weapon
);
1231 NetOut
.Write(ShotID
);
1233 g_Net_Host_Send(ID
, True, NET_CHAN_SHOTS
);
1236 procedure MH_SEND_PlayerDelete(PID
: Word; ID
: Integer = NET_EVERYONE
);
1238 NetOut
.Write(Byte(NET_MSG_PLRDEL
));
1241 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1244 procedure MH_SEND_PlayerSettings(PID
: Word; Mdl
: string = ''; ID
: Integer = NET_EVERYONE
);
1248 Pl
:= g_Player_Get(PID
);
1249 if Pl
= nil then Exit
;
1251 NetOut
.Write(Byte(NET_MSG_PLRSET
));
1253 NetOut
.Write(Pl
.Name
);
1255 NetOut
.Write(Pl
.Model
.Name
)
1258 NetOut
.Write(Pl
.FColor
.R
);
1259 NetOut
.Write(Pl
.FColor
.G
);
1260 NetOut
.Write(Pl
.FColor
.B
);
1261 NetOut
.Write(Pl
.Team
);
1263 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1268 procedure MH_SEND_ItemSpawn(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1273 it
:= g_Items_ByIdx(IID
);
1275 NetOut
.Write(Byte(NET_MSG_ISPAWN
));
1277 NetOut
.Write(Byte(Quiet
));
1279 if it
.dropped
then tt
:= tt
or $80;
1281 NetOut
.Write(Byte(it
.Fall
));
1282 NetOut
.Write(Byte(it
.Respawnable
));
1283 NetOut
.Write(it
.Obj
.X
);
1284 NetOut
.Write(it
.Obj
.Y
);
1285 NetOut
.Write(it
.Obj
.Vel
.X
);
1286 NetOut
.Write(it
.Obj
.Vel
.Y
);
1288 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1291 procedure MH_SEND_ItemDestroy(Quiet
: Boolean; IID
: Word; ID
: Integer = NET_EVERYONE
);
1293 NetOut
.Write(Byte(NET_MSG_IDEL
));
1295 NetOut
.Write(Byte(Quiet
));
1297 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1302 procedure MH_SEND_PanelTexture(PGUID
: Integer; AnimLoop
: Byte; ID
: Integer = NET_EVERYONE
);
1306 TP
:= g_Map_PanelByGUID(PGUID
);
1307 if (TP
= nil) then exit
;
1311 NetOut
.Write(Byte(NET_MSG_PTEX
));
1312 NetOut
.Write(LongWord(PGUID
));
1313 NetOut
.Write(FCurTexture
);
1314 NetOut
.Write(FCurFrame
);
1315 NetOut
.Write(FCurFrameCount
);
1316 NetOut
.Write(AnimLoop
);
1319 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1322 procedure MH_SEND_PanelState(PGUID
: Integer; ID
: Integer = NET_EVERYONE
);
1327 TP
:= g_Map_PanelByGUID(PGUID
);
1328 if (TP
= nil) then exit
;
1330 NetOut
.Write(Byte(NET_MSG_PSTATE
));
1331 NetOut
.Write(LongWord(PGUID
));
1332 NetOut
.Write(Byte(TP
.Enabled
));
1333 NetOut
.Write(TP
.LiftType
);
1336 NetOut
.Write(Word(TP
.Width
));
1337 NetOut
.Write(Word(TP
.Height
));
1339 NetOut
.Write(LongInt(TP
.movingSpeedX
));
1340 NetOut
.Write(LongInt(TP
.movingSpeedY
));
1341 NetOut
.Write(LongInt(TP
.movingStartX
));
1342 NetOut
.Write(LongInt(TP
.movingStartY
));
1343 NetOut
.Write(LongInt(TP
.movingEndX
));
1344 NetOut
.Write(LongInt(TP
.movingEndY
));
1345 NetOut
.Write(LongInt(TP
.sizeSpeedX
));
1346 NetOut
.Write(LongInt(TP
.sizeSpeedY
));
1347 NetOut
.Write(LongInt(TP
.sizeEndX
));
1348 NetOut
.Write(LongInt(TP
.sizeEndY
));
1349 if TP
.movingActive
then mpflags
:= mpflags
or 1;
1350 if TP
.moveOnce
then mpflags
:= mpflags
or 2;
1351 NetOut
.Write(Byte(mpflags
));
1353 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1358 procedure MH_SEND_TriggerSound(var T
: TTrigger
; ID
: Integer = NET_EVERYONE
);
1360 if gTriggers
= nil then Exit
;
1361 if T
.Sound
= nil then Exit
;
1363 NetOut
.Write(Byte(NET_MSG_TSOUND
));
1364 NetOut
.Write(T
.ClientID
);
1365 NetOut
.Write(Byte(T
.Sound
.IsPlaying
));
1366 NetOut
.Write(LongWord(T
.Sound
.GetPosition
));
1367 NetOut
.Write(T
.SoundPlayCount
);
1369 g_Net_Host_Send(ID
, True);
1372 procedure MH_SEND_TriggerMusic(ID
: Integer = NET_EVERYONE
);
1374 NetOut
.Write(Byte(NET_MSG_TMUSIC
));
1375 NetOut
.Write(gMusic
.Name
);
1376 NetOut
.Write(Byte(gMusic
.IsPlaying
));
1377 NetOut
.Write(LongWord(gMusic
.GetPosition
));
1378 NetOut
.Write(Byte(gMusic
.SpecPause
or gMusic
.IsPaused
));
1380 g_Net_Host_Send(ID
, True);
1385 procedure MH_SEND_MonsterSpawn(UID
: Word; ID
: Integer = NET_EVERYONE
);
1389 M
:= g_Monsters_ByUID(UID
);
1395 NetOut
.Write(Byte(NET_MSG_MSPAWN
));
1397 NetOut
.Write(MonsterType
);
1398 NetOut
.Write(MonsterState
);
1399 NetOut
.Write(MonsterAnim
);
1400 NetOut
.Write(MonsterTargetUID
);
1401 NetOut
.Write(MonsterTargetTime
);
1402 NetOut
.Write(MonsterBehaviour
);
1403 NetOut
.Write(MonsterSleep
);
1404 NetOut
.Write(MonsterHealth
);
1405 NetOut
.Write(MonsterAmmo
);
1406 NetOut
.Write(GameX
);
1407 NetOut
.Write(GameY
);
1408 NetOut
.Write(GameVelX
);
1409 NetOut
.Write(GameVelY
);
1410 NetOut
.Write(Byte(GameDirection
));
1413 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1416 procedure MH_SEND_MonsterPos(UID
: Word; ID
: Integer = NET_EVERYONE
);
1420 M
:= g_Monsters_ByUID(UID
);
1421 if M
= nil then Exit
;
1423 NetOut
.Write(Byte(NET_MSG_MPOS
));
1428 NetOut
.Write(GameX
);
1429 NetOut
.Write(GameY
);
1430 NetOut
.Write(GameVelX
);
1431 NetOut
.Write(GameVelY
);
1432 NetOut
.Write(Byte(GameDirection
));
1435 g_Net_Host_Send(ID
, False, NET_CHAN_MONSTERPOS
);
1438 procedure MH_SEND_MonsterState(UID
: Word; ForcedAnim
: Byte = 255; ID
: Integer = NET_EVERYONE
);
1442 M
:= g_Monsters_ByUID(UID
);
1443 if M
= nil then Exit
;
1445 NetOut
.Write(Byte(NET_MSG_MSTATE
));
1450 NetOut
.Write(MonsterState
);
1451 NetOut
.Write(ForcedAnim
);
1452 NetOut
.Write(MonsterTargetUID
);
1453 NetOut
.Write(MonsterTargetTime
);
1454 NetOut
.Write(MonsterSleep
);
1455 NetOut
.Write(MonsterHealth
);
1456 NetOut
.Write(MonsterAmmo
);
1457 NetOut
.Write(MonsterPain
);
1458 NetOut
.Write(Byte(AnimIsReverse
));
1459 NetOut
.Write(FFireTime
);
1462 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1465 procedure MH_SEND_MonsterShot(UID
: Word; X
, Y
, VX
, VY
: Integer; ID
: Integer = NET_EVERYONE
);
1467 NetOut
.Write(Byte(NET_MSG_MSHOT
));
1474 g_Net_Host_Send(ID
, True, NET_CHAN_MONSTER
);
1477 procedure MH_SEND_MonsterDelete(UID
: Word; ID
: Integer = NET_EVERYONE
);
1481 M
:= g_Monsters_ByUID(UID
);
1482 if M
= nil then Exit
;
1484 NetOut
.Write(Byte(NET_MSG_MDEL
));
1487 g_Net_Host_Send(ID
, True, NET_CHAN_LARGEDATA
);
1492 procedure MH_SEND_TimeSync(Time
: LongWord; ID
: Integer = NET_EVERYONE
);
1494 NetOut
.Write(Byte(NET_MSG_TIME_SYNC
));
1497 g_Net_Host_Send(ID
, False, NET_CHAN_SERVICE
);
1500 procedure MH_SEND_VoteEvent(EvType
: Byte;
1501 StrArg1
: string = 'a'; StrArg2
: string = 'b';
1502 IntArg1
: SmallInt = 0; IntArg2
: SmallInt = 0;
1503 ID
: Integer = NET_EVERYONE
);
1505 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
1506 NetOut
.Write(EvType
);
1507 NetOut
.Write(IntArg1
);
1508 NetOut
.Write(IntArg2
);
1509 NetOut
.Write(StrArg1
);
1510 NetOut
.Write(StrArg2
);
1512 g_Net_Host_Send(ID
, True, NET_CHAN_IMPORTANT
);
1515 // CLIENT MESSAGES //
1519 procedure MC_RECV_Chat(var M
: TMsg
);
1524 Txt
:= M
.ReadString();
1525 Mode
:= M
.ReadByte();
1527 if Mode
<> NET_CHAT_SYSTEM
then
1529 if NetDeafLevel
= 0 then
1531 if Mode
= NET_CHAT_PLAYER
then
1533 g_Console_Add(Txt
, True);
1534 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1535 g_Game_ChatSound(b_Text_Unformat(Txt
));
1537 if (Mode
= NET_CHAT_TEAM
) and (gPlayer1
<> nil) then
1539 if gPlayer1
.Team
= TEAM_RED
then
1540 g_Console_Add(b_Text_Format('\r[Team] ') + Txt
, True);
1541 if gPlayer1
.Team
= TEAM_BLUE
then
1542 g_Console_Add(b_Text_Format('\b[Team] ') + Txt
, True);
1543 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt
), TMsgType
.Notify
);
1544 g_Game_ChatSound(b_Text_Unformat(Txt
));
1547 end else if (NetDeafLevel
< 2) then
1548 g_Console_Add(Txt
, True);
1551 procedure MC_RECV_Effect(var M
: TMsg
);
1559 if not gGameOn
then Exit
;
1560 Kind
:= M
.ReadByte();
1561 X
:= M
.ReadLongInt();
1562 Y
:= M
.ReadLongInt();
1563 Ang
:= M
.ReadSmallInt();
1567 g_GFX_Spark(X
, Y
, 2 + Random(2), Ang
, 0, 0);
1571 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
1573 Anim
:= TAnimation
.Create(ID
, False, 3);
1574 g_GFX_OnceAnim(X
, Y
, Anim
);
1578 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
1583 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_ROCKET') then
1585 Anim
:= TAnimation
.Create(ID
, False, 6);
1586 Anim
.Blending
:= False;
1587 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1591 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X
, Y
);
1596 if g_Frames_Get(ID
, 'FRAMES_EXPLODE_BFG') then
1598 Anim
:= TAnimation
.Create(ID
, False, 6);
1599 Anim
.Blending
:= False;
1600 g_GFX_OnceAnim(X
-64, Y
-64, Anim
);
1604 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X
, Y
);
1609 if g_Frames_Get(ID
, 'FRAMES_BFGHIT') then
1611 Anim
:= TAnimation
.Create(ID
, False, 4);
1612 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
1619 if g_Frames_Get(ID
, 'FRAMES_FIRE') then
1621 Anim
:= TAnimation
.Create(ID
, False, 4);
1622 g_GFX_OnceAnim(X
, Y
, Anim
);
1626 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
1631 if g_Frames_Get(ID
, 'FRAMES_ITEM_RESPAWN') then
1633 Anim
:= TAnimation
.Create(ID
, False, 4);
1634 g_GFX_OnceAnim(X
, Y
, Anim
);
1638 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
1642 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_BULLET
);
1645 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1649 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1650 g_Player_CreateShell(X
, Y
, 0, -2, SHELL_SHELL
);
1655 procedure MC_RECV_Sound(var M
: TMsg
);
1661 Name
:= M
.ReadString();
1662 Pos
:= M
.ReadByte() <> 0;
1665 X
:= M
.ReadLongInt();
1666 Y
:= M
.ReadLongInt();
1667 g_Sound_PlayExAt(Name
, X
, Y
);
1670 g_Sound_PlayEx(Name
);
1673 procedure MC_RECV_CreateShot(var M
: TMsg
);
1675 I
, X
, Y
, XV
, YV
: Integer;
1677 Target
, Spawner
: Word;
1680 I
:= M
.ReadLongInt();
1681 ShType
:= M
.ReadByte();
1682 Target
:= M
.ReadWord();
1683 Spawner
:= M
.ReadWord();
1684 Timeout
:= M
.ReadLongWord();
1685 X
:= M
.ReadLongInt();
1686 Y
:= M
.ReadLongInt();
1687 XV
:= M
.ReadLongInt();
1688 YV
:= M
.ReadLongInt();
1690 I
:= g_Weapon_CreateShot(I
, ShType
, Spawner
, Target
, X
, Y
, XV
, YV
);
1691 if (Shots
<> nil) and (I
<= High(Shots
)) then
1693 Shots
[I
].Timeout
:= Timeout
;
1694 //Shots[I].Target := Target; // TODO: find a use for Target later
1698 procedure MC_RECV_UpdateShot(var M
: TMsg
);
1700 I
, TX
, TY
, TXV
, TYV
: Integer;
1702 I
:= M
.ReadLongInt();
1703 TX
:= M
.ReadLongInt();
1704 TY
:= M
.ReadLongInt();
1705 TXV
:= M
.ReadLongInt();
1706 TYV
:= M
.ReadLongInt();
1708 if (Shots
<> nil) and (I
<= High(Shots
)) then
1718 procedure MC_RECV_DeleteShot(var M
: TMsg
);
1723 if not gGameOn
then Exit
;
1724 I
:= M
.ReadLongInt();
1725 L
:= (M
.ReadByte() <> 0);
1726 X
:= M
.ReadLongInt();
1727 Y
:= M
.ReadLongInt();
1729 g_Weapon_DestroyShot(I
, X
, Y
, L
);
1732 procedure MC_RECV_GameStats(var M
: TMsg
);
1734 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1736 gTeamStat
[TEAM_RED
].Goals
:= M
.ReadSmallInt();
1737 gTeamStat
[TEAM_BLUE
].Goals
:= M
.ReadSmallInt();
1740 if gGameSettings
.GameMode
= GM_COOP
then
1742 gCoopMonstersKilled
:= M
.ReadWord();
1743 gCoopSecretsFound
:= M
.ReadWord();
1747 procedure MC_RECV_CoopStats(var M
: TMsg
);
1749 gTotalMonsters
:= M
.ReadLongInt();
1750 gSecretsCount
:= M
.ReadLongInt();
1751 gCoopTotalMonstersKilled
:= M
.ReadWord();
1752 gCoopTotalSecretsFound
:= M
.ReadWord();
1753 gCoopTotalMonsters
:= M
.ReadWord();
1754 gCoopTotalSecrets
:= M
.ReadWord();
1757 procedure MC_RECV_GameEvent(var M
: TMsg
);
1766 i1
, i2
: TStrings_Locale
;
1769 goodCmd
: Boolean = true;
1771 FillChar(EvHash
, Sizeof(EvHash
), 0);
1772 EvType
:= M
.ReadByte();
1773 EvNum
:= M
.ReadLongInt();
1774 EvStr
:= M
.ReadString();
1775 gLastMap
:= M
.ReadByte() <> 0;
1776 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then gStatsOff
:= True;
1777 gStatsPressed
:= True;
1778 EvTime
:= M
.ReadLongWord();
1779 BHash
:= M
.ReadByte() <> 0;
1781 EvHash
:= M
.ReadMD5();
1785 if (g_Res_received_map_start
<> 0) then
1787 if (g_Res_received_map_start
< 0) then exit
;
1790 NET_EV_MAPSTART
: goodCmd
:= true;
1791 NET_EV_MAPEND
: goodCmd
:= true;
1792 NET_EV_PLAYER_KICK
: goodCmd
:= true;
1793 NET_EV_PLAYER_BAN
: goodCmd
:= true;
1794 NET_EV_LMS_WARMUP
: goodCmd
:= true;
1796 if not goodCmd
then exit
;
1802 if (g_Res_received_map_start
<> 0) then
1804 g_Res_received_map_start
:= -1;
1809 g_Game_ClearLoading();
1810 g_Game_StopAllSounds(True);
1812 gSwitchGameMode
:= Byte(EvNum
);
1813 gGameSettings
.GameMode
:= gSwitchGameMode
;
1816 if not g_Game_StartMap(false{asMegawad}, EvStr
, True) then
1818 if not isWadPath(EvStr
) then
1819 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + EvStr
]))
1821 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [EvStr
]));
1825 MC_SEND_FullStateRequest
;
1831 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1832 gLMSRespawnTime
:= 0;
1833 if (g_Res_received_map_start
<> 0) then
1835 g_Res_received_map_start
:= -1;
1839 gMissionFailed
:= EvNum
<> 0;
1840 gExit
:= EXIT_ENDLEVELCUSTOM
;
1848 g_Console_Add(_lc
[I_NET_RCON_NOAUTH
], True);
1850 g_Console_Add(_lc
[I_NET_RCON_PWD_VALID
], True);
1852 g_Console_Add(_lc
[I_NET_RCON_PWD_INVALID
], True);
1858 if NetDeafLevel
< 2 then
1860 if EvNum
= TEAM_RED
then
1861 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [EvStr
]), True);
1862 if EvNum
= TEAM_BLUE
then
1863 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [EvStr
]), True);
1869 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [EvStr
]), True);
1870 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1875 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [EvStr
]), True);
1876 if (g_Res_received_map_start
<> 0) then g_Res_received_map_start
:= -1;
1883 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
1884 gLMSRespawnTime
:= gTime
+ EvNum
;
1885 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [EvNum
div 1000]), True);
1887 else if gPlayer1
= nil then
1889 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
1893 NET_EV_LMS_SURVIVOR
:
1894 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True);
1897 if NetDeafLevel
< 2 then g_Game_Message(AnsiUpperCase(EvStr
), Word(EvNum
));
1901 pl
:= g_Player_Get(EvNum
and $FFFF);
1906 cnt
:= (EvNum
shr 16) and $FF;
1907 if Pos('w', EvStr
) = 0 then
1910 if Pos('t', EvStr
) = 0 then
1913 if Pos('-', EvStr
) = 0 then
1915 if Pos('e', EvStr
) = 0 then
1916 i1
:= I_PLAYER_SCORE_ADD_OWN
1918 i1
:= I_PLAYER_SCORE_ADD_ENEMY
;
1921 if Pos('e', EvStr
) = 0 then
1922 i1
:= I_PLAYER_SCORE_SUB_OWN
1924 i1
:= I_PLAYER_SCORE_SUB_ENEMY
;
1927 if Pos('r', EvStr
) > 0 then
1928 i2
:= I_PLAYER_SCORE_TO_RED
1930 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1931 g_Console_Add(Format(_lc
[i1
], [pln
, cnt
, _lc
[i2
]]), True);
1935 if Pos('-', EvStr
) = 0 then
1936 i1
:= I_PLAYER_SCORE_ADD_TEAM
1938 i1
:= I_PLAYER_SCORE_SUB_TEAM
;
1940 if Pos('r', EvStr
) > 0 then
1941 i2
:= I_PLAYER_SCORE_RED
1943 i2
:= I_PLAYER_SCORE_BLUE
;
1944 g_Console_Add(Format(_lc
[i1
], [_lc
[i2
], cnt
]), True);
1949 if Pos('e', EvStr
) = 0 then
1950 i1
:= I_PLAYER_SCORE_WIN_OWN
1952 i1
:= I_PLAYER_SCORE_WIN_ENEMY
;
1954 if Pos('r', EvStr
) > 0 then
1955 i2
:= I_PLAYER_SCORE_TO_RED
1957 i2
:= I_PLAYER_SCORE_TO_BLUE
;
1958 g_Console_Add(Format(_lc
[i1
], [pln
, _lc
[i2
]]), True);
1964 if EvNum
= TEAM_RED
then
1965 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1966 if EvNum
= TEAM_BLUE
then
1967 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1968 if EvNum
= -TEAM_RED
then
1969 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1970 if EvNum
= -TEAM_BLUE
then
1971 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1976 g_Player_RemoveAllCorpses
;
1977 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1978 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
1982 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(EvStr
)]), 144);
1986 if EvNum
= TEAM_RED
then
1987 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
1988 if EvNum
= TEAM_BLUE
then
1989 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
1993 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
1996 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
1999 g_Console_Add(_lc
[I_PLAYER_SPECT4
], True);
2002 g_Game_Announce_KillCombo(EvNum
);
2004 NET_EV_PLAYER_TOUCH
:
2006 pl
:= g_Player_Get(EvNum
);
2013 pl
:= g_Player_Get(EvNum
);
2016 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [pl
.Name
]), True);
2017 g_Sound_PlayEx('SOUND_GAME_SECRET');
2023 pl
:= g_Player_Get(EvNum
);
2024 if pl
<> nil then pl
.FReady
:= (EvStr
= 'Y');
2029 procedure MC_RECV_FlagEvent(var M
: TMsg
);
2038 EvType
:= M
.ReadByte();
2041 if Fl
= FLAG_NONE
then Exit
;
2043 Quiet
:= (M
.ReadByte() <> 0);
2044 PID
:= M
.ReadWord();
2046 gFlags
[Fl
].State
:= M
.ReadByte();
2047 gFlags
[Fl
].CaptureTime
:= M
.ReadLongWord();
2048 gFlags
[Fl
].Obj
.X
:= M
.ReadLongInt();
2049 gFlags
[Fl
].Obj
.Y
:= M
.ReadLongInt();
2050 gFlags
[Fl
].Obj
.Vel
.X
:= M
.ReadLongInt();
2051 gFlags
[Fl
].Obj
.Vel
.Y
:= M
.ReadLongInt();
2053 Pl
:= g_Player_Get(PID
);
2055 (EvType
<> FLAG_STATE_NORMAL
) and
2056 (EvType
<> FLAG_STATE_DROPPED
) and
2057 (EvType
<> FLAG_STATE_RETURNED
) then
2063 if Quiet
or (Pl
= nil) then Exit
;
2065 if Fl
= FLAG_RED
then
2066 s
:= _lc
[I_PLAYER_FLAG_RED
]
2068 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2070 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2072 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2073 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2074 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2079 if not sound_ret_flag
[a
].IsPlaying() then
2080 sound_ret_flag
[a
].Play();
2083 FLAG_STATE_CAPTURED
:
2085 if (Pl
<> nil) then Pl
.SetFlag(Fl
);
2089 if Fl
= FLAG_RED
then
2090 s
:= _lc
[I_PLAYER_FLAG_RED
]
2092 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2094 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [Pl
.Name
, s
]), True);
2095 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
2097 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2098 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2099 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2104 if not sound_get_flag
[a
].IsPlaying() then
2105 sound_get_flag
[a
].Play();
2110 if (Pl
<> nil) then Pl
.SetFlag(FLAG_NONE
);
2112 if Quiet
or (Pl
= nil) then Exit
;
2114 if Fl
= FLAG_RED
then
2115 s
:= _lc
[I_PLAYER_FLAG_RED
]
2117 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2119 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [Pl
.Name
, s
]), True);
2120 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
2122 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2123 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2124 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2129 if not sound_lost_flag
[a
].IsPlaying() then
2130 sound_lost_flag
[a
].Play();
2135 g_Map_ResetFlag(FLAG_RED
);
2136 g_Map_ResetFlag(FLAG_BLUE
);
2137 if Quiet
or (Pl
= nil) then Exit
;
2138 Pl
.SetFlag(FLAG_NONE
);
2140 if Fl
= FLAG_RED
then
2141 s
:= _lc
[I_PLAYER_FLAG_RED
]
2143 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2145 ts
:= Format('%.4d', [gFlags
[Fl
].CaptureTime
]);
2146 Insert('.', ts
, Length(ts
) + 1 - 3);
2147 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [Pl
.Name
, s
, ts
]), True);
2148 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
2150 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2151 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2152 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2157 if not sound_cap_flag
[a
].IsPlaying() then
2158 sound_cap_flag
[a
].Play();
2161 FLAG_STATE_RETURNED
:
2163 g_Map_ResetFlag(Fl
);
2166 if Fl
= FLAG_RED
then
2167 s
:= _lc
[I_PLAYER_FLAG_RED
]
2169 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2171 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2173 if ((Pl
= gPlayer1
) or (Pl
= gPlayer2
)
2174 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= Pl
.Team
))
2175 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= Pl
.Team
))) then
2180 if not sound_ret_flag
[a
].IsPlaying() then
2181 sound_ret_flag
[a
].Play();
2186 procedure MC_RECV_GameSettings(var M
: TMsg
);
2188 gGameSettings
.GameMode
:= M
.ReadByte();
2189 gGameSettings
.GoalLimit
:= M
.ReadWord();
2190 gGameSettings
.TimeLimit
:= M
.ReadWord();
2191 gGameSettings
.MaxLives
:= M
.ReadByte();
2192 gGameSettings
.Options
:= M
.ReadLongWord();
2197 function MC_RECV_PlayerCreate(var M
: TMsg
): Word;
2200 PName
, Model
: string;
2205 PID
:= M
.ReadWord();
2206 Pl
:= g_Player_Get(PID
);
2208 PName
:= M
.ReadString();
2209 Model
:= M
.ReadString();
2210 Color
.R
:= M
.ReadByte();
2211 Color
.G
:= M
.ReadByte();
2212 Color
.B
:= M
.ReadByte();
2216 if (PID
<> NetPlrUID1
) and (PID
<> NetPlrUID2
) then
2218 if (Pl
<> nil) then Exit
;
2219 DID
:= g_Player_Create(Model
, Color
, T
, False);
2220 with g_Player_Get(DID
) do
2229 if (PID
= NetPlrUID1
) and (gPlayer1
<> nil) then begin
2230 gPlayer1
.UID
:= PID
;
2231 gPlayer1
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2232 gPlayer1
.ChangeTeam(T
);
2234 if (PID
= NetPlrUID2
) and (gPlayer2
<> nil) then begin
2235 gPlayer2
.UID
:= PID
;
2236 gPlayer2
.Model
.SetColor(Color
.R
, Color
.G
, Color
.B
);
2237 gPlayer2
.ChangeTeam(T
);
2241 if NetDeafLevel
< 3 then
2242 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [PName
]), True);
2243 e_WriteLog('NET: Player ' + PName
+ ' [' + IntToStr(PID
) + '] added.', TMsgType
.Notify
);
2247 function MC_RECV_PlayerPos(var M
: TMsg
): Word;
2254 TmpX
, TmpY
: Integer;
2258 GT
:= M
.ReadLongWord();
2259 if GT
< gTime
- NET_MAX_DIFFTIME
then
2266 PID
:= M
.ReadWord();
2267 Pl
:= g_Player_Get(PID
);
2269 if Pl
= nil then Exit
;
2275 FPing
:= M
.ReadWord();
2276 FLoss
:= M
.ReadByte();
2277 kByte
:= M
.ReadWord();
2278 Dir
:= M
.ReadByte();
2280 TmpX
:= M
.ReadLongInt();
2281 TmpY
:= M
.ReadLongInt();
2285 if LongBool(kByte
and NET_KEY_CHAT
) then
2286 PressKey(KEY_CHAT
, 10000)
2289 if LongBool(kByte
and NET_KEY_LEFT
) then PressKey(KEY_LEFT
, 10000);
2290 if LongBool(kByte
and NET_KEY_RIGHT
) then PressKey(KEY_RIGHT
, 10000);
2291 if LongBool(kByte
and NET_KEY_UP
) then PressKey(KEY_UP
, 10000);
2292 if LongBool(kByte
and NET_KEY_DOWN
) then PressKey(KEY_DOWN
, 10000);
2293 if LongBool(kByte
and NET_KEY_JUMP
) then PressKey(KEY_JUMP
, 10000);
2296 JustTeleported
:= LongBool(kByte
and NET_KEY_FORCEDIR
);
2298 if ((Pl
<> gPlayer1
) and (Pl
<> gPlayer2
)) or JustTeleported
then
2299 SetDirection(TDirection(Dir
));
2301 GameVelX
:= M
.ReadLongInt();
2302 GameVelY
:= M
.ReadLongInt();
2303 GameAccelX
:= M
.ReadLongInt();
2304 GameAccelY
:= M
.ReadLongInt();
2305 SetLerp(TmpX
, TmpY
);
2306 if NetForcePlayerUpdate
then Update();
2310 function MC_RECV_PlayerStats(var M
: TMsg
): Word;
2314 I
, OldFire
: Integer;
2315 OldJet
, Flam
: Boolean;
2318 PID
:= M
.ReadWord();
2319 Pl
:= g_Player_Get(PID
);
2326 alive
:= (M
.ReadByte() <> 0);
2327 GodMode
:= (M
.ReadByte() <> 0);
2328 Health
:= M
.ReadLongInt();
2329 Armor
:= M
.ReadLongInt();
2330 Air
:= M
.ReadLongInt();
2331 JetFuel
:= M
.ReadLongInt();
2332 Lives
:= M
.ReadByte();
2333 NewTeam
:= M
.ReadByte();
2335 for I
:= WP_FIRST
to WP_LAST
do
2336 FWeapon
[I
] := (M
.ReadByte() <> 0);
2338 for I
:= A_BULLETS
to A_HIGH
do
2339 FAmmo
[I
] := M
.ReadWord();
2341 for I
:= A_BULLETS
to A_HIGH
do
2342 FMaxAmmo
[I
] := M
.ReadWord();
2344 for I
:= MR_SUIT
to MR_MAX
do
2345 FMegaRulez
[I
] := M
.ReadLongWord();
2348 if (M
.ReadByte() <> 0) then
2349 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
2350 if (M
.ReadByte() <> 0) then
2351 FRulez
:= FRulez
+ [R_KEY_RED
];
2352 if (M
.ReadByte() <> 0) then
2353 FRulez
:= FRulez
+ [R_KEY_GREEN
];
2354 if (M
.ReadByte() <> 0) then
2355 FRulez
:= FRulez
+ [R_KEY_BLUE
];
2356 if (M
.ReadByte() <> 0) then
2357 FRulez
:= FRulez
+ [R_BERSERK
];
2359 Frags
:= M
.ReadLongInt();
2360 Death
:= M
.ReadLongInt();
2362 SetWeapon(M
.ReadByte());
2364 FSpectator
:= M
.ReadByte() <> 0;
2367 if UID
= NetPlrUID1
then
2369 gSpectLatchPID1
:= UID
;
2372 if UID
= NetPlrUID2
then
2374 gSpectLatchPID2
:= UID
;
2380 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) and (UID
= gSpectLatchPID1
) then
2383 gSpectLatchPID1
:= 0;
2385 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) and (UID
= gSpectLatchPID2
) then
2388 gSpectLatchPID2
:= 0;
2391 FGhost
:= M
.ReadByte() <> 0;
2392 FPhysics
:= M
.ReadByte() <> 0;
2393 FNoRespawn
:= M
.ReadByte() <> 0;
2395 FJetpack
:= M
.ReadByte() <> 0;
2396 OldFire
:= FFireTime
;
2397 FFireTime
:= M
.ReadLongInt();
2398 if (OldFire
<= 0) and (FFireTime
> 0) then
2399 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2400 Flam
:= M
.ReadByte() <> 0;
2401 FSpawnInvul
:= M
.ReadLongInt();
2402 if OldJet
and not FJetpack
then
2404 else if not OldJet
and FJetpack
then
2406 if FFlaming
and not Flam
then
2408 if Team
<> NewTeam
then
2409 Pl
.ChangeTeam(NewTeam
);
2415 function MC_RECV_PlayerDamage(var M
: TMsg
): Word;
2420 Attacker
, Value
: Word;
2424 if not gGameOn
then Exit
;
2425 PID
:= M
.ReadWord();
2426 Pl
:= g_Player_Get(PID
);
2427 if Pl
= nil then Exit
;
2429 Kind
:= M
.ReadByte();
2430 Attacker
:= M
.ReadWord();
2431 Value
:= M
.ReadWord();
2436 Damage(Value
, Attacker
, VX
, VY
, Kind
);
2441 function MC_RECV_PlayerDeath(var M
: TMsg
): Word;
2445 KillType
, DeathType
: Byte;
2449 if not gGameOn
then Exit
;
2450 PID
:= M
.ReadWord();
2451 Pl
:= g_Player_Get(PID
);
2452 if Pl
= nil then Exit
;
2454 KillType
:= M
.ReadByte();
2455 DeathType
:= M
.ReadByte();
2456 Attacker
:= M
.ReadWord();
2460 Kill(KillType
, Attacker
, DeathType
);
2465 function MC_RECV_PlayerDelete(var M
: TMsg
): Word;
2470 PID
:= M
.ReadWord();
2471 Pl
:= g_Player_Get(PID
);
2473 if Pl
= nil then Exit
;
2475 if NetDeafLevel
< 3 then
2476 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2477 e_WriteLog('NET: Player ' + Pl
.Name
+ ' [' + IntToStr(PID
) + '] removed.', TMsgType
.Notify
);
2479 g_Player_Remove(PID
);
2484 function MC_RECV_PlayerFire(var M
: TMsg
): Word;
2489 X
, Y
, AX
, AY
: Integer;
2493 if not gGameOn
then Exit
;
2494 PID
:= M
.ReadWord();
2495 Pl
:= g_Player_Get(PID
);
2496 if Pl
= nil then Exit
;
2498 Weap
:= M
.ReadByte();
2499 X
:= M
.ReadLongInt();
2500 Y
:= M
.ReadLongInt();
2501 AX
:= M
.ReadLongInt();
2502 AY
:= M
.ReadLongInt();
2503 SHID
:= M
.ReadLongInt();
2506 if alive
then NetFire(Weap
, X
, Y
, AX
, AY
, SHID
);
2509 procedure MC_RECV_PlayerSettings(var M
: TMsg
);
2518 PID
:= M
.ReadWord();
2519 Pl
:= g_Player_Get(PID
);
2520 if Pl
= nil then Exit
;
2522 TmpName
:= M
.ReadString();
2523 TmpModel
:= M
.ReadString();
2524 TmpColor
.R
:= M
.ReadByte();
2525 TmpColor
.G
:= M
.ReadByte();
2526 TmpColor
.B
:= M
.ReadByte();
2527 TmpTeam
:= M
.ReadByte();
2529 if (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) and (Pl
.Team
<> TmpTeam
) then
2531 Pl
.ChangeTeam(TmpTeam
);
2532 if gPlayer1
= Pl
then
2533 gPlayer1Settings
.Team
:= TmpTeam
;
2534 if gPlayer2
= Pl
then
2535 gPlayer2Settings
.Team
:= TmpTeam
;
2537 Pl
.SetColor(TmpColor
);
2539 if Pl
.Name
<> TmpName
then
2541 if NetDeafLevel
< 3 then
2542 g_Console_Add(Format(_lc
[I_PLAYER_NAME
], [Pl
.Name
, TmpName
]), True);
2546 if TmpModel
<> Pl
.Model
.Name
then
2547 Pl
.SetModel(TmpModel
);
2552 procedure MC_RECV_ItemSpawn(var M
: TMsg
);
2556 X
, Y
, VX
, VY
: Integer;
2558 Quiet
, Fall
{, Resp}: Boolean;
2562 if not gGameOn
then Exit
;
2564 Quiet
:= M
.ReadByte() <> 0;
2566 Fall
:= M
.ReadByte() <> 0;
2567 {Resp :=} M
.ReadByte();
2568 X
:= M
.ReadLongInt();
2569 Y
:= M
.ReadLongInt();
2570 VX
:= M
.ReadLongInt();
2571 VY
:= M
.ReadLongInt();
2573 g_Items_Create(X
, Y
, T
and $7F, Fall
, False, False, ID
);
2574 if ((T
and $80) <> 0) then g_Items_SetDrop(ID
);
2576 it
:= g_Items_ByIdx(ID
);
2582 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
2583 if g_Frames_Get(AID
, 'FRAMES_ITEM_RESPAWN') then
2585 Anim
:= TAnimation
.Create(AID
, False, 4);
2586 g_GFX_OnceAnim(X
+(it
.Obj
.Rect
.Width
div 2)-16, Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
2592 procedure MC_RECV_ItemDestroy(var M
: TMsg
);
2597 if not gGameOn
then Exit
;
2599 Quiet
:= M
.ReadByte() <> 0;
2601 if not g_Items_ValidId(ID
) then exit
;
2603 if not Quiet
then g_Items_EmitPickupSound(ID
);
2610 procedure MC_RECV_PanelTexture(var M
: TMsg
);
2617 if not gGameOn
then Exit
;
2619 PGUID
:= Integer(M
.ReadLongWord());
2620 Tex
:= M
.ReadLongInt();
2621 Fr
:= M
.ReadLongInt();
2622 Cnt
:= M
.ReadByte();
2623 Loop
:= M
.ReadByte();
2625 TP
:= g_Map_PanelByGUID(PGUID
);
2629 TP
.SetTexture(Tex
, Loop
);
2630 TP
.SetFrame(Fr
, Cnt
);
2634 procedure MC_RECV_PanelState(var M
: TMsg
);
2639 X
, Y
, W
, H
: Integer;
2641 speedX
, speedY
, startX
, startY
, endX
, endY
: Integer;
2642 sizeSpX
, sizeSpY
, sizeEX
, sizeEY
: Integer;
2645 if not gGameOn
then Exit
;
2647 PGUID
:= Integer(M
.ReadLongWord());
2648 E
:= (M
.ReadByte() <> 0);
2649 Lift
:= M
.ReadByte();
2650 X
:= M
.ReadLongInt();
2651 Y
:= M
.ReadLongInt();
2655 speedX
:= M
.ReadLongInt();
2656 speedY
:= M
.ReadLongInt();
2657 startX
:= M
.ReadLongInt();
2658 startY
:= M
.ReadLongInt();
2659 endX
:= M
.ReadLongInt();
2660 endY
:= M
.ReadLongInt();
2661 sizeSpX
:= M
.ReadLongInt();
2662 sizeSpY
:= M
.ReadLongInt();
2663 sizeEX
:= M
.ReadLongInt();
2664 sizeEY
:= M
.ReadLongInt();
2665 mpflags
:= M
.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2667 TP
:= g_Map_PanelByGUID(PGUID
);
2668 if (TP
= nil) then exit
;
2670 // update lifts state
2671 if TP
.isGLift
then g_Map_SetLiftGUID(PGUID
, Lift
);
2673 // update enabled/disabled state for all panels
2674 if E
then g_Map_EnableWallGUID(PGUID
) else g_Map_DisableWallGUID(PGUID
);
2676 // update panel position, as it can be moved (mplat)
2681 // update mplat state
2682 TP
.movingSpeedX
:= speedX
;
2683 TP
.movingSpeedY
:= speedY
;
2684 TP
.movingStartX
:= startX
;
2685 TP
.movingStartY
:= startY
;
2686 TP
.movingEndX
:= endX
;
2687 TP
.movingEndY
:= endY
;
2688 TP
.sizeSpeedX
:= sizeSpX
;
2689 TP
.sizeSpeedY
:= sizeSpY
;
2690 TP
.sizeEndX
:= sizeEX
;
2691 TP
.sizeEndY
:= sizeEY
;
2692 TP
.movingActive
:= ((mpflags
and 1) <> 0);
2693 TP
.moveOnce
:= ((mpflags
and 2) <> 0);
2694 // notify panel of it's position/size change, so it can fix other internal structures
2695 TP
.positionChanged();
2700 procedure MC_RECV_TriggerSound(var M
: TMsg
);
2703 SPos
, SID
: LongWord;
2707 if not gGameOn
then Exit
;
2708 if gTriggers
= nil then Exit
;
2710 SID
:= M
.ReadLongWord();
2711 SPlaying
:= M
.ReadByte() <> 0;
2712 SPos
:= M
.ReadLongWord();
2713 SCount
:= M
.ReadLongInt();
2715 for I
:= Low(gTriggers
) to High(gTriggers
) do
2716 if gTriggers
[I
].TriggerType
= TRIGGER_SOUND
then
2717 if gTriggers
[I
].ClientID
= SID
then
2718 with gTriggers
[I
] do
2720 if Sound
<> nil then
2725 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0)
2727 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2728 Sound
.SetPosition(SPos
);
2731 if Sound
.IsPlaying
then Sound
.Stop
;
2734 SoundPlayCount
:= SCount
;
2738 procedure MC_RECV_TriggerMusic(var M
: TMsg
);
2745 if not gGameOn
then Exit
;
2747 MName
:= M
.ReadString();
2748 MPlaying
:= M
.ReadByte() <> 0;
2749 MPos
:= M
.ReadLongWord();
2750 MPaused
:= M
.ReadByte() <> 0;
2751 MPos
:= MPos
+1; //k8: stfu, fpc!
2755 gMusic
.SetByName(MName
);
2757 // gMusic.SetPosition(MPos);
2758 gMusic
.SpecPause
:= MPaused
;
2761 if gMusic
.IsPlaying
then gMusic
.Stop
;
2766 procedure MC_RECV_MonsterSpawn(var M
: TMsg
);
2769 MType
, MState
, MDir
, MAnim
, MBehav
: Byte;
2770 X
, Y
, VX
, VY
, MTargTime
, MHealth
, MAmmo
, MSleep
: Integer;
2775 Mon
:= g_Monsters_ByUID(ID
);
2779 MType
:= M
.ReadByte();
2780 MState
:= M
.ReadByte();
2781 MAnim
:= M
.ReadByte();
2782 MTarg
:= M
.ReadWord();
2783 MTargTime
:= M
.ReadLongInt();
2784 MBehav
:= M
.ReadByte();
2785 MSleep
:= M
.ReadLongInt();
2786 MHealth
:= M
.ReadLongInt();
2787 MAmmo
:= M
.ReadLongInt();
2789 X
:= M
.ReadLongInt();
2790 Y
:= M
.ReadLongInt();
2791 VX
:= M
.ReadLongInt();
2792 VY
:= M
.ReadLongInt();
2793 MDir
:= M
.ReadByte();
2795 g_Monsters_Create(MType
, X
, Y
, TDirection(MDir
), False, ID
);
2796 Mon
:= g_Monsters_ByUID(ID
);
2803 MonsterAnim
:= MAnim
;
2804 MonsterTargetUID
:= MTarg
;
2805 MonsterTargetTime
:= MTargTime
;
2806 MonsterBehaviour
:= MBehav
;
2807 MonsterSleep
:= MSleep
;
2808 MonsterAmmo
:= MAmmo
;
2813 setPosition(X
, Y
); // this will call positionChanged();
2819 procedure MC_RECV_MonsterPos(var M
: TMsg
);
2826 Mon
:= g_Monsters_ByUID(ID
);
2832 X
:= M
.ReadLongInt();
2833 Y
:= M
.ReadLongInt();
2834 Mon
.setPosition(X
, Y
); // this will call `positionChanged()`
2835 GameVelX
:= M
.ReadLongInt();
2836 GameVelY
:= M
.ReadLongInt();
2837 GameDirection
:= TDirection(M
.ReadByte());
2841 procedure MC_RECV_MonsterState(var M
: TMsg
);
2843 ID
, OldFire
: Integer;
2844 MState
, MFAnm
: Byte;
2846 AnimRevert
: Boolean;
2849 Mon
:= g_Monsters_ByUID(ID
);
2850 if Mon
= nil then Exit
;
2852 MState
:= M
.ReadByte();
2853 MFAnm
:= M
.ReadByte();
2857 MonsterTargetUID
:= M
.ReadWord();
2858 MonsterTargetTime
:= M
.ReadLongInt();
2859 MonsterSleep
:= M
.ReadLongInt();
2860 MonsterHealth
:= M
.ReadLongInt();
2861 MonsterAmmo
:= M
.ReadLongInt();
2862 MonsterPain
:= M
.ReadLongInt();
2863 AnimRevert
:= M
.ReadByte() <> 0;
2864 OldFire
:= FFireTime
;
2865 FFireTime
:= M
.ReadLongInt();
2866 if (OldFire
<= 0) and (FFireTime
> 0) then
2867 g_Sound_PlayExAt('SOUND_IGNITE', Obj
.X
, Obj
.Y
);
2868 RevertAnim(AnimRevert
);
2870 if MonsterState
<> MState
then
2872 if (MState
= MONSTATE_GO
) and (MonsterState
= MONSTATE_SLEEP
) then WakeUpSound();
2873 if (MState
= MONSTATE_DIE
) then DieSound();
2874 if (MState
= MONSTATE_PAIN
) then MakeBloodSimple(Min(200, MonsterPain
));
2875 if (MState
= MONSTATE_ATTACK
) then kick(nil);
2876 if (MState
= MONSTATE_DEAD
) then SetDeadAnim();
2878 SetState(MState
, MFAnm
);
2883 procedure MC_RECV_MonsterShot(var M
: TMsg
);
2887 X
, Y
, VX
, VY
: Integer;
2891 Mon
:= g_Monsters_ByUID(ID
);
2892 if Mon
= nil then Exit
;
2894 X
:= M
.ReadLongInt();
2895 Y
:= M
.ReadLongInt();
2896 VX
:= M
.ReadLongInt();
2897 VY
:= M
.ReadLongInt();
2899 Mon
.ClientAttack(X
, Y
, VX
, VY
);
2902 procedure MC_RECV_MonsterDelete(var M
: TMsg
);
2908 Mon
:= g_Monsters_ByUID(ID
);
2909 if Mon
= nil then Exit
;
2911 Mon
.MonsterRemoved
:= True;
2914 procedure MC_RECV_TimeSync(var M
: TMsg
);
2918 Time
:= M
.ReadLongWord();
2920 if gState
= STATE_INTERCUSTOM
then
2921 gServInterTime
:= Min(Time
, 255);
2924 procedure MC_RECV_VoteEvent(var M
: TMsg
);
2928 Int1
, Int2
: SmallInt;
2930 EvID
:= M
.ReadByte();
2931 Int1
:= M
.ReadSmallInt();
2932 Int2
:= M
.ReadSmallInt();
2933 Str1
:= M
.ReadString();
2934 Str2
:= M
.ReadString();
2936 if NetDeafLevel
< 2 then
2939 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Str1
, Str2
, Int1
]), True);
2941 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [Str1
]), True);
2943 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
2945 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [Str1
, Int1
, Int2
]), True);
2947 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [Str1
]), True);
2953 procedure MC_SEND_Info(Password
: string);
2957 NetOut
.Write(Byte(NET_MSG_INFO
));
2958 NetOut
.Write(GAME_VERSION
);
2959 NetOut
.Write(Password
);
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_SERVICE
);
2970 procedure MC_SEND_Chat(Txt
: string; Mode
: Byte);
2972 NetOut
.Write(Byte(NET_MSG_CHAT
));
2976 g_Net_Client_Send(True, NET_CHAN_CHAT
);
2979 procedure MC_SEND_PlayerPos();
2984 WeaponAct
: Byte = 0;
2985 WeaponSelect
: Word = 0;
2988 if not gGameOn
then Exit
;
2989 if gPlayers
= nil then Exit
;
2990 if gPlayer1
= nil then Exit
;
2993 Predict
:= NetPredictSelf
; // and (not NetGotKeys);
2995 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2997 strafeDir
:= P1MoveButton
shr 4;
2998 P1MoveButton
:= P1MoveButton
and $0F;
3000 if gPlayerAction
[0, ACTION_MOVELEFT
] and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3002 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3004 else if (not gPlayerAction
[0, ACTION_MOVELEFT
]) and (not gPlayerAction
[0, ACTION_MOVERIGHT
]) then
3008 if gPlayerAction
[0, ACTION_STRAFE
] then
3010 // new strafe mechanics
3011 if (strafeDir
= 0) then
3012 strafeDir
:= P1MoveButton
; // start strafing
3013 // now set direction according to strafe (reversed)
3014 if (strafeDir
= 2) then
3015 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3016 else if (strafeDir
= 1) then
3017 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3021 strafeDir
:= 0; // not strafing anymore
3022 if (P1MoveButton
= 2) and gPlayerAction
[0, ACTION_MOVELEFT
] then
3023 gPlayer1
.SetDirection(TDirection
.D_LEFT
)
3024 else if (P1MoveButton
= 1) and gPlayerAction
[0, ACTION_MOVERIGHT
] then
3025 gPlayer1
.SetDirection(TDirection
.D_RIGHT
)
3026 else if P1MoveButton
<> 0 then
3027 gPlayer1
.SetDirection(TDirection(P1MoveButton
-1));
3030 gPlayer1
.ReleaseKeys
;
3031 if P1MoveButton
= 1 then
3033 kByte
:= kByte
or NET_KEY_LEFT
;
3034 if Predict
then gPlayer1
.PressKey(KEY_LEFT
, 10000);
3036 if P1MoveButton
= 2 then
3038 kByte
:= kByte
or NET_KEY_RIGHT
;
3039 if Predict
then gPlayer1
.PressKey(KEY_RIGHT
, 10000);
3041 if gPlayerAction
[0, ACTION_LOOKUP
] then
3043 kByte
:= kByte
or NET_KEY_UP
;
3044 gPlayer1
.PressKey(KEY_UP
, 10000);
3046 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
3048 kByte
:= kByte
or NET_KEY_DOWN
;
3049 gPlayer1
.PressKey(KEY_DOWN
, 10000);
3051 if gPlayerAction
[0, ACTION_JUMP
] then
3053 kByte
:= kByte
or NET_KEY_JUMP
;
3054 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3056 if gPlayerAction
[0, ACTION_ATTACK
] then kByte
:= kByte
or NET_KEY_FIRE
;
3057 if gPlayerAction
[0, ACTION_ACTIVATE
] then kByte
:= kByte
or NET_KEY_OPEN
;
3059 for i
:= WP_FACT
to WP_LACT
do
3061 if gWeaponAction
[0, i
] then
3063 WeaponAct
:= WeaponAct
or Byte(1 shl i
);
3064 gWeaponAction
[0, i
] := False
3068 for i
:= WP_FIRST
to WP_LAST
do
3070 if gSelectWeapon
[0, i
] then
3072 WeaponSelect
:= WeaponSelect
or Word(1 shl i
);
3073 gSelectWeapon
[0, i
] := False
3077 // fix movebutton state
3078 P1MoveButton
:= P1MoveButton
or (strafeDir
shl 4);
3081 kByte
:= NET_KEY_CHAT
;
3083 NetOut
.Write(Byte(NET_MSG_PLRPOS
));
3084 NetOut
.Write(gTime
);
3085 NetOut
.Write(kByte
);
3086 NetOut
.Write(Byte(gPlayer1
.Direction
));
3087 NetOut
.Write(WeaponAct
);
3088 NetOut
.Write(WeaponSelect
);
3089 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3090 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS
);
3092 //kBytePrev := kByte;
3093 //kDirPrev := gPlayer1.Direction;
3096 procedure MC_SEND_Vote(Start
: Boolean = False; Command
: string = 'a');
3098 NetOut
.Write(Byte(NET_MSG_VOTE_EVENT
));
3099 NetOut
.Write(Byte(Start
));
3100 NetOut
.Write(Command
);
3101 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3104 procedure MC_SEND_PlayerSettings();
3106 NetOut
.Write(Byte(NET_MSG_PLRSET
));
3107 NetOut
.Write(gPlayer1Settings
.Name
);
3108 NetOut
.Write(gPlayer1Settings
.Model
);
3109 NetOut
.Write(gPlayer1Settings
.Color
.R
);
3110 NetOut
.Write(gPlayer1Settings
.Color
.G
);
3111 NetOut
.Write(gPlayer1Settings
.Color
.B
);
3112 NetOut
.Write(gPlayer1Settings
.Team
);
3114 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3117 procedure MC_SEND_FullStateRequest();
3119 NetOut
.Write(Byte(NET_MSG_REQFST
));
3121 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3124 procedure MC_SEND_CheatRequest(Kind
: Byte);
3126 NetOut
.Write(Byte(NET_MSG_CHEAT
));
3129 g_Net_Client_Send(True, NET_CHAN_IMPORTANT
);
3131 procedure MC_SEND_RCONPassword(Password
: string);
3133 NetOut
.Write(Byte(NET_MSG_RCON_AUTH
));
3134 NetOut
.Write(Password
);
3136 g_Net_Client_Send(True, NET_CHAN_SERVICE
);
3138 procedure MC_SEND_RCONCommand(Cmd
: string);
3140 NetOut
.Write(Byte(NET_MSG_RCON_CMD
));
3143 g_Net_Client_Send(True, NET_CHAN_SERVICE
);