Eluna Fix static analysis noted warnings and errors

This commit is contained in:
Rochet2
2014-12-23 23:21:13 +02:00
parent 36e8704853
commit 07d25f5031
11 changed files with 195 additions and 198 deletions

View File

@@ -73,9 +73,10 @@ public:
{ {
for (EventToFunctionsMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr) for (EventToFunctionsMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr)
{ {
for (FunctionRefVector::iterator it = itr->second.begin(); it != itr->second.end(); ++it) FunctionRefVector& funcrefvec = itr->second;
for (FunctionRefVector::iterator it = funcrefvec.begin(); it != funcrefvec.end(); ++it)
delete *it; delete *it;
itr->second.clear(); funcrefvec.clear();
} }
Bindings.clear(); Bindings.clear();
} }
@@ -145,13 +146,15 @@ public:
{ {
for (EntryToEventsMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr) for (EntryToEventsMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr)
{ {
for (EventToFunctionsMap::iterator it = itr->second.begin(); it != itr->second.end(); ++it) EventToFunctionsMap& funcmap = itr->second;
for (EventToFunctionsMap::iterator it = funcmap.begin(); it != funcmap.end(); ++it)
{ {
for (FunctionRefVector::iterator i = it->second.begin(); i != it->second.end(); ++i) FunctionRefVector& funcrefvec = it->second;
for (FunctionRefVector::iterator i = funcrefvec.begin(); i != funcrefvec.end(); ++i)
delete *i; delete *i;
it->second.clear(); funcrefvec.clear();
} }
itr->second.clear(); funcmap.clear();
} }
Bindings.clear(); Bindings.clear();
} }

View File

@@ -45,8 +45,8 @@ bool ElunaUtil::ObjectDistanceOrderPred::operator()(WorldObject const* pLeft, Wo
} }
ElunaUtil::WorldObjectInRangeCheck::WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range, ElunaUtil::WorldObjectInRangeCheck::WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range,
uint16 typeMask, uint32 entry, uint32 hostile) : i_nearest(nearest), uint16 typeMask, uint32 entry, uint32 hostile) :
i_obj(obj), i_range(range), i_typeMask(typeMask), i_entry(entry), i_hostile(hostile) i_obj(obj), i_hostile(hostile), i_entry(entry), i_range(range), i_typeMask(typeMask), i_nearest(nearest)
{ {
} }
WorldObject const& ElunaUtil::WorldObjectInRangeCheck::GetFocusObject() const WorldObject const& ElunaUtil::WorldObjectInRangeCheck::GetFocusObject() const

View File

