OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
EventQueueHelper.cs
Go to the documentation of this file.
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", OSD.FromInteger(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  // not sure why flags get overwritten here
161  if ((flags & (uint)TeleportFlags.IsFlying) != 0)
162  flags = (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.IsFlying;
163  else
164  flags = (uint)TeleportFlags.ViaLocation;
165 
166  OSDMap info = new OSDMap();
167  info.Add("AgentID", OSD.FromUUID(agentID));
168  info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this?
169  info.Add("RegionHandle", OSD.FromBinary(ulongToByteArray(regionHandle)));
170  info.Add("SeedCapability", OSD.FromString(capsURL));
171  info.Add("SimAccess", OSD.FromInteger(simAccess));
172  info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes()));
173  info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port));
174 // info.Add("TeleportFlags", OSD.FromULong(1L << 4)); // AgentManager.TeleportFlags.ViaLocation
175  info.Add("TeleportFlags", OSD.FromUInteger(flags));
176  info.Add("RegionSizeX", OSD.FromUInteger((uint)regionSizeX));
177  info.Add("RegionSizeY", OSD.FromUInteger((uint)regionSizeY));
178 
179  OSDArray infoArr = new OSDArray();
180  infoArr.Add(info);
181 
182  OSDMap body = new OSDMap();
183  body.Add("Info", infoArr);
184 
185  return BuildEvent("TeleportFinish", body);
186  }
187 
188  public static OSD ScriptRunningReplyEvent(UUID objectID, UUID itemID, bool running, bool mono)
189  {
190  OSDMap script = new OSDMap();
191  script.Add("ObjectID", OSD.FromUUID(objectID));
192  script.Add("ItemID", OSD.FromUUID(itemID));
193  script.Add("Running", OSD.FromBoolean(running));
194  script.Add("Mono", OSD.FromBoolean(mono));
195 
196  OSDArray scriptArr = new OSDArray();
197  scriptArr.Add(script);
198 
199  OSDMap body = new OSDMap();
200  body.Add("Script", scriptArr);
201 
202  return BuildEvent("ScriptRunningReply", body);
203  }
204 
205  public static OSD EstablishAgentCommunication(UUID agentID, string simIpAndPort, string seedcap,
206  ulong regionHandle, int regionSizeX, int regionSizeY)
207  {
208  OSDMap body = new OSDMap(6)
209  {
210  {"agent-id", new OSDUUID(agentID)},
211  {"sim-ip-and-port", new OSDString(simIpAndPort)},
212  {"seed-capability", new OSDString(seedcap)},
213  {"region-handle", OSD.FromULong(regionHandle)},
214  {"region-size-x", OSD.FromUInteger((uint)regionSizeX)},
215  {"region-size-y", OSD.FromUInteger((uint)regionSizeY)}
216  };
217 
218  return BuildEvent("EstablishAgentCommunication", body);
219  }
220 
221  public static OSD KeepAliveEvent()
222  {
223  return BuildEvent("FAKEEVENT", new OSDMap());
224  }
225 
226  public static OSD AgentParams(UUID agentID, bool checkEstate, int godLevel, bool limitedToEstate)
227  {
228  OSDMap body = new OSDMap(4);
229 
230  body.Add("agent_id", new OSDUUID(agentID));
231  body.Add("check_estate", new OSDInteger(checkEstate ? 1 : 0));
232  body.Add("god_level", new OSDInteger(godLevel));
233  body.Add("limited_to_estate", new OSDInteger(limitedToEstate ? 1 : 0));
234 
235  return body;
236  }
237 
238  public static OSD InstantMessageParams(UUID fromAgent, string message, UUID toAgent,
239  string fromName, byte dialog, uint timeStamp, bool offline, int parentEstateID,
240  Vector3 position, uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
241  {
242  OSDMap messageParams = new OSDMap(15);
243  messageParams.Add("type", new OSDInteger((int)dialog));
244 
245  OSDArray positionArray = new OSDArray(3);
246  positionArray.Add(OSD.FromReal(position.X));
247  positionArray.Add(OSD.FromReal(position.Y));
248  positionArray.Add(OSD.FromReal(position.Z));
249  messageParams.Add("position", positionArray);
250 
251  messageParams.Add("region_id", new OSDUUID(UUID.Zero));
252  messageParams.Add("to_id", new OSDUUID(toAgent));
253  messageParams.Add("source", new OSDInteger(0));
254 
255  OSDMap data = new OSDMap(1);
256  data.Add("binary_bucket", OSD.FromBinary(binaryBucket));
257  messageParams.Add("data", data);
258  messageParams.Add("message", new OSDString(message));
259  messageParams.Add("id", new OSDUUID(transactionID));
260  messageParams.Add("from_name", new OSDString(fromName));
261  messageParams.Add("timestamp", new OSDInteger((int)timeStamp));
262  messageParams.Add("offline", new OSDInteger(offline ? 1 : 0));
263  messageParams.Add("parent_estate_id", new OSDInteger(parentEstateID));
264  messageParams.Add("ttl", new OSDInteger((int)ttl));
265  messageParams.Add("from_id", new OSDUUID(fromAgent));
266  messageParams.Add("from_group", new OSDInteger(fromGroup ? 1 : 0));
267 
268  return messageParams;
269  }
270 
271  public static OSD InstantMessage(UUID fromAgent, string message, UUID toAgent,
272  string fromName, byte dialog, uint timeStamp, bool offline, int parentEstateID,
273  Vector3 position, uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket,
274  bool checkEstate, int godLevel, bool limitedToEstate)
275  {
276  OSDMap im = new OSDMap(2);
277  im.Add("message_params", InstantMessageParams(fromAgent, message, toAgent,
278  fromName, dialog, timeStamp, offline, parentEstateID,
279  position, ttl, transactionID, fromGroup, binaryBucket));
280 
281  im.Add("agent_params", AgentParams(fromAgent, checkEstate, godLevel, limitedToEstate));
282 
283  return im;
284  }
285 
286 
287  public static OSD ChatterboxInvitation(UUID sessionID, string sessionName,
288  UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog,
289  uint timeStamp, bool offline, int parentEstateID, Vector3 position,
290  uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
291  {
292  OSDMap body = new OSDMap(5);
293  body.Add("session_id", new OSDUUID(sessionID));
294  body.Add("from_name", new OSDString(fromName));
295  body.Add("session_name", new OSDString(sessionName));
296  body.Add("from_id", new OSDUUID(fromAgent));
297 
298  body.Add("instantmessage", InstantMessage(fromAgent, message, toAgent,
299  fromName, dialog, timeStamp, offline, parentEstateID, position,
300  ttl, transactionID, fromGroup, binaryBucket, true, 0, true));
301 
302  OSDMap chatterboxInvitation = new OSDMap(2);
303  chatterboxInvitation.Add("message", new OSDString("ChatterBoxInvitation"));
304  chatterboxInvitation.Add("body", body);
305  return chatterboxInvitation;
306  }
307 
308  public static OSD ChatterBoxSessionAgentListUpdates(UUID sessionID,
309  UUID agentID, bool canVoiceChat, bool isModerator, bool textMute)
310  {
311  OSDMap body = new OSDMap();
312  OSDMap agentUpdates = new OSDMap();
313  OSDMap infoDetail = new OSDMap();
314  OSDMap mutes = new OSDMap();
315 
316  mutes.Add("text", OSD.FromBoolean(textMute));
317  infoDetail.Add("can_voice_chat", OSD.FromBoolean(canVoiceChat));
318  infoDetail.Add("is_moderator", OSD.FromBoolean(isModerator));
319  infoDetail.Add("mutes", mutes);
320  OSDMap info = new OSDMap();
321  info.Add("info", infoDetail);
322  agentUpdates.Add(agentID.ToString(), info);
323  body.Add("agent_updates", agentUpdates);
324  body.Add("session_id", OSD.FromUUID(sessionID));
325  body.Add("updates", new OSD());
326 
327  OSDMap chatterBoxSessionAgentListUpdates = new OSDMap();
328  chatterBoxSessionAgentListUpdates.Add("message", OSD.FromString("ChatterBoxSessionAgentListUpdates"));
329  chatterBoxSessionAgentListUpdates.Add("body", body);
330 
331  return chatterBoxSessionAgentListUpdates;
332  }
333 
334  public static OSD GroupMembership(AgentGroupDataUpdatePacket groupUpdatePacket)
335  {
336  OSDMap groupUpdate = new OSDMap();
337  groupUpdate.Add("message", OSD.FromString("AgentGroupDataUpdate"));
338 
339  OSDMap body = new OSDMap();
340  OSDArray agentData = new OSDArray();
341  OSDMap agentDataMap = new OSDMap();
342  agentDataMap.Add("AgentID", OSD.FromUUID(groupUpdatePacket.AgentData.AgentID));
343  agentData.Add(agentDataMap);
344  body.Add("AgentData", agentData);
345 
346  OSDArray groupData = new OSDArray();
347 
348  foreach (AgentGroupDataUpdatePacket.GroupDataBlock groupDataBlock in groupUpdatePacket.GroupData)
349  {
350  OSDMap groupDataMap = new OSDMap();
351  groupDataMap.Add("ListInProfile", OSD.FromBoolean(false));
352  groupDataMap.Add("GroupID", OSD.FromUUID(groupDataBlock.GroupID));
353  groupDataMap.Add("GroupInsigniaID", OSD.FromUUID(groupDataBlock.GroupInsigniaID));
354  groupDataMap.Add("Contribution", OSD.FromInteger(groupDataBlock.Contribution));
355  groupDataMap.Add("GroupPowers", OSD.FromBinary(ulongToByteArray(groupDataBlock.GroupPowers)));
356  groupDataMap.Add("GroupName", OSD.FromString(Utils.BytesToString(groupDataBlock.GroupName)));
357  groupDataMap.Add("AcceptNotices", OSD.FromBoolean(groupDataBlock.AcceptNotices));
358 
359  groupData.Add(groupDataMap);
360 
361  }
362  body.Add("GroupData", groupData);
363  groupUpdate.Add("body", body);
364 
365  return groupUpdate;
366  }
367 
368  public static OSD PlacesQuery(PlacesReplyPacket PlacesReply)
369  {
370  OSDMap placesReply = new OSDMap();
371  placesReply.Add("message", OSD.FromString("PlacesReplyMessage"));
372 
373  OSDMap body = new OSDMap();
374  OSDArray agentData = new OSDArray();
375  OSDMap agentDataMap = new OSDMap();
376  agentDataMap.Add("AgentID", OSD.FromUUID(PlacesReply.AgentData.AgentID));
377  agentDataMap.Add("QueryID", OSD.FromUUID(PlacesReply.AgentData.QueryID));
378  agentDataMap.Add("TransactionID", OSD.FromUUID(PlacesReply.TransactionData.TransactionID));
379  agentData.Add(agentDataMap);
380  body.Add("AgentData", agentData);
381 
382  OSDArray QueryData = new OSDArray();
383 
384  foreach (PlacesReplyPacket.QueryDataBlock groupDataBlock in PlacesReply.QueryData)
385  {
386  OSDMap QueryDataMap = new OSDMap();
387  QueryDataMap.Add("ActualArea", OSD.FromInteger(groupDataBlock.ActualArea));
388  QueryDataMap.Add("BillableArea", OSD.FromInteger(groupDataBlock.BillableArea));
389  QueryDataMap.Add("Description", OSD.FromBinary(groupDataBlock.Desc));
390  QueryDataMap.Add("Dwell", OSD.FromInteger((int)groupDataBlock.Dwell));
391  QueryDataMap.Add("Flags", OSD.FromString(Convert.ToString(groupDataBlock.Flags)));
392  QueryDataMap.Add("GlobalX", OSD.FromInteger((int)groupDataBlock.GlobalX));
393  QueryDataMap.Add("GlobalY", OSD.FromInteger((int)groupDataBlock.GlobalY));
394  QueryDataMap.Add("GlobalZ", OSD.FromInteger((int)groupDataBlock.GlobalZ));
395  QueryDataMap.Add("Name", OSD.FromBinary(groupDataBlock.Name));
396  QueryDataMap.Add("OwnerID", OSD.FromUUID(groupDataBlock.OwnerID));
397  QueryDataMap.Add("SimName", OSD.FromBinary(groupDataBlock.SimName));
398  QueryDataMap.Add("SnapShotID", OSD.FromUUID(groupDataBlock.SnapshotID));
399  QueryDataMap.Add("ProductSku", OSD.FromInteger(0));
400  QueryDataMap.Add("Price", OSD.FromInteger(groupDataBlock.Price));
401 
402  QueryData.Add(QueryDataMap);
403  }
404  body.Add("QueryData", QueryData);
405  placesReply.Add("QueryData[]", body);
406 
407  return placesReply;
408  }
409 
410  public static OSD ParcelProperties(ParcelPropertiesMessage parcelPropertiesMessage)
411  {
412  OSDMap message = new OSDMap();
413  message.Add("message", OSD.FromString("ParcelProperties"));
414  OSD message_body = parcelPropertiesMessage.Serialize();
415  message.Add("body", message_body);
416  return message;
417  }
418 
419  public static OSD partPhysicsProperties(uint localID, byte physhapetype,
420  float density, float friction, float bounce, float gravmod)
421  {
422 
423  OSDMap physinfo = new OSDMap(6);
424  physinfo["LocalID"] = localID;
425  physinfo["Density"] = density;
426  physinfo["Friction"] = friction;
427  physinfo["GravityMultiplier"] = gravmod;
428  physinfo["Restitution"] = bounce;
429  physinfo["PhysicsShapeType"] = (int)physhapetype;
430 
431  OSDArray array = new OSDArray(1);
432  array.Add(physinfo);
433 
434  OSDMap llsdBody = new OSDMap(1);
435  llsdBody.Add("ObjectData", array);
436 
437  return BuildEvent("ObjectPhysicsProperties", llsdBody);
438  }
439  }
440 }
static OSD GroupMembership(AgentGroupDataUpdatePacket groupUpdatePacket)
static OSD EstablishAgentCommunication(UUID agentID, string simIpAndPort, string seedcap, ulong regionHandle, int regionSizeX, int regionSizeY)
OpenMetaverse.StructuredData.OSDArray OSDArray
OpenSim.Framework.Constants.TeleportFlags TeleportFlags
static OSD ChatterboxInvitation(UUID sessionID, string sessionName, UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog, uint timeStamp, bool offline, int parentEstateID, Vector3 position, uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
static OSD PlacesQuery(PlacesReplyPacket PlacesReply)
OpenMetaverse.StructuredData.OSDMap OSDMap
static OSD ScriptRunningReplyEvent(UUID objectID, UUID itemID, bool running, bool mono)
static OSD ChatterBoxSessionAgentListUpdates(UUID sessionID, UUID agentID, bool canVoiceChat, bool isModerator, bool textMute)
static OSD CrossRegion(ulong handle, Vector3 pos, Vector3 lookAt, IPEndPoint newRegionExternalEndPoint, string capsURL, UUID agentID, UUID sessionID, int regionSizeX, int regionSizeY)
OpenMetaverse.StructuredData.OSD OSD
static OSD InstantMessage(UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog, uint timeStamp, bool offline, int parentEstateID, Vector3 position, uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket, bool checkEstate, int godLevel, bool limitedToEstate)
static OSD partPhysicsProperties(uint localID, byte physhapetype, float density, float friction, float bounce, float gravmod)
static OSD ParcelProperties(ParcelPropertiesMessage parcelPropertiesMessage)
static OSD EnableSimulator(ulong handle, IPEndPoint endPoint, int regionSizeX, int regionSizeY)
static OSD BuildEvent(string eventName, OSD eventBody)
static OSD AgentParams(UUID agentID, bool checkEstate, int godLevel, bool limitedToEstate)
static OSD InstantMessageParams(UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog, uint timeStamp, bool offline, int parentEstateID, Vector3 position, uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
static OSD TeleportFinishEvent(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, uint locationID, uint flags, string capsURL, UUID agentID, int regionSizeX, int regionSizeY)