Contains the Avatar's Appearance and methods to manipulate the appearance.
Пример #1
0
 public bool SetAppearance (UUID userID, AvatarAppearance appearance)
 {
     bool success = m_localService.SetAppearance (userID, appearance);
     if (!success)
         success = m_remoteService.SetAppearance (userID, appearance);
     return success;
 }
Пример #2
0
        private AvatarAppearance CreateDefault(UUID avatarId)
        {
            AvatarAppearance appearance = null;
            AvatarWearable[] wearables;
            byte[] visualParams;
            GetDefaultAvatarAppearance(out wearables, out visualParams);
            appearance = new AvatarAppearance(avatarId, wearables, visualParams);

            return appearance;
        }
Пример #3
0
        public bool TryGetAvatarAppearance(UUID avatarId, out AvatarAppearance appearance)
        {
            AvatarData avatar = m_scene.AvatarService.GetAvatar(avatarId);
            //if ((profile != null) && (profile.RootFolder != null))
            if (avatar != null)
            {
                appearance = avatar.ToAvatarAppearance(avatarId);
                return true;
            }

            m_log.ErrorFormat("[APPEARANCE]: Appearance not found for {0}, creating default", avatarId);
            appearance = CreateDefault(avatarId);
            return false;
        }
Пример #4
0
        public bool TryGetAvatarAppearance(UUID avatarId, out AvatarAppearance appearance)
        {
            CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(avatarId);
            //if ((profile != null) && (profile.RootFolder != null))
            if (profile != null)
            {
                appearance = m_scene.CommsManager.AvatarService.GetUserAppearance(avatarId);
                if (appearance != null)
                {
                    //SetAppearanceAssets(profile, ref appearance);
                    //m_log.DebugFormat("[APPEARANCE]: Found : {0}", appearance.ToString());
                    return true;
                }
            }

            appearance = CreateDefault(avatarId);
            m_log.ErrorFormat("[APPEARANCE]: Appearance not found for {0}, creating default", avatarId);
            return false;
        }
Пример #5
0
        public bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene)
        {
            ScenePresence sp = scene.GetScenePresence(agentId);
            if (sp == null || sp.IsChildAgent)
                return false;

            lock (m_avatars)
                if (!m_avatars.ContainsKey(agentId))
                    return false;

            scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, false);

            AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
            sp.Appearance = npcAppearance;
            scene.AttachmentsModule.RezAttachments(sp);

            IAvatarFactoryModule module = scene.RequestModuleInterface<IAvatarFactoryModule>();
            module.SendAppearance(sp.UUID);

            return true;
        }
Пример #6
0
 public void GetAssetsFrom(AvatarAppearance app)
 {
     for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
     {
         for (int j = 0; j < m_wearables[i].Count; j++)
         {
             UUID itemID = m_wearables[i][j].ItemID;
             UUID assetID = app.Wearables[i].GetAsset(itemID);
             if (assetID != UUID.Zero)
                 m_wearables[i].Add(itemID, assetID);
         }
     }
 }
Пример #7
0
 public AvatarAppearance(AvatarAppearance appearance)
     : this(appearance, true)
 {
 }
Пример #8
0
        /// <summary>
        /// This method is called by establishAppearance to copy inventory folders to make
        /// copies of Clothing and Bodyparts inventory folders and attaches worn attachments
        /// </summary>

        private void CopyInventoryFolders(UUID destination, UUID source, AssetType assetType, Dictionary<UUID,UUID> inventoryMap,
                                          AvatarAppearance avatarAppearance)
        {
            IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService;

            InventoryFolderBase sourceFolder = inventoryService.GetFolderForType(source, assetType);
            InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, assetType);

            if (sourceFolder == null || destinationFolder == null)
                throw new Exception("Cannot locate folder(s)");

            // Missing source folder? This should *never* be the case
            if (sourceFolder.Type != (short)assetType)
            {
                sourceFolder = new InventoryFolderBase();
                sourceFolder.ID       = UUID.Random();
                if (assetType == AssetType.Clothing) {
                    sourceFolder.Name     = "Clothing";
                } else {
                    sourceFolder.Name     = "Body Parts";
                }
                sourceFolder.Owner    = source;
                sourceFolder.Type     = (short)assetType;
                sourceFolder.ParentID = inventoryService.GetRootFolder(source).ID;
                sourceFolder.Version  = 1;
                inventoryService.AddFolder(sourceFolder);     // store base record
                m_log.ErrorFormat("[RADMIN] Created folder for source {0}", source);
            }

            // Missing destination folder? This should *never* be the case
            if (destinationFolder.Type != (short)assetType)
            {
                destinationFolder = new InventoryFolderBase();
                destinationFolder.ID       = UUID.Random();
                if (assetType == AssetType.Clothing) {
                    destinationFolder.Name  = "Clothing";
                } else {
                    destinationFolder.Name  = "Body Parts";
                }
                destinationFolder.Owner    = destination;
                destinationFolder.Type     = (short)assetType;
                destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID;
                destinationFolder.Version  = 1;
                inventoryService.AddFolder(destinationFolder);     // store base record
                m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source);
            }

            InventoryFolderBase extraFolder;
            List<InventoryFolderBase> folders = inventoryService.GetFolderContent(source, sourceFolder.ID).Folders;

            foreach (InventoryFolderBase folder in folders)
            {

                extraFolder = new InventoryFolderBase();
                extraFolder.ID = UUID.Random();
                extraFolder.Name = folder.Name;
                extraFolder.Owner = destination;
                extraFolder.Type = folder.Type;
                extraFolder.Version = folder.Version;
                extraFolder.ParentID = destinationFolder.ID;
                inventoryService.AddFolder(extraFolder);

                m_log.DebugFormat("[RADMIN]: Added folder {0} to folder {1}", extraFolder.ID, sourceFolder.ID);

                List<InventoryItemBase> items = inventoryService.GetFolderContent(source, folder.ID).Items;

                foreach (InventoryItemBase item in items)
                {
                    InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
                    destinationItem.Name = item.Name;
                    destinationItem.Owner = destination;
                    destinationItem.Description = item.Description;
                    destinationItem.InvType = item.InvType;
                    destinationItem.CreatorId = item.CreatorId;
                    destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid;
                    destinationItem.CreatorData = item.CreatorData;
                    destinationItem.NextPermissions = item.NextPermissions;
                    destinationItem.CurrentPermissions = item.CurrentPermissions;
                    destinationItem.BasePermissions = item.BasePermissions;
                    destinationItem.EveryOnePermissions = item.EveryOnePermissions;
                    destinationItem.GroupPermissions = item.GroupPermissions;
                    destinationItem.AssetType = item.AssetType;
                    destinationItem.AssetID = item.AssetID;
                    destinationItem.GroupID = item.GroupID;
                    destinationItem.GroupOwned = item.GroupOwned;
                    destinationItem.SalePrice = item.SalePrice;
                    destinationItem.SaleType = item.SaleType;
                    destinationItem.Flags = item.Flags;
                    destinationItem.CreationDate = item.CreationDate;
                    destinationItem.Folder = extraFolder.ID;
                    ApplyNextOwnerPermissions(destinationItem);

                    m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
                    inventoryMap.Add(item.ID, destinationItem.ID);
                    m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, extraFolder.ID);

                    // Attach item, if original is attached
                    int attachpoint = avatarAppearance.GetAttachpoint(item.ID);
                    if (attachpoint != 0)
                    {
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                }
            }
        }
Пример #9
0
        private AgentCircuitData MakeAgent(GridRegion region, UserAccount account, 
            AvatarAppearance avatar, UUID session, UUID secureSession, uint circuit, Vector3 position, 
            string ipaddress, string viewer, string channel, string mac, string id0)
        {
            AgentCircuitData aCircuit = new AgentCircuitData();

            aCircuit.AgentID = account.PrincipalID;
            if (avatar != null)
                aCircuit.Appearance = new AvatarAppearance(avatar);
            else
                aCircuit.Appearance = new AvatarAppearance();

            //aCircuit.BaseFolder = irrelevant
            aCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
            aCircuit.child = false; // the first login agent is root
            aCircuit.ChildrenCapSeeds = new Dictionary<ulong, string>();
            aCircuit.circuitcode = circuit;
            aCircuit.firstname = account.FirstName;
            //aCircuit.InventoryFolder = irrelevant
            aCircuit.lastname = account.LastName;
            aCircuit.SecureSessionID = secureSession;
            aCircuit.SessionID = session;
            aCircuit.startpos = position;
            aCircuit.IPAddress = ipaddress;
            aCircuit.Viewer = viewer;
            aCircuit.Channel = channel;
            aCircuit.Mac = mac;
            aCircuit.Id0 = id0;
            SetServiceURLs(aCircuit, account);

            return aCircuit;
        }
