diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs (renamed from OpenSim/Region/Environment/Modules/FriendsModule.cs) | 1008 |
1 files changed, 504 insertions, 504 deletions
diff --git a/OpenSim/Region/Environment/Modules/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs index 7078906..3b0cc4c 100644 --- a/OpenSim/Region/Environment/Modules/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs | |||
@@ -1,504 +1,504 @@ | |||
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 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Reflection; | 29 | using System.Reflection; |
30 | using libsecondlife; | 30 | using libsecondlife; |
31 | using libsecondlife.Packets; | 31 | using libsecondlife.Packets; |
32 | using log4net; | 32 | using log4net; |
33 | using Nini.Config; | 33 | using Nini.Config; |
34 | using Nwc.XmlRpc; | 34 | using Nwc.XmlRpc; |
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Region.Environment.Interfaces; | 36 | using OpenSim.Region.Environment.Interfaces; |
37 | using OpenSim.Region.Environment.Scenes; | 37 | using OpenSim.Region.Environment.Scenes; |
38 | 38 | ||
39 | namespace OpenSim.Region.Environment.Modules | 39 | namespace OpenSim.Region.Environment.Modules.Avatar.Friends |
40 | { | 40 | { |
41 | public class FriendsModule : IRegionModule | 41 | public class FriendsModule : IRegionModule |
42 | { | 42 | { |
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
44 | 44 | ||
45 | private List<Scene> m_scene = new List<Scene>(); | 45 | private List<Scene> m_scene = new List<Scene>(); |
46 | 46 | ||
47 | Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>(); | 47 | Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>(); |
48 | 48 | ||
49 | Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>(); | 49 | Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>(); |
50 | 50 | ||
51 | Dictionary<LLUUID, List<FriendListItem>> FriendLists = new Dictionary<LLUUID, List<FriendListItem>>(); | 51 | Dictionary<LLUUID, List<FriendListItem>> FriendLists = new Dictionary<LLUUID, List<FriendListItem>>(); |
52 | 52 | ||
53 | public void Initialise(Scene scene, IConfigSource config) | 53 | public void Initialise(Scene scene, IConfigSource config) |
54 | { | 54 | { |
55 | lock (m_scene) | 55 | lock (m_scene) |
56 | { | 56 | { |
57 | if (m_scene.Count == 0) | 57 | if (m_scene.Count == 0) |
58 | { | 58 | { |
59 | scene.AddXmlRPCHandler("presence_update", processPresenceUpdate); | 59 | scene.AddXmlRPCHandler("presence_update", processPresenceUpdate); |
60 | } | 60 | } |
61 | 61 | ||
62 | if (!m_scene.Contains(scene)) | 62 | if (!m_scene.Contains(scene)) |
63 | m_scene.Add(scene); | 63 | m_scene.Add(scene); |
64 | } | 64 | } |
65 | scene.EventManager.OnNewClient += OnNewClient; | 65 | scene.EventManager.OnNewClient += OnNewClient; |
66 | scene.EventManager.OnGridInstantMessageToFriendsModule += OnGridInstantMessage; | 66 | scene.EventManager.OnGridInstantMessageToFriendsModule += OnGridInstantMessage; |
67 | scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; | 67 | scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; |
68 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; | 68 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; |
69 | scene.EventManager.OnClientClosed += ClientLoggedOut; | 69 | scene.EventManager.OnClientClosed += ClientLoggedOut; |
70 | } | 70 | } |
71 | public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req) | 71 | public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req) |
72 | { | 72 | { |
73 | m_log.Info("[FRIENDS]: Got Notification about a user! OMG"); | 73 | m_log.Info("[FRIENDS]: Got Notification about a user! OMG"); |
74 | return new XmlRpcResponse(); | 74 | return new XmlRpcResponse(); |
75 | } | 75 | } |
76 | private void OnNewClient(IClientAPI client) | 76 | private void OnNewClient(IClientAPI client) |
77 | { | 77 | { |
78 | // All friends establishment protocol goes over instant message | 78 | // All friends establishment protocol goes over instant message |
79 | // There's no way to send a message from the sim | 79 | // There's no way to send a message from the sim |
80 | // to a user to 'add a friend' without causing dialog box spam | 80 | // to a user to 'add a friend' without causing dialog box spam |
81 | // | 81 | // |
82 | // The base set of friends are added when the user signs on in their XMLRPC response | 82 | // The base set of friends are added when the user signs on in their XMLRPC response |
83 | // Generated by LoginService. The friends are retreived from the database by the UserManager | 83 | // Generated by LoginService. The friends are retreived from the database by the UserManager |
84 | 84 | ||
85 | // Subscribe to instant messages | 85 | // Subscribe to instant messages |
86 | 86 | ||
87 | client.OnInstantMessage += OnInstantMessage; | 87 | client.OnInstantMessage += OnInstantMessage; |
88 | client.OnApproveFriendRequest += OnApprovedFriendRequest; | 88 | client.OnApproveFriendRequest += OnApprovedFriendRequest; |
89 | client.OnDenyFriendRequest += OnDenyFriendRequest; | 89 | client.OnDenyFriendRequest += OnDenyFriendRequest; |
90 | client.OnTerminateFriendship += OnTerminateFriendship; | 90 | client.OnTerminateFriendship += OnTerminateFriendship; |
91 | 91 | ||
92 | List<FriendListItem> fl = new List<FriendListItem>(); | 92 | List<FriendListItem> fl = new List<FriendListItem>(); |
93 | 93 | ||
94 | //bool addFLback = false; | 94 | //bool addFLback = false; |
95 | 95 | ||
96 | lock (FriendLists) | 96 | lock (FriendLists) |
97 | { | 97 | { |
98 | if (FriendLists.ContainsKey(client.AgentId)) | 98 | if (FriendLists.ContainsKey(client.AgentId)) |
99 | { | 99 | { |
100 | fl = FriendLists[client.AgentId]; | 100 | fl = FriendLists[client.AgentId]; |
101 | } | 101 | } |
102 | else | 102 | else |
103 | { | 103 | { |
104 | fl = m_scene[0].GetFriendList(client.AgentId); | 104 | fl = m_scene[0].GetFriendList(client.AgentId); |
105 | 105 | ||
106 | //lock (FriendLists) | 106 | //lock (FriendLists) |
107 | //{ | 107 | //{ |
108 | if (!FriendLists.ContainsKey(client.AgentId)) | 108 | if (!FriendLists.ContainsKey(client.AgentId)) |
109 | FriendLists.Add(client.AgentId, fl); | 109 | FriendLists.Add(client.AgentId, fl); |
110 | //} | 110 | //} |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | List<LLUUID> UpdateUsers = new List<LLUUID>(); | 114 | List<LLUUID> UpdateUsers = new List<LLUUID>(); |
115 | 115 | ||
116 | foreach (FriendListItem f in fl) | 116 | foreach (FriendListItem f in fl) |
117 | { | 117 | { |
118 | if (m_rootAgents.ContainsKey(f.Friend)) | 118 | if (m_rootAgents.ContainsKey(f.Friend)) |
119 | { | 119 | { |
120 | if (f.onlinestatus == false) | 120 | if (f.onlinestatus == false) |
121 | { | 121 | { |
122 | UpdateUsers.Add(f.Friend); | 122 | UpdateUsers.Add(f.Friend); |
123 | f.onlinestatus = true; | 123 | f.onlinestatus = true; |
124 | } | 124 | } |
125 | } | 125 | } |
126 | } | 126 | } |
127 | foreach (LLUUID user in UpdateUsers) | 127 | foreach (LLUUID user in UpdateUsers) |
128 | { | 128 | { |
129 | ScenePresence av = GetPresenceFromAgentID(user); | 129 | ScenePresence av = GetPresenceFromAgentID(user); |
130 | if (av != null) | 130 | if (av != null) |
131 | { | 131 | { |
132 | List<FriendListItem> usrfl = new List<FriendListItem>(); | 132 | List<FriendListItem> usrfl = new List<FriendListItem>(); |
133 | 133 | ||
134 | lock (FriendLists) | 134 | lock (FriendLists) |
135 | { | 135 | { |
136 | usrfl = FriendLists[user]; | 136 | usrfl = FriendLists[user]; |
137 | } | 137 | } |
138 | 138 | ||
139 | lock (usrfl) | 139 | lock (usrfl) |
140 | { | 140 | { |
141 | foreach (FriendListItem fli in usrfl) | 141 | foreach (FriendListItem fli in usrfl) |
142 | { | 142 | { |
143 | if (fli.Friend == client.AgentId) | 143 | if (fli.Friend == client.AgentId) |
144 | { | 144 | { |
145 | fli.onlinestatus = true; | 145 | fli.onlinestatus = true; |
146 | OnlineNotificationPacket onp = new OnlineNotificationPacket(); | 146 | OnlineNotificationPacket onp = new OnlineNotificationPacket(); |
147 | OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[1]; | 147 | OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[1]; |
148 | OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock(); | 148 | OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock(); |
149 | onpbl.AgentID = client.AgentId; | 149 | onpbl.AgentID = client.AgentId; |
150 | onpb[0] = onpbl; | 150 | onpb[0] = onpbl; |
151 | onp.AgentBlock = onpb; | 151 | onp.AgentBlock = onpb; |
152 | av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task); | 152 | av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task); |
153 | } | 153 | } |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
159 | if (UpdateUsers.Count > 0) | 159 | if (UpdateUsers.Count > 0) |
160 | { | 160 | { |
161 | OnlineNotificationPacket onp = new OnlineNotificationPacket(); | 161 | OnlineNotificationPacket onp = new OnlineNotificationPacket(); |
162 | OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[UpdateUsers.Count]; | 162 | OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[UpdateUsers.Count]; |
163 | for (int i = 0; i < UpdateUsers.Count; i++) | 163 | for (int i = 0; i < UpdateUsers.Count; i++) |
164 | { | 164 | { |
165 | OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock(); | 165 | OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock(); |
166 | onpbl.AgentID = UpdateUsers[i]; | 166 | onpbl.AgentID = UpdateUsers[i]; |
167 | onpb[i] = onpbl; | 167 | onpb[i] = onpbl; |
168 | } | 168 | } |
169 | onp.AgentBlock = onpb; | 169 | onp.AgentBlock = onpb; |
170 | client.OutPacket(onp, ThrottleOutPacketType.Task); | 170 | client.OutPacket(onp, ThrottleOutPacketType.Task); |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | 174 | ||
175 | 175 | ||
176 | } | 176 | } |
177 | 177 | ||
178 | private void ClientLoggedOut(LLUUID AgentId) | 178 | private void ClientLoggedOut(LLUUID AgentId) |
179 | { | 179 | { |
180 | lock (m_rootAgents) | 180 | lock (m_rootAgents) |
181 | { | 181 | { |
182 | if (m_rootAgents.ContainsKey(AgentId)) | 182 | if (m_rootAgents.ContainsKey(AgentId)) |
183 | { | 183 | { |
184 | m_rootAgents.Remove(AgentId); | 184 | m_rootAgents.Remove(AgentId); |
185 | m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out."); | 185 | m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out."); |
186 | } | 186 | } |
187 | } | 187 | } |
188 | List<FriendListItem> lfli = new List<FriendListItem>(); | 188 | List<FriendListItem> lfli = new List<FriendListItem>(); |
189 | lock (FriendLists) | 189 | lock (FriendLists) |
190 | { | 190 | { |
191 | if (FriendLists.ContainsKey(AgentId)) | 191 | if (FriendLists.ContainsKey(AgentId)) |
192 | { | 192 | { |
193 | lfli = FriendLists[AgentId]; | 193 | lfli = FriendLists[AgentId]; |
194 | } | 194 | } |
195 | } | 195 | } |
196 | List<LLUUID> updateUsers = new List<LLUUID>(); | 196 | List<LLUUID> updateUsers = new List<LLUUID>(); |
197 | foreach (FriendListItem fli in lfli) | 197 | foreach (FriendListItem fli in lfli) |
198 | { | 198 | { |
199 | if (fli.onlinestatus == true) | 199 | if (fli.onlinestatus == true) |
200 | { | 200 | { |
201 | updateUsers.Add(fli.Friend); | 201 | updateUsers.Add(fli.Friend); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | lock (updateUsers) | 204 | lock (updateUsers) |
205 | { | 205 | { |
206 | for (int i = 0; i < updateUsers.Count; i++) | 206 | for (int i = 0; i < updateUsers.Count; i++) |
207 | { | 207 | { |
208 | List<FriendListItem> flfli = new List<FriendListItem>(); | 208 | List<FriendListItem> flfli = new List<FriendListItem>(); |
209 | try | 209 | try |
210 | { | 210 | { |
211 | 211 | ||
212 | lock (FriendLists) | 212 | lock (FriendLists) |
213 | { | 213 | { |
214 | if (FriendLists.ContainsKey(updateUsers[i])) | 214 | if (FriendLists.ContainsKey(updateUsers[i])) |
215 | flfli = FriendLists[updateUsers[i]]; | 215 | flfli = FriendLists[updateUsers[i]]; |
216 | } | 216 | } |
217 | } | 217 | } |
218 | catch (IndexOutOfRangeException) | 218 | catch (IndexOutOfRangeException) |
219 | { | 219 | { |
220 | // Ignore the index out of range exception. | 220 | // Ignore the index out of range exception. |
221 | // This causes friend lists to get out of sync slightly.. however | 221 | // This causes friend lists to get out of sync slightly.. however |
222 | // prevents a sim crash. | 222 | // prevents a sim crash. |
223 | m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off"); | 223 | m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off"); |
224 | } | 224 | } |
225 | 225 | ||
226 | for (int j = 0; j < flfli.Count; j++) | 226 | for (int j = 0; j < flfli.Count; j++) |
227 | { | 227 | { |
228 | try | 228 | try |
229 | { | 229 | { |
230 | if (flfli[i].Friend == AgentId) | 230 | if (flfli[i].Friend == AgentId) |
231 | { | 231 | { |
232 | flfli[i].onlinestatus = false; | 232 | flfli[i].onlinestatus = false; |
233 | } | 233 | } |
234 | 234 | ||
235 | } | 235 | } |
236 | 236 | ||
237 | catch (IndexOutOfRangeException) | 237 | catch (IndexOutOfRangeException) |
238 | { | 238 | { |
239 | // Ignore the index out of range exception. | 239 | // Ignore the index out of range exception. |
240 | // This causes friend lists to get out of sync slightly.. however | 240 | // This causes friend lists to get out of sync slightly.. however |
241 | // prevents a sim crash. | 241 | // prevents a sim crash. |
242 | m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off"); | 242 | m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off"); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | } | 246 | } |
247 | 247 | ||
248 | for (int i = 0; i < updateUsers.Count; i++) | 248 | for (int i = 0; i < updateUsers.Count; i++) |
249 | { | 249 | { |
250 | ScenePresence av = GetPresenceFromAgentID(updateUsers[i]); | 250 | ScenePresence av = GetPresenceFromAgentID(updateUsers[i]); |
251 | if (av != null) | 251 | if (av != null) |
252 | { | 252 | { |
253 | 253 | ||
254 | OfflineNotificationPacket onp = new OfflineNotificationPacket(); | 254 | OfflineNotificationPacket onp = new OfflineNotificationPacket(); |
255 | OfflineNotificationPacket.AgentBlockBlock[] onpb = new OfflineNotificationPacket.AgentBlockBlock[1]; | 255 | OfflineNotificationPacket.AgentBlockBlock[] onpb = new OfflineNotificationPacket.AgentBlockBlock[1]; |
256 | OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock(); | 256 | OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock(); |
257 | onpbl.AgentID = AgentId; | 257 | onpbl.AgentID = AgentId; |
258 | onpb[0] = onpbl; | 258 | onpb[0] = onpbl; |
259 | onp.AgentBlock = onpb; | 259 | onp.AgentBlock = onpb; |
260 | av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task); | 260 | av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task); |
261 | } | 261 | } |
262 | } | 262 | } |
263 | } | 263 | } |
264 | lock (FriendLists) | 264 | lock (FriendLists) |
265 | { | 265 | { |
266 | FriendLists.Remove(AgentId); | 266 | FriendLists.Remove(AgentId); |
267 | } | 267 | } |
268 | 268 | ||
269 | } | 269 | } |
270 | 270 | ||
271 | private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) | 271 | private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) |
272 | { | 272 | { |
273 | lock (m_rootAgents) | 273 | lock (m_rootAgents) |
274 | { | 274 | { |
275 | if (m_rootAgents.ContainsKey(avatar.UUID)) | 275 | if (m_rootAgents.ContainsKey(avatar.UUID)) |
276 | { | 276 | { |
277 | if (avatar.RegionHandle != m_rootAgents[avatar.UUID]) | 277 | if (avatar.RegionHandle != m_rootAgents[avatar.UUID]) |
278 | { | 278 | { |
279 | m_rootAgents[avatar.UUID] = avatar.RegionHandle; | 279 | m_rootAgents[avatar.UUID] = avatar.RegionHandle; |
280 | m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); | 280 | m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); |
281 | if (avatar.JID.Length > 0) | 281 | if (avatar.JID.Length > 0) |
282 | { | 282 | { |
283 | JId avatarID = new JId(avatar.JID); | 283 | JId avatarID = new JId(avatar.JID); |
284 | // REST Post XMPP Stanzas! | 284 | // REST Post XMPP Stanzas! |
285 | 285 | ||
286 | } | 286 | } |
287 | // Claim User! my user! Mine mine mine! | 287 | // Claim User! my user! Mine mine mine! |
288 | } | 288 | } |
289 | } | 289 | } |
290 | else | 290 | else |
291 | { | 291 | { |
292 | m_rootAgents.Add(avatar.UUID, avatar.RegionHandle); | 292 | m_rootAgents.Add(avatar.UUID, avatar.RegionHandle); |
293 | m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); | 293 | m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); |
294 | } | 294 | } |
295 | } | 295 | } |
296 | //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); | 296 | //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); |
297 | } | 297 | } |
298 | private void MakeChildAgent(ScenePresence avatar) | 298 | private void MakeChildAgent(ScenePresence avatar) |
299 | { | 299 | { |
300 | 300 | ||
301 | lock (m_rootAgents) | 301 | lock (m_rootAgents) |
302 | { | 302 | { |
303 | if (m_rootAgents.ContainsKey(avatar.UUID)) | 303 | if (m_rootAgents.ContainsKey(avatar.UUID)) |
304 | { | 304 | { |
305 | if (m_rootAgents[avatar.UUID] == avatar.RegionHandle) | 305 | if (m_rootAgents[avatar.UUID] == avatar.RegionHandle) |
306 | { | 306 | { |
307 | m_rootAgents.Remove(avatar.UUID); | 307 | m_rootAgents.Remove(avatar.UUID); |
308 | m_log.Info("[FRIEND]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent"); | 308 | m_log.Info("[FRIEND]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent"); |
309 | } | 309 | } |
310 | 310 | ||
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | } | 314 | } |
315 | #region FriendRequestHandling | 315 | #region FriendRequestHandling |
316 | private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID, | 316 | private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID, |
317 | LLUUID fromAgentSession, LLUUID toAgentID, | 317 | LLUUID fromAgentSession, LLUUID toAgentID, |
318 | LLUUID imSessionID, uint timestamp, string fromAgentName, | 318 | LLUUID imSessionID, uint timestamp, string fromAgentName, |
319 | string message, byte dialog, bool fromGroup, byte offline, | 319 | string message, byte dialog, bool fromGroup, byte offline, |
320 | uint ParentEstateID, LLVector3 Position, LLUUID RegionID, | 320 | uint ParentEstateID, LLVector3 Position, LLUUID RegionID, |
321 | byte[] binaryBucket) | 321 | byte[] binaryBucket) |
322 | { | 322 | { |
323 | // Friend Requests go by Instant Message.. using the dialog param | 323 | // Friend Requests go by Instant Message.. using the dialog param |
324 | // https://wiki.secondlife.com/wiki/ImprovedInstantMessage | 324 | // https://wiki.secondlife.com/wiki/ImprovedInstantMessage |
325 | 325 | ||
326 | // 38 == Offer friendship | 326 | // 38 == Offer friendship |
327 | if (dialog == (byte)38) | 327 | if (dialog == (byte)38) |
328 | { | 328 | { |
329 | LLUUID friendTransactionID = LLUUID.Random(); | 329 | LLUUID friendTransactionID = LLUUID.Random(); |
330 | 330 | ||
331 | m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); | 331 | m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); |
332 | 332 | ||
333 | m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); | 333 | m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); |
334 | GridInstantMessage msg = new GridInstantMessage(); | 334 | GridInstantMessage msg = new GridInstantMessage(); |
335 | msg.fromAgentID = fromAgentID.UUID; | 335 | msg.fromAgentID = fromAgentID.UUID; |
336 | msg.fromAgentSession = fromAgentSession.UUID; | 336 | msg.fromAgentSession = fromAgentSession.UUID; |
337 | msg.toAgentID = toAgentID.UUID; | 337 | msg.toAgentID = toAgentID.UUID; |
338 | msg.imSessionID = friendTransactionID.UUID; // This is the item we're mucking with here | 338 | msg.imSessionID = friendTransactionID.UUID; // This is the item we're mucking with here |
339 | m_log.Info("[FRIEND]: Filling Session: " + msg.imSessionID.ToString()); | 339 | m_log.Info("[FRIEND]: Filling Session: " + msg.imSessionID.ToString()); |
340 | msg.timestamp = timestamp; | 340 | msg.timestamp = timestamp; |
341 | if (client != null) | 341 | if (client != null) |
342 | { | 342 | { |
343 | msg.fromAgentName = client.FirstName + " " + client.LastName;// fromAgentName; | 343 | msg.fromAgentName = client.FirstName + " " + client.LastName;// fromAgentName; |
344 | } | 344 | } |
345 | else | 345 | else |
346 | { | 346 | { |
347 | msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it | 347 | msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it |
348 | } | 348 | } |
349 | msg.message = message; | 349 | msg.message = message; |
350 | msg.dialog = dialog; | 350 | msg.dialog = dialog; |
351 | msg.fromGroup = fromGroup; | 351 | msg.fromGroup = fromGroup; |
352 | msg.offline = offline; | 352 | msg.offline = offline; |
353 | msg.ParentEstateID = ParentEstateID; | 353 | msg.ParentEstateID = ParentEstateID; |
354 | msg.Position = new sLLVector3(Position); | 354 | msg.Position = new sLLVector3(Position); |
355 | msg.RegionID = RegionID.UUID; | 355 | msg.RegionID = RegionID.UUID; |
356 | msg.binaryBucket = binaryBucket; | 356 | msg.binaryBucket = binaryBucket; |
357 | // We don't really care which scene we pipe it through. | 357 | // We don't really care which scene we pipe it through. |
358 | m_scene[0].TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); | 358 | m_scene[0].TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); |
359 | } | 359 | } |
360 | 360 | ||
361 | // 39 == Accept Friendship | 361 | // 39 == Accept Friendship |
362 | if (dialog == (byte)39) | 362 | if (dialog == (byte)39) |
363 | { | 363 | { |
364 | m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); | 364 | m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); |
365 | } | 365 | } |
366 | 366 | ||
367 | // 40 == Decline Friendship | 367 | // 40 == Decline Friendship |
368 | if (dialog == (byte)40) | 368 | if (dialog == (byte)40) |
369 | { | 369 | { |
370 | m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); | 370 | m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); |
371 | } | 371 | } |
372 | } | 372 | } |
373 | 373 | ||
374 | private void OnApprovedFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders) | 374 | private void OnApprovedFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders) |
375 | { | 375 | { |
376 | if (m_pendingFriendRequests.ContainsKey(transactionID)) | 376 | if (m_pendingFriendRequests.ContainsKey(transactionID)) |
377 | { | 377 | { |
378 | // Found Pending Friend Request with that Transaction.. | 378 | // Found Pending Friend Request with that Transaction.. |
379 | Scene SceneAgentIn = m_scene[0]; | 379 | Scene SceneAgentIn = m_scene[0]; |
380 | 380 | ||
381 | // Found Pending Friend Request with that Transaction.. | 381 | // Found Pending Friend Request with that Transaction.. |
382 | ScenePresence agentpresence = GetPresenceFromAgentID(agentID); | 382 | ScenePresence agentpresence = GetPresenceFromAgentID(agentID); |
383 | if (agentpresence != null) | 383 | if (agentpresence != null) |
384 | { | 384 | { |
385 | SceneAgentIn = agentpresence.Scene; | 385 | SceneAgentIn = agentpresence.Scene; |
386 | } | 386 | } |
387 | 387 | ||
388 | // Compose response to other agent. | 388 | // Compose response to other agent. |
389 | GridInstantMessage msg = new GridInstantMessage(); | 389 | GridInstantMessage msg = new GridInstantMessage(); |
390 | msg.toAgentID = m_pendingFriendRequests[transactionID].UUID; | 390 | msg.toAgentID = m_pendingFriendRequests[transactionID].UUID; |
391 | msg.fromAgentID = agentID.UUID; | 391 | msg.fromAgentID = agentID.UUID; |
392 | msg.fromAgentName = client.FirstName + " " + client.LastName; | 392 | msg.fromAgentName = client.FirstName + " " + client.LastName; |
393 | msg.fromAgentSession = client.SessionId.UUID; | 393 | msg.fromAgentSession = client.SessionId.UUID; |
394 | msg.fromGroup = false; | 394 | msg.fromGroup = false; |
395 | msg.imSessionID = transactionID.UUID; | 395 | msg.imSessionID = transactionID.UUID; |
396 | msg.message = agentID.UUID.ToString(); | 396 | msg.message = agentID.UUID.ToString(); |
397 | msg.ParentEstateID = 0; | 397 | msg.ParentEstateID = 0; |
398 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); | 398 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); |
399 | msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; | 399 | msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; |
400 | msg.dialog = (byte)39;// Approved friend request | 400 | msg.dialog = (byte)39;// Approved friend request |
401 | msg.Position = new sLLVector3(); | 401 | msg.Position = new sLLVector3(); |
402 | msg.offline = (byte)0; | 402 | msg.offline = (byte)0; |
403 | msg.binaryBucket = new byte[0]; | 403 | msg.binaryBucket = new byte[0]; |
404 | // We don't really care which scene we pipe it through, it goes to the shared IM Module and/or the database | 404 | // We don't really care which scene we pipe it through, it goes to the shared IM Module and/or the database |
405 | 405 | ||
406 | SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); | 406 | SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); |
407 | SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1); | 407 | SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1); |
408 | m_pendingFriendRequests.Remove(transactionID); | 408 | m_pendingFriendRequests.Remove(transactionID); |
409 | 409 | ||
410 | // TODO: Inform agent that the friend is online | 410 | // TODO: Inform agent that the friend is online |
411 | } | 411 | } |
412 | } | 412 | } |
413 | 413 | ||
414 | private void OnDenyFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders) | 414 | private void OnDenyFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders) |
415 | { | 415 | { |
416 | if (m_pendingFriendRequests.ContainsKey(transactionID)) | 416 | if (m_pendingFriendRequests.ContainsKey(transactionID)) |
417 | { | 417 | { |
418 | Scene SceneAgentIn = m_scene[0]; | 418 | Scene SceneAgentIn = m_scene[0]; |
419 | 419 | ||
420 | // Found Pending Friend Request with that Transaction.. | 420 | // Found Pending Friend Request with that Transaction.. |
421 | ScenePresence agentpresence = GetPresenceFromAgentID(agentID); | 421 | ScenePresence agentpresence = GetPresenceFromAgentID(agentID); |
422 | if (agentpresence != null) | 422 | if (agentpresence != null) |
423 | { | 423 | { |
424 | SceneAgentIn = agentpresence.Scene; | 424 | SceneAgentIn = agentpresence.Scene; |
425 | } | 425 | } |
426 | // Compose response to other agent. | 426 | // Compose response to other agent. |
427 | GridInstantMessage msg = new GridInstantMessage(); | 427 | GridInstantMessage msg = new GridInstantMessage(); |
428 | msg.toAgentID = m_pendingFriendRequests[transactionID].UUID; | 428 | msg.toAgentID = m_pendingFriendRequests[transactionID].UUID; |
429 | msg.fromAgentID = agentID.UUID; | 429 | msg.fromAgentID = agentID.UUID; |
430 | msg.fromAgentName = client.FirstName + " " + client.LastName; | 430 | msg.fromAgentName = client.FirstName + " " + client.LastName; |
431 | msg.fromAgentSession = client.SessionId.UUID; | 431 | msg.fromAgentSession = client.SessionId.UUID; |
432 | msg.fromGroup = false; | 432 | msg.fromGroup = false; |
433 | msg.imSessionID = transactionID.UUID; | 433 | msg.imSessionID = transactionID.UUID; |
434 | msg.message = agentID.UUID.ToString(); | 434 | msg.message = agentID.UUID.ToString(); |
435 | msg.ParentEstateID = 0; | 435 | msg.ParentEstateID = 0; |
436 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); | 436 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); |
437 | msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; | 437 | msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; |
438 | msg.dialog = (byte)40;// Deny friend request | 438 | msg.dialog = (byte)40;// Deny friend request |
439 | msg.Position = new sLLVector3(); | 439 | msg.Position = new sLLVector3(); |
440 | msg.offline = (byte)0; | 440 | msg.offline = (byte)0; |
441 | msg.binaryBucket = new byte[0]; | 441 | msg.binaryBucket = new byte[0]; |
442 | SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); | 442 | SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); |
443 | m_pendingFriendRequests.Remove(transactionID); | 443 | m_pendingFriendRequests.Remove(transactionID); |
444 | } | 444 | } |
445 | } | 445 | } |
446 | 446 | ||
447 | private void OnTerminateFriendship(IClientAPI client, LLUUID agent, LLUUID exfriendID) | 447 | private void OnTerminateFriendship(IClientAPI client, LLUUID agent, LLUUID exfriendID) |
448 | { | 448 | { |
449 | m_scene[0].StoreRemoveFriendship(agent, exfriendID); | 449 | m_scene[0].StoreRemoveFriendship(agent, exfriendID); |
450 | // TODO: Inform the client that the ExFriend is offline | 450 | // TODO: Inform the client that the ExFriend is offline |
451 | } | 451 | } |
452 | 452 | ||
453 | private void OnGridInstantMessage(GridInstantMessage msg) | 453 | private void OnGridInstantMessage(GridInstantMessage msg) |
454 | { | 454 | { |
455 | // Trigger the above event handler | 455 | // Trigger the above event handler |
456 | OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), | 456 | OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), |
457 | new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, | 457 | new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, |
458 | msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, | 458 | msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, |
459 | new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID), | 459 | new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID), |
460 | msg.binaryBucket); | 460 | msg.binaryBucket); |
461 | } | 461 | } |
462 | #endregion | 462 | #endregion |
463 | private ScenePresence GetPresenceFromAgentID(LLUUID AgentID) | 463 | private ScenePresence GetPresenceFromAgentID(LLUUID AgentID) |
464 | { | 464 | { |
465 | ScenePresence returnAgent = null; | 465 | ScenePresence returnAgent = null; |
466 | lock (m_scene) | 466 | lock (m_scene) |
467 | { | 467 | { |
468 | ScenePresence queryagent = null; | 468 | ScenePresence queryagent = null; |
469 | for (int i = 0; i < m_scene.Count; i++) | 469 | for (int i = 0; i < m_scene.Count; i++) |
470 | { | 470 | { |
471 | queryagent = m_scene[i].GetScenePresence(AgentID); | 471 | queryagent = m_scene[i].GetScenePresence(AgentID); |
472 | if (queryagent != null) | 472 | if (queryagent != null) |
473 | { | 473 | { |
474 | if (!queryagent.IsChildAgent) | 474 | if (!queryagent.IsChildAgent) |
475 | { | 475 | { |
476 | returnAgent = queryagent; | 476 | returnAgent = queryagent; |
477 | break; | 477 | break; |
478 | } | 478 | } |
479 | } | 479 | } |
480 | } | 480 | } |
481 | } | 481 | } |
482 | return returnAgent; | 482 | return returnAgent; |
483 | 483 | ||
484 | } | 484 | } |
485 | 485 | ||
486 | public void PostInitialise() | 486 | public void PostInitialise() |
487 | { | 487 | { |
488 | } | 488 | } |
489 | 489 | ||
490 | public void Close() | 490 | public void Close() |
491 | { | 491 | { |
492 | } | 492 | } |
493 | 493 | ||
494 | public string Name | 494 | public string Name |
495 | { | 495 | { |
496 | get { return "FriendsModule"; } | 496 | get { return "FriendsModule"; } |
497 | } | 497 | } |
498 | 498 | ||
499 | public bool IsSharedModule | 499 | public bool IsSharedModule |
500 | { | 500 | { |
501 | get { return true; } | 501 | get { return true; } |
502 | } | 502 | } |
503 | } | 503 | } |
504 | } | 504 | } \ No newline at end of file |