Beispiel #1
0
        /// <summary>
        /// Move an inventory folder
        /// </summary>
        /// <param name="folder">Folder to move</param>
        /// <remarks>UPDATE inventoryfolders SET parentFolderID=?parentFolderID WHERE folderID=?folderID</remarks>
        public void moveInventoryFolder(InventoryFolderBase folder, UUID parentId)
        {
            string query = "UPDATE inventoryfolders SET parentFolderID=?parentFolderID WHERE folderID=?folderID";

            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    Dictionary <string, object> parms = new Dictionary <string, object>();
                    parms.Add("?folderID", folder.ID.ToString());
                    parms.Add("?parentFolderID", parentId.ToString());

                    conn.QueryNoResults(query, parms);

                    folder.ParentID = parentId; // Only change if the above succeeded.

                    // Increment both the old and the new parents - checking for null.
                    this.IncrementSpecifiedFolderVersion(conn, parentId);
                    this.IncrementSpecifiedFolderVersion(conn, folder.ParentID);
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
            }
        }
        void client_OnGrantUserRights(IClientAPI sender, OpenMetaverse.UUID grantor, OpenMetaverse.UUID grantee, int rights)
        {
            if (sender.AgentId != grantor)
            {
                return;
            }

            //set the user rights on the DB
            using (ISimpleDB db = _connFactory.GetConnection())
            {
                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("rights", rights);
                parms.Add("ownerID", grantor);
                parms.Add("friendID", grantee);

                db.QueryNoResults("UPDATE userfriends " +
                                  "SET friendPerms = ?rights " +
                                  "WHERE ownerID = ?ownerID AND friendID = ?friendID;",

                                  parms);
            }

            m_scene.CommsManager.UserService.UpdateUserFriendPerms(grantor, grantee, (uint)rights);
            sender.SendChangeUserRights(grantor, grantee, rights);
        }
Beispiel #3
0
        private void DBStoreMuteListEntry(UUID AgentID, UUID MuteID, MuteListEntry entry, bool isUpdate)
        {
            using (ISimpleDB db = _connectionFactory.GetConnection())
            {
                string query;
                if (isUpdate)
                {
                    query = "UPDATE mutelist " +
                            "SET " +
                            "    MuteType = ?muteType" +
                            "    , MuteName = ?muteName" +
                            "    , MuteFlags= ?muteFlags" +
                            " WHERE " +
                            "    AgentID = ?agentID AND MuteID = ?muteID";
                }
                else
                {
                    query = "INSERT INTO mutelist " +
                            "(AgentID, MuteType, MuteID, MuteName, MuteFlags) " +
                            "VALUES(?AgentID, ?MuteType, ?MuteID, ?MuteName, ?MuteFlags)";
                }

                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("?agentID", AgentID);
                parms.Add("?muteID", MuteID);
                parms.Add("?muteType", entry.m_Type);
                parms.Add("?muteName", entry.m_Name);
                parms.Add("?muteFlags", entry.m_Flags);

                db.QueryNoResults(query, parms);
            }
        }
Beispiel #4
0
        public void AvatarNotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes)
        {
            UUID avatarID = remoteClient.AgentId;

            // allow leading spaces for formatting, but TrimEnd will help us detect an empty field other than spaces
            string notes = queryNotes.TrimEnd();

            // filter out the old text that said there was no text. ;)
            if (notes == LEGACY_EMPTY)
            {
                notes = String.Empty;
            }

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("?avatarID", avatarID);
                parms.Add("?targetID", queryTargetID);
                parms.Add("?notes", notes);

                string query;
                if (String.IsNullOrEmpty(notes))
                {
                    query = "DELETE FROM usernotes WHERE useruuid=?avatarID AND targetuuid=?targetID";
                }
                else
                {
                    query = "INSERT INTO usernotes(useruuid, targetuuid, notes) VALUES(?avatarID,?targetID,?notes) ON DUPLICATE KEY UPDATE notes=?notes";
                }
                db.QueryNoResults(query, parms);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Updates the specified inventory item
        /// </summary>
        /// <param name="item">Inventory item to update</param>
        public void updateInventoryItem(InventoryItemBase item)
        {
            //addInventoryItem(item);

            /* 12/9/2009 - Ele's Edit - Rather than simply adding a whole new item, which seems kind of pointless to me,
             * let's actually try UPDATING the item as it should be. This is not fully functioning yet from the updating of items
             * within Scene.Inventory.cs MoveInventoryItem yet. Not sure the effect it will have on the rest of the updates either, as they
             * originally pointed back to addInventoryItem above.
             */

            string query =
                "UPDATE inventoryitems SET assetID=?assetID, assetType=?assetType, parentFolderID=?parentFolderID, "
                + "avatarID=?avatarID, inventoryName=?inventoryName, inventoryDescription=?inventoryDescription, inventoryNextPermissions=?inventoryNextPermissions, "
                + "inventoryCurrentPermissions=?inventoryCurrentPermissions, invType=?invType, creatorID=?creatorID, inventoryBasePermissions=?inventoryBasePermissions, "
                + "inventoryEveryOnePermissions=?inventoryEveryOnePermissions, inventoryGroupPermissions=?inventoryGroupPermissions, salePrice=?salePrice, "
                + "saleType=?saleType, creationDate=?creationDate, groupID=?groupID, groupOwned=?groupOwned, flags=?flags "
                + "WHERE inventoryID=?inventoryID";

            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    Dictionary <string, object> parms = new Dictionary <string, object>();
                    parms.Add("?inventoryID", item.ID.ToString());
                    parms.Add("?assetID", item.AssetID.ToString());
                    parms.Add("?assetType", item.AssetType.ToString());
                    parms.Add("?parentFolderID", item.Folder.ToString());
                    parms.Add("?avatarID", item.Owner.ToString());
                    parms.Add("?inventoryName", item.Name);
                    parms.Add("?inventoryDescription", item.Description);
                    parms.Add("?inventoryNextPermissions", item.NextPermissions.ToString());
                    parms.Add("?inventoryCurrentPermissions", item.CurrentPermissions.ToString());
                    parms.Add("?invType", item.InvType);
                    parms.Add("?creatorID", item.CreatorId);
                    parms.Add("?inventoryBasePermissions", item.BasePermissions);
                    parms.Add("?inventoryEveryOnePermissions", item.EveryOnePermissions);
                    parms.Add("?inventoryGroupPermissions", item.GroupPermissions);
                    parms.Add("?salePrice", item.SalePrice);
                    parms.Add("?saleType", item.SaleType);
                    parms.Add("?creationDate", item.CreationDate);
                    parms.Add("?groupID", item.GroupID);
                    parms.Add("?groupOwned", item.GroupOwned);
                    parms.Add("?flags", item.Flags);

                    conn.QueryNoResults(query, parms);

                    // Also increment the parent version number if not null.
                    this.IncrementSpecifiedFolderVersion(conn, item.Folder);
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
            }
        }
