Beispiel #1
0
        /// <summary>
        /// This doesn't return the mutelist (mutees) for a user, it returns all users who have this user/object muted (muters).
        /// Implemented as a single DB call.
        /// </summary>
        /// <param name="id">The user or object that may be muted.</param>
        /// <returns>UUIDs of those who have it muted.</returns>
        public List <UUID> GetInverseMuteList(UUID muteID)
        {
            List <UUID> muters = new List <UUID>();

            using (ISimpleDB db = _connectionFactory.GetConnection())
            {
                string query = " SELECT * FROM mutelist WHERE MuteID = ?muteID";

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

                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);

                if (results.Count < 1 || results[0]["AgentID"] == null)
                {
                    return(muters);  // empty list
                }
                foreach (Dictionary <string, string> result in results)
                {
                    UUID MuteID = new UUID(result["AgentID"]);
                    muters.Add(MuteID);
                }
            }
            return(muters);
        }
Beispiel #2
0
        /// <summary>
        /// Return the current regions UP after possibly refreshing if stale.
        /// </summary>
        /// <returns>
        /// null if could not fetch the list (error, unreliable list)
        /// a list (possibly empty although it should always find this one) otherwise
        /// </returns>
        protected List <UUID> UpdateRegionsList(ISimpleDB coredb)
        {
            List <UUID> regions = new List <UUID>();

            lock (mRegionsOnline)
            {
                // The viewer fires 3 parallel requests together.
                // Protect against multiple initial parallel requests by using
                // the lock to block the other threads during the refresh. They need it anyway.

                // If we're up to date though, just return it.
                if ((DateTime.Now - mRegionsOnlineStamp).TotalSeconds < REGIONS_CACHE_TIME)
                {
                    return(mRegionsOnline);
                }

                List <Dictionary <string, string> > results = coredb.QueryWithResults("SELECT uuid FROM regions LIMIT 999999999999");  // no limit
                foreach (var row in results)
                {
                    regions.Add(new UUID(row["UUID"]));
                }

                // Now stamp it inside the lock so that if we reenter,
                // second caller will not make another request.
                mRegionsOnline      = regions;
                mRegionsOnlineStamp = DateTime.Now;
            }
            return(regions);
        }
Beispiel #3
0
        // Picks Handler

        public void HandleAvatarPicksRequest(Object sender, List <String> args)
        {
            if (!(sender is IClientAPI))
            {
                return;
            }

            IClientAPI remoteClient = (IClientAPI)sender;

            UUID avatarID = new UUID(args[0]);

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                Dictionary <UUID, string> picksRequest = new Dictionary <UUID, string>();

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

                string query = "SELECT pickuuid, name from userpicks " +
                               "WHERE creatoruuid=?avatarID";

                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);

                foreach (Dictionary <string, string> row in results)
                {
                    picksRequest[new UUID(row["pickuuid"].ToString())] = row["name"].ToString();
                }

                remoteClient.SendAvatarPicksReply(avatarID,
                                                  picksRequest);
            }
        }
Beispiel #4
0
        public void HandleAvatarNotesRequest(Object sender, string method, List <String> args)
        {
            if (!(sender is IClientAPI))
            {
                return;
            }

            IClientAPI remoteClient   = (IClientAPI)sender;
            UUID       avatarID       = remoteClient.AgentId;
            UUID       targetAvatarID = new UUID(args[0]);

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

                string query = "SELECT notes from usernotes where useruuid=?avatarID AND targetuuid=?targetID";
                List <Dictionary <string, string> > notesResult = db.QueryWithResults(query, parms);

                string notes = String.Empty;
                if (notesResult.Count > 0)
                {
                    notes = notesResult[0]["notes"];
                }
                if (notes == LEGACY_EMPTY)  // filter out the old text that said there was no text. ;)
                {
                    notes = String.Empty;
                }

                remoteClient.SendAvatarNotesReply(targetAvatarID, notes);
            }
        }
