def client_hit(data): draw(identifier_to_steamid(data['identifier']), db.session.query(Game).filter(Game.player_steamid == identifier_to_steamid(data['identifier'])).one().deck_identifier, Status.visible) socketio.emit('update_table', json.dumps(update_table(data['identifier'])), room=request.sid) if isGameOver(identifier_to_steamid(data['identifier'])): client_stand(data)
def client_balance(data): print('Client requested balance update') socketio.emit('balance_update', json.dumps({ 'balance': db.session.query(User).filter( User.identifier == data['identifier']).one().balance }), room=request.sid)
def validate(data): if 'user_identifier' not in data: socketio.emit('login_required', room=request.sid) return if db.session.query(User).filter( User.user_identifier == data['user_identifier']).count(): return func(data) else: socketio.emit('login_required', room=request.sid)
def client_doubledown(data): if doubledown_valid(data['identifier']): if sufficent_funds(data['identifier'], current_bet(data['identifier'])): draw(identifier_to_steamid(data['identifier']), db.session.query(Game).filter(Game.player_steamid == identifier_to_steamid(data['identifier'])).one().deck_identifier, Status.hidden) double_bet(data['identifier']) socketio.emit('update_table', json.dumps(update_table(data['identifier'])), room=request.sid) client_stand(data) else: socketio.emit('error', {'message': 'insufficent funds'}, room=request.sid)
def send_options(steamid, option): sid = db.session.query(Active_player).filter( Active_player.steamid == steamid).one().session_id if option == options.bet: option_data = {'message': 'Please bet', 'action_required': 'bet'} elif option == options.play: option_data = {'message': 'Make a play', 'action_required': 'play'} socketio.emit('client_action_required', json.dumps(option_data), room=sid)
def client_connect(data): print('Client has connected') deck_identifier = db.session.query(Game).filter(Game.player_steamid == identifier_to_steamid(data['identifier'])).one().deck_identifier draw(identifier_to_steamid(data['identifier']), deck_identifier,Status.visible) draw(identifier_to_steamid(data['identifier']), deck_identifier,Status.hidden) draw(get_cpu_identifier(data['identifier']), deck_identifier, Status.visible) draw(get_cpu_identifier(data['identifier']), deck_identifier, Status.hidden) socketio.emit('update_table', json.dumps(update_table(data['identifier'])), room=request.sid) if isGameOver(identifier_to_steamid(data['identifier'])): client_stand(data)
def update_user_event(data): if 'identifier' in data: user_identifier = data['identifier'] else: return user_query = db.session.query(User).filter( User.user_identifier == user_identifier) if user_query.count(): user = user_query.one() socketio.emit('update_user_response', str(user.balance), room=request.sid)
def time_roulettes(): global timer timer += 1 if timer < int(config.interval): socketio.emit('update_time', str(int(config.interval) - timer), broadcast=True) if timer == int(config.interval): winning_alternative = bet.lottery() socketio.emit('run_script', str(winning_alternative), broadcast=True) bet.finish_round(winning_alternative) if timer == int(config.interval) + 3: timer = 0
def simulate_cpu(steamid, sid): cpu_identifer = db.session.query(Game).filter( Game.player_steamid == steamid).one().cpu_hand_identifier while True: if get_game_state( steamid ) == Game_state.player_busted or calculate_hand(cpu_identifer) > 16: break else: draw( cpu_identifer, db.session.query(Game).filter( Game.player_steamid == steamid).one().deck_identifier, Status.visible) socketio.emit('update_table', json.dumps( update_table(steamid_to_identifer(steamid))), room=sid)
def client_connect(data): player = db.session.query(Active_player).filter( Active_player.steamid == identifier_to_steamid(data['identifier']) ).filter(Active_player.session_id == None).one() player.session_id = request.sid db.session.commit() print('Client has connected to table') round_handler.round_action(data['identifier']) if table_handler.get_turn( table_handler.get_current_table( identifier_to_steamid(data['identifier'])).id) != None: socketio.emit('client_message', json.dumps({'message': 'Wait till next round'}), room=request.sid)
def client_bet(data): bet_amount = float(data['bet_amount']) user_identifier = data['user_identifier'] alternative = data['alternative'] user = db.session.query(User).filter( User.user_identifier == user_identifier).one() if user.balance < bet_amount: errors.send_error('Insufficent funds', request.sid) elif bet_amount > float(config.max_bet): errors.send_error('Max bet is ' + config.max_bet, request.sid) elif bet_amount < float(config.min_bet): errors.send_error('Min bet is ' + config.min_bet, request.sid) else: json_resp = { 'status': 'success', 'balance': user.balance, 'bet_amount': bet_amount, 'alternative': alternative } socketio.emit('bet_response', json.dumps(json_resp), room=request.sid) bet.bet(user_identifier, bet_amount, alternative) new_bet_data = { 'name': steamid_to_name(user.steamid), 'amount': bet_amount } if str(alternative) == str(1): new_bet_data['alternative'] = 'red' elif str(alternative) == str(2): new_bet_data['alternative'] = 'black' else: new_bet_data['alternative'] = 'green' socketio.emit('new_bet', json.dumps(new_bet_data), broadcast=True)
def client_action(data): if data['action'] == 'bet': response = table_handler.validate_bet(data['identifier'], int(data['amount'])) print(response) if response == 'Bet placed': socketio.emit('action_confirmed', room=request.sid) socketio.emit('client_message', json.dumps({'message': response}), room=request.sid) elif data['action'] == 'hit': draw( identifier_to_steamid(data['identifier']), table_handler.get_current_table( identifier_to_steamid(data['identifier'])).deck_identifier, Status.visible) round_handler.round_action(data['identifier'])
def client_stand(data): simulate_cpu(identifier_to_steamid(data['identifier']), request.sid) payout_bet(identifier_to_steamid(data['identifier'])) socketio.emit('game_finished', json.dumps(finish_game(data['identifier'])), room=request.sid)
def emit_to_table(table_id, event_name, data): for player in db.session.query(Active_player).filter( Active_player.table_id == table_id).all(): socketio.emit(event_name, data, room=player.session_id)
def send_error(message, sid): socketio.emit('error', message, room=sid)
def client_message(json): socketio.emit('new_client', broadcast=True)