- Fixed some properties in GameServerSettings not being saved due to being private.

- Fixed serversettings.xml overriding the settings entered in the "host server" menu in the client project.
- Added a default serversettings.xml file.

TODO: either add an error/warning of some sort if trying to use any of the ObjectProperty attributes on a non-public property or make ObjectProperty compatible with private properties. + Refactor Properties.cs, class/method naming in particular.
This commit is contained in:
Joonas Rikkonen
2017-07-20 21:03:00 +03:00
parent d694c7efdc
commit ce3a8df9e0
7 changed files with 55 additions and 39 deletions

View File

@@ -102,7 +102,7 @@ namespace Barotrauma
XDocument doc = ToolBox.TryLoadXml(GameServer.SettingsFile);
if (doc == null)
{
DebugConsole.ThrowError("File \""+GameServer.SettingsFile+"\" not found. Starting the server with default settings.");
DebugConsole.ThrowError("File \"" + GameServer.SettingsFile + "\" not found. Starting the server with default settings.");
Server = new GameServer("Server", 14242, false, "", false, 10);
return;
}
@@ -112,7 +112,7 @@ namespace Barotrauma
ToolBox.GetAttributeInt(doc.Root, "port", 14242),
ToolBox.GetAttributeBool(doc.Root, "public", false),
ToolBox.GetAttributeString(doc.Root, "password", ""),
ToolBox.GetAttributeBool(doc.Root, "attemptupnp", false),
ToolBox.GetAttributeBool(doc.Root, "enableupnp", false),
ToolBox.GetAttributeInt(doc.Root, "maxplayers", 10));
}

View File

@@ -734,6 +734,9 @@
<Content Include="$(MSBuildThisFileDirectory)serverconfig.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(MSBuildThisFileDirectory)serversettings.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)Content\blurshader.xnb">

View File

@@ -76,7 +76,8 @@ namespace Barotrauma.Networking
AdminAuthPass = "";
this.name = name;
this.Public = isPublic;
this.isPublic = isPublic;
this.maxPlayers = maxPlayers;
this.password = "";
if (password.Length>0)
{
@@ -107,14 +108,13 @@ namespace Barotrauma.Networking
config.EnableUPnP = true;
}
config.MaximumConnections = maxPlayers*2; //double the lidgren connections for unauthenticated players
MaxPlayers = maxPlayers;
config.MaximumConnections = maxPlayers * 2; //double the lidgren connections for unauthenticated players
config.DisableMessageType(NetIncomingMessageType.DebugMessage |
config.DisableMessageType(NetIncomingMessageType.DebugMessage |
NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt |
NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error |
NetIncomingMessageType.UnconnectedData);
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
log = new ServerLog(name);
@@ -229,7 +229,7 @@ namespace Barotrauma.Networking
request.AddParameter("servername", name);
request.AddParameter("serverport", Port);
request.AddParameter("currplayers", connectedClients.Count);
request.AddParameter("maxplayers", MaxPlayers);
request.AddParameter("maxplayers", maxPlayers);
request.AddParameter("password", string.IsNullOrWhiteSpace(password) ? 0 : 1);
request.AddParameter("version", GameMain.Version.ToString());
if (GameMain.Config.SelectedContentPackage != null)
@@ -284,7 +284,7 @@ namespace Barotrauma.Networking
request.AddParameter("serverport", Port);
request.AddParameter("gamestarted", gameStarted ? 1 : 0);
request.AddParameter("currplayers", connectedClients.Count);
request.AddParameter("maxplayers", MaxPlayers);
request.AddParameter("maxplayers", maxPlayers);
Log("Refreshing connection with master server...", ServerLog.MessageType.ServerMessage);
@@ -469,7 +469,7 @@ namespace Barotrauma.Networking
{
inc.SenderConnection.Deny("You have been banned from the server");
}
else if (ConnectedClients.Count >= MaxPlayers)
else if (ConnectedClients.Count >= maxPlayers)
{
inc.SenderConnection.Deny("Server full");
}

View File

@@ -43,7 +43,7 @@ namespace Barotrauma.Networking
if (unauthClient == null)
{
//new client, generate nonce and add to unauth queue
if (ConnectedClients.Count >= MaxPlayers)
if (ConnectedClients.Count >= maxPlayers)
{
//server is full, can't allow new connection
conn.Disconnect("Server full");

View File

@@ -80,8 +80,12 @@ namespace Barotrauma.Networking
private bool autoRestart;
private List<SavedClientPermission> clientPermissions = new List<SavedClientPermission>();
private bool isPublic;
private int maxPlayers;
private List<SavedClientPermission> clientPermissions = new List<SavedClientPermission>();
[HasDefaultValue(true, true)]
public bool RandomizeSeed
{
@@ -170,41 +174,20 @@ namespace Barotrauma.Networking
AutoRestartTimer = autoRestart ? AutoRestartInterval : 0.0f;
}
}
[HasDefaultValue(8, true)]
private int MaxPlayers
[HasDefaultValue(true, true)]
public bool AllowRespawn
{
get;
set;
}
[HasDefaultValue(false, true)]
private bool Public
{
get;
set;
}
[HasDefaultValue(false, true)]
private bool AttemptUPNP
{
get { return config.EnableUPnP; }
set { config.EnableUPnP = value; }
}
public YesNoMaybe TraitorsEnabled
{
get;
set;
}
[HasDefaultValue(true, true)]
public bool AllowRespawn
{
get;
set;
}
public SelectionMode SubSelectionMode
{
get { return subSelectionMode; }
@@ -246,6 +229,12 @@ namespace Barotrauma.Networking
XDocument doc = new XDocument(new XElement("serversettings"));
ObjectProperty.SaveProperties(this, doc.Root, true);
doc.Root.SetAttributeValue("name", name);
doc.Root.SetAttributeValue("public", isPublic);
doc.Root.SetAttributeValue("port", config.Port);
doc.Root.SetAttributeValue("maxplayers", maxPlayers);
doc.Root.SetAttributeValue("enableupnp", config.EnableUPnP);
doc.Root.SetAttributeValue("SubSelection", subSelectionMode.ToString());
doc.Root.SetAttributeValue("ModeSelection", modeSelectionMode.ToString());

View File

@@ -91,14 +91,12 @@ namespace Barotrauma.Networking
public Voting Voting;
[HasDefaultValue(14242, true)]
public int Port
{
get;
set;
}
[HasDefaultValue("", true)]
public string Name
{
get { return name; }

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<serversettings
name="Server"
ServerMessage=""
port="14242"
password=""
public="True"
maxplayers="10"
attemptupnp="false"
randomizeseed="True"
respawninterval="300"
maxtransporttime="180"
minrespawnratio="0.2"
autorestartinterval="60"
allowspectating="True"
endroundatlevelend="True"
saveserverlogs="True"
allowfiletransfers="True"
allowrespawn="True"
allowvotekick="True"
endvoterequiredratio="0.6"
kickvoterequiredratio="0.6"
SubSelection="Manual"
ModeSelection="Manual"
TraitorsEnabled="No"
/>