clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Net; |
||
31 | using System.Reflection; |
||
32 | using Nini.Config; |
||
33 | using log4net; |
||
34 | using OpenSim.Framework; |
||
35 | using OpenSim.Framework.Console; |
||
36 | using OpenSim.Data; |
||
37 | using OpenSim.Services.Interfaces; |
||
38 | using OpenMetaverse; |
||
39 | |||
40 | namespace 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 | } |