ServerMain.cs 6.1 KB

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