Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
2jammers committed Oct 11, 2024
1 parent 46442e4 commit cc693e9
Show file tree
Hide file tree
Showing 30 changed files with 383 additions and 413 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/event.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
prerelease: ${{ contains(github.ref_name, 'rc') }}
generate_release_notes: true
body: |
## Changelog
${{ needs.bump.outputs.release-body }}
Expand Down
2 changes: 1 addition & 1 deletion dev.project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"emitLegacyScripts": true,
"emitLegacyScripts": false,
"name": "net",
"tree": {
"$className": "DataModel",
Expand Down
30 changes: 30 additions & 0 deletions docs/api/client/async.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Async

A client-sided async.

## Properties

---

### `Reliable`

Whether or not the async uses a reliable remote event.

- **boolean**

## Methods

---

### `Request`

Requests data the server, equivalent to [RemoteFunction:InvokeServer](https://create.roblox.com/docs/reference/engine/classes/RemoteFunction#InvokeServer). Returns a Future.

**Parameters**

- **data:** `...any`<br>
The data to request the server with

**Returns**

- **...any**
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions docs/api/server/async.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Async

A server-sided async.

## Properties

---

### `Reliable`

Whether or not the async uses a reliable remote event.

- **boolean**

## Methods

---

### `OnRequest`

Recieves a request from the client, and runs the callback function which returns some data. Equivalent to [RemoteFunction.OnServerInvoke](https://create.roblox.com/docs/reference/engine/classes/RemoteFunction#OnServerInvoke).

**Parameters**

- **callback:** `(sender: Player, ...: any) -> (any, ...any)`<br>
The callback function to run on requesting, must return at least 1 value

**Returns**

- **void**

---

### `SetMiddleware`

Allows you to set middleware that runs at specific points in time.

**Parameters**

- **middleware** `{ [MiddlewareType]: (...any) -> () }`<br>
A table of middleware for the event.

**Returns**

- **void**
34 changes: 5 additions & 29 deletions docs/reference/server/event.md → docs/api/server/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The data that should be sent to each player

---

### `FireExcept`
### `FireAllExcept`

Fires an event which sends data to every client connected to the server, except for players defined in the `except` parameter.

Expand Down Expand Up @@ -112,44 +112,20 @@ Listens for the event to be fired by the client, then runs the provided function
- **listener:** `(sender: Player, ...: any) -> ()`<br>
The function to call when data is recieved

- **validTypes:** `{ string }?`<br>
Valid types that the server should recieve in the order they are specified

**Returns**

- **void**

---

### `SetRateLimit`

Sets a rate limit that is applied when firing an event from the client.

**Parameters**

- **maxCalls:** `number`<br>
The maximum amount of invokes allowed every `interval` seconds; set to -1 to disable the rate limit

- **resetInterval:** `number?`<br>
The interval of which `maxCalls` is reset

- **overflowCallback:** `(sender: Player) -> ()?`<br>
The callback function to run when the player has exceeded the current rate limit

**Returns**

- **void**

---

### `SetInvalidTypeCallback`
### `SetMiddleware`

Allows you to set a callback that runs whenever an invalid type is sent by the client.
Allows you to set middleware that runs at specific points in time.

**Parameters**

- **callback:** `(sender: Player) -> ()`<br>
The function to run when an invalid type is reached and a packet is dropped
- **middleware** `{ [MiddlewareType]: (...any) -> () }`<br>
A table of middleware for the event.

**Returns**

Expand Down
48 changes: 48 additions & 0 deletions docs/api/server/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Interface

References the server event and function constructors

## Functions

---

### `Event`

Creates a new event

**Parameters**

- **name:** `string`\
The name of the event to reference or create

- **reliable:** `boolean`\
Whether the event should be reliable or not. Defaults to true

- **types:** `{ string }`\
Type validation params to be applied at `Listen`

**Returns**

- [**Event**](./event)

---

### `Async`

Creates a new async

**Parameters**

- **name:** `string`\
The name of the async to reference or create

- **reliable:** `boolean`\
Whether the async should be reliable or not. Defaults to true\
*This currently has no effect on asyncs*

- **types:** `{ string }`\
Type validation params to be applied at `OnRequest`

**Returns**

- [**Async**](./async)
15 changes: 15 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Adds a middleware API in place of callbacks
- Packet is now dropped if args contain `NaN`

### Changed

- Changes `Functions` to `Async`
- Moves `Listen` & `OnRequest` type validation params to constructor
- Changes `OnInvoke` and `InvokeAsync` to `OnRequest` and `Request`

### Removed

- Removes default ratelimiting in favor of a custom middleware-based solution

## [0.4.1] - 2024-09-19

### Fixed
Expand Down
31 changes: 31 additions & 0 deletions docs/guides/asyncs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Asyncs

Asyncs are similar to how RemoteFunctions work and also act as a better way to perform tasks where the server returns data back to the client in a call.

## Requesting

Requesting is done on the client. Calling this method will yield the thread until the value is resolved.

```luau
local Net = require(Packages.net).Client
local MyAsync = Net.Async("MyAsync")
local Response = MyAsync:Request("Hi")
print(Response) -- Output: Goodbye
```

## Listening To Request

When listening to a request you must return a value. This is what happens on the server, and if you don't return a value it defeats the purpose of using a async. Use an event instead for this.

```luau
local Net = require(Packages.net).Client
local MyAsync = Net.Async("MyAsync")
MyAsync:OnRequest(function(sender, data)
if data == "Hi" then
return "Goodbye"
end
return "Huh?"
end)
```
31 changes: 0 additions & 31 deletions docs/guides/functions.md

This file was deleted.

32 changes: 32 additions & 0 deletions docs/guides/middleware.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Middleware

The middleware feature allows you to run functions before or after something happens. For example, the `Throttle` middleware runs before the internal `Listen` code is ran and will throttle the event with your code.

## Usage

There are 2 different types of middleware. These are `Throttle` and `Dropped`. Throttle runs before `Listen` or `OnRequest`, and `Dropped` runs when the packet is dropped due to invalid types or NaN.

```luau
local Net = require(Packages.net).Server
local MyEvent = Net.Event("MyEvent")
MyEvent:SetMiddleware({
Throttle = function()
if math.random(1, 2) == 1 then
print("I randomly decided to throttle.")
return false -- Returning false indicates that the event/async should throttle
end
return true
end,
Dropped = function(sender)
print(sender.Name, "sent the incorrect value from the client!")
end,
})
MyEvent:Listen(function()
print("Might print depending on the throttle middleware.")
end)
```

`Dropped` middleware is explained further in the [type validation article](type-validation.md).
22 changes: 0 additions & 22 deletions docs/guides/ratelimiting.md

This file was deleted.

Loading

0 comments on commit cc693e9

Please sign in to comment.