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