Package: battlebit-community-server-api
BattleBit Community Server APIA re-implementation of the official community server API for BattleBitPreambleThe goal of this project is to create an alternate, Python-implementation to theofficial community server API, which is written in C#. This project can be considered production-ready.PrerequisitesPython 3.10 or laterA running, whitelisted BattleBit Server (Version 2.1.2)UsageAs a user of this API, there are two important things to know,Handlers andCommands. More on those in the following paragraphs. Basic examples on how to use this project can be found in/battlebit_community_server_api/example.HandlersHandlers 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 theApiServer.register_handlermethod. This method takes  anOpCodesvalue and anyCallable.IMPORTANT:Each handler has the signatureasync def handler(d: bytes) -> bytes. It receives the raw TCP message as an input and returns a TCP message.UseTcpParsingServiceto parse the incoming data into the datamodel objects. UseOutgoingGameServerMessageto return data. Refer to the examples for further information.Default HandlersIf there is noHandlerregistered for an OP-Code, the defaultHandlerfor that event is executed. The user can also use defaultHandlers in their ownHandler, seeexample/SendingCommands.py.Implementation status of default handlersEventStatusBehaviorAssociated Parser (fromTcpParingService)HAILHAIL is acceptedparse_hail_messagePLAYER_CONNECTEDEvent does not expect a responseparse_player_connectedPLAYER_DISCONNECTEDEvent does not expect a responseparse_player_disconnectedON_PLAYER_TYPED_MESSAGEAllows message viaRESPOND_PLAYER_MESSAGEparse_on_player_typed_messageON_PLAYER_KILLED_ANOTHER_PLAYEREvent does not expect a responseparse_on_player_killed_another_playerON_PLAYER_JOININGOfficial Stats are returned viaSEND_PLAYER_STATSparse_on_player_joiningSAVE_PLAYER_STATSEvent does not expect a responseparse_save_player_statsON_PLAYER_ASKING_TO_CHANGE_ROLEAllows requested role change viaSetRoleToparse_on_player_asking_to_change_roleON_PLAYER_CHANGED_ROLEEvent does not expect a responseparse_on_player_changed_roleON_PLAYER_JOINED_A_SQUADEvent does not expect a responseparse_on_player_joined_a_squadON_PLAYER_LEFT_SQUADEvent does not expect a responseparse_on_player_left_squadON_PLAYER_CHANGED_TEAMEvent does not expect a responseparse_on_player_changed_teamON_PLAYER_REQUESTING_TO_SPAWNRequest is granted viaSPAWN_PLAYERparse_on_player_requesting_to_spawnON_PLAYER_REPORTEvent does not expect a responseparse_on_player_reportON_PLAYER_SPAWNEvent does not expect a responseparse_on_player_spawnON_PLAYER_DIEEvent does not expect a responseparse_on_player_dieNOTIFY_NEW_MAP_ROTATIONEvent does not expect a responseparse_notify_new_map_rotationNOTIFY_NEW_GAME_MODE_ROTATIONEvent does not expect a responseparse_notify_new_gamemode_rotationNOTIFY_NEW_ROUND_STATEEvent does not expect a responseparse_new_round_stateON_PLAYER_ASKING_TO_CHANGE_TEAMAllows requested team change viaSetTeamToparse_on_player_asking_to_change_teamGAME_TICKEvent does not expect a responseparse_game_tickON_PLAYER_GIVEN_UPEvent does not expect a responseparse_on_player_given_upON_PLAYER_REVIVED_ANOTHEREvent does not expect a responseparse_on_player_revived_anotherON_SQUAD_POINTS_CHANGEDEvent does not expect a responseparse_on_squad_points_changedNOTIFY_NEW_ROUND_IDEvent does not expect a responseparse_notify_new_round_idLOGLogs will be written to logger on DEBUG levelparse_logON_SQUAD_LEADER_CHANGEDEvent does not expect a responseparse_on_squad_leader_changedUPDATE_NEW_GAME_DATAEvent does not expect a responseparse_update_new_game_dataUPDATE_CONNECTED_PLAYERSEvent does not expect a responseparse_update_connected_playersCommandsWhile Handlers are triggered on an event and respond to the server,Commands can be executed at any point.To execute anCommand, pick aCommandfrom theCommandmodule (for exampleCommand.SayToChat), use its initializer to prepare it, and then queue it for execution.You can also build your own commands by using theCommandbase class.To execute a command, useApiServer.add_command_to_queue.Predefined commandsCommandEffectForceStartGameStarts the RoundForceStartGameEnds the RoundSayToAllChatSends chat message into All-ChatSayToChatSends chat message that is only visible to a specific playerSetRoleToSets the role of playerSetTeamToSets the team of playerSetNewPasswordSets a new password for the serverSetPingLimitSets a new ping limit for the serverAnnounceShortDisplays an announcement to all players for a short durationAnnounceLongDisplays an announcement to all players for a long durationUILogOnServerDisplays a log message on the server for a set durationSetLoadingScreenTextSets the text that is displayed to players in the loading screenSetRulesScreenTextSets the text that is displayed to the players in the rules screenStopServerStops the serverCloseServerAnnounces that the server will closeKickAllPlayersKicks every playerKickPlayerKicks specific player, optionally with a text that is displayed to the playerKillPlayerKills specific playerSwapTeamSwaps specific player to the other teamKickFromSquadKicks specific player from squadJoinSquadJoins specific player into a squadDisbandPlayerSquadDisbands a squadPromoteSquadLeaderPromotes specific player to be the squadleader of the squad he is currently inWarnPlayerDisplays warn message to playerMessageToPlayerDisplays message to player (not in chat, useSayToChatif you want that)SetPlayerHpSets a specific player's HPDamagePlayerDamage specific playerHealPlayerHeal specific playerSetSquadPointsSets squadpoints for a specific squadSetMapRotationSets the map rotationSetGamemodeRotationSets the gamemode rotationSetMapSizeSets the map size for the next roundPredefined OutgoingGameServerMessagesNew in version 0.1.1There areOutgoingGameServerMessages that have already been preconfigured with the correct OP-Code and accept typed arguments.
Below is a list of the ones that are currently available.NameEffectSetPlayerModificationGiven a SteamID and a PlayerModification object, this OutgoingGameServerMessage will apply the modifications to the player with that SteamID (if that player is still on the server)PlaceVoxelBlockGiven a Vector3 and a VoxelBlockData object, this OutgoingGameServerMessage will place the specified block at the specified location.DestroyVoxelBlockDestroys a block at the specified locationThe predefinedOutgoingGameServerMessages can be imported frombattlebit_community_server_api.helper.PredefinedOutgoingGameServerMessages.Adding commands from outsideAt some point you might want to queue Commands or OutgoingGameServerMessages from outside the API loop.
You can find an example doing just that atexample/SetNewRoomSettings.py.ContributingThe current state of development does not yet allow for productive, cooperative contribution.LicenceDO 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.