Socket
Book a DemoInstallSign in
Socket

@rbxts/flamework-gateways-mod

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rbxts/flamework-gateways-mod

A class-based Flamework networking mod

0.2.4
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
ย 
Created
Source

๐ŸŒ‰flamework-gateways-mod๐ŸŒ‰

A Flamework networking mod

โœจ Featuring

๐ŸŒ‰ Gateways - Handle remote events and functions with classes

๐Ÿ›ก๏ธ Guards - Block certain requests before they are processed

๐Ÿ“ž Pipes - Transform and validate parameters passed to requests

๐ŸŒป Motivation

This is mainly a personal project to handle remotes with classes and decorators.

๐Ÿ”Œ Installation

npm install @flamework/core@modding
npm install -D rbxts-transformer-flamework@modding
npm install @rbxts/flamework-gateways-mod

๐Ÿ“š Examples

๐Ÿ—‚๏ธ Client-server connection

connectServer and connectClient should be called before igniting Flamework.

Do note that guards & pipes will not be applied to external listeners like .on, .wait, etc.!

type ServerGateway = OneGateway & AnotherGateway;

const server = connectServer<ServerGateway, ClientGateway>();

server.emit("clientEvent", players, ...args);
server.broadcast("clientEvent", ...args);
type ClientGateway = OneGateway & AnotherGateway;

const client = connectClient<ServerGateway, ClientGateway>();

client.emit("serverEvent", ...args);
client.request("serverInvoke", ...args);

๐ŸŒ‰ Gateway

Gateways should be added to Flamework.addPaths()

@Gateway({
  guards: [new AdminGuard(["littensy"])],
})
class AdminGateway {
  constructor(private readonly adminService: AdminService) {}

  @OnEvent()
  @UseGuards(CommandDebounceGuard)
  @UsePipes([], CommandPipe)
  async processCommand(player: Player, message: string | Array<string>) {
    this.adminService.runCommand(player, message as Array<string>);
  }

  @OnInvoke()
  async getCommands() {
    return this.adminService.getCommands();
  }
}

๐Ÿ›ก๏ธ Guard

Creatable guards

class AdminGuard implements CanActivate {
  constructor(private readonly admins: Array<string>) {}

  canActivate(context: ExecutionContext) {
    return this.admins.includes(context.getPlayer().Name);
  }
}

Singleton guards should be added to Flamework.addPaths()

@Guard()
class CommandDebounceGuard implements CanActivate {
  constructor(private readonly roduxService: RoduxService) {}

  canActivate(context: ExecutionContext) {
    const state = this.roduxService.getState();
    return time() >= state.commandDebounce;
  }
}

๐Ÿ“ž Pipe

Creatable pipe

class CommandPipe implements PipeTransform {
  transform(value: unknown) {
    assert(typeIs(value, "string"), "(CommandPipe) Value must be a string");
    return value.split(" ");
  }
}

Singleton pipes should be added to Flamework.addPaths()

โš ๏ธ Limitations

โŒ Client-side RemoteFunctions are not supported

  • It is difficult to safely determine whether a client remote is a function or an event from the server.

โŒ Some type limitations

  • Pipe transformation input/output is not type checked, use Input | Output in the parameter type to keep track (see examples).

Keywords

flamework

FAQs

Package last updated on 17 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.