Jump to content
Elliot Beckett

Server side mod help needed - Reading content from external file

Recommended Posts

Help me BI Forums, you're my only hope <3

 

Hey peeps, 

 

I have searched and searched on the forums, wiki, Reddit and just about everywhere I can to try to find the answers I need, but my code still doesn't work. I have come to the wonderful people here to seek help and answers, I need my guardian Jedi Knight of Coding. 

 

So, I am basically setting up a good old whitelist that will run a certain function for the players in the whitelist but not in there are a certain unit type (I will post the code in a bit). I have the UID's of the players stored in an external .txt file, this is because we want to create a web-based API to write new UID's to that file (though that is not what I am dealing with) and we don't want to have to keep updating the mod. The Whitelist function is a server-side mod and the function it is calling is in a separate mod (Again, I will post the code below). I have tried every suggestion that I have found, and none of them seem to work when connecting to the server (works fine when I launch the server mods on my client and set up a game, go figure). On the server, the UID's are stored in the userconfig file in the root directory of the server (not in the mod).

 

I have got filepatching enabled on the server, both in the server.cfg and as a startup parameter, since I know that can be an issue

 

I am hoping that you will be able to help me work through these issues and provide some clarity, again I have tried my best to find answers but no luck. Also, this is kinda stretching my knowledge of coding (I am not that great at it), if someone can help me write the code I'd appreciate it. Sending me wiki pages doesn't help, unfortunately, I can't always wrap my head around them <3 

 

Anyways, the code:

 

Server side Mod

 

So, this is the content of the fn_AdminCheck.Sqf, the code that I want to check the UIDs and make sure players aren't a certain unit (That unit has the code called as part of its config, I don't need it to be loaded twice). I have also tried putting the userconfig file as part of the mod folder and called it using "@1BDE_Server\userconfig\admin.txt";

 

_adminUID = call compile preprocessFileLineNumbers "\userconfig\BDE\admins.txt";


if ((getplayerUID player in _adminUID) && !((typeOf player) in ["1BDE_Infantry_Intel_Officer"])) then
	{

		_this call BDE_fnc_AdminTools;
		player addEventHandler ["Respawn", {_this call BDE_fnc_AdminTools}];
	};

 

This is the Config.cpp for the server side mod. Now, I am not binarizing this mod (just building it into a .pbo). As you can see, I have tried using the #include "\userconfig\BDE\admins.txt". When I do that, it kicks up an error to do with my admin.txt, saying it encountered a " instead of a ]. From my research, it seems PostInit is my best option, since it is pointless to load this function before the units have been created? Would I need to add #include"<PathToAdminToolsfnc>";? I assume since it is a function, I wouldn't have to?

 

/*
	Name: 1BDE Mods - Server Files
	Author: Elliot Beckett
	Date: 08/12/19
	File Name: config.hpp
	Description: Main config file for the mod, this is an important file as it loads the other .hpp files.

*/

#define mag_xx(a,b) class _xx_##a {magazine = a; count = b;}
#define weap_xx(a,b) class _xx_##a {weapon = a; count = b;}
#define item_xx(a,b) class _xx_##a {name = a; count = b;}
#define pack_xx(a,b) class _xx_##a {backpack = a; count = b;}

//#include "units\cfgMarkers.hpp"

//#include "define_macros.hpp"

//#include "\userconfig\BDE\admins.txt";

class CfgPatches
{
	class 1BDE_Server
	{
		author="Elliot Beckett";
		url="https://1brigade.com/";
		units[] ={};
		weapons[] = {};
		version="v.0.1";
		requiredAddons[] =
		{

			"a3_characters_F",
			"a3_characters_F_beta",
			"A3_Characters_F_Common",
			"a3_characters_f_beta",
			"a3_characters_f_gamma",
			"1BDE_Units"
		};
	};
};

class Markers
{
    units[] = {};
    weapons[] = {};
    requiredVersion=1.00;
};

class CfgFunctions
{
	class BDE_Server_fnc
	{
		tag = "BDE_Server";
		class init
		{
			file = "1BDE_server\Functions\admin";
			class AdminCheck {postInit = 1;};

		};
	};
};

 

