C2G_HGHHKickHandler.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. namespace ET.Server
  3. {
  4. /// <summary>
  5. /// 黄冈晃晃 踢人
  6. /// </summary>
  7. [MessageHandler(SceneType.Game)]
  8. public class C2G_HGHHKickHandler : AMRpcHandler<C2G_HGHHKick, G2C_HGHHKick>
  9. {
  10. protected override async ETTask Run(Session session, C2G_HGHHKick request, G2C_HGHHKick response, Action reply)
  11. {
  12. Player player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
  13. if (player == null)
  14. {
  15. response.Error = ErrorCode.ERR_OperationError;
  16. response.Message = "玩家不存在或离线...";
  17. reply();
  18. return;
  19. }
  20. // 判断参数
  21. if (request.RoomId <= 0)
  22. {
  23. response.Error = ErrorCode.ERR_ParameterError;
  24. response.Message = "参数错误,房间号为空...";
  25. reply();
  26. return;
  27. }
  28. Scene scene = session.DomainScene();
  29. // 请求的房间是否能找到
  30. Room room = scene.GetComponent<GameRoomComponent>().Get(request.RoomId);
  31. if (room == null)
  32. {
  33. response.Error = ErrorCode.ERR_OperationError;
  34. response.Message = "请求的房间不存在或已解散...";
  35. reply();
  36. return;
  37. }
  38. // 玩家是否是房主
  39. if (room.OwnerId != player.Id)
  40. {
  41. response.Error = ErrorCode.ERR_OperationError;
  42. response.Message = "玩家不是房主,不可操作...";
  43. reply();
  44. return;
  45. }
  46. // 判断玩家是否在其他房间
  47. if (!player.RoomId.Equals(request.RoomId))
  48. {
  49. response.Error = ErrorCode.ERR_OperationError;
  50. response.Message = "玩家不在此房间,不可操作...";
  51. reply();
  52. return;
  53. }
  54. // 是否踢自己
  55. if (request.PlayerId == player.Id)
  56. {
  57. response.Error = ErrorCode.ERR_ParameterError;
  58. response.Message = "不可自己踢自己...";
  59. reply();
  60. return;
  61. }
  62. // 状态是否可踢人
  63. HGHuangHuangComponent hgHuangHuangComponent = room.GetComponent<HGHuangHuangComponent>();
  64. if (hgHuangHuangComponent != null && hgHuangHuangComponent.State != 0)
  65. {
  66. response.Error = ErrorCode.ERR_ParameterError;
  67. response.Message = "游戏进行中,不可踢人...";
  68. reply();
  69. return;
  70. }
  71. room.Remove(request.PlayerId);
  72. reply();
  73. await ETTask.CompletedTask;
  74. }
  75. }
  76. }