OsO.cp

antiban

Recommended Posts

Hello guys, how can i make my script able to ban someone who tried to ban me on server?for example somebody tries to ban me, but gets ban instead of me and for me nothing happens

here's the undone one, which blocks to ban all admins

function onBan ( _, Player )
    for _, ban in ipairs( getBans() )do
        if isObjectInACLGroup ( "user."..getAccountName(getPlayerAccount(source)),aclGetGroup("Admin")) then
            if getPlayerName ( source ) == getBanNick( ban ) then
                if ( removeBan ( ban ) ) then
                    outputChatBox("This is a bad idea. :)",Player , 255, 255, 255, true)    
                end
            end
        end
    end
end
addEventHandler ( "onPlayerBan", root, onBan )

Edited by OsO.cp

Share this post


Link to post

I don't get what you're trying to do.

Players shouldn't have access to ban - why would admins be getting banned?

Share this post


Link to post
1 minute ago, LopSided_ said:

I don't get what you're trying to do.

Players shouldn't have access to ban - why would admins be getting banned?

because i have special type of server,  there is a lot of supermoderators

Share this post


Link to post

This isn't a problem you should initially be trying to solve with code. You shouldn't be giving people permissions on your server if you can't trust them.

However, something like this might help. If anyone tries to ban an admin the action will be blocked and they'll get banned them-self (Serial and IP ban).

function verifyBan(banPointer, responsiblePlayer)
    if getElementType(responsiblePlayer) ~= "player" then return false end
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) then
    	cancelEvent() --Cancel the ban on admin
    	addBan(getPlayerIP(responsiblePlayer), nil, getPlayerSerial(responsiblePlayer), root, "Banning other admins") --Ban the offending moderator
        outputChatBox (getPlayerName(responsiblePlayer).." has been banned for banning admins!", getRootElement(), 255, 0, 0) -- Output the ban.
    end
end
addEventHandler ( "onPlayerBan", getRootElement(), verifyBan )

Not tested, try it out and see if it works.

Edited by LopSided_

Share this post


Link to post
10 minutes ago, LopSided_ said:

This isn't a problem you should initially be trying to solve with code. You shouldn't be giving people permissions on your server if you can't trust them.

However, something like this might help. If anyone tries to ban an admin the action will be blocked and they'll get banned them-self (Serial and IP ban).


function verifyBan(banPointer, responsiblePlayer)
	if getElementType(responsiblePlayer) ~= "player" then return false end
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) then
    	cancelEvent() --Cancel the ban on admin
    	addBan(getPlayerIP(responsiblePlayer), nil, getPlayerSerial(responsiblePlayer), root, "Banning other admins") --Ban the offending moderator
        outputChatBox (getPlayerName(responsiblePlayer).." has been banned for banning admins!", getRootElement(), 255, 0, 0) -- Output the ban.
    end
end
addEventHandler ( "onPlayerBan", getRootElement(), verifyBan )

Not tested, try it out and see if it works.

just tested, doesnt work

Share this post


Link to post

I assume you used debugscript? Can you tell me what the errors are, or what exactly it is that doesn't work?

Edited by LopSided_

Share this post


Link to post
5 minutes ago, LopSided_ said:

I assume you used debugscript? Can you tell me what the errors are, or what exactly it is that doesn't work?

check out the pic: https://ibb.co/kBemqm

Share this post


Link to post

It would be better to modify the admin panel.

Go to admin/server/ and open admin_server.lua

search for this: at line ~855

elseif ( action == "ban" ) then

and add this line after it:

elseif ( action == "ban" ) then
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
  outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true)	return false end

 

Same goes for kick, if you want to.

if ( action == "kick" ) then
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
  outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true)	return false end

 

Note: this works with admin commands too.

Edited by King12

Share this post


Link to post
9 minutes ago, King12 said:

It would be better to modify the admin panel.

Go to admin/server/ and open admin_server.lua

search for this: at line ~855


elseif ( action == "ban" ) then

and add this line after it:


elseif ( action == "ban" ) then
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
  outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true)	return false end

 

Same goes for kick, if you want to.


if ( action == "kick" ) then
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
  outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true)	return false end

 

