Exemple #1
0
class Callback(Signal):
    """
	A callback signal is an double signal. Once for the GBX Callback itself (the Gbx callback named). And the destination
	Between those two signals is a sort of `processor` that confirms it into the PyPlanet style objects.

	For example, a player connect will result in a player database object instead of the plain Maniaplanet payload.
	This will make it possible to develop your app as fast as possible, without any overhead and make it better
	with callback payload changes!
	"""
    def __init__(self, call, namespace, code, target=None):
        """
		Shortcut for registering two signals, one is the raw signal and the second one is the parsed and structured
		output signal. This also glues the two together.

		:param call:
		:param namespace:
		:param code:
		:param target:
		"""
        # Initiate destination signal (ourself).
        super().__init__(code=code, namespace=namespace, process_target=target)

        # Initiate raw signal, the raw gbx/script callback.
        self.raw_signal = Signal(code=call, namespace='raw')
        self.raw_signal.register(self.glue, weak=False)

        SignalManager.register_signal(self.raw_signal, app=None, callback=True)
        SignalManager.register_signal(self, app=None)

    async def glue(self, signal, source, **kwargs):
        """
		The glue method converts the source signal (gbx callback) into the pyplanet signal.
		"""
        return await self.send_robust(source)
Exemple #2
0
    async def test_registering(self):
        instance = Controller.prepare(name='default').instance

        test1 = Signal(code='test1', namespace='tests')
        instance.signals.register_signal(test1)
        test2 = Signal(code='test2', namespace='tests')
        instance.signals.register_signal(test2)

        test1_comp = instance.signals.get_signal('tests:test1')
        test2_comp = instance.signals.get_signal('tests:test2')

        assert test1 == test1_comp
        assert test2 == test2_comp
Exemple #3
0
    async def test_app_manager(self):
        instance = Controller.prepare(name='default').instance
        manager = instance.signals.create_app_manager(None)

        test1 = Signal(code='test1',
                       namespace='tests',
                       process_target=self.glue)
        manager.register_signal(test1)

        self.got_sync = 0
        self.got_async = 0
        self.got_glue = 0
        self.got_raw = 0

        manager.listen(test1, self.sync_listener)
        manager.listen(test1, self.async_listener)

        await test1.send(dict(glue=False))

        await manager.on_destroy()

        # This one will be ignored because the app is destroyed.
        await test1.send(dict(glue=False), raw=True)

        assert self.got_sync == 1
        assert self.got_async == 1
Exemple #4
0
    def __init__(self, call, namespace, code, target=None):
        """
		Shortcut for registering two signals, one is the raw signal and the second one is the parsed and structured
		output signal. This also glues the two together.

		:param call:
		:param namespace:
		:param code:
		:param target:
		"""
        # Initiate destination signal (ourself).
        super().__init__(code=code, namespace=namespace, process_target=target)

        # Initiate raw signal, the raw gbx/script callback.
        self.raw_signal = Signal(code=call, namespace='raw')
        self.raw_signal.register(self.glue, weak=False)

        SignalManager.register_signal(self.raw_signal, app=None, callback=True)
        SignalManager.register_signal(self, app=None)
Exemple #5
0
    async def test_listening(self):
        instance = Controller.prepare(name='default').instance

        test1 = Signal(code='test1',
                       namespace='tests',
                       process_target=self.glue)
        instance.signals.register_signal(test1)

        self.got_sync = 0
        self.got_async = 0
        self.got_glue = 0
        self.got_raw = 0

        test1.register(self.sync_listener)
        test1.register(self.async_listener)

        await test1.send(dict(glue=False), raw=True)
        await test1.send(dict(glue=False), raw=False)
        await test1.send_robust(dict(glue=False), raw=True)
        await test1.send_robust(dict(glue=False), raw=False)

        assert self.got_async == 4
        assert self.got_sync == 4
        assert self.got_glue == 2
        assert self.got_raw == 4
Exemple #6
0
	Vote has been updated.
:Code:
	``maniaplanet:vote_updated``
:Description:
	Callback sent when a call vote has been updated.
:Original Callback:
	`Native` Maniaplanet.VoteUpdated

:param player: Player instance
:param state: State name
:param cmd_name: Command name
:param cmd_param: Parameter given with command.
:type player: pyplanet.apps.core.maniaplanet.models.player.Player
"""

server_chat = Signal(namespace='maniaplanet', code='server_chat')
"""
:Signal:
	Server send a chat message.
:Code:
	``maniaplanet:server_chat``
:Description:
	Custom signal called when the server outputs a message.
:Origin Callback:
	None (via Chat callback).
"""

server_password = Signal(namespace='maniaplanet', code='server_password')
"""
:Signal:
	Server player or spectator password changed
Exemple #7
0
:Original Callback:
	`Script` Trackmania.Scores

:param players: Player score payload. Including player instance etc.
:param teams: Team score payload.
:param winner_team: The winning team.
:param use_teams: Use teams.
:param winner_player: The winning player.
:param section: Section, current progress of match. Important to check before you save results!!
:type players: list
:type teams: list
"""


finish = Signal(
	namespace='trackmania',
	code='finish',
)
"""
:Signal:
	Player finishes a lap or the race.
:Code:
	``trackmania:finish``
:Description:
	Player finishes a lap or the complete race. Custom signal!.
:Original Callback:
	*None*

:param player: Player instance.
:param race_time: Time in milliseconds of the complete race.
:param lap_time: Time in milliseconds of the current lap.
:param cps: Deprecated!
Exemple #8
0
:param force_spectator: 1, 2 or 3. Force spectator state
:param is_referee: Is the player a referee.
:param is_podium_ready: Is the player podium ready.
:param is_using_stereoscopy: Is the player using stereoscopy
:param is_managed_by_other_server: Is the player managed by another server (relaying).
:param is_server: Is the player one of the servers.
:param has_player_slot: Has the player a reserved player slot.
:param is_broadcasting: Is the player broadcasting (steaming) via the in-game stream functionality.
:param has_joined_game: Is the player ready and has it joined the game as player.
:type force_spectator: int
:type player: pyplanet.apps.core.maniaplanet.models.player.Player
:type target: pyplanet.apps.core.maniaplanet.models.player.Player
"""

player_enter_player_slot = Signal(
    namespace='maniaplanet',
    code='player_enter_player_slot',
)
"""
:Signal: 
	Player enters a player slot.
:Code:
	``maniaplanet:player_enter_player_slot``
:Description:
	Player change into a player, is using a player slot.
:Original Callback:
	*None*

:param player: Player instance.
:type player: pyplanet.apps.core.maniaplanet.models.player.Player
"""
Exemple #9
0
	Teams and players scores.
:Original Callback:
	`Script` Trackmania.Scores

:param players: Player score payload. Including player instance etc.
:param teams: Team score payload.
:param winner_team: The winning team.
:param use_teams: Use teams.
:param winner_player: The winning player.
:param section: Section, current progress of match. Important to check before you save results!!
:type players: list
:type teams: list
"""

finish = Signal(
    namespace='trackmania',
    code='finish',
)
"""
:Signal:
	Player finishes a lap or the race.
:Code:
	``trackmania:finish``
:Description:
	Player finishes a lap or the complete race. Custom signal!.
:Original Callback:
	*None*

:param player: Player instance.
:param race_time: Time in milliseconds of the complete race.
:param lap_time: Time in milliseconds of the current lap.
:param cps: Deprecated!
Exemple #10
0
	Vote has been updated.
:Code:
	``maniaplanet:vote_updated``
:Description:
	Callback sent when a call vote has been updated.
:Original Callback:
	`Native` Maniaplanet.VoteUpdated

:param player: Player instance
:param state: State name
:param cmd_name: Command name
:param cmd_param: Parameter given with command.
:type player: pyplanet.apps.core.maniaplanet.models.player.Player
"""

server_chat = Signal(namespace='maniaplanet', code='server_chat')
"""
:Signal:
	Server send a chat message.
:Code:
	``maniaplanet:server_chat``
:Description:
	Custom signal called when the server outputs a message.
:Origin Callback:
	None (via Chat callback).
"""

channel_progression_start = Callback(
    call='Script.ManiaPlanet.ChannelProgression_Start',
    namespace='maniaplanet',
    code='channel_progression_start',