Пример #1
0
        public bool TryDoCommand(Players.Player causedBy, string chattext, List <string> splits)
        {
            if (!splits[0].Equals("/unmute"))
            {
                return(false);
            }
            if (!PermissionsManager.CheckAndWarnPermission(causedBy, AntiGrief.MOD_PREFIX + "mute"))
            {
                return(true);
            }
            var m = Regex.Match(chattext, @"/unmute (?<targetplayername>['].+[']|[^ ]+)");

            if (!m.Success)
            {
                Chat.Send(causedBy, "Syntax: /unmute [targetplayername]");
                return(true);
            }
            var targetPlayerName = m.Groups["targetplayername"].Value;

            Players.Player targetPlayer;
            string         error;

            if (!PlayerHelper.TryGetPlayer(targetPlayerName, out targetPlayer, out error))
            {
                Chat.Send(causedBy, $"Could not find target player '{targetPlayerName}': {error}");
                return(true);
            }
            if (MuteList.MutedMinutes.ContainsKey(targetPlayer))
            {
                MuteList.MutedMinutes.Remove(targetPlayer);
                Log.Write($"Unmuted {targetPlayer.Name}");
            }
            else
            {
                Chat.Send(causedBy, $"{targetPlayer.Name} was not muted");
            }
            return(true);
        }
        public bool TryDoCommand(Players.Player causedBy, string chattext, List <string> splits)
        {
            if (!splits[0].Equals("/warpspawn"))
            {
                return(false);
            }
            if (!PermissionsManager.CheckAndWarnPermission(causedBy, AntiGrief.MOD_PREFIX + "warp.spawn.self"))
            {
                return(true);
            }
            var m = Regex.Match(chattext, @"/warpspawn ?(?<playername>.+)?");

            if (!m.Success)
            {
                Chat.Send(causedBy, "use /warpspawn or /warpspawn <playername>");
                return(true);
            }
            var TeleportPlayer     = causedBy;
            var TeleportPlayerName = m.Groups ["playername"].Value;

            if (TeleportPlayerName.Length > 0)
            {
                if (!PermissionsManager.CheckAndWarnPermission(causedBy, AntiGrief.MOD_PREFIX + "warp.spawn"))
                {
                    return(true);
                }
                string Error;
                if (!PlayerHelper.TryGetPlayer(TeleportPlayerName, out TeleportPlayer, out Error))
                {
                    Chat.Send(causedBy, $"Could not find teleport player '{TeleportPlayerName}'; {Error}");
                    return(true);
                }
            }

            Teleport.TeleportTo(TeleportPlayer, ServerManager.TerrainGenerator.GetDefaultSpawnLocation().Vector);
            return(true);
        }
Пример #3
0
        // load from config file
        public static void Load()
        {
            JSONNode jsonConfig;

            if (!JSON.Deserialize(ConfigfilePath, out jsonConfig, false))
            {
                Log.Write("No {0} found inside world directory, creating default config", CONFIG_FILE);
                return;
            }

            Log.Write("Loading jail config from {0}", CONFIG_FILE);
            try {
                JSONNode position;
                if (jsonConfig.TryGetAs("position", out position))
                {
                    jailPosition.x = position.GetAs <float>("x");
                    jailPosition.y = position.GetAs <float>("y");
                    jailPosition.z = position.GetAs <float>("z");
                    jailRange      = position.GetAs <uint>("range");
                    validJail      = true;
                }
                else
                {
                    Log.Write("Did not find a jail position, invalid config");
                }

                JSONNode visitorPos;
                if (jsonConfig.TryGetAs("visitorPosition", out visitorPos))
                {
                    jailVisitorPosition.x = visitorPos.GetAs <float>("x");
                    jailVisitorPosition.y = visitorPos.GetAs <float>("y");
                    jailVisitorPosition.z = visitorPos.GetAs <float>("z");
                    validVisitorPos       = true;
                }

                uint defaultJailTime;
                if (jsonConfig.TryGetAs("defaultJailTime", out defaultJailTime))
                {
                    DEFAULT_JAIL_TIME = defaultJailTime;
                }

                uint graceEscapeAttempts;
                if (jsonConfig.TryGetAs("graceEscapeAttempts", out graceEscapeAttempts))
                {
                    GRACE_ESCAPE_ATTEMPTS = graceEscapeAttempts;
                }

                JSONNode players;
                jsonConfig.TryGetAs("players", out players);
                foreach (JSONNode node in players.LoopArray())
                {
                    string PlayerName    = node.GetAs <string>("target");
                    long   jailTimestamp = node.GetAs <long>("time");
                    long   jailDuration  = node.GetAs <long>("duration");
                    string causedByName  = node.GetAs <string>("jailedBy");
                    string reason        = node.GetAs <string>("jailReason");

                    List <string> permissions = node.GetAs <List <string> >("permissions"); // TODO
                    // List<string> permissions = new List<string>;
                    // JSONNode jsonPerm;
                    // node.TryGetAs("permissions", out jsonPerm);
                    // foreach (string perm in jsonPerm.LoopArray()) {
                    //   permissions.Add(perm);
                    // }

                    Players.Player target;
                    Players.Player causedBy;
                    string         error;

                    // causedBy can be null in case of server actions, but target has to be a valid player
                    PlayerHelper.TryGetPlayer(causedByName, out causedBy, out error, true);
                    if (PlayerHelper.TryGetPlayer(PlayerName, out target, out error, true))
                    {
                        JailRecord record = new JailRecord(jailTimestamp, jailDuration, causedBy, reason, permissions);
                        jailedPersons.Add(target, record);
                    }
                }
            } catch (Exception e) {
                Log.Write("Error parsing {0}: {1}", CONFIG_FILE, e.Message);
            }

            LoadLogFile();
            return;
        }
        public bool TryDoCommand(Players.Player causedBy, string chattext, List <string> splits)
        {
            if (!splits[0].Equals("/spawnnpc"))
            {
                return(false);
            }
            if (!PermissionsManager.CheckAndWarnPermission(causedBy, AntiGrief.MOD_PREFIX + "npcandbeds"))
            {
                return(true);
            }

            Match m = Regex.Match(chattext, @"/spawnnpc (?<amount>\d+) ?(?<player>['].+[']|[^ ]+)?");

            if (!m.Success)
            {
                Chat.Send(causedBy, "Syntax: /spawnnpc {number} [targetplayer]");
                return(true);
            }
            int amount = 0;

            if (!int.TryParse(m.Groups["amount"].Value, out amount) || amount <= 0)
            {
                Chat.Send(causedBy, "Number should be > 0");
                return(true);
            }

            Players.Player target = causedBy;
            string         error;

            if (!m.Groups["player"].Value.Equals(""))
            {
                if (!PlayerHelper.TryGetPlayer(m.Groups["player"].Value, out target, out error))
                {
                    Chat.Send(causedBy, "Could not find target: {error}");
                }
            }

            Colony colony = target.ActiveColony;

            if (colony == null)
            {
                Chat.Send(target, "You need to be at an active colony to spawn beds");
                if (causedBy != target)
                {
                    Chat.Send(causedBy, " {target} has no active colony");
                }
                return(true);
            }
            BannerTracker.Banner banner = colony.GetClosestBanner(causedBy.VoxelPosition);
            if (banner == null)
            {
                Chat.Send(causedBy, "No banners found for the active colony");
                return(true);
            }

            for (int i = 0; i < amount; i++)
            {
                NPCBase npc = new NPCBase(colony, banner.Position);
                NPCTracker.Add(npc);
                colony.RegisterNPC(npc);
                ModLoader.Callbacks.OnNPCRecruited.Invoke(npc);
            }

            Chat.Send(causedBy, $"Spawned {amount} colonists");
            return(true);
        }
