OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
ServerMain.cs
Go to the documentation of this file.
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 Nini.Config;
29 using log4net;
30 using System.Reflection;
31 using System;
32 using System.Net;
33 using System.Collections.Generic;
34 using OpenSim.Framework.Servers;
35 using OpenSim.Framework.Servers.HttpServer;
36 using OpenSim.Server.Base;
37 using OpenSim.Server.Handlers.Base;
38 using Mono.Addins;
39 
40 namespace OpenSim.Server
41 {
42  public class OpenSimServer
43  {
44  private static readonly ILog m_log =
45  LogManager.GetLogger(
46  MethodBase.GetCurrentMethod().DeclaringType);
47 
48  protected static HttpServerBase m_Server = null;
49 
50  protected static List<IServiceConnector> m_ServiceConnectors =
51  new List<IServiceConnector>();
52 
53  protected static PluginLoader loader;
54 
55  public static int Main(string[] args)
56  {
57  // Make sure we don't get outbound connections queueing
58  ServicePointManager.DefaultConnectionLimit = 50;
59  ServicePointManager.UseNagleAlgorithm = false;
60 
61  m_Server = new HttpServerBase("R.O.B.U.S.T.", args);
62 
63  string registryLocation;
64 
65  IConfig serverConfig = m_Server.Config.Configs["Startup"];
66  if (serverConfig == null)
67  {
68  System.Console.WriteLine("Startup config section missing in .ini file");
69  throw new Exception("Configuration error");
70  }
71 
72  string connList = serverConfig.GetString("ServiceConnectors", String.Empty);
73 
74  registryLocation = serverConfig.GetString("RegistryLocation",".");
75 
76  IConfig servicesConfig = m_Server.Config.Configs["ServiceList"];
77  if (servicesConfig != null)
78  {
79  List<string> servicesList = new List<string>();
80  if (connList != String.Empty)
81  servicesList.Add(connList);
82 
83  foreach (string k in servicesConfig.GetKeys())
84  {
85  string v = servicesConfig.GetString(k);
86  if (v != String.Empty)
87  servicesList.Add(v);
88  }
89 
90  connList = String.Join(",", servicesList.ToArray());
91  }
92 
93  string[] conns = connList.Split(new char[] {',', ' ', '\n', '\r', '\t'});
94 
95 // int i = 0;
96  foreach (string c in conns)
97  {
98  if (c == String.Empty)
99  continue;
100 
101  string configName = String.Empty;
102  string conn = c;
103  uint port = 0;
104 
105  string[] split1 = conn.Split(new char[] {'/'});
106  if (split1.Length > 1)
107  {
108  conn = split1[1];
109 
110  string[] split2 = split1[0].Split(new char[] {'@'});
111  if (split2.Length > 1)
112  {
113  configName = split2[0];
114  port = Convert.ToUInt32(split2[1]);
115  }
116  else
117  {
118  port = Convert.ToUInt32(split1[0]);
119  }
120  }
121  string[] parts = conn.Split(new char[] {':'});
122  string friendlyName = parts[0];
123  if (parts.Length > 1)
124  friendlyName = parts[1];
125 
126  IHttpServer server;
127 
128  if (port != 0)
129  server = MainServer.GetHttpServer(port);
130  else
131  server = MainServer.Instance;
132 
133  m_log.InfoFormat("[SERVER]: Loading {0} on port {1}", friendlyName, server.Port);
134 
135  IServiceConnector connector = null;
136 
137  Object[] modargs = new Object[] { m_Server.Config, server, configName };
138  connector = ServerUtils.LoadPlugin<IServiceConnector>(conn, modargs);
139 
140  if (connector == null)
141  {
142  modargs = new Object[] { m_Server.Config, server };
143  connector = ServerUtils.LoadPlugin<IServiceConnector>(conn, modargs);
144  }
145 
146  if (connector != null)
147  {
148  m_ServiceConnectors.Add(connector);
149  m_log.InfoFormat("[SERVER]: {0} loaded successfully", friendlyName);
150  }
151  else
152  {
153  m_log.ErrorFormat("[SERVER]: Failed to load {0}", conn);
154  }
155  }
156 
157  loader = new PluginLoader(m_Server.Config, registryLocation);
158 
159  int res = m_Server.Run();
160 
161  Environment.Exit(res);
162 
163  return 0;
164  }
165  }
166 }
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
Definition: IHttpServer.cs:36
static PluginLoader loader
Definition: ServerMain.cs:53
static int Main(string[] args)
Definition: ServerMain.cs:55