Skip to content

Commit

Permalink
Cross-platform compatability
Browse files Browse the repository at this point in the history
* Process exit handler is cross-platform.
* Copy Data folder and GameServer.ini when building.
* Set version to 1.0.0
  • Loading branch information
Makkkkus committed Dec 4, 2022
1 parent b973b8d commit b17fade
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 547 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,6 @@ FodyWeavers.xsd

**_log.txt
**_log_backup.txt
*.log
*.log
*.save
ServerID.txt
500 changes: 0 additions & 500 deletions Data/Glossery.json

This file was deleted.

1 change: 0 additions & 1 deletion Data/Modules.json

This file was deleted.

File renamed without changes.
7 changes: 5 additions & 2 deletions HELLION_Dedicated.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
<PropertyGroup>
<ApplicationIcon>app.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup />
<ItemGroup>
<None Include="Data\**" CopyToPublishDirectory="PreserveNewest" />
<None Update="GameServer.ini" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="protobuf-net" Version="3.1.17" />
<PackageReference Include="protobuf-net" Version="3.1.25" />
<PackageReference Include="BulletSharp.x64" Version="0.12.0" />
</ItemGroup>
</Project>
57 changes: 16 additions & 41 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,22 @@

public static class Program
{
private enum CtrlType
private static void ProcessExit(object sender, EventArgs e)
{
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT = 1,
CTRL_CLOSE_EVENT = 2,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT = 6
}

[Flags]
public enum ErrorModes : uint
{
SYSTEM_DEFAULT = 0u,
SEM_FAILCRITICALERRORS = 1u,
SEM_NOALIGNMENTFAULTEXCEPT = 4u,
SEM_NOGPFAULTERRORBOX = 2u,
SEM_NOOPENFILEERRORBOX = 0x8000u
}

private delegate bool EventHandler(CtrlType sig);

private static EventHandler _handler;

[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);

[DllImport("kernel32.dll")]
private static extern ErrorModes SetErrorMode(ErrorModes uMode);

private static bool Handler(CtrlType sig)
{
if (sig == CtrlType.CTRL_C_EVENT || sig == CtrlType.CTRL_BREAK_EVENT || sig == CtrlType.CTRL_LOGOFF_EVENT || sig == CtrlType.CTRL_SHUTDOWN_EVENT || sig == CtrlType.CTRL_CLOSE_EVENT)
Console.WriteLine("Exiting safely...");
Server.IsRunning = false;
if (Server.PersistenceSaveInterval > 0.0)
{
Server.IsRunning = false;
if (Server.PersistenceSaveInterval > 0.0)
{
Server.SavePersistenceDataOnShutdown = true;
}
Server.MainLoopEnded.WaitOne(10000);
Server.SavePersistenceDataOnShutdown = true;
}
return false;
Server.MainLoopEnded.WaitOne(10000);
}

private static void Main(string[] args)
{
SetErrorMode(ErrorModes.SEM_NOGPFAULTERRORBOX);
_handler = (EventHandler)Delegate.Combine(_handler, new EventHandler(Handler));
SetConsoleCtrlHandler(_handler, add: true);
AppDomain.CurrentDomain.ProcessExit += new EventHandler(ProcessExit);
Console.CancelKeyPress += new ConsoleCancelEventHandler(ProcessExit);

bool shutDown = false;
string gport = null;
string sport = null;
Expand Down Expand Up @@ -124,6 +92,13 @@ private static void Main(string[] args)
ShutdownServerInstance();
return;
}

if (!File.Exists(Server.ConfigDir + "GameServer.ini"))
{
Console.WriteLine("GameServer.ini not found in folder " + Server.ConfigDir);
return;
}

CheckIniFields();
Dbg.OutputDir = Server.ConfigDir;
Dbg.Initialize();
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("21ae7db9-f4b6-4058-b6e3-ed651f6d3dfc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.0")]
1 change: 1 addition & 0 deletions ZeroGravity/Network/GameClientThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private void Listen()
Dbg.Exception(ex);
Disconnect();
}

if (client != null && client.Player != null)
{
client.Player.RemovePlayerFromTrigger();
Expand Down

0 comments on commit b17fade

Please sign in to comment.