*The last merge from Mangos TBC. Update to Mangos v0.12.

--HG--
branch : trunk
This commit is contained in:
megamage
2008-12-22 10:59:38 -06:00
parent f7dd2df795
commit 65ef38963d
15 changed files with 214 additions and 171 deletions
+7 -2
View File
@@ -367,10 +367,15 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
return;
}
if ((price < (auction->bid + objmgr.GetAuctionOutBid(auction->bid))) && ((price < auction->buyout) || (auction->buyout == 0)))
// cheating
if(price <= auction->bid)
return;
// price too low for next bid if not buyout
if ((price < auction->buyout || auction->buyout == 0) &&
price < auction->bid + objmgr.GetAuctionOutBid(auction->bid))
{
//auction has already higher bid, client tests it!
//SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???);
return;
}
+18 -25
View File
@@ -937,18 +937,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;
@@ -956,33 +966,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();
std::string oldname = result->Fetch()[1].GetCppString();
delete result;
if(oldname == newname)
{
WorldPacket data(SMSG_CHAR_RENAME, 1);
data << (uint8)CHAR_CREATE_ERROR;
session->SendPacket( &data );
return;
}
// 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;
}
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("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().c_str(),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;
+23 -10
View File
@@ -376,28 +376,41 @@ bool Guild::FillPlayerData(uint64 guid, MemberSlot* memslot)
}
else
{
if(!objmgr.GetPlayerNameByGUID(guid, plName)) // player doesn't exist
return false;
QueryResult *result = CharacterDatabase.PQuery("SELECT name,data,zone,class FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
if(!result)
return false; // player doesn't exist
Field *fields = result->Fetch();
plName = fields[0].GetCppString();
Tokens data = StrSplit(fields[1].GetCppString(), " ");
plLevel = Player::GetUInt32ValueFromArray(data,UNIT_FIELD_LEVEL);
plZone = fields[2].GetUInt32();
plClass = fields[3].GetUInt32();
delete result;
plLevel = Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL, guid);
if(plLevel<1||plLevel>STRONG_MAX_LEVEL) // can be at broken `data` field
{
sLog.outError("Player (GUID: %u) has a broken data in field `characters`.`data`.",GUID_LOPART(guid));
return false;
}
plZone = Player::GetZoneIdFromDB(guid);
QueryResult *result = CharacterDatabase.PQuery("SELECT class FROM characters WHERE guid='%u'", GUID_LOPART(guid));
if(!result)
return false;
plClass = (*result)[0].GetUInt32();
if(!plZone)
{
sLog.outError("Player (GUID: %u) has broken zone-data",GUID_LOPART(guid));
//here it will also try the same, to get the zone from characters-table, but additional it tries to find
plZone = Player::GetZoneIdFromDB(guid);
//the zone through xy coords.. this is a bit redundant, but
//shouldn't be called often
}
if(plClass<CLASS_WARRIOR||plClass>=MAX_CLASSES) // can be at broken `class` field
{
sLog.outError("Player (GUID: %u) has a broken data in field `characters`.`class`.",GUID_LOPART(guid));
return false;
}
delete result;
}
}
+10 -1
View File
@@ -163,8 +163,17 @@ MotionMaster::MoveTargetedHome()
}
else if(i_owner->GetTypeId()==TYPEID_UNIT && ((Creature*)i_owner)->GetCharmerOrOwnerGUID())
{
sLog.outError("Pet or controlled creature (Entry: %u GUID: %u) attempt targeted home",
DEBUG_LOG("Pet or controlled creature (Entry: %u GUID: %u) targeting home",
i_owner->GetEntry(), i_owner->GetGUIDLow() );
Unit *target = ((Creature*)i_owner)->GetCharmerOrOwner();
if(target)
{
i_owner->addUnitState(UNIT_STAT_FOLLOW);
DEBUG_LOG("Following %s (GUID: %u)",
target->GetTypeId()==TYPEID_PLAYER ? "player" : "creature",
target->GetTypeId()==TYPEID_PLAYER ? target->GetGUIDLow() : ((Creature*)target)->GetDBTableGUIDLow() );
Mutate(new TargetedMovementGenerator<Creature>(*target,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE));
}
}
else
{
+2
View File
@@ -2194,6 +2194,8 @@ void ObjectMgr::LoadPlayerInfo()
{
barGoLink bar( 1 );
bar.step();
sLog.outString();
sLog.outString( ">> Loaded %u custom player create items", count );
}
+6 -1
View File
@@ -27,6 +27,12 @@
#include "Common.h"
// Note: this include need for be sure have full definition of class WorldSession
// if this class definition not complite then VS for x64 release use different size for
// struct OpcodeHandler in this header and Opcode.cpp and get totally wrong data from
// table opcodeTable in source when Opcode.h included but WorldSession.h not included
#include "WorldSession.h"
/// List of Opcodes
enum Opcodes
{
@@ -1104,7 +1110,6 @@ enum SessionStatus
STATUS_NEVER ///< Opcode not accepted from client (deprecated or server side only)
};
class WorldSession;
class WorldPacket;
struct OpcodeHandler
+1 -1
View File
@@ -113,7 +113,7 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data)
// TODO: find correct opcode
if(_player->getLevel() < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL))
{
SendNotification(LANG_ARENA_ONE_TOOLOW, 70);
SendNotification(LANG_ARENA_ONE_TOOLOW, sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL));
return;
}
+2 -2
View File
@@ -11641,9 +11641,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)
+3 -3
View File
@@ -2161,15 +2161,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;
}
+12 -5
View File
@@ -10274,8 +10274,12 @@ bool Unit::CanHaveThreatList() const
if( !isAlive() )
return false;
// pets and totems can not have threat list
if( ((Creature*)this)->isPet() || ((Creature*)this)->isTotem() )
// totems can not have threat list
if( ((Creature*)this)->isTotem() )
return false;
// pets can not have a threat list, unless they are controlled by a creature
if( ((Creature*)this)->isPet() && IS_PLAYER_GUID(((Pet*)this)->GetOwnerGUID()) )
return false;
return true;
@@ -10454,9 +10458,12 @@ int32 Unit::CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_inde
uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0;
int32 level = int32(getLevel()) - int32(spellProto->spellLevel);
if (level > spellProto->maxLevel && spellProto->maxLevel > 0)
level = spellProto->maxLevel;
int32 level = int32(getLevel());
if (level > (int32)spellProto->maxLevel && spellProto->maxLevel > 0)
level = (int32)spellProto->maxLevel;
else if (level < (int32)spellProto->baseLevel)
level = (int32)spellProto->baseLevel;
level-= (int32)spellProto->spellLevel;
float basePointsPerLevel = spellProto->EffectRealPointsPerLevel[effect_index];
float randomPointsPerLevel = spellProto->EffectDicePerLevel[effect_index];
+14
View File
@@ -57,27 +57,41 @@ class TRINITY_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);
+106 -112
View File
@@ -23,84 +23,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 Trinity::QueryCallback<Class>(object, method), itr->second));
return true;
ASYNC_QUERY_BODY(sql, itr)
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::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 Trinity::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 Trinity::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 Trinity::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 Trinity::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 Trinity::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 Trinity::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second));
return true;
ASYNC_QUERY_BODY(sql, itr)
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::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 Trinity::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 Trinity::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 Trinity::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);
}
@@ -108,20 +138,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);
}
@@ -129,41 +146,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);
}
@@ -171,43 +172,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 Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second);
return true;
ASYNC_DELAYHOLDER_BODY(holder, itr)
return holder->Execute(new Trinity::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 Trinity::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 Trinity::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
+1 -1
View File
@@ -42,7 +42,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
+3 -2
View File
@@ -81,15 +81,16 @@ void SqlResultQueue::Update()
}
}
void SqlQueryHolder::Execute(Trinity::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue)
bool SqlQueryHolder::Execute(Trinity::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)
+1 -1
View File
@@ -106,7 +106,7 @@ class SqlQueryHolder
void SetSize(size_t size);
QueryResult* GetResult(size_t index);
void SetResult(size_t index, QueryResult *result);
void Execute(Trinity::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue);
bool Execute(Trinity::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue);
};
class SqlQueryHolderEx : public SqlOperation