[General] Add error messages & shutdowns for invalid file reading

This commit is contained in:
David Cernat
2020-11-19 06:12:19 +02:00
parent 33c631511f
commit 0c81b97ff2
5 changed files with 57 additions and 31 deletions
+8 -3
View File
@@ -48,9 +48,14 @@ end
function Cell:LoadFromDrive()
self.data = jsonInterface.load("cell/" .. self.entryFile)
-- JSON doesn't allow numerical keys, but we use them, so convert
-- all string number keys into numerical keys
tableHelper.fixNumericalKeys(self.data)
if self.data == nil then
tes3mp.LogMessage(enumerations.log.ERROR, "cell/" .. self.entryFile .. " cannot be read!")
tes3mp.StopServer(2)
else
-- JSON doesn't allow numerical keys, but we use them, so convert
-- all string number keys into numerical keys
tableHelper.fixNumericalKeys(self.data)
end
end
-- Deprecated function with confusing name, kept around for backwards compatibility
+10 -5
View File
@@ -49,12 +49,17 @@ end
function Player:LoadFromDrive()
self.data = jsonInterface.load("player/" .. self.accountFile)
-- JSON doesn't allow numerical keys, but we use them, so convert
-- all string number keys into numerical keys
tableHelper.fixNumericalKeys(self.data)
if self.data == nil then
tes3mp.LogMessage(enumerations.log.ERROR, "player/" .. self.accountFile .. " cannot be read!")
tes3mp.StopServer(2)
else
-- JSON doesn't allow numerical keys, but we use them, so convert
-- all string number keys into numerical keys
tableHelper.fixNumericalKeys(self.data)
if self.data.login.password ~= nil and self.data.login.passwordHash == nil then
self:ConvertPlaintextPassword()
if self.data.login.password ~= nil and self.data.login.passwordHash == nil then
self:ConvertPlaintextPassword()
end
end
end
+8 -3
View File
@@ -43,9 +43,14 @@ end
function RecordStore:LoadFromDrive()
self.data = jsonInterface.load("recordstore/" .. self.recordstoreFile)
-- JSON doesn't allow numerical keys, but we use them, so convert
-- all string number keys into numerical keys
tableHelper.fixNumericalKeys(self.data)
if self.data == nil then
tes3mp.LogMessage(enumerations.log.ERROR, "recordstore/" .. self.recordstoreFile .. " cannot be read!")
tes3mp.StopServer(2)
else
-- JSON doesn't allow numerical keys, but we use them, so convert
-- all string number keys into numerical keys
tableHelper.fixNumericalKeys(self.data)
end
end
-- Deprecated functions with confusing names, kept around for backwards compatibility
+23 -17
View File
@@ -297,31 +297,37 @@ function LoadDataFileList(filename)
local jsonDataFileList = jsonInterface.load(filename)
-- Fix numerical keys to print plugins in the correct order
tableHelper.fixNumericalKeys(jsonDataFileList, true)
if jsonDataFileList == nil then
tes3mp.LogMessage(enumerations.log.ERROR, "Data file list " .. filename .. " cannot be read!")
tes3mp.StopServer(2)
else
-- Fix numerical keys to print plugins in the correct order
tableHelper.fixNumericalKeys(jsonDataFileList, true)
for listIndex, pluginEntry in ipairs(jsonDataFileList) do
for entryIndex, checksumStringArray in pairs(pluginEntry) do
for listIndex, pluginEntry in ipairs(jsonDataFileList) do
for entryIndex, checksumStringArray in pairs(pluginEntry) do
dataFileList[listIndex] = {}
dataFileList[listIndex].name = entryIndex
dataFileList[listIndex] = {}
dataFileList[listIndex].name = entryIndex
local checksums = {}
local debugMessage = ("- %d: \"%s\": ["):format(listIndex, entryIndex)
local checksums = {}
local debugMessage = ("- %d: \"%s\": ["):format(listIndex, entryIndex)
for _, checksumString in ipairs(checksumStringArray) do
for _, checksumString in ipairs(checksumStringArray) do
debugMessage = debugMessage .. ("%X, "):format(tonumber(checksumString, 16))
table.insert(checksums, tonumber(checksumString, 16))
debugMessage = debugMessage .. ("%X, "):format(tonumber(checksumString, 16))
table.insert(checksums, tonumber(checksumString, 16))
end
dataFileList[listIndex].checksums = checksums
table.insert(dataFileList[listIndex], "")
debugMessage = debugMessage .. "\b\b]"
tes3mp.LogAppend(enumerations.log.WARN, debugMessage)
end
dataFileList[listIndex].checksums = checksums
table.insert(dataFileList[listIndex], "")
debugMessage = debugMessage .. "\b\b]"
tes3mp.LogAppend(enumerations.log.WARN, debugMessage)
end
return dataFileList
end
return dataFileList
end
function OnRequestDataFileList()
+8 -3
View File
@@ -52,9 +52,14 @@ function World:LoadFromDrive()
self.coreVariables = jsonInterface.load("world/" .. self.coreVariablesFile)
self.data = jsonInterface.load("world/" .. self.worldFile)
-- JSON doesn't allow numerical keys, but we use them, so convert
-- all string number keys into numerical keys
tableHelper.fixNumericalKeys(self.data)
if self.data == nil then
tes3mp.LogMessage(enumerations.log.ERROR, "world/" .. self.worldFile .. " cannot be read!")
tes3mp.StopServer(2)
else
-- JSON doesn't allow numerical keys, but we use them, so convert
-- all string number keys into numerical keys
tableHelper.fixNumericalKeys(self.data)
end
end