Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby -w
- # encoding: utf-8
- require 'socket'
- require 'cinch' # Why reinvent the wheel, y'know?
- require 'json' # We need clean, easy to parse information. Apparently XML is shitty.
- require 'sqlite3' # We're gonna use a database handler for database handling. Ahurr.
- $db = SQLite3::Database.new("etc.db") # Global so we can get at it from anywhere, obviously.
- $irc = "etc" # Global variable to push the irc data through to the udpserv so it can format and pass it along.
- class IRCRelay
- def udpserv # Create the server to recieve input from modules.
- udps = UDPSocket.new
- udps.bind(nil, 1134)
- $modarray = Array.new
- loop do
- data, addr = udps.recvfrom(4096)
- $sender = addr[2] # Who sent the information? Global so we can pass this around.
- print "[#{$sender}] #{data}" # Data recieved should be JSON formatted.
- begin
- pdata = JSON.parse(data) # Check for a module 'sign in.'
- rescue
- print "[!] Invalid JSON string recieved from #{$sender}"
- udpsend("[!] Invalid JSON string detected! Dropped.", $sender, '1134')
- end
- #if pdata['connect'] =~ /MOD-TUNEIN/ # Do they want parsed data? Are they in the allowed list?
- #begin
- if pdata.key?("connect")
- $modarray = $db.execute("SELECT name FROM modules")
- print "\nDB.EXEC IS: #{$db.execute("SELECT name FROM modules")}\n\n"
- print "MODARRAY IS: #{$modarray}\n\n"
- print "PDATA IS: #{pdata['connect']['name']}\n\n"
- $modarray.each do |el|
- puts el
- if el.include? pdata['connect']['name']
- print "[!] Module already connected!"
- end
- if !el.include? pdata['connect']['name']
- print "[!] Activating module!"
- $db.execute("INSERT INTO modules (name,dev,desc) values ('#{pdata['connect']['name']}','#{pdata['connect']['dev']}','#{pdata['connect']['desc']}');")
- end
- end
- end
- #rescue
- #print "[!] Error in db.execute!"
- #end
- #if pdata.key?("tuneout") # Mark active mods that don't use the broadcast.
- # File.open('tunedout.log', 'a') do |mods|
- # mods.write("#{sender}")
- # end
- #end
- #File.open('recv.log', 'a') do |log|
- # log.write(data)
- #end
- #if data =~ /DBG-TUNERS/ # Debug command. Show the tuners array.
- # tunedmods.each { |i| print i, "\n" }
- #end
- end
- end
- def udpsend(string,target,port)
- udps = UDPSocket.new
- udps.send(string, 0, target, port)
- end
- def ircinch
- # Connect to IRC. Read and parse. Cinch is fucking ace for this shit.
- bot = Cinch::Bot.new do
- configure do |c|
- c.server = "irc.rizon.net"
- c.channels = ["#orange"]
- c.nick = "dxe"
- end
- #on :message do |m|
- on :message, ".info" do |m|
- m.reply "\\\\ IRC Relay バージョン 0.1a\n"
- m.reply "\\\\ greyEAXでプログラムされた\n"
- m.reply "\\\\ 現在実行中のモジュール: #{$modarray}\n"
- end
- end
- bot.start
- end
- puts "Starting at #{Time.now}"
- t1 = Thread.new{IRCRelay::udpserv.new()}
- t2 = Thread.new{IRCRelay::ircinch.new()}
- t1.join
- t2.join
- puts "End at #{Time.now}"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement