PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Smulf on 27 July, 2004, 21:18:49

Title: Implant some strings
Post by: Smulf on 27 July, 2004, 21:18:49
Wazup guess

Is it posible to write a string that would do so you are not only banned after 3 kicks, but also the "!drop" command. So that when the OPs kicks or drops the user 3 times he will get banned. Here is the script thats in use:

--Ban-4X-Kick 1.0
--
--Auto bans a user on 'x' times kicked.    [+1]     :)
--
-- Provides option for:
-- - Report to Admin, Ops or Main
-- - Set number of kicks before ban
-- - send user website/forum message
-- - loads/saves kicks to external files
--  files(s) when hub/scripts restart
--
-- Local Ops now exempt
--
--User Settings-------------------------------------------------------------------------------------

--Number of time a user may be kicked, user will be banned at next login.
kickcount = 1
--Send report to main chat
Snd2All = "0"
--Send pm report to ops
Snd2Ops = "1" -- 1 = on / 0 = off
--Send pm report Admin's Nick
Snd2Admin = "0"
--Admin's Nick or any other single nick
AdminName = "Mutor"
--Name for bot [You can use your main bot, if so no need to register this bot. See 'function main'.
Bot = "OP_Ban"

--End User Settings----------------------------------------------------------------------------------

--
Kicked = {}
KickFile = "OP_Ban\kicks.txt"

function Main()
--frmHub:RegBot(Bot) --If using main bot, remark this line, add -- ie.. --frmHub:RegBot(Bot)
frmHub:EnableFullData(1)
LoadFromFile(KickFile)
end

function NewUserConnected(user, data)
if Kicked[user.sName]==kickcount then Kicked[user.sName]=nil
local Report2
Report2 = "\r\n\r\n\t---<>-------------------------------------------------------<>---    \r\n"  
Report2 = Report2.."\tThe user "..user.sName.." has been kicked [ "..kickcount.." ] times.\r\n"
Report2 = Report2.."\t"..user.sName.." attempted login and has been banned.               \r\n"
Report2 = Report2.."\t---<>-------------------------------------------------------<>---   \r\n"
if Snd2Admin == "1" then
SendPmToNick(AdminName,Bot,Report2)
end
if Snd2Ops == "1" then
SendPmToOps(Bot,Report2)
end
if Snd2All == "1" then
SendToAll(Bot,Report2)
end
local BanMsg
BanMsg = "\r\n\r\n\t---<>----------------------------------------------------------------<>---\r\n"  
BanMsg = BanMsg.."\tYou had been kicked [ "..kickcount.." ] times, now your banned.           \r\n"
BanMsg = BanMsg.."\tIf you disagree with your ban. Visit our forum at :                   \r\n\r\n"
BanMsg = BanMsg.."\t\thttp://hubforum.no-ip.com                                               \r\n"
BanMsg = BanMsg.."\t---<>----------------------------------------------------------------<>---\r\n"
user:SendData(Bot, BanMsg)
user:SendPM(Bot, BanMsg)
user:Ban()
end
end

function DataArrival(user, data)
data=strsub(data,1,-2)
_,_,cmd,unick = strfind( data, "(%S+)%s+(%S+)" )
if cmd == "$Kick" and user.bOperator then
if Kicked[unick]==nil then Kicked[unick]=1
elseif Kicked[unick]~= nil then Kicked[unick] = Kicked[unick]+1
if Kicked[unick]== kickcount then
local Report1
Report1 = "\r\n\r\n\t---<>-------------------------------------------------------<>---\r\n"  
Report1 = Report1.."\tThe user "..unick.." has been kicked [ "..kickcount.." ] times.\r\n"
Report1 = Report1.."\t"..unick.." will be banned at next login to this hub.\r\n"
Report1 = Report1.."\t---<>-------------------------------------------------------<>---\r\n"
if Snd2Admin == "1" then
SendPmToNick(AdminName,Bot,Report2)
end
if Snd2Ops == "1" then
SendPmToOps(Bot,Report2)
end
if Snd2All == "1" then
SendToAll(Bot,Report2)
end

end
end
end
end


function OnExit()
SaveToFile(KickFile , Kicked , "Kicked")
end

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 format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and 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)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end


Thanks for your time...!
Title:
Post by: Troubadour on 27 July, 2004, 23:22:26
you could change this line

   if cmd == "$Kick" and user.bOperator then

to

   if cmd == "$Kick" or cmd == "$Drop" and user.bOperator then

so with both commands it will do the same counting.
Title:
Post by: nErBoS on 27 July, 2004, 23:52:17
Hi,

"$Drop" ??? Dc client don't have this string sent, i suposse that !drop is an in script command or potkax comand, can you tell us ?? And also tell us the phrase sent by the bot when some one is droped.

Best regards, nErBoS
Title:
Post by: NightLitch on 28 July, 2004, 00:29:20
This should maybe work:

_,_,cmd,unick = strfind( data, "%!*(%S+)%s+(%S+)" )
if cmd == "$Kick" or cmd=="drop" and user.bOperator then

/NL
Title:
Post by: nErBoS on 28 July, 2004, 01:29:13
Hi,

