private static void Main(string[] args) { // 异步方法全部会回掉到主线程 SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); try { Game.EventSystem.Add(typeof(Game).Assembly); Game.EventSystem.Add(DllHelper.GetHotfixAssembly()); MongoHelper.Init(); // 命令行参数 Options options = null; Parser.Default.ParseArguments <Options>(args) .WithNotParsed(error => throw new Exception($"命令行格式错误!")) .WithParsed(o => { options = o; }); Game.Scene.AddComponent(options); IdGenerater.Process = options.Process; LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Scene.Id:0000}"; Log.Info($"server start........................ {Game.Scene.Id}"); _ = Game.EventSystem.Publish(new EventType.AppStart()); while (true) { try { Thread.Sleep(1); OneThreadSynchronizationContext.Instance.Update(); Game.EventSystem.Update(); } catch (Exception e) { Log.Error(e); } } } catch (Exception e) { Log.Error(e); } }
public async ETVoid Start() { this.CancellationTokenSource = new CancellationTokenSource(); while (true) { try { string line = await Task.Factory.StartNew(() => { Console.Write($"{this.Mode}> "); return(Console.In.ReadLine()); }, this.CancellationTokenSource.Token); line = line.Trim(); if (this.Mode != "") { bool isExited = true; switch (this.Mode) { case ConsoleMode.Repl: { ReplComponent replComponent = this.GetComponent <ReplComponent>(); if (replComponent == null) { Console.WriteLine($"no command: {line}!"); break; } try { isExited = await replComponent.Run(line, this.CancellationTokenSource.Token); } catch (Exception e) { Console.WriteLine(e); } break; } } if (isExited) { this.Mode = ""; } continue; } switch (line) { case "reload": try { Game.EventSystem.Add(DllHelper.GetHotfixAssembly()); } catch (Exception e) { Console.WriteLine(e); } break; case "repl": try { this.Mode = ConsoleMode.Repl; this.AddComponent <ReplComponent>(); } catch (Exception e) { Console.WriteLine(e); } break; default: Console.WriteLine($"no such command: {line}"); break; } } catch (Exception e) { Console.WriteLine(e); } } }
protected override async ETTask Run(Session session, M2A_Reload request, A2M_Reload response, Action reply) { Game.EventSystem.Add(DllHelper.GetHotfixAssembly()); reply(); await ETTask.CompletedTask; }