Automatic Profile Manager
 

Automatic Profile Manager

Started by panthera, 24 May, 2011, 12:46:38

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

panthera

Hello,

My hub has the following Profiles
================================================
    [SHARE SIZE]                [TAG]
    ================================================
    125 GB                         STAR
    250 GB                         WOW
    500 GB                         VIP
    1 TB                             VVIP
    ================================================

I wanted a script which will automatically upgrade and downgrade users according to their Shares.

I found a script which upgrades but does not downgrade please make the required changes and post the whole script back.

Thanks In Advance.

Panthera

Script:
RegConnected = function(User)
	if Core.GetUserValue(User,16) >= (500*(1024^3)) then       
		local tCurProf = ProfMan.GetProfile(User.iProfile)
		if tCurProf.sProfileName ~= "VIP" then                 
			local tCurReg = RegMan.GetReg(User.sNick)
			local tProfiles = ProfMan.GetProfiles()
			for k in pairs(tProfiles) do
				if tProfiles[k].sProfileName == "VIP" then      
					RegMan.ChangeReg(tCurReg.sNick, tCurReg.sPassword, tProfiles[k].iProfileNumber)
					Core.SendPmToUser(User,SetMan.GetString(21),"Your profile has been automatically updated to VIP.|")
				end
			end
		end
	end
end

Hamachi


panthera

Quote from: Hamachi on 24 May, 2011, 21:04:39
why downgrade  ?

So tat if the share come down he/she will get the lower profile......as one can hash data to become vip then lower it down.which will cause Profile problems...unequal distribution.....so wanted to add downgrade system also...........


PaNtHeRa

Madman

Give this a try...
I been out of PtokaX scripting for like a year or so, so script can be full of holes, errors, flawd logic and spelling misstakes and so on.
I'm to lazy to install a PtokaX on my pc, it's UNTESTED

tShareReg = {
	[0] = {1,"FailSafe"}, -- DO NOT EDIT!
	[1] = {125,"STAR"},
	[2] = {250,"WOW"},
	[3] = {500,"VIP"},
	[4] = {1024,"VVIP"},
}

RegConnected = function(User)
	local Size = ConvShare(User.iShareSize,"B")
	local tCurProf = ProfMan.GetProfile(User.iProfile)
	
	for i,t in ipairs(tShareReg) do
		ShareRegProf = t[2] -- Should work as a failsafe if user exeades latest profile upgrade
		if Size <= t[1] and Size >= tShareReg[i-1][1] then -- If share is less then current and higher then previous
			ShareRegProf = t[2] -- Get new profilename
		end
	end
	-- Time to set the ShareRegProf
	if tCurProf.sProfileName ~= ShareRegProf and SharRegProf ~= "FailSafe" then
		oldnr = tCurProf.iProfileNumber
			local tCurReg = RegMan.GetReg(User.sNick)
			local tProfiles = ProfMan.GetProfiles()
			for k in pairs(tProfiles) do
				if tProfiles[k].sProfileName == ShareRegProf then      
					RegMan.ChangeReg(tCurReg.sNick, tCurReg.sPassword, tProfiles[k].iProfileNumber)
					if tProfiles[k].iProfileNumber > oldnr then
						UnD = "updated"
						InD = "increased"
					else
						UnD = "downgraded"
						InD = "decreased"
					end
					Core.SendPmToUser(User,SetMan.GetString(21),"Your profile has been automatically " .. UnD .. " to " .. ShareRegProf .. " due to your share has " .. InD .. ".|")
				end
			end
	end
	
-- 	if Core.GetUserValue(User,16) >= (500*(1024^3)) then       
-- 		local tCurProf = ProfMan.GetProfile(User.iProfile)
-- 		if tCurProf.sProfileName ~= "VIP" then                 
-- 			local tCurReg = RegMan.GetReg(User.sNick)
-- 			local tProfiles = ProfMan.GetProfiles()
-- 			for k in pairs(tProfiles) do
-- 				if tProfiles[k].sProfileName == "VIP" then      
-- 					RegMan.ChangeReg(tCurReg.sNick, tCurReg.sPassword, tProfiles[k].iProfileNumber)
-- 					Core.SendPmToUser(User,SetMan.GetString(21),"Your profile has been automatically updated to VIP.|")
-- 				end
-- 			end
-- 		end
-- 	end
end

-- Lost credits for this func, but thanks to the creator of it =)
function ConvShare(iShareSize, Type) -- Convert Share Size...
	while iShareSize >= 1024 and Type ~= "PB" do
		if Type == "B" then
			Type = "KB"
		elseif Type == "KB" then
			Type = "MB"
		elseif Type == "MB" then
			Type = "GB"
		elseif Type == "GB" then
			Type = "TB"
		elseif Type == "TB" then
			Type = "PB"
		end
		iShareSize = iShareSize/1024
	end
	return string.format("%.2f", iShareSize),Type
	--return string.format("%.2f", iShareSize).." "..Type
end
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

SMF spam blocked by CleanTalk