diff options
author | ShadowNinja <shadowninja@minetest.net> | 2014-10-24 15:01:46 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2014-10-24 16:45:10 -0400 |
commit | 796aa3870d5cd45696cb253024aa75e8bbc2b462 (patch) | |
tree | ea17e9c6e87af555427f1ec9c8ce9bce2be66c57 /worldedit_commands | |
parent | 70c24c9501c691d85bbe267ee79547fb490e6c00 (diff) |
Clean up serialization
* Adds a header to serialized data (to make version checking sane).
* Removes the duplicate deserialization for `worldedit.deserialize` and `worldedit.allocate`.
* Optimizes `worldedit.deserialize` by only deserializing the data once.
* Makes some fields optional.
* Cleans up the comments and a little of the code style.
Diffstat (limited to 'worldedit_commands')
-rw-r--r-- | worldedit_commands/init.lua | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 7d347c9..93e594a 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -911,9 +911,12 @@ minetest.register_chatcommand("/allocate", { local value = file:read("*a")
file:close()
- if worldedit.valueversion(value) == 0 then --unknown version
- worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
+ local version = worldedit.read_header(value)
+ if version == 0 then
+ worldedit.player_notify(name, "File is invalid!")
return
+ elseif version > worldedit.LATEST_SERIALIZATION_VERSION then
+ worldedit.player_notify(name, "File was created with newer version of WorldEdit!")
end
local nodepos1, nodepos2, count = worldedit.allocate(pos, value)
@@ -963,8 +966,12 @@ minetest.register_chatcommand("/load", { local value = file:read("*a")
file:close()
- if worldedit.valueversion(value) == 0 then --unknown version
- worldedit.player_notify(name, "invalid file: file is invalid or created with newer version of WorldEdit")
+ local version = worldedit.read_header(value)
+ if version == 0 then
+ worldedit.player_notify(name, "File is invalid!")
+ return
+ elseif version > worldedit.LATEST_SERIALIZATION_VERSION then
+ worldedit.player_notify(name, "File was created with newer version of WorldEdit!")
return
end
|