Beispiel #6
0
        /// <summary>
        /// Delete a folder from database. Must be called from within a using{} block for the database connection.
        /// </summary>
        /// Passing in the connection allows for consolidation of the DB connections, important as this method is often called from an inner loop.
        /// <param name="folderID">the folder UUID</param>
        /// <param name="conn">the database connection</param>
        private void deleteOneFolder(ISimpleDB conn, InventoryFolderBase folder)
        {
            string query = "DELETE FROM inventoryfolders WHERE folderID=?uuid";
            Dictionary <string, object> parms = new Dictionary <string, object>();

            parms.Add("?uuid", folder.ID.ToString());

            conn.QueryNoResults(query, parms);

            // As the callers of this function will increment the version, there's no need to do so here.
        }
Beispiel #7
0
        /// <summary>
        /// Increments the version of the passed folder, making sure the folder isn't Zero. Must be called from within a using{} block!
        /// </summary>
        /// <param name="conn">Database connection.</param>
        /// <param name="folderId">Folder UUID to increment</param>
        private void IncrementSpecifiedFolderVersion(ISimpleDB conn, UUID folderId)
        {
            if (folderId != UUID.Zero)
            {
                string query = "update inventoryfolders set version=version+1 where folderID = ?folderID";
                Dictionary <string, object> updParms = new Dictionary <string, object>();
                updParms.Add("?folderID", folderId.ToString());

                conn.QueryNoResults(query, updParms);
            }
        }
Beispiel #8
0
 private void DBRemoveMuteListEntry(UUID AgentID, UUID MuteID)
 {
     using (ISimpleDB db = _connectionFactory.GetConnection())
     {
         Dictionary <string, object> parms = new Dictionary <string, object>();
         string query = "DELETE FROM mutelist WHERE AgentID = ?agentID AND MuteID = ?muteID";
         parms.Add("?agentID", AgentID);
         parms.Add("?muteID", MuteID);
         db.QueryNoResults(query, parms);
     }
 }
Beispiel #9
0
        /// <summary>
        /// Adds a specified item to the database
        /// </summary>
        /// <param name="item">The inventory item</param>
        public void addInventoryItem(InventoryItemBase item)
        {
            string query =
                "REPLACE INTO inventoryitems (inventoryID, assetID, assetType, parentFolderID, avatarID, inventoryName"
                + ", inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions, invType"
                + ", creatorID, inventoryBasePermissions, inventoryEveryOnePermissions, inventoryGroupPermissions, salePrice, saleType"
                + ", creationDate, groupID, groupOwned, flags) VALUES ";

            query +=
                "(?inventoryID, ?assetID, ?assetType, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription"
                + ", ?inventoryNextPermissions, ?inventoryCurrentPermissions, ?invType, ?creatorID"
                + ", ?inventoryBasePermissions, ?inventoryEveryOnePermissions, ?inventoryGroupPermissions, ?salePrice, ?saleType, ?creationDate"
                + ", ?groupID, ?groupOwned, ?flags)";

            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    Dictionary <string, object> parms = new Dictionary <string, object>();
                    parms.Add("?inventoryID", item.ID.ToString());
                    parms.Add("?assetID", item.AssetID.ToString());
                    parms.Add("?assetType", item.AssetType.ToString());
                    parms.Add("?parentFolderID", item.Folder.ToString());
                    parms.Add("?avatarID", item.Owner.ToString());
                    parms.Add("?inventoryName", item.Name);
                    parms.Add("?inventoryDescription", item.Description);
                    parms.Add("?inventoryNextPermissions", item.NextPermissions.ToString());
                    parms.Add("?inventoryCurrentPermissions", item.CurrentPermissions.ToString());
                    parms.Add("?invType", item.InvType);
                    parms.Add("?creatorID", item.CreatorId);
                    parms.Add("?inventoryBasePermissions", item.BasePermissions);
                    parms.Add("?inventoryEveryOnePermissions", item.EveryOnePermissions);
                    parms.Add("?inventoryGroupPermissions", item.GroupPermissions);
                    parms.Add("?salePrice", item.SalePrice);
                    parms.Add("?saleType", item.SaleType);
                    parms.Add("?creationDate", item.CreationDate);
                    parms.Add("?groupID", item.GroupID);
                    parms.Add("?groupOwned", item.GroupOwned);
                    parms.Add("?flags", item.Flags);

                    conn.QueryNoResults(query, parms);

                    // Also increment the parent version number if not null.
                    this.IncrementSpecifiedFolderVersion(conn, item.Folder);
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
            }
        }