Пример #5
0
        public bool TryDoCommand(Players.Player causedBy, string chattext, List <string> splits)
        {
            if (!splits[0].Equals("/jailrec"))
            {
                return(false);
            }
            if (!PermissionsManager.CheckAndWarnPermission(causedBy, AntiGrief.MOD_PREFIX + "jail"))
            {
                return(true);
            }

            // get log by player
            var m = Regex.Match(chattext, @"/jailrec (?<target>.+)");

            if (m.Success)
            {
                string         targetName = m.Groups["target"].Value;
                Players.Player target;
                string         error;
                if (!PlayerHelper.TryGetPlayer(targetName, out target, out error))
                {
                    Chat.Send(causedBy, $"Could not find {targetName}: {error}");
                    return(true);
                }
                List <JailManager.JailLogRecord> PlayerJailLog;
                if (!JailManager.jailLog.TryGetValue(target, out PlayerJailLog))
                {
                    Chat.Send(causedBy, $"No records found - {targetName} is clean");
                    return(true);
                }
                foreach (JailManager.JailLogRecord record in PlayerJailLog)
                {
                    DateTime timestamp = new DateTime(record.timestamp * TimeSpan.TicksPerMillisecond * 1000);
                    string   jailedBy  = "Server";
                    if (record.jailedBy != null)
                    {
                        jailedBy = record.jailedBy.Name;
                    }
                    Chat.Send(causedBy, String.Format("{0} by: {1} for: {2}", timestamp.ToString(), jailedBy, record.reason));
                }

                // or get the full log
            }
            else
            {
                // in full log mode only timestamp and playername are displayed (last 10 jailed).
                // showing more would require a more capable chat window
                List <combinedJailLog> combinedLog = new List <combinedJailLog>();
                foreach (KeyValuePair <Players.Player, List <JailManager.JailLogRecord> > kvp in JailManager.jailLog)
                {
                    Players.Player target = kvp.Key;
                    List <JailManager.JailLogRecord> records = kvp.Value;
                    foreach (JailManager.JailLogRecord record in records)
                    {
                        combinedLog.Add(new combinedJailLog(target, record.jailedBy, record.timestamp));
                    }
                }
                combinedLog.Sort(delegate(combinedJailLog a, combinedJailLog b)
                {
                    return(a.timestamp.CompareTo(b.timestamp));
                });

                int limit = 10;
                if (combinedLog.Count < limit)
                {
                    limit = combinedLog.Count;
                }

                Chat.Send(causedBy, "Jail Records (last 10):");
                for (int i = 0; i < limit; ++i)
                {
                    combinedJailLog record     = combinedLog[i];
                    DateTime        timestamp  = new DateTime(record.timestamp * TimeSpan.TicksPerMillisecond * 1000);
                    string          targetName = record.target.Name;
                    string          jailerName = "Server";
                    if (record.causedBy != null)
                    {
                        jailerName = record.causedBy.Name;
                    }
                    Chat.Send(causedBy, String.Format("{0} {1} by: {2}", timestamp.ToString(), targetName, jailerName));
                }
            }

            return(true);
        }
