public static void NewWorld(Player p, string message) { if (message.Trim().Equals("")) { Help(p, "newworld"); return; } string[] args = message.Trim().Split(' '); if (args.Length != 4) { Help(p, "newworld"); return; } string worldname = args[0]; short w = Int16.Parse(args[1]); short h = Int16.Parse(args[2]); short d = Int16.Parse(args[3]); worldname += ".umw"; if (System.IO.File.Exists("maps/" + worldname)) { p.SendMessage(0xFF, "That filename already exists!"); return; } World newworld = new World(worldname, w, h, d); newworld.Save(); p.SendMessage(0xFF, "Created new world: " + worldname); }
public void Init() { logger.log("Server initialized"); //Init salt string saltChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.~"; Random rand = new Random(); int saltLength = rand.Next(12, 16); for (int i = 0; i < saltLength; i++) { salt += saltChars[rand.Next(0, saltChars.Length - 1)]; } //Load config LoadConfig(); //Put server name in console title Console.Title = this.serverName; if (!this.isPublic) { Console.Title += " (PRIVATE)"; } playerlist = new Player[maxPlayers + 2]; //Extra slot is for rejects, and another one (for some odd reason it's less by one) for (int i = 0; i < maxPlayers + 2; i++) { playerlist[i] = null; } //Load world and start save timer if (!Directory.Exists("maps")) { Directory.CreateDirectory("maps"); } if (!File.Exists("maps/" + worldPath)) { world = new World(worldPath, 256, 64, 256); world.Save(); } else { world = new World(worldPath); //world.Save(); } worldSaveTimer = new System.Timers.Timer(60000.0); worldSaveTimer.Elapsed += new System.Timers.ElapsedEventHandler(delegate { world.Save(); SavePlayerStats(); }); worldBackupTimer = new System.Timers.Timer(600000.0); worldBackupTimer.Elapsed += new System.Timers.ElapsedEventHandler(delegate { world.Backup(); SavePlayerStats(); }); physics = new BasicPhysics(world, lavaSpongeEnabled); advPhysics = new AdvancedPhysics(world); this.physThread = new System.Threading.Thread(PhysicsUpdateLoop); physThread.Start(); logger.log("Started Physics Thread"); //Intercept Ctrl+C Console.CancelKeyPress += new ConsoleCancelEventHandler(delegate { world.Save(); SavePlayerStats(); }); //Load Commands Command.Init(); consolePlayer = new ConsolePlayer(); //Load accounts accounts = new Dictionary<string,Account>(); LoadPlayerStats(); //Load blocks Blocks.Init(); //Load special chars Player.specialChars = new Dictionary<string, char>(); Player.specialChars.Add(@"\:D", (char)2); //☻ Player.specialChars.Add(@"\<3", (char)3); //♥ Player.specialChars.Add(@"\<>", (char)4); //♦ Player.specialChars.Add(@"\club", (char)5); //♣ Player.specialChars.Add(@"\spade", (char)6); //♠ Player.specialChars.Add(@"\boy", (char)11); //♂ Player.specialChars.Add(@"\girl", (char)12); //♀ Player.specialChars.Add(@"\8note", (char)13); //♪ Player.specialChars.Add(@"\16note", (char)14); //♫ Player.specialChars.Add(@"\*", (char)15); //☼ Player.specialChars.Add(@"\>", (char)16); //► Player.specialChars.Add(@"\<-", (char)27); //← Player.specialChars.Add(@"\<", (char)17); //◄ Player.specialChars.Add(@"\updn", (char)18); //↕ Player.specialChars.Add(@"\2!", (char)19); //‼ Player.specialChars.Add(@"\p", (char)20); //¶ Player.specialChars.Add(@"\sec", (char)21); //§ Player.specialChars.Add(@"\|up", (char)24); //↑ Player.specialChars.Add(@"\|dn", (char)25); //↓ Player.specialChars.Add(@"\->", (char)26); //→ //** The ← symbol was moved before ◄ due to parsing order issues Player.specialChars.Add(@"\lr", (char)29); //↔ Player.specialChars.Add(@"\up", (char)30); //▲ Player.specialChars.Add(@"\dn", (char)31); //▼ //Load ranks playerRanksDict = new Dictionary<string, ushort>(); try { if (File.Exists("ranks.txt")) { StreamReader sr = new StreamReader(File.OpenRead("ranks.txt")); while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line != null && !line.Equals("") && line.IndexOf(':') >= 0) { string user = line.Substring(0, line.IndexOf(':')); ushort rank = ushort.Parse(line.Substring(line.IndexOf(':') + 1)); playerRanksDict.Add(user, rank); } } sr.Close(); } } catch (OverflowException) { logger.log("Error while loading ranks: rank cannot be higher than 65535", Logger.LogType.Error); running = false; return; } catch (Exception e) { logger.log("Error while loading ranks:", Logger.LogType.Error); logger.log(e); running = false; return; } logger.log("Loaded ranks from ranks.txt"); ipbanned = new List<string>(); try { if (File.Exists("ipbans.txt")) { StreamReader sr = new StreamReader(File.OpenRead("ipbans.txt")); while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line != null && !line.Equals("")) { ipbanned.Add(line.Trim()); } } sr.Close(); } } catch (Exception e) { logger.log("Error while loading ranks:", Logger.LogType.Error); logger.log(e); running = false; return; } logger.log("Loaded ipbans from ipbans.txt"); //etc //Initialize heartbeat timer heartbeatTimer.Elapsed += new System.Timers.ElapsedEventHandler(delegate { beater.Beat(false); }); heartbeatTimer.Start(); beater.Beat(true); //Initial heartbeat //Start TCP listener thread this.ListenThread = new System.Threading.Thread( new System.Threading.ThreadStart( delegate { this.listener = new TcpListener(IPAddress.Any, this.port); try { listener.Start(); listener.BeginAcceptTcpClient(new AsyncCallback(ClientAccept), null); } catch(Exception e) { listener.Stop(); logger.log(e); } logger.log("Started listener thread"); })); this.ListenThread.IsBackground = true; this.ListenThread.Start(); }