Main.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.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.Reflection;
  31. using libsecondlife;
  32. using OpenSim.Framework.Console;
  33. using OpenSim.Framework.Interfaces;
  34. using OpenSim.Framework.Servers;
  35. using OpenSim.Framework.User;
  36. using OpenSim.Framework.Utilities;
  37. using OpenSim.GenericConfig;
  38. namespace OpenSim.Grid.UserServer
  39. {
  40. /// <summary>
  41. /// </summary>
  42. public class OpenUser_Main : conscmd_callback
  43. {
  44. private string ConfigDll = "OpenSim.Grid.UserServer.Config.dll";
  45. private string StorageDll = "OpenSim.Framework.Data.MySQL.dll";
  46. private UserConfig Cfg;
  47. protected IGenericConfig localXMLConfig;
  48. public UserManager m_userManager;
  49. public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>();
  50. LogBase m_console;
  51. [STAThread]
  52. public static void Main(string[] args)
  53. {
  54. Console.WriteLine("Launching UserServer...");
  55. OpenUser_Main userserver = new OpenUser_Main();
  56. userserver.Startup();
  57. userserver.Work();
  58. }
  59. private OpenUser_Main()
  60. {
  61. m_console = new LogBase("opengrid-userserver-console.log", "OpenUser", this , false);
  62. MainLog.Instance = m_console;
  63. }
  64. private void Work()
  65. {
  66. m_console.Notice("Enter help for a list of commands\n");
  67. while (true)
  68. {
  69. m_console.MainLogPrompt();
  70. }
  71. }
  72. public void Startup()
  73. {
  74. this.localXMLConfig = new XmlConfig("UserServerConfig.xml");
  75. this.localXMLConfig.LoadData();
  76. this.ConfigDB(this.localXMLConfig);
  77. this.localXMLConfig.Close();
  78. MainLog.Instance.Verbose("Main.cs:Startup() - Loading configuration");
  79. Cfg = this.LoadConfigDll(this.ConfigDll);
  80. Cfg.InitConfig();
  81. MainLog.Instance.Verbose("Main.cs:Startup() - Establishing data connection");
  82. m_userManager = new UserManager();
  83. m_userManager._config = Cfg;
  84. m_userManager.AddPlugin(StorageDll);
  85. MainLog.Instance.Verbose("Main.cs:Startup() - Starting HTTP process");
  86. BaseHttpServer httpServer = new BaseHttpServer(8002);
  87. httpServer.AddXmlRPCHandler("login_to_simulator", m_userManager.XmlRpcLoginMethod);
  88. httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName);
  89. httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID);
  90. httpServer.AddStreamHandler( new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod ));
  91. httpServer.Start();
  92. m_console.Status("Userserver 0.3 - Startup complete");
  93. }
  94. public void do_create(string what)
  95. {
  96. switch (what)
  97. {
  98. case "user":
  99. string tempfirstname;
  100. string templastname;
  101. string tempMD5Passwd;
  102. uint regX = 1000;
  103. uint regY = 1000;
  104. tempfirstname = m_console.CmdPrompt("First name");
  105. templastname = m_console.CmdPrompt("Last name");
  106. tempMD5Passwd = m_console.PasswdPrompt("Password");
  107. regX = Convert.ToUInt32(m_console.CmdPrompt("Start Region X"));
  108. regY = Convert.ToUInt32(m_console.CmdPrompt("Start Region Y"));
  109. tempMD5Passwd = Util.Md5Hash(Util.Md5Hash(tempMD5Passwd) + ":" + "");
  110. m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY);
  111. break;
  112. }
  113. }
  114. public void RunCmd(string cmd, string[] cmdparams)
  115. {
  116. switch (cmd)
  117. {
  118. case "help":
  119. m_console.Notice("create user - create a new user");
  120. m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
  121. break;
  122. case "create":
  123. do_create(cmdparams[0]);
  124. break;
  125. case "shutdown":
  126. m_console.Close();
  127. Environment.Exit(0);
  128. break;
  129. }
  130. }
  131. private void ConfigDB(IGenericConfig configData)
  132. {
  133. try
  134. {
  135. string attri = "";
  136. attri = configData.GetAttribute("DataBaseProvider");
  137. if (attri == "")
  138. {
  139. StorageDll = "OpenSim.Framework.Data.DB4o.dll";
  140. configData.SetAttribute("DataBaseProvider", "OpenSim.Framework.Data.DB4o.dll");
  141. }
  142. else
  143. {
  144. StorageDll = attri;
  145. }
  146. configData.Commit();
  147. }
  148. catch
  149. {
  150. }
  151. }
  152. private UserConfig LoadConfigDll(string dllName)
  153. {
  154. Assembly pluginAssembly = Assembly.LoadFrom(dllName);
  155. UserConfig config = null;
  156. foreach (Type pluginType in pluginAssembly.GetTypes())
  157. {
  158. if (pluginType.IsPublic)
  159. {
  160. if (!pluginType.IsAbstract)
  161. {
  162. Type typeInterface = pluginType.GetInterface("IUserConfig", true);
  163. if (typeInterface != null)
  164. {
  165. IUserConfig plug = (IUserConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
  166. config = plug.GetConfigObject();
  167. break;
  168. }
  169. typeInterface = null;
  170. }
  171. }
  172. }
  173. pluginAssembly = null;
  174. return config;
  175. }
  176. public void Show(string ShowWhat)
  177. {
  178. }
  179. }
  180. }