@@ -108,12 +108,12 @@ namespace ElunaUtil
WorldObject const& GetFocusObject() const; WorldObject const& GetFocusObject() const;
bool operator()(WorldObject* u); bool operator()(WorldObject* u);
bool i_nearest;
WorldObject const* i_obj; WorldObject const* i_obj;
uint32 i_hostile;
uint32 i_entry;
float i_range; float i_range;
uint16 i_typeMask; uint16 i_typeMask;
uint32 i_entry; bool i_nearest;
uint32 i_hostile;
}; };
/* /*

View File

@@ -1532,7 +1532,7 @@ namespace LuaGlobalFunctions
int CreatePacket(Eluna* /*E*/, lua_State* L) int CreatePacket(Eluna* /*E*/, lua_State* L)
{ {
uint32 opcode = Eluna::CHECKVAL<uint32>(L, 1); uint32 opcode = Eluna::CHECKVAL<uint32>(L, 1);
uint32 size = Eluna::CHECKVAL<uint32>(L, 2); size_t size = Eluna::CHECKVAL<size_t>(L, 2);
if (opcode >= NUM_MSG_TYPES) if (opcode >= NUM_MSG_TYPES)
return luaL_argerror(L, 1, "valid opcode expected"); return luaL_argerror(L, 1, "valid opcode expected");

View File

@@ -46,7 +46,6 @@ using namespace HookMgr;
#define EVENT_BEGIN(BINDMAP, EVENT, RET) \ #define EVENT_BEGIN(BINDMAP, EVENT, RET) \
if (!BINDMAP->HasEvents(EVENT)) \ if (!BINDMAP->HasEvents(EVENT)) \
RET; \ RET; \
lua_State* L = this->L; \
const char* _LuaBindType = this->BINDMAP->groupName; \ const char* _LuaBindType = this->BINDMAP->groupName; \
uint32 _LuaEvent = EVENT; \ uint32 _LuaEvent = EVENT; \
int _LuaStackTop = lua_gettop(L); \ int _LuaStackTop = lua_gettop(L); \
@@ -79,7 +78,6 @@ using namespace HookMgr;
#define ENTRY_BEGIN(BINDMAP, ENTRY, EVENT, RET) \ #define ENTRY_BEGIN(BINDMAP, ENTRY, EVENT, RET) \
if (!BINDMAP->HasEvents(ENTRY, EVENT)) \ if (!BINDMAP->HasEvents(ENTRY, EVENT)) \
RET; \ RET; \
lua_State* L = this->L; \
const char* _LuaBindType = this->BINDMAP->groupName; \ const char* _LuaBindType = this->BINDMAP->groupName; \
uint32 _LuaEvent = EVENT; \ uint32 _LuaEvent = EVENT; \
int _LuaStackTop = lua_gettop(L); \ int _LuaStackTop = lua_gettop(L); \
@@ -382,7 +380,7 @@ void Eluna::OnShutdown()
ENDCALL(); ENDCALL();
} }
void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code) void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, const std::string& code)
{ {
ENTRY_BEGIN(ItemGossipBindings, item->GetEntry(), GOSSIP_EVENT_ON_SELECT, return); ENTRY_BEGIN(ItemGossipBindings, item->GetEntry(), GOSSIP_EVENT_ON_SELECT, return);
pPlayer->PlayerTalkClass->ClearMenus(); pPlayer->PlayerTalkClass->ClearMenus();
@@ -398,7 +396,7 @@ void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender,
ENDCALL(); ENDCALL();
} }
void Eluna::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code) void Eluna::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, const std::string& code)
{ {
ENTRY_BEGIN(playerGossipBindings, menuId, GOSSIP_EVENT_ON_SELECT, return); ENTRY_BEGIN(playerGossipBindings, menuId, GOSSIP_EVENT_ON_SELECT, return);
pPlayer->PlayerTalkClass->ClearMenus(); pPlayer->PlayerTalkClass->ClearMenus();
@@ -744,7 +742,12 @@ void Eluna::OnMoneyChanged(Player* pPlayer, int32& amount)
EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_MONEY_CHANGE, return); EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_MONEY_CHANGE, return);
Push(L, pPlayer); Push(L, pPlayer);
Push(L, amount); Push(L, amount);
EVENT_EXECUTE(0); EVENT_EXECUTE(1);
FOR_RETS(i)
{
if (lua_isnumber(L, i))
amount = CHECKVAL<int32>(L, i, amount);
}
ENDCALL(); ENDCALL();
} }
@@ -1180,24 +1183,34 @@ void Eluna::OnDisband(Guild* guild)
ENDCALL(); ENDCALL();
} }
void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32 &amount, bool isRepair) // isRepair not a part of Mangos, implement? void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair) // isRepair not a part of Mangos, implement?
{ {
EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_MONEY_WITHDRAW, return); EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_MONEY_WITHDRAW, return);
Push(L, guild); Push(L, guild);
Push(L, player); Push(L, player);
Push(L, amount); Push(L, amount);
Push(L, isRepair); // isRepair not a part of Mangos, implement? Push(L, isRepair); // isRepair not a part of Mangos, implement?
EVENT_EXECUTE(0); EVENT_EXECUTE(1);
FOR_RETS(i)
{
if (lua_isnumber(L, i))
amount = CHECKVAL<uint32>(L, i, amount);
}
ENDCALL(); ENDCALL();
} }
void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32 &amount) void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount)
{ {
EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_MONEY_DEPOSIT, return); EVENT_BEGIN(GuildEventBindings, GUILD_EVENT_ON_MONEY_DEPOSIT, return);
Push(L, guild); Push(L, guild);
Push(L, player); Push(L, player);
Push(L, amount); Push(L, amount);
EVENT_EXECUTE(0); EVENT_EXECUTE(1);
FOR_RETS(i)
{
if (lua_isnumber(L, i))
amount = CHECKVAL<uint32>(L, i, amount);
}
ENDCALL(); ENDCALL();
} }

View File

@@ -110,7 +110,7 @@ namespace HookMgr
PLAYER_EVENT_ON_DUEL_END = 11, // (event, winner, loser, type) PLAYER_EVENT_ON_DUEL_END = 11, // (event, winner, loser, type)
PLAYER_EVENT_ON_GIVE_XP = 12, // (event, player, amount, victim) - Can return new XP amount PLAYER_EVENT_ON_GIVE_XP = 12, // (event, player, amount, victim) - Can return new XP amount
PLAYER_EVENT_ON_LEVEL_CHANGE = 13, // (event, player, oldLevel) PLAYER_EVENT_ON_LEVEL_CHANGE = 13, // (event, player, oldLevel)
PLAYER_EVENT_ON_MONEY_CHANGE = 14, // (event, player, amount) PLAYER_EVENT_ON_MONEY_CHANGE = 14, // (event, player, amount) - Can return new money amount
PLAYER_EVENT_ON_REPUTATION_CHANGE = 15, // (event, player, factionId, standing, incremental) - Can return new standing PLAYER_EVENT_ON_REPUTATION_CHANGE = 15, // (event, player, factionId, standing, incremental) - Can return new standing
PLAYER_EVENT_ON_TALENTS_CHANGE = 16, // (event, player, points) PLAYER_EVENT_ON_TALENTS_CHANGE = 16, // (event, player, points)
PLAYER_EVENT_ON_TALENTS_RESET = 17, // (event, player, noCost) PLAYER_EVENT_ON_TALENTS_RESET = 17, // (event, player, noCost)
@@ -155,8 +155,8 @@ namespace HookMgr
GUILD_EVENT_ON_INFO_CHANGE = 4, // (event, guild, newInfo) GUILD_EVENT_ON_INFO_CHANGE = 4, // (event, guild, newInfo)
GUILD_EVENT_ON_CREATE = 5, // (event, guild, leader, name) // Not on TC GUILD_EVENT_ON_CREATE = 5, // (event, guild, leader, name) // Not on TC
GUILD_EVENT_ON_DISBAND = 6, // (event, guild) GUILD_EVENT_ON_DISBAND = 6, // (event, guild)
GUILD_EVENT_ON_MONEY_WITHDRAW = 7, // (event, guild, player, amount, isRepair) GUILD_EVENT_ON_MONEY_WITHDRAW = 7, // (event, guild, player, amount, isRepair) - Can return new money amount
GUILD_EVENT_ON_MONEY_DEPOSIT = 8, // (event, guild, player, amount) GUILD_EVENT_ON_MONEY_DEPOSIT = 8, // (event, guild, player, amount) - Can return new money amount
GUILD_EVENT_ON_ITEM_MOVE = 9, // (event, guild, player, item, isSrcBank, srcContainer, srcSlotId, isDestBank, destContainer, destSlotId) // TODO GUILD_EVENT_ON_ITEM_MOVE = 9, // (event, guild, player, item, isSrcBank, srcContainer, srcSlotId, isDestBank, destContainer, destSlotId) // TODO
GUILD_EVENT_ON_EVENT = 10, // (event, guild, eventType, plrGUIDLow1, plrGUIDLow2, newRank) // TODO GUILD_EVENT_ON_EVENT = 10, // (event, guild, eventType, plrGUIDLow1, plrGUIDLow2, newRank) // TODO
GUILD_EVENT_ON_BANK_EVENT = 11, // (event, guild, eventType, tabId, playerGUIDLow, itemOrMoney, itemStackCount, destTabId) GUILD_EVENT_ON_BANK_EVENT = 11, // (event, guild, eventType, tabId, playerGUIDLow, itemOrMoney, itemStackCount, destTabId)