Beispiel #5
0
        // Picks Request

        public void HandlePickInfoRequest(Object sender, string method, List <String> args)
        {
            if (!(sender is IClientAPI))
            {
                return;
            }

            IClientAPI remoteClient = (IClientAPI)sender;

            UUID avatarID = new UUID(args[0]);
            UUID pickID   = new UUID(args[1]);

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

                string query = "SELECT * from userpicks WHERE creatoruuid=?avatarID AND pickuuid=?pickID";

                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);

                bool    topPick      = new bool();
                UUID    parcelUUID   = new UUID();
                string  name         = String.Empty;
                string  description  = String.Empty;
                UUID    snapshotID   = new UUID();
                string  userName     = String.Empty;
                string  originalName = String.Empty;
                string  simName      = String.Empty;
                Vector3 globalPos    = new Vector3();
                int     sortOrder    = new int();
                bool    enabled      = new bool();


                foreach (Dictionary <string, string> row in results)
                {
                    topPick     = Boolean.Parse(row["toppick"]);
                    parcelUUID  = UUID.Parse(row["parceluuid"]);
                    name        = row["name"];
                    description = row["description"];
                    snapshotID  = UUID.Parse(row["snapshotuuid"]);
                    userName    = row["user"];
                    //userName = row["simname"];
                    originalName = row["originalname"];
                    simName      = row["simname"];
                    globalPos    = Vector3.Parse(row["posglobal"]);
                    sortOrder    = Convert.ToInt32(row["sortorder"]);
                    enabled      = Boolean.Parse(row["enabled"]);
                }

                remoteClient.SendPickInfoReply(pickID, avatarID,
                                               topPick, parcelUUID, name, description,
                                               snapshotID, userName, originalName,
                                               simName, globalPos, sortOrder,
                                               enabled);
            }
        }
Beispiel #6
0
        private void CacheRdbHosts(ISimpleDB db)
        {
            List <Dictionary <string, string> > hostNames = db.QueryWithResults("SELECT host_name FROM RdbHosts");

            _rdbHostCache.Clear();
            foreach (var hostNameDict in hostNames)
            {
                _rdbHostCache.Add(hostNameDict["host_name"]);
            }

            _rdbCacheTime = DateTime.Now;
        }
Beispiel #7
0
        private List <Dictionary <string, string> > DoLandQueryAndCombine(IClientAPI remoteClient, ISimpleDB coreDb,
                                                                          string query, Dictionary <string, object> parms,
                                                                          uint queryFlags, int queryStart, int queryEnd,
                                                                          List <UUID> regionsToInclude)
        {
            string[] rdbHosts = this.CheckAndRetrieveRdbHostList(coreDb);
            if (rdbHosts.Length == 0)
            {
                // RDB not configured.  Fall back to core db.
                return(coreDb.QueryWithResults(query, parms));
            }

            List <RDBConnectionQuery> rdbQueries = new List <RDBConnectionQuery>();
            int whichDB = 0;

            foreach (string host in rdbHosts)
            {
                // Initialize the RDB connection and initial results lists

                ConnectionFactory rdbFactory;
                if ((++whichDB == 1) || (_rdbConnectionTemplateDebug.Trim() == String.Empty))
                {
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplate, host));
                }
                else  // Special debugging support for multiple RDBs on one machine ("inworldz_rdb2", etc)
                {
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplateDebug, host, whichDB));
                }
                RDBConnectionQuery rdb = new RDBConnectionQuery(rdbFactory.GetConnection(), query, queryFlags, parms);
                rdbQueries.Add(rdb);
            }

            List <Dictionary <string, string> > finalList = new List <Dictionary <string, string> >();
            int current = 0;
            Dictionary <string, string> result = null;

            while ((result = ConsumeNext(rdbQueries, queryFlags)) != null)
            {
                UUID regionUUID = new UUID(result["RegionUUID"]);
                // When regionsToInclude.Count==0, it means do not filter by regions.
                if ((regionsToInclude.Count == 0) || regionsToInclude.Contains(regionUUID))
                {
                    // 0-based numbering
                    if ((current >= queryStart) && (current <= queryEnd))
                    {
                        finalList.Add(result);
                    }
                    current++;
                }
            }

            return(finalList);
        }
Beispiel #8
0
        /// <summary>
        /// Don't use this for messages broadcast to more than one user
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="target"></param>
        /// <returns>Returns true if target has sender muted.</returns>
        public bool IsMuted(UUID sender, UUID target)
        {
            using (ISimpleDB db = _connectionFactory.GetConnection())
            {
                string query = "SELECT COUNT(*) as MuteCount FROM mutelist WHERE AgentID = ?agentID AND MuteID = ?muteID";

                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("?agentID", target);
                parms.Add("?muteID", sender);

                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);

                return(Convert.ToInt32(results[0]["MuteCount"]) != 0);
            }
        }
Beispiel #9
0
        private Email QueryNextEmail(ISimpleDB db, UUID uuid, string sender, string subject)
        {
            Email msg = new Email();

            try
            {
                Dictionary <string, object> parms = new Dictionary <string, object>();
                string query = "SELECT * FROM emailmessages WHERE uuid = ?uuid";
                parms.Add("?uuid", uuid);
                if (!String.IsNullOrEmpty(sender))
                {
                    query += " AND from = ?from";
                    parms.Add("?from", sender);
                }
                if (!String.IsNullOrEmpty(subject))
                {
                    query += " AND subject = ?subject";
                    parms.Add("?subject", subject);
                }
                query += " ORDER BY sent LIMIT 1";

                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);
                if (results.Count != 1)
                {
                    return(null);
                }

                uint ID       = Convert.ToUInt32(results[0]["ID"]);
                uint unixtime = Convert.ToUInt32(results[0]["sent"]);
                msg.time    = unixtime.ToString();  // Note: email event is documented as string form of *UTC* unix time
                msg.sender  = results[0]["from"];
                msg.subject = results[0]["subject"];
                msg.message = results[0]["body"];

                // This one has been handled, remove it from those queued in the DB.
                DeleteMessage(db, ID);
            }
            catch (Exception e)
            {
                m_log.Error("[InboundEmail]: Exception during database call to store message: " + e.Message);
                m_log.Error(e.StackTrace);
                return(null);
            }

            msg.numLeft = (int)QueryEmailCount(db, uuid);
            return(msg);
        }
