Base web UI port number off bot name

This commit is contained in:
Tanner committed 2026-11-09 04:24:39 +00:00
1 parent b2bf939c74
commit 243e34e26f
2 files changed
+17 -1

No files matched your search

+7 -1
View File
@@ -1,5 +1,6 @@
import importlib
import json
import os
import queue
import re
import urllib.error
@@ -522,9 +523,14 @@ def main():
observer.join()
worker.join(timeout=2.0)
def web_port_for_player(name):
suffix = str(name or '')[-1:]
return 3300 + int(suffix) if suffix in tuple('123456789') else 3300
def run_api():
host = '0.0.0.0'
port = 3300
port = web_port_for_player(os.environ.get('PLAYER_NAME', 'mosfet1'))
while True:
print('Trying to run web interface on port:', port)
+10
View File
@@ -30,6 +30,16 @@ class FakeGame:
class TestWebInventoryAPI(unittest.TestCase):
def test_web_port_uses_bot_name_suffix(self):
for suffix in range(1, 10):
with self.subTest(suffix=suffix):
self.assertEqual(
mosfet_web.web_port_for_player('mosfet{}'.format(suffix)),
3300 + suffix)
for name in ('mosfet0', 'mosfet', 'bot10', None, ''):
with self.subTest(name=name):
self.assertEqual(mosfet_web.web_port_for_player(name), 3300)
def setUp(self):
self.g = mosfet_web.g
self.original = {