Example #1
0
 public void Start()
 {
     MinecraftServer.AddLevel(new Level(Level.GetGenerator(SettingsProvider.Get <string>("level.type")),
                                        SettingsProvider.Get <string>("level.name")));
     MinecraftServer.DefaultLevel.GameMode = SettingsProvider.Get <GameMode>("level.gamemode");
     MinecraftServer.Start();
 }
Example #2
0
        public static void Main(string[] args)
        {
            // Create a server on 0.0.0.0:25565
            minecraftServer = new MinecraftServer(
                new IPEndPoint(IPAddress.Any, 25565));
            minecraftServer.Settings.OnlineMode       = false;
            minecraftServer.Settings.EnableEncryption = true;
            CustomLeatherItem.Server = minecraftServer;
            Item.SetItemClass(new CustomLeatherItem());
            // Add a console logger
            LogProvider.RegisterProvider(new ConsoleLogWriter(LogImportance.Medium));
            LogProvider.RegisterProvider(new FileLogWriter("packetLog.txt", LogImportance.Low));
            // Add a flatland world
#if DEBUG
            // Use a fresh world each time
            if (Directory.Exists("world"))
            {
                Directory.Delete("world", true);
            }
#endif
            IWorldGenerator generator = new FlatlandGenerator();
            minecraftServer.AddLevel(new Level(generator, Path.Combine(Directory.GetCurrentDirectory(), "world")));
            minecraftServer.DefaultLevel.GameMode = GameMode.Survival;
            // Register the chat handler
            minecraftServer.ChatMessage += HandleOnChatMessage;
            // Start the server
            minecraftServer.Start();
            Console.WriteLine("Press 'q' key to exit.");
            while (Console.ReadKey(true).Key != ConsoleKey.Q)
            {
            }
            // Stop the server
            minecraftServer.Stop();
            minecraftServer.DefaultLevel.Save();
        }
Example #3
0
        public void TestSoundEffects()
        {
            var server = new MinecraftServer(new IPEndPoint(IPAddress.Loopback, 25565));
            server.AddLevel(new Level());
            server.Settings.MotD = "Sound effect test";
            server.Settings.OnlineMode = false;
            server.Start();
            bool success = true;
            string failedSound = "n/a";
            DateTime inconclusiveTime = DateTime.Now.AddSeconds(100);

            Queue<string> effects = new Queue<string>();
            Thread test = null;

            foreach (var effect in typeof(SoundEffect).GetFields().Where(f => f.FieldType == typeof(string) && f.IsLiteral))
            {
                effects.Enqueue(effect.GetValue(new SoundEffect()) as string);
            }

            server.PlayerLoggedIn += (s ,e) =>
                {
                    e.Client.SendChat("Beginning sound effect test in 5 seconds. Type \"fail\" into chat to indicate failure.");
                    inconclusiveTime = DateTime.MaxValue;
                    test = new Thread(new ThreadStart(() =>
                        {
                            Thread.Sleep(5000);
                            while (effects.Any())
                            {
                                e.Client.SendChat("Playing sound: " + effects.Peek());
                                e.Client.SendPacket(new NamedSoundEffectPacket(effects.Peek(), e.Client.Entity.Position));
                                Thread.Sleep(5000);
                                effects.Dequeue();
                            }
                        }));
                    test.Start();
                    e.Handled = true;
                };

            server.PlayerLoggedOut += (s, e) =>
                {
                    test.Abort();
                    server.Stop();
                    success = false;
                    failedSound = "Player left before test completion.";
                    effects = new Queue<string>();
                    e.Handled = true;
                    Assert.Fail("Player left before test completion.");
                };

            server.ChatMessage += (s, e) =>
                {
                    if (e.RawMessage == "fail")
                    {
                        test.Abort();
                        server.Stop();
                        failedSound = effects.Peek();
                        effects = new Queue<string>();
                        success = false;
                        Assert.Fail("Sound effect: " + effects.Peek());
                    }
                };

            while (effects.Count != 0 && DateTime.Now < inconclusiveTime) { Thread.Sleep(100); }
            if (DateTime.Now >= inconclusiveTime)
                Assert.Inconclusive("No player joined within 10 second time limit.");
            else
            {
                if (success)
                    Assert.Pass();
                else
                    Assert.Fail("Failed sound effect: " + failedSound);
            }
        }
Example #4
0
        public void TestSoundEffects()
        {
            var server = new MinecraftServer(new IPEndPoint(IPAddress.Loopback, 25565));

            server.AddLevel(new Level());
            server.Settings.MotD       = "Sound effect test";
            server.Settings.OnlineMode = false;
            server.Start();
            bool     success          = true;
            string   failedSound      = "n/a";
            DateTime inconclusiveTime = DateTime.Now.AddSeconds(100);

            Queue <string> effects = new Queue <string>();
            Thread         test    = null;

            foreach (var effect in typeof(SoundEffect).GetFields().Where(f => f.FieldType == typeof(string) && f.IsLiteral))
            {
                effects.Enqueue(effect.GetValue(new SoundEffect()) as string);
            }

            server.PlayerLoggedIn += (s, e) =>
            {
                e.Client.SendChat("Beginning sound effect test in 5 seconds. Type \"fail\" into chat to indicate failure.");
                inconclusiveTime = DateTime.MaxValue;
                test             = new Thread(new ThreadStart(() =>
                {
                    Thread.Sleep(5000);
                    while (effects.Any())
                    {
                        e.Client.SendChat("Playing sound: " + effects.Peek());
                        e.Client.SendPacket(new NamedSoundEffectPacket(effects.Peek(), (int)e.Client.Entity.Position.X,
                                                                       (int)e.Client.Entity.Position.Y, (int)e.Client.Entity.Position.Z, 1.0f, 63));
                        Thread.Sleep(5000);
                        effects.Dequeue();
                    }
                }));
                test.Start();
                e.Handled = true;
            };

            server.PlayerLoggedOut += (s, e) =>
            {
                test.Abort();
                server.Stop();
                success     = false;
                failedSound = "Player left before test completion.";
                effects     = new Queue <string>();
                e.Handled   = true;
                Assert.Fail("Player left before test completion.");
            };

            server.ChatMessage += (s, e) =>
            {
                if (e.RawMessage == "fail")
                {
                    test.Abort();
                    server.Stop();
                    failedSound = effects.Peek();
                    effects     = new Queue <string>();
                    success     = false;
                    Assert.Fail("Sound effect: " + effects.Peek());
                }
            };

            while (effects.Count != 0 && DateTime.Now < inconclusiveTime)
            {
                Thread.Sleep(100);
            }
            if (DateTime.Now >= inconclusiveTime)
            {
                Assert.Inconclusive("No player joined within 10 second time limit.");
            }
            else
            {
                if (success)
                {
                    Assert.Pass();
                }
                else
                {
                    Assert.Fail("Failed sound effect: " + failedSound);
                }
            }
        }