コード例 #1
0
        private void PunishPlayer(BasePlayer player, int new_time = -1, bool message = true)
        {
            ProtectionInfo p = null;

            if (storedData.Players.TryGetValue(player.userID, out p))
            {
                int punish = 0;
                if (new_time != -1)
                {
                    punish = new_time;
                }
                else
                {
                    punish = Convert.ToInt32(Config["iPunishment"]);
                }
                p.TimeLeft = p.TimeLeft - punish;
                if (p.TimeLeft <= 0)
                {
                    UpdateProtectedListEx(player);
                }
                if (message)
                {
                    string minutes       = Convert.ToInt32(TimeSpan.FromSeconds(p.TimeLeft).TotalMinutes).ToString();
                    string punishment    = Convert.ToInt32(TimeSpan.FromSeconds(punish).TotalMinutes).ToString();
                    string parsed_config = GetMessage("tPunishment", player.UserIDString);
                    parsed_config = parsed_config.Replace("{minutes_revoked}", punishment.ToString());
                    parsed_config = parsed_config.Replace("{minutes_left}", minutes.ToString());
                    PrintToChatEx(player, parsed_config);
                }
            }
        }
コード例 #2
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
        void OnPlayerFirstInit(ulong steamid, int timeleft = -1)
        {
            ProtectionInfo p = null;

            if (storedData.Players.TryGetValue(steamid, out p))
            {
                if (p.Multiple == false && p.TimeLeft == iTime)
                {
                    Log("Removing " + steamid + " from protection list, cleaning up...");
                    storedData.Players.Remove(steamid);
                    OnPlayerFirstInit(steamid, timeleft);
                }
            }
            else
            {
                var info = new ProtectionInfo();
                if (timeleft == -1)
                {
                    timeleft = iTime;
                }
                info.TimeLeft      = timeleft;
                info.Multiple      = false;
                info.InitTimestamp = UnixTimeStampUTC();// Timestamp
                info.UserId        = steamid;
                storedData.Players.Add(steamid, info);
                Interface.GetMod().DataFileSystem.WriteObject(this.Title, storedData);
            }
        }
コード例 #3
0
 public override void SetInfoData(GameObject parent)
 {
     protection_info = parent.GetComponentInChildren <ProtectionInfo>(true);
     protection_info.gameObject.SetActive(true);
     Round.gameObject.SetActive(true);
     SetInfoData();
 }
コード例 #4
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
        private void OnPlayerSleepEnded(BasePlayer player)
        {
            ProtectionInfo p = null;

            if (storedData.Players.TryGetValue(player.userID, out p))
            {
                int minutes = 0;
                if (!p.Multiple)
                {
                    minutes = Convert.ToInt32(TimeSpan.FromSeconds(p.TimeLeft).TotalMinutes);
                    Log("Start protection enabled for " + player.displayName + " [" + player.userID.ToString() + "] - Duration: " + minutes + " minutes.");
                    string parsed_config = GetMessage("tFirstSpawn", player.UserIDString);
                    parsed_config = parsed_config.Replace("{minutes_left}", minutes.ToString());
                    SPUi(player, parsed_config);
                    p.Multiple = true;
                }
                else
                {
                    minutes = Convert.ToInt32(TimeSpan.FromSeconds(p.TimeLeft).TotalMinutes);
                    string parsed_config = GetMessage("tSpawn", player.UserIDString);
                    parsed_config = parsed_config.Replace("{minutes_left}", minutes.ToString());
                    PrintToChatEx(player, parsed_config);
                }
                if (showUIIcon)
                {
                    SPUiUser(player, minutes.ToString());
                }
            }
        }
コード例 #5
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
 private void UpdateProtectedListEx(BasePlayer player, bool init = false)
 {
     if (player != null)
     {
         ProtectionInfo p = null;
         if (storedData.Players.TryGetValue(player.userID, out p))
         {
             if (p.TimeLeft >= 1 && p.TimeLeft <= iTime)
             {
                 p.TimeLeft = p.TimeLeft - iUpdateTimerInterval;
                 if (init)
                 {
                     int minutes = Convert.ToInt32(TimeSpan.FromSeconds(p.TimeLeft).TotalMinutes);
                     if (showUIIcon)
                     {
                         SPUiUser(player, minutes.ToString());
                     }
                 }
             }
             else
             {
                 storedData.Players.Remove(player.userID);
                 storedPlayersData.Players.Add(player.userID);
                 PrintToChatEx(player, GetMessage("tProtectionEnded", player.UserIDString));
                 DestroyUi(player);
             }
         }
     }
 }
コード例 #6
0
 private void UpdateProtectedListEx(BasePlayer player)
 {
     if (player != null)
     {
         ProtectionInfo p = null;
         if (storedData.Players.TryGetValue(player.userID, out p))
         {
             if (p.TimeLeft >= 1 && p.TimeLeft <= Convert.ToInt32(Config["iTime"]))
             {
                 p.TimeLeft = p.TimeLeft - Convert.ToInt32(Config["iUpdateTimerInterval"]);
             }
             else
             {
                 storedData.Players.Remove(player.userID);
                 PrintToChatEx(player, GetMessage("tProtectionEnded", player.UserIDString));
             }
         }
     }
 }
コード例 #7
0
        /// <summary>
        /// Fills the ProtectionList based on the current Taxon, sets the height of the ListView.
        /// </summary>
        private void FillProtectionList()
        {
            var taxonProtectionClassList = ((App)App.Current).TaxonProtectionClasses.FindAll(i => i.TaxonId == SelectedTaxon.TaxonId);

            if (!taxonProtectionClassList.Any(i => i.ClassId == 2))
            {
                taxonProtectionClassList.Insert(0, new TaxonProtectionClass()
                {
                    ClassId = 2, TaxonId = SelectedTaxon.TaxonId, ClassValue = "nicht besonders geschützt"
                });
            }
            foreach (var protectionClass in taxonProtectionClassList)
            {
                ProtectionInfo protectionInfo = new ProtectionInfo();
                protectionInfo.ProtectionStatus = protectionClass.ClassValue;
                //protectionInfo.ProtectionName = ((App)App.Current).ProtectionClasses.First(i => i.ClassId == protectionClass.ClassId).ClassName;
                //ProtectionInfos.Add(protectionInfo);
            }
            ProtectionHeight = ProtectionInfos.Count() * 45;
            OnPropertyChanged(nameof(ProtectionHeight));
        }
コード例 #8
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
        object OnItemPickup(Item item, BasePlayer player)
        {
            if (bProtectionEnabled == true)
            {
                ProtectionInfo p             = null;
                var            hasProtection = storedData.Players.TryGetValue(player.userID, out p);
                if (!hasProtection)
                {
                    return(null);
                }

                if (item.info.category == ItemCategory.Weapon)
                {
                    string minutes       = Convert.ToInt32(TimeSpan.FromSeconds(p.TimeLeft).TotalMinutes).ToString();
                    string parsed_config = GetMessage("cantDo", player.UserIDString);
                    parsed_config = parsed_config.Replace("{minutes_left}", minutes.ToString());
                    SPUi(player, parsed_config);
                    return(false);
                }
            }
            return(null);
        }
コード例 #9
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
        private void RemoveOldUsers()
        {
            int removed = 0;

            new List <ulong>(storedData.Players.Keys).ForEach(u =>
            {
                ulong steamid = u; ProtectionInfo item = null;
                if (storedData.Players.TryGetValue(steamid, out item))
                {
                    if (item.InitTimestamp == 0)
                    {
                        storedData.Players.Remove(steamid);
                        storedPlayersData.Players.Add(steamid);
                        removed++;
                    }
                    else
                    {
                        DateTime compareDate = UnixTimeStampToDateTime(item.InitTimestamp);
                        var days             = (DateTime.Now - compareDate).Days;
                        if (days >= iInactiveDays)
                        {
                            storedData.Players.Remove(steamid);
                            storedPlayersData.Players.Add(steamid);
                            removed++;
                        }
                    }
                }
            });
            if (removed >= 1)
            {
                Puts("Removing " + removed.ToString() + " old entries from the protection list.");
                SaveData();
            }
            else
            {
                Puts("Entry list up to date.");
            }
        }
