PtokaX forum

Archive => Archived 5.1 boards => Finished Scripts => Topic started by: CrazyGuy on 31 July, 2006, 14:47:47

Title: Terms & Conditions
Post by: CrazyGuy on 31 July, 2006, 14:47:47

--- This script forces connected people to agree with Terms & Conditions before they can do certain actions
--- Written by CrazyGuy
--- version 1.0
--- LUA 5.1
--- July 31st 2006
--- Please only edit lines in Settings part
--- Thnx to plop, Mutor for Serialize function

fPassed = "TCUserDB.tbl"
tPassed = {}
sAcceptDecline = " is disabled until you agree to the hub's Terms & Conditions\n\n\t\tType !accept to Accept , !decline to Decline or !terms to read them again"

-- Settings

fTerms = "terms.txt" ? -- name of file holding the Terms & Conditions
bCanSearch = 0 ? -- 0 for disable, any other value for enable Search
bCanPM = 0 ? -- 0 for disable, any other value for enable PM
bCanMainChat = 0 ? -- 0 for disable, any other value for enable MainChat
bCanDownload = 0 ? -- 0 for disable, any other value for enable Download
OpConnected = NewUserConnected?? ?-- remove this to exclude OPs from Terms & Conditions

-- End Settings

function Main()
SetTimer(21600000)
StartTimer()
local fileUsers = io.open(fPassed)
if fileUsers ~= nil then
tPassed.items = dofile(fPassed)
fileUsers:close()
end
end

function NewUserConnected(curUser)
if tPassed[curUser.sName] == nil then
ShowTerms(curUser.sName)
end
end


function ToArrival(User, Data)
if tPassed[User.sName] == nil then
if bCanPM == 0 then
User:SendPM(frmHub:GetHubBotName(), "Private Message"..sAcceptDecline)
return 1
else
return 0
end
else
return 0
end
end


function ConnectToMeArrival(User, Data)
if tPassed[User.sName] == nil then
if bCanDownload == 0 then
User:SendPM(frmHub:GetHubBotName(), "Downloading"..sAcceptDecline)
return 1
else
return 0
end
else
return 0
end
end

MultiConnectToMeArrival = ConnectToMeArrival
RevConnectToMeArrival = ConnectToMeArrival


function SearchArrival(User, Data)
if tPassed[User.sName] == nil then
if bCanSearch == 0 then
User:SendPM(frmHub:GetHubBotName(), "Searching"..sAcceptDecline)
return 1
else
return 0
end
else
return 0
end
end


function ChatArrival(User, Data)
if tPassed[User.sName] == nil then
Data = string.sub(Data, 1, string.len(Data)-1)
local _,_,cmd = string.find(Data, "%b<>%s+(%S+)")
if cmd == "!accept" then
User:SendData(frmHub:GetHubBotName(), "Thank you for agreeing to the hub's Terms & Conditions. Enjoy your stay")
tPassed[User.sName] = 1
return 1
elseif cmd == "!decline" then
User:SendData(frmHub:GetHubBotName(), "We are sorry to hear that you have decided to decline this hub's Terms & Conditions. You will now be disconnected")
User:Disconnect()
return 1
elseif cmd == "!terms" then
ShowTerms(User.sName)
return 1
else
if bCanMainChat == 0 then
User:SendData(frmHub:GetHubBotName(), "Participation in mainchat"..sAcceptDecline)
return 1
else
return 0
end
end
else
return 0
end
end

function ShowTerms(sNick)
local fileTerms = io.open(fTerms)
if fileTerms ~= nil then
local sTerms = fileTerms:read("*a")
fileTerms:close()
SendToNick(sNick, sTerms)
SendToNick(sNick, "Type !accept to Accept , !decline to Decline or !terms to read them again")
else
SendToAll(frmHub:GetHubBotName(), "An error occurred opening the Terms & Conditions. For safety purposes, all options will be unblocked")
bCanSearch = 1
bCanPM = 1
bCanMainChat = 1
bCanDownload = 1
end
end

function OnExit()
local fTCUserDB = io.open(fPassed, "w+")
Save_Serialize(tPassed, "tPassed", fTCUserDB)
fTCUserDB:close()
end

OnTimer = OnExit

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


Make a file in Notepad first that holds you hub's Terms & Conditions. The default filename is terms.txt but you can change this by changing fTerms
Title: Re: Terms & Conditions
Post by: Nor-Hand on 31 July, 2006, 18:15:12
ii got this message in main    An error occurred opening the Terms & Conditions. For safety purposes, all options will be unblocked
Title: Re: Terms & Conditions
Post by: CrazyGuy on 31 July, 2006, 18:29:47
Quote
ii got this message in main? ? An error occurred opening the Terms & Conditions. For safety purposes, all options will be unblocked

Have you created a seperate text file that contains the Terms & Conditions ??

