Class: Fargo::Protocol::Hub
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Fargo::Protocol::Hub
- Defined in:
- lib/fargo/protocol/hub.rb
Instance Attribute Summary collapse
-
#hubname ⇒ Object
readonly
Returns the value of attribute hubname.
Attributes included from DC
Instance Method Summary collapse
-
#receive_message(type, message) ⇒ Object
See <www.teamfair.info/DC-Protocol.htm> for specifics on the DC protocol.
Methods included from Utils
#encode_char, #generate_key, #generate_lock
Methods included from DC
#post_init, #publish_args, #receive_data, #send_message, #unbind
Methods included from Fargo::Parser
#parse_command_message, #parse_message
Instance Attribute Details
#hubname ⇒ Object (readonly)
Returns the value of attribute hubname.
8 9 10 |
# File 'lib/fargo/protocol/hub.rb', line 8 def hubname @hubname end |
Instance Method Details
#receive_message(type, message) ⇒ Object
See <www.teamfair.info/DC-Protocol.htm> for specifics on the DC protocol
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 |
# File 'lib/fargo/protocol/hub.rb', line 12 def type, case type when :lock @validated = false 'Key', generate_key([:lock]) when :hubname @hubname = [:name] 'ValidateNick', @client.config.nick unless @validated when :getpass 'MyPass', @client.config.password when :badpass, :hubfull Fargo.logger.warn "Disconnecting because of: #{.inspect}" close_connection_after_writing when :hello if [:who] == @client.config.nick Fargo.logger.info "Connected to DC Hub #{@hubname}" @validated = true 'Version', '1,0091' 'MyINFO', "$ALL #{@client.config.nick} " + "#{@client.description}$ $#{@client.config.speed}" + "#{@status || 1.chr}$#{@client.config.email}" + "$#{@client.share_size}$" 'GetNickList' end when :connect_to_me if !@client.nicks.include?([:nick]) Fargo.logger.info "Invalid connect_to_me request from: #{[:nick]}" return end EventMachine.connect [:address], [:port], Fargo::Protocol::Download do |conn| conn.client = @client conn.send_lock # We connect first, we send lock first end when :search # Let the client handle the results @results = @client.search_files # Send all the results to the peer. Take care of active/passive # connections @results.each { |r| if [:address] r.active_send @client.config.nick, [:ip], [:port] else 'SR', "#{@client.config.nick} #{r}" end } when :revconnect if @client.config.passive 'RevConnectToMe', "#{@client.config.nick} #{[:who]}" else 'ConnectToMe', "#{@client.config.nick} #{@client.config.address}:#{@client.config.extport}" end # proxy this message on up the stack if we don't handle it else super end end |