This is the handler for socket connections from players
(self)
| 507 | return message |
| 508 | |
| 509 | def player_handler(self): |
| 510 | ''' |
| 511 | This is the handler for socket connections from players |
| 512 | ''' |
| 513 | self.logged_in = False |
| 514 | logging.debug("Client connected to server") |
| 515 | self.request.settimeout(TIMEOUT) |
| 516 | |
| 517 | TIMEDOUTLOG = False |
| 518 | |
| 519 | # Handle Login phase |
| 520 | while not self.logged_in and not self.game.game_over: |
| 521 | # do the json parsing ourself instead of handing it off to rust |
| 522 | unpacked_data = json.loads(self.get_next_message()) |
| 523 | |
| 524 | verify_out = self.game.verify_login(unpacked_data) |
| 525 | |
| 526 | self.error = "" |
| 527 | if not isinstance(verify_out, int): |
| 528 | self.error = verify_out |
| 529 | logging.warning("Client failed to log in error: %s", |
| 530 | self.client_id) |
| 531 | else: |
| 532 | logging.info("Client %s: logged in succesfully", self.client_id) |
| 533 | self.logged_in = True |
| 534 | self.client_id = verify_out |
| 535 | self.game.player_connected(self.client_id) |
| 536 | self.game.get_player(self.client_id)['built_successfully'] = True |
| 537 | |
| 538 | log_success = self.message("") |
| 539 | |
| 540 | self.send_message(log_success) |
| 541 | |
| 542 | if self.game.game_over: |
| 543 | return |
| 544 | |
| 545 | logging.debug("Client %s: Spinning waiting for game to start", |
| 546 | self.client_id) |
| 547 | |
| 548 | while not self.game.started and not self.game.game_over: |
| 549 | # Spin while waiting for game to start |
| 550 | time.sleep(0.05) |
| 551 | |
| 552 | logging.info("Client %s: Game started", self.client_id) |
| 553 | |
| 554 | my_sandbox = dockers[self.client_id] |
| 555 | running_stats = self.game.get_player(self.client_id)['running_stats'] |
| 556 | |
| 557 | # average time used, in seconds |
| 558 | atu = 0 |
| 559 | |
| 560 | while self.game.started and not self.game.game_over: |
| 561 | # This is the loop that the code will always remain in |
| 562 | # Blocks until it this clients turn |
| 563 | if not self.game.start_turn(self.client_id): |
| 564 | self.request.close() |
| 565 | return |
| 566 |
no test coverage detected