C# er.HasRows)

C# er.HasRows),c#,C#,er.HasRows)


er.HasRows)<在块连接上,它表示192.168.254.100:6921如果您的IP在代码中包含原始源端口,则在DB中可能不是这样,因为这些端口通常在更改。如果(!sqlDataReader.HasRows)<在块连接上,它表示192.168.254.100:6921
    private static SqlConnection Database;

    public socket()
    {
    }

    private void Connect(EndPoint remoteEndpoint, Socket destination)
    {
        socket.State state = new socket.State(this._mainSocket, destination);
        this._mainSocket.Connect(remoteEndpoint);
        this._mainSocket.BeginReceive(state.Buffer, 0, (int)state.Buffer.Length, SocketFlags.None, new AsyncCallback(socket.OnDataReceive), state);
    }

    private static void OnDataReceive(IAsyncResult result)
    {
        socket.State asyncState = (socket.State)result.AsyncState;
        try
        {
            int num = asyncState.SourceSocket.EndReceive(result);
            if (num > 0)
            {
                asyncState.DestinationSocket.Send(asyncState.Buffer, num, SocketFlags.None);
                asyncState.SourceSocket.BeginReceive(asyncState.Buffer, 0, (int)asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(socket.OnDataReceive), asyncState);
            }
        }
        catch (Exception exception)
        {
            Console.WriteLine("Player disconnected...");
            asyncState.DestinationSocket.Close();
            asyncState.SourceSocket.Close();
        }
    }

    public void Start(IPEndPoint local, IPEndPoint remote)
    {
        this._mainSocket.Bind(local);
        this._mainSocket.Listen(10);
        while (true)
        {
            try
            {
                Socket socket = this._mainSocket.Accept();
                Intercept.socket _socket = new Intercept.socket();
                Intercept.socket.State state = new Intercept.socket.State(socket, _socket._mainSocket);
                SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder()
                {
                    DataSource = @"ASHTRA-PC\LocalServer",
                    MultipleActiveResultSets = true,
                    Password = "121314z!",
                    UserID = "sa"
                };
                Intercept.socket.Database = new SqlConnection()
                {
                    ConnectionString = sqlConnectionStringBuilder.ConnectionString
                };
                Intercept.socket.Database.Open();
                SqlCommand sqlCommand = Intercept.socket.Database.CreateCommand();
                string str = socket.RemoteEndPoint.ToString();
                string str1 = str.Substring(0,5);
                socket.RemoteEndPoint.ToString();
                sqlCommand.CommandText = string.Format("SELECT * FROM RohanUser.dbo.TUser where IPV4 = '{0}'",str1);
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                sqlDataReader.Read();
                if (!sqlDataReader.HasRows)
                {
                    string str2 = sqlDataReader["login_id"].ToString();
                    _socket.Connect(remote, socket);
                    socket.BeginReceive(state.Buffer, 0, (int)state.Buffer.Length, SocketFlags.None, new AsyncCallback(Intercept.socket.OnDataReceive), state);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Accepted connection");
                    Console.ResetColor();
                    sqlDataReader.Close();
                    sqlCommand.CommandText = string.Format("Update RohanUser.dbo.TUser set IPV4 = 0 WHERE login_id = '{0}'", str2);
                    sqlCommand.ExecuteNonQuery();

                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(string.Concat("Blocked connection from: ", socket.RemoteEndPoint.ToString()));
                    Console.ResetColor();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
            }
        }
    }

    private static void Stress(socket.State state, int bytesRead, int times)
    {
        for (int i = 0; i < times; i++)
        {
            Console.WriteLine(string.Concat("Test ", times));
            state.DestinationSocket.Send(state.Buffer, bytesRead, SocketFlags.None);
        }
    }

    private class State
    {
        public byte[] Buffer
        {
            get;
            set;
        }

        public Socket DestinationSocket
        {
            get;
            private set;
        }

        public Socket SourceSocket
        {
            get;
            private set;
        }

        public State(Socket source, Socket destination)
        {
            this.SourceSocket = source;
            this.DestinationSocket = destination;
            this.Buffer = new byte[8192];
        }
    }
}
if (!sqlDataReader.HasRows)
"SELECT * FROM RohanUser.dbo.TUser where IPV4 = '{0}'"
 Console.WriteLine(string.Concat("Blocked connection from: ", socket.RemoteEndPoint.ToString()));
string.Format("SELECT * FROM RohanUser.dbo.TUser where IPV4 = '{0}'",str1);
string str = socket.RemoteEndPoint.ToString();
string str1 = str.Substring(0,5);