Minor networking fixes

- Don't spam the shit out of status updates (TODO: send update
immediately on drastic changes)
- Fixed some potential message misreading
- Readded homoglyph name comparison
This commit is contained in:
juanjp600
2017-12-21 16:00:04 -03:00
parent 40a46f96e2
commit c593fdb7c6
8 changed files with 56 additions and 37 deletions
@@ -145,6 +145,10 @@ namespace Barotrauma
float rotation = msg.ReadFloat(); float rotation = msg.ReadFloat();
ReadStatus(msg);
msg.ReadPadBits();
int index = 0; int index = 0;
if (GameMain.NetworkMember.Character == this) if (GameMain.NetworkMember.Character == this)
{ {
@@ -193,9 +197,6 @@ namespace Barotrauma
IsRemotePlayer = ownerID > 0; IsRemotePlayer = ownerID > 0;
} }
break; break;
case 2:
ReadStatus(msg);
break;
} }
break; break;
@@ -36,7 +36,7 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\x86\ReleaseLinux</OutputPath> <OutputPath>..\bin\ReleaseLinux</OutputPath>
<DefineConstants>TRACE;SERVER</DefineConstants> <DefineConstants>TRACE;SERVER</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
@@ -45,7 +45,7 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\x86\DebugLinux</OutputPath> <OutputPath>..\bin\DebugLinux</OutputPath>
<DefineConstants>TRACE;SERVER;DEBUG</DefineConstants> <DefineConstants>TRACE;SERVER;DEBUG</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
@@ -54,7 +54,7 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\x86\ReleaseWindows</OutputPath> <OutputPath>..\bin\ReleaseWindows</OutputPath>
<DefineConstants>TRACE;SERVER</DefineConstants> <DefineConstants>TRACE;SERVER</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
@@ -63,7 +63,7 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\x86\DebugWindows</OutputPath> <OutputPath>..\bin\DebugWindows</OutputPath>
<DefineConstants>TRACE;SERVER;DEBUG</DefineConstants> <DefineConstants>TRACE;SERVER;DEBUG</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
@@ -12,7 +12,7 @@
<WeldedSprite texture ="door.png" sourcerect="99,0,32,188" depth="0.0" origin="0.5,0.5"/> <WeldedSprite texture ="door.png" sourcerect="99,0,32,188" depth="0.0" origin="0.5,0.5"/>
<BrokenSprite texture ="door.png" sourcerect="133,0,58,208" depth="0.051" origin="0.5,0.0" scale="true"/> <BrokenSprite texture ="door.png" sourcerect="133,0,58,208" depth="0.051" origin="0.5,0.0" scale="true"/>
<sound file="door.ogg" type="OnUse" range="500.0"/> <sound file="door.ogg" type="OnUse" range="500.0"/>
<sound file="Content/Items/Tools/Crowbar.ogg" type="OnPicked" range="2000.0"/> <sound file="Content/Items/Tools/crowbar.ogg" type="OnPicked" range="2000.0"/>
</Door> </Door>
<AiTarget sightrange="500.0"/> <AiTarget sightrange="500.0"/>
@@ -159,4 +159,4 @@
<output name="proximity_sensor"/> <output name="proximity_sensor"/>
</ConnectionPanel> </ConnectionPanel>
</Item> </Item>
</Items> </Items>
@@ -344,18 +344,18 @@ namespace Barotrauma
if (GameMain.Client != null) return; if (GameMain.Client != null) return;
float newHealth = MathHelper.Clamp(value, minHealth, maxHealth); float newHealth = MathHelper.Clamp(value, minHealth, maxHealth);
if (newHealth == health) return; //if (newHealth == health) return;
health = newHealth; health = newHealth;
if (GameMain.Server != null) /*if (GameMain.Server != null)
{ {
if (Math.Abs(health - lastSentHealth) > (maxHealth - minHealth) / 255.0f || Math.Sign(health) != Math.Sign(lastSentHealth)) if (Math.Abs(health - lastSentHealth) > (maxHealth - minHealth) / 255.0f || Math.Sign(health) != Math.Sign(lastSentHealth))
{ {
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status }); GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });
lastSentHealth = health; lastSentHealth = health;
} }
} }*/
} }
} }
@@ -373,12 +373,12 @@ namespace Barotrauma
if (GameMain.Client != null) return; if (GameMain.Client != null) return;
float newBleeding = MathHelper.Clamp(value, 0.0f, 5.0f); float newBleeding = MathHelper.Clamp(value, 0.0f, 5.0f);
if (newBleeding == bleeding) return; //if (newBleeding == bleeding) return;
bleeding = newBleeding; bleeding = newBleeding;
if (GameMain.Server != null) /*if (GameMain.Server != null)
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status }); GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });*/
} }
} }
@@ -1534,11 +1534,11 @@ namespace Barotrauma
if (stunTimer > 0.0f) if (stunTimer > 0.0f)
{ {
stunTimer -= deltaTime; stunTimer -= deltaTime;
if (stunTimer < 0.0f && GameMain.Server != null) /*if (stunTimer < 0.0f && GameMain.Server != null)
{ {
//stun ended -> notify clients //stun ended -> notify clients
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status }); GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });
} } */
} }
//Skip health effects as critical health handles it differently //Skip health effects as critical health handles it differently
@@ -1568,8 +1568,8 @@ namespace Barotrauma
if (IsRagdolled) if (IsRagdolled)
{ {
if (AnimController is HumanoidAnimController) ((HumanoidAnimController)AnimController).Crouching = false; if (AnimController is HumanoidAnimController) ((HumanoidAnimController)AnimController).Crouching = false;
if(GameMain.Server != null) /*if(GameMain.Server != null)
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status }); GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });*/
AnimController.ResetPullJoints(); AnimController.ResetPullJoints();
selectedConstruction = null; selectedConstruction = null;
return; return;
@@ -1815,11 +1815,11 @@ namespace Barotrauma
if ((newStun <= stunTimer && !allowStunDecrease) || !MathUtils.IsValid(newStun)) return; if ((newStun <= stunTimer && !allowStunDecrease) || !MathUtils.IsValid(newStun)) return;
if (GameMain.Server != null && /*if (GameMain.Server != null &&
(Math.Sign(newStun) != Math.Sign(stunTimer) || Math.Abs(newStun - stunTimer) > 0.1f)) (Math.Sign(newStun) != Math.Sign(stunTimer) || Math.Abs(newStun - stunTimer) > 0.1f))
{ {
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status }); GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });
} }*/
if (Math.Sign(newStun) != Math.Sign(stunTimer)) AnimController.ResetPullJoints(); if (Math.Sign(newStun) != Math.Sign(stunTimer)) AnimController.ResetPullJoints();
@@ -1878,11 +1878,11 @@ namespace Barotrauma
return; return;
} }
if (GameMain.NetworkMember != null) /*if (GameMain.NetworkMember != null)
{ {
if (GameMain.Server != null) if (GameMain.Server != null)
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status }); GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });
} }*/
AnimController.Frozen = false; AnimController.Frozen = false;
@@ -332,6 +332,7 @@ namespace Barotrauma
inventory.ServerRead(type, msg, c); inventory.ServerRead(type, msg, c);
break; break;
case 1: case 1:
bool doingCPR = msg.ReadBoolean();
if (c.Character != this) if (c.Character != this)
{ {
#if DEBUG #if DEBUG
@@ -340,7 +341,6 @@ namespace Barotrauma
return; return;
} }
bool doingCPR = msg.ReadBoolean();
AnimController.Anim = doingCPR ? AnimController.Animation.CPR : AnimController.Animation.None; AnimController.Anim = doingCPR ? AnimController.Animation.CPR : AnimController.Animation.None;
break; break;
case 2: case 2:
@@ -358,7 +358,15 @@ namespace Barotrauma
} }
break; break;
case 3: case 3:
AnimController.GrabLimb = (LimbType)msg.ReadUInt16(); LimbType grabLimb = (LimbType)msg.ReadUInt16();
if (c.Character != this)
{
#if DEBUG
DebugConsole.Log("Received a character update message from a client who's not controlling the character");
#endif
return;
}
AnimController.GrabLimb = grabLimb;
break; break;
} }
break; break;
@@ -384,10 +392,6 @@ namespace Barotrauma
Client owner = ((Client)extraData[1]); Client owner = ((Client)extraData[1]);
msg.Write(owner == null ? (byte)0 : owner.ID); msg.Write(owner == null ? (byte)0 : owner.ID);
break; break;
case NetEntityEvent.Type.Status:
msg.WriteRangedInteger(0, 2, 2);
WriteStatus(msg);
break;
} }
msg.WritePadBits(); msg.WritePadBits();
} }
@@ -474,6 +478,8 @@ namespace Barotrauma
tempBuffer.Write(SimPosition.Y); tempBuffer.Write(SimPosition.Y);
tempBuffer.Write(AnimController.Collider.Rotation); tempBuffer.Write(AnimController.Collider.Rotation);
WriteStatus(tempBuffer);
tempBuffer.WritePadBits(); tempBuffer.WritePadBits();
msg.Write((byte)tempBuffer.LengthBytes); msg.Write((byte)tempBuffer.LengthBytes);
@@ -126,7 +126,7 @@ namespace Barotrauma.Networking
public static bool IsValidName(string name) public static bool IsValidName(string name)
{ {
if (name.Contains("\n") || name.Contains("\r\n")) return false; if (name.Contains("\n") || name.Contains("\r")) return false;
return (name.All(c => return (name.All(c =>
c != ';' && c != ';' &&
@@ -172,7 +172,7 @@ namespace Barotrauma.Networking
DebugConsole.NewMessage(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (invalid name)", Color.Red); DebugConsole.NewMessage(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (invalid name)", Color.Red);
return; return;
} }
if (clName.ToLower() == Name.ToLower()) if (Homoglyphs.Compare(clName.ToLower(),Name.ToLower()))
{ {
DisconnectUnauthClient(inc, unauthClient, "That name is taken."); DisconnectUnauthClient(inc, unauthClient, "That name is taken.");
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (name taken by the server)", ServerLog.MessageType.Error); Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (name taken by the server)", ServerLog.MessageType.Error);
+18 -6
View File
@@ -22,26 +22,38 @@
<ApplicationIcon>Icon.ico</ApplicationIcon> <ApplicationIcon>Icon.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseLinux|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseLinux|x86' ">
<Optimize>false</Optimize> <DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\ReleaseLinux</OutputPath> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\ReleaseLinux</OutputPath>
<DefineConstants>TRACE;LINUX;CLIENT</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugLinux|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugLinux|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\x86\DebugLinux</OutputPath> <OutputPath>..\bin\DebugLinux</OutputPath>
<DefineConstants>TRACE;LINUX;CLIENT;DEBUG</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseWindows|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseWindows|x86' ">
<Optimize>false</Optimize> <DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\ReleaseWindows</OutputPath> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\ReleaseWindows</OutputPath>
<DefineConstants>TRACE;WINDOWS;CLIENT</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWindows|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWindows|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\x86\DebugWindows</OutputPath> <OutputPath>..\bin\DebugWindows</OutputPath>
<DefineConstants>TRACE;WINDOWS;CLIENT;DEBUG</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
</PropertyGroup> </PropertyGroup>