Пример #10
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            // DEBUG ON
            //m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data");
            // DEBUG OFF

            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args["region_id"].AsString(), out RegionID);
            }

            if (args["circuit_code"] != null)
            {
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args["agent_uuid"] != null)
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args["session_uuid"] != null)
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args["position"] != null)
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args["velocity"] != null)
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args["center"] != null)
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args["size"] != null)
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args["at_axis"] != null)
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args["left_axis"] != null)
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args["up_axis"] != null)
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args["far"] != null)
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args["aspect"] != null)
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args["throttles"] != null)
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args["locomotion_state"] != null)
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args["head_rotation"] != null)
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args["body_rotation"] != null)
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args["control_flags"] != null)
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args["energy_level"] != null)
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            //This IS checked later
            if (args["god_level"] != null)
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args["speed"] != null)
            {
                float.TryParse(args["speed"].AsString(), out Speed);
            }
            else
            {
                Speed = 1;
            }

            if (args["draw_distance"] != null)
            {
                float.TryParse(args["draw_distance"].AsString(), out DrawDistance);
            }
            else
            {
                DrawDistance = 0;
            }

            //Reset this to fix movement... since regions are being bad about this
            if (Speed == 0)
            {
                Speed = 1;
            }

            if (args["always_run"] != null)
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            if (args["sent_initial_wearables"] != null)
            {
                SentInitialWearables = args["sent_initial_wearables"].AsBoolean();
            }
            else
            {
                SentInitialWearables = false;
            }

            if (args["prey_agent"] != null)
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args["callback_uri"] != null)
            {
                CallbackURI = args["callback_uri"].AsString();
            }

            if (args["agent_access"] != null)
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args["active_group_id"] != null)
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            Appearance = new AvatarAppearance(AgentID);

            try
            {
                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                {
                    Appearance = new AvatarAppearance(AgentID, (OSDMap)args["packed_appearance"]);
                }
                // DEBUG ON
                else
                {
                    m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
                }
                // DEBUG OFF
            }
            catch
            {
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Update a user appearence
        /// </summary>
        /// <param name="user">the user UUID</param>
        /// <param name="appearance">appearence</param>
        override public void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
        {
            appearance.Owner = user;
            DataTable aap = ds.Tables["avatarappearance"];
            lock (ds)
            {
                DataRow row = aap.Rows.Find(Util.ToRawUuidString(user));
                if (row == null)
                {
                    m_log.Debug("[USER DB]: Creating UserAppearance For: " + user.ToString());

                    row = aap.NewRow();
                    fillAvatarAppearanceRow(row, user, appearance);
                    aap.Rows.Add(row);
                    //    m_log.Debug("[USER DB]: Syncing user database: " + ds.Tables["users"].Rows.Count + " users stored");
                    // save changes off to disk
                    daa.Update(ds, "avatarappearance");
                }
                else
                {
                    m_log.Debug("[USER DB]: Updating UserAppearance For: " + user.ToString());
                    fillAvatarAppearanceRow(row, user, appearance);
                    daa.Update(ds, "avatarappearance");
                }
            }
        }
Пример #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <param name="user"></param>
        private void fillAvatarAppearanceRow(DataRow row, UUID user, AvatarAppearance appearance)
        {
            row["Owner"] = Util.ToRawUuidString(user);
            row["BodyItem"] = appearance.BodyItem.ToString();
            row["BodyAsset"] = appearance.BodyAsset.ToString();
            row["SkinItem"] = appearance.SkinItem.ToString();
            row["SkinAsset"] = appearance.SkinAsset.ToString();
            row["HairItem"] = appearance.HairItem.ToString();
            row["HairAsset"] = appearance.HairAsset.ToString();
            row["EyesItem"] = appearance.EyesItem.ToString();
            row["EyesAsset"] = appearance.EyesAsset.ToString();
            row["ShirtItem"] = appearance.ShirtItem.ToString();
            row["ShirtAsset"] = appearance.ShirtAsset.ToString();
            row["PantsItem"] = appearance.PantsItem.ToString();
            row["PantsAsset"] = appearance.PantsAsset.ToString();
            row["ShoesItem"] = appearance.ShoesItem.ToString();
            row["ShoesAsset"] = appearance.ShoesAsset.ToString();
            row["SocksItem"] = appearance.SocksItem.ToString();
            row["SocksAsset"] = appearance.SocksAsset.ToString();
            row["JacketItem"] = appearance.JacketItem.ToString();
            row["JacketAsset"] = appearance.JacketAsset.ToString();
            row["GlovesItem"] = appearance.GlovesItem.ToString();
            row["GlovesAsset"] = appearance.GlovesAsset.ToString();
            row["UnderShirtItem"] = appearance.UnderShirtItem.ToString();
            row["UnderShirtAsset"] = appearance.UnderShirtAsset.ToString();
            row["UnderPantsItem"] = appearance.UnderPantsItem.ToString();
            row["UnderPantsAsset"] = appearance.UnderPantsAsset.ToString();
            row["SkirtItem"] = appearance.SkirtItem.ToString();
            row["SkirtAsset"] = appearance.SkirtAsset.ToString();

            //  Used Base64String because for some reason it wont accept using Byte[] (which works in Region date)
            row["Texture"] = Convert.ToBase64String(appearance.Texture.GetBytes());
            row["VisualParams"] = Convert.ToBase64String(appearance.VisualParams);

            row["Serial"] = appearance.Serial;
            row["AvatarHeight"] = appearance.AvatarHeight;

            // ADO.NET doesn't handle NULL very well
            foreach (DataColumn col in ds.Tables["avatarappearance"].Columns)
            {
                if (row[col] == null)
                {
                    row[col] = String.Empty;
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Unpack agent circuit data map into an AgentCiruitData object
        /// </summary>
        /// <param name="args"></param>
        public void UnpackAgentCircuitData(OSDMap args)
        {
            if (args["agent_id"] != null)
            {
                AgentID = args["agent_id"].AsUUID();
            }
            if (args["base_folder"] != null)
            {
                BaseFolder = args["base_folder"].AsUUID();
            }
            if (args["caps_path"] != null)
            {
                CapsPath = args["caps_path"].AsString();
            }

            if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
            {
                OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
                ChildrenCapSeeds = new Dictionary <ulong, string>();
                foreach (OSD o in childrenSeeds)
                {
                    if (o.Type == OSDType.Map)
                    {
                        ulong  handle = 0;
                        string seed   = "";
                        OSDMap pair   = (OSDMap)o;
                        if (pair["handle"] != null)
                        {
                            if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
                            {
                                continue;
                            }
                        }
                        if (pair["seed"] != null)
                        {
                            seed = pair["seed"].AsString();
                        }
                        if (!ChildrenCapSeeds.ContainsKey(handle))
                        {
                            ChildrenCapSeeds.Add(handle, seed);
                        }
                    }
                }
            }
            else
            {
                ChildrenCapSeeds = new Dictionary <ulong, string>();
            }

            if (args["child"] != null)
            {
                child = args["child"].AsBoolean();
            }
            if (args["circuit_code"] != null)
            {
                UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
            }
            if (args["first_name"] != null)
            {
                firstname = args["first_name"].AsString();
            }
            if (args["last_name"] != null)
            {
                lastname = args["last_name"].AsString();
            }
            if (args["inventory_folder"] != null)
            {
                InventoryFolder = args["inventory_folder"].AsUUID();
            }
            if (args["secure_session_id"] != null)
            {
                SecureSessionID = args["secure_session_id"].AsUUID();
            }
            if (args["session_id"] != null)
            {
                SessionID = args["session_id"].AsUUID();
            }
            if (args["service_session_id"] != null)
            {
                ServiceSessionID = args["service_session_id"].AsString();
            }
            if (args["client_ip"] != null)
            {
                IPAddress = args["client_ip"].AsString();
            }
            if (args["viewer"] != null)
            {
                Viewer = args["viewer"].AsString();
            }
            if (args["channel"] != null)
            {
                Channel = args["channel"].AsString();
            }
            if (args["mac"] != null)
            {
                Mac = args["mac"].AsString();
            }
            if (args["id0"] != null)
            {
                Id0 = args["id0"].AsString();
            }
            if (args["teleport_flags"] != null)
            {
                teleportFlags = args["teleport_flags"].AsUInteger();
            }

            if (args["start_pos"] != null)
            {
                Vector3.TryParse(args["start_pos"].AsString(), out startpos);
            }

            //m_log.InfoFormat("[AGENTCIRCUITDATA]: agentid={0}, child={1}, startpos={2}", AgentID, child, startpos);

            try
            {
                // Unpack various appearance elements
                Appearance = new AvatarAppearance();

                // Eventually this code should be deprecated, use full appearance
                // packing in packed_appearance
                if (args["appearance_serial"] != null)
                {
                    Appearance.Serial = args["appearance_serial"].AsInteger();
                }

                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
                {
                    Appearance.Unpack((OSDMap)args["packed_appearance"]);
//                    m_log.InfoFormat("[AGENTCIRCUITDATA] unpacked appearance");
                }
                else
                {
                    m_log.Warn("[AGENTCIRCUITDATA]: failed to find a valid packed_appearance");
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}", e.Message);
            }

            ServiceURLs = new Dictionary <string, object>();
            // Try parse the new way, OSDMap
            if (args.ContainsKey("serviceurls") && args["serviceurls"] != null && (args["serviceurls"]).Type == OSDType.Map)
            {
                OSDMap urls = (OSDMap)(args["serviceurls"]);
                foreach (KeyValuePair <String, OSD> kvp in urls)
                {
                    ServiceURLs[kvp.Key] = kvp.Value.AsString();
                    //System.Console.WriteLine("XXX " + kvp.Key + "=" + ServiceURLs[kvp.Key]);
                }
            }
            // else try the old way, OSDArray
            // OBSOLETE -- soon to be deleted
            else if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
            {
                OSDArray urls = (OSDArray)(args["service_urls"]);
                for (int i = 0; i < urls.Count / 2; i++)
                {
                    ServiceURLs[urls[i * 2].AsString()] = urls[(i * 2) + 1].AsString();
                    //System.Console.WriteLine("XXX " + urls[i * 2].AsString() + "=" + urls[(i * 2) + 1].AsString());
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            if (args.ContainsKey("region_handle"))
            {
                UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);
            }

            if (args.ContainsKey("circuit_code"))
            {
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args.ContainsKey("agent_uuid"))
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args.ContainsKey("session_uuid"))
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args.ContainsKey("position"))
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args.ContainsKey("velocity"))
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args.ContainsKey("center"))
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args.ContainsKey("size"))
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args.ContainsKey("at_axis"))
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args.ContainsKey("left_axis"))
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args.ContainsKey("up_axis"))
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args.ContainsKey("changed_grid"))
            {
                ChangedGrid = args["changed_grid"].AsBoolean();
            }

            if (args.ContainsKey("far"))
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args.ContainsKey("aspect"))
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args.ContainsKey("throttles"))
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args.ContainsKey("locomotion_state"))
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args.ContainsKey("head_rotation"))
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args.ContainsKey("body_rotation"))
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args.ContainsKey("control_flags"))
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args.ContainsKey("energy_level"))
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            if (args.ContainsKey("god_level"))
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args.ContainsKey("always_run"))
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            if (args.ContainsKey("prey_agent"))
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args.ContainsKey("agent_access"))
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args.ContainsKey("active_group_id"))
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if ((args.ContainsKey("groups")) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args.ContainsKey("animations")) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            // Initialize an Appearance
            Appearance = new AvatarAppearance(AgentID);

            if (args.ContainsKey("texture_entry"))
            {
                byte[] data = args["texture_entry"].AsBinary();
                Primitive.TextureEntry textureEntries = new Primitive.TextureEntry(data, 0, data.Length);
                Appearance.SetTextureEntries(textureEntries);
            }

            if (args.ContainsKey("visual_params"))
            {
                byte[] visualParams = args["visual_params"].AsBinary();
                Appearance.SetVisualParams(visualParams);
            }

            if ((args.ContainsKey("wearables")) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                List <AvatarWearable> wearables = new List <AvatarWearable>();

                int offset = 0;
                for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
                {
                    if ((offset + 1) < wears.Count)
                    {
                        UUID itemID  = wears[offset++].AsUUID();
                        UUID assetID = wears[offset++].AsUUID();
                        wearables.Add(new AvatarWearable(i, itemID, assetID));
                    }
                    else
                    {
                        break;
                    }
                }

                Appearance.SetWearables(wearables);
            }

            if (args.ContainsKey("callback_uri"))
            {
                CallbackURI = args["callback_uri"].AsString();
            }

            if (args.ContainsKey("avatar_as_a_prim"))
            {
                AvatarAsAPrim = args["avatar_as_a_prim"].AsBoolean();
            }

            if (args.ContainsKey("sat_on_group"))
            {
                SatOnGroup = args["sat_on_group"].AsUUID();
                SatOnPrim  = args["sat_on_prim"].AsUUID();
                try
                {
                    // "sit_offset" previously used OSD.FromVector3(vec) was used to store the data.
                    // Other Vector3 storage uses OSD.FromString(vec.ToString()).
                    // If originating from old region code, that will still be the case
                    // and the TryParse will trigger a format exception.
                    Vector3.TryParse(args["sit_offset"].ToString(), out SatOnPrimOffset);
                }
                catch (Exception)
                {
                    // The following is compatible with OSD.FromVector3(vec), since Vector3.TryParse is not.
                    SatOnPrimOffset = args["sit_offset"].AsVector3();
                }
            }

            // Initialize AgentPrefs from viewer
            AgentPrefs = new AgentPreferencesData();
            if (args.ContainsKey("hover_height"))
            {
                AgentPrefs.HoverHeight = args["hover_height"];
            }
            if (args.ContainsKey("access_prefs"))
            {
                AgentPrefs.AccessPrefs = args["access_prefs"];
            }
            if (args.ContainsKey("perm_everyone"))
            {
                AgentPrefs.PermEveryone = args["perm_everyone"];
            }
            if (args.ContainsKey("perm_group"))
            {
                AgentPrefs.PermGroup = args["perm_group"];
            }
            if (args.ContainsKey("perm_next_owner"))
            {
                AgentPrefs.PermNextOwner = args["perm_next_owner"];
            }
            if (args.ContainsKey("language"))
            {
                AgentPrefs.Language = args["language"];
            }
            if (args.ContainsKey("language_is_public"))
            {
                AgentPrefs.LanguageIsPublic = args["language_is_public"];
            }
            if (args.ContainsKey("principal_id"))
            {
                AgentPrefs.PrincipalID = args["principal_id"];
            }
        }