Beispiel #10
0
        public void ClassifiedInfoRequest(UUID queryClassifiedID, IClientAPI remoteClient)
        {
            // okies this is pretty simple straightforward stuff as well... pull the info from the
            // db based on the Classified ID we got back from viewer from the original query above
            // and send it back.

            //ClassifiedData data = new ClassifiedData();

            string query = "select * from classifieds where classifieduuid=?classifiedID";

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

            parms.Add("?classifiedID", queryClassifiedID);

            Vector3 globalPos = new Vector3();

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);
                foreach (Dictionary <string, string> row in results)
                {
                    Vector3.TryParse(row["posglobal"].ToString(), out globalPos);

                    //remoteClient.SendClassifiedInfoReply(data);

                    remoteClient.SendClassifiedInfoReply(
                        new UUID(row["classifieduuid"].ToString()),
                        new UUID(row["creatoruuid"].ToString()),
                        Convert.ToUInt32(row["creationdate"]),
                        Convert.ToUInt32(row["expirationdate"]),
                        Convert.ToUInt32(row["category"]),
                        row["name"].ToString(),
                        row["description"].ToString(),
                        new UUID(row["parceluuid"].ToString()),
                        Convert.ToUInt32(row["parentestate"]),
                        new UUID(row["snapshotuuid"].ToString()),
                        row["simname"].ToString(),
                        globalPos,
                        row["parcelname"].ToString(),
                        Convert.ToByte(row["classifiedflags"]),
                        Convert.ToInt32(row["priceforlisting"]));
                }
            }
        }
Beispiel #11
0
        // Interests Handler

        public void HandleAvatarInterestsRequest(Object sender, List <String> args)
        {
            IClientAPI remoteClient = (IClientAPI)sender;

            UUID avatarID = new UUID(args[0]);

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                uint   skillsMask    = new uint();
                string skillsText    = String.Empty;
                uint   wantToMask    = new uint();
                string wantToText    = String.Empty;
                string languagesText = String.Empty;

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

                string query = "SELECT skillsMask, skillsText, wantToMask, wantToText, languagesText FROM users " +
                               "WHERE UUID=?avatarID";

                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);

                foreach (Dictionary <string, string> row in results)
                {
                    skillsMask    = Convert.ToUInt16(row["skillsMask"]);
                    skillsText    = row["skillsText"];
                    wantToMask    = Convert.ToUInt16(row["wantToMask"]);
                    wantToText    = row["wantToText"];
                    languagesText = row["languagesText"];
                }

                remoteClient.SendAvatarInterestsReply(avatarID,
                                                      wantToMask,
                                                      wantToText,
                                                      skillsMask,
                                                      skillsText,
                                                      languagesText);
            }
        }
Beispiel #12
0
        private Dictionary <UUID, MuteListEntry> DBLoadMuteList(UUID AgentID)
        {
            using (ISimpleDB db = _connectionFactory.GetConnection())
            {
                string query = " SELECT AgentID, MuteType, MuteID, MuteName, MuteFlags" +
                               " FROM mutelist" +
                               " WHERE " +
                               "  AgentID = ?agentID";

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

                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);

                if (results.Count < 1 || results[0]["AgentID"] == null)
                {
                    return(null);
                }

                return(MapMuteListFromDBResults(results));
            }
        }
Beispiel #13
0
        private uint QueryEmailCount(ISimpleDB db, UUID uuid)
        {
            try
            {
                string query
                    = "SELECT COUNT(*) FROM emailmessages WHERE uuid = ?uuid";
                Dictionary <string, object> parms = new Dictionary <string, object>();
                parms.Add("?uuid", uuid);

                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);
                if (results.Count != 1)
                {
                    return(0);
                }

                return(Convert.ToUInt32(results[0]["COUNT(*)"]));
            }
            catch (Exception e)
            {
                m_log.Error("[InboundEmail]: Exception during database call to count messages: " + e.Message);
                m_log.Error(e.StackTrace);
                return(0);
            }
        }
Beispiel #14
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.
                }
            }
        }
