public bool UpdatePicksRecord(UserProfilePick pick)
        {       
            string query = string.Empty;

            query = @"INSERT INTO userpicks VALUES ( :PickId, :CreatorId, :TopPick, :ParcelId,:Name, :Desc, :SnapshotId,:User,
                          :Original, :SimName, :GlobalPos, :SortOrder, :Enabled) 
                      where not exists ( select pickid from userpicks where pickid = :pickid);

                     Update userpicks
                        set parceluuid = :ParcelId,
                            name = :Name,
                            description  = :Desc,
                            snapshotuuid = :SnapshotId,
                            pickuuid     = :PickId,
                            posglobal    = :GlobalPos
                       where pickid = :PickId;
                    ";
            
            try
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(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 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 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 (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
         {
             dbcon.Open();
             using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
             {
                 cmd.Parameters.AddWithValue("CreatorId", avatarId.ToString());
                 cmd.Parameters.AddWithValue("PickId", pickId.ToString());
                 
                 using (NpgsqlDataReader 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 = @"WITH upsert AS (
                        UPDATE userpicks SET
                            pickuuid = :PickId, creatoruuid = :CreatorId, toppick = :TopPick, parceluuid = :ParcelId,
                            name = :Name, description = :Desc, snapshotuuid = :SnapshotId, ""user"" = :User, 
                            originalname = :Original, simname = :SimName, posglobal = :GlobalPos, 
                            sortorder = :SortOrder, enabled = :Enabled 
                        RETURNING * ) 
                      INSERT INTO userpicks (pickuuid,creatoruuid,toppick,parceluuid,name,description,
                            snapshotuuid,""user"",originalname,simname,posglobal,sortorder,enabled) 
                      SELECT
                            :PickId,:CreatorId,:TopPick,:ParcelId,:Name,:Desc,:SnapshotId,:User,
                            :Original,:SimName,:GlobalPos,:SortOrder,:Enabled 
                      WHERE NOT EXISTS (
                        SELECT * FROM upsert )";
                    
            try
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
                    {
                        cmd.Parameters.Add(m_database.CreateParameter("PickId", pick.PickId));
                        cmd.Parameters.Add(m_database.CreateParameter("CreatorId", pick.CreatorId));
                        cmd.Parameters.Add(m_database.CreateParameter("TopPick", pick.TopPick));
                        cmd.Parameters.Add(m_database.CreateParameter("ParcelId", pick.ParcelId));
                        cmd.Parameters.Add(m_database.CreateParameter("Name", pick.Name));
                        cmd.Parameters.Add(m_database.CreateParameter("Desc", pick.Desc));
                        cmd.Parameters.Add(m_database.CreateParameter("SnapshotId", pick.SnapshotId));
                        cmd.Parameters.Add(m_database.CreateParameter("User", pick.ParcelName));
                        cmd.Parameters.Add(m_database.CreateParameter("Original", pick.OriginalName));
                        cmd.Parameters.Add(m_database.CreateParameter("SimName",pick.SimName));
                        cmd.Parameters.Add(m_database.CreateParameter("GlobalPos", pick.GlobalPos));
                        cmd.Parameters.Add(m_database.CreateParameter("SortOrder", pick.SortOrder));
                        cmd.Parameters.Add(m_database.CreateParameter("Enabled", pick.Enabled));
                        
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                m_log.Error("[PROFILES_DATA]: UpdateAvatarNotes exception ", e);
                return false;
            }

            return true;
        }
        public bool UpdatePicksRecord(UserProfilePick pick)
        {      
            string query = string.Empty;

            query += "INSERT OR REPLACE INTO userpicks (";
            query += "pickuuid, ";
            query += "creatoruuid, ";
            query += "toppick, ";
            query += "parceluuid, ";
            query += "name, ";
            query += "description, ";
            query += "snapshotuuid, ";
            query += "user, ";
            query += "originalname, ";
            query += "simname, ";
            query += "posglobal, ";
            query += "sortorder, ";
            query += "enabled ) ";
            query += "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) ";
            
            try
            {
                using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
                {
                    int top_pick;
                    int.TryParse(pick.TopPick.ToString(), out top_pick);
                    int enabled;
                    int.TryParse(pick.Enabled.ToString(), out enabled);

                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue(":PickId", pick.PickId.ToString());
                    cmd.Parameters.AddWithValue(":CreatorId", pick.CreatorId.ToString());
                    cmd.Parameters.AddWithValue(":TopPick", top_pick);
                    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", enabled);

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[PROFILES_DATA]" +
                                  ": UpdateAvatarNotes exception {0}", e.Message);
                return false;
            }
            return true;
        }
        /// <summary>
        /// Updates the userpicks
        /// </summary>
        /// <param name='remoteClient'>
        /// Remote client.
        /// </param>
        /// <param name='pickID'>
        /// Pick I.
        /// </param>
        /// <param name='creatorID'>
        /// the creator of the pick
        /// </param>
        /// <param name='topPick'>
        /// Top pick.
        /// </param>
        /// <param name='name'>
        /// Name.
        /// </param>
        /// <param name='desc'>
        /// Desc.
        /// </param>
        /// <param name='snapshotID'>
        /// Snapshot I.
        /// </param>
        /// <param name='sortOrder'>
        /// Sort order.
        /// </param>
        /// <param name='enabled'>
        /// Enabled.
        /// </param>
        public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc, UUID snapshotID, int sortOrder, bool enabled)
        {            
            m_log.DebugFormat("[PROFILES]: Start PickInfoUpdate Name: {0} PickId: {1} SnapshotId: {2}", name, pickID.ToString(), snapshotID.ToString());

            UserProfilePick pick = new UserProfilePick();
            string serverURI = string.Empty;
            GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
            ScenePresence p = FindPresence(remoteClient.AgentId);

            Vector3 avaPos = p.AbsolutePosition;
            // Getting the global position for the Avatar
            Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.WorldLocX + avaPos.X,
                                            remoteClient.Scene.RegionInfo.WorldLocY + avaPos.Y,
                                            avaPos.Z);

            string landOwnerName = string.Empty;
            ILandObject land = p.Scene.LandChannel.GetLandObject(avaPos.X, avaPos.Y);

            if (land != null)
            {
                if (land.LandData.IsGroupOwned)
                {
                    IGroupsModule groupMod = p.Scene.RequestModuleInterface<IGroupsModule>();
                    UUID groupId = land.LandData.GroupID;
                    GroupRecord groupRecord = groupMod.GetGroupRecord(groupId);
                    landOwnerName = groupRecord.GroupName;
                }
                else
                {
                    IUserAccountService accounts = p.Scene.RequestModuleInterface<IUserAccountService>();
                    UserAccount user = accounts.GetUserAccount(p.Scene.RegionInfo.ScopeID, land.LandData.OwnerID);
                    landOwnerName = user.Name;
                }
            }
            else
            {
                m_log.WarnFormat(
                    "[PROFILES]: PickInfoUpdate found no parcel info at {0},{1} in {2}", 
                    avaPos.X, avaPos.Y, p.Scene.Name);
            }

            pick.PickId = pickID;
            pick.CreatorId = creatorID;
            pick.TopPick = topPick;
            pick.Name = name;
            pick.Desc = desc;
            pick.ParcelId = p.currentParcelUUID;
            pick.SnapshotId = snapshotID;
            pick.User = landOwnerName;
            pick.SimName = remoteClient.Scene.RegionInfo.RegionName;
            pick.GlobalPos = posGlobal.ToString();
            pick.SortOrder = sortOrder;
            pick.Enabled = enabled;

            object Pick = (object)pick;
            if(!rpc.JsonRpcRequest(ref Pick, "picks_update", serverURI, UUID.Random().ToString()))
            {
                remoteClient.SendAgentAlertMessage(
                        "Error updating pick", false);
                return;
            }

            m_log.DebugFormat("[PROFILES]: Finish PickInfoUpdate {0} {1}", pick.Name, pick.PickId.ToString());
        }
        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 (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
                    {
                        cmd.Parameters.Add(m_database.CreateParameter("CreatorId", avatarId));
                        cmd.Parameters.Add(m_database.CreateParameter("PickId", pickId));
                        
                        using (NpgsqlDataReader reader = cmd.ExecuteReader())
                        {
                            if(reader.HasRows)
                            {
                                reader.Read();
                                
                                string description = (string)reader["description"];
                                
                                if (string.IsNullOrEmpty(description))
                                    description = "No description given.";
                                
                                pick.PickId = DBGuid.FromDB(reader["pickuuid"]);
                                pick.CreatorId = DBGuid.FromDB(reader["creatoruuid"]);
                                pick.ParcelId = DBGuid.FromDB(reader["parceluuid"]);
                                pick.SnapshotId = DBGuid.FromDB(reader["snapshotuuid"]);
                                pick.GlobalPos = (string)reader["posglobal"].ToString();
                                pick.TopPick = Convert.ToBoolean(reader["toppick"]);
                                pick.Enabled = Convert.ToBoolean(reader["enabled"]);
                                pick.Name = reader["name"].ToString ();
                                pick.Desc = reader["description"].ToString();
                                pick.ParcelName = reader["user"].ToString();
                                pick.OriginalName = reader["originalname"].ToString();
                                pick.SimName = reader["simname"].ToString();
                                pick.SortOrder = (int)reader["sortorder"];
                            }
                        }
                    }
                    dbcon.Close();
                }
            }
            catch (Exception e)
            {
                m_log.Error("[PROFILES_DATA]: GetPickInfo exception ", e);
            }

            return pick;
        }
 public bool PicksUpdate(OSDMap json, ref JsonRpcResponse response)
 {
     if(!json.ContainsKey("params"))
     {
         response.Error.Code = ErrorCode.ParseError;
         response.Error.Message = "no parameters supplied";
         m_log.DebugFormat ("Avatar Picks Update Request");
         return false;
     }
     
     string result = string.Empty;
     UserProfilePick pick = new UserProfilePick();
     object Pick = (object)pick;
     OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]);
     if(Service.PicksUpdate(ref pick, ref result))
     {
         response.Result = OSD.SerializeMembers(pick);
         return true;
     }
     
     response.Error.Code = ErrorCode.InternalError;
     response.Error.Message = "unable to update pick";
     
     return false;
 }
        /// <summary>
        /// Handles the pick info request.
        /// </summary>
        /// <param name='sender'>
        /// Sender.
        /// </param>
        /// <param name='method'>
        /// Method.
        /// </param>
        /// <param name='args'>
        /// Arguments.
        /// </param>
        public void PickInfoRequest(Object sender, string method, List<String> args)
        {
            if (!(sender is IClientAPI))
                return;

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

            UserProfilePick pick = new UserProfilePick();
            UUID.TryParse(args[0], out pick.CreatorId);
            UUID.TryParse(args[1], out pick.PickId);

                
            object Pick = (object)pick;
            if(!rpc.JsonRpcRequest(ref Pick, "pickinforequest", serverURI, UUID.Random().ToString()))
            {
                remoteClient.SendAgentAlertMessage(
                        "Error selecting pick", false);
                return;
            }
            pick = (UserProfilePick) Pick;
             
            Vector3 globalPos;
            Vector3.TryParse(pick.GlobalPos,out globalPos);

            m_log.DebugFormat("[PROFILES]: PickInfoRequest: {0} : {1}", pick.Name.ToString(), pick.SnapshotId.ToString());

            remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
                                           pick.Desc,pick.SnapshotId,pick.User,pick.OriginalName,pick.SimName,
                                           globalPos,pick.SortOrder,pick.Enabled);
        }
 public bool PickInfoRequest(ref UserProfilePick pick, ref string result)
 {
     pick = ProfilesData.GetPickInfo(pick.CreatorId, pick.PickId);
     result = "OK";
     return true;
 }
 public bool PicksUpdate(ref UserProfilePick pick, ref string result)
 {
     return ProfilesData.UpdatePicksRecord(pick);
 }
