Skip to content

Commit

Permalink
50 (#123)
Browse files Browse the repository at this point in the history
* feat: docs update, free book release, and small api changes

* chore: version bump, dependency upgrade

* Move Transmitter to Hono API #116 (#119)

* added volume option to useAudio Composable (#117)

* Move Transmitter to Hono API #116

* Changed / to /client for client endpoint

---------

Co-authored-by: Liam Robinson <liamrobinson5@web.de>

* docs: update changelog

* fix: loading issue

* feat: experimental dev:reload script

* fix: add package.json

* feat: Extendable Hono API (#122)

* docs: update docs

---------

Co-authored-by: Vladyslav Halatskyi <xfloydya@gmail.com>
Co-authored-by: Liam Robinson <liamrobinson5@web.de>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent 89f190f commit ef896bd
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 32 deletions.
16 changes: 16 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ order: 95

# Changelog

## Version 50

### Code Changes

- Permission system was redone by @floydya for better performance and usage
- Added hot reloading option for `core and webview` resources, accessible through `dev:hot`
- This keeps you connected to the server while the resource itself reloads, it's quite fast
- Split nodemon into two configurations, added new script for reloading

### Docs Changes

- Permission system was updated / documented by @floydya
- Documented `dev:hot` for install

---

## Version 49

### Code Changes
Expand Down
6 changes: 6 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ Alternatively, development mode can be started with
pnpm dev
```

If you want to use an even faster development mode, try out hot reloading. This one simply reloads the resource.

```
pnpm dev:hot
```

---

## 3b. Linux
Expand Down
2 changes: 1 addition & 1 deletion docs/useRebar/document/document-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function someFunction(player: alt.Player) {
const document = Rebar.document.account.useAccount(player);
const isStaff = document.groupPermissions.hasAtLeastOneGroupWithSpecificPerm({
admin: ['noclip', 'ban'],
support: ['answerReport']
support: ['answerReport'],
});
// This will be true if:
// 1. Account has `admin` group with `noclip` OR/AND `ban` permission.
Expand Down
2 changes: 1 addition & 1 deletion docs/useRebar/document/document-character.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function someFunction(player: alt.Player) {
const document = Rebar.document.character.useCharacter(player);
const isStaff = document.groupPermissions.hasAtLeastOneGroupWithSpecificPerm({
admin: ['noclip', 'ban'],
support: ['answerReport']
support: ['answerReport'],
});
// This will be true if:
// 1. Character has `admin` group with `noclip` OR/AND `ban` permission.
Expand Down
98 changes: 98 additions & 0 deletions docs/useRebar/useHono.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
order: 425
---

# useHono

The `useHono` function is designed to extend the game-server web API server by utilizing the Hono framework. It provides mechanisms to register new routes and use middlewares for handling incoming requests.

## addRouter

Registers a new router with the main Hono application.

```ts
import { useRebar } from '@Server/index.js';

const Rebar = useRebar();
const hono = Rebar.useHono();

const app = new Hono<{ Bindings: HttpBindings }>();

// Do stuff with your Hono app.

hono.addRouter('/api/v1', app);
```

## midlewares

A collection of middleware functions for request handling.

### localOnly

Middleware to restrict access to requests coming from the local machine (IP address `127.0.0.1`).

```ts
import { useRebar } from '@Server/index.js';

const Rebar = useRebar();
const hono = Rebar.useHono();

const app = new Hono<{ Bindings: HttpBindings }>();

app.get('/ban', hono.middlewares.localOnly, (c) => {
// Handle the request
});

hono.addRouter('/api/v1', app);
```

> You can also build your own middlewares, such as check auth token or whatever else.
## Example usage

Here is an example of creating a `/ban` endpoint, that will allow you to ban an account via api.

```ts
import { HttpBindings } from "@hono/node-server";
import { useRebar } from "@Server/index.js";
import { Account } from "@Shared/types/account.js";
import { Hono } from "hono";

const Rebar = useRebar();
const hono = Rebar.useHono();
const app = new Hono<{ Bindings: HttpBindings }>();

app.get('/ban', hono.middlewares.localOnly, (c) => {
let { reason, _id } = c.req.query();

if (!_id) {
c.status(400);
return c.json({ data: 'ID was not provided' });
}

if (!reason) {
reason = 'No Reason Given';
}

const onlinePlayer = Rebar.get.usePlayerGetter().byAccount(_id);
if (!onlinePlayer) {
const document = Rebar.document.virtual.useVirtual<Account>(_id, Rebar.database.CollectionNames.Accounts);
if (!document.get()) {
c.status(400);
return c.json({ data: `Account does not exist on the server` });
} else {
document.setBulk({
banned: true,
reason,
});
}
} else {
const rPlayer = Rebar.usePlayer(onlinePlayer);
rPlayer.account.setBanned(reason);
}
c.status(200);
return c.json({ data: `Banned ${_id} with reason '${reason}'` });
})

hono.addRouter('/api/v1', app);
```
18 changes: 18 additions & 0 deletions nodemon-dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"verbose": false,
"ext": "ts, vue",
"watch": ["./src", "./webview"],
"ignore": [
"webview/pages/*",
"webview/vite.config.*",
"*/package.json",
"*.mjs",
"ignore*.ts",
"autogen*.ts",
"webview/src/main.ts",
"src/scratchpad"
],
"events": {
"restart": "node ./scripts/restart.js"
}
}
18 changes: 18 additions & 0 deletions nodemon-hot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"verbose": false,
"ext": "ts, vue",
"watch": ["./src", "./webview"],
"ignore": [
"webview/pages/*",
"webview/vite.config.*",
"*/package.json",
"*.mjs",
"ignore*.ts",
"autogen*.ts",
"webview/src/main.ts",
"src/scratchpad"
],
"events": {
"exit": "node ./scripts/reload.js"
}
}
29 changes: 5 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"author": "stuyk",
"type": "module",
"version": "49",
"version": "50",
"scripts": {
"dev": "nodemon -x pnpm start",
"dev:linux": "nodemon -x pnpm start:linux",
"dev": "nodemon --config ./nodemon-dev.json -x pnpm start",
"dev:linux": "nodemon --config ./nodemon-dev.json -x pnpm start:linux",
"start": "node ./scripts/compile.js && altv-server",
"start:linux": "node ./scripts/compile.js && ./altv-server",
"dev:hot": "pnpm build:docker && concurrently --raw \"nodemon -C --config ./nodemon-hot.json -x pnpm build:docker\" \"altv-server\"",
"build:docker": "node ./scripts/compile.js -- docker",
"binaries": "pnpm altv-pkg",
"rebar:upgrade": "node ./scripts/upgrade.js",
Expand Down Expand Up @@ -37,6 +38,7 @@
"dependencies": {
"@hono/node-server": "^1.12.0",
"@vitejs/plugin-vue": "^5.0.5",
"concurrently": "^8.2.2",
"dotenv": "^16.4.5",
"hono": "^4.5.0",
"mongodb": "^6.8.0",
Expand All @@ -54,26 +56,5 @@
"plugins": [
"prettier-plugin-tailwindcss"
]
},
"nodemonConfig": {
"verbose": false,
"ext": "ts, vue",
"watch": [
"./src",
"./webview"
],
"ignore": [
"webview/pages/*",
"webview/vite.config.*",
"*/package.json",
"*.mjs",
"ignore*.ts",
"autogen*.ts",
"webview/src/main.ts",
"src/scratchpad"
],
"events": {
"restart": "node ./scripts/restart.js"
}
}
}
Loading

0 comments on commit ef896bd

Please sign in to comment.