Beispiel #15
0
        public void DirEventsQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart)
        {
            // Flags are going to be 0 or 32 for Mature
            // We also know text comes in 3 segments X|Y|Text where X is the day difference from
            // the current day, Y is the category to search, Text is the user input for search string
            // so let's 'split up the queryText to get our values we need first off
            string eventTime     = "";
            string eventCategory = "";
            string userText      = "";

            queryText = queryText.Trim();   // newer viewers sometimes append a space

            string[] querySplode = queryText.Split(new Char[] { '|' });
            if (querySplode.Length > 0)
            {
                eventTime = querySplode[0];
            }
            if (querySplode.Length > 1)
            {
                eventCategory = querySplode[1];
            }
            if (querySplode.Length > 0)
            {
                userText = querySplode[2];
                userText = userText.Trim();   // newer viewers sometimes append a space
            }

            // Ok we have values, now we need to do something with all this lovely information
            string query       = "";
            string searchStart = Convert.ToString(queryStart);
            int    count       = 100;

            DirEventsReplyData[] data = new DirEventsReplyData[count];
            string searchEnd          = Convert.ToString(queryStart + count);
            int    i = 0;
            int    unixEventUpcomingEndDateToCheck = 0;

            int eventTimeAmt = 0;
            int unixEventDateToCheckMidnight    = 0;
            int unixEventEndDateToCheckMidnight = 0;

            string sqlAddTerms = "";

            DateTime saveNow = DateTime.Now;
            int      startDateCheck;

            // Quick catch to see if the eventTime is set to "u" for In Progress & Upcoming Radio button
            if (eventTime == "u")
            {
                DateTime eventUpcomingEndDateToCheck         = saveNow.AddDays(+7);
                DateTime eventUpcomingEndDateToCheckMidnight = new DateTime(eventUpcomingEndDateToCheck.Year, eventUpcomingEndDateToCheck.Month, eventUpcomingEndDateToCheck.Day);
                unixEventUpcomingEndDateToCheck = Util.ToUnixTime(eventUpcomingEndDateToCheckMidnight);

                // for "in progress" events, show everything that has started within the last three hours (arbitrary)
                startDateCheck = Util.ToUnixTime(saveNow.AddHours(-3.0));
                sqlAddTerms    = " where (dateUTC>=?startDateCheck AND dateUTC<=?unixEventUpcomingEndDateToCheck)";
            }
            else
            {
                // we need the current date, in order to subtract/add the days to view, or see the week upcoming.
                // this will probably be some really ugly code :)
                startDateCheck = Util.ToUnixTime(saveNow);
                eventTimeAmt   = Convert.ToInt16(eventTime);
                DateTime eventDateToCheck    = saveNow.AddDays(Convert.ToInt16(eventTime));
                DateTime eventEndDateToCheck = new DateTime();
                if (eventTime == "0")
                {
                    eventEndDateToCheck = saveNow.AddDays(+2);
                }
                else
                {
                    eventEndDateToCheck = saveNow.AddDays(eventTimeAmt + 1);
                }
                // now truncate the information so we get the midnight value (and yes David, I'm sure there's an
                // easier way to do this, but this will work for now :)  )
                DateTime eventDateToCheckMidnight    = new DateTime(eventDateToCheck.Year, eventDateToCheck.Month, eventDateToCheck.Day);
                DateTime eventEndDateToCheckMidnight = new DateTime(eventEndDateToCheck.Year, eventEndDateToCheck.Month, eventEndDateToCheck.Day);


                // this is the start unix timestamp to look for, we still need the end which is the next day, plus
                // we need the week end unix timestamp for the In Progress & upcoming radio button
                unixEventDateToCheckMidnight    = Util.ToUnixTime(eventDateToCheckMidnight);
                unixEventEndDateToCheckMidnight = Util.ToUnixTime(eventEndDateToCheckMidnight);

                sqlAddTerms = " where (dateUTC>=?unixEventDateToCheck AND dateUTC<=?unixEventEndDateToCheckMidnight)";
            }

            if ((queryFlags & ((uint)DirFindFlags.IncludeAdult | (uint)DirFindFlags.IncludeAdult | (uint)DirFindFlags.IncludeAdult)) == 0)
            {
                // don't just give them an empty list...
                remoteClient.SendAlertMessage("You must included at least one maturity rating.");
                remoteClient.SendDirEventsReply(queryID, data);
                return;
            }

            // Event DB storage does not currently support adult events, so if someone asks for adult, search mature for now.
            if ((queryFlags & (uint)DirFindFlags.IncludeAdult) != 0)
            {
                queryFlags |= (uint)DirFindFlags.IncludeMature;
            }

            if ((queryFlags & (uint)DirFindFlags.IncludeMature) != 0)
            {
                // they included mature and possibly others
                if ((queryFlags & (uint)DirFindFlags.IncludePG) == 0)
                {
                    sqlAddTerms += " AND mature='true'";   // exclude PG
                }
            }
            if ((queryFlags & (uint)DirFindFlags.IncludePG) != 0)
            {
                // they included PG and possibly others
                if ((queryFlags & (uint)DirFindFlags.IncludeMature) == 0)
                {
                    sqlAddTerms += " AND mature='false'";  // exclude mature
                }
            }

            if (eventCategory != "0")
            {
                sqlAddTerms += " AND category=?category";
            }

            if (userText != "")
            {
                sqlAddTerms += " AND (description LIKE ?userText OR name LIKE ?userText)";
            }

            // Events results should come back sorted by date
            sqlAddTerms += " order by dateUTC ASC";

            query = "select owneruuid, name, eventid, dateUTC, eventflags from events" + sqlAddTerms + " limit " + searchStart + ", " + searchEnd + "";

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

            parms.Add("?startDateCheck", Convert.ToString(startDateCheck));
            parms.Add("?unixEventUpcomingEndDateToCheck", Convert.ToString(unixEventUpcomingEndDateToCheck));
            parms.Add("?unixEventDateToCheck", Convert.ToString(unixEventDateToCheckMidnight));
            parms.Add("?unixEventEndDateToCheckMidnight", Convert.ToString(unixEventEndDateToCheckMidnight));
            parms.Add("?category", eventCategory);
            parms.Add("?userText", "%" + Convert.ToString(userText) + "%");

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);
                foreach (Dictionary <string, string> row in results)
                {
                    data[i]         = new DirEventsReplyData();
                    data[i].ownerID = new UUID(row["owneruuid"].ToString());
                    data[i].name    = row["name"].ToString();
                    data[i].eventID = Convert.ToUInt32(row["eventid"]);

                    // need to convert the unix timestamp we get into legible date for viewer
                    DateTime localViewerEventTime = Util.UnixToLocalDateTime(Convert.ToInt32(row["dateUTC"]));
                    string   newSendingDate       = String.Format("{0:MM/dd hh:mm tt}", localViewerEventTime);

                    data[i].date       = newSendingDate;
                    data[i].unixTime   = Convert.ToUInt32(row["dateUTC"]);
                    data[i].eventFlags = Convert.ToUInt32(row["eventflags"]);
                    i++;
                    if (i >= count)
                    {
                        break;
                    }
                }
            }
            remoteClient.SendDirEventsReply(queryID, data);
        }
