本文整理汇总了C++中PetIds类的典型用法代码示例。如果您正苦于以下问题:C++ PetIds类的具体用法?C++ PetIds怎么用?C++ PetIds使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PetIds类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fopen
DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, std::string name, uint32 guid)
{
bool nameInvalidated = false; // set when name changed or will requested changed at next login
// check character count
uint32 charcount = sAccountMgr.GetCharactersCount(account);
if (charcount >= 10)
return DUMP_TOO_MANY_CHARS;
FILE* fin = fopen(file.c_str(), "r");
if (!fin)
return DUMP_FILE_OPEN_ERROR;
QueryResult* result = NULL;
char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20];
// make sure the same guid doesn't already exist and is safe to use
bool incHighest = true;
if (guid != 0 && guid < sObjectMgr.m_CharGuids.GetNextAfterMaxUsed())
{
result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE guid = '%u'", guid);
if (result)
{
guid = sObjectMgr.m_CharGuids.GetNextAfterMaxUsed();
delete result;
}
else incHighest = false;
}
else
guid = sObjectMgr.m_CharGuids.GetNextAfterMaxUsed();
// normalize the name if specified and check if it exists
if (!normalizePlayerName(name))
name = "";
if (ObjectMgr::CheckPlayerName(name, true) == CHAR_NAME_SUCCESS)
{
CharacterDatabase.escape_string(name); // for safe, we use name only for sql quearies anyway
result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE name = '%s'", name.c_str());
if (result)
{
name = ""; // use the one from the dump
delete result;
}
}
else
name = "";
// name encoded or empty
snprintf(newguid, 20, "%u", guid);
snprintf(chraccount, 20, "%u", account);
snprintf(newpetid, 20, "%u", sObjectMgr.GeneratePetNumber());
snprintf(lastpetid, 20, "%s", "");
std::map<uint32, uint32> items;
std::map<uint32, uint32> mails;
std::map<uint32, uint32> itemTexts;
char buf[32000] = "";
typedef std::map<uint32, uint32> PetIds; // old->new petid relation
typedef PetIds::value_type PetIdsPair;
PetIds petids;
CharacterDatabase.BeginTransaction();
while (!feof(fin))
{
if (!fgets(buf, 32000, fin))
{
if (feof(fin)) break;
ROLLBACK(DUMP_FILE_BROKEN);
}
std::string line; line.assign(buf);
// skip empty strings
size_t nw_pos = line.find_first_not_of(" \t\n\r\7");
if (nw_pos == std::string::npos)
continue;
// skip NOTE
if (line.substr(nw_pos, 15) == "IMPORTANT NOTE:")
continue;
// add required_ check
if (line.substr(nw_pos, 41) == "UPDATE character_db_version SET required_")
{
if (!CharacterDatabase.Execute(line.c_str()))
ROLLBACK(DUMP_FILE_BROKEN);
continue;
}
// determine table name and load type
std::string tn = gettablename(line);
if (tn.empty())
{
sLog.outError("LoadPlayerDump: Can't extract table name from line: '%s'!", line.c_str());
ROLLBACK(DUMP_FILE_BROKEN);
}
//.........这里部分代码省略.........
示例2: fopen
DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, std::string name, uint32 guid)
{
uint32 charcount = AccountMgr::GetCharactersCount(account);
if (charcount >= 10)
return DUMP_TOO_MANY_CHARS;
FILE* fin = fopen(file.c_str(), "r");
if (!fin)
return DUMP_FILE_OPEN_ERROR;
char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20];
// make sure the same guid doesn't already exist and is safe to use
bool incHighest = true;
if (guid != 0 && guid < sObjectMgr->_hiCharGuid)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_GUID);
stmt->setUInt32(0, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
guid = sObjectMgr->_hiCharGuid; // use first free if exists
else incHighest = false;
}
else
guid = sObjectMgr->_hiCharGuid;
// normalize the name if specified and check if it exists
if (!normalizePlayerName(name))
name = "";
if (ObjectMgr::CheckPlayerName(name, true) == CHAR_NAME_SUCCESS)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME);
stmt->setString(0, name);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
name = ""; // use the one from the dump
}
else
name = "";
// name encoded or empty
snprintf(newguid, 20, "%u", guid);
snprintf(chraccount, 20, "%u", account);
snprintf(newpetid, 20, "%u", sObjectMgr->GeneratePetNumber());
snprintf(lastpetid, 20, "%s", "");
std::map<uint32, uint32> items;
std::map<uint32, uint32> mails;
char buf[32000] = "";
typedef std::map<uint32, uint32> PetIds; // old->new petid relation
typedef PetIds::value_type PetIdsPair;
PetIds petids;
uint8 gender = GENDER_NONE;
uint8 race = RACE_NONE;
uint8 playerClass = 0;
uint8 level = 1;
SQLTransaction trans = CharacterDatabase.BeginTransaction();
while (!feof(fin))
{
if (!fgets(buf, 32000, fin))
{
if (feof(fin))
break;
ROLLBACK(DUMP_FILE_BROKEN);
}
std::string line; line.assign(buf);
// skip empty strings
size_t nw_pos = line.find_first_not_of(" \t\n\r\7");
if (nw_pos == std::string::npos)
continue;
// skip logfile-side dump start notice, the important notes and dump end notices
if ((line.substr(nw_pos, 16) == "== START DUMP ==") ||
(line.substr(nw_pos, 15) == "IMPORTANT NOTE:") ||
(line.substr(nw_pos, 14) == "== END DUMP =="))
continue;
// add required_ check
/*
if (line.substr(nw_pos, 41) == "UPDATE character_db_version SET required_")
{
if (!CharacterDatabase.Execute(line.c_str()))
ROLLBACK(DUMP_FILE_BROKEN);
continue;
}
*/
// determine table name and load type
std::string tn = gettablename(line);
if (tn.empty())
//.........这里部分代码省略.........
示例3: COUNT
DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, std::string name, uint32 guid)
{
// check character count
{
QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", account);
uint8 charcount = 0;
if (result)
{
Field *fields=result->Fetch();
charcount = fields[0].GetUInt8();
delete result;
if (charcount >= 10)
return DUMP_TOO_MANY_CHARS;
}
}
FILE *fin = fopen(file.c_str(), "r");
if (!fin)
return DUMP_FILE_OPEN_ERROR;
QueryResult * result = NULL;
char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20];
// make sure the same guid doesn't already exist and is safe to use
bool incHighest = true;
if (guid != 0 && guid < objmgr.m_hiCharGuid)
{
result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE guid = '%d'", guid);
if (result)
{
guid = objmgr.m_hiCharGuid; // use first free if exists
delete result;
}
else incHighest = false;
}
else
guid = objmgr.m_hiCharGuid;
// normalize the name if specified and check if it exists
if (!normalizePlayerName(name))
name = "";
if (ObjectMgr::CheckPlayerName(name,true) == CHAR_NAME_SUCCESS)
{
CharacterDatabase.escape_string(name); // for safe, we use name only for sql quearies anyway
result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE name = '%s'", name.c_str());
if (result)
{
name = ""; // use the one from the dump
delete result;
}
}
else
name = "";
// name encoded or empty
snprintf(newguid, 20, "%d", guid);
snprintf(chraccount, 20, "%d", account);
snprintf(newpetid, 20, "%d", objmgr.GeneratePetNumber());
snprintf(lastpetid, 20, "%s", "");
std::map<uint32,uint32> items;
std::map<uint32,uint32> mails;
std::map<uint32,uint32> itemTexts;
char buf[32000] = "";
typedef std::map<uint32, uint32> PetIds; // old->new petid relation
typedef PetIds::value_type PetIdsPair;
PetIds petids;
CharacterDatabase.BeginTransaction();
while(!feof(fin))
{
if(!fgets(buf, 32000, fin))
{
if(feof(fin)) break;
ROLLBACK(DUMP_FILE_BROKEN);
}
std::string line; line.assign(buf);
// skip empty strings
size_t nw_pos = line.find_first_not_of(" \t\n\r\7");
if(nw_pos==std::string::npos)
continue;
// skip NOTE
if(line.substr(nw_pos,15)=="IMPORTANT NOTE:")
continue;
// add required_ check
if(line.substr(nw_pos,41)=="UPDATE character_db_version SET required_")
{
if(!CharacterDatabase.Execute(line.c_str()))
ROLLBACK(DUMP_FILE_BROKEN);
continue;
}
//.........这里部分代码省略.........
示例4: fopen
DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, std::string name, ObjectGuid::LowType guid)
{
uint32 charcount = AccountMgr::GetCharactersCount(account);
if (charcount >= sWorld->getIntConfig(CONFIG_CHARACTERS_PER_REALM))
return DUMP_TOO_MANY_CHARS;
FILE* fin = fopen(file.c_str(), "r");
if (!fin)
return DUMP_FILE_OPEN_ERROR;
char newguid[20], chraccount[20];
// make sure the same guid doesn't already exist and is safe to use
bool incHighest = true;
if (guid && guid < sObjectMgr->GetGenerator<HighGuid::Player>().GetNextAfterMaxUsed())
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_GUID);
stmt->setUInt64(0, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
guid = sObjectMgr->GetGenerator<HighGuid::Player>().GetNextAfterMaxUsed(); // use first free if exists
else
incHighest = false;
}
else
guid = sObjectMgr->GetGenerator<HighGuid::Player>().GetNextAfterMaxUsed();
// normalize the name if specified and check if it exists
if (!normalizePlayerName(name))
name.clear();
if (ObjectMgr::CheckPlayerName(name, sWorld->GetDefaultDbcLocale(), true) == CHAR_NAME_SUCCESS)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME);
stmt->setString(0, name);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
name.clear(); // use the one from the dump
}
else
name.clear();
// name encoded or empty
snprintf(newguid, 20, UI64FMTD, guid);
snprintf(chraccount, 20, "%u", account);
DumpGuidMap items;
DumpGuidMap mails;
char buf[32000] = "";
typedef std::map<uint32 /*old*/, uint32 /*new*/> PetIds;
PetIds petIds;
uint8 gender = GENDER_NONE;
uint8 race = RACE_NONE;
uint8 playerClass = 0;
uint8 level = 1;
ObjectGuid::LowType itemLowGuidOffset = sObjectMgr->GetGenerator<HighGuid::Item>().GetNextAfterMaxUsed();
SQLTransaction trans = CharacterDatabase.BeginTransaction();
while (!feof(fin))
{
if (!fgets(buf, 32000, fin))
{
if (feof(fin))
break;
ROLLBACK(DUMP_FILE_BROKEN);
}
std::string line; line.assign(buf);
// skip empty strings
size_t nw_pos = line.find_first_not_of(" \t\n\r\7");
if (nw_pos == std::string::npos)
continue;
// skip logfile-side dump start notice, the important notes and dump end notices
if ((line.substr(nw_pos, 16) == "== START DUMP ==") ||
(line.substr(nw_pos, 15) == "IMPORTANT NOTE:") ||
(line.substr(nw_pos, 14) == "== END DUMP =="))
continue;
// add required_ check
/*
if (line.substr(nw_pos, 41) == "UPDATE character_db_version SET required_")
{
if (!CharacterDatabase.Execute(line.c_str()))
ROLLBACK(DUMP_FILE_BROKEN);
continue;
}
*/
// determine table name and load type
std::string tn = GetTableName(line);
if (tn.empty())
//.........这里部分代码省略.........