public void SendMessageToGroup(GridInstantMessage im, UUID groupID)
        {
            if (m_debugEnabled)
                MainConsole.Instance.DebugFormat("[GROUPS-MESSAGING]: {0} called", MethodBase.GetCurrentMethod().Name);

            // Copy Message

            GridInstantMessage msg = new GridInstantMessage
                                         {
                                             imSessionID = groupID,
                                             fromAgentName = im.fromAgentName,
                                             message = im.message,
                                             dialog = (byte) InstantMessageDialog.SessionSend,
                                             offline = 0,
                                             ParentEstateID = 0,
                                             Position = Vector3.Zero,
                                             RegionID = UUID.Zero
                                         };
            ChatSession session = m_groupData.GetSession(im.imSessionID);
            msg.binaryBucket = Utils.StringToBytes(session.Name);
            msg.timestamp = (uint) Util.UnixTimeSinceEpoch();

            msg.fromAgentID = im.fromAgentID;
            msg.fromGroup = true;

            Util.FireAndForget(SendInstantMessages, msg);
        }
        public virtual void SendInstantMessages(GridInstantMessage im, List<UUID> AgentsToSendTo)
        {
            //Check for local users first
            List<UUID> RemoveUsers = new List<UUID>();
            foreach (IScene scene in m_Scenes)
            {
                foreach (UUID t in AgentsToSendTo)
                {
                    IScenePresence user;
                    if (!RemoveUsers.Contains(t) &&
                        scene.TryGetScenePresence(t, out user))
                    {
                        // Local message
                        user.ControllingClient.SendInstantMessage(im);
                        RemoveUsers.Add(t);
                    }
                }
            }
            //Clear the local users out
            foreach (UUID agentID in RemoveUsers)
            {
                AgentsToSendTo.Remove(agentID);
            }

            SendMultipleGridInstantMessageViaXMLRPC(im, AgentsToSendTo);
        }
예제 #3
0
        public void HGIM_001()
        {
            GridInstantMessage im = new GridInstantMessage();
            im.fromAgentID = new Guid();
            im.toAgentID = new Guid();
            im.message = "Hello";
            im.imSessionID = new Guid();

            bool success = InstantMessageServiceConnector.SendInstantMessage(DemonServer.Address, im);
            Assert.IsFalse(success, "Sending of IM succeeded, but it should have failed");
        }
예제 #4
0
        public static GridInstantMessage GridInstantMessage(Dictionary<string, object> dict)
        {
            GridInstantMessage im = new GridInstantMessage();

            if (dict.ContainsKey("BinaryBucket") && dict["BinaryBucket"] != null)
                im.binaryBucket = OpenMetaverse.Utils.HexStringToBytes(dict["BinaryBucket"].ToString(), true);

            if (dict.ContainsKey("Dialog") && dict["Dialog"] != null)
                im.dialog = byte.Parse(dict["Dialog"].ToString());

            if (dict.ContainsKey("FromAgentID") && dict["FromAgentID"] != null)
                im.fromAgentID = new Guid(dict["FromAgentID"].ToString());

            if (dict.ContainsKey("FromAgentName") && dict["FromAgentName"] != null)
                im.fromAgentName = dict["FromAgentName"].ToString();
            else
                im.fromAgentName = string.Empty;

            if (dict.ContainsKey("FromGroup") && dict["FromGroup"] != null)
                im.fromGroup = bool.Parse(dict["FromGroup"].ToString());

            if (dict.ContainsKey("SessionID") && dict["SessionID"] != null)
                im.imSessionID = new Guid(dict["SessionID"].ToString());

            if (dict.ContainsKey("Message") && dict["Message"] != null)
                im.message = dict["Message"].ToString();
            else
                im.message = string.Empty;

            if (dict.ContainsKey("Offline") && dict["Offline"] != null)
                im.offline = byte.Parse(dict["Offline"].ToString());

            if (dict.ContainsKey("EstateID") && dict["EstateID"] != null)
                im.ParentEstateID = UInt32.Parse(dict["EstateID"].ToString());

            if (dict.ContainsKey("Position") && dict["Position"] != null)
                im.Position = Vector3.Parse(dict["Position"].ToString());

            if (dict.ContainsKey("RegionID") && dict["RegionID"] != null)
                im.RegionID = new Guid(dict["RegionID"].ToString());

            if (dict.ContainsKey("Timestamp") && dict["Timestamp"] != null)
                im.timestamp = UInt32.Parse(dict["Timestamp"].ToString());

            if (dict.ContainsKey("ToAgentID") && dict["ToAgentID"] != null)
                im.toAgentID = new Guid(dict["ToAgentID"].ToString());

            return im;
        }
예제 #5
0
        public GridInstantMessage(GridInstantMessage im, bool addTimestamp)
        {
            fromAgentID = im.fromAgentID;
            fromAgentName = im.fromAgentName;
            toAgentID = im.toAgentID;
            dialog = im.dialog;
            fromGroup = im.fromGroup;
            message = im.message;
            imSessionID = im.imSessionID;
            offline = im.offline;
            Position = im.Position;
            binaryBucket = im.binaryBucket;
            RegionID = im.RegionID;

            if (addTimestamp)
                timestamp = (uint)Util.UnixTimeSinceEpoch();
        }
        public GridInstantMessage(GridInstantMessage im, bool addTimestamp)
        {
            fromAgentID   = im.fromAgentID;
            fromAgentName = im.fromAgentName;
            toAgentID     = im.toAgentID;
            dialog        = im.dialog;
            fromGroup     = im.fromGroup;
            message       = im.message;
            imSessionID   = im.imSessionID;
            offline       = im.offline;
            Position      = im.Position;
            binaryBucket  = im.binaryBucket;
            RegionID      = im.RegionID;

            if (addTimestamp)
            {
                timestamp = (uint)Util.UnixTimeSinceEpoch();
            }
        }
        /// <summary>
        /// This actually does the XMLRPC Request
        /// </summary>
        /// <param name="url">URL we pull the data out of to send the request to</param>
        /// <param name="im">The Instant Message </param>
        /// <returns>Bool if the message was successfully delivered at the other side.</returns>
        public static bool SendInstantMessage(string url, GridInstantMessage im)
        {
            Hashtable xmlrpcdata = ConvertGridInstantMessageToXMLRPC(im);
            xmlrpcdata["region_handle"] = 0;

            ArrayList SendParams = new ArrayList();
            SendParams.Add(xmlrpcdata);
            XmlRpcRequest GridReq = new XmlRpcRequest("grid_instant_message", SendParams);
            try
            {

                XmlRpcResponse GridResp = GridReq.Send(url, 10000);

                Hashtable responseData = (Hashtable)GridResp.Value;

                if (responseData.ContainsKey("success"))
                {
                    if ((string)responseData["success"] == "TRUE")
                    {
                        //m_log.DebugFormat("[XXX] Success");
                        return true;
                    }
                    else
                    {
                        //m_log.DebugFormat("[XXX] Fail");
                        return false;
                    }
                }
                else
                {
                    m_log.DebugFormat("[GRID INSTANT MESSAGE]: No response from {0}", url);
                    return false;
                }
            }
            catch (WebException e)
            {
                m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Error sending message to {0} the host didn't respond " + e.ToString(), url);
            }

            return false;
        }
예제 #8
0
        private void onInstantMessage(GridInstantMessage msg)
        {
            if(msg.dialog != 0)
            {
                return;
            }

            string sender = msg.fromAgentID.ToString();
            string target = msg.toAgentID.ToString();
            int isGroup;
            if(msg.fromGroup)
            {
                isGroup = 1;//
            }
            else
            {
                isGroup = 0;
            }
            string body = msg.message;
            String message = MGMJson.InstantMessage(sender, target,isGroup,body);
            link.send(message);
        }
예제 #9
0
        public static void Main(string[] args)
        {
            ConsoleAppender consoleAppender = new ConsoleAppender();
            consoleAppender.Layout =
                new PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
            log4net.Config.BasicConfigurator.Configure(consoleAppender);

            string serverURI = "http://127.0.0.1:8002"; 
            GridInstantMessage im = new GridInstantMessage();
            im.fromAgentID = new Guid();
            im.toAgentID = new Guid();
            im.message = "Hello";
            im.imSessionID = new Guid();

            bool success = InstantMessageServiceConnector.SendInstantMessage(serverURI, im);

            if (success)
                m_log.InfoFormat("[IM CLIENT]: Successfully IMed {0}", serverURI);
            else
                m_log.InfoFormat("[IM CLIENT]: failed to IM {0}", serverURI);

            System.Console.WriteLine("\n");
        }
예제 #10
0
        public bool StoreMessage(GridInstantMessage im, out string reason)
        {
            reason = string.Empty;
            
            // Check limits
            UUID principalID = new UUID(im.toAgentID);
            long count = m_Database.GetCount("PrincipalID", principalID.ToString());
            if (count >= MAX_IM)
            {
                reason = "Number of offline IMs has maxed out";
                return false;
            }

            string imXml;
            using (MemoryStream mstream = new MemoryStream())
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = Util.UTF8NoBomEncoding;

                using (XmlWriter writer = XmlWriter.Create(mstream, settings))
                {
                    m_serializer.Serialize(writer, im);
                    writer.Flush();
                }

                imXml = Util.UTF8NoBomEncoding.GetString(mstream.ToArray());
            }

            OfflineIMData data = new OfflineIMData();
            data.PrincipalID = principalID;
            data.FromID = new UUID(im.fromAgentID);
            data.Data = new Dictionary<string, string>();
            data.Data["Message"] = imXml;

            return m_Database.Store(data);

        }
예제 #11
0
        private void OnGridInstantMessage(GridInstantMessage msg)
        {
            if (m_debugEnabled) m_log.InfoFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);

            // Trigger the above event handler
            OnInstantMessage(null, msg);

            // If a message from a group arrives here, it may need to be forwarded to a local client
            if (msg.fromGroup == true)
            {
                switch (msg.dialog)
                {
                    case (byte)InstantMessageDialog.GroupInvitation:
                    case (byte)InstantMessageDialog.GroupNotice:
                        UUID toAgentID = new UUID(msg.toAgentID);
                        IClientAPI localClient = GetActiveClient(toAgentID);
                        if (localClient != null)
                        {
                            localClient.SendInstantMessage(msg);
                        }
                        break;
                }
            }
        }
예제 #12
0
        public bool LocalFriendshipApproved(UUID userID, string userName, UUID friendID)
        {
            IClientAPI friendClient = LocateClientObject(friendID);
            if (friendClient != null)
            {
                // the prospective friend in this sim as root agent
                GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID,
                    (byte)OpenMetaverse.InstantMessageDialog.FriendshipAccepted, userID.ToString(), false, Vector3.Zero);
                friendClient.SendInstantMessage(im);
                // update the local cache
                m_Friends[friendID].Friends = FriendsService.GetFriends(friendID);
                // we're done
                return true;
            }

            return false;
        }
예제 #13
0
        private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im)
        {
            // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID)
            // We stick this agent's ID as imSession, so that it's directly available on the receiving end
            im.imSessionID = im.fromAgentID;

            // Try the local sim
            if (LocalFriendshipOffered(friendID, im))
                return;

            // The prospective friend is not here [as root]. Let's forward.
            PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
            PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions);
            if (friendSession != null)
            {
                GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
                m_FriendsSimConnector.FriendshipOffered(region, agentID, friendID, im.message);
            }

            // If the prospective friend is not online, he'll get the message upon login.
        }
예제 #14
0
        public void SendFriendsOnlineIfNeeded(IClientAPI client)
        {
            UUID agentID = client.AgentId;
            if (m_NeedsListOfFriends.Contains(agentID))
            {
                if (!m_Friends.ContainsKey(agentID))
                {
                    m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID);
                    return;
                }

                //
                // Send the friends online
                //
                List<UUID> online = GetOnlineFriends(agentID);
                if (online.Count > 0)
                {
                    m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count);
                    client.SendAgentOnline(online.ToArray());
                }

                //
                // Send outstanding friendship offers
                //
                if (m_Friends.ContainsKey(agentID))
                {
                    List<string> outstanding = new List<string>();

                    foreach (FriendInfo fi in m_Friends[agentID].Friends)
                        if (fi.TheirFlags == -1)
                            outstanding.Add(fi.Friend);

                    GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, "", agentID, (byte)InstantMessageDialog.FriendshipOffered, "Will you be my friend?", true, Vector3.Zero);
                    foreach (string fid in outstanding)
                    {
                        try
                        {
                            im.fromAgentID = new Guid(fid);
                        }
                        catch
                        {
                            continue;
                        }

                        UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, new UUID(im.fromAgentID));
                        im.fromAgentName = account.FirstName + " " + account.LastName;

                        PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid });
                        PresenceInfo presence = PresenceInfo.GetOnlinePresence(presences);
                        if (presence != null)
                            im.offline = 0;

                        im.imSessionID = im.fromAgentID;

                        // Finally
                        LocalFriendshipOffered(agentID, im);
                    }
                }

                lock (m_NeedsListOfFriends)
                    m_NeedsListOfFriends.Remove(agentID);
            }
        }
예제 #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="msg"></param>
 private void OnGridInstantMessage(GridInstantMessage msg)
 {
     // Just call the Text IM handler above
     // This event won't be raised unless we have that agent,
     // so we can depend on the above not trying to send
     // via grid again
     //
     OnInstantMessage(null, msg);
 }
예제 #16
0
 public void TriggerUnhandledInstantMessage(GridInstantMessage message)
 {
     IncomingInstantMessage handlerUnhandledInstantMessage = OnUnhandledInstantMessage;
     if (handlerUnhandledInstantMessage != null)
     {
         foreach (IncomingInstantMessage d in handlerUnhandledInstantMessage.GetInvocationList())
         {
             try
             {
                 d(message);
             }
             catch (Exception e)
             {
                 m_log.ErrorFormat(
                     "[EVENT MANAGER]: Delegate for TriggerOnAttach failed - continuing.  {0} {1}", 
                     e.Message, e.StackTrace);
             }
         }
     }
 }
예제 #17
0
        public GridInstantMessage CreateGroupNoticeIM(UUID agentID, UUID groupNoticeID, byte dialog)
        {
            if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);

            GridInstantMessage msg = new GridInstantMessage();
            byte[] bucket;

            msg.imSessionID = groupNoticeID.Guid;
            msg.toAgentID = agentID.Guid;
            msg.dialog = dialog;
            // msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupNotice;
            msg.fromGroup = true;
            msg.offline = (byte)0;
            msg.ParentEstateID = 0;
            msg.Position = Vector3.Zero;
            msg.RegionID = UUID.Zero.Guid;

            GroupNoticeInfo info = m_groupData.GetGroupNotice(agentID.ToString(), groupNoticeID);
            if (info != null)
            {
                msg.fromAgentID = info.GroupID.Guid;
                msg.timestamp = info.noticeData.Timestamp;
                msg.fromAgentName = info.noticeData.FromName;
                msg.message = info.noticeData.Subject + "|" + info.Message;
                if (info.noticeData.HasAttachment)
                {
                    byte[] name = System.Text.Encoding.UTF8.GetBytes(info.noticeData.AttachmentName);
                    bucket = new byte[19 + name.Length];
                    bucket[0] = 1; // has attachment?
                    bucket[1] = info.noticeData.AttachmentType; // attachment type
                    name.CopyTo(bucket, 18);
                }
                else
                {
                    bucket = new byte[19];
                    bucket[0] = 0; // Has att?
                    bucket[1] = 0; // type
                    bucket[18] = 0; // null terminated
                }

                info.GroupID.ToBytes(bucket, 2);
                msg.binaryBucket = bucket;
            }
            else
            {
                m_log.DebugFormat("[Groups]: Group Notice {0} not found, composing empty message.", groupNoticeID);
                msg.fromAgentID = UUID.Zero.Guid;
                msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); ;
                msg.fromAgentName = string.Empty;
                msg.message = string.Empty;
                msg.binaryBucket = new byte[0];
            }

            return msg;
        }
예제 #18
0
파일: Scene.cs 프로젝트: CCIR/opensim
        /// <summary>
        /// Backup the scene.  This acts as the main method of the backup thread.
        /// </summary>
        /// <param name="forced">
        /// If true, then any changes that have not yet been persisted are persisted.  If false,
        /// then the persistence decision is left to the backup code (in some situations, such as object persistence,
        /// it's much more efficient to backup multiple changes at once rather than every single one).
        /// <returns></returns>
        public void Backup(bool forced)
        {
            lock (m_returns)
            {
                EventManager.TriggerOnBackup(SimulationDataService, forced);
                m_backingup = false;

                foreach (KeyValuePair<UUID, ReturnInfo> ret in m_returns)
                {
                    UUID transaction = UUID.Random();

                    GridInstantMessage msg = new GridInstantMessage();
                    msg.fromAgentID = new Guid(UUID.Zero.ToString()); // From server
                    msg.toAgentID = new Guid(ret.Key.ToString());
                    msg.imSessionID = new Guid(transaction.ToString());
                    msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
                    msg.fromAgentName = "Server";
                    msg.dialog = (byte)19; // Object msg
                    msg.fromGroup = false;
                    msg.offline = (byte)0;
                    msg.ParentEstateID = RegionInfo.EstateSettings.ParentEstateID;
                    msg.Position = Vector3.Zero;
                    msg.RegionID = RegionInfo.RegionID.Guid;

                    // We must fill in a null-terminated 'empty' string here since bytes[0] will crash viewer 3.
                    msg.binaryBucket = Util.StringToBytes256("\0");
                    if (ret.Value.count > 1)
                        msg.message = string.Format("Your {0} objects were returned from {1} in region {2} due to {3}", ret.Value.count, ret.Value.location.ToString(), RegionInfo.RegionName, ret.Value.reason);
                    else
                        msg.message = string.Format("Your object {0} was returned from {1} in region {2} due to {3}", ret.Value.objectName, ret.Value.location.ToString(), RegionInfo.RegionName, ret.Value.reason);

                    IMessageTransferModule tr = RequestModuleInterface<IMessageTransferModule>();
                    if (tr != null)
                        tr.SendInstantMessage(msg, delegate(bool success) {});
                }
                m_returns.Clear();
            }
        }
예제 #19
0
 public void SendInstantMessage(GridInstantMessage im)
 {
     
 }
예제 #20
0
        public void OnInstantMessage(IClientAPI client, GridInstantMessage im)
        {
            byte dialog = im.dialog;

            if (client != null && dialog == (byte)InstantMessageDialog.MessageFromAgent)
                LogInstantMesssage(im);

            if (dialog != (byte)InstantMessageDialog.MessageFromAgent
                && dialog != (byte)InstantMessageDialog.StartTyping
                && dialog != (byte)InstantMessageDialog.StopTyping
                && dialog != (byte)InstantMessageDialog.BusyAutoResponse
                && dialog != (byte)InstantMessageDialog.MessageFromObject)
            {
                return;
            }

            //DateTime dt = DateTime.UtcNow;

            // Ticks from UtcNow, but make it look like local. Evil, huh?
            //dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);

            //try
            //{
            //    // Convert that to the PST timezone
            //    TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
            //    dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
            //}
            //catch
            //{
            //    //m_log.Info("[OFFLINE MESSAGING]: No PST timezone found on this machine. Saving with local timestamp.");
            //}

            //// And make it look local again to fool the unix time util
            //dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);

            // If client is null, this message comes from storage and IS offline
            if (client != null)
                im.offline = 0;

            if (im.offline == 0)
                im.timestamp = (uint)Util.UnixTimeSinceEpoch();

            if (m_TransferModule != null)
            {
                if (client != null)
                    im.fromAgentName = client.FirstName + " " + client.LastName;
                m_TransferModule.SendInstantMessage(im,
                    delegate(bool success)
                    {
                        if (dialog == (uint)InstantMessageDialog.StartTyping ||
                            dialog == (uint)InstantMessageDialog.StopTyping ||
                            dialog == (uint)InstantMessageDialog.MessageFromObject)
                        {
                            return;
                        }

                        if ((client != null) && !success)
                        {
                            client.SendInstantMessage(
                                    new GridInstantMessage(
                                    null, new UUID(im.fromAgentID), "System",
                                    new UUID(im.toAgentID),
                                    (byte)InstantMessageDialog.BusyAutoResponse,
                                    "Unable to send instant message. "+
                                    "User is not logged in.", false,
                                    new Vector3()));
                        }
                    }
                );
            }
        }
