اسم العضو كلمة المرور حفظ البيانات؟ تسجيل عضوية



ايجى4يو || Egy4u


  ايجى4يو || Egy4u > أقسام كونكر برفيت > تطوير سيرفرات كـــونـــكر تـــهيس

اعلانات ايجى4يو


المشاركات: 27 [+]
: [+]
:
: [+]
محمد مصطفي غير متواجد حالياً
محمد مصطفي
( مراقب اقسام كونكر برفيت )
سوكت حلو للناس الي بتعاني من مشكلة البنج !

السلام عليكم ورحمة الله
==============


بقدملكوا انهاردا سوكت جميل جدآ ويشيل ويظبط البنج بأذن الله

هتدخل ع المسار دا في السورس ,

Html

Network\Sockets 
بدل دول بالي في ملف ClientWrapper.cs ,

Html

namespace Phoenix_Project.Network.Sockets 

    
using System
    
using System.Collections.Generic
    
using System.Net.Sockets
    
using System.Runtime.InteropServices
    
using System.Threading
    
using Phoenix_Project

    public class 
ClientWrapper 
    

        public 
bool Alive
        public 
byte[] Buffer
        public 
int BufferSize
        public 
Action<byte[], intClientWrapperCallback
        public 
object Connector
        public 
string IP
        public 
Time32 LastReceive
        public 
Time32 LastReceiveCall
        public 
string LocalIp
        public 
string MAC
        public 
bool OverrideTiming
        private 
Queue<byte[]> SendQueue
        private 
object SendSyncRoot
        public 
ServerSocket Server
        public 
System.Net.Sockets.Socket Socket
        private 
IDisposable[] TimerSubscriptions

        [
DllImport("ws2_32.dll"CharSet CharSet.UnicodeSetLastError true)] 
        public static 
extern int closesocket(IntPtr s); 
        public 
void Create(System.Net.Sockets.Socket socketServerSocket serverAction<byte[], intClientWrappercallBack
        { 
            
this.Callback callBack
            
this.BufferSize 0x7ff
            
this.Socket socket
            
this.Server server
            
this.Buffer = new byte[this.BufferSize]; 
            
this.LastReceive Time32.Now
            
this.OverrideTiming false
            
this.SendQueue = new Queue<byte[]>(); 
            
this.SendSyncRoot = new object(); 
            
this.TimerSubscriptions = new IDisposable[] { World.Subscribe<ClientWrapper>(Program.World.ConnectionReviewthisWorld.GenericThreadPool), World.Subscribe<ClientWrapper>(Program.World.ConnectionReceivethisWorld.ReceivePool), World.Subscribe<ClientWrapper>(Program.World.ConnectionSendthisWorld.SendPool) }; 
        } 

        public 
void Disconnect() 
        { 
            
lock (this.Socket
            { 
                
int num 0x3e8
                while (((
this.SendQueue.Count 0) && this.Alive) && (num-- > 0)) 
                { 
                    
Thread.Sleep(1); 
                } 
                if (
this.Alive
                { 
                    
this.Alive false
                    for (
int i 0this.TimerSubscriptions.Lengthi++) 
                    { 
                        
this.TimerSubscriptions[i].Dispose(); 
                    } 
                    
shutdown(this.Socket.HandleShutDownFlags.SD_BOTH); 
                    
closesocket(this.Socket.Handle); 
                    
this.Socket.Dispose(); 
                } 
            } 
        } 

        private 
void doReceive(int available
        { 
            
this.LastReceive Time32.Now
            try 
            { 
                if (
available this.Buffer.Length
                { 
                    
available this.Buffer.Length
                } 
                
int num this.Socket.Receive(this.BufferavailableSocketFlags.None); 
                if (
num != 0
                { 
                    if (
this.Callback != null
                    { 
                        
this.Callback(this.Buffernumthis); 
                    } 
                } 
                else 
                { 
                    
this.Server.InvokeDisconnect(this); 
                } 
            } 
            catch (
SocketException
            { 
                
this.Server.InvokeDisconnect(this); 
            } 
            catch (
Exception exception
            { 
                
Phoenix_Project.Console.WriteLine(exceptionConsoleColor.DarkYellow); 
            } 
        } 

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

        private 
bool isValid() 
        { 
            if (
this.Alive || (this.TimerSubscriptions == null)) 
            { 
                return 
true
            } 
            for (
int i 0this.TimerSubscriptions.Lengthi++) 
            { 
                
this.TimerSubscriptions[i].Dispose(); 
            } 
            return 
false
        } 

        public 
void Send(byte[] data
        { 
            
lock (this.SendSyncRoot
            { 
                
this.SendQueue.Enqueue(data); 
            } 
        } 

        [
DllImport("ws2_32.dll"CharSet CharSet.UnicodeSetLastError true)] 
        public static 
extern int shutdown(IntPtr sShutDownFlags how); 
        private 
bool TryDequeueSend(out byte[] buffer
        { 
            
buffer null
            
lock (this.SendSyncRoot
            { 
                if (
this.SendQueue.Count != 0
                { 
                    
buffer this.SendQueue.Dequeue(); 
                } 
            } 
            return (
buffer != null); 
        } 

        public static 
void TryReceive(ClientWrapper wrapper
        { 
            
wrapper.LastReceiveCall Time32.Now
            if (
wrapper.isValid()) 
            { 
                try 
                { 
                    
bool flag wrapper.Socket.Poll(0SelectMode.SelectRead); 
                    
int available wrapper.Socket.Available
                    if (
available 0
                    { 
                        
wrapper.doReceive(available); 
                    } 
                    else if (
flag
                    { 
                        
wrapper.Server.InvokeDisconnect(wrapper); 
                    } 
                } 
                catch (
SocketException
                { 
                    
wrapper.Server.InvokeDisconnect(wrapper); 
                } 
            } 
        } 

        public static 
void TryReview(ClientWrapper wrapper
        { 
            if (
wrapper.Alive
            { 
                if (
wrapper.OverrideTiming
                { 
                    if (
Time32.Now wrapper.LastReceive.AddMilliseconds(0x2bf20)) 
                    { 
                        
wrapper.Server.InvokeDisconnect(wrapper); 
                    } 
                } 
                else if ((
Time32.Now wrapper.LastReceiveCall.AddMilliseconds(0x7d0)) && (Time32.Now wrapper.LastReceive.AddMilliseconds(0xea60))) 
                { 
                    
wrapper.Server.InvokeDisconnect(wrapper); 
                } 
            } 
        } 

        public static 
void TrySend(ClientWrapper wrapper
        { 
            if (
wrapper.isValid()) 
            { 
                
byte[] buffer
                while (
wrapper.TryDequeueSend(out buffer)) 
                { 
                    try 
                    { 
                        
wrapper.Socket.Send(buffer); 
                    } 
                    catch 
                    { 
                        
wrapper.Server.InvokeDisconnect(wrapper); 
                    } 
                } 
            } 
        } 

        public 
enum ShutDownFlags 
        

            
SD_RECEIVE
            
SD_SEND
            
SD_BOTH 
        

    } 

ودول بملف ServerSocket.cs ,


Html

namespace Phoenix_Project.Network.Sockets 

    
using System
    
using System.Collections.Concurrent
    
using System.Net
    
using System.Net.Sockets
    
using System.Runtime.InteropServices
    
using System.Threading
    
using Phoenix_Project

    public class 
ServerSocket 
    

        private 
ConcurrentDictionary<intintBruteforceProtection
        private 
Socket Connection = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp); 
        private 
bool enabled
        private 
string ipString
        private 
ushort port
        public 
bool PrintoutIPs
        private 
object SyncRoot = new object(); 
        private 
Thread thread
        private const 
int TimeLimit 0x3a98

        public 
event Action<ClientWrapperOnClientConnect

        public 
event Action<ClientWrapperOnClientDisconnect

        public 
event Action<byte[], intClientWrapperOnClientReceive

        public 
ServerSocket() 
        { 
            
this.thread = new Thread(new ThreadStart(this.doSyncAccept)); 
            
this.thread.Start(); 
        } 

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

        private 
void doSyncAccept() 
        { 
            while (
true
            { 
                if (
this.enabled
                { 
                    try 
                    { 
                        
this.processSocket(this.Connection.Accept()); 
                    } 
                    catch 
                    { 
                    } 
                } 
                
Thread.Sleep(1); 
            } 
        } 

        public 
void Enable() 
        { 
            if (!
this.enabled
            { 
                
this.Connection = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp); 
                
this.Connection.Bind(new IPEndPoint(IPAddress.Anythis.port)); 
                
this.Connection.Listen(100); 
                
this.enabled true
            } 
        } 

        public 
void Enable(ushort port
        { 
            
this.port port
            
this.Connection.Bind(new IPEndPoint(IPAddress.Anythis.port)); 
            
this.Connection.Listen(100); 
            
this.enabled true
            
this.BruteforceProtection = new ConcurrentDictionary<intint>(); 
        } 

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

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

        private 
void processSocket(Socket socket
        { 
            try 
            { 
                
string str = (socket.RemoteEndPoint as IPEndPoint).Address.ToString(); 
                
string str2 = (socket.LocalEndPoint as IPEndPoint).Address.ToString(); 
                
int hashCode str.GetHashCode(); 
                if (!
Program.ALEXPC
                { 
                    
int num3
                    
int num2 Time32.Now.GetHashCode(); 
                    if (!
this.BruteforceProtection.TryGetValue(hashCodeout num3)) 
                    { 
                        
this.BruteforceProtection[hashCode] = num2
                    } 
                    else 
                    { 
                        if ((
num2 num3) < 0x3a98
                        { 
                            if (
this.PrintoutIPs
                            { 
                                
Phoenix_Project.Console.WriteLine("Dropped connection: " strConsoleColor.DarkYellow); 
                            } 
                            
socket.Disconnect(false); 
                            
socket.Close(); 
                            return; 
                        } 
                        
this.BruteforceProtection[hashCode] = num2
                        if (
this.PrintoutIPs
                        { 
                            
Phoenix_Project.Console.WriteLine("Allowed connection: " strConsoleColor.DarkYellow); 
                        } 
                    } 
                } 
                
ClientWrapper wrapper = new ClientWrapper(); 
                
wrapper.Create(socketthisthis.OnClientReceive); 
                
wrapper.Alive true
                
wrapper.IP str
                
wrapper.LocalIp str2
                if (
this.OnClientConnect != null
                { 
                    
this.OnClientConnect(wrapper); 
                } 
            } 
            catch (
Exception exception
            { 
                
Phoenix_Project.Console.WriteLine(exceptionConsoleColor.DarkYellow); 
            } 
        } 

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

        public 
void stoptheard() 
        { 
            
this.thread null
        } 

        public 
bool Enabled 
        

            
get 
            

                return 
this.enabled
            } 
        } 
    } 



 
المواضيع المتشابهه
الموضوع كاتب الموضوع المنتدى مشاركات آخر مشاركة
سوكت حلو للناس الي بتعاني من مشكلة البنج Senior.Egy4U تطوير سيرفرات كـــونـــكر تـــهيس 0 07-14-2017 10:49 PM