You are viewing a potentially older version of this package. View all versions.
Soggy_Pancake-AtlyssCommandLib-0.0.6 icon

AtlyssCommandLib

[BETA] A library to easily create chat commands for Atlyss

Date uploaded 4 days ago
Version 0.0.6
Download link Soggy_Pancake-AtlyssCommandLib-0.0.6.zip
Downloads 2943
Dependency string Soggy_Pancake-AtlyssCommandLib-0.0.6

This mod requires the following mods to function

BepInEx-BepInExPack-5.4.2100 icon
BepInEx-BepInExPack

BepInEx pack for Mono Unity games. Preconfigured and ready to use.

Preferred version: 5.4.2100
Soggy_Pancake-CodeYapper-2.0.1 icon
Soggy_Pancake-CodeYapper

A simple library to abstract away networking

Preferred version: 2.0.1
Nessie-EasySettings-1.2.1 icon
Nessie-EasySettings

A mod API for easily adding options to the settings menu.

Preferred version: 1.2.1

README

Atlyss Command Library

Requirements

  • CodeYapper (Used to provide clients all root providers/commands that should be forwarded to the server)

Goals of this project

  1. Prevent people from putting failed chatcolor commands in chat like this /chatcolor aaff21, then requiring someone to tell them that they need to include the hashtag.
  2. Provide a nice interface to register chat or console commands.

How it works

This uses patches to capture chat messages before they are forwarded to the server. If it detects that it starts with a / then it begins to parse as a command. CodeYapper is required as anything that is unknown simply prints the default help message and the server will never see it as I am assuming the server is vanilla and will chuck any failed command straight into chat.

Usage

It is recommended that you put all of your commands under your own command provider. A command provider can be thought of as a command folder. Any name conflicts result in the command or provider silently failing and being ignored

\-- YourMod (Provider)
    +-- Command1
    +-- Command2
    \-- CommandGroup (Provider)
        +-- Grouped1
        +-- Grouped2

First in your imports add

using AtlyssCommandLib.API;
using static AtlyssCommandLib.API.Utils;

There are static methods to register your commands to the 'root' provider that contains this library's included built in commands and vanilla commands.

Commands

Commands can be registered using the RegisterCommand method, either using the static one that registers to the root provider or by calling the method on your own provider. All commands default to being client side, however you can specify a client-side, server-side, or console command by creating a CommandOptions object. CommandOptions is intentially a struct to avoid the ability to overwrite the options of an already created command. For commands that might do local checks before forwarding to the server you should mark it as client and server side.

Commands recieve a Caller and a string array containing the arguments.

delegate bool CommandCallback(Caller caller, string[] args);

As a server or client command returning false will result in showing the help message for your method.

Note: Returning true as a server+client side command will forward the command to the server.

Providers

A command provider is essentially a directory that can contain commands and other providers.

To create a provider use: CommandProvider cp = new CommandProvider(<Prefix>, <HelpMsg>, [RootProvider]) Providing the root provider is optional but can save time registering it to your target provider without needing to explicitly register it yourself. If the target root provider is null it will autoregister itself to the root.

License

The license is LGPLv3

CHANGELOG

0.0.6

  • Make sure chatcolors loads before commandlib

0.0.5

  • Add option to send failed commands to server anyway (defaults to false)
    • Allows server side mods like HostModeration to still recieve commands
  • Fix some bad namespaces
  • Update game version to 12026.a2

0.0.4

  • Always parse like in 0.0.2 but delays killing the message so other mods can still parse it
    • Parses commands first and if fails adds a flag to prevent sending to server
    • This allows other mods to still parse the message even if it's a command
      • Any mod that would forward the message to the server tho would still break
  • Clients no longer send a server command list packet
  • Server command list is now sent through p2p
  • CommandOptions is now optional again when registering commands

0.0.3

  • Make patches run last so other mods can recieve commands

0.0.2

  • Ignore // since some people use it in rp
  • Fix console commands being broken
  • only print full help message when /help is called and not when a command fails
  • better homebrewery compatibility

0.0.1

  • WARNING: BETA RELEASE
  • Server side commands have NOT been well tested so expect bugs.
  • This hooks into every chat message and should remove any failed commands before they get sent to the server.
  • /chatcolor command added as a test for a client and server side command. This will be removed whenever some command library becomes standard or chatcolor prevents failed commands from entering chat.
  • Suggestions to improve the API are welcome. Open an issue on github or use the Atlyss Modding Discord server.