1
0
Fork 0
This commit is contained in:
khr 2020-03-29 03:56:32 +02:00
parent 52ad431877
commit 14f7819a79
1 changed files with 10 additions and 10 deletions

View File

@ -80,7 +80,6 @@ class socket_util(object):
self.write(integer_buf) self.write(integer_buf)
def write(self, data: bytes): def write(self, data: bytes):
#socket.bind(address)
data_len = len(data) data_len = len(data)
offset = 0 offset = 0
while offset != data_len: while offset != data_len:
@ -88,7 +87,7 @@ class socket_util(object):
def receive(self): def receive(self):
r,s,e = select.select([self.soc], [], [], 1) r,s,e = select.select([self.soc], [], [], 1)
#LOG.info("r" + str(r)) LOG.debug("r: {!r}".format(r))
if r == []: if r == []:
return "" return ""
message_size = self.read_int() message_size = self.read_int()
@ -96,10 +95,11 @@ class socket_util(object):
self.close_socket() self.close_socket()
return None return None
data = self.read(message_size) data = self.read(message_size)
LOG.debug("data: {!r}".format(data))
if data == None: if data == None:
LOG.debug("data_none") LOG.debug("data was none")
return None return None
message = json.loads(data) message = json.loads(data.decode("utf-8"))
return message return message
@ -111,7 +111,7 @@ class socket_util(object):
return struct.unpack('>i', intbuf)[0] return struct.unpack('>i', intbuf)[0]
def read(self, size): def read(self, size):
data = "" data = b""
while len(data) != size: while len(data) != size:
newdata = self.soc.recv(size - len(data)) newdata = self.soc.recv(size - len(data))
if len(newdata) == 0: if len(newdata) == 0:
@ -148,7 +148,7 @@ class MinecraftWrapper(socket_util):
raise subprocess.CalledProcessError(return_code, self.command) raise subprocess.CalledProcessError(return_code, self.command)
def msg_process(self): def msg_process(self):
while(not self.exit): while not self.exit:
try: try:
self.proc_monitor() self.proc_monitor()
status = 1 status = 1
@ -239,7 +239,6 @@ class MinecraftServerBridge(socket_util):
self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
LOG.info("Server accepted connection: " + str(self.addr)) LOG.info("Server accepted connection: " + str(self.addr))
def msg_process(self): def msg_process(self):
while(True): while(True):
try: try:
@ -250,10 +249,9 @@ class MinecraftServerBridge(socket_util):
if rcv != "" and rcv != None: if rcv != "" and rcv != None:
self.msg_handle(rcv) self.msg_handle(rcv)
except Exception as e: except Exception as e:
LOG.info(e) LOG.exception(e)
self.socket_reset() self.socket_reset()
def msg_handle(self, msg): def msg_handle(self, msg):
#for msg, create user and post as user #for msg, create user and post as user
#add minecraft user to minecraft channel, if this fails, no big deal #add minecraft user to minecraft channel, if this fails, no big deal
@ -284,7 +282,7 @@ class MinecraftServerBridge(socket_util):
self.avatar_update_log[msg['user']] = time.time() self.avatar_update_log[msg['user']] = time.time()
avatar_url = self.get_mc_skin(msg['user'], user_id) avatar_url = self.get_mc_skin(msg['user'], user_id)
if avatar_url: if avatar_url:
LOG.info("avatar_url is " + avatar_url) LOG.debug("avatar_url is " + avatar_url)
self.api._send("PUT", '/profile/'+user_id+'/avatar_url/', content={"avatar_url":avatar_url}, query_params={"user_id": user_id}, headers={"Content-Type":"application/json"}) self.api._send("PUT", '/profile/'+user_id+'/avatar_url/', content={"avatar_url":avatar_url}, query_params={"user_id": user_id}, headers={"Content-Type":"application/json"})
#attempt to post in room #attempt to post in room
@ -422,3 +420,5 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()
# vi: set expandtab sw=4 ts=4 softtabstop=4