diff --git a/docs/commands.md b/docs/commands.md index 7930ea5e..514f008f 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -522,15 +522,16 @@ - `start` starts the previously set timer, so `/timer 0 start`. - `pause` OR `stop` pauses the timer that's currently running, so `/timer 0 pause`. - `unset` OR `hide` hides the timer for it to no longer show up, so `/timer 0 hide`. -* **format_timer** ` ` +* **timer\_format** ` ` - Format the timer in the current area or hub. - - Example of format: `Time Left: hh:mm` - - Default format: `hh:mm:ss.zzz` + - Example of format: `'Time Left:' hh:mm`, where 'Time Left:' is surrounded by single quotes so it's not affected by the formatting, hh stands for hours and mm stands for minutes. + - Default format: `hh:mm:ss.zzz` where hh stands for hours, mm stands for minutes, ss stands for seconds, and zzz stands for milliseconds. - For more information on how to implement your format, [go here!](https://doc.qt.io/qt-6/qtime.html#toString) -* **timer_interval** ` ` - - Set timer interval in the current area or hub. - - Example: `/timer_interval 1 15m` - - Default interval: `/timer_interval 1 16ms` +* **timer\_interval** ` ` + - Set the timer's interval, which is how often it fires in milliseconds. + - If timer interval is not written, it will reset the interval to the default value, which is 16. + - Example: `/timer_interval 1 16` + - Default interval: `/timer_interval 1 16` ## Musiclists * **musiclist\_add** `` `` `` `[Length]` `[Path]` - Allow you to add a song in a loaded musiclist! diff --git a/server/area.py b/server/area.py index 1a5c350b..dce8026d 100644 --- a/server/area.py +++ b/server/area.py @@ -742,7 +742,7 @@ def update_timers(self, client, running_only=False): if timer.started: current_time = timer.target - arrow.get() int_time = int(current_time.total_seconds()) * 1000 - client.send_timer_set_time(0, int_time, timer.started) + client.send_timer_set_time(0, int_time, timer.started, timer.format, timer.interval) elif not running_only: client.send_timer_set_time(0, None, False) @@ -754,7 +754,7 @@ def update_timers(self, client, running_only=False): if timer.started: current_time = timer.target - arrow.get() int_time = int(current_time.total_seconds()) * 1000 - client.send_timer_set_time(timer_id + 1, int_time, timer.started) + client.send_timer_set_time(timer_id + 1, int_time, timer.started, timer.format, timer.interval) elif not running_only: client.send_timer_set_time(timer_id + 1, None, False) @@ -927,10 +927,10 @@ def send_owner_ic(self, bg, cmd, *args): if c.area.background != bg: c.send_command("BN", c.area.background) - def send_timer_set_time(self, timer_id=None, new_time=None, start=False): + def send_timer_set_time(self, timer_id=None, new_time=None, start=False, format=None, interval=None): """Broadcast a timer to all clients in this area.""" for c in self.clients: - c.send_timer_set_time(timer_id, new_time, start) + c.send_timer_set_time(timer_id, new_time, start, format, interval) def broadcast_ooc(self, msg): """ diff --git a/server/area_manager.py b/server/area_manager.py index d12da701..93edd734 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -601,10 +601,10 @@ def send_remote_command(self, area_list, cmd, *args): a.send_command(cmd, *args) a.send_owner_command(cmd, *args) - def send_timer_set_time(self, timer_id=None, new_time=None, start=False): + def send_timer_set_time(self, timer_id=None, new_time=None, start=False, format=None, interval=None): """Broadcast a timer to all areas in this hub.""" for area in self.areas: - area.send_timer_set_time(timer_id, new_time, start) + area.send_timer_set_time(timer_id, new_time, start, format, interval) def broadcast_area_list(self, refresh=False): """Global update of all areas for the client music lists in the hub.""" diff --git a/server/client_manager.py b/server/client_manager.py index 240d31ae..9f27490b 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -344,11 +344,11 @@ def send_player_count(self): limit = self.server.config["playerlimit"] self.send_ooc(f"👥{players}/{limit} players online.") - def send_timer_set_time(self, timer_id=None, new_time=None, start=False): + def send_timer_set_time(self, timer_id=None, new_time=None, start=False, format=None, interval=None): if self.software == "DRO": # configuration. There's no situation where these values are different on KFO-Server - self.send_timer_set_step_length(timer_id, -16) # 16 milliseconds, matches AO - self.send_timer_set_firing_interval(timer_id, 16) # 16 milliseconds, matches AO + self.send_timer_set_step_length(timer_id, -timer.interval) # 16 milliseconds, matches AO + self.send_timer_set_firing_interval(timer_id, timer.interval) # 16 milliseconds, matches AO self.send_command("TST", timer_id, new_time) # set time if start: @@ -366,19 +366,10 @@ def send_timer_set_time(self, timer_id=None, new_time=None, start=False): timer = self.area.area_manager.timer else: timer = self.area.timers[timer_id-1] - self.send_command("TF", timer_id, timer.format, new_time) - self.send_command("TIN", timer_id, timer.interval) - - def send_timer_set_interval(self, timer_id, timer): - if timer.started: - current_time = timer.target - arrow.get() - current_time = int(current_time.total_seconds()) * 1000 - else: - current_time = int(timer.static.total_seconds()) * 1000 - if timer_id == 0: - self.area.area_manager.send_timer_set_time(timer_id, current_time, timer.started) - else: - self.area.send_timer_set_time(timer_id, current_time, timer.started) + if format: + self.send_command("TF", timer_id, format, new_time) + if interval: + self.send_command("TIN", timer_id, interval) def send_timer_set_step_length(self, timer_id=None, new_step_length=None): if self.software == "DRO": @@ -390,7 +381,7 @@ def send_timer_set_firing_interval(self, timer_id=None, new_firing_interval=None if self.software == "DRO": self.send_command("TSF", timer_id, new_firing_interval) #set firing else: - pass # no ao equivalent + self.send_command("TIN", timer_id, new_firing_interval) def is_valid_name(self, name): """ diff --git a/server/commands/roleplay.py b/server/commands/roleplay.py index d2a37ee7..68c71398 100644 --- a/server/commands/roleplay.py +++ b/server/commands/roleplay.py @@ -35,7 +35,7 @@ "ooc_cmd_timer", "ooc_cmd_demo", "ooc_cmd_trigger", - "ooc_cmd_format_timer", + "ooc_cmd_timer_format", "ooc_cmd_timer_interval", ] @@ -825,9 +825,9 @@ def ooc_cmd_timer(client, arg): s = int(not timer.started) static_time = int(timer.static.total_seconds()) * 1000 if timer_id == 0: - client.area.area_manager.send_timer_set_time(timer_id, static_time, timer.started) + client.area.area_manager.send_timer_set_time(timer_id, static_time, timer.started, timer.format, timer.interval) else: - client.area.send_timer_set_time(timer_id, static_time, timer.started) + client.area.send_timer_set_time(timer_id, static_time, timer.started, timer.format, timer.interval) client.send_ooc(f"Timer {timer_id} is at {timer.static}") if timer_id == 0: @@ -954,12 +954,12 @@ def ooc_cmd_trigger(client, arg): client.send_ooc(f'Changed to Call "{val}" on trigger "{trig}"') -def ooc_cmd_format_timer(client, arg): +def ooc_cmd_timer_format(client, arg): """ Format the timer - Usage: /format_timer + Usage: /timer_format """ - args = shlex.split(arg) + args = arg.split() try: args[0] = int(args[0]) except: @@ -980,25 +980,20 @@ def ooc_cmd_format_timer(client, arg): else: client.send_ooc("You cannot change timer format if you are at least CM") return - timer.format = args[1:] - if timer.set: - if timer.started: - current_time = timer.target - arrow.get() - current_time = int(current_time.total_seconds()) * 1000 - else: - current_time = int(timer.static.total_seconds()) * 1000 - if args[0] == 0: - client.area.area_manager.send_timer_set_time(args[0], current_time, timer.started) - else: - client.area.send_timer_set_time(args[0], current_time, timer.started) + if len(args) <= 1: + args.append("hh:mm:ss.zzz") + timer.format = ' '.join(args[1:]) + area = client.area + for c in area.clients: + area.update_timers(c) client.send_ooc(f"Timer {args[0]} format: '{args[1]}'") def ooc_cmd_timer_interval(client, arg): """ - Set timer interval - If timer interval is not written than will show default timer interval (16ms) - Example: /timer_interval 1 15m + Set the timer's interval, which is how often it fires in milliseconds. + If timer interval is not written, it will reset the interval to the default value, which is 16 . + Example: /timer_interval 1 16 Usage: /timer_interval """ args = shlex.split(arg) @@ -1026,9 +1021,9 @@ def ooc_cmd_timer_interval(client, arg): if len(args) == 1: timer.interval = 16 else: - timer.interval = pytimeparse.parse(args[1]) * 1000 + timer.interval = int(args[1]) except: raise ArgumentError("Interval value not valid!") if timer.set: - client.send_timer_set_interval(args[0], timer) - client.send_ooc(f"Timer {args[0]} interval is set to '{args[1]}'") + client.send_timer_set_firing_interval(args[0], timer) + client.send_ooc(f"Timer {args[0]} interval is set to '{timer.interval}'")