EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Server Code Submissions (https://www.eqemulator.org/forums/forumdisplay.php?f=669)
-   -   quest::varlink() patch (https://www.eqemulator.org/forums/showthread.php?t=36375)

c0ncrete 01-29-2013 09:20 PM

quest::varlink() patch
 
this will keep improper use of quest::varlink() from crashing the zone.

Code:

@@ -2293,6 +2293,8 @@
        const ItemInst* inst = database.CreateItem(item_id);
        if (!inst)
                return "INVALID ITEM ID IN VARLINK";
+    if ( !initiator || !initiator->IsClient() )
+        return "INVALID INITIATOR IN VARLINK";
        char* link = 0;
        char* tempstr = 0;
        if (initiator->MakeItemLink(link, inst)) {        // make a link to the item


c0ncrete 01-29-2013 09:31 PM

i should lay off the coffee so i can see i missed copying a few lines...

Code:

Index: questmgr.cpp
===================================================================
--- questmgr.cpp        (revision 2468)
+++ questmgr.cpp        (working copy)
@@ -2293,6 +2293,8 @@
        const ItemInst* inst = database.CreateItem(item_id);
        if (!inst)
                return "INVALID ITEM ID IN VARLINK";
+    if ( !initiator || !initiator->IsClient() )
+        return "INVALID INITIATOR IN VARLINK";
        char* link = 0;
        char* tempstr = 0;
        if (initiator->MakeItemLink(link, inst)) {        // make a link to the item


Drajor 01-29-2013 09:49 PM

Increase coffee! :) Nice work.

wolfwalkereci 01-30-2013 12:05 AM

Hey I think you need more coffee !

trevius 01-30-2013 03:11 AM

That patch should prevent the crash, but it might be best to just move MakeItemLink() to Mob:: instead of Client::, so they can be generated by NPCs as well without requiring a client. We would still probably want to check for initiator to be safe, but it would allow for more flexibility.

c0ncrete 01-30-2013 08:49 AM

i wasn't familiar with how that function worked, but that does indeed sound like a much better solution.

c0ncrete 01-31-2013 12:39 AM

compiled and tested. won't crash the zone if there is no client initiator, but the results won't print out correctly in all cases, because it doesn't know what client version is being used (falls through to version < SoF).

Code:

Index: client.h
===================================================================
--- client.h        (revision 2472)
+++ client.h        (working copy)
@@ -773,7 +773,6 @@
        void        SetStats(uint8 type,int16 set_val);
        void        IncStats(uint8 type,int16 increase_val);
        void        DropItem(int16 slot_id);
-        bool        MakeItemLink(char* &ret_link, const ItemInst* inst);
        int                GetItemLinkHash(const ItemInst* inst);
        void        SendItemLink(const ItemInst* inst, bool sendtoall=false);
        void        SendLootItemInPacket(const ItemInst* inst, int16 slot_id);
Index: inventory.cpp
===================================================================
--- inventory.cpp        (revision 2472)
+++ inventory.cpp        (working copy)
@@ -719,7 +719,7 @@
        }
 }
 
-bool Client::MakeItemLink(char* &ret_link, const ItemInst *inst) {
+bool Mob::MakeItemLink(char* &ret_link, const ItemInst *inst) {
        //we're sending back the entire "link", minus the null characters & item name
        //that way, we can use it for regular links & Task links
        //note: initiator needs to pass us ret_link
@@ -747,7 +747,8 @@
        uint8 evolvedlevel = 0;
        int hash = 0;
        //int hash = GetItemLinkHash(inst);        //eventually this will work (currently crashes zone), but for now we'll skip the extra overhead
-        if (GetClientVersion() >= EQClientRoF)
+   
+        if (IsClient() && CastToClient()->GetClientVersion() >= EQClientRoF)
        {
                MakeAnyLenString(&ret_link, "%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%1X" "%04X" "%1X" "%05X" "%08X",
                        0,
@@ -765,7 +766,7 @@
                        hash
                );
        }
-        else if (GetClientVersion() >= EQClientSoF)
+        else if (IsClient() && CastToClient()->GetClientVersion() >= EQClientSoF)
        {
                MakeAnyLenString(&ret_link, "%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%1X" "%04X" "%1X" "%05X" "%08X",
                        0,
Index: mob.h
===================================================================
--- mob.h        (revision 2472)
+++ mob.h        (working copy)
@@ -869,6 +869,7 @@
        void Emote(const char *format, ...);
        void QuestJournalledSay(Client *QuestInitiator, const char *str);
        uint32 GetItemStat(uint32 itemid, const char *identifier);
+    bool MakeItemLink(char* &ret_link, const ItemInst* inst);
 
        //Casting related
          void SendSpellBarDisable();
Index: questmgr.cpp
===================================================================
--- questmgr.cpp        (revision 2472)
+++ questmgr.cpp        (working copy)
@@ -1099,7 +1099,7 @@
 void QuestManager::itemlink(int item_id) {
        const ItemInst* inst = database.CreateItem(item_id);
        char* link = 0;
-        if (initiator->MakeItemLink(link, inst))
+        if (owner->MakeItemLink(link, inst))
                initiator->Message(0, "%s tells you, %c%s%s%c", owner->GetCleanName(), 0x12, link, inst->GetItem()->Name, 0x12);
        safe_delete_array(link);
        safe_delete(inst);
@@ -2295,7 +2295,7 @@
                return "INVALID ITEM ID IN VARLINK";
        char* link = 0;
        char* tempstr = 0;
-        if (initiator->MakeItemLink(link, inst)) {        // make a link to the item
+        if (owner->MakeItemLink(link, inst)) {        // make a link to the item
                MakeAnyLenString(&tempstr, "%c%s%s%c", 0x12, link, inst->GetItem()->Name, 0x12);
                strn0cpy(perltext, tempstr,250);        // the perl string is only 250 chars, so make sure the link isn't too large
                safe_delete_array(tempstr);        // MakeAnyLenString() uses new, so clean up after it


sorvani 01-31-2013 11:36 AM

I would fail it to SoF+
Titanium needs to die in a fire.

c0ncrete 02-03-2013 12:42 AM

this one defaults to SoF instead of titanium.

it also isn't quite as ignorant as my last one. i was calling MakeItemLink via the quest's owner instead of the initiator, so it'd obviously rarely see a client and instead fall through to the default format (derp). now it prefers to use the quest's initiator, but will fall back to the owner. if neither is found, it produces an error.

Code:

Index: client.h
===================================================================
--- client.h        (revision 2479)
+++ client.h        (working copy)
@@ -773,7 +773,6 @@
        void        SetStats(uint8 type,int16 set_val);
        void        IncStats(uint8 type,int16 increase_val);
        void        DropItem(int16 slot_id);
-        bool        MakeItemLink(char* &ret_link, const ItemInst* inst);
        int                GetItemLinkHash(const ItemInst* inst);
        void        SendItemLink(const ItemInst* inst, bool sendtoall=false);
        void        SendLootItemInPacket(const ItemInst* inst, int16 slot_id);
Index: inventory.cpp
===================================================================
--- inventory.cpp        (revision 2479)
+++ inventory.cpp        (working copy)
@@ -719,7 +719,7 @@
        }
 }
 
-bool Client::MakeItemLink(char* &ret_link, const ItemInst *inst) {
+bool Mob::MakeItemLink(char* &ret_link, const ItemInst *inst) {
        //we're sending back the entire "link", minus the null characters & item name
        //that way, we can use it for regular links & Task links
        //note: initiator needs to pass us ret_link
@@ -747,7 +747,9 @@
        uint8 evolvedlevel = 0;
        int hash = 0;
        //int hash = GetItemLinkHash(inst);        //eventually this will work (currently crashes zone), but for now we'll skip the extra overhead
-        if (GetClientVersion() >= EQClientRoF)
+   
+        // client with RoF or greater
+        if (IsClient() && CastToClient()->GetClientVersion() >= EQClientRoF)
        {
                MakeAnyLenString(&ret_link, "%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%1X" "%04X" "%1X" "%05X" "%08X",
                        0,
@@ -765,9 +767,10 @@
                        hash
                );
        }
-        else if (GetClientVersion() >= EQClientSoF)
+        // client with less than SoF
+        else if (IsClient() && CastToClient()->GetClientVersion() < EQClientSoF)
        {
-                MakeAnyLenString(&ret_link, "%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%1X" "%04X" "%1X" "%05X" "%08X",
+                MakeAnyLenString(&ret_link, "%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%1X" "%04X" "%1X" "%08X",
                        0,
                        item->ID,
                        inst->GetAugmentItemID(0),
@@ -777,14 +780,14 @@
                        inst->GetAugmentItemID(4),
                        evolving,
                        loregroup,
-                        evolvedlevel,
-                        0,
+                        evolvedlevel,
                        hash
                );
        }
+        // default to SoF format (client or npc)
        else
        {
-                MakeAnyLenString(&ret_link, "%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%1X" "%04X" "%1X" "%08X",
+                MakeAnyLenString(&ret_link, "%1X" "%05X" "%05X" "%05X" "%05X" "%05X" "%05X" "%1X" "%04X" "%1X" "%05X" "%08X",
                        0,
                        item->ID,
                        inst->GetAugmentItemID(0),
@@ -794,7 +797,8 @@
                        inst->GetAugmentItemID(4),
                        evolving,
                        loregroup,
-                        evolvedlevel,
+                        evolvedlevel,
+                        0,
                        hash
                );
        }
Index: mob.h
===================================================================
--- mob.h        (revision 2479)
+++ mob.h        (working copy)
@@ -869,6 +869,7 @@
        void Emote(const char *format, ...);
        void QuestJournalledSay(Client *QuestInitiator, const char *str);
        uint32 GetItemStat(uint32 itemid, const char *identifier);
+    bool MakeItemLink(char* &ret_link, const ItemInst* inst);
 
        //Casting related
          void SendSpellBarDisable();
Index: questmgr.cpp
===================================================================
--- questmgr.cpp        (revision 2479)
+++ questmgr.cpp        (working copy)
@@ -2292,10 +2292,13 @@
 const char* QuestManager::varlink(char* perltext, int item_id) {
        const ItemInst* inst = database.CreateItem(item_id);
        if (!inst)
-                return "INVALID ITEM ID IN VARLINK";
+                return "ERROR: Invalid item ID in QuestManager::varlink";
+        if ( !(initiator||owner) )
+                return "ERROR: No valid Mob object in QuestManager::varlink";
        char* link = 0;
        char* tempstr = 0;
-        if (initiator->MakeItemLink(link, inst)) {        // make a link to the item
+        Mob* caller = initiator ? initiator->CastToMob() : owner->CastToMob();
+        if ( caller->MakeItemLink(link, inst) ) {        // make a link to the item
                MakeAnyLenString(&tempstr, "%c%s%s%c", 0x12, link, inst->GetItem()->Name, 0x12);
                strn0cpy(perltext, tempstr,250);        // the perl string is only 250 chars, so make sure the link isn't too large
                safe_delete_array(tempstr);        // MakeAnyLenString() uses new, so clean up after it
@@ -2736,3 +2739,4 @@
        worldserver.SendPacket(pack);
        safe_delete(pack);
 }
+



All times are GMT -4. The time now is 10:44 AM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.