Class: EatMySoul::Netsoul

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/eatmysoul.rb

Constant Summary collapse

ERROR =
0
NOT_CONNECTED =
1
CONNECTED =
2
AUTHING =
3
AUTHACK =
4
AUTHED =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Netsoul

Returns a new instance of Netsoul.



130
131
132
133
134
135
# File 'lib/eatmysoul.rb', line 130

def initialize(settings)
  @o = settings
  @status = NOT_CONNECTED
  @last_ping = Time.now
  Manager.instance.active_connection = self
end

Instance Attribute Details

#last_pingObject (readonly)

Returns the value of attribute last_ping.



128
129
130
# File 'lib/eatmysoul.rb', line 128

def last_ping
  @last_ping
end

Instance Method Details

#post_initObject



137
138
139
# File 'lib/eatmysoul.rb', line 137

def post_init
  @status = CONNECTED
end

#receive_data(data) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/eatmysoul.rb', line 141

def receive_data(data)
  @o.logger.debug "Read from server \"#{data.chomp}\""

  if @status == CONNECTED
    auth_start data
  elsif @status == AUTHING
    auth data
  elsif @status == AUTHACK
    auth_ack data
  elsif @status == AUTHED
    ping (data)
  elsif @status == ERROR
    @o.logger.warn "Receiving data, but connection is in ERROR state"
  end
end

#unbindObject



157
158
159
160
# File 'lib/eatmysoul.rb', line 157

def unbind
  Manager.instance.active_connection = nil
  EM.add_timer(5) { EM.connect @o.server, @o.port, Netsoul, @o }
end