diff options
Diffstat (limited to 'OpenSim/Grid/UserServer/Main.cs')
-rw-r--r-- | OpenSim/Grid/UserServer/Main.cs | 316 |
1 files changed, 0 insertions, 316 deletions
diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs deleted file mode 100644 index d598728..0000000 --- a/OpenSim/Grid/UserServer/Main.cs +++ /dev/null | |||
@@ -1,316 +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 | using Nini.Config; | ||
47 | |||
48 | namespace OpenSim.Grid.UserServer | ||
49 | { | ||
50 | /// <summary> | ||
51 | /// Grid user server main class | ||
52 | /// </summary> | ||
53 | public class OpenUser_Main : BaseOpenSimServer, IGridServiceCore | ||
54 | { | ||
55 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
56 | |||
57 | protected UserConfig Cfg; | ||
58 | |||
59 | protected UserDataBaseService m_userDataBaseService; | ||
60 | |||
61 | public UserManager m_userManager; | ||
62 | |||
63 | protected UserServerAvatarAppearanceModule m_avatarAppearanceModule; | ||
64 | protected UserServerFriendsModule m_friendsModule; | ||
65 | |||
66 | public UserLoginService m_loginService; | ||
67 | public MessageServersConnector m_messagesService; | ||
68 | |||
69 | protected UserServerCommandModule m_consoleCommandModule; | ||
70 | protected UserServerEventDispatchModule m_eventDispatcher; | ||
71 | |||
72 | protected AvatarCreationModule m_appearanceModule; | ||
73 | |||
74 | protected static string m_consoleType = "local"; | ||
75 | protected static IConfigSource m_config = null; | ||
76 | protected static string m_configFile = "UserServer_Config.xml"; | ||
77 | |||
78 | public static void Main(string[] args) | ||
79 | { | ||
80 | ArgvConfigSource argvSource = new ArgvConfigSource(args); | ||
81 | argvSource.AddSwitch("Startup", "console", "c"); | ||
82 | argvSource.AddSwitch("Startup", "xmlfile", "x"); | ||
83 | |||
84 | IConfig startupConfig = argvSource.Configs["Startup"]; | ||
85 | if (startupConfig != null) | ||
86 | { | ||
87 | m_consoleType = startupConfig.GetString("console", "local"); | ||
88 | m_configFile = startupConfig.GetString("xmlfile", "UserServer_Config.xml"); | ||
89 | } | ||
90 | |||
91 | m_config = argvSource; | ||
92 | |||
93 | XmlConfigurator.Configure(); | ||
94 | |||
95 | m_log.Info("Launching UserServer..."); | ||
96 | |||
97 | OpenUser_Main userserver = new OpenUser_Main(); | ||
98 | |||
99 | userserver.Startup(); | ||
100 | userserver.Work(); | ||
101 | } | ||
102 | |||
103 | public OpenUser_Main() | ||
104 | { | ||
105 | switch (m_consoleType) | ||
106 | { | ||
107 | case "rest": | ||
108 | m_console = new RemoteConsole("User"); | ||
109 | break; | ||
110 | case "basic": | ||
111 | m_console = new CommandConsole("User"); | ||
112 | break; | ||
113 | default: | ||
114 | m_console = new LocalConsole("User"); | ||
115 | break; | ||
116 | } | ||
117 | MainConsole.Instance = m_console; | ||
118 | } | ||
119 | |||
120 | public void Work() | ||
121 | { | ||
122 | m_console.Output("Enter help for a list of commands\n"); | ||
123 | |||
124 | while (true) | ||
125 | { | ||
126 | m_console.Prompt(); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | protected override void StartupSpecific() | ||
131 | { | ||
132 | IInterServiceInventoryServices inventoryService = StartupCoreComponents(); | ||
133 | |||
134 | m_stats = StatsManager.StartCollectingUserStats(); | ||
135 | |||
136 | //setup services/modules | ||
137 | StartupUserServerModules(); | ||
138 | |||
139 | StartOtherComponents(inventoryService); | ||
140 | |||
141 | //PostInitialise the modules | ||
142 | PostInitialiseModules(); | ||
143 | |||
144 | //register http handlers and start http server | ||
145 | m_log.Info("[STARTUP]: Starting HTTP process"); | ||
146 | RegisterHttpHandlers(); | ||
147 | m_httpServer.Start(); | ||
148 | |||
149 | base.StartupSpecific(); | ||
150 | } | ||
151 | |||
152 | protected virtual IInterServiceInventoryServices StartupCoreComponents() | ||
153 | { | ||
154 | Cfg = new UserConfig("USER SERVER", (Path.Combine(Util.configDir(), m_configFile))); | ||
155 | |||
156 | m_httpServer = new BaseHttpServer(Cfg.HttpPort); | ||
157 | |||
158 | if (m_console is RemoteConsole) | ||
159 | { | ||
160 | RemoteConsole c = (RemoteConsole)m_console; | ||
161 | c.SetServer(m_httpServer); | ||
162 | IConfig netConfig = m_config.AddConfig("Network"); | ||
163 | netConfig.Set("ConsoleUser", Cfg.ConsoleUser); | ||
164 | netConfig.Set("ConsolePass", Cfg.ConsolePass); | ||
165 | c.ReadConfig(m_config); | ||
166 | } | ||
167 | |||
168 | RegisterInterface<CommandConsole>(m_console); | ||
169 | RegisterInterface<UserConfig>(Cfg); | ||
170 | |||
171 | //Should be in modules? | ||
172 | IInterServiceInventoryServices inventoryService = new OGS1InterServiceInventoryService(Cfg.InventoryUrl); | ||
173 | // IRegionProfileRouter regionProfileService = new RegionProfileServiceProxy(); | ||
174 | |||
175 | RegisterInterface<IInterServiceInventoryServices>(inventoryService); | ||
176 | // RegisterInterface<IRegionProfileRouter>(regionProfileService); | ||
177 | |||
178 | return inventoryService; | ||
179 | } | ||
180 | |||
181 | /// <summary> | ||
182 | /// Start up the user manager | ||
183 | /// </summary> | ||
184 | /// <param name="inventoryService"></param> | ||
185 | protected virtual void StartupUserServerModules() | ||
186 | { | ||
187 | m_log.Info("[STARTUP]: Establishing data connection"); | ||
188 | |||
189 | //we only need core components so we can request them from here | ||
190 | IInterServiceInventoryServices inventoryService; | ||
191 | TryGet<IInterServiceInventoryServices>(out inventoryService); | ||
192 | |||
193 | CommunicationsManager commsManager = new UserServerCommsManager(inventoryService); | ||
194 | |||
195 | //setup database access service, for now this has to be created before the other modules. | ||
196 | m_userDataBaseService = new UserDataBaseService(commsManager); | ||
197 | m_userDataBaseService.Initialise(this); | ||
198 | |||
199 | //TODO: change these modules so they fetch the databaseService class in the PostInitialise method | ||
200 | m_userManager = new UserManager(m_userDataBaseService); | ||
201 | m_userManager.Initialise(this); | ||
202 | |||
203 | m_avatarAppearanceModule = new UserServerAvatarAppearanceModule(m_userDataBaseService); | ||
204 | m_avatarAppearanceModule.Initialise(this); | ||
205 | |||
206 | m_friendsModule = new UserServerFriendsModule(m_userDataBaseService); | ||
207 | m_friendsModule.Initialise(this); | ||
208 | |||
209 | m_consoleCommandModule = new UserServerCommandModule(); | ||
210 | m_consoleCommandModule.Initialise(this); | ||
211 | |||
212 | m_messagesService = new MessageServersConnector(); | ||
213 | m_messagesService.Initialise(this); | ||
214 | } | ||
215 | |||
216 | protected virtual void StartOtherComponents(IInterServiceInventoryServices inventoryService) | ||
217 | { | ||
218 | m_appearanceModule = new AvatarCreationModule(m_userDataBaseService, Cfg, inventoryService); | ||
219 | m_appearanceModule.Initialise(this); | ||
220 | |||
221 | StartupLoginService(inventoryService); | ||
222 | // | ||
223 | // Get the minimum defaultLevel to access to the grid | ||
224 | // | ||
225 | m_loginService.setloginlevel((int)Cfg.DefaultUserLevel); | ||
226 | |||
227 | RegisterInterface<UserLoginService>(m_loginService); //TODO: should be done in the login service | ||
228 | |||
229 | m_eventDispatcher = new UserServerEventDispatchModule(m_userManager, m_messagesService, m_loginService); | ||
230 | m_eventDispatcher.Initialise(this); | ||
231 | } | ||
232 | |||
233 | /// <summary> | ||
234 | /// Start up the login service | ||
235 | /// </summary> | ||
236 | /// <param name="inventoryService"></param> | ||
237 | protected virtual void StartupLoginService(IInterServiceInventoryServices inventoryService) | ||
238 | { | ||
239 | m_loginService = new UserLoginService( | ||
240 | m_userDataBaseService, inventoryService, new LibraryRootFolder(Cfg.LibraryXmlfile), Cfg, Cfg.DefaultStartupMsg, new RegionProfileServiceProxy()); | ||
241 | |||
242 | } | ||
243 | |||
244 | protected virtual void PostInitialiseModules() | ||
245 | { | ||
246 | m_consoleCommandModule.PostInitialise(); //it will register its Console command handlers in here | ||
247 | m_userDataBaseService.PostInitialise(); | ||
248 | m_messagesService.PostInitialise(); | ||
249 | m_eventDispatcher.PostInitialise(); //it will register event handlers in here | ||
250 | m_userManager.PostInitialise(); | ||
251 | m_avatarAppearanceModule.PostInitialise(); | ||
252 | m_friendsModule.PostInitialise(); | ||
253 | } | ||
254 | |||
255 | protected virtual void RegisterHttpHandlers() | ||
256 | { | ||
257 | m_loginService.RegisterHandlers(m_httpServer, Cfg.EnableLLSDLogin, true); | ||
258 | |||
259 | m_userManager.RegisterHandlers(m_httpServer); | ||
260 | m_friendsModule.RegisterHandlers(m_httpServer); | ||
261 | m_avatarAppearanceModule.RegisterHandlers(m_httpServer); | ||
262 | m_messagesService.RegisterHandlers(m_httpServer); | ||
263 | } | ||
264 | |||
265 | public override void ShutdownSpecific() | ||
266 | { | ||
267 | m_eventDispatcher.Close(); | ||
268 | } | ||
269 | |||
270 | #region IUGAIMCore | ||
271 | protected Dictionary<Type, object> m_moduleInterfaces = new Dictionary<Type, object>(); | ||
272 | |||
273 | /// <summary> | ||
274 | /// Register an Module interface. | ||
275 | /// </summary> | ||
276 | /// <typeparam name="T"></typeparam> | ||
277 | /// <param name="iface"></param> | ||
278 | public void RegisterInterface<T>(T iface) | ||
279 | { | ||
280 | lock (m_moduleInterfaces) | ||
281 | { | ||
282 | if (!m_moduleInterfaces.ContainsKey(typeof(T))) | ||
283 | { | ||
284 | m_moduleInterfaces.Add(typeof(T), iface); | ||
285 | } | ||
286 | } | ||
287 | } | ||
288 | |||
289 | public bool TryGet<T>(out T iface) | ||
290 | { | ||
291 | if (m_moduleInterfaces.ContainsKey(typeof(T))) | ||
292 | { | ||
293 | iface = (T)m_moduleInterfaces[typeof(T)]; | ||
294 | return true; | ||
295 | } | ||
296 | iface = default(T); | ||
297 | return false; | ||
298 | } | ||
299 | |||
300 | public T Get<T>() | ||
301 | { | ||
302 | return (T)m_moduleInterfaces[typeof(T)]; | ||
303 | } | ||
304 | |||
305 | public BaseHttpServer GetHttpServer() | ||
306 | { | ||
307 | return m_httpServer; | ||
308 | } | ||
309 | #endregion | ||
310 | |||
311 | public void TestResponse(List<InventoryFolderBase> resp) | ||
312 | { | ||
313 | m_console.Output("response got"); | ||
314 | } | ||
315 | } | ||
316 | } | ||