Module: Fargo::Protocol::Hub
Instance Attribute Summary collapse
-
#hubname ⇒ Object
readonly
Returns the value of attribute hubname.
Attributes included from DC
Instance Method Summary collapse
- #connection_type ⇒ Object
-
#receive_message(type, message) ⇒ Object
See <www.teamfair.info/DC-Protocol.htm> for specifics on the DC protocol.
Methods included from DC
#parse_data?, #post_init, #publish_args, #receive_data, #receive_data_chunk, #send_message, #unbind
Methods included from Fargo::Parser
#parse_command_message, #parse_message
Methods included from Utils
#encode_char, #generate_key, #generate_lock
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
#connection_type ⇒ Object
10 11 12 |
# File 'lib/fargo/protocol/hub.rb', line 10 def connection_type :hub end |
#receive_message(type, message) ⇒ Object
See <www.teamfair.info/DC-Protocol.htm> for specifics on the DC protocol
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/fargo/protocol/hub.rb', line 16 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.info "Disconnecting because of: #{.inspect}" close_connection_after_writing when :hello if [:nick] == @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 EventMachine.connect [:address], [:port], Protocol::Peer do |conn| conn.client = @client conn.send_lock # We connect first, we send lock first end when :search # Let the client handle the results search = Search.new @listings = @client.search_local_listings search @results = @listings.map do |l| file = l.name.gsub '/', "\\" if File.directory? l.name s = file else s = "#{file}\005#{l.size}" end s + sprintf(" %d/%d\005%s (%s:%d)", @client.open_upload_slots, @client.config.upload_slots, 'TTH:' + l.tth, @client.config.hub_address, @client.config.hub_port) end # Send all the results to the peer. Take care of active/passive # connections if [:address] socket = EventMachine.open_datagram_socket '0.0.0.0', 0 @results.each{ |r| socket.send_datagram "$SR #{@client.config.nick} #{r}|", [:address], [:port] } socket.close_connection_after_writing else @results.each{ |r| 'SR', "#{@client.config.nick} #{r}\005#{[:searcher]}" } end when :revconnect if @client.config.passive 'RevConnectToMe', "#{@client.config.nick} #{[:who]}" else 'ConnectToMe', "#{[:who]} #{@client.config.address}:#{@client.config.active_port}" end # proxy this message on up the stack if we don't handle it else super end end |