Beispiel #16
0
 private void RefreshList(ISimpleDB rdb, string query, Dictionary <string, object> parms, List <Dictionary <string, string> > results)
 {
     results.AddRange(rdb.QueryWithResults(query, parms));
 }
        /// <summary>
        /// Return the current regions UP after possibly refreshing if stale.
        /// </summary>
        /// <returns>
        /// null if could not fetch the list (error, unreliable list)
        /// a list (possibly empty although it should always find this one) otherwise
        /// </returns>
        protected List<UUID> UpdateRegionsList(ISimpleDB coredb)
        {
            List<UUID> regions = new List<UUID>();

            lock (mRegionsOnline)
            {
                // The viewer fires 3 parallel requests together.
                // Protect against multiple initial parallel requests by using
                // the lock to block the other threads during the refresh. They need it anyway.

                // If we're up to date though, just return it.
                if ((DateTime.Now - mRegionsOnlineStamp).TotalSeconds < REGIONS_CACHE_TIME)
                    return mRegionsOnline;

                List<Dictionary<string, string>> results = coredb.QueryWithResults("SELECT uuid FROM regions LIMIT 999999999999");  // no limit
                foreach (var row in results)
                {
                    regions.Add(new UUID(row["UUID"]));
                }

                // Now stamp it inside the lock so that if we reenter, 
                // second caller will not make another request.
                mRegionsOnline = regions;
                mRegionsOnlineStamp = DateTime.Now;
            }
            return regions;
        }
        private List<Dictionary<string, string>> DoLandQueryAndCombine(IClientAPI remoteClient, ISimpleDB coreDb, 
                                                                    string query, Dictionary<string, object> parms,
                                                                    uint queryFlags, int queryStart, int queryEnd, 
                                                                    List<UUID> regionsToInclude)
        {
            string[] rdbHosts = this.CheckAndRetrieveRdbHostList(coreDb);
            if (rdbHosts.Length == 0)
            {
                // RDB not configured.  Fall back to core db.
                return coreDb.QueryWithResults(query, parms);
            }

            List<RDBConnectionQuery> rdbQueries = new List<RDBConnectionQuery>();
            int whichDB = 0;
            foreach (string host in rdbHosts)
            {
                // Initialize the RDB connection and initial results lists

                ConnectionFactory rdbFactory;
                if ((++whichDB == 1) || String.IsNullOrWhiteSpace(_rdbConnectionTemplateDebug))
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplate, host));
                else  // Special debugging support for multiple RDBs on one machine ("inworldz_rdb2", etc)
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplateDebug, host, whichDB));
                RDBConnectionQuery rdb = new RDBConnectionQuery(rdbFactory.GetConnection(), query, queryFlags, parms);
                rdbQueries.Add(rdb);
            }

            List<Dictionary<string, string>> finalList = new List<Dictionary<string, string>>();
            int current = 0;
            Dictionary<string, string> result = null;
            while ((result = ConsumeNext(rdbQueries, queryFlags)) != null)
            {
                UUID regionUUID = new UUID(result["RegionUUID"]);
                // When regionsToInclude.Count==0, it means do not filter by regions.
                if ((regionsToInclude.Count == 0) || regionsToInclude.Contains(regionUUID))
                {
                    // 0-based numbering
                    if ((current >= queryStart) && (current <= queryEnd))
                        finalList.Add(result);
                    current++;
                }
            }

            return finalList;
        }
 private void RefreshList(ISimpleDB rdb, string query, Dictionary<string, object> parms, List<Dictionary<string, string>> results)
 {
     results.AddRange(rdb.QueryWithResults(query, parms));
 }
