Browse Source

Merge pull request #3 from dathost/master

Wait for auth response packet
pull/7/head
Richard Neumann 4 years ago
committed by GitHub
parent
commit
6457a9b103
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      rcon/client.py

8
rcon/client.py

@ -4,7 +4,7 @@ from socket import socket
from typing import Optional from typing import Optional
from rcon.exceptions import RequestIdMismatch, WrongPassword from rcon.exceptions import RequestIdMismatch, WrongPassword
from rcon.proto import Packet from rcon.proto import Packet, Type
__all__ = ['Client'] __all__ = ['Client']
@ -63,6 +63,9 @@ class Client:
with self._socket.makefile('wb') as file: with self._socket.makefile('wb') as file:
file.write(bytes(packet)) file.write(bytes(packet))
return self.read()
def read(self) -> Packet:
with self._socket.makefile('rb') as file: with self._socket.makefile('rb') as file:
return Packet.read(file) return Packet.read(file)
@ -70,6 +73,9 @@ class Client:
"""Performs a login.""" """Performs a login."""
response = self.communicate(Packet.make_login(passwd)) response = self.communicate(Packet.make_login(passwd))
while response.type != Type.SERVERDATA_AUTH_RESPONSE:
response = self.read()
if response.id == -1: if response.id == -1:
raise WrongPassword() raise WrongPassword()

Loading…
Cancel
Save