diff options
First step in separating out the Userserver console command handling to a "module".
Added OpenSim.Grid.UserServer.Modules project/dll which now contains the components of the userserver. With the OpenSim.Grid.UserServer being the setup and initiate exe.
Diffstat (limited to 'OpenSim/Grid/UserServer')
-rw-r--r-- | OpenSim/Grid/UserServer/IUGAIMCore.cs | 43 | ||||
-rw-r--r-- | OpenSim/Grid/UserServer/Main.cs | 276 | ||||
-rw-r--r-- | OpenSim/Grid/UserServer/MessageServersConnector.cs | 509 | ||||
-rw-r--r-- | OpenSim/Grid/UserServer/OpenIdService.cs | 337 | ||||
-rw-r--r-- | OpenSim/Grid/UserServer/UserDataBaseService.cs | 68 | ||||
-rw-r--r-- | OpenSim/Grid/UserServer/UserLoginService.cs | 600 | ||||
-rw-r--r-- | OpenSim/Grid/UserServer/UserManager.cs | 686 | ||||
-rw-r--r-- | OpenSim/Grid/UserServer/UserServerAvatarAppearanceModule.cs | 124 | ||||
-rw-r--r-- | OpenSim/Grid/UserServer/UserServerCommandModule.cs | 349 | ||||
-rw-r--r-- | OpenSim/Grid/UserServer/UserServerFriendsModule.cs | 173 |
10 files changed, 360 insertions, 2805 deletions
diff --git a/OpenSim/Grid/UserServer/IUGAIMCore.cs b/OpenSim/Grid/UserServer/IUGAIMCore.cs deleted file mode 100644 index 0783fe5..0000000 --- a/OpenSim/Grid/UserServer/IUGAIMCore.cs +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.Framework.Servers; | ||
32 | |||
33 | namespace OpenSim.Grid.UserServer | ||
34 | { | ||
35 | public interface IUGAIMCore | ||
36 | { | ||
37 | T Get<T>(); | ||
38 | void RegisterInterface<T>(T iface); | ||
39 | bool TryGet<T>(out T iface); | ||
40 | BaseHttpServer GetHttpServer(); | ||
41 | |||
42 | } | ||
43 | } | ||
diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index efa090e..61f9800 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs | |||
@@ -40,6 +40,8 @@ using OpenSim.Framework.Console; | |||
40 | using OpenSim.Framework.Servers; | 40 | using OpenSim.Framework.Servers; |
41 | using OpenSim.Framework.Statistics; | 41 | using OpenSim.Framework.Statistics; |
42 | using OpenSim.Grid.Communications.OGS1; | 42 | using OpenSim.Grid.Communications.OGS1; |
43 | using OpenSim.Grid.Framework; | ||
44 | using OpenSim.Grid.UserServer.Modules; | ||
43 | 45 | ||
44 | namespace OpenSim.Grid.UserServer | 46 | namespace OpenSim.Grid.UserServer |
45 | { | 47 | { |
@@ -63,6 +65,8 @@ namespace OpenSim.Grid.UserServer | |||
63 | public GridInfoService m_gridInfoService; | 65 | public GridInfoService m_gridInfoService; |
64 | public MessageServersConnector m_messagesService; | 66 | public MessageServersConnector m_messagesService; |
65 | 67 | ||
68 | protected UserServerCommandModule m_consoleCommandModule; | ||
69 | |||
66 | private UUID m_lastCreatedUser = UUID.Random(); | 70 | private UUID m_lastCreatedUser = UUID.Random(); |
67 | 71 | ||
68 | public static void Main(string[] args) | 72 | public static void Main(string[] args) |
@@ -123,6 +127,8 @@ namespace OpenSim.Grid.UserServer | |||
123 | 127 | ||
124 | m_messagesService = new MessageServersConnector(); | 128 | m_messagesService = new MessageServersConnector(); |
125 | 129 | ||
130 | m_consoleCommandModule = new UserServerCommandModule(m_console, Cfg, m_userDataBaseService, m_loginService); | ||
131 | |||
126 | //register event handlers | 132 | //register event handlers |
127 | RegisterEventHandlers(); | 133 | RegisterEventHandlers(); |
128 | 134 | ||
@@ -172,34 +178,7 @@ namespace OpenSim.Grid.UserServer | |||
172 | 178 | ||
173 | protected virtual void RegisterConsoleCommands() | 179 | protected virtual void RegisterConsoleCommands() |
174 | { | 180 | { |
175 | m_console.Commands.AddCommand("userserver", false, "create user", | 181 | m_consoleCommandModule.RegisterConsoleCommands(); |
176 | "create user [<first> [<last> [<x> <y> [email]]]]", | ||
177 | "Create a new user account", RunCommand); | ||
178 | |||
179 | m_console.Commands.AddCommand("userserver", false, "reset user password", | ||
180 | "reset user password [<first> [<last> [<new password>]]]", | ||
181 | "Reset a user's password", RunCommand); | ||
182 | |||
183 | m_console.Commands.AddCommand("userserver", false, "login level", | ||
184 | "login level <level>", | ||
185 | "Set the minimum user level to log in", HandleLoginCommand); | ||
186 | |||
187 | m_console.Commands.AddCommand("userserver", false, "login reset", | ||
188 | "login reset", | ||
189 | "Reset the login level to allow all users", | ||
190 | HandleLoginCommand); | ||
191 | |||
192 | m_console.Commands.AddCommand("userserver", false, "login text", | ||
193 | "login text <text>", | ||
194 | "Set the text users will see on login", HandleLoginCommand); | ||
195 | |||
196 | m_console.Commands.AddCommand("userserver", false, "test-inventory", | ||
197 | "test-inventory", | ||
198 | "Perform a test inventory transaction", RunCommand); | ||
199 | |||
200 | m_console.Commands.AddCommand("userserver", false, "logoff-user", | ||
201 | "logoff-user <first> <last> <message>", | ||
202 | "Log off a named user", RunCommand); | ||
203 | } | 182 | } |
204 | 183 | ||
205 | protected virtual void RegisterHttpHandlers() | 184 | protected virtual void RegisterHttpHandlers() |
@@ -261,247 +240,14 @@ namespace OpenSim.Grid.UserServer | |||
261 | return m_httpServer; | 240 | return m_httpServer; |
262 | } | 241 | } |
263 | #endregion | 242 | #endregion |
264 | |||
265 | #region Console Command Handlers | ||
266 | public void do_create(string[] args) | ||
267 | { | ||
268 | switch (args[0]) | ||
269 | { | ||
270 | case "user": | ||
271 | CreateUser(args); | ||
272 | break; | ||
273 | } | ||
274 | } | ||
275 | |||
276 | /// <summary> | ||
277 | /// Execute switch for some of the reset commands | ||
278 | /// </summary> | ||
279 | /// <param name="args"></param> | ||
280 | protected void Reset(string[] args) | ||
281 | { | ||
282 | if (args.Length == 0) | ||
283 | return; | ||
284 | |||
285 | switch (args[0]) | ||
286 | { | ||
287 | case "user": | ||
288 | |||
289 | switch (args[1]) | ||
290 | { | ||
291 | case "password": | ||
292 | ResetUserPassword(args); | ||
293 | break; | ||
294 | } | ||
295 | |||
296 | break; | ||
297 | } | ||
298 | } | ||
299 | |||
300 | /// <summary> | ||
301 | /// Create a new user | ||
302 | /// </summary> | ||
303 | /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param> | ||
304 | protected void CreateUser(string[] cmdparams) | ||
305 | { | ||
306 | string firstName; | ||
307 | string lastName; | ||
308 | string password; | ||
309 | string email; | ||
310 | uint regX = 1000; | ||
311 | uint regY = 1000; | ||
312 | |||
313 | if (cmdparams.Length < 2) | ||
314 | firstName = MainConsole.Instance.CmdPrompt("First name", "Default"); | ||
315 | else firstName = cmdparams[1]; | ||
316 | |||
317 | if (cmdparams.Length < 3) | ||
318 | lastName = MainConsole.Instance.CmdPrompt("Last name", "User"); | ||
319 | else lastName = cmdparams[2]; | ||
320 | |||
321 | if (cmdparams.Length < 4) | ||
322 | password = MainConsole.Instance.PasswdPrompt("Password"); | ||
323 | else password = cmdparams[3]; | ||
324 | |||
325 | if (cmdparams.Length < 5) | ||
326 | regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString())); | ||
327 | else regX = Convert.ToUInt32(cmdparams[4]); | ||
328 | |||
329 | if (cmdparams.Length < 6) | ||
330 | regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString())); | ||
331 | else regY = Convert.ToUInt32(cmdparams[5]); | ||
332 | |||
333 | if (cmdparams.Length < 7) | ||
334 | email = MainConsole.Instance.CmdPrompt("Email", ""); | ||
335 | else email = cmdparams[6]; | ||
336 | |||
337 | if (null == m_userDataBaseService.GetUserProfile(firstName, lastName)) | ||
338 | { | ||
339 | m_lastCreatedUser = m_userDataBaseService.AddUser(firstName, lastName, password, email, regX, regY); | ||
340 | } | ||
341 | else | ||
342 | { | ||
343 | m_log.ErrorFormat("[USERS]: A user with the name {0} {1} already exists!", firstName, lastName); | ||
344 | } | ||
345 | } | ||
346 | |||
347 | /// <summary> | ||
348 | /// Reset a user password. | ||
349 | /// </summary> | ||
350 | /// <param name="cmdparams"></param> | ||
351 | private void ResetUserPassword(string[] cmdparams) | ||
352 | { | ||
353 | string firstName; | ||
354 | string lastName; | ||
355 | string newPassword; | ||
356 | |||
357 | if (cmdparams.Length < 3) | ||
358 | firstName = MainConsole.Instance.CmdPrompt("First name"); | ||
359 | else firstName = cmdparams[2]; | ||
360 | |||
361 | if ( cmdparams.Length < 4 ) | ||
362 | lastName = MainConsole.Instance.CmdPrompt("Last name"); | ||
363 | else lastName = cmdparams[3]; | ||
364 | |||
365 | if ( cmdparams.Length < 5 ) | ||
366 | newPassword = MainConsole.Instance.PasswdPrompt("New password"); | ||
367 | else newPassword = cmdparams[4]; | ||
368 | |||
369 | m_userDataBaseService.ResetUserPassword(firstName, lastName, newPassword); | ||
370 | } | ||
371 | |||
372 | private void HandleLoginCommand(string module, string[] cmd) | ||
373 | { | ||
374 | string subcommand = cmd[1]; | ||
375 | |||
376 | switch (subcommand) | ||
377 | { | ||
378 | case "level": | ||
379 | // Set the minimal level to allow login | ||
380 | // Useful to allow grid update without worrying about users. | ||
381 | // or fixing critical issues | ||
382 | // | ||
383 | if (cmd.Length > 2) | ||
384 | { | ||
385 | int level = Convert.ToInt32(cmd[2]); | ||
386 | m_loginService.setloginlevel(level); | ||
387 | } | ||
388 | break; | ||
389 | case "reset": | ||
390 | m_loginService.setloginlevel(0); | ||
391 | break; | ||
392 | case "text": | ||
393 | if (cmd.Length > 2) | ||
394 | { | ||
395 | m_loginService.setwelcometext(cmd[2]); | ||
396 | } | ||
397 | break; | ||
398 | } | ||
399 | } | ||
400 | |||
401 | public void RunCommand(string module, string[] cmd) | ||
402 | { | ||
403 | List<string> args = new List<string>(cmd); | ||
404 | string command = cmd[0]; | ||
405 | |||
406 | args.RemoveAt(0); | ||
407 | |||
408 | string[] cmdparams = args.ToArray(); | ||
409 | |||
410 | switch (command) | ||
411 | { | ||
412 | case "create": | ||
413 | do_create(cmdparams); | ||
414 | break; | ||
415 | |||
416 | case "reset": | ||
417 | Reset(cmdparams); | ||
418 | break; | ||
419 | |||
420 | |||
421 | case "test-inventory": | ||
422 | // RestObjectPosterResponse<List<InventoryFolderBase>> requester = new RestObjectPosterResponse<List<InventoryFolderBase>>(); | ||
423 | // requester.ReturnResponseVal = TestResponse; | ||
424 | // requester.BeginPostObject<UUID>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser); | ||
425 | SynchronousRestObjectPoster.BeginPostObject<UUID, List<InventoryFolderBase>>( | ||
426 | "POST", Cfg.InventoryUrl + "RootFolders/", m_lastCreatedUser); | ||
427 | break; | ||
428 | |||
429 | case "logoff-user": | ||
430 | if (cmdparams.Length >= 3) | ||
431 | { | ||
432 | string firstname = cmdparams[0]; | ||
433 | string lastname = cmdparams[1]; | ||
434 | string message = ""; | ||
435 | |||
436 | for (int i = 2; i < cmdparams.Length; i++) | ||
437 | message += " " + cmdparams[i]; | ||
438 | |||
439 | UserProfileData theUser = null; | ||
440 | try | ||
441 | { | ||
442 | theUser = m_loginService.GetTheUser(firstname, lastname); | ||
443 | } | ||
444 | catch (Exception) | ||
445 | { | ||
446 | m_log.Error("[LOGOFF]: Error getting user data from the database."); | ||
447 | } | ||
448 | |||
449 | if (theUser != null) | ||
450 | { | ||
451 | if (theUser.CurrentAgent != null) | ||
452 | { | ||
453 | if (theUser.CurrentAgent.AgentOnline) | ||
454 | { | ||
455 | m_log.Info("[LOGOFF]: Logging off requested user!"); | ||
456 | m_loginService.LogOffUser(theUser, message); | ||
457 | |||
458 | theUser.CurrentAgent.AgentOnline = false; | ||
459 | |||
460 | m_loginService.CommitAgent(ref theUser); | ||
461 | } | ||
462 | else | ||
463 | { | ||
464 | m_log.Info( | ||
465 | "[LOGOFF]: User Doesn't appear to be online, sending the logoff message anyway."); | ||
466 | m_loginService.LogOffUser(theUser, message); | ||
467 | |||
468 | theUser.CurrentAgent.AgentOnline = false; | ||
469 | |||
470 | m_loginService.CommitAgent(ref theUser); | ||
471 | } | ||
472 | } | ||
473 | else | ||
474 | { | ||
475 | m_log.Error( | ||
476 | "[LOGOFF]: Unable to logoff-user. User doesn't have an agent record so I can't find the simulator to notify"); | ||
477 | } | ||
478 | } | ||
479 | else | ||
480 | { | ||
481 | m_log.Info("[LOGOFF]: User doesn't exist in the database"); | ||
482 | } | ||
483 | } | ||
484 | else | ||
485 | { | ||
486 | m_log.Error( | ||
487 | "[LOGOFF]: Invalid amount of parameters. logoff-user takes at least three. Firstname, Lastname, and message"); | ||
488 | } | ||
489 | |||
490 | break; | ||
491 | } | ||
492 | } | ||
493 | 243 | ||
244 | #region Console Command Handlers | ||
245 | |||
494 | protected override void ShowHelp(string[] helpArgs) | 246 | protected override void ShowHelp(string[] helpArgs) |
495 | { | 247 | { |
496 | base.ShowHelp(helpArgs); | 248 | base.ShowHelp(helpArgs); |
497 | |||
498 | m_console.Notice("create user - create a new user"); | ||
499 | m_console.Notice("logoff-user <firstname> <lastname> <message> - logs off the specified user from the grid"); | ||
500 | m_console.Notice("reset user password - reset a user's password."); | ||
501 | m_console.Notice("login-level <value> - Set the miminim userlevel allowed To login."); | ||
502 | m_console.Notice("login-reset - reset the login level to its default value."); | ||
503 | m_console.Notice("login-text <text to print during the login>"); | ||
504 | 249 | ||
250 | m_consoleCommandModule.ShowHelp(helpArgs); | ||
505 | } | 251 | } |
506 | #endregion | 252 | #endregion |
507 | 253 | ||
diff --git a/OpenSim/Grid/UserServer/MessageServersConnector.cs b/OpenSim/Grid/UserServer/MessageServersConnector.cs deleted file mode 100644 index 1d0649c..0000000 --- a/OpenSim/Grid/UserServer/MessageServersConnector.cs +++ /dev/null | |||
@@ -1,509 +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 | |||
28 | using System.Collections; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using Nwc.XmlRpc; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Servers; | ||
38 | |||
39 | namespace OpenSim.Grid.UserServer | ||
40 | { | ||
41 | public enum NotificationRequest : int | ||
42 | { | ||
43 | Login = 0, | ||
44 | Logout = 1, | ||
45 | Shutdown = 2 | ||
46 | } | ||
47 | |||
48 | public struct PresenceNotification | ||
49 | { | ||
50 | public NotificationRequest request; | ||
51 | public UUID agentID; | ||
52 | public UUID sessionID; | ||
53 | public UUID RegionID; | ||
54 | public ulong regionhandle; | ||
55 | public float positionX; | ||
56 | public float positionY; | ||
57 | public float positionZ; | ||
58 | public string firstname; | ||
59 | public string lastname; | ||
60 | } | ||
61 | |||
62 | public delegate void AgentLocationDelegate(UUID agentID, UUID regionID, ulong regionHandle); | ||
63 | public delegate void AgentLeavingDelegate(UUID agentID, UUID regionID, ulong regionHandle); | ||
64 | public delegate void RegionStartupDelegate(UUID regionID); | ||
65 | public delegate void RegionShutdownDelegate(UUID regionID); | ||
66 | |||
67 | |||
68 | public class MessageServersConnector | ||
69 | { | ||
70 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
71 | |||
72 | public Dictionary<string, MessageServerInfo> MessageServers; | ||
73 | |||
74 | private BaseHttpServer m_httpServer; | ||
75 | |||
76 | private BlockingQueue<PresenceNotification> m_NotifyQueue = | ||
77 | new BlockingQueue<PresenceNotification>(); | ||
78 | |||
79 | Thread m_NotifyThread; | ||
80 | |||
81 | public event AgentLocationDelegate OnAgentLocation; | ||
82 | public event AgentLeavingDelegate OnAgentLeaving; | ||
83 | public event RegionStartupDelegate OnRegionStartup; | ||
84 | public event RegionShutdownDelegate OnRegionShutdown; | ||
85 | |||
86 | public MessageServersConnector() | ||
87 | { | ||
88 | MessageServers = new Dictionary<string, MessageServerInfo>(); | ||
89 | m_NotifyThread = new Thread(new ThreadStart(NotifyQueueRunner)); | ||
90 | m_NotifyThread.Start(); | ||
91 | } | ||
92 | |||
93 | public void Initialise() | ||
94 | { | ||
95 | |||
96 | } | ||
97 | |||
98 | public void PostInitialise() | ||
99 | { | ||
100 | |||
101 | } | ||
102 | |||
103 | public void RegisterHandlers(BaseHttpServer httpServer) | ||
104 | { | ||
105 | m_httpServer = httpServer; | ||
106 | |||
107 | m_httpServer.AddXmlRPCHandler("region_startup", RegionStartup); | ||
108 | m_httpServer.AddXmlRPCHandler("region_shutdown", RegionShutdown); | ||
109 | m_httpServer.AddXmlRPCHandler("agent_location", AgentLocation); | ||
110 | m_httpServer.AddXmlRPCHandler("agent_leaving", AgentLeaving); | ||
111 | // Message Server ---> User Server | ||
112 | m_httpServer.AddXmlRPCHandler("register_messageserver", XmlRPCRegisterMessageServer); | ||
113 | m_httpServer.AddXmlRPCHandler("agent_change_region", XmlRPCUserMovedtoRegion); | ||
114 | m_httpServer.AddXmlRPCHandler("deregister_messageserver", XmlRPCDeRegisterMessageServer); | ||
115 | } | ||
116 | |||
117 | public void RegisterMessageServer(string URI, MessageServerInfo serverData) | ||
118 | { | ||
119 | lock (MessageServers) | ||
120 | { | ||
121 | if (!MessageServers.ContainsKey(URI)) | ||
122 | MessageServers.Add(URI, serverData); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | public void DeRegisterMessageServer(string URI) | ||
127 | { | ||
128 | lock (MessageServers) | ||
129 | { | ||
130 | if (MessageServers.ContainsKey(URI)) | ||
131 | MessageServers.Remove(URI); | ||
132 | } | ||
133 | } | ||
134 | |||
135 | public void AddResponsibleRegion(string URI, ulong regionhandle) | ||
136 | { | ||
137 | if (!MessageServers.ContainsKey(URI)) | ||
138 | { | ||
139 | m_log.Warn("[MSGSERVER]: Got addResponsibleRegion Request for a MessageServer that isn't registered"); | ||
140 | } | ||
141 | else | ||
142 | { | ||
143 | MessageServerInfo msginfo = MessageServers["URI"]; | ||
144 | msginfo.responsibleForRegions.Add(regionhandle); | ||
145 | MessageServers["URI"] = msginfo; | ||
146 | } | ||
147 | } | ||
148 | public void RemoveResponsibleRegion(string URI, ulong regionhandle) | ||
149 | { | ||
150 | if (!MessageServers.ContainsKey(URI)) | ||
151 | { | ||
152 | m_log.Warn("[MSGSERVER]: Got RemoveResponsibleRegion Request for a MessageServer that isn't registered"); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | MessageServerInfo msginfo = MessageServers["URI"]; | ||
157 | if (msginfo.responsibleForRegions.Contains(regionhandle)) | ||
158 | { | ||
159 | msginfo.responsibleForRegions.Remove(regionhandle); | ||
160 | MessageServers["URI"] = msginfo; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | } | ||
165 | public XmlRpcResponse XmlRPCRegisterMessageServer(XmlRpcRequest request) | ||
166 | { | ||
167 | XmlRpcResponse response = new XmlRpcResponse(); | ||
168 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
169 | Hashtable responseData = new Hashtable(); | ||
170 | |||
171 | if (requestData.Contains("uri")) | ||
172 | { | ||
173 | string URI = (string)requestData["uri"]; | ||
174 | string sendkey=(string)requestData["sendkey"]; | ||
175 | string recvkey=(string)requestData["recvkey"]; | ||
176 | MessageServerInfo m = new MessageServerInfo(); | ||
177 | m.URI = URI; | ||
178 | m.sendkey = sendkey; | ||
179 | m.recvkey = recvkey; | ||
180 | RegisterMessageServer(URI, m); | ||
181 | responseData["responsestring"] = "TRUE"; | ||
182 | response.Value = responseData; | ||
183 | } | ||
184 | return response; | ||
185 | } | ||
186 | public XmlRpcResponse XmlRPCDeRegisterMessageServer(XmlRpcRequest request) | ||
187 | { | ||
188 | XmlRpcResponse response = new XmlRpcResponse(); | ||
189 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
190 | Hashtable responseData = new Hashtable(); | ||
191 | |||
192 | if (requestData.Contains("uri")) | ||
193 | { | ||
194 | string URI = (string)requestData["uri"]; | ||
195 | |||
196 | DeRegisterMessageServer(URI); | ||
197 | responseData["responsestring"] = "TRUE"; | ||
198 | response.Value = responseData; | ||
199 | } | ||
200 | return response; | ||
201 | } | ||
202 | public XmlRpcResponse XmlRPCUserMovedtoRegion(XmlRpcRequest request) | ||
203 | { | ||
204 | XmlRpcResponse response = new XmlRpcResponse(); | ||
205 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
206 | Hashtable responseData = new Hashtable(); | ||
207 | |||
208 | if (requestData.Contains("fromuri")) | ||
209 | { | ||
210 | // string sURI = (string)requestData["fromuri"]; | ||
211 | // string sagentID = (string)requestData["agentid"]; | ||
212 | // string ssessionID = (string)requestData["sessionid"]; | ||
213 | // string scurrentRegionID = (string)requestData["regionid"]; | ||
214 | // string sregionhandle = (string)requestData["regionhandle"]; | ||
215 | // string scurrentpos = (string)requestData["currentpos"]; | ||
216 | //Vector3.TryParse((string)reader["currentPos"], out retval.currentPos); | ||
217 | // TODO: Okay now raise event so the user server can pass this data to the Usermanager | ||
218 | |||
219 | responseData["responsestring"] = "TRUE"; | ||
220 | response.Value = responseData; | ||
221 | } | ||
222 | return response; | ||
223 | } | ||
224 | |||
225 | public void TellMessageServersAboutUser(UUID agentID, UUID sessionID, UUID RegionID, | ||
226 | ulong regionhandle, float positionX, float positionY, | ||
227 | float positionZ, string firstname, string lastname) | ||
228 | { | ||
229 | PresenceNotification notification = new PresenceNotification(); | ||
230 | |||
231 | notification.request = NotificationRequest.Login; | ||
232 | notification.agentID = agentID; | ||
233 | notification.sessionID = sessionID; | ||
234 | notification.RegionID = RegionID; | ||
235 | notification.regionhandle = regionhandle; | ||
236 | notification.positionX = positionX; | ||
237 | notification.positionY = positionY; | ||
238 | notification.positionZ = positionZ; | ||
239 | notification.firstname = firstname; | ||
240 | notification.lastname = lastname; | ||
241 | |||
242 | m_NotifyQueue.Enqueue(notification); | ||
243 | } | ||
244 | |||
245 | private void TellMessageServersAboutUserInternal(UUID agentID, UUID sessionID, UUID RegionID, | ||
246 | ulong regionhandle, float positionX, float positionY, | ||
247 | float positionZ, string firstname, string lastname) | ||
248 | { | ||
249 | // Loop over registered Message Servers (AND THERE WILL BE MORE THEN ONE :D) | ||
250 | lock (MessageServers) | ||
251 | { | ||
252 | if (MessageServers.Count > 0) | ||
253 | { | ||
254 | m_log.Info("[MSGCONNECTOR]: Sending login notice to registered message servers"); | ||
255 | } | ||
256 | // else | ||
257 | // { | ||
258 | // m_log.Debug("[MSGCONNECTOR]: No Message Servers registered, ignoring"); | ||
259 | // } | ||
260 | foreach (MessageServerInfo serv in MessageServers.Values) | ||
261 | { | ||
262 | NotifyMessageServerAboutUser(serv, agentID, sessionID, RegionID, | ||
263 | regionhandle, positionX, positionY, positionZ, | ||
264 | firstname, lastname); | ||
265 | } | ||
266 | } | ||
267 | } | ||
268 | |||
269 | private void TellMessageServersAboutUserLogoffInternal(UUID agentID) | ||
270 | { | ||
271 | lock (MessageServers) | ||
272 | { | ||
273 | if (MessageServers.Count > 0) | ||
274 | { | ||
275 | m_log.Info("[MSGCONNECTOR]: Sending logoff notice to registered message servers"); | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | // m_log.Debug("[MSGCONNECTOR]: No Message Servers registered, ignoring"); | ||
280 | } | ||
281 | foreach (MessageServerInfo serv in MessageServers.Values) | ||
282 | { | ||
283 | NotifyMessageServerAboutUserLogoff(serv,agentID); | ||
284 | } | ||
285 | } | ||
286 | } | ||
287 | |||
288 | private void TellMessageServersAboutRegionShutdownInternal(UUID regionID) | ||
289 | { | ||
290 | lock (MessageServers) | ||
291 | { | ||
292 | if (MessageServers.Count > 0) | ||
293 | { | ||
294 | m_log.Info("[MSGCONNECTOR]: Sending region down notice to registered message servers"); | ||
295 | } | ||
296 | else | ||
297 | { | ||
298 | // m_log.Debug("[MSGCONNECTOR]: No Message Servers registered, ignoring"); | ||
299 | } | ||
300 | foreach (MessageServerInfo serv in MessageServers.Values) | ||
301 | { | ||
302 | NotifyMessageServerAboutRegionShutdown(serv,regionID); | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | |||
307 | public void TellMessageServersAboutUserLogoff(UUID agentID) | ||
308 | { | ||
309 | PresenceNotification notification = new PresenceNotification(); | ||
310 | |||
311 | notification.request = NotificationRequest.Logout; | ||
312 | notification.agentID = agentID; | ||
313 | |||
314 | m_NotifyQueue.Enqueue(notification); | ||
315 | } | ||
316 | |||
317 | public void TellMessageServersAboutRegionShutdown(UUID regionID) | ||
318 | { | ||
319 | PresenceNotification notification = new PresenceNotification(); | ||
320 | |||
321 | notification.request = NotificationRequest.Shutdown; | ||
322 | notification.RegionID = regionID; | ||
323 | |||
324 | m_NotifyQueue.Enqueue(notification); | ||
325 | } | ||
326 | |||
327 | private void NotifyMessageServerAboutUserLogoff(MessageServerInfo serv, UUID agentID) | ||
328 | { | ||
329 | Hashtable reqparams = new Hashtable(); | ||
330 | reqparams["sendkey"] = serv.sendkey; | ||
331 | reqparams["agentid"] = agentID.ToString(); | ||
332 | ArrayList SendParams = new ArrayList(); | ||
333 | SendParams.Add(reqparams); | ||
334 | |||
335 | XmlRpcRequest GridReq = new XmlRpcRequest("logout_of_simulator", SendParams); | ||
336 | try | ||
337 | { | ||
338 | GridReq.Send(serv.URI, 6000); | ||
339 | } | ||
340 | catch (WebException) | ||
341 | { | ||
342 | m_log.Warn("[MSGCONNECTOR]: Unable to notify Message Server about log out. Other users might still think this user is online"); | ||
343 | } | ||
344 | m_log.Info("[LOGOUT]: Notified : " + serv.URI + " about user logout"); | ||
345 | } | ||
346 | |||
347 | private void NotifyMessageServerAboutRegionShutdown(MessageServerInfo serv, UUID regionID) | ||
348 | { | ||
349 | Hashtable reqparams = new Hashtable(); | ||
350 | reqparams["sendkey"] = serv.sendkey; | ||
351 | reqparams["regionid"] = regionID.ToString(); | ||
352 | ArrayList SendParams = new ArrayList(); | ||
353 | SendParams.Add(reqparams); | ||
354 | |||
355 | XmlRpcRequest GridReq = new XmlRpcRequest("process_region_shutdown", SendParams); | ||
356 | try | ||
357 | { | ||
358 | GridReq.Send(serv.URI, 6000); | ||
359 | } | ||
360 | catch (WebException) | ||
361 | { | ||
362 | m_log.Warn("[MSGCONNECTOR]: Unable to notify Message Server about region shutdown."); | ||
363 | } | ||
364 | m_log.Info("[REGION UPDOWN]: Notified : " + serv.URI + " about region state change"); | ||
365 | } | ||
366 | |||
367 | private void NotifyMessageServerAboutUser(MessageServerInfo serv, | ||
368 | UUID agentID, UUID sessionID, UUID RegionID, | ||
369 | ulong regionhandle, float positionX, float positionY, float positionZ, | ||
370 | string firstname, string lastname) | ||
371 | { | ||
372 | Hashtable reqparams = new Hashtable(); | ||
373 | reqparams["sendkey"] = serv.sendkey; | ||
374 | reqparams["agentid"] = agentID.ToString(); | ||
375 | reqparams["sessionid"] = sessionID.ToString(); | ||
376 | reqparams["regionid"] = RegionID.ToString(); | ||
377 | reqparams["regionhandle"] = regionhandle.ToString(); | ||
378 | reqparams["positionx"] = positionX.ToString(); | ||
379 | reqparams["positiony"] = positionY.ToString(); | ||
380 | reqparams["positionz"] = positionZ.ToString(); | ||
381 | reqparams["firstname"] = firstname; | ||
382 | reqparams["lastname"] = lastname; | ||
383 | |||
384 | //reqparams["position"] = Position.ToString(); | ||
385 | |||
386 | ArrayList SendParams = new ArrayList(); | ||
387 | SendParams.Add(reqparams); | ||
388 | |||
389 | XmlRpcRequest GridReq = new XmlRpcRequest("login_to_simulator", SendParams); | ||
390 | try | ||
391 | { | ||
392 | GridReq.Send(serv.URI, 6000); | ||
393 | m_log.Info("[LOGIN]: Notified : " + serv.URI + " about user login"); | ||
394 | } | ||
395 | catch (WebException) | ||
396 | { | ||
397 | m_log.Warn("[MSGCONNECTOR]: Unable to notify Message Server about login. Presence might be borked for this user"); | ||
398 | } | ||
399 | |||
400 | } | ||
401 | |||
402 | private void NotifyQueueRunner() | ||
403 | { | ||
404 | while (true) | ||
405 | { | ||
406 | PresenceNotification presence = m_NotifyQueue.Dequeue(); | ||
407 | |||
408 | if (presence.request == NotificationRequest.Shutdown) | ||
409 | { | ||
410 | TellMessageServersAboutRegionShutdownInternal(presence.RegionID); | ||
411 | } | ||
412 | |||
413 | if (presence.request == NotificationRequest.Login) | ||
414 | { | ||
415 | TellMessageServersAboutUserInternal(presence.agentID, | ||
416 | presence.sessionID, presence.RegionID, | ||
417 | presence.regionhandle, presence.positionX, | ||
418 | presence.positionY, presence.positionZ, | ||
419 | presence.firstname, presence.lastname); | ||
420 | } | ||
421 | |||
422 | if (presence.request == NotificationRequest.Logout) | ||
423 | { | ||
424 | TellMessageServersAboutUserLogoffInternal(presence.agentID); | ||
425 | } | ||
426 | } | ||
427 | } | ||
428 | |||
429 | public XmlRpcResponse RegionStartup(XmlRpcRequest request) | ||
430 | { | ||
431 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
432 | Hashtable result = new Hashtable(); | ||
433 | |||
434 | UUID regionID; | ||
435 | if (UUID.TryParse((string)requestData["RegionUUID"], out regionID)) | ||
436 | { | ||
437 | if (OnRegionStartup != null) | ||
438 | OnRegionStartup(regionID); | ||
439 | |||
440 | result["responsestring"] = "TRUE"; | ||
441 | } | ||
442 | |||
443 | XmlRpcResponse response = new XmlRpcResponse(); | ||
444 | response.Value = result; | ||
445 | return response; | ||
446 | } | ||
447 | |||
448 | public XmlRpcResponse RegionShutdown(XmlRpcRequest request) | ||
449 | { | ||
450 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
451 | Hashtable result = new Hashtable(); | ||
452 | |||
453 | UUID regionID; | ||
454 | if (UUID.TryParse((string)requestData["RegionUUID"], out regionID)) | ||
455 | { | ||
456 | if (OnRegionShutdown != null) | ||
457 | OnRegionShutdown(regionID); | ||
458 | |||
459 | result["responsestring"] = "TRUE"; | ||
460 | } | ||
461 | |||
462 | XmlRpcResponse response = new XmlRpcResponse(); | ||
463 | response.Value = result; | ||
464 | return response; | ||
465 | } | ||
466 | |||
467 | public XmlRpcResponse AgentLocation(XmlRpcRequest request) | ||
468 | { | ||
469 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
470 | Hashtable result = new Hashtable(); | ||
471 | |||
472 | UUID agentID; | ||
473 | UUID regionID; | ||
474 | ulong regionHandle; | ||
475 | if (UUID.TryParse((string)requestData["AgentID"], out agentID) && UUID.TryParse((string)requestData["RegionUUID"], out regionID) && ulong.TryParse((string)requestData["RegionHandle"], out regionHandle)) | ||
476 | { | ||
477 | if (OnAgentLocation != null) | ||
478 | OnAgentLocation(agentID, regionID, regionHandle); | ||
479 | |||
480 | result["responsestring"] = "TRUE"; | ||
481 | } | ||
482 | |||
483 | XmlRpcResponse response = new XmlRpcResponse(); | ||
484 | response.Value = result; | ||
485 | return response; | ||
486 | } | ||
487 | |||
488 | public XmlRpcResponse AgentLeaving(XmlRpcRequest request) | ||
489 | { | ||
490 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
491 | Hashtable result = new Hashtable(); | ||
492 | |||
493 | UUID agentID; | ||
494 | UUID regionID; | ||
495 | ulong regionHandle; | ||
496 | if (UUID.TryParse((string)requestData["AgentID"], out agentID) && UUID.TryParse((string)requestData["RegionUUID"], out regionID) && ulong.TryParse((string)requestData["RegionHandle"], out regionHandle)) | ||
497 | { | ||
498 | if (OnAgentLeaving != null) | ||
499 | OnAgentLeaving(agentID, regionID, regionHandle); | ||
500 | |||
501 | result["responsestring"] = "TRUE"; | ||
502 | } | ||
503 | |||
504 | XmlRpcResponse response = new XmlRpcResponse(); | ||
505 | response.Value = result; | ||
506 | return response; | ||
507 | } | ||
508 | } | ||
509 | } | ||
diff --git a/OpenSim/Grid/UserServer/OpenIdService.cs b/OpenSim/Grid/UserServer/OpenIdService.cs deleted file mode 100644 index 187758f..0000000 --- a/OpenSim/Grid/UserServer/OpenIdService.cs +++ /dev/null | |||
@@ -1,337 +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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Collections.Specialized; | ||
31 | using System.IO; | ||
32 | using System.Net; | ||
33 | using System.Web; | ||
34 | using DotNetOpenId; | ||
35 | using DotNetOpenId.Provider; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Servers; | ||
38 | |||
39 | namespace OpenSim.Grid.UserServer | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// Temporary, in-memory store for OpenID associations | ||
43 | /// </summary> | ||
44 | public class ProviderMemoryStore : IAssociationStore<AssociationRelyingPartyType> | ||
45 | { | ||
46 | private class AssociationItem | ||
47 | { | ||
48 | public AssociationRelyingPartyType DistinguishingFactor; | ||
49 | public string Handle; | ||
50 | public DateTime Expires; | ||
51 | public byte[] PrivateData; | ||
52 | } | ||
53 | |||
54 | Dictionary<string, AssociationItem> m_store = new Dictionary<string, AssociationItem>(); | ||
55 | SortedList<DateTime, AssociationItem> m_sortedStore = new SortedList<DateTime, AssociationItem>(); | ||
56 | object m_syncRoot = new object(); | ||
57 | |||
58 | #region IAssociationStore<AssociationRelyingPartyType> Members | ||
59 | |||
60 | public void StoreAssociation(AssociationRelyingPartyType distinguishingFactor, Association assoc) | ||
61 | { | ||
62 | AssociationItem item = new AssociationItem(); | ||
63 | item.DistinguishingFactor = distinguishingFactor; | ||
64 | item.Handle = assoc.Handle; | ||
65 | item.Expires = assoc.Expires.ToLocalTime(); | ||
66 | item.PrivateData = assoc.SerializePrivateData(); | ||
67 | |||
68 | lock (m_syncRoot) | ||
69 | { | ||
70 | m_store[item.Handle] = item; | ||
71 | m_sortedStore[item.Expires] = item; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor) | ||
76 | { | ||
77 | lock (m_syncRoot) | ||
78 | { | ||
79 | if (m_sortedStore.Count > 0) | ||
80 | { | ||
81 | AssociationItem item = m_sortedStore.Values[m_sortedStore.Count - 1]; | ||
82 | return Association.Deserialize(item.Handle, item.Expires.ToUniversalTime(), item.PrivateData); | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | return null; | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor, string handle) | ||
92 | { | ||
93 | AssociationItem item; | ||
94 | bool success = false; | ||
95 | lock (m_syncRoot) | ||
96 | success = m_store.TryGetValue(handle, out item); | ||
97 | |||
98 | if (success) | ||
99 | return Association.Deserialize(item.Handle, item.Expires.ToUniversalTime(), item.PrivateData); | ||
100 | else | ||
101 | return null; | ||
102 | } | ||
103 | |||
104 | public bool RemoveAssociation(AssociationRelyingPartyType distinguishingFactor, string handle) | ||
105 | { | ||
106 | lock (m_syncRoot) | ||
107 | { | ||
108 | for (int i = 0; i < m_sortedStore.Values.Count; i++) | ||
109 | { | ||
110 | AssociationItem item = m_sortedStore.Values[i]; | ||
111 | if (item.Handle == handle) | ||
112 | { | ||
113 | m_sortedStore.RemoveAt(i); | ||
114 | break; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | return m_store.Remove(handle); | ||
119 | } | ||
120 | } | ||
121 | |||
122 | public void ClearExpiredAssociations() | ||
123 | { | ||
124 | lock (m_syncRoot) | ||
125 | { | ||
126 | List<AssociationItem> itemsCopy = new List<AssociationItem>(m_sortedStore.Values); | ||
127 | DateTime now = DateTime.Now; | ||
128 | |||
129 | for (int i = 0; i < itemsCopy.Count; i++) | ||
130 | { | ||
131 | AssociationItem item = itemsCopy[i]; | ||
132 | |||
133 | if (item.Expires <= now) | ||
134 | { | ||
135 | m_sortedStore.RemoveAt(i); | ||
136 | m_store.Remove(item.Handle); | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | |||
142 | #endregion | ||
143 | } | ||
144 | |||
145 | public class OpenIdStreamHandler : IStreamHandler | ||
146 | { | ||
147 | #region HTML | ||
148 | |||
149 | /// <summary>Login form used to authenticate OpenID requests</summary> | ||
150 | const string LOGIN_PAGE = | ||
151 | @"<html> | ||
152 | <head><title>OpenSim OpenID Login</title></head> | ||
153 | <body> | ||
154 | <h3>OpenSim Login</h3> | ||
155 | <form method=""post""> | ||
156 | <label for=""first"">First Name:</label> <input readonly type=""text"" name=""first"" id=""first"" value=""{0}""/> | ||
157 | <label for=""last"">Last Name:</label> <input readonly type=""text"" name=""last"" id=""last"" value=""{1}""/> | ||
158 | <label for=""pass"">Password:</label> <input type=""password"" name=""pass"" id=""pass""/> | ||
159 | <input type=""submit"" value=""Login""> | ||
160 | </form> | ||
161 | </body> | ||
162 | </html>"; | ||
163 | |||
164 | /// <summary>Page shown for a valid OpenID identity</summary> | ||
165 | const string OPENID_PAGE = | ||
166 | @"<html> | ||
167 | <head> | ||
168 | <title>{2} {3}</title> | ||
169 | <link rel=""openid2.provider openid.server"" href=""{0}://{1}/openid/server/""/> | ||
170 | </head> | ||
171 | <body>OpenID identifier for {2} {3}</body> | ||
172 | </html> | ||
173 | "; | ||
174 | |||
175 | /// <summary>Page shown for an invalid OpenID identity</summary> | ||
176 | const string INVALID_OPENID_PAGE = | ||
177 | @"<html><head><title>Identity not found</title></head> | ||
178 | <body>Invalid OpenID identity</body></html>"; | ||
179 | |||
180 | /// <summary>Page shown if the OpenID endpoint is requested directly</summary> | ||
181 | const string ENDPOINT_PAGE = | ||
182 | @"<html><head><title>OpenID Endpoint</title></head><body> | ||
183 | This is an OpenID server endpoint, not a human-readable resource. | ||
184 | For more information, see <a href='http://openid.net/'>http://openid.net/</a>. | ||
185 | </body></html>"; | ||
186 | |||
187 | #endregion HTML | ||
188 | |||
189 | public string ContentType { get { return m_contentType; } } | ||
190 | public string HttpMethod { get { return m_httpMethod; } } | ||
191 | public string Path { get { return m_path; } } | ||
192 | |||
193 | string m_contentType; | ||
194 | string m_httpMethod; | ||
195 | string m_path; | ||
196 | UserLoginService m_loginService; | ||
197 | ProviderMemoryStore m_openidStore = new ProviderMemoryStore(); | ||
198 | |||
199 | /// <summary> | ||
200 | /// Constructor | ||
201 | /// </summary> | ||
202 | public OpenIdStreamHandler(string httpMethod, string path, UserLoginService loginService) | ||
203 | { | ||
204 | m_loginService = loginService; | ||
205 | m_httpMethod = httpMethod; | ||
206 | m_path = path; | ||
207 | |||
208 | m_contentType = "text/html"; | ||
209 | } | ||
210 | |||
211 | /// <summary> | ||
212 | /// Handles all GET and POST requests for OpenID identifier pages and endpoint | ||
213 | /// server communication | ||
214 | /// </summary> | ||
215 | public void Handle(string path, Stream request, Stream response, OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
216 | { | ||
217 | Uri providerEndpoint = new Uri(String.Format("{0}://{1}{2}", httpRequest.Url.Scheme, httpRequest.Url.Authority, httpRequest.Url.AbsolutePath)); | ||
218 | |||
219 | // Defult to returning HTML content | ||
220 | m_contentType = "text/html"; | ||
221 | |||
222 | try | ||
223 | { | ||
224 | NameValueCollection postQuery = HttpUtility.ParseQueryString(new StreamReader(httpRequest.InputStream).ReadToEnd()); | ||
225 | NameValueCollection getQuery = HttpUtility.ParseQueryString(httpRequest.Url.Query); | ||
226 | NameValueCollection openIdQuery = (postQuery.GetValues("openid.mode") != null ? postQuery : getQuery); | ||
227 | |||
228 | OpenIdProvider provider = new OpenIdProvider(m_openidStore, providerEndpoint, httpRequest.Url, openIdQuery); | ||
229 | |||
230 | if (provider.Request != null) | ||
231 | { | ||
232 | if (!provider.Request.IsResponseReady && provider.Request is IAuthenticationRequest) | ||
233 | { | ||
234 | IAuthenticationRequest authRequest = (IAuthenticationRequest)provider.Request; | ||
235 | string[] passwordValues = postQuery.GetValues("pass"); | ||
236 | |||
237 | UserProfileData profile; | ||
238 | if (TryGetProfile(new Uri(authRequest.ClaimedIdentifier.ToString()), out profile)) | ||
239 | { | ||
240 | // Check for form POST data | ||
241 | if (passwordValues != null && passwordValues.Length == 1) | ||
242 | { | ||
243 | if (profile != null && m_loginService.AuthenticateUser(profile, passwordValues[0])) | ||
244 | authRequest.IsAuthenticated = true; | ||
245 | else | ||
246 | authRequest.IsAuthenticated = false; | ||
247 | } | ||
248 | else | ||
249 | { | ||
250 | // Authentication was requested, send the client a login form | ||
251 | using (StreamWriter writer = new StreamWriter(response)) | ||
252 | writer.Write(String.Format(LOGIN_PAGE, profile.FirstName, profile.SurName)); | ||
253 | return; | ||
254 | } | ||
255 | } | ||
256 | else | ||
257 | { | ||
258 | // Cannot find an avatar matching the claimed identifier | ||
259 | authRequest.IsAuthenticated = false; | ||
260 | } | ||
261 | } | ||
262 | |||
263 | // Add OpenID headers to the response | ||
264 | foreach (string key in provider.Request.Response.Headers.Keys) | ||
265 | httpResponse.AddHeader(key, provider.Request.Response.Headers[key]); | ||
266 | |||
267 | string[] contentTypeValues = provider.Request.Response.Headers.GetValues("Content-Type"); | ||
268 | if (contentTypeValues != null && contentTypeValues.Length == 1) | ||
269 | m_contentType = contentTypeValues[0]; | ||
270 | |||
271 | // Set the response code and document body based on the OpenID result | ||
272 | httpResponse.StatusCode = (int)provider.Request.Response.Code; | ||
273 | response.Write(provider.Request.Response.Body, 0, provider.Request.Response.Body.Length); | ||
274 | response.Close(); | ||
275 | } | ||
276 | else if (httpRequest.Url.AbsolutePath.Contains("/openid/server")) | ||
277 | { | ||
278 | // Standard HTTP GET was made on the OpenID endpoint, send the client the default error page | ||
279 | using (StreamWriter writer = new StreamWriter(response)) | ||
280 | writer.Write(ENDPOINT_PAGE); | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | // Try and lookup this avatar | ||
285 | UserProfileData profile; | ||
286 | if (TryGetProfile(httpRequest.Url, out profile)) | ||
287 | { | ||
288 | using (StreamWriter writer = new StreamWriter(response)) | ||
289 | { | ||
290 | // TODO: Print out a full profile page for this avatar | ||
291 | writer.Write(String.Format(OPENID_PAGE, httpRequest.Url.Scheme, | ||
292 | httpRequest.Url.Authority, profile.FirstName, profile.SurName)); | ||
293 | } | ||
294 | } | ||
295 | else | ||
296 | { | ||
297 | // Couldn't parse an avatar name, or couldn't find the avatar in the user server | ||
298 | using (StreamWriter writer = new StreamWriter(response)) | ||
299 | writer.Write(INVALID_OPENID_PAGE); | ||
300 | } | ||
301 | } | ||
302 | } | ||
303 | catch (Exception ex) | ||
304 | { | ||
305 | httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError; | ||
306 | using (StreamWriter writer = new StreamWriter(response)) | ||
307 | writer.Write(ex.Message); | ||
308 | } | ||
309 | } | ||
310 | |||
311 | /// <summary> | ||
312 | /// Parse a URL with a relative path of the form /users/First_Last and try to | ||
313 | /// retrieve the profile matching that avatar name | ||
314 | /// </summary> | ||
315 | /// <param name="requestUrl">URL to parse for an avatar name</param> | ||
316 | /// <param name="profile">Profile data for the avatar</param> | ||
317 | /// <returns>True if the parse and lookup were successful, otherwise false</returns> | ||
318 | bool TryGetProfile(Uri requestUrl, out UserProfileData profile) | ||
319 | { | ||
320 | if (requestUrl.Segments.Length == 3 && requestUrl.Segments[1] == "users/") | ||
321 | { | ||
322 | // Parse the avatar name from the path | ||
323 | string username = requestUrl.Segments[requestUrl.Segments.Length - 1]; | ||
324 | string[] name = username.Split('_'); | ||
325 | |||
326 | if (name.Length == 2) | ||
327 | { | ||
328 | profile = m_loginService.GetTheUser(name[0], name[1]); | ||
329 | return (profile != null); | ||
330 | } | ||
331 | } | ||
332 | |||
333 | profile = null; | ||
334 | return false; | ||
335 | } | ||
336 | } | ||
337 | } | ||
diff --git a/OpenSim/Grid/UserServer/UserDataBaseService.cs b/OpenSim/Grid/UserServer/UserDataBaseService.cs deleted file mode 100644 index 85c98a6..0000000 --- a/OpenSim/Grid/UserServer/UserDataBaseService.cs +++ /dev/null | |||
@@ -1,68 +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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nwc.XmlRpc; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Communications; | ||
37 | using OpenSim.Framework.Servers; | ||
38 | |||
39 | namespace OpenSim.Grid.UserServer | ||
40 | { | ||
41 | public class UserDataBaseService : UserManagerBase | ||
42 | { | ||
43 | public UserDataBaseService() | ||
44 | : base(null) | ||
45 | { | ||
46 | } | ||
47 | |||
48 | public UserDataBaseService(IInterServiceInventoryServices interServiceInventoryService) | ||
49 | : base(interServiceInventoryService) | ||
50 | { | ||
51 | } | ||
52 | |||
53 | public override UserProfileData SetupMasterUser(string firstName, string lastName) | ||
54 | { | ||
55 | throw new Exception("The method or operation is not implemented."); | ||
56 | } | ||
57 | |||
58 | public override UserProfileData SetupMasterUser(string firstName, string lastName, string password) | ||
59 | { | ||
60 | throw new Exception("The method or operation is not implemented."); | ||
61 | } | ||
62 | |||
63 | public override UserProfileData SetupMasterUser(UUID uuid) | ||
64 | { | ||
65 | throw new Exception("The method or operation is not implemented."); | ||
66 | } | ||
67 | } | ||
68 | } | ||
diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs deleted file mode 100644 index 0cb4976..0000000 --- a/OpenSim/Grid/UserServer/UserLoginService.cs +++ /dev/null | |||
@@ -1,600 +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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using System.Text.RegularExpressions; | ||
33 | using log4net; | ||
34 | using Nwc.XmlRpc; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Data; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Communications; | ||
39 | using OpenSim.Framework.Communications.Cache; | ||
40 | using OpenSim.Framework.Communications.Capabilities; | ||
41 | using OpenSim.Framework.Servers; | ||
42 | |||
43 | namespace OpenSim.Grid.UserServer | ||
44 | { | ||
45 | public delegate void UserLoggedInAtLocation(UUID agentID, UUID sessionID, UUID RegionID, | ||
46 | ulong regionhandle, float positionX, float positionY, float positionZ, | ||
47 | string firstname, string lastname); | ||
48 | |||
49 | /// <summary> | ||
50 | /// Login service used in grid mode. | ||
51 | /// </summary> | ||
52 | public class UserLoginService : LoginService | ||
53 | { | ||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | protected IInterServiceInventoryServices m_inventoryService; | ||
57 | |||
58 | public event UserLoggedInAtLocation OnUserLoggedInAtLocation; | ||
59 | |||
60 | private UserLoggedInAtLocation handlerUserLoggedInAtLocation; | ||
61 | |||
62 | public UserConfig m_config; | ||
63 | private readonly IRegionProfileService m_regionProfileService; | ||
64 | |||
65 | protected BaseHttpServer m_httpServer; | ||
66 | |||
67 | public UserLoginService( | ||
68 | UserManagerBase userManager, IInterServiceInventoryServices inventoryService, | ||
69 | LibraryRootFolder libraryRootFolder, | ||
70 | UserConfig config, string welcomeMess, IRegionProfileService regionProfileService) | ||
71 | : base(userManager, libraryRootFolder, welcomeMess) | ||
72 | { | ||
73 | m_config = config; | ||
74 | m_inventoryService = inventoryService; | ||
75 | m_regionProfileService = regionProfileService; | ||
76 | } | ||
77 | |||
78 | public void RegisterHandlers(BaseHttpServer httpServer, bool registerLLSDHandler, bool registerOpenIDHandlers) | ||
79 | { | ||
80 | m_httpServer = httpServer; | ||
81 | |||
82 | m_httpServer.AddXmlRPCHandler("login_to_simulator", XmlRpcLoginMethod); | ||
83 | m_httpServer.AddHTTPHandler("login", ProcessHTMLLogin); | ||
84 | m_httpServer.AddXmlRPCHandler("set_login_params", XmlRPCSetLoginParams); | ||
85 | |||
86 | if (registerLLSDHandler) | ||
87 | { | ||
88 | m_httpServer.SetDefaultLLSDHandler(LLSDLoginMethod); | ||
89 | } | ||
90 | |||
91 | if (registerOpenIDHandlers) | ||
92 | { | ||
93 | // Handler for OpenID avatar identity pages | ||
94 | m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/users/", this)); | ||
95 | // Handlers for the OpenID endpoint server | ||
96 | m_httpServer.AddStreamHandler(new OpenIdStreamHandler("POST", "/openid/server/", this)); | ||
97 | m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", this)); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | public void setloginlevel(int level) | ||
102 | { | ||
103 | m_minLoginLevel = level; | ||
104 | m_log.InfoFormat("[GRID]: Login Level set to {0} ", level); | ||
105 | } | ||
106 | public void setwelcometext(string text) | ||
107 | { | ||
108 | m_welcomeMessage = text; | ||
109 | m_log.InfoFormat("[GRID]: Login text set to {0} ", text); | ||
110 | } | ||
111 | |||
112 | public override void LogOffUser(UserProfileData theUser, string message) | ||
113 | { | ||
114 | RegionProfileData SimInfo; | ||
115 | try | ||
116 | { | ||
117 | SimInfo = m_regionProfileService.RequestSimProfileData( | ||
118 | theUser.CurrentAgent.Handle, m_config.GridServerURL, | ||
119 | m_config.GridSendKey, m_config.GridRecvKey); | ||
120 | |||
121 | if (SimInfo == null) | ||
122 | { | ||
123 | m_log.Error("[GRID]: Region user was in isn't currently logged in"); | ||
124 | return; | ||
125 | } | ||
126 | } | ||
127 | catch (Exception) | ||
128 | { | ||
129 | m_log.Error("[GRID]: Unable to look up region to log user off"); | ||
130 | return; | ||
131 | } | ||
132 | |||
133 | // Prepare notification | ||
134 | Hashtable SimParams = new Hashtable(); | ||
135 | SimParams["agent_id"] = theUser.ID.ToString(); | ||
136 | SimParams["region_secret"] = theUser.CurrentAgent.SecureSessionID.ToString(); | ||
137 | SimParams["region_secret2"] = SimInfo.regionSecret; | ||
138 | //m_log.Info(SimInfo.regionSecret); | ||
139 | SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); | ||
140 | SimParams["message"] = message; | ||
141 | ArrayList SendParams = new ArrayList(); | ||
142 | SendParams.Add(SimParams); | ||
143 | |||
144 | m_log.InfoFormat( | ||
145 | "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", | ||
146 | SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, | ||
147 | theUser.FirstName + " " + theUser.SurName); | ||
148 | |||
149 | try | ||
150 | { | ||
151 | XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); | ||
152 | XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); | ||
153 | |||
154 | if (GridResp.IsFault) | ||
155 | { | ||
156 | m_log.ErrorFormat( | ||
157 | "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", | ||
158 | SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); | ||
159 | } | ||
160 | } | ||
161 | catch (Exception) | ||
162 | { | ||
163 | m_log.Error("[LOGIN]: Error telling region to logout user!"); | ||
164 | } | ||
165 | |||
166 | // Prepare notification | ||
167 | SimParams = new Hashtable(); | ||
168 | SimParams["agent_id"] = theUser.ID.ToString(); | ||
169 | SimParams["region_secret"] = SimInfo.regionSecret; | ||
170 | //m_log.Info(SimInfo.regionSecret); | ||
171 | SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); | ||
172 | SimParams["message"] = message; | ||
173 | SendParams = new ArrayList(); | ||
174 | SendParams.Add(SimParams); | ||
175 | |||
176 | m_log.InfoFormat( | ||
177 | "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", | ||
178 | SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, | ||
179 | theUser.FirstName + " " + theUser.SurName); | ||
180 | |||
181 | try | ||
182 | { | ||
183 | XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); | ||
184 | XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); | ||
185 | |||
186 | if (GridResp.IsFault) | ||
187 | { | ||
188 | m_log.ErrorFormat( | ||
189 | "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", | ||
190 | SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); | ||
191 | } | ||
192 | } | ||
193 | catch (Exception) | ||
194 | { | ||
195 | m_log.Error("[LOGIN]: Error telling region to logout user!"); | ||
196 | } | ||
197 | //base.LogOffUser(theUser); | ||
198 | } | ||
199 | |||
200 | /// <summary> | ||
201 | /// Customises the login response and fills in missing values. | ||
202 | /// </summary> | ||
203 | /// <param name="response">The existing response</param> | ||
204 | /// <param name="theUser">The user profile</param> | ||
205 | /// <param name="startLocationRequest">The requested start location</param> | ||
206 | public override bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest) | ||
207 | { | ||
208 | // add active gestures to login-response | ||
209 | AddActiveGestures(response, theUser); | ||
210 | |||
211 | // HomeLocation | ||
212 | RegionProfileData homeInfo = null; | ||
213 | // use the homeRegionID if it is stored already. If not, use the regionHandle as before | ||
214 | UUID homeRegionId = theUser.HomeRegionID; | ||
215 | ulong homeRegionHandle = theUser.HomeRegion; | ||
216 | if (homeRegionId != UUID.Zero) | ||
217 | { | ||
218 | homeInfo = GetRegionInfo(homeRegionId); | ||
219 | } | ||
220 | else | ||
221 | { | ||
222 | homeInfo = GetRegionInfo(homeRegionHandle); | ||
223 | } | ||
224 | |||
225 | if (homeInfo != null) | ||
226 | { | ||
227 | response.Home = | ||
228 | string.Format( | ||
229 | "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", | ||
230 | (homeInfo.regionLocX*Constants.RegionSize), | ||
231 | (homeInfo.regionLocY*Constants.RegionSize), | ||
232 | theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, | ||
233 | theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); | ||
234 | } | ||
235 | else | ||
236 | { | ||
237 | // Emergency mode: Home-region isn't available, so we can't request the region info. | ||
238 | // Use the stored home regionHandle instead. | ||
239 | // NOTE: If the home-region moves, this will be wrong until the users update their user-profile again | ||
240 | ulong regionX = homeRegionHandle >> 32; | ||
241 | ulong regionY = homeRegionHandle & 0xffffffff; | ||
242 | response.Home = | ||
243 | string.Format( | ||
244 | "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", | ||
245 | regionX, regionY, | ||
246 | theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, | ||
247 | theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); | ||
248 | m_log.InfoFormat("[LOGIN] Home region of user {0} {1} is not available; using computed region position {2} {3}", | ||
249 | theUser.FirstName, theUser.SurName, | ||
250 | regionX, regionY); | ||
251 | } | ||
252 | |||
253 | // StartLocation | ||
254 | RegionProfileData regionInfo = null; | ||
255 | if (startLocationRequest == "home") | ||
256 | { | ||
257 | regionInfo = homeInfo; | ||
258 | theUser.CurrentAgent.Position = theUser.HomeLocation; | ||
259 | response.LookAt = "[r" + theUser.HomeLookAt.X.ToString() + ",r" + theUser.HomeLookAt.Y.ToString() + ",r" + theUser.HomeLookAt.Z.ToString() + "]"; | ||
260 | } | ||
261 | else if (startLocationRequest == "last") | ||
262 | { | ||
263 | UUID lastRegion = theUser.CurrentAgent.Region; | ||
264 | regionInfo = GetRegionInfo(lastRegion); | ||
265 | response.LookAt = "[r" + theUser.CurrentAgent.LookAt.X.ToString() + ",r" + theUser.CurrentAgent.LookAt.Y.ToString() + ",r" + theUser.CurrentAgent.LookAt.Z.ToString() + "]"; | ||
266 | } | ||
267 | else | ||
268 | { | ||
269 | Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$"); | ||
270 | Match uriMatch = reURI.Match(startLocationRequest); | ||
271 | if (uriMatch == null) | ||
272 | { | ||
273 | m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, but can't process it", startLocationRequest); | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | string region = uriMatch.Groups["region"].ToString(); | ||
278 | regionInfo = RequestClosestRegion(region); | ||
279 | if (regionInfo == null) | ||
280 | { | ||
281 | m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, can't locate region {1}", startLocationRequest, region); | ||
282 | } | ||
283 | else | ||
284 | { | ||
285 | theUser.CurrentAgent.Position = new Vector3(float.Parse(uriMatch.Groups["x"].Value), | ||
286 | float.Parse(uriMatch.Groups["y"].Value), float.Parse(uriMatch.Groups["z"].Value)); | ||
287 | } | ||
288 | } | ||
289 | response.LookAt = "[r0,r1,r0]"; | ||
290 | // can be: last, home, safe, url | ||
291 | response.StartLocation = "url"; | ||
292 | } | ||
293 | |||
294 | if ((regionInfo != null) && (PrepareLoginToRegion(regionInfo, theUser, response))) | ||
295 | { | ||
296 | return true; | ||
297 | } | ||
298 | |||
299 | // StartLocation not available, send him to a nearby region instead | ||
300 | //regionInfo = RegionProfileData.RequestSimProfileData("", m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey); | ||
301 | //m_log.InfoFormat("[LOGIN]: StartLocation not available sending to region {0}", regionInfo.regionName); | ||
302 | |||
303 | // Send him to default region instead | ||
304 | // Load information from the gridserver | ||
305 | ulong defaultHandle = (((ulong) m_config.DefaultX * Constants.RegionSize) << 32) | | ||
306 | ((ulong) m_config.DefaultY * Constants.RegionSize); | ||
307 | |||
308 | if ((regionInfo != null) && (defaultHandle == regionInfo.regionHandle)) | ||
309 | { | ||
310 | m_log.ErrorFormat("[LOGIN]: Not trying the default region since this is the same as the selected region"); | ||
311 | return false; | ||
312 | } | ||
313 | |||
314 | m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead"); | ||
315 | regionInfo = GetRegionInfo(defaultHandle); | ||
316 | |||
317 | // Customise the response | ||
318 | //response.Home = | ||
319 | // string.Format( | ||
320 | // "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", | ||
321 | // (SimInfo.regionLocX * Constants.RegionSize), | ||
322 | // (SimInfo.regionLocY*Constants.RegionSize), | ||
323 | // theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, | ||
324 | // theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); | ||
325 | theUser.CurrentAgent.Position = new Vector3(128,128,0); | ||
326 | response.StartLocation = "safe"; | ||
327 | |||
328 | return PrepareLoginToRegion(regionInfo, theUser, response); | ||
329 | } | ||
330 | |||
331 | protected RegionProfileData RequestClosestRegion(string region) | ||
332 | { | ||
333 | return m_regionProfileService.RequestSimProfileData(region, | ||
334 | m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey); | ||
335 | } | ||
336 | |||
337 | protected RegionProfileData GetRegionInfo(ulong homeRegionHandle) | ||
338 | { | ||
339 | return m_regionProfileService.RequestSimProfileData(homeRegionHandle, | ||
340 | m_config.GridServerURL, m_config.GridSendKey, | ||
341 | m_config.GridRecvKey); | ||
342 | } | ||
343 | |||
344 | protected RegionProfileData GetRegionInfo(UUID homeRegionId) | ||
345 | { | ||
346 | return m_regionProfileService.RequestSimProfileData(homeRegionId, | ||
347 | m_config.GridServerURL, m_config.GridSendKey, | ||
348 | m_config.GridRecvKey); | ||
349 | } | ||
350 | |||
351 | /// <summary> | ||
352 | /// Add active gestures of the user to the login response. | ||
353 | /// </summary> | ||
354 | /// <param name="response"> | ||
355 | /// A <see cref="LoginResponse"/> | ||
356 | /// </param> | ||
357 | /// <param name="theUser"> | ||
358 | /// A <see cref="UserProfileData"/> | ||
359 | /// </param> | ||
360 | private void AddActiveGestures(LoginResponse response, UserProfileData theUser) | ||
361 | { | ||
362 | List<InventoryItemBase> gestures = m_inventoryService.GetActiveGestures(theUser.ID); | ||
363 | //m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count); | ||
364 | ArrayList list = new ArrayList(); | ||
365 | if (gestures != null) | ||
366 | { | ||
367 | foreach (InventoryItemBase gesture in gestures) | ||
368 | { | ||
369 | Hashtable item = new Hashtable(); | ||
370 | item["item_id"] = gesture.ID.ToString(); | ||
371 | item["asset_id"] = gesture.AssetID.ToString(); | ||
372 | list.Add(item); | ||
373 | } | ||
374 | } | ||
375 | response.ActiveGestures = list; | ||
376 | } | ||
377 | |||
378 | /// <summary> | ||
379 | /// Prepare a login to the given region. This involves both telling the region to expect a connection | ||
380 | /// and appropriately customising the response to the user. | ||
381 | /// </summary> | ||
382 | /// <param name="sim"></param> | ||
383 | /// <param name="user"></param> | ||
384 | /// <param name="response"></param> | ||
385 | /// <returns>true if the region was successfully contacted, false otherwise</returns> | ||
386 | private bool PrepareLoginToRegion(RegionProfileData regionInfo, UserProfileData user, LoginResponse response) | ||
387 | { | ||
388 | try | ||
389 | { | ||
390 | response.SimAddress = Util.GetHostFromURL(regionInfo.serverURI).ToString(); | ||
391 | response.SimPort = uint.Parse(regionInfo.serverURI.Split(new char[] { '/', ':' })[4]); | ||
392 | response.RegionX = regionInfo.regionLocX; | ||
393 | response.RegionY = regionInfo.regionLocY; | ||
394 | |||
395 | string capsPath = CapsUtil.GetRandomCapsObjectPath(); | ||
396 | |||
397 | // Take off trailing / so that the caps path isn't //CAPS/someUUID | ||
398 | if (regionInfo.httpServerURI.EndsWith("/")) | ||
399 | regionInfo.httpServerURI = regionInfo.httpServerURI.Substring(0, regionInfo.httpServerURI.Length - 1); | ||
400 | response.SeedCapability = regionInfo.httpServerURI + CapsUtil.GetCapsSeedPath(capsPath); | ||
401 | |||
402 | // Notify the target of an incoming user | ||
403 | m_log.InfoFormat( | ||
404 | "[LOGIN]: Telling {0} @ {1},{2} ({3}) to prepare for client connection", | ||
405 | regionInfo.regionName, response.RegionX, response.RegionY, regionInfo.httpServerURI); | ||
406 | |||
407 | // Update agent with target sim | ||
408 | user.CurrentAgent.Region = regionInfo.UUID; | ||
409 | user.CurrentAgent.Handle = regionInfo.regionHandle; | ||
410 | |||
411 | // Prepare notification | ||
412 | Hashtable loginParams = new Hashtable(); | ||
413 | loginParams["session_id"] = user.CurrentAgent.SessionID.ToString(); | ||
414 | loginParams["secure_session_id"] = user.CurrentAgent.SecureSessionID.ToString(); | ||
415 | loginParams["firstname"] = user.FirstName; | ||
416 | loginParams["lastname"] = user.SurName; | ||
417 | loginParams["agent_id"] = user.ID.ToString(); | ||
418 | loginParams["circuit_code"] = (Int32) Convert.ToUInt32(response.CircuitCode); | ||
419 | loginParams["startpos_x"] = user.CurrentAgent.Position.X.ToString(); | ||
420 | loginParams["startpos_y"] = user.CurrentAgent.Position.Y.ToString(); | ||
421 | loginParams["startpos_z"] = user.CurrentAgent.Position.Z.ToString(); | ||
422 | loginParams["regionhandle"] = user.CurrentAgent.Handle.ToString(); | ||
423 | loginParams["caps_path"] = capsPath; | ||
424 | |||
425 | // Get appearance | ||
426 | AvatarAppearance appearance = m_userManager.GetUserAppearance(user.ID); | ||
427 | if (appearance != null) | ||
428 | { | ||
429 | loginParams["appearance"] = appearance.ToHashTable(); | ||
430 | m_log.DebugFormat("[LOGIN]: Found appearance for {0} {1}", user.FirstName, user.SurName); | ||
431 | } | ||
432 | else | ||
433 | { | ||
434 | m_log.DebugFormat("[LOGIN]: Appearance not for {0} {1}. Creating default.", user.FirstName, user.SurName); | ||
435 | appearance = new AvatarAppearance(user.ID); | ||
436 | } | ||
437 | |||
438 | ArrayList SendParams = new ArrayList(); | ||
439 | SendParams.Add(loginParams); | ||
440 | |||
441 | // Send | ||
442 | XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams); | ||
443 | XmlRpcResponse GridResp = GridReq.Send(regionInfo.httpServerURI, 6000); | ||
444 | |||
445 | if (!GridResp.IsFault) | ||
446 | { | ||
447 | bool responseSuccess = true; | ||
448 | |||
449 | if (GridResp.Value != null) | ||
450 | { | ||
451 | Hashtable resp = (Hashtable) GridResp.Value; | ||
452 | if (resp.ContainsKey("success")) | ||
453 | { | ||
454 | if ((string) resp["success"] == "FALSE") | ||
455 | { | ||
456 | responseSuccess = false; | ||
457 | } | ||
458 | } | ||
459 | } | ||
460 | if (responseSuccess) | ||
461 | { | ||
462 | handlerUserLoggedInAtLocation = OnUserLoggedInAtLocation; | ||
463 | if (handlerUserLoggedInAtLocation != null) | ||
464 | { | ||
465 | handlerUserLoggedInAtLocation(user.ID, user.CurrentAgent.SessionID, | ||
466 | user.CurrentAgent.Region, | ||
467 | user.CurrentAgent.Handle, | ||
468 | user.CurrentAgent.Position.X, | ||
469 | user.CurrentAgent.Position.Y, | ||
470 | user.CurrentAgent.Position.Z, | ||
471 | user.FirstName, user.SurName); | ||
472 | } | ||
473 | } | ||
474 | else | ||
475 | { | ||
476 | m_log.ErrorFormat("[LOGIN]: Region responded that it is not available to receive clients"); | ||
477 | return false; | ||
478 | } | ||
479 | } | ||
480 | else | ||
481 | { | ||
482 | m_log.ErrorFormat("[LOGIN]: XmlRpc request to region failed with message {0}, code {1} ", GridResp.FaultString, GridResp.FaultCode); | ||
483 | return false; | ||
484 | } | ||
485 | } | ||
486 | catch (Exception e) | ||
487 | { | ||
488 | m_log.ErrorFormat("[LOGIN]: Region not available for login, {0}", e); | ||
489 | return false; | ||
490 | } | ||
491 | |||
492 | return true; | ||
493 | } | ||
494 | |||
495 | // See LoginService | ||
496 | protected override InventoryData GetInventorySkeleton(UUID userID) | ||
497 | { | ||
498 | m_log.DebugFormat( | ||
499 | "[LOGIN]: Contacting inventory service at {0} for inventory skeleton of user {1}", | ||
500 | m_config.InventoryUrl, userID); | ||
501 | |||
502 | List<InventoryFolderBase> folders = m_inventoryService.GetInventorySkeleton(userID); | ||
503 | |||
504 | if (null == folders || folders.Count == 0) | ||
505 | { | ||
506 | m_log.InfoFormat( | ||
507 | "[LOGIN]: A root inventory folder for user {0} was not found. Requesting creation.", userID); | ||
508 | |||
509 | // Although the create user function creates a new agent inventory along with a new user profile, some | ||
510 | // tools are creating the user profile directly in the database without creating the inventory. At | ||
511 | // this time we'll accomodate them by lazily creating the user inventory now if it doesn't already | ||
512 | // exist. | ||
513 | if (!m_inventoryService.CreateNewUserInventory(userID)) | ||
514 | { | ||
515 | throw new Exception( | ||
516 | String.Format( | ||
517 | "The inventory creation request for user {0} did not succeed." | ||
518 | + " Please contact your inventory service provider for more information.", | ||
519 | userID)); | ||
520 | } | ||
521 | m_log.InfoFormat("[LOGIN]: A new inventory skeleton was successfully created for user {0}", userID); | ||
522 | |||
523 | folders = m_inventoryService.GetInventorySkeleton(userID); | ||
524 | } | ||
525 | |||
526 | if (folders != null && folders.Count > 0) | ||
527 | { | ||
528 | UUID rootID = UUID.Zero; | ||
529 | ArrayList AgentInventoryArray = new ArrayList(); | ||
530 | Hashtable TempHash; | ||
531 | |||
532 | foreach (InventoryFolderBase InvFolder in folders) | ||
533 | { | ||
534 | // m_log.DebugFormat("[LOGIN]: Received agent inventory folder {0}", InvFolder.name); | ||
535 | |||
536 | if (InvFolder.ParentID == UUID.Zero) | ||
537 | { | ||
538 | rootID = InvFolder.ID; | ||
539 | } | ||
540 | TempHash = new Hashtable(); | ||
541 | TempHash["name"] = InvFolder.Name; | ||
542 | TempHash["parent_id"] = InvFolder.ParentID.ToString(); | ||
543 | TempHash["version"] = (Int32) InvFolder.Version; | ||
544 | TempHash["type_default"] = (Int32) InvFolder.Type; | ||
545 | TempHash["folder_id"] = InvFolder.ID.ToString(); | ||
546 | AgentInventoryArray.Add(TempHash); | ||
547 | } | ||
548 | |||
549 | return new InventoryData(AgentInventoryArray, rootID); | ||
550 | } | ||
551 | throw new Exception( | ||
552 | String.Format( | ||
553 | "A root inventory folder for user {0} could not be retrieved from the inventory service", | ||
554 | userID)); | ||
555 | } | ||
556 | |||
557 | public XmlRpcResponse XmlRPCSetLoginParams(XmlRpcRequest request) | ||
558 | { | ||
559 | XmlRpcResponse response = new XmlRpcResponse(); | ||
560 | Hashtable requestData = (Hashtable) request.Params[0]; | ||
561 | UserProfileData userProfile; | ||
562 | Hashtable responseData = new Hashtable(); | ||
563 | |||
564 | UUID uid; | ||
565 | string pass = requestData["password"].ToString(); | ||
566 | |||
567 | if (!UUID.TryParse((string) requestData["avatar_uuid"], out uid)) | ||
568 | { | ||
569 | responseData["error"] = "No authorization"; | ||
570 | response.Value = responseData; | ||
571 | return response; | ||
572 | } | ||
573 | |||
574 | userProfile = m_userManager.GetUserProfile(uid); | ||
575 | |||
576 | if (userProfile == null || | ||
577 | (!AuthenticateUser(userProfile, pass)) || | ||
578 | userProfile.GodLevel < 200) | ||
579 | { | ||
580 | responseData["error"] = "No authorization"; | ||
581 | response.Value = responseData; | ||
582 | return response; | ||
583 | } | ||
584 | |||
585 | if (requestData.ContainsKey("login_level")) | ||
586 | { | ||
587 | m_minLoginLevel = Convert.ToInt32(requestData["login_level"]); | ||
588 | } | ||
589 | |||
590 | if (requestData.ContainsKey("login_motd")) | ||
591 | { | ||
592 | m_welcomeMessage = requestData["login_motd"].ToString(); | ||
593 | } | ||
594 | |||
595 | response.Value = responseData; | ||
596 | return response; | ||
597 | } | ||
598 | |||
599 | } | ||
600 | } | ||
diff --git a/OpenSim/Grid/UserServer/UserManager.cs b/OpenSim/Grid/UserServer/UserManager.cs deleted file mode 100644 index ca50421..0000000 --- a/OpenSim/Grid/UserServer/UserManager.cs +++ /dev/null | |||
@@ -1,686 +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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nwc.XmlRpc; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Communications; | ||
37 | using OpenSim.Framework.Servers; | ||
38 | |||
39 | namespace OpenSim.Grid.UserServer | ||
40 | { | ||
41 | public delegate void logOffUser(UUID AgentID); | ||
42 | |||
43 | public class UserManager | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | public event logOffUser OnLogOffUser; | ||
48 | private logOffUser handlerLogOffUser; | ||
49 | |||
50 | private UserDataBaseService m_userDataBaseService; | ||
51 | private BaseHttpServer m_httpServer; | ||
52 | |||
53 | /// <summary> | ||
54 | /// | ||
55 | /// </summary> | ||
56 | /// <param name="userDataBaseService"></param> | ||
57 | public UserManager( UserDataBaseService userDataBaseService) | ||
58 | { | ||
59 | m_userDataBaseService = userDataBaseService; | ||
60 | } | ||
61 | |||
62 | public void Initialise() | ||
63 | { | ||
64 | |||
65 | } | ||
66 | |||
67 | public void PostInitialise() | ||
68 | { | ||
69 | |||
70 | } | ||
71 | |||
72 | public void RegisterHandlers(BaseHttpServer httpServer) | ||
73 | { | ||
74 | m_httpServer = httpServer; | ||
75 | |||
76 | m_httpServer.AddXmlRPCHandler("get_user_by_name", XmlRPCGetUserMethodName); | ||
77 | m_httpServer.AddXmlRPCHandler("get_user_by_uuid", XmlRPCGetUserMethodUUID); | ||
78 | m_httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", XmlRPCGetAvatarPickerAvatar); | ||
79 | |||
80 | m_httpServer.AddXmlRPCHandler("update_user_current_region", XmlRPCAtRegion); | ||
81 | m_httpServer.AddXmlRPCHandler("logout_of_simulator", XmlRPCLogOffUserMethodUUID); | ||
82 | m_httpServer.AddXmlRPCHandler("get_agent_by_uuid", XmlRPCGetAgentMethodUUID); | ||
83 | m_httpServer.AddXmlRPCHandler("check_auth_session", XmlRPCCheckAuthSession); | ||
84 | |||
85 | m_httpServer.AddXmlRPCHandler("update_user_profile", XmlRpcResponseXmlRPCUpdateUserProfile); | ||
86 | |||
87 | m_httpServer.AddStreamHandler(new RestStreamHandler("DELETE", "/usersessions/", RestDeleteUserSessionMethod)); | ||
88 | } | ||
89 | |||
90 | /// <summary> | ||
91 | /// Deletes an active agent session | ||
92 | /// </summary> | ||
93 | /// <param name="request">The request</param> | ||
94 | /// <param name="path">The path (eg /bork/narf/test)</param> | ||
95 | /// <param name="param">Parameters sent</param> | ||
96 | /// <param name="httpRequest">HTTP request header object</param> | ||
97 | /// <param name="httpResponse">HTTP response header object</param> | ||
98 | /// <returns>Success "OK" else error</returns> | ||
99 | public string RestDeleteUserSessionMethod(string request, string path, string param, | ||
100 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
101 | { | ||
102 | // TODO! Important! | ||
103 | |||
104 | return "OK"; | ||
105 | } | ||
106 | |||
107 | /// <summary> | ||
108 | /// Returns an error message that the user could not be found in the database | ||
109 | /// </summary> | ||
110 | /// <returns>XML string consisting of a error element containing individual error(s)</returns> | ||
111 | public XmlRpcResponse CreateUnknownUserErrorResponse() | ||
112 | { | ||
113 | XmlRpcResponse response = new XmlRpcResponse(); | ||
114 | Hashtable responseData = new Hashtable(); | ||
115 | responseData["error_type"] = "unknown_user"; | ||
116 | responseData["error_desc"] = "The user requested is not in the database"; | ||
117 | |||
118 | response.Value = responseData; | ||
119 | return response; | ||
120 | } | ||
121 | |||
122 | public XmlRpcResponse AvatarPickerListtoXmlRPCResponse(UUID queryID, List<AvatarPickerAvatar> returnUsers) | ||
123 | { | ||
124 | XmlRpcResponse response = new XmlRpcResponse(); | ||
125 | Hashtable responseData = new Hashtable(); | ||
126 | // Query Result Information | ||
127 | responseData["queryid"] = queryID.ToString(); | ||
128 | responseData["avcount"] = returnUsers.Count.ToString(); | ||
129 | |||
130 | for (int i = 0; i < returnUsers.Count; i++) | ||
131 | { | ||
132 | responseData["avatarid" + i] = returnUsers[i].AvatarID.ToString(); | ||
133 | responseData["firstname" + i] = returnUsers[i].firstName; | ||
134 | responseData["lastname" + i] = returnUsers[i].lastName; | ||
135 | } | ||
136 | response.Value = responseData; | ||
137 | |||
138 | return response; | ||
139 | } | ||
140 | |||
141 | /// <summary> | ||
142 | /// Converts a user profile to an XML element which can be returned | ||
143 | /// </summary> | ||
144 | /// <param name="profile">The user profile</param> | ||
145 | /// <returns>A string containing an XML Document of the user profile</returns> | ||
146 | public XmlRpcResponse ProfileToXmlRPCResponse(UserProfileData profile) | ||
147 | { | ||
148 | XmlRpcResponse response = new XmlRpcResponse(); | ||
149 | Hashtable responseData = new Hashtable(); | ||
150 | |||
151 | // Account information | ||
152 | responseData["firstname"] = profile.FirstName; | ||
153 | responseData["lastname"] = profile.SurName; | ||
154 | responseData["uuid"] = profile.ID.ToString(); | ||
155 | // Server Information | ||
156 | responseData["server_inventory"] = profile.UserInventoryURI; | ||
157 | responseData["server_asset"] = profile.UserAssetURI; | ||
158 | // Profile Information | ||
159 | responseData["profile_about"] = profile.AboutText; | ||
160 | responseData["profile_firstlife_about"] = profile.FirstLifeAboutText; | ||
161 | responseData["profile_firstlife_image"] = profile.FirstLifeImage.ToString(); | ||
162 | responseData["profile_can_do"] = profile.CanDoMask.ToString(); | ||
163 | responseData["profile_want_do"] = profile.WantDoMask.ToString(); | ||
164 | responseData["profile_image"] = profile.Image.ToString(); | ||
165 | responseData["profile_created"] = profile.Created.ToString(); | ||
166 | responseData["profile_lastlogin"] = profile.LastLogin.ToString(); | ||
167 | // Home region information | ||
168 | responseData["home_coordinates_x"] = profile.HomeLocation.X.ToString(); | ||
169 | responseData["home_coordinates_y"] = profile.HomeLocation.Y.ToString(); | ||
170 | responseData["home_coordinates_z"] = profile.HomeLocation.Z.ToString(); | ||
171 | |||
172 | responseData["home_region"] = profile.HomeRegion.ToString(); | ||
173 | responseData["home_region_id"] = profile.HomeRegionID.ToString(); | ||
174 | |||
175 | responseData["home_look_x"] = profile.HomeLookAt.X.ToString(); | ||
176 | responseData["home_look_y"] = profile.HomeLookAt.Y.ToString(); | ||
177 | responseData["home_look_z"] = profile.HomeLookAt.Z.ToString(); | ||
178 | |||
179 | responseData["user_flags"] = profile.UserFlags.ToString(); | ||
180 | responseData["god_level"] = profile.GodLevel.ToString(); | ||
181 | responseData["custom_type"] = profile.CustomType; | ||
182 | responseData["partner"] = profile.Partner.ToString(); | ||
183 | response.Value = responseData; | ||
184 | |||
185 | return response; | ||
186 | } | ||
187 | |||
188 | #region XMLRPC User Methods | ||
189 | |||
190 | public XmlRpcResponse XmlRPCGetAvatarPickerAvatar(XmlRpcRequest request) | ||
191 | { | ||
192 | // XmlRpcResponse response = new XmlRpcResponse(); | ||
193 | Hashtable requestData = (Hashtable) request.Params[0]; | ||
194 | List<AvatarPickerAvatar> returnAvatar = new List<AvatarPickerAvatar>(); | ||
195 | UUID queryID = new UUID(UUID.Zero.ToString()); | ||
196 | |||
197 | if (requestData.Contains("avquery") && requestData.Contains("queryid")) | ||
198 | { | ||
199 | queryID = new UUID((string) requestData["queryid"]); | ||
200 | returnAvatar = m_userDataBaseService.GenerateAgentPickerRequestResponse(queryID, (string) requestData["avquery"]); | ||
201 | } | ||
202 | |||
203 | m_log.InfoFormat("[AVATARINFO]: Servicing Avatar Query: " + (string) requestData["avquery"]); | ||
204 | return AvatarPickerListtoXmlRPCResponse(queryID, returnAvatar); | ||
205 | } | ||
206 | |||
207 | public XmlRpcResponse XmlRPCAtRegion(XmlRpcRequest request) | ||
208 | { | ||
209 | XmlRpcResponse response = new XmlRpcResponse(); | ||
210 | Hashtable requestData = (Hashtable) request.Params[0]; | ||
211 | Hashtable responseData = new Hashtable(); | ||
212 | string returnstring = "FALSE"; | ||
213 | |||
214 | if (requestData.Contains("avatar_id") && requestData.Contains("region_handle") && | ||
215 | requestData.Contains("region_uuid")) | ||
216 | { | ||
217 | // ulong cregionhandle = 0; | ||
218 | UUID regionUUID; | ||
219 | UUID avatarUUID; | ||
220 | |||
221 | UUID.TryParse((string) requestData["avatar_id"], out avatarUUID); | ||
222 | UUID.TryParse((string) requestData["region_uuid"], out regionUUID); | ||
223 | |||
224 | if (avatarUUID != UUID.Zero) | ||
225 | { | ||
226 | UserProfileData userProfile = m_userDataBaseService.GetUserProfile(avatarUUID); | ||
227 | userProfile.CurrentAgent.Region = regionUUID; | ||
228 | userProfile.CurrentAgent.Handle = (ulong) Convert.ToInt64((string) requestData["region_handle"]); | ||
229 | //userProfile.CurrentAgent. | ||
230 | m_userDataBaseService.CommitAgent(ref userProfile); | ||
231 | //setUserProfile(userProfile); | ||
232 | |||
233 | |||
234 | returnstring = "TRUE"; | ||
235 | } | ||
236 | } | ||
237 | responseData.Add("returnString", returnstring); | ||
238 | response.Value = responseData; | ||
239 | return response; | ||
240 | } | ||
241 | |||
242 | public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request) | ||
243 | { | ||
244 | // XmlRpcResponse response = new XmlRpcResponse(); | ||
245 | Hashtable requestData = (Hashtable) request.Params[0]; | ||
246 | UserProfileData userProfile; | ||
247 | if (requestData.Contains("avatar_name")) | ||
248 | { | ||
249 | string query = (string) requestData["avatar_name"]; | ||
250 | |||
251 | // Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]"); | ||
252 | |||
253 | string[] querysplit = query.Split(' '); | ||
254 | |||
255 | if (querysplit.Length == 2) | ||
256 | { | ||
257 | userProfile = m_userDataBaseService.GetUserProfile(querysplit[0], querysplit[1]); | ||
258 | if (userProfile == null) | ||
259 | { | ||
260 | return CreateUnknownUserErrorResponse(); | ||
261 | } | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | return CreateUnknownUserErrorResponse(); | ||
266 | } | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | return CreateUnknownUserErrorResponse(); | ||
271 | } | ||
272 | |||
273 | return ProfileToXmlRPCResponse(userProfile); | ||
274 | } | ||
275 | |||
276 | public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request) | ||
277 | { | ||
278 | // XmlRpcResponse response = new XmlRpcResponse(); | ||
279 | Hashtable requestData = (Hashtable) request.Params[0]; | ||
280 | UserProfileData userProfile; | ||
281 | //CFK: this clogs the UserServer log and is not necessary at this time. | ||
282 | //CFK: m_log.Debug("METHOD BY UUID CALLED"); | ||
283 | if (requestData.Contains("avatar_uuid")) | ||
284 | { | ||
285 | try | ||
286 | { | ||
287 | UUID guess = new UUID((string) requestData["avatar_uuid"]); | ||
288 | |||
289 | userProfile = m_userDataBaseService.GetUserProfile(guess); | ||
290 | } | ||
291 | catch (FormatException) | ||
292 | { | ||
293 | return CreateUnknownUserErrorResponse(); | ||
294 | } | ||
295 | |||
296 | if (userProfile == null) | ||
297 | { | ||
298 | return CreateUnknownUserErrorResponse(); | ||
299 | } | ||
300 | } | ||
301 | else | ||
302 | { | ||
303 | return CreateUnknownUserErrorResponse(); | ||
304 | } | ||
305 | |||
306 | return ProfileToXmlRPCResponse(userProfile); | ||
307 | } | ||
308 | |||
309 | public XmlRpcResponse XmlRPCGetAgentMethodUUID(XmlRpcRequest request) | ||
310 | { | ||
311 | XmlRpcResponse response = new XmlRpcResponse(); | ||
312 | Hashtable requestData = (Hashtable) request.Params[0]; | ||
313 | UserProfileData userProfile; | ||
314 | //CFK: this clogs the UserServer log and is not necessary at this time. | ||
315 | //CFK: m_log.Debug("METHOD BY UUID CALLED"); | ||
316 | if (requestData.Contains("avatar_uuid")) | ||
317 | { | ||
318 | UUID guess; | ||
319 | |||
320 | UUID.TryParse((string) requestData["avatar_uuid"], out guess); | ||
321 | |||
322 | if (guess == UUID.Zero) | ||
323 | { | ||
324 | return CreateUnknownUserErrorResponse(); | ||
325 | } | ||
326 | |||
327 | userProfile = m_userDataBaseService.GetUserProfile(guess); | ||
328 | |||
329 | if (userProfile == null) | ||
330 | { | ||
331 | return CreateUnknownUserErrorResponse(); | ||
332 | } | ||
333 | |||
334 | // no agent??? | ||
335 | if (userProfile.CurrentAgent == null) | ||
336 | { | ||
337 | return CreateUnknownUserErrorResponse(); | ||
338 | } | ||
339 | Hashtable responseData = new Hashtable(); | ||
340 | |||
341 | responseData["handle"] = userProfile.CurrentAgent.Handle.ToString(); | ||
342 | responseData["session"] = userProfile.CurrentAgent.SessionID.ToString(); | ||
343 | if (userProfile.CurrentAgent.AgentOnline) | ||
344 | responseData["agent_online"] = "TRUE"; | ||
345 | else | ||
346 | responseData["agent_online"] = "FALSE"; | ||
347 | |||
348 | response.Value = responseData; | ||
349 | } | ||
350 | else | ||
351 | { | ||
352 | return CreateUnknownUserErrorResponse(); | ||
353 | } | ||
354 | |||
355 | return response; | ||
356 | } | ||
357 | |||
358 | public XmlRpcResponse XmlRPCCheckAuthSession(XmlRpcRequest request) | ||
359 | { | ||
360 | XmlRpcResponse response = new XmlRpcResponse(); | ||
361 | Hashtable requestData = (Hashtable) request.Params[0]; | ||
362 | UserProfileData userProfile; | ||
363 | |||
364 | string authed = "FALSE"; | ||
365 | if (requestData.Contains("avatar_uuid") && requestData.Contains("session_id")) | ||
366 | { | ||
367 | UUID guess_aid; | ||
368 | UUID guess_sid; | ||
369 | |||
370 | UUID.TryParse((string) requestData["avatar_uuid"], out guess_aid); | ||
371 | if (guess_aid == UUID.Zero) | ||
372 | { | ||
373 | return CreateUnknownUserErrorResponse(); | ||
374 | } | ||
375 | UUID.TryParse((string) requestData["session_id"], out guess_sid); | ||
376 | if (guess_sid == UUID.Zero) | ||
377 | { | ||
378 | return CreateUnknownUserErrorResponse(); | ||
379 | } | ||
380 | userProfile = m_userDataBaseService.GetUserProfile(guess_aid); | ||
381 | if (userProfile != null && userProfile.CurrentAgent != null && | ||
382 | userProfile.CurrentAgent.SessionID == guess_sid) | ||
383 | { | ||
384 | authed = "TRUE"; | ||
385 | } | ||
386 | m_log.InfoFormat("[UserManager]: CheckAuthSession TRUE for user {0}", guess_aid); | ||
387 | } | ||
388 | else | ||
389 | { | ||
390 | m_log.InfoFormat("[UserManager]: CheckAuthSession FALSE"); | ||
391 | return CreateUnknownUserErrorResponse(); | ||
392 | } | ||
393 | Hashtable responseData = new Hashtable(); | ||
394 | responseData["auth_session"] = authed; | ||
395 | response.Value = responseData; | ||
396 | return response; | ||
397 | } | ||
398 | |||
399 | public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserProfile(XmlRpcRequest request) | ||
400 | { | ||
401 | m_log.Debug("[UserManager]: Got request to update user profile"); | ||
402 | XmlRpcResponse response = new XmlRpcResponse(); | ||
403 | Hashtable requestData = (Hashtable) request.Params[0]; | ||
404 | Hashtable responseData = new Hashtable(); | ||
405 | |||
406 | if (!requestData.Contains("avatar_uuid")) | ||
407 | { | ||
408 | return CreateUnknownUserErrorResponse(); | ||
409 | } | ||
410 | |||
411 | UUID UserUUID = new UUID((string) requestData["avatar_uuid"]); | ||
412 | UserProfileData userProfile = m_userDataBaseService.GetUserProfile(UserUUID); | ||
413 | if (null == userProfile) | ||
414 | { | ||
415 | return CreateUnknownUserErrorResponse(); | ||
416 | } | ||
417 | // don't know how yet. | ||
418 | if (requestData.Contains("AllowPublish")) | ||
419 | { | ||
420 | } | ||
421 | if (requestData.Contains("FLImageID")) | ||
422 | { | ||
423 | userProfile.FirstLifeImage = new UUID((string) requestData["FLImageID"]); | ||
424 | } | ||
425 | if (requestData.Contains("ImageID")) | ||
426 | { | ||
427 | userProfile.Image = new UUID((string) requestData["ImageID"]); | ||
428 | } | ||
429 | // dont' know how yet | ||
430 | if (requestData.Contains("MaturePublish")) | ||
431 | { | ||
432 | } | ||
433 | if (requestData.Contains("AboutText")) | ||
434 | { | ||
435 | userProfile.AboutText = (string) requestData["AboutText"]; | ||
436 | } | ||
437 | if (requestData.Contains("FLAboutText")) | ||
438 | { | ||
439 | userProfile.FirstLifeAboutText = (string) requestData["FLAboutText"]; | ||
440 | } | ||
441 | // not in DB yet. | ||
442 | if (requestData.Contains("ProfileURL")) | ||
443 | { | ||
444 | } | ||
445 | if (requestData.Contains("home_region")) | ||
446 | { | ||
447 | try | ||
448 | { | ||
449 | userProfile.HomeRegion = Convert.ToUInt64((string) requestData["home_region"]); | ||
450 | } | ||
451 | catch (ArgumentException) | ||
452 | { | ||
453 | m_log.Error("[PROFILE]:Failed to set home region, Invalid Argument"); | ||
454 | } | ||
455 | catch (FormatException) | ||
456 | { | ||
457 | m_log.Error("[PROFILE]:Failed to set home region, Invalid Format"); | ||
458 | } | ||
459 | catch (OverflowException) | ||
460 | { | ||
461 | m_log.Error("[PROFILE]:Failed to set home region, Value was too large"); | ||
462 | } | ||
463 | } | ||
464 | if (requestData.Contains("home_region_id")) | ||
465 | { | ||
466 | UUID regionID; | ||
467 | UUID.TryParse((string) requestData["home_region_id"], out regionID); | ||
468 | userProfile.HomeRegionID = regionID; | ||
469 | } | ||
470 | if (requestData.Contains("home_pos_x")) | ||
471 | { | ||
472 | try | ||
473 | { | ||
474 | userProfile.HomeLocationX = (float) Convert.ToDecimal((string) requestData["home_pos_x"]); | ||
475 | } | ||
476 | catch (InvalidCastException) | ||
477 | { | ||
478 | m_log.Error("[PROFILE]:Failed to set home postion x"); | ||
479 | } | ||
480 | } | ||
481 | if (requestData.Contains("home_pos_y")) | ||
482 | { | ||
483 | try | ||
484 | { | ||
485 | userProfile.HomeLocationY = (float) Convert.ToDecimal((string) requestData["home_pos_y"]); | ||
486 | } | ||
487 | catch (InvalidCastException) | ||
488 | { | ||
489 | m_log.Error("[PROFILE]:Failed to set home postion y"); | ||
490 | } | ||
491 | } | ||
492 | if (requestData.Contains("home_pos_z")) | ||
493 | { | ||
494 | try | ||
495 | { | ||
496 | userProfile.HomeLocationZ = (float) Convert.ToDecimal((string) requestData["home_pos_z"]); | ||
497 | } | ||
498 | catch (InvalidCastException) | ||
499 | { | ||
500 | m_log.Error("[PROFILE]:Failed to set home postion z"); | ||
501 | } | ||
502 | } | ||
503 | if (requestData.Contains("home_look_x")) | ||
504 | { | ||
505 | try | ||
506 | { | ||
507 | userProfile.HomeLookAtX = (float) Convert.ToDecimal((string) requestData["home_look_x"]); | ||
508 | } | ||
509 | catch (InvalidCastException) | ||
510 | { | ||
511 | m_log.Error("[PROFILE]:Failed to set home lookat x"); | ||
512 | } | ||
513 | } | ||
514 | if (requestData.Contains("home_look_y")) | ||
515 | { | ||
516 | try | ||
517 | { | ||
518 | userProfile.HomeLookAtY = (float) Convert.ToDecimal((string) requestData["home_look_y"]); | ||
519 | } | ||
520 | catch (InvalidCastException) | ||
521 | { | ||
522 | m_log.Error("[PROFILE]:Failed to set home lookat y"); | ||
523 | } | ||
524 | } | ||
525 | if (requestData.Contains("home_look_z")) | ||
526 | { | ||
527 | try | ||
528 | { | ||
529 | userProfile.HomeLookAtZ = (float) Convert.ToDecimal((string) requestData["home_look_z"]); | ||
530 | } | ||
531 | catch (InvalidCastException) | ||
532 | { | ||
533 | m_log.Error("[PROFILE]:Failed to set home lookat z"); | ||
534 | } | ||
535 | } | ||
536 | if (requestData.Contains("user_flags")) | ||
537 | { | ||
538 | try | ||
539 | { | ||
540 | userProfile.UserFlags = Convert.ToInt32((string) requestData["user_flags"]); | ||
541 | } | ||
542 | catch (InvalidCastException) | ||
543 | { | ||
544 | m_log.Error("[PROFILE]:Failed to set user flags"); | ||
545 | } | ||
546 | } | ||
547 | if (requestData.Contains("god_level")) | ||
548 | { | ||
549 | try | ||
550 | { | ||
551 | userProfile.GodLevel = Convert.ToInt32((string) requestData["god_level"]); | ||
552 | } | ||
553 | catch (InvalidCastException) | ||
554 | { | ||
555 | m_log.Error("[PROFILE]:Failed to set god level"); | ||
556 | } | ||
557 | } | ||
558 | if (requestData.Contains("custom_type")) | ||
559 | { | ||
560 | try | ||
561 | { | ||
562 | userProfile.CustomType = (string) requestData["custom_type"]; | ||
563 | } | ||
564 | catch (InvalidCastException) | ||
565 | { | ||
566 | m_log.Error("[PROFILE]:Failed to set custom type"); | ||
567 | } | ||
568 | } | ||
569 | if (requestData.Contains("partner")) | ||
570 | { | ||
571 | try | ||
572 | { | ||
573 | userProfile.Partner = new UUID((string) requestData["partner"]); | ||
574 | } | ||
575 | catch (InvalidCastException) | ||
576 | { | ||
577 | m_log.Error("[PROFILE]:Failed to set partner"); | ||
578 | } | ||
579 | } | ||
580 | else | ||
581 | { | ||
582 | userProfile.Partner = UUID.Zero; | ||
583 | } | ||
584 | |||
585 | // call plugin! | ||
586 | bool ret = m_userDataBaseService.UpdateUserProfile(userProfile); | ||
587 | responseData["returnString"] = ret.ToString(); | ||
588 | response.Value = responseData; | ||
589 | return response; | ||
590 | } | ||
591 | |||
592 | public XmlRpcResponse XmlRPCLogOffUserMethodUUID(XmlRpcRequest request) | ||
593 | { | ||
594 | XmlRpcResponse response = new XmlRpcResponse(); | ||
595 | Hashtable requestData = (Hashtable) request.Params[0]; | ||
596 | |||
597 | if (requestData.Contains("avatar_uuid")) | ||
598 | { | ||
599 | try | ||
600 | { | ||
601 | UUID userUUID = new UUID((string)requestData["avatar_uuid"]); | ||
602 | UUID RegionID = new UUID((string)requestData["region_uuid"]); | ||
603 | ulong regionhandle = (ulong)Convert.ToInt64((string)requestData["region_handle"]); | ||
604 | Vector3 position = new Vector3( | ||
605 | (float)Convert.ToDecimal((string)requestData["region_pos_x"]), | ||
606 | (float)Convert.ToDecimal((string)requestData["region_pos_y"]), | ||
607 | (float)Convert.ToDecimal((string)requestData["region_pos_z"])); | ||
608 | Vector3 lookat = new Vector3( | ||
609 | (float)Convert.ToDecimal((string)requestData["lookat_x"]), | ||
610 | (float)Convert.ToDecimal((string)requestData["lookat_y"]), | ||
611 | (float)Convert.ToDecimal((string)requestData["lookat_z"])); | ||
612 | |||
613 | handlerLogOffUser = OnLogOffUser; | ||
614 | if (handlerLogOffUser != null) | ||
615 | handlerLogOffUser(userUUID); | ||
616 | |||
617 | m_userDataBaseService.LogOffUser(userUUID, RegionID, regionhandle, position, lookat); | ||
618 | } | ||
619 | catch (FormatException) | ||
620 | { | ||
621 | m_log.Warn("[LOGOUT]: Error in Logout XMLRPC Params"); | ||
622 | return response; | ||
623 | } | ||
624 | } | ||
625 | else | ||
626 | { | ||
627 | return CreateUnknownUserErrorResponse(); | ||
628 | } | ||
629 | |||
630 | return response; | ||
631 | } | ||
632 | |||
633 | #endregion | ||
634 | |||
635 | |||
636 | public void HandleAgentLocation(UUID agentID, UUID regionID, ulong regionHandle) | ||
637 | { | ||
638 | UserProfileData userProfile = m_userDataBaseService.GetUserProfile(agentID); | ||
639 | if (userProfile != null) | ||
640 | { | ||
641 | userProfile.CurrentAgent.Region = regionID; | ||
642 | userProfile.CurrentAgent.Handle = regionHandle; | ||
643 | m_userDataBaseService.CommitAgent(ref userProfile); | ||
644 | } | ||
645 | } | ||
646 | |||
647 | public void HandleAgentLeaving(UUID agentID, UUID regionID, ulong regionHandle) | ||
648 | { | ||
649 | UserProfileData userProfile = m_userDataBaseService.GetUserProfile(agentID); | ||
650 | if (userProfile != null) | ||
651 | { | ||
652 | if (userProfile.CurrentAgent.Region == regionID) | ||
653 | { | ||
654 | UserAgentData userAgent = userProfile.CurrentAgent; | ||
655 | if (userAgent != null && userAgent.AgentOnline) | ||
656 | { | ||
657 | userAgent.AgentOnline = false; | ||
658 | userAgent.LogoutTime = Util.UnixTimeSinceEpoch(); | ||
659 | if (regionID != UUID.Zero) | ||
660 | { | ||
661 | userAgent.Region = regionID; | ||
662 | } | ||
663 | userAgent.Handle = regionHandle; | ||
664 | userProfile.LastLogin = userAgent.LogoutTime; | ||
665 | |||
666 | m_userDataBaseService.CommitAgent(ref userProfile); | ||
667 | |||
668 | handlerLogOffUser = OnLogOffUser; | ||
669 | if (handlerLogOffUser != null) | ||
670 | handlerLogOffUser(agentID); | ||
671 | } | ||
672 | } | ||
673 | } | ||
674 | } | ||
675 | |||
676 | public void HandleRegionStartup(UUID regionID) | ||
677 | { | ||
678 | m_userDataBaseService.LogoutUsers(regionID); | ||
679 | } | ||
680 | |||
681 | public void HandleRegionShutdown(UUID regionID) | ||
682 | { | ||
683 | m_userDataBaseService.LogoutUsers(regionID); | ||
684 | } | ||
685 | } | ||
686 | } | ||
diff --git a/OpenSim/Grid/UserServer/UserServerAvatarAppearanceModule.cs b/OpenSim/Grid/UserServer/UserServerAvatarAppearanceModule.cs deleted file mode 100644 index 28ac2dc..0000000 --- a/OpenSim/Grid/UserServer/UserServerAvatarAppearanceModule.cs +++ /dev/null | |||
@@ -1,124 +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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nwc.XmlRpc; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Communications; | ||
37 | using OpenSim.Framework.Servers; | ||
38 | |||
39 | namespace OpenSim.Grid.UserServer | ||
40 | { | ||
41 | public class UserServerAvatarAppearanceModule | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private UserDataBaseService m_userDataBaseService; | ||
46 | private BaseHttpServer m_httpServer; | ||
47 | |||
48 | public UserServerAvatarAppearanceModule(UserDataBaseService userDataBaseService) | ||
49 | { | ||
50 | m_userDataBaseService = userDataBaseService; | ||
51 | } | ||
52 | |||
53 | public void Initialise() | ||
54 | { | ||
55 | |||
56 | } | ||
57 | |||
58 | public void PostInitialise() | ||
59 | { | ||
60 | |||
61 | } | ||
62 | |||
63 | public void RegisterHandlers(BaseHttpServer httpServer) | ||
64 | { | ||
65 | m_httpServer = httpServer; | ||
66 | |||
67 | m_httpServer.AddXmlRPCHandler("get_avatar_appearance", XmlRPCGetAvatarAppearance); | ||
68 | m_httpServer.AddXmlRPCHandler("update_avatar_appearance", XmlRPCUpdateAvatarAppearance); | ||
69 | } | ||
70 | |||
71 | public XmlRpcResponse XmlRPCGetAvatarAppearance(XmlRpcRequest request) | ||
72 | { | ||
73 | XmlRpcResponse response = new XmlRpcResponse(); | ||
74 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
75 | AvatarAppearance appearance; | ||
76 | Hashtable responseData; | ||
77 | if (requestData.Contains("owner")) | ||
78 | { | ||
79 | appearance = m_userDataBaseService.GetUserAppearance(new UUID((string)requestData["owner"])); | ||
80 | if (appearance == null) | ||
81 | { | ||
82 | responseData = new Hashtable(); | ||
83 | responseData["error_type"] = "no appearance"; | ||
84 | responseData["error_desc"] = "There was no appearance found for this avatar"; | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | responseData = appearance.ToHashTable(); | ||
89 | } | ||
90 | } | ||
91 | else | ||
92 | { | ||
93 | responseData = new Hashtable(); | ||
94 | responseData["error_type"] = "unknown_avatar"; | ||
95 | responseData["error_desc"] = "The avatar appearance requested is not in the database"; | ||
96 | } | ||
97 | |||
98 | response.Value = responseData; | ||
99 | return response; | ||
100 | } | ||
101 | |||
102 | public XmlRpcResponse XmlRPCUpdateAvatarAppearance(XmlRpcRequest request) | ||
103 | { | ||
104 | XmlRpcResponse response = new XmlRpcResponse(); | ||
105 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
106 | Hashtable responseData; | ||
107 | if (requestData.Contains("owner")) | ||
108 | { | ||
109 | AvatarAppearance appearance = new AvatarAppearance(requestData); | ||
110 | m_userDataBaseService.UpdateUserAppearance(new UUID((string)requestData["owner"]), appearance); | ||
111 | responseData = new Hashtable(); | ||
112 | responseData["returnString"] = "TRUE"; | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | responseData = new Hashtable(); | ||
117 | responseData["error_type"] = "unknown_avatar"; | ||
118 | responseData["error_desc"] = "The avatar appearance requested is not in the database"; | ||
119 | } | ||
120 | response.Value = responseData; | ||
121 | return response; | ||
122 | } | ||
123 | } | ||
124 | } | ||
diff --git a/OpenSim/Grid/UserServer/UserServerCommandModule.cs b/OpenSim/Grid/UserServer/UserServerCommandModule.cs new file mode 100644 index 0000000..fbdd73f --- /dev/null +++ b/OpenSim/Grid/UserServer/UserServerCommandModule.cs | |||
@@ -0,0 +1,349 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using log4net.Config; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Data; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Communications; | ||
38 | using OpenSim.Framework.Communications.Cache; | ||
39 | using OpenSim.Framework.Console; | ||
40 | using OpenSim.Framework.Servers; | ||
41 | using OpenSim.Framework.Statistics; | ||
42 | using OpenSim.Grid.Communications.OGS1; | ||
43 | using OpenSim.Grid.Framework; | ||
44 | using OpenSim.Grid.UserServer.Modules; | ||
45 | |||
46 | namespace OpenSim.Grid.UserServer | ||
47 | { | ||
48 | public class UserServerCommandModule | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | protected ConsoleBase m_console; | ||
53 | protected UserConfig Cfg; | ||
54 | |||
55 | protected UserDataBaseService m_userDataBaseService; | ||
56 | protected UserLoginService m_loginService; | ||
57 | |||
58 | private UUID m_lastCreatedUser = UUID.Random(); | ||
59 | |||
60 | public UserServerCommandModule(ConsoleBase console, UserConfig cfg, UserDataBaseService userDBservice, UserLoginService loginService) | ||
61 | { | ||
62 | m_console = console; | ||
63 | Cfg = cfg; | ||
64 | m_userDataBaseService = userDBservice; | ||
65 | m_loginService = loginService; | ||
66 | } | ||
67 | |||
68 | public virtual void RegisterConsoleCommands() | ||
69 | { | ||
70 | m_console.Commands.AddCommand("userserver", false, "create user", | ||
71 | "create user [<first> [<last> [<x> <y> [email]]]]", | ||
72 | "Create a new user account", RunCommand); | ||
73 | |||
74 | m_console.Commands.AddCommand("userserver", false, "reset user password", | ||
75 | "reset user password [<first> [<last> [<new password>]]]", | ||
76 | "Reset a user's password", RunCommand); | ||
77 | |||
78 | m_console.Commands.AddCommand("userserver", false, "login level", | ||
79 | "login level <level>", | ||
80 | "Set the minimum user level to log in", HandleLoginCommand); | ||
81 | |||
82 | m_console.Commands.AddCommand("userserver", false, "login reset", | ||
83 | "login reset", | ||
84 | "Reset the login level to allow all users", | ||
85 | HandleLoginCommand); | ||
86 | |||
87 | m_console.Commands.AddCommand("userserver", false, "login text", | ||
88 | "login text <text>", | ||
89 | "Set the text users will see on login", HandleLoginCommand); | ||
90 | |||
91 | m_console.Commands.AddCommand("userserver", false, "test-inventory", | ||
92 | "test-inventory", | ||
93 | "Perform a test inventory transaction", RunCommand); | ||
94 | |||
95 | m_console.Commands.AddCommand("userserver", false, "logoff-user", | ||
96 | "logoff-user <first> <last> <message>", | ||
97 | "Log off a named user", RunCommand); | ||
98 | |||
99 | m_console.Commands.AddCommand("userserver", false, "test-command", | ||
100 | "test-command", | ||
101 | "test command", HandleTestCommand); | ||
102 | } | ||
103 | |||
104 | #region Console Command Handlers | ||
105 | public void do_create(string[] args) | ||
106 | { | ||
107 | switch (args[0]) | ||
108 | { | ||
109 | case "user": | ||
110 | CreateUser(args); | ||
111 | break; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | /// <summary> | ||
116 | /// Execute switch for some of the reset commands | ||
117 | /// </summary> | ||
118 | /// <param name="args"></param> | ||
119 | protected void Reset(string[] args) | ||
120 | { | ||
121 | if (args.Length == 0) | ||
122 | return; | ||
123 | |||
124 | switch (args[0]) | ||
125 | { | ||
126 | case "user": | ||
127 | |||
128 | switch (args[1]) | ||
129 | { | ||
130 | case "password": | ||
131 | ResetUserPassword(args); | ||
132 | break; | ||
133 | } | ||
134 | |||
135 | break; | ||
136 | } | ||
137 | } | ||
138 | |||
139 | /// <summary> | ||
140 | /// Create a new user | ||
141 | /// </summary> | ||
142 | /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param> | ||
143 | protected void CreateUser(string[] cmdparams) | ||
144 | { | ||
145 | string firstName; | ||
146 | string lastName; | ||
147 | string password; | ||
148 | string email; | ||
149 | uint regX = 1000; | ||
150 | uint regY = 1000; | ||
151 | |||
152 | if (cmdparams.Length < 2) | ||
153 | firstName = MainConsole.Instance.CmdPrompt("First name", "Default"); | ||
154 | else firstName = cmdparams[1]; | ||
155 | |||
156 | if (cmdparams.Length < 3) | ||
157 | lastName = MainConsole.Instance.CmdPrompt("Last name", "User"); | ||
158 | else lastName = cmdparams[2]; | ||
159 | |||
160 | if (cmdparams.Length < 4) | ||
161 | password = MainConsole.Instance.PasswdPrompt("Password"); | ||
162 | else password = cmdparams[3]; | ||
163 | |||
164 | if (cmdparams.Length < 5) | ||
165 | regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString())); | ||
166 | else regX = Convert.ToUInt32(cmdparams[4]); | ||
167 | |||
168 | if (cmdparams.Length < 6) | ||
169 | regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString())); | ||
170 | else regY = Convert.ToUInt32(cmdparams[5]); | ||
171 | |||
172 | if (cmdparams.Length < 7) | ||
173 | email = MainConsole.Instance.CmdPrompt("Email", ""); | ||
174 | else email = cmdparams[6]; | ||
175 | |||
176 | if (null == m_userDataBaseService.GetUserProfile(firstName, lastName)) | ||
177 | { | ||
178 | m_lastCreatedUser = m_userDataBaseService.AddUser(firstName, lastName, password, email, regX, regY); | ||
179 | } | ||
180 | else | ||
181 | { | ||
182 | m_log.ErrorFormat("[USERS]: A user with the name {0} {1} already exists!", firstName, lastName); | ||
183 | } | ||
184 | } | ||
185 | |||
186 | /// <summary> | ||
187 | /// Reset a user password. | ||
188 | /// </summary> | ||
189 | /// <param name="cmdparams"></param> | ||
190 | private void ResetUserPassword(string[] cmdparams) | ||
191 | { | ||
192 | string firstName; | ||
193 | string lastName; | ||
194 | string newPassword; | ||
195 | |||
196 | if (cmdparams.Length < 3) | ||
197 | firstName = MainConsole.Instance.CmdPrompt("First name"); | ||
198 | else firstName = cmdparams[2]; | ||
199 | |||
200 | if (cmdparams.Length < 4) | ||
201 | lastName = MainConsole.Instance.CmdPrompt("Last name"); | ||
202 | else lastName = cmdparams[3]; | ||
203 | |||
204 | if (cmdparams.Length < 5) | ||
205 | newPassword = MainConsole.Instance.PasswdPrompt("New password"); | ||
206 | else newPassword = cmdparams[4]; | ||
207 | |||
208 | m_userDataBaseService.ResetUserPassword(firstName, lastName, newPassword); | ||
209 | } | ||
210 | |||
211 | private void HandleTestCommand(string module, string[] cmd) | ||
212 | { | ||
213 | m_log.Info("test command received"); | ||
214 | } | ||
215 | |||
216 | private void HandleLoginCommand(string module, string[] cmd) | ||
217 | { | ||
218 | string subcommand = cmd[1]; | ||
219 | |||
220 | switch (subcommand) | ||
221 | { | ||
222 | case "level": | ||
223 | // Set the minimal level to allow login | ||
224 | // Useful to allow grid update without worrying about users. | ||
225 | // or fixing critical issues | ||
226 | // | ||
227 | if (cmd.Length > 2) | ||
228 | { | ||
229 | int level = Convert.ToInt32(cmd[2]); | ||
230 | m_loginService.setloginlevel(level); | ||
231 | } | ||
232 | break; | ||
233 | case "reset": | ||
234 | m_loginService.setloginlevel(0); | ||
235 | break; | ||
236 | case "text": | ||
237 | if (cmd.Length > 2) | ||
238 | { | ||
239 | m_loginService.setwelcometext(cmd[2]); | ||
240 | } | ||
241 | break; | ||
242 | } | ||
243 | } | ||
244 | |||
245 | public void RunCommand(string module, string[] cmd) | ||
246 | { | ||
247 | List<string> args = new List<string>(cmd); | ||
248 | string command = cmd[0]; | ||
249 | |||
250 | args.RemoveAt(0); | ||
251 | |||
252 | string[] cmdparams = args.ToArray(); | ||
253 | |||
254 | switch (command) | ||
255 | { | ||
256 | case "create": | ||
257 | do_create(cmdparams); | ||
258 | break; | ||
259 | |||
260 | case "reset": | ||
261 | Reset(cmdparams); | ||
262 | break; | ||
263 | |||
264 | |||
265 | case "test-inventory": | ||
266 | // RestObjectPosterResponse<List<InventoryFolderBase>> requester = new RestObjectPosterResponse<List<InventoryFolderBase>>(); | ||
267 | // requester.ReturnResponseVal = TestResponse; | ||
268 | // requester.BeginPostObject<UUID>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser); | ||
269 | SynchronousRestObjectPoster.BeginPostObject<UUID, List<InventoryFolderBase>>( | ||
270 | "POST", Cfg.InventoryUrl + "RootFolders/", m_lastCreatedUser); | ||
271 | break; | ||
272 | |||
273 | case "logoff-user": | ||
274 | if (cmdparams.Length >= 3) | ||
275 | { | ||
276 | string firstname = cmdparams[0]; | ||
277 | string lastname = cmdparams[1]; | ||
278 | string message = ""; | ||
279 | |||
280 | for (int i = 2; i < cmdparams.Length; i++) | ||
281 | message += " " + cmdparams[i]; | ||
282 | |||
283 | UserProfileData theUser = null; | ||
284 | try | ||
285 | { | ||
286 | theUser = m_loginService.GetTheUser(firstname, lastname); | ||
287 | } | ||
288 | catch (Exception) | ||
289 | { | ||
290 | m_log.Error("[LOGOFF]: Error getting user data from the database."); | ||
291 | } | ||
292 | |||
293 | if (theUser != null) | ||
294 | { | ||
295 | if (theUser.CurrentAgent != null) | ||
296 | { | ||
297 | if (theUser.CurrentAgent.AgentOnline) | ||
298 | { | ||
299 | m_log.Info("[LOGOFF]: Logging off requested user!"); | ||
300 | m_loginService.LogOffUser(theUser, message); | ||
301 | |||
302 | theUser.CurrentAgent.AgentOnline = false; | ||
303 | |||
304 | m_loginService.CommitAgent(ref theUser); | ||
305 | } | ||
306 | else | ||
307 | { | ||
308 | m_log.Info( | ||
309 | "[LOGOFF]: User Doesn't appear to be online, sending the logoff message anyway."); | ||
310 | m_loginService.LogOffUser(theUser, message); | ||
311 | |||
312 | theUser.CurrentAgent.AgentOnline = false; | ||
313 | |||
314 | m_loginService.CommitAgent(ref theUser); | ||
315 | } | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | m_log.Error( | ||
320 | "[LOGOFF]: Unable to logoff-user. User doesn't have an agent record so I can't find the simulator to notify"); | ||
321 | } | ||
322 | } | ||
323 | else | ||
324 | { | ||
325 | m_log.Info("[LOGOFF]: User doesn't exist in the database"); | ||
326 | } | ||
327 | } | ||
328 | else | ||
329 | { | ||
330 | m_log.Error( | ||
331 | "[LOGOFF]: Invalid amount of parameters. logoff-user takes at least three. Firstname, Lastname, and message"); | ||
332 | } | ||
333 | |||
334 | break; | ||
335 | } | ||
336 | } | ||
337 | |||
338 | public virtual void ShowHelp(string[] helpArgs) | ||
339 | { | ||
340 | m_console.Notice("create user - create a new user"); | ||
341 | m_console.Notice("logoff-user <firstname> <lastname> <message> - logs off the specified user from the grid"); | ||
342 | m_console.Notice("reset user password - reset a user's password."); | ||
343 | m_console.Notice("login-level <value> - Set the miminim userlevel allowed To login."); | ||
344 | m_console.Notice("login-reset - reset the login level to its default value."); | ||
345 | m_console.Notice("login-text <text to print during the login>"); | ||
346 | } | ||
347 | } | ||
348 | #endregion | ||
349 | } | ||
diff --git a/OpenSim/Grid/UserServer/UserServerFriendsModule.cs b/OpenSim/Grid/UserServer/UserServerFriendsModule.cs deleted file mode 100644 index 4a3efe0..0000000 --- a/OpenSim/Grid/UserServer/UserServerFriendsModule.cs +++ /dev/null | |||
@@ -1,173 +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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nwc.XmlRpc; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Communications; | ||
37 | using OpenSim.Framework.Servers; | ||
38 | |||
39 | namespace OpenSim.Grid.UserServer | ||
40 | { | ||
41 | public class UserServerFriendsModule | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private UserDataBaseService m_userDataBaseService; | ||
46 | |||
47 | private BaseHttpServer m_httpServer; | ||
48 | |||
49 | public UserServerFriendsModule(UserDataBaseService userDataBaseService) | ||
50 | { | ||
51 | m_userDataBaseService = userDataBaseService; | ||
52 | } | ||
53 | |||
54 | public void Initialise() | ||
55 | { | ||
56 | |||
57 | } | ||
58 | |||
59 | public void PostInitialise() | ||
60 | { | ||
61 | |||
62 | } | ||
63 | |||
64 | public void RegisterHandlers(BaseHttpServer httpServer) | ||
65 | { | ||
66 | m_httpServer = httpServer; | ||
67 | |||
68 | m_httpServer.AddXmlRPCHandler("add_new_user_friend", XmlRpcResponseXmlRPCAddUserFriend); | ||
69 | m_httpServer.AddXmlRPCHandler("remove_user_friend", XmlRpcResponseXmlRPCRemoveUserFriend); | ||
70 | m_httpServer.AddXmlRPCHandler("update_user_friend_perms", XmlRpcResponseXmlRPCUpdateUserFriendPerms); | ||
71 | m_httpServer.AddXmlRPCHandler("get_user_friend_list", XmlRpcResponseXmlRPCGetUserFriendList); | ||
72 | } | ||
73 | |||
74 | public XmlRpcResponse FriendListItemListtoXmlRPCResponse(List<FriendListItem> returnUsers) | ||
75 | { | ||
76 | XmlRpcResponse response = new XmlRpcResponse(); | ||
77 | Hashtable responseData = new Hashtable(); | ||
78 | // Query Result Information | ||
79 | |||
80 | responseData["avcount"] = returnUsers.Count.ToString(); | ||
81 | |||
82 | for (int i = 0; i < returnUsers.Count; i++) | ||
83 | { | ||
84 | responseData["ownerID" + i] = returnUsers[i].FriendListOwner.ToString(); | ||
85 | responseData["friendID" + i] = returnUsers[i].Friend.ToString(); | ||
86 | responseData["ownerPerms" + i] = returnUsers[i].FriendListOwnerPerms.ToString(); | ||
87 | responseData["friendPerms" + i] = returnUsers[i].FriendPerms.ToString(); | ||
88 | } | ||
89 | response.Value = responseData; | ||
90 | |||
91 | return response; | ||
92 | } | ||
93 | |||
94 | public XmlRpcResponse XmlRpcResponseXmlRPCAddUserFriend(XmlRpcRequest request) | ||
95 | { | ||
96 | XmlRpcResponse response = new XmlRpcResponse(); | ||
97 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
98 | Hashtable responseData = new Hashtable(); | ||
99 | string returnString = "FALSE"; | ||
100 | // Query Result Information | ||
101 | |||
102 | if (requestData.Contains("ownerID") && requestData.Contains("friendID") && | ||
103 | requestData.Contains("friendPerms")) | ||
104 | { | ||
105 | // UserManagerBase.AddNewuserFriend | ||
106 | m_userDataBaseService.AddNewUserFriend(new UUID((string)requestData["ownerID"]), | ||
107 | new UUID((string)requestData["friendID"]), | ||
108 | (uint)Convert.ToInt32((string)requestData["friendPerms"])); | ||
109 | returnString = "TRUE"; | ||
110 | } | ||
111 | responseData["returnString"] = returnString; | ||
112 | response.Value = responseData; | ||
113 | return response; | ||
114 | } | ||
115 | |||
116 | public XmlRpcResponse XmlRpcResponseXmlRPCRemoveUserFriend(XmlRpcRequest request) | ||
117 | { | ||
118 | XmlRpcResponse response = new XmlRpcResponse(); | ||
119 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
120 | Hashtable responseData = new Hashtable(); | ||
121 | string returnString = "FALSE"; | ||
122 | // Query Result Information | ||
123 | |||
124 | if (requestData.Contains("ownerID") && requestData.Contains("friendID")) | ||
125 | { | ||
126 | // UserManagerBase.AddNewuserFriend | ||
127 | m_userDataBaseService.RemoveUserFriend(new UUID((string)requestData["ownerID"]), | ||
128 | new UUID((string)requestData["friendID"])); | ||
129 | returnString = "TRUE"; | ||
130 | } | ||
131 | responseData["returnString"] = returnString; | ||
132 | response.Value = responseData; | ||
133 | return response; | ||
134 | } | ||
135 | |||
136 | public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserFriendPerms(XmlRpcRequest request) | ||
137 | { | ||
138 | XmlRpcResponse response = new XmlRpcResponse(); | ||
139 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
140 | Hashtable responseData = new Hashtable(); | ||
141 | string returnString = "FALSE"; | ||
142 | |||
143 | if (requestData.Contains("ownerID") && requestData.Contains("friendID") && | ||
144 | requestData.Contains("friendPerms")) | ||
145 | { | ||
146 | m_userDataBaseService.UpdateUserFriendPerms(new UUID((string)requestData["ownerID"]), | ||
147 | new UUID((string)requestData["friendID"]), | ||
148 | (uint)Convert.ToInt32((string)requestData["friendPerms"])); | ||
149 | // UserManagerBase. | ||
150 | returnString = "TRUE"; | ||
151 | } | ||
152 | responseData["returnString"] = returnString; | ||
153 | response.Value = responseData; | ||
154 | return response; | ||
155 | } | ||
156 | |||
157 | public XmlRpcResponse XmlRpcResponseXmlRPCGetUserFriendList(XmlRpcRequest request) | ||
158 | { | ||
159 | // XmlRpcResponse response = new XmlRpcResponse(); | ||
160 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
161 | // Hashtable responseData = new Hashtable(); | ||
162 | |||
163 | List<FriendListItem> returndata = new List<FriendListItem>(); | ||
164 | |||
165 | if (requestData.Contains("ownerID")) | ||
166 | { | ||
167 | returndata = m_userDataBaseService.GetUserFriendList(new UUID((string)requestData["ownerID"])); | ||
168 | } | ||
169 | |||
170 | return FriendListItemListtoXmlRPCResponse(returndata); | ||
171 | } | ||
172 | } | ||
173 | } | ||