Exemple #1
0
        internal AvatarAppearance ToAppearance(OpenMetaverse.UUID owner)
        {
            AvatarAppearance app =
                new AvatarAppearance
                {
                    Owner = owner,
                    Serial = this.Serial,
                    VisualParams = this.VisualParams
                };

            List<AvatarWearable> wearables = new List<AvatarWearable>();

            for (int i = 0; i < AvatarWearable.MAX_WEARABLES && i < this.Wearables.Length; i++)
            {
                OpenMetaverse.UUID itemID = new OpenMetaverse.UUID(this.Wearables[i].ItemId);
                OpenMetaverse.UUID assetID = new OpenMetaverse.UUID(this.Wearables[i].AssetId);

                wearables.Add(new AvatarWearable(i, itemID, assetID));
            }

            app.SetWearables(wearables);

            var te = new OpenMetaverse.Primitive.TextureEntry(this.TextureEntry, 0, this.TextureEntry.Length);
            app.SetTextureEntries(te);

            app.SetHeight();

            return app;
        }
Exemple #2
0
        internal static PackedAppearance FromAppearance(AvatarAppearance avatarAppearance)
        {
            PackedAppearance app = new PackedAppearance
            {
                TextureEntry = avatarAppearance.Texture.GetBytes(),
                VisualParams = avatarAppearance.VisualParams,
                Wearables = PackedWearable.FromWearables(avatarAppearance.GetWearables()),
                Serial = avatarAppearance.Serial
            };

            return app;
        }
 public virtual void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
 {
     foreach (IUserDataPlugin plugin in m_plugins)
     {
         try
         {
             plugin.UpdateUserAppearance(user, appearance);
         }
         catch (Exception e)
         {
             m_log.ErrorFormat("[USERSTORAGE]: Unable to update user appearance {0} via {1} ({2})", user.ToString(), plugin.Name, e.ToString());
         }
     }
 }
        public UUID CreateAvatar(string firstName, string lastName, IScene scene, AvatarAppearance avatarApp,
                                 UUID creatorID, Vector3 startPos)
        {
            // Add the circuit data so they can login
            AgentCircuitData m_aCircuitData = new AgentCircuitData
            {
                IsChildAgent = false,
                CircuitCode  = (uint)Util.RandomClass.Next()
            };

            // Create the new bot data
            BotClientAPI m_character = new BotClientAPI(scene, m_aCircuitData)
            {
                Name = firstName + " " + lastName
            };

            m_aCircuitData.AgentID = m_character.AgentId;

            // Set up appearance
            var origOwner = avatarApp.Owner;

            avatarApp.Owner = m_character.AgentId;
            List <AvatarAttachment> attachments = avatarApp.GetAttachments();

            avatarApp.ClearAttachments();
            // get original attachments
            foreach (AvatarAttachment t in attachments)
            {
                InventoryItemBase item = scene.InventoryService.GetItem(origOwner, t.ItemID);
                if (item != null)
                {
                    item.ID     = UUID.Random();
                    item.Owner  = m_character.AgentId;
                    item.Folder = UUID.Zero;
                    scene.InventoryService.AddCacheItemAsync(item);
                    // Now fix the ItemID
                    avatarApp.SetAttachment(t.AttachPoint, item.ID, t.AssetID);
                }
            }

            scene.AuthenticateHandler.AgentCircuits.Add(m_character.CircuitCode, m_aCircuitData);
            // This adds them to the scene and sets them in world
            AddAndWaitUntilAgentIsAdded(scene, m_character);

            IScenePresence SP = scene.GetScenePresence(m_character.AgentId);

            if (SP == null)
            {
                return(UUID.Zero);       // Failed!
            }
            // set this as a NPC character
            SP.IsNpcAgent = true;

            IAvatarAppearanceModule appearance = SP.RequestModuleInterface <IAvatarAppearanceModule>();

            appearance.Appearance = avatarApp;
            appearance.InitialHasWearablesBeenSent = true;
            Bot bot = new Bot();

            bot.Initialize(SP, creatorID);
            try {
                SP.MakeRootAgent(startPos, false, true);
            } catch {
                MainConsole.Instance.ErrorFormat("[BotManager]: Error creating bot {0} as root agent!", m_character.AgentId);
            }
            // Move them
            SP.Teleport(startPos);

            foreach (var presence in scene.GetScenePresences())
            {
                presence.SceneViewer.QueuePresenceForUpdate(SP, PrimUpdateFlags.ForcedFullUpdate);
            }
            IAttachmentsModule attModule = SP.Scene.RequestModuleInterface <IAttachmentsModule>();

            if (attModule != null)
            {
                foreach (AvatarAttachment att in attachments)
                {
                    attModule.RezSingleAttachmentFromInventory(SP.ControllingClient, att.ItemID, att.AssetID, 0, true);
                }
            }

            // Save them in the bots list
            m_bots.Add(m_character.AgentId, bot);
            AddTagToBot(m_character.AgentId, "AllBots", bot.AvatarCreatorID);

            MainConsole.Instance.InfoFormat("[BotManager]: Added bot {0} to region {1}",
                                            m_character.Name, scene.RegionInfo.RegionName);

            // Return their UUID
            return(m_character.AgentId);
        }
        private void SetAppearanceAssets(UUID userID, ref AvatarAppearance appearance)
        {
            IInventoryService invService = m_scene.InventoryService;

            for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
            {
                for (int j = 0; j < appearance.Wearables[j].Count; j++)
                {
                    if (appearance.Wearables[i][j].ItemID == UUID.Zero)
                        continue;

                    // Ignore ruth's assets
                    if (appearance.Wearables[i][j].ItemID == AvatarWearable.DefaultWearables[i][j].ItemID)
                    {
                        //MainConsole.Instance.ErrorFormat(
                        //    "[AvatarFactory]: Found an asset for the default avatar, itemID {0}, wearable {1}, asset {2}" +
                        //    ", setting to default asset {3}.",
                        //    appearance.Wearables[i][j].ItemID, (WearableType)i, appearance.Wearables[i][j].AssetID,
                        //    AvatarWearable.DefaultWearables[i][j].AssetID);
                        appearance.Wearables[i].Add(appearance.Wearables[i][j].ItemID,
                                                    appearance.Wearables[i][j].AssetID);
                        continue;
                    }

                    InventoryItemBase baseItem = new InventoryItemBase(appearance.Wearables[i][j].ItemID, userID);
                    baseItem = invService.GetItem(baseItem);

                    if (baseItem != null)
                    {
                        if (baseItem.AssetType == (int) AssetType.Link)
                        {
                            baseItem = new InventoryItemBase(baseItem.AssetID, userID);
                            baseItem = invService.GetItem(baseItem);
                        }
                        appearance.Wearables[i].Add(baseItem.ID, baseItem.AssetID);
                    }
                    else
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[AvatarFactory]: Can't find inventory item {0} for {1}, setting to default",
                            appearance.Wearables[i][j].ItemID, (WearableType) i);

                        appearance.Wearables[i].RemoveItem(appearance.Wearables[i][j].ItemID);
                        appearance.Wearables[i].Add(AvatarWearable.DefaultWearables[i][j].ItemID,
                                                    AvatarWearable.DefaultWearables[i][j].AssetID);
                    }
                }
            }
        }
 private void LoadItems(OSDMap items, UUID OwnerID, InventoryFolderBase folderForAppearance, AvatarAppearance appearance, out List<InventoryItemBase> litems)
 {
     litems = new List<InventoryItemBase>();
     foreach (KeyValuePair<string, OSD> kvp in items)
     {
         string serialization = kvp.Value.AsString();
         InventoryItemBase item = OpenSim.Framework.Serialization.External.UserInventoryItemSerializer.Deserialize(serialization);
         m_log.Info("[AvatarArchive]: Loading item " + item.ID.ToString());
         UUID oldID = item.ID;
         item = GiveInventoryItem(item.CreatorIdAsUuid, OwnerID, item, folderForAppearance);
         litems.Add(item);
         FixItemIDs(oldID, item, appearance);
     }
 }
Exemple #7
0
        public LoginResponse Login(UUID AgentID, string Name, string authType, string passwd, string startLocation,
            string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP,
            Hashtable requestData)
        {
            LoginResponse response;
            UUID session = UUID.Random();
            UUID secureSession = UUID.Zero;

            MainConsole.Instance.InfoFormat(
                "[LLOGIN SERVICE]: Login request for {0} from {1} with user agent {2} starting in {3}",
                Name, clientIP.Address, clientVersion, startLocation);

            UserAccount account = AgentID != UUID.Zero
                                      ? m_UserAccountService.GetUserAccount(null, AgentID)
                                      : m_UserAccountService.GetUserAccount(null, Name);
            if (account == null && m_AllowAnonymousLogin)
            {
                m_UserAccountService.CreateUser(Name, passwd.StartsWith("$1$") ? passwd.Remove(0, 3) : passwd, "");
                account = m_UserAccountService.GetUserAccount(null, Name);
            }
            if (account == null)
            {
                MainConsole.Instance.InfoFormat("[LLOGIN SERVICE]: Login failed for user {0}: no account found", Name);
                return LLFailedLoginResponse.AccountProblem;
            }

            if (account.UserLevel < 0) //No allowing anyone less than 0
            {
                MainConsole.Instance.InfoFormat(
                    "[LLOGIN SERVICE]: Login failed for user {0}, reason: user is banned",
                    account.Name);
                return LLFailedLoginResponse.PermanentBannedProblem;
            }

            if (account.UserLevel < m_MinLoginLevel)
            {
                MainConsole.Instance.InfoFormat(
                    "[LLOGIN SERVICE]: Login failed for user {1}, reason: login is blocked for user level {0}",
                    account.UserLevel, account.Name);
                return LLFailedLoginResponse.LoginBlockedProblem;
            }

            IAgentInfo agent = null;
            IAgentConnector agentData = Framework.Utilities.DataManager.RequestPlugin<IAgentConnector>();
            if (agentData != null)
                agent = agentData.GetAgent(account.PrincipalID);
            if (agent == null)
            {
                agentData.CreateNewAgent(account.PrincipalID);
                agent = agentData.GetAgent(account.PrincipalID);
            }

            requestData["ip"] = clientIP.ToString();
            foreach (ILoginModule module in LoginModules)
            {
                object data;
                if ((response = module.Login(requestData, account, agent, authType, passwd, out data)) != null)
                {
                    MainConsole.Instance.InfoFormat(
                        "[LLOGIN SERVICE]: Login failed for user {1}, reason: {0}",
                        (data != null ? data.ToString() : (response is LLFailedLoginResponse) ? (response as LLFailedLoginResponse).Value : "Unknown"), account.Name);
                    return response;
                }
                if (data != null)
                    secureSession = (UUID) data; //TODO: NEED TO FIND BETTER WAY TO GET THIS DATA
            }

            try
            {
                string DisplayName = account.Name;
                AvatarAppearance avappearance = null;
                IProfileConnector profileData = Framework.Utilities.DataManager.RequestPlugin<IProfileConnector>();

                //
                // Get the user's inventory
                //
                if (m_RequireInventory && m_InventoryService == null)
                {
                    MainConsole.Instance.WarnFormat(
                        "[LLOGIN SERVICE]: Login failed for user {0}, reason: inventory service not set up",
                        account.Name);
                    return LLFailedLoginResponse.InventoryProblem;
                }
                List<InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
                if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel.Count == 0)))
                {
                    List<InventoryItemBase> defaultItems;
                    m_InventoryService.CreateUserInventory(account.PrincipalID, m_DefaultUserAvatarArchive == "",
                                                           out defaultItems);
                    inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
                    if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel.Count == 0)))
                    {
                        MainConsole.Instance.InfoFormat(
                            "[LLOGIN SERVICE]: Login failed for user {0}, reason: unable to retrieve user inventory",
                            account.Name);
                        return LLFailedLoginResponse.InventoryProblem;
                    }
                    if (defaultItems.Count > 0)
                    {
                        avappearance = new AvatarAppearance(account.PrincipalID);
                        avappearance.SetWearable((int)WearableType.Shape,
                                                 new AvatarWearable(defaultItems[0].ID, defaultItems[0].AssetID));
                        avappearance.SetWearable((int)WearableType.Skin,
                                                 new AvatarWearable(defaultItems[1].ID, defaultItems[1].AssetID));
                        avappearance.SetWearable((int)WearableType.Hair,
                                                 new AvatarWearable(defaultItems[2].ID, defaultItems[2].AssetID));
                        avappearance.SetWearable((int)WearableType.Eyes,
                                                 new AvatarWearable(defaultItems[3].ID, defaultItems[3].AssetID));
                        avappearance.SetWearable((int)WearableType.Shirt,
                                                 new AvatarWearable(defaultItems[4].ID, defaultItems[4].AssetID));
                        avappearance.SetWearable((int)WearableType.Pants,
                                                 new AvatarWearable(defaultItems[5].ID, defaultItems[5].AssetID));
                        m_AvatarService.SetAppearance(account.PrincipalID, avappearance);
                    }
                }

                if (profileData != null)
                {
                    IUserProfileInfo UPI = profileData.GetUserProfile(account.PrincipalID);
                    if (UPI == null)
                    {
                        profileData.CreateNewProfile(account.PrincipalID);
                        UPI = profileData.GetUserProfile(account.PrincipalID);
                        UPI.AArchiveName = m_DefaultUserAvatarArchive;
                        UPI.IsNewUser = true;
                        //profileData.UpdateUserProfile(UPI); //It gets hit later by the next thing
                    }
                    //Find which is set, if any
                    string archiveName = (UPI.AArchiveName != "" && UPI.AArchiveName != " ")
                                             ? UPI.AArchiveName
                                             : m_DefaultUserAvatarArchive;
                    if (UPI.IsNewUser && archiveName != "")
                    {
                        AvatarArchive arch = m_ArchiveService.LoadAvatarArchive(archiveName, account.PrincipalID);
                        UPI.AArchiveName = "";
                        if (arch != null)
                        {
                            avappearance = arch.Appearance;
                            m_AvatarService.SetAppearance(account.PrincipalID, avappearance);
                            //Must reload this, as we created a new folder
                            inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
                        }
                    }
                    if (UPI.IsNewUser)
                    {
                        UPI.IsNewUser = false;
                        profileData.UpdateUserProfile(UPI);
                    }
                    if (UPI.DisplayName != "")
                        DisplayName = UPI.DisplayName;
                }

                // Get active gestures
                List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(account.PrincipalID);
                //MainConsole.Instance.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count);

                //Now get the logged in status, then below make sure to kill the previous agent if we crashed before
                UserInfo guinfo = m_agentInfoService.GetUserInfo(account.PrincipalID.ToString());
                //
                // Clear out any existing CAPS the user may have
                //
                if (m_CapsService != null)
                {
                    IAgentProcessing agentProcessor = m_registry.RequestModuleInterface<IAgentProcessing>();
                    if (agentProcessor != null)
                    {
                        IClientCapsService clientCaps = m_CapsService.GetClientCapsService(account.PrincipalID);
                        if (clientCaps != null)
                        {
                            IRegionClientCapsService rootRegionCaps = clientCaps.GetRootCapsService();
                            if (rootRegionCaps != null)
                                agentProcessor.LogoutAgent(rootRegionCaps, !m_AllowDuplicateLogin);
                        }
                    }
                    else
                        m_CapsService.RemoveCAPS(account.PrincipalID);
                }

                //
                // Change Online status and get the home region
                //
                GridRegion home = null;
                if (guinfo != null && (guinfo.HomeRegionID != UUID.Zero) && m_GridService != null)
                    home = m_GridService.GetRegionByUUID(account.AllScopeIDs, guinfo.HomeRegionID);

                if (guinfo == null || guinfo.HomeRegionID == UUID.Zero) //Give them a default home and last
                {
                    if (guinfo == null)
                        guinfo = new UserInfo {UserID = account.PrincipalID.ToString()};
                    GridRegion DefaultRegion = null, FallbackRegion = null, SafeRegion = null;
                    if (m_GridService != null)
                    {
                        if (m_DefaultHomeRegion != "")
                        {
                            DefaultRegion = m_GridService.GetRegionByName(account.AllScopeIDs, m_DefaultHomeRegion);
                            if (DefaultRegion != null)
                                guinfo.HomeRegionID = guinfo.CurrentRegionID = DefaultRegion.RegionID;
                        }
                        if (guinfo.HomeRegionID == UUID.Zero)
                        {
                            List<GridRegion> DefaultRegions = m_GridService.GetDefaultRegions(account.AllScopeIDs);
                            DefaultRegion = DefaultRegions.Count == 0 ? null : DefaultRegions[0];

                            if (DefaultRegion != null)
                                guinfo.HomeRegionID = guinfo.CurrentRegionID = DefaultRegion.RegionID;

                            if (guinfo.HomeRegionID == UUID.Zero)
                            {
                                List<GridRegion> Fallback = m_GridService.GetFallbackRegions(account.AllScopeIDs, 0, 0);
                                FallbackRegion = Fallback.Count == 0 ? null : Fallback[0];

                                if (FallbackRegion != null)
                                    guinfo.HomeRegionID = guinfo.CurrentRegionID = FallbackRegion.RegionID;

                                if (guinfo.HomeRegionID == UUID.Zero)
                                {
                                    List<GridRegion> Safe = m_GridService.GetSafeRegions(account.AllScopeIDs, 0, 0);
                                    SafeRegion = Safe.Count == 0 ? null : Safe[0];

                                    if (SafeRegion != null)
                                        guinfo.HomeRegionID = guinfo.CurrentRegionID = SafeRegion.RegionID;
                                }
                            }
                        }
                    }

                    guinfo.CurrentPosition = guinfo.HomePosition = new Vector3(128, 128, 25);
                    guinfo.HomeLookAt = guinfo.CurrentLookAt = new Vector3(0, 0, 0);

                    m_agentInfoService.SetHomePosition(guinfo.UserID, guinfo.HomeRegionID, guinfo.HomePosition,
                                                       guinfo.HomeLookAt);

                    MainConsole.Instance.Info("[LLLoginService]: User did not have a home, set to " +
                                              (guinfo.HomeRegionID == UUID.Zero ? "(no region found)" : guinfo.HomeRegionID.ToString()));
                }

                //
                // Find the destination region/grid
                //
                string where = string.Empty;
                Vector3 position = Vector3.Zero;
                Vector3 lookAt = Vector3.Zero;
                TeleportFlags tpFlags = TeleportFlags.ViaLogin;
                GridRegion destination = FindDestination(account, guinfo, session, startLocation, home, out tpFlags,
                                                         out where, out position, out lookAt);
                if (destination == null)
                {
                    MainConsole.Instance.InfoFormat(
                        "[LLOGIN SERVICE]: Login failed for user {0}, reason: destination not found", account.Name);
                    return LLFailedLoginResponse.DeadRegionProblem;
                }

                #region Appearance

                //
                // Get the avatar
                //
                if (m_AvatarService != null)
                {
                    bool loadedArchive;
                    avappearance = m_AvatarService.GetAndEnsureAppearance(account.PrincipalID, m_DefaultUserAvatarArchive, out loadedArchive);
                    if (loadedArchive)
                        //Must reload this, as we created a new folder
                        inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
                }
                else
                    avappearance = new AvatarAppearance(account.PrincipalID);

                if ((m_forceUserToWearFolderName != "") && (m_forceUserToWearFolderOwnerUUID.Length == 36))
                {
                    UUID userThatOwnersFolder;
                    if (UUID.TryParse(m_forceUserToWearFolderOwnerUUID, out userThatOwnersFolder))
                    {
                        avappearance = WearFolder(avappearance, account.PrincipalID, userThatOwnersFolder);
                    }
                }

                //Makes sure that all links are properly placed in the current outfit folder for v2 viewers
                FixCurrentOutFitFolder(account.PrincipalID, ref avappearance);

                #endregion

                List<UUID> friendsToInform = new List<UUID>();
                if (m_FriendsService != null)
                    friendsToInform = m_FriendsService.GetFriendOnlineStatuses(account.PrincipalID, true);

                //
                // Instantiate/get the simulation interface and launch an agent at the destination
                //
                string reason = "", seedCap = "";
                AgentCircuitData aCircuit = LaunchAgentAtGrid(destination, tpFlags, account, session,
                                                              secureSession, position, where,
                                                              clientIP, friendsToInform, out where, out reason, out seedCap,
                                                              out destination);

                if (aCircuit == null)
                {
                    MainConsole.Instance.InfoFormat("[LLOGIN SERVICE]: Login failed for user {1}, reason: {0}", reason,
                                                    account.Name);
                    return new LLFailedLoginResponse(LoginResponseEnum.InternalError, reason, false);
                }

                // Get Friends list
                List<FriendInfo> friendsList = new List<FriendInfo>();
                if (m_FriendsService != null)
                    friendsList = m_FriendsService.GetFriends(account.PrincipalID);

                //Set them as logged in now, they are ready, and fire the logged in event now, as we're all done
                m_agentInfoService.SetLastPosition(account.PrincipalID.ToString(), destination.RegionID, position,
                                                   lookAt, destination.ServerURI);
                m_agentInfoService.SetLoggedIn(account.PrincipalID.ToString(), true, destination.RegionID,
                                               destination.ServerURI);
                m_agentInfoService.FireUserStatusChangeEvent(account.PrincipalID.ToString(), true, destination.RegionID);

                //
                // Finally, fill out the response and return it
                //
                string MaturityRating = "A";
                string MaxMaturity = "A";
                if (agent != null)
                {
                    MaturityRating = agent.MaturityRating == 0
                                         ? "P"
                                         : agent.MaturityRating == 1 ? "M" : "A";
                    MaxMaturity = agent.MaxMaturity == 0
                                      ? "P"
                                      : agent.MaxMaturity == 1 ? "M" : "A";
                }

                ArrayList eventNotifications = new ArrayList();
                BuildEventNotifications(account.PrincipalID, ref eventNotifications);

                if (m_FriendsService != null)
                    m_FriendsService.SendFriendOnlineStatuses(account.PrincipalID, true);

                response = new LLLoginResponse(account, aCircuit, guinfo, destination, inventorySkel,
                                               friendsList.ToArray(), m_InventoryService, m_LibraryService,
                                               where, startLocation, position, lookAt, gestures, home, clientIP,
                                               MaxMaturity, MaturityRating,
                                               eventCategories, eventNotifications, classifiedCategories, seedCap,
                                               m_config, DisplayName, avappearance.Serial.ToString(), m_registry.RequestModuleInterface<IGridInfo>());

                MainConsole.Instance.InfoFormat(
                    "[LLOGIN SERVICE]: All clear. Sending login response to client to login to region " +
                    destination.RegionName + ", tried to login to " + startLocation + " at " + position.ToString() + ".");
                return response;
            }
            catch (Exception e)
            {
                MainConsole.Instance.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} : {1}", Name, e);
                if (account != null)
                {
                    //Revert their logged in status if we got that far
                    m_agentInfoService.SetLoggedIn(account.PrincipalID.ToString(), false, UUID.Zero, "");
                }
                return LLFailedLoginResponse.InternalError;
            }
        }
