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.

How to get version

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
N
Nadae
Voice
Posts: 5
Joined: Wed Mar 24, 2021 8:30 pm

How to get version

Post by Nadae »

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 ?
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

First of all: this is "Scripting Help" this post is better in "Script Requests"

Second:

Code: Select all


# 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 :wink:
Last edited by ComputerTech on Thu Mar 25, 2021 5:42 pm, edited 2 times in total.
ComputerTech
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

1. string match expects two arguments (two strings), while in:

Code: Select all

if {![string match -nocase "$nicks"]} {
and:

Code: Select all

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: Select all

% 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: Select all

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: Select all

% 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: Select all

% 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: Select all

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: Select all

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.
Last edited by caesar on Thu Mar 25, 2021 12:53 pm, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

well first you need to know what IRCD is it running in and does bot have IRCOP
privileges
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

If you use unrealircd, you can use the ban version feature
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Thats even a better approach thanks CrazyCat
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

heh yeah, was doing that code this morning at 5am and hadn't slept, will try fix it after work.

Thanks caesar :D
ComputerTech
N
Nadae
Voice
Posts: 5
Joined: Wed Mar 24, 2021 8:30 pm

Post by Nadae »

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?
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

No, the ban version block is here to forbid some client version, not to forbid all but one or two.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

perhaps this will be of use:

Code: Select all

 

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."
           }
       }
   }
}

User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Nadae asked me an example of script which forbid all clients version different of (in example) "Kiwi IRC" and "mIRC", working for everybody but "lololo".

I did it (sorry guys, with french comments) : https://gitlab.com/-/snippets/2095934
Post Reply