aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/PresenceService/PresenceService.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/PresenceService/PresenceService.cs177
1 files changed, 166 insertions, 11 deletions
diff --git a/OpenSim/Services/PresenceService/PresenceService.cs b/OpenSim/Services/PresenceService/PresenceService.cs
index 2157462..ea8d673 100644
--- a/OpenSim/Services/PresenceService/PresenceService.cs
+++ b/OpenSim/Services/PresenceService/PresenceService.cs
@@ -41,27 +41,182 @@ 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 data.Data["Position"] = d[0].Data["Position"];
76 data.Data["LookAt"] = d[0].Data["LookAt"];
77
78 data.RegionID = d[0].RegionID;
79 }
80 else
81 {
82 data.Data["HomeRegionID"] = UUID.Zero.ToString();
83 data.Data["HomePosition"] = new Vector3(128, 128, 0).ToString();
84 data.Data["HomeLookAt"] = new Vector3(0, 1, 0).ToString();
85 }
86
87 m_Database.Store(data);
88
89 m_log.DebugFormat("[PRESENCE SERVICE]: LoginAgent {0} with session {1} and ssession {2}",
90 userID, sessionID, secureSessionID);
91 return true;
92 }
93
94 public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat)
95 {
96 PresenceData data = m_Database.Get(sessionID);
97 if (data == null)
98 return false;
99
100 PresenceData[] d = m_Database.Get("UserID", data.UserID);
101
102 m_log.DebugFormat("[PRESENCE SERVICE]: LogoutAgent {0} with {1} sessions currently present", data.UserID, d.Length);
103 if (d.Length > 1)
104 {
105 m_Database.Delete("UserID", data.UserID);
106 }
107
108 data.Data["Online"] = "false";
109 data.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString();
110 data.Data["Position"] = position.ToString();
111 data.Data["LookAt"] = lookat.ToString();
112
113 m_Database.Store(data);
114
115 return true;
116 }
117
118 public bool LogoutRegionAgents(UUID regionID)
119 {
120 m_Database.LogoutRegionAgents(regionID);
121
122 return true;
123 }
124
125
126 public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
127 {
128 m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent with session {0} in region {1}", sessionID, regionID);
129 try
130 {
131 PresenceData pdata = m_Database.Get(sessionID);
132 if (pdata == null)
133 return false;
134 if (pdata.Data == null)
135 return false;
136
137 if (!pdata.Data.ContainsKey("Online") || (pdata.Data.ContainsKey("Online") && pdata.Data["Online"] == "false"))
138 {
139 m_log.WarnFormat("[PRESENCE SERVICE]: Someone tried to report presence of an agent who's not online");
140 return false;
141 }
142
143 return m_Database.ReportAgent(sessionID, regionID,
144 position.ToString(), lookAt.ToString());
145 }
146 catch (Exception e)
147 {
148 m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent threw exception {0}", e.StackTrace);
149 return false;
150 }
151 }
152
153 public PresenceInfo GetAgent(UUID sessionID)
154 {
155 PresenceInfo ret = new PresenceInfo();
156
157 PresenceData data = m_Database.Get(sessionID);
158 if (data == null)
159 return null;
160
161 ret.UserID = data.UserID;
162 ret.RegionID = data.RegionID;
163 if (data.Data.ContainsKey("Online"))
164 ret.Online = bool.Parse(data.Data["Online"]);
165 if (data.Data.ContainsKey("Login"))
166 ret.Login = Util.ToDateTime(Convert.ToInt32(data.Data["Login"]));
167 if (data.Data.ContainsKey("Logout"))
168 ret.Logout = Util.ToDateTime(Convert.ToInt32(data.Data["Logout"]));
169 if (data.Data.ContainsKey("Position"))
170 ret.Position = Vector3.Parse(data.Data["Position"]);
171 if (data.Data.ContainsKey("LookAt"))
172 ret.LookAt = Vector3.Parse(data.Data["LookAt"]);
173 if (data.Data.ContainsKey("HomeRegionID"))
174 ret.HomeRegionID = new UUID(data.Data["HomeRegionID"]);
175 if (data.Data.ContainsKey("HomePosition"))
176 ret.HomePosition = Vector3.Parse(data.Data["HomePosition"]);
177 if (data.Data.ContainsKey("HomeLookAt"))
178 ret.HomeLookAt = Vector3.Parse(data.Data["HomeLookAt"]);
179
180 return ret;
181 }
182
183 public PresenceInfo[] GetAgents(string[] userIDs)
184 {
185 List<PresenceInfo> info = new List<PresenceInfo>();
186
187 foreach (string userIDStr in userIDs)
188 {
189 PresenceData[] data = m_Database.Get("UserID",
190 userIDStr);
191
192 foreach (PresenceData d in data)
193 {
194 PresenceInfo ret = new PresenceInfo();
195
196 ret.UserID = d.UserID;
197 ret.RegionID = d.RegionID;
198 ret.Online = bool.Parse(d.Data["Online"]);
199 ret.Login = Util.ToDateTime(Convert.ToInt32(
200 d.Data["Login"]));
201 ret.Logout = Util.ToDateTime(Convert.ToInt32(
202 d.Data["Logout"]));
203 ret.Position = Vector3.Parse(d.Data["Position"]);
204 ret.LookAt = Vector3.Parse(d.Data["LookAt"]);
205 ret.HomeRegionID = new UUID(d.Data["HomeRegionID"]);
206 ret.HomePosition = Vector3.Parse(d.Data["HomePosition"]);
207 ret.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]);
208
209 info.Add(ret);
210 }
211 }
212
213 // m_log.DebugFormat("[PRESENCE SERVICE]: GetAgents for {0} userIDs found {1} presences", userIDs.Length, info.Count);
214 return info.ToArray();
215 }
216
217 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
218 {
219 return m_Database.SetHomeLocation(userID, regionID, position, lookAt);
65 } 220 }
66 } 221 }
67} 222}