1
0

PresenceService.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. protected bool m_allowDuplicatePresences = false;
  46. public PresenceService(IConfigSource config)
  47. : base(config)
  48. {
  49. m_log.Debug("[PRESENCE SERVICE]: Starting presence service");
  50. IConfig presenceConfig = config.Configs["PresenceService"];
  51. if (presenceConfig != null)
  52. {
  53. m_allowDuplicatePresences =
  54. presenceConfig.GetBoolean("AllowDuplicatePresences",
  55. m_allowDuplicatePresences);
  56. }
  57. }
  58. public bool LoginAgent(string userID, UUID sessionID,
  59. UUID secureSessionID)
  60. {
  61. //PresenceData[] d = m_Database.Get("UserID", userID);
  62. //m_Database.Get("UserID", userID);
  63. if (!m_allowDuplicatePresences)
  64. m_Database.Delete("UserID", userID.ToString());
  65. PresenceData data = new PresenceData();
  66. data.UserID = userID;
  67. data.RegionID = UUID.Zero;
  68. data.SessionID = sessionID;
  69. data.Data = new Dictionary<string, string>();
  70. data.Data["SecureSessionID"] = secureSessionID.ToString();
  71. m_Database.Store(data);
  72. m_log.DebugFormat("[PRESENCE SERVICE]: LoginAgent {0} with session {1} and ssession {2}",
  73. userID, sessionID, secureSessionID);
  74. return true;
  75. }
  76. public bool LogoutAgent(UUID sessionID)
  77. {
  78. m_log.DebugFormat("[PRESENCE SERVICE]: Session {0} logout", sessionID);
  79. return m_Database.Delete("SessionID", sessionID.ToString());
  80. }
  81. public bool LogoutRegionAgents(UUID regionID)
  82. {
  83. m_Database.LogoutRegionAgents(regionID);
  84. return true;
  85. }
  86. public bool ReportAgent(UUID sessionID, UUID regionID)
  87. {
  88. // m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent with session {0} in region {1}", sessionID, regionID);
  89. try
  90. {
  91. PresenceData pdata = m_Database.Get(sessionID);
  92. if (pdata == null)
  93. return false;
  94. if (pdata.Data == null)
  95. return false;
  96. return m_Database.ReportAgent(sessionID, regionID);
  97. }
  98. catch (Exception e)
  99. {
  100. m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent threw exception {0}", e.StackTrace);
  101. return false;
  102. }
  103. }
  104. public PresenceInfo GetAgent(UUID sessionID)
  105. {
  106. PresenceInfo ret = new PresenceInfo();
  107. PresenceData data = m_Database.Get(sessionID);
  108. if (data == null)
  109. return null;
  110. ret.UserID = data.UserID;
  111. ret.RegionID = data.RegionID;
  112. return ret;
  113. }
  114. public PresenceInfo[] GetAgents(string[] userIDs)
  115. {
  116. List<PresenceInfo> info = new List<PresenceInfo>();
  117. foreach (string userIDStr in userIDs)
  118. {
  119. PresenceData[] data = m_Database.Get("UserID",
  120. userIDStr);
  121. foreach (PresenceData d in data)
  122. {
  123. PresenceInfo ret = new PresenceInfo();
  124. ret.UserID = d.UserID;
  125. ret.RegionID = d.RegionID;
  126. info.Add(ret);
  127. }
  128. }
  129. // m_log.DebugFormat("[PRESENCE SERVICE]: GetAgents for {0} userIDs found {1} presences", userIDs.Length, info.Count);
  130. return info.ToArray();
  131. }
  132. }
  133. }