قديم 2020-04-10, 11:59 PM
المشاركة 2
ElSaher
.:: عضو خبير ::.
  • غير متواجد
افتراضي رد: مشكلة في البنج
غير السوكت يا حوب

شوف اي سورس عجبك واسحب منو السوكت بس

قديم 2020-04-11, 05:22 AM
المشاركة 3
Hassan Emprator
.:: عضو خبير ::.
  • غير متواجد
افتراضي رد: مشكلة في البنج
كلاس
ServerSocket

امسسحه اكواده وحط دا


كود:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Collections.Generic;
using System.Collections.Concurrent;

namespace 
MrHassan.Network.Sockets
{
    public class 
ServerSocket
    
{
        public 
event Action<ClientWrapperOnClientConnectOnClientDisconnect;
        public 
event Action<byte[], intClientWrapperOnClientReceive;

        private 
ConcurrentDictionary<intintBruteforceProtection;
        private const 
int TimeLimit 1000 15// 1 connection every 10 seconds for one ip
        
private object SyncRoot;

        private 
Socket Connection;
        private 
ushort port;
        private 
string ipString;
        private 
bool enabled;
        private 
Thread thread;
        public 
ServerSocket()
        {
            
this.Connection = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
            
this.SyncRoot = new object();
            
thread = new Thread(doSyncAccept);
            
thread.Start();
        }

        public 
void Enable(ushort portstring ipbool BigSend false)
        {
            
this.ipString ip;
            
this.port port;
            
this.Connection.Bind(new IPEndPoint(IPAddress.Parse(ipString), this.port));
            
this.Connection.Listen((int)SocketOptionName.MaxConnections);
            if (
BigSend)
            {
                
this.Connection.ReceiveBufferSize ushort.MaxValue;
                
this.Connection.SendBufferSize ushort.MaxValue;
            }
            
this.enabled true;
            
BruteforceProtection = new ConcurrentDictionary<intint>();
        }

        public 
bool PrintoutIPs false;
        private 
void doSyncAccept()
        {
            while (
true)
            {
                if (
this.enabled)
                {
                    try
                    {
                        
processSocket(this.Connection.Accept());
                    }
                    catch { }
                }
                
Thread.Sleep(1);
            }
        }
        private 
void doAsyncAccept(IAsyncResult res)
        {
            try
            {
                
Socket socket this.Connection.EndAccept(res);
                
processSocket(socket);
                
this.Connection.BeginAccept(doAsyncAcceptnull);
            }
            catch
            {

            }
        }

        private 
void processSocket(Socket socket)
        {
            try
            {
                
string ip = (socket.RemoteEndPoint as IPEndPoint).Address.ToString();
                
int ipHash ip.GetHashCode();
                
/* if (!Program.ALEXPC)
                 {
                     int time = Time32.Now.GetHashCode();
                     int oldValue;
                     if (!BruteforceProtection.TryGetValue(ipHash, out oldValue))
                     {
                         BruteforceProtection[ipHash] = time;
                     }
                     else
                     {
                         if (time - oldValue < TimeLimit)
                         {
                             if (PrintoutIPs) Console.WriteLine("Dropped connection: " + ip);
                             socket.Disconnect(false);
                             socket.Close();
                             return;
                         }
                         else
                         {
                             BruteforceProtection[ipHash] = time;
                             if (PrintoutIPs) Console.WriteLine("Allowed connection: " + ip);
                         }
                     }
                 }*/
                
ClientWrapper wrapper = new ClientWrapper();
                
wrapper.Create(socketthisOnClientReceive);
                
wrapper.IsAlive true;
                
wrapper.IP ip;
                if (
this.OnClientConnect != nullthis.OnClientConnect(wrapper);
            }
            catch
            {

            }
        }

        public 
void Reset()
        {
            
this.Disable();
            
this.Enable();
        }

        public 
void Disable()
        {
            
this.enabled false;
            
this.Connection.Close(1);
        }

        public 
void Enable()
        {
            if (!
this.enabled)
            {
                
this.Connection = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
                
this.Connection.Bind(new IPEndPoint(IPAddress.Parse(ipString), this.port));
                
this.Connection.Listen((int)SocketOptionName.MaxConnections);
                
this.enabled true;
                
//this.Connection.BeginAccept(doAsyncAccept, null);
            
}
        }

        public 
void InvokeDisconnect(ClientWrapper Client)
        {
            if (
this.OnClientDisconnect != null)
                
this.OnClientDisconnect(Client);
        }

        public 
bool Enabled
        
{
            
get
            
{
                return 
this.enabled;
            }
        }
    }


كلاس
ClientWrapper

نفس كلام وحط


كود:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using MrHassan.Network.Cryptography;

namespace 
MrHassan.Network.Sockets
{
    public class 
ClientWrapper
    
{
        [
DllImport("ws2_32.dll"CharSet CharSet.UnicodeSetLastError true)]
        public static 
extern int closesocket(IntPtr s);
        [
DllImport("ws2_32.dll"CharSet CharSet.UnicodeSetLastError true)]
        public static 
extern int shutdown(IntPtr sShutDownFlags how);
        public 
enum ShutDownFlags int
        
{
            
SD_RECEIVE 0,
            
SD_SEND 1,
            
SD_BOTH 2
        
}

        public 
int BufferSize;
        public 
byte[] Buffer;
        public 
Socket Socket;
        public 
object Owner;
        public 
ServerSocket Server;
        public 
string IP;
        public 
string MAC;
        public 
bool IsAlive;
        public 
bool OverrideTiming;
        private 
IDisposable[] TimerSubscriptions;
        private 
Queue<byte[]> SendQueue;
        private 
object SendSyncRoot;

        public 
Action<byte[], intClientWrapperCallback;
        public 
void Create(Socket socketServerSocket serverAction<byte[], intClientWrappercallBack)
        {
            
Callback callBack;
            
BufferSize 2047;//ushort.MaxValue
            
Socket socket;
            
Server server;
            
Buffer = new byte[BufferSize];
            
LastReceive Time32.Now;
            
OverrideTiming false;
            
SendQueue = new Queue<byte[]>();
            
SendSyncRoot = new object();
            
TimerSubscriptions = new[] 
            {
                
World.Subscribe<ClientWrapper>(Program.World.ConnectionReviewthisWorld.GenericThreadPool),
                
World.Subscribe<ClientWrapper>(Program.World.ConnectionReceivethisWorld.ReceivePool),
                
World.Subscribe<ClientWrapper>(Program.World.ConnectionSendthisWorld.SendPool)
            };
        }

        
/// <summary>
        /// To be called only from a syncrhonized block of code
        /// </summary>
        /// <param name="data"></param>
        
public void Send(byte[] data)
        {
#if DIRECTSEND
            
lock (SendSyncRoot)
                
Socket.Send(data);
#else
            
lock (SendSyncRoot)
            {

                
SendQueue.Enqueue(data);
            }
#endif
        
}

        public 
Time32 LastReceive;
        public 
Time32 LastReceiveCall;
        public 
bool Connected;

        public 
void Disconnect()
        {
            
lock (Socket)
            {
                
int K 1000;
                while (
SendQueue.Count && IsAlive && (K--) > 0)
                    
Thread.Sleep(1);
                if (!
IsAlive) return;
                
IsAlive false;

                for (
int i 0TimerSubscriptions.Lengthi++)
                    
TimerSubscriptions[i].Dispose();

                
shutdown(Socket.HandleShutDownFlags.SD_BOTH);
                
closesocket(Socket.Handle);

                
Socket.Dispose();
            }
        }

        public static 
void TryReview(ClientWrapper wrapper)
        {
            if (
wrapper.IsAlive)
            {
                if (
wrapper.OverrideTiming)
                {
                    if (
Time32.Now wrapper.LastReceive.AddMilliseconds(180000))
                        
wrapper.Server.InvokeDisconnect(wrapper);
                }
                else
                {
                    if (
Time32.Now wrapper.LastReceiveCall.AddMilliseconds(2000))
                        if (
Time32.Now wrapper.LastReceive.AddMilliseconds(60000))
                            
wrapper.Server.InvokeDisconnect(wrapper);
                }
            }
        }

        private 
bool isValid()
        {
            if (!
IsAlive)
            {
                for (
int i 0TimerSubscriptions.Lengthi++)
                    
TimerSubscriptions[i].Dispose();
                return 
false;
            }
            return 
true;
        }

        private 
void doReceive(int available)
        {
            
LastReceive Time32.Now;
            try
            {
                if (
available Buffer.Lengthavailable Buffer.Length;
                
int size Socket.Receive(BufferavailableSocketFlags.None);
                if (
size != 0)
                {
                    if (
Callback != null)
                    {
                        
Callback(Buffersizethis);

                    }
                }
                else
                {
                    
Server.InvokeDisconnect(this);
                }
            }
            catch (
SocketException)
            {
                
Server.InvokeDisconnect(this);
            }
            catch (
Exception e)
            {
                
Console.WriteLine(e);
            }
        }
        public static 
void TryReceive(ClientWrapper wrapper)
        {
            
wrapper.LastReceiveCall Time32.Now;
            if (!
wrapper.isValid()) return;
            try
            {
                
bool poll wrapper.Socket.Poll(0SelectMode.SelectRead);
                
int available wrapper.Socket.Available;
                if (
available 0)
                    
wrapper.doReceive(available);
                else if (
poll)
                    
wrapper.Server.InvokeDisconnect(wrapper);
            }
            catch (
SocketException)
            {
                
wrapper.Server.InvokeDisconnect(wrapper);
            }
        }

        private 
bool TryDequeueSend(out byte[] buffer)
        {
            
buffer null;
            
lock (SendSyncRoot)
                if (
SendQueue.Count != 0)
                    
buffer SendQueue.Dequeue();
            return 
buffer != null;
        }
        public static 
void TrySend(ClientWrapper wrapper)
        {
            if (!
wrapper.isValid()) return;
            
byte[] buffer;

            while (
wrapper.TryDequeueSend(out buffer))
            {
                try
                {
                    
wrapper.Socket.Send(buffer);
                    
//wrapper.Socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, endSend, wrapper);
                
}
                catch
                {
                    
wrapper.Server.InvokeDisconnect(wrapper);
                }
            }
        }

        private static 
void endSend(IAsyncResult ar)
        {
            var 
wrapper ar.AsyncState as ClientWrapper;
            try
            {
                
wrapper.Socket.EndSend(ar);
            }
            catch
            {
                
wrapper.Server.InvokeDisconnect(wrapper);
            }
        }
    }



قديم 2020-04-11, 04:39 PM
المشاركة 4
ahmeddd
.:: عضو نشيط ::.
  • غير متواجد
افتراضي رد: مشكلة في البنج
كلاس
ServerSocket

امسسحه اكواده وحط دا


كود:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Collections.Generic;
using System.Collections.Concurrent;

namespace 
MrHassan.Network.Sockets
{
    public class 
ServerSocket
    
{
        public 
event Action<ClientWrapperOnClientConnectOnClientDisconnect;
        public 
event Action<byte[], intClientWrapperOnClientReceive;

        private 
ConcurrentDictionary<intintBruteforceProtection;
        private const 
int TimeLimit 1000 15// 1 connection every 10 seconds for one ip
        
private object SyncRoot;

        private 
Socket Connection;
        private 
ushort port;
        private 
string ipString;
        private 
bool enabled;
        private 
Thread thread;
        public 
ServerSocket()
        {
            
this.Connection = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
            
this.SyncRoot = new object();
            
thread = new Thread(doSyncAccept);
            
thread.Start();
        }

        public 
void Enable(ushort portstring ipbool BigSend false)
        {
            
this.ipString ip;
            
this.port port;
            
this.Connection.Bind(new IPEndPoint(IPAddress.Parse(ipString), this.port));
            
this.Connection.Listen((int)SocketOptionName.MaxConnections);
            if (
BigSend)
            {
                
this.Connection.ReceiveBufferSize ushort.MaxValue;
                
this.Connection.SendBufferSize ushort.MaxValue;
            }
            
this.enabled true;
            
BruteforceProtection = new ConcurrentDictionary<intint>();
        }

        public 
bool PrintoutIPs false;
        private 
void doSyncAccept()
        {
            while (
true)
            {
                if (
this.enabled)
                {
                    try
                    {
                        
processSocket(this.Connection.Accept());
                    }
                    catch { }
                }
                
Thread.Sleep(1);
            }
        }
        private 
void doAsyncAccept(IAsyncResult res)
        {
            try
            {
                
Socket socket this.Connection.EndAccept(res);
                
processSocket(socket);
                
this.Connection.BeginAccept(doAsyncAcceptnull);
            }
            catch
            {

            }
        }

        private 
void processSocket(Socket socket)
        {
            try
            {
                
string ip = (socket.RemoteEndPoint as IPEndPoint).Address.ToString();
                
int ipHash ip.GetHashCode();
                
/* if (!Program.ALEXPC)
                 {
                     int time = Time32.Now.GetHashCode();
                     int oldValue;
                     if (!BruteforceProtection.TryGetValue(ipHash, out oldValue))
                     {
                         BruteforceProtection[ipHash] = time;
                     }
                     else
                     {
                         if (time - oldValue < TimeLimit)
                         {
                             if (PrintoutIPs) Console.WriteLine("Dropped connection: " + ip);
                             socket.Disconnect(false);
                             socket.Close();
                             return;
                         }
                         else
                         {
                             BruteforceProtection[ipHash] = time;
                             if (PrintoutIPs) Console.WriteLine("Allowed connection: " + ip);
                         }
                     }
                 }*/
                
ClientWrapper wrapper = new ClientWrapper();
                
wrapper.Create(socketthisOnClientReceive);
                
wrapper.IsAlive true;
                
wrapper.IP ip;
                if (
this.OnClientConnect != nullthis.OnClientConnect(wrapper);
            }
            catch
            {

            }
        }

        public 
void Reset()
        {
            
this.Disable();
            
this.Enable();
        }

        public 
void Disable()
        {
            
this.enabled false;
            
this.Connection.Close(1);
        }

        public 
void Enable()
        {
            if (!
this.enabled)
            {
                
this.Connection = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
                
this.Connection.Bind(new IPEndPoint(IPAddress.Parse(ipString), this.port));
                
this.Connection.Listen((int)SocketOptionName.MaxConnections);
                
this.enabled true;
                
//this.Connection.BeginAccept(doAsyncAccept, null);
            
}
        }

        public 
void InvokeDisconnect(ClientWrapper Client)
        {
            if (
this.OnClientDisconnect != null)
                
this.OnClientDisconnect(Client);
        }

        public 
bool Enabled
        
{
            
get
            
{
                return 
this.enabled;
            }
        }
    }


كلاس
ClientWrapper

نفس كلام وحط


كود:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using MrHassan.Network.Cryptography;

namespace 
MrHassan.Network.Sockets
{
    public class 
ClientWrapper
    
{
        [
DllImport("ws2_32.dll"CharSet CharSet.UnicodeSetLastError true)]
        public static 
extern int closesocket(IntPtr s);
        [
DllImport("ws2_32.dll"CharSet CharSet.UnicodeSetLastError true)]
        public static 
extern int shutdown(IntPtr sShutDownFlags how);
        public 
enum ShutDownFlags int
        
{
            
SD_RECEIVE 0,
            
SD_SEND 1,
            
SD_BOTH 2
        
}

        public 
int BufferSize;
        public 
byte[] Buffer;
        public 
Socket Socket;
        public 
object Owner;
        public 
ServerSocket Server;
        public 
string IP;
        public 
string MAC;
        public 
bool IsAlive;
        public 
bool OverrideTiming;
        private 
IDisposable[] TimerSubscriptions;
        private 
Queue<byte[]> SendQueue;
        private 
object SendSyncRoot;

        public 
Action<byte[], intClientWrapperCallback;
        public 
void Create(Socket socketServerSocket serverAction<byte[], intClientWrappercallBack)
        {
            
Callback callBack;
            
BufferSize 2047;//ushort.MaxValue
            
Socket socket;
            
Server server;
            
Buffer = new byte[BufferSize];
            
LastReceive Time32.Now;
            
OverrideTiming false;
            
SendQueue = new Queue<byte[]>();
            
SendSyncRoot = new object();
            
TimerSubscriptions = new[] 
            {
                
World.Subscribe<ClientWrapper>(Program.World.ConnectionReviewthisWorld.GenericThreadPool),
                
World.Subscribe<ClientWrapper>(Program.World.ConnectionReceivethisWorld.ReceivePool),
                
World.Subscribe<ClientWrapper>(Program.World.ConnectionSendthisWorld.SendPool)
            };
        }

        
/// <summary>
        /// To be called only from a syncrhonized block of code
        /// </summary>
        /// <param name="data"></param>
        
public void Send(byte[] data)
        {
#if DIRECTSEND
            
lock (SendSyncRoot)
                
Socket.Send(data);
#else
            
lock (SendSyncRoot)
            {

                
SendQueue.Enqueue(data);
            }
#endif
        
}

        public 
Time32 LastReceive;
        public 
Time32 LastReceiveCall;
        public 
bool Connected;

        public 
void Disconnect()
        {
            
lock (Socket)
            {
                
int K 1000;
                while (
SendQueue.Count && IsAlive && (K--) > 0)
                    
Thread.Sleep(1);
                if (!
IsAlive) return;
                
IsAlive false;

                for (
int i 0TimerSubscriptions.Lengthi++)
                    
TimerSubscriptions[i].Dispose();

                
shutdown(Socket.HandleShutDownFlags.SD_BOTH);
                
closesocket(Socket.Handle);

                
Socket.Dispose();
            }
        }

        public static 
void TryReview(ClientWrapper wrapper)
        {
            if (
wrapper.IsAlive)
            {
                if (
wrapper.OverrideTiming)
                {
                    if (
Time32.Now wrapper.LastReceive.AddMilliseconds(180000))
                        
wrapper.Server.InvokeDisconnect(wrapper);
                }
                else
                {
                    if (
Time32.Now wrapper.LastReceiveCall.AddMilliseconds(2000))
                        if (
Time32.Now wrapper.LastReceive.AddMilliseconds(60000))
                            
wrapper.Server.InvokeDisconnect(wrapper);
                }
            }
        }

        private 
bool isValid()
        {
            if (!
IsAlive)
            {
                for (
int i 0TimerSubscriptions.Lengthi++)
                    
TimerSubscriptions[i].Dispose();
                return 
false;
            }
            return 
true;
        }

        private 
void doReceive(int available)
        {
            
LastReceive Time32.Now;
            try
            {
                if (
available Buffer.Lengthavailable Buffer.Length;
                
int size Socket.Receive(BufferavailableSocketFlags.None);
                if (
size != 0)
                {
                    if (
Callback != null)
                    {
                        
Callback(Buffersizethis);

                    }
                }
                else
                {
                    
Server.InvokeDisconnect(this);
                }
            }
            catch (
SocketException)
            {
                
Server.InvokeDisconnect(this);
            }
            catch (
Exception e)
            {
                
Console.WriteLine(e);
            }
        }
        public static 
void TryReceive(ClientWrapper wrapper)
        {
            
wrapper.LastReceiveCall Time32.Now;
            if (!
wrapper.isValid()) return;
            try
            {
                
bool poll wrapper.Socket.Poll(0SelectMode.SelectRead);
                
int available wrapper.Socket.Available;
                if (
available 0)
                    
wrapper.doReceive(available);
                else if (
poll)
                    
wrapper.Server.InvokeDisconnect(wrapper);
            }
            catch (
SocketException)
            {
                
wrapper.Server.InvokeDisconnect(wrapper);
            }
        }

        private 
bool TryDequeueSend(out byte[] buffer)
        {
            
buffer null;
            
lock (SendSyncRoot)
                if (
SendQueue.Count != 0)
                    
buffer SendQueue.Dequeue();
            return 
buffer != null;
        }
        public static 
void TrySend(ClientWrapper wrapper)
        {
            if (!
wrapper.isValid()) return;
            
byte[] buffer;

            while (
wrapper.TryDequeueSend(out buffer))
            {
                try
                {
                    
wrapper.Socket.Send(buffer);
                    
//wrapper.Socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, endSend, wrapper);
                
}
                catch
                {
                    
wrapper.Server.InvokeDisconnect(wrapper);
                }
            }
        }

        private static 
void endSend(IAsyncResult ar)
        {
            var 
wrapper ar.AsyncState as ClientWrapper;
            try
            {
                
wrapper.Socket.EndSend(ar);
            }
            catch
            {
                
wrapper.Server.InvokeDisconnect(wrapper);
            }
        }
    }

تسلم يا باشا

قديم 2020-04-12, 01:41 AM
المشاركة 5
ahmeddd
.:: عضو نشيط ::.
  • غير متواجد
افتراضي رد: مشكلة في البنج
كلاس
ServerSocket

امسسحه اكواده وحط دا


كود:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Collections.Generic;
using System.Collections.Concurrent;

namespace 
MrHassan.Network.Sockets
{
    public class 
ServerSocket
    
{
        public 
event Action<ClientWrapperOnClientConnectOnClientDisconnect;
        public 
event Action<byte[], intClientWrapperOnClientReceive;

        private 
ConcurrentDictionary<intintBruteforceProtection;
        private const 
int TimeLimit 1000 15// 1 connection every 10 seconds for one ip
        
private object SyncRoot;

        private 
Socket Connection;
        private 
ushort port;
        private 
string ipString;
        private 
bool enabled;
        private 
Thread thread;
        public 
ServerSocket()
        {
            
this.Connection = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
            
this.SyncRoot = new object();
            
thread = new Thread(doSyncAccept);
            
thread.Start();
        }

        public 
void Enable(ushort portstring ipbool BigSend false)
        {
            
this.ipString ip;
            
this.port port;
            
this.Connection.Bind(new IPEndPoint(IPAddress.Parse(ipString), this.port));
            
this.Connection.Listen((int)SocketOptionName.MaxConnections);
            if (
BigSend)
            {
                
this.Connection.ReceiveBufferSize ushort.MaxValue;
                
this.Connection.SendBufferSize ushort.MaxValue;
            }
            
this.enabled true;
            
BruteforceProtection = new ConcurrentDictionary<intint>();
        }

        public 
bool PrintoutIPs false;
        private 
void doSyncAccept()
        {
            while (
true)
            {
                if (
this.enabled)
                {
                    try
                    {
                        
processSocket(this.Connection.Accept());
                    }
                    catch { }
                }
                
Thread.Sleep(1);
            }
        }
        private 
void doAsyncAccept(IAsyncResult res)
        {
            try
            {
                
Socket socket this.Connection.EndAccept(res);
                
processSocket(socket);
                
this.Connection.BeginAccept(doAsyncAcceptnull);
            }
            catch
            {

            }
        }

        private 
void processSocket(Socket socket)
        {
            try
            {
                
string ip = (socket.RemoteEndPoint as IPEndPoint).Address.ToString();
                
int ipHash ip.GetHashCode();
                
/* if (!Program.ALEXPC)
                 {
                     int time = Time32.Now.GetHashCode();
                     int oldValue;
                     if (!BruteforceProtection.TryGetValue(ipHash, out oldValue))
                     {
                         BruteforceProtection[ipHash] = time;
                     }
                     else
                     {
                         if (time - oldValue < TimeLimit)
                         {
                             if (PrintoutIPs) Console.WriteLine("Dropped connection: " + ip);
                             socket.Disconnect(false);
                             socket.Close();
                             return;
                         }
                         else
                         {
                             BruteforceProtection[ipHash] = time;
                             if (PrintoutIPs) Console.WriteLine("Allowed connection: " + ip);
                         }
                     }
                 }*/
                
ClientWrapper wrapper = new ClientWrapper();
                
wrapper.Create(socketthisOnClientReceive);
                
wrapper.IsAlive true;
                
wrapper.IP ip;
                if (
this.OnClientConnect != nullthis.OnClientConnect(wrapper);
            }
            catch
            {

            }
        }

        public 
void Reset()
        {
            
this.Disable();
            
this.Enable();
        }

        public 
void Disable()
        {
            
this.enabled false;
            
this.Connection.Close(1);
        }

        public 
void Enable()
        {
            if (!
this.enabled)
            {
                
this.Connection = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
                
this.Connection.Bind(new IPEndPoint(IPAddress.Parse(ipString), this.port));
                
this.Connection.Listen((int)SocketOptionName.MaxConnections);
                
this.enabled true;
                
//this.Connection.BeginAccept(doAsyncAccept, null);
            
}
        }

        public 
void InvokeDisconnect(ClientWrapper Client)
        {
            if (
this.OnClientDisconnect != null)
                
this.OnClientDisconnect(Client);
        }

        public 
bool Enabled
        
{
            
get
            
{
                return 
this.enabled;
            }
        }
    }


كلاس
ClientWrapper

نفس كلام وحط


كود:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using MrHassan.Network.Cryptography;

namespace 
MrHassan.Network.Sockets
{
    public class 
ClientWrapper
    
{
        [
DllImport("ws2_32.dll"CharSet CharSet.UnicodeSetLastError true)]
        public static 
extern int closesocket(IntPtr s);
        [
DllImport("ws2_32.dll"CharSet CharSet.UnicodeSetLastError true)]
        public static 
extern int shutdown(IntPtr sShutDownFlags how);
        public 
enum ShutDownFlags int
        
{
            
SD_RECEIVE 0,
            
SD_SEND 1,
            
SD_BOTH 2
        
}

        public 
int BufferSize;
        public 
byte[] Buffer;
        public 
Socket Socket;
        public 
object Owner;
        public 
ServerSocket Server;
        public 
string IP;
        public 
string MAC;
        public 
bool IsAlive;
        public 
bool OverrideTiming;
        private 
IDisposable[] TimerSubscriptions;
        private 
Queue<byte[]> SendQueue;
        private 
object SendSyncRoot;

        public 
Action<byte[], intClientWrapperCallback;
        public 
void Create(Socket socketServerSocket serverAction<byte[], intClientWrappercallBack)
        {
            
Callback callBack;
            
BufferSize 2047;//ushort.MaxValue
            
Socket socket;
            
Server server;
            
Buffer = new byte[BufferSize];
            
LastReceive Time32.Now;
            
OverrideTiming false;
            
SendQueue = new Queue<byte[]>();
            
SendSyncRoot = new object();
            
TimerSubscriptions = new[] 
            {
                
World.Subscribe<ClientWrapper>(Program.World.ConnectionReviewthisWorld.GenericThreadPool),
                
World.Subscribe<ClientWrapper>(Program.World.ConnectionReceivethisWorld.ReceivePool),
                
World.Subscribe<ClientWrapper>(Program.World.ConnectionSendthisWorld.SendPool)
            };
        }

        
/// <summary>
        /// To be called only from a syncrhonized block of code
        /// </summary>
        /// <param name="data"></param>
        
public void Send(byte[] data)
        {
#if DIRECTSEND
            
lock (SendSyncRoot)
                
Socket.Send(data);
#else
            
lock (SendSyncRoot)
            {

                
SendQueue.Enqueue(data);
            }
#endif
        
}

        public 
Time32 LastReceive;
        public 
Time32 LastReceiveCall;
        public 
bool Connected;

        public 
void Disconnect()
        {
            
lock (Socket)
            {
                
int K 1000;
                while (
SendQueue.Count && IsAlive && (K--) > 0)
                    
Thread.Sleep(1);
                if (!
IsAlive) return;
                
IsAlive false;

                for (
int i 0TimerSubscriptions.Lengthi++)
                    
TimerSubscriptions[i].Dispose();

                
shutdown(Socket.HandleShutDownFlags.SD_BOTH);
                
closesocket(Socket.Handle);

                
Socket.Dispose();
            }
        }

        public static 
void TryReview(ClientWrapper wrapper)
        {
            if (
wrapper.IsAlive)
            {
                if (
wrapper.OverrideTiming)
                {
                    if (
Time32.Now wrapper.LastReceive.AddMilliseconds(180000))
                        
wrapper.Server.InvokeDisconnect(wrapper);
                }
                else
                {
                    if (
Time32.Now wrapper.LastReceiveCall.AddMilliseconds(2000))
                        if (
Time32.Now wrapper.LastReceive.AddMilliseconds(60000))
                            
wrapper.Server.InvokeDisconnect(wrapper);
                }
            }
        }

        private 
bool isValid()
        {
            if (!
IsAlive)
            {
                for (
int i 0TimerSubscriptions.Lengthi++)
                    
TimerSubscriptions[i].Dispose();
                return 
false;
            }
            return 
true;
        }

        private 
void doReceive(int available)
        {
            
LastReceive Time32.Now;
            try
            {
                if (
available Buffer.Lengthavailable Buffer.Length;
                
int size Socket.Receive(BufferavailableSocketFlags.None);
                if (
size != 0)
                {
                    if (
Callback != null)
                    {
                        
Callback(Buffersizethis);

                    }
                }
                else
                {
                    
Server.InvokeDisconnect(this);
                }
            }
            catch (
SocketException)
            {
                
Server.InvokeDisconnect(this);
            }
            catch (
Exception e)
            {
                
Console.WriteLine(e);
            }
        }
        public static 
void TryReceive(ClientWrapper wrapper)
        {
            
wrapper.LastReceiveCall Time32.Now;
            if (!
wrapper.isValid()) return;
            try
            {
                
bool poll wrapper.Socket.Poll(0SelectMode.SelectRead);
                
int available wrapper.Socket.Available;
                if (
available 0)
                    
wrapper.doReceive(available);
                else if (
poll)
                    
wrapper.Server.InvokeDisconnect(wrapper);
            }
            catch (
SocketException)
            {
                
wrapper.Server.InvokeDisconnect(wrapper);
            }
        }

        private 
bool TryDequeueSend(out byte[] buffer)
        {
            
buffer null;
            
lock (SendSyncRoot)
                if (
SendQueue.Count != 0)
                    
buffer SendQueue.Dequeue();
            return 
buffer != null;
        }
        public static 
void TrySend(ClientWrapper wrapper)
        {
            if (!
wrapper.isValid()) return;
            
byte[] buffer;

            while (
wrapper.TryDequeueSend(out buffer))
            {
                try
                {
                    
wrapper.Socket.Send(buffer);
                    
//wrapper.Socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, endSend, wrapper);
                
}
                catch
                {
                    
wrapper.Server.InvokeDisconnect(wrapper);
                }
            }
        }

        private static 
void endSend(IAsyncResult ar)
        {
            var 
wrapper ar.AsyncState as ClientWrapper;
            try
            {
                
wrapper.Socket.EndSend(ar);
            }
            catch
            {
                
wrapper.Server.InvokeDisconnect(wrapper);
            }
        }
    }

بيجيلي ايرورات في كلمة alive ٣٦ ايرور

قديم 2020-04-12, 02:01 AM
المشاركة 6
ElSaher
.:: عضو خبير ::.
  • غير متواجد
افتراضي رد: مشكلة في البنج
بيجيلي ايرورات في كلمة alive ٣٦ ايرور
اكتب جنب الايررور Is

قديم 2020-04-12, 09:06 AM
المشاركة 7
Users
.:: عضو خبير ::.
  • غير متواجد
افتراضي رد: مشكلة في البنج
كلاس
serversocket

امسسحه اكواده وحط دا


كود:
using system;
using system.io;
using system.net;
using system.net.sockets;
using system.text;
using system.threading;
using system.collections.generic;
using system.collections.concurrent;

namespace 
mrhassan.network.sockets
{
    public class 
serversocket
    
{
        public 
event action<clientwrapperonclientconnectonclientdisconnect;
        public 
event action<byte[], intclientwrapperonclientreceive;

        private 
concurrentdictionary<intintbruteforceprotection;
        private const 
int timelimit 1000 15// 1 connection every 10 seconds for one ip
        
private object syncroot;

        private 
socket connection;
        private 
ushort port;
        private 
string ipstring;
        private 
bool enabled;
        private 
thread thread;
        public 
serversocket()
        {
            
this.connection = new socket(addressfamily.internetworksockettype.streamprotocoltype.tcp);
            
this.syncroot = new object();
            
thread = new thread(dosyncaccept);
            
thread.start();
        }

        public 
void enable(ushort portstring ipbool bigsend false)
        {
            
this.ipstring ip;
            
this.port port;
            
this.connection.bind(new ipendpoint(ipaddress.parse(ipstring), this.port));
            
this.connection.listen((int)socketoptionname.maxconnections);
            if (
bigsend)
            {
                
this.connection.receivebuffersize ushort.maxvalue;
                
this.connection.sendbuffersize ushort.maxvalue;
            }
            
this.enabled true;
            
bruteforceprotection = new concurrentdictionary<intint>();
        }

        public 
bool printoutips false;
        private 
void dosyncaccept()
        {
            while (
true)
            {
                if (
this.enabled)
                {
                    try
                    {
                        
processsocket(this.connection.accept());
                    }
                    catch { }
                }
                
thread.sleep(1);
            }
        }
        private 
void doasyncaccept(iasyncresult res)
        {
            try
            {
                
socket socket this.connection.endaccept(res);
                
processsocket(socket);
                
this.connection.beginaccept(doasyncacceptnull);
            }
            catch
            {

            }
        }

        private 
void processsocket(socket socket)
        {
            try
            {
                
string ip = (socket.remoteendpoint as ipendpoint).address.tostring();
                
int iphash ip.gethashcode();
                
/* if (!program.alexpc)
                 {
                     int time = time32.now.gethashcode();
                     int oldvalue;
                     if (!bruteforceprotection.trygetvalue(iphash, out oldvalue))
                     {
                         bruteforceprotection[iphash] = time;
                     }
                     else
                     {
                         if (time - oldvalue < timelimit)
                         {
                             if (printoutips) console.writeline("dropped connection: " + ip);
                             socket.disconnect(false);
                             socket.close();
                             return;
                         }
                         else
                         {
                             bruteforceprotection[iphash] = time;
                             if (printoutips) console.writeline("allowed connection: " + ip);
                         }
                     }
                 }*/
                
clientwrapper wrapper = new clientwrapper();
                
wrapper.create(socketthisonclientreceive);
                
wrapper.isalive true;
                
wrapper.ip ip;
                if (
this.onclientconnect != nullthis.onclientconnect(wrapper);
            }
            catch
            {

            }
        }

        public 
void reset()
        {
            
this.disable();
            
this.enable();
        }

        public 
void disable()
        {
            
this.enabled false;
            
this.connection.close(1);
        }

        public 
void enable()
        {
            if (!
this.enabled)
            {
                
this.connection = new socket(addressfamily.internetworksockettype.streamprotocoltype.tcp);
                
this.connection.bind(new ipendpoint(ipaddress.parse(ipstring), this.port));
                
this.connection.listen((int)socketoptionname.maxconnections);
                
this.enabled true;
                
//this.connection.beginaccept(doasyncaccept, null);
            
}
        }

        public 
void invokedisconnect(clientwrapper client)
        {
            if (
this.onclientdisconnect != null)
                
this.onclientdisconnect(client);
        }

        public 
bool enabled
        
{
            
get
            
{
                return 
this.enabled;
            }
        }
    }


كلاس
clientwrapper

نفس كلام وحط


كود:
using system;
using system.collections.generic;
using system.linq;
using system.net.sockets;
using system.threading;
using system.collections.concurrent;
using system.runtime.interopservices;
using mrhassan.network.cryptography;

namespace 
mrhassan.network.sockets
{
    public class 
clientwrapper
    
{
        [
dllimport("ws2_32.dll"charset charset.unicodesetlasterror true)]
        public static 
extern int closesocket(intptr s);
        [
dllimport("ws2_32.dll"charset charset.unicodesetlasterror true)]
        public static 
extern int shutdown(intptr sshutdownflags how);
        public 
enum shutdownflags Int
        
{
            
sd_receive 0,
            
sd_send 1,
            
sd_both 2
        
}

        public 
int buffersize;
        public 
byte[] buffer;
        public 
socket socket;
        public 
object owner;
        public 
serversocket server;
        public 
string ip;
        public 
string mac;
        public 
bool isalive;
        public 
bool overridetiming;
        private 
idisposable[] timersubscriptions;
        private 
queue<byte[]> sendqueue;
        private 
object sendsyncroot;

        public 
action<byte[], intclientwrappercallback;
        public 
void create(socket socketserversocket serveraction<byte[], intclientwrappercallback)
        {
            
callback callback;
            
buffersize 2047;//ushort.maxvalue
            
socket socket;
            
server server;
            
buffer = new byte[buffersize];
            
lastreceive time32.now;
            
overridetiming false;
            
sendqueue = new queue<byte[]>();
            
sendsyncroot = new object();
            
timersubscriptions = new[] 
            {
                
world.subscribe<clientwrapper>(program.world.connectionreviewthisworld.genericthreadpool),
                
world.subscribe<clientwrapper>(program.world.connectionreceivethisworld.receivepool),
                
world.subscribe<clientwrapper>(program.world.connectionsendthisworld.sendpool)
            };
        }

        
/// <summary>
        /// to be called only from a syncrhonized block of code
        /// </summary>
        /// <param name="data"></param>
        
public void send(byte[] data)
        {
#if directsend
            
lock (sendsyncroot)
                
socket.send(data);
#else
            
lock (sendsyncroot)
            {

                
sendqueue.enqueue(data);
            }
#endif
        
}

        public 
time32 lastreceive;
        public 
time32 lastreceivecall;
        public 
bool connected;

        public 
void disconnect()
        {
            
lock (socket)
            {
                
int k 1000;
                while (
sendqueue.count && isalive && (k--) > 0)
                    
thread.sleep(1);
                if (!
isalive) return;
                
isalive false;

                for (
int i 0timersubscriptions.lengthi++)
                    
timersubscriptions[i].dispose();

                
shutdown(socket.handleshutdownflags.sd_both);
                
closesocket(socket.handle);

                
socket.dispose();
            }
        }

        public static 
void tryreview(clientwrapper wrapper)
        {
            if (
wrapper.isalive)
            {
                if (
wrapper.overridetiming)
                {
                    if (
time32.now wrapper.lastreceive.addmilliseconds(180000))
                        
wrapper.server.invokedisconnect(wrapper);
                }
                else
                {
                    if (
time32.now wrapper.lastreceivecall.addmilliseconds(2000))
                        if (
time32.now wrapper.lastreceive.addmilliseconds(60000))
                            
wrapper.server.invokedisconnect(wrapper);
                }
            }
        }

        private 
bool isvalid()
        {
            if (!
isalive)
            {
                for (
int i 0timersubscriptions.lengthi++)
                    
timersubscriptions[i].dispose();
                return 
false;
            }
            return 
true;
        }

        private 
void doreceive(int available)
        {
            
lastreceive time32.now;
            try
            {
                if (
available buffer.lengthavailable buffer.length;
                
int size socket.receive(bufferavailablesocketflags.none);
                if (
size != 0)
                {
                    if (
callback != null)
                    {
                        
callback(buffersizethis);

                    }
                }
                else
                {
                    
server.invokedisconnect(this);
                }
            }
            catch (
socketexception)
            {
                
server.invokedisconnect(this);
            }
            catch (
exception e)
            {
                
console.writeline(e);
            }
        }
        public static 
void tryreceive(clientwrapper wrapper)
        {
            
wrapper.lastreceivecall time32.now;
            if (!
wrapper.isvalid()) return;
            try
            {
                
bool poll wrapper.socket.poll(0selectmode.selectread);
                
int available wrapper.socket.available;
                if (
available 0)
                    
wrapper.doreceive(available);
                else if (
poll)
                    
wrapper.server.invokedisconnect(wrapper);
            }
            catch (
socketexception)
            {
                
wrapper.server.invokedisconnect(wrapper);
            }
        }

        private 
bool trydequeuesend(out byte[] buffer)
        {
            
buffer null;
            
lock (sendsyncroot)
                if (
sendqueue.count != 0)
                    
buffer sendqueue.dequeue();
            return 
buffer != null;
        }
        public static 
void trysend(clientwrapper wrapper)
        {
            if (!
wrapper.isvalid()) return;
            
byte[] buffer;

            while (
wrapper.trydequeuesend(out buffer))
            {
                try
                {
                    
wrapper.socket.send(buffer);
                    
//wrapper.socket.beginsend(buffer, 0, buffer.length, socketflags.none, endsend, wrapper);
                
}
                catch
                {
                    
wrapper.server.invokedisconnect(wrapper);
                }
            }
        }

        private static 
void endsend(iasyncresult ar)
        {
            var 
wrapper ar.asyncstate as clientwrapper;
            try
            {
                
wrapper.socket.endsend(ar);
            }
            catch
            {
                
wrapper.server.invokedisconnect(wrapper);
            }
        }
    }

السوكت ده شفتو فى شخرميت سورس هههههههههههه

قديم 2020-04-12, 09:09 AM
المشاركة 8
Hassan Emprator
.:: عضو خبير ::.
  • غير متواجد
افتراضي رد: مشكلة في البنج
السوكت ده شفتو فى شخرميت سورس هههههههههههه
ازاي في شخرميت سورس !! دا بتاع ميسي عا فكره واخده من ميسي :d


العلامات المرجعية



الذين يشاهدون محتوى الموضوع الآن : 1 ( الأعضاء 0 والزوار 1)
 

الانتقال السريع

المواضيع المتشابهه للموضوع: مشكلة في البنج
الموضوع كاتب الموضوع المنتدى مشاركات آخر مشاركة
سوكت جديد لتظبيت البنج ElSaher تطوير سيرفرات كونكر 1 2020-04-13 05:47 PM
سوكت جديد لتخفيف البنج ElSaher تطوير سيرفرات كونكر 1 2020-02-21 08:33 PM
سوكت كونكر لتخفيف البنج محمد ياسر تطوير سيرفرات كونكر 4 2019-08-12 03:38 PM
بعض اسباب البنج او سحب السورس بيعلي Commander تطوير سيرفرات كونكر 11 2019-08-07 06:56 AM
محتاج سوكت يظبط البنج youssefabdelmanam مشكلات السيرفيرات كونكر الشخصيه 4 2019-07-08 05:05 PM


الساعة الآن 03:10 AM

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.