v0.13.0.11

This commit is contained in:
Joonas Rikkonen
2021-04-22 17:33:08 +03:00
parent 0697d7fc64
commit 8bb31f2893
391 changed files with 17271 additions and 5949 deletions
@@ -73,17 +73,27 @@ namespace Barotrauma
Stopwatch sw = new Stopwatch();
sw.Start();
int consoleWidth = Console.WindowWidth;
if (consoleWidth < 5) consoleWidth = 5;
int consoleHeight = Console.WindowHeight;
if (consoleHeight < 5) consoleHeight = 5;
int consoleWidth = 0;
int consoleHeight = 0;
if(!Console.IsOutputRedirected)
{
consoleWidth = Console.WindowWidth;
if (consoleWidth < 5) consoleWidth = 5;
consoleHeight = Console.WindowHeight;
if (consoleHeight < 5) consoleHeight = 5;
}
//dequeue messages
lock (queuedMessages)
{
if (queuedMessages.Count > 0)
{
Console.CursorLeft = 0;
if (!Console.IsOutputRedirected)
{
Console.CursorLeft = 0;
}
while (queuedMessages.Count > 0)
{
ColoredText msg = queuedMessages.Dequeue();
@@ -102,15 +112,21 @@ namespace Barotrauma
if (msg.IsCommand) commandMemory.Add(msgTxt);
int paddingLen = consoleWidth - (msg.Text.Length % consoleWidth)-1;
msgTxt += new string(' ', paddingLen>0 ? paddingLen : 0);
if(!Console.IsOutputRedirected)
{
int paddingLen = consoleWidth - (msg.Text.Length % consoleWidth) - 1;
msgTxt += new string(' ', paddingLen > 0 ? paddingLen : 0);
Console.ForegroundColor = XnaToConsoleColor.Convert(msg.Color);
Console.ForegroundColor = XnaToConsoleColor.Convert(msg.Color);
}
Console.WriteLine(msgTxt);
if (sw.ElapsedMilliseconds >= maxTime) { break; }
}
RewriteInputToCommandLine(input);
if(!Console.IsOutputRedirected)
{
RewriteInputToCommandLine(input);
}
}
if (Messages.Count > MaxMessages)
{
@@ -118,73 +134,78 @@ namespace Barotrauma
}
}
//read player input
bool rewriteInput = false;
while (Console.KeyAvailable)
// No good way to display input when console output is redirected, and can't read from redirected input using KeyAvailable.
if(!Console.IsOutputRedirected && !Console.IsInputRedirected)
{
if (sw.ElapsedMilliseconds >= maxTime)
//read player input
bool rewriteInput = false;
while (Console.KeyAvailable)
{
rewriteInput = false;
break;
}
rewriteInput = true;
ConsoleKeyInfo key = Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.Enter:
lock (QueuedCommands)
{
QueuedCommands.Add(input);
}
input = "";
memoryIndex = -1;
if (sw.ElapsedMilliseconds >= maxTime)
{
rewriteInput = false;
break;
case ConsoleKey.Backspace:
if (input.Length > 0) input = input.Substring(0, input.Length - 1);
memoryIndex = -1;
break;
case ConsoleKey.LeftArrow:
input = AutoComplete(input, -1);
break;
case ConsoleKey.RightArrow:
input = AutoComplete(input, 1);
break;
case ConsoleKey.UpArrow:
memoryIndex--;
if (memoryIndex < 0) memoryIndex = commandMemory.Count - 1;
if (memoryIndex >= commandMemory.Count) memoryIndex = commandMemory.Count - 1;
if (memoryIndex >= 0)
{
input = commandMemory[memoryIndex];
}
break;
case ConsoleKey.DownArrow:
memoryIndex++;
if (memoryIndex < 0) memoryIndex = 0;
if (memoryIndex >= commandMemory.Count) memoryIndex = 0;
if (commandMemory.Count>0)
{
input = commandMemory[memoryIndex];
}
break;
case ConsoleKey.Tab:
if (input.Length > 0)
{
input = AutoComplete(input, 0);
}
rewriteInput = true;
ConsoleKeyInfo key = Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.Enter:
lock (QueuedCommands)
{
QueuedCommands.Add(input);
}
input = "";
memoryIndex = -1;
}
break;
default:
if (key.KeyChar != 0)
{
input += key.KeyChar;
break;
case ConsoleKey.Backspace:
if (input.Length > 0) input = input.Substring(0, input.Length - 1);
ResetAutoComplete();
memoryIndex = -1;
}
ResetAutoComplete();
break;
break;
case ConsoleKey.LeftArrow:
input = AutoComplete(input, -1);
break;
case ConsoleKey.RightArrow:
input = AutoComplete(input, 1);
break;
case ConsoleKey.UpArrow:
memoryIndex--;
if (memoryIndex < 0) memoryIndex = commandMemory.Count - 1;
if (memoryIndex >= commandMemory.Count) memoryIndex = commandMemory.Count - 1;
if (memoryIndex >= 0)
{
input = commandMemory[memoryIndex];
}
break;
case ConsoleKey.DownArrow:
memoryIndex++;
if (memoryIndex < 0) memoryIndex = 0;
if (memoryIndex >= commandMemory.Count) memoryIndex = 0;
if (commandMemory.Count>0)
{
input = commandMemory[memoryIndex];
}
break;
case ConsoleKey.Tab:
if (input.Length > 0)
{
input = AutoComplete(input, 0);
memoryIndex = -1;
}
break;
default:
if (key.KeyChar != 0)
{
input += key.KeyChar;
memoryIndex = -1;
}
ResetAutoComplete();
break;
}
}
if (rewriteInput) { RewriteInputToCommandLine(input); }
}
if (rewriteInput) { RewriteInputToCommandLine(input); }
sw.Stop();
}
@@ -512,6 +533,13 @@ namespace Barotrauma
NewMessage(perm + " is not a valid permission!", Color.Red);
return;
}
if (permission == ClientPermissions.None)
{
NewMessage($"No permissions were given to {client.Name}. Did you mean \"revokeperm {client.Name} All\"?");
return;
}
client.GivePermission(permission);
GameMain.Server.UpdateClientPermissions(client);
NewMessage("Granted " + perm + " permissions to " + client.Name + ".", Color.White);
@@ -539,10 +567,13 @@ namespace Barotrauma
return;
}
NewMessage("Valid permissions are:", Color.White);
foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions)))
if (args.Length < 2)
{
NewMessage(" - " + permission.ToString(), Color.White);
NewMessage("Valid permissions are:", Color.White);
foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions)))
{
NewMessage(" - " + permission.ToString(), Color.White);
}
}
ShowQuestionPrompt("Permission to revoke from \"" + client.Name + "\"?", (perm) =>
{
@@ -715,7 +746,6 @@ namespace Barotrauma
{
NewMessage("Revoked \"" + client.Name + "\"'s permission to use the console commands " + string.Join(", ", revokedCommands.Select(c => c.names[0])) + ".", Color.White);
}
}, args, 1);
});
@@ -1801,6 +1831,14 @@ namespace Barotrauma
GameMain.Server.SendConsoleMessage(perm + " is not a valid permission!", senderClient);
return;
}
if (permission == ClientPermissions.None)
{
GameMain.Server.SendConsoleMessage($"No permissions were given to {client.Name}. Did you mean \"revokeperm {client.Name} All\"?", senderClient);
NewMessage($"No permissions were given to {client.Name}. Did you mean \"revokeperm {client.Name} All\"?");
return;
}
client.GivePermission(permission);
GameMain.Server.UpdateClientPermissions(client);
GameMain.Server.SendConsoleMessage("Granted " + perm + " permissions to " + client.Name + ".", senderClient);
@@ -1954,7 +1992,6 @@ namespace Barotrauma
if (revokeAll)
{
revokedCommands.AddRange(commands);
client.RemovePermission(ClientPermissions.ConsoleCommands);
}
else
{
@@ -1971,10 +2008,13 @@ namespace Barotrauma
revokedCommands.Add(matchingCommand);
}
}
client.GivePermission(ClientPermissions.ConsoleCommands);
}
client.SetPermissions(client.Permissions, client.PermittedConsoleCommands.Except(revokedCommands).ToList());
if (client.PermittedConsoleCommands.Count == 0)
{
client.RemovePermission(ClientPermissions.ConsoleCommands);
}
GameMain.Server.UpdateClientPermissions(client);
GameMain.Server.SendConsoleMessage("Revoked \"" + client.Name + "\"'s permission to use the console commands " + string.Join(", ", revokedCommands.Select(c => c.names[0])) + ".", senderClient);
if (revokeAll)