Beispiel #20
0
            private void RefreshResults()
            {
                string limited_query = m_query + " LIMIT " + m_offset.ToString() + ", " + QUERY_SIZE.ToString();

                m_results.AddRange(m_rdb.QueryWithResults(limited_query, m_parms));
            }
Beispiel #21
0
        public void DirClassifiedQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, uint category,
                                       int queryStart)
        {
            // This is pretty straightforward here, get the input, set up the query, run it through, send back to viewer.
            string query       = "";
            string sqlAddTerms = "";
            string userText    = queryText.Trim(); // newer viewers sometimes append a space

            string searchStart = Convert.ToString(queryStart);
            int    count       = MAX_RESULTS + 1; // +1 so that the viewer knows to enable the NEXT button (it seems)
            string searchEnd   = Convert.ToString(queryStart + count);
            int    i           = 0;

            // There is a slight issue with the parcel data not coming from land first so the
            //  parcel information is never displayed correctly within in the classified ad.

            //stop blank queries here before they explode mysql
            if (userText == "")
            {
                remoteClient.SendDirClassifiedReply(queryID, new DirClassifiedReplyData[0]);
                return;
            }

            if (queryFlags == 0)
            {
                sqlAddTerms = " AND (classifiedflags='2' OR classifiedflags='34') ";
            }

            if (category != 0)
            {
                sqlAddTerms = " AND category=?category ";
            }

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

            parms.Add("?matureFlag", queryFlags);
            parms.Add("?category", category);
            parms.Add("?userText", userText);

            // Ok a test cause the query pulls fine direct in MySQL, but not from here, so WTF?!
            //query = "select classifieduuid, name, classifiedflags, creationdate, expirationdate, priceforlisting from classifieds " +
            //        "where name LIKE '" + userText + "' OR description LIKE '" + userText + "' " + sqlAddTerms;

            query = "select classifieduuid, name, classifiedflags, creationdate, expirationdate, priceforlisting from classifieds " +
                    "where (description REGEXP ?userText OR name REGEXP ?userText) " + sqlAddTerms + " order by priceforlisting DESC limit " + searchStart + ", " + searchEnd + "";

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);
                count = results.Count;
                DirClassifiedReplyData[] data = new DirClassifiedReplyData[count];
                foreach (Dictionary <string, string> row in results)
                {
                    data[i] = new DirClassifiedReplyData();
                    data[i].classifiedID    = new UUID(row["classifieduuid"].ToString());
                    data[i].name            = row["name"].ToString();
                    data[i].classifiedFlags = Convert.ToByte(row["classifiedflags"]);
                    data[i].creationDate    = Convert.ToUInt32(row["creationdate"]);
                    data[i].expirationDate  = Convert.ToUInt32(row["expirationdate"]);
                    data[i].price           = Convert.ToInt32(row["priceforlisting"]);
                    i++;
                }
                remoteClient.SendDirClassifiedReply(queryID, data);
            }
        }
Beispiel #22
0
        private uint QueryEmailCount(ISimpleDB db, UUID uuid)
        {
            try
            {
                string query
                    = "SELECT COUNT(*) FROM emailmessages WHERE uuid = ?uuid";
                Dictionary<string, object> parms = new Dictionary<string, object>();
                parms.Add("?uuid", uuid);

                List<Dictionary<string, string>> results = db.QueryWithResults(query, parms);
                if (results.Count != 1)
                    return 0;

                return Convert.ToUInt32(results[0]["COUNT(*)"]);
            }
            catch (Exception e)
            {
                m_log.Error("[InboundEmail]: Exception during database call to count messages: " + e.Message);
                m_log.Error(e.StackTrace);
                return 0;
            }
        }
