[FSoD] IP-Ban!
Made IP-Ban for some people, so i decided to release it here too.
Add this to your rotmgprod.sql, and import your database into xampp again.
Above:
Add:
Then under:
Add:
And finally, under:
Add:
When all these steps are done, you should be able to go ingame and do /ipban <User> and watch them be IP-Banned!
rotmgprod.sql
Add this to your rotmgprod.sql, and import your database into xampp again.
Code:
CREATE TABLE IF NOT EXISTS `ips` ( `ip` varchar(128) NOT NULL, `banned` int(11) NOT NULL, PRIMARY KEY (`ip`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Database.cs
Code:
public void StoreIP(string ip) //Adds users IP to table for itself to be.
{
bool IsThere = false;
MySqlCommand cmd = CreateQuery();
cmd.CommandText = "SELECT * FROM ips";
using (MySqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
if (rdr.GetString("ip") == ip) //Ip is here, we do nothing.
IsThere = true;
}
}
if (!IsThere)
{
cmd.CommandText = "INSERT INTO ips(ip, banned) VALUES(@ip ,0);";
cmd.Parameters.AddWithValue("@ip", ip);
cmd.ExecuteNonQuery();
}
}
public bool CheckIP(string ip)
{
MySqlCommand cmd = CreateQuery();
cmd.CommandText = "SELECT * FROM ips WHERE ip=@ipx;";
cmd.Parameters.AddWithValue("@ipx", ip);
using (MySqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
if (rdr.GetInt16("banned") == 1) //If banned is 1, then user is ipbanned.
return true;
}
}
return false;
}
public void BanIP(string ip)
{
MySqlCommand cmd = CreateQuery();
cmd.CommandText = "UPDATE ips SET banned=1 WHERE ip=@ipx;";
cmd.Parameters.AddWithValue("@ipx", ip);
cmd.ExecuteNonQuery();
}
HelloHandler.cs
Above:
Code:
if (Client.SERVER_VERSION != packet.BuildVersion)
Code:
string[] ip = client.Socket.RemoteEndPoint.ToString().Split(':');
Code:
if (DateTime.Now <= Program.WhiteListTurnOff)
{
if (!IsWhiteListed(client.Account.Rank))
{
client.SendPacket(new FailurePacket
{
ErrorId = 0,
ErrorDescription = "You are not whitelisted!"
});
client.Disconnect();
return;
}
}
Code:
if (db.CheckIP(ip[0]))
{
client.SendPacket(new FailurePacket
{
ErrorId = 0,
ErrorDescription = "You are IP-Banned!"
});
client.Disconnect();
return;
}
Code:
if (world.IsLimbo)
world = world.GetInstance(client);
Code:
db.StoreIP(ip[0]);
AdminCommands.cs
Code:
internal class IpBan : Command
{
public IpBan()
: base("ipban", permLevel: 1)
{
}
protected override bool Process(Player player, RealmTime time, string[] args)
{
if (string.IsNullOrEmpty(args[0]))
{
player.SendInfo("Usage: /ipban <User>");
return false;
}
var p = player.Manager.FindPlayer(args[0]);
if (p == null)
{
player.SendInfo($"{args[0]} is offline, or you made a mistake typing in his name. (could ban him using database?)");
return false;
}
var ipToBan = p.Client.Socket.RemoteEndPoint.ToString().Split(':');
player.Manager.Database.DoActionAsync(db =>
{
db.BanIP(ipToBan[0]);
});
p.Client.Disconnect();
player.SendInfo(p.Name + " has been IP-Banned!");
return true;
}
}
When all these steps are done, you should be able to go ingame and do /ipban <User> and watch them be IP-Banned!