View File

@@ -55,7 +55,7 @@ void Eluna::Initialize()
lua_folderpath.replace(0, 1, home); lua_folderpath.replace(0, 1, home);
#endif #endif
ELUNA_LOG_INFO("[Eluna]: Searching scripts from `%s`", lua_folderpath.c_str()); ELUNA_LOG_INFO("[Eluna]: Searching scripts from `%s`", lua_folderpath.c_str());
lua_requirepath = ""; lua_requirepath.clear();
GetScripts(lua_folderpath); GetScripts(lua_folderpath);
// Erase last ; // Erase last ;
if (!lua_requirepath.empty()) if (!lua_requirepath.empty())
@@ -215,7 +215,7 @@ Eluna::~Eluna()
lua_close(L); lua_close(L);
} }
void Eluna::AddScriptPath(std::string filename, std::string fullpath) void Eluna::AddScriptPath(std::string filename, const std::string& fullpath)
{ {
ELUNA_LOG_DEBUG("[Eluna]: AddScriptPath Checking file `%s`", fullpath.c_str()); ELUNA_LOG_DEBUG("[Eluna]: AddScriptPath Checking file `%s`", fullpath.c_str());
@@ -421,11 +421,11 @@ void Eluna::InvalidateObjects()
lua_pop(L, 1); lua_pop(L, 1);
} }
void Eluna::report(lua_State* L) void Eluna::report(lua_State* luastate)
{ {
const char* msg = lua_tostring(L, -1); const char* msg = lua_tostring(luastate, -1);
ELUNA_LOG_ERROR("%s", msg); ELUNA_LOG_ERROR("%s", msg);
lua_pop(L, 1); lua_pop(luastate, 1);
} }
void Eluna::ExecuteCall(int params, int res) void Eluna::ExecuteCall(int params, int res)
@@ -446,270 +446,270 @@ void Eluna::ExecuteCall(int params, int res)
--event_level; --event_level;
} }
void Eluna::Push(lua_State* L) void Eluna::Push(lua_State* luastate)
{ {
lua_pushnil(L); lua_pushnil(luastate);
} }
void Eluna::Push(lua_State* L, const long long l) void Eluna::Push(lua_State* luastate, const long long l)
{ {
ElunaTemplate<long long>::Push(L, new long long(l)); ElunaTemplate<long long>::Push(luastate, new long long(l));
} }
void Eluna::Push(lua_State* L, const unsigned long long l) void Eluna::Push(lua_State* luastate, const unsigned long long l)
{ {
ElunaTemplate<unsigned long long>::Push(L, new unsigned long long(l)); ElunaTemplate<unsigned long long>::Push(luastate, new unsigned long long(l));
} }
void Eluna::Push(lua_State* L, const long l) void Eluna::Push(lua_State* luastate, const long l)
{ {
Push(L, static_cast<long long>(l)); Push(luastate, static_cast<long long>(l));
} }
void Eluna::Push(lua_State* L, const unsigned long l) void Eluna::Push(lua_State* luastate, const unsigned long l)
{ {
Push(L, static_cast<unsigned long long>(l)); Push(luastate, static_cast<unsigned long long>(l));
} }
void Eluna::Push(lua_State* L, const int i) void Eluna::Push(lua_State* luastate, const int i)
{ {
lua_pushinteger(L, i); lua_pushinteger(luastate, i);
} }
void Eluna::Push(lua_State* L, const unsigned int u) void Eluna::Push(lua_State* luastate, const unsigned int u)
{ {
lua_pushunsigned(L, u); lua_pushunsigned(luastate, u);
} }
void Eluna::Push(lua_State* L, const double d) void Eluna::Push(lua_State* luastate, const double d)
{ {
lua_pushnumber(L, d); lua_pushnumber(luastate, d);
} }
void Eluna::Push(lua_State* L, const float f) void Eluna::Push(lua_State* luastate, const float f)
{ {
lua_pushnumber(L, f); lua_pushnumber(luastate, f);
} }
void Eluna::Push(lua_State* L, const bool b) void Eluna::Push(lua_State* luastate, const bool b)
{ {
lua_pushboolean(L, b); lua_pushboolean(luastate, b);
} }
void Eluna::Push(lua_State* L, const std::string& str) void Eluna::Push(lua_State* luastate, const std::string& str)
{ {
lua_pushstring(L, str.c_str()); lua_pushstring(luastate, str.c_str());
} }
void Eluna::Push(lua_State* L, const char* str) void Eluna::Push(lua_State* luastate, const char* str)
{ {
lua_pushstring(L, str); lua_pushstring(luastate, str);
} }
void Eluna::Push(lua_State* L, Pet const* pet) void Eluna::Push(lua_State* luastate, Pet const* pet)
{ {
Push(L, pet->ToCreature()); Push(luastate, pet->ToCreature());
} }
void Eluna::Push(lua_State* L, TempSummon const* summon) void Eluna::Push(lua_State* luastate, TempSummon const* summon)
{ {
Push(L, summon->ToCreature()); Push(luastate, summon->ToCreature());
} }
void Eluna::Push(lua_State* L, Unit const* unit) void Eluna::Push(lua_State* luastate, Unit const* unit)
{ {
if (!unit) if (!unit)
{ {
Push(L); Push(luastate);
return; return;
} }
switch (unit->GetTypeId()) switch (unit->GetTypeId())
{ {
case TYPEID_UNIT: case TYPEID_UNIT:
Push(L, unit->ToCreature()); Push(luastate, unit->ToCreature());
break; break;
case TYPEID_PLAYER: case TYPEID_PLAYER:
Push(L, unit->ToPlayer()); Push(luastate, unit->ToPlayer());
break; break;
default: default:
ElunaTemplate<Unit>::Push(L, unit); ElunaTemplate<Unit>::Push(luastate, unit);
} }
} }
void Eluna::Push(lua_State* L, WorldObject const* obj) void Eluna::Push(lua_State* luastate, WorldObject const* obj)
{ {
if (!obj) if (!obj)
{ {
Push(L); Push(luastate);
return; return;
} }
switch (obj->GetTypeId()) switch (obj->GetTypeId())
{ {
case TYPEID_UNIT: case TYPEID_UNIT:
Push(L, obj->ToCreature()); Push(luastate, obj->ToCreature());
break; break;
case TYPEID_PLAYER: case TYPEID_PLAYER:
Push(L, obj->ToPlayer()); Push(luastate, obj->ToPlayer());
break; break;
case TYPEID_GAMEOBJECT: case TYPEID_GAMEOBJECT:
Push(L, obj->ToGameObject()); Push(luastate, obj->ToGameObject());
break; break;
case TYPEID_CORPSE: case TYPEID_CORPSE:
Push(L, obj->ToCorpse()); Push(luastate, obj->ToCorpse());
break; break;
default: default:
ElunaTemplate<WorldObject>::Push(L, obj); ElunaTemplate<WorldObject>::Push(luastate, obj);
} }
} }
void Eluna::Push(lua_State* L, Object const* obj) void Eluna::Push(lua_State* luastate, Object const* obj)
{ {
if (!obj) if (!obj)
{ {
Push(L); Push(luastate);
return; return;
} }
switch (obj->GetTypeId()) switch (obj->GetTypeId())
{ {
case TYPEID_UNIT: case TYPEID_UNIT:
Push(L, obj->ToCreature()); Push(luastate, obj->ToCreature());
break; break;
case TYPEID_PLAYER: case TYPEID_PLAYER:
Push(L, obj->ToPlayer()); Push(luastate, obj->ToPlayer());
break; break;
case TYPEID_GAMEOBJECT: case TYPEID_GAMEOBJECT:
Push(L, obj->ToGameObject()); Push(luastate, obj->ToGameObject());
break; break;
case TYPEID_CORPSE: case TYPEID_CORPSE:
Push(L, obj->ToCorpse()); Push(luastate, obj->ToCorpse());
break; break;
default: default:
ElunaTemplate<Object>::Push(L, obj); ElunaTemplate<Object>::Push(luastate, obj);
} }
} }
static int CheckIntegerRange(lua_State* L, int narg, int min, int max) static int CheckIntegerRange(lua_State* luastate, int narg, int min, int max)
{ {
double value = luaL_checknumber(L, narg); double value = luaL_checknumber(luastate, narg);
char error_buffer[64]; char error_buffer[64];
if (value > max) if (value > max)
{ {
snprintf(error_buffer, 64, "value must be less than or equal to %i", max); snprintf(error_buffer, 64, "value must be less than or equal to %i", max);
return luaL_argerror(L, narg, error_buffer); return luaL_argerror(luastate, narg, error_buffer);
} }
if (value < min) if (value < min)
{ {
snprintf(error_buffer, 64, "value must be greater than or equal to %i", min); snprintf(error_buffer, 64, "value must be greater than or equal to %i", min);
return luaL_argerror(L, narg, error_buffer); return luaL_argerror(luastate, narg, error_buffer);
} }
return static_cast<int>(value); return static_cast<int>(value);
} }
static unsigned int CheckUnsignedRange(lua_State* L, int narg, unsigned int max) static unsigned int CheckUnsignedRange(lua_State* luastate, int narg, unsigned int max)
{ {
double value = luaL_checknumber(L, narg); double value = luaL_checknumber(luastate, narg);
char error_buffer[64]; char error_buffer[64];
if (value < 0) if (value < 0)
return luaL_argerror(L, narg, "value must be greater than or equal to 0"); return luaL_argerror(luastate, narg, "value must be greater than or equal to 0");
if (value > max) if (value > max)
{ {
snprintf(error_buffer, 64, "value must be less than or equal to %u", max); snprintf(error_buffer, 64, "value must be less than or equal to %u", max);
return luaL_argerror(L, narg, error_buffer); return luaL_argerror(luastate, narg, error_buffer);
} }
return static_cast<unsigned int>(value); return static_cast<unsigned int>(value);
} }
template<> bool Eluna::CHECKVAL<bool>(lua_State* L, int narg) template<> bool Eluna::CHECKVAL<bool>(lua_State* luastate, int narg)
{ {
return lua_toboolean(L, narg) != 0; return lua_toboolean(luastate, narg) != 0;
} }
template<> float Eluna::CHECKVAL<float>(lua_State* L, int narg) template<> float Eluna::CHECKVAL<float>(lua_State* luastate, int narg)
{ {
return luaL_checknumber(L, narg); return luaL_checknumber(luastate, narg);
} }
template<> double Eluna::CHECKVAL<double>(lua_State* L, int narg) template<> double Eluna::CHECKVAL<double>(lua_State* luastate, int narg)
{ {
return luaL_checknumber(L, narg); return luaL_checknumber(luastate, narg);
} }
template<> signed char Eluna::CHECKVAL<signed char>(lua_State* L, int narg) template<> signed char Eluna::CHECKVAL<signed char>(lua_State* luastate, int narg)
{ {
return CheckIntegerRange(L, narg, SCHAR_MIN, SCHAR_MAX); return CheckIntegerRange(luastate, narg, SCHAR_MIN, SCHAR_MAX);
} }
template<> unsigned char Eluna::CHECKVAL<unsigned char>(lua_State* L, int narg) template<> unsigned char Eluna::CHECKVAL<unsigned char>(lua_State* luastate, int narg)
{ {
return CheckUnsignedRange(L, narg, UCHAR_MAX); return CheckUnsignedRange(luastate, narg, UCHAR_MAX);
} }
template<> short Eluna::CHECKVAL<short>(lua_State* L, int narg) template<> short Eluna::CHECKVAL<short>(lua_State* luastate, int narg)
{ {
return CheckIntegerRange(L, narg, SHRT_MIN, SHRT_MAX); return CheckIntegerRange(luastate, narg, SHRT_MIN, SHRT_MAX);
} }
template<> unsigned short Eluna::CHECKVAL<unsigned short>(lua_State* L, int narg) template<> unsigned short Eluna::CHECKVAL<unsigned short>(lua_State* luastate, int narg)
{ {
return CheckUnsignedRange(L, narg, USHRT_MAX); return CheckUnsignedRange(luastate, narg, USHRT_MAX);
} }
template<> int Eluna::CHECKVAL<int>(lua_State* L, int narg) template<> int Eluna::CHECKVAL<int>(lua_State* luastate, int narg)
{ {
return CheckIntegerRange(L, narg, INT_MIN, INT_MAX); return CheckIntegerRange(luastate, narg, INT_MIN, INT_MAX);
} }
template<> unsigned int Eluna::CHECKVAL<unsigned int>(lua_State* L, int narg) template<> unsigned int Eluna::CHECKVAL<unsigned int>(lua_State* luastate, int narg)
{ {
return CheckUnsignedRange(L, narg, UINT_MAX); return CheckUnsignedRange(luastate, narg, UINT_MAX);
} }
template<> const char* Eluna::CHECKVAL<const char*>(lua_State* L, int narg) template<> const char* Eluna::CHECKVAL<const char*>(lua_State* luastate, int narg)
{ {
return luaL_checkstring(L, narg); return luaL_checkstring(luastate, narg);
} }
template<> std::string Eluna::CHECKVAL<std::string>(lua_State* L, int narg) template<> std::string Eluna::CHECKVAL<std::string>(lua_State* luastate, int narg)
{ {
return luaL_checkstring(L, narg); return luaL_checkstring(luastate, narg);
} }
template<> long long Eluna::CHECKVAL<long long>(lua_State* L, int narg) template<> long long Eluna::CHECKVAL<long long>(lua_State* luastate, int narg)
{ {
if (lua_isnumber(L, narg)) if (lua_isnumber(luastate, narg))
return static_cast<long long>(CHECKVAL<double>(L, narg)); return static_cast<long long>(CHECKVAL<double>(luastate, narg));
return *(Eluna::CHECKOBJ<long long>(L, narg, true)); return *(Eluna::CHECKOBJ<long long>(luastate, narg, true));
} }
template<> unsigned long long Eluna::CHECKVAL<unsigned long long>(lua_State* L, int narg) template<> unsigned long long Eluna::CHECKVAL<unsigned long long>(lua_State* luastate, int narg)
{ {
if (lua_isnumber(L, narg)) if (lua_isnumber(luastate, narg))
return static_cast<unsigned long long>(CHECKVAL<uint32>(L, narg)); return static_cast<unsigned long long>(CHECKVAL<uint32>(luastate, narg));
return *(Eluna::CHECKOBJ<unsigned long long>(L, narg, true)); return *(Eluna::CHECKOBJ<unsigned long long>(luastate, narg, true));
} }
template<> long Eluna::CHECKVAL<long>(lua_State* L, int narg) template<> long Eluna::CHECKVAL<long>(lua_State* luastate, int narg)
{ {
return static_cast<long>(CHECKVAL<long long>(L, narg)); return static_cast<long>(CHECKVAL<long long>(luastate, narg));
} }
template<> unsigned long Eluna::CHECKVAL<unsigned long>(lua_State* L, int narg) template<> unsigned long Eluna::CHECKVAL<unsigned long>(lua_State* luastate, int narg)
{ {
return static_cast<unsigned long>(CHECKVAL<unsigned long long>(L, narg)); return static_cast<unsigned long>(CHECKVAL<unsigned long long>(luastate, narg));
} }
template<> Object* Eluna::CHECKOBJ<Object>(lua_State* L, int narg, bool error) template<> Object* Eluna::CHECKOBJ<Object>(lua_State* luastate, int narg, bool error)
{ {
Object* obj = CHECKOBJ<WorldObject>(L, narg, false); Object* obj = CHECKOBJ<WorldObject>(luastate, narg, false);
if (!obj) if (!obj)
obj = CHECKOBJ<Item>(L, narg, false); obj = CHECKOBJ<Item>(luastate, narg, false);
if (!obj) if (!obj)
obj = ElunaTemplate<Object>::Check(L, narg, error); obj = ElunaTemplate<Object>::Check(luastate, narg, error);
return obj; return obj;
} }
template<> WorldObject* Eluna::CHECKOBJ<WorldObject>(lua_State* L, int narg, bool error) template<> WorldObject* Eluna::CHECKOBJ<WorldObject>(lua_State* luastate, int narg, bool error)
{ {
WorldObject* obj = CHECKOBJ<Unit>(L, narg, false); WorldObject* obj = CHECKOBJ<Unit>(luastate, narg, false);
if (!obj) if (!obj)
obj = CHECKOBJ<GameObject>(L, narg, false); obj = CHECKOBJ<GameObject>(luastate, narg, false);
if (!obj) if (!obj)
obj = CHECKOBJ<Corpse>(L, narg, false); obj = CHECKOBJ<Corpse>(luastate, narg, false);
if (!obj) if (!obj)
obj = ElunaTemplate<WorldObject>::Check(L, narg, error); obj = ElunaTemplate<WorldObject>::Check(luastate, narg, error);
return obj; return obj;
} }
template<> Unit* Eluna::CHECKOBJ<Unit>(lua_State* L, int narg, bool error) template<> Unit* Eluna::CHECKOBJ<Unit>(lua_State* luastate, int narg, bool error)
{ {
Unit* obj = CHECKOBJ<Player>(L, narg, false); Unit* obj = CHECKOBJ<Player>(luastate, narg, false);
if (!obj) if (!obj)
obj = CHECKOBJ<Creature>(L, narg, false); obj = CHECKOBJ<Creature>(luastate, narg, false);
if (!obj) if (!obj)
obj = ElunaTemplate<Unit>::Check(L, narg, error); obj = ElunaTemplate<Unit>::Check(luastate, narg, error);
return obj; return obj;
} }
template<> ElunaObject* Eluna::CHECKOBJ<ElunaObject>(lua_State* L, int narg, bool error) template<> ElunaObject* Eluna::CHECKOBJ<ElunaObject>(lua_State* luastate, int narg, bool error)
{ {
return CHECKTYPE(L, narg, NULL, error); return CHECKTYPE(luastate, narg, NULL, error);
} }
ElunaObject* Eluna::CHECKTYPE(lua_State* L, int narg, const char* tname, bool error) ElunaObject* Eluna::CHECKTYPE(lua_State* luastate, int narg, const char* tname, bool error)
{ {
bool valid = false; bool valid = false;
ElunaObject** ptrHold = NULL; ElunaObject** ptrHold = NULL;
@@ -717,19 +717,19 @@ ElunaObject* Eluna::CHECKTYPE(lua_State* L, int narg, const char* tname, bool er
if (!tname) if (!tname)
{ {
valid = true; valid = true;
ptrHold = static_cast<ElunaObject**>(lua_touserdata(L, narg)); ptrHold = static_cast<ElunaObject**>(lua_touserdata(luastate, narg));
} }
else else
{ {
if (lua_getmetatable(L, narg)) if (lua_getmetatable(luastate, narg))
{ {
luaL_getmetatable(L, tname); luaL_getmetatable(luastate, tname);
if (lua_rawequal(L, -1, -2) == 1) if (lua_rawequal(luastate, -1, -2) == 1)
{ {
valid = true; valid = true;
ptrHold = static_cast<ElunaObject**>(lua_touserdata(L, narg)); ptrHold = static_cast<ElunaObject**>(lua_touserdata(luastate, narg));
} }
lua_pop(L, 2); lua_pop(luastate, 2);
} }
} }
@@ -738,8 +738,8 @@ ElunaObject* Eluna::CHECKTYPE(lua_State* L, int narg, const char* tname, bool er
if (error) if (error)
{ {
char buff[256]; char buff[256];
snprintf(buff, 256, "bad argument : %s expected, got %s", tname ? tname : "userdata", luaL_typename(L, narg)); snprintf(buff, 256, "bad argument : %s expected, got %s", tname ? tname : "userdata", luaL_typename(luastate, narg));
luaL_argerror(L, narg, buff); luaL_argerror(luastate, narg, buff);
} }
return NULL; return NULL;
} }

View File

@@ -150,48 +150,48 @@ public:
// This will be called on next update // This will be called on next update
static void ReloadEluna(); static void ReloadEluna();
static void GetScripts(std::string path); static void GetScripts(std::string path);
static void AddScriptPath(std::string filename, std::string fullpath); static void AddScriptPath(std::string filename, const std::string& fullpath);
static void report(lua_State*); static void report(lua_State* luastate);
void ExecuteCall(int params, int res); void ExecuteCall(int params, int res);
void Register(uint8 reg, uint32 id, uint32 evt, int func, uint32 shots); void Register(uint8 reg, uint32 id, uint32 evt, int func, uint32 shots);
void RunScripts(); void RunScripts();
void InvalidateObjects(); void InvalidateObjects();
// Pushes // Pushes
static void Push(lua_State* L); // nil static void Push(lua_State* luastate); // nil
static void Push(lua_State* L, const long long); static void Push(lua_State* luastate, const long long);
static void Push(lua_State* L, const unsigned long long); static void Push(lua_State* luastate, const unsigned long long);
static void Push(lua_State* L, const long); static void Push(lua_State* luastate, const long);
static void Push(lua_State* L, const unsigned long); static void Push(lua_State* luastate, const unsigned long);
static void Push(lua_State* L, const int); static void Push(lua_State* luastate, const int);
static void Push(lua_State* L, const unsigned int); static void Push(lua_State* luastate, const unsigned int);
static void Push(lua_State* L, const bool); static void Push(lua_State* luastate, const bool);
static void Push(lua_State* L, const float); static void Push(lua_State* luastate, const float);
static void Push(lua_State* L, const double); static void Push(lua_State* luastate, const double);
static void Push(lua_State* L, const std::string&); static void Push(lua_State* luastate, const std::string&);
static void Push(lua_State* L, const char*); static void Push(lua_State* luastate, const char*);
template<typename T> static void Push(lua_State* L, T const* ptr) template<typename T> static void Push(lua_State* luastate, T const* ptr)
{ {
ElunaTemplate<T>::Push(L, ptr); ElunaTemplate<T>::Push(luastate, ptr);
} }
static void Push(lua_State* L, Object const* obj); static void Push(lua_State* luastate, Object const* obj);
static void Push(lua_State* L, WorldObject const* obj); static void Push(lua_State* luastate, WorldObject const* obj);
static void Push(lua_State* L, Unit const* unit); static void Push(lua_State* luastate, Unit const* unit);
static void Push(lua_State* L, Pet const* pet); static void Push(lua_State* luastate, Pet const* pet);
static void Push(lua_State* L, TempSummon const* summon); static void Push(lua_State* luastate, TempSummon const* summon);
// Checks // Checks
template<typename T> static T CHECKVAL(lua_State* L, int narg); template<typename T> static T CHECKVAL(lua_State* luastate, int narg);
template<typename T> static T CHECKVAL(lua_State* L, int narg, T def) template<typename T> static T CHECKVAL(lua_State* luastate, int narg, T def)
{ {
return lua_isnoneornil(L, narg) ? def : CHECKVAL<T>(L, narg); return lua_isnoneornil(luastate, narg) ? def : CHECKVAL<T>(luastate, narg);
} }
template<typename T> static T* CHECKOBJ(lua_State* L, int narg, bool error = true) template<typename T> static T* CHECKOBJ(lua_State* luastate, int narg, bool error = true)
{ {
return ElunaTemplate<T>::Check(L, narg, error); return ElunaTemplate<T>::Check(luastate, narg, error);
} }
static ElunaObject* CHECKTYPE(lua_State* L, int narg, const char *tname, bool error = true); static ElunaObject* CHECKTYPE(lua_State* luastate, int narg, const char *tname, bool error = true);
CreatureAI* GetAI(Creature* creature); CreatureAI* GetAI(Creature* creature);
@@ -218,7 +218,7 @@ public:
bool OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& targets); bool OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& targets);
bool OnExpire(Player* pPlayer, ItemTemplate const* pProto); bool OnExpire(Player* pPlayer, ItemTemplate const* pProto);
bool OnRemove(Player* pPlayer, Item* item); bool OnRemove(Player* pPlayer, Item* item);
void HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code); void HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, const std::string& code);
/* Creature */ /* Creature */
bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget); bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget);
@@ -311,7 +311,7 @@ public:
void OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent); void OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent);
void OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea); void OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea);
void OnMapChanged(Player* pPlayer); void OnMapChanged(Player* pPlayer);
void HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code); void HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, const std::string& code);
#ifndef CLASSIC #ifndef CLASSIC
#ifndef TBC #ifndef TBC

