Page 1 of 1

Global variables and multiplayer considerations?

Posted: Sat Oct 10, 2015 10:11 am
by SuicideKing
So two questions specific to multiplayer and global variables:

#1

If my init.sqf has the following line:

Code: Select all

counterVar = 0;
and in an editor placed trigger I write:

Code: Select all

counterVar = counterVar +1;
Assuming the clients aren't doing anything with the variables later, is doing the following pointless (in the trigger mentioned above)?:

Code: Select all

if (isServer) then { counterVar = counterVar +1}
#2
I was reading through the BIS wiki on variables, and there's this part in the end (Multiplayer Considerations):
Storing vars and functions into global vars without securing them with compileFinal is a very bad practice in MP. Basically, if you have a script installed on a server in mission file that uses functions stored in unprotected variables then hackers can overwrite that function attached to a global variable and make it execute code for everyone and do a lot of nasty stuff. So please put all of the code for each function in a SEPARATE file and initialize them like this:

Code: Select all

myGlobalVarFunction = compileFinal preprocessFileLineNumbers "Dir\where\function\is\fnc_globalVarFunction.sqf";
That way, the function can be called and spawned without it being subject to hackers that attempt to overwrite the global variable "myGlobalVarFunction".
Should I be doing this with the simple global variable initialised in init.sqf above?

Re: Global variables and multiplayer considerations?

Posted: Tue Oct 13, 2015 6:31 am
by Pooter
#1 It doesn't really matter, as long as the client isn't accessing the value later.
#2 The BI stuff is primarily about storing functions into the global space, where any client could potentially overwrite its contents, then use the publicVariable command to broadcast the value to everyone else and you will unknowingly execute their code.
In order to take advantage of this though the hacker has to already be able to execute code in order to change the value, while our admins have the debug console I think normal players have no ability to execute arbitrary code.

Additionally the hacker would have to know the name of the variable and roughly what it is used for. Since we rarely re-use maps, it's not much of a consideration for us.

It's mainly an issue for mod makers and people that make popular maps that get run on public servers.

Re: Global variables and multiplayer considerations?

Posted: Tue Oct 13, 2015 9:21 am
by SuicideKing
Thanks a lot, Pooter!