def del_friend(self, username): # update data other_index = Data.users[Data.users['username'] == username].index[0] Data.users.loc[self.index, 'friends'].remove(other_index) Data.users.loc[other_index, 'friends'].remove(self.index) if Interaction.is_connected(username): other_client = Interaction.get_client(username) send(other_client.conn, f'delfr|{self.username}')
def create_env(self, username): # check other is conn if Interaction.is_connected(username): other_client = Interaction.get_client(username) self.env = Env((self, other_client), (self.username, other_client.username)) other_client.env = self.env Interaction.inform_inenv(other_client.username) other_client.in_env = True self.in_env = True
def check_env_rinv(self, username): # check other is conn if Interaction.is_connected(username): other_client = Interaction.get_client(username) # check if other client is already in env if other_client.in_env: other_client.env.add_client(self) self.in_env = True self.env = other_client.env else: self.create_env(username) Interaction.inform_inenv(self.username)
def add_friend(self, username): other_index = Data.users[Data.users['username'] == username].index[0] # add friend to data Data.users.loc[self.index, 'friends'].append(other_index) Data.users.loc[other_index, 'friends'].append(self.index) # remove other from demands Data.users.loc[self.index, 'demands'].remove(other_index) store_user_data() Interaction.manage_friends(self) # if other is connected, update his friends if Interaction.is_connected(username): other_client = Interaction.get_client(username) Interaction.manage_friends(other_client)
def quit(self, username): client = Interaction.get_client(username) # update client attributes client.in_env = False client.env = None send(client.conn, f'env|stop') # send to friends: out env Interaction.inform_outenv(client.username) # update env attributes self.clients.remove(client) self.usernames.remove(username) self.n_clients -= 1 # check if there is still someone if self.n_clients == 0: self.active = False else: # inform other user in env for client in self.clients: send(client.conn, f'env|quit|{username}')
def invite_friend(self, username): # check if friend is conn if Interaction.is_connected(username): other_client = Interaction.get_client(username) send(other_client.conn, f'inv|{self.username}')