コード例 #1
0
        public void Initialize()
        {
            using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            {
                socket.Bind(new IPEndPoint(IPAddress.Any, 19132));

                var startInfo = new ProcessStartInfo(@"C:\Development\Other\bedrock-server-1.14.1.4\bedrock_server.exe");
                startInfo.CreateNoWindow  = false;
                startInfo.WindowStyle     = ProcessWindowStyle.Normal;
                startInfo.UseShellExecute = false;

                _bedrock = Process.Start(startInfo);
                _client  = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.0.4"), 19162), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
                _client.MessageHandler = new ChunkGeneratorHandler(_client);
                _client.StartClient();

                if (_client.ServerEndPoint != null)
                {
                    while (!_client.FoundServer)
                    {
                        _client.SendUnconnectedPing();
                        Thread.Sleep(100);
                    }
                }
            }

            Log.Info("Found server, waiting for spawn");


            Task.Run(BotHelpers.DoWaitForSpawn(_client)).Wait();
            Log.Info("Spawned on bedrock server");
        }
コード例 #2
0
ファイル: BedrockGenerator.cs プロジェクト: sccGg/MiNET
        public void Initialize(IWorldProvider worldProvider)
        {
            Process blocker;

            {
                // Block port!
                var startInfo = new ProcessStartInfo("MiNET.Console.exe", "listener");
                startInfo.CreateNoWindow  = false;
                startInfo.WindowStyle     = ProcessWindowStyle.Normal;
                startInfo.UseShellExecute = false;
                blocker = Process.Start(startInfo);
            }
            {
                var startInfo = new ProcessStartInfo(Path.Combine(Config.GetProperty("BDSPath", null), Config.GetProperty("BDSExe", null)));
                startInfo.WorkingDirectory      = Config.GetProperty("BDSPath", null);
                startInfo.CreateNoWindow        = false;
                startInfo.WindowStyle           = ProcessWindowStyle.Normal;
                startInfo.UseShellExecute       = false;
                startInfo.RedirectStandardInput = true;

                _bedrock = Process.Start(startInfo);

                _client = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.10.178"), 19162), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
                _client.MessageHandler = new ChunkGeneratorHandler(_client, worldProvider);
                //_client.UseBlobCache = true;
                _client.StartClient();

                if (_client.ServerEndPoint != null)
                {
                    while (!_client.FoundServer)
                    {
                        _client.SendUnconnectedPing();
                        Thread.Sleep(100);
                    }
                }
            }

            Log.Info("Found server, waiting for spawn");


            Task.Run(BotHelpers.DoWaitForSpawn(_client)).Wait();
            Log.Info("Spawned on bedrock server");

            blocker?.Kill();             // no need to block further once we have spawned our bot.

            // Shutdown hook. Must use to flush in memory log of LevelDB.
            AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
            {
                Log.Warn("Closing bedrock dedicated server (BDS)");
                _bedrock.StandardInput.WriteLine("stop");
                _bedrock.WaitForExit(1000);
                _bedrock.Kill();
            };
        }