Note: this works with admin commands too.

tbh, i would like to have it as separate script, but i will check out this one

21 minutes ago, King12 said:

It would be better to modify the admin panel.

Go to admin/server/ and open admin_server.lua

search for this: at line ~855


elseif ( action == "ban" ) then

and add this line after it:


elseif ( action == "ban" ) then
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
  outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true)	return false end

 

Same goes for kick, if you want to.


if ( action == "kick" ) then
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
  outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true)	return false end

 

Note: this works with admin commands too.

that works, but what sense if it doesnt ban somebody who tried to ban me 

Edited by OsO.cp

Share this post


Link to post
14 minutes ago, OsO.cp said:

tbh, i would like to have it as separate script, but i will check out this one

I believe that is impossible, because onPlayerBan is triggered once the ban is added to the banlist.

  • Confused 1

Share this post


Link to post
Just now, King12 said:

I believe that is impossible, because onPlayerBan is triggered once the ban is added to the banlist.

what's about counter-ban? 

Share this post


Link to post
1 minute ago, OsO.cp said:

what's about counter-ban? 

remove the ban after it's added.

Share this post


Link to post
4 minutes ago, King12 said:

remove the ban after it's added.

noo, i just meant a function like: a guy which tried to ban me to gets banned instead of me 

Edited by OsO.cp

Share this post


Link to post
function outputBan ( banPointer, responsibleElement )
		if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) then
			for _,ban in ipairs(getBans()) do
			if getBanSerial(ban) == getPlayerSerial(source) then
				setTimer ( function() removeBan (ban) end, 1000, 1 )
			  local banner = getPlayerSerial ( responsibleElement ) or nil
			  if banner then
				addBan ( nil, nil, banner , root, "You were banned for banning a staff member")
				outputChatBox(getPlayerName(banner).." has been banned for banning a staff member")
			  else return 
			  end
			else return
			end
			end
		else return
		end
end
addEventHandler ( "onPlayerBan", getRootElement(), outputBan )

Other than that, is impossible.

Edited by King12

Share this post


Link to post
4 minutes ago, King12 said:

function outputBan ( banPointer, responsibleElement )
		if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) then
			for _,ban in ipairs(getBans()) do
			if getBanSerial(ban) == getPlayerSerial(source) then
				setTimer ( function() removeBan (ban) end, 1000, 1 )
			  local banner = getPlayerSerial ( responsibleElement ) or nil
			  if banner then
				addBan ( nil, nil, banner , root, "You were banned for banning a staff member")
				outputChatBox(getPlayerName(banner).." has been banned for banning a staff member")
			  else return 
			  end
			else return
			end
			end
		else return
		end
end
addEventHandler ( "onPlayerBan", getRootElement(), outputBan )

Other than that, is impossible.

i should apply this to the first one you wrote?

  1. elseif ( action == "ban" ) then
  2. if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then
  3. outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true) return false end

Share this post


Link to post

well, it doesnt work, if i've done everythin correctly

        elseif ( action == "ban" ) then
        if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
        outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true)    return false end
        function outputBan ( banPointer, responsibleElement )
        if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) then
            for _,ban in ipairs(getBans()) do
            if getBanSerial(ban) == getPlayerSerial(source) then
                setTimer ( function() removeBan (ban) end, 1000, 1 )
              local banner = getPlayerSerial ( responsibleElement ) or nil
              if banner then
                addBan ( nil, nil, banner , root, "You were banned for banning a staff member")
                outputChatBox(getPlayerName(banner).." has been banned for banning a staff member")
              else return 
              end
            else return
            end
            end
        else return
        end
end
addEventHandler ( "onPlayerBan", getRootElement(), outputBan )
            local reason = data or ""

Share this post


Link to post
6 minutes ago, OsO.cp said:

well, it doesnt work, if i've done everythin correctly

        elseif ( action == "ban" ) then
        if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
        outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true)    return false end
        function outputBan ( banPointer, responsibleElement )
        if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) then
            for _,ban in ipairs(getBans()) do
            if getBanSerial(ban) == getPlayerSerial(source) then
                setTimer ( function() removeBan (ban) end, 1000, 1 )
              local banner = getPlayerSerial ( responsibleElement ) or nil
              if banner then
                addBan ( nil, nil, banner , root, "You were banned for banning a staff member")
                outputChatBox(getPlayerName(banner).." has been banned for banning a staff member")
              else return 
              end
            else return
            end
            end
        else return
        end
end
addEventHandler ( "onPlayerBan", getRootElement(), outputBan )
            local reason = data or ""

You don't have to use the 2nd code [the latest], you just have to add this under elseif (action == "ban" ) then

elseif ( action == "ban" ) then
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then
outputChatBox( getPlayerName(source).."#ff0000 tried to ban you.", player, 255, 0, 0, true)
addBan ( nil, nil, source , root, "You were banned for banning a staff member")  return false end
local reason = data or ""
-- etc..

 

Edited by King12

Share this post


Link to post

        elseif ( action == "ban" ) then
        function outputBan ( banPointer, responsibleElement )
        if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) then
            for _,ban in ipairs(getBans()) do
            if getBanSerial(ban) == getPlayerSerial(source) then
                setTimer ( function() removeBan (ban) end, 1000, 1 )
              local banner = getPlayerSerial ( responsibleElement ) or nil
              if banner then
                addBan ( nil, nil, banner , root, "You were banned for banning a staff member")
                outputChatBox(getPlayerName(banner).." has been banned for banning a staff member")
              else return 
              end
            else return
            end
            end
        else return
        end
end
addEventHandler ( "onPlayerBan", getRootElement(), outputBan )
            local reason = data or ""

 

now its just bans the admin 

maybe its would be easier if u would add me on skype? because its kinda worse to talk like this

Share this post


Link to post

Code should be like this:

		elseif ( action == "ban" ) then
		  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then
		  outputChatBox( getPlayerName(source):gsub("#%x%x%x%x%x%x","").." has tried to ban you.", player, 255, 0, 0)
		  local banner = getPlayerSerial (source)
		  outputChatBox( getPlayerName(source):gsub("#%x%x%x%x%x%x","").." has been banned. [Reason: trying to ban staff member]", root, 255, 0, 0)
		  setTimer ( function () addBan ( nil, nil, banner , root, "You were banned for trying to ban a staff member") end, 500, 1) return false end
			local reason = data or ""
			local seconds = tonumber(additional) and tonumber(additional) > 0 and tonumber(additional)
			local bUseSerial = additional2
			local isAnonAdmin = getElementData(source, "AnonAdmin")
			-- etc..

 

Share this post


Link to post
5 minutes ago, King12 said:

Code should be like this:


		elseif ( action == "ban" ) then
		  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then
		  outputChatBox( getPlayerName(source):gsub("#%x%x%x%x%x%x","").." has tried to ban you.", player, 255, 0, 0)
		  local banner = getPlayerSerial (source)
		  outputChatBox( getPlayerName(source):gsub("#%x%x%x%x%x%x","").." has been banned. [Reason: trying to ban staff member]", root, 255, 0, 0)
		  setTimer ( function () addBan ( nil, nil, banner , root, "You were banned for trying to ban a staff member") end, 500, 1) return false end
			local reason = data or ""
			local seconds = tonumber(additional) and tonumber(additional) > 0 and tonumber(additional)
			local bUseSerial = additional2
			local isAnonAdmin = getElementData(source, "AnonAdmin")
			-- etc..

 

THAT FUKCING WORKS, Thank you so much, fam!

Edited by OsO.cp

Share this post


Link to post
1 minute ago, OsO.cp said:

THAT FUKCING WORKS, Thank you so much, fam!

You are welcome. :)

Share this post


Link to post
Just now, King12 said:

You are welcome. :)

ah forgot smth. the last question :D Is it possible to change the group from Admin to anything else?Or it won't work

Share this post


Link to post
14 minutes ago, OsO.cp said:

ah forgot smth. the last question :D Is it possible to change the group from Admin to anything else?Or it won't work

It's possible. You can even use two groups.

elseif ( action == "ban" ) then
		  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin") ) or isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Console") ) then

 

Edited by King12

Share this post


Link to post

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.