(ded4a3e0a) v0.9.0.7
This commit is contained in:
@@ -165,13 +165,27 @@ namespace Barotrauma.Networking
|
||||
expirationTime = DateTime.Now + duration.Value;
|
||||
}
|
||||
|
||||
bannedPlayers.Add(new BannedPlayer(name, ip, reason, expirationTime));
|
||||
if (!string.IsNullOrEmpty(ip))
|
||||
{
|
||||
bannedPlayers.Add(new BannedPlayer(name, ip, reason, expirationTime));
|
||||
}
|
||||
else if (steamID > 0)
|
||||
{
|
||||
bannedPlayers.Add(new BannedPlayer(name, steamID, reason, expirationTime));
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to ban a client (no valid IP or Steam ID given)");
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
public void UnbanPlayer(string name)
|
||||
{
|
||||
var player = bannedPlayers.Find(bp => bp.Name == name);
|
||||
name = name.ToLower();
|
||||
var player = bannedPlayers.Find(bp => bp.Name.ToLower() == name);
|
||||
if (player == null)
|
||||
{
|
||||
DebugConsole.Log("Could not unban player \"" + name + "\". Matching player not found.");
|
||||
|
||||
@@ -26,6 +26,10 @@ namespace Barotrauma.Networking
|
||||
//for keeping track of disconnected clients in case the reconnect shortly after
|
||||
private List<Client> disconnectedClients = new List<Client>();
|
||||
|
||||
//keeps track of players who've previously been playing on the server
|
||||
//so kick votes persist during the session and the server can let the clients know what name this client used previously
|
||||
private readonly List<PreviousPlayer> previousPlayers = new List<PreviousPlayer>();
|
||||
|
||||
private int roundStartSeed;
|
||||
|
||||
//is the server running
|
||||
@@ -34,7 +38,7 @@ namespace Barotrauma.Networking
|
||||
private NetServer server;
|
||||
|
||||
private DateTime refreshMasterTimer;
|
||||
private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 30);
|
||||
private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 60);
|
||||
private bool registeredToMaster;
|
||||
|
||||
private DateTime roundStartTime;
|
||||
@@ -657,23 +661,25 @@ namespace Barotrauma.Networking
|
||||
updateTimer = DateTime.Now + updateInterval;
|
||||
}
|
||||
|
||||
if (!registeredToMaster || refreshMasterTimer >= DateTime.Now) return;
|
||||
|
||||
if (GameMain.Config.UseSteamMatchmaking)
|
||||
if (registeredToMaster && (DateTime.Now > refreshMasterTimer || serverSettings.ServerDetailsChanged))
|
||||
{
|
||||
bool refreshSuccessful = SteamManager.RefreshServerDetails(this);
|
||||
if (GameSettings.VerboseLogging)
|
||||
if (GameMain.Config.UseSteamMatchmaking)
|
||||
{
|
||||
Log(refreshSuccessful ?
|
||||
"Refreshed server info on the server list." :
|
||||
"Refreshing server info on the server list failed.", ServerLog.MessageType.ServerMessage);
|
||||
bool refreshSuccessful = SteamManager.RefreshServerDetails(this);
|
||||
if (GameSettings.VerboseLogging)
|
||||
{
|
||||
Log(refreshSuccessful ?
|
||||
"Refreshed server info on the server list." :
|
||||
"Refreshing server info on the server list failed.", ServerLog.MessageType.ServerMessage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CoroutineManager.StartCoroutine(RefreshMaster());
|
||||
}
|
||||
refreshMasterTimer = DateTime.Now + refreshMasterInterval;
|
||||
serverSettings.ServerDetailsChanged = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
CoroutineManager.StartCoroutine(RefreshMaster());
|
||||
}
|
||||
refreshMasterTimer = DateTime.Now + refreshMasterInterval;
|
||||
}
|
||||
|
||||
private void ReadDataMessage(NetIncomingMessage inc)
|
||||
@@ -724,7 +730,7 @@ namespace Barotrauma.Networking
|
||||
bool isNew = inc.ReadBoolean(); inc.ReadPadBits();
|
||||
if (isNew)
|
||||
{
|
||||
string savePath = inc.ReadString();
|
||||
string saveName = inc.ReadString();
|
||||
string seed = inc.ReadString();
|
||||
string subName = inc.ReadString();
|
||||
string subHash = inc.ReadString();
|
||||
@@ -739,7 +745,11 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
if (connectedClient.HasPermission(ClientPermissions.SelectMode)) MultiPlayerCampaign.StartNewCampaign(savePath, matchingSub.FilePath, seed);
|
||||
string localSavePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveName);
|
||||
if (connectedClient.HasPermission(ClientPermissions.SelectMode))
|
||||
{
|
||||
MultiPlayerCampaign.StartNewCampaign(localSavePath, matchingSub.FilePath, seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -2182,7 +2192,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
public override void UnbanPlayer(string playerName, string playerIP)
|
||||
{
|
||||
playerName = playerName.ToLowerInvariant();
|
||||
if (!string.IsNullOrEmpty(playerIP))
|
||||
{
|
||||
serverSettings.BanList.UnbanIP(playerIP);
|
||||
@@ -2230,6 +2239,19 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (client.SteamID > 0) { SteamManager.StopAuthSession(client.SteamID); }
|
||||
|
||||
var previousPlayer = previousPlayers.Find(p => p.MatchesClient(client));
|
||||
if (previousPlayer == null)
|
||||
{
|
||||
previousPlayer = new PreviousPlayer(client);
|
||||
previousPlayers.Add(previousPlayer);
|
||||
}
|
||||
previousPlayer.Name = client.Name;
|
||||
previousPlayer.KickVoters.Clear();
|
||||
foreach (Client c in connectedClients)
|
||||
{
|
||||
if (client.HasKickVoteFrom(c)) { previousPlayer.KickVoters.Add(c); }
|
||||
}
|
||||
|
||||
client.Connection.Disconnect(targetmsg);
|
||||
client.Dispose();
|
||||
connectedClients.Remove(client);
|
||||
@@ -2240,6 +2262,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
UpdateCrewFrame();
|
||||
|
||||
serverSettings.ServerDetailsChanged = true;
|
||||
refreshMasterTimer = DateTime.Now;
|
||||
}
|
||||
|
||||
@@ -2558,6 +2581,13 @@ namespace Barotrauma.Networking
|
||||
c.KickVoteCount >= connectedClients.Count * serverSettings.KickVoteRequiredRatio);
|
||||
foreach (Client c in clientsToKick)
|
||||
{
|
||||
var previousPlayer = previousPlayers.Find(p => p.MatchesClient(c));
|
||||
if (previousPlayer != null)
|
||||
{
|
||||
//reset the client's kick votes (they can rejoin after their ban expires)
|
||||
previousPlayer.KickVoters.Clear();
|
||||
}
|
||||
|
||||
SendChatMessage($"ServerMessage.KickedFromServer~[client]={c.Name}", ChatMessageType.Server, null);
|
||||
KickClient(c, "ServerMessage.KickedByVote");
|
||||
BanClient(c, "ServerMessage.KickedByVoteAutoBan", duration: TimeSpan.FromSeconds(serverSettings.AutoBanTime));
|
||||
@@ -3030,4 +3060,25 @@ namespace Barotrauma.Networking
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
|
||||
partial class PreviousPlayer
|
||||
{
|
||||
public string Name;
|
||||
public string IP;
|
||||
public UInt64 SteamID;
|
||||
public readonly List<Client> KickVoters = new List<Client>();
|
||||
|
||||
public PreviousPlayer(Client c)
|
||||
{
|
||||
Name = c.Name;
|
||||
IP = c.Connection?.RemoteEndPoint?.Address?.ToString() ?? "";
|
||||
SteamID = c.SteamID;
|
||||
}
|
||||
|
||||
public bool MatchesClient(Client c)
|
||||
{
|
||||
if (c.SteamID > 0 && SteamID > 0) { return c.SteamID == SteamID; }
|
||||
return c.IPMatches(IP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ namespace Barotrauma.Networking
|
||||
return "\"" + nameAndHash.First + "\" (hash " + Md5Hash.GetShortHash(nameAndHash.Second) + ")";
|
||||
}
|
||||
|
||||
if (!serverSettings.Whitelist.IsWhiteListed(clName, inc.SenderConnection.RemoteEndPoint.Address))
|
||||
if (inc.SenderConnection != OwnerConnection && !serverSettings.Whitelist.IsWhiteListed(clName, inc.SenderConnection.RemoteEndPoint.Address))
|
||||
{
|
||||
DisconnectUnauthClient(inc, unauthClient, DisconnectReason.NotOnWhitelist, "");
|
||||
Log(clName + " (" + inc.SenderConnection.RemoteEndPoint.Address.ToString() + ") couldn't join the server (not in whitelist)", ServerLog.MessageType.Error);
|
||||
@@ -470,6 +470,17 @@ namespace Barotrauma.Networking
|
||||
unauthenticatedClients.Remove(unauthClient);
|
||||
unauthClient = null;
|
||||
ConnectedClients.Add(newClient);
|
||||
|
||||
var previousPlayer = previousPlayers.Find(p => p.MatchesClient(newClient));
|
||||
if (previousPlayer != null)
|
||||
{
|
||||
foreach (Client c in previousPlayer.KickVoters)
|
||||
{
|
||||
if (!connectedClients.Contains(c)) { continue; }
|
||||
newClient.AddKickVote(c);
|
||||
}
|
||||
}
|
||||
|
||||
LastClientListUpdateID++;
|
||||
|
||||
if (newClient.Connection == OwnerConnection)
|
||||
@@ -482,6 +493,13 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
GameMain.Server.SendChatMessage($"ServerMessage.JoinedServer~[client]={clName}", ChatMessageType.Server, null);
|
||||
serverSettings.ServerDetailsChanged = true;
|
||||
|
||||
if (previousPlayer != null && previousPlayer.Name != newClient.Name)
|
||||
{
|
||||
GameMain.Server.SendChatMessage($"ServerMessage.PreviousClientName~[client]={clName}~[previousname]={previousPlayer.Name}", ChatMessageType.Server, null);
|
||||
previousPlayer.Name = newClient.Name;
|
||||
}
|
||||
|
||||
var savedPermissions = serverSettings.ClientPermissions.Find(cp =>
|
||||
cp.SteamID > 0 ?
|
||||
|
||||
@@ -42,6 +42,8 @@ namespace Barotrauma.Steam
|
||||
return false;
|
||||
}
|
||||
|
||||
var contentPackages = GameMain.Config.SelectedContentPackages.Where(cp => cp.HasMultiplayerIncompatibleContent);
|
||||
|
||||
// These server state variables may be changed at any time. Note that there is no longer a mechanism
|
||||
// to send the player count. The player count is maintained by steam and you should use the player
|
||||
// creation/authentication functions to maintain your player count.
|
||||
@@ -51,9 +53,10 @@ namespace Barotrauma.Steam
|
||||
instance.server.MapName = GameMain.NetLobbyScreen?.SelectedSub?.DisplayName ?? "";
|
||||
Instance.server.SetKey("message", GameMain.Server.ServerSettings.ServerMessageText);
|
||||
Instance.server.SetKey("version", GameMain.Version.ToString());
|
||||
Instance.server.SetKey("contentpackage", string.Join(",", GameMain.Config.SelectedContentPackages.Select(cp => cp.Name)));
|
||||
Instance.server.SetKey("contentpackagehash", string.Join(",", GameMain.Config.SelectedContentPackages.Select(cp => cp.MD5hash.Hash)));
|
||||
Instance.server.SetKey("contentpackageurl", string.Join(",", GameMain.Config.SelectedContentPackages.Select(cp => cp.SteamWorkshopUrl ?? "")));
|
||||
Instance.server.SetKey("playercount", GameMain.Server.ConnectedClients.Count.ToString());
|
||||
Instance.server.SetKey("contentpackage", string.Join(",", contentPackages.Select(cp => cp.Name)));
|
||||
Instance.server.SetKey("contentpackagehash", string.Join(",", contentPackages.Select(cp => cp.MD5hash.Hash)));
|
||||
Instance.server.SetKey("contentpackageurl", string.Join(",", contentPackages.Select(cp => cp.SteamWorkshopUrl ?? "")));
|
||||
Instance.server.SetKey("usingwhitelist", (server.ServerSettings.Whitelist != null && server.ServerSettings.Whitelist.Enabled).ToString());
|
||||
Instance.server.SetKey("modeselectionmode", server.ServerSettings.ModeSelectionMode.ToString());
|
||||
Instance.server.SetKey("subselectionmode", server.ServerSettings.SubSelectionMode.ToString());
|
||||
@@ -72,7 +75,7 @@ namespace Barotrauma.Steam
|
||||
public static bool StartAuthSession(byte[] authTicketData, ulong clientSteamID)
|
||||
{
|
||||
if (instance == null || !instance.isInitialized || instance.server == null) return false;
|
||||
|
||||
|
||||
DebugConsole.Log("SteamManager authenticating Steam client " + clientSteamID);
|
||||
if (!instance.server.Auth.StartSession(authTicketData, clientSteamID))
|
||||
{
|
||||
|
||||
@@ -77,9 +77,10 @@ namespace Barotrauma.Networking
|
||||
bool recipientSpectating = recipient.Character == null || recipient.Character.IsDead;
|
||||
bool senderSpectating = sender.Character == null || sender.Character.IsDead;
|
||||
|
||||
//spectators cannot speak with in-game players or vice versa
|
||||
//TODO: allow spectators to hear the voice chat if close enough to the speaker?
|
||||
if (recipientSpectating != senderSpectating) { return false; }
|
||||
//TODO: only allow spectators to hear the voice chat if close enough to the speaker?
|
||||
|
||||
//non-spectators cannot hear spectators
|
||||
if (senderSpectating && !recipientSpectating) { return false; }
|
||||
|
||||
//both spectating, no need to do radio/distance checks
|
||||
if (recipientSpectating && senderSpectating) { return true; }
|
||||
|
||||
@@ -25,47 +25,45 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
partial void InitProjSpecific()
|
||||
{
|
||||
if (File.Exists(SavePath))
|
||||
if (!File.Exists(SavePath)) { return; }
|
||||
|
||||
string[] lines;
|
||||
try
|
||||
{
|
||||
string[] lines;
|
||||
try
|
||||
{
|
||||
lines = File.ReadAllLines(SavePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to open whitelist in " + SavePath, e);
|
||||
return;
|
||||
}
|
||||
lines = File.ReadAllLines(SavePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to open whitelist in " + SavePath, e);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string line in lines)
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (line[0] == '#')
|
||||
{
|
||||
if (line[0] == '#')
|
||||
string lineval = line.Substring(1, line.Length - 1);
|
||||
Int32.TryParse(lineval, out int intVal);
|
||||
if (lineval.ToLower() == "true" || intVal != 0)
|
||||
{
|
||||
string lineval = line.Substring(1, line.Length - 1);
|
||||
int intVal = 0;
|
||||
Int32.TryParse(lineval, out intVal);
|
||||
if (lineval.ToLower() == "true" || intVal != 0)
|
||||
{
|
||||
Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] separatedLine = line.Split(',');
|
||||
if (separatedLine.Length < 2) continue;
|
||||
|
||||
string name = String.Join(",", separatedLine.Take(separatedLine.Length - 1));
|
||||
string ip = separatedLine.Last();
|
||||
|
||||
whitelistedPlayers.Add(new WhiteListedPlayer(name, ip));
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] separatedLine = line.Split(',');
|
||||
if (separatedLine.Length < 2) continue;
|
||||
|
||||
string name = string.Join(",", separatedLine.Take(separatedLine.Length - 1));
|
||||
string ip = separatedLine.Last();
|
||||
|
||||
whitelistedPlayers.Add(new WhiteListedPlayer(name, ip));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Save()
|
||||
@@ -119,9 +117,7 @@ namespace Barotrauma.Networking
|
||||
private void RemoveFromWhiteList(WhiteListedPlayer wlp)
|
||||
{
|
||||
GameServer.Log("Removing " + wlp.Name + " from whitelist", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
whitelistedPlayers.Remove(wlp);
|
||||
Save();
|
||||
}
|
||||
|
||||
private void AddToWhiteList(string name, string ip)
|
||||
@@ -129,7 +125,6 @@ namespace Barotrauma.Networking
|
||||
if (string.IsNullOrWhiteSpace(name)) return;
|
||||
if (whitelistedPlayers.Any(x => x.Name.ToLower() == name.ToLower() && x.IP == ip)) return;
|
||||
whitelistedPlayers.Add(new WhiteListedPlayer(name, ip));
|
||||
Save();
|
||||
}
|
||||
|
||||
public void ServerAdminWrite(NetBuffer outMsg, Client c)
|
||||
@@ -201,8 +196,10 @@ namespace Barotrauma.Networking
|
||||
GameServer.Log(c.Name + " added " + name + " to whitelist (" + ip + ")", ServerLog.MessageType.ConsoleUsage);
|
||||
AddToWhiteList(name, ip);
|
||||
}
|
||||
|
||||
return removeCount > 0 || addCount > 0 || prevEnabled!=enabled;
|
||||
|
||||
bool changed = removeCount > 0 || addCount > 0 || prevEnabled != enabled;
|
||||
if (changed) { Save(); }
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user