diff options
author | Diva Canto | 2010-01-10 20:17:37 -0800 |
---|---|---|
committer | Diva Canto | 2010-01-10 20:17:37 -0800 |
commit | 5cf6d6fa79dada85bd56530551409809d338b7d2 (patch) | |
tree | 24f89393fc9b25f138caed27919800230dafe70d /OpenSim/Grid/UserServer/UserServerCommandModule.cs | |
parent | OpenSim.Region.Communications.* is no more. Thanks to everyone who contribute... (diff) | |
download | opensim-SC_OLD-5cf6d6fa79dada85bd56530551409809d338b7d2.zip opensim-SC_OLD-5cf6d6fa79dada85bd56530551409809d338b7d2.tar.gz opensim-SC_OLD-5cf6d6fa79dada85bd56530551409809d338b7d2.tar.bz2 opensim-SC_OLD-5cf6d6fa79dada85bd56530551409809d338b7d2.tar.xz |
All grid servers deleted, including user server. They served us well.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Grid/UserServer/UserServerCommandModule.cs | 375 |
1 files changed, 0 insertions, 375 deletions
diff --git a/OpenSim/Grid/UserServer/UserServerCommandModule.cs b/OpenSim/Grid/UserServer/UserServerCommandModule.cs deleted file mode 100644 index cca410e..0000000 --- a/OpenSim/Grid/UserServer/UserServerCommandModule.cs +++ /dev/null | |||
@@ -1,375 +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.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.Servers.HttpServer; | ||
42 | using OpenSim.Framework.Statistics; | ||
43 | using OpenSim.Grid.Communications.OGS1; | ||
44 | using OpenSim.Grid.Framework; | ||
45 | using OpenSim.Grid.UserServer.Modules; | ||
46 | |||
47 | namespace OpenSim.Grid.UserServer | ||
48 | { | ||
49 | public class UserServerCommandModule | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | protected CommandConsole m_console; | ||
54 | protected UserConfig m_cfg; | ||
55 | |||
56 | protected UserDataBaseService m_userDataBaseService; | ||
57 | protected UserLoginService m_loginService; | ||
58 | |||
59 | protected UUID m_lastCreatedUser = UUID.Random(); | ||
60 | |||
61 | protected IGridServiceCore m_core; | ||
62 | |||
63 | public UserServerCommandModule() | ||
64 | { | ||
65 | } | ||
66 | |||
67 | public void Initialise(IGridServiceCore core) | ||
68 | { | ||
69 | m_core = core; | ||
70 | } | ||
71 | |||
72 | public void PostInitialise() | ||
73 | { | ||
74 | UserConfig cfg; | ||
75 | if (m_core.TryGet<UserConfig>(out cfg)) | ||
76 | { | ||
77 | m_cfg = cfg; | ||
78 | } | ||
79 | |||
80 | UserDataBaseService userDBservice; | ||
81 | if (m_core.TryGet<UserDataBaseService>(out userDBservice)) | ||
82 | { | ||
83 | m_userDataBaseService = userDBservice; | ||
84 | } | ||
85 | |||
86 | UserLoginService loginService; | ||
87 | if (m_core.TryGet<UserLoginService>(out loginService)) | ||
88 | { | ||
89 | m_loginService = loginService; | ||
90 | } | ||
91 | |||
92 | CommandConsole console; | ||
93 | if ((m_core.TryGet<CommandConsole>(out console)) && (m_cfg != null) | ||
94 | && (m_userDataBaseService != null) && (m_loginService != null)) | ||
95 | { | ||
96 | RegisterConsoleCommands(console); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | public void RegisterHandlers(BaseHttpServer httpServer) | ||
101 | { | ||
102 | |||
103 | } | ||
104 | |||
105 | private void RegisterConsoleCommands(CommandConsole console) | ||
106 | { | ||
107 | m_console = console; | ||
108 | m_console.Commands.AddCommand("userserver", false, "create user", | ||
109 | "create user [<first> [<last> [<x> <y> [email]]]]", | ||
110 | "Create a new user account", RunCommand); | ||
111 | |||
112 | m_console.Commands.AddCommand("userserver", false, "reset user password", | ||
113 | "reset user password [<first> [<last> [<new password>]]]", | ||
114 | "Reset a user's password", RunCommand); | ||
115 | |||
116 | m_console.Commands.AddCommand("userserver", false, "login level", | ||
117 | "login level <level>", | ||
118 | "Set the minimum user level to log in", HandleLoginCommand); | ||
119 | |||
120 | m_console.Commands.AddCommand("userserver", false, "login reset", | ||
121 | "login reset", | ||
122 | "Reset the login level to allow all users", | ||
123 | HandleLoginCommand); | ||
124 | |||
125 | m_console.Commands.AddCommand("userserver", false, "login text", | ||
126 | "login text <text>", | ||
127 | "Set the text users will see on login", HandleLoginCommand); | ||
128 | |||
129 | m_console.Commands.AddCommand("userserver", false, "test-inventory", | ||
130 | "test-inventory", | ||
131 | "Perform a test inventory transaction", RunCommand); | ||
132 | |||
133 | m_console.Commands.AddCommand("userserver", false, "logoff-user", | ||
134 | "logoff-user <first> <last> <message>", | ||
135 | "Log off a named user", RunCommand); | ||
136 | } | ||
137 | |||
138 | #region Console Command Handlers | ||
139 | public void do_create(string[] args) | ||
140 | { | ||
141 | switch (args[0]) | ||
142 | { | ||
143 | case "user": | ||
144 | CreateUser(args); | ||
145 | break; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// Execute switch for some of the reset commands | ||
151 | /// </summary> | ||
152 | /// <param name="args"></param> | ||
153 | protected void Reset(string[] args) | ||
154 | { | ||
155 | if (args.Length == 0) | ||
156 | return; | ||
157 | |||
158 | switch (args[0]) | ||
159 | { | ||
160 | case "user": | ||
161 | |||
162 | switch (args[1]) | ||
163 | { | ||
164 | case "password": | ||
165 | ResetUserPassword(args); | ||
166 | break; | ||
167 | } | ||
168 | |||
169 | break; | ||
170 | } | ||
171 | } | ||
172 | |||
173 | /// <summary> | ||
174 | /// Create a new user | ||
175 | /// </summary> | ||
176 | /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param> | ||
177 | protected void CreateUser(string[] cmdparams) | ||
178 | { | ||
179 | string firstName; | ||
180 | string lastName; | ||
181 | string password; | ||
182 | string email; | ||
183 | uint regX = 1000; | ||
184 | uint regY = 1000; | ||
185 | |||
186 | if (cmdparams.Length < 2) | ||
187 | firstName = MainConsole.Instance.CmdPrompt("First name", "Default"); | ||
188 | else firstName = cmdparams[1]; | ||
189 | |||
190 | if (cmdparams.Length < 3) | ||
191 | lastName = MainConsole.Instance.CmdPrompt("Last name", "User"); | ||
192 | else lastName = cmdparams[2]; | ||
193 | |||
194 | if (cmdparams.Length < 4) | ||
195 | password = MainConsole.Instance.PasswdPrompt("Password"); | ||
196 | else password = cmdparams[3]; | ||
197 | |||
198 | if (cmdparams.Length < 5) | ||
199 | regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString())); | ||
200 | else regX = Convert.ToUInt32(cmdparams[4]); | ||
201 | |||
202 | if (cmdparams.Length < 6) | ||
203 | regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString())); | ||
204 | else regY = Convert.ToUInt32(cmdparams[5]); | ||
205 | |||
206 | if (cmdparams.Length < 7) | ||
207 | email = MainConsole.Instance.CmdPrompt("Email", ""); | ||
208 | else email = cmdparams[6]; | ||
209 | |||
210 | if (null == m_userDataBaseService.GetUserProfile(firstName, lastName)) | ||
211 | { | ||
212 | m_lastCreatedUser = m_userDataBaseService.AddUser(firstName, lastName, password, email, regX, regY); | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | m_log.ErrorFormat("[USERS]: A user with the name {0} {1} already exists!", firstName, lastName); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | /// <summary> | ||
221 | /// Reset a user password. | ||
222 | /// </summary> | ||
223 | /// <param name="cmdparams"></param> | ||
224 | private void ResetUserPassword(string[] cmdparams) | ||
225 | { | ||
226 | string firstName; | ||
227 | string lastName; | ||
228 | string newPassword; | ||
229 | |||
230 | if (cmdparams.Length < 3) | ||
231 | firstName = MainConsole.Instance.CmdPrompt("First name"); | ||
232 | else firstName = cmdparams[2]; | ||
233 | |||
234 | if (cmdparams.Length < 4) | ||
235 | lastName = MainConsole.Instance.CmdPrompt("Last name"); | ||
236 | else lastName = cmdparams[3]; | ||
237 | |||
238 | if (cmdparams.Length < 5) | ||
239 | newPassword = MainConsole.Instance.PasswdPrompt("New password"); | ||
240 | else newPassword = cmdparams[4]; | ||
241 | |||
242 | m_userDataBaseService.ResetUserPassword(firstName, lastName, newPassword); | ||
243 | } | ||
244 | |||
245 | /* | ||
246 | private void HandleTestCommand(string module, string[] cmd) | ||
247 | { | ||
248 | m_log.Info("test command received"); | ||
249 | } | ||
250 | */ | ||
251 | |||
252 | private void HandleLoginCommand(string module, string[] cmd) | ||
253 | { | ||
254 | string subcommand = cmd[1]; | ||
255 | |||
256 | switch (subcommand) | ||
257 | { | ||
258 | case "level": | ||
259 | // Set the minimal level to allow login | ||
260 | // Useful to allow grid update without worrying about users. | ||
261 | // or fixing critical issues | ||
262 | // | ||
263 | if (cmd.Length > 2) | ||
264 | { | ||
265 | int level = Convert.ToInt32(cmd[2]); | ||
266 | m_loginService.setloginlevel(level); | ||
267 | } | ||
268 | break; | ||
269 | case "reset": | ||
270 | m_loginService.setloginlevel(0); | ||
271 | break; | ||
272 | case "text": | ||
273 | if (cmd.Length > 2) | ||
274 | { | ||
275 | m_loginService.setwelcometext(cmd[2]); | ||
276 | } | ||
277 | break; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | public void RunCommand(string module, string[] cmd) | ||
282 | { | ||
283 | List<string> args = new List<string>(cmd); | ||
284 | string command = cmd[0]; | ||
285 | |||
286 | args.RemoveAt(0); | ||
287 | |||
288 | string[] cmdparams = args.ToArray(); | ||
289 | |||
290 | switch (command) | ||
291 | { | ||
292 | case "create": | ||
293 | do_create(cmdparams); | ||
294 | break; | ||
295 | |||
296 | case "reset": | ||
297 | Reset(cmdparams); | ||
298 | break; | ||
299 | |||
300 | |||
301 | case "test-inventory": | ||
302 | // RestObjectPosterResponse<List<InventoryFolderBase>> requester = new RestObjectPosterResponse<List<InventoryFolderBase>>(); | ||
303 | // requester.ReturnResponseVal = TestResponse; | ||
304 | // requester.BeginPostObject<UUID>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser); | ||
305 | SynchronousRestObjectPoster.BeginPostObject<UUID, List<InventoryFolderBase>>( | ||
306 | "POST", m_cfg.InventoryUrl + "RootFolders/", m_lastCreatedUser); | ||
307 | break; | ||
308 | |||
309 | case "logoff-user": | ||
310 | if (cmdparams.Length >= 3) | ||
311 | { | ||
312 | string firstname = cmdparams[0]; | ||
313 | string lastname = cmdparams[1]; | ||
314 | string message = ""; | ||
315 | |||
316 | for (int i = 2; i < cmdparams.Length; i++) | ||
317 | message += " " + cmdparams[i]; | ||
318 | |||
319 | UserProfileData theUser = null; | ||
320 | try | ||
321 | { | ||
322 | theUser = m_loginService.GetTheUser(firstname, lastname); | ||
323 | } | ||
324 | catch (Exception) | ||
325 | { | ||
326 | m_log.Error("[LOGOFF]: Error getting user data from the database."); | ||
327 | } | ||
328 | |||
329 | if (theUser != null) | ||
330 | { | ||
331 | if (theUser.CurrentAgent != null) | ||
332 | { | ||
333 | if (theUser.CurrentAgent.AgentOnline) | ||
334 | { | ||
335 | m_log.Info("[LOGOFF]: Logging off requested user!"); | ||
336 | m_loginService.LogOffUser(theUser, message); | ||
337 | |||
338 | theUser.CurrentAgent.AgentOnline = false; | ||
339 | |||
340 | m_loginService.CommitAgent(ref theUser); | ||
341 | } | ||
342 | else | ||
343 | { | ||
344 | m_log.Info( | ||
345 | "[LOGOFF]: User Doesn't appear to be online, sending the logoff message anyway."); | ||
346 | m_loginService.LogOffUser(theUser, message); | ||
347 | |||
348 | theUser.CurrentAgent.AgentOnline = false; | ||
349 | |||
350 | m_loginService.CommitAgent(ref theUser); | ||
351 | } | ||
352 | } | ||
353 | else | ||
354 | { | ||
355 | m_log.Error( | ||
356 | "[LOGOFF]: Unable to logoff-user. User doesn't have an agent record so I can't find the simulator to notify"); | ||
357 | } | ||
358 | } | ||
359 | else | ||
360 | { | ||
361 | m_log.Info("[LOGOFF]: User doesn't exist in the database"); | ||
362 | } | ||
363 | } | ||
364 | else | ||
365 | { | ||
366 | m_log.Error( | ||
367 | "[LOGOFF]: Invalid amount of parameters. logoff-user takes at least three. Firstname, Lastname, and message"); | ||
368 | } | ||
369 | |||
370 | break; | ||
371 | } | ||
372 | } | ||
373 | } | ||
374 | #endregion | ||
375 | } | ||