Using CO socket for another job ...

08/18/2013 19:59 abdeen#1
Hello Epvp members ...

i am using co socket with all socket files which in source to make a server/client apps for for any job like chatting or file transfer .. etc .

now i can connect to server through client .. and i can send byte`s .. but i wanna make the client just like a conquer client ... i mean i want it working with packets not bytes ... i know the packets is a something like decrypted bytes but i wanna explain it like this :

Conquer online Login packet

Code:
#region LoginPacket (1052)
                case 1052:
                    {
                        if (client.Action == 1)
                        {
                            Connect connect = new Connect();
                            connect.Deserialize(packet);
                            AppendConnect(connect, client);
                        }
                        else
                            client.Disconnect();
                        Console.WriteLine("Disconnect 5");
                        break;
                    }
                #endregion
i can send bytes like this ..

Code:
 byte[] data = new byte[276];
            Begin_Send(data);

and here is begin send void

Code:
        void Begin_Send(byte[] Message)
        {
            try
            {
                ClientSocket.Send(Message);
            }
            catch (Exception g) { Update_Screen(g.Message); }
        }
Code:
ClientSocket = new WinSocket();
i am using full co socket in server side ... and just used WinSocket.cs file from conquer socket files in my Client ...

but i wanna it handle or contains User id and password if my app needs to login or something like conquer ....

any suggest idea ?

sorry for my bad English ... long time not using it ..
08/19/2013 09:56 go for it#2
im not sure if you entirely understand the concept of packets, so ill explain it briefly
a packet is a byte[] with a constant structure for the first 4 bytes and last 8 bytes (talking about conquer packets)
first ushort is length, second ushort is type, and last string is the sealing

if you are trying to send a packet as a structure it should end up sending a byte[] (atleast that's what it did on c++ last time i tried)

let me explain what it really does at the example you gave us
lets just stick with the fact that packet is a byte[] with structure for every type

it first switch on the type of the packet with something like

Code:
switch (BitConverter.ToUInt16(Packet, 2))
{
case 1052:
                   {

                   }
}
and then it creates a new instance of the class Connect which it then calls a function inside calls "Deserialize" which mainly assign the byte[]/packet you pass as parameter to another byte[]/packet inside this class
which let the other properties read and write to it

i don't currently have any of trinity bases to get code snippet but it's basically something like

Code:
public class Connect 
{
public byte[] packet
//ctor
        public uint Identifier
        {
            get { return ReadUInt32(4); }
            set { WriteUInt32(value, 4); }
        }
        public Deserialize (byte[] _packet)
        {
            packet = _packet
        }
//dtor
}
back to what you really want
conquer login sequence is a bit complicated if you don't really understand the crypto behind it, but lets put the crypto away
all you need is to auth the player which requires on packet sending the username and password
then you can either follow tq logic of having 2 instances with 2 connections, one of each for login/auth and the other for the game, where you are not allowed to login to the game server without first passing the login/auth server
or you may use a simpler logic of having just one connection with one instance with a bool property indicating the verification status, that being set by matching the account and password from the database to true and to false whenever it doesn't or the account disconnect
which will decide later to forward packets and analyise it from this connection or just drop the connection

so all in all, packet is a byte[] and i've mentioned above how it works
08/25/2013 14:21 Danial Eugen#3
You may also take a look at my simple socket tutorial :D

[Only registered and activated users can see links. Click Here To Register...]