Beispiel #10
0
        // Picks Delete

        public void PickDelete(IClientAPI remoteClient, UUID queryPickID)
        {
            UUID avatarID = remoteClient.AgentId;

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("?pickID", queryPickID);
                parms.Add("?avatarID", avatarID);

                string query = "delete from userpicks where pickuuid=?pickID AND creatoruuid=?avatarID";

                db.QueryNoResults(query, parms);
            }
        }
Beispiel #11
0
        // Classifieds Delete

        public void ClassifiedDelete(UUID queryClassifiedID, IClientAPI remoteClient)
        {
            UUID avatarID     = remoteClient.AgentId;
            UUID classifiedID = queryClassifiedID;

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("?classifiedID", classifiedID);
                parms.Add("?avatarID", avatarID);

                string query = "delete from classifieds where classifieduuid=?classifiedID AND creatorUUID=?avatarID";

                db.QueryNoResults(query, parms);
            }
        }
Beispiel #12
0
        private void DeleteMessage(ISimpleDB db, uint ID)
        {
            string sql = "DELETE FROM emailmessages WHERE `ID`=?id";

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["?ID"] = ID.ToString();

            try
            {
                db.QueryNoResults(sql, parameters);
            }
            catch (Exception e)
            {
                m_log.Error("[InboundEmail]: Exception during database call to delete delivered message: " + e.Message);
                m_log.Error(e.StackTrace);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Detele the specified inventory item
        /// </summary>
        /// <param name="item">The inventory item UUID to delete</param>
        public void deleteInventoryItem(InventoryItemBase item)
        {
            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    string query = "DELETE FROM inventoryitems WHERE inventoryID=?uuid";
                    Dictionary <string, object> parms = new Dictionary <string, object>();
                    parms.Add("?uuid", item.ID.ToString());

                    conn.QueryNoResults(query, parms);

                    // Also increment the parent version number if not null.
                    this.IncrementSpecifiedFolderVersion(conn, item.Folder);
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
            }
        }
Beispiel #14
0
        // Interests Update

        public void AvatarInterestsUpdate(IClientAPI remoteClient, uint querySkillsMask, string querySkillsText, uint queryWantToMask, string queryWantToText, string
                                          queryLanguagesText)
        {
            UUID avatarID = remoteClient.AgentId;

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("?avatarID", avatarID);
                parms.Add("?skillsMask", querySkillsMask);
                parms.Add("?skillsText", querySkillsText);
                parms.Add("?wantToMask", queryWantToMask);
                parms.Add("?wantToText", queryWantToText);
                parms.Add("?languagesText", queryLanguagesText);

                string query = "UPDATE users set skillsMask=?wantToMask, skillsText=?wantToText, wantToMask=?skillsMask, " +
                               "wantToText=?skillsText, languagesText=?languagesText where UUID=?avatarID";

                db.QueryNoResults(query, parms);
            }
        }
        /// <summary>
        /// Deletes a sim profile from the database
        /// </summary>
        /// <param name="uuid">the sim UUID</param>
        /// <returns>Successful?</returns>
        //public DataResponse DeleteProfile(RegionProfileData profile)
        override public DataResponse DeleteProfile(string uuid)
        {
            string sql = "DELETE FROM regions WHERE uuid = ?uuid;";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["?uuid"] = uuid;

            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    conn.QueryNoResults(sql, parameters);
                    return(DataResponse.RESPONSE_OK);
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
                return(DataResponse.RESPONSE_ERROR);
            }
        }
Beispiel #16
0
        private void UpdateRegistration(ISimpleDB db, UUID uuid, UUID regionUUID)
        {
            string sql = "INSERT INTO emailregistrations (`uuid`, `time`, `region`) VALUES (?uuid, ?time, ?region)";

            sql += " ON DUPLICATE KEY UPDATE `time`=?time";

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["?uuid"]   = uuid.ToString();
            parameters["?region"] = regionUUID.ToString();
            parameters["?time"]   = DateTime2UnixTime(DateTime.UtcNow); // All storage dates are UTC

            try
            {
                db.QueryNoResults(sql, parameters);
            }
            catch (Exception e)
            {
                m_log.Error("[InboundEmail]: Exception during database call to store message: " + e.Message);
                m_log.Error(e.StackTrace);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Delete all subfolders and items in a folder. Must be called from within a using{} block for the database connection.
        /// </summary>
        /// Passing in the connection allows for consolidation of the DB connections, important as this method is often called from an inner loop.
        /// <param name="folderID">the folder UUID</param>
        /// <param name="conn">the database connection</param>
        private void deleteFolderContents(ISimpleDB conn, UUID folderID)
        {
            // Get a flattened list of all subfolders.
            List <InventoryFolderBase> subFolders = getFolderHierarchy(folderID);

            // Delete all sub-folders
            foreach (InventoryFolderBase f in subFolders)
            {
                deleteFolderContents(conn, f.ID); // Recurse!
                deleteOneFolder(conn, f);
            }

            // Delete the actual items in this folder.
            string query = "DELETE FROM inventoryitems WHERE parentFolderID=?uuid";
            Dictionary <string, object> parms = new Dictionary <string, object>();

            parms.Add("?uuid", folderID.ToString());

            conn.QueryNoResults(query, parms);

            // As the callers of this function will increment the version, there's no need to do so here where this is most often ceing called from an inner loop!
        }
Beispiel #18
0
        /// <summary>
        /// Creates a new inventory folder
        /// </summary>
        /// <param name="folder">Folder to create</param>
        public void addInventoryFolder(InventoryFolderBase folder)
        {
            if (folder.ID == UUID.Zero)
            {
                m_log.Error("[Inventory]: Not storing zero UUID folder for " + folder.Owner.ToString());
                return;
            }

            string query =
                "REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName, type, version) VALUES ";

            query += "(?folderID, ?agentID, ?parentFolderID, ?folderName, ?type, ?version)";

            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    Dictionary <string, object> parms = new Dictionary <string, object>();
                    parms.Add("?folderID", folder.ID.ToString());
                    parms.Add("?agentID", folder.Owner.ToString());
                    parms.Add("?parentFolderID", folder.ParentID.ToString());
                    parms.Add("?folderName", folder.Name);
                    parms.Add("?type", (short)folder.Type);
                    parms.Add("?version", folder.Version);

                    conn.QueryNoResults(query, parms);

                    // Also increment the parent version number if not null.
                    this.IncrementSpecifiedFolderVersion(conn, folder.ParentID);
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
            }
        }
Beispiel #19
0
        /// <summary>
        /// Updates an inventory folder
        /// </summary>
        /// <param name="folder">Folder to update</param>
        public void updateInventoryFolder(InventoryFolderBase folder)
        {
            string query =
                "update inventoryfolders set folderName=?folderName where folderID=?folderID";

            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    Dictionary <string, object> parms = new Dictionary <string, object>();
                    parms.Add("?folderName", folder.Name);
                    parms.Add("?folderID", folder.ID.ToString());

                    conn.QueryNoResults(query, parms);

                    // Also increment the version number if not null.
                    this.IncrementSpecifiedFolderVersion(conn, folder.ID);
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
            }
        }
        /// <summary>
        /// Delete all subfolders and items in a folder. Must be called from within a using{} block for the database connection.
        /// </summary>
        /// Passing in the connection allows for consolidation of the DB connections, important as this method is often called from an inner loop.
        /// <param name="folderID">the folder UUID</param>
        /// <param name="conn">the database connection</param>
        private void deleteFolderContents(ISimpleDB conn, UUID folderID)
        {
            // Get a flattened list of all subfolders.
            List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID);

            // Delete all sub-folders
            foreach (InventoryFolderBase f in subFolders)
            {
                deleteFolderContents(conn, f.ID); // Recurse!
                deleteOneFolder(conn, f);
            }

            // Delete the actual items in this folder.
            string query = "DELETE FROM inventoryitems WHERE parentFolderID=?uuid";
            Dictionary<string, object> parms = new Dictionary<string, object>();
            parms.Add("?uuid", folderID.ToString());

            conn.QueryNoResults(query, parms);

            // As the callers of this function will increment the version, there's no need to do so here where this is most often ceing called from an inner loop!
        }
