From 20804d918263acd55b99da63aadaef6f2498d67d Mon Sep 17 00:00:00 2001
From: Ferywir <65760459+Ferywir@users.noreply.github.com>
Date: Tue, 9 Jun 2026 14:15:27 +0200
Subject: [PATCH] feat: IP ban support (#185) (#188)
---
Admin/Templates/ban.tpl | 71 ++++++++++++
Admin/Templates/resetServer.php | 5 +-
GameEngine/Admin/database.php | 92 ++++++++++++++-
GameEngine/Admin/function.php | 6 +
GameEngine/Database.php | 33 ++++++
GameEngine/Logging.php | 3 +-
GameEngine/Session.php | 9 +-
README.md | 62 ++++++++++
install/data/constant_format.tpl | 12 ++
src/Utils/AccessLogger.php | 4 +-
src/Utils/IpResolver.php | 193 +++++++++++++++++++++++++++++++
var/db/struct.sql | 20 ++++
12 files changed, 501 insertions(+), 9 deletions(-)
create mode 100644 src/Utils/IpResolver.php
diff --git a/Admin/Templates/ban.tpl b/Admin/Templates/ban.tpl
index 5d1628ba..b24b026d 100644
--- a/Admin/Templates/ban.tpl
+++ b/Admin/Templates/ban.tpl
@@ -53,8 +53,27 @@ if(isset($_POST['action']) && $_POST['action'] == 'addBan') {
}
}
+// ========================= HANDLE ADD IP BAN (issue #185) =========================
+if(isset($_POST['action']) && $_POST['action'] == 'addIpBan') {
+ $ip = trim($_POST['ip'] ?? '');
+ $reason = trim($_POST['reason'] ?? '');
+ $time = (int)($_POST['time'] ?? 0);
+
+ if(@inet_pton($ip) === false) {
+ $error = "Invalid IP address!";
+ } else {
+ $end = $time > 0 ? time() + $time : 0;
+ if($admin->AddIpBan($ip, $end, $reason)) {
+ $success = "IP ".htmlspecialchars($ip)." has been banned successfully!";
+ } else {
+ $error = "Could not ban this IP!";
+ }
+ }
+}
+
// ========================= DATA =========================
$bannedUsers = $admin->search_banned();
+$bannedIps = $admin->search_banned_ip();
$banHistory = mysqli_query($database->dblink,"SELECT * FROM ".TB_PREFIX."banlist WHERE active=0 ORDER BY id DESC LIMIT 50");
?>