public bool Ban(IUserInfo target, IUser bannedBy = null, string reason = null, TimeSpan?duration = null)
        {
            //todo: this is wrong
            var player = ((UnturnedUser)target).Player;

            PlayerBanEvent @event = new PlayerBanEvent(player.User, bannedBy, reason, duration, true);

            eventManager.Emit(host, @event);
            if (@event.IsCancelled)
            {
                return(false);
            }

            if (target is IUser u && u.IsOnline)
            {
                var uPlayer = ((UnturnedUser)target).Player;
                Provider.ban(uPlayer.CSteamID, reason, (uint)(duration?.TotalSeconds ?? uint.MaxValue));
                return(true);
            }

            var steamId  = new CSteamID(ulong.Parse(target.Id));
            var callerId = (bannedBy is UnturnedUser up) ? up.Player.CSteamID : CSteamID.Nil;

            SteamBlacklist.ban(steamId, 0, callerId, reason, (uint)(duration?.TotalSeconds ?? uint.MaxValue));
            return(true);
        }
Example #2
0
        internal void InvokePlayerBanEvent(Player bannedPlayer, Player issuer, ref long duration, ref string reason,
                                           ref bool allow)
        {
            var ev = new PlayerBanEventArgs {
                Allow = allow, BanDuration = duration, Issuer = issuer, Reason = reason, BannedPlayer = bannedPlayer
            };

            PlayerBanEvent?.Invoke(ev);

            duration = ev.BanDuration;
            reason   = ev.Reason;
            allow    = ev.Allow;
        }
        public void playerBan(PlayerBanEvent ev)
        {
            ev.Allow = false;
            GameObject player = ev.BannedPlayer.characterClassManager.gameObject;

            if (ev.Duration == 0)
            {
                ServerConsole.Disconnect(player, ev.FullMessage);
            }
            else
            {
                ServerConsole.Disconnect(player, ev.FullMessage);

                Ban BanJSON = new Ban();
                BanJSON.Steamid64   = ev.BannedPlayer.characterClassManager.UserId;
                BanJSON.Ip          = ev.BannedPlayer.queryProcessor._ipAddress;
                BanJSON.BannedAt    = TimeBehaviour.CurrentTimestamp();
                BanJSON.BannedUntil = DateTime.UtcNow.AddMinutes((double)ev.Duration).Ticks;
                BanJSON.By          = ev.Issuer.characterClassManager.UserId;
                if (!String.IsNullOrEmpty(ev.Reason))
                {
                    BanJSON.Reason = ev.Reason;
                }

                String JSON         = Serialize.ToJson(BanJSON);
                String JsonResponse = Methods.Post(Plugin.BanURL, JSON);

                try
                {
                    JSON.Success.SuccessResponseJSON json = SanctionSystem.JSON.Success.SuccessResponseJSON.FromJson(JsonResponse);
                }
                catch (Exception e)
                {
                    JSON.Error.ErrorResponseJSON json = SanctionSystem.JSON.Error.ErrorResponseJSON.FromJson(JsonResponse);

                    if (!String.IsNullOrEmpty(json.Code))
                    {
                        Log.Error("Erreur durant le processus d'API (Code d'erreur répondu par l'API: " + json.Code);
                    }
                    else
                    {
                        Log.Error("Erreur durant le processus d'API (Code d'erreur plugin: " + e);
                    }
                }
            }
        }
Example #4
0
        internal static void InvokePlayerBanEvent(Player player, int duration, ref bool allow,
                                                  string reason, Player issuer)
        {
            if (PlayerBanEvent == null)
            {
                return;
            }

            var ev = new PlayerBanEvent
            {
                Issuer       = issuer,
                Duration     = duration,
                Reason       = reason,
                BannedPlayer = player
            };

            PlayerBanEvent.Invoke(ev);

            allow = ev.Allowed;
        }
Example #5
0
 public void OnPlayerBan(PlayerBanEvent ev)
 => DiscordLab.bot.NewMessage($"**New Ban!**```autohotkey\nUser: {ev.Player}\nAdmin: {ev.Admin}\nDuration: {ev.Duration / 60} {(ev.Duration > 1 ? "minutes" : "minute")}\nReason: {(string.IsNullOrEmpty(ev.Reason) ? "No reason provided" : ev.Reason )}```");
Example #6
0
 public void OnPlayerBan(PlayerBanEvent ev) =>
 DiscordLab.bot.NewMessage($"**New Ban!**```autohotkey\nUser: {ev.Player.ToString()}\nAdmin: {ev.Admin.ToString()}\nDuration: {ev.Duration / 60} {(ev.Duration > 1 ? "minutes" : "minute")}```");