This is how I have the admin.txt filled at the moment (Just added the periods/full stops as a censor, the real file has complete UID's)

[ "7656.198076402..." , "7..611980.3722..." ];

 

 

 

If someone can give me a hand, I would really appreciate it. I have searched and searched, but can't seem to figure it out. I can add the code for the AdminTools function and also the way I have defined it in the other mod, but I know that it works as I am able to call the function manually.  

 

Thanks all <3

Elliot

 

 

 

Share this post


Link to post
Share on other sites
19 hours ago, Elliot Beckett said:

As you can see, I have tried using the #include "\userconfig\BDE\admins.txt". When I do that, it kicks up an error to do with my admin.txt, saying it encountered a " instead of a ].

if you include into a config file, thats the same as copy pasting the files contents.

a ["...", ".."] in a config file is a syntax error. config arrays are {"...", "..."}

 

19 hours ago, Elliot Beckett said:

_adminUID = call compile preprocessFileLineNumbers "\userconfig\BDE\admins.txt";

this seems inefficient.

_adminUIDs = parseSimpleArray loadFile "\userconfig\BDE\admins.txt"

what is your actual problem with that script code? it looks fine to me.

Share this post


Link to post
Share on other sites
6 hours ago, Dedmen said:

if you include into a config file, thats the same as copy pasting the files contents.

a ["...", ".."] in a config file is a syntax error. config arrays are {"...", "..."}

 

this seems inefficient.


_adminUIDs = parseSimpleArray loadFile "\userconfig\BDE\admins.txt"

what is your actual problem with that script code? it looks fine to me.

 

As I said, I am kinda new to all the coding side of things, this was what I stumbled across haha Just trying to throw together some code and see what happens? That's my approach to coding at the moment 😄

 

What the code is supposed to do, is give the admin tools to the people within the admin whitelist. The reason for this is I want the admins to have those tools no matter what role they are playing in, I know I can make an initPlayer.sqf or something like that, but I want to make it easier for mission makers so they don't have worry about forgetting to add that file etc. 

 

I will give your tweaks a whirl and see what happens 🙂 Thanks for the help 

Share this post


Link to post
Share on other sites

So as an update, I tried running the code with your updates and got an error. I will list both below

 

_adminUIDs = parseSimpleArray loadFile "\userconfig\BDE\admins.txt"


if ((getplayerUID player in _adminUID) && !((typeOf player) in ["1BDE_Infantry_Intel_Officer"])) then
	{

		_this call BDE_fnc_AdminTools;
		player addEventHandler ["Respawn", {_this call BDE_fnc_AdminTools}];
	};

The error I get is:

 

_adminUIDs = parseSimpleArray loadFile "\userconfig\B>
12:23:23   Error position: <parseSimpleArray loadFile "\userconfig\B>
12:23:23   Error Generic error in expression
12:23:23 File 1BDE_server\Functions\admin\fn_AdminCheck.sqf [BDE_Server_fnc_AdminCheck]..., line 3

Just in case I didn't mention it, the admin.txt is in the server root folder\userconfig file. I believe that pathing is correct? I haven't adjusted the admin.txt file from what I posted above and I have tried adding a semi-colon at the end of the _adminUIDs = parseSimpleArray loadFile "\userconfig\BDE\admins.txt" and still get the same error

Share this post


Link to post
Share on other sites

sorry forgot to tell, as the wiki page already tells you that.
 

for parseSimpleArray the text file content must look like

["1231243","1433424","2324323"]


no whitespace, no semicolon at end

 

15 hours ago, Elliot Beckett said:

I believe that pathing is correct?

if it weren't you would've gotten a different error.

Share this post


Link to post
Share on other sites
4 hours ago, Dedmen said:

sorry forgot to tell, as the wiki page already tells you that.
 

for parseSimpleArray the text file content must look like


["1231243","1433424","2324323"]


no whitespace, no semicolon at end

 

if it weren't you would've gotten a different error.

 

Ok, thanks man :) I will give this a try

Share this post


Link to post
Share on other sites
1 hour ago, Elliot Beckett said:

 

Ok, thanks man 🙂 I will give this a try

 

Unfortunately, no luck with this, it doesn't seem to add the function. 

 

If it is easier, I have uploaded all my code to Gitlab and also included the latest RPTI couldn't see anything personally, but you may be able to see where I am going wrong? Also, please forgive any janky code 😛 I am still a noob. 

 

There is no rush to get a solution as well, so don't spend hours pouring over my code or missing out on the holiday season, I am working on other parts of the mod. This is just a wishlist item really

 

Again, thanks for all of the help so far

Share this post


Link to post
Share on other sites
On 12/22/2019 at 12:23 AM, Elliot Beckett said:

it doesn't seem to add the function. 

Then has to be something wrong in CfgFunctions, but that looks correct to me.

Also no errors in RPT.
You kept in mind that the function will only exist on serverside right?

Its name should be BDE_Server_fnc_AdminCheck and it should run on poooooooo........... Yes.. Thats it.

Its serverside only.
the player command returns objNull in dedicated server. Meaning getPlayerUID will just return "" (I assume, or something else similarly invalid)
Do you want the server to execute that code when a player joins, who is in the admin list?

You'll need a eventhandler for that.
there's https://community.bistudio.com/wiki/Arma_3:_Event_Handlers/addMissionEventHandler#PlayerConnected

but it doesn't give you the body the player is in.

Instead you could use https://community.bistudio.com/wiki/Arma_3:_Event_Handlers/addMissionEventHandler#EntityRespawned

just like you already use respawn.

For the BDE_fnc_AdminTools you have to think about server/clientside, you might want to remoteExec that over to the player.

 

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

×