Beispiel #21
0
        // Picks Update

        // pulled the original method due to UUID queryParcelID always being returned as null. If this is ever fixed to where
        // the viewer does in fact return the parcelID, then we can put this back in.
        //public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc,
        //                    UUID queryParcelID, Vector3 queryGlobalPos, UUID snapshotID, int sortOrder, bool enabled)

        public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc,
                                   Vector3 queryGlobalPos, UUID snapshotID, int sortOrder, bool enabled)
        {
            string userRegion     = remoteClient.Scene.RegionInfo.RegionName;
            UUID   userRegionID   = remoteClient.Scene.RegionInfo.RegionID;
            string userFName      = remoteClient.FirstName;
            string userLName      = remoteClient.LastName;
            string avatarName     = userFName + " " + userLName;
            UUID   tempParcelUUID = UUID.Zero;
            UUID   avatarID       = remoteClient.AgentId;


            using (ISimpleDB db = _connFactory.GetConnection())
            {
                //if this is an existing pick make sure the client is the owner or don't touch it
                string existingCheck = "SELECT creatoruuid FROM userpicks WHERE pickuuid = ?pickID";
                Dictionary <string, object> checkParms = new Dictionary <string, object>();
                checkParms.Add("?pickID", pickID);

                List <Dictionary <string, string> > existingResults = db.QueryWithResults(existingCheck, checkParms);
                if (existingResults.Count > 0)
                {
                    if (existingResults[0]["creatoruuid"] != avatarID.ToString())
                    {
                        return;
                    }
                }

                //reassign creator id, it has to be this avatar
                creatorID = avatarID;

                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("?avatarID", avatarID);
                parms.Add("?pickID", pickID);
                parms.Add("?creatorID", creatorID);
                parms.Add("?topPick", topPick);
                parms.Add("?name", name);
                parms.Add("?desc", desc);
                parms.Add("?globalPos", queryGlobalPos);
                parms.Add("?snapshotID", snapshotID);
                parms.Add("?sortOrder", sortOrder);
                parms.Add("?enabled", enabled);
                parms.Add("?regionID", userRegionID);
                parms.Add("?regionName", userRegion);

                // we need to know if we're on a parcel or not, and if so, put it's UUID in there
                // viewer isn't giving it to us from what I can determine
                // TODO: David will need to clean this up cause more arrays are not my thing  :)

                string queryParcelUUID = "select UUID from land where regionUUID=?regionID AND name=?name limit 1";
                using (ISimpleDB landDb = _regionConnFactory.GetConnection())
                {
                    List <Dictionary <string, string> > simID = landDb.QueryWithResults(queryParcelUUID, parms);

                    foreach (Dictionary <string, string> row in simID)
                    {
                        tempParcelUUID = UUID.Parse(row["UUID"]);
                    }
                }

                UUID parcelUUID = tempParcelUUID;
                parms.Add("?parcelID", parcelUUID);
                m_log.Debug("Got parcel of: " + parcelUUID.ToString());
                parms.Add("?parcelName", name);

                string queryPicksCount = "select COUNT(pickuuid) from userpicks where pickuuid=?pickID AND " +
                                         "creatoruuid=?creatorID";

                List <Dictionary <string, string> > countList = db.QueryWithResults(queryPicksCount, parms);

                string query;
                string picksCount = String.Empty;

                foreach (Dictionary <string, string> row in countList)
                {
                    picksCount = row["COUNT(pickuuid)"];
                }

                parms.Add("?avatarName", avatarName);

                //TODO: We're defaulting topPick to false for the moment along with enabled default to True
                // We'll need to look over the conversion vs MySQL cause data truncating should not happen
                if (picksCount == "0")
                {
                    query = "INSERT into userpicks (pickuuid, creatoruuid, toppick, parceluuid, name, description, snapshotuuid, user, " +
                            "originalname, simname, posglobal, sortorder, enabled) " +
                            "VALUES (?pickID, ?creatorID, 'false', ?parcelID, ?name, ?desc, ?snapshotID, " +
                            "?avatarName, ?parcelName, ?regionName, ?globalPos, ?sortOrder, 'true')";
                }
                else
                {
                    query = "UPDATE userpicks set toppick='false', " +
                            " parceluuid=?parcelID, name=?name, description=?desc, snapshotuuid=?snapshotID, " +
                            "user=?avatarName, originalname=?parcelName, simname=?regionName, posglobal=?globalPos, sortorder=?sortOrder, " +
                            " enabled='true' where pickuuid=?pickID";
                }
                db.QueryNoResults(query, parms);
            }
        }
