Merge remote-tracking branch 'refs/remotes/origin/master'
Conflicts: Subsurface/Barotrauma.csproj Subsurface/Source/Characters/AI/EnemyAIController.cs Subsurface/Source/Characters/AICharacter.cs Subsurface/Source/Characters/Character.cs Subsurface/Source/Items/Components/DockingPort.cs Subsurface/Source/Items/Components/Door.cs Subsurface/Source/Items/Item.cs Subsurface/Source/Networking/GameClient.cs Subsurface/Source/Networking/GameServer.cs Subsurface/Source/Physics/PhysicsBody.cs
This commit is contained in:
@@ -115,21 +115,46 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void WriteNetworkMessage(NetOutgoingMessage msg)
|
||||
{
|
||||
msg.WriteRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length, (byte)Type);
|
||||
msg.Write(Sender == null ? (ushort)0 : Sender.ID);
|
||||
msg.Write(SenderName);
|
||||
msg.WriteRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length, (byte)Type);
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
msg.Write(Sender == null ? (ushort)0 : Sender.ID);
|
||||
msg.Write(SenderName);
|
||||
}
|
||||
|
||||
msg.Write(Text);
|
||||
}
|
||||
|
||||
public static ChatMessage ReadNetworkMessage(NetBuffer msg)
|
||||
{
|
||||
ChatMessageType type = (ChatMessageType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length);
|
||||
ushort senderId = msg.ReadUInt16();
|
||||
string senderName = msg.ReadString();
|
||||
ChatMessageType type = (ChatMessageType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length);
|
||||
string senderName="";
|
||||
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();
|
||||
|
||||
return new ChatMessage(senderName, text, type, Entity.FindEntityByID(senderId) as Character);
|
||||
return new ChatMessage(senderName, text, type, character);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace Barotrauma.Networking
|
||||
public string version;
|
||||
public bool inGame;
|
||||
|
||||
public List<string> ChatMessages = new List<string>();
|
||||
public float ChatSpamSpeed;
|
||||
public float ChatSpamTimer;
|
||||
public int ChatSpamCount;
|
||||
|
||||
private List<Client> kickVoters;
|
||||
|
||||
public bool ReadyToStart;
|
||||
@@ -84,8 +89,21 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
name = name.Substring(0, 20);
|
||||
}
|
||||
string rName = "";
|
||||
for (int i=0;i<name.Length;i++)
|
||||
{
|
||||
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
|
||||
rName += '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
rName += name[i];
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
return rName;
|
||||
}
|
||||
|
||||
public void SetPermissions(ClientPermissions permissions)
|
||||
@@ -105,7 +123,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public bool HasPermission(ClientPermissions permission)
|
||||
{
|
||||
return Permissions.HasFlag(permission);
|
||||
return false; //Permissions.HasFlag(permission);
|
||||
}
|
||||
|
||||
public T GetVote<T>(VoteType voteType)
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using FarseerPhysics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Barotrauma.Items.Components;
|
||||
using System.ComponentModel;
|
||||
|
||||
@@ -165,7 +166,12 @@ namespace Barotrauma.Networking
|
||||
reconnectBox.Buttons[0].OnClicked += reconnectBox.Close;
|
||||
}
|
||||
|
||||
CoroutineManager.StartCoroutine(WaitForStartingInfo(password));
|
||||
String sendPw = "";
|
||||
if (password.Length>0)
|
||||
{
|
||||
sendPw = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password)));
|
||||
}
|
||||
CoroutineManager.StartCoroutine(WaitForStartingInfo(sendPw));
|
||||
|
||||
// Start the timer
|
||||
//update.Start();
|
||||
@@ -408,43 +414,7 @@ namespace Barotrauma.Networking
|
||||
byte characterCount = inc.ReadByte();
|
||||
for (int i = 0; i < characterCount; i++)
|
||||
{
|
||||
bool isAiCharacter = inc.ReadBoolean();
|
||||
ushort id = inc.ReadUInt16();
|
||||
|
||||
if (isAiCharacter)
|
||||
{
|
||||
string configPath = inc.ReadString();
|
||||
|
||||
Vector2 position = new Vector2(inc.ReadFloat(), inc.ReadFloat());
|
||||
|
||||
var existingEntity = Entity.FindEntityByID(id);
|
||||
if (existingEntity is AICharacter && existingEntity.ID == id)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var character = Character.Create(configPath, position, null, true);
|
||||
if (character != null) character.ID = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool hasOwner = inc.ReadBoolean();
|
||||
int ownerId = -1;
|
||||
if (hasOwner)
|
||||
{
|
||||
ownerId = inc.ReadByte();
|
||||
}
|
||||
|
||||
Character newCharacter = ReadCharacterData(inc, ownerId == myID);
|
||||
|
||||
if (ownerId != myID)
|
||||
{
|
||||
var characterOwner = otherClients.Find(c => c.ID == ownerId);
|
||||
if (characterOwner != null) characterOwner.Character = newCharacter;
|
||||
}
|
||||
|
||||
crew.Add(newCharacter);
|
||||
}
|
||||
ReadCharacterData(inc);
|
||||
}
|
||||
|
||||
gameStarted = true;
|
||||
@@ -509,7 +479,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public bool HasPermission(ClientPermissions permission)
|
||||
{
|
||||
return permissions.HasFlag(permission);
|
||||
return false;// permissions.HasFlag(permission);
|
||||
}
|
||||
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
@@ -547,15 +517,23 @@ namespace Barotrauma.Networking
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black * 0.7f, true);
|
||||
spriteBatch.DrawString(GUI.Font, "Network statistics:", new Vector2(x + 10, y + 10), Color.White);
|
||||
|
||||
spriteBatch.DrawString(GUI.Font, "Ping: " + (int)(client.ServerConnection.AverageRoundtripTime * 1000.0f) + " ms", new Vector2(x + 10, y + 25), Color.White);
|
||||
if (client.ServerConnection != null)
|
||||
{
|
||||
spriteBatch.DrawString(GUI.Font, "Ping: " + (int)(client.ServerConnection.AverageRoundtripTime * 1000.0f) + " ms", new Vector2(x + 10, y + 25), Color.White);
|
||||
|
||||
y += 15;
|
||||
y += 15;
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Received bytes: " + client.Statistics.ReceivedBytes, new Vector2(x + 10, y + 45), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Received packets: " + client.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Received bytes: " + client.Statistics.ReceivedBytes, new Vector2(x + 10, y + 45), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Received packets: " + client.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White);
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Sent bytes: " + client.Statistics.SentBytes, new Vector2(x + 10, y + 75), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Sent packets: " + client.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White);
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteBatch.DrawString(GUI.Font, "Disconnected", new Vector2(x + 10, y + 25), Color.White);
|
||||
}
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Sent bytes: " + client.Statistics.SentBytes, new Vector2(x + 10, y + 75), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Sent packets: " + client.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White);
|
||||
|
||||
}
|
||||
|
||||
@@ -609,25 +587,6 @@ namespace Barotrauma.Networking
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ReadCharacterSpawnMessage(NetIncomingMessage message)
|
||||
{
|
||||
string configPath = message.ReadString();
|
||||
|
||||
if (configPath != Character.HumanConfigFile)
|
||||
{
|
||||
ushort id = message.ReadUInt16();
|
||||
|
||||
Vector2 position = new Vector2(message.ReadFloat(), message.ReadFloat());
|
||||
|
||||
var character = Character.Create(configPath, position, null, true);
|
||||
if (character != null) character.ID = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadCharacterData(message, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestFile(string file, FileTransferMessageType fileType)
|
||||
{
|
||||
if (fileStreamReceiver!=null)
|
||||
@@ -812,35 +771,77 @@ namespace Barotrauma.Networking
|
||||
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||
}
|
||||
|
||||
public Character ReadCharacterData(NetIncomingMessage inc, bool isMyCharacter, bool hasAi = false)
|
||||
public Character ReadCharacterData(NetIncomingMessage inc)
|
||||
{
|
||||
string newName = inc.ReadString();
|
||||
ushort ID = inc.ReadUInt16();
|
||||
bool isFemale = inc.ReadBoolean();
|
||||
bool noInfo = inc.ReadBoolean();
|
||||
ushort id = inc.ReadUInt16();
|
||||
string configPath = inc.ReadString();
|
||||
|
||||
int headSpriteID = inc.ReadByte();
|
||||
|
||||
Vector2 position = new Vector2(inc.ReadFloat(), inc.ReadFloat());
|
||||
|
||||
bool enabled = inc.ReadBoolean();
|
||||
|
||||
string jobName = inc.ReadString();
|
||||
JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name == jobName);
|
||||
Character character = null;
|
||||
|
||||
CharacterInfo ch = new CharacterInfo(Character.HumanConfigFile, newName, isFemale ? Gender.Female : Gender.Male, jobPrefab);
|
||||
ch.HeadSpriteId = headSpriteID;
|
||||
|
||||
Character character = Character.Create(ch, position, !isMyCharacter, hasAi);
|
||||
GameMain.GameSession.CrewManager.characters.Add(character);
|
||||
|
||||
character.ID = ID;
|
||||
|
||||
if (isMyCharacter)
|
||||
if (noInfo)
|
||||
{
|
||||
myCharacter = character;
|
||||
Character.Controlled = character;
|
||||
GameMain.LightManager.LosEnabled = true;
|
||||
var existingEntity = Entity.FindEntityByID(id);
|
||||
if (existingEntity is AICharacter && existingEntity.ID == id)
|
||||
{
|
||||
return (Character)existingEntity;
|
||||
}
|
||||
|
||||
if (endVoteTickBox != null) endVoteTickBox.Visible = Voting.AllowEndVoting;
|
||||
character = Character.Create(configPath, position, null, true);
|
||||
character.ID = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool hasOwner = inc.ReadBoolean();
|
||||
int ownerId = -1;
|
||||
if (hasOwner)
|
||||
{
|
||||
ownerId = inc.ReadByte();
|
||||
}
|
||||
|
||||
string newName = inc.ReadString();
|
||||
|
||||
bool hasAi = inc.ReadBoolean();
|
||||
bool isFemale = inc.ReadBoolean();
|
||||
int headSpriteID = inc.ReadByte();
|
||||
string jobName = inc.ReadString();
|
||||
|
||||
JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name == jobName);
|
||||
|
||||
CharacterInfo ch = new CharacterInfo(configPath, newName, isFemale ? Gender.Female : Gender.Male, jobPrefab);
|
||||
ch.HeadSpriteId = headSpriteID;
|
||||
|
||||
character = Character.Create(configPath, position, ch, ownerId != myID, hasAi);
|
||||
character.ID = id;
|
||||
|
||||
if (configPath == Character.HumanConfigFile)
|
||||
{
|
||||
GameMain.GameSession.CrewManager.characters.Add(character);
|
||||
}
|
||||
|
||||
Item.Spawner.ReadNetworkData(inc);
|
||||
|
||||
if (ownerId == myID)
|
||||
{
|
||||
myCharacter = character;
|
||||
Character.Controlled = character;
|
||||
GameMain.LightManager.LosEnabled = true;
|
||||
|
||||
if (endVoteTickBox != null) endVoteTickBox.Visible = Voting.AllowEndVoting;
|
||||
}
|
||||
else
|
||||
{
|
||||
var characterOwner = otherClients.Find(c => c.ID == ownerId);
|
||||
if (characterOwner != null) characterOwner.Character = character;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
character.Enabled = enabled;
|
||||
|
||||
return character;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using RestSharp;
|
||||
@@ -54,7 +55,11 @@ namespace Barotrauma.Networking
|
||||
name = name.Replace(";", "");
|
||||
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
this.password = "";
|
||||
if (password.Length>0)
|
||||
{
|
||||
this.password = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password)));
|
||||
}
|
||||
|
||||
config = new NetPeerConfiguration("barotrauma");
|
||||
|
||||
@@ -104,6 +109,10 @@ namespace Barotrauma.Networking
|
||||
return true;
|
||||
};
|
||||
|
||||
GUIButton settingsButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170 - 170 - 170, 20, 150, 20), "Settings", Alignment.TopLeft, GUI.Style, inGameHUD);
|
||||
settingsButton.OnClicked = ToggleSettingsFrame;
|
||||
settingsButton.UserData = "settingsButton";
|
||||
|
||||
banList = new BanList();
|
||||
|
||||
LoadSettings();
|
||||
@@ -342,7 +351,13 @@ namespace Barotrauma.Networking
|
||||
|
||||
foreach (Client c in connectedClients)
|
||||
{
|
||||
if (c.FileStreamSender != null) UpdateFileTransfer(c, deltaTime);
|
||||
if (c.FileStreamSender != null) UpdateFileTransfer(c, deltaTime);
|
||||
|
||||
c.ReliableChannel.Update(deltaTime);
|
||||
|
||||
//slowly reset spam timers
|
||||
c.ChatSpamTimer = Math.Max(0.0f, c.ChatSpamTimer - deltaTime);
|
||||
c.ChatSpamSpeed = Math.Max(0.0f, c.ChatSpamSpeed - deltaTime);
|
||||
}
|
||||
|
||||
NetIncomingMessage inc = null;
|
||||
@@ -974,35 +989,7 @@ namespace Barotrauma.Networking
|
||||
msg.Write((byte)characters.Count);
|
||||
foreach (Character c in characters)
|
||||
{
|
||||
msg.Write(c is AICharacter);
|
||||
msg.Write(c.ID);
|
||||
|
||||
if (c is AICharacter)
|
||||
{
|
||||
msg.Write(c.ConfigPath);
|
||||
|
||||
msg.Write(c.Position.X);
|
||||
msg.Write(c.Position.Y);
|
||||
}
|
||||
else
|
||||
{
|
||||
Client client = connectedClients.Find(cl => cl.Character == c);
|
||||
if (client != null)
|
||||
{
|
||||
msg.Write(true);
|
||||
msg.Write(client.ID);
|
||||
}
|
||||
else if (myCharacter == c)
|
||||
{
|
||||
msg.Write(true);
|
||||
msg.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write(false);
|
||||
}
|
||||
WriteCharacterData(msg, c.Name, c);
|
||||
}
|
||||
WriteCharacterData(msg, c.Name, c);
|
||||
}
|
||||
|
||||
return msg;
|
||||
@@ -1435,12 +1422,15 @@ namespace Barotrauma.Networking
|
||||
|
||||
private void ReadChatMessage(NetIncomingMessage inc)
|
||||
{
|
||||
Client sender = connectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||
ChatMessage message = ChatMessage.ReadNetworkMessage(inc);
|
||||
if (message == null) return;
|
||||
|
||||
List<Client> recipients = new List<Client>();
|
||||
|
||||
foreach (Client c in connectedClients)
|
||||
{
|
||||
if (!sender.inGame && c.inGame) continue; //people in lobby can't talk to people ingame
|
||||
switch (message.Type)
|
||||
{
|
||||
case ChatMessageType.Dead:
|
||||
@@ -1462,7 +1452,71 @@ namespace Barotrauma.Networking
|
||||
recipients.Add(c);
|
||||
}
|
||||
|
||||
AddChatMessage(message);
|
||||
//SPAM FILTER
|
||||
if (sender.ChatSpamTimer > 0.0f)
|
||||
{
|
||||
//player has already been spamming, stop again
|
||||
ChatMessage denyMsg = ChatMessage.Create("", "You have been blocked by the spam filter. Try again after 10 seconds.", ChatMessageType.Server, null);
|
||||
sender.ChatSpamTimer = 10.0f;
|
||||
SendChatMessage(denyMsg, sender);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
float similarity = 0;
|
||||
similarity += sender.ChatSpamSpeed * 0.05f; //the faster messages are being sent, the faster the filter will block
|
||||
for (int i = 0; i < sender.ChatMessages.Count; i++)
|
||||
{
|
||||
float closeFactor = 1.0f / (20.0f - i);
|
||||
|
||||
int levenshteinDist = ToolBox.LevenshteinDistance(message.Text, sender.ChatMessages[i]);
|
||||
similarity += Math.Max((message.Text.Length - levenshteinDist) / message.Text.Length * closeFactor, 0.0f);
|
||||
}
|
||||
|
||||
if (similarity > 5.0f)
|
||||
{
|
||||
sender.ChatSpamCount++;
|
||||
|
||||
if (sender.ChatSpamCount > 3)
|
||||
{
|
||||
//kick for spamming too much
|
||||
KickClient(sender, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatMessage denyMsg = ChatMessage.Create("", "You have been blocked by the spam filter. Try again after 10 seconds.", ChatMessageType.Server, null);
|
||||
sender.ChatSpamTimer = 10.0f;
|
||||
SendChatMessage(denyMsg, sender);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sender.ChatMessages.Add(message.Text);
|
||||
if (sender.ChatMessages.Count > 20)
|
||||
{
|
||||
sender.ChatMessages.RemoveAt(0);
|
||||
}
|
||||
|
||||
if (sender.inGame || (Screen.Selected == GameMain.NetLobbyScreen))
|
||||
{
|
||||
AddChatMessage(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameServer.Log(message.TextWithSender, message.Color);
|
||||
}
|
||||
sender.ChatSpamSpeed += 5.0f;
|
||||
|
||||
foreach (Client c in recipients)
|
||||
{
|
||||
ReliableMessage msg = c.ReliableChannel.CreateMessage();
|
||||
msg.InnerMessage.Write((byte)PacketTypes.Chatmessage);
|
||||
|
||||
message.WriteNetworkMessage(msg.InnerMessage);
|
||||
|
||||
c.ReliableChannel.SendMessage(msg, c.Connection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void SendChatMessage(string message, ChatMessageType? type = null)
|
||||
@@ -1521,6 +1575,16 @@ namespace Barotrauma.Networking
|
||||
SendChatMessage(chatMessage, recipients);
|
||||
}
|
||||
|
||||
public void SendChatMessage(ChatMessage chatMessage, Client recipient)
|
||||
{
|
||||
ReliableMessage msg = recipient.ReliableChannel.CreateMessage();
|
||||
msg.InnerMessage.Write((byte)PacketTypes.Chatmessage);
|
||||
|
||||
chatMessage.WriteNetworkMessage(msg.InnerMessage);
|
||||
|
||||
recipient.ReliableChannel.SendMessage(msg, recipient.Connection);
|
||||
}
|
||||
|
||||
public void SendChatMessage(ChatMessage chatMessage, List<Client> recipients)
|
||||
{
|
||||
|
||||
@@ -1528,6 +1592,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
private void ReadCharacterData(NetIncomingMessage message)
|
||||
{
|
||||
Client sender = connectedClients.Find(c => c.Connection == message.SenderConnection);
|
||||
if (sender == null) return;
|
||||
|
||||
string name = "";
|
||||
Gender gender = Gender.Male;
|
||||
int headSpriteId = 0;
|
||||
@@ -1545,6 +1612,11 @@ namespace Barotrauma.Networking
|
||||
headSpriteId = 0;
|
||||
}
|
||||
|
||||
if (sender.characterInfo != null)
|
||||
{
|
||||
//clients can't change their character's name once it's been set
|
||||
name = sender.characterInfo.Name;
|
||||
}
|
||||
|
||||
List<JobPrefab> jobPreferences = new List<JobPrefab>();
|
||||
int count = message.ReadByte();
|
||||
@@ -1555,51 +1627,60 @@ namespace Barotrauma.Networking
|
||||
if (jobPrefab != null) jobPreferences.Add(jobPrefab);
|
||||
}
|
||||
|
||||
foreach (Client c in connectedClients)
|
||||
{
|
||||
if (c.Connection != message.SenderConnection) continue;
|
||||
|
||||
c.characterInfo = new CharacterInfo(Character.HumanConfigFile, name, gender);
|
||||
c.characterInfo.HeadSpriteId = headSpriteId;
|
||||
c.jobPreferences = jobPreferences;
|
||||
break;
|
||||
}
|
||||
sender.characterInfo = new CharacterInfo(Character.HumanConfigFile, name, gender);
|
||||
sender.characterInfo.HeadSpriteId = headSpriteId;
|
||||
sender.jobPreferences = jobPreferences;
|
||||
}
|
||||
|
||||
public void WriteCharacterData(NetOutgoingMessage message, string name, Character character)
|
||||
public void WriteCharacterData(NetOutgoingMessage msg, string name, Character c)
|
||||
{
|
||||
message.Write(name);
|
||||
message.Write(character.ID);
|
||||
message.Write(character.Info.Gender == Gender.Female);
|
||||
msg.Write(c.Info == null);
|
||||
msg.Write(c.ID);
|
||||
msg.Write(c.ConfigPath);
|
||||
|
||||
message.Write((byte)character.Info.HeadSpriteId);
|
||||
msg.Write(c.WorldPosition.X);
|
||||
msg.Write(c.WorldPosition.Y);
|
||||
|
||||
message.Write(character.WorldPosition.X);
|
||||
message.Write(character.WorldPosition.Y);
|
||||
|
||||
message.Write(character.Info.Job.Name);
|
||||
msg.Write(c.Enabled);
|
||||
|
||||
if (c.Info != null)
|
||||
{
|
||||
Client client = connectedClients.Find(cl => cl.Character == c);
|
||||
if (client != null)
|
||||
{
|
||||
msg.Write(true);
|
||||
msg.Write(client.ID);
|
||||
}
|
||||
else if (myCharacter == c)
|
||||
{
|
||||
msg.Write(true);
|
||||
msg.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write(false);
|
||||
}
|
||||
|
||||
msg.Write(name);
|
||||
|
||||
msg.Write(c is AICharacter);
|
||||
msg.Write(c.Info.Gender == Gender.Female);
|
||||
msg.Write((byte)c.Info.HeadSpriteId);
|
||||
msg.Write(c.Info.Job == null ? "" : c.Info.Job.Name);
|
||||
|
||||
Item.Spawner.FillNetworkData(msg, c.SpawnItems);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendCharacterSpawnMessage(Character character, List<NetConnection> recipients = null)
|
||||
{
|
||||
if (recipients != null && !recipients.Any()) return;
|
||||
|
||||
NetOutgoingMessage message = server.CreateMessage();
|
||||
message.Write((byte)PacketTypes.NewCharacter);
|
||||
|
||||
message.Write(character.ConfigPath);
|
||||
|
||||
if (character.ConfigPath == Character.HumanConfigFile)
|
||||
{
|
||||
WriteCharacterData(message, character.Name, character);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.Write(character.ID);
|
||||
|
||||
message.Write(character.Position.X);
|
||||
message.Write(character.Position.Y);
|
||||
}
|
||||
|
||||
WriteCharacterData(message, character.Name, character);
|
||||
|
||||
SendMessage(message, NetDeliveryMethod.ReliableUnordered, recipients);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,11 +61,14 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
unauthenticatedClients.Remove(unauthenticatedClient);
|
||||
|
||||
NetEncryption algo = new NetXtea(server, password);
|
||||
string saltedPw = password;
|
||||
saltedPw = saltedPw + Convert.ToString(unauthenticatedClient.Nonce);
|
||||
saltedPw = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(saltedPw)));
|
||||
NetEncryption algo = new NetXtea(server, saltedPw);
|
||||
inc.Decrypt(algo);
|
||||
|
||||
int nonce = inc.ReadInt32();
|
||||
if (nonce != unauthenticatedClient.Nonce)
|
||||
string rdPw = inc.ReadString();
|
||||
if (rdPw != saltedPw)
|
||||
{
|
||||
inc.SenderConnection.Disconnect("Wrong password!");
|
||||
return;
|
||||
@@ -74,6 +77,13 @@ namespace Barotrauma.Networking
|
||||
else
|
||||
{
|
||||
inc.SenderConnection.Disconnect("Authentication failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ConnectedClients.Count>=config.MaximumConnections)
|
||||
{
|
||||
inc.SenderConnection.Disconnect("Server full");
|
||||
return;
|
||||
}
|
||||
|
||||
DebugConsole.NewMessage("New player has joined the server", Color.White);
|
||||
|
||||
@@ -646,5 +646,38 @@ namespace Barotrauma.Networking
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ManagePlayersFrame(GUIFrame infoFrame)
|
||||
{
|
||||
GUIListBox cList = new GUIListBox(new Rectangle(0, 0, 0, 300), Color.White * 0.7f, GUI.Style, infoFrame);
|
||||
cList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
//crewList.OnSelected = SelectCrewCharacter;
|
||||
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, cList);
|
||||
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
frame.Color = (c.inGame && c.Character!=null && !c.Character.IsDead) ? Color.Gold * 0.2f : Color.Transparent;
|
||||
frame.HoverColor = Color.LightGray * 0.5f;
|
||||
frame.SelectedColor = Color.Gold * 0.5f;
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(40, 0, 0, 25),
|
||||
c.name + " (" + c.Connection.RemoteEndPoint.Address.ToString() + ")",
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.Left, Alignment.Left,
|
||||
null, frame);
|
||||
|
||||
var banButton = new GUIButton(new Rectangle(-120, 0, 100, 20), "Ban", Alignment.Right | Alignment.CenterY, GUI.Style, frame);
|
||||
banButton.UserData = c.name;
|
||||
banButton.OnClicked += GameMain.NetLobbyScreen.BanPlayer;
|
||||
|
||||
var kickButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Kick", Alignment.Right | Alignment.CenterY, GUI.Style, frame);
|
||||
kickButton.UserData = c.name;
|
||||
kickButton.OnClicked += GameMain.NetLobbyScreen.KickPlayer;
|
||||
|
||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,6 +264,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void AddChatMessage(ChatMessage message)
|
||||
{
|
||||
|
||||
if (message.Type == ChatMessageType.Radio &&
|
||||
Character.Controlled != null &&
|
||||
message.Sender != null && message.Sender != myCharacter)
|
||||
@@ -278,6 +279,8 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
GameServer.Log(message.TextWithSender, message.Color);
|
||||
|
||||
string displayedText = message.Text;
|
||||
|
||||
if (message.Sender != null)
|
||||
@@ -293,8 +296,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
GameMain.NetLobbyScreen.NewChatMessage(message);
|
||||
|
||||
GameServer.Log(message.Text, message.Color);
|
||||
|
||||
while (chatBox.CountChildren > 20)
|
||||
{
|
||||
chatBox.RemoveChild(chatBox.children[1]);
|
||||
@@ -304,11 +305,12 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
displayedText = message.SenderName + ": " + displayedText;
|
||||
}
|
||||
|
||||
|
||||
GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20), displayedText,
|
||||
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f, message.Color,
|
||||
Alignment.Left, null, null, true);
|
||||
msg.Font = GUI.SmallFont;
|
||||
msg.UserData = message.SenderName;
|
||||
|
||||
msg.Padding = new Vector4(20.0f, 0, 0, 0);
|
||||
|
||||
@@ -340,15 +342,12 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (gameStarted && Screen.Selected == GameMain.GameScreen)
|
||||
{
|
||||
chatMsgBox.Visible = Character.Controlled == null ||
|
||||
(!Character.Controlled.IsUnconscious && Character.Controlled.Stun <= 0.0f);
|
||||
chatMsgBox.Visible = Character.Controlled == null || Character.Controlled.CanSpeak;
|
||||
|
||||
inGameHUD.Update(deltaTime);
|
||||
|
||||
GameMain.GameSession.CrewManager.Update(deltaTime);
|
||||
|
||||
//if (crewFrameOpen) crewFrame.Update(deltaTime);
|
||||
|
||||
|
||||
if (Character.Controlled == null || Character.Controlled.IsDead)
|
||||
{
|
||||
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
|
||||
|
||||
@@ -532,7 +532,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
byte clientId = inc.ReadByte();
|
||||
|
||||
var character = client.ReadCharacterData(inc, clientId == client.ID);
|
||||
var character = client.ReadCharacterData(inc);
|
||||
}
|
||||
|
||||
if (state != newState)
|
||||
|
||||
@@ -98,10 +98,10 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
float prevSize = listBox.BarSize;
|
||||
|
||||
var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), line.Text, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, null, true, GUI.SmallFont);
|
||||
var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 0), line.Text, GUI.Style, Alignment.TopLeft, Alignment.TopLeft, listBox, true, GUI.SmallFont);
|
||||
textBlock.Rect = new Rectangle(textBlock.Rect.X, textBlock.Rect.Y, textBlock.Rect.Width, Math.Max(13, textBlock.Rect.Height));
|
||||
|
||||
listBox.AddChild(textBlock);
|
||||
//listBox.AddChild(textBlock);
|
||||
|
||||
textBlock.TextColor = line.Color;
|
||||
textBlock.CanBeFocused = false;
|
||||
|
||||
Reference in New Issue
Block a user