added utf8 support, limit messages length to prevent unexpected disconnects
This commit is contained in:
1 parent
4988ab6ae1
commit
7e993237e3
3 files changed
+10
-11
No files matched your search
@@ -46,7 +46,7 @@ def readByteArray(FileObject, length):
|
||||
|
||||
def readString(FileObject):
|
||||
length = readShort(FileObject) * 2
|
||||
return FileObject.read(length).decode("utf-16be")
|
||||
return unicode(FileObject.read(length), "utf-16be")
|
||||
|
||||
|
||||
def sendBoolean(socket, value):
|
||||
@@ -88,10 +88,9 @@ def sendDouble(socket, value):
|
||||
|
||||
|
||||
def sendString(socket, value):
|
||||
if (type(value) is not types.StringType):
|
||||
value = str(value)
|
||||
socket.send(struct.pack('>h', value.__len__()))
|
||||
socket.send(value.encode('utf-16be'))
|
||||
value = unicode(value).encode('utf-16be')
|
||||
socket.send(struct.pack('>h', len(value) / 2))
|
||||
socket.send(value)
|
||||
|
||||
|
||||
def readEntityMetadata(FileObject):
|
||||
@@ -145,4 +144,4 @@ def readSlotData(FileObject):
|
||||
}
|
||||
return {'BlockID': -1,
|
||||
'ItemCount': 0
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user