Class: Burn::Server::Telnet::Messenger

Inherits:
EM::Connection
  • Object
show all
Includes:
Debug
Defined in:
lib/burn/server/telnet.rb

Constant Summary collapse

@@channel =
EM::Channel.new

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Debug

#log

Class Method Details

.publish(message) ⇒ Object



64
65
66
# File 'lib/burn/server/telnet.rb', line 64

def self.publish(message)
  @@channel.push message
end

Instance Method Details

#post_initObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/burn/server/telnet.rb', line 35

def post_init
  if EM::connection_count <= Telnet.conf.server.max_clients then
    log "-- someone connected"
    @sid = @@channel.subscribe { |data| send_data data }
    log @sid
    # display current screen for newly connected user
    @@channel.push Telnet.vm.screen.to_terminal
  else
    send_data "Burn telnet server refused to establish connection, since there is no remaining connection slots. Please try later."
    close_connection true
  end
end

#receive_data(data) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/burn/server/telnet.rb', line 48

def receive_data(data)
  #@@channel.push data
  #puts data # only shown in server's terminal
  receive = proc do
    #"user=#{@sid} typed [" + data + "]"
    Telnet.vm.interrupt data.ord
    log "...ord=#{data.ord},#{data}"
  end
  Telnet.op receive
end

#unbindObject



59
60
61
62
# File 'lib/burn/server/telnet.rb', line 59

def unbind
  log "-- someone(#{@sid}) disconnected from the server"
  @@channel.unsubscribe(@sid)
end