本文整理汇总了C++中DBResult::getDataStream方法的典型用法代码示例。如果您正苦于以下问题:C++ DBResult::getDataStream方法的具体用法?C++ DBResult::getDataStream怎么用?C++ DBResult::getDataStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBResult
的用法示例。
在下文中一共展示了DBResult::getDataStream方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadMap
bool IOMapSerialize::loadMap(Map* map)
{
int64_t start = OTSYS_TIME();
Database* db = Database::getInstance();
std::ostringstream query;
DBResult* result = db->storeQuery("SELECT `id` FROM `houses`");
if (!result) {
return true;
}
do {
query.str("");
query << "SELECT `data` FROM `tile_store` WHERE `house_id` = " << result->getDataInt("id");
DBResult* tileResult = db->storeQuery(query.str());
if (!tileResult) {
continue;
}
do {
unsigned long attrSize = 0;
const char* attr = tileResult->getDataStream("data", attrSize);
PropStream propStream;
propStream.init(attr, attrSize);
uint16_t x = 0, y = 0;
uint8_t z = 0;
propStream.GET_USHORT(x);
propStream.GET_USHORT(y);
propStream.GET_UCHAR(z);
if (x == 0 || y == 0) {
continue;
}
Tile* tile = map->getTile(x, y, z);
if (!tile) {
continue;
}
uint32_t item_count = 0;
propStream.GET_ULONG(item_count);
while (item_count--) {
loadItem(propStream, tile);
}
} while (tileResult->next());
db->freeResult(tileResult);
} while (result->next());
db->freeResult(result);
std::cout << "> Loaded house items in: " << (OTSYS_TIME() - start) / (1000.) << " s" << std::endl;
return true;
}
示例2: loadMap
void IOMapSerialize::loadMap(Map* map)
{
int64_t start = OTSYS_TIME();
Database* db = Database::getInstance();
DBResult* result = db->storeQuery("SELECT `data` FROM `tile_store`");
if (!result) {
return;
}
do {
unsigned long attrSize;
const char* attr = result->getDataStream("data", attrSize);
PropStream propStream;
propStream.init(attr, attrSize);
uint16_t x, y;
uint8_t z;
if (!propStream.GET_USHORT(x) || !propStream.GET_USHORT(y) || !propStream.GET_UCHAR(z)) {
continue;
}
Tile* tile = map->getTile(x, y, z);
if (!tile) {
continue;
}
uint32_t item_count;
if (!propStream.GET_ULONG(item_count)) {
continue;
}
while (item_count--) {
loadItem(propStream, tile);
}
} while (result->next());
db->freeResult(result);
std::cout << "> Loaded house items in: " << (OTSYS_TIME() - start) / (1000.) << " s" << std::endl;
}
示例3: loadMapBinaryTileBased
bool IOMapSerialize::loadMapBinaryTileBased(Map* map)
{
Database* db = Database::getInstance();
DBResult* result;
DBQuery query;
query << "SELECT `house_id`, `data` FROM `tile_store` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
if(!(result = db->storeQuery(query.str())))
return false;
House* house = NULL;
do
{
int32_t houseId = result->getDataInt("house_id");
house = Houses::getInstance()->getHouse(houseId);
uint64_t attrSize = 0;
const char* attr = result->getDataStream("data", attrSize);
PropStream propStream;
propStream.init(attr, attrSize);
while(propStream.size())
{
uint16_t x = 0, y = 0;
uint8_t z = 0;
propStream.getShort(x);
propStream.getShort(y);
propStream.getByte(z);
uint32_t itemCount = 0;
propStream.getLong(itemCount);
Position pos(x, y, (int16_t)z);
if(house && house->hasPendingTransfer())
{
if(Player* player = g_game.getPlayerByGuidEx(house->getOwner()))
{
while(itemCount--)
loadItem(propStream, player->getInbox(), true);
if(player->isVirtual())
{
IOLoginData::getInstance()->savePlayer(player);
delete player;
}
}
}
else if(Tile* tile = map->getTile(pos))
{
while(itemCount--)
loadItem(propStream, tile, false);
}
else
{
std::clog << "[Error - IOMapSerialize::loadMapBinary] Unserialization of invalid tile"
<< " at position " << pos << std::endl;
break;
}
}
}
while(result->next());
result->free();
return true;
}
示例4: loadPlayer
bool IOPlayer::loadPlayer(Player* player, const std::string& name, bool preload /*= false*/)
{
Database* db = Database::instance();
DBQuery query;
DBResult* result;
query << "SELECT `players`.`id` AS `id`, `players`.`name` AS `name`, `account_id`, \
`players`.`group_id` as `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, \
`healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `direction`, `lookbody`, \
`lookfeet`, `lookhead`, `looklegs`, `looktype`, `posx`, `posy`, \
`posz`, `cap`, `lastlogin`, `lastip`, `save`, `conditions`, `redskulltime`, \
`redskull`, `guildnick`, `loss_experience`, `loss_mana`, `loss_skills`, \
`loss_items`, `rank_id`, `town_id`, `balance`, `premend` \
FROM `players` LEFT JOIN `accounts` ON `account_id` = `accounts`.`id` \
WHERE `players`.`name` = " + db->escapeString(name);
if(!(result = db->storeQuery(query.str()))){
return false;
}
query.str("");
player->setGUID(result->getDataInt("id"));
player->accountNumber = result->getDataInt("account_id");
const PlayerGroup* group = getPlayerGroup(result->getDataInt("group_id"));
if(group){
player->accessLevel = group->m_access;
player->maxDepotLimit = group->m_maxDepotItems;
player->maxVipLimit = group->m_maxVip;
player->setFlags(group->m_flags);
}
if(preload){
//only loading basic info
db->freeResult(result);
return true;
}
// Getting all player properties
player->setSex((playersex_t)result->getDataInt("sex"));
player->setDirection((Direction)result->getDataInt("direction"));
player->level = std::max((uint32_t)1, (uint32_t)result->getDataInt("level"));
uint64_t currExpCount = Player::getExpForLevel(player->level);
uint64_t nextExpCount = Player::getExpForLevel(player->level + 1);
uint64_t experience = (uint64_t)result->getDataLong("experience");
if(experience < currExpCount || experience > nextExpCount){
experience = currExpCount;
}
player->experience = experience;
player->levelPercent = Player::getPercentLevel(player->experience - currExpCount, nextExpCount - currExpCount);
player->soul = result->getDataInt("soul");
player->capacity = result->getDataInt("cap");
player->lastLoginSaved = result->getDataInt("lastlogin");
player->health = result->getDataInt("health");
player->healthMax = result->getDataInt("healthmax");
player->defaultOutfit.lookType = result->getDataInt("looktype");
player->defaultOutfit.lookHead = result->getDataInt("lookhead");
player->defaultOutfit.lookBody = result->getDataInt("lookbody");
player->defaultOutfit.lookLegs = result->getDataInt("looklegs");
player->defaultOutfit.lookFeet = result->getDataInt("lookfeet");
player->currentOutfit = player->defaultOutfit;
#ifdef __SKULLSYSTEM__
int32_t redSkullSeconds = result->getDataInt("redskulltime") - std::time(NULL);
if(redSkullSeconds > 0){
//ensure that we round up the number of ticks
player->redSkullTicks = (redSkullSeconds + 2)*1000;
if(result->getDataInt("redskull") == 1){
player->skull = SKULL_RED;
}
}
#endif
unsigned long conditionsSize = 0;
const char* conditions = result->getDataStream("conditions", conditionsSize);
PropStream propStream;
propStream.init(conditions, conditionsSize);
Condition* condition;
while((condition = Condition::createCondition(propStream))){
if(condition->unserialize(propStream)){
player->storedConditionList.push_back(condition);
}
else{
delete condition;
}
}
// you need to set the vocation after conditions in order to ensure the proper regeneration rates for the vocation
player->setVocation(result->getDataInt("vocation"));
// this stuff has to go after the vocation is set
player->mana = result->getDataInt("mana");
player->manaMax = result->getDataInt("manamax");
player->magLevel = result->getDataInt("maglevel");
uint32_t nextManaCount = (uint32_t)player->vocation->getReqMana(player->magLevel + 1);
uint32_t manaSpent = (uint32_t)result->getDataInt("manaspent");
if(manaSpent > nextManaCount){
//.........这里部分代码省略.........
示例5: loadPlayer
bool IOLoginData::loadPlayer(Player* player, const std::string& name, bool preload /*= false*/)
{
Database* db = Database::getInstance();
std::ostringstream query;
query << "SELECT `id`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `offlinetraining_time`, `offlinetraining_skill`, `stamina` FROM `players` WHERE `name` = " << db->escapeString(name);
DBResult* result = db->storeQuery(query.str());
if (!result) {
return false;
}
uint32_t accno = result->getDataInt("account_id");
Account acc = loadAccount(accno);
player->setGUID(result->getDataInt("id"));
player->accountNumber = accno;
player->accountType = acc.accountType;
if (g_config.getBoolean(ConfigManager::FREE_PREMIUM)) {
player->premiumDays = 0xFFFF;
} else {
player->premiumDays = acc.premiumDays;
}
player->setGroupId(result->getDataInt("group_id"));
if (preload) {
//only loading basic info
db->freeResult(result);
return true;
}
player->bankBalance = (uint64_t)result->getDataLong("balance");
player->setSex((PlayerSex_t)result->getDataInt("sex"));
player->level = std::max<uint32_t>(1, result->getDataInt("level"));
uint64_t currExpCount = Player::getExpForLevel(player->level);
uint64_t nextExpCount = Player::getExpForLevel(player->level + 1);
uint64_t experience = (uint64_t)result->getDataLong("experience");
if (experience < currExpCount || experience > nextExpCount) {
experience = currExpCount;
}
player->experience = experience;
if (currExpCount < nextExpCount) {
player->levelPercent = Player::getPercentLevel(player->experience - currExpCount, nextExpCount - currExpCount);
} else {
player->levelPercent = 0;
}
player->soul = result->getDataInt("soul");
player->capacity = result->getDataInt("cap");
player->blessings = result->getDataInt("blessings");
unsigned long conditionsSize = 0;
const char* conditions = result->getDataStream("conditions", conditionsSize);
PropStream propStream;
propStream.init(conditions, conditionsSize);
Condition* condition = Condition::createCondition(propStream);
while (condition) {
if (condition->unserialize(propStream)) {
player->storedConditionList.push_back(condition);
} else {
delete condition;
}
condition = Condition::createCondition(propStream);
}
player->setVocation(result->getDataInt("vocation"));
player->mana = result->getDataInt("mana");
player->manaMax = result->getDataInt("manamax");
player->magLevel = result->getDataInt("maglevel");
uint64_t nextManaCount = player->vocation->getReqMana(player->magLevel + 1);
uint64_t manaSpent = result->getDataLong("manaspent");
if (manaSpent > nextManaCount) {
manaSpent = 0;
}
player->manaSpent = manaSpent;
player->magLevelPercent = Player::getPercentLevel(player->manaSpent,
nextManaCount);
player->health = result->getDataInt("health");
player->healthMax = result->getDataInt("healthmax");
player->defaultOutfit.lookType = result->getDataInt("looktype");
player->defaultOutfit.lookHead = result->getDataInt("lookhead");
player->defaultOutfit.lookBody = result->getDataInt("lookbody");
player->defaultOutfit.lookLegs = result->getDataInt("looklegs");
player->defaultOutfit.lookFeet = result->getDataInt("lookfeet");
player->defaultOutfit.lookAddons = result->getDataInt("lookaddons");
//.........这里部分代码省略.........