public void DirEventsQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart) { Hashtable ReqHash = new Hashtable(); ReqHash["text"] = queryText; ReqHash["flags"] = queryFlags.ToString(); ReqHash["query_start"] = queryStart.ToString(); Hashtable result = GenericXMLRPCRequest(ReqHash, "dir_events_query"); if (!Convert.ToBoolean(result["success"])) { remoteClient.SendAgentAlertMessage( result["errorMessage"].ToString(), false); return; } ArrayList dataArray = (ArrayList)result["data"]; int count = dataArray.Count; if (count > 100) { count = 101; } DirEventsReplyData[] data = new DirEventsReplyData[count]; int i = 0; foreach (Object o in dataArray) { Hashtable d = (Hashtable)o; data[i] = new DirEventsReplyData(); data[i].ownerID = new UUID(d["owner_id"].ToString()); data[i].name = d["name"].ToString(); data[i].eventID = Convert.ToUInt32(d["event_id"]); data[i].date = d["date"].ToString(); data[i].unixTime = Convert.ToUInt32(d["unix_time"]); data[i].eventFlags = Convert.ToUInt32(d["event_flags"]); i++; if (i >= count) { break; } } remoteClient.SendDirEventsReply(queryID, data); }
public void DirEventsQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart) { DirEventsReplyData[] ReturnValues = directoryService.FindEvents(queryText, queryFlags.ToString(), queryStart); //Split into sets of 10 packets if (ReturnValues.Length > 10) { DirEventsReplyData[] data = new DirEventsReplyData[10]; int i = 0; foreach (DirEventsReplyData d in ReturnValues) { data[i] = d; i++; if (i == 10) { remoteClient.SendDirEventsReply(queryID, data); i = 0; if (data.Length - i < 10) data = new DirEventsReplyData[data.Length - i]; else data = new DirEventsReplyData[10]; } } //Send the remaining packets if(data.Length != 0) remoteClient.SendDirEventsReply(queryID, data); } else //Send the remaining as they are under 10 remoteClient.SendDirEventsReply(queryID, ReturnValues); }
public void DirEventsQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart) { Hashtable ReqHash = new Hashtable(); ReqHash["text"] = queryText; ReqHash["flags"] = queryFlags.ToString(); ReqHash["query_start"] = queryStart.ToString(); Hashtable result = GenericXMLRPCRequest(ReqHash, "dir_events_query"); if (!Convert.ToBoolean(result["success"])) { remoteClient.SendAgentAlertMessage( result["errorMessage"].ToString(), false); return; } ArrayList dataArray = (ArrayList)result["data"]; int count = dataArray.Count; if (count > 100) count = 101; DirEventsReplyData[] data = new DirEventsReplyData[count]; int i = 0; foreach (Object o in dataArray) { Hashtable d = (Hashtable)o; data[i] = new DirEventsReplyData(); data[i].ownerID = new UUID(d["owner_id"].ToString()); data[i].name = d["name"].ToString(); data[i].eventID = Convert.ToUInt32(d["event_id"]); data[i].date = d["date"].ToString(); data[i].unixTime = Convert.ToUInt32(d["unix_time"]); data[i].eventFlags = Convert.ToUInt32(d["event_flags"]); if (++i >= count) break; } remoteClient.SendDirEventsReply(queryID, data); }
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.Empty; string eventCategory = String.Empty; string userText = String.Empty; 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.Empty; 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 = String.Empty; 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(!String.IsNullOrEmpty(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 + String.Empty; 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); }
public void DirEventsQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart) { DirEventsReplyData[] ReturnValues = DSC.FindEvents(queryText, queryFlags.ToString(), queryStart); if (ReturnValues.Length > 10) { DirEventsReplyData[] data = new DirEventsReplyData[10]; int i = 0; foreach (DirEventsReplyData d in ReturnValues) { data[i] = d; i++; if (i == 10) { remoteClient.SendDirEventsReply(queryID, data); i = 0; if (data.Length - i < 10) { data = new DirEventsReplyData[data.Length - i]; } else { data = new DirEventsReplyData[10]; } } } remoteClient.SendDirEventsReply(queryID, data); } else remoteClient.SendDirEventsReply(queryID, ReturnValues); }
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); }