opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 OpenSimulator 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.Packets;
32 using OpenMetaverse.StructuredData;
33 using OpenMetaverse.Messages.Linden;
34  
35 namespace OpenSim.Region.ClientStack.Linden
36 {
37 public class EventQueueHelper
38 {
39 private EventQueueHelper() {} // no construction possible, it's an utility class
40  
41 private static byte[] ulongToByteArray(ulong uLongValue)
42 {
43 // Reverse endianness of RegionHandle
44 return new byte[]
45 {
46 (byte)((uLongValue >> 56) % 256),
47 (byte)((uLongValue >> 48) % 256),
48 (byte)((uLongValue >> 40) % 256),
49 (byte)((uLongValue >> 32) % 256),
50 (byte)((uLongValue >> 24) % 256),
51 (byte)((uLongValue >> 16) % 256),
52 (byte)((uLongValue >> 8) % 256),
53 (byte)(uLongValue % 256)
54 };
55 }
56  
57 // private static byte[] uintToByteArray(uint uIntValue)
58 // {
59 // byte[] result = new byte[4];
60 // Utils.UIntToBytesBig(uIntValue, result, 0);
61 // return result;
62 // }
63  
64 public static OSD BuildEvent(string eventName, OSD eventBody)
65 {
66 OSDMap llsdEvent = new OSDMap(2);
67 llsdEvent.Add("message", new OSDString(eventName));
68 llsdEvent.Add("body", eventBody);
69  
70 return llsdEvent;
71 }
72  
73 public static OSD EnableSimulator(ulong handle, IPEndPoint endPoint, int regionSizeX, int regionSizeY)
74 {
75 OSDMap llsdSimInfo = new OSDMap(5);
76  
77 llsdSimInfo.Add("Handle", new OSDBinary(ulongToByteArray(handle)));
78 llsdSimInfo.Add("IP", new OSDBinary(endPoint.Address.GetAddressBytes()));
79 llsdSimInfo.Add("Port", new OSDInteger(endPoint.Port));
80 llsdSimInfo.Add("RegionSizeX", OSD.FromUInteger((uint) regionSizeX));
81 llsdSimInfo.Add("RegionSizeY", OSD.FromUInteger((uint) regionSizeY));
82  
83 OSDArray arr = new OSDArray(1);
84 arr.Add(llsdSimInfo);
85  
86 OSDMap llsdBody = new OSDMap(1);
87 llsdBody.Add("SimulatorInfo", arr);
88  
89 return BuildEvent("EnableSimulator", llsdBody);
90 }
91  
92 public static OSD DisableSimulator(ulong handle)
93 {
94 //OSDMap llsdSimInfo = new OSDMap(1);
95  
96 //llsdSimInfo.Add("Handle", new OSDBinary(regionHandleToByteArray(handle)));
97  
98 //OSDArray arr = new OSDArray(1);
99 //arr.Add(llsdSimInfo);
100  
101 OSDMap llsdBody = new OSDMap(0);
102 //llsdBody.Add("SimulatorInfo", arr);
103  
104 return BuildEvent("DisableSimulator", llsdBody);
105 }
106  
107 public static OSD CrossRegion(ulong handle, Vector3 pos, Vector3 lookAt,
108 IPEndPoint newRegionExternalEndPoint,
109 string capsURL, UUID agentID, UUID sessionID,
110 int regionSizeX, int regionSizeY)
111 {
112 OSDArray lookAtArr = new OSDArray(3);
113 lookAtArr.Add(OSD.FromReal(lookAt.X));
114 lookAtArr.Add(OSD.FromReal(lookAt.Y));
115 lookAtArr.Add(OSD.FromReal(lookAt.Z));
116  
117 OSDArray positionArr = new OSDArray(3);
118 positionArr.Add(OSD.FromReal(pos.X));
119 positionArr.Add(OSD.FromReal(pos.Y));
120 positionArr.Add(OSD.FromReal(pos.Z));
121  
122 OSDMap infoMap = new OSDMap(2);
123 infoMap.Add("LookAt", lookAtArr);
124 infoMap.Add("Position", positionArr);
125  
126 OSDArray infoArr = new OSDArray(1);
127 infoArr.Add(infoMap);
128  
129 OSDMap agentDataMap = new OSDMap(2);
130 agentDataMap.Add("AgentID", OSD.FromUUID(agentID));
131 agentDataMap.Add("SessionID", OSD.FromUUID(sessionID));
132  
133 OSDArray agentDataArr = new OSDArray(1);
134 agentDataArr.Add(agentDataMap);
135  
136 OSDMap regionDataMap = new OSDMap(6);
137 regionDataMap.Add("RegionHandle", OSD.FromBinary(ulongToByteArray(handle)));
138 regionDataMap.Add("SeedCapability", OSD.FromString(capsURL));
139 regionDataMap.Add("SimIP", OSD.FromBinary(newRegionExternalEndPoint.Address.GetAddressBytes()));
140 regionDataMap.Add("SimPort", OSD.FromInteger(newRegionExternalEndPoint.Port));
141 regionDataMap.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX));
142 regionDataMap.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY));
143  
144 OSDArray regionDataArr = new OSDArray(1);
145 regionDataArr.Add(regionDataMap);
146  
147 OSDMap llsdBody = new OSDMap(3);
148 llsdBody.Add("Info", infoArr);
149 llsdBody.Add("AgentData", agentDataArr);
150 llsdBody.Add("RegionData", regionDataArr);
151  
152 return BuildEvent("CrossedRegion", llsdBody);
153 }
154  
155 public static OSD TeleportFinishEvent(
156 ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint,
157 uint locationID, uint flags, string capsURL, UUID agentID,
158 int regionSizeX, int regionSizeY)
159 {
160 OSDMap info = new OSDMap();
161 info.Add("AgentID", OSD.FromUUID(agentID));
162 info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this?
163 info.Add("RegionHandle", OSD.FromBinary(ulongToByteArray(regionHandle)));
164 info.Add("SeedCapability", OSD.FromString(capsURL));
165 info.Add("SimAccess", OSD.FromInteger(simAccess));
166 info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes()));
167 info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port));
168 info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation
169 info.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX));
170 info.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY));
171  
172 OSDArray infoArr = new OSDArray();
173 infoArr.Add(info);
174  
175 OSDMap body = new OSDMap();
176 body.Add("Info", infoArr);
177  
178 return BuildEvent("TeleportFinish", body);
179 }
180  
181 public static OSD ScriptRunningReplyEvent(UUID objectID, UUID itemID, bool running, bool mono)
182 {
183 OSDMap script = new OSDMap();
184 script.Add("ObjectID", OSD.FromUUID(objectID));
185 script.Add("ItemID", OSD.FromUUID(itemID));
186 script.Add("Running", OSD.FromBoolean(running));
187 script.Add("Mono", OSD.FromBoolean(mono));
188  
189 OSDArray scriptArr = new OSDArray();
190 scriptArr.Add(script);
191  
192 OSDMap body = new OSDMap();
193 body.Add("Script", scriptArr);
194  
195 return BuildEvent("ScriptRunningReply", body);
196 }
197  
198 public static OSD EstablishAgentCommunication(UUID agentID, string simIpAndPort, string seedcap,
199 ulong regionHandle, int regionSizeX, int regionSizeY)
200 {
201 OSDMap body = new OSDMap(6)
202 {
203 {"agent-id", new OSDUUID(agentID)},
204 {"sim-ip-and-port", new OSDString(simIpAndPort)},
205 {"seed-capability", new OSDString(seedcap)},
206 {"region-handle", OSD.FromULong(regionHandle)},
207 {"region-size-x", OSD.FromInteger(regionSizeX)},
208 {"region-size-y", OSD.FromInteger(regionSizeY)}
209 };
210  
211 return BuildEvent("EstablishAgentCommunication", body);
212 }
213  
214 public static OSD KeepAliveEvent()
215 {
216 return BuildEvent("FAKEEVENT", new OSDMap());
217 }
218  
219 public static OSD AgentParams(UUID agentID, bool checkEstate, int godLevel, bool limitedToEstate)
220 {
221 OSDMap body = new OSDMap(4);
222  
223 body.Add("agent_id", new OSDUUID(agentID));
224 body.Add("check_estate", new OSDInteger(checkEstate ? 1 : 0));
225 body.Add("god_level", new OSDInteger(godLevel));
226 body.Add("limited_to_estate", new OSDInteger(limitedToEstate ? 1 : 0));
227  
228 return body;
229 }
230  
231 public static OSD InstantMessageParams(UUID fromAgent, string message, UUID toAgent,
232 string fromName, byte dialog, uint timeStamp, bool offline, int parentEstateID,
233 Vector3 position, uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
234 {
235 OSDMap messageParams = new OSDMap(15);
236 messageParams.Add("type", new OSDInteger((int)dialog));
237  
238 OSDArray positionArray = new OSDArray(3);
239 positionArray.Add(OSD.FromReal(position.X));
240 positionArray.Add(OSD.FromReal(position.Y));
241 positionArray.Add(OSD.FromReal(position.Z));
242 messageParams.Add("position", positionArray);
243  
244 messageParams.Add("region_id", new OSDUUID(UUID.Zero));
245 messageParams.Add("to_id", new OSDUUID(toAgent));
246 messageParams.Add("source", new OSDInteger(0));
247  
248 OSDMap data = new OSDMap(1);
249 data.Add("binary_bucket", OSD.FromBinary(binaryBucket));
250 messageParams.Add("data", data);
251 messageParams.Add("message", new OSDString(message));
252 messageParams.Add("id", new OSDUUID(transactionID));
253 messageParams.Add("from_name", new OSDString(fromName));
254 messageParams.Add("timestamp", new OSDInteger((int)timeStamp));
255 messageParams.Add("offline", new OSDInteger(offline ? 1 : 0));
256 messageParams.Add("parent_estate_id", new OSDInteger(parentEstateID));
257 messageParams.Add("ttl", new OSDInteger((int)ttl));
258 messageParams.Add("from_id", new OSDUUID(fromAgent));
259 messageParams.Add("from_group", new OSDInteger(fromGroup ? 1 : 0));
260  
261 return messageParams;
262 }
263  
264 public static OSD InstantMessage(UUID fromAgent, string message, UUID toAgent,
265 string fromName, byte dialog, uint timeStamp, bool offline, int parentEstateID,
266 Vector3 position, uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket,
267 bool checkEstate, int godLevel, bool limitedToEstate)
268 {
269 OSDMap im = new OSDMap(2);
270 im.Add("message_params", InstantMessageParams(fromAgent, message, toAgent,
271 fromName, dialog, timeStamp, offline, parentEstateID,
272 position, ttl, transactionID, fromGroup, binaryBucket));
273  
274 im.Add("agent_params", AgentParams(fromAgent, checkEstate, godLevel, limitedToEstate));
275  
276 return im;
277 }
278  
279  
280 public static OSD ChatterboxInvitation(UUID sessionID, string sessionName,
281 UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog,
282 uint timeStamp, bool offline, int parentEstateID, Vector3 position,
283 uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
284 {
285 OSDMap body = new OSDMap(5);
286 body.Add("session_id", new OSDUUID(sessionID));
287 body.Add("from_name", new OSDString(fromName));
288 body.Add("session_name", new OSDString(sessionName));
289 body.Add("from_id", new OSDUUID(fromAgent));
290  
291 body.Add("instantmessage", InstantMessage(fromAgent, message, toAgent,
292 fromName, dialog, timeStamp, offline, parentEstateID, position,
293 ttl, transactionID, fromGroup, binaryBucket, true, 0, true));
294  
295 OSDMap chatterboxInvitation = new OSDMap(2);
296 chatterboxInvitation.Add("message", new OSDString("ChatterBoxInvitation"));
297 chatterboxInvitation.Add("body", body);
298 return chatterboxInvitation;
299 }
300  
301 public static OSD ChatterBoxSessionAgentListUpdates(UUID sessionID,
302 UUID agentID, bool canVoiceChat, bool isModerator, bool textMute)
303 {
304 OSDMap body = new OSDMap();
305 OSDMap agentUpdates = new OSDMap();
306 OSDMap infoDetail = new OSDMap();
307 OSDMap mutes = new OSDMap();
308  
309 mutes.Add("text", OSD.FromBoolean(textMute));
310 infoDetail.Add("can_voice_chat", OSD.FromBoolean(canVoiceChat));
311 infoDetail.Add("is_moderator", OSD.FromBoolean(isModerator));
312 infoDetail.Add("mutes", mutes);
313 OSDMap info = new OSDMap();
314 info.Add("info", infoDetail);
315 agentUpdates.Add(agentID.ToString(), info);
316 body.Add("agent_updates", agentUpdates);
317 body.Add("session_id", OSD.FromUUID(sessionID));
318 body.Add("updates", new OSD());
319  
320 OSDMap chatterBoxSessionAgentListUpdates = new OSDMap();
321 chatterBoxSessionAgentListUpdates.Add("message", OSD.FromString("ChatterBoxSessionAgentListUpdates"));
322 chatterBoxSessionAgentListUpdates.Add("body", body);
323  
324 return chatterBoxSessionAgentListUpdates;
325 }
326  
327 public static OSD GroupMembership(AgentGroupDataUpdatePacket groupUpdatePacket)
328 {
329 OSDMap groupUpdate = new OSDMap();
330 groupUpdate.Add("message", OSD.FromString("AgentGroupDataUpdate"));
331  
332 OSDMap body = new OSDMap();
333 OSDArray agentData = new OSDArray();
334 OSDMap agentDataMap = new OSDMap();
335 agentDataMap.Add("AgentID", OSD.FromUUID(groupUpdatePacket.AgentData.AgentID));
336 agentData.Add(agentDataMap);
337 body.Add("AgentData", agentData);
338  
339 OSDArray groupData = new OSDArray();
340  
341 foreach (AgentGroupDataUpdatePacket.GroupDataBlock groupDataBlock in groupUpdatePacket.GroupData)
342 {
343 OSDMap groupDataMap = new OSDMap();
344 groupDataMap.Add("ListInProfile", OSD.FromBoolean(false));
345 groupDataMap.Add("GroupID", OSD.FromUUID(groupDataBlock.GroupID));
346 groupDataMap.Add("GroupInsigniaID", OSD.FromUUID(groupDataBlock.GroupInsigniaID));
347 groupDataMap.Add("Contribution", OSD.FromInteger(groupDataBlock.Contribution));
348 groupDataMap.Add("GroupPowers", OSD.FromBinary(ulongToByteArray(groupDataBlock.GroupPowers)));
349 groupDataMap.Add("GroupName", OSD.FromString(Utils.BytesToString(groupDataBlock.GroupName)));
350 groupDataMap.Add("AcceptNotices", OSD.FromBoolean(groupDataBlock.AcceptNotices));
351  
352 groupData.Add(groupDataMap);
353  
354 }
355 body.Add("GroupData", groupData);
356 groupUpdate.Add("body", body);
357  
358 return groupUpdate;
359 }
360  
361 public static OSD PlacesQuery(PlacesReplyPacket PlacesReply)
362 {
363 OSDMap placesReply = new OSDMap();
364 placesReply.Add("message", OSD.FromString("PlacesReplyMessage"));
365  
366 OSDMap body = new OSDMap();
367 OSDArray agentData = new OSDArray();
368 OSDMap agentDataMap = new OSDMap();
369 agentDataMap.Add("AgentID", OSD.FromUUID(PlacesReply.AgentData.AgentID));
370 agentDataMap.Add("QueryID", OSD.FromUUID(PlacesReply.AgentData.QueryID));
371 agentDataMap.Add("TransactionID", OSD.FromUUID(PlacesReply.TransactionData.TransactionID));
372 agentData.Add(agentDataMap);
373 body.Add("AgentData", agentData);
374  
375 OSDArray QueryData = new OSDArray();
376  
377 foreach (PlacesReplyPacket.QueryDataBlock groupDataBlock in PlacesReply.QueryData)
378 {
379 OSDMap QueryDataMap = new OSDMap();
380 QueryDataMap.Add("ActualArea", OSD.FromInteger(groupDataBlock.ActualArea));
381 QueryDataMap.Add("BillableArea", OSD.FromInteger(groupDataBlock.BillableArea));
382 QueryDataMap.Add("Description", OSD.FromBinary(groupDataBlock.Desc));
383 QueryDataMap.Add("Dwell", OSD.FromInteger((int)groupDataBlock.Dwell));
384 QueryDataMap.Add("Flags", OSD.FromString(Convert.ToString(groupDataBlock.Flags)));
385 QueryDataMap.Add("GlobalX", OSD.FromInteger((int)groupDataBlock.GlobalX));
386 QueryDataMap.Add("GlobalY", OSD.FromInteger((int)groupDataBlock.GlobalY));
387 QueryDataMap.Add("GlobalZ", OSD.FromInteger((int)groupDataBlock.GlobalZ));
388 QueryDataMap.Add("Name", OSD.FromBinary(groupDataBlock.Name));
389 QueryDataMap.Add("OwnerID", OSD.FromUUID(groupDataBlock.OwnerID));
390 QueryDataMap.Add("SimName", OSD.FromBinary(groupDataBlock.SimName));
391 QueryDataMap.Add("SnapShotID", OSD.FromUUID(groupDataBlock.SnapshotID));
392 QueryDataMap.Add("ProductSku", OSD.FromInteger(0));
393 QueryDataMap.Add("Price", OSD.FromInteger(groupDataBlock.Price));
394  
395 QueryData.Add(QueryDataMap);
396 }
397 body.Add("QueryData", QueryData);
398 placesReply.Add("QueryData[]", body);
399  
400 return placesReply;
401 }
402  
403 public static OSD ParcelProperties(ParcelPropertiesMessage parcelPropertiesMessage)
404 {
405 OSDMap message = new OSDMap();
406 message.Add("message", OSD.FromString("ParcelProperties"));
407 OSD message_body = parcelPropertiesMessage.Serialize();
408 message.Add("body", message_body);
409 return message;
410 }
411  
412 public static OSD partPhysicsProperties(uint localID, byte physhapetype,
413 float density, float friction, float bounce, float gravmod)
414 {
415  
416 OSDMap physinfo = new OSDMap(6);
417 physinfo["LocalID"] = localID;
418 physinfo["Density"] = density;
419 physinfo["Friction"] = friction;
420 physinfo["GravityMultiplier"] = gravmod;
421 physinfo["Restitution"] = bounce;
422 physinfo["PhysicsShapeType"] = (int)physhapetype;
423  
424 OSDArray array = new OSDArray(1);
425 array.Add(physinfo);
426  
427 OSDMap llsdBody = new OSDMap(1);
428 llsdBody.Add("ObjectData", array);
429  
430 return BuildEvent("ObjectPhysicsProperties", llsdBody);
431 }
432 }
433 }