Skip to main content

A Python library for utilizing the Nebulous.io UDP protocol.

Project description

nebulous.py

PyPI - Version PyPI - Python Version


Table of Contents

Installation

  1. Install git
  2. Install java-random: python -m pip install --user git+https://github.com/MostAwesomeDude/java-random
    • NOTE: This is a required step, as the java-random package on pypi is outdated and broken.
  3. Install nebulous.py: python -m pip install --user nebulous.py

Usage

Utilizing the client

From test_connect.py:

import time

from nebulous.game.account import ServerRegions
from nebulous.game.models.client import Client, ClientCallbacks
from nebulous.game.packets import ConnectRequest3, ConnectResult2, Disconnect, KeepAlive


TEST_TICKET = ""


class TestCallbacks(ClientCallbacks):
    def on_connect(self, client: Client, packet: ConnectRequest3) -> ConnectRequest3:
        print("Connected to server")
        return packet

    def on_disconnect(self, client: Client, packet: Disconnect) -> Disconnect:
        print("Disconnected from server")
        return packet

    def on_keep_alive(self, client: Client, packet: KeepAlive) -> KeepAlive:
        print("Sending keep alive packet")
        return packet

    def on_connect_result(self, client: Client, packet: ConnectResult2) -> ConnectResult2:
        print(f"Received connection result: {packet.result}")
        return packet


def test_client():
    client = Client(TEST_TICKET, ServerRegions.US_EAST, callbacks=TestCallbacks())

    client.start()

    # disconnect after 3 seconds.
    # can also use client.run_forever() to keep the client running indefinitely
    # until ctrl+c is pressed.
    time.sleep(3)

    client.stop()


if __name__ == "__main__":
    test_client()

Interacting with the API

From test_account.py:

def test_fetch_self():
    account = Account(secrets.get("TICKET", ""), ServerRegions.US_EAST)  # type: ignore
    player = account.player_obj

    if player is None:
        logger.error("Failed to fetch player object")

        return

    player_profile = player.get_profile()
    player_stats = player.get_stats()

    player_xp = player_stats.general_stats.xp

    logger.info(f"Player: {player_stats.account_name}")
    logger.info(f"Level: {xp2level(player_xp)}")
    logger.info(f"Current XP: {player_xp}")

    clan_member = player_stats.clan_member

    logger.info(f"Clan: {clan_member.clan.name}")
    logger.info(f"Role: {clan_member.clan_role}")

    logger.info(f"Account bio: {player_profile.bio}")

    # fetch friends
    logger.info("Fetching friends...")

    friends = player.get_friends()

    if len(friends) == 0:
        logger.info("No friends :(")

        return

    for friend in friends:
        friend_profile = friend.get_profile()
        friend_stats = friend.get_stats()
        friend_xp = friend_stats.general_stats.xp

        logger.info(f"Friend: {friend_stats.account_name}")
        logger.info(f"Level: {xp2level(friend_xp)}")
        logger.info(f"Current XP: {friend_xp}")
        logger.info(f"Account bio: {friend_profile.bio}")
        logger.info(f"BFF: {friend.bff}")
        logger.info(f"Last seen: {friend.last_played_utc}\n")

        logger.info("Cooldown for 1.5 seconds...")
        time.sleep(1.5)  # don't spam the API

Dumping Packets

You can also dump packets as json, as shown in sample_packet.json:

print(packet.as_json(indent=4))

License

nebulous.py is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nebulous_py-1.3.0.tar.gz (31.0 kB view details)

Uploaded Source

Built Distribution

nebulous_py-1.3.0-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file nebulous_py-1.3.0.tar.gz.

File metadata

  • Download URL: nebulous_py-1.3.0.tar.gz
  • Upload date:
  • Size: 31.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for nebulous_py-1.3.0.tar.gz
Algorithm Hash digest
SHA256 d4db1b304382b423d694ac7ffe9470020fcaee2055e076572b0e10274a23559f
MD5 a990017572b5d1674ba2cead5217f96a
BLAKE2b-256 6cc8e0232f575f48631b61480f709bf399ad0dcffba806e89b1ca23c2f62e3f2

See more details on using hashes here.

File details

Details for the file nebulous_py-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nebulous_py-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be5e6c551031475a83e40f0a5b1923b20a224cb94eddbcbd065e79f969095f34
MD5 66f39498eae6e47f8b13182dc5c83dc1
BLAKE2b-256 df82890266b25c1ac188caa1ef780ee328845f2db27f9aaa8ee248f70e85bb0f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page