Exemple #8
0
        public AvatarAppearance BakeAppearance(UUID agentID, int cof_version)
        {
            AvatarAppearance appearance = m_avatarService.GetAppearance(agentID);

            if (appearance == null)
            {
                MainConsole.Instance.Error("[ServerSide appearance]: Unable to retrieve avatar appearance for bake!");
                return(new AvatarAppearance());
            }

            List <BakeType>     pendingBakes = new List <BakeType> ();
            InventoryFolderBase cof          = m_inventoryService.GetFolderForType(agentID, InventoryType.Unknown, FolderType.CurrentOutfit);

            if (cof.Version < cof_version)
            {
                int i = 0;
                while (i < 10)
                {
                    cof = m_inventoryService.GetFolderForType(agentID, InventoryType.Unknown, FolderType.CurrentOutfit);
                    System.Threading.Thread.Sleep(100);
                    if (cof.Version >= cof_version)
                    {
                        break;
                    }
                    i++;
                }
            }

            List <InventoryItemBase> items = m_inventoryService.GetFolderItems(agentID, cof.ID);

            foreach (InventoryItemBase itm in items)
            {
                MainConsole.Instance.Info("[ServerSide appearance]: Baking " + itm.Name);
            }

            for (int i = 0; i < textures.Length; i++)
            {
                textures [i] = new TextureData();
            }

            WearableData alphaWearable  = null;
            List <UUID>  currentItemIDs = new List <UUID> ();

            foreach (InventoryItemBase itm in items)
            {
                if (itm.AssetType == (int)AssetType.Link)
                {
                    UUID assetID = m_inventoryService.GetItemAssetID(agentID, itm.AssetID);
                    if (appearance.Wearables.Any((w) => w.GetItem(assetID) != UUID.Zero))
                    {
                        currentItemIDs.Add(assetID);
                        //if (m_lastInventoryItemIDs.Contains(assetID))
                        //    continue;
                        WearableData wearable = new WearableData();
                        AssetBase    asset    = m_assetService.Get(assetID.ToString());
                        if (asset != null && asset.TypeAsset != AssetType.Object)
                        {
                            var assetData = new byte [asset.Data.Length];
                            asset.Data.CopyTo(assetData, 0);
                            asset.Dispose();
                            wearable.Asset = new AssetClothing(assetID, assetData);
                            if (wearable.Asset.Decode())
                            {
                                wearable.AssetID      = assetID;
                                wearable.AssetType    = wearable.Asset.AssetType;
                                wearable.WearableType = wearable.Asset.WearableType;
                                wearable.ItemID       = itm.AssetID;
                                if (wearable.WearableType == WearableType.Alpha)
                                {
                                    alphaWearable = wearable;
                                    continue;
                                }
                                AppearanceManager.DecodeWearableParams(wearable, ref textures);
                            }
                        }
                        if (asset != null)  // have asset but not an object
                        {
                            asset.Dispose();
                        }
                    }
                }
            }

            /*foreach (UUID id in m_lastInventoryItemIDs)
             * {
             *  if (!currentItemIDs.Contains(id))
             *  {
             *      OpenMetaverse.AppearanceManager.WearableData wearable = new OpenMetaverse.AppearanceManager.WearableData();
             *      AssetBase asset = m_assetService.Get(id.ToString());
             *      if (asset != null && asset.TypeAsset != AssetType.Object)
             *      {
             *          wearable.Asset = new AssetClothing(id, asset.Data);
             *          if (wearable.Asset.Decode())
             *          {
             *              foreach (KeyValuePair<AvatarTextureIndex, UUID> entry in wearable.Asset.Textures)
             *              {
             *                  int i = (int)entry.Key;
             *
             *                  textures[i].Texture = null;
             *                  textures[i].TextureID = UUID.Zero;
             *              }
             *          }
             *      }
             *  }
             * }*/
            //m_lastInventoryItemIDs = currentItemIDs;
            for (int i = 0; i < textures.Length; i++)
            {
                /*if (textures[i].TextureID == UUID.Zero)
                 *  continue;
                 * if (textures[i].Texture != null)
                 *  continue;*/
                AssetBase asset = m_assetService.Get(textures [i].TextureID.ToString());
                if (asset != null)
                {
                    var assetData = new byte [asset.Data.Length];
                    asset.Data.CopyTo(assetData, 0);
                    asset.Dispose();
                    textures [i].Texture = new AssetTexture(textures [i].TextureID, assetData);
                    textures [i].Texture.Decode();
                }
            }

            for (int bakedIndex = 0; bakedIndex < AppearanceManager.BAKED_TEXTURE_COUNT; bakedIndex++)
            {
                AvatarTextureIndex textureIndex = AppearanceManager.BakeTypeToAgentTextureIndex((BakeType)bakedIndex);

                if (textures [(int)textureIndex].TextureID == UUID.Zero)
                {
                    // If this is the skirt layer and we're not wearing a skirt then skip it
                    if (bakedIndex == (int)BakeType.Skirt && appearance.Wearables [(int)WearableType.Skirt].Count == 0)
                    {
                        continue;
                    }

                    pendingBakes.Add((BakeType)bakedIndex);
                }
            }

            int         start      = Environment.TickCount;
            List <UUID> newBakeIDs = new List <UUID> ();

            foreach (BakeType bakeType in pendingBakes)
            {
                UUID assetID = UUID.Zero;
                List <AvatarTextureIndex> textureIndices = AppearanceManager.BakeTypeToTextures(bakeType);
                Baker oven = new Baker(bakeType);

                for (int i = 0; i < textureIndices.Count; i++)
                {
                    int         textureIndex = (int)textureIndices [i];
                    TextureData texture      = textures [textureIndex];
                    texture.TextureIndex = (AvatarTextureIndex)textureIndex;
                    if (alphaWearable != null)
                    {
                        if (alphaWearable.Asset.Textures.ContainsKey(texture.TextureIndex) &&
                            alphaWearable.Asset.Textures [texture.TextureIndex] != UUID.Parse("5748decc-f629-461c-9a36-a35a221fe21f"))
                        {
                            assetID = alphaWearable.Asset.Textures [texture.TextureIndex];
                            goto bake_complete;
                        }
                    }

                    oven.AddTexture(texture);
                }

                oven.Bake();
                byte []   assetData     = oven.BakedTexture.AssetData;
                AssetBase newBakedAsset = new AssetBase(UUID.Random());
                newBakedAsset.Data      = assetData;
                newBakedAsset.TypeAsset = AssetType.Texture;
                newBakedAsset.Name      = "ServerSideAppearance Texture";
                newBakedAsset.Flags     = AssetFlags.Deletable | AssetFlags.Collectable | AssetFlags.Rewritable | AssetFlags.Temporary;

                var faceTextureID = appearance.Texture.FaceTextures [(int)AppearanceManager.BakeTypeToAgentTextureIndex(bakeType)].TextureID;
                if (faceTextureID != UUID.Zero)
                {
                    try {
                        m_assetService.Delete(faceTextureID);
                    } catch {
                        MainConsole.Instance.ErrorFormat("[Serverside apperance]: Unable to delete asset {0} during bake", faceTextureID);
                    }
                }
                assetID = m_assetService.Store(newBakedAsset);

bake_complete:
                newBakeIDs.Add(assetID);
                MainConsole.Instance.WarnFormat("[ServerSide appearance]: Baked {0}", assetID);
                int place = (int)AppearanceManager.BakeTypeToAgentTextureIndex(bakeType);
                appearance.Texture.FaceTextures [place].TextureID = assetID;
            }

            MainConsole.Instance.ErrorFormat("[ServerSide appearance]: Baking took {0} ms", (Environment.TickCount - start));

            appearance.Serial = cof_version + 1;
            cof = m_inventoryService.GetFolderForType(agentID, InventoryType.Unknown, FolderType.CurrentOutfit);
            if (cof.Version > cof_version)
            {
                // it changed during the baking... kill it with fire!
                return(null);
            }

            m_avatarService.SetAppearance(agentID, appearance);
            return(appearance);
        }
 protected bool TryFindGridRegionForAgentLogin(List<GridRegion> regions, UserAccount account,
     AvatarAppearance appearance, UUID session, UUID secureSession, uint circuitCode, Vector3 position,
     IPEndPoint clientIP, AgentCircuitData aCircuit, out GridRegion destination)
 {
     foreach (GridRegion r in regions)
     {
         string reason;
         bool success = LaunchAgentDirectly(r, ref aCircuit, out reason);
         if (success)
         {
             aCircuit = MakeAgent(r, account, appearance, session, secureSession, circuitCode, position, clientIP);
             destination = r;
             return true;
         }
         else
             m_GridService.SetRegionUnsafe(r.RegionID);
     }
     destination = null;
     return false;
 }
        public bool SetAppearance(UUID principalID, AvatarAppearance appearance)
        {
            AvatarData avatar = new AvatarData(appearance);

            return(SetAvatar(principalID, avatar));
        }
 public virtual void AddOrUpdateBotOutfit(UUID uuid, string outfitName, AvatarAppearance appearance)
 {
     m_storage.AddOrUpdateBotOutfit(uuid, outfitName, appearance);
 }
Exemple #12
0
        public AvatarAppearance LoadAvatarArchive(string FileName, string Name)
        {
            UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, Name);

            MainConsole.Instance.Info("[AvatarArchive] Loading archive from " + FileName);
            if (account == null)
            {
                MainConsole.Instance.Error("[AvatarArchive] User not found!");
                return(null);
            }

            StreamReader reader = new StreamReader(FileName);
            string       file   = reader.ReadToEnd();

            reader.Close();
            reader.Dispose();

            IScenePresence SP      = null;
            SceneManager   manager = m_registry.RequestModuleInterface <SceneManager>();

            if (manager != null)
            {
                foreach (IScene scene in manager.Scenes)
                {
                    if (scene.TryGetScenePresence(account.PrincipalID, out SP))
                    {
                        break;
                    }
                }
                if (SP == null)
                {
                    return(null); //Bad people!
                }
            }

            if (SP != null)
            {
                SP.ControllingClient.SendAlertMessage("Appearance loading in progress...");
            }

            string FolderNameToLoadInto = "";

            OSDMap map = ((OSDMap)OSDParser.DeserializeLLSDXml(file));

            OSDMap assetsMap = ((OSDMap)map["Assets"]);
            OSDMap itemsMap  = ((OSDMap)map["Items"]);
            OSDMap bodyMap   = ((OSDMap)map["Body"]);

            AvatarAppearance appearance = ConvertXMLToAvatarAppearance(bodyMap, out FolderNameToLoadInto);

            appearance.Owner = account.PrincipalID;

            List <InventoryItemBase> items = new List <InventoryItemBase>();

            InventoryFolderBase AppearanceFolder = InventoryService.GetFolderForType(account.PrincipalID,
                                                                                     InventoryType.Wearable,
                                                                                     AssetType.Clothing);

            InventoryFolderBase folderForAppearance
                = new InventoryFolderBase(
                      UUID.Random(), FolderNameToLoadInto, account.PrincipalID,
                      -1, AppearanceFolder.ID, 1);

            InventoryService.AddFolder(folderForAppearance);

            folderForAppearance = InventoryService.GetFolder(folderForAppearance);

            try
            {
                LoadAssets(assetsMap);
                appearance = CopyWearablesAndAttachments(account.PrincipalID, UUID.Zero, appearance, folderForAppearance);
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[AvatarArchiver]: Error loading assets and items, " + ex);
            }



            //Now update the client about the new items
            if (SP != null)
            {
                SP.ControllingClient.SendBulkUpdateInventory(folderForAppearance);
                foreach (InventoryItemBase itemCopy in items)
                {
                    if (itemCopy == null)
                    {
                        SP.ControllingClient.SendAgentAlertMessage("Can't find item to give. Nothing given.", false);
                        continue;
                    }
                    if (!SP.IsChildAgent)
                    {
                        SP.ControllingClient.SendBulkUpdateInventory(itemCopy);
                    }
                }
            }
            MainConsole.Instance.Info("[AvatarArchive] Loaded archive from " + FileName);
            return(appearance);
        }
Exemple #13
0
        public UUID CreateNPC(string firstname, string lastname,
                              Vector3 position, UUID agentID, UUID owner, bool senseAsAgent, Scene scene,
                              AvatarAppearance appearance)
        {
            NPCAvatar npcAvatar = null;

            try
            {
                if (agentID == UUID.Zero)
                {
                    npcAvatar = new NPCAvatar(firstname, lastname, position,
                                              owner, senseAsAgent, scene);
                }
                else
                {
                    npcAvatar = new NPCAvatar(firstname, lastname, agentID, position,
                                              owner, senseAsAgent, scene);
                }
            }
            catch (Exception e)
            {
                m_log.Info("[NPC MODULE]: exception creating NPC avatar: " + e.ToString());
                return(UUID.Zero);
            }

            npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
                                                                int.MaxValue);

            m_log.DebugFormat(
                "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
                firstname, lastname, npcAvatar.AgentId, owner,
                senseAsAgent, position, scene.RegionInfo.RegionName);

            AgentCircuitData acd = new AgentCircuitData();

            acd.AgentID     = npcAvatar.AgentId;
            acd.firstname   = firstname;
            acd.lastname    = lastname;
            acd.ServiceURLs = new Dictionary <string, object>();

            AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
                                                                  true);

            acd.Appearance = npcAppearance;

            /*
             * for (int i = 0;
             *      i < acd.Appearance.Texture.FaceTextures.Length; i++)
             * {
             *  m_log.DebugFormat(
             *          "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
             *          acd.AgentID, i,
             *          acd.Appearance.Texture.FaceTextures[i]);
             * }
             */

            lock (m_avatars)
            {
                scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
                                                        acd);
                scene.AddNewAgent(npcAvatar, PresenceType.Npc);

                ScenePresence sp;
                if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
                {
                    /*
                     * m_log.DebugFormat(
                     *      "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}",
                     *      sp.Name, sp.UUID);
                     */

                    sp.CompleteMovement(npcAvatar, false);
                    m_avatars.Add(npcAvatar.AgentId, npcAvatar);
                    m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);

                    return(npcAvatar.AgentId);
                }
                else
                {
                    m_log.WarnFormat(
                        "[NPC MODULE]: Could not find scene presence for NPC {0} {1}",
                        sp.Name, sp.UUID);

                    return(UUID.Zero);
                }
            }
        }
Exemple #14
0
        protected void HandleSaveAvatarArchive(string[] cmdparams)
        {
            if (cmdparams.Length != 7)
            {
                MainConsole.Instance.Info("[AvatarArchive] Not enough parameters!");
            }
            UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, cmdparams[3] + " " + cmdparams[4]);

            if (account == null)
            {
                MainConsole.Instance.Error("[AvatarArchive] User not found!");
                return;
            }

            IScenePresence SP      = null;
            SceneManager   manager = m_registry.RequestModuleInterface <SceneManager>();

            if (manager != null)
            {
                foreach (IScene scene in manager.Scenes)
                {
                    if (scene.TryGetScenePresence(account.PrincipalID, out SP))
                    {
                        break;
                    }
                }
                if (SP == null)
                {
                    return; //Bad people!
                }
            }

            if (SP != null)
            {
                SP.ControllingClient.SendAlertMessage("Appearance saving in progress...");
            }

            AvatarAppearance appearance = AvatarService.GetAppearance(SP.UUID);

            if (appearance == null)
            {
                IAvatarAppearanceModule appearancemod = SP.RequestModuleInterface <IAvatarAppearanceModule>();
                appearance = appearancemod.Appearance;
            }
            StreamWriter writer = new StreamWriter(cmdparams[5], false);
            OSDMap       map    = new OSDMap();
            OSDMap       body   = new OSDMap();
            OSDMap       assets = new OSDMap();
            OSDMap       items  = new OSDMap();

            body = appearance.Pack();
            body.Add("FolderName", OSD.FromString(cmdparams[6]));

            foreach (AvatarWearable wear in appearance.Wearables)
            {
                for (int i = 0; i < wear.Count; i++)
                {
                    WearableItem w = wear[i];
                    if (w.AssetID != UUID.Zero)
                    {
                        SaveItem(w.ItemID, items, assets);
                        SaveAsset(w.AssetID, assets);
                    }
                }
            }
            List <AvatarAttachment> attachments = appearance.GetAttachments();

#if (!ISWIN)
            foreach (AvatarAttachment a in attachments)
            {
                if (a.AssetID != UUID.Zero)
                {
                    SaveItem(a.ItemID, items, assets);
                    SaveAsset(a.AssetID, assets);
                }
            }
#else
            foreach (AvatarAttachment a in attachments.Where(a => a.AssetID != UUID.Zero))
            {
                SaveItem(a.ItemID, items, assets);
                SaveAsset(a.AssetID, assets);
            }
#endif
            map.Add("Body", body);
            map.Add("Assets", assets);
            map.Add("Items", items);
            //Write the map
            writer.Write(OSDParser.SerializeLLSDXmlString(map));
            writer.Close();
            writer.Dispose();
            MainConsole.Instance.Info("[AvatarArchive] Saved archive to " + cmdparams[5]);
        }
Exemple #15
0
        private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance, InventoryFolderBase destinationFolder)
        {
            if (destinationFolder == null)
            {
                throw new Exception("Cannot locate folder(s)");
            }


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

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

                        if (item != null)
                        {
                            InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination)
                            {
                                Name                = item.Name,
                                Description         = item.Description,
                                InvType             = item.InvType,
                                CreatorId           = item.CreatorId,
                                CreatorData         = item.CreatorData,
                                CreatorIdAsUuid     = item.CreatorIdAsUuid,
                                NextPermissions     = item.NextPermissions,
                                CurrentPermissions  = item.CurrentPermissions,
                                BasePermissions     = item.BasePermissions,
                                EveryOnePermissions = item.EveryOnePermissions,
                                GroupPermissions    = item.GroupPermissions,
                                AssetType           = item.AssetType,
                                AssetID             = item.AssetID,
                                GroupID             = item.GroupID,
                                GroupOwned          = item.GroupOwned,
                                SalePrice           = item.SalePrice,
                                SaleType            = item.SaleType,
                                Flags               = item.Flags,
                                CreationDate        = item.CreationDate,
                                Folder              = destinationFolder.ID
                            };
                            if (InventoryService != null)
                            {
                                InventoryService.AddItem(destinationItem);
                            }
                            MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}",
                                                             destinationItem.ID, destinationFolder.ID);

                            // Wear item
                            AvatarWearable newWearable = new AvatarWearable();
                            newWearable.Wear(destinationItem.ID, wearable[ii].AssetID);
                            avatarAppearance.SetWearable(i, newWearable);
                        }
                        else
                        {
                            MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}",
                                                            wearable[ii].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)
                        {
                            Name                = item.Name,
                            Description         = item.Description,
                            InvType             = item.InvType,
                            CreatorId           = item.CreatorId,
                            CreatorData         = item.CreatorData,
                            CreatorIdAsUuid     = item.CreatorIdAsUuid,
                            NextPermissions     = item.NextPermissions,
                            CurrentPermissions  = item.CurrentPermissions,
                            BasePermissions     = item.BasePermissions,
                            EveryOnePermissions = item.EveryOnePermissions,
                            GroupPermissions    = item.GroupPermissions,
                            AssetType           = item.AssetType,
                            AssetID             = item.AssetID,
                            GroupID             = item.GroupID,
                            GroupOwned          = item.GroupOwned,
                            SalePrice           = item.SalePrice,
                            SaleType            = item.SaleType,
                            Flags               = item.Flags,
                            CreationDate        = item.CreationDate,
                            Folder              = destinationFolder.ID
                        };
                        if (InventoryService != null)
                        {
                            InventoryService.AddItem(destinationItem);
                        }
                        MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);

                        // Attach item
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                    else
                    {
                        MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID);
                    }
                }
            }
            return(avatarAppearance);
        }
 public void UpdateDatabase(UUID user, AvatarAppearance appearance)
 {
     m_scene.CommsManager.AvatarService.UpdateUserAppearance(user, appearance);
 }
