ABossCommand.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Threading.Tasks;
  3. using BossBase;
  4. using Helper;
  5. using Logger;
  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. public string CommandString { get; set; }
  16. protected async Task<T> RecvMessage<T>()
  17. {
  18. var result = await this.IMessageChannel.RecvMessage();
  19. ushort opcode = result.Item1;
  20. byte[] content = result.Item2;
  21. try
  22. {
  23. var message = ProtobufHelper.FromBytes<T>(content);
  24. return message;
  25. }
  26. catch (Exception)
  27. {
  28. Log.Trace("parse message fail, opcode: {0}", opcode);
  29. throw;
  30. }
  31. }
  32. protected ABossCommand(IMessageChannel iMessageChannel)
  33. {
  34. this.IMessageChannel = iMessageChannel;
  35. }
  36. public virtual Task<object> DoAsync()
  37. {
  38. throw new NotImplementedException();
  39. }
  40. public void UndoAsync()
  41. {
  42. throw new NotImplementedException();
  43. }
  44. }
  45. }