コード例 #10
0
        void OnPlayerFirstInit(ulong steamid)
        {
            ProtectionInfo p = null;

            if (storedData.Players.TryGetValue(steamid, out p))
            {
                if (p.Multiple == false || p.TimeLeft == Convert.ToInt32(Config["iTime"]))
                {
                    Puts("Removing " + steamid + " from protection list, cleaning up...");
                    storedData.Players.Remove(steamid);
                    OnPlayerFirstInit(steamid);
                }
            }
            else
            {
                var info = new ProtectionInfo();
                info.TimeLeft      = Convert.ToInt32(Config["iTime"]);
                info.Multiple      = false;
                info.InitTimestamp = UnixTimeStampUTC();// Timestamp
                info.UserId        = steamid;
                storedData.Players.Add(steamid, info);
                Interface.GetMod().DataFileSystem.WriteObject(this.Title, storedData);
            }
        }
コード例 #11
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
        private object HasProtection(BasePlayer player)
        {
            ProtectionInfo p = null;

            return(storedData.Players.TryGetValue(player.userID, out p));
        }
コード例 #12
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
        private void SPUiUser(BasePlayer player, string inputText = "")
        {
            DestroyUi(player);
            guiInfo[player.userID] = CuiHelper.GetGuid();

            if (inputText == "")
            {
                ProtectionInfo p = null;
                if (storedData.Players.TryGetValue(player.userID, out p))
                {
                    inputText = Convert.ToInt32(TimeSpan.FromSeconds(p.TimeLeft).TotalMinutes).ToString();
                }
            }

            var elements = new CuiElementContainer();
            var panel    = elements.Add(new CuiPanel()
            {
                Image =
                {
                    Color = "0.75 0.75 0.75 0.0"
                },
                RectTransform =
                {
                    AnchorMin = UIIconAnchorMin,
                    AnchorMax = UIIconAnchorMax
                }
            }, "Overlay", guiInfo[player.userID]);

            elements.Add(new CuiElement()
            {
                Name       = CuiHelper.GetGuid(),
                Parent     = panel,
                Components =
                {
                    new CuiRawImageComponent      {
                        Png = nofight_png, Sprite = "assets/content/textures/generic/fulltransparent.tga"
                    },
                    new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1"
                    }
                }
            });

            elements.Add(new CuiLabel()
            {
                Text =
                {
                    Text     = "NO PVP\n" + inputText + " min",
                    FontSize =                              18,
                    Color    = "1 1 1 1",
                    Align    = TextAnchor.MiddleCenter
                },
                RectTransform =
                {
                    AnchorMin = "0 0",
                    AnchorMax = "1 1"
                }
            }, panel);

            elements.Add(new CuiButton
            {
                Button =
                {
                    Command = "spinfo.show",
                    Color   = "0.8 0.8 0.8 0"
                },
                RectTransform =
                {
                    AnchorMin = "0 0",
                    AnchorMax = "1 1"
                },
                Text =
                {
                    Text     = "",
                    FontSize = 22,
                    Align    = TextAnchor.MiddleCenter
                }
            }, panel);

            // Create the UI elements
            CuiHelper.AddUi(player, elements);
        }
