/// <summary> /// Emulate sending an IM from the viewer to the simulator. /// </summary> /// <param name='im'></param> public void HandleImprovedInstantMessage(GridInstantMessage im) { ImprovedInstantMessage handlerInstantMessage = OnInstantMessage; if (handlerInstantMessage != null) { handlerInstantMessage(this, im); } }
private void HandleGroupNotice(ViewerAgent agent, SceneInterface scene, ImprovedInstantMessage m) { /* no validation needed with IM, that is already done in circuit */ var groupsService = scene.GroupsService; if (groupsService == null) { return; } UGI group; try { group = groupsService.Groups[agent.Owner, m.ToAgentID]; } catch { return; } if ((GetGroupPowers(agent.Owner, groupsService, group) & GroupPowers.SendNotices) == 0) { return; } InventoryItem item = null; if (m.BinaryBucket.Length >= 1 && m.BinaryBucket[0] > 0) { try { var iv = LlsdXml.Deserialize(new MemoryStream(m.BinaryBucket)); if (iv is Map) { var binBuck = (Map)iv; var itemID = binBuck["item_id"].AsUUID; var ownerID = binBuck["owner_id"].AsUUID; item = agent.InventoryService.Item[ownerID, itemID]; } } catch { /* do not expose exceptions to caller */ } } var gn = new GroupNotice { ID = UUID.Random, Group = group, FromName = agent.NamedOwner.FullName }; var submsg = m.Message.Split(new char[] { '|' }, 2); gn.Subject = submsg.Length > 1 ? submsg[0] : string.Empty; gn.Message = submsg.Length > 1 ? submsg[1] : submsg[0]; gn.HasAttachment = item != null; gn.AttachmentType = item != null ? item.AssetType : Types.Asset.AssetType.Unknown; gn.AttachmentName = item != null ? item.Name : string.Empty; gn.AttachmentItemID = item != null ? item.ID : UUID.Zero; gn.AttachmentOwner = item != null ? item.Owner : UGUI.Unknown; var gim = new GridInstantMessage { FromAgent = agent.NamedOwner, Dialog = GridInstantMessageDialog.GroupNotice, IsFromGroup = true, Message = m.Message, IMSessionID = gn.ID, BinaryBucket = m.BinaryBucket }; try { groupsService.Notices.Add(agent.Owner, gn); IMGroupNoticeQueue.Enqueue(new KeyValuePair <SceneInterface, GridInstantMessage>(scene, gim)); } catch { /* do not expose exceptions to caller */ } }
private void HandleSessionAdd(ViewerAgent agent, SceneInterface scene, ImprovedInstantMessage m) { }
private void HandleFriendshipOffered(ImprovedInstantMessage m) { if (m.CircuitAgentID != m.AgentID || m.CircuitSessionID != m.SessionID) { return; } SceneInterface scene; if (!m_Scenes.TryGetValue(m.CircuitSceneID, out scene)) { return; } IAgent agent; if (!scene.Agents.TryGetValue(m.AgentID, out agent)) { return; } if (agent.KnownFriends.ContainsKey(m.ToAgentID)) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "AlreadyYourFriend", "This person is already your friend."), m.CircuitSceneID); return; } if (agent.FriendsService == null) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "FriendsServiceNotAccessible", "The friends service is not accessible."), m.CircuitSceneID); return; } var thisAgent = agent.NamedOwner; UGUIWithName otherAgent; var foreignagent = true; if (!scene.AvatarNameService.TryGetValue(m.ToAgentID, out otherAgent)) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "OtherPersonIdentityIsNotKnown", "Other person's identity is not known."), m.CircuitSceneID); return; } FriendsServiceInterface otherFriendsService; if ((otherAgent.HomeURI == null && thisAgent.HomeURI == null) || otherAgent.HomeURI.Equals(thisAgent.HomeURI)) { /* same user service including friends */ otherFriendsService = agent.FriendsService; foreignagent = false; } else if (!TryGetFriendsService(otherAgent, out otherFriendsService)) { return; } var fi = new FriendInfo { User = thisAgent, Friend = otherAgent, FriendGivenFlags = 0, UserGivenFlags = 0, Secret = string.Empty }; fi.User.HomeURI = null; fi.Friend.HomeURI = null; if (foreignagent) { otherFriendsService.StoreOffer(fi); } agent.FriendsService.StoreOffer(fi); var gim = (GridInstantMessage)m; gim.FromAgent = thisAgent; gim.ToAgent = otherAgent; gim.IMSessionID = thisAgent.ID; m_IMService.Send(gim); }