Пример #15
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args, IScene scene)
        {
            if (m_log.IsDebugEnabled)
            {
                m_log.DebugFormat("{0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
            }

            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args ["region_id"].AsString(), out RegionID);
            }

            if (args ["circuit_code"] != null)
            {
                UInt32.TryParse((string)args ["circuit_code"].AsString(), out CircuitCode);
            }

            if (args ["agent_uuid"] != null)
            {
                AgentID = args ["agent_uuid"].AsUUID();
            }

            if (args ["session_uuid"] != null)
            {
                SessionID = args ["session_uuid"].AsUUID();
            }

            if (args ["position"] != null)
            {
                Vector3.TryParse(args ["position"].AsString(), out Position);
            }

            if (args ["velocity"] != null)
            {
                Vector3.TryParse(args ["velocity"].AsString(), out Velocity);
            }

            if (args ["center"] != null)
            {
                Vector3.TryParse(args ["center"].AsString(), out Center);
            }

            if (args ["size"] != null)
            {
                Vector3.TryParse(args ["size"].AsString(), out Size);
            }

            if (args ["at_axis"] != null)
            {
                Vector3.TryParse(args ["at_axis"].AsString(), out AtAxis);
            }

            if (args ["left_axis"] != null)
            {
                Vector3.TryParse(args ["left_axis"].AsString(), out AtAxis);
            }

            if (args ["up_axis"] != null)
            {
                Vector3.TryParse(args ["up_axis"].AsString(), out AtAxis);
            }

            if (args.ContainsKey("wait_for_root") && args ["wait_for_root"] != null)
            {
                SenderWantsToWaitForRoot = args ["wait_for_root"].AsBoolean();
            }

            if (args ["far"] != null)
            {
                Far = (float)(args ["far"].AsReal());
            }

            if (args ["aspect"] != null)
            {
                Aspect = (float)args ["aspect"].AsReal();
            }

            if (args ["throttles"] != null)
            {
                Throttles = args ["throttles"].AsBinary();
            }

            if (args ["locomotion_state"] != null)
            {
                UInt32.TryParse(args ["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args ["head_rotation"] != null)
            {
                Quaternion.TryParse(args ["head_rotation"].AsString(), out HeadRotation);
            }

            if (args ["body_rotation"] != null)
            {
                Quaternion.TryParse(args ["body_rotation"].AsString(), out BodyRotation);
            }

            if (args ["control_flags"] != null)
            {
                UInt32.TryParse(args ["control_flags"].AsString(), out ControlFlags);
            }

            if (args ["energy_level"] != null)
            {
                EnergyLevel = (float)(args ["energy_level"].AsReal());
            }

            if (args ["god_level"] != null)
            {
                Byte.TryParse(args ["god_level"].AsString(), out GodLevel);
            }

            if (args ["always_run"] != null)
            {
                AlwaysRun = args ["always_run"].AsBoolean();
            }

            if (args ["prey_agent"] != null)
            {
                PreyAgent = args ["prey_agent"].AsUUID();
            }

            if (args ["agent_access"] != null)
            {
                Byte.TryParse(args ["agent_access"].AsString(), out AgentAccess);
            }

            if (args ["active_group_id"] != null)
            {
                ActiveGroupID = args ["active_group_id"].AsUUID();
            }

            if ((args ["groups"] != null) && (args ["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args ["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups [i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args ["animations"] != null) && (args ["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args ["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims [i++] = new Animation((OSDMap)o);
                    }
                }
            }

            if (args ["default_animation"] != null)
            {
                try {
                    DefaultAnim = new Animation((OSDMap)args ["default_animation"]);
                } catch {
                    DefaultAnim = null;
                }
            }

            if (args ["animation_state"] != null)
            {
                try {
                    AnimState = new Animation((OSDMap)args ["animation_state"]);
                } catch {
                    AnimState = null;
                }
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}

            Appearance = new AvatarAppearance();

            // The code to unpack textures, visuals, wearables and attachments
            // should be removed; packed appearance contains the full appearance
            // This is retained for backward compatibility only
            if (args ["texture_entry"] != null)
            {
                byte[] rawtextures = args ["texture_entry"].AsBinary();
                Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
                Appearance.SetTextureEntries(textures);
            }

            if (args ["visual_params"] != null)
            {
                Appearance.SetVisualParams(args ["visual_params"].AsBinary());
            }

            if ((args ["wearables"] != null) && (args ["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args ["wearables"]);
                for (int i = 0; i < wears.Count / 2; i++)
                {
                    AvatarWearable awear = new AvatarWearable((OSDArray)wears [i]);
                    Appearance.SetWearable(i, awear);
                }
            }

            if ((args ["attachments"] != null) && (args ["attachments"]).Type == OSDType.Array)
            {
                OSDArray attachs = (OSDArray)(args ["attachments"]);
                foreach (OSD o in attachs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        // We know all of these must end up as attachments so we
                        // append rather than replace to ensure multiple attachments
                        // per point continues to work
//                        m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
                        Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                    }
                }
            }
            // end of code to remove

            if (args.ContainsKey("packed_appearance") && (args ["packed_appearance"]).Type == OSDType.Map)
            {
                Appearance = new AvatarAppearance((OSDMap)args ["packed_appearance"]);
            }
            else
            {
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
            {
                CallbackURI = args["callback_uri"].AsString();
            }

            // Attachment objects
            if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array)
            {
                OSDArray attObjs = (OSDArray)(args["attach_objects"]);
                AttachmentObjects      = new List <ISceneObject>();
                AttachmentObjectStates = new List <string>();
                foreach (OSD o in attObjs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        OSDMap       info = (OSDMap)o;
                        ISceneObject so   = scene.DeserializeObject(info["sog"].AsString());
                        so.ExtraFromXmlString(info["extra"].AsString());
                        so.HasGroupChanged = info["modified"].AsBoolean();
                        AttachmentObjects.Add(so);
                        AttachmentObjectStates.Add(info["state"].AsString());
                    }
                }
            }
        }
Пример #16
0
 public AvatarAppearance(AvatarAppearance appearance) : this(appearance, true)
 {
 }
Пример #17
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");

            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args["region_id"].AsString(), out RegionID);
            }

            if (args["circuit_code"] != null)
            {
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args["agent_uuid"] != null)
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args["session_uuid"] != null)
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args["position"] != null)
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args["velocity"] != null)
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args["center"] != null)
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args["size"] != null)
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args["at_axis"] != null)
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args["left_axis"] != null)
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args["up_axis"] != null)
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args["changed_grid"] != null)
            {
                ChangedGrid = args["changed_grid"].AsBoolean();
            }

            if (args["far"] != null)
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args["aspect"] != null)
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args["throttles"] != null)
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args["locomotion_state"] != null)
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args["head_rotation"] != null)
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args["body_rotation"] != null)
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args["control_flags"] != null)
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args["energy_level"] != null)
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            if (args["god_level"] != null)
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args["always_run"] != null)
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            if (args["prey_agent"] != null)
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args["agent_access"] != null)
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args["active_group_id"] != null)
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}

            Appearance = new AvatarAppearance(AgentID);

            // The code to unpack textures, visuals, wearables and attachments
            // should be removed; packed appearance contains the full appearance
            // This is retained for backward compatibility only
            if (args["texture_entry"] != null)
            {
                byte[] rawtextures = args["texture_entry"].AsBinary();
                Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
                Appearance.SetTextureEntries(textures);
            }

            if (args["visual_params"] != null)
            {
                Appearance.SetVisualParams(args["visual_params"].AsBinary());
            }

            if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                for (int i = 0; i < wears.Count / 2; i++)
                {
                    AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
                    Appearance.SetWearable(i, awear);
                }
            }

            if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
            {
                OSDArray attachs = (OSDArray)(args["attachments"]);
                foreach (OSD o in attachs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        // We know all of these must end up as attachments so we
                        // append rather than replace to ensure multiple attachments
                        // per point continues to work
                        Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                    }
                }
            }
            // end of code to remove

            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
            {
                Appearance = new AvatarAppearance(AgentID, (OSDMap)args["packed_appearance"]);
            }
            else
            {
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
            {
                CallbackURI = args["callback_uri"].AsString();
            }
        }
Пример #18
0
        /// <summary>
        /// Unpack agent circuit data map into an AgentCiruitData object
        /// </summary>
        /// <param name="args"></param>
        public void UnpackAgentCircuitData(OSDMap args)
        {
            if (args["agent_id"] != null)
            {
                AgentID = args["agent_id"].AsUUID();
            }
            if (args["base_folder"] != null)
            {
                BaseFolder = args["base_folder"].AsUUID();
            }
            if (args["caps_path"] != null)
            {
                CapsPath = args["caps_path"].AsString();
            }

            if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
            {
                OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
                ChildrenCapSeeds = new Dictionary <ulong, string>();
                foreach (OSD o in childrenSeeds)
                {
                    if (o.Type == OSDType.Map)
                    {
                        ulong  handle = 0;
                        string seed   = "";
                        OSDMap pair   = (OSDMap)o;
                        if (pair["handle"] != null)
                        {
                            if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
                            {
                                continue;
                            }
                        }
                        if (pair["seed"] != null)
                        {
                            seed = pair["seed"].AsString();
                        }
                        if (!ChildrenCapSeeds.ContainsKey(handle))
                        {
                            ChildrenCapSeeds.Add(handle, seed);
                        }
                    }
                }
            }
            else
            {
                ChildrenCapSeeds = new Dictionary <ulong, string>();
            }

            if (args["child"] != null)
            {
                child = args["child"].AsBoolean();
            }
            if (args["circuit_code"] != null)
            {
                UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
            }
            if (args["first_name"] != null)
            {
                firstname = args["first_name"].AsString();
            }
            if (args["last_name"] != null)
            {
                lastname = args["last_name"].AsString();
            }
            if (args["inventory_folder"] != null)
            {
                InventoryFolder = args["inventory_folder"].AsUUID();
            }
            if (args["secure_session_id"] != null)
            {
                SecureSessionID = args["secure_session_id"].AsUUID();
            }
            if (args["session_id"] != null)
            {
                SessionID = args["session_id"].AsUUID();
            }
            if (args["service_session_id"] != null)
            {
                ServiceSessionID = args["service_session_id"].AsString();
            }
            if (args["viewer"] != null)
            {
                Viewer = args["viewer"].AsString();
            }

            if (args["start_pos"] != null)
            {
                Vector3.TryParse(args["start_pos"].AsString(), out startpos);
            }

            Appearance = new AvatarAppearance(AgentID);
            if (args["appearance_serial"] != null)
            {
                Appearance.Serial = args["appearance_serial"].AsInteger();
            }
            if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                for (int i = 0; i < wears.Count / 2; i++)
                {
                    Appearance.Wearables[i].ItemID  = wears[i * 2].AsUUID();
                    Appearance.Wearables[i].AssetID = wears[(i * 2) + 1].AsUUID();
                }
            }

            if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
            {
                OSDArray         attachs     = (OSDArray)(args["attachments"]);
                AttachmentData[] attachments = new AttachmentData[attachs.Count];
                int i = 0;
                foreach (OSD o in attachs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        attachments[i++] = new AttachmentData((OSDMap)o);
                    }
                }
                Appearance.SetAttachments(attachments);
            }

            ServiceURLs = new Dictionary <string, object>();
            if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
            {
                OSDArray urls = (OSDArray)(args["service_urls"]);
                for (int i = 0; i < urls.Count / 2; i++)
                {
                    ServiceURLs[urls[i * 2].AsString()] = urls[(i * 2) + 1].AsString();
                    //System.Console.WriteLine("XXX " + urls[i * 2].AsString() + "=" + urls[(i * 2) + 1].AsString());
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Prepare a login to the given region.  This involves both telling the region to expect a connection
        /// and appropriately customising the response to the user.
        /// </summary>
        /// <param name="regionInfo"></param>
        /// <param name="user"></param>
        /// <param name="response"></param>
        /// <returns>true if the region was successfully contacted, false otherwise</returns>
        private bool PrepareLoginToRegion(RegionProfileData regionInfo, UserProfileData user, LoginResponse response, string clientVersion)
        {
            string regionName = regionInfo.regionName;
            bool success = false;

            try
            {
                lock (_LastRegionFailure)
                {
                    if (_LastRegionFailure.ContainsKey(regionName))
                    {
                        // region failed previously
                        RegionLoginFailure failure = _LastRegionFailure[regionName];
                        if (failure.IsExpired())
                        {
                            // failure has expired, retry this region again
                            _LastRegionFailure.Remove(regionName);
//                            m_log.WarnFormat("[LOGIN]: Region '{0}' was previously down, retrying.", regionName);
                        }
                        else
                        {
                            if (failure.IsFailed())
                            {
//                                m_log.WarnFormat("[LOGIN]: Region '{0}' was recently down, skipping.", regionName);
                                return false;   // within 5 minutes, don't repeat attempt
                            }
//                            m_log.WarnFormat("[LOGIN]: Region '{0}' was recently down but under threshold, retrying.", regionName);
                        }
                    }
                }

                response.SimAddress = regionInfo.OutsideIpOrResolvedHostname;
                response.SimPort = regionInfo.serverPort;
                response.RegionX = regionInfo.regionLocX;
                response.RegionY = regionInfo.regionLocY;

                string capsPath = CapsUtil.GetRandomCapsObjectPath();

                response.SeedCapability = CapsUtil.GetFullCapsSeedURL(regionInfo.httpServerURI, capsPath);

                // Notify the target of an incoming user
                m_log.InfoFormat(
                    "[LOGIN]: Telling {0} @ {1},{2} ({3}) to prepare for client connection",
                    regionInfo.regionName, response.RegionX, response.RegionY, response.SeedCapability);

                // Update agent with target sim
                user.CurrentAgent.Region = regionInfo.UUID;
                user.CurrentAgent.Handle = regionInfo.regionHandle;

                // Prepare notification
                Hashtable loginParams = new Hashtable();
                loginParams["session_id"] = user.CurrentAgent.SessionID.ToString();
                loginParams["secure_session_id"] = user.CurrentAgent.SecureSessionID.ToString();
                loginParams["firstname"] = user.FirstName;
                loginParams["lastname"] = user.SurName;
                loginParams["agent_id"] = user.ID.ToString();
                loginParams["circuit_code"] = (Int32)Convert.ToUInt32(response.CircuitCode);
                loginParams["startpos_x"] = user.CurrentAgent.Position.X.ToString();
                loginParams["startpos_y"] = user.CurrentAgent.Position.Y.ToString();
                loginParams["startpos_z"] = user.CurrentAgent.Position.Z.ToString();
                loginParams["regionhandle"] = user.CurrentAgent.Handle.ToString();
                loginParams["caps_path"] = capsPath;
                loginParams["client_version"] = clientVersion;

                // Get appearance
                AvatarAppearance appearance = m_userManager.GetUserAppearance(user.ID);
                if (appearance != null)
                {
                    loginParams["appearance"] = appearance.ToHashTable();
                    m_log.DebugFormat("[LOGIN]: Found appearance version {0} for {1} {2}", appearance.Serial, user.FirstName, user.SurName);
                }
                else
                {
                    m_log.DebugFormat("[LOGIN]: Appearance not for {0} {1}. Creating default.", user.FirstName, user.SurName);
                    appearance = new AvatarAppearance(user.ID);
                }

                // Tell the client the COF version so it can use cached appearance if it matches.
                response.CofVersion = appearance.Serial.ToString();
                loginParams["cof_version"] = response.CofVersion;

                ArrayList SendParams = new ArrayList();
                SendParams.Add(loginParams);
                SendParams.Add(m_config.GridSendKey);

                // Send
                const string METHOD_NAME = "expect_user";
                XmlRpcRequest GridReq = new XmlRpcRequest(METHOD_NAME, SendParams);
                XmlRpcResponse GridResp = GridReq.Send(Util.XmlRpcRequestURI(regionInfo.httpServerURI, METHOD_NAME), 6000);

                if (!GridResp.IsFault)
                {
                    bool responseSuccess = true;

                    if (GridResp.Value != null)
                    {
                        Hashtable resp = (Hashtable)GridResp.Value;
                        if (resp.ContainsKey("success"))
                        {
                            if ((string)resp["success"] == "FALSE")
                            {
                                responseSuccess = false;
                            }
                        }
                        if (!responseSuccess)
                        {
                            if (resp.ContainsKey("reason"))
                            {
                                response.ErrorMessage = resp["reason"].ToString();
                            }
                        }
                    }
                    
                    if (responseSuccess)
                    {
                        handlerUserLoggedInAtLocation = OnUserLoggedInAtLocation;
                        if (handlerUserLoggedInAtLocation != null)
                        {
                            handlerUserLoggedInAtLocation(user.ID, user.CurrentAgent.SessionID,
                                                          user.CurrentAgent.Region,
                                                          user.CurrentAgent.Handle,
                                                          user.CurrentAgent.Position.X,
                                                          user.CurrentAgent.Position.Y,
                                                          user.CurrentAgent.Position.Z,
                                                          user.FirstName, user.SurName);
                        }
                        success = true;
                    }
                    else
                    {
                        m_log.ErrorFormat("[LOGIN]: Region responded that it is not available to receive clients");
                    }
                }
                else
                {
                    m_log.ErrorFormat("[LOGIN]: XmlRpc request to region failed with message {0}, code {1} ", GridResp.FaultString, GridResp.FaultCode);
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[LOGIN]: Region not available for login, {0}", e);
            }

            lock (_LastRegionFailure)
            {
                if (_LastRegionFailure.ContainsKey(regionName))
                {
                    RegionLoginFailure failure = _LastRegionFailure[regionName];
                    if (success)
                    {   // Success, so if we've been storing this as a failed region, remove that from the failed list.
                        m_log.WarnFormat("[LOGIN]: Region '{0}' recently down, is available again.", regionName);
                        _LastRegionFailure.Remove(regionName);
                    }
                    else
                    {
                        // Region not available, update cache with incremented count.
                        failure.AddFailure();
//                        m_log.WarnFormat("[LOGIN]: Region '{0}' is still down ({1}).", regionName, failure.Count);
                    }
                }
                else
                {
                    if (!success)
                    {
                        // Region not available, cache that temporarily.
                        m_log.WarnFormat("[LOGIN]: Region '{0}' is down, marking.", regionName);
                        _LastRegionFailure[regionName] = new RegionLoginFailure();
                    }
                }
            }
            return success;
        }
Пример #20
0
        /// <summary>
        /// Get the avatar apperance for the given client.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="appearance"></param>
        public void GetAvatarAppearance(IClientAPI client, out AvatarAppearance appearance)
        {
            AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode);

            if (aCircuit == null)
            {
                m_log.DebugFormat("[APPEARANCE] Client did not supply a circuit. Non-Linden? Creating default appearance.");
                appearance = new AvatarAppearance();
                return;
            }

            appearance = aCircuit.Appearance;
            if (appearance == null)
            {
                m_log.DebugFormat("[APPEARANCE]: Appearance not found in {0}, returning default", RegionInfo.RegionName);
                appearance = new AvatarAppearance();
            }
        }
Пример #21
0
        public void osNpcLoadAppearance(LSL_Key npc, string notecard)
        {
            CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
            m_host.AddScriptLPS(1);

            INPCModule npcModule = World.RequestModuleInterface<INPCModule>();

            if (npcModule != null)
            {
                UUID npcId;
                if (!UUID.TryParse(npc.m_string, out npcId))
                    return;

                if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
                    return;

                string appearanceSerialized = LoadNotecard(notecard);

                if (appearanceSerialized == null)
                    OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));

                OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
//                OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
//                Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
//                Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
                AvatarAppearance appearance = new AvatarAppearance();
                appearance.Unpack(appearanceOsd);

                npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene);
            }
        }
