diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas
index 0a4facfdbdc7a0fe1c91cd362962b5fc7e3dadc1..01708c297bf82b1d108efa9c427d892e90a29c08 100644 (file)
--- a/src/game/g_netmsg.pas
+++ b/src/game/g_netmsg.pas
NET_MSG_FLAG = 107;
NET_MSG_REQFST = 108;
NET_MSG_GSET = 109;
NET_MSG_FLAG = 107;
NET_MSG_REQFST = 108;
NET_MSG_GSET = 109;
+ NET_MSG_FLAGPOS= 110;
NET_MSG_PLR = 111;
NET_MSG_PLRPOS = 112;
NET_MSG_PLR = 111;
NET_MSG_PLRPOS = 112;
NET_MSG_ISPAWN = 121;
NET_MSG_IDEL = 122;
NET_MSG_ISPAWN = 121;
NET_MSG_IDEL = 122;
+ NET_MSG_IPOS = 123;
NET_MSG_MSPAWN = 131;
NET_MSG_MPOS = 132;
NET_MSG_MSPAWN = 131;
NET_MSG_MPOS = 132;
NET_MSG_MSHOT = 134;
NET_MSG_MDEL = 135;
NET_MSG_MSHOT = 134;
NET_MSG_MDEL = 135;
- NET_MSG_PSTATE = 141;
- NET_MSG_PTEX = 142;
+ NET_MSG_PSTATE = 141;
+ NET_MSG_PTEX = 142;
NET_MSG_TSOUND = 151;
NET_MSG_TMUSIC = 152;
NET_MSG_TSOUND = 151;
NET_MSG_TMUSIC = 152;
// HOST MESSAGES
// HOST MESSAGES
+procedure MH_MalformedPacket(C: pTNetClient);
procedure MH_ProcessFirstSpawn (C: pTNetClient);
procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
procedure MH_ProcessFirstSpawn (C: pTNetClient);
procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
+procedure MH_SEND_FlagPos(Flag: Byte; ID: Integer = NET_EVERYONE);
procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
// PLAYER
procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
// PLAYER
procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
@@ -175,6 +179,7 @@ procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_
// ITEM
procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
// ITEM
procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
+procedure MH_SEND_ItemPos(IID: Word; ID: Integer = NET_EVERYONE);
// PANEL
procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
// PANEL
procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
procedure MC_RECV_CoopStats(var M: TMsg);
procedure MC_RECV_GameEvent(var M: TMsg);
procedure MC_RECV_FlagEvent(var M: TMsg);
procedure MC_RECV_CoopStats(var M: TMsg);
procedure MC_RECV_GameEvent(var M: TMsg);
procedure MC_RECV_FlagEvent(var M: TMsg);
+procedure MC_RECV_FlagPos(var M: TMsg);
procedure MC_RECV_GameSettings(var M: TMsg);
// PLAYER
function MC_RECV_PlayerCreate(var M: TMsg): Word;
procedure MC_RECV_GameSettings(var M: TMsg);
// PLAYER
function MC_RECV_PlayerCreate(var M: TMsg): Word;
// ITEM
procedure MC_RECV_ItemSpawn(var M: TMsg);
procedure MC_RECV_ItemDestroy(var M: TMsg);
// ITEM
procedure MC_RECV_ItemSpawn(var M: TMsg);
procedure MC_RECV_ItemDestroy(var M: TMsg);
+procedure MC_RECV_ItemPos(var M: TMsg);
// PANEL
procedure MC_RECV_PanelTexture(var M: TMsg);
procedure MC_RECV_PanelState(var M: TMsg);
// PANEL
procedure MC_RECV_PanelTexture(var M: TMsg);
procedure MC_RECV_PanelState(var M: TMsg);
// GAME
// GAME
+procedure MH_MalformedPacket(C: pTNetClient);
+begin
+ g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
+ _lc[I_NET_DISC_PROTOCOL]);
+ enet_peer_disconnect(C^.Peer, NET_DISC_PROTOCOL);
+end;
+
procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
var
Txt: string;
Mode: Byte;
PID: Word;
Pl: TPlayer;
procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
var
Txt: string;
Mode: Byte;
PID: Word;
Pl: TPlayer;
+ Err: Boolean;
begin
PID := C^.Player;
Pl := g_Player_Get(PID);
begin
PID := C^.Player;
Pl := g_Player_Get(PID);
- Txt := M.ReadString();
- Mode := M.ReadByte();
+ Err := False;
+ try
+ Txt := M.ReadString();
+ Mode := M.ReadByte();
+ except
+ Err := True;
+ end;
+
+ if Err then begin MH_MalformedPacket(C); Exit; end;
+
if (Mode = NET_CHAT_SYSTEM) then
Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
if (Mode = NET_CHAT_SYSTEM) then
Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
var
Ver, PName, Model, Pw: string;
R, G, B, T: Byte;
var
Ver, PName, Model, Pw: string;
R, G, B, T: Byte;
+ WeapSwitch: Byte;
+ TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
+ SwitchEmpty: Byte;
+ SkipF: Byte;
PID: Word;
Color: TRGB;
I: Integer;
PID: Word;
Color: TRGB;
I: Integer;
-begin
- Ver := M.ReadString();
- Pw := M.ReadString();
- PName := M.ReadString();
- Model := M.ReadString();
- R := M.ReadByte();
- G := M.ReadByte();
- B := M.ReadByte();
- T := M.ReadByte();
+ Err: Boolean;
+begin
+ Err := False;
+ try
+ Ver := M.ReadString();
+ Pw := M.ReadString();
+ PName := M.ReadString();
+ Model := M.ReadString();
+ R := M.ReadByte();
+ G := M.ReadByte();
+ B := M.ReadByte();
+ T := M.ReadByte();
+ WeapSwitch := M.ReadByte();
+ for I := WP_FIRST to WP_LAST + 1 do
+ TmpPrefArray[I] := M.ReadByte();
+ SwitchEmpty := M.ReadByte();
+ SkipF := M.ReadByte();
+ except
+ Err := True;
+ end;
+
+ if Err then begin MH_MalformedPacket(C); Exit; end;
if Ver <> GAME_VERSION then
begin
if Ver <> GAME_VERSION then
begin
Exit;
end;
Exit;
end;
+ if (C^.Player <> 0) then
+ begin
+ // already received info
+ g_Net_Penalize(C, 'client info spam');
+ Exit;
+ end;
+
Color.R := R;
Color.B := B;
Color.G := G;
Color.R := R;
Color.B := B;
Color.G := G;
with g_Player_Get(PID) do
begin
Name := PName;
with g_Player_Get(PID) do
begin
Name := PName;
+ WeapSwitchMode := WeapSwitch;
+ SetWeaponPrefs(TmpPrefArray);
+ SwitchToEmpty := SwitchEmpty;
+ SkipFist := SkipF;
Reset(True);
end;
C^.Player := PID;
C^.WaitForFirstSpawn := false;
Reset(True);
end;
C^.Player := PID;
C^.WaitForFirstSpawn := false;
+ C^.AuthTime := 0;
g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
kByte: Word;
Pl: TPlayer;
GT: LongWord;
kByte: Word;
Pl: TPlayer;
GT: LongWord;
+ Err: Boolean;
begin
Result := 0;
begin
Result := 0;
+ Err := False;
if not gGameOn then Exit;
if not gGameOn then Exit;
- GT := M.ReadLongWord();
+ try
+ GT := M.ReadLongWord();
+ except
+ Err := True;
+ end;
+
+ if Err then begin MH_MalformedPacket(C); Exit; end;
+
PID := C^.Player;
Pl := g_Player_Get(PID);
if Pl = nil then
PID := C^.Player;
Pl := g_Player_Get(PID);
if Pl = nil then
with Pl do
begin
NetTime := GT;
with Pl do
begin
NetTime := GT;
- kByte := M.ReadWord();
- Dir := M.ReadByte();
- WeaponAct := M.ReadByte();
- WeaponSelect := M.ReadWord();
+ try
+ kByte := M.ReadWord();
+ Dir := M.ReadByte();
+ WeaponAct := M.ReadByte();
+ WeaponSelect := M.ReadWord();
+ except
+ Err := True;
+ end;
+
+ if Err then begin MH_MalformedPacket(C); Exit; end;
+
//e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
if Direction <> TDirection(Dir) then
JustTeleported := False;
//e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
if Direction <> TDirection(Dir) then
JustTeleported := False;
var
CheatKind: Byte;
Pl: TPlayer;
var
CheatKind: Byte;
Pl: TPlayer;
+ Err: Boolean;
begin
begin
+ Err := False;
Pl := g_Player_Get(C^.Player);
if Pl = nil then Exit;
Pl := g_Player_Get(C^.Player);
if Pl = nil then Exit;
- CheatKind := M.ReadByte();
+ try
+ CheatKind := M.ReadByte();
+ except
+ Err := True;
+ end;
+
+ if Err then begin MH_MalformedPacket(C); Exit; end;
case CheatKind of
NET_CHEAT_SUICIDE:
case CheatKind of
NET_CHEAT_SUICIDE:
TmpModel: string;
TmpColor: TRGB;
TmpTeam: Byte;
TmpModel: string;
TmpColor: TRGB;
TmpTeam: Byte;
+ TmpWeapSwitch: Byte;
+ TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
+ TmpSwEmpty: Byte;
+ TmpSkipF: Byte;
+ I: Integer;
Pl: TPlayer;
Pl: TPlayer;
-begin
- TmpName := M.ReadString();
- TmpModel := M.ReadString();
- TmpColor.R := M.ReadByte();
- TmpColor.G := M.ReadByte();
- TmpColor.B := M.ReadByte();
- TmpTeam := M.ReadByte();
+ Err: Boolean;
+begin
+ Err := False;
+ try
+ TmpName := M.ReadString();
+ TmpModel := M.ReadString();
+ TmpColor.R := M.ReadByte();
+ TmpColor.G := M.ReadByte();
+ TmpColor.B := M.ReadByte();
+ TmpTeam := M.ReadByte();
+ TmpWeapSwitch := M.ReadByte();
+ for I := WP_FIRST to WP_LAST + 1 do
+ TmpPrefArray[I] := M.ReadByte();
+ TmpSwEmpty := M.ReadByte();
+ TmpSkipF := M.ReadByte();
+ except
+ Err := True;
+ end;
+
+ if Err then begin MH_MalformedPacket(C); Exit; end;
Pl := g_Player_Get(C^.Player);
if Pl = nil then Exit;
Pl := g_Player_Get(C^.Player);
if Pl = nil then Exit;
if TmpModel <> Pl.Model.Name then
Pl.SetModel(TmpModel);
if TmpModel <> Pl.Model.Name then
Pl.SetModel(TmpModel);
+ if (TmpWeapSwitch <> Pl.WeapSwitchMode) then
+ Pl.WeapSwitchMode := TmpWeapSwitch;
+
+ Pl.SetWeaponPrefs(TmpPrefArray);
+ if (TmpSwEmpty <> Pl.SwitchToEmpty) then
+ Pl.SwitchToEmpty := TmpSwEmpty;
+
+ if (TmpSkipF <> Pl.SkipFist) then
+ Pl.SkipFist := TmpSkipF;
+
MH_SEND_PlayerSettings(Pl.UID, TmpModel);
end;
MH_SEND_PlayerSettings(Pl.UID, TmpModel);
end;
procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
var
Pwd: string;
procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
var
Pwd: string;
+ Err: Boolean;
begin
begin
- Pwd := M.ReadString();
+ Err := False;
+ try
+ Pwd := M.ReadString();
+ except
+ Err := True;
+ end;
+ if Err then begin MH_MalformedPacket(C); Exit; end;
if not NetAllowRCON then Exit;
if Pwd = NetRCONPassword then
begin
if not NetAllowRCON then Exit;
if Pwd = NetRCONPassword then
begin
procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
var
Cmd: string;
procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
var
Cmd: string;
+ Err: Boolean;
begin
begin
- Cmd := M.ReadString();
+ Err := False;
+ try
+ Cmd := M.ReadString();
+ except
+ Err := True;
+ end;
+ if Err then begin MH_MalformedPacket(C); Exit; end;
if not NetAllowRCON then Exit;
if not C^.RCONAuth then
begin
if not NetAllowRCON then Exit;
if not C^.RCONAuth then
begin
Name, Command: string;
Need: Integer;
Pl: TPlayer;
Name, Command: string;
Need: Integer;
Pl: TPlayer;
-begin
- Start := M.ReadByte() <> 0;
- Command := M.ReadString();
+ Err: Boolean;
+begin
+ Err := False;
+ try
+ Start := M.ReadByte() <> 0;
+ Command := M.ReadString();
+ except
+ Err := True;
+ end;
+
+ if Err then begin MH_MalformedPacket(C); Exit; end;
Pl := g_Player_Get(C^.Player);
if Pl = nil then Exit;
Pl := g_Player_Get(C^.Player);
if Pl = nil then Exit;
NetOut.Write(gFlags[Flag].Obj.Y);
NetOut.Write(gFlags[Flag].Obj.Vel.X);
NetOut.Write(gFlags[Flag].Obj.Vel.Y);
NetOut.Write(gFlags[Flag].Obj.Y);
NetOut.Write(gFlags[Flag].Obj.Vel.X);
NetOut.Write(gFlags[Flag].Obj.Vel.Y);
+ NetOut.Write(Byte(gFlags[Flag].Direction));
g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
end;
g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
end;
+procedure MH_SEND_FlagPos(Flag: Byte; ID: Integer = NET_EVERYONE);
+begin
+ NetOut.Write(Byte(NET_MSG_FLAGPOS));
+ NetOut.Write(Flag);
+ NetOut.Write(gFlags[Flag].Obj.X);
+ NetOut.Write(gFlags[Flag].Obj.Y);
+ NetOut.Write(gFlags[Flag].Obj.Vel.X);
+ NetOut.Write(gFlags[Flag].Obj.Vel.Y);
+
+ g_Net_Host_Send(ID, False, NET_CHAN_IMPORTANT);
+end;
+
procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
begin
NetOut.Write(Byte(NET_MSG_GSET));
procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
begin
NetOut.Write(Byte(NET_MSG_GSET));
g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
end;
g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
end;
+procedure MH_SEND_ItemPos(IID: Word; ID: Integer = NET_EVERYONE);
+var
+ it: PItem;
+begin
+ it := g_Items_ByIdx(IID);
+
+ NetOut.Write(Byte(NET_MSG_IPOS));
+ NetOut.Write(IID);
+ NetOut.Write(it.Obj.X);
+ NetOut.Write(it.Obj.Y);
+ NetOut.Write(it.Obj.Vel.X);
+ NetOut.Write(it.Obj.Vel.Y);
+
+ g_Net_Host_Send(ID, False, NET_CHAN_LARGEDATA);
+end;
+
// PANEL
procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
// PANEL
procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
end;
end;
end;
end;
+procedure MC_RECV_FlagPos(var M: TMsg);
+var
+ Fl: Byte;
+begin
+ Fl := M.ReadByte();
+ if Fl = FLAG_NONE then Exit;
+ gFlags[Fl].Obj.X := M.ReadLongInt();
+ gFlags[Fl].Obj.Y := M.ReadLongInt();
+ gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
+ gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
+end;
+
procedure MC_RECV_FlagEvent(var M: TMsg);
var
PID: Word;
procedure MC_RECV_FlagEvent(var M: TMsg);
var
PID: Word;
gFlags[Fl].Obj.Y := M.ReadLongInt();
gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
gFlags[Fl].Obj.Y := M.ReadLongInt();
gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
+ gFlags[Fl].Direction := TDirection(M.ReadByte());
Pl := g_Player_Get(PID);
if (Pl = nil) and
Pl := g_Player_Get(PID);
if (Pl = nil) and
g_Items_Remove(ID);
end;
g_Items_Remove(ID);
end;
+procedure MC_RECV_ItemPos(var M: TMsg);
+var
+ ID: Word;
+ X, Y, VX, VY: Integer;
+ it: PItem;
+begin
+ if not gGameOn then Exit;
+
+ ID := M.ReadWord();
+ X := M.ReadLongInt();
+ Y := M.ReadLongInt();
+ VX := M.ReadLongInt();
+ VY := M.ReadLongInt();
+
+ if g_Items_ValidId(ID) then
+ begin
+ it := g_Items_ByIdx(ID);
+ it.Obj.X := X;
+ it.Obj.Y := Y;
+ it.Obj.Vel.X := VX;
+ it.Obj.Vel.Y := VY;
+ it.positionChanged();
+ end;
+end;
+
// PANEL
procedure MC_RECV_PanelTexture(var M: TMsg);
// PANEL
procedure MC_RECV_PanelTexture(var M: TMsg);
// CLIENT SEND
procedure MC_SEND_Info(Password: string);
// CLIENT SEND
procedure MC_SEND_Info(Password: string);
+var i: Integer;
begin
NetOut.Clear();
begin
NetOut.Clear();
NetOut.Write(gPlayer1Settings.Color.G);
NetOut.Write(gPlayer1Settings.Color.B);
NetOut.Write(gPlayer1Settings.Team);
NetOut.Write(gPlayer1Settings.Color.G);
NetOut.Write(gPlayer1Settings.Color.B);
NetOut.Write(gPlayer1Settings.Team);
+ NetOut.Write(gPlayer1Settings.WeaponSwitch);
+ for i := WP_FIRST to WP_LAST + 1 do
+ NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
+ NetOut.Write(gPlayer1Settings.SwitchToEmpty);
+ NetOut.Write(gPlayer1Settings.SkipFist);
g_Net_Client_Send(True, NET_CHAN_SERVICE);
end;
g_Net_Client_Send(True, NET_CHAN_SERVICE);
end;
end;
procedure MC_SEND_PlayerSettings();
end;
procedure MC_SEND_PlayerSettings();
+var i: Integer;
begin
NetOut.Write(Byte(NET_MSG_PLRSET));
NetOut.Write(gPlayer1Settings.Name);
begin
NetOut.Write(Byte(NET_MSG_PLRSET));
NetOut.Write(gPlayer1Settings.Name);
NetOut.Write(gPlayer1Settings.Color.G);
NetOut.Write(gPlayer1Settings.Color.B);
NetOut.Write(gPlayer1Settings.Team);
NetOut.Write(gPlayer1Settings.Color.G);
NetOut.Write(gPlayer1Settings.Color.B);
NetOut.Write(gPlayer1Settings.Team);
+ NetOut.Write(gPlayer1Settings.WeaponSwitch);
+ for i := WP_FIRST to WP_LAST + 1 do
+ NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
+ NetOut.Write(gPlayer1Settings.SwitchToEmpty);
+ NetOut.Write(gPlayer1Settings.SkipFist);
g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
end;
g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
end;