What is the ban syntax?
 

What is the ban syntax?

Started by Driveways, 13 September, 2008, 02:23:32

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Driveways

I'm rebuilding Mutor's share checker script for the new API to use on my school's DC hubs.
It's just about finished but I need to know what the syntax is for a temporary ban by ip.

Here's the code if anyone's interested. It's a bit sloppy but it works and I wasn't making it for public release. :P


--[[Share Enforcer. Allows you to set the number of days before a user is kicked for being under a specified share limit.]]


admin = "Driveways" -- change to your nick

-- {w,x,z} w = whether to check user tye 1=check 0=don't; x = days before the user is kicked; z = minimum share in MB
Share = {
	 [0] = {0,5,300},   -- Master
	 [1] = {0,5,300},   -- Operator
	 [2] = {0,5,300},   -- VIP
	 [3] = {0,5,300},   -- Registered
	 [-1] = {1,3,300},  -- Unreg
}

Bytes = 1048576
File = "usertimes.dat"

---------------------------------------------------------

OnStartup = function()
	if loadfile(File)
	then	
	dofile(File) 
	else
	usert = {}
	SaveToFile(File,usert,"usert")
 end
end

OnExit = function()
SaveToFile(File,usert,"usert")
end

----------------------------------------------------------


MyINFOArrival = function(user,data)
	Core.GetUserAllData(user)

	if Share[user.iProfile] then
		local day 	= tonumber(os.date("%j"))
		local shared	= tonumber(user.iShareSize)
		if shared == nil then
			shared = 0
		local minShare 	= Share[user.iProfile][3]*Bytes
		local minNr 	= Share[user.iProfile][2]
		local name 	= user.sNick
		local dayD	= (tonumber(os.date("%j")) - usert[user.sNick][1])		
	end

	if usert[user.sNick] == nil then
		--Core.SendPmToNick("Driveways","Share Enforcer"," "..user.sNick.. "\n \t\tMyInfo received, current share size is ".. string.format(" %4.2f", (shared/Bytes)) .."MB, minimum required is "..Share[user.iProfile][3].."MB.")
		Core.SendPmToNick(admin,"Share Enforcer","New user '"..user.sNick.."' registered. Logging information.")

		if shared < (Share[user.iProfile][3]*Bytes) then
			Core.SendPmToNick(admin,"Share Enforcer","Violation! \nUser is in violation of sharing policy, they have ".. string.format(" %4.2f", (shared/Bytes)) .."MB shared. \n ")
			Core.SendPmToNick(user.sNick,"Share Enforcer", "You don't currently have enough shared. A bare minimum of ".. Share[user.iProfile][3] .."MB is required. \n If you do not have the minimum required in ".. Share[user.iProfile][2] .." days from today you will be banned from the hub for one week. If you need help, just ask in main chat.")
			Core.SendToAll("<Share Enforcer> "..user.sNick.." you are leeching, if your shared data does not increase to a minimum of "..Share[user.iProfile][3].."MB in ".. Share[user.iProfile][2] .." days you will be banned for .")
			usert[user.sNick] = {day,shared,0}
			SaveToFile(File,usert,"usert")
		return 1
		else
			Core.SendPmToNick(admin,"Share Enforcer","User has an acceptable amount of data shared. \n   ")
			usert[user.sNick] = {999,shared,0}
			SaveToFile(File,usert,"usert")
		end
	end
	local dayD	= (tonumber(os.date("%j")) - usert[user.sNick][1])
	if usert[user.sNick] and (usert[user.sNick][1] < 999) and (usert[user.sNick][2] < Share[user.iProfile][3]*Bytes) and ((tonumber(os.date("%j")) - usert[user.sNick][1]) > usert[user.sNick][3]) then
		Core.SendPmToNick(admin,"Share Enforcer",""..user.sNick.." is continuing to leech, they have been leeching for "..dayD.." days.\n ")
		Core.SendPmToNick(user.sNick,"Share Enforcer","You are continuing to leech, you need to increase your share size to "..Share[user.iProfile][3].." before ".. Share[user.iProfile][2] .." days is up! It has been "..dayD.." days.")
		Core.SendToAll("<Share Enforcer> "..user.sNick.." has been leeching for "..dayD.." days.")
		usert[user.sNick][3] = (usert[user.sNick][3] + 1)
	end
	if (usert[user.sNick][2] < Share[user.iProfile][3]*Bytes) and (usert[user.sNick][1] == 999) then
		usert[user.sNick][1] = tonumber(os.date("%j"))
		usert[user.sNick][3] = 0
		Core.SendToAll("Share Enforcer"," "..user.sNick.." has dropped below the share threshold!")
	end
	if dayD == Share[user.iProfile][2] then
	Core.SendPmToNick(admin,"Share Enforcer",""..user.sNick.." is over the limit, ban that fucker.")
	--This is where I need the ban code.
	end
	
		
