Global variables and multiplayer considerations?

Workshop for all Mission Engineer Comrades. Home of the FA Mission Making Template.

Global variables and multiplayer considerations?

Postby SuicideKing » Sat Oct 10, 2015 10:11 am

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?
themiddlevoid.wordpress.com
User avatar
SuicideKing
Host
 
Posts: 275
Joined: Wed Nov 27, 2013 1:29 pm
Location: India/Netherlands

Re: Global variables and multiplayer considerations?

Postby Pooter » Tue Oct 13, 2015 6:31 am

#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.
Pooter
Host
 
Posts: 116
Joined: Tue Jul 28, 2015 2:26 am

Re: Global variables and multiplayer considerations?

Postby SuicideKing » Tue Oct 13, 2015 9:21 am

Thanks a lot, Pooter!
themiddlevoid.wordpress.com
User avatar
SuicideKing
Host
 
Posts: 275
Joined: Wed Nov 27, 2013 1:29 pm
Location: India/Netherlands


Return to ArmA 3: Mission Making & F3 Development

Who is online

Users browsing this forum: No registered users and 1 guest