mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
Merge branch 'master' into 303
Conflicts: src/game/CharacterHandler.cpp
This commit is contained in:
commit
4c258e20a1
10 changed files with 161 additions and 175 deletions
|
|
@ -956,18 +956,28 @@ void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data)
|
|||
return;
|
||||
}
|
||||
|
||||
CharacterDatabase.escape_string(newname);
|
||||
std::string escaped_newname = newname;
|
||||
CharacterDatabase.escape_string(escaped_newname);
|
||||
|
||||
CharacterDatabase.AsyncPQuery(&WorldSession::HandleChangePlayerNameOpcodeCallBack, GUID_LOPART(guid), newname, "SELECT guid, at_login, name FROM characters WHERE guid = '%u' XOR name = '%s'", GUID_LOPART(guid), newname.c_str());
|
||||
// make sure that the character belongs to the current account, that rename at login is enabled
|
||||
// and that there is no character with the desired new name
|
||||
CharacterDatabase.AsyncPQuery(&WorldSession::HandleChangePlayerNameOpcodeCallBack,
|
||||
GetAccountId(), newname,
|
||||
"SELECT guid, name FROM characters WHERE guid = %d AND account = %d AND (at_login & %d) = %d AND NOT EXISTS (SELECT NULL FROM characters WHERE name = '%s')",
|
||||
GUID_LOPART(guid), GetAccountId(), AT_LOGIN_RENAME, AT_LOGIN_RENAME, escaped_newname.c_str()
|
||||
);
|
||||
}
|
||||
|
||||
void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uint32 accountId, std::string newname)
|
||||
{
|
||||
WorldSession * session = sWorld.FindSession(accountId);
|
||||
if(!session)
|
||||
{
|
||||
if(result) delete result;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result || result->GetRowCount() != 1)
|
||||
if (!result)
|
||||
{
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||
data << uint8(CHAR_CREATE_ERROR);
|
||||
|
|
@ -975,33 +985,16 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uin
|
|||
return;
|
||||
}
|
||||
|
||||
Field *fields = result->Fetch();
|
||||
uint32 guidLow = fields[0].GetUInt32();
|
||||
uint32 guidLow = result->Fetch()[0].GetUInt32();
|
||||
uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
|
||||
uint32 at_loginFlags = fields[1].GetUInt32();
|
||||
std::string oldname = fields[2].GetCppString();
|
||||
delete result;
|
||||
if(oldname == newname)
|
||||
{
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||
data << uint8(CHAR_CREATE_ERROR);
|
||||
session->SendPacket( &data );
|
||||
return;
|
||||
}
|
||||
std::string oldname = result->Fetch()[1].GetCppString();
|
||||
|
||||
// we have to check character at_login_flag & AT_LOGIN_RENAME also (fake packets hehe)
|
||||
if (!(at_loginFlags & AT_LOGIN_RENAME))
|
||||
{
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||
data << uint8(CHAR_CREATE_ERROR);
|
||||
session->SendPacket( &data );
|
||||
return;
|
||||
}
|
||||
delete result;
|
||||
|
||||
CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_RENAME), guidLow);
|
||||
CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow);
|
||||
|
||||
sLog.outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s", session->GetAccountId(), session->GetRemoteAddress(), oldname.c_str(), guidLow, newname.c_str());
|
||||
sLog.outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s", session->GetAccountId(), session->GetRemoteAddress().c_str(), oldname.c_str(), guidLow, newname.c_str());
|
||||
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1+8+(newname.size()+1));
|
||||
data << uint8(RESPONSE_SUCCESS);
|
||||
|
|
|
|||
|
|
@ -317,8 +317,8 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid)
|
|||
|
||||
QueryResult *result = CharacterDatabase.PQuery(
|
||||
"SELECT ownerguid, name, "
|
||||
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs "
|
||||
"type "
|
||||
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, "
|
||||
" type "
|
||||
"FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid), GUID_LOPART(petitionguid));
|
||||
|
||||
if(result)
|
||||
|
|
@ -449,17 +449,14 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
|
|||
|
||||
Field *fields;
|
||||
uint64 petitionguid;
|
||||
uint32 type;
|
||||
uint8 unk;
|
||||
uint64 ownerguid;
|
||||
recv_data >> petitionguid; // petition guid
|
||||
recv_data >> unk;
|
||||
|
||||
uint8 signs = 0;
|
||||
|
||||
QueryResult *result = CharacterDatabase.PQuery(
|
||||
"SELECT ownerguid, "
|
||||
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs "
|
||||
" (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, "
|
||||
" type "
|
||||
"FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid), GUID_LOPART(petitionguid));
|
||||
|
||||
if(!result)
|
||||
|
|
@ -469,8 +466,9 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
|
|||
}
|
||||
|
||||
fields = result->Fetch();
|
||||
ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
signs = fields[1].GetUInt8();
|
||||
uint64 ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
uint8 signs = fields[1].GetUInt8();
|
||||
uint32 type = fields[2].GetUInt32();
|
||||
|
||||
delete result;
|
||||
|
||||
|
|
@ -488,20 +486,6 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data)
|
|||
return;
|
||||
}
|
||||
|
||||
QueryResult *result2 = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid));
|
||||
|
||||
if(result2)
|
||||
{
|
||||
Field* fields = result2->Fetch();
|
||||
type = fields[0].GetUInt32();
|
||||
delete result2;
|
||||
}
|
||||
else
|
||||
{
|
||||
sLog.outDebug("CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionguid));
|
||||
return;
|
||||
}
|
||||
|
||||
if(type != 9)
|
||||
{
|
||||
if(_player->getLevel() < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL))
|
||||
|
|
|
|||
|
|
@ -11654,9 +11654,9 @@ void Player::ApplyEnchantment(Item *item,EnchantmentSlot slot,bool apply, bool a
|
|||
{
|
||||
if(apply)
|
||||
{
|
||||
int32 basepoints = int32(enchant_amount);
|
||||
int32 basepoints = 0;
|
||||
// Random Property Exist - try found basepoints for spell (basepoints depends from item suffix factor)
|
||||
if (item->GetItemRandomPropertyId() !=0 && !enchant_amount)
|
||||
if (item->GetItemRandomPropertyId())
|
||||
{
|
||||
ItemRandomSuffixEntry const *item_rand = sItemRandomSuffixStore.LookupEntry(abs(item->GetItemRandomPropertyId()));
|
||||
if (item_rand)
|
||||
|
|
@ -13734,12 +13734,12 @@ void Player::_LoadArenaTeamInfo(QueryResult *result)
|
|||
ArenaTeam* aTeam = objmgr.GetArenaTeamById(arenateamid);
|
||||
uint8 arenaSlot = aTeam->GetSlot();
|
||||
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 3] = arenateamid; // TeamID
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 3 + 1] = ((aTeam->GetCaptain() == GetGUID()) ? (uint32)0 : (uint32)1); // Captain 0, member 1
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 3 + 2] = played_week; // Played Week
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 3 + 3] = played_season; // Played Season
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 3 + 4] = 0; // Unk
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 3 + 5] = personal_rating; // Personal Rating
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 6] = arenateamid; // TeamID
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 6 + 1] = ((aTeam->GetCaptain() == GetGUID()) ? (uint32)0 : (uint32)1); // Captain 0, member 1
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 6 + 2] = played_week; // Played Week
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 6 + 3] = played_season; // Played Season
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 6 + 4] = 0; // Unk
|
||||
m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + arenaSlot * 6 + 5] = personal_rating; // Personal Rating
|
||||
|
||||
}while (result->NextRow());
|
||||
delete result;
|
||||
|
|
|
|||
|
|
@ -2183,15 +2183,15 @@ bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg)
|
|||
}
|
||||
case SPELL_EFFECT_LEARN_SPELL:
|
||||
{
|
||||
SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[0]);
|
||||
SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[i]);
|
||||
if( !IsSpellValid(spellInfo2,pl,msg) )
|
||||
{
|
||||
if(msg)
|
||||
{
|
||||
if(pl)
|
||||
ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]);
|
||||
ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
|
||||
else
|
||||
sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]);
|
||||
sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,27 +55,41 @@ class MANGOS_DLL_SPEC Database
|
|||
QueryResult* PQuery(const char *format,...) ATTR_PRINTF(2,3);
|
||||
|
||||
/// Async queries and query holders, implemented in DatabaseImpl.h
|
||||
|
||||
// Query / member
|
||||
template<class Class>
|
||||
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql);
|
||||
template<class Class, typename ParamType1>
|
||||
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
|
||||
template<class Class, typename ParamType1, typename ParamType2>
|
||||
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
|
||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
|
||||
// Query / static
|
||||
template<typename ParamType1>
|
||||
bool AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
|
||||
template<typename ParamType1, typename ParamType2>
|
||||
bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
|
||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
|
||||
// PQuery / member
|
||||
template<class Class>
|
||||
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) ATTR_PRINTF(4,5);
|
||||
template<class Class, typename ParamType1>
|
||||
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6);
|
||||
template<class Class, typename ParamType1, typename ParamType2>
|
||||
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6);
|
||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(5,6);
|
||||
// PQuery / static
|
||||
template<typename ParamType1>
|
||||
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6);
|
||||
template<typename ParamType1, typename ParamType2>
|
||||
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6);
|
||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(5,6);
|
||||
template<class Class>
|
||||
// QueryHolder
|
||||
bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder);
|
||||
template<class Class, typename ParamType1>
|
||||
bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1);
|
||||
|
|
|
|||
|
|
@ -21,84 +21,114 @@
|
|||
|
||||
/// Function body definitions for the template function members of the Database class
|
||||
|
||||
#define ASYNC_QUERY_BODY(sql, queue_itr) \
|
||||
if (!sql) return false; \
|
||||
\
|
||||
QueryQueues::iterator queue_itr; \
|
||||
\
|
||||
{ \
|
||||
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); \
|
||||
queue_itr = m_queryQueues.find(queryThread); \
|
||||
if (queue_itr == m_queryQueues.end()) return false; \
|
||||
}
|
||||
|
||||
#define ASYNC_PQUERY_BODY(format, szQuery) \
|
||||
if(!format) return false; \
|
||||
\
|
||||
char szQuery [MAX_QUERY_LEN]; \
|
||||
\
|
||||
{ \
|
||||
va_list ap; \
|
||||
\
|
||||
va_start(ap, format); \
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); \
|
||||
va_end(ap); \
|
||||
\
|
||||
if(res==-1) \
|
||||
{ \
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format); \
|
||||
return false; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ASYNC_DELAYHOLDER_BODY(holder, queue_itr) \
|
||||
if (!holder) return false; \
|
||||
\
|
||||
QueryQueues::iterator queue_itr; \
|
||||
\
|
||||
{ \
|
||||
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); \
|
||||
queue_itr = m_queryQueues.find(queryThread); \
|
||||
if (queue_itr == m_queryQueues.end()) return false; \
|
||||
}
|
||||
|
||||
// -- Query / member --
|
||||
|
||||
template<class Class>
|
||||
bool
|
||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql)
|
||||
{
|
||||
if (!sql) return false;
|
||||
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
|
||||
QueryQueues::iterator itr = m_queryQueues.find(queryThread);
|
||||
if (itr == m_queryQueues.end()) return false;
|
||||
m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class>(object, method), itr->second));
|
||||
return true;
|
||||
ASYNC_QUERY_BODY(sql, itr)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class>(object, method), itr->second));
|
||||
}
|
||||
|
||||
template<class Class, typename ParamType1>
|
||||
bool
|
||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
|
||||
{
|
||||
if (!sql) return false;
|
||||
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
|
||||
QueryQueues::iterator itr = m_queryQueues.find(queryThread);
|
||||
if (itr == m_queryQueues.end()) return false;
|
||||
m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), itr->second));
|
||||
return true;
|
||||
ASYNC_QUERY_BODY(sql, itr)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), itr->second));
|
||||
}
|
||||
|
||||
template<class Class, typename ParamType1, typename ParamType2>
|
||||
bool
|
||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
|
||||
{
|
||||
if (!sql) return false;
|
||||
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
|
||||
QueryQueues::iterator itr = m_queryQueues.find(queryThread);
|
||||
if (itr == m_queryQueues.end()) return false;
|
||||
m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), itr->second));
|
||||
return true;
|
||||
ASYNC_QUERY_BODY(sql, itr)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), itr->second));
|
||||
}
|
||||
|
||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool
|
||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
|
||||
{
|
||||
ASYNC_QUERY_BODY(sql, itr)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult*)NULL, param1, param2, param3), itr->second));
|
||||
}
|
||||
|
||||
// -- Query / static --
|
||||
|
||||
template<typename ParamType1>
|
||||
bool
|
||||
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
|
||||
{
|
||||
if (!sql) return false;
|
||||
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
|
||||
QueryQueues::iterator itr = m_queryQueues.find(queryThread);
|
||||
if (itr == m_queryQueues.end()) return false;
|
||||
m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second));
|
||||
return true;
|
||||
ASYNC_QUERY_BODY(sql, itr)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second));
|
||||
}
|
||||
|
||||
template<typename ParamType1, typename ParamType2>
|
||||
bool
|
||||
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
|
||||
{
|
||||
if (!sql) return false;
|
||||
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
|
||||
QueryQueues::iterator itr = m_queryQueues.find(queryThread);
|
||||
if (itr == m_queryQueues.end()) return false;
|
||||
m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), itr->second));
|
||||
return true;
|
||||
ASYNC_QUERY_BODY(sql, itr)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), itr->second));
|
||||
}
|
||||
|
||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool
|
||||
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
|
||||
{
|
||||
ASYNC_QUERY_BODY(sql, itr)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult*)NULL, param1, param2, param3), itr->second));
|
||||
}
|
||||
|
||||
// -- PQuery / member --
|
||||
|
||||
template<class Class>
|
||||
bool
|
||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...)
|
||||
{
|
||||
if(!format) return false;
|
||||
|
||||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
}
|
||||
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(object, method, szQuery);
|
||||
}
|
||||
|
||||
|
|
@ -106,20 +136,7 @@ template<class Class, typename ParamType1>
|
|||
bool
|
||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
|
||||
{
|
||||
if(!format) return false;
|
||||
|
||||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
}
|
||||
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(object, method, param1, szQuery);
|
||||
}
|
||||
|
||||
|
|
@ -127,41 +144,25 @@ template<class Class, typename ParamType1, typename ParamType2>
|
|||
bool
|
||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
|
||||
{
|
||||
if(!format) return false;
|
||||
|
||||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
}
|
||||
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(object, method, param1, param2, szQuery);
|
||||
}
|
||||
|
||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool
|
||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
|
||||
{
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(object, method, param1, param2, param3, szQuery);
|
||||
}
|
||||
|
||||
// -- PQuery / static --
|
||||
|
||||
template<typename ParamType1>
|
||||
bool
|
||||
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
|
||||
{
|
||||
if(!format) return false;
|
||||
|
||||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
}
|
||||
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(method, param1, szQuery);
|
||||
}
|
||||
|
||||
|
|
@ -169,43 +170,36 @@ template<typename ParamType1, typename ParamType2>
|
|||
bool
|
||||
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
|
||||
{
|
||||
if(!format) return false;
|
||||
|
||||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
}
|
||||
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(method, param1, param2, szQuery);
|
||||
}
|
||||
|
||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool
|
||||
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
|
||||
{
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(method, param1, param2, param3, szQuery);
|
||||
}
|
||||
|
||||
// -- QueryHolder --
|
||||
|
||||
template<class Class>
|
||||
bool
|
||||
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder)
|
||||
{
|
||||
if (!holder) return false;
|
||||
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
|
||||
QueryQueues::iterator itr = m_queryQueues.find(queryThread);
|
||||
if (itr == m_queryQueues.end()) return false;
|
||||
holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second);
|
||||
return true;
|
||||
ASYNC_DELAYHOLDER_BODY(holder, itr)
|
||||
return holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second);
|
||||
}
|
||||
|
||||
template<class Class, typename ParamType1>
|
||||
bool
|
||||
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1)
|
||||
{
|
||||
if (!holder) return false;
|
||||
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
|
||||
QueryQueues::iterator itr = m_queryQueues.find(queryThread);
|
||||
if (itr == m_queryQueues.end()) return false;
|
||||
holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, itr->second);
|
||||
return true;
|
||||
ASYNC_DELAYHOLDER_BODY(holder, itr)
|
||||
return holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, itr->second);
|
||||
}
|
||||
|
||||
#undef ASYNC_QUERY_BODY
|
||||
#undef ASYNC_PQUERY_BODY
|
||||
#undef ASYNC_DELAYHOLDER_BODY
|
||||
|
|
@ -40,7 +40,7 @@ class SqlDelayThread : public ZThread::Runnable
|
|||
SqlDelayThread(Database* db);
|
||||
|
||||
///< Put sql statement to delay queue
|
||||
inline void Delay(SqlOperation* sql) { m_sqlQueue.add(sql); }
|
||||
inline bool Delay(SqlOperation* sql) { m_sqlQueue.add(sql); return true; }
|
||||
|
||||
virtual void Stop(); ///< Stop event
|
||||
virtual void run(); ///< Main Thread loop
|
||||
|
|
|
|||
|
|
@ -79,15 +79,16 @@ void SqlResultQueue::Update()
|
|||
}
|
||||
}
|
||||
|
||||
void SqlQueryHolder::Execute(MaNGOS::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue)
|
||||
bool SqlQueryHolder::Execute(MaNGOS::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue)
|
||||
{
|
||||
if(!callback || !thread || !queue)
|
||||
return;
|
||||
return false;
|
||||
|
||||
/// delay the execution of the queries, sync them with the delay thread
|
||||
/// which will in turn resync on execution (via the queue) and call back
|
||||
SqlQueryHolderEx *holderEx = new SqlQueryHolderEx(this, callback, queue);
|
||||
thread->Delay(holderEx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqlQueryHolder::SetQuery(size_t index, const char *sql)
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class SqlQueryHolder
|
|||
void SetSize(size_t size);
|
||||
QueryResult* GetResult(size_t index);
|
||||
void SetResult(size_t index, QueryResult *result);
|
||||
void Execute(MaNGOS::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue);
|
||||
bool Execute(MaNGOS::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue);
|
||||
};
|
||||
|
||||
class SqlQueryHolderEx : public SqlOperation
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "6913"
|
||||
#define REVISION_NR "6920"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue