EventQueueHelper.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. using System;
  28. using System.Net;
  29. using OpenMetaverse;
  30. using OpenMetaverse.StructuredData;
  31. namespace OpenSim.Region.Environment
  32. {
  33. public class EventQueueHelper
  34. {
  35. private EventQueueHelper() {} // no construction possible, it's an utility class
  36. private static byte[] regionHandleToByteArray(ulong regionHandle)
  37. {
  38. // Reverse endianness of RegionHandle
  39. return new byte[]
  40. {
  41. (byte)((regionHandle >> 56) % 256),
  42. (byte)((regionHandle >> 48) % 256),
  43. (byte)((regionHandle >> 40) % 256),
  44. (byte)((regionHandle >> 32) % 256),
  45. (byte)((regionHandle >> 24) % 256),
  46. (byte)((regionHandle >> 16) % 256),
  47. (byte)((regionHandle >> 8) % 256),
  48. (byte)(regionHandle % 256)
  49. };
  50. }
  51. public static OSD buildEvent(string eventName, OSD eventBody)
  52. {
  53. OSDMap llsdEvent = new OSDMap(2);
  54. llsdEvent.Add("message", new OSDString(eventName));
  55. llsdEvent.Add("body", eventBody);
  56. return llsdEvent;
  57. }
  58. public static OSD EnableSimulator(ulong Handle, IPEndPoint endPoint)
  59. {
  60. OSDMap llsdSimInfo = new OSDMap(3);
  61. llsdSimInfo.Add("Handle", new OSDBinary(regionHandleToByteArray(Handle)));
  62. llsdSimInfo.Add("IP", new OSDBinary(endPoint.Address.GetAddressBytes()));
  63. llsdSimInfo.Add("Port", new OSDInteger(endPoint.Port));
  64. OSDArray arr = new OSDArray(1);
  65. arr.Add(llsdSimInfo);
  66. OSDMap llsdBody = new OSDMap(1);
  67. llsdBody.Add("SimulatorInfo", arr);
  68. return buildEvent("EnableSimulator", llsdBody);
  69. }
  70. public static OSD DisableSimulator(ulong Handle)
  71. {
  72. //OSDMap llsdSimInfo = new OSDMap(1);
  73. //llsdSimInfo.Add("Handle", new OSDBinary(regionHandleToByteArray(Handle)));
  74. //OSDArray arr = new OSDArray(1);
  75. //arr.Add(llsdSimInfo);
  76. OSDMap llsdBody = new OSDMap(0);
  77. //llsdBody.Add("SimulatorInfo", arr);
  78. return buildEvent("DisableSimulator", llsdBody);
  79. }
  80. public static OSD CrossRegion(ulong Handle, Vector3 pos, Vector3 lookAt,
  81. IPEndPoint newRegionExternalEndPoint,
  82. string capsURL, UUID AgentID, UUID SessionID)
  83. {
  84. OSDArray LookAtArr = new OSDArray(3);
  85. LookAtArr.Add(OSD.FromReal(lookAt.X));
  86. LookAtArr.Add(OSD.FromReal(lookAt.Y));
  87. LookAtArr.Add(OSD.FromReal(lookAt.Z));
  88. OSDArray PositionArr = new OSDArray(3);
  89. PositionArr.Add(OSD.FromReal(pos.X));
  90. PositionArr.Add(OSD.FromReal(pos.Y));
  91. PositionArr.Add(OSD.FromReal(pos.Z));
  92. OSDMap InfoMap = new OSDMap(2);
  93. InfoMap.Add("LookAt", LookAtArr);
  94. InfoMap.Add("Position", PositionArr);
  95. OSDArray InfoArr = new OSDArray(1);
  96. InfoArr.Add(InfoMap);
  97. OSDMap AgentDataMap = new OSDMap(2);
  98. AgentDataMap.Add("AgentID", OSD.FromUUID(AgentID));
  99. AgentDataMap.Add("SessionID", OSD.FromUUID(SessionID));
  100. OSDArray AgentDataArr = new OSDArray(1);
  101. AgentDataArr.Add(AgentDataMap);
  102. OSDMap RegionDataMap = new OSDMap(4);
  103. RegionDataMap.Add("RegionHandle", OSD.FromBinary(regionHandleToByteArray(Handle)));
  104. RegionDataMap.Add("SeedCapability", OSD.FromString(capsURL));
  105. RegionDataMap.Add("SimIP", OSD.FromBinary(newRegionExternalEndPoint.Address.GetAddressBytes()));
  106. RegionDataMap.Add("SimPort", OSD.FromInteger(newRegionExternalEndPoint.Port));
  107. OSDArray RegionDataArr = new OSDArray(1);
  108. RegionDataArr.Add(RegionDataMap);
  109. OSDMap llsdBody = new OSDMap(3);
  110. llsdBody.Add("Info", InfoArr);
  111. llsdBody.Add("AgentData", AgentDataArr);
  112. llsdBody.Add("RegionData", RegionDataArr);
  113. return buildEvent("CrossedRegion", llsdBody);
  114. }
  115. public static OSD TeleportFinishEvent(
  116. ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint,
  117. uint locationID, uint flags, string capsURL, UUID AgentID)
  118. {
  119. OSDMap info = new OSDMap();
  120. info.Add("AgentID", OSD.FromUUID(AgentID));
  121. info.Add("LocationID", OSD.FromInteger(4)); // TODO what is this?
  122. info.Add("RegionHandle", OSD.FromBinary(regionHandleToByteArray(regionHandle)));
  123. info.Add("SeedCapability", OSD.FromString(capsURL));
  124. info.Add("SimAccess", OSD.FromInteger(simAccess));
  125. info.Add("SimIP", OSD.FromBinary(regionExternalEndPoint.Address.GetAddressBytes()));
  126. info.Add("SimPort", OSD.FromInteger(regionExternalEndPoint.Port));
  127. info.Add("TeleportFlags", OSD.FromBinary(1L << 4)); // AgentManager.TeleportFlags.ViaLocation
  128. OSDArray infoArr = new OSDArray();
  129. infoArr.Add(info);
  130. OSDMap body = new OSDMap();
  131. body.Add("Info", infoArr);
  132. return buildEvent("TeleportFinish", body);
  133. }
  134. public static OSD ScriptRunningReplyEvent(UUID objectID, UUID itemID, bool running, bool mono)
  135. {
  136. OSDMap script = new OSDMap();
  137. script.Add("ObjectID", OSD.FromUUID(objectID));
  138. script.Add("ItemID", OSD.FromUUID(itemID));
  139. script.Add("Running", OSD.FromBoolean(running));
  140. script.Add("Mono", OSD.FromBoolean(mono));
  141. OSDArray scriptArr = new OSDArray();
  142. scriptArr.Add(script);
  143. OSDMap body = new OSDMap();
  144. body.Add("Script", scriptArr);
  145. return buildEvent("ScriptRunningReply", body);
  146. }
  147. public static OSD EstablishAgentCommunication(UUID agentID, string simIpAndPort, string seedcap)
  148. {
  149. OSDMap body = new OSDMap(3);
  150. body.Add("agent-id", new OSDUUID(agentID));
  151. body.Add("sim-ip-and-port", new OSDString(simIpAndPort));
  152. body.Add("seed-capability", new OSDString(seedcap));
  153. return buildEvent("EstablishAgentCommunication", body);
  154. }
  155. public static OSD KeepAliveEvent()
  156. {
  157. return buildEvent("FAKEEVENT", new OSDMap());
  158. }
  159. }
  160. }