PresenceService.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using System.Reflection;
  31. using Nini.Config;
  32. using log4net;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Console;
  35. using OpenSim.Data;
  36. using OpenSim.Services.Interfaces;
  37. using OpenMetaverse;
  38. namespace OpenSim.Services.PresenceService
  39. {
  40. public class PresenceService : PresenceServiceBase, IPresenceService
  41. {
  42. private static readonly ILog m_log =
  43. LogManager.GetLogger(
  44. MethodBase.GetCurrentMethod().DeclaringType);
  45. public PresenceService(IConfigSource config)
  46. : base(config)
  47. {
  48. m_log.Debug("[PRESENCE SERVICE]: Starting presence service");
  49. }
  50. public bool LoginAgent(string userID, UUID sessionID,
  51. UUID secureSessionID)
  52. {
  53. //PresenceData[] d = m_Database.Get("UserID", userID);
  54. //m_Database.Get("UserID", userID);
  55. PresenceData data = new PresenceData();
  56. data.UserID = userID;
  57. data.RegionID = UUID.Zero;
  58. data.SessionID = sessionID;
  59. data.Data = new Dictionary<string, string>();
  60. data.Data["SecureSessionID"] = secureSessionID.ToString();
  61. m_Database.Store(data);
  62. m_log.DebugFormat("[PRESENCE SERVICE]: LoginAgent {0} with session {1} and ssession {2}",
  63. userID, sessionID, secureSessionID);
  64. return true;
  65. }
  66. public bool LogoutAgent(UUID sessionID)
  67. {
  68. m_log.DebugFormat("[PRESENCE SERVICE]: Session {0} logout", sessionID);
  69. return m_Database.Delete("SessionID", sessionID.ToString());
  70. }
  71. public bool LogoutRegionAgents(UUID regionID)
  72. {
  73. m_Database.LogoutRegionAgents(regionID);
  74. return true;
  75. }
  76. public bool ReportAgent(UUID sessionID, UUID regionID)
  77. {
  78. m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent with session {0} in region {1}", sessionID, regionID);
  79. try
  80. {
  81. PresenceData pdata = m_Database.Get(sessionID);
  82. if (pdata == null)
  83. return false;
  84. if (pdata.Data == null)
  85. return false;
  86. return m_Database.ReportAgent(sessionID, regionID);
  87. }
  88. catch (Exception e)
  89. {
  90. m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent threw exception {0}", e.StackTrace);
  91. return false;
  92. }
  93. }
  94. public PresenceInfo GetAgent(UUID sessionID)
  95. {
  96. PresenceInfo ret = new PresenceInfo();
  97. PresenceData data = m_Database.Get(sessionID);
  98. if (data == null)
  99. return null;
  100. ret.UserID = data.UserID;
  101. ret.RegionID = data.RegionID;
  102. return ret;
  103. }
  104. public PresenceInfo[] GetAgents(string[] userIDs)
  105. {
  106. List<PresenceInfo> info = new List<PresenceInfo>();
  107. foreach (string userIDStr in userIDs)
  108. {
  109. PresenceData[] data = m_Database.Get("UserID",
  110. userIDStr);
  111. foreach (PresenceData d in data)
  112. {
  113. PresenceInfo ret = new PresenceInfo();
  114. ret.UserID = d.UserID;
  115. ret.RegionID = d.RegionID;
  116. info.Add(ret);
  117. }
  118. }
  119. // m_log.DebugFormat("[PRESENCE SERVICE]: GetAgents for {0} userIDs found {1} presences", userIDs.Length, info.Count);
  120. return info.ToArray();
  121. }
  122. }
  123. }