Exemplo n.º 1
0
        public void GivenIHaveARunningServer(string serverConfig, string clusterConfig)
        {
            NameValueCollection parameters = new NameValueCollection {
                { "port", GetFreePort().ToString() }
            };

            DarkRiftServerConfigurationBuilder serverConfigurationBuilder = DarkRiftServerConfigurationBuilder.CreateFromXml("Configurations/Server/" + serverConfig, parameters);

#if PRO
            serverConfigurationBuilder.AddPluginType(typeof(InMemoryServerRegistryConnector));

            DarkRiftServer server = new DarkRiftServer(
                serverConfigurationBuilder.ServerSpawnData,
                ClusterSpawnData.CreateFromXml("Configurations/Cluster/" + clusterConfig, new NameValueCollection())
                );
#else
            DarkRiftServer server = new DarkRiftServer(
                serverConfigurationBuilder.ServerSpawnData
                );
#endif

            server.StartServer();

            world.AddServer(server);

#if DEBUG
            // We've just requested a load of objects that wont be returned until we close
            // UDP receive TCP accept
            performanceSteps.ExpectedUnaccountedForSocketAsyncEventArgs += 2;
#endif
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Main entry point of the server which starts a single server.
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            string[]            rawArguments = CommandEngine.ParseArguments(string.Join(" ", args));
            string[]            arguments    = CommandEngine.GetArguments(rawArguments);
            NameValueCollection variables    = CommandEngine.GetFlags(rawArguments);

            foreach (DictionaryEntry environmentVariable in Environment.GetEnvironmentVariables())
            {
                variables.Add((string)environmentVariable.Key, (string)environmentVariable.Value);
            }

            string serverConfigFile;
            string clusterConfigFile;

            if (arguments.Length < 1)
            {
                serverConfigFile  = "Server.config";
                clusterConfigFile = "Cluster.config";
            }
            else if (arguments.Length == 1)
            {
                serverConfigFile  = arguments[0];
                clusterConfigFile = "Cluster.config";
            }
            else if (arguments.Length == 2)
            {
                serverConfigFile  = arguments[0];
                clusterConfigFile = arguments[1];
            }
            else
            {
                System.Console.Error.WriteLine("Unexpected number of comand line arguments passed. Expected 0-2 but found " + arguments.Length + ".");
                System.Console.WriteLine("Press any key to exit...");
                System.Console.ReadKey();
                return;
            }

            DarkRiftServerConfigurationBuilder serverConfigurationBuilder;

            try
            {
                serverConfigurationBuilder = DarkRiftServerConfigurationBuilder.CreateFromXml(serverConfigFile, variables);
            }
            catch (IOException e)
            {
                System.Console.Error.WriteLine("Could not load the server config file needed to start (" + e.Message + "). Are you sure it's present and accessible?");
                System.Console.WriteLine("Press any key to exit...");
                System.Console.ReadKey();
                return;
            }
            catch (XmlConfigurationException e)
            {
                System.Console.Error.WriteLine($"Failed to load '{serverConfigFile}': {e.Message}");
                System.Console.Error.WriteLine();
                System.Console.Error.WriteLine(e.DocumentationLink != null ? $"See {e.DocumentationLink} for more information." : "No additional documentation available.");
                System.Console.Error.WriteLine();
                System.Console.Error.WriteLine(e.LineInfo != null && e.LineInfo.HasLineInfo() ? $"Line {e.LineInfo.LineNumber} Col: {e.LineInfo.LinePosition}" : "(Unknown location)");
                System.Console.Error.WriteLine();
                System.Console.WriteLine("Press any key to exit...");
                System.Console.ReadKey();
                return;
            }

            // Set this thread as the one executing dispatcher tasks
            serverConfigurationBuilder.WithDispatcherExecutorThreadID(Thread.CurrentThread.ManagedThreadId);

#if PRO
            if (File.Exists(clusterConfigFile))
            {
                DarkRiftClusterConfigurationBuilder clusterConfigurationBuilder;
                try
                {
                    clusterConfigurationBuilder = DarkRiftClusterConfigurationBuilder.CreateFromXml(clusterConfigFile, variables);
                }
                catch (IOException e)
                {
                    System.Console.Error.WriteLine("Could not load the cluster config file needed to start (" + e.Message + "). Are you sure it's present and accessible?");
                    System.Console.WriteLine("Press any key to exit...");
                    System.Console.ReadKey();
                    return;
                }
                catch (XmlConfigurationException e)
                {
                    System.Console.Error.WriteLine($"Failed to load '{clusterConfigFile}': {e.Message}");
                    System.Console.Error.WriteLine();
                    System.Console.Error.WriteLine(e.DocumentationLink != null ? $"See {e.DocumentationLink} for more information." : "No additional documentation available.");
                    System.Console.Error.WriteLine();
                    System.Console.Error.WriteLine(e.LineInfo != null && e.LineInfo.HasLineInfo() ? $"Line {e.LineInfo.LineNumber} Col: {e.LineInfo.LinePosition}" : "(Unknown location)");
                    System.Console.Error.WriteLine();
                    System.Console.WriteLine("Press any key to exit...");
                    System.Console.ReadKey();
                    return;
                }

                server = new DarkRiftServer(serverConfigurationBuilder.ServerSpawnData, clusterConfigurationBuilder.ClusterSpawnData);
            }
            else
            {
                server = new DarkRiftServer(serverConfigurationBuilder.ServerSpawnData);
            }
#else
            server = new DarkRiftServer(serverConfigurationBuilder.ServerSpawnData);
#endif


            server.StartServer();

            new Thread(new ThreadStart(ConsoleLoop)).Start();

            while (!server.Disposed)
            {
                server.DispatcherWaitHandle.WaitOne();
                server.ExecuteDispatcherTasks();
            }
        }