- 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>
34 lines
1023 B
Python
34 lines
1023 B
Python
import importlib.util
|
|
spec=importlib.util.spec_from_file_location('srv','/var/minis/workspace/drinking-games-ui/server.py')
|
|
srv=importlib.util.module_from_spec(spec); spec.loader.exec_module(srv)
|
|
|
|
def new_room():
|
|
room, host=srv.create_room('dice','房主','p-host')
|
|
for _ in range(2): srv.add_bot(room['code'],'p-host')
|
|
srv.start_room(room['code'],'p-host')
|
|
return room
|
|
|
|
room=new_room()
|
|
srv.call_dice(room['code'],'p-host',5,2,'斋')
|
|
print('first 5x2 zhai', room['currentCall'])
|
|
assert room['currentCall']['mode']=='斋'
|
|
|
|
room=new_room()
|
|
srv.call_dice(room['code'],'p-host',5,2,'飞')
|
|
print('first 5x2 fly', room['currentCall'])
|
|
assert room['currentCall']['mode']=='飞'
|
|
|
|
room=new_room()
|
|
try:
|
|
srv.call_dice(room['code'],'p-host',5,1,'飞')
|
|
print('bad 5x1 fly accepted')
|
|
except Exception as e:
|
|
print('bad 5x1 fly rejected', str(e))
|
|
|
|
room=new_room()
|
|
try:
|
|
srv.call_dice(room['code'],'p-host',3,2,'斋')
|
|
print('bad 3x2 accepted')
|
|
except Exception as e:
|
|
print('bad 3x2 rejected', str(e))
|