public static RexUserProfileData ConvertXMLRPCDataToUserProfile(Hashtable data)
        {
            try
            {

            if (data.Contains("error_type"))
            {
                m_log.Warn("[AUTHENTICATIONSERVICE]: " +
                           "Error sent by authentication server server when trying to get user profile: (" +
                           data["error_type"] +
                           "): " + data["error_desc"]);
                return null;
            }

                RexUserProfileData userData = new RexUserProfileData();
                userData.FirstName = (string)data["firstname"];
                userData.SurName = (string)data["lastname"];
                userData.ID = new UUID((string)data["uuid"]);
                userData.UserInventoryURI = (string)data["server_inventory"];
                userData.UserAssetURI = (string)data["server_asset"];
                userData.FirstLifeAboutText = (string)data["profile_firstlife_about"];
                userData.FirstLifeImage = new UUID((string)data["profile_firstlife_image"]);
                userData.CanDoMask = Convert.ToUInt32((string)data["profile_can_do"]);
                userData.WantDoMask = Convert.ToUInt32(data["profile_want_do"]);
                userData.AboutText = (string)data["profile_about"];
                userData.Image = new UUID((string)data["profile_image"]);
                userData.LastLogin = Convert.ToInt32((string)data["profile_lastlogin"]);
                userData.HomeRegion = Convert.ToUInt64((string)data["home_region"]);
                if (data.Contains("home_region_id"))
                    userData.HomeRegionID = new UUID((string)data["home_region_id"]);
                else
                    userData.HomeRegionID = UUID.Zero;
                userData.HomeLocation =
                    new Vector3((float)Convert.ToDecimal((string)data["home_coordinates_x"]),
                                  (float)Convert.ToDecimal((string)data["home_coordinates_y"]),
                                  (float)Convert.ToDecimal((string)data["home_coordinates_z"]));
                userData.HomeLookAt =
                    new Vector3((float)Convert.ToDecimal((string)data["home_look_x"]),
                                  (float)Convert.ToDecimal((string)data["home_look_y"]),
                                  (float)Convert.ToDecimal((string)data["home_look_z"]));
                if (data.Contains("user_flags"))
                    userData.UserFlags = Convert.ToInt32((string)data["user_flags"]);
                if (data.Contains("god_level"))
                    userData.GodLevel = Convert.ToInt32((string)data["god_level"]);

                if (data.Contains("custom_type"))
                    userData.CustomType = (string)data["custom_type"];
                else
                    userData.CustomType = "";
                if (userData.CustomType == null)
                    userData.CustomType = "";

                if (data.Contains("partner"))
                    userData.Partner = new UUID((string)data["partner"]);
                else
                    userData.Partner = UUID.Zero;

                if (data.Contains("account"))
                    userData.Account = (string)data["account"];
                else
                    userData.Account = "";

                if (data.Contains("realname"))
                    userData.RealName = (string)data["realname"];
                else
                    userData.RealName = "";

                if (data.Contains("sessionHash"))
                    userData.SessionHash = (string)data["sessionHash"];
                else
                    userData.SessionHash = "";

                if (data.Contains("as_address"))
                    userData.AvatarStorageUrl = (string)data["as_address"];
                else
                    userData.AvatarStorageUrl = "";

                if (data.Contains("skypeUrl"))
                    userData.SkypeUrl = (string)data["skypeUrl"];
                else
                    userData.Account = "";

                if (data.Contains("gridUrl"))
                    userData.GridUrl = (string)data["gridUrl"];
                else
                    userData.GridUrl = "";

                RexUserAgentData agent = new RexUserAgentData();

                if (data.Contains("currentAgent"))
                {
                    Hashtable agentData = (Hashtable)data["currentAgent"];

                    agent.AgentIP = (string)agentData["agentIP"];
                    agent.AgentOnline = Convert.ToBoolean((string)data["agentOnline"]);
                    agent.AgentPort = Convert.ToUInt32((string)data["agentPort"]);
                    agent.Handle = Convert.ToUInt64((string)data["handle"]);
                    agent.InitialRegion = new UUID((string)data["initialRegion"]);
                    agent.LoginTime = Convert.ToInt32((string)data["loginTime"]);
                    agent.LogoutTime = Convert.ToInt32((string)data["logoutTime"]);
                    agent.LookAt = new Vector3((float)Convert.ToDecimal((string)data["home_look_x"]),
                                  (float)Convert.ToDecimal((string)data["home_look_y"]),
                                  (float)Convert.ToDecimal((string)data["home_look_z"]));

                    agent.Position = new Vector3((float)Convert.ToDecimal((string)data["currentPos_x"]),
                                  (float)Convert.ToDecimal((string)data["currentPos_y"]),
                                  (float)Convert.ToDecimal((string)data["currentPos_z"]));

                    agent.ProfileID = new UUID((string)data["UUID"]); ;
                    agent.Region = new UUID((string)data["regionID"]);
                    agent.SecureSessionID = new UUID((string)data["secureSessionID"]);
                    agent.SessionID = new UUID((string)data["sessionID"]);
                    agent.currentRegion = new UUID((string)data["currentRegion"]);

                    userData.CurrentAgent = agent;

                }

                return userData;

            }
            catch (Exception except)
            {
                m_log.Error("[AUTHENTICATION SERVICE]: ConvertXMLRPCDataToUserProfile", except);
            }

            return null;
        }
        /// <summary>
        /// Set up avatar basic data
        /// </summary>
        /// <param name="account"></param>
        /// <param name="authUrl"></param>
        /// <param name="sessionID"></param>
        /// <param name="theUser"></param>
        /// <param name="clientVersion"></param>
        /// <param name="client"></param>
        /// <returns></returns>
        protected OpenSim.Grid.UserServer.Modules.RexLogin.Avatar SetUpAvatar(
            string account, string authUrl, UUID sessionID,
            RexUserProfileData theUser) 
        {
            OpenSim.Grid.UserServer.Modules.RexLogin.ServiceCollection services =
                new OpenSim.Grid.UserServer.Modules.RexLogin.ServiceCollection();

            OpenSim.Grid.UserServer.Modules.RexLogin.Avatar avatar =
                OpenSim.Grid.UserServer.Modules.RexLogin.RexLoginHelper.GetUserByAccount(account, authUrl);

            avatar.Services = services;
            avatar.Attributes[AvatarAttributes.FIRST_NAME] = OSD.FromString(theUser.FirstName);
            avatar.Attributes[AvatarAttributes.LAST_NAME] = OSD.FromString(theUser.SurName);
                
            
            if(theUser.CanDoMask!=null)
                avatar.Attributes[AvatarAttributes.CAN_DO] = OSD.FromUInteger(theUser.CanDoMask);
            if(theUser.Created!=null)
                avatar.Attributes[AvatarAttributes.BIRTH_DATE] = OSD.FromInteger(theUser.Created);
            if(theUser.CustomType!=null)
                avatar.Attributes[AvatarAttributes.CUSTOM_TYPE] = OSD.FromString(theUser.CustomType);
            if(theUser.Email!=null)
                avatar.Attributes[AvatarAttributes.EMAIL] = OSD.FromString(theUser.Email);
            if(theUser.FirstLifeAboutText!=null)
                avatar.Attributes[AvatarAttributes.FIRST_LIFE_BIOGRAPHY] = OSD.FromString(theUser.FirstLifeAboutText);
            if(theUser.FirstLifeImage!=null)
                avatar.Attributes[AvatarAttributes.FIRST_LIFE_IMAGE_ID] = OSD.FromUUID(theUser.FirstLifeImage);
            if(theUser.GodLevel!=null)
                avatar.Attributes[AvatarAttributes.GOD_LEVEL] = OSD.FromInteger(theUser.GodLevel);
            if(theUser.HomeLocation!=null)
                avatar.Attributes[AvatarAttributes.HOME_POSITION] = OSD.FromVector3(theUser.HomeLocation);
            if(theUser.HomeLookAt!=null)
                avatar.Attributes[AvatarAttributes.HOME_LOOKAT] = OSD.FromVector3(theUser.HomeLookAt);
            if(theUser.HomeRegionID!=null)
                avatar.Attributes[AvatarAttributes.HOME_REGION_ID] = OSD.FromUUID(theUser.HomeRegionID);
            if (theUser.HomeRegionX != null)
            {
                avatar.Attributes[AvatarAttributes.HOME_REGION_X] = OSD.FromUInteger(theUser.HomeRegionX);
            }
            if (theUser.HomeRegionY != null)
            {
                avatar.Attributes[AvatarAttributes.HOME_REGION_Y] = OSD.FromUInteger(theUser.HomeRegionY);
            }
            if(theUser.ID!=null)
                avatar.Attributes[AvatarAttributes.AVATAR_ID] = OSD.FromUUID(theUser.ID);
            if(theUser.Image!=null)
                avatar.Attributes[AvatarAttributes.IMAGE_ID] = OSD.FromUUID(theUser.Image);
            if(theUser.LastLogin!=null)
                avatar.Attributes[AvatarAttributes.LAST_LOGIN_DATE] = OSD.FromInteger(theUser.LastLogin);
            if(theUser.Partner!=null)
                avatar.Attributes[AvatarAttributes.PARTNER_ID] = OSD.FromUUID(theUser.Partner);

            RegionProfileData rpd = CableBeachState.LoginService.RegionProfileService.RequestSimProfileData(theUser.CurrentAgent.Handle, m_UserConfig.GridServerURL,
                m_UserConfig.GridSendKey, m_UserConfig.GridRecvKey);
            if (rpd.UUID != UUID.Zero)
            {
                avatar.Attributes[AvatarAttributes.LAST_REGION_X] = OSD.FromUInteger(rpd.RegionLocX);
                avatar.Attributes[AvatarAttributes.LAST_REGION_Y] = OSD.FromUInteger(rpd.RegionLocY);
            }
            else 
            {
                avatar.Attributes[AvatarAttributes.LAST_REGION_X] = OSD.FromUInteger(theUser.HomeRegionX);
                avatar.Attributes[AvatarAttributes.LAST_REGION_Y] = OSD.FromUInteger(theUser.HomeRegionY);
            }

            //*/
            //OSD.FromString(theUser.PasswordHash);
            //OSD.FromString(theUser.PasswordSalt);
            //OSD.FromString(theUser.ProfileUrl);
            //OSD.FromString(theUser.UserAssetURI);
            if(theUser.UserFlags!=null)
                avatar.Attributes[AvatarAttributes.USER_FLAGS] = OSD.FromInteger(theUser.UserFlags);
            //OSD.FromString(theUser.UserInventoryURI);
            if(theUser.WantDoMask!=null)
                avatar.Attributes[AvatarAttributes.WANT_DO] = OSD.FromInteger(theUser.WantDoMask);
            //OSD.FromString(theUser.WebLoginKey);
            
            return avatar;
        }