Class: IRC::Commands::PingCommand

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

Overview

4.6.2 Ping message

Command: PING Parameters: <server1> [<server2>]

The PING message is used to test the presence of an active client at the other end of the connection. A PING message is sent at regular intervals if no other activity detected coming from a connection. If a connection fails to respond to a PING command within a set amount of time, that connection is closed.

Any client which receives a PING message must respond to <server1> (server which sent the PING message out) as quickly as possible with an appropriate PONG message to indicate it is still there and alive. Servers should not respond to PING commands but rely on PINGs from the other end of the connection to indicate the connection is alive. If the <server2> parameter is specified, the PING message gets forwarded there.

Numeric Replies:

  • ERR_NOORIGIN

  • ERR_NOSUCHSERVER

Examples:

PING tolsun.oulu.fi ; server sending a PING message to

another server to indicate it is still
alive.

PING WiZ ; PING message being sent to nick WiZ

Instance Attribute Summary collapse

Attributes inherited from Command

#response

Instance Method Summary collapse

Methods inherited from Command

#execute, #on_server_response, #to_s, #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(first_server, second_server = nil) ⇒ PingCommand

Returns a new instance of PingCommand.

Raises:



68
69
70
71
72
# File 'lib/irc/commands/ping_command.rb', line 68

def initialize(first_server, second_server = nil)
  raise InvalidCommand.new("Can't create ping command. No server.") unless first_server
  @first_server, @second_server = first_server, second_server
  super(command)              
end

Instance Attribute Details

#first_serverObject (readonly)

Returns the value of attribute first_server.



65
66
67
# File 'lib/irc/commands/ping_command.rb', line 65

def first_server
  @first_server
end

#second_serverObject (readonly)

Returns the value of attribute second_server.



66
67
68
# File 'lib/irc/commands/ping_command.rb', line 66

def second_server
  @second_server
end

Instance Method Details

#commandObject

Returns the command as a string.



75
76
77
# File 'lib/irc/commands/ping_command.rb', line 75

def command
  return "PING #{first_server} #{second_server != nil ? second_server.to_s : ''}".strip
end

#valid_response?(message) ⇒ Boolean

Returns true, if the message is a valid response to the command.

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/irc/commands/ping_command.rb', line 80

def valid_response?(message)

  if message.kind_of?(IRC::Messages::PongMessage)
    return first_server == message.daemons[0] && second_server == message.daemons[1]
    
  elsif message.kind_of?(IRC::Messages::ErrorNoOriginMessage) || message.kind_of?(IRC::Messages::ErrorNoSuchServerMessage)
    return true
    
  end      
  
  return false
  
end