aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs128
1 files changed, 128 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs
new file mode 100644
index 0000000..6c88ae86
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs
@@ -0,0 +1,128 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using libsecondlife;
32using OpenSim.Region.ScriptEngine.Shared;
33using OpenSim.Region.ScriptEngine.Shared.Api;
34
35namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
36{
37 public class Dataserver
38 {
39 public AsyncCommandManager m_CmdManager;
40
41 private Dictionary<string, DataserverRequest> DataserverRequests =
42 new Dictionary<string, DataserverRequest>();
43
44 public Dataserver(AsyncCommandManager CmdManager)
45 {
46 m_CmdManager = CmdManager;
47 }
48
49 private class DataserverRequest
50 {
51 public uint localID;
52 public LLUUID itemID;
53
54 public LLUUID ID;
55 public string handle;
56
57 public DateTime startTime;
58 }
59
60 public LLUUID RegisterRequest(uint localID, LLUUID itemID,
61 string identifier)
62 {
63 lock (DataserverRequests)
64 {
65 if (DataserverRequests.ContainsKey(identifier))
66 return LLUUID.Zero;
67
68 DataserverRequest ds = new DataserverRequest();
69
70 ds.localID = localID;
71 ds.itemID = itemID;
72
73 ds.ID = LLUUID.Random();
74 ds.handle = identifier;
75
76 ds.startTime = DateTime.Now;
77
78 DataserverRequests[identifier]=ds;
79
80 return ds.ID;
81 }
82 }
83
84 public void DataserverReply(string identifier, string reply)
85 {
86 DataserverRequest ds;
87
88 lock (DataserverRequests)
89 {
90 if (!DataserverRequests.ContainsKey(identifier))
91 return;
92
93 ds=DataserverRequests[identifier];
94 DataserverRequests.Remove(identifier);
95 }
96
97 m_CmdManager.m_ScriptEngine.PostObjectEvent(ds.localID,
98 new EventParams("dataserver", new Object[]
99 { new LSL_Types.LSLString(ds.ID.ToString()),
100 new LSL_Types.LSLString(reply)},
101 new DetectParams[0]));
102 }
103
104 public void RemoveEvents(uint localID, LLUUID itemID)
105 {
106 lock (DataserverRequests)
107 {
108 foreach (DataserverRequest ds in new List<DataserverRequest>(DataserverRequests.Values))
109 {
110 if (ds.itemID == itemID)
111 DataserverRequests.Remove(ds.handle);
112 }
113 }
114 }
115
116 public void ExpireRequests()
117 {
118 lock (DataserverRequests)
119 {
120 foreach (DataserverRequest ds in new List<DataserverRequest>(DataserverRequests.Values))
121 {
122 if (ds.startTime > DateTime.Now.AddSeconds(30))
123 DataserverRequests.Remove(ds.handle);
124 }
125 }
126 }
127 }
128}