Merge pull request #35 from DarkCat09/darkcat09-patch1
Errors, bedrock whitelist bug
This commit is contained in:
commit
b80defe9b3
5 changed files with 55 additions and 70 deletions
|
@ -21,10 +21,7 @@ from .aterrors import CloudflareError
|
||||||
from .aterrors import CredentialsError
|
from .aterrors import CredentialsError
|
||||||
from .aterrors import TokenError
|
from .aterrors import TokenError
|
||||||
from .aterrors import ServerError
|
from .aterrors import ServerError
|
||||||
from .aterrors import ServerEulaError
|
from .aterrors import ServerStartError
|
||||||
from .aterrors import ServerRunningError
|
|
||||||
from .aterrors import ServerSoftwareError
|
|
||||||
from .aterrors import ServerStorageError
|
|
||||||
from .aterrors import FileError
|
from .aterrors import FileError
|
||||||
from .aterrors import PermissionError
|
from .aterrors import PermissionError
|
||||||
from .atjsparse import exec, atob
|
from .atjsparse import exec, atob
|
||||||
|
@ -41,8 +38,8 @@ __all__ = [
|
||||||
'PlayersList', 'AternosConfig', 'AternosWss',
|
'PlayersList', 'AternosConfig', 'AternosWss',
|
||||||
'FileManager', 'AternosFile', 'AternosError',
|
'FileManager', 'AternosFile', 'AternosError',
|
||||||
'CloudflareError', 'CredentialsError', 'TokenError',
|
'CloudflareError', 'CredentialsError', 'TokenError',
|
||||||
'ServerError', 'ServerEulaError', 'ServerRunningError',
|
'ServerError', 'ServerStartError', 'FileError',
|
||||||
'ServerSoftwareError', 'ServerStorageError', 'FileError',
|
'PermissionError',
|
||||||
'exec', 'atob', 'to_ecma5_function',
|
'exec', 'atob', 'to_ecma5_function',
|
||||||
|
|
||||||
'Edition', 'Status', 'Lists',
|
'Edition', 'Status', 'Lists',
|
||||||
|
|
|
@ -249,4 +249,6 @@ class AternosConnect:
|
||||||
f'{method} completed with {req.status_code} status'
|
f'{method} completed with {req.status_code} status'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
req.raise_for_status()
|
||||||
|
|
||||||
return req
|
return req
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
from typing import Final
|
||||||
|
|
||||||
|
|
||||||
class AternosError(Exception):
|
class AternosError(Exception):
|
||||||
|
|
||||||
"""Common error class"""
|
"""Common error class"""
|
||||||
|
@ -23,31 +26,53 @@ class TokenError(AternosError):
|
||||||
|
|
||||||
class ServerError(AternosError):
|
class ServerError(AternosError):
|
||||||
|
|
||||||
"""Common class for server errors"""
|
"""Common class for server errors
|
||||||
|
|
||||||
|
:param reason: Code which contains error reason
|
||||||
|
:type reason: str
|
||||||
|
:param message: Error message, defaults to ''
|
||||||
|
:type message: str, optional
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, reason: str, message: str = '') -> None:
|
||||||
|
|
||||||
|
self.reason = reason
|
||||||
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
class ServerEulaError(ServerError):
|
class ServerStartError(AternosError):
|
||||||
|
|
||||||
"""Raised when trying to start without
|
"""Raised when Aternos can not start Minecraft server
|
||||||
confirming Mojang EULA"""
|
|
||||||
|
|
||||||
|
:param reason: Code which contains error reason
|
||||||
|
:type reason: str
|
||||||
|
"""
|
||||||
|
|
||||||
class ServerRunningError(ServerError):
|
MESSAGE: Final = 'Unable to start server, code: {}'
|
||||||
|
reason_msg = {
|
||||||
|
|
||||||
"""Raised when trying to start
|
'eula':
|
||||||
already running server"""
|
'EULA was not accepted. '
|
||||||
|
'Use start(accepteula=True)',
|
||||||
|
|
||||||
|
'already': 'Server is already running',
|
||||||
|
'wrongversion': 'Incorrect software version installed',
|
||||||
|
|
||||||
class ServerSoftwareError(ServerError):
|
'file':
|
||||||
|
'File server is unavailbale, '
|
||||||
|
'view https://status.aternos.gmbh',
|
||||||
|
|
||||||
"""Raised when Aternos notifies about
|
'size': 'Available storage size limit (4 GB) was reached'
|
||||||
incorrect software version"""
|
}
|
||||||
|
|
||||||
|
def __init__(self, reason: str) -> None:
|
||||||
|
|
||||||
class ServerStorageError(ServerError):
|
super().__init__(
|
||||||
|
reason,
|
||||||
"""Raised when Aternos notifies about
|
self.reason_msg.get(
|
||||||
violation of storage limits (4 GB for now)"""
|
reason, self.MESSAGE.format(reason)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class FileError(AternosError):
|
class FileError(AternosError):
|
||||||
|
@ -55,7 +80,8 @@ class FileError(AternosError):
|
||||||
"""Raised when trying to execute a disallowed
|
"""Raised when trying to execute a disallowed
|
||||||
by Aternos file operation"""
|
by Aternos file operation"""
|
||||||
|
|
||||||
|
|
||||||
class PermissionError(AternosError):
|
class PermissionError(AternosError):
|
||||||
"""Raised when trying to execute a non-allowed
|
|
||||||
command on a server (Think friends permissions)"""
|
"""Raised when trying to execute a disallowed command,
|
||||||
|
usually because of shared access rights"""
|
||||||
|
|
|
@ -35,7 +35,7 @@ class PlayersList:
|
||||||
|
|
||||||
self.atserv = atserv
|
self.atserv = atserv
|
||||||
self.lst = Lists(lst)
|
self.lst = Lists(lst)
|
||||||
|
|
||||||
common_whl = (self.lst == Lists.whl)
|
common_whl = (self.lst == Lists.whl)
|
||||||
bedrock = (atserv.edition == Edition.bedrock)
|
bedrock = (atserv.edition == Edition.bedrock)
|
||||||
if common_whl and bedrock:
|
if common_whl and bedrock:
|
||||||
|
|
|
@ -4,11 +4,7 @@ from requests import Response
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
from .atconnect import AternosConnect
|
from .atconnect import AternosConnect
|
||||||
from .aterrors import ServerError
|
from .aterrors import ServerStartError
|
||||||
from .aterrors import ServerEulaError
|
|
||||||
from .aterrors import ServerRunningError
|
|
||||||
from .aterrors import ServerSoftwareError
|
|
||||||
from .aterrors import ServerStorageError
|
|
||||||
from .atfm import FileManager
|
from .atfm import FileManager
|
||||||
from .atconf import AternosConfig
|
from .atconf import AternosConfig
|
||||||
from .atplayers import PlayersList
|
from .atplayers import PlayersList
|
||||||
|
@ -99,16 +95,8 @@ class AternosServer:
|
||||||
:param accepteula: Automatically accept
|
:param accepteula: Automatically accept
|
||||||
the Mojang EULA, defaults to `True`
|
the Mojang EULA, defaults to `True`
|
||||||
:type accepteula: bool, optional
|
:type accepteula: bool, optional
|
||||||
:raises ServerEulaError: When trying to start a server
|
:raises ServerStartError: When Aternos
|
||||||
without accepting the Mojang EULA
|
is unable to start the server
|
||||||
:raises ServerRunningError: When trying to start a server
|
|
||||||
which is alreday running
|
|
||||||
:raises ServerSoftwareError: When Aternos notifies about
|
|
||||||
incorrect software version
|
|
||||||
:raises ServerStorageError: When Aternos notifies about
|
|
||||||
voilation of storage limits (4 GB for now)
|
|
||||||
:raises ServerError: When API is unable to start a Minecraft server
|
|
||||||
due to unavailability of Aternos' file servers or other problems
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
startreq = self.atserver_request(
|
startreq = self.atserver_request(
|
||||||
|
@ -120,42 +108,14 @@ class AternosServer:
|
||||||
|
|
||||||
if startresult['success']:
|
if startresult['success']:
|
||||||
return
|
return
|
||||||
|
|
||||||
error = startresult['error']
|
error = startresult['error']
|
||||||
|
|
||||||
if error == 'eula' and accepteula:
|
if error == 'eula' and accepteula:
|
||||||
self.eula()
|
self.eula()
|
||||||
self.start(accepteula=False)
|
return self.start(accepteula=False)
|
||||||
|
|
||||||
elif error == 'eula':
|
raise ServerStartError(error)
|
||||||
raise ServerEulaError(
|
|
||||||
'EULA was not accepted. Use start(accepteula=True)'
|
|
||||||
)
|
|
||||||
|
|
||||||
elif error == 'already':
|
|
||||||
raise ServerRunningError(
|
|
||||||
'Server is already running'
|
|
||||||
)
|
|
||||||
|
|
||||||
elif error == 'wrongversion':
|
|
||||||
raise ServerSoftwareError(
|
|
||||||
'Incorrect software version installed'
|
|
||||||
)
|
|
||||||
|
|
||||||
elif error == 'file':
|
|
||||||
raise ServerError(
|
|
||||||
'File server is unavailbale, view https://status.aternos.gmbh'
|
|
||||||
)
|
|
||||||
|
|
||||||
elif error == 'size':
|
|
||||||
raise ServerStorageError(
|
|
||||||
f'Available storage size is 4GB, '
|
|
||||||
f'your server used: {startresult["size"]}'
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise ServerError(
|
|
||||||
f'Unable to start server, code: {error}'
|
|
||||||
)
|
|
||||||
|
|
||||||
def confirm(self) -> None:
|
def confirm(self) -> None:
|
||||||
|
|
||||||
|
|
Reference in a new issue