1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| import threading from flask import session, request from flask_socketio import emit, join_room, leave_room, disconnect
@clearmind_socketio.on('connect', namespace='/wslogin') def login_connect(): print_and_log('收到登录请求...') try: username = request.args['username'] password = request.args['password'] '''......''' if 4 < 5: emit('reply', reply) else: emit('reply', 'deny') except Exception as e: print_and_log(str(type(e)),str(e)) disconnect() return False
@clearmind_socketio.on('disconnect', namespace='/wslogin') def login_disconnect(): '''登录连接断开时执行''' try : username = request.args['username'] password = request.args['password'] except: pass print_and_log(f'登录连接断开... {username}')
@clearmind_socketio.on('click', namespace='/wsmine') def mine_click(info): '''收到点击地图时间, 把数据中的参数抛给后端处理'''
try : cookie = request.args['cookie'] data = json.loads(info) x, y = data['x'], data['y'] username, tm = cookie_user_dict[cookie] except Exception as e: print_and_log('>>> error ' + str(type(e)) + ' ' + str(e)) disconnect() return False
'''代码''' emit('broadcast', json.dumps({'x' : x, 'y' : y, 'color' : color, 'timmer' : timmer, 'username' : username}), broadcast = True)
'''代码''' emit('game end', json.dumps(CM_server.rank()), broadcast = True) '''代码''' emit('args', json.dumps(CM_server.args()), broadcast = True)
|