Main.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. Copyright (c) OpenSim project, http://osgrid.org/
  3. * All rights reserved.
  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 <organization> 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 <copyright holder> ``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 <copyright holder> 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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using System.IO;
  32. using System.Text;
  33. using libsecondlife;
  34. using OpenSim.Framework.User;
  35. using OpenSim.Framework.Sims;
  36. using OpenSim.Framework.Inventory;
  37. using OpenSim.Framework.Interfaces;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Servers;
  40. namespace OpenGridServices.UserServer
  41. {
  42. /// <summary>
  43. /// </summary>
  44. public class OpenUser_Main : BaseServer, conscmd_callback
  45. {
  46. private string ConfigDll = "OpenUser.Config.UserConfigDb4o.dll";
  47. private UserConfig Cfg;
  48. private UserProfileManager m_userProfileManager;
  49. public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>();
  50. ConsoleBase m_console;
  51. [STAThread]
  52. public static void Main(string[] args)
  53. {
  54. Console.WriteLine("Starting...\n");
  55. OpenUser_Main userserver = new OpenUser_Main();
  56. userserver.Startup();
  57. userserver.Work();
  58. }
  59. private OpenUser_Main()
  60. {
  61. m_console = new ConsoleBase("opengrid-userserver-console.log", "OpenUser", this , false);
  62. MainConsole.Instance = m_console;
  63. }
  64. private void Work()
  65. {
  66. m_console.WriteLine("\nEnter help for a list of commands\n");
  67. while (true)
  68. {
  69. m_console.MainConsolePrompt();
  70. }
  71. }
  72. public void Startup()
  73. {
  74. MainConsole.Instance.WriteLine("Main.cs:Startup() - Loading configuration");
  75. Cfg = this.LoadConfigDll(this.ConfigDll);
  76. Cfg.InitConfig();
  77. MainConsole.Instance.WriteLine("Main.cs:Startup() - Creating user profile manager");
  78. m_userProfileManager = new UserProfileManager();
  79. m_userProfileManager.InitUserProfiles();
  80. m_userProfileManager.SetKeys(Cfg.GridSendKey, Cfg.GridRecvKey, Cfg.GridServerURL, Cfg.DefaultStartupMsg);
  81. MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process");
  82. BaseHttpServer httpServer = new BaseHttpServer(8002);
  83. httpServer.AddXmlRPCHandler("login_to_simulator", m_userProfileManager.XmlRpcLoginMethod);
  84. httpServer.AddRestHandler("DELETE", "/usersessions/", m_userProfileManager.RestDeleteUserSessionMethod);
  85. // I guess that this was never used?
  86. //Listener.Prefixes.Add("http://+:8002/userserver/");
  87. httpServer.Start();
  88. }
  89. public void do_create(string what)
  90. {
  91. switch (what)
  92. {
  93. case "user":
  94. m_console.WriteLine("Creating new user profile");
  95. string tempfirstname;
  96. string templastname;
  97. string tempMD5Passwd;
  98. tempfirstname = m_console.CmdPrompt("First name");
  99. templastname = m_console.CmdPrompt("Last name");
  100. tempMD5Passwd = m_console.PasswdPrompt("Password");
  101. System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
  102. byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd);
  103. bs = x.ComputeHash(bs);
  104. System.Text.StringBuilder s = new System.Text.StringBuilder();
  105. foreach (byte b in bs)
  106. {
  107. s.Append(b.ToString("x2").ToLower());
  108. }
  109. tempMD5Passwd = s.ToString();
  110. UserProfile newuser = m_userProfileManager.CreateNewProfile(tempfirstname, templastname, tempMD5Passwd);
  111. newuser.homelookat = new LLVector3(-0.57343f, -0.819255f, 0f);
  112. newuser.homepos = new LLVector3(128f, 128f, 23f);
  113. m_userProfileManager.SaveUserProfiles();
  114. break;
  115. }
  116. }
  117. public void RunCmd(string cmd, string[] cmdparams)
  118. {
  119. switch (cmd)
  120. {
  121. case "help":
  122. m_console.WriteLine("create user - create a new user");
  123. m_console.WriteLine("shutdown - shutdown the grid (USE CAUTION!)");
  124. break;
  125. case "create":
  126. do_create(cmdparams[0]);
  127. break;
  128. case "shutdown":
  129. m_console.Close();
  130. Environment.Exit(0);
  131. break;
  132. }
  133. }
  134. private UserConfig LoadConfigDll(string dllName)
  135. {
  136. Assembly pluginAssembly = Assembly.LoadFrom(dllName);
  137. UserConfig config = null;
  138. foreach (Type pluginType in pluginAssembly.GetTypes())
  139. {
  140. if (pluginType.IsPublic)
  141. {
  142. if (!pluginType.IsAbstract)
  143. {
  144. Type typeInterface = pluginType.GetInterface("IUserConfig", true);
  145. if (typeInterface != null)
  146. {
  147. IUserConfig plug = (IUserConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
  148. config = plug.GetConfigObject();
  149. break;
  150. }
  151. typeInterface = null;
  152. }
  153. }
  154. }
  155. pluginAssembly = null;
  156. return config;
  157. }
  158. public void Show(string ShowWhat)
  159. {
  160. }
  161. }
  162. }