• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

AAC Znote/POTCP - login via php to OTS

Tubeshop

Member
Joined
Nov 23, 2023
Messages
173
Reaction score
19
GitHub - Znote/POTCP: (P)HP (O)pen (T)ibia (C)lient (P)rotocol (https://github.com/Znote/POTCP) it's about this system

8.0 client tfs 1.2

Do I need to change something more than I wrote here or add something to make this system work? So far I keep getting the message "hi! logging in.." and the character does not log in to the server.

I set it in loginPlayerBot.php:

PHP:
$tc = new Tibia_client('tibiaidle.com', 7171, 'myaccname', 'mypass', 'Testerinho', true);

I also changed in Tibia_client.class.php:

PHP:
const TIBIA_VERSION_INT = 800;
    const TIBIA_VERSION_STRING = "8.00";
 
Last edited:
@Znote may be happy to see someone taking an interest in POTCP, try pinging him.

POTCP has only been tested on the 10.97 and 7.6 protocols,
AFAIK nobody has ever tested it against the 8.0 protocol,
and given your experience, the login protocol probably changed between 8.0 and 10.96 (not surprising, they're years apart)

I know the login protocol changed significantly between the 7.6 protocol and 7.7 protocol, so the 7.6 version probably won't help you.

Seems someone with the appropriate skills needs to adapt the 10.97 version to 8.0.. It's not easy to study, it's a custom binary protocol,

To get started, go to your protocollogin.cpp and prop `ProtocolLogin::OnRecvFirstMessage full of debugging prints:
in
Code:
    uint16_t version = msg.get<uint16_t>();
what version is POTCP sending?
Code:
    uint16_t version = msg.get<uint16_t>();
    std::cout << "version: " << version << std::endl;
check if RSA decryption is failing? add a debug print in
Code:
    if (!Protocol::RSA_decrypt(msg)) {
        disconnect();
        return;
    }

is the keys being read correctly? add debug prints in
Code:
    uint32_t key[4];
    key[0] = msg.get<uint32_t>();
    key[1] = msg.get<uint32_t>();
    key[2] = msg.get<uint32_t>();
    key[3] = msg.get<uint32_t>();
and go in POTCP class Tibia_client_internal replace
PHP:
                //<xtea_initialization>
                if ($this->debugging) {
                    // nice keys for debugging (but insecure)
                    $this->xtea_key_binary = (new Tibia_binary_serializer())->add_string("xtea_key_12345")->str();
                    $this->xtea_key_binary = str_repeat((new Tibia_binary_serializer())->addU32(1337)->str(), 4);
                    $this->xtea_key_binary = str_repeat("\x00", 4 * 4);
                } else {
                    // secure key, not good for debugging.
                    $this->xtea_key_binary = random_bytes(4 * 4);
                }
with just
Code:
    $this->xtea_key_binary = str_repeat("\x00", 4 * 4);
if tfs reads the key correctly, key[0]-key[3] should all be 0, is it?

and add a debug print in
Code:
    if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) {
        std::ostringstream ss;
        ss << "Only clients with protocol " << CLIENT_VERSION_STR << " allowed!";
is this being hit? add a debugging print basically everywhere it can possibly fail in
ProtocolLogin::OnRecvFirstMessage and find the failure, it's probably in onRecvFirstMessage somewhere
 
I added this code to protocollogin.cpp but I don't know where this information should be displayed. In a programming environment? I don't know C++ and I don't know how to check it. After compilation, there is no information in the TFS console when logging in from the client and PHP POTCP. I'm using Ubuntu.


C++:
uint16_t version = msg.get<uint16_t>();
    std::cout << "version: " << version << std::endl;
Code:
if (!Protocol::RSA_decrypt(msg)) {
    std::cout << "RSA decryption failed!" << std::endl;
    disconnect();
    return;
}
C++:
uint32_t key[4];
key[0] = msg.get<uint32_t>();
key[1] = msg.get<uint32_t>();
key[2] = msg.get<uint32_t>();
key[3] = msg.get<uint32_t>();

std::cout << "Received key: " << key[0] << ", " << key[1] << ", " << key[2] << ", " << key[3] << std::endl;
 
i can't even find a copy of tibia 8.0, closest i can find is 8.1 and 7.72, strange.

Anyway, you seem to have done it correctly, are you using the GUI version of TFS or the pure console version?

Assuming you're using the GUI, don't start tfs by double-clicking on it, instead open cmd and write
Code:
cd "path to folder of tfs.exe"
tfs.exe
and run it again, and you should see your debug prints in cmd when logging in
 
I'm using the console version on Ubuntu. I also added set(CMAKE_BUILD_TYPE Debug) to CMakeLists.txt before compilation. I deleted the old build and run the new one, but I don't see any information in the console. I only have:


Lua:
>> Loaded all modules, server starting up...
>> TibiaIdle Server Online!


GOD has logged in.
 
yes, I have tfs 1.2 to support 8.0, exactly this:
Post automatically merged:

wait :) I think PHP logging sent something to the server
I received a message:

Lua:
Knight Idle has logged out.
version: 800
Received key: 279590138, 3236357030, 2204739371, 1063565238

However, I don't know what it means at all.
this message appears when I click "login" in the client and a list of characters to choose from is displayed.
 
Last edited:

That's a random key, even looks like a cryptographic key. If you replaced the key generation in PHP with
$this->xtea_key_binary = str_repeat("\x00", 4 * 4);

And you got that random key on the server, it means something in the protocol changed before sending the XTEA key 🤔 Question is what. Don't have an easy idea but you should add more logging to find out, somewhere you should find the last data that makes sense, and the first data that doesn't make sense (maybe the key is the first thing that doesn't make sense? In that case, what is the last thing POTCP sends before the key?)
 
Back
Top