rcon: fix for python 3
We need to encode the payload since rcon is a binary protocol. Also, add some more error checking. Fixes #1605.
This commit is contained in:
@@ -37,10 +37,11 @@ class RConConnection():
|
|||||||
|
|
||||||
def send(self, t, payload):
|
def send(self, t, payload):
|
||||||
self.rid = self.rid + 1
|
self.rid = self.rid + 1
|
||||||
|
pld_enc = payload.encode("utf-8")
|
||||||
header = struct.pack("<iii",
|
header = struct.pack("<iii",
|
||||||
len(payload) + 4 + 4 + 2, # rid, type and padding
|
len(pld_enc) + 4 + 4 + 2, # rid, type and padding
|
||||||
self.rid, t)
|
self.rid, t)
|
||||||
data = header + payload + '\x00\x00'
|
data = header + pld_enc + b'\x00\x00'
|
||||||
self.sock.send(data)
|
self.sock.send(data)
|
||||||
|
|
||||||
toread = select.select([self.sock], [], [], 30)
|
toread = select.select([self.sock], [], [], 30)
|
||||||
@@ -51,6 +52,9 @@ class RConConnection():
|
|||||||
try:
|
try:
|
||||||
res_len, res_id, res_type = \
|
res_len, res_id, res_type = \
|
||||||
struct.unpack("<iii", self.sock.recv(12, socket.MSG_WAITALL))
|
struct.unpack("<iii", self.sock.recv(12, socket.MSG_WAITALL))
|
||||||
|
if res_len < 0:
|
||||||
|
raise Exception("Response length is {}.".format(res_len))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RConException(self.rid,
|
raise RConException(self.rid,
|
||||||
"RCon protocol error. Are you sure you're "
|
"RCon protocol error. Are you sure you're "
|
||||||
|
|||||||
Reference in New Issue
Block a user