public override void Use(Player p, string message) { if (message == "") { Help(p); return; } if (message[0] == '@') { message = message.Remove(0, 1).Trim(); Player who = Player.Find(message); if (who == null) { DataTable ip; int tryCounter = 0; rerun : try { ip = MySQL.fillData("SELECT IP FROM Players WHERE Name = '" + message + "'"); } catch (Exception e) { tryCounter++; if (tryCounter < 10) { goto rerun; } else { Server.ErrorLog(e); return; } } if (ip.Rows.Count > 0) { message = ip.Rows[0]["IP"].ToString(); } else { Player.SendMessage(p, "Unable to find an IP address for that user."); return; } ip.Dispose(); } else { message = who.ip; } } else { Player who = Player.Find(message); if (who != null) { message = who.ip; } } if (message.Equals("127.0.0.1")) { Player.SendMessage(p, "You can't ip-ban the server!"); return; } if (message.IndexOf('.') == -1) { Player.SendMessage(p, "Invalid IP!"); return; } if (message.Split('.').Length != 4) { Player.SendMessage(p, "Invalid IP!"); return; } if (p != null) { if (p.ip == message) { Player.SendMessage(p, "You can't ip-ban yourself.!"); return; } } if (Server.bannedIP.Contains(message)) { Player.SendMessage(p, message + " is already ip-banned."); return; } Player.GlobalMessage(message + " got &8ip-banned!"); if (p != null) { IRCBot.Say("IP-BANNED: " + message.ToLower() + " by " + p.name); } else { IRCBot.Say("IP-BANNED: " + message.ToLower() + " by console"); } Server.bannedIP.Add(message); Server.bannedIP.Save("banned-ip.txt", false); Server.s.Log("IP-BANNED: " + message.ToLower()); /* * foreach (Player pl in Player.players) { * if (message == pl.ip) { pl.Kick("Kicked by ipban"); } * }*/ }
public override void Use(Player p, string message) { try { MySQL.executeQuery("CREATE TABLE if not exists `Inbox" + p.name + "` (PlayerFrom CHAR(20), TimeSent DATETIME, Contents VARCHAR(255));"); if (message == "") { DataTable Inbox = MySQL.fillData("SELECT * FROM `Inbox" + p.name + "` ORDER BY TimeSent"); if (Inbox.Rows.Count == 0) { Player.SendMessage(p, "No messages found."); Inbox.Dispose(); return; } for (int i = 0; i < Inbox.Rows.Count; ++i) { Player.SendMessage(p, i + ": From &5" + Inbox.Rows[i]["PlayerFrom"].ToString() + Server.DefaultColor + " at &a" + Inbox.Rows[i]["TimeSent"].ToString()); } Inbox.Dispose(); } else if (message.Split(' ')[0].ToLower() == "del" || message.Split(' ')[0].ToLower() == "delete") { int FoundRecord = -1; if (message.Split(' ')[1].ToLower() != "all") { try { FoundRecord = int.Parse(message.Split(' ')[1]); } catch { Player.SendMessage(p, "Incorrect number given."); return; } if (FoundRecord < 0) { Player.SendMessage(p, "Cannot delete records below 0"); return; } } DataTable Inbox = MySQL.fillData("SELECT * FROM `Inbox" + p.name + "` ORDER BY TimeSent"); if (Inbox.Rows.Count - 1 < FoundRecord || Inbox.Rows.Count == 0) { Player.SendMessage(p, "\"" + FoundRecord + "\" does not exist."); Inbox.Dispose(); return; } string queryString; if (FoundRecord == -1) { queryString = "TRUNCATE TABLE `Inbox" + p.name + "`"; } else { queryString = "DELETE FROM `Inbox" + p.name + "` WHERE PlayerFrom='" + Inbox.Rows[FoundRecord]["PlayerFrom"] + "' AND TimeSent='" + Convert.ToDateTime(Inbox.Rows[FoundRecord]["TimeSent"]).ToString("yyyy-MM-dd HH:mm:ss") + "'"; } MySQL.executeQuery(queryString); if (FoundRecord == -1) { Player.SendMessage(p, "Deleted all messages."); } else { Player.SendMessage(p, "Deleted message."); } Inbox.Dispose(); } else { int FoundRecord; try { FoundRecord = int.Parse(message); } catch { Player.SendMessage(p, "Incorrect number given."); return; } if (FoundRecord < 0) { Player.SendMessage(p, "Cannot read records below 0"); return; } DataTable Inbox = MySQL.fillData("SELECT * FROM `Inbox" + p.name + "` ORDER BY TimeSent"); if (Inbox.Rows.Count - 1 < FoundRecord || Inbox.Rows.Count == 0) { Player.SendMessage(p, "\"" + FoundRecord + "\" does not exist."); Inbox.Dispose(); return; } Player.SendMessage(p, "Message from &5" + Inbox.Rows[FoundRecord]["PlayerFrom"] + Server.DefaultColor + " sent at &a" + Inbox.Rows[FoundRecord]["TimeSent"] + ":"); Player.SendMessage(p, Inbox.Rows[FoundRecord]["Contents"].ToString()); Inbox.Dispose(); } } catch { Player.SendMessage(p, "Error accessing inbox. You may have no mail, try again."); } }
public void Start() { shuttingDown = false; Log("Starting Your Server"); if (!Directory.Exists("properties")) { Directory.CreateDirectory("properties"); } if (!Directory.Exists("bots")) { Directory.CreateDirectory("bots"); } if (!Directory.Exists("text")) { Directory.CreateDirectory("text"); } if (!Directory.Exists("extra")) { Directory.CreateDirectory("extra"); } if (!Directory.Exists("extra/undo")) { Directory.CreateDirectory("extra/undo"); } if (!Directory.Exists("extra/undoPrevious")) { Directory.CreateDirectory("extra/undoPrevious"); } if (!Directory.Exists("extra/copy/")) { Directory.CreateDirectory("extra/copy/"); } if (!Directory.Exists("extra/copyBackup/")) { Directory.CreateDirectory("extra/copyBackup/"); } try { if (File.Exists("server.properties")) { File.Move("server.properties", "properties/server.properties"); } if (File.Exists("rules.txt")) { File.Move("rules.txt", "text/rules.txt"); } if (File.Exists("welcome.txt")) { File.Move("welcome.txt", "text/welcome.txt"); } if (File.Exists("messages.txt")) { File.Move("messages.txt", "text/messages.txt"); } if (File.Exists("externalurl.txt")) { File.Move("externalurl.txt", "text/externalurl.txt"); } if (File.Exists("autoload.txt")) { File.Move("autoload.txt", "text/autoload.txt"); } if (File.Exists("IRC_Controllers.txt")) { File.Move("IRC_Controllers.txt", "ranks/IRC_Controllers.txt"); } if (Server.useWhitelist) { if (File.Exists("whitelist.txt")) { File.Move("whitelist.txt", "ranks/whitelist.txt"); } } } catch { } Properties.Load("properties/server.properties"); Updater.Load("properties/update.properties"); Group.InitAll(); Command.InitAll(); GrpCommands.fillRanks(); Block.SetBlocks(); Awards.Load(); if (File.Exists("text/emotelist.txt")) { foreach (string s in File.ReadAllLines("text/emotelist.txt")) { Player.emoteList.Add(s); } } else { File.Create("text/emotelist.txt"); } timeOnline = DateTime.Now; try { MySQL.executeQuery("CREATE DATABASE if not exists `" + MySQLDatabaseName + "`", true); } catch (Exception e) { Server.s.Log("MySQL password has not been set! Please reference the MySQL_Setup.txt file on setting up MySQL!"); Server.ErrorLog(e); //process.Kill(); return; } MySQL.executeQuery("CREATE TABLE if not exists Players (ID MEDIUMINT not null auto_increment, Name VARCHAR(20), IP CHAR(15), FirstLogin DATETIME, LastLogin DATETIME, totalLogin MEDIUMINT, Title CHAR(20), TotalDeaths SMALLINT, Money MEDIUMINT UNSIGNED, totalBlocks BIGINT, totalKicked MEDIUMINT, color VARCHAR(6), title_color VARCHAR(6), PRIMARY KEY (ID));"); // Check if the color column exists. DataTable colorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='color'"); if (colorExists.Rows.Count == 0) { MySQL.executeQuery("ALTER TABLE Players ADD COLUMN color VARCHAR(6) AFTER totalKicked"); } colorExists.Dispose(); // Check if the title color column exists. DataTable tcolorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='title_color'"); if (tcolorExists.Rows.Count == 0) { MySQL.executeQuery("ALTER TABLE Players ADD COLUMN title_color VARCHAR(6) AFTER color"); } tcolorExists.Dispose(); if (levels != null) { foreach (Level l in levels) { l.Unload(); } } ml.Queue(delegate { try { levels = new List <Level>(Server.maps); MapGen = new MapGenerator(); Random random = new Random(); if (File.Exists("levels/" + Server.level + ".lvl")) { mainLevel = Level.Load(Server.level); mainLevel.unload = false; if (mainLevel == null) { if (File.Exists("levels/" + Server.level + ".lvl.backup")) { Log("Attempting to load backup."); File.Copy("levels/" + Server.level + ".lvl.backup", "levels/" + Server.level + ".lvl", true); mainLevel = Level.Load(Server.level); if (mainLevel == null) { Log("BACKUP FAILED!"); Console.ReadLine(); return; } } else { Log("Your main level was not found"); mainLevel = new Level(Server.level, 128, 128, 128, "flat"); mainLevel.permissionvisit = LevelPermission.Guest; mainLevel.permissionbuild = LevelPermission.Guest; mainLevel.Save(); } } } else { Log("You need a main level, creating one for you now"); mainLevel = new Level(Server.level, 128, 128, 128, "flat"); mainLevel.permissionvisit = LevelPermission.Guest; mainLevel.permissionbuild = LevelPermission.Guest; mainLevel.Save(); } addLevel(mainLevel); mainLevel.physThread.Start(); } catch (Exception e) { Server.ErrorLog(e); } }); ml.Queue(delegate { bannedIP = PlayerList.Load("banned-ip.txt", null); ircControllers = PlayerList.Load("IRC_Controllers.txt", null); foreach (Group grp in Group.GroupList) { grp.playerList = PlayerList.Load(grp.fileName, grp); } if (Server.useWhitelist) { whiteList = PlayerList.Load("whitelist.txt", null); } }); ml.Queue(delegate { if (File.Exists("text/autoload.txt")) { try { string[] lines = File.ReadAllLines("text/autoload.txt"); foreach (string line in lines) { //int temp = 0; string _line = line.Trim(); try { if (_line == "") { continue; } if (_line[0] == '#') { continue; } int index = _line.IndexOf("="); string key = _line.Split('=')[0].Trim(); string value; try { value = _line.Split('=')[1].Trim(); } catch { value = "0"; } if (!key.Equals(mainLevel.name)) { Command.all.Find("load").Use(null, key + " " + value); Level l = Level.FindExact(key); } else { try { int temp = int.Parse(value); if (temp >= 0 && temp <= 3) { mainLevel.setPhysics(temp); } } catch { Server.s.Log("Physics variable invalid"); } } } catch { Server.s.Log(_line + " failed."); } } } catch { Server.s.Log("autoload.txt error"); } GC.Collect(); GC.WaitForPendingFinalizers(); } else { Log("autoload.txt does not exist"); } }); ml.Queue(delegate { Log("Creating listening socket on port " + Server.port + "... "); if (Setup()) { s.Log("Done."); } else { s.Log("Could not create socket connection. Shutting down."); return; } }); ml.Queue(delegate { updateTimer.Elapsed += delegate { Player.GlobalUpdate(); PlayerBot.GlobalUpdatePosition(); }; updateTimer.Start(); }); // Heartbeat code here: ml.Queue(delegate { try { Heartbeat.Init(); } catch (Exception e) { Server.ErrorLog(e); } }); // END Heartbeat code /* * Thread processThread = new Thread(new ThreadStart(delegate * { * try * { * PCCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); * ProcessCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName); * PCCounter.BeginInit(); * ProcessCounter.BeginInit(); * PCCounter.NextValue(); * ProcessCounter.NextValue(); * } * catch { } * })); * processThread.Start(); */ ml.Queue(delegate { messageTimer.Elapsed += delegate { RandomMessage(); }; messageTimer.Start(); process = System.Diagnostics.Process.GetCurrentProcess(); if (File.Exists("text/messages.txt")) { StreamReader r = File.OpenText("text/messages.txt"); while (!r.EndOfStream) { messages.Add(r.ReadLine()); } r.Dispose(); } else { File.Create("text/messages.txt").Close(); } if (Server.irc) { new IRCBot(); } // string CheckName = "FROSTEDBUTTS"; // if (Server.name.IndexOf(CheckName.ToLower())!= -1){ Server.s.Log("FROSTEDBUTTS DETECTED");} new AutoSaver(Server.backupInterval); //2 and a half mins blockThread = new Thread(new ThreadStart(delegate { while (true) { Thread.Sleep(blockInterval * 1000); foreach (Level l in levels) { l.saveChanges(); } } })); blockThread.Start(); locationChecker = new Thread(new ThreadStart(delegate { while (true) { Thread.Sleep(3); for (int i = 0; i < Player.players.Count; i++) { try { Player p = Player.players[i]; if (p.frozen) { unchecked { p.SendPos((byte)-1, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]); } continue; } else if (p.following != "") { Player who = Player.Find(p.following); if (who == null || who.level != p.level) { p.following = ""; if (!p.canBuild) { p.canBuild = true; } if (who != null && who.possess == p.name) { who.possess = ""; } continue; } if (p.canBuild) { unchecked { p.SendPos((byte)-1, who.pos[0], (ushort)(who.pos[1] - 16), who.pos[2], who.rot[0], who.rot[1]); } } else { unchecked { p.SendPos((byte)-1, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1]); } } } else if (p.possess != "") { Player who = Player.Find(p.possess); if (who == null || who.level != p.level) { p.possess = ""; } } ushort x = (ushort)(p.pos[0] / 32); ushort y = (ushort)(p.pos[1] / 32); ushort z = (ushort)(p.pos[2] / 32); if (p.level.Death) { p.RealDeath(x, y, z); } p.CheckBlock(x, y, z); p.oldBlock = (ushort)(x + y + z); } catch (Exception e) { Server.ErrorLog(e); } } } })); locationChecker.Start(); Log("Finished setting up " + Server.name + "."); }); }
public override void Use(Player p, string message) { if (message == "" || message.Split(' ').Length > 2) { Help(p); return; } int pos = message.IndexOf(' '); if (pos != -1) { Player who = Player.Find(message.Substring(0, pos)); if (who == null) { Player.SendMessage(p, "There is no player \"" + message.Substring(0, pos) + "\"!"); return; } if (message.Substring(pos + 1) == "del") { MySQL.executeQuery("UPDATE Players SET color = '' WHERE name = '" + who.name + "'"); Player.GlobalChat(who, who.color + "*" + Name(who.name) + " color reverted to " + who.group.color + "their group's default" + Server.DefaultColor + ".", false); who.color = who.group.color; Player.GlobalDie(who, false); Player.GlobalSpawn(who, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1], false); who.SetPrefix(); return; } string color = c.Parse(message.Substring(pos + 1)); if (color == "") { Player.SendMessage(p, "There is no color \"" + message + "\"."); } else if (color == who.color) { Player.SendMessage(p, who.name + " already has that color."); } else { //Player.GlobalChat(who, p.color + "*" + p.name + "&e changed " + who.color + Name(who.name) + // " color to " + color + // c.Name(color) + "&e.", false); MySQL.executeQuery("UPDATE Players SET color = '" + c.Name(color) + "' WHERE name = '" + who.name + "'"); Player.GlobalChat(who, who.color + "*" + Name(who.name) + " color changed to " + color + c.Name(color) + Server.DefaultColor + ".", false); who.color = color; Player.GlobalDie(who, false); Player.GlobalSpawn(who, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1], false); who.SetPrefix(); } } else { if (message == "del") { MySQL.executeQuery("UPDATE Players SET color = '' WHERE name = '" + p.name + "'"); Player.GlobalChat(p, p.color + "*" + Name(p.name) + " color reverted to " + p.group.color + "their group's default" + Server.DefaultColor + ".", false); p.color = p.group.color; Player.GlobalDie(p, false); Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false); p.SetPrefix(); return; } string color = c.Parse(message); if (color == "") { Player.SendMessage(p, "There is no color \"" + message + "\"."); } else if (color == p.color) { Player.SendMessage(p, "You already have that color."); } else { MySQL.executeQuery("UPDATE Players SET color = '" + c.Name(color) + "' WHERE name = '" + p.name + "'"); Player.GlobalChat(p, p.color + "*" + Name(p.name) + " color changed to " + color + c.Name(color) + Server.DefaultColor + ".", false); p.color = color; Player.GlobalDie(p, false); Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false); p.SetPrefix(); } } }
public override void Use(Player p, string message) { if (message == "") { Help(p); return; } if (message[0] == '@') { message = message.Remove(0, 1).Trim(); Player who = Player.Find(message); if (who == null) { DataTable ip; int tryCounter = 0; rerun : try { ip = MySQL.fillData("SELECT IP FROM Players WHERE Name = '" + message + "'"); } catch (Exception e) { tryCounter++; if (tryCounter < 10) { goto rerun; } else { Server.ErrorLog(e); Player.SendMessage(p, "There was a database error fetching the IP address. It has been logged."); return; } } if (ip.Rows.Count > 0) { message = ip.Rows[0]["IP"].ToString(); } else { Player.SendMessage(p, "Unable to find an IP address for that user."); return; } ip.Dispose(); } else { message = who.ip; } } if (!regex.IsMatch(message)) { Player.SendMessage(p, "Not a valid ip!"); return; } if (p != null) { if (p.ip == message) { Player.SendMessage(p, "You shouldn't be able to use this command..."); return; } } if (!Server.bannedIP.Contains(message)) { Player.SendMessage(p, message + " doesn't seem to be banned..."); return; } Player.GlobalMessage(message + " got &8unip-banned" + Server.DefaultColor + "!"); Server.bannedIP.Remove(message); Server.bannedIP.Save("banned-ip.txt", false); Server.s.Log("IP-UNBANNED: " + message.ToLower()); }
public override void Use(Player p, string message) { CatchPos cpos; if (message == "") { p.ZoneCheck = true; Player.SendMessage(p, "Place a block where you would like to check for zones."); return; } else if (p.group.Permission < LevelPermission.Operator) { Player.SendMessage(p, "Reserved for OP+"); return; } if (message.IndexOf(' ') == -1) { switch (message.ToLower()) { case "del": p.zoneDel = true; Player.SendMessage(p, "Place a block where you would like to delete a zone."); return; default: Help(p); return; } } if (message.ToLower() == "del all") { if (p.group.Permission < LevelPermission.Admin) { Player.SendMessage(p, "Only a SuperOP may delete all zones at once"); return; } else { for (int i = 0; i < p.level.ZoneList.Count; i++) { Level.Zone Zn = p.level.ZoneList[i]; MySQL.executeQuery("DELETE FROM `Zone" + p.level.name + "` WHERE Owner='" + Zn.Owner + "' AND SmallX='" + Zn.smallX + "' AND SMALLY='" + Zn.smallY + "' AND SMALLZ='" + Zn.smallZ + "' AND BIGX='" + Zn.bigX + "' AND BIGY='" + Zn.bigY + "' AND BIGZ='" + Zn.bigZ + "'"); Player.SendMessage(p, "Zone deleted for &b" + Zn.Owner); p.level.ZoneList.Remove(p.level.ZoneList[i]); if (i == p.level.ZoneList.Count) { Player.SendMessage(p, "Finished removing all zones"); return; } i--; } } } if (p.group.Permission < LevelPermission.Operator) { Player.SendMessage(p, "Setting zones is reserved for OP+"); return; } if (Group.Find(message.Split(' ')[1]) != null) { message = message.Split(' ')[0] + " grp" + Group.Find(message.Split(' ')[1]).name; } if (message.Split(' ')[0].ToLower() == "add") { Player foundPlayer = Player.Find(message.Split(' ')[1]); if (foundPlayer == null) { cpos.Owner = message.Split(' ')[1].ToString(); } else { cpos.Owner = foundPlayer.name; } } else { Help(p); return; } if (!Player.ValidName(cpos.Owner)) { Player.SendMessage(p, "INVALID NAME."); return; } cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos; Player.SendMessage(p, "Place two blocks to determine the edges."); Player.SendMessage(p, "Zone for: &b" + cpos.Owner + "."); p.ClearBlockchange(); p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); }
public override void Use(Player p, string message) { if (message == "") { Help(p); return; } int pos = message.IndexOf(' '); Player who = Player.Find(message.Split(' ')[0]); if (who == null) { Player.SendMessage(p, "Could not find player."); return; } string query; string newTitle = ""; if (message.Split(' ').Length > 1) { newTitle = message.Substring(pos + 1); } else { who.title = ""; who.SetPrefix(); Player.GlobalChat(null, who.color + who.name + Server.DefaultColor + " had their title removed.", false); query = "UPDATE Players SET Title = '' WHERE Name = '" + who.name + "'"; MySQL.executeQuery(query); return; } if (newTitle != "") { newTitle = newTitle.ToString().Trim().Replace("[", ""); newTitle = newTitle.Replace("]", ""); /* if (newTitle[0].ToString() != "[") newTitle = "[" + newTitle; * if (newTitle.Trim()[newTitle.Trim().Length - 1].ToString() != "]") newTitle = newTitle.Trim() + "]"; * if (newTitle[newTitle.Length - 1].ToString() != " ") newTitle = newTitle + " "; */ } if (newTitle.Length > 17) { Player.SendMessage(p, "Title must be under 17 letters."); return; } if (!Server.devs.Contains(p.name)) { if (Server.devs.Contains(who.name) || newTitle.ToLower() == "dev") { Player.SendMessage(p, "Can't let you do that, starfox."); return; } } if (newTitle != "") { Player.GlobalChat(null, who.color + who.name + Server.DefaultColor + " was given the title of &b[" + newTitle + "]", false); } else { Player.GlobalChat(null, who.color + who.prefix + who.name + Server.DefaultColor + " had their title removed.", false); } if (newTitle == "") { query = "UPDATE Players SET Title = '' WHERE Name = '" + who.name + "'"; } else { query = "UPDATE Players SET Title = '" + newTitle.Replace("'", "\'") + "' WHERE Name = '" + who.name + "'"; } MySQL.executeQuery(query); who.title = newTitle; who.SetPrefix(); }