Note: The mainteinance of the scripting examples is discontinued since I no longer have an interest to continue doing so. The pages will remain here, for now, but that might not be the case in the future. You are free to download all the material on these pages and set a up mirror, or even continue the maintenance of the material by enhancing the examples yourself.
All the material in these examples are for the mIRC version 6.03. It is very likely that some or most of these examples won't work in future versions.
Many IRC networks are truly international. You might see people from countries you can barely remember. The problem is that when you see someone's hostname, it might look like hawking.pp.htv.fi. So what does .fi mean? Fiji? Finland? Something else? The truth is that nobody remembers all the country codes unless you are one of those who have a hobby of learning pi decimals. :-)
Converting a country code (like .uk) into a country name (like United Kingdom) is something that hash tables are very good for. It is a prime example of the intended use of hash tables. We set an item (uk) that will resolve into a country name (United Kingdom). Then we can simply do $hget(<hash table>,uk) and it will return 'United Kingdom'.
Usually the only real problem in making a country code to country name convertor is where to get all the codes and names. It's not hard to get them but it is often a frustrating task that is merely repeating certain keystrokes. You can do one yourself from IANA ccTLD Database or then use the conversion table I have made. The file is only a few kilobytes. Note that some browsers might try to save the cc.dat as cc.dat.txt so be sure that your browser doesn't fool you. The default path is the mIRC directory so save it there or then modify the script to use it from another location.
; Load the country code conversion table when you start mIRC
; Give an error if the file isn't found
on *:START: {
if ( $exists(cc.dat) ) {
hmake countries 150
hload countries cc.dat
}
else echo -se * Country code conversion table not found
}
; Returns the country name for a hostname (like machine.example.co.uk)
; Note that many hostnames can't be resolved into a country
; If it can't be resolved, the alias returns an empty value
; $1 = Hostname
alias cc_to_country {
; The country code is the last item separated by a dot
return $hget(countries,$gettok($1,-1,46))
}
; If we can resolve the code into a country name, display it on joins
on ^!*:JOIN:#: {
if ( $cc_to_country($site) ) {
echo $color(join text) -t $chan * $nick ( $+ $address $+ ) ( $+ $cc_to_country($site) $+ ) has joined $chan
haltdef
}
}
; Display the country in whois replies if it's available
raw 311:*: {
if ( $cc_to_country($4) ) {
echo $color(whois text) -s $2 is $3 $+ $4 ( $+ $cc_to_country($4) $+ ) * $6-
halt
}
}
Note that the countries can't be displayed if the hash table isn't loaded. If the script doesn't work, first check that you really have loaded the hash table succesfully. If you are not sure how you can check it, just restart mIRC and see the possible error replies on startup.
My own conversion table has only the country codes that are clearly for one country. That means it lacks codes like .com, .net, .org, .edu, and .info. Feel free to add them to the conversion table if you wish to convert them into something descriptive.