Skip to content

Instantly share code, notes, and snippets.

@lluchs
Created November 5, 2017 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lluchs/b1a1f28bf6eba6e0d0d39dced353cf5c to your computer and use it in GitHub Desktop.
Save lluchs/b1a1f28bf6eba6e0d0d39dced353cf5c to your computer and use it in GitHub Desktop.
Script for automatically testing OpenClonk runtime join
#!/usr/bin/env python3
import pexpect
import os
import sys
import time
openclonk = './openclonk-server'
#scenario = 'planet/Tests.ocf/Minimal.ocs'
#scenario = 'planet/Worlds.ocf/GoldRush.ocs'
scenario = 'marsmoon/RuntimeJoinTest-broken-water.ocs'
player1 = f'{os.environ["HOME"]}/.clonk/openclonk/Test3.ocp'
player2 = f'{os.environ["HOME"]}/.clonk/openclonk/Test2.ocp'
host = pexpect.spawnu(f'{openclonk} --language=US --runtimejoin --host {scenario} {player1}', timeout=None)
host.logfile = sys.stdout
# Start the game from the lobby.
host.expect('Awaiting participants...')
host.sendline('/start 0')
host.expect('Game started.')
host.expect('Player join:')
# Game is running now, launch the client.
client = pexpect.spawnu(f'{openclonk} --language=US --client=1 {player2}', timeout=None)
client.logfile = sys.stdout
client.expect('Start!')
index = client.expect(['Player join:', 'Game over.'])
if index == 1:
print('Runtime join failed!')
sys.exit(1)
# Verify connection by executing script.
host.sendline('/script Log("%d foobarxyz", Random(10000))')
host.expect('foobarxyz\r\n')
client.expect('foobarxyz\r\n')
client.sendintr()
host.sendintr()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment