Skip to content

Commit

Permalink
Fix global middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorlias committed Jan 30, 2025
1 parent 326da5e commit 2bf4525
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.0.10
- ServerGlobalMiddleware should now function :-)

## 3.0.6
- Fixes (https://github.com/roblox-aurora/rbx-net/pull/84) `Client:Get(remoteId) causing delays`

Expand Down
6 changes: 4 additions & 2 deletions example/client/index.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const testEvents = Remotes.Client.GetNamespace("TestingEvents");

const add = testFunctions.Get("CallServerAndAddNumbers");

add.CallServerAsync(10, 10).then((result) => {
add.CallServerAsync(10, 10).then(result => {
if (result === 20) {
print("RESULT IS 20");
} else {
error("RESULT IS WRONG");
error("RESULT IS WRONG " + tostring(result));
}
});

testEvents.Get("PrintMessage").SendToServer("Hwello, World!");
4 changes: 2 additions & 2 deletions example/server/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const testEvents = Remotes.Server.GetNamespace("TestingEvents");
testFunctions.OnFunction("CallServerAndAddNumbers", (_, a, b) => a + b);
testEvents.OnEvent("PrintMessage", print);
const testLegacy = Remotes.Server.GetNamespace("Legacy").Create("LegacyFunction");
const testLegacy2 = Remotes.Client.GetNamespace("Legacy").Get("LegacyFunction");
// const testLegacy2 = Remotes.Client.GetNamespace("Legacy").Get("LegacyFunction");

testFunctions.Create("CallServerAndAddNumbers").SetCallback((_, a, b) => a + b);

Expand All @@ -21,7 +21,7 @@ type NamespaceTest = Net.Util.GetNamespaceDefinitions<GlobalNamespace, "TestingE
type TestNamespaceAsServerRemotes = Net.Util.GetServerRemotes<NamespaceTest>;
type TestNamespaceAsClientRemotes = Net.Util.GetClientRemotes<NamespaceTest>;

Remotes.Server.Get("Srv").Connect((message) => {});
Remotes.Server.Get("Srv").Connect(message => {});

Remotes.Server.GetNamespace("TestingFunctions").OnFunction("CallServerAndAddNumbers", async () => {
return 10;
Expand Down
2 changes: 1 addition & 1 deletion example/shared/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Remotes = Create(
{
ServerGlobalMiddleware: [
Net.Middleware.Global((remote, data, player) => {
$print("call from", player, "via", remote, ...data);
$print("**** call from", player, "via", remote, ...data);
}),
],
},
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rbxts/net",
"version": "3.0.9",
"version": "3.0.10",
"description": "",
"main": "out/init.lua",
"scripts": {
Expand All @@ -13,8 +13,8 @@
"build:dev": "cross-env NODE_ENV=development rbxtsc --verbose",
"watch:dev": "cross-env NODE_ENV=development rbxtsc -w --verbose",
"build:rbxmx": "npm run build:luau && rojo build luau/build.project.json -o luau.net.rbxmx",
"build:example": "cross-env NODE_ENV=development rbxtsc-dev --type=game -p ./example -i ./include",
"watch:example": "cross-env NODE_ENV=development TYPE=TestTS rbxtsc-dev -w --type=game -p ./example -i ./include",
"build:example": "cross-env NODE_ENV=development rbxtsc --type=game -p ./example -i ./include",
"watch:example": "cross-env NODE_ENV=development TYPE=TestTS rbxtsc -w --type=game -p ./example -i ./include",
"serve:example": "rojo serve ./example/default.project.json --port 34567",
"dev:example": "concurrently npm:watch:example npm:serve:example"
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace Net {
/**
* The version of RbxNet
*/
export const VERSION = $NODE_ENV === "production" ? PKG_VERSION : `DEV ${DIST})} ${PKG_VERSION}`;
export const VERSION = ($NODE_ENV as string) === "production" ? PKG_VERSION : `DEV ${DIST})} ${PKG_VERSION}`;

/**
* Built-in middlewares
Expand Down
3 changes: 2 additions & 1 deletion src/server/ServerEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MiddlewareEvent, { MiddlewareList } from "./MiddlewareEvent";
import { MiddlewareOverload } from "../middleware";
import { NetServerScriptSignal, NetServerSignalConnection } from "./NetServerScriptSignal";
import { DefinitionConfiguration } from "../definitions";
import { $dbg } from "rbxts-transform-debug";

/**
* Interface for server listening events
Expand Down Expand Up @@ -62,7 +63,7 @@ export default class ServerEvent<
middlewares: MiddlewareOverload<ConnectArgs> = [],
private configuration: DefinitionConfiguration,
) {
super(middlewares);
super([...middlewares, ...(configuration.ServerGlobalMiddleware ?? [])]);
assert(!IS_CLIENT, "Cannot create a NetServerEvent on the client!");
this.instance = findOrCreateRemote("RemoteEvent", name);
this.connection = new NetServerScriptSignal(this.instance.OnServerEvent, this.instance);
Expand Down
8 changes: 6 additions & 2 deletions src/server/ServerFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export default class ServerFunction<
return undefined;
};

constructor(name: string, middlewares: MiddlewareOverload<CallbackArgs> = [], private configuration: DefinitionConfiguration) {
constructor(
name: string,
middlewares: MiddlewareOverload<CallbackArgs> = [],
private configuration: DefinitionConfiguration,
) {
super(middlewares);
this.instance = findOrCreateRemote("RemoteFunction", name, (instance) => {
this.instance = findOrCreateRemote("RemoteFunction", name, instance => {
// Default listener
instance.OnServerInvoke = ServerFunction.DefaultFunctionHook;
CollectionService.AddTag(instance, TagId.DefaultFunctionListener);
Expand Down

0 comments on commit 2bf4525

Please sign in to comment.