static void ASK_JOIN_ROOM_REPLY(byte[] bytes) { UIManager.Instance.EndConnecting(); AskJoinRoomReply input = AskJoinRoomReply.Parser.ParseFrom(bytes); if (input.Ret) { // 根据大厅传递回来的RoomServer的地址,链接RoomServer // 这个类是Room场景初始化的时候,GameRoomManager需要的数据,因为跨场景了,所以需要一个全局的地方进行传递 EnterRoomData roomData = new EnterRoomData() { Address = input.RoomServerAddress, Port = input.RoomServerPort, RoomId = input.RoomId, IsCreatingRoom = false, // 加入房间 }; ClientManager.Instance.EnterRoom = roomData; // 正式进入房间了。。。加载Room场景 ClientManager.Instance.StateMachine.TriggerTransition(ConnectionFSMStateEnum.StateEnum.CONNECTING_ROOM); ClientManager.Instance.LobbyManager.Log($"MSG: ASK_JOIN_ROOM_REPLY OK - 大厅回复可以加入房间。RoomServer:{roomData.Address}:{roomData.Port} - Room Name:{roomData.RoomId}"); } else { string msg = $"大厅发现没有多余的房间服务器可以分配!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); ClientManager.Instance.LobbyManager.Log("MSG: ASK_JOIN_ROOM_REPLY - Error " + msg); } }
static void ASK_JOIN_ROOM(byte[] bytes) { AskJoinRoom input = AskJoinRoom.Parser.ParseFrom(bytes); RoomServerLogin theRoomServer = null; ServerLobbyManager.Instance.Log($"LobbyMsgReply ASK_JOIN_ROOM - Received!"); // foreach (var keyValue in ServerLobbyManager.Instance.RoomServers) { RoomServerInfo roomServerInfo = keyValue.Value; RoomServerLogin roomServer = roomServerInfo.Login; if (ServerLobbyManager.Instance.Rooms.Count < roomServer.MaxRoomCount && input.MaxPlayerCount < roomServer.MaxPlayerPerRoom) { theRoomServer = roomServer; } } if (theRoomServer == null) { AskJoinRoomReply output = new AskJoinRoomReply() { Ret = false, }; ServerLobbyManager.Instance.SendMsg(_args, LOBBY_REPLY.AskJoinRoomReply, output.ToByteArray()); ServerLobbyManager.Instance.Log("MSG: There is not enough free room-servers!"); // 没有空余的房间服务器! } else { AskJoinRoomReply output = new AskJoinRoomReply() { Ret = true, RoomServerAddress = theRoomServer.AddressReal, // 发给客户端的是从外部连接的地址 RoomServerPort = theRoomServer.Port, RoomId = input.RoomId, }; ServerLobbyManager.Instance.SendMsg(_args, LOBBY_REPLY.AskJoinRoomReply, output.ToByteArray()); ServerLobbyManager.Instance.Log($"MSG: Find a free room-server, you can join the room! - {theRoomServer.Address}:{theRoomServer.Port}"); // 找到空余的房间服务器,可以加入房间 } }