Exemplo n.º 1
0
    public async Task <LoginResponse> Connect(string uri, Credential credential, Slurl slurl = null, bool getInventoryLibrary = true, bool godMode = false)
    {
        if (slurl == null)
        {
            slurl = new Slurl(Slurl.SIM_LOCATION_LAST);
        }
        Logger.LogDebug($"INFO Login.Connect: Connecting {credential.First} {credential.Last} using {uri}.");

        XmlRpcParameterArray parameters = CreateLoginParameters(credential, slurl, getInventoryLibrary, godMode);

        XmlRpcResponse response = await XmlRpcClient.Call(uri, "login_to_simulator", parameters);

        LoginResponse loginResponse = new LoginResponse();

        if (response.FaultCode != 0)
        {
            loginResponse.LoginSucceeded  = false;
            loginResponse.LoginFailReason = response.FaultCode.ToString();
            loginResponse.Message         = response.FaultString;
            loginResponse.MessageId       = "XmlRpcError";
            return(loginResponse);
        }

        if (response.Parameters.Count != 1 || (response.Parameters[0] is XmlRpcStruct == false))
        {
            loginResponse.LoginSucceeded  = false;
            loginResponse.LoginFailReason = "500";
            loginResponse.Message         = "Login response contained incorrect parameters.";
            loginResponse.MessageId       = "XmlRpcError";
            return(loginResponse);
        }

        XmlRpcStruct responseData = (XmlRpcStruct)response.Parameters[0];

        if (responseData.Has("login") == false ||
            (responseData["login"] is XmlRpcString == false) ||
            ((XmlRpcString)responseData["login"]).Value != "true")
        {
            loginResponse.LoginSucceeded  = false;
            loginResponse.LoginFailReason = responseData["reason"]?.AsString;
            loginResponse.Message         = responseData["message"]?.AsString;
            loginResponse.MessageId       = responseData["message_id"]?.AsString;
            return(loginResponse);
        }

        Logger.LogInfo("Login.Connect: Connection was successful.");

        if (ProcessLoginSuccessResponse(responseData, loginResponse))
        {
            loginResponse.LoginSucceeded = true;
            return(loginResponse);
        }
        else
        {
            // Yet another error
        }

        return(loginResponse);
    }