Scripting help needed

Releases and bugs in here...
BSOD2600
Forum Moderator
Posts: 503
Joined: 2003-01-27 23:47
Location: USA

Scripting help needed

Post by BSOD2600 » 2003-07-05 23:47

I'm trying to convert a Ptokax script over to DCH (so I dont have to use all those other scripts to make it work). I've never programmed in Lua (or vbscript really either) so I'm kinda lost. Unlike the original script that logs it to a text file, I want it to simply PM me/OPs with the messages. Will this even intercept the hub redirecting people with the reason it gave?
I got the easy parts of the conversion, but its the logic portion I have no idea what to do...

DCH script

Code: Select all

BotName = "RedirectLogger"

function DataArrival(curUser, data)
   if( strsub(data, 1, 12) == "$ForceMove" ) then


   local function send( client )
      client:privateMessage( totalmsg, BotName )
   end
   local name = client:getNick()
   local ip = client:getIp()
   if not name then name = "(unknown)" end
   if not ip then ip = "(unknown)" end
   totalmsg =    ""..name.." from "..ip.." was Redirected because "..reason..""
   dchpp.foreach( send )
   end
end


Ptokax Script

Code: Select all

--    Redirect Logger              
-- A little script for logging the redirect-action in hub.
-- Who (with IP-number) is redirecting who, and where to.
-- Can be used to reveal unhonest OP's.
-- Redirect Logger-Script by VidFamne ( 11.04.2003 )
 

botname="RedirectLog"
file = "RedirectLog.txt"

function Main()
--frmHub:RegBot(botname)
end

function DataArrival(curUser, sData)

if ( strsub(sData, 1, 12) == "$OpForceMove" ) then

s,e,name = strfind(sData,"$Who:([^$]+)")
s,e,where = strfind(sData,"$Where:([^$]+)")

Time = date()

appendto(file)
write(Time, "\t" ..curUser.sName.." with IP; "..curUser.sIP.." has redirect "..name.." to: "..where.." \r\n")
writeto()

end
end

qqzm
Posts: 47
Joined: 2003-01-23 12:08

Post by qqzm » 2003-07-07 07:26

Try something like this (Note: completely untested...)

Code: Select all

local bot_name = "LoggerBot"


function dchpp.startup()
   dchpp.addNick(bot_name)
end


function dchpp.clientLine(client, data)
   if string.sub(data, 1, 13) == "$OpForceMove " then
      s,e,name = string.find(data,"$Who:([^$]+)")
      s,e,where = string.find(data,"$Where:([^$]+)")
      local function send(client)
         client:hubMessage("<"..bot_name.."> "..client:getNick().." has redirected "..name.." to "..where, bot_name)
      end
      dchpp.foreach(send, -1)
   end
end

Sedulus
Forum Moderator
Posts: 687
Joined: 2003-01-04 14:32

Post by Sedulus » 2003-07-07 11:42

A couple of notes
qqzm wrote:

Code: Select all

local bot_name = "LoggerBot"


function dchpp.startup()
   dchpp.addNick(bot_name)
end

-- if you use addNick, you should also use removenick, like:
function dchpp.shutdown()
   dchpp.removeNick(bot_name)
end

function dchpp.clientLine(client, data)
   if string.sub(data, 1, 13) == "$OpForceMove " then
      -- use local whenever possible.. it keeps your code a lot cleaner
      local s,e,name,where
      s,e,name = string.find(data,"$Who:([^$]+)")
      s,e,where = string.find(data,"$Where:([^$]+)")
      --
      -- I think client:getNick takes a call to dch++ #OP times during the loop..
      -- it would be wiser to get the name first... and..
      -- this goes for the string concatenation as well
      -- never do stuff inside a loop if not necessary
      -- local function send(client)
      --   client:hubMessage("<"..bot_name.."> "..client:getNick().." has redirected "..name.." to "..where, bot_name)
      -- end
      -- like this:
      local str = "<"..bot_name.."> "..client:getNick().." has redirected "..name.." to "..where
      local function send(client)
         client:hubMessage(str, bot_name)
      end
      dchpp.foreach(send, -1)
   end
end
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)

qqzm
Posts: 47
Joined: 2003-01-23 12:08

Post by qqzm » 2003-07-07 13:36

Note to self: this is what happens when you try to write a script in 5 minutes without even testing it. Naughty qqzm. :oops:

BSOD2600
Forum Moderator
Posts: 503
Joined: 2003-01-27 23:47
Location: USA

Post by BSOD2600 » 2003-07-07 23:24

thanks to the both of you for helping out. It sucessfully logs when an OP redirects someone, but I'm also interested in when the hub itself redirects someone and the reason why. Can Lua scripts do that?

Who is online

Users browsing this forum: Google [Bot] and 0 guests