home
·
contact
·
privacy
projects
/
plomrogue
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6a0fd2e
)
Server/py: On savefile writing, handle escapes and quotes.
author
Christian Heller
<c.heller@plomlompom.de>
Mon, 2 Mar 2015 04:17:27 +0000
(
05:17
+0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Mon, 2 Mar 2015 04:17:27 +0000
(
05:17
+0100)
plomrogue-server.py
patch
|
blob
|
history
diff --git
a/plomrogue-server.py
b/plomrogue-server.py
index 7c67024f39d6e7e4b17aa00912feb839c7597e9f..c8cb0eebaa8548018f8fce0f990e7d784180d96b 100755
(executable)
--- a/
plomrogue-server.py
+++ b/
plomrogue-server.py
@@
-119,18
+119,20
@@
def record(command):
def save_world():
"""Save all commands needed to reconstruct current world state."""
# TODO: Misses same optimizations as record() from the original record().
def save_world():
"""Save all commands needed to reconstruct current world state."""
# TODO: Misses same optimizations as record() from the original record().
- # TODO: How to handle strings that contain ' or "?
+
+ def quote(string):
+ string = string.replace("\u005C", '\u005C\u005C')
+ return '"' + string.replace('"', '\u005C"') + '"'
def mapsetter(key):
def helper(id):
string = ""
if world_db["Things"][id][key]:
def mapsetter(key):
def helper(id):
string = ""
if world_db["Things"][id][key]:
-
mem
map = world_db["Things"][id][key]
+
r
map = world_db["Things"][id][key]
length = world_db["MAP_LENGTH"]
for i in range(world_db["MAP_LENGTH"]):
length = world_db["MAP_LENGTH"]
for i in range(world_db["MAP_LENGTH"]):
- string = string + key + " " + str(i) + " '" + \
- memmap[i * length:(i * length) + length].decode() \
- + "'\n"
+ line = rmap[i * length:(i * length) + length].decode()
+ string = string + key + " " + str(i) + quote(line) + "\n"
return string
return helper
return string
return helper
@@
-148,7
+150,7
@@
def save_world():
for key in world_db[category][id]:
if not key in special_keys:
x = world_db[category][id][key]
for key in world_db[category][id]:
if not key in special_keys:
x = world_db[category][id][key]
- argument =
"'" + x + "'"
if str == type(x) else str(x)
+ argument =
quote(x)
if str == type(x) else str(x)
string = string + key + " " + argument + "\n"
elif special_keys[key]:
string = string + special_keys[key](id)
string = string + key + " " + argument + "\n"
elif special_keys[key]:
string = string + special_keys[key](id)