static void Main(string[] args) { try { Console.Title = "Terraria's Dedicated Server Mod. (" + Statics.versionNumber + " {" + Statics.currentRelease + "}) #" + Statics.build + " r" + Statics.revision; Console.WriteLine("Setting up Paths."); if (!setupPaths()) { return; } Console.WriteLine("Initializing..."); LuaManager.Initialise("Scripts/Default.lua"); if (Statics.isLinux) { Console.WriteLine("Detected Linux OS."); Statics.platform = 1; } else if (Statics.isMac) { Console.WriteLine("Detected Mac OS."); Statics.platform = 2; } else if (Statics.isWindows == false) { Console.WriteLine("Unknown OS."); Statics.platform = 3; } tConsole = new TConsole(Statics.getDataPath + Statics.systemSeperator + "server.log"); if (args != null && args.Length > 0) { string CmdMessage = args[0].Trim(); if (CmdMessage.Length > 0) { // 0 for Ops if (CmdMessage.ToLower().Equals("-ignoremessages:0")) { Statics.cmdMessages = false; } } } Program.tConsole.WriteLine("Setting up Properties."); if (!System.IO.File.Exists("server.properties")) { Console.Write("Properties not found, Create and exit? [Y/n]: "); if (Console.ReadLine().ToLower() == "y") { setupProperties(); Console.WriteLine("Complete, Press any Key to Exit..."); Console.ReadKey(true); return; } } setupProperties(); Statics.debugMode = properties.debugMode(); if (Statics.debugMode) { Program.tConsole.WriteLine("CAUTION: Running Debug Mode! Unexpected errors may occur!"); } Program.tConsole.WriteLine("Preparing Server Data..."); string worldFile = properties.getInitialWorldPath(); FileInfo file = new FileInfo(worldFile); if (!file.Exists) { try { file.Directory.Create(); } catch (Exception exception) { Program.tConsole.WriteLine(exception.ToString()); Program.tConsole.WriteLine("Press any key to continue..."); Console.ReadKey(true); return; } Program.tConsole.WriteLine("Generating World '" + worldFile + "'"); int seed = properties.getSeed(); if (seed == -1) { Console.Write("Generating Seed..."); seed = new Random().Next(100); Console.Write(seed.ToString() + "\n"); } int worldX = properties.getMapSizes()[0]; int worldY = properties.getMapSizes()[1]; if (properties.isUsingCutomTiles()) { int X = properties.getMaxTilesX(); int Y = properties.getMaxTilesY(); if (X > 0 && Y > 0) { worldX = X; worldY = Y; } if (worldX < (int)World.MAP_SIZE.SMALL_X || worldY < (int)World.MAP_SIZE.SMALL_Y) { Program.tConsole.WriteLine("World dimensions need to be equal to or larger than " + (int)World.MAP_SIZE.SMALL_X + " by " + (int)World.MAP_SIZE.SMALL_Y + "; using built-in 'small'"); worldX = (int)((int)World.MAP_SIZE.SMALL_Y * 3.5); worldY = (int)World.MAP_SIZE.SMALL_Y; } Program.tConsole.WriteLine("Generating World with Custom Map Size { " + worldX.ToString() + ", " + worldY.ToString() + " }"); } Server.maxTilesX = worldX; Server.maxTilesY = worldY; Server.tile = new Tile[Server.maxTilesX + 1, Server.maxTilesY + 1]; WorldGen.clearWorld(); (new Server()).Initialize(); if (properties.getUsingCustomGenOpts()) { WorldGen.numDungeons = properties.getDungeonAmount(); WorldGen.ficount = properties.getFloatingIslandAmount(); } else { WorldGen.numDungeons = 1; WorldGen.ficount = (int)((double)Server.maxTilesX * 0.0008); //The Statics one was generating with default values, We want it to use the actual tileX for the world } WorldGen.generateWorld(seed); WorldGen.saveWorld(worldFile, true); } int worldXtiles = properties.getMapSizes()[0]; int worldYtiles = properties.getMapSizes()[1]; if (properties.isUsingCutomTiles()) { int X = properties.getMaxTilesX(); int Y = properties.getMaxTilesY(); if (X > 0 && Y > 0) { worldXtiles = X; worldYtiles = Y; } if (worldXtiles < (int)World.MAP_SIZE.SMALL_X || worldYtiles < (int)World.MAP_SIZE.SMALL_Y) { Program.tConsole.WriteLine("World dimensions need to be equal to or larger than " + (int)World.MAP_SIZE.SMALL_X + " by " + (int)World.MAP_SIZE.SMALL_Y + "; using built-in 'small'"); worldXtiles = (int)((int)World.MAP_SIZE.SMALL_Y * 3.5); worldYtiles = (int)World.MAP_SIZE.SMALL_Y; } Program.tConsole.WriteLine("Using World with Custom Map Size { " + worldXtiles.ToString() + ", " + worldYtiles.ToString() + " }"); } World world = new World(worldXtiles, worldYtiles); world.setSavePath(worldFile); server = new Server(world, properties.getMaxPlayers(), Statics.getDataPath + Statics.systemSeperator + "whitelist.txt", Statics.getDataPath + Statics.systemSeperator + "banlist.txt", Statics.getDataPath + Statics.systemSeperator + "oplist.txt"); server.setOpPassword(properties.getOpPassword()); server.setPort(properties.getPort()); server.setIP(properties.getServerIP()); server.Initialize(); WorldGen.loadWorld(); server.StartServer(); updateThread = new Thread(Program.Updater); Statics.IsActive = true; while (!Statics.serverStarted) { } commandParser = new CommandParser(server); Program.tConsole.WriteLine("You can now insert Commands."); while (Statics.IsActive) { try { string line = Console.ReadLine().Trim().ToLower(); if (line.Length > 0) { commandParser.parseConsoleCommand(line, server); } } catch(Exception) { } } while (Statics.serverStarted) { } Program.tConsole.WriteLine("Exiting..."); } catch (Exception e) { try { using (StreamWriter streamWriter = new StreamWriter(Statics.getDataPath + Statics.systemSeperator + "crashlog.txt", true)) { streamWriter.WriteLine(DateTime.Now); streamWriter.WriteLine("Crash Log Generated by TDSM #" + Statics.build + " r" + Statics.revision + " for " + Statics.versionNumber + " {" + Statics.currentRelease + "}"); streamWriter.WriteLine(e); streamWriter.WriteLine(""); } Debug.WriteLine("Server crash: " + DateTime.Now); Program.tConsole.WriteLine(e.Message); Program.tConsole.WriteLine(e.StackTrace); Program.tConsole.WriteLine(e.InnerException.Message); Program.tConsole.WriteLine(""); Program.tConsole.WriteLine("Please send crashlog.txt to http://tdsm.org/"); } catch { //Program.tConsole.WriteLine("Lol You crashed your crash log, Good work."); } } if (Program.tConsole != null) { Program.tConsole.Close(); } }
public static void Main(string[] args) { try { string MODInfo = "Terraria's Dedicated Server Mod. (" + VERSION_NUMBER + " {" + Statics.CURRENT_RELEASE + "}) #" + Statics.BUILD; Console.Title = MODInfo; Console.WriteLine("Initializing " + MODInfo); if (args != null && args.Length > 0) { string commandMessage = args[0].ToLower().Trim(); // 0 for Ops if (commandMessage.Equals("-ignoremessages:0")) { Statics.cmdMessages = false; } } Console.WriteLine("Setting up Paths."); if (!SetupPaths()) { return; } Platform.InitPlatform(); tConsole = new TConsole(Statics.DataPath + Path.DirectorySeparatorChar + "server.log", Platform.Type); Program.tConsole.WriteLine("Setting up Properties."); bool propertiesExist = File.Exists("server.properties"); SetupProperties(); if(!propertiesExist) { Console.Write("New properties file created. Would you like to exit for editing? [Y/n]: "); if (Console.ReadLine().ToLower() == "y") { Console.WriteLine("Complete, Press any Key to Exit..."); Console.ReadKey(true); return; } } #if (DEBUG == false) try { if (UpdateManager.performProcess()) { Program.tConsole.WriteLine("Restarting into new update!"); return; } } catch (Exception e) { Program.tConsole.WriteLine("Error updating!"); Program.tConsole.WriteLine(e.Message); } #endif Statics.debugMode = properties.DebugMode; if (Statics.debugMode) { Program.tConsole.WriteLine("CAUTION: Running Debug Mode! Unexpected errors may occur!"); } Program.tConsole.WriteLine("Preparing Server Data..."); string worldFile = properties.InitialWorldPath; FileInfo file = new FileInfo(worldFile); if (!file.Exists) { try { file.Directory.Create(); } catch (Exception exception) { Program.tConsole.WriteLine(exception.ToString()); Program.tConsole.WriteLine("Press any key to continue..."); Console.ReadKey(true); return; } Program.tConsole.WriteLine("Generating World '" + worldFile + "'"); int seed = properties.Seed; if (seed == -1) { Console.Write("Generating Seed..."); seed = new Random().Next(100); Console.Write(seed.ToString() + "\n"); } int worldX = properties.getMapSizes()[0]; int worldY = properties.getMapSizes()[1]; if (properties.UseCustomTiles) { int X = properties.MaxTilesX; int Y = properties.MaxTilesY; if (X > 0 && Y > 0) { worldX = X; worldY = Y; } if (worldX < (int)World.MAP_SIZE.SMALL_X || worldY < (int)World.MAP_SIZE.SMALL_Y) { Program.tConsole.WriteLine("World dimensions need to be equal to or larger than " + (int)World.MAP_SIZE.SMALL_X + " by " + (int)World.MAP_SIZE.SMALL_Y + "; using built-in 'small'"); worldX = (int)((int)World.MAP_SIZE.SMALL_Y * 3.5); worldY = (int)World.MAP_SIZE.SMALL_Y; } Program.tConsole.WriteLine("Generating World with Custom Map Size { " + worldX.ToString() + ", " + worldY.ToString() + " }"); } Server.maxTilesX = worldX; Server.maxTilesY = worldY; Server.tile = new Tile[Server.maxTilesX + 1, Server.maxTilesY + 1]; WorldGen.clearWorld(); (new Server()).Initialize(); if (properties.UseCustomGenOpts) { WorldGen.numDungeons = properties.DungeonAmount; WorldGen.ficount = properties.FloatingIslandAmount; } else { WorldGen.numDungeons = 1; WorldGen.ficount = (int)((double)Server.maxTilesX * 0.0008); //The Statics one was generating with default values, We want it to use the actual tileX for the world } WorldGen.generateWorld(seed); WorldGen.saveWorld(worldFile, true); } int worldXtiles = properties.getMapSizes()[0]; int worldYtiles = properties.getMapSizes()[1]; if (properties.UseCustomTiles) { int X = properties.MaxTilesX; int Y = properties.MaxTilesY; if (X > 0 && Y > 0) { worldXtiles = X; worldYtiles = Y; } if (worldXtiles < (int)World.MAP_SIZE.SMALL_X || worldYtiles < (int)World.MAP_SIZE.SMALL_Y) { Program.tConsole.WriteLine("World dimensions need to be equal to or larger than " + (int)World.MAP_SIZE.SMALL_X + " by " + (int)World.MAP_SIZE.SMALL_Y + "; using built-in 'small'"); worldXtiles = (int)((int)World.MAP_SIZE.SMALL_Y * 3.5); worldYtiles = (int)World.MAP_SIZE.SMALL_Y; } Program.tConsole.WriteLine("Using World with Custom Map Size { " + worldXtiles.ToString() + ", " + worldYtiles.ToString() + " }"); } World world = new World(worldXtiles, worldYtiles); world.SavePath = worldFile; server = new Server(world, properties.MaxPlayers, Statics.DataPath + Path.DirectorySeparatorChar + "whitelist.txt", Statics.DataPath + Path.DirectorySeparatorChar + "banlist.txt", Statics.DataPath + Path.DirectorySeparatorChar + "oplist.txt"); server.setOpPassword(properties.Password); server.setPort(properties.Port); server.setIP(properties.ServerIP); server.Initialize(); WorldGen.loadWorld(); tConsole.WriteLine("Starting the Server"); server.StartServer(); updateThread = new Thread(Program.Updater); Statics.IsActive = true; while (!Statics.serverStarted) { } commandParser = new CommandParser(server); Program.tConsole.WriteLine("You can now insert Commands."); while (Statics.IsActive) { try { string line = Console.ReadLine().Trim().ToLower(); if (line.Length > 0) { commandParser.parseConsoleCommand(line, server); } } catch (Exception) { Program.tConsole.WriteLine("Issue parsing Console Command"); } } while (Statics.serverStarted) { } Program.tConsole.WriteLine("Exiting..."); } catch (Exception e) { try { using (StreamWriter streamWriter = new StreamWriter(Statics.DataPath + Path.DirectorySeparatorChar + "crashlog.txt", true)) { streamWriter.WriteLine(DateTime.Now); streamWriter.WriteLine("Crash Log Generated by TDSM #" + Statics.BUILD + " for " + //+ " r" + Statics.revision + " for " + VERSION_NUMBER + " {" + Statics.CURRENT_RELEASE + "}"); streamWriter.WriteLine(e); streamWriter.WriteLine(""); } Program.tConsole.WriteLine("Server crash: " + DateTime.Now); Program.tConsole.WriteLine(e.Message); Program.tConsole.WriteLine(e.StackTrace); Program.tConsole.WriteLine(e.InnerException.Message); Program.tConsole.WriteLine(""); Program.tConsole.WriteLine("Please send crashlog.txt to http://tdsm.org/"); } catch { } } if (Program.tConsole != null) { Program.tConsole.Close(); } }