Пример #22
0
        /// <summary>
        /// Appearance.
        /// TODO: stubs for now to do in memory appearance.
        /// </summary>
        /// <param name="user">The user UUID</param>
        /// <returns>Avatar Appearence</returns>
        override public AvatarAppearance GetUserAppearance(UUID user)
        {
            m_log.Info("[APPEARANCE] GetUserAppearance " + user.ToString());

            AvatarAppearance aa = new AvatarAppearance(user);
            //try {
            aa.Owner = user;

            DataTable aap = ds.Tables["avatarappearance"];
            lock (ds)
            {
                DataRow row = aap.Rows.Find(Util.ToRawUuidString(user));
                if (row == null)
                {
                    m_log.Info("[APPEARANCE] Could not find appearance for " + user.ToString());

                    //m_log.Debug("[USER DB]: Creating avatarappearance For: " + user.ToString());

                    //row = aap.NewRow();
                    //fillAvatarAppearanceRow(row, user, appearance);
                    //aap.Rows.Add(row);
                    //    m_log.Debug("[USER DB]: Syncing user database: " + ds.Tables["users"].Rows.Count + " users stored");
                    // save changes off to disk
                    //daa.Update(ds, "avatarappearance");
                }
                else
                {
                    m_log.InfoFormat("[APPEARANCE] appearance found for {0}", user.ToString());

                    aa.BodyAsset        = new UUID((String)row["BodyAsset"]);
                    aa.BodyItem         = new UUID((String)row["BodyItem"]);
                    aa.SkinItem         = new UUID((String)row["SkinItem"]);
                    aa.SkinAsset        = new UUID((String)row["SkinAsset"]);
                    aa.HairItem         = new UUID((String)row["HairItem"]);
                    aa.HairAsset        = new UUID((String)row["HairAsset"]);
                    aa.EyesItem         = new UUID((String)row["EyesItem"]);
                    aa.EyesAsset        = new UUID((String)row["EyesAsset"]);
                    aa.ShirtItem        = new UUID((String)row["ShirtItem"]);
                    aa.ShirtAsset       = new UUID((String)row["ShirtAsset"]);
                    aa.PantsItem        = new UUID((String)row["PantsItem"]);
                    aa.PantsAsset       = new UUID((String)row["PantsAsset"]);
                    aa.ShoesItem        = new UUID((String)row["ShoesItem"]);
                    aa.ShoesAsset       = new UUID((String)row["ShoesAsset"]);
                    aa.SocksItem        = new UUID((String)row["SocksItem"]);
                    aa.SocksAsset       = new UUID((String)row["SocksAsset"]);
                    aa.JacketItem       = new UUID((String)row["JacketItem"]);
                    aa.JacketAsset      = new UUID((String)row["JacketAsset"]);
                    aa.GlovesItem       = new UUID((String)row["GlovesItem"]);
                    aa.GlovesAsset      = new UUID((String)row["GlovesAsset"]);
                    aa.UnderShirtItem   = new UUID((String)row["UnderShirtItem"]);
                    aa.UnderShirtAsset  = new UUID((String)row["UnderShirtAsset"]);
                    aa.UnderPantsItem   = new UUID((String)row["UnderPantsItem"]);
                    aa.UnderPantsAsset  = new UUID((String)row["UnderPantsAsset"]);
                    aa.SkirtItem        = new UUID((String)row["SkirtItem"]);
                    aa.SkirtAsset       = new UUID((String)row["SkirtAsset"]);

                    // Ewe Loon
                    //  Used Base64String because for some reason it wont accept using Byte[] (which works in Region date)

                    String str = (String)row["Texture"];
                    byte[] texture = Convert.FromBase64String(str);
                    aa.Texture = new Primitive.TextureEntry(texture, 0, texture.Length);

                    str = (String)row["VisualParams"];
                    byte[] VisualParams = Convert.FromBase64String(str);
                    aa.VisualParams = VisualParams;

                    aa.Serial = Convert.ToInt32(row["Serial"]);
                    aa.AvatarHeight = Convert.ToSingle(row["AvatarHeight"]);
                    m_log.InfoFormat("[APPEARANCE] appearance set for {0}", user.ToString());
                }
            }

           //     m_log.Info("[APPEARANCE] Found appearance for " + user.ToString() + aa.ToString());
           // } catch (KeyNotFoundException) {
           //     m_log.InfoFormat("[APPEARANCE] No appearance found for {0}", user.ToString());
           // }
            return aa;
        }
Пример #23
0
        public ScenePresence(
            IClientAPI client, Scene world, AvatarAppearance appearance, PresenceType type)
        {            
            m_scene = world;
            AttachmentsSyncLock = new Object();
            AllowMovement = true;
            IsChildAgent = true;
            IsLoggingIn = false;
            m_sendCoarseLocationsMethod = SendCoarseLocationsDefault;
            Animator = new ScenePresenceAnimator(this);
            Overrides = new MovementAnimationOverrides();
            PresenceType = type;
            DrawDistance = world.DefaultDrawDistance;
            RegionHandle = world.RegionInfo.RegionHandle;
            ControllingClient = client;
            Firstname = ControllingClient.FirstName;
            Lastname = ControllingClient.LastName;
            m_name = String.Format("{0} {1}", Firstname, Lastname);
            m_uuid = client.AgentId;
            LocalId = m_scene.AllocateLocalId();
            LegacySitOffsets = m_scene.LegacySitOffsets;

            UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, m_uuid);
            if (account != null)
                m_userFlags = account.UserFlags;
            else
                m_userFlags = 0;

            if (account != null)
                UserLevel = account.UserLevel;

            IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
            if (gm != null)
               Grouptitle = gm.GetGroupTitle(m_uuid);

            m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>();
            
            AbsolutePosition = posLastSignificantMove = CameraPosition =
                m_lastCameraPosition = ControllingClient.StartPos;

            m_reprioritization_timer = new Timer(world.ReprioritizationInterval);
            m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize);
            m_reprioritization_timer.AutoReset = false;

            AdjustKnownSeeds();

            RegisterToEvents();
            SetDirectionVectors();

            Appearance = appearance;

            m_stateMachine = new ScenePresenceStateMachine(this);
        }
Пример #24
0
        /// <summary>
        /// Unpack agent circuit data map into an AgentCiruitData object
        /// </summary>
        /// <param name="args"></param>
        public void UnpackAgentCircuitData(OSDMap args)
        {
            if (args["agent_id"] != null)
                AgentID = args["agent_id"].AsUUID();
            if (args["base_folder"] != null)
                BaseFolder = args["base_folder"].AsUUID();
            if (args["caps_path"] != null)
                CapsPath = args["caps_path"].AsString();

            if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
            {
                OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
                ChildrenCapSeeds = new Dictionary<ulong, string>();
                foreach (OSD o in childrenSeeds)
                {
                    if (o.Type == OSDType.Map)
                    {
                        ulong handle = 0;
                        string seed = "";
                        OSDMap pair = (OSDMap)o;
                        if (pair["handle"] != null)
                            if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
                                continue;
                        if (pair["seed"] != null)
                            seed = pair["seed"].AsString();
                        if (!ChildrenCapSeeds.ContainsKey(handle))
                            ChildrenCapSeeds.Add(handle, seed);
                    }
                }
            }
            else
                ChildrenCapSeeds = new Dictionary<ulong, string>();

            if (args["child"] != null)
                child = args["child"].AsBoolean();
            if (args["circuit_code"] != null)
                UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
            if (args["first_name"] != null)
                firstname = args["first_name"].AsString();
            if (args["last_name"] != null)
                lastname = args["last_name"].AsString();
            if (args["inventory_folder"] != null)
                InventoryFolder = args["inventory_folder"].AsUUID();
            if (args["secure_session_id"] != null)
                SecureSessionID = args["secure_session_id"].AsUUID();
            if (args["session_id"] != null)
                SessionID = args["session_id"].AsUUID();
            if (args["service_session_id"] != null)
                ServiceSessionID = args["service_session_id"].AsString();
            if (args["client_ip"] != null)
                IPAddress = args["client_ip"].AsString();
            if (args["viewer"] != null)
                Viewer = args["viewer"].AsString();
            if (args["channel"] != null)
                Channel = args["channel"].AsString();
            if (args["mac"] != null)
                Mac = args["mac"].AsString();
            if (args["id0"] != null)
                Id0 = args["id0"].AsString();

            if (args["start_pos"] != null)
                Vector3.TryParse(args["start_pos"].AsString(), out startpos);

            // DEBUG ON
            //m_log.WarnFormat("[AGENTCIRCUITDATA] agentid={0}, child={1}, startpos={2}", AgentID, child, startpos.ToString());
            // DEBUG OFF

            try
            {
                // Unpack various appearance elements
                Appearance = new AvatarAppearance(AgentID);

                // Eventually this code should be deprecated, use full appearance
                // packing in packed_appearance
                if (args["appearance_serial"] != null)
                    Appearance.Serial = args["appearance_serial"].AsInteger();

                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
                {
                    Appearance.Unpack((OSDMap)args["packed_appearance"]);
                    // DEBUG ON
                    //m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance");
                    // DEBUG OFF
                }
                // DEBUG ON
                else
                    m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
                // DEBUG OFF
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}", e.Message);
            }

            ServiceURLs = new Dictionary<string, object>();
            if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
            {
                OSDArray urls = (OSDArray)(args["service_urls"]);
                for (int i = 0; i < urls.Count / 2; i++)
                {
                    ServiceURLs[urls[i * 2].AsString()] = urls[(i * 2) + 1].AsString();
                    //System.Console.WriteLine("XXX " + urls[i * 2].AsString() + "=" + urls[(i * 2) + 1].AsString());

                }
            }
        }
