Exemplo n.º 1
0
 private void mClientDestroy()
 {
     if (!FuzzyServer.getInstance().DestroyThread.IsAlive)
     {
         FuzzyServer.getInstance().DestroyThread.IsBackground = true;
         FuzzyServer.getInstance().DestroyThread.Start();
     }
 }
Exemplo n.º 2
0
        private Client CreateAndGet_Client(Socket Sck)
        {
            int    CurrentClientId = FuzzyServer.getInstance().getID();
            Client CurrentClient   = new Client();

            CurrentClient.ID                 = CurrentClientId;
            CurrentClient.SOCKET             = Sck;
            CurrentClient.CLOSEDSTATE        = Client.ClosedStates.NULL;
            CurrentClient.LASTCONNECTIONTIME = DateTime.Now.ToString();
            CurrentClient.PROCESS            = 0;
            return(CurrentClient);
        }
Exemplo n.º 3
0
        public override Client Invoke()
        {
            // Permission Control
            Accept_PermissionControl();
            // Wait clients reconnecting.
            // And destroy.
            mClientDestroy();
            //Get Accepted Client
            Socket mSocket = GetClientWithState();

            #region Ip Permission Control
            Console.WriteLine(mSocket.RemoteEndPoint.ToString());
            string   REMOTEIP = mSocket.RemoteEndPoint.ToString();
            string[] exp      = REMOTEIP.Split(':');
            Permissions.IpPermission Permission = new Permissions.IpPermission();
            Permission.FilePath = FuzzyServer.getInstance().m_initializeType.Paths.IpPermissions;
            Permission.TargetIP = exp[0].ToString();
            if (!Permission.PermissionControl())
            {
                mSocket.Send(Encoding.UTF8.GetBytes("You have banned This Server!"));
                mSocket.Close();
                throw new Exception(exp[0].ToString() + " Banned This Server!");
            }
            #endregion
            //Detect forcibly closed client
            DetectReconnection(mSocket);
            //Create Client Datas
            Client mClient = CreateAndGet_Client(mSocket);
            //Send accepting data for user method.
            Thread AcceptTaskTh = new Thread(new ThreadStart(() => {
                FuzzyServer.getInstance().AcceptTask(mClient);
            }));
            if (FuzzyServer.getInstance().AcceptTask != null)
            {
                AcceptTaskTh.Start();
            }
            AddSocketList_Client(mClient);

            return(mClient);
        }
Exemplo n.º 4
0
 private Socket GetClientWithState()
 {
     return(FuzzyServer.getInstance().ServerSocket.EndAccept(Result));
 }