#C#/.NET Server Wrapper
A temporary wrapper to let servers support C#/.NET server-side scripts until FXServer is available.
##Source-code + Example script
To build a script, add reference to System.ComponentModel.Composition and the ServerWrapper binary, inherit the ServerScript class and add the Export attribute to it with the typeof() interface IServerScript, the project has to be built for .NET Framework 4.6.1 targeting x64.
** Dependencies that aren’t other scripts go to the server’s root folder since the scripts’ domain base folder is the same as the server domain’s, this is intentional, use this class and add the dependencies as embedded resources to the project if you wish to avoid bloating the server folder.
##Download
##Setup
Download the zip archive from the link above
Make sure you’re using the latest CitizenMP.Server available
Drag and drop all the files and folders onto the root folder of the server (where “CitizenMP.Server.exe” is located)
Make sure all the assemblies (*.dll) are unblocked (Right click -> Properties -> “Unblock” if available).
Add ServerWrapper as a resource in the server config
Add any scripts to the “Scripts” subfolder inside the ServerWrapper folder.
Updated to 1.1, see releases on GitHub for changes.
I’ve included a proof-of-concept MySQL script to demo use cases of the wrapper - queries can be executed on a separate thread, no longer stalling the main thread, which should reduce instancing (with the provided code callbacks are invoked back on the main thread).
EDIT: Update 1.2 will address some issues people were having. As for anyone experiencing issues with the “/example” command in the example script, I haven’t actually tested the command in-game and forgot that the color array is a NeoLua type which cannot be marshaled, causing an error when used, I’ll try to work on a workaround devs would manually configure, although it would likely require a server restart when you add/remove other events to the workaround.
I do. but if i take all files in the ServerScriptExample download on latest release on github, the result is exatly the same way, crash after creating proxy.
I detect one problem of AddEventHandler() when i get my event this function dont send the source of event.
And on playerConnecting event i cant get identifier of player call this event because is not registered yet in ReadOnlyDictionary<ushort, Player> PlayersByNetId or ReadOnlyDictionary<string, Player> Players, and GetPlayerIdentifiers crash with Player null.
You need to explicitly add “source” as a parameter in the event handler, see how chatMessage is handled in the example script.
Seems like chatMessage passes source and other events aren’t handled the same way, working on a way to obtain “source” now.
PlayersByNetId and Players are both cloned from the server’s internal dictionaries, if the player is not available there, then the server hasn’t added said player to the dictionaries yet. The GetPlayerSOMETHING functions are all based on the dictionaries, there’s no point using them if you know the player isn’t in the dictionary.