Reputation: 169
I am building a very basic Python BOT in Python 3; Mostly feeding off several manuals and tutorials since I am just learning the language. My issue right now is connecting into the server, all I receive is the following:
:ircserver NOTICE * :*** Looking up your hostname...
:ircserver NOTICE * :*** Couldn't resolve your hostname; using your IP address instead
PING :CFC3BEE0
:ircserver 451 JOIN :You have not registered
ERROR :Closing Link: Botski[serverIPaddress] (Registration Timeout)
whereas ircserver is the address of the server; and serverIPaddress is the IP, ommited because it's irrelevant
I have read somewhere that "Registration Timeout" is caused due to failure to respond to PING. I can see right there it says PING :CFC3BEE0
I respond to that this way
if ircmsg.find("PING :") != -1:
pongvalor = ircmsg[6:13]
ping(pongvalor)
So, what I believe this should do is, if it receives a message where it says PING : ; it should take the characters 6 to 13 (in this case CFC3BEE0), put them in variable pongvalor and send them into ping() ; whereas ping() is:
def ping(pong):
ircsock.send(bytes("PONG :" + pong + "\r\n", "UTF-8"))
So, it should respond PONG :CFC3BEE0 ; Am I doing something wrong?
Code, in case it's necesary: https://pastebin.com/2HdgBF58
Thanks for your time.
Upvotes: 3
Views: 2161
Reputation: 528
You've confused a couple of things here.
First, the "Registration timeout" error means you did not register your connection in time, and the server closed the connection. Second, you do not need to send a PING
message to the server; the server sends a PING
to you, to which you reply with a matching PONG
, but this is not (normally; see end) part of connection registration. These messages are for testing the presence at the other end of the connection, which is almost always for making sure the connection is still alive.
Connection Registration refers to the initial NICK
and USER
messages that must be sent by the connecting client to the IRC server before sending any other message. As detailed in RFC 1459, basic connection registration is a 2-3 step process:
PASS
message containing the server passwordNICK
messageUSER
messageA PASS
message is optional, but if one is required, then it must be sent before the NICK
and USER
messages.
Capability negotiation also takes place at this point, but this is beyond the scope of this answer, and indeed basic RFC 1459-compliance. Don't worry about it for now.
Once the NICK
and USER
messages have been received by the server, connection registration will be complete, and the server will then proceed with the usual routine of RPL_WELCOME
, RPL_ISUPPORT
, server information, MOTD, etc. You can now send any other arbitrary IRC message at this point, like JOIN
, for example.
Some servers also send a PING
immediately after receiving the NICK
/USER
pair and expect a matching PONG
before completing connection registration, so make sure your recv
loop starts early enough to handle this.
You need to register your connection immediately after connecting to the server. The server may or may not send a PING
and expect a PONG
at any point during this phase. If registration is successful, you will be greeted by the server and sent the usual messages such as the MOTD.
Upvotes: 3