MessageService.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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 System.Collections;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Threading;
  33. using libsecondlife;
  34. using log4net;
  35. using Nwc.XmlRpc;
  36. using OpenSim.Data;
  37. using OpenSim.Framework;
  38. //using System.Xml;
  39. namespace OpenSim.Grid.MessagingServer
  40. {
  41. public class MessageService
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. private MessageServerConfig m_cfg;
  45. private UserManager m_userManager;
  46. //A hashtable of all current presences this server knows about
  47. private Hashtable m_presences = new Hashtable();
  48. //a hashtable of all current regions this server knows about
  49. private Hashtable m_regionInfoCache = new Hashtable();
  50. //A hashtable containing lists of UUIDs keyed by UUID for fast backreferencing
  51. private Hashtable m_presence_BackReferences = new Hashtable();
  52. // Hashtable containing work units that need to be processed
  53. // private Hashtable m_unProcessedWorkUnits = new Hashtable();
  54. public MessageService(MessageServerConfig cfg)
  55. {
  56. m_cfg = cfg;
  57. m_userManager = new UserManager();
  58. UserConfig uc = new UserConfig();
  59. uc.DatabaseConnect = cfg.DatabaseConnect;
  60. uc.DatabaseProvider = cfg.DatabaseProvider;
  61. m_userManager._config = uc;
  62. m_userManager.AddPlugin(cfg.DatabaseProvider, cfg.DatabaseConnect);
  63. }
  64. #region FriendList Methods
  65. /// <summary>
  66. /// Process Friendlist subscriptions for a user
  67. /// The login method calls this for a User
  68. /// </summary>
  69. /// <param name="userpresence">The Agent we're processing the friendlist subscriptions</param>
  70. public void ProcessFriendListSubscriptions(UserPresenceData userpresence)
  71. {
  72. lock (m_presences)
  73. {
  74. if (!m_presences.Contains(userpresence.agentData.AgentID))
  75. m_presences.Add(userpresence.agentData.AgentID, userpresence);
  76. else
  77. m_presences[userpresence.agentData.AgentID] = userpresence;
  78. }
  79. List<FriendListItem> uFriendList = userpresence.friendData;
  80. for (int i = 0; i < uFriendList.Count; i++)
  81. {
  82. //m_presence_BackReferences.Add(userpresence.agentData.AgentID, uFriendList[i].Friend);
  83. // m_presence_BackReferences.Add(uFriendList[i].Friend, userpresence.agentData.AgentID);
  84. if (m_presences.Contains(uFriendList[i].Friend))
  85. {
  86. UserPresenceData friendup = (UserPresenceData)m_presences[uFriendList[i].Friend];
  87. // Add backreference
  88. SubscribeToPresenceUpdates(userpresence, friendup, uFriendList[i],i);
  89. }
  90. }
  91. }
  92. /// <summary>
  93. /// Does the necessary work to subscribe one agent to another's presence notifications
  94. /// Gets called by ProcessFriendListSubscriptions. You shouldn't call this directly
  95. /// unless you know what you're doing
  96. /// </summary>
  97. /// <param name="userpresence">P1</param>
  98. /// <param name="friendpresence">P2</param>
  99. /// <param name="uFriendListItem"></param>
  100. /// <param name="uFriendListIndex"></param>
  101. public void SubscribeToPresenceUpdates(UserPresenceData userpresence, UserPresenceData friendpresence,
  102. FriendListItem uFriendListItem, int uFriendListIndex)
  103. {
  104. if ((uFriendListItem.FriendListOwnerPerms & (uint)FriendRights.CanSeeOnline) != 0)
  105. {
  106. // Subscribe and Send Out updates
  107. if (!friendpresence.subscriptionData.Contains(friendpresence.agentData.AgentID))
  108. {
  109. userpresence.subscriptionData.Add(friendpresence.agentData.AgentID);
  110. //Send Region Notice....
  111. }
  112. else
  113. {
  114. // we need to send out online status update, but the user is already subscribed
  115. }
  116. UserAgentData p2Handle = m_userManager.GetUserAgentData(userpresence.agentData.AgentID);
  117. if (p2Handle != null)
  118. {
  119. if (userpresence.lookupUserRegionYN)
  120. {
  121. userpresence.regionData.regionHandle = p2Handle.Handle;
  122. }
  123. else
  124. {
  125. userpresence.lookupUserRegionYN = true;
  126. }
  127. PresenceInformer friendlistupdater = new PresenceInformer();
  128. friendlistupdater.presence1 = friendpresence;
  129. //friendlistupdater.gridserverurl = m_cfg.GridServerURL;
  130. //friendlistupdater.gridserversendkey = m_cfg.GridSendKey;
  131. //friendlistupdater.gridserverrecvkey = m_cfg.GridRecvKey;
  132. friendlistupdater.presence2 = userpresence;
  133. friendlistupdater.OnGetRegionData += GetRegionInfo;
  134. friendlistupdater.OnDone += PresenceUpdateDone;
  135. WaitCallback cb = new WaitCallback(friendlistupdater.go);
  136. ThreadPool.QueueUserWorkItem(cb);
  137. }
  138. else
  139. {
  140. // Skip because we can't find any data on the user
  141. }
  142. //SendRegionPresenceUpdate(friendpresence, userpresence);
  143. }
  144. if ((uFriendListItem.FriendPerms & (uint)FriendRights.CanSeeOnline) != 0)
  145. {
  146. if (!friendpresence.subscriptionData.Contains(userpresence.agentData.AgentID))
  147. {
  148. friendpresence.subscriptionData.Add(userpresence.agentData.AgentID);
  149. //Send Region Notice....
  150. }
  151. else
  152. {
  153. // we need to send out online status update, but the user is already subscribed
  154. }
  155. UserAgentData p2Handle = m_userManager.GetUserAgentData(friendpresence.agentData.AgentID);
  156. if (p2Handle != null)
  157. {
  158. friendpresence.regionData.regionHandle = p2Handle.Handle;
  159. PresenceInformer friendlistupdater = new PresenceInformer();
  160. friendlistupdater.presence1 = userpresence;
  161. friendlistupdater.presence2 = friendpresence;
  162. //friendlistupdater.gridserverurl = m_cfg.GridServerURL;
  163. //friendlistupdater.gridserversendkey = m_cfg.GridSendKey;
  164. //friendlistupdater.gridserverrecvkey = m_cfg.GridRecvKey;
  165. friendlistupdater.OnGetRegionData += GetRegionInfo;
  166. friendlistupdater.OnDone += PresenceUpdateDone;
  167. WaitCallback cb2 = new WaitCallback(friendlistupdater.go);
  168. ThreadPool.QueueUserWorkItem(cb2);
  169. }
  170. else
  171. {
  172. // skip, agent doesn't appear to exist anymore
  173. }
  174. //SendRegionPresenceUpdate(userpresence, friendpresence);
  175. }
  176. }
  177. /// <summary>
  178. /// Adds a backreference so presence specific data doesn't have to be
  179. /// enumerated for each logged in user every time someone logs on or off.
  180. /// </summary>
  181. /// <param name="agentID"></param>
  182. /// <param name="friendID"></param>
  183. public void addBackReference(LLUUID agentID, LLUUID friendID)
  184. {
  185. if (m_presence_BackReferences.Contains(friendID))
  186. {
  187. List<LLUUID> presenseBackReferences = (List<LLUUID>)m_presence_BackReferences[friendID];
  188. if (!presenseBackReferences.Contains(agentID))
  189. {
  190. presenseBackReferences.Add(agentID);
  191. }
  192. m_presence_BackReferences[friendID] = presenseBackReferences;
  193. }
  194. else
  195. {
  196. List<LLUUID> presenceBackReferences = new List<LLUUID>();
  197. presenceBackReferences.Add(agentID);
  198. m_presence_BackReferences[friendID] = presenceBackReferences;
  199. }
  200. }
  201. /// <summary>
  202. /// Removes a backreference to free up some memory
  203. /// </summary>
  204. /// <param name="agentID"></param>
  205. /// <param name="friendID"></param>
  206. public void removeBackReference(LLUUID agentID, LLUUID friendID)
  207. {
  208. if (m_presence_BackReferences.Contains(friendID))
  209. {
  210. List<LLUUID> presenseBackReferences = (List<LLUUID>)m_presence_BackReferences[friendID];
  211. if (presenseBackReferences.Contains(agentID))
  212. {
  213. presenseBackReferences.Remove(agentID);
  214. }
  215. // If there are no more backreferences for this agent,
  216. // remove it to free up memory.
  217. if (presenseBackReferences.Count == 0)
  218. {
  219. m_presence_BackReferences.Remove(agentID);
  220. }
  221. }
  222. }
  223. /// <summary>
  224. /// Logoff Processor. Call this to clean up agent presence data and send logoff presence notifications
  225. /// </summary>
  226. /// <param name="AgentID"></param>
  227. private void ProcessLogOff(LLUUID AgentID)
  228. {
  229. m_log.Info("[LOGOFF]: Processing Logoff");
  230. UserPresenceData AgentData = null;
  231. List<LLUUID> AgentsNeedingNotification = new List<LLUUID>();
  232. UserPresenceData friendd = null;
  233. lock (m_presences)
  234. {
  235. if (m_presences.Contains(AgentID))
  236. {
  237. AgentData = (UserPresenceData)m_presences[AgentID];
  238. }
  239. }
  240. if (AgentData != null)
  241. {
  242. AgentsNeedingNotification = AgentData.subscriptionData;
  243. AgentData.OnlineYN = false;
  244. //lock (m_presence_BackReferences)
  245. //{
  246. //if (m_presence_BackReferences.Contains(AgentID))
  247. //{
  248. //AgentsNeedingNotification = (List<LLUUID>)m_presence_BackReferences[AgentID];
  249. //}
  250. //}
  251. for (int i = 0; i < AgentsNeedingNotification.Count; i++)
  252. {
  253. // TODO: Do Region Notifications
  254. lock (m_presences)
  255. {
  256. if (m_presences.Contains(AgentsNeedingNotification[i]))
  257. {
  258. friendd = (UserPresenceData)m_presences[AgentsNeedingNotification[i]];
  259. }
  260. }
  261. // This might need to be enumerated and checked before we try to remove it.
  262. if (friendd != null)
  263. {
  264. lock (friendd)
  265. {
  266. friendd.subscriptionData.Remove(AgentID);
  267. List<FriendListItem> fl = friendd.friendData;
  268. for (int j = 0; j < fl.Count; j++)
  269. {
  270. if (fl[j].Friend == AgentID)
  271. {
  272. fl[j].onlinestatus = false;
  273. }
  274. }
  275. friendd.friendData = fl;
  276. m_presences[AgentsNeedingNotification[i]] = friendd;
  277. }
  278. UserAgentData p2Handle = m_userManager.GetUserAgentData(friendd.agentData.AgentID);
  279. if (p2Handle != null)
  280. {
  281. friendd.regionData.regionHandle = p2Handle.Handle;
  282. PresenceInformer friendlistupdater = new PresenceInformer();
  283. friendlistupdater.presence1 = AgentData;
  284. friendlistupdater.presence2 = friendd;
  285. //friendlistupdater.gridserverurl = m_cfg.GridServerURL;
  286. //friendlistupdater.gridserversendkey = m_cfg.GridSendKey;
  287. //friendlistupdater.gridserverrecvkey = m_cfg.GridRecvKey;
  288. friendlistupdater.OnGetRegionData += GetRegionInfo;
  289. friendlistupdater.OnDone += PresenceUpdateDone;
  290. WaitCallback cb3 = new WaitCallback(friendlistupdater.go);
  291. ThreadPool.QueueUserWorkItem(cb3);
  292. }
  293. else
  294. {
  295. // skip, agent can't be found
  296. }
  297. //SendRegionPresenceUpdate(AgentData, friendd);
  298. //removeBackReference(AgentID, AgentsNeedingNotification[i]);
  299. }
  300. }
  301. }
  302. }
  303. #endregion
  304. public void PresenceUpdateDone(PresenceInformer obj)
  305. {
  306. obj.OnGetRegionData -= GetRegionInfo;
  307. obj.OnDone -= PresenceUpdateDone;
  308. }
  309. #region UserServer Comms
  310. /// <summary>
  311. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for LLUUID friendslistowner
  312. /// </summary>
  313. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  314. public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
  315. {
  316. List<FriendListItem> buddylist = new List<FriendListItem>();
  317. try
  318. {
  319. Hashtable param = new Hashtable();
  320. param["ownerID"] = friendlistowner.UUID.ToString();
  321. IList parameters = new ArrayList();
  322. parameters.Add(param);
  323. XmlRpcRequest req = new XmlRpcRequest("get_user_friend_list", parameters);
  324. XmlRpcResponse resp = req.Send(m_cfg.UserServerURL, 3000);
  325. Hashtable respData = (Hashtable)resp.Value;
  326. if (respData.Contains("avcount"))
  327. {
  328. buddylist = ConvertXMLRPCDataToFriendListItemList(respData);
  329. }
  330. }
  331. catch (WebException e)
  332. {
  333. m_log.Warn("Error when trying to fetch Avatar's friends list: " +
  334. e.Message);
  335. // Return Empty list (no friends)
  336. }
  337. return buddylist;
  338. }
  339. /// <summary>
  340. /// Converts XMLRPC Friend List to FriendListItem Object
  341. /// </summary>
  342. /// <param name="data">XMLRPC response data Hashtable</param>
  343. /// <returns></returns>
  344. public List<FriendListItem> ConvertXMLRPCDataToFriendListItemList(Hashtable data)
  345. {
  346. List<FriendListItem> buddylist = new List<FriendListItem>();
  347. int buddycount = Convert.ToInt32((string)data["avcount"]);
  348. for (int i = 0; i < buddycount; i++)
  349. {
  350. FriendListItem buddylistitem = new FriendListItem();
  351. buddylistitem.FriendListOwner = new LLUUID((string)data["ownerID" + i.ToString()]);
  352. buddylistitem.Friend = new LLUUID((string)data["friendID" + i.ToString()]);
  353. buddylistitem.FriendListOwnerPerms = (uint)Convert.ToInt32((string)data["ownerPerms" + i.ToString()]);
  354. buddylistitem.FriendPerms = (uint)Convert.ToInt32((string)data["friendPerms" + i.ToString()]);
  355. buddylist.Add(buddylistitem);
  356. }
  357. return buddylist;
  358. }
  359. /// <summary>
  360. /// UserServer sends an expect_user method
  361. /// this handles the method and provisions the
  362. /// necessary info for presence to work
  363. /// </summary>
  364. /// <param name="request">UserServer Data</param>
  365. /// <returns></returns>
  366. public XmlRpcResponse UserLoggedOn(XmlRpcRequest request)
  367. {
  368. m_log.Info("[LOGON]: User logged on, building indexes for user");
  369. Hashtable requestData = (Hashtable)request.Params[0];
  370. //requestData["sendkey"] = serv.sendkey;
  371. //requestData["agentid"] = agentID.ToString();
  372. //requestData["sessionid"] = sessionID.ToString();
  373. //requestData["regionid"] = RegionID.ToString();
  374. //requestData["regionhandle"] = regionhandle.ToString();
  375. //requestData["positionx"] = positionX.ToString();
  376. //requestData["positiony"] = positionY.ToString();
  377. //requestData["positionz"] = positionZ.ToString();
  378. //requestData["firstname"] = firstname;
  379. //requestData["lastname"] = lastname;
  380. AgentCircuitData agentData = new AgentCircuitData();
  381. agentData.SessionID = new LLUUID((string)requestData["sessionid"]);
  382. agentData.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]);
  383. agentData.firstname = (string)requestData["firstname"];
  384. agentData.lastname = (string)requestData["lastname"];
  385. agentData.AgentID = new LLUUID((string)requestData["agentid"]);
  386. agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
  387. agentData.CapsPath = (string)requestData["caps_path"];
  388. if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1"))
  389. {
  390. agentData.child = true;
  391. }
  392. else
  393. {
  394. agentData.startpos =
  395. new LLVector3(Convert.ToUInt32(requestData["positionx"]),
  396. Convert.ToUInt32(requestData["positiony"]),
  397. Convert.ToUInt32(requestData["positionz"]));
  398. agentData.child = false;
  399. }
  400. ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
  401. UserPresenceData up = new UserPresenceData();
  402. up.agentData = agentData;
  403. List<FriendListItem> flData = GetUserFriendList(agentData.AgentID);
  404. up.friendData = flData;
  405. RegionProfileData riData = GetRegionInfo(regionHandle);
  406. up.regionData = riData;
  407. up.OnlineYN = true;
  408. up.lookupUserRegionYN = false;
  409. ProcessFriendListSubscriptions(up);
  410. return new XmlRpcResponse();
  411. }
  412. /// <summary>
  413. /// The UserServer got a Logoff message
  414. /// Cleanup time for that user. Send out presence notifications
  415. /// </summary>
  416. /// <param name="request"></param>
  417. /// <returns></returns>
  418. public XmlRpcResponse UserLoggedOff(XmlRpcRequest request)
  419. {
  420. m_log.Info("[USERLOGOFF]: User logged off called");
  421. Hashtable requestData = (Hashtable)request.Params[0];
  422. LLUUID AgentID = new LLUUID((string)requestData["agentid"]);
  423. ProcessLogOff(AgentID);
  424. return new XmlRpcResponse();
  425. }
  426. #endregion
  427. #region regioninfo gathering
  428. /// <summary>
  429. /// Gets and caches a RegionInfo object from the gridserver based on regionhandle
  430. /// if the regionhandle is already cached, use the cached values
  431. /// Gets called by lots of threads!!!!!
  432. /// </summary>
  433. /// <param name="regionhandle">handle to the XY of the region we're looking for</param>
  434. /// <returns>A RegionInfo object to stick in the presence info</returns>
  435. public RegionProfileData GetRegionInfo(ulong regionhandle)
  436. {
  437. RegionProfileData regionInfo = null;
  438. bool lookup = false;
  439. lock (m_regionInfoCache)
  440. {
  441. if (m_regionInfoCache.Contains(regionhandle))
  442. {
  443. regionInfo = (RegionProfileData)m_regionInfoCache[regionhandle];
  444. }
  445. else
  446. {
  447. // Don't lock the cache while we're looking up the region!
  448. lookup = true;
  449. }
  450. }
  451. if (lookup)
  452. {
  453. regionInfo = RequestRegionInfo(regionhandle);
  454. if (regionInfo != null)
  455. {
  456. lock (m_regionInfoCache)
  457. {
  458. if (m_regionInfoCache.Contains(regionhandle))
  459. {
  460. m_regionInfoCache[regionhandle] = regionInfo;
  461. }
  462. else
  463. {
  464. m_regionInfoCache.Add(regionhandle, regionInfo);
  465. }
  466. }
  467. }
  468. }
  469. return regionInfo;
  470. }
  471. public int ClearRegionCache()
  472. {
  473. int cachecount = 0;
  474. lock (m_regionInfoCache)
  475. {
  476. cachecount = m_regionInfoCache.Count;
  477. m_regionInfoCache.Clear();
  478. }
  479. return cachecount;
  480. }
  481. /// <summary>
  482. /// Get RegionProfileData from the GridServer
  483. /// We'll Cache this information and use it for presence updates
  484. /// </summary>
  485. /// <param name="regionHandle"></param>
  486. /// <returns></returns>
  487. public RegionProfileData RequestRegionInfo(ulong regionHandle)
  488. { RegionProfileData regionProfile = null;
  489. try
  490. {
  491. Hashtable requestData = new Hashtable();
  492. requestData["region_handle"] = regionHandle.ToString();
  493. requestData["authkey"] = m_cfg.GridSendKey;
  494. ArrayList SendParams = new ArrayList();
  495. SendParams.Add(requestData);
  496. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  497. XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000);
  498. Hashtable responseData = (Hashtable)GridResp.Value;
  499. if (responseData.ContainsKey("error"))
  500. {
  501. m_log.Error("[GRID]: error received from grid server" + responseData["error"]);
  502. return null;
  503. }
  504. uint regX = Convert.ToUInt32((string)responseData["region_locx"]);
  505. uint regY = Convert.ToUInt32((string)responseData["region_locy"]);
  506. string internalIpStr = (string)responseData["sim_ip"];
  507. // uint port = Convert.ToUInt32(responseData["sim_port"]);
  508. // string externalUri = (string)responseData["sim_uri"];
  509. // string neighbourExternalUri = externalUri;
  510. regionProfile = new RegionProfileData();
  511. regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]);
  512. regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/";
  513. regionProfile.regionHandle = Helpers.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize));
  514. regionProfile.regionLocX = regX;
  515. regionProfile.regionLocY = regY;
  516. regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
  517. regionProfile.UUID = new LLUUID((string)responseData["region_UUID"]);
  518. regionProfile.regionName = (string)responseData["region_name"];
  519. lock (m_regionInfoCache)
  520. {
  521. if (!m_regionInfoCache.Contains(regionHandle))
  522. {
  523. m_regionInfoCache.Add(regionHandle, regionProfile);
  524. }
  525. }
  526. }
  527. catch (WebException)
  528. {
  529. m_log.Error("[GRID]: " +
  530. "Region lookup failed for: " + regionHandle.ToString() +
  531. " - Is the GridServer down?");
  532. return null;
  533. }
  534. return regionProfile;
  535. }
  536. public bool registerWithUserServer ()
  537. {
  538. Hashtable UserParams = new Hashtable();
  539. // Login / Authentication
  540. if (m_cfg.HttpSSL)
  541. {
  542. UserParams["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
  543. }
  544. else
  545. {
  546. UserParams["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
  547. }
  548. UserParams["recvkey"] = m_cfg.UserRecvKey;
  549. UserParams["sendkey"] = m_cfg.UserRecvKey;
  550. // Package into an XMLRPC Request
  551. ArrayList SendParams = new ArrayList();
  552. SendParams.Add(UserParams);
  553. // Send Request
  554. XmlRpcRequest UserReq;
  555. XmlRpcResponse UserResp;
  556. try
  557. {
  558. UserReq = new XmlRpcRequest("register_messageserver", SendParams);
  559. UserResp = UserReq.Send(m_cfg.UserServerURL, 16000);
  560. } catch (Exception ex)
  561. {
  562. m_log.Error("Unable to connect to grid. Grid server not running?");
  563. throw(ex);
  564. }
  565. Hashtable GridRespData = (Hashtable)UserResp.Value;
  566. // Hashtable griddatahash = GridRespData;
  567. // Process Response
  568. if (GridRespData.ContainsKey("responsestring"))
  569. {
  570. return true;
  571. }
  572. else
  573. {
  574. return false;
  575. }
  576. }
  577. public bool deregisterWithUserServer()
  578. {
  579. Hashtable UserParams = new Hashtable();
  580. // Login / Authentication
  581. if (m_cfg.HttpSSL)
  582. {
  583. UserParams["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
  584. }
  585. else
  586. {
  587. UserParams["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
  588. }
  589. UserParams["recvkey"] = m_cfg.UserRecvKey;
  590. UserParams["sendkey"] = m_cfg.UserRecvKey;
  591. // Package into an XMLRPC Request
  592. ArrayList SendParams = new ArrayList();
  593. SendParams.Add(UserParams);
  594. // Send Request
  595. XmlRpcRequest UserReq;
  596. XmlRpcResponse UserResp;
  597. try
  598. {
  599. UserReq = new XmlRpcRequest("deregister_messageserver", SendParams);
  600. UserResp = UserReq.Send(m_cfg.UserServerURL, 16000);
  601. }
  602. catch (Exception ex)
  603. {
  604. m_log.Error("Unable to connect to grid. Grid server not running?");
  605. throw (ex);
  606. }
  607. Hashtable UserRespData = (Hashtable)UserResp.Value;
  608. // Hashtable userdatahash = UserRespData;
  609. // Process Response
  610. if (UserRespData.ContainsKey("responsestring"))
  611. {
  612. return true;
  613. }
  614. else
  615. {
  616. return false;
  617. }
  618. }
  619. #endregion
  620. }
  621. }