diff --git a/TBConsole/TBConsole.csproj b/TBConsole/TBConsole.csproj
index 4fd66f2..6d02b3b 100644
--- a/TBConsole/TBConsole.csproj
+++ b/TBConsole/TBConsole.csproj
@@ -5,8 +5,9 @@
netcoreapp3.1
Exe
-->
- netstandard2.0
+ netstandard2.1
NorbiPeti
+ 8
@@ -18,10 +19,10 @@
..\..\ref\Plugins\TechbloxModdingAPI.dll
- ..\..\ref\TechbloxPreview_Data\Managed\IllusionPlugin.dll
+ ..\..\ref\Techblox_Data\Managed\IllusionPlugin.dll
- ..\..\ref\TechbloxPreview_Data\Managed\UnityEngine.CoreModule.dll
+ ..\..\ref\Techblox_Data\Managed\UnityEngine.CoreModule.dll
diff --git a/TBConsole/TBConsoleMod.cs b/TBConsole/TBConsoleMod.cs
index 0b51db6..5f8fd11 100644
--- a/TBConsole/TBConsoleMod.cs
+++ b/TBConsole/TBConsoleMod.cs
@@ -41,38 +41,48 @@ namespace TBConsole
if (_logHandler == null)
Debug.unityLogger.logHandler = _logHandler = new UnityLogHandler(Debug.unityLogger.logHandler);
_logHandler.StartCollectingLogMessages();
- bool inString = false;
- var cmdparts = new List();
- command = command.Trim();
- int lastIndex = 0;
- for (int i = 0; i <= command.Length; i++)
+ try
{
- if (i < command.Length && command[i] == '"') inString = !inString;
- else if (!inString && (i == command.Length || command[i] == ' '))
+ bool inString = false;
+ var cmdparts = new List();
+ command = command.Trim();
+ int lastIndex = 0;
+ for (int i = 0; i <= command.Length; i++)
{
- cmdparts.Add(command.Substring(lastIndex, i - lastIndex).Trim('"'));
- lastIndex = i + 1;
+ if (i < command.Length && command[i] == '"') inString = !inString;
+ else if (!inString && (i == command.Length || command[i] == ' '))
+ {
+ cmdparts.Add(command.Substring(lastIndex, i - lastIndex).Trim('"'));
+ lastIndex = i + 1;
+ }
+ }
+
+ switch (cmdparts.Count)
+ {
+ case 1:
+ ExistingCommands.Call(cmdparts[0]);
+ break;
+ case 2:
+ ExistingCommands.Call(cmdparts[0], cmdparts[1]);
+ break;
+ case 3:
+ ExistingCommands.Call(cmdparts[0], cmdparts[1], cmdparts[2]);
+ break;
+ case 4:
+ ExistingCommands.Call(cmdparts[0], cmdparts[1], cmdparts[2], cmdparts[3]);
+ break;
+ default:
+ return "Too many arguments! Maximum for default commands is 3";
}
}
-
- switch (cmdparts.Count)
+ catch (Exception e) when (e is CommandException || e is TargetParameterCountException)
{
- case 1:
- ExistingCommands.Call(cmdparts[0]);
- break;
- case 2:
- ExistingCommands.Call(cmdparts[0], cmdparts[1]);
- break;
- case 3:
- ExistingCommands.Call(cmdparts[0], cmdparts[1], cmdparts[2]);
- break;
- case 4:
- ExistingCommands.Call(cmdparts[0], cmdparts[1], cmdparts[2], cmdparts[3]);
- break;
- default:
- return "Too many arguments! Maximum for default commands is 3";
+ Logging.CommandLogWarning(e.Message);
+ }
+ catch (Exception e)
+ {
+ Logging.CommandLogWarning(e);
}
-
string result = _logHandler.FinishCollectingLogMessages();
return $"Got it: {command}\n{result}";
}
diff --git a/TBConsole/WebServer.cs b/TBConsole/WebServer.cs
index 6366725..e311273 100644
--- a/TBConsole/WebServer.cs
+++ b/TBConsole/WebServer.cs
@@ -40,25 +40,20 @@ namespace TBConsole
{
var context = await _listener.GetContextAsync();
string request = await new StreamReader(context.Request.InputStream).ReadToEndAsync();
- string resp;
- switch (context.Request.Url.AbsolutePath)
+ string resp = context.Request.Url.AbsolutePath switch
{
- case "/command":
- resp = _commandReceiver(request);
- break;
- case "/commands":
- resp = _commandsListSender();
- break;
- default:
- resp = "";
- break;
- }
+ "/command" => _commandReceiver(request),
+ "/commands" => _commandsListSender(),
+ _ => ""
+ };
string origin = context.Request.Headers["Origin"];
if (origin == "http://localhost:4200" || origin == "https://tb-console.web.app")
context.Response.AddHeader("Access-Control-Allow-Origin", origin);
- var sw = new StreamWriter(context.Response.OutputStream);
+ await using var sw = new StreamWriter(context.Response.OutputStream);
await sw.WriteLineAsync(resp);
- sw.Close();
+ }
+ catch (ObjectDisposedException)
+ {
}
catch (Exception e)
{