<commit_before>#!/usr/bin/python3
# -*- coding: utf-8

import json
import os
import select
import socket
import time

from network import *

VERSION = '0.0.1'

class Client(Connection):

    def __init__(self, conn):
        super().__init__(conn)
        self.name = None
        self.version = None
        self.current_game = None
        self.last_message = time.monotonic()
        self.last_ping = 0

class Game:

    def __init__(self, name, host, num_players):
        self.name = name
        self.players = [host]
        self.num_players = num_players
        self.started = False

    def empty(self):
        if self.started:
            return all(p is None for p in self.players)
        else:
            return len(self.players) == 0

    def ready(self):
        return len(self.players) == self.num_players and \
            all(p is not None for p in self.players)

    def join(self, conn):
        if self.started:
            raise ClientError('game has already started')
        else:
            self.send_all({ 'action': 'join', 'name': conn.name })
            self.players.append(conn)

    def leave(self, conn):
        self.players.remove(conn)
        self.send_all({ 'action': 'leave', 'name': conn.name })

    def rejoin(self, conn):
        raise NotImplementedError

    def start(self):
        self.started = True
        names = [p.name for p in self.players]
        # Send 'start' to the host
        self.players[0].write_message({ 'action': 'start', 'players': names })

    def send(self, conn, msg):
        if not self.started:
            raise ClientError("the game hasn't started")

        for p in self.players:
            if p is not conn:
                p.write_message(msg)

    def send_all(self, msg):
        for p in self.players:
            p.write_message(msg)

PING_INTERVAL = 5

class CashanServer:

    def __init__(self, config):
        self.config = config
        self.epoll = None
        self.connections = {}
        self.names = {}
        self.games = {}
        self.listener = None

    def run(self):
        self.setup()

        while True:
            for fd, events in self.epoll.poll(timeout = 1):<commit_msg>Increase PING_INTERVAL to 30 seconds<commit_after>#!/usr/bin/python3
# -*- coding: utf-8

import json
import os
import select
import socket
import time

from network import *

VERSION = '0.0.1'

class Client(Connection):

    def __init__(self, conn):
        super().__init__(conn)
        self.name = None
        self.version = None
        self.current_game = None
        self.last_message = time.monotonic()
        self.last_ping = 0

class Game:

    def __init__(self, name, host, num_players):
        self.name = name
        self.players = [host]
        self.num_players = num_players
        self.started = False

    def empty(self):
        if self.started:
            return all(p is None for p in self.players)
        else:
            return len(self.players) == 0

    def ready(self):
        return len(self.players) == self.num_players and \
            all(p is not None for p in self.players)

    def join(self, conn):
        if self.started:
            raise ClientError('game has already started')
        else:
            self.send_all({ 'action': 'join', 'name': conn.name })
            self.players.append(conn)

    def leave(self, conn):
        self.players.remove(conn)
        self.send_all({ 'action': 'leave', 'name': conn.name })

    def rejoin(self, conn):
        raise NotImplementedError

    def start(self):
        self.started = True
        names = [p.name for p in self.players]
        # Send 'start' to the host
        self.players[0].write_message({ 'action': 'start', 'players': names })

    def send(self, conn, msg):
        if not self.started:
            raise ClientError("the game hasn't started")

        for p in self.players:
            if p is not conn:
                p.write_message(msg)

    def send_all(self, msg):
        for p in self.players:
            p.write_message(msg)

PING_INTERVAL = 30

class CashanServer:

    def __init__(self, config):
        self.config = config
        self.epoll = None
        self.connections = {}
        self.names = {}
        self.games = {}
        self.listener = None

    def run(self):
        self.setup()

        while True:
            for fd, events in self.epoll.poll(timeout = 1):
{'fraction_non_alphanumeric': 0.10929705215419501, 'fraction_numerical': 0.005215419501133787, 'mean_word_length': 1.9623908663532572, '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': '1150981', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1321, 'n_words': 377}