EventManager.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. /* Original code: Tedd Hansen */
  28. using System;
  29. using libsecondlife;
  30. using OpenSim.Framework;
  31. using OpenSim.Region.ScriptEngine.Common;
  32. using OpenSim.Region.ScriptEngine.Common.TRPC;
  33. namespace OpenSim.Region.ScriptEngine.RemoteServer
  34. {
  35. /// <summary>
  36. /// Handles events from OpenSim. Uses RemoteServer to send commands.
  37. /// </summary>
  38. [Serializable]
  39. internal class EventManager
  40. {
  41. // TODO: unused: System.Collections.Generic.Dictionary<uint, ScriptServerInterfaces.ServerRemotingObject> remoteScript = new System.Collections.Generic.Dictionary<uint, ScriptServerInterfaces.ServerRemotingObject>();
  42. TCPClient m_TCPClient;
  43. TRPC_Remote RPC;
  44. int myScriptServerID;
  45. string remoteHost = "127.0.0.1";
  46. int remotePort = 8010;
  47. private ScriptEngine myScriptEngine;
  48. public EventManager(ScriptEngine _ScriptEngine)
  49. {
  50. myScriptEngine = _ScriptEngine;
  51. m_TCPClient = new TCPClient();
  52. RPC = new TRPC_Remote(m_TCPClient);
  53. RPC.ReceiveCommand += new TRPC_Remote.ReceiveCommandDelegate(RPC_ReceiveCommand);
  54. myScriptServerID = m_TCPClient.ConnectAndReturnID(remoteHost, remotePort);
  55. myScriptEngine.Log.Info("[RemoteEngine]: Hooking up to server events");
  56. //myScriptEngine.World.EventManager.OnObjectGrab += touch_start;
  57. myScriptEngine.World.EventManager.OnRezScript += OnRezScript;
  58. //myScriptEngine.World.EventManager.OnRemoveScript += OnRemoveScript;
  59. }
  60. void RPC_ReceiveCommand(int ID, string Command, params object[] p)
  61. {
  62. myScriptEngine.Log.Info("[REMOTESERVER]: Received command: '" + Command + "'");
  63. if (p != null)
  64. {
  65. for (int i = 0; i < p.Length; i++)
  66. {
  67. myScriptEngine.Log.Info("[REMOTESERVER]: Param " + i + ": " + p[i].ToString());
  68. }
  69. }
  70. }
  71. public void OnRezScript(uint localID, LLUUID itemID, string script)
  72. {
  73. // WE ARE CREATING A NEW SCRIPT ... CREATE SCRIPT, GET A REMOTEID THAT WE MAP FROM LOCALID
  74. myScriptEngine.Log.Info("[RemoteEngine]: Creating new script (with connection)");
  75. // Temp for now: We have one connection only - this is hardcoded in myScriptServerID
  76. RPC.SendCommand(myScriptServerID, "OnRezScript", localID, itemID.ToString(), script);
  77. //ScriptServerInterfaces.ServerRemotingObject obj = myScriptEngine.m_RemoteServer.Connect("localhost", 1234);
  78. //remoteScript.Add(localID, obj);
  79. //remoteScript[localID].Events().OnRezScript(localID, itemID, script);
  80. }
  81. public void touch_start(uint localID, LLVector3 offsetPos, IClientAPI remoteClient)
  82. {
  83. //remoteScript[localID].Events.touch_start(localID, offsetPos, remoteClient);
  84. RPC.SendCommand(myScriptServerID, "touch_start", offsetPos, "How to transfer IClientAPI?");
  85. }
  86. // PLACEHOLDERS -- CODE WILL CHANGE!
  87. //public void OnRemoveScript(uint localID, LLUUID itemID)
  88. //{
  89. // remoteScript[localID].Events.OnRemoveScript(localID, itemID);
  90. //}
  91. //public void state_exit(uint localID, LLUUID itemID)
  92. //{
  93. // remoteScript[localID].Events.state_exit(localID, itemID);
  94. //}
  95. //public void touch(uint localID, LLUUID itemID)
  96. //{
  97. // remoteScript[localID].Events.touch(localID, itemID);
  98. //}
  99. //public void touch_end(uint localID, LLUUID itemID)
  100. //{
  101. // remoteScript[localID].Events.touch_end(localID, itemID);
  102. //}
  103. //public void collision_start(uint localID, LLUUID itemID)
  104. //{
  105. // remoteScript[localID].Events.collision_start(localID, itemID);
  106. //}
  107. //public void collision(uint localID, LLUUID itemID)
  108. //{
  109. // remoteScript[localID].Events.collision(localID, itemID);
  110. //}
  111. //public void collision_end(uint localID, LLUUID itemID)
  112. //{
  113. // remoteScript[localID].Events.collision_end(localID, itemID);
  114. //}
  115. //public void land_collision_start(uint localID, LLUUID itemID)
  116. //{
  117. // remoteScript[localID].Events.land_collision_start(localID, itemID);
  118. //}
  119. //public void land_collision(uint localID, LLUUID itemID)
  120. //{
  121. // remoteScript[localID].Events.land_collision(localID, itemID);
  122. //}
  123. //public void land_collision_end(uint localID, LLUUID itemID)
  124. //{
  125. // remoteScript[localID].Events.land_collision_end(localID, itemID);
  126. //}
  127. //public void timer(uint localID, LLUUID itemID)
  128. //{
  129. // remoteScript[localID].Events.timer(localID, itemID);
  130. //}
  131. //public void listen(uint localID, LLUUID itemID)
  132. //{
  133. // remoteScript[localID].Events.listen(localID, itemID);
  134. //}
  135. //public void on_rez(uint localID, LLUUID itemID)
  136. //{
  137. // remoteScript[localID].Events.on_rez(localID, itemID);
  138. //}
  139. //public void sensor(uint localID, LLUUID itemID)
  140. //{
  141. // remoteScript[localID].Events.sensor(localID, itemID);
  142. //}
  143. //public void no_sensor(uint localID, LLUUID itemID)
  144. //{
  145. // remoteScript[localID].Events.no_sensor(localID, itemID);
  146. //}
  147. //public void control(uint localID, LLUUID itemID)
  148. //{
  149. // remoteScript[localID].Events.control(localID, itemID);
  150. //}
  151. //public void money(uint localID, LLUUID itemID)
  152. //{
  153. // remoteScript[localID].Events.money(localID, itemID);
  154. //}
  155. //public void email(uint localID, LLUUID itemID)
  156. //{
  157. // remoteScript[localID].Events.email(localID, itemID);
  158. //}
  159. //public void at_target(uint localID, LLUUID itemID)
  160. //{
  161. // remoteScript[localID].Events.at_target(localID, itemID);
  162. //}
  163. //public void not_at_target(uint localID, LLUUID itemID)
  164. //{
  165. // remoteScript[localID].Events.not_at_target(localID, itemID);
  166. //}
  167. //public void at_rot_target(uint localID, LLUUID itemID)
  168. //{
  169. // remoteScript[localID].Events.at_rot_target(localID, itemID);
  170. //}
  171. //public void not_at_rot_target(uint localID, LLUUID itemID)
  172. //{
  173. // remoteScript[localID].Events.not_at_rot_target(localID, itemID);
  174. //}
  175. //public void run_time_permissions(uint localID, LLUUID itemID)
  176. //{
  177. // remoteScript[localID].Events.run_time_permissions(localID, itemID);
  178. //}
  179. //public void changed(uint localID, LLUUID itemID)
  180. //{
  181. // remoteScript[localID].Events.changed(localID, itemID);
  182. //}
  183. //public void attach(uint localID, LLUUID itemID)
  184. //{
  185. // remoteScript[localID].Events.attach(localID, itemID);
  186. //}
  187. //public void dataserver(uint localID, LLUUID itemID)
  188. //{
  189. // remoteScript[localID].Events.dataserver(localID, itemID);
  190. //}
  191. //public void link_message(uint localID, LLUUID itemID)
  192. //{
  193. // remoteScript[localID].Events.link_message(localID, itemID);
  194. //}
  195. //public void moving_start(uint localID, LLUUID itemID)
  196. //{
  197. // remoteScript[localID].Events.moving_start(localID, itemID);
  198. //}
  199. //public void moving_end(uint localID, LLUUID itemID)
  200. //{
  201. // remoteScript[localID].Events.moving_end(localID, itemID);
  202. //}
  203. //public void object_rez(uint localID, LLUUID itemID)
  204. //{
  205. // remoteScript[localID].Events.object_rez(localID, itemID);
  206. //}
  207. //public void remote_data(uint localID, LLUUID itemID)
  208. //{
  209. // remoteScript[localID].Events.remote_data(localID, itemID);
  210. //}
  211. //public void http_response(uint localID, LLUUID itemID)
  212. //{
  213. // remoteScript[localID].Events.http_response(localID, itemID);
  214. //}
  215. }
  216. }