C# Get Username and password from the Client using sockets ?

04/15/2014 19:44 abdeen#1
Hello , i have a server a client , client have two text box's for Username and password and when i press Login button in the client it shall connect to the server login socket , and the server login socket will check the packet number , if its the specified one for login for example ( 1051) so it will get the username and password value to check if they are same in the database or not , so i can`t do this til now , any help ?

i have an online game code for the server but i don't know the client side how is it ..

here is the code for login at Server

Code:
#region AuthServer_AnnounceReceive
    static void AuthServer_AnnounceReceive(byte[] arg1, Interfaces.ISocketWrapper arg2)
    {

        if (arg1.Length == 240)
        {
            Client.AuthState player = arg2.Connector as Client.AuthState;
            player.Cryptographer.Decrypt(arg1);
            //player.Info = new Authentication();
            //player.Info.Deserialize(arg1);
            byte[] usernamearray = new byte[16];
            Buffer.BlockCopy(arg1, 8, usernamearray, 0, 16);
            var username = Encoding.Default.GetString(usernamearray).Replace("\0", "");

            player.Account = new TQ_Server.Game_Database.cq_account.Table(username);

            byte[] passwordarray = new byte[16];
            Buffer.BlockCopy(arg1, 72, passwordarray, 0, 16);
            var password = (Encoding.Default.GetString(passwordarray).Replace("\0", "")).Split('\0')[0];                

        }
        else
        {

            arg2.Socket.Disconnect(false);
        }
    }
    #endregion:rolleyes:
04/16/2014 14:46 abdoumatrix#2
check this better
[Only registered and activated users can see links. Click Here To Register...]
SuperAids 's chat project

why u use Cryptographer.Decrypt?

u just need to getbytes from the selected offset then get string then search for the string in the database
04/16/2014 15:02 Aceking#3
What patch?
That is the most important thing.

The amount of crypto changes and password seeds and all that wonderful stuff that has changed over the years.

Is it even Conquer or a different TQ game??

I haven't worked with higher patch servers, but 240 for the length of the authorization packet seems high to me. But in higher patches maybe thats what it is
04/16/2014 15:31 abdoumatrix#4
Quote:
Originally Posted by Aceking View Post
What patch?
That is the most important thing.

The amount of crypto changes and password seeds and all that wonderful stuff that has changed over the years.

Is it even Conquer or a different TQ game??

I haven't worked with higher patch servers, but 240 for the length of the authorization packet seems high to me. But in higher patches maybe thats what it is
now 312 Lenght :D
04/16/2014 16:29 abdeen#5
Quote:
Originally Posted by abdoumatrix View Post
check this better
[Only registered and activated users can see links. Click Here To Register...]
SuperAids 's chat project

why u use Cryptographer.Decrypt?

u just need to getbytes from the selected offset then get string then search for the string in the database
i will check this source but i am not using Cryptographer.Decrypt, i just posted a sample from conquer ...
Quote:
Originally Posted by Aceking View Post
What patch?
That is the most important thing.

The amount of crypto changes and password seeds and all that wonderful stuff that has changed over the years.

Is it even Conquer or a different TQ game??

I haven't worked with higher patch servers, but 240 for the length of the authorization packet seems high to me. But in higher patches maybe thats what it is
Quote:
Originally Posted by abdoumatrix View Post
now 312 Lenght :D
i am talking about sockets not about CONQUER sockets :)

EDIT :

another question , how i can serialize and send an packet struct , something like this :

PHP Code:
        struct LoginForm
        
{
            public 
string Username;
            public 
string Password;
        } 
04/16/2014 19:18 Aceking#6
Once you hit enter on the login screen, the client then opens a connection to the authentication server.
Once this connection has been accepted and receive has been called in the socket, then the authentication server receives packet 1051.
Using this packet, you get the username and password depending on the crypto method for that patch.
04/16/2014 20:35 abdoumatrix#7
I got Lost :D

u wanna make a program when u log in using a specific username and pass
and the server search for this username and send the info back.
if so

u need to send for example
username string with max. lenght = 16 at offset 4 for expample.
and pass string with max. lenght = 16 at offset 4+16
from client

and the server get it pack and send the info back into another packet
04/16/2014 22:41 abdeen#8
Quote:
Originally Posted by Aceking View Post
Once you hit enter on the login screen, the client then opens a connection to the authentication server.
Once this connection has been accepted and receive has been called in the socket, then the authentication server receives packet 1051.
Using this packet, you get the username and password depending on the crypto method for that patch.
Great , but you are talking about Conquer , its Dot net Chat System ...
04/16/2014 22:46 abdoumatrix#9
Quote:
Originally Posted by abdeen View Post
Great , but you are talking about Conquer , its Dot net Chat System ...
all the same , all using socket , all using packets.

PS: i'm talk about a client program request info by username and pass with packets
04/16/2014 22:57 abdeen#10
Quote:
Originally Posted by abdoumatrix View Post
I got Lost :D

u wanna make a program when u log in using a specific username and pass
and the server search for this username and send the info back.
if so

u need to send for example
username string with max. lenght = 16 at offset 4 for expample.
and pass string with max. lenght = 16 at offset 4+16
from client

and the server get it pack and send the info back into another packet
could you tell me what about this ?

client Side :

Code:
public class Packet
    {
        [Serializable]
        public class LoginPacket
        {
            private short Packet;
            private int MaxLength;
            private string Username;
            private string Password;
            public LoginPacket(string _Username, string _Password)
            {
                Packet = 1001;
                this.MaxLength = 16;
                this.Username = _Username;
                this.Password = _Password;
            }
        }

        public static byte[] GetPacketBytes(LoginPacket packetHdr)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(ms, packetHdr);
            return ms.ToArray();
        }
}
Code:
private void LOGIN_BUTTON_Click(object sender, EventArgs e)
        {
        Network.Packets.Packet.LoginPacket LOGIN = new Network.Packets.Packet.LoginPacket(USERNAME_BOX.Text, PASSWORD_BOX.Text);
        byte[] Packet = Network.Packets.PacketS.GetPacketBytes(LOGIN);
        Send(Packet);
        }
Code:
private void LOGIN_BUTTON_Click(object sender, EventArgs e)
        {

        private void Send(Byte[] Buffer)
        {
            if (Buffer != null)
            {
                ChatSocket.Connection.Send(Buffer);
            }
        }
Server Side :

Code:
public void AuthReceive(YukiSocketClient Sender, byte[] packet)
        {
            Network.Packets.Packet.LoginPacket BB = Network.Packets.Packet.GetPacketObject(packet);
        }
Code:
public class Packet
    {
        [Serializable]
        public class LoginPacket
        {
            private short Packet;
            private int MaxLength;
            private string Username;
            private string Password;
        }


        public static LoginPacket GetPacketObject(byte[] packetBytes)
        {
            MemoryStream ms = new MemoryStream();
            ms.Write(packetBytes, 0, packetBytes.Length);
            ms.Position = 0;
            BinaryFormatter formatter = new BinaryFormatter();
            return formatter.Deserialize(ms) as LoginPacket;
        }
}
04/17/2014 00:10 abdoumatrix#11
I'm not fimiliar with ur code
but i think 16 packet lenght? for whole packet that is too short
2 + 2 + 16 +16 = 36 is min. lenght that could fit.

i would prefer using this for write
PHP Code:
 public static void WriteString(string argint offsetbyte[] buffer)
        {
            if (
buffer == null)
                return;
            if (
offset buffer.Length 1)
                return;
            
byte[] argEncoded Program.Encoding.GetBytes(arg);
            if (
buffer.Length >= offset arg.Length)
                Array.
Copy(argEncoded0bufferoffsetarg.Length);
        } 
and this for reading

PHP Code:
 public static void ReadString(out string valueint offsetbyte[] buffer)
        {
            
value Program.Encoding.GetString(buffer, (offset 1), buffer[offset]);
        } 
04/17/2014 03:33 abdeen#12
Quote:
Originally Posted by abdoumatrix View Post
I'm not fimiliar with ur code
but i think 16 packet lenght? for whole packet that is too short
2 + 2 + 16 +16 = 36 is min. lenght that could fit.

i would prefer using this for write
PHP Code:
 public static void WriteString(string argint offsetbyte[] buffer)
        {
            if (
buffer == null)
                return;
            if (
offset buffer.Length 1)
                return;
            
byte[] argEncoded Program.Encoding.GetBytes(arg);
            if (
buffer.Length >= offset arg.Length)
                Array.
Copy(argEncoded0bufferoffsetarg.Length);
        } 
and this for reading

PHP Code:
 public static void ReadString(out string valueint offsetbyte[] buffer)
        {
            
value Program.Encoding.GetString(buffer, (offset 1), buffer[offset]);
        } 

Thanks Button was pressed ... can i get a sample ?
04/17/2014 12:24 abdoumatrix#13
first:

Secend:

04/17/2014 16:38 abdeen#14
Quote:
Originally Posted by abdoumatrix View Post
first:

Secend:


thanks brother , its was helpful code , i changed it to be like this :

Server Side :

Client Side


all works fine , but now i want to make or change this socket library to make it for client i mean connect and receive incoming bytes , i tried many times but fails ...

here is Server socket [ its related to Conquer 5517+ Server files ] and i wanna make edits to make it Client socket which connect to server ,receive and send bytes .


Socket Files .

04/17/2014 17:16 abdoumatrix#15
check this better
[Only registered and activated users can see links. Click Here To Register...]
SuperAids 's chat project