Exemple #1
0
        public static InventoryFolder[] ParseInventoryFolders(string key, LLUUID owner, LLSDMap reply)
        {
            List <InventoryFolder> folders = new List <InventoryFolder>();

            LLSD skeleton;

            if (reply.TryGetValue(key, out skeleton) && skeleton.Type == LLSDType.Array)
            {
                LLSDArray array = (LLSDArray)skeleton;

                for (int i = 0; i < array.Count; i++)
                {
                    if (array[i].Type == LLSDType.Map)
                    {
                        LLSDMap         map    = (LLSDMap)array[i];
                        InventoryFolder folder = new InventoryFolder(map["folder_id"].AsUUID());
                        folder.PreferredType = (AssetType)map["type_default"].AsInteger();
                        folder.Version       = map["version"].AsInteger();
                        folder.OwnerID       = owner;
                        folder.ParentUUID    = map["parent_id"].AsUUID();
                        folder.Name          = map["name"].AsString();

                        folders.Add(folder);
                    }
                }

                return(folders.ToArray());
            }

            return(new InventoryFolder[0]);
        }
Exemple #2
0
        public static LLUUID ParseUUID(string key, LLSDMap reply)
        {
            LLSD llsd;

            if (reply.TryGetValue(key, out llsd))
            {
                return(llsd.AsUUID());
            }
            else
            {
                return(LLUUID.Zero);
            }
        }
Exemple #3
0
        public static uint ParseUInt(string key, LLSDMap reply)
        {
            LLSD llsd;

            if (reply.TryGetValue(key, out llsd))
            {
                return((uint)llsd.AsInteger());
            }
            else
            {
                return(0);
            }
        }
Exemple #4
0
        public static string ParseString(string key, LLSDMap reply)
        {
            LLSD llsd;

            if (reply.TryGetValue(key, out llsd))
            {
                return(llsd.AsString());
            }
            else
            {
                return(String.Empty);
            }
        }
Exemple #5
0
        public static Vector3 ParseVector3(string key, LLSDMap reply)
        {
            LLSD llsd;

            if (reply.TryGetValue(key, out llsd))
            {
                if (llsd.Type == LLSDType.Array)
                {
                    return(((LLSDArray)llsd).AsVector3());
                }
                else if (llsd.Type == LLSDType.String)
                {
                    LLSDArray array = (LLSDArray)LLSDParser.DeserializeNotation(llsd.AsString());
                    return(array.AsVector3());
                }
            }

            return(Vector3.Zero);
        }
        public void Start(Simian server)
        {
            this.server = server;

            LLSD llsd;

            try
            {
                XmlTextReader reader = new XmlTextReader(File.OpenRead(server.DataDir + "simiandata.xml"));
                llsd = LLSDParser.DeserializeXml(reader);
                reader.Close();
            }
            catch (FileNotFoundException)
            {
                return;
            }
            catch (Exception ex)
            {
                Logger.Log("Failed to load saved data: " + ex.Message, Helpers.LogLevel.Error);
                return;
            }

            if (llsd is LLSDMap)
            {
                LLSDMap dictionary = (LLSDMap)llsd;

                for (int i = 0; i < server.PersistentExtensions.Count; i++)
                {
                    IPersistable persistable = server.PersistentExtensions[i];

                    LLSD savedData;
                    if (dictionary.TryGetValue(persistable.ToString(), out savedData))
                    {
                        Logger.DebugLog("Loading saved data for " + persistable.ToString());
                        persistable.Deserialize(savedData);
                    }
                    else
                    {
                        Logger.DebugLog("No saved data found for " + persistable.ToString());
                    }
                }
            }
        }
Exemple #7
0
        public static LLUUID ParseMappedUUID(string key, string key2, LLSDMap reply)
        {
            LLSD folderLLSD;

            if (reply.TryGetValue(key, out folderLLSD) && folderLLSD.Type == LLSDType.Array)
            {
                LLSDArray array = (LLSDArray)folderLLSD;
                if (array.Count == 1 && array[0].Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)array[0];
                    LLSD    folder;
                    if (map.TryGetValue(key2, out folder))
                    {
                        return(folder.AsUUID());
                    }
                }
            }

            return(LLUUID.Zero);
        }
Exemple #8
0
        public static LLVector3 ParseLLVector3(string key, LLSDMap reply)
        {
            LLSD llsd;

            if (reply.TryGetValue(key, out llsd))
            {
                if (llsd.Type == LLSDType.Array)
                {
                    LLVector3 vec = new LLVector3();
                    vec.FromLLSD(llsd);
                    return(vec);
                }
                else if (llsd.Type == LLSDType.String)
                {
                    LLSDArray array = (LLSDArray)LLSDParser.DeserializeNotation(llsd.AsString());
                    LLVector3 vec   = new LLVector3();
                    vec.FromLLSD(array);
                    return(vec);
                }
            }

            return(LLVector3.Zero);
        }