コード例 #13
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
        void OnLootEntity(BasePlayer player, BaseEntity entity)
        {
            if (bProtectionEnabled == true)
            {
                ProtectionInfo p             = null;
                var            hasProtection = storedData.Players.TryGetValue(player.userID, out p);
                if (!hasProtection)
                {
                    return;
                }

                var    corpse        = entity as LootableCorpse;
                var    sleeper       = entity as BasePlayer;
                string minutes       = Convert.ToInt32(TimeSpan.FromSeconds(p.TimeLeft).TotalMinutes).ToString();
                string parsed_config = GetMessage("cantDo", player.UserIDString);
                parsed_config = parsed_config.Replace("{minutes_left}", minutes.ToString());

                //can loot corpses own and bots
                if (corpse != null && corpse.playerSteamID != player.userID && corpse.playerSteamID > 76560000000000000L)
                {
                    SPUi(player, parsed_config);
                    timer.Once(0.01f, player.EndLooting);
                }
                //can loot friend sleeper
                else if (sleeper != null && canLootFriends && !(bool)(Friends?.CallHook("AreFriends", sleeper.userID, player.userID) ?? false))
                {
                    SPUi(player, parsed_config);
                    timer.Once(0.01f, player.EndLooting);
                }
                //can loot self or bot dropped rust_backpack
                else if (entity.PrefabName.Contains("item_drop"))
                {
                    if ((entity as DroppedItemContainer).playerSteamID == 0)
                    {
                        SPUi(player, parsed_config);
                        timer.Once(0.01f, player.EndLooting);
                    }
                    else if ((entity as DroppedItemContainer).playerSteamID != player.userID && (entity as DroppedItemContainer).playerSteamID > 76560000000000000L && !(canLootFriends && (bool)(Friends?.CallHook("AreFriends", entity.OwnerID, player.userID) ?? false)))
                    {
                        SPUi(player, parsed_config);
                        timer.Once(0.01f, player.EndLooting);
                    }
                }
                //no loot heli or supply
                else if (!canLootHeli && entity.PrefabName.Contains("heli_crate"))
                {
                    SPUi(player, parsed_config);
                    timer.Once(0.01f, player.EndLooting);
                }
                else if (!canLootDrop && entity.PrefabName.Contains("supply_drop"))
                {
                    SPUi(player, parsed_config);
                    timer.Once(0.01f, player.EndLooting);
                }
                //can loot friends deployables or own
                else if (entity.PrefabName.Contains("deployable") && entity.OwnerID != 0 && entity.OwnerID != player.userID)
                {
                    if (!(canLootFriendDeployables && (bool)(Friends?.CallHook("AreFriends", entity.OwnerID, player.userID) ?? false)))
                    {
                        SPUi(player, parsed_config);
                        timer.Once(0.01f, player.EndLooting);
                    }
                }
            }
        }
コード例 #14
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
        private HitInfo OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
        {
            if (bProtectionEnabled == true)
            {
                if (entity is BasePlayer)
                {
                    var player = entity as BasePlayer;
                    if (player.userID < 76560000000000000L || player is NPCPlayer)
                    {
                        return(null);
                    }

                    ProtectionInfo p = null;
                    ProtectionInfo z = null;
                    if (hitInfo.Initiator is BasePlayer)
                    {
                        var attacker = hitInfo.Initiator as BasePlayer;
                        if (attacker.userID < 76560000000000000L || attacker is NPCPlayer)
                        {
                            return(null);
                        }
                        if (storedData.Players.TryGetValue(player.userID, out p))
                        {
                            if (storedData.Players.TryGetValue(attacker.userID, out z))
                            {
                                if (attacker.userID == player.userID)
                                {
                                    return(null);
                                }
                                else
                                {
                                    PunishPlayer(attacker);
                                    Log("Punishing " + attacker.displayName.ToString() + " for attempting to pvp.");
                                }
                            }
                            if (attacker.userID != player.userID)
                            {
                                if (player.IsSleeping())
                                {
                                    //TODO possibly bug
                                    if (bSleeperProtection == false)
                                    {
                                        storedData.Players.Remove(player.userID);
                                        storedPlayersData.Players.Add(player.userID);
                                        Log("Removed " + player.displayName.ToString() + " (Sleeping) from the Start Protection list.");
                                        return(null);
                                    }
                                }
                            }
                            PrintToChatEx(attacker, GetMessage("tAttackAttempt", attacker.UserIDString));
                            hitInfo.damageTypes.ScaleAll(0f);
                            return(hitInfo);
                        }
                        else
                        {
                            if (storedData.Players.TryGetValue(attacker.userID, out p))
                            {
                                PunishPlayer(attacker);
                                Log("Punishing " + attacker.displayName.ToString() + " for attempting to pvp.");
                                hitInfo.damageTypes.ScaleAll(0f);
                                return(hitInfo);
                            }
                        }
                    }
                    else if (hitInfo.Initiator is BaseHelicopter)
                    {
                        if (bHelicopterProtection == true)
                        {
                            if (player == null)
                            {
                                return(null);
                            }
                            if (storedData.Players.TryGetValue(player.userID, out z))
                            {
                                hitInfo.damageTypes.ScaleAll(0f);
                                return(hitInfo);
                            }
                        }
                    }
                }
                else if (entity is BuildingBlock || entity is Door || (entity.PrefabName?.Contains("building") ?? false) || (entity.PrefabName?.Contains("deployable") ?? false))
                {
                    if (hitInfo.Initiator is BasePlayer && entity.OwnerID != 0 && entity.OwnerID != (hitInfo.Initiator as BasePlayer).userID)
                    {
                        ProtectionInfo p        = null;
                        var            attacker = hitInfo.Initiator as BasePlayer;

                        if ((entity as BaseEntity).OwnerID != attacker.userID)
                        {
                            if (storedData.Players.TryGetValue(attacker.userID, out p))
                            {
                                PunishPlayer(attacker);
                                Log("Punishing " + attacker.displayName.ToString() + " for attempting to blow.");
                                hitInfo.damageTypes.ScaleAll(0f);
                                return(hitInfo);
                            }
                        }
                    }
                }
                else if (entity is LootableCorpse && (entity as LootableCorpse).playerSteamID > 76560000000000000L)
                {
                    if (hitInfo.Initiator is BasePlayer)
                    {
                        ProtectionInfo p        = null;
                        var            attacker = hitInfo.Initiator as BasePlayer;

                        if ((entity as LootableCorpse).playerSteamID != attacker.userID)
                        {
                            if (storedData.Players.TryGetValue(attacker.userID, out p))
                            {
                                PunishPlayer(attacker);
                                Log("Punishing " + attacker.displayName.ToString() + " for attempting to corpse.");
                                hitInfo.damageTypes.ScaleAll(0f);
                                return(hitInfo);
                            }
                        }
                    }
                }
            }
            return(null);
        }