View File

@@ -260,7 +260,7 @@ ElunaRegister<Unit> UnitMethods[] =
{ "GetUnfriendlyUnitsInRange", &LuaUnit::GetUnfriendlyUnitsInRange }, // :GetUnfriendlyUnitsInRange([range]) - Returns a list of unfriendly units in range, can return nil { "GetUnfriendlyUnitsInRange", &LuaUnit::GetUnfriendlyUnitsInRange }, // :GetUnfriendlyUnitsInRange([range]) - Returns a list of unfriendly units in range, can return nil
{ "GetOwnerGUID", &LuaUnit::GetOwnerGUID }, // :GetOwnerGUID() - Returns the UNIT_FIELD_SUMMONEDBY owner { "GetOwnerGUID", &LuaUnit::GetOwnerGUID }, // :GetOwnerGUID() - Returns the UNIT_FIELD_SUMMONEDBY owner
{ "GetCreatorGUID", &LuaUnit::GetCreatorGUID }, // :GetCreatorGUID() - Returns the UNIT_FIELD_CREATEDBY creator { "GetCreatorGUID", &LuaUnit::GetCreatorGUID }, // :GetCreatorGUID() - Returns the UNIT_FIELD_CREATEDBY creator
{ "GetMinionGUID", &LuaUnit::GetMinionGUID }, // :GetMinionGUID() - Returns the UNIT_FIELD_SUMMON unit's minion GUID { "GetMinionGUID", &LuaUnit::GetPetGUID }, // :GetMinionGUID() - Decapreted. GetMinionGUID is same as GetPetGUID
{ "GetCharmerGUID", &LuaUnit::GetCharmerGUID }, // :GetCharmerGUID() - Returns the UNIT_FIELD_CHARMEDBY charmer { "GetCharmerGUID", &LuaUnit::GetCharmerGUID }, // :GetCharmerGUID() - Returns the UNIT_FIELD_CHARMEDBY charmer
{ "GetCharmGUID", &LuaUnit::GetCharmGUID }, // :GetCharmGUID() - Returns the unit's UNIT_FIELD_CHARM guid { "GetCharmGUID", &LuaUnit::GetCharmGUID }, // :GetCharmGUID() - Returns the unit's UNIT_FIELD_CHARM guid
{ "GetPetGUID", &LuaUnit::GetPetGUID }, // :GetPetGUID() - Returns the unit's pet GUID { "GetPetGUID", &LuaUnit::GetPetGUID }, // :GetPetGUID() - Returns the unit's pet GUID
@@ -313,7 +313,7 @@ ElunaRegister<Unit> UnitMethods[] =
{ "SetName", &LuaUnit::SetName }, // :SetName(name) - Sets the unit's name { "SetName", &LuaUnit::SetName }, // :SetName(name) - Sets the unit's name
{ "SetSheath", &LuaUnit::SetSheath }, // :SetSheath(SheathState) - Sets unit's sheathstate { "SetSheath", &LuaUnit::SetSheath }, // :SetSheath(SheathState) - Sets unit's sheathstate
{ "SetCreatorGUID", &LuaUnit::SetCreatorGUID }, // :SetOwnerGUID(uint64 ownerGUID) - Sets the owner's guid of a summoned creature, etc { "SetCreatorGUID", &LuaUnit::SetCreatorGUID }, // :SetOwnerGUID(uint64 ownerGUID) - Sets the owner's guid of a summoned creature, etc
{ "SetMinionGUID", &LuaUnit::SetMinionGUID }, // :SetCreatorGUID(uint64 creatorGUID) - Sets the UNIT_FIELD_CREATEDBY creator's guid { "SetMinionGUID", &LuaUnit::SetPetGUID }, // Decapreted. Same as SetPetGUID
{ "SetCharmerGUID", &LuaUnit::SetCharmerGUID }, // :SetCharmerGUID(uint64 ownerGUID) - Sets the UNIT_FIELD_CHARMEDBY charmer GUID { "SetCharmerGUID", &LuaUnit::SetCharmerGUID }, // :SetCharmerGUID(uint64 ownerGUID) - Sets the UNIT_FIELD_CHARMEDBY charmer GUID
{ "SetPetGUID", &LuaUnit::SetPetGUID }, // :SetPetGUID(uint64 guid) - Sets the pet's guid { "SetPetGUID", &LuaUnit::SetPetGUID }, // :SetPetGUID(uint64 guid) - Sets the pet's guid
#if (!defined(TBC) && !defined(CLASSIC)) #if (!defined(TBC) && !defined(CLASSIC))