Quote
Make a file in Notepad first that holds you hub's Terms & Conditions. The default filename is terms.txt but you can change this by changing fTerms
Title: Re: Terms & Conditions
Post by: Nor-Hand on 31 July, 2006, 18:47:03
Thanks.
Title: Re: Terms & Conditions
Post by: CrazyGuy on 31 July, 2006, 18:50:31
ur welcome  :)  is it working now ?  ???
Title: Re: Terms & Conditions
Post by: Nor-Hand on 31 July, 2006, 20:05:36
working now :D
Title: Re: Terms & Conditions
Post by: Herodes on 31 July, 2006, 20:09:46
[...]
function ToArrival(User, Data)
if tPassed[User.sName] == nil and bCanPM == 0 then
User:SendPM(frmHub:GetHubBotName(), "Private Message"..sAcceptDecline)
return 1
end
return 0
end


function ConnectToMeArrival(User, Data)
if tPassed[User.sName] == nil and bCanDownload == 0 then
User:SendPM(frmHub:GetHubBotName(), "Downloading"..sAcceptDecline)
return 1
end
return 0
end

MultiConnectToMeArrival = ConnectToMeArrival
RevConnectToMeArrival = ConnectToMeArrival


function SearchArrival(User, Data)
if tPassed[User.sName] == nil and bCanSearch == 0 then
User:SendPM(frmHub:GetHubBotName(), "Searching"..sAcceptDecline)
return 1
end
return 0
end
[...]
Look those kind of having your script operate in a short-way logic...
Title: Re: Terms & Conditions
Post by: CrazyGuy on 31 July, 2006, 21:54:08
true, I added the boolean's later but thinking it over, you're right.  ;D

Here's new complete code:


--- This script forces connected people to agree with Terms & Conditions before they can do certain actions
--- Written by CrazyGuy
--- version 1.1
--- LUA 5.1
--- July 31st 2006
--- Please only edit lines in Settings part
--- Thnx to plop, Mutor for Serialize function
--- Thnx to Herodes for pointing out a simplification

fPassed = "TCUserDB.tbl"
tPassed = {}
sAcceptDecline = " is disabled until you agree to the hub's Terms & Conditions\n\n\t\tType !accept to Accept , !decline to Decline or !terms to read them again"

-- Settings

fTerms = "terms.txt" -- name of file holding the Terms & Conditions
bCanSearch = 1 -- 0 for disable, any other value for enable Search
bCanPM = 0 -- 0 for disable, any other value for enable PM
bCanMainChat = 0 -- 0 for disable, any other value for enable MainChat
bCanDownload = 0 -- 0 for disable, any other value for enable Download
OpConnected = NewUserConnected  -- remove this to exclude OPs from Terms & Conditions

-- End Settings

function Main()
SetTimer(21600000)
StartTimer()
local fileUsers = io.open(fPassed)
if fileUsers ~= nil then
tPassed.items = dofile(fPassed)
fileUsers:close()
end
end

function NewUserConnected(curUser)
if tPassed[curUser.sName] == nil then
ShowTerms(curUser.sName)
end
end


function ToArrival(User, Data)
if tPassed[User.sName] == nil and bCanPM == 0 then
User:SendPM(frmHub:GetHubBotName(), "Private Message"..sAcceptDecline)
return 1
else
return 0
end
end


function ConnectToMeArrival(User, Data)
if tPassed[User.sName] == nil and bCanDownload == 0 then
User:SendPM(frmHub:GetHubBotName(), "Downloading"..sAcceptDecline)
return 1
else
return 0
end
end

MultiConnectToMeArrival = ConnectToMeArrival
RevConnectToMeArrival = ConnectToMeArrival


function SearchArrival(User, Data)
if tPassed[User.sName] == nil and bCanSearch == 0 then
User:SendPM(frmHub:GetHubBotName(), "Searching"..sAcceptDecline)
return 1
else
return 0
end
end


function ChatArrival(User, Data)
if tPassed[User.sName] == nil then
Data = string.sub(Data, 1, string.len(Data)-1)
local _,_,cmd = string.find(Data, "%b<>%s+(%S+)")
if cmd == "!accept" then
User:SendData(frmHub:GetHubBotName(), "Thank you for agreeing to the hub's Terms & Conditions. Enjoy your stay")
tPassed[User.sName] = 1
return 1
elseif cmd == "!decline" then
User:SendData(frmHub:GetHubBotName(), "We are sorry to hear that you have decided to decline this hub's Terms & Conditions. You will now be disconnected")
User:Disconnect()
return 1
elseif cmd == "!terms" then
ShowTerms(User.sName)
return 1
else
if bCanMainChat == 0 then
User:SendData(frmHub:GetHubBotName(), "Participation in mainchat"..sAcceptDecline)
return 1
else
return 0
end
end
else
return 0
end
end

function ShowTerms(sNick)
local fileTerms = io.open(fTerms)
if fileTerms ~= nil then
local sTerms = fileTerms:read("*a")
fileTerms:close()
SendToNick(sNick, sTerms)
SendToNick(sNick, "Type !accept to Accept , !decline to Decline or !terms to read them again")
else
SendToAll(frmHub:GetHubBotName(), "An error occurred opening the Terms & Conditions. For safety purposes, all options will be unblocked")
bCanSearch = 1
bCanPM = 1
bCanMainChat = 1
bCanDownload = 1
end
end