Beispiel #22
0
        public void ClassifiedInfoUpdate(UUID queryclassifiedID, uint queryCategory, string queryName, string queryDescription, UUID queryParcelID,
                                         uint queryParentEstate, UUID querySnapshotID, Vector3 queryGlobalPos, byte queryclassifiedFlags,
                                         int queryclassifiedPrice, IClientAPI remoteClient)
        {
            // getting information lined up for the query
            UUID avatarID   = remoteClient.AgentId;
            UUID regionUUID = remoteClient.Scene.RegionInfo.RegionID;
            UUID ParcelID   = UUID.Zero;

            uint regionX = remoteClient.Scene.RegionInfo.RegionLocX;
            uint regionY = remoteClient.Scene.RegionInfo.RegionLocY;

//            m_log.DebugFormat("[CLASSIFIED]: Got the RegionX Location as: {0}, and RegionY as: {1}", regionX.ToString(), regionY.ToString());

            string regionName     = remoteClient.Scene.RegionInfo.RegionName;
            int    creationDate   = Util.UnixTimeSinceEpoch();
            int    expirationDate = creationDate + 604800;

            if (queryclassifiedPrice < MIN_CLASSIFIED_PRICE)
            {
                m_log.ErrorFormat("[CLASSIFIED]: Got a request for invalid price I'z${0} on a classified from {1}.", queryclassifiedPrice.ToString(), remoteClient.AgentId.ToString());
                remoteClient.SendAgentAlertMessage("Error: The minimum price for a classified advertisement is I'z$" + MIN_CLASSIFIED_PRICE.ToString() + ".", true);
                return;
            }

            // Check for hacked names that start with special characters
            if (!Char.IsLetterOrDigit(queryName, 0))
            {
                m_log.ErrorFormat("[CLASSIFIED]: Got a hacked request from {0} for invalid name classified name: {1}", remoteClient.AgentId.ToString(), queryName);
                remoteClient.SendAgentAlertMessage("Error: The name of your classified must start with a letter or a number. No punctuation is allowed.", true);
                return;
            }


            // In case of insert, original values are the new values (by default)
            int origPrice = 0;

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                //if this is an existing classified make sure the client is the owner or don't touch it
                string existingCheck = "SELECT creatoruuid FROM classifieds WHERE classifieduuid = ?classifiedID";
                Dictionary <string, object> checkParms = new Dictionary <string, object>();
                checkParms.Add("?classifiedID", queryclassifiedID);

                List <Dictionary <string, string> > existingResults = db.QueryWithResults(existingCheck, checkParms);
                if (existingResults.Count > 0)
                {
                    string existingAuthor = existingResults[0]["creatoruuid"];
                    if (existingAuthor != avatarID.ToString())
                    {
                        m_log.ErrorFormat("[CLASSIFIED]: Got a request for from {0} to modify a classified from {1}: {2}",
                                          remoteClient.AgentId.ToString(), existingAuthor, queryclassifiedID.ToString());
                        remoteClient.SendAgentAlertMessage("Error: You do not have permission to modify that classified ad.", true);
                        return;
                    }
                }

                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("?avatarID", avatarID);
                parms.Add("?classifiedID", queryclassifiedID);
                parms.Add("?category", queryCategory);
                parms.Add("?name", queryName);
                parms.Add("?description", queryDescription);
                //parms.Add("?parcelID", queryParcelID);
                parms.Add("?parentEstate", queryParentEstate);
                parms.Add("?snapshotID", querySnapshotID);
                parms.Add("?globalPos", queryGlobalPos);
                parms.Add("?classifiedFlags", queryclassifiedFlags);
                parms.Add("?classifiedPrice", queryclassifiedPrice);
                parms.Add("?creationDate", creationDate);
                parms.Add("?expirationDate", expirationDate);
                parms.Add("?regionUUID", regionUUID);
                parms.Add("?regionName", regionName);

                // We need parcelUUID from land to place in the query properly
                // However, there can be multiple Parcel UUIDS per region,
                // so we need to do some math from the classified entry
                // to the positioning of the avatar
                // The point we have is a global position value, which means
                // we need to to get the location with: (GlobalX / 256) - RegionX and
                // (GlobalY / 256) - RegionY for the values of the avatar standign position
                // then compare that to the parcels for the closest match

                // explode the GlobalPos value off the bat

                string origGlobPos  = queryGlobalPos.ToString();
                string tempAGlobPos = origGlobPos.Replace("<", String.Empty);
                string tempBGlobPos = tempAGlobPos.Replace(">", String.Empty);

                char[]   delimiterChars = { ',', ' ' };
                string[] globalPosBits  = tempBGlobPos.Split(delimiterChars);

                uint tempAvaXLoc = Convert.ToUInt32(Convert.ToDouble(globalPosBits[0]));
                uint tempAvaYLoc = Convert.ToUInt32(Convert.ToDouble(globalPosBits[2]));

                uint avaXLoc = tempAvaXLoc - (256 * regionX);
                uint avaYLoc = tempAvaYLoc - (256 * regionY);


                //uint avatarPosX = (posGlobalX / 256) - regionX;
                parms.Add("?avaXLoc", avaXLoc.ToString());
                parms.Add("?avaYLoc", avaYLoc.ToString());
                string parcelLocate = "select  uuid, MIN(ABS(UserLocationX - ?avaXLoc)) as minXValue, MIN(ABS(UserLocationY - ?avaYLoc)) as minYValue from land where RegionUUID=?regionUUID GROUP BY UserLocationX ORDER BY minXValue, minYValue LIMIT 1;";

                using (ISimpleDB landDb = _regionConnFactory.GetConnection())
                {
                    List <Dictionary <string, string> > parcelLocated = landDb.QueryWithResults(parcelLocate, parms);
                    foreach (Dictionary <string, string> row in parcelLocated)
                    {
                        ParcelID = new UUID(row["uuid"].ToString());
                    }
                }

                parms.Add("?parcelID", ParcelID);
                string queryClassifieds = "select * from classifieds where classifieduuid=?classifiedID AND creatoruuid=?avatarID";
                List <Dictionary <string, string> > results = db.QueryWithResults(queryClassifieds, parms);
                bool   isUpdate = false;
                int    costToApply;
                string transactionDesc;

                if (results.Count != 0)
                {
                    if (results.Count != 1)
                    {
                        remoteClient.SendAgentAlertMessage("Classified record is not consistent. Contact Support for assistance.", false);
                        m_log.ErrorFormat("[CLASSIFIED]: Error, query for user {0} classified ad {1} returned {2} results.",
                                          avatarID.ToString(), queryclassifiedID.ToString(), results.Count.ToString());
                        return;
                    }

                    // This is an upgrade of a classified ad.
                    Dictionary <string, string> row = results[0];
                    isUpdate        = true;
                    transactionDesc = "Classified price change";
                    origPrice       = Convert.ToInt32(row["priceforlisting"]);

                    // Also preserve original creation date and expiry.
                    creationDate   = Convert.ToInt32(row["creationdate"]);
                    expirationDate = Convert.ToInt32(row["expirationdate"]);

                    costToApply = queryclassifiedPrice - origPrice;
                    if (costToApply < 0)
                    {
                        costToApply = 0;
                    }
                }
                else
                {
                    // This is the initial placement of the classified.
                    transactionDesc = "Classified charge";

                    creationDate   = Util.UnixTimeSinceEpoch();
                    expirationDate = creationDate + 604800;

                    costToApply = queryclassifiedPrice;
                }
                EventManager.ClassifiedPaymentArgs paymentArgs = new EventManager.ClassifiedPaymentArgs(remoteClient.AgentId, queryclassifiedID, origPrice, queryclassifiedPrice, transactionDesc, true);

                if (costToApply > 0)
                {
                    // Now check whether the payment is authorized by the currency system.
                    ((Scene)remoteClient.Scene).EventManager.TriggerClassifiedPayment(remoteClient, paymentArgs);
                    if (!paymentArgs.mIsAuthorized)
                    {
                        return; // already reported to user by the check above.
                    }
                }

                string query;
                if (isUpdate)
                {
                    query = "UPDATE classifieds set creationdate=?creationDate, " +
                            "category=?category, name=?name, description=?description, parceluuid=?parcelID, " +
                            "parentestate=?parentEstate, snapshotuuid=?snapshotID, simname=?regionName, posglobal=?globalPos, parcelname=?name, " +
                            " classifiedflags=?classifiedFlags, priceforlisting=?classifiedPrice where classifieduuid=?classifiedID";
                }
                else
                {
                    query = "INSERT into classifieds (classifieduuid, creatoruuid, creationdate, expirationdate, category, name, " +
                            "description, parceluuid, parentestate, snapshotuuid, simname, posglobal, parcelname, classifiedflags, priceforlisting) " +
                            "VALUES (?classifiedID, ?avatarID, ?creationDate, ?expirationDate, ?category, ?name, ?description, ?parcelID, " +
                            "?parentEstate, ?snapshotID, ?regionName, ?globalPos, ?name, ?classifiedFlags, ?classifiedPrice)";
                }
                db.QueryNoResults(query, parms);

                if (costToApply > 0)    // no refunds for lower prices
                {
                    // Handle the actual money transaction here.
                    paymentArgs.mIsPreCheck = false;    // now call it again but for real this time
                    ((Scene)remoteClient.Scene).EventManager.TriggerClassifiedPayment(remoteClient, paymentArgs);
                    // Errors reported by the payment request above.
                }
            }
        }
        /// <summary>
        /// Inserts a new region into the database
        /// </summary>
        /// <param name="regiondata">The region to insert</param>
        /// <returns>Success?</returns>
        public bool insertRegion(RegionProfileData regiondata)
        {
            bool GRID_ONLY_UPDATE_NECESSARY_DATA = false;

            string sql = String.Empty;

            if (GRID_ONLY_UPDATE_NECESSARY_DATA)
            {
                sql += "INSERT INTO ";
            }
            else
            {
                sql += "REPLACE INTO ";
            }

            sql += "regions (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
            sql +=
                "serverIP, serverPort, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";

            // part of an initial brutish effort to provide accurate information (as per the xml region spec)
            // wrt the ownership of a given region
            // the (very bad) assumption is that this value is being read and handled inconsistently or
            // not at all. Current strategy is to put the code in place to support the validity of this information
            // and to roll forward debugging any issues from that point
            //
            // this particular section of the mod attempts to implement the commit of a supplied value
            // server for the UUID of the region's owner (master avatar). It consists of the addition of the column and value to the relevant sql,
            // as well as the related parameterization
            sql +=
                "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey, regionMapTexture, serverHttpPort, serverRemotingPort, owner_uuid, originUUID, access, product, outside_ip) VALUES ";

            sql += "(?regionHandle, ?regionName, ?uuid, ?regionRecvKey, ?regionSecret, ?regionSendKey, ?regionDataURI, ";
            sql +=
                "?serverIP, ?serverPort, ?locX, ?locY, ?locZ, ?eastOverrideHandle, ?westOverrideHandle, ?southOverrideHandle, ?northOverrideHandle, ?regionAssetURI, ?regionAssetRecvKey, ";
            sql +=
                "?regionAssetSendKey, ?regionUserURI, ?regionUserRecvKey, ?regionUserSendKey, ?regionMapTexture, ?serverHttpPort, ?serverRemotingPort, ?owner_uuid, ?originUUID, ?access, ?product, ?outside_ip)";

            if (GRID_ONLY_UPDATE_NECESSARY_DATA)
            {
                sql += "ON DUPLICATE KEY UPDATE serverIP = ?serverIP, serverPort = ?serverPort, owner_uuid - ?owner_uuid;";
            }
            else
            {
                sql += ";";
            }

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["?regionHandle"]        = regiondata.regionHandle.ToString();
            parameters["?regionName"]          = regiondata.regionName.ToString();
            parameters["?uuid"]                = regiondata.UUID.ToString();
            parameters["?regionRecvKey"]       = regiondata.regionRecvKey.ToString();
            parameters["?regionSecret"]        = regiondata.regionSecret.ToString();
            parameters["?regionSendKey"]       = regiondata.regionSendKey.ToString();
            parameters["?regionDataURI"]       = regiondata.regionDataURI.ToString();
            parameters["?serverIP"]            = regiondata.serverHostName.ToString();
            parameters["?serverPort"]          = regiondata.serverPort.ToString();
            parameters["?locX"]                = regiondata.regionLocX.ToString();
            parameters["?locY"]                = regiondata.regionLocY.ToString();
            parameters["?locZ"]                = regiondata.regionLocZ.ToString();
            parameters["?eastOverrideHandle"]  = regiondata.regionEastOverrideHandle.ToString();
            parameters["?westOverrideHandle"]  = regiondata.regionWestOverrideHandle.ToString();
            parameters["?northOverrideHandle"] = regiondata.regionNorthOverrideHandle.ToString();
            parameters["?southOverrideHandle"] = regiondata.regionSouthOverrideHandle.ToString();
            parameters["?regionAssetURI"]      = regiondata.regionAssetURI.ToString();
            parameters["?regionAssetRecvKey"]  = regiondata.regionAssetRecvKey.ToString();
            parameters["?regionAssetSendKey"]  = regiondata.regionAssetSendKey.ToString();
            parameters["?regionUserURI"]       = regiondata.regionUserURI.ToString();
            parameters["?regionUserRecvKey"]   = regiondata.regionUserRecvKey.ToString();
            parameters["?regionUserSendKey"]   = regiondata.regionUserSendKey.ToString();
            parameters["?regionMapTexture"]    = regiondata.regionMapTextureID.ToString();
            parameters["?serverHttpPort"]      = regiondata.httpPort.ToString();
            parameters["?serverRemotingPort"]  = regiondata.remotingPort.ToString();
            parameters["?owner_uuid"]          = regiondata.owner_uuid.ToString();
            parameters["?originUUID"]          = regiondata.originUUID.ToString();
            parameters["?access"]              = regiondata.maturity.ToString();
            parameters["?product"]             = Convert.ToInt32(regiondata.product).ToString();

            if (regiondata.OutsideIP != null)
            {
                parameters["?outside_ip"] = regiondata.OutsideIP;
            }
            else
            {
                parameters["?outside_ip"] = DBNull.Value;
            }

            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    conn.QueryNoResults(sql, parameters);
                    return(true);
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
                return(false);
            }
        }
        private void DoInsertGroupMembership(ISimpleDB db, OpenMetaverse.UUID agentID, OpenMetaverse.UUID groupID, OpenMetaverse.UUID roleID)
        {
            string qInsMembership =
                "INSERT INTO osgroupmembership (GroupID, AgentID, Contribution, ListInProfile, AcceptNotices, SelectedRoleID) " +
                "VALUES (?groupID,?agentID, 0, 1, 1,?roleID)";

            Dictionary<string, object> parms = new Dictionary<string, object>();
            parms.Add("?agentID", agentID);
            parms.Add("?groupID", groupID);
            parms.Add("?roleID", roleID);

            db.QueryNoResults(qInsMembership, parms);
        }
        private void SetAgentGroupSelectedRole(ISimpleDB db, OpenMetaverse.UUID agentID, OpenMetaverse.UUID groupID, OpenMetaverse.UUID roleID)
        {
            string query 
                =   "UPDATE osgroupmembership " +
                    "SET SelectedRoleID = ?roleID " +
                    "WHERE AgentID = ?agentID AND GroupID = ?groupID";

            Dictionary<string, object> parms = new Dictionary<string, object>();
            parms.Add("?roleID", roleID);
            parms.Add("?agentID", agentID);
            parms.Add("?groupID", groupID);

            db.QueryNoResults(query, parms);
        }
        /// <summary>
        /// Delete a folder from database. Must be called from within a using{} block for the database connection.
        /// </summary>
        /// Passing in the connection allows for consolidation of the DB connections, important as this method is often called from an inner loop.
        /// <param name="folderID">the folder UUID</param>
        /// <param name="conn">the database connection</param>
        private void deleteOneFolder(ISimpleDB conn, InventoryFolderBase folder)
        {
            string query = "DELETE FROM inventoryfolders WHERE folderID=?uuid";
            Dictionary<string, object> parms = new Dictionary<string, object>();
            parms.Add("?uuid", folder.ID.ToString());

            conn.QueryNoResults(query, parms);

            // As the callers of this function will increment the version, there's no need to do so here.
        }