Пример #25
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args, IScene scene, EntityTransferContext ctx)
        {
            //m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");
            OSD tmp;

            if (args.TryGetValue("region_id", out tmp) && tmp != null)
            {
                UUID.TryParse(tmp.AsString(), out RegionID);
            }

            if (args.TryGetValue("circuit_code", out tmp) && tmp != null)
            {
                UInt32.TryParse(tmp.AsString(), out CircuitCode);
            }

            if (args.TryGetValue("agent_uuid", out tmp) && tmp != null)
            {
                AgentID = tmp.AsUUID();
            }

            if (args.TryGetValue("session_uuid", out tmp) && tmp != null)
            {
                SessionID = tmp.AsUUID();
            }

            if (args.TryGetValue("position", out tmp) && tmp != null)
            {
                Vector3.TryParse(tmp.AsString(), out Position);
            }

            if (args.TryGetValue("velocity", out tmp) && tmp != null)
            {
                Vector3.TryParse(tmp.AsString(), out Velocity);
            }

            if (args.TryGetValue("center", out tmp) && tmp != null)
            {
                Vector3.TryParse(tmp.AsString(), out Center);
            }

            if (args.TryGetValue("size", out tmp) && tmp != null)
            {
                Vector3.TryParse(tmp.AsString(), out Size);
            }

            if (args.TryGetValue("at_axis", out tmp) && tmp != null)
            {
                Vector3.TryParse(tmp.AsString(), out AtAxis);
            }

            if (args.TryGetValue("left_axis", out tmp) && tmp != null)
            {
                Vector3.TryParse(tmp.AsString(), out AtAxis);
            }

            if (args.TryGetValue("up_axis", out tmp) && tmp != null)
            {
                Vector3.TryParse(tmp.AsString(), out AtAxis);
            }

            if (args.TryGetValue("wait_for_root", out tmp) && tmp != null)
            {
                SenderWantsToWaitForRoot = tmp.AsBoolean();
            }

            if (args.TryGetValue("far", out tmp) && tmp != null)
            {
                Far = (float)(tmp.AsReal());
            }

            if (args.TryGetValue("aspect", out tmp) && tmp != null)
            {
                Aspect = (float)tmp.AsReal();
            }

            if (args.TryGetValue("throttles", out tmp) && tmp != null)
            {
                Throttles = tmp.AsBinary();
            }

            if (args.TryGetValue("locomotion_state", out tmp) && tmp != null)
            {
                UInt32.TryParse(tmp.AsString(), out LocomotionState);
            }

            if (args.TryGetValue("head_rotation", out tmp) && tmp != null)
            {
                Quaternion.TryParse(tmp.AsString(), out HeadRotation);
            }

            if (args.TryGetValue("body_rotation", out tmp) && tmp != null)
            {
                Quaternion.TryParse(tmp.AsString(), out BodyRotation);
            }

            if (args.TryGetValue("control_flags", out tmp) && tmp != null)
            {
                UInt32.TryParse(tmp.AsString(), out ControlFlags);
            }

            if (args.TryGetValue("energy_level", out tmp) && tmp != null)
            {
                EnergyLevel = (float)(tmp.AsReal());
            }

            if (args.TryGetValue("god_data", out tmp) && tmp != null)
            {
                GodData = tmp;
            }

            if (args.TryGetValue("always_run", out tmp) && tmp != null)
            {
                AlwaysRun = tmp.AsBoolean();
            }

            if (args.TryGetValue("prey_agent", out tmp) && tmp != null)
            {
                PreyAgent = tmp.AsUUID();
            }

            if (args.TryGetValue("agent_access", out tmp) && tmp != null)
            {
                Byte.TryParse(tmp.AsString(), out AgentAccess);
            }

            if (args.TryGetValue("agent_cof", out tmp) && tmp != null)
            {
                agentCOF = tmp.AsUUID();
            }

            if (args.TryGetValue("crossingflags", out tmp) && tmp != null)
            {
                CrossingFlags = (byte)tmp.AsInteger();
            }

            if (CrossingFlags != 0)
            {
                if (args.TryGetValue("crossExtraFlags", out tmp) && tmp != null)
                {
                    CrossExtraFlags = (byte)tmp.AsInteger();
                }
            }

            if (args.TryGetValue("active_group_id", out tmp) && tmp != null)
            {
                ActiveGroupID = tmp.AsUUID();
            }

            if (args.TryGetValue("active_group_name", out tmp) && tmp != null)
            {
                ActiveGroupName = tmp.AsString();
            }

            if (args.TryGetValue("active_group_title", out tmp) && tmp != null)
            {
                ActiveGroupTitle = tmp.AsString();
            }

            if (args.TryGetValue("children_seeds", out tmp) && tmp is OSDArray)
            {
                OSDArray childrenSeeds = (OSDArray)tmp;
                ChildrenCapSeeds = new Dictionary <ulong, string>();
                foreach (OSD o in childrenSeeds)
                {
                    if (o is OSDMap)
                    {
                        ulong  handle = 0;
                        string seed   = "";
                        OSDMap pair   = (OSDMap)o;
                        if (pair.TryGetValue("handle", out tmp))
                        {
                            if (!UInt64.TryParse(tmp.AsString(), out handle))
                            {
                                continue;
                            }
                        }
                        if (pair.TryGetValue("seed", out tmp))
                        {
                            seed = tmp.AsString();
                        }
                        if (!ChildrenCapSeeds.ContainsKey(handle))
                        {
                            ChildrenCapSeeds.Add(handle, seed);
                        }
                    }
                }
            }

            if (args.TryGetValue("animations", out tmp) && tmp is OSDArray)
            {
                OSDArray anims = (OSDArray)tmp;
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o is OSDMap)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            if (args.TryGetValue("default_animation", out tmp) && tmp is OSDMap)
            {
                try
                {
                    DefaultAnim = new Animation((OSDMap)tmp);
                }
                catch
                {
                    DefaultAnim = null;
                }
            }

            if (args.TryGetValue("animation_state", out tmp) && tmp is OSDMap)
            {
                try
                {
                    AnimState = new Animation((OSDMap)tmp);
                }
                catch
                {
                    AnimState = null;
                }
            }

            MovementAnimationOverRides.Clear();

            if (args.TryGetValue("movementAO", out tmp) && tmp is OSDArray)
            {
                OSDArray AOs   = (OSDArray)tmp;
                int      count = AOs.Count;

                for (int i = 0; i < count; i++)
                {
                    OSDMap ao = (OSDMap)AOs[i];
                    if (ao["state"] != null && ao["uuid"] != null)
                    {
                        string state = ao["state"].AsString();
                        UUID   id    = ao["uuid"].AsUUID();
                        MovementAnimationOverRides[state] = id;
                    }
                }
            }

            if (args.TryGetValue("motion_state", out tmp) && tmp != null)
            {
                MotionState = (byte)tmp.AsInteger();
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}


            // packed_appearence should contain all appearance information
            if (args.TryGetValue("packed_appearance", out tmp) && tmp is OSDMap)
            {
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] got packed appearance");
                Appearance = new AvatarAppearance((OSDMap)tmp);
            }
            else
            {
                // if missing try the old pack method
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance, checking old method");

                Appearance = new AvatarAppearance();

                // The code to unpack textures, visuals, wearables and attachments
                // should be removed; packed appearance contains the full appearance
                // This is retained for backward compatibility only
                if (args.TryGetValue("texture_entry", out tmp) && tmp != null)
                {
                    byte[] rawtextures = tmp.AsBinary();
                    Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
                    Appearance.SetTextureEntries(textures);
                }

                if (args.TryGetValue("visual_params", out tmp) && tmp != null)
                {
                    Appearance.SetVisualParams(tmp.AsBinary());
                }

                if (args.TryGetValue("wearables", out tmp) && tmp is OSDArray)
                {
                    OSDArray wears = (OSDArray)tmp;

                    for (int i = 0; i < wears.Count / 2; i++)
                    {
                        AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
                        Appearance.SetWearable(i, awear);
                    }
                }

                if (args.TryGetValue("attachments", out tmp) && tmp is OSDArray)
                {
                    OSDArray attachs = (OSDArray)tmp;
                    foreach (OSD o in attachs)
                    {
                        if (o is OSDMap)
                        {
                            // We know all of these must end up as attachments so we
                            // append rather than replace to ensure multiple attachments
                            // per point continues to work
                            //                        m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
                            Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                        }
                    }
                }
                // end of code to remove
            }

            if (args.TryGetValue("controllers", out tmp) && tmp is OSDArray)
            {
                OSDArray controls = (OSDArray)tmp;
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o is OSDMap)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args.TryGetValue("callback_uri", out tmp) && tmp != null)
            {
                CallbackURI = tmp.AsString();
            }

            if (args.TryGetValue("cb_uri", out tmp) && tmp != null)
            {
                NewCallbackURI = tmp.AsString();
            }

            // Attachment objects
            if (args.TryGetValue("attach_objects", out tmp) && tmp is OSDArray)
            {
                OSDArray attObjs = (OSDArray)tmp;
                AttachmentObjects      = new List <ISceneObject>();
                AttachmentObjectStates = new List <string>();
                foreach (OSD o in attObjs)
                {
                    if (o is OSDMap)
                    {
                        OSDMap       info = (OSDMap)o;
                        ISceneObject so   = scene.DeserializeObject(info["sog"].AsString());
                        so.ExtraFromXmlString(info["extra"].AsString());
                        so.HasGroupChanged = info["modified"].AsBoolean();
                        AttachmentObjects.Add(so);
                        AttachmentObjectStates.Add(info["state"].AsString());
                    }
                }
            }

            if (args.TryGetValue("parent_part", out tmp) && tmp != null)
            {
                ParentPart = tmp.AsUUID();
            }
            if (args.TryGetValue("sit_offset", out tmp) && tmp != null)
            {
                Vector3.TryParse(tmp.AsString(), out SitOffset);
            }
        }
Пример #26
0
        private LSL_Key NpcCreate(
            string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent, bool hostGroupID)
        {
            if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
            {
                OSSLError("no permission to rez NPC at requested location");
                return new LSL_Key(UUID.Zero.ToString());
            }

            INPCModule module = World.RequestModuleInterface<INPCModule>();
            if(module == null)
            {
                OSSLError("NPC module not enabled");
                return new LSL_Key(UUID.Zero.ToString());
            }

            string groupTitle = String.Empty;
            UUID groupID = UUID.Zero;

            AvatarAppearance appearance = null;

            // check creation options
            NPCOptionsFlags createFlags = module.NPCOptionFlags;

            if((createFlags & NPCOptionsFlags.AllowNotOwned) == 0 && !owned)
            {
                OSSLError("Not owned NPCs disabled");
                owned = true; // we should get here...
            }

            if((createFlags & NPCOptionsFlags.AllowSenseAsAvatar) == 0 && senseAsAgent)
            {
                OSSLError("NPC allow sense as Avatar disabled");
                senseAsAgent = false;
            }

            if(hostGroupID && m_host.GroupID != UUID.Zero)
            {
                IGroupsModule groupsModule = m_ScriptEngine.World.RequestModuleInterface<IGroupsModule>();
                if (groupsModule != null)
                {
                    GroupMembershipData member = groupsModule.GetMembershipData(m_host.GroupID, m_host.OwnerID);
                    if (member == null)
                    {
                        OSSLError(string.Format("osNpcCreate: the object owner is not member of the object group"));
                        return new LSL_Key(UUID.Zero.ToString());
                    }

                    groupID = m_host.GroupID;

                    if((createFlags & NPCOptionsFlags.NoNPCGroup) != 0)
                    {
                        GroupRecord grprec = groupsModule.GetGroupRecord(m_host.GroupID);
                        if(grprec != null && grprec.GroupName != "")
                            groupTitle = grprec.GroupName;
                    }
                }
            }

            if((createFlags & NPCOptionsFlags.NoNPCGroup) == 0)
            {
                if (firstname != String.Empty || lastname != String.Empty)
                {
                    if (firstname != "Shown outfit:")
                        groupTitle = "- NPC -";
                }
            }
               
            if((createFlags & NPCOptionsFlags.AllowCloneOtherAvatars) != 0)
            {
                UUID id;
                if (UUID.TryParse(notecard, out id))
                {
                    ScenePresence clonePresence = World.GetScenePresence(id);
                    if (clonePresence != null)
                        appearance = clonePresence.Appearance;
                }
            }

            if (appearance == null)
            {
                string appearanceSerialized = LoadNotecard(notecard);

                if (appearanceSerialized != null)
                {
                    try
                    {
                        OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
                        appearance = new AvatarAppearance();
                        appearance.Unpack(appearanceOsd);
                    }
                    catch
                    {
                        OSSLError(string.Format("osNpcCreate: Error processing notcard '{0}'", notecard));
                        return new LSL_Key(UUID.Zero.ToString());
                    }
                }
            else
                {
                    OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard));
                }
            }

            UUID ownerID = UUID.Zero;
            if (owned)
                ownerID = m_host.OwnerID;
            UUID x = module.CreateNPC(firstname,
                                      lastname,
                                      position,
                                      UUID.Random(),
                                      ownerID,
                                      groupTitle,
                                      groupID,
                                      senseAsAgent,
                                      World,
                                      appearance);

            ScenePresence sp;
            if (World.TryGetScenePresence(x, out sp))
            {
                sp.SendAvatarDataToAllAgents();
            }
            return new LSL_Key(x.ToString());
        }