Exemple #17
0
 public bool SetAppearance(UUID principalID, AvatarAppearance appearance)
 {
     AvatarData avatar = new AvatarData(appearance);
     return SetAvatar(principalID, avatar);
 }
 private AvatarAppearance ConvertXMLToAvatarAppearance(OSDMap map)
 {
     AvatarAppearance appearance = new AvatarAppearance();
     appearance.Unpack(map);
     return appearance;
 }
        public void LoadAvatarArchive(string FileName, string First, string Last, string pass)
        {
            UserAccount account = GetUserInfo(First, Last, pass);

            if (account == null)
            {
                return;
            }

            m_log.Info("[AvatarArchive] Loading archive from " + FileName);

            try
            {
                StreamReader reader = new StreamReader(FileName + ".aa");



                string file = reader.ReadToEnd();
                reader.Close();
                reader.Dispose();

                ScenePresence SP;
                m_scene.TryGetScenePresence(account.PrincipalID, out SP);
                if (SP == null)
                {
                    return; //Bad people!
                }
                SP.ControllingClient.SendAlertMessage("Appearance loading in progress...");

                string FolderNameToLoadInto = "";

                OSDMap map = ((OSDMap)OSDParser.DeserializeLLSDXml(file));

                OSDMap assetsMap = ((OSDMap)map["Assets"]);
                OSDMap itemsMap  = ((OSDMap)map["Items"]);
                OSDMap bodyMap   = ((OSDMap)map["Body"]);

                AvatarAppearance appearance = ConvertXMLToAvatarAppearance(bodyMap, out FolderNameToLoadInto);

                //appearance.Owner = account.PrincipalID;

                List <InventoryItemBase> items = new List <InventoryItemBase>();

                InventoryFolderBase AppearanceFolder = InventoryService.GetFolderForType(account.PrincipalID, AssetType.Clothing);

                InventoryFolderBase folderForAppearance
                    = new InventoryFolderBase(
                          UUID.Random(), FolderNameToLoadInto, account.PrincipalID,
                          -1, AppearanceFolder.ID, 1);

                InventoryService.AddFolder(folderForAppearance);

                folderForAppearance = InventoryService.GetFolder(folderForAppearance);

                try
                {
                    LoadAssets(assetsMap);
                    LoadItems(itemsMap, account.PrincipalID, folderForAppearance, out items);
                }
                catch (Exception ex)
                {
                    m_log.Warn("[AvatarArchiver]: Error loading assets and items, " + ex.ToString());
                }


                //Now update the client about the new items
                SP.ControllingClient.SendBulkUpdateInventory(folderForAppearance);
                foreach (InventoryItemBase itemCopy in items)
                {
                    if (itemCopy == null)
                    {
                        SP.ControllingClient.SendAgentAlertMessage("Can't find item to give. Nothing given.", false);
                        continue;
                    }
                    if (!SP.IsChildAgent)
                    {
                        SP.ControllingClient.SendBulkUpdateInventory(itemCopy);
                    }
                }
                m_log.Info("[AvatarArchive] Loaded archive from " + FileName + ".aa");
            }
            catch (Exception e)
            {
                m_log.Error("[AvatarArchive] " + e.Message);
            }
        }
Exemple #20
0
        public override void FromOSD(OSDMap map)
        {
            AgentInfo = new IAgentInfo();
            AgentInfo.FromOSD((OSDMap)(map["AgentInfo"]));
            UserAccount = new UserAccount();
            UserAccount.FromOSD((OSDMap)(map["UserAccount"]));
            if (!map.ContainsKey("ActiveGroup"))
            {
                ActiveGroup = null;
            }
            else
            {
                ActiveGroup = new GroupMembershipData();
                ActiveGroup.FromOSD((OSDMap)(map["ActiveGroup"]));
            }
            GroupMemberships = ((OSDArray)map["GroupMemberships"]).ConvertAll <GroupMembershipData>((o) =>
            {
                GroupMembershipData
                group =
                    new GroupMembershipData
                        ();
                group
                .FromOSD
                    ((OSDMap
                      )o);
                return(group);
            });
            OfflineMessages = ((OSDArray)map["OfflineMessages"]).ConvertAll <GridInstantMessage>((o) =>
            {
                GridInstantMessage
                group =
                    new GridInstantMessage
                        ();
                group.FromOSD(
                    (OSDMap)o);
                return(group);
            });
            MuteList = ((OSDArray)map["MuteList"]).ConvertAll <MuteList>((o) =>
            {
                MuteList group = new MuteList();
                group.FromOSD((OSDMap)o);
                return(group);
            });

            if (map.ContainsKey("Appearance"))
            {
                Appearance = new AvatarAppearance();
                Appearance.FromOSD((OSDMap)map["Appearance"]);
            }
            if (map.ContainsKey("FriendOnlineStatuses"))
            {
                FriendOnlineStatuses = ((OSDArray)map["FriendOnlineStatuses"]).ConvertAll <UUID>((o) => { return(o); });
            }
            if (map.ContainsKey("Friends"))
            {
                Friends = ((OSDArray)map["Friends"]).ConvertAll <FriendInfo>((o) =>
                {
                    FriendInfo f = new FriendInfo();
                    f.FromOSD((OSDMap)o);
                    return(f);
                });
            }
        }
        public void SetAppearance(UUID principalID, AvatarAppearance appearance)
        {
            if (m_doRemoteOnly)
            {
                DoRemotePostByURL("AvatarServerURI", principalID, appearance);
                return;
            }

            m_registry.RequestModuleInterface<ISimulationBase>().EventManager.FireGenericEventHandler("SetAppearance",
                                                                                                      new object[2]
                                                                                                          {
                                                                                                              principalID,
                                                                                                              appearance
                                                                                                          });
            m_Database.Store(principalID, appearance);
        }
        protected void HandleSaveAvatarArchive(string module, string[] cmdparams)
        {
            if (cmdparams.Length != 8)
            {
                m_log.Info("[AvatarArchive] Not enough parameters!");
                return;
            }
            string ext = Path.GetExtension(cmdparams[6]);

            if (ext != "")
            {
                m_log.Error("[AvatarArchive] Do not Specify File Extention, It is automaticly Added");
                return;
            }
            UserAccount account = GetUserInfo(cmdparams[3], cmdparams[4], cmdparams[5]);

            if (account == null)
            {
                return;
            }

            ScenePresence SP;

            m_scene.TryGetScenePresence(account.PrincipalID, out SP);
            if (SP == null)
            {
                return; //Bad people!
            }
            SP.ControllingClient.SendAlertMessage("Appearance saving in progress...");

            AvatarAppearance appearance = AvatarService.GetAppearance(SP.UUID);

            if (appearance == null)
            {
                appearance = SP.Appearance;
            }
            StreamWriter writer = new StreamWriter(cmdparams[6] + ".aa", false);
            OSDMap       map    = new OSDMap();
            OSDMap       body   = new OSDMap();
            OSDMap       assets = new OSDMap();
            OSDMap       items  = new OSDMap();

            body = appearance.Pack();
            body.Add("FolderName", OSD.FromString(cmdparams[7]));
            int wearCount = 0;

            foreach (AvatarWearable wear in appearance.Wearables)
            {
                for (int i = 0; i < wear.Count; i++)
                {
                    WearableItem w = wear[i];

                    SaveAsset(w.AssetID, assets);
                    SaveItem(w.ItemID, items, assets);
                    wearCount++;
                }
            }

            int attachCount = 0;
            List <AvatarAttachment> attachments = appearance.GetAttachments();

            foreach (AvatarAttachment a in attachments)
            {
                UUID itemID = a.ItemID;
                m_log.Info("[AvatarArchive] Saved attachment " + a.ItemID);
                if (a.ItemID != UUID.Zero)
                {
                    SaveAsset(a.ItemID, assets);
                    SaveItem(a.ItemID, items, assets);

                    attachCount++;
                }
            }
            foreach (AvatarAttachment a in attachments.Where(a => a.AssetID != UUID.Zero))
            {
                SaveItem(a.ItemID, items, assets);
                SaveAsset(a.AssetID, assets);
            }

            map.Add("Body", body);
            map.Add("Assets", assets);
            map.Add("Items", items);
            //Write the map
            writer.Write(OSDParser.SerializeLLSDXmlString(map));
            writer.Close();
            writer.Dispose();
            m_log.Info("[AvatarArchive] Saved archive to " + cmdparams[6] + ".aa");
        }
        private AvatarAppearance ConvertXMLToAvatarAppearance(List<string> file, out List<UUID> AttachmentIDs, out List<string> AttachmentPoints, out List<string> AttachmentAsset, out string FolderNameToPlaceAppearanceIn)
        {
            AvatarAppearance appearance = new AvatarAppearance();
            List<string> newFile = new List<string>();
            foreach (string line in file)
            {
                string newLine = line.TrimStart('<');
                newFile.Add(newLine.TrimEnd('>'));
            }
            appearance.AvatarHeight = Convert.ToInt32(newFile[1]);
            appearance.BodyAsset = new UUID(newFile[2]);
            appearance.BodyItem = new UUID(newFile[3]);
            appearance.EyesAsset = new UUID(newFile[4]);
            appearance.EyesItem = new UUID(newFile[5]);
            appearance.GlovesAsset = new UUID(newFile[6]);
            appearance.GlovesItem = new UUID(newFile[7]);
            appearance.HairAsset = new UUID(newFile[8]);
            appearance.HairItem = new UUID(newFile[9]);
            //Skip Hip Offset
            appearance.JacketAsset = new UUID(newFile[11]);
            appearance.JacketItem = new UUID(newFile[12]);
            appearance.Owner = new UUID(newFile[13]);
            appearance.PantsAsset = new UUID(newFile[14]);
            appearance.PantsItem = new UUID(newFile[15]);
            appearance.Serial = Convert.ToInt32(newFile[16]);
            appearance.ShirtAsset = new UUID(newFile[17]);
            appearance.ShirtItem = new UUID(newFile[18]);
            appearance.ShoesAsset = new UUID(newFile[19]);
            appearance.ShoesItem = new UUID(newFile[20]);
            appearance.SkinAsset = new UUID(newFile[21]);
            appearance.SkinItem = new UUID(newFile[22]);
            appearance.SkirtAsset = new UUID(newFile[23]);
            appearance.SkirtItem = new UUID(newFile[24]);
            appearance.SocksAsset = new UUID(newFile[25]);
            appearance.SocksItem = new UUID(newFile[26]);
            //appearance.Texture = new Primitive.TextureEntry(newFile[27],);
            appearance.UnderPantsAsset = new UUID(newFile[27]);
            appearance.UnderPantsItem = new UUID(newFile[28]);
            appearance.UnderShirtAsset = new UUID(newFile[29]);
            appearance.UnderShirtItem = new UUID(newFile[30]);
            FolderNameToPlaceAppearanceIn = newFile[31];

            Byte[] bytes = new byte[218];
            int i = 0;
            while (i <= 31)
            {
                newFile.RemoveAt(0); //Clear out the already processed parts
                i++;
            }
            i = 0;
            if (newFile[0] == "VisualParams")
            {
                foreach (string partLine in newFile)
                {
                    if (partLine.StartsWith("/VP"))
                    {
                        string newpartLine = "";
                        newpartLine = partLine.Replace("/VP", "");
                        bytes[i] = Convert.ToByte(newpartLine);
                        i++;
                    }
                }
            }
            appearance.VisualParams = bytes;
            List<string> WearableAsset = new List<string>();
            List<string> WearableItem = new List<string>();
            string texture = "";
            AttachmentIDs = new List<UUID>();
            AttachmentPoints = new List<string>();
            AttachmentAsset = new List<string>();
            foreach (string partLine in newFile)
            {
                if (partLine.StartsWith("WA"))
                {
                    string newpartLine = "";
                    newpartLine = partLine.Replace("WA", "");
                    WearableAsset.Add(newpartLine);
                }
                if (partLine.StartsWith("WI"))
                {
                    string newpartLine = "";
                    newpartLine = partLine.Replace("WI", "");
                    WearableItem.Add(newpartLine);
                }
                if (partLine.StartsWith("TEXTURE"))
                {
                    string newpartLine = "";
                    newpartLine = partLine.Replace("TEXTURE", "");
                    texture = newpartLine;
                }
                if (partLine.StartsWith("AI"))
                {
                    string newpartLine = "";
                    newpartLine = partLine.Replace("AI", "");
                    AttachmentIDs.Add(new UUID(newpartLine));
                }
                if (partLine.StartsWith("AA"))
                {
                    string newpartLine = "";
                    newpartLine = partLine.Replace("AA", "");
                    AttachmentAsset.Add(newpartLine);
                }
                if (partLine.StartsWith("AP"))
                {
                    string newpartLine = "";
                    newpartLine = partLine.Replace("AP", "");
                    AttachmentPoints.Add(newpartLine);
                }
            }
            //byte[] textureBytes = Utils.StringToBytes(texture);
            //appearance.Texture = new Primitive.TextureEntry(textureBytes, 0, textureBytes.Length);
            AvatarWearable[] wearables = new AvatarWearable[13];
            i = 0;
            foreach (string asset in WearableAsset)
            {
                AvatarWearable wearable = new AvatarWearable(new UUID(asset), new UUID(WearableItem[i]));
                wearables[i] = wearable;
                i++;
            }
            i = 0;
            foreach (string asset in AttachmentAsset)
            {
                appearance.SetAttachment(Convert.ToInt32(AttachmentPoints[i]), AttachmentIDs[i], new UUID(asset));
                i++;
            }
            return appearance;
        }
Exemple #24
0
        public AvatarAppearance ToAvatarAppearance(UUID owner)
        {
            AvatarAppearance appearance = new AvatarAppearance(owner);

            try
            {
                appearance.Serial = Int32.Parse(Data["Serial"]);

                // Wearables
                appearance.BodyItem       = UUID.Parse(Data["BodyItem"]);
                appearance.EyesItem       = UUID.Parse(Data["EyesItem"]);
                appearance.GlovesItem     = UUID.Parse(Data["GlovesItem"]);
                appearance.HairItem       = UUID.Parse(Data["HairItem"]);
                appearance.JacketItem     = UUID.Parse(Data["JacketItem"]);
                appearance.PantsItem      = UUID.Parse(Data["PantsItem"]);
                appearance.ShirtItem      = UUID.Parse(Data["ShirtItem"]);
                appearance.ShoesItem      = UUID.Parse(Data["ShoesItem"]);
                appearance.SkinItem       = UUID.Parse(Data["SkinItem"]);
                appearance.SkirtItem      = UUID.Parse(Data["SkirtItem"]);
                appearance.SocksItem      = UUID.Parse(Data["SocksItem"]);
                appearance.UnderPantsItem = UUID.Parse(Data["UnderPantsItem"]);
                appearance.UnderShirtItem = UUID.Parse(Data["UnderShirtItem"]);

                appearance.BodyAsset       = UUID.Parse(Data["BodyAsset"]);
                appearance.EyesAsset       = UUID.Parse(Data["EyesAsset"]);
                appearance.GlovesAsset     = UUID.Parse(Data["GlovesAsset"]);
                appearance.HairAsset       = UUID.Parse(Data["HairAsset"]);
                appearance.JacketAsset     = UUID.Parse(Data["JacketAsset"]);
                appearance.PantsAsset      = UUID.Parse(Data["PantsAsset"]);
                appearance.ShirtAsset      = UUID.Parse(Data["ShirtAsset"]);
                appearance.ShoesAsset      = UUID.Parse(Data["ShoesAsset"]);
                appearance.SkinAsset       = UUID.Parse(Data["SkinAsset"]);
                appearance.SkirtAsset      = UUID.Parse(Data["SkirtAsset"]);
                appearance.SocksAsset      = UUID.Parse(Data["SocksAsset"]);
                appearance.UnderPantsAsset = UUID.Parse(Data["UnderPantsAsset"]);
                appearance.UnderShirtAsset = UUID.Parse(Data["UnderShirtAsset"]);

                // Attachments
                Dictionary <string, string> attchs = new Dictionary <string, string>();
                foreach (KeyValuePair <string, string> _kvp in Data)
                {
                    if (_kvp.Key.StartsWith("_ap_"))
                    {
                        attchs[_kvp.Key] = _kvp.Value;
                    }
                }
                Hashtable aaAttachs = new Hashtable();
                foreach (KeyValuePair <string, string> _kvp in attchs)
                {
                    string pointStr = _kvp.Key.Substring(4);
                    int    point    = 0;
                    if (!Int32.TryParse(pointStr, out point))
                    {
                        continue;
                    }
                    Hashtable tmp  = new Hashtable();
                    UUID      uuid = UUID.Zero;
                    UUID.TryParse(_kvp.Value, out uuid);
                    tmp["item"]      = uuid;
                    tmp["asset"]     = UUID.Zero.ToString();
                    aaAttachs[point] = tmp;
                }
                appearance.SetAttachments(aaAttachs);
            }
            catch { }

            return(appearance);
        }
Exemple #25
0
        private AvatarAppearance ConvertXMLToAvatarAppearance(OSDMap map, out string FolderNameToPlaceAppearanceIn)
        {
            AvatarAppearance appearance = new AvatarAppearance();

            appearance.Unpack(map);
            FolderNameToPlaceAppearanceIn = map["FolderName"].AsString();
            return appearance;
        }
        public LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID,
                                   string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP)
        {
            bool success = false;
            UUID session = UUID.Random();

            m_log.InfoFormat("[LLOGIN SERVICE]: Login request for {0} {1} at {2} using viewer {3}, channel {4}, IP {5}, Mac {6}, Id0 {7}",
                             firstName, lastName, startLocation, clientVersion, channel, clientIP.Address.ToString(), mac, id0);

            try
            {
                //
                // Check client
                //
                if (m_AllowedClients != string.Empty)
                {
                    Regex arx = new Regex(m_AllowedClients);
                    Match am  = arx.Match(clientVersion);

                    if (!am.Success)
                    {
                        m_log.InfoFormat(
                            "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: client {2} is not allowed",
                            firstName, lastName, clientVersion);
                        return(LLFailedLoginResponse.LoginBlockedProblem);
                    }
                }

                if (m_DeniedClients != string.Empty)
                {
                    Regex drx = new Regex(m_DeniedClients);
                    Match dm  = drx.Match(clientVersion);

                    if (dm.Success)
                    {
                        m_log.InfoFormat(
                            "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: client {2} is denied",
                            firstName, lastName, clientVersion);
                        return(LLFailedLoginResponse.LoginBlockedProblem);
                    }
                }

                //
                // Get the account and check that it exists
                //
                UserAccount account = m_UserAccountService.GetUserAccount(scopeID, firstName, lastName);
                if (account == null)
                {
                    m_log.InfoFormat(
                        "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: user not found", firstName, lastName);
                    return(LLFailedLoginResponse.UserProblem);
                }

                if (account.UserLevel < m_MinLoginLevel)
                {
                    m_log.InfoFormat(
                        "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: user level is {2} but minimum login level is {3}",
                        firstName, lastName, account.UserLevel, m_MinLoginLevel);
                    return(LLFailedLoginResponse.LoginBlockedProblem);
                }

                // If a scope id is requested, check that the account is in
                // that scope, or unscoped.
                //
                if (scopeID != UUID.Zero)
                {
                    if (account.ScopeID != scopeID && account.ScopeID != UUID.Zero)
                    {
                        m_log.InfoFormat(
                            "[LLOGIN SERVICE]: Login failed, reason: user {0} {1} not found", firstName, lastName);
                        return(LLFailedLoginResponse.UserProblem);
                    }
                }
                else
                {
                    scopeID = account.ScopeID;
                }

                //
                // Authenticate this user
                //
                if (!passwd.StartsWith("$1$"))
                {
                    passwd = "$1$" + Util.Md5Hash(passwd);
                }
                passwd = passwd.Remove(0, 3); //remove $1$
                string token         = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30);
                UUID   secureSession = UUID.Zero;
                if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession)))
                {
                    m_log.InfoFormat(
                        "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: authentication failed",
                        firstName, lastName);
                    return(LLFailedLoginResponse.UserProblem);
                }

                //
                // Get the user's inventory
                //
                if (m_RequireInventory && m_InventoryService == null)
                {
                    m_log.WarnFormat(
                        "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: inventory service not set up",
                        firstName, lastName);
                    return(LLFailedLoginResponse.InventoryProblem);
                }

                if (m_HGInventoryService != null)
                {
                    // Give the Suitcase service a chance to create the suitcase folder.
                    // (If we're not using the Suitcase inventory service then this won't do anything.)
                    m_HGInventoryService.GetRootFolder(account.PrincipalID);
                }

                List <InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
                if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)))
                {
                    m_log.InfoFormat(
                        "[LLOGIN SERVICE]: Login failed, for {0} {1}, reason: unable to retrieve user inventory",
                        firstName, lastName);
                    return(LLFailedLoginResponse.InventoryProblem);
                }

                // Get active gestures
                List <InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(account.PrincipalID);
                //                m_log.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count);

                //
                // Login the presence
                //
                if (m_PresenceService != null)
                {
                    success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession);

                    if (!success)
                    {
                        m_log.InfoFormat(
                            "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: could not login presence",
                            firstName, lastName);
                        return(LLFailedLoginResponse.GridProblem);
                    }
                }

                //
                // Change Online status and get the home region
                //
                GridRegion   home   = null;
                GridUserInfo guinfo = m_GridUserService.LoggedIn(account.PrincipalID.ToString());

                // We are only going to complain about no home if the user actually tries to login there, to avoid
                // spamming the console.
                if (guinfo != null)
                {
                    if (guinfo.HomeRegionID == UUID.Zero && startLocation == "home")
                    {
                        m_log.WarnFormat(
                            "[LLOGIN SERVICE]: User {0} tried to login to a 'home' start location but they have none set",
                            account.Name);
                    }
                    else if (m_GridService != null)
                    {
                        home = m_GridService.GetRegionByUUID(scopeID, guinfo.HomeRegionID);

                        if (home == null && startLocation == "home")
                        {
                            m_log.WarnFormat(
                                "[LLOGIN SERVICE]: User {0} tried to login to a 'home' start location with ID {1} but this was not found.",
                                account.Name, guinfo.HomeRegionID);
                        }
                    }
                }
                else
                {
                    // something went wrong, make something up, so that we don't have to test this anywhere else
                    m_log.DebugFormat("{0} Failed to fetch GridUserInfo. Creating empty GridUserInfo as home", LogHeader);
                    guinfo = new GridUserInfo();
                    guinfo.LastPosition = guinfo.HomePosition = new Vector3(128, 128, 30);
                }

                //
                // Find the destination region/grid
                //
                string where = string.Empty;
                Vector3       position   = Vector3.Zero;
                Vector3       lookAt     = Vector3.Zero;
                GridRegion    gatekeeper = null;
                TeleportFlags flags;
                GridRegion    destination = FindDestination(account, scopeID, guinfo, session, startLocation, home, out gatekeeper, out where, out position, out lookAt, out flags);
                if (destination == null)
                {
                    m_PresenceService.LogoutAgent(session);

                    m_log.InfoFormat(
                        "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: destination not found",
                        firstName, lastName);
                    return(LLFailedLoginResponse.GridProblem);
                }
                else
                {
                    m_log.DebugFormat(
                        "[LLOGIN SERVICE]: Found destination {0}, endpoint {1} for {2} {3}",
                        destination.RegionName, destination.ExternalEndPoint, firstName, lastName);
                }

                if (account.UserLevel >= 200)
                {
                    flags |= TeleportFlags.Godlike;
                }
                //
                // Get the avatar
                //
                AvatarAppearance avatar = null;
                if (m_AvatarService != null)
                {
                    avatar = m_AvatarService.GetAppearance(account.PrincipalID);
                }

                //
                // Instantiate/get the simulation interface and launch an agent at the destination
                //
                string           reason = string.Empty;
                GridRegion       dest;
                AgentCircuitData aCircuit = LaunchAgentAtGrid(gatekeeper, destination, account, avatar, session, secureSession, position, where,
                                                              clientVersion, channel, mac, id0, clientIP, flags, out where, out reason, out dest);
                destination = dest;
                if (aCircuit == null)
                {
                    m_PresenceService.LogoutAgent(session);
                    m_log.InfoFormat("[LLOGIN SERVICE]: Login failed for {0} {1}, reason: {2}", firstName, lastName, reason);
                    return(new LLFailedLoginResponse("key", reason, "false"));
                }
                // Get Friends list
                FriendInfo[] friendsList = new FriendInfo[0];
                if (m_FriendsService != null)
                {
                    friendsList = m_FriendsService.GetFriends(account.PrincipalID);
                    //                    m_log.DebugFormat("[LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length);
                }

                //
                // Finally, fill out the response and return it
                //
                LLLoginResponse response
                    = new LLLoginResponse(
                          account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService,
                          where, startLocation, position, lookAt, gestures, m_WelcomeMessage, home, clientIP,
                          m_MapTileURL, m_ProfileURL, m_OpenIDURL, m_SearchURL, m_Currency, m_DSTZone,
                          m_DestinationGuide, m_AvatarPicker, m_ClassifiedFee);

                m_log.DebugFormat("[LLOGIN SERVICE]: All clear. Sending login response to {0} {1}", firstName, lastName);

                return(response);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2} {3}", firstName, lastName, e.ToString(), e.StackTrace);
                if (m_PresenceService != null)
                {
                    m_PresenceService.LogoutAgent(session);
                }
                return(LLFailedLoginResponse.InternalError);
            }
        }
Exemple #27
0
        public LoginResponse Login(string Name, string passwd, string startLocation, UUID scopeID,
            string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP, Hashtable requestData, UUID secureSession)
        {
            UUID session = UUID.Random();

            m_log.InfoFormat("[LLOGIN SERVICE]: Login request for {0} from {1} with user agent {2} starting in {3}",
                Name, clientIP.Address.ToString(), clientVersion, startLocation);
            UserAccount account = m_UserAccountService.GetUserAccount (scopeID, Name);
            try
            {
                string DisplayName = account.Name;
                IAgentInfo agent = null;

                IAgentConnector agentData = DataManager.RequestPlugin<IAgentConnector>();
                IProfileConnector profileData = DataManager.RequestPlugin<IProfileConnector>();
                if (agentData != null)
                    agent = agentData.GetAgent(account.PrincipalID);

                requestData["ip"] = clientIP.ToString();
                foreach (ILoginModule module in LoginModules)
                {
                    string message;
                    if (!module.Login(requestData, account.PrincipalID, out message))
                    {
                        LLFailedLoginResponse resp = new LLFailedLoginResponse(LoginResponseEnum.PasswordIncorrect,
                            message, false);
                        return resp;
                    }
                }
                

                //
                // Get the user's inventory
                //
                if (m_RequireInventory && m_InventoryService == null)
                {
                    m_log.WarnFormat("[LLOGIN SERVICE]: Login failed, reason: inventory service not set up");
                    return LLFailedLoginResponse.InventoryProblem;
                }
                List<InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
                if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)))
                {
                    m_InventoryService.CreateUserInventory(account.PrincipalID, m_DefaultUserAvatarArchive == "");
                    inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
                    if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)))
                    {
                        m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: unable to retrieve user inventory");
                        return LLFailedLoginResponse.InventoryProblem;
                    }
                }
                if (m_InventoryService.CreateUserRootFolder (account.PrincipalID))
                    ///Gotta refetch... since something went wrong
                    inventorySkel = m_InventoryService.GetInventorySkeleton (account.PrincipalID);

                if (profileData != null)
                {
                    IUserProfileInfo UPI = profileData.GetUserProfile(account.PrincipalID);
                    if (UPI == null)
                    {
                        profileData.CreateNewProfile(account.PrincipalID);
                        UPI = profileData.GetUserProfile(account.PrincipalID);
                        UPI.AArchiveName = m_DefaultUserAvatarArchive;
                        UPI.IsNewUser = true;
                        //profileData.UpdateUserProfile(UPI); //It gets hit later by the next thing
                    }
                    //Find which is set, if any
                    string archiveName = (UPI.AArchiveName != "" && UPI.AArchiveName != " ") ? UPI.AArchiveName : m_DefaultUserAvatarArchive;
                    if (UPI.IsNewUser && archiveName != "")
                    {
                        archiver.LoadAvatarArchive(archiveName, account.Name);
                        UPI.AArchiveName = "";
                    }
                    if (UPI.IsNewUser)
                    {
                        UPI.IsNewUser = false;
                        profileData.UpdateUserProfile(UPI);
                    }
                    if(UPI.DisplayName != "")
                        DisplayName = UPI.DisplayName;
                }

                // Get active gestures
                List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(account.PrincipalID);
                //m_log.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count);

                //Reset logged in to true if the user was crashed, but don't fire the logged in event yet
                m_agentInfoService.SetLoggedIn (account.PrincipalID.ToString (), true, false, UUID.Zero);
                //Lock it as well
                m_agentInfoService.LockLoggedInStatus (account.PrincipalID.ToString (), true);
                //Now get the logged in status, then below make sure to kill the previous agent if we crashed before
                UserInfo guinfo = m_agentInfoService.GetUserInfo (account.PrincipalID.ToString ());
                //
                // Clear out any existing CAPS the user may have
                //
                if (m_CapsService != null)
                {
                    IAgentProcessing agentProcessor = m_registry.RequestModuleInterface<IAgentProcessing>();
                    if (agentProcessor != null)
                    {
                        IClientCapsService clientCaps = m_CapsService.GetClientCapsService(account.PrincipalID);
                        if (clientCaps != null)
                        {
                            IRegionClientCapsService rootRegionCaps = clientCaps.GetRootCapsService();
                            if (rootRegionCaps != null)
                                agentProcessor.LogoutAgent(rootRegionCaps, !m_AllowDuplicateLogin);
                        }
                    }
                    else
                        m_CapsService.RemoveCAPS(account.PrincipalID);
                }

                //
                // Change Online status and get the home region
                //
                GridRegion home = null;
                if (guinfo != null && (guinfo.HomeRegionID != UUID.Zero) && m_GridService != null)
                {
                    home = m_GridService.GetRegionByUUID(scopeID, guinfo.HomeRegionID);
                }
                bool GridUserInfoFound = true;
                if (guinfo == null)
                {
                    GridUserInfoFound = false;
                    // something went wrong, make something up, so that we don't have to test this anywhere else
                    guinfo = new UserInfo();
                    guinfo.UserID = account.PrincipalID.ToString();
                    guinfo.CurrentPosition = guinfo.HomePosition = new Vector3(128, 128, 30);
                }

                //
                // Find the destination region/grid
                //
                string where = string.Empty;
                Vector3 position = Vector3.Zero;
                Vector3 lookAt = Vector3.Zero;
                TeleportFlags tpFlags = TeleportFlags.ViaLogin;
                GridRegion destination = FindDestination (account, scopeID, guinfo, session, startLocation, home, out tpFlags, out where, out position, out lookAt);
                if (destination == null)
                {
                    m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: destination not found");
                    return LLFailedLoginResponse.DeadRegionProblem;
                }
                if (!GridUserInfoFound || guinfo.HomeRegionID == UUID.Zero) //Give them a default home and last
                {
                    List<GridRegion> DefaultRegions = m_GridService.GetDefaultRegions(account.ScopeID);
                    GridRegion DefaultRegion = null;
                    if (DefaultRegions.Count == 0)
                        DefaultRegion = destination;
                    else
                        DefaultRegion = DefaultRegions[0];

                    if (m_DefaultHomeRegion != "" && guinfo.HomeRegionID == UUID.Zero)
                    {
                        GridRegion newHomeRegion = m_GridService.GetRegionByName(account.ScopeID, m_DefaultHomeRegion);
                        if (newHomeRegion == null)
                            guinfo.HomeRegionID = guinfo.CurrentRegionID = DefaultRegion.RegionID;
                        else
                            guinfo.HomeRegionID = guinfo.CurrentRegionID = newHomeRegion.RegionID;
                    }
                    else if (guinfo.HomeRegionID == UUID.Zero)
                        guinfo.HomeRegionID = guinfo.CurrentRegionID = DefaultRegion.RegionID;

                    //Z = 0 so that it fixes it on the region server and puts it on the ground
                    guinfo.CurrentPosition = guinfo.HomePosition = new Vector3(128, 128, 25);

                    guinfo.HomeLookAt = guinfo.CurrentLookAt = new Vector3(0, 0, 0);

                    m_agentInfoService.SetLastPosition(guinfo.UserID, guinfo.CurrentRegionID, guinfo.CurrentPosition, guinfo.CurrentLookAt);
                    m_agentInfoService.SetHomePosition(guinfo.UserID, guinfo.HomeRegionID, guinfo.HomePosition, guinfo.HomeLookAt);
                }

                //
                // Get the avatar
                //
                AvatarAppearance avappearance = new AvatarAppearance(account.PrincipalID);
                if (m_AvatarService != null)
                {
                    avappearance = m_AvatarService.GetAppearance(account.PrincipalID);
                    if (avappearance == null)
                    {
                        //Create an appearance for the user if one doesn't exist
                        if (m_DefaultUserAvatarArchive != "")
                        {
                            m_log.Error("[LLoginService]: Cannot find an appearance for user " + account.Name +
                                ", loading the default avatar from " + m_DefaultUserAvatarArchive + ".");
                            archiver.LoadAvatarArchive(m_DefaultUserAvatarArchive, account.Name);
                        }
                        else
                        {
                            m_log.Error("[LLoginService]: Cannot find an appearance for user " + account.Name + ", setting to the default avatar.");
                            AvatarAppearance appearance = new AvatarAppearance(account.PrincipalID);
                            m_AvatarService.SetAvatar(account.PrincipalID, new AvatarData(appearance));
                        }
                        avappearance = m_AvatarService.GetAppearance(account.PrincipalID);
                    }
                    else
                    {
                        //Verify that all assets exist now
                        for (int i = 0; i < avappearance.Wearables.Length; i++)
                        {
                            bool messedUp = false;
                            foreach (KeyValuePair<UUID, UUID> item in avappearance.Wearables[i].GetItems())
                            {
                                AssetBase asset = m_AssetService.Get(item.Value.ToString());
                                if (asset == null)
                                {
                                    InventoryItemBase invItem = m_InventoryService.GetItem (new InventoryItemBase (item.Value));
                                    if (invItem == null)
                                    {
                                        m_log.Warn ("Missing avatar appearance asset for user " + account.Name + " for item " + item.Value + ", asset should be " + item.Key + "!");
                                        messedUp = true;
                                    }
                                }
                            }
                            if (messedUp)
                                avappearance.Wearables[i] = AvatarWearable.DefaultWearables[i];
                        }
                        //Also verify that all baked texture indices exist
                        foreach (byte BakedTextureIndex in AvatarAppearance.BAKE_INDICES)
                        {
                            if (BakedTextureIndex == 19) //Skirt isn't used unless you have a skirt
                                continue;
                            if (avappearance.Texture.GetFace(BakedTextureIndex).TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE)
                            {
                                m_log.Warn("Bad texture index for user " + account.Name + " for " + BakedTextureIndex + "!");
                                avappearance = new AvatarAppearance(account.PrincipalID);
                                m_AvatarService.SetAvatar(account.PrincipalID, new AvatarData(avappearance));
                                break;
                            }
                        }
                    }
                }

                //
                // Instantiate/get the simulation interface and launch an agent at the destination
                //
                string reason = string.Empty;
                AgentCircuitData aCircuit = LaunchAgentAtGrid (destination, tpFlags, account, avappearance, session, secureSession, position, where,
                    clientIP, out where, out reason, out destination);

                if (aCircuit == null)
                {
                    m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: {0}", reason);
                    return new LLFailedLoginResponse (LoginResponseEnum.InternalError, reason, false);
                }

                // Get Friends list 
                FriendInfo[] friendsList = new FriendInfo[0];
                if (m_FriendsService != null)
                {
                    friendsList = m_FriendsService.GetFriends(account.PrincipalID);
                    //m_log.DebugFormat("[LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length);
                }

                //Set them as logged in now, they are ready, and fire the logged in event now, as we're all done
                m_agentInfoService.SetLastPosition (account.PrincipalID.ToString (), destination.RegionID, position, lookAt);
                m_agentInfoService.LockLoggedInStatus (account.PrincipalID.ToString (), false); //Unlock it now
                m_agentInfoService.SetLoggedIn(account.PrincipalID.ToString(), true, true, destination.RegionID);
                
                //
                // Finally, fill out the response and return it
                //
                string MaturityRating = "A";
                string MaxMaturity = "A";
                if (agent != null)
                {
                    if (agent.MaturityRating == 0)
                        MaturityRating = "P";
                    else if (agent.MaturityRating == 1)
                        MaturityRating = "M";
                    else if (agent.MaturityRating == 2)
                        MaturityRating = "A";

                    if (agent.MaxMaturity == 0)
                        MaxMaturity = "P";
                    else if (agent.MaxMaturity == 1)
                        MaxMaturity = "M";
                    else if (agent.MaxMaturity == 2)
                        MaxMaturity = "A";
                }

                LLLoginResponse response = new LLLoginResponse(account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_InventoryService, m_LibraryService,
                    where, startLocation, position, lookAt, gestures, home, clientIP, MaxMaturity, MaturityRating,
                    eventCategories, classifiedCategories, FillOutSeedCap (aCircuit, destination, clientIP, account.PrincipalID), m_config, DisplayName, m_registry);

                m_log.InfoFormat("[LLOGIN SERVICE]: All clear. Sending login response to client to login to region " + destination.RegionName + ", tried to login to " + startLocation + " at " + position.ToString() + ".");
                return response;
            }
            catch (Exception e)
            {
                m_log.WarnFormat ("[LLOGIN SERVICE]: Exception processing login for {0} : {1}", Name, e.ToString ());
                if (account != null)
                {
                    //Revert their logged in status if we got that far
                    m_agentInfoService.LockLoggedInStatus (account.PrincipalID.ToString (), false); //Unlock it now
                    m_agentInfoService.SetLoggedIn (account.PrincipalID.ToString (), false, false, UUID.Zero);
                }
                return LLFailedLoginResponse.InternalError;
            }
            
        }
        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);
            }
        }
Exemple #29
0
        public AvatarData(AvatarAppearance appearance)
        {
            AvatarType = 1; // SL avatars
            Data = new Dictionary<string, string>();

            Data["Serial"] = appearance.Serial.ToString();
            // Wearables
            Data["AvatarHeight"] = appearance.AvatarHeight.ToString();

            Data["Textures"] = OSDParser.SerializeJsonString(appearance.Texture.GetOSD());

            for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
            {
                for (int j = 0; j < appearance.Wearables[i].Count; j++)
                {
                    string fieldName = String.Format("Wearable {0}:{1}", i, j);
                    Data[fieldName] = String.Format("{0}:{1}",
                            appearance.Wearables[i][j].ItemID.ToString(),
                            appearance.Wearables[i][j].AssetID.ToString());
                }
            }

            // Visual Params
            string[] vps = new string[AvatarAppearance.VISUALPARAM_COUNT];
            byte[] binary = appearance.VisualParams;

            for (int i = 0; i < AvatarAppearance.VISUALPARAM_COUNT; i++)
            {
                vps[i] = binary[i].ToString();
            }

            Data["VisualParams"] = String.Join(",", vps);

            // Attachments
            List<AvatarAttachment> attachments = appearance.GetAttachments();
            foreach (AvatarAttachment attach in attachments)
            {
                Data["_ap_" + attach.AttachPoint] = attach.ItemID.ToString();
            }
        }
Exemple #30
0
 public void AvatarAppearance_InitClass()
 {
     AvatarAppearance.InitClass();
 }
        /// <summary>
        ///   Update what the avatar is wearing using an item from their inventory.
        /// </summary>
        /// <param name = "client"></param>
        /// <param name = "e"></param>
        public void AvatarIsWearing(IClientAPI client, AvatarWearingArgs e)
        {
            IScenePresence sp = m_scene.GetScenePresence(client.AgentId);
            if (sp == null)
            {
                MainConsole.Instance.WarnFormat("[AvatarFactory]: AvatarIsWearing unable to find presence for {0}", client.AgentId);
                return;
            }

            MainConsole.Instance.DebugFormat("[AvatarFactory]: AvatarIsWearing called for {0}", client.AgentId);

            // operate on a copy of the appearance so we don't have to lock anything
            IAvatarAppearanceModule appearance = sp.RequestModuleInterface<IAvatarAppearanceModule>();
            AvatarAppearance avatAppearance = new AvatarAppearance(appearance.Appearance, false);

            IOpenRegionSettingsModule module = m_scene.RequestModuleInterface<IOpenRegionSettingsModule>();

            bool NeedsRebake = false;
            if (module != null && module.EnableTeenMode)
            {
                foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
                {
                    if (wear.Type == 10 & wear.ItemID == UUID.Zero && module.DefaultUnderpants != UUID.Zero)
                    {
                        NeedsRebake = true;
                        wear.ItemID = module.DefaultUnderpants;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Underpants",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0,
                                                         CreatorId = UUID.Zero.ToString(),
                                                         AssetID = module.DefaultUnderpants
                                                     };
                        //Locked
                        client.SendInventoryItemCreateUpdate(item, 0);
                    }
                    else if (wear.Type == 10 & wear.ItemID == UUID.Zero)
                    {
                        NeedsRebake = true;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Underpants",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0
                                                     };
                        //Locked
                        if (m_underPantsUUID == UUID.Zero)
                        {
                            m_underPantsUUID = UUID.Random();
                            AssetBase asset = new AssetBase(m_underPantsUUID, "Default Underpants", AssetType.Clothing,
                                                            UUID.Zero) {Data = Utils.StringToBytes(m_defaultUnderPants)};
                            asset.FillHash();
                            asset.ID = m_scene.AssetService.Store(asset);
                            m_underPantsUUID = asset.ID;
                        }
                        item.CreatorId = UUID.Zero.ToString();
                        item.AssetID = m_underPantsUUID;
                        m_scene.InventoryService.AddItem(item);
                        client.SendInventoryItemCreateUpdate(item, 0);
                        wear.ItemID = item.ID;
                    }
                    if (wear.Type == 11 && wear.ItemID == UUID.Zero && module.DefaultUndershirt != UUID.Zero)
                    {
                        NeedsRebake = true;
                        wear.ItemID = module.DefaultUndershirt;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Undershirt",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0,
                                                         CreatorId = UUID.Zero.ToString(),
                                                         AssetID = module.DefaultUndershirt
                                                     };
                        //Locked
                        client.SendInventoryItemCreateUpdate(item, 0);
                    }
                    else if (wear.Type == 11 & wear.ItemID == UUID.Zero)
                    {
                        NeedsRebake = true;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Undershirt",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0
                                                     };
                        //Locked
                        if (m_underShirtUUID == UUID.Zero)
                        {
                            m_underShirtUUID = UUID.Random();
                            AssetBase asset = new AssetBase(m_underShirtUUID, "Default Undershirt", AssetType.Clothing,
                                                            UUID.Zero) {Data = Utils.StringToBytes(m_defaultUnderShirt)};
                            asset.FillHash();
                            asset.ID = m_scene.AssetService.Store(asset);
                            m_underShirtUUID = asset.ID;
                        }
                        item.CreatorId = UUID.Zero.ToString();
                        item.AssetID = m_underShirtUUID;
                        m_scene.InventoryService.AddItem(item);
                        client.SendInventoryItemCreateUpdate(item, 0);
                        wear.ItemID = item.ID;
                    }
                }
            }

#if (!ISWIN)
            foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
            {
                if (wear.Type < AvatarWearable.MAX_WEARABLES)
                {
                    /*if (incomingLinks.ContainsKey (wear.ItemID))
                    {
                        wear.ItemID = incomingLinks[wear.ItemID];
                    }*/
                    avatAppearance.Wearables[wear.Type].Add(wear.ItemID, UUID.Zero);
                }
            }
#else
            foreach (AvatarWearingArgs.Wearable wear in e.NowWearing.Where(wear => wear.Type < AvatarWearable.MAX_WEARABLES))
            {
                avatAppearance.Wearables[wear.Type].Add(wear.ItemID, UUID.Zero);
            }
#endif

            avatAppearance.GetAssetsFrom(appearance.Appearance);

            // This could take awhile since it needs to pull inventory
            SetAppearanceAssets(sp.UUID, ref avatAppearance);

            // could get fancier with the locks here, but in the spirit of "last write wins"
            // this should work correctly, also, we don't need to send the appearance here
            // since the "iswearing" will trigger a new set of visual param and baked texture changes
            // when those complete, the new appearance will be sent
            appearance.Appearance = avatAppearance;
            if (NeedsRebake)
            {
                //Tell the client about the new things it is wearing
                sp.ControllingClient.SendWearables(appearance.Appearance.Wearables, appearance.Appearance.Serial);
                //Then forcefully tell it to rebake
#if (!ISWIN)
                foreach (Primitive.TextureEntryFace t in appearance.Appearance.Texture.FaceTextures)
                {
                    Primitive.TextureEntryFace face = (t);
                    if (face != null)
                    {
                        sp.ControllingClient.SendRebakeAvatarTextures(face.TextureID);
                    }
                }
#else
                foreach (Primitive.TextureEntryFace face in appearance.Appearance.Texture.FaceTextures.Select(t => (t)).Where(face => face != null))
                {
                    sp.ControllingClient.SendRebakeAvatarTextures(face.TextureID);
                }
#endif
            }
            QueueAppearanceSave(sp.UUID);
            //Send the wearables HERE so that the client knows what it is wearing
            //sp.ControllingClient.SendWearables(sp.Appearance.Wearables, sp.Appearance.Serial);
            //Do not save or send the appearance! The client loops back and sends a bunch of SetAppearance
            //  (handled above) and that takes care of it
        }
        /// <summary>
        /// Update what the avatar is wearing using an item from their inventory.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void AvatarIsWearing(Object sender, AvatarWearingArgs e)
        {
            IClientAPI    clientView = (IClientAPI)sender;
            ScenePresence avatar     = m_scene.GetScenePresence(clientView.AgentId);

            if (avatar == null)
            {
                m_log.Error("[APPEARANCE]: Avatar is child agent, ignoring AvatarIsWearing event");
                return;
            }

            CachedUserInfo profile = m_scene.CommsManager.UserService.GetUserDetails(clientView.AgentId);

            if (profile != null)
            {
                AvatarAppearance appearance = avatar.Appearance;

                // we need to clean out the existing textures
                appearance.Texture = AvatarAppearance.GetDefaultTexture();

                List <AvatarWearable> wearables = new List <AvatarWearable>();
                lock (_currentlyWaitingCOFBuilds)
                {
                    //Check to see whether the client can manage itself
                    if (_cofSyncEnabled && !_viewer2Users.Contains(clientView.AgentId))
                    {
                        foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
                        {
                            wearables.Add(new AvatarWearable(wear.Type, wear.ItemID, UUID.Zero));
                            AvatarWearable oldWearable = appearance.GetWearableOfType(wear.Type);
                            if (wear.ItemID != UUID.Zero)
                            {
                                if (oldWearable == null || oldWearable.ItemID == UUID.Zero || wear.ItemID != oldWearable.ItemID)
                                {
                                    bool add = false;
                                    Dictionary <UUID, BuildCOF> waitingCOFs = new Dictionary <UUID, BuildCOF>();
                                    if ((add = !_currentlyWaitingCOFBuilds.TryGetValue(clientView.AgentId, out waitingCOFs)))
                                    {
                                        waitingCOFs = new Dictionary <UUID, BuildCOF>();
                                    }
                                    //Make sure that the new item is added
                                    if (waitingCOFs.ContainsKey(wear.ItemID))
                                    {
                                        BuildCOF cof = waitingCOFs[wear.ItemID];
                                        cof.SetWearableToLookFor(wear.ItemID, m_scene, clientView.AgentId, true);
                                        if (cof.Finished())
                                        {
                                            waitingCOFs.Remove(wear.ItemID);
                                        }
                                    }
                                    else
                                    {
                                        BuildCOF cof = new BuildCOF(ClearWaitingCOF);
                                        cof.SetWearableToLookFor(wear.ItemID, m_scene, clientView.AgentId, true);
                                        waitingCOFs.Add(wear.ItemID, cof);
                                    }
                                    if (add)
                                    {
                                        _currentlyWaitingCOFBuilds.Add(clientView.AgentId, waitingCOFs);
                                    }
                                }
                                if (oldWearable != null && oldWearable.ItemID != UUID.Zero && wear.ItemID != oldWearable.ItemID)
                                {
                                    bool add = false;
                                    Dictionary <UUID, BuildCOF> waitingCOFs = new Dictionary <UUID, BuildCOF>();
                                    if ((add = !_currentlyWaitingCOFBuilds.TryGetValue(clientView.AgentId, out waitingCOFs)))
                                    {
                                        waitingCOFs = new Dictionary <UUID, BuildCOF>();
                                    }
                                    //Check for removal of old item
                                    if (waitingCOFs.ContainsKey(oldWearable.ItemID))
                                    {
                                        BuildCOF cof = waitingCOFs[oldWearable.ItemID];
                                        cof.SetWearableToLookFor(oldWearable.ItemID, m_scene, clientView.AgentId, false);
                                        if (cof.Finished())
                                        {
                                            waitingCOFs.Remove(oldWearable.ItemID);
                                        }
                                    }
                                    else
                                    {
                                        BuildCOF cof = new BuildCOF(ClearWaitingCOF);
                                        cof.SetWearableToLookFor(oldWearable.ItemID, m_scene, clientView.AgentId, false);
                                        waitingCOFs.Add(oldWearable.ItemID, cof);
                                    }
                                    if (add)
                                    {
                                        _currentlyWaitingCOFBuilds.Add(clientView.AgentId, waitingCOFs);
                                    }
                                }
                            }
                            else if (oldWearable != null && oldWearable.ItemID != UUID.Zero)
                            {
                                bool add = false;
                                Dictionary <UUID, BuildCOF> waitingCOFs = new Dictionary <UUID, BuildCOF>();
                                if ((add = !_currentlyWaitingCOFBuilds.TryGetValue(clientView.AgentId, out waitingCOFs)))
                                {
                                    waitingCOFs = new Dictionary <UUID, BuildCOF>();
                                }
                                //Remove the item if it was just removed
                                if (waitingCOFs.ContainsKey(oldWearable.ItemID))
                                {
                                    BuildCOF cof = waitingCOFs[oldWearable.ItemID];
                                    cof.SetWearableToLookFor(oldWearable.ItemID, m_scene, clientView.AgentId, false);
                                    if (cof.Finished())
                                    {
                                        waitingCOFs.Remove(oldWearable.ItemID);
                                    }
                                }
                                else
                                {
                                    BuildCOF cof = new BuildCOF(ClearWaitingCOF);
                                    cof.SetWearableToLookFor(oldWearable.ItemID, m_scene, clientView.AgentId, false);
                                    waitingCOFs.Add(oldWearable.ItemID, cof);
                                }
                                if (add)
                                {
                                    _currentlyWaitingCOFBuilds.Add(clientView.AgentId, waitingCOFs);
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
                        {
                            wearables.Add(new AvatarWearable(wear.Type, wear.ItemID, UUID.Zero));
                        }
                    }
                }
                // Wearables are a stack. The entries we have represent the current "top" stack state.  Apply them

                SetAppearanceAssets(profile, ref wearables, clientView);
                avatar.Appearance.SetWearables(wearables);
                this.UpdateDatabase(clientView.AgentId, avatar.Appearance, null, null);
            }
            else
            {
                m_log.WarnFormat("[APPEARANCE]: Cannot set wearables for {0}, no user profile found", clientView.Name);
            }
        }
Exemple #33
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(client.AgentId);
                return;
            }

            appearance = aCircuit.Appearance;
            if (appearance == null)
            {
                m_log.DebugFormat("[APPEARANCE]: Appearance not found in {0}, returning default", RegionInfo.RegionName);
                appearance = new AvatarAppearance(client.AgentId);
            }
        }
Exemple #34
0
 /// </summary>
 /// <param name="sp"></param>
 /// <param name="texture"></param>
 /// <param name="visualParam"></param>
 public void SetAppearance(IScenePresence sp, AvatarAppearance appearance)
 {
     SetAppearance(sp, appearance.Texture, appearance.VisualParams);
 }
        public void setup()
        {
            AgentId = UUID.Random();
            BaseFolder = UUID.Random();
            CapsPath = "http://www.opensimulator.org/Caps/Foo";
            ChildrenCapsPaths = new Dictionary<ulong, string>();
            ChildrenCapsPaths.Add(ulong.MaxValue, "http://www.opensimulator.org/Caps/Foo2");
            firstname = "CoolAvatarTest";
            lastname = "test";
            StartPos = new Vector3(5,23,125);

            SecureSessionId = UUID.Random();
            SessionId = UUID.Random();

            AvAppearance = new AvatarAppearance(AgentId);
            VisualParams = new byte[218];

            //body
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HEIGHT] = 155;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_THICKNESS] = 00;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BODY_FAT] = 0;

            //Torso
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_TORSO_MUSCLES] = 48;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_NECK_THICKNESS] = 43;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_NECK_LENGTH] = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SHOULDERS] = 94;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_CHEST_MALE_NO_PECS] = 199;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_ARM_LENGTH] = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HAND_SIZE] = 33;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_TORSO_LENGTH] = 240;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LOVE_HANDLES] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BELLY_SIZE] = 0;

            // legs
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LEG_MUSCLES] = 82;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LEG_LENGTH] = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HIP_WIDTH] = 84;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HIP_LENGTH] = 166;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BUTT_SIZE] = 64;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SADDLEBAGS] = 89;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BOWED_LEGS] = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_FOOT_SIZE] = 45;


            // head 
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HEAD_SIZE] = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SQUASH_STRETCH_HEAD] = 0; // head stretch
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HEAD_SHAPE] = 155;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EGG_HEAD] = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_POINTY_EARS] = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HEAD_LENGTH] = 45;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_FACE_SHEAR] = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_FOREHEAD_ANGLE] = 104;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BIG_BROW] = 94;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_PUFFY_UPPER_CHEEKS] = 0; //  upper cheeks 
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_DOUBLE_CHIN] = 122; //  lower cheeks
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HIGH_CHEEK_BONES] = 130;



            // eyes
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYE_SIZE] = 105;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WIDE_EYES] = 135;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYE_SPACING] = 184;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYELID_CORNER_UP] = 230;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYELID_INNER_CORNER_UP] = 120;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYE_DEPTH] = 158;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_UPPER_EYELID_FOLD] = 69;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BAGGY_EYES] = 38;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYELASHES_LONG] = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_POP_EYE] = 127;

            VisualParams[(int)AvatarAppearance.VPElement.EYES_EYE_COLOR] = 25;
            VisualParams[(int)AvatarAppearance.VPElement.EYES_EYE_LIGHTNESS] = 127;

            // ears
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BIG_EARS] = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EARS_OUT] = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_ATTACHED_EARLOBES] = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_POINTY_EARS] = 255;

            // nose
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_NOSE_BIG_OUT] = 79;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WIDE_NOSE] = 35;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BROAD_NOSTRILS] = 86;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LOW_SEPTUM_NOSE] = 112; // nostril division
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BULBOUS_NOSE] = 25;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_NOBLE_NOSE_BRIDGE] = 25; // upper bridge
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LOWER_BRIDGE_NOSE] = 25; // lower bridge
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WIDE_NOSE_BRIDGE] = 25;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_UPTURNED_NOSE_TIP] = 107;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BULBOUS_NOSE_TIP] = 25;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_CROOKED_NOSE] = 127;


            // Mouth
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LIP_WIDTH] = 122;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_TALL_LIPS] = 10; // lip fullness
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LIP_THICKNESS] = 112;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LIP_RATIO] = 137;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MOUTH_HEIGHT] = 176;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MOUTH_CORNER] = 140; // Sad --> happy
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LIP_CLEFT_DEEP] = 84;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WIDE_LIP_CLEFT] = 84;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SHIFT_MOUTH] = 127;


            // chin
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WEAK_CHIN] = 119;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SQUARE_JAW] = 5;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_DEEP_CHIN] = 132;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_JAW_ANGLE] = 153;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_JAW_JUT] = 100;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_JOWLS] = 38;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_CLEFT_CHIN] = 89;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_CLEFT_CHIN_UPPER] = 89;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_DOUBLE_CHIN] = 0;


            // hair color
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_WHITE_HAIR] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_RAINBOW_COLOR_39] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_BLONDE_HAIR] = 24;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_RED_HAIR] = 0;

            // hair style
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_VOLUME] = 160;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_FRONT] = 153;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SIDES] = 153;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_BACK] = 170;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_BIG_FRONT] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_BIG_TOP] = 117;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_BIG_BACK] = 170;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_FRONT_FRINGE] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_SIDE_FRINGE] = 142;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_BACK_FRINGE] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SIDES_FULL] = 146;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SWEEP] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SHEAR_FRONT] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SHEAR_BACK] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_TAPER_FRONT] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_TAPER_BACK] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_RUMPLED] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_PIGTAILS] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_PONYTAIL] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SPIKED] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_TILT] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_PART_MIDDLE] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_PART_RIGHT] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_PART_LEFT] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_BANGS_PART_MIDDLE] = 155;

            //Eyebrows
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_EYEBROW_SIZE] = 20;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_EYEBROW_DENSITY] = 140;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_LOWER_EYEBROWS] = 200; // eyebrow height
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_ARCED_EYEBROWS] = 124;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_POINTY_EYEBROWS] = 65;

            //Facial hair
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_THICKNESS] = 65;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_SIDEBURNS] = 235;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_MOUSTACHE] = 75;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_CHIN_CURTAINS] = 140;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_SOULPATCH] = 0;

            AvAppearance.VisualParams = VisualParams;

            List<byte> wearbyte = new List<byte>();
            for (int i = 0; i < VisualParams.Length; i++)
            {
                wearbyte.Add(VisualParams[i]);
            }

            AvAppearance.SetAppearance(AvAppearance.Texture, (byte[])VisualParams.Clone());
        }
Exemple #36
0
 public void SendAppearance(AvatarAppearance app, Vector3 hover)
 {
 }
Exemple #37
0
 public abstract void UpdateUserAppearance(UUID user, AvatarAppearance appearance);
Exemple #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["roothandle"] != null)
            {
                roothandle = args["roothandle"].AsULong();
            }
            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();
            }
            if (args["draw_distance"] != null)
            {
                DrawDistance = args["draw_distance"];
            }

            // DEBUG ON
            //MainConsole.Instance.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
                    //MainConsole.Instance.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance");
                    // DEBUG OFF
                }
                // DEBUG ON
                else
                {
                    MainConsole.Instance.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance, dne ? " +
                                              !args.ContainsKey("packed_appearance"));
                }
                // DEBUG OFF
            }
            catch (Exception e)
            {
                MainConsole.Instance.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}", e);
            }

            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]);
                }
            }
        }
 public virtual void UpdateUserAppearance(UUID uuid, AvatarAppearance appearance)
 {
     m_storage.UpdateUserAppearance(uuid, appearance);
 }
Exemple #40
0
        protected void CreateDefaultAppearanceEntries(UUID principalID)
        {
            m_log.DebugFormat("[USER ACCOUNT SERVICE]: Creating default appearance items for {0}", principalID);

            InventoryFolderBase bodyPartsFolder = m_InventoryService.GetFolderForType(principalID, AssetType.Bodypart);

            InventoryItemBase eyes = new InventoryItemBase(UUID.Random(), principalID);

            eyes.AssetID             = new UUID("4bb6fa4d-1cd2-498a-a84c-95c1a0e745a7");
            eyes.Name                = "Default Eyes";
            eyes.CreatorId           = principalID.ToString();
            eyes.AssetType           = (int)AssetType.Bodypart;
            eyes.InvType             = (int)InventoryType.Wearable;
            eyes.Folder              = bodyPartsFolder.ID;
            eyes.BasePermissions     = (uint)PermissionMask.All;
            eyes.CurrentPermissions  = (uint)PermissionMask.All;
            eyes.EveryOnePermissions = (uint)PermissionMask.All;
            eyes.GroupPermissions    = (uint)PermissionMask.All;
            eyes.NextPermissions     = (uint)PermissionMask.All;
            eyes.Flags               = (uint)WearableType.Eyes;
            m_InventoryService.AddItem(eyes);

            InventoryItemBase shape = new InventoryItemBase(UUID.Random(), principalID);

            shape.AssetID             = AvatarWearable.DEFAULT_BODY_ASSET;
            shape.Name                = "Default Shape";
            shape.CreatorId           = principalID.ToString();
            shape.AssetType           = (int)AssetType.Bodypart;
            shape.InvType             = (int)InventoryType.Wearable;
            shape.Folder              = bodyPartsFolder.ID;
            shape.BasePermissions     = (uint)PermissionMask.All;
            shape.CurrentPermissions  = (uint)PermissionMask.All;
            shape.EveryOnePermissions = (uint)PermissionMask.All;
            shape.GroupPermissions    = (uint)PermissionMask.All;
            shape.NextPermissions     = (uint)PermissionMask.All;
            shape.Flags               = (uint)WearableType.Shape;
            m_InventoryService.AddItem(shape);

            InventoryItemBase skin = new InventoryItemBase(UUID.Random(), principalID);

            skin.AssetID             = AvatarWearable.DEFAULT_SKIN_ASSET;
            skin.Name                = "Default Skin";
            skin.CreatorId           = principalID.ToString();
            skin.AssetType           = (int)AssetType.Bodypart;
            skin.InvType             = (int)InventoryType.Wearable;
            skin.Folder              = bodyPartsFolder.ID;
            skin.BasePermissions     = (uint)PermissionMask.All;
            skin.CurrentPermissions  = (uint)PermissionMask.All;
            skin.EveryOnePermissions = (uint)PermissionMask.All;
            skin.GroupPermissions    = (uint)PermissionMask.All;
            skin.NextPermissions     = (uint)PermissionMask.All;
            skin.Flags               = (uint)WearableType.Skin;
            m_InventoryService.AddItem(skin);

            InventoryItemBase hair = new InventoryItemBase(UUID.Random(), principalID);

            hair.AssetID             = AvatarWearable.DEFAULT_HAIR_ASSET;
            hair.Name                = "Default Hair";
            hair.CreatorId           = principalID.ToString();
            hair.AssetType           = (int)AssetType.Bodypart;
            hair.InvType             = (int)InventoryType.Wearable;
            hair.Folder              = bodyPartsFolder.ID;
            hair.BasePermissions     = (uint)PermissionMask.All;
            hair.CurrentPermissions  = (uint)PermissionMask.All;
            hair.EveryOnePermissions = (uint)PermissionMask.All;
            hair.GroupPermissions    = (uint)PermissionMask.All;
            hair.NextPermissions     = (uint)PermissionMask.All;
            hair.Flags               = (uint)WearableType.Hair;
            m_InventoryService.AddItem(hair);

            InventoryFolderBase clothingFolder = m_InventoryService.GetFolderForType(principalID, AssetType.Clothing);

            InventoryItemBase shirt = new InventoryItemBase(UUID.Random(), principalID);

            shirt.AssetID             = AvatarWearable.DEFAULT_SHIRT_ASSET;
            shirt.Name                = "Default Shirt";
            shirt.CreatorId           = principalID.ToString();
            shirt.AssetType           = (int)AssetType.Clothing;
            shirt.InvType             = (int)InventoryType.Wearable;
            shirt.Folder              = clothingFolder.ID;
            shirt.BasePermissions     = (uint)PermissionMask.All;
            shirt.CurrentPermissions  = (uint)PermissionMask.All;
            shirt.EveryOnePermissions = (uint)PermissionMask.All;
            shirt.GroupPermissions    = (uint)PermissionMask.All;
            shirt.NextPermissions     = (uint)PermissionMask.All;
            shirt.Flags               = (uint)WearableType.Shirt;
            m_InventoryService.AddItem(shirt);

            InventoryItemBase pants = new InventoryItemBase(UUID.Random(), principalID);

            pants.AssetID             = AvatarWearable.DEFAULT_PANTS_ASSET;
            pants.Name                = "Default Pants";
            pants.CreatorId           = principalID.ToString();
            pants.AssetType           = (int)AssetType.Clothing;
            pants.InvType             = (int)InventoryType.Wearable;
            pants.Folder              = clothingFolder.ID;
            pants.BasePermissions     = (uint)PermissionMask.All;
            pants.CurrentPermissions  = (uint)PermissionMask.All;
            pants.EveryOnePermissions = (uint)PermissionMask.All;
            pants.GroupPermissions    = (uint)PermissionMask.All;
            pants.NextPermissions     = (uint)PermissionMask.All;
            pants.Flags               = (uint)WearableType.Pants;
            m_InventoryService.AddItem(pants);

            if (m_AvatarService != null)
            {
                m_log.DebugFormat("[USER ACCOUNT SERVICE]: Creating default avatar entries for {0}", principalID);

                AvatarWearable[] wearables = new AvatarWearable[6];
                wearables[AvatarWearable.EYES]  = new AvatarWearable(eyes.ID, eyes.AssetID);
                wearables[AvatarWearable.BODY]  = new AvatarWearable(shape.ID, shape.AssetID);
                wearables[AvatarWearable.SKIN]  = new AvatarWearable(skin.ID, skin.AssetID);
                wearables[AvatarWearable.HAIR]  = new AvatarWearable(hair.ID, hair.AssetID);
                wearables[AvatarWearable.SHIRT] = new AvatarWearable(shirt.ID, shirt.AssetID);
                wearables[AvatarWearable.PANTS] = new AvatarWearable(pants.ID, pants.AssetID);

                AvatarAppearance ap = new AvatarAppearance();
                for (int i = 0; i < 6; i++)
                {
                    ap.SetWearable(i, wearables[i]);
                }

                m_AvatarService.SetAppearance(principalID, ap);
            }
        }
 public AvatarAppearance GetAndEnsureAppearance(UUID principalID, string defaultUserAvatarArchive, out bool loadedArchive)
 {
     loadedArchive = false;
     AvatarAppearance avappearance = GetAppearance(principalID);
     if (avappearance == null)
     {
         //Create an appearance for the user if one doesn't exist
         if (defaultUserAvatarArchive != "")
         {
             AvatarArchive arch = m_ArchiveService.LoadAvatarArchive(defaultUserAvatarArchive, principalID);
             if (arch != null)
             {
                 avappearance = arch.Appearance;
                 SetAppearance(principalID, avappearance);
                 loadedArchive = true;
             }
         }
         if(avappearance == null)//Set as ruth
         {
             avappearance = new AvatarAppearance(principalID);
             SetAppearance(principalID, avappearance);
         }
     }
     return avappearance;
 }
