本文整理汇总了C++中PreparedStatement::setString方法的典型用法代码示例。如果您正苦于以下问题:C++ PreparedStatement::setString方法的具体用法?C++ PreparedStatement::setString怎么用?C++ PreparedStatement::setString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement::setString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandlePetitionRenameOpcode
void WorldSession::HandlePetitionRenameOpcode(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "Received opcode CMSG_PETITION_RENAME");
ObjectGuid petitionGuid;
uint32 type;
uint8 nameLen;
std::string newName;
nameLen = recvData.ReadBits(7);
recvData.ReadGuidMask(petitionGuid, 7, 4, 6, 2, 0, 5, 3, 1);
recvData.ReadGuidBytes(petitionGuid, 4, 1, 7);
newName = recvData.ReadString(nameLen);
recvData.ReadGuidBytes(petitionGuid, 0, 3, 2, 6, 5);
Item* item = _player->GetItemByGuid(petitionGuid);
if (!item)
return;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_TYPE);
stmt->setUInt32(0, GUID_LOPART(petitionGuid));
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
Field* fields = result->Fetch();
type = fields[0].GetUInt8();
}
else
{
TC_LOG_DEBUG("network", "CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionGuid));
return;
}
if (sGuildMgr->GetGuildByName(newName))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, newName);
return;
}
if (sObjectMgr->IsReservedName(newName) || !ObjectMgr::IsValidCharterName(newName))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, newName);
return;
}
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_PETITION_NAME);
stmt->setString(0, newName);
stmt->setUInt32(1, GUID_LOPART(petitionGuid));
CharacterDatabase.Execute(stmt);
TC_LOG_DEBUG("network", "Petition (GUID: %u) renamed to '%s'", GUID_LOPART(petitionGuid), newName.c_str());
WorldPacket data(SMSG_PETITION_RENAME_RESULT, (9 + 1 + newName.size()));
data.WriteBits(newName.length(), 7);
data.WriteGuidMask(petitionGuid, 0, 3, 4, 2, 6, 5, 7, 1);
data.WriteGuidBytes(petitionGuid, 4, 3, 6, 0, 5, 2, 1, 7);
data.WriteString(newName);
SendPacket(&data);
}
示例2: LoadDump
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: HandlePetRename
void WorldSession::HandlePetRename(WorldPacket & recvData)
{
;//sLog->outDetail("HandlePetRename. CMSG_PET_RENAME");
uint64 petguid;
uint8 isdeclined;
std::string name;
DeclinedName declinedname;
recvData >> petguid;
recvData >> name;
recvData >> isdeclined;
Pet* pet = ObjectAccessor::FindPet(petguid);
// check it!
if (!pet || !pet->IsPet() || ((Pet*)pet)->getPetType()!= HUNTER_PET ||
!pet->HasByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED) ||
pet->GetOwnerGUID() != _player->GetGUID() || !pet->GetCharmInfo())
return;
PetNameInvalidReason res = ObjectMgr::CheckPetName(name);
if (res != PET_NAME_SUCCESS)
{
SendPetNameInvalid(res, name, NULL);
return;
}
if (sObjectMgr->IsReservedName(name))
{
SendPetNameInvalid(PET_NAME_RESERVED, name, NULL);
return;
}
pet->SetName(name);
Unit* owner = pet->GetOwner();
if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup())
owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_NAME);
pet->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
if (isdeclined)
{
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
{
recvData >> declinedname.name[i];
}
std::wstring wname;
Utf8toWStr(name, wname);
if (!ObjectMgr::CheckDeclinedNames(wname, declinedname))
{
SendPetNameInvalid(PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME, name, &declinedname);
return;
}
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
if (isdeclined)
{
if (sWorld->getBoolConfig(CONFIG_DECLINED_NAMES_USED))
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_PET_DECLINEDNAME);
stmt->setUInt32(0, pet->GetCharmInfo()->GetPetNumber());
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_CHAR_PET_DECLINEDNAME);
stmt->setUInt32(0, _player->GetGUIDLow());
for (uint8 i = 0; i < 5; i++)
stmt->setString(i+1, declinedname.name[i]);
trans->Append(stmt);
}
}
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_PET_NAME);
stmt->setString(0, name);
stmt->setUInt32(1, _player->GetGUIDLow());
stmt->setUInt32(2, pet->GetCharmInfo()->GetPetNumber());
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);
pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped
}
示例4: HandlePetitionBuyOpcode
//.........这里部分代码省略.........
}
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_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, name);
return;
}
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, 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_CANT_FIND_ITEM, NULL, charterid, 0);
return;
}
if (!_player->HasEnoughMoney(cost))
{ //player hasn't got enough money
_player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, 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
Petition const* petition = sPetitionMgr->GetPetitionByOwnerWithType(_player->GetGUIDLow(), type);
;//sLog->outDebug(LOG_FILTER_NETWORKIO, "Invalid petition GUIDs: %s", ssInvalidPetitionGUIDs.str().c_str());
CharacterDatabase.EscapeString(name);
SQLTransaction trans = CharacterDatabase.BeginTransaction();
if (petition)
{
trans->PAppend("DELETE FROM petition WHERE petitionguid = %u", petition->petitionGuid);
trans->PAppend("DELETE FROM petition_sign WHERE petitionguid = %u", petition->petitionGuid);
// xinef: clear petition store
sPetitionMgr->RemovePetition(petition->petitionGuid);
}
// xinef: petition pointer is invalid from now on
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PETITION);
stmt->setUInt32(0, _player->GetGUIDLow());
stmt->setUInt32(1, charter->GetGUIDLow());
stmt->setString(2, name);
stmt->setUInt8(3, uint8(type));
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);
// xinef: fill petition store
sPetitionMgr->AddPetition(charter->GetGUIDLow(), _player->GetGUIDLow(), name, uint8(type));
}
示例5: 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
wpGuid = target->GetGUIDLow();
// User did select a visual waypoint?
// Check the creature
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_WPGUID);
stmt->setUInt32(0, wpGuid);
PreparedQueryResult result = WorldDatabase.Query(stmt);
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
std::string maxDiff = "0.01";
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_POS);
stmt->setFloat(0, target->GetPositionX());
stmt->setString(1, maxDiff);
stmt->setFloat(2, target->GetPositionY());
stmt->setString(3, maxDiff);
stmt->setFloat(4, target->GetPositionZ());
stmt->setString(5, maxDiff);
PreparedQueryResult result = WorldDatabase.Query(stmt);
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")
{
handler->PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
if (wpGuid != 0)
//.........这里部分代码省略.........
示例6: HandleAddDisables
//.........这里部分代码省略.........
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
disableTypeStr = "quest";
break;
}
case DISABLE_TYPE_MAP:
{
if (!sMapStore.LookupEntry(entry))
{
handler->PSendSysMessage(LANG_COMMAND_NOMAPFOUND);
handler->SetSentErrorMessage(true);
return false;
}
disableTypeStr = "map";
break;
}
case DISABLE_TYPE_BATTLEGROUND:
{
if (!sBattlemasterListStore.LookupEntry(entry))
{
handler->PSendSysMessage(LANG_COMMAND_NO_BATTLEGROUND_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
disableTypeStr = "battleground";
break;
}
case DISABLE_TYPE_ACHIEVEMENT_CRITERIA:
{
if (!sAchievementMgr->GetAchievementCriteria(entry))
{
handler->PSendSysMessage(LANG_COMMAND_NO_ACHIEVEMENT_CRITERIA_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
disableTypeStr = "achievement criteria";
break;
}
case DISABLE_TYPE_OUTDOORPVP:
{
if (entry > MAX_OUTDOORPVP_TYPES)
{
handler->PSendSysMessage(LANG_COMMAND_NO_OUTDOOR_PVP_FORUND);
handler->SetSentErrorMessage(true);
return false;
}
disableTypeStr = "outdoorpvp";
break;
}
case DISABLE_TYPE_VMAP:
{
if (!sMapStore.LookupEntry(entry))
{
handler->PSendSysMessage(LANG_COMMAND_NOMAPFOUND);
handler->SetSentErrorMessage(true);
return false;
}
disableTypeStr = "vmap";
break;
}
case DISABLE_TYPE_MMAP:
{
if (!sMapStore.LookupEntry(entry))
{
handler->PSendSysMessage(LANG_COMMAND_NOMAPFOUND);
handler->SetSentErrorMessage(true);
return false;
}
disableTypeStr = "mmap";
break;
}
default:
break;
}
PreparedStatement* stmt = NULL;
stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_DISABLES);
stmt->setUInt32(0, entry);
stmt->setUInt8(1, disableType);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (result)
{
handler->PSendSysMessage("This %s (Id: %u) is already disabled.", disableTypeStr.c_str(), entry);
handler->SetSentErrorMessage(true);
return false;
}
stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_DISABLES);
stmt->setUInt32(0, entry);
stmt->setUInt8(1, disableType);
stmt->setUInt16(2, flags);
stmt->setString(3, disableComment);
WorldDatabase.Execute(stmt);
handler->PSendSysMessage("Add Disabled %s (Id: %u) for reason %s", disableTypeStr.c_str(), entry, disableComment.c_str());
return true;
}
示例7: SaveToDB
void Item::SaveToDB(SQLTransaction& trans)
{
bool isInTransaction = !(trans.null());
if (!isInTransaction)
trans = CharacterDatabase.BeginTransaction();
uint32 guid = GetGUIDLow();
switch (uState)
{
case ITEM_NEW:
case ITEM_CHANGED:
{
uint8 index = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(uState == ITEM_NEW ? CHAR_REP_ITEM_INSTANCE : CHAR_UPD_ITEM_INSTANCE);
stmt->setUInt32( index, GetEntry());
stmt->setUInt32(++index, GUID_LOPART(GetOwnerGUID()));
stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_CREATOR)));
stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_GIFTCREATOR)));
stmt->setUInt32(++index, GetCount());
stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_DURATION));
std::ostringstream ssSpells;
for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
ssSpells << GetSpellCharges(i) << ' ';
stmt->setString(++index, ssSpells.str());
stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_FLAGS));
std::ostringstream ssEnchants;
for (uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i)
{
ssEnchants << GetEnchantmentId(EnchantmentSlot(i)) << ' ';
ssEnchants << GetEnchantmentDuration(EnchantmentSlot(i)) << ' ';
ssEnchants << GetEnchantmentCharges(EnchantmentSlot(i)) << ' ';
}
stmt->setString(++index, ssEnchants.str());
stmt->setInt16 (++index, GetItemRandomPropertyId());
stmt->setUInt16(++index, GetUInt32Value(ITEM_FIELD_DURABILITY));
stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME));
stmt->setString(++index, m_text);
stmt->setUInt32(++index, guid);
trans->Append(stmt);
if ((uState == ITEM_CHANGED) && HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GIFT_OWNER);
stmt->setUInt32(0, GUID_LOPART(GetOwnerGUID()));
stmt->setUInt32(1, guid);
trans->Append(stmt);
}
break;
}
case ITEM_REMOVED:
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE);
stmt->setUInt32(0, guid);
trans->Append(stmt);
if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT);
stmt->setUInt32(0, guid);
trans->Append(stmt);
}
if (!isInTransaction)
CharacterDatabase.CommitTransaction(trans);
// Delete the items if this is a container
if (!loot.isLooted())
ItemContainerDeleteLootMoneyAndLootItemsFromDB();
delete this;
return;
}
case ITEM_UNCHANGED:
break;
}
SetState(ITEM_UNCHANGED);
if (!isInTransaction)
CharacterDatabase.CommitTransaction(trans);
}
示例8: _HandleRealmList
// Realm List command handler
bool AuthSocket::_HandleRealmList()
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "Entering _HandleRealmList");
#endif
if (socket().recv_len() < 5)
return false;
socket().recv_skip(5);
// Get the user id (else close the connection)
// No SQL injection (prepared statement)
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_ID_BY_NAME);
stmt->setString(0, _login);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
{
sLog->outError("'%s:%d' [ERROR] user %s tried to login but we cannot find him in the database.", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
socket().shutdown();
return false;
}
Field* fields = result->Fetch();
uint32 id = fields[0].GetUInt32();
// Update realm list if need
sRealmList->UpdateIfNeed();
ACE_INET_Addr clientAddr;
socket().peer().get_remote_addr(clientAddr);
// Circle through realms in the RealmList and construct the return packet (including # of user characters in each realm)
ByteBuffer pkt;
size_t RealmListSize = 0;
for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i)
{
const Realm &realm = i->second;
// don't work with realms which not compatible with the client
bool okBuild = ((_expversion & POST_BC_EXP_FLAG) && realm.gamebuild == _build) || ((_expversion & PRE_BC_EXP_FLAG) && !AuthHelper::IsPreBCAcceptedClientBuild(realm.gamebuild));
// No SQL injection. id of realm is controlled by the database.
uint32 flag = realm.flag;
RealmBuildInfo const* buildInfo = AuthHelper::GetBuildInfo(realm.gamebuild);
if (!okBuild)
{
if (!buildInfo)
continue;
flag |= REALM_FLAG_OFFLINE | REALM_FLAG_SPECIFYBUILD; // tell the client what build the realm is for
}
if (!buildInfo)
flag &= ~REALM_FLAG_SPECIFYBUILD;
std::string name = i->first;
if (_expversion & PRE_BC_EXP_FLAG && flag & REALM_FLAG_SPECIFYBUILD)
{
std::ostringstream ss;
ss << name << " (" << buildInfo->MajorVersion << '.' << buildInfo->MinorVersion << '.' << buildInfo->BugfixVersion << ')';
name = ss.str();
}
// We don't need the port number from which client connects with but the realm's port
clientAddr.set_port_number(realm.ExternalAddress.get_port_number());
uint8 lock = (realm.allowedSecurityLevel > _accountSecurityLevel) ? 1 : 0;
uint8 AmountOfCharacters = 0;
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_NUM_CHARS_ON_REALM);
stmt->setUInt32(0, realm.m_ID);
stmt->setUInt32(1, id);
result = LoginDatabase.Query(stmt);
if (result)
AmountOfCharacters = (*result)[0].GetUInt8();
pkt << realm.icon; // realm type
if (_expversion & POST_BC_EXP_FLAG) // only 2.x and 3.x clients
pkt << lock; // if 1, then realm locked
pkt << uint8(flag); // RealmFlags
pkt << name;
pkt << GetAddressString(GetAddressForClient(realm, clientAddr));
pkt << realm.populationLevel;
pkt << AmountOfCharacters;
pkt << realm.timezone; // realm category
if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
pkt << uint8(realm.m_ID);
else
pkt << uint8(0x0); // 1.12.1 and 1.12.2 clients
if (_expversion & POST_BC_EXP_FLAG && flag & REALM_FLAG_SPECIFYBUILD)
{
pkt << uint8(buildInfo->MajorVersion);
pkt << uint8(buildInfo->MinorVersion);
pkt << uint8(buildInfo->BugfixVersion);
pkt << uint16(buildInfo->Build);
}
++RealmListSize;
//.........这里部分代码省略.........
示例9: _HandleRealmList
// Realm List command handler
bool AuthSocket::_HandleRealmList()
{
sLog->outDebug(LOG_FILTER_AUTHSERVER, "Entering _HandleRealmList");
if (socket().recv_len() < 5)
return false;
socket().recv_skip(5);
// Get the user id (else close the connection)
// No SQL injection (prepared statement)
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_ID_BY_NAME);
stmt->setString(0, _login);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
{
sLog->outError(LOG_FILTER_AUTHSERVER, "'%s:%d' [ERROR] user %s tried to login but we cannot find him in the database.", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
socket().shutdown();
return false;
}
Field* fields = result->Fetch();
uint32 id = fields[0].GetUInt32();
// Update realm list if need
sRealmList->UpdateIfNeed();
// Circle through realms in the RealmList and construct the return packet (including # of user characters in each realm)
ByteBuffer pkt;
size_t RealmListSize = 0;
for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i)
{
// don't work with realms which not compatible with the client
if ((_expversion & POST_BC_EXP_FLAG) && i->second.gamebuild != _build)
continue;
else if ((_expversion & PRE_BC_EXP_FLAG) && !AuthHelper::IsPreBCAcceptedClientBuild(i->second.gamebuild))
continue;
uint8 AmountOfCharacters;
// No SQL injection. id of realm is controlled by the database.
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_NUM_CHARS_ON_REALM);
stmt->setUInt32(0, i->second.m_ID);
stmt->setUInt32(1, id);
result = LoginDatabase.Query(stmt);
if (result)
AmountOfCharacters = (*result)[0].GetUInt8();
else
AmountOfCharacters = 0;
uint8 lock = (i->second.allowedSecurityLevel > _accountSecurityLevel) ? 1 : 0;
pkt << i->second.icon; // realm type
if ( _expversion & POST_BC_EXP_FLAG ) // only 2.x and 3.x clients
pkt << lock; // if 1, then realm locked
pkt << uint8(i->second.flag); // RealmFlags
pkt << i->first;
pkt << i->second.address;
pkt << i->second.populationLevel;
pkt << AmountOfCharacters;
pkt << i->second.timezone; // realm category
if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
pkt << (uint8)0x2C; // unk, may be realm number/id?
else
pkt << (uint8)0x0; // 1.12.1 and 1.12.2 clients
if (i->second.flag & REALM_FLAG_SPECIFYBUILD)
{
// TODO: Make this customizable
pkt << uint8(3);
pkt << uint8(3);
pkt << uint8(5);
pkt << uint16(12340);
}
++RealmListSize;
}
if ( _expversion & POST_BC_EXP_FLAG ) // 2.x and 3.x clients
{
pkt << (uint8)0x10;
pkt << (uint8)0x00;
}
else // 1.12.1 and 1.12.2 clients
{
pkt << (uint8)0x00;
pkt << (uint8)0x02;
}
// make a ByteBuffer which stores the RealmList's size
ByteBuffer RealmListSizeBuffer;
RealmListSizeBuffer << (uint32)0;
if (_expversion & POST_BC_EXP_FLAG) // only 2.x and 3.x clients
RealmListSizeBuffer << (uint16)RealmListSize;
else
RealmListSizeBuffer << (uint32)RealmListSize;
ByteBuffer hdr;
hdr << (uint8) REALM_LIST;
//.........这里部分代码省略.........
示例10: _HandleLogonChallenge
// Logon Challenge command handler
bool AuthSocket::_HandleLogonChallenge()
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "Entering _HandleLogonChallenge");
#endif
if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
return false;
///- Session is closed unless overriden
_status = STATUS_CLOSED;
// pussywizard: logon flood protection:
{
TRINITY_GUARD(ACE_Thread_Mutex, LastLoginAttemptMutex);
std::string ipaddr = socket().getRemoteAddress();
uint32 currTime = time(NULL);
std::map<std::string, uint32>::iterator itr = LastLoginAttemptTimeForIP.find(ipaddr);
if (itr != LastLoginAttemptTimeForIP.end() && itr->second >= currTime)
{
ByteBuffer pkt;
pkt << uint8(AUTH_LOGON_CHALLENGE);
pkt << uint8(0x00);
pkt << uint8(WOW_FAIL_UNKNOWN_ACCOUNT);
socket().send((char const*)pkt.contents(), pkt.size());
return true;
}
if (LastLoginAttemptCleanTime+60 < currTime)
{
LastLoginAttemptTimeForIP.clear();
LastLoginAttemptCleanTime = currTime;
}
else
LastLoginAttemptTimeForIP[ipaddr] = currTime;
}
// Read the first 4 bytes (header) to get the length of the remaining of the packet
std::vector<uint8> buf;
buf.resize(4);
socket().recv((char *)&buf[0], 4);
EndianConvertPtr<uint16>(&buf[0]);
uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "[AuthChallenge] got header, body is %#04x bytes", remaining);
#endif
if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (socket().recv_len() < remaining))
return false;
//No big fear of memory outage (size is int16, i.e. < 65536)
buf.resize(remaining + buf.size() + 1);
buf[buf.size() - 1] = 0;
sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[0];
// Read the remaining of the packet
socket().recv((char *)&buf[4], remaining);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "[AuthChallenge] got full packet, %#04x bytes", ch->size);
sLog->outDebug(LOG_FILTER_NETWORKIO, "[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I);
#endif
// BigEndian code, nop in little endian case
// size already converted
EndianConvertPtr<uint32>(&ch->gamename[0]);
EndianConvert(ch->build);
EndianConvertPtr<uint32>(&ch->platform[0]);
EndianConvertPtr<uint32>(&ch->os[0]);
EndianConvertPtr<uint32>(&ch->country[0]);
EndianConvert(ch->timezone_bias);
EndianConvert(ch->ip);
ByteBuffer pkt;
_login = (const char*)ch->I;
_build = ch->build;
_expversion = uint8(AuthHelper::IsPostBCAcceptedClientBuild(_build) ? POST_BC_EXP_FLAG : (AuthHelper::IsPreBCAcceptedClientBuild(_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG));
_os = (const char*)ch->os;
if (_os.size() > 4)
return false;
// Restore string order as its byte order is reversed
std::reverse(_os.begin(), _os.end());
pkt << uint8(AUTH_LOGON_CHALLENGE);
pkt << uint8(0x00);
// Verify that this IP is not in the ip_banned table
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS));
std::string const& ip_address = socket().getRemoteAddress();
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED);
stmt->setString(0, ip_address);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (result)
{
pkt << uint8(WOW_FAIL_BANNED);
//.........这里部分代码省略.........
示例11: _HandleReconnectChallenge
// Reconnect Challenge command handler
bool AuthSocket::_HandleReconnectChallenge()
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "Entering _HandleReconnectChallenge");
#endif
if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
return false;
// Read the first 4 bytes (header) to get the length of the remaining of the packet
std::vector<uint8> buf;
buf.resize(4);
socket().recv((char *)&buf[0], 4);
EndianConvertPtr<uint16>(&buf[0]);
uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "[ReconnectChallenge] got header, body is %#04x bytes", remaining);
#endif
if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (socket().recv_len() < remaining))
return false;
///- Session is closed unless overriden
_status = STATUS_CLOSED;
// No big fear of memory outage (size is int16, i.e. < 65536)
buf.resize(remaining + buf.size() + 1);
buf[buf.size() - 1] = 0;
sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[0];
// Read the remaining of the packet
socket().recv((char *)&buf[4], remaining);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
sLog->outDebug(LOG_FILTER_NETWORKIO, "[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);
#endif
_login = (const char*)ch->I;
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_SESSIONKEY);
stmt->setString(0, _login);
PreparedQueryResult result = LoginDatabase.Query(stmt);
// Stop if the account is not found
if (!result)
{
sLog->outError("'%s:%d' [ERROR] user %s tried to login and we cannot find his session key in the database.", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
socket().shutdown();
return false;
}
// Reinitialize build, expansion and the account securitylevel
_build = ch->build;
_expversion = uint8(AuthHelper::IsPostBCAcceptedClientBuild(_build) ? POST_BC_EXP_FLAG : (AuthHelper::IsPreBCAcceptedClientBuild(_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG));
_os = (const char*)ch->os;
if (_os.size() > 4)
return false;
// Restore string order as its byte order is reversed
std::reverse(_os.begin(), _os.end());
Field* fields = result->Fetch();
uint8 secLevel = fields[2].GetUInt8();
_accountSecurityLevel = secLevel <= SEC_ADMINISTRATOR ? AccountTypes(secLevel) : SEC_ADMINISTRATOR;
K.SetHexStr ((*result)[0].GetCString());
///- All good, await client's proof
_status = STATUS_RECON_PROOF;
// Sending response
ByteBuffer pkt;
pkt << uint8(AUTH_RECONNECT_CHALLENGE);
pkt << uint8(0x00);
_reconnectProof.SetRand(16 * 8);
pkt.append(_reconnectProof.AsByteArray(16).get(), 16); // 16 bytes random
pkt << uint64(0x00) << uint64(0x00); // 16 bytes zeros
socket().send((char const*)pkt.contents(), pkt.size());
return true;
}
示例12: HandleBanListIPCommand
static bool HandleBanListIPCommand(ChatHandler* handler, char const* args)
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS);
LoginDatabase.Execute(stmt);
char* filterStr = strtok((char*)args, " ");
std::string filter = filterStr ? filterStr : "";
LoginDatabase.EscapeString(filter);
PreparedQueryResult result;
if (filter.empty())
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_ALL);
result = LoginDatabase.Query(stmt);
}
else
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_BY_IP);
stmt->setString(0, filter);
result = LoginDatabase.Query(stmt);
}
if (!result)
{
handler->PSendSysMessage(LANG_BANLIST_NOIP);
return true;
}
handler->PSendSysMessage(LANG_BANLIST_MATCHINGIP);
// Chat short output
if (handler->GetSession())
{
do
{
Field* fields = result->Fetch();
handler->PSendSysMessage("%s", fields[0].GetCString());
}
while (result->NextRow());
}
// Console wide output
else
{
handler->SendSysMessage(LANG_BANLIST_IPS);
handler->SendSysMessage(" ===============================================================================");
handler->SendSysMessage(LANG_BANLIST_IPS_HEADER);
do
{
handler->SendSysMessage("-------------------------------------------------------------------------------");
Field* fields = result->Fetch();
time_t timeBan = time_t(fields[1].GetUInt32());
tm* tmBan = localtime(&timeBan);
if (fields[1].GetUInt32() == fields[2].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
fields[0].GetCString(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
fields[3].GetCString(), fields[4].GetCString());
}
else
{
time_t timeUnban = time_t(fields[2].GetUInt32());
tm* tmUnban = localtime(&timeUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
fields[0].GetCString(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
tmUnban->tm_year%100, tmUnban->tm_mon+1, tmUnban->tm_mday, tmUnban->tm_hour, tmUnban->tm_min,
fields[3].GetCString(), fields[4].GetCString());
}
}
while (result->NextRow());
handler->SendSysMessage(" ===============================================================================");
}
return true;
}
示例13: HandleBanListCharacterCommand
static bool HandleBanListCharacterCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* filterStr = strtok((char*)args, " ");
if (!filterStr)
return false;
std::string filter(filterStr);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME_FILTER);
stmt->setString(0, filter);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
{
handler->PSendSysMessage(LANG_BANLIST_NOCHARACTER);
return true;
}
handler->PSendSysMessage(LANG_BANLIST_MATCHINGCHARACTER);
// Chat short output
if (handler->GetSession())
{
do
{
Field* fields = result->Fetch();
PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANNED_NAME);
stmt2->setUInt32(0, fields[0].GetUInt32());
PreparedQueryResult banResult = CharacterDatabase.Query(stmt2);
if (banResult)
handler->PSendSysMessage("%s", (*banResult)[0].GetCString());
}
while (result->NextRow());
}
// Console wide output
else
{
handler->SendSysMessage(LANG_BANLIST_CHARACTERS);
handler->SendSysMessage(" =============================================================================== ");
handler->SendSysMessage(LANG_BANLIST_CHARACTERS_HEADER);
do
{
handler->SendSysMessage("-------------------------------------------------------------------------------");
Field* fields = result->Fetch();
std::string char_name = fields[1].GetString();
PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_SEL_BANINFO_LIST);
stmt2->setUInt32(0, fields[0].GetUInt32());
PreparedQueryResult banInfo = CharacterDatabase.Query(stmt2);
if (banInfo)
{
Field* banFields = banInfo->Fetch();
do
{
time_t timeBan = time_t(banFields[0].GetUInt32());
tm* tmBan = localtime(&timeBan);
if (banFields[0].GetUInt32() == banFields[1].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
char_name.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
banFields[2].GetCString(), banFields[3].GetCString());
}
else
{
time_t timeUnban = time_t(banFields[1].GetUInt32());
tm* tmUnban = localtime(&timeUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
char_name.c_str(), tmBan->tm_year%100, tmBan->tm_mon+1, tmBan->tm_mday, tmBan->tm_hour, tmBan->tm_min,
tmUnban->tm_year%100, tmUnban->tm_mon+1, tmUnban->tm_mday, tmUnban->tm_hour, tmUnban->tm_min,
banFields[2].GetCString(), banFields[3].GetCString());
}
}
while (banInfo->NextRow());
}
}
while (result->NextRow());
handler->SendSysMessage(" =============================================================================== ");
}
return true;
}
示例14: HandlePetitionBuyOpcode
//.........这里部分代码省略.........
// remove fake death
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
uint32 charterid = 0;
uint32 cost = 0;
uint32 type = 0;
// if tabard designer, then trying to buy a guild charter.
// do not let if already in guild.
if (_player->GetGuildId())
return;
charterid = GUILD_CHARTER;
cost = GUILD_CHARTER_COST;
type = GUILD_CHARTER_TYPE;
if (sGuildMgr->GetGuildByName(name))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, name);
return;
}
if (sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, name);
return;
}
ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(charterid);
if (!pProto)
{
_player->SendBuyError(BUY_ERR_CANT_FIND_ITEM, NULL, charterid, 0);
return;
}
if (!_player->HasEnoughMoney(uint64(cost)))
{ //player hasn't got enough money
_player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, 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;
//I think this has changed
charter->SetUInt32Value(ITEM_FIELD_ENCHANTMENT, charter->GetGUIDLow());
// ITEM_FIELD_ENCHANTMENT is guild/arenateam id
// ITEM_FIELD_ENCHANTMENT+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
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_BY_OWNER);
stmt->setUInt32(0, _player->GetGUIDLow());
stmt->setUInt8(1, type);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
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() << '\'';
//Probably DB Charter Petitions has changed too
TC_LOG_DEBUG("network", "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());
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PETITION);
stmt->setUInt32(0, _player->GetGUIDLow());
stmt->setUInt32(1, charter->GetGUIDLow());
stmt->setString(2, name);
stmt->setUInt8(3, uint8(type)); //Type no needed anymore
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);
}
示例15: HandlePetitionRenameOpcode
void WorldSession::HandlePetitionRenameOpcode(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "Received opcode MSG_PETITION_RENAME");
uint64 petitionGuid;
uint32 type;
std::string newName;
recvData >> petitionGuid; // guid
recvData >> newName; // new name
Item* item = _player->GetItemByGuid(petitionGuid);
if (!item)
return;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_TYPE);
stmt->setUInt32(0, GUID_LOPART(petitionGuid));
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
Field* fields = result->Fetch();
type = fields[0].GetUInt8();
}
else
{
TC_LOG_DEBUG("network", "CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionGuid));
return;
}
if (type == GUILD_CHARTER_TYPE)
{
if (sGuildMgr->GetGuildByName(newName))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_EXISTS_S, newName);
return;
}
if (sObjectMgr->IsReservedName(newName) || !ObjectMgr::IsValidCharterName(newName))
{
Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NAME_INVALID, newName);
return;
}
}
else
{
if (sArenaTeamMgr->GetArenaTeamByName(newName))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_EXISTS_S);
return;
}
if (sObjectMgr->IsReservedName(newName) || !ObjectMgr::IsValidCharterName(newName))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_INVALID);
return;
}
}
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_PETITION_NAME);
stmt->setString(0, newName);
stmt->setUInt32(1, GUID_LOPART(petitionGuid));
CharacterDatabase.Execute(stmt);
TC_LOG_DEBUG("network", "Petition (GUID: %u) renamed to '%s'", GUID_LOPART(petitionGuid), newName.c_str());
WorldPacket data(MSG_PETITION_RENAME, (8+newName.size()+1));
data << uint64(petitionGuid);
data << newName;
SendPacket(&data);
}