<commit_before>#!/usr/bin/env python

# Set this variable to "threading", "eventlet" or "gevent" to test the
# different async modes, or leave it set to None for the application to choose
# the best option based on available packages.
async_mode = None

if async_mode is None:
    try:
        import eventlet
        async_mode = 'eventlet'
    except ImportError:
        pass
    
    if async_mode is None:
        try:
            from gevent import monkey
            async_mode = 'gevent'
        except ImportError:
            pass
    
    if async_mode is None:
        async_mode = 'threading'
    print('async_mode is ' + async_mode)

# monkey patching is necessary because this application uses a background
# thread
if async_mode == 'eventlet':
    import eventlet
    eventlet.monkey_patch()
elif async_mode == 'gevent':
    from gevent import monkey
    monkey.patch_all()

import time
from multiprocessing.pool import ThreadPool
from threading import Thread
from flask import Flask, render_template, session, request, copy_current_request_context
from flask_socketio import SocketIO, emit, join_room, leave_room, \
    close_room, rooms, disconnect
import game

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, async_mode=async_mode)
thread = None
thread2 = None
roomsDict = {}

games = None
inputdone = False
output = []
inptt = None
state = 0

def input_thread():
    print("INPUT")
    if(games is not None):
        global output 
        inputdone = False
        output = games.update()
        inputdone = True
    print("END INPUT")

def background_thread():
    """Example of how to send server generated events to clients."""
    global games, socketio, state
    count = 0
    while True:
        time.sleep(10)
        count += 1
        with app.test_request_context('/'):
            if games is not None:
                players = games.getPlayers()
                if state == 0:
                    for player in players:
                        socketio.emit('my hand',
                            {'user': 'Deceit', 'data': player.displayHand()}, room=player.getName(), namespace='/test')
                    socketio.emit('my response',
                        {'user': 'Deceit', 'data': 'You have been selected as the host.'}, room=games.getHost(), namespace='/test')
                    state += 1
                if state == 3:
                    cards = []
                    for player in players:
                        cards.append(player.getSelectedCard())
                        player.removeCard(player.getSelectedCard())
                        player.setSelectedCard(None)
                    games.resetPending()
                    games.setDisplayedBoard(cards)
                    games.setHiddenBoard(cards)
                    for player in players:
                        socketio.emit('my voting hand',
                            {'user': 'Deceit', 'data': games.displayVotingHand()}, room=player.getName(), namespace='/test')
                    state += 1

      # print("BACKGROUND")
      # #print("Game none:"),
      # #print(games)
      # if(games is not None):<commit_msg>Store owner with selected card in object<commit_after>#!/usr/bin/env python

# Set this variable to "threading", "eventlet" or "gevent" to test the
# different async modes, or leave it set to None for the application to choose
# the best option based on available packages.
async_mode = None

if async_mode is None:
    try:
        import eventlet
        async_mode = 'eventlet'
    except ImportError:
        pass
    
    if async_mode is None:
        try:
            from gevent import monkey
            async_mode = 'gevent'
        except ImportError:
            pass
    
    if async_mode is None:
        async_mode = 'threading'
    print('async_mode is ' + async_mode)

# monkey patching is necessary because this application uses a background
# thread
if async_mode == 'eventlet':
    import eventlet
    eventlet.monkey_patch()
elif async_mode == 'gevent':
    from gevent import monkey
    monkey.patch_all()

import time
from multiprocessing.pool import ThreadPool
from threading import Thread
from flask import Flask, render_template, session, request, copy_current_request_context
from flask_socketio import SocketIO, emit, join_room, leave_room, \
    close_room, rooms, disconnect
import game

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, async_mode=async_mode)
thread = None
thread2 = None
roomsDict = {}

games = None
inputdone = False
output = []
inptt = None
state = 0

def input_thread():
    print("INPUT")
    if(games is not None):
        global output 
        inputdone = False
        output = games.update()
        inputdone = True
    print("END INPUT")

def background_thread():
    """Example of how to send server generated events to clients."""
    global games, socketio, state
    count = 0
    while True:
        time.sleep(10)
        count += 1
        with app.test_request_context('/'):
            if games is not None:
                players = games.getPlayers()
                if state == 0:
                    for player in players:
                        socketio.emit('my hand',
                            {'user': 'Deceit', 'data': player.displayHand()}, room=player.getName(), namespace='/test')
                    socketio.emit('my response',
                        {'user': 'Deceit', 'data': 'You have been selected as the host.'}, room=games.getHost(), namespace='/test')
                    state += 1
                elif state == 3:
                    cards = []
                    for player in players:
                        obj = {
                            'image': player.getSelectedCard(),
                            'owner': player.getName()
                        }
                        cards.append(obj)
                        player.removeCard(player.getSelectedCard())
                        player.setSelectedCard(None)
                    games.resetPending()
                    games.setDisplayedBoard(cards)
                    games.setHiddenBoard(cards)
                    for player in players:
                        socketio.emit('my voting hand',
                            {'user': 'Deceit', 'data': games.displayVotingHand()}, room=player.getName(), namespace='/test')
                    state += 1
                elif state == 5:
                    cards = []
                    for player in players:
                        obj = {
                            'vote': player.getSelectedCard(),
                            'owner': player.getName()
                        }
                        cards.append(obj)
                        player.removeCard(player.getSelectedCard())
                        player.setSelectedCard(None)
                    games.resetPending()
                    games.setDisplayedBoard(cards)
                    games.setHiddenBoard(cards)
                    # for player in players:
                    #     socketio.emit('my voting hand',
                    #         {'user': 'Deceit', 'data': games.displayVotingHand()}, room=player.getName(), namespace='/test')
                    state += 1

      # print("BACKGROUND")
      # #print("Game none:"),
      # #print(games)
      # if(games is not None):
{'fraction_non_alphanumeric': 0.09461288576069302, 'fraction_numerical': 0.002977801840822956, 'mean_word_length': 1.7705286839145107, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '837650', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1855, 'n_words': 572}