mIRC Homepage

Need a very simple code

Posted By: Sleepyhead

Need a very simple code - 30/12/21 06:19 AM


i have an alias code as following :-

/bos ban -u14500 # $$1 2 | /kick # $$1 $2- Fast Ban!

and i have a remote code as following :-

on *:JOIN:#:{
var %ident $remove($gettok($address($nick,5),1,64),$nick $+ !)
var %host $gettok($address($nick,5),2,64)
var %c 1, %l $lines(scripts\Abuse.ini)
while (%c <= %l) {
var %line $read(scripts\Abuse.ini,%c)
if ($findtok(%line,$nick,0,32) || $findtok(%line,%ident,0,32) || $findtok(%line,%host,0,32)) {
mode # +b $+($nick,!*@*)
kick # $nick [Banned] Oh i know u!
inc %c 1

i am looking to integrate both the codes as such that a manual kick/ban (by typing /bos nick) should automatically add that banned ip & nick into a file (say abuser.ini). The remote code in return will always look for ips and nicks saved in that abuser.ini file and ban them as soon as they join. The code should either look for a matching ip or nick or both. A dialogue to add or delete any ip or nick manually would be wonderful laugh

any other suggestions are most welcome smile

p.s none of these codes are mine but i have found it elsewhere. i am just grateful for all those ppl who post their codes to help ppl like us.
Posted By: maroon

Re: Need a very simple code - 30/12/21 05:46 PM

The solution is similar to an earlier thread

... except they had many badwords to match against all the words in a sentence, while you have many banned-addresses to match against 1 person.

If you compare the person's address against each banned-address 1 at a time, it will be a slow loop that must repeat for each address in the banned list.

Instead of putting each banned address into a disk file which requires reading each line 1 at a time, you can put them all in a hashtable, which can be loaded/saved as needed.

Then, you can have $hfind use the capital W switch so that it sees each hashtable item as a wildcard. You'd then compare them against a text string containing the nick!userid@hostname without wildcards, which is $address($nick,5) and can also be the same as $fulladdress within some events.

You can tell it you want to see the 1st match, and it stops when there's a match, and reports the itemnamed used for the match.

These wildcards would be valid itemnames, so you can use them as the itemname to avoid the need to create a random itemname in order to hold the banned addresses as the 'data' for hashtable items.
Posted By: Sleepyhead

Re: Need a very simple code - 31/12/21 01:17 AM

Hello Maroon,

I hope you are doing well,

I totally agree with what you just said but there is a problem. although i could read a code and understand it, i do not know how to write it. I get the logic behind using hashtable and not .ini or txt file to save and pull data from it. It would be awesome if you could help me with the code. I also went through the link you have posted in your response. I do understand that code but i am not sure how i could modify it just to suit my needs.

Posted By: maroon

Re: Need a very simple code - 02/01/22 01:49 AM

This is an example of how $hfind can find matches between 1 person's address and all the wildcard banmasks in the hashtable.

//hfree -w foo | hadd -ms foo *@*.irccloud.com data | hadd -ms foo *!*foobar@* data | var %address nick!sid12345@servername.irccloud.com | echo -a $hfind(foo,%address,1,W)

With this syntax, when it finds a match, it returns the 1st item-name in the hashtable that's a wildcard match against the not-wildcard string in %address. Hashtables only exist in ram, so if you need to save things for next time you run mirc, you need to save changes to disk, and then reload next time.

write to disk in ini format after making updates to the list:

hsave -si foo filename

The -i switch causes this to be in .ini format, regardless what kind of filename you use.

The next time you start mirc, you'd load the ban list from disk:

hload -sim foo filename
Posted By: Sleepyhead

Re: Need a very simple code - 02/01/22 03:19 AM

Hello Maroon,

Happy new year to you!

So, if i m getting this all right, This example illustrates that the code would create a .ini file and store the banned mask or wildcards in it just to fetch it later using hfind? In that case, will it create multiple hash files for different masks or wildcards or will i be able to integrate all the entries in just 1 file just to save some space on the disk? And where am i suppose to paste this code just to make it work?

I am sorry, i am just a novice when it comes to scripting frown

Thanks & Regards,
Posted By: maroon

Re: Need a very simple code - 02/01/22 09:57 PM

There's more on hashtables at https://en.wikichip.org/wiki/mirc/hash_tables

In a lot of ways, the /hadd item data command is to hashtables what /set %item data is for %variables
In a lot of ways, the $hget(table,item) command is to hashtables what accessing a variable named %item does
In a lot of ways, the /hdel item command is to hashtables what /unset %item is for %variables

Hashtables don't autosave to disk by themselves, so it's up to the script to decide when/if they should be written to disk

Hashtables are different than %variables because all global %variables are in effect located in the same global 'table' that should be saved to disk by itself.

There's several formats for hashtables to be written to disk, including 2 formats for saving binary data, including the -B option which can old variables up to 2^32-1 in length assuming mirc can handle them

When saving/loading disk data in the ini format, it defaults to using a [section] named Hashtable but you can override that to have several different sections all within the same file.

So, if you wish, you can keep everything in 1 table and 1 [section], or you can split them into a different table per channel etc.
Posted By: Raccoon

Re: Need a very simple code - 04/01/22 07:22 AM

One benefit to Hash Tables that needs to be pointed out is the total ease in adding and retrieving dynamically named items, in comparison to dynamically named variables. No messing around with nested brackets or $eval(). Just simple concatenation in both /hadd and $hget().

/hadd MyTable $+(spammer.,$nick,.,$chan,.,$network,.,$cid) $ctime

if ($hget(spammer.,$nick,.,$chan,.,$network,.,$cid)) { ban -k $chan $nick 2 Spammer! }
Posted By: Sleepyhead

Re: Need a very simple code - 07/01/22 02:34 AM


Thanks for your response,

Although, i agree to the points you guys are making out here but I am actually looking for an entire code as i dont know how to code.
© 2022 mIRC Discussion Forums