Exemple #42
0
        /// <summary>
        /// Login procedure, as copied from superclass.
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="passwd"></param>
        /// <param name="startLocation"></param>
        /// <param name="scopeID"></param>
        /// <param name="clientVersion"></param>
        /// <param name="clientIP">The very important TCP/IP EndPoint of the client</param>
        /// <returns></returns>
        /// <remarks>You need to change bits and pieces of this method</remarks>
        public new LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID,
                                       string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP)
        {
            bool success = false;
            UUID session = UUID.Random();

            try
            {
                //
                // Get the account and check that it exists
                //
                UserAccount account = m_UserAccountService.GetUserAccount(scopeID, firstName, lastName);
                if (account == null)
                {
                    // Account doesn't exist. Is this a user from an external ID provider?
                    //
                    // <your code here>
                    //
                    // After verification, your code should create a UserAccount object, filled out properly.
                    // Do not store that account object persistently; we don't want to be creating local accounts
                    // for external users! Create and fill out a UserAccount object, because it has the information
                    // that the rest of the code needs.

                    m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: user not found");
                    return(LLFailedLoginResponse.UserProblem);
                }

                if (account.UserLevel < m_MinLoginLevel)
                {
                    m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: login is blocked for user level {0}", account.UserLevel);
                    return(LLFailedLoginResponse.LoginBlockedProblem);
                }

                // If a scope id is requested, check that the account is in
                // that scope, or unscoped.
                //
                if (scopeID != UUID.Zero)
                {
                    if (account.ScopeID != scopeID && account.ScopeID != UUID.Zero)
                    {
                        m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: user not found");
                        return(LLFailedLoginResponse.UserProblem);
                    }
                }
                else
                {
                    scopeID = account.ScopeID;
                }

                //
                // Authenticate this user
                //
                // Local users and external users will need completely different authentication procedures.
                // The piece of code below is for local users who authenticate with a password.
                //
                if (!passwd.StartsWith("$1$"))
                {
                    passwd = "$1$" + Util.Md5Hash(passwd);
                }
                passwd = passwd.Remove(0, 3); //remove $1$
                string token         = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30);
                UUID   secureSession = UUID.Zero;
                if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession)))
                {
                    m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: authentication failed");
                    return(LLFailedLoginResponse.UserProblem);
                }

                //
                // Get the user's inventory
                //
                // m_RequireInventory is set to false in .ini, therefore inventory is not required for login.
                // If you want to change this state of affairs and let external users have local inventory,
                // you need to think carefully about how to do that.
                //
                if (m_RequireInventory && m_InventoryService == null)
                {
                    m_log.WarnFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: inventory service not set up");
                    return(LLFailedLoginResponse.InventoryProblem);
                }
                List <InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
                if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)))
                {
                    m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: unable to retrieve user inventory");
                    return(LLFailedLoginResponse.InventoryProblem);
                }

                if (inventorySkel == null)
                {
                    inventorySkel = new List <InventoryFolderBase>();
                }

                // Get active gestures
                List <InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(account.PrincipalID);
                m_log.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count);

                //
                // From here on, things should be exactly the same for all users
                //

                //
                // Login the presence
                //
                if (m_PresenceService != null)
                {
                    success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession);
                    if (!success)
                    {
                        m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: could not login presence");
                        return(LLFailedLoginResponse.GridProblem);
                    }
                }

                //
                // Change Online status and get the home region
                //
                GridRegion   home   = null;
                GridUserInfo guinfo = m_GridUserService.LoggedIn(account.PrincipalID.ToString());
                if (guinfo != null && (guinfo.HomeRegionID != UUID.Zero) && m_GridService != null)
                {
                    home = m_GridService.GetRegionByUUID(scopeID, guinfo.HomeRegionID);
                }
                if (guinfo == null)
                {
                    // something went wrong, make something up, so that we don't have to test this anywhere else
                    guinfo = new GridUserInfo();
                    guinfo.LastPosition = guinfo.HomePosition = new Vector3(128, 128, 30);
                }

                //
                // Find the destination region/grid
                //
                string where = string.Empty;
                Vector3       position    = Vector3.Zero;
                Vector3       lookAt      = Vector3.Zero;
                GridRegion    gatekeeper  = null;
                TeleportFlags flags       = TeleportFlags.Default;
                GridRegion    destination = FindDestination(account, scopeID, guinfo, session, startLocation, home, out gatekeeper, out where, out position, out lookAt, out flags);
                if (destination == null)
                {
                    m_PresenceService.LogoutAgent(session);
                    m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: destination not found");
                    return(LLFailedLoginResponse.GridProblem);
                }

                //
                // Get the avatar
                //
                AvatarAppearance avatar = null;
                if (m_AvatarService != null)
                {
                    avatar = m_AvatarService.GetAppearance(account.PrincipalID);
                }

                //
                // Instantiate/get the simulation interface and launch an agent at the destination
                //
                string           reason   = string.Empty;
                GridRegion       dest     = null;
                AgentCircuitData aCircuit = LaunchAgentAtGrid(gatekeeper, destination, account, avatar, session, secureSession, position, where,
                                                              clientVersion, channel, mac, id0, clientIP, flags, out where, out reason, out dest);

                if (aCircuit == null)
                {
                    m_PresenceService.LogoutAgent(session);
                    m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: {0}", reason);
                    return(new LLFailedLoginResponse("key", reason, "false"));
                }
                // Get Friends list
                FriendInfo[] friendsList = new FriendInfo[0];
                if (m_FriendsService != null)
                {
                    friendsList = m_FriendsService.GetFriends(account.PrincipalID);
                    m_log.DebugFormat("[DIVA LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length);
                }

                //
                // Finally, fill out the response and return it
                //
                LLLoginResponse response = new LLLoginResponse(account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService,
                                                               where, startLocation, position, lookAt, gestures, m_WelcomeMessage, home, clientIP, m_MapTileURL, m_SearchURL, m_Currency);

                m_log.DebugFormat("[DIVA LLOGIN SERVICE]: All clear. Sending login response to client.");
                return(response);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[DIVA LLOGIN SERVICE]: Exception processing login for {0} {1}: {2} {3}", firstName, lastName, e.ToString(), e.StackTrace);
                if (m_PresenceService != null)
                {
                    m_PresenceService.LogoutAgent(session);
                }
                return(LLFailedLoginResponse.InternalError);
            }
        }
 public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) {}
Exemple #44
0
        /// <summary>
        ///     Update what the avatar is wearing using an item from their inventory.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="e"></param>
        public void AvatarIsWearing(IClientAPI client, AvatarWearingArgs e)
        {
            IScenePresence sp = m_scene.GetScenePresence(client.AgentId);

            if (sp == null)
            {
                MainConsole.Instance.WarnFormat("[AvatarFactory]: AvatarIsWearing unable to find presence for {0}",
                                                client.AgentId);
                return;
            }

            MainConsole.Instance.DebugFormat("[AvatarFactory]: AvatarIsWearing called for {0}", client.AgentId);

            // operate on a copy of the appearance so we don't have to lock anything
            IAvatarAppearanceModule appearance     = sp.RequestModuleInterface <IAvatarAppearanceModule> ();
            AvatarAppearance        avatAppearance = new AvatarAppearance(appearance.Appearance, false);

            #region Teen Mode Stuff

            IOpenRegionSettingsModule module = m_scene.RequestModuleInterface <IOpenRegionSettingsModule> ();

            bool NeedsRebake = false;
            if (module != null && module.EnableTeenMode)
            {
                foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
                {
                    if (wear.Type == 10 & wear.ItemID == UUID.Zero && module.DefaultUnderpants != UUID.Zero)
                    {
                        NeedsRebake = true;
                        wear.ItemID = module.DefaultUnderpants;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                        {
                            InvType   = (int)InventoryType.Wearable,
                            AssetType = (int)AssetType.Clothing,
                            Name      = "Default Underpants",
                            Folder    =
                                m_scene.InventoryService.GetFolderForType(client.AgentId, InventoryType.Wearable, FolderType.Clothing).ID,
                            Owner = client.AgentId,
                            CurrentPermissions = 0,
                            CreatorId          = UUID.Zero.ToString(),
                            AssetID            = module.DefaultUnderpants
                        };
                        //Locked
                        client.SendInventoryItemCreateUpdate(item, 0);
                    }
                    else if (wear.Type == 10 & wear.ItemID == UUID.Zero)
                    {
                        NeedsRebake = true;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                        {
                            InvType   = (int)InventoryType.Wearable,
                            AssetType = (int)AssetType.Clothing,
                            Name      = "Default Underpants",
                            Folder    =
                                m_scene.InventoryService.GetFolderForType(client.AgentId, InventoryType.Wearable, FolderType.Clothing).ID,
                            Owner = client.AgentId,
                            CurrentPermissions = 0
                        };
                        //Locked
                        if (m_underPantsUUID == UUID.Zero)
                        {
                            m_underPantsUUID = UUID.Random();
                            AssetBase asset = new AssetBase(m_underPantsUUID, "Default Underpants", AssetType.Clothing,
                                                            UUID.Zero)
                            {
                                Data = Utils.StringToBytes(m_defaultUnderPants)
                            };
                            asset.ID         = m_scene.AssetService.Store(asset);
                            m_underPantsUUID = asset.ID;
                        }
                        item.CreatorId = UUID.Zero.ToString();
                        item.AssetID   = m_underPantsUUID;
                        m_scene.InventoryService.AddItemAsync(item, null);
                        client.SendInventoryItemCreateUpdate(item, 0);
                        wear.ItemID = item.ID;
                    }
                    if (wear.Type == 11 && wear.ItemID == UUID.Zero && module.DefaultUndershirt != UUID.Zero)
                    {
                        NeedsRebake = true;
                        wear.ItemID = module.DefaultUndershirt;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                        {
                            InvType   = (int)InventoryType.Wearable,
                            AssetType = (int)AssetType.Clothing,
                            Name      = "Default Undershirt",
                            Folder    =
                                m_scene.InventoryService.GetFolderForType(client.AgentId, InventoryType.Wearable, FolderType.Clothing).ID,
                            Owner = client.AgentId,
                            CurrentPermissions = 0,
                            CreatorId          = UUID.Zero.ToString(),
                            AssetID            = module.DefaultUndershirt
                        };
                        //Locked
                        client.SendInventoryItemCreateUpdate(item, 0);
                    }
                    else if (wear.Type == 11 & wear.ItemID == UUID.Zero)
                    {
                        NeedsRebake = true;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                        {
                            InvType   = (int)InventoryType.Wearable,
                            AssetType = (int)AssetType.Clothing,
                            Name      = "Default Undershirt",
                            Folder    =
                                m_scene.InventoryService.GetFolderForType(client.AgentId, InventoryType.Wearable, FolderType.Clothing).ID,
                            Owner = client.AgentId,
                            CurrentPermissions = 0
                        };
                        //Locked
                        if (m_underShirtUUID == UUID.Zero)
                        {
                            m_underShirtUUID = UUID.Random();
                            AssetBase asset = new AssetBase(m_underShirtUUID, "Default Undershirt", AssetType.Clothing,
                                                            UUID.Zero)
                            {
                                Data = Utils.StringToBytes(m_defaultUnderShirt)
                            };
                            asset.ID         = m_scene.AssetService.Store(asset);
                            m_underShirtUUID = asset.ID;
                        }
                        item.CreatorId = UUID.Zero.ToString();
                        item.AssetID   = m_underShirtUUID;
                        m_scene.InventoryService.AddItemAsync(item, null);
                        client.SendInventoryItemCreateUpdate(item, 0);
                        wear.ItemID = item.ID;
                    }
                }
            }

            #endregion

            foreach (
                AvatarWearingArgs.Wearable wear in e.NowWearing.Where(wear => wear.Type < AvatarWearable.MAX_WEARABLES))
            {
                avatAppearance.Wearables [wear.Type].Add(wear.ItemID, UUID.Zero);
            }

            avatAppearance.GetAssetsFrom(appearance.Appearance);

            // This could take awhile since it needs to pull inventory
            SetAppearanceAssets(sp.UUID, e.NowWearing, appearance.Appearance, ref avatAppearance);

            // could get fancier with the locks here, but in the spirit of "last write wins"
            // this should work correctly, also, we don't need to send the appearance here
            // since the "iswearing" will trigger a new set of visual param and baked texture changes
            // when those complete, the new appearance will be sent
            appearance.Appearance = avatAppearance;

            //This only occurs if something has been forced on afterwards (teen mode stuff)
            if (NeedsRebake)
            {
                //Tell the client about the new things it is wearing
                sp.ControllingClient.SendWearables(appearance.Appearance.Wearables, appearance.Appearance.Serial);
                //Then forcefully tell it to rebake
                foreach (
                    Primitive.TextureEntryFace face in
                    appearance.Appearance.Texture.FaceTextures.Select(t => (t)).Where(face => face != null))
                {
                    sp.ControllingClient.SendRebakeAvatarTextures(face.TextureID);
                }
            }

            QueueAppearanceSave(sp.UUID);
            //Send the wearables HERE so that the client knows what it is wearing
            //sp.ControllingClient.SendWearables(sp.Appearance.Wearables, sp.Appearance.Serial);
            //Do not save or send the appearance! The client loops back and sends a bunch of SetAppearance
            //  (handled above) and that takes care of it
        }
        private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source,
            AvatarAppearance avatarAppearance,
            InventoryFolderBase destinationFolder, UUID agentid,
            OSDMap itemsMap,
            out List<InventoryItemBase> items)
        {
            if (destinationFolder == null)
                throw new Exception("Cannot locate folder(s)");
            items = new List<InventoryItemBase>();

            List<InventoryItemBase> litems = new List<InventoryItemBase>();
            foreach (KeyValuePair<string, OSD> kvp in itemsMap)
            {
                InventoryItemBase item = new InventoryItemBase();
                item.FromOSD((OSDMap)kvp.Value);
                MainConsole.Instance.Info("[AvatarArchive]: Loading item " + item.ID.ToString());
                litems.Add(item);
            }

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

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

                        if (item == null)
                        {
                            //Attempt to get from the map if it doesn't already exist on the grid
                            item = litems.First((itm) => itm.ID == wearable[ii].ItemID);
                        }
                        if (item != null)
                        {
                            InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                        destination,
                                                                                                        item,
                                                                                                        destinationFolder
                                                                                                            .ID,
                                                                                                        false, false);
                            items.Add(destinationItem);
                            MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}",
                                                             destinationItem.ID, destinationFolder.ID);

                            // Wear item
                            AvatarWearable newWearable = new AvatarWearable();
                            newWearable.Wear(destinationItem.ID, destinationItem.AssetID);
                            avatarAppearance.SetWearable(i, newWearable);
                        }
                        else
                        {
                            MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}",
                                                            wearable[ii].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 = InventoryService.GetItem(UUID.Zero, itemID);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                    destination, item,
                                                                                                    destinationFolder.ID,
                                                                                                    false, false);
                        items.Add(destinationItem);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID,
                                                         destinationFolder.ID);

                        // Attach item
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                    else
                    {
                        MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID,
                                                        destinationFolder.ID);
                    }
                }
            }
            return avatarAppearance;
        }
Exemple #46
0
 public UUID CreateNPC(string firstname, string lastname,
                       Vector3 position, UUID owner, bool senseAsAgent, Scene scene,
                       AvatarAppearance appearance)
 {
     return(CreateNPC(firstname, lastname, position, UUID.Zero, owner, "", UUID.Zero, senseAsAgent, scene, appearance));
 }
Exemple #47
0
        protected AgentCircuitData LaunchAgentAtGrid(GridRegion destination, TeleportFlags tpFlags, UserAccount account, AvatarAppearance appearance,
            UUID session, UUID secureSession, Vector3 position, string currentWhere,
            IPEndPoint clientIP, out string where, out string reason, out GridRegion dest)
        {
            where = currentWhere;
            reason = string.Empty;
            uint circuitCode = 0;
            AgentCircuitData aCircuit = null;
            dest = destination;

            bool success = false;

            #region Launch Agent

            circuitCode = (uint)Util.RandomClass.Next(); ;
            aCircuit = MakeAgent(destination, account, appearance, session, secureSession, circuitCode, position, clientIP);
            aCircuit.teleportFlags = (uint)tpFlags;
            success = LaunchAgentDirectly(destination, ref aCircuit, out reason);
            if (!success && m_GridService != null)
            {
                //Remove the landmark flag (landmark is used for ignoring the landing points in the region)
                aCircuit.teleportFlags &= ~(uint)TeleportFlags.ViaLandmark;
                m_GridService.SetRegionUnsafe(destination.RegionID);

                // Make sure the client knows this isn't where they wanted to land
                where = "safe";

                // Try the default regions
                List<GridRegion> defaultRegions = m_GridService.GetDefaultRegions(account.ScopeID);
                if (defaultRegions != null)
                {
                    success = TryFindGridRegionForAgentLogin(defaultRegions, account,
                        appearance, session, secureSession, circuitCode, position,
                        clientIP, aCircuit, out dest);
                }
                if (!success)
                {
                    // Try the fallback regions
                    List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
                    if (fallbacks != null)
                    {
                        success = TryFindGridRegionForAgentLogin(fallbacks, account,
                            appearance, session, secureSession, circuitCode, position,
                            clientIP, aCircuit, out dest);
                    }
                    if (!success)
                    {
                        //Try to find any safe region
                        List<GridRegion> safeRegions = m_GridService.GetSafeRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
                        if (safeRegions != null)
                        {
                            success = TryFindGridRegionForAgentLogin(safeRegions, account,
                                appearance, session, secureSession, circuitCode, position,
                                clientIP, aCircuit, out dest);
                            if (!success)
                                reason = "No Region Found";
                        }
                    }
                }
            }

            #endregion

            if (success)
            {
                //Set the region to safe since we got there
                m_GridService.SetRegionSafe (destination.RegionID);
                return aCircuit;
            }
            else
                return null;
        }
Exemple #48
0
        public UUID CreateNPC(string firstname, string lastname,
                              Vector3 position, UUID agentID, UUID owner, string groupTitle, UUID groupID, bool senseAsAgent, Scene scene,
                              AvatarAppearance appearance)
        {
            NPCAvatar npcAvatar = null;
            string    born      = DateTime.UtcNow.ToString();

            try
            {
                if (agentID == UUID.Zero)
                {
                    npcAvatar = new NPCAvatar(firstname, lastname, position,
                                              owner, senseAsAgent, scene);
                }
                else
                {
                    npcAvatar = new NPCAvatar(firstname, lastname, agentID, position,
                                              owner, senseAsAgent, scene);
                }
            }
            catch (Exception e)
            {
                m_log.Info("[NPC MODULE]: exception creating NPC avatar: " + e.ToString());
                return(UUID.Zero);
            }

            npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
                                                                int.MaxValue);

//            m_log.DebugFormat(
//                "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
//                firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName);

            AgentCircuitData acd = new AgentCircuitData();

            acd.AgentID     = npcAvatar.AgentId;
            acd.firstname   = firstname;
            acd.lastname    = lastname;
            acd.ServiceURLs = new Dictionary <string, object>();

            AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);

            acd.Appearance = npcAppearance;

            /*
             * for (int i = 0;
             *      i < acd.Appearance.Texture.FaceTextures.Length; i++)
             * {
             *  m_log.DebugFormat(
             *          "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
             *          acd.AgentID, i,
             *          acd.Appearance.Texture.FaceTextures[i]);
             * }
             */

//            ManualResetEvent ev = new ManualResetEvent(false);

//            Util.FireAndForget(delegate(object x) {
            lock (m_avatars)
            {
                scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
                scene.AddNewAgent(npcAvatar, PresenceType.Npc);

                ScenePresence sp;
                if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
                {
                    npcAvatar.Born          = born;
                    npcAvatar.ActiveGroupId = groupID;
                    sp.CompleteMovement(npcAvatar, false);
                    sp.Grouptitle = groupTitle;
                    m_avatars.Add(npcAvatar.AgentId, npcAvatar);
//                        m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);
                }
            }
//                ev.Set();
//            });

//            ev.WaitOne();

