Class: Callsigns::TCP
- Inherits:
-
Object
- Object
- Callsigns::TCP
- Defined in:
- lib/callsigns/tcp.rb
Class Method Summary collapse
- .goodbye(client) ⇒ Object
- .greet(client) ⇒ Object
- .help(client) ⇒ Object
- .main(port) ⇒ Object
- .menu(client) ⇒ Object
Class Method Details
.goodbye(client) ⇒ Object
26 27 28 |
# File 'lib/callsigns/tcp.rb', line 26 def self.goodbye(client) client.puts "Thanks for using Callsigns by AL0Y. 73 de AL0Y\n\n" end |
.greet(client) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/callsigns/tcp.rb', line 5 def self.greet(client) client.puts "\n\nWelcome to [Callsigns by AL0Y]" client.puts "This is an interactive server to search information of ham radio operators" client.puts "by their callsign [only USA-based], DMR ID or NXDN ID" help(client) end |
.help(client) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/callsigns/tcp.rb', line 13 def self.help(client) client.puts "\n\nAvilable commands:\n" client.puts " Lookup [callsign] - Gives information about the given callsign" client.puts " As of now, the callsign must be USA-Based." client.puts " DMR [number] - Gives information about a DMR ID\n " client.puts " NXDN [number] - Gives information about a NXDN ID" client.puts " HELP or ? - Shows this command list" client.puts " Version - Shows the current version for this server" client.puts " Bye - Disconnect from the Callsigns server and" client.puts " return to node." end |
.main(port) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/callsigns/tcp.rb', line 66 def self.main(port) server = TCPServer.new port.to_i loop do Thread.start(server.accept) do |client| greet(client) (client) client.close end end end |
.menu(client) ⇒ Object
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 |
# File 'lib/callsigns/tcp.rb', line 30 def self.(client) input = nil while input != "bye" client.puts "\nPlease enter a command, or type ? for a list of commands>" input = client.gets.chomp.downcase if input == "bye" goodbye(client) elsif input == "version" client.puts "Callsigns by AL0Y - Version:" + Callsigns::VERSION.to_s elsif input == "?" || input == "help" help(client) elsif input.split(" ").count == 2 && input.split(" ")[0] == "lookup" lookup_callsign = input.split(" ")[1] client.puts "Getting information for " + lookup_callsign.to_s + "\n..." Callsigns::Callook.lookup(lookup_callsign, client) elsif input.split(" ").count == 2 && input.split(" ")[0] == "dmr" dmr_id = input.split(" ")[1] client.puts "Getting information for " + dmr_id.to_s Callsigns::RadioID.dmr(dmr_id, client) elsif input.split(" ").count == 2 && input.split(" ")[0] == "nxdn" nxdn_id = input.split(" ")[1] client.puts "Getting information for " + nxdn_id.to_s Callsigns::RadioID.nxdn(nxdn_id, client) else client.puts "Unknown command!" end end end |