Beispiel #27
0
        private void UpdateRegistration(ISimpleDB db, UUID uuid, UUID regionUUID)
        {
            string sql = "INSERT INTO emailregistrations (`uuid`, `time`, `region`) VALUES (?uuid, ?time, ?region)";
            sql += " ON DUPLICATE KEY UPDATE `time`=?time";

            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters["?uuid"] = uuid.ToString();
            parameters["?region"] = regionUUID.ToString();
            parameters["?time"] = DateTime2UnixTime(DateTime.UtcNow);   // All storage dates are UTC

            try
            {
                db.QueryNoResults(sql, parameters);
            }
            catch (Exception e)
            {
                m_log.Error("[InboundEmail]: Exception during database call to store message: "+e.Message);
                m_log.Error(e.StackTrace);
            }
        }
Beispiel #28
0
        private void DeleteMessage(ISimpleDB db, uint ID)
        {
            string sql = "DELETE FROM emailmessages WHERE `ID`=?id";

            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters["?ID"] = ID.ToString();

            try
            {
                db.QueryNoResults(sql, parameters);
            }
            catch (Exception e)
            {
                m_log.Error("[InboundEmail]: Exception during database call to delete delivered message: " + e.Message);
                m_log.Error(e.StackTrace);
            }
        }
        /// <summary>
        /// Increments the version of the passed folder, making sure the folder isn't Zero. Must be called from within a using{} block!
        /// </summary>
        /// <param name="conn">Database connection.</param>
        /// <param name="folderId">Folder UUID to increment</param>
        private void IncrementSpecifiedFolderVersion(ISimpleDB conn, UUID folderId)
        {
            if (folderId != UUID.Zero)
            {
                string query = "update inventoryfolders set version=version+1 where folderID = ?folderID";
                Dictionary<string, object> updParms = new Dictionary<string, object>();
                updParms.Add("?folderID", folderId.ToString());

                conn.QueryNoResults(query, updParms);
            }
        }