private static void ENTER_ROOM_REPLY(byte[] bytes) { EnterRoomReply input = EnterRoomReply.Parser.ParseFrom(bytes); if (!input.Ret) { string msg = "进入战场失败:" + input.ErrMsg; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); GameRoomManager.Instance.Log("MSG: ENTER_ROOM_REPLY - " + msg); if (ClientManager.Instance) { ClientManager.Instance.StateMachine.TriggerTransition( ConnectionFSMStateEnum.StateEnum.DISCONNECTED_ROOM); } return; } // 请求地图数据 DownloadMap output = new DownloadMap() { RoomId = input.RoomId, }; GameRoomManager.Instance.SendMsg(ROOM.DownloadMap, output.ToByteArray()); // 请求地图上的资源变化数据 DownloadResCell output2 = new DownloadResCell() { RoomId = input.RoomId, }; GameRoomManager.Instance.SendMsg(ROOM.DownloadResCell, output2.ToByteArray()); { string msg = "成功进入战场!"; GameRoomManager.Instance.Log($"MSG: ENTER_ROOM_REPLY OK - " + msg); } }
private static void ENTER_ROOM(byte[] bytes) { bool ret = false; string errMsg = ""; EnterRoom input = EnterRoom.Parser.ParseFrom(bytes); RoomLogic roomLogic = ServerRoomManager.Instance.GetRoomLogic(input.RoomId); if (roomLogic == null) { // 房间没有开启,需要开启并进入 roomLogic = new RoomLogic(); if (roomLogic != null) { string tableName = $"MAP:{input.RoomId}"; if (ServerRoomManager.Instance.Redis.CSRedis.Exists(tableName)) { long createrId = ServerRoomManager.Instance.Redis.CSRedis.HGet <long>(tableName, "Creator"); NetRoomInfo roomInfo = new NetRoomInfo() { RoomId = ServerRoomManager.Instance.Redis.CSRedis.HGet <long>(tableName, "RoomId"), MaxPlayerCount = ServerRoomManager.Instance.Redis.CSRedis.HGet <int>(tableName, "MaxPlayerCount"), RoomName = ServerRoomManager.Instance.Redis.CSRedis.HGet <string>(tableName, "RoomName"), Creator = createrId, }; // 初始化 roomLogic.Init(roomInfo); ServerRoomManager.Instance.AddRoomLogic(roomInfo.RoomId, roomLogic); } else {// 房间地图数据没有找到,等于没有创建房间 roomLogic = null; } } } PlayerInfo pi = null; PlayerInfoInRoom piir = null; if (roomLogic == null) { errMsg = $"Battlefield is not found! RoomId:{input.RoomId}"; // 战场没有找到! } else { pi = ServerRoomManager.Instance.GetPlayer(_args); if (pi == null) { errMsg = "PlayerInfo is not found!"; // 玩家没有找到! } else { pi.RoomId = input.RoomId; piir = roomLogic.GetPlayerInRoom(pi.Enter.TokenId); if (piir == null) { errMsg = "PlayerInfoInRoom is not found!"; // 玩家没有找到! roomLogic.Online(_args, pi.Enter, pi.RoomId); piir = roomLogic.GetPlayerInRoom(pi.Enter.TokenId); } } } if (piir != null) { // 把当前玩家设置为在线(所有玩家信息在房间创建的时候(RoomLogic.Init)就存在了, 只是不在线) roomLogic.Online(_args, pi.Enter, input.RoomId); // 通知大厅 ServerRoomManager.Instance.UpdateRoomInfoToLobby(roomLogic); // 返回成功 EnterRoomReply output = new EnterRoomReply() { Ret = true, RoomId = roomLogic.RoomId, RoomName = roomLogic.RoomName, }; ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.EnterRoomReply, output.ToByteArray()); ServerRoomManager.Instance.Log($"MSG: ENTER_ROOM OK - Player enters the battlefield! Account:{pi.Enter.Account} - Room:{roomLogic.RoomName}"); // 玩家进入战场! } else { // 返回失败 EnterRoomReply output = new EnterRoomReply() { Ret = false, ErrMsg = errMsg, }; ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.EnterRoomReply, output.ToByteArray()); ServerRoomManager.Instance.Log("MSG: ENTER_ROOM Error - " + errMsg); } }