Пример #27
0
        public AvatarAppearance(AvatarAppearance appearance, bool copyWearables, bool copyBaked)
        {
//            m_log.WarnFormat("[AVATAR APPEARANCE] create from an existing appearance");

            if (appearance == null)
            {
                m_serial = 0;
                SetDefaultWearables();
                SetDefaultTexture();
                SetDefaultParams();
//                SetHeight();
                SetSize(new Vector3(0.45f, 0.6f, 1.9f));
                m_attachments = new Dictionary<int, List<AvatarAttachment>>();

                return;
            }

            m_serial = appearance.Serial;

            if (copyWearables && (appearance.Wearables != null))
            {
                m_wearables = new AvatarWearable[appearance.Wearables.Length];
                for (int i = 0; i < appearance.Wearables.Length; i++)
                {
                    m_wearables[i] = new AvatarWearable();
                    AvatarWearable wearable = appearance.Wearables[i];
                    for (int j = 0; j < wearable.Count; j++)
                            m_wearables[i].Add(wearable[j].ItemID, wearable[j].AssetID);                       
                 }
            }
            else
                ClearWearables();

            m_texture = null;
            if (appearance.Texture != null)
            {
                byte[] tbytes = appearance.Texture.GetBytes();
                m_texture = new Primitive.TextureEntry(tbytes,0,tbytes.Length);
                if (copyBaked && appearance.m_cacheitems != null)
                    m_cacheitems = (WearableCacheItem[])appearance.m_cacheitems.Clone();
                else
                    m_cacheitems = null;
            }

            m_visualparams = null;
            if (appearance.VisualParams != null)
                m_visualparams = (byte[])appearance.VisualParams.Clone();

//            m_avatarHeight = appearance.m_avatarHeight;
            SetSize(appearance.AvatarSize);

            // Copy the attachment, force append mode since that ensures consistency
            m_attachments = new Dictionary<int, List<AvatarAttachment>>();
            foreach (AvatarAttachment attachment in appearance.GetAttachments())
                AppendAttachment(new AvatarAttachment(attachment));
        }
Пример #28
0
        private void CopyFrom(AgentData cAgent)
        {
            m_callbackURI = cAgent.CallbackURI;
//            m_log.DebugFormat(
//                "[SCENE PRESENCE]: Set callback for {0} in {1} to {2} in CopyFrom()",
//                Name, m_scene.RegionInfo.RegionName, m_callbackURI);

            m_pos = cAgent.Position;
            m_velocity = cAgent.Velocity;
            CameraPosition = cAgent.Center;
            CameraAtAxis = cAgent.AtAxis;
            CameraLeftAxis = cAgent.LeftAxis;
            CameraUpAxis = cAgent.UpAxis;
            ParentUUID = cAgent.ParentPart;
            PrevSitOffset = cAgent.SitOffset;

            // When we get to the point of re-computing neighbors everytime this
            // changes, then start using the agent's drawdistance rather than the 
            // region's draw distance.
            DrawDistance = cAgent.Far;
            //DrawDistance = Scene.DefaultDrawDistance;

            if (cAgent.ChildrenCapSeeds != null && cAgent.ChildrenCapSeeds.Count > 0)
            {
                if (Scene.CapsModule != null)
                {
                    Scene.CapsModule.SetChildrenSeed(UUID, cAgent.ChildrenCapSeeds);
                }
                KnownRegions = cAgent.ChildrenCapSeeds;
            }

            if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0)
                ControllingClient.SetChildAgentThrottle(cAgent.Throttles);

            m_headrotation = cAgent.HeadRotation;
            Rotation = cAgent.BodyRotation;
            m_AgentControlFlags = (AgentManager.ControlFlags)cAgent.ControlFlags; 

            if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
                GodLevel = cAgent.GodLevel;
            SetAlwaysRun = cAgent.AlwaysRun;


            Appearance = new AvatarAppearance(cAgent.Appearance);
/*
            bool isFlying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 

            if (PhysicsActor != null)
            {
                RemoveFromPhysicalScene();
                AddToPhysicalScene(isFlying);
            }
*/            
            try
            {
                lock (scriptedcontrols)
                {
                    if (cAgent.Controllers != null)
                    {
                        scriptedcontrols.Clear();

                        foreach (ControllerData c in cAgent.Controllers)
                        {
                            ScriptControllers sc = new ScriptControllers();
                            sc.objectID = c.ObjectID;
                            sc.itemID = c.ItemID;
                            sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
                            sc.eventControls = (ScriptControlled)c.EventControls;

                            scriptedcontrols[sc.itemID] = sc;
                        }
                    }
                }
            }
            catch { }

            Animator.ResetAnimations();

            Overrides.CopyAOPairsFrom(cAgent.MovementAnimationOverRides);

            // FIXME: Why is this null check necessary?  Where are the cases where we get a null Anims object?
            if (cAgent.DefaultAnim != null)
                Animator.Animations.SetDefaultAnimation(cAgent.DefaultAnim.AnimID, cAgent.DefaultAnim.SequenceNum, UUID.Zero);
            if (cAgent.AnimState != null)
                Animator.Animations.SetImplicitDefaultAnimation(cAgent.AnimState.AnimID, cAgent.AnimState.SequenceNum, UUID.Zero);
            if (cAgent.Anims != null)
                Animator.Animations.FromArray(cAgent.Anims);
            if (cAgent.MotionState != 0)
                Animator.currentControlState = (ScenePresenceAnimator.motionControlStates) cAgent.MotionState;

            if (Scene.AttachmentsModule != null)
                Scene.AttachmentsModule.CopyAttachments(cAgent, this);

            lock (m_originRegionIDAccessLock)
                m_originRegionID = cAgent.RegionID;
        }
Пример #29
0
        public void GetAssetsFrom(AvatarAppearance app)
        {
            int len =  m_wearables.Length;
            if(len > app.m_wearables.Length)
                len = app.m_wearables.Length;

            for (int i = 0; i < len; i++)
            {
                int count =  m_wearables[i].Count;
                if(count > app.m_wearables[i].Count)
                    count = app.m_wearables[i].Count;

                for (int j = 0; j < count; j++)
                {
                    UUID itemID = m_wearables[i][j].ItemID;
                    UUID assetID = app.Wearables[i].GetAsset(itemID);

                    if (assetID != UUID.Zero)
                        m_wearables[i].Add(itemID, assetID);
                }
            }
        }
Пример #30
0
        protected AgentCircuitData LaunchAgentAtGrid(GridRegion gatekeeper, GridRegion destination, UserAccount account, AvatarAppearance avatar,
            UUID session, UUID secureSession, Vector3 position, string currentWhere, string viewer, string channel, string mac, string id0,
            IPEndPoint clientIP, TeleportFlags flags, out string where, out string reason, out GridRegion dest)
        {
            where = currentWhere;
            ISimulationService simConnector = null;
            reason = string.Empty;
            uint circuitCode = 0;
            AgentCircuitData aCircuit = null;

            if (m_UserAgentService == null)
            {
                // HG standalones have both a localSimulatonDll and a remoteSimulationDll
                // non-HG standalones have just a localSimulationDll
                // independent login servers have just a remoteSimulationDll
                if (m_LocalSimulationService != null)
                    simConnector = m_LocalSimulationService;
                else if (m_RemoteSimulationService != null)
                    simConnector = m_RemoteSimulationService;
            }
            else // User Agent Service is on
            {
                if (gatekeeper == null) // login to local grid
                {
                    if (hostName == string.Empty)
                        SetHostAndPort(m_GatekeeperURL);

                    gatekeeper = new GridRegion(destination);
                    gatekeeper.ExternalHostName = hostName;
                    gatekeeper.HttpPort = (uint)port;
                    gatekeeper.ServerURI = m_GatekeeperURL;
                }
                m_log.Debug("[LLLOGIN SERVICE]: no gatekeeper detected..... using " + m_GatekeeperURL);
            }

            bool success = false;

            if (m_UserAgentService == null && simConnector != null)
            {
                circuitCode = (uint)Util.RandomClass.Next(); ;
                aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position, clientIP.Address.ToString(), viewer, channel, mac, id0);
                success = LaunchAgentDirectly(simConnector, destination, aCircuit, flags, out reason);
                if (!success && m_GridService != null)
                {
                    // Try the fallback regions
                    List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
                    if (fallbacks != null)
                    {
                        foreach (GridRegion r in fallbacks)
                        {
                            success = LaunchAgentDirectly(simConnector, r, aCircuit, flags | TeleportFlags.ViaRegionID, out reason);
                            if (success)
                            {
                                where = "safe";
                                destination = r;
                                break;
                            }
                        }
                    }
                }
            }

            if (m_UserAgentService != null)
            {
                circuitCode = (uint)Util.RandomClass.Next(); ;
                aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position, clientIP.Address.ToString(), viewer, channel, mac, id0);
                aCircuit.teleportFlags |= (uint)flags;
                success = LaunchAgentIndirectly(gatekeeper, destination, aCircuit, clientIP, out reason);
                if (!success && m_GridService != null)
                {
                    // Try the fallback regions
                    List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
                    if (fallbacks != null)
                    {
                        foreach (GridRegion r in fallbacks)
                        {
                            success = LaunchAgentIndirectly(gatekeeper, r, aCircuit, clientIP, out reason);
                            if (success)
                            {
                                where = "safe";
                                destination = r;
                                break;
                            }
                        }
                    }
                }
            }
            dest = destination;
            if (success)
                return aCircuit;
            else
                return null;
        }
Пример #31
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            // DEBUG ON
            m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data");
            // DEBUG OFF

            if (args.ContainsKey("region_id"))
                UUID.TryParse(args["region_id"].AsString(), out RegionID);

            if (args["circuit_code"] != null)
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);

            if (args["agent_uuid"] != null)
                AgentID = args["agent_uuid"].AsUUID();

            if (args["session_uuid"] != null)
                SessionID = args["session_uuid"].AsUUID();

            if (args["position"] != null)
                Vector3.TryParse(args["position"].AsString(), out Position);

            if (args["velocity"] != null)
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);

            if (args["center"] != null)
                Vector3.TryParse(args["center"].AsString(), out Center);

            if (args["size"] != null)
                Vector3.TryParse(args["size"].AsString(), out Size);

            if (args["at_axis"] != null)
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);

            if (args["left_axis"] != null)
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);

            if (args["up_axis"] != null)
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);

            if (args["changed_grid"] != null)
                ChangedGrid = args["changed_grid"].AsBoolean();

            if (args["far"] != null)
                Far = (float)(args["far"].AsReal());

            if (args["aspect"] != null)
                Aspect = (float)args["aspect"].AsReal();

            if (args["throttles"] != null)
                Throttles = args["throttles"].AsBinary();

            if (args["locomotion_state"] != null)
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);

            if (args["head_rotation"] != null)
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);

            if (args["body_rotation"] != null)
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);

            if (args["control_flags"] != null)
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);

            if (args["energy_level"] != null)
                EnergyLevel = (float)(args["energy_level"].AsReal());

            //This IS checked later
            if (args["god_level"] != null)
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);

            if (args["speed"] != null)
                float.TryParse(args["speed"].AsString(), out Speed);
            else
                Speed = 1;

            if (args["draw_distance"] != null)
                float.TryParse(args["draw_distance"].AsString(), out DrawDistance);
            else
                DrawDistance = 0;

            //Reset this to fix movement... since regions are being bad about this
            if (Speed == 0)
                Speed = 1;

            if (args["always_run"] != null)
                AlwaysRun = args["always_run"].AsBoolean();

            if (args["sent_initial_wearables"] != null)
                SentInitialWearables = args["sent_initial_wearables"].AsBoolean();
            else
                SentInitialWearables = false;

            if (args["prey_agent"] != null)
                PreyAgent = args["prey_agent"].AsUUID();

            if (args["agent_access"] != null)
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);

            if (args["active_group_id"] != null)
                ActiveGroupID = args["active_group_id"].AsUUID();

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}

            Appearance = new AvatarAppearance(AgentID);

            // The code to unpack textures, visuals, wearables and attachments
            // should be removed; packed appearance contains the full appearance
            // This is retained for backward compatibility only
            if (args["texture_entry"] != null)
            {
                byte[] rawtextures = args["texture_entry"].AsBinary();
                Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
                List<UUID> changed = new List<UUID>();
                Appearance.SetTextureEntries(textures, out changed);
            }

            if (args["visual_params"] != null)
                Appearance.SetVisualParams(args["visual_params"].AsBinary());

            if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                for (int i = 0; i < wears.Count / 2; i++)
                {
                    AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
                    Appearance.SetWearable(i, awear);
                }
            }

            if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
            {
                OSDArray attachs = (OSDArray)(args["attachments"]);
                foreach (OSD o in attachs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        // We know all of these must end up as attachments so we
                        // append rather than replace to ensure multiple attachments
                        // per point continues to work
                        Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                    }
                }
            }
            // end of code to remove

            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                Appearance = new AvatarAppearance(AgentID, (OSDMap)args["packed_appearance"]);
            // DEBUG ON
            else
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
            // DEBUG OFF

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
                CallbackURI = args["callback_uri"].AsString();
        }
