Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scripting/net): Unreliable network events #2841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tens0rfl0w
Copy link
Contributor

Goal of this PR

There are certain scenarios where resource developers may want to send frequent data that is not state-critical (i.e., can be lost). Currently, all script-transmitted data is treated as reliable (ACK, resends, etc.), which can introduce a noticeable hit on general server performance when used for data that should not get sent as reliable.

How is this PR achieving the goal

  • Introducing a new API to send unreliable client and server network events
  • All new API functions are equal to the existing reliable send functions:
    • Lua: TriggerUnreliableClientEvent and TriggerUnreliableServerEvent
    • JS; emitUnreliableNet, TriggerUnreliableClientEvent and TriggerUnreliableServerEvent
    • C# V1: Player.TriggerUnreliableEvent, TriggerUnreliableClientEvent and TriggerUnreliableServerEvent
    • C# V2: Player.TriggerUnreliableEvent, Events.TriggerUnreliableAllClientsEvent, Events.TriggerUnreliableClientEvent, and Events.TriggerUnreliableServerEvent

Implementation has been tested on all available ScRTs and should not introduce any breaking changes (*__INTERNAL natives are already declared as internal functions).

This PR applies to the following area(s)

FiveM, Server, Natives, ScRT: Lua, ScRT: C#, ScRT: JS

Successfully tested on

Game builds: Not applicable

Platforms: Windows, Linux

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

/

@github-actions github-actions bot added ScRT: C# Issues/PRs related to either C# scripting runtimes ScRT: JS Issues/PRs related to the JavaScript scripting runtime ScRT: Lua Issues/PRs related to the Lua scripting runtime invalid Requires changes before it's considered valid and can be (re)triaged labels Oct 5, 2024
@manzarek123
Copy link
Contributor

This is going to break a lot of server since people are using TRIGGER_CLIENT_EVENT_INTERNAL directly

Maybe last arg should be "unreliable" instead of "reliable"

https://github.com/overextended/ox_lib/blob/a2a711498658d36e51bd9853f681cacac502f9bb/imports/triggerClientEvent/server.lua#L14

This introduces a new API to send unreliable client and server events from within all ScRTs.
@github-actions github-actions bot added triage Needs a preliminary assessment to determine the urgency and required action and removed invalid Requires changes before it's considered valid and can be (re)triaged labels Oct 5, 2024
@tens0rfl0w
Copy link
Contributor Author

This is going to break a lot of server since people are using TRIGGER_CLIENT_EVENT_INTERNAL directly

Thanks for pointing this out!

I went with moving the shared code paths for reliable and unreliable network events one step deeper internally, so this shouldn't break any usage of backing natives anymore.

(ScRTs now invoke TRIGGER_UNRELIABLE_*_EVENT_INTERNAL)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ScRT: C# Issues/PRs related to either C# scripting runtimes ScRT: JS Issues/PRs related to the JavaScript scripting runtime ScRT: Lua Issues/PRs related to the Lua scripting runtime triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants