def main(args): # Parse options import optparse parser = optparse.OptionParser( usage="usage: %prog <connect-host> <connect-port> " "<username> <password>") (options, args) = parser.parse_args(args) if len(args) != 4: return parser.print_usage() host, port, username, password = args # Create profile profile = Profile() # Create factory factory = ChatLoggerFactory() factory.profile = profile # Log in and connect deferred = profile.login(username, password) deferred.addCallbacks( lambda data: factory.connect(host, int(port)), lambda err: print("login failed:", err.value)) factory.run()
def main(args): # Parse options import optparse parser = optparse.OptionParser( usage="usage: %prog client_player_list " "<connect-host> <connect-port> <username> <password>") (options, args) = parser.parse_args(args) if len(args) != 4: return parser.print_usage() host, port, username, password = args # Create profile profile = Profile() # Create factory factory = PlayerListFactory() factory.profile = profile def login_ok(data): factory.connect(host, int(port)) def login_failed(err): print "login failed:", err.value factory.stop() deferred = profile.login(username, password) deferred.addCallbacks(login_ok, login_failed) factory.run()
def main(): # Parse options import optparse parser = optparse.OptionParser( usage="usage: %prog host port username password") (options, args) = parser.parse_args() if len(args) != 4: return parser.print_usage() host, port, username, password = args # Create profile profile = Profile() # Create factory factory = PlayerListFactory() factory.profile = profile def login_ok(data): factory.connect(host, int(port)) def login_failed(err): print "login failed:", err.value factory.stop() deferred = profile.login(username, password) deferred.addCallbacks(login_ok, login_failed) factory.run()
def main(): # Parse options import optparse parser = optparse.OptionParser( usage="usage: %prog host port username password") (options, args) = parser.parse_args() if len(args) != 4: return parser.print_usage() host, port, username, password = args # Create profile profile = Profile() # Create factory factory = ChatLoggerFactory() factory.profile = profile def login_ok(data): factory.connect(host, int(port)) def login_failed(err): print "login failed:", err.value factory.stop() deferred = profile.login(username, password) deferred.addCallbacks(login_ok, login_failed) factory.run()
def main(args): # Parse options import optparse parser = optparse.OptionParser( usage="usage: %prog <connect-host> <connect-port> " "<username> <password>") (options, args) = parser.parse_args(args) if len(args) != 4: return parser.print_usage() host, port, username, password = args # Create profile profile = Profile() # Create factory factory = PlayerListFactory() factory.profile = profile # Log in and connect deferred = profile.login(username, password) deferred.addCallbacks(lambda data: factory.connect(host, int(port)), lambda err: print("login failed:", err.value)) factory.run()
def main(): if os.path.isfile(CONFIG_FILE): CONFIG.read(CONFIG_FILE) else: generate_config_file(CONFIG_FILE, CONFIG) profile = Profile() if not CONFIG['auth'].getboolean('auth'): profile.login_offline(CONFIG['auth']['username']) factory.profile = profile else: def login_ok(data): factory.connect(CONFIG['server']['ip'], int(CONFIG['server']['port'])) def login_failed(err): print('login failed:', err.value) factory.stop() sys.exit(1) factory.profile = profile deferred = profile.login(CONFIG['auth']['username'], CONFIG['auth']['password']) deferred.addCallbacks(login_ok, login_failed) factory.run()
def main(args): # Parse options import argparse parser = argparse.ArgumentParser() group = parser.add_argument_group("upstream options") group.add_argument("-c", "--connect", dest="connect", metavar="HOST[:PORT]", help="Sets the address the proxy should connect to. " "If not given, the proxy connects to the address " "requested by the user. You probably want to set " "this.") group.add_argument("-a", "--account", dest="account", metavar=("EMAIL", "PASSWORD"), nargs=2, help="Sets the minecraft account with which to log " "in. Without setting this, the proxy will not be " "capable of logging in to online-mode servers.") group = parser.add_argument_group("downstream options") group.add_argument("-l", "--listen", dest="listen", metavar="HOST[:PORT]", help="Sets the address the proxy should listen on. " "If not given, the proxy listens on port 25565 on " "all interfaces.") group.add_argument("-o", "--online-mode", dest="online_mode", action="store_true", help="If given, users connecting to the proxy are " "authenticated by the Mojang session servers, " "i.e. the server bit of the proxy is running in " "online-mode.") group.add_argument("-v", "--protocol-version", dest="protocol_version", type=int, help="Sets the protocol version that the proxy " "accepts from connecting users. If not set, the " "proxy will attempt to use whichever the user " "requests.") group = parser.add_argument_group("sniffer options") inner_group = group.add_mutually_exclusive_group() inner_group.add_argument("-p", "--packet", dest="packets", action="append", metavar=("DIRECTION", "NAME"), nargs=2, help="Adds a packet to be sniffed. " "DIRECTION should be one of: " "'up' (client --> server), " "'down' (server -> client).") inner_group.add_argument("-d", "--direction", dest="direction", choices=("up", "down"), help="Only sniff packets heading in a particular " "direction.") group.add_argument("-x", "--print-payload", dest="print_payload", action="store_true", help="Prints a hexdump with attempted ASCII " "interpretation of the payload of sniffed " "packets") group.add_argument("-y", "--dump-payload", dest="dump_payload", metavar="DEST_PATH", help="Dumps the payload of sniffed packets to the " "specified directory") args = parser.parse_args(args) listen_host = "" listen_port = 25565 factory = PacketSnifferDownstreamFactory() factory.online_mode = args.online_mode factory.force_protocol_version = args.protocol_version if args.direction is not None: factory.packet_direction = args.direction + "stream" if args.packets is not None: packets = set() for direction, name in args.packets: assert direction in ('up', 'down') direction += 'stream' packets.add((direction, name)) factory.packet_whitelist = packets factory.print_payload = args.print_payload factory.dump_payload = args.dump_payload if args.listen: listen = split_host_port(args.listen) listen_host = listen[0] listen_port = int(listen[1]) if args.connect: connect = split_host_port(args.connect) factory.connect_host = connect[0] factory.connect_port = int(connect[1]) if args.account: def login_ok(data): factory.listen(listen_host, listen_port) def login_failed(err): print "login failed:", err.value factory.stop() username, password = args.account profile = Profile() factory.upstream_factory_class.profile = profile deferred = profile.login(username, password) deferred.addCallbacks(login_ok, login_failed) else: factory.listen(listen_host, listen_port) factory.run()