static bool ChangeReason(string who, string reason, PlayerMetaList list) { who = who.ToLower(); reason = reason.Replace(" ", "%20"); bool success = false; StringBuilder sb = new StringBuilder(); foreach (string line in File.ReadAllLines(list.file)) { string[] parts = line.Split(' '); if (parts.Length > 2 && parts[1] == who) { parts[2] = CP437Writer.ConvertToUnicode(reason); success = true; sb.AppendLine(String.Join(" ", parts)); } else { sb.AppendLine(line); } } if (success) { File.WriteAllText(list.file, sb.ToString()); } return(success); }
public void OpLog(string message, bool systemMsg = false) { message = CP437Writer.ConvertToUnicode(message); if (ServerOpLog != null) { OpLog(message); if (canceloplog) { canceloplog = false; return; } } if (OnOp != null) { if (!systemMsg) { OnOp(DateTime.Now.ToString("(HH:mm:ss) ") + message); } else { OnSystem(DateTime.Now.ToString("(HH:mm:ss) ") + message); } } Logger.Write(DateTime.Now.ToString("(HH:mm:ss) ") + message + Environment.NewLine); }
public static void Serialise(ConfigElement[] elements, string suffix, CP437Writer dst, object instance) { Dictionary <string, List <ConfigElement> > sections = new Dictionary <string, List <ConfigElement> >(); foreach (ConfigElement elem in elements) { List <ConfigElement> members; if (!sections.TryGetValue(elem.Attrib.Section, out members)) { members = new List <ConfigElement>(); sections[elem.Attrib.Section] = members; } members.Add(elem); } foreach (var kvp in sections) { dst.WriteLine("# " + kvp.Key + suffix); foreach (ConfigElement elem in kvp.Value) { object value = elem.Field.GetValue(instance); dst.WriteLine(elem.Attrib.Name + " = " + elem.Attrib.Serialise(value)); } dst.WriteLine(); } }
public void AdminLog(string message, bool systemMsg = false) { message = CP437Writer.ConvertToUnicode(message); if (ServerAdminLog != null) { ServerAdminLog(message); if (canceladmin) { canceladmin = false; return; } } string now = DateTime.Now.ToString("(HH:mm:ss) "); if (OnAdmin != null) { if (!systemMsg) { OnAdmin(now + message); } else { OnSystem(now + message); } } Logger.Write(now + message + Environment.NewLine); }
internal static void LoadCustom() { CustomTokens.Clear(); if (File.Exists("text/custom$s.txt")) { using (CP437Reader r = new CP437Reader("text/custom$s.txt")) { string line; while ((line = r.ReadLine()) != null) { if (line.StartsWith("//")) { continue; } string[] split = line.Split(new[] { ':' }, 2); if (split.Length == 2 && !String.IsNullOrEmpty(split[0])) { CustomTokens.Add(split[0], split[1]); } } } } else { Server.s.Log("custom$s.txt does not exist, creating"); using (CP437Writer w = new CP437Writer("text/custom$s.txt")) { w.WriteLine("// This is used to create custom $s"); w.WriteLine("// If you start the line with a // it wont be used"); w.WriteLine("// It should be formatted like this:"); w.WriteLine("// $website:http://example.org"); w.WriteLine("// That would replace '$website' in any message to 'http://example.org'"); w.WriteLine("// It must not start with a // and it must not have a space between the 2 sides and the colon (:)"); } } }
void LoginTimerElapsed(object sender, ElapsedEventArgs e) { if (!Loading) { loginTimer.Stop(); if (File.Exists("text/welcome.txt")) { try { List <string> welcome = CP437Reader.ReadAllLines("text/welcome.txt"); foreach (string w in welcome) { SendMessage(w); } } catch { } } else { Server.s.Log("Could not find Welcome.txt. Using default."); CP437Writer.WriteAllText("text/welcome.txt", "Welcome to my server!"); SendMessage("Welcome to my server!"); } loginTimer.Dispose(); extraTimer.Start(); } }
public static void AppendLine(string file, string text) { using (CP437Writer writer = new CP437Writer(file, true)) { writer.Write(text); writer.WriteLine(); } }
/// <summary> Change the ban reason for the given user. </summary> public static string EditReason(string who, string reason) { who = who.ToLower(); reason = reason.Replace(" ", "%20"); bool found = false; StringBuilder sb = new StringBuilder(); foreach (string line in File.ReadAllLines("text/bans.txt")) { string[] parts = line.Split(' '); if (parts.Length > 2 && parts[1] == who) { parts[2] = CP437Writer.ConvertToUnicode(reason); found = true; sb.Append(String.Join(" ", parts) + "\r\n"); } else { sb.Append(line + "\r\n"); } } if (found) { File.WriteAllText("text/bans.txt", sb.ToString()); return(""); } return("This player isn't banned!"); }
public void Log(string message, bool systemMsg = false) { message = CP437Writer.ConvertToUnicode(message); if (ServerLog != null) { ServerLog(message); if (cancellog) { cancellog = false; return; } } if (!systemMsg) { OnServerLogEvent.Call(message); } string now = DateTime.Now.ToString("(HH:mm:ss) "); if (!systemMsg && OnLog != null) { OnLog(now + message); } if (systemMsg && OnSystem != null) { OnSystem(now + message); } Logger.Write(now + message + Environment.NewLine); }
/// <summary> Save givenList group </summary> /// <param name="givenList">The list of groups to save</param> public static void SaveGroups(List <Group> givenList) { using (CP437Writer w = new CP437Writer(filename)) { w.WriteLine("#Version 3"); w.WriteLine("#RankName = string"); w.WriteLine("#\tThe name of the rank, use capitalization."); w.WriteLine("#"); w.WriteLine("#Permission = num"); w.WriteLine("#\tThe \"permission\" of the rank. It's a number."); w.WriteLine("#\tThere are pre-defined permissions already set. (for the old ranks)"); w.WriteLine("#\t\tBanned = -20, Guest = 0, Builder = 30, AdvBuilder = 50, Operator = 80"); w.WriteLine("#\t\tSuperOP = 100, Nobody = 120"); w.WriteLine("#\tMust be greater than -50 and less than 120"); w.WriteLine("#\tThe higher the number, the more commands do (such as undo allowing more seconds)"); w.WriteLine("#Limit = num"); w.WriteLine("#\tThe command limit for the rank (can be changed in-game with /limit)"); w.WriteLine("#\tMust be greater than 0 and less than 10000000"); w.WriteLine("#MaxUndo = num"); w.WriteLine("#\tThe undo limit for the rank, only applies when undoing others."); w.WriteLine("#\tMust be greater than 0 and less than " + int.MaxValue); w.WriteLine("#Color = char"); w.WriteLine("#\tA single letter or number denoting the color of the rank"); w.WriteLine("#\tPossibilities: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f"); w.WriteLine("#FileName = string.txt"); w.WriteLine("#\tThe file which players of this rank will be stored in"); w.WriteLine("#\t\tIt doesn't need to be a .txt file, but you may as well"); w.WriteLine("#\t\tGenerally a good idea to just use the same file name as the rank name"); w.WriteLine("#MOTD = string"); w.WriteLine("#\tAlternate MOTD players of the rank will see when joining the server."); w.WriteLine("#\tLeave blank to use the server MOTD."); w.WriteLine("#OSMaps = num"); w.WriteLine("#\tThe number of maps the players will have in /os"); w.WriteLine("#\tDefaults to 2 if invalid number (number has to be between 0-128"); w.WriteLine("#Prefix = string"); w.WriteLine("#\tCharacters that appear directly before a player's name in chat."); w.WriteLine("#\tLeave blank to have no characters before the names of players."); w.WriteLine(); w.WriteLine(); foreach (Group grp in givenList) { if (grp.name == "nobody") { continue; } w.WriteLine("RankName = " + grp.trueName); w.WriteLine("Permission = " + (int)grp.Permission); w.WriteLine("Limit = " + grp.maxBlocks); w.WriteLine("MaxUndo = " + grp.maxUndo); w.WriteLine("Color = " + grp.color[1]); w.WriteLine("MOTD = " + grp.MOTD); w.WriteLine("FileName = " + grp.fileName); w.WriteLine("OSMaps = " + grp.OverseerMaps); w.WriteLine("Prefix = " + grp.prefix); w.WriteLine(); } } }
public static void WriteAllLines(string file, string[] lines) { using (CP437Writer writer = new CP437Writer(file)) { for (int i = 0; i < lines.Length; i++) { writer.Write(lines[i]); writer.WriteLine(); } } }
public static void AppendInfectMessage(string name, string value) { if (!Directory.Exists("text/infect")) { Directory.CreateDirectory("text/infect"); } CP437Writer.AppendLine("text/infect/" + name.ToLower() + ".txt", value); }
public static void AppendInfectMessage(string name, string value) { if (!Directory.Exists("text/infect")) { Directory.CreateDirectory("text/infect"); } CP437Writer.AppendLine(InfectPath(name), value); }
public void CommandUsed(string message) { message = CP437Writer.ConvertToUnicode(message); if (OnCommand != null) { OnCommand(DateTime.Now.ToString("(HH:mm:ss) ") + message); } Logger.Write(DateTime.Now.ToString("(HH:mm:ss) ") + message + Environment.NewLine); }
/// <summary> Adds the given line to the end of the file. </summary> public void Append(string data) { string line = CP437Writer.ConvertToUnicode(data); lock (locker) { using (StreamWriter w = new StreamWriter(file, true)) w.WriteLine(line); } }
public static void Save(string givenPath) { try { lock (saveLock) { using (CP437Writer w = new CP437Writer(givenPath)) SaveProps(w); } } catch (Exception ex) { Server.ErrorLog(ex); Server.s.Log("SAVE FAILED! " + givenPath); } }
static string ConvertMessage(string message, bool color) { if (String.IsNullOrEmpty(message.Trim())) { message = "."; } message = CP437Writer.ConvertToUnicode(message); if (color) { message = Colors.MinecraftToIrcColors(message.Replace("%r", ResetSignal)); } return(message); }
public static void SaveAwards() { lock (awardLock) using (CP437Writer w = new CP437Writer("text/awardsList.txt")) { w.WriteLine("# This is a full list of awards. The server will load these and they can be awarded as you please"); w.WriteLine("# Format is:"); w.WriteLine("# AwardName : Description of award goes after the colon"); w.WriteLine(); foreach (Award award in AwardsList) { w.WriteLine(award.Name + " : " + award.Description); } } }
static string ConvertMessage(string message, bool color) { if (String.IsNullOrEmpty(message.Trim())) { message = "."; } message = EmotesHandler.Replace(message); message = FullCP437Handler.Replace(message); message = ChatTokens.ApplyCustom(message); message = CP437Writer.ConvertToUnicode(message); if (color) { message = Colors.MinecraftToIrcColors(message.Replace("%S", ResetSignal)); } return(message); }
public static void Load() { if (!File.Exists("text/awardsList.txt")) { using (CP437Writer w = new CP437Writer("text/awardsList.txt")) { w.WriteLine("#This is a full list of awards. The server will load these and they can be awarded as you please"); w.WriteLine("#Format is:"); w.WriteLine("# AwardName : Description of award goes after the colon"); w.WriteLine(); w.WriteLine("Gotta start somewhere : Built your first house"); w.WriteLine("Climbing the ladder : Earned a rank advancement"); w.WriteLine("Do you live here? : Joined the server a huge bunch of times"); } } AwardsList = new List <Award>(); PropertiesFile.Read("text/awardsList.txt", AwardsListLineProcessor, ':'); PlayerAwards = new List <PlayerAward>(); PropertiesFile.Read("text/playerAwards.txt", PlayerAwardsLineProcessor, ':'); }
public static void SetLoginMessage(string name, string value) { CP437Writer.WriteAllText(LoginPath(name), value); }
public static void WriteAllText(string file, string text) { using (CP437Writer writer = new CP437Writer(file)) writer.Write(text); }
public void RankReason(DateTime when, string type, string group, string reason, string assigner) { if (!Directory.Exists("ranks/reasons")) Directory.CreateDirectory("ranks/reasons"); string path = "ranks/reasons/" + this.name + ".txt"; if (!File.Exists(path)) File.Create(path).Dispose(); try { using (CP437Writer sw = new CP437Writer(path, true)) { sw.WriteLine(Server.DefaultColor + "[" + when.Day + "." + when.Month + "." + when.Year + "] " + type + Server.DefaultColor + " - " + GetColor(this.name) + group + Server.DefaultColor + " : \"" + reason + "\" by " + GetColor(assigner) + assigner); } } catch { Server.s.Log("Error saving RankReason!"); } }
static void SaveProps(CP437Writer w) { w.WriteLine("# Edit the settings below to modify how your server operates. This is an explanation of what each setting does."); w.WriteLine("# server-name = The name which displays on classicube.net"); w.WriteLine("# motd = The message which displays when a player connects"); w.WriteLine("# port = The port to operate from"); w.WriteLine("# console-only = Run without a GUI (useful for Linux servers with mono)"); w.WriteLine("# verify-names = Verify the validity of names"); w.WriteLine("# public = Set to true to appear in the public server list"); w.WriteLine("# max-players = The maximum number of connections"); w.WriteLine("# max-guests = The maximum number of guests allowed"); w.WriteLine("# max-maps = The maximum number of maps loaded at once"); w.WriteLine("# world-chat = Set to true to enable world chat"); w.WriteLine("# irc = Set to true to enable the IRC bot"); w.WriteLine("# irc-nick = The name of the IRC bot"); w.WriteLine("# irc-server = The server to connect to"); w.WriteLine("# irc-channel = The channel to join"); w.WriteLine("# irc-opchannel = The channel to join (posts OpChat)"); w.WriteLine("# irc-port = The port to use to connect"); w.WriteLine("# irc-identify = (true/false) Do you want the IRC bot to Identify itself with nickserv. Note: You will need to register it's name with nickserv manually."); w.WriteLine("# irc-password = The password you want to use if you're identifying with nickserv"); w.WriteLine("# anti-tunnels = Stops people digging below max-depth"); w.WriteLine("# max-depth = The maximum allowed depth to dig down"); w.WriteLine("# backup-time = The number of seconds between automatic backups"); w.WriteLine("# overload = The higher this is, the longer the physics is allowed to lag. Default 1500"); w.WriteLine("# use-whitelist = Switch to allow use of a whitelist to override IP bans for certain players. Default false."); w.WriteLine("# premium-only = Only allow premium players (paid for minecraft) to access the server. Default false."); w.WriteLine("# force-cuboid = Run cuboid until the limit is hit, instead of canceling the whole operation. Default false."); w.WriteLine("# profanity-filter = Replace certain bad words in the chat. Default false."); w.WriteLine("# notify-on-join-leave = Show a balloon popup in tray notification area when a player joins/leaves the server. Default false."); w.WriteLine("# allow-tp-to-higher-ranks = Allows the teleportation to players of higher ranks"); w.WriteLine("# agree-to-rules-on-entry = Forces all new players to the server to agree to the rules before they can build or use commands."); w.WriteLine("# adminchat-perm = The rank required to view adminchat. Default rank is superop."); w.WriteLine("# admins-join-silent = Players who have adminchat permission join the game silently. Default true"); w.WriteLine("# server-owner = The minecraft name, of the owner of the server."); w.WriteLine("# zombie-on-server-start = Starts Zombie Survival when server is started."); w.WriteLine("# no-respawning-during-zombie = Disables respawning (Pressing R) while Zombie is on."); w.WriteLine("# no-pillaring-during-zombie = Disables pillaring while Zombie Survival is activated."); w.WriteLine("# zombie-name-while-infected = Sets the zombies name while actived if there is a value."); w.WriteLine("# enable-changing-levels = After a Zombie Survival round has finished, will change the level it is running on."); w.WriteLine("# zombie-survival-only-server = EXPERIMENTAL! Makes the server only for Zombie Survival (etc. changes main level)"); w.WriteLine("# use-level-list = Only gets levels for changing levels in Zombie Survival from zombie-level-list."); w.WriteLine("# zombie-level-list = List of levels for changing levels (Must be comma seperated, no spaces. Must have changing levels and use level list enabled.)"); w.WriteLine("# total-undo = Track changes made by the last X people logged on for undo purposes. Folder is rotated when full, so when set to 200, will actually track around 400."); w.WriteLine("# guest-limit-notify = Show -Too Many Guests- message in chat when maxGuests has been reached. Default false"); w.WriteLine("# guest-join-notify = Shows when guests and lower ranks join server in chat and IRC. Default true"); w.WriteLine("# guest-leave-notify = Shows when guests and lower ranks leave server in chat and IRC. Default true"); w.WriteLine(); w.WriteLine("# UseMySQL = Use MySQL (true) or use SQLite (false)"); w.WriteLine("# Host = The host name for the database (usually 127.0.0.1)"); w.WriteLine("# SQLPort = Port number to be used for MySQL. Unless you manually changed the port, leave this alone. Default 3306."); w.WriteLine("# Username = The username you used to create the database (usually root)"); w.WriteLine("# Password = The password set while making the database"); w.WriteLine("# DatabaseName = The name of the database stored (Default = MCZall)"); w.WriteLine(); w.WriteLine("# defaultColor = The color code of the default messages (Default = &e)"); w.WriteLine(); w.WriteLine("# kick-on-hackrank = Set to true if hackrank should kick players"); w.WriteLine("# hackrank-kick-time = Number of seconds until player is kicked"); w.WriteLine("# custom-rank-welcome-messages = Decides if different welcome messages for each rank is enabled. Default true."); w.WriteLine("# ignore-ops = Decides whether or not an operator can be ignored. Default false."); w.WriteLine(); w.WriteLine("# admin-verification = Determines whether admins have to verify on entry to the server. Default true."); w.WriteLine("# verify-admin-perm = The minimum rank required for admin verification to occur."); w.WriteLine(); w.WriteLine("# mute-on-spam = If enabled it mutes a player for spamming. Default false."); w.WriteLine("# spam-messages = The amount of messages that have to be sent \"consecutively\" to be muted."); w.WriteLine("# spam-mute-time = The amount of seconds a player is muted for spam."); w.WriteLine("# spam-counter-reset-time = The amount of seconds the \"consecutive\" messages have to fall between to be considered spam."); w.WriteLine(); w.WriteLine("# As an example, if you wanted the spam to only mute if a user posts 5 messages in a row within 2 seconds, you would use the folowing:"); w.WriteLine("# mute-on-spam = true"); w.WriteLine("# spam-messages = 5"); w.WriteLine("# spam-mute-time = 60"); w.WriteLine("# spam-counter-reset-time = 2"); w.WriteLine("# bufferblocks = Should buffer blocks by default for maps?"); w.WriteLine(); ConfigElement.Serialise(Server.serverConfig, " options", w, null); }
public static void SetLogoutMessage(string name, string value) { CP437Writer.WriteAllText("text/logout/" + name.ToLower() + ".txt", value); }