PresenceInformer.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 OpenSimulator 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.Collections;
  28. using System.Net;
  29. using System.Reflection;
  30. using log4net;
  31. using Nwc.XmlRpc;
  32. using OpenSim.Data;
  33. namespace OpenSim.Grid.MessagingServer.Modules
  34. {
  35. public delegate RegionProfileData GetRegionData(ulong region_handle);
  36. public delegate void Done(PresenceInformer obj);
  37. public class PresenceInformer
  38. {
  39. public event GetRegionData OnGetRegionData;
  40. public event Done OnDone;
  41. private GetRegionData handlerGetRegionData = null;
  42. private Done handlerDone = null;
  43. public UserPresenceData presence1 = null;
  44. public UserPresenceData presence2 = null;
  45. public string gridserverurl, gridserversendkey, gridserverrecvkey;
  46. public bool lookupRegion = true;
  47. //public methodGroup
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. public PresenceInformer()
  50. {
  51. }
  52. public void go(object o)
  53. {
  54. if (presence1 != null && presence2 != null)
  55. {
  56. SendRegionPresenceUpdate(presence1, presence2);
  57. }
  58. }
  59. /// <summary>
  60. /// Informs a region about an Agent
  61. /// </summary>
  62. /// <param name="TalkingAbout">User to talk about</param>
  63. /// <param name="UserToUpdate">User we're sending this too (contains the region)</param>
  64. public void SendRegionPresenceUpdate(UserPresenceData TalkingAbout, UserPresenceData UserToUpdate)
  65. {
  66. // TODO: Fill in pertenant Presence Data from 'TalkingAbout'
  67. RegionProfileData whichRegion = new RegionProfileData();
  68. if (lookupRegion)
  69. {
  70. handlerGetRegionData = OnGetRegionData;
  71. if (handlerGetRegionData != null)
  72. {
  73. whichRegion = handlerGetRegionData(UserToUpdate.regionData.regionHandle);
  74. }
  75. //RegionProfileData rp = RegionProfileData.RequestSimProfileData(UserToUpdate.regionData.regionHandle, gridserverurl, gridserversendkey, gridserverrecvkey);
  76. //whichRegion = rp;
  77. }
  78. else
  79. {
  80. whichRegion = UserToUpdate.regionData;
  81. }
  82. //whichRegion.httpServerURI
  83. if (whichRegion != null)
  84. {
  85. Hashtable PresenceParams = new Hashtable();
  86. PresenceParams.Add("agent_id",TalkingAbout.agentData.AgentID.ToString());
  87. PresenceParams.Add("notify_id",UserToUpdate.agentData.AgentID.ToString());
  88. if (TalkingAbout.OnlineYN)
  89. PresenceParams.Add("status","TRUE");
  90. else
  91. PresenceParams.Add("status","FALSE");
  92. ArrayList SendParams = new ArrayList();
  93. SendParams.Add(PresenceParams);
  94. m_log.InfoFormat("[PRESENCE]: Informing {0}@{1} at {2} about {3}", TalkingAbout.agentData.firstname + " " + TalkingAbout.agentData.lastname, whichRegion.regionName, whichRegion.httpServerURI, UserToUpdate.agentData.firstname + " " + UserToUpdate.agentData.lastname);
  95. // Send
  96. XmlRpcRequest RegionReq = new XmlRpcRequest("presence_update", SendParams);
  97. try
  98. {
  99. // XmlRpcResponse RegionResp = RegionReq.Send(whichRegion.httpServerURI, 6000);
  100. RegionReq.Send(whichRegion.httpServerURI, 6000);
  101. }
  102. catch (WebException)
  103. {
  104. m_log.WarnFormat("[INFORM]: failed notifying region {0} containing user {1} about {2}", whichRegion.regionName, UserToUpdate.agentData.firstname + " " + UserToUpdate.agentData.lastname, TalkingAbout.agentData.firstname + " " + TalkingAbout.agentData.lastname);
  105. }
  106. }
  107. else
  108. {
  109. m_log.Info("[PRESENCEUPDATER]: Region data was null skipping");
  110. }
  111. handlerDone = OnDone;
  112. if (handlerDone != null)
  113. {
  114. handlerDone(this);
  115. }
  116. }
  117. }
  118. }