I've looked at the RFC but I am still struggling. I've written a basic client in C# but I cannot find documentation for how to connect properly.
Once I connect and transmit NICK and USER information, I need to join a channel. If I do a JOIN straight away, nothing happens - presumably because it's too soon. I have to delay it, but I don't know which command I need to wait for to know it's okay to go ahead.
I get stuff like:
:irc.fish.net NOTICE AUTH :looking up your hostname...
and
:irc.fish.net 001 FishBot :Welcome
as well as stuff with codes 002, 003, 005, 251, 252, etc. but I can't find anywhere online that shows me what these are.
So my basic 2 questions are: What do you send a JOIN in response to, and where can I find what the IRC codes above correspond to? The RFC document was useless!
The RFC documents are certainly not useless! You are correct that you need to send
USER
followed byNICK
. TheNOTICE
you are getting is that the IRC server is attempting to connect back to your PC via a protocol calledIDENTD
. It's a relatively simple protocol but the upshot of it is that it wants to know that a program on the host that is connected to the server, is using the local/remote ports that the server has.Chances are, your firewall is preventing this (and you're probably not running an IDENTD server). This is not a huge problem, though a fully-fledged IRC client will implement it. You can find out more here. That goes in to much more detail. It's relatively simple to implement.
Most IRC servers will give up if it cannot connect to you, and I've forgotten the exact side-effect of this (it has been a while), but the next messages you want to look out for are the MOTD_START/MOTD/MOTD_END and ERR_NOMOTD. Only after you have received the end of the Message of the day, or handled the ERR_NOMOTD (there isn't one), can you then use
JOIN
to join channels.Incidentally, this is a good RegEx for matching input from an IRC Server:
The IRC RFCs list all the possible codes and what they mean. I'm not sure why you think they are useless. Which ones have you been referencing?
EDIT
I looked up my old C++ code for IRC so I could be a bit more helpful. After connecting, it enters a stage (that I have labelled) negotiating:
Negotiating Stage:
PASS mypassword
.USER
command.ERR_NOMOTD
,END_OFMOTD
. Until one of these comes, you're not "officially connected".Negotiate Nickname Stage:
It's entirely possible that during connection, the nickname you want to use is already in use. Therefore the client should:
NICK
commandERR_NICKINUSE
response, issue it again. If you have no more nicknames to use, you can either bailout or prompt the user for another one.Some other thing to consider:
PING
command. The server will send this when you're idle. Handle this as high-priority and returnPONG
with the data the server gave you. Failure to do this will ensure you get disconnected and when you're testing an IRC client, this can be a pain in the rear-end.Bonus Fun
This is my enum for the IRC commands, you should be able to put this in to C# easily enough:
The codes can be found in this document, the ones you specified are:
Maybe you looked at an old version (RFC 1459) instead of the current version (RFC 2812) of the standard?
The latter one lists the numeric codes in Section 5 "Replies":
(That should answer your second question; unfortunately, I'm not familiar enough with the protocol to answer your first. A simple solution to get you on the right track might be to trace the connection of an existing IRC client using some packet sniffer.)