public override bool AddUserAgent(UserAgentData agentdata)
        {
            if (m_localUserServices != null)
                return m_localUserServices.AddUserAgent(agentdata);

            return base.AddUserAgent(agentdata);
        }        
Esempio n. 2
0
        private OSD EnableClientMessageHandler(string path, OSD request, string endpoint)
        {
            EnableClientMessage message = new EnableClientMessage();
            EnableClientReplyMessage reply = new EnableClientReplyMessage();

            if (request.Type == OSDType.Map)
            {
                message.Deserialize((OSDMap)request);

                WorldServiceConnector wsConnector;
                if (m_regionWorldServiceConnectors.TryGetValue(message.RegionHandle, out wsConnector))
                {
                    Scene scene = wsConnector.Scene;

                    AgentCircuitData agentData = new AgentCircuitData();
                    agentData.AgentID = message.AgentID;
                    agentData.BaseFolder = UUID.Zero; // TODO: What is this?
                    agentData.CapsPath = CapsUtil.GetRandomCapsObjectPath();
                    agentData.child = message.ChildAgent;
                    agentData.circuitcode = (uint)message.CircuitCode;
                    agentData.firstname = GetStringAttribute(message.Attributes, AvatarAttributes.FIRST_NAME);
                    agentData.lastname = GetStringAttribute(message.Attributes, AvatarAttributes.LAST_NAME);
                    agentData.SecureSessionID = message.SecureSessionID;
                    agentData.SessionID = message.SessionID;
                    agentData.startpos = GetVector3Attribute(message.Attributes, AvatarAttributes.LAST_POSITION);

                    UserAgentData useragent = new UserAgentData();
                    useragent.AgentIP = message.IP.ToString();
                    useragent.AgentOnline = true;
                    useragent.AgentPort = 0u;
                    useragent.Handle = scene.RegionInfo.RegionHandle;
                    useragent.InitialRegion = scene.RegionInfo.RegionID;
                    useragent.LoginTime = Util.UnixTimeSinceEpoch();
                    useragent.LogoutTime = 0;
                    useragent.Position = agentData.startpos;
                    useragent.Region = useragent.InitialRegion;
                    useragent.SecureSessionID = agentData.SecureSessionID;
                    useragent.SessionID = agentData.SessionID;

                    UserProfileData userProfile = new UserProfileData();
                    userProfile.AboutText = GetStringAttribute(message.Attributes, AvatarAttributes.BIOGRAPHY);
                    userProfile.CanDoMask = (uint)GetIntegerAttribute(message.Attributes, AvatarAttributes.CAN_DO);
                    userProfile.Created = (int)Utils.DateTimeToUnixTime(GetDateAttribute(message.Attributes, AvatarAttributes.BIRTH_DATE));
                    userProfile.CurrentAgent = useragent;
                    userProfile.CustomType = "CableBeach";
                    userProfile.FirstLifeAboutText = GetStringAttribute(message.Attributes, AvatarAttributes.FIRST_LIFE_BIOGRAPHY);
                    userProfile.FirstLifeImage = GetUUIDAttribute(message.Attributes, AvatarAttributes.FIRST_LIFE_IMAGE_ID);
                    userProfile.FirstName = agentData.firstname;
                    userProfile.GodLevel = GetIntegerAttribute(message.Attributes, AvatarAttributes.GOD_LEVEL);
                    userProfile.HomeLocation = GetVector3Attribute(message.Attributes, AvatarAttributes.HOME_POSITION);
                    userProfile.HomeLocationX = userProfile.HomeLocation.X;
                    userProfile.HomeLocationY = userProfile.HomeLocation.Y;
                    userProfile.HomeLocationZ = userProfile.HomeLocation.Z;
                    userProfile.HomeLookAt = GetVector3Attribute(message.Attributes, AvatarAttributes.HOME_LOOKAT);
                    userProfile.HomeLookAtX = userProfile.HomeLookAt.X;
                    userProfile.HomeLookAtY = userProfile.HomeLookAt.Y;
                    userProfile.HomeLookAtZ = userProfile.HomeLookAt.Z;
                    userProfile.HomeRegionID = GetUUIDAttribute(message.Attributes, AvatarAttributes.HOME_REGION_ID);
                    userProfile.HomeRegionX = (uint)GetIntegerAttribute(message.Attributes, AvatarAttributes.HOME_REGION_X);
                    userProfile.HomeRegionY = (uint)GetIntegerAttribute(message.Attributes, AvatarAttributes.HOME_REGION_Y);
                    userProfile.HomeRegion = Utils.UIntsToLong(userProfile.HomeRegionX, userProfile.HomeRegionY);
                    userProfile.ID = agentData.AgentID;
                    userProfile.Image = UUID.Zero;
                    userProfile.LastLogin = useragent.LoginTime;
                    userProfile.Partner = GetUUIDAttribute(message.Attributes, AvatarAttributes.PARTNER_ID);
                    userProfile.PasswordHash = "$1$";
                    userProfile.PasswordSalt = String.Empty;

                    userProfile.SurName = agentData.lastname;
                    userProfile.UserFlags = GetIntegerAttribute(message.Attributes, AvatarAttributes.USER_FLAGS);
                    userProfile.WantDoMask = (uint)GetIntegerAttribute(message.Attributes, AvatarAttributes.WANT_DO);
                    userProfile.WebLoginKey = UUID.Zero;
                    // Cable Beach does not tie all endpoints for a service under a single URL, so these won't do
                    userProfile.UserAssetURI = String.Empty;
                    userProfile.UserInventoryURI = String.Empty;

                    // Stick our user data in the cache so the region will know something about us
                    scene.CommsManager.UserProfileCacheService.PreloadUserCache(userProfile);

                    // Add this incoming EnableClient message to the database of active sessions
                    wsConnector.EnableClientMessages.Add(message.Identity, message.AgentID, message);

                    // Call 'new user' event handler
                    string reason;
                    if (wsConnector.NewUserConnection(agentData, out reason))
                    {
                        string capsSeedPath = CapsUtil.GetCapsSeedPath(
                            scene.CapsModule.GetCapsHandlerForUser(agentData.AgentID).CapsObjectPath);

                        // Set the response message to successful
                        reply.Success = true;
                        reply.SeedCapability = wsConnector.GetServiceEndpoint(capsSeedPath);

                        m_Log.Info("[CABLE BEACH MOD]: enable_client succeeded for " + userProfile.Name);
                    }
                    else
                    {
                        reply.Message = "Connection refused: " + reason;
                        m_Log.Error("[CABLE BEACH MOD]: enable_client failed: " + reason);
                    }
                }
                else
                {
                    m_Log.Error("[CABLE BEACH MOD]: enable_client received an unrecognized region handle " + message.RegionHandle);
                }
            }

            return reply.Serialize();
        }
