*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; 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! //auction has already higher bid, client tests it!
//SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???);
return; return;
} }
+16 -23
View File
@@ -937,18 +937,28 @@ void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data)
return; 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) void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uint32 accountId, std::string newname)
{ {
WorldSession * session = sWorld.FindSession(accountId); WorldSession * session = sWorld.FindSession(accountId);
if(!session) if(!session)
{
if(result) delete result;
return; return;
}
if (!result || result->GetRowCount() != 1) if (!result)
{ {
WorldPacket data(SMSG_CHAR_RENAME, 1); WorldPacket data(SMSG_CHAR_RENAME, 1);
data << (uint8)CHAR_CREATE_ERROR; data << (uint8)CHAR_CREATE_ERROR;
@@ -956,28 +966,11 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uin
return; return;
} }
Field *fields = result->Fetch(); uint32 guidLow = result->Fetch()[0].GetUInt32();
uint32 guidLow = fields[0].GetUInt32();
uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER); uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
uint32 at_loginFlags = fields[1].GetUInt32(); std::string oldname = result->Fetch()[1].GetCppString();
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;
}
// we have to check character at_login_flag & AT_LOGIN_RENAME also (fake packets hehe) delete result;
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); CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow);
+23 -10
View File
@@ -376,28 +376,41 @@ bool Guild::FillPlayerData(uint64 guid, MemberSlot* memslot)
} }
else else
{ {
if(!objmgr.GetPlayerNameByGUID(guid, plName)) // player doesn't exist QueryResult *result = CharacterDatabase.PQuery("SELECT name,data,zone,class FROM characters WHERE guid = '%u'", GUID_LOPART(guid));
return false; 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 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)); sLog.outError("Player (GUID: %u) has a broken data in field `characters`.`data`.",GUID_LOPART(guid));
return false; return false;
} }
plZone = Player::GetZoneIdFromDB(guid);
QueryResult *result = CharacterDatabase.PQuery("SELECT class FROM characters WHERE guid='%u'", GUID_LOPART(guid)); if(!plZone)
if(!result) {
return false; sLog.outError("Player (GUID: %u) has broken zone-data",GUID_LOPART(guid));
plClass = (*result)[0].GetUInt32(); //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 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)); sLog.outError("Player (GUID: %u) has a broken data in field `characters`.`class`.",GUID_LOPART(guid));
return false; 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()) 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() ); 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 else
{ {
+2
View File
@@ -2194,6 +2194,8 @@ void ObjectMgr::LoadPlayerInfo()
{ {
barGoLink bar( 1 ); barGoLink bar( 1 );
bar.step();
sLog.outString(); sLog.outString();
sLog.outString( ">> Loaded %u custom player create items", count ); sLog.outString( ">> Loaded %u custom player create items", count );
} }
+6 -1
View File
@@ -27,6 +27,12 @@
#include "Common.h" #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 /// List of Opcodes
enum Opcodes enum Opcodes
{ {
@@ -1104,7 +1110,6 @@ enum SessionStatus
STATUS_NEVER ///< Opcode not accepted from client (deprecated or server side only) STATUS_NEVER ///< Opcode not accepted from client (deprecated or server side only)
}; };
class WorldSession;
class WorldPacket; class WorldPacket;
struct OpcodeHandler struct OpcodeHandler
+1 -1
View File
@@ -113,7 +113,7 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data)
// TODO: find correct opcode // TODO: find correct opcode
if(_player->getLevel() < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)) 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; return;
} }
+2 -2
View File
@@ -11641,9 +11641,9 @@ void Player::ApplyEnchantment(Item *item,EnchantmentSlot slot,bool apply, bool a
{ {
if(apply) if(apply)
{ {
int32 basepoints = int32(enchant_amount); int32 basepoints = 0;
// Random Property Exist - try found basepoints for spell (basepoints depends from item suffix factor) // 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())); ItemRandomSuffixEntry const *item_rand = sItemRandomSuffixStore.LookupEntry(abs(item->GetItemRandomPropertyId()));
if (item_rand) 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: 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( !IsSpellValid(spellInfo2,pl,msg) )
{ {
if(msg) if(msg)
{ {
if(pl) 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 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; return false;
} }
+12 -5
View File
@@ -10274,8 +10274,12 @@ bool Unit::CanHaveThreatList() const
if( !isAlive() ) if( !isAlive() )
return false; return false;
// pets and totems can not have threat list // totems can not have threat list
if( ((Creature*)this)->isPet() || ((Creature*)this)->isTotem() ) 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 false;
return true; return true;
@@ -10454,9 +10458,12 @@ int32 Unit::CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_inde
uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0; uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0;
int32 level = int32(getLevel()) - int32(spellProto->spellLevel); int32 level = int32(getLevel());
if (level > spellProto->maxLevel && spellProto->maxLevel > 0) if (level > (int32)spellProto->maxLevel && spellProto->maxLevel > 0)
level = spellProto->maxLevel; 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 basePointsPerLevel = spellProto->EffectRealPointsPerLevel[effect_index];
float randomPointsPerLevel = spellProto->EffectDicePerLevel[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); QueryResult* PQuery(const char *format,...) ATTR_PRINTF(2,3);
/// Async queries and query holders, implemented in DatabaseImpl.h /// Async queries and query holders, implemented in DatabaseImpl.h
// Query / member
template<class Class> template<class Class>
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql); bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql);
template<class Class, typename ParamType1> template<class Class, typename ParamType1>
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql); bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
template<class Class, typename ParamType1, typename ParamType2> template<class Class, typename ParamType1, typename ParamType2>
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql); 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> template<typename ParamType1>
bool AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql); bool AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
template<typename ParamType1, typename ParamType2> template<typename ParamType1, typename ParamType2>
bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql); 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> template<class Class>
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) ATTR_PRINTF(4,5); bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) ATTR_PRINTF(4,5);
template<class Class, typename ParamType1> template<class Class, typename ParamType1>
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6); 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> 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); 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> template<typename ParamType1>
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6); bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6);
template<typename ParamType1, typename ParamType2> template<typename ParamType1, typename ParamType2>
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6); 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> template<class Class>
// QueryHolder
bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder); bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder);
template<class Class, typename ParamType1> template<class Class, typename ParamType1>
bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1); 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 /// 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> template<class Class>
bool bool
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql) Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql)
{ {
if (!sql) return false; ASYNC_QUERY_BODY(sql, itr)
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class>(object, method), itr->second));
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;
} }
template<class Class, typename ParamType1> template<class Class, typename ParamType1>
bool bool
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql) Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
{ {
if (!sql) return false; ASYNC_QUERY_BODY(sql, itr)
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), itr->second));
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;
} }
template<class Class, typename ParamType1, typename ParamType2> template<class Class, typename ParamType1, typename ParamType2>
bool bool
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
{ {
if (!sql) return false; ASYNC_QUERY_BODY(sql, itr)
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), itr->second));
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;
} }
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> template<typename ParamType1>
bool bool
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql) Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
{ {
if (!sql) return false; ASYNC_QUERY_BODY(sql, itr)
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second));
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;
} }
template<typename ParamType1, typename ParamType2> template<typename ParamType1, typename ParamType2>
bool bool
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
{ {
if (!sql) return false; ASYNC_QUERY_BODY(sql, itr)
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), itr->second));
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;
} }
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> template<class Class>
bool bool
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...)
{ {
if(!format) return false; ASYNC_PQUERY_BODY(format, szQuery)
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;
}
return AsyncQuery(object, method, szQuery); return AsyncQuery(object, method, szQuery);
} }
@@ -108,20 +138,7 @@ template<class Class, typename ParamType1>
bool bool
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
{ {
if(!format) return false; ASYNC_PQUERY_BODY(format, szQuery)
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;
}
return AsyncQuery(object, method, param1, szQuery); return AsyncQuery(object, method, param1, szQuery);
} }
@@ -129,41 +146,25 @@ template<class Class, typename ParamType1, typename ParamType2>
bool bool
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
{ {
if(!format) return false; ASYNC_PQUERY_BODY(format, szQuery)
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;
}
return AsyncQuery(object, method, param1, param2, 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> template<typename ParamType1>
bool bool
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
{ {
if(!format) return false; ASYNC_PQUERY_BODY(format, szQuery)
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;
}
return AsyncQuery(method, param1, szQuery); return AsyncQuery(method, param1, szQuery);
} }
@@ -171,43 +172,36 @@ template<typename ParamType1, typename ParamType2>
bool bool
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
{ {
if(!format) return false; ASYNC_PQUERY_BODY(format, szQuery)
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;
}
return AsyncQuery(method, param1, param2, 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> template<class Class>
bool bool
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder) Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder)
{ {
if (!holder) return false; ASYNC_DELAYHOLDER_BODY(holder, itr)
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second);
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;
} }
template<class Class, typename ParamType1> template<class Class, typename ParamType1>
bool bool
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1) Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1)
{ {
if (!holder) return false; ASYNC_DELAYHOLDER_BODY(holder, itr)
ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, itr->second);
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;
} }
#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); SqlDelayThread(Database* db);
///< Put sql statement to delay queue ///< 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 Stop(); ///< Stop event
virtual void run(); ///< Main Thread loop 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) if(!callback || !thread || !queue)
return; return false;
/// delay the execution of the queries, sync them with the delay thread /// 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 /// which will in turn resync on execution (via the queue) and call back
SqlQueryHolderEx *holderEx = new SqlQueryHolderEx(this, callback, queue); SqlQueryHolderEx *holderEx = new SqlQueryHolderEx(this, callback, queue);
thread->Delay(holderEx); thread->Delay(holderEx);
return true;
} }
bool SqlQueryHolder::SetQuery(size_t index, const char *sql) bool SqlQueryHolder::SetQuery(size_t index, const char *sql)
+1 -1
View File
@@ -106,7 +106,7 @@ class SqlQueryHolder
void SetSize(size_t size); void SetSize(size_t size);
QueryResult* GetResult(size_t index); QueryResult* GetResult(size_t index);
void SetResult(size_t index, QueryResult *result); 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 class SqlQueryHolderEx : public SqlOperation