aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/ServerMain.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/ServerMain.cs161
1 files changed, 161 insertions, 0 deletions
diff --git a/OpenSim/Server/ServerMain.cs b/OpenSim/Server/ServerMain.cs
new file mode 100644
index 0000000..65e9287
--- /dev/null
+++ b/OpenSim/Server/ServerMain.cs
@@ -0,0 +1,161 @@
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
28using Nini.Config;
29using log4net;
30using System.Reflection;
31using System;
32using System.Collections.Generic;
33using OpenSim.Framework.Servers;
34using OpenSim.Framework.Servers.HttpServer;
35using OpenSim.Server.Base;
36using OpenSim.Server.Handlers.Base;
37using Mono.Addins;
38
39namespace OpenSim.Server
40{
41 public class OpenSimServer
42 {
43 private static readonly ILog m_log =
44 LogManager.GetLogger(
45 MethodBase.GetCurrentMethod().DeclaringType);
46
47 protected static HttpServerBase m_Server = null;
48
49 protected static List<IServiceConnector> m_ServiceConnectors =
50 new List<IServiceConnector>();
51
52 protected static PluginLoader loader;
53
54 public static int Main(string[] args)
55 {
56 m_Server = new HttpServerBase("R.O.B.U.S.T.", args);
57
58 string registryLocation;
59
60 IConfig serverConfig = m_Server.Config.Configs["Startup"];
61 if (serverConfig == null)
62 {
63 System.Console.WriteLine("Startup config section missing in .ini file");
64 throw new Exception("Configuration error");
65 }
66
67 string connList = serverConfig.GetString("ServiceConnectors", String.Empty);
68
69 registryLocation = serverConfig.GetString("RegistryLocation",".");
70
71 IConfig servicesConfig = m_Server.Config.Configs["ServiceList"];
72 if (servicesConfig != null)
73 {
74 List<string> servicesList = new List<string>();
75 if (connList != String.Empty)
76 servicesList.Add(connList);
77
78 foreach (string k in servicesConfig.GetKeys())
79 {
80 string v = servicesConfig.GetString(k);
81 if (v != String.Empty)
82 servicesList.Add(v);
83 }
84
85 connList = String.Join(",", servicesList.ToArray());
86 }
87
88 string[] conns = connList.Split(new char[] {',', ' ', '\n', '\r', '\t'});
89
90// int i = 0;
91 foreach (string c in conns)
92 {
93 if (c == String.Empty)
94 continue;
95
96 string configName = String.Empty;
97 string conn = c;
98 uint port = 0;
99
100 string[] split1 = conn.Split(new char[] {'/'});
101 if (split1.Length > 1)
102 {
103 conn = split1[1];
104
105 string[] split2 = split1[0].Split(new char[] {'@'});
106 if (split2.Length > 1)
107 {
108 configName = split2[0];
109 port = Convert.ToUInt32(split2[1]);
110 }
111 else
112 {
113 port = Convert.ToUInt32(split1[0]);
114 }
115 }
116 string[] parts = conn.Split(new char[] {':'});
117 string friendlyName = parts[0];
118 if (parts.Length > 1)
119 friendlyName = parts[1];
120
121 IHttpServer server;
122
123 if (port != 0)
124 server = MainServer.GetHttpServer(port);
125 else
126 server = MainServer.Instance;
127
128 m_log.InfoFormat("[SERVER]: Loading {0} on port {1}", friendlyName, server.Port);
129
130 IServiceConnector connector = null;
131
132 Object[] modargs = new Object[] { m_Server.Config, server, configName };
133 connector = ServerUtils.LoadPlugin<IServiceConnector>(conn, modargs);
134
135 if (connector == null)
136 {
137 modargs = new Object[] { m_Server.Config, server };
138 connector = ServerUtils.LoadPlugin<IServiceConnector>(conn, modargs);
139 }
140
141 if (connector != null)
142 {
143 m_ServiceConnectors.Add(connector);
144 m_log.InfoFormat("[SERVER]: {0} loaded successfully", friendlyName);
145 }
146 else
147 {
148 m_log.ErrorFormat("[SERVER]: Failed to load {0}", conn);
149 }
150 }
151
152 loader = new PluginLoader(m_Server.Config, registryLocation);
153
154 int res = m_Server.Run();
155
156 Environment.Exit(res);
157
158 return 0;
159 }
160 }
161}