コード例 #1
0
ファイル: game.py プロジェクト: backfrip/LesMUD
 def __init__(self, host, port, debug=False):
     self.actionable = []
     self.avatars = []
     self.connections = []
     
     connect.ThreadedTCPServer.allow_reuse_address = debug
     if debug:
         logging.debug("Server allow_reuse_address is active for debugging purposes!")
     
     self.server = connect.ThreadedTCPServer(
         self, (host, port), connect.ThreadedTCPRequestHandler)
     self.server_thread = connect.make_target_thread(
         self.server.serve_forever)
コード例 #2
0
ファイル: main.py プロジェクト: backfrip/LesMUD
    parser.add_argument('--debug', action='store_true',
        help='run the game in debug mode')
    args = parser.parse_args()
    
    config = configparser.ConfigParser()
    
    logging.basicConfig(level=('DEBUG' if args.debug else 'INFO'))
    
    data_dir = os.path.join(os.path.dirname(__file__), args.data_dir)
    logging.info('Using "{}" for data loading/saving.'.format(data_dir))
    stdin, input_thread = connect.make_queue_thread(sys.stdin)
    
    commands = defaultdict(command_unrecognized)
    for k, v in [('stop', break_loop), ('exit', break_loop)]:
        commands[k] = v
    
    game_server = game.GameServer('0.0.0.0', 26101, debug=args.debug)
    game_server_thread = connect.make_target_thread(target=game_server.run)
    try:
        while game_server_thread.is_alive():
            line = stdin.readline()
            if line:
                line = list(shlex.shlex(line, posix=True))
                if commands[line[0]]():
                    break
    except KeyboardInterrupt:
        print()
    game_server.stop()
    
    logging.info("Exiting...")