This function verifies the login and then logins in the player code. Adds them to the game state Args: data: A socket that we received data from the client on Return: Boolean if login was successful
(self, unpacked_data: str)
| 163 | return total |
| 164 | |
| 165 | def verify_login(self, unpacked_data: str): |
| 166 | ''' |
| 167 | This function verifies the login and then logins in the player code. |
| 168 | Adds them to the game state |
| 169 | |
| 170 | Args: |
| 171 | data: A socket that we received data from the client on |
| 172 | Return: |
| 173 | Boolean if login was successful |
| 174 | ''' |
| 175 | |
| 176 | client_id = int(unpacked_data['client_id']) |
| 177 | |
| 178 | # Check if they are in our list of clients |
| 179 | if client_id not in [player['id'] for player in self.players]: |
| 180 | return "Client id Mismatch" |
| 181 | |
| 182 | # Check if they logged in already |
| 183 | if self.player_logged[client_id]: |
| 184 | return "Already Logged In" |
| 185 | |
| 186 | self.player_logged[client_id] = True |
| 187 | |
| 188 | # Check if all the players are logged in and then start the game |
| 189 | logging.info("Player logged in: %s", self.player_logged) |
| 190 | if len(self.players) == self.num_log_in: |
| 191 | self.start_game() |
| 192 | return client_id |
| 193 | |
| 194 | def set_player_turn(self, player_index): |
| 195 | self.current_player_index = player_index |
no test coverage detected