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 (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
         {
             dbcon.Open();
             using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
             {
                 cmd.Parameters.AddWithValue("Id", notes.UserId.ToString());
                 cmd.Parameters.AddWithValue("TargetId", notes.TargetId.ToString());
                 
                 using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                 {
                     if(reader.HasRows)
                     {
                         reader.Read();
                         notes.Notes = OSD.FromString((string)reader["notes"]);
                     }
                 }
             }
         }
     }
     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 ( :UserId, :TargetId, :Notes )
                            where not exists ( Select useruuid from usernotes where useruuid = :UserId and targetuuid = :TargetId );

                           update usernotes
                              set notes = :Notes
                            where useruuid = :UserId 
                              and targetuuid = :TargetId;
                        ";
            }
            
            try
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(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;
            
        }
예제 #3
0
        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 OR REPLACE INTO usernotes VALUES ( ";
                query += ":UserId,";
                query += ":TargetId,";
                query += ":Notes )";
            }
            
            try
            {
                using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
                {
                    cmd.CommandText = query;

                    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;
        }
 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;
     
 }
예제 #5
0
        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 = @"WITH upsert AS (
                          UPDATE usernotes SET notes = :Notes, useruuid = :UserId, targetuuid = :TargetId RETURNING * )
                          INSERT INTO usernotes (notes,useruuid,targetuuid)
                          SELECT :Notes,:UserId,:TargetId
                            WHERE NOT EXISTS (
                              SELECT * FROM upsert
                            )";
            }
            
            try
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
                    {
                        if(!remove)
                            cmd.Parameters.Add(m_database.CreateParameter("Notes", note.Notes));

                        cmd.Parameters.Add(m_database.CreateParameter("TargetId", note.TargetId));
                        cmd.Parameters.Add(m_database.CreateParameter("UserId", note.UserId));
                        
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                m_log.Error("[PROFILES_DATA]: UpdateAvatarNotes exception ", e);
                return false;
            }

            return true;            
        }
예제 #6
0
 public bool GetAvatarNotes(ref UserProfileNotes notes)
 {  
     IDataReader reader = null;
     string query = string.Empty;
     
     query += "SELECT `notes` FROM usernotes WHERE ";
     query += "useruuid = :Id AND ";
     query += "targetuuid = :TargetId";
     OSDArray data = new OSDArray();
     
     try
     {
         using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
         {
             cmd.CommandText = query;
             cmd.Parameters.AddWithValue(":Id", notes.UserId.ToString());
             cmd.Parameters.AddWithValue(":TargetId", notes.TargetId.ToString());
             
             using (reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
             {
                 while (reader.Read())
                 {
                     notes.Notes = OSD.FromString((string)reader["notes"]);
                 }
             }
         }
     }
     catch (Exception e)
     {
         m_log.DebugFormat("[PROFILES_DATA]" +
                           ": GetAvatarNotes exception {0}", e.Message);
     }
     return true;
 }
        /// <summary>
        /// Handles the avatar notes request.
        /// </summary>
        /// <param name='sender'>
        /// Sender.
        /// </param>
        /// <param name='method'>
        /// Method.
        /// </param>
        /// <param name='args'>
        /// Arguments.
        /// </param>
        public void NotesRequest(Object sender, string method, List<String> args)
        {
            UserProfileNotes note = new UserProfileNotes();

            if (!(sender is IClientAPI))
                return;

            IClientAPI remoteClient = (IClientAPI)sender;
            string serverURI = string.Empty;
            GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
            note.UserId = remoteClient.AgentId;
            UUID.TryParse(args[0], out note.TargetId);

            object Note = (object)note;
            if(!rpc.JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString()))
            {
                remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
                return;
            }
            note = (UserProfileNotes) Note;
                
            remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
        }
        /// <summary>
        /// Avatars the notes update.
        /// </summary>
        /// <param name='remoteClient'>
        /// Remote client.
        /// </param>
        /// <param name='queryTargetID'>
        /// Query target I.
        /// </param>
        /// <param name='queryNotes'>
        /// Query notes.
        /// </param>
        public void NotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes)
        {
            UserProfileNotes note = new UserProfileNotes();

            note.UserId = remoteClient.AgentId;
            note.TargetId = queryTargetID;
            note.Notes = queryNotes;

            string serverURI = string.Empty;
            GetUserProfileServerURI(remoteClient.AgentId, out serverURI);

            object Note = note;
            if(!rpc.JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString()))
            {
                remoteClient.SendAgentAlertMessage(
                        "Error updating note", false);
                return;
            }
        }
 public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response)
 {
     if(!json.ContainsKey("params"))
     {
         response.Error.Code = ErrorCode.ParseError;
         response.Error.Message = "No parameters";
         m_log.DebugFormat ("Avatar Notes Update Request");
         return false;
     }
     
     string result = string.Empty;
     UserProfileNotes note = new UserProfileNotes();
     object Notes = (object) note;
     OSD.DeserializeMembers(ref Notes, (OSDMap)json["params"]);
     if(Service.NotesUpdate(ref note, ref result))
     {
         response.Result = OSD.SerializeMembers(note);
         return true;
     }
     return true;
 }
예제 #10
0
 public bool NotesUpdate(ref UserProfileNotes note, ref string result)
 {
     return ProfilesData.UpdateAvatarNotes(ref note, ref result);
 }
예제 #11
0
 public bool AvatarNotesRequest(ref UserProfileNotes note)
 {
     return ProfilesData.GetAvatarNotes(ref note);
 }
예제 #12
0
        /// <summary>
        /// Avatars the notes update.
        /// </summary>
        /// <param name='remoteClient'>
        /// Remote client.
        /// </param>
        /// <param name='queryTargetID'>
        /// Query target I.
        /// </param>
        /// <param name='queryNotes'>
        /// Query notes.
        /// </param>
        public void NotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes)
        {
            ScenePresence p = FindPresence(queryTargetID);
            if (p != null && p.isNPC)
            {
                remoteClient.SendAgentAlertMessage(
                        "Notes for NPCs not available", false);
                return;
            }

            UserProfileNotes note = new UserProfileNotes();

            note.UserId = remoteClient.AgentId;
            note.TargetId = queryTargetID;
            note.Notes = queryNotes;

            string serverURI = string.Empty;
            GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
            if(string.IsNullOrWhiteSpace(serverURI))
                return;

            object Note = note;
            if(!rpc.JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString()))
            {
                remoteClient.SendAgentAlertMessage(
                        "Error updating note", false);
                return;
            }
        }
예제 #13
0
        public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response)
        {
            if(!json.ContainsKey("params"))
            {
                response.Error.Code = ErrorCode.ParseError;
                response.Error.Message = "Params missing";
                m_log.DebugFormat ("Avatar Notes Request");
                return false;
            }

            UserProfileNotes note = new UserProfileNotes();
            object Note = (object)note;
            OSD.DeserializeMembers(ref Note, (OSDMap)json["params"]);
            if(Service.AvatarNotesRequest(ref note))
            {
                response.Result = OSD.SerializeMembers(note);
                return true;
            }

            response.Error.Code = ErrorCode.InternalError;
            response.Error.Message = "Error reading notes";
            return false;
        }