2022-07-01 14:28:39 +04:00
|
|
|
"""Operators, whitelist and banned players lists"""
|
|
|
|
|
2022-03-18 18:38:36 +04:00
|
|
|
import enum
|
2022-08-22 09:55:08 +04:00
|
|
|
|
2022-03-25 16:45:38 +04:00
|
|
|
from typing import List, Union
|
2021-10-15 19:31:47 +04:00
|
|
|
from typing import TYPE_CHECKING
|
2021-10-15 15:12:45 +04:00
|
|
|
|
2022-08-22 09:55:08 +04:00
|
|
|
import lxml.html
|
|
|
|
|
2021-10-15 19:31:47 +04:00
|
|
|
if TYPE_CHECKING:
|
2022-06-23 15:13:56 +04:00
|
|
|
from .atserver import AternosServer
|
|
|
|
|
2022-03-18 18:38:36 +04:00
|
|
|
|
|
|
|
class Lists(enum.Enum):
|
2021-10-15 19:31:47 +04:00
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
"""Players list type enum"""
|
|
|
|
|
|
|
|
whl = 'whitelist'
|
2022-07-01 09:36:52 +04:00
|
|
|
whl_je = 'whitelist'
|
|
|
|
whl_be = 'allowlist'
|
2022-06-23 15:13:56 +04:00
|
|
|
ops = 'ops'
|
|
|
|
ban = 'banned-players'
|
|
|
|
ips = 'banned-ips'
|
|
|
|
|
2022-03-18 18:38:36 +04:00
|
|
|
|
|
|
|
class PlayersList:
|
2021-10-15 15:12:45 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
"""Class for managing operators,
|
|
|
|
whitelist and banned players lists"""
|
2022-06-23 15:13:56 +04:00
|
|
|
|
2022-07-01 14:28:39 +04:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
lst: Union[str, Lists],
|
|
|
|
atserv: 'AternosServer') -> None:
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
"""Class for managing operators,
|
|
|
|
whitelist and banned players lists
|
|
|
|
|
|
|
|
Args:
|
|
|
|
lst (Union[str,Lists]): Players list type, must be
|
|
|
|
atplayers.Lists enum value
|
|
|
|
atserv (python_aternos.atserver.AternosServer):
|
|
|
|
atserver.AternosServer instance
|
|
|
|
"""
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
self.atserv = atserv
|
|
|
|
self.lst = Lists(lst)
|
2022-07-01 10:31:23 +04:00
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
# Fix for #30 issue
|
|
|
|
# whl_je = whitelist for java
|
|
|
|
# whl_be = whitelist for bedrock
|
|
|
|
# whl = common whitelist
|
2022-07-01 09:36:52 +04:00
|
|
|
common_whl = (self.lst == Lists.whl)
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
bedrock = (atserv.is_bedrock)
|
2022-07-01 14:28:39 +04:00
|
|
|
|
2022-07-01 09:36:52 +04:00
|
|
|
if common_whl and bedrock:
|
|
|
|
self.lst = Lists.whl_be
|
|
|
|
|
|
|
|
self.players: List[str] = []
|
2022-06-23 15:13:56 +04:00
|
|
|
self.parsed = False
|
|
|
|
|
|
|
|
def list_players(self, cache: bool = True) -> List[str]:
|
|
|
|
"""Parse a players list
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Args:
|
|
|
|
cache (bool, optional): If the function should
|
|
|
|
return cached list (highly recommended)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
List of players' nicknames
|
2022-06-23 15:13:56 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
if cache and self.parsed:
|
|
|
|
return self.players
|
|
|
|
|
|
|
|
listreq = self.atserv.atserver_request(
|
|
|
|
f'https://aternos.org/players/{self.lst.value}',
|
|
|
|
'GET'
|
|
|
|
)
|
|
|
|
listtree = lxml.html.fromstring(listreq.content)
|
|
|
|
items = listtree.xpath(
|
|
|
|
'//div[@class="list-item"]'
|
|
|
|
)
|
|
|
|
|
|
|
|
result = []
|
|
|
|
for i in items:
|
|
|
|
name = i.xpath('./div[@class="list-name"]')
|
|
|
|
result.append(name[0].text.strip())
|
|
|
|
|
|
|
|
self.players = result
|
|
|
|
self.parsed = True
|
|
|
|
return result
|
|
|
|
|
|
|
|
def add(self, name: str) -> None:
|
|
|
|
"""Appends a player to the list by the nickname
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Args:
|
|
|
|
name (str): Player's nickname
|
2022-06-23 15:13:56 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
self.atserv.atserver_request(
|
|
|
|
'https://aternos.org/panel/ajax/players/add.php',
|
|
|
|
'POST', data={
|
|
|
|
'list': self.lst.value,
|
|
|
|
'name': name
|
|
|
|
}, sendtoken=True
|
|
|
|
)
|
|
|
|
|
|
|
|
self.players.append(name)
|
|
|
|
|
|
|
|
def remove(self, name: str) -> None:
|
|
|
|
"""Removes a player from the list by the nickname
|
|
|
|
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
Args:
|
|
|
|
name (str): Player's nickname
|
2022-06-23 15:13:56 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
self.atserv.atserver_request(
|
|
|
|
'https://aternos.org/panel/ajax/players/remove.php',
|
|
|
|
'POST', data={
|
|
|
|
'list': self.lst.value,
|
|
|
|
'name': name
|
|
|
|
}, sendtoken=True
|
|
|
|
)
|
|
|
|
|
|
|
|
for i, j in enumerate(self.players):
|
|
|
|
if j == name:
|
|
|
|
del self.players[i]
|