Beispiel #23
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);
            }
        }
        private bool AgentHasActiveGroup(ISimpleDB db, OpenMetaverse.UUID agentID)
        {
            string query
                = "SELECT COUNT(*) AS agentCount " +
                    "FROM osagent " +
                    "WHERE AgentID = ?agentID";

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

            List<Dictionary<string, string>> results = db.QueryWithResults(query, parms);
            if (results.Count > 0 && Int32.Parse(results[0]["agentCount"]) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        // WARNING: This function only supports queries that result in a TOTAL number of results of 100 or less.
        // If too many results come back, the rest can be discarded/lost. Intended for searching for a specific parcel ID (1 result).
        // See AvatarSearchModule.cs for the alternative more complex implementation that avoids this restriction.
        private List<Dictionary<string, string>> DoLandQueryAndCombine(ISimpleDB coreDb, string query, Dictionary<string, object> parms)
        {
            string[] rdbHosts = this.CheckAndRetrieveRdbHostList(coreDb);

            if (rdbHosts.Length == 0)
            {
                // RDB not configured.  Fall back to core db.
                return coreDb.QueryWithResults(query, parms);
            }

            List<Dictionary<string, string>> finalList = new List<Dictionary<string, string>>();
            int whichDB = 0;
            foreach (string host in rdbHosts)
            {
                ConnectionFactory rdbFactory;
                if ((++whichDB == 1) || String.IsNullOrWhiteSpace(_rdbConnectionTemplateDebug))
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplate, host));
                else  // Special debugging support for multiple RDBs on one machine ("inworldz_rdb2", etc)
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplateDebug, host, whichDB));
                using (ISimpleDB rdb = rdbFactory.GetConnection())
                {
                    finalList.AddRange(rdb.QueryWithResults(query, parms));
                }
            }

            return finalList;
        }
        private static Dictionary<string, string> FindGroupPowersForAgent(ISimpleDB db, UUID groupID, UUID agentID)
        {
            string query =  " SELECT BIT_OR(osrole.Powers) AS GroupPowers" +
                            " FROM osgrouprolemembership JOIN osrole ON (osgrouprolemembership.GroupID = osrole.GroupID AND osgrouprolemembership.RoleID = osrole.RoleID)" +
                            " WHERE osgrouprolemembership.GroupID = ?groupID AND osgrouprolemembership.AgentID = ?agentID";

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

            List<Dictionary<string, string>> powersResults = db.QueryWithResults(query, parms);

            if (powersResults.Count == 0)
            {
                m_log.Error("[GROUPS]: Could not find any matching powers for agent");
                return null;
            }

            return powersResults[0];
        }
        private void CacheRdbHosts(ISimpleDB db)
        {
            List<Dictionary<string, string>> hostNames = db.QueryWithResults("SELECT host_name FROM RdbHosts");

            _rdbHostCache.Clear();
            foreach (var hostNameDict in hostNames)
            {
                _rdbHostCache.Add(hostNameDict["host_name"]);
            }

            _rdbCacheTime = DateTime.Now;
        }
        private bool IsAgentMemberOfGroup(ISimpleDB db, OpenMetaverse.UUID agentID, OpenMetaverse.UUID groupID)
        {
            // If the caller intends to allow a group operation for a null group ID (e.g. ActivateGroup),
            // then the caller is the one that needs to check that case and support it.
            if (groupID == UUID.Zero)
                return false;   // don't bother making the DB call

            string qIsAgentMember =
                    "SELECT count(AgentID) AS isMember " +
                    "FROM osgroupmembership " +
                    "WHERE AgentID = ?agentID AND GroupID = ?groupID";

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

            List<Dictionary<string, string>> isAgentMemberResults = db.QueryWithResults(qIsAgentMember, parms);

            if (isAgentMemberResults.Count == 0)
            {
                //this shouldnt happen
                m_log.Error("[GROUPS]: IsAgentMemberOfGroup: Expected at least one record");
                return false;
            }
            if (Convert.ToInt32(isAgentMemberResults[0]["isMember"]) > 0)
            {
                return true;
            }
            return false;
        }
        private bool IsAgentInRole(ISimpleDB db, OpenMetaverse.UUID AgentID, OpenMetaverse.UUID GroupID, OpenMetaverse.UUID RoleID)
        {
            string query
                = "SELECT count(AgentID) as isMember " +
                    "FROM osgrouprolemembership " +
                    "WHERE AgentID = ?agentID AND RoleID = ?roleID AND GroupID = ?groupID";

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

            List<Dictionary<string, string>> agentInRoleResults = db.QueryWithResults(query, parms);

            if (agentInRoleResults.Count == 0)
            {
                //this shouldnt happen
                m_log.Error("[GROUPS]: IsAgentInRole: Expected at least one record");
                return false;
            }
            else if (agentInRoleResults[0]["isMember"] == "0")
            {
                return false;
            }
            else
            {
                return true;
            }
        }
