From bbed2258612edb632ae56ab52b5e5348f2fc92c8 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 15 Aug 2020 18:40:29 +0100 Subject: [PATCH] modify Dataserver request functions --- .../Api/Implementation/Plugins/Dataserver.cs | 90 ++++++++++++++++--- 1 file changed, 77 insertions(+), 13 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs index 9fbcde1af8..9b3a23315b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs @@ -82,6 +82,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins public Action action; } + public string RequestWithImediatePost(uint localID, UUID itemID, string reply) + { + string ID = UUID.Random().ToString(); + m_CmdManager.m_ScriptEngine.PostObjectEvent(localID, + new EventParams("dataserver", new Object[] + { new LSL_Types.LSLString(ID), + new LSL_Types.LSLString(reply)}, + new DetectParams[0])); + return ID; + } + + public UUID RegisterRequest(uint localID, UUID itemID, string identifier) + { + lock (DataserverRequests) + { + if (DataserverRequests.ContainsKey(identifier)) + return UUID.Zero; + + DataserverRequest ds = new DataserverRequest() + { + localID = localID, + itemID = itemID, + + ID = UUID.Random(), + handle = identifier, + + startTime = DateTime.UtcNow, + action = null + }; + + DataserverRequests[identifier] = ds; + return ds.ID; + } + } + // action, if provided, is executed async // its code pattern should be: //Action act = eventID => @@ -92,33 +127,61 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins // eventID is the event id, provided by this on Invoque // see ProcessActions below - public UUID RegisterRequest(uint localID, UUID itemID, - string identifier, Action action = null) + // temporary don't use + public UUID RegisterRequest(uint localID, UUID itemID, string identifier, Action action) { lock (DataserverRequests) { if (DataserverRequests.ContainsKey(identifier)) return UUID.Zero; - DataserverRequest ds = new DataserverRequest(); + DataserverRequest ds = new DataserverRequest() + { + localID = localID, + itemID = itemID, - ds.localID = localID; - ds.itemID = itemID; + ID = UUID.Random(), + handle = identifier, - ds.ID = UUID.Random(); - ds.handle = identifier; - - ds.startTime = DateTime.Now; - ds.action = action; + startTime = DateTime.UtcNow, + action = action + }; DataserverRequests[identifier] = ds; - if(action != null) - m_ThreadPool.QueueWorkItem((WorkItemCallback)ProcessActions, (object)identifier); + if (action != null) + m_ThreadPool.QueueWorkItem((WorkItemCallback)ProcessActions, identifier); return ds.ID; } } + public UUID RegisterRequest(uint localID, UUID itemID, Action action) + { + lock (DataserverRequests) + { + string identifier = UUID.Random().ToString(); + + DataserverRequest ds = new DataserverRequest() + { + localID = localID, + itemID = itemID, + + ID = UUID.Random(), + handle = identifier, + + startTime = DateTime.MaxValue, + action = action + }; + + DataserverRequests[identifier] = ds; + if (action != null) + m_ThreadPool.QueueWorkItem((WorkItemCallback)ProcessActions, identifier); + + return ds.ID; + } + } + + public object ProcessActions(object st) { string id = st as string; @@ -192,9 +255,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins lock (DataserverRequests) { List toremove = new List(DataserverRequests.Count); + DateTime expirebase = DateTime.UtcNow.AddSeconds(-30); foreach (DataserverRequest ds in DataserverRequests.Values) { - if (ds.startTime > DateTime.Now.AddSeconds(30) && ds.action == null) + if (ds.action == null && ds.startTime < expirebase) toremove.Add(ds.handle); } foreach (string s in toremove)