- server.py: zero-dependency stdlib backend (HTTP + WebSocket /ws), 大话骰 rule engine, server-driven bots - live.html: real MVP frontend wired to the backend over WebSocket - index.html/app.js/style.css: older static prototype - deploy/: systemd unit + Nginx reverse proxy + Let's Encrypt setup.sh - test_*.py: standalone HTTP / in-process test scripts Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
24 lines
1.3 KiB
Python
24 lines
1.3 KiB
Python
import json, urllib.request, time
|
|
base='http://127.0.0.1:8765'
|
|
def post(path, data):
|
|
req=urllib.request.Request(base+path, data=json.dumps(data).encode(), headers={'Content-Type':'application/json'})
|
|
try:
|
|
return json.loads(urllib.request.urlopen(req, timeout=5).read())
|
|
except Exception as e:
|
|
body=e.read().decode() if hasattr(e,'read') else str(e)
|
|
return json.loads(body) if body.startswith('{') else {'ok':False,'error':body}
|
|
time.sleep(1)
|
|
r=post('/api/create', {'game':'dice','name':'小鱼','playerId':'p-test'})
|
|
print('create', r['ok'], r['room']['code'], len(r['room']['players']))
|
|
code=r['room']['code']
|
|
j=post('/api/join', {'code':code,'name':'小鱼','playerId':'p-test'})
|
|
print('rejoin', j['ok'], j.get('reused'), len(j['room']['players']))
|
|
s=post('/api/start', {'code':code})
|
|
print('start', s['ok'], s['room']['status'], s['room']['turnPlayerName'], len(s['room']['players']))
|
|
c1=post('/api/call', {'code':code,'playerId':'p-test','count':1,'point':1})
|
|
print('call1', c1['ok'], c1['room']['currentCall'], 'turn', c1['room']['turnPlayerName'])
|
|
bad=post('/api/call', {'code':code,'playerId':'p-test','count':1,'point':1})
|
|
print('bad call', bad['ok'], bad.get('error'))
|
|
op=post('/api/open', {'code':code,'playerId':'p-test'})
|
|
print('open', op['ok'], op['room']['status'], op['room']['lastResult']['loser'])
|