Beispiel #30
0
        private Email QueryNextEmail(ISimpleDB db, UUID uuid, string sender, string subject)
        {
            Email msg = new Email();

            try
            {
                Dictionary<string, object> parms = new Dictionary<string, object>();
                string query = "SELECT * FROM emailmessages WHERE uuid = ?uuid";
                parms.Add("?uuid", uuid);
                if (!String.IsNullOrEmpty(sender))
                {
                    query += " AND from = ?from";
                    parms.Add("?from", sender);
                }
                if (!String.IsNullOrEmpty(subject))
                {
                    query += " AND subject = ?subject";
                    parms.Add("?subject", subject);
                }
                query += " ORDER BY sent LIMIT 1";

                List<Dictionary<string, string>> results = db.QueryWithResults(query, parms);
                if (results.Count != 1)
                    return null;

                uint ID = Convert.ToUInt32(results[0]["ID"]);
                uint unixtime = Convert.ToUInt32(results[0]["sent"]);
                msg.time = unixtime.ToString();     // Note: email event is documented as string form of *UTC* unix time
                msg.sender = results[0]["from"];
                msg.subject = results[0]["subject"];
                msg.message = results[0]["body"];

                // This one has been handled, remove it from those queued in the DB.
                DeleteMessage(db, ID);
            }
            catch (Exception e)
            {
                m_log.Error("[InboundEmail]: Exception during database call to store message: " + e.Message);
                m_log.Error(e.StackTrace);
                return null;
            }

            msg.numLeft = (int)QueryEmailCount(db, uuid);
            return msg;
        }
Beispiel #31
0
        public void EventInfoRequest(IClientAPI remoteClient, uint queryEventID)
        {
            EventData data = new EventData();
            Dictionary <string, object> parms = new Dictionary <string, object>();

            parms.Add("?eventID", queryEventID);

            string query = "select * from events where eventid=?eventID";

            using (ISimpleDB db = _connFactory.GetConnection())
            {
                List <Dictionary <string, string> > results = db.QueryWithResults(query, parms);
                foreach (Dictionary <string, string> row in results)
                {
                    data.eventID = Convert.ToUInt32(row["eventid"]);
                    data.creator = row["creatoruuid"].ToString();
                    data.name    = row["name"].ToString();
                    // need to convert this from the integer it is to the
                    // real string value so it shows correctly
                    if (row["category"] == "18")
                    {
                        data.category = "Discussion";
                    }
                    if (row["category"] == "19")
                    {
                        data.category = "Sports";
                    }
                    if (row["category"] == "20")
                    {
                        data.category = "Live Music";
                    }
                    if (row["category"] == "22")
                    {
                        data.category = "Commercial";
                    }
                    if (row["category"] == "23")
                    {
                        data.category = "Nightlife/Entertainment";
                    }
                    if (row["category"] == "24")
                    {
                        data.category = "Games/Contests";
                    }
                    if (row["category"] == "25")
                    {
                        data.category = "Pageants";
                    }
                    if (row["category"] == "26")
                    {
                        data.category = "Education";
                    }
                    if (row["category"] == "27")
                    {
                        data.category = "Arts and Culture";
                    }
                    if (row["category"] == "28")
                    {
                        data.category = "Charity/Support Groups";
                    }
                    if (row["category"] == "29")
                    {
                        data.category = "Miscellaneous";
                    }

                    data.description = row["description"].ToString();

                    // do something here with date to format it correctly for what
                    // the viewer needs!
                    //data.date = row["date"].ToString();

                    // need to convert the unix timestamp we get into legible date for viewer
                    DateTime localViewerEventTime = Util.UnixToLocalDateTime(Convert.ToInt32(row["dateUTC"]));
                    string   newSendingDate       = String.Format("{0:yyyy-MM-dd HH:MM:ss}", localViewerEventTime);

                    data.date = newSendingDate;

                    data.dateUTC  = Convert.ToUInt32(row["dateUTC"]);
                    data.duration = Convert.ToUInt32(row["duration"]);
                    data.cover    = Convert.ToUInt32(row["covercharge"]);
                    data.amount   = Convert.ToUInt32(row["coveramount"]);
                    data.simName  = row["simname"].ToString();
                    Vector3.TryParse(row["globalPos"].ToString(), out data.globalPos);
                    data.eventFlags = Convert.ToUInt32(row["eventflags"]);
                }
            }

            remoteClient.SendEventInfoReply(data);
        }