Skip to content

Commit

Permalink
fix: Links various build and db combinations
Browse files Browse the repository at this point in the history
This should address a lot of the mismatch linkdb vs build issues.

We will check for the DB against Build type MQ2LinkDB_Live
MQ2LinkDB_Test
MQ2LinkDB_Emu
and if that doesn't exist for the current build. we will check for the merged db.
MQ2LinkDB

if EMU and using a merged DB fresh from live. the links will need additional formating.
** Recommend EMU users start with no DB and build a fresh one to eliminate these issues **
  • Loading branch information
grimmier378 committed May 16, 2024
1 parent 57729a5 commit 6861d17
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 48 deletions.
3 changes: 3 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,7 @@ function ChatWin.Config_GUI(open)

local tmpRefLink = (doRefresh and ChatWin.Settings.refreshLinkDB >=5) and ChatWin.Settings.refreshLinkDB or 0
tmpRefLink = ImGui.InputInt("Refresh Delay##LinkRefresh",tmpRefLink, 5, 5)
if tmpRefLink < 0 then tmpRefLink = 0 end
if tmpRefLink ~= ChatWin.Settings.refreshLinkDB then
-- ChatWin.Settings.refreshLinkDB = tmpRefLink
tempSettings.refreshLinkDB = tmpRefLink
Expand Down Expand Up @@ -1986,6 +1987,7 @@ end

local function loop()
while running do
if mq.TLO.Window('CharacterListWnd').Open() then running = false end
if ChatWin.Settings.refreshLinkDB > 0 and doRefresh then
local timeB = os.time()
if timeB - timeA >= ChatWin.Settings.refreshLinkDB * 60 then
Expand All @@ -1998,6 +2000,7 @@ local function loop()
mq.doevents()
mq.delay(100)
end
mq.exit()
end

loadSettings()
Expand Down
180 changes: 132 additions & 48 deletions links.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
local mq = require('mq')
local PackageMan = require('mq/PackageMan')
local sqlite3 = PackageMan.Require('lsqlite3')
local dbname = 'MQ2LinkDB.db'
local liveDb = 'MQ2LinkDB.db'
local mergedDB = 'MQ2LinkDB.db'
local currDB = 'MQ2LinkDB.db'
local liveDb = 'MQ2LinkDB_Live.db'
local testDb = 'MQ2LinkDB_Test.db'
local emuDb = 'MQ2LinkDB_Emu.db'
local Build = mq.TLO.MacroQuest.BuildName()
local path = mq.TLO.MacroQuest.Path('resources')() .."/"
local db, pathDB
local GoodToGo = false
local sortedTable = {}
local msgOut = ''
local links = {
Expand Down Expand Up @@ -62,20 +65,56 @@ end
local function loadSortedItems()
sortedTable = {}
sortedTable = nonLinks
-- print(Build)
-- Pull database and ignore the item ID 1048575 as that is the npc say link. which is only set once to the first npc line it sees
local fetchQuery = [[
SELECT
SUBSTR(link, 1, INSTR(SUBSTR(link, 2), x'12') + 1) AS link,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
SUBSTR(link, 58, INSTR(SUBSTR(link, 58), x'12') - 1),
'.', ''), '`', ''), '''', ''), ',', ''), '(', ''), ')', ''), '#', '') AS name
FROM
item_links
WHERE
item_id != 1048575
ORDER BY
LENGTH(name) DESC, name;
]]
local fetchQuery = ''
if Build == 'Emu' then
fetchQuery = [[
SELECT
SUBSTR(link, 1, INSTR(SUBSTR(link, 2), x'12') + 1) AS link,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
SUBSTR(link, 58, INSTR(SUBSTR(link, 58), x'12') - 1),
'.', ''), '`', ''), '''', ''), ',', ''), '(', ''), ')', ''), '#', '') AS name
FROM
item_links
WHERE
item_id != 1048575
ORDER BY
LENGTH(name) DESC, name;
]]
elseif Build == 'Live' or Build == 'Merged' then
fetchQuery = [[
SELECT
SUBSTR(link, 1, INSTR(SUBSTR(link, 2), x'12') + 1) AS link,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
SUBSTR(link, 93, INSTR(SUBSTR(link, 93), x'12') - 1),
'.', ''), '`', ''), '''', ''), ',', ''), '(', ''), ')', ''), '#', '') AS name
FROM
item_links
WHERE
item_id != 1048575
ORDER BY
LENGTH(name) DESC, name;
]]
end
if mq.TLO.MacroQuest.BuildName() == 'Emu' and Build == 'Merged' then
fetchQuery = [[
SELECT
SUBSTR(link, 1, 8) ||
SUBSTR(link, 44, INSTR(SUBSTR(link, 44), x'12') + 1) ||
SUBSTR(link, INSTR(SUBSTR(link, 44), x'12') + 44) AS link,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
SUBSTR(link, 93, INSTR(SUBSTR(link, 93), x'12') - 1),
'.', ''), '`', ''), '''', ''), ',', ''), '(', ''), ')', ''), '#', '') AS name
FROM
item_links
WHERE
item_id != 1048575
ORDER BY
LENGTH(name) DESC, name;
]]
end
-- print(fetchQuery)
for row in db:nrows(fetchQuery) do
local name =row.name
-- printf("Name: %s", name)
Expand All @@ -92,56 +131,103 @@ end

