From 9f26b337110165c599ee50050404f8fdc5cc7566 Mon Sep 17 00:00:00 2001 From: icecool Date: Thu, 7 Mar 2019 13:49:07 -0600 Subject: [PATCH] GMCP Error handling --- EquipmentManager.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/EquipmentManager.xml b/EquipmentManager.xml index 9c443ba..52c1447 100644 --- a/EquipmentManager.xml +++ b/EquipmentManager.xml @@ -105,6 +105,10 @@ end -- Function to return GMCP value function checkGMCPValue(key) local result, value = CallPlugin(GMCPPluginID,"gmcpval", key) + if result ~= 0 then + dnote( ("%s: checkGMCPValue for %s did not return any data."):format(Prepend, key) + return false + end return value end -- Return true if tonumber() is not nil @@ -120,6 +124,7 @@ end EqCheck = { Debug=false, Level=0 } function EqCheck.IsPlaying() if not IsConnected() then return false end + if not checkGMCPValue("char.status.state") then return false end local state = tonumber(checkGMCPValue("char.status.state")) if not state then return false @@ -153,6 +158,10 @@ end Character = { } Player_MT = { __index = Character } function Character.New() + if not (checkGMCPValue("char.base.name") or checkGMCPValue("char.status.level") or checkGMCPValue("char.status.level")) then + dnote(("%s: Character.New() failed to create character object. Missing GMCP data was detected."):format(Prepend)) + return nil + end local player = { Name = checkGMCPValue("char.base.name"), LastLevel = checkGMCPValue("char.status.level"), @@ -164,6 +173,7 @@ function Character.New() end function Character:Level() if not checkGMCPValue("char.status.level") then + dnote(("%s: Character:Level() did not return any GMCP data. Attempting to call the GMCP data."):format(Prepend)) Send_GMCP_Packet("request char") end dnote(("%s Character:Level() returns: %d"):format(Prepend, tonumber(checkGMCPValue("char.status.level")))) @@ -171,6 +181,7 @@ function Character:Level() end function Character:TierLevel() if not checkGMCPValue("char.base.tier") then + dnote(("%s: Character:TierLevel() did not return any GMCP data. Attempting to call the GMCP data."):format(Prepend)) Send_GMCP_Packet("request char") end dnote(("%s Character:TierLevel() returns: %d"):format(Prepend, (tonumber(checkGMCPValue("char.base.tier"))*10))) @@ -178,6 +189,7 @@ function Character:TierLevel() end function Character:EffectiveLevel() if not checkGMCPValue("char") then + dnote(("%s: Character:EffectiveLevel() did not return any GMCP data. Attempting to call the GMCP data."):format(Prepend)) Send_GMCP_Packet("request char") end dnote(("%s Character:EffectiveLevel() returns: %d"):format(Prepend, (self:Level()+self:TierLevel())))