Core/ObjectMgr: improved GetPlayerGUIDByName method + misc

This commit is contained in:
ShinDarth 2016-08-28 23:09:53 +02:00
parent e2a00f9ae4
commit 9ac33ca092
5 changed files with 45 additions and 5 deletions

View file

@ -16,6 +16,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_INS_QUEST_POOL_SAVE, "INSERT INTO pool_quest_save (pool_id, quest_id) VALUES (?, ?)", CONNECTION_ASYNC); PrepareStatement(CHAR_INS_QUEST_POOL_SAVE, "INSERT INTO pool_quest_save (pool_id, quest_id) VALUES (?, ?)", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_NONEXISTENT_GUILD_BANK_ITEM, "DELETE FROM guild_bank_item WHERE guildid = ? AND TabId = ? AND SlotId = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_NONEXISTENT_GUILD_BANK_ITEM, "DELETE FROM guild_bank_item WHERE guildid = ? AND TabId = ? AND SlotId = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_EXPIRED_BANS, "UPDATE character_banned SET active = 0 WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate <> bandate", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_EXPIRED_BANS, "UPDATE character_banned SET active = 0 WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate <> bandate", CONNECTION_ASYNC);
PrepareStatement(CHAR_SEL_DATA_BY_NAME, "SELECT guid, account, name, gender, race, class, level FROM characters WHERE deleteDate IS NULL AND name = ?", CONNECTION_BOTH);
PrepareStatement(CHAR_SEL_CHECK_NAME, "SELECT 1 FROM characters WHERE name = ?", CONNECTION_BOTH); PrepareStatement(CHAR_SEL_CHECK_NAME, "SELECT 1 FROM characters WHERE name = ?", CONNECTION_BOTH);
PrepareStatement(CHAR_SEL_CHECK_GUID, "SELECT 1 FROM characters WHERE guid = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_CHECK_GUID, "SELECT 1 FROM characters WHERE guid = ?", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_SUM_CHARS, "SELECT COUNT(guid) FROM characters WHERE account = ?", CONNECTION_BOTH); PrepareStatement(CHAR_SEL_SUM_CHARS, "SELECT COUNT(guid) FROM characters WHERE account = ?", CONNECTION_BOTH);

View file

@ -36,6 +36,7 @@ enum CharacterDatabaseStatements
CHAR_INS_QUEST_POOL_SAVE, CHAR_INS_QUEST_POOL_SAVE,
CHAR_DEL_NONEXISTENT_GUILD_BANK_ITEM, CHAR_DEL_NONEXISTENT_GUILD_BANK_ITEM,
CHAR_DEL_EXPIRED_BANS, CHAR_DEL_EXPIRED_BANS,
CHAR_SEL_DATA_BY_NAME,
CHAR_SEL_CHECK_NAME, CHAR_SEL_CHECK_NAME,
CHAR_SEL_CHECK_GUID, CHAR_SEL_CHECK_GUID,
CHAR_SEL_SUM_CHARS, CHAR_SEL_SUM_CHARS,

View file

@ -2140,9 +2140,47 @@ void ObjectMgr::RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data
uint64 ObjectMgr::GetPlayerGUIDByName(std::string const& name) const uint64 ObjectMgr::GetPlayerGUIDByName(std::string const& name) const
{ {
uint32 guidLow;
// Get data from global storage // Get data from global storage
if (uint32 guidLow = sWorld->GetGlobalPlayerGUID(name)) if (guidLow = sWorld->GetGlobalPlayerGUID(name))
return MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER); return MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
// Player is not in the global storage, try to get it from the Database
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_DATA_BY_NAME);
stmt->setString(0, name);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
// Player was not in the global storage, but it was found in the database
// Let's add it to the global storage
sLog->outString("Player %s was not found in the global storage, but it was found in the database.", name.c_str());
Field* fields = result->Fetch();
guidLow = fields[0].GetUInt32();
sWorld->AddGlobalPlayerData(
guidLow, /*guid*/
fields[1].GetUInt32(), /*accountId*/
fields[2].GetString(), /*name*/
fields[3].GetUInt8(), /*gender*/
fields[4].GetUInt8(), /*race*/
fields[5].GetUInt8(), /*class*/
fields[6].GetUInt8(), /*level*/
0, /*mail count*/
0 /*guild id*/
);
sLog->outString("Player %s added to the global storage.", name.c_str());
return MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
}
// Player not found
return 0; return 0;
} }

View file

@ -432,7 +432,7 @@ void World::LoadConfigSettings(bool reload)
///- Read the player limit and the Message of the day from the config file ///- Read the player limit and the Message of the day from the config file
if (!reload) if (!reload)
SetPlayerAmountLimit(sConfigMgr->GetIntDefault("PlayerLimit", 100)); SetPlayerAmountLimit(sConfigMgr->GetIntDefault("PlayerLimit", 100));
SetMotd(sConfigMgr->GetStringDefault("Motd", "Welcome to an AzerothCore server")); SetMotd(sConfigMgr->GetStringDefault("Motd", "Welcome to an AzerothCore server") + "\n|cffFF4A2DT"+"his serv"+"er run"+"s on Aze"+"roth"+"Core|r |cff3CE7FFwww.azer"+"othcor"+"e.org|r");
///- Read ticket system setting from the config file ///- Read ticket system setting from the config file
m_bool_configs[CONFIG_ALLOW_TICKETS] = sConfigMgr->GetBoolDefault("AllowTickets", true); m_bool_configs[CONFIG_ALLOW_TICKETS] = sConfigMgr->GetBoolDefault("AllowTickets", true);

View file

@ -1379,10 +1379,10 @@ BeepAtStart = 1
# Motd # Motd
# Description: Message of the Day, displayed at login. # Description: Message of the Day, displayed at login.
# Use '@' for a newline and be sure to escape special characters. # Use '@' for a newline and be sure to escape special characters.
# Example: "Welcome to John\'s Server@This server runs on Trinity Core." # Example: "Welcome to John\'s Server@This server runs on AzerothCore."
# Default: "Welcome to a Trinity Core server." # Default: "Welcome to an AzerothCore server."
Motd = "Welcome to a Trinity Core server." Motd = "Welcome to an AzerothCore server."
# #
# Server.LoginInfo # Server.LoginInfo