private OSDMap syncRecievedService_OnMessageReceived(OSDMap message)
        {
            string method = message["Method"];
            if (method == "SendInstantMessages")
            {
                List<GridInstantMessage> messages =
                    ((OSDArray) message["Messages"]).ConvertAll<GridInstantMessage>((o) =>
                                                                                        {
                                                                                            GridInstantMessage im =
                                                                                                new GridInstantMessage();
                                                                                            im.FromOSD((OSDMap) o);
                                                                                            return im;
                                                                                        });
                ISceneManager manager = m_registry.RequestModuleInterface<ISceneManager>();
                if (manager != null)
                {
                    foreach (GridInstantMessage im in messages)
                    {
                        Framework.PresenceInfo.IScenePresence UserPresence;

                        foreach (IScene scene in manager.Scenes)
                        {
                            UserPresence = scene.GetScenePresence(im.ToAgentID);

                            //AR: Do not fire for child agents or group messages are sent for every region
                            if (UserPresence != null && UserPresence.IsChildAgent == false)
                            {
                                IMessageTransferModule messageTransfer = scene.RequestModuleInterface<IMessageTransferModule>();
                                if (messageTransfer != null)
                                {
                                    messageTransfer.SendInstantMessage(im);
                                }
                            }
                        }
                    }
                }
            }
            return null;
        }
 protected OSDMap OnMessageReceived(OSDMap message)
 {
     if (!message.ContainsKey ("Method"))
         return null;
     if (message ["Method"] == "FriendGrantRights")
     {
         UUID Requester = message ["Requester"].AsUUID ();
         UUID Target = message ["Target"].AsUUID ();
         int MyFlags = message ["MyFlags"].AsInteger ();
         int Rights = message ["Rights"].AsInteger ();
         LocalGrantRights (Requester, Target, MyFlags, Rights);
     } else if (message ["Method"] == "FriendTerminated")
     {
         UUID Requester = message ["Requester"].AsUUID ();
         UUID ExFriend = message ["ExFriend"].AsUUID ();
         LocalFriendshipTerminated (ExFriend, Requester);
     } else if (message ["Method"] == "FriendshipOffered")
     {
         //UUID Requester = message["Requester"].AsUUID();
         UUID Friend = message ["Friend"].AsUUID ();
         GridInstantMessage im = new GridInstantMessage ();
         im.FromOSD ((OSDMap)message ["Message"]);
         LocalFriendshipOffered (Friend, im);
     } else if (message ["Method"] == "FriendshipDenied")
     {
         UUID Requester = message ["Requester"].AsUUID ();
         string ClientName = message ["ClientName"].AsString ();
         UUID FriendID = message ["FriendID"].AsUUID ();
         LocalFriendshipDenied (Requester, ClientName, FriendID);
     } else if (message ["Method"] == "FriendshipApproved")
     {
         UUID Requester = message ["Requester"].AsUUID ();
         string ClientName = message ["ClientName"].AsString ();
         UUID FriendID = message ["FriendID"].AsUUID ();
         LocalFriendshipApproved (Requester, ClientName, null, FriendID);
     }
     return null;
 }
        public void SendChatToSession(UUID agentID, GridInstantMessage im)
        {
            if (m_doRemoteOnly)
            {
                DoRemoteCallPost(true, "InstantMessageServerURI", agentID, im);
                return;
            }

            Util.FireAndForget((o) =>
                                   {
                                       ChatSession session;
                                       ChatSessions.TryGetValue(im.SessionID, out session);
                                       if (session == null)
                                           return;

                                       if (agentID != UUID.Zero) //Not system
                                       {
                                           ChatSessionMember sender = FindMember(im.SessionID, agentID);
                                           if (sender.MuteText)
                                               return; //They have been admin muted, don't allow them to send anything
                                       }

                                       Dictionary<string, List<GridInstantMessage>> messagesToSend =
                                           new Dictionary<string, List<GridInstantMessage>>();
                                       foreach (ChatSessionMember member in session.Members)
                                       {
                                           if (member.HasBeenAdded)
                                           {
                                               im.ToAgentID = member.AvatarKey;
                                               im.BinaryBucket = Utils.StringToBytes(session.Name);
                                               im.RegionID = UUID.Zero;
                                               im.ParentEstateID = 0;
                                               im.Offline = 0;
                                               GridInstantMessage message = new GridInstantMessage();
                                               message.FromOSD(im.ToOSD());
                                               //im.timestamp = 0;
                                               string uri = FindRegionURI(member.AvatarKey);
                                               if (uri != "") //Check if they are online
                                               {
                                                   //Bulk send all of the instant messages to the same region, so that we don't send them one-by-one over and over
                                                   if (messagesToSend.ContainsKey(uri))
                                                       messagesToSend[uri].Add(message);
                                                   else
                                                       messagesToSend.Add(uri, new List<GridInstantMessage>() {message});
                                               }
                                           }
                                           else if (!member.RequestedRemoval)
                                               //If they're requested to leave, don't recontact them
                                           {
                                               UUID regionID = FindRegionID(member.AvatarKey);
                                               if (regionID != UUID.Zero)
                                               {
                                                   im.ToAgentID = member.AvatarKey;
                                                   m_eventQueueService.ChatterboxInvitation(
                                                       session.SessionID
                                                       , session.Name
                                                       , im.FromAgentID
                                                       , im.Message
                                                       , im.ToAgentID
                                                       , im.FromAgentName
                                                       , im.Dialog
                                                       , im.Timestamp
                                                       , im.Offline == 1
                                                       , (int) im.ParentEstateID
                                                       , im.Position
                                                       , 1
                                                       , im.SessionID
                                                       , false
                                                       , Utils.StringToBytes(session.Name)
                                                       , regionID
                                                       );
                                               }
                                           }
                                       }
                                       foreach (KeyValuePair<string, List<GridInstantMessage>> kvp in messagesToSend)
                                       {
                                           SendInstantMessages(kvp.Key, kvp.Value);
                                       }
                                   });
        }
        public override void FromOSD(OSDMap map)
        {
            AgentInfo = new IAgentInfo();
            AgentInfo.FromOSD((OSDMap) (map["AgentInfo"]));
            UserAccount = new UserAccount();
            UserAccount.FromOSD((OSDMap)(map["UserAccount"]));
            if (!map.ContainsKey("ActiveGroup"))
                ActiveGroup = null;
            else
            {
                ActiveGroup = new GroupMembershipData();
                ActiveGroup.FromOSD((OSDMap)(map["ActiveGroup"]));
            }
            GroupMemberships = ((OSDArray) map["GroupMemberships"]).ConvertAll<GroupMembershipData>((o) =>
                                                                                                        {
                                                                                                            GroupMembershipData
                                                                                                                group =
                                                                                                                    new GroupMembershipData
                                                                                                                        ();
                                                                                                            group
                                                                                                                .FromOSD
                                                                                                                ((OSDMap
                                                                                                                 ) o);
                                                                                                            return group;
                                                                                                        });
            OfflineMessages = ((OSDArray) map["OfflineMessages"]).ConvertAll<GridInstantMessage>((o) =>
                                                                                                     {
                                                                                                         GridInstantMessage
                                                                                                             group =
                                                                                                                 new GridInstantMessage
                                                                                                                     ();
                                                                                                         group.FromOSD(
                                                                                                             (OSDMap) o);
                                                                                                         return group;
                                                                                                     });
            MuteList = ((OSDArray) map["MuteList"]).ConvertAll<MuteList>((o) =>
                                                                             {
                                                                                 MuteList group = new MuteList();
                                                                                 group.FromOSD((OSDMap) o);
                                                                                 return group;
                                                                             });

            if (map.ContainsKey("Appearance"))
            {
                Appearance = new AvatarAppearance();
                Appearance.FromOSD((OSDMap)map["Appearance"]);
            }
            if (map.ContainsKey("FriendOnlineStatuses"))
                FriendOnlineStatuses = ((OSDArray)map["FriendOnlineStatuses"]).ConvertAll<UUID>((o) => { return o; });
            if (map.ContainsKey("Friends"))
                Friends = ((OSDArray)map["Friends"]).ConvertAll<FriendInfo>((o) =>
                {
                    FriendInfo f = new FriendInfo();
                    f.FromOSD((OSDMap)o);
                    return f;
                });
        }