Пример #6
0
        // load config
        public static void Load()
        {
            SpawnProtectionRangeXPos = 50;
            SpawnProtectionRangeXNeg = 50;
            SpawnProtectionRangeZPos = 50;
            SpawnProtectionRangeZNeg = 50;
            BannerProtectionRangeX   = 50;
            BannerProtectionRangeZ   = 50;
            CustomAreas.Clear();
            JSONNode jsonConfig;

            if (JSON.Deserialize(ConfigFilepath, out jsonConfig, false))
            {
                int rx;
                if (jsonConfig.TryGetAs("SpawnProtectionRangeX+", out rx))
                {
                    SpawnProtectionRangeXPos = rx;
                }
                else if (jsonConfig.TryGetAs("SpawnProtectionRangeX", out rx))
                {
                    SpawnProtectionRangeXPos = rx;
                }
                else
                {
                    Log.Write($"Could not get SpawnProtectionRangeX+ or SpawnProtectionRangeX from json config, using default value {SpawnProtectionRangeXPos}");
                }
                if (jsonConfig.TryGetAs("SpawnProtectionRangeX-", out rx))
                {
                    SpawnProtectionRangeXNeg = rx;
                }
                else if (jsonConfig.TryGetAs("SpawnProtectionRangeX", out rx))
                {
                    SpawnProtectionRangeXNeg = rx;
                }
                else
                {
                    Log.Write($"Could not get SpawnProtectionRangeX- or SpawnProtectionRangeX from json config, using default value {SpawnProtectionRangeXNeg}");
                }
                int rz;
                if (jsonConfig.TryGetAs("SpawnProtectionRangeZ+", out rz))
                {
                    SpawnProtectionRangeZPos = rz;
                }
                else if (jsonConfig.TryGetAs("SpawnProtectionRangeZ", out rz))
                {
                    SpawnProtectionRangeZPos = rz;
                }
                else
                {
                    Log.Write($"Could not get SpawnProtectionRangeZ+ or SpawnProtectionRangeZ from json config, using default value {SpawnProtectionRangeZPos}");
                }
                if (jsonConfig.TryGetAs("SpawnProtectionRangeZ-", out rz))
                {
                    SpawnProtectionRangeZNeg = rz;
                }
                else if (jsonConfig.TryGetAs("SpawnProtectionRangeZ", out rz))
                {
                    SpawnProtectionRangeZNeg = rz;
                }
                else
                {
                    Log.Write($"Could not get SpawnProtectionRangeZ- or SpawnProtectionRangeZ from json config, using default value {SpawnProtectionRangeZNeg}");
                }
                if (!jsonConfig.TryGetAs("BannerProtectionRangeX", out BannerProtectionRangeX))
                {
                    Log.Write($"Could not get banner protection x-range from json config, using default value {BannerProtectionRangeX}");
                }
                if (!jsonConfig.TryGetAs("BannerProtectionRangeZ", out BannerProtectionRangeZ))
                {
                    Log.Write($"Could not get banner protection z-range from json config, using default value {BannerProtectionRangeZ}");
                }
                JSONNode jsonCustomAreas;
                if (jsonConfig.TryGetAs("CustomAreas", out jsonCustomAreas) && jsonCustomAreas.NodeType == NodeType.Array)
                {
                    foreach (var jsonCustomArea in jsonCustomAreas.LoopArray())
                    {
                        try {
                            CustomAreas.Add(new CustomProtectionArea(jsonCustomArea));
                        } catch (Exception exception) {
                            Log.WriteError($"Exception loading custom area; {exception.Message}");
                        }
                    }
                    Log.Write($"Loaded {CustomAreas.Count} from file");
                }
                jsonConfig.TryGetAsOrDefault("NpcKillsJailThreshold", out NpcKillsJailThreshold, 2);
                jsonConfig.TryGetAsOrDefault("NpcKillsKickThreshold", out NpcKillsKickThreshold, 5);
                jsonConfig.TryGetAsOrDefault("NpcKillsBanThreshold", out NpcKillsBanThreshold, 6);

                JSONNode jsonNameList;
                if (jsonConfig.TryGetAs("UnscoredPlayers", out jsonNameList) && jsonNameList.NodeType == NodeType.Array)
                {
                    foreach (JSONNode jsonName in jsonNameList.LoopArray())
                    {
                        Players.Player player;
                        string         error;
                        string         playerName = jsonName.GetAs <string>();
                        if (PlayerHelper.TryGetPlayer(playerName, out player, out error, true))
                        {
                            UnscoredPlayers.Add(player);
                        }
                        else
                        {
                            Log.Write($"Error loading unscored players {playerName}: {error}");
                        }
                    }
                }
                jsonConfig.TryGetAsOrDefault("ColonistLimit", out ColonistLimit, 0);
                jsonConfig.TryGetAsOrDefault("ColonistCheckInterval", out ColonistLimitCheckSeconds, 30);

                int speed = 0;
                jsonConfig.TryGetAsOrDefault("DeleteJobSpeed", out speed, 4);
                // DeleteJobsManager.SetDeleteJobSpeed(speed, false);
            }
            else
            {
                Save();
                Log.Write($"Could not find {ConfigFilepath} file, created default one");
            }
            Log.Write($"Using spawn protection with X+ range {SpawnProtectionRangeXPos}");
            Log.Write($"Using spawn protection with X- range {SpawnProtectionRangeXNeg}");
            Log.Write($"Using spawn protection with Z+ range {SpawnProtectionRangeZPos}");
            Log.Write($"Using spawn protection with Z- range {SpawnProtectionRangeZNeg}");
            Log.Write($"Using banner protection with X range {BannerProtectionRangeX}");
            Log.Write($"Using banner protection with Z range {BannerProtectionRangeZ}");
        }
