[FSoD] IP-Ban!

Posts 1–7 of 7 · Page 1 of 1
[FSoD] IP-Ban!
Made IP-Ban for some people, so i decided to release it here too.

 
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)
Add:
Code:
string[] ip = client.Socket.RemoteEndPoint.ToString().Split(':');
Then under:
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;
                        }
                    }
Add:
Code:
                    if (db.CheckIP(ip[0]))
                    {
                        client.SendPacket(new FailurePacket
                        {
                            ErrorId = 0,
                            ErrorDescription = "You are IP-Banned!"
                        });
                        client.Disconnect();
                        return;  
                    }
And finally, under:
Code:
                    if (world.IsLimbo)
                        world = world.GetInstance(client);
Add:
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!
Nice release! but doesn't NrCore have Ip Ban?
Quote Originally Posted by Demon View Post
Nice release! but doesn't NrCore have Ip Ban?
No? Not as im aware of, but that wouldnt work on fsod either. xd
Quote Originally Posted by MikeRaarupBirk View Post
No? Not as im aware of, but that wouldnt work on fsod either. xd
Ya true. But wouldn't be hard to convert redis to mysql, considering that the big difference lies in the database. But I thought I saw IP Ban related stuff when looking through the NrCore, but oh well.
It does log the ips now but when i use it they can still get back on why is that?




EDITED:

NVM i got it to work
but can you make an unbanip as well?
just asking
Quote Originally Posted by MikeRaarupBirk View Post
Made IP-Ban for some people, so i decided to release it here too.

 
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)
Add:
Code:
string[] ip = client.Socket.RemoteEndPoint.ToString().Split(':');
Then under:
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;
                        }
                    }
Add:
Code:
                    if (db.CheckIP(ip[0]))
                    {
                        client.SendPacket(new FailurePacket
                        {
                            ErrorId = 0,
                            ErrorDescription = "You are IP-Banned!"
                        });
                        client.Disconnect();
                        return;  
                    }
And finally, under:
Code:
                    if (world.IsLimbo)
                        world = world.GetInstance(client);
Add:
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!
RIP all pserver hackers
Quote Originally Posted by TorFourr View Post
RIP all pserver hackers
No not really, RIP all half-ass PServer Hackers is what you meant to say. If they actually think that hacking a "PServer" is worth their time and resources, then theirs many ways to avoid an IP Ban.
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us