Skip to content

Commit

Permalink
Port options to use duration
Browse files Browse the repository at this point in the history
  • Loading branch information
godwhoa committed Jan 19, 2019
1 parent 9155805 commit 88aa261
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 50 deletions.
4 changes: 2 additions & 2 deletions doc/config-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ a block when :ref:`friendly_fire_on_grief` is enabled.
teamswitch_interval
+++++++++++++++++++

Forces players to wait a number of minutes before being able to switch back
Forces players to wait a set duration before being able to switch back
again after they switched teams.

0 disables the cooldown.
"0sec" disables the cooldown.

teamswitch_allowed
++++++++++++++++++
Expand Down
4 changes: 4 additions & 0 deletions piqueserver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ def set(self, value):


def cast_duration(d) -> int:
"""
casts duration(1min, 1hr) into seconds.
If input is an int it returns that unmodified.
"""
if isinstance(d, int):
return d
if not isinstance(d, str):
Expand Down
41 changes: 20 additions & 21 deletions piqueserver/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ tips = [
"Type /help for info & commands"
]

# how often in minutes the tips should display
tips_frequency = 5
# how often the tips should display
tips_frequency = "5min"

# SERVER
# set this if the server should register on the master server list
Expand Down Expand Up @@ -108,15 +108,15 @@ random_rotation = false
# Examples: "piqueserver.game_modes.push", "mygame" (where you have config/game_modes/mygame.py)
game_mode = "ctf"

# TODO: document
# default time limit to set per map. When the time limit runs out, the map rotation is advanced
default_time_limit = "2hours"
# TODO: document
# advances the map rotation when the game ends, if set to true
advance_on_win = true

# time in seconds before player respawns
# time before player respawns
# TODO: document how spawn time is calculated (it's not always the time given)
# (default: 8)
respawn_time = 16
# (default: 8 seconds)
respawn_time = "16sec"

# if respawns should line up with each other (multiple players will respawn at
# the same time instead of exactly the time from when they died
Expand All @@ -129,9 +129,9 @@ friendly_fire = false
# griefers
friendly_fire_on_grief = true

# number of seconds a player is vulnerable to friendly fire if
# duration a player is vulnerable to friendly fire if
# friendly_fire_on_grief enabled
grief_friendly_fire_time = 5
grief_friendly_fire_time = "5sec"

# If friendly fire should be enabled for the spade too. This is disabled by default,
# because it frequently causes accidental teamkills
Expand All @@ -142,9 +142,9 @@ spade_teamkills_on_grief = false
# The value is thus the maximum player number difference allowed between teams
balanced_teams = 2

# time in minutes players must wait before switching teams again
# 0 disables cooldown time
teamswitch_interval = 0
# time players must wait before switching teams again
# 0sec disables cooldown time
teamswitch_interval = "0sec"
# whether players are allowed to switch teams at all
teamswitch_allowed = true

Expand All @@ -163,7 +163,7 @@ fall_damage = true
# disable users ability to affect the map's initial blocks
user_blocks_only = false

# TODO
# puts the player into god build mode automatically when entering god mode, if set to true
set_god_build = false

# time in seconds remaining when the time remaining should be announced
Expand Down Expand Up @@ -196,15 +196,15 @@ color = [ 0, 255, 0]
# logging in as admin or trusted also disables being votekicked (if that script is enabled)
# For security reasons, logins are disabled by default.
#
#admin = ["adminpass1", "adminpass2"]
admin = ["adminpass1", "adminpass2"]
#moderator = ["modpass"]
#guard = ["guardpass"]
#trusted = ["trustedpass"]


[bans]
# default duration in minutes a banned player will be banned for
default_duration = 1440
# default duration a banned player will be banned for
default_duration = "1day"

# location the bans are saved and loaded from
#file = "bans.txt"
Expand Down Expand Up @@ -252,7 +252,7 @@ debug_log = false
# directories are created as necessary
logfile = "./logs/log.txt"

# TODO: document
# writes a new log file each day
rotate_daily = true

profile = false
Expand Down Expand Up @@ -310,7 +310,7 @@ chatprefix = "."

# piqueserver.scripts.squad
[squad]
respawn_time = 32
respawn_time = "32sec"
size = 4
auto_squad = false

Expand Down Expand Up @@ -341,7 +341,7 @@ time_limit = "30min"
# successfully votekick a player
percentage = 35

# duration in minutes that votekicked player will be banned for
# duration that votekicked player will be banned for
ban_duration = "30min"

public_votes = true
Expand All @@ -355,10 +355,9 @@ public_votes = true
public_votes = true