Пример #32
0
        /// <summary>
        /// This method is called by establishAppearance to do a copy all inventory items
        /// worn or attached to the Clothing inventory folder of the receiving avatar.
        /// In parallel the avatar wearables and attachments are updated.
        /// </summary>

        private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance)
        {
            IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService;

            // Get Clothing folder of receiver
            InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, AssetType.Clothing);

            if (destinationFolder == null)
                throw new Exception("Cannot locate folder(s)");

            // Missing destination folder? This should *never* be the case
            if (destinationFolder.Type != (short)AssetType.Clothing)
            {
                destinationFolder = new InventoryFolderBase();
                
                destinationFolder.ID       = UUID.Random();
                destinationFolder.Name     = "Clothing";
                destinationFolder.Owner    = destination;
                destinationFolder.Type     = (short)AssetType.Clothing;
                destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID;
                destinationFolder.Version  = 1;
                inventoryService.AddFolder(destinationFolder);     // store base record
                m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source);
            }

            // Wearables
            AvatarWearable[] wearables = avatarAppearance.Wearables;
            AvatarWearable wearable;

            for (int i=0; i<wearables.Length; i++)
            {
                wearable = wearables[i];
                if (wearable[0].ItemID != UUID.Zero)
                {
                    // Get inventory item and copy it
                    InventoryItemBase item = new InventoryItemBase(wearable[0].ItemID, source);
                    item = inventoryService.GetItem(item);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
                        destinationItem.Name = item.Name;
                        destinationItem.Owner = destination;
                        destinationItem.Description = item.Description;
                        destinationItem.InvType = item.InvType;
                        destinationItem.CreatorId = item.CreatorId;
                        destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid;
                        destinationItem.CreatorData = item.CreatorData;
                        destinationItem.NextPermissions = item.NextPermissions;
                        destinationItem.CurrentPermissions = item.CurrentPermissions;
                        destinationItem.BasePermissions = item.BasePermissions;
                        destinationItem.EveryOnePermissions = item.EveryOnePermissions;
                        destinationItem.GroupPermissions = item.GroupPermissions;
                        destinationItem.AssetType = item.AssetType;
                        destinationItem.AssetID = item.AssetID;
                        destinationItem.GroupID = item.GroupID;
                        destinationItem.GroupOwned = item.GroupOwned;
                        destinationItem.SalePrice = item.SalePrice;
                        destinationItem.SaleType = item.SaleType;
                        destinationItem.Flags = item.Flags;
                        destinationItem.CreationDate = item.CreationDate;
                        destinationItem.Folder = destinationFolder.ID;
                        ApplyNextOwnerPermissions(destinationItem);

                        m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
                        m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);

                        // Wear item
                        AvatarWearable newWearable = new AvatarWearable();
                        newWearable.Wear(destinationItem.ID, wearable[0].AssetID);
                        avatarAppearance.SetWearable(i, newWearable);
                    }
                    else
                    {
                        m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID);
                    }
                }
            }

            // Attachments
            List<AvatarAttachment> attachments = avatarAppearance.GetAttachments();

            foreach (AvatarAttachment attachment in attachments)
            {
                int attachpoint = attachment.AttachPoint;
                UUID itemID = attachment.ItemID;

                if (itemID != UUID.Zero)
                {
                    // Get inventory item and copy it
                    InventoryItemBase item = new InventoryItemBase(itemID, source);
                    item = inventoryService.GetItem(item);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
                        destinationItem.Name = item.Name;
                        destinationItem.Owner = destination;
                        destinationItem.Description = item.Description;
                        destinationItem.InvType = item.InvType;
                        destinationItem.CreatorId = item.CreatorId;
                        destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid;
                        destinationItem.CreatorData = item.CreatorData;
                        destinationItem.NextPermissions = item.NextPermissions;
                        destinationItem.CurrentPermissions = item.CurrentPermissions;
                        destinationItem.BasePermissions = item.BasePermissions;
                        destinationItem.EveryOnePermissions = item.EveryOnePermissions;
                        destinationItem.GroupPermissions = item.GroupPermissions;
                        destinationItem.AssetType = item.AssetType;
                        destinationItem.AssetID = item.AssetID;
                        destinationItem.GroupID = item.GroupID;
                        destinationItem.GroupOwned = item.GroupOwned;
                        destinationItem.SalePrice = item.SalePrice;
                        destinationItem.SaleType = item.SaleType;
                        destinationItem.Flags = item.Flags;
                        destinationItem.CreationDate = item.CreationDate;
                        destinationItem.Folder = destinationFolder.ID;
                        ApplyNextOwnerPermissions(destinationItem);

                        m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
                        m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);

                        // Attach item
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                    else
                    {
                        m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID);
                    }
                }
            }


        }
Пример #33
0
 public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) {}
Пример #34
0
        /// <summary>
        /// This method is called if a given model avatar name can not be found. If the external
        /// file has already been loaded once, then control returns immediately. If not, then it
        /// looks for a default appearance file. This file contains XML definitions of zero or more named
        /// avatars, each avatar can specify zero or more "outfits". Each outfit is a collection
        /// of items that together, define a particular ensemble for the avatar. Each avatar should
        /// indicate which outfit is the default, and this outfit will be automatically worn. The
        /// other outfits are provided to allow "real" avatars a way to easily change their outfits.
        /// </summary>
        private bool CreateDefaultAvatars()
        {
            // Only load once
            if (m_defaultAvatarsLoaded)
            {
                return false;
            }

            m_log.DebugFormat("[RADMIN]: Creating default avatar entries");

            m_defaultAvatarsLoaded = true;

            // Load processing starts here...

            try
            {
                string defaultAppearanceFileName = null;

                //m_config may be null if RemoteAdmin configuration secition is missing or disabled in OpenSim.ini
                if (m_config != null)
                {
                    defaultAppearanceFileName = m_config.GetString("default_appearance", "default_appearance.xml");
                }

                if (File.Exists(defaultAppearanceFileName))
                {
                    XmlDocument doc = new XmlDocument();
                    string name     = "*unknown*";
                    string email    = "anon@anon";
                    uint   regionXLocation     = 1000;
                    uint   regionYLocation     = 1000;
                    string password   = UUID.Random().ToString(); // No requirement to sign-in.
                    UUID ID = UUID.Zero;
                    AvatarAppearance avatarAppearance;
                    XmlNodeList avatars;
                    XmlNodeList assets;
                    XmlNode perms = null;
                    bool include = false;
                    bool select  = false;

                    Scene scene = m_application.SceneManager.CurrentOrFirstScene;
                    IInventoryService inventoryService = scene.InventoryService;
                    IAssetService assetService = scene.AssetService;

                    doc.LoadXml(File.ReadAllText(defaultAppearanceFileName));

                    // Load up any included assets. Duplicates will be ignored
                    assets = doc.GetElementsByTagName("RequiredAsset");
                    foreach (XmlNode assetNode in assets)
                    {
                        AssetBase asset = new AssetBase(UUID.Random(), GetStringAttribute(assetNode, "name", ""), SByte.Parse(GetStringAttribute(assetNode, "type", "")), UUID.Zero.ToString());
                        asset.Description = GetStringAttribute(assetNode,"desc","");
                        asset.Local       = Boolean.Parse(GetStringAttribute(assetNode,"local",""));
                        asset.Temporary   = Boolean.Parse(GetStringAttribute(assetNode,"temporary",""));
                        asset.Data        = Convert.FromBase64String(assetNode.InnerText);
                        assetService.Store(asset);
                    }

                    avatars = doc.GetElementsByTagName("Avatar");

                    // The document may contain multiple avatars

                    foreach (XmlElement avatar in avatars)
                    {
                        m_log.DebugFormat("[RADMIN]: Loading appearance for {0}, gender = {1}",
                            GetStringAttribute(avatar,"name","?"), GetStringAttribute(avatar,"gender","?"));

                        // Create the user identified by the avatar entry

                        try
                        {
                            // Only the name value is mandatory
                            name   = GetStringAttribute(avatar,"name",name);
                            email  = GetStringAttribute(avatar,"email",email);
                            regionXLocation   = GetUnsignedAttribute(avatar,"regx",regionXLocation);
                            regionYLocation   = GetUnsignedAttribute(avatar,"regy",regionYLocation);
                            password = GetStringAttribute(avatar,"password",password);

                            string[] names = name.Split();
                            UUID scopeID = scene.RegionInfo.ScopeID;
                            UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, names[0], names[1]);
                            if (null == account)
                            {
                                account = CreateUser(scopeID, names[0], names[1], password, email);
                                if (null == account)
                                {
                                    m_log.ErrorFormat("[RADMIN]: Avatar {0} {1} was not created", names[0], names[1]);
                                    return false;
                                }
                            }

                            // Set home position

                            GridRegion home = scene.GridService.GetRegionByPosition(scopeID, 
                                (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize));
                            if (null == home) {
                                m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", names[0], names[1]);
                            } else {
                                scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
                                m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, names[0], names[1]);
                            }

                            ID = account.PrincipalID;

                            m_log.DebugFormat("[RADMIN]: User {0}[{1}] created or retrieved", name, ID);
                            include = true;
                        }
                        catch (Exception e)
                        {
                            m_log.DebugFormat("[RADMIN]: Error creating user {0} : {1}", name, e.Message);
                            include = false;
                        }

                        // OK, User has been created OK, now we can install the inventory.
                        // First retrieve the current inventory (the user may already exist)
                        // Note that althought he inventory is retrieved, the hierarchy has
                        // not been interpreted at all.

                        if (include)
                        {
                            // Setup for appearance processing
                            avatarAppearance = scene.AvatarService.GetAppearance(ID);
                            if (avatarAppearance == null)
                                avatarAppearance = new AvatarAppearance();

                            AvatarWearable[] wearables = avatarAppearance.Wearables;
                            for (int i=0; i<wearables.Length; i++)
                            {
                                wearables[i] = new AvatarWearable();
                            }

                            try
                            {
                                // m_log.DebugFormat("[RADMIN] {0} folders, {1} items in inventory",
                                //   uic.folders.Count, uic.items.Count);

                                InventoryFolderBase clothingFolder = inventoryService.GetFolderForType(ID, AssetType.Clothing);

                                // This should *never* be the case
                                if (clothingFolder == null || clothingFolder.Type != (short)AssetType.Clothing)
                                {
                                    clothingFolder = new InventoryFolderBase();
                                    clothingFolder.ID       = UUID.Random();
                                    clothingFolder.Name     = "Clothing";
                                    clothingFolder.Owner    = ID;
                                    clothingFolder.Type     = (short)AssetType.Clothing;
                                    clothingFolder.ParentID = inventoryService.GetRootFolder(ID).ID;
                                    clothingFolder.Version  = 1;
                                    inventoryService.AddFolder(clothingFolder);     // store base record
                                    m_log.ErrorFormat("[RADMIN]: Created clothing folder for {0}/{1}", name, ID);
                                }

                                // OK, now we have an inventory for the user, read in the outfits from the
                                // default appearance XMl file.

                                XmlNodeList outfits = avatar.GetElementsByTagName("Ensemble");
                                InventoryFolderBase extraFolder;
                                string outfitName;
                                UUID assetid;

                                foreach (XmlElement outfit in outfits)
                                {
                                    m_log.DebugFormat("[RADMIN]: Loading outfit {0} for {1}",
                                        GetStringAttribute(outfit,"name","?"), GetStringAttribute(avatar,"name","?"));

                                    outfitName   = GetStringAttribute(outfit,"name","");
                                    select  = (GetStringAttribute(outfit,"default","no") == "yes");

                                    // If the folder already exists, re-use it. The defaults may
                                    // change over time. Augment only.

                                    List<InventoryFolderBase> folders = inventoryService.GetFolderContent(ID, clothingFolder.ID).Folders;
                                    extraFolder = null;

                                    foreach (InventoryFolderBase folder in folders)
                                    {
                                    if (folder.Name == outfitName)
                                        {
                                            extraFolder = folder;
                                            break;
                                        }
                                    }

                                    // Otherwise, we must create the folder.
                                    if (extraFolder == null)
                                    {
                                        m_log.DebugFormat("[RADMIN]: Creating outfit folder {0} for {1}", outfitName, name);
                                        extraFolder          = new InventoryFolderBase();
                                        extraFolder.ID       = UUID.Random();
                                        extraFolder.Name     = outfitName;
                                        extraFolder.Owner    = ID;
                                        extraFolder.Type     = (short)AssetType.Clothing;
                                        extraFolder.Version  = 1;
                                        extraFolder.ParentID = clothingFolder.ID;
                                        inventoryService.AddFolder(extraFolder);
                                        m_log.DebugFormat("[RADMIN]: Adding outfile folder {0} to folder {1}", extraFolder.ID, clothingFolder.ID);
                                    }

                                    // Now get the pieces that make up the outfit
                                    XmlNodeList items = outfit.GetElementsByTagName("Item");

                                    foreach (XmlElement item in items)
                                    {
                                        assetid = UUID.Zero;
                                        XmlNodeList children = item.ChildNodes;
                                        foreach (XmlNode child in children)
                                        {
                                            switch (child.Name)
                                            {
                                                case "Permissions" :
                                                    m_log.DebugFormat("[RADMIN]: Permissions specified");
                                                    perms = child;
                                                    break;
                                                case "Asset" :
                                                    assetid = new UUID(child.InnerText);
                                                    break;
                                            }
                                        }

                                        InventoryItemBase inventoryItem = null;

                                        // Check if asset is in inventory already
                                        inventoryItem = null;
                                        List<InventoryItemBase> inventoryItems = inventoryService.GetFolderContent(ID, extraFolder.ID).Items;

                                        foreach (InventoryItemBase listItem in inventoryItems)
                                        {
                                            if (listItem.AssetID == assetid)
                                            {
                                                inventoryItem = listItem;
                                                break;
                                            }
                                        }

                                        // Create inventory item
                                        if (inventoryItem == null)
                                        {
                                            inventoryItem = new InventoryItemBase(UUID.Random(), ID);
                                            inventoryItem.Name = GetStringAttribute(item,"name","");
                                            inventoryItem.Description = GetStringAttribute(item,"desc","");
                                            inventoryItem.InvType = GetIntegerAttribute(item,"invtype",-1);
                                            inventoryItem.CreatorId = GetStringAttribute(item,"creatorid","");
                                            inventoryItem.CreatorIdAsUuid = (UUID)GetStringAttribute(item,"creatoruuid","");
                                            inventoryItem.CreatorData = GetStringAttribute(item, "creatordata", "");
                                            inventoryItem.NextPermissions = GetUnsignedAttribute(perms, "next", 0x7fffffff);
                                            inventoryItem.CurrentPermissions = GetUnsignedAttribute(perms,"current",0x7fffffff);
                                            inventoryItem.BasePermissions = GetUnsignedAttribute(perms,"base",0x7fffffff);
                                            inventoryItem.EveryOnePermissions = GetUnsignedAttribute(perms,"everyone",0x7fffffff);
                                            inventoryItem.GroupPermissions = GetUnsignedAttribute(perms,"group",0x7fffffff);
                                            inventoryItem.AssetType = GetIntegerAttribute(item,"assettype",-1);
                                            inventoryItem.AssetID = assetid; // associated asset
                                            inventoryItem.GroupID = (UUID)GetStringAttribute(item,"groupid","");
                                            inventoryItem.GroupOwned = (GetStringAttribute(item,"groupowned","false") == "true");
                                            inventoryItem.SalePrice = GetIntegerAttribute(item,"saleprice",0);
                                            inventoryItem.SaleType = (byte)GetIntegerAttribute(item,"saletype",0);
                                            inventoryItem.Flags = GetUnsignedAttribute(item,"flags",0);
                                            inventoryItem.CreationDate = GetIntegerAttribute(item,"creationdate",Util.UnixTimeSinceEpoch());
                                            inventoryItem.Folder = extraFolder.ID; // Parent folder

                                            m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(inventoryItem);
                                            m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", inventoryItem.ID, extraFolder.ID);
                                        }

                                        // Attach item, if attachpoint is specified
                                        int attachpoint = GetIntegerAttribute(item,"attachpoint",0);
                                        if (attachpoint != 0)
                                        {
                                            avatarAppearance.SetAttachment(attachpoint, inventoryItem.ID, inventoryItem.AssetID);
                                            m_log.DebugFormat("[RADMIN]: Attached {0}", inventoryItem.ID);
                                        }

                                        // Record whether or not the item is to be initially worn
                                        try
                                        {
                                        if (select && (GetStringAttribute(item, "wear", "false") == "true"))
                                            {
                                                avatarAppearance.Wearables[inventoryItem.Flags].Wear(inventoryItem.ID, inventoryItem.AssetID);
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            m_log.WarnFormat("[RADMIN]: Error wearing item {0} : {1}", inventoryItem.ID, e.Message);
                                        }
                                    } // foreach item in outfit
                                    m_log.DebugFormat("[RADMIN]: Outfit {0} load completed", outfitName);
                                } // foreach outfit
                                m_log.DebugFormat("[RADMIN]: Inventory update complete for {0}", name);
                                scene.AvatarService.SetAppearance(ID, avatarAppearance);
                            }
                            catch (Exception e)
                            {
                                m_log.WarnFormat("[RADMIN]: Inventory processing incomplete for user {0} : {1}",
                                    name, e.Message);
                            }
                        } // End of include
                    }
                    m_log.DebugFormat("[RADMIN]: Default avatar loading complete");
                }
                else
                {
                    m_log.DebugFormat("[RADMIN]: No default avatar information available");
                    return false;
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[RADMIN]: Exception whilst loading default avatars ; {0}", e.Message);
                return false;
            }

            return true;
        }
