DebugConsole refactoring : available console commands are stored in a list of "Command" objects which contain the name, help text and the action that's invoked when the command is entered. Commands can also now be autocompleted in the client project by pressing tab (TODO: implement in the server project). + Now it should be easier to implement giving clients the permission to use specific console commands.

This commit is contained in:
Joonas Rikkonen
2017-07-10 21:10:54 +03:00
parent 59fba47f63
commit 6ad5dd6c1e
4 changed files with 1018 additions and 960 deletions
+128 -233
View File
@@ -42,16 +42,12 @@ namespace Barotrauma
//listBox.Color = Color.Black * 0.7f; //listBox.Color = Color.Black * 0.7f;
textBox = new GUITextBox(new Rectangle(0, 0, 0, 20), Color.Black, Color.White, Alignment.BottomLeft, Alignment.Left, "", frame); textBox = new GUITextBox(new Rectangle(0, 0, 0, 20), Color.Black, Color.White, Alignment.BottomLeft, Alignment.Left, "", frame);
//textBox.Color = Color.Black * 0.7f; textBox.OnTextChanged += (textBox, text) =>
//messages already added before initialization -> add them to the listbox
List<ColoredText> unInitializedMessages = new List<ColoredText>(Messages);
Messages.Clear();
foreach (ColoredText msg in unInitializedMessages)
{ {
NewMessage(msg.Text, msg.Color); ResetAutoComplete();
} return true;
};
NewMessage("Press F3 to open/close the debug console", Color.Cyan); NewMessage("Press F3 to open/close the debug console", Color.Cyan);
NewMessage("Enter \"help\" for a list of available console commands", Color.Cyan); NewMessage("Enter \"help\" for a list of available console commands", Color.Cyan);
@@ -105,6 +101,10 @@ namespace Barotrauma
{ {
SelectMessage(1); SelectMessage(1);
} }
else if (PlayerInput.KeyHit(Keys.Tab))
{
textBox.Text = AutoComplete(textBox.Text);
}
if (PlayerInput.KeyHit(Keys.Enter)) if (PlayerInput.KeyHit(Keys.Enter))
{ {
@@ -195,72 +195,21 @@ namespace Barotrauma
} }
} }
private static bool ExecProjSpecific(string[] commands) private static void InitProjectSpecific()
{ {
switch (commands[0].ToLowerInvariant()) commands.Add(new Command("startclient", "", (string[] args) =>
{ {
case "help": if (args.Length == 0) return;
NewMessage("menu: go to main menu", Color.Cyan);
NewMessage("game: enter the \"game screen\"", Color.Cyan);
NewMessage("edit: switch to submarine editor", Color.Cyan);
NewMessage("edit [submarine name]: load a submarine and switch to submarine editor", Color.Cyan);
NewMessage("load [submarine name]: load a submarine", Color.Cyan);
NewMessage("save [submarine name]: save the current submarine using the specified name", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("spawn [creaturename] [near/inside/outside]: spawn a creature at a random spawnpoint (use the second parameter to only select spawnpoints near/inside/outside the submarine)", Color.Cyan);
NewMessage("spawnitem [itemname] [cursor/inventory]: spawn an item at the position of the cursor, in the inventory of the controlled character or at a random spawnpoint if the last parameter is omitted", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("lights: disable lighting", Color.Cyan);
NewMessage("los: disable the line of sight effect", Color.Cyan);
NewMessage("freecam: detach the camera from the controlled character", Color.Cyan);
NewMessage("control [character name]: start controlling the specified character", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("water: allows adding water into rooms or removing it by holding the left/right mouse buttons", Color.Cyan);
NewMessage("fire: allows putting up fires by left clicking", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("teleport: teleport the controlled character to the position of the cursor", Color.Cyan);
NewMessage("teleport [character name]: teleport the specified character to the position of the cursor", Color.Cyan);
NewMessage("heal: restore the controlled character to full health", Color.Cyan);
NewMessage("heal [character name]: restore the specified character to full health", Color.Cyan);
NewMessage("revive: bring the controlled character back from the dead", Color.Cyan);
NewMessage("revive [character name]: bring the specified character back from the dead", Color.Cyan);
NewMessage("killmonsters: immediately kills all AI-controlled enemies in the level", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("fixwalls: fixes all the walls", Color.Cyan);
NewMessage("fixitems: fixes every item/device in the sub", Color.Cyan);
NewMessage("oxygen: replenishes the oxygen in every room to 100%", Color.Cyan);
NewMessage("power [amount]: immediately sets the temperature of the reactor to the specified value", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("kick [name]: kick a player out from the server", Color.Cyan);
NewMessage("ban [name]: kick and ban the player from the server", Color.Cyan);
NewMessage("banip [IP address]: ban the IP address from the server", Color.Cyan);
NewMessage("debugdraw: toggles the \"debug draw mode\"", Color.Cyan);
NewMessage("netstats: toggles the visibility of the network statistics panel", Color.Cyan);
break;
case "startclient":
if (commands.Length == 1) return true;
if (GameMain.Client == null) if (GameMain.Client == null)
{ {
GameMain.NetworkMember = new GameClient("Name"); GameMain.NetworkMember = new GameClient("Name");
GameMain.Client.ConnectToServer(commands[1]); GameMain.Client.ConnectToServer(args[0]);
} }
break; }));
case "mainmenuscreen":
case "mainmenu": commands.Add(new Command("mainmenuscreen|mainmenu|menu", "mainmenu/menu: Go to the main menu.", (string[] args) =>
case "menu": {
GameMain.GameSession = null; GameMain.GameSession = null;
List<Character> characters = new List<Character>(Character.CharacterList); List<Character> characters = new List<Character>(Character.CharacterList);
@@ -270,139 +219,109 @@ namespace Barotrauma
} }
GameMain.MainMenuScreen.Select(); GameMain.MainMenuScreen.Select();
break; }));
case "gamescreen":
case "game": commands.Add(new Command("gamescreen|game", "gamescreen/game: Go to the \"in-game\" view.", (string[] args) =>
GameMain.GameScreen.Select();
break;
case "editmapscreen":
case "editmap":
case "edit":
if (commands.Length > 1)
{ {
Submarine.Load(string.Join(" ", commands.Skip(1)), true);
}));
commands.Add(new Command("editsubscreen|editsub|subeditor", "editsub/subeditor: Switch to the submarine editor.", (string[] args) =>
{
if (args.Length > 0)
{
Submarine.Load(string.Join(" ", args), true);
} }
GameMain.EditMapScreen.Select(); GameMain.EditMapScreen.Select();
break; }));
case "editcharacter":
case "editchar":
GameMain.EditCharacterScreen.Select();
break;
case "controlcharacter":
case "control":
{
if (commands.Length < 2) break;
var character = FindMatchingCharacter(commands, true); commands.Add(new Command("editcharacter", "", (string[] args) =>
{
GameMain.EditCharacterScreen.Select();
}));
commands.Add(new Command("control|controlcharacter", "control [character name]: Start controlling the specified character.", (string[] args) =>
{
if (args.Length < 1) return;
var character = FindMatchingCharacter(args, true);
if (character != null) if (character != null)
{ {
Character.Controlled = character; Character.Controlled = character;
} }
} }));
break;
case "setclientcharacter": commands.Add(new Command("shake", "", (string[] args) =>
{ {
if (GameMain.Server == null) break;
int separatorIndex = Array.IndexOf(commands, ";");
if (separatorIndex == -1 || commands.Length < 4)
{
ThrowError("Invalid parameters. The command should be formatted as \"setclientcharacter [client] ; [character]\"");
break;
}
string[] commandsLeft = commands.Take(separatorIndex).ToArray();
string[] commandsRight = commands.Skip(separatorIndex).ToArray();
string clientName = String.Join(" ", commandsLeft.Skip(1));
var client = GameMain.Server.ConnectedClients.Find(c => c.name == clientName);
if (client == null)
{
ThrowError("Client \"" + clientName + "\" not found.");
}
var character = FindMatchingCharacter(commandsRight, false);
GameMain.Server.SetClientCharacter(client, character);
}
break;
case "test":
Submarine.Load("aegir mark ii", true);
GameMain.DebugDraw = true;
GameMain.LightManager.LosEnabled = false;
GameMain.EditMapScreen.Select();
break;
case "shake":
GameMain.GameScreen.Cam.Shake = 10.0f; GameMain.GameScreen.Cam.Shake = 10.0f;
break; }));
case "losenabled":
case "los": commands.Add(new Command("los", "los: Toggle the line of sight effect on/off.", (string[] args) =>
case "drawlos": {
GameMain.LightManager.LosEnabled = !GameMain.LightManager.LosEnabled; GameMain.LightManager.LosEnabled = !GameMain.LightManager.LosEnabled;
break; NewMessage("Line of sight effect " + (GameMain.LightManager.LosEnabled ? "enabled" : "disabled"), Color.White);
case "lighting": }));
case "lightingenabled":
case "light": commands.Add(new Command("lighting|lights", "Toggle lighting on/off.", (string[] args) =>
case "lights": {
GameMain.LightManager.LightingEnabled = !GameMain.LightManager.LightingEnabled; GameMain.LightManager.LightingEnabled = !GameMain.LightManager.LightingEnabled;
break; NewMessage("Lighting " + (GameMain.LightManager.LightingEnabled ? "enabled" : "disabled"), Color.White);
case "tutorial": }));
commands.Add(new Command("tutorial", "", (string[] args) =>
{
TutorialMode.StartTutorial(Tutorials.TutorialType.TutorialTypes[0]); TutorialMode.StartTutorial(Tutorials.TutorialType.TutorialTypes[0]);
break; }));
case "editortutorial":
GameMain.EditMapScreen.Select(); commands.Add(new Command("lobby|lobbyscreen", "", (string[] args) =>
GameMain.EditMapScreen.StartTutorial(); {
break;
case "lobbyscreen":
case "lobby":
GameMain.LobbyScreen.Select(); GameMain.LobbyScreen.Select();
break; }));
case "savemap":
case "savesub": commands.Add(new Command("save|savesub", "save [submarine name]: Save the currently loaded submarine using the specified name.", (string[] args) =>
case "save": {
if (commands.Length < 2) break; if (args.Length < 1) return;
if (GameMain.EditMapScreen.CharacterMode) if (GameMain.EditMapScreen.CharacterMode)
{ {
GameMain.EditMapScreen.ToggleCharacterMode(); GameMain.EditMapScreen.ToggleCharacterMode();
} }
string fileName = string.Join(" ", commands.Skip(1)); string fileName = string.Join(" ", args);
if (fileName.Contains("../")) if (fileName.Contains("../"))
{ {
DebugConsole.ThrowError("Illegal symbols in filename (../)"); ThrowError("Illegal symbols in filename (../)");
return true; return;
} }
if (Submarine.SaveCurrent(System.IO.Path.Combine(Submarine.SavePath, fileName + ".sub"))) if (Submarine.SaveCurrent(System.IO.Path.Combine(Submarine.SavePath, fileName + ".sub")))
{ {
NewMessage("Sub saved", Color.Green); NewMessage("Sub saved", Color.Green);
//Submarine.Loaded.First().CheckForErrors();
} }
}));
break; commands.Add(new Command("load|loadsub", "load [submarine name]: Load a submarine.", (string[] args) =>
case "loadmap": {
case "loadsub": if (args.Length == 0) return;
case "load": Submarine.Load(string.Join(" ", args), true);
if (commands.Length < 2) break; }));
Submarine.Load(string.Join(" ", commands.Skip(1)), true); commands.Add(new Command("cleansub", "", (string[] args) =>
break; {
case "cleansub":
for (int i = MapEntity.mapEntityList.Count - 1; i >= 0; i--) for (int i = MapEntity.mapEntityList.Count - 1; i >= 0; i--)
{ {
MapEntity me = MapEntity.mapEntityList[i]; MapEntity me = MapEntity.mapEntityList[i];
if (me.SimPosition.Length() > 2000.0f) if (me.SimPosition.Length() > 2000.0f)
{ {
DebugConsole.NewMessage("Removed " + me.Name + " (simposition " + me.SimPosition + ")", Color.Orange); NewMessage("Removed " + me.Name + " (simposition " + me.SimPosition + ")", Color.Orange);
MapEntity.mapEntityList.RemoveAt(i); MapEntity.mapEntityList.RemoveAt(i);
} }
else if (me.MoveWithLevel) else if (me.MoveWithLevel)
{ {
DebugConsole.NewMessage("Removed " + me.Name + " (MoveWithLevel==true)", Color.Orange); NewMessage("Removed " + me.Name + " (MoveWithLevel==true)", Color.Orange);
MapEntity.mapEntityList.RemoveAt(i); MapEntity.mapEntityList.RemoveAt(i);
} }
else if (me is Item) else if (me is Item)
@@ -414,72 +333,53 @@ namespace Barotrauma
if (wire.GetNodes().Count > 0 && !wire.Connections.Any(c => c != null)) if (wire.GetNodes().Count > 0 && !wire.Connections.Any(c => c != null))
{ {
wire.Item.Drop(null); wire.Item.Drop(null);
DebugConsole.NewMessage("Dropped wire (ID: " + wire.Item.ID + ") - attached on wall but no connections found", Color.Orange); NewMessage("Dropped wire (ID: " + wire.Item.ID + ") - attached on wall but no connections found", Color.Orange);
} }
} }
}
}));
} commands.Add(new Command("messagebox", "", (string[] args) =>
break; {
case "messagebox": new GUIMessageBox("", string.Join(" ", args));
if (commands.Length < 3) break; }));
new GUIMessageBox(commands[1], commands[2]);
break; commands.Add(new Command("debugdraw", "debugdraw: Toggle the debug drawing mode on/off.", (string[] args) =>
case "debugdraw": {
GameMain.DebugDraw = !GameMain.DebugDraw; GameMain.DebugDraw = !GameMain.DebugDraw;
break; NewMessage("Debug draw mode " + (GameMain.DebugDraw ? "enabled" : "disabled"), Color.White);
case "disablehud":
case "hud": }));
commands.Add(new Command("togglehud|hud", "togglehud/hud: Toggle the character HUD (inventories, icons, buttons, etc) on/off.", (string[] args) =>
{
GUI.DisableHUD = !GUI.DisableHUD; GUI.DisableHUD = !GUI.DisableHUD;
GameMain.Instance.IsMouseVisible = !GameMain.Instance.IsMouseVisible; GameMain.Instance.IsMouseVisible = !GameMain.Instance.IsMouseVisible;
break; NewMessage(GUI.DisableHUD ? "Disabled HUD" : "Enabled HUD", Color.White);
case "followsub": }));
commands.Add(new Command("followsub", "followsub: Toggle whether the ", (string[] args) =>
{
Camera.FollowSub = !Camera.FollowSub; Camera.FollowSub = !Camera.FollowSub;
break; NewMessage(Camera.FollowSub ? "Set the camera to follow the closest submarine" : "Disabled submarine following.", Color.White);
case "drawaitargets": }));
case "showaitargets":
commands.Add(new Command("toggleaitargets|aitargets", "toggleaitargets/aitargets: Toggle the visibility of AI targets (= targets that enemies can detect and attack/escape from).", (string[] args) =>
{
AITarget.ShowAITargets = !AITarget.ShowAITargets; AITarget.ShowAITargets = !AITarget.ShowAITargets;
break; NewMessage(AITarget.ShowAITargets ? "Enabled AI target drawing" : "Disabled AI target drawing", Color.White);
}));
#if DEBUG #if DEBUG
case "spamevents": commands.Add(new Command("spamchatmessages", "", (string[] args) =>
foreach (Item item in Item.ItemList)
{ {
for (int i = 0; i<item.components.Count; i++)
{
if (item.components[i] is IServerSerializable)
{
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, i });
}
var itemContainer = item.GetComponent<ItemContainer>();
if (itemContainer != null)
{
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.InventoryState });
}
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.Status });
item.NeedsPositionUpdate = true;
}
}
foreach (Character c in Character.CharacterList)
{
GameMain.Server.CreateEntityEvent(c, new object[] { NetEntityEvent.Type.Status });
}
foreach (Structure wall in Structure.WallList)
{
GameMain.Server.CreateEntityEvent(wall);
}
break;
case "spamchatmessages":
int msgCount = 1000; int msgCount = 1000;
if (commands.Length > 1) int.TryParse(commands[1], out msgCount); if (args.Length > 0) int.TryParse(args[0], out msgCount);
int msgLength = 50; int msgLength = 50;
if (commands.Length > 2) int.TryParse(commands[2], out msgLength); if (args.Length > 1) int.TryParse(args[1], out msgLength);
for (int i = 0; i < msgCount; i++) for (int i = 0; i < msgCount; i++)
{ {
if (GameMain.Server != null) if (GameMain.Client != null)
{ {
GameMain.Server.SendChatMessage(ToolBox.RandomSeed(msgLength), ChatMessageType.Default); GameMain.Server.SendChatMessage(ToolBox.RandomSeed(msgLength), ChatMessageType.Default);
} }
@@ -488,24 +388,25 @@ namespace Barotrauma
GameMain.Client.SendChatMessage(ToolBox.RandomSeed(msgLength)); GameMain.Client.SendChatMessage(ToolBox.RandomSeed(msgLength));
} }
} }
break; }));
#endif #endif
case "cleanbuild": commands.Add(new Command("cleanbuild", "", (string[] args) =>
{
GameMain.Config.MusicVolume = 0.5f; GameMain.Config.MusicVolume = 0.5f;
GameMain.Config.SoundVolume = 0.5f; GameMain.Config.SoundVolume = 0.5f;
DebugConsole.NewMessage("Music and sound volume set to 0.5", Color.Green); NewMessage("Music and sound volume set to 0.5", Color.Green);
GameMain.Config.GraphicsWidth = 0; GameMain.Config.GraphicsWidth = 0;
GameMain.Config.GraphicsHeight = 0; GameMain.Config.GraphicsHeight = 0;
GameMain.Config.WindowMode = WindowMode.Fullscreen; GameMain.Config.WindowMode = WindowMode.Fullscreen;
DebugConsole.NewMessage("Resolution set to 0 x 0 (screen resolution will be used)", Color.Green); NewMessage("Resolution set to 0 x 0 (screen resolution will be used)", Color.Green);
DebugConsole.NewMessage("Fullscreen enabled", Color.Green); NewMessage("Fullscreen enabled", Color.Green);
GameSettings.VerboseLogging = false; GameSettings.VerboseLogging = false;
if (GameMain.Config.MasterServerUrl != "http://www.undertowgames.com/baromaster") if (GameMain.Config.MasterServerUrl != "http://www.undertowgames.com/baromaster")
{ {
DebugConsole.ThrowError("MasterServerUrl \"" + GameMain.Config.MasterServerUrl + "\"!"); ThrowError("MasterServerUrl \"" + GameMain.Config.MasterServerUrl + "\"!");
} }
GameMain.Config.Save("config.xml"); GameMain.Config.Save("config.xml");
@@ -515,13 +416,13 @@ namespace Barotrauma
foreach (string saveFile in saveFiles) foreach (string saveFile in saveFiles)
{ {
System.IO.File.Delete(saveFile); System.IO.File.Delete(saveFile);
DebugConsole.NewMessage("Deleted " + saveFile, Color.Green); NewMessage("Deleted " + saveFile, Color.Green);
} }
if (System.IO.Directory.Exists(System.IO.Path.Combine(SaveUtil.SaveFolder, "temp"))) if (System.IO.Directory.Exists(System.IO.Path.Combine(SaveUtil.SaveFolder, "temp")))
{ {
System.IO.Directory.Delete(System.IO.Path.Combine(SaveUtil.SaveFolder, "temp"), true); System.IO.Directory.Delete(System.IO.Path.Combine(SaveUtil.SaveFolder, "temp"), true);
DebugConsole.NewMessage("Deleted temp save folder", Color.Green); NewMessage("Deleted temp save folder", Color.Green);
} }
if (System.IO.Directory.Exists(ServerLog.SavePath)) if (System.IO.Directory.Exists(ServerLog.SavePath))
@@ -531,14 +432,14 @@ namespace Barotrauma
foreach (string logFile in logFiles) foreach (string logFile in logFiles)
{ {
System.IO.File.Delete(logFile); System.IO.File.Delete(logFile);
DebugConsole.NewMessage("Deleted " + logFile, Color.Green); NewMessage("Deleted " + logFile, Color.Green);
} }
} }
if (System.IO.File.Exists("filelist.xml")) if (System.IO.File.Exists("filelist.xml"))
{ {
System.IO.File.Delete("filelist.xml"); System.IO.File.Delete("filelist.xml");
DebugConsole.NewMessage("Deleted filelist", Color.Green); NewMessage("Deleted filelist", Color.Green);
} }
@@ -546,39 +447,33 @@ namespace Barotrauma
{ {
System.IO.File.Delete("Submarines/TutorialSub.sub"); System.IO.File.Delete("Submarines/TutorialSub.sub");
DebugConsole.NewMessage("Deleted TutorialSub from the submarine folder", Color.Green); NewMessage("Deleted TutorialSub from the submarine folder", Color.Green);
} }
if (System.IO.File.Exists(GameServer.SettingsFile)) if (System.IO.File.Exists(GameServer.SettingsFile))
{ {
System.IO.File.Delete(GameServer.SettingsFile); System.IO.File.Delete(GameServer.SettingsFile);
DebugConsole.NewMessage("Deleted server settings", Color.Green); NewMessage("Deleted server settings", Color.Green);
} }
if (System.IO.File.Exists(GameServer.ClientPermissionsFile)) if (System.IO.File.Exists(GameServer.ClientPermissionsFile))
{ {
System.IO.File.Delete(GameServer.ClientPermissionsFile); System.IO.File.Delete(GameServer.ClientPermissionsFile);
DebugConsole.NewMessage("Deleted client permission file", Color.Green); NewMessage("Deleted client permission file", Color.Green);
} }
if (System.IO.File.Exists("crashreport.txt")) if (System.IO.File.Exists("crashreport.txt"))
{ {
System.IO.File.Delete("crashreport.txt"); System.IO.File.Delete("crashreport.txt");
DebugConsole.NewMessage("Deleted crashreport.txt", Color.Green); NewMessage("Deleted crashreport.txt", Color.Green);
} }
if (!System.IO.File.Exists("Content/Map/TutorialSub.sub")) if (!System.IO.File.Exists("Content/Map/TutorialSub.sub"))
{ {
DebugConsole.ThrowError("TutorialSub.sub not found!"); ThrowError("TutorialSub.sub not found!");
} }
}));
break;
default:
return false; //command not found
break;
}
return true; //command found
} }
} }
} }
@@ -304,18 +304,10 @@ namespace Barotrauma
{ {
case '\b': //backspace case '\b': //backspace
if (Text.Length > 0) Text = Text.Substring(0, Text.Length - 1); if (Text.Length > 0) Text = Text.Substring(0, Text.Length - 1);
if (OnTextChanged != null) OnTextChanged(this, Text);
break; break;
//case '\r': //return
// if (OnEnterPressed != null)
// OnEnterPressed(this);
// break;
//case '\t': //tab
// if (OnTabPressed != null)
// OnTabPressed(this);
// break;
} }
if (OnTextChanged != null) OnTextChanged(this, Text);
} }
public void ReceiveSpecialInput(Keys key) public void ReceiveSpecialInput(Keys key)
@@ -22,116 +22,82 @@ namespace Barotrauma
} }
} }
private static bool ExecProjSpecific(string[] commands) private static void InitProjectSpecific()
{ {
switch (commands[0].ToLower()) commands.Add(new Command("restart|reset", "restart/reset: Close and restart the server.", (string[] args) =>
{ {
case "help":
NewMessage("start: start a new round", Color.Cyan);
NewMessage("end: end the current round", Color.Cyan);
NewMessage("restart: restart the server", Color.Cyan);
NewMessage("quit: exit the game", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("say [chat message]: send a chat message", Color.Cyan);
NewMessage("clientlist: list the names and IPs of the connected clients", Color.Cyan);
NewMessage("kick [name]: kick a player out from the server", Color.Cyan);
NewMessage("ban [name]: kick and ban the player from the server", Color.Cyan);
NewMessage("banip [IP address]: ban the IP address from the server", Color.Cyan);
NewMessage("debugdraw: toggles the \"debug draw mode\"", Color.Cyan);
NewMessage("netstats: toggles the visibility of the network statistics panel", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("servername [name]: change the name of the server", Color.Cyan);
NewMessage("servermsg [message]: change the message in the server lobby", Color.Cyan);
NewMessage("seed [seed]: changes the level seed for the next round", Color.Cyan);
NewMessage("gamemode [name]: select the specified game mode for the next round", Color.Cyan);
NewMessage("gamemode [index]: select the specified game mode (0 = sandbox, 1 = mission, etc)", Color.Cyan);
NewMessage("submarine [name]: select the specified game mode for the next round", Color.Cyan);
NewMessage("shuttle [name]: select the specified submarine as the respawn shuttle for the next round", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("spawn [creaturename] [near/inside/outside]: spawn a creature at a random spawnpoint (use the second parameter to only select spawnpoints near/inside/outside the submarine)", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("heal [character name]: restore the specified character to full health", Color.Cyan);
NewMessage("revive [character name]: bring the specified character back from the dead", Color.Cyan);
NewMessage("killmonsters: immediately kills all AI-controlled enemies in the level", Color.Cyan);
NewMessage(" ", Color.Cyan);
NewMessage("fixwalls: fixes all the walls", Color.Cyan);
NewMessage("fixitems: fixes every item/device in the sub", Color.Cyan);
NewMessage("oxygen: replenishes the oxygen in every room to 100%", Color.Cyan);
NewMessage("power [amount]: immediately sets the temperature of the reactor to the specified value", Color.Cyan);
break;
case "restart":
case "reset":
NewMessage("*****************", Color.Lime); NewMessage("*****************", Color.Lime);
NewMessage("RESTARTING SERVER", Color.Lime); NewMessage("RESTARTING SERVER", Color.Lime);
NewMessage("*****************", Color.Lime); NewMessage("*****************", Color.Lime);
GameMain.Instance.CloseServer(); GameMain.Instance.CloseServer();
GameMain.Instance.StartServer(); GameMain.Instance.StartServer();
break; }));
case "exit":
case "close": commands.Add(new Command("exit|quit|close", "exit/quit/close: Exit the application.", (string[] args) =>
case "quit": {
GameMain.ShouldRun = false; GameMain.ShouldRun = false;
break; }));
case "say":
case "msg": commands.Add(new Command("say", "say [message]: Send a chat message that displays \"HOST\" as the sender.", (string[] args) =>
string text = string.Join(" ", commands.Skip(1)); {
if (commands[0].ToLower() == "say") text = "HOST: " + text; string text = string.Join(" ", args);
text = "HOST: " + text;
GameMain.Server.SendChatMessage(text, ChatMessageType.Server); GameMain.Server.SendChatMessage(text, ChatMessageType.Server);
break; }));
case "servername":
GameMain.Server.Name = string.Join(" ", commands.Skip(1)); commands.Add(new Command("msg", "msg [message]: Send a chat message with no sender specified.", (string[] args) =>
GameMain.NetLobbyScreen.ChangeServerName(string.Join(" ", commands.Skip(1))); {
break; string text = string.Join(" ", args);
case "servermsg": GameMain.Server.SendChatMessage(text, ChatMessageType.Server);
GameMain.NetLobbyScreen.ChangeServerMessage(string.Join(" ", commands.Skip(1))); }));
break;
case "seed": commands.Add(new Command("servername", "servername [name]: Change the name of the server.", (string[] args) =>
GameMain.NetLobbyScreen.LevelSeed = string.Join(" ", commands.Skip(1)); {
break; GameMain.Server.Name = string.Join(" ", args);
case "gamemode": GameMain.NetLobbyScreen.ChangeServerName(string.Join(" ", args));
}));
commands.Add(new Command("servermsg", "servermsg [message]: Change the message displayed in the server lobby.", (string[] args) =>
{
GameMain.NetLobbyScreen.ChangeServerMessage(string.Join(" ", args));
}));
commands.Add(new Command("seed|levelseed", "seed/levelseed: Changes the level seed for the next round.", (string[] args) =>
{
GameMain.NetLobbyScreen.LevelSeed = string.Join(" ", args);
}));
commands.Add(new Command("gamemode", "gamemode [name]/[index]: Select the game mode for the next round. The parameter can either be the name or the index number of the game mode (0 = sandbox, 1 = mission, etc).", (string[] args) =>
{ {
int index = -1; int index = -1;
if (int.TryParse(string.Join(" ", commands.Skip(1)), out index)) if (int.TryParse(string.Join(" ", args), out index))
{ {
GameMain.NetLobbyScreen.SelectedModeIndex = index; GameMain.NetLobbyScreen.SelectedModeIndex = index;
} }
else else
{ {
GameMain.NetLobbyScreen.SelectedModeName = string.Join(" ", commands.Skip(1)); GameMain.NetLobbyScreen.SelectedModeName = string.Join(" ", args);
} }
NewMessage("Set gamemode to " + GameMain.NetLobbyScreen.SelectedModeName, Color.Cyan); NewMessage("Set gamemode to " + GameMain.NetLobbyScreen.SelectedModeName, Color.Cyan);
} }));
break;
case "mission": commands.Add(new Command("mission", "mission [name]/[index]: Select the mission type for the next round. The parameter can either be the name or the index number of the mission type (0 = first mission type, 1 = second mission type, etc).", (string[] args) =>
{ {
int index = -1; int index = -1;
if (int.TryParse(string.Join(" ", commands.Skip(1)), out index)) if (int.TryParse(string.Join(" ", args), out index))
{ {
GameMain.NetLobbyScreen.MissionTypeIndex = index; GameMain.NetLobbyScreen.MissionTypeIndex = index;
} }
else else
{ {
GameMain.NetLobbyScreen.MissionTypeName = string.Join(" ", commands.Skip(1)); GameMain.NetLobbyScreen.MissionTypeName = string.Join(" ", args);
} }
NewMessage("Set mission to " + GameMain.NetLobbyScreen.MissionTypeName, Color.Cyan); NewMessage("Set mission to " + GameMain.NetLobbyScreen.MissionTypeName, Color.Cyan);
} }));
break;
case "sub": commands.Add(new Command("sub|submarine", "submarine [name]: Select the submarine for the next round.", (string[] args) =>
case "submarine":
{ {
Submarine sub = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", commands.Skip(1)).ToLower()); Submarine sub = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", args).ToLower());
if (sub != null) if (sub != null)
{ {
@@ -139,11 +105,11 @@ namespace Barotrauma
} }
sub = GameMain.NetLobbyScreen.SelectedSub; sub = GameMain.NetLobbyScreen.SelectedSub;
NewMessage("Selected sub: " + sub.Name + (sub.HasTag(SubmarineTag.Shuttle) ? " (shuttle)" : ""), Color.Cyan); NewMessage("Selected sub: " + sub.Name + (sub.HasTag(SubmarineTag.Shuttle) ? " (shuttle)" : ""), Color.Cyan);
} }));
break;
case "shuttle": commands.Add(new Command("shuttle", "shuttle [name]: Select the specified submarine as the respawn shuttle for the next round.", (string[] args) =>
{ {
Submarine shuttle = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", commands.Skip(1)).ToLower()); Submarine shuttle = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", args).ToLower());
if (shuttle != null) if (shuttle != null)
{ {
@@ -151,40 +117,53 @@ namespace Barotrauma
} }
shuttle = GameMain.NetLobbyScreen.SelectedShuttle; shuttle = GameMain.NetLobbyScreen.SelectedShuttle;
NewMessage("Selected shuttle: " + shuttle.Name + (shuttle.HasTag(SubmarineTag.Shuttle) ? "" : " (not shuttle)"), Color.Cyan); NewMessage("Selected shuttle: " + shuttle.Name + (shuttle.HasTag(SubmarineTag.Shuttle) ? "" : " (not shuttle)"), Color.Cyan);
} }));
break;
case "startgame": commands.Add(new Command("startgame|startround|start", "start/startgame/startround: Start a new round.", (string[] args) =>
case "startround": {
case "start": if (Screen.Selected == GameMain.GameScreen) return;
if (Screen.Selected == GameMain.GameScreen) break;
if (!GameMain.Server.StartGame()) NewMessage("Failed to start a new round", Color.Yellow); if (!GameMain.Server.StartGame()) NewMessage("Failed to start a new round", Color.Yellow);
break; }));
case "endgame":
case "endround": commands.Add(new Command("endgame|endround|end", "end/endgame/endround: End the current round.", (string[] args) =>
case "end": {
if (Screen.Selected == GameMain.NetLobbyScreen) break; if (Screen.Selected == GameMain.NetLobbyScreen) return;
GameMain.Server.EndGame(); GameMain.Server.EndGame();
break; }));
case "entitydata":
Entity ent = Entity.FindEntityByID(Convert.ToUInt16(commands[1])); commands.Add(new Command("entitydata", "", (string[] args) =>
{
if (args.Length == 0) return;
Entity ent = Entity.FindEntityByID(Convert.ToUInt16(args[0]));
if (ent != null) if (ent != null)
{ {
NewMessage(ent.ToString(), Color.Lime); NewMessage(ent.ToString(), Color.Lime);
} }
break; }));
#if DEBUG #if DEBUG
case "eventdata": commands.Add(new Command("eventdata", "", (string[] args) =>
ServerEntityEvent ev = GameMain.Server.EntityEventManager.Events[Convert.ToUInt16(commands[1])]; {
if (args.Length == 0) return;
ServerEntityEvent ev = GameMain.Server.EntityEventManager.Events[Convert.ToUInt16(args[0])];
if (ev != null) if (ev != null)
{ {
NewMessage(ev.StackTrace, Color.Lime); NewMessage(ev.StackTrace, Color.Lime);
} }
break; }));
commands.Add(new Command("spamchatmessages", "", (string[] args) =>
{
int msgCount = 1000;
if (args.Length > 0) int.TryParse(args[0], out msgCount);
int msgLength = 50;
if (args.Length > 1) int.TryParse(args[1], out msgLength);
for (int i = 0; i < msgCount; i++)
{
GameMain.Server.SendChatMessage(ToolBox.RandomSeed(msgLength), ChatMessageType.Default);
}
}));
#endif #endif
default:
return false;
}
return true; //command found
} }
} }
} }
File diff suppressed because it is too large Load Diff