Ejemplo n.º 1
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}"); // 找到空余的房间服务器,可以创建房间
        }
    }
Ejemplo n.º 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}"); // 房间服务器登录成功!
    }
Ejemplo n.º 3
0
    private void OnComplete(SocketAction action, string msg)
    {
        switch (action)
        {
        case SocketAction.Connect:
        {
            Log("GameLobbyManager OnComplete - Connected!");
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Success);
            // RoomServer向LobbyServer发送第一条消息,登录该RoomServer
            RoomServerLogin data = new RoomServerLogin()
            {
                ServerName       = ServerRoomManager.Instance.ServerName,
                ServerId         = ServerRoomManager.Instance.ServerId,
                MaxRoomCount     = ServerRoomManager.Instance.MaxRoomCount,
                MaxPlayerPerRoom = ServerRoomManager.Instance.MaxPlayerPerRoom,
                Address          = ServerRoomManager.Instance._server.Address,
                Port             = ServerRoomManager.Instance._server.Port,
                AddressReal      = ServerRoomManager.Instance.AddressReal,
            };
            SendMsg(LOBBY.RoomServerLogin, data.ToByteArray());
            StartHeartBeat();
            Debug.Log(msg);
        }
        break;

        case SocketAction.Send:
            break;

        case SocketAction.Receive:
            break;

        case SocketAction.Close:
            StopHeartBeat();
            //UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            Debug.LogWarning(msg);
            break;

        case SocketAction.Error:
            Debug.LogWarning(msg);
            break;
        }
    }