mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-04-24 15:26:48 -05:00
Added IP range bans.
This commit is contained in:
parent
b2b7839948
commit
61db2d427c
|
|
@ -16,6 +16,7 @@ namespace PkmnFoundations.GTS
|
|||
BanStatus pidBan = Database.Instance.CheckBanStatus(pid);
|
||||
BanStatus ipBan = Database.Instance.CheckBanStatus(IpAddress);
|
||||
BanStatus macBan = null;
|
||||
BanStatus ipRangeBan = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -39,7 +40,16 @@ namespace PkmnFoundations.GTS
|
|||
{
|
||||
}
|
||||
|
||||
return new[] { pidBan, ipBan, macBan }.Where(ban => ban != null).OrderBy(ban => ban.Level).LastOrDefault();
|
||||
try
|
||||
{
|
||||
uint ipBinary = IpAddressHelper.Ipv4ToBinary(IpAddress);
|
||||
ipRangeBan = Database.Instance.CheckBanStatus(ipBinary);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
return new[] { pidBan, ipBan, macBan, ipRangeBan }.Where(ban => ban != null).OrderBy(ban => ban.Level).LastOrDefault();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,5 +32,13 @@ namespace PkmnFoundations.GTS
|
|||
else
|
||||
return ip;
|
||||
}
|
||||
|
||||
public static uint Ipv4ToBinary(string ip)
|
||||
{
|
||||
string[] split = ip.Split('.');
|
||||
if (split.Length != 4) throw new FormatException("Format not valid for an IPV4 address.");
|
||||
|
||||
return BitConverter.ToUInt32(split.Select(s => Convert.ToByte(s)).Reverse().ToArray(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1233,6 +1233,27 @@ namespace PkmnFoundations.Data
|
|||
);
|
||||
}
|
||||
|
||||
public override BanStatus CheckBanStatus(uint ip_address)
|
||||
{
|
||||
return WithTransaction(tran => CheckBanStatus(tran, ip_address));
|
||||
}
|
||||
|
||||
public BanStatus CheckBanStatus(MySqlTransaction tran, uint ip_address)
|
||||
{
|
||||
DataTable result = tran.ExecuteDataTable("SELECT Level, Reason, Expires " +
|
||||
"FROM pkmncf_gamestats_bans_ipv4_range " +
|
||||
"WHERE (@ip BETWEEN IpAddressMin AND IpAddressMax) AND (Expires > UTC_TIMESTAMP() OR Expires IS NULL)",
|
||||
new MySqlParameter("@ip", ip_address));
|
||||
|
||||
if (result.Rows.Count == 0) return new BanStatus(BanLevels.None, null, DateTime.MinValue);
|
||||
DataRow row = result.Rows[0];
|
||||
return new BanStatus(
|
||||
(BanLevels)DatabaseExtender.Cast<int>(row["Level"]),
|
||||
DatabaseExtender.Cast<string>(row["Reason"]),
|
||||
DatabaseExtender.Cast<DateTime?>(row["Expires"])
|
||||
);
|
||||
}
|
||||
|
||||
public override void AddBan(int pid, BanStatus status)
|
||||
{
|
||||
WithTransaction(tran => AddBan(tran, pid, status));
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ namespace PkmnFoundations.Data
|
|||
public abstract BanStatus CheckBanStatus(byte[] mac_address);
|
||||
public abstract BanStatus CheckBanStatus(string ip_address);
|
||||
public abstract BanStatus CheckBanStatus(TrainerProfileBase profile);
|
||||
public abstract BanStatus CheckBanStatus(uint ip_address);
|
||||
|
||||
public abstract void AddBan(int pid, BanStatus status);
|
||||
public abstract void AddBan(byte[] mac_address, BanStatus status);
|
||||
|
|
|
|||
|
|
@ -14,11 +14,6 @@
|
|||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
|
||||
-- Dumping database structure for gts
|
||||
CREATE DATABASE IF NOT EXISTS `gts` /*!40100 DEFAULT CHARACTER SET utf8 */;
|
||||
USE `gts`;
|
||||
|
||||
-- Dumping structure for table gts.BattleVideoCrawlQueue
|
||||
CREATE TABLE IF NOT EXISTS `BattleVideoCrawlQueue` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
|
@ -443,6 +438,17 @@ CREATE TABLE IF NOT EXISTS `pkmncf_gamestats_bans_ip` (
|
|||
|
||||
-- Data exporting was unselected.
|
||||
|
||||
-- Dumping structure for table gts.pkmncf_gamestats_bans_ipv4_range
|
||||
CREATE TABLE IF NOT EXISTS `pkmncf_gamestats_bans_ipv4_range` (
|
||||
`IpAddressMin` int(10) unsigned NOT NULL,
|
||||
`IpAddressMax` int(10) unsigned NOT NULL,
|
||||
`Level` int(11) NOT NULL,
|
||||
`Reason` text DEFAULT NULL,
|
||||
`Expires` datetime DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- Data exporting was unselected.
|
||||
|
||||
-- Dumping structure for table gts.pkmncf_gamestats_bans_mac
|
||||
CREATE TABLE IF NOT EXISTS `pkmncf_gamestats_bans_mac` (
|
||||
`MacAddress` binary(6) NOT NULL,
|
||||
|
|
@ -465,6 +471,20 @@ CREATE TABLE IF NOT EXISTS `pkmncf_gamestats_bans_pid` (
|
|||
|
||||
-- Data exporting was unselected.
|
||||
|
||||
-- Dumping structure for table gts.pkmncf_gamestats_bans_savefile
|
||||
CREATE TABLE IF NOT EXISTS `pkmncf_gamestats_bans_savefile` (
|
||||
`Version` tinyint(3) unsigned NOT NULL,
|
||||
`Language` tinyint(3) unsigned NOT NULL,
|
||||
`OT` int(10) unsigned NOT NULL,
|
||||
`Name` binary(16) NOT NULL,
|
||||
`Level` int(11) NOT NULL,
|
||||
`Reason` text DEFAULT NULL,
|
||||
`Expires` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`Version`,`Language`,`OT`,`Name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- Data exporting was unselected.
|
||||
|
||||
-- Dumping structure for table gts.pkmncf_plaza_profiles
|
||||
CREATE TABLE IF NOT EXISTS `pkmncf_plaza_profiles` (
|
||||
`pid` int(11) NOT NULL,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user