From 7a03ca204f1d89cc2593da8b6223a4c763ce968f Mon Sep 17 00:00:00 2001 From: c43721 Date: Sun, 27 Oct 2024 15:29:49 -0500 Subject: [PATCH] chore(docs): more docs and examples --- README.md | 14 ++++++++++++++ deno.json | 2 +- src/errors.ts | 20 +++++++++++++++++++- src/rcon.ts | 4 ++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e50d2c6..9916429 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,20 @@ Checkout the [jsr page](https://jsr.io/@c43721/rcon) for more details. ### Examples +A simple example that connects to a server and executes the `status` command and logs to console + +```ts +using rcon = new Rcon({ host: "game.example.com", port: 27015 }); + +const didAuthenticate = await rcon.authenticate("myrconpassword"); + +console.log(didAuthenticate ? "Authenticated to the server" : "Could not authenticate"); + +const result = await rcon.execute("status"); + +console.log(result); +``` + For more examples, see the [documentation on jsr](https://jsr.io/@c43721/rcon/doc). ## Contributing diff --git a/deno.json b/deno.json index eff7dfe..94ff92b 100644 --- a/deno.json +++ b/deno.json @@ -5,6 +5,6 @@ "@std/cli": "jsr:@std/cli@^1.0.6", "@std/io": "jsr:@std/io@^0.225.0" }, - "version": "0.0.1", + "version": "0.0.2", "exports": "./mod.ts" } diff --git a/src/errors.ts b/src/errors.ts index 0d2c7a6..0a34134 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,3 +1,6 @@ +/** + * The socket was already authenticated + */ export class AlreadyAuthenicatedException extends Error { constructor() { super(); @@ -5,6 +8,9 @@ export class AlreadyAuthenicatedException extends Error { } } +/** + * Unable to authenticate the socket + */ export class UnableToAuthenicateException extends Error { constructor() { super(); @@ -12,13 +18,19 @@ export class UnableToAuthenicateException extends Error { } } -export class NotAuthorizedException extends Error { +/** + * Not authenticated to the socket and the user tried to send a command + */ +export class NotAuthenticatedException extends Error { constructor() { super(); this.message = "Not authenticated"; } } +/** + * The socket was never connected or disconnected too early + */ export class NotConnectedException extends Error { constructor() { super(); @@ -26,6 +38,9 @@ export class NotConnectedException extends Error { } } +/** + * The packet was unable to be parsed into the expected value + */ export class UnableToParseResponseException extends Error { constructor() { super(); @@ -33,6 +48,9 @@ export class UnableToParseResponseException extends Error { } } +/** + * The packet being sent is too large to send to the server + */ export class PacketSizeTooBigException extends Error { constructor() { super(); diff --git a/src/rcon.ts b/src/rcon.ts index 2a73f20..64c11ed 100644 --- a/src/rcon.ts +++ b/src/rcon.ts @@ -3,7 +3,7 @@ import { iterateReader } from "@std/io"; import { concat } from "@std/bytes"; import { encode, decode } from "./packet.ts"; import { - NotAuthorizedException, + NotAuthenticatedException, NotConnectedException, PacketSizeTooBigException, UnableToAuthenicateException, @@ -102,7 +102,7 @@ export default class Rcon { } if (!this.#authenticated) { - throw new NotAuthorizedException(); + throw new NotAuthenticatedException(); } const packetId = Math.floor(Math.random() * (256 - 1) + 1);