RequestServerUtil.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using static System.Collections.Specialized.BitVector32;
  4. namespace ET.Client
  5. {
  6. public class RequestServerUtil : Singleton<RequestServerUtil>
  7. {
  8. public async ETTask OpenRequestServer(ushort messageId,Dictionary<string,object> param = null, Action<object, int> cb = null )
  9. {
  10. Scene scene = GameUtil.Instance.GetSceneComponent();
  11. Session session = scene.GetComponent<SessionComponent>().Session;
  12. switch (messageId)
  13. {
  14. case OuterMessage.C2G_CreatRoom:
  15. {
  16. G2C_CreatRoom g2CreatRoom = (G2C_CreatRoom)await session.Call(
  17. new C2G_CreatRoom() { });
  18. if (g2CreatRoom.Error != ErrorCode.ERR_Success)
  19. {
  20. cb?.Invoke(null, g2CreatRoom.Error);
  21. return;
  22. }
  23. cb?.Invoke(g2CreatRoom.Info, ErrorCode.ERR_Success);
  24. break;
  25. }
  26. case OuterMessage.C2G_JoinRoom:
  27. {
  28. var roomId = param["roomId"];
  29. G2C_JoinRoom g2JoinRoom = (G2C_JoinRoom)await session.Call(
  30. new C2G_JoinRoom() { RoomId = int.Parse(roomId.ToString()) });
  31. if (g2JoinRoom.Error != ErrorCode.ERR_Success)
  32. {
  33. cb?.Invoke(null, g2JoinRoom.Error);
  34. return;
  35. }
  36. cb?.Invoke(null, ErrorCode.ERR_Success);
  37. break;
  38. }
  39. case HGHHMessage.C2G_HGHHOperation:
  40. {
  41. var OpType = param["OpType"];
  42. var Card = param["Card"];
  43. G2C_HGHHOperation g2Operation = (G2C_HGHHOperation)await session.Call(
  44. new C2G_HGHHOperation() { OpType = int.Parse(OpType.ToString()),
  45. Card = int.Parse(Card.ToString()) });
  46. if (g2Operation.Error != ErrorCode.ERR_Success)
  47. {
  48. cb?.Invoke(null, g2Operation.Error);
  49. return;
  50. }
  51. cb?.Invoke(null, ErrorCode.ERR_Success);
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. }