2008-09-27 18:33:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) Contributors, http://opensimulator.org/
|
|
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2009-06-01 06:37:14 +00:00
|
|
|
* * Neither the name of the OpenSimulator Project nor the
|
2008-09-27 18:33:54 +00:00
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2009-01-02 20:22:35 +00:00
|
|
|
|
2009-02-12 18:59:45 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Net;
|
|
|
|
using System.Reflection;
|
2017-06-06 20:55:47 +00:00
|
|
|
using System.Text;
|
2009-02-12 18:59:45 +00:00
|
|
|
using log4net;
|
|
|
|
using Nini.Config;
|
2011-04-30 20:24:25 +00:00
|
|
|
using Mono.Addins;
|
2009-02-12 18:59:45 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
using OpenMetaverse.StructuredData;
|
|
|
|
using OpenSim.Framework;
|
2009-05-04 20:15:39 +00:00
|
|
|
using OpenSim.Framework.Servers.HttpServer;
|
2009-02-12 18:59:45 +00:00
|
|
|
using OpenSim.Region.Framework.Interfaces;
|
|
|
|
using OpenSim.Region.Framework.Scenes;
|
2009-06-18 14:33:35 +00:00
|
|
|
using Caps=OpenSim.Framework.Capabilities.Caps;
|
2008-09-27 09:42:31 +00:00
|
|
|
|
2011-04-30 16:24:15 +00:00
|
|
|
namespace OpenSim.Region.ClientStack.Linden
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
2008-09-27 22:05:36 +00:00
|
|
|
public struct QueueItem
|
|
|
|
{
|
|
|
|
public int id;
|
2008-11-19 06:25:34 +00:00
|
|
|
public OSDMap body;
|
2008-09-27 22:05:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 02:08:02 +00:00
|
|
|
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EventQueueGetModule")]
|
2020-05-07 01:26:25 +00:00
|
|
|
public partial class EventQueueGetModule : IEventQueue, INonSharedRegionModule
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
|
|
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
2014-01-12 06:00:24 +00:00
|
|
|
private static string LogHeader = "[EVENT QUEUE GET MODULE]";
|
2011-11-24 20:27:11 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
private const int KEEPALIVE = 60; // this could be larger now, but viewers expect it on opensim
|
|
|
|
// we need to go back to close before viwers, or we may lose data
|
|
|
|
private const int VIEWERKEEPALIVE = (KEEPALIVE - 1) * 1000; // do it shorter
|
|
|
|
|
2011-11-24 20:27:11 +00:00
|
|
|
/// <value>
|
|
|
|
/// Debug level.
|
|
|
|
/// </value>
|
|
|
|
public int DebugLevel { get; set; }
|
|
|
|
|
|
|
|
protected Scene m_scene;
|
2017-01-05 19:07:37 +00:00
|
|
|
|
2008-09-27 22:05:36 +00:00
|
|
|
private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>();
|
2008-09-27 09:42:31 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
private Dictionary<UUID, Queue<byte[]>> queues = new Dictionary<UUID, Queue<byte[]>>();
|
2008-10-01 04:16:41 +00:00
|
|
|
private Dictionary<UUID, UUID> m_AvatarQueueUUIDMapping = new Dictionary<UUID, UUID>();
|
2017-01-05 19:07:37 +00:00
|
|
|
|
2012-11-10 16:48:31 +00:00
|
|
|
#region INonSharedRegionModule methods
|
|
|
|
public virtual void Initialise(IConfigSource config)
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
2012-11-10 16:48:31 +00:00
|
|
|
}
|
2008-09-27 23:06:28 +00:00
|
|
|
|
2012-11-10 16:48:31 +00:00
|
|
|
public void AddRegion(Scene scene)
|
|
|
|
{
|
|
|
|
m_scene = scene;
|
|
|
|
scene.RegisterModuleInterface<IEventQueue>(this);
|
|
|
|
|
|
|
|
scene.EventManager.OnClientClosed += ClientClosed;
|
|
|
|
scene.EventManager.OnRegisterCaps += OnRegisterCaps;
|
|
|
|
|
|
|
|
MainConsole.Instance.Commands.AddCommand(
|
|
|
|
"Debug",
|
|
|
|
false,
|
|
|
|
"debug eq",
|
|
|
|
"debug eq [0|1|2]",
|
|
|
|
"Turn on event queue debugging\n"
|
|
|
|
+ " <= 0 - turns off all event queue logging\n"
|
2014-08-04 23:49:17 +00:00
|
|
|
+ " >= 1 - turns on event queue setup and outgoing event logging\n"
|
2012-11-10 16:48:31 +00:00
|
|
|
+ " >= 2 - turns on poll notification",
|
|
|
|
HandleDebugEq);
|
2013-03-28 01:36:34 +00:00
|
|
|
|
|
|
|
MainConsole.Instance.Commands.AddCommand(
|
|
|
|
"Debug",
|
|
|
|
false,
|
|
|
|
"show eq",
|
|
|
|
"show eq",
|
|
|
|
"Show contents of event queues for logged in avatars. Used for debugging.",
|
|
|
|
HandleShowEq);
|
2008-09-27 09:42:31 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 16:48:31 +00:00
|
|
|
public void RemoveRegion(Scene scene)
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
2012-11-10 16:48:31 +00:00
|
|
|
if (m_scene != scene)
|
|
|
|
return;
|
|
|
|
|
|
|
|
scene.EventManager.OnClientClosed -= ClientClosed;
|
|
|
|
scene.EventManager.OnRegisterCaps -= OnRegisterCaps;
|
|
|
|
|
|
|
|
scene.UnregisterModuleInterface<IEventQueue>(this);
|
|
|
|
m_scene = null;
|
2008-09-27 09:42:31 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 16:48:31 +00:00
|
|
|
public void RegionLoaded(Scene scene)
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-03-19 07:06:30 +00:00
|
|
|
public virtual void Close()
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-03-19 07:06:30 +00:00
|
|
|
public virtual string Name
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
|
|
|
get { return "EventQueueGetModule"; }
|
|
|
|
}
|
|
|
|
|
2012-11-10 16:48:31 +00:00
|
|
|
public Type ReplaceableInterface
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
2012-11-10 16:48:31 +00:00
|
|
|
get { return null; }
|
2008-09-27 09:42:31 +00:00
|
|
|
}
|
2012-11-10 16:48:31 +00:00
|
|
|
|
2008-09-27 09:42:31 +00:00
|
|
|
#endregion
|
|
|
|
|
2011-11-24 20:27:11 +00:00
|
|
|
protected void HandleDebugEq(string module, string[] args)
|
|
|
|
{
|
|
|
|
int debugLevel;
|
|
|
|
|
|
|
|
if (!(args.Length == 3 && int.TryParse(args[2], out debugLevel)))
|
|
|
|
{
|
2019-08-20 22:28:59 +00:00
|
|
|
MainConsole.Instance.Output("Usage: debug eq [0|1|2]");
|
2011-11-24 20:27:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DebugLevel = debugLevel;
|
2019-08-20 22:28:59 +00:00
|
|
|
MainConsole.Instance.Output(
|
2020-05-07 01:26:25 +00:00
|
|
|
"Set event queue debug level to {0} in {1}", DebugLevel, m_scene.RegionInfo.RegionName);
|
2011-11-24 20:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 01:36:34 +00:00
|
|
|
protected void HandleShowEq(string module, string[] args)
|
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
MainConsole.Instance.Output("Events in Scene {0} agents queues :", m_scene.Name);
|
2013-03-28 01:36:34 +00:00
|
|
|
|
|
|
|
lock (queues)
|
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
foreach (KeyValuePair<UUID, Queue<byte[]>> kvp in queues)
|
2013-03-28 01:36:34 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
MainConsole.Instance.Output(" {0} {1}", kvp.Key, kvp.Value.Count);
|
2013-03-28 01:36:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-19 20:31:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Always returns a valid queue
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="agentId"></param>
|
|
|
|
/// <returns></returns>
|
2020-05-07 01:26:25 +00:00
|
|
|
private Queue<byte[]> TryGetQueue(UUID agentId)
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
2008-10-10 13:46:43 +00:00
|
|
|
lock (queues)
|
2008-09-27 18:33:54 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
Queue<byte[]> queue;
|
|
|
|
if (queues.TryGetValue(agentId, out queue))
|
|
|
|
return queue;
|
|
|
|
|
|
|
|
if (DebugLevel > 0)
|
|
|
|
m_log.DebugFormat(
|
|
|
|
"[EVENTQUEUE]: Adding new queue for agent {0} in region {1}",
|
|
|
|
agentId, m_scene.RegionInfo.RegionName);
|
|
|
|
|
|
|
|
queue = new Queue<byte[]>();
|
|
|
|
queues[agentId] = queue;
|
|
|
|
|
|
|
|
return queue;
|
2008-09-27 18:33:54 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-27 09:42:31 +00:00
|
|
|
|
2008-12-19 20:31:32 +00:00
|
|
|
/// <summary>
|
2015-09-02 18:54:53 +00:00
|
|
|
|
2008-12-19 20:31:32 +00:00
|
|
|
/// May return a null queue
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="agentId"></param>
|
|
|
|
/// <returns></returns>
|
2020-05-07 01:26:25 +00:00
|
|
|
private Queue<byte[]> GetQueue(UUID agentId)
|
2008-12-19 20:31:32 +00:00
|
|
|
{
|
|
|
|
lock (queues)
|
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
if (queues.TryGetValue(agentId, out Queue<byte[]> queue))
|
|
|
|
return queue;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#region IEventQueue Members
|
|
|
|
//legacy
|
|
|
|
public bool Enqueue(OSD data, UUID avatarID)
|
|
|
|
{
|
|
|
|
//m_log.DebugFormat("[EVENTQUEUE]: Enqueuing event for {0} in region {1}", avatarID, m_scene.RegionInfo.RegionName);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Queue<byte[]> queue = GetQueue(avatarID);
|
|
|
|
if (queue != null)
|
2008-12-19 20:31:32 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
byte[] evData = Util.UTF8NBGetbytes(OSDParser.SerializeLLSDInnerXmlString(data));
|
|
|
|
lock (queue)
|
|
|
|
queue.Enqueue(evData);
|
2008-12-19 20:31:32 +00:00
|
|
|
}
|
|
|
|
else
|
2020-05-07 01:26:25 +00:00
|
|
|
{
|
|
|
|
m_log.WarnFormat(
|
|
|
|
"[EVENTQUEUE]: (Enqueue) No queue found for agent {0} in region {1}",
|
|
|
|
avatarID, m_scene.Name);
|
|
|
|
}
|
2008-12-19 20:31:32 +00:00
|
|
|
}
|
2020-05-07 01:26:25 +00:00
|
|
|
catch (NullReferenceException e)
|
|
|
|
{
|
|
|
|
m_log.Error("[EVENTQUEUE] Caught exception: " + e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2008-12-19 20:31:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
//legacy
|
|
|
|
/*
|
|
|
|
public bool Enqueue(string ev, UUID avatarID)
|
2008-09-27 18:33:54 +00:00
|
|
|
{
|
2009-01-06 21:39:55 +00:00
|
|
|
//m_log.DebugFormat("[EVENTQUEUE]: Enqueuing event for {0} in region {1}", avatarID, m_scene.RegionInfo.RegionName);
|
2008-10-10 14:46:01 +00:00
|
|
|
try
|
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
Queue<byte[]> queue = GetQueue(avatarID);
|
2008-12-19 20:31:32 +00:00
|
|
|
if (queue != null)
|
This should fix all issues with teleports. One should be able to TP as fast as needed. (Although sometimes Justin's state machine kicks in and doesn't let you) The EventQueues are a hairy mess, and it's very easy to mess things up. But it looks like this commit makes them work right. Here's what's going on:
- Child and root agents are only closed after 15 sec, maybe
- If the user comes back, they aren't closed, and everything is reused
- On the receiving side, clients and scene presences are reused if they already exist
- Caps are always recreated (this is where I spent most of my time!). It turns out that, because the agents carry the seeds around, the seed gets the same URL, except for the root agent coming back to a far away region, which gets a new seed (because we don't know what was its seed in the departing region, and we can't send it back to the client when the agent returns there).
2013-07-26 06:44:58 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
byte[] evData = Util.UTF8NBGetbytes(ev);
|
2011-09-24 00:10:23 +00:00
|
|
|
lock (queue)
|
2020-05-07 01:26:25 +00:00
|
|
|
queue.Enqueue(evData);
|
This should fix all issues with teleports. One should be able to TP as fast as needed. (Although sometimes Justin's state machine kicks in and doesn't let you) The EventQueues are a hairy mess, and it's very easy to mess things up. But it looks like this commit makes them work right. Here's what's going on:
- Child and root agents are only closed after 15 sec, maybe
- If the user comes back, they aren't closed, and everything is reused
- On the receiving side, clients and scene presences are reused if they already exist
- Caps are always recreated (this is where I spent most of my time!). It turns out that, because the agents carry the seeds around, the seed gets the same URL, except for the root agent coming back to a far away region, which gets a new seed (because we don't know what was its seed in the departing region, and we can't send it back to the client when the agent returns there).
2013-07-26 06:44:58 +00:00
|
|
|
}
|
2015-09-03 17:39:08 +00:00
|
|
|
else
|
2013-08-12 18:38:23 +00:00
|
|
|
{
|
2019-01-28 04:01:09 +00:00
|
|
|
m_log.WarnFormat(
|
2019-04-16 14:31:31 +00:00
|
|
|
"[EVENTQUEUE]: (Enqueue) No queue found for agent {0} in region {1}",
|
2019-01-28 04:01:09 +00:00
|
|
|
avatarID, m_scene.Name);
|
2013-08-12 18:38:23 +00:00
|
|
|
}
|
2017-01-05 19:07:37 +00:00
|
|
|
}
|
2011-09-24 00:10:23 +00:00
|
|
|
catch (NullReferenceException e)
|
2008-10-10 14:46:01 +00:00
|
|
|
{
|
2009-01-06 21:39:55 +00:00
|
|
|
m_log.Error("[EVENTQUEUE] Caught exception: " + e);
|
2008-10-10 14:46:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-07 01:26:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
*/
|
2017-01-05 19:07:37 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
public bool Enqueue(byte[] evData, UUID avatarID)
|
|
|
|
{
|
|
|
|
//m_log.DebugFormat("[EVENTQUEUE]: Enqueuing event for {0} in region {1}", avatarID, m_scene.RegionInfo.RegionName);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Queue<byte[]> queue = GetQueue(avatarID);
|
|
|
|
if (queue != null)
|
|
|
|
{
|
|
|
|
lock (queue)
|
|
|
|
queue.Enqueue(evData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_log.WarnFormat(
|
|
|
|
"[EVENTQUEUE]: (Enqueue) No queue found for agent {0} in region {1}",
|
|
|
|
avatarID, m_scene.Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (NullReferenceException e)
|
|
|
|
{
|
|
|
|
m_log.Error("[EVENTQUEUE] Caught exception: " + e);
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-27 18:33:54 +00:00
|
|
|
return true;
|
2008-09-27 09:42:31 +00:00
|
|
|
}
|
2008-12-19 20:31:32 +00:00
|
|
|
|
2008-09-27 09:42:31 +00:00
|
|
|
#endregion
|
|
|
|
|
2012-05-17 23:38:29 +00:00
|
|
|
private void ClientClosed(UUID agentID, Scene scene)
|
2008-09-27 09:42:31 +00:00
|
|
|
{
|
This should fix all issues with teleports. One should be able to TP as fast as needed. (Although sometimes Justin's state machine kicks in and doesn't let you) The EventQueues are a hairy mess, and it's very easy to mess things up. But it looks like this commit makes them work right. Here's what's going on:
- Child and root agents are only closed after 15 sec, maybe
- If the user comes back, they aren't closed, and everything is reused
- On the receiving side, clients and scene presences are reused if they already exist
- Caps are always recreated (this is where I spent most of my time!). It turns out that, because the agents carry the seeds around, the seed gets the same URL, except for the root agent coming back to a far away region, which gets a new seed (because we don't know what was its seed in the departing region, and we can't send it back to the client when the agent returns there).
2013-07-26 06:44:58 +00:00
|
|
|
//m_log.DebugFormat("[EVENTQUEUE]: Closed client {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
|
2008-12-22 06:10:36 +00:00
|
|
|
|
2008-10-10 13:46:43 +00:00
|
|
|
lock (queues)
|
2019-01-28 04:01:09 +00:00
|
|
|
{
|
2012-05-17 23:38:29 +00:00
|
|
|
queues.Remove(agentID);
|
2011-10-24 22:16:03 +00:00
|
|
|
|
2019-01-28 04:01:09 +00:00
|
|
|
lock (m_AvatarQueueUUIDMapping)
|
|
|
|
m_AvatarQueueUUIDMapping.Remove(agentID);
|
2013-07-15 23:05:45 +00:00
|
|
|
|
2019-01-28 04:01:09 +00:00
|
|
|
lock (m_ids)
|
2014-07-25 12:03:40 +00:00
|
|
|
m_ids.Remove(agentID);
|
2008-10-03 09:53:49 +00:00
|
|
|
}
|
2008-09-27 09:42:31 +00:00
|
|
|
|
This should fix all issues with teleports. One should be able to TP as fast as needed. (Although sometimes Justin's state machine kicks in and doesn't let you) The EventQueues are a hairy mess, and it's very easy to mess things up. But it looks like this commit makes them work right. Here's what's going on:
- Child and root agents are only closed after 15 sec, maybe
- If the user comes back, they aren't closed, and everything is reused
- On the receiving side, clients and scene presences are reused if they already exist
- Caps are always recreated (this is where I spent most of my time!). It turns out that, because the agents carry the seeds around, the seed gets the same URL, except for the root agent coming back to a far away region, which gets a new seed (because we don't know what was its seed in the departing region, and we can't send it back to the client when the agent returns there).
2013-07-26 06:44:58 +00:00
|
|
|
// m_log.DebugFormat("[EVENTQUEUE]: Deleted queues for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
|
|
|
|
|
2008-09-27 09:42:31 +00:00
|
|
|
}
|
2008-09-27 18:33:54 +00:00
|
|
|
|
2012-05-17 23:38:29 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Generate an Event Queue Get handler path for the given eqg uuid.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name='eqgUuid'></param>
|
|
|
|
private string GenerateEqgCapPath(UUID eqgUuid)
|
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
return string.Format("/CE/{0}/", eqgUuid);
|
2012-05-17 23:38:29 +00:00
|
|
|
}
|
|
|
|
|
2008-09-27 09:42:31 +00:00
|
|
|
public void OnRegisterCaps(UUID agentID, Caps caps)
|
|
|
|
{
|
2009-01-06 21:39:55 +00:00
|
|
|
// Register an event queue for the client
|
2011-05-03 02:45:47 +00:00
|
|
|
|
2014-08-04 23:49:17 +00:00
|
|
|
if (DebugLevel > 0)
|
|
|
|
m_log.DebugFormat(
|
|
|
|
"[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}",
|
|
|
|
agentID, caps, m_scene.RegionInfo.RegionName);
|
2008-12-19 23:58:13 +00:00
|
|
|
|
2012-05-17 23:38:29 +00:00
|
|
|
UUID eventQueueGetUUID;
|
2020-05-07 01:26:25 +00:00
|
|
|
Queue<Byte[]> queue = null;
|
2008-10-01 04:16:41 +00:00
|
|
|
|
2014-07-25 16:29:41 +00:00
|
|
|
lock (queues)
|
2008-10-01 04:16:41 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
queues.TryGetValue(agentID, out queue);
|
2014-07-25 16:29:41 +00:00
|
|
|
|
|
|
|
if (queue == null)
|
2008-10-01 04:16:41 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
queue = new Queue<byte[]>();
|
2014-07-25 16:29:41 +00:00
|
|
|
queues[agentID] = queue;
|
|
|
|
|
|
|
|
lock (m_AvatarQueueUUIDMapping)
|
|
|
|
{
|
|
|
|
eventQueueGetUUID = UUID.Random();
|
2019-01-28 04:01:09 +00:00
|
|
|
m_AvatarQueueUUIDMapping[agentID] = eventQueueGetUUID;
|
|
|
|
lock (m_ids)
|
|
|
|
{
|
|
|
|
if (m_ids.ContainsKey(agentID))
|
|
|
|
m_ids[agentID]++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Random rnd = new Random(Environment.TickCount);
|
|
|
|
m_ids[agentID] = rnd.Next(30000000);
|
|
|
|
}
|
|
|
|
}
|
2014-07-25 16:29:41 +00:00
|
|
|
}
|
2008-10-01 04:16:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-25 16:29:41 +00:00
|
|
|
queue.Enqueue(null);
|
2019-01-28 04:01:09 +00:00
|
|
|
|
2017-06-06 20:55:47 +00:00
|
|
|
// reuse or not to reuse
|
2014-07-25 16:29:41 +00:00
|
|
|
lock (m_AvatarQueueUUIDMapping)
|
|
|
|
{
|
|
|
|
// Its reuse caps path not queues those are been reused already
|
|
|
|
if (m_AvatarQueueUUIDMapping.ContainsKey(agentID))
|
|
|
|
{
|
|
|
|
m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!");
|
|
|
|
eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID];
|
2017-06-06 20:55:47 +00:00
|
|
|
lock (m_ids)
|
|
|
|
{
|
|
|
|
// change to negative numbers so they are changed at end of sending first marker
|
|
|
|
// old data on a queue may be sent on a response for a new caps
|
|
|
|
// but at least will be sent with coerent IDs
|
2019-01-28 04:01:09 +00:00
|
|
|
if (m_ids.ContainsKey(agentID))
|
2017-06-06 20:55:47 +00:00
|
|
|
m_ids[agentID] = -m_ids[agentID];
|
2019-01-28 04:01:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Random rnd = new Random(Environment.TickCount);
|
|
|
|
m_ids[agentID] = -rnd.Next(30000000);
|
|
|
|
}
|
2017-06-06 20:55:47 +00:00
|
|
|
}
|
2014-07-25 16:29:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eventQueueGetUUID = UUID.Random();
|
2019-01-28 04:01:09 +00:00
|
|
|
m_AvatarQueueUUIDMapping[agentID] = eventQueueGetUUID;
|
2017-06-06 20:55:47 +00:00
|
|
|
lock (m_ids)
|
|
|
|
{
|
2019-01-28 04:01:09 +00:00
|
|
|
if (m_ids.ContainsKey(agentID))
|
2017-06-06 20:55:47 +00:00
|
|
|
m_ids[agentID]++;
|
2019-01-28 04:01:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Random rnd = new Random(Environment.TickCount);
|
|
|
|
m_ids.Add(agentID, rnd.Next(30000000));
|
|
|
|
}
|
2017-06-06 20:55:47 +00:00
|
|
|
}
|
2014-07-25 16:29:41 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-01 04:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
caps.RegisterPollHandler(
|
|
|
|
"EventQueueGet",
|
|
|
|
new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, Drop, agentID, VIEWERKEEPALIVE));
|
2008-09-27 09:42:31 +00:00
|
|
|
}
|
2008-09-27 18:33:54 +00:00
|
|
|
|
2009-09-21 17:11:40 +00:00
|
|
|
public bool HasEvents(UUID requestID, UUID agentID)
|
2009-07-29 02:15:45 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
Queue<byte[]> queue = GetQueue(agentID);
|
2009-08-11 23:47:36 +00:00
|
|
|
if (queue != null)
|
2020-05-07 01:26:25 +00:00
|
|
|
{
|
2009-08-11 23:47:36 +00:00
|
|
|
lock (queue)
|
2013-07-18 19:23:27 +00:00
|
|
|
{
|
|
|
|
//m_log.WarnFormat("POLLED FOR EVENTS BY {0} in {1} -- {2}", agentID, m_scene.RegionInfo.RegionName, queue.Count);
|
2011-09-24 00:10:23 +00:00
|
|
|
return queue.Count > 0;
|
2013-07-18 19:23:27 +00:00
|
|
|
}
|
2020-05-07 01:26:25 +00:00
|
|
|
}
|
2014-08-02 23:22:21 +00:00
|
|
|
//m_log.WarnFormat("POLLED FOR EVENTS BY {0} unknown agent", agentID);
|
2014-07-24 16:14:14 +00:00
|
|
|
return true;
|
2009-07-29 02:15:45 +00:00
|
|
|
}
|
|
|
|
|
2012-05-18 02:43:36 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Logs a debug line for an outbound event queue message if appropriate.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name='element'>Element containing message</param>
|
|
|
|
private void LogOutboundDebugMessage(OSD element, UUID agentId)
|
|
|
|
{
|
|
|
|
if (element is OSDMap)
|
|
|
|
{
|
|
|
|
OSDMap ev = (OSDMap)element;
|
|
|
|
m_log.DebugFormat(
|
|
|
|
"Eq OUT {0,-30} to {1,-20} {2,-20}",
|
2013-08-12 18:38:23 +00:00
|
|
|
ev["message"], m_scene.GetScenePresence(agentId).Name, m_scene.Name);
|
2012-05-18 02:43:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-07 01:26:25 +00:00
|
|
|
|
2016-07-17 12:20:56 +00:00
|
|
|
public void Drop(UUID requestID, UUID pAgentId)
|
|
|
|
{
|
2020-04-20 23:19:19 +00:00
|
|
|
// do nothing, in last case http server will do it
|
2016-07-17 12:20:56 +00:00
|
|
|
}
|
2012-05-18 02:43:36 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
private readonly byte[] EventHeader = GenEventHeader();
|
|
|
|
|
|
|
|
private static byte[] GenEventHeader()
|
|
|
|
{
|
|
|
|
return Encoding.UTF8.GetBytes("<llsd><map><key>events</key><array>");
|
|
|
|
}
|
|
|
|
|
2013-06-07 22:43:45 +00:00
|
|
|
public Hashtable GetEvents(UUID requestID, UUID pAgentId)
|
2009-07-29 02:15:45 +00:00
|
|
|
{
|
2012-05-18 02:43:36 +00:00
|
|
|
if (DebugLevel >= 2)
|
2013-08-12 18:38:23 +00:00
|
|
|
m_log.WarnFormat("POLLED FOR EQ MESSAGES BY {0} in {1}", pAgentId, m_scene.Name);
|
2011-11-24 21:27:35 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
Queue<byte[]> queue = GetQueue(pAgentId);
|
This should fix all issues with teleports. One should be able to TP as fast as needed. (Although sometimes Justin's state machine kicks in and doesn't let you) The EventQueues are a hairy mess, and it's very easy to mess things up. But it looks like this commit makes them work right. Here's what's going on:
- Child and root agents are only closed after 15 sec, maybe
- If the user comes back, they aren't closed, and everything is reused
- On the receiving side, clients and scene presences are reused if they already exist
- Caps are always recreated (this is where I spent most of my time!). It turns out that, because the agents carry the seeds around, the seed gets the same URL, except for the root agent coming back to a far away region, which gets a new seed (because we don't know what was its seed in the departing region, and we can't send it back to the client when the agent returns there).
2013-07-26 06:44:58 +00:00
|
|
|
if (queue == null)
|
2020-05-07 01:26:25 +00:00
|
|
|
return NoAgent(requestID, pAgentId);
|
This should fix all issues with teleports. One should be able to TP as fast as needed. (Although sometimes Justin's state machine kicks in and doesn't let you) The EventQueues are a hairy mess, and it's very easy to mess things up. But it looks like this commit makes them work right. Here's what's going on:
- Child and root agents are only closed after 15 sec, maybe
- If the user comes back, they aren't closed, and everything is reused
- On the receiving side, clients and scene presences are reused if they already exist
- Caps are always recreated (this is where I spent most of my time!). It turns out that, because the agents carry the seeds around, the seed gets the same URL, except for the root agent coming back to a far away region, which gets a new seed (because we don't know what was its seed in the departing region, and we can't send it back to the client when the agent returns there).
2013-07-26 06:44:58 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
byte[] element = null;
|
|
|
|
List<byte[]> elements;
|
|
|
|
|
|
|
|
int totalSize = 0;
|
2014-07-25 16:29:41 +00:00
|
|
|
int thisID = 0;
|
|
|
|
bool negativeID = false;
|
|
|
|
|
2009-07-31 20:53:35 +00:00
|
|
|
lock (queue)
|
|
|
|
{
|
|
|
|
if (queue.Count == 0)
|
2009-09-21 17:11:40 +00:00
|
|
|
return NoEvents(requestID, pAgentId);
|
2011-11-24 20:27:11 +00:00
|
|
|
|
2014-07-25 16:29:41 +00:00
|
|
|
lock (m_ids)
|
|
|
|
thisID = m_ids[pAgentId];
|
2011-11-24 20:27:11 +00:00
|
|
|
|
2014-07-25 16:29:41 +00:00
|
|
|
if (thisID < 0)
|
2009-07-29 02:15:45 +00:00
|
|
|
{
|
2014-07-25 16:29:41 +00:00
|
|
|
negativeID = true;
|
|
|
|
thisID = -thisID;
|
|
|
|
}
|
2017-01-05 19:07:37 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
elements = new List<byte[]>(queue.Count + 2);
|
|
|
|
elements.Add(EventHeader);
|
|
|
|
|
2014-07-25 16:29:41 +00:00
|
|
|
while (queue.Count > 0)
|
|
|
|
{
|
|
|
|
element = queue.Dequeue();
|
|
|
|
// add elements until a marker is found
|
|
|
|
// so they get into a response
|
|
|
|
if (element == null)
|
|
|
|
break;
|
2019-01-28 04:01:09 +00:00
|
|
|
|
2014-07-25 16:29:41 +00:00
|
|
|
if (DebugLevel > 0)
|
|
|
|
LogOutboundDebugMessage(element, pAgentId);
|
2020-05-07 01:26:25 +00:00
|
|
|
|
|
|
|
elements.Add(element);
|
|
|
|
totalSize += element.Length;
|
2014-07-25 16:29:41 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-24 20:27:11 +00:00
|
|
|
|
2019-01-28 04:01:09 +00:00
|
|
|
lock (m_ids)
|
2014-07-25 16:29:41 +00:00
|
|
|
{
|
2019-01-28 04:01:09 +00:00
|
|
|
if (element == null && negativeID)
|
|
|
|
{
|
|
|
|
Random rnd = new Random(Environment.TickCount);
|
|
|
|
m_ids[pAgentId] = rnd.Next(30000000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_ids[pAgentId] = thisID + 1;
|
2009-07-29 02:15:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
if (totalSize == 0)
|
2019-01-28 04:01:09 +00:00
|
|
|
return NoEvents(requestID, pAgentId);
|
2009-07-29 02:15:45 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
totalSize += EventHeader.Length;
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
LLSDxmlEncode.AddEndArray(sb); // events array
|
|
|
|
LLSDxmlEncode.AddElem("id", thisID, sb);
|
|
|
|
LLSDxmlEncode.AddEndMap(sb);
|
|
|
|
element = Encoding.UTF8.GetBytes(LLSDxmlEncode.End(sb));
|
|
|
|
elements.Add(element);
|
|
|
|
totalSize += element.Length;
|
2019-01-28 04:01:09 +00:00
|
|
|
|
|
|
|
Hashtable responsedata = new Hashtable();
|
|
|
|
responsedata["int_response_code"] = 200;
|
|
|
|
responsedata["content_type"] = "application/xml";
|
2017-06-06 20:55:47 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
//temporary
|
|
|
|
byte[] finalData = new byte[totalSize];
|
|
|
|
int dst = 0;
|
|
|
|
foreach(byte[] src in elements)
|
2019-01-28 04:01:09 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
Array.Copy(src, 0, finalData, dst, src.Length);
|
|
|
|
dst += src.Length;
|
2019-01-28 04:01:09 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
responsedata["bin_response_data"] = finalData;
|
|
|
|
responsedata["keepaliveTimeout"] = KEEPALIVE;
|
2016-06-19 23:27:12 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
return responsedata;
|
2011-04-30 16:24:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
public Hashtable NoEvents(UUID requestID, UUID agentID)
|
2013-02-07 22:25:28 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
Hashtable responsedata = new Hashtable();
|
|
|
|
Queue<byte[]> queue = GetQueue(agentID);
|
|
|
|
if (queue == null)
|
|
|
|
{
|
|
|
|
responsedata["int_response_code"] = (int)HttpStatusCode.NotFound;
|
|
|
|
return responsedata;
|
|
|
|
}
|
|
|
|
responsedata["int_response_code"] = (int)HttpStatusCode.BadGateway;
|
|
|
|
return responsedata;
|
2013-02-07 22:25:28 +00:00
|
|
|
}
|
2019-01-28 04:01:09 +00:00
|
|
|
|
2020-05-07 01:26:25 +00:00
|
|
|
public Hashtable NoAgent(UUID requestID, UUID agentID)
|
2019-01-28 04:01:09 +00:00
|
|
|
{
|
2020-05-07 01:26:25 +00:00
|
|
|
Hashtable responsedata = new Hashtable();
|
|
|
|
responsedata["int_response_code"] = (int)HttpStatusCode.NotFound;
|
|
|
|
return responsedata;
|
2019-01-28 04:01:09 +00:00
|
|
|
}
|
2008-09-27 09:42:31 +00:00
|
|
|
}
|
|
|
|
}
|