Class: IRC::Commands::UserCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/irc/commands/user_command.rb

Overview

Command: USER

Parameters: <username> <hostname> <servername> <realname>

The USER message is used at the beginning of connection to specify the username, hostname, servername and realname of s new user. It is also used in communication between servers to indicate new user arriving on IRC, since only after both USER and NICK have been received from a client does a user become registered.

Between servers USER must to be prefixed with client’s NICKname. Note that hostname and servername are normally ignored by the IRC server when the USER command comes from a directly connected client (for security reasons), but they are used in server to server communication. This means that a NICK must always be sent to a remote server when a new user is being introduced to the rest of the network before the accompanying USER is sent.

It must be noted that realname parameter must be the last parameter, because it may contain space characters and must be prefixed with a colon (‘:’) to make sure this is recognised as such.

Since it is easy for a client to lie about its username by relying solely on the USER message, the use of an “Identity Server” is recommended. If the host which a user connects from has such a server enabled the username is set to that as in the reply from the “Identity Server”.

Numeric Replies:

  • ERR_NEEDMOREPARAMS

  • ERR_ALREADYREGISTRED

Examples:

User registering themselves with a username of “guest” and real name “Ronnie Reagan”.

USER guest tolmoon tolsun :Ronnie Reagan

Message between servers with the nickname for which the USER command belongs to

:testnick USER guest tolmoon tolsun :Ronnie Reagan

Instance Attribute Summary collapse

Attributes inherited from Command

#response

Instance Method Summary collapse

Methods inherited from Command

#execute, #on_server_response, #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_server_response, #on_welcome

Constructor Details

#initialize(user, host, server, realname) ⇒ UserCommand

Returns a new instance of UserCommand.

Raises:



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/irc/commands/user_command.rb', line 81

def initialize(user, host, server, realname)

  raise InvalidCommand.new("Can't create user command. User name is missing.") unless user
  @user = user
  
  raise InvalidCommand.new("Can't create user command. Host is missing.") unless host        
  @host = host
  
  raise InvalidCommand.new("Can't create user command. Server is missing.") unless server        
  @server = server
  
  raise InvalidCommand.new("Can't create user command. Real name is missing.") unless realname        
  @realname = realname

  super(command)      
          
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



77
78
79
# File 'lib/irc/commands/user_command.rb', line 77

def host
  @host
end

#realnameObject (readonly)

Returns the value of attribute realname.



79
80
81
# File 'lib/irc/commands/user_command.rb', line 79

def realname
  @realname
end

#serverObject (readonly)

Returns the value of attribute server.



78
79
80
# File 'lib/irc/commands/user_command.rb', line 78

def server
  @server
end

#userObject (readonly)

Returns the value of attribute user.



76
77
78
# File 'lib/irc/commands/user_command.rb', line 76

def user
  @user
end

Instance Method Details

#commandObject



99
100
101
# File 'lib/irc/commands/user_command.rb', line 99

def command 
  return "USER #{user} #{host} #{server} :#{realname}"
end