Server responses to clients using console commands ("granted permissions to client", error messages, etc) are displayed in the client's debug console instead of the chat box. Client command usage is included in server logs.

This commit is contained in:
Joonas Rikkonen
2017-12-20 19:18:32 +02:00
parent 91699b26a6
commit b3c3970209
5 changed files with 47 additions and 30 deletions
@@ -44,6 +44,10 @@ namespace Barotrauma.Networking
{ {
new GUIMessageBox("", txt); new GUIMessageBox("", txt);
} }
else if (type == ChatMessageType.Console)
{
DebugConsole.NewMessage(txt, MessageColor[(int)ChatMessageType.Console]);
}
else else
{ {
GameMain.Client.AddChatMessage(txt, type, senderName, senderCharacter); GameMain.Client.AddChatMessage(txt, type, senderName, senderCharacter);
@@ -157,12 +157,12 @@ namespace Barotrauma
}, null, }, null,
(Client client, Vector2 cursorWorldPos, string[] args) => (Client client, Vector2 cursorWorldPos, string[] args) =>
{ {
GameMain.Server.SendChatMessage("***************", client); GameMain.Server.SendConsoleMessage("***************", client);
foreach (Client c in GameMain.Server.ConnectedClients) foreach (Client c in GameMain.Server.ConnectedClients)
{ {
GameMain.Server.SendChatMessage("- " + c.ID.ToString() + ": " + c.Name + ", " + c.Connection.RemoteEndPoint.Address.ToString(), client); GameMain.Server.SendConsoleMessage("- " + c.ID.ToString() + ": " + c.Name + ", " + c.Connection.RemoteEndPoint.Address.ToString(), client);
} }
GameMain.Server.SendChatMessage("***************", client); GameMain.Server.SendConsoleMessage("***************", client);
})); }));
@@ -222,7 +222,7 @@ namespace Barotrauma
{ {
HumanAIController.DisableCrewAI = true; HumanAIController.DisableCrewAI = true;
NewMessage("Crew AI disabled by \"" + client.Name + "\"", Color.White); NewMessage("Crew AI disabled by \"" + client.Name + "\"", Color.White);
GameMain.Server.SendChatMessage("Crew AI disabled", client); GameMain.Server.SendConsoleMessage("Crew AI disabled", client);
})); }));
commands.Add(new Command("enablecrewai", "enablecrewai: Enable the AI of the NPCs in the crew.", (string[] args) => commands.Add(new Command("enablecrewai", "enablecrewai: Enable the AI of the NPCs in the crew.", (string[] args) =>
@@ -235,7 +235,7 @@ namespace Barotrauma
{ {
HumanAIController.DisableCrewAI = false; HumanAIController.DisableCrewAI = false;
NewMessage("Crew AI enabled by \"" + client.Name + "\"", Color.White); NewMessage("Crew AI enabled by \"" + client.Name + "\"", Color.White);
GameMain.Server.SendChatMessage("Crew AI enabled", client); GameMain.Server.SendConsoleMessage("Crew AI enabled", client);
})); }));
commands.Add(new Command("autorestart", "autorestart [true/false]: Enable or disable round auto-restart.", (string[] args) => commands.Add(new Command("autorestart", "autorestart [true/false]: Enable or disable round auto-restart.", (string[] args) =>
@@ -384,7 +384,7 @@ namespace Barotrauma
var client = GameMain.Server.ConnectedClients.Find(c => c.ID == id); var client = GameMain.Server.ConnectedClients.Find(c => c.ID == id);
if (client == null) if (client == null)
{ {
GameMain.Server.SendChatMessage("Client id \"" + id + "\" not found.", senderClient); GameMain.Server.SendConsoleMessage("Client id \"" + id + "\" not found.", senderClient);
return; return;
} }
@@ -400,13 +400,13 @@ namespace Barotrauma
{ {
if (!Enum.TryParse(perm, true, out permission)) if (!Enum.TryParse(perm, true, out permission))
{ {
GameMain.Server.SendChatMessage(perm + " is not a valid permission!", senderClient); GameMain.Server.SendConsoleMessage(perm + " is not a valid permission!", senderClient);
return; return;
} }
} }
client.GivePermission(permission); client.GivePermission(permission);
GameMain.Server.UpdateClientPermissions(client); GameMain.Server.UpdateClientPermissions(client);
GameMain.Server.SendChatMessage("Granted " + perm + " permissions to " + client.Name + ".", senderClient); GameMain.Server.SendConsoleMessage("Granted " + perm + " permissions to " + client.Name + ".", senderClient);
NewMessage(senderClient.Name + " granted " + perm + " permissions to " + client.Name + ".", Color.White); NewMessage(senderClient.Name + " granted " + perm + " permissions to " + client.Name + ".", Color.White);
})); }));
@@ -472,7 +472,7 @@ namespace Barotrauma
var client = GameMain.Server.ConnectedClients.Find(c => c.ID == id); var client = GameMain.Server.ConnectedClients.Find(c => c.ID == id);
if (client == null) if (client == null)
{ {
GameMain.Server.SendChatMessage("Client id \"" + id + "\" not found.", senderClient); GameMain.Server.SendConsoleMessage("Client id \"" + id + "\" not found.", senderClient);
return; return;
} }
@@ -488,13 +488,13 @@ namespace Barotrauma
{ {
if (!Enum.TryParse(perm, true, out permission)) if (!Enum.TryParse(perm, true, out permission))
{ {
GameMain.Server.SendChatMessage(perm + " is not a valid permission!", senderClient); GameMain.Server.SendConsoleMessage(perm + " is not a valid permission!", senderClient);
return; return;
} }
} }
client.RemovePermission(permission); client.RemovePermission(permission);
GameMain.Server.UpdateClientPermissions(client); GameMain.Server.UpdateClientPermissions(client);
GameMain.Server.SendChatMessage("Revoked " + perm + " permissions from " + client.Name + ".", senderClient); GameMain.Server.SendConsoleMessage("Revoked " + perm + " permissions from " + client.Name + ".", senderClient);
NewMessage(senderClient.Name + " revoked " + perm + " permissions from " + client.Name + ".", Color.White); NewMessage(senderClient.Name + " revoked " + perm + " permissions from " + client.Name + ".", Color.White);
})); }));
@@ -682,7 +682,7 @@ namespace Barotrauma
Submarine.MainSub.GodMode = !Submarine.MainSub.GodMode; Submarine.MainSub.GodMode = !Submarine.MainSub.GodMode;
NewMessage((Submarine.MainSub.GodMode ? "Godmode turned on by \"" : "Godmode off by \"") + client.Name+"\"", Color.White); NewMessage((Submarine.MainSub.GodMode ? "Godmode turned on by \"" : "Godmode off by \"") + client.Name+"\"", Color.White);
GameMain.Server.SendChatMessage(Submarine.MainSub.GodMode ? "Godmode on" : "Godmode off", client); GameMain.Server.SendConsoleMessage(Submarine.MainSub.GodMode ? "Godmode on" : "Godmode off", client);
})); }));
commands.Add(new Command("lockx", "lockx: Lock horizontal movement of the main submarine.", (string[] args) => commands.Add(new Command("lockx", "lockx: Lock horizontal movement of the main submarine.", (string[] args) =>
@@ -953,7 +953,7 @@ namespace Barotrauma
int separatorIndex = Array.IndexOf(args, ";"); int separatorIndex = Array.IndexOf(args, ";");
if (separatorIndex == -1 || args.Length < 3) if (separatorIndex == -1 || args.Length < 3)
{ {
GameMain.Server.SendChatMessage("Invalid parameters. The command should be formatted as \"setclientcharacter [client] ; [character]\"", senderClient); GameMain.Server.SendConsoleMessage("Invalid parameters. The command should be formatted as \"setclientcharacter [client] ; [character]\"", senderClient);
return; return;
} }
@@ -964,7 +964,7 @@ namespace Barotrauma
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)
{ {
GameMain.Server.SendChatMessage("Client \"" + clientName + "\" not found.", senderClient); GameMain.Server.SendConsoleMessage("Client \"" + clientName + "\" not found.", senderClient);
} }
var character = FindMatchingCharacter(argsRight, false); var character = FindMatchingCharacter(argsRight, false);
@@ -1076,7 +1076,7 @@ namespace Barotrauma
var campaign = GameMain.GameSession?.GameMode as CampaignMode; var campaign = GameMain.GameSession?.GameMode as CampaignMode;
if (campaign == null) if (campaign == null)
{ {
GameMain.Server.SendChatMessage("No campaign active!", senderClient); GameMain.Server.SendConsoleMessage("No campaign active!", senderClient);
return; return;
} }
@@ -1084,12 +1084,12 @@ namespace Barotrauma
if (args.Length < 1 || !int.TryParse(args[0], out destinationIndex)) return; if (args.Length < 1 || !int.TryParse(args[0], out destinationIndex)) return;
if (destinationIndex < 0 || destinationIndex >= campaign.Map.CurrentLocation.Connections.Count) if (destinationIndex < 0 || destinationIndex >= campaign.Map.CurrentLocation.Connections.Count)
{ {
GameMain.Server.SendChatMessage("Index out of bounds!", senderClient); GameMain.Server.SendConsoleMessage("Index out of bounds!", senderClient);
return; return;
} }
Location location = campaign.Map.CurrentLocation.Connections[destinationIndex].OtherLocation(campaign.Map.CurrentLocation); Location location = campaign.Map.CurrentLocation.Connections[destinationIndex].OtherLocation(campaign.Map.CurrentLocation);
campaign.Map.SelectLocation(location); campaign.Map.SelectLocation(location);
GameMain.Server.SendChatMessage(location.Name + " selected.", senderClient); GameMain.Server.SendConsoleMessage(location.Name + " selected.", senderClient);
})); }));
#if DEBUG #if DEBUG
@@ -1289,7 +1289,8 @@ namespace Barotrauma
if (string.IsNullOrWhiteSpace(command)) return; if (string.IsNullOrWhiteSpace(command)) return;
if (!client.HasPermission(ClientPermissions.ConsoleCommands)) if (!client.HasPermission(ClientPermissions.ConsoleCommands))
{ {
GameMain.Server.SendChatMessage("You are not permitted to use console commands!", client); GameMain.Server.SendConsoleMessage("You are not permitted to use console commands!", client);
GameServer.Log(client.Name + " attempted to execute the console command \"" + command + "\" without a permission to use console commands.", ServerLog.MessageType.ConsoleUsage);
return; return;
} }
@@ -1297,22 +1298,24 @@ namespace Barotrauma
Command matchingCommand = commands.Find(c => c.names.Contains(splitCommand[0].ToLowerInvariant())); Command matchingCommand = commands.Find(c => c.names.Contains(splitCommand[0].ToLowerInvariant()));
if (matchingCommand != null && !client.PermittedConsoleCommands.Contains(matchingCommand)) if (matchingCommand != null && !client.PermittedConsoleCommands.Contains(matchingCommand))
{ {
GameMain.Server.SendChatMessage("You are not permitted to use the command\"" + matchingCommand.names[0] + "\"!", client); GameMain.Server.SendConsoleMessage("You are not permitted to use the command\"" + matchingCommand.names[0] + "\"!", client);
GameServer.Log(client.Name + " attempted to execute the console command \"" + command + "\" without a permission to use the command.", ServerLog.MessageType.ConsoleUsage);
return; return;
} }
else if (matchingCommand == null) else if (matchingCommand == null)
{ {
GameMain.Server.SendChatMessage("Command \"" + splitCommand[0] + "\" not found.", client); GameMain.Server.SendConsoleMessage("Command \"" + splitCommand[0] + "\" not found.", client);
return; return;
} }
try try
{ {
matchingCommand.ServerExecuteOnClientRequest(client, cursorWorldPos, splitCommand.Skip(1).ToArray()); matchingCommand.ServerExecuteOnClientRequest(client, cursorWorldPos, splitCommand.Skip(1).ToArray());
GameServer.Log("Console command \"" + command + "\" executed by " + client.Name + ".", ServerLog.MessageType.ConsoleUsage);
} }
catch (Exception e) catch (Exception e)
{ {
ThrowError("Executing the command \"" + matchingCommand.names[0]+"\" by request from \""+client.Name+"\" failed.", e); ThrowError("Executing the command \"" + matchingCommand.names[0] + "\" by request from \"" + client.Name + "\" failed.", e);
} }
} }
@@ -7,7 +7,7 @@ namespace Barotrauma.Networking
{ {
enum ChatMessageType enum ChatMessageType
{ {
Default, Error, Dead, Server, Radio, Private, MessageBox Default, Error, Dead, Server, Radio, Private, Console, MessageBox
} }
partial class ChatMessage partial class ChatMessage
@@ -25,7 +25,8 @@ namespace Barotrauma.Networking
new Color(63, 72, 204), //dead new Color(63, 72, 204), //dead
new Color(157, 225, 160), //server new Color(157, 225, 160), //server
new Color(238, 208, 0), //radio new Color(238, 208, 0), //radio
new Color(228, 199, 27) //private new Color(228, 199, 27), //private
new Color(255, 255, 255) //console
}; };
public readonly string Text; public readonly string Text;
@@ -1634,6 +1634,12 @@ namespace Barotrauma.Networking
SendChatMessage(msg, recipient); SendChatMessage(msg, recipient);
} }
public void SendConsoleMessage(string txt, Client recipient)
{
ChatMessage msg = ChatMessage.Create("", txt, ChatMessageType.Console, null);
SendChatMessage(msg, recipient);
}
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 ?
@@ -28,18 +28,20 @@ namespace Barotrauma.Networking
Attack, Attack,
Spawning, Spawning,
ServerMessage, ServerMessage,
ConsoleUsage,
Error Error
} }
private readonly Color[] messageColor = private readonly Color[] messageColor =
{ {
Color.LightBlue, Color.LightBlue, //Chat
new Color(255, 142, 0), new Color(255, 142, 0), //ItemInteraction
new Color(238, 208, 0), new Color(238, 208, 0), //Inventory
new Color(204, 74, 78), new Color(204, 74, 78), //Attack
new Color(163, 73, 164), new Color(163, 73, 164), //Spawning
new Color(157, 225, 160), new Color(157, 225, 160), //ServerMessage
Color.Red new Color(0, 162, 232), //ConsoleUsage
Color.Red //Error
}; };
private readonly string[] messageTypeName = private readonly string[] messageTypeName =
@@ -50,6 +52,7 @@ namespace Barotrauma.Networking
"Attack & death", "Attack & death",
"Spawning", "Spawning",
"Server message", "Server message",
"Console usage",
"Error" "Error"
}; };