Skip to content

Commit

Permalink
fixed error on multi sized packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshi-E committed Apr 21, 2023
1 parent 3f9eb23 commit a4959b6
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions bec_rcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import socket
import re
import time
import zlib
import asyncio
from collections import deque
Expand Down Expand Up @@ -240,10 +239,9 @@ def sendReciveConfirmation(self, sequence):

async def listenForData(self):
while (self.disconnected == False):
answer = ""
answer = None
try:
answer = self.socket.recv(102400).decode(self.codec)

answer = self.socket.recv(4096).decode(self.codec)
header = answer[:7]
crc32_checksum = header[2:-1] # TODO: verify checksum

Expand All @@ -267,11 +265,13 @@ async def listenForData(self):
raise PermissionError(excption)
else:
self.login_Sucess()
except BlockingIOError:
except BlockingIOError as e:
pass
if(answer==""):
await asyncio.sleep(0.2)

except Exception as e:
self.logger.exception(f"listenForData: {e}")

if not answer:
await asyncio.sleep(0.2)

async def keepAliveLoop(self):
while (self.disconnected == False):
Expand Down Expand Up @@ -360,10 +360,10 @@ def received_ServerMessage(self, packet, message):
#waitForResponse() handles all inbound packets, you can still fetch them here though.
def received_CommandMessage(self, packet, message):
if(len(message)>3 and self.String2Hex(message[0]) =="00"): #is multi packet
self.MultiPackets.append(message[3:])
self.multiPackets.append(message[3:])
if(int(self.String2Hex(message[1]),16)-1 == int(self.String2Hex(message[2]),16)):
self.serverCommandData.append([datetime.datetime.now(), "".join(self.MultiPackets)])
self.MultiPackets = []
self.serverCommandData.append([datetime.datetime.now(), "".join(self.multiPackets)])
self.multiPackets = []
else: #Normal Package
self.serverCommandData.append([datetime.datetime.now(), message])
self.check_Event("received_CommandMessage", message)
Expand Down

0 comments on commit a4959b6

Please sign in to comment.