Exemple #9
0
        public static Vector3 ParseVector3(string key, LLSDMap reply)
        {
            LLSD llsd;
            if (reply.TryGetValue(key, out llsd))
            {
                if (llsd.Type == LLSDType.Array)
                {
                    Vector3 vec = new Vector3();
                    vec.FromLLSD(llsd);
                    return vec;
                }
                else if (llsd.Type == LLSDType.String)
                {
                    LLSDArray array = (LLSDArray)LLSDParser.DeserializeNotation(llsd.AsString());
                    Vector3 vec = new Vector3();
                    vec.FromLLSD(array);
                    return vec;
                }
            }

            return Vector3.Zero;
        }
Exemple #10
0
 public static string ParseString(string key, LLSDMap reply)
 {
     LLSD llsd;
     if (reply.TryGetValue(key, out llsd))
         return llsd.AsString();
     else
         return String.Empty;
 }
Exemple #11
0
 public static UUID ParseUUID(string key, LLSDMap reply)
 {
     LLSD llsd;
     if (reply.TryGetValue(key, out llsd))
         return llsd.AsUUID();
     else
         return UUID.Zero;
 }
Exemple #12
0
 public static uint ParseUInt(string key, LLSDMap reply)
 {
     LLSD llsd;
     if (reply.TryGetValue(key, out llsd))
         return (uint)llsd.AsInteger();
     else
         return 0;
 }
Exemple #13
0
        public void Parse(LLSDMap reply)
        {
            try
            {
                AgentID = ParseUUID("agent_id", reply);
                SessionID = ParseUUID("session_id", reply);
                SecureSessionID = ParseUUID("secure_session_id", reply);
                FirstName = ParseString("first_name", reply).Trim('"');
                LastName = ParseString("last_name", reply).Trim('"');
                StartLocation = ParseString("start_location", reply);
                AgentAccess = ParseString("agent_access", reply);
                LookAt = ParseVector3("look_at", reply); 
            }
            catch (LLSDException e)
            {
                // FIXME: sometimes look_at comes back with invalid values e.g: 'look_at':'[r1,r2.0193899999999998204e-06,r0]'
                // need to handle that somehow
                Logger.DebugLog("login server returned (some) invalid data: " + e.Message);
            }

            // Home
            LLSDMap home = null;
            LLSD llsdHome = LLSDParser.DeserializeNotation(reply["home"].AsString());

            if (llsdHome.Type == LLSDType.Map)
            {
                home = (LLSDMap)llsdHome;

                LLSD homeRegion;
                if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == LLSDType.Array)
                {
                    LLSDArray homeArray = (LLSDArray)homeRegion;
                    if (homeArray.Count == 2)
                        HomeRegion = Helpers.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger());
                    else
                        HomeRegion = 0;
                }

                HomePosition = ParseVector3("position", home);
                HomeLookAt = ParseVector3("look_at", home);
            }
            else
            {
                HomeRegion = 0;
                HomePosition = Vector3.Zero;
                HomeLookAt = Vector3.Zero;
            }

            CircuitCode = ParseUInt("circuit_code", reply);
            RegionX = ParseUInt("region_x", reply);
            RegionY = ParseUInt("region_y", reply);
            SimPort = (ushort)ParseUInt("sim_port", reply);
            string simIP = ParseString("sim_ip", reply);
            IPAddress.TryParse(simIP, out SimIP);
            SeedCapability = ParseString("seed_capability", reply);

            // Buddy list
            LLSD buddyLLSD;
            if (reply.TryGetValue("buddy-list", out buddyLLSD) && buddyLLSD.Type == LLSDType.Array)
            {
                LLSDArray buddyArray = (LLSDArray)buddyLLSD;
                BuddyList = new FriendInfo[buddyArray.Count];

                for (int i = 0; i < buddyArray.Count; i++)
                {
                    if (buddyArray[i].Type == LLSDType.Map)
                    {
                        LLSDMap buddy = (LLSDMap)buddyArray[i];
                        BuddyList[i] = new FriendInfo(
                            ParseUUID("buddy_id", buddy),
                            (FriendRights)ParseUInt("buddy_rights_given", buddy),
                            (FriendRights)ParseUInt("buddy_rights_has", buddy));
                    }
                }
            }

            SecondsSinceEpoch = Helpers.UnixTimeToDateTime(ParseUInt("seconds_since_epoch", reply));
            InventoryRoot = ParseMappedUUID("inventory-root", "folder_id", reply);
            InventoryFolders = ParseInventoryFolders("inventory-skeleton", AgentID, reply);
            LibraryRoot = ParseMappedUUID("inventory-lib-root", "folder_id", reply);
            LibraryOwner = ParseMappedUUID("inventory-lib-owner", "agent_id", reply);
            LibraryFolders = ParseInventoryFolders("inventory-skel-lib", LibraryOwner, reply);
        }
