* This enables grid-wide instant messaging in a peer to peer with tracker style way over XMLRPC.
* Friend status updates are still only local, so you still won't know before instant messaging someone if they're online. * The server each user is on and the user server must be updated or the instant message won't get to the destination.0.6.0-stable
parent
d20cae2d03
commit
e0b821f875
|
@ -133,7 +133,7 @@ namespace OpenSim.Grid.UserServer
|
|||
m_httpServer.AddXmlRPCHandler("update_avatar_appearance", m_userManager.XmlRPCUpdateAvatarAppearance);
|
||||
m_httpServer.AddXmlRPCHandler("update_user_current_region", m_userManager.XmlRPCAtRegion);
|
||||
m_httpServer.AddXmlRPCHandler("logout_of_simulator", m_userManager.XmlRPCLogOffUserMethodUUID);
|
||||
|
||||
m_httpServer.AddXmlRPCHandler("get_agent_by_uuid", m_userManager.XmlRPCGetAgentMethodUUID);
|
||||
// Message Server ---> User Server
|
||||
m_httpServer.AddXmlRPCHandler("register_messageserver", m_messagesService.XmlRPCRegisterMessageServer);
|
||||
m_httpServer.AddXmlRPCHandler("agent_change_region", m_messagesService.XmlRPCUserMovedtoRegion);
|
||||
|
|
|
@ -466,7 +466,7 @@ namespace OpenSim.Grid.UserServer
|
|||
return CreateUnknownUserErrorResponse();
|
||||
}
|
||||
|
||||
return ProfileToXmlRPCResponse(userProfile);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -161,11 +161,24 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
if (gridmode)
|
||||
{
|
||||
// Still here, try send via Grid
|
||||
// TODO
|
||||
|
||||
// don't send session drop yet, as it's not reliable somehow.
|
||||
if (dialog != (byte)InstantMessageDialog.SessionDrop)
|
||||
{
|
||||
SendGridInstantMessageViaXMLRPC(client, fromAgentID,
|
||||
fromAgentSession, toAgentID,
|
||||
imSessionID, timestamp, fromAgentName,
|
||||
message, dialog, fromGroup, offline,
|
||||
ParentEstateID, Position, RegionID,
|
||||
binaryBucket, getLocalRegionHandleFromUUID(RegionID), 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (client != null)
|
||||
{
|
||||
if (dialog != (byte)InstantMessageDialog.StartTyping && dialog != (byte)InstantMessageDialog.StopTyping && dialog != (byte)InstantMessageDialog.SessionDrop)
|
||||
client.SendInstantMessage(toAgentID, fromAgentSession, "Unable to send instant message", fromAgentID, imSessionID, "System", (byte)InstantMessageDialog.BusyAutoResponse, (uint)Util.UnixTimeSinceEpoch());// SendAlertMessage("Unable to send instant message");
|
||||
client.SendInstantMessage(toAgentID, fromAgentSession, "Unable to send instant message. User is not logged in.", fromAgentID, imSessionID, "System", (byte)InstantMessageDialog.BusyAutoResponse, (uint)Util.UnixTimeSinceEpoch());// SendAlertMessage("Unable to send instant message");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -175,7 +188,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
|
||||
// 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.
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
private void OnGridInstantMessage(GridInstantMessage msg)
|
||||
{
|
||||
// Trigger the above event handler
|
||||
|
@ -185,6 +201,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
|
||||
msg.binaryBucket);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Process a XMLRPC Grid Instant Message
|
||||
/// </summary>
|
||||
/// <param name="request">XMLRPC parameters from_agent_id from_agent_session to_agent_id im_session_id timestamp
|
||||
/// from_agent_name message dialog from_group offline parent_estate_id position_x position_y position_z region_id
|
||||
/// binary_bucket region_handle</param>
|
||||
/// <returns>Nothing much</returns>
|
||||
protected virtual XmlRpcResponse processXMLRPCGridInstantMessage(XmlRpcRequest request)
|
||||
{
|
||||
bool successful = false;
|
||||
|
@ -207,11 +232,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
float pos_x = 0;
|
||||
float pos_y = 0;
|
||||
float pos_z = 0;
|
||||
|
||||
//m_log.Info("Processing IM");
|
||||
|
||||
|
||||
Hashtable requestData = (Hashtable)request.Params[0];
|
||||
|
||||
// Check if it's got all the data
|
||||
if (requestData.ContainsKey("from_agent_id") && requestData.ContainsKey("from_agent_session")
|
||||
&& requestData.ContainsKey("to_agent_id") && requestData.ContainsKey("im_session_id")
|
||||
&& requestData.ContainsKey("timestamp") && requestData.ContainsKey("from_agent_name")
|
||||
|
@ -222,6 +247,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
&& requestData.ContainsKey("position_z") && requestData.ContainsKey("region_id")
|
||||
&& requestData.ContainsKey("binary_bucket") && requestData.ContainsKey("region_handle"))
|
||||
{
|
||||
// Do the easy way of validating the UUIDs
|
||||
Helpers.TryParse((string)requestData["from_agent_id"], out fromAgentID);
|
||||
Helpers.TryParse((string)requestData["from_agent_session"], out fromAgentSession);
|
||||
Helpers.TryParse((string)requestData["to_agent_id"], out toAgentID);
|
||||
|
@ -246,12 +272,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
|
||||
fromAgentName = (string)requestData["from_agent_name"];
|
||||
message = (string)requestData["message"];
|
||||
dialog = (byte)requestData["dialog"];
|
||||
|
||||
// Bytes don't transfer well over XMLRPC, so, we Base64 Encode them.
|
||||
byte[] dialogdata = Convert.FromBase64String((string)requestData["dialog"]);
|
||||
dialog = dialogdata[0];
|
||||
|
||||
if ((string)requestData["from_group"] == "TRUE")
|
||||
fromGroup = true;
|
||||
|
||||
offline = (byte)requestData["offline"];
|
||||
byte[] offlinedata = Convert.FromBase64String((string)requestData["offline"]);
|
||||
offline = offlinedata[0];
|
||||
|
||||
# region ParentEstateID
|
||||
try
|
||||
|
@ -316,7 +346,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
# endregion
|
||||
|
||||
Position = new LLVector3(pos_x, pos_y, pos_z);
|
||||
binaryBucket = (byte[])requestData["binary_bucket"];
|
||||
binaryBucket = Convert.FromBase64String((string)requestData["binary_bucket"]);
|
||||
|
||||
// Create a New GridInstantMessageObject the the data
|
||||
GridInstantMessage gim = new GridInstantMessage();
|
||||
gim.fromAgentID = fromAgentID.UUID;
|
||||
gim.fromAgentName = fromAgentName;
|
||||
|
@ -334,6 +366,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
gim.binaryBucket = binaryBucket;
|
||||
|
||||
|
||||
// Trigger the Instant message in the scene.
|
||||
foreach (Scene scene in m_scenes)
|
||||
{
|
||||
if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
|
||||
|
@ -343,13 +376,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
if (!user.IsChildAgent)
|
||||
{
|
||||
scene.EventManager.TriggerGridInstantMessage(gim, InstantMessageReceiver.FriendsModule | InstantMessageReceiver.GroupsModule | InstantMessageReceiver.IMModule);
|
||||
successful = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
OnGridInstantMessage(gim);
|
||||
successful = true;
|
||||
//OnGridInstantMessage(gim);
|
||||
|
||||
}
|
||||
|
||||
//Send response back to region calling if it was successful
|
||||
// calling region uses this to know when to look up a user's location again.
|
||||
XmlRpcResponse resp = new XmlRpcResponse();
|
||||
Hashtable respdata = new Hashtable();
|
||||
if (successful)
|
||||
|
@ -361,12 +397,74 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
return resp;
|
||||
}
|
||||
|
||||
#region Asynchronous setup
|
||||
/// <summary>
|
||||
/// delegate for sending a grid instant message asynchronously
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="fromAgentID"></param>
|
||||
/// <param name="fromAgentSession"></param>
|
||||
/// <param name="toAgentID"></param>
|
||||
/// <param name="imSessionID"></param>
|
||||
/// <param name="timestamp"></param>
|
||||
/// <param name="fromAgentName"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="dialog"></param>
|
||||
/// <param name="fromGroup"></param>
|
||||
/// <param name="offline"></param>
|
||||
/// <param name="ParentEstateID"></param>
|
||||
/// <param name="Position"></param>
|
||||
/// <param name="RegionID"></param>
|
||||
/// <param name="binaryBucket"></param>
|
||||
/// <param name="regionhandle"></param>
|
||||
/// <param name="prevRegionHandle"></param>
|
||||
public delegate void GridInstantMessageDelegate(IClientAPI client, 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, ulong regionhandle, ulong prevRegionHandle);
|
||||
|
||||
private void GridInstantMessageCompleted(IAsyncResult iar)
|
||||
{
|
||||
GridInstantMessageDelegate icon = (GridInstantMessageDelegate)iar.AsyncState;
|
||||
icon.EndInvoke(iar);
|
||||
}
|
||||
|
||||
|
||||
protected virtual void SendGridInstantMessageViaXMLRPC(IClientAPI client, 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, ulong regionhandle, ulong prevRegionHandle)
|
||||
{
|
||||
GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync;
|
||||
|
||||
d.BeginInvoke(client,fromAgentID,
|
||||
fromAgentSession,toAgentID,
|
||||
imSessionID,timestamp, fromAgentName,
|
||||
message, dialog, fromGroup, offline,
|
||||
ParentEstateID, Position, RegionID,
|
||||
binaryBucket, regionhandle, prevRegionHandle,
|
||||
GridInstantMessageCompleted,
|
||||
d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Recursive SendGridInstantMessage over XMLRPC method. The prevRegionHandle contains the last regionhandle tried
|
||||
/// if it's the same as the user's looked up region handle, then we end the recursive loop
|
||||
/// </summary>
|
||||
/// <param name="prevRegionHandle"></param>
|
||||
protected virtual void SendGridInstantMessageViaXMLRPCAsync(IClientAPI client, 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, ulong regionhandle, ulong prevRegionHandle)
|
||||
{
|
||||
UserAgentData upd = null;
|
||||
|
||||
|
@ -389,16 +487,34 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
}
|
||||
}
|
||||
|
||||
// Are we needing to look-up an agent?
|
||||
if (lookupAgent)
|
||||
{
|
||||
// Non-cached user agent lookup.
|
||||
upd = m_scenes[0].CommsManager.UserService.GetAgentByUUID(toAgentID);
|
||||
|
||||
// check if we've tried this before..
|
||||
if (upd.Handle == prevRegionHandle)
|
||||
if (upd != null)
|
||||
{
|
||||
// check if we've tried this before.. This is one way to end the recursive loop
|
||||
if (upd.Handle == prevRegionHandle)
|
||||
{
|
||||
m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
|
||||
if (client != null)
|
||||
{
|
||||
if (dialog != (byte)InstantMessageDialog.StartTyping && dialog != (byte)InstantMessageDialog.StopTyping && dialog != (byte)InstantMessageDialog.SessionDrop)
|
||||
client.SendInstantMessage(toAgentID, fromAgentSession, "Unable to send instant message", fromAgentID, imSessionID, "System", (byte)InstantMessageDialog.BusyAutoResponse, (uint)Util.UnixTimeSinceEpoch());// SendAlertMessage("Unable to send instant message");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
|
||||
if (client != null)
|
||||
client.SendInstantMessage(toAgentID, fromAgentSession, "Unable to send instant message", fromAgentID, imSessionID, "System", (byte)InstantMessageDialog.MessageFromObject,(uint)Util.UnixTimeSinceEpoch());// SendAlertMessage("Unable to send instant message");
|
||||
{
|
||||
if (dialog != (byte)InstantMessageDialog.StartTyping && dialog != (byte)InstantMessageDialog.StopTyping && dialog != (byte)InstantMessageDialog.SessionDrop)
|
||||
client.SendInstantMessage(toAgentID, fromAgentSession, "Unable to send instant message", fromAgentID, imSessionID, "System", (byte)InstantMessageDialog.BusyAutoResponse, (uint)Util.UnixTimeSinceEpoch());// SendAlertMessage("Unable to send instant message");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -431,6 +547,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
bool imresult = doIMSending(reginfo, msgdata);
|
||||
if (imresult)
|
||||
{
|
||||
// IM delivery successful, so store the Agent's location in our local cache.
|
||||
lock (m_userRegionMap)
|
||||
{
|
||||
if (m_userRegionMap.ContainsKey(toAgentID))
|
||||
|
@ -442,12 +559,18 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
m_userRegionMap.Add(toAgentID, upd.Handle);
|
||||
}
|
||||
}
|
||||
m_log.Info("[GRID INSTANT MESSAGE]: Successfully sent a message");
|
||||
//m_log.Info("[GRID INSTANT MESSAGE]: Successfully sent a message");
|
||||
}
|
||||
else
|
||||
{
|
||||
// try again, but lookup user this time.
|
||||
SendGridInstantMessageViaXMLRPC(client, fromAgentID,
|
||||
// Warning, this must call the Async version
|
||||
// of this method or we'll be making thousands of threads
|
||||
// The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
|
||||
// The version that spawns the thread is SendGridInstantMessageViaXMLRPC
|
||||
|
||||
// This is recursive!!!!!
|
||||
SendGridInstantMessageViaXMLRPCAsync(client, fromAgentID,
|
||||
fromAgentSession, toAgentID,
|
||||
imSessionID, timestamp, fromAgentName,
|
||||
message, dialog, fromGroup, offline,
|
||||
|
@ -461,18 +584,27 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
{
|
||||
// send Agent Offline message
|
||||
if (client != null)
|
||||
client.SendInstantMessage(toAgentID, fromAgentSession, "Unable to send instant message", fromAgentID, imSessionID, "System", (byte)InstantMessageDialog.MessageFromObject, (uint)Util.UnixTimeSinceEpoch());// SendAlertMessage("Unable to send instant message");
|
||||
{
|
||||
if (dialog != (byte)InstantMessageDialog.StartTyping && dialog != (byte)InstantMessageDialog.StopTyping && dialog != (byte)InstantMessageDialog.SessionDrop)
|
||||
client.SendInstantMessage(toAgentID, fromAgentSession, "Unable to send instant message: Agent Offline", fromAgentID, imSessionID, "System", (byte)InstantMessageDialog.BusyAutoResponse, (uint)Util.UnixTimeSinceEpoch());// SendAlertMessage("Unable to send instant message");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// send Agent Offline message
|
||||
// send Agent doesn't exist message
|
||||
if (client != null)
|
||||
client.SendInstantMessage(toAgentID, fromAgentSession, "Unable to send instant message", fromAgentID, imSessionID, "System", (byte)InstantMessageDialog.MessageFromObject, (uint)Util.UnixTimeSinceEpoch());// SendAlertMessage("Unable to send instant message");
|
||||
client.SendInstantMessage(toAgentID, fromAgentSession, "Unable to send instant message: Are you sure this agent exists anymore?", fromAgentID, imSessionID, "System", (byte)InstantMessageDialog.MessageFromObject, (uint)Util.UnixTimeSinceEpoch());// SendAlertMessage("Unable to send instant message");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This actually does the XMLRPC Request
|
||||
/// </summary>
|
||||
/// <param name="reginfo">RegionInfo we pull the data out of to send the request to</param>
|
||||
/// <param name="xmlrpcdata">The Instant Message data Hashtable</param>
|
||||
/// <returns>Bool if the message was successfully delivered at the other side.</returns>
|
||||
private bool doIMSending(RegionInfo reginfo, Hashtable xmlrpcdata)
|
||||
{
|
||||
|
||||
|
@ -502,7 +634,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
return false;
|
||||
}
|
||||
}
|
||||
catch (WebException)
|
||||
catch (WebException e)
|
||||
{
|
||||
m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Error sending message to {0} the host didn't respond", "http://" + reginfo.ExternalHostName + ":" + reginfo.HttpPort);
|
||||
}
|
||||
|
@ -510,6 +642,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get ulong region handle for region by it's Region UUID.
|
||||
/// We use region handles over grid comms because there's all sorts of free and cool caching.
|
||||
/// </summary>
|
||||
/// <param name="regionID">UUID of region to get the region handle for</param>
|
||||
/// <returns></returns>
|
||||
private ulong getLocalRegionHandleFromUUID(LLUUID regionID)
|
||||
{
|
||||
ulong returnhandle = 0;
|
||||
|
@ -528,6 +666,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
return returnhandle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes a GridInstantMessage and converts it into a Hashtable for XMLRPC
|
||||
/// </summary>
|
||||
/// <param name="msg">The GridInstantMessage object</param>
|
||||
/// <returns>Hashtable containing the XMLRPC request</returns>
|
||||
private Hashtable ConvertGridInstantMessageToXMLRPC(GridInstantMessage msg)
|
||||
{
|
||||
Hashtable gim = new Hashtable();
|
||||
|
@ -538,20 +681,21 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
|
|||
gim["timestamp"] = msg.timestamp.ToString();
|
||||
gim["from_agent_name"] = msg.fromAgentName;
|
||||
gim["message"] = msg.message;
|
||||
gim["dialog"] = msg.dialog;
|
||||
byte[] dialogdata = new byte[1];dialogdata[0] = msg.dialog;
|
||||
gim["dialog"] = Convert.ToBase64String(dialogdata,Base64FormattingOptions.None);
|
||||
|
||||
if (msg.fromGroup)
|
||||
gim["from_group"] = "TRUE";
|
||||
else
|
||||
gim["from_group"] = "FALSE";
|
||||
|
||||
gim["offline"] = msg.offline;
|
||||
byte[] offlinedata = new byte[1]; offlinedata[0] = msg.offline;
|
||||
gim["offline"] = Convert.ToBase64String(offlinedata, Base64FormattingOptions.None);
|
||||
gim["parent_estate_id"] = msg.ParentEstateID.ToString();
|
||||
gim["position_x"] = msg.Position.x.ToString();
|
||||
gim["position_y"] = msg.Position.y.ToString();
|
||||
gim["position_z"] = msg.Position.z.ToString();
|
||||
gim["region_id"] = msg.RegionID.ToString();
|
||||
gim["binary_bucket"] = msg.binaryBucket;
|
||||
gim["binary_bucket"] = Convert.ToBase64String(msg.binaryBucket,Base64FormattingOptions.None);
|
||||
return gim;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue