Пример #1
0
    def end_game(cls, tag):
        '''
        End a game, stop udp clients.  
        '''
        user1, user2 = cls.games[tag].keys()

        # update DataBase
        if cls.games[tag][user1] == 'win':
            DataBase.increment_wins(user1)
        else:
            DataBase.increment_loss(user1)

        if cls.games[tag][user2] == 'win':
            DataBase.increment_wins(user2)
        else:
            DataBase.increment_loss(user2)

        # update udp clients
        ip1 = cls.clients[user1].ip
        ip2 = cls.clients[user2].ip

        cls.queue.put(['unlink', ip1, ip2])

        cls.games.pop(tag)
Пример #2
0
    def on_disconnect(self, content=None):
        '''
        Executed on disconnection, to have a clean disconnection
        '''
        self.logged = False
        self.print("Disconnected.")

        if self.username is None:
            return

        # inform friends
        Interaction.send_connection_state(self.username, False)

        # remove from Interaction
        Interaction.remove(self.username)

        # if in game -> inform opponent that is leaving
        if not self.game_tag is None:
            Interaction.send(self.opponent, Message('olg', True))

            # count game as a loss
            DataBase.increment_loss(self.username)

        self.username = None