Class: IRC::Client::DisconnectedState

Inherits:
ConnectionState show all
Defined in:
lib/irc/client/disconnected_state.rb

Instance Method Summary collapse

Methods inherited from ConnectionState

#on_ping, #on_welcome

Methods included from ConnectionListener

#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

#initializeDisconnectedState

Returns a new instance of DisconnectedState.



42
43
44
# File 'lib/irc/client/disconnected_state.rb', line 42

def initialize
  @log = Log4r::Logger.new('IRC::Client::DisconnectedState')  
end

Instance Method Details

#change_nick(context, nick) ⇒ Object

Changes the nick name.

Raises:



47
48
49
# File 'lib/irc/client/disconnected_state.rb', line 47

def change_nick(context, nick)
  raise ClientError.new("Can't change nick name. Not connected to a server.")
end

#connect(context, server) ⇒ Object

Connects to the server.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/irc/client/disconnected_state.rb', line 52

def connect(context, server)
  
  @log.debug("#{network_name(context)} Trying to connect to server #{server.hostname} on port #{server.port}.")
  
  # Establish the connection to the server.        
  establish_connection(context, server)
  
  # Set the server to which we are connected.    
  context.server = server
  
  # Clear the supported options, that get initialized by the isupport messages.
  context.options = Hash.new
  
  # Initialize and start the command & message handlers.
  context.start_command_handler
  context.start_message_handler      
  
  # Change to the unregistered state.
  change_state(context, UnregisteredState.instance)                  
  
  # Notify all connection listeners that we are successfully connected now.
  context.connection_listeners.each do |connection_listener|
    connection_listener.on_connect(context, server)
  end  
  
rescue Exception => e
  raise ClientError.new("Can't connect to server #{server.hostname} on port #{server.port}. #{e.message.capitalize}.")
  
end

#disconnect(context, message = nil) ⇒ Object

Disconnects from the currently connected server.

Raises:



83
84
85
# File 'lib/irc/client/disconnected_state.rb', line 83

def disconnect(context, message = nil)
  raise ClientError.new("Can't disconnect. Not connected to a server.")
end

#join(context, channels) ⇒ Object

Joins the given channels.

Raises:



88
89
90
# File 'lib/irc/client/disconnected_state.rb', line 88

def join(context, channels)
  raise ClientError.new("Can't join any channel. Not connected to a server.")      
end

#on_connect(connection, server) ⇒ Object

This method gets called when successfully connected to a server.



120
121
122
# File 'lib/irc/client/disconnected_state.rb', line 120

def on_connect(connection, server)
  log.debug("#{network_name(connection)} Successfully connected to #{server} on port #{server.respond_to?(port) ? server.port.to_s : IRC::Models::Server::DEFAULT_PORT}.")
end

#part(context, channels) ⇒ Object

Leaves the given channels.

Raises:



93
94
95
# File 'lib/irc/client/disconnected_state.rb', line 93

def part(context, channels)
  raise ClientError.new("Can't leave any channel. Not connected to a server.")      
end

#private_message(context, target, message) ⇒ Object

Sends a private message to the target (a nick or a channel).

Raises:



98
99
100
# File 'lib/irc/client/disconnected_state.rb', line 98

def private_message(context, target, message)
  raise ClientError.new("Can't send a private message. Not connected to a server.")            
end

#register(context, nick, login, realname) ⇒ Object

Register the connection by sending the password, nick and user commands.

Raises:



103
104
105
# File 'lib/irc/client/disconnected_state.rb', line 103

def register(context, nick, , realname)
  raise ClientError.new("Can't register connection. Not connected to a server.")                  
end

#send_command(context, command) ⇒ Object

Sends the command to the server bypassing the command queue.

Raises:



108
109
110
# File 'lib/irc/client/disconnected_state.rb', line 108

def send_command(context, command)
  raise ClientError.new("Can't send command. Not connected to a server.")
end

#send_command_via_queue(context, command) ⇒ Object

Sends the command to the server using the command queue.

Raises:



113
114
115
# File 'lib/irc/client/disconnected_state.rb', line 113

def send_command_via_queue(context, command)
  raise ClientError.new("Can't send command. Not connected to a server.")
end