MCPcopy Create free account
hub / github.com/battlecode/battlecode-2018 / start_server

Function start_server

battlecode-manager/server.py:670–713  ·  view source on GitHub ↗

Start a socket server for the players to connect to Args: sock_file: This is a string name of the file that will be used for as UnixStream game: The game information that is being run use_docker bool: whether to use docker or not Return:

(sock_file: str, game: Game, dockers, use_docker=True)

Source from the content-addressed store, hash-verified

668
669
670def start_server(sock_file: str, game: Game, dockers, use_docker=True) -> socketserver.BaseServer:
671 '''
672 Start a socket server for the players to connect to
673 Args:
674 sock_file: This is a string name of the file that will be used for
675 as UnixStream
676
677 game: The game information that is being run
678
679 use_docker bool: whether to use docker or not
680
681 Return:
682 server_thread: The connection so it can be closed by parent functions at
683 the appropriate time
684 '''
685
686 # Create handler for mangaing each connections to server
687 receive_handler = create_receive_handler(game, dockers, use_docker, True)
688
689 if isinstance(sock_file, tuple):
690 # tcp port
691 server = socketserver.ThreadingTCPServer(sock_file, receive_handler)
692 else:
693 server = socketserver.ThreadingUnixStreamServer(sock_file, receive_handler)
694
695 def wait_for_connections():
696 time.sleep(BUILD_TIMEOUT)
697 for player in game.players:
698 if not player['built_successfully']:
699 print('Player failed to connect to manager after',BUILD_TIMEOUT,'seconds:', player['player'])
700 if bc.Team.Red == player['player'].team:
701 game.winner = 'player2'
702 else:
703 game.winner = 'player1'
704 game.disconnected = True
705 game.game_over = True
706
707 server_thread = threading.Thread(target=server.serve_forever, daemon=True)
708 logging.info("Server Started at %s", sock_file)
709 server_thread.start()
710 waiter_thread = threading.Thread(target=wait_for_connections, daemon=True)
711 waiter_thread.start()
712
713 return server
714
715def start_viewer_server(port: int, game: Game) -> socketserver.BaseServer:
716 '''

Callers

nothing calls this directly

Calls 2

create_receive_handlerFunction · 0.85
startMethod · 0.45

Tested by

no test coverage detected