Program.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using Base;
  5. using Model;
  6. using Object = Base.Object;
  7. namespace App
  8. {
  9. internal static class Program
  10. {
  11. private static void Main(string[] args)
  12. {
  13. try
  14. {
  15. Log.Info("server start........................");
  16. Object.ObjectManager.Register("Base", typeof(Game).Assembly);
  17. Object.ObjectManager.Register("Model", typeof(ErrorCode).Assembly);
  18. byte[] dllBytes = File.ReadAllBytes("./Controller.dll");
  19. byte[] pdbBytes = File.ReadAllBytes("./Controller.pdb");
  20. Assembly controller = Assembly.Load(dllBytes, pdbBytes);
  21. Object.ObjectManager.Register("Controller", controller);
  22. Options options = Game.Scene.AddComponent<OptionsComponent, string[]>(args).Options;
  23. Game.Scene.AddComponent<EventComponent>();
  24. Game.Scene.AddComponent<TimerComponent>();
  25. Game.Scene.AddComponent<NetworkComponent, NetworkProtocol, string, int>(options.Protocol, options.Host, options.Port);
  26. Game.Scene.AddComponent<MessageDispatherComponent, string>(options.AppType);
  27. // 根据不同的AppType添加不同的组件
  28. switch (options.AppType)
  29. {
  30. case "Realm":
  31. Game.Scene.AddComponent<RealmGateAddressComponent>();
  32. break;
  33. case "Gate":
  34. Game.Scene.AddComponent<GateSessionKeyComponent>();
  35. break;
  36. default:
  37. throw new Exception($"命令行参数没有设置正确的AppType: {options.AppType}");
  38. }
  39. while (true)
  40. {
  41. Object.ObjectManager.Update();
  42. }
  43. }
  44. catch (Exception e)
  45. {
  46. Log.Error(e.ToString());
  47. }
  48. }
  49. }
  50. }