void ProtocolLogin::getCharacterList(const std::string& accountName, const std::string& password, uint16_t version) { Account account; if (!IOLoginData::loginserverAuthentication(accountName, password, account)) { disconnectClient("Account name or password is not correct.", version); return; } OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if (output) { //Update premium days Game::updatePremium(account); //Add MOTD output->addByte(0x14); std::ostringstream ss; ss << g_game.getMotdNum() << "\n" << g_config.getString(ConfigManager::MOTD); output->addString(ss.str()); //Add session key output->addByte(0x28); output->addString(accountName + "\n" + password); //Add char list output->addByte(0x64); output->addByte(1); // number of worlds output->addByte(0); // world id output->addString(g_config.getString(ConfigManager::SERVER_NAME)); output->addString(g_config.getString(ConfigManager::IP)); output->add<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT)); output->addByte(0); uint8_t size = std::min<size_t>(std::numeric_limits<uint8_t>::max(), account.characters.size()); output->addByte(size); for (uint8_t i = 0; i < size; i++) { output->addByte(0); output->addString(account.characters[i]); } //Add premium days if (g_config.getBoolean(ConfigManager::FREE_PREMIUM)) { output->add<uint16_t>(0xFFFF); //client displays free premium } else { output->add<uint16_t>(account.premiumDays); } OutputMessagePool::getInstance()->send(output); } getConnection()->close(); }
void ProtocolLogin::disconnectClient(const std::string& message, uint16_t version) { OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if (output) { output->addByte(version >= 1076 ? 0x0B : 0x0A); output->addString(message); OutputMessagePool::getInstance()->send(output); } getConnection()->close(); }
void ProtocolOld::dispatchedDisconnectClient(const std::string& message) { OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if (output) { output->addByte(0x0A); output->addString(message); OutputMessagePool::getInstance()->send(output); } getConnection()->close(); }
void ProtocolSpectator::disconnectSpectator(const std::string& message) { if (client) { client->removeSpectator(this); player = nullptr; client = nullptr; } OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if (output) { output->addByte(0x14); output->addString(message); OutputMessagePool::getInstance()->send(output); } disconnect(); }
void ProtocolStatus::sendInfo(uint16_t requestedInfo, const std::string& characterName) { OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if (!output) { getConnection()->close(); return; } if (requestedInfo & REQUEST_BASIC_SERVER_INFO) { output->addByte(0x10); output->addString(g_config.getString(ConfigManager::SERVER_NAME)); output->addString(g_config.getString(ConfigManager::IP)); output->addString(std::to_string(g_config.getNumber(ConfigManager::LOGIN_PORT))); } if (requestedInfo & REQUEST_OWNER_SERVER_INFO) { output->addByte(0x11); output->addString(g_config.getString(ConfigManager::OWNER_NAME)); output->addString(g_config.getString(ConfigManager::OWNER_EMAIL)); } if (requestedInfo & REQUEST_MISC_SERVER_INFO) { output->addByte(0x12); output->addString(g_config.getString(ConfigManager::MOTD)); output->addString(g_config.getString(ConfigManager::LOCATION)); output->addString(g_config.getString(ConfigManager::URL)); output->add<uint64_t>((OTSYS_TIME() - ProtocolStatus::start) / 1000); } if (requestedInfo & REQUEST_PLAYERS_INFO) { output->addByte(0x20); output->add<uint32_t>(g_game.getPlayersOnline()); output->add<uint32_t>(g_config.getNumber(ConfigManager::MAX_PLAYERS)); output->add<uint32_t>(g_game.getPlayersRecord()); } if (requestedInfo & REQUEST_MAP_INFO) { output->addByte(0x30); output->addString(g_config.getString(ConfigManager::MAP_NAME)); output->addString(g_config.getString(ConfigManager::MAP_AUTHOR)); uint32_t mapWidth, mapHeight; g_game.getMapDimensions(mapWidth, mapHeight); output->add<uint16_t>(mapWidth); output->add<uint16_t>(mapHeight); } if (requestedInfo & REQUEST_EXT_PLAYERS_INFO) { output->addByte(0x21); // players info - online players list const auto& players = g_game.getPlayers(); output->add<uint32_t>(players.size()); for (const auto& it : players) { output->addString(it.second->getName()); output->add<uint32_t>(it.second->getLevel()); } } if (requestedInfo & REQUEST_PLAYER_STATUS_INFO) { output->addByte(0x22); // players info - online status info of a player if (g_game.getPlayerByName(characterName) != nullptr) { output->addByte(0x01); } else { output->addByte(0x00); } } if (requestedInfo & REQUEST_SERVER_SOFTWARE_INFO) { output->addByte(0x23); // server software info output->addString(STATUS_SERVER_NAME); output->addString(STATUS_SERVER_VERSION); output->addString(CLIENT_VERSION_STR); } OutputMessagePool::getInstance()->send(output); getConnection()->close(); }
void ProtocolLogin::getCastingStreamsList(const std::string& password, uint16_t version) { const auto& casts = ProtocolCaster::getLiveCasts(); std::vector<std::pair<uint32_t, std::string>> castList; bool havePassword = !password.empty(); for (const auto& cast : casts) { if (havePassword) { if (cast.second->isPasswordProtected() && (cast.second->getLiveCastPassword() == password)) { castList.push_back(std::make_pair(cast.second->getSpectatorCount(), cast.first->getName())); } } else { if (!cast.second->isPasswordProtected()) { castList.push_back(std::make_pair(cast.second->getSpectatorCount(), cast.first->getName())); } } } if (castList.size() == 0) { if (havePassword) { disconnectClient("No cast avaliable with this password.", version); } else { disconnectClient("No cast avaliable.", version); } return; } std::sort(castList.begin(), castList.end(), [](const std::pair<uint32_t, std::string>& lhs, const std::pair<uint32_t, std::string>& rhs) { return lhs.first > rhs.first; }); //dispatcher thread OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if (output) { //Add MOTD output->addByte(0x14); std::ostringstream ss; ss << g_game.getMotdNum() << "\n" << g_config.getString(ConfigManager::MOTD); output->addString(ss.str()); //Add session key output->addByte(0x28); output->addString("\n" + password); //Add char list output->addByte(0x64); //add worlds output->addByte(castList.size()); uint32_t world = 0; for (const auto& it : castList) { output->addByte(world); // world id uint32_t count = it.first; std::stringstream ss; if (count == 0) ss << "no viewer"; else if (count == 1) ss << count << "viewer"; else ss << count << " viewers"; output->addString(ss.str()); output->addString(g_config.getString(ConfigManager::IP)); output->add<uint16_t>(g_config.getNumber(ConfigManager::LIVE_CAST_PORT)); output->addByte(0); world++; } world = 0; output->addByte(castList.size()); for (const auto& it : castList) { output->addByte(world); // world id output->addString(it.second); world++; } output->add<uint16_t>(0x0); //The client expects the number of premium days left. OutputMessagePool::getInstance()->send(output); } getConnection()->close(); }