• 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!

tfs 1.5 8.6 cast system partially working need help

johnsamir

Advanced OT User
Joined
Oct 13, 2009
Messages
965
Solutions
6
Reaction score
166
Location
Nowhere
have added your cast system into my tfs i can see character list


GM Ratx has logged in.


finally logged in but cant enable cast i does not work when i type command !cast also if i try to log in to game with no password/account i get message invalidad account name

Lua:
Lua:
void ProtocolLogin::onRecvFirstMessage(NetworkMessage& msg)
{
if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
disconnect();
return;
}

msg.skipBytes(2); // client OS

uint16_t version = msg.get<uint16_t>();
msg.skipBytes(12);
/*
* Skipped bytes:
* 4 bytes: protocolVersion
* 12 bytes: dat, spr, pic signatures (4 bytes each)
* 1 byte: 0
*/

if (version <= 760) {
disconnectClient(fmt::format("Only clients with protocol {:s} allowed!", CLIENT_VERSION_STR));
return;
}

if (!Protocol::RSA_decrypt(msg)) {
disconnect();
return;
}

xtea::key key;
key[0] = msg.get<uint32_t>();
key[1] = msg.get<uint32_t>();
key[2] = msg.get<uint32_t>();
key[3] = msg.get<uint32_t>();
enableXTEAEncryption();
setXTEAKey(std::move(key));

if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) {
disconnectClient(fmt::format("Only clients with protocol {:s} allowed!", CLIENT_VERSION_STR));
return;
}

if (g_game.getGameState() == GAME_STATE_STARTUP) {
disconnectClient("Gameworld is starting up. Please wait.");
return;
}

if (g_game.getGameState() == GAME_STATE_MAINTAIN) {
disconnectClient("Gameworld is under maintenance.\nPlease re-connect in a while.");
return;
}

BanInfo banInfo;
auto connection = getConnection();
if (!connection) {
return;
}

if (IOBan::isIpBanned(connection->getIP(), banInfo)) {
if (banInfo.reason.empty()) {
banInfo.reason = "(none)";
}

disconnectClient(fmt::format("Your IP has been banned until {:s} by {:s}.\n\nReason specified:\n{:s}", formatDateShort(banInfo.expiresAt), banInfo.bannedBy, banInfo.reason));
return;
}

std::string accountName = msg.getString();
if (accountName.empty()) {
disconnectClient("Invalid account name.");
return;
}

std::string password = msg.getString();
if (password.empty()) {
disconnectClient("Invalid password.");
return;
}

// OTCv8 version detection
uint16_t otclientV8 = 0;
uint16_t otcV8StringLength = msg.get<uint16_t>();
if (otcV8StringLength == 5 && msg.getString(5) == "OTCv8") {
otclientV8 = msg.get<uint16_t>(); // 253, 260, 261, ...
}

auto thisPtr = std::static_pointer_cast<ProtocolLogin>(shared_from_this());

if (password.empty())
{
if (!g_config.getBoolean(ConfigManager::ENABLE_LIVE_CASTING))
disconnectClient("Cast System is disabled.");
else
g_dispatcher.addTask([thisPtr]() { thisPtr->getCastingStreamsList(); });
return;
}

g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::getCharacterList, thisPtr, accountName, password)));
}
 
upup have made new changes now im getting msgs if no one is casting
Lua:
if (casts.size() == 0) {
    disconnectClient("There is no one live, try later.");
    return;
}
but i can't log in i get message password or account number is wrong

protocologin.cpp


