GithubHelp home page GithubHelp logo

invouker / fxevents Goto Github PK

View Code? Open in Web Editor NEW

This project forked from manups4e/fxevents

0.0 0.0 0.0 909 KB

An advanced event subsystem for FiveM

License: GNU General Public License v3.0

C# 99.80% Batchfile 0.20%

fxevents's Introduction

FxEvents an advanced event subsystem for FiveM

With FxEvents you can send and get values between client and server using an advanced event handling process. Signatures are encrypted per each client and using the provided MsgPack binary serialization you can hide contents from malicious clients! To work you only need to add FXEvents.Client.dll or FXEvents.Server.dll and Newtonsoft.Json.dll (In case of json serialization) to your resource. No need of any external library for MsgPack, the event system uses the internal MsgPack dll provided with fivem itself!!

Discord Server Invite

Usage examples:

Initialization

  • Encryption key CANNOT remain empty or null, you can generate encryption keys, passphrases, passwords online or use the provided serverside command generagekey to let the library generate a random passphrase both literal and encrtypted to be copied and stored in a safe place. PLEASE NOTE: FXEvents won't store nor save any passkey anywhere for security reasons, do not lose the key or your data won't be recovered.
public class Main : BaseScript
{
 public Main()
 {
  // The Event Dispatcher can now be initialized with your own inbound, outbound, and signatures.
  // This allows you to use FxEvents in more than one resource on the server without having signature collisions.
  EventDispatcher.Initalize("inbound", "outbound", "signature", "encryption key");
 }
}

To mount an event:

  • Events can be mounted like normal events, this example is made to show an event mounted in-line.
EventDispatcher.Mount("eventName", new Action<ISource, type1, type2>(([FromSource] source, val1, val2) =>    
{
  // code to be used inside the event.
  // ISource is the optional insider class that handles clients triggering the event.. is like the "[FromSource] Player player" parameter but can be derived and handled as you want!!
  // Clientside is the same thing without the ClientId parameter
}));

To trigger an event

The library only works in client <--> server communication.. for the moment same side events are not working but the feature will be added in the future!

// clientside
EventDispatcher.Send("eventName", params);

// serverside
EventDispatcher.Send(Player, "eventName", params);
EventDispatcher.Send(List<Player>, "eventName", params);
EventDispatcher.Send(ISource, "eventName", params);
EventDispatcher.Send(List<ISource>, "eventName", params);

To trigger a callback

Mounting it

EventDispatcher.Mount("eventName", new Func<ISource, type1, type2, Task<returnType>>(async ([FromSource] source, val1, val2) =>    
{
  // code to be used inside the event.
  // ISource is the optional insider class that handles clients triggering the event.. is like the "[FromSource] Player player" parameter but can be derived and handled as you want!!
  // Clientside is the same thing without the ISource parameter
  return val3
}));

Calling it

// clientside
type param = await EventDispatcher.Get<type>("eventName", params);

// serverside
type param = await EventDispatcher.Get<type>(ClientId, "eventName", params);
type param = await EventDispatcher.Get<type>(Player, "eventName", params);

Callbacks can be called serverside too because it might happen that the server needs info from certain clients and this will help you doing it.

The library comes with some goodies to help with customization and debugging serialization printing.

ToJson()

image

⚠️ You need Newtonsoft.Json to make this work!!

string text = param.ToJson();

FromJson()

⚠️ You need Newtonsoft.Json to make this work!!

type value = jsonText.FromJson<type>();

ToBytes()

image

byte[] bytes = param.ToBytes();

FromBytes()

type value = bytes.FromBytes<type>();

EncryptObject(string passkey)

  • Binary serialization performed internally.
byte[] bytes = param.EncryptObject("passkey");

DecryptObject(string passkey)

  • Binary deserialization performed internally.
T object = bytes.DecryptObject<T>("passkey");

BytesToString

byte[] bytes = param.ToBytes();
string txt = bytes.BytesToString();

StringToBytes

byte[] bytes = txt.StringToBytes();
type value = bytes.FromBytes<type>();

fxevents's People

Contributors

manups4e avatar local9 avatar whoeza avatar quadrupleturbo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.