Skip to content

Commit

Permalink
Banlist v1.2.2
Browse files Browse the repository at this point in the history
- Adds preference to control behavior of the host's Kick button
if Ban_HostKickButton_Permabans is set to true then the Kick button adds the kicked player to the permanent banlist
if Ban_HostKickButton_Permabans is set to false then the Kick button adds the kicked player only to the temporary banlist (disappears when server restarts)
  • Loading branch information
data-bomb authored Nov 10, 2023
1 parent d46c797 commit bfb0183
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Si_BasicBanlist/Si_BasicBans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ You should have received a copy of the GNU General Public License
using Si_BasicBanlist;
using AdminExtension;

[assembly: MelonInfo(typeof(BasicBanlist), "[Si] Basic Banlist", "1.2.1", "databomb")]
[assembly: MelonInfo(typeof(BasicBanlist), "[Si] Basic Banlist", "1.2.2", "databomb")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]

namespace Si_BasicBanlist
Expand Down Expand Up @@ -63,6 +63,9 @@ public String? Comments
static readonly String banListFile = System.IO.Path.Combine(MelonEnvironment.UserDataDirectory, "banned_users.json");
static bool AdminModAvailable = false;

static MelonPreferences_Category _modCategory;
static MelonPreferences_Entry<bool> Pref_Ban_KickButton_PermaBan;

public static void UpdateBanFile()
{
// convert back to json string
Expand All @@ -74,6 +77,9 @@ public override void OnInitializeMelon()
{
try
{
_modCategory ??= MelonPreferences.CreateCategory("Silica");
Pref_Ban_KickButton_PermaBan ??= _modCategory.CreateEntry<bool>("Ban_HostKickButton_Permabans", false);

if (System.IO.File.Exists(banListFile))
{
// Open the stream and read it back.
Expand Down Expand Up @@ -245,13 +251,20 @@ public static BanEntry GenerateBanEntry(Il2Cpp.Player player, Il2Cpp.Player admi
[HarmonyPatch(typeof(Il2Cpp.NetworkGameServer), nameof(Il2Cpp.NetworkGameServer.KickPlayer))]
private static class ApplyPatchKickPlayer
{
public static bool Prefix(Il2Cpp.Player __0, bool __1)
public static void Prefix(Il2Cpp.Player __0, bool __1)
{
try
{
if (MasterBanList == null)
{
return true;
return;
}

// if we just intended to kick, we can skip the rest
if (!Pref_Ban_KickButton_PermaBan.Value)
{
MelonLogger.Msg("Kicked player name (" + __0.PlayerName + ") SteamID (" + __0.ToString() + ")");
return;
}

BanEntry thisBan = GenerateBanEntry(__0, Il2Cpp.NetworkGameServer.GetServerPlayer());
Expand All @@ -273,7 +286,7 @@ public static bool Prefix(Il2Cpp.Player __0, bool __1)
HelperMethods.PrintError(error, "Failed to run NetworkGameServer::KickPlayer");
}

return true;
return;
}
}

Expand Down
Binary file modified Si_BasicBanlist/bin/Si_BasicBanlist.dll
Binary file not shown.

0 comments on commit bfb0183

Please # to comment.