From 14ea1e3d97f43ab1efb2fa3b245e7768f5bc5027 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 2 Nov 2025 21:14:21 -0800 Subject: [PATCH] enhance game.ini to custom values and doc --- modules/games/README.md | 14 ++++++++++++++ modules/games/tictactoe_vid.py | 1 + script/game.ini | 14 ++++++++++++++ script/game_serve.py | 25 +++++++++++++++++++++---- 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 script/game.ini diff --git a/modules/games/README.md b/modules/games/README.md index c3e4294..45f1eeb 100644 --- a/modules/games/README.md +++ b/modules/games/README.md @@ -13,6 +13,7 @@ - [Quiz](#quiz-game-module) - [Survey](#survey--module-game) - [Word of the Day Game](#word-of-the-day-game--rules--features) +- [Game Server Configuration (`game.ini`)](#game-server-configuration-gameini) - [PyGame Help](#pygame-help) --- @@ -739,6 +740,19 @@ This module implements a survey system for the Meshtastic mesh-bot. ___ +# Game Server Configuration (`game.ini`) + +The game server (`script/game_serve.py`) supports configuration via a `game.ini` file placed in the same directory as the script. This allows you to customize network and node settings without modifying the Python code. + +## How to Use + +1. **Create a `game.ini` file** in the `script/` directory (next to `game_serve.py`). + +If `game.ini` is not present, the server will use built-in default values. + +--- + + # PyGame Help 'pygame - Community Edition' ('pygame-ce' for short) is a fork of the original 'pygame' library by former 'pygame' core contributors. diff --git a/modules/games/tictactoe_vid.py b/modules/games/tictactoe_vid.py index cd13c86..6e8a6ca 100644 --- a/modules/games/tictactoe_vid.py +++ b/modules/games/tictactoe_vid.py @@ -180,6 +180,7 @@ def ttt_main(): screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) pygame.display.set_caption("Tic-Tac-Toe 3D Display") info = pygame.display.Info() + print(f"[MeshBot TTT Display] Pygame version: {pygame.version.ver}") print(f"[MeshBot TTT Display] Resolution: {info.current_w}x{info.current_h} (fullscreen)") print(f"[MeshBot TTT Display] Display driver: {pygame.display.get_driver()}") running = True diff --git a/script/game.ini b/script/game.ini new file mode 100644 index 0000000..09de35e --- /dev/null +++ b/script/game.ini @@ -0,0 +1,14 @@ +[network] +MCAST_GRP = 224.0.0.69 +MCAST_PORT = 4403 +CHANNEL_ID = LongFast +KEY = 1PG7OiApB1nwvP+rz05pAQ== +PUBLIC_CHANNEL_IDS = LongFast,ShortSlow,Medium,LongSlow,ShortFast,ShortTurbo + +[node] +NODE_ID = !meshbotg +LONG_NAME = Mesh Bot Game Server +SHORT_NAME = MBGS + +[game] +SEEN_MESSAGES_MAX = 1000 \ No newline at end of file diff --git a/script/game_serve.py b/script/game_serve.py index b57cc59..ee3c6d9 100644 --- a/script/game_serve.py +++ b/script/game_serve.py @@ -7,6 +7,7 @@ import os import sys import time from collections import OrderedDict +import configparser try: from pubsub import pub @@ -42,11 +43,27 @@ except Exception as e: # logger.addHandler(handler) # logger.debug("Mesh Bot Game Server Logger initialized") -MCAST_GRP, MCAST_PORT, CHANNEL_ID, KEY = "224.0.0.69", 4403, "LongFast", "1PG7OiApB1nwvP+rz05pAQ==" -PUBLIC_CHANNEL_IDS = ["LongFast", "ShortSlow", "Medium", "LongSlow", "ShortFast", "ShortTurbo"] -NODE_ID, LONG_NAME, SHORT_NAME = "!meshbotg", "Mesh Bot Game Server", "MBGS" +# Load config from game.ini if it exists +config = configparser.ConfigParser() +config_path = os.path.join(os.path.dirname(__file__), "game.ini") +if os.path.exists(config_path): + config.read(config_path) + MCAST_GRP = config.get("network", "MCAST_GRP", fallback="224.0.0.69") + MCAST_PORT = config.getint("network", "MCAST_PORT", fallback=4403) + CHANNEL_ID = config.get("network", "CHANNEL_ID", fallback="LongFast") + KEY = config.get("network", "KEY", fallback="1PG7OiApB1nwvP+rz05pAQ==") + PUBLIC_CHANNEL_IDS = [x.strip() for x in config.get("network", "PUBLIC_CHANNEL_IDS", fallback="LongFast,ShortSlow,Medium,LongSlow,ShortFast,ShortTurbo").split(",")] + NODE_ID = config.get("node", "NODE_ID", fallback="!meshbotg") + LONG_NAME = config.get("node", "LONG_NAME", fallback="Mesh Bot Game Server") + SHORT_NAME = config.get("node", "SHORT_NAME", fallback="MBGS") + SEEN_MESSAGES_MAX = config.getint("game", "SEEN_MESSAGES_MAX", fallback=1000) +else: + MCAST_GRP, MCAST_PORT, CHANNEL_ID, KEY = "224.0.0.69", 4403, "LongFast", "1PG7OiApB1nwvP+rz05pAQ==" + PUBLIC_CHANNEL_IDS = ["LongFast", "ShortSlow", "Medium", "LongSlow", "ShortFast", "ShortTurbo"] + NODE_ID, LONG_NAME, SHORT_NAME = "!meshbotg", "Mesh Bot Game Server", "MBGS" + SEEN_MESSAGES_MAX = 1000 # Adjust as needed + CHANNEL_HASHES = {generate_hash(name, KEY): name for name in PUBLIC_CHANNEL_IDS} -SEEN_MESSAGES_MAX = 1000 # Adjust as needed mudpEnabled, mudpInterface = True, None seen_messages = OrderedDict() # Track seen (from, to, payload) tuples is_running = False