/// <summary> /// Set things in motion so your service can do its work. /// </summary> protected override void OnStart(string[] args) { try { threadManager.Start(true); } catch (Exception ex) { Lib.PrintLine(ex.Message + ex.StackTrace); } }
public override bool Start() { // This section of code finds and loads the tigermud.xml file. // The code is more complex because it supports the location of tigermud.xml in both // the dev team environment and normal user runtime environments. string path = AppDomain.CurrentDomain.BaseDirectory + @"\TigerMUD.xml"; try { Lib.Serverinfo = Lib.Readxmldoc(path); threadManager.Start(false); } catch (Exception ex) { Lib.PrintLine(ex.Message + ex.StackTrace); //throw new Exception("Cannot find TigerMUD.xml configuration file. Server load failed."); } return(true); }
public void Start() { Lib.PathtoRoot = AppDomain.CurrentDomain.BaseDirectory; Lib.PathtoRootScriptsandPlugins = Lib.PathtoRoot + @"scripts"; // this must come before ANY printing to console // logwriters are opened in Start() method and closed in Stop() method Lib.serverlogwriter = new StreamWriter(Path.GetFullPath(Path.Combine(Lib.PathtoRoot, Lib.serverLogFileName)), true); Lib.serverlogwriter.AutoFlush = true; Lib.commandlogwriter = new StreamWriter(Path.GetFullPath(Path.Combine(Lib.PathtoRoot, Lib.commandLogFileName)), true); Lib.commandlogwriter.AutoFlush = true; // This section of code finds and loads the tigermud.xml file. // The code is more complex because it supports the location of tigermud.xml in both // the dev team environment and normal user runtime environments. try { Lib.Serverinfo = Lib.Readxmldoc(Path.Combine(Lib.PathtoRoot, "tigermud.xml")); } catch (Exception ex) { Lib.PrintLine("EXCEPTION in Server.Start (reading tigermud.xml): " + ex.Message + ex.StackTrace); } // Only run in console mode if explicitly told // to do so by tigermud.xml. if (Lib.Serverinfo.ServerMode == "console") { threadManager = new Threadmanager(); try { threadManager.Start(false); } catch (Exception ex) { Lib.PrintLine("*********************** SERVER CRASH ***************************\r\n\r\n" + ex.Message + ex.StackTrace); Lib.log.Add("Error on MUD Startup:", ex.Message + ex.StackTrace); Console.ReadLine(); return; } // Listen for user input Lib.PrintLine("\n\nTigerMUD Console. Type 'help' to see a list of commands."); ConsoleControl control = new ConsoleControl(); // Loop on user commands Started = true; while (!exit) { string command = control.GetUserInput().ToLower(); switch (command) { case "shutdown": foreach (Actor actor in Lib.actors) { if (Lib.ConvertToBoolean(actor["connected"])) { actor.SendAnnouncement("\r\nServer shutdown initiated from console. Server coming down NOW.\r\n"); } } threadManager.Stop(); exit = true; break; case "restart": threadManager.Stop(); threadManager.Start(false); break; default: control.HandleConsoleCommand(command); break; } } } else { // We are running in service mode ServiceBase[] ServicesToRun = new ServiceBase[] { new TigerMUDService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } }