Client Handshake Problem

05/14/2010 23:05 kinshi88#1
I'm having a problem with the Client Handshake and the ClientKeyPacket.

Login is fine, when I recieve the game connection I send the ServerKeyPacket:
Code:
            byte[] Junk1 = new byte[11];
            byte[] Junk2 = new byte[5];
            Xio.Random.NextBytes(Junk1);
            Xio.Random.NextBytes(Junk2);
            COPacket P = new COPacket(68 + p.Length + g.Length + pub_key.Length);
            P.WriteBytes(Junk1);
            P.WriteUInt32(Convert.ToUInt32(P.Length - 11)); 
            P.WriteUInt32(5); 
            P.WriteBytes(Junk2); 
            P.WriteUInt32(Convert.ToUInt32(ClientIV.Length));
            P.WriteBytes(ClientIV);
            P.WriteUInt32(Convert.ToUInt32(ServerIV.Length));
            P.WriteBytes(ServerIV);
            P.WriteUInt32(Convert.ToUInt32(p.Length));
            P.WriteString(p);
            P.WriteUInt32(Convert.ToUInt32(g.Length));
            P.WriteString(g);
            P.WriteUInt32(Convert.ToUInt32(pub_key.Length));
            P.WriteString(pub_key);
            P.WriteString("TQServer");
            return P.Packet;
I'm supposed to get the ClientKeyPacket back from the client right?
Cause after I sent that I just get a blank packet and the client disconnects >.<

I'm using a 5095 client to test since it's the only one I have.

Any ideas?

EDIT:
Before it says Client Handshake Reply should be the dump of the received packet, but it's blank so it dumps nothing.
The error is caused because the packet is blank..
[Only registered and activated users can see links. Click Here To Register...]
05/15/2010 02:09 Korvacs#2
If it helps this is how i used to do it:

Code:
        public static OutgoingPacket HandShakePacket(cnt Conn, string g, string p, string pub_key)
        {
            int Size = 47 + p.Length + g.Length + pub_key.Length + 12 + 8 + 8;
            Async_GameServer.MainBuff.Buff = new byte[Size];
            fixed (byte* lpBuffer = Async_GameServer.MainBuff.Buff)
            {
                *((uint*)(lpBuffer + 0)) = 3932315834;
                *((uint*)(lpBuffer + 4)) = 2592193404;
                *((byte*)(lpBuffer + 8)) = 69;
                *((ushort*)(lpBuffer + 9)) = 35628;
                *((uint*)(lpBuffer + 11)) = (uint)(Size - 11);
                *((uint*)(lpBuffer + 15)) = 10;
                *((uint*)(lpBuffer + 19)) = 4143858738;
                *((uint*)(lpBuffer + 23)) = 3801427934;
                *((ushort*)(lpBuffer + 27)) = 41236;
                *((uint*)(lpBuffer + 29)) = 8; // client_bf_data.length
                *((uint*)(lpBuffer + 41)) = 8; // server_bf_data.length

                *((int*)(lpBuffer + 53)) = p.Length;
                ushort Offset = 57;
                for (int i = 0; i < p.Length; i++)
                {
                    *((byte*)(lpBuffer + Offset)) = (byte)p[i];
                    Offset++;
                }
                *((int*)(lpBuffer + Offset)) = g.Length;
                Offset += 4;
                for (int i = 0; i < g.Length; i++)
                {
                    *((byte*)(lpBuffer + Offset)) = (byte)g[i];
                    Offset++;
                }
                *((int*)(lpBuffer + Offset)) = pub_key.Length;
                Offset += 4;
                for (int i = 0; i < pub_key.Length; i++)
                {
                    *((byte*)(lpBuffer + Offset)) = (byte)pub_key[i];
                    Offset++;
                }
                Offset += 2;
                string amend = "TQServer";
                for (int i = 0; i < amend.Length; i++)
                {
                    *((byte*)(lpBuffer + Offset)) = (byte)amend[i];
                    Offset++;
                }
            }
            OutgoingPacket OGP = new OutgoingPacket(Conn, Async_GameServer.MainBuff.Buff);
            Async_GameServer.MainBuff.ClearBuffer();
            return OGP;
        }
Ive noticed that between pub_key and TQServer theres a 2 byte filler on mine, although mines not exactly a correct structure lol.

The 5165 server source doesnt have that 2 byte filler on it however.

The next packet you receive does not have a fixed type or length, so you need to watch out for that.
05/15/2010 03:07 kinshi88#3
Alright, so I pretty much copy/pasted yours and it worked =P
My class for building packets must be fucked or something...
I shall fix that now!
Thank you very much!
05/15/2010 18:45 Unidentified#4
Quote:
Originally Posted by kinshi88 View Post
Alright, so I pretty much copy/pasted yours and it worked =P
My class for building packets must be fucked or something...
I shall fix that now!
Thank you very much!
Don't tell me you couldn't figure out by reading a .NET exception? What happened to this forum :facepalm:
05/15/2010 19:15 Korvacs#5
Quote:
Originally Posted by Unidentified View Post
Don't tell me you couldn't figure out by reading a .NET exception? What happened to this forum :facepalm:
...You didnt reallly read what he said did you?

The reason for the exception was because the client was replying to his handshake packet with a blank packet, and his problem was that his handshake packet was not being correctly made and the client was not responding correctly.

So the problem was not the exception, the exception is a result of the problem. The exception had nothing to do with the problem in this case.

:facepalm:
05/15/2010 19:20 Unidentified#6
Quote:
Originally Posted by Korvacs View Post
...You didnt reallly read what he said did you?

The reason for the exception was because the client was replying to his handshake packet with a blank packet, and his problem was that his handshake packet was not being correctly made and the client was not responding correctly.

So the problem was not the exception, the exception is a result of the problem. The exception had nothing to do with the problem in this case.

:facepalm:
I guess .NET offers the oppurtinity to use breakpointing, both ways he should of debugged the problem before posting. And there is no argueing in that.
05/15/2010 22:57 kinshi88#7
Ugh, yes I knew exactly what the problem was, as I said in my post.
But I wasn't sure if it was the ServerKeyPacket's structure or my Packet builder.
So plz, gtfo =D
05/15/2010 23:34 Unidentified#8
Quote:
Originally Posted by kinshi88 View Post
Ugh, yes I knew exactly what the problem was, as I said in my post.
But I wasn't sure if it was the ServerKeyPacket's structure or my Packet builder.
So plz, gtfo =D
Again, you could debug it yourself hardly dumping the packet eh?
05/15/2010 23:42 ImmuneOne#9
Quote:
Originally Posted by Unidentified View Post
Again, you could debug it yourself hardly dumping the packet eh?
Drop the attidude.

Quote:
Originally Posted by kinshi88 View Post
Ugh, yes I knew exactly what the problem was, as I said in my post.
But I wasn't sure if it was the ServerKeyPacket's structure or my Packet builder.
So plz, gtfo =D
Watch your words.

Now both rest your case, no matter who-ever 'started' violating the rules can result to an infraction.
05/16/2010 11:35 Korvacs#10
Quote:
Originally Posted by Unidentified View Post
Again, you could debug it yourself hardly dumping the packet eh?
Its impossible to debug an issue with a packet structure, either you get it right or you get it wrong.

Your new here, i suggest that you if you want to have a go at people who have contributed here, that you gain some respect first, otherwise your not going to get anyway.

Closed.