예제 #21
0
		public void OnStartLure(byte lureType, string message, UUID targetid, IClientAPI client)
		{
			if (!(client.Scene is Scene))
				return;
			Scene scene = (Scene)(client.Scene);

            IScenePresence presence = scene.GetScenePresence (client.AgentId);
            UUID dest = Util.BuildFakeParcelID(
				scene.RegionInfo.RegionHandle,
				(uint)presence.AbsolutePosition.X,
				(uint)presence.AbsolutePosition.Y,
				(uint)presence.AbsolutePosition.Z);

			GridInstantMessage m;

            if (scene.Permissions.IsAdministrator(client.AgentId))//if we are an admin
			{
                if (scene.Permissions.IsAdministrator(targetid)) //if they are an admin
				{
                    //Gods do not tp other gods
					m = new GridInstantMessage(scene, client.AgentId,
					                           client.FirstName+" "+client.LastName, targetid,
					                           (byte)InstantMessageDialog.RequestTeleport, false,
					                           message, dest, false, presence.AbsolutePosition,
					                           new Byte[0]);
				}
				else
				{
                    //God tp them
					m = new GridInstantMessage(scene, client.AgentId,
					                           client.FirstName+" "+client.LastName, targetid,
					                           (byte)InstantMessageDialog.GodLikeRequestTeleport, false,
					                           "", dest, false, presence.AbsolutePosition,
					                           new Byte[0]);
				}
			}
			else
			{
                //Not a god, so no god tp
				m = new GridInstantMessage(scene, client.AgentId,
				                           client.FirstName+" "+client.LastName, targetid,
				                           (byte)InstantMessageDialog.RequestTeleport, false,
				                           message, dest, false, presence.AbsolutePosition,
				                           new Byte[0]);
			}
			if (m_TransferModule != null)
			{
				m_TransferModule.SendInstantMessage(m,
				                                    delegate(bool success) { });
			}
		}
예제 #22
0
        private void LogInstantMesssage(GridInstantMessage im)
        {
            if (m_logData.Count < 20)
            {
                // Restart the log write timer
                m_logTimer.Stop();
            }
            if (!m_logTimer.Enabled)
                m_logTimer.Start();

            lock (m_logData)
            {
                m_logData.Add(im);
            }
        }
예제 #23
0
        private void OnGridInstantMessage(GridInstantMessage msg)
		{
			// Forward remote teleport requests
			//
			if (msg.dialog != 22)
				return;

			if (m_TransferModule != null)
			{
				m_TransferModule.SendInstantMessage(msg,
				                                    delegate(bool success) { });
			}
        }
예제 #24
0
        private void OnInstantMessage(IClientAPI client, GridInstantMessage im)
        {
            if (im.dialog == (byte)OpenMetaverse.InstantMessageDialog.FriendshipOffered)
            { 
                // we got a friendship offer
                UUID principalID = new UUID(im.fromAgentID);
                UUID friendID = new UUID(im.toAgentID);

                m_log.DebugFormat("[FRIENDS]: {0} offered friendship to {1}", principalID, friendID);

                // This user wants to be friends with the other user.
                // Let's add the relation backwards, in case the other is not online
                FriendsService.StoreFriend(friendID, principalID.ToString(), 0);

                // Now let's ask the other user to be friends with this user
                ForwardFriendshipOffer(principalID, friendID, im);
            }
        }
