aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/MessagingServer.Modules/MessageService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Grid/MessagingServer.Modules/MessageService.cs')
-rw-r--r--OpenSim/Grid/MessagingServer.Modules/MessageService.cs503
1 files changed, 0 insertions, 503 deletions
diff --git a/OpenSim/Grid/MessagingServer.Modules/MessageService.cs b/OpenSim/Grid/MessagingServer.Modules/MessageService.cs
deleted file mode 100644
index 8ad1e9c..0000000
--- a/OpenSim/Grid/MessagingServer.Modules/MessageService.cs
+++ /dev/null
@@ -1,503 +0,0 @@
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;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33using System.Threading;
34using System.Timers;
35using log4net;
36using Nwc.XmlRpc;
37using OpenMetaverse;
38using OpenSim.Data;
39using OpenSim.Framework;
40using OpenSim.Grid.Framework;
41using Timer=System.Timers.Timer;
42
43namespace OpenSim.Grid.MessagingServer.Modules
44{
45 public class MessageService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private MessageServerConfig m_cfg;
50 private UserDataBaseService m_userDataBaseService;
51
52 private IGridServiceCore m_messageCore;
53
54 private IInterServiceUserService m_userServerModule;
55 private IMessageRegionLookup m_regionModule;
56
57 // a dictionary of all current presences this server knows about
58 private Dictionary<UUID, UserPresenceData> m_presences = new Dictionary<UUID,UserPresenceData>();
59
60 public MessageService(MessageServerConfig cfg, IGridServiceCore messageCore, UserDataBaseService userDataBaseService)
61 {
62 m_cfg = cfg;
63 m_messageCore = messageCore;
64
65 m_userDataBaseService = userDataBaseService;
66
67 //???
68 UserConfig uc = new UserConfig();
69 uc.DatabaseConnect = cfg.DatabaseConnect;
70 uc.DatabaseProvider = cfg.DatabaseProvider;
71 }
72
73 public void Initialise()
74 {
75 }
76
77 public void PostInitialise()
78 {
79 IInterServiceUserService messageUserServer;
80 if (m_messageCore.TryGet<IInterServiceUserService>(out messageUserServer))
81 {
82 m_userServerModule = messageUserServer;
83 }
84
85 IMessageRegionLookup messageRegion;
86 if (m_messageCore.TryGet<IMessageRegionLookup>(out messageRegion))
87 {
88 m_regionModule = messageRegion;
89 }
90 }
91
92 public void RegisterHandlers()
93 {
94 //have these in separate method as some servers restart the http server and reregister all the handlers.
95
96 }
97
98 #region FriendList Methods
99
100 /// <summary>
101 /// Process Friendlist subscriptions for a user
102 /// The login method calls this for a User
103 /// </summary>
104 /// <param name="userpresence">The Agent we're processing the friendlist subscriptions for</param>
105 private void ProcessFriendListSubscriptions(UserPresenceData userpresence)
106 {
107 lock (m_presences)
108 {
109 m_presences[userpresence.agentData.AgentID] = userpresence;
110 }
111
112 Dictionary<UUID, FriendListItem> uFriendList = userpresence.friendData;
113 foreach (KeyValuePair<UUID, FriendListItem> pair in uFriendList)
114 {
115 UserPresenceData friendup = null;
116 lock (m_presences)
117 {
118 m_presences.TryGetValue(pair.Key, out friendup);
119 }
120 if (friendup != null)
121 {
122 SubscribeToPresenceUpdates(userpresence, friendup, pair.Value);
123 }
124 }
125 }
126
127 /// <summary>
128 /// Enqueues a presence update, sending info about user 'talkingAbout' to user 'receiver'.
129 /// </summary>
130 /// <param name="talkingAbout">We are sending presence information about this user.</param>
131 /// <param name="receiver">We are sending the presence update to this user</param>
132 private void enqueuePresenceUpdate(UserPresenceData talkingAbout, UserPresenceData receiver)
133 {
134 UserAgentData p2Handle = m_userDataBaseService.GetUserAgentData(receiver.agentData.AgentID);
135 if (p2Handle != null)
136 {
137 if (receiver.lookupUserRegionYN)
138 {
139 receiver.regionData.regionHandle = p2Handle.Handle;
140 }
141 else
142 {
143 receiver.lookupUserRegionYN = true; // TODO Huh?
144 }
145
146 PresenceInformer friendlistupdater = new PresenceInformer();
147 friendlistupdater.presence1 = talkingAbout;
148 friendlistupdater.presence2 = receiver;
149 friendlistupdater.OnGetRegionData += m_regionModule.GetRegionInfo;
150 friendlistupdater.OnDone += PresenceUpdateDone;
151 Util.FireAndForget(friendlistupdater.go);
152 }
153 else
154 {
155 m_log.WarnFormat("no data found for user {0}", receiver.agentData.AgentID);
156 // Skip because we can't find any data on the user
157 }
158 }
159
160 /// <summary>
161 /// Does the necessary work to subscribe one agent to another's presence notifications
162 /// Gets called by ProcessFriendListSubscriptions. You shouldn't call this directly
163 /// unless you know what you're doing
164 /// </summary>
165 /// <param name="userpresence">P1</param>
166 /// <param name="friendpresence">P2</param>
167 /// <param name="uFriendListItem"></param>
168 private void SubscribeToPresenceUpdates(UserPresenceData userpresence,
169 UserPresenceData friendpresence,
170 FriendListItem uFriendListItem)
171 {
172 // Can the friend see me online?
173 if ((uFriendListItem.FriendListOwnerPerms & (uint)FriendRights.CanSeeOnline) != 0)
174 {
175 // tell user to update friend about user's presence changes
176 if (!userpresence.subscriptionData.Contains(friendpresence.agentData.AgentID))
177 {
178 userpresence.subscriptionData.Add(friendpresence.agentData.AgentID);
179 }
180
181 // send an update about user's presence to the friend
182 enqueuePresenceUpdate(userpresence, friendpresence);
183 }
184
185 // Can I see the friend online?
186 if ((uFriendListItem.FriendPerms & (uint)FriendRights.CanSeeOnline) != 0)
187 {
188 // tell friend to update user about friend's presence changes
189 if (!friendpresence.subscriptionData.Contains(userpresence.agentData.AgentID))
190 {
191 friendpresence.subscriptionData.Add(userpresence.agentData.AgentID);
192 }
193
194 // send an update about friend's presence to user.
195 enqueuePresenceUpdate(friendpresence, userpresence);
196 }
197 }
198
199 /// <summary>
200 /// Logoff Processor. Call this to clean up agent presence data and send logoff presence notifications
201 /// </summary>
202 /// <param name="AgentID"></param>
203 private void ProcessLogOff(UUID AgentID)
204 {
205 m_log.Info("[LOGOFF]: Processing Logoff");
206
207 UserPresenceData userPresence = null;
208 lock (m_presences)
209 {
210 m_presences.TryGetValue(AgentID, out userPresence);
211 }
212
213 if (userPresence != null) // found the user
214 {
215 List<UUID> AgentsNeedingNotification = userPresence.subscriptionData;
216 userPresence.OnlineYN = false;
217
218 for (int i = 0; i < AgentsNeedingNotification.Count; i++)
219 {
220 UserPresenceData friendPresence = null;
221 lock (m_presences)
222 {
223 m_presences.TryGetValue(AgentsNeedingNotification[i], out friendPresence);
224 }
225
226 // This might need to be enumerated and checked before we try to remove it.
227 if (friendPresence != null)
228 {
229 lock (friendPresence)
230 {
231 // no updates for this user anymore
232 friendPresence.subscriptionData.Remove(AgentID);
233
234 // set user's entry in the friend's list to offline (if it exists)
235 if (friendPresence.friendData.ContainsKey(AgentID))
236 {
237 friendPresence.friendData[AgentID].onlinestatus = false;
238 }
239 }
240
241 enqueuePresenceUpdate(userPresence, friendPresence);
242 }
243 }
244 }
245 }
246
247 #endregion
248
249 private void PresenceUpdateDone(PresenceInformer obj)
250 {
251 obj.OnGetRegionData -= m_regionModule.GetRegionInfo;
252 obj.OnDone -= PresenceUpdateDone;
253 }
254
255 #region UserServer Comms
256
257 /// <summary>
258 /// Returns a list of FriendsListItems that describe the friends and permissions in the friend
259 /// relationship for UUID friendslistowner. For faster lookup, we index by friend's UUID.
260 /// </summary>
261 /// <param name="friendlistowner">The agent that we're retreiving the friends Data for.</param>
262 private Dictionary<UUID, FriendListItem> GetUserFriendList(UUID friendlistowner)
263 {
264 Dictionary<UUID, FriendListItem> buddies = new Dictionary<UUID,FriendListItem>();
265
266 try
267 {
268 Hashtable param = new Hashtable();
269 param["ownerID"] = friendlistowner.ToString();
270
271 IList parameters = new ArrayList();
272 parameters.Add(param);
273 XmlRpcRequest req = new XmlRpcRequest("get_user_friend_list", parameters);
274 XmlRpcResponse resp = req.Send(m_cfg.UserServerURL, 3000);
275 Hashtable respData = (Hashtable)resp.Value;
276
277 if (respData.Contains("avcount"))
278 {
279 buddies = ConvertXMLRPCDataToFriendListItemList(respData);
280 }
281
282 }
283 catch (WebException e)
284 {
285 m_log.Warn("Error when trying to fetch Avatar's friends list: " +
286 e.Message);
287 // Return Empty list (no friends)
288 }
289 return buddies;
290 }
291
292 /// <summary>
293 /// Converts XMLRPC Friend List to FriendListItem Object
294 /// </summary>
295 /// <param name="data">XMLRPC response data Hashtable</param>
296 /// <returns></returns>
297 public Dictionary<UUID, FriendListItem> ConvertXMLRPCDataToFriendListItemList(Hashtable data)
298 {
299 Dictionary<UUID, FriendListItem> buddies = new Dictionary<UUID,FriendListItem>();
300 int buddycount = Convert.ToInt32((string)data["avcount"]);
301
302 for (int i = 0; i < buddycount; i++)
303 {
304 FriendListItem buddylistitem = new FriendListItem();
305
306 buddylistitem.FriendListOwner = new UUID((string)data["ownerID" + i.ToString()]);
307 buddylistitem.Friend = new UUID((string)data["friendID" + i.ToString()]);
308 buddylistitem.FriendListOwnerPerms = (uint)Convert.ToInt32((string)data["ownerPerms" + i.ToString()]);
309 buddylistitem.FriendPerms = (uint)Convert.ToInt32((string)data["friendPerms" + i.ToString()]);
310
311 buddies.Add(buddylistitem.Friend, buddylistitem);
312 }
313
314 return buddies;
315 }
316
317 /// <summary>
318 /// UserServer sends an expect_user method
319 /// this handles the method and provisions the
320 /// necessary info for presence to work
321 /// </summary>
322 /// <param name="request">UserServer Data</param>
323 /// <returns></returns>
324 public XmlRpcResponse UserLoggedOn(XmlRpcRequest request, IPEndPoint remoteClient)
325 {
326 try
327 {
328 Hashtable requestData = (Hashtable)request.Params[0];
329
330 AgentCircuitData agentData = new AgentCircuitData();
331 agentData.SessionID = new UUID((string)requestData["sessionid"]);
332 agentData.SecureSessionID = new UUID((string)requestData["secure_session_id"]);
333 agentData.firstname = (string)requestData["firstname"];
334 agentData.lastname = (string)requestData["lastname"];
335 agentData.AgentID = new UUID((string)requestData["agentid"]);
336 agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
337 agentData.CapsPath = (string)requestData["caps_path"];
338
339 if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1"))
340 {
341 agentData.child = true;
342 }
343 else
344 {
345 agentData.startpos =
346 new Vector3(Convert.ToSingle(requestData["positionx"]),
347 Convert.ToSingle(requestData["positiony"]),
348 Convert.ToSingle(requestData["positionz"]));
349 agentData.child = false;
350 }
351
352 ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
353
354 m_log.InfoFormat("[LOGON]: User {0} {1} logged into region {2} as {3} agent, building indexes for user",
355 agentData.firstname, agentData.lastname, regionHandle, agentData.child ? "child" : "root");
356
357 UserPresenceData up = new UserPresenceData();
358 up.agentData = agentData;
359 up.friendData = GetUserFriendList(agentData.AgentID);
360 up.regionData = m_regionModule.GetRegionInfo(regionHandle);
361 up.OnlineYN = true;
362 up.lookupUserRegionYN = false;
363 ProcessFriendListSubscriptions(up);
364
365 }
366 catch (Exception e)
367 {
368 m_log.WarnFormat("[LOGIN]: Exception on UserLoggedOn: {0}", e);
369 }
370
371 return new XmlRpcResponse();
372
373 }
374
375 /// <summary>
376 /// The UserServer got a Logoff message
377 /// Cleanup time for that user. Send out presence notifications
378 /// </summary>
379 /// <param name="request"></param>
380 /// <returns></returns>
381 public XmlRpcResponse UserLoggedOff(XmlRpcRequest request, IPEndPoint remoteClient)
382 {
383 try
384 {
385 m_log.Info("[USERLOGOFF]: User logged off called");
386 Hashtable requestData = (Hashtable)request.Params[0];
387
388 UUID AgentID = new UUID((string)requestData["agentid"]);
389 ProcessLogOff(AgentID);
390 }
391 catch (Exception e)
392 {
393 m_log.WarnFormat("[USERLOGOFF]: Exception on UserLoggedOff: {0}", e);
394 }
395
396 return new XmlRpcResponse();
397 }
398
399 #endregion
400
401 public XmlRpcResponse GetPresenceInfoBulk(XmlRpcRequest request, IPEndPoint remoteClient)
402 {
403 Hashtable paramHash = (Hashtable)request.Params[0];
404 Hashtable result = new Hashtable();
405
406 // TODO check access (recv_key/send_key)
407
408 IList list = (IList)paramHash["uuids"];
409
410 // convert into List<UUID>
411 List<UUID> uuids = new List<UUID>();
412 for (int i = 0; i < list.Count; ++i)
413 {
414 UUID uuid;
415 if (UUID.TryParse((string)list[i], out uuid))
416 {
417 uuids.Add(uuid);
418 }
419 }
420
421 try {
422 Dictionary<UUID, FriendRegionInfo> infos = m_userDataBaseService.GetFriendRegionInfos(uuids);
423 m_log.DebugFormat("[FRIEND]: Got {0} region entries back.", infos.Count);
424 int count = 0;
425 foreach (KeyValuePair<UUID, FriendRegionInfo> pair in infos)
426 {
427 result["uuid_" + count] = pair.Key.ToString();
428 result["isOnline_" + count] = pair.Value.isOnline;
429 result["regionHandle_" + count] = pair.Value.regionHandle.ToString(); // XML-RPC doesn't know ulongs
430 ++count;
431 }
432 result["count"] = count;
433
434 XmlRpcResponse response = new XmlRpcResponse();
435 response.Value = result;
436 return response;
437 }
438 catch(Exception e) {
439 m_log.Error("Got exception:", e);
440 throw e;
441 }
442 }
443
444 public XmlRpcResponse AgentLocation(XmlRpcRequest request, IPEndPoint remoteClient)
445 {
446 Hashtable requestData = (Hashtable)request.Params[0];
447 Hashtable result = new Hashtable();
448 result["success"] = "FALSE";
449
450 if (m_userServerModule.SendToUserServer(requestData, "agent_location"))
451 result["success"] = "TRUE";
452
453
454 XmlRpcResponse response = new XmlRpcResponse();
455 response.Value = result;
456 return response;
457 }
458
459 public XmlRpcResponse AgentLeaving(XmlRpcRequest request, IPEndPoint remoteClient)
460 {
461 Hashtable requestData = (Hashtable)request.Params[0];
462 Hashtable result = new Hashtable();
463 result["success"] = "FALSE";
464
465 if (m_userServerModule.SendToUserServer(requestData, "agent_leaving"))
466 result["success"] = "TRUE";
467
468 XmlRpcResponse response = new XmlRpcResponse();
469 response.Value = result;
470 return response;
471 }
472
473 public XmlRpcResponse ProcessRegionShutdown(XmlRpcRequest request, IPEndPoint remoteClient)
474 {
475 Hashtable requestData = (Hashtable)request.Params[0];
476 Hashtable result = new Hashtable();
477 result["success"] = "FALSE";
478
479 UUID regionID;
480 if (UUID.TryParse((string)requestData["regionid"], out regionID))
481 {
482 m_log.DebugFormat("[PRESENCE] Processing region restart for {0}", regionID);
483 result["success"] = "TRUE";
484
485 foreach (UserPresenceData up in m_presences.Values)
486 {
487 if (up.regionData.UUID == regionID)
488 {
489 if (up.OnlineYN)
490 {
491 m_log.DebugFormat("[PRESENCE] Logging off {0} because the region they were in has gone", up.agentData.AgentID);
492 ProcessLogOff(up.agentData.AgentID);
493 }
494 }
495 }
496 }
497
498 XmlRpcResponse response = new XmlRpcResponse();
499 response.Value = result;
500 return response;
501 }
502 }
503} \ No newline at end of file