MessageServersConnector.cs 7.6 KB

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