Пример #35
0
        private LSL_Key NpcCreate(
            string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent)
        {
            INPCModule module = World.RequestModuleInterface<INPCModule>();
            if (module != null)
            {
                AvatarAppearance appearance = null;

                UUID id;
                if (UUID.TryParse(notecard, out id))
                {
                    ScenePresence clonePresence = World.GetScenePresence(id);
                    if (clonePresence != null)
                        appearance = clonePresence.Appearance;
                }

                if (appearance == null)
                {
                    string appearanceSerialized = LoadNotecard(notecard);

                    if (appearanceSerialized != null)
                    {
                        OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
                        appearance = new AvatarAppearance();
                        appearance.Unpack(appearanceOsd);
                    }
                }

                if (appearance == null)
                    return new LSL_Key(UUID.Zero.ToString());

                UUID ownerID = UUID.Zero;
                if (owned)
                    ownerID = m_host.OwnerID;
                UUID x = module.CreateNPC(firstname,
                                          lastname,
                                          position,
                                          ownerID,
                                          senseAsAgent,
                                          World,
                                          appearance);

                return new LSL_Key(x.ToString());
            }

            return new LSL_Key(UUID.Zero.ToString());
        }
Пример #36
0
        public AvatarAppearance(AvatarAppearance appearance, bool copyWearables)
        {
            //            m_log.WarnFormat("[AVATAR APPEARANCE] create from an existing appearance");

            if (appearance == null)
            {
                m_serial = 1;
                m_owner = UUID.Zero;

                SetDefaultWearables();
                SetDefaultTexture();
                SetDefaultParams();
                SetHeight();

                m_attachments = new Dictionary<int, List<AvatarAttachment>>();

                return;
            }

            m_serial = appearance.Serial;
            m_owner = appearance.Owner;

            m_wearables = new AvatarWearable[AvatarWearable.MAX_WEARABLES];
            for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
                m_wearables[i] = new AvatarWearable();
            if (copyWearables && (appearance.Wearables != null))
            {
                for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
                    SetWearable(i, appearance.Wearables[i]);
            }

            m_texture = null;
            if (appearance.Texture != null)
            {
                byte[] tbytes = appearance.Texture.GetBytes();
                m_texture = new Primitive.TextureEntry(tbytes, 0, tbytes.Length);
            }

            m_visualparams = null;
            if (appearance.VisualParams != null)
                m_visualparams = (byte[])appearance.VisualParams.Clone();

            // Copy the attachment, force append mode since that ensures consistency
            m_attachments = new Dictionary<int, List<AvatarAttachment>>();
            foreach (AvatarAttachment attachment in appearance.GetAttachments())
                AppendAttachment(new AvatarAttachment(attachment));
        }
Пример #37
0
 public bool SetAppearance(UUID userID, AvatarAppearance appearance)
 {
     AvatarData avatar = new AvatarData(appearance);
     return SetAvatar(userID,avatar);
 }
Пример #38
0
        /// <summary>
        /// Unpack agent circuit data map into an AgentCiruitData object
        /// </summary>
        /// <param name="args"></param>
        public virtual void UnpackAgentCircuitData (OSDMap args)
        {
            if (args["agent_id"] != null)
                AgentID = args["agent_id"].AsUUID();
            if (args["caps_path"] != null)
                CapsPath = args["caps_path"].AsString();
            if (args["reallyischild"] != null)
                reallyischild = args["reallyischild"].AsBoolean ();
            if (args["child"] != null)
                child = args["child"].AsBoolean();
            if (args["circuit_code"] != null)
                UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
            if (args["secure_session_id"] != null)
                SecureSessionID = args["secure_session_id"].AsUUID();
            if (args["session_id"] != null)
                SessionID = args["session_id"].AsUUID();
            if (args["service_session_id"] != null)
                ServiceSessionID = args["service_session_id"].AsString ();
            if (args["client_ip"] != null)
                IPAddress = args["client_ip"].AsString ();
            if (args["first_name"] != null)
                firstname = args["first_name"].AsString ();
            if (args["last_name"] != null)
                lastname = args["last_name"].AsString ();

            if (args["start_pos"] != null)
                Vector3.TryParse(args["start_pos"].AsString(), out startpos);

            if (args["teleport_flags"] != null)
                teleportFlags = args["teleport_flags"].AsUInteger();

            // DEBUG ON
            //m_log.WarnFormat("[AGENTCIRCUITDATA] agentid={0}, child={1}, startpos={2}", AgentID, child, startpos.ToString());
            // DEBUG OFF

            try
            {
                // Unpack various appearance elements
                Appearance = new AvatarAppearance(AgentID);

                // Eventually this code should be deprecated, use full appearance
                // packing in packed_appearance
                if (args["appearance_serial"] != null)
                    Appearance.Serial = args["appearance_serial"].AsInteger();

                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
                {
                    Appearance.Unpack((OSDMap)args["packed_appearance"]);
                    // DEBUG ON
                    //m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance");
                    // DEBUG OFF
                }
                // DEBUG ON
                else
                    m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
                // DEBUG OFF
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}", e.ToString());
            }

            if (args.ContainsKey("otherInfo"))
                OtherInformation = (OSDMap)OSDParser.DeserializeLLSDXml(args["otherInfo"].AsString());

            ServiceURLs = new Dictionary<string, object> ();
            // Try parse the new way, OSDMap
            if (args.ContainsKey ("serviceurls") && args["serviceurls"] != null && (args["serviceurls"]).Type == OSDType.Map)
            {
                OSDMap urls = (OSDMap)(args["serviceurls"]);
                foreach (KeyValuePair<String, OSD> kvp in urls)
                {
                    ServiceURLs[kvp.Key] = kvp.Value.AsString ();
                    //System.Console.WriteLine("XXX " + kvp.Key + "=" + ServiceURLs[kvp.Key]);

                }
            }
        }
Пример #39
0
        /// <summary>
        /// Unpack agent circuit data map into an AgentCiruitData object
        /// </summary>
        /// <param name="args"></param>
        public void UnpackAgentCircuitData(OSDMap args)
        {
            if (args["agent_id"] != null)
            {
                AgentID = args["agent_id"].AsUUID();
            }
            if (args["caps_path"] != null)
            {
                CapsPath = args["caps_path"].AsString();
            }

            if (args["child"] != null)
            {
                child = args["child"].AsBoolean();
            }
            if (args["circuit_code"] != null)
            {
                UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
            }
            if (args["secure_session_id"] != null)
            {
                SecureSessionID = args["secure_session_id"].AsUUID();
            }
            if (args["session_id"] != null)
            {
                SessionID = args["session_id"].AsUUID();
            }
            if (args["service_session_id"] != null)
            {
                ServiceSessionID = args["service_session_id"].AsString();
            }
            if (args["client_ip"] != null)
            {
                IPAddress = args["client_ip"].AsString();
            }

            if (args["start_pos"] != null)
            {
                Vector3.TryParse(args["start_pos"].AsString(), out startpos);
            }

            if (args["teleport_flags"] != null)
            {
                teleportFlags = args["teleport_flags"].AsUInteger();
            }

            // DEBUG ON
            //m_log.WarnFormat("[AGENTCIRCUITDATA] agentid={0}, child={1}, startpos={2}", AgentID, child, startpos.ToString());
            // DEBUG OFF

            try
            {
                // Unpack various appearance elements
                Appearance = new AvatarAppearance(AgentID);

                // Eventually this code should be deprecated, use full appearance
                // packing in packed_appearance
                if (args["appearance_serial"] != null)
                {
                    Appearance.Serial = args["appearance_serial"].AsInteger();
                }

                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
                {
                    Appearance.Unpack((OSDMap)args["packed_appearance"]);
                    // DEBUG ON
                    //m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance");
                    // DEBUG OFF
                }
                // DEBUG ON
                else
                {
                    m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
                }
                // DEBUG OFF
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}", e.ToString());
            }

            if (args.ContainsKey("otherInfo"))
            {
                OtherInformation = (OSDMap)OSDParser.DeserializeLLSDXml(args["otherInfo"].AsString());
            }
        }