ABossCommand.cs 1003 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Threading.Tasks;
  3. using BossBase;
  4. using Helper;
  5. using Log;
  6. namespace BossCommand
  7. {
  8. public abstract class ABossCommand
  9. {
  10. protected IMessageChannel IMessageChannel { get; set; }
  11. protected void SendMessage(CMSG_Boss_Gm cmsgBossGm)
  12. {
  13. this.IMessageChannel.SendMessage(MessageOpcode.CMSG_BOSS_GM, cmsgBossGm);
  14. }
  15. protected async Task<T> RecvMessage<T>()
  16. {
  17. var result = await this.IMessageChannel.RecvMessage();
  18. ushort opcode = result.Item1;
  19. byte[] content = result.Item2;
  20. try
  21. {
  22. var message = ProtobufHelper.FromBytes<T>(content);
  23. return message;
  24. }
  25. catch (Exception)
  26. {
  27. Logger.Trace("parse message fail, opcode: {0}", opcode);
  28. throw;
  29. }
  30. }
  31. protected ABossCommand(IMessageChannel iMessageChannel)
  32. {
  33. this.IMessageChannel = iMessageChannel;
  34. }
  35. public virtual Task<object> DoAsync()
  36. {
  37. throw new NotImplementedException();
  38. }
  39. public void UndoAsync()
  40. {
  41. throw new NotImplementedException();
  42. }
  43. }
  44. }