Example #1
0
        public bool SendLoginInfomation()
        {
            byte[] nameBuffer = new byte[SIZE_OF_BYTE];
            byte[] imgBuffer  = new byte[IMAGE_BYTE_SIZE];
            nameBuffer = Encoding.UTF8.GetBytes($"[username]{username}[password]{password}[end]");

            NetworkStream stream = player.GetStream();

            stream.Write(nameBuffer, 0, nameBuffer.Length);
            byte[] buffer = new byte[SIZE_OF_BYTE];
            stream.Read(buffer, 0, buffer.Length);
            string loginMessage = Encoding.UTF8.GetString(buffer);

            LoginMessageReceivedEventArgs args = new LoginMessageReceivedEventArgs();

            if (loginMessage.Substring(0, loginMessage.IndexOf("[end]")).Equals("valid"))
            {
                args.IsValidLogin = true;
            }
            else
            {
                args.IsValidLogin = false;
            }
            OnLoginMessageReceived(args);
            return(args.IsValidLogin);
        }
Example #2
0
        protected virtual void OnLoginMessageReceived(LoginMessageReceivedEventArgs e)
        {
            EventHandler <LoginMessageReceivedEventArgs> handler = LoginMessageReceived;

            if (handler != null)
            {
                handler(this, e);
            }
        }