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); } }
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 !"); } } }
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); } }
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); } }