예제 #25
0
        public void EjectGroupMember(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID ejecteeID)
        {
            if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);

            // Todo: Security check?
            m_groupData.RemoveAgentFromGroup(agentID.ToString(), ejecteeID.ToString(), groupID);

            string agentName;
            RegionInfo regionInfo;

            // remoteClient provided or just agentID?
            if (remoteClient != null)
            {
                agentName = remoteClient.Name;
                regionInfo = remoteClient.Scene.RegionInfo;
                remoteClient.SendEjectGroupMemberReply(agentID, groupID, true);
            }
            else
            {
                IClientAPI client = GetActiveClient(agentID);

                if (client != null)
                {
                    agentName = client.Name;
                    regionInfo = client.Scene.RegionInfo;
                    client.SendEjectGroupMemberReply(agentID, groupID, true);
                }
                else
                {
                    regionInfo = m_sceneList[0].RegionInfo;
                    UserAccount acc = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, agentID);

                    if (acc != null)
                    {
                        agentName = acc.FirstName + " " + acc.LastName;
                    }
                    else
                    {
                        agentName = "Unknown member";
                    }
                }
            }

            GroupRecord groupInfo = m_groupData.GetGroupRecord(agentID.ToString(), groupID, null);

            UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, ejecteeID);
            if ((groupInfo == null) || (account == null))
            {
                return;
            }

            // Send Message to Ejectee
            GridInstantMessage msg = new GridInstantMessage();
            
            msg.imSessionID = UUID.Zero.Guid;
            msg.fromAgentID = agentID.Guid;
            // msg.fromAgentID = info.GroupID;
            msg.toAgentID = ejecteeID.Guid;
            //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
            msg.timestamp = 0;
            msg.fromAgentName = agentName;
            msg.message = string.Format("You have been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName);
            msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageFromAgent;
            msg.fromGroup = false;
            msg.offline = (byte)0;
            msg.ParentEstateID = 0;
            msg.Position = Vector3.Zero;
            msg.RegionID = regionInfo.RegionID.Guid;
            msg.binaryBucket = new byte[0];
            OutgoingInstantMessage(msg, ejecteeID);

            // Message to ejector
            // Interop, received special 210 code for ejecting a group member
            // this only works within the comms servers domain, and won't work hypergrid
            // TODO:FIXME: Use a presense server of some kind to find out where the 
            // client actually is, and try contacting that region directly to notify them,
            // or provide the notification via xmlrpc update queue

            msg = new GridInstantMessage();
            msg.imSessionID = UUID.Zero.Guid;
            msg.fromAgentID = agentID.Guid;
            msg.toAgentID = agentID.Guid;
            msg.timestamp = 0;
            msg.fromAgentName = agentName;
            if (account != null)
            {
                msg.message = string.Format("{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName, account.FirstName + " " + account.LastName);
            }
            else
            {
                msg.message = string.Format("{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName, "Unknown member");
            }
            msg.dialog = (byte)210; //interop
            msg.fromGroup = false;
            msg.offline = (byte)0;
            msg.ParentEstateID = 0;
            msg.Position = Vector3.Zero;
            msg.RegionID = regionInfo.RegionID.Guid;
            msg.binaryBucket = new byte[0];
            OutgoingInstantMessage(msg, agentID);


            // SL sends out messages to everyone in the group
            // Who all should receive updates and what should they be updated with?
            UpdateAllClientsWithGroupInfo(ejecteeID);
        }
예제 #26
0
 public bool LocalFriendshipOffered(UUID toID, GridInstantMessage im)
 {
     IClientAPI friendClient = LocateClientObject(toID);
     if (friendClient != null)
     {
         // the prospective friend in this sim as root agent
         friendClient.SendInstantMessage(im);
         // we're done
         return true;
     }
     return false;
 }
예제 #27
0
        public void InviteGroup(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID invitedAgentID, UUID roleID)
        {
            if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);

            string agentName = m_UserManagement.GetUserName(agentID);
            RegionInfo regionInfo = m_sceneList[0].RegionInfo;

            GroupRecord group = m_groupData.GetGroupRecord(agentID.ToString(), groupID, null);
            if (group == null)
            {
                m_log.DebugFormat("[Groups]: No such group {0}", groupID);
                return;
            }

            // Todo: Security check, probably also want to send some kind of notification
            UUID InviteID = UUID.Random();

            if (m_groupData.AddAgentToGroupInvite(agentID.ToString(), InviteID, groupID, roleID, invitedAgentID.ToString()))
            {
                if (m_msgTransferModule != null)
                {
                    Guid inviteUUID = InviteID.Guid;

                    GridInstantMessage msg = new GridInstantMessage();

                    msg.imSessionID = inviteUUID;

                    // msg.fromAgentID = agentID.Guid;
                    msg.fromAgentID = groupID.Guid;
                    msg.toAgentID = invitedAgentID.Guid;
                    //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
                    msg.timestamp = 0;
                    msg.fromAgentName = agentName;
                    msg.message = string.Format("{0} has invited you to join a group called {1}. There is no cost to join this group.", agentName, group.GroupName);
                    msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupInvitation;
                    msg.fromGroup = true;
                    msg.offline = (byte)0;
                    msg.ParentEstateID = 0;
                    msg.Position = Vector3.Zero;
                    msg.RegionID = regionInfo.RegionID.Guid;
                    msg.binaryBucket = new byte[20];

                    OutgoingInstantMessage(msg, invitedAgentID);
                }
            }
        }
예제 #28
0
        public bool LocalFriendshipDenied(UUID userID, string userName, UUID friendID)
        {
            IClientAPI friendClient = LocateClientObject(friendID);
            if (friendClient != null)
            {
                // the prospective friend in this sim as root agent

                GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID,
                    (byte)OpenMetaverse.InstantMessageDialog.FriendshipDeclined, userID.ToString(), false, Vector3.Zero);
                friendClient.SendInstantMessage(im);
                // we're done
                return true;
            }
            
            return false;
        }
예제 #29
0
        private void OutgoingInstantMessage(GridInstantMessage msg, UUID msgTo)
        {
            if (m_debugEnabled) m_log.InfoFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);

            IClientAPI localClient = GetActiveClient(msgTo);
            if (localClient != null)
            {
                if (m_debugEnabled) m_log.InfoFormat("[Groups]: MsgTo ({0}) is local, delivering directly", localClient.Name);
                localClient.SendInstantMessage(msg);
            }
            else if (m_msgTransferModule != null)
            {
                if (m_debugEnabled) m_log.InfoFormat("[Groups]: MsgTo ({0}) is not local, delivering via TransferModule", msgTo);
                m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { if (m_debugEnabled) m_log.DebugFormat("[Groups]: Message Sent: {0}", success?"Succeeded":"Failed"); });
            }
        }
예제 #30
0
        public static Dictionary<string, object> GridInstantMessage(GridInstantMessage im)
        {
            Dictionary<string, object> dict = new Dictionary<string, object>();

            dict["BinaryBucket"] = OpenMetaverse.Utils.BytesToHexString(im.binaryBucket, im.binaryBucket.Length, null);
            dict["Dialog"] = im.dialog.ToString();
            dict["FromAgentID"] = im.fromAgentID.ToString();
            dict["FromAgentName"] = im.fromAgentName == null ? string.Empty : im.fromAgentName;
            dict["FromGroup"] = im.fromGroup.ToString();
            dict["SessionID"] = im.imSessionID.ToString();
            dict["Message"] = im.message == null ? string.Empty : im.message;
            dict["Offline"] = im.offline.ToString();
            dict["EstateID"] = im.ParentEstateID.ToString();
            dict["Position"] = im.Position.ToString();
            dict["RegionID"] = im.RegionID.ToString();
            dict["Timestamp"] = im.timestamp.ToString();
            dict["ToAgentID"] = im.toAgentID.ToString();

            return dict;
        }
