Class: Nova::Starbound::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/nova/starbound/client.rb

Overview

A client for Nova.

Constant Summary collapse

DEFAULT_OPTIONS =

The default options when dealing with this class.

{
  :type => :tcp,
  :host => "127.0.0.1",
  :port => 2010
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Initialize with the given options.

Parameters:

  • options (Hash) (defaults to: {})


29
30
31
32
33
# File 'lib/nova/starbound/client.rb', line 29

def initialize(options = {})
  @options = DEFAULT_OPTIONS.merge(options)
  @protocol_options = (@options.delete(:protocol) || {}).dup
  @protocol = Protocol.new @protocol_options.merge(:type => :client)
end

Instance Attribute Details

#optionsHash (readonly)

The options that were passed to the client on initialization.

Returns:

  • (Hash)


12
13
14
# File 'lib/nova/starbound/client.rb', line 12

def options
  @options
end

#protocolProtocol (readonly)

The underlying protocol that powers this client.

Returns:



17
18
19
# File 'lib/nova/starbound/client.rb', line 17

def protocol
  @protocol
end

Instance Method Details

#handshakevoid

This method returns an undefined value.

Do the handshake with the server.



38
39
40
41
# File 'lib/nova/starbound/client.rb', line 38

def handshake
  @protocol.socket = socket
  @protocol.handshake
end

#socketObject

Create the socket.

Returns:

  • (Object)


46
47
48
49
50
51
52
53
54
55
# File 'lib/nova/starbound/client.rb', line 46

def socket
  @_socket ||= case options[:type]
  when :tcp
    TCPSocket.new(options[:host], options[:port])
  when :unix
    UNIXSocket.new(options[:path])
  when :pipe
    options[:pipe]
  end
end