예제 #1
0
class WaterfallHandler(BungeecordHandler):
	# The logging format of waterfall server is paper like
	# [02:18:30 INFO]: Enabled plugin cmd_list version git:cmd_list:1.15-SNAPSHOT:f1c32f8:1489 by SpigotMC
	# [02:18:29 INFO] [ViaVersion]: Loading 1.12.2 -> 1.13 mappings..."

	FORMATTERS = [
		BukkitHandler.get_content_parsing_formatter(),
		'[{hour:d}:{min:d}:{sec:d} {logging}] {why_this}: {content}'
	]

	def parse_server_stdout(self, text):
		result = self._get_server_stdout_raw_result(text)
		for formatter in self.FORMATTERS:
			try:
				self._content_parse(result, formatter=formatter)
				return result
			except:
				pass
		raise ValueError()

	def parse_player_joined(self, info: Info) -> Optional[str]:
		# [02:18:52 INFO]: [/127.0.0.1:14426] <-> InitialHandler has connected
		# sadly no player id display here
		return None

	def parse_player_left(self, info):
		# [/127.0.0.1:14426|Fallen_Breath] -> UpstreamBridge has disconnected
		if not info.is_user:
			parsed = parse('[/{ip}|{name}] -> UpstreamBridge has disconnected', info.content)
			if parsed is not None:
				return parsed['name']
		return None
예제 #2
0
	def get_content_parsing_formatter(cls):
		return (
			BukkitHandler.get_content_parsing_formatter(),
			'[{hour:d}:{min:d}:{sec:d} {logging}] {dummy}: {content}'  # somethings there is an extra element after the heading [] and :
		)
 def __init__(self, *args):
     super().__init__(*args)
     self.handler = BukkitHandler()
class MyTestCase(unittest.TestCase):
    def __init__(self, *args):
        super().__init__(*args)
        self.handler = BukkitHandler()

    def test_0_general(self):
        self.assertEqual(self.handler.get_name(), 'bukkit_handler')
        info = self.handler.parse_server_stdout(
            '[00:11:34 INFO]: Found new data pack file/bukkit, loading it automatically'
        )
        self.assertEqual(0, info.hour)
        self.assertEqual(11, info.min)
        self.assertEqual(34, info.sec)
        self.assertEqual('INFO', info.logging_level)
        self.assertEqual(
            'Found new data pack file/bukkit, loading it automatically',
            info.content)

        info = self.handler.parse_server_stdout(
            '[00:11:37 INFO]: ---- Migration of old nether folder complete ----'
        )
        self.assertEqual(0, info.hour)
        self.assertEqual(11, info.min)
        self.assertEqual(37, info.sec)
        self.assertEqual('INFO', info.logging_level)
        self.assertEqual('---- Migration of old nether folder complete ----',
                         info.content)

        self.assertRaises(
            Exception, self.handler.parse_server_stdout,
            '[16:56:48] [main/INFO]: Loaded 0 advancements')  # vanilla thing

    def test_1_player(self):
        info = self.handler.parse_server_stdout(
            '[00:12:10 INFO]: <Fallen_Breath> test')
        self.assertEqual('Fallen_Breath', info.player)
        self.assertEqual('test', info.content)
        info = self.handler.parse_server_stdout(
            '[09:00:04 INFO]: [world_nether]<Alex> hello')
        self.assertEqual('Alex', info.player)
        self.assertEqual('hello', info.content)

    def test_2_player_events(self):
        info = self.handler.parse_server_stdout(
            '[00:11:54 INFO]: Fallen_Breath[/127.0.0.1:11115] logged in with entity id 665 at ([world]124.37274191311167, 279.4052172954894, 141.89424426399407)'
        )
        self.assertEqual('Fallen_Breath',
                         self.handler.parse_player_joined(info))

        info = self.handler.parse_server_stdout(
            '[00:12:25 INFO]: Fallen_Breath left the game')
        self.assertEqual('Fallen_Breath', self.handler.parse_player_left(info))

    def test_3_server_info(self):
        info = self.handler.parse_server_stdout(
            '[00:11:21 INFO]: Starting minecraft server version 1.13.2')
        self.assertEqual('1.13.2', self.handler.parse_server_version(info))
        info = self.handler.parse_server_stdout(
            '[00:11:22 INFO]: Starting Minecraft server on *:25565')
        self.assertEqual(('*', 25565), self.handler.parse_server_address(info))

    def test_4_server_events(self):
        info = self.handler.parse_server_stdout(
            '[00:11:46 INFO]: Done (12.080s)! For help, type "help"')
        self.assertEqual(True, self.handler.test_server_startup_done(info))
        info = self.handler.parse_server_stdout(
            '[00:11:46 INFO]: RCON running on 0.0.0.0:25575')
        self.assertEqual(True, self.handler.test_rcon_started(info))
        info = self.handler.parse_server_stdout(
            '[00:12:27 INFO]: Stopping server')
        self.assertEqual(True, self.handler.test_server_stopping(info))

    def test_5_lifecycle(self):
        for line in TEXT.splitlines():
            info = self.handler.parse_server_stdout(line)
            # no exception
            if not info.is_player:
                self.assertEqual(line.split(']: ', 1)[1], info.content)
            self.assertIn(info.logging_level, {'INFO', 'WARN'})