From b6449a7056d0fb0941b6af2faf44eedd0657f34b Mon Sep 17 00:00:00 2001 From: MetalStormGhost Date: Mon, 9 Oct 2023 10:51:13 +0300 Subject: [PATCH] In the event of too many channel users, fail gracefully by reusing a random channel instead of always the previous one. --- game/radio/radios.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/game/radio/radios.py b/game/radio/radios.py index cf02f040..85d67d0f 100644 --- a/game/radio/radios.py +++ b/game/radio/radios.py @@ -405,15 +405,19 @@ class RadioRegistry: already allocated. """ try: + while_count = 0 while (channel := random_frequency(radio)) in self.allocated_channels: + while_count += 1 + if while_count > 1000: + raise StopIteration pass self.reserve(channel) return channel except StopIteration: # In the event of too many channel users, fail gracefully by reusing - # the last channel. + # a channel. # https://github.com/dcs-liberation/dcs_liberation/issues/598 - channel = radio.last_channel + channel = random_frequency(radio) logging.warning( f"No more free channels for {radio.name}. Reusing {channel}." )