public SingleplayerServer(World world) { World = world; Server = new MultiplayerServer(); TrueCraft.Program.ServerConfiguration = new ServerConfiguration() { MOTD = null, Singleplayer = true }; world.BlockRepository = Server.BlockRepository; Server.AddWorld(world); Server.AddLogProvider(new ConsoleLogProvider()); }
public static void Main(string[] args) { if (File.Exists("config.yaml")) { var deserializer = new Deserializer(ignoreUnmatched: true); using (var file = File.OpenText("config.yaml")) Configuration = deserializer.Deserialize <Configuration>(file); } else { Configuration = new Configuration(); } var serializer = new Serializer(); using (var writer = new StreamWriter("config.yaml")) serializer.Serialize(writer, Configuration); Server = new MultiplayerServer(); Server.AddLogProvider(new ConsoleLogProvider(LogCategory.Notice | LogCategory.Warning | LogCategory.Error | LogCategory.Debug)); #if DEBUG Server.AddLogProvider(new FileLogProvider(new StreamWriter("packets.log", false), LogCategory.Packets)); #endif if (Configuration.Debug.DeleteWorldOnStartup) { if (Directory.Exists("world")) { Directory.Delete("world", true); } } if (Configuration.Debug.DeletePlayersOnStartup) { if (Directory.Exists("players")) { Directory.Delete("players", true); } } IWorld world; try { world = World.LoadWorld("world"); Server.AddWorld(world); } catch { world = new World("default", new StandardGenerator()); world.BlockRepository = Server.BlockRepository; world.Save("world"); Server.AddWorld(world); Server.Log(LogCategory.Notice, "Generating world around spawn point..."); for (int x = -5; x < 5; x++) { for (int z = -5; z < 5; z++) { world.GetChunk(new Coordinates2D(x, z)); } int progress = (int)(((x + 5) / 10.0) * 100); if (progress % 10 == 0) { Server.Log(LogCategory.Notice, "{0}% complete", progress + 10); } } Server.Log(LogCategory.Notice, "Simulating the world for a moment..."); for (int x = -5; x < 5; x++) { for (int z = -5; z < 5; z++) { var chunk = world.GetChunk(new Coordinates2D(x, z)); for (byte _x = 0; _x < Chunk.Width; _x++) { for (byte _z = 0; _z < Chunk.Depth; _z++) { for (int _y = 0; _y < chunk.GetHeight(_x, _z); _y++) { var coords = new Coordinates3D(x + _x, _y, z + _z); var data = world.GetBlockData(coords); var provider = world.BlockRepository.GetBlockProvider(data.ID); provider.BlockUpdate(data, data, Server, world); } } } } int progress = (int)(((x + 5) / 10.0) * 100); if (progress % 10 == 0) { Server.Log(LogCategory.Notice, "{0}% complete", progress + 10); } } } CommandManager = new CommandManager(); Server.ChatMessageReceived += HandleChatMessageReceived; Server.Start(new IPEndPoint(IPAddress.Parse(Configuration.ServerAddress), Configuration.ServerPort)); Console.CancelKeyPress += HandleCancelKeyPress; while (true) { Thread.Sleep(1000 * 30); // TODO: Allow users to customize world save interval foreach (var w in Server.Worlds) { w.Save(); } } }
public static void Main(string[] args) { Server = new MultiplayerServer(); Server.AddLogProvider(new ConsoleLogProvider(LogCategory.Notice | LogCategory.Warning | LogCategory.Error | LogCategory.Debug)); #if DEBUG Server.AddLogProvider(new FileLogProvider(new StreamWriter("packets.log", false), LogCategory.Packets)); #endif ServerConfiguration = Configuration.LoadConfiguration <ServerConfiguration>("config.yaml"); var buckets = ServerConfiguration.Debug?.Profiler?.Buckets?.Split(','); if (buckets != null) { foreach (var bucket in buckets) { Profiler.EnableBucket(bucket.Trim()); } } if (ServerConfiguration.Debug.DeleteWorldOnStartup) { if (Directory.Exists("world")) { Directory.Delete("world", true); } } if (ServerConfiguration.Debug.DeletePlayersOnStartup) { if (Directory.Exists("players")) { Directory.Delete("players", true); } } IWorld world; try { world = World.LoadWorld("world"); Server.AddWorld(world); } catch { world = new World("default", new StandardGenerator()); world.BlockRepository = Server.BlockRepository; world.Save("world"); Server.AddWorld(world); Server.Log(LogCategory.Notice, "Generating world around spawn point..."); for (int x = -5; x < 5; x++) { for (int z = -5; z < 5; z++) { world.GetChunk(new Coordinates2D(x, z)); } int progress = (int)(((x + 5) / 10.0) * 100); if (progress % 10 == 0) { Server.Log(LogCategory.Notice, "{0}% complete", progress + 10); } } Server.Log(LogCategory.Notice, "Simulating the world for a moment..."); for (int x = -5; x < 5; x++) { for (int z = -5; z < 5; z++) { var chunk = world.GetChunk(new Coordinates2D(x, z)); for (byte _x = 0; _x < Chunk.Width; _x++) { for (byte _z = 0; _z < Chunk.Depth; _z++) { for (int _y = 0; _y < chunk.GetHeight(_x, _z); _y++) { var coords = new Coordinates3D(x + _x, _y, z + _z); var data = world.GetBlockData(coords); var provider = world.BlockRepository.GetBlockProvider(data.ID); provider.BlockUpdate(data, data, Server, world); } } } } int progress = (int)(((x + 5) / 10.0) * 100); if (progress % 10 == 0) { Server.Log(LogCategory.Notice, "{0}% complete", progress + 10); } } Server.Log(LogCategory.Notice, "Lighting the world (this will take a moment)..."); foreach (var lighter in Server.WorldLighters) { while (lighter.TryLightNext()) { ; } } } world.Save(); CommandManager = new CommandManager(); Server.ChatMessageReceived += HandleChatMessageReceived; Server.Start(new IPEndPoint(IPAddress.Parse(ServerConfiguration.ServerAddress), ServerConfiguration.ServerPort)); Console.CancelKeyPress += HandleCancelKeyPress; Server.Scheduler.ScheduleEvent("world.save", null, TimeSpan.FromSeconds(ServerConfiguration.WorldSaveInterval), SaveWorlds); while (true) { Thread.Yield(); } }
public static void Main(string[] args) { Server = new MultiplayerServer(); Server.AddLogProvider(new ConsoleLogProvider(LogCategory.Notice | LogCategory.Warning | LogCategory.Error | LogCategory.Debug)); #if DEBUG Server.AddLogProvider(new FileLogProvider(new StreamWriter("packets.log", false), LogCategory.Packets)); #endif ServerConfiguration = Configuration.LoadConfiguration<ServerConfiguration>("config.yaml"); var buckets = ServerConfiguration.Debug?.Profiler?.Buckets?.Split(','); if (buckets != null) { foreach (var bucket in buckets) { Profiler.EnableBucket(bucket.Trim()); } } if (ServerConfiguration.Debug.DeleteWorldOnStartup) { if (Directory.Exists("world")) Directory.Delete("world", true); } if (ServerConfiguration.Debug.DeletePlayersOnStartup) { if (Directory.Exists("players")) Directory.Delete("players", true); } IWorld world; try { world = World.LoadWorld("world"); Server.AddWorld(world); } catch { world = new World("default", new StandardGenerator()); world.BlockRepository = Server.BlockRepository; world.Save("world"); Server.AddWorld(world); Server.Log(LogCategory.Notice, "Generating world around spawn point..."); for (int x = -5; x < 5; x++) { for (int z = -5; z < 5; z++) world.GetChunk(new Coordinates2D(x, z)); int progress = (int)(((x + 5) / 10.0) * 100); if (progress % 10 == 0) Server.Log(LogCategory.Notice, "{0}% complete", progress + 10); } Server.Log(LogCategory.Notice, "Simulating the world for a moment..."); for (int x = -5; x < 5; x++) { for (int z = -5; z < 5; z++) { var chunk = world.GetChunk(new Coordinates2D(x, z)); for (byte _x = 0; _x < Chunk.Width; _x++) { for (byte _z = 0; _z < Chunk.Depth; _z++) { for (int _y = 0; _y < chunk.GetHeight(_x, _z); _y++) { var coords = new Coordinates3D(x + _x, _y, z + _z); var data = world.GetBlockData(coords); var provider = world.BlockRepository.GetBlockProvider(data.ID); provider.BlockUpdate(data, data, Server, world); } } } } int progress = (int)(((x + 5) / 10.0) * 100); if (progress % 10 == 0) Server.Log(LogCategory.Notice, "{0}% complete", progress + 10); } } world.Save(); CommandManager = new CommandManager(); Server.ChatMessageReceived += HandleChatMessageReceived; Server.Start(new IPEndPoint(IPAddress.Parse(ServerConfiguration.ServerAddress), ServerConfiguration.ServerPort)); Console.CancelKeyPress += HandleCancelKeyPress; while (true) { Thread.Sleep(1000 * ServerConfiguration.WorldSaveInterval); foreach (var w in Server.Worlds) { w.Save(); } } }