/// <summary> Find partial matches of 'name' against the list of ranks. </summary> public static Group FindRanks(Player p, string name) { Group.MapName(ref name); int matches; return(Find(p, name, out matches, Group.GroupList, null, g => Colors.Strip(g.Name), "ranks")); }
void PlayerChat(Player p, string message) { if (p.cancelchat || !p.level.Config.ServerWideChat) { return; } message = config.DiscordPrefix + config.DiscordMessage.Replace("{name}", p.DisplayName).Replace("{msg}", message); SendMessage(Colors.Strip(message)); }
void ModAction(ModAction e) { if (!e.Announce) { return; } string message = config.DisconnectPrefix + e.FormatMessage(e.Target, GetActionType(e.Type)); SendMessage(Colors.Strip(message)); }
static string Reduce(string text) { text = text.ToLower(); text = Colors.Strip(text); for (int i = 0; i < reduceKeys.Length; i++) { text = text.Replace(reduceKeys[i], reduceValues[i]); } return(text); }
static void FlushCache(string path, Queue <string> cache) { //TODO: not happy about constantly opening and closing a stream like this but I suppose its ok (Pidgeon) using (StreamWriter w = new StreamWriter(path, true)) { while (cache.Count > 0) { string item = cache.Dequeue(); item = Colors.Strip(item); w.WriteLine(item); } } }
void PlayerConnect(Player p) { SetPresence(); if (p.hidden) { return; } string message = config.DiscordPrefix + config.ConnectPrefix + " " + p.DisplayName + " " + PlayerDB.GetLoginMessage(p); SendMessage(Colors.Strip(message)); }
public static Team Find(string name) { name = Colors.Strip(name); foreach (Team team in Teams) { string teamName = Colors.Strip(team.Name); if (name.CaselessEq(teamName)) { return(team); } } return(null); }
void PlayerDisconnect(Player p, string reason) { SetPresence(); if (p.hidden) { return; } if (reason == null) { reason = PlayerDB.GetLogoutMessage(p); } string message = config.DiscordPrefix + config.DisconnectPrefix + " " + p.DisplayName + " " + reason; SendMessage(Colors.Strip(message)); }
const int MAX_LOG_SIZE = 1024 * 1024 * 1024; // 1 GB static void FlushCache(string path, Queue <string> cache) { //TODO: not happy about constantly opening and closing a stream like this but I suppose its ok (Pidgeon) using (StreamWriter w = new StreamWriter(path, true)) { // Failsafe in case something has gone catastrophically wrong if (w.BaseStream.Length > MAX_LOG_SIZE) { cache.Clear(); return; } while (cache.Count > 0) { string item = cache.Dequeue(); item = Colors.Strip(item); w.WriteLine(item); } } }
static void Append(GroupPlayers list, Player p, bool showmaps) { StringBuilder data = list.builder; data.Append(' '); if (p.voice) { data.Append("+").Append(list.group.Color); } data.Append(Colors.Strip(Player.Console.FormatNick(p))); if (p.muted) { data.Append("-muted"); } if (p.frozen) { data.Append("-frozen"); } if (p.Game.Referee) { data.Append("-ref"); } if (p.IsAfk) { data.Append("-afk"); } if (p.Unverified) { data.Append("-unverified"); } if (!showmaps) { data.Append(","); return; } string lvlName = Colors.Strip(p.level.name); // for museums data.Append(" (").Append(lvlName).Append("),"); }
void PlayerCommand(Player p, string cmd, string args, CommandData data) { if (cmd != "hide") { return; } // Offset the player count by one if player is going to hide // Has to be done because this event is called before /hide is called if (p.hidden) { SetPresence(1); string message = config.DiscordPrefix + config.ConnectPrefix + " " + p.DisplayName + " " + PlayerDB.GetLoginMessage(p); SendMessage(Colors.Strip(message)); } else { SetPresence(-1); string message = config.DiscordPrefix + config.DisconnectPrefix + " " + p.DisplayName + " " + PlayerDB.GetLogoutMessage(p); SendMessage(Colors.Strip(message)); } }
/// <summary> Attempts to change the nickname of the target player </summary> /// <remarks> Not allowed when players who cannot speak (e.g. muted) </remarks> public static bool SetNick(Player p, string target, string nick) { if (Colors.Strip(nick).Length >= 30) { p.Message("Nick must be under 30 letters."); return(false); } Player who = PlayerInfo.FindExact(target); if (nick.Length == 0) { MessageAction(p, target, who, "λACTOR &Sremoved λTARGET nick"); nick = Server.ToRawUsername(target); } else { if (!p.CheckCanSpeak("change nicks")) { return(false); } // TODO: select color from database? string color = who != null ? who.color : Group.GroupIn(target).Color; MessageAction(p, target, who, "λACTOR &Schanged λTARGET nick to " + color + nick); } if (who != null) { who.DisplayName = nick; } if (who != null) { TabList.Update(who, true); } PlayerDB.SetNick(target, nick); return(true); }
public static byte[] MakeHackControl(Player p, string motd) { motd = Colors.Strip(motd); bool isOp = p.Rank >= LevelPermission.Operator; bool fly = true, noclip = true, speed = true, respawn = true, _3rdPerson = true; short maxJump = -1; string[] parts = motd.SplitSpaces(); for (int i = 0; i < parts.Length; i++) { string part = parts[i]; if (part.CaselessEq("-hax")) { fly = false; noclip = false; speed = false; respawn = false; _3rdPerson = false; } if (part.CaselessEq("-hax")) { fly = false; noclip = false; speed = false; respawn = false; _3rdPerson = false; } else if (part.CaselessEq("-ophax") && isOp) { fly = false; noclip = false; speed = false; respawn = false; _3rdPerson = false; } else if (part.CaselessEq("+ophax") && isOp) { fly = true; noclip = true; speed = true; respawn = true; _3rdPerson = true; } if (part.CaselessEq("+noclip")) { noclip = true; } else if (part.CaselessEq("+fly")) { fly = true; } else if (part.CaselessEq("+speed")) { speed = true; } else if (part.CaselessEq("+respawn")) { respawn = true; } else if (part.CaselessEq("+thirdperson")) { _3rdPerson = true; } if (part.CaselessEq("-noclip")) { noclip = false; } else if (part.CaselessEq("-fly")) { fly = false; } else if (part.CaselessEq("-speed")) { speed = false; } else if (part.CaselessEq("-respawn")) { respawn = false; } else if (part.CaselessEq("-thirdperson")) { _3rdPerson = false; } if (!part.CaselessStarts("jumpheight=")) { continue; } string heightPart = part.Substring(part.IndexOf('=') + 1); float value; if (Utils.TryParseDecimal(heightPart, out value)) { maxJump = (short)(value * 32); } } return(Packet.HackControl(fly, noclip, speed, respawn, _3rdPerson, maxJump)); }
static void ParseProperty(string key, string value, ref Group temp) { string raw = value; // for prefix we need to keep space value = value.Trim(); if (key.CaselessEq("rankname")) { if (temp != null) { AddGroup(ref temp); } value = value.Replace(" ", ""); if (value.CaselessEq("op")) { Logger.Log(LogType.Warning, "Cannot have a rank named \"{0}\", this rank is hard-coded.", value); } else if (Group.Find(value) == null) { temp = new Group(); temp.Name = value; } else { Logger.Log(LogType.Warning, "Cannot add the rank {0} twice", value); } return; } if (temp == null) { return; } switch (key.ToLower()) { case "permission": int perm; if (!int.TryParse(value, out perm)) { Logger.Log(LogType.Warning, "Invalid permission: " + value); temp = null; } if (perm > 120 || perm < -50) { Logger.Log(LogType.Warning, "Permission must be between -50 and 120 for ranks"); temp = null; } else if (Group.Find((LevelPermission)perm) == null) { temp.Permission = (LevelPermission)perm; } else { Logger.Log(LogType.Warning, "Cannot have 2 ranks set at permission level " + value); temp = null; } break; case "limit": temp.DrawLimit = int.Parse(value); break; case "maxundo": temp.MaxUndo = int.Parse(value); break; case "genvolume": temp.GenVolume = int.Parse(value); break; case "afkkicked": temp.AfkKicked = bool.Parse(value); break; case "afkkickminutes": temp.AfkKickMinutes = int.Parse(value); break; case "color": char col; char.TryParse(value, out col); if (Colors.IsDefined(col)) { temp.Color = "&" + col; } else { Logger.Log(LogType.Warning, "Invalid color code: " + value); temp = null; } break; case "filename": if (value.Contains("\\") || value.Contains("/")) { Logger.Log(LogType.Warning, "Invalid filename: " + value); temp = null; } else { temp.filename = value; } break; case "motd": temp.MOTD = value; break; case "osmaps": temp.OverseerMaps = byte.Parse(value); break; case "prefix": if (!String.IsNullOrEmpty(value)) { temp.Prefix = raw.TrimStart(); } if (Colors.Strip(temp.Prefix).Length > 3) { Logger.Log(LogType.Warning, "Prefixes may only consist of color codes and three letters"); temp.Prefix = temp.Prefix.Substring(0, 3); } break; case "copyslots": temp.CopySlots = byte.Parse(value); break; } }
static string TokenName(Player p) { return((Server.Config.DollarNames ? "$" : "") + Colors.Strip(p.DisplayName)); }