Other note to take the script must be first in the list of the scripts then the script that have the !drop command because of the return 1

Best regards, nErBoS
Title: Reply
Post by: Smulf on 28 July, 2004, 21:32:52
QuoteHi,

"$Drop" ??? Dc client don't have this string sent, i suposse that !drop is an in script command or potkax comand, can you tell us ?? And also tell us the phrase sent by the bot when some one is droped.

Best regards, nErBoS

I think it's an Potkax command.

QuoteMethods:
SendData(data)
SendPM(from, data)
Disconnect()
Ban()
NickBan()
TempBan()
TimeBan(time)

Am I missing any?

!drop is just curUser:Disconnect()

Anyway I made this script at request for the kick but
you can use this script for any string

Adjust function:

DataArrival(user, data)

to suit your needs.

Thx Mutor, you'v solt my other problem with the "TempBan()" method:)


Thx to Troubadour and NightLitch for the tip, but it makes a - "Syntax Error: table index is nil" - and I have changed what you'v told me:

--Ban-4X-Kick 1.0
--
--Auto bans a user on 'x' times kicked.    [+1]     :)
--
-- Provides option for:
-- - Report to Admin, Ops or Main
-- - Set number of kicks before ban
-- - send user website/forum message
-- - loads/saves kicks to external files
--  files(s) when hub/scripts restart
--
-- Local Ops now exempt
--
--User Settings-------------------------------------------------------------------------------------

--Number of time a user may be kicked, user will be banned at next login.
kickcount = 1
--Send report to main chat
Snd2All = "0"
--Send pm report to ops
Snd2Ops = "1" -- 1 = on / 0 = off
--Send pm report Admin's Nick
Snd2Admin = "0"
--Admin's Nick or any other single nick
AdminName = "Mutor"
--Name for bot [You can use your main bot, if so no need to register this bot. See 'function main'.
Bot = "OP_Ban"

--End User Settings----------------------------------------------------------------------------------

--
Kicked = {}
KickFile = "OP_Ban\kicks.txt"

function Main()
--frmHub:RegBot(Bot) --If using main bot, remark this line, add -- ie.. --frmHub:RegBot(Bot)
frmHub:EnableFullData(1)
LoadFromFile(KickFile)
end

function NewUserConnected(user, data)
if Kicked[user.sName]==kickcount then Kicked[user.sName]=nil
local Report2
Report2 = "\r\n\r\n\t---<>-------------------------------------------------------<>---    \r\n"  
Report2 = Report2.."\tThe user "..user.sName.." has been kicked [ "..kickcount.." ] times.\r\n"
Report2 = Report2.."\t"..user.sName.." attempted login and has been banned.               \r\n"
Report2 = Report2.."\t---<>-------------------------------------------------------<>---   \r\n"
if Snd2Admin == "1" then
SendPmToNick(AdminName,Bot,Report2)
end
if Snd2Ops == "1" then
SendPmToOps(Bot,Report2)
end
if Snd2All == "1" then
SendToAll(Bot,Report2)
end
local BanMsg
BanMsg = "\r\n\r\n\t---<>----------------------------------------------------------------<>---\r\n"  
BanMsg = BanMsg.."\tYou had been kicked [ "..kickcount.." ] times, now your banned.           \r\n"
BanMsg = BanMsg.."\tIf you disagree with your ban. Visit our forum at :                   \r\n\r\n"
BanMsg = BanMsg.."\t\thttp://hubforum.no-ip.com                                               \r\n"
BanMsg = BanMsg.."\t---<>----------------------------------------------------------------<>---\r\n"
user:SendData(Bot, BanMsg)
user:SendPM(Bot, BanMsg)
user:Ban()
end
end

function DataArrival(user, data)
data=strsub(data,1,-2)
_,_,cmd,unick = strfind( data, "%!*(%S+)%s+(%S+)" )
if cmd == "$Kick" or cmd == "$Drop" and user.bOperator then
if Kicked[unick]==nil then Kicked[unick]=1
elseif Kicked[unick]~= nil then Kicked[unick] = Kicked[unick]+1
if Kicked[unick]== kickcount then
local Report1
Report1 = "\r\n\r\n\t---<>-------------------------------------------------------<>---\r\n"  
Report1 = Report1.."\tThe user "..unick.." has been kicked [ "..kickcount.." ] times.\r\n"
Report1 = Report1.."\t"..unick.." will be banned at next login to this hub.\r\n"
Report1 = Report1.."\t---<>-------------------------------------------------------<>---\r\n"
if Snd2Admin == "1" then
SendPmToNick(AdminName,Bot,Report2)
end
if Snd2Ops == "1" then
SendPmToOps(Bot,Report2)
end
if Snd2All == "1" then
SendToAll(Bot,Report2)
end

end
end
end
end


function OnExit()
SaveToFile(KickFile , Kicked , "Kicked")
end

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 format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and 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)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end
Title:
Post by: NightLitch on 29 July, 2004, 00:16:34
change:

if cmd == "$Kick" or cmd == "$Drop" and user.bOperator then

to

if cmd == "$Kick" or cmd == "drop" and user.bOperator then

the drop is a command not a $Syntax/Cmd.

/NL