Hello everyone. I'm creating custom client (I mean really custom, based on YATC but in Delphi) and I have a problem with few things. At shortcut - I can't get how packets are made. I have read here:
http://tpforums.org/forum/thread-7722.html?highlight=tibia+login
How login packet looks like. But this is login to game server and I want to get characters list first. So I found this:
http://tpforums.ianobermiller.com/forum/thread-4838.html
And with YATC source I menaged to create packet class which helps me to send and parse packets.
But information provided by *DEAD* completly messed up my mind. First example:
But when I got first packet after sending login packet (this isn't encrypted because encryption is disabled on server side):Originally Posted by *DEAD*
[code=delphi]
$31 $00 $A2 $0E $35 $40 $2B $00 $14 $28 $00 $4F $6E $6C $79 $20 $63 $6C $69 $65 $6E $74 $73 $20 $77 $69 $74 $68 $20 $70 $72 $6F $74 $6F $63 $6F $6C $20 $38 $2E $35 $34 $20 $61 $6C $6C $6F $77 $65 $64 $21 $00
-- 1 -- ------ 2 ------ -- 3 -- -4- -- 5 -- ------------------------------------------------------------------------- 6 ---------------------------------------------------------------------------------------
[/code]
As I menaged to read myself:
1 - $0031 - Packet length: 49 which is good without terminating zero
2 - $40350EA2 - Adler32 checksum which I don't use at all
3 - $002B - this appears to be data length (43 in DEC) which *DEAD* don't wrote about
4 - $14 - this should be message type. But it isn't MoTD ($14 is MoTD message type)
5 - $0028 - next string's length: 40
6 - $4F...$21 - message string: Only clients with protocol 8.54 allowed!
So, do I need to add data length (only data, not the length of whole packet) to buffer before sending it? Cuz in YATC source in part when it's sending login packet.
[code=cpp]
void Connection::sendMessage(NetworkMessage& msg)
{
if(m_state != STATE_CONNECTED){
DEBUGPRINT(DEBUGPRINT_ERROR, DEBUGPRINT_LEVEL_OBLIGATORY, "Calling send when state != STATE_CONNECTED(state = %d)\n", m_state);
return;
}
if(msg.getSize() == 0){
DEBUGPRINT(DEBUGPRINT_WARNING, DEBUGPRINT_LEVEL_OBLIGATORY, "Sending size = 0 in message\n");
return;
}
//add message size
msg.addHeader();
//and encrypt if needed
if(m_cryptoEnable && m_crypto){
m_crypto->encrypt(msg);
}
//and add checksum if needed
if(m_checksumEnable){
msg.addChecksum();
}
//wait until all bytes are sent
int sendBytes = 0;
do{
socketret_t b = send(m_socket, msg.getBuffer() + sendBytes, min(msg.getSize() - sendBytes, 1000), 0);
if(b <= 0){
closeConnectionError(ERROR_SEND_FAIL);
return;
}
sendBytes += b;
} while(sendBytes < msg.getSize());
m_sentBytes += sendBytes;
}
[/code]
.addHeader adds only whole packet size before message buffer. So how can I work?