end
end

Save_Serialize = function(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n" )
	for key, value in pairs(tTable) do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
		if(type(value) == "table") then
			Save_Serialize(value, sKey, hFile, sTab.."\t")
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value)
			hFile:write( sTab.."\t"..sKey.." = "..sValue)
		end
		hFile:write( ",\n")
	end
	hFile:write( sTab.."}")
end

SaveToFile = function(file,table , tablename )
	local hFile = io.open(file , "w")
	Save_Serialize(table, tablename, hFile);
	hFile:close()
	collectgarbage("collect")
end


Thanks to mutor for making the original, it was a great example to learn some LUA off of.

Driveways

Thanks for the quick reply, I didn't realize the docs were sitting right in front of me.  ::)

Driveways

Yeah, I know better, just being lazy. I changed the nick logging to IP logging and figured added commenting to it.
I figure instead of a ban I can just have it check to see if the user has fixed their shares on join and boot them if they haven't. That way I can send a message too.

Driveways

Okay, so the script is practically finished. The only thing left is to implement something that will disconnect users who are over the limit.
" if dayD >= Share[user.iProfile][2] then "
dayD is the number of days it has been since there initial connection
Share[user.iProfile][2] is the number of days after that intial connection that they are allowed to have less than the minimum share.
But I'd also like to send the user a short message before it disconnects them, giving them information on how to set up sharing. This is a university hub so we get a lot of people who are pretty ignorant about that sort of stuff, but have DC set up for them by a friend.
This should be a pretty simple function that gets called on user connection, so if anyone has some suggestions for the code that would be greatly appreciated.

Any general comments on the script would be welcome too.

--[[Share Enforcer. Allows you to set the number of days before a user is kicked for being under a specified share limit.]]


admin = "Driveways" -- change to your nick

-- {w,x,z} w = whether to check user type 1=check 0=don't; x = days before the user is kicked; z = minimum share in MB
Share = {
	 [0] = {0,2,300},   -- Master
	 [1] = {0,5,300},   -- Operator
	 [2] = {0,5,300},   -- VIP
	 [3] = {0,5,300},   -- Registered
	 [-1] = {1,3,300},  -- Unreg
}

Bytes = 1048576
File = "usertimes.dat"

---------------------------------------------------------

OnStartup = function()
	if loadfile(File)
	then	
	dofile(File) 
	else
	usert = {}
	SaveToFile(File,usert,"usert")
 end
end

OnExit = function()
SaveToFile(File,usert,"usert")
end

----------------------------------------------------------


MyINFOArrival = function(user,data)
	Core.GetUserAllData(user)

		local day 	= tonumber(os.date("%j"))
		local shared	= tonumber(user.iShareSize)
		if shared == nil then
			shared = 0
			end


