Hacked clients can't send chat messages from other characters anymore
Also added sendername as userdata in chat messages, for now it's not used for anything but we'll probably find something where this is useful
This commit is contained in:
@@ -864,12 +864,12 @@ namespace Barotrauma
|
|||||||
return owner.isDead || owner.IsUnconscious || owner.Stun > 0.0f || owner.LockHands;
|
return owner.isDead || owner.IsUnconscious || owner.Stun > 0.0f || owner.LockHands;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inventory.Owner is Item)
|
if (inventory.Owner is Item)
|
||||||
{
|
{
|
||||||
var owner = (Item)inventory.Owner;
|
var owner = (Item)inventory.Owner;
|
||||||
if (!CanAccessItem(owner))
|
if (!CanAccessItem(owner))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -878,22 +878,22 @@ namespace Barotrauma
|
|||||||
public bool CanAccessItem(Item item)
|
public bool CanAccessItem(Item item)
|
||||||
{
|
{
|
||||||
if (item.ParentInventory != null)
|
if (item.ParentInventory != null)
|
||||||
{
|
{
|
||||||
return CanAccessInventory(item.ParentInventory);
|
return CanAccessInventory(item.ParentInventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
float maxDist = item.PickDistance * 1.2f;
|
float maxDist = item.PickDistance * 1.2f;
|
||||||
if (maxDist <= 0.01f)
|
if (maxDist <= 0.01f)
|
||||||
{
|
{
|
||||||
maxDist = 150.0f;
|
maxDist = 150.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Vector2.Distance(WorldPosition, item.WorldPosition) < maxDist ||
|
if (Vector2.Distance(WorldPosition, item.WorldPosition) < maxDist ||
|
||||||
item.IsInsideTrigger(WorldPosition))
|
item.IsInsideTrigger(WorldPosition))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return item.GetComponent<Items.Components.Ladder>() != null;
|
return item.GetComponent<Items.Components.Ladder>() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,21 +116,46 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public void WriteNetworkMessage(NetOutgoingMessage msg)
|
public void WriteNetworkMessage(NetOutgoingMessage msg)
|
||||||
{
|
{
|
||||||
msg.WriteRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length, (byte)Type);
|
msg.WriteRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length, (byte)Type);
|
||||||
msg.Write(Sender == null ? (ushort)0 : Sender.ID);
|
if (GameMain.Server != null)
|
||||||
msg.Write(SenderName);
|
{
|
||||||
|
msg.Write(Sender == null ? (ushort)0 : Sender.ID);
|
||||||
|
msg.Write(SenderName);
|
||||||
|
}
|
||||||
|
|
||||||
msg.Write(Text);
|
msg.Write(Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatMessage ReadNetworkMessage(NetBuffer msg)
|
public static ChatMessage ReadNetworkMessage(NetBuffer msg)
|
||||||
{
|
{
|
||||||
ChatMessageType type = (ChatMessageType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length);
|
ChatMessageType type = (ChatMessageType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length);
|
||||||
ushort senderId = msg.ReadUInt16();
|
string senderName="";
|
||||||
string senderName = msg.ReadString();
|
Character character = null;
|
||||||
|
if (GameMain.Server == null)
|
||||||
|
{
|
||||||
|
ushort senderId = msg.ReadUInt16();
|
||||||
|
character = Entity.FindEntityByID(senderId) as Character;
|
||||||
|
senderName = msg.ReadString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NetIncomingMessage inc = msg as NetIncomingMessage;
|
||||||
|
if (inc == null) return null;
|
||||||
|
Client sender = GameMain.Server.ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||||
|
if (sender == null) return null;
|
||||||
|
character = sender.Character;
|
||||||
|
if (character != null)
|
||||||
|
{
|
||||||
|
senderName = character.Name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
senderName = sender.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
string text = msg.ReadString();
|
string text = msg.ReadString();
|
||||||
|
|
||||||
return new ChatMessage(senderName, text, type, Entity.FindEntityByID(senderId) as Character);
|
return new ChatMessage(senderName, text, type, character);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,17 +93,17 @@ namespace Barotrauma.Networking
|
|||||||
name = name.Substring(0, 20);
|
name = name.Substring(0, 20);
|
||||||
}
|
}
|
||||||
string rName = "";
|
string rName = "";
|
||||||
for (int i=0;i<name.Length;i++)
|
for (int i=0;i<name.Length;i++)
|
||||||
{
|
{
|
||||||
if (name[i] < 32 || name[i] > 126)
|
if (name[i] < 32 || name[i] > 126)
|
||||||
{
|
{
|
||||||
//TODO: allow safe unicode characters, this is just to prevent players from taking names that look similar but aren't the same
|
//TODO: allow safe unicode characters, this is just to prevent players from taking names that look similar but aren't the same
|
||||||
rName += '?';
|
rName += '?';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rName += name[i];
|
rName += name[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rName;
|
return rName;
|
||||||
@@ -125,7 +125,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool HasPermission(ClientPermissions permission)
|
public bool HasPermission(ClientPermissions permission)
|
||||||
{
|
{
|
||||||
return false; //Permissions.HasFlag(permission);
|
return false; //Permissions.HasFlag(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1443,6 +1443,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
Client sender = connectedClients.Find(x => x.Connection == inc.SenderConnection);
|
Client sender = connectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||||
ChatMessage message = ChatMessage.ReadNetworkMessage(inc);
|
ChatMessage message = ChatMessage.ReadNetworkMessage(inc);
|
||||||
|
if (message == null) return;
|
||||||
|
|
||||||
List<Client> recipients = new List<Client>();
|
List<Client> recipients = new List<Client>();
|
||||||
|
|
||||||
@@ -1494,7 +1495,7 @@ namespace Barotrauma.Networking
|
|||||||
if (similarity > 5.0f)
|
if (similarity > 5.0f)
|
||||||
{
|
{
|
||||||
sender.ChatSpamCount++;
|
sender.ChatSpamCount++;
|
||||||
|
|
||||||
if (sender.ChatSpamCount > 3)
|
if (sender.ChatSpamCount > 3)
|
||||||
{
|
{
|
||||||
//kick for spamming too much
|
//kick for spamming too much
|
||||||
@@ -1633,10 +1634,10 @@ namespace Barotrauma.Networking
|
|||||||
headSpriteId = 0;
|
headSpriteId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.characterInfo != null)
|
if (sender.characterInfo != null)
|
||||||
{
|
{
|
||||||
//clients can't change their character's name once it's been set
|
//clients can't change their character's name once it's been set
|
||||||
name = sender.characterInfo.Name;
|
name = sender.characterInfo.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<JobPrefab> jobPreferences = new List<JobPrefab>();
|
List<JobPrefab> jobPreferences = new List<JobPrefab>();
|
||||||
|
|||||||
@@ -81,10 +81,10 @@ namespace Barotrauma.Networking
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConnectedClients.Count>=config.MaximumConnections)
|
if (ConnectedClients.Count>=config.MaximumConnections)
|
||||||
{
|
{
|
||||||
inc.SenderConnection.Disconnect("Server full");
|
inc.SenderConnection.Disconnect("Server full");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugConsole.NewMessage("New player has joined the server", Color.White);
|
DebugConsole.NewMessage("New player has joined the server", Color.White);
|
||||||
|
|||||||
@@ -309,6 +309,7 @@ namespace Barotrauma.Networking
|
|||||||
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f, message.Color,
|
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f, message.Color,
|
||||||
Alignment.Left, null, null, true);
|
Alignment.Left, null, null, true);
|
||||||
msg.Font = GUI.SmallFont;
|
msg.Font = GUI.SmallFont;
|
||||||
|
msg.UserData = message.SenderName;
|
||||||
|
|
||||||
msg.Padding = new Vector4(20.0f, 0, 0, 0);
|
msg.Padding = new Vector4(20.0f, 0, 0, 0);
|
||||||
|
|
||||||
|
|||||||
@@ -989,6 +989,7 @@ namespace Barotrauma
|
|||||||
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, message.Color,
|
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, message.Color,
|
||||||
Alignment.Left, GUI.Style, null, true);
|
Alignment.Left, GUI.Style, null, true);
|
||||||
msg.Font = GUI.SmallFont;
|
msg.Font = GUI.SmallFont;
|
||||||
|
msg.UserData = message.SenderName;
|
||||||
msg.CanBeFocused = false;
|
msg.CanBeFocused = false;
|
||||||
|
|
||||||
msg.Padding = new Vector4(20, 0, 0, 0);
|
msg.Padding = new Vector4(20, 0, 0, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user