Esempio n. 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="row"></param>
 /// <param name="ua"></param>
 private static void fillUserAgentRow(DataRow row, UserAgentData ua)
 {
     row["UUID"] = ua.ProfileID.ToString();
     row["agentIP"] = ua.AgentIP;
     row["agentPort"] = ua.AgentPort;
     row["agentOnline"] = ua.AgentOnline;
     row["sessionID"] = ua.SessionID.ToString();
     row["secureSessionID"] = ua.SecureSessionID.ToString();
     row["regionID"] = ua.InitialRegion.ToString();
     row["loginTime"] = ua.LoginTime;
     row["logoutTime"] = ua.LogoutTime;
     row["currentRegion"] = ua.Region.ToString();
     row["currentHandle"] = ua.Handle.ToString();
     // vectors
     row["currentPosX"] = ua.Position.X;
     row["currentPosY"] = ua.Position.Y;
     row["currentPosZ"] = ua.Position.Z;
     row["currentLookAtX"] = ua.LookAt.X;
     row["currentLookAtY"] = ua.LookAt.Y;
     row["currentLookAtZ"] = ua.LookAt.Z;
 }
Esempio n. 4
0
 public void AddNewUserAgent(UserAgentData agent)
 {
     m_agentByProfileUuid[agent.ProfileID] = agent;
 }
Esempio n. 5
0
        /// <summary>
        /// Insert/Update a agent row in the DB.
        /// </summary>
        /// <param name="agentdata">agentdata.</param>
        private void InsertUpdateAgentRow(UserAgentData agentdata)
        {
            string sql = @"

IF EXISTS (SELECT * FROM agents WHERE UUID = @UUID)
    BEGIN
        UPDATE agents SET UUID = @UUID, sessionID = @sessionID, secureSessionID = @secureSessionID, agentIP = @agentIP, agentPort = @agentPort, agentOnline = @agentOnline, loginTime = @loginTime, logoutTime = @logoutTime, currentRegion = @currentRegion, currentHandle = @currentHandle, currentPos = @currentPos
        WHERE UUID = @UUID
    END
ELSE
    BEGIN
        INSERT INTO 
            agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos) VALUES 
            (@UUID, @sessionID, @secureSessionID, @agentIP, @agentPort, @agentOnline, @loginTime, @logoutTime, @currentRegion, @currentHandle, @currentPos)
    END
";

            using (AutoClosingSqlCommand command = database.Query(sql))
            {
                command.Parameters.Add(database.CreateParameter("@UUID", agentdata.ProfileID));
                command.Parameters.Add(database.CreateParameter("@sessionID", agentdata.SessionID));
                command.Parameters.Add(database.CreateParameter("@secureSessionID", agentdata.SecureSessionID));
                command.Parameters.Add(database.CreateParameter("@agentIP", agentdata.AgentIP));
                command.Parameters.Add(database.CreateParameter("@agentPort", agentdata.AgentPort));
                command.Parameters.Add(database.CreateParameter("@agentOnline", agentdata.AgentOnline));
                command.Parameters.Add(database.CreateParameter("@loginTime", agentdata.LoginTime));
                command.Parameters.Add(database.CreateParameter("@logoutTime", agentdata.LogoutTime));
                command.Parameters.Add(database.CreateParameter("@currentRegion", agentdata.Region));
                command.Parameters.Add(database.CreateParameter("@currentHandle", agentdata.Handle));
                command.Parameters.Add(database.CreateParameter("@currentPos", "<" + ((int)agentdata.Position.X) + "," + ((int)agentdata.Position.Y) + "," + ((int)agentdata.Position.Z) + ">"));

                command.Transaction = command.Connection.BeginTransaction(IsolationLevel.Serializable);
                try
                {
                    if (command.ExecuteNonQuery() > 0)
                    {
                        command.Transaction.Commit();
                        return;
                    }

                    command.Transaction.Rollback();
                    return;
                }
                catch (Exception e)
                {
                    command.Transaction.Rollback();
                    m_log.Error(e.ToString());
                    return;
                }
            }

        }
Esempio n. 6
0
        override public void AddNewUserAgent(UserAgentData agent)
        {
            if (agent.ProfileID == UUID.Zero)
            {
                m_log.ErrorFormat("[NHIBERNATE] Attempted to add new user agent with zero user id. Agent session id: {0}", agent.SessionID);
                return;
            }

            if (agent.SessionID == UUID.Zero)
            {
                m_log.ErrorFormat("[NHIBERNATE] Attempted to add new user agent with zero session id. User profile id: {0}", agent.SessionID);
                return;
            }


            UserAgentData old = (UserAgentData)manager.Get(typeof(UserAgentData), agent.ProfileID);
            if (old != null)
            {
                manager.Delete(old);
            }
            
            manager.Insert(agent);
            
        }
