aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/MessagingServer/MessageService.cs
diff options
context:
space:
mode:
authorMW2009-02-24 16:13:16 +0000
committerMW2009-02-24 16:13:16 +0000
commit98178b4e9f5637eed9ab5ebb7c44f2eb71c30093 (patch)
tree7602f67161fcf14990a840b57c672e2f24d9d0ae /OpenSim/Grid/MessagingServer/MessageService.cs
parentAdded OpenSim.Grid.GridServer.Modules, for the GridServer modules/components. (diff)
downloadopensim-SC-98178b4e9f5637eed9ab5ebb7c44f2eb71c30093.zip
opensim-SC-98178b4e9f5637eed9ab5ebb7c44f2eb71c30093.tar.gz
opensim-SC-98178b4e9f5637eed9ab5ebb7c44f2eb71c30093.tar.bz2
opensim-SC-98178b4e9f5637eed9ab5ebb7c44f2eb71c30093.tar.xz
Same treatment for the MessagingServer... added OpenSim.Grid.MessagingServer.Modules for the modules/components of it.
Diffstat (limited to 'OpenSim/Grid/MessagingServer/MessageService.cs')
-rw-r--r--OpenSim/Grid/MessagingServer/MessageService.cs488
1 files changed, 0 insertions, 488 deletions
diff --git a/OpenSim/Grid/MessagingServer/MessageService.cs b/OpenSim/Grid/MessagingServer/MessageService.cs
deleted file mode 100644
index a301732..0000000
--- a/OpenSim/Grid/MessagingServer/MessageService.cs
+++ /dev/null
@@ -1,488 +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 OpenSim 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
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 IUGAIMCore m_messageCore;
53
54 private IMessageUserServerService m_userServerModule;
55 private IMessageRegionService 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, IUGAIMCore 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 IMessageUserServerService messageUserServer;
80 if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer))
81 {
82 m_userServerModule = messageUserServer;
83 }
84
85 IMessageRegionService messageRegion;
86 if (m_messageCore.TryGet<IMessageRegionService>(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 WaitCallback cb = new WaitCallback(friendlistupdater.go);
152 ThreadPool.QueueUserWorkItem(cb);
153 }
154 else
155 {
156 m_log.WarnFormat("no data found for user {0}", receiver.agentData.AgentID);
157 // Skip because we can't find any data on the user
158 }
159 }
160
161 /// <summary>
162 /// Does the necessary work to subscribe one agent to another's presence notifications
163 /// Gets called by ProcessFriendListSubscriptions. You shouldn't call this directly
164 /// unless you know what you're doing
165 /// </summary>
166 /// <param name="userpresence">P1</param>
167 /// <param name="friendpresence">P2</param>
168 /// <param name="uFriendListItem"></param>
169 private void SubscribeToPresenceUpdates(UserPresenceData userpresence,
170 UserPresenceData friendpresence,
171 FriendListItem uFriendListItem)
172 {
173 // Can the friend see me online?
174 if ((uFriendListItem.FriendListOwnerPerms & (uint)FriendRights.CanSeeOnline) != 0)
175 {
176 // tell user to update friend about user's presence changes
177 if (!userpresence.subscriptionData.Contains(friendpresence.agentData.AgentID))
178 {
179 userpresence.subscriptionData.Add(friendpresence.agentData.AgentID);
180 }
181
182 // send an update about user's presence to the friend
183 enqueuePresenceUpdate(userpresence, friendpresence);
184 }
185
186 // Can I see the friend online?
187 if ((uFriendListItem.FriendPerms & (uint)FriendRights.CanSeeOnline) != 0)
188 {
189 // tell friend to update user about friend's presence changes
190 if (!friendpresence.subscriptionData.Contains(userpresence.agentData.AgentID))
191 {
192 friendpresence.subscriptionData.Add(userpresence.agentData.AgentID);
193 }
194
195 // send an update about friend's presence to user.
196 enqueuePresenceUpdate(friendpresence, userpresence);
197 }
198 }
199
200 /// <summary>
201 /// Logoff Processor. Call this to clean up agent presence data and send logoff presence notifications
202 /// </summary>
203 /// <param name="AgentID"></param>
204 private void ProcessLogOff(UUID AgentID)
205 {
206 m_log.Info("[LOGOFF]: Processing Logoff");
207
208 UserPresenceData userPresence = null;
209 lock (m_presences)
210 {
211 m_presences.TryGetValue(AgentID, out userPresence);
212 }
213
214 if (userPresence != null) // found the user
215 {
216 List<UUID> AgentsNeedingNotification = userPresence.subscriptionData;
217 userPresence.OnlineYN = false;
218
219 for (int i = 0; i < AgentsNeedingNotification.Count; i++)
220 {
221 UserPresenceData friendPresence = null;
222 lock (m_presences)
223 {
224 m_presences.TryGetValue(AgentsNeedingNotification[i], out friendPresence);
225 }
226
227 // This might need to be enumerated and checked before we try to remove it.
228 if (friendPresence != null)
229 {
230 lock (friendPresence)
231 {
232 // no updates for this user anymore
233 friendPresence.subscriptionData.Remove(AgentID);
234
235 // set user's entry in the friend's list to offline (if it exists)
236 if (friendPresence.friendData.ContainsKey(AgentID))
237 {
238 friendPresence.friendData[AgentID].onlinestatus = false;
239 }
240 }
241
242 enqueuePresenceUpdate(userPresence, friendPresence);
243 }
244 }
245 }
246 }
247
248 #endregion
249
250 private void PresenceUpdateDone(PresenceInformer obj)
251 {
252 obj.OnGetRegionData -= m_regionModule.GetRegionInfo;
253 obj.OnDone -= PresenceUpdateDone;
254 }
255
256 #region UserServer Comms
257
258 /// <summary>
259 /// Returns a list of FriendsListItems that describe the friends and permissions in the friend
260 /// relationship for UUID friendslistowner. For faster lookup, we index by friend's UUID.
261 /// </summary>
262 /// <param name="friendlistowner">The agent that we're retreiving the friends Data for.</param>
263 private Dictionary<UUID, FriendListItem> GetUserFriendList(UUID friendlistowner)
264 {
265 Dictionary<UUID, FriendListItem> buddies = new Dictionary<UUID,FriendListItem>();
266
267 try
268 {
269 Hashtable param = new Hashtable();
270 param["ownerID"] = friendlistowner.ToString();
271
272 IList parameters = new ArrayList();
273 parameters.Add(param);
274 XmlRpcRequest req = new XmlRpcRequest("get_user_friend_list", parameters);
275 XmlRpcResponse resp = req.Send(m_cfg.UserServerURL, 3000);
276 Hashtable respData = (Hashtable)resp.Value;
277
278 if (respData.Contains("avcount"))
279 {
280 buddies = ConvertXMLRPCDataToFriendListItemList(respData);
281 }
282
283 }
284 catch (WebException e)
285 {
286 m_log.Warn("Error when trying to fetch Avatar's friends list: " +
287 e.Message);
288 // Return Empty list (no friends)
289 }
290 return buddies;
291 }
292
293 /// <summary>
294 /// Converts XMLRPC Friend List to FriendListItem Object
295 /// </summary>
296 /// <param name="data">XMLRPC response data Hashtable</param>
297 /// <returns></returns>
298 public Dictionary<UUID, FriendListItem> ConvertXMLRPCDataToFriendListItemList(Hashtable data)
299 {
300 Dictionary<UUID, FriendListItem> buddies = new Dictionary<UUID,FriendListItem>();
301 int buddycount = Convert.ToInt32((string)data["avcount"]);
302
303 for (int i = 0; i < buddycount; i++)
304 {
305 FriendListItem buddylistitem = new FriendListItem();
306
307 buddylistitem.FriendListOwner = new UUID((string)data["ownerID" + i.ToString()]);
308 buddylistitem.Friend = new UUID((string)data["friendID" + i.ToString()]);
309 buddylistitem.FriendListOwnerPerms = (uint)Convert.ToInt32((string)data["ownerPerms" + i.ToString()]);
310 buddylistitem.FriendPerms = (uint)Convert.ToInt32((string)data["friendPerms" + i.ToString()]);
311
312 buddies.Add(buddylistitem.Friend, buddylistitem);
313 }
314
315 return buddies;
316 }
317
318 /// <summary>
319 /// UserServer sends an expect_user method
320 /// this handles the method and provisions the
321 /// necessary info for presence to work
322 /// </summary>
323 /// <param name="request">UserServer Data</param>
324 /// <returns></returns>
325 public XmlRpcResponse UserLoggedOn(XmlRpcRequest request)
326 {
327 Hashtable requestData = (Hashtable)request.Params[0];
328
329 AgentCircuitData agentData = new AgentCircuitData();
330 agentData.SessionID = new UUID((string)requestData["sessionid"]);
331 agentData.SecureSessionID = new UUID((string)requestData["secure_session_id"]);
332 agentData.firstname = (string)requestData["firstname"];
333 agentData.lastname = (string)requestData["lastname"];
334 agentData.AgentID = new UUID((string)requestData["agentid"]);
335 agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
336 agentData.CapsPath = (string)requestData["caps_path"];
337
338 if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1"))
339 {
340 agentData.child = true;
341 }
342 else
343 {
344 agentData.startpos =
345 new Vector3(Convert.ToSingle(requestData["positionx"]),
346 Convert.ToSingle(requestData["positiony"]),
347 Convert.ToSingle(requestData["positionz"]));
348 agentData.child = false;
349 }
350
351 ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
352
353 m_log.InfoFormat("[LOGON]: User {0} {1} logged into region {2} as {3} agent, building indexes for user",
354 agentData.firstname, agentData.lastname, regionHandle, agentData.child ? "child" : "root");
355
356 UserPresenceData up = new UserPresenceData();
357 up.agentData = agentData;
358 up.friendData = GetUserFriendList(agentData.AgentID);
359 up.regionData = m_regionModule.GetRegionInfo(regionHandle);
360 up.OnlineYN = true;
361 up.lookupUserRegionYN = false;
362 ProcessFriendListSubscriptions(up);
363
364 return new XmlRpcResponse();
365 }
366
367 /// <summary>
368 /// The UserServer got a Logoff message
369 /// Cleanup time for that user. Send out presence notifications
370 /// </summary>
371 /// <param name="request"></param>
372 /// <returns></returns>
373 public XmlRpcResponse UserLoggedOff(XmlRpcRequest request)
374 {
375 m_log.Info("[USERLOGOFF]: User logged off called");
376 Hashtable requestData = (Hashtable)request.Params[0];
377
378 UUID AgentID = new UUID((string)requestData["agentid"]);
379 ProcessLogOff(AgentID);
380
381 return new XmlRpcResponse();
382 }
383
384 #endregion
385
386 public XmlRpcResponse GetPresenceInfoBulk(XmlRpcRequest request)
387 {
388 Hashtable paramHash = (Hashtable)request.Params[0];
389 Hashtable result = new Hashtable();
390
391 // TODO check access (recv_key/send_key)
392
393 IList list = (IList)paramHash["uuids"];
394
395 // convert into List<UUID>
396 List<UUID> uuids = new List<UUID>();
397 for (int i = 0; i < list.Count; ++i)
398 {
399 UUID uuid;
400 if (UUID.TryParse((string)list[i], out uuid))
401 {
402 uuids.Add(uuid);
403 }
404 }
405
406 try {
407 Dictionary<UUID, FriendRegionInfo> infos = m_userDataBaseService.GetFriendRegionInfos(uuids);
408 m_log.DebugFormat("[FRIEND]: Got {0} region entries back.", infos.Count);
409 int count = 0;
410 foreach (KeyValuePair<UUID, FriendRegionInfo> pair in infos)
411 {
412 result["uuid_" + count] = pair.Key.ToString();
413 result["isOnline_" + count] = pair.Value.isOnline;
414 result["regionHandle_" + count] = pair.Value.regionHandle.ToString(); // XML-RPC doesn't know ulongs
415 ++count;
416 }
417 result["count"] = count;
418
419 XmlRpcResponse response = new XmlRpcResponse();
420 response.Value = result;
421 return response;
422 }
423 catch(Exception e) {
424 m_log.Error("Got exception:", e);
425 throw e;
426 }
427 }
428
429 public XmlRpcResponse AgentLocation(XmlRpcRequest request)
430 {
431 Hashtable requestData = (Hashtable)request.Params[0];
432 Hashtable result = new Hashtable();
433 result["success"] = "FALSE";
434
435 if (m_userServerModule.SendToUserServer(requestData, "agent_location"))
436 result["success"] = "TRUE";
437
438
439 XmlRpcResponse response = new XmlRpcResponse();
440 response.Value = result;
441 return response;
442 }
443
444 public XmlRpcResponse AgentLeaving(XmlRpcRequest request)
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_leaving"))
451 result["success"] = "TRUE";
452
453 XmlRpcResponse response = new XmlRpcResponse();
454 response.Value = result;
455 return response;
456 }
457
458 public XmlRpcResponse ProcessRegionShutdown(XmlRpcRequest request)
459 {
460 Hashtable requestData = (Hashtable)request.Params[0];
461 Hashtable result = new Hashtable();
462 result["success"] = "FALSE";
463
464 UUID regionID;
465 if (UUID.TryParse((string)requestData["regionid"], out regionID))
466 {
467 m_log.DebugFormat("[PRESENCE] Processing region restart for {0}", regionID);
468 result["success"] = "TRUE";
469
470 foreach (UserPresenceData up in m_presences.Values)
471 {
472 if (up.regionData.UUID == regionID)
473 {
474 if (up.OnlineYN)
475 {
476 m_log.DebugFormat("[PRESENCE] Logging off {0} because the region they were in has gone", up.agentData.AgentID);
477 ProcessLogOff(up.agentData.AgentID);
478 }
479 }
480 }
481 }
482
483 XmlRpcResponse response = new XmlRpcResponse();
484 response.Value = result;
485 return response;
486 }
487 }
488} \ No newline at end of file