XmlRequest.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 OpenSim.Region.Environment.Interfaces;
  29. using OpenSim.Region.Environment.Modules.Scripting.XMLRPC;
  30. using OpenSim.Region.ScriptEngine.Interfaces;
  31. using OpenSim.Region.ScriptEngine.Shared;
  32. using OpenSim.Region.ScriptEngine.Shared.Api;
  33. namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
  34. {
  35. public class XmlRequest
  36. {
  37. public AsyncCommandManager m_CmdManager;
  38. public XmlRequest(AsyncCommandManager CmdManager)
  39. {
  40. m_CmdManager = CmdManager;
  41. }
  42. public void CheckXMLRPCRequests()
  43. {
  44. if (m_CmdManager.m_ScriptEngine.World == null)
  45. return;
  46. IXMLRPC xmlrpc = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  47. if (xmlrpc != null)
  48. {
  49. RPCRequestInfo rInfo = xmlrpc.GetNextCompletedRequest();
  50. while (rInfo != null)
  51. {
  52. xmlrpc.RemoveCompletedRequest(rInfo.GetMessageID());
  53. //Deliver data to prim's remote_data handler
  54. object[] resobj = new object[]
  55. {
  56. new LSL_Types.LSLInteger(2),
  57. new LSL_Types.LSLString(
  58. rInfo.GetChannelKey().ToString()),
  59. new LSL_Types.LSLString(
  60. rInfo.GetMessageID().ToString()),
  61. new LSL_Types.LSLString(String.Empty),
  62. new LSL_Types.LSLInteger(rInfo.GetIntValue()),
  63. new LSL_Types.LSLString(rInfo.GetStrVal())
  64. };
  65. foreach (AsyncCommandManager m in m_CmdManager.Managers)
  66. {
  67. if (m.m_ScriptEngine.PostScriptEvent(
  68. rInfo.GetItemID(), new EventParams(
  69. "remote_data", resobj,
  70. new DetectParams[0])))
  71. break;
  72. }
  73. rInfo = xmlrpc.GetNextCompletedRequest();
  74. }
  75. SendRemoteDataRequest srdInfo = xmlrpc.GetNextCompletedSRDRequest();
  76. while (srdInfo != null)
  77. {
  78. xmlrpc.RemoveCompletedSRDRequest(srdInfo.GetReqID());
  79. //Deliver data to prim's remote_data handler
  80. object[] resobj = new object[]
  81. {
  82. new LSL_Types.LSLInteger(3),
  83. new LSL_Types.LSLString(srdInfo.channel.ToString()),
  84. new LSL_Types.LSLString(srdInfo.GetReqID().ToString()),
  85. new LSL_Types.LSLString(String.Empty),
  86. new LSL_Types.LSLInteger(srdInfo.idata),
  87. new LSL_Types.LSLString(srdInfo.sdata)
  88. };
  89. foreach (AsyncCommandManager m in m_CmdManager.Managers)
  90. {
  91. if (m.m_ScriptEngine.PostScriptEvent(
  92. srdInfo.m_itemID, new EventParams(
  93. "remote_data", resobj,
  94. new DetectParams[0])))
  95. break;
  96. }
  97. srdInfo = xmlrpc.GetNextCompletedSRDRequest();
  98. }
  99. }
  100. }
  101. }
  102. }