Esempio n. 7
0
        private void UpdateLoginHistory(UserAgentData agent)
        {
            if (agent.AgentOnline)
            {
                const string UPDATE_HISTORY =
                    @"REPLACE INTO LoginHistory(session_id, user_id, login_time, session_ip, last_region) 
                    VALUES(?sessionId, ?userId, ?loginTime, ?sessionIp, ?lastRegion)";

                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters["?sessionId"] = agent.SessionID;
                parameters["?userId"] = agent.ProfileID;
                parameters["?loginTime"] = Util.UnixToLocalDateTime(agent.LoginTime);
                parameters["?sessionIp"] = agent.AgentIP;
                parameters["?lastRegion"] = agent.Region;

                try
                {
                    using (ISimpleDB conn = _connFactory.GetConnection())
                    {
                        conn.QueryNoResults(UPDATE_HISTORY, parameters);
                    }
                }
                catch (Exception e)
                {
                    m_log.Error("[MySQLUserData.InWorldz] UpdateLoginHistory: " + e.ToString());
                }
            }
            else
            {
                const string RECORD_LOGOUT =
                    @"UPDATE LoginHistory SET last_region = ?lastRegion, logout_time = ?logoutTime
                    WHERE session_id = ?sessionId";

                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters["?lastRegion"] = agent.Region;
                parameters["?logoutTime"] = DateTime.Now;
                parameters["?sessionId"] = agent.SessionID;

                try
                {
                    using (ISimpleDB conn = _connFactory.GetConnection())
                    {
                        conn.QueryNoResults(RECORD_LOGOUT, parameters);
                    }
                }
                catch (Exception e)
                {
                    m_log.Error("[MySQLUserData.InWorldz] UpdateLoginHistory: " + e.ToString());
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// This implementation only authenticates users.
        /// </summary>
        /// <param name="principalID"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public UUID AuthenticatePassword(UUID principalID, string password)
        {
            bool writeAgentData = false;

            UserAgentData agent = m_Database.GetAgentByUUID(principalID);
            if (agent == null)
            {
                agent = new UserAgentData();
                agent.ProfileID = principalID;
                agent.SessionID = UUID.Random();
                agent.SecureSessionID = UUID.Random();
                agent.AgentIP = "127.0.0.1";
                agent.AgentPort = 0;
                agent.AgentOnline = false;

                writeAgentData = true;
            }

            if (!m_PerformAuthentication)
            {
                if (writeAgentData)
                    m_Database.AddNewUserAgent(agent);
                return agent.SessionID;
            }

            UserProfileData profile = m_Database.GetUserByUUID(principalID);
            bool passwordSuccess = false;
            m_log.InfoFormat("[AUTH]: Authenticating {0} {1} ({2})", profile.FirstName, profile.SurName, profile.ID);

            // we do this to get our hash in a form that the server password code can consume
            // when the web-login-form submits the password in the clear (supposed to be over SSL!)
            if (!password.StartsWith("$1$"))
                password = "******" + Util.Md5Hash(password);

            password = password.Remove(0, 3); //remove $1$

            string s = Util.Md5Hash(password + ":" + profile.PasswordSalt);
            // Testing...
            //m_log.Info("[LOGIN]: SubHash:" + s + " userprofile:" + profile.passwordHash);
            //m_log.Info("[LOGIN]: userprofile:" + profile.passwordHash + " SubCT:" + password);

            passwordSuccess = (profile.PasswordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase)
                               || profile.PasswordHash.Equals(password, StringComparison.InvariantCulture));

            if (!passwordSuccess)
                return UUID.Zero;

            if (writeAgentData)
                m_Database.AddNewUserAgent(agent);

            return agent.SessionID;
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a new agent and inserts it into the database
        /// </summary>
        /// <param name="agentdata">The agent data to be inserted</param>
        /// <returns>Success?</returns>
        public bool insertAgentRow(UserAgentData agentdata)
        {
            string sql = String.Empty;
            sql += "REPLACE INTO ";
            sql += "agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos, currentLookAt) VALUES ";
            sql += "(?UUID, ?sessionID, ?secureSessionID, ?agentIP, ?agentPort, ?agentOnline, ?loginTime, ?logoutTime, ?currentRegion, ?currentHandle, ?currentPos, ?currentLookAt);";
            Dictionary<string, object> parameters = new Dictionary<string, object>();

            parameters["?UUID"] = agentdata.ProfileID.ToString();
            parameters["?sessionID"] = agentdata.SessionID.ToString();
            parameters["?secureSessionID"] = agentdata.SecureSessionID.ToString();
            parameters["?agentIP"] = agentdata.AgentIP.ToString();
            parameters["?agentPort"] = agentdata.AgentPort.ToString();
            parameters["?agentOnline"] = (agentdata.AgentOnline == true) ? "1" : "0";
            parameters["?loginTime"] = agentdata.LoginTime.ToString();
            parameters["?logoutTime"] = agentdata.LogoutTime.ToString();
            parameters["?currentRegion"] = agentdata.Region.ToString();
            parameters["?currentHandle"] = agentdata.Handle.ToString();
            parameters["?currentPos"] = "<" + (agentdata.Position.X).ToString().Replace(",", ".") + "," + (agentdata.Position.Y).ToString().Replace(",", ".") + "," + (agentdata.Position.Z).ToString().Replace(",", ".") + ">";
            parameters["?currentLookAt"] = "<" + (agentdata.LookAt.X).ToString().Replace(",", ".") + "," + (agentdata.LookAt.Y).ToString().Replace(",", ".") + "," + (agentdata.LookAt.Z).ToString().Replace(",", ".") + ">";

            bool returnval = false;

            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    conn.QueryNoResults(sql, parameters);
                    returnval = true;
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
                return false;
            }

            return returnval;
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new agent
        /// </summary>
        /// <param name="agent">The agent to create</param>
        public override void AddNewUserAgent(UserAgentData agent)
        {
            UUID zero = UUID.Zero;
            if (agent.ProfileID == zero || agent.SessionID == zero)
                return;

            try
            {
                this.insertAgentRow(agent);
                this.UpdateLoginHistory(agent);
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Creates a new agent
        /// </summary>
        /// <param name="agent">The agent to create</param>
        public override void AddNewUserAgent(UserAgentData agent)
        {
            UUID zero = UUID.Zero;
            if (agent.ProfileID == zero || agent.SessionID == zero)
                return;

            MySQLSuperManager dbm = GetLockedConnection("AddNewUserAgent");
            try
            {
                dbm.Manager.insertAgentRow(agent);
            }
            catch (Exception e)
            {
                dbm.Manager.Reconnect();
                m_log.Error(e.Message, e);
            }
            finally
            {
                dbm.Release();
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Creates a new agent
        /// </summary>
        /// <param name="agent">The agent to create</param>
        public override void AddNewUserAgent(UserAgentData agent)
        {
            UUID zero = UUID.Zero;
            if (agent.ProfileID == zero || agent.SessionID == zero)
                return;

            try
            {
                m_database.insertAgentRow(agent);
            }
            catch (Exception e)
            {
                m_log.Error(e.Message, e);
            }
        }
        /// <summary>
        /// Recursive SendGridInstantMessage over XMLRPC method.
        /// This is called from within a dedicated thread.
        /// The first time this is called, prevRegionHandle will be 0 Subsequent times this is called from 
        /// itself, prevRegionHandle will be the last region handle that we tried to send.
        /// If the handles are the same, we look up the user's location using the grid.
        /// If the handles are still the same, we end.  The send failed.
        /// </summary>
        /// <param name="prevRegionHandle">
        /// Pass in 0 the first time this method is called.  It will be called recursively with the last 
        /// regionhandle tried
        /// </param>
        protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, ulong prevRegionHandle)
        {
            UUID toAgentID = new UUID(im.toAgentID);

            UserAgentData  upd = null;

            bool lookupAgent = false;

            lock (m_UserRegionMap)
            {
                if (m_UserRegionMap.ContainsKey(toAgentID))
                {
                    upd = new UserAgentData();
                    upd.AgentOnline = true;
                    upd.Handle = m_UserRegionMap[toAgentID];

                    // We need to compare the current regionhandle with the previous region handle
                    // or the recursive loop will never end because it will never try to lookup the agent again
                    if (prevRegionHandle == upd.Handle)
                    {
                        lookupAgent = true;
                    }
                }
                else
                {
                    lookupAgent = true;
                }
            }
            

            // Are we needing to look-up an agent?
            if (lookupAgent)
            {
                // Non-cached user agent lookup.
                upd = m_Scenes[0].CommsManager.UserService.GetAgentByUUID(toAgentID);

                if (upd != null)
                {
                    // check if we've tried this before..
                    // This is one way to end the recursive loop
                    //
                    if (upd.Handle == prevRegionHandle)
                    {
                        m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
                        HandleUndeliveredMessage(im, result);
                        return;
                    }
                }
                else
                {
                    m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
                    HandleUndeliveredMessage(im, result);
                    return;
                }
            }

            if (upd != null)
            {
                if (upd.AgentOnline)
                {
                    RegionInfo reginfo = m_Scenes[0].SceneGridService.RequestNeighbouringRegionInfo(upd.Handle);
                    if (reginfo != null)
                    {
                        Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im);
                        // Not actually used anymore, left in for compatibility
                        // Remove at next interface change
                        //
                        msgdata["region_handle"] = 0;
                        bool imresult = doIMSending(reginfo, msgdata);
                        if (imresult)
                        {
                            // IM delivery successful, so store the Agent's location in our local cache.
                            lock (m_UserRegionMap)
                            {
                                if (m_UserRegionMap.ContainsKey(toAgentID))
                                {
                                    m_UserRegionMap[toAgentID] = upd.Handle;
                                }
                                else
                                {
                                    m_UserRegionMap.Add(toAgentID, upd.Handle);
                                }
                            }
                            result(true);
                        }
                        else
                        {
                            // try again, but lookup user this time.
                            // Warning, this must call the Async version
                            // of this method or we'll be making thousands of threads
                            // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
                            // The version that spawns the thread is SendGridInstantMessageViaXMLRPC

                            // This is recursive!!!!!
                            SendGridInstantMessageViaXMLRPCAsync(im, result,
                                    upd.Handle);
                        }
                    }
                    else
                    {
                        m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.Handle);
                        HandleUndeliveredMessage(im, result);
                    }
                }
                else
                {
                    HandleUndeliveredMessage(im, result);
                }
            }
            else
            {
                m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find user {0}", toAgentID);
                HandleUndeliveredMessage(im, result);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Reads an agent row from a database reader
        /// </summary>
        /// <param name="reader">An active database reader</param>
        /// <returns>A user session agent</returns>
        public UserAgentData readAgentRow(IDataReader reader)
        {
            UserAgentData retval = new UserAgentData();

            if (reader.Read())
            {
                // Agent IDs
                UUID tmp;
                if (!UUID.TryParse(Convert.ToString(reader["UUID"]), out tmp))
                    return null;
                retval.ProfileID = tmp;

                UUID.TryParse(Convert.ToString(reader["sessionID"]), out tmp);
                retval.SessionID = tmp;

                UUID.TryParse(Convert.ToString(reader["secureSessionID"]), out tmp);
                retval.SecureSessionID = tmp;

                // Agent Who?
                retval.AgentIP = (string)reader["agentIP"];
                retval.AgentPort = Convert.ToUInt32(reader["agentPort"].ToString());
                retval.AgentOnline = Convert.ToBoolean(Convert.ToInt16(reader["agentOnline"].ToString()));

                // Login/Logout times (UNIX Epoch)
                retval.LoginTime = Convert.ToInt32(reader["loginTime"].ToString());
                retval.LogoutTime = Convert.ToInt32(reader["logoutTime"].ToString());

                // Current position
                retval.Region = new UUID(Convert.ToString(reader["currentRegion"]));
                retval.Handle = Convert.ToUInt64(reader["currentHandle"].ToString());
                Vector3 tmp_v;
                Vector3.TryParse((string)reader["currentPos"], out tmp_v);
                retval.Position = tmp_v;
                Vector3.TryParse((string)reader["currentLookAt"], out tmp_v);
                retval.LookAt = tmp_v;
            }
            else
            {
                return null;
            }
            return retval;
        }
Esempio n. 15
0
        private void AttachUserAgentToUserProfile(Session session, UUID sessionId, UUID sceneId, UserProfileData userProfile)
        {
            //Scene scene = m_scenes[sceneId];
            CommunicationsManager commsManager = m_scenes[sceneId].CommsManager;
            IUserService userService = (IUserService)commsManager.UserService;

            UserAgentData agent = new UserAgentData();

            // User connection
            agent.AgentOnline = true;
            agent.AgentIP = session.RemoteEndPoint.Address.ToString();
            agent.AgentPort = (uint)session.RemoteEndPoint.Port;

            agent.SecureSessionID = UUID.Random();
            agent.SessionID = sessionId;

            // Profile UUID
            agent.ProfileID = userProfile.ID;

            // Current location/position/alignment
            if (userProfile.CurrentAgent != null)
            {
                agent.Region = userProfile.CurrentAgent.Region;
                agent.Handle = userProfile.CurrentAgent.Handle;
                agent.Position = userProfile.CurrentAgent.Position;
                agent.LookAt = userProfile.CurrentAgent.LookAt;
            }
            else
            {
                agent.Region = userProfile.HomeRegionID;
                agent.Handle = userProfile.HomeRegion;
                agent.Position = userProfile.HomeLocation;
                agent.LookAt = userProfile.HomeLookAt;
            }

            // What time did the user login?
            agent.LoginTime = Util.UnixTimeSinceEpoch();
            agent.LogoutTime = 0;

            userProfile.CurrentAgent = agent;


            userService.UpdateUserProfile(userProfile);
            //userService.CommitAgent(ref userProfile);
        }
Esempio n. 16
0
        public UUID AuthenticateKey(UUID principalID, string key)
        {
            bool writeAgentData = false;

            UserAgentData agent = m_Database.GetAgentByUUID(principalID);
            if (agent == null)
            {
                agent = new UserAgentData();
                agent.ProfileID = principalID;
                agent.SessionID = UUID.Random();
                agent.SecureSessionID = UUID.Random();
                agent.AgentIP = "127.0.0.1";
                agent.AgentPort = 0;
                agent.AgentOnline = false;

                writeAgentData = true;
            }

            if (!m_PerformAuthentication)
            {
                if (writeAgentData)
                    m_Database.AddNewUserAgent(agent);
                return agent.SessionID;
            }

            if (!VerifyKey(principalID, key))
                return UUID.Zero;

            if (writeAgentData)
                m_Database.AddNewUserAgent(agent);

            return agent.SessionID;
        }
Esempio n. 17
0
        public OSD RequestRezAvatarMethod(string path, OSD request)
        {
            //m_log.Debug("[REQUESTREZAVATAR]: " + request.ToString());

            OSDMap requestMap = (OSDMap)request;


            Scene homeScene = null;

            lock (m_loginToRegionState)
            {
                if (m_loginToRegionState.ContainsKey(path))
                {
                    homeScene = GetScene(m_loginToRegionState[path]);
                    m_loginToRegionState.Remove(path);

                    if (homeScene == null)
                        homeScene = GetRootScene();
                }
                else
                {
                    homeScene = GetRootScene();
                }
            }

            // Homescene is still null, we must have no regions that are up
            if (homeScene == null)
                return GenerateNoHandlerMessage();

            RegionInfo reg = homeScene.RegionInfo;
            ulong regionhandle = GetOSCompatibleRegionHandle(reg);
            //string RegionURI = reg.ServerURI;
            //int RegionPort = (int)reg.HttpPort;

            UUID RemoteAgentID = requestMap["agent_id"].AsUUID();
            
            // will be used in the future.  The client always connects with the aditi agentid currently
            UUID LocalAgentID = RemoteAgentID;

            string FirstName = requestMap["first_name"].AsString();
            string LastName = requestMap["last_name"].AsString();

            FirstName = FirstNamePrefix + FirstName;
            LastName = LastName + LastNameSuffix;

            OGPState userState = GetOGPState(LocalAgentID);

            userState.first_name = requestMap["first_name"].AsString();
            userState.last_name = requestMap["last_name"].AsString();
            userState.age_verified = requestMap["age_verified"].AsBoolean();
            userState.transacted = requestMap["transacted"].AsBoolean();
            userState.agent_access = requestMap["agent_access"].AsBoolean();
            userState.allow_redirect = requestMap["allow_redirect"].AsBoolean();
            userState.identified = requestMap["identified"].AsBoolean();
            userState.god_level = (uint)requestMap["god_level"].AsInteger();
            userState.sim_access = requestMap["sim_access"].AsString();
            userState.agent_id = RemoteAgentID;
            userState.limited_to_estate = requestMap["limited_to_estate"].AsInteger();
            userState.src_can_see_mainland = requestMap["src_can_see_mainland"].AsBoolean();
            userState.src_estate_id = requestMap["src_estate_id"].AsInteger();
            userState.local_agent_id = LocalAgentID;
            userState.teleported_into_region = reg.RegionName.ToLower();

            UpdateOGPState(LocalAgentID, userState);

            OSDMap responseMap = new OSDMap();

            if (RemoteAgentID == UUID.Zero)
            {
                responseMap["connect"] = OSD.FromBoolean(false);
                responseMap["message"] = OSD.FromString("No agent ID was specified in rez_avatar/request");
                m_log.Error("[OGP]: rez_avatar/request failed because no avatar UUID was provided in the request body");
                return responseMap;
            }

            responseMap["sim_host"] = OSD.FromString(reg.ExternalHostName);
            
            // DEPRECATED
            responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(reg.ExternalHostName).ToString());
            
            responseMap["connect"] = OSD.FromBoolean(true);
            responseMap["sim_port"] = OSD.FromInteger(reg.InternalEndPoint.Port);
            responseMap["region_x"] = OSD.FromInteger(reg.RegionLocX * (uint)Constants.RegionSize); // LLX
            responseMap["region_y"] = OSD.FromInteger(reg.RegionLocY * (uint)Constants.RegionSize); // LLY
            responseMap["region_id"] = OSD.FromUUID(reg.originRegionID);

            if (reg.RegionSettings.Maturity == 1)
            {
                responseMap["sim_access"] = OSD.FromString("Mature");
            }
            else if (reg.RegionSettings.Maturity == 2)
            {
                responseMap["sim_access"] = OSD.FromString("Adult");
            }
            else
            {
                responseMap["sim_access"] = OSD.FromString("PG");
            }

            // Generate a dummy agent for the user so we can get back a CAPS path
            AgentCircuitData agentData = new AgentCircuitData();
            agentData.AgentID = LocalAgentID;
            agentData.BaseFolder = UUID.Zero;
            agentData.CapsPath = CapsUtil.GetRandomCapsObjectPath();
            agentData.child = false;
            agentData.circuitcode = (uint)(Util.RandomClass.Next());
            agentData.firstname = FirstName;
            agentData.lastname = LastName;
            agentData.SecureSessionID = UUID.Random();
            agentData.SessionID = UUID.Random();
            agentData.startpos = new Vector3(128f, 128f, 100f);

            // Pre-Fill our region cache with information on the agent.
            UserAgentData useragent = new UserAgentData();
            useragent.AgentIP = "unknown";
            useragent.AgentOnline = true;
            useragent.AgentPort = (uint)0;
            useragent.Handle = regionhandle;
            useragent.InitialRegion = reg.originRegionID;
            useragent.LoginTime = Util.UnixTimeSinceEpoch();
            useragent.LogoutTime = 0;
            useragent.Position = agentData.startpos;
            useragent.Region = reg.originRegionID;
            useragent.SecureSessionID = agentData.SecureSessionID;
            useragent.SessionID = agentData.SessionID;

            UserProfileData userProfile = new UserProfileData();
            userProfile.AboutText = "OGP User";
            userProfile.CanDoMask = (uint)0;
            userProfile.Created = Util.UnixTimeSinceEpoch();
            userProfile.CurrentAgent = useragent;
            userProfile.CustomType = "OGP";
            userProfile.FirstLifeAboutText = "I'm testing OpenGrid Protocol";
            userProfile.FirstLifeImage = UUID.Zero;
            userProfile.FirstName = agentData.firstname;
            userProfile.GodLevel = 0;
            userProfile.HomeLocation = agentData.startpos;
            userProfile.HomeLocationX = agentData.startpos.X;
            userProfile.HomeLocationY = agentData.startpos.Y;
            userProfile.HomeLocationZ = agentData.startpos.Z;
            userProfile.HomeLookAt = Vector3.Zero;
            userProfile.HomeLookAtX = userProfile.HomeLookAt.X;
            userProfile.HomeLookAtY = userProfile.HomeLookAt.Y;
            userProfile.HomeLookAtZ = userProfile.HomeLookAt.Z;
            userProfile.HomeRegion = reg.RegionHandle;
            userProfile.HomeRegionID = reg.originRegionID;
            userProfile.HomeRegionX = reg.RegionLocX;
            userProfile.HomeRegionY = reg.RegionLocY;
            userProfile.ID = agentData.AgentID;
            userProfile.Image = UUID.Zero;
            userProfile.LastLogin = Util.UnixTimeSinceEpoch();
            userProfile.Partner = UUID.Zero;
            userProfile.PasswordHash = "$1$";
            userProfile.PasswordSalt = "";
            userProfile.SurName = agentData.lastname;
            //userProfile.UserAssetURI = homeScene.CommsManager.NetworkServersInfo.AssetURL;
            userProfile.UserFlags = 0;
            //userProfile.UserInventoryURI = homeScene.CommsManager.NetworkServersInfo.InventoryURL;
            userProfile.WantDoMask = 0;
            userProfile.WebLoginKey = UUID.Random();

            // !!! REFACTORING PROBLEM. This needs to be changed for 0.7
            //
            //// Do caps registration
            //// get seed capagentData.firstname = FirstName;agentData.lastname = LastName;
            //if (homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID) == null && !GridMode)
            //{
            //    homeScene.CommsManager.UserAdminService.AddUser(
            //        agentData.firstname, agentData.lastname, CreateRandomStr(7), "", 
            //        homeScene.RegionInfo.RegionLocX, homeScene.RegionInfo.RegionLocY, agentData.AgentID);
                
            //    UserProfileData userProfile2 = homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID);
            //    if (userProfile2 != null)
            //    {
            //        userProfile = userProfile2;
            //        userProfile.AboutText = "OGP USER";
            //        userProfile.FirstLifeAboutText = "OGP USER";
            //        homeScene.CommsManager.UserService.UpdateUserProfile(userProfile);
            //    }
            //}
            
            //// Stick our data in the cache so the region will know something about us
            //homeScene.CommsManager.UserProfileCacheService.PreloadUserCache(userProfile);

            // Call 'new user' event handler
            string reason;
            if (!homeScene.NewUserConnection(agentData, (uint)TeleportFlags.ViaLogin, out reason))
            {
                responseMap["connect"] = OSD.FromBoolean(false);
                responseMap["message"] = OSD.FromString(String.Format("Connection refused: {0}", reason));
                m_log.ErrorFormat("[OGP]: rez_avatar/request failed: {0}", reason);
                return responseMap;
            }


            //string raCap = string.Empty;

            UUID AvatarRezCapUUID = LocalAgentID;
            string rezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/rez";
            string derezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/derez";
            // Get a reference to the user's cap so we can pull out the Caps Object Path
            Caps userCap 
                = homeScene.CapsModule.GetCapsHandlerForUser(agentData.AgentID);

            string rezHttpProtocol = "http://";
            string regionCapsHttpProtocol = "http://";
            string httpaddr = reg.ExternalHostName;
            string urlport = reg.HttpPort.ToString();

            if (httpSSL)
            {
                rezHttpProtocol = "https://";
                regionCapsHttpProtocol = "https://";
                urlport = httpsslport.ToString();

                if (httpsCN.Length > 0)
                    httpaddr = httpsCN;
            }
            
            // DEPRECATED
            responseMap["seed_capability"] 
                = OSD.FromString(
                    regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + CapsUtil.GetCapsSeedPath(userCap.CapsObjectPath));
            
            // REPLACEMENT
            responseMap["region_seed_capability"] 
                = OSD.FromString(
                    regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + CapsUtil.GetCapsSeedPath(userCap.CapsObjectPath));

            responseMap["rez_avatar"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
            responseMap["rez_avatar/rez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
            responseMap["rez_avatar/derez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + derezAvatarPath);

            // Add the user to the list of CAPS that are outstanding.
            // well allow the caps hosts in this dictionary
            lock (CapsLoginID)
            {
                if (CapsLoginID.ContainsKey(rezAvatarPath))
                {
                    CapsLoginID[rezAvatarPath] = agentData;
                    
                    // This is a joke, if you didn't notice...  It's so unlikely to happen, that I'll print this message if it does occur!
                    m_log.Error("[OGP]: Holy anomoly batman! Caps path already existed!  All the UUID Duplication worries were founded!");
                }
                else
                {
                    CapsLoginID.Add(rezAvatarPath, agentData);
                }
            }
            
            //m_log.Debug("Response:" + responseMap.ToString());
            return responseMap;
        }
Esempio n. 18
0
 //public abstract bool UpdateUserInterests(UserInterestsData user);
 public abstract void AddNewUserAgent(UserAgentData agent);
Esempio n. 19
0
        public void T023_AgentPersistency()
        {
            UUID user = user4;
            UUID agent = agent4;
            UUID secureagent = UUID.Random();
            string agentip = RandomName();
            uint agentport = (uint)random.Next();
            bool agentonline = (random.NextDouble() > 0.5);
            int logintime = random.Next();
            int logouttime = random.Next();
            UUID regionid = UUID.Random();
            ulong regionhandle = (ulong) random.Next();
            Vector3 currentpos = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
            Vector3 currentlookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
            UUID orgregionid = UUID.Random();
            
            UserAgentData a = new UserAgentData();
            a.ProfileID = user;
            a.SessionID = agent;
            a.SecureSessionID = secureagent;
            a.AgentIP = agentip;
            a.AgentPort = agentport;
            a.AgentOnline = agentonline;
            a.LoginTime = logintime;
            a.LogoutTime = logouttime;
            a.Region = regionid;
            a.Handle = regionhandle;
            a.Position = currentpos;
            a.LookAt = currentlookat;
            a.InitialRegion = orgregionid;

            db.AddNewUserAgent(a);

            UserAgentData a1 = db.GetAgentByUUID(user4);
            Assert.That(user,Is.EqualTo(a1.ProfileID), "Assert.That(user,Is.EqualTo(a1.ProfileID))");
            Assert.That(agent,Is.EqualTo(a1.SessionID), "Assert.That(agent,Is.EqualTo(a1.SessionID))");
            Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID), "Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID))");
            Assert.That(agentip,Is.EqualTo(a1.AgentIP), "Assert.That(agentip,Is.EqualTo(a1.AgentIP))");
            Assert.That(agentport,Is.EqualTo(a1.AgentPort), "Assert.That(agentport,Is.EqualTo(a1.AgentPort))");
            Assert.That(agentonline,Is.EqualTo(a1.AgentOnline), "Assert.That(agentonline,Is.EqualTo(a1.AgentOnline))");
            Assert.That(logintime,Is.EqualTo(a1.LoginTime), "Assert.That(logintime,Is.EqualTo(a1.LoginTime))");
            Assert.That(logouttime,Is.EqualTo(a1.LogoutTime), "Assert.That(logouttime,Is.EqualTo(a1.LogoutTime))");
            Assert.That(regionid,Is.EqualTo(a1.Region), "Assert.That(regionid,Is.EqualTo(a1.Region))");
            Assert.That(regionhandle,Is.EqualTo(a1.Handle), "Assert.That(regionhandle,Is.EqualTo(a1.Handle))");
            Assert.That(currentpos,Is.EqualTo(a1.Position), "Assert.That(currentpos,Is.EqualTo(a1.Position))");
            Assert.That(currentlookat,Is.EqualTo(a1.LookAt), "Assert.That(currentlookat,Is.EqualTo(a1.LookAt))");
        }
Esempio n. 20
0
 public void UpdateUserAgent(UserAgentData agent)
 {
     m_log.InfoFormat("[NHIBERNATE] UpdateUserAgent: {0} ", agent.ProfileID);
     manager.Update(agent);
 }
Esempio n. 21
0
 public UserAgentData NewAgent(UUID user_profile, UUID agent)
 {
     UserAgentData a = new UserAgentData();
     a.ProfileID = user_profile;
     a.SessionID = agent;
     a.SecureSessionID = UUID.Random();
     a.AgentIP = RandomName();
     return a;
 }
Esempio n. 22
0
 /// <summary>
 /// Creates a new agent
 /// </summary>
 /// <param name="agent">The agent to create</param>
 override public void AddNewUserAgent(UserAgentData agent)
 {
     try
     {
         InsertUpdateAgentRow(agent);
     }
     catch (Exception e)
     {
         m_log.ErrorFormat("[USER DB] Error adding new agentdata, error: {0}", e.Message);
     }
 }
Esempio n. 23
0
//        public Uri GetUserUri(UserProfileData userProfile)
//        {
//            throw new NotImplementedException();
//        }
        
        public virtual UserAgentData GetAgentByUUID(UUID userId)
        {
            try
            {
                Hashtable param = new Hashtable();
                param["avatar_uuid"] = userId.ToString();
                IList parameters = new ArrayList();
                parameters.Add(param);
                XmlRpcRequest req = new XmlRpcRequest("get_agent_by_uuid", parameters);

                XmlRpcResponse resp = req.Send(GetUserServerURL(userId), 6000);
                Hashtable respData = (Hashtable)resp.Value;
                if (respData.Contains("error_type"))
                {
                    //m_log.Warn("[GRID]: " +
                    //           "Error sent by user server when trying to get agent: (" +
                    //           (string) respData["error_type"] +
                    //           "): " + (string)respData["error_desc"]);
                    return null;
                }
                UUID sessionid = UUID.Zero;

                UserAgentData userAgent = new UserAgentData();
                userAgent.Handle = Convert.ToUInt64((string)respData["handle"]);
                UUID.TryParse((string)respData["sessionid"], out sessionid);
                userAgent.SessionID = sessionid;

                if ((string)respData["agent_online"] == "TRUE")
                {
                    userAgent.AgentOnline = true;
                }
                else
                {
                    userAgent.AgentOnline = false;
                }

                return userAgent;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat(
                    "[OGS1 USER SERVICES]: Error when trying to fetch agent data by uuid from remote user server: {0}",
                    e);
            }

            return null;
        }
Esempio n. 24
0
        /// <summary>
        /// Reads an agent row from a database reader
        /// </summary>
        /// <param name="reader">An active database reader</param>
        /// <returns>A user session agent</returns>
        private UserAgentData readAgentRow(SqlDataReader reader)
        {
            UserAgentData retval = new UserAgentData();

            if (reader.Read())
            {
                // Agent IDs
                retval.ProfileID = new UUID((Guid)reader["UUID"]);
                retval.SessionID = new UUID((Guid)reader["sessionID"]);
                retval.SecureSessionID = new UUID((Guid)reader["secureSessionID"]);

                // Agent Who?
                retval.AgentIP = (string)reader["agentIP"];
                retval.AgentPort = Convert.ToUInt32(reader["agentPort"].ToString());
                retval.AgentOnline = Convert.ToInt32(reader["agentOnline"].ToString()) != 0;

                // Login/Logout times (UNIX Epoch)
                retval.LoginTime = Convert.ToInt32(reader["loginTime"].ToString());
                retval.LogoutTime = Convert.ToInt32(reader["logoutTime"].ToString());

                // Current position
                retval.Region = new UUID((Guid)reader["currentRegion"]);
                retval.Handle = Convert.ToUInt64(reader["currentHandle"].ToString());
                Vector3 tmp_v;
                Vector3.TryParse((string)reader["currentPos"], out tmp_v);
                retval.Position = tmp_v;

            }
            else
            {
                return null;
            }
            return retval;
        }
Esempio n. 25
0
 public void AddNewUserAgent(UserAgentData agent) {}
Esempio n. 26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private static UserAgentData buildUserAgent(DataRow row)
        {
            UserAgentData ua = new UserAgentData();

            UUID tmp;
            UUID.TryParse((String)row["UUID"], out tmp);
            ua.ProfileID = tmp;
            ua.AgentIP = (String)row["agentIP"];
            ua.AgentPort = Convert.ToUInt32(row["agentPort"]);
            ua.AgentOnline = Convert.ToBoolean(row["agentOnline"]);
            ua.SessionID = new UUID((String) row["sessionID"]);
            ua.SecureSessionID = new UUID((String) row["secureSessionID"]);
            ua.InitialRegion = new UUID((String) row["regionID"]);
            ua.LoginTime = Convert.ToInt32(row["loginTime"]);
            ua.LogoutTime = Convert.ToInt32(row["logoutTime"]);
            ua.Region = new UUID((String) row["currentRegion"]);
            ua.Handle = Convert.ToUInt64(row["currentHandle"]);
            ua.Position = new Vector3(
                Convert.ToSingle(row["currentPosX"]),
                Convert.ToSingle(row["currentPosY"]),
                Convert.ToSingle(row["currentPosZ"])
                );
            ua.LookAt = new Vector3(
                Convert.ToSingle(row["currentLookAtX"]),
                Convert.ToSingle(row["currentLookAtY"]),
                Convert.ToSingle(row["currentLookAtZ"])
                );
            return ua;
        }
Esempio n. 27
0
        /// <summary>
        /// Creates a new agent and inserts it into the database
        /// </summary>
        /// <param name="agentdata">The agent data to be inserted</param>
        /// <returns>Success?</returns>
        public bool insertAgentRow(UserAgentData agentdata)
        {
            string sql = String.Empty;
            sql += "REPLACE INTO ";
            sql += "agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos, currentLookAt) VALUES ";
            sql += "(?UUID, ?sessionID, ?secureSessionID, ?agentIP, ?agentPort, ?agentOnline, ?loginTime, ?logoutTime, ?currentRegion, ?currentHandle, ?currentPos, ?currentLookAt);";
            Dictionary<string, object> parameters = new Dictionary<string, object>();

            parameters["?UUID"] = agentdata.ProfileID.ToString();
            parameters["?sessionID"] = agentdata.SessionID.ToString();
            parameters["?secureSessionID"] = agentdata.SecureSessionID.ToString();
            parameters["?agentIP"] = agentdata.AgentIP.ToString();
            parameters["?agentPort"] = agentdata.AgentPort.ToString();
            parameters["?agentOnline"] = (agentdata.AgentOnline == true) ? "1" : "0";
            parameters["?loginTime"] = agentdata.LoginTime.ToString();
            parameters["?logoutTime"] = agentdata.LogoutTime.ToString();
            parameters["?currentRegion"] = agentdata.Region.ToString();
            parameters["?currentHandle"] = agentdata.Handle.ToString();
            parameters["?currentPos"] = "<" + (agentdata.Position.X).ToString().Replace(",", ".") + "," + (agentdata.Position.Y).ToString().Replace(",", ".") + "," + (agentdata.Position.Z).ToString().Replace(",", ".") + ">";
            parameters["?currentLookAt"] = "<" + (agentdata.LookAt.X).ToString().Replace(",", ".") + "," + (agentdata.LookAt.Y).ToString().Replace(",", ".") + "," + (agentdata.LookAt.Z).ToString().Replace(",", ".") + ">";

            bool returnval = false;

            try
            {
                IDbCommand result = Query(sql, parameters);

                // int x;
                // if ((x = result.ExecuteNonQuery()) > 0)
                // {
                //     returnval = true;
                // }
                if (result.ExecuteNonQuery() > 0)
                {
                    returnval = true;
                }
                result.Dispose();
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
                return false;
            }

            return returnval;
        }
Esempio n. 28
0
        /// <summary>
        /// Creates a new user agent
        /// </summary>
        /// <param name="agent">The agent to add to the database</param>
        override public void AddNewUserAgent(UserAgentData agent)
        {
            UUID zero = UUID.Zero;
            if (agent.SessionID == zero || agent.ProfileID == zero)
                return;

            DataTable agents = ds.Tables["useragents"];
            lock (ds)
            {
                DataRow row = agents.Rows.Find(agent.ProfileID.ToString());
                if (row == null)
                {
                    row = agents.NewRow();
                    fillUserAgentRow(row, agent);
                    agents.Rows.Add(row);
                }
                else
                {
                    fillUserAgentRow(row, agent);

                }
                m_log.Info("[USER DB]: Syncing useragent database: " + ds.Tables["useragents"].Rows.Count + " agents stored");
                // save changes off to disk
                dua.Update(ds, "useragents");
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Recursive SendGridInstantMessage over XMLRPC method.
        /// This is called from within a dedicated thread.
        /// The first time this is called, prevRegionHandle will be 0 Subsequent times this is called from 
        /// itself, prevRegionHandle will be the last region handle that we tried to send.
        /// If the handles are the same, we look up the user's location using the grid.
        /// If the handles are still the same, we end.  The send failed.
        /// </summary>
        /// <param name="prevRegionHandle">
        /// Pass in 0 the first time this method is called.  It will be called recursively with the last 
        /// regionhandle tried
        /// </param>
        protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result,
            ulong prevRegionHandle, int tries)
        {
            UserAgentData upd = null;
            bool lookupAgent = false;
            UUID toAgentID = new UUID(im.toAgentID);

            if (tries > 5)
            {
                m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Retries exhausted - Unable to deliver an instant message to {0}", toAgentID.ToString());
                return;
            }

            if (m_DebugLevel >= 2)
                m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} tries={1}", prevRegionHandle, tries);

            lock (m_UserRegionMap)
            {
                if (m_UserRegionMap.ContainsKey(toAgentID))
                {
                    upd = new UserAgentData();
                    upd.AgentOnline = true;
                    upd.Handle = m_UserRegionMap[toAgentID];

                    // We need to compare the current regionhandle with the previous region handle
                    // or the recursive loop will never end because it will never try to lookup the agent again
                    if (prevRegionHandle == upd.Handle)
                    {
                        lookupAgent = true;
                        if (m_DebugLevel >= 2)
                            m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} tries={1} in region map, same region, requires lookup", prevRegionHandle, tries);
                    }
                    else
                    if (prevRegionHandle == 0)
                    {
                        if (m_DebugLevel >= 1)
                            m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} tries={1} in region map, using {2}, no lookup", prevRegionHandle, tries, upd.Handle);
                    }
                    else
                    {
                        if (m_DebugLevel >= 1)
                            m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} tries={1} in region map, different region, no lookup", prevRegionHandle, tries);
                    }
                }
                else
                {
                    lookupAgent = true;
                    if (m_DebugLevel >= 2)
                        m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} tries={1} not in region map, requires lookup", prevRegionHandle, tries);
                }
            }

            // Are we needing to look-up an agent?
            if (lookupAgent)
            {
                // Non-cached user agent lookup.
                upd = m_Scenes[0].CommsManager.UserService.GetUserAgent(toAgentID,true);

                if (upd != null)
                {
                    // check if we've tried this before..
                    // This is one way to end the recursive loop
                    //
                    if (upd.Handle == prevRegionHandle)
                    {
                        if (m_DebugLevel >= 1)
                            m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} still, tries={1}", upd.Handle, tries);
                        HandleUndeliveredMessage(im, result);
                        return;
                    }
                    else
                    {
                        if (m_DebugLevel >= 1)
                            m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} now, tries={1} lookup success", upd.Handle, tries);
                    }
                }
                else
                {
                    m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Unable to deliver an instant message to {0} (user lookup failed).", toAgentID.ToString());
                    HandleUndeliveredMessage(im, result);
                    return;
                }
            }

            if (upd != null)
            {
                if (upd.AgentOnline)
                {
                    RegionInfo reginfo = m_Scenes[0].SceneGridService.RequestNeighbouringRegionInfo(upd.Handle);
                    if (reginfo != null)
                    {
                        if (m_DebugLevel >= 2)
                            m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} now, sending grid IM", upd.Handle);
                        Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im);
                        // Not actually used anymore, left in for compatibility
                        // Remove at next interface change
                        //
                        msgdata["region_handle"] = 0;
                        bool imresult = doIMSending(reginfo, msgdata);
                        if (imresult)
                        {
                            // IM delivery successful, so store the Agent's location in our local cache.
                            lock (m_UserRegionMap)
                            {
                                if (m_UserRegionMap.ContainsKey(toAgentID))
                                {
                                    m_UserRegionMap[toAgentID] = upd.Handle;
                                    if (m_DebugLevel >= 1)
                                        m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} success, updating map", upd.Handle);
                                }
                                else
                                {
                                    m_UserRegionMap.Add(toAgentID, upd.Handle);
                                    if (m_DebugLevel >= 1)
                                        m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} success, adding to map", upd.Handle);
                                }
                            }
                            result(true);
                        }
                        else
                        {
                            // try again, but lookup user this time.
                            // Warning, this must call the Async version
                            // of this method or we'll be making thousands of threads
                            // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
                            // The version that spawns the thread is SendGridInstantMessageViaXMLRPC

                            // This is recursive!!!!!
                            if (m_DebugLevel >= 2)
                                m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} failed, retrying recursively", upd.Handle);
                            SendGridInstantMessageViaXMLRPCAsync(im, result, upd.Handle, ++tries);
                        }
                    }
                    else
                    {
                        if (m_DebugLevel >= 2)
                            m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}, will retry", upd.Handle);
                        SendGridInstantMessageViaXMLRPCAsync(im, result, upd.Handle, ++tries);
                    }
                }
                else
                {
                    if (m_DebugLevel >= 1)
                        m_log.ErrorFormat("[GRID INSTANT MESSAGE]: region={0} user offline.", upd.Handle);
                    HandleUndeliveredMessage(im, result);
                }
            }
            else
            {
                if (m_DebugLevel >= 1)
                    m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find user {0}", toAgentID);
                HandleUndeliveredMessage(im, result);
            }
        }