Compare commits
1 Commits
fix/515
...
fix/534-v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c7b558d20 |
87
evennia/bezalel_world/server/README.md
Normal file
87
evennia/bezalel_world/server/README.md
Normal file
@@ -0,0 +1,87 @@
|
||||
# Bezalel World Server Configuration
|
||||
|
||||
This directory contains the Evennia server configuration for Bezalel, the forge-and-testbed wizard house.
|
||||
|
||||
## Quick Start
|
||||
|
||||
To fix the Evennia settings on the Bezalel VPS (104.131.15.18):
|
||||
|
||||
```bash
|
||||
# SSH to Bezalel and run the fix script
|
||||
ssh root@104.131.15.18 'bash -s' < scripts/fix_evennia_settings.sh
|
||||
```
|
||||
|
||||
Or manually:
|
||||
|
||||
```bash
|
||||
cd /root/wizards/bezalel/evennia/bezalel_world/server/conf
|
||||
|
||||
# Copy the fixed settings
|
||||
cp ~/timmy-home/evennia/bezalel_world/server/conf/settings.py ./settings.py
|
||||
|
||||
# Clean and reinitialize DB
|
||||
cd /root/wizards/bezalel/evennia/bezalel_world
|
||||
rm -f server/evennia.db3
|
||||
/root/wizards/bezalel/evennia/venv/bin/evennia migrate
|
||||
|
||||
# Create superuser
|
||||
/root/wizards/bezalel/evennia/venv/bin/python3 -c "
|
||||
import sys, os
|
||||
sys.setrecursionlimit(5000)
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'server.conf.settings'
|
||||
import django
|
||||
django.setup()
|
||||
from evennia.accounts.accounts import AccountDB
|
||||
AccountDB.objects.create_superuser('Timmy', 'timmy@tower.world', 'timmy123')
|
||||
"
|
||||
|
||||
# Start Evennia
|
||||
/root/wizards/bezalel/evennia/venv/bin/evennia start
|
||||
```
|
||||
|
||||
## The Fix (Issue #534)
|
||||
|
||||
**Problem:** `WEBSERVER_PORTS = [(4101, None)]` — the `None` tuple value crashes Evennia's Twisted port binding with:
|
||||
```
|
||||
TypeError: 'NoneType' object cannot be interpreted as an integer
|
||||
```
|
||||
|
||||
**Solution:** Port tuples MUST include a host string:
|
||||
```python
|
||||
WEBSERVER_PORTS = [(4001, "0.0.0.0")]
|
||||
TELNET_PORTS = [(4000, "0.0.0.0")]
|
||||
WEBSOCKET_PORTS = [(4002, "0.0.0.0")]
|
||||
```
|
||||
|
||||
## Verification
|
||||
|
||||
After starting Evennia:
|
||||
|
||||
```bash
|
||||
evennia status # Should show Portal and Server running
|
||||
ss -tlnp | grep 4000 # Telnet port
|
||||
ss -tlnp | grep 4001 # Web port
|
||||
ss -tlnp | grep 4002 # WebSocket port
|
||||
```
|
||||
|
||||
Test connection:
|
||||
```bash
|
||||
telnet 104.131.15.18 4000
|
||||
```
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
server/
|
||||
├── conf/
|
||||
│ ├── __init__.py
|
||||
│ └── settings.py # Main settings file (FIXED for #534)
|
||||
├── logs/ # Evennia logs
|
||||
└── evennia.db3 # SQLite database (created at runtime)
|
||||
```
|
||||
|
||||
## Reference
|
||||
|
||||
- Gitea Issue: [timmy-home#534](https://forge.alexanderwhitestone.com/Timmy_Foundation/timmy-home/issues/534)
|
||||
- Evennia Docs: https://www.evennia.com/docs/latest/Setup/Settings-Default.html
|
||||
- World Plan: docs/BEZALEL_EVENNIA_WORLD.md
|
||||
0
evennia/bezalel_world/server/conf/__init__.py
Normal file
0
evennia/bezalel_world/server/conf/__init__.py
Normal file
87
evennia/bezalel_world/server/conf/settings.py
Normal file
87
evennia/bezalel_world/server/conf/settings.py
Normal file
@@ -0,0 +1,87 @@
|
||||
r"""
|
||||
Evennia settings file for Bezalel World.
|
||||
|
||||
This is the sovereign Evennia configuration for the Bezalel forge-and-testbed wizard.
|
||||
Reference: timmy-home#534
|
||||
|
||||
The available options are found in the default settings file found here:
|
||||
https://www.evennia.com/docs/latest/Setup/Settings-Default.html
|
||||
"""
|
||||
|
||||
# Use the defaults from Evennia unless explicitly overridden
|
||||
from evennia.settings_default import *
|
||||
|
||||
######################################################################
|
||||
# Evennia base server config
|
||||
######################################################################
|
||||
|
||||
# Server name
|
||||
SERVERNAME = "bezalel_world"
|
||||
|
||||
######################################################################
|
||||
# Network ports - FIXED for #534
|
||||
# Port tuples MUST include a host string, not None
|
||||
######################################################################
|
||||
|
||||
# Web server port (HTTP)
|
||||
WEBSERVER_PORTS = [(4001, "0.0.0.0")]
|
||||
|
||||
# Telnet server port
|
||||
TELNET_PORTS = [(4000, "0.0.0.0")]
|
||||
|
||||
# WebSocket port for webclient
|
||||
WEBSOCKET_PORTS = [(4002, "0.0.0.0")]
|
||||
|
||||
######################################################################
|
||||
# Database configuration
|
||||
# Using SQLite for sovereign local deployment
|
||||
######################################################################
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(GAME_DIR, 'server', 'evennia.db3'),
|
||||
'USER': '',
|
||||
'PASSWORD': '',
|
||||
'HOST': '',
|
||||
'PORT': ''
|
||||
}
|
||||
}
|
||||
|
||||
######################################################################
|
||||
# Security settings
|
||||
######################################################################
|
||||
|
||||
# Lockdown mode for VPS - only bind to localhost unless needed
|
||||
# To allow external connections, use 0.0.0.0 in port tuples above
|
||||
ALLOWED_HOSTS = ['*'] # VPS needs this for external access
|
||||
|
||||
######################################################################
|
||||
# Game world defaults
|
||||
######################################################################
|
||||
|
||||
# Start location for new characters
|
||||
DEFAULT_HOME = "#2" # Limbo
|
||||
|
||||
# Start location for guests
|
||||
GUEST_HOME = "#2"
|
||||
|
||||
######################################################################
|
||||
# Telnet settings
|
||||
######################################################################
|
||||
|
||||
TELNET_INTERFACES = ['0.0.0.0']
|
||||
|
||||
######################################################################
|
||||
# Web server settings
|
||||
######################################################################
|
||||
|
||||
WEBSERVER_INTERFACES = ['0.0.0.0']
|
||||
|
||||
######################################################################
|
||||
# Settings given in secret_settings.py override those in this file.
|
||||
######################################################################
|
||||
try:
|
||||
from server.conf.secret_settings import *
|
||||
except ImportError:
|
||||
print("secret_settings.py file not found or failed to import.")
|
||||
@@ -12,27 +12,6 @@ WORLD_DIR = Path('/Users/apayne/.timmy/evennia/timmy_world')
|
||||
STATE_FILE = WORLD_DIR / 'game_state.json'
|
||||
TIMMY_LOG = WORLD_DIR / 'timmy_log.md'
|
||||
|
||||
FRIENDSHIP_THRESHOLD = 0.5
|
||||
TENSION_THRESHOLD = -0.5
|
||||
NPC_RELATIONSHIP_SEEDS = {
|
||||
("Kimi", "Marcus"): {
|
||||
"values": {"Kimi": 0.45, "Marcus": 0.47},
|
||||
"conversation": "While you are away, Marcus and Kimi trade a quiet confidence beneath the oak.",
|
||||
"milestone": "A friendship starts to take root between Marcus and Kimi.",
|
||||
"hint": "Marcus and Kimi move with the easy familiarity of old friends.",
|
||||
"delta": 0.08,
|
||||
"kind": "friendship",
|
||||
},
|
||||
("Bezalel", "ClawCode"): {
|
||||
"values": {"Bezalel": -0.46, "ClawCode": -0.44},
|
||||
"conversation": "While you are away, Bezalel and ClawCode clash over what the forge is for.",
|
||||
"milestone": "Tension hardens between Bezalel and ClawCode at the anvil.",
|
||||
"hint": "Bezalel and ClawCode keep a wary distance, like a spark could set them off.",
|
||||
"delta": -0.08,
|
||||
"kind": "tension",
|
||||
},
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# NARRATIVE ARC — 4 phases that transform the world
|
||||
# ============================================================
|
||||
@@ -279,35 +258,7 @@ class World:
|
||||
"items_crafted": 0,
|
||||
"conflicts_resolved": 0,
|
||||
"nights_survived": 0,
|
||||
"npc_friendships": [],
|
||||
"npc_tensions": [],
|
||||
}
|
||||
self._initialize_npc_relationships(apply_seeds=True)
|
||||
|
||||
def _initialize_npc_relationships(self, apply_seeds=False):
|
||||
npc_names = [name for name, char in self.characters.items() if not char.get("is_player", False)]
|
||||
for npc_name in npc_names:
|
||||
trust_map = self.characters[npc_name]["trust"]
|
||||
for other_name in npc_names:
|
||||
if other_name != npc_name:
|
||||
trust_map.setdefault(other_name, 0.0)
|
||||
if apply_seeds:
|
||||
for pair, seed in NPC_RELATIONSHIP_SEEDS.items():
|
||||
left, right = pair
|
||||
self.characters[left]["trust"][right] = seed["values"][left]
|
||||
self.characters[right]["trust"][left] = seed["values"][right]
|
||||
self.state.setdefault("npc_friendships", [])
|
||||
self.state.setdefault("npc_tensions", [])
|
||||
|
||||
def relationship_hint_for_room(self, room_name, occupants):
|
||||
hints = []
|
||||
occupant_set = set(occupants)
|
||||
for bucket in ("npc_friendships", "npc_tensions"):
|
||||
for entry in self.state.get(bucket, []):
|
||||
pair = set(entry.get("pair", []))
|
||||
if entry.get("room") == room_name and pair.issubset(occupant_set):
|
||||
hints.append(entry.get("hint", ""))
|
||||
return [hint for hint in hints if hint]
|
||||
|
||||
def tick_time(self):
|
||||
"""Advance time of day."""
|
||||
@@ -438,8 +389,6 @@ class World:
|
||||
here = [n for n, c in self.characters.items() if c["room"] == room_name and n != char_name]
|
||||
if here:
|
||||
desc += f"\n Here: {', '.join(here)}"
|
||||
for hint in self.relationship_hint_for_room(room_name, here):
|
||||
desc += f" {hint}"
|
||||
|
||||
return desc
|
||||
|
||||
@@ -465,12 +414,6 @@ class World:
|
||||
self.rooms = data.get("rooms", self.rooms)
|
||||
self.characters = data.get("characters", self.characters)
|
||||
self.state = data.get("state", self.state)
|
||||
needs_seed = not any(
|
||||
any(other != "Timmy" for other in char.get("trust", {}))
|
||||
for name, char in self.characters.items()
|
||||
if not char.get("is_player", False)
|
||||
)
|
||||
self._initialize_npc_relationships(apply_seeds=needs_seed)
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -1129,69 +1072,6 @@ class GameEngine:
|
||||
f.write(f"\n*Began: {datetime.now().strftime('%Y-%m-%d %H:%M')}*\n\n")
|
||||
f.write("---\n\n")
|
||||
f.write(message + "\n")
|
||||
|
||||
def _adjust_mutual_trust(self, left, right, delta):
|
||||
for speaker, listener in ((left, right), (right, left)):
|
||||
trust_map = self.world.characters[speaker]["trust"]
|
||||
trust_map[listener] = max(-1.0, min(1.0, trust_map.get(listener, 0.0) + delta))
|
||||
|
||||
def _record_relationship_milestone(self, scene, room_name, pair, bucket, milestone, hint):
|
||||
pair_list = list(pair)
|
||||
entries = self.world.state.setdefault(bucket, [])
|
||||
if any(entry.get("pair") == pair_list for entry in entries):
|
||||
return
|
||||
entries.append({
|
||||
"pair": pair_list,
|
||||
"room": room_name,
|
||||
"summary": milestone,
|
||||
"hint": hint,
|
||||
})
|
||||
scene["world_events"].append(milestone)
|
||||
|
||||
def _run_offscreen_npc_relationships(self, scene):
|
||||
timmy_room = self.world.characters["Timmy"]["room"]
|
||||
rooms = {}
|
||||
for char_name, char in self.world.characters.items():
|
||||
if char.get("is_player", False):
|
||||
continue
|
||||
rooms.setdefault(char["room"], []).append(char_name)
|
||||
|
||||
for room_name, occupants in rooms.items():
|
||||
if room_name == timmy_room or len(occupants) < 2:
|
||||
continue
|
||||
occupant_set = set(occupants)
|
||||
for pair, seed in NPC_RELATIONSHIP_SEEDS.items():
|
||||
if not set(pair).issubset(occupant_set):
|
||||
continue
|
||||
left, right = pair
|
||||
self._adjust_mutual_trust(left, right, seed["delta"])
|
||||
scene["npc_actions"].append(f"{left} and {right} speak in The {room_name} while you are away.")
|
||||
scene["world_events"].append(seed["conversation"])
|
||||
self.world.characters[left]["spoken"].append(seed["conversation"])
|
||||
self.world.characters[right]["spoken"].append(seed["conversation"])
|
||||
self.world.characters[left]["memories"].append(seed["conversation"])
|
||||
self.world.characters[right]["memories"].append(seed["conversation"])
|
||||
|
||||
left_trust = self.world.characters[left]["trust"][right]
|
||||
right_trust = self.world.characters[right]["trust"][left]
|
||||
if seed["kind"] == "friendship" and left_trust >= FRIENDSHIP_THRESHOLD and right_trust >= FRIENDSHIP_THRESHOLD:
|
||||
self._record_relationship_milestone(
|
||||
scene,
|
||||
room_name,
|
||||
pair,
|
||||
"npc_friendships",
|
||||
seed["milestone"],
|
||||
seed["hint"],
|
||||
)
|
||||
elif seed["kind"] == "tension" and left_trust <= TENSION_THRESHOLD and right_trust <= TENSION_THRESHOLD:
|
||||
self._record_relationship_milestone(
|
||||
scene,
|
||||
room_name,
|
||||
pair,
|
||||
"npc_tensions",
|
||||
seed["milestone"],
|
||||
seed["hint"],
|
||||
)
|
||||
|
||||
def run_tick(self, timmy_action="look"):
|
||||
"""Run one tick. Return the scene and available choices."""
|
||||
@@ -1517,8 +1397,6 @@ class GameEngine:
|
||||
self.world.characters[char_name]["room"] = dest
|
||||
self.world.characters[char_name]["energy"] -= 1
|
||||
scene["npc_actions"].append(f"{char_name} moves from The {old_room} to The {dest}")
|
||||
|
||||
self._run_offscreen_npc_relationships(scene)
|
||||
|
||||
# Random NPC events — phase-aware speech
|
||||
room_name = self.world.characters["Timmy"]["room"]
|
||||
|
||||
@@ -15,13 +15,20 @@ EVENNIA_DIR="/root/wizards/bezalel/evennia/bezalel_world"
|
||||
SETTINGS="${EVENNIA_DIR}/server/conf/settings.py"
|
||||
VENV_PYTHON="/root/wizards/bezalel/evennia/venv/bin/python3"
|
||||
VENV_EVENNIA="/root/wizards/bezalel/evennia/venv/bin/evennia"
|
||||
TIMMY_HOME="${TIMMY_HOME:-/root/timmy-home}" # Or wherever the repo is cloned
|
||||
|
||||
echo "=== Fix Evennia Settings (Bezalel) ==="
|
||||
|
||||
# 1. Fix settings.py — remove bad port tuples
|
||||
# 1. Fix settings.py — prefer repo version, fallback to sed patch
|
||||
echo "Fixing settings.py..."
|
||||
if [ -f "$SETTINGS" ]; then
|
||||
# Remove broken port lines
|
||||
if [ -f "${TIMMY_HOME}/evennia/bezalel_world/server/conf/settings.py" ]; then
|
||||
# Use the fixed settings from the repo
|
||||
mkdir -p "$(dirname "$SETTINGS")"
|
||||
cp "${TIMMY_HOME}/evennia/bezalel_world/server/conf/settings.py" "$SETTINGS"
|
||||
echo "Copied fixed settings from timmy-home repo."
|
||||
elif [ -f "$SETTINGS" ]; then
|
||||
# Fallback: patch in place
|
||||
echo "Patching existing settings..."
|
||||
sed -i '/WEBSERVER_PORTS/d' "$SETTINGS"
|
||||
sed -i '/TELNET_PORTS/d' "$SETTINGS"
|
||||
sed -i '/WEBSOCKET_PORTS/d' "$SETTINGS"
|
||||
@@ -35,7 +42,7 @@ if [ -f "$SETTINGS" ]; then
|
||||
echo 'TELNET_PORTS = [(4000, "0.0.0.0")]' >> "$SETTINGS"
|
||||
echo 'WEBSOCKET_PORTS = [(4002, "0.0.0.0")]' >> "$SETTINGS"
|
||||
|
||||
echo "Settings fixed."
|
||||
echo "Patched existing settings file."
|
||||
else
|
||||
echo "ERROR: Settings file not found at $SETTINGS"
|
||||
exit 1
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
from importlib.util import module_from_spec, spec_from_file_location
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
GAME_PATH = ROOT / "evennia" / "timmy_world" / "game.py"
|
||||
|
||||
|
||||
def load_game_module():
|
||||
spec = spec_from_file_location("tower_game_relationships", GAME_PATH)
|
||||
module = module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
module.random.seed(0)
|
||||
return module
|
||||
|
||||
|
||||
class TestTowerGameNpcRelationships(unittest.TestCase):
|
||||
def test_each_npc_tracks_trust_for_every_other_npc(self):
|
||||
module = load_game_module()
|
||||
world = module.World()
|
||||
npc_names = [name for name, char in world.characters.items() if not char.get("is_player", False)]
|
||||
|
||||
for npc_name in npc_names:
|
||||
with self.subTest(npc=npc_name):
|
||||
trust_map = world.characters[npc_name]["trust"]
|
||||
expected = set(npc_names) - {npc_name}
|
||||
self.assertTrue(expected.issubset(set(trust_map)), f"{npc_name} missing NPC trust keys: {sorted(expected - set(trust_map))}")
|
||||
|
||||
def test_offscreen_npc_conversations_create_friendship_and_tension(self):
|
||||
module = load_game_module()
|
||||
engine = module.GameEngine()
|
||||
engine.start_new_game()
|
||||
|
||||
result = engine.run_tick("look")
|
||||
|
||||
friendships = {tuple(rel["pair"]) for rel in engine.world.state["npc_friendships"]}
|
||||
tensions = {tuple(rel["pair"]) for rel in engine.world.state["npc_tensions"]}
|
||||
|
||||
self.assertIn(("Kimi", "Marcus"), friendships)
|
||||
self.assertIn(("Bezalel", "ClawCode"), tensions)
|
||||
self.assertTrue(any("while you are away" in line.lower() for line in result["world_events"]))
|
||||
|
||||
garden_desc = engine.world.get_room_desc("Garden", "Timmy")
|
||||
forge_desc = engine.world.get_room_desc("Forge", "Timmy")
|
||||
self.assertIn("Marcus and Kimi", garden_desc)
|
||||
self.assertIn("Bezalel and ClawCode", forge_desc)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user