World.cs 883 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.IO;
  3. using Helper;
  4. namespace World
  5. {
  6. public class World
  7. {
  8. private static readonly World instance = new World();
  9. private IDispatcher dispatcher;
  10. private World()
  11. {
  12. this.Load();
  13. }
  14. private void Load()
  15. {
  16. string dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Handler.dll");
  17. if (!File.Exists(dllPath))
  18. {
  19. throw new Exception("not found handler dll!");
  20. }
  21. var assembly = LoaderHelper.Load(dllPath);
  22. this.dispatcher = (IDispatcher)assembly.CreateInstance("Handler.Dispatcher");
  23. }
  24. public static World Instance
  25. {
  26. get
  27. {
  28. return instance;
  29. }
  30. }
  31. public void Reload()
  32. {
  33. this.Load();
  34. }
  35. public void Dispatcher(short opcode, byte[] content)
  36. {
  37. var messageEnv = new MessageEnv();
  38. messageEnv["world"] = this;
  39. this.dispatcher.Dispatch(messageEnv, opcode, content);
  40. }
  41. }
  42. }