public virtual void Init() { Directory.SetCurrentDirectory("../../debug"); string CD = Directory.GetCurrentDirectory(); Console.WriteLine(CD); if (GameServer.Instance == null) { FileInfo configFile = new FileInfo("./config/serverconfig.xml"); GameServerConfiguration config = new GameServerConfiguration(); if (!configFile.Exists) config.SaveToXMLFile(configFile); else config.LoadFromXMLFile(configFile); GameServer.CreateInstance(config); Directory.SetCurrentDirectory(CD); } if (!GameServer.Instance.IsRunning) { Language.LanguageMgr.SetLangPath(Path.Combine(CD, "languages")); Console.WriteLine("Starting GameServer"); if (!GameServer.Instance.Start()) { Console.WriteLine("Error init GameServer"); } } else { Console.WriteLine("GameServer already running, skip init of Gameserver..."); } }
private static bool StartServer() { //TODO parse args for -config parameter! FileInfo dolserver = new FileInfo(Assembly.GetExecutingAssembly().Location); Directory.SetCurrentDirectory(dolserver.DirectoryName); FileInfo configFile = new FileInfo("./config/serverconfig.xml"); GameServerConfiguration config = new GameServerConfiguration(); if(configFile.Exists) { config.LoadFromXMLFile(configFile); } else { if(!configFile.Directory.Exists) configFile.Directory.Create(); config.SaveToXMLFile(configFile); } GameServer.CreateInstance(config); return GameServer.Instance.Start(); }
public void OnAction(Hashtable parameters) { Console.WriteLine("Starting GameServer ... please wait a moment!"); FileInfo configFile; FileInfo currentAssembly = null; if (parameters["-config"] != null) { Console.WriteLine("Using config file: " + parameters["-config"]); configFile = new FileInfo((String)parameters["-config"]); } else { currentAssembly = new FileInfo(Assembly.GetEntryAssembly().Location); configFile = new FileInfo(currentAssembly.DirectoryName + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "serverconfig.xml"); } GameServerConfiguration config = new GameServerConfiguration(); if (configFile.Exists) { config.LoadFromXMLFile(configFile); } else { if (!configFile.Directory.Exists) configFile.Directory.Create(); config.SaveToXMLFile(configFile); if (File.Exists(currentAssembly.DirectoryName + Path.DirectorySeparatorChar + "DOLConfig.exe")) { Console.WriteLine("No config file found, launching DOLConfig.exe..."); System.Diagnostics.Process.Start(currentAssembly.DirectoryName + Path.DirectorySeparatorChar + "DOLConfig.exe"); return; } } GameServer.CreateInstance(config); StartServer(); bool run = true; while (run) { Console.Write("> "); string line = Console.ReadLine(); switch (line.ToLower()) { case "exit": run = false; break; case "stacktrace": log.Debug(PacketProcessor.GetConnectionThreadpoolStacks()); break; case "clear": Console.Clear(); break; default: if (line.Length <= 0) break; if (line[0] == '/') { line = line.Remove(0, 1); line = line.Insert(0, "&"); } GameClient client = new GameClient(null); client.Out = new ConsolePacketLib(); try { bool res = ScriptMgr.HandleCommandNoPlvl(client, line); if (!res) { Console.WriteLine("Unknown command: " + line); } } catch (Exception e) { Console.WriteLine(e.ToString()); } break; } } if (GameServer.Instance != null) GameServer.Instance.Stop(); }
/// <summary> /// Save the GameServer configuration /// </summary> /// <param name="gsc">The GameServer configuration which should be saved.</param> /// <returns></returns> public static void saveCurrentConfiguration(GameServerConfiguration gsc) { try { FileInfo configFileInfo = new FileInfo(getCurrentConfigFile()); gsc.SaveToXMLFile(configFileInfo); } catch (Exception e) { throw e; } }