function links.initDB()
links.ready = false
dbname = liveDb
pathDB = path..liveDb
local GoodToGo = false
if Build == 'Emu' then
-- set path to Emu db
pathDB = path..emuDb
if not File_Exists(pathDB) then -- check for EMU Db
-- emu db doesn't exist chedk for alive
-- dbname = liveDb
pathDB = path..currDB
if not GoodToGo then
if Build == 'Emu' then
-- set path to Emu db
pathDB = path..emuDb
if not File_Exists(pathDB) then -- check for EMU Db
-- emu db doesn't exist chedk for alive
pathDB = path..mergedDB
-- check for live db EMU was missing
if File_Exists(pathDB) then
-- Live DB Exists
Build = 'Merged' -- change local build var so we don't have to dbl check next cycle
msgOut = string.format("\ay[\aw%s\ay]\atYou are using a \arMerged server DB\aw on\ay EMU\at You may recieve false links!.",mq.TLO.Time())
if links.Console then
links.Console:AppendText(msgOut)
else print(msgOut) end
currDB = mergedDB
GoodToGo = true
end
else
currDB = emuDb
GoodToGo = true
end
elseif Build == 'Test' then
-- set path to Test db
pathDB = path..testDb
if not File_Exists(pathDB) then -- check for Test Db
-- Test db doesn't exist chedk for alive
pathDB = path..mergedDB
-- check for live db Test was missing
if File_Exists(pathDB) then
-- Live DB Exists
Build = 'Merged' -- change local build var so we don't have to dbl check next cycle
msgOut = string.format("\ay[\aw%s\ay]\atYou are using a \arMerged server DB\aw on\ay Test\at You may recieve false links!.",mq.TLO.Time())
if links.Console then
links.Console:AppendText(msgOut)
else print(msgOut) end
currDB = mergedDB
GoodToGo = true
end
else
currDB = testDb
GoodToGo = true
end
elseif Build == 'Live' then
-- set path to Test db
pathDB = path..liveDb
-- check for live db EMU was missing
if File_Exists(pathDB) then
-- Live DB Exists
Build = 'Live' -- change local build var so we don't have to dbl check next cycle
msgOut = string.format("\ay[\aw%s\ay]\atYou are using a \arLive server DB\aw on\ay EMU\at You may recieve false links!.",mq.TLO.Time())
if links.Console then
links.Console:AppendText(msgOut)
else print(msgOut) end
dbname = liveDb
if not File_Exists(pathDB) then -- check for Test Db
-- Test db doesn't exist chedk for alive
pathDB = path..mergedDB
-- check for live db Test was missing
if File_Exists(pathDB) then
-- Live DB Exists
Build = 'Merged' -- change local build var so we don't have to dbl check next cycle
msgOut = string.format("\ay[\aw%s\ay]\atYou are using a \arMerged server DB\aw on\ay Live\at You may recieve false links!.",mq.TLO.Time())
if links.Console then
links.Console:AppendText(msgOut)
else print(msgOut) end
currDB = mergedDB
GoodToGo = true
end
else
currDB = liveDb
GoodToGo = true
end

else
dbname = emuDb
GoodToGo = true
pathDB = path..mergedDB
if not File_Exists(pathDB) then
msgOut = string.format("\ay[\aw%s\ay]\arNO DB's Found Links are Disabled, \atRun MQ2LindDB /link /import and try again.",mq.TLO.Time())
links.enabled = false
GoodToGo = false
return (links.Console and links.Console:AppendText(msgOut) or print(msgOut))
else
Build = 'Merged'
GoodToGo = true
links.enabled = true
end
end

elseif not File_Exists(pathDB) then
msgOut = string.format("\ay[\aw%s\ay]\arNO DB's Found Links are Disabled, \atRun MQ2LindDB /link /import and try again.",mq.TLO.Time())
links.enabled = false
return (links.Console and links.Console:AppendText(msgOut) or print(msgOut))

else
GoodToGo = true
links.enabled = true
end

if GoodToGo then
pathDB = path..currDB
db = sqlite3.open(pathDB, sqlite3.OPEN_READONLY)

-- print(db)
-- Check if the local table has Data
if not tableHasData(db, "item_links") then
msgOut = string.format("\ay[\aw%s\ay]\at %s \arMissing \axrun \ao/link /update \agto create.",mq.TLO.Time(), dbname)
msgOut = string.format("\ay[\aw%s\ay]\at %s \arMissing \axrun \ao/link /update \agto create.",mq.TLO.Time(), currDB)
if links.running then
return (links.Console and links.Console:AppendText(msgOut) or print(msgOut))
else
print(msgOut)
end
end

msgOut = string.format("\ay[\aw%s\ay]\at Fetching \agItems\ax from \ao%s...",mq.TLO.Time(),dbname)
msgOut = string.format("\ay[\aw%s\ay]\at Fetching \agItems\ax from \ao%s...",mq.TLO.Time(),currDB)
if links.running then
return (links.Console and links.Console:AppendText(msgOut) or print(msgOut))
else
Expand All @@ -154,8 +240,6 @@ local GoodToGo = false
end
end



--- Table Stuff ---
function links.collectItemLinks(line)
local linksFound = {}
Expand Down

0 comments on commit 6861d17

Please sign in to comment.