Example #1
0
    public RoomServerInfo GetRoomServer(SocketAsyncEventArgs args)
    {
        if (RoomServers.ContainsKey(args))
        {
            RoomServerInfo rsi = RoomServers[args];
            return(rsi);
        }

        return(null);
    }
Example #2
0
    static void ROOM_SERVER_LOGIN(byte[] bytes)
    {
        RoomServerLogin input          = RoomServerLogin.Parser.ParseFrom(bytes);
        RoomServerInfo  roomServerInfo = new RoomServerInfo()
        {
            Login = input,
        };

        ServerLobbyManager.Instance.RoomServers[_args] = roomServerInfo;

        RoomServerLoginReply output = new RoomServerLoginReply()
        {
            Ret = true,
        };

        // 返回消息
        ServerLobbyManager.Instance.SendMsg(_args, LOBBY_REPLY.RoomServerLoginReply, output.ToByteArray());
        ServerLobbyManager.Instance.Log($"MSG: Room-server Logged in! Address:{input.ServerName} - Address Real:{input.AddressReal} - MaxRoomCount:{input.MaxRoomCount} - MaxPlayerPerRoom:{input.MaxPlayerPerRoom}"); // 房间服务器登录成功!
    }
Example #3
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}"); // 找到空余的房间服务器,可以创建房间
        }
    }