public async Task <bool> DoBan(BanningEventArgs ev)
        {
            string banned_user_id    = ev.Target.UserId;
            string banned_nickname   = ev.Target.Nickname;
            string banned_ip_address = ev.Target.IPAddress;
            int    banduration       = ev.Duration;
            Player adminHub          = ev.Issuer;

            Log.Info("--------------------------------------");
            Log.Info("Ban detected, plugin taking over:");
            Log.Info($"Banned Name: {banned_nickname}");
            Log.Info($"Banned ID: {banned_user_id}");
            Log.Info($"Banned IP: {banned_ip_address}");
            Log.Info($"Admin Name: {adminHub.Nickname}");
            Log.Info($"Admin ID: {adminHub.UserId}");
            Log.Info($"Duration: {banduration}");
            if (banduration.ToString().Contains("1576800000"))
            {
                banduration = 0;
                Log.Info($"Duration: UPDATED TO PERM!");
            }
            string reason = ev.Reason;

            if (reason == "")
            {
                reason = "No reason provided. Please contact a Head Administrator for further details.";
            }
            if (await WebTask.IssueBan(plugin.Config.APIKey, banned_user_id, banned_nickname, banned_ip_address, adminHub.UserId, banduration, reason, ev.Target.ReferenceHub.serverRoles.DoNotTrack))
            {
                Log.Info($"Successfully pushed ban for {banned_user_id} ({banned_ip_address}) to the web API!");
                Log.Info("--------------------------------------");
                SendClientToServer(ev.Target, 7790);
                // We can safely remove the ban since the web client will handle it from here.
                //BanHandler.RemoveBan(ev.Target.UserId, ev.);
                return(true);
            }
            else
            {
                // Error out to requesting admin
                adminHub.Broadcast(15, $"ERROR while adding ban to web API for: {banned_nickname}({banned_user_id})");
                Log.Error($"FATAL BANNING ERROR! WebTask.IssueBan() Failed to push to web API");


                // Actually ban them since the webapi decided to do the funny...
                BanDetails ban = new BanDetails
                {
                    OriginalName = ev.Target.Nickname,
                    Id           = ev.Target.UserId,
                    IssuanceTime = TimeBehaviour.CurrentTimestamp(),
                    Expires      = DateTime.UtcNow.AddMinutes((double)ev.Duration).Ticks,
                    Reason       = ev.Reason,
                    Issuer       = ev.Issuer.UserId
                };
                BanHandler.IssueBan(ban, BanHandler.BanType.UserId);
                Log.Info("Pushed manual server-side ban.");
                Log.Info("--------------------------------------");
                return(false);
            }
            return(false);
        }
 public void OnPreBan(BanningEventArgs ev)
 {
     // This is a backup if the website is down and the plugin is blocking bans. The admin will have to set the reason to localban for it to override.
     if (ev.Reason == "localban")
     {
         ev.IsAllowed = true;
         ev.Issuer.Broadcast(10, "You banned the player with a localban, this does not affect the entire network!");
     }
     else
     {
         _            = DoBan(ev);
         ev.IsAllowed = false;
     }
 }
Example #3
0
 /// <summary>
 /// Invoked before banning a player.
 /// </summary>
 /// <param name="ev">The <see cref="BanningEventArgs"/> instance.</param>
 public static void OnBanning(BanningEventArgs ev) => Banning.InvokeSafely(ev);
Example #4
0
        private static bool Prefix(GameObject user, int duration, string reason, string issuer, bool isGlobalBan)
        {
            try
            {
                if (isGlobalBan && ConfigFile.ServerConfig.GetBool("gban_ban_ip", false))
                {
                    duration = int.MaxValue;
                }

                string userId  = null;
                string address = user.GetComponent <NetworkIdentity>().connectionToClient.address;

                API.Features.Player targetPlayer = API.Features.Player.Get(user);
                API.Features.Player issuerPlayer = API.Features.Player.Get(issuer) ?? API.Features.Server.Host;

                try
                {
                    if (ConfigFile.ServerConfig.GetBool("online_mode", false))
                    {
                        userId = targetPlayer.UserId;
                    }
                }
                catch
                {
                    ServerConsole.AddLog("Failed during issue of User ID ban (1)!");
                    return(false);
                }

                string message = $"You have been {((duration > 0) ? "banned" : "kicked")}. ";
                if (!string.IsNullOrEmpty(reason))
                {
                    message = message + "Reason: " + reason;
                }

                if (!ServerStatic.PermissionsHandler.IsVerified || !targetPlayer.IsStaffBypassEnabled)
                {
                    if (duration > 0)
                    {
                        var ev = new BanningEventArgs(targetPlayer, issuerPlayer, duration, reason, message);

                        Player.OnBanning(ev);

                        duration = ev.Duration;
                        reason   = ev.Reason;
                        message  = ev.FullMessage;

                        if (!ev.IsAllowed)
                        {
                            return(false);
                        }

                        string originalName = string.IsNullOrEmpty(targetPlayer.Nickname)
                            ? "(no nick)"
                            : targetPlayer.Nickname;
                        long issuanceTime   = TimeBehaviour.CurrentTimestamp();
                        long banExpieryTime = TimeBehaviour.GetBanExpirationTime((uint)duration);
                        try
                        {
                            if (userId != null && !isGlobalBan)
                            {
                                BanHandler.IssueBan(
                                    new BanDetails
                                {
                                    OriginalName = originalName,
                                    Id           = userId,
                                    IssuanceTime = issuanceTime,
                                    Expires      = banExpieryTime,
                                    Reason       = reason,
                                    Issuer       = issuer,
                                }, BanHandler.BanType.UserId);

                                if (!string.IsNullOrEmpty(targetPlayer.CustomUserId))
                                {
                                    BanHandler.IssueBan(
                                        new BanDetails
                                    {
                                        OriginalName = originalName,
                                        Id           = targetPlayer.CustomUserId,
                                        IssuanceTime = issuanceTime,
                                        Expires      = banExpieryTime,
                                        Reason       = reason,
                                        Issuer       = issuer,
                                    }, BanHandler.BanType.UserId);
                                }
                            }
                        }
                        catch
                        {
                            ServerConsole.AddLog("Failed during issue of User ID ban (2)!");
                            return(false);
                        }

                        try
                        {
                            if (ConfigFile.ServerConfig.GetBool("ip_banning", false) || isGlobalBan)
                            {
                                BanHandler.IssueBan(
                                    new BanDetails
                                {
                                    OriginalName = originalName,
                                    Id           = address,
                                    IssuanceTime = issuanceTime,
                                    Expires      = banExpieryTime,
                                    Reason       = reason,
                                    Issuer       = issuer,
                                }, BanHandler.BanType.IP);
                            }
                        }
                        catch
                        {
                            ServerConsole.AddLog("Failed during issue of IP ban!");
                            return(false);
                        }
                    }
                    else if (duration == 0)
                    {
                        var ev = new KickingEventArgs(targetPlayer, issuerPlayer, reason, message);

                        Player.OnKicking(ev);

                        reason  = ev.Reason;
                        message = ev.FullMessage;

                        if (!ev.IsAllowed)
                        {
                            return(false);
                        }
                    }
                }

                ServerConsole.Disconnect(targetPlayer.ReferenceHub.gameObject, message);

                return(false);
            }
            catch (Exception e)
            {
                Exiled.API.Features.Log.Error($"Exiled.Events.Patches.Events.Player.BanningAndKicking: {e}\n{e.StackTrace}");

                return(true);
            }
        }