123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101 |
- /*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- using System;
- using System.Data;
- using System.Reflection;
- using OpenSim.Data;
- using OpenSim.Framework;
- using MySql.Data.MySqlClient;
- using OpenMetaverse;
- using OpenMetaverse.StructuredData;
- using log4net;
- namespace OpenSim.Data.MySQL
- {
- public class UserProfilesData: IProfilesData
- {
- static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-
- #region Properites
- string ConnectionString
- {
- get; set;
- }
- protected object Lock
- {
- get; set;
- }
-
- protected virtual Assembly Assembly
- {
- get { return GetType().Assembly; }
- }
-
- #endregion Properties
-
- #region class Member Functions
- public UserProfilesData(string connectionString)
- {
- ConnectionString = connectionString;
- Init();
- }
-
- void Init()
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
-
- Migration m = new Migration(dbcon, Assembly, "UserProfiles");
- m.Update();
- }
- }
- #endregion Member Functions
-
- #region Classifieds Queries
- /// <summary>
- /// Gets the classified records.
- /// </summary>
- /// <returns>
- /// Array of classified records
- /// </returns>
- /// <param name='creatorId'>
- /// Creator identifier.
- /// </param>
- public OSDArray GetClassifiedRecords(UUID creatorId)
- {
- OSDArray data = new OSDArray();
-
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- string query = "SELECT classifieduuid, name FROM classifieds WHERE creatoruuid = ?Id";
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?Id", creatorId);
- using( MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
- {
- if(reader.HasRows)
- {
- while (reader.Read())
- {
- OSDMap n = new OSDMap();
- UUID Id = UUID.Zero;
-
- string Name = null;
- try
- {
- UUID.TryParse(Convert.ToString( reader["classifieduuid"]), out Id);
- Name = Convert.ToString(reader["name"]);
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": UserAccount exception {0}", e.Message);
- }
- n.Add("classifieduuid", OSD.FromUUID(Id));
- n.Add("name", OSD.FromString(Name));
- data.Add(n);
- }
- }
- }
- }
- }
- return data;
- }
-
- public bool UpdateClassifiedRecord(UserClassifiedAdd ad, ref string result)
- {
- string query = string.Empty;
-
-
- query += "INSERT INTO classifieds (";
- query += "`classifieduuid`,";
- query += "`creatoruuid`,";
- query += "`creationdate`,";
- query += "`expirationdate`,";
- query += "`category`,";
- query += "`name`,";
- query += "`description`,";
- query += "`parceluuid`,";
- query += "`parentestate`,";
- query += "`snapshotuuid`,";
- query += "`simname`,";
- query += "`posglobal`,";
- query += "`parcelname`,";
- query += "`classifiedflags`,";
- query += "`priceforlisting`) ";
- query += "VALUES (";
- query += "?ClassifiedId,";
- query += "?CreatorId,";
- query += "?CreatedDate,";
- query += "?ExpirationDate,";
- query += "?Category,";
- query += "?Name,";
- query += "?Description,";
- query += "?ParcelId,";
- query += "?ParentEstate,";
- query += "?SnapshotId,";
- query += "?SimName,";
- query += "?GlobalPos,";
- query += "?ParcelName,";
- query += "?Flags,";
- query += "?ListingPrice ) ";
- query += "ON DUPLICATE KEY UPDATE ";
- query += "category=?Category, ";
- query += "expirationdate=?ExpirationDate, ";
- query += "name=?Name, ";
- query += "description=?Description, ";
- query += "parentestate=?ParentEstate, ";
- query += "posglobal=?GlobalPos, ";
- query += "parcelname=?ParcelName, ";
- query += "classifiedflags=?Flags, ";
- query += "priceforlisting=?ListingPrice, ";
- query += "snapshotuuid=?SnapshotId";
-
- if(string.IsNullOrEmpty(ad.ParcelName))
- ad.ParcelName = "Unknown";
- if(ad.ParcelId == null)
- ad.ParcelId = UUID.Zero;
- if(string.IsNullOrEmpty(ad.Description))
- ad.Description = "No Description";
-
- DateTime epoch = new DateTime(1970, 1, 1);
- DateTime now = DateTime.Now;
- TimeSpan epochnow = now - epoch;
- TimeSpan duration;
- DateTime expiration;
- TimeSpan epochexp;
-
- if(ad.Flags == 2)
- {
- duration = new TimeSpan(7,0,0,0);
- expiration = now.Add(duration);
- epochexp = expiration - epoch;
- }
- else
- {
- duration = new TimeSpan(365,0,0,0);
- expiration = now.Add(duration);
- epochexp = expiration - epoch;
- }
- ad.CreationDate = (int)epochnow.TotalSeconds;
- ad.ExpirationDate = (int)epochexp.TotalSeconds;
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?ClassifiedId", ad.ClassifiedId.ToString());
- cmd.Parameters.AddWithValue("?CreatorId", ad.CreatorId.ToString());
- cmd.Parameters.AddWithValue("?CreatedDate", ad.CreationDate.ToString());
- cmd.Parameters.AddWithValue("?ExpirationDate", ad.ExpirationDate.ToString());
- cmd.Parameters.AddWithValue("?Category", ad.Category.ToString());
- cmd.Parameters.AddWithValue("?Name", ad.Name.ToString());
- cmd.Parameters.AddWithValue("?Description", ad.Description.ToString());
- cmd.Parameters.AddWithValue("?ParcelId", ad.ParcelId.ToString());
- cmd.Parameters.AddWithValue("?ParentEstate", ad.ParentEstate.ToString());
- cmd.Parameters.AddWithValue("?SnapshotId", ad.SnapshotId.ToString ());
- cmd.Parameters.AddWithValue("?SimName", ad.SimName.ToString());
- cmd.Parameters.AddWithValue("?GlobalPos", ad.GlobalPos.ToString());
- cmd.Parameters.AddWithValue("?ParcelName", ad.ParcelName.ToString());
- cmd.Parameters.AddWithValue("?Flags", ad.Flags.ToString());
- cmd.Parameters.AddWithValue("?ListingPrice", ad.Price.ToString ());
-
- cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": ClassifiedesUpdate exception {0}", e.Message);
- result = e.Message;
- return false;
- }
- return true;
- }
-
- public bool DeleteClassifiedRecord(UUID recordId)
- {
- string query = string.Empty;
-
- query += "DELETE FROM classifieds WHERE ";
- query += "classifieduuid = ?ClasifiedId";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
-
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?ClassifiedId", recordId.ToString());
-
- lock(Lock)
- {
- cmd.ExecuteNonQuery();
- }
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": DeleteClassifiedRecord exception {0}", e.Message);
- return false;
- }
- return true;
- }
-
- public bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result)
- {
- string query = string.Empty;
-
- query += "SELECT * FROM classifieds WHERE ";
- query += "classifieduuid = ?AdId";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?AdId", ad.ClassifiedId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- if(reader.Read ())
- {
- ad.CreatorId = new UUID(reader.GetGuid("creatoruuid"));
- ad.ParcelId = new UUID(reader.GetGuid("parceluuid"));
- ad.SnapshotId = new UUID(reader.GetGuid("snapshotuuid"));
- ad.CreationDate = Convert.ToInt32(reader["creationdate"]);
- ad.ExpirationDate = Convert.ToInt32(reader["expirationdate"]);
- ad.ParentEstate = Convert.ToInt32(reader["parentestate"]);
- ad.Flags = (byte)reader.GetUInt32("classifiedflags");
- ad.Category = reader.GetInt32("category");
- ad.Price = reader.GetInt16("priceforlisting");
- ad.Name = reader.GetString("name");
- ad.Description = reader.GetString("description");
- ad.SimName = reader.GetString("simname");
- ad.GlobalPos = reader.GetString("posglobal");
- ad.ParcelName = reader.GetString("parcelname");
-
- }
- }
- }
- dbcon.Close();
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": GetPickInfo exception {0}", e.Message);
- }
- return true;
- }
- #endregion Classifieds Queries
-
- #region Picks Queries
- public OSDArray GetAvatarPicks(UUID avatarId)
- {
- string query = string.Empty;
-
- query += "SELECT `pickuuid`,`name` FROM userpicks WHERE ";
- query += "creatoruuid = ?Id";
- OSDArray data = new OSDArray();
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- if(reader.HasRows)
- {
- while (reader.Read())
- {
- OSDMap record = new OSDMap();
-
- record.Add("pickuuid",OSD.FromString((string)reader["pickuuid"]));
- record.Add("name",OSD.FromString((string)reader["name"]));
- data.Add(record);
- }
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": GetAvatarPicks exception {0}", e.Message);
- }
- return data;
- }
-
- public UserProfilePick GetPickInfo(UUID avatarId, UUID pickId)
- {
- string query = string.Empty;
- UserProfilePick pick = new UserProfilePick();
-
- query += "SELECT * FROM userpicks WHERE ";
- query += "creatoruuid = ?CreatorId AND ";
- query += "pickuuid = ?PickId";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?CreatorId", avatarId.ToString());
- cmd.Parameters.AddWithValue("?PickId", pickId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- if(reader.HasRows)
- {
- reader.Read();
-
- string description = (string)reader["description"];
-
- if (string.IsNullOrEmpty(description))
- description = "No description given.";
-
- UUID.TryParse((string)reader["pickuuid"], out pick.PickId);
- UUID.TryParse((string)reader["creatoruuid"], out pick.CreatorId);
- UUID.TryParse((string)reader["parceluuid"], out pick.ParcelId);
- UUID.TryParse((string)reader["snapshotuuid"], out pick.SnapshotId);
- pick.GlobalPos = (string)reader["posglobal"];
- bool.TryParse((string)reader["toppick"], out pick.TopPick);
- bool.TryParse((string)reader["enabled"], out pick.Enabled);
- pick.Name = (string)reader["name"];
- pick.Desc = description;
- pick.User = (string)reader["user"];
- pick.OriginalName = (string)reader["originalname"];
- pick.SimName = (string)reader["simname"];
- pick.SortOrder = (int)reader["sortorder"];
- }
- }
- }
- dbcon.Close();
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": GetPickInfo exception {0}", e.Message);
- }
- return pick;
- }
-
- public bool UpdatePicksRecord(UserProfilePick pick)
- {
- string query = string.Empty;
-
- query += "INSERT INTO userpicks VALUES (";
- query += "?PickId,";
- query += "?CreatorId,";
- query += "?TopPick,";
- query += "?ParcelId,";
- query += "?Name,";
- query += "?Desc,";
- query += "?SnapshotId,";
- query += "?User,";
- query += "?Original,";
- query += "?SimName,";
- query += "?GlobalPos,";
- query += "?SortOrder,";
- query += "?Enabled) ";
- query += "ON DUPLICATE KEY UPDATE ";
- query += "parceluuid=?ParcelId,";
- query += "name=?Name,";
- query += "description=?Desc,";
- query += "snapshotuuid=?SnapshotId,";
- query += "pickuuid=?PickId,";
- query += "posglobal=?GlobalPos";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?PickId", pick.PickId.ToString());
- cmd.Parameters.AddWithValue("?CreatorId", pick.CreatorId.ToString());
- cmd.Parameters.AddWithValue("?TopPick", pick.TopPick.ToString());
- cmd.Parameters.AddWithValue("?ParcelId", pick.ParcelId.ToString());
- cmd.Parameters.AddWithValue("?Name", pick.Name.ToString());
- cmd.Parameters.AddWithValue("?Desc", pick.Desc.ToString());
- cmd.Parameters.AddWithValue("?SnapshotId", pick.SnapshotId.ToString());
- cmd.Parameters.AddWithValue("?User", pick.User.ToString());
- cmd.Parameters.AddWithValue("?Original", pick.OriginalName.ToString());
- cmd.Parameters.AddWithValue("?SimName",pick.SimName.ToString());
- cmd.Parameters.AddWithValue("?GlobalPos", pick.GlobalPos);
- cmd.Parameters.AddWithValue("?SortOrder", pick.SortOrder.ToString ());
- cmd.Parameters.AddWithValue("?Enabled", pick.Enabled.ToString());
-
- cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": UpdateAvatarNotes exception {0}", e.Message);
- return false;
- }
- return true;
- }
-
- public bool DeletePicksRecord(UUID pickId)
- {
- string query = string.Empty;
-
- query += "DELETE FROM userpicks WHERE ";
- query += "pickuuid = ?PickId";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
-
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?PickId", pickId.ToString());
-
- cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": DeleteUserPickRecord exception {0}", e.Message);
- return false;
- }
- return true;
- }
- #endregion Picks Queries
-
- #region Avatar Notes Queries
- public bool GetAvatarNotes(ref UserProfileNotes notes)
- { // WIP
- string query = string.Empty;
-
- query += "SELECT `notes` FROM usernotes WHERE ";
- query += "useruuid = ?Id AND ";
- query += "targetuuid = ?TargetId";
- OSDArray data = new OSDArray();
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?Id", notes.UserId.ToString());
- cmd.Parameters.AddWithValue("?TargetId", notes.TargetId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
- {
- if(reader.HasRows)
- {
- reader.Read();
- notes.Notes = OSD.FromString((string)reader["notes"]);
- }
- else
- {
- notes.Notes = OSD.FromString("");
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": GetAvatarNotes exception {0}", e.Message);
- }
- return true;
- }
-
- public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
- {
- string query = string.Empty;
- bool remove;
-
- if(string.IsNullOrEmpty(note.Notes))
- {
- remove = true;
- query += "DELETE FROM usernotes WHERE ";
- query += "useruuid=?UserId AND ";
- query += "targetuuid=?TargetId";
- }
- else
- {
- remove = false;
- query += "INSERT INTO usernotes VALUES ( ";
- query += "?UserId,";
- query += "?TargetId,";
- query += "?Notes )";
- query += "ON DUPLICATE KEY ";
- query += "UPDATE ";
- query += "notes=?Notes";
- }
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- if(!remove)
- cmd.Parameters.AddWithValue("?Notes", note.Notes);
- cmd.Parameters.AddWithValue("?TargetId", note.TargetId.ToString ());
- cmd.Parameters.AddWithValue("?UserId", note.UserId.ToString());
-
- cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": UpdateAvatarNotes exception {0}", e.Message);
- return false;
- }
- return true;
-
- }
- #endregion Avatar Notes Queries
-
- #region Avatar Properties
- public bool GetAvatarProperties(ref UserProfileProperties props, ref string result)
- {
- string query = string.Empty;
-
- query += "SELECT * FROM userprofile WHERE ";
- query += "useruuid = ?Id";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?Id", props.UserId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
- {
- if(reader.HasRows)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": Getting data for {0}.", props.UserId);
- reader.Read();
- props.WebUrl = (string)reader["profileURL"];
- UUID.TryParse((string)reader["profileImage"], out props.ImageId);
- props.AboutText = (string)reader["profileAboutText"];
- UUID.TryParse((string)reader["profileFirstImage"], out props.FirstLifeImageId);
- props.FirstLifeText = (string)reader["profileFirstText"];
- UUID.TryParse((string)reader["profilePartner"], out props.PartnerId);
- props.WantToMask = (int)reader["profileWantToMask"];
- props.WantToText = (string)reader["profileWantToText"];
- props.SkillsMask = (int)reader["profileSkillsMask"];
- props.SkillsText = (string)reader["profileSkillsText"];
- props.Language = (string)reader["profileLanguages"];
- }
- else
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": No data for {0}", props.UserId);
-
- props.WebUrl = string.Empty;
- props.ImageId = UUID.Zero;
- props.AboutText = string.Empty;
- props.FirstLifeImageId = UUID.Zero;
- props.FirstLifeText = string.Empty;
- props.PartnerId = UUID.Zero;
- props.WantToMask = 0;
- props.WantToText = string.Empty;
- props.SkillsMask = 0;
- props.SkillsText = string.Empty;
- props.Language = string.Empty;
- props.PublishProfile = false;
- props.PublishMature = false;
- query = "INSERT INTO userprofile (";
- query += "useruuid, ";
- query += "profilePartner, ";
- query += "profileAllowPublish, ";
- query += "profileMaturePublish, ";
- query += "profileURL, ";
- query += "profileWantToMask, ";
- query += "profileWantToText, ";
- query += "profileSkillsMask, ";
- query += "profileSkillsText, ";
- query += "profileLanguages, ";
- query += "profileImage, ";
- query += "profileAboutText, ";
- query += "profileFirstImage, ";
- query += "profileFirstText) VALUES (";
- query += "?userId, ";
- query += "?profilePartner, ";
- query += "?profileAllowPublish, ";
- query += "?profileMaturePublish, ";
- query += "?profileURL, ";
- query += "?profileWantToMask, ";
- query += "?profileWantToText, ";
- query += "?profileSkillsMask, ";
- query += "?profileSkillsText, ";
- query += "?profileLanguages, ";
- query += "?profileImage, ";
- query += "?profileAboutText, ";
- query += "?profileFirstImage, ";
- query += "?profileFirstText)";
- dbcon.Close();
- dbcon.Open();
- using (MySqlCommand put = new MySqlCommand(query, dbcon))
- {
- put.Parameters.AddWithValue("?userId", props.UserId.ToString());
- put.Parameters.AddWithValue("?profilePartner", props.PartnerId.ToString());
- put.Parameters.AddWithValue("?profileAllowPublish", props.PublishProfile);
- put.Parameters.AddWithValue("?profileMaturePublish", props.PublishMature);
- put.Parameters.AddWithValue("?profileURL", props.WebUrl);
- put.Parameters.AddWithValue("?profileWantToMask", props.WantToMask);
- put.Parameters.AddWithValue("?profileWantToText", props.WantToText);
- put.Parameters.AddWithValue("?profileSkillsMask", props.SkillsMask);
- put.Parameters.AddWithValue("?profileSkillsText", props.SkillsText);
- put.Parameters.AddWithValue("?profileLanguages", props.Language);
- put.Parameters.AddWithValue("?profileImage", props.ImageId.ToString());
- put.Parameters.AddWithValue("?profileAboutText", props.AboutText);
- put.Parameters.AddWithValue("?profileFirstImage", props.FirstLifeImageId.ToString());
- put.Parameters.AddWithValue("?profileFirstText", props.FirstLifeText);
- put.ExecuteNonQuery();
- }
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": Requst properties exception {0}", e.Message);
- result = e.Message;
- return false;
- }
- return true;
- }
-
- public bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result)
- {
- string query = string.Empty;
-
- query += "UPDATE userprofile SET ";
- query += "profilePartner=?profilePartner, ";
- query += "profileURL=?profileURL, ";
- query += "profileImage=?image, ";
- query += "profileAboutText=?abouttext,";
- query += "profileFirstImage=?firstlifeimage,";
- query += "profileFirstText=?firstlifetext ";
- query += "WHERE useruuid=?uuid";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?profileURL", props.WebUrl);
- cmd.Parameters.AddWithValue("?profilePartner", props.PartnerId.ToString());
- cmd.Parameters.AddWithValue("?image", props.ImageId.ToString());
- cmd.Parameters.AddWithValue("?abouttext", props.AboutText);
- cmd.Parameters.AddWithValue("?firstlifeimage", props.FirstLifeImageId.ToString());
- cmd.Parameters.AddWithValue("?firstlifetext", props.FirstLifeText);
- cmd.Parameters.AddWithValue("?uuid", props.UserId.ToString());
-
- cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": AgentPropertiesUpdate exception {0}", e.Message);
-
- return false;
- }
- return true;
- }
- #endregion Avatar Properties
-
- #region Avatar Interests
- public bool UpdateAvatarInterests(UserProfileProperties up, ref string result)
- {
- string query = string.Empty;
-
- query += "UPDATE userprofile SET ";
- query += "profileWantToMask=?WantMask, ";
- query += "profileWantToText=?WantText,";
- query += "profileSkillsMask=?SkillsMask,";
- query += "profileSkillsText=?SkillsText, ";
- query += "profileLanguages=?Languages ";
- query += "WHERE useruuid=?uuid";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?WantMask", up.WantToMask);
- cmd.Parameters.AddWithValue("?WantText", up.WantToText);
- cmd.Parameters.AddWithValue("?SkillsMask", up.SkillsMask);
- cmd.Parameters.AddWithValue("?SkillsText", up.SkillsText);
- cmd.Parameters.AddWithValue("?Languages", up.Language);
- cmd.Parameters.AddWithValue("?uuid", up.UserId.ToString());
-
- cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": AgentInterestsUpdate exception {0}", e.Message);
- result = e.Message;
- return false;
- }
- return true;
- }
- #endregion Avatar Interests
- public OSDArray GetUserImageAssets(UUID avatarId)
- {
- OSDArray data = new OSDArray();
- string query = "SELECT `snapshotuuid` FROM {0} WHERE `creatoruuid` = ?Id";
- // Get classified image assets
-
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(string.Format (query,"`classifieds`"), dbcon))
- {
- cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
- {
- if(reader.HasRows)
- {
- while (reader.Read())
- {
- data.Add(new OSDString((string)reader["snapshotuuid"].ToString ()));
- }
- }
- }
- }
- dbcon.Close();
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(string.Format (query,"`userpicks`"), dbcon))
- {
- cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
- {
- if(reader.HasRows)
- {
- while (reader.Read())
- {
- data.Add(new OSDString((string)reader["snapshotuuid"].ToString ()));
- }
- }
- }
- }
-
- dbcon.Close();
- dbcon.Open();
- query = "SELECT `profileImage`, `profileFirstImage` FROM `userprofile` WHERE `useruuid` = ?Id";
- using (MySqlCommand cmd = new MySqlCommand(string.Format (query,"`userpicks`"), dbcon))
- {
- cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
- {
- if(reader.HasRows)
- {
- while (reader.Read())
- {
- data.Add(new OSDString((string)reader["profileImage"].ToString ()));
- data.Add(new OSDString((string)reader["profileFirstImage"].ToString ()));
- }
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": GetAvatarNotes exception {0}", e.Message);
- }
- return data;
- }
-
- #region User Preferences
- public bool GetUserPreferences(ref UserPreferences pref, ref string result)
- {
- string query = string.Empty;
-
- query += "SELECT imviaemail,visible,email FROM ";
- query += "usersettings WHERE ";
- query += "useruuid = ?Id";
-
- OSDArray data = new OSDArray();
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?Id", pref.UserId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader())
- {
- if(reader.HasRows)
- {
- reader.Read();
- bool.TryParse((string)reader["imviaemail"], out pref.IMViaEmail);
- bool.TryParse((string)reader["visible"], out pref.Visible);
- pref.EMail = (string)reader["email"];
- }
- else
- {
- dbcon.Close();
- dbcon.Open();
-
- query = "INSERT INTO usersettings VALUES ";
- query += "(?uuid,'false','false', ?Email)";
- using (MySqlCommand put = new MySqlCommand(query, dbcon))
- {
-
- put.Parameters.AddWithValue("?Email", pref.EMail);
- put.Parameters.AddWithValue("?uuid", pref.UserId.ToString());
- put.ExecuteNonQuery();
- }
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": Get preferences exception {0}", e.Message);
- result = e.Message;
- return false;
- }
- return true;
- }
-
- public bool UpdateUserPreferences(ref UserPreferences pref, ref string result)
- {
- string query = string.Empty;
- query += "UPDATE usersettings SET ";
- query += "imviaemail=?ImViaEmail, ";
- query += "visible=?Visible ";
- query += "WHERE useruuid=?uuid";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?ImViaEmail", pref.IMViaEmail);
- cmd.Parameters.AddWithValue("?Visible", pref.Visible);
- cmd.Parameters.AddWithValue("?uuid", pref.UserId.ToString());
- cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": AgentInterestsUpdate exception {0}", e.Message);
- result = e.Message;
- return false;
- }
- return true;
- }
- #endregion User Preferences
-
- #region Integration
- public bool GetUserAppData(ref UserAppData props, ref string result)
- {
- string query = string.Empty;
-
- query += "SELECT * FROM `userdata` WHERE ";
- query += "UserId = ?Id AND ";
- query += "TagId = ?TagId";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?Id", props.UserId.ToString());
- cmd.Parameters.AddWithValue ("?TagId", props.TagId.ToString());
-
- using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
- {
- if(reader.HasRows)
- {
- reader.Read();
- props.DataKey = (string)reader["DataKey"];
- props.DataVal = (string)reader["DataVal"];
- }
- else
- {
- query += "INSERT INTO userdata VALUES ( ";
- query += "?UserId,";
- query += "?TagId,";
- query += "?DataKey,";
- query += "?DataVal) ";
-
- using (MySqlCommand put = new MySqlCommand(query, dbcon))
- {
- put.Parameters.AddWithValue("?Id", props.UserId.ToString());
- put.Parameters.AddWithValue("?TagId", props.TagId.ToString());
- put.Parameters.AddWithValue("?DataKey", props.DataKey.ToString());
- put.Parameters.AddWithValue("?DataVal", props.DataVal.ToString());
-
- lock(Lock)
- {
- put.ExecuteNonQuery();
- }
- }
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": Requst application data exception {0}", e.Message);
- result = e.Message;
- return false;
- }
- return true;
- }
- public bool SetUserAppData(UserAppData props, ref string result)
- {
- string query = string.Empty;
-
- query += "UPDATE userdata SET ";
- query += "TagId = ?TagId, ";
- query += "DataKey = ?DataKey, ";
- query += "DataVal = ?DataVal WHERE ";
- query += "UserId = ?UserId AND ";
- query += "TagId = ?TagId";
-
- try
- {
- using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
- {
- cmd.Parameters.AddWithValue("?UserId", props.UserId.ToString());
- cmd.Parameters.AddWithValue("?TagId", props.TagId.ToString ());
- cmd.Parameters.AddWithValue("?DataKey", props.DataKey.ToString ());
- cmd.Parameters.AddWithValue("?DataVal", props.DataKey.ToString ());
-
- lock(Lock)
- {
- cmd.ExecuteNonQuery();
- }
- }
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[PROFILES_DATA]" +
- ": SetUserData exception {0}", e.Message);
- return false;
- }
- return true;
- }
- #endregion Integration
- }
- }
|