diff options
Diffstat (limited to 'docs/api')
| -rw-r--r-- | docs/api/_sidebar.md | 4 | ||||
| -rw-r--r-- | docs/api/commands.md | 37 | ||||
| -rw-r--r-- | docs/api/objects.md | 30 | ||||
| -rw-r--r-- | docs/api/packets.md | 2 |
4 files changed, 70 insertions, 3 deletions
diff --git a/docs/api/_sidebar.md b/docs/api/_sidebar.md index 1ba0b50..feee103 100644 --- a/docs/api/_sidebar.md +++ b/docs/api/_sidebar.md @@ -1,8 +1,9 @@ -* [Home](/api/README.md) +* [Quick Start](/api/README.md) * [Plugin Structure](/api/plugin.md) * [Class Reference](/api/objects.md) - [Aircraft](/api/objects.md#aircraft-class) - [Player](/api/objects.md#player-class) + - [YSChat](/api/objects.md#yschat-class) * [Packet Reference](/api/packets.md) - [FSNETCMD_ADDOBJECT](/api/packets.md#fsnetcmd_addobject) - [FSNETCMD_AIRCMD](/api/packets.md#fsnetcmd_aircmd) @@ -33,3 +34,4 @@ - [FSNETCMD_UNJOIN](/api/packets.md#fsnetcmd_unjoin) - [FSNETCMD_WEAPONCONFIG](/api/packets.md#fsnetcmd_weaponconfig) * [Hooks Reference](/api/hooks.md) +* [Commands Reference](/api/commands.md) diff --git a/docs/api/commands.md b/docs/api/commands.md new file mode 100644 index 0000000..dc4cd6c --- /dev/null +++ b/docs/api/commands.md @@ -0,0 +1,37 @@ +# Introduction + +Commands can be called by users joined in the server using the prefix defined +in the `config.py` file concartinated with the command name. Commands, unlike hooks +are *non-blocking*. Meaning the proxy continues its operation without waiting for +the function to return a value. It is useful when sending your own packets to the +server or client. + +# Command Structure + +In main `Plugin` Class, there must be a `register` method, under which +you must declare your commands. +> eg. +> ```python +> def register(self, plugin_manager): +> self.plugin_manager = plugin_manager +> self.plugin_manager.register_command('test', self.test) +>``` + +Now if a person sends a message `!test` in the chat, the `test` method of your plugin +will run. + +# Command Function Structure + +Every command function must have the following structure: +```python +def test(self, full_message, player, message_to_client, message_to_server) +``` +Where: +- `full_message` is the full message sent by the user. (including the command, but excluding the username) +- `player` is the `Player` object that triggered the command. +- `message_to_client` is the list that contains the packets that will be sent to the client. + you must append to it and return a value for the packet to be sent. +- `message_to_server` is the list that contains the packets that will be sent to the server. + you must append to it and return a value for the packet to be sent. + +> You must always return a `True` value, otherwise the proxy thinks your command ran into an error. diff --git a/docs/api/objects.md b/docs/api/objects.md index bdd5d49..af9d1a0 100644 --- a/docs/api/objects.md +++ b/docs/api/objects.md @@ -270,3 +270,33 @@ __str__() Returns a user-friendly string representation of the `Player` object. This string includes the player's `username`, the name of their `aircraft`, and its current `position`. Useful for logging and debugging purposes. * **Returns**: A descriptive string of the `Player` object. + +## ``YSchat`` Class + +!> Deprecated! It is recomemded to use `FSNETCMD_TEXTMESSAGE` packet for chat messages. + +The `YSchat` class is a simple way to pack data into YSF Net commands and also quick way to +pack text messages into chat messages. + +- It is located in `lib.YSchat` + +#### Methods + +##### ``YSchat.send(buffer: bytes)`` + +- It take buffer as input and adds the header size info to it, therefore preparing +the packet just before being sent + +**Returns** : Bytes Type object + +##### ``YSchat.reply(type: int, buffer: bytes)`` + +- It adds the header packet type info to the buffer and then calls `send` method + +**Returns** : Bytes Type object + +##### ``YSchat.message(msg: str)`` + +- Fully prepares a packet with the message string, can be directly sent to client or server. + +**Returns** : Bytes Type object diff --git a/docs/api/packets.md b/docs/api/packets.md index 38ed2e8..0869755 100644 --- a/docs/api/packets.md +++ b/docs/api/packets.md @@ -1947,5 +1947,3 @@ This packet is used to transmit weapon configuration settings for aircraft. It a * Sets the `aircraft_id`. * Creates a `weapon_config` dictionary with three smoke weapon types (32, 33, 34 - likely representing different smoke launcher positions or types) and sets their color to gray `[66, 66, 66]`. * Sets `with_size=True` to include the packet size prefix in the encoded buffer. - -**In summary,** `FSNETCMD_WEAPONCONFIG` is designed for transmitting aircraft weapon loadout details. It handles regular weapon counts and has special logic for encoding and decoding smoke weapon colors using bit packing and scaling. The `addSmoke` method provides a convenience function to quickly enable smoke for a given aircraft. |
