Skip to main content

Testing with Bots

The client has headless modes that play without a person: a gameplay bot for long soak runs, load bots for measuring the server, and a screenshot mode for the portal. All of them run the real client and use the same RPCs a player does.

They need test accounts. scripts/create_test_accounts.py creates them, gives them the Tester role and saves their credentials in .env.test-accounts (ignored by Git). Tokens are minted fresh on every run.

Stevedave, the gameplay bot​

Stevedave plays the game for hours, so that problems that only show up over a long session surface without anyone sitting there. Its code is godot_client/scripts/Bot.gd, and Network.gd starts it when the client is run with --bot.

It loops through what a new character does:

  1. Hunts rabbits, geese and slimes with bare hands. It never picks a wolf or a bear, and leaves prey alone if one is within 25 m of it.
  2. Loots each kill's pack.
  3. Gathers flint or limestone.
  4. Crushes two at the Crusher and collects the job.
  5. Sells meat, pelts, goo and any stone beyond 6 to Anyxa.

It moves by probe teleport, not by walking. It listens for server notices, so when it is told that its job slots are in use, it waits.

Create its account, then run it:

python scripts/create_test_accounts.py --name stevedave
python scripts/run_bot.py # until Ctrl-C
python scripts/run_bot.py --hours 8
python scripts/run_bot.py --email someone@moondog.local --log bot.log
flagdefault
--creds.env.test-accounts
--urlhttp://localhost:8082/api/gameauth/token
--host, --port127.0.0.1, 7777
--godot$GODOT, else W:/Godot/Godot_v4.7.2-stable_win64_console.exe
--containermoondog-mmo-engine-game-server-1
--interval60 (seconds between server samples)
--log<name>-bot.log

The runner launches godot --headless --path godot_client -- --bot with MOONDOG_TOKEN, MOONDOG_HOST and MOONDOG_PORT set. It relaunches the client if it exits, and waits longer before the next try if a client dies within 30 s.

The log file gets all of the client's output. Three kinds of line matter:

linewhat it is
BOT <time> ...one per finished or abandoned task, and a stats line each minute
SERVER <time> cpu=..% mem=..MiBa sample of the game server container, or sample missed
RUNNER ...launches and token failures

Only the BOT lines are echoed to the console.

Load bots​

scripts/load_bots.py connects many headless clients that wander around spawn, and samples the game server container's CPU and memory while they do.

python scripts/create_test_accounts.py --prefix load --count 20
python scripts/load_bots.py --count 20 --seconds 300
flagdefaultmeaning
--count20number of bots
--prefixloadwhich test accounts to use
--seconds300how long to run
--baseline30seconds of sampling before any bot connects
--stagger1.0seconds between bot connections
--interval5seconds between samples
--log-dir<temp>/moondog-load-botswhere each bot's log goes

--creds, --url, --host, --port, --godot and --container work as for run_bot.py.

Each bot runs the wander movement probe (Diagnostics), starting at a different heading so they spread out. The script prints the number of bots alive with each sample, and a summary at the end that names any bot that exited abnormally. CPU is given with 100% meaning one core.

When it was added, 5 bots cost about 20–30% of one core on a Ryzen 5 3600 that was also running the server.

Screenshots​

--shots takes the screenshots for the portal's home page from the real client against a live server. The code is godot_client/scripts/CaptureShots.gd. It needs a Tester token, because it moves by probe teleport, and a window, because a headless run has nothing to capture.

# list every world entity's name and position, to write a plan against
MOONDOG_HOST=127.0.0.1 godot --path godot_client -- --token-file=shots.token --shots --survey

# take each shot in the plan, save <out>/<name>.png, and quit
MOONDOG_HOST=127.0.0.1 godot --path godot_client -- --token-file=shots.token --shots --plan=shots.json --out=dir/

A plan is a JSON array of shots. Each shot names a target entity or a fixed point, where to stand relative to it, the camera pitch, the in-game hour, whether to show the HUD, and whether to open the target's window:

{"name": "wolf", "target": "Wolf", "from": [4, 3], "hour": 17.5,
"ui": false, "interact": false, "wait": 3.0}

The portal's images are kept in Moondog.Portal/wwwroot/img/shots/.