Skip to main content

A re-implementation of the official community server API for BattleBit

Project description

BattleBit Community Server API

A re-implementation of the official community server API for BattleBit

Discord Stability Stage Official API Version LICENSE

ATTENTION: This project is still in Alpha. You might encounter bugs on a regular basis. If you do, please report them via the Discord server

Preamble

The goal of this project is to create an alternate, Python-implementation to the official community server API, which is written in C#. This project is still under development and can not yet be considered production-ready.

Prerequisites

  • Python 3.10 or later
  • A running, whitelisted BattleBit Server (Version 2.1.0)

Usage

As a user of this API, there are two important things to know, Handlers and Commands. More on those in the following paragraphs. Basic examples on how to use this project can be found in /src/battlebit_community_server_api/example.

Handlers

Handlers are the users way of hooking themselves onto certain events that are happening. Such as "A player joins the server" and "A player sent a chat message".

For each event, the user can register their own handler with the ApiServer.register_handler method. This method takes an OpCodes value and any Callable.

IMPORTANT: Each handler has the signature async def handler(d: bytes) -> bytes. It receives the raw TCP message as an input and returns a TCP message.

Use TcpParsingService to parse the incoming data into the datamodel objects. Use OutgoingGameServerMessage to return data. Refer to the examples for further information.

Default Handlers

If there is no Handler registered for an OP-Code, the default Handler for that event is executed. The user can also use default Handlers in their own Handler, see example/SendingCommands.py.

Implementation status of default handlers

Event Status Behavior Associated Parser (from TcpParingService)
HAIL Implemented HAIL is accepted parse_hail_message
PLAYER_CONNECTED Unneeded Event does not expect a response not implemented, but planned
PLAYER_DISCONNECTED Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_TYPED_MESSAGE Implemented Allows message via RESPOND_PLAYER_MESSAGE parse_on_player_typed_message
ON_PLAYER_KILLED_ANOTHER_PLAYER Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_JOINING Implemented Official Stats are returned via SEND_PLAYER_STATS parse_on_player_joining
SAVE_PLAYER_STATS Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_ASKING_TO_CHANGE_ROLE Implemented Allows requested role change via SetRoleTo parse_on_player_asking_to_change_role
ON_PLAYER_CHANGED_ROLE Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_JOINED_A_SQUAD Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_LEFT_SQUAD Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_CHANGED_TEAM Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_REQUESTING_TO_SPAWN Implemented Request is granted via SPAWN_PLAYER parse_on_player_requesting_to_spawn
ON_PLAYER_REPORT Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_SPAWN Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_DIE Unneeded Event does not expect a response not implemented, but planned
NOTIFY_NEW_MAP_ROTATION Unneeded Event does not expect a response not implemented, but planned
NOTIFY_NEW_GAME_MODE_ROTATION Unneeded Event does not expect a response not implemented, but planned
NOTIFY_NEW_ROUND_STATE Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_ASKING_TO_CHANGE_TEAM Implemented Allows requested team change via SetTeamTo parse_on_player_asking_to_change_team
GAME_TICK Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_GIVEN_UP Unneeded Event does not expect a response not implemented, but planned
ON_PLAYER_REVIVED_ANOTHER Unneeded Event does not expect a response not implemented, but planned
ON_SQUAD_POINTS_CHANGED Unneeded Event does not expect a response not implemented, but planned
NOTIFY_NEW_ROUND_ID Unneeded Event does not expect a response not implemented, but planned
LOG Unneeded Event does not expect a response Log will be written to logger on DEBUG level
ON_SQUAD_LEADER_CHANGED Unneeded Event does not expect a response not implemented, but planned
UPDATE_NEW_GAME_DATA Unneeded Event does not expect a response not implemented, but planned
UPDATE_CONNECTED_PLAYERS Unneeded Event does not expect a response not implemented, but planned

Commands

While Handlers are triggered on an event and respond to the server, Commands can be executed at any point.

To execute an Command, pick a Command from the Command module (for example Command.SayToChatCommand), use its initializer to prepare it, and then queue it for execution.

You can also build your own commands by using the Command base class.

To execute a command, use ApiServer.add_command_to_queue.

Predefined commands

Command Effect
ForceStartGame Starts the Round
ForceStartGame Ends the Round
SayToAllChat Sends chat message into All-Chat
SayToChat Sends chat message that is only visible to a specific player
SetRoleTo Sets the role of player
SetTeamTo Sets the team of player
SetNewPassword Sets a new password for the server
SetPingLimit Sets a new ping limit for the server
AnnounceShort Displays an announcement to all players for a short duration
AnnounceLong Displays an announcement to all players for a long duration
UILogOnServer Displays a log message on the server for a set duration
SetLoadingScreenText Sets the text that is displayed to players in the loading screen
SetRulesScreenText Sets the text that is displayed to the players in the rules screen
StopServer Stops the server
CloseServer Announces that the server will close
KickAllPlayers Kicks every player
KickPlayer Kicks specific player, optionally with a text that is displayed to the player
KillPlayer Kills specific player
SwapTeam Swaps specific player to the other team
KickFromSquad Kicks specific player from squad
JoinSquad Joins specific player into a squad
DisbandPlayerSquad Disbands a squad
PromoteSquadLeader Promotes specific player to be the squadleader of the squad he is currently in
WarnPlayer Displays warn message to player
MessageToPlayer Displays message to player (not in chat, use SayToChat if you want that)
SetPlayerHp Sets a specific player's HP
DamagePlayer Damage specific player
HealPlayer Heal specific player
SetSquadPoints Sets squadpoints for a specific squad

Contributing

The current state of development does not yet allow for productive, cooperative contribution.

Licence

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                   Version 2, December 2004

Copyright (C) 2023 David Rodenkirchen <davidr.develop@gmail.com>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

 0. You just DO WHAT THE FUCK YOU WANT TO.

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

battlebit-community-server-api-0.0.1.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

battlebit_community_server_api-0.0.1-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

Details for the file battlebit-community-server-api-0.0.1.tar.gz.

File metadata

File hashes

Hashes for battlebit-community-server-api-0.0.1.tar.gz
Algorithm Hash digest
SHA256 976228aadb6068215d935724159f2d8af589f4f77117fc37883e14e90e7256b9
MD5 155204d3612c3cfe8d5beb2302d5a83d
BLAKE2b-256 49f6e3ba0b554a4c8438d93d85e5aa15da1993344eb318bf27cd8e6833101cc1

See more details on using hashes here.

File details

Details for the file battlebit_community_server_api-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for battlebit_community_server_api-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ee1978ffc68c3a42fd1c08f9771f4b538827d341e758fc3b9ded2cc2e924433
MD5 58c797bb3651b6d0a124f7b25da04ebd
BLAKE2b-256 4b28e739bd9c682a6b2aa3ae9eb1a0efd0e6204d87cf9812b515a83acd16c1d9

See more details on using hashes here.

Supported by

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