//            m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId);

            return(npcAvatar.AgentId);
        }
Exemple #49
0
        protected AgentCircuitData MakeAgent(GridRegion region, UserAccount account,
            AvatarAppearance appearance, UUID session, UUID secureSession, uint circuit, Vector3 position,
            IPEndPoint clientIP)
        {
            AgentCircuitData aCircuit = new AgentCircuitData();

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

            aCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
            aCircuit.child = false; // the first login agent is root
            aCircuit.circuitcode = circuit;
            aCircuit.SecureSessionID = secureSession;
            aCircuit.SessionID = session;
            aCircuit.startpos = position;
            aCircuit.IPAddress = clientIP.Address.ToString();
            aCircuit.ClientIPEndPoint = clientIP;

            return aCircuit;
        }
Exemple #50
0
        public AvatarAppearance ToAvatarAppearance()
        {
            AvatarAppearance appearance = new AvatarAppearance();

            if (Data.Count == 0)
            {
                return(appearance);
            }

            appearance.ClearWearables();
            try
            {
                if (Data.ContainsKey("Serial"))
                {
                    appearance.Serial = Int32.Parse(Data["Serial"]);
                }

                if (Data.ContainsKey("AvatarHeight"))
                {
                    float h = float.Parse(Data["AvatarHeight"]);
                    if (h == 0f)
                    {
                        h = 1.9f;
                    }
                    appearance.SetSize(new Vector3(0.45f, 0.6f, h));
                }

                // Legacy Wearables
                if (Data.ContainsKey("BodyItem"))
                {
                    appearance.Wearables[AvatarWearable.BODY].Wear(
                        UUID.Parse(Data["BodyItem"]),
                        UUID.Parse(Data["BodyAsset"]));
                }

                if (Data.ContainsKey("SkinItem"))
                {
                    appearance.Wearables[AvatarWearable.SKIN].Wear(
                        UUID.Parse(Data["SkinItem"]),
                        UUID.Parse(Data["SkinAsset"]));
                }

                if (Data.ContainsKey("HairItem"))
                {
                    appearance.Wearables[AvatarWearable.HAIR].Wear(
                        UUID.Parse(Data["HairItem"]),
                        UUID.Parse(Data["HairAsset"]));
                }

                if (Data.ContainsKey("EyesItem"))
                {
                    appearance.Wearables[AvatarWearable.EYES].Wear(
                        UUID.Parse(Data["EyesItem"]),
                        UUID.Parse(Data["EyesAsset"]));
                }

                if (Data.ContainsKey("ShirtItem"))
                {
                    appearance.Wearables[AvatarWearable.SHIRT].Wear(
                        UUID.Parse(Data["ShirtItem"]),
                        UUID.Parse(Data["ShirtAsset"]));
                }

                if (Data.ContainsKey("PantsItem"))
                {
                    appearance.Wearables[AvatarWearable.PANTS].Wear(
                        UUID.Parse(Data["PantsItem"]),
                        UUID.Parse(Data["PantsAsset"]));
                }

                if (Data.ContainsKey("ShoesItem"))
                {
                    appearance.Wearables[AvatarWearable.SHOES].Wear(
                        UUID.Parse(Data["ShoesItem"]),
                        UUID.Parse(Data["ShoesAsset"]));
                }

                if (Data.ContainsKey("SocksItem"))
                {
                    appearance.Wearables[AvatarWearable.SOCKS].Wear(
                        UUID.Parse(Data["SocksItem"]),
                        UUID.Parse(Data["SocksAsset"]));
                }

                if (Data.ContainsKey("JacketItem"))
                {
                    appearance.Wearables[AvatarWearable.JACKET].Wear(
                        UUID.Parse(Data["JacketItem"]),
                        UUID.Parse(Data["JacketAsset"]));
                }

                if (Data.ContainsKey("GlovesItem"))
                {
                    appearance.Wearables[AvatarWearable.GLOVES].Wear(
                        UUID.Parse(Data["GlovesItem"]),
                        UUID.Parse(Data["GlovesAsset"]));
                }

                if (Data.ContainsKey("UnderShirtItem"))
                {
                    appearance.Wearables[AvatarWearable.UNDERSHIRT].Wear(
                        UUID.Parse(Data["UnderShirtItem"]),
                        UUID.Parse(Data["UnderShirtAsset"]));
                }

                if (Data.ContainsKey("UnderPantsItem"))
                {
                    appearance.Wearables[AvatarWearable.UNDERPANTS].Wear(
                        UUID.Parse(Data["UnderPantsItem"]),
                        UUID.Parse(Data["UnderPantsAsset"]));
                }

                if (Data.ContainsKey("SkirtItem"))
                {
                    appearance.Wearables[AvatarWearable.SKIRT].Wear(
                        UUID.Parse(Data["SkirtItem"]),
                        UUID.Parse(Data["SkirtAsset"]));
                }

                if (Data.ContainsKey("VisualParams"))
                {
                    string[] vps    = Data["VisualParams"].Split(new char[] { ',' });
                    byte[]   binary = new byte[vps.Length];

                    for (int i = 0; i < vps.Length; i++)
                    {
                        binary[i] = (byte)Convert.ToInt32(vps[i]);
                    }

                    appearance.VisualParams = binary;
                }

                AvatarWearable[] wearables = appearance.Wearables;
                int currentLength          = wearables.Length;
                foreach (KeyValuePair <string, string> _kvp in Data)
                {
                    // New style wearables
                    if (_kvp.Key.StartsWith("Wearable ") && _kvp.Key.Length > 9)
                    {
                        string   wearIndex   = _kvp.Key.Substring(9);
                        string[] wearIndices = wearIndex.Split(new char[] { ':' });
                        int      index       = Convert.ToInt32(wearIndices[0]);

                        string[] ids     = _kvp.Value.Split(new char[] { ':' });
                        UUID     itemID  = new UUID(ids[0]);
                        UUID     assetID = new UUID(ids[1]);
                        if (index >= currentLength)
                        {
                            Array.Resize(ref wearables, index + 1);
                            for (int i = currentLength; i < wearables.Length; i++)
                            {
                                wearables[i] = new AvatarWearable();
                            }
                            currentLength = wearables.Length;
                        }
                        wearables[index].Add(itemID, assetID);
                        continue;
                    }
                    // Attachments
                    if (_kvp.Key.StartsWith("_ap_") && _kvp.Key.Length > 4)
                    {
                        string pointStr = _kvp.Key.Substring(4);
                        int    point    = 0;
                        if (Int32.TryParse(pointStr, out point))
                        {
                            List <string> idList = new List <string>(_kvp.Value.Split(new char[] { ',' }));

                            appearance.SetAttachment(point, UUID.Zero, UUID.Zero);
                            foreach (string id in idList)
                            {
                                UUID uuid = UUID.Zero;
                                if (UUID.TryParse(id, out uuid))
                                {
                                    appearance.SetAttachment(point | 0x80, uuid, UUID.Zero);
                                }
                            }
                        }
                    }
                }

                if (appearance.Wearables[AvatarWearable.BODY].Count == 0)
                {
                    appearance.Wearables[AvatarWearable.BODY].Wear(
                        AvatarWearable.DefaultWearables[
                            AvatarWearable.BODY][0]);
                }

                if (appearance.Wearables[AvatarWearable.SKIN].Count == 0)
                {
                    appearance.Wearables[AvatarWearable.SKIN].Wear(
                        AvatarWearable.DefaultWearables[
                            AvatarWearable.SKIN][0]);
                }

                if (appearance.Wearables[AvatarWearable.HAIR].Count == 0)
                {
                    appearance.Wearables[AvatarWearable.HAIR].Wear(
                        AvatarWearable.DefaultWearables[
                            AvatarWearable.HAIR][0]);
                }

                if (appearance.Wearables[AvatarWearable.EYES].Count == 0)
                {
                    appearance.Wearables[AvatarWearable.EYES].Wear(
                        AvatarWearable.DefaultWearables[
                            AvatarWearable.EYES][0]);
                }
            }
            catch
            {
                // We really should report something here, returning null
                // will at least break the wrapper
                return(null);
            }

            return(appearance);
        }
Exemple #51
0
 private void LoadAssets(OSDMap assets, AvatarAppearance appearance)
 {
     foreach (KeyValuePair<string, OSD> kvp in assets)
     {
         UUID AssetID = UUID.Parse(kvp.Key);
         OSDMap assetMap = (OSDMap)kvp.Value;
         AssetBase asset = AssetService.Get(AssetID.ToString());
         m_log.Info("[AvatarArchive]: Loading asset " + AssetID.ToString());
         if (asset == null) //Don't overwrite
         {
             asset = LoadAssetBase(assetMap);
             UUID oldassetID = asset.ID;
             UUID newAssetID = AssetService.Store(asset);
             asset.ID = newAssetID;
             //Fix the IDs
             AvatarWearable[] wearables = new AvatarWearable[appearance.Wearables.Length];
             appearance.Wearables.CopyTo(wearables, 0);
             for (int a = 0; a < wearables.Length; a++)
             {
                 for (int i = 0; i < wearables[a].Count; i++)
                 {
                     if (wearables[a][i].AssetID == oldassetID)
                     {
                         //Fix the ItemID
                         AvatarWearable w = wearables[a];
                         UUID itemID = w.GetItem(oldassetID);
                         w.RemoveItem(oldassetID);
                         w.Add(itemID, newAssetID);
                         appearance.SetWearable(a, w);
                         break;
                     }
                 }
             }
         }
     }
 }
Exemple #52
0
        public AvatarAppearance ToAvatarAppearance(UUID owner)
        {
            AvatarAppearance appearance = new AvatarAppearance(owner);

            if (Data.Count == 0)
            {
                return(appearance);
            }

            appearance.ClearWearables();
            try
            {
                if (Data.ContainsKey("Serial"))
                {
                    appearance.Serial = Int32.Parse(Data["Serial"]);
                }

                if (Data.ContainsKey("AvatarHeight"))
                {
                    appearance.AvatarHeight = float.Parse(Data["AvatarHeight"]);
                }

                // Legacy Wearables
                if (Data.ContainsKey("BodyItem"))
                {
                    appearance.Wearables[AvatarWearable.BODY].Wear(
                        UUID.Parse(Data["BodyItem"]),
                        UUID.Parse(Data["BodyAsset"]));
                }

                if (Data.ContainsKey("SkinItem"))
                {
                    appearance.Wearables[AvatarWearable.SKIN].Wear(
                        UUID.Parse(Data["SkinItem"]),
                        UUID.Parse(Data["SkinAsset"]));
                }

                if (Data.ContainsKey("HairItem"))
                {
                    appearance.Wearables[AvatarWearable.HAIR].Wear(
                        UUID.Parse(Data["HairItem"]),
                        UUID.Parse(Data["HairAsset"]));
                }

                if (Data.ContainsKey("EyesItem"))
                {
                    appearance.Wearables[AvatarWearable.EYES].Wear(
                        UUID.Parse(Data["EyesItem"]),
                        UUID.Parse(Data["EyesAsset"]));
                }

                if (Data.ContainsKey("ShirtItem"))
                {
                    appearance.Wearables[AvatarWearable.SHIRT].Wear(
                        UUID.Parse(Data["ShirtItem"]),
                        UUID.Parse(Data["ShirtAsset"]));
                }

                if (Data.ContainsKey("PantsItem"))
                {
                    appearance.Wearables[AvatarWearable.PANTS].Wear(
                        UUID.Parse(Data["PantsItem"]),
                        UUID.Parse(Data["PantsAsset"]));
                }

                if (Data.ContainsKey("ShoesItem"))
                {
                    appearance.Wearables[AvatarWearable.SHOES].Wear(
                        UUID.Parse(Data["ShoesItem"]),
                        UUID.Parse(Data["ShoesAsset"]));
                }

                if (Data.ContainsKey("SocksItem"))
                {
                    appearance.Wearables[AvatarWearable.SOCKS].Wear(
                        UUID.Parse(Data["SocksItem"]),
                        UUID.Parse(Data["SocksAsset"]));
                }

                if (Data.ContainsKey("JacketItem"))
                {
                    appearance.Wearables[AvatarWearable.JACKET].Wear(
                        UUID.Parse(Data["JacketItem"]),
                        UUID.Parse(Data["JacketAsset"]));
                }

                if (Data.ContainsKey("GlovesItem"))
                {
                    appearance.Wearables[AvatarWearable.GLOVES].Wear(
                        UUID.Parse(Data["GlovesItem"]),
                        UUID.Parse(Data["GlovesAsset"]));
                }

                if (Data.ContainsKey("UnderShirtItem"))
                {
                    appearance.Wearables[AvatarWearable.UNDERSHIRT].Wear(
                        UUID.Parse(Data["UnderShirtItem"]),
                        UUID.Parse(Data["UnderShirtAsset"]));
                }

                if (Data.ContainsKey("UnderPantsItem"))
                {
                    appearance.Wearables[AvatarWearable.UNDERPANTS].Wear(
                        UUID.Parse(Data["UnderPantsItem"]),
                        UUID.Parse(Data["UnderPantsAsset"]));
                }

                if (Data.ContainsKey("SkirtItem"))
                {
                    appearance.Wearables[AvatarWearable.SKIRT].Wear(
                        UUID.Parse(Data["SkirtItem"]),
                        UUID.Parse(Data["SkirtAsset"]));
                }


                if (Data.ContainsKey("VisualParams"))
                {
                    string[] vps    = Data["VisualParams"].Split(new[] { ',' });
                    byte[]   binary = new byte[AvatarAppearance.VISUALPARAM_COUNT];

                    for (int i = 0; i < vps.Length && i < binary.Length; i++)
                    {
                        binary[i] = (byte)Convert.ToInt32(vps[i]);
                    }

                    appearance.VisualParams = binary;
                }

                if (Data.ContainsKey("Textures"))
                {
                    string t   = Data["Textures"];
                    OSD    tex = OSDParser.DeserializeJson(t);
                    appearance.Texture = Primitive.TextureEntry.FromOSD(tex);
                }

                // New style wearables
                foreach (KeyValuePair <string, string> _kvp in Data)
                {
                    if (_kvp.Key.StartsWith("Wearable "))
                    {
                        string   wearIndex   = _kvp.Key.Substring(9);
                        string[] wearIndices = wearIndex.Split(new[] { ':' });
                        int      index       = Convert.ToInt32(wearIndices[0]);

                        string[] ids     = _kvp.Value.Split(new[] { ':' });
                        UUID     itemID  = new UUID(ids[0]);
                        UUID     assetID = new UUID(ids[1]);

                        appearance.Wearables[index].Add(itemID, assetID);
                    }
                }


                // Attachments
                Dictionary <string, string> attchs       = new Dictionary <string, string>();
                Dictionary <string, string> attchsAssets = new Dictionary <string, string>();
#if (!ISWIN)
                foreach (KeyValuePair <string, string> _kvp in Data)
                {
                    if (_kvp.Key.StartsWith("_ap_"))
                    {
                        attchs[_kvp.Key] = _kvp.Value;
                    }
                    if (_kvp.Key.StartsWith("_apa_"))
                    {
                        attchsAssets[_kvp.Key] = _kvp.Value;
                    }
                }
#else
                foreach (KeyValuePair <string, string> _kvp in Data.Where(_kvp => _kvp.Key.StartsWith("_ap_")))
                {
                    attchs[_kvp.Key] = _kvp.Value;
                }
#endif

                foreach (KeyValuePair <string, string> _kvp in attchs)
                {
                    string pointStr = _kvp.Key.Substring(4);
                    int    point    = 0;
                    if (!Int32.TryParse(pointStr, out point))
                    {
                        continue;
                    }

                    UUID uuid = UUID.Zero;
                    UUID.TryParse(_kvp.Value, out uuid);
                    UUID assetuuid = UUID.Zero;
                    if (attchsAssets.ContainsKey(_kvp.Key))
                    {
                        UUID.TryParse(attchsAssets[_kvp.Key], out uuid);
                    }

                    appearance.SetAttachment(point, uuid, assetuuid);
                }

                if (appearance.Wearables[AvatarWearable.BODY].Count == 0)
                {
                    appearance.Wearables[AvatarWearable.BODY].Wear(
                        AvatarWearable.DefaultWearables[
                            AvatarWearable.BODY][0]);
                }

                if (appearance.Wearables[AvatarWearable.SKIN].Count == 0)
                {
                    appearance.Wearables[AvatarWearable.SKIN].Wear(
                        AvatarWearable.DefaultWearables[
                            AvatarWearable.SKIN][0]);
                }

                if (appearance.Wearables[AvatarWearable.HAIR].Count == 0)
                {
                    appearance.Wearables[AvatarWearable.HAIR].Wear(
                        AvatarWearable.DefaultWearables[
                            AvatarWearable.HAIR][0]);
                }

                if (appearance.Wearables[AvatarWearable.EYES].Count == 0)
                {
                    appearance.Wearables[AvatarWearable.EYES].Wear(
                        AvatarWearable.DefaultWearables[
                            AvatarWearable.EYES][0]);
                }
            }
            catch
            {
                // We really should report something here, returning null
                // will at least break the wrapper
                return(null);
            }

            return(appearance);
        }
Exemple #53
0
 private void FixItemIDs(UUID oldID, InventoryItemBase item, AvatarAppearance appearance)
 {
     //Fix the IDs
     AvatarWearable[] wearables = new AvatarWearable[appearance.Wearables.Length];
     appearance.Wearables.CopyTo(wearables, 0);
     for (int a = 0; a < wearables.Length; a++)
     {
         for (int i = 0; i < wearables[a].Count; i++)
         {
             if (wearables[a][i].ItemID == oldID)
             {
                 //Fix the ItemID
                 AvatarWearable w = new AvatarWearable();
                 w.Unpack((OSDArray)wearables[a].Pack());
                 UUID assetID = w.GetAsset(oldID);
                 w.RemoveItem(oldID);
                 w.Add(item.ID, assetID);
                 appearance.SetWearable(a, w);
                 return;
             }
         }
     }
 }
        public void setup()
        {
            AgentId           = UUID.Random();
            BaseFolder        = UUID.Random();
            CapsPath          = "http://www.opensimulator.org/Caps/Foo";
            ChildrenCapsPaths = new Dictionary <ulong, string>();
            ChildrenCapsPaths.Add(ulong.MaxValue, "http://www.opensimulator.org/Caps/Foo2");
            firstname = "CoolAvatarTest";
            lastname  = "test";
            StartPos  = new Vector3(5, 23, 125);

            SecureSessionId = UUID.Random();
            SessionId       = UUID.Random();

            AvAppearance = new AvatarAppearance();
            VisualParams = new byte[218];

            //body
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HEIGHT]    = 155;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_THICKNESS] = 00;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BODY_FAT]  = 0;

            //Torso
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_TORSO_MUSCLES]      = 48;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_NECK_THICKNESS]     = 43;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_NECK_LENGTH]        = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SHOULDERS]          = 94;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_CHEST_MALE_NO_PECS] = 199;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_ARM_LENGTH]         = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HAND_SIZE]          = 33;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_TORSO_LENGTH]       = 240;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LOVE_HANDLES]       = 0;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BELLY_SIZE]         = 0;

            // legs
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LEG_MUSCLES] = 82;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LEG_LENGTH]  = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HIP_WIDTH]   = 84;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HIP_LENGTH]  = 166;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BUTT_SIZE]   = 64;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SADDLEBAGS]  = 89;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BOWED_LEGS]  = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_FOOT_SIZE]   = 45;

            // head
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HEAD_SIZE]           = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SQUASH_STRETCH_HEAD] = 0; // head stretch
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HEAD_SHAPE]          = 155;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EGG_HEAD]            = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_POINTY_EARS]         = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HEAD_LENGTH]         = 45;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_FACE_SHEAR]          = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_FOREHEAD_ANGLE]      = 104;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BIG_BROW]            = 94;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_PUFFY_UPPER_CHEEKS]  = 0;   //  upper cheeks
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_DOUBLE_CHIN]         = 122; //  lower cheeks
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HIGH_CHEEK_BONES]    = 130;

            // eyes
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYE_SIZE]               = 105;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WIDE_EYES]              = 135;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYE_SPACING]            = 184;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYELID_CORNER_UP]       = 230;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYELID_INNER_CORNER_UP] = 120;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYE_DEPTH]              = 158;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_UPPER_EYELID_FOLD]      = 69;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BAGGY_EYES]             = 38;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EYELASHES_LONG]         = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_POP_EYE] = 127;

            VisualParams[(int)AvatarAppearance.VPElement.EYES_EYE_COLOR]     = 25;
            VisualParams[(int)AvatarAppearance.VPElement.EYES_EYE_LIGHTNESS] = 127;

            // ears
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BIG_EARS]          = 255;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_EARS_OUT]          = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_ATTACHED_EARLOBES] = 127;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_POINTY_EARS]       = 255;

            // nose
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_NOSE_BIG_OUT]      = 79;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WIDE_NOSE]         = 35;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BROAD_NOSTRILS]    = 86;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LOW_SEPTUM_NOSE]   = 112; // nostril division
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BULBOUS_NOSE]      = 25;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_NOBLE_NOSE_BRIDGE] = 25;  // upper bridge
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LOWER_BRIDGE_NOSE] = 25;  // lower bridge
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WIDE_NOSE_BRIDGE]  = 25;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_UPTURNED_NOSE_TIP] = 107;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_BULBOUS_NOSE_TIP]  = 25;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_CROOKED_NOSE]      = 127;

            // Mouth
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LIP_WIDTH]      = 122;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_TALL_LIPS]      = 10; // lip fullness
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LIP_THICKNESS]  = 112;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LIP_RATIO]      = 137;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MOUTH_HEIGHT]   = 176;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MOUTH_CORNER]   = 140; // Sad --> happy
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_LIP_CLEFT_DEEP] = 84;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WIDE_LIP_CLEFT] = 84;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SHIFT_MOUTH]    = 127;

            // chin
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_WEAK_CHIN]        = 119;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_SQUARE_JAW]       = 5;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_DEEP_CHIN]        = 132;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_JAW_ANGLE]        = 153;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_JAW_JUT]          = 100;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_JOWLS]            = 38;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_CLEFT_CHIN]       = 89;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_CLEFT_CHIN_UPPER] = 89;
            VisualParams[(int)AvatarAppearance.VPElement.SHAPE_DOUBLE_CHIN]      = 0;

            // hair color
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_WHITE_HAIR]       = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_RAINBOW_COLOR_39] = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_BLONDE_HAIR]      = 24;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_RED_HAIR]         = 0;

            // hair style
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_VOLUME]       = 160;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_FRONT]        = 153;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SIDES]        = 153;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_BACK]         = 170;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_BIG_FRONT]    = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_BIG_TOP]      = 117;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_BIG_BACK]     = 170;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_FRONT_FRINGE]      = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_SIDE_FRINGE]       = 142;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_BACK_FRINGE]       = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SIDES_FULL]   = 146;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SWEEP]        = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SHEAR_FRONT]  = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SHEAR_BACK]   = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_TAPER_FRONT]  = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_TAPER_BACK]   = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_RUMPLED]      = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_PIGTAILS]          = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_PONYTAIL]          = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_SPIKED]       = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_TILT]         = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_PART_MIDDLE]  = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_PART_RIGHT]   = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_PART_LEFT]    = 0;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_BANGS_PART_MIDDLE] = 155;

            //Eyebrows
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_EYEBROW_SIZE]    = 20;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_EYEBROW_DENSITY] = 140;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_LOWER_EYEBROWS]  = 200; // eyebrow height
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_ARCED_EYEBROWS]  = 124;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_POINTY_EYEBROWS] = 65;

            //Facial hair
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_HAIR_THICKNESS] = 65;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_SIDEBURNS]      = 235;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_MOUSTACHE]      = 75;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_CHIN_CURTAINS]  = 140;
            VisualParams[(int)AvatarAppearance.VPElement.HAIR_SOULPATCH]      = 0;

            AvAppearance.VisualParams = VisualParams;

            List <byte> wearbyte = new List <byte>();

            for (int i = 0; i < VisualParams.Length; i++)
            {
                wearbyte.Add(VisualParams[i]);
            }

            AvAppearance.SetAppearance(AvAppearance.Texture, (byte[])VisualParams.Clone());
        }
