Added timestep accumulator to dedicated server, improved autorestart commands, added client permission commands
This commit is contained in:
@@ -340,13 +340,6 @@ namespace Barotrauma
|
||||
new GUIMessageBox("", string.Join(" ", args));
|
||||
}));
|
||||
|
||||
commands.Add(new Command("autorestart", "autorestart: Toggle autorestart on/off when hosting a server.", (string[] args) =>
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
GameMain.NetLobbyScreen.ToggleAutoRestart();
|
||||
NewMessage(GameMain.Server.AutoRestart ? "Automatic restart enabled." : "Automatic restart disabled.", Color.White);
|
||||
}));
|
||||
|
||||
commands.Add(new Command("debugdraw", "debugdraw: Toggle the debug drawing mode on/off.", (string[] args) =>
|
||||
{
|
||||
GameMain.DebugDraw = !GameMain.DebugDraw;
|
||||
|
||||
@@ -8,26 +8,11 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public enum WindowMode
|
||||
{
|
||||
Windowed, Fullscreen, BorderlessWindowed
|
||||
}
|
||||
|
||||
public partial class GameSettings
|
||||
{
|
||||
private GUIFrame settingsFrame;
|
||||
private GUIButton applyButton;
|
||||
|
||||
private float soundVolume, musicVolume;
|
||||
|
||||
private WindowMode windowMode;
|
||||
|
||||
public List<string> jobNamePreferences;
|
||||
|
||||
private KeyOrMouse[] keyMapping;
|
||||
|
||||
private bool unsavedSettings;
|
||||
|
||||
public GUIFrame SettingsFrame
|
||||
{
|
||||
get
|
||||
@@ -41,263 +26,7 @@ namespace Barotrauma
|
||||
{
|
||||
return keyMapping[(int)inputType];
|
||||
}
|
||||
|
||||
public int GraphicsWidth { get; set; }
|
||||
public int GraphicsHeight { get; set; }
|
||||
|
||||
public bool VSyncEnabled { get; set; }
|
||||
|
||||
public bool EnableSplashScreen { get; set; }
|
||||
|
||||
//public bool FullScreenEnabled { get; set; }
|
||||
|
||||
public WindowMode WindowMode
|
||||
{
|
||||
get { return windowMode; }
|
||||
set { windowMode = value; }
|
||||
}
|
||||
|
||||
public List<string> JobNamePreferences
|
||||
{
|
||||
get { return jobNamePreferences; }
|
||||
set
|
||||
{
|
||||
// Begin saving coroutine. Remove any existing save coroutines if one is running.
|
||||
if (CoroutineManager.IsCoroutineRunning("saveCoroutine")) { CoroutineManager.StopCoroutines("saveCoroutine"); }
|
||||
CoroutineManager.StartCoroutine(ApplyUnsavedChanges(), "saveCoroutine");
|
||||
|
||||
jobNamePreferences = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UnsavedSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return unsavedSettings;
|
||||
}
|
||||
private set
|
||||
{
|
||||
unsavedSettings = value;
|
||||
|
||||
if (applyButton != null)
|
||||
{
|
||||
//applyButton.Selected = unsavedSettings;
|
||||
applyButton.Enabled = unsavedSettings;
|
||||
applyButton.Text = unsavedSettings ? "Apply*" : "Apply";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float SoundVolume
|
||||
{
|
||||
get { return soundVolume; }
|
||||
set
|
||||
{
|
||||
soundVolume = MathHelper.Clamp(value, 0.0f, 1.0f);
|
||||
Sounds.SoundManager.MasterVolume = soundVolume;
|
||||
}
|
||||
}
|
||||
|
||||
public float MusicVolume
|
||||
{
|
||||
get { return musicVolume; }
|
||||
set
|
||||
{
|
||||
musicVolume = MathHelper.Clamp(value, 0.0f, 1.0f);
|
||||
SoundPlayer.MusicVolume = musicVolume;
|
||||
}
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(XDocument doc)
|
||||
{
|
||||
if (doc == null)
|
||||
{
|
||||
GraphicsWidth = 1024;
|
||||
GraphicsHeight = 678;
|
||||
|
||||
MasterServerUrl = "";
|
||||
|
||||
SelectedContentPackage = ContentPackage.list.Any() ? ContentPackage.list[0] : new ContentPackage("");
|
||||
|
||||
JobNamePreferences = new List<string>();
|
||||
foreach (JobPrefab job in JobPrefab.List)
|
||||
{
|
||||
JobNamePreferences.Add(job.Name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
XElement graphicsMode = doc.Root.Element("graphicsmode");
|
||||
GraphicsWidth = graphicsMode.GetAttributeInt("width", 0);
|
||||
GraphicsHeight = graphicsMode.GetAttributeInt("height", 0);
|
||||
VSyncEnabled = graphicsMode.GetAttributeBool("vsync", true);
|
||||
|
||||
if (GraphicsWidth == 0 || GraphicsHeight == 0)
|
||||
{
|
||||
GraphicsWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
|
||||
GraphicsHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
|
||||
}
|
||||
|
||||
//FullScreenEnabled = ToolBox.GetAttributeBool(graphicsMode, "fullscreen", true);
|
||||
|
||||
var windowModeStr = graphicsMode.GetAttributeString("displaymode", "Fullscreen");
|
||||
if (!Enum.TryParse<WindowMode>(windowModeStr, out windowMode))
|
||||
{
|
||||
windowMode = WindowMode.Fullscreen;
|
||||
}
|
||||
|
||||
SoundVolume = doc.Root.GetAttributeFloat("soundvolume", 1.0f);
|
||||
MusicVolume = doc.Root.GetAttributeFloat("musicvolume", 0.3f);
|
||||
|
||||
EnableSplashScreen = doc.Root.GetAttributeBool("enablesplashscreen", true);
|
||||
|
||||
keyMapping = new KeyOrMouse[Enum.GetNames(typeof(InputType)).Length];
|
||||
keyMapping[(int)InputType.Up] = new KeyOrMouse(Keys.W);
|
||||
keyMapping[(int)InputType.Down] = new KeyOrMouse(Keys.S);
|
||||
keyMapping[(int)InputType.Left] = new KeyOrMouse(Keys.A);
|
||||
keyMapping[(int)InputType.Right] = new KeyOrMouse(Keys.D);
|
||||
keyMapping[(int)InputType.Run] = new KeyOrMouse(Keys.LeftShift);
|
||||
|
||||
keyMapping[(int)InputType.Chat] = new KeyOrMouse(Keys.Tab);
|
||||
keyMapping[(int)InputType.RadioChat] = new KeyOrMouse(Keys.OemPipe);
|
||||
keyMapping[(int)InputType.CrewOrders] = new KeyOrMouse(Keys.C);
|
||||
|
||||
keyMapping[(int)InputType.Select] = new KeyOrMouse(Keys.E);
|
||||
|
||||
keyMapping[(int)InputType.Use] = new KeyOrMouse(0);
|
||||
keyMapping[(int)InputType.Aim] = new KeyOrMouse(1);
|
||||
|
||||
foreach (XElement subElement in doc.Root.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "keymapping":
|
||||
foreach (XAttribute attribute in subElement.Attributes())
|
||||
{
|
||||
InputType inputType;
|
||||
if (Enum.TryParse(attribute.Name.ToString(), true, out inputType))
|
||||
{
|
||||
int mouseButton;
|
||||
if (int.TryParse(attribute.Value.ToString(), out mouseButton))
|
||||
{
|
||||
keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
Keys key;
|
||||
if (Enum.TryParse(attribute.Value.ToString(), true, out key))
|
||||
{
|
||||
keyMapping[(int)inputType] = new KeyOrMouse(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "gameplay":
|
||||
JobNamePreferences = new List<string>();
|
||||
foreach (XElement ele in subElement.Element("jobpreferences").Elements("job"))
|
||||
{
|
||||
JobNamePreferences.Add(ele.GetAttributeString("name", ""));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
|
||||
{
|
||||
if (keyMapping[(int)inputType] == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Key binding for the input type \"" + inputType + " not set!");
|
||||
keyMapping[(int)inputType] = new KeyOrMouse(Keys.D1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UnsavedSettings = false;
|
||||
}
|
||||
|
||||
public void Save(string filePath)
|
||||
{
|
||||
UnsavedSettings = false;
|
||||
|
||||
XDocument doc = new XDocument();
|
||||
|
||||
if (doc.Root == null)
|
||||
{
|
||||
doc.Add(new XElement("config"));
|
||||
}
|
||||
|
||||
doc.Root.Add(
|
||||
new XAttribute("masterserverurl", MasterServerUrl),
|
||||
new XAttribute("autocheckupdates", AutoCheckUpdates),
|
||||
new XAttribute("musicvolume", musicVolume),
|
||||
new XAttribute("soundvolume", soundVolume),
|
||||
new XAttribute("verboselogging", VerboseLogging),
|
||||
new XAttribute("enablesplashscreen", EnableSplashScreen));
|
||||
|
||||
if (WasGameUpdated)
|
||||
{
|
||||
doc.Root.Add(new XAttribute("wasgameupdated", true));
|
||||
}
|
||||
|
||||
XElement gMode = doc.Root.Element("graphicsmode");
|
||||
if (gMode == null)
|
||||
{
|
||||
gMode = new XElement("graphicsmode");
|
||||
doc.Root.Add(gMode);
|
||||
}
|
||||
|
||||
if (GraphicsWidth == 0 || GraphicsHeight == 0)
|
||||
{
|
||||
gMode.ReplaceAttributes(new XAttribute("displaymode", windowMode));
|
||||
}
|
||||
else
|
||||
{
|
||||
gMode.ReplaceAttributes(
|
||||
new XAttribute("width", GraphicsWidth),
|
||||
new XAttribute("height", GraphicsHeight),
|
||||
new XAttribute("vsync", VSyncEnabled),
|
||||
new XAttribute("displaymode", windowMode));
|
||||
}
|
||||
|
||||
|
||||
if (SelectedContentPackage != null)
|
||||
{
|
||||
doc.Root.Add(new XElement("contentpackage",
|
||||
new XAttribute("path", SelectedContentPackage.Path)));
|
||||
}
|
||||
|
||||
var keyMappingElement = new XElement("keymapping");
|
||||
doc.Root.Add(keyMappingElement);
|
||||
for (int i = 0; i < keyMapping.Length; i++)
|
||||
{
|
||||
if (keyMapping[i].MouseButton == null)
|
||||
{
|
||||
keyMappingElement.Add(new XAttribute(((InputType)i).ToString(), keyMapping[i].Key));
|
||||
}
|
||||
else
|
||||
{
|
||||
keyMappingElement.Add(new XAttribute(((InputType)i).ToString(), keyMapping[i].MouseButton));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
var gameplay = new XElement("gameplay");
|
||||
|
||||
var jobPreferences = new XElement("jobpreferences");
|
||||
foreach (string jobName in JobNamePreferences)
|
||||
{
|
||||
jobPreferences.Add(new XElement("job", new XAttribute("name", jobName)));
|
||||
}
|
||||
|
||||
gameplay.Add(jobPreferences);
|
||||
doc.Root.Add(gameplay);
|
||||
|
||||
doc.Save(filePath);
|
||||
}
|
||||
|
||||
private bool ChangeSoundVolume(GUIScrollBar scrollBar, float barScroll)
|
||||
{
|
||||
UnsavedSettings = true;
|
||||
@@ -494,14 +223,7 @@ namespace Barotrauma
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
private IEnumerable<object> ApplyUnsavedChanges()
|
||||
{
|
||||
yield return new WaitForSeconds(10.0f);
|
||||
|
||||
Save("config.xml");
|
||||
}
|
||||
|
||||
|
||||
private bool ApplyClicked(GUIButton button, object userData)
|
||||
{
|
||||
Save("config.xml");
|
||||
|
||||
@@ -66,7 +66,6 @@
|
||||
<Compile Include="Source\Characters\Character.cs" />
|
||||
<Compile Include="Source\DebugConsole.cs" />
|
||||
<Compile Include="Source\GameMain.cs" />
|
||||
<Compile Include="Source\GameSettings.cs" />
|
||||
<Compile Include="Source\Items\Components\ItemComponent.cs" />
|
||||
<Compile Include="Source\Items\Components\ItemLabel.cs" />
|
||||
<Compile Include="Source\Items\Components\Machines\Steering.cs" />
|
||||
|
||||
@@ -63,12 +63,12 @@ namespace Barotrauma
|
||||
FarseerPhysics.Settings.VelocityIterations = 1;
|
||||
FarseerPhysics.Settings.PositionIterations = 1;
|
||||
|
||||
Config = new GameSettings("serverconfig.xml");
|
||||
Config = new GameSettings("config.xml");
|
||||
if (Config.WasGameUpdated)
|
||||
{
|
||||
UpdaterUtil.CleanOldFiles();
|
||||
Config.WasGameUpdated = false;
|
||||
Config.Save("serverconfig.xml");
|
||||
Config.Save("config.xml");
|
||||
}
|
||||
|
||||
GameScreen = new GameScreen();
|
||||
@@ -131,19 +131,25 @@ namespace Barotrauma
|
||||
Init();
|
||||
StartServer();
|
||||
|
||||
Timing.Accumulator = 0.0;
|
||||
|
||||
DateTime prevTime = DateTime.Now;
|
||||
|
||||
while (ShouldRun)
|
||||
{
|
||||
Timing.Accumulator += ((float)(DateTime.Now.Subtract(prevTime).Milliseconds) / 1000.0)/Timing.Step;
|
||||
prevTime = DateTime.Now;
|
||||
while (Timing.Accumulator>0.0)
|
||||
{
|
||||
DebugConsole.Update();
|
||||
if (Screen.Selected != null) Screen.Selected.Update((float)Timing.Step);
|
||||
Server.Update((float)Timing.Step);
|
||||
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
||||
|
||||
DebugConsole.Update();
|
||||
if (Screen.Selected != null) Screen.Selected.Update((float)Timing.Step);
|
||||
Server.Update((float)Timing.Step);
|
||||
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
||||
|
||||
Timing.Accumulator -= 1.0;
|
||||
}
|
||||
int frameTime = DateTime.Now.Subtract(prevTime).Milliseconds;
|
||||
Thread.Sleep(Math.Max((int)(Timing.Step * 1000.0) - frameTime,0));
|
||||
Thread.Sleep(Math.Max((int)(Timing.Step * 1000.0) - frameTime/2,0));
|
||||
}
|
||||
|
||||
CloseServer();
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public enum WindowMode
|
||||
{
|
||||
Windowed, Fullscreen, BorderlessWindowed
|
||||
}
|
||||
|
||||
public partial class GameSettings
|
||||
{
|
||||
public void Save(string filePath)
|
||||
{
|
||||
XDocument doc = new XDocument();
|
||||
|
||||
if (doc.Root == null)
|
||||
{
|
||||
doc.Add(new XElement("config"));
|
||||
}
|
||||
|
||||
doc.Root.Add(
|
||||
new XAttribute("masterserverurl", MasterServerUrl),
|
||||
new XAttribute("autocheckupdates", AutoCheckUpdates),
|
||||
new XAttribute("verboselogging", VerboseLogging));
|
||||
|
||||
if (WasGameUpdated)
|
||||
{
|
||||
doc.Root.Add(new XAttribute("wasgameupdated", true));
|
||||
}
|
||||
|
||||
if (SelectedContentPackage != null)
|
||||
{
|
||||
doc.Root.Add(new XElement("contentpackage",
|
||||
new XAttribute("path", SelectedContentPackage.Path)));
|
||||
}
|
||||
|
||||
doc.Save(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ namespace Barotrauma
|
||||
}
|
||||
}));
|
||||
|
||||
commands.Add(new Command("clientlist", "clientlist: List all the clients connected to the server.", (string[] args) =>
|
||||
commands.Add(new Command("clientlist", "clientlist: List all the clients connected to the server.", (string[] args) =>
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
NewMessage("***************", Color.Cyan);
|
||||
@@ -264,35 +264,149 @@ namespace Barotrauma
|
||||
NewMessage("Crew AI enabled", Color.White);
|
||||
}));
|
||||
|
||||
commands.Add(new Command("autorestartinterval", "autorestartinterval [seconds]: Set how long the server waits between rounds before automatically starting a new one.", (string[] args) =>
|
||||
commands.Add(new Command("autorestart", "autorestart [true/false]: Enable or disable round auto-restart.", (string[] args) =>
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
bool enabled = GameMain.Server.AutoRestart;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
bool.TryParse(args[0], out enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
enabled = !enabled;
|
||||
}
|
||||
if (enabled != GameMain.Server.AutoRestart)
|
||||
{
|
||||
if (GameMain.Server.AutoRestartInterval <= 0) GameMain.Server.AutoRestartInterval = 10;
|
||||
GameMain.Server.AutoRestartTimer = GameMain.Server.AutoRestartInterval;
|
||||
GameMain.Server.AutoRestart = enabled;
|
||||
#if CLIENT
|
||||
GameMain.NetLobbyScreen.SetAutoRestart(enabled, GameMain.Server.AutoRestartTimer);
|
||||
#endif
|
||||
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||
}
|
||||
NewMessage(GameMain.Server.AutoRestart ? "Automatic restart enabled." : "Automatic restart disabled.", Color.White);
|
||||
}));
|
||||
|
||||
commands.Add(new Command("autorestartinterval", "autorestartinterval [seconds]: Set how long the server waits between rounds before automatically starting a new one. If set to 0, autorestart is disabled.", (string[] args) =>
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
int parsedInt = 0;
|
||||
if (int.TryParse(args[0], out parsedInt) && parsedInt >= 0)
|
||||
if (int.TryParse(args[0], out parsedInt))
|
||||
{
|
||||
GameMain.Server.AutoRestartInterval = parsedInt;
|
||||
NewMessage("Autorestart interval set to " + GameMain.Server.AutoRestartInterval + " seconds.", Color.White);
|
||||
if (parsedInt >= 0)
|
||||
{
|
||||
GameMain.Server.AutoRestart = true;
|
||||
GameMain.Server.AutoRestartInterval = parsedInt;
|
||||
if (GameMain.Server.AutoRestartTimer >= GameMain.Server.AutoRestartInterval) GameMain.Server.AutoRestartTimer = GameMain.Server.AutoRestartInterval;
|
||||
NewMessage("Autorestart interval set to " + GameMain.Server.AutoRestartInterval + " seconds.", Color.White);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.Server.AutoRestart = false;
|
||||
NewMessage("Autorestart disabled.", Color.White);
|
||||
}
|
||||
#if CLIENT
|
||||
GameMain.NetLobbyScreen.SetAutoRestart(GameMain.Server.AutoRestart, GameMain.Server.AutoRestartTimer);
|
||||
#endif
|
||||
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
|
||||
commands.Add(new Command("autorestarttimer", "autorestarttimer [seconds]: Set the current autorestart countdown to the specified value.", (string[] args) =>
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
int parsedInt = 0;
|
||||
if (int.TryParse(args[0], out parsedInt) && parsedInt >= 0)
|
||||
if (int.TryParse(args[0], out parsedInt))
|
||||
{
|
||||
GameMain.Server.AutoRestartTimer = parsedInt;
|
||||
if (parsedInt >= 0)
|
||||
{
|
||||
GameMain.Server.AutoRestart = true;
|
||||
GameMain.Server.AutoRestartTimer = parsedInt;
|
||||
if (GameMain.Server.AutoRestartInterval <= GameMain.Server.AutoRestartTimer) GameMain.Server.AutoRestartInterval = GameMain.Server.AutoRestartTimer;
|
||||
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||
NewMessage("Autorestart timer set to " + GameMain.Server.AutoRestartTimer + " seconds.", Color.White);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.Server.AutoRestart = false;
|
||||
NewMessage("Autorestart disabled.", Color.White);
|
||||
}
|
||||
#if CLIENT
|
||||
GameMain.NetLobbyScreen.SetAutoRestart(GameMain.Server.AutoRestart, GameMain.Server.AutoRestartTimer);
|
||||
#endif
|
||||
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||
NewMessage("Autorestart timer set to " + GameMain.Server.AutoRestartTimer + " seconds.", Color.White);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) =>
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
if (args.Length < 1) return;
|
||||
|
||||
int id;
|
||||
int.TryParse(args[0], out id);
|
||||
var client = GameMain.Server.ConnectedClients.Find(c => c.ID == id);
|
||||
if (client == null)
|
||||
{
|
||||
ThrowError("Client id \"" + id + "\" not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
ShowQuestionPrompt("Permission to grant to \"" + client.Name + "\"?", (perm) =>
|
||||
{
|
||||
ClientPermissions permission = ClientPermissions.None;
|
||||
if (perm.ToLower() == "all")
|
||||
{
|
||||
permission = ClientPermissions.EndRound | ClientPermissions.Kick | ClientPermissions.Ban | ClientPermissions.SelectSub | ClientPermissions.SelectMode | ClientPermissions.ManageCampaign;
|
||||
}
|
||||
else
|
||||
{
|
||||
Enum.TryParse<ClientPermissions>(perm, out permission);
|
||||
}
|
||||
client.SetPermissions(client.Permissions | permission);
|
||||
GameMain.Server.UpdateClientPermissions(client);
|
||||
DebugConsole.NewMessage("Granted "+perm+" permissions to "+client.Name+".",Color.White);
|
||||
});
|
||||
}));
|
||||
|
||||
commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) =>
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
if (args.Length < 1) return;
|
||||
|
||||
int id;
|
||||
int.TryParse(args[0], out id);
|
||||
var client = GameMain.Server.ConnectedClients.Find(c => c.ID == id);
|
||||
if (client == null)
|
||||
{
|
||||
ThrowError("Client id \"" + id + "\" not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
ShowQuestionPrompt("Permission to revoke from \"" + client.Name + "\"?", (perm) =>
|
||||
{
|
||||
ClientPermissions permission = ClientPermissions.None;
|
||||
if (perm.ToLower() == "all")
|
||||
{
|
||||
permission = ClientPermissions.EndRound | ClientPermissions.Kick | ClientPermissions.Ban | ClientPermissions.SelectSub | ClientPermissions.SelectMode | ClientPermissions.ManageCampaign;
|
||||
}
|
||||
else
|
||||
{
|
||||
Enum.TryParse<ClientPermissions>(perm, out permission);
|
||||
}
|
||||
client.SetPermissions(client.Permissions & ~permission);
|
||||
GameMain.Server.UpdateClientPermissions(client);
|
||||
DebugConsole.NewMessage("Revoked " + perm + " permissions from " + client.Name + ".", Color.White);
|
||||
});
|
||||
}));
|
||||
|
||||
commands.Add(new Command("kick", "kick [name]: Kick a player out of the server.", (string[] args) =>
|
||||
{
|
||||
|
||||
@@ -1,12 +1,104 @@
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
#if CLIENT
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
#endif
|
||||
using System;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public enum WindowMode
|
||||
{
|
||||
Windowed, Fullscreen, BorderlessWindowed
|
||||
}
|
||||
|
||||
public partial class GameSettings
|
||||
{
|
||||
public int GraphicsWidth { get; set; }
|
||||
public int GraphicsHeight { get; set; }
|
||||
|
||||
public bool VSyncEnabled { get; set; }
|
||||
|
||||
public bool EnableSplashScreen { get; set; }
|
||||
|
||||
//public bool FullScreenEnabled { get; set; }
|
||||
|
||||
private KeyOrMouse[] keyMapping;
|
||||
|
||||
private WindowMode windowMode;
|
||||
|
||||
public List<string> jobNamePreferences;
|
||||
|
||||
public WindowMode WindowMode
|
||||
{
|
||||
get { return windowMode; }
|
||||
set { windowMode = value; }
|
||||
}
|
||||
|
||||
public List<string> JobNamePreferences
|
||||
{
|
||||
get { return jobNamePreferences; }
|
||||
set
|
||||
{
|
||||
// Begin saving coroutine. Remove any existing save coroutines if one is running.
|
||||
if (CoroutineManager.IsCoroutineRunning("saveCoroutine")) { CoroutineManager.StopCoroutines("saveCoroutine"); }
|
||||
CoroutineManager.StartCoroutine(ApplyUnsavedChanges(), "saveCoroutine");
|
||||
|
||||
jobNamePreferences = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool unsavedSettings;
|
||||
|
||||
public bool UnsavedSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return unsavedSettings;
|
||||
}
|
||||
private set
|
||||
{
|
||||
unsavedSettings = value;
|
||||
#if CLIENT
|
||||
if (applyButton != null)
|
||||
{
|
||||
//applyButton.Selected = unsavedSettings;
|
||||
applyButton.Enabled = unsavedSettings;
|
||||
applyButton.Text = unsavedSettings ? "Apply*" : "Apply";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private float soundVolume, musicVolume;
|
||||
|
||||
public float SoundVolume
|
||||
{
|
||||
get { return soundVolume; }
|
||||
set
|
||||
{
|
||||
soundVolume = MathHelper.Clamp(value, 0.0f, 1.0f);
|
||||
#if CLIENT
|
||||
Sounds.SoundManager.MasterVolume = soundVolume;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public float MusicVolume
|
||||
{
|
||||
get { return musicVolume; }
|
||||
set
|
||||
{
|
||||
musicVolume = MathHelper.Clamp(value, 0.0f, 1.0f);
|
||||
#if CLIENT
|
||||
SoundPlayer.MusicVolume = musicVolume;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public ContentPackage SelectedContentPackage { get; set; }
|
||||
|
||||
public string MasterServerUrl { get; set; }
|
||||
@@ -25,17 +117,6 @@ namespace Barotrauma
|
||||
public void Load(string filePath)
|
||||
{
|
||||
XDocument doc = XMLExtensions.TryLoadXml(filePath);
|
||||
|
||||
if (doc == null)
|
||||
{
|
||||
DebugConsole.ThrowError("No config file found");
|
||||
|
||||
MasterServerUrl = "";
|
||||
|
||||
SelectedContentPackage = ContentPackage.list.Any() ? ContentPackage.list[0] : new ContentPackage("");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
MasterServerUrl = doc.Root.GetAttributeString("masterserverurl", "");
|
||||
|
||||
@@ -44,7 +125,111 @@ namespace Barotrauma
|
||||
|
||||
VerboseLogging = doc.Root.GetAttributeBool("verboselogging", false);
|
||||
|
||||
InitProjSpecific(doc);
|
||||
if (doc == null)
|
||||
{
|
||||
GraphicsWidth = 1024;
|
||||
GraphicsHeight = 678;
|
||||
|
||||
MasterServerUrl = "";
|
||||
|
||||
SelectedContentPackage = ContentPackage.list.Any() ? ContentPackage.list[0] : new ContentPackage("");
|
||||
|
||||
JobNamePreferences = new List<string>();
|
||||
foreach (JobPrefab job in JobPrefab.List)
|
||||
{
|
||||
JobNamePreferences.Add(job.Name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
XElement graphicsMode = doc.Root.Element("graphicsmode");
|
||||
GraphicsWidth = graphicsMode.GetAttributeInt("width", 0);
|
||||
GraphicsHeight = graphicsMode.GetAttributeInt("height", 0);
|
||||
VSyncEnabled = graphicsMode.GetAttributeBool("vsync", true);
|
||||
|
||||
#if CLIENT
|
||||
if (GraphicsWidth == 0 || GraphicsHeight == 0)
|
||||
{
|
||||
GraphicsWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
|
||||
GraphicsHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
|
||||
}
|
||||
#endif
|
||||
|
||||
//FullScreenEnabled = ToolBox.GetAttributeBool(graphicsMode, "fullscreen", true);
|
||||
|
||||
var windowModeStr = graphicsMode.GetAttributeString("displaymode", "Fullscreen");
|
||||
if (!Enum.TryParse<WindowMode>(windowModeStr, out windowMode))
|
||||
{
|
||||
windowMode = WindowMode.Fullscreen;
|
||||
}
|
||||
|
||||
SoundVolume = doc.Root.GetAttributeFloat("soundvolume", 1.0f);
|
||||
MusicVolume = doc.Root.GetAttributeFloat("musicvolume", 0.3f);
|
||||
|
||||
EnableSplashScreen = doc.Root.GetAttributeBool("enablesplashscreen", true);
|
||||
|
||||
keyMapping = new KeyOrMouse[Enum.GetNames(typeof(InputType)).Length];
|
||||
keyMapping[(int)InputType.Up] = new KeyOrMouse(Keys.W);
|
||||
keyMapping[(int)InputType.Down] = new KeyOrMouse(Keys.S);
|
||||
keyMapping[(int)InputType.Left] = new KeyOrMouse(Keys.A);
|
||||
keyMapping[(int)InputType.Right] = new KeyOrMouse(Keys.D);
|
||||
keyMapping[(int)InputType.Run] = new KeyOrMouse(Keys.LeftShift);
|
||||
|
||||
keyMapping[(int)InputType.Chat] = new KeyOrMouse(Keys.Tab);
|
||||
keyMapping[(int)InputType.RadioChat] = new KeyOrMouse(Keys.OemPipe);
|
||||
keyMapping[(int)InputType.CrewOrders] = new KeyOrMouse(Keys.C);
|
||||
|
||||
keyMapping[(int)InputType.Select] = new KeyOrMouse(Keys.E);
|
||||
|
||||
keyMapping[(int)InputType.Use] = new KeyOrMouse(0);
|
||||
keyMapping[(int)InputType.Aim] = new KeyOrMouse(1);
|
||||
|
||||
foreach (XElement subElement in doc.Root.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "keymapping":
|
||||
foreach (XAttribute attribute in subElement.Attributes())
|
||||
{
|
||||
InputType inputType;
|
||||
if (Enum.TryParse(attribute.Name.ToString(), true, out inputType))
|
||||
{
|
||||
int mouseButton;
|
||||
if (int.TryParse(attribute.Value.ToString(), out mouseButton))
|
||||
{
|
||||
keyMapping[(int)inputType] = new KeyOrMouse(mouseButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
Keys key;
|
||||
if (Enum.TryParse(attribute.Value.ToString(), true, out key))
|
||||
{
|
||||
keyMapping[(int)inputType] = new KeyOrMouse(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "gameplay":
|
||||
JobNamePreferences = new List<string>();
|
||||
foreach (XElement ele in subElement.Element("jobpreferences").Elements("job"))
|
||||
{
|
||||
JobNamePreferences.Add(ele.GetAttributeString("name", ""));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
|
||||
{
|
||||
if (keyMapping[(int)inputType] == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Key binding for the input type \"" + inputType + " not set!");
|
||||
keyMapping[(int)inputType] = new KeyOrMouse(Keys.D1);
|
||||
}
|
||||
}
|
||||
|
||||
UnsavedSettings = false;
|
||||
|
||||
foreach (XElement subElement in doc.Root.Elements())
|
||||
{
|
||||
@@ -61,7 +246,93 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(string filePath)
|
||||
{
|
||||
UnsavedSettings = false;
|
||||
|
||||
partial void InitProjSpecific(XDocument doc);
|
||||
XDocument doc = new XDocument();
|
||||
|
||||
if (doc.Root == null)
|
||||
{
|
||||
doc.Add(new XElement("config"));
|
||||
}
|
||||
|
||||
doc.Root.Add(
|
||||
new XAttribute("masterserverurl", MasterServerUrl),
|
||||
new XAttribute("autocheckupdates", AutoCheckUpdates),
|
||||
new XAttribute("musicvolume", musicVolume),
|
||||
new XAttribute("soundvolume", soundVolume),
|
||||
new XAttribute("verboselogging", VerboseLogging),
|
||||
new XAttribute("enablesplashscreen", EnableSplashScreen));
|
||||
|
||||
if (WasGameUpdated)
|
||||
{
|
||||
doc.Root.Add(new XAttribute("wasgameupdated", true));
|
||||
}
|
||||
|
||||
XElement gMode = doc.Root.Element("graphicsmode");
|
||||
if (gMode == null)
|
||||
{
|
||||
gMode = new XElement("graphicsmode");
|
||||
doc.Root.Add(gMode);
|
||||
}
|
||||
|
||||
if (GraphicsWidth == 0 || GraphicsHeight == 0)
|
||||
{
|
||||
gMode.ReplaceAttributes(new XAttribute("displaymode", windowMode));
|
||||
}
|
||||
else
|
||||
{
|
||||
gMode.ReplaceAttributes(
|
||||
new XAttribute("width", GraphicsWidth),
|
||||
new XAttribute("height", GraphicsHeight),
|
||||
new XAttribute("vsync", VSyncEnabled),
|
||||
new XAttribute("displaymode", windowMode));
|
||||
}
|
||||
|
||||
|
||||
if (SelectedContentPackage != null)
|
||||
{
|
||||
doc.Root.Add(new XElement("contentpackage",
|
||||
new XAttribute("path", SelectedContentPackage.Path)));
|
||||
}
|
||||
|
||||
var keyMappingElement = new XElement("keymapping");
|
||||
doc.Root.Add(keyMappingElement);
|
||||
for (int i = 0; i < keyMapping.Length; i++)
|
||||
{
|
||||
if (keyMapping[i].MouseButton == null)
|
||||
{
|
||||
keyMappingElement.Add(new XAttribute(((InputType)i).ToString(), keyMapping[i].Key));
|
||||
}
|
||||
else
|
||||
{
|
||||
keyMappingElement.Add(new XAttribute(((InputType)i).ToString(), keyMapping[i].MouseButton));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
var gameplay = new XElement("gameplay");
|
||||
|
||||
var jobPreferences = new XElement("jobpreferences");
|
||||
foreach (string jobName in JobNamePreferences)
|
||||
{
|
||||
jobPreferences.Add(new XElement("job", new XAttribute("name", jobName)));
|
||||
}
|
||||
|
||||
gameplay.Add(jobPreferences);
|
||||
doc.Root.Add(gameplay);
|
||||
|
||||
doc.Save(filePath);
|
||||
}
|
||||
|
||||
private IEnumerable<object> ApplyUnsavedChanges()
|
||||
{
|
||||
yield return new WaitForSeconds(10.0f);
|
||||
|
||||
Save("config.xml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,9 +72,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
name = name.Replace(":", "");
|
||||
name = name.Replace(";", "");
|
||||
|
||||
AdminAuthPass = "";
|
||||
|
||||
|
||||
this.name = name;
|
||||
this.isPublic = isPublic;
|
||||
this.maxPlayers = maxPlayers;
|
||||
|
||||
@@ -61,21 +61,7 @@ namespace Barotrauma.Networking
|
||||
private BanList banList;
|
||||
|
||||
private string password;
|
||||
|
||||
private string adminAuthPass = "";
|
||||
public string AdminAuthPass
|
||||
{
|
||||
set
|
||||
{
|
||||
DebugConsole.NewMessage("Admin auth pass changed!",Color.Yellow);
|
||||
adminAuthPass = "";
|
||||
if (value.Length > 0)
|
||||
{
|
||||
adminAuthPass = Encoding.UTF8.GetString(Lidgren.Network.NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public float AutoRestartTimer;
|
||||
|
||||
private bool autoRestart;
|
||||
|
||||
Reference in New Issue
Block a user