Exemple #14
0
        public void Parse(LLSDMap reply)
        {
            AgentID = ParseUUID("agent_id", reply);
            SessionID = ParseUUID("session_id", reply);
            SecureSessionID = ParseUUID("secure_session_id", reply);
            FirstName = ParseString("first_name", reply).Trim('"');
            LastName = ParseString("last_name", reply).Trim('"');
            StartLocation = ParseString("start_location", reply);
            AgentAccess = ParseString("agent_access", reply);
            LookAt = ParseLLVector3("look_at", reply);

            // Home
            LLSDMap home = (LLSDMap)LLSDParser.DeserializeNotation(reply["home"].AsString());

            if (home != null)
            {
                LLSD homeRegion;
                if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == LLSDType.Array)
                {
                    LLSDArray homeArray = (LLSDArray)homeRegion;
                    if (homeArray.Count == 2)
                        HomeRegion = Helpers.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger());
                    else
                        HomeRegion = 0;
                }

                HomePosition = ParseLLVector3("position", home);
                HomeLookAt = ParseLLVector3("look_at", home);
            }
            else
            {
                HomeRegion = 0;
                HomePosition = LLVector3.Zero;
                HomeLookAt = LLVector3.Zero;
            }

            CircuitCode = ParseUInt("circuit_code", reply);
            RegionX = ParseUInt("region_x", reply);
            RegionY = ParseUInt("region_y", reply);
            SimPort = (ushort)ParseUInt("sim_port", reply);
            string simIP = ParseString("sim_ip", reply);
            IPAddress.TryParse(simIP, out SimIP);
            SeedCapability = ParseString("seed_capability", reply);

            // Buddy list
            LLSD buddyLLSD;
            if (reply.TryGetValue("buddy-list", out buddyLLSD) && buddyLLSD.Type == LLSDType.Array)
            {
                LLSDArray buddyArray = (LLSDArray)buddyLLSD;
                BuddyList = new FriendInfo[buddyArray.Count];

                for (int i = 0; i < buddyArray.Count; i++)
                {
                    if (buddyArray[i].Type == LLSDType.Map)
                    {
                        LLSDMap buddy = (LLSDMap)buddyArray[i];
                        BuddyList[i] = new FriendInfo(
                            ParseUUID("buddy_id", buddy),
                            (FriendRights)ParseUInt("buddy_rights_given", buddy),
                            (FriendRights)ParseUInt("buddy_rights_has", buddy));
                    }
                }
            }

            SecondsSinceEpoch = Helpers.UnixTimeToDateTime(ParseUInt("seconds_since_epoch", reply));
            InventoryRoot = ParseMappedUUID("inventory-root", "folder_id", reply);
            InventorySkeleton = ParseInventoryFolders("inventory-skeleton", AgentID, reply);
            LibraryRoot = ParseMappedUUID("inventory-lib-root", "folder_id", reply);
            LibraryOwner = ParseMappedUUID("inventory-lib-owner", "agent_id", reply);
            LibrarySkeleton = ParseInventoryFolders("inventory-skel-lib", LibraryOwner, reply);
        }
Exemple #15
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);
            }
        }
