Skip to content

Commit

Permalink
Added admins commands for maximum players/spectators. (#1260)
Browse files Browse the repository at this point in the history
* Added admins commands for maximum players/spectators.

* Added configuration option to disable changing setting max players/spectators.

* Added configuration documentation for ALLOW_SLOTS_CHANGE setting.
  • Loading branch information
TheMaximum committed Aug 29, 2023
1 parent 90d08dd commit 2f64782
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
25 changes: 25 additions & 0 deletions docs/source/intro/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,31 @@ You don't want this to be enabled on shared servers (hosting environments) as it
**We advice to use the manual PIP method of upgrading over the in-game upgrading process!**


Allow slots change (base)
~~~~~~~~~~~~~~~~~~~~~~~~~

In 0.10.6, the commands ``//setmaxplayers`` and ``//setmaxspectators`` are added, giving admins the possibility to change the maximum amount of players and spectators on the server.
To allow hosters to disable the action for their customers, ``ALLOW_SLOTS_CHANGE`` can be changed to ``False``.


.. code-block:: python
:caption: base.py
ALLOW_SLOTS_CHANGE = True
.. code-block:: yaml
:caption: base.yaml
ALLOW_SLOTS_CHANGE: true
.. code-block:: json
:caption: base.json
{
"ALLOW_SLOTS_CHANGE": true
}
Songs (base)
~~~~~~~~~~~~

Expand Down
34 changes: 31 additions & 3 deletions pyplanet/apps/contrib/admin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import asyncio

from pyplanet.apps.core.maniaplanet.callbacks.player import player_chat
from pyplanet.conf import settings
from pyplanet.contrib.command import Command
from xmlrpc.client import Fault

Expand All @@ -25,6 +26,7 @@ async def on_start(self):
await self.instance.permission_manager.register('callvoting', 'Handle server callvoting', app=self.app, min_level=1)
await self.instance.permission_manager.register('password', 'Set the server passwords', app=self.app, min_level=2)
await self.instance.permission_manager.register('servername', 'Set the server name', app=self.app, min_level=2)
await self.instance.permission_manager.register('maxplayers', 'Set the maximum players/spectators', app=self.app, min_level=2)
await self.instance.permission_manager.register('mode', 'Set the server game mode', app=self.app, min_level=2)
await self.instance.permission_manager.register('chat_toggle', 'Turn the public chat on or off', app=self.app, min_level=2)

Expand All @@ -37,6 +39,10 @@ async def on_start(self):
admin=True, description='Sets the spectator password of the server.').add_param(name='password', required=False),
Command(command='servername', target=self.set_servername, perms='admin:servername', admin=True,
description='Changes the name of the server.').add_param(name='server_name', required=True, nargs='*'),
Command(command='setmaxplayers', target=self.set_max_players, perms='admin:maxplayers', admin=True,
description='Sets the maximum amount of players on the server.').add_param(name='amount', type=int, required=True),
Command(command='setmaxspectators', target=self.set_max_spectators, perms='admin:maxplayers', admin=True,
description='Sets the maximum amount of spectators on the server.').add_param(name='amount', type=int, required=True),
Command(command='mode', target=self.set_mode, perms='admin:mode', admin=True,
description='Changes the gamemode of the server.').add_param(name='mode', required=True, nargs='*'),
Command(command='modesettings', target=self.mode_settings, perms='admin:mode', admin=True,
Expand Down Expand Up @@ -85,7 +91,7 @@ async def set_mode(self, player, data, **kwargs):
mode = (' '.join(data.mode))
lower_mode = mode.lower()
if self.instance.game.game == 'tm':

if lower_mode == 'ta' or lower_mode == 'timeattack':
mode = 'TimeAttack.Script.txt'
elif lower_mode == 'laps':
Expand All @@ -98,9 +104,9 @@ async def set_mode(self, player, data, **kwargs):
mode = 'Chase.Script.txt'
elif lower_mode == 'team':
mode = 'Team.Script.txt'

if self.instance.game.game == 'tmnext':

if lower_mode == 'ta' or lower_mode == 'timeattack':
mode = 'Trackmania/TM_TimeAttack_Online.Script.txt'
elif lower_mode == 'laps':
Expand Down Expand Up @@ -218,3 +224,25 @@ async def set_password(self, player, data, **kwargs):
await self.app.context.signals.get_signal('maniaplanet:server_password').send(
dict(password=data.password, kind='player'), True
)

async def set_max_players(self, player, data, **kwargs):
if not settings.ALLOW_SLOTS_CHANGE:
return await self.instance.chat('$f00Changing maximum players is disabled by the hoster!', player)

amount = getattr(data, 'amount', None)
message = '$ff0You changed the maximum players to: $fff{}$ff0 $i(takes effect on next map)$i.'.format(amount)
await self.instance.gbx.multicall(
self.instance.gbx('SetMaxPlayers', amount),
self.instance.chat(message, player)
)

async def set_max_spectators(self, player, data, **kwargs):
if not settings.ALLOW_SLOTS_CHANGE:
return await self.instance.chat('$f00Changing maximum players is disabled by the hoster!', player)

amount = getattr(data, 'amount', None)
message = '$ff0You changed the maximum spectators to: $fff{}$ff0 $i(takes effect on next map)$i.'.format(amount)
await self.instance.gbx.multicall(
self.instance.gbx('SetMaxSpectators', amount),
self.instance.chat(message, player)
)
13 changes: 8 additions & 5 deletions pyplanet/apps/core/maniaplanet/callbacks/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@


async def handle_map_begin(source, signal, **kwargs):
# Refresh the server info in the GBX client.
await Controller.instance.gbx.refresh_info()

# Retrieve and update map, return it to our callback listeners.
map = await Controller.instance.map_manager.handle_map_change(source)
return dict(map=map)
Expand Down Expand Up @@ -36,7 +39,7 @@ async def handle_map_start(source, signal, **kwargs):
target=handle_map_begin,
)
"""
:Signal:
:Signal:
Begin of map.
:Code:
``maniaplanet:map_begin``
Expand All @@ -56,7 +59,7 @@ async def handle_map_start(source, signal, **kwargs):
target=handle_map_end,
)
"""
:Signal:
:Signal:
End of map.
:Code:
``maniaplanet:map_end``
Expand All @@ -76,7 +79,7 @@ async def handle_map_start(source, signal, **kwargs):
target=handle_playlist_modified
)
"""
:Signal:
:Signal:
Maplist changes.
:Code:
``maniaplanet:playlist_modified``
Expand All @@ -100,7 +103,7 @@ async def handle_map_start(source, signal, **kwargs):
target=handle_map_start
)
"""
:Signal:
:Signal:
Begin of map. (Scripted!)
:Code:
``maniaplanet:map_begin``
Expand All @@ -123,7 +126,7 @@ async def handle_map_start(source, signal, **kwargs):
target=handle_map_start
)
"""
:Signal:
:Signal:
Begin of map, end of event. (Scripted!)
:Code:
``maniaplanet:map_start__end``
Expand Down
3 changes: 3 additions & 0 deletions pyplanet/conf/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
# Allow self-upgrading the installation. Disable on shared servers with one installation!
SELF_UPGRADE = True

# Allow changing the server slots (max players/spectators).
ALLOW_SLOTS_CHANGE = True

##########################################
################## DB ####################
##########################################
Expand Down
3 changes: 3 additions & 0 deletions pyplanet/conf/project_template/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
# Allow self-upgrading the installation. Disable on shared servers with one installation (hosting environment)!
SELF_UPGRADE = True

# Allow changing the server slots (max players/spectators).
ALLOW_SLOTS_CHANGE = True

# Databases configuration holds an dictionary with information of the database backend.
# Please refer to the documentation for all examples. http://pypla.net/
DATABASES = {
Expand Down

0 comments on commit 2f64782

Please sign in to comment.