/Aurora/AuroraDotNetEngine/ScriptPlugins/XmlRequest.cs
C# | 156 lines | 105 code | 23 blank | 28 comment | 11 complexity | 5135875591536a8e721dccb0a6f9d509 MD5 | raw file
1/* 2 * Copyright (c) Contributors, http://aurora-sim.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 Aurora-Sim 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 28using System; 29using System.Collections.Generic; 30using Aurora.Framework; 31using Aurora.Framework.Modules; 32using Aurora.Framework.SceneInfo; 33using OpenMetaverse; 34using OpenMetaverse.StructuredData; 35 36namespace Aurora.ScriptEngine.AuroraDotNetEngine.Plugins 37{ 38 public class XmlRequestPlugin : IScriptPlugin 39 { 40 private readonly List<IXMLRPC> m_modules = new List<IXMLRPC>(); 41 public ScriptEngine m_ScriptEngine; 42 43 #region IScriptPlugin Members 44 45 public bool RemoveOnStateChange 46 { 47 get { return false; } 48 } 49 50 public void Initialize(ScriptEngine ScriptEngine) 51 { 52 m_ScriptEngine = ScriptEngine; 53 } 54 55 public void AddRegion(IScene scene) 56 { 57 m_modules.Add(scene.RequestModuleInterface<IXMLRPC>()); 58 } 59 60 public bool Check() 61 { 62 bool needToContinue = false; 63 foreach (IXMLRPC xmlrpc in m_modules) 64 { 65 if (xmlrpc == null) 66 continue; 67 IXmlRpcRequestInfo rInfo = xmlrpc.GetNextCompletedRequest(); 68 ISendRemoteDataRequest srdInfo = (ISendRemoteDataRequest) xmlrpc.GetNextCompletedSRDRequest(); 69 70 if (!needToContinue) 71 needToContinue = xmlrpc.hasRequests(); 72 73 if (rInfo == null && srdInfo == null) 74 continue; 75 76 while (rInfo != null) 77 { 78 xmlrpc.RemoveCompletedRequest(rInfo.GetMessageID()); 79 80 //Deliver data to prim's remote_data handler 81 object[] resobj = new object[] 82 { 83 new LSL_Types.LSLInteger(2), 84 new LSL_Types.LSLString( 85 rInfo.GetChannelKey().ToString()), 86 new LSL_Types.LSLString( 87 rInfo.GetMessageID().ToString()), 88 new LSL_Types.LSLString(String.Empty), 89 new LSL_Types.LSLInteger(rInfo.GetIntValue()), 90 new LSL_Types.LSLString(rInfo.GetStrVal()) 91 }; 92 93 m_ScriptEngine.PostScriptEvent( 94 rInfo.GetItemID(), rInfo.GetPrimID(), new EventParams( 95 "remote_data", resobj, 96 new DetectParams[0]), EventPriority.Suspended); 97 98 rInfo = xmlrpc.GetNextCompletedRequest(); 99 } 100 101 while (srdInfo != null) 102 { 103 xmlrpc.RemoveCompletedSRDRequest(srdInfo.GetReqID()); 104 105 //Deliver data to prim's remote_data handler 106 object[] resobj = new object[] 107 { 108 new LSL_Types.LSLInteger(3), 109 new LSL_Types.LSLString(srdInfo.Channel), 110 new LSL_Types.LSLString(srdInfo.GetReqID().ToString()), 111 new LSL_Types.LSLString(String.Empty), 112 new LSL_Types.LSLInteger(srdInfo.Idata), 113 new LSL_Types.LSLString(srdInfo.Sdata) 114 }; 115 116 m_ScriptEngine.PostScriptEvent( 117 srdInfo.ItemID, srdInfo.PrimID, new EventParams( 118 "remote_data", resobj, 119 new DetectParams[0]), EventPriority.Suspended); 120 121 srdInfo = (ISendRemoteDataRequest) xmlrpc.GetNextCompletedSRDRequest(); 122 } 123 } 124 return needToContinue; 125 } 126 127 public string Name 128 { 129 get { return "XmlRequest"; } 130 } 131 132 public OSD GetSerializationData(UUID itemID, UUID primID) 133 { 134 return ""; 135 } 136 137 public void CreateFromData(UUID itemID, UUID objectID, OSD data) 138 { 139 } 140 141 public void RemoveScript(UUID primID, UUID itemID) 142 { 143 foreach (IXMLRPC xmlrpc in m_modules) 144 { 145 xmlrpc.DeleteChannels(itemID); 146 xmlrpc.CancelSRDRequests(itemID); 147 } 148 } 149 150 #endregion 151 152 public void Dispose() 153 { 154 } 155 } 156}