Code:
void ProtocolLogin::getCastingStreamsList()
{
    uint32_t serverIp = serverIPs[0].first;
    for (uint32_t i = 0; i < serverIPs.size(); i++) {
        if ((serverIPs[i].first & serverIPs[i].second) == (getConnection()->getIP() & serverIPs[i].second)) {
            serverIp = serverIPs[i].first;
            break;
        }
    }
    auto output = OutputMessagePool::getOutputMessage();

    const std::string& motd = g_config.getString(ConfigManager::MOTD);
    if (!motd.empty()) {
        output->addByte(0x14);

        std::ostringstream ss;
        ss << g_game.getMotdNum() << "\n" << motd;
        output->addString(ss.str());
    }

    output->addByte(0x64);

    const auto& casts = ProtocolGame::getLiveCasts();
    output->addByte(casts.size());

    if (casts.size() == 0) {
        disconnectClient("There is no one live, try later.");
        return;
    }

    for (const auto& cast : casts)
    {
        std::ostringstream entry;
        entry << cast.first->getName() << " [" << cast.second->getSpectatorCount() << (cast.second->isPasswordProtected() ? "*]" : "]");
        output->addString(entry.str());
        entry.str(std::string());
        output->addString("Lvl " + std::to_string(cast.first->getLevel()));
        output->add<uint32_t>(serverIp);
        output->add<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT));
    }

    output->add<uint16_t>(0);
    send(std::move(output));
    disconnect();
}




void ProtocolLogin::onRecvFirstMessage(NetworkMessage& msg)
{
    if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
        disconnect();
        return;
    }

    msg.skipBytes(2); // client OS

    /*uint16_t version =*/ msg.get<uint16_t>();
    msg.skipBytes(12);

    /*
     * Skipped bytes:
     * 4 bytes: protocolVersion
     * 12 bytes: dat, spr, pic signatures (4 bytes each)
     */

    if (!Protocol::RSA_decrypt(msg)) {
        disconnect();
        return;
    }

    //uint32_t key[4];
    xtea::key key;
    key[0] = msg.get<uint32_t>();
    key[1] = msg.get<uint32_t>();
    key[2] = msg.get<uint32_t>();
    key[3] = msg.get<uint32_t>();
    enableXTEAEncryption();
    setXTEAKey(std::move(key));
    //setXTEAKey(key);

    /*if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) {
        //sendUpdateRequest();
        disconnectClient("Use Tibia 7.72 to login!");
        return;
    }*/

    if (g_game.getGameState() == GAME_STATE_STARTUP) {
        disconnectClient("Gameworld is starting up. Please wait.");
        return;
    }

    if (g_game.getGameState() == GAME_STATE_MAINTAIN) {
        disconnectClient("Gameworld is under maintenance.\nPlease re-connect in a while.");
        return;
    }

    BanInfo banInfo;
    auto connection = getConnection();
    if (!connection) {
        return;
    }

    if (IOBan::isIpBanned(connection->getIP(), banInfo)) {
        if (banInfo.reason.empty()) {
            banInfo.reason = "(none)";
        }

        std::ostringstream ss;
        ss << "Your IP has been banned until " << formatDateShort(banInfo.expiresAt) << " by " << banInfo.bannedBy << ".\n\nReason specified:\n" << banInfo.reason;
        disconnectClient(ss.str());
        return;
    }

    // Previous code... // was working
    //std::string accountName = msg.getString();
    //uint32_t accountName = msg.get<uint32_t>();
//    std::string password = msg.getString();

    //auto thisPtr = std::static_pointer_cast<ProtocolLogin>(shared_from_this());
    //uint32_t accountName = msg.get<uint32_t>(); //changed
    //std::string password = msg.getString();
    std::string password = msg.getString();
    std::string accountName = msg.getString();

    auto thisPtr = std::static_pointer_cast<ProtocolLogin>(shared_from_this());

    if (accountName.empty())
    {
        if (!g_config.getBoolean(ConfigManager::ENABLE_LIVE_CASTING))
            disconnectClient("Cast System is disabled.");
        else
            g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::getCastingStreamsList, thisPtr)));
        return;
    }
    //g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::getCharacterList, thisPtr, accountName, password)));
    g_dispatcher.addTask(createTask([thisPtr, accountName, password]() {
        thisPtr->getCharacterList(accountName, password);
        })); // was working
}

    //was working
    //if (!accountName)
    /*    if (!accountName.empty())
    {
        if (!g_config.getBoolean(ConfigManager::ENABLE_LIVE_CASTING))
            disconnectClient("Cast System is disabled.");
        else
            g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::getCastingStreamsList, thisPtr)));
        return;
    }
    g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::getCharacterList, thisPtr, accountName, password))); // original
    //g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::getCharacterList, thisPtr, std::placeholders::_1, std::placeholders::_2), accountName, password)); //proposal 1
    //g_dispatcher.addTask(createTask([thisPtr, accountName, password]() {
        //thisPtr->getCharacterList(accountName, password);
        //})); // was working
}*/

protcolgame.cpp
Code:
void ProtocolGame::onRecvFirstMessage(NetworkMessage& msg)
{
    if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
        disconnect();
        return;
    }

    OperatingSystem_t operatingSystem = static_cast<OperatingSystem_t>(msg.get<uint16_t>());
    version = msg.get<uint16_t>();

    if (!Protocol::RSA_decrypt(msg)) {
        disconnect();
        return;
    }

    xtea::key key;
    key[0] = msg.get<uint32_t>();
    key[1] = msg.get<uint32_t>();
    key[2] = msg.get<uint32_t>();
    key[3] = msg.get<uint32_t>();
    enableXTEAEncryption();
    setXTEAKey(std::move(key));

    /*if (operatingSystem >= CLIENTOS_OTCLIENT_LINUX) {
        NetworkMessage opcodeMessage;
        opcodeMessage.addByte(0x32);
        opcodeMessage.addByte(0x00);
        opcodeMessage.add<uint16_t>(0x00);
        writeToOutputBuffer(opcodeMessage);
    }*/

    msg.skipBytes(1); // gamemaster flag

    //uint32_t accountName = msg.get<uint32_t>();
    std::string accountName = msg.getString();
    std::string characterName = msg.getString();
    std::string password = msg.getString();

    /*if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) {
        //sendUpdateRequest();
        disconnectClient("Use Tibia 7.72 to login!");
        return;
    }*/

    if (g_game.getGameState() == GAME_STATE_STARTUP) {
        disconnectClient("Gameworld is starting up. Please wait.");
        return;
    }

    if (g_game.getGameState() == GAME_STATE_MAINTAIN) {
        disconnectClient("Gameworld is under maintenance. Please re-connect in a while.");
        return;
    }

    BanInfo banInfo;
    if (IOBan::isIpBanned(getIP(), banInfo)) {
        if (banInfo.reason.empty()) {
            banInfo.reason = "(none)";
        }

        std::ostringstream ss;
        ss << "Your IP has been banned until " << formatDateShort(banInfo.expiresAt) << " by " << banInfo.bannedBy << ".\n\nReason specified:\n" << banInfo.reason;
        disconnectClient(ss.str());
        return;
    }

    // OTCv8 version detection
    uint16_t otclientV8 = 0;
    uint16_t otcV8StringLength = msg.get<uint16_t>();
    if (otcV8StringLength == 5 && msg.getString(5) == "OTCv8") {
        otclientV8 = msg.get<uint16_t>(); // 253, 260, 261, ...
    }

    uint32_t accountId = IOLoginData::gameworldAuthentication(accountName, password, characterName);
    if (accountId == 0) {
        std::size_t pos = characterName.find("[");
        if (pos != std::string::npos) {
            pos -= 1;
        }
        g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::spectate, getThis(), characterName.substr(0, pos), password)));
    }
    else {
        Account account;
        if (accountId == 0) {
            disconnectClient("Account number or password is not correct.");
            return;
        }
        g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::login, getThis(), characterName, accountId, operatingSystem)));
    }
}

gameworldauth iologindata.cpp
Code:
uint32_t IOLoginData::gameworldAuthentication(const std::string& accountName, const std::string& password, std::string& characterName)
{
    Database& db = Database::getInstance();

    DBResult_ptr result = db.storeQuery(fmt::format("SELECT `id`, `password` FROM `accounts` WHERE `name` = {:s}", db.escapeString(accountName)));
    if (!result) {
        return 0;
    }

    if (transformToSHA1(password) != result->getString("password")) {
        return 0;
    }

    uint32_t accountId = result->getNumber<uint32_t>("id");

    result = db.storeQuery(fmt::format("SELECT `name` FROM `players` WHERE `name` = {:s} AND `account_id` = {:d} AND `deletion` = 0", db.escapeString(characterName), accountId));
    if (!result) {
        return 0;
    }

    characterName = result->getString("name");
    return accountId;
}
 
Back
Top