diff --git a/src/aiocraft/mc/auth/__init__.py b/src/aiocraft/mc/auth/__init__.py index e51c27c..a960dfc 100644 --- a/src/aiocraft/mc/auth/__init__.py +++ b/src/aiocraft/mc/auth/__init__.py @@ -1,3 +1,3 @@ -from .interface import AuthException, AuthInterface +from .interface import AuthException, AuthInterface, OfflineAuthenticator from .microsoft import MicrosoftAuthenticator from .mojang import MojangAuthenticator diff --git a/src/aiocraft/mc/auth/interface.py b/src/aiocraft/mc/auth/interface.py index b68a364..ed1b9b0 100644 --- a/src/aiocraft/mc/auth/interface.py +++ b/src/aiocraft/mc/auth/interface.py @@ -1,5 +1,6 @@ """Minecraft authentication interface""" import logging +from multiprocessing.sharedctypes import Value from typing import Optional, Dict, Any import aiohttp @@ -40,7 +41,7 @@ class AuthInterface: def serialize(self) -> Dict[str, Any]: raise NotImplementedError - def deserialize(self, data:Dict[str, Any]) -> 'AuthInterface': + def deserialize(self, data:Dict[str, Any]): raise NotImplementedError async def join(self, server_id) -> dict: @@ -80,3 +81,24 @@ class AuthInterface: if res.status >= 400: raise AuthException(endpoint, res.status, data, kwargs) return data + +class OfflineAuthenticator(AuthInterface): + def __init__(self, name:str, id:str=''): + self.accessToken = '' + self.selectedProfile = GameProfile(id=id, name=name) + + async def login(self) -> 'AuthInterface': + raise AuthException('login', 418, {"error":"offline authenticator cannot login"}, kwargs={}) + + async def refresh(self) -> 'AuthInterface': + raise AuthException('refresh', 418, {"error":"offline authenticator cannot refresh"}, kwargs={}) + + async def validate(self) -> 'AuthInterface': + raise AuthException('validate', 418, {"error":"offline authenticator cannot validate"}, kwargs={}) + + def serialize(self) -> Dict[str, Any]: + return {} + + def deserialize(self, data:Dict[str, Any]) -> 'AuthInterface': + pass +