Example #1
0
	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()
Example #2
0
    def __init__(self, *args, **kwargs):
        self.core = CoreProtocol(self)
        self.ticker = self.ticker_type(self.logger)

        super(ProxyBridge, self).__init__(*args, **kwargs)

        self.setup()
Example #3
0
    def __init__(self, *args, **kwargs):
        self.core = CoreProtocol(self)
        self.disconnect_message = None

        super(UpstreamProtocol, self).__init__(*args, **kwargs)

        self.bots = UpstreamBots(self)
        self._setup()
Example #4
0
class DownstreamProtocol(Downstream):
	from core.downstream.packets import packet_received, log_packet
	
	def __init__(self, *args, **kwargs):
		self.core = CoreProtocol(self)
		self._uuid = UUID.random()
		self.real_uuid = None
		
		super(DownstreamProtocol, self).__init__(*args, **kwargs)
	
	def setup(self):
		super(DownstreamProtocol, self).setup()
		self.core.load_plugins(get_plugins())
		self.core.on_ready_plugins()
		return
		
	def connection_lost(self, reason=None):
		super(ServerProtocol, self).connection_lost(reason)
		if self.protocol_mode in ("login", "play"):
			self.factory.players.discard(self)
			
		self.bridge.downstream_disconnected()
		self.core.unload_plugins()
		return
	
	def player_joined(self):
		self.real_uuid = self.uuid
		self.uuid = self._uuid
		
		super(DownstreamProtocol, self).player_joined()
		self.core.on_join_plugins()
		return

	def player_left(self):
		super(DownstreamProtocol, self).player_left()
		self.core.on_leave_plugins()
		return
	
	def super_handle_packet(self, buff, name):
		super(DownstreamProtocol, self).packet_received(buff, name)
Example #5
0
class PseudoProtocol(UpstreamProtocol):
	# replaces all connection details with pseudo info
	# noinspection PyMissingConstructor,PyUnusedLocal,PyUnusedLocal
	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()
	
	def setup(self):
		super(PseudoProtocol, self)._setup()
		super(PseudoProtocol, self).player_joined()
		return
	
	# noinspection PyArgumentList
	def player_joined(self):
		super(ClientProtocol, self).player_joined()
		self.core.on_join_plugins()
		
		if self.factory.protocol_callback:
			try:
				self.factory.protocol_callback(self)
			except Exception as e:
				print("Error in protocol callback", e)
		
		for bridge in self.factory.bridges:
			self.setup_bridge(bridge)
		return

	def packet_received(self, buff, name):
		buff.save()
		for bridge in self.factory.bridges:
			bridge.packet_received(buff, self.recv_direction, name)
			buff.restore()
		buff.discard()
		return
	
	# discards all packets that would normally be forwarded
	def send_packet(self, name, *data):
		pass
	
	
	def player_left(self):
		pass
Example #6
0
class UpstreamProtocol(ClientProtocol):
    from core.upstream.bridges import setup_bridge, add_forwarding_bridge, remove_forwarding_bridge
    from core.upstream.packets import log_packet, packet_received

    def __init__(self, *args, **kwargs):
        self.core = CoreProtocol(self)
        self.disconnect_message = None

        super(UpstreamProtocol, self).__init__(*args, **kwargs)

        self.bots = UpstreamBots(self)
        self._setup()

    def setup(self):
        pass

    # using a different setup so it can be called after init
    def _setup(self):
        self.core.load_plugins(get_plugins())
        self.core.on_ready_plugins()

        self.bots.load_bots()
        self.bots.on_ready_bots()

    def player_joined(self):
        super(UpstreamProtocol, self).player_joined()

        self.factory.account_manager.sessions.add_session(self)
        self.core.on_join_plugins()
        self.bots.on_join_bots()

        self.bots.update_bots()

        if self.factory.protocol_callback:
            try:
                self.factory.protocol_callback(self)
            except Exception as e:
                print("Error in protocol callback", e)

        for bridge in self.factory.bridges:
            # noinspection PyArgumentList
            self.setup_bridge(bridge)

    def player_left(self):
        super(UpstreamProtocol, self).player_left()

        self.factory.account_manager.sessions.remove_session(self)

        self.bots.on_leave_bots()
        self.bots.unload_bots()

        self.core.on_leave_plugins()
        self.core.unload_plugins()

    def close(self, reason=None):
        if not self.in_game and self.factory.protocol_callback:
            try:
                self.factory.protocol_callback(self)
            except Exception as e:
                print("Error in protocol callback", e)

        for bridge in self.factory.bridges:
            # noinspection PyArgumentList
            self.remove_forwarding_bridge(bridge)
            bridge.upstream_disconnected()

        super(UpstreamProtocol, self).close(reason)
        del self

    def packet_login_disconnect(self, buff):
        buff.save()
        self.disconnect_message = buff.unpack_chat()
        buff.restore()
        super(UpstreamProtocol, self).packet_login_disconnect(buff)

    def packet_disconnect(self, buff):
        buff.save()
        self.disconnect_message = buff.unpack_chat()
        buff.restore()
        super(UpstreamProtocol, self).packet_disconnect(buff)

    def super_handle_packet(self, buff, name):
        super(UpstreamProtocol, self).packet_received(buff, name)
Example #7
0
class ProxyBridge(HotBridge):
    ticker_type = Ticker

    from core.bridge.proxy.packets import packet_received

    def __init__(self, *args, **kwargs):
        self.core = CoreProtocol(self)
        self.ticker = self.ticker_type(self.logger)

        super(ProxyBridge, self).__init__(*args, **kwargs)

        self.setup()

    def setup(self):
        self.core.load_plugins(get_plugins())
        self.core.on_ready_plugins()

        self.ticker.start()
        return

    def downstream_disconnected(self, *args, **kwargs):
        self.core.on_leave_plugins()
        self.core.unload_plugins()

        super(ProxyBridge, self).downstream_disconnected(*args, **kwargs)
        return

    def switch_protocol(self, *args, **kwargs):
        self.core.on_leave_plugins()
        super(ProxyBridge, self).switch_protocol(*args, **kwargs)
        self.core.on_join_plugins()
        return

    def super_handle_packet(self, buff, direction, name):
        super(ProxyBridge, self).packet_received(buff, direction, name)
        return
Example #8
0
	def __init__(self, *args, **kwargs):
		self.core = CoreProtocol(self)
		self._uuid = UUID.random()
		self.real_uuid = None
		
		super(DownstreamProtocol, self).__init__(*args, **kwargs)