Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
Custom client (really custom) and few problems with packets
Results 1 to 9 of 9

Thread: Custom client (really custom) and few problems with packets

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    27

    Custom client (really custom) and few problems with packets

    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:

    Quote Originally Posted by *DEAD*
    recall the that the typical tibia packet is in this format

    [2 bytes packet length] [4 bytes adler32] [XTEA encrypted data]
    But when I got first packet after sending login packet (this isn't encrypted because encryption is disabled on server side):
    [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?

  2. #2

    RE: Custom client (really custom) and few problems with packets

    You need to add Whole packet size in the begining of the packet and after the adler32 you need to add the Data Packet Size.

  3. #3
    Junior Member
    Join Date
    Mar 2009
    Posts
    27

    RE: Custom client (really custom) and few problems with packets

    Ok, thanks.
    And about that weird message type? Because I can see that server is adding $0A byte, but when I recieve it I have $14. Any ideas why?

  4. #4
    Senior Member
    Join Date
    Jul 2007
    Posts
    129

    RE: Custom client (really custom) and few problems with packets

    you compiled both the server AND client?

    If you compiled it to send the error as 0x0A packet and it is sending 0x14, there's something much wrong

  5. #5
    Junior Member
    Join Date
    Mar 2009
    Posts
    27

    RE: Custom client (really custom) and few problems with packets

    Well, server is just TFS without any encryption, and client, for now is only a little packet parser which doesn't work correctly.
    TFS default error message is $0A (0x0A) and I got $14 (0x14). I looked for many ways to explain why is it happening and I ended with nothing (well.. not exactly, I written whole encryption, now I'm turning it on on the server and maybe It'll work fine). Maybe TFS is encrypting message header in different place, I'll never know this

  6. #6
    Senior Member
    Join Date
    Jul 2007
    Posts
    129

    RE: Custom client (really custom) and few problems with packets

    well, in the otserv sources i have here, at protocollogin.cpp and bool ProtocolLogin:arseFirstPacket(NetworkMessage& msg):

    Code:
    if(version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX){
    	disconnectClient(0x0A, STRING_CLIENT_VERSION);
    	return false;
    }
    can you find it?

  7. #7
    Junior Member
    Join Date
    May 2007
    Posts
    27

    RE: Custom client (really custom) and few problems with packets

    Remember that YATC is under GPL, so if you make your custom client you will have to give out the sources.

  8. #8
    Junior Member
    Join Date
    Mar 2009
    Posts
    27

    RE: Custom client (really custom) and few problems with packets

    I know it's GPL, but:
    I don't copy/paste code, maybe because I'm writing in Delphi - not in C++. It has whole different structure, only packets are the same, but they are from CipSoft's client. Anyway it's for private use so I can give 'em source.
    (If I'll finish packet parser I'll post it here)

  9. #9
    Administrator
    Join Date
    Mar 2007
    Posts
    436

    RE: Custom client (really custom) and few problems with packets

    Quote Originally Posted by tekop
    Remember that YATC is under GPL, so if you make your custom client you will have to give out the sources.
    Even if it's under GPL you don't HAVE to share the code if you don't want to. Who will find out that you used the GPL licensed sourcecode anyway? It's a question of moral, if you have good moral then yes, you will share. Else you're just a dick leeching on others work and taking credit for it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •