本文整理汇总了C++中QueryResult::Fetch方法的典型用法代码示例。如果您正苦于以下问题:C++ QueryResult::Fetch方法的具体用法?C++ QueryResult::Fetch怎么用?C++ QueryResult::Fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryResult
的用法示例。
在下文中一共展示了QueryResult::Fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandlePlayerbotCommand
bool ChatHandler::HandlePlayerbotCommand(const char* args)
{
if(!(m_session->GetSecurity() > SEC_PLAYER))
if(sConfig.GetBoolDefault("PlayerbotAI.DisableBots", false))
{
PSendSysMessage("|cffff0000Playerbot system is currently disabled!");
SetSentErrorMessage(true);
return false;
}
if (! m_session)
{
PSendSysMessage("|cffff0000You may only add bots from an active session");
SetSentErrorMessage(true);
return false;
}
if (!*args)
{
PSendSysMessage("|cffff0000usage: add PLAYERNAME or remove PLAYERNAME");
SetSentErrorMessage(true);
return false;
}
char *cmd = strtok ((char*)args, " ");
char *charname = strtok (NULL, " ");
if (!cmd || !charname)
{
PSendSysMessage("|cffff0000usage: add PLAYERNAME or remove PLAYERNAME");
SetSentErrorMessage(true);
return false;
}
std::string cmdStr = cmd;
std::string charnameStr = charname;
if(!normalizePlayerName(charnameStr))
return false;
uint64 guid = sObjectMgr.GetPlayerGUIDByName(charnameStr.c_str());
if (guid == 0 || (guid == m_session->GetPlayer()->GetGUID()))
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
uint32 accountId = sObjectMgr.GetPlayerAccountIdByGUID(guid);
if (accountId != m_session->GetAccountId())
{
PSendSysMessage("|cffff0000You may only add bots from the same account.");
SetSentErrorMessage(true);
return false;
}
// create the playerbot manager if it doesn't already exist
PlayerbotMgr* mgr = m_session->GetPlayer()->GetPlayerbotMgr();
if (!mgr)
{
mgr = new PlayerbotMgr(m_session->GetPlayer());
m_session->GetPlayer()->SetPlayerbotMgr(mgr);
}
QueryResult *resultchar = CharacterDatabase.PQuery("SELECT Count(*) FROM characters WHERE online = 1 AND account = '%u'", m_session->GetAccountId());
if(resultchar)
{
Field *fields=resultchar->Fetch();
int acctcharcount = fields[0].GetUInt32();
if(!(m_session->GetSecurity() > SEC_PLAYER))
if((acctcharcount > sConfig.GetIntDefault("PlayerbotAI.MaxNumBots", 9)) && (cmdStr == "add" || cmdStr == "login"))
{
PSendSysMessage("|cffff0000You cannot summon anymore bots, for this account.");
SetSentErrorMessage(true);
delete resultchar;
return false;
}
}
delete resultchar;
QueryResult *resultlvl = CharacterDatabase.PQuery("SELECT level,name FROM characters WHERE guid = '%u'", guid);
if(resultlvl)
{
Field *fields=resultlvl->Fetch();
int charlvl = fields[0].GetUInt32();
if(!(m_session->GetSecurity() > SEC_PLAYER))
if(charlvl > sConfig.GetIntDefault("PlayerbotAI.RestrictBotLevel", 80))
{
PSendSysMessage("|cffff0000You cannot summon |cffffffff[%s]|cffff0000, it's level is too high.",fields[1].GetString());
SetSentErrorMessage(true);
delete resultlvl;
return false;
}
}
delete resultlvl;
// end of gmconfig patch
if (cmdStr == "add" || cmdStr == "login")
{
if (mgr->GetPlayerBot(guid))
{
PSendSysMessage("Bot already exists in world.");
//.........这里部分代码省略.........
示例2: LoadDisables
void LoadDisables()
{
uint32 oldMSTime = getMSTime();
// reload case
for (std::size_t i = 0; i < m_DisableMap.size(); ++i)
m_DisableMap[i].clear();
QueryResult result = WorldDatabase.Query("SELECT sourceType, entry, flags, params_0, params_1 FROM disables");
uint32 total_count = 0;
if (!result)
{
TC_LOG_INFO("server.loading", ">> Loaded 0 disables. DB table `disables` is empty!");
return;
}
Field* fields;
do
{
fields = result->Fetch();
uint32 type = fields[0].GetUInt32();
if (type >= MAX_DISABLE_TYPES)
{
TC_LOG_ERROR("sql.sql", "Invalid type %u specified in `disables` table, skipped.", type);
continue;
}
uint32 entry = fields[1].GetUInt32();
uint8 flags = fields[2].GetUInt8();
std::string params_0 = fields[3].GetString();
std::string params_1 = fields[4].GetString();
DisableData data;
data.flags = flags;
switch (type)
{
case DISABLE_TYPE_SPELL:
if (!(sSpellMgr->GetSpellInfo(entry) || flags & SPELL_DISABLE_DEPRECATED_SPELL))
{
TC_LOG_ERROR("sql.sql", "Spell entry %u from `disables` doesn't exist in dbc, skipped.", entry);
continue;
}
if (!flags || flags > MAX_SPELL_DISABLE_TYPE)
{
TC_LOG_ERROR("sql.sql", "Disable flags for spell %u are invalid, skipped.", entry);
continue;
}
if (flags & SPELL_DISABLE_MAP)
{
Tokenizer tokens(params_0, ',');
for (uint8 i = 0; i < tokens.size(); )
data.params[0].insert(atoi(tokens[i++]));
}
if (flags & SPELL_DISABLE_AREA)
{
Tokenizer tokens(params_1, ',');
for (uint8 i = 0; i < tokens.size(); )
data.params[1].insert(atoi(tokens[i++]));
}
break;
// checked later
case DISABLE_TYPE_QUEST:
break;
case DISABLE_TYPE_MAP:
{
MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
if (!mapEntry)
{
TC_LOG_ERROR("sql.sql", "Map entry %u from `disables` doesn't exist in dbc, skipped.", entry);
continue;
}
bool isFlagInvalid = false;
switch (mapEntry->InstanceType)
{
case MAP_COMMON:
if (flags)
isFlagInvalid = true;
break;
case MAP_INSTANCE:
case MAP_RAID:
if (flags & DUNGEON_STATUSFLAG_HEROIC && !sDB2Manager.GetMapDifficultyData(entry, DIFFICULTY_HEROIC))
flags -= DUNGEON_STATUSFLAG_HEROIC;
if (flags & RAID_STATUSFLAG_10MAN_HEROIC && !sDB2Manager.GetMapDifficultyData(entry, DIFFICULTY_10_HC))
flags -= RAID_STATUSFLAG_10MAN_HEROIC;
if (flags & RAID_STATUSFLAG_25MAN_HEROIC && !sDB2Manager.GetMapDifficultyData(entry, DIFFICULTY_25_HC))
flags -= RAID_STATUSFLAG_25MAN_HEROIC;
if (!flags)
isFlagInvalid = true;
break;
case MAP_BATTLEGROUND:
case MAP_ARENA:
TC_LOG_ERROR("sql.sql", "Battleground map %u specified to be disabled in map case, skipped.", entry);
continue;
//.........这里部分代码省略.........
示例3: DumpTable
// Writing - High-level functions
bool PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type)
{
GUIDs const* guids = NULL;
char const* fieldname = NULL;
switch (type)
{
case DTT_ITEM: fieldname = "guid"; guids = &items; break;
case DTT_ITEM_GIFT: fieldname = "item_guid"; guids = &items; break;
case DTT_PET: fieldname = "owner"; break;
case DTT_PET_TABLE: fieldname = "guid"; guids = &pets; break;
case DTT_MAIL: fieldname = "receiver"; break;
case DTT_MAIL_ITEM: fieldname = "mail_id"; guids = &mails; break;
default: fieldname = "guid"; break;
}
// for guid set stop if set is empty
if (guids && guids->empty())
return true; // nothing to do
// setup for guids case start position
GUIDs::const_iterator guids_itr;
if (guids)
guids_itr = guids->begin();
do
{
std::string wherestr;
if (guids) // set case, get next guids string
wherestr = GenerateWhereStr(fieldname, *guids, guids_itr);
else // not set case, get single guid string
wherestr = GenerateWhereStr(fieldname, guid);
QueryResult result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str());
if (!result)
return true;
do
{
// collect guids
switch (type)
{
case DTT_INVENTORY:
StoreGUID(result, 3, items); // item guid collection (character_inventory.item)
break;
case DTT_PET:
StoreGUID(result, 0, pets); // pet petnumber collection (character_pet.id)
break;
case DTT_MAIL:
StoreGUID(result, 0, mails); // mail id collection (mail.id)
break;
case DTT_MAIL_ITEM:
StoreGUID(result, 1, items); // item guid collection (mail_items.item_guid)
break;
case DTT_CHARACTER:
{
if (result->GetFieldCount() <= 64) // avoid crashes on next check
{
TC_LOG_FATAL("misc", "PlayerDumpWriter::DumpTable - Trying to access non-existing or wrong positioned field (`deleteInfos_Account`) in `characters` table.");
return false;
}
if (result->Fetch()[64].GetUInt32()) // characters.deleteInfos_Account - if filled error
return false;
break;
}
default:
break;
}
dump += CreateDumpString(tableTo, result);
dump += "\n";
}
while (result->NextRow());
}
while (guids && guids_itr != guids->end()); // not set case iterate single time, set case iterate for all guids
return true;
}
示例4: HandlePetitionBuyOpcode
//.........这里部分代码省略.........
break;
default:
sLog->outDebug(LOG_FILTER_NETWORKIO, "unknown selection at buy arena petition: %u", clientIndex);
return;
}
if (_player->GetArenaTeamId(clientIndex - 1)) // arenaSlot+1 as received from client
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ALREADY_IN_ARENA_TEAM);
return;
}
}
if (type == GUILD_CHARTER_TYPE)
{
if (sGuildMgr->GetGuildByName(name))
{
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_EXISTS_S, name);
return;
}
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_INVALID, name);
return;
}
}
else
{
if (sArenaTeamMgr->GetArenaTeamByName(name))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
return;
}
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_INVALID);
return;
}
}
ItemTemplate const *pProto = sObjectMgr->GetItemTemplate(charterid);
if (!pProto)
{
_player->SendBuyError(BUY_ERR_ITEM_NOT_FOUND, NULL, charterid, 0);
return;
}
if (!_player->HasEnoughMoney(cost))
{ //player hasn't got enough money
_player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, pCreature, charterid, 0);
return;
}
ItemPosCountVec dest;
InventoryResult msg = _player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, charterid, pProto->BuyCount);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, NULL, NULL, charterid);
return;
}
_player->ModifyMoney(-(int32)cost);
Item *charter = _player->StoreNewItem(dest, charterid, true);
if (!charter)
return;
charter->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1, charter->GetGUIDLow());
// ITEM_FIELD_ENCHANTMENT_1_1 is guild/arenateam id
// ITEM_FIELD_ENCHANTMENT_1_1+1 is current signatures count (showed on item)
charter->SetState(ITEM_CHANGED, _player);
_player->SendNewItem(charter, 1, true, false);
// a petition is invalid, if both the owner and the type matches
// we checked above, if this player is in an arenateam, so this must be
// datacorruption
QueryResult result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player->GetGUIDLow(), type);
std::ostringstream ssInvalidPetitionGUIDs;
if (result)
{
do
{
Field *fields = result->Fetch();
ssInvalidPetitionGUIDs << '\'' << fields[0].GetUInt32() << "' , ";
} while (result->NextRow());
}
// delete petitions with the same guid as this one
ssInvalidPetitionGUIDs << '\'' << charter->GetGUIDLow() << '\'';
sLog->outDebug(LOG_FILTER_NETWORKIO, "Invalid petition GUIDs: %s", ssInvalidPetitionGUIDs.str().c_str());
CharacterDatabase.EscapeString(name);
SQLTransaction trans = CharacterDatabase.BeginTransaction();
trans->PAppend("DELETE FROM petition WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str());
trans->PAppend("DELETE FROM petition_sign WHERE petitionguid IN (%s)", ssInvalidPetitionGUIDs.str().c_str());
trans->PAppend("INSERT INTO petition (ownerguid, petitionguid, name, type) VALUES ('%u', '%u', '%s', '%u')",
_player->GetGUIDLow(), charter->GetGUIDLow(), name.c_str(), type);
CharacterDatabase.CommitTransaction(trans);
}
示例5: OnGossipSelectCode
bool OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 uiSender, uint32 uiAction, const char* code)
{
pPlayer->PlayerTalkClass->ClearMenus();
if (uiSender == GOSSIP_SENDER_MAIN)
{
switch (uiAction)
{
case GOSSIP_ACTION_INFO_DEF:
{
char * charCode = (char*)code;
std::string strCode = (char*)code;
char * tmp;
int32 number[5];
std::string error = ("Вы ввели неверное число. Ваша ставка должна находится в пределах от 1 до " + std::string(sConfig->GetStringDefault("Lottery.MaxNumber", "30")));
std::string errordub = ("Вы уже делали ставку. Ожидайте розыграша и да благословит вас Элуна");
std::string numbers = ("Вы сделали ставку на номера:" + std::string(strCode));
tmp = strtok (charCode," ");
for (int8 n = 0; n < 5; ++n)
{
if (tmp != NULL)
{
number[n] = atoi(tmp);
if (number[n] < 0 || number[n] > sConfig->GetIntDefault("Lottery.MaxNumber", 30))
{
pCreature->MonsterWhisper(error.c_str(), pPlayer->GetGUID());
pPlayer->CLOSE_GOSSIP_MENU();
return false;
}
tmp = strtok (NULL, " ");
}
else
{
pCreature->MonsterWhisper(error.c_str(), pPlayer->GetGUID());
pPlayer->CLOSE_GOSSIP_MENU();
return false;
}
}
uint32 betMaxID;
QueryResult qbetMaxID = WorldDatabase.Query("SELECT MAX(id) FROM lottery_bets");
if (qbetMaxID)
betMaxID = qbetMaxID->Fetch()->GetUInt32();
else
betMaxID = 0;
uint32 rBetGuid;
QueryResult pBetGuid = WorldDatabase.Query("SELECT guid FROM lottery_bets");
if (pBetGuid)
rBetGuid = pBetGuid->Fetch()->GetUInt32();
else
rBetGuid = 0;
if (rBetGuid == pPlayer->GetGUID())
{
pCreature->MonsterWhisper(errordub.c_str(), pPlayer->GetGUID());
pPlayer->CLOSE_GOSSIP_MENU();
return false;
}
WorldDatabase.PExecute("INSERT INTO lottery_bets (id, name, guid, bet) VALUES ('%u', '%s', '%u', '%s')", betMaxID+1, pPlayer->GetName(), pPlayer->GetGUIDLow(), strCode.c_str());
pCreature->MonsterWhisper(numbers.c_str(), pPlayer->GetGUID());
pPlayer->ModifyMoney(-sConfig->GetIntDefault("Lottery.BetCost", 500000));
pPlayer->CLOSE_GOSSIP_MENU();
return true;
}
}
}
return false;
}
示例6: SendPetitionQueryOpcode
void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid)
{
uint64 ownerguid = 0;
uint32 type;
std::string name = "NO_NAME_FOR_GUID";
uint8 signs = 0;
QueryResult result = CharacterDatabase.PQuery(
"SELECT ownerguid, name, "
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, "
" type "
"FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid), GUID_LOPART(petitionguid));
if (result)
{
Field* fields = result->Fetch();
ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
name = fields[1].GetString();
signs = fields[2].GetUInt8();
type = fields[3].GetUInt32();
}
else
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionguid));
return;
}
WorldPacket data(SMSG_PETITION_QUERY_RESPONSE, (4+8+name.size()+1+1+4*12+2+10));
data << uint32(GUID_LOPART(petitionguid)); // guild/team guid (in Trillium always same as GUID_LOPART(petition guid)
data << uint64(ownerguid); // charter owner guid
data << name; // name (guild/arena team)
data << uint8(0); // some string
if (type == GUILD_CHARTER_TYPE)
{
data << uint32(9);
data << uint32(9);
data << uint32(0); // bypass client - side limitation, a different value is needed here for each petition
}
else
{
data << uint32(type-1);
data << uint32(type-1);
data << uint32(type); // bypass client - side limitation, a different value is needed here for each petition
}
data << uint32(0); // 5
data << uint32(0); // 6
data << uint32(0); // 7
data << uint32(0); // 8
data << uint16(0); // 9 2 bytes field
data << uint32(0); // 10
data << uint32(0); // 11
data << uint32(0); // 13 count of next strings?
for (int i = 0; i < 10; ++i)
data << uint8(0); // some string
data << uint32(0); // 14
if (type == GUILD_CHARTER_TYPE)
data << uint32(0); // 15 0 - guild, 1 - arena team
else
data << uint32(1);
SendPacket(&data);
}
示例7: HandlePetitionSignOpcode
void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "Received opcode CMSG_PETITION_SIGN"); // ok
Field *fields;
uint64 petitionguid;
uint8 unk;
recv_data >> petitionguid; // petition guid
recv_data >> unk;
QueryResult result = CharacterDatabase.PQuery(
"SELECT ownerguid, "
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, "
" type "
"FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid), GUID_LOPART(petitionguid));
if (!result)
{
sLog->outError("Petition %u is not found for player %u %s", GUID_LOPART(petitionguid), GetPlayer()->GetGUIDLow(), GetPlayer()->GetName());
return;
}
fields = result->Fetch();
uint64 ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
uint8 signs = fields[1].GetUInt8();
uint32 type = fields[2].GetUInt32();
uint32 plguidlo = _player->GetGUIDLow();
if (GUID_LOPART(ownerguid) == plguidlo)
return;
// not let enemies sign guild charter
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != sObjectMgr->GetPlayerTeamByGUID(ownerguid))
{
if (type != GUILD_CHARTER_TYPE)
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED);
else
Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NOT_ALLIED);
return;
}
if (type != GUILD_CHARTER_TYPE)
{
if (_player->getLevel() < sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", _player->GetName(), ERR_ARENA_TEAM_TARGET_TOO_LOW_S);
return;
}
uint8 slot = ArenaTeam::GetSlotByType(type);
if (slot >= MAX_ARENA_SLOT)
return;
if (_player->GetArenaTeamId(slot))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", _player->GetName(), ERR_ALREADY_IN_ARENA_TEAM_S);
return;
}
if (_player->GetArenaTeamIdInvited())
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", _player->GetName(), ERR_ALREADY_INVITED_TO_ARENA_TEAM_S);
return;
}
}
else
{
if (_player->GetGuildId())
{
Guild::SendCommandResult(this, GUILD_INVITE_S, ERR_ALREADY_IN_GUILD_S, _player->GetName());
return;
}
if (_player->GetGuildIdInvited())
{
Guild::SendCommandResult(this, GUILD_INVITE_S, ERR_ALREADY_INVITED_TO_GUILD_S, _player->GetName());
return;
}
}
if (++signs > type) // client signs maximum
return;
//client doesn't allow to sign petition two times by one character, but not check sign by another character from same account
//not allow sign another player from already sign player account
result = CharacterDatabase.PQuery("SELECT playerguid FROM petition_sign WHERE player_account = '%u' AND petitionguid = '%u'", GetAccountId(), GUID_LOPART(petitionguid));
if (result)
{
WorldPacket data(SMSG_PETITION_SIGN_RESULTS, (8+8+4));
data << uint64(petitionguid);
data << uint64(_player->GetGUID());
data << (uint32)PETITION_SIGN_ALREADY_SIGNED;
// close at signer side
SendPacket(&data);
// update for owner if online
if (Player *owner = ObjectAccessor::FindPlayer(ownerguid))
owner->GetSession()->SendPacket(&data);
return;
//.........这里部分代码省略.........
示例8: HandleWpModifyCommand
static bool HandleWpModifyCommand(ChatHandler* handler, const char* args) {
if (!*args)
return false;
// first arg: add del text emote spell waittime move
char* show_str = strtok((char*) args, " ");
if (!show_str) {
return false;
}
std::string show = show_str;
// Check
// Remember: "show" must also be the name of a column!
if ((show != "delay") && (show != "action") && (show != "action_chance")
&& (show != "move_flag") && (show != "del") && (show != "move")
&& (show != "wpadd")) {
return false;
}
// Next arg is: <PATHID> <WPNUM> <ARGUMENT>
char* arg_str = NULL;
// Did user provide a GUID
// or did the user select a creature?
// -> variable lowguid is filled with the GUID of the NPC
uint32 pathid = 0;
uint32 point = 0;
uint32 wpGuid = 0;
Creature* target = handler->getSelectedCreature();
if (!target || target->GetEntry() != VISUAL_WAYPOINT) {
handler->SendSysMessage(
"|cffff33ffERROR: You must select a waypoint.|r");
return false;
}
// The visual waypoint
Creature* wpCreature = NULL;
wpGuid = target->GetGUIDLow();
// Did the user select a visual spawnpoint?
if (wpGuid)
wpCreature =
handler->GetSession()->GetPlayer()->GetMap()->GetCreature(
MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
// attempt check creature existence by DB data
else {
handler->PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, wpGuid);
return false;
}
// User did select a visual waypoint?
// Check the creature
if (wpCreature->GetEntry() == VISUAL_WAYPOINT) {
QueryResult result = WorldDatabase.PQuery(
"SELECT id, point FROM waypoint_data WHERE wpguid = %u",
wpGuid);
if (!result) {
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH,
target->GetGUIDLow());
// Select waypoint number from database
// Since we compare float values, we have to deal with
// some difficulties.
// Here we search for all waypoints that only differ in one from 1 thousand
// (0.001) - There is no other way to compare C++ floats with mySQL floats
// See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
const char* maxDIFF = "0.01";
result =
WorldDatabase.PQuery(
"SELECT id, point FROM waypoint_data WHERE (abs(position_x - %f) <= %s) and (abs(position_y - %f) <= %s) and (abs(position_z - %f) <= %s)",
wpCreature->GetPositionX(), maxDIFF,
wpCreature->GetPositionY(), maxDIFF,
wpCreature->GetPositionZ(), maxDIFF);
if (!result) {
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM,
wpGuid);
return true;
}
}
do {
Field *fields = result->Fetch();
pathid = fields[0].GetUInt32();
point = fields[1].GetUInt32();
} while (result->NextRow());
// We have the waypoint number and the GUID of the "master npc"
// Text is enclosed in "<>", all other arguments not
arg_str = strtok((char*) NULL, " ");
}
// Check for argument
if (show != "del" && show != "move" && arg_str == NULL) {
handler->PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str);
return false;
}
if (show == "del" && target) {
handler->PSendSysMessage(
"|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r",
//.........这里部分代码省略.........
示例9: HandleWpShowCommand
static bool HandleWpShowCommand(ChatHandler* handler, const char* args) {
if (!*args)
return false;
// first arg: on, off, first, last
char* show_str = strtok((char*) args, " ");
if (!show_str)
return false;
// second arg: GUID (optional, if a creature is selected)
char* guid_str = strtok((char*) NULL, " ");
uint32 pathid = 0;
Creature* target = handler->getSelectedCreature();
// Did player provide a PathID?
if (!guid_str) {
// No PathID provided
// -> Player must have selected a creature
if (!target) {
handler->SendSysMessage(LANG_SELECT_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
pathid = target->GetWaypointPath();
} else {
// PathID provided
// Warn if player also selected a creature
// -> Creature selection is ignored <-
if (target)
handler->SendSysMessage(LANG_WAYPOINT_CREATSELECTED);
pathid = atoi((char*) guid_str);
}
std::string show = show_str;
uint32 Maxpoint;
//handler->PSendSysMessage("wpshow - show: %s", show);
// Show info for the selected waypoint
if (show == "info") {
// Check if the user did specify a visual waypoint
if (target->GetEntry() != VISUAL_WAYPOINT) {
handler->PSendSysMessage(LANG_WAYPOINT_VP_SELECT);
handler->SetSentErrorMessage(true);
return false;
}
QueryResult result =
WorldDatabase.PQuery(
"SELECT id, point, delay, move_flag, action, action_chance FROM waypoint_data WHERE wpguid = %u",
target->GetGUIDLow());
if (!result) {
handler->SendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM);
return true;
}
handler->SendSysMessage("|cff00ffffDEBUG: wp show info:|r");
do {
Field *fields = result->Fetch();
pathid = fields[0].GetUInt32();
uint32 point = fields[1].GetUInt32();
uint32 delay = fields[2].GetUInt32();
uint32 flag = fields[3].GetUInt32();
uint32 ev_id = fields[4].GetUInt32();
uint32 ev_chance = fields[5].GetUInt32();
handler->PSendSysMessage(
"|cff00ff00Show info: for current point: |r|cff00ffff%u|r|cff00ff00, Path ID: |r|cff00ffff%u|r",
point, pathid);
handler->PSendSysMessage(
"|cff00ff00Show info: delay: |r|cff00ffff%u|r", delay);
handler->PSendSysMessage(
"|cff00ff00Show info: Move flag: |r|cff00ffff%u|r",
flag);
handler->PSendSysMessage(
"|cff00ff00Show info: Waypoint event: |r|cff00ffff%u|r",
ev_id);
handler->PSendSysMessage(
"|cff00ff00Show info: Event chance: |r|cff00ffff%u|r",
ev_chance);
} while (result->NextRow());
return true;
}
if (show == "on") {
QueryResult result =
WorldDatabase.PQuery(
"SELECT point, position_x, position_y, position_z FROM waypoint_data WHERE id = '%u'",
pathid);
if (!result) {
handler->SendSysMessage("|cffff33ffPath no found.|r");
handler->SetSentErrorMessage(true);
//.........这里部分代码省略.........
示例10: LoadSkillExtraItemTable
// loads the extra item creation info from DB
void LoadSkillExtraItemTable() {
uint32 oldMSTime = getMSTime();
SkillExtraItemStore.clear(); // need for reload
// 0 1 2 3
QueryResult result =
WorldDatabase.Query(
"SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template");
if (!result) {
sLog->outErrorDb(
">> Loaded 0 spell specialization definitions. DB table `skill_extra_item_template` is empty.");
sLog->outString();
return;
}
uint32 count = 0;
do {
Field *fields = result->Fetch();
uint32 spellId = fields[0].GetUInt32();
if (!sSpellStore.LookupEntry(spellId)) {
sLog->outError(
"Skill specialization %u has non-existent spell id in `skill_extra_item_template`!",
spellId);
continue;
}
uint32 requiredSpecialization = fields[1].GetUInt32();
if (!sSpellStore.LookupEntry(requiredSpecialization)) {
sLog->outError(
"Skill specialization %u have not existed required specialization spell id %u in `skill_extra_item_template`!",
spellId, requiredSpecialization);
continue;
}
float additionalCreateChance = fields[2].GetFloat();
if (additionalCreateChance <= 0.0f) {
sLog->outError(
"Skill specialization %u has too low additional create chance in `skill_extra_item_template`!",
spellId);
continue;
}
uint8 additionalMaxNum = fields[3].GetUInt8();
if (!additionalMaxNum) {
sLog->outError(
"Skill specialization %u has 0 max number of extra items in `skill_extra_item_template`!",
spellId);
continue;
}
SkillExtraItemEntry& skillExtraItemEntry = SkillExtraItemStore[spellId];
skillExtraItemEntry.requiredSpecialization = requiredSpecialization;
skillExtraItemEntry.additionalCreateChance = additionalCreateChance;
skillExtraItemEntry.additionalMaxNum = additionalMaxNum;
++count;
} while (result->NextRow());
sLog->outString(">> Loaded %u spell specialization definitions in %u ms",
count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
示例11: HandleWpEventCommand
static bool HandleWpEventCommand(ChatHandler* handler, const char* args) {
if (!*args)
return false;
char* show_str = strtok((char*) args, " ");
std::string show = show_str;
// Check
if ((show != "add") && (show != "mod") && (show != "del")
&& (show != "listid"))
return false;
char* arg_id = strtok(NULL, " ");
uint32 id = 0;
if (show == "add") {
if (arg_id)
id = atoi(arg_id);
if (id) {
QueryResult result = WorldDatabase.PQuery(
"SELECT id FROM waypoint_scripts WHERE guid = %u", id);
if (!result) {
WorldDatabase.PExecute(
"INSERT INTO waypoint_scripts(guid)VALUES(%u)", id);
handler->PSendSysMessage("%s%s%u|r", "|cff00ff00",
"Wp Event: New waypoint event added: ", id);
} else
handler->PSendSysMessage(
"|cff00ff00Wp Event: You have choosed an existing waypoint script guid: %u|r",
id);
} else {
QueryResult result = WorldDatabase.Query(
"SELECT MAX(guid) FROM waypoint_scripts");
id = result->Fetch()->GetUInt32();
WorldDatabase.PExecute(
"INSERT INTO waypoint_scripts(guid)VALUES(%u)", id + 1);
handler->PSendSysMessage("%s%s%u|r", "|cff00ff00",
"Wp Event: New waypoint event added: |r|cff00ffff",
id + 1);
}
return true;
}
if (show == "listid") {
if (!arg_id) {
handler->PSendSysMessage("%s%s|r", "|cff33ffff",
"Wp Event: You must provide waypoint script id.");
return true;
}
id = atoi(arg_id);
uint32 a2, a3, a4, a5, a6;
float a8, a9, a10, a11;
char const* a7;
QueryResult result =
WorldDatabase.PQuery(
"SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = %u",
id);
if (!result) {
handler->PSendSysMessage("%s%s%u|r", "|cff33ffff",
"Wp Event: No waypoint scripts found on id: ", id);
return true;
}
Field *fields;
do {
fields = result->Fetch();
a2 = fields[0].GetUInt32();
a3 = fields[1].GetUInt32();
a4 = fields[2].GetUInt32();
a5 = fields[3].GetUInt32();
a6 = fields[4].GetUInt32();
a7 = fields[5].GetCString();
a8 = fields[6].GetFloat();
a9 = fields[7].GetFloat();
a10 = fields[8].GetFloat();
a11 = fields[9].GetFloat();
handler->PSendSysMessage(
"|cffff33ffid:|r|cff00ffff %u|r|cff00ff00, guid: |r|cff00ffff%u|r|cff00ff00, delay: |r|cff00ffff%u|r|cff00ff00, command: |r|cff00ffff%u|r|cff00ff00, datalong: |r|cff00ffff%u|r|cff00ff00, datalong2: |r|cff00ffff%u|r|cff00ff00, datatext: |r|cff00ffff%s|r|cff00ff00, posx: |r|cff00ffff%f|r|cff00ff00, posy: |r|cff00ffff%f|r|cff00ff00, posz: |r|cff00ffff%f|r|cff00ff00, orientation: |r|cff00ffff%f|r",
id, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
} while (result->NextRow());
}
if (show == "del") {
id = atoi(arg_id);
QueryResult result = WorldDatabase.PQuery(
"SELECT guid FROM waypoint_scripts WHERE guid = %u", id);
if (result) {
WorldDatabase.PExecute(
"DELETE FROM waypoint_scripts WHERE guid = %u", id);
//.........这里部分代码省略.........
示例12: LoadGuilds
void GuildMgr::LoadGuilds()
{
// 1. Load all guilds
sLog->outString("Loading guilds definitions...");
{
uint32 oldMSTime = getMSTime();
// 0 1 2 3 4 5 6
QueryResult result = CharacterDatabase.Query("SELECT g.guildid, g.name, g.leaderguid, g.EmblemStyle, g.EmblemColor, g.BorderStyle, g.BorderColor, "
// 7 8 9 10 11 12 13 14
"g.BackgroundColor, g.info, g.motd, g.createdate, g.BankMoney, COUNT(gbt.guildid), xp, level "
"FROM guild g LEFT JOIN guild_bank_tab gbt ON g.guildid = gbt.guildid GROUP BY g.guildid ORDER BY g.guildid ASC");
if (!result)
{
sLog->outString(">> Loaded 0 guild definitions. DB table `guild` is empty.");
sLog->outString();
return;
}
else
{
uint32 count = 0;
do
{
Field* fields = result->Fetch();
Guild* guild = new Guild();
if (!guild->LoadFromDB(fields))
{
delete guild;
continue;
}
AddGuild(guild);
++count;
}
while (result->NextRow());
sLog->outString(">> Loaded %u guild definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
}
// 2. Load all guild ranks
sLog->outString("Loading guild ranks...");
{
uint32 oldMSTime = getMSTime();
// Delete orphaned guild rank entries before loading the valid ones
CharacterDatabase.DirectExecute("DELETE gr FROM guild_rank gr LEFT JOIN guild g ON gr.guildId = g.guildId WHERE g.guildId IS NULL");
// 0 1 2 3 4
QueryResult result = CharacterDatabase.Query("SELECT guildid, rid, rname, rights, BankMoneyPerDay FROM guild_rank ORDER BY guildid ASC, rid ASC");
if (!result)
{
sLog->outString(">> Loaded 0 guild ranks. DB table `guild_rank` is empty.");
sLog->outString();
}
else
{
uint32 count = 0;
do
{
Field* fields = result->Fetch();
uint32 guildId = fields[0].GetUInt32();
if (Guild* guild = GetGuildById(guildId))
guild->LoadRankFromDB(fields);
++count;
}
while (result->NextRow());
sLog->outString(">> Loaded %u guild ranks in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
}
// 3. Load all guild members
sLog->outString("Loading guild members...");
{
uint32 oldMSTime = getMSTime();
// Delete orphaned guild member entries before loading the valid ones
CharacterDatabase.DirectExecute("DELETE gm FROM guild_member gm LEFT JOIN guild g ON gm.guildId = g.guildId WHERE g.guildId IS NULL");
// 0 1 2 3 4 5 6
QueryResult result = CharacterDatabase.Query("SELECT guildid, gm.guid, rank, pnote, offnote, BankResetTimeMoney, BankRemMoney, "
// 7 8 9 10 11 12
"BankResetTimeTab0, BankRemSlotsTab0, BankResetTimeTab1, BankRemSlotsTab1, BankResetTimeTab2, BankRemSlotsTab2, "
// 13 14 15 16 17 18
"BankResetTimeTab3, BankRemSlotsTab3, BankResetTimeTab4, BankRemSlotsTab4, BankResetTimeTab5, BankRemSlotsTab5, "
// 19 20 21 22 23 24
"c.name, c.level, c.class, c.zone, c.account, c.logout_time "
"FROM guild_member gm LEFT JOIN characters c ON c.guid = gm.guid ORDER BY guildid ASC");
if (!result)
{
sLog->outString(">> Loaded 0 guild members. DB table `guild_member` is empty.");
//.........这里部分代码省略.........
示例13: LoadDisables
void LoadDisables()
{
uint32 oldMSTime = getMSTime();
// reload case
for (DisableMap::iterator itr = m_DisableMap.begin(); itr != m_DisableMap.end(); ++itr)
itr->second.clear();
m_DisableMap.clear();
QueryResult result = WorldDatabase.Query("SELECT sourceType, entry, flags, params_0, params_1 FROM disables");
uint32 total_count = 0;
if (!result)
{
sLog->outString(">> Loaded 0 disables. DB table `disables` is empty!");
sLog->outString();
return;
}
Field* fields;
do
{
fields = result->Fetch();
DisableType type = DisableType(fields[0].GetUInt32());
if (type >= MAX_DISABLE_TYPES)
{
sLog->outErrorDb("Invalid type %u specified in `disables` table, skipped.", type);
continue;
}
uint32 entry = fields[1].GetUInt32();
uint8 flags = fields[2].GetUInt8();
std::string params_0 = fields[3].GetString();
std::string params_1 = fields[4].GetString();
DisableData data;
data.flags = flags;
switch (type)
{
case DISABLE_TYPE_GO_LOS:
if (!sObjectMgr->GetGameObjectTemplate(entry))
{
sLog->outErrorDb("Gameobject entry %u from `disables` doesn't exist in dbc, skipped.", entry);
continue;
}
if (flags)
sLog->outErrorDb("Disable flags specified for gameobject %u, useless data.", entry);
break;
case DISABLE_TYPE_SPELL:
if (!(sSpellMgr->GetSpellInfo(entry) || flags & SPELL_DISABLE_DEPRECATED_SPELL))
{
sLog->outErrorDb("Spell entry %u from `disables` doesn't exist in dbc, skipped.", entry);
continue;
}
if (!flags || flags > MAX_SPELL_DISABLE_TYPE)
{
sLog->outErrorDb("Disable flags for spell %u are invalid, skipped.", entry);
continue;
}
if (flags & SPELL_DISABLE_MAP)
{
Tokenizer tokens(params_0, ',');
for (uint8 i = 0; i < tokens.size(); )
data.params[0].insert(atoi(tokens[i++]));
}
if (flags & SPELL_DISABLE_AREA)
{
Tokenizer tokens(params_1, ',');
for (uint8 i = 0; i < tokens.size(); )
data.params[1].insert(atoi(tokens[i++]));
}
// xinef: if spell has disabled los, add flag
if (flags & SPELL_DISABLE_LOS)
{
SpellInfo* spellInfo = const_cast<SpellInfo*>(sSpellMgr->GetSpellInfo(entry));
spellInfo->AttributesEx2 |= SPELL_ATTR2_CAN_TARGET_NOT_IN_LOS;
}
break;
// checked later
case DISABLE_TYPE_QUEST:
break;
case DISABLE_TYPE_MAP:
{
MapEntry const* mapEntry = sMapStore.LookupEntry(entry);
if (!mapEntry)
{
sLog->outErrorDb("Map entry %u from `disables` doesn't exist in dbc, skipped.", entry);
continue;
}
bool isFlagInvalid = false;
switch (mapEntry->map_type)
{
//.........这里部分代码省略.........
示例14: SendAuthResponse
void WorldSession::SendAuthResponse(uint8 code, bool queued, uint32 queuePos)
{
QueryResult classResult = LoginDatabase.PQuery("SELECT class, expansion FROM realm_classes WHERE realmId = %u", realmID);
QueryResult raceResult = LoginDatabase.PQuery("SELECT race, expansion FROM realm_races WHERE realmId = %u", realmID);
if (!classResult || !raceResult)
{
TC_LOG_ERROR("network", "Unable to retrieve class or race data.");
return;
}
TC_LOG_ERROR("network", "SMSG_AUTH_RESPONSE");
WorldPacket packet(SMSG_AUTH_RESPONSE, 80);
packet.WriteBit(code == AUTH_OK);
if (code == AUTH_OK)
{
packet.WriteBits(0, 21);
packet.WriteBit(0);
packet.WriteBits(raceResult->GetRowCount(), 23);
packet.WriteBits(0, 21);
packet.WriteBit(0);
packet.WriteBits(classResult->GetRowCount(), 23);
packet.WriteBit(0);
packet.WriteBit(0);
packet.WriteBit(0);
}
packet.WriteBit(queued);
if (queued)
packet.WriteBit(1); // Unknown
packet.FlushBits();
if (queued)
packet << uint32(0); // Unknown
if (code == AUTH_OK)
{
do
{
Field* fields = classResult->Fetch();
packet << fields[1].GetUInt8();
packet << fields[0].GetUInt8();
}
while (classResult->NextRow());
packet << uint8(Expansion());
do
{
Field* fields = raceResult->Fetch();
packet << fields[1].GetUInt8();
packet << fields[0].GetUInt8();
}
while (raceResult->NextRow());
packet << uint32(Expansion());
packet << uint32(0);
packet << uint32(0);
packet << uint32(0);
packet << uint32(0);
packet << uint8(Expansion());
packet << uint32(0);
}
packet << uint8(code); // Auth response ?
SendPacket(&packet);
}
示例15: HandleTurnInPetitionOpcode
void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
{
sLog.outDebug("Received opcode CMSG_TURN_IN_PETITION"); // ok
//recv_data.hexlike();
WorldPacket data;
uint64 petitionguid;
uint32 ownerguidlo;
uint32 type;
std::string name;
recv_data >> petitionguid;
sLog.outDebug("Petition %u turned in by %u", GUID_LOPART(petitionguid), _player->GetGUIDLow());
// data
QueryResult *result = CharacterDatabase.PQuery("SELECT ownerguid, name, type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
if(result)
{
Field *fields = result->Fetch();
ownerguidlo = fields[0].GetUInt32();
name = fields[1].GetCppString();
type = fields[2].GetUInt32();
delete result;
}
else
{
sLog.outError("petition table has broken data!");
return;
}
if(type == 9)
{
if(_player->GetGuildId())
{
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
data << (uint32)PETITION_TURN_ALREADY_IN_GUILD; // already in guild
_player->GetSession()->SendPacket(&data);
return;
}
}
else
{
uint8 slot = ArenaTeam::GetSlotByType(type);
if(slot >= MAX_ARENA_SLOT)
return;
if(_player->GetArenaTeamId(slot))
{
//data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
//data << (uint32)PETITION_TURN_ALREADY_IN_GUILD; // already in guild
//_player->GetSession()->SendPacket(&data);
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ALREADY_IN_ARENA_TEAM);
return;
}
}
if(_player->GetGUIDLow() != ownerguidlo)
return;
// signs
uint8 signs;
result = CharacterDatabase.PQuery("SELECT playerguid FROM petition_sign WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
if(result)
signs = result->GetRowCount();
else
signs = 0;
uint32 count;
//if(signs < sWorld.getConfig(CONFIG_MIN_PETITION_SIGNS))
if(type == 9)
count = sWorld.getConfig(CONFIG_MIN_PETITION_SIGNS);
else
count = type-1;
if(signs < count)
{
data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4);
data << (uint32)PETITION_TURN_NEED_MORE_SIGNATURES; // need more signatures...
SendPacket(&data);
delete result;
return;
}
if(type == 9)
{
if(objmgr.GetGuildByName(name))
{
SendGuildCommandResult(GUILD_CREATE_S, name, GUILD_NAME_EXISTS);
delete result;
return;
}
}
else
{
if(objmgr.GetArenaTeamByName(name))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
delete result;
return;
//.........这里部分代码省略.........