mirror of
https://github.com/opensim/opensim.git
synced 2026-08-09 18:55:58 +08:00
* You can add and remove a friend in standalone now within the same simulator. It saves.
* You can add and remove a friend in grid mode now within the same simulator. It doesn't save yet. * I got rid of Mr. OpenSim as a friend.. he bothers me /:b...
This commit is contained in:
28
OpenSim/Region/Environment/InstantMessageReceiver.cs
Normal file
28
OpenSim/Region/Environment/InstantMessageReceiver.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace OpenSim.Region.Environment
|
||||
{
|
||||
/// <summary>
|
||||
/// Bit Vector for Which Modules to send an instant message to from the Scene or an Associated Module
|
||||
/// </summary>
|
||||
|
||||
// This prevents the Modules from sending Instant messages to other modules through the scene
|
||||
// and then receiving the same messages
|
||||
|
||||
// This is mostly here because on LLSL and the SecondLife Client, IMs,Groups and friends are linked
|
||||
// inseparably
|
||||
|
||||
[Flags]
|
||||
public enum InstantMessageReceiver : uint
|
||||
{
|
||||
/// <summary>None of them.. here for posterity and amusement</summary>
|
||||
None = 0,
|
||||
/// <summary>The IM Module</summary>
|
||||
IMModule = 0x00000001,
|
||||
/// <summary>The Friends Module</summary>
|
||||
FriendsModule = 0x00000002,
|
||||
/// <summary>The Groups Module</summary>
|
||||
GroupsModule = 0x00000004
|
||||
|
||||
}
|
||||
}
|
||||
@@ -35,52 +35,179 @@ using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using libsecondlife;
|
||||
using libsecondlife.Packets;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class FriendsModule : IRegionModule
|
||||
{
|
||||
private List<Scene> m_scenes = new List<Scene>();
|
||||
|
||||
private LogBase m_log;
|
||||
|
||||
private Scene m_scene;
|
||||
|
||||
Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>();
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_log = MainLog.Instance;
|
||||
if (!m_scenes.Contains(scene))
|
||||
{
|
||||
m_scenes.Add(scene);
|
||||
scene.EventManager.OnNewClient += OnNewClient;
|
||||
}
|
||||
m_scene = scene;
|
||||
scene.EventManager.OnNewClient += OnNewClient;
|
||||
scene.EventManager.OnGridInstantMessageToFriendsModule += OnGridInstantMessage;
|
||||
}
|
||||
|
||||
private void OnNewClient(IClientAPI client)
|
||||
{
|
||||
//FormFriendship(client,new Guid("c43a67ab-b196-4d62-936c-b40369547dee"));
|
||||
//FormFriendship(client, new Guid("0a2f777b-f44c-4662-8b22-c90ae038a3e6"));
|
||||
// All friends establishment protocol goes over instant message
|
||||
// There's no way to send a message from the sim
|
||||
// to a user to 'add a friend' without causing dialog box spam
|
||||
//
|
||||
// The base set of friends are added when the user signs on in their XMLRPC response
|
||||
// Generated by LoginService. The friends are retreived from the database by the UserManager
|
||||
|
||||
// Subscribe to instant messages
|
||||
client.OnInstantMessage += OnInstantMessage;
|
||||
client.OnApproveFriendRequest += OnApprovedFriendRequest;
|
||||
client.OnDenyFriendRequest += OnDenyFriendRequest;
|
||||
client.OnTerminateFriendship += OnTerminateFriendship;
|
||||
|
||||
|
||||
}
|
||||
private void OnInstantMessage(LLUUID fromAgentID,
|
||||
LLUUID fromAgentSession, LLUUID toAgentID,
|
||||
LLUUID imSessionID, uint timestamp, string fromAgentName,
|
||||
string message, byte dialog, bool fromGroup, byte offline,
|
||||
uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
|
||||
byte[] binaryBucket)
|
||||
{
|
||||
// Friend Requests go by Instant Message.. using the dialog param
|
||||
// https://wiki.secondlife.com/wiki/ImprovedInstantMessage
|
||||
|
||||
// 38 == Offer friendship
|
||||
if (dialog == (byte)38)
|
||||
{
|
||||
LLUUID friendTransactionID = LLUUID.Random();
|
||||
|
||||
m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
|
||||
|
||||
m_log.Verbose("FRIEND", "38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message);
|
||||
GridInstantMessage msg = new GridInstantMessage();
|
||||
msg.fromAgentID = fromAgentID.UUID;
|
||||
msg.fromAgentSession = fromAgentSession.UUID;
|
||||
msg.toAgentID = toAgentID.UUID;
|
||||
msg.imSessionID = friendTransactionID.UUID; // This is the item we're mucking with here
|
||||
m_log.Verbose("FRIEND","Filling Session: " + msg.imSessionID.ToString());
|
||||
msg.timestamp = timestamp;
|
||||
msg.fromAgentName = fromAgentName;
|
||||
msg.message = message;
|
||||
msg.dialog = dialog;
|
||||
msg.fromGroup = fromGroup;
|
||||
msg.offline = offline;
|
||||
msg.ParentEstateID = ParentEstateID;
|
||||
msg.Position = new sLLVector3(Position);
|
||||
msg.RegionID = RegionID.UUID;
|
||||
msg.binaryBucket = binaryBucket;
|
||||
m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
|
||||
}
|
||||
if (dialog == (byte)39)
|
||||
{
|
||||
m_log.Verbose("FRIEND", "38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message);
|
||||
|
||||
}
|
||||
if (dialog == (byte)40)
|
||||
{
|
||||
m_log.Verbose("FRIEND", "38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message);
|
||||
}
|
||||
|
||||
// 39 == Accept Friendship
|
||||
|
||||
// 40 == Decline Friendship
|
||||
|
||||
}
|
||||
|
||||
private void OnApprovedFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders)
|
||||
{
|
||||
if (m_pendingFriendRequests.ContainsKey(transactionID))
|
||||
{
|
||||
// Found Pending Friend Request with that Transaction..
|
||||
|
||||
// Compose response to other agent.
|
||||
GridInstantMessage msg = new GridInstantMessage();
|
||||
msg.toAgentID = m_pendingFriendRequests[transactionID].UUID;
|
||||
msg.fromAgentID = agentID.UUID;
|
||||
msg.fromAgentName = client.FirstName + " " + client.LastName;
|
||||
msg.fromAgentSession = client.SessionId.UUID;
|
||||
msg.fromGroup = false;
|
||||
msg.imSessionID = transactionID.UUID;
|
||||
msg.message = agentID.UUID.ToString();
|
||||
msg.ParentEstateID = 0;
|
||||
msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
|
||||
msg.RegionID = m_scene.RegionInfo.RegionID.UUID;
|
||||
msg.dialog = (byte)39;// Approved friend request
|
||||
msg.Position = new sLLVector3();
|
||||
msg.offline = (byte)0;
|
||||
msg.binaryBucket = new byte[0];
|
||||
m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
|
||||
m_scene.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1);
|
||||
m_pendingFriendRequests.Remove(transactionID);
|
||||
|
||||
// TODO: Inform agent that the friend is online
|
||||
}
|
||||
}
|
||||
private void OnDenyFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders)
|
||||
{
|
||||
if (m_pendingFriendRequests.ContainsKey(transactionID))
|
||||
{
|
||||
// Found Pending Friend Request with that Transaction..
|
||||
|
||||
// Compose response to other agent.
|
||||
GridInstantMessage msg = new GridInstantMessage();
|
||||
msg.toAgentID = m_pendingFriendRequests[transactionID].UUID;
|
||||
msg.fromAgentID = agentID.UUID;
|
||||
msg.fromAgentName = client.FirstName + " " + client.LastName;
|
||||
msg.fromAgentSession = client.SessionId.UUID;
|
||||
msg.fromGroup = false;
|
||||
msg.imSessionID = transactionID.UUID;
|
||||
msg.message = agentID.UUID.ToString();
|
||||
msg.ParentEstateID = 0;
|
||||
msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
|
||||
msg.RegionID = m_scene.RegionInfo.RegionID.UUID;
|
||||
msg.dialog = (byte)40;// Deny friend request
|
||||
msg.Position = new sLLVector3();
|
||||
msg.offline = (byte)0;
|
||||
msg.binaryBucket = new byte[0];
|
||||
m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
|
||||
m_pendingFriendRequests.Remove(transactionID);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnTerminateFriendship(IClientAPI client, LLUUID agent, LLUUID exfriendID)
|
||||
{
|
||||
m_scene.StoreRemoveFriendship(agent, exfriendID);
|
||||
// TODO: Inform the client that the ExFriend is offline
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void OnGridInstantMessage(GridInstantMessage msg)
|
||||
{
|
||||
// Trigger the above event handler
|
||||
OnInstantMessage(new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
|
||||
new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
|
||||
msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
|
||||
new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
|
||||
msg.binaryBucket);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
private void FormFriendship(IClientAPI client, Guid friend)
|
||||
{
|
||||
foreach (Scene scene in m_scenes)
|
||||
{
|
||||
if (scene.Entities.ContainsKey(client.AgentId) && scene.Entities[client.AgentId] is ScenePresence)
|
||||
{
|
||||
OnlineNotificationPacket ONPack = new OnlineNotificationPacket();
|
||||
OnlineNotificationPacket.AgentBlockBlock[] AgentBlock = new OnlineNotificationPacket.AgentBlockBlock[1];
|
||||
|
||||
AgentBlock[0] = new OnlineNotificationPacket.AgentBlockBlock();
|
||||
AgentBlock[0].AgentID = new LLUUID(friend);
|
||||
ONPack.AgentBlock = AgentBlock;
|
||||
client.OutPacket(ONPack,ThrottleOutPacketType.Task);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void Close()
|
||||
{
|
||||
@@ -93,7 +220,7 @@ namespace OpenSim.Region.Environment.Modules
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
m_scenes.Add(scene);
|
||||
scene.EventManager.OnNewClient += OnNewClient;
|
||||
scene.EventManager.OnGridInstantMessageToIMModule += OnGridInstantMessage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,19 +68,29 @@ namespace OpenSim.Region.Environment.Modules
|
||||
uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
|
||||
byte[] binaryBucket)
|
||||
{
|
||||
foreach (Scene scene in m_scenes)
|
||||
|
||||
bool FriendDialog = ((dialog == (byte)38) || (dialog == (byte)39) || (dialog == (byte)40));
|
||||
|
||||
// IM dialogs need to be pre-processed and have their sessionID filled by the server
|
||||
// so the sim can match the transaction on the return packet.
|
||||
|
||||
// Don't send a Friend Dialog IM with a LLUUID.Zero session.
|
||||
if (!(FriendDialog && imSessionID == LLUUID.Zero))
|
||||
{
|
||||
if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
|
||||
foreach (Scene scene in m_scenes)
|
||||
{
|
||||
// Local message
|
||||
ScenePresence user = (ScenePresence) scene.Entities[toAgentID];
|
||||
if (!user.IsChildAgent)
|
||||
if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
|
||||
{
|
||||
user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
|
||||
toAgentID, imSessionID, fromAgentName, dialog,
|
||||
timestamp);
|
||||
// Message sent
|
||||
return;
|
||||
// Local message
|
||||
ScenePresence user = (ScenePresence)scene.Entities[toAgentID];
|
||||
if (!user.IsChildAgent)
|
||||
{
|
||||
user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
|
||||
toAgentID, imSessionID, fromAgentName, dialog,
|
||||
timestamp);
|
||||
// Message sent
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,6 +98,20 @@ namespace OpenSim.Region.Environment.Modules
|
||||
// Still here, try send via Grid
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Trusty OSG1 called method. This method also gets called from the FriendsModule
|
||||
// Turns out the sim has to send an instant message to the user to get it to show an accepted friend.
|
||||
|
||||
private void OnGridInstantMessage(GridInstantMessage msg)
|
||||
{
|
||||
// Trigger the above event handler
|
||||
OnInstantMessage(new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
|
||||
new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
|
||||
msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
|
||||
new LLVector3(msg.Position.x,msg.Position.y,msg.Position.z), new LLUUID(msg.RegionID),
|
||||
msg.binaryBucket);
|
||||
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
|
||||
@@ -1625,6 +1625,8 @@ namespace OpenSim.Region.Environment.Scenes
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Other Methods
|
||||
@@ -1699,6 +1701,45 @@ namespace OpenSim.Region.Environment.Scenes
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is a way for the Friends Module to create an instant
|
||||
/// message to the avatar and for Instant Messages that travel across
|
||||
/// gridcomms to make it to the Instant Message Module.
|
||||
///
|
||||
/// Friendship establishment and groups are unfortunately tied with instant messaging and
|
||||
/// there's no way to separate them completely.
|
||||
/// </summary>
|
||||
/// <param name="message">object containing the instant message data</param>
|
||||
/// <returns>void</returns>
|
||||
public void TriggerGridInstantMessage(GridInstantMessage message,InstantMessageReceiver options)
|
||||
{
|
||||
m_eventManager.TriggerGridInstantMessage(message,options);
|
||||
}
|
||||
|
||||
|
||||
public virtual void StoreAddFriendship(LLUUID ownerID, LLUUID friendID, uint perms)
|
||||
{
|
||||
// TODO: m_sceneGridService.DoStuff;
|
||||
CommsManager.AddNewUserFriend(ownerID, friendID, perms);
|
||||
}
|
||||
|
||||
public virtual void StoreUpdateFriendship(LLUUID ownerID, LLUUID friendID, uint perms)
|
||||
{
|
||||
// TODO: m_sceneGridService.DoStuff;
|
||||
CommsManager.UpdateUserFriendPerms(ownerID, friendID, perms);
|
||||
}
|
||||
|
||||
public virtual void StoreRemoveFriendship(LLUUID ownerID, LLUUID ExfriendID)
|
||||
{
|
||||
// TODO: m_sceneGridService.DoStuff;
|
||||
CommsManager.RemoveUserFriend(ownerID, ExfriendID);
|
||||
}
|
||||
public virtual List<FriendListItem> StoreGetFriendsForUser(LLUUID ownerID)
|
||||
{
|
||||
// TODO: m_sceneGridService.DoStuff;
|
||||
return CommsManager.GetUserFriendList(ownerID);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Console Commands
|
||||
|
||||
@@ -27,12 +27,14 @@
|
||||
*/
|
||||
|
||||
using libsecondlife;
|
||||
using System;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.LandManagement;
|
||||
|
||||
namespace OpenSim.Region.Environment.Scenes
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// A class for triggering remote scene events.
|
||||
/// </summary>
|
||||
@@ -115,6 +117,16 @@ namespace OpenSim.Region.Environment.Scenes
|
||||
public event AvatarEnteringNewParcel OnAvatarEnteringNewParcel;
|
||||
|
||||
|
||||
public delegate void NewGridInstantMessage(GridInstantMessage message);
|
||||
|
||||
public event NewGridInstantMessage OnGridInstantMessageToIMModule;
|
||||
|
||||
public event NewGridInstantMessage OnGridInstantMessageToFriendsModule;
|
||||
|
||||
public event NewGridInstantMessage OnGridInstantMessageToGroupsModule;
|
||||
|
||||
|
||||
|
||||
public void TriggerOnClientMovement(ScenePresence avatar)
|
||||
{
|
||||
if (OnClientMovement != null)
|
||||
@@ -265,5 +277,29 @@ namespace OpenSim.Region.Environment.Scenes
|
||||
OnAvatarEnteringNewParcel(avatar, localLandID, regionID);
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>Used to pass instnat messages around between the Scene, the Friends Module and the Instant Messsage Module</summary>
|
||||
///<param name="message">Object containing the Instant Message Data</param>
|
||||
///<param name="whichModule">A bit vector containing the modules to send the message to</param>
|
||||
public void TriggerGridInstantMessage(GridInstantMessage message, InstantMessageReceiver whichModule)
|
||||
{
|
||||
if ((whichModule & InstantMessageReceiver.IMModule) != 0)
|
||||
{
|
||||
|
||||
if (OnGridInstantMessageToIMModule != null)
|
||||
{
|
||||
OnGridInstantMessageToIMModule(message);
|
||||
}
|
||||
}
|
||||
if ((whichModule & InstantMessageReceiver.FriendsModule) != 0)
|
||||
{
|
||||
if (OnGridInstantMessageToFriendsModule != null)
|
||||
{
|
||||
OnGridInstantMessageToFriendsModule(message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user