Jump to content
celludriel

Best way to create admin functions

Recommended Posts

Hey,

 

I'm looking for the best way to create admin scripts on server side, that can be called with remoteExecCall.  Take this one for example,

 

<fn_adminListSectors.sqf>

if(!isDedicated) exitWith {};

_sectorTags = [];

{
	_sectorTag = _x getVAriable ["markerName"];
	_sectorTags pushBack _sectorTag;
} forEach CTI_SECTOR_OBJECTS;

[format ["%1", _sectorTags]] remoteExecCall ["hint", <find a way to get the calling clientID>];

This function should return a list of all sector tags I have in my map.  It's configured like this:

class CTITemplateServerFunctions {
	tag = "CTISRV";

	class CTISRVInitialize {
		file = "core\server\functions";

		class adminListSectors {};
	};
};

I had hoped to call it from any client with:

[] remoteExecCall ["CTISRV_fnc_adminListSectors", 2];

But I haven't seen anything in the documentation yet, how I can find the calling client ID at server side (or I looked over it).  I'm open for other suggestions to make admin functions and how to call them though.

Share this post


Link to post
Share on other sites

Well I got a sollution not sure it's the best but best I could come up with

if(!isDedicated) exitWith {};

params ["_player"];

diag_log format ["Calling adminListSectors with %1", _player];

_sectorTags = [];

{
	_sectorTag = _x getVariable "markerName";
	_sectorTags pushBack _sectorTag;
} forEach CTI_SECTOR_OBJECTS;

_output = format ["%1", _sectorTags];
[[_output]] call CTISHR_fnc_ctiLog;
(_output) remoteExecCall ["hint", (owner _player)];

calling it with

[player] remoteExecCall ["CTISRV_fnc_adminListSectors", 2];

 

Share this post


Link to post
Share on other sites

What I would add to this is to keep all your admin scripts/functions on the server so that it is harder for clients (and potential hackers) to be able to get access to them and to execute them. Also, with regards to remote executing and security you may also want to have a look at this page: https://community.bistudio.com/wiki/Arma_3_Remote_Execution

 

It might  be worth building in something into the server config/game files that has the ability to 'whitelist' player UID's when attempting to remoteExec certain functions

 

Hope this is useful,

Bull

 

 

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, bull_a said:

What I would add to this is to keep all your admin scripts/functions on the server so that it is harder for clients (and potential hackers) to be able to get access to them and to execute them. Also, with regards to remote executing and security you may also want to have a look at this page: https://community.bistudio.com/wiki/Arma_3_Remote_Execution

 

It might  be worth building in something into the server config/game files that has the ability to 'whitelist' player UID's when attempting to remoteExec certain functions

 

Hope this is useful,

Bull

 

 

 

I wasn't worried about security yet since I'm still full in development, but this will have to be done.  Thanks for reminding me

Share this post


Link to post
Share on other sites

If you need to get the clientID when doing a remoteExecute on the server, the best method is to pass it in as a parameter like so to remoteExec, just before the code is executed on the server:
 

[clientOwner, {_clientID = _this; ...}] remoteExec ["bis_fnc_call", 2];

This example is one way, there are other ways of calling remoteExec that don't rely on bis_fnc_call. You would only use bis_fnc_call on anonymous functions/code that is not defined globally for example. This is how I implemented global events and remote handlers.

If you have multiple admin scripts that you need access to, you could do something like this with IGN_EH: IGN_EH

if (isDedicated) then
{ 
	// create an AdminCallRequested event, with parameters ["fncName", clientID, params]
	SERVER_EVT_AdminCallRequested = [["", 0, [] ], "SERVER_EVT_AdminCallRequested", true] call IGN_fnc_createEvent;

	AdminCallRequestedHandler = ["SERVER_EVT_AdminCallRequested",
	{
		params["_fnc", "_clientID", "_params"];
		// use your method for validating the client has permissions to run
		// if _fnc is a valid function on server

		call compile format ["_adminFnc = %1", _fnc];	// this will strip the quotes off _fnc, so that "MyFunction" becomes MyFunction 
		_data = _params call _adminFnc;

		// get some data and return it to remote caller
		_data remoteExec ["hint", _clientID];
	}] call IGN_fnc_addEventHandler;
};

// somewhere locally on a machine...
["AdminGetSectors", clientOwner, [someArgs, 0, ...] ] call IGN_fnc_raiseEvent;

This will create a global event that the server owns, with a server side handler. When a client raises the event, the server handler takes the clientID passed in and can do some validation to ensure the proper client has access. It's a somewhat contrived example, as it's not completely secure, since all clients are aware of the event and can register their own handlers or raise it. But this should hopefully give you some ideas for getting what you want done.

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×