Program.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #if __MonoCS__
  20. byte[] pdbBytes = File.ReadAllBytes("./Controller.dll.mdb");
  21. #else
  22. byte[] pdbBytes = File.ReadAllBytes("./Controller.pdb");
  23. #endif
  24. Assembly controller = Assembly.Load(dllBytes, pdbBytes);
  25. Object.ObjectManager.Register("Controller", controller);
  26. Options options = Game.Scene.AddComponent<OptionsComponent, string[]>(args).Options;
  27. Game.Scene.AddComponent<EventComponent>();
  28. Game.Scene.AddComponent<TimerComponent>();
  29. Game.Scene.AddComponent<NetworkComponent, NetworkProtocol, string, int>(options.Protocol, options.Host, options.Port);
  30. Game.Scene.AddComponent<MessageDispatherComponent, string>(options.AppType);
  31. // 根据不同的AppType添加不同的组件
  32. switch (options.AppType)
  33. {
  34. case "Realm":
  35. Game.Scene.AddComponent<RealmGateAddressComponent>();
  36. break;
  37. case "Gate":
  38. Game.Scene.AddComponent<GateSessionKeyComponent>();
  39. break;
  40. default:
  41. throw new Exception($"命令行参数没有设置正确的AppType: {options.AppType}");
  42. }
  43. while (true)
  44. {
  45. Object.ObjectManager.Update();
  46. }
  47. }
  48. catch (Exception e)
  49. {
  50. Log.Error(e.ToString());
  51. }
  52. }
  53. }
  54. }