MessageServersConnector.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. */
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Text;
  32. using System.Threading;
  33. using libsecondlife;
  34. using Nwc.XmlRpc;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Communications.Cache;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Framework.Servers;
  39. namespace OpenSim.Grid.UserServer
  40. {
  41. public class MessageServersConnector
  42. {
  43. private LogBase m_log;
  44. public Dictionary<string, MessageServerInfo> MessageServers;
  45. public MessageServersConnector(LogBase log)
  46. {
  47. m_log=log;
  48. MessageServers = new Dictionary<string, MessageServerInfo>();
  49. }
  50. public void RegisterMessageServer(string URI, MessageServerInfo serverData)
  51. {
  52. MessageServers.Add(URI, serverData);
  53. }
  54. public void DeRegisterMessageServer(string URI)
  55. {
  56. MessageServers.Remove(URI);
  57. }
  58. public void AddResponsibleRegion(string URI, ulong regionhandle)
  59. {
  60. if (!MessageServers.ContainsKey(URI))
  61. {
  62. m_log.Warn("MSGSERVER", "Got addResponsibleRegion Request for a MessageServer that isn't registered");
  63. }
  64. else
  65. {
  66. MessageServerInfo msginfo = MessageServers["URI"];
  67. msginfo.responsibleForRegions.Add(regionhandle);
  68. MessageServers["URI"] = msginfo;
  69. }
  70. }
  71. public void RemoveResponsibleRegion(string URI, ulong regionhandle)
  72. {
  73. if (!MessageServers.ContainsKey(URI))
  74. {
  75. m_log.Warn("MSGSERVER", "Got RemoveResponsibleRegion Request for a MessageServer that isn't registered");
  76. }
  77. else
  78. {
  79. MessageServerInfo msginfo = MessageServers["URI"];
  80. if (msginfo.responsibleForRegions.Contains(regionhandle))
  81. {
  82. msginfo.responsibleForRegions.Remove(regionhandle);
  83. MessageServers["URI"] = msginfo;
  84. }
  85. }
  86. }
  87. public XmlRpcResponse XmlRPCRegisterMessageServer(XmlRpcRequest request)
  88. {
  89. XmlRpcResponse response = new XmlRpcResponse();
  90. Hashtable requestData = (Hashtable)request.Params[0];
  91. Hashtable responseData = new Hashtable();
  92. if (requestData.Contains("uri"))
  93. {
  94. string URI = (string)requestData["uri"];
  95. string sendkey=(string)requestData["sendkey"];
  96. string recvkey=(string)requestData["recvkey"];
  97. MessageServerInfo m = new MessageServerInfo();
  98. m.URI = URI;
  99. m.sendkey = sendkey;
  100. m.recvkey = recvkey;
  101. RegisterMessageServer(URI, m);
  102. responseData["responsestring"] = "TRUE";
  103. response.Value = responseData;
  104. }
  105. return response;
  106. }
  107. public XmlRpcResponse XmlRPCDeRegisterMessageServer(XmlRpcRequest request)
  108. {
  109. XmlRpcResponse response = new XmlRpcResponse();
  110. Hashtable requestData = (Hashtable)request.Params[0];
  111. Hashtable responseData = new Hashtable();
  112. if (requestData.Contains("uri"))
  113. {
  114. string URI = (string)requestData["URI"];
  115. DeRegisterMessageServer(URI);
  116. responseData["responsestring"] = "TRUE";
  117. response.Value = responseData;
  118. }
  119. return response;
  120. }
  121. public XmlRpcResponse XmlRPCUserMovedtoRegion(XmlRpcRequest request)
  122. {
  123. XmlRpcResponse response = new XmlRpcResponse();
  124. Hashtable requestData = (Hashtable)request.Params[0];
  125. Hashtable responseData = new Hashtable();
  126. if (requestData.Contains("fromuri"))
  127. {
  128. string sURI = (string)requestData["fromuri"];
  129. string sagentID = (string)requestData["agentid"];
  130. string ssessionID = (string)requestData["sessionid"];
  131. string scurrentRegionID = (string)requestData["regionid"];
  132. string sregionhandle = (string)requestData["regionhandle"];
  133. string scurrentpos = (string)requestData["currentpos"];
  134. //LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos);
  135. // TODO: Okay now raise event so the user server can pass this data to the Usermanager
  136. responseData["responsestring"] = "TRUE";
  137. response.Value = responseData;
  138. }
  139. return response;
  140. }
  141. public void TellMessageServersAboutUser(LLUUID agentID, LLUUID sessionID, LLUUID RegionID, ulong regionhandle, LLVector3 Position)
  142. {
  143. // Loop over registered Message Servers ( AND THERE WILL BE MORE THEN ONE :D )
  144. foreach (MessageServerInfo serv in MessageServers.Values)
  145. {
  146. NotifyMessageServerAboutUser(serv, agentID, sessionID, RegionID, regionhandle, Position);
  147. }
  148. }
  149. private void NotifyMessageServerAboutUser(MessageServerInfo serv, LLUUID agentID, LLUUID sessionID, LLUUID RegionID, ulong regionhandle, LLVector3 Position)
  150. {
  151. Hashtable reqparams = new Hashtable();
  152. reqparams["sendkey"] = serv.sendkey;
  153. reqparams["agentid"] = agentID.ToString();
  154. reqparams["sessionid"] = sessionID.ToString();
  155. reqparams["regionid"] = RegionID.ToString();
  156. reqparams["regionhandle"] = regionhandle.ToString();
  157. reqparams["position"] = Position.ToString();
  158. ArrayList SendParams = new ArrayList();
  159. SendParams.Add(reqparams);
  160. XmlRpcRequest GridReq = new XmlRpcRequest("login_to_simulator", SendParams);
  161. XmlRpcResponse GridResp = GridReq.Send(serv.URI, 6000);
  162. m_log.Verbose("LOGIN","Notified : " + serv.URI + " about user login");
  163. }
  164. }
  165. }