function OnExit()
local fTCUserDB = io.open(fPassed, "w+")
Save_Serialize(tPassed, "tPassed", fTCUserDB)
fTCUserDB:close()
end

OnTimer = OnExit

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
Title: Re: Terms & Conditions
Post by: Herodes on 01 August, 2006, 07:59:58
--- This script forces connected people to agree with Terms & Conditions before they can do certain actions
--- Written by CrazyGuy
--- version 1.2
--- LUA 5.1
--- July 31st 2006
--- Please only edit lines in Settings part
--- Thnx to plop, Mutor for Serialize function
--- Thnx to Herodes for pointing out a simplification
--- touched by Herodes himself...

fPassed = "TCUserDB.tbl"
tBlocked = {}
sAcceptDecline = " is disabled until you agree to the hub's Terms & Conditions\n\n\t\tType !accept to Accept , !decline to Decline or !terms to read them again"

-- Settings

fTerms = "terms.txt"   -- name of file holding the Terms & Conditions
bCanSearch = 0   -- 0 for disable, any other value for enable Search
bCanPM = 0   -- 0 for disable, any other value for enable PM
bCanMainChat = 0   -- 0 for disable, any other value for enable MainChat
bCanDownload = 0   -- 0 for disable, any other value for enable Download
OpConnected = NewUserConnected    -- remove this to exclude OPs from Terms & Conditions

-- End Settings

function Main()
SetTimer(21600000)
StartTimer()
local fileUsers = io.open(fPassed)
if fileUsers then
tPassed.items = dofile(fPassed)
fileUsers:close()
end
end

function NewUserConnected( user )
if not tPassed[user.sName] then ShowTerms(user.sName) end
end


function ToArrival(user, data)
return BlockUser( user, bCanPM, "Private Message"..sAcceptDecline )
end


function ConnectToMeArrival(user, data)
return BlockUser( user, bCanDownload, "Downloading"..sAcceptDecline )
end

MultiConnectToMeArrival = ConnectToMeArrival
RevConnectToMeArrival = ConnectToMeArrival


function SearchArrival(user, data)
return BlockUser( user, bCanSearch, "Searching"..sAcceptDecline )
end

function BlockUser( user, block_what, msg )
if ( (not tPassed[user.sName]) and (block_what == 0) ) then
user:SendPM( frmHub:GetHubBotName(), msg);
return 1;
end
return 0;
end

function ChatArrival(user, data)
if not tPassed[user.sName] then
data = string.sub( data, 1, -1)
local _,_,cmd = string.find(data, "%b<>%s+%!(%S+)")
local tCmds = {
"accept" = function( user )
user:SendData( fmrHub:GetHubBotName(), "Thank you for agreeing to the hub's Terms & Conditions. Enjoy your stay")
tPassed[user.sName] = nil;return 1
end,
"decline" = function( user )
user:SendData(frmHub:GetHubBotName(), "We are sorry to hear that you have decided to decline this hub's Terms & Conditions. You will now be disconnected")
user:Disconnect();return 1;
end,
"terms" = function(user)
ShowTerms(user.sName);return 1;
end
}
if tCmds[cmd] then
return tCmds[cmd](user);
end
if not bCanMainChat then
user:SendData( frmHub:GetHubBotName(), "Participation in mainchat"..sAcceptDecline);return 1;
end
end
end


function ShowTerms(sNick)
local fileTerms = io.open(fTerms)
if fileTerms ~= nil then
local sTerms = fileTerms:read("*a")
fileTerms:close()
SendToNick(sNick, sTerms)
SendToNick(sNick, "Type !accept to Accept , !decline to Decline or !terms to read them again")
else
SendToAll(frmHub:GetHubBotName(), "An error occurred opening the Terms & Conditions. For safety purposes, all options will be unblocked")
bCanSearch = 1
bCanPM = 1
bCanMainChat = 1
bCanDownload = 1
end
end

function OnExit()
local f = io.open(fPassed, "w+")
Save_Serialize(tPassed, "tPassed", f)
f:close()
end

OnTimer = OnExit

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
Title: Re: Terms & Conditions
Post by: CrazyGuy on 09 August, 2006, 11:28:25
hmm,

I tried myself making something like that BlockUser function but i didn't get that to work properly on all functions.
But, if you did, then good  ;D
Title: Re: Terms & Conditions
Post by: Herodes on 09 August, 2006, 19:57:07
I want to point out that it is way of separating normal users from whatever crawls DC takes some more effort than simply having them respond with "!accept" ...

...try searching in Lawmaker by bastya_elvtars and find the way for registering users with an account.
I have a snippet of code that creates passwords whenever a user doesn't enter one for his account.

Use that for making up the word that the users must type in.

Be sure to give them 3 or 5 tries to get it right...

This way is similar to the way some websites are validating the users from webspiders - bots.... and imho it is quite succesful...
Title: Re: Terms & Conditions
Post by: Herodes on 28 August, 2006, 08:22:46
I don't think that you need all that to distinuish human from bots,...

the following should do the job cleanly enough:
function GenSmallPass()
local s = ''
for i = 1, 4 do
str = str..math.random(1, 8)
end
return s;
end