aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGridServices.UserServer/Main.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenGridServices/OpenGridServices.UserServer/Main.cs217
1 files changed, 217 insertions, 0 deletions
diff --git a/OpenGridServices/OpenGridServices.UserServer/Main.cs b/OpenGridServices/OpenGridServices.UserServer/Main.cs
new file mode 100644
index 0000000..aec80dc
--- /dev/null
+++ b/OpenGridServices/OpenGridServices.UserServer/Main.cs
@@ -0,0 +1,217 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3
4
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Collections;
32using System.Collections.Generic;
33using System.Reflection;
34using System.IO;
35using System.Text;
36using libsecondlife;
37using OpenSim.Framework.User;
38using OpenSim.Framework.Sims;
39using OpenSim.Framework.Inventory;
40using OpenSim.Framework.Interfaces;
41using OpenSim.Framework.Console;
42using OpenSim.Servers;
43using OpenSim.Framework.Utilities;
44using OpenSim.GenericConfig;
45
46namespace OpenGridServices.UserServer
47{
48 /// <summary>
49 /// </summary>
50 public class OpenUser_Main : BaseServer, conscmd_callback
51 {
52 private string ConfigDll = "OpenUser.Config.UserConfigDb4o.dll";
53 private string StorageDll = "OpenGrid.Framework.Data.DB4o.dll";
54 private UserConfig Cfg;
55 protected IGenericConfig localXMLConfig;
56
57 public UserManager m_userManager; // Replaces below.
58
59 //private UserProfileManager m_userProfileManager; // Depreciated
60
61 public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>();
62
63 ConsoleBase m_console;
64
65 [STAThread]
66 public static void Main(string[] args)
67 {
68 Console.WriteLine("Starting...\n");
69
70 OpenUser_Main userserver = new OpenUser_Main();
71
72 userserver.Startup();
73 userserver.Work();
74 }
75
76 private OpenUser_Main()
77 {
78 m_console = new ConsoleBase("opengrid-userserver-console.log", "OpenUser", this , false);
79 MainConsole.Instance = m_console;
80 }
81
82 private void Work()
83 {
84 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"\nEnter help for a list of commands\n");
85
86 while (true)
87 {
88 m_console.MainConsolePrompt();
89 }
90 }
91
92 public void Startup()
93 {
94 this.localXMLConfig = new XmlConfig("UserServerConfig.xml");
95 this.localXMLConfig.LoadData();
96 this.ConfigDB(this.localXMLConfig);
97 this.localXMLConfig.Close();
98
99 MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Loading configuration");
100 Cfg = this.LoadConfigDll(this.ConfigDll);
101 Cfg.InitConfig();
102
103 MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Establishing data connection");
104 m_userManager = new UserManager();
105 m_userManager._config = Cfg;
106 m_userManager.AddPlugin(StorageDll);
107
108 MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Starting HTTP process");
109 BaseHttpServer httpServer = new BaseHttpServer(8002);
110
111 httpServer.AddXmlRPCHandler("login_to_simulator", m_userManager.XmlRpcLoginMethod);
112 httpServer.AddRestHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod);
113
114 httpServer.Start();
115 }
116
117
118 public void do_create(string what)
119 {
120 switch (what)
121 {
122 case "user":
123 string tempfirstname;
124 string templastname;
125 string tempMD5Passwd;
126 uint regX = 997;
127 uint regY = 996;
128
129 tempfirstname = m_console.CmdPrompt("First name");
130 templastname = m_console.CmdPrompt("Last name");
131 tempMD5Passwd = m_console.PasswdPrompt("Password");
132 regX = Convert.ToUInt32(m_console.CmdPrompt("Start Region X"));
133 regY = Convert.ToUInt32(m_console.CmdPrompt("Start Region Y"));
134
135 tempMD5Passwd = Util.Md5Hash(Util.Md5Hash(tempMD5Passwd) + ":" + "");
136
137 m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY);
138 break;
139 }
140 }
141
142 public void RunCmd(string cmd, string[] cmdparams)
143 {
144 switch (cmd)
145 {
146 case "help":
147 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"create user - create a new user");
148 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"shutdown - shutdown the grid (USE CAUTION!)");
149 break;
150
151 case "create":
152 do_create(cmdparams[0]);
153 break;
154
155 case "shutdown":
156 m_console.Close();
157 Environment.Exit(0);
158 break;
159 }
160 }
161
162 private void ConfigDB(IGenericConfig configData)
163 {
164 try
165 {
166 string attri = "";
167 attri = configData.GetAttribute("DataBaseProvider");
168 if (attri == "")
169 {
170 StorageDll = "OpenGrid.Framework.Data.DB4o.dll";
171 configData.SetAttribute("DataBaseProvider", "OpenGrid.Framework.Data.DB4o.dll");
172 }
173 else
174 {
175 StorageDll = attri;
176 }
177 configData.Commit();
178 }
179 catch (Exception e)
180 {
181
182 }
183 }
184
185 private UserConfig LoadConfigDll(string dllName)
186 {
187 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
188 UserConfig config = null;
189
190 foreach (Type pluginType in pluginAssembly.GetTypes())
191 {
192 if (pluginType.IsPublic)
193 {
194 if (!pluginType.IsAbstract)
195 {
196 Type typeInterface = pluginType.GetInterface("IUserConfig", true);
197
198 if (typeInterface != null)
199 {
200 IUserConfig plug = (IUserConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
201 config = plug.GetConfigObject();
202 break;
203 }
204
205 typeInterface = null;
206 }
207 }
208 }
209 pluginAssembly = null;
210 return config;
211 }
212
213 public void Show(string ShowWhat)
214 {
215 }
216 }
217}