Ejemplo n.º 1
0
        private static void Server_OnRequestReceived(TcpClient client, byte[] buffer)
        {
            PacketReader reader = new PacketReader(buffer);
            byte ID = reader.ReadByte();

            if (ID == 1) //Login request
            {
                Log("Connection request received :");
                string username = reader.ReadString();
                string password = reader.ReadString();
                byte[] result = dbmanager.LoginRequest(username, password);
                server.SendTo(result, client);
            }
        }
Ejemplo n.º 2
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 !");
                }

            }
        }
Ejemplo n.º 3
0
        private void Client_OnDataReceived(byte[] buffer)
        {
            PacketReader pr = new PacketReader(buffer);
            Byte ID = pr.ReadByte();

            if(ID == 1)
            {
                int id = pr.ReadInt32();
                string message = pr.ReadString();
                string msg = id + " : " + message;
                listBox_messages.Items.Add(msg);
            }
        }
Ejemplo n.º 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);
            }
        }