当前位置: 首页>>代码示例>>C++>>正文


C++ OutputMessage_ptr::addString方法代码示例

本文整理汇总了C++中OutputMessage_ptr::addString方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputMessage_ptr::addString方法的具体用法?C++ OutputMessage_ptr::addString怎么用?C++ OutputMessage_ptr::addString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OutputMessage_ptr的用法示例。


在下文中一共展示了OutputMessage_ptr::addString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getCharacterList

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();
}
开发者ID:HeavenIsLost,项目名称:cast,代码行数:54,代码来源:protocollogin.cpp

示例2: disconnectClient

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();
}
开发者ID:HeavenIsLost,项目名称:cast,代码行数:11,代码来源:protocollogin.cpp

示例3: dispatchedDisconnectClient

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();
}
开发者ID:Blaggo,项目名称:forgottenserver,代码行数:11,代码来源:protocolold.cpp

示例4: disconnectSpectator

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();
}
开发者ID:ricker75,项目名称:forgottenserver,代码行数:16,代码来源:protocolspectator.cpp

示例5: sendInfo

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();
}
开发者ID:CyCu991,项目名称:forgottenserver,代码行数:75,代码来源:protocolstatus.cpp

示例6: getCastingStreamsList

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();
}
开发者ID:HeavenIsLost,项目名称:cast,代码行数:96,代码来源:protocollogin.cpp


注:本文中的OutputMessage_ptr::addString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。