Beispiel #1
0
 private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason,
                                      LoginResponseData replyData)
 {
     if (loginSuccess)
     {
         lock (_Friends)
         {
             for (int i = 0; i < replyData.BuddyList.Length; i++)
             {
                 FriendInfo friend = replyData.BuddyList[i];
                 _Friends[friend.UUID] = friend;
             }
         }
     }
 }
Beispiel #2
0
        private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason, LoginResponseData replyData)
        {
            if (loginSuccess)
            {
                _Client.DebugLog("Setting InventoryRoot to " + replyData.InventoryRoot.ToString());
                InventoryFolder rootFolder = new InventoryFolder(replyData.InventoryRoot);
                rootFolder.Name = String.Empty;
                rootFolder.ParentUUID = LLUUID.Zero;
                _Store.RootFolder = rootFolder;

                for (int i = 0; i < replyData.InventorySkeleton.Length; i++)
                    _Store.UpdateNodeFor(replyData.InventorySkeleton[i]);
            }
        }
Beispiel #3
0
 private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason,
     LoginResponseData reply)
 {
     id = reply.AgentID;
     sessionID = reply.SessionID;
     secureSessionID = reply.SecureSessionID;
     firstName = reply.FirstName;
     lastName = reply.LastName;
     startLocation = reply.StartLocation;
     agentAccess = reply.AgentAccess;
     Movement.Camera.LookDirection(reply.LookAt);
     homePosition = reply.HomePosition;
     homeLookAt = reply.HomeLookAt;
 }
Beispiel #4
0
        private void LoginReplyHandler(CapsClient client, LLSD result, Exception error)
        {
            if (error == null)
            {
                if (result != null && result.Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)result;

                    LLSD llsd;
                    string reason, message;

                    if (map.TryGetValue("reason", out llsd))
                        reason = llsd.AsString();
                    else
                        reason = String.Empty;

                    if (map.TryGetValue("message", out llsd))
                        message = llsd.AsString();
                    else
                        message = String.Empty;

                    if (map.TryGetValue("login", out llsd))
                    {
                        bool loginSuccess = llsd.AsBoolean();
                        bool redirect = (llsd.AsString() == "indeterminate");
                        LoginResponseData data = new LoginResponseData();

                        // Parse successful login replies in to LoginResponseData structs
                        if (loginSuccess)
                            data.Parse(map);

                        if (OnLoginResponse != null)
                        {
                            try { OnLoginResponse(loginSuccess, redirect, message, reason, data); }
                            catch (Exception ex) { Client.Log(ex.ToString(), Helpers.LogLevel.Error); }
                        }

                        if (loginSuccess && !redirect)
                        {
                            // Login succeeded

                            // These parameters are stored in NetworkManager, so instead of registering
                            // another callback for them we just set the values here
                            CircuitCode = data.CircuitCode;
                            LoginSeedCapability = data.SeedCapability;

                            UpdateLoginStatus(LoginStatus.ConnectingToSim, "Connecting to simulator...");

                            ulong handle = Helpers.UIntsToLong(data.RegionX, data.RegionY);

                            if (data.SimIP != null && data.SimPort != 0)
                            {
                                // Connect to the sim given in the login reply
                                if (Connect(data.SimIP, data.SimPort, handle, true, LoginSeedCapability) != null)
                                {
                                    // Request the economy data right after login
                                    SendPacket(new EconomyDataRequestPacket());

                                    // Update the login message with the MOTD returned from the server
                                    UpdateLoginStatus(LoginStatus.Success, message);

                                    // Fire an event for connecting to the grid
                                    if (OnConnected != null)
                                    {
                                        try { OnConnected(this.Client); }
                                        catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                                    }
                                }
                                else
                                {
                                    UpdateLoginStatus(LoginStatus.Failed,
                                        "Unable to establish a UDP connection to the simulator");
                                }
                            }
                            else
                            {
                                UpdateLoginStatus(LoginStatus.Failed,
                                    "Login server did not return a simulator address");
                            }
                        }
                        else if (redirect)
                        {
                            // Login redirected

                            // Make the next login URL jump
                            UpdateLoginStatus(LoginStatus.Redirecting, "Redirecting login...");

                            LoginParams loginParams = CurrentContext.Value;
                            loginParams.URI = LoginResponseData.ParseString("next_url", map);
                            //CurrentContext.Params.MethodName = LoginResponseData.ParseString("next_method", map);
                            // Ignore next_options and next_duration for now
                            CurrentContext = loginParams;

                            BeginLogin();
                        }
                        else
                        {
                            // Login failed

                            // Make sure a usable error key is set
                            if (reason != String.Empty)
                                InternalErrorKey = reason;
                            else
                                InternalErrorKey = "unknown";

                            UpdateLoginStatus(LoginStatus.Failed, message);
                        }
                    }
                    else
                    {
                        // Got an LLSD map but no login value
                        UpdateLoginStatus(LoginStatus.Failed, "login parameter missing in the response");
                    }
                }
                else
                {
                    // No LLSD response
                    UpdateLoginStatus(LoginStatus.Failed, "Empty or unparseable login response");
                }
            }
            else
            {
                // Connection error
                UpdateLoginStatus(LoginStatus.Failed, error.Message);
            }
        }
