BUY THIS BOOK
Add to Cart

Print Book $24.95


Safari Books Online

What is this?

Add to UK Cart

Print Book £17.50

What is this?

Looking to Reprint this content?


IRC Hacks
IRC Hacks 100 Industrial-Strength Tips & Tools

By Paul Mutton
Price: $24.95 USD
£17.50 GBP

Cover | Table of Contents | Colophon


Table of Contents

Chapter 1: Connecting to IRC
One of the great features about IRC is its accessibility. You can connect to any IRC network using an IRC client (read: application). For many users, the IRC client is the friendly face of IRC, allowing you to chat with individuals or groups of users. IRC clients are available for virtually all operating systems. In fact, several different IRC clients are available for Windows, Linux, and Mac OS X, so you are spoiled for choice if you have time to experiment with all available choices.
This chapter will show you how to use some of the most popular IRC clients to connect to IRC. Later hacks will then show you how to go beyond the basics and enhance the functionality of some of these IRC clients by exploiting existing features and writing your own IRC client scripts.
Ask any Windows user what he uses to connect to IRC, and the chances are he will say mIRC.
mIRC is undoubtedly the most popular IRC client for Windows, offering lots of tools, functions, and features. mIRC is shareware, but this fact has not dampened its success over free clients such as Bersirc (http://bersirc.free2code.net) and ChatZilla [Hack #4] . This can be partly attributed to its ease of use, but seasoned IRC users will also find that it provides all of the powerful features they want. mIRC provides extensive scripting support, and thousands of mIRC scripts are available on the Web. mIRC is under active development.
You can grab mIRC from http://www.mirc.com. Like most Windows software, installation is quite straightforward, and it will offer you the chance to create a desktop icon to run it. The first time you run mIRC, it will pop up the Connect dialog automatically, where you must provide some details (as in Figure 1-1).
Figure 1-1: mIRC Options dialog box
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Introduction: Hacks #1-4
One of the great features about IRC is its accessibility. You can connect to any IRC network using an IRC client (read: application). For many users, the IRC client is the friendly face of IRC, allowing you to chat with individuals or groups of users. IRC clients are available for virtually all operating systems. In fact, several different IRC clients are available for Windows, Linux, and Mac OS X, so you are spoiled for choice if you have time to experiment with all available choices.
This chapter will show you how to use some of the most popular IRC clients to connect to IRC. Later hacks will then show you how to go beyond the basics and enhance the functionality of some of these IRC clients by exploiting existing features and writing your own IRC client scripts.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
IRC from Windows
Ask any Windows user what he uses to connect to IRC, and the chances are he will say mIRC.
mIRC is undoubtedly the most popular IRC client for Windows, offering lots of tools, functions, and features. mIRC is shareware, but this fact has not dampened its success over free clients such as Bersirc (http://bersirc.free2code.net) and ChatZilla [Hack #4] . This can be partly attributed to its ease of use, but seasoned IRC users will also find that it provides all of the powerful features they want. mIRC provides extensive scripting support, and thousands of mIRC scripts are available on the Web. mIRC is under active development.
You can grab mIRC from http://www.mirc.com. Like most Windows software, installation is quite straightforward, and it will offer you the chance to create a desktop icon to run it. The first time you run mIRC, it will pop up the Connect dialog automatically, where you must provide some details (as in Figure 1-1).
Figure 1-1: mIRC Options dialog box
Full Name
This is where you can specify your full name (if you want!). Because this is visible to all other IRC users, most people try to protect their anonymity to some extent by entering something funny instead.
Email Address
This is obviously useful if you want other IRC users to be able to contact you, but most people tend to enter fake addresses for fear of spam.
Nickname and Alternative
Here you can specify your nicknames. Whenever you say something on IRC, it will appear to come from your nickname. Because all nicknames on an IRC server must be unique, the dialog requests an alternative nickname, as somebody else may already be connected and using your preferred nickname.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
IRC from Linux
XChat is a popular IRC client with a graphical user interface. You can download the source code or precompiled binaries for a variety of platforms.
XChat can be downloaded from http://xchat.org, either as source code or in the form of precompiled binaries or packages. If you have a packaging system such as apt or Gentoo's emerge, then you may be able to get away with apt-get xchat or emerge xchat.
When you first run XChat, you will be presented with a Server List dialog box. The first task is to go down to the bottom and select Edit Mode. From there, you can see all your server settings. Next examine the top area marked Global User Info. The top three boxes are for your nickname . Most of the time, you will connect with your first listed nickname; however, if that name is already in use by another user, it will try again with the second and then with the third. You shouldn't make these the same, but they can be close variants, for example:
Bob, Bob_, Bobby
Foo, FooBar, Foo_Bar
CoolDude, Cool_Dude, Kewld00d
Your username is used internally by the server to form your host mask, although some servers will try to use an Ident call [Hack #80] to look up your username instead. Your chosen username will be used if the Ident call fails. You can use your nickname, an alternate nickname, or just about anything you want here—although it may be truncated and must not contain any special characters. Your real name can also be anything you want, but it can be longer and can include spaces. As an example, your IRC nickname might be "Han" with username "solo" and real name "Harrison Ford." Be as creative as you like.
The next step is to configure your servers. XChat comes with a lot of servers listed, and it may already have the one you want; if not, you can click
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
IRC from Mac OS X
Several IRC clients are available for Mac OS X. Check them out for your favorite features.
There is no shortage of IRC clients for Macintosh users. ChatZilla [Hack #4] , the truly outstanding IRC client integrated into Mozilla, is popular among Mac users and can also be used on other operating systems. Non-Mozilla users have many alternatives, too. Some applications, such as Fire (http://fire.sourceforge.net), combine IRC chat with ICQ, AIM, and JabberIM. However, because the features of IRC are different than the set for other chat applications, IRC users may find themselves frustrated with these programs. The server-channel model is not clearly supported, and sending standard IRC commands is difficult when they are not all fully supported. One of the friendliest and three of the more popular, and more powerful, IRC clients available for OS X are presented here: Conversation, X-Chat Aqua, Snak, and IRCle.
Conversation (http://www.conversation.pwp.blueyonder.co.uk) is about as close as you'll come to using iChat for IRC. It sports a rather iChat-like look-and-feel (Figure 1-3) with just about everything accessible through an intuitive set of buttons and switches and drag-and-drop support throughout. A Favorites list holds your best buddies and preferred channels so you can just log on and click your way to conversation. A Recent Channels and Users list helps you find that person you were chatting with yesterday or where you had that fabulous conversation last week. Or just set things up so you automatically log in and join your various discussion channels automatically.
Figure 1-3: Conversation, an iChat-like IRC client
While you're best off comparing and contrasting Conversation's feature set with the other clients covered here, it's a good bet you'll find it an intuitive vehicle for your first foray into IRC.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
IRC with ChatZilla
Jump around platforms with the ChatZilla IRC client for Mozilla-based web browsers.
ChatZilla is a cross-platform IRC client written for Mozilla-based browsers. If you're like me and work under various operating systems, you'll have a consistent IRC interface across the board.
If you are using Netscape or a Mozilla build, ChatZilla is quick and easy to start using. If you are using Internet Explorer, Safari, or another non-Mozilla browser, you will need to download the latest version of either Netscape from http://home.netscape.org/downloads or Mozilla from http://mozilla.org.
ChatZilla can be installed directly through the web browser at http://www.hacksrus.com/~ginda/chatzilla. This page contains news and installers. Toward the bottom of the page, you will find the Download section. Several revisions will be listed in the table. If the version has a yellow star next to it, this means the release is probably stable but may contain some bugs. Releases that are expected to be stable will be marked with a green tick. Every version will contain a list of any reported bugs, so you can decide which one you want to install.
The last column of the table has install links, each pointing to an XPI file. These types of files are installers for Mozilla chrome packages. When you click an install link, you will be prompted to accept the install. When you click OK, the software will automatically download and install itself (see Figure 1-10).
Figure 1-10: Installing ChatZilla
Once the installation is complete, you should close your browser. Some versions of Windows may also require you to restart the operating system. Once all the restarts are complete, ChatZilla is ready to use.
ChatZilla can be launched in three ways. The IRC Chat option will appear in the Window menu in your browser. Selecting this will launch the client. You can also use the
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 2: Using IRC
Now that you know how to connect to IRC, it's time to get familiar with the way it works. It is essential to understand the IRC model of networks, servers, channels, and users to chat with individuals and groups alike. IRC is quite often a free-for-all, where unique nicknames are allocated to the first people to ask for them. If you are lucky enough to get the nickname you want, this chapter will show you how to protect this valuable asset and ensure that you can always use it when you reconnect to that particular IRC network.
As with all mature Internet-based technologies, a variety of acronyms and abbreviations are commonly used on IRC. This chapter will familiarize you with the essential lingo, so you won't get confused when people start asking WTH you don't RTFM.
IRC gives you the freedom of creating your own channels—groups of users that share a common interest or theme. This chapter also provides your first glimpse into channel management, showing you how to use ChanServ and CHANFIX to protect your own channel from abuse and to keep out unwelcome visitors.
If you are totally new to IRC, you may be wondering where to begin. Understand the conceptual model of Internet Relay Chat for a good start.
Internet Relay Chat was originally implemented so that users of bulletin board systems could chat with one another in real time. It has grown considerably since then, and thousands of networks of servers are now available for public use. The IRC protocol is text based, so programs that connect to IRC servers are easy to write.
Each IRC network consists of at least one server. If there is more than one server, they are linked together to form a spanning tree. A spanning tree is a structure that allows each server in the network to communicate with all the other servers in the network, even if there is no direct connection between them. Because the servers in an IRC network are connected like this, two users can talk to each other even if they are using different servers on the same IRC network.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Introduction: Hacks #5-11
Now that you know how to connect to IRC, it's time to get familiar with the way it works. It is essential to understand the IRC model of networks, servers, channels, and users to chat with individuals and groups alike. IRC is quite often a free-for-all, where unique nicknames are allocated to the first people to ask for them. If you are lucky enough to get the nickname you want, this chapter will show you how to protect this valuable asset and ensure that you can always use it when you reconnect to that particular IRC network.
As with all mature Internet-based technologies, a variety of acronyms and abbreviations are commonly used on IRC. This chapter will familiarize you with the essential lingo, so you won't get confused when people start asking WTH you don't RTFM.
IRC gives you the freedom of creating your own channels—groups of users that share a common interest or theme. This chapter also provides your first glimpse into channel management, showing you how to use ChanServ and CHANFIX to protect your own channel from abuse and to keep out unwelcome visitors.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
The IRC Model
If you are totally new to IRC, you may be wondering where to begin. Understand the conceptual model of Internet Relay Chat for a good start.
Internet Relay Chat was originally implemented so that users of bulletin board systems could chat with one another in real time. It has grown considerably since then, and thousands of networks of servers are now available for public use. The IRC protocol is text based, so programs that connect to IRC servers are easy to write.
Each IRC network consists of at least one server. If there is more than one server, they are linked together to form a spanning tree. A spanning tree is a structure that allows each server in the network to communicate with all the other servers in the network, even if there is no direct connection between them. Because the servers in an IRC network are connected like this, two users can talk to each other even if they are using different servers on the same IRC network.
Anything that connects to an IRC server that is not another server is called a client. This includes the set of programs that most people use to chat with each other on IRC. An IRC client can connect directly to one of the servers on the IRC network and allow the user to chat with other users on the network. When a private message is sent to another client, it is sent via the IRC network, so there is no need for a separate connection to be made.
Each client that connects to an IRC network must have a unique nickname. Some servers still enforce a limit of nine characters for this nickname, but most servers these days allow much longer nicknames. Nicknames cannot contain spaces or certain punctuation characters.
Communication on IRC is not limited to just sending messages between pairs of users. IRC is very strongly oriented toward the concept of channels. A channel is something rather analogous to a room, where a group of clients can stay and chat as a whole. When a message is sent to a channel, all clients in that channel will receive it. The process of entering a channel is called
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Common Terms, Abbreviations, and Phrases
Once you get into IRC, you need to understand the barrage of abbreviations and phrases that are commonly used.
People will do anything to be lazy—especially where typing is concerned. Anyone who uses IRC will come across abbreviations and certain jargon that will stump them initially. Do not look like a fool by asking unless you absolutely must!
One peculiarity you may notice is that IRC commands are often treated as both verbs and nouns. You can refer to your IRC client documentation for additional commands, but here are some examples:
op
n. A person in a channel who has the +o flag in a channel. Usually has the @ prefix in the username.
v. The act of setting mode +o. Used with omitted subject "me" as a request.
<lamer> op
/mode #
                        
                           channel
                        
                         +o lamer
* idiot sets mode +o lamer
oper
n. A person who has been granted special privileges on the IRC server.
<w8> TsTech is an oper, right?
v. To identify to an IRC server with an administrator login and password, for example.
                        User Password
                     
msg (short for privmsg)
n. A private message to a user.
[lamer(idiot@some-host.com)] you're cool
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Common Acronyms and Initialisms
Master the obscure acronyms people use on IRC to save keystrokes.
IRC attracts a curious breed of user—people who seem happy to sit around chatting all day, yet are too lazy to type full words at times. Understanding the acronyms they use will make it easier to fit in, but you are advised not to join in with their acronym overload.
Here is a list of the most commonly used abbreviations and acronyms on IRC. Some of them may already be familiar to users of Usenet groups or web boards:
AFAIK
As far as I know.
AFK
Away from keyboard. People often type this if they are in the middle of a conversation and want other people to realize they are not around. It is sometimes added to the end of a user's nickname to indicate the same fact; for example, Jibbler may change his nickname to Jibbler|afk.
ASL
Age/Sex/Location. This is something asked of all newcomers in prepubescent channels.
ATM
At the moment.
BBIAB
Be back in a bit.
BBIAF
Be back in a few.
BBL
Be back later.
BBS
Be back soon.
BRB
Be right back. Often said when someone is in the middle of a conversation but has to dash off to do something, with the intention of returning to the conversation.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Register with NickServ
All nicknames on an IRC network must be unique, so if someone steals your nickname, you won't be able to use it. Protect your nickname and get it back with NickServ.
It may have happened to you already—someone trying to impersonate you or just "stealing" your nickname for the fun of it. NickServ will solve this problem for you.
Impersonating someone on IRC is quite easy. When logging in, you can specify your nickname, and the server will never check whether you really are who you pretend to be. This could be considered a weakness. Fortunately, NickServ tries to fix this weakness.
NickServ is one of the Services available on a large number of IRC networks. It sits on the IRC network and sees all the connecting and disconnecting users and nick changes. Of course, just that isn't enough. When you register your nickname with NickServ, you can ask NickServ to kill someone if they are already logged in with your nickname. This can be useful when someone's impersonating you, but it's probably even more useful if your Internet connection fails and you have to log back in—your old session will probably still be active on the server, so you won't be able to use your regular nickname. But if you ask NickServ to kill your old connection, you can take your nickname back.
A more important advantage of registering your nickname with NickServ is that it allows you to register new channels with ChanServ and/or be in channel access lists. This means, among other things, that you can get channel operator status from ChanServ [Hack #9] .
The first step is to register your nickname. This is quite easy on most IRC networks, as all you have to do is send a register message to NickServ. To do this on the freenode IRC network, open a query with NickServ and send the register message like this:
<Wilmer> register 
               password
<NickServ> Your nickname is now registered under the hostmask [*~blabla@*.ipv6.gaast.net].
<NickServ> Your password is [password].  Please remember this for later use.
<NickServ> Freenode is a service of Peer-Directed Projects Center, an
<NickServ> IRS 501(c)(3) (tax-exempt) charitable and educational organization.
<NickServ> For frequently-asked questions about the network, please see the
<NickServ> FAQ page (http://freenode.net/faq.shtml).
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Register Your Channel with ChanServ
Are you having problems with unruly users causing mayhem in your channel? Protect your channel with the ChanServ service.
So you've just created your own channel. If you were the first person to join the channel, then it is likely that the IRC server will have made you into a channel operator. Other users are free to wander into your channel, but you have ultimate control over what goes on. Having operator status means that you can kick and ban unruly users or even moderate the channel, which means people can speak only if you allow them to. Several users have already gathered in your channel, but a software installation requires you to reboot your computer. When you return to your channel, you discover that you are no longer a channel operator! More importantly, nobody else in the channel is a channel operator. The only way to restore your operator status is to ask everybody to leave the channel and be the first to rejoin. Practically speaking, this isn't going to happen.
One solution to this problem would have been to use your operator status to grant the same status to other users in your channel. The problem with this approach is that you need to be able to trust those other users to op you when you rejoin the channel. Another problem is that netsplits (where servers in an IRC network become disconnected) and server maintenance can easily wipe out entire sets of channel operators.
The best solution to this problem is ChanServ . Many IRC networks run Services such as ChanServ, which allow users to manage their channels. Not all ChanServs behave identically, but on the whole they are pretty similar. This hack makes use of the ChanServ on the freenode IRC network. ChanServ can be treated just like any other IRC user, and you can interact with it by sending private messages. To get help on any of the features of ChanServ, simply send the help command via a private message:
               /msg ChanServ help
            
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
The QuakeNet L Channel Bot
ChanServ and NickServ aren't always available. When on QuakeNet, use the L bot to manage your channels.
QuakeNet provides some service bots for you to use so that you can maintain a channel on their servers. The two channel management bots are called Q and L. The Q service provides a few more features than the lighter L bot, but requires a little more effort to request it to join your channel. If you just want a channel for a few friends to chat in or for a small gaming clan, then L is the bot for you. The L bot will allow you to auto-op, voice friends or clan members, and keep your channel open and protected.
You can connect to QuakeNet by typing /server irc.quakenet.org in your favorite IRC client.
This is a quick guide to getting and configuring an L bot. Detailed information and help about these bots can be found at http://www.quakenet.org.
First you need to create an account with Q. All L account information is dealt with through Q, so you need to be authed with Q whenever you want to do anything with an L bot.
Imagine your nickname is ChatterBox and you want to register your nickname. You can do so by sending a private message to Q, like so:
               /msg Q HELLO 
               chatterbox@wanttochat.com chatterbox@wanttochat.com
            
Q will respond with the following:
-Q- Hello, ChatterBox. A new user account has been created for you, with nick ChatterBox.
-Q- OK, Your login information has been sent to "chatterbox@wanttochat.com".
        please check your email for further instructions.
When you receive the email, you should change the password as instructed in the email.
Let's say that your password is "password". Now you can auth with Q:
               /msg Q
               @CServe.quakenet.org AUTH ChatterBox password
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Fix Channel Problems with CHANFIX
EFnet is the oldest IRC network in the world and does not use IRC Services. But it's CHANFIX to the rescue if problems occur in your channel.
Many IRC users are familiar with Services. NickServ and ChanServ keep order on IRC and make problems like "nick juping" (someone preventing your reconnecting by using your nickname) and "channel takeover" a rare event on many IRC networks. However, IRC Services as we know it today was first written in 1995 by Brian "Morpher" Smith and was implemented on the DALnet IRC network, which started up in 1994.
The EFnet IRC network was created in 1988 and is the oldest and one of the largest networks in the world. By 1995, EFnet had achieved 15,000 concurrent users, which was quite a lot back then. To implement Services at that point would undermine the sometimes years of work that had gone into maintaining a channel. It could cause unjust channel takeovers if one user managed to register a channel before the real founder. People who regularly use the same nickname could lose out by being offline when NickServ was implemented and find that someone else had registered their nickname.
For those reasons, EFnet has chosen to go without Services and will continue to do so for the foreseeable future. In its place, Chris "comstud" Behrens has coded a service known as CHANFIX, which monitors channels on the network, tracks who has ops and how often, and can restore channels to their original state in the event of a takeover or complete loss of ops due to splits or attacks against the channel operators.
CHANFIX is linked to EFnet via a custom Services module, giving it an omniscient presence, capable of seeing all channels and users on any server of the network. No registration is required; CHANFIX indexes all channels on EFnet.
Every five minutes, CHANFIX does an index of every channel it sees on EFnet and keeps track of who has ops. Every time CHANFIX runs an index pass, it awards the user@host a single point and keeps a score for the past two weeks. Thus, the maximum score any user can have for a channel is 4032.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 3: Users and Channels
Users and channels are the main components in the conceptual model of IRC. Users are the people you talk to, and you can also talk to channels, which contain groups of users. Channels are often built around a particular topic or theme, and one of the problems for any IRC user is finding the right channel to join. This chapter shows you how to find suitable channels by filtering entire channel lists from a network or how to search on a more global scale and find all relevant channels on any public server in the world. To satisfy the curious, there are also hacks to show you how to find users in channels and to try to guess where in the world a particular user is located.
One of the fun hacks in this chapter shows you how to generate interesting statistics. This lets you bring life to the community in your channel by displaying their photos, along with amusing information such as who talks most, who is least popular, and what time of day the channel is busiest.
If you're new to IRC, one of the biggest problems is working out which network to use. Find a perfect match with one of the search engines for IRC channels.
If you haven't got a clue which IRC network to use, picking a random one is not always the best idea. You may find that the one you choose doesn't cater to your interests. A surefire method of picking the right network is to use an IRC search engine.
One popular IRC search engine can be found at http://irc.netsplit.de/channels. This is maintained by Andreas Gelhausen and uses a collection of IRC bots to connect to hundreds of IRC networks and collect data.
Let's assume that you are new to IRC and need some help, so you enter "irc for beginners" into the search box and click on the Search button. This will search through all of the IRC networks it knows about, looking for channels with topics that match your search terms. The results are shown in Figure 3-1.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Introduction: Hacks #12-16
Users and channels are the main components in the conceptual model of IRC. Users are the people you talk to, and you can also talk to channels, which contain groups of users. Channels are often built around a particular topic or theme, and one of the problems for any IRC user is finding the right channel to join. This chapter shows you how to find suitable channels by filtering entire channel lists from a network or how to search on a more global scale and find all relevant channels on any public server in the world. To satisfy the curious, there are also hacks to show you how to find users in channels and to try to guess where in the world a particular user is located.
One of the fun hacks in this chapter shows you how to generate interesting statistics. This lets you bring life to the community in your channel by displaying their photos, along with amusing information such as who talks most, who is least popular, and what time of day the channel is busiest.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Find Relevant Channels and Servers
If you're new to IRC, one of the biggest problems is working out which network to use. Find a perfect match with one of the search engines for IRC channels.
If you haven't got a clue which IRC network to use, picking a random one is not always the best idea. You may find that the one you choose doesn't cater to your interests. A surefire method of picking the right network is to use an IRC search engine.
One popular IRC search engine can be found at http://irc.netsplit.de/channels. This is maintained by Andreas Gelhausen and uses a collection of IRC bots to connect to hundreds of IRC networks and collect data.
Let's assume that you are new to IRC and need some help, so you enter "irc for beginners" into the search box and click on the Search button. This will search through all of the IRC networks it knows about, looking for channels with topics that match your search terms. The results are shown in Figure 3-1.
Figure 3-1: Using the IRC search engine
The search results are presented as a list of all channels that have topics containing the words you searched for. Each row shows the name of the channel, the name of the network, the time the data was collected, the number of users in the channel, and the topic of the channel. From these results, you can decide which channel you want to join.
If you have an IRC client installed, you can click on the "irc://" link beneath the channel name to automatically connect to that server and join that channel.
You can also use the IRC search engine at http://irc.netsplit.de/channels to view statistics about networks and servers. Figure 3-2 shows the growth of the freenode IRC network over the past five years.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Guess the Time Zone of a User
You're almost off to bed while other users on the channel seem to just get out of bed. That's what happens when IRC is available all over the world, but how can you find out if someone is likely to be awake?
There are several ways to guess the local time of an IRC user, but not all of them are guaranteed to be accurate. The most obvious is to simply ask them what the time is. But what if they aren't around to answer your question? How do you know if they're asleep, not there, or simply ignoring you?
First, you can try to get the user's hostname. You can get it using the /who or /whois command, which reveals information about a user [Hack #15] , or maybe you have the hostname already. Most IRC clients will offer you the option of displaying it when a person joins or parts the channel.
In most cases, you'll see a hostname ending with a two-character country code. Take cc123-a.hnglo1.ov.home.nl as an example. As you may know, NL is the abbreviation for the Netherlands. Now you can look up the current time there. One way to do it is using the Time Zone Converter (http://www.timezoneconverter.com). You can see it in action in Figure 3-3. If you don't know the capital of the country, open the Lookup Time Zone by Country link on the left.
Figure 3-3: Comparing the time in Amsterdam with GMT
There is an obvious problem when you deal with countries that have more than one time zone. Also, with domain extensions like .com or .net, you can't be sure about the user's location. Usually, they point at hosts in the United States, but there are six U.S. time zones in the winter and seven in the summer. Also, there is no guarantee that a .com or .net address even points to somewhere in the United States. Fortunately, there's still a way of finding out where these hostnames belong. For example, you can use the Whois service to check out where the owner of the domain name lives. If that doesn't give any useful information, your last chance is to fetch the Whois information for the IP address the user's hostname points at. To get the Whois information, you can use the
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Study Channel Statistics with pisg
Most IRC clients will give you the option of saving messages to a log file. Generate entertaining statistics from these log files.
pisg is the Perl IRC Statistics Generator. It's available from the web site http://pisg.sourceforge.net and is one of the most popular IRC statistics generators in use today. This hack will show you how to use it to create amusing statistics for your channels and display them to everybody on the Web.
The most important thing you need in order to run pisg is a log file. This log file should contain timestamps so pisg can tell when each message was sent. pisg supports several log file formats, including those used by mIRC, XChat, Eggdrop, irssi, infobot, and PircBot. You will also need Perl in order to run pisg.

Section 3.4.1.1: Editing pisg.cfg

Editing pisg.cfg should be your first step. Set up a channel item that corresponds to the options you would like for your channel. This lets you specify the name of the channel, the log file to read from, the format of the log file, the maintainer of the log file, and the name of the output file, for example:
<channel="#irchacks">
 Logfile = "#irchacks.freenode.log"
 Format = "mIRC"
 Maintainer = "Bob"
 OutputFile = "irchacks.html"
</channel>
Once everything is set up, it's just a simple case of executing the pisg script:
% ./pisg
               
pisg will then tear away at your log files and churn out its statistics. In a matter of seconds to minutes (depending on your computer's speed and the size of the log), you will have a file called irchacks.html (or whatever else you called it) containing all of the statistics.
Copy the output HTML file to somewhere that can display web pages. Any old web server will do the job, as it is just a static HTML page with no server-side content.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Find Users in Channels
Finding someone on IRC is not always that easy, particularly if you don't know his exact nickname. Write some scripts and discover who's in a channel.
Sooner or later, you will probably want to write an IRC gadget that finds specific people in a channel (and possibly sends them a message or does something else to them). In a usual scenario, you can get the list of people dwelling in the channel quite easily, with varying efficiency depending on what approach you take.
Let's take a look at the problem from several different perspectives and see how to solve it in various programming environments.
You could have different criteria for your search. Perhaps you just want to examine whether a user with a given nick is around on the channel. For example, you could be writing a simple !seen robot, which records the time of the last visit of a given person (usually identified by her nick), and you want to check whether the queried nick is actually present on the channel.
If you are interested only in the nick, you could use the NAMES #channel command. This is the command that is automatically executed whenever you join a channel. The command returns a few lines of 353 numeric, ending with the 366 numeric [Hack #78] . One sample line could look like this:
:x.fn.net 353 nickseek @ #irchacks :DeadEd MD87 Monty dg @Jibbler +elvum +pasky
As you can see, the command reveals not only the nicknames of all users in that channel, but also their status. Channel operators will have nicknames that start with @ , half-opped users will start with %, and voiced users will start with +. However, there's a danger here: if the user is both opped and voiced, only the op status will be shown in the NAMES list. When the user loses his op status, he will still be voiced, but you will not know about it. Even some popular IRC clients suffer from this problem, unfortunately.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Filter Channel Lists
Even if you've already found a satisfactory IRC network, you may have missed some interesting channels. Discover them in the output from the LIST command.
One way of finding a relevant channel on a particular IRC network is to ask the network for the list of channels currently in use. Apart from guessing the names of these channels or finding them by word of mouth, you can apply appropriate filters to the list of all the available channels. To acquire such a list, you can use the LIST command, which returns the list of all public channels, together with their topic and number of users.
You can use the skeleton code from the RSS to IRC hack [Hack #66] , again using the Net::IRC Perl module [Hack #33] . For improved performance, you should precompile the regular expressions that get passed from the command line, as you will be matching them over and over many times. Eventually, you can use printf to pretty-print the matching channels with the columns nicely aligned.
Save the following as filterlist.pl:
#!/usr/bin/perl -w
# filterlist.pl - Filter a list of channels based on given criteria.
# MIT licence, (c) Petr Baudis <pasky@ucw.cz>.

use strict;

### Configuration section.
use vars qw ($nick $server $port);
$nick = 'filtelst';
$server = 'irc.freenode.net';
$port = 6667;

### Preamble.
use Net::IRC;

### Arguments munching and data structures setup.
# Arguments.
use vars qw ($chanre $topicre $userlimit);
($chanre, $topicre, $userlimit) = @ARGV;
$chanre ||= ''; $topicre ||= ''; $userlimit ||= 0;

# Precompile the patterns.
$chanre = qr/$chanre/i;
$topicre = qr/$topicre/i;

# List of matched channels, and maximal length of each field for pretty-printing.
use vars qw (@channels $chanlen $userlen);

# This will eventually print out the channels list when it gets called.
sub list_channels {
  my (@channels) = @_;
  foreach my $chan (@channels) {
    my ($channel, $topic, $usercount) = @$chan;
    printf ("\%-${chanlen}s \%${userlen}d \%s\n", $channel, $usercount, $topic);
  }
}

### Connection initialization.
use vars qw ($irc $conn);
$irc = new Net::IRC;
$conn = $irc->newconn (Nick => $nick, Server => $server, Port => $port,
                       Ircname => 'Channels List Filter');

### The event handlers.
# Connect handler - we immediately try to get the channels list.
sub on_connect {
  my ($self, $event) = @_;
  $self->list ( );
}
$conn->add_handler ('welcome', \&on_connect);

# Received one channel item.
sub on_list {
  my ($self, $event) = @_;
  my (undef, $channel, $usercount, $topic) = $event->args;

  # Filter.
  return unless ($channel =~ $chanre);
  return unless ($topic =~ $topicre);
  return unless ($userlimit == 0
                 or ($userlimit < 0 ? $usercount <= -$userlimit
                            : $usercount >= $userlimit));

  # Enqueue for listing.
  push (@channels, [ $channel, $topic, $usercount ]);

  # Update the pretty-printing skids.
  $^W = 0; # Undefined $chanlen.
  $chanlen = length ($channel) if (length ($channel) > $chanlen);
  $userlen = length ($usercount) if (length ($usercount) > $userlen);
  $^W = 1;
}
$conn->add_handler ('list', \&on_list);

# Received the whole channels list.
sub on_listend {
  my ($self, $event) = @_;
  list_channels (@channels);
  exit;
}
$conn->add_handler ('listend', \&on_listend);

# Fire up the IRC loop.
$irc->start;
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 4: Enhancing IRC Clients
Most IRC clients provide the same basic subset of functionality, but you can really improve your IRC experience by exploiting the features provided by your particular IRC client. Almost all IRC clients offer various shortcuts to prevent your having to type more than necessary. Nickname completion is seemingly universally supported and means you don't have to type the full nickname of another user when you address her. This is particularly useful when you encounter channels that contain users with strange nicknames.
Some of the enhancements introduced by this chapter are simple yet useful, such as adding timestamps to your messages and highlighting keywords from other users. You will also be introduced to IRC scripting, which enables you to customize the functionality of your IRC client. Practical examples include filtering banned words, managing huge debate channels, getting your IRC client to talk out loud, and controlling captions on webcams.
IRC is primarily a text-based chat system, but that doesn't mean you are limited to using just plain text. This chapter shows you how to add colors and other formatting to your messages, making them stand out among the rest.
While older IRC clients could connect to only one server at a time, modern IRC clients allow you to connect to any number of servers. Even the most paranoid user can feel safe using IRC, as this chapter also shows you how to secure your IRC connection or tunnel it through other machines.
Your client does the typing so that you don't have to.
Often when chatting on IRC you spend much of your time just typing in people's nicknames. This can get tedious, so many clients have some kind of automatic completion facility that works out whose nick you're trying to type and finishes the job for you. This hack will explain the nick-completion functionality provided in several popular IRC clients.
mIRC provides basic tab-completion functionality that will be familiar to anyone who's used a modern command-line interface. Type the first letter or so of a nickname and press the Tab key. mIRC will then complete the rest of the nickname for you, as shown in Figure 4-1. If more than one nick starts with the part that you typed, mIRC will allow you to cycle through the available options by repeatedly pressing the Tab key.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Introduction: Hacks #17-30
Most IRC clients provide the same basic subset of functionality, but you can really improve your IRC experience by exploiting the features provided by your particular IRC client. Almost all IRC clients offer various shortcuts to prevent your having to type more than necessary. Nickname completion is seemingly universally supported and means you don't have to type the full nickname of another user when you address her. This is particularly useful when you encounter channels that contain users with strange nicknames.
Some of the enhancements introduced by this chapter are simple yet useful, such as adding timestamps to your messages and highlighting keywords from other users. You will also be introduced to IRC scripting, which enables you to customize the functionality of your IRC client. Practical examples include filtering banned words, managing huge debate channels, getting your IRC client to talk out loud, and controlling captions on webcams.
IRC is primarily a text-based chat system, but that doesn't mean you are limited to using just plain text. This chapter shows you how to add colors and other formatting to your messages, making them stand out among the rest.
While older IRC clients could connect to only one server at a time, modern IRC clients allow you to connect to any number of servers. Even the most paranoid user can feel safe using IRC, as this chapter also shows you how to secure your IRC connection or tunnel it through other machines.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Automatic Completion of Nicknames
Your client does the typing so that you don't have to.
Often when chatting on IRC you spend much of your time just typing in people's nicknames. This can get tedious, so many clients have some kind of automatic completion facility that works out whose nick you're trying to type and finishes the job for you. This hack will explain the nick-completion functionality provided in several popular IRC clients.
mIRC provides basic tab-completion functionality that will be familiar to anyone who's used a modern command-line interface. Type the first letter or so of a nickname and press the Tab key. mIRC will then complete the rest of the nickname for you, as shown in Figure 4-1. If more than one nick starts with the part that you typed, mIRC will allow you to cycle through the available options by repeatedly pressing the Tab key.
Figure 4-1: Tab completion in mIRC: before (left) and after (right) pressing Tab
irssi provides tab-completion features similar to those found in mIRC. If the nick you tab-complete is the first word in a message, irssi assumes that you're addressing someone, and automatically adds a colon to the end of the nick. In addition, the concept of tab completion has been extended to the rest of the irssi interface. You can see a list of all user completions by entering /completion .
XChat offers some more advanced nick-completion features, which are configured in the Interface Input Box page of the Preferences dialog. As with irssi, if the nick you are trying to complete is the first word of a line, XChat will assume that you are addressing the person in question and add an optional suffix to the nick. By default, this suffix is a comma, as shown in Figure 4-2. Unlike mIRC and
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Add Timestamps to mIRC Messages
If you leave your IRC client running all the time, learn when each message was sent.
Many people leave their IRC c