static void HandleTime(string userNick, string name) { if (name == null) { IRC.SendChannelMessage("Server has been up for: " + Bold + DateTime.UtcNow.Subtract(Server.StartTime).ToMiniString()); return; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(name); if (info == null) { IRC.SendChannelMessage("No player found with name \"" + Bold + name + Reset + "\""); return; } if (info.IsOnline) { TimeSpan idle = info.PlayerObject.IdleTime; IRC.SendChannelMessage("Player " + Bold + "{0}" + Reset + " has spent a total of: " + Bold + "{1:F1}" + Reset + " hours (" + Bold + "{2:F1}" + Reset + " hours this session{3}", info.ClassyName, (info.TotalTime + info.TimeSinceLastLogin).TotalHours, info.TimeSinceLastLogin.TotalHours, idle > TimeSpan.FromMinutes(1) ? ", been idle for " + Bold + string.Format("{0:F2}", idle.TotalMinutes) + Reset + " minutes)" : ")"); } else { IRC.SendChannelMessage("Player " + Bold + "{0}" + Reset + " has spent a total of: " + Bold + "{1:F1}" + Reset + " hours", info.ClassyName, info.TotalTime.TotalHours); } }
/// <summary> /// Changes the skin of the bot /// </summary> public void Clone(String targetSkin) { PlayerInfo target = PlayerDB.FindPlayerInfoExact(targetSkin); if (target == null) { //something went wrong, player doesn't exist } World.Players.Where(p => p.usesCPE).Send(PacketWriter.MakeExtAddEntity((byte)ID, targetSkin, targetSkin)); Skin = targetSkin; }
public SecurityController([NotNull] XContainer el, bool parseExceptions) { if (el == null) { throw new ArgumentNullException("el"); } if (el.Element("minRank") != null) { // ReSharper disable PossibleNullReferenceException minRank = Rank.Parse(el.Element("minRank").Value); // ReSharper restore PossibleNullReferenceException } else { minRank = null; } if (parseExceptions) { //maxRank = Rank.Parse( root.Element( "maxRank" ).Value ); foreach (XElement player in el.Elements("included")) { if (!Player.IsValidName(player.Value)) { continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(player.Value); if (info != null) { Include(info); } } foreach (XElement player in el.Elements("excluded")) { if (!Player.IsValidName(player.Value)) { continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(player.Value); if (info != null) { Exclude(info); } } } else { rawExceptions = el.Elements("included").Union(el.Elements("excluded")).ToArray(); } UpdatePlayerListCache(); }
public SecurityController([NotNull] XContainer el, bool parseExceptions) { if (el == null) { throw new ArgumentNullException("el"); } XElement minRankEl = el.Element("minRank"); if (minRankEl != null) { minRank = Rank.Parse(minRankEl.Value); } else { minRank = null; } if (parseExceptions) { foreach (XElement player in el.Elements("included")) { if (!Player.IsValidPlayerName(player.Value)) { continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(player.Value); if (info != null) { Include(info); } } foreach (XElement player in el.Elements("excluded")) { if (!Player.IsValidPlayerName(player.Value)) { continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(player.Value); if (info != null) { Exclude(info); } } } else { rawExceptions = el.Elements("included").Union(el.Elements("excluded")).ToArray(); } UpdatePlayerListCache(); }
public SecurityController(XElement el) { if (el == null) { throw new ArgumentNullException("el"); } if (el.Element("minRank") != null) { minRank = RankManager.ParseRank(el.Element("minRank").Value); } else { minRank = null; } //maxRank = RankManager.ParseRank( root.Element( "maxRank" ).Value ); foreach (XElement player in el.Elements("included")) { if (!Player.IsValidName(player.Value)) { continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(player.Value); if (info != null) { Include(info); } } foreach (XElement player in el.Elements("excluded")) { if (!Player.IsValidName(player.Value)) { continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(player.Value); if (info != null) { Exclude(info); } } UpdatePlayerListCache(); }
static void HandleBlockDelete(string userNick, string name) { if (name == null) { IRC.SendChannelMessage("Please specify a player name"); return; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(name); if (info == null) { IRC.SendChannelMessage("No player found with name \"" + Bold + name + Reset + "\""); return; } IRC.SendChannelMessage("Player " + Bold + "{0}" + Reset + " has Built: " + Bold + "{1}" + Reset + " blocks Deleted: " + Bold + "{2}" + Reset + " blocks{3}", info.ClassyName, info.BlocksBuilt, info.BlocksDeleted, (info.Can(Permission.Draw) ? " Drawn: " + Bold + info.BlocksDrawnString + Reset + " blocks." : "")); }
public Zone([NotNull] XContainer root) { if (root == null) { throw new ArgumentNullException("root"); } // ReSharper disable PossibleNullReferenceException Name = root.Element("name").Value; if (root.Element("created") != null) { XElement created = root.Element("created"); CreatedBy = PlayerDB.FindPlayerInfoExact(created.Attribute("by").Value); CreatedDate = DateTime.Parse(created.Attribute("on").Value); } if (root.Element("edited") != null) { XElement edited = root.Element("edited"); EditedBy = PlayerDB.FindPlayerInfoExact(edited.Attribute("by").Value); EditedDate = DateTime.Parse(edited.Attribute("on").Value); } XElement temp = root.Element(BoundingBox.XmlRootElementName); if (temp == null) { throw new FormatException("No BoundingBox specified for zone."); } Bounds = new BoundingBox(temp); temp = root.Element(SecurityController.XmlRootElementName); if (temp == null) { throw new FormatException("No SecurityController specified for zone."); } Controller = new SecurityController(temp, true); // ReSharper restore PossibleNullReferenceException }
static void HandleSeen(string userNick, string name) { if (name == null) { IRC.SendChannelMessage("Please specify a player name"); return; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(name); if (info == null) { IRC.SendChannelMessage("No player found with name \"" + Bold + name + Reset + "\""); return; } Player target = info.PlayerObject; if (target != null) { IRC.SendChannelMessage("Player " + Bold + "{0}" + Reset + " has been " + Bold + "&aOnline" + Reset + " for " + Bold + "{1}", target.Info.Rank.Color + target.Name, target.Info.TimeSinceLastLogin.ToMiniString()); if (target.World != null) { IRC.SendChannelMessage("They are currently on world " + Bold + "{0}", target.World.ClassyName); } } else { IRC.SendChannelMessage("Player " + Bold + "{0}" + Reset + " is " + Bold + "&cOffline", info.ClassyName); IRC.SendChannelMessage("They were last seen " + Bold + "{0}" + Reset + " ago on world " + Bold + "{1}", info.TimeSinceLastSeen.ToMiniString(), info.LastWorld); } }
public Zone([NotNull] string raw, [CanBeNull] World world) : this() { if (raw == null) { throw new ArgumentNullException("raw"); } string[] parts = raw.Split(','); string[] header = parts[0].Split(' '); Name = header[0]; Bounds = new BoundingBox(Int32.Parse(header[1]), Int32.Parse(header[2]), Int32.Parse(header[3]), Int32.Parse(header[4]), Int32.Parse(header[5]), Int32.Parse(header[6])); Rank buildRank = Rank.Parse(header[7]); // if all else fails, fall back to lowest class if (buildRank == null) { if (world != null) { Controller.MinRank = world.BuildSecurity.MinRank; } else { Controller.ResetMinRank(); } Logger.Log(LogType.Error, "Zone: Error parsing zone definition: unknown rank \"{0}\". Permission reset to default ({1}).", header[7], Controller.MinRank.Name); } else { Controller.MinRank = buildRank; } // Part 2: foreach (string player in parts[1].Split(' ')) { if (!Player.IsValidName(player)) { continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(player); if (info == null) { continue; // player name not found in the DB (discarded) } Controller.Include(info); } // Part 3: excluded list foreach (string player in parts[2].Split(' ')) { if (!Player.IsValidName(player)) { continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(player); if (info == null) { continue; // player name not found in the DB (discarded) } Controller.Exclude(info); } // Part 4: extended header if (parts.Length > 3) { string[] xheader = parts[3].Split(' '); CreatedBy = PlayerDB.FindPlayerInfoExact(xheader[0]); if (CreatedBy != null) { CreatedDate = DateTime.Parse(xheader[1]); } EditedBy = PlayerDB.FindPlayerInfoExact(xheader[2]); if (EditedBy != null) { EditedDate = DateTime.Parse(xheader[3]); } } }
public Zone([NotNull] string raw, [CanBeNull] World world) : this() { if (raw == null) { throw new ArgumentNullException("raw"); } string[] parts = raw.Split(','); string[] header = parts[0].Split(' '); Name = header[0]; Bounds = new BoundingBox(Int32.Parse(header[1]), Int32.Parse(header[2]), Int32.Parse(header[3]), Int32.Parse(header[4]), Int32.Parse(header[5]), Int32.Parse(header[6])); // If no ranks are loaded (e.g. MapConverter/MapRenderer)( if (RankManager.Ranks.Count > 0) { Rank buildRank = Rank.Parse(header[7]); // if all else fails, fall back to lowest class if (buildRank == null) { if (world != null) { Controller.MinRank = world.BuildSecurity.MinRank; } else { Controller.ResetMinRank(); } Logger.Log(LogType.Error, "Zone: Error parsing zone definition: unknown rank \"{0}\". Permission reset to default ({1}).", header[7], Controller.MinRank.Name); } else { Controller.MinRank = buildRank; } } // If PlayerDB is not loaded (e.g. ConfigGUI) if (PlayerDB.IsLoaded) { // Part 2: if (parts[1].Length > 0) { foreach (string playerName in parts[1].Split(' ')) { if (!Player.IsValidPlayerName(playerName)) { Logger.Log(LogType.Warning, "Invalid entry in zone \"{0}\" whitelist: {1}", Name, playerName); continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName); if (info == null) { Logger.Log(LogType.Warning, "Unrecognized player in zone \"{0}\" whitelist: {1}", Name, playerName); continue; // player name not found in the DB (discarded) } Controller.Include(info); } } // Part 3: excluded list if (parts[2].Length > 0) { foreach (string playerName in parts[2].Split(' ')) { if (!Player.IsValidPlayerName(playerName)) { Logger.Log(LogType.Warning, "Invalid entry in zone \"{0}\" blacklist: {1}", Name, playerName); continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName); if (info == null) { Logger.Log(LogType.Warning, "Unrecognized player in zone \"{0}\" whitelist: {1}", Name, playerName); continue; // player name not found in the DB (discarded) } Controller.Exclude(info); } } } else { RawWhitelist = parts[1]; RawBlacklist = parts[2]; } // Part 4: extended header if (parts.Length > 3) { string[] xheader = parts[3].Split(' '); if (xheader[0] == "-") { CreatedBy = null; CreatedDate = DateTime.MinValue; } else { CreatedBy = xheader[0]; CreatedDate = DateTime.Parse(xheader[1]); } if (xheader[2] == "-") { EditedBy = null; EditedDate = DateTime.MinValue; } else { EditedBy = xheader[2]; EditedDate = DateTime.Parse(xheader[3]); } } }
public Zone([NotNull] string raw, [CanBeNull] World world) : this() { if (raw == null) { throw new ArgumentNullException("raw"); } string[] parts = raw.Split(','); string[] header = parts[0].Split(' '); Name = header[0]; Bounds = new BoundingBox(Int32.Parse(header[1]), Int32.Parse(header[2]), Int32.Parse(header[3]), Int32.Parse(header[4]), Int32.Parse(header[5]), Int32.Parse(header[6])); Rank buildRank = Rank.Parse(header[7]); if (header.Length > 8) { // Part 5: Zone color try { bool zoneShow; if (bool.TryParse(header[8], out zoneShow)) { ShowZone = zoneShow; } Color = header[9]; short zoneAlpha; if (short.TryParse(header[10], out zoneAlpha)) { Alpha = zoneAlpha; } } catch (Exception ex) { Logger.Log(LogType.Error, "Could not load Zone Colors for {0}", Name); Logger.Log(LogType.Error, ex.StackTrace); } } if (header[0].Contains(SpecialZone.Door)) { buildRank = RankManager.DefaultRank; } // if all else fails, fall back to lowest class... ignore door instances if (buildRank == null && !header[0].Contains(SpecialZone.Door)) { if (world != null) { Controller.MinRank = world.BuildSecurity.MinRank; } else { Controller.ResetMinRank(); } Logger.Log(LogType.Error, "Zone: Error parsing zone definition: unknown rank \"{0}\". Permission reset to default ({1}). Ignore this message if you have recently changed rank permissions.", header[7], Controller.MinRank.Name); } else { Controller.MinRank = buildRank; } if (PlayerDB.IsLoaded) { // Part 2: if (parts[1].Length > 0) { foreach (string playerName in parts[1].Split(' ')) { if (!Player.IsValidPlayerName(playerName)) { Logger.Log(LogType.Warning, "Invalid entry in zone \"{0}\" whitelist: {1}", Name, playerName); continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName); if (info == null) { Logger.Log(LogType.Warning, "Unrecognized player in zone \"{0}\" whitelist: {1}", Name, playerName); continue; // player name not found in the DB (discarded) } Controller.Include(info); } } // Part 3: excluded list if (parts[2].Length > 0) { foreach (string playerName in parts[2].Split(' ')) { if (!Player.IsValidPlayerName(playerName)) { Logger.Log(LogType.Warning, "Invalid entry in zone \"{0}\" blacklist: {1}", Name, playerName); continue; } PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName); if (info == null) { Logger.Log(LogType.Warning, "Unrecognized player in zone \"{0}\" whitelist: {1}", Name, playerName); continue; // player name not found in the DB (discarded) } Controller.Exclude(info); } } } else { RawWhitelist = parts[1]; RawBlacklist = parts[2]; } // Part 4: extended header if (parts.Length > 3) { string[] xheader = parts[3].Split(' '); if (xheader[0] == "-") { CreatedBy = null; CreatedDate = DateTime.MinValue; } else { CreatedBy = xheader[0]; CreatedDate = DateTime.Parse(xheader[1]); } if (xheader[2] == "-") { EditedBy = null; EditedDate = DateTime.MinValue; } else { EditedBy = xheader[2]; EditedDate = DateTime.Parse(xheader[3]); } } }
public static void RevertNames() //reverts names for online players. offline players get reverted upon leaving the game { List <PlayerInfo> TDPlayers = new List <PlayerInfo>(PlayerDB.PlayerInfoList.Where(r => (r.isOnBlueTeam || r.isOnRedTeam) && r.IsOnline).ToArray()); for (int i = 0; i < TDPlayers.Count(); i++) { string p1 = TDPlayers[i].Name.ToString(); PlayerInfo pI = PlayerDB.FindPlayerInfoExact(p1); Player p = pI.PlayerObject; if (p != null) { p.iName = null; pI.tempDisplayedName = null; pI.isOnRedTeam = false; pI.isOnBlueTeam = false; pI.isPlayingTD = false; pI.Health = 100; p.entityChanged = true; //reset all special messages if (p.usesCPE) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f")); p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f")); p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&f")); } //undo gunmode (taken from GunHandler.cs) p.GunMode = false; try { foreach (Vector3I block in p.GunCache.Values) { p.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, p.WorldMap.GetBlock(block))); Vector3I removed; p.GunCache.TryRemove(block.ToString(), out removed); } if (p.bluePortal.Count > 0) { int j = 0; foreach (Vector3I block in p.bluePortal) { if (p.WorldMap != null && p.World.IsLoaded) { p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.blueOld[j])); j++; } } p.blueOld.Clear(); p.bluePortal.Clear(); } if (p.orangePortal.Count > 0) { int j = 0; foreach (Vector3I block in p.orangePortal) { if (p.WorldMap != null && p.World.IsLoaded) { p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.orangeOld[j])); j++; } } p.orangeOld.Clear(); p.orangePortal.Clear(); } } catch (Exception ex) { Logger.Log(LogType.SeriousError, "" + ex); } if (p.IsOnline) { p.Message("Your status has been reverted."); } } } }
public SecurityController([NotNull] NbtCompound tag) { if (tag == null) { throw new ArgumentNullException("tag"); } var rankNameTag = tag.Get <NbtString>("MinRank"); if (rankNameTag == null) { throw new SerializationException("MinRank missing"); } minRankName = rankNameTag.Value; minRank = Rank.Parse(minRankName); if (minRank == null) { Logger.Log(LogType.Warning, "Unrecognized rank name: {0}", minRankName); } var whitelistTag = tag.Get <NbtList>("Whitelist"); if (whitelistTag == null) { throw new SerializationException("Whitelist missing"); } var blacklistTag = tag.Get <NbtList>("Blacklist"); if (blacklistTag == null) { throw new SerializationException("Whitelist missing"); } if (PlayerDB.IsLoaded) { foreach (NbtString whitelistNameTag in whitelistTag) { string playerName = whitelistNameTag.Value; PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName); if (info == null) { Logger.Log(LogType.Warning, "Unrecognized player name on a permission whitelist: {0}", playerName); } else { Include(info); } } foreach (NbtString blacklistNameTag in blacklistTag) { string playerName = blacklistNameTag.Value; PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName); if (info == null) { Logger.Log(LogType.Warning, "Unrecognized player name on a permission blacklist: {0}", playerName); } else { Exclude(info); } } } else { rawWhitelist = whitelistTag.Select(nameTag => nameTag.StringValue).ToArray(); rawBlacklist = blacklistTag.Select(nameTag => nameTag.StringValue).ToArray(); } }
internal static void LoadAll() { try { if (!Directory.Exists("./Timers")) { return; } string[] files = Directory.GetFiles("./Timers"); foreach (string file in files) { if (Path.GetExtension("./Timers/" + file) != ".txt") { continue; } string[] data = File.ReadAllLines(file); DateTime start = default(DateTime); DateTime end = default(DateTime); PlayerInfo creator = null; string message = null; foreach (string line in data) { if (line.Contains("StartDate: ")) { string date = line.Remove(0, "StartDate: ".Length); DateTime.TryParse(date, out start); } else if (line.Contains("EndDate: ")) { string date = line.Remove(0, "EndDate: ".Length); DateTime.TryParse(date, out end); } else if (line.Contains("CreatedBy: ")) { string creatorName = line.Remove(0, "CreatedBy: ".Length); creator = PlayerDB.FindPlayerInfoExact(creatorName); } else if (line.Contains("Message: ")) { message = line.Remove(0, "Creator: ".Length); } } if (creator == null) { creator = Player.Console.Info; } if (start.Ticks == 0 || end.Ticks == 0 || message == null) { Player.Console.Message("Error starting a Timer: {0}, {1}, {2}, {3}", start, end, creator.Name, message); continue; } if (end < DateTime.UtcNow) { Player.Console.Message("Timer Expired: {0}, {1}, {2}, {3} Time Now: {4}", start, end, creator.Name, message, DateTime.UtcNow); File.Delete(file); continue; } ChatTimer.Start((end - DateTime.UtcNow), message, creator.Name); } if (files.Length > 0) { Player.Console.Message("All Timers Loaded. ({0})", files.Length); } else { Player.Console.Message("No Timers Were Loaded."); } } catch (Exception ex) { Player.Console.Message("Timer Loader Has Crashed: {0}", ex); } }