def __init__(self): self.config = ConfigController.instance().data self.accounts = Accounts() self.sessions = Sessions() self.setup()
def __init__(self, factory, *args, **kwargs): self.config = ConfigController.instance().data self.core = CoreProtocol(self) self.factory = factory self.buff_type = self.factory.get_buff_type(self.config["version"]) self.recv_buff = self.buff_type() self.cipher = Cipher() self.logger = logging.getLogger("%s{%s}" % ( self.__class__.__name__, "pseudo host")) self.logger.setLevel(self.factory.log_level) self.ticker = self.factory.ticker_type(self.logger) self.ticker.start() self.bots = UpstreamBots(self) def no_bots(): return [] self.bots.get_bots = no_bots self.setup()
class HotBridge(Bridge): forwarding = None joined_game = None config = ConfigController.instance().data upstream_controller = UpstreamController.instance() log_level = config["bridge"]["log_level"] from core.bridge.hot.connection import connect, downstream_disconnected, upstream_disconnected from core.bridge.hot.forwarding import enable_fast_forwarding, enable_forwarding, disable_forwarding from core.bridge.hot.packets import packet_received, packet_unhandled, mirror_packet from core.bridge.hot.protocols import default_factory_settings, switch_protocol, send_to_the_void def __init__(self, *args, **kwargs): self.forwarding = False self.joined_game = False self.switching_protocol = False super(HotBridge, self).__init__(*args, **kwargs) def make_profile(self): raise Exception( "make_profile is not available for hot swappable bridges") # noinspection PyArgumentList def upstream_ready(self): self.logger.debug("Upstream ready") self.enable_forwarding()
def __init__(self, bridge, ticker): self.bridge = bridge self.ticker = ticker self.config = ConfigController.instance().data self.upstream_controller = UpstreamController.instance() self.buff_type = self.bridge.downstream.factory.get_buff_type( self.config["version"]) self.logger = logging.getLogger( "Plugin %s (%s)" % (self.__class__.__name__, self.bridge.__class__.__name__)) self.logger.setLevel(self.config["plugins"]["log_level"]) self.setup()
class UpstreamFactory(ClientFactory, ReconnectingClientFactory): config = ConfigController.instance().data protocol = UpstreamProtocol account_manager = None protocol_callback = None connection_timeout = 5 force_protocol_version = config["version"] log_level = config["client"]["log_level"] def __init__(self, *args, **kwargs): self.bridges = [] self.controlling_bridges = [] self.player_username = None super(UpstreamFactory, self).__init__(*args, **kwargs) def add_bridge(self, bridge): self.bridges.append(bridge) return def remove_bridge(self, bridge): while bridge in self.bridges: self.bridges.remove(bridge) return def request_control(self, bridge): if bridge in self.controlling_bridges: return True self.controlling_bridges.append(bridge) return True def remove_control(self, bridge): while bridge in self.controlling_bridges: self.controlling_bridges.remove(bridge) return def check_permission(self, bridge): return bridge in self.controlling_bridges
def main(): # initializes the config controller and returns the data config = ConfigController.instance().data # Initializes the upstream controller UpstreamController.instance() # Create factory factory = DownstreamFactory() factory.bridge_class = ProxyBridge # get connection details from config host = config["server"]["host"] port = config["server"]["port"] # starts the downstream server factory.listen(host, port) return
class DownstreamFactory(_DownstreamFactory): config = ConfigController.instance().data protocol = DownstreamProtocol log_level = config["server"]["log_level"] online_mode = config["server"]["online"]
class Plugin: protocol = None ticker = None config = ConfigController.instance().data def __init__(self, protocol, ticker): self.protocol = protocol self.ticker = ticker self.buff_type = self.protocol.buff_type self.logger = logging.getLogger( "Plugin %s (%s)" % (self.__class__.__name__, self.protocol.__class__.__name__)) self.logger.setLevel(self.config["plugins"]["log_level"]) self.setup() # return with false to emulate mirroring # # return types # continue - act as a mirror # finish - let plugins finish but dont go after that # break - no more plugins will be looped def handle_packet(self, method_pointer, buff): handler = getattr(self, method_pointer, None) if handler: try: handled = handler(buff) assert len(buff) == 0, "Packet too long: %s" % method_pointer except Exception as e: print("plugin error", method_pointer, e) handled = "continue" if handled == "finish": return "finish" elif handled == "break": return "break" return "continue" # callbacks # called right after plugin is constructed def setup(self): self.logger.debug("setting up") return # called after all plugins are initialized def on_ready(self): return # when the protocol "despawns" def on_unload(self): return # when the protocol join the game def on_join(self): return # when the protocol leaves the game def on_leave(self): return