View File

@@ -1994,9 +1994,11 @@ namespace LuaPlayer
uint32 muteseconds = Eluna::CHECKVAL<uint32>(L, 2); uint32 muteseconds = Eluna::CHECKVAL<uint32>(L, 2);
/*const char* reason = luaL_checkstring(E, 2);*/ // Mangos does not have a reason field in database. /*const char* reason = luaL_checkstring(E, 2);*/ // Mangos does not have a reason field in database.
uint64 muteTime = time(NULL) + muteseconds; time_t muteTime = time(NULL) + muteseconds;
player->GetSession()->m_muteTime = muteTime; player->GetSession()->m_muteTime = muteTime;
LoginDatabase.PExecute("UPDATE account SET mutetime = " UI64FMTD " WHERE id = '%u'", muteTime, player->GetSession()->GetAccountId()); std::ostringstream oss;
oss << "UPDATE account SET mutetime = " << muteTime << " WHERE id = " << player->GetSession()->GetAccountId();
LoginDatabase.PExecute("%s", oss.str().c_str());
return 0; return 0;
} }

View File

@@ -412,16 +412,6 @@ namespace LuaUnit
return 1; return 1;
} }
int GetMinionGUID(Eluna* /*E*/, lua_State* L, Unit* unit)
{
#ifndef TRINITY
Eluna::Push(L, unit->GetPetGuid());
#else
Eluna::Push(L, unit->GetPetGUID());
#endif
return 1;
}
int GetCharmerGUID(Eluna* /*E*/, lua_State* L, Unit* unit) int GetCharmerGUID(Eluna* /*E*/, lua_State* L, Unit* unit)
{ {
#ifndef TRINITY #ifndef TRINITY
@@ -1087,20 +1077,9 @@ namespace LuaUnit
{ {
uint64 guid = Eluna::CHECKVAL<uint64>(L, 2); uint64 guid = Eluna::CHECKVAL<uint64>(L, 2);
#ifndef TRINITY #ifndef TRINITY
unit->SetOwnerGuid(ObjectGuid(guid)); unit->SetCreatorGuid(ObjectGuid(guid));
#else #else
unit->SetOwnerGUID(ObjectGuid(guid)); unit->SetCreatorGUID(ObjectGuid(guid));
#endif
return 0;
}
int SetMinionGUID(Eluna* /*E*/, lua_State* L, Unit* unit)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 2);
#ifndef TRINITY
unit->SetPetGuid(ObjectGuid(guid));
#else
unit->SetMinionGUID(ObjectGuid(guid));
#endif #endif
return 0; return 0;
} }