blacklist system ip

Share your gamemodes and snippets here
Post Reply
Ahmed Ly
Posts: 6
Joined: Mon Mar 30, 2020 8:50 am

blacklist system ip

Post by Ahmed Ly » Fri Apr 03, 2020 9:43 am

hello people
This is a system that makes players unable to connect to the server by adding ip player on blacklist.txt
note: to run srcipt very well you must create blacklist.txt in folder you server

Also you can use on chat/add [name player] to add player on blacklist
----------------------------------------------------------------------
code

Code: Select all

local configuration = {
    ["blacklisted_names"] = {}
}
local blacklistConfig = 'blacklist.txt'
local Command = "/add"
function refreshdata ()
local file = io.open(blacklistConfig, "r")
	  if file then 
		for line in io.lines(blacklistConfig) do 
			table.insert(configuration["blacklisted_names"], line)	
		end
		file:close() 
	else
		print("Error: can not  blacklist.txt")
	end
end 
refreshdata ()
function output ()
	print("Found " ..#configuration["blacklisted_names"].. " blacklisted ")
	print("all players on blacklist")
	for i, v in ipairs(configuration["blacklisted_names"]) do
	print(" "..v.." ")
	end 
end 
output ()
 -- useful functions 
	function getplayerfromName (name)
		players = getPlayers()
	   for k, v in ipairs(players) do
		   if ( getPlayerName(v)  == name  ) then 
			return v
		  end 
	   end
	end

	
	function addPlayerToBlacklist (str)
		if str ~= "" then 
		local file_1 = io.open(blacklistConfig, "a")
		io.output(file_1)
		io.write(""..str.."\n")
		io.close(file_1)
    	end
	end 

function isUserBlacklisted(name)
	isWhitelisted = false
	for key, value in ipairs(configuration["blacklisted_names"]) do
		if configuration["blacklisted_names"][key] == name then
			print(" " ..configuration["blacklisted_names"][key].. " : "..name.." " )
			isWhitelisted = true;
			break;
		end
	end
	return isWhitelisted
end

local Command = "/add"


addCommand(Command, 
   function(playerid, params)
		 otherplayer = getplayerfromName(""..params[1].."")
		  serialotherplayer   = getPlayerIp(otherplayer)
         if playerid ~= otherplayer then 
        if isPlayerOnline(otherplayer) then 
		  sendPlayerMsg(playerid,"[BlackList] its will be added  "..getPlayerName(otherplayer).." To blacklist", 0xFFFFFFFF)
		  if not isUserBlacklisted(getPlayerName(otherplayer)) then
			addPlayerToBlacklist(""..serialotherplayer.."")
			refreshdata ()
			output ()
		else 
            sendPlayerMsg(playerid,"[BlackList] player is on  blacklist already	", 0xFFFFFFFF)
         end
     else
        sendPlayerMsg(playerid,"[BlackList] player not at server", 0xFFFFFFFF)
	  end 
	else
		sendPlayerMsg(playerid,"[BlackList] you  cant add youself to blacklist", 0xFFFFFFFF)
	end
	end
,nil)





function PlayerConnect(playerid)
  ipp = getPlayerIp(playerid)
 isBlacklisted = isUserBlacklisted(ipp)
	if isBlacklisted   then
		disconnectPlayer(playerid)
		return false
    end
    return true
end
registerEvent("PlayerConnect", "onPlayerCredential")

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest