Jump to content

Exporting function client-side that contains ACL functions


Hale

Recommended Posts

Hi, I'm trying to find the best and fastest (when it comes to performance) way to export a function 'getAccountAdminLevel' to client-side, the problem is it contains some MTA functions that are made server-side only. I know a few ways already but find them quite unstable and too long for such a simple task. Does anyone have any ideas or suggestions?

function getAccountAdminLevel(player)
	if not player or not isElement(player) or not getElementType(player) == "player" then return 0 end
	
	local account = getPlayerAccount(player)
	if not account or isGuestAccount(account) then
		return 0
	end
	local acc = getAccountName(account)
	if not acc then
		return 0
	end
	acc = "user."..acc
	local adminLevel = "Player"
	local groupList = aclGroupList()
	for i=1, #groupList do
		local groupName = aclGroupGetName(groupList[i])
		if not unwantedGroups[groupName] and isObjectInACLGroup (acc, groupList[i]) then
			adminLevel = groupName
		end
	end
	for i=1, #adminLevels do
		if adminLevel == adminLevels[i] then
			return i
		end
	end
	return 0
end

 

Thanks in advance!

Link to comment

The best option with a script like this, where you will need to access the same data so many times, maybe even in renders (ie. displaying [ADMIN] in the player's name) you are better of using setElementData when the user logs in. 

Link to comment
8 minutes ago, pa3ck said:

The best option with a script like this, where you will need to access the same data so many times, maybe even in renders (ie. displaying [ADMIN] in the player's name) you are better of using setElementData when the user logs in. 

 

I'm trying to avoid using that function as much as possible for the sake of performance, do you have any other ideas?

Link to comment

I never understood why people think that using element data is worse than triggering many server events? I mean aren't they doing the same thing? Communicating between the client and server? Or is it because of the RAM? Why do people think element data is performance killer? 

If you're really concerned about performance (honestly, it doesn't really matter unless you're building a server that has an avg. of 300+ players), you can send everything to the client once, when they log in and whenever a new data is created on the run, let the client know about it.

Link to comment

I can safely say that setElementData is no performance killer or anything. My server has 90 resources running and whenever I needed to send data from server to client (or vice versa) I used element data. And the (little xd) players that have played there didn't experience any lag from element data (if they did, their pc laptop was a potato and couldn't handle a few resources, nothing to do with element data).

@pa3ck Actually I think that using triggers should theoretically be a bigger performance killer because with element data you send it once and then any resource can use it, but with events - you need to send the data separately to each resource that needs it.

But the difference should be unnoticable for the normal player so it's the same which one you choose to use, be it element data or events.

  • Like 1
Link to comment

Element data doesn't create lags for servers with a smaller playerbase, but it's different when it comes to servers with 100+ players... I doubt using one or two element data's for players will make some lag, so I'll probably use that. If anyone does have a suggestion please post one!

  • Like 1
Link to comment
  • Moderators

 

Elementdata:

  • Uses ~7x times less data in comparison with the triggerEvent. (I haven't been able to test it with accurate results, but you can assume it is 7 times less usage.)
  • Automatic send to new joiners, because it becomes part of the element itself.
  • Disable synchronization can be useful for sharing data between resources without wasting the network.

 

triggerEvent:

  • Normal triggerEvent variant sends faster data than elementdata.
  • Latent trigger event can be used. (The latent variable, which makes it possible to send it slowly and without blocking the network)
  • Can be send to a specific player / list. (Which makes it possible to reduce network usage for clients that don't need the data.)
  • Afaik it can handle large amount of data better.

 


For a nametag, elementdata wouldn't be a bad idea. Since everybody in the server need to see that a specific player is admin, right?

 

So it is better to pick the method that suits best for the situation.

And it is even better if you mind disabling synchronization when you only need it one side.

 


Elementdata can indeed ruin your server if you use it not carefully enough. Take a look at the mini-mission server, it laggs like hell.

 


Edited by IIYAMA
  • Like 2
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...