diff options
Diffstat (limited to 'OpenSim/Services/PresenceService')
-rw-r--r-- | OpenSim/Services/PresenceService/PresenceService.cs | 172 | ||||
-rw-r--r-- | OpenSim/Services/PresenceService/PresenceServiceBase.cs | 4 |
2 files changed, 163 insertions, 13 deletions
diff --git a/OpenSim/Services/PresenceService/PresenceService.cs b/OpenSim/Services/PresenceService/PresenceService.cs index 2157462..350eac8 100644 --- a/OpenSim/Services/PresenceService/PresenceService.cs +++ b/OpenSim/Services/PresenceService/PresenceService.cs | |||
@@ -41,27 +41,177 @@ namespace OpenSim.Services.PresenceService | |||
41 | { | 41 | { |
42 | public class PresenceService : PresenceServiceBase, IPresenceService | 42 | public class PresenceService : PresenceServiceBase, IPresenceService |
43 | { | 43 | { |
44 | // private static readonly ILog m_log = | 44 | private static readonly ILog m_log = |
45 | // LogManager.GetLogger( | 45 | LogManager.GetLogger( |
46 | // MethodBase.GetCurrentMethod().DeclaringType); | 46 | MethodBase.GetCurrentMethod().DeclaringType); |
47 | 47 | ||
48 | public PresenceService(IConfigSource config) | 48 | public PresenceService(IConfigSource config) |
49 | : base(config) | 49 | : base(config) |
50 | { | 50 | { |
51 | m_log.Debug("[PRESENCE SERVICE]: Starting presence service"); | ||
51 | } | 52 | } |
52 | 53 | ||
53 | public bool Report(PresenceInfo presence) | 54 | public bool LoginAgent(string userID, UUID sessionID, |
55 | UUID secureSessionID) | ||
54 | { | 56 | { |
55 | PresenceData p = new PresenceData(); | 57 | m_Database.Prune(userID); |
56 | p.Data = new Dictionary<string, string>(); | ||
57 | 58 | ||
58 | p.UUID = presence.PrincipalID; | 59 | PresenceData[] d = m_Database.Get("UserID", userID); |
59 | p.currentRegion = presence.RegionID; | ||
60 | 60 | ||
61 | foreach (KeyValuePair<string, string> kvp in presence.Data) | 61 | PresenceData data = new PresenceData(); |
62 | p.Data[kvp.Key] = kvp.Value; | ||
63 | 62 | ||
64 | return false; | 63 | data.UserID = userID; |
64 | data.RegionID = UUID.Zero; | ||
65 | data.SessionID = sessionID; | ||
66 | data.Data = new Dictionary<string, string>(); | ||
67 | data.Data["SecureSessionID"] = secureSessionID.ToString(); | ||
68 | data.Data["Online"] = "true"; | ||
69 | data.Data["Login"] = Util.UnixTimeSinceEpoch().ToString(); | ||
70 | if (d != null && d.Length > 0) | ||
71 | { | ||
72 | data.Data["HomeRegionID"] = d[0].Data["HomeRegionID"]; | ||
73 | data.Data["HomePosition"] = d[0].Data["HomePosition"]; | ||
74 | data.Data["HomeLookAt"] = d[0].Data["HomeLookAt"]; | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | data.Data["HomeRegionID"] = UUID.Zero.ToString(); | ||
79 | data.Data["HomePosition"] = new Vector3(128, 128, 0).ToString(); | ||
80 | data.Data["HomeLookAt"] = new Vector3(0, 1, 0).ToString(); | ||
81 | } | ||
82 | |||
83 | m_Database.Store(data); | ||
84 | |||
85 | m_log.DebugFormat("[PRESENCE SERVICE]: LoginAgent {0} with session {1} and ssession {2}", | ||
86 | userID, sessionID, secureSessionID); | ||
87 | return true; | ||
88 | } | ||
89 | |||
90 | public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) | ||
91 | { | ||
92 | PresenceData data = m_Database.Get(sessionID); | ||
93 | if (data == null) | ||
94 | return false; | ||
95 | |||
96 | PresenceData[] d = m_Database.Get("UserID", data.UserID); | ||
97 | |||
98 | m_log.DebugFormat("[PRESENCE SERVICE]: LogoutAgent {0} with {1} sessions currently present", data.UserID, d.Length); | ||
99 | if (d.Length > 1) | ||
100 | { | ||
101 | m_Database.Delete("UserID", data.UserID); | ||
102 | } | ||
103 | |||
104 | data.Data["Online"] = "false"; | ||
105 | data.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString(); | ||
106 | data.Data["Position"] = position.ToString(); | ||
107 | data.Data["LookAt"] = lookat.ToString(); | ||
108 | |||
109 | m_Database.Store(data); | ||
110 | |||
111 | return true; | ||
112 | } | ||
113 | |||
114 | public bool LogoutRegionAgents(UUID regionID) | ||
115 | { | ||
116 | m_Database.LogoutRegionAgents(regionID); | ||
117 | |||
118 | return true; | ||
119 | } | ||
120 | |||
121 | |||
122 | public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
123 | { | ||
124 | m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent with session {0} in region {1}", sessionID, regionID); | ||
125 | try | ||
126 | { | ||
127 | PresenceData pdata = m_Database.Get(sessionID); | ||
128 | if (pdata == null) | ||
129 | return false; | ||
130 | if (pdata.Data == null) | ||
131 | return false; | ||
132 | |||
133 | if (!pdata.Data.ContainsKey("Online") || (pdata.Data.ContainsKey("Online") && pdata.Data["Online"] == "false")) | ||
134 | { | ||
135 | m_log.WarnFormat("[PRESENCE SERVICE]: Someone tried to report presence of an agent who's not online"); | ||
136 | return false; | ||
137 | } | ||
138 | |||
139 | return m_Database.ReportAgent(sessionID, regionID, | ||
140 | position.ToString(), lookAt.ToString()); | ||
141 | } | ||
142 | catch (Exception e) | ||
143 | { | ||
144 | m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent threw exception {0}", e.StackTrace); | ||
145 | return false; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | public PresenceInfo GetAgent(UUID sessionID) | ||
150 | { | ||
151 | PresenceInfo ret = new PresenceInfo(); | ||
152 | |||
153 | PresenceData data = m_Database.Get(sessionID); | ||
154 | if (data == null) | ||
155 | return null; | ||
156 | |||
157 | ret.UserID = data.UserID; | ||
158 | ret.RegionID = data.RegionID; | ||
159 | if (data.Data.ContainsKey("Online")) | ||
160 | ret.Online = bool.Parse(data.Data["Online"]); | ||
161 | if (data.Data.ContainsKey("Login")) | ||
162 | ret.Login = Util.ToDateTime(Convert.ToInt32(data.Data["Login"])); | ||
163 | if (data.Data.ContainsKey("Logout")) | ||
164 | ret.Logout = Util.ToDateTime(Convert.ToInt32(data.Data["Logout"])); | ||
165 | if (data.Data.ContainsKey("Position")) | ||
166 | ret.Position = Vector3.Parse(data.Data["Position"]); | ||
167 | if (data.Data.ContainsKey("LookAt")) | ||
168 | ret.LookAt = Vector3.Parse(data.Data["LookAt"]); | ||
169 | if (data.Data.ContainsKey("HomeRegionID")) | ||
170 | ret.HomeRegionID = new UUID(data.Data["HomeRegionID"]); | ||
171 | if (data.Data.ContainsKey("HomePosition")) | ||
172 | ret.HomePosition = Vector3.Parse(data.Data["HomePosition"]); | ||
173 | if (data.Data.ContainsKey("HomeLookAt")) | ||
174 | ret.HomeLookAt = Vector3.Parse(data.Data["HomeLookAt"]); | ||
175 | |||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | public PresenceInfo[] GetAgents(string[] userIDs) | ||
180 | { | ||
181 | List<PresenceInfo> info = new List<PresenceInfo>(); | ||
182 | |||
183 | foreach (string userIDStr in userIDs) | ||
184 | { | ||
185 | PresenceData[] data = m_Database.Get("UserID", | ||
186 | userIDStr); | ||
187 | |||
188 | foreach (PresenceData d in data) | ||
189 | { | ||
190 | PresenceInfo ret = new PresenceInfo(); | ||
191 | |||
192 | ret.UserID = d.UserID; | ||
193 | ret.RegionID = d.RegionID; | ||
194 | ret.Online = bool.Parse(d.Data["Online"]); | ||
195 | ret.Login = Util.ToDateTime(Convert.ToInt32( | ||
196 | d.Data["Login"])); | ||
197 | ret.Logout = Util.ToDateTime(Convert.ToInt32( | ||
198 | d.Data["Logout"])); | ||
199 | ret.Position = Vector3.Parse(d.Data["Position"]); | ||
200 | ret.LookAt = Vector3.Parse(d.Data["LookAt"]); | ||
201 | ret.HomeRegionID = new UUID(d.Data["HomeRegionID"]); | ||
202 | ret.HomePosition = Vector3.Parse(d.Data["HomePosition"]); | ||
203 | ret.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]); | ||
204 | |||
205 | info.Add(ret); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | return info.ToArray(); | ||
210 | } | ||
211 | |||
212 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
213 | { | ||
214 | return m_Database.SetHomeLocation(userID, regionID, position, lookAt); | ||
65 | } | 215 | } |
66 | } | 216 | } |
67 | } | 217 | } |
diff --git a/OpenSim/Services/PresenceService/PresenceServiceBase.cs b/OpenSim/Services/PresenceService/PresenceServiceBase.cs index 60a246b..a4adb2f 100644 --- a/OpenSim/Services/PresenceService/PresenceServiceBase.cs +++ b/OpenSim/Services/PresenceService/PresenceServiceBase.cs | |||
@@ -44,7 +44,7 @@ namespace OpenSim.Services.PresenceService | |||
44 | { | 44 | { |
45 | string dllName = String.Empty; | 45 | string dllName = String.Empty; |
46 | string connString = String.Empty; | 46 | string connString = String.Empty; |
47 | string realm = "agents"; | 47 | string realm = "Presence"; |
48 | 48 | ||
49 | // | 49 | // |
50 | // Try reading the [DatabaseService] section, if it exists | 50 | // Try reading the [DatabaseService] section, if it exists |
@@ -77,7 +77,7 @@ namespace OpenSim.Services.PresenceService | |||
77 | 77 | ||
78 | m_Database = LoadPlugin<IPresenceData>(dllName, new Object[] { connString, realm }); | 78 | m_Database = LoadPlugin<IPresenceData>(dllName, new Object[] { connString, realm }); |
79 | if (m_Database == null) | 79 | if (m_Database == null) |
80 | throw new Exception("Could not find a storage interface in the given module"); | 80 | throw new Exception("Could not find a storage interface in the given module " + dllName); |
81 | 81 | ||
82 | } | 82 | } |
83 | } | 83 | } |