Custom ShareLimter
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Custom ShareLimter

Started by Madman, 27 February, 2006, 00:53:48

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Madman

-- Custom ShareLimter
-- Made by Madman
-- Based on a requst by Northwind and Pablo.zz

Set = { -- Profiles allowed to set sharelimit
	[0] = 1,
	[1] = 0,
}

function Main()
	-- Check For file
	local file = io.open("CustomShares.dat")
	if file then
		file:close()
	else
		local file = io.open("CustomShares.dat", "w+")
		file:write("CustomShare = {}")
		file:close()
	end
end

function MyINFOArrival(curUser, data)
	LoadFromFile("CustomShares.dat") -- Load table
	if CustomShare[curUser.sName] then -- If user in table
		if ConvShare(curUser.iShareSize, "B") < (ConvShare(CustomShare[curUser.sName]["Share"], CustomShare[curUser.sName]["Unit"])) then
			-- Compar and if share less then in table, disconnect
			curUser:SendData(frmHub:GetHubBotName(), "Your customshare is " ..CustomShare[curUser.sName]["Share"].. " " ..CustomShare[curUser.sName]["Unit"].. ", please get more share")
			curUser:Disconnect()
		end
	end
	CustomShare = nil -- "Unload table"
end

function ChatArrival(curUser, data)
	local data = string.sub(data, 1, -2)
	local s,e,cmd = string.find(data, "%b<>%s+%p(%S+)")
	if cmd and Set[curUser.iProfile] == 1 then
		local tCmds = {
		["addsharelimit"] = function(curUser, data)
			local s,e,Nick,Share,Unit = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(%d+)%s+(%S+)")
			if Nick and Share and Unit then
				LoadFromFile("CustomShares.dat")
				if CustomShare[Nick] == nil then
					CustomShare[Nick] = {}
					CustomShare[Nick]["Share"] = {}
					CustomShare[Nick]["Unit"] = {}
					CustomShare[Nick]["Share"] = tonumber(Share)
					CustomShare[Nick]["Unit"] = string.upper(Unit)
				else
					CustomShare[Nick]["Share"] = tonumber(Share)
					CustomShare[Nick]["Unit"] = string.upper(Unit)
				end
				curUser:SendData(frmHub:GetHubBotName(), Nick.." added with the share " ..Share.." "..string.upper(Unit))
				SaveToFile("CustomShares.dat", CustomShare, "CustomShare")
				CustomShare = nil
			else
				curUser:SendData(frmHub:GetHubBotName(), "Syntax: !" ..cmd.. " <Nick> <Share> <Unit>")
			end
			return 1
		end,
		["delsharelimit"] = function(curUser, data)
			local s,e,Nick = string.find(data, "%b<>%s+%S+%s+(%S+)")
			if Nick then
				LoadFromFile("CustomShares.dat")
				if CustomShare[Nick] == nil then
					curUser:SendData(frmHub:GetHubBotName(), Nick.. " not in table")
				else
					CustomShare[Nick] = nil
					SaveToFile("CustomShares.dat", CustomShare, "CustomShare")
					curUser:SendData(frmHub:GetHubBotName(), Nick.. " removed from table")
				end
				CustomShare = nil
			else
				curUser:SendData(frmHub:GetHubBotName(), "Syntax: !" ..cmd.. " <Nick>")
			end
			return 1
		end,
		["viewsharelimit"] = function(curUser, data)
			LoadFromFile("CustomShares.dat")
			Msg = "\r\nCustom Shares\r\n"
			for Nick,_ in CustomShare do
				Msg = Msg.."Nick: " ..Nick
				for That,Set in CustomShare[Nick] do
					Msg = Msg.." " ..That.. ": " ..Set
				end
				Msg = Msg.."\r\n"
			end
			curUser:SendData(frmHub:GetHubBotName(), Msg) CustomShare = nil
			return 1
		end,
		}
		if tCmds[cmd] then
			return tCmds[cmd](curUser, data)
		end
	end
end

-- Created by Corayzon
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("%.0f", iShareSize).." "..Type
end

-- Serialize by nErBoS
function Serialize(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");
	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in tTable do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end
		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

function SaveToFile(file , table , tablename)
	local handle = io.open(file,"w+")
	handle:write(Serialize(table, tablename))
	handle:flush()
	handle:close()
end

function LoadFromFile(filename)
	local f = io.open(filename)
	if f then
		local r = f:read("*a")
		f:flush()
		f:close()
		local func,err = loadstring(r)
		if func then x,err = pcall(func) end
	end
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