Exemple #16
0
        public void Parse(LLSDMap reply)
        {
            try
            {
                AgentID         = ParseUUID("agent_id", reply);
                SessionID       = ParseUUID("session_id", reply);
                SecureSessionID = ParseUUID("secure_session_id", reply);
                FirstName       = ParseString("first_name", reply).Trim('"');
                LastName        = ParseString("last_name", reply).Trim('"');
                StartLocation   = ParseString("start_location", reply);
                AgentAccess     = ParseString("agent_access", reply);
                LookAt          = ParseLLVector3("look_at", reply);
            }
            catch (LLSDException e)
            {
                // FIXME: sometimes look_at comes back with invalid values e.g: 'look_at':'[r1,r2.0193899999999998204e-06,r0]'
                // need to handle that somehow
                Logger.DebugLog("login server returned (some) invalid data: " + e.Message);
            }

            // Home
            LLSDMap home     = null;
            LLSD    llsdHome = LLSDParser.DeserializeNotation(reply["home"].AsString());

            if (llsdHome.Type == LLSDType.Map)
            {
                home = (LLSDMap)llsdHome;

                LLSD homeRegion;
                if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == LLSDType.Array)
                {
                    LLSDArray homeArray = (LLSDArray)homeRegion;
                    if (homeArray.Count == 2)
                    {
                        HomeRegion = Helpers.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger());
                    }
                    else
                    {
                        HomeRegion = 0;
                    }
                }

                HomePosition = ParseLLVector3("position", home);
                HomeLookAt   = ParseLLVector3("look_at", home);
            }
            else
            {
                HomeRegion   = 0;
                HomePosition = LLVector3.Zero;
                HomeLookAt   = LLVector3.Zero;
            }

            CircuitCode = ParseUInt("circuit_code", reply);
            RegionX     = ParseUInt("region_x", reply);
            RegionY     = ParseUInt("region_y", reply);
            SimPort     = (ushort)ParseUInt("sim_port", reply);
            string simIP = ParseString("sim_ip", reply);

            IPAddress.TryParse(simIP, out SimIP);
            SeedCapability = ParseString("seed_capability", reply);

            // Buddy list
            LLSD buddyLLSD;

            if (reply.TryGetValue("buddy-list", out buddyLLSD) && buddyLLSD.Type == LLSDType.Array)
            {
                LLSDArray buddyArray = (LLSDArray)buddyLLSD;
                BuddyList = new FriendInfo[buddyArray.Count];

                for (int i = 0; i < buddyArray.Count; i++)
                {
                    if (buddyArray[i].Type == LLSDType.Map)
                    {
                        LLSDMap buddy = (LLSDMap)buddyArray[i];
                        BuddyList[i] = new FriendInfo(
                            ParseUUID("buddy_id", buddy),
                            (FriendRights)ParseUInt("buddy_rights_given", buddy),
                            (FriendRights)ParseUInt("buddy_rights_has", buddy));
                    }
                }
            }

            SecondsSinceEpoch = Helpers.UnixTimeToDateTime(ParseUInt("seconds_since_epoch", reply));
            InventoryRoot     = ParseMappedUUID("inventory-root", "folder_id", reply);
            InventorySkeleton = ParseInventoryFolders("inventory-skeleton", AgentID, reply);
            LibraryRoot       = ParseMappedUUID("inventory-lib-root", "folder_id", reply);
            LibraryOwner      = ParseMappedUUID("inventory-lib-owner", "agent_id", reply);
            LibrarySkeleton   = ParseInventoryFolders("inventory-skel-lib", LibraryOwner, reply);
        }
Exemple #17
0
        public static UUID ParseMappedUUID(string key, string key2, LLSDMap reply)
        {
            LLSD folderLLSD;
            if (reply.TryGetValue(key, out folderLLSD) && folderLLSD.Type == LLSDType.Array)
            {
                LLSDArray array = (LLSDArray)folderLLSD;
                if (array.Count == 1 && array[0].Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)array[0];
                    LLSD folder;
                    if (map.TryGetValue(key2, out folder))
                        return folder.AsUUID();
                }
            }

            return UUID.Zero;
        }
Exemple #18
0
        public static FolderData[] ParseInventoryFolders(string key, UUID owner, LLSDMap reply)
        {
            List<FolderData> folders = new List<FolderData>();

            LLSD skeleton;
            if (reply.TryGetValue(key, out skeleton) && skeleton.Type == LLSDType.Array)
            {
                LLSDArray array = (LLSDArray)skeleton;

                for (int i = 0; i < array.Count; i++)
                {
                    if (array[i].Type == LLSDType.Map)
                    {
                        LLSDMap map = (LLSDMap)array[i];
                        FolderData folder = new FolderData(map["folder_id"].AsUUID());
                        folder.PreferredType = (AssetType)map["type_default"].AsInteger();
                        folder.Version = map["version"].AsInteger();
                        folder.OwnerID = owner;
                        folder.ParentUUID = map["parent_id"].AsUUID();
                        folder.Name = map["name"].AsString();

                        folders.Add(folder);
                    }
                }
            }

            return folders.ToArray();
        }
Exemple #19
0
        public static Vector3 ParseVector3(string key, LLSDMap reply)
        {
            LLSD llsd;
            if (reply.TryGetValue(key, out llsd))
            {
                if (llsd.Type == LLSDType.Array)
                {
                    return ((LLSDArray)llsd).AsVector3();
                }
                else if (llsd.Type == LLSDType.String)
                {
                    LLSDArray array = (LLSDArray)LLSDParser.DeserializeNotation(llsd.AsString());
                    return array.AsVector3();
                }
            }

            return Vector3.Zero;
        }