Renaming fields in the Client class for consistency
This commit is contained in:
@@ -91,6 +91,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
fileReceiver = new FileReceiver();
|
fileReceiver = new FileReceiver();
|
||||||
fileReceiver.OnFinished += OnFileReceived;
|
fileReceiver.OnFinished += OnFileReceived;
|
||||||
|
fileReceiver.OnTransferFailed += OnTransferFailed;
|
||||||
|
|
||||||
characterInfo = new CharacterInfo(Character.HumanConfigFile, name,Gender.None,null);
|
characterInfo = new CharacterInfo(Character.HumanConfigFile, name,Gender.None,null);
|
||||||
characterInfo.Job = null;
|
characterInfo.Job = null;
|
||||||
@@ -765,7 +766,7 @@ namespace Barotrauma.Networking
|
|||||||
myCharacter = null;
|
myCharacter = null;
|
||||||
foreach (Client c in otherClients)
|
foreach (Client c in otherClients)
|
||||||
{
|
{
|
||||||
c.inGame = false;
|
c.InGame = false;
|
||||||
c.Character = null;
|
c.Character = null;
|
||||||
}
|
}
|
||||||
yield return CoroutineStatus.Success;
|
yield return CoroutineStatus.Success;
|
||||||
@@ -908,7 +909,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConnectedClients.Add(newClient);
|
ConnectedClients.Add(newClient);
|
||||||
GameMain.NetLobbyScreen.AddPlayer(newClient.name);
|
GameMain.NetLobbyScreen.AddPlayer(newClient.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Voting.AllowSubVoting = allowSubVoting;
|
Voting.AllowSubVoting = allowSubVoting;
|
||||||
@@ -1142,6 +1143,14 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnTransferFailed(FileReceiver.FileTransferIn transfer)
|
||||||
|
{
|
||||||
|
if (transfer.FileType == FileTransferType.CampaignSave)
|
||||||
|
{
|
||||||
|
GameMain.Client.RequestFile(FileTransferType.CampaignSave, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateEntityEvent(IClientSerializable entity, object[] extraData)
|
public void CreateEntityEvent(IClientSerializable entity, object[] extraData)
|
||||||
{
|
{
|
||||||
entityEventManager.CreateEvent(entity, extraData);
|
entityEventManager.CreateEvent(entity, extraData);
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (y >= startY && y < startY + height - 120)
|
if (y >= startY && y < startY + height - 120)
|
||||||
{
|
{
|
||||||
GUI.SmallFont.DrawString(spriteBatch, c.name + " (" + c.Connection.RemoteEndPoint.Address.ToString() + ")", new Vector2(x + 10, y), clientColor);
|
GUI.SmallFont.DrawString(spriteBatch, c.Name + " (" + c.Connection.RemoteEndPoint.Address.ToString() + ")", new Vector2(x + 10, y), clientColor);
|
||||||
GUI.SmallFont.DrawString(spriteBatch, "Ping: " + (int)(c.Connection.AverageRoundtripTime * 1000.0f) + " ms", new Vector2(x + 20, y + 10), clientColor);
|
GUI.SmallFont.DrawString(spriteBatch, "Ping: " + (int)(c.Connection.AverageRoundtripTime * 1000.0f) + " ms", new Vector2(x + 20, y + 10), clientColor);
|
||||||
}
|
}
|
||||||
if (y + 25 >= startY && y < startY + height - 130) GUI.SmallFont.DrawString(spriteBatch, "Resent messages: " + c.Connection.Statistics.ResentMessages, new Vector2(x + 20, y + 20), clientColor);
|
if (y + 25 >= startY && y < startY + height - 130) GUI.SmallFont.DrawString(spriteBatch, "Resent messages: " + c.Connection.Statistics.ResentMessages, new Vector2(x + 20, y + 20), clientColor);
|
||||||
@@ -130,7 +130,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
var transfers = fileSender.ActiveTransfers.FindAll(t => t.Connection == client.Connection);
|
var transfers = fileSender.ActiveTransfers.FindAll(t => t.Connection == client.Connection);
|
||||||
|
|
||||||
var clientNameBox = GameMain.NetLobbyScreen.PlayerList.FindChild(client.name);
|
var clientNameBox = GameMain.NetLobbyScreen.PlayerList.FindChild(client.Name);
|
||||||
|
|
||||||
var clientInfo = clientNameBox.FindChild("filetransfer");
|
var clientInfo = clientNameBox.FindChild("filetransfer");
|
||||||
if (clientInfo == null)
|
if (clientInfo == null)
|
||||||
|
|||||||
@@ -473,27 +473,27 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, cList);
|
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.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.Color = (c.InGame && c.Character != null && !c.Character.IsDead) ? Color.Gold * 0.2f : Color.Transparent;
|
||||||
frame.HoverColor = Color.LightGray * 0.5f;
|
frame.HoverColor = Color.LightGray * 0.5f;
|
||||||
frame.SelectedColor = Color.Gold * 0.5f;
|
frame.SelectedColor = Color.Gold * 0.5f;
|
||||||
|
|
||||||
GUITextBlock textBlock = new GUITextBlock(
|
GUITextBlock textBlock = new GUITextBlock(
|
||||||
new Rectangle(40, 0, 0, 25),
|
new Rectangle(40, 0, 0, 25),
|
||||||
c.name + " (" + c.Connection.RemoteEndPoint.Address.ToString() + ")",
|
c.Name + " (" + c.Connection.RemoteEndPoint.Address.ToString() + ")",
|
||||||
Color.Transparent, Color.White,
|
Color.Transparent, Color.White,
|
||||||
Alignment.Left, Alignment.Left,
|
Alignment.Left, Alignment.Left,
|
||||||
null, frame);
|
null, frame);
|
||||||
|
|
||||||
var banButton = new GUIButton(new Rectangle(-110, 0, 100, 20), "Ban", Alignment.Right | Alignment.CenterY, "", frame);
|
var banButton = new GUIButton(new Rectangle(-110, 0, 100, 20), "Ban", Alignment.Right | Alignment.CenterY, "", frame);
|
||||||
banButton.UserData = c.name;
|
banButton.UserData = c.Name;
|
||||||
banButton.OnClicked = GameMain.NetLobbyScreen.BanPlayer;
|
banButton.OnClicked = GameMain.NetLobbyScreen.BanPlayer;
|
||||||
|
|
||||||
var rangebanButton = new GUIButton(new Rectangle(-220, 0, 100, 20), "Ban range", Alignment.Right | Alignment.CenterY, "", frame);
|
var rangebanButton = new GUIButton(new Rectangle(-220, 0, 100, 20), "Ban range", Alignment.Right | Alignment.CenterY, "", frame);
|
||||||
rangebanButton.UserData = c.name;
|
rangebanButton.UserData = c.Name;
|
||||||
rangebanButton.OnClicked = GameMain.NetLobbyScreen.BanPlayerRange;
|
rangebanButton.OnClicked = GameMain.NetLobbyScreen.BanPlayerRange;
|
||||||
|
|
||||||
var kickButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Kick", Alignment.Right | Alignment.CenterY, "", frame);
|
var kickButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Kick", Alignment.Right | Alignment.CenterY, "", frame);
|
||||||
kickButton.UserData = c.name;
|
kickButton.UserData = c.Name;
|
||||||
kickButton.OnClicked = GameMain.NetLobbyScreen.KickPlayer;
|
kickButton.OnClicked = GameMain.NetLobbyScreen.KickPlayer;
|
||||||
|
|
||||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
foreach (Client c in GameMain.Server.ConnectedClients)
|
foreach (Client c in GameMain.Server.ConnectedClients)
|
||||||
{
|
{
|
||||||
if (!IsWhiteListed(c.name, c.Connection.RemoteEndPoint.Address.ToString()))
|
if (!IsWhiteListed(c.Name, c.Connection.RemoteEndPoint.Address.ToString()))
|
||||||
{
|
{
|
||||||
whitelistedPlayers.Add(new WhiteListedPlayer(c.name, c.Connection.RemoteEndPoint.Address.ToString()));
|
whitelistedPlayers.Add(new WhiteListedPlayer(c.Name, c.Connection.RemoteEndPoint.Address.ToString()));
|
||||||
if (whitelistFrame != null) CreateWhiteListFrame(whitelistFrame.Parent);
|
if (whitelistFrame != null) CreateWhiteListFrame(whitelistFrame.Parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -866,7 +866,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (GameMain.Server != null)
|
if (GameMain.Server != null)
|
||||||
{
|
{
|
||||||
var selectedClient = GameMain.Server.ConnectedClients.Find(c => c.name == component.UserData.ToString());
|
var selectedClient = GameMain.Server.ConnectedClients.Find(c => c.Name == component.UserData.ToString());
|
||||||
|
|
||||||
new GUITextBlock(new Rectangle(0, 25, 150, 15), selectedClient.Connection.RemoteEndPoint.Address.ToString(), "", playerFrameInner);
|
new GUITextBlock(new Rectangle(0, 25, 150, 15), selectedClient.Connection.RemoteEndPoint.Address.ToString(), "", playerFrameInner);
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ namespace Barotrauma
|
|||||||
NewMessage("***************", Color.Cyan);
|
NewMessage("***************", Color.Cyan);
|
||||||
foreach (Client c in GameMain.Server.ConnectedClients)
|
foreach (Client c in GameMain.Server.ConnectedClients)
|
||||||
{
|
{
|
||||||
NewMessage("- " + c.ID.ToString() + ": " + c.name + ", " + c.Connection.RemoteEndPoint.Address.ToString(), Color.Cyan);
|
NewMessage("- " + c.ID.ToString() + ": " + c.Name + ", " + c.Connection.RemoteEndPoint.Address.ToString(), Color.Cyan);
|
||||||
}
|
}
|
||||||
NewMessage("***************", Color.Cyan);
|
NewMessage("***************", Color.Cyan);
|
||||||
}));
|
}));
|
||||||
@@ -304,9 +304,9 @@ namespace Barotrauma
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowQuestionPrompt("Reason for kicking \"" + client.name + "\"?", (reason) =>
|
ShowQuestionPrompt("Reason for kicking \"" + client.Name + "\"?", (reason) =>
|
||||||
{
|
{
|
||||||
GameMain.Server.KickPlayer(client.name, reason);
|
GameMain.Server.KickPlayer(client.Name, reason);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -349,7 +349,7 @@ namespace Barotrauma
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowQuestionPrompt("Reason for banning \"" + client.name + "\"?", (reason) =>
|
ShowQuestionPrompt("Reason for banning \"" + client.Name + "\"?", (reason) =>
|
||||||
{
|
{
|
||||||
ShowQuestionPrompt("Enter the duration of the ban (leave empty to ban permanently, or use the format \"[days] d [hours] h\")", (duration) =>
|
ShowQuestionPrompt("Enter the duration of the ban (leave empty to ban permanently, or use the format \"[days] d [hours] h\")", (duration) =>
|
||||||
{
|
{
|
||||||
@@ -365,7 +365,7 @@ namespace Barotrauma
|
|||||||
banDuration = parsedBanDuration;
|
banDuration = parsedBanDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameMain.Server.BanPlayer(client.name, reason, false, banDuration);
|
GameMain.Server.BanPlayer(client.Name, reason, false, banDuration);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
@@ -625,7 +625,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
string clientName = String.Join(" ", argsLeft);
|
string clientName = String.Join(" ", argsLeft);
|
||||||
|
|
||||||
var client = GameMain.Server.ConnectedClients.Find(c => c.name == clientName);
|
var client = GameMain.Server.ConnectedClients.Find(c => c.Name == clientName);
|
||||||
if (client == null)
|
if (client == null)
|
||||||
{
|
{
|
||||||
ThrowError("Client \"" + clientName + "\" not found.");
|
ThrowError("Client \"" + clientName + "\" not found.");
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ namespace Barotrauma
|
|||||||
lastUpdateID++;
|
lastUpdateID++;
|
||||||
|
|
||||||
bool success =
|
bool success =
|
||||||
GameMain.Server.ConnectedClients.Any(c => c.inGame && c.Character != null && !c.Character.IsDead) ||
|
GameMain.Server.ConnectedClients.Any(c => c.InGame && c.Character != null && !c.Character.IsDead) ||
|
||||||
(GameMain.Server.Character != null && !GameMain.Server.Character.IsDead);
|
(GameMain.Server.Character != null && !GameMain.Server.Character.IsDead);
|
||||||
|
|
||||||
/*if (success)
|
/*if (success)
|
||||||
@@ -409,7 +409,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (!sender.HasPermission(ClientPermissions.ManageCampaign))
|
if (!sender.HasPermission(ClientPermissions.ManageCampaign))
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Client \""+sender.name+"\" does not have a permission to manage the campaign");
|
DebugConsole.ThrowError("Client \""+sender.Name+"\" does not have a permission to manage the campaign");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,26 +135,26 @@ namespace Barotrauma.Networking
|
|||||||
string txt = msg.ReadString();
|
string txt = msg.ReadString();
|
||||||
if (txt == null) txt = "";
|
if (txt == null) txt = "";
|
||||||
|
|
||||||
if (!NetIdUtils.IdMoreRecent(ID, c.lastSentChatMsgID)) return;
|
if (!NetIdUtils.IdMoreRecent(ID, c.LastSentChatMsgID)) return;
|
||||||
|
|
||||||
c.lastSentChatMsgID = ID;
|
c.LastSentChatMsgID = ID;
|
||||||
|
|
||||||
if (txt.Length > MaxLength)
|
if (txt.Length > MaxLength)
|
||||||
{
|
{
|
||||||
txt = txt.Substring(0, MaxLength);
|
txt = txt.Substring(0, MaxLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
c.lastSentChatMessages.Add(txt);
|
c.LastSentChatMessages.Add(txt);
|
||||||
if (c.lastSentChatMessages.Count > 10)
|
if (c.LastSentChatMessages.Count > 10)
|
||||||
{
|
{
|
||||||
c.lastSentChatMessages.RemoveRange(0, c.lastSentChatMessages.Count-10);
|
c.LastSentChatMessages.RemoveRange(0, c.LastSentChatMessages.Count-10);
|
||||||
}
|
}
|
||||||
|
|
||||||
float similarity = 0.0f;
|
float similarity = 0.0f;
|
||||||
for (int i = 0; i < c.lastSentChatMessages.Count; i++)
|
for (int i = 0; i < c.LastSentChatMessages.Count; i++)
|
||||||
{
|
{
|
||||||
float closeFactor = 1.0f / (c.lastSentChatMessages.Count - i);
|
float closeFactor = 1.0f / (c.LastSentChatMessages.Count - i);
|
||||||
int levenshteinDist = ToolBox.LevenshteinDistance(txt, c.lastSentChatMessages[i]);
|
int levenshteinDist = ToolBox.LevenshteinDistance(txt, c.LastSentChatMessages[i]);
|
||||||
similarity += Math.Max((txt.Length - levenshteinDist) / (float)txt.Length * closeFactor, 0.0f);
|
similarity += Math.Max((txt.Length - levenshteinDist) / (float)txt.Length * closeFactor, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ namespace Barotrauma.Networking
|
|||||||
1 + //(byte)Type
|
1 + //(byte)Type
|
||||||
Encoding.UTF8.GetBytes(Text).Length + 2;
|
Encoding.UTF8.GetBytes(Text).Length + 2;
|
||||||
|
|
||||||
if (Sender != null && c.inGame)
|
if (Sender != null && c.InGame)
|
||||||
{
|
{
|
||||||
length += 2; //sender ID (UInt16)
|
length += 2; //sender ID (UInt16)
|
||||||
}
|
}
|
||||||
@@ -224,8 +224,8 @@ namespace Barotrauma.Networking
|
|||||||
msg.Write((byte)Type);
|
msg.Write((byte)Type);
|
||||||
msg.Write(Text);
|
msg.Write(Text);
|
||||||
|
|
||||||
msg.Write(Sender != null && c.inGame);
|
msg.Write(Sender != null && c.InGame);
|
||||||
if (Sender != null && c.inGame)
|
if (Sender != null && c.InGame)
|
||||||
{
|
{
|
||||||
msg.Write(Sender.ID);
|
msg.Write(Sender.ID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,35 +26,36 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
class Client
|
class Client
|
||||||
{
|
{
|
||||||
public string name;
|
public string Name;
|
||||||
public byte ID;
|
public byte ID;
|
||||||
|
|
||||||
public byte TeamID = 0;
|
public byte TeamID = 0;
|
||||||
|
|
||||||
public Character Character;
|
public Character Character;
|
||||||
public CharacterInfo characterInfo;
|
public CharacterInfo CharacterInfo;
|
||||||
public NetConnection Connection { get; set; }
|
public NetConnection Connection { get; set; }
|
||||||
public bool inGame;
|
public bool InGame;
|
||||||
public UInt16 lastRecvGeneralUpdate = 0;
|
|
||||||
|
|
||||||
public UInt16 lastSentChatMsgID = 0; //last msg this client said
|
public UInt16 LastRecvGeneralUpdate = 0;
|
||||||
public UInt16 lastRecvChatMsgID = 0; //last msg this client knows about
|
|
||||||
|
public UInt16 LastSentChatMsgID = 0; //last msg this client said
|
||||||
|
public UInt16 LastRecvChatMsgID = 0; //last msg this client knows about
|
||||||
|
|
||||||
public UInt16 lastSentEntityEventID = 0;
|
public UInt16 LastSentEntityEventID = 0;
|
||||||
public UInt16 lastRecvEntityEventID = 0;
|
public UInt16 LastRecvEntityEventID = 0;
|
||||||
|
|
||||||
public UInt16 lastRecvCampaignUpdate = 0;
|
public UInt16 LastRecvCampaignUpdate = 0;
|
||||||
public UInt16 lastRecvCampaignSave = 0;
|
public UInt16 LastRecvCampaignSave = 0;
|
||||||
|
|
||||||
public List<ChatMessage> chatMsgQueue = new List<ChatMessage>();
|
public readonly List<ChatMessage> ChatMsgQueue = new List<ChatMessage>();
|
||||||
public UInt16 lastChatMsgQueueID;
|
public UInt16 LastChatMsgQueueID;
|
||||||
|
|
||||||
//latest chat messages sent by this client
|
//latest chat messages sent by this client
|
||||||
public List<string> lastSentChatMessages = new List<string>();
|
public readonly List<string> LastSentChatMessages = new List<string>();
|
||||||
public float ChatSpamSpeed;
|
public float ChatSpamSpeed;
|
||||||
public float ChatSpamTimer;
|
public float ChatSpamTimer;
|
||||||
public int ChatSpamCount;
|
public int ChatSpamCount;
|
||||||
|
|
||||||
public double MidRoundSyncTimeOut;
|
public double MidRoundSyncTimeOut;
|
||||||
|
|
||||||
public bool NeedsMidRoundSync;
|
public bool NeedsMidRoundSync;
|
||||||
@@ -66,36 +67,31 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
//when was a specific entity event last sent to the client
|
//when was a specific entity event last sent to the client
|
||||||
// key = event id, value = NetTime.Now when sending
|
// key = event id, value = NetTime.Now when sending
|
||||||
public Dictionary<UInt16, float> entityEventLastSent;
|
public readonly Dictionary<UInt16, float> EntityEventLastSent = new Dictionary<UInt16, float>();
|
||||||
|
|
||||||
private Queue<Entity> pendingPositionUpdates = new Queue<Entity>();
|
|
||||||
|
|
||||||
|
public readonly Queue<Entity> PendingPositionUpdates = new Queue<Entity>();
|
||||||
|
|
||||||
public bool ReadyToStart;
|
public bool ReadyToStart;
|
||||||
|
|
||||||
private object[] votes;
|
public List<JobPrefab> JobPreferences;
|
||||||
|
public JobPrefab AssignedJob;
|
||||||
public List<JobPrefab> jobPreferences;
|
|
||||||
public JobPrefab assignedJob;
|
|
||||||
|
|
||||||
public float deleteDisconnectedTimer;
|
public float DeleteDisconnectedTimer;
|
||||||
|
|
||||||
public ClientPermissions Permissions = ClientPermissions.None;
|
public ClientPermissions Permissions = ClientPermissions.None;
|
||||||
|
|
||||||
public bool SpectateOnly;
|
public bool SpectateOnly;
|
||||||
|
|
||||||
|
private object[] votes;
|
||||||
|
|
||||||
public Queue<Entity> PendingPositionUpdates
|
|
||||||
{
|
|
||||||
get { return pendingPositionUpdates; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InitClientSync()
|
public void InitClientSync()
|
||||||
{
|
{
|
||||||
lastSentChatMsgID = 0;
|
LastSentChatMsgID = 0;
|
||||||
lastRecvChatMsgID = ChatMessage.LastID;
|
LastRecvChatMsgID = ChatMessage.LastID;
|
||||||
|
|
||||||
lastRecvGeneralUpdate = 0;
|
LastRecvGeneralUpdate = 0;
|
||||||
|
|
||||||
lastRecvEntityEventID = 0;
|
LastRecvEntityEventID = 0;
|
||||||
|
|
||||||
UnreceivedEntityEventCount = 0;
|
UnreceivedEntityEventCount = 0;
|
||||||
NeedsMidRoundSync = false;
|
NeedsMidRoundSync = false;
|
||||||
@@ -114,16 +110,14 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public Client(string name, byte ID)
|
public Client(string name, byte ID)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.Name = name;
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
|
|
||||||
kickVoters = new List<Client>();
|
kickVoters = new List<Client>();
|
||||||
|
|
||||||
votes = new object[Enum.GetNames(typeof(VoteType)).Length];
|
votes = new object[Enum.GetNames(typeof(VoteType)).Length];
|
||||||
|
|
||||||
jobPreferences = new List<JobPrefab>(JobPrefab.List.GetRange(0, Math.Min(JobPrefab.List.Count, 3)));
|
JobPreferences = new List<JobPrefab>(JobPrefab.List.GetRange(0, Math.Min(JobPrefab.List.Count, 3)));
|
||||||
|
|
||||||
entityEventLastSent = new Dictionary<UInt16, float>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsValidName(string name)
|
public static bool IsValidName(string name)
|
||||||
|
|||||||
@@ -408,8 +408,8 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
for (int i = disconnectedClients.Count - 1; i >= 0; i-- )
|
for (int i = disconnectedClients.Count - 1; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
disconnectedClients[i].deleteDisconnectedTimer -= deltaTime;
|
disconnectedClients[i].DeleteDisconnectedTimer -= deltaTime;
|
||||||
if (disconnectedClients[i].deleteDisconnectedTimer > 0.0f) continue;
|
if (disconnectedClients[i].DeleteDisconnectedTimer > 0.0f) continue;
|
||||||
|
|
||||||
if (gameStarted && disconnectedClients[i].Character!=null)
|
if (gameStarted && disconnectedClients[i].Character!=null)
|
||||||
{
|
{
|
||||||
@@ -449,7 +449,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
DisconnectClient(inc.SenderConnection,
|
DisconnectClient(inc.SenderConnection,
|
||||||
connectedClient != null ? connectedClient.name + " has disconnected" : "");
|
connectedClient != null ? connectedClient.Name + " has disconnected" : "");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -496,7 +496,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Failed to write a network message for the client \""+c.name+"\"!", e);
|
DebugConsole.ThrowError("Failed to write a network message for the client \""+c.Name+"\"!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,13 +598,13 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
case ClientNetObject.SYNC_IDS:
|
case ClientNetObject.SYNC_IDS:
|
||||||
//TODO: might want to use a clever class for this
|
//TODO: might want to use a clever class for this
|
||||||
c.lastRecvGeneralUpdate = NetIdUtils.Clamp(inc.ReadUInt16(), c.lastRecvGeneralUpdate, GameMain.NetLobbyScreen.LastUpdateID);
|
c.LastRecvGeneralUpdate = NetIdUtils.Clamp(inc.ReadUInt16(), c.LastRecvGeneralUpdate, GameMain.NetLobbyScreen.LastUpdateID);
|
||||||
c.lastRecvChatMsgID = NetIdUtils.Clamp(inc.ReadUInt16(), c.lastRecvChatMsgID, c.lastChatMsgQueueID);
|
c.LastRecvChatMsgID = NetIdUtils.Clamp(inc.ReadUInt16(), c.LastRecvChatMsgID, c.LastChatMsgQueueID);
|
||||||
|
|
||||||
c.lastRecvCampaignSave = inc.ReadUInt16();
|
c.LastRecvCampaignSave = inc.ReadUInt16();
|
||||||
if (c.lastRecvCampaignSave > 0)
|
if (c.LastRecvCampaignSave > 0)
|
||||||
{
|
{
|
||||||
c.lastRecvCampaignUpdate = inc.ReadUInt16();
|
c.LastRecvCampaignUpdate = inc.ReadUInt16();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ClientNetObject.CHAT_MESSAGE:
|
case ClientNetObject.CHAT_MESSAGE:
|
||||||
@@ -633,11 +633,11 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (gameStarted)
|
if (gameStarted)
|
||||||
{
|
{
|
||||||
if (!c.inGame)
|
if (!c.InGame)
|
||||||
{
|
{
|
||||||
//check if midround syncing is needed due to missed unique events
|
//check if midround syncing is needed due to missed unique events
|
||||||
entityEventManager.InitClientMidRoundSync(c);
|
entityEventManager.InitClientMidRoundSync(c);
|
||||||
c.inGame = true;
|
c.InGame = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -663,7 +663,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
c.NeedsMidRoundSync = false;
|
c.NeedsMidRoundSync = false;
|
||||||
lastRecvEntityEventID = (UInt16)(c.FirstNewEventID - 1);
|
lastRecvEntityEventID = (UInt16)(c.FirstNewEventID - 1);
|
||||||
c.lastRecvEntityEventID = lastRecvEntityEventID;
|
c.LastRecvEntityEventID = lastRecvEntityEventID;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -671,28 +671,28 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastRecvChatMsgID) && //more recent than the last ID received by the client
|
if (NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.LastRecvChatMsgID) && //more recent than the last ID received by the client
|
||||||
!NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.lastChatMsgQueueID)) //NOT more recent than the latest existing ID
|
!NetIdUtils.IdMoreRecent(lastRecvChatMsgID, c.LastChatMsgQueueID)) //NOT more recent than the latest existing ID
|
||||||
{
|
{
|
||||||
c.lastRecvChatMsgID = lastRecvChatMsgID;
|
c.LastRecvChatMsgID = lastRecvChatMsgID;
|
||||||
}
|
}
|
||||||
else if (lastRecvChatMsgID != c.lastRecvChatMsgID && GameSettings.VerboseLogging)
|
else if (lastRecvChatMsgID != c.LastRecvChatMsgID && GameSettings.VerboseLogging)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError(
|
DebugConsole.ThrowError(
|
||||||
"Invalid lastRecvChatMsgID " + lastRecvChatMsgID +
|
"Invalid lastRecvChatMsgID " + lastRecvChatMsgID +
|
||||||
" (previous: " + c.lastChatMsgQueueID + ", latest: "+c.lastChatMsgQueueID+")");
|
" (previous: " + c.LastChatMsgQueueID + ", latest: "+c.LastChatMsgQueueID+")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NetIdUtils.IdMoreRecent(lastRecvEntityEventID, c.lastRecvEntityEventID) &&
|
if (NetIdUtils.IdMoreRecent(lastRecvEntityEventID, c.LastRecvEntityEventID) &&
|
||||||
!NetIdUtils.IdMoreRecent(lastRecvEntityEventID, lastEntityEventID))
|
!NetIdUtils.IdMoreRecent(lastRecvEntityEventID, lastEntityEventID))
|
||||||
{
|
{
|
||||||
c.lastRecvEntityEventID = lastRecvEntityEventID;
|
c.LastRecvEntityEventID = lastRecvEntityEventID;
|
||||||
}
|
}
|
||||||
else if (lastRecvEntityEventID != c.lastRecvEntityEventID && GameSettings.VerboseLogging)
|
else if (lastRecvEntityEventID != c.LastRecvEntityEventID && GameSettings.VerboseLogging)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError(
|
DebugConsole.ThrowError(
|
||||||
"Invalid lastRecvEntityEventID " + lastRecvEntityEventID +
|
"Invalid lastRecvEntityEventID " + lastRecvEntityEventID +
|
||||||
" (previous: " + c.lastRecvEntityEventID + ", latest: " + lastEntityEventID + ")");
|
" (previous: " + c.LastRecvEntityEventID + ", latest: " + lastEntityEventID + ")");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ClientNetObject.CHAT_MESSAGE:
|
case ClientNetObject.CHAT_MESSAGE:
|
||||||
@@ -741,7 +741,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (!sender.HasPermission(command))
|
if (!sender.HasPermission(command))
|
||||||
{
|
{
|
||||||
Log("Client \"" + sender.name + "\" sent a server command \"" + command + "\". Permission denied.", ServerLog.MessageType.ServerMessage);
|
Log("Client \"" + sender.Name + "\" sent a server command \"" + command + "\". Permission denied.", ServerLog.MessageType.ServerMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -750,27 +750,27 @@ namespace Barotrauma.Networking
|
|||||||
case ClientPermissions.Kick:
|
case ClientPermissions.Kick:
|
||||||
string kickedName = inc.ReadString().ToLowerInvariant();
|
string kickedName = inc.ReadString().ToLowerInvariant();
|
||||||
string kickReason = inc.ReadString();
|
string kickReason = inc.ReadString();
|
||||||
var kickedClient = connectedClients.Find(cl => cl != sender && cl.name.ToLowerInvariant() == kickedName);
|
var kickedClient = connectedClients.Find(cl => cl != sender && cl.Name.ToLowerInvariant() == kickedName);
|
||||||
if (kickedClient != null)
|
if (kickedClient != null)
|
||||||
{
|
{
|
||||||
Log("Client \"" + sender.name + "\" kicked \"" + kickedClient.name + "\".", ServerLog.MessageType.ServerMessage);
|
Log("Client \"" + sender.Name + "\" kicked \"" + kickedClient.Name + "\".", ServerLog.MessageType.ServerMessage);
|
||||||
KickClient(kickedClient, string.IsNullOrEmpty(kickReason) ? "Kicked by " + sender.name : kickReason);
|
KickClient(kickedClient, string.IsNullOrEmpty(kickReason) ? "Kicked by " + sender.Name : kickReason);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ClientPermissions.Ban:
|
case ClientPermissions.Ban:
|
||||||
string bannedName = inc.ReadString().ToLowerInvariant();
|
string bannedName = inc.ReadString().ToLowerInvariant();
|
||||||
string banReason = inc.ReadString();
|
string banReason = inc.ReadString();
|
||||||
var bannedClient = connectedClients.Find(cl => cl != sender && cl.name.ToLowerInvariant() == bannedName);
|
var bannedClient = connectedClients.Find(cl => cl != sender && cl.Name.ToLowerInvariant() == bannedName);
|
||||||
if (bannedClient != null)
|
if (bannedClient != null)
|
||||||
{
|
{
|
||||||
Log("Client \"" + sender.name + "\" banned \"" + bannedClient.name + "\".", ServerLog.MessageType.ServerMessage);
|
Log("Client \"" + sender.Name + "\" banned \"" + bannedClient.Name + "\".", ServerLog.MessageType.ServerMessage);
|
||||||
BanClient(bannedClient, string.IsNullOrEmpty(banReason) ? "Banned by " + sender.name : banReason, false);
|
BanClient(bannedClient, string.IsNullOrEmpty(banReason) ? "Banned by " + sender.Name : banReason, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ClientPermissions.EndRound:
|
case ClientPermissions.EndRound:
|
||||||
if (gameStarted)
|
if (gameStarted)
|
||||||
{
|
{
|
||||||
Log("Client \"" + sender.name + "\" ended the round.", ServerLog.MessageType.ServerMessage);
|
Log("Client \"" + sender.Name + "\" ended the round.", ServerLog.MessageType.ServerMessage);
|
||||||
EndGame();
|
EndGame();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -779,7 +779,7 @@ namespace Barotrauma.Networking
|
|||||||
var subList = GameMain.NetLobbyScreen.GetSubList();
|
var subList = GameMain.NetLobbyScreen.GetSubList();
|
||||||
if (subIndex >= subList.Count)
|
if (subIndex >= subList.Count)
|
||||||
{
|
{
|
||||||
DebugConsole.NewMessage("Client \"" + sender.name + "\" attempted to select a sub, index out of bounds (" + subIndex + ")", Color.Red);
|
DebugConsole.NewMessage("Client \"" + sender.Name + "\" attempted to select a sub, index out of bounds (" + subIndex + ")", Color.Red);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -805,7 +805,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private void ClientWrite(Client c)
|
private void ClientWrite(Client c)
|
||||||
{
|
{
|
||||||
if (gameStarted && c.inGame)
|
if (gameStarted && c.InGame)
|
||||||
{
|
{
|
||||||
ClientWriteIngame(c);
|
ClientWriteIngame(c);
|
||||||
}
|
}
|
||||||
@@ -822,7 +822,7 @@ namespace Barotrauma.Networking
|
|||||||
ClientWriteLobby(c);
|
ClientWriteLobby(c);
|
||||||
|
|
||||||
MultiplayerCampaign campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign;
|
MultiplayerCampaign campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign;
|
||||||
if (campaign != null && NetIdUtils.IdMoreRecent(campaign.LastSaveID, c.lastRecvCampaignSave))
|
if (campaign != null && NetIdUtils.IdMoreRecent(campaign.LastSaveID, c.LastRecvCampaignSave))
|
||||||
{
|
{
|
||||||
if (!fileSender.ActiveTransfers.Any(t => t.Connection == c.Connection && t.FileType == FileTransferType.CampaignSave))
|
if (!fileSender.ActiveTransfers.Any(t => t.Connection == c.Connection && t.FileType == FileTransferType.CampaignSave))
|
||||||
{
|
{
|
||||||
@@ -897,8 +897,8 @@ namespace Barotrauma.Networking
|
|||||||
outmsg.Write((float)NetTime.Now);
|
outmsg.Write((float)NetTime.Now);
|
||||||
|
|
||||||
outmsg.Write((byte)ServerNetObject.SYNC_IDS);
|
outmsg.Write((byte)ServerNetObject.SYNC_IDS);
|
||||||
outmsg.Write(c.lastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server
|
outmsg.Write(c.LastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server
|
||||||
outmsg.Write(c.lastSentEntityEventID);
|
outmsg.Write(c.LastSentEntityEventID);
|
||||||
|
|
||||||
entityEventManager.Write(c, outmsg);
|
entityEventManager.Write(c, outmsg);
|
||||||
|
|
||||||
@@ -942,7 +942,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
outmsg.Write((byte)ServerNetObject.SYNC_IDS);
|
outmsg.Write((byte)ServerNetObject.SYNC_IDS);
|
||||||
|
|
||||||
if (NetIdUtils.IdMoreRecent(GameMain.NetLobbyScreen.LastUpdateID, c.lastRecvGeneralUpdate))
|
if (NetIdUtils.IdMoreRecent(GameMain.NetLobbyScreen.LastUpdateID, c.LastRecvGeneralUpdate))
|
||||||
{
|
{
|
||||||
outmsg.Write(true);
|
outmsg.Write(true);
|
||||||
outmsg.WritePadBits();
|
outmsg.WritePadBits();
|
||||||
@@ -951,8 +951,8 @@ namespace Barotrauma.Networking
|
|||||||
outmsg.Write(GameMain.NetLobbyScreen.GetServerName());
|
outmsg.Write(GameMain.NetLobbyScreen.GetServerName());
|
||||||
outmsg.Write(GameMain.NetLobbyScreen.ServerMessageText);
|
outmsg.Write(GameMain.NetLobbyScreen.ServerMessageText);
|
||||||
|
|
||||||
outmsg.Write(c.lastRecvGeneralUpdate < 1);
|
outmsg.Write(c.LastRecvGeneralUpdate < 1);
|
||||||
if (c.lastRecvGeneralUpdate < 1)
|
if (c.LastRecvGeneralUpdate < 1)
|
||||||
{
|
{
|
||||||
isInitialUpdate = true;
|
isInitialUpdate = true;
|
||||||
ClientWriteInitial(c, outmsg);
|
ClientWriteInitial(c, outmsg);
|
||||||
@@ -984,7 +984,7 @@ namespace Barotrauma.Networking
|
|||||||
foreach (Client client in connectedClients)
|
foreach (Client client in connectedClients)
|
||||||
{
|
{
|
||||||
outmsg.Write(client.ID);
|
outmsg.Write(client.ID);
|
||||||
outmsg.Write(client.name);
|
outmsg.Write(client.Name);
|
||||||
outmsg.Write(client.Character == null || !gameStarted ? (ushort)0 : client.Character.ID);
|
outmsg.Write(client.Character == null || !gameStarted ? (ushort)0 : client.Character.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -997,7 +997,7 @@ namespace Barotrauma.Networking
|
|||||||
var campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign;
|
var campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign;
|
||||||
if (campaign != null)
|
if (campaign != null)
|
||||||
{
|
{
|
||||||
if (NetIdUtils.IdMoreRecent(campaign.LastUpdateID, c.lastRecvCampaignUpdate))
|
if (NetIdUtils.IdMoreRecent(campaign.LastUpdateID, c.LastRecvCampaignUpdate))
|
||||||
{
|
{
|
||||||
outmsg.Write(true);
|
outmsg.Write(true);
|
||||||
outmsg.WritePadBits();
|
outmsg.WritePadBits();
|
||||||
@@ -1015,7 +1015,7 @@ namespace Barotrauma.Networking
|
|||||||
outmsg.WritePadBits();
|
outmsg.WritePadBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
outmsg.Write(c.lastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server
|
outmsg.Write(c.LastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server
|
||||||
|
|
||||||
WriteChatMessages(outmsg, c);
|
WriteChatMessages(outmsg, c);
|
||||||
|
|
||||||
@@ -1031,7 +1031,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
//and assume the message was received, so we don't have to keep resending
|
//and assume the message was received, so we don't have to keep resending
|
||||||
//these large initial messages until the client acknowledges receiving them
|
//these large initial messages until the client acknowledges receiving them
|
||||||
c.lastRecvGeneralUpdate++;
|
c.LastRecvGeneralUpdate++;
|
||||||
|
|
||||||
SendVoteStatus(new List<Client>() { c });
|
SendVoteStatus(new List<Client>() { c });
|
||||||
}
|
}
|
||||||
@@ -1048,15 +1048,15 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private void WriteChatMessages(NetOutgoingMessage outmsg, Client c)
|
private void WriteChatMessages(NetOutgoingMessage outmsg, Client c)
|
||||||
{
|
{
|
||||||
c.chatMsgQueue.RemoveAll(cMsg => !NetIdUtils.IdMoreRecent(cMsg.NetStateID, c.lastRecvChatMsgID));
|
c.ChatMsgQueue.RemoveAll(cMsg => !NetIdUtils.IdMoreRecent(cMsg.NetStateID, c.LastRecvChatMsgID));
|
||||||
for (int i = 0; i < c.chatMsgQueue.Count && i < ChatMessage.MaxMessagesPerPacket; i++)
|
for (int i = 0; i < c.ChatMsgQueue.Count && i < ChatMessage.MaxMessagesPerPacket; i++)
|
||||||
{
|
{
|
||||||
if (outmsg.LengthBytes + c.chatMsgQueue[i].EstimateLengthBytesServer(c) > config.MaximumTransmissionUnit - 5)
|
if (outmsg.LengthBytes + c.ChatMsgQueue[i].EstimateLengthBytesServer(c) > config.MaximumTransmissionUnit - 5)
|
||||||
{
|
{
|
||||||
//not enough room in this packet
|
//not enough room in this packet
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
c.chatMsgQueue[i].ServerWrite(outmsg, c);
|
c.ChatMsgQueue[i].ServerWrite(outmsg, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1243,17 +1243,17 @@ namespace Barotrauma.Networking
|
|||||||
client.NeedsMidRoundSync = false;
|
client.NeedsMidRoundSync = false;
|
||||||
|
|
||||||
client.PendingPositionUpdates.Clear();
|
client.PendingPositionUpdates.Clear();
|
||||||
client.entityEventLastSent.Clear();
|
client.EntityEventLastSent.Clear();
|
||||||
client.lastSentEntityEventID = 0;
|
client.LastSentEntityEventID = 0;
|
||||||
client.lastRecvEntityEventID = 0;
|
client.LastRecvEntityEventID = 0;
|
||||||
client.UnreceivedEntityEventCount = 0;
|
client.UnreceivedEntityEventCount = 0;
|
||||||
|
|
||||||
if (client.characterInfo == null)
|
if (client.CharacterInfo == null)
|
||||||
{
|
{
|
||||||
client.characterInfo = new CharacterInfo(Character.HumanConfigFile, client.name);
|
client.CharacterInfo = new CharacterInfo(Character.HumanConfigFile, client.Name);
|
||||||
}
|
}
|
||||||
characterInfos.Add(client.characterInfo);
|
characterInfos.Add(client.CharacterInfo);
|
||||||
client.characterInfo.Job = new Job(client.assignedJob);
|
client.CharacterInfo.Job = new Job(client.AssignedJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
//host's character
|
//host's character
|
||||||
@@ -1266,7 +1266,7 @@ namespace Barotrauma.Networking
|
|||||||
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSubs[teamID - 1]);
|
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSubs[teamID - 1]);
|
||||||
for (int i = 0; i < teamClients.Count; i++)
|
for (int i = 0; i < teamClients.Count; i++)
|
||||||
{
|
{
|
||||||
Character spawnedCharacter = Character.Create(teamClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false);
|
Character spawnedCharacter = Character.Create(teamClients[i].CharacterInfo, assignedWayPoints[i].WorldPosition, true, false);
|
||||||
spawnedCharacter.AnimController.Frozen = true;
|
spawnedCharacter.AnimController.Frozen = true;
|
||||||
spawnedCharacter.GiveJobItems(assignedWayPoints[i]);
|
spawnedCharacter.GiveJobItems(assignedWayPoints[i]);
|
||||||
spawnedCharacter.TeamID = (byte)teamID;
|
spawnedCharacter.TeamID = (byte)teamID;
|
||||||
@@ -1446,7 +1446,7 @@ namespace Barotrauma.Networking
|
|||||||
entityEventManager.Clear();
|
entityEventManager.Clear();
|
||||||
foreach (Client c in connectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
c.entityEventLastSent.Clear();
|
c.EntityEventLastSent.Clear();
|
||||||
c.PendingPositionUpdates.Clear();
|
c.PendingPositionUpdates.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1471,7 +1471,7 @@ namespace Barotrauma.Networking
|
|||||||
foreach (Client client in connectedClients)
|
foreach (Client client in connectedClients)
|
||||||
{
|
{
|
||||||
client.Character = null;
|
client.Character = null;
|
||||||
client.inGame = false;
|
client.InGame = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1505,7 +1505,7 @@ namespace Barotrauma.Networking
|
|||||||
playerName = playerName.ToLowerInvariant();
|
playerName = playerName.ToLowerInvariant();
|
||||||
|
|
||||||
Client client = connectedClients.Find(c =>
|
Client client = connectedClients.Find(c =>
|
||||||
c.name.ToLowerInvariant() == playerName ||
|
c.Name.ToLowerInvariant() == playerName ||
|
||||||
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
|
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
|
||||||
|
|
||||||
KickClient(client, reason);
|
KickClient(client, reason);
|
||||||
@@ -1523,7 +1523,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
string msg = "You have been kicked from the server.";
|
string msg = "You have been kicked from the server.";
|
||||||
if (!string.IsNullOrWhiteSpace(reason)) msg += "\nReason: " + reason;
|
if (!string.IsNullOrWhiteSpace(reason)) msg += "\nReason: " + reason;
|
||||||
DisconnectClient(client, client.name + " has been kicked from the server.", msg);
|
DisconnectClient(client, client.Name + " has been kicked from the server.", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void BanPlayer(string playerName, string reason, bool range = false, TimeSpan? duration = null)
|
public override void BanPlayer(string playerName, string reason, bool range = false, TimeSpan? duration = null)
|
||||||
@@ -1531,7 +1531,7 @@ namespace Barotrauma.Networking
|
|||||||
playerName = playerName.ToLowerInvariant();
|
playerName = playerName.ToLowerInvariant();
|
||||||
|
|
||||||
Client client = connectedClients.Find(c =>
|
Client client = connectedClients.Find(c =>
|
||||||
c.name.ToLowerInvariant() == playerName ||
|
c.Name.ToLowerInvariant() == playerName ||
|
||||||
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
|
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
|
||||||
|
|
||||||
if (client == null)
|
if (client == null)
|
||||||
@@ -1566,10 +1566,10 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
string msg = "You have been banned from the server.";
|
string msg = "You have been banned from the server.";
|
||||||
if (!string.IsNullOrWhiteSpace(reason)) msg += "\nReason: " + reason;
|
if (!string.IsNullOrWhiteSpace(reason)) msg += "\nReason: " + reason;
|
||||||
DisconnectClient(client, client.name + " has been banned from the server.", msg);
|
DisconnectClient(client, client.Name + " has been banned from the server.", msg);
|
||||||
string ip = client.Connection.RemoteEndPoint.Address.ToString();
|
string ip = client.Connection.RemoteEndPoint.Address.ToString();
|
||||||
if (range) { ip = banList.ToRange(ip); }
|
if (range) { ip = banList.ToRange(ip); }
|
||||||
banList.BanPlayer(client.name, ip, reason, duration);
|
banList.BanPlayer(client.Name, ip, reason, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisconnectClient(NetConnection senderConnection, string msg = "", string targetmsg = "")
|
public void DisconnectClient(NetConnection senderConnection, string msg = "", string targetmsg = "")
|
||||||
@@ -1591,9 +1591,9 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.Character = null;
|
client.Character = null;
|
||||||
client.inGame = false;
|
client.InGame = false;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(msg)) msg = client.name + " has left the server";
|
if (string.IsNullOrWhiteSpace(msg)) msg = client.Name + " has left the server";
|
||||||
if (string.IsNullOrWhiteSpace(targetmsg)) targetmsg = "You have left the server";
|
if (string.IsNullOrWhiteSpace(targetmsg)) targetmsg = "You have left the server";
|
||||||
|
|
||||||
Log(msg, ServerLog.MessageType.ServerMessage);
|
Log(msg, ServerLog.MessageType.ServerMessage);
|
||||||
@@ -1602,7 +1602,7 @@ namespace Barotrauma.Networking
|
|||||||
connectedClients.Remove(client);
|
connectedClients.Remove(client);
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
GameMain.NetLobbyScreen.RemovePlayer(client.name);
|
GameMain.NetLobbyScreen.RemovePlayer(client.Name);
|
||||||
Voting.UpdateVoteTexts(connectedClients, VoteType.Sub);
|
Voting.UpdateVoteTexts(connectedClients, VoteType.Sub);
|
||||||
Voting.UpdateVoteTexts(connectedClients, VoteType.Mode);
|
Voting.UpdateVoteTexts(connectedClients, VoteType.Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -1620,18 +1620,18 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
foreach (Client c in connectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
if (c.Character == null || !c.inGame) continue;
|
if (c.Character == null || !c.InGame) continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendChatMessage(ChatMessage msg, Client recipient)
|
public void SendChatMessage(ChatMessage msg, Client recipient)
|
||||||
{
|
{
|
||||||
msg.NetStateID = recipient.chatMsgQueue.Count > 0 ?
|
msg.NetStateID = recipient.ChatMsgQueue.Count > 0 ?
|
||||||
(ushort)(recipient.chatMsgQueue.Last().NetStateID + 1) :
|
(ushort)(recipient.ChatMsgQueue.Last().NetStateID + 1) :
|
||||||
(ushort)(recipient.lastRecvChatMsgID + 1);
|
(ushort)(recipient.LastRecvChatMsgID + 1);
|
||||||
|
|
||||||
recipient.chatMsgQueue.Add(msg);
|
recipient.ChatMsgQueue.Add(msg);
|
||||||
recipient.lastChatMsgQueueID = msg.NetStateID;
|
recipient.LastChatMsgQueueID = msg.NetStateID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1668,7 +1668,7 @@ namespace Barotrauma.Networking
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
targetClient = connectedClients.Find(c =>
|
targetClient = connectedClients.Find(c =>
|
||||||
command == c.name.ToLowerInvariant() ||
|
command == c.Name.ToLowerInvariant() ||
|
||||||
(c.Character != null && command == c.Character.Name.ToLowerInvariant()));
|
(c.Character != null && command == c.Character.Name.ToLowerInvariant()));
|
||||||
|
|
||||||
if (targetClient == null)
|
if (targetClient == null)
|
||||||
@@ -1679,12 +1679,12 @@ namespace Barotrauma.Networking
|
|||||||
"", "Player \"" + command + "\" not found!",
|
"", "Player \"" + command + "\" not found!",
|
||||||
ChatMessageType.Error, null);
|
ChatMessageType.Error, null);
|
||||||
|
|
||||||
chatMsg.NetStateID = senderClient.chatMsgQueue.Count > 0 ?
|
chatMsg.NetStateID = senderClient.ChatMsgQueue.Count > 0 ?
|
||||||
(ushort)(senderClient.chatMsgQueue.Last().NetStateID + 1) :
|
(ushort)(senderClient.ChatMsgQueue.Last().NetStateID + 1) :
|
||||||
(ushort)(senderClient.lastRecvChatMsgID + 1);
|
(ushort)(senderClient.LastRecvChatMsgID + 1);
|
||||||
|
|
||||||
senderClient.chatMsgQueue.Add(chatMsg);
|
senderClient.ChatMsgQueue.Add(chatMsg);
|
||||||
senderClient.lastChatMsgQueueID = chatMsg.NetStateID;
|
senderClient.LastChatMsgQueueID = chatMsg.NetStateID;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1718,7 +1718,7 @@ namespace Barotrauma.Networking
|
|||||||
else //msg sent by a client
|
else //msg sent by a client
|
||||||
{
|
{
|
||||||
senderCharacter = senderClient.Character;
|
senderCharacter = senderClient.Character;
|
||||||
senderName = senderCharacter == null ? senderClient.name : senderCharacter.Name;
|
senderName = senderCharacter == null ? senderClient.Name : senderCharacter.Name;
|
||||||
|
|
||||||
//sender doesn't have an alive character -> only ChatMessageType.Dead allowed
|
//sender doesn't have an alive character -> only ChatMessageType.Dead allowed
|
||||||
if (senderCharacter == null || senderCharacter.IsDead)
|
if (senderCharacter == null || senderCharacter.IsDead)
|
||||||
@@ -1744,7 +1744,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
//game not started -> clients can only send normal and private chatmessages
|
//game not started -> clients can only send normal and private chatmessages
|
||||||
if (type != ChatMessageType.Private) type = ChatMessageType.Default;
|
if (type != ChatMessageType.Private) type = ChatMessageType.Default;
|
||||||
senderName = senderClient.name;
|
senderName = senderClient.Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1864,6 +1864,11 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private void FileTransferChanged(FileSender.FileTransferOut transfer)
|
private void FileTransferChanged(FileSender.FileTransferOut transfer)
|
||||||
{
|
{
|
||||||
|
if (connectedClients.Any(c=> c.Connection == null))
|
||||||
|
{
|
||||||
|
int sdfgsdfg = 1;
|
||||||
|
}
|
||||||
|
|
||||||
Client recipient = connectedClients.Find(c => c.Connection == transfer.Connection);
|
Client recipient = connectedClients.Find(c => c.Connection == transfer.Connection);
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
UpdateFileTransferIndicator(recipient);
|
UpdateFileTransferIndicator(recipient);
|
||||||
@@ -1888,7 +1893,7 @@ namespace Barotrauma.Networking
|
|||||||
var clientsToKick = connectedClients.FindAll(c => c.KickVoteCount >= connectedClients.Count * KickVoteRequiredRatio);
|
var clientsToKick = connectedClients.FindAll(c => c.KickVoteCount >= connectedClients.Count * KickVoteRequiredRatio);
|
||||||
foreach (Client c in clientsToKick)
|
foreach (Client c in clientsToKick)
|
||||||
{
|
{
|
||||||
SendChatMessage(c.name + " has been kicked from the server.", ChatMessageType.Server, null);
|
SendChatMessage(c.Name + " has been kicked from the server.", ChatMessageType.Server, null);
|
||||||
KickClient(c, "Kicked by vote");
|
KickClient(c, "Kicked by vote");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1922,7 +1927,7 @@ namespace Barotrauma.Networking
|
|||||||
if (client.Permissions != ClientPermissions.None)
|
if (client.Permissions != ClientPermissions.None)
|
||||||
{
|
{
|
||||||
clientPermissions.Add(new SavedClientPermission(
|
clientPermissions.Add(new SavedClientPermission(
|
||||||
client.name,
|
client.Name,
|
||||||
client.Connection.RemoteEndPoint.Address.ToString(),
|
client.Connection.RemoteEndPoint.Address.ToString(),
|
||||||
client.Permissions));
|
client.Permissions));
|
||||||
}
|
}
|
||||||
@@ -1989,7 +1994,7 @@ namespace Barotrauma.Networking
|
|||||||
gender = Gender.Male;
|
gender = Gender.Male;
|
||||||
headSpriteId = 0;
|
headSpriteId = 0;
|
||||||
|
|
||||||
DebugConsole.Log("Received invalid characterinfo from \"" + sender.name + "\"! { " + e.Message + " }");
|
DebugConsole.Log("Received invalid characterinfo from \"" + sender.Name + "\"! { " + e.Message + " }");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<JobPrefab> jobPreferences = new List<JobPrefab>();
|
List<JobPrefab> jobPreferences = new List<JobPrefab>();
|
||||||
@@ -2002,9 +2007,9 @@ namespace Barotrauma.Networking
|
|||||||
if (jobPrefab != null) jobPreferences.Add(jobPrefab);
|
if (jobPrefab != null) jobPreferences.Add(jobPrefab);
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.characterInfo = new CharacterInfo(Character.HumanConfigFile, sender.name, gender);
|
sender.CharacterInfo = new CharacterInfo(Character.HumanConfigFile, sender.Name, gender);
|
||||||
sender.characterInfo.HeadSpriteId = headSpriteId;
|
sender.CharacterInfo.HeadSpriteId = headSpriteId;
|
||||||
sender.jobPreferences = jobPreferences;
|
sender.JobPreferences = jobPreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AssignJobs(List<Client> unassigned, bool assignHost)
|
public void AssignJobs(List<Client> unassigned, bool assignHost)
|
||||||
@@ -2049,8 +2054,8 @@ namespace Barotrauma.Networking
|
|||||||
//if any of the players has chosen a job that is Always Allowed, give them that job
|
//if any of the players has chosen a job that is Always Allowed, give them that job
|
||||||
for (int i = unassigned.Count - 1; i >= 0; i--)
|
for (int i = unassigned.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (!unassigned[i].jobPreferences[0].AllowAlways) continue;
|
if (!unassigned[i].JobPreferences[0].AllowAlways) continue;
|
||||||
unassigned[i].assignedJob = unassigned[i].jobPreferences[0];
|
unassigned[i].AssignedJob = unassigned[i].JobPreferences[0];
|
||||||
unassigned.RemoveAt(i);
|
unassigned.RemoveAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2068,7 +2073,7 @@ namespace Barotrauma.Networking
|
|||||||
//find the client that wants the job the most, or force it to random client if none of them want it
|
//find the client that wants the job the most, or force it to random client if none of them want it
|
||||||
Client assignedClient = FindClientWithJobPreference(unassigned, jobPrefab, true);
|
Client assignedClient = FindClientWithJobPreference(unassigned, jobPrefab, true);
|
||||||
|
|
||||||
assignedClient.assignedJob = jobPrefab;
|
assignedClient.AssignedJob = jobPrefab;
|
||||||
assignedClientCount[jobPrefab]++;
|
assignedClientCount[jobPrefab]++;
|
||||||
unassigned.Remove(assignedClient);
|
unassigned.Remove(assignedClient);
|
||||||
|
|
||||||
@@ -2080,18 +2085,18 @@ namespace Barotrauma.Networking
|
|||||||
//find a suitable job for the rest of the players
|
//find a suitable job for the rest of the players
|
||||||
foreach (Client c in unassigned)
|
foreach (Client c in unassigned)
|
||||||
{
|
{
|
||||||
foreach (JobPrefab preferredJob in c.jobPreferences)
|
foreach (JobPrefab preferredJob in c.JobPreferences)
|
||||||
{
|
{
|
||||||
//the maximum number of players that can have this job hasn't been reached yet
|
//the maximum number of players that can have this job hasn't been reached yet
|
||||||
// -> assign it to the client
|
// -> assign it to the client
|
||||||
if (assignedClientCount[preferredJob] < preferredJob.MaxNumber)
|
if (assignedClientCount[preferredJob] < preferredJob.MaxNumber)
|
||||||
{
|
{
|
||||||
c.assignedJob = preferredJob;
|
c.AssignedJob = preferredJob;
|
||||||
assignedClientCount[preferredJob]++;
|
assignedClientCount[preferredJob]++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//none of the jobs the client prefers are available anymore
|
//none of the jobs the client prefers are available anymore
|
||||||
else if (preferredJob == c.jobPreferences.Last())
|
else if (preferredJob == c.JobPreferences.Last())
|
||||||
{
|
{
|
||||||
//find all jobs that are still available
|
//find all jobs that are still available
|
||||||
var remainingJobs = JobPrefab.List.FindAll(jp => assignedClientCount[preferredJob] < jp.MaxNumber);
|
var remainingJobs = JobPrefab.List.FindAll(jp => assignedClientCount[preferredJob] < jp.MaxNumber);
|
||||||
@@ -2099,14 +2104,14 @@ namespace Barotrauma.Networking
|
|||||||
//all jobs taken, give a random job
|
//all jobs taken, give a random job
|
||||||
if (remainingJobs.Count == 0)
|
if (remainingJobs.Count == 0)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Failed to assign a suitable job for \"" + c.name + "\" (all jobs already have the maximum numbers of players). Assigning a random job...");
|
DebugConsole.ThrowError("Failed to assign a suitable job for \"" + c.Name + "\" (all jobs already have the maximum numbers of players). Assigning a random job...");
|
||||||
c.assignedJob = JobPrefab.List[Rand.Range(0, JobPrefab.List.Count)];
|
c.AssignedJob = JobPrefab.List[Rand.Range(0, JobPrefab.List.Count)];
|
||||||
assignedClientCount[c.assignedJob]++;
|
assignedClientCount[c.AssignedJob]++;
|
||||||
}
|
}
|
||||||
else //some jobs still left, choose one of them by random
|
else //some jobs still left, choose one of them by random
|
||||||
{
|
{
|
||||||
c.assignedJob = remainingJobs[Rand.Range(0, remainingJobs.Count)];
|
c.AssignedJob = remainingJobs[Rand.Range(0, remainingJobs.Count)];
|
||||||
assignedClientCount[c.assignedJob]++;
|
assignedClientCount[c.AssignedJob]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2119,7 +2124,7 @@ namespace Barotrauma.Networking
|
|||||||
Client preferredClient = null;
|
Client preferredClient = null;
|
||||||
foreach (Client c in clients)
|
foreach (Client c in clients)
|
||||||
{
|
{
|
||||||
int index = c.jobPreferences.IndexOf(job);
|
int index = c.JobPreferences.IndexOf(job);
|
||||||
if (index == -1) index = 1000;
|
if (index == -1) index = 1000;
|
||||||
|
|
||||||
if (preferredClient == null || index < bestPreference)
|
if (preferredClient == null || index < bestPreference)
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ namespace Barotrauma.Networking
|
|||||||
DebugConsole.NewMessage(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (name taken by the server)", Color.Red);
|
DebugConsole.NewMessage(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (name taken by the server)", Color.Red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Client nameTaken = ConnectedClients.Find(c => c.name.ToLower() == clName.ToLower());
|
Client nameTaken = ConnectedClients.Find(c => c.Name.ToLower() == clName.ToLower());
|
||||||
if (nameTaken != null)
|
if (nameTaken != null)
|
||||||
{
|
{
|
||||||
if (nameTaken.Connection.RemoteEndPoint.Address.ToString() == inc.SenderEndPoint.Address.ToString())
|
if (nameTaken.Connection.RemoteEndPoint.Address.ToString() == inc.SenderEndPoint.Address.ToString())
|
||||||
@@ -211,7 +211,7 @@ namespace Barotrauma.Networking
|
|||||||
ConnectedClients.Add(newClient);
|
ConnectedClients.Add(newClient);
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
GameMain.NetLobbyScreen.AddPlayer(newClient.name);
|
GameMain.NetLobbyScreen.AddPlayer(newClient.Name);
|
||||||
#endif
|
#endif
|
||||||
GameMain.Server.SendChatMessage(clName + " has joined the server.", ChatMessageType.Server, null);
|
GameMain.Server.SendChatMessage(clName + " has joined the server.", ChatMessageType.Server, null);
|
||||||
|
|
||||||
|
|||||||
+19
-19
@@ -82,7 +82,7 @@ namespace Barotrauma.Networking
|
|||||||
//keep at least one event in the list (lastSentToAll == e.ID) so we can use it to keep track of the latest ID
|
//keep at least one event in the list (lastSentToAll == e.ID) so we can use it to keep track of the latest ID
|
||||||
events.RemoveAll(e => NetIdUtils.IdMoreRecent(lastSentToAll, e.ID));
|
events.RemoveAll(e => NetIdUtils.IdMoreRecent(lastSentToAll, e.ID));
|
||||||
|
|
||||||
if (server.ConnectedClients.Count(c => c.inGame) == 0 && events.Count > 1)
|
if (server.ConnectedClients.Count(c => c.InGame) == 0 && events.Count > 1)
|
||||||
{
|
{
|
||||||
events.RemoveRange(0, events.Count - 1);
|
events.RemoveRange(0, events.Count - 1);
|
||||||
}
|
}
|
||||||
@@ -144,21 +144,21 @@ namespace Barotrauma.Networking
|
|||||||
bufferedEvent.IsProcessed = true;
|
bufferedEvent.IsProcessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var inGameClients = clients.FindAll(c => c.inGame && !c.NeedsMidRoundSync);
|
var inGameClients = clients.FindAll(c => c.InGame && !c.NeedsMidRoundSync);
|
||||||
if (inGameClients.Count > 0)
|
if (inGameClients.Count > 0)
|
||||||
{
|
{
|
||||||
lastSentToAll = inGameClients[0].lastRecvEntityEventID;
|
lastSentToAll = inGameClients[0].LastRecvEntityEventID;
|
||||||
inGameClients.ForEach(c => { if (NetIdUtils.IdMoreRecent(lastSentToAll, c.lastRecvEntityEventID)) lastSentToAll = c.lastRecvEntityEventID; });
|
inGameClients.ForEach(c => { if (NetIdUtils.IdMoreRecent(lastSentToAll, c.LastRecvEntityEventID)) lastSentToAll = c.LastRecvEntityEventID; });
|
||||||
|
|
||||||
ServerEntityEvent firstEventToResend = events.Find(e => e.ID == (ushort)(lastSentToAll + 1));
|
ServerEntityEvent firstEventToResend = events.Find(e => e.ID == (ushort)(lastSentToAll + 1));
|
||||||
if (firstEventToResend != null && (Timing.TotalTime - firstEventToResend.CreateTime) > 10.0f)
|
if (firstEventToResend != null && (Timing.TotalTime - firstEventToResend.CreateTime) > 10.0f)
|
||||||
{
|
{
|
||||||
//it's been 10 seconds since this event was created
|
//it's been 10 seconds since this event was created
|
||||||
//kick everyone that hasn't received it yet, this is way too old
|
//kick everyone that hasn't received it yet, this is way too old
|
||||||
List<Client> toKick = inGameClients.FindAll(c => NetIdUtils.IdMoreRecent((UInt16)(lastSentToAll + 1), c.lastRecvEntityEventID));
|
List<Client> toKick = inGameClients.FindAll(c => NetIdUtils.IdMoreRecent((UInt16)(lastSentToAll + 1), c.LastRecvEntityEventID));
|
||||||
toKick.ForEach(c =>
|
toKick.ForEach(c =>
|
||||||
{
|
{
|
||||||
DebugConsole.NewMessage(c.name + " was kicked due to excessive desync (expected old event " + c.lastRecvEntityEventID.ToString() + ")", Microsoft.Xna.Framework.Color.Red);
|
DebugConsole.NewMessage(c.Name + " was kicked due to excessive desync (expected old event " + c.LastRecvEntityEventID.ToString() + ")", Microsoft.Xna.Framework.Color.Red);
|
||||||
server.DisconnectClient(c, "", "You have been disconnected because of excessive desync");
|
server.DisconnectClient(c, "", "You have been disconnected because of excessive desync");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -168,17 +168,17 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
//the client is waiting for an event that we don't have anymore
|
//the client is waiting for an event that we don't have anymore
|
||||||
//(the ID they're expecting is smaller than the ID of the first event in our list)
|
//(the ID they're expecting is smaller than the ID of the first event in our list)
|
||||||
List<Client> toKick = inGameClients.FindAll(c => NetIdUtils.IdMoreRecent(events[0].ID, (UInt16)(c.lastRecvEntityEventID + 1)));
|
List<Client> toKick = inGameClients.FindAll(c => NetIdUtils.IdMoreRecent(events[0].ID, (UInt16)(c.LastRecvEntityEventID + 1)));
|
||||||
toKick.ForEach(c =>
|
toKick.ForEach(c =>
|
||||||
{
|
{
|
||||||
DebugConsole.NewMessage(c.name + " was kicked due to excessive desync (expected " + c.lastRecvEntityEventID.ToString() + ", last available is " + events[0].ID.ToString() + ")", Microsoft.Xna.Framework.Color.Red);
|
DebugConsole.NewMessage(c.Name + " was kicked due to excessive desync (expected " + c.LastRecvEntityEventID.ToString() + ", last available is " + events[0].ID.ToString() + ")", Microsoft.Xna.Framework.Color.Red);
|
||||||
server.DisconnectClient(c, "", "You have been disconnected because of excessive desync");
|
server.DisconnectClient(c, "", "You have been disconnected because of excessive desync");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var timedOutClients = clients.FindAll(c => c.inGame && c.NeedsMidRoundSync && Timing.TotalTime > c.MidRoundSyncTimeOut);
|
var timedOutClients = clients.FindAll(c => c.InGame && c.NeedsMidRoundSync && Timing.TotalTime > c.MidRoundSyncTimeOut);
|
||||||
timedOutClients.ForEach(c => GameMain.Server.DisconnectClient(c, "", "You have been disconnected because syncing your client with the server took too long."));
|
timedOutClients.ForEach(c => GameMain.Server.DisconnectClient(c, "", "You have been disconnected because syncing your client with the server took too long."));
|
||||||
|
|
||||||
bufferedEvents.RemoveAll(b => b.IsProcessed);
|
bufferedEvents.RemoveAll(b => b.IsProcessed);
|
||||||
@@ -225,7 +225,7 @@ namespace Barotrauma.Networking
|
|||||||
foreach (NetEntityEvent entityEvent in eventsToSync)
|
foreach (NetEntityEvent entityEvent in eventsToSync)
|
||||||
{
|
{
|
||||||
(entityEvent as ServerEntityEvent).Sent = true;
|
(entityEvent as ServerEntityEvent).Sent = true;
|
||||||
client.entityEventLastSent[entityEvent.ID] = (float)NetTime.Now;
|
client.EntityEventLastSent[entityEvent.ID] = (float)NetTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.NeedsMidRoundSync)
|
if (client.NeedsMidRoundSync)
|
||||||
@@ -265,7 +265,7 @@ namespace Barotrauma.Networking
|
|||||||
//find the index of the first event the client hasn't received
|
//find the index of the first event the client hasn't received
|
||||||
int startIndex = eventList.Count;
|
int startIndex = eventList.Count;
|
||||||
while (startIndex > 0 &&
|
while (startIndex > 0 &&
|
||||||
NetIdUtils.IdMoreRecent(eventList[startIndex - 1].ID,client.lastRecvEntityEventID))
|
NetIdUtils.IdMoreRecent(eventList[startIndex - 1].ID,client.LastRecvEntityEventID))
|
||||||
{
|
{
|
||||||
startIndex--;
|
startIndex--;
|
||||||
}
|
}
|
||||||
@@ -274,7 +274,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
//find the first event that hasn't been sent in 1.5 * roundtriptime or at all
|
//find the first event that hasn't been sent in 1.5 * roundtriptime or at all
|
||||||
float lastSent = 0;
|
float lastSent = 0;
|
||||||
client.entityEventLastSent.TryGetValue(eventList[i].ID, out lastSent);
|
client.EntityEventLastSent.TryGetValue(eventList[i].ID, out lastSent);
|
||||||
|
|
||||||
if (lastSent > NetTime.Now - client.Connection.AverageRoundtripTime * 1.5f)
|
if (lastSent > NetTime.Now - client.Connection.AverageRoundtripTime * 1.5f)
|
||||||
{
|
{
|
||||||
@@ -326,7 +326,7 @@ namespace Barotrauma.Networking
|
|||||||
if (entityID == 0)
|
if (entityID == 0)
|
||||||
{
|
{
|
||||||
msg.ReadPadBits();
|
msg.ReadPadBits();
|
||||||
sender.lastSentEntityEventID++;
|
sender.LastSentEntityEventID++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,11 +335,11 @@ namespace Barotrauma.Networking
|
|||||||
IClientSerializable entity = Entity.FindEntityByID(entityID) as IClientSerializable;
|
IClientSerializable entity = Entity.FindEntityByID(entityID) as IClientSerializable;
|
||||||
|
|
||||||
//skip the event if we've already received it or if the entity isn't found
|
//skip the event if we've already received it or if the entity isn't found
|
||||||
if (thisEventID != (UInt16)(sender.lastSentEntityEventID + 1) || entity == null)
|
if (thisEventID != (UInt16)(sender.LastSentEntityEventID + 1) || entity == null)
|
||||||
{
|
{
|
||||||
if (GameSettings.VerboseLogging)
|
if (GameSettings.VerboseLogging)
|
||||||
{
|
{
|
||||||
if (thisEventID != (UInt16) (sender.lastSentEntityEventID + 1))
|
if (thisEventID != (UInt16) (sender.LastSentEntityEventID + 1))
|
||||||
{
|
{
|
||||||
DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Red);
|
DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Red);
|
||||||
}
|
}
|
||||||
@@ -365,7 +365,7 @@ namespace Barotrauma.Networking
|
|||||||
buffer.Write(msg.ReadBytes(msgLength - 2));
|
buffer.Write(msg.ReadBytes(msgLength - 2));
|
||||||
BufferEvent(new BufferedEvent(sender, sender.Character, characterStateID, entity, buffer));
|
BufferEvent(new BufferedEvent(sender, sender.Character, characterStateID, entity, buffer));
|
||||||
|
|
||||||
sender.lastSentEntityEventID++;
|
sender.LastSentEntityEventID++;
|
||||||
}
|
}
|
||||||
msg.ReadPadBits();
|
msg.ReadPadBits();
|
||||||
}
|
}
|
||||||
@@ -400,9 +400,9 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
foreach (Client c in server.ConnectedClients)
|
foreach (Client c in server.ConnectedClients)
|
||||||
{
|
{
|
||||||
c.entityEventLastSent.Clear();
|
c.EntityEventLastSent.Clear();
|
||||||
c.lastRecvEntityEventID = 0;
|
c.LastRecvEntityEventID = 0;
|
||||||
c.lastSentEntityEventID = 0;
|
c.LastSentEntityEventID = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ namespace Barotrauma.Networking
|
|||||||
private List<Client> GetClientsToRespawn()
|
private List<Client> GetClientsToRespawn()
|
||||||
{
|
{
|
||||||
return networkMember.ConnectedClients.FindAll(c =>
|
return networkMember.ConnectedClients.FindAll(c =>
|
||||||
c.inGame &&
|
c.InGame &&
|
||||||
(!c.SpectateOnly || !((GameServer)networkMember).AllowSpectating) &&
|
(!c.SpectateOnly || !((GameServer)networkMember).AllowSpectating) &&
|
||||||
(c.Character == null || c.Character.IsDead));
|
(c.Character == null || c.Character.IsDead));
|
||||||
}
|
}
|
||||||
@@ -408,10 +408,10 @@ namespace Barotrauma.Networking
|
|||||||
//all characters are in Team 1 in game modes/missions with only one team.
|
//all characters are in Team 1 in game modes/missions with only one team.
|
||||||
//if at some point we add a game mode with multiple teams where respawning is possible, this needs to be reworked
|
//if at some point we add a game mode with multiple teams where respawning is possible, this needs to be reworked
|
||||||
c.TeamID = 1;
|
c.TeamID = 1;
|
||||||
if (c.characterInfo == null) c.characterInfo = new CharacterInfo(Character.HumanConfigFile, c.name);
|
if (c.CharacterInfo == null) c.CharacterInfo = new CharacterInfo(Character.HumanConfigFile, c.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CharacterInfo> characterInfos = clients.Select(c => c.characterInfo).ToList();
|
List<CharacterInfo> characterInfos = clients.Select(c => c.CharacterInfo).ToList();
|
||||||
if (server.Character != null && server.Character.IsDead)
|
if (server.Character != null && server.Character.IsDead)
|
||||||
{
|
{
|
||||||
characterInfos.Add(server.CharacterInfo);
|
characterInfos.Add(server.CharacterInfo);
|
||||||
@@ -420,7 +420,7 @@ namespace Barotrauma.Networking
|
|||||||
server.AssignJobs(clients, server.Character != null && server.Character.IsDead);
|
server.AssignJobs(clients, server.Character != null && server.Character.IsDead);
|
||||||
foreach (Client c in clients)
|
foreach (Client c in clients)
|
||||||
{
|
{
|
||||||
c.characterInfo.Job = new Job(c.assignedJob);
|
c.CharacterInfo.Job = new Job(c.AssignedJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
//the spawnpoints where the characters will spawn
|
//the spawnpoints where the characters will spawn
|
||||||
@@ -460,7 +460,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
clients[i].Character = character;
|
clients[i].Character = character;
|
||||||
GameServer.Log(string.Format("Respawning {0} ({1}) as {2}", clients[i].name, clients[i].Connection?.RemoteEndPoint?.Address, characterInfos[i].Job.Name), ServerLog.MessageType.Spawning);
|
GameServer.Log(string.Format("Respawning {0} ({1}) as {2}", clients[i].Name, clients[i].Connection?.RemoteEndPoint?.Address, characterInfos[i].Job.Name), ServerLog.MessageType.Spawning);
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ namespace Barotrauma
|
|||||||
kicked.AddKickVote(sender);
|
kicked.AddKickVote(sender);
|
||||||
Client.UpdateKickVotes(GameMain.Server.ConnectedClients);
|
Client.UpdateKickVotes(GameMain.Server.ConnectedClients);
|
||||||
|
|
||||||
GameMain.Server.SendChatMessage(sender.name + " has voted to kick " + kicked.name, ChatMessageType.Server, null);
|
GameMain.Server.SendChatMessage(sender.Name + " has voted to kick " + kicked.Name, ChatMessageType.Server, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user