Main.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. namespace OpenGridServices.UserServer
  40. {
  41. /// <summary>
  42. /// </summary>
  43. public class OpenUser_Main : conscmd_callback
  44. {
  45. private string ConfigDll = "OpenUser.Config.UserConfigDb4o.dll";
  46. private UserConfig Cfg;
  47. public static OpenUser_Main userserver;
  48. public UserHTTPServer _httpd;
  49. public UserProfileManager _profilemanager;
  50. public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>();
  51. ConsoleBase m_console;
  52. [STAThread]
  53. public static void Main( string[] args )
  54. {
  55. Console.WriteLine("Starting...\n");
  56. userserver = new OpenUser_Main();
  57. userserver.Startup();
  58. userserver.Work();
  59. }
  60. private OpenUser_Main()
  61. {
  62. m_console = new ConsoleBase("opengrid-userserver-console.log", "OpenUser", this);
  63. MainConsole.Instance = m_console;
  64. }
  65. private void Work()
  66. {
  67. m_console.WriteLine("\nEnter help for a list of commands\n");
  68. while (true)
  69. {
  70. m_console.MainConsolePrompt();
  71. }
  72. }
  73. public void Startup() {
  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. _profilemanager = new UserProfileManager();
  79. _profilemanager.InitUserProfiles();
  80. _profilemanager.SetKeys(Cfg.GridSendKey, Cfg.GridRecvKey, Cfg.GridServerURL, Cfg.DefaultStartupMsg);
  81. MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process");
  82. _httpd = new UserHTTPServer();
  83. }
  84. public void RunCmd(string cmd, string[] cmdparams)
  85. {
  86. switch (cmd)
  87. {
  88. case "help":
  89. m_console.WriteLine("create user - create a new user");
  90. m_console.WriteLine("shutdown - shutdown the grid (USE CAUTION!)");
  91. break;
  92. case "create user":
  93. m_console.WriteLine("Creating new user profile");
  94. string tempfirstname;
  95. string templastname;
  96. string tempMD5Passwd;
  97. tempfirstname=m_console.CmdPrompt("First name: ");
  98. templastname=m_console.CmdPrompt("Last name: ");
  99. tempMD5Passwd=m_console.PasswdPrompt("Password: ");
  100. System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
  101. byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd);
  102. bs = x.ComputeHash(bs);
  103. System.Text.StringBuilder s = new System.Text.StringBuilder();
  104. foreach (byte b in bs)
  105. {
  106. s.Append(b.ToString("x2").ToLower());
  107. }
  108. tempMD5Passwd = "$1$" + s.ToString();
  109. UserProfile newuser=_profilemanager.CreateNewProfile(tempfirstname,templastname,tempMD5Passwd);
  110. newuser.homelookat = new LLVector3(-0.57343f, -0.819255f, 0f);
  111. newuser.homepos = new LLVector3(128f,128f,23f);
  112. _profilemanager.SaveUserProfiles();
  113. break;
  114. case "shutdown":
  115. m_console.Close();
  116. Environment.Exit(0);
  117. break;
  118. }
  119. }
  120. private UserConfig LoadConfigDll(string dllName)
  121. {
  122. Assembly pluginAssembly = Assembly.LoadFrom(dllName);
  123. UserConfig config = null;
  124. foreach (Type pluginType in pluginAssembly.GetTypes())
  125. {
  126. if (pluginType.IsPublic)
  127. {
  128. if (!pluginType.IsAbstract)
  129. {
  130. Type typeInterface = pluginType.GetInterface("IUserConfig", true);
  131. if (typeInterface != null)
  132. {
  133. IUserConfig plug = (IUserConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
  134. config = plug.GetConfigObject();
  135. break;
  136. }
  137. typeInterface = null;
  138. }
  139. }
  140. }
  141. pluginAssembly = null;
  142. return config;
  143. }
  144. public void Show(string ShowWhat)
  145. {
  146. }
  147. }
  148. }