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