tweaks and fixes
This commit is contained in:
parent
e14d27f999
commit
f6f55d4c17
3 changed files with 11 additions and 3 deletions
|
@ -95,6 +95,9 @@ class MinecraftClient(CallbacksHolder, Runnable):
|
|||
def connected(self) -> bool:
|
||||
return self.started and self.dispatcher.connected
|
||||
|
||||
async def write(self, packet:Packet, wait:bool=False):
|
||||
await self.dispatcher.write(packet, wait)
|
||||
|
||||
def on_connected(self) -> Callable:
|
||||
def wrapper(fun):
|
||||
self.register(ClientEvent.CONNECTED, fun)
|
||||
|
@ -173,6 +176,9 @@ class MinecraftClient(CallbacksHolder, Runnable):
|
|||
except AuthException as e:
|
||||
self._logger.error(str(e))
|
||||
break
|
||||
except Exception as e:
|
||||
self._logger.exception("Unexpected error while authenticating")
|
||||
break
|
||||
try:
|
||||
packet_whitelist = self.callback_keys(filter=Packet) if self.options.use_packet_whitelist else set()
|
||||
await self.dispatcher.connect(
|
||||
|
|
|
@ -23,6 +23,7 @@ class AuthInterface:
|
|||
selectedProfile : GameProfile
|
||||
|
||||
SESSION_SERVER = "https://sessionserver.mojang.com/session/minecraft"
|
||||
TIMEOUT = aiohttp.ClientTimeout(total=3)
|
||||
|
||||
# async def authenticate(self, user:str, pwd:str):
|
||||
# raise NotImplementedError
|
||||
|
@ -50,7 +51,7 @@ class AuthInterface:
|
|||
|
||||
@classmethod
|
||||
async def _post(cls, endpoint:str, **kwargs) -> Dict[str, Any]:
|
||||
async with aiohttp.ClientSession() as sess:
|
||||
async with aiohttp.ClientSession(timeout=cls.TIMEOUT) as sess:
|
||||
async with sess.post(endpoint, **kwargs) as res:
|
||||
data = await res.json(content_type=None)
|
||||
if res.status >= 400:
|
||||
|
@ -59,7 +60,7 @@ class AuthInterface:
|
|||
|
||||
@classmethod
|
||||
async def _get(cls, endpoint:str, **kwargs) -> Dict[str, Any]:
|
||||
async with aiohttp.ClientSession() as sess:
|
||||
async with aiohttp.ClientSession(timeout=cls.TIMEOUT) as sess:
|
||||
async with sess.get(endpoint, **kwargs) as res:
|
||||
data = await res.json(content_type=None)
|
||||
if res.status >= 400:
|
||||
|
|
|
@ -85,6 +85,7 @@ class MicrosoftAuthenticator(AuthInterface):
|
|||
async def validate(self):
|
||||
prof = await self.fetch_profile()
|
||||
self.selectedProfile = GameProfile(id=prof['id'], name=prof['name'])
|
||||
logging.info("Session validated : %s", self.selectedProfile)
|
||||
|
||||
async def authenticate(self, code:str="") -> str:
|
||||
"""Authorize Microsoft account"""
|
||||
|
@ -106,7 +107,7 @@ class MicrosoftAuthenticator(AuthInterface):
|
|||
headers={ "Content-Type": "application/x-www-form-urlencoded" },
|
||||
data=urlencode(payload)
|
||||
)
|
||||
self.refreshToken = auth_response['refreshToken']
|
||||
self.refreshToken = auth_response['refresh_token']
|
||||
# maybe store expire_in and other stuff too? TODO
|
||||
|
||||
ms_token = auth_response['access_token']
|
||||
|
|
Loading…
Reference in a new issue