Skip to content

Commit

Permalink
Fix packet processing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekuruu committed May 31, 2024
1 parent 54f1256 commit 25f2f85
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions osu/tcp/bancho.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,23 @@ def connect(self):

def process_packets(self) -> None:
"""Process incoming packets from the server"""
while True:
packet_header = StreamIn(self.socket.recv(7))
packet_header = StreamIn(self.socket.recv(7))

if packet_header.eof():
return
if packet_header.eof():
return

packet_id = packet_header.u16()
compression = packet_header.bool()
packet_size = packet_header.u32()
packet_data = self.socket.recv(packet_size)
packet_id = packet_header.u16()
compression = packet_header.bool()
packet_size = packet_header.u32()
packet_data = self.socket.recv(packet_size)

if compression:
packet_data = gzip.decompress(packet_data)
if compression:
packet_data = gzip.decompress(packet_data)

packet, stream = ServerPackets(packet_id), StreamIn(packet_data)
packet, stream = ServerPackets(packet_id), StreamIn(packet_data)

self.logger.debug(f'Received packet {packet.name} -> "{stream.get()}"')
self.game.packets.packet_received(packet, stream, self.game)
self.logger.debug(f'Received packet {packet.name} -> "{stream.get()}"')
self.game.packets.packet_received(packet, stream, self.game)

def enqueue(
self, packet: ClientPackets, data: bytes = b"", dequeue: bool = False
Expand Down

0 comments on commit 25f2f85

Please sign in to comment.