Skip to content

Commit

Permalink
Merge pull request #594 from Jipok/load_map
Browse files Browse the repository at this point in the history
always_save_map for savemap.py
  • Loading branch information
NotAFile committed May 19, 2021
2 parents 2871a3a + dc98ab8 commit c357d04
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
8 changes: 5 additions & 3 deletions piqueserver/config/config.toml
Expand Up @@ -321,10 +321,12 @@ auto_squad = false
# piqueserver.scripts.savemap
# allows automatically saving a snapshot of the map on server close
[savemap]

# automatically load the saved map on map load
load_saved_map = false

load_saved_map = true
# automatically save map at shutdown
save_at_shutdown = false
# automatically save map at map rotation or server shutdown
always_save_map = false

# piqueserver.scripts.rollback
[rollback]
Expand Down
14 changes: 14 additions & 0 deletions piqueserver/core_commands/map.py
Expand Up @@ -108,3 +108,17 @@ def advance(connection):
/advancemap
"""
connection.protocol.advance_rotation('Map advance forced.')

@command('loadmap', admin_only=True)
def load_map(connection, map):
"""
Instantly switches map to the specified
/loadmap <mapname>
"""
protocol = connection.protocol

try:
protocol.planned_map = check_rotation([map])[0]
protocol.advance_rotation()
except MapNotFound:
return 'Map %s not found' % (map)
16 changes: 11 additions & 5 deletions piqueserver/scripts/savemap.py
Expand Up @@ -4,17 +4,18 @@
be saved with the '.saved' suffix.
With /rmsaved you can delete a '.saved' version of this map.
Also adds two options: for automatically saving map at shutdown and
loading saved map instead of the original.
Options
^^^^^^^
.. code-block:: toml
[savemap]
load_saved_map = false
# automatically load the saved map on map load
load_saved_map = true
# automatically save map at shutdown
save_at_shutdown = false
# automatically save map at map rotation or server shutdown
always_save_map = false
"""

import os
Expand Down Expand Up @@ -57,11 +58,16 @@ class SaveMapProtocol(protocol):
def __init__(self, *arg, **kw):
protocol.__init__(self, *arg, **kw)
def call():
if savemap_config.option('save_at_shutdown', False).get():
at_shutdown = savemap_config.option('save_at_shutdown', False).get()
always = savemap_config.option('always_save_map', False).get()
if at_shutdown or always:
self.save_map()
reactor.addSystemEventTrigger('before', 'shutdown', call)

async def set_map_name(self, rot_info: RotationInfo) -> None:
if savemap_config.option('always_save_map', False).get():
if self.map is not None:
self.save_map()
if savemap_config.option('load_saved_map', False).get():
if os.path.isfile(get_path(rot_info.name)):
log.info("Saved version of '%s' found" % rot_info.name)
Expand Down

0 comments on commit c357d04

Please sign in to comment.