# extend current map (meaning?)
extension_time = 15
extension_time = "15min"

# players can initiate voting for a new map with /votemap
player_driven = false
autoschedule = false
time = 120
percentage = 80
12 changes: 8 additions & 4 deletions piqueserver/core_commands/game.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import math
import re
from twisted.internet import reactor
from piqueserver.config import cast_duration
from pyspades.common import prettify_timespan
from piqueserver.commands import command, CommandError, get_player, get_team, get_truthy


Expand Down Expand Up @@ -215,15 +217,17 @@ def global_chat(connection, value=None):


@command('timelimit', admin_only=True)
def set_time_limit(connection, value):
def set_time_limit(connection, duration):
"""
Set this game time limit
/timelimit <duration>
"""
value = float(value)
limit = cast_duration(duration)
span = prettify_timespan(limit)
protocol = connection.protocol
protocol.set_time_limit(value)
protocol.send_chat('Time limit set to %s' % value, irc=True)
# takes time in minutes
protocol.set_time_limit(limit/60)
protocol.send_chat('Time limit set to {}'.format(span), irc=True)


@command(admin_only=True)
Expand Down
1 change: 0 additions & 1 deletion piqueserver/core_commands/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def kick(connection, value, *arg):
def ban(connection, value, *arg):
"""
Ban a given player forever or for a limited amount of time.
It takes duration in minutes.
/ban <player> [duration] [reason]
"""
duration, reason = get_ban_arguments(connection, arg)
Expand Down
2 changes: 1 addition & 1 deletion piqueserver/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def on_team_join(self, team: 'FeatureTeam') -> HookValue:
self.send_chat('Switching teams is not allowed')
return False
if (self.last_switch is not None and
reactor.seconds() - self.last_switch < teamswitch_interval * 60):
reactor.seconds() - self.last_switch < teamswitch_interval):
self.send_chat(
'You must wait before switching teams again')
return False
Expand Down
2 changes: 1 addition & 1 deletion piqueserver/scripts/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
S_AFK_KICK_REASON = 'Inactive for {time}'

afk_config = config.section('afk')
time_limit_option = afk_config.option('time_limit', default="5min", cast=cast_duration)
time_limit_option = afk_config.option('time_limit', default="1hour", cast=cast_duration)

def afk(connection, player):
player = get_player(connection.protocol, player)
Expand Down
6 changes: 3 additions & 3 deletions piqueserver/scripts/spawn_protect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
.. code-block:: guess
[spawn_protect]
protection_time = 3 # in seconds
protection_time = "3sec"
.. codeauthor:: ? & kmsi <kmsiapps@gmail.com>
"""

from pyspades.common import prettify_timespan
from piqueserver.config import config
from piqueserver.config import config, cast_duration
from twisted.internet import reactor

spawn_protect_config = config.section("spawn_protect")
protection_time = spawn_protect_config.option("protection_time", 3.0)
protection_time = spawn_protect_config.option("protection_time", default="3sec", cast=cast_duration)


def apply_script(protocol, connection, config):
Expand Down
6 changes: 3 additions & 3 deletions piqueserver/scripts/spectatorcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
[spectator_control]
no_chat = false # determines whether spectators can chat or not in your server
kick = false # determines whether spectators will be kicked after remaining for so long
kick_time = 300 # how long a spectator may remain before they are kicked; time in seconds
kick_time = "5min" # how long a spectator may remain before they are kicked
.. codeauthor:: Tocksman (made for Goon Haven)
"""

from math import ceil, floor
from twisted.internet import reactor
from piqueserver.config import config
from piqueserver.config import config, cast_duration

spectator_ctrl_config = config.section("spectator_control")
no_chat = spectator_ctrl_config.option("no_chat", False)
kick = spectator_ctrl_config.option("kick", False)
kick_time = spectator_ctrl_config.option("kick_time", 300) # in seconds
kick_time = spectator_ctrl_config.option("kick_time", default="5min", cast=cast_duration)

def apply_script(protocol, connection, config):
class SpectatorControlConnection(connection):
Expand Down
6 changes: 3 additions & 3 deletions piqueserver/scripts/squad.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.. code-block:: guess
[squad]
respawn_time = 10 # in seconds
respawn_time = "10sec"
auto_squad = true
.. codeauthor:: Triplefox
Expand All @@ -22,7 +22,7 @@
import random
from piqueserver.commands import command, get_player
from piqueserver import commands
from piqueserver.config import config
from piqueserver.config import config, cast_duration
from piqueserver.server import respawn_time_option

