can some1 translate this to Lua5?
 

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

can some1 translate this to Lua5?

Started by aL1en, 30 July, 2005, 05:45:00

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aL1en

Quote-- regonly by bastya_elvtars
-- requested by aL1en

-- sorry 4 possible bugs, cannot test it and forgot lua a bit :)
-- disconnects unreg users if hub is set private
-- well, here is an array that contains allowed ppl. this is the safest.
-- command prefixes: + ! # ? (as usual)
-- ptokax>advanced>registered users only must be unmarked ;)
-- enjoy

-- // settings

userswhocansetregonly={ -- ppl who are allowed to use it

"aL1en",

}

-- the bot1s name:

Bot="TheKEY"

--- // end of settings, do not edit below


regO={}

regonly=0 -- for safety only

dofile("regonly.ini") -- loads settings

function Main() -- loads on script start
   for b=1,getn(userswhocansetregonly) do
      regO[userswhocansetregonly]=1 -- makes a metatable to use l8r
   end
end


function NewUserConnected(user) -- user connects
   if regonly==1 then
      if user.iProfile==-1 then
         user:SendData(Bot,"This hub is for registered users only.")
         user:Disconnect()
      end
   end
end

function DataArrival(user,data)
   if strsub(data,1,1)=="<" then
      data=strsub(data,1,strlen(data)-1)
      local _,_,cmd=strfind(data,"%b<>%s+[%+%!%#%?](%S+)")
      if cmd=="private" then
         if regO[user.sName] then
            if regonly~=1 then
               regonly=1
               save()
               user:SendData(Bot,"Hub is now private.")
            else
               user:SendData(Bot,"Hub is already private.")
            end
         else
            user:SendData(Bot,"You are not allowed to use this command.")
         end
      elseif cmd=="public" then
         if regO[user.sName] then
            if regonly~=0 then
               regonly=0
               save()
               user:SendData(Bot,"Hub is now public.")
            else
               user:SendData(Bot,"Hub is already public.")
            end
         else
            user:SendData(Bot,"You are not allowed to use this command.")
         end
      end
   end
end

function save()
   writeto("regonly.ini")
   write("regonly="..regonly)
   writeto()
end

TTB

#1
Hi, here we go:

A. First you need to make a file called "regonly.dat" and put that in the scripts folder!
B. The table in this file should be this (copy paste this in the file "regonly.dat"):
Setting = {
	["regonly"] = 1,
}
C. This is the script u asked for (have fun), please report bugs:
-----------------------------------------------------------------------------
-- regonly by bastya_elvtars 
-- requested by aL1en 
-----------------------------------------------------------------------------
-- Changed to LUA5 on request by TTB (30-07-05)
-- Table in txt is serialized... ow my, I love that function!
-----------------------------------------------------------------------------
-- sorry 4 possible bugs, cannot test it and forgot lua a bit :) 
-- disconnects unreg users if hub is set private 
-- well, here is an array that contains allowed ppl. this is the safest. 
-- command prefixes: + ! # ? (as usual) 
-- ptokax>advanced>registered users only must be unmarked ;) 
-- enjoy 
-----------------------------------------------------------------------------

-- // settings 

-->> Who can reg set the regonly?
userswhocansetregonly={
"aL1en",
"[SU]TTB",
} 

-->> What is the name of your bot?
Bot="TheKEY" 

-->> What is the filename of the settings?
file = "regonly.dat"

--- // end of settings, do not edit below 
regO={} 

function Main() -- loads on script start
	local handle = io.open(file,"r")
	if (handle ~= nil) then
		dofile(file)
		handle:flush()
		handle:close()
	else
		SendToAll(Bot, "The file: "..file.." has not been found in the scripts folder!")
	end
	for b=1,table.getn(userswhocansetregonly) do 
		regO[userswhocansetregonly[b]]=1 -- makes a metatable to use l8r 
	end 
end 

function NewUserConnected(user) -- user connects 
	if Setting["regonly"] == 1 then 
		if user.iProfile==-1 then 
			user:SendData(Bot,"This hub is for registered users only.") 
			user:Disconnect() 
		end 
	end 
end 

function ChatArrival(user,data) 
	mijntabel = "Setting"
	data = string.sub(data,1,string.len(data)-1) 
	local _,_,cmd=string.find(data,"%b<>%s+[%+%!%#%?](%S+)") 
	if cmd=="private" then 
		if regO[user.sName] then 
			if Setting["regonly"] ~=1 then 
				Setting["regonly"] = 1
				WriteFile(Setting,mijntabel,file)
				user:SendData(Bot,"Hub is now private.") 
			else 
				user:SendData(Bot,"Hub is already private.") 
			end 
		else 
			user:SendData(Bot,"You are not allowed to use this command.") 
		end 
		return 1
	elseif cmd=="public" then 
		if regO[user.sName] then 
			if Setting["regonly"] ~= 0 then
				Setting["regonly"] = 0
				WriteFile(Setting,mijntabel,file)
				user:SendData(Bot,"Hub is now public.") 
			else 
				user:SendData(Bot,"Hub is already public.") 
			end 
		else 
			user:SendData(Bot,"You are not allowed to use this command.") 
		end 
		return 1
	end	
end 

function Serialize(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	hFile:write(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
			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

function WriteFile(table, tablename, file)
	local handle = io.open(file, "w")
	Serialize(table, tablename, handle)
  	handle:close()
end
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

aL1en


TTB

TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

SMF spam blocked by CleanTalk