本文整理汇总了C++中QueryResult类的典型用法代码示例。如果您正苦于以下问题:C++ QueryResult类的具体用法?C++ QueryResult怎么用?C++ QueryResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QueryResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendRewards
void sendRewards() {
QueryResult res = CharacterDatabase.PQuery("SELECT id,receiver,type,miscA,miscB,miscC,miscD FROM donations LEFT JOIN characters ON receiver=guid WHERE online=1");
if(res)
{
do
{
Field * field = res->Fetch();
uint32 id = field[0].GetUInt32();
uint32 receiver = field[1].GetUInt32();
uint32 type = field[2].GetUInt32();
uint32 misc[REWARD_SIZE];
misc[0] = field[3].GetUInt32();
misc[1] = field[4].GetUInt32();
misc[2] = field[5].GetUInt32();
misc[3] = field[6].GetUInt32();
Player * plr = sObjectAccessor->FindPlayer(receiver);
if(!plr || !plr->IsInWorld())
continue;
uint8 code = 0;
SQLTransaction trans = CharacterDatabase.BeginTransaction();
switch(type)
{
case REWARD_TYPE_GOLD:
plr->SetMoney(plr->GetMoney() + misc[0]);
break;
case REWARD_TYPE_RENAME:
plr->SetAtLoginFlag(AT_LOGIN_RENAME);
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", plr->GetGUIDLow());
break;
case REWARD_TYPE_CUSTOMIZE:
plr->SetAtLoginFlag(AT_LOGIN_CUSTOMIZE);
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'", plr->GetGUIDLow());
break;
case REWARD_TYPE_RACECHANGE:
plr->SetAtLoginFlag(AT_LOGIN_CHANGE_RACE);
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '128' WHERE guid = '%u'", plr->GetGUIDLow());
break;
case REWARD_TYPE_FACTIONCHANGE:
plr->SetAtLoginFlag(AT_LOGIN_CHANGE_FACTION);
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '64' WHERE guid = '%u'", plr->GetGUIDLow());
break;
case REWARD_TYPE_SINGLEITEM:
{
for(int i = 0; i < REWARD_SIZE; i++)
{
if(misc[i] == 0) continue;
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(misc[i]);
if(!proto)
{
code = 3;
break;
}
ItemPosCountVec pos;
uint32 extra = 0;
uint8 r = plr->CanStoreNewItem(NULL_BAG, NULL_SLOT, pos, misc[i], 1, &extra);
if(r != EQUIP_ERR_OK)
{
code = 4;
MailSender sender(MAIL_NORMAL,plr->GetGUIDLow(),MAIL_STATIONERY_VAL);
MailReceiver mailrecv(plr);
MailDraft draft("Reward Delivery","Here is your reward.");
Item * item = Item::CreateItem(misc[i],1);
item->SaveToDB(trans);
draft.AddItem(item);
draft.SendMailTo(trans,mailrecv,sender);
}
else
{
Item * item = plr->StoreNewItem(pos,misc[i],true);
plr->SendNewItem(item,1,true,false);
}
}
}
break;
case REWARD_TYPE_MULTIITEM:
{
for(int i = 0; i < REWARD_SIZE; i = i + 2)
{
uint32 itemid = misc[i];
uint32 itemcount = misc[i+1];
if(itemid == 0 || itemcount == 0)
continue;
ItemTemplate const * proto = sObjectMgr->GetItemTemplate(itemid);
if(!proto)
{
code = 3;
break;
}
ItemPosCountVec pos;
uint32 extra = 0;
uint32 addcount = itemcount;
uint8 r = plr->CanStoreNewItem(NULL_BAG,NULL_SLOT,pos,itemid,itemcount,&extra);
//.........这里部分代码省略.........
示例2: LoadMembersFromDB
bool ArenaTeam::LoadMembersFromDB(QueryResult arenaTeamMembersResult)
{
if (!arenaTeamMembersResult)
return false;
bool captainPresentInTeam = false;
do
{
Field *fields = arenaTeamMembersResult->Fetch();
//prevent crash if db records are broken, when all members in result are already processed and current team hasn't got any members
if (!fields)
break;
uint32 arenaTeamId = fields[0].GetUInt32();
if (arenaTeamId < m_TeamId)
{
//there is in table arena_team_member record which doesn't have arenateamid in arena_team table, report error
sLog.outErrorDb("ArenaTeam %u does not exist but it has record in arena_team_member table, deleting it!", arenaTeamId);
CharacterDatabase.PExecute("DELETE FROM arena_team_member WHERE arenateamid = '%u'", arenaTeamId);
continue;
}
if (arenaTeamId > m_TeamId)
//we loaded all members for this arena_team already, break cycle
break;
uint32 player_guid = fields[1].GetUInt32();
QueryResult result = CharacterDatabase.PQuery(
"SELECT personal_rating, matchmaker_rating FROM character_arena_stats WHERE guid = '%u' AND slot = '%u'", player_guid, GetSlot());
uint32 personalrating = 0;
uint32 matchmakerrating = 1500;
if (result)
{
personalrating = (*result)[0].GetUInt32();
matchmakerrating = (*result)[1].GetUInt32();
}
ArenaTeamMember newmember;
newmember.guid = MAKE_NEW_GUID(player_guid, 0, HIGHGUID_PLAYER);
newmember.games_week = fields[2].GetUInt32();
newmember.wins_week = fields[3].GetUInt32();
newmember.games_season = fields[4].GetUInt32();
newmember.wins_season = fields[5].GetUInt32();
newmember.name = fields[6].GetString();
newmember.Class = fields[7].GetUInt8();
newmember.personal_rating = personalrating;
newmember.matchmaker_rating = matchmakerrating;
//check if member exists in characters table
if (newmember.name.empty())
{
sLog.outErrorDb("ArenaTeam %u has member with empty name - probably player %u doesn't exist, deleting him from memberlist!", arenaTeamId, GUID_LOPART(newmember.guid));
this->DelMember(newmember.guid);
continue;
}
if (newmember.guid == GetCaptain())
captainPresentInTeam = true;
m_members.push_back(newmember);
}while (arenaTeamMembersResult->NextRow());
if (Empty() || !captainPresentInTeam)
{
// arena team is empty or captain is not in team, delete from db
sLog.outErrorDb("ArenaTeam %u does not have any members or its captain is not in team, disbanding it...", m_TeamId);
return false;
}
return true;
}
示例3: getMSTime
void GuildMgr::LoadGuilds()
{
// 1. Load all guilds
sLog->outString("Loading Guilds...");
{
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 15
"g.BackgroundColor, g.info, g.motd, g.createdate, g.BankMoney, COUNT(gbt.guildid), xp, level, m_today_xp, m_xp_cap "
"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 Guilds. 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;
}
QueryResult guildNews = CharacterDatabase.PQuery("SELECT type, date, value1, value2, source_guid, flags FROM guild_news WHERE guildid = %u ORDER BY date DESC", guild->GetId());
if (guildNews)
{
Field* fields = guildNews->Fetch();
guild->LoadGuildNewsFromDB(fields);
}
AddGuild(guild);
++count;
}
while (result->NextRow());
sLog->outString(">> Loaded %u Guilds 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
//.........这里部分代码省略.........
示例4: strcmp
bool Master::CheckDBVersion()
{
QueryResult* wqr = WorldDatabase.QueryNA( "SELECT LastUpdate FROM world_db_version;" );
if(wqr == NULL)
{
Log.Error("Database", "World database is missing the table `world_db_version` OR the table doesn't contain any rows. Can't validate database version. Exiting.");
Log.Error( "Database","You may need to update your database" );
return false;
}
Field* f = wqr->Fetch();
const char *WorldDBVersion = f->GetString();
Log.Notice("Database", "Last world database update: %s", WorldDBVersion);
int result = strcmp( WorldDBVersion, REQUIRED_WORLD_DB_VERSION );
if( result != 0 )
{
Log.Error("Database", "Last world database update doesn't match the required one which is %s.", REQUIRED_WORLD_DB_VERSION);
if( result < 0 ){
Log.Error("Database", "You need to apply the world update queries that are newer than %s. Exiting.", WorldDBVersion);
Log.Error( "Database", "You can find the world update queries in the sql/world_updates sub-directory of your ArcPro source directory." );
}else
Log.Error("Database", "Your world database is probably too new for this ArcPro version, you need to update your server. Exiting.");
delete wqr;
return false;
}
delete wqr;
QueryResult* cqr = CharacterDatabase.QueryNA( "SELECT LastUpdate FROM character_db_version;" );
if(cqr == NULL)
{
Log.Error("Database", "Character database is missing the table `character_db_version` OR the table doesn't contain any rows. Can't validate database version. Exiting.");
Log.Error( "Database","You may need to update your database" );
return false;
}
f = cqr->Fetch();
const char *CharDBVersion = f->GetString();
Log.Notice("Database", "Last character database update: %s", CharDBVersion);
result = strcmp( CharDBVersion, REQUIRED_CHAR_DB_VERSION );
if( result != 0 )
{
Log.Error("Database", "Last character database update doesn't match the required one which is %s.", REQUIRED_CHAR_DB_VERSION);
if( result < 0 ){
Log.Error("Database", "You need to apply the character update queries that are newer than %s. Exiting.", CharDBVersion);
Log.Error( "Database", "You can find the character update queries in the sql/character_updates sub-directory of your ArcPro source directory." );
}else
Log.Error("Database", "Your character database is too new for this ArcPro version, you need to update your server. Exiting.");
delete cqr;
return false;
}
delete cqr;
Log.Success("Database", "Database successfully validated.");
return true;
}
示例5: delete
void Map::LoadSpawns(bool reload)
{
//uint32 st=getMSTime();
CreatureSpawnCount = 0;
if ( reload )//perform cleanup
for ( uint32 x = 0; x < _sizeX; x++ )
for ( uint32 y = 0; y < _sizeY; y++ )
if ( spawns[x][y])
{
CellSpawns * sp = spawns[x][y];
for ( CreatureSpawnList::iterator i = sp->CreatureSpawns.begin(); i != sp->CreatureSpawns.end(); i++ )
delete (*i);
for ( GOSpawnList::iterator it = sp->GOSpawns.begin(); it != sp->GOSpawns.end(); it++ )
delete (*it);
delete sp;
spawns[x][y] = NULL;
}
QueryResult * result;
set<string>::iterator tableiterator;
for(tableiterator=ExtraMapCreatureTables.begin(); tableiterator!=ExtraMapCreatureTables.end();++tableiterator)
{
result = WorldDatabase.Query("SELECT * FROM %s WHERE Map = %u",(*tableiterator).c_str(),this->_mapId);
if(result)
{
if(CheckResultLengthCreatures( result) )
{
do{
Field * fields = result->Fetch();
CreatureSpawn * cspawn = new CreatureSpawn;
cspawn->id = fields[0].GetUInt32();
cspawn->form = FormationMgr::getSingleton().GetFormation(cspawn->id);
cspawn->entry = fields[1].GetUInt32();
cspawn->x = fields[3].GetFloat();
cspawn->y = fields[4].GetFloat();
cspawn->z = fields[5].GetFloat();
cspawn->o = fields[6].GetFloat();
/*uint32 cellx=float2int32(((_maxX-cspawn->x)/_cellSize));
uint32 celly=float2int32(((_maxY-cspawn->y)/_cellSize));*/
uint32 cellx=CellHandler<MapMgr>::GetPosX(cspawn->x);
uint32 celly=CellHandler<MapMgr>::GetPosY(cspawn->y);
if(spawns[cellx]== NULL)
{
spawns[cellx]=new CellSpawns*[_sizeY];
memset(spawns[cellx],0,sizeof(CellSpawns*)*_sizeY);
}
if(!spawns[cellx][celly])
spawns[cellx][celly]=new CellSpawns;
cspawn->movetype = fields[7].GetUInt8();
cspawn->displayid = fields[8].GetUInt32();
cspawn->factionid = fields[9].GetUInt32();
cspawn->flags = fields[10].GetUInt32();
cspawn->bytes0 = fields[11].GetUInt32();
cspawn->bytes1 = fields[12].GetUInt32();
cspawn->bytes2 = fields[13].GetUInt32();
cspawn->emote_state = fields[14].GetUInt32();
//cspawn->respawnNpcLink = fields[15].GetUInt32();
cspawn->channel_spell = fields[16].GetUInt16();
cspawn->channel_target_go = fields[17].GetUInt32();
cspawn->channel_target_creature = fields[18].GetUInt32();
cspawn->stand_state = fields[19].GetUInt16();
cspawn->MountedDisplayID = fields[20].GetUInt32();
cspawn->Item1SlotDisplay = fields[21].GetUInt32();
cspawn->Item2SlotDisplay = fields[22].GetUInt32();
cspawn->Item3SlotDisplay = fields[23].GetUInt32();
cspawn->CanFly = fields[24].GetUInt32();
cspawn->phase = fields[25].GetUInt32();
if( cspawn->phase == 0 ) cspawn->phase= 0xFFFFFFFF;
spawns[cellx][celly]->CreatureSpawns.push_back(cspawn);
++CreatureSpawnCount;
}while(result->NextRow());
}
delete result;
}
}
result = WorldDatabase.Query("SELECT * FROM creature_staticspawns WHERE Map = %u",this->_mapId);
if(result)
{
if( CheckResultLengthCreatures(result) )
{
do{
Field * fields = result->Fetch();
CreatureSpawn * cspawn = new CreatureSpawn;
cspawn->id = fields[0].GetUInt32();
cspawn->form = FormationMgr::getSingleton().GetFormation(cspawn->id);
cspawn->entry = fields[1].GetUInt32();
cspawn->x = fields[3].GetFloat();
cspawn->y = fields[4].GetFloat();
cspawn->z = fields[5].GetFloat();
cspawn->o = fields[6].GetFloat();
cspawn->movetype = fields[7].GetUInt8();
cspawn->displayid = fields[8].GetUInt32();
cspawn->factionid = fields[9].GetUInt32();
cspawn->flags = fields[10].GetUInt32();
cspawn->bytes0 = fields[11].GetUInt32();
//.........这里部分代码省略.........
示例6: CHECK_PACKET_SIZE
//.........这里部分代码省略.........
}
sLog.outDetail("Player %u is sending mail to %s (GUID: %u) with subject %s and body %s includes %u items, %u copper and %u COD copper with unk1 = %u, unk2 = %u", pl->GetGUIDLow(), receiver.c_str(), GUID_LOPART(rc), subject.c_str(), body.c_str(), items_count, money, COD, unk1, unk2);
if(pl->GetGUID() == rc)
{
pl->SendMailResult(0, 0, MAIL_ERR_CANNOT_SEND_TO_SELF);
return;
}
uint32 cost = items_count ? 30 * items_count : 30; // price hardcoded in client
uint32 reqmoney = cost + money;
if (pl->GetMoney() < reqmoney)
{
pl->SendMailResult(0, 0, MAIL_ERR_NOT_ENOUGH_MONEY);
return;
}
Player *receive = objmgr.GetPlayer(rc);
uint32 rc_team = 0;
uint8 mails_count = 0; //do not allow to send to one player more than 100 mails
if(receive)
{
rc_team = receive->GetTeam();
mails_count = receive->GetMailSize();
}
else
{
rc_team = objmgr.GetPlayerTeamByGUID(rc);
QueryResult* result = CharacterDatabase.PQuery("SELECT COUNT(*) FROM mail WHERE receiver = '%u'", GUID_LOPART(rc));
if(result)
{
Field *fields = result->Fetch();
mails_count = fields[0].GetUInt32();
delete result;
}
}
//do not allow to have more than 100 mails in mailbox.. mails count is in opcode uint8!!! - so max can be 255..
if (mails_count > 100)
{
pl->SendMailResult(0, 0, MAIL_ERR_INTERNAL_ERROR);
return;
}
// test the receiver's Faction...
if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_MAIL) && pl->GetTeam() != rc_team && GetSecurity() == SEC_PLAYER)
{
pl->SendMailResult(0, 0, MAIL_ERR_NOT_YOUR_TEAM);
return;
}
if (items_count)
{
for(MailItemMap::iterator mailItemIter = mi.begin(); mailItemIter != mi.end(); ++mailItemIter)
{
MailItem& mailItem = mailItemIter->second;
if(!mailItem.item_guidlow)
{
pl->SendMailResult(0, 0, MAIL_ERR_INTERNAL_ERROR);
return;
}
示例7: ReloadAccounts
void AccountMgr::ReloadAccounts(bool silent)
{
setBusy.Acquire();
if(!silent) sLog.outString("[AccountMgr] Reloading Accounts...");
// Load *all* accounts.
QueryResult * result = sLogonSQL->Query("SELECT acct, login, password, encrypted_password, gm, flags, banned, forceLanguage, muted FROM accounts");
Field * field;
string AccountName;
set<string> account_list;
Account * acct;
if(result)
{
do
{
field = result->Fetch();
AccountName = field[1].GetString();
// transform to uppercase
ASCENT_TOUPPER(AccountName);
//Use private __GetAccount, for locks
acct = __GetAccount(AccountName);
if(acct == 0)
{
// New account.
AddAccount(field);
}
else
{
// Update the account with possible changed details.
UpdateAccount(acct, field);
}
// add to our "known" list
account_list.insert(AccountName);
} while(result->NextRow());
delete result;
}
// check for any purged/deleted accounts
#ifdef WIN32
HM_NAMESPACE::hash_map<string, Account*>::iterator itr = AccountDatabase.begin();
HM_NAMESPACE::hash_map<string, Account*>::iterator it2;
#else
std::map<string, Account*>::iterator itr = AccountDatabase.begin();
std::map<string, Account*>::iterator it2;
#endif
for(; itr != AccountDatabase.end();)
{
it2 = itr;
++itr;
if(account_list.find(it2->first) == account_list.end())
{
delete it2->second;
AccountDatabase.erase(it2);
}
else
{
it2->second->UsernamePtr = (std::string*)&it2->first;
}
}
if(!silent) sLog.outString("[AccountMgr] Found %u accounts.", AccountDatabase.size());
setBusy.Release();
IPBanner::getSingleton().Reload();
}
示例8: data
void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
{
std::string name;
uint8 race_,class_;
recv_data >> name;
recv_data >> race_;
recv_data >> class_;
WorldPacket data(SMSG_CHAR_CREATE, 1); // returned with diff.values in all cases
if(GetSecurity() == SEC_PLAYER)
{
if(uint32 mask = sWorld.getConfig(CONFIG_CHARACTERS_CREATING_DISABLED))
{
bool disabled = false;
uint32 team = Player::TeamForRace(race_);
switch(team)
{
case ALLIANCE: disabled = mask & (1<<0); break;
case HORDE: disabled = mask & (1<<1); break;
}
if(disabled)
{
data << (uint8)CHAR_CREATE_DISABLED;
SendPacket( &data );
return;
}
}
}
ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(class_);
ChrRacesEntry const* raceEntry = sChrRacesStore.LookupEntry(race_);
if( !classEntry || !raceEntry )
{
data << (uint8)CHAR_CREATE_FAILED;
SendPacket( &data );
sLog.outError("Class: %u or Race %u not found in DBC (Wrong DBC files?) or Cheater?", class_, race_);
return;
}
// prevent character creating Expansion race without Expansion account
if (raceEntry->addon > Expansion())
{
data << (uint8)CHAR_CREATE_EXPANSION;
sLog.outError("Expansion %u account:[%d] tried to Create character with expansion %u race (%u)",Expansion(),GetAccountId(),raceEntry->addon,race_);
SendPacket( &data );
return;
}
// prevent character creating Expansion class without Expansion account
if (classEntry->addon > Expansion())
{
data << (uint8)CHAR_CREATE_EXPANSION_CLASS;
sLog.outError("Expansion %u account:[%d] tried to Create character with expansion %u class (%u)",Expansion(),GetAccountId(),classEntry->addon,class_);
SendPacket( &data );
return;
}
// prevent character creating with invalid name
if (!normalizePlayerName(name))
{
data << (uint8)CHAR_NAME_NO_NAME;
SendPacket( &data );
sLog.outError("Account:[%d] but tried to Create character with empty [name] ",GetAccountId());
return;
}
// check name limitations
uint8 res = ObjectMgr::CheckPlayerName(name,true);
if (res != CHAR_NAME_SUCCESS)
{
data << uint8(res);
SendPacket( &data );
return;
}
if (GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(name))
{
data << (uint8)CHAR_NAME_RESERVED;
SendPacket( &data );
return;
}
if (objmgr.GetPlayerGUIDByName(name))
{
data << (uint8)CHAR_CREATE_NAME_IN_USE;
SendPacket( &data );
return;
}
QueryResult *resultacct = loginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
if (resultacct)
{
Field *fields=resultacct->Fetch();
uint32 acctcharcount = fields[0].GetUInt32();
//.........这里部分代码省略.........
示例9: Player
void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder)
{
uint64 playerGuid = holder->GetGuid();
Player* pCurrChar = new Player(this);
pCurrChar->GetMotionMaster()->Initialize();
// "GetAccountId()==db stored account id" checked in LoadFromDB (prevent login not own character using cheating tools)
if(!pCurrChar->LoadFromDB(GUID_LOPART(playerGuid), holder))
{
KickPlayer(); // disconnect client, player no set to session and it will not deleted or saved at kick
delete pCurrChar; // delete it manually
delete holder; // delete all unprocessed queries
m_playerLoading = false;
return;
}
SetPlayer(pCurrChar);
pCurrChar->SendDungeonDifficulty(false);
WorldPacket data( SMSG_LOGIN_VERIFY_WORLD, 20 );
data << pCurrChar->GetMapId();
data << pCurrChar->GetPositionX();
data << pCurrChar->GetPositionY();
data << pCurrChar->GetPositionZ();
data << pCurrChar->GetOrientation();
SendPacket(&data);
// load player specific part before send times
LoadAccountData(holder->GetResult(PLAYER_LOGIN_QUERY_LOADACCOUNTDATA),PER_CHARACTER_CACHE_MASK);
SendAccountDataTimes();
data.Initialize(SMSG_FEATURE_SYSTEM_STATUS, 2); // added in 2.2.0
data << uint8(2); // unknown value
data << uint8(0); // enable(1)/disable(0) voice chat interface in client
SendPacket(&data);
// Send MOTD
{
data.Initialize(SMSG_MOTD, 50); // new in 2.0.1
data << (uint32)0;
uint32 linecount=0;
std::string str_motd = sWorld.GetMotd();
std::string::size_type pos, nextpos;
pos = 0;
while ( (nextpos= str_motd.find('@',pos)) != std::string::npos )
{
if (nextpos != pos)
{
data << str_motd.substr(pos,nextpos-pos);
++linecount;
}
pos = nextpos+1;
}
if (pos<str_motd.length())
{
data << str_motd.substr(pos);
++linecount;
}
data.put(0, linecount);
SendPacket( &data );
DEBUG_LOG( "WORLD: Sent motd (SMSG_MOTD)" );
}
data.Initialize(SMSG_LEARNED_DANCE_MOVES, 4+4);
data << uint32(0);
data << uint32(0);
SendPacket(&data);
//QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow());
QueryResult *resultGuild = holder->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD);
if(resultGuild)
{
Field *fields = resultGuild->Fetch();
pCurrChar->SetInGuild(fields[0].GetUInt32());
pCurrChar->SetRank(fields[1].GetUInt32());
delete resultGuild;
}
else if(pCurrChar->GetGuildId()) // clear guild related fields in case wrong data about non existed membership
{
pCurrChar->SetInGuild(0);
pCurrChar->SetRank(0);
}
if(pCurrChar->GetGuildId() != 0)
{
Guild* guild = objmgr.GetGuildById(pCurrChar->GetGuildId());
if(guild)
{
data.Initialize(SMSG_GUILD_EVENT, (2+guild->GetMOTD().size()+1));
data << (uint8)GE_MOTD;
data << (uint8)1;
data << guild->GetMOTD();
//.........这里部分代码省略.........
示例10: OutPacket
void WorldSession::LoadPlayerFromDBProc(QueryResultVector & results)
{
if(results.size() < 1)
{
uint8 respons = E_CHAR_LOGIN_NO_CHARACTER;
OutPacket(SMSG_CHARACTER_LOGIN_FAILED, 1, &respons);
return;
}
QueryResult* result = results[0].result;
if(! result)
{
Log.Error("WorldSession::LoadPlayerFromDBProc", "Player login query failed!");
uint8 respons = E_CHAR_LOGIN_NO_CHARACTER;
OutPacket(SMSG_CHARACTER_LOGIN_FAILED, 1, &respons);
return;
}
Field* fields = result->Fetch();
uint64 playerGuid = fields[0].GetUInt64();
uint8 _class = fields[1].GetUInt8();
Player* plr = NULL;
switch(_class)
{
case WARRIOR:
plr = new Warrior(playerGuid);
break;
case PALADIN:
plr = new Paladin(playerGuid);
break;
case HUNTER:
plr = new Hunter(playerGuid);
break;
case ROGUE:
plr = new Rogue(playerGuid);
break;
case PRIEST:
plr = new Priest(playerGuid);
break;
case DEATHKNIGHT:
plr = new DeathKnight(playerGuid);
break;
case SHAMAN:
plr = new Shaman(playerGuid);
break;
case MAGE:
plr = new Mage(playerGuid);
break;
case WARLOCK:
plr = new Warlock(playerGuid);
break;
case DRUID:
plr = new Druid(playerGuid);
break;
}
if(plr == NULL)
{
Log.Error("WorldSession::LoadPlayerFromDBProc", "Class %u unknown!", _class);
uint8 respons = E_CHAR_LOGIN_NO_CHARACTER;
OutPacket(SMSG_CHARACTER_LOGIN_FAILED, 1, &respons);
return;
}
plr->SetSession(this);
m_bIsWLevelSet = false;
Log.Debug("WorldSession", "Async loading player %u", (uint32)playerGuid);
m_loggingInPlayer = plr;
plr->LoadFromDB((uint32)playerGuid);
}
示例11: GUID_LOPART
void WorldSession::HandleCharCustomize(WorldPacket& recv_data)
{
uint64 guid;
std::string newname;
recv_data >> guid;
recv_data >> newname;
uint8 gender, skin, face, hairStyle, hairColor, facialHair;
recv_data >> gender >> skin >> hairColor >> hairStyle >> facialHair >> face;
QueryResult *result = CharacterDatabase.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid));
if (!result)
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(CHAR_CREATE_ERROR);
SendPacket( &data );
return;
}
Field *fields = result->Fetch();
uint32 at_loginFlags = fields[0].GetUInt32();
delete result;
if (!(at_loginFlags & AT_LOGIN_CUSTOMIZE))
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(CHAR_CREATE_ERROR);
SendPacket( &data );
return;
}
// prevent character rename to invalid name
if (!normalizePlayerName(newname))
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(CHAR_NAME_NO_NAME);
SendPacket( &data );
return;
}
uint8 res = ObjectMgr::CheckPlayerName(newname,true);
if (res != CHAR_NAME_SUCCESS)
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(res);
SendPacket( &data );
return;
}
// check name limitations
if (GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(newname))
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(CHAR_NAME_RESERVED);
SendPacket( &data );
return;
}
// character with this name already exist
if (uint64 newguid = objmgr.GetPlayerGUIDByName(newname))
{
if (newguid != guid)
{
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
data << uint8(CHAR_CREATE_NAME_IN_USE);
SendPacket( &data );
return;
}
}
CharacterDatabase.escape_string(newname);
Player::Customize(guid, gender, skin, face, hairStyle, hairColor, facialHair);
CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_CUSTOMIZE), GUID_LOPART(guid));
CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", GUID_LOPART(guid));
std::string IP_str = GetRemoteAddress();
sLog.outChar("Account: %d (IP: %s), Character guid: %u Customized to: %s", GetAccountId(), IP_str.c_str(), GUID_LOPART(guid), newname.c_str());
WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1+8+(newname.size()+1)+6);
data << uint8(RESPONSE_SUCCESS);
data << uint64(guid);
data << newname;
data << uint8(gender);
data << uint8(skin);
data << uint8(face);
data << uint8(hairStyle);
data << uint8(hairColor);
data << uint8(facialHair);
SendPacket(&data);
}
示例12: DeleteCharacter
uint8 WorldSession::DeleteCharacter(uint32 guid)
{
PlayerInfo* inf = objmgr.GetPlayerInfo(guid);
if(inf != NULL && inf->m_loggedInPlayer == NULL)
{
QueryResult* result = CharacterDatabase.Query("SELECT name FROM characters WHERE guid = %u AND acct = %u", (uint32)guid, _accountId);
if(!result)
return E_CHAR_DELETE_FAILED;
string name = result->Fetch()[0].GetString();
delete result;
if(inf->guild)
{
if(inf->guild->GetGuildLeader() == inf->guid)
return E_CHAR_DELETE_FAILED_GUILD_LEADER;
else
inf->guild->RemoveGuildMember(inf, NULL);
}
for(int i = 0; i < NUM_CHARTER_TYPES; ++i)
{
Charter* c = objmgr.GetCharterByGuid(guid, (CharterTypes)i);
if(c != NULL)
c->RemoveSignature((uint32)guid);
}
for(int i = 0; i < NUM_ARENA_TEAM_TYPES; ++i)
{
ArenaTeam* t = objmgr.GetArenaTeamByGuid((uint32)guid, i);
if(t != NULL && t->m_leader == guid)
return E_CHAR_DELETE_FAILED_ARENA_CAPTAIN;
if(t != NULL)
t->RemoveMember(inf);
}
/*if( _socket != NULL )
sPlrLog.write("Account: %s | IP: %s >> Deleted player %s", GetAccountName().c_str(), GetSocket()->GetRemoteIP().c_str(), name.c_str());*/
sPlrLog.writefromsession(this, "deleted character %s (GUID: %u)", name.c_str(), (uint32)guid);
CharacterDatabase.WaitExecute("DELETE FROM characters WHERE guid = %u", (uint32)guid);
Corpse* c = objmgr.GetCorpseByOwner((uint32)guid);
if(c)
CharacterDatabase.Execute("DELETE FROM corpses WHERE guid = %u", c->GetLowGUID());
CharacterDatabase.Execute("DELETE FROM playeritems WHERE ownerguid=%u", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM gm_tickets WHERE playerguid = %u", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM playerpets WHERE ownerguid = %u", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM playerpetspells WHERE ownerguid = %u", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM tutorials WHERE playerId = %u", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM questlog WHERE player_guid = %u", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM playercooldowns WHERE player_guid = %u", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM mailbox WHERE player_guid = %u", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM social_friends WHERE character_guid = %u OR friend_guid = %u", (uint32)guid, (uint32)guid);
CharacterDatabase.Execute("DELETE FROM social_ignores WHERE character_guid = %u OR ignore_guid = %u", (uint32)guid, (uint32)guid);
CharacterDatabase.Execute("DELETE FROM character_achievement WHERE guid = '%u' AND achievement NOT IN (457, 467, 466, 465, 464, 463, 462, 461, 460, 459, 458, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 1413, 1415, 1414, 1416, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1427, 1463, 1400, 456, 1402)", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM character_achievement_progress WHERE guid = '%u'", (uint32)guid);
CharacterDatabase.Execute("DELETE FROM playerspells WHERE GUID = '%u'", guid);
CharacterDatabase.Execute("DELETE FROM playerdeletedspells WHERE GUID = '%u'", guid);
CharacterDatabase.Execute("DELETE FROM playerreputations WHERE guid = '%u'", guid);
CharacterDatabase.Execute("DELETE FROM playerskills WHERE GUID = '%u'", guid);
/* remove player info */
objmgr.DeletePlayerInfo((uint32)guid);
return E_CHAR_DELETE_SUCCESS;
}
return E_CHAR_DELETE_FAILED;
}
示例13: CHECK_PACKET_SIZE
void WorldSession::HandleCharCreateOpcode(WorldPacket & recv_data)
{
CHECK_PACKET_SIZE(recv_data, 10);
std::string name;
uint8 race, class_;
recv_data >> name >> race >> class_;
recv_data.rpos(0);
LoginErrorCode res = VerifyName(name.c_str(), name.length());
if(res != E_CHAR_NAME_SUCCESS)
{
OutPacket(SMSG_CHAR_CREATE, 1, &res);
return;
}
res = g_characterNameFilter->Parse(name, false) ? E_CHAR_NAME_PROFANE : E_CHAR_NAME_SUCCESS;
if(res != E_CHAR_NAME_SUCCESS)
{
OutPacket(SMSG_CHAR_CREATE, 1, &res);
return;
}
res = objmgr.GetPlayerInfoByName(name.c_str()) == NULL ? E_CHAR_CREATE_SUCCESS : E_CHAR_CREATE_NAME_IN_USE;
if(res != E_CHAR_CREATE_SUCCESS)
{
OutPacket(SMSG_CHAR_CREATE, 1, &res);
return;
}
res = sHookInterface.OnNewCharacter(race, class_, this, name.c_str()) ? E_CHAR_CREATE_SUCCESS : E_CHAR_CREATE_ERROR;
if(res != E_CHAR_CREATE_SUCCESS)
{
OutPacket(SMSG_CHAR_CREATE, 1, &res);
return;
}
QueryResult* result = CharacterDatabase.Query("SELECT COUNT(*) FROM banned_names WHERE name = '%s'", CharacterDatabase.EscapeString(name).c_str());
if(result)
{
if(result->Fetch()[0].GetUInt32() > 0)
{
// That name is banned!
OutPacket(SMSG_CHAR_CREATE, 1, CHAR_NAME_PROFANE);
delete result;
return;
}
delete result;
}
// Check if player got Death Knight already on this realm.
if(Config.OptionalConfig.GetBoolDefault("ClassOptions" , "DeathKnightLimit" , true) && has_dk
&& (class_ == DEATHKNIGHT))
{
OutPacket(SMSG_CHAR_CREATE, 1, CHAR_CREATE_UNIQUE_CLASS_LIMIT);
return;
}
// loading characters
// Check the number of characters, so we can't make over 10.
// They're able to manage to create >10 sometimes, not exactly sure how ..
result = CharacterDatabase.Query("SELECT COUNT(*) FROM characters WHERE acct = %u", GetAccountId());
if(result)
{
if(result->Fetch()[0].GetUInt32() >= 10)
{
// We can't make any more characters.
OutPacket(SMSG_CHAR_CREATE, 1, CHAR_CREATE_SERVER_LIMIT);
delete result;
return;
}
delete result;
}
Player* pNewChar = objmgr.CreatePlayer(class_);
pNewChar->SetSession(this);
if(!pNewChar->Create(recv_data))
{
// failed.
pNewChar->ok_to_remove = true;
delete pNewChar;
OutPacket(SMSG_CHAR_CREATE, 1, CHAR_CREATE_FAILED);
return;
}
//Same Faction limitation only applies to PVP and RPPVP realms :)
uint32 realmType = sLogonCommHandler.GetRealmType();
if(!HasGMPermissions() && realmType == REALMTYPE_PVP && _side >= 0 && !sWorld.crossover_chars) // ceberwow fixed bug
{
if((pNewChar->IsTeamAlliance() && (_side == 1)) || (pNewChar->IsTeamHorde() && (_side == 0)))
{
pNewChar->ok_to_remove = true;
delete pNewChar;
OutPacket(SMSG_CHAR_CREATE, 1, CHAR_CREATE_PVP_TEAMS_VIOLATION);
return;
}
}
//.........这里部分代码省略.........
示例14: getMSTime
void WorldSession::CharacterEnumProc(QueryResult* result)
{
struct player_item
{
uint32 displayid;
uint8 invtype;
uint32 enchantment; // added in 2.4
};
uint32 start_time = getMSTime();
player_item items[23];
int8 slot;
uint32 i;
ItemPrototype* proto;
QueryResult* res;
CreatureInfo* info = NULL;
uint8 race;
has_dk = false;
_side = -1; // side should be set on every enumeration for safety
uint32 numchar;
if(result)
numchar = result->GetRowCount();
else
numchar = 0;
// should be more than enough.. 200 bytes per char..
WorldPacket data(SMSG_CHAR_ENUM, 1 + numchar * 200);
// parse m_characters and build a mighty packet of
// characters to send to the client.
data << uint8(numchar);
if(result)
{
uint64 guid;
uint8 Class;
uint32 bytes2;
uint32 flags;
uint32 banned;
Field* fields;
uint32 petLevel = 0;
do
{
fields = result->Fetch();
guid = fields[0].GetUInt64();
bytes2 = fields[6].GetUInt32();
Class = fields[3].GetUInt8();
flags = fields[17].GetUInt32();
race = fields[2].GetUInt8();
if(_side < 0)
{
// work out the side
static uint8 sides[RACE_DRAENEI + 1] = {0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0};
_side = sides[race];
}
// Death Knight starting information
// Note: To change what level is required to make a dk change the >= 55 to something.
// For example >=80 would require a level 80 to create a DK
has_level_55_char = has_level_55_char || (fields[1].GetUInt8() >= 55);
has_dk = has_dk || (Class == 6);
/* build character enum, w0000t :p */
data << uint64(guid); //guid
data << fields[7].GetString(); //name
data << uint8(race); //race
data << uint8(Class); //class
data << uint8(fields[4].GetUInt8()); //gender
data << uint32(fields[5].GetUInt32()); //PLAYER_BYTES
data << uint8(bytes2 & 0xFF); //facial hair
data << uint8(fields[1].GetUInt8()); //Level
data << uint32(fields[12].GetUInt32()); //zoneid
data << uint32(fields[11].GetUInt32()); //Mapid
data << float(fields[8].GetFloat()); //X
data << float(fields[9].GetFloat()); //Y
data << float(fields[10].GetFloat()); //Z
data << uint32(fields[18].GetUInt32()); //GuildID
banned = fields[13].GetUInt32();
uint32 char_flags = 0;
if(banned && (banned < 10 || banned > (uint32)UNIXTIME))
char_flags |= 0x01000000; //Character is banned
if(fields[15].GetUInt32() != 0)
char_flags |= 0x00002000; //Character is dead
if(flags & PLAYER_FLAG_NOHELM)
char_flags |= 0x00000400; //Helm not displayed
if(flags & PLAYER_FLAG_NOCLOAK)
char_flags |= 0x00000800; //Cloak not displayed
if(fields[16].GetUInt32() != 0)
char_flags |= 0x00004000; //Character has to be renamed before logging in
data << uint32(char_flags);
data << uint32(0); //Character recustomization flags
data << uint8(0); //Unknown 3.2.0
//.........这里部分代码省略.........
示例15: 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->outError(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 spell specialization definitions. DB table `skill_extra_item_template` is empty.");
return;
}
uint32 count = 0;
do
{
Field* fields = result->Fetch();
uint32 spellId = fields[0].GetUInt32();
if (!sSpellMgr->GetSpellInfo(spellId))
{
sLog->outError(LOG_FILTER_SQL, "Skill specialization %u has non-existent spell id in `skill_extra_item_template`!", spellId);
continue;
}
uint32 requiredSpecialization = fields[1].GetUInt32();
if (!sSpellMgr->GetSpellInfo(requiredSpecialization))
{
sLog->outError(LOG_FILTER_SQL, "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(LOG_FILTER_SQL, "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(LOG_FILTER_SQL, "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->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u spell specialization definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}