Example #12
0
        /// <summary>
        /// Updates the userpicks
        /// </summary>
        /// <param name='remoteClient'>
        /// Remote client.
        /// </param>
        /// <param name='pickID'>
        /// Pick I.
        /// </param>
        /// <param name='creatorID'>
        /// the creator of the pick
        /// </param>
        /// <param name='topPick'>
        /// Top pick.
        /// </param>
        /// <param name='name'>
        /// Name.
        /// </param>
        /// <param name='desc'>
        /// Desc.
        /// </param>
        /// <param name='snapshotID'>
        /// Snapshot I.
        /// </param>
        /// <param name='sortOrder'>
        /// Sort order.
        /// </param>
        /// <param name='enabled'>
        /// Enabled.
        /// </param>
        public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc, UUID snapshotID, int sortOrder, bool enabled)
        {        
            //TODO: See how this works with NPC, May need to test
            m_log.DebugFormat("[PROFILES]: Start PickInfoUpdate Name: {0} PickId: {1} SnapshotId: {2}", name, pickID.ToString(), snapshotID.ToString());

            UserProfilePick pick = new UserProfilePick();
            string serverURI = string.Empty;
            GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
            ScenePresence p = FindPresence(remoteClient.AgentId);

            Vector3 avaPos = p.AbsolutePosition;
            // Getting the global position for the Avatar
            Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.WorldLocX + avaPos.X,
                                            remoteClient.Scene.RegionInfo.WorldLocY + avaPos.Y,
                                            avaPos.Z);

            string  landParcelName  = "My Parcel";
            UUID    landParcelID    = p.currentParcelUUID;

            ILandObject land = p.Scene.LandChannel.GetLandObject(avaPos.X, avaPos.Y);

            if (land != null)
            {
                // If land found, use parcel uuid from here because the value from SP will be blank if the avatar hasnt moved
                landParcelName  = land.LandData.Name;
                landParcelID    = land.LandData.GlobalID;
            }
            else
            {
                m_log.WarnFormat(
                    "[PROFILES]: PickInfoUpdate found no parcel info at {0},{1} in {2}", 
                    avaPos.X, avaPos.Y, p.Scene.Name);
            }


            pick.PickId = pickID;
            pick.CreatorId = creatorID;
            pick.TopPick = topPick;
            pick.Name = name;
            pick.Desc = desc;
            pick.ParcelId = landParcelID;
            pick.SnapshotId = snapshotID;
            pick.ParcelName = landParcelName;
            pick.SimName = remoteClient.Scene.RegionInfo.RegionName;
            pick.Gatekeeper = MyGatekeeper;
            pick.GlobalPos = posGlobal.ToString();
            pick.SortOrder = sortOrder;
            pick.Enabled = enabled;

            object Pick = (object)pick;
            if(!rpc.JsonRpcRequest(ref Pick, "picks_update", serverURI, UUID.Random().ToString()))
            {
                remoteClient.SendAgentAlertMessage(
                        "Error updating pick", false);
                return;
            }

            m_log.DebugFormat("[PROFILES]: Finish PickInfoUpdate {0} {1}", pick.Name, pick.PickId.ToString());
        }
