fivem-docs icon indicating copy to clipboard operation
fivem-docs copied to clipboard

Add C# Server Side Documentation

Open Luke20201 opened this issue 3 years ago • 6 comments

I saw C# only had client-side Documentation, so I decided to spend a few hours documenting what I felt was the most important and useful for FiveM developers in C#.

This covers;

  • Setting up the environment (using NuGet)
  • Hooking events and using [FromSource]
  • Server Callbacks
  • MySQL

I think I explained everything in good detail, though this doc assumes the user read the client-side documentation first.

Luke20201 avatar Jul 01 '22 21:07 Luke20201

While we appreciate the effort, this seems to be having quite a bit of outdated/weird/wrong information. (for one, you should not. ever. use. the 'network callback' stuff. it's inherently broken and relies on a memory leak to work, which means you will experience lots of weird issues with it)

The C# docs already mention setting up a server script because the template does so already.

(I am currently not able to provide more detailed comments as I'm on my phone, just remarking to other project members that this should not be merged without a lot of rewriting!)

blattersturm avatar Jul 02 '22 15:07 blattersturm

Hi,

I was 100% confused on whether to use NetworkCallbackDelegate or not, I saw a lot of people saying it didn't work, and a few others saying that CFX confirmed it working. I went with it because I have had no issues using it, but if there is an issue with it I understand.

Could you elaborate on anything else I may have confused so it can be corrected?

Luke20201 avatar Jul 02 '22 18:07 Luke20201

As an extra to the rewriting: don't use dynamic types unless you really need to make use of the dynamic-ness it offers.

dynamic is compiled to type object with a lot of extra IL code to make sure it can do all the stuff you do with it. This also makes JITting the code slower (I've seen freezes up to several seconds with some specific code). Better to use var (or the type) for local variable declarations and the exact type as parameters. Also, although small, object also has a (hidden) runtime pack/unpack cost. Better not teaching new programmers bad habits ;)

thorium-cfx avatar Jul 03 '22 12:07 thorium-cfx

As an extra to the rewriting: don't use dynamic types unless you really need to make use of the dynamic-ness it offers.

dynamic is compiled to type object with a lot of extra IL code to make sure it can do all the stuff you do with it. This also makes JITting the code slower (I've seen freezes up to several seconds with some specific code). Better to use var (or the type) for local variable declarations and the exact type as parameters. Also, although small, object also has a (hidden) runtime pack/unpack cost. Better not teaching new programmers bad habits ;)

Hi thorium,

The reason for using dynamic was that was how it is done in the playerConnecting event within the scripting reference. Though I did assume setKickReason could've been a string, I just didn't test it to confirm. I'll edit that shortly.

I completely agree it would be bad to teach bad habits!

Luke20201 avatar Jul 03 '22 12:07 Luke20201

The reason for using dynamic was that was how it is done in the playerConnecting event within the scripting reference. Though I did assume setKickReason could've been a string, I just didn't test it to confirm. I'll edit that shortly.

I see :thinking: From looking into the source it looks like that parameter will be of type CallbackDelegate (CitizenFX.Core.CallbackDelegate to be precise). The deferrals on the other hand might just be better of as a dynamic, looks like that would be an ExpandoObject which is related to them.

thorium-cfx avatar Jul 03 '22 13:07 thorium-cfx

Hello, I am just reading through this post. Since I am also interested in improving the docs.

Only unfortunately I notice that it is always mentioned how some elements like "NetworkCallBackDelegate" are deprecated, but no working alternative is mentioned.

Is there any update?

ThePawlow avatar Dec 19 '22 11:12 ThePawlow

Going to close this, C# documentation will be improved later.

AvarianKnight avatar Aug 15 '24 19:08 AvarianKnight