bool IOPlayer::cleanOnlineInfo() { DatabaseDriver* db = DatabaseDriver::instance(); DBQuery query; query << "UPDATE `players` SET `online` = 0 WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID); return db->executeQuery(query); }
bool IOAccount::saveAccount(const Account& acc) { DatabaseDriver* db = DatabaseDriver::instance(); DBQuery query; query << "UPDATE `accounts` SET `premend` = " << acc.premiumEnd << ", `warnings` = " << acc.warnings << " WHERE `id` = " << acc.number; return db->executeQuery(query); }
void IOPlayer::updateLogoutInfo(Player* player) { DatabaseDriver* db = DatabaseDriver::instance(); DBQuery query; query << "UPDATE `players` SET `lastlogout` = " << player->lastLogout << ", `online` = 0" << " WHERE `id` = " << player->getGUID(); db->executeQuery(query); }
bool IOPlayer::savePlayer(Player* player, bool shallow) { player->preSave(); DatabaseDriver* db = DatabaseDriver::instance(); DBQuery query; DBResult_ptr result; //check if the player has to be saved or not query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID(); if(!(result = db->storeQuery(query))){ return false; } const uint32_t save = result->getDataInt("save"); if(save == 0) return true; //serialize conditions PropWriteStream propWriteStream; for(ConditionList::const_iterator it = player->conditions.begin(); it != player->conditions.end(); ++it){ if((*it)->isPersistent()){ if(!(*it)->serialize(propWriteStream)){ return false; } propWriteStream.ADD_UCHAR(*CONDITIONATTR_END); } } uint32_t conditionsSize; const char* conditions = propWriteStream.getStream(conditionsSize); //First, an UPDATE query to write the player itself query.reset(); query << "UPDATE `players` SET `level` = " << player->level << ", `vocation` = " << (int32_t)player->getVocationId() << ", `health` = " << player->health << ", `healthmax` = " << player->healthMax << ", `direction` = " << player->getDirection().value() << ", `experience` = " << player->experience << ", `lookbody` = " << (int32_t)player->defaultOutfit.lookBody << ", `lookfeet` = " << (int32_t)player->defaultOutfit.lookFeet << ", `lookhead` = " << (int32_t)player->defaultOutfit.lookHead << ", `looklegs` = " << (int32_t)player->defaultOutfit.lookLegs << ", `looktype` = " << (int32_t)player->defaultOutfit.lookType << ", `lookaddons` = " << (int32_t)player->defaultOutfit.lookAddons << ", `maglevel` = " << player->magLevel << ", `mana` = " << player->mana << ", `manamax` = " << player->manaMax << ", `manaspent` = " << player->manaSpent << ", `soul` = " << player->soul << ", `town_id` = " << player->town << ", `posx` = " << player->getLoginPosition().x << ", `posy` = " << player->getLoginPosition().y << ", `posz` = " << player->getLoginPosition().z << ", `cap` = " << player->getCapacity() << ", `sex` = " << player->sex.value() << ", `conditions` = " << db->escapeBlob(conditions, conditionsSize) << ", `loss_experience` = " << (int32_t)player->getLossPercent(LOSS_EXPERIENCE) << ", `loss_mana` = " << (int32_t)player->getLossPercent(LOSS_MANASPENT) << ", `loss_skills` = " << (int32_t)player->getLossPercent(LOSS_SKILLTRIES) << ", `loss_items` = " << (int32_t)player->getLossPercent(LOSS_ITEMS) << ", `loss_containers` = " << (int32_t)player->getLossPercent(LOSS_CONTAINERS) << ", `stamina` = " << player->stamina; #ifdef __SKULLSYSTEM__ query << ", `skull_type` = " << (player->getSkull() == SKULL_RED || player->getSkull() == SKULL_BLACK ? player->getSkull().value() : 0); query << ", `skull_time` = " << player->lastSkullTime; #endif query << " WHERE `id` = " << player->getGUID(); DBTransaction transaction(db); if(!transaction.begin()) return false; if(!db->executeQuery(query)){ return false; } //skills for(int32_t i = 0; i <= 6; i++){ query.reset(); query << "UPDATE `player_skills` SET `value` = " << player->skills[i][SKILL_LEVEL] << ", `count` = " << player->skills[i][SKILL_TRIES] << " WHERE `player_id` = " << player->getGUID() << " AND `skill_id` = " << i; if(!db->executeQuery(query)){ return false; } } if(shallow) return transaction.commit(); // deletes all player-related stuff /* query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID(); if(!db->executeQuery(query.str())){ return false; } query.str(""); query << "DELETE FROM `player_depotitems` WHERE `player_id` = " << player->getGUID(); if(!db->executeQuery(query.str())){ return false; } query.str(""); */ query.reset(); query << "DELETE FROM `player_storage` WHERE `player_id` = " << player->getGUID(); if(!db->executeQuery(query)){ return false; } query.reset(); query << "DELETE FROM `player_viplist` WHERE `player_id` = " << player->getGUID(); if(!db->executeQuery(query.str())){ return false; } // Starti inserting DBInsert insert(db); /* ItemBlockList itemList; Item* item; for(int32_t slotId = 1; slotId <= 10; ++slotId){ if((item = player->inventory[slotId])){ itemList.push_back(itemBlock(slotId, item)); } } //item saving stmt.setQuery("INSERT INTO `player_items` (`player_id` , `pid` , `sid` , `itemtype` , `count` , `attributes` ) VALUES "); if(!(saveItems(player, itemList, stmt) && stmt.execute())){ return false; } itemList.clear(); for(DepotMap::iterator it = player->depots.begin(); it != player->depots.end(); ++it){ itemList.push_back(itemBlock(it->first, it->second)); } //save depot items stmt.setQuery("INSERT INTO `player_depotitems` (`player_id` , `pid` , `sid` , `itemtype` , `count` , `attributes` ) VALUES "); if(!(saveItems(player, itemList, stmt) && stmt.execute())){ return false; } */ insert.setQuery("INSERT INTO `player_storage` (`player_id` , `id` , `value` ) VALUES "); for(StorageMap::const_iterator cit = player->getCustomValueIteratorBegin(); cit != player->getCustomValueIteratorEnd();cit++){ query.reset(); query << player->getGUID() << ", " << db->escapeString(cit->first) << ", " << db->escapeString(cit->second); if(!insert.addRow(query.str())){ return false; } } if(!insert.execute()){ return false; } //save vip list if(!player->VIPList.empty()){ query.reset(); query << "INSERT INTO `player_viplist` (`player_id`, `vip_id`) SELECT " << player->getGUID() << ", `id` FROM `players` WHERE `id` IN ("; for(VIPListSet::iterator it = player->VIPList.begin(); it != player->VIPList.end(); ){ query << (*it); ++it; if(it != player->VIPList.end()){ query << ","; } else{ query << ")"; } } if(!db->executeQuery(query)){ return false; } } //End the transaction return transaction.commit(); }