diff options
author | Diego Roversi <diegor@tiscali.it> | 2019-09-20 11:03:21 +0200 |
---|---|---|
committer | Diego Roversi <diegor@tiscali.it> | 2019-09-20 11:03:21 +0200 |
commit | a78183e29504b9c1915b9e3d254db6ab185f7b33 (patch) | |
tree | ab315cd36780759e37ab42caa0a41c7e5841341b /common | |
parent | 41dcc63938e33f88ba0925f24d9835ab478e194d (diff) |
use hashlib instead of md5, convert string to bytearrays
Diffstat (limited to 'common')
-rw-r--r-- | common/gamesrv.py | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/common/gamesrv.py b/common/gamesrv.py index 303d7d0..fed2320 100644 --- a/common/gamesrv.py +++ b/common/gamesrv.py @@ -86,8 +86,10 @@ class DataChunk: client.msgl.append(msgdef) def getmd5def(self, fileid, data, offset=0): - checksum = md5.new(data).digest() - return message(MSG_MD5_FILE, fileid, protofilepath(self.filename), + md5 = hashlib.md5() + md5.update(data) + checksum = md5.digest() + return message(MSG_MD5_FILE, fileid, protofilepath(self.filename).encode(), offset, len(data), checksum) @@ -229,9 +231,9 @@ class Music(DataChunk): try: msg = self.md5msgs[position] except KeyError: - data = self.read((position, blocksize)) - checksum = md5.new(data).digest() - msg = message(MSG_MD5_FILE, self.fileid, protofilepath(self.filename), + data = self.read(position, blocksize) + checksum = hashlib.md5(data).digest() + msg = message(MSG_MD5_FILE, self.fileid, protofilepath(self.filename).encode(), position, blocksize, checksum) self.md5msgs[position] = msg return msg @@ -253,7 +255,7 @@ class Music(DataChunk): def clearsprites(): sprites_by_n.clear() - sprites[:] = [''] + sprites[:] = [b''] def compactsprites(insert_new=None, insert_before=None): global sprites, sprites_by_n @@ -262,7 +264,7 @@ def compactsprites(insert_new=None, insert_before=None): insert_before = insert_before.alive else: insert_before = None - newsprites = [''] + newsprites = [b''] newd = {} l = list(sprites_by_n.items()) l.sort() @@ -299,7 +301,7 @@ class Sprite: -ico.h < y < game.height): sprites.append(pack("!hhh", x, y, ico.code)) else: - sprites.append('') # starts off-screen + sprites.append(b'') # starts off-screen sprites_by_n[self.alive] = self def move(self, x,y, ico=None): @@ -340,12 +342,12 @@ class Sprite: sprites[self.alive] = pack("!hhh", self.x, self.y, ico.code) def hide(self): - sprites[self.alive] = '' + sprites[self.alive] = b'' def kill(self): if self.alive: del sprites_by_n[self.alive] - sprites[self.alive] = '' + sprites[self.alive] = b'' self.alive = 0 def prefix(self, n, m=0): @@ -357,7 +359,7 @@ class Sprite: def _force_to_front(self): info = sprites[self.alive] - sprites[self.alive] = '' + sprites[self.alive] = b'' del sprites_by_n[self.alive] self.alive = len(sprites) sprites_by_n[self.alive] = self @@ -380,7 +382,7 @@ class Sprite: s1._force_to_front() assert n1 not in sprites_by_n info = sprites[self.alive] - sprites[self.alive] = '' + sprites[self.alive] = b'' del sprites_by_n[self.alive] self.alive = n1 sprites_by_n[n1] = self @@ -459,7 +461,7 @@ class Client: if self.initialdata: self.send_buffer(self.initialdata) elif self.initialized == 2: - buffer = ''.join(self.msgl) + buffer = b''.join(self.msgl) if buffer: self.send_buffer(buffer) if self.udpsocket is not None: @@ -503,7 +505,7 @@ class Client: threads = [] for t in range(3): co = zlib.compressobj(6) - threads.append((chr(0x88 + t) + chr(t), co)) + threads.append( (bytes(0x88 + t, t), co) ) frame = 0 globalsync = 0 @@ -593,16 +595,16 @@ class Client: except struct.error: import traceback traceback.print_exc() - self.socket.send('\n\n<h1>Protocol Error</h1>\n') + self.socket.send(b'\n\n<h1>Protocol Error</h1>\n') hs = findsocket('HTTP') if hs is not None: url = 'http://%s:%s' % (HOSTNAME, displaysockport(hs)) - self.socket.send(''' + self.socket.send(b''' If you meant to point your web browser to this server, then use the following address: <a href="%s">%s</a> -''' % (url, url)) +''' % (url.encode(), url.encode())) self.disconnect('protocol error', 'receive') def input_handler(self): @@ -820,7 +822,7 @@ class SimpleClient(Client): def finishinit(self, game): num = 0 for keyname, icolist, fn in game.FnKeys: - self.msgl.append(message(MSG_DEF_KEY, keyname, num, + self.msgl.append(message(MSG_DEF_KEY, keyname.encode(), num, *[ico.code for ico in icolist])) num += 1 @@ -850,7 +852,7 @@ bitmaps = {} samples = {} music_by_id = {} currentmusics = [0] -sprites = [''] +sprites = [b''] sprites_by_n = {} recording = None game = None @@ -1137,7 +1139,7 @@ class Game: def deffieldmsg(self): return message(MSG_DEF_PLAYFIELD, self.width, self.height, self.backcolor, - self.FnDesc) + self.FnDesc.encode()) def socketerrors(self, ewtd): for c in clients[:]: |