diff --git a/ghost.lua b/ghost.lua index ec98f42..230a224 100644 --- a/ghost.lua +++ b/ghost.lua @@ -123,9 +123,16 @@ Ghosts = { this:reset() local headers = Index:getMap(gamemap, mapChecksum(gamemap)) - local data + local ok, data for _, header in ipairs(headers) do - data = Ghost.read(header, Ghost.tableReader) + ok, data = pcall(Ghost.read, header, Ghost.tableReader) + if not ok then + print(data) + print("\x85\ERROR:\x80 invalid ghost data, removing entry") + Index:remove(header) + Index:write() + continue + end this:set(header, data) end end, @@ -583,7 +590,7 @@ local function open(filename, mode, fn) f:close() if not ok then - err = string.format("%s\n(%s (%s))", err, filename, mode) + err = string.format("%s\n(\x82%s\x80 (%s))", err, filename, mode) end return ok, err @@ -606,6 +613,17 @@ Index = { this:setMap(header.map, header.checksum, map) end, + remove = function(this, header) + local map = this:getMap(header.map, header.checksum) + for i, h in ipairs(map) do + if h.player == header.player then + map[i] = nil + this:setMap(header.map, header.checksum, map) + return + end + end + end, + find = function(this, header) local index = this:getMap(header.map, header.checksum) for i, h in ipairs(index) do