Exemplo n.º 1
0
    static void ASK_CREATE_ROOM_REPLY(byte[] bytes)
    {
        UIManager.Instance.EndConnecting();
        AskCreateRoomReply input = AskCreateRoomReply.Parser.ParseFrom(bytes);

        if (input.Ret)
        {
            // 根据大厅传递回来的RoomServer的地址,链接RoomServer
            // 这个类是Room场景初始化的时候,GameRoomManager需要的数据,因为跨场景了,所以需要一个全局的地方进行传递
            EnterRoomData roomData = new EnterRoomData()
            {
                Address        = input.RoomServerAddress,
                Port           = input.RoomServerPort,
                MaxPlayerCount = input.MaxPlayerCount,
                RoomName       = input.RoomName,
                IsCreatingRoom = true, // 创建房间
                RoomId         = 0,
            };
            ClientManager.Instance.EnterRoom = roomData;

            // 正式进入房间了。。。加载Room场景
            ClientManager.Instance.StateMachine.TriggerTransition(ConnectionFSMStateEnum.StateEnum.CONNECTING_ROOM);
            ClientManager.Instance.LobbyManager.Log($"MSG: ASK_CREATE_ROOM_REPLY OK - 大厅回复可以创建房间。RoomServer:{roomData.Address}:{roomData.Port} - Room Name:{roomData.RoomName}");
        }
        else
        {
            string msg = $"大厅发现没有多余的房间服务器可以分配!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            ClientManager.Instance.LobbyManager.Log("MSG: ASK_CREATE_ROOM_REPLY Error - " + msg);
        }
    }
Exemplo n.º 2
0
    static void ASK_CREATE_ROOM(byte[] bytes)
    {
        AskCreateRoom   input         = AskCreateRoom.Parser.ParseFrom(bytes);
        RoomServerLogin theRoomServer = null;

        ServerLobbyManager.Instance.Log($"LobbyMsgReply ASK_CREATE_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)
        {
            AskCreateRoomReply output = new AskCreateRoomReply()
            {
                Ret = false,
            };
            ServerLobbyManager.Instance.SendMsg(_args, LOBBY_REPLY.AskCreateRoomReply, output.ToByteArray());
            ServerLobbyManager.Instance.Log("MSG: There is not enough free room-servers!"); // 没有空余的房间服务器!
        }
        else
        {
            AskCreateRoomReply output = new AskCreateRoomReply()
            {
                Ret = true,
                RoomServerAddress = theRoomServer.AddressReal, // 发给客户端的是从外部连接的地址
                RoomServerPort    = theRoomServer.Port,
                MaxPlayerCount    = input.MaxPlayerCount,
                RoomName          = input.RoomName,
            };

            ServerLobbyManager.Instance.SendMsg(_args, LOBBY_REPLY.AskCreateRoomReply, output.ToByteArray());
            ServerLobbyManager.Instance.Log($"MSG: Find a free room-server, you can create the room! - {theRoomServer.Address}:{theRoomServer.Port}"); // 找到空余的房间服务器,可以创建房间
        }
    }