[Request]Blocking IP connections for 5165

01/15/2010 02:29 copz1337#1
How can I block IPs for my 5165 server? I want to know so I can IP ban people and/or block them if they are flooding my server in any way.
01/15/2010 06:36 Huseby#2
#Wiped
01/15/2010 06:39 Nullable#3
This is the easiest way to do it, LetterX has a point basic winsock operation -.-
Code:
if(Socket.RemoteEndPoint.ToString().Split(':')[0] == BANNEDIPADDR)
{
   Socket.Disconnect(false);
}
01/15/2010 16:57 copz1337#4
Quote:
Originally Posted by Nullable View Post
This is the easiest way to do it, LetterX has a point basic winsock operation -.-
Code:
if(Socket.RemoteEndPoint.ToString().Split(':')[0] == BANNEDIPADDR)
{
   Socket.Disconnect(false);
}
is this all? where do I put it.
01/15/2010 16:59 Nullable#5
Quote:
Originally Posted by copz1337 View Post
is this all? where do I put it.
Just where your (i assume) asynchronous callback for accepting connections is..
Probably where you may find this line
Quote:
Socket.BeginAccept(...)
01/15/2010 17:15 copz1337#6
alright um im probably putting it in the wrong place but check it out...

[Only registered and activated users can see links. Click Here To Register...]
01/15/2010 17:43 Nullable#7
Quote:
Originally Posted by copz1337 View Post
Will it still work if I put it anywhere on my source?
Depends on the place that you will put it in..
01/15/2010 17:46 copz1337#8
Quote:
Originally Posted by Nullable View Post
Depends on the place that you will put it in..
lol read my previous post i edited it.
01/15/2010 17:51 Sinestro#9
Good job Nullable
Your good at this stuff
01/15/2010 17:56 Nullable#10
Ehm, you shouldn't have c&p'd the code, it was just a skeleton, you need to change stuff in it. .
I never used this version you are using so look for something like this from a proxy i was making a while ago:
Code:
        private void OnClientConnect(IAsyncResult Res)
        {
            string[] IPS = File.ReadAllText(Application.StartupPath + @"\BannedIPs.txt").Split('\r', '\n'); // here i read the ips that i want to block
            SocketPacket sender = null;
            try
            {
                sender = new SocketPacket(this.ProxySocket.EndAccept(Res)) { Connected = true };
                foreach (string IP in IPS)
                {
                    if (IP == sender.RemoteIP) // I created a property for the ip it is the same as Socket.RemoteEndPoint.ToString().Split(':')[0]
                    {
                        if (this.OnClientBlocked != null)
                        {
                            this.OnClientBlocked.Invoke(sender, null);
                        }
                        sender.Connected = false;
                        sender.cont = false;
                        sender.ClientSocket.Disconnect(true);
                    }
                    else
                    {
                        sender.cont = true;
                    }
                }
                if (sender.cont == true)
                {
                    ClientPool.Add(sender.UniqueID, sender);
                    if (this.OnClientConnected != null)
                        this.OnClientConnected.Invoke(sender, null);
                    if (sender.Connected)
                    {
                        sender.ClientSocket.BeginReceive(sender.dataBuffer, 0, sender.dataBuffer.Length, SocketFlags.None
                                                                    , new AsyncCallback(this.OnDataRecieve), sender);
                    }
                }
            }

            catch (Exception)
            {
                if (this.Enabled)
                {
                    sender.cont = false;
                    sender.Connected = false;
                    if (this.OnClientDisconnect != null)
                    {
                        this.OnClientDisconnect.Invoke(sender, null);
                    }
                }
            }
            finally
            {
                if (this.Enabled)
                    ProxySocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
            }
01/15/2010 18:44 Sinestro#11
nice job nullable
This really helped me
01/15/2010 19:11 Nullable#12
Quote:
Originally Posted by Sinestro View Post
nice job nullable
This really helped me
No problem :)
01/15/2010 21:07 copz1337#13
can't i just make like a banned ip list in my oldcodb