This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Connect LookUp

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
F
Furbs
Voice
Posts: 7
Joined: Wed Oct 01, 2008 9:16 pm
Location: Adealide, South Australia, Australia
Contact:

Connect LookUp

Post by Furbs »

Hey all, long time visitor, first time poster ;)

was wondering if i could get a bit of help

what i want is, my eggdrop will get a line, example: [03:01] <OperServ> 4CONNECT on server 12nick!host@stuff (ip) and i want it to, dns the IP, and if it resolves to Australian or New Zealand, to increase a variable (Based on the resolution of their IP). Kiwi = New Zealand and aussie = Australian :)

its pretty simple and that, but just having problems :(

so far i've got

Code: Select all

bind pubm f * check:connect

proc check:connect { nick host hand chan arg } {
        global kiwi,aussie
        putlog [lindex $arg 0]
        if { "4CONNECT" == [lindex $arg 0] } {
                putserv "PRIVMSG #sl-oceania :woahh new increase $counter"
        }
}
FYI, the putlog [lindex $arg 0] is returning [03:05] 4CONNECT

and its not getting pass the if

Thanks for the help :)
F
Furbs
Voice
Posts: 7
Joined: Wed Oct 01, 2008 9:16 pm
Location: Adealide, South Australia, Australia
Contact:

Post by Furbs »

ok i've made some more improvements,

it catches when Operserv says CONNECT

so now i just need someone to make it dns the IP and determine where its from :)

heres what i've got so far

Code: Select all

bind pubm f * check:connect

proc check:connect { nick host hand chan arg } {
        if {([string match -nocase "*connect*" [lindex $arg 0]])} {
                regexp "(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})" [lindex $arg 4] all first second third fourth
                putserv "PRIVMSG #sl-oceania :$all"
        }
}
and it msg's the channel with

[11:52:13] <@Shiela> 123.456.789.011 (Example IP address :) )
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Use the dnslookup function and appropriate callback. This skeleton code should help you get started.

Code: Select all

proc dns_callback {ip host status args} {
 global kiwi aussie
 if {$status} {
  switch -glob $host {
   *.nz {incr kiwi}
   *.au {incr aussie}
  }
 }
}

proc yourproc ....
...
 dnslookup $thehost
...
}
Also, a comment on both posts: don't use lindex and other list operations on strings. If you have to convert a string into a list, use the split command. It seems you are having problems with control-codes (ctrl+c for colors in this case), consider scrubbing the string using the stripcodes command.

Both dnslookup and stripcodes are documented in doc/tcl-commands.doc, and lindex and split are documented in the tcl manual ("man n lindex" or http://www.tcl.tk/man/tcl8.3/TclCmd/lindex.htm)
NML_375
F
Furbs
Voice
Posts: 7
Joined: Wed Oct 01, 2008 9:16 pm
Location: Adealide, South Australia, Australia
Contact:

Post by Furbs »

Code: Select all

bind pubm f * check:connect

set aussie "0"
set kiwis "0"

proc check:connect { nick host hand chan arg } {
        if {([string match -nocase "*connect*" [lindex $arg 0]])} {
                set nick [lindex $arg 5]
                regexp "(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})" [lindex $arg 4] all
                putserv "PRIVMSG #sl-oceania :$all"
                dnslookup $all resolve_rep
        }
        if {[string match -nocase "*join*" [lindex $arg 2]]} {
                putserv "PRIVMSG #sl-oceania :$arg !"
        }
}

proc resolve_rep {ip host status} {
        global aussie kiwis
        if {!$status} { putlog "Unable to resolve \037\002$ip\017 ."
        } else {
                if {[string match -nocase "*.au" $host]} {
                        set newnumber [expr $aussie + 1]
                        set aussie $newnumber
                        putserv "privmsg #sl-oceania :Aussie's Connected: $aussie Woah!!!"
                } elseif {[string match -nocase "*.nz" $host]} {
                        set newnumber [expr $kiwis + 1]
                        set kiwis $newnumber
                        putserv "privmsg #sl-oceania :Kiwi's Connected: $kiwis Woah!!!!"
                }
        }
}
:)

now i want to make it a bit better, and have absolutely no idea if it'll work or how to do it....

i know its possible, at that much :)

Connect to a MySQL DB
then insert information when it comes in, stored by times
i.e. if its 1:30 and it gets the information, it UPDATES a field, named 1-30, the stuff in it and adds for example, "hello"

an then if its 2:45 it gets the information, it UPDATES the field, 2-30, and yeah.... done in half hour brackets.....

heres like a PHP Version if thats helpful

Code: Select all

$qry = "UPDATE `2-30` SET `kiwis`='$kiwis',`aussies`='$aussies'";
mysql_query($qry);
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You'll need some myqsl-package such as mysqltcl for this..
Creating the time-stamp would probably be best done something like this:

Code: Select all

set now [clock seconds]
set time "[clock format $now -format "%k"]-[expr [clock format $now -format "%M"]<30?"0":"3"]0"
As for your SQL-query, are you using one table (with one row) for each time-period? If so, wouldn't it be more intuitive to just have one table with several rows (not to mention more efficient)?
Also, if you only wish to store the statistical data in the database, you could simply use SQL's own facilities to increase values, rather than keeping a duplicate in your eggdrop...

A few things tho;
Why use multiple string match's instead of a single switch structure? If you need case-insensitive matching, you could simply replace $host with [string tolower $host] as switch-string...

Why this huge block, instead of the very simple incr command?

Code: Select all

set newnumber [expr $aussie + 1]
set aussie $newnumber
#vs
incr aussie
#or incr aussie 1
NML_375
Post Reply