Exemple #55
0
        public void FixCurrentOutFitFolder(UUID user, ref AvatarAppearance avappearance)
        {
            InventoryFolderBase CurrentOutFitFolder = m_InventoryService.GetFolderForType(user, 0,
                                                                                          AssetType.CurrentOutfitFolder);
            if (CurrentOutFitFolder == null) return;
            List<InventoryItemBase> ic = m_InventoryService.GetFolderItems(user, CurrentOutFitFolder.ID);
            List<UUID> brokenLinks = new List<UUID>();
            List<UUID> OtherStuff = new List<UUID>();
            foreach (var i in ic)
            {
                InventoryItemBase linkedItem = null;
                if ((linkedItem = m_InventoryService.GetItem(user, i.AssetID)) == null)
                    brokenLinks.Add(i.ID);
                else if (linkedItem.ID == AvatarWearable.DEFAULT_EYES_ITEM ||
                         linkedItem.ID == AvatarWearable.DEFAULT_BODY_ITEM ||
                         linkedItem.ID == AvatarWearable.DEFAULT_HAIR_ITEM ||
                         linkedItem.ID == AvatarWearable.DEFAULT_PANTS_ITEM ||
                         linkedItem.ID == AvatarWearable.DEFAULT_SHIRT_ITEM ||
                         linkedItem.ID == AvatarWearable.DEFAULT_SKIN_ITEM)
                    brokenLinks.Add(i.ID); //Default item link, needs removed
                else if (!OtherStuff.Contains(i.AssetID))
                    OtherStuff.Add(i.AssetID);
            }

            for (int i = 0; i < avappearance.Wearables.Length; i++)
            {
                AvatarWearable wearable = avappearance.Wearables[i];
                for (int ii = 0; ii < wearable.Count; ii++)
                {
                    if (!OtherStuff.Contains(wearable[ii].ItemID))
                    {
                        InventoryItemBase linkedItem2 = null;
                        if ((linkedItem2 = m_InventoryService.GetItem(user, wearable[ii].ItemID)) != null)
                        {
                            InventoryItemBase linkedItem3 = (InventoryItemBase) linkedItem2.Clone();
                            linkedItem3.AssetID = linkedItem2.ID;
                            linkedItem3.AssetType = (int) AssetType.Link;
                            linkedItem3.ID = UUID.Random();
                            linkedItem3.CurrentPermissions = linkedItem2.NextPermissions;
                            linkedItem3.EveryOnePermissions = linkedItem2.NextPermissions;
                            linkedItem3.Folder = CurrentOutFitFolder.ID;
                            m_InventoryService.AddItem(linkedItem3);
                        }
                        else
                        {
                            avappearance.Wearables[i] = AvatarWearable.DefaultWearables[i];
                        }
                    }
                }
            }

            List<UUID> items2UnAttach = new List<UUID>();
            foreach (KeyValuePair<int, List<AvatarAttachment>> attachmentSpot in avappearance.Attachments)
            {
                foreach (AvatarAttachment attachment in attachmentSpot.Value)
                {
                    if (!OtherStuff.Contains(attachment.ItemID))
                    {
                        InventoryItemBase linkedItem2 = null;
                        if ((linkedItem2 = m_InventoryService.GetItem(user, attachment.ItemID)) != null)
                        {
                            InventoryItemBase linkedItem3 = (InventoryItemBase) linkedItem2.Clone();
                            linkedItem3.AssetID = linkedItem2.ID;
                            linkedItem3.AssetType = (int) AssetType.Link;
                            linkedItem3.ID = UUID.Random();
                            linkedItem3.CurrentPermissions = linkedItem2.NextPermissions;
                            linkedItem3.EveryOnePermissions = linkedItem2.NextPermissions;
                            linkedItem3.Folder = CurrentOutFitFolder.ID;
                            m_InventoryService.AddItem(linkedItem3);
                        }
                        else
                            items2UnAttach.Add(attachment.ItemID);
                    }
                }
            }

            foreach (UUID uuid in items2UnAttach)
            {
                avappearance.DetachAttachment(uuid);
            }

            if (brokenLinks.Count != 0)
                m_InventoryService.DeleteItems(user, brokenLinks);
        }
Exemple #56
0
        public UUID CreateNPC(string firstname, string lastname,
                              Vector3 position, UUID owner, bool senseAsAgent, Scene scene,
                              AvatarAppearance appearance)
        {
            NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position,
                                                owner, senseAsAgent, scene);

            npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
                                                                int.MaxValue);

            m_log.DebugFormat(
                "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
                firstname, lastname, npcAvatar.AgentId, owner,
                senseAsAgent, position, scene.RegionInfo.RegionName);

            AgentCircuitData acd = new AgentCircuitData();

            acd.AgentID     = npcAvatar.AgentId;
            acd.firstname   = firstname;
            acd.lastname    = lastname;
            acd.ServiceURLs = new Dictionary <string, object>();

            AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
                                                                  true);

            acd.Appearance = npcAppearance;

            /*
             * for (int i = 0;
             *      i < acd.Appearance.Texture.FaceTextures.Length; i++)
             * {
             *  m_log.DebugFormat(
             *          "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
             *          acd.AgentID, i,
             *          acd.Appearance.Texture.FaceTextures[i]);
             * }
             */

            lock (m_avatars)
            {
                scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
                                                        acd);
                scene.AddNewClient(npcAvatar, PresenceType.Npc);

                ScenePresence sp;
                if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
                {
                    /*
                     * m_log.DebugFormat(
                     *      "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}",
                     *      sp.Name, sp.UUID);
                     */

                    sp.CompleteMovement(npcAvatar, false);

                    /*
                     * If the parameters gave us a group title to force all NPCs to,
                     * and the firstname does not contain the exclude string
                     * and the lastname does not contain the exclude string,
                     * set the NPCs group title to the given string and send it to
                     * all connected viewers.
                     *
                     * This must be done before adding to m_avatars as once so added,
                     * the group title cannot be changed.
                     */
                    if ((npcGroupTitle != "") &&
                        !firstname.Contains(npcGroupTitleExcludeName) &&
                        !lastname.Contains(npcGroupTitleExcludeName))
                    {
                        sp.Grouptitle = npcGroupTitle;
                        sp.SendAvatarDataToAllAgents();
                    }

                    m_avatars.Add(npcAvatar.AgentId, npcAvatar);
                    m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}",
                                      npcAvatar.AgentId, sp.Name);

                    return(npcAvatar.AgentId);
                }
                else
                {
                    m_log.WarnFormat(
                        "[NPC MODULE]: Could not find scene presence for NPC {0} {1}",
                        sp.Name, sp.UUID);
                    return(UUID.Zero);
                }
            }
        }
Exemple #57
0
        public AvatarAppearance WearFolder(AvatarAppearance avappearance, UUID user, UUID folderOwnerID)
        {
            InventoryFolderBase Folder2Wear = m_InventoryService.GetFolderByOwnerAndName(folderOwnerID,
                                                                                         m_forceUserToWearFolderName);
            if (Folder2Wear != null)
            {
                List<InventoryItemBase> itemsInFolder = m_InventoryService.GetFolderItems(UUID.Zero, Folder2Wear.ID);

                InventoryFolderBase appearanceFolder = m_InventoryService.GetFolderForType(user, InventoryType.Wearable,
                                                                                           AssetType.Clothing);

                InventoryFolderBase folderForAppearance = new InventoryFolderBase(UUID.Random(), "GridWear", user, -1,
                                                                                  appearanceFolder.ID, 1);
                List<InventoryFolderBase> userFolders = m_InventoryService.GetFolderFolders(user, appearanceFolder.ID);
                bool alreadyThere = false;
                List<UUID> items2RemoveFromAppearence = new List<UUID>();
                List<UUID> toDelete = new List<UUID>();
                foreach (InventoryFolderBase folder in userFolders)
                {
                    if (folder.Name == folderForAppearance.Name)
                    {
                        List<InventoryItemBase> itemsInCurrentFolder = m_InventoryService.GetFolderItems(UUID.Zero,
                                                                                                         folder.ID);
                        foreach (InventoryItemBase itemBase in itemsInCurrentFolder)
                        {
                            items2RemoveFromAppearence.Add(itemBase.AssetID);
                            items2RemoveFromAppearence.Add(itemBase.ID);
                            toDelete.Add(itemBase.ID);
                        }
                        folderForAppearance = folder;
                        alreadyThere = true;
                        m_InventoryService.DeleteItems(user, toDelete);
                        break;
                    }
                }

                if (!alreadyThere)
                    m_InventoryService.AddFolder(folderForAppearance);
                else
                {
                    // we have to remove all the old items if they are currently wearing them
                    for (int i = 0; i < avappearance.Wearables.Length; i++)
                    {
                        AvatarWearable wearable = avappearance.Wearables[i];
                        for (int ii = 0; ii < wearable.Count; ii++)
                        {
                            if (items2RemoveFromAppearence.Contains(wearable[ii].ItemID))
                            {
                                avappearance.Wearables[i] = AvatarWearable.DefaultWearables[i];
                                break;
                            }
                        }
                    }

                    List<AvatarAttachment> attachments = avappearance.GetAttachments();
                    foreach (AvatarAttachment attachment in attachments)
                    {
                        if ((items2RemoveFromAppearence.Contains(attachment.AssetID)) ||
                            (items2RemoveFromAppearence.Contains(attachment.ItemID)))
                        {
                            avappearance.DetachAttachment(attachment.ItemID);
                        }
                    }
                }

                // ok, now we have a empty folder, lets add the items
                foreach (InventoryItemBase itemBase in itemsInFolder)
                {
                    InventoryItemBase newcopy = m_InventoryService.InnerGiveInventoryItem(user, folderOwnerID, itemBase,
                                                                                          folderForAppearance.ID,
                                                                                          true, true);

                    if (newcopy.InvType == (int) InventoryType.Object)
                    {
                        byte[] attobj = m_AssetService.GetData(newcopy.AssetID.ToString());

                        if (attobj != null)
                        {
                            string xmlData = Utils.BytesToString(attobj);
                            XmlDocument doc = new XmlDocument();
                            try
                            {
                                doc.LoadXml(xmlData);
                            }
                            catch
                            {
                                continue;
                            }

                            if (doc.FirstChild.OuterXml.StartsWith("<groups>") ||
                                (doc.FirstChild.NextSibling != null &&
                                 doc.FirstChild.NextSibling.OuterXml.StartsWith("<groups>")))
                                continue;

                            string xml = "";
                            if ((doc.FirstChild.NodeType == XmlNodeType.XmlDeclaration) &&
                                (doc.FirstChild.NextSibling != null))
                                xml = doc.FirstChild.NextSibling.OuterXml;
                            else
                                xml = doc.FirstChild.OuterXml;
                            doc.LoadXml(xml);

                            if (doc.DocumentElement == null) continue;

                            XmlNodeList xmlNodeList = doc.DocumentElement.SelectNodes("//State");
                            int attchspot;
                            if ((xmlNodeList != null) && (int.TryParse(xmlNodeList[0].InnerText, out attchspot)))
                            {
                                AvatarAttachment a = new AvatarAttachment(attchspot, newcopy.ID, newcopy.AssetID);
                                Dictionary<int, List<AvatarAttachment>> ac = avappearance.Attachments;

                                if (!ac.ContainsKey(attchspot))
                                    ac[attchspot] = new List<AvatarAttachment>();

                                ac[attchspot].Add(a);
                                avappearance.Attachments = ac;
                            }
                        }
                    }
                    m_InventoryService.AddItem(newcopy);
                }
            }
            return avappearance;
        }
        protected AgentCircuitData MakeAgent(GridRegion region, UserAccount account,
            AvatarAppearance appearance, UUID session, UUID secureSession, uint circuit, Vector3 position,
            string ipaddress)
        {
            AgentCircuitData aCircuit = new AgentCircuitData();

            aCircuit.AgentID = account.PrincipalID;
            if (appearance != null)
                aCircuit.Appearance = appearance;
            else
            {
                m_log.Warn("Could not find appearance for acircuit!");
                aCircuit.Appearance = new AvatarAppearance(account.PrincipalID);
            }

            aCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
            aCircuit.child = false; // the first login agent is root
            aCircuit.circuitcode = circuit;
            aCircuit.SecureSessionID = secureSession;
            aCircuit.SessionID = session;
            aCircuit.startpos = position;
            aCircuit.IPAddress = ipaddress;

            return aCircuit;
        }
Exemple #59
0
        public AvatarAppearance ToAvatarAppearance(UUID owner)
        {
            AvatarAppearance appearance = new AvatarAppearance(owner);

            if (Data.Count == 0)
                return appearance;

            appearance.ClearWearables();
            try
            {
                if (Data.ContainsKey("Serial"))
                    appearance.Serial = Int32.Parse(Data["Serial"]);

                if (Data.ContainsKey("AvatarHeight"))
                    appearance.AvatarHeight = float.Parse(Data["AvatarHeight"]);

                // Legacy Wearables
                if (Data.ContainsKey("BodyItem"))
                    appearance.Wearables[AvatarWearable.BODY].Wear(
                            UUID.Parse(Data["BodyItem"]),
                            UUID.Parse(Data["BodyAsset"]));

                if (Data.ContainsKey("SkinItem"))
                    appearance.Wearables[AvatarWearable.SKIN].Wear(
                            UUID.Parse(Data["SkinItem"]),
                            UUID.Parse(Data["SkinAsset"]));

                if (Data.ContainsKey("HairItem"))
                    appearance.Wearables[AvatarWearable.HAIR].Wear(
                            UUID.Parse(Data["HairItem"]),
                            UUID.Parse(Data["HairAsset"]));

                if (Data.ContainsKey("EyesItem"))
                    appearance.Wearables[AvatarWearable.EYES].Wear(
                            UUID.Parse(Data["EyesItem"]),
                            UUID.Parse(Data["EyesAsset"]));

                if (Data.ContainsKey("ShirtItem"))
                    appearance.Wearables[AvatarWearable.SHIRT].Wear(
                            UUID.Parse(Data["ShirtItem"]),
                            UUID.Parse(Data["ShirtAsset"]));

                if (Data.ContainsKey("PantsItem"))
                    appearance.Wearables[AvatarWearable.PANTS].Wear(
                            UUID.Parse(Data["PantsItem"]),
                            UUID.Parse(Data["PantsAsset"]));

                if (Data.ContainsKey("ShoesItem"))
                    appearance.Wearables[AvatarWearable.SHOES].Wear(
                            UUID.Parse(Data["ShoesItem"]),
                            UUID.Parse(Data["ShoesAsset"]));

                if (Data.ContainsKey("SocksItem"))
                    appearance.Wearables[AvatarWearable.SOCKS].Wear(
                            UUID.Parse(Data["SocksItem"]),
                            UUID.Parse(Data["SocksAsset"]));

                if (Data.ContainsKey("JacketItem"))
                    appearance.Wearables[AvatarWearable.JACKET].Wear(
                            UUID.Parse(Data["JacketItem"]),
                            UUID.Parse(Data["JacketAsset"]));

                if (Data.ContainsKey("GlovesItem"))
                    appearance.Wearables[AvatarWearable.GLOVES].Wear(
                            UUID.Parse(Data["GlovesItem"]),
                            UUID.Parse(Data["GlovesAsset"]));

                if (Data.ContainsKey("UnderShirtItem"))
                    appearance.Wearables[AvatarWearable.UNDERSHIRT].Wear(
                            UUID.Parse(Data["UnderShirtItem"]),
                            UUID.Parse(Data["UnderShirtAsset"]));

                if (Data.ContainsKey("UnderPantsItem"))
                    appearance.Wearables[AvatarWearable.UNDERPANTS].Wear(
                            UUID.Parse(Data["UnderPantsItem"]),
                            UUID.Parse(Data["UnderPantsAsset"]));

                if (Data.ContainsKey("SkirtItem"))
                    appearance.Wearables[AvatarWearable.SKIRT].Wear(
                            UUID.Parse(Data["SkirtItem"]),
                            UUID.Parse(Data["SkirtAsset"]));


                if (Data.ContainsKey("VisualParams"))
                {
                    string[] vps = Data["VisualParams"].Split(new char[] { ',' });
                    byte[] binary = new byte[AvatarAppearance.VISUALPARAM_COUNT];

                    for (int i = 0; i < vps.Length && i < binary.Length; i++)
                        binary[i] = (byte)Convert.ToInt32(vps[i]);

                    appearance.VisualParams = binary;
                }

                if (Data.ContainsKey("Textures"))
                {
                    string t = Data["Textures"];
                    OSD tex = OSDParser.DeserializeJson(t);
                    appearance.Texture = Primitive.TextureEntry.FromOSD(tex);
                }

                // New style wearables
                foreach (KeyValuePair<string, string> _kvp in Data)
                {
                    if (_kvp.Key.StartsWith("Wearable "))
                    {
                        string wearIndex = _kvp.Key.Substring(9);
                        string[] wearIndices = wearIndex.Split(new char[] { ':' });
                        int index = Convert.ToInt32(wearIndices[0]);

                        string[] ids = _kvp.Value.Split(new char[] { ':' });
                        UUID itemID = new UUID(ids[0]);
                        UUID assetID = new UUID(ids[1]);

                        appearance.Wearables[index].Add(itemID, assetID);
                    }
                }


                // Attachments
                Dictionary<string, string> attchs = new Dictionary<string, string>();
                foreach (KeyValuePair<string, string> _kvp in Data)
                    if (_kvp.Key.StartsWith("_ap_"))
                        attchs[_kvp.Key] = _kvp.Value;

                foreach (KeyValuePair<string, string> _kvp in attchs)
                {
                    string pointStr = _kvp.Key.Substring(4);
                    int point = 0;
                    if (!Int32.TryParse(pointStr, out point))
                        continue;

                    UUID uuid = UUID.Zero;
                    UUID.TryParse(_kvp.Value, out uuid);

                    appearance.SetAttachment(point, uuid, UUID.Zero);
                }

                if (appearance.Wearables[AvatarWearable.BODY].Count == 0)
                    appearance.Wearables[AvatarWearable.BODY].Wear(
                            AvatarWearable.DefaultWearables[
                            AvatarWearable.BODY][0]);

                if (appearance.Wearables[AvatarWearable.SKIN].Count == 0)
                    appearance.Wearables[AvatarWearable.SKIN].Wear(
                            AvatarWearable.DefaultWearables[
                            AvatarWearable.SKIN][0]);

                if (appearance.Wearables[AvatarWearable.HAIR].Count == 0)
                    appearance.Wearables[AvatarWearable.HAIR].Wear(
                            AvatarWearable.DefaultWearables[
                            AvatarWearable.HAIR][0]);

                if (appearance.Wearables[AvatarWearable.EYES].Count == 0)
                    appearance.Wearables[AvatarWearable.EYES].Wear(
                            AvatarWearable.DefaultWearables[
                            AvatarWearable.EYES][0]);
            }
            catch
            {
                // We really should report something here, returning null
                // will at least break the wrapper
                return null;
            }

            return appearance;
        }
        public bool SetAppearance(UUID userID, AvatarAppearance appearance)
        {
            AvatarData avatar = new AvatarData(appearance);

            return(SetAvatar(userID, avatar));
        }