aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/PresenceService
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 11:43:07 +0100
committerUbitUmarov2015-09-01 11:43:07 +0100
commitfb78b182520fc9bb0f971afd0322029c70278ea6 (patch)
treeb4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Services/PresenceService
parentlixo (diff)
parentMantis #7713: fixed bug introduced by 1st MOSES patch. (diff)
downloadopensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Services/PresenceService')
-rw-r--r--OpenSim/Services/PresenceService/PresenceService.cs201
-rw-r--r--OpenSim/Services/PresenceService/PresenceServiceBase.cs84
-rw-r--r--OpenSim/Services/PresenceService/Properties/AssemblyInfo.cs33
3 files changed, 318 insertions, 0 deletions
diff --git a/OpenSim/Services/PresenceService/PresenceService.cs b/OpenSim/Services/PresenceService/PresenceService.cs
new file mode 100644
index 0000000..0fe0200
--- /dev/null
+++ b/OpenSim/Services/PresenceService/PresenceService.cs
@@ -0,0 +1,201 @@
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
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Reflection;
32using Nini.Config;
33using log4net;
34using OpenSim.Framework;
35using OpenSim.Framework.Console;
36using OpenSim.Data;
37using OpenSim.Services.Interfaces;
38using OpenMetaverse;
39
40namespace OpenSim.Services.PresenceService
41{
42 public class PresenceService : PresenceServiceBase, IPresenceService
43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 protected bool m_allowDuplicatePresences = false;
47
48 public PresenceService(IConfigSource config)
49 : base(config)
50 {
51 m_log.Debug("[PRESENCE SERVICE]: Starting presence service");
52
53 IConfig presenceConfig = config.Configs["PresenceService"];
54 if (presenceConfig != null)
55 {
56 m_allowDuplicatePresences = presenceConfig.GetBoolean("AllowDuplicatePresences", m_allowDuplicatePresences);
57 }
58 }
59
60 public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
61 {
62 PresenceData prevUser = GetUser(userID);
63
64 if (!m_allowDuplicatePresences && (prevUser != null))
65 m_Database.Delete("UserID", userID.ToString());
66
67 PresenceData data = new PresenceData();
68
69 data.UserID = userID;
70 data.RegionID = UUID.Zero;
71 data.SessionID = sessionID;
72 data.Data = new Dictionary<string, string>();
73 data.Data["SecureSessionID"] = secureSessionID.ToString();
74
75 m_Database.Store(data);
76
77 string prevUserStr = "";
78 if (prevUser != null)
79 prevUserStr = string.Format(". This user was already logged-in: session {0}, region {1}", prevUser.SessionID, prevUser.RegionID);
80
81 m_log.DebugFormat("[PRESENCE SERVICE]: LoginAgent: session {0}, user {1}, region {2}, secure session {3}{4}",
82 data.SessionID, data.UserID, data.RegionID, secureSessionID, prevUserStr);
83
84 return true;
85 }
86
87 public bool LogoutAgent(UUID sessionID)
88 {
89 PresenceInfo presence = GetAgent(sessionID);
90
91 m_log.DebugFormat("[PRESENCE SERVICE]: LogoutAgent: session {0}, user {1}, region {2}",
92 sessionID,
93 (presence == null) ? null : presence.UserID,
94 (presence == null) ? null : presence.RegionID.ToString());
95
96 return m_Database.Delete("SessionID", sessionID.ToString());
97 }
98
99 public bool LogoutRegionAgents(UUID regionID)
100 {
101 PresenceData[] prevSessions = GetRegionAgents(regionID);
102
103 if ((prevSessions == null) || (prevSessions.Length == 0))
104 return true;
105
106 m_log.DebugFormat("[PRESENCE SERVICE]: Logout users in region {0}: {1}", regionID,
107 string.Join(", ", Array.ConvertAll(prevSessions, session => session.UserID)));
108
109 // There's a small chance that LogoutRegionAgents() will logout different users than the
110 // list that was logged above, but it's unlikely and not worth dealing with.
111
112 m_Database.LogoutRegionAgents(regionID);
113
114 return true;
115 }
116
117
118 public bool ReportAgent(UUID sessionID, UUID regionID)
119 {
120 try
121 {
122 PresenceData presence = m_Database.Get(sessionID);
123
124 bool success;
125 if (presence == null)
126 success = false;
127 else
128 success = m_Database.ReportAgent(sessionID, regionID);
129
130 m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent{0}: session {1}, user {2}, region {3}. Previously: {4}",
131 success ? "" : " failed",
132 sessionID, (presence == null) ? null : presence.UserID, regionID,
133 (presence == null) ? "not logged-in" : "region " + presence.RegionID);
134
135 return success;
136 }
137 catch (Exception e)
138 {
139 m_log.Debug(string.Format("[PRESENCE SERVICE]: ReportAgent for session {0} threw exception ", sessionID), e);
140 return false;
141 }
142 }
143
144 public PresenceInfo GetAgent(UUID sessionID)
145 {
146 PresenceInfo ret = new PresenceInfo();
147
148 PresenceData data = m_Database.Get(sessionID);
149 if (data == null)
150 return null;
151
152 ret.UserID = data.UserID;
153 ret.RegionID = data.RegionID;
154
155 return ret;
156 }
157
158 public PresenceInfo[] GetAgents(string[] userIDs)
159 {
160 List<PresenceInfo> info = new List<PresenceInfo>();
161
162 foreach (string userIDStr in userIDs)
163 {
164 PresenceData[] data = m_Database.Get("UserID", userIDStr);
165
166 foreach (PresenceData d in data)
167 {
168 PresenceInfo ret = new PresenceInfo();
169
170 ret.UserID = d.UserID;
171 ret.RegionID = d.RegionID;
172
173 info.Add(ret);
174 }
175
176// m_log.DebugFormat(
177// "[PRESENCE SERVICE]: GetAgents for {0} found {1} presences", userIDStr, data.Length);
178 }
179
180 return info.ToArray();
181 }
182
183 /// <summary>
184 /// Return the user's Presence. This only really works well if !AllowDuplicatePresences, but that's the default.
185 /// </summary>
186 private PresenceData GetUser(string userID)
187 {
188 PresenceData[] data = m_Database.Get("UserID", userID);
189 if (data.Length > 0)
190 return data[0];
191 else
192 return null;
193 }
194
195 private PresenceData[] GetRegionAgents(UUID regionID)
196 {
197 return m_Database.Get("RegionID", regionID.ToString());
198 }
199
200 }
201} \ No newline at end of file
diff --git a/OpenSim/Services/PresenceService/PresenceServiceBase.cs b/OpenSim/Services/PresenceService/PresenceServiceBase.cs
new file mode 100644
index 0000000..a4adb2f
--- /dev/null
+++ b/OpenSim/Services/PresenceService/PresenceServiceBase.cs
@@ -0,0 +1,84 @@
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
28using System;
29using System.Reflection;
30using Nini.Config;
31using OpenSim.Framework;
32using OpenSim.Data;
33using OpenSim.Services.Interfaces;
34using OpenSim.Services.Base;
35
36namespace OpenSim.Services.PresenceService
37{
38 public class PresenceServiceBase : ServiceBase
39 {
40 protected IPresenceData m_Database = null;
41
42 public PresenceServiceBase(IConfigSource config)
43 : base(config)
44 {
45 string dllName = String.Empty;
46 string connString = String.Empty;
47 string realm = "Presence";
48
49 //
50 // Try reading the [DatabaseService] section, if it exists
51 //
52 IConfig dbConfig = config.Configs["DatabaseService"];
53 if (dbConfig != null)
54 {
55 if (dllName == String.Empty)
56 dllName = dbConfig.GetString("StorageProvider", String.Empty);
57 if (connString == String.Empty)
58 connString = dbConfig.GetString("ConnectionString", String.Empty);
59 }
60
61 //
62 // [PresenceService] section overrides [DatabaseService], if it exists
63 //
64 IConfig presenceConfig = config.Configs["PresenceService"];
65 if (presenceConfig != null)
66 {
67 dllName = presenceConfig.GetString("StorageProvider", dllName);
68 connString = presenceConfig.GetString("ConnectionString", connString);
69 realm = presenceConfig.GetString("Realm", realm);
70 }
71
72 //
73 // We tried, but this doesn't exist. We can't proceed.
74 //
75 if (dllName.Equals(String.Empty))
76 throw new Exception("No StorageProvider configured");
77
78 m_Database = LoadPlugin<IPresenceData>(dllName, new Object[] { connString, realm });
79 if (m_Database == null)
80 throw new Exception("Could not find a storage interface in the given module " + dllName);
81
82 }
83 }
84}
diff --git a/OpenSim/Services/PresenceService/Properties/AssemblyInfo.cs b/OpenSim/Services/PresenceService/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..9ef0ff3
--- /dev/null
+++ b/OpenSim/Services/PresenceService/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("OpenSim.Services.PresenceService")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("http://opensimulator.org")]
12[assembly: AssemblyProduct("OpenSim")]
13[assembly: AssemblyCopyright("OpenSimulator developers")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("a875a0bd-eab0-40a2-b5c4-3afddc3b4d2d")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32[assembly: AssemblyVersion("0.8.2.*")]
33