Reverse illegitimate changes on server

This commit is contained in:
Joscha 2017-04-14 09:41:02 +00:00
parent 54e09d18cc
commit 3cb21c02bc
3 changed files with 50 additions and 6 deletions

View file

@ -1,3 +1,4 @@
import string
import threading
import time
from utils import CHUNK_WIDTH, CHUNK_HEIGHT, Position
@ -65,6 +66,20 @@ class ChunkDiff():
def empty(self):
return not bool(self._chars)
def legitimate(self):
for i, char in self._chars.items():
if not (isinstance(char, str) and len(char) == 1 and ord(char) > 31 and (char not in string.whitespace or char == " ")):
return False
else:
return True
def diff(self, chunk):
diffs = {}
for pos, char in self._chars.items():
diffs[pos] = chunk._chars.get(pos, " ")
return ChunkDiff.from_dict(diffs)
def jsonify_changes(changes):
dchanges = []