1
0

EventQueueHelper.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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.Text;
  29. using System.Net;
  30. using OpenMetaverse;
  31. using OpenMetaverse.Packets;
  32. using OpenMetaverse.StructuredData;
  33. using OpenMetaverse.Messages.Linden;
  34. using OpenSim.Framework;
  35. namespace OpenSim.Region.ClientStack.Linden
  36. {
  37. public class EventQueueHelper
  38. {
  39. private EventQueueHelper() {} // no construction possible, it's an utility class
  40. public static StringBuilder StartEvent(string eventName)
  41. {
  42. StringBuilder sb = new StringBuilder(256);
  43. LLSDxmlEncode.AddMap(sb);
  44. LLSDxmlEncode.AddElem("message", eventName, sb);
  45. LLSDxmlEncode.AddMap("body", sb);
  46. return sb;
  47. }
  48. public static string EndEvent(StringBuilder sb)
  49. {
  50. LLSDxmlEncode.AddEndMap(sb); // close body
  51. LLSDxmlEncode.AddEndMap(sb); // close event
  52. return sb.ToString();
  53. }
  54. public static OSD BuildEvent(string eventName, OSD eventBody)
  55. {
  56. OSDMap llsdEvent = new OSDMap(2);
  57. llsdEvent.Add("message", new OSDString(eventName));
  58. llsdEvent.Add("body", eventBody);
  59. return llsdEvent;
  60. }
  61. public static OSD KeepAliveEvent()
  62. {
  63. return BuildEvent("FAKEEVENT", new OSDMap());
  64. }
  65. public static OSD AgentParams(UUID agentID, bool checkEstate, int godLevel, bool limitedToEstate)
  66. {
  67. OSDMap body = new OSDMap(4);
  68. body.Add("agent_id", new OSDUUID(agentID));
  69. body.Add("check_estate", new OSDInteger(checkEstate ? 1 : 0));
  70. body.Add("god_level", new OSDInteger(godLevel));
  71. body.Add("limited_to_estate", new OSDInteger(limitedToEstate ? 1 : 0));
  72. return body;
  73. }
  74. public static OSD InstantMessageParams(UUID fromAgent, string message, UUID toAgent,
  75. string fromName, byte dialog, uint timeStamp, bool offline, int parentEstateID,
  76. Vector3 position, uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
  77. {
  78. OSDMap messageParams = new OSDMap(15);
  79. messageParams.Add("type", new OSDInteger((int)dialog));
  80. OSDArray positionArray = new OSDArray(3);
  81. positionArray.Add(OSD.FromReal(position.X));
  82. positionArray.Add(OSD.FromReal(position.Y));
  83. positionArray.Add(OSD.FromReal(position.Z));
  84. messageParams.Add("position", positionArray);
  85. messageParams.Add("region_id", new OSDUUID(UUID.Zero));
  86. messageParams.Add("to_id", new OSDUUID(toAgent));
  87. messageParams.Add("source", new OSDInteger(0));
  88. OSDMap data = new OSDMap(1);
  89. data.Add("binary_bucket", OSD.FromBinary(binaryBucket));
  90. messageParams.Add("data", data);
  91. messageParams.Add("message", new OSDString(message));
  92. messageParams.Add("id", new OSDUUID(transactionID));
  93. messageParams.Add("from_name", new OSDString(fromName));
  94. messageParams.Add("timestamp", new OSDInteger((int)timeStamp));
  95. messageParams.Add("offline", new OSDInteger(offline ? 1 : 0));
  96. messageParams.Add("parent_estate_id", new OSDInteger(parentEstateID));
  97. messageParams.Add("ttl", new OSDInteger((int)ttl));
  98. messageParams.Add("from_id", new OSDUUID(fromAgent));
  99. messageParams.Add("from_group", new OSDInteger(fromGroup ? 1 : 0));
  100. /*
  101. StringBuilder sb = new StringBuilder(256);
  102. LLSDxmlEncode.AddMap(sb); //messageParams
  103. LLSDxmlEncode.AddElem("type", dialog, sb);
  104. LLSDxmlEncode.AddElem("position", position, sb);
  105. LLSDxmlEncode.AddElem("region_id", UUID.Zero, sb);
  106. LLSDxmlEncode.AddElem("to_id", toAgent, sb);
  107. LLSDxmlEncode.AddElem("source", 0, sb);
  108. LLSDxmlEncode.AddMap("data", sb); //messageParams data
  109. LLSDxmlEncode.AddElem("binary_bucket", binaryBucket, sb);
  110. LLSDxmlEncode.AddEndMap(sb); //messageParams data
  111. LLSDxmlEncode.AddElem("message", message, sb);
  112. LLSDxmlEncode.AddElem("id", transactionID, sb);
  113. LLSDxmlEncode.AddElem("from_name", fromName, sb);
  114. LLSDxmlEncode.AddElem("timestamp", timeStamp, sb);
  115. LLSDxmlEncode.AddElem("offline", (offline ? 1 : 0), sb);
  116. LLSDxmlEncode.AddElem("parent_estate_id", parentEstateID, sb);
  117. LLSDxmlEncode.AddElem("ttl", (int)ttl, sb);
  118. LLSDxmlEncode.AddElem("from_id", fromAgent, sb);
  119. LLSDxmlEncode.AddElem("from_group",fromGroup, sb);
  120. LLSDxmlEncode.AddEndMap(sb); //messageParams
  121. string tt = sb.ToString();
  122. */
  123. return messageParams;
  124. }
  125. public static OSD InstantMessage(UUID fromAgent, string message, UUID toAgent,
  126. string fromName, byte dialog, uint timeStamp, bool offline, int parentEstateID,
  127. Vector3 position, uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket,
  128. bool checkEstate, int godLevel, bool limitedToEstate)
  129. {
  130. OSDMap im = new OSDMap(2);
  131. im.Add("message_params", InstantMessageParams(fromAgent, message, toAgent,
  132. fromName, dialog, timeStamp, offline, parentEstateID,
  133. position, ttl, transactionID, fromGroup, binaryBucket));
  134. im.Add("agent_params", AgentParams(fromAgent, checkEstate, godLevel, limitedToEstate));
  135. return im;
  136. }
  137. public static OSD ChatterboxInvitation(UUID sessionID, string sessionName,
  138. UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog,
  139. uint timeStamp, bool offline, int parentEstateID, Vector3 position,
  140. uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
  141. {
  142. OSDMap body = new OSDMap(5);
  143. body.Add("session_id", new OSDUUID(sessionID));
  144. body.Add("from_name", new OSDString(fromName));
  145. body.Add("session_name", new OSDString(sessionName));
  146. body.Add("from_id", new OSDUUID(fromAgent));
  147. body.Add("instantmessage", InstantMessage(fromAgent, message, toAgent,
  148. fromName, dialog, timeStamp, offline, parentEstateID, position,
  149. ttl, transactionID, fromGroup, binaryBucket, true, 0, true));
  150. OSDMap chatterboxInvitation = new OSDMap(2);
  151. chatterboxInvitation.Add("message", new OSDString("ChatterBoxInvitation"));
  152. chatterboxInvitation.Add("body", body);
  153. return chatterboxInvitation;
  154. }
  155. public static OSD ChatterBoxSessionAgentListUpdates(UUID sessionID,
  156. UUID agentID, bool canVoiceChat, bool isModerator, bool textMute, bool isEnterorLeave)
  157. {
  158. OSDMap body = new OSDMap();
  159. OSDMap agentUpdates = new OSDMap();
  160. OSDMap infoDetail = new OSDMap();
  161. OSDMap mutes = new OSDMap();
  162. // this should be a list of agents and parameters
  163. // foreach agent
  164. mutes.Add("text", OSD.FromBoolean(textMute));
  165. infoDetail.Add("can_voice_chat", OSD.FromBoolean(canVoiceChat));
  166. infoDetail.Add("is_moderator", OSD.FromBoolean(isModerator));
  167. infoDetail.Add("mutes", mutes);
  168. OSDMap info = new OSDMap();
  169. info.Add("info", infoDetail);
  170. if(isEnterorLeave)
  171. info.Add("transition",OSD.FromString("ENTER"));
  172. else
  173. info.Add("transition",OSD.FromString("LEAVE"));
  174. agentUpdates.Add(agentID.ToString(), info);
  175. // foreach end
  176. body.Add("agent_updates", agentUpdates);
  177. body.Add("session_id", OSD.FromUUID(sessionID));
  178. body.Add("updates", new OSD());
  179. OSDMap chatterBoxSessionAgentListUpdates = new OSDMap();
  180. chatterBoxSessionAgentListUpdates.Add("message", OSD.FromString("ChatterBoxSessionAgentListUpdates"));
  181. chatterBoxSessionAgentListUpdates.Add("body", body);
  182. return chatterBoxSessionAgentListUpdates;
  183. }
  184. public static OSD ChatterBoxForceClose(UUID sessionID, string reason)
  185. {
  186. OSDMap body = new OSDMap(2);
  187. body.Add("session_id", new OSDUUID(sessionID));
  188. body.Add("reason", new OSDString(reason));
  189. OSDMap chatterBoxForceClose = new OSDMap(2);
  190. chatterBoxForceClose.Add("message", new OSDString("ForceCloseChatterBoxSession"));
  191. chatterBoxForceClose.Add("body", body);
  192. return chatterBoxForceClose;
  193. }
  194. public static OSD PlacesQuery(PlacesReplyPacket PlacesReply)
  195. {
  196. OSDMap placesReply = new OSDMap();
  197. placesReply.Add("message", OSD.FromString("PlacesReplyMessage"));
  198. OSDMap body = new OSDMap();
  199. OSDArray agentData = new OSDArray();
  200. OSDMap agentDataMap = new OSDMap();
  201. agentDataMap.Add("AgentID", OSD.FromUUID(PlacesReply.AgentData.AgentID));
  202. agentDataMap.Add("QueryID", OSD.FromUUID(PlacesReply.AgentData.QueryID));
  203. agentDataMap.Add("TransactionID", OSD.FromUUID(PlacesReply.TransactionData.TransactionID));
  204. agentData.Add(agentDataMap);
  205. body.Add("AgentData", agentData);
  206. OSDArray QueryData = new OSDArray();
  207. foreach (PlacesReplyPacket.QueryDataBlock groupDataBlock in PlacesReply.QueryData)
  208. {
  209. OSDMap QueryDataMap = new OSDMap();
  210. QueryDataMap.Add("ActualArea", OSD.FromInteger(groupDataBlock.ActualArea));
  211. QueryDataMap.Add("BillableArea", OSD.FromInteger(groupDataBlock.BillableArea));
  212. QueryDataMap.Add("Description", OSD.FromBinary(groupDataBlock.Desc));
  213. QueryDataMap.Add("Dwell", OSD.FromInteger((int)groupDataBlock.Dwell));
  214. QueryDataMap.Add("Flags", OSD.FromString(Convert.ToString(groupDataBlock.Flags)));
  215. QueryDataMap.Add("GlobalX", OSD.FromInteger((int)groupDataBlock.GlobalX));
  216. QueryDataMap.Add("GlobalY", OSD.FromInteger((int)groupDataBlock.GlobalY));
  217. QueryDataMap.Add("GlobalZ", OSD.FromInteger((int)groupDataBlock.GlobalZ));
  218. QueryDataMap.Add("Name", OSD.FromBinary(groupDataBlock.Name));
  219. QueryDataMap.Add("OwnerID", OSD.FromUUID(groupDataBlock.OwnerID));
  220. QueryDataMap.Add("SimName", OSD.FromBinary(groupDataBlock.SimName));
  221. QueryDataMap.Add("SnapShotID", OSD.FromUUID(groupDataBlock.SnapshotID));
  222. QueryDataMap.Add("ProductSku", OSD.FromInteger(0));
  223. QueryDataMap.Add("Price", OSD.FromInteger(groupDataBlock.Price));
  224. QueryData.Add(QueryDataMap);
  225. }
  226. body.Add("QueryData", QueryData);
  227. placesReply.Add("QueryData[]", body);
  228. return placesReply;
  229. }
  230. }
  231. }