aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/AuctionHouse.cpp9
-rw-r--r--src/game/CharacterHandler.cpp45
-rw-r--r--src/game/Guild.cpp33
-rw-r--r--src/game/MotionMaster.cpp11
-rw-r--r--src/game/ObjectMgr.cpp4
-rw-r--r--src/game/Opcodes.h7
-rw-r--r--src/game/PetitionsHandler.cpp2
-rw-r--r--src/game/Player.cpp4
-rw-r--r--src/game/SpellMgr.cpp6
-rw-r--r--src/game/Unit.cpp17
-rw-r--r--src/shared/Database/Database.h18
-rw-r--r--src/shared/Database/DatabaseImpl.h218
-rw-r--r--src/shared/Database/SqlDelayThread.h6
-rw-r--r--src/shared/Database/SqlOperations.cpp5
-rw-r--r--src/shared/Database/SqlOperations.h2
15 files changed, 215 insertions, 172 deletions
diff --git a/src/game/AuctionHouse.cpp b/src/game/AuctionHouse.cpp
index 8a2ce27d24d..71a8bb495b4 100644
--- a/src/game/AuctionHouse.cpp
+++ b/src/game/AuctionHouse.cpp
@@ -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;
}
diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp
index f5d0ff73bbf..aa884ddd2df 100644
--- a/src/game/CharacterHandler.cpp
+++ b/src/game/CharacterHandler.cpp
@@ -937,32 +937,28 @@ void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data)
return;
}
- CharacterDatabase.escape_string(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());
+ std::string escaped_newname = newname;
+ CharacterDatabase.escape_string(escaped_newname);
+
+ // 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)
- return;
-
- if (!result || result->GetRowCount() != 1)
{
- WorldPacket data(SMSG_CHAR_RENAME, 1);
- data << (uint8)CHAR_CREATE_ERROR;
- session->SendPacket( &data );
+ if(result) delete result;
return;
}
- Field *fields = result->Fetch();
- uint32 guidLow = fields[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)
+ if (!result)
{
WorldPacket data(SMSG_CHAR_RENAME, 1);
data << (uint8)CHAR_CREATE_ERROR;
@@ -970,19 +966,16 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uin
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;
- }
+ uint32 guidLow = result->Fetch()[0].GetUInt32();
+ uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
+ std::string oldname = result->Fetch()[1].GetCppString();
+
+ 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("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;
diff --git a/src/game/Guild.cpp b/src/game/Guild.cpp
index df2554db9ea..897110afe55 100644
--- a/src/game/Guild.cpp
+++ b/src/game/Guild.cpp
@@ -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;
}
}
diff --git a/src/game/MotionMaster.cpp b/src/game/MotionMaster.cpp
index 4b667ad9ccd..36bdbbb3a01 100644
--- a/src/game/MotionMaster.cpp
+++ b/src/game/MotionMaster.cpp
@@ -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
{
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index 06bc3b95304..594cfaf0877 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -640,7 +640,7 @@ void ObjectMgr::LoadCreatureLocales()
sLog.outString();
sLog.outString( ">> Loaded %u creature locale strings", mCreatureLocaleMap.size() );
}
-
+
void ObjectMgr::LoadNpcOptionLocales()
{
mNpcOptionLocaleMap.clear(); // need for reload case
@@ -2194,6 +2194,8 @@ void ObjectMgr::LoadPlayerInfo()
{
barGoLink bar( 1 );
+ bar.step();
+
sLog.outString();
sLog.outString( ">> Loaded %u custom player create items", count );
}
diff --git a/src/game/Opcodes.h b/src/game/Opcodes.h
index 457058b957c..202166a57a0 100644
--- a/src/game/Opcodes.h
+++ b/src/game/Opcodes.h
@@ -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
diff --git a/src/game/PetitionsHandler.cpp b/src/game/PetitionsHandler.cpp
index 52e6559073b..8fc18b1c259 100644
--- a/src/game/PetitionsHandler.cpp
+++ b/src/game/PetitionsHandler.cpp
@@ -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;
}
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index 314e6c5ac09..1f3e4e120f9 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -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)
diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp
index 18fcf5ecdfa..43bb112360c 100644
--- a/src/game/SpellMgr.cpp
+++ b/src/game/SpellMgr.cpp
@@ -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;
}
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 6541a098922..50691592983 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -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];
diff --git a/src/shared/Database/Database.h b/src/shared/Database/Database.h
index dc3eb174727..30d7193801e 100644
--- a/src/shared/Database/Database.h
+++ b/src/shared/Database/Database.h
@@ -10,12 +10,12 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DATABASE_H
@@ -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);
diff --git a/src/shared/Database/DatabaseImpl.h b/src/shared/Database/DatabaseImpl.h
index 175de989d75..85ce1aa3ec1 100644
--- a/src/shared/Database/DatabaseImpl.h
+++ b/src/shared/Database/DatabaseImpl.h
@@ -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<class Class>
+template<typename ParamType1, typename ParamType2, typename ParamType3>
bool
-Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...)
+Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
{
- 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);
+ 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));
+}
- if(res==-1)
- {
- sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
- return false;
- }
+// -- PQuery / member --
+template<class Class>
+bool
+Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...)
+{
+ 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<typename ParamType1>
+template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
bool
-Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
+Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, 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);
+ ASYNC_PQUERY_BODY(format, szQuery)
+ return AsyncQuery(object, method, param1, param2, param3, szQuery);
+}
- if(res==-1)
- {
- sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
- return false;
- }
+// -- PQuery / static --
+template<typename ParamType1>
+bool
+Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
+{
+ 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
diff --git a/src/shared/Database/SqlDelayThread.h b/src/shared/Database/SqlDelayThread.h
index fece5d719f6..707a3cab941 100644
--- a/src/shared/Database/SqlDelayThread.h
+++ b/src/shared/Database/SqlDelayThread.h
@@ -10,12 +10,12 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __SQLDELAYTHREAD_H
@@ -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
diff --git a/src/shared/Database/SqlOperations.cpp b/src/shared/Database/SqlOperations.cpp
index b229b9a5918..42094229b17 100644
--- a/src/shared/Database/SqlOperations.cpp
+++ b/src/shared/Database/SqlOperations.cpp
@@ -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)
diff --git a/src/shared/Database/SqlOperations.h b/src/shared/Database/SqlOperations.h
index a51e48bf929..b06397e84d5 100644
--- a/src/shared/Database/SqlOperations.h
+++ b/src/shared/Database/SqlOperations.h
@@ -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