Beispiel #5
0
        private void LoginMethodCallback(IAsyncResult result)
        {
            object[] asyncState = result.AsyncState as object[];
            LoginProxy proxy = asyncState[0] as LoginProxy;
            LoginContext context = asyncState[1] as LoginContext;
            XmlRpcAsyncResult clientResult = result as XmlRpcAsyncResult;
            LoginMethodResponse reply;
            IPAddress simIP = IPAddress.Any; // Temporary
            ushort simPort = 0;
            uint regionX = 0;
            uint regionY = 0;
            bool loginSuccess = false;

            // Fetch the login response
            try
            {
                reply = proxy.EndLoginToSimulator(clientResult);
                if (context != CurrentContext)
                    return;
            }
            catch (Exception ex)
            {
                Client.DebugLog(ex.ToString());

                UpdateLoginStatus(LoginStatus.Failed, "Error retrieving the login response from the server");
                return;
            }

            string reason = reply.reason;
            string message = reply.message;

            if (reply.login == "true")
            {
                loginSuccess = true;

                // FIXME: No information should be set here, everything can take care of itself
                // through login reply handlers

                #region Critical Information

                try
                {
                    // Networking
                    Client.Network.CircuitCode = (uint)reply.circuit_code;
                    regionX = (uint)reply.region_x;
                    regionY = (uint)reply.region_y;
                    simPort = (ushort)reply.sim_port;
                    Helpers.TryParse(reply.sim_ip, out simIP);
                    LoginSeedCapability = reply.seed_capability;
                }
                catch (Exception)
                {
                    UpdateLoginStatus(LoginStatus.Failed, "Login server failed to return critical information");
                    return;
                }

                #endregion Critical Information
            }

            bool redirect = (reply.login == "indeterminate");

            try
            {
                if (OnLoginResponse != null)
                {
                    LoginResponseData data = new LoginResponseData();
                    if (loginSuccess)
                    {
                        data.Parse(reply);
                    }
                    try { OnLoginResponse(loginSuccess, redirect, message, reason, data); }
                    catch (Exception ex) { Client.Log(ex.ToString(), Helpers.LogLevel.Error); }
                }
            }
            catch (Exception ex) { Client.Log(ex.ToString(), Helpers.LogLevel.Error); }

            // Make the next network jump, if needed
            if (redirect)
            {
                UpdateLoginStatus(LoginStatus.Redirecting, "Redirecting login...");

                // Handle indeterminate logins
                CurrentContext.Params.URI = reply.next_url;
                CurrentContext.Params.MethodName = reply.next_method;

                // Ignore next_options and next_duration for now
                BeginLogin();
            }
            else if (loginSuccess)
            {
                UpdateLoginStatus(LoginStatus.ConnectingToSim, "Connecting to simulator...");

                ulong handle = Helpers.UIntsToLong(regionX, regionY);

                // Connect to the sim given in the login reply
                if (Connect(simIP, simPort, handle, true, LoginSeedCapability) != null)
                {
                    // Request the economy data right after login
                    SendPacket(new EconomyDataRequestPacket());

                    // Update the login message with the MOTD returned from the server
                    UpdateLoginStatus(LoginStatus.Success, message);

                    // Fire an event for connecting to the grid
                    if (OnConnected != null)
                    {
                        try { OnConnected(this.Client); }
                        catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                    }
                }
                else
                {
                    UpdateLoginStatus(LoginStatus.Failed, "Unable to connect to simulator");
                }
            }
            else
            {
                // Make sure a usable error key is set
                if (!String.IsNullOrEmpty(reason))
                    InternalErrorKey = reason;
                else
                    InternalErrorKey = "unknown";

                UpdateLoginStatus(LoginStatus.Failed, message);
            }
        }
Beispiel #6
0
        private void LoginMethodCallback(IAsyncResult result)
        {
            object[]            asyncState   = result.AsyncState as object[];
            LoginProxy          proxy        = asyncState[0] as LoginProxy;
            LoginContext        context      = asyncState[1] as LoginContext;
            XmlRpcAsyncResult   clientResult = result as XmlRpcAsyncResult;
            LoginMethodResponse reply;
            IPAddress           simIP = IPAddress.Any; // Temporary
            ushort simPort            = 0;
            uint   regionX            = 0;
            uint   regionY            = 0;
            bool   loginSuccess       = false;

            // Fetch the login response
            try
            {
                reply = proxy.EndLoginToSimulator(clientResult);
                if (context != CurrentContext)
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                Client.DebugLog(ex.ToString());

                UpdateLoginStatus(LoginStatus.Failed, "Error retrieving the login response from the server");
                return;
            }

            string reason  = reply.reason;
            string message = reply.message;

            if (reply.login == "true")
            {
                loginSuccess = true;

                // FIXME: No information should be set here, everything can take care of itself
                // through login reply handlers

                #region Critical Information

                try
                {
                    // Networking
                    Client.Network.CircuitCode = (uint)reply.circuit_code;
                    regionX = (uint)reply.region_x;
                    regionY = (uint)reply.region_y;
                    simPort = (ushort)reply.sim_port;
                    Helpers.TryParse(reply.sim_ip, out simIP);
                    LoginSeedCapability = reply.seed_capability;
                }
                catch (Exception)
                {
                    UpdateLoginStatus(LoginStatus.Failed, "Login server failed to return critical information");
                    return;
                }

                #endregion Critical Information
            }

            bool redirect = (reply.login == "indeterminate");

            try
            {
                if (OnLoginResponse != null)
                {
                    LoginResponseData data = new LoginResponseData();
                    if (loginSuccess)
                    {
                        data.Parse(reply);
                    }
                    try { OnLoginResponse(loginSuccess, redirect, message, reason, data); }
                    catch (Exception ex) { Client.Log(ex.ToString(), Helpers.LogLevel.Error); }
                }
            }
            catch (Exception ex) { Client.Log(ex.ToString(), Helpers.LogLevel.Error); }

            // Make the next network jump, if needed
            if (redirect)
            {
                UpdateLoginStatus(LoginStatus.Redirecting, "Redirecting login...");

                // Handle indeterminate logins
                CurrentContext.Params.URI        = reply.next_url;
                CurrentContext.Params.MethodName = reply.next_method;

                // Ignore next_options and next_duration for now
                BeginLogin();
            }
            else if (loginSuccess)
            {
                UpdateLoginStatus(LoginStatus.ConnectingToSim, "Connecting to simulator...");

                ulong handle = Helpers.UIntsToLong(regionX, regionY);

                // Connect to the sim given in the login reply
                if (Connect(simIP, simPort, handle, true, LoginSeedCapability) != null)
                {
                    // Request the economy data right after login
                    SendPacket(new EconomyDataRequestPacket());

                    // Update the login message with the MOTD returned from the server
                    UpdateLoginStatus(LoginStatus.Success, message);

                    // Fire an event for connecting to the grid
                    if (OnConnected != null)
                    {
                        try { OnConnected(this.Client); }
                        catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                    }
                }
                else
                {
                    UpdateLoginStatus(LoginStatus.Failed, "Unable to connect to simulator");
                }
            }
            else
            {
                // Make sure a usable error key is set
                if (!String.IsNullOrEmpty(reason))
                {
                    InternalErrorKey = reason;
                }
                else
                {
                    InternalErrorKey = "unknown";
                }

                UpdateLoginStatus(LoginStatus.Failed, message);
            }
        }
        private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason, LoginResponseData replyData)
        {
            if (loginSuccess)
            {
                // Initialize the store here so we know who owns it:
                _Store = new Inventory(_Client, this, _Client.Self.AgentID);
                Logger.DebugLog("Setting InventoryRoot to " + replyData.InventoryRoot.ToString(), _Client);
                InventoryFolder rootFolder = new InventoryFolder(replyData.InventoryRoot);
                rootFolder.Name = String.Empty;
                rootFolder.ParentUUID = LLUUID.Zero;
                _Store.RootFolder = rootFolder;

                for (int i = 0; i < replyData.InventorySkeleton.Length; i++)
                    _Store.UpdateNodeFor(replyData.InventorySkeleton[i]);

                InventoryFolder libraryRootFolder = new InventoryFolder(replyData.LibraryRoot);
                libraryRootFolder.Name = String.Empty;
                libraryRootFolder.ParentUUID = LLUUID.Zero;
                _Store.LibraryFolder = libraryRootFolder;

                for(int i = 0; i < replyData.LibrarySkeleton.Length; i++)
                    _Store.UpdateNodeFor(replyData.LibrarySkeleton[i]);
            }
        }
