game.ini to custom values and doc
This commit is contained in:
SpudGunMan
2025-11-02 21:14:21 -08:00
parent fb7bf1975b
commit 14ea1e3d97
4 changed files with 50 additions and 4 deletions

View File

@@ -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.

View File

@@ -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

14
script/game.ini Normal file
View File

@@ -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

View File

@@ -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