---------------------------- New User
	if usert[user.sIP] == nil then
		Core.SendPmToNick(admin,"Share Enforcer","New user '"..user.sNick.."' registered. Logging information.")
	------------ Not enough Shared
		if shared < (Share[user.iProfile][3]*Bytes) then
			Core.SendPmToNick(admin,"Share Enforcer","Violation! \nUser is in violation of sharing policy, they have ".. string.format(" %4.2f", (shared/Bytes)) .."MB shared. \n ")
			Core.SendPmToNick(user.sNick,"Share Enforcer", "You don't currently have enough shared. A bare minimum of ".. Share[user.iProfile][3] .."MB is required. \n If you do not have the minimum required in ".. Share[user.iProfile][2] .." days from today you will be temporarily banned from the hub. If you need help, just ask in main chat.")
	--		Core.SendToAll("<Share Enforcer> "..user.sNick.." you are leeching, if your shared data does not increase to a minimum of "..Share[user.iProfile][3].."MB in ".. Share[user.iProfile][2] .." days you will be banned.")
			usert[user.sIP] = {day,shared,0,user.sNick}
			SaveToFile(File,usert,"usert")
		return 1
	------------ Sufficient Shares
		else
			Core.SendPmToNick(admin,"Share Enforcer","User has an acceptable amount of data shared. \n   ")
			usert[user.sIP] = {999,shared,0,user.sNick}
			SaveToFile(File,usert,"usert")
		end
	end
---------------------------- Existing User
	if usert[user.sIP] then
		usert[user.sIP][2] = shared
		usert[user.sIP][4] = user.sNick
		SaveToFile(File,usert,"usert")
	end
---------------------------- Existing User, now has enough shared
	if usert[user.sIP] and (shared > Share[user.iProfile][3]*Bytes) then
		usert[user.sIP] = {999,shared,0,user.sNick}
	SaveToFile(File,usert,"usert")
	end
---------------------------- Existing User drops below minimum share
	if (usert[user.sIP][2] < Share[user.iProfile][3]*Bytes) and (usert[user.sIP][1] == 999) then
		usert[user.sIP][1] = tonumber(os.date("%j"))
		usert[user.sIP][3] = 0
--		Core.SendToAll("<Share Enforcer> "..user.sNick.." has dropped below the minimum share threshold!")
	SaveToFile(File,usert,"usert")
	end
----------------------------
	local dayD	= (tonumber(os.date("%j")) - usert[user.sIP][1])
---------------------------- Next Day of Leeching
	if usert[user.sIP] and (usert[user.sIP][1] < 999) and (usert[user.sIP][2] < Share[user.iProfile][3]*Bytes) and (dayD > usert[user.sIP][3]) then
		Core.SendPmToNick(admin,"Share Enforcer",""..user.sNick.." is continuing to leech, they have been leeching for "..dayD.." days.\n ")
		Core.SendPmToNick(user.sNick,"Share Enforcer","You are continuing to leech, you need to increase your share size to "..Share[user.iProfile][3].." before ".. Share[user.iProfile][2] .." days is up! It has been "..dayD.." days.")
	--	Core.SendToAll("<Share Enforcer> "..user.sNick.." has been leeching for "..dayD.." days.")
		usert[user.sIP][3] = (dayD)
		SaveToFile(File,usert,"usert")
	end
---------------------------- Time limit is Up
	if dayD >= Share[user.iProfile][2] then
	Core.SendPmToNick(admin,"Share Enforcer",""..user.sNick.." is over the limit, ban that fucker.")
	SaveToFile(File,usert,"usert")
	end
end		



Save_Serialize = function(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n" )
	for key, value in pairs(tTable) do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
		if(type(value) == "table") then
			Save_Serialize(value, sKey, hFile, sTab.."\t")
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value)
			hFile:write( sTab.."\t"..sKey.." = "..sValue)
		end
		hFile:write( ",\n")
	end
	hFile:write( sTab.."}")
end

SaveToFile = function(file,table , tablename )
	local hFile = io.open(file , "w")
	Save_Serialize(table, tablename, hFile);
	hFile:close()
	collectgarbage("collect")
end

SMF spam blocked by CleanTalk