SQUAD_NAMES = set([
Expand All @@ -33,7 +33,7 @@

squad_config = config.section('squad')
RESPAWN_TIME_OPTION = squad_config.option('respawn_time',
default=respawn_time_option.get())
default=respawn_time_option.get(), cast=cast_duration)
SIZE_OPTION = squad_config.option('size', 0)
AUTO_SQUAD_OPTION = squad_config.option('auto_squad', True)

Expand Down
13 changes: 7 additions & 6 deletions piqueserver/scripts/votemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
[votemap]
public_votes = true
extension_time = 15
extension_time = "15min"
player_driven = false
autoschedule = false
time = 120
percentage = 80
.. codeauthor:: James Hofmann a.k.a triplefox (GPL LICENSE)
Expand All @@ -28,14 +27,16 @@
from piqueserver.map import check_rotation
from piqueserver.scheduler import Scheduler
from piqueserver.commands import command
from piqueserver.config import config
from piqueserver.config import config, cast_duration

votemap_config = config.section('votemap')

VOTEMAP_AUTOSCHEDULE_OPTION = votemap_config.option('autoschedule', 180)
VOTEMAP_PUBLIC_VOTES_OPTION = votemap_config.option( 'public_votes', True)
VOTEMAP_TIME_OPTION = votemap_config.option('time', 120)
VOTEMAP_EXTENSION_TIME_OPTION = votemap_config.option('extension_time', 15)
VOTEMAP_PUBLIC_VOTES_OPTION = votemap_config.option('public_votes', True)
# godwhoa: This option gets loaded into votemap_time but that doesn't get used anywhere.
VOTEMAP_TIME_OPTION = votemap_config.option('time', default="2min", cast=cast_duration)
VOTEMAP_EXTENSION_TIME_OPTION = votemap_config.option('extension_time', default="15min",
cast=lambda x: cast_duration(x)/60)
VOTEMAP_PLAYER_DRIVEN_OPTION = votemap_config.option('player_driven', False)
VOTEMAP_PERCENTAGE_OPTION = votemap_config.option('percentage', 80)

Expand Down
8 changes: 4 additions & 4 deletions piqueserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def sleep(secs):

bans_file = bans_config.option('file', default='bans.txt')
bans_urls = bans_config.option('urls', [])
respawn_time_option = config.option('respawn_time', default=8)
respawn_time_option = config.option('respawn_time', default="8sec", cast=cast_duration)
respawn_waves = config.option('respawn_waves', default=False)
game_mode = config.option('game_mode', default='ctf')
random_rotation = config.option('random_rotation', default=False)
Expand All @@ -132,7 +132,7 @@ def sleep(secs):
friendly_fire_on_grief = config.option('friendly_fire_on_grief',
default=True)
grief_friendly_fire_time = config.option('grief_friendly_fire_time',
default=2)
default='2sec', cast=cast_duration)
spade_teamkills_on_grief = config.option('spade_teamkills_on_grief',
default=False)
time_announcements = config.option('time_announcements', default=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
Expand All @@ -142,7 +142,7 @@ def sleep(secs):
port_option = config.option('port', default=32887,
validate=lambda n: type(n) == int)
fall_damage = config.option('fall_damage', default=True)
teamswitch_interval = config.option('teamswitch_interval', default=0)
teamswitch_interval = config.option('teamswitch_interval', default="0sec", cast=cast_duration)
teamswitch_allowed = config.option('teamswitch_allowed', default=True)
max_players = config.option('max_players', default=20)
melee_damage = config.option('melee_damage', default=100)
Expand All @@ -163,7 +163,7 @@ def sleep(secs):
ban_publish = bans_config.option('publish', False)
ban_publish_port = bans_config.option('publish_port', 32885)
logging_rotate_daily = logging_config.option('rotate_daily', False)
tip_frequency = config.option('tips_frequency', 0)
tip_frequency = config.option('tips_frequency', default="5sec", cast=lambda x: cast_duration(x)/60)
register_master_option = config.option('master', False)

# default to http for ip_getter on windows
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def run(self):
'%s.web' % PKG_NAME: 'piqueserver/web',
'%s.scripts' % PKG_NAME: 'piqueserver/scripts',
'%s.game_modes' % PKG_NAME: 'piqueserver/game_modes',
'pyspades': 'pyspades'
'pyspades': 'pyspades',
}, # some kind of find_packages?
package_data={"%s.web" % PKG_NAME: ["templates/status.html"]},
include_package_data=True,
Expand Down

0 comments on commit 88aa261

Please sign in to comment.