Skip to content

Commit 2fde181

Browse files
committed
Fix barrier data not loading on Windows
1 parent cd48f6a commit 2fde181

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

mods/ctf/ctf_map/map_meta.lua

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local CURRENT_MAP_VERSION = "3"
2-
local BARRIER_Y_SIZE = 16 * 2
2+
local BARRIER_Y_SIZE = 16
33

4-
local modname = minetest.get_current_modname();
4+
local modname = minetest.get_current_modname()
55

66
function ctf_map.skybox_exists(subdir)
77
local list = minetest.get_dir_list(subdir, true)
@@ -160,7 +160,7 @@ function ctf_map.load_map_meta(idx, dirname)
160160
enable_shadows = tonumber(meta:get("enable_shadows") or "0.26"),
161161
}
162162
if tonumber(meta:get("map_version")) > 2 then
163-
local f = assert(io.open(ctf_map.maps_dir .. dirname .. "/barriers.data", "r"))
163+
local f = assert(io.open(ctf_map.maps_dir .. dirname .. "/barriers.data", "rb"))
164164

165165
local barriers = f:read("*all")
166166

@@ -170,20 +170,28 @@ function ctf_map.load_map_meta(idx, dirname)
170170

171171
barriers = minetest.deserialize(minetest.decompress(barriers, "deflate"))
172172

173-
for _, barrier_area in pairs(barriers) do
174-
barrier_area.pos1 = vector.add(barrier_area.pos1, offset)
175-
barrier_area.pos2 = vector.add(barrier_area.pos2, offset)
176-
177-
for i = 1, barrier_area.max do
178-
if not barrier_area.reps[i] then
179-
barrier_area.reps[i] = minetest.CONTENT_IGNORE
180-
else
181-
barrier_area.reps[i] = minetest.get_content_id(barrier_area.reps[i])
173+
if barriers then
174+
for _, barrier_area in pairs(barriers) do
175+
barrier_area.pos1 = vector.add(barrier_area.pos1, offset)
176+
barrier_area.pos2 = vector.add(barrier_area.pos2, offset)
177+
178+
for i = 1, barrier_area.max do
179+
if not barrier_area.reps[i] then
180+
barrier_area.reps[i] = minetest.CONTENT_IGNORE
181+
else
182+
barrier_area.reps[i] = minetest.get_content_id(barrier_area.reps[i])
183+
end
182184
end
183185
end
184-
end
185186

186-
map.barriers = barriers
187+
map.barriers = barriers
188+
else
189+
if ctf_core.settings.server_mode ~= "mapedit" then
190+
assert(false, "Map "..dirname.." has a corrupted barriers file. Re-save map to fix")
191+
end
192+
193+
minetest.log("error", "Map "..dirname.." has a corrupted barriers file. Re-save map to fix")
194+
end
187195
else
188196
map.barrier_area = minetest.deserialize(meta:get("barrier_area"))
189197
end
@@ -351,7 +359,7 @@ function ctf_map.save_map(mapmeta)
351359
minetest.chat_send_all(minetest.colorize(ctf_map.CHAT_COLOR, "Map Saving Failed!"))
352360
end
353361

354-
local f = assert(io.open(path .. "barriers.data", "w"))
355-
f:write(minetest.compress(minetest.serialize(barriers), "deflate", 9))
362+
local f = assert(io.open(path .. "barriers.data", "wb"))
363+
f:write(minetest.serialize(barriers))
356364
f:close()
357365
end

0 commit comments

Comments
 (0)