Help needed to convert TagCheck 1.0 LUA 5.1 by Mutor
 

Help needed to convert TagCheck 1.0 LUA 5.1 by Mutor

Started by miago, 21 April, 2008, 10:14:04

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

miago

Hi all.

Would be glad if this script could be converted so it works with ptokax 0.4.0.0.
Thanx in advance

Edit: Maybe it will need a total rewrite and not only a conversion, I have no grip on that, but thx if U find the time.

--[[

	TagCheck 1.0 LUA 5.1
	By Mutor	01/21/07
	
	Requested by miago
	
	Checks min/max slots and max hubs for specified reg prefix tags
	
]]

--Script configuration
Cfg = {
-- Admin's nick for status / error messages
OpNick = "OPtest",
-- Name for bot
Bot = "TagCheck",
-- Profile to check
Profile = 3,
--["Tag"] = {minslots,maxslots,maxhubs}.
--Use lower case here
Params = {
	["[0.2mbit]"] = {1,2,3},	
	["[0.5mbit]"] = {1,2,3},
	["[0.7mbit]"] = {1,2,3},
	["[0.8mbit]"] = {1,2,3},
	["[1mbit]"] = {2,3,4},
	["[2mbit]"] = {2,3,4},
	["[online]"] = {1,6,5},
	["[2.5mbit]"] = {3,4,4},
	["[3mbit]"] = {3,4,4},
	["[5mbit]"] = {3,4,4},
	["[8mbit]"] = {4,6,5},
	["[9mbit]"] = {4,6,5},
	["[10mbit]"] = {4,6,5},
	["[20mbit]"] = {4,6,5},
	["[25mbit]"] = {4,6,5},
	["[30mbit]"] = {4,6,5},
	["[40mbit]"] = {4,6,5},
	["[50mbit]"] = {4,6,5},
	["[100mbit]"] = {4,6,5},
	},
}

OnError = function(msg)
	SendToNick(Cfg.OpNick,"<"..Cfg.Bot.."> "..msg)
end

MyINFOArrival = function(user,data)
	if user.iProfile == Cfg.Profile then
		local s,e,tag = string.find(user.sName,"^(%b[]).+")
		if tag then
			--convert any [valid] tag (any case) to lower case for comparison
			tag = string.lower(tag)
			if Cfg.Params[tag] then
				CheckUser(user,tag)
			else
				OnError(GetProfileName(user.iProfile).." "..user.sName.." is using an invalid prefix tag")
			end
		else
			OnError(GetUserProfile(user.sName).." "..user.sName.." is missing a prefix tag")
		end
	end
end

CheckUser = function(user,tag)
	local Msg,Kick = "",false
	for i,v in ipairs(Cfg.Params[tag]) do
		if i == 1 and user.iSlots < v then
			Msg = Msg.."You have too few slots open. "..tag.."'s are required to have a minimum of "..
			v.." slots open. You have only "..user.iSlots
			Kick = true
			break
		elseif i == 2 and user.iSlots > v then
			Msg = Msg.."You have too many slots open. "..tag.."'s are required to have a maximum of "..
			v.." slots open. You have "..user.iSlots
			Kick = true
			break
		elseif i == 3 and user.iHubs > v then
			Msg = Msg.."You are in too many hubs. "..tag.."'s are required to have a maximum of "..
			v.." hub connections. You are connected to "..user.iHubs
			Kick = true
			break
		end
	end
	if Kick then
		local nick = user.sName
		local OpMsg = string.gsub(Msg,"You have", user.sName.." has")
		OpMsg = string.gsub(OpMsg,"You are", user.sName.." is")
		SendToOpChat("<"..Cfg.Bot.."> "..OpMsg)
		user:SendData(Cfg.Bot,Msg)
		user:Disconnect()
		if not GetItemByName(nick) then
			SendToOpChat("<"..Cfg.Bot.."> "..nick.." has been removed from the hub.")
		end
	end
end
Being a biatch aint easy ;)

miago

Being a biatch aint easy ;)

miago

This works great  :D :-*

Only strange thing was that I had to change what prof it should check, from 3 to 4. When having 3 it checked VIP.
Atm I havent got any all-in-one script running, so the profiles Ive got in ptokax are Master, Operator, VIP, Reg, NetFounder and Moderator so maybe its therefor, but at least I know where to change it.

Many thanks to U for the work U've done.
Regards
miago
Being a biatch aint easy ;)

miago

Hi.

Have tested with clean ptokax and only tagcheck.lua to try to see where the problem was.

1st time I registered some users manually in ptokax and started the hub and the tagcheck worked as it should with 3 as profilecheck when a reguser entered.
2nd time I copied the registeredusers.xml from my hub running now (doublechecked that all profilesnr were ok in that file and they were), started the ptokax, started the hub and when a reguser entered in to the hub, nothing happened. Changed the profcheck to 4 and it worked. In registeredusers.xml the profilenr for reg was still 3.

Seems like something happens somewhere when I copy the file that stirs it up, so my conclusion is that Im gonna have to register all users manually before starting up the new ptokax. At least now I know what caused the problem.

Regards
miago
Being a biatch aint easy ;)

SMF spam blocked by CleanTalk