예제 #31
0
        private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im)
        {
            if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);

            //m_log.DebugFormat("[Groups]: IM From {0} to {1} msg {2} type {3}", im.fromAgentID, im.toAgentID, im.message, (InstantMessageDialog)im.dialog);
            // Group invitations
            if ((im.dialog == (byte)InstantMessageDialog.GroupInvitationAccept) || (im.dialog == (byte)InstantMessageDialog.GroupInvitationDecline))
            {
                UUID inviteID = new UUID(im.imSessionID);
                GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(GetRequestingAgentIDStr(remoteClient), inviteID);

                if (inviteInfo == null)
                {
                    if (m_debugEnabled) m_log.WarnFormat("[Groups]: Received an Invite IM for an invite that does not exist {0}.", inviteID);
                    return;
                }

                //m_log.DebugFormat("[XXX]: Invite is for Agent {0} to Group {1}.", inviteInfo.AgentID, inviteInfo.GroupID);

                UUID fromAgentID = new UUID(im.fromAgentID);
                UUID invitee = UUID.Zero;
                string tmp = string.Empty;
                Util.ParseUniversalUserIdentifier(inviteInfo.AgentID, out invitee, out tmp, out tmp, out tmp, out tmp);
                if ((inviteInfo != null) && (fromAgentID == invitee))
                {
                    // Accept
                    if (im.dialog == (byte)InstantMessageDialog.GroupInvitationAccept)
                    {
                        //m_log.DebugFormat("[XXX]: Received an accept invite notice.");

                        // and the sessionid is the role
                        string reason = string.Empty;
                        if (!m_groupData.AddAgentToGroup(GetRequestingAgentIDStr(remoteClient), invitee.ToString(), inviteInfo.GroupID, inviteInfo.RoleID, string.Empty, out reason))
                            remoteClient.SendAgentAlertMessage("Unable to add you to the group: " + reason, false);
                        else
                        {
                            GridInstantMessage msg = new GridInstantMessage();
                            msg.imSessionID = UUID.Zero.Guid;
                            msg.fromAgentID = UUID.Zero.Guid;
                            msg.toAgentID = invitee.Guid;
                            msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
                            msg.fromAgentName = "Groups";
                            msg.message = string.Format("You have been added to the group.");
                            msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageBox;
                            msg.fromGroup = false;
                            msg.offline = (byte)0;
                            msg.ParentEstateID = 0;
                            msg.Position = Vector3.Zero;
                            msg.RegionID = UUID.Zero.Guid;
                            msg.binaryBucket = new byte[0];

                            OutgoingInstantMessage(msg, invitee);

                            UpdateAllClientsWithGroupInfo(invitee);
                        }

                        m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentIDStr(remoteClient), inviteID);

                    }

                    // Reject
                    if (im.dialog == (byte)InstantMessageDialog.GroupInvitationDecline)
                    {
                        if (m_debugEnabled) m_log.DebugFormat("[Groups]: Received a reject invite notice.");
                        m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentIDStr(remoteClient), inviteID);

                        m_groupData.RemoveAgentFromGroup(GetRequestingAgentIDStr(remoteClient), inviteInfo.AgentID, inviteInfo.GroupID);
                    }
                }
            }

            // Group notices
            if ((im.dialog == (byte)InstantMessageDialog.GroupNotice))
            {
                if (!m_groupNoticesEnabled)
                {
                    return;
                }

                UUID GroupID = new UUID(im.toAgentID);
                if (m_groupData.GetGroupRecord(GetRequestingAgentIDStr(remoteClient), GroupID, null) != null)
                {
                    UUID NoticeID = UUID.Random();
                    string Subject = im.message.Substring(0, im.message.IndexOf('|'));
                    string Message = im.message.Substring(Subject.Length + 1);

                    InventoryItemBase item = null;
                    bool hasAttachment = false;

                    if (im.binaryBucket.Length >= 1 && im.binaryBucket[0] > 0)
                    {
                        hasAttachment = true;
                        string binBucket = OpenMetaverse.Utils.BytesToString(im.binaryBucket);
                        binBucket = binBucket.Remove(0, 14).Trim();

                        OSD binBucketOSD = OSDParser.DeserializeLLSDXml(binBucket);
                        if (binBucketOSD is OSDMap)
                        {
                            OSDMap binBucketMap = (OSDMap)binBucketOSD;

                            UUID itemID = binBucketMap["item_id"].AsUUID();
                            UUID ownerID = binBucketMap["owner_id"].AsUUID();
                            item = new InventoryItemBase(itemID, ownerID);
                            item = m_sceneList[0].InventoryService.GetItem(item);
                        }
                        else
                            m_log.DebugFormat("[Groups]: Received OSD with unexpected type: {0}", binBucketOSD.GetType());
                    }

                    if (m_groupData.AddGroupNotice(GetRequestingAgentIDStr(remoteClient), GroupID, NoticeID, im.fromAgentName, Subject, Message,
                        hasAttachment, 
                        (byte)(item == null ? 0 : item.AssetType),
                        item == null ? null : item.Name, 
                        item == null ? UUID.Zero : item.ID,
                        item == null ? UUID.Zero.ToString() : item.Owner.ToString()))
                    {
                        if (OnNewGroupNotice != null)
                        {
                            OnNewGroupNotice(GroupID, NoticeID);
                        }

                       
                        // Send notice out to everyone that wants notices
                        foreach (GroupMembersData member in m_groupData.GetGroupMembers(GetRequestingAgentIDStr(remoteClient), GroupID))
                        {
                            if (member.AcceptNotices)
                            {
                                // Build notice IIM, one of reach, because the sending may be async
                                GridInstantMessage msg = CreateGroupNoticeIM(UUID.Zero, NoticeID, (byte)OpenMetaverse.InstantMessageDialog.GroupNotice);
                                msg.toAgentID = member.AgentID.Guid;
                                OutgoingInstantMessage(msg, member.AgentID);
                            }
                        }
                    }
                }
            }

            if (im.dialog == (byte)InstantMessageDialog.GroupNoticeInventoryAccepted)
            {
                if (im.binaryBucket.Length < 16) // Invalid
                    return;

                //// 16 bytes are the UUID. Maybe.
//                UUID folderID = new UUID(im.binaryBucket, 0);
                UUID noticeID = new UUID(im.imSessionID);

                GroupNoticeInfo notice = m_groupData.GetGroupNotice(remoteClient.AgentId.ToString(), noticeID);
                if (notice != null)
                {
                    UUID giver = new UUID(im.toAgentID);
                    string tmp = string.Empty;
                    Util.ParseUniversalUserIdentifier(notice.noticeData.AttachmentOwnerID, out giver, out tmp, out tmp, out tmp, out tmp);

                    m_log.DebugFormat("[Groups]: Giving inventory from {0} to {1}", giver, remoteClient.AgentId);
                    InventoryItemBase itemCopy = ((Scene)(remoteClient.Scene)).GiveInventoryItem(remoteClient.AgentId, 
                        giver, notice.noticeData.AttachmentItemID);

                    if (itemCopy == null)
                    {
                        remoteClient.SendAgentAlertMessage("Can't find item to give. Nothing given.", false);
                        return;
                    }

                    remoteClient.SendInventoryItemCreateUpdate(itemCopy, 0);
                }

            }
          
            // Interop, received special 210 code for ejecting a group member
            // this only works within the comms servers domain, and won't work hypergrid
            // TODO:FIXME: Use a presense server of some kind to find out where the 
            // client actually is, and try contacting that region directly to notify them,
            // or provide the notification via xmlrpc update queue
            if ((im.dialog == 210))
            {
                // This is sent from the region that the ejectee was ejected from
                // if it's being delivered here, then the ejectee is here
                // so we need to send local updates to the agent.

                UUID ejecteeID = new UUID(im.toAgentID);

                im.dialog = (byte)InstantMessageDialog.MessageFromAgent;
                OutgoingInstantMessage(im, ejecteeID);

                IClientAPI ejectee = GetActiveClient(ejecteeID);
                if (ejectee != null)
                {
                    UUID groupID = new UUID(im.imSessionID);
                    ejectee.SendAgentDropGroup(groupID);
                }
            }
        }