public void OnClickJoinRoom()
 {
     if (_selectedItem != null)
     {
         long        roomId         = _selectedItem.RoomId;
         int         maxPlayerCount = _selectedItem.MaxPlayerCount;
         AskJoinRoom output         = new AskJoinRoom()
         {
             RoomId         = roomId,
             MaxPlayerCount = maxPlayerCount,
         };
         ClientManager.Instance.LobbyManager.SendMsg(LOBBY.AskJoinRoom, output.ToByteArray());
         ClientManager.Instance.LobbyManager.Log("PanelLobbyMain OnClickJoinRoom.");
     }
 }
Пример #2
0
    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}"); // 找到空余的房间服务器,可以加入房间
        }
    }