| View previous topic :: View next topic |
| Author |
Message |
Nadae Voice
Joined: 24 Mar 2021 Posts: 5
|
Posted: Wed Mar 24, 2021 8:35 pm Post subject: How to get version |
|
|
Hello,
I would like that for each person who connects, we can get their ctcp version. And that if the person is not the nickname "John" and the version of the person does not correspond to what I want it is gline for 30 minutes.
How to do ? |
|
| Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Thu Mar 25, 2021 12:02 am Post subject: |
|
|
First of all: this is "Scripting Help" this post is better in "Script Requests"
Second:
| Code: |
# set allow nicks
set bv_nicks {"john" "paddy"}
# Set allow versions
set bv_versions {"version1" "version2"}
bind raw - NOTICE Client_Connect
bind ctcr - VERSION ctcr:bv_ctcp
proc Client_Connect {from key arg} {
putserv "PRIVMSG $from :\001VERSION\001"
}
proc ctcr:bv_ctcp {nick host hand dest key arg} {
global bv_versions bv_nicks
if {![isbotnick $nick]} {
foreach nicks $bv_nicks {
if {![string match -nocase "$nicks"]} {
return 0
}
foreach version $bv_versions {
if {![string match -nocase "*[string tolower $version]*"]} {
return 0
}
}
putquick "gline $host 30m :Bad Version"
}
}
}
|
Untested  _________________ ComputerTech
Last edited by ComputerTech on Thu Mar 25, 2021 5:42 pm; edited 2 times in total |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu Mar 25, 2021 2:29 am Post subject: |
|
|
1. string match expects two arguments (two strings), while in:
| Code: |
if {![string match -nocase "$nicks"]} {
|
and:
| Code: |
if {![string match -nocase "*[string tolower $version]*"]} {
|
you are missing one of them. You should ditch looping over a list and use lsearch (that means list search) directly instead.
| Code: |
% set bv_nicks {"john" "paddy"}
"john" "paddy"
% set nick "something"
something
% lsearch -nocase $bv_nicks $nick
-1
% set nick Paddy
Paddy
% lsearch -nocase $bv_nicks $nick
1
|
2. In this code
| Code: |
foreach nicks $bv_nicks {
if {![string match -nocase "$nicks"]} {
return 0
}
|
if you want to stop the iteration or skip one element use break or continue, depending on what you want to achieve. For example:
| Code: |
% set numbers { 1 2 3 4 5 6 }
1 2 3 4 5 6
% foreach number [split $numbers] {
if {$number == 3} {
continue
}
puts $number
}
1
2
4
5
6
|
Notice that 3 is missing, and in this:
| Code: |
% foreach number [split $numbers] {
if {$number == 3} {
break
}
puts $number
}
1
2
|
notice that the execution has been stopped when number is 3.
3. In this code:
| Code: |
if {![isbotnick $nick]} {
|
you can test the TRUE state instead of FALSE one and return, so this saves you of the keeping in mind you have one } to add somewhere at the end.
4. In this code:
| Code: |
proc Client_Connect {from key arg} {
putserv "PRIVMSG $from :\001VERSION\001"
}
|
I have my doubts that using $from is the client you want to version check, most likely that's the server itself sending you something in the $arg (avoid using arg as it has some special meaning in TCL) with client information and you need to parse the details from the line it sends. Might want to do some research first.
Oh, and don't use return 0 if you don't want to have an actual 0 (zero) returned in a function or whatnot.
I've moved the topic to the correct section. _________________ Once the game is over, the king and the pawn go back in the same box.
Last edited by caesar on Thu Mar 25, 2021 12:53 pm; edited 1 time in total |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Thu Mar 25, 2021 8:19 am Post subject: |
|
|
well first you need to know what IRCD is it running in and does bot have IRCOP
privileges |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Thu Mar 25, 2021 8:56 am Post subject: |
|
|
| Thats even a better approach thanks CrazyCat |
|
| Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Thu Mar 25, 2021 11:07 am Post subject: |
|
|
heh yeah, was doing that code this morning at 5am and hadn't slept, will try fix it after work.
Thanks caesar  _________________ ComputerTech |
|
| Back to top |
|
 |
Nadae Voice
Joined: 24 Mar 2021 Posts: 5
|
Posted: Thu Mar 25, 2021 2:54 pm Post subject: |
|
|
| CrazyCat wrote: | | If you use unrealircd, you can use the ban version feature |
CrazyCat with unrealircd is it possible to choose: if the version is different from ...?
In this case it is written how? |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Fri Mar 26, 2021 8:53 am Post subject: |
|
|
perhaps this will be of use:
| Code: |
set acnick {
"John"
}
bind raw - NOTICE server:notices
proc server:notices {from keyword text} {
global acnick
if {[string match -nocase "*client connecting on*" $text]} {
set nick [lindex [split $text] 9]
set hostmask [lindex [split $text] 10]
foreach i [string tolower $acnick] {
if {![string match -nocase $i $nick]} {
putserv "PRIVMSG $nick :\001VERSION\001"
}
}
return 0
}
if {[string match -nocase "*client connecting at*" $text]} {
set nick [lindex [split $text] 8]
set hostmask [lindex [split $text] 9]
foreach i [string tolower $acnick] {
if {![string match -nocase $i $nick]} {
putserv "PRIVMSG $nick :\001VERSION\001"
}
}
return 0
}
}
set badclient {
"mirc"
}
bind ctcr -|- "VERSION" ctcr:check
proc ctcr:check {nick host hand dest keyword text} {
if {$keyword == "VERSION"} {
foreach checknick $::badclient {
if {[string match -nocase *$checknick* [stripcodes bcruag $text]]} {
putquick "GLINE $host 1h :You match a Bad Client. This is not Permitted on \017\002\00306 $::network. \017 Please Use another Client and Reconnect."
}
}
}
}
|
|
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
|