// 创建实验室用的服务器,返回启动操作 public static Action BuildLibServer(GameServer gs, int port) { srv = gs; var ci = BC <ConsoleInput>(); ci.Srv = gs; BuildBaseComponents(); // 基础模块 BuildBussinessLoggers(gs); // 日志系统 BuildQuestionnaire(gs); // 问卷系统 BuildLogicComponents(gs); // 逻辑功能 BuildGMComponent(); // GM 和调试功能 // 初始化所有模块 srv.Initialize(); return(() => { // 启动服务器 srv.Get <NetCore>().StartListening("0.0.0.0", port); srv.Get <ILog>().Info("GameServer started at: " + port); srv.Start(); }); }
// 战斗数据分析用服务器 public static Action BuildConsoleDataAnalysis(GameServer gs, int port) { srv = gs; var cida = BC <ConsoleInputDataAnalysis>(); cida.Srv = gs; BuildBaseComponents(); // 基础模块 BuildLogicComponents(gs); // 逻辑功能 BuildDataAnalysisComponents(); // 数据分析功能 // 初始化所有模块 srv.Initialize(); return(() => { // 启动服务器 srv.Get <ILog>().Info("DataAnalysisServer started at: " + port); srv.Start(); }); }
static void Main(string[] args) { var port = 9530; var srvAddr = "127.0.0.1"; var noConsole = false; var onlyConsoleAgent = false; var runScripts = new List <string>(); foreach (var p in args) { if (p == "-noconsole") { noConsole = true; } else if (p.StartsWith("-p")) { port = int.Parse(p.Substring(2)); } else if (p == "-console-agent") { onlyConsoleAgent = true; } else if (p.StartsWith("-h")) { srvAddr = p.Substring(2); } else if (p.StartsWith("-r")) { runScripts.Add(Path.Combine("./init", p.Substring(2))); } else { Console.WriteLine("unknown parameter: " + p); } } var srv = new GameServer(); try { if (!onlyConsoleAgent) { var startSrv = ServerBuilder.BuildLibServer(srv, port); var css = srv.Get <CsScriptShell <ScriptObject> >(); foreach (var s in runScripts) { css.RunScript(s, "Init", new object[] { srv }); } if (!noConsole) { srv.Get <ConsoleInput>().Start(); // 启用控制台输入 } startSrv(); } else if (onlyConsoleAgent) { ServerBuilder.BuildConsoleAgent(srv, srvAddr, port)(); } } catch (Exception ex) { Console.WriteLine("!!!! EXCEPTION: " + ex.Message); Console.WriteLine("!!!! STACK: " + ex.StackTrace); srv.Get <ILog>().Error("[!!!! EXCEPTION]:" + ex.Message); srv.Get <ILog>().Error("[!!!! STACK]:" + ex.StackTrace); srv.Stop(); } }