2022-05-18 19:35:46 +04:00
|
|
|
import asyncio
|
|
|
|
from getpass import getpass
|
|
|
|
|
2022-10-05 16:59:48 +04:00
|
|
|
from typing import Tuple, Dict, Any
|
|
|
|
|
|
|
|
from python_aternos import Client, Streams
|
|
|
|
|
2023-05-29 11:44:19 +04:00
|
|
|
|
2022-10-05 16:59:48 +04:00
|
|
|
# Request credentials
|
2022-05-18 19:35:46 +04:00
|
|
|
user = input('Username: ')
|
|
|
|
pswd = getpass('Password: ')
|
2022-06-17 12:30:58 +04:00
|
|
|
|
2023-05-29 11:44:19 +04:00
|
|
|
# Instantiate Client
|
|
|
|
atclient = Client()
|
|
|
|
aternos = atclient.account
|
|
|
|
|
|
|
|
# Enable debug logging
|
2022-06-17 12:30:58 +04:00
|
|
|
logs = input('Show detailed logs? (y/n) ').strip().lower() == 'y'
|
|
|
|
if logs:
|
2023-05-29 11:44:19 +04:00
|
|
|
atclient.debug = True
|
2022-06-17 12:30:58 +04:00
|
|
|
|
2023-05-29 11:44:19 +04:00
|
|
|
# Authenticate
|
2023-05-24 20:04:00 +04:00
|
|
|
atclient.login(user, pswd)
|
2022-05-18 19:35:46 +04:00
|
|
|
|
2022-10-05 16:59:48 +04:00
|
|
|
server = aternos.list_servers()[0]
|
|
|
|
socket = server.wss()
|
2022-05-18 19:35:46 +04:00
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
|
2022-10-05 16:59:48 +04:00
|
|
|
# Handler for console messages
|
2023-05-24 20:04:00 +04:00
|
|
|
@socket.wssreceiver(Streams.console, ('Server 1',)) # type: ignore
|
2022-10-05 16:59:48 +04:00
|
|
|
async def console(
|
|
|
|
msg: Dict[Any, Any],
|
|
|
|
args: Tuple[str]) -> None:
|
|
|
|
|
2022-05-18 19:35:46 +04:00
|
|
|
print(args[0], 'received', msg)
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
|
2022-10-05 16:59:48 +04:00
|
|
|
# Main function
|
|
|
|
async def main() -> None:
|
|
|
|
server.start()
|
2022-05-18 19:35:46 +04:00
|
|
|
await socket.connect()
|
|
|
|
await asyncio.create_task(loop())
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
|
2022-10-05 16:59:48 +04:00
|
|
|
# Keepalive
|
|
|
|
async def loop() -> None:
|
2022-05-18 19:35:46 +04:00
|
|
|
while True:
|
2022-10-05 16:59:48 +04:00
|
|
|
await asyncio.Future()
|
|
|
|
|
2022-05-18 19:35:46 +04:00
|
|
|
|
|
|
|
asyncio.run(main())
|