Пример #7
0
        public bool TryDoCommand(Players.Player causedBy, string chattext, List <string> splits)
        {
            if (!splits[0].Equals("/trade"))
            {
                return(false);
            }
            var m = Regex.Match(chattext, @"/trade (?<playername>['].+[']|[^ ]+) (?<material>.+) (?<amount>\d+)");

            if (!m.Success)
            {
                Chat.Send(causedBy, "Command didn't match, use /trade [playername] [material] [amount]");
                return(true);
            }
            var targetPlayerName = m.Groups ["playername"].Value;

            if (targetPlayerName.StartsWith("'"))
            {
                if (targetPlayerName.EndsWith("'"))
                {
                    targetPlayerName = targetPlayerName.Substring(1, targetPlayerName.Length - 2);
                }
                else
                {
                    Chat.Send(causedBy, "Command didn't match, missing ' after playername");
                    return(true);
                }
            }
            if (targetPlayerName.Length < 1)
            {
                Chat.Send(causedBy, "Command didn't match, no playername given");
                return(true);
            }
            var    itemTypeName = m.Groups ["material"].Value;
            ushort itemType;

            if (!ItemTypes.IndexLookup.TryGetIndex(itemTypeName, out itemType))
            {
                Chat.Send(causedBy, "Command didn't match, item type not found");
                return(true);
            }
            var amount = Int32.Parse(m.Groups ["amount"].Value);

            if (amount <= 0)
            {
                Chat.Send(causedBy, "Command didn't match, amount too low");
                return(true);
            }
            Players.Player targetPlayer;
            string         error;

            if (!PlayerHelper.TryGetPlayer(targetPlayerName, out targetPlayer, out error))
            {
                Chat.Send(causedBy, $"Could not find target player '{targetPlayerName}'; {error}");
                return(true);
            }
            Colony sourceColony = causedBy.ActiveColony;
            Colony targetColony = targetPlayer.ActiveColony;

            if (sourceColony == null || targetColony == null)
            {
                Chat.Send(causedBy, "Coud not get active colony for both players");
                return(false);
            }
            InventoryItem tradeItem = new InventoryItem(itemType, amount);

            if (sourceColony.Stockpile.TryRemove(tradeItem))
            {
                targetColony.Stockpile.Add(tradeItem);
                Chat.Send(causedBy, $"Send {amount} x {itemTypeName} to '{targetPlayer.Name}'");
                Chat.Send(targetPlayer, $"Received {amount} x {itemTypeName} from '{causedBy.Name}'");
            }
            else
            {
                Chat.Send(causedBy, "You don't have enough items");
            }
            return(true);
        }
        public bool TryDoCommand(Players.Player causedBy, string chattext, List <string> splits)
        {
            if (!splits[0].Equals("/warpbanner"))
            {
                return(false);
            }
            if (!PermissionsManager.CheckAndWarnPermission(causedBy, AntiGrief.MOD_PREFIX + "warp.banner.self"))
            {
                return(true);
            }

            Players.Player targetPlayer = null;
            Colony         targetColony = null;
            Match          m            = Regex.Match(chattext, @"/warpbanner (?<target>['].+[']|[^ ]+)");

            if (m.Success)
            {
                string error;
                if (!PlayerHelper.TryGetColony(m.Groups["target"].Value, out targetColony, out error) &&
                    !PlayerHelper.TryGetPlayer(m.Groups["target"].Value, out targetPlayer, out error))
                {
                    Chat.Send(causedBy, $"Could not find target: {error}");
                    return(true);
                }
            }

            string permission = AntiGrief.MOD_PREFIX + "warp.banner";

            if (targetColony != null)
            {
                if (targetColony.Owners.ContainsByReference(causedBy))
                {
                    permission += ".self";
                }
                if (!PermissionsManager.CheckAndWarnPermission(causedBy, permission))
                {
                    return(true);
                }
            }
            else if (targetPlayer != null)
            {
                if (!PermissionsManager.CheckAndWarnPermission(causedBy, permission))
                {
                    return(true);
                }
            }
            else
            {
                targetPlayer = causedBy;
            }

            if (targetColony == null)
            {
                int      num      = int.MaxValue;
                Colony[] colonies = targetPlayer.Colonies;
                for (int i = 0; i < colonies.Length; i++)
                {
                    BannerTracker.Banner found;
                    int closestDistance = colonies[i].Banners.GetClosestDistance(targetPlayer.VoxelPosition, out found);
                    if (closestDistance < num)
                    {
                        targetColony = colonies[i];
                        num          = closestDistance;
                    }
                }
                if (targetColony == null)
                {
                    Chat.Send(causedBy, $"Could not find any banner for '{targetPlayer.Name}'");
                    return(true);
                }
            }

            Helper.TeleportPlayer(causedBy, targetColony.Banners[0].Position.Vector);
            return(true);
        }