فوكس كونكر تهيس - conquer private server
(نسخة قابلة للطباعة من الموضوع)
https://fox.vpscairo.com/t1825
أنقر هنا لمشاهدة الموضوع بهيئته الأصلية

افتراضي سوكت جديد لتخفيف البنج
ElSaher 30-01-2020 09:59 صباحا
بسم الله وصلاة واسلام علي سيدنا محمد رصول الله

اليوم معانا سوكت كويس لتظبيت البنج وا اللعبه وا Fbs

نبدا التركيب

1_ServerSocket


 
كود:
namespace ElSaher.Network.Sockets
{
    
using System;
    
using System.Collections.Concurrent;
    
using System.Net;
    
using System.Net.Sockets;
    
using System.Runtime.InteropServices;
    
using System.Threading;
    
using ElSaher;

    public 
delegate void NetworkClientConnection(ClientWrapper client);
    public 
delegate void NetworkClientReceive(Byte[] bufferInt32 lengthClientWrapper client);

    public class 
ServerSocket
    
{
        public 
Socket Socket get; private set; }
        public 
IPEndPoint LocalEndPoint get; private set; }
        public 
String Name get; private set; }

        public 
NetworkClientConnection OnConnect;
        public 
NetworkClientReceive OnReceive;
        public 
NetworkClientConnection OnDisconnect;
        public 
BruteForceAttackProtection AttackProtector;

        public 
Int32 ClientBufferSize;

        public 
ServerSocket(String nameUInt32 maximumUInt32 banTime)
        {
            
Name name;
            
AttackProtector = new BruteForceAttackProtection(maximumbanTime);
        }

        
/*
         The Set IP Protection Level m*ethod enables restricting an a IPv6 or IP socket to listen on a specified scope, such as addresses with the same link local or site local prefix. This socket option enables applications to place access restrictions on IPv6 or IP sockets. Such restrictions enable an application running on a private LAN to simply and robustly harden itself against external attacks. This socket option can also be used to remove access restrictions if the level parameter is set to Unrestricted. This socket option widens or narrows the scope of a listening socket, enabling unrestricted access from public and private users when appropriate, or restricting access only to the same site, as required.

        This socket option has defined protection levels specified in the IPProtectionLevel enumeration.

        The SetIPProtectionLevel m*ethod is used to enable or disable Network Address Traversal (NAT) for a Socket instance. NAT traversal may be provided using Teredo, 6to4, or an ISATAP tunnel.

        When the level parameter is set to EdgeRestricted, or Restricted, this explicitly disables NAT traversal for a Socket instance.

        When the level parameter is set to EdgeRestricted, this may allow NAT traversal for a Socket depending on firewall rules in place on the system. 
        */
        
public void Prepare(int portIPProtectionLevel protectionLevel)
        {
            
LocalEndPoint = new IPEndPoint(IPAddress.Anyport);
            
Socket = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
            
Socket.Bind(LocalEndPoint);
            
Socket.SetIPProtectionLevel(protectionLevel);
            
Socket.NoDelay true;
            
Socket.Listen((int)SocketOptionName.MaxConnections);
        }

        public 
void BeginAccept()
        {
            
Socket.SetSocketOption(SocketOptionLevel.SocketSocketOptionName.KeepAlivefalse);
            
Socket.SetSocketOption(SocketOptionLevel.SocketSocketOptionName.DontLingertrue);
            
Socket.BeginAccept(Acceptnull);
        }

        private 
void Accept(IAsyncResult result)
        {
            
Socket clientSocket;

            try
            {
                
clientSocket Socket.EndAccept(result);
            }
            catch (
SocketException)
            {
                
BeginAccept();
                return;
            }

            if (
AttackProtector.Authenticate(clientSocket))
            {
                
clientSocket.ReceiveBufferSize ClientBufferSize;
                var 
client = new ClientWrapper(thisclientSocketClientBufferSize);
                
InvokeOnConnect(client);
                
client.BeginReceive();
            }
            else
                
clientSocket.Disconnect(false);
            
BeginAccept();
        }

        public 
