|
@@ -1,15 +1,66 @@
|
|
|
using System;
|
|
|
+using System.Drawing;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
|
|
|
-namespace ET.Server;
|
|
|
-
|
|
|
-/// <summary>
|
|
|
-/// 加入房间
|
|
|
-/// </summary>
|
|
|
-[MessageHandler(SceneType.Game)]
|
|
|
-public class C2G_JoinRoomHandler : AMRpcHandler<C2G_JoinRoom, G2C_JoinRoom>
|
|
|
+namespace ET.Server
|
|
|
{
|
|
|
- protected override ETTask Run(Session session, C2G_JoinRoom request, G2C_JoinRoom response, Action reply)
|
|
|
+ /// <summary>
|
|
|
+ /// 加入房间
|
|
|
+ /// </summary>
|
|
|
+ [MessageHandler(SceneType.Game)]
|
|
|
+ public class C2G_JoinRoomHandler : AMRpcHandler<C2G_JoinRoom, G2C_JoinRoom>
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ protected override async ETTask Run(Session session, C2G_JoinRoom request, G2C_JoinRoom response, Action reply)
|
|
|
+ {
|
|
|
+ Player player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
|
|
|
+ if (player == null)
|
|
|
+ {
|
|
|
+ response.Error = ErrorCode.ERR_OperationError;
|
|
|
+ response.Message = "玩家不存在或离线...";
|
|
|
+ reply();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 判断参数
|
|
|
+ if (string.IsNullOrEmpty(request.RoomId))
|
|
|
+ {
|
|
|
+ response.Error = ErrorCode.ERR_ParameterError;
|
|
|
+ response.Message = "参数错误,请输入要加入房间的id...";
|
|
|
+ reply();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 房间号格式是否正确
|
|
|
+ if (Regex.IsMatch(request.RoomId, @"^\d+$"))
|
|
|
+ {
|
|
|
+ response.Error = ErrorCode.ERR_ParameterError;
|
|
|
+ response.Message = "参数错误,格式有误...";
|
|
|
+ reply();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 判断玩家是否已加入房间
|
|
|
+ if (!string.IsNullOrEmpty(player.RoomID) && !player.RoomID.Equals(request.RoomId))
|
|
|
+ {
|
|
|
+ response.Error = ErrorCode.ERR_OperationError;
|
|
|
+ response.Message = "玩家已在房间,不可加入其他房间...";
|
|
|
+ reply();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Scene scene = session.DomainScene();
|
|
|
+
|
|
|
+ // 请求的房间是否能找到
|
|
|
+ Room room = scene.GetComponent<GameRoomComponent>().Get(request.RoomId);
|
|
|
+ if (room == null)
|
|
|
+ {
|
|
|
+ response.Error = ErrorCode.ERR_OperationError;
|
|
|
+ response.Message = "请求的房间不存在或已解散...";
|
|
|
+ reply();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回房间数据
|
|
|
+ response.Info = ProtoHelper.RoomToProto(room);
|
|
|
+ reply();
|
|
|
+ await ETTask.CompletedTask;
|
|
|
+ }
|
|
|
}
|
|
|
}
|