Jump to content
Sign in to follow this  
GuideZ

Whitelisting in Init.sqf

Recommended Posts

Ok, I'll admit I have no freaking clue what I am doing. The best response I have gotten to finding a user-whitelisting mod/addon was to "make one yourself". I pretty much suck at coding, and after hours of reading the wiki and forums posts and etc etc, this was the best I could come up with (which of course doesn't work). Please help!

//whitelist
onPlayerConnected "_allowedBool = false; playerID = _uid; playerName = _name";
whiteList = ["GUID_OF_USER_HERE_1","GUID_OF_USER_HERE_2"];
if (playerName == "__SERVER__") then {_allowedBool = true} else {
for "_i" from 0 to (count whiteList)-1  do {
currentWhite = whiteList select _i;
if (currentWhite == playerID) exitWith {_allowedBool = true};
};
};
if (_allowed = false) serverCommand format["#kick %1", player];

Share this post


Link to post
Share on other sites

Why not just password the server? :)

Also I think serverCommand has been disabled since 1.59

Maybe something like this

if (!isServer && isMultiplayer) then {
 _whiteList = ["12356","654321"]; // enter ID's here
 waitUntil {!isNull player};
 waitUntil {(getPlayerUID player) != ""};
 _id = getPlayerUID player;
 if (!(_id in _whiteList)) then {
   sleep 1;
   forceEnd;
 }; 
};

Untested, will only work in a MP game (not the editor).

Edited by cuel

Share this post


Link to post
Share on other sites

Because a password can be freely shared with others once given. I need total control of who can get in/out of the server. Gonna try out that code. Thanks!

---------- Post added at 11:03 ---------- Previous post was at 10:23 ----------

Hmm, that didn't seem to work. I tried it two ways:

Method one:

Put the code you mentioned into the init.sqf file. Packed PBO mission, still got into server.

Method two:

Added the following to init.sqf:

null=[] execVM "whtlist.sqf";

Wasn't sure where to put the "whtlist.sqf" file, so I placed it all over the place. Still didn't kick me when I entered the server. :/

*edit*

I think the code works dandy, it's just the actual "kick" portion doesn't work with "forceEnd". "forceEnd - Enforces mission termination. Can be used in an "END" trigger to force end conditions in the editor."

Share this post


Link to post
Share on other sites

Hmm forceEnd should work. Updated it, try it now, maybe you can't terminate until the mission is loaded.

Share this post


Link to post
Share on other sites

But I place that in the init.sqf file, correct? The mission is technically always running: User's connect and disconnect whenever they want. If they die they respawn, etc. Does that have an effect? Also, a bit confused: init.sqf is only run once when the first player joins or everytime a player joins and "reads" the mission?

---------- Post added at 11:49 ---------- Previous post was at 11:48 ----------

And extreme thanks to you sir for the help: I've been at this for days now :/

---------- Post added at 13:24 ---------- Previous post was at 11:49 ----------

Yeps, that didn't work either. I think it's because how the rest of the mods on the server are run that "forceEnd" doesn't do anything. Too bad that "serverCommand" was altered that way: If something is removed that way, they should provide an alternative.

Share this post


Link to post
Share on other sites

Didn't see your edits. Unfortunately I can't test this code since I don't have a good enough computer atm. But I'm sure forceEnd has worked before.

You could try editing the line that says forceEnd to

endMission "LOSER";

And see if that helps.

Are you running with -showScriptErrors? Maybe you need the functions module aswell.

EDIT: Oh, this will only work on a dedicated server / having someone connect to your server. You won't run the check as a listen server since that would forceEnd the mission for everyone :).

Edited by cuel

Share this post


Link to post
Share on other sites

I am pretty new to the whole "running your own server in ARMA 2" thing, XD. It's not as simple as running a Minecraft server (and I've had CraftBukkit before), but it's kinda cool that you have some granularity over what you can do.

I'll try out that new bit to the code (again, assuming I need to put it all in the Init.sqf file of my MPMission?). I didn't know -ShowScriptErrors existed till you mentioned it, I will try it all out when I get back from the office. I hate day jobs.

Share this post


Link to post
Share on other sites

You just need to put it inside your init.sqf in your mission folder and then you can export it as an MPMission in the editor. The SP and MP editor are the same.

Hosting a listen server is as easy as clicking on Multiplayer and then "New" :). A bit more complicated for a dedicated server.

Share this post


Link to post
Share on other sites

Cool beans, thanks! I am going to assume it doesn't fully matter if I export as MPMission or Single player, does it? I've just been updating the INIT.SQF file manually and re-packing it with CPBO

Share this post


Link to post
Share on other sites

That code doesn't run in single player. I think the only difference between exporting as MP/SP mission is where the .pbo file is placed. Export it as a MPMissions since that would place it in the correct folder (the MPMissions folder in your game folder) if you're hosting a listen server.

Share this post


Link to post
Share on other sites

I think I see what you mean now between listen/dedicated. Listen servers are ones I run just from my computer while in-game, and dedicated run with ARMA2OASERVER.exe, correct? If so, I am running the latter on a VPS, hence why I manually pack the files and just like that. The server and mission works and all, and I am sure that it's pulling the correct files (i've messed them up before), I was just curious as to where to place the code.

So if this whitelist works (wishful thinking on my part at this point), I am not going to want to have to reload the mission/restart the server everytime a whitelist adjustment is made. Would I then do something like the below in the INIT and just place the code/file somewhere outside of the mission file?

null[] = execVM "MyWhitelist.sqf";

Share this post


Link to post
Share on other sites

Correct.

You don't have to manually pack the pbo file. Export is as an MPMission in the editor, go into the folder called "MPMissions" in your A2/OA root folder, select the .pbo file and upload it :). But if you think it's easier to manually export it, whatever floats your boat.

The server would need to be restarted everytime you want to update the whitelist. The mission file is packed and loaded already and cannot be "edited" while running if you catch my drift. To get around that problem you would need to use some other addon, like ARMA2Net. Or write your own .dll file and use callExtension, unfortunately I can not help you with this.

Share this post


Link to post
Share on other sites

I asked the ARMA 2 Net regarding their Whitelist Plugin they had at one time, and the response was "Don't have anymore" and another "Go make it yourself". Sigh! At this point, I'll take anything that works.

Share this post


Link to post
Share on other sites

You my good sir, are the man! That worked! endMission worked! I love you.

Share this post


Link to post
Share on other sites

GuideZ, there was never any whitelist plugin. You must be confused with something else.

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
Sign in to follow this  

×