public void Game_Exit() { Exit = true; GameAPI.Console_Write($"ModClientDll: Game_Exit {CurrentConfig.Current.ModToEmpyrionPipeName}"); OutServer?.SendMessage(new ClientHostComData() { Command = ClientHostCommand.Game_Exit }); if (!ExposeShutdownHost && CurrentConfig.Current.AutoshutdownModHost && mHostProcess != null) { try { try { mHostProcess.CloseMainWindow(); } catch { } CurrentConfig.Current.HostProcessId = 0; CurrentConfig.Save(); Thread.Sleep(1000); } catch (Exception Error) { GameAPI.Console_Write($"ModClientDll: Game_Exit {Error}"); } } InServer?.Close(); OutServer?.Close(); }
void CheckHostProcess() { if (Exit) { return; } if (ExistsStopFile()) { try { if (mHostProcess != null && !mHostProcess.HasExited) { GameAPI.Console_Write($"ModClientDll: stop.txt found"); OutServer?.SendMessage(new ClientHostComData() { Command = ClientHostCommand.Game_Exit }); Thread.Sleep(1000); InServer?.Close(); OutServer?.Close(); GameAPI.Console_Write($"ModClientDll: stopped"); } } catch { } return; } if (CurrentConfig.Current.AutostartModHostAfterNSeconds == 0 || !CurrentConfig.Current.AutostartModHost) { return; } try { if (mHostProcess != null && !mHostProcess.HasExited) { return; } } catch { } if (!mHostProcessAlive.HasValue) { mHostProcessAlive = DateTime.Now; } if ((DateTime.Now - mHostProcessAlive.Value).TotalSeconds <= CurrentConfig.Current.AutostartModHostAfterNSeconds) { return; } mHostProcessAlive = null; StartModToEmpyrionPipe(); StartHostProcess(); StartEmpyrionToModPipe(); }
private void StartModToEmpyrionPipe() { GameAPI.Console_Write($"StartModToEmpyrionPipe: start {CurrentConfig.Current.ModToEmpyrionPipeName}"); try { InServer?.Close(); } catch { } Thread.Sleep(1000); InServer = new ServerMessagePipe(CurrentConfig.Current.ModToEmpyrionPipeName) { log = GameAPI.Console_Write }; InServer.Callback = Msg => { if (InServerMessageHandler.TryGetValue(Msg.GetType(), out Action <object> Handler)) { Handler(Msg); } }; GameAPI.Console_Write($"StartModToEmpyrionPipe: startet {CurrentConfig.Current.ModToEmpyrionPipeName}"); }