Ejemplo n.º 1
0
    def demand_friend(self, content):
        '''
        Manage the friend demand
        Content: target username
        '''
        is_error = False

        # check target is not user
        if content == self.username:
            is_error = True

        # check requested user exist
        if not DataBase.is_user(content):
            is_error = True

        # check not already friends
        if content in DataBase.get_friends(self.username):
            is_error = True

        if is_error:
            # send error in friend demand
            self.send(Message('rdfr', False), pickling=True)
            return

        DataBase.add_friend_demand(content, self.username)

        # check if requested user is connected
        if Interaction.is_user(content):
            Interaction.send_demand_friend(content, self.username)

        # send friend demand is ok
        self.send(Message('rdfr', True), pickling=True)
Ejemplo n.º 2
0
    def send_connection_state(cls, username, state):
        '''
        Send to every friend of user his state: if he's connected.
        '''
        # get friends
        friends = DataBase.get_friends(username)

        for friend in friends:
            if cls.is_user(friend):
                cls.send(friend, Message('frs', [[username, state]]))
Ejemplo n.º 3
0
    def _send_connected_friends(self):
        '''Send the status of each friend of client'''
        friends = []

        # get friends
        username_friends = DataBase.get_friends(self.username)

        for username in username_friends:

            friends.append([username, Interaction.is_user(username)])

        self.send(Message('frs', friends), pickling=True)
Ejemplo n.º 4
0
    def profil_demand(self, username):
        '''
        Get the stats of a user,  
        send stats to user
        '''
        wins = DataBase.get_wins(username)
        loss = DataBase.get_loss(username)
        ship = DataBase.get_ship(username)
        friends = DataBase.get_friends(username)
        grid = DataBase.get_ship(username)

        if self.username in friends:
            friends.remove(self.username)

        msg = Message(
            'rpd', {
                'username': username,
                'wins': wins,
                'loss': loss,
                'friends': friends,
                'grid': grid
            })

        self.send(msg, pickling=True)