Example #13
0
        /// <summary>
        /// Handles the pick info request.
        /// </summary>
        /// <param name='sender'>
        /// Sender.
        /// </param>
        /// <param name='method'>
        /// Method.
        /// </param>
        /// <param name='args'>
        /// Arguments.
        /// </param>
        public void PickInfoRequest(Object sender, string method, List<String> args)
        {
            if (!(sender is IClientAPI))
                return;

            UUID targetID;
            UUID.TryParse (args [0], out targetID);
            string serverURI = string.Empty;
            GetUserProfileServerURI (targetID, out serverURI);

            string theirGatekeeperURI;
            GetUserGatekeeperURI (targetID, out theirGatekeeperURI);

            IClientAPI remoteClient = (IClientAPI)sender;

            UserProfilePick pick = new UserProfilePick ();
            UUID.TryParse (args [0], out pick.CreatorId);
            UUID.TryParse (args [1], out pick.PickId);

                
            object Pick = (object)pick;
            if (!rpc.JsonRpcRequest (ref Pick, "pickinforequest", serverURI, UUID.Random ().ToString ())) {
                remoteClient.SendAgentAlertMessage (
                        "Error selecting pick", false);
                return;
            }
            pick = (UserProfilePick)Pick;
            
            Vector3 globalPos = new Vector3(Vector3.Zero);
            
            // Smoke and mirrors
            if (pick.Gatekeeper == MyGatekeeper) 
            {
                Vector3.TryParse(pick.GlobalPos,out globalPos);
            } 
            else 
            {
                // Setup the illusion
                string region = string.Format("{0} {1}",pick.Gatekeeper,pick.SimName);
                GridRegion target = Scene.GridService.GetRegionByName(Scene.RegionInfo.ScopeID, region);

                if(target == null)
                {
                    // This is a dead or unreachable region
                }
                else
                {
                    // Work our slight of hand
                    int x = target.RegionLocX;
                    int y = target.RegionLocY;

                    dynamic synthX = globalPos.X - (globalPos.X/Constants.RegionSize) * Constants.RegionSize;
                    synthX += x;
                    globalPos.X = synthX;

                    dynamic synthY = globalPos.Y - (globalPos.Y/Constants.RegionSize) * Constants.RegionSize;
                    synthY += y;
                    globalPos.Y = synthY;
                }
            }

            m_log.DebugFormat("[PROFILES]: PickInfoRequest: {0} : {1}", pick.Name.ToString(), pick.SnapshotId.ToString());

            // Pull the rabbit out of the hat
            remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
                                           pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
                                           globalPos,pick.SortOrder,pick.Enabled);
        }
        /// <summary>
        /// Updates the userpicks
        /// </summary>
        /// <param name='remoteClient'>
        /// Remote client.
        /// </param>
        /// <param name='pickID'>
        /// Pick I.
        /// </param>
        /// <param name='creatorID'>
        /// the creator of the pick
        /// </param>
        /// <param name='topPick'>
        /// Top pick.
        /// </param>
        /// <param name='name'>
        /// Name.
        /// </param>
        /// <param name='desc'>
        /// Desc.
        /// </param>
        /// <param name='snapshotID'>
        /// Snapshot I.
        /// </param>
        /// <param name='sortOrder'>
        /// Sort order.
        /// </param>
        /// <param name='enabled'>
        /// Enabled.
        /// </param>
        public void PickInfoUpdate(IClientAPI remoteClient, UUID pickID, UUID creatorID, bool topPick, string name, string desc, UUID snapshotID, int sortOrder, bool enabled)
        {        
            m_log.DebugFormat("[PROFILES]: Start PickInfoUpdate Name: {0} PickId: {1} SnapshotId: {2}", name, pickID.ToString(), snapshotID.ToString());

            UserProfilePick pick = new UserProfilePick();
            string serverURI = string.Empty;
            GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
            if(string.IsNullOrWhiteSpace(serverURI))
            {
                return;
            }

            ScenePresence p = FindPresence(remoteClient.AgentId);

            Vector3 avaPos = p.AbsolutePosition;
            // Getting the global position for the Avatar
            Vector3 posGlobal = new Vector3(remoteClient.Scene.RegionInfo.WorldLocX + avaPos.X,
                                            remoteClient.Scene.RegionInfo.WorldLocY + avaPos.Y,
                                            avaPos.Z);

            string  landParcelName  = "My Parcel";
//            UUID    landParcelID    = p.currentParcelUUID;

            // to locate parcels we use a fake id that encodes the region handle
            // since we do not have a global locator
            // this fails on HG
            UUID  landParcelID = Util.BuildFakeParcelID(remoteClient.Scene.RegionInfo.RegionHandle, (uint)avaPos.X, (uint)avaPos.Y);
            ILandObject land = p.Scene.LandChannel.GetLandObject(avaPos.X, avaPos.Y);

            if (land != null)
            {
                // If land found, use parcel uuid from here because the value from SP will be blank if the avatar hasnt moved
                landParcelName  = land.LandData.Name;
//                landParcelID    = land.LandData.GlobalID;
            }
            else
            {
                m_log.WarnFormat(
                    "[PROFILES]: PickInfoUpdate found no parcel info at {0},{1} in {2}", 
                    avaPos.X, avaPos.Y, p.Scene.Name);
            }

            pick.PickId = pickID;
            pick.CreatorId = creatorID;
            pick.TopPick = topPick;
            pick.Name = name;
            pick.Desc = desc;
            pick.ParcelId = landParcelID;
            pick.SnapshotId = snapshotID;
            pick.ParcelName = landParcelName;
            pick.SimName = remoteClient.Scene.RegionInfo.RegionName;
            pick.Gatekeeper = MyGatekeeper;
            pick.GlobalPos = posGlobal.ToString();
            pick.SortOrder = sortOrder;
            pick.Enabled = enabled;

            object Pick = (object)pick;
            if(!rpc.JsonRpcRequest(ref Pick, "picks_update", serverURI, UUID.Random().ToString()))
            {
                remoteClient.SendAgentAlertMessage(
                        "Error updating pick", false);
                return;
            }

            UserProfileCacheEntry uce = null;
            lock(m_profilesCache)
            {
                if(!m_profilesCache.TryGetValue(remoteClient.AgentId, out uce) || uce == null)
                    uce = new UserProfileCacheEntry();
                if(uce.picks == null)
                    uce.picks = new Dictionary<UUID, UserProfilePick>();
                if(uce.picksList == null)
                    uce.picksList = new Dictionary<UUID, string>();
                uce.picks[pick.PickId] = pick;
                uce.picksList[pick.PickId] = pick.Name;
                m_profilesCache.AddOrUpdate(remoteClient.AgentId, uce, PROFILECACHEEXPIRE);
            }
            remoteClient.SendAvatarPicksReply(remoteClient.AgentId, uce.picksList);
            remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
                                           pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
                                           posGlobal,pick.SortOrder,pick.Enabled);

            m_log.DebugFormat("[PROFILES]: Finish PickInfoUpdate {0} {1}", pick.Name, pick.PickId.ToString());
        }
        /// <summary>
        /// Handles the pick info request.
        /// </summary>
        /// <param name='sender'>
        /// Sender.
        /// </param>
        /// <param name='method'>
        /// Method.
        /// </param>
        /// <param name='args'>
        /// Arguments.
        /// </param>
        public void PickInfoRequest(Object sender, string method, List<String> args)
        {
            if (!(sender is IClientAPI))
                return;

            UserProfilePick pick = new UserProfilePick ();
            UUID targetID;
            if(!UUID.TryParse(args [0], out targetID))
                return;

            pick.CreatorId = targetID;

            if(!UUID.TryParse (args [1], out pick.PickId))
                return;

            IClientAPI remoteClient = (IClientAPI)sender;
            UserProfileCacheEntry uce = null;
            lock(m_profilesCache)
            {
                if(m_profilesCache.TryGetValue(targetID, out uce) && uce != null)
                {
                    if(uce != null && uce.picks != null && uce.picks.ContainsKey(pick.PickId))
                    {
                        pick = uce.picks[pick.PickId];
                        Vector3 gPos = new Vector3(Vector3.Zero);
                        Vector3.TryParse(pick.GlobalPos, out gPos);
                        remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
                                           pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
                                           gPos,pick.SortOrder,pick.Enabled);
                        return;
                    }
                }
            }

            string serverURI = string.Empty;
            bool foreign =  GetUserProfileServerURI (targetID, out serverURI);
            if(string.IsNullOrWhiteSpace(serverURI))
            {
                return;
            }

            string theirGatekeeperURI;
            GetUserGatekeeperURI(targetID, out theirGatekeeperURI);
                
            object Pick = (object)pick;
            if (!rpc.JsonRpcRequest (ref Pick, "pickinforequest", serverURI, UUID.Random ().ToString ())) {
                remoteClient.SendAgentAlertMessage (
                        "Error selecting pick", false);
                return;
            }
            pick = (UserProfilePick)Pick;
            if(foreign)
                cacheForeignImage(targetID, pick.SnapshotId);
            
            Vector3 globalPos = new Vector3(Vector3.Zero);
            Vector3.TryParse(pick.GlobalPos, out globalPos);
            
            if (!string.IsNullOrWhiteSpace(MyGatekeeper) && pick.Gatekeeper != MyGatekeeper) 
            {
                // Setup the illusion
                string region = string.Format("{0} {1}",pick.Gatekeeper,pick.SimName);
                GridRegion target = Scene.GridService.GetRegionByName(Scene.RegionInfo.ScopeID, region);

                if(target == null)
                {
                    // This is a unreachable region
                }
                else
                {
                    // we have a proxy on map 
                    ulong oriHandle;
                    uint oriX;
                    uint oriY;
                    if(Util.ParseFakeParcelID(pick.ParcelId, out oriHandle, out oriX, out oriY))
                    {
                        pick.ParcelId = Util.BuildFakeParcelID(target.RegionHandle, oriX, oriY);
                        globalPos.X = target.RegionLocX + oriX;
                        globalPos.Y = target.RegionLocY + oriY;
                        pick.GlobalPos = globalPos.ToString();
                    }
                    else
                    {
                        // this is a fail on large regions                  
                        uint gtmp = (uint)globalPos.X >> 8;
                        globalPos.X -= (gtmp << 8);

                        gtmp = (uint)globalPos.Y >> 8;
                        globalPos.Y -= (gtmp << 8);

                        pick.ParcelId = Util.BuildFakeParcelID(target.RegionHandle, (uint)globalPos.X, (uint)globalPos.Y);

                        globalPos.X += target.RegionLocX;
                        globalPos.Y += target.RegionLocY;
                        pick.GlobalPos = globalPos.ToString();
                    }
                }
            }

            m_log.DebugFormat("[PROFILES]: PickInfoRequest: {0} : {1}", pick.Name.ToString(), pick.SnapshotId.ToString());

            lock(m_profilesCache)
            {
                if(!m_profilesCache.TryGetValue(targetID, out uce) || uce == null)
                    uce = new UserProfileCacheEntry();
                if(uce.picks == null)
                    uce.picks = new Dictionary<UUID, UserProfilePick>();
                uce.picks[pick.PickId] = pick;

                m_profilesCache.AddOrUpdate(targetID, uce, PROFILECACHEEXPIRE);
            }

            // Pull the rabbit out of the hat
            remoteClient.SendPickInfoReply(pick.PickId,pick.CreatorId,pick.TopPick,pick.ParcelId,pick.Name,
                                           pick.Desc,pick.SnapshotId,pick.ParcelName,pick.OriginalName,pick.SimName,
                                           globalPos,pick.SortOrder,pick.Enabled);
        }