EventQueueHelper.cs 18 KB

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