Class: IRC::Commands::NickCommand
- Defined in:
- lib/irc/commands/nick_command.rb
Overview
4.1.2 Nick message
Command: NICK Parameters: <nickname> [ <hopcount> ]
NICK message is used to give user a nickname or change the previous one. The <hopcount> parameter is only used by servers to indicate how far away a nick is from its home server. A local connection has a hopcount of 0. If supplied by a client, it must be ignored.
If a NICK message arrives at a server which already knows about an identical nickname for another client, a nickname collision occurs. As a result of a nickname collision, all instances of the nickname are removed from the server’s database, and a KILL command is issued to remove the nickname from all other server’s database. If the NICK message causing the collision was a nickname change, then the original (old) nick must be removed as well.
If the server recieves an identical NICK from a client which is directly connected, it may issue an ERR_NICKCOLLISION to the local client, drop the NICK command, and not generate any kills.
Numeric Replies:
ERR_NONICKNAMEGIVEN ERR_ERRONEUSNICKNAME ERR_NICKNAMEINUSE ERR_NICKCOLLISION
Example:
NICK Wiz ; Introducing new nick “Wiz”.
:WiZ NICK Kilroy ; WiZ changed his nickname to Kilroy.
Instance Attribute Summary collapse
-
#hopcount ⇒ Object
readonly
Returns the value of attribute hopcount.
-
#nick ⇒ Object
readonly
Returns the value of attribute nick.
Attributes inherited from Command
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(nick, hopcount = nil) ⇒ NickCommand
constructor
A new instance of NickCommand.
-
#on_server_response(connection, message) ⇒ Object
This method gets called when a message from the server is received.
Methods inherited from Command
#execute, #to_s, #valid_response?, #wait
Methods included from IRC::Client::ConnectionListener
#on_connect, #on_disconnect, #on_error, #on_join, #on_join_failure, #on_kick, #on_nick, #on_nick_already_in_use, #on_notice, #on_part, #on_part_failure, #on_ping, #on_pong, #on_private_message, #on_registration, #on_registration_failure, #on_welcome
Constructor Details
#initialize(nick, hopcount = nil) ⇒ NickCommand
Returns a new instance of NickCommand.
73 74 75 76 77 78 |
# File 'lib/irc/commands/nick_command.rb', line 73 def initialize(nick, hopcount = nil) raise InvalidCommand.new("Can't create nick command. No nick name.") unless nick @nick = nick @hopcount = hopcount super(command) end |
Instance Attribute Details
#hopcount ⇒ Object (readonly)
Returns the value of attribute hopcount.
71 72 73 |
# File 'lib/irc/commands/nick_command.rb', line 71 def hopcount @hopcount end |
#nick ⇒ Object (readonly)
Returns the value of attribute nick.
70 71 72 |
# File 'lib/irc/commands/nick_command.rb', line 70 def nick @nick end |
Instance Method Details
#command ⇒ Object
80 81 82 |
# File 'lib/irc/commands/nick_command.rb', line 80 def command return "NICK #{nick} #{hopcount ? hopcount.to_s : ''}" end |
#on_server_response(connection, message) ⇒ Object
This method gets called when a message from the server is received.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/irc/commands/nick_command.rb', line 85 def on_server_response(connection, ) # Ignore notice messages return if .code == IRC::Messages::NoticeMessage::CODE if !connection.registered? || (connection.registered? && .code == IRC::Messages::NickMessage::CODE) connection.remove_connection_listener(self) @response = end end |