Ejemplo n.º 1
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;
            // 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.Creative;
            // 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();
        }
Ejemplo n.º 2
0
        public Server()
        {
            Config = new ServerConfig();
            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.MissingMemberHandling = MissingMemberHandling.Error;
            //Parse the config file. If the config isn't valid, throw an error.
            if (File.Exists("config.json"))
                try { Config = JsonConvert.DeserializeObject<ServerConfig>(File.ReadAllText("config.json"), settings); }
                catch (JsonException e) { Logger.Log("Config file is invalid!", LogType.Error); }
            else
                File.WriteAllText("config.json", JsonConvert.SerializeObject(Config, Formatting.Indented));

            //Parse the IP from the config file.
            if (!string.IsNullOrWhiteSpace(Config.IP))
            {
                if (!IPAddress.TryParse(Config.IP, out ServerIP))
                    ServerIP = IPAddress.Any;
            }
            else
                ServerIP = IPAddress.Any;
            ServerPort = Config.Port;
            MCServer = new MinecraftServer(new IPEndPoint(ServerIP, ServerPort));
            LogProvider.RegisterProvider(new MCServerLogger());

            //Choose the world generator based on the config file.
            if (string.IsNullOrWhiteSpace(Config.World))
                Config.World = "world";
            switch (Config.WorldType)
            {
                case LevelGenerator.Debug:
                    Generator = new DebugGenerator();
                    break;
                case LevelGenerator.Flatland:
                    Generator = new FlatlandGenerator();
                    break;
                default:
                    //No default generator yet!
                    Generator = new DebugGenerator();
                    break;
            }
            Level l = new Level(Generator, Config.World);
            l.GameMode = GameMode.Survival;
            if (Config.Gamemode == Gamemode.Creative) l.GameMode = GameMode.Creative;
            MCServer.AddLevel(l);

            MCServer.Settings.MotD = Config.MOTD;
            MCServer.Settings.MaxPlayers = Config.MaxPlayers;
            MCServer.Settings.OnlineMode = Config.Online;
            MCServer.Settings.Difficulty = Config.Difficulty;

            MCServer.PlayerLoggedIn += new EventHandler<Craft.Net.Server.Events.PlayerLogInEventArgs>(PlayerLoggedIn);
            MCServer.Start();
        }
Ejemplo n.º 3
0
 static void Main(string[] args)
 {
     if (Directory.Exists("world"))
         Directory.Delete("world", true);
     level = new Level(new StandardGenerator(), "world");
     level.AddWorld("region");
     level.SaveTo("world");
     var server = new MinecraftServer(level);
     server.ChatMessage += server_ChatMessage;
     server.PlayerLoggedIn += server_PlayerLoggedIn;
     server.Settings.OnlineMode = true;
     server.Start(new IPEndPoint(IPAddress.Any, 25565));
     Console.WriteLine("Press 'q' to exit");
     ConsoleKeyInfo cki;
     do cki = Console.ReadKey(true);
     while (cki.KeyChar != 'q');
     server.Stop();
 }
Ejemplo n.º 4
0
 static void Main(string[] args)
 {
     if (Directory.Exists("world"))
         Directory.Delete("world", true);
     level = new Level(new StandardGenerator(), "world");
     level.AddWorld("region");
     level.AddWorld("test", new FlatlandGenerator());
     level.Worlds[1].GenerateChunk(Coordinates2D.Zero);
     level.SaveTo("world");
     server = new MinecraftServer(level);
     server.ChatMessage += server_ChatMessage;
     server.Settings.OnlineMode = true;
     server.Settings.MotD = "Craft.Net Test Server";
     server.Start(new IPEndPoint(IPAddress.Any, 25565));
     Console.WriteLine("Press 'q' to exit");
     ConsoleKeyInfo cki;
     do cki = Console.ReadKey(true);
     while (cki.KeyChar != 'q');
     server.Stop();
 }
Ejemplo n.º 5
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.OnlineMode = false;
            minecraftServer.EncryptionEnabled = false;
            // Add a console logger
            minecraftServer.AddLogProvider(new ConsoleLogWriter(LogImportance.High));
            minecraftServer.AddLogProvider(new FileLogWriter("packetLog.txt", LogImportance.Low));
            // Add a flatland world
            minecraftServer.AddWorld(new World(new DebugGenerator()));
            // Register the chat handler
            minecraftServer.OnChatMessage += HandleOnChatMessage;
            // Start the server
            minecraftServer.Start();
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey(true);
            // Stop the server
            minecraftServer.Stop();
        }