diff options
author | Justin Clarke Casey | 2009-01-02 20:07:29 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-01-02 20:07:29 +0000 |
commit | 2a7e3b9cff17d91831ae31e6a1119200ed88200f (patch) | |
tree | 65bad6c8c92a4b654e5104d24d10dc20f99a1d2c /OpenSim/Region/Environment/Modules/Framework/EventQueue/EventQueueHelper.cs | |
parent | * reference is to Nini.Config, not Nini (diff) | |
download | opensim-SC-2a7e3b9cff17d91831ae31e6a1119200ed88200f.zip opensim-SC-2a7e3b9cff17d91831ae31e6a1119200ed88200f.tar.gz opensim-SC-2a7e3b9cff17d91831ae31e6a1119200ed88200f.tar.bz2 opensim-SC-2a7e3b9cff17d91831ae31e6a1119200ed88200f.tar.xz |
* refactor: move event queue module code to its own folder
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Framework/EventQueue/EventQueueHelper.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Framework/EventQueue/EventQueueHelper.cs | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueue/EventQueueHelper.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueue/EventQueueHelper.cs new file mode 100644 index 0000000..0ffa8aa --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Framework/EventQueue/EventQueueHelper.cs | |||
@@ -0,0 +1,196 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Net; | ||
30 | using OpenMetaverse; | ||
31 | using OpenMetaverse.StructuredData; | ||
32 | |||
33 | namespace OpenSim.Region.Environment | ||
34 | { | ||
35 | public class EventQueueHelper | ||
36 | { | ||
37 | private EventQueueHelper() {} // no construction possible, it's an utility class | ||
38 | |||
39 | private static byte[] regionHandleToByteArray(ulong regionHandle) | ||
40 | { | ||
41 | // Reverse endianness of RegionHandle | ||
42 | return new byte[] | ||
43 | { | ||
44 | (byte)((regionHandle >> 56) % 256), | ||
45 | (byte)((regionHandle >> 48) % 256), | ||
46 | (byte)((regionHandle >> 40) % 256), | ||
47 | (byte)((regionHandle >> 32) % 256), | ||
48 | (byte)((regionHandle >> 24) % 256), | ||
49 | (byte)((regionHandle >> 16) % 256), | ||
50 | (byte)((regionHandle >> 8) % 256), | ||
51 | (byte)(regionHandle % 256) | ||
52 | }; | ||
53 | } | ||
54 | |||
55 | public static OSD buildEvent(string eventName, OSD eventBody) | ||
56 | { | ||
57 | OSDMap llsdEvent = new OSDMap(2); | ||
58 | llsdEvent.Add("message", new OSDString(eventName)); | ||
59 | llsdEvent.Add("body", eventBody); | ||
60 | |||
61 | return llsdEvent; | ||
62 | } | ||
63 | |||
64 | public static OSD EnableSimulator(ulong Handle, IPEndPoint endPoint) | ||
65 | { | ||
66 | OSDMap llsdSimInfo = new OSDMap(3); | ||
67 | |||
68 | llsdSimInfo.Add("Handle", new OSDBinary(regionHandleToByteArray(Handle))); | ||
69 | llsdSimInfo.Add("IP", new OSDBinary(endPoint.Address.GetAddressBytes())); | ||
70 | llsdSimInfo.Add("Port", new OSDInteger(endPoint.Port)); | ||
71 | |||
72 | OSDArray arr = new OSDArray(1); | ||
73 | arr.Add(llsdSimInfo); | ||
74 | |||
75 | OSDMap llsdBody = new OSDMap(1); | ||
76 | llsdBody.Add("SimulatorInfo", arr); | ||
77 | |||
78 | return buildEvent("EnableSimulator", llsdBody); | ||
79 | } | ||
80 | |||
81 | public static OSD DisableSimulator(ulong Handle) | ||
82 | { | ||
83 | //OSDMap llsdSimInfo = new OSDMap(1); | ||
84 | |||
85 | //llsdSimInfo.Add("Handle", new OSDBinary(regionHandleToByteArray(Handle))); | ||
86 | |||
87 | //OSDArray arr = new OSDArray(1); | ||
88 | //arr.Add(llsdSimInfo); | ||
89 | |||
90 | OSDMap llsdBody = new OSDMap(0); | ||
91 | //llsdBody.Add("SimulatorInfo", arr); | ||
92 | |||
93 | return buildEvent("DisableSimulator", llsdBody); | ||
94 | } | ||
95 | |||
96 | public static OSD CrossRegion(ulong Handle, Vector3 pos, Vector3 lookAt, | ||
97 | IPEndPoint newRegionExternalEndPoint, | ||
98 | string capsURL, UUID AgentID, UUID SessionID) | ||
99 | { | ||
100 | OSDArray LookAtArr = new OSDArray(3); | ||
101 | LookAtArr.Add(OSD.FromReal(lookAt.X)); | ||
102 | LookAtArr.Add(OSD.FromReal(lookAt.Y)); | ||
103 | LookAtArr.Add(OSD.FromReal(lookAt.Z)); | ||
104 | |||
105 | OSDArray PositionArr = new OSDArray(3); | ||
106 | PositionArr.Add(OSD.FromReal(pos.X)); | ||
107 | PositionArr.Add(OSD.FromReal(pos.Y)); | ||
108 | PositionArr.Add(OSD.FromReal(pos.Z)); | ||
109 | |||
110 | OSDMap InfoMap = new OSDMap(2); | ||
111 | InfoMap.Add("LookAt", LookAtArr); | ||
112 | InfoMap.Add("Position", PositionArr); | ||
113 | |||
114 | OSDArray InfoArr = new OSDArray(1); | ||
115 | InfoArr.Add(InfoMap); | ||
116 | |||
117 | OSDMap AgentDataMap = new OSDMap(2); | ||
118 | AgentDataMap.Add("AgentID", OSD.FromUUID(AgentID)); | ||
119 | AgentDataMap.Add("SessionID", OSD.FromUUID(SessionID)); | ||
120 | |||
121 | OSDArray AgentDataArr = new OSDArray(1); | ||
122 | AgentDataArr.Add(AgentDataMap); | ||
123 | |||
124 | OSDMap RegionDataMap = new OSDMap(4); | ||
125 | RegionDataMap.Add("RegionHandle", OSD.FromBinary(regionHandleToByteArray(Handle))); | ||
126 | RegionDataMap.Add("SeedCapability", OSD.FromString(capsURL)); | ||
127 | RegionDataMap.Add("SimIP", OSD.FromBinary(newRegionExternalEndPoint.Address.GetAddressBytes())); | ||
128 | RegionDataMap.Add("SimPort", OSD.FromInteger(newRegionExternalEndPoint.Port)); | ||
129 | |||
130 | OSDArray RegionDataArr = new OSDArray(1); | ||
131 | RegionDataArr.Add(RegionDataMap); | ||
132 | |||
133 | OSDMap llsdBody = new OSDMap(3); | ||
134 | llsdBody.Add("Info", InfoArr); | ||
135 | llsdBody.Add("AgentData", AgentDataArr); | ||
136 | llsdBody.Add("RegionData", RegionDataArr); | ||
137 | |||
138 | return buildEvent("CrossedRegion", llsdBody); | ||
139 | } | ||
140 | |||
141 | public static OSD TeleportFinishEvent( | ||
142 | ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, | ||
143 | uint locationID, uint flags, string capsURL, UUID AgentID) | ||
144 | { | ||
145 | OSDMap info = new OSDMap(); | ||
146 | info.Add("AgentID", OSD.FromUUID(AgentID)); | ||
147 | info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this? | ||
148 | info.Add("RegionHandle", OSD.FromBinary(regionHandleToByteArray(regionHandle))); | ||
149 | info.Add("SeedCapability", OSD.FromString(capsURL)); | ||
150 | info.Add("SimAccess", OSD.FromInteger(simAccess)); | ||
151 | info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes())); | ||
152 | info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port)); | ||
153 | info.Add("TeleportFlags", OSD.FromBinary(1L << 4)); // AgentManager.TeleportFlags.ViaLocation | ||
154 | |||
155 | OSDArray infoArr = new OSDArray(); | ||
156 | infoArr.Add(info); | ||
157 | |||
158 | OSDMap body = new OSDMap(); | ||
159 | body.Add("Info", infoArr); | ||
160 | |||
161 | return buildEvent("TeleportFinish", body); | ||
162 | } | ||
163 | |||
164 | public static OSD ScriptRunningReplyEvent(UUID objectID, UUID itemID, bool running, bool mono) | ||
165 | { | ||
166 | OSDMap script = new OSDMap(); | ||
167 | script.Add("ObjectID", OSD.FromUUID(objectID)); | ||
168 | script.Add("ItemID", OSD.FromUUID(itemID)); | ||
169 | script.Add("Running", OSD.FromBoolean(running)); | ||
170 | script.Add("Mono", OSD.FromBoolean(mono)); | ||
171 | |||
172 | OSDArray scriptArr = new OSDArray(); | ||
173 | scriptArr.Add(script); | ||
174 | |||
175 | OSDMap body = new OSDMap(); | ||
176 | body.Add("Script", scriptArr); | ||
177 | |||
178 | return buildEvent("ScriptRunningReply", body); | ||
179 | } | ||
180 | |||
181 | public static OSD EstablishAgentCommunication(UUID agentID, string simIpAndPort, string seedcap) | ||
182 | { | ||
183 | OSDMap body = new OSDMap(3); | ||
184 | body.Add("agent-id", new OSDUUID(agentID)); | ||
185 | body.Add("sim-ip-and-port", new OSDString(simIpAndPort)); | ||
186 | body.Add("seed-capability", new OSDString(seedcap)); | ||
187 | |||
188 | return buildEvent("EstablishAgentCommunication", body); | ||
189 | } | ||
190 | |||
191 | public static OSD KeepAliveEvent() | ||
192 | { | ||
193 | return buildEvent("FAKEEVENT", new OSDMap()); | ||
194 | } | ||
195 | } | ||
196 | } | ||