Beispiel #8
0
        private void LoginReplyHandler(CapsClient client, LLSD result, Exception error)
        {
            if (error == null)
            {
                if (result != null && result.Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)result;

                    LLSD   llsd;
                    string reason, message;

                    if (map.TryGetValue("reason", out llsd))
                    {
                        reason = llsd.AsString();
                    }
                    else
                    {
                        reason = String.Empty;
                    }

                    if (map.TryGetValue("message", out llsd))
                    {
                        message = llsd.AsString();
                    }
                    else
                    {
                        message = String.Empty;
                    }

                    if (map.TryGetValue("login", out llsd))
                    {
                        bool loginSuccess      = llsd.AsBoolean();
                        bool redirect          = (llsd.AsString() == "indeterminate");
                        LoginResponseData data = new LoginResponseData();

                        // Parse successful login replies in to LoginResponseData structs
                        if (loginSuccess)
                        {
                            data.Parse(map);
                        }

                        if (OnLoginResponse != null)
                        {
                            try { OnLoginResponse(loginSuccess, redirect, message, reason, data); }
                            catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }
                        }

                        if (loginSuccess && !redirect)
                        {
                            // Login succeeded

                            // These parameters are stored in NetworkManager, so instead of registering
                            // another callback for them we just set the values here
                            CircuitCode         = data.CircuitCode;
                            LoginSeedCapability = data.SeedCapability;

                            UpdateLoginStatus(LoginStatus.ConnectingToSim, "Connecting to simulator...");

                            ulong handle = Helpers.UIntsToLong(data.RegionX, data.RegionY);

                            if (data.SimIP != null && data.SimPort != 0)
                            {
                                // Connect to the sim given in the login reply
                                if (Connect(data.SimIP, data.SimPort, handle, true, LoginSeedCapability) != null)
                                {
                                    // Request the economy data right after login
                                    SendPacket(new EconomyDataRequestPacket());

                                    // Update the login message with the MOTD returned from the server
                                    UpdateLoginStatus(LoginStatus.Success, message);

                                    // Fire an event for connecting to the grid
                                    if (OnConnected != null)
                                    {
                                        try { OnConnected(this.Client); }
                                        catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                                    }
                                }
                                else
                                {
                                    UpdateLoginStatus(LoginStatus.Failed,
                                                      "Unable to establish a UDP connection to the simulator");
                                }
                            }
                            else
                            {
                                UpdateLoginStatus(LoginStatus.Failed,
                                                  "Login server did not return a simulator address");
                            }
                        }
                        else if (redirect)
                        {
                            // Login redirected

                            // Make the next login URL jump
                            UpdateLoginStatus(LoginStatus.Redirecting, "Redirecting login...");

                            LoginParams loginParams = CurrentContext.Value;
                            loginParams.URI = LoginResponseData.ParseString("next_url", map);
                            //CurrentContext.Params.MethodName = LoginResponseData.ParseString("next_method", map);

                            // Sleep for some amount of time while the servers work
                            int seconds = (int)LoginResponseData.ParseUInt("next_duration", map);
                            Logger.Log("Sleeping for " + seconds + " seconds during a login redirect",
                                       Helpers.LogLevel.Info);
                            Thread.Sleep(seconds * 1000);

                            // Ignore next_options for now
                            CurrentContext = loginParams;

                            BeginLogin();
                        }
                        else
                        {
                            // Login failed

                            // Make sure a usable error key is set
                            if (reason != String.Empty)
                            {
                                InternalErrorKey = reason;
                            }
                            else
                            {
                                InternalErrorKey = "unknown";
                            }

                            UpdateLoginStatus(LoginStatus.Failed, message);
                        }
                    }
                    else
                    {
                        // Got an LLSD map but no login value
                        UpdateLoginStatus(LoginStatus.Failed, "login parameter missing in the response");
                    }
                }
                else
                {
                    // No LLSD response
                    InternalErrorKey = "bad response";
                    UpdateLoginStatus(LoginStatus.Failed, "Empty or unparseable login response");
                }
            }
            else
            {
                // Connection error
                InternalErrorKey = "no connection";
                UpdateLoginStatus(LoginStatus.Failed, error.Message);
            }
        }
Beispiel #9
0
 private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason,
     LoginResponseData replyData)
 {
     if (loginSuccess && replyData.BuddyList != null)
     {
         lock (FriendList)
         {
             for (int i = 0; i < replyData.BuddyList.Length; i++)
             {
                 FriendInfo friend = replyData.BuddyList[i];
                 FriendList[friend.UUID] = friend;
             }
         }
     }
 }
Beispiel #10
0
        private void LoginMethodCallback(IAsyncResult result)
        {
            object[] asyncState = result.AsyncState as object[];
            ILoginProxy proxy = asyncState[0] as ILoginProxy;
            LoginContext context = asyncState[1] as LoginContext;
            XmlRpcAsyncResult clientResult = result as XmlRpcAsyncResult;
            LoginMethodResponse reply;
            IPAddress simIP = IPAddress.Any; // Temporary
            ushort simPort = 0;
            uint regionX = 0;
            uint regionY = 0;
            bool loginSuccess = false;

            // Fetch the login response
            try
            {
                reply = proxy.EndLoginToSimulator(clientResult);
                if (context != CurrentContext)
                    return;
            }
            catch (Exception)
            {
                UpdateLoginStatus(LoginStatus.Failed, "Error retrieving the login response from the server");
                return;
            }

            string reason = reply.reason;
            string message = reply.message;

            if (reply.login == "true")
            {
                loginSuccess = true;

                // FIXME: No information should be set here, everything can take care of itself
                // through login reply handlers

                // Remove the quotes around our first name.
                if (reply.first_name[0] == '"')
                    reply.first_name = reply.first_name.Remove(0, 1);
                if (reply.first_name[reply.first_name.Length - 1] == '"')
                    reply.first_name = reply.first_name.Remove(reply.first_name.Length - 1);

                #region Critical Information

                try
                {
                    // Networking
                    Client.Network.CircuitCode = (uint)reply.circuit_code;
                    regionX = (uint)reply.region_x;
                    regionY = (uint)reply.region_y;
                    simPort = (ushort)reply.sim_port;
                    IPAddress.TryParse(reply.sim_ip, out simIP);
                    LoginSeedCapability = reply.seed_capability;
                }
                catch (Exception)
                {
                    UpdateLoginStatus(LoginStatus.Failed, "Login server failed to return critical information");
                    return;
                }

                #endregion Critical Information

                // Buddies:
                if (reply.buddy_list != null)
                {
                    foreach (BuddyListEntry buddy in reply.buddy_list)
                    {
                        Client.Friends.AddFriend(buddy.buddy_id, (FriendsManager.RightsFlags)buddy.buddy_rights_given,
                            (FriendsManager.RightsFlags)buddy.buddy_rights_has);
                    }
                }

                // Misc:
                //uint timestamp = (uint)reply.seconds_since_epoch;
                //DateTime time = Helpers.UnixTimeToDateTime(timestamp); // TODO: Do something with this?

                // Unhandled:
                // reply.gestures
                // reply.event_categories
                // reply.classified_categories
                // reply.event_notifications
                // reply.ui_config
                // reply.login_flags
                // reply.global_textures
                // reply.inventory_lib_root
                // reply.inventory_lib_owner
                // reply.inventory_skeleton
                // reply.inventory_skel_lib
                // reply.initial_outfit
            }

            bool redirect = (reply.login == "indeterminate");

            // Fire the client handler
            if (OnLoginReply != null)
            {
                try { OnLoginReply(loginSuccess, redirect, simIP, simPort, regionX, regionY, reason, message); }
                catch (Exception ex) { Client.Log(ex.ToString(), Helpers.LogLevel.Error); }
            }

            try
            {
                if (OnLoginResponse != null)
                {
                    LoginResponseData data = new LoginResponseData();
                    if (loginSuccess)
                    {
                        data.Parse(reply);
                    }
                    try { OnLoginResponse(loginSuccess, redirect, message, reason, data); }
                    catch (Exception ex) { Client.Log(ex.ToString(), Helpers.LogLevel.Error); }
                }
            }
            catch (Exception ex) { Client.Log(ex.ToString(), Helpers.LogLevel.Error); }

            // Make the next network jump, if needed
            if (redirect)
            {
                UpdateLoginStatus(LoginStatus.Redirecting, "Redirecting login...");

                // Handle indeterminate logins
                CurrentContext.Params.URI = reply.next_url;
                CurrentContext.Params.MethodName = reply.next_method;

                // Ignore next_options and next_duration for now
                BeginLogin();
            }
            else if (loginSuccess)
            {
                UpdateLoginStatus(LoginStatus.ConnectingToSim, "Connecting to simulator...");

                ulong handle = Helpers.UIntsToLong(regionX, regionY);

                // Connect to the sim given in the login reply
                if (Connect(simIP, simPort, handle, true, LoginSeedCapability) != null)
                {
                    // Request the economy data right after login
                    SendPacket(new EconomyDataRequestPacket());

                    // Update the login message with the MOTD returned from the server
                    UpdateLoginStatus(LoginStatus.Success, message);

                    // Fire an event for connecting to the grid
                    if (OnConnected != null)
                    {
                        try { OnConnected(this.Client); }
                        catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                    }
                }
                else
                {
                    UpdateLoginStatus(LoginStatus.Failed, "Unable to connect to simulator");
                }
            }
            else
            {
                // Make sure a usable error key is set
                if (!String.IsNullOrEmpty(reason))
                    InternalErrorKey = reason;
                else
                    InternalErrorKey = "unknown";

                UpdateLoginStatus(LoginStatus.Failed, message);
            }
        }