diff options
21 files changed, 448 insertions, 131 deletions
diff --git a/src/server/game/Chat/Commands/Level2.cpp b/src/server/game/Chat/Commands/Level2.cpp index 9b13d1ce822..ff681b327a7 100755 --- a/src/server/game/Chat/Commands/Level2.cpp +++ b/src/server/game/Chat/Commands/Level2.cpp @@ -479,7 +479,7 @@ bool ChatHandler::HandleCharacterRenameCommand(const char* args) PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid)); - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_RENAME)); stmt->setUInt32(1, GUID_LOPART(targetGuid)); @@ -499,7 +499,7 @@ bool ChatHandler::HandleCharacterCustomizeCommand(const char* args) if (!extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_CUSTOMIZE)); @@ -533,7 +533,7 @@ bool ChatHandler::HandleCharacterChangeFactionCommand(const char* args) if (!extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_CHANGE_FACTION)); @@ -566,7 +566,7 @@ bool ChatHandler::HandleCharacterChangeRaceCommand(const char * args) if (!extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_CHANGE_FACTION)); diff --git a/src/server/game/Chat/Commands/Level3.cpp b/src/server/game/Chat/Commands/Level3.cpp index 9b29483bcb4..8705f6b190e 100755 --- a/src/server/game/Chat/Commands/Level3.cpp +++ b/src/server/game/Chat/Commands/Level3.cpp @@ -2585,7 +2585,7 @@ bool ChatHandler::HandleResetSpellsCommand(const char* args) } else { - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_RESET_SPELLS)); stmt->setUInt32(1, GUID_LOPART(targetGuid)); @@ -2643,7 +2643,7 @@ bool ChatHandler::HandleResetTalentsCommand(const char* args) } else if (targetGuid) { - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_NONE | AT_LOGIN_RESET_PET_TALENTS)); stmt->setUInt32(1, GUID_LOPART(targetGuid)); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 53257622e68..93df73ef928 100755 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -16507,7 +16507,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS || (AccountMgr::IsPlayerAccount(GetSession()->GetSecurity()) && sObjectMgr->IsReservedName(m_name))) { - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_RENAME)); stmt->setUInt32(1, guid); @@ -17560,7 +17560,13 @@ void Player::_LoadMailedItems(Mail* mail) if (!item->LoadFromDB(itemGuid, MAKE_NEW_GUID(fields[13].GetUInt32(), 0, HIGHGUID_PLAYER), fields, itemTemplate)) { sLog->outError("Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail->messageID, itemGuid); - CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", itemGuid); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_ITEM); + + stmt->setUInt32(0, itemGuid); + + CharacterDatabase.Execute(stmt); + item->FSetState(ITEM_REMOVED); SQLTransaction temp = SQLTransaction(NULL); @@ -17895,33 +17901,43 @@ void Player::_LoadBoundInstances(PreparedQueryResult result) // so the value read from the DB may be wrong here but only if the InstanceSave is loaded // and in that case it is not used + bool deleteInstance = false; + MapEntry const* mapEntry = sMapStore.LookupEntry(mapId); if (!mapEntry || !mapEntry->IsDungeon()) { sLog->outError("_LoadBoundInstances: player %s(%d) has bind to not existed or not dungeon map %d", GetName(), GetGUIDLow(), mapId); - CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId); - continue; + deleteInstance = true; } - - if (difficulty >= MAX_DIFFICULTY) + else if (difficulty >= MAX_DIFFICULTY) { sLog->outError("_LoadBoundInstances: player %s(%d) has bind to not existed difficulty %d instance for map %u", GetName(), GetGUIDLow(), difficulty, mapId); - CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId); - continue; + deleteInstance = true; } - - MapDifficulty const* mapDiff = GetMapDifficultyData(mapId, Difficulty(difficulty)); - if (!mapDiff) + else { - sLog->outError("_LoadBoundInstances: player %s(%d) has bind to not existed difficulty %d instance for map %u", GetName(), GetGUIDLow(), difficulty, mapId); - CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId); - continue; + MapDifficulty const* mapDiff = GetMapDifficultyData(mapId, Difficulty(difficulty)); + if (!mapDiff) + { + sLog->outError("_LoadBoundInstances: player %s(%d) has bind to not existed difficulty %d instance for map %u", GetName(), GetGUIDLow(), difficulty, mapId); + deleteInstance = true; + } + else if (!perm && group) + { + sLog->outError("_LoadBoundInstances: player %s(%d) is in group %d but has a non-permanent character bind to map %d, %d, %d", GetName(), GetGUIDLow(), GUID_LOPART(group->GetGUID()), mapId, instanceId, difficulty); + deleteInstance = true; + } } - if (!perm && group) + if (deleteInstance) { - sLog->outError("_LoadBoundInstances: player %s(%d) is in group %d but has a non-permanent character bind to map %d, %d, %d", GetName(), GetGUIDLow(), GUID_LOPART(group->GetGUID()), mapId, instanceId, difficulty); - CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INSTANCE); + + stmt->setUInt32(0, GetGUIDLow()); + stmt->setUInt32(1, instanceId); + + CharacterDatabase.Execute(stmt); + continue; } @@ -17970,7 +17986,15 @@ void Player::UnbindInstance(BoundInstancesMap::iterator &itr, Difficulty difficu if (itr != m_boundInstances[difficulty].end()) { if (!unload) - CharacterDatabase.PExecute("DELETE FROM character_instance WHERE guid = '%u' AND instance = '%u'", GetGUIDLow(), itr->second.save->GetInstanceId()); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INSTANCE); + + stmt->setUInt32(0, GetGUIDLow()); + stmt->setUInt32(1, itr->second.save->GetInstanceId()); + + CharacterDatabase.Execute(stmt); + } + itr->second.save->RemovePlayer(this); // save can become invalid m_boundInstances[difficulty].erase(itr++); } @@ -17986,11 +18010,28 @@ InstancePlayerBind* Player::BindToInstance(InstanceSave* save, bool permanent, b // update the save when the group kills a boss if (permanent != bind.perm || save != bind.save) if (!load) - CharacterDatabase.PExecute("UPDATE character_instance SET instance = '%u', permanent = '%u' WHERE guid = '%u' AND instance = '%u'", save->GetInstanceId(), permanent, GetGUIDLow(), bind.save->GetInstanceId()); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_INSTANCE); + + stmt->setUInt32(0, save->GetInstanceId()); + stmt->setBool(1, permanent); + stmt->setUInt32(2, GetGUIDLow()); + stmt->setUInt32(3, bind.save->GetInstanceId()); + + CharacterDatabase.Execute(stmt); + } } else if (!load) - CharacterDatabase.PExecute("INSERT INTO character_instance (guid, instance, permanent) VALUES ('%u', '%u', '%u')", GetGUIDLow(), save->GetInstanceId(), permanent); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_INSTANCE); + + stmt->setUInt32(0, GetGUIDLow()); + stmt->setUInt32(1, save->GetInstanceId()); + stmt->setBool(2, permanent); + + CharacterDatabase.Execute(stmt); + } if (bind.save != save) { @@ -19102,11 +19143,18 @@ void Player::Customize(uint64 guid, uint8 gender, uint8 skin, uint8 face, uint8 Field* fields = result->Fetch(); - uint32 player_bytes2 = fields[0].GetUInt32(); - player_bytes2 &= ~0xFF; - player_bytes2 |= facialHair; + uint32 playerBytes2 = fields[0].GetUInt32(); + playerBytes2 &= ~0xFF; + playerBytes2 |= facialHair; - CharacterDatabase.PExecute("UPDATE characters SET gender = '%u', playerBytes = '%u', playerBytes2 = '%u' WHERE guid = '%u'", gender, skin | (face << 8) | (hairStyle << 16) | (hairColor << 24), player_bytes2, GUID_LOPART(guid)); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GENDER_PLAYERBYTES); + + stmt->setUInt8(0, gender); + stmt->setUInt32(1, skin | (face << 8) | (hairStyle << 16) | (hairColor << 24)); + stmt->setUInt32(2, playerBytes2); + stmt->setUInt32(3, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); } void Player::SendAttackSwingDeadTarget() @@ -19953,9 +20001,22 @@ void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type) } while (result->NextRow()); if (type == 10) - CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid)); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ALL_PETITION_SIGNATURES); + + stmt->setUInt32(0, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); + } else - CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u' AND type = '%u'", GUID_LOPART(guid), type); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PETITION_SIGNATURE); + + stmt->setUInt32(0, GUID_LOPART(guid)); + stmt->setUInt8(1, uint8(type)); + + CharacterDatabase.Execute(stmt); + } } SQLTransaction trans = CharacterDatabase.BeginTransaction(); @@ -23383,7 +23444,14 @@ void Player::_LoadSkills(PreparedQueryResult result) if (value == 0) { sLog->outError("Character %u has skill %u with value 0. Will be deleted.", GetGUIDLow(), skill); - CharacterDatabase.PExecute("DELETE FROM character_skills WHERE guid = '%u' AND skill = '%u' ", GetGUIDLow(), skill); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHARACTER_SKILL); + + stmt->setUInt32(0, GetGUIDLow()); + stmt->setUInt16(1, skill); + + CharacterDatabase.Execute(stmt); + continue; } @@ -24243,12 +24311,19 @@ void Player::DeleteEquipmentSet(uint64 setGuid) } } -void Player::RemoveAtLoginFlag(AtLoginFlags f, bool in_db_also /*= false*/) +void Player::RemoveAtLoginFlag(AtLoginFlags flags, bool persist /*= false*/) { - m_atLoginFlags &= ~f; + m_atLoginFlags &= ~flags; + + if (persist) + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_REM_AT_LOGIN_FLAG); + + stmt->setUInt16(0, uint16(flags)); + stmt->setUInt32(1, GetGUIDLow()); - if (in_db_also) - CharacterDatabase.PExecute("UPDATE characters set at_login = at_login & ~ %u WHERE guid ='%u'", uint32(f), GetGUIDLow()); + CharacterDatabase.Execute(stmt); + } } void Player::SendClearCooldown(uint32 spell_id, Unit* target) @@ -24760,7 +24835,13 @@ void Player::SetRandomWinner(bool isWinner) { m_IsBGRandomWinner = isWinner; if (m_IsBGRandomWinner) - CharacterDatabase.PExecute("INSERT INTO character_battleground_random (guid) VALUES ('%u')", GetGUIDLow()); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_BATTLEGROUND_RANDOM); + + stmt->setUInt32(0, GetGUIDLow()); + + CharacterDatabase.Execute(stmt); + } } void Player::_LoadRandomBGStatus(PreparedQueryResult result) diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index a9bba9cbdc4..3e70ace4262 100755 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -2352,7 +2352,7 @@ class Player : public Unit, public GridObject<Player> bool HasAtLoginFlag(AtLoginFlags f) const { return m_atLoginFlags & f; } void SetAtLoginFlag(AtLoginFlags f) { m_atLoginFlags |= f; } - void RemoveAtLoginFlag(AtLoginFlags f, bool in_db_also = false); + void RemoveAtLoginFlag(AtLoginFlags flags, bool persist = false); bool isUsingLfg(); diff --git a/src/server/game/Entities/Player/SocialMgr.cpp b/src/server/game/Entities/Player/SocialMgr.cpp index dbb18496515..e587834201c 100755 --- a/src/server/game/Entities/Player/SocialMgr.cpp +++ b/src/server/game/Entities/Player/SocialMgr.cpp @@ -47,7 +47,7 @@ uint32 PlayerSocial::GetNumberOfSocialsWithFlag(SocialFlag flag) return counter; } -bool PlayerSocial::AddToSocialList(uint32 friend_guid, bool ignore) +bool PlayerSocial::AddToSocialList(uint32 friendGuid, bool ignore) { // check client limits if (ignore) @@ -65,25 +65,39 @@ bool PlayerSocial::AddToSocialList(uint32 friend_guid, bool ignore) if (ignore) flag = SOCIAL_FLAG_IGNORED; - PlayerSocialMap::const_iterator itr = m_playerSocialMap.find(friend_guid); + PlayerSocialMap::const_iterator itr = m_playerSocialMap.find(friendGuid); if (itr != m_playerSocialMap.end()) { - CharacterDatabase.PExecute("UPDATE character_social SET flags = (flags | %u) WHERE guid = '%u' AND friend = '%u'", flag, GetPlayerGUID(), friend_guid); - m_playerSocialMap[friend_guid].Flags |= flag; + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_CHARACTER_SOCIAL_FLAGS); + + stmt->setUInt8(0, uint8(flag)); + stmt->setUInt32(1, GetPlayerGUID()); + stmt->setUInt32(2, friendGuid); + + CharacterDatabase.Execute(stmt); + + m_playerSocialMap[friendGuid].Flags |= flag; } else { - CharacterDatabase.PExecute("INSERT INTO character_social (guid, friend, flags) VALUES ('%u', '%u', '%u')", GetPlayerGUID(), friend_guid, flag); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHARACTER_SOCIAL); + + stmt->setUInt32(0, GetPlayerGUID()); + stmt->setUInt32(1, friendGuid); + stmt->setUInt8(2, uint8(flag)); + + CharacterDatabase.Execute(stmt); + FriendInfo fi; fi.Flags |= flag; - m_playerSocialMap[friend_guid] = fi; + m_playerSocialMap[friendGuid] = fi; } return true; } -void PlayerSocial::RemoveFromSocialList(uint32 friend_guid, bool ignore) +void PlayerSocial::RemoveFromSocialList(uint32 friendGuid, bool ignore) { - PlayerSocialMap::iterator itr = m_playerSocialMap.find(friend_guid); + PlayerSocialMap::iterator itr = m_playerSocialMap.find(friendGuid); if (itr == m_playerSocialMap.end()) // not exist return; @@ -94,24 +108,44 @@ void PlayerSocial::RemoveFromSocialList(uint32 friend_guid, bool ignore) itr->second.Flags &= ~flag; if (itr->second.Flags == 0) { - CharacterDatabase.PExecute("DELETE FROM character_social WHERE guid = '%u' AND friend = '%u'", GetPlayerGUID(), friend_guid); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHARACTER_SOCIAL); + + stmt->setUInt32(0, GetPlayerGUID()); + stmt->setUInt32(1, friendGuid); + + CharacterDatabase.Execute(stmt); + m_playerSocialMap.erase(itr); } else - CharacterDatabase.PExecute("UPDATE character_social SET flags = (flags & ~%u) WHERE guid = '%u' AND friend = '%u'", flag, GetPlayerGUID(), friend_guid); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_REM_CHARACTER_SOCIAL_FLAGS); + + stmt->setUInt8(0, uint8(flag)); + stmt->setUInt32(1, GetPlayerGUID()); + stmt->setUInt32(2, friendGuid); + + CharacterDatabase.Execute(stmt); + } } -void PlayerSocial::SetFriendNote(uint32 friend_guid, std::string note) +void PlayerSocial::SetFriendNote(uint32 friendGuid, std::string note) { - PlayerSocialMap::const_iterator itr = m_playerSocialMap.find(friend_guid); + PlayerSocialMap::const_iterator itr = m_playerSocialMap.find(friendGuid); if (itr == m_playerSocialMap.end()) // not exist return; utf8truncate(note, 48); // DB and client size limitation - CharacterDatabase.EscapeString(note); - CharacterDatabase.PExecute("UPDATE character_social SET note = '%s' WHERE guid = '%u' AND friend = '%u'", note.c_str(), GetPlayerGUID(), friend_guid); - m_playerSocialMap[friend_guid].Note = note; + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHARACTER_SOCIAL_NOTE); + + stmt->setString(0, note); + stmt->setUInt32(1, GetPlayerGUID()); + stmt->setUInt32(2, friendGuid); + + CharacterDatabase.Execute(stmt); + + m_playerSocialMap[friendGuid].Note = note; } void PlayerSocial::SendSocialList(Player* player) diff --git a/src/server/game/Entities/Player/SocialMgr.h b/src/server/game/Entities/Player/SocialMgr.h index 78965c13948..bae423d7094 100755 --- a/src/server/game/Entities/Player/SocialMgr.h +++ b/src/server/game/Entities/Player/SocialMgr.h @@ -122,7 +122,7 @@ class PlayerSocial // adding/removing bool AddToSocialList(uint32 friend_guid, bool ignore); void RemoveFromSocialList(uint32 friend_guid, bool ignore); - void SetFriendNote(uint32 friend_guid, std::string note); + void SetFriendNote(uint32 friendGuid, std::string note); // Packet send's void SendSocialList(Player* player); // Misc diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 5353e048066..9c5719a84ae 100755 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -3683,7 +3683,7 @@ void ObjectMgr::LoadQuests() QueryResult result = WorldDatabase.Query("SELECT " //0 1 2 3 4 5 6 7 8 9 10 11 12 "Id, Method, Level, MinLevel, MaxLevel, ZoneOrSort, Type, SuggestedPlayers, LimitTime, RequiredClasses, RequiredRaces, RequiredSkillId, RequiredSkillPoints, " - // 13 14 15 16 17 18 19 20 + // 13 14 15 16 17 18 19 20 "RequiredFactionId1, RequiredFactionId2, RequiredFactionValue1, RequiredFactionValue2, RequiredMinRepFaction, RequiredMaxRepFaction, RequiredMinRepValue, RequiredMaxRepValue, " // 21 22 23 24 25 26 27 28 29 30 31 "PrevQuestId, NextQuestId, ExclusiveGroup, NextQuestIdChain, RewardXPId, RewardOrRequiredMoney, RewardMoneyMaxLevel, RewardSpell, RewardSpellCast, RewardHonor, RewardHonorMultiplier, " @@ -5873,7 +5873,7 @@ GraveYardData const* ObjectMgr::FindGraveYardData(uint32 id, uint32 zoneId) return NULL; } -bool ObjectMgr::AddGraveYardLink(uint32 id, uint32 zoneId, uint32 team, bool inDB) +bool ObjectMgr::AddGraveYardLink(uint32 id, uint32 zoneId, uint32 team, bool persist /*= true*/) { if (FindGraveYardData(id, zoneId)) return false; @@ -5886,16 +5886,21 @@ bool ObjectMgr::AddGraveYardLink(uint32 id, uint32 zoneId, uint32 team, bool inD mGraveYardMap.insert(GraveYardMap::value_type(zoneId, data)); // add link to DB - if (inDB) + if (persist) { - WorldDatabase.PExecute("INSERT INTO game_graveyard_zone (id, ghost_zone, faction) " - "VALUES ('%u', '%u', '%u')", id, zoneId, team); + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_GRAVEYARD_ZONE); + + stmt->setUInt32(0, id); + stmt->setUInt32(1, zoneId); + stmt->setUInt16(2, uint16(team)); + + WorldDatabase.Execute(stmt); } return true; } -void ObjectMgr::RemoveGraveYardLink(uint32 id, uint32 zoneId, uint32 team, bool inDB) +void ObjectMgr::RemoveGraveYardLink(uint32 id, uint32 zoneId, uint32 team, bool persist /*= false*/) { GraveYardMap::iterator graveLow = mGraveYardMap.lower_bound(zoneId); GraveYardMap::iterator graveUp = mGraveYardMap.upper_bound(zoneId); @@ -5934,9 +5939,15 @@ void ObjectMgr::RemoveGraveYardLink(uint32 id, uint32 zoneId, uint32 team, bool mGraveYardMap.erase(itr); // remove link from DB - if (inDB) + if (persist) { - WorldDatabase.PExecute("DELETE FROM game_graveyard_zone WHERE id = '%u' AND ghost_zone = '%u' AND faction = '%u'", id, zoneId, team); + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_GRAVEYARD_ZONE); + + stmt->setUInt32(0, id); + stmt->setUInt32(1, zoneId); + stmt->setUInt16(2, uint16(team)); + + WorldDatabase.Execute(stmt); } return; @@ -6160,10 +6171,10 @@ void ObjectMgr::SetHighestGuids() m_hiItemGuid = (*result)[0].GetUInt32()+1; // Cleanup other tables from not existed guids ( >= m_hiItemGuid) - CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", m_hiItemGuid); - CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid >= '%u'", m_hiItemGuid); - CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE itemguid >= '%u'", m_hiItemGuid); - CharacterDatabase.PExecute("DELETE FROM guild_bank_item WHERE item_guid >= '%u'", m_hiItemGuid); + CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", m_hiItemGuid); // One-time query + CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid >= '%u'", m_hiItemGuid); // One-time query + CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE itemguid >= '%u'", m_hiItemGuid); // One-time query + CharacterDatabase.PExecute("DELETE FROM guild_bank_item WHERE item_guid >= '%u'", m_hiItemGuid); // One-time query result = WorldDatabase.Query("SELECT MAX(guid) FROM gameobject"); if (result) @@ -8046,11 +8057,18 @@ bool ObjectMgr::AddGameTele(GameTele& tele) m_GameTeleMap[new_id] = tele; - std::string safeName(tele.name); - WorldDatabase.EscapeString(safeName); + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_GAME_TELE); + + stmt->setUInt32(0, new_id); + stmt->setFloat(1, tele.position_x); + stmt->setFloat(2, tele.position_y); + stmt->setFloat(3, tele.position_z); + stmt->setFloat(4, tele.orientation); + stmt->setUInt16(5, uint16(tele.mapId)); + stmt->setString(6, tele.name); + + WorldDatabase.Execute(stmt); - WorldDatabase.PExecute("INSERT INTO game_tele (id, position_x, position_y, position_z, orientation, map, name) VALUES (%u, %f, %f, %f, %f, %d, '%s')", - new_id, tele.position_x, tele.position_y, tele.position_z, tele.orientation, tele.mapId, safeName.c_str()); return true; } @@ -8068,7 +8086,12 @@ bool ObjectMgr::DeleteGameTele(const std::string& name) { if (itr->second.wnameLow == wname) { - WorldDatabase.PExecute("DELETE FROM game_tele WHERE name = '%s'", itr->second.name.c_str()); + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_GAME_TELE); + + stmt->setString(0, itr->second.name); + + WorldDatabase.Execute(stmt); + m_GameTeleMap.erase(itr); return true; } @@ -8456,16 +8479,26 @@ void ObjectMgr::LoadGossipMenuItems() sLog->outString(); } -void ObjectMgr::AddVendorItem(uint32 entry, uint32 item, int32 maxcount, uint32 incrtime, uint32 extendedcost, bool savetodb) +void ObjectMgr::AddVendorItem(uint32 entry, uint32 item, int32 maxcount, uint32 incrtime, uint32 extendedCost, bool persist /*= true*/) { VendorItemData& vList = m_mCacheVendorItemMap[entry]; - vList.AddItem(item, maxcount, incrtime, extendedcost); + vList.AddItem(item, maxcount, incrtime, extendedCost); - if (savetodb) - WorldDatabase.PExecute("INSERT INTO npc_vendor (entry, item, maxcount, incrtime, extendedcost) VALUES('%u', '%u', '%u', '%u', '%u')", entry, item, maxcount, incrtime, extendedcost); + if (persist) + { + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_NPC_VENODR); + + stmt->setUInt32(0, entry); + stmt->setUInt32(1, item); + stmt->setUInt8(2, maxcount); + stmt->setUInt32(3, incrtime); + stmt->setUInt32(4, extendedCost); + + WorldDatabase.Execute(stmt); + } } -bool ObjectMgr::RemoveVendorItem(uint32 entry, uint32 item, bool savetodb) +bool ObjectMgr::RemoveVendorItem(uint32 entry, uint32 item, bool persist /*= true*/) { CacheVendorItemMap::iterator iter = m_mCacheVendorItemMap.find(entry); if (iter == m_mCacheVendorItemMap.end()) @@ -8474,7 +8507,16 @@ bool ObjectMgr::RemoveVendorItem(uint32 entry, uint32 item, bool savetodb) if (!iter->second.RemoveItem(item)) return false; - if (savetodb) WorldDatabase.PExecute("DELETE FROM npc_vendor WHERE entry='%u' AND item='%u'", entry, item); + if (persist) + { + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_NPC_VENDOR); + + stmt->setUInt32(0, entry); + stmt->setUInt32(1, item); + + WorldDatabase.Execute(stmt); + } + return true; } diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 88c593a009d..6c6ed19ac6c 100755 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -710,8 +710,8 @@ class ObjectMgr WorldSafeLocsEntry const* GetDefaultGraveYard(uint32 team); WorldSafeLocsEntry const* GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team); - bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true); - void RemoveGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = false); + bool AddGraveYardLink(uint32 id, uint32 zoneId, uint32 team, bool persist = true); + void RemoveGraveYardLink(uint32 id, uint32 zoneId, uint32 team, bool persist = false); void LoadGraveyardZones(); GraveYardData const* FindGraveYardData(uint32 id, uint32 zone); @@ -1138,8 +1138,8 @@ class ObjectMgr return &iter->second; } - void AddVendorItem(uint32 entry, uint32 item, int32 maxcount, uint32 incrtime, uint32 ExtendedCost, bool savetodb = true); // for event - bool RemoveVendorItem(uint32 entry, uint32 item, bool savetodb = true); // for event + void AddVendorItem(uint32 entry, uint32 item, int32 maxcount, uint32 incrtime, uint32 extendedCost, bool persist = true); // for event + bool RemoveVendorItem(uint32 entry, uint32 item, bool persist = true); // for event bool IsVendorItemValid(uint32 vendor_entry, uint32 item, int32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* player = NULL, std::set<uint32>* skip_vendors = NULL, uint32 ORnpcflag = 0) const; void LoadScriptNames(); diff --git a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp index 2a4e1c50ac5..d8be111cd18 100755 --- a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp @@ -904,8 +904,18 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) pCurrChar->SendInitialPacketsAfterAddToMap(); - CharacterDatabase.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar->GetGUIDLow()); - LoginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = '%u'", GetAccountId()); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_CHAR_ONLINE); + + stmt->setUInt32(0, pCurrChar->GetGUIDLow()); + + CharacterDatabase.Execute(stmt); + + stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_ACCOUNT_ONLINE); + + stmt->setUInt32(0, GetAccountId()); + + LoginDatabase.Execute(stmt); + pCurrChar->SetInGameTime(getMSTime()); // announce group about member online (must be after add to player list to receive announce to self) @@ -1330,10 +1340,10 @@ void WorldSession::HandleRemoveGlyph(WorldPacket & recv_data) void WorldSession::HandleCharCustomize(WorldPacket& recv_data) { uint64 guid; - std::string newname; + std::string newName; recv_data >> guid; - recv_data >> newname; + recv_data >> newName; uint8 gender, skin, face, hairStyle, hairColor, facialHair; recv_data >> gender >> skin >> hairColor >> hairStyle >> facialHair >> face; @@ -1359,7 +1369,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data) } // prevent character rename to invalid name - if (!normalizePlayerName(newname)) + if (!normalizePlayerName(newName)) { WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1); data << uint8(CHAR_NAME_NO_NAME); @@ -1367,7 +1377,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data) return; } - uint8 res = ObjectMgr::CheckPlayerName(newname, true); + uint8 res = ObjectMgr::CheckPlayerName(newName, true); if (res != CHAR_NAME_SUCCESS) { WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1); @@ -1377,7 +1387,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data) } // check name limitations - if (AccountMgr::IsPlayerAccount(GetSecurity()) && sObjectMgr->IsReservedName(newname)) + if (AccountMgr::IsPlayerAccount(GetSecurity()) && sObjectMgr->IsReservedName(newName)) { WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1); data << uint8(CHAR_NAME_RESERVED); @@ -1386,7 +1396,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data) } // character with this name already exist - if (uint64 newguid = sObjectMgr->GetPlayerGUIDByName(newname)) + if (uint64 newguid = sObjectMgr->GetPlayerGUIDByName(newName)) { if (newguid != guid) { @@ -1397,22 +1407,34 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data) } } - CharacterDatabase.EscapeString(newname); if (QueryResult oldNameResult = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid ='%u'", GUID_LOPART(guid))) { std::string oldname = oldNameResult->Fetch()[0].GetString(); std::string IP_str = GetRemoteAddress(); - sLog->outChar("Account: %d (IP: %s), Character[%s] (guid:%u) Customized to: %s", GetAccountId(), IP_str.c_str(), oldname.c_str(), GUID_LOPART(guid), newname.c_str()); + sLog->outChar("Account: %d (IP: %s), Character[%s] (guid:%u) Customized to: %s", GetAccountId(), IP_str.c_str(), oldname.c_str(), GUID_LOPART(guid), newName.c_str()); } 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)); - sWorld->UpdateCharacterNameData(GUID_LOPART(guid), newname, gender); - WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1+8+(newname.size()+1)+6); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_CHAR_NAME_AT_LOGIN); + + stmt->setString(0, newName); + stmt->setUInt16(1, uint16(AT_LOGIN_CUSTOMIZE)); + stmt->setUInt32(2, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); + + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_DECLINED_NAME); + + stmt->setUInt32(0, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); + + sWorld->UpdateCharacterNameData(GUID_LOPART(guid), newName, gender); + + WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1+8+(newName.size()+1)+6); data << uint8(RESPONSE_SUCCESS); data << uint64(guid); - data << newname; + data << newName; data << uint8(gender); data << uint8(skin); data << uint8(face); diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 3288224e1f2..d8988cd5207 100755 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -101,7 +101,7 @@ isRecruiter(isARecruiter) m_Address = sock->GetRemoteAddress(); sock->AddReference(); ResetTimeOutTime(); - LoginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = %u;", GetAccountId()); + LoginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = %u;", GetAccountId()); // One-time query } InitializeQueryCallbackParameters(); @@ -127,7 +127,7 @@ WorldSession::~WorldSession() while (_recvQueue.next(packet)) delete packet; - LoginDatabase.PExecute("UPDATE account SET online = 0 WHERE id = %u;", GetAccountId()); + LoginDatabase.PExecute("UPDATE account SET online = 0 WHERE id = %u;", GetAccountId()); // One-time query } void WorldSession::SizeError(WorldPacket const &packet, uint32 size) const diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index ea3f86c81b3..bfed9a0bb5d 100755 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -1246,8 +1246,10 @@ void World::SetInitialWorldSettings() server_type = REALM_TYPE_PVP; else server_type = getIntConfig(CONFIG_GAME_TYPE); + uint32 realm_zone = getIntConfig(CONFIG_REALM_ZONE); - LoginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realmID); + + LoginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realmID); // One-time query ///- Remove the bones (they should not exist in DB though) and old corpses after a restart PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_OLD_CORPSES); @@ -1650,7 +1652,7 @@ void World::SetInitialWorldSettings() local.tm_year+1900, local.tm_mon+1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec); LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, startstring, uptime, revision) VALUES('%u', " UI64FMTD ", '%s', 0, '%s')", - realmID, uint64(m_startTime), isoDate, _FULLVERSION); + realmID, uint64(m_startTime), isoDate, _FULLVERSION); // One-time query m_timers[WUPDATE_WEATHERS].SetInterval(1*IN_MILLISECONDS); m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS); @@ -1928,7 +1930,15 @@ void World::Update(uint32 diff) uint32 maxOnlinePlayers = GetMaxPlayerCount(); m_timers[WUPDATE_UPTIME].Reset(); - LoginDatabase.PExecute("UPDATE uptime SET uptime = %u, maxplayers = %u WHERE realmid = %u AND starttime = " UI64FMTD, tmpDiff, maxOnlinePlayers, realmID, uint64(m_startTime)); + + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_UPTIME_PLAYERS); + + stmt->setUInt64(0, uint64(tmpDiff)); + stmt->setUInt16(1, uint16(maxOnlinePlayers)); + stmt->setUInt32(2, realmID); + stmt->setUInt16(3, uint64(m_startTime)); + + LoginDatabase.Execute(stmt); } /// <li> Clean logs table @@ -1937,8 +1947,13 @@ void World::Update(uint32 diff) if (m_timers[WUPDATE_CLEANDB].Passed()) { m_timers[WUPDATE_CLEANDB].Reset(); - LoginDatabase.PExecute("DELETE FROM logs WHERE (time + %u) < "UI64FMTD";", - sWorld->getIntConfig(CONFIG_LOGDB_CLEARTIME), uint64(time(0))); + + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_OLD_LOGS); + + stmt->setUInt32(0, sWorld->getIntConfig(CONFIG_LOGDB_CLEARTIME)); + stmt->setUInt32(1, uint32(time(0))); + + LoginDatabase.Execute(stmt); } } @@ -2821,9 +2836,23 @@ void World::setWorldState(uint32 index, uint64 value) { WorldStatesMap::const_iterator it = m_worldstates.find(index); if (it != m_worldstates.end()) - CharacterDatabase.PExecute("UPDATE worldstates SET value="UI64FMTD" where entry=%u", value, index); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_WORLDSTATE); + + stmt->setUInt32(0, uint32(value)); + stmt->setUInt32(1, index); + + CharacterDatabase.Execute(stmt); + } else - CharacterDatabase.PExecute("INSERT INTO worldstates (entry, value) VALUES (%u, "UI64FMTD")", index, value); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_WORLDSTATE); + + stmt->setUInt32(0, index); + stmt->setUInt32(1, uint32(value)); + + CharacterDatabase.Execute(stmt); + } m_worldstates[index] = value; } diff --git a/src/server/scripts/Commands/cs_account.cpp b/src/server/scripts/Commands/cs_account.cpp index bcef7ac9ba9..a8e0c972607 100644 --- a/src/server/scripts/Commands/cs_account.cpp +++ b/src/server/scripts/Commands/cs_account.cpp @@ -388,8 +388,13 @@ public: if (expansion < 0 || uint8(expansion) > sWorld->getIntConfig(CONFIG_EXPANSION)) return false; - // No SQL injection - LoginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'", expansion, accountId); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_EXPANSION); + + stmt->setUInt8(0, expansion); + stmt->setUInt32(1, accountId); + + LoginDatabase.Execute(stmt); + handler->PSendSysMessage(LANG_ACCOUNT_SETADDON, accountName.c_str(), accountId, expansion); return true; } @@ -480,13 +485,34 @@ public: } // If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realmID + PreparedStatement* stmt; + if (gmRealmID == -1) - LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u'", targetAccountId); + { + stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS); + + stmt->setUInt32(0, targetAccountId); + } else - LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u' AND (RealmID = '%d' OR RealmID = '-1')", targetAccountId, realmID); + { + stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM); + + stmt->setUInt32(0, targetAccountId); + stmt->setUInt32(1, realmID); + } + LoginDatabase.Execute(stmt); if (gm != 0) - LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u', '%d', '%d')", targetAccountId, gm, gmRealmID); + { + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_ACCESS); + + stmt->setUInt32(0, targetAccountId); + stmt->setUInt8(1, uint8(gm)); + stmt->setUInt32(2, gmRealmID); + + LoginDatabase.Execute(stmt); + } + handler->PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm); return true; diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index a5aa2a516f3..2d52a0e80d4 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -219,10 +219,10 @@ public: if (!*args) return false; - char* guid_str = strtok((char*)args, " "); - char* wait_str = strtok((char*)NULL, " "); + char* guidStr = strtok((char*)args, " "); + char* waitStr = strtok((char*)NULL, " "); - uint32 lowguid = atoi((char*)guid_str); + uint32 lowGuid = atoi((char*)guidStr); Creature* creature = NULL; @@ -234,10 +234,10 @@ public: // attempt check creature existence by DB data if (!creature) { - CreatureData const* data = sObjectMgr->GetCreatureData(lowguid); + CreatureData const* data = sObjectMgr->GetCreatureData(lowGuid); if (!data) { - handler->PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND, lowguid); + handler->PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND, lowGuid); handler->SetSentErrorMessage(true); return false; } @@ -245,20 +245,22 @@ public: else { // obtain real GUID for DB operations - lowguid = creature->GetDBTableGUIDLow(); + lowGuid = creature->GetDBTableGUIDLow(); } - int wait = wait_str ? atoi(wait_str) : 0; + int wait = waitStr ? atoi(waitStr) : 0; if (wait < 0) wait = 0; - //Player* player = handler->GetSession()->GetPlayer(); + // Update movement type + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_MOVEMENT_TYPE); - //WaypointMgr.AddLastNode(lowguid, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), wait, 0); + stmt->setUInt8(0, uint8(WAYPOINT_MOTION_TYPE)); + stmt->setUInt32(1, lowGuid); + + CharacterDatabase.Execute(stmt); - // update movement type - WorldDatabase.PExecute("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", WAYPOINT_MOTION_TYPE, lowguid); if (creature && creature->GetWaypointPath()) { creature->SetDefaultMovementType(WAYPOINT_MOTION_TYPE); @@ -457,17 +459,23 @@ public: creature->setFaction(factionId); - // faction is set in creature_template - not inside creature + // Faction is set in creature_template - not inside creature - // update in memory + // Update in memory.. if (CreatureTemplate const* cinfo = creature->GetCreatureInfo()) { const_cast<CreatureTemplate*>(cinfo)->faction_A = factionId; const_cast<CreatureTemplate*>(cinfo)->faction_H = factionId; } - // and DB - WorldDatabase.PExecute("UPDATE creature_template SET faction_A = '%u', faction_H = '%u' WHERE entry = '%u'", factionId, factionId, creature->GetEntry()); + // ..and DB + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_FACTION); + + stmt->setUInt16(0, uint16(factionId)); + stmt->setUInt16(1, uint16(factionId)); + stmt->setUInt32(2, creature->GetEntry()); + + WorldDatabase.Execute(stmt); return true; } diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index 28f7f95b319..4e2964881a7 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -47,6 +47,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_DEL_QUEST_STATUS_DAILY, "DELETE FROM character_queststatus_daily", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_DEL_QUEST_STATUS_WEEKLY, "DELETE FROM character_queststatus_weekly", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_DEL_BATTLEGROUND_RANDOM, "DELETE FROM character_battleground_random", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_INS_BATTLEGROUND_RANDOM, "INSERT INTO character_battleground_random (guid) VALUES (?)", CONNECTION_ASYNC); // Start LoginQueryHolder content PREPARE_STATEMENT(CHAR_LOAD_PLAYER, "SELECT guid, account, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags, " @@ -97,6 +98,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_ADD_MAIL, "INSERT INTO mail(id, messageType, stationery, mailTemplateId, sender, receiver, subject, body, has_items, expire_time, deliver_time, money, cod, checked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_DEL_MAIL, "DELETE FROM mail WHERE id = ?", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_ADD_MAIL_ITEM, "INSERT INTO mail_items(mail_id, item_guid, receiver) VALUES (?, ?, ?)", CONNECTION_ASYNC) + PREPARE_STATEMENT(CHAR_DEL_MAIL_ITEM, "DELETE FROM mail_items WHERE item_guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_DEL_INVALID_MAIL_ITEM, "DELETE FROM mail_items WHERE item_guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_DEL_EMPTY_EXPIRED_MAIL, "DELETE FROM mail WHERE expire_time < ? AND has_items = 0 AND body = ''", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_GET_EXPIRED_MAIL, "SELECT id, messageType, sender, receiver, has_items, expire_time, cod, checked, mailTemplateId FROM mail WHERE expire_time < ?", CONNECTION_SYNCH) @@ -251,6 +253,8 @@ void CharacterDatabaseConnection::DoPrepareStatements() // Petitions PREPARE_STATEMENT(CHAR_LOAD_PETITION, "SELECT ownerguid, name, type FROM petition WHERE petitionguid = ?", CONNECTION_SYNCH); PREPARE_STATEMENT(CHAR_LOAD_PETITION_SIGNATURE, "SELECT playerguid FROM petition_sign WHERE petitionguid = ?", CONNECTION_SYNCH); + PREPARE_STATEMENT(CHAR_DEL_ALL_PETITION_SIGNATURES, "DELETE FROM petition_sign WHERE playerguid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_PETITION_SIGNATURE, "DELETE FROM petition_sign WHERE playerguid = ? AND type = ?", CONNECTION_ASYNC); // Arena teams PREPARE_STATEMENT(CHAR_LOAD_PLAYER_ARENAINFO, "SELECT arenaTeamId, weekGames, seasonGames, seasonWins, personalRating FROM arena_team_member WHERE guid = ?", CONNECTION_ASYNC) @@ -331,7 +335,8 @@ void CharacterDatabaseConnection::DoPrepareStatements() "watchedFaction=?,drunk=?,health=?,power1=?,power2=?,power3=?,power4=?,power5=?,power6=?,power7=?,latency=?,speccount=?,activespec=?,exploredZones=?," "equipmentCache=?,ammoId=?,knownTitles=?,actionBars=?,grantableLevels=?,online=? WHERE guid=?", CONNECTION_ASYNC); - PREPARE_STATEMENT(CHAR_UPDATE_AT_LOGIN_FLAG, "UPDATE characters SET at_login = at_login | ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_ADD_AT_LOGIN_FLAG, "UPDATE characters SET at_login = at_login | ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_REM_AT_LOGIN_FLAG, "UPDATE characters set at_login = at_login & ~ ? WHERE guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPDATE_ALL_AT_LOGIN_FLAGS, "UPDATE characters SET at_login = at_login | ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_ADD_BUG_REPORT, "INSERT INTO bugreport (type, content) VALUES(?, ?)", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPD_PETITION_NAME, "UPDATE petition SET name = ? WHERE petitionguid = ?", CONNECTION_ASYNC); @@ -350,6 +355,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_DEL_ALL_GM_TICKETS, "TRUNCATE TABLE gm_tickets", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_DEL_INVALID_SPELL, "DELETE FROM character_talent WHERE spell = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPDATE_DELETE_INFO, "UPDATE characters SET deleteInfos_Name = name, deleteInfos_Account = account, deleteDate = UNIX_TIMESTAMP(), name = '', account = 0 WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UDP_RESTORE_DELETE_INFO, "UPDATE characters SET name = ?, account = ?, deleteDate = NULL, deleteInfos_Name = NULL, deleteInfos_Account = NULL WHERE deleteDate IS NOT NULL AND guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPDATE_ZONE, "UPDATE characters SET zone = ? WHERE guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPDATE_LEVEL, "UPDATE characters SET level = ?, xp = 0 WHERE guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA, "DELETE FROM character_achievement_progress WHERE criteria = ?", CONNECTION_ASYNC); @@ -361,4 +367,19 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_ADD_GROUP_INSTANCE, "REPLACE INTO group_instance (guid, instance, permanent) VALUES (?, ?, ?)", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPDATE_INSTANCE_RESETTIME, "UPDATE instance SET resettime = ? WHERE id = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPDATE_GLOBAL_INSTANCE_RESETTIME, "UPDATE instance_reset SET resettime = ? WHERE mapid = ? AND difficulty = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_CHAR_ONLINE, "UPDATE characters SET online = 1 WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_CHAR_NAME_AT_LOGIN, "UPDATE characters set name = ?, at_login = at_login & ~ ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_WORLDSTATE, "UPDATE worldstates SET value = ? WHERE entry = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_INS_WORLDSTATE, "INSERT INTO worldstates (entry, value) VALUES (?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_CHAR_INSTANCE, "DELETE FROM character_instance WHERE guid = ? AND instance = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_CHAR_INSTANCE, "UPDATE character_instance SET instance = ?, permanent = ? WHERE guid = ? AND instance = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_INS_CHAR_INSTANCE, "INSERT INTO character_instance (guid, instance, permanent) VALUES (?, ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_GENDER_PLAYERBYTES, "UPDATE characters SET gender = ?, playerBytes = ?, playerBytes2 = ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_CHARACTER_SKILL, "DELETE FROM character_skills WHERE guid = ? AND skill = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_ADD_CHARACTER_SOCIAL_FLAGS, "UPDATE character_social SET flags = flags | ? WHERE guid = ? AND friend = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_REM_CHARACTER_SOCIAL_FLAGS, "UPDATE character_social SET flags = flags & ~ ? WHERE guid = ? AND friend = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_INS_CHARACTER_SOCIAL, "INSERT INTO character_social (guid, friend, flags) VALUES (?, ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_CHARACTER_SOCIAL, "DELETE FROM character_social WHERE guid = ? AND friend = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_CHARACTER_SOCIAL_NOTE, "UPDATE character_social SET note = ? WHERE guid = ? AND friend = ?", CONNECTION_ASYNC); + } diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index eea02ee60b9..f0ac3e49d1e 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -67,6 +67,8 @@ enum CharacterDatabaseStatements CHAR_DEL_QUEST_STATUS_DAILY, CHAR_DEL_QUEST_STATUS_WEEKLY, CHAR_DEL_BATTLEGROUND_RANDOM, + CHAR_INS_BATTLEGROUND_RANDOM, + CHAR_LOAD_PLAYER, CHAR_LOAD_PLAYER_GROUP, CHAR_LOAD_PLAYER_BOUNDINSTANCES, @@ -106,6 +108,7 @@ enum CharacterDatabaseStatements CHAR_ADD_MAIL, CHAR_DEL_MAIL, CHAR_ADD_MAIL_ITEM, + CHAR_DEL_MAIL_ITEM, CHAR_DEL_INVALID_MAIL_ITEM, CHAR_DEL_EMPTY_EXPIRED_MAIL, CHAR_GET_EXPIRED_MAIL, @@ -247,6 +250,8 @@ enum CharacterDatabaseStatements CHAR_LOAD_PETITION, CHAR_LOAD_PETITION_SIGNATURE, + CHAR_DEL_ALL_PETITION_SIGNATURES, + CHAR_DEL_PETITION_SIGNATURE, CHAR_ADD_PLAYER_BGDATA, CHAR_DEL_PLAYER_BGDATA, @@ -293,7 +298,8 @@ enum CharacterDatabaseStatements CHAR_ADD_CHARACTER, CHAR_UPD_CHARACTER, - CHAR_UPDATE_AT_LOGIN_FLAG, + CHAR_UPD_ADD_AT_LOGIN_FLAG, + CHAR_UPD_REM_AT_LOGIN_FLAG, CHAR_UPDATE_ALL_AT_LOGIN_FLAGS, CHAR_ADD_BUG_REPORT, CHAR_UPD_PETITION_NAME, @@ -311,6 +317,7 @@ enum CharacterDatabaseStatements CHAR_UPDATE_GROUP_RAID_DIFFICULTY, CHAR_DEL_INVALID_SPELL, CHAR_UPDATE_DELETE_INFO, + CHAR_UDP_RESTORE_DELETE_INFO, CHAR_UPDATE_ZONE, CHAR_UPDATE_LEVEL, CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA, @@ -322,6 +329,20 @@ enum CharacterDatabaseStatements CHAR_ADD_GROUP_INSTANCE, CHAR_UPDATE_INSTANCE_RESETTIME, CHAR_UPDATE_GLOBAL_INSTANCE_RESETTIME, + CHAR_UPDATE_CHAR_ONLINE, + CHAR_UPDATE_CHAR_NAME_AT_LOGIN, + CHAR_UPD_WORLDSTATE, + CHAR_INS_WORLDSTATE, + CHAR_DEL_CHAR_INSTANCE, + CHAR_UPD_CHAR_INSTANCE, + CHAR_INS_CHAR_INSTANCE, + CHAR_UPD_GENDER_PLAYERBYTES, + CHAR_DEL_CHARACTER_SKILL, + CHAR_UPD_ADD_CHARACTER_SOCIAL_FLAGS, + CHAR_UPD_REM_CHARACTER_SOCIAL_FLAGS, + CHAR_INS_CHARACTER_SOCIAL, + CHAR_DEL_CHARACTER_SOCIAL, + CHAR_UPD_CHARACTER_SOCIAL_NOTE, MAX_CHARACTERDATABASE_STATEMENTS, }; diff --git a/src/server/shared/Database/Implementation/LoginDatabase.cpp b/src/server/shared/Database/Implementation/LoginDatabase.cpp index 713d4a31e6d..a42614e6053 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.cpp +++ b/src/server/shared/Database/Implementation/LoginDatabase.cpp @@ -56,4 +56,10 @@ void LoginDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(LOGIN_UPDATE_PASSWORD, "UPDATE account SET v = 0, s = 0, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(LOGIN_UPDATE_MUTE_TIME, "UPDATE account SET mutetime = ? WHERE id = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(LOGIN_UPDATE_LAST_IP, "UPDATE account SET last_ip = ? WHERE username = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_UPDATE_ACCOUNT_ONLINE, "UPDATE account SET online = 1 WHERE id = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_UPDATE_UPTIME_PLAYERS, "UPDATE uptime SET uptime = ?, maxplayers = ? WHERE realmid = ? AND starttime = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_DEL_OLD_LOGS, "DELETE FROM logs WHERE (time + ?) < ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_DEL_ACCOUNT_ACCESS, "DELETE FROM account_access WHERE id = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM, "DELETE FROM account_access WHERE id = ? AND (RealmID = ? OR RealmID = -1)", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_INS_ACCOUNT_ACCESS, "INSERT INTO account_access VALUES (?, ?, ?)", CONNECTION_ASYNC); } diff --git a/src/server/shared/Database/Implementation/LoginDatabase.h b/src/server/shared/Database/Implementation/LoginDatabase.h index 98d9c505fa0..3b0a45c27cf 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.h +++ b/src/server/shared/Database/Implementation/LoginDatabase.h @@ -76,6 +76,12 @@ enum LoginDatabaseStatements LOGIN_UPDATE_PASSWORD, LOGIN_UPDATE_MUTE_TIME, LOGIN_UPDATE_LAST_IP, + LOGIN_UPDATE_ACCOUNT_ONLINE, + LOGIN_UPDATE_UPTIME_PLAYERS, + LOGIN_DEL_OLD_LOGS, + LOGIN_DEL_ACCOUNT_ACCESS, + LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM, + LOGIN_INS_ACCOUNT_ACCESS, MAX_LOGINDATABASE_STATEMENTS, }; diff --git a/src/server/shared/Database/Implementation/WorldDatabase.cpp b/src/server/shared/Database/Implementation/WorldDatabase.cpp index 5df8299310f..ba1434e997a 100755 --- a/src/server/shared/Database/Implementation/WorldDatabase.cpp +++ b/src/server/shared/Database/Implementation/WorldDatabase.cpp @@ -30,4 +30,12 @@ void WorldDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(WORLD_LOAD_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z FROM waypoints ORDER BY entry, pointid", CONNECTION_SYNCH) PREPARE_STATEMENT(WORLD_DEL_GAMEOBJECT, "DELETE FROM gameobject WHERE guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(WORLD_DEL_EVENT_GAMEOBJECT, "DELETE FROM game_event_gameobject WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(WORLD_INS_GRAVEYARD_ZONE, "INSERT INTO game_graveyard_zone (id, ghost_zone, faction) VALUES (?, ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(WORLD_DEL_GRAVEYARD_ZONE, "DELETE FROM game_graveyard_zone WHERE id = ? AND ghost_zone = ? AND faction = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(WORLD_INS_GAME_TELE, "INSERT INTO game_tele (id, position_x, position_y, position_z, orientation, map, name) VALUES (?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(WORLD_DEL_GAME_TELE, "DELETE FROM game_tele WHERE name = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(WORLD_INS_NPC_VENODR, "INSERT INTO npc_vendor (entry, item, maxcount, incrtime, extendedcost) VALUES(?, ?, ?, ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(WORLD_DEL_NPC_VENDOR, "DELETE FROM npc_vendor WHERE entry = ? AND item = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(WORLD_UPD_CREATURE_MOVEMENT_TYPE, "UPDATE creature SET MovementType = ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(WORLD_UPD_CREATURE_FACTION, "UPDATE creature_template SET faction_A = ?, faction_H = ? WHERE entry = ?", CONNECTION_ASYNC); } diff --git a/src/server/shared/Database/Implementation/WorldDatabase.h b/src/server/shared/Database/Implementation/WorldDatabase.h index 94d6365c081..93dcc23b4f8 100755 --- a/src/server/shared/Database/Implementation/WorldDatabase.h +++ b/src/server/shared/Database/Implementation/WorldDatabase.h @@ -50,6 +50,14 @@ enum WorldDatabaseStatements WORLD_LOAD_SMARTAI_WP, WORLD_DEL_GAMEOBJECT, WORLD_DEL_EVENT_GAMEOBJECT, + WORLD_INS_GRAVEYARD_ZONE, + WORLD_DEL_GRAVEYARD_ZONE, + WORLD_INS_GAME_TELE, + WORLD_DEL_GAME_TELE, + WORLD_INS_NPC_VENODR, + WORLD_DEL_NPC_VENDOR, + WORLD_UPD_CREATURE_MOVEMENT_TYPE, + WORLD_UPD_CREATURE_FACTION, MAX_WORLDDATABASE_STATEMENTS, }; diff --git a/src/server/worldserver/CommandLine/CliRunnable.cpp b/src/server/worldserver/CommandLine/CliRunnable.cpp index 61352521d9f..6cbdb43a343 100755 --- a/src/server/worldserver/CommandLine/CliRunnable.cpp +++ b/src/server/worldserver/CommandLine/CliRunnable.cpp @@ -292,8 +292,13 @@ void ChatHandler::HandleCharacterDeletedRestoreHelper(DeletedInfo const& delInfo return; } - CharacterDatabase.PExecute("UPDATE characters SET name='%s', account='%u', deleteDate=NULL, deleteInfos_Name=NULL, deleteInfos_Account=NULL WHERE deleteDate IS NOT NULL AND guid = %u", - delInfo.name.c_str(), delInfo.accountId, delInfo.lowguid); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UDP_RESTORE_DELETE_INFO); + + stmt->setString(0, delInfo.name); + stmt->setUInt32(1, delInfo.accountId); + stmt->setUInt32(2, delInfo.lowguid); + + CharacterDatabase.Execute(stmt); } /** diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp index 42d72aa2c6f..e4009f42429 100755 --- a/src/server/worldserver/Master.cpp +++ b/src/server/worldserver/Master.cpp @@ -457,7 +457,7 @@ bool Master::_StartDB() clearOnlineAccounts(); ///- Insert version info into DB - WorldDatabase.PExecute("UPDATE version SET core_version = '%s', core_revision = '%s'", _FULLVERSION, _HASH); + WorldDatabase.PExecute("UPDATE version SET core_version = '%s', core_revision = '%s'", _FULLVERSION, _HASH); // One-time query sWorld->LoadDBVersion(); |
