Skip to content

Commit

Permalink
Fix when dotnet MCGalaxy build is started through dotnet process (e.g…
Browse files Browse the repository at this point in the history
…. 'dotnet MCGalaxyCLI_core.dll'), that /restart would fail to work

Also fix exporting BLOB values via /server backup table, would generate invalid SQL that could not be subsequently imported again with /server import table
  • Loading branch information
UnknownShadow200 committed Aug 13, 2022
1 parent 009b317 commit 36ba055
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 38 deletions.
1 change: 0 additions & 1 deletion GUI/Window/Window.Map.cs
Expand Up @@ -16,7 +16,6 @@
permissions and limitations under the Licenses.
*/
using System;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using MCGalaxy.UI;
Expand Down
3 changes: 1 addition & 2 deletions MCGalaxy/Commands/Information/CmdAbout.cs
Expand Up @@ -109,8 +109,7 @@ public sealed class CmdAbout : Command2 {
}

static void OutputEntry(Player p, ref bool foundAny, Dictionary<int, string> names, BlockDBEntry entry) {
DateTime now = DateTime.UtcNow;
string name = null;
string name;
if (!names.TryGetValue(entry.PlayerID, out name)) {
name = NameConverter.FindName(entry.PlayerID);
names[entry.PlayerID] = name;
Expand Down
1 change: 0 additions & 1 deletion MCGalaxy/Commands/other/CmdAscend.cs
Expand Up @@ -17,7 +17,6 @@
*/
using System;
using MCGalaxy.Blocks;
using MCGalaxy.Commands.Fun;
using BlockID = System.UInt16;

namespace MCGalaxy.Commands.Misc {
Expand Down
1 change: 0 additions & 1 deletion MCGalaxy/Commands/other/CmdDescend.cs
Expand Up @@ -17,7 +17,6 @@
*/
using System;
using MCGalaxy.Blocks;
using MCGalaxy.Commands.Fun;
using BlockID = System.UInt16;

namespace MCGalaxy.Commands.Misc {
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Database/Backends/MySQL.cs
Expand Up @@ -258,7 +258,7 @@ sealed class MySQLReader : ISqlReader
Type colType = rdr.GetFieldType(col);

// TODO doubles not exact? probably doesn't matter
if (colType == typeof(string)) {
if (colType == typeof(string) || colType == typeof(byte[])) {
return Quote(GetString(col));
} else if (colType == typeof(DateTime)) {
return Quote(RawGetDateTime(col));
Expand Down
3 changes: 2 additions & 1 deletion MCGalaxy/Database/Backends/SQLiteBackend.cs
Expand Up @@ -543,7 +543,8 @@ public sealed class SQLiteDataReader : ISqlReader
if (affinity == TypeAffinity.Null) return "NULL";

string value = GetString(col);
if (affinity == TypeAffinity.Text) return Quote(value);
if (affinity == TypeAffinity.Text || affinity == TypeAffinity.Blob)
return Quote(value);

// TODO doubles not exact? probably doesn't matter
return value;
Expand Down
41 changes: 12 additions & 29 deletions MCGalaxy/Server/OperatingSystem.cs
Expand Up @@ -144,7 +144,6 @@ class UnixOS : IOperatingSystem
}
public override bool IsWindows { get { return false; } }

#if !NETSTANDARD
[DllImport("libc", SetLastError = true)]
static extern int execvp(string path, string[] argv);

Expand All @@ -170,40 +169,24 @@ class UnixOS : IOperatingSystem
//
// Note this issue does NOT happen with GUI mode for some reason - and also
// don't want to use excevp in GUI mode, otherwise the X socket FDs pile up
//
//
// a similar issue occurs with dotnet, but errors with this instead
// "IOException with 'I/O error' message
// ...
// at System.IO.StdInReader.ReadKey()

// try to exec using actual runtime path first, e.g. /usr/bin/mono-sgen
// try to exec using actual runtime path first
// e.g. /usr/bin/mono-sgen, /home/test/.dotnet/dotnet
string exe = Process.GetCurrentProcess().MainModule.FileName;
execvp(exe, new string[] { exe, Server.GetRestartPath() });
execvp(exe, new string[] { exe, Server.RestartPath, null });
Console.WriteLine("execvp {0} failed: {1}", exe, Marshal.GetLastWin32Error());

#if !NETSTANDARD
// .. and fallback to mono if that doesn't work for some reason
execvp("mono", new string[] { "mono", Server.GetRestartPath() });
execvp("mono", new string[] { "mono", Server.RestartPath, null });
Console.WriteLine("execvp mono failed: {0}", Marshal.GetLastWin32Error());
}
#else
[DllImport("libc", SetLastError = true)]
unsafe static extern int execvp(byte* path, byte** argv);

unsafe static void HACK_Execvp() {
// similar issue as with Mono, but happens with this instead
// "IOException with 'I/O error' message
// ...
// at System.IO.StdInReader.ReadKey()
//
// Trying to use heap allocated string sometimes causes EFAULT error,
// therefore manually allocate arguments on the stack instead
byte* path = stackalloc byte[8192];
byte** args = stackalloc byte*[2];
args[0] = path;
args[1] = (byte*)IntPtr.Zero;
// TODO add null argument at end, see if that works

byte[] tmp = Encoding.UTF8.GetBytes(Server.GetRestartPath());
Marshal.Copy(tmp, 0, (IntPtr)path, tmp.Length);

execvp(path, args);
Console.WriteLine("execvp failed: {0}", Marshal.GetLastWin32Error());
}
#endif
}
}
}
2 changes: 0 additions & 2 deletions MCGalaxy/util/Formatting/Matcher.cs
Expand Up @@ -18,10 +18,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using MCGalaxy.Eco;
using MCGalaxy.Modules.Awards;

namespace MCGalaxy {
Expand Down

0 comments on commit 36ba055

Please sign in to comment.