Initial commit: 酒桌派对 / 大话骰 multiplayer drinking-game hub

- 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>
This commit is contained in:
gongch
2026-06-17 10:05:10 +08:00
commit 6d1dd5d56c
28 changed files with 2167 additions and 0 deletions

30
test_dice_enhanced.py Normal file
View File

@@ -0,0 +1,30 @@
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)
try: return json.loads(body)
except Exception: return {'ok':False,'error':body}
time.sleep(1)
r=post('/api/create', {'game':'dice','name':'房主','playerId':'p-host'})
code=r['room']['code']
print('create', r['ok'], code, r['player']['ready'])
j=post('/api/join', {'code':code,'name':'客人','playerId':'p-guest'})
print('join guest ready', j['room']['players'][1]['ready'])
bad=post('/api/start', {'code':code,'playerId':'p-host'})
print('start before ready', bad['ok'], bad.get('error'))
ready=post('/api/ready', {'code':code,'playerId':'p-guest'})
print('guest ready', [p['ready'] for p in ready['room']['players']])
setg=post('/api/settings', {'code':code,'playerId':'p-host','cupsPerLoss':2})
print('settings', setg['room']['settings'])
bot=post('/api/add-bot', {'code':code,'playerId':'p-host'})
print('add bot', len(bot['room']['players']))
s=post('/api/start', {'code':code,'playerId':'p-host'})
print('start', s['ok'], s['room']['status'], s['room']['diceRule'])
# 3人局最低3个1
badcall=post('/api/call', {'code':code,'playerId':'p-host','count':2,'point':6})
print('bad call', badcall['ok'], badcall.get('error'))
c=post('/api/call', {'code':code,'playerId':'p-host','count':3,'point':1})
print('call', c['ok'], c['room']['currentCall'])