* Refactor: Move some code into separate methods in FriendsModule
parent
06f74e4295
commit
e0b7ad7677
|
@ -382,10 +382,28 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
|
|||
{
|
||||
// Friend Requests go by Instant Message.. using the dialog param
|
||||
// https://wiki.secondlife.com/wiki/ImprovedInstantMessage
|
||||
UUID fromAgentID = new UUID(im.fromAgentID);
|
||||
UUID toAgentID = new UUID(im.toAgentID);
|
||||
|
||||
if (im.dialog == (byte)InstantMessageDialog.FriendshipOffered) // 38
|
||||
{
|
||||
FriendshipOffered(client, im);
|
||||
}
|
||||
else if (im.dialog == (byte)InstantMessageDialog.FriendshipAccepted) // 39
|
||||
{
|
||||
FriendshipAccepted(client, im);
|
||||
}
|
||||
else if (im.dialog == (byte)InstantMessageDialog.FriendshipDeclined) // 40
|
||||
{
|
||||
FriendshipDeclined(client, im);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a user offers a friendship.
|
||||
/// </summary>
|
||||
/// May not currently be used - see OnApproveFriendRequest() instead
|
||||
/// <param name="im"></param>
|
||||
/// <param name="client"></param>
|
||||
private void FriendshipOffered(IClientAPI client, GridInstantMessage im)
|
||||
{
|
||||
// this is triggered by the initiating agent:
|
||||
// A local agent offers friendship to some possibly remote friend.
|
||||
|
@ -394,7 +412,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
|
|||
// some properties are misused here:
|
||||
// fromAgentName is the *destination* name (the friend we offer friendship to)
|
||||
|
||||
m_log.InfoFormat("[FRIEND]: Offer(38) - From: {0}, FromName: {1} To: {2}, Session: {3}, Message: {4}, Offline {5}",
|
||||
m_log.DebugFormat("[FRIEND]: Offer(38) - From: {0}, FromName: {1} To: {2}, Session: {3}, Message: {4}, Offline {5}",
|
||||
im.fromAgentID, im.fromAgentName, im.toAgentID, im.imSessionID, im.message, im.offline);
|
||||
|
||||
// 1.20 protocol sends an UUID in the message field, instead of the friendship offer text.
|
||||
|
@ -412,20 +430,36 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
|
|||
// If new friend is local, it will send an IM to the viewer.
|
||||
// If new friend is remote, it will cause a OnGridInstantMessage on the remote server
|
||||
m_TransferModule.SendInstantMessage(im,
|
||||
delegate(bool success) {
|
||||
delegate(bool success)
|
||||
{
|
||||
m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (im.dialog == (byte)InstantMessageDialog.FriendshipAccepted) // 39
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a user accepts a friendship offer.
|
||||
/// </summary>
|
||||
/// <param name="im"></param>
|
||||
/// <param name="client"></param>
|
||||
private void FriendshipAccepted(IClientAPI client, GridInstantMessage im)
|
||||
{
|
||||
m_log.DebugFormat("[FRIEND]: 39 - from client {0}, agent {2} {3}, imsession {4} to {5}: {6} (dialog {7})",
|
||||
client.AgentId, im.fromAgentID, im.fromAgentName, im.imSessionID, im.toAgentID, im.message, im.dialog);
|
||||
|
||||
}
|
||||
else if (im.dialog == (byte)InstantMessageDialog.FriendshipDeclined) // 40
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a user declines a friendship offer.
|
||||
/// </summary>
|
||||
/// May not currently be used - see OnDenyFriendRequest() instead
|
||||
/// <param name="im"></param>
|
||||
/// <param name="client"></param>
|
||||
private void FriendshipDeclined(IClientAPI client, GridInstantMessage im)
|
||||
{
|
||||
UUID fromAgentID = new UUID(im.fromAgentID);
|
||||
UUID toAgentID = new UUID(im.toAgentID);
|
||||
|
||||
// declining the friendship offer causes a type 40 IM being sent to the (possibly remote) initiator
|
||||
// toAgentID is initiator, fromAgentID declined friendship
|
||||
m_log.DebugFormat("[FRIEND]: 40 - from client {0}, agent {1} {2}, imsession {3} to {4}: {5} (dialog {6})",
|
||||
|
@ -435,6 +469,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
|
|||
// Send the decline to whoever is the destination.
|
||||
GridInstantMessage msg = new GridInstantMessage(client.Scene, fromAgentID, client.Name, toAgentID,
|
||||
im.dialog, im.message, im.offline != 0, im.Position);
|
||||
|
||||
// If new friend is local, it will send an IM to the viewer.
|
||||
// If new friend is remote, it will cause a OnGridInstantMessage on the remote server
|
||||
m_TransferModule.SendInstantMessage(msg,
|
||||
|
@ -443,7 +478,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
|
|||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGridInstantMessage(GridInstantMessage msg)
|
||||
{
|
||||
|
@ -467,11 +501,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
|
|||
if (msg.dialog == (byte)InstantMessageDialog.FriendshipAccepted)
|
||||
{
|
||||
// for accept friendship, we have to do a bit more
|
||||
approveFriendship(new UUID(msg.fromAgentID), new UUID(msg.toAgentID), msg.fromAgentName);
|
||||
ApproveFriendship(new UUID(msg.fromAgentID), new UUID(msg.toAgentID), msg.fromAgentName);
|
||||
}
|
||||
}
|
||||
|
||||
private void approveFriendship(UUID fromAgentID, UUID toAgentID, string fromName)
|
||||
private void ApproveFriendship(UUID fromAgentID, UUID toAgentID, string fromName)
|
||||
{
|
||||
m_log.DebugFormat("[FRIEND]: Approve friendship from {0} (ID: {1}) to {2}",
|
||||
fromAgentID, fromName, toAgentID);
|
||||
|
@ -537,7 +571,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
|
|||
friendPresence.ControllingClient.SendInstantMessage(agentID, agentID.ToString(), friendID, client.Name,
|
||||
(byte)InstantMessageDialog.FriendshipAccepted,
|
||||
(uint)Util.UnixTimeSinceEpoch());
|
||||
approveFriendship(agentID, friendID, client.Name);
|
||||
ApproveFriendship(agentID, friendID, client.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue