Example #1
0
        private void button_connect_Click(object sender, EventArgs e)
        {
            if (textBox_username.Text.Trim() != "" && textBox_password.Text.Trim() != "")
            {
                PacketWriter pw = new PacketWriter();
                pw.WriteByte(1);
                pw.WriteString(textBox_username.Text.Trim());
                pw.WriteString(textBox_password.Text.Trim());

                byte[] response = client.SendRequest(pw.ToArray());

                PacketReader pr = new PacketReader(response);
                byte r = pr.ReadByte();

                if(r == 0)
                {
                    MessageBox.Show("Connection successful !");
                }
                else if(r == 2)
                {
                    MessageBox.Show("Banned : " + pr.ReadString());
                }
                else
                {
                    MessageBox.Show("Wrong password or username !");
                }

            }
        }
Example #2
0
 private void textBox_message_KeyDown(object sender, KeyEventArgs e)
 {
     if(e.KeyCode == Keys.Enter)
     {
         PacketWriter pw = new PacketWriter();
         pw.WriteByte(1);
         pw.WriteString(textBox_message.Text);
         textBox_message.Clear();
         client.Send(pw.ToArray());
     }
 }
Example #3
0
        public byte[] LoginRequest(string username, string password)
        {
            connection.Open();

            byte[] response = null;

            SQLiteCommand command = new SQLiteCommand("select * from accounts where username='******'", connection);
            SQLiteDataReader sqlreader = command.ExecuteReader();
            if (sqlreader.Read())
            {
                if (SHA256Encrypt(password) == sqlreader["password"].ToString())
                {

                    if (!(bool)sqlreader["banned"])
                    {
                        Program.Log("Connection request accepted !");
                        response = new byte[1];
                        using (PacketWriter pw = new PacketWriter())
                        {
                            pw.WriteByte(0);
                            response = pw.ToArray();
                        }
                    }
                    else
                    {
                        Program.Log("Connection request failed : banned user !");
                        using (PacketWriter pw = new PacketWriter())
                        {
                            pw.WriteByte(2);
                            pw.WriteString(sqlreader["bannedr"].ToString());
                            response = pw.ToArray();
                        }
                    }
                }
            }

            if (response == null)
            {
                Program.Log("Connection request failed : bad username or password !");
                using (PacketWriter pw = new PacketWriter())
                {
                    pw.WriteByte(1);
                    response = pw.ToArray();
                }
            }

            connection.Close();

            return response;
        }
Example #4
0
        static void server_OnDataReceived(eSClient client, byte[] buffer)
        {
            PacketReader pr = new PacketReader(buffer);
            Byte ID = pr.ReadByte();

            if(ID == 1)
            {
                string message = pr.ReadString();
                PacketWriter pw = new PacketWriter();
                pw.WriteByte(ID);
                pw.WriteInt32(server.GetIDFromTcpClient(client.GetTcpClient()));
                pw.WriteString(message);
                server.SendToAll(pw.ToArray());

                Console.WriteLine("Message received from " + client.GetID() + " : " + message);
            }
        }