コード例 #1
0
ファイル: SmartGuard.cs プロジェクト: iD4NG3R/PheggMod
        private void HandlePunishments(GameObject go, string reason)
        {
            if (_banDurationOne < 0)
            {
                return;
            }

            Base.Disconnect(go, $"You have been automatically disconnected from the server by SmartGuard.\nReason: {reason}");

            Base.SmartGuard($"{go.GetComponent<NicknameSync>().MyNick} was {(_banDurationOne > 0 ? "banned" : "kicked")}: {reason}");

            if (_banDurationOne > 0)
            {
                Base.Disconnect(go, $"You have been automatically disconnected from the server by SmartGuard.\nReason: {reason}\nNote: This action was performed automatically by a server modification!");

                BanHandler.IssueBan(new BanDetails
                {
                    OriginalName = go.GetComponent <NicknameSync>().MyNick,
                    Id           = go.GetComponent <CharacterClassManager>().UserId,
                    Expires      = DateTime.UtcNow.AddMinutes(_banDurationOne).Ticks,
                    Reason       = $"SMARTGUARD - {reason}",
                    Issuer       = "SMARTGUARD",
                    IssuanceTime = DateTime.UtcNow.Ticks
                }, BanHandler.BanType.UserId);

                BanHandler.IssueBan(new BanDetails
                {
                    OriginalName = go.GetComponent <NicknameSync>().MyNick,
                    Id           = go.GetComponent <NetworkIdentity>().connectionToClient.address,
                    Expires      = DateTime.UtcNow.AddMinutes(_banDurationOne).Ticks,
                    Reason       = $"SMARTGUARD - {reason}",
                    Issuer       = "SMARTGUARD",
                    IssuanceTime = DateTime.UtcNow.Ticks
                }, BanHandler.BanType.IP);

                Base.SmartGuard($"{go.GetComponent<NicknameSync>().MyNick} was banned for: {reason}");
            }
        }
コード例 #2
0
ファイル: SmartGuard.cs プロジェクト: iD4NG3R/PheggMod
        /// <summary>
        /// Is run whenever a user joins the server (instead of pre-authenticates)
        /// </summary>
        /// <param name="gameObject"></param>
        public void SmartGuardDeepCheck(GameObject go)
        {
            try
            {
                if (!_enable)
                {
                    return;
                }

                CharacterClassManager            ccm = go.GetComponent <CharacterClassManager>();
                ServerRoles                      sr  = go.GetComponent <ServerRoles>();
                NicknameSync                     ns  = go.GetComponent <NicknameSync>();
                CustomLiteNetLib4MirrorTransport cln = go.GetComponent <CustomLiteNetLib4MirrorTransport>();

                string domain = ccm.UserId.Split('@')[1].ToLower();

                //Whitelist Check
                if (sr.BypassStaff && _skStaffGlobal)
                {
                    Base.SmartGuard("User is global staff. Skipping...");
                    return;
                }
                else if (sr.RemoteAdmin && _skStaffServer)
                {
                    Base.SmartGuard("User is server staff. Skipping...");
                    return;
                }
                else if (_uidWhitelist.Contains(ccm.UserId))
                {
                    Base.SmartGuard("User's UserId is whitelisted. Skipping...");
                }
                else if (_nameWhitelist.Contains(ns.MyNick))
                {
                    Base.SmartGuard("User's name is whitelisted (not recommended). Skipping...");
                    return;
                }

                //Blacklist Check
                if (_nameFilterSmart)
                {
                    string antil33t = _rgx.Replace(ns.MyNick.ToLower(), string.Empty);

                    foreach (KeyValuePair <string, string> pair in leetrules)
                    {
                        antil33t = antil33t.Replace(pair.Key, pair.Value);
                    }

                    if (_nameBlacklist.Contains(antil33t))
                    {
                        if (_banDurationOne == 0)
                        {
                            HandlePunishments(go, "Blacklisted name");
                            return;
                        }
                        else if (_banDurationOne > 0)
                        {
                            HandlePunishments(go, "Blacklisted name");
                            return;
                        }
                    }
                }
                else if (!_nameFilterSmart)
                {
                    if (_nameBlacklist.Contains(ns.MyNick.ToLower()))
                    {
                        if (_banDurationOne == 0)
                        {
                            HandlePunishments(go, "Blacklisted name");
                            return;
                        }
                        else if (_banDurationOne > 0)
                        {
                            HandlePunishments(go, "Blacklisted name");
                            return;
                        }
                    }
                }

                if (_uidBlacklist.Contains(ccm.UserId))
                {
                    if (_banDurationOne == 0)
                    {
                        HandlePunishments(go, "Blacklisted UID");
                    }
                    else if (_banDurationOne > 0)
                    {
                        HandlePunishments(go, "Blacklisted UID");
                    }
                }

                bool doContinue = true;

                if (domain == "discord")
                {
                    doContinue = CheckDiscord(go);
                }
                else if (domain == "steam")
                {
                    doContinue = CheckSteam(go);
                }

                if (!doContinue)
                {
                    return;
                }
            }
            catch (Exception e)
            {
                Base.Error(e.ToString());
            }
        }