mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
Fix for potential nullptr when using base lua class constructors in debug mode, also added eq.get_qglobals and removed automatic export of them (will do this for a lot of other automatic exports)
This commit is contained in:
parent
85c7e1b059
commit
1b290b577d
@ -19,7 +19,7 @@ class Lua_Client : public Lua_Mob
|
||||
{
|
||||
typedef Client NativeType;
|
||||
public:
|
||||
Lua_Client() { }
|
||||
Lua_Client() { SetLuaPtrData(nullptr); }
|
||||
Lua_Client(Client *d) { SetLuaPtrData(d); }
|
||||
virtual ~Lua_Client() { }
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ class Lua_Corpse : public Lua_Mob
|
||||
{
|
||||
typedef Corpse NativeType;
|
||||
public:
|
||||
Lua_Corpse() { }
|
||||
Lua_Corpse() { SetLuaPtrData(nullptr); }
|
||||
Lua_Corpse(Corpse *d) { SetLuaPtrData(d); }
|
||||
virtual ~Lua_Corpse() { }
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ class Lua_Entity : public Lua_Ptr<void>
|
||||
{
|
||||
typedef Entity NativeType;
|
||||
public:
|
||||
Lua_Entity() { }
|
||||
Lua_Entity() : Lua_Ptr(nullptr) { }
|
||||
Lua_Entity(Entity *d) : Lua_Ptr(d) { }
|
||||
virtual ~Lua_Entity() { }
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ class Lua_EntityList : public Lua_Ptr<void>
|
||||
{
|
||||
typedef EntityList NativeType;
|
||||
public:
|
||||
Lua_EntityList() { }
|
||||
Lua_EntityList() : Lua_Ptr(nullptr) { }
|
||||
Lua_EntityList(EntityList *d) : Lua_Ptr(d) { }
|
||||
virtual ~Lua_EntityList() { }
|
||||
|
||||
|
||||
@ -10,9 +10,11 @@
|
||||
#include "lua_parser.h"
|
||||
#include "lua_item.h"
|
||||
#include "lua_iteminst.h"
|
||||
#include "lua_mob.h"
|
||||
#include "lua_client.h"
|
||||
#include "lua_npc.h"
|
||||
#include "QuestParserCollection.h"
|
||||
#include "questmgr.h"
|
||||
#include "QGlobals.h"
|
||||
|
||||
struct Events { };
|
||||
struct Factions { };
|
||||
@ -354,7 +356,6 @@ void lua_set_proximity(float min_x, float max_x, float min_y, float max_y, float
|
||||
quest_manager.set_proximity(min_x, max_x, min_y, max_y, min_z, max_z);
|
||||
}
|
||||
|
||||
|
||||
void lua_clear_proximity() {
|
||||
quest_manager.clear_proximity();
|
||||
}
|
||||
@ -724,6 +725,42 @@ void lua_cross_zone_message_player_by_name(uint32 type, const char *player, cons
|
||||
quest_manager.CrossZoneMessagePlayerByName(type, player, message);
|
||||
}
|
||||
|
||||
luabind::object lua_get_qglobals(lua_State *L, Lua_NPC npc, Lua_Client client) {
|
||||
luabind::object ret = luabind::newtable(L);
|
||||
|
||||
NPC *n = npc;
|
||||
Client *c = client;
|
||||
|
||||
if(n && !n->GetQglobal()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::list<QGlobal> global_map;
|
||||
QGlobalCache::GetQGlobals(global_map, n, c, zone);
|
||||
auto iter = global_map.begin();
|
||||
while(iter != global_map.end()) {
|
||||
ret[(*iter).name] = (*iter).value;
|
||||
++iter;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
luabind::object lua_get_qglobals(lua_State *L, Lua_Client client, Lua_NPC npc) {
|
||||
return lua_get_qglobals(L, npc, client);
|
||||
}
|
||||
|
||||
luabind::object lua_get_qglobals(lua_State *L, Lua_Client client) {
|
||||
return lua_get_qglobals(L, Lua_NPC(nullptr), client);
|
||||
}
|
||||
|
||||
luabind::object lua_get_qglobals(lua_State *L, Lua_NPC npc) {
|
||||
return lua_get_qglobals(L, npc, Lua_Client(nullptr));
|
||||
}
|
||||
|
||||
luabind::object lua_get_qglobals(lua_State *L) {
|
||||
return lua_get_qglobals(L, Lua_NPC(nullptr), Lua_Client(nullptr));
|
||||
}
|
||||
|
||||
|
||||
luabind::scope lua_register_general() {
|
||||
return luabind::namespace_("eq")
|
||||
@ -855,7 +892,12 @@ luabind::scope lua_register_general() {
|
||||
luabind::def("send_mail", &lua_send_mail),
|
||||
luabind::def("cross_zone_signal_client_by_char_id", &lua_cross_zone_signal_client_by_char_id),
|
||||
luabind::def("cross_zone_signal_client_by_name", &lua_cross_zone_signal_client_by_name),
|
||||
luabind::def("cross_zone_message_player_by_name", &lua_cross_zone_message_player_by_name)
|
||||
luabind::def("cross_zone_message_player_by_name", &lua_cross_zone_message_player_by_name),
|
||||
luabind::def("get_qglobals", (luabind::object(*)(lua_State*,Lua_NPC,Lua_Client))&lua_get_qglobals),
|
||||
luabind::def("get_qglobals", (luabind::object(*)(lua_State*,Lua_Client,Lua_NPC))&lua_get_qglobals),
|
||||
luabind::def("get_qglobals", (luabind::object(*)(lua_State*,Lua_Client))&lua_get_qglobals),
|
||||
luabind::def("get_qglobals", (luabind::object(*)(lua_State*,Lua_NPC))&lua_get_qglobals),
|
||||
luabind::def("get_qglobals", (luabind::object(*)(lua_State*))&lua_get_qglobals)
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ class Lua_Group : public Lua_Ptr<void>
|
||||
{
|
||||
typedef Group NativeType;
|
||||
public:
|
||||
Lua_Group() { }
|
||||
Lua_Group() : Lua_Ptr(nullptr) { }
|
||||
Lua_Group(Group *d) : Lua_Ptr(d) { }
|
||||
virtual ~Lua_Group() { }
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ class Lua_HateEntry : public Lua_Ptr<void>
|
||||
{
|
||||
typedef tHateEntry NativeType;
|
||||
public:
|
||||
Lua_HateEntry() { }
|
||||
Lua_HateEntry() : Lua_Ptr(nullptr) { }
|
||||
Lua_HateEntry(tHateEntry *d) : Lua_Ptr(d) { }
|
||||
virtual ~Lua_HateEntry() { }
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ class Lua_Item : public Lua_Ptr<const void>
|
||||
typedef const Item_Struct NativeType;
|
||||
public:
|
||||
Lua_Item(uint32 item_id);
|
||||
Lua_Item() { }
|
||||
Lua_Item() : Lua_Ptr(nullptr) { }
|
||||
Lua_Item(const Item_Struct *d) : Lua_Ptr(d) { }
|
||||
virtual ~Lua_Item() { }
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ class Lua_ItemInst : public Lua_Ptr<void>
|
||||
{
|
||||
typedef ItemInst NativeType;
|
||||
public:
|
||||
Lua_ItemInst() { }
|
||||
Lua_ItemInst() : Lua_Ptr(nullptr) { }
|
||||
Lua_ItemInst(ItemInst *d) : Lua_Ptr(d) { }
|
||||
virtual ~Lua_ItemInst() { }
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ class Lua_Mob : public Lua_Entity
|
||||
{
|
||||
typedef Mob NativeType;
|
||||
public:
|
||||
Lua_Mob() { }
|
||||
Lua_Mob() { SetLuaPtrData(nullptr); }
|
||||
Lua_Mob(Mob *d) { SetLuaPtrData(d); }
|
||||
virtual ~Lua_Mob() { }
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ class Lua_NPC : public Lua_Mob
|
||||
{
|
||||
typedef NPC NativeType;
|
||||
public:
|
||||
Lua_NPC() { }
|
||||
Lua_NPC() { SetLuaPtrData(nullptr); }
|
||||
Lua_NPC(NPC *d) { SetLuaPtrData(d); }
|
||||
virtual ~Lua_NPC() { }
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ class Lua_Object : public Lua_Entity
|
||||
{
|
||||
typedef Object NativeType;
|
||||
public:
|
||||
Lua_Object() { }
|
||||
Lua_Object() { SetLuaPtrData(nullptr); }
|
||||
Lua_Object(Object *d) { SetLuaPtrData(d); }
|
||||
virtual ~Lua_Object() { }
|
||||
|
||||
|
||||
@ -27,7 +27,6 @@
|
||||
#include "lua_object.h"
|
||||
#include "lua_door.h"
|
||||
#include "lua_general.h"
|
||||
#include "QGlobals.h"
|
||||
#include "questmgr.h"
|
||||
#include "zone.h"
|
||||
#include "lua_parser.h"
|
||||
@ -229,7 +228,6 @@ int LuaParser::_EventNPC(std::string package_name, QuestEventID evt, NPC* npc, M
|
||||
arg_function(this, L, npc, init, data, extra_data);
|
||||
ExportZoneVariables();
|
||||
Client *c = (init && init->IsClient()) ? init->CastToClient() : nullptr;
|
||||
ExportQGlobals(npc, c);
|
||||
|
||||
quest_manager.StartQuest(npc, c, nullptr);
|
||||
if(lua_pcall(L, 1, 1, 0)) {
|
||||
@ -320,7 +318,6 @@ int LuaParser::_EventPlayer(std::string package_name, QuestEventID evt, Client *
|
||||
auto arg_function = PlayerArgumentDispatch[evt];
|
||||
arg_function(this, L, client, data, extra_data);
|
||||
ExportZoneVariables();
|
||||
ExportQGlobals(nullptr, client);
|
||||
|
||||
quest_manager.StartQuest(nullptr, client, nullptr);
|
||||
if(lua_pcall(L, 1, 1, 0)) {
|
||||
@ -416,7 +413,6 @@ int LuaParser::_EventItem(std::string package_name, QuestEventID evt, Client *cl
|
||||
auto arg_function = ItemArgumentDispatch[evt];
|
||||
arg_function(this, L, client, item, objid, extra_data);
|
||||
ExportZoneVariables();
|
||||
ExportQGlobals(nullptr, nullptr);
|
||||
|
||||
quest_manager.StartQuest(nullptr, client, item);
|
||||
if(lua_pcall(L, 1, 1, 0)) {
|
||||
@ -498,7 +494,6 @@ int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc,
|
||||
auto arg_function = SpellArgumentDispatch[evt];
|
||||
arg_function(this, L, npc, client, spell_id, extra_data);
|
||||
ExportZoneVariables();
|
||||
ExportQGlobals(npc, client);
|
||||
|
||||
quest_manager.StartQuest(npc, client, nullptr);
|
||||
if(lua_pcall(L, 1, 1, 0)) {
|
||||
@ -560,7 +555,6 @@ int LuaParser::_EventEncounter(std::string package_name, QuestEventID evt, std::
|
||||
lua_setfield(L, -2, "name");
|
||||
|
||||
ExportZoneVariables();
|
||||
ExportQGlobals(nullptr, nullptr);
|
||||
|
||||
quest_manager.StartQuest(nullptr, nullptr, nullptr);
|
||||
if(lua_pcall(L, 1, 1, 0)) {
|
||||
@ -961,27 +955,6 @@ void LuaParser::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, u
|
||||
}
|
||||
}
|
||||
|
||||
void LuaParser::ExportQGlobals(NPC *n, Client *c) {
|
||||
lua_createtable(L, 0, 0);
|
||||
|
||||
if(n && !n->GetQglobal()) {
|
||||
lua_setfield(L, -2, "qglobals");
|
||||
return;
|
||||
}
|
||||
|
||||
std::list<QGlobal> global_map;
|
||||
QGlobalCache::GetQGlobals(global_map, n, c, zone);
|
||||
|
||||
auto iter = global_map.begin();
|
||||
while(iter != global_map.end()) {
|
||||
lua_pushstring(L, (*iter).value.c_str());
|
||||
lua_setfield(L, -2, (*iter).name.c_str());
|
||||
++iter;
|
||||
}
|
||||
|
||||
lua_setfield(L, -2, "qglobals");
|
||||
}
|
||||
|
||||
void LuaParser::ExportZoneVariables() {
|
||||
if(zone == nullptr) {
|
||||
return;
|
||||
|
||||
@ -75,7 +75,6 @@ private:
|
||||
bool HasFunction(std::string function, std::string package_name);
|
||||
void ClearStates();
|
||||
void MapFunctions(lua_State *L);
|
||||
void ExportQGlobals(NPC *n, Client *c);
|
||||
void ExportZoneVariables();
|
||||
|
||||
std::map<std::string, std::string> vars_;
|
||||
|
||||
@ -18,7 +18,7 @@ class Lua_Raid : public Lua_Ptr<void>
|
||||
{
|
||||
typedef Raid NativeType;
|
||||
public:
|
||||
Lua_Raid() { }
|
||||
Lua_Raid() : Lua_Ptr(nullptr) { }
|
||||
Lua_Raid(Raid *d) : Lua_Ptr(d) { }
|
||||
virtual ~Lua_Raid() { }
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ class Lua_Spell : public Lua_Ptr<const void>
|
||||
{
|
||||
typedef const SPDat_Spell_Struct NativeType;
|
||||
public:
|
||||
Lua_Spell() { }
|
||||
Lua_Spell() : Lua_Ptr(nullptr) { }
|
||||
Lua_Spell(const SPDat_Spell_Struct *d) : Lua_Ptr(d) { }
|
||||
virtual ~Lua_Spell() { }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user