Skip to content

Commit

Permalink
chore(docs): more docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
c43721 committed Oct 27, 2024
1 parent 42e689c commit 7a03ca2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
20 changes: 19 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,56 @@
/**
* The socket was already authenticated
*/
export class AlreadyAuthenicatedException extends Error {
constructor() {
super();
this.message = "Already authenticated";
}
}

/**
* Unable to authenticate the socket
*/
export class UnableToAuthenicateException extends Error {
constructor() {
super();
this.message = "Unable to authenticate";
}
}

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();
this.message = "Not connected";
}
}

/**
* The packet was unable to be parsed into the expected value
*/
export class UnableToParseResponseException extends Error {
constructor() {
super();
this.message = "Unable to parse response";
}
}

/**
* The packet being sent is too large to send to the server
*/
export class PacketSizeTooBigException extends Error {
constructor() {
super();
Expand Down
4 changes: 2 additions & 2 deletions src/rcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7a03ca2

Please sign in to comment.