ServerMain.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.Collections.Generic;
  32. using OpenSim.Framework.Servers;
  33. using OpenSim.Framework.Servers.HttpServer;
  34. using OpenSim.Server.Base;
  35. using OpenSim.Server.Handlers.Base;
  36. namespace OpenSim.Server
  37. {
  38. public class OpenSimServer
  39. {
  40. private static readonly ILog m_log =
  41. LogManager.GetLogger(
  42. MethodBase.GetCurrentMethod().DeclaringType);
  43. protected static HttpServerBase m_Server = null;
  44. protected static List<IServiceConnector> m_ServiceConnectors =
  45. new List<IServiceConnector>();
  46. public static int Main(string[] args)
  47. {
  48. m_Server = new HttpServerBase("R.O.B.U.S.T.", args);
  49. IConfig serverConfig = m_Server.Config.Configs["Startup"];
  50. if (serverConfig == null)
  51. {
  52. System.Console.WriteLine("Startup config section missing in .ini file");
  53. throw new Exception("Configuration error");
  54. }
  55. string connList = serverConfig.GetString("ServiceConnectors", String.Empty);
  56. string[] conns = connList.Split(new char[] {',', ' '});
  57. // int i = 0;
  58. foreach (string c in conns)
  59. {
  60. if (c == String.Empty)
  61. continue;
  62. string configName = String.Empty;
  63. string conn = c;
  64. uint port = 0;
  65. string[] split1 = conn.Split(new char[] {'/'});
  66. if (split1.Length > 1)
  67. {
  68. conn = split1[1];
  69. string[] split2 = split1[0].Split(new char[] {'@'});
  70. if (split2.Length > 1)
  71. {
  72. configName = split2[0];
  73. port = Convert.ToUInt32(split2[1]);
  74. }
  75. else
  76. {
  77. port = Convert.ToUInt32(split1[0]);
  78. }
  79. }
  80. string[] parts = conn.Split(new char[] {':'});
  81. string friendlyName = parts[0];
  82. if (parts.Length > 1)
  83. friendlyName = parts[1];
  84. IHttpServer server;
  85. if (port != 0)
  86. server = MainServer.GetHttpServer(port);
  87. else
  88. server = MainServer.Instance;
  89. m_log.InfoFormat("[SERVER]: Loading {0} on port {1}", friendlyName, server.Port);
  90. IServiceConnector connector = null;
  91. Object[] modargs = new Object[] { m_Server.Config, server, configName };
  92. connector = ServerUtils.LoadPlugin<IServiceConnector>(conn, modargs);
  93. if (connector == null)
  94. {
  95. modargs = new Object[] { m_Server.Config, server };
  96. connector = ServerUtils.LoadPlugin<IServiceConnector>(conn, modargs);
  97. }
  98. if (connector != null)
  99. {
  100. m_ServiceConnectors.Add(connector);
  101. m_log.InfoFormat("[SERVER]: {0} loaded successfully", friendlyName);
  102. }
  103. else
  104. {
  105. m_log.InfoFormat("[SERVER]: Failed to load {0}", conn);
  106. }
  107. }
  108. int res = m_Server.Run();
  109. Environment.Exit(res);
  110. return 0;
  111. }
  112. }
  113. }