32 lines
1012 B
Python
32 lines
1012 B
Python
from asyncio import sleep
|
|
|
|
from .client_base import ClientBase
|
|
from .packet import packet_handler, oPacket
|
|
from .opcodes import RecvOps, SendOps
|
|
|
|
|
|
class Client(ClientBase):
|
|
def __init__(self, loop=None, username=None, password=None):
|
|
super().__init__(loop)
|
|
self._username = username
|
|
self._password = password
|
|
|
|
async def begin(self):
|
|
while self._loop.is_running() and self._sock.fileno():
|
|
action = await self._action_queue.get()
|
|
match action:
|
|
case SendOps.LOGIN_PASSWORD:
|
|
self._loop.create_task(self.do_login())
|
|
|
|
@packet_handler(RecvOps.PING)
|
|
async def pong(self, ipkt):
|
|
print("Sending PONG packet")
|
|
await sleep(1)
|
|
opkt = oPacket(SendOps.PONG)
|
|
await self.send_packet(opkt)
|
|
|
|
async def do_login(self):
|
|
opkt = oPacket(SendOps.LOGIN_PASSWORD)
|
|
opkt.encode_string(self._username)
|
|
opkt.encode_string(self._password)
|
|
await self.send_packet(opkt) |