World.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.IO;
  3. using Component;
  4. using Helper;
  5. using Log;
  6. namespace World
  7. {
  8. public class World
  9. {
  10. private static readonly World instance = new World();
  11. private ILogicEntry iLogicEntry;
  12. private readonly Config config;
  13. private World()
  14. {
  15. this.config = Config.Instance;
  16. this.LoadLogic();
  17. }
  18. private void LoadLogic()
  19. {
  20. string dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logic.dll");
  21. if (!File.Exists(dllPath))
  22. {
  23. throw new Exception(string.Format("not found logic dll, path: {0}", dllPath));
  24. }
  25. var assembly = LoaderHelper.Load(dllPath);
  26. this.iLogicEntry = (ILogicEntry)assembly.CreateInstance("Logic.LogicEntry");
  27. }
  28. public static World Instance
  29. {
  30. get
  31. {
  32. return instance;
  33. }
  34. }
  35. public void ReloadLogic()
  36. {
  37. this.LoadLogic();
  38. }
  39. public void ReloadConfig()
  40. {
  41. this.config.Reload();
  42. }
  43. public void Dispatcher(short opcode, byte[] content)
  44. {
  45. try
  46. {
  47. var messageEnv = new MessageEnv();
  48. messageEnv.Set(this);
  49. this.iLogicEntry.Enter(messageEnv, opcode, content);
  50. }
  51. catch (Exception e)
  52. {
  53. Logger.Trace("message handle error: {0}", e.Message);
  54. }
  55. }
  56. public Config Config
  57. {
  58. get
  59. {
  60. return this.config;
  61. }
  62. }
  63. }
  64. }