コード例 #15
0
        //public static string[] ProtectWords(
        //    string[] texts,
        //    string[] wordsToProtect)
        //{
        //    if (texts == null || texts.Length <= 0 || wordsToProtect == null || wordsToProtect.Length <= 0)
        //    {
        //        return texts;
        //    }
        //    else
        //    {
        //        return texts.Select(text => ProtectWords(text, wordsToProtect)).ToArray();
        //    }
        //}

        public static ProtectionResult ProtectWords(
            ProtectionInfo input)
        {
            if (StringExtensionMethods.IsNullOrWhiteSpace(input?.UnprotectedText) || input?.WordsToProtect == null || input.WordsToProtect.Length <= 0)
            {
                return(new ProtectionResult
                {
                    ProtectedText = input?.UnprotectedText,
                    WordsToProtect = input?.WordsToProtect,
                    UnprotectedToProtectedMapping = new Dictionary <string, string>()
                });
            }
            else
            {
                var result = new ProtectionResult
                {
                    WordsToProtect = input.WordsToProtect,
                    ProtectedText  = input.UnprotectedText,
                    UnprotectedToProtectedMapping = new Dictionary <string, string>()
                };

                const string regexPrefix    = @"[RX]";
                const string wildcardPrefix = @"[WC]";

                var index = 0;
                foreach (var word in input.WordsToProtect)
                {
                    var isRegex    = word.StartsWithNoCase(regexPrefix);
                    var isWildcard = word.StartsWithNoCase(wildcardPrefix);

                    if (isRegex || isWildcard)
                    {
                        string pattern;
                        if (isRegex)
                        {
                            pattern = word.Substring(regexPrefix.Length);
                        }
                        else
                        {
                            pattern = word.Substring(wildcardPrefix.Length);
                            pattern = convertWildcardToRegex(pattern);
                        }

                        var matches = Regex.Matches(result.ProtectedText, pattern);

                        foreach (Match match in matches)
                        {
                            var replacement = $@"3213213{index}4234234";
                            index++;

                            var actualWord = match.Value;
                            result.ProtectedText = result.ProtectedText.Replace(actualWord, replacement);

                            result.UnprotectedToProtectedMapping[actualWord] = replacement;
                        }
                    }
                    else
                    {
                        var replacement = $@"3213213{index}4234234";
                        index++;

                        result.ProtectedText = result.ProtectedText.Replace(word, replacement);

                        result.UnprotectedToProtectedMapping[word] = replacement;
                    }
                }

                return(result);
            }
        }
