Class: IRC::Client::ConnectedState
- Inherits:
-
ConnectionState
- Object
- ConnectionState
- IRC::Client::ConnectedState
- Defined in:
- lib/irc/client/connected_state.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#connect(context, server) ⇒ Object
Connects to the server.
-
#disconnect(context, message = nil) ⇒ Object
Disconnects from the currently connected server.
-
#initialize ⇒ ConnectedState
constructor
A new instance of ConnectedState.
-
#on_disconnect(connection, server, reason = nil) ⇒ Object
This method gets called when disconnected from a server.
-
#send_command(context, command) ⇒ Object
Sends the command to the server bypassing the command queue.
-
#send_command_via_queue(context, command) ⇒ Object
Sends the command to the server using the command queue.
Methods inherited from ConnectionState
#join, #on_ping, #part, #private_message
Methods included from ConnectionListener
#on_connect, #on_join, #on_join_failure, #on_kick, #on_need_more_parameters, #on_notice, #on_part, #on_part_failure, #on_ping, #on_pong, #on_private_message, #on_registration_failure, #on_server_response
Constructor Details
#initialize ⇒ ConnectedState
Returns a new instance of ConnectedState.
39 40 41 |
# File 'lib/irc/client/connected_state.rb', line 39 def initialize @log = Log4r::Logger.new('IRC::Client::ConnectedState') end |
Instance Method Details
#connect(context, server) ⇒ Object
Connects to the server.
44 45 46 |
# File 'lib/irc/client/connected_state.rb', line 44 def connect(context, server) raise ClientError.new("Can't connect to server. Already connected to a server.") end |
#disconnect(context, message = nil) ⇒ Object
Disconnects from the currently connected server.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/irc/client/connected_state.rb', line 49 def disconnect(context, = nil) @log.debug("#{network_name(context)} Disconnecting from server #{context.server.hostname}.") # Send the quit command. If no quit message is given, the nick name will be # send as the default quit message. send_command(context, IRC::Commands::QuitCommand.new( || context.nick)) # Stop the command & message handlers. context.stop_command_handler context. # Set network & server to nil. context.network = context.server = nil # Close socket and set socket to nil. context.socket.close if context.socket != nil context.socket = nil # Change to the disconnected state. change_state(context, DisconnectedState.instance) end |
#on_disconnect(connection, server, reason = nil) ⇒ Object
This method gets called when disconnected from a server.
86 87 88 |
# File 'lib/irc/client/connected_state.rb', line 86 def on_disconnect(connection, server, reason = nil) log.debug("#{network_name(connection)} Successfully disconnected from #{server}. #{reason != nil ? reason + '.' : ''}") end |
#send_command(context, command) ⇒ Object
Sends the command to the server bypassing the command queue.
74 75 76 |
# File 'lib/irc/client/connected_state.rb', line 74 def send_command(context, command) context.command_handler.send_command(command) end |
#send_command_via_queue(context, command) ⇒ Object
Sends the command to the server using the command queue.
79 80 81 |
# File 'lib/irc/client/connected_state.rb', line 79 def send_command_via_queue(context, command) context.command_handler.send_command_via_queue(command) end |