private void Instance_OnUpdateApplied(Octokit.Release release) { var result = MessageBox.Show( $"You must restart before the update can be completed!\r\n\r\n" + $"Would you like to restart now?\r\n" + $"Note: The server was saved after downloading this release.", "HES Updater", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { HES.Restart(); } else { StatusBar.Text = "HES needs to be restarted before you can use the new features!"; } }
private void server_config_stopserver_Click(object sender, EventArgs e) { try { if (ServerInstance.Instance.IsRunning) { StatusBar.Text = "Server Stopping"; HES.KeyPressSimulator("/ss"); } else { StatusBar.Text = "The server is already stopped!"; } } catch (Exception) { } }
private static void Main(string[] args) { // Setup the handler for closing HES properly and saving HES._handler += new HES.EventHandler(HES.Handler); HES.SetConsoleCtrlHandler(HES._handler, true); // the GUI thread Thread uiThread = new Thread(LoadGUI); uiThread.SetApartmentState(ApartmentState.STA); //uiThread.Start(); Disabled for now! Console.Title = String.Format("HELLION EXTENDED SERVER V{0}) - Game Patch Version: {1} ", Version, "0.1.5"); Console.WriteLine("Hellion Extended Server Initialized."); HES program = new HES(args); program.Run(args); }
private void server_config_startserver_Click(object sender, EventArgs e) { try { CheckForIllegalCrossThreadCalls = false; if (!ServerInstance.Instance.IsRunning) { StatusBar.Text = "Server Starting"; HES.KeyPressSimulator("/s"); AddChatLine("Starting Server!"); } else { StatusBar.Text = "The server is already started!"; } } catch (Exception) { } }
public HES(string[] args) { m_instance = this; _handler += new EventHandler(Handler); SetConsoleCtrlHandler(_handler, true); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CrashDump.CurrentDomain_UnhandledException); LogManager.Configuration = CreateNLogConfiguration(); new Log(); mainLogger = LogManager.GetCurrentClassLogger(); mainLogger.Info($"Git Branch: {ThisAssembly.Git.Branch}"); if (debugMode) { mainLogger.Info($"Git Commit: {ThisAssembly.Git.Commit}"); mainLogger.Info($"Git SHA: {ThisAssembly.Git.Sha}"); } mainLogger.Info("Hellion Extended Server Initializing...."); }
public HES(string[] args) { m_instance = this; m_serverInstance = new ServerInstance(); }
private static void Main(string[] args) { ThisProcess = Process.GetCurrentProcess(); CommandLineArgs = args; Console.Title = WindowTitle; new FolderStructure().Build(); m_config = new Config(); debugMode = m_config.Settings.DebugMode; var path = Path.Combine(Environment.CurrentDirectory, "Newtonsoft.Json.dll"); if (File.Exists(path)) { try { var name = AssemblyName.GetAssemblyName(path); if (name.Version < new Version("10.0.0.0")) { using (Stream s = Assembly.GetCallingAssembly().GetManifestResourceStream("HellionExtendedServer.Resources.Newtonsoft.Json.dll")) { byte[] data = new byte[s.Length]; s.Read(data, 0, data.Length); File.WriteAllBytes(path, data); } } } catch (Exception) { } } else { try { using (Stream s = Assembly.GetCallingAssembly().GetManifestResourceStream("HellionExtendedServer.Resources.Newtonsoft.Json.dll")) { byte[] data = new byte[s.Length]; s.Read(data, 0, data.Length); File.WriteAllBytes(path, data); } } catch (Exception) { } } AppDomain.CurrentDomain.AssemblyResolve += (sender, rArgs) => { string assemblyName = new AssemblyName(rArgs.Name).Name; if (assemblyName.EndsWith(".resources")) { return(null); } string dllName = assemblyName + ".dll"; string dllFullPath = Path.Combine(Path.GetFullPath("Hes\\bin"), dllName); if (dllName == "Newtonsoft.Json.dll") { try { if (new AssemblyName(rArgs.Name).Version < new Version("10.0.0.0")) { using (Stream s = Assembly.GetCallingAssembly().GetManifestResourceStream("HellionExtendedServer.Resources.Newtonsoft.Json.dll")) { byte[] data = new byte[s.Length]; s.Read(data, 0, data.Length); File.WriteAllBytes(path, data); } return(Assembly.LoadFrom(path)); } } catch (Exception) { } } if (debugMode) { Console.WriteLine($"The assembly '{dllName}' is missing or has been updated. Adding/Updating missing assembly."); } using (Stream s = Assembly.GetCallingAssembly().GetManifestResourceStream("HellionExtendedServer.Resources." + dllName)) { byte[] data = new byte[s.Length]; s.Read(data, 0, data.Length); File.WriteAllBytes(dllFullPath, data); } return(Assembly.LoadFrom(dllFullPath)); }; // This is for args that should be used before HES loads bool noUpdateHes = false; bool noUpdateHellion = false; bool usePrereleaseVersions = false; Console.ForegroundColor = ConsoleColor.Green; foreach (string arg in args) { if (arg.Equals("-noupdatehes")) { noUpdateHes = true; } if (arg.Equals("-noupdatehellion")) { noUpdateHellion = true; } if (arg.Equals("-usedevversion")) { usePrereleaseVersions = true; } } if (usePrereleaseVersions || Config.Settings.EnableDevelopmentVersion) { Console.WriteLine("HellionExtendedServer: (Arg: -usedevversion is set) HES Will use Pre-releases versions"); } if (noUpdateHes || !Config.Settings.EnableAutomaticUpdates) { UpdateManager.EnableAutoUpdates = false; Console.WriteLine("HellionExtendedServer: (Arg: -noupdatehes is set or option in HES config is enabled) HES will not be auto-updated.\r\n"); } if (noUpdateHellion || !Config.Settings.EnableHellionAutomaticUpdates) { SteamCMD.AutoUpdateHellion = false; Console.WriteLine("HellionExtendedServer: (Arg: -noupdatehellion is set) Hellion Dedicated will not be auto-updated."); } Console.ResetColor(); updateManager = new UpdateManager(); var program = new HES(args); program.Run(args); }
/// <summary> /// This contains the console commands /// </summary> public void ReadConsoleCommands(string[] commandLineArgs) { while (true) { string cmd = Console.ReadLine(); if (cmd.Length > 1) { if (!cmd.StartsWith("/")) { if (Server.Instance != null) { if (Server.IsRunning) { NetworkManager.Instance.MessageAllClients(cmd); } } if (!Server.IsRunning) { Log.Instance.Warn("The Server must be running to message connected clients!"); } continue; } string cmmd = cmd.Split(" ".ToCharArray())[0].Replace("/", ""); string[] args = cmd.Split(" ".ToCharArray()).Skip(1).ToArray(); //if (ServerInstance.Instance.CommandManager.HandleConsoleCommand(cmmd, args)) continue; string[] strArray = Regex.Split(cmd, "^/([a-z]+) (\\([a-zA-Z\\(\\)\\[\\]. ]+\\))|([a-zA-Z\\-]+)"); List <string> stringList = new List <string>(); int num = 1; foreach (string str2 in strArray) { if (str2 != "" && str2 != " ") { stringList.Add(str2); } ++num; } bool flag = false; if (Server.IsRunning && ServerInstance.Instance.CommandManager != null) { ServerInstance.Instance.CommandManager.HandleConsoleCommand(cmmd, args); flag = true; } if (stringList[1] == "help") { HES.PrintHelp(); flag = true; } if (stringList[1] == "checkupdate") { updateManager.CheckForUpdates().GetAwaiter().GetResult(); flag = true; } if (stringList[1] == "restart") { Restart(); flag = true; } if (stringList[1] == "forceupdate") { updateManager.CheckForUpdates(true).GetAwaiter().GetResult(); flag = true; } //Different args for /players command to display the count, the full list of players (disconnected and disconnected) and the list of connected players. if (stringList[1] == "players" && stringList.Count > 2 & Server.IsRunning) { if (stringList[2] == "-count") { Console.WriteLine(string.Format(HES.m_localization.Sentences["PlayersConnected"], ServerInstance.Instance.Server.NetworkController.CurrentOnlinePlayers(), ServerInstance.Instance.Server.MaxPlayers)); flag = true; } else if (stringList[2] == "-list") { Console.WriteLine(string.Format("\t-------Pseudo------- | -------SteamId-------")); foreach (var client in NetworkManager.Instance.ClientList) { Console.WriteLine(string.Format("\t {0} \t {1}", client.Value.Player.Name, client.Value.Player.SteamId)); } flag = true; } else if (stringList[2] == "-all") { Console.WriteLine(string.Format(m_localization.Sentences["AllPlayers"], ServerInstance.Instance.Server.AllPlayers.Count)); Console.WriteLine( string.Format( "\t-------Pseudo------- | -------SteamId------- | -------Connected-------")); foreach (var player in ServerInstance.Instance.Server.AllPlayers) { Console.WriteLine(string.Format("\t {0} \t {1} \t {2}", player.Name, player.SteamId, NetworkManager.Instance.ClientList.Values.Contains( NetworkManager.Instance.GetClient(player)))); } flag = true; } Console.WriteLine(); } if (stringList[1] == "save" & Server.IsRunning) { ServerInstance.Instance.Save((stringList.Count > 2 && stringList[2] == "-show")); flag = true; } if (stringList[1] == "msg" && stringList.Count > 2 & Server.IsRunning) { flag = true; var msg = ""; if (stringList.Count > 2 && stringList[2].Contains("(") && stringList[2].Contains(")")) { foreach (string str2 in stringList) { if (stringList.IndexOf(str2) > 2) { msg = msg + str2 + " "; } } if (NetworkManager.Instance.ConnectedPlayer(stringList[3])) { Console.WriteLine("Server > " + stringList[3] + " : " + msg); NetworkManager.Instance.MessageToClient(msg, "Server", stringList[3]); } else { Console.WriteLine(HES.m_localization.Sentences["PlayerNotConnected"]); } } else { Console.WriteLine(HES.m_localization.Sentences["NoPlayerName"]); } } if (stringList[1] == "kick" && stringList.Count > 2 & Server.IsRunning) { flag = true; if (stringList[3].Contains("(") && stringList[3].Contains(")")) { if (NetworkManager.Instance.ConnectedPlayer(stringList[3], out Player player)) { try { player.DiconnectFromNetworkContoller(); Console.WriteLine(string.Format(HES.m_localization.Sentences["PlayerKicked"], (object)player.Name)); } catch (Exception ex) { Log.Instance.Error(ex, "Hellion Extended Server [KICK ERROR] : " + ex.Message); } } else { Console.WriteLine(HES.m_localization.Sentences["PlayerNotConnected"]); } } } if (stringList[1] == "start" || stringList[1] == "s") { if (!Server.IsRunning) { ServerInstance.Instance.Start(); } else { Console.WriteLine("The server is already running."); } flag = true; } if (stringList[1] == "stop" || stringList[1] == "ss") { if (Server.IsRunning) { ServerInstance.Instance.Stop(); } else { Console.WriteLine("The server is not running"); } flag = true; } if (stringList[1] == "opengui") { SetupGUI(); flag = true; } if (!flag) { Console.WriteLine(HES.m_localization.Sentences["BadSyntax"]); } } } }