コード例 #16
0
ファイル: StartProtection.cs プロジェクト: saunders-d/RustDev
        private void SPCommand(BasePlayer player, string command, string[] args)
        {
            if (bProtectionEnabled == false && player.net.connection.authLevel < 2)
            {
                PrintToChatEx(player, GetMessage("tDisabled", player.UserIDString));
                return;
            }
            if (args.Length == 0 || args.Length > 2)
            {
                PrintToChatEx(player, "USAGE: /sp <time | end>");
                if (player.net.connection.authLevel >= 2)
                {
                    PrintToChatEx(player, "<color=yellow>ADMIN: /sp <toggle | togglesleep | cleardb | me></color>");
                }
            }
            else if (args[0] == "me")
            {
                if (player.net.connection.authLevel >= 2)
                {
                    if (storedPlayersData.Players.Contains(player.userID))
                    {
                        storedPlayersData.Players.Remove(player.userID);
                    }
                    OnPlayerFirstInit(player.userID);
                    ProtectionInfo p = null;
                    if (storedData.Players.TryGetValue(player.userID, out p))
                    {
                        int minutes = Convert.ToInt32(TimeSpan.FromSeconds(p.TimeLeft).TotalMinutes);
                        Log("Start protection enabled for " + player.displayName + " [" + player.userID.ToString() + "] - Duration: " + minutes + " minutes.");
                        string parsed_config = GetMessage("tFirstSpawn", player.UserIDString);
                        parsed_config = parsed_config.Replace("{minutes_left}", minutes.ToString());
                        PrintToChatEx(player, parsed_config);
                        if (showUIIcon)
                        {
                            SPUiUser(BasePlayer.Find(player.userID.ToString()), minutes.ToString());
                        }
                    }
                    else
                    {
                        Log($"Failed for {player.userID}...");
                    }
                }
                else
                {
                    PrintToChatEx(player, GetMessage("tNoAuthLevel", player.UserIDString));
                }
            }
            else if (args[0] == "cleardb")
            {
                if (player.net.connection.authLevel >= 2)
                {
                    storedData.Players.Clear();
                    storedPlayersData.Players.Clear();
                    PrintToChatEx(player, GetMessage("tDBCleared", player.UserIDString));
                    SaveData();
                }
                else
                {
                    PrintToChatEx(player, GetMessage("tNoAuthLevel", player.UserIDString));
                }
            }
            else if (args[0] == "togglesleep")
            {
                if (player.net.connection.authLevel >= 2)
                {
                    if (bSleeperProtection == true)
                    {
                        PrintToChatEx(player, "Sleep Protection: <color=red>disabled</color>.");
                        Log("Start Protection sleeper protection has been disabled by " + player.displayName + " (type /sp togglesleep to enable).");
                        Config["bSleeperProtection"] = false;
                        SaveConfig();
                    }
                    else
                    {
                        PrintToChatEx(player, "Sleep Protection: <color=green>enabled</color>.");
                        Log("Start Protection sleeper protection has been enabled by " + player.displayName + " (type /sp togglesleep to disabled).");
                        Config["bSleeperProtection"] = true;
                        SaveConfig();
                    }
                }
                else
                {
                    PrintToChatEx(player, GetMessage("tNoAuthLevel", player.UserIDString));
                }
            }
            else if (args[0] == "toggle")
            {
                if (player.net.connection.authLevel >= 2)
                {
                    if (bProtectionEnabled == true)
                    {
                        if (ProtectionTimer != null)
                        {
                            ProtectionTimer.Destroy();
                        }
                        PrintToChatEx(player, GetMessage("tDisabled", player.UserIDString));
                        Puts("Start Protection has been disabled by " + player.displayName + " (type /sp toggle to enable).");
                        Config["bProtectionEnabled"] = false;
                        SaveConfig();
                    }
                    else
                    {
                        ProtectionTimer = timer.Repeat(iUpdateTimerInterval, 0, () => UpdateProtectedList(true));
                        PrintToChatEx(player, GetMessage("tEnabled", player.UserIDString));
                        int minutes = Convert.ToInt32(TimeSpan.FromSeconds(iTime).TotalMinutes);
                        Puts("Start Protection has been enabled by " + player.displayName + " [Minutes: " + minutes.ToString() + "] (type /sp toggle to disable).");
                        Config["bProtectionEnabled"] = true;
                        SaveConfig();
                    }
                }
                else
                {
                    PrintToChatEx(player, GetMessage("tNoAuthLevel", player.UserIDString));
                }
            }
            else if (args[0] == "end")
            {
                ProtectionInfo p = null;
                if (storedData.Players.TryGetValue(player.userID, out p))
                {
                    Log("Start protection disabled by user " + player.displayName + " [" + player.userID.ToString() + "]");
                    PunishPlayer(player, iTime + 1, false);
                }
                else
                {
                    PrintToChatEx(player, GetMessage("tNoProtection", player.UserIDString));
                }
            }
            else if (args[0] == "time")
            {
                ProtectionInfo p = null;
                if (storedData.Players.TryGetValue(player.userID, out p))
                {
                    string minutes = Convert.ToInt32(TimeSpan.FromSeconds(p.TimeLeft).TotalMinutes).ToString();

                    string parsed_config = GetMessage("tSpawn", player.UserIDString);
                    parsed_config = parsed_config.Replace("{minutes_left}", minutes.ToString());
                    PrintToChatEx(player, parsed_config);
                }
                else
                {
                    PrintToChatEx(player, GetMessage("tNoProtection", player.UserIDString));
                }
            }
        }
コード例 #17
0
 private HitInfo OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
 {
     if (Convert.ToBoolean(Config["bProtectionEnabled"]) == true)
     {
         if (entity is BasePlayer)
         {
             var            player = entity as BasePlayer;
             ProtectionInfo p      = null;
             ProtectionInfo z      = null;
             if (hitInfo.Initiator is BasePlayer)
             {
                 var attacker = hitInfo.Initiator as BasePlayer;
                 if (storedData.Players.TryGetValue(player.userID, out p))
                 {
                     if (storedData.Players.TryGetValue(attacker.userID, out z))
                     {
                         if (attacker.userID == player.userID)
                         {
                             return(null);
                         }
                         else
                         {
                             PunishPlayer(attacker);
                             Puts("Punishing " + attacker.displayName.ToString() + " for attempting to pvp.");
                         }
                     }
                     if (attacker.userID != player.userID)
                     {
                         if (player.IsSleeping())
                         {
                             if (Convert.ToBoolean(Config["bSleeperProtection"]) == false)
                             {
                                 storedData.Players.Remove(player.userID);
                                 Puts("Removed " + player.displayName.ToString() + " (Sleeping) from the Start Protection list.");
                                 return(null);
                             }
                             else
                             {
                                 PrintToChatEx(player, GetMessage("tAttackAttempt", player.UserIDString));
                             }
                         }
                     }
                     hitInfo.damageTypes.ScaleAll(0f);
                     return(hitInfo);
                 }
                 else
                 {
                     if (storedData.Players.TryGetValue(attacker.userID, out p))
                     {
                         PunishPlayer(attacker);
                         Puts("Punishing " + attacker.displayName.ToString() + " for attempting to pvp.");
                         hitInfo.damageTypes.ScaleAll(0f);
                         return(hitInfo);
                     }
                 }
             }
             else if (hitInfo.Initiator is BaseHelicopter)
             {
                 if (Convert.ToBoolean(Config["bHelicopterProtection"]) == true)
                 {
                     if (player == null)
                     {
                         return(null);
                     }
                     if (storedData.Players.TryGetValue(player.userID, out z))
                     {
                         hitInfo.damageTypes.ScaleAll(0f);
                         return(hitInfo);
                     }
                 }
             }
         }
     }
     return(null);
 }