opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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.Reflection;
31 using log4net;
32 using Nini.Config;
33 using OpenSim.Server.Base;
34 using OpenSim.Services.Interfaces;
35 using OpenSim.Framework;
36 using OpenSim.Framework.Servers.HttpServer;
37 using OpenSim.Server.Handlers.Base;
38  
39 namespace OpenSim.Server.Handlers.Login
40 {
41 public class LLLoginServiceInConnector : ServiceConnector
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44  
45 private ILoginService m_LoginService;
46 private bool m_Proxy;
47 private BasicDosProtectorOptions m_DosProtectionOptions;
48  
49 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) :
50 base(config, server, String.Empty)
51 {
52 m_log.Debug("[LLLOGIN IN CONNECTOR]: Starting...");
53 string loginService = ReadLocalServiceFromConfig(config);
54  
55 ISimulationService simService = scene.RequestModuleInterface<ISimulationService>();
56 ILibraryService libService = scene.RequestModuleInterface<ILibraryService>();
57  
58 Object[] args = new Object[] { config, simService, libService };
59 m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args);
60  
61 InitializeHandlers(server);
62 }
63  
64 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, string configName) :
65 base(config, server, configName)
66 {
67 string loginService = ReadLocalServiceFromConfig(config);
68  
69 Object[] args = new Object[] { config };
70  
71 m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args);
72  
73 InitializeHandlers(server);
74 }
75  
76 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server) :
77 this(config, server, String.Empty)
78 {
79 }
80  
81 private string ReadLocalServiceFromConfig(IConfigSource config)
82 {
83 IConfig serverConfig = config.Configs["LoginService"];
84 if (serverConfig == null)
85 throw new Exception(String.Format("No section LoginService in config file"));
86  
87 string loginService = serverConfig.GetString("LocalServiceModule", String.Empty);
88 if (loginService == string.Empty)
89 throw new Exception(String.Format("No LocalServiceModule for LoginService in config file"));
90  
91 m_Proxy = serverConfig.GetBoolean("HasProxy", false);
92 m_DosProtectionOptions = new BasicDosProtectorOptions();
93 // Dos Protection Options
94 m_DosProtectionOptions.AllowXForwardedFor = serverConfig.GetBoolean("DOSAllowXForwardedForHeader", false);
95 m_DosProtectionOptions.RequestTimeSpan =
96 TimeSpan.FromMilliseconds(serverConfig.GetInt("DOSRequestTimeFrameMS", 10000));
97 m_DosProtectionOptions.MaxRequestsInTimeframe = serverConfig.GetInt("DOSMaxRequestsInTimeFrame", 5);
98 m_DosProtectionOptions.ForgetTimeSpan =
99 TimeSpan.FromMilliseconds(serverConfig.GetInt("DOSForgiveClientAfterMS", 120000));
100 m_DosProtectionOptions.ReportingName = "LOGINDOSPROTECTION";
101  
102  
103 return loginService;
104 }
105  
106 private void InitializeHandlers(IHttpServer server)
107 {
108 LLLoginHandlers loginHandlers = new LLLoginHandlers(m_LoginService, m_Proxy);
109 server.AddXmlRPCHandler("login_to_simulator",
110 new XmlRpcBasicDOSProtector(loginHandlers.HandleXMLRPCLogin,loginHandlers.HandleXMLRPCLoginBlocked,
111 m_DosProtectionOptions).Process, false);
112 server.AddXmlRPCHandler("set_login_level", loginHandlers.HandleXMLRPCSetLoginLevel, false);
113 server.SetDefaultLLSDHandler(loginHandlers.HandleLLSDLogin);
114 server.AddWebSocketHandler("/WebSocket/GridLogin", loginHandlers.HandleWebSocketLoginEvents);
115 }
116 }
117 }