void InvokeOnConnect(ClientWrapper client)
        {
            if (
OnConnect != nullOnConnect(client);
        }

        public 
void InvokeOnReceive(Byte[] bufferInt32 lengthClientWrapper client)
        {
            if (
OnReceive != nullOnReceive(bufferlengthclient);
        }

        public 
void InvokeOnDisconnect(ClientWrapper client)
        {
            if (!
client.IsAlive) return;

            
//   client.IsAlive = false;

            
if (OnDisconnect != nullOnDisconnect(client);
        }
    }

_ClientWrapper
 
كود:
namespace ElSaher.Network.Sockets
{
    
using System;
    
using System.Collections.Generic;
    
using System.Net.Sockets;
    
using System.Runtime.InteropServices;
    
using System.Threading;
    
using ElSaher;
    
using System.Net;

    public class 
ClientWrapper
    
{
        public 
Socket Socket get; private set; }
        public 
ServerSocket Server get; private set; }
        public 
IPEndPoint RemoteEndPoint get; private set; }
        private 
readonly byte[] _buffer;
        public 
object Owner;
        public 
Boolean IsAlive get { return Socket.Connected; } }

        public 
String IP
        
{
            
get
            
{
                if (
Socket != null)
                    return (
Socket.RemoteEndPoint as IPEndPoint).Address.ToString();
                else
                    return 
null;
            }
        }

        public 
ClientWrapper(ServerSocket serverSocket socketInt32 bufferLength)
        {
            
//IsAlive = true;
            
Server server;
            
Socket socket;
            
_buffer = new byte[bufferLength];
            
RemoteEndPoint = (IPEndPoint)Socket.RemoteEndPoint;
            
Socket.NoDelay true;
        }

        public 
void BeginReceive()
        {
            try
            {
                
Socket.BeginReceive(_buffer0_buffer.LengthSocketFlags.None, new AsyncCallback(Receive), null);
            }
            catch (
SocketException)
            {
                
Server.InvokeOnDisconnect(this);
            }
        }

        private 
void Receive(IAsyncResult result)
        {
            if (
Socket != null)
            {
                try
                {
                    
SocketError error;
                    
Int32 length Socket.EndReceive(resultout error);
                    if (
IsAlive && error == SocketError.Success)
                    {
                        if (
length 0)
                        {
                            try
                            {
                                
Server.InvokeOnReceive(_bufferlengththis);
                            }
                            catch (
Exception e)
                            {
                                
System.Console.WriteLine(e.ToString());
                            }
                            finally
                            {
                                
BeginReceive();
                            }
                        }
                        else
                        {
                            
Server.InvokeOnDisconnect(this);
                        }
                    }
                }
                catch (
SocketException)
                {
                    
Server.InvokeOnDisconnect(this);
                }
            }
        }
        public 
void Send(byte[] packet)
        {
            if (
IsAlive)
            {
                try
                {
                    
Socket.BeginSend(packet0packet.LengthSocketFlags.None, new AsyncCallback(EndSend), null);
                }
                catch (
SocketException)
                {
                    
Server.InvokeOnDisconnect(this);
                }
            }
        }

        private 
void EndSend(IAsyncResult result)
        {
            try
            {
                
Socket.EndSend(result);
            }
            catch (
SocketException)
            {
                
Server.InvokeOnDisconnect(this);
            }
        }

        public 
void Disconnect()
        {
            try
            {
                
Socket.Disconnect(false);
            }
            catch (
SocketException)
            {
            }
            
Server.InvokeOnDisconnect(this);
        }

        public 
override string ToString()
        {
            return 
RemoteEndPoint.ToString();
        }
    }

بلتوفيق يا رجاله
 
فوكس كونكر تهيس - conquer private server

Powered by PBBoard ©Version 3.0.3