Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby1.9.1
- #Main.rb
- #Main portion of the Orchid::IRC module, contains the server's core as well as some base modules, however, any module defined here can be overridden in the
- #module API. This product is protected by use un the BSD terms of use Clase
- require 'socket'
- require 'resolv'
- require 'digest'
- load './lib/rehash.rb'
- $loads = ['numeric','privmsg','user','quit','channel','config','join','init','motd','server_notice','part','hash_changes', 'ping', 'names', 'who', 'unix_time', 'topic', 'nick', 'parse', 'new_client', 'load_mod', 'mode']
- $loads.push('resolv_host')
- $loads.each do |loadz|
- load './lib/' + loadz + '.rb'
- puts "Loaded module: #{'./lib/' + loadz + '.rb'}"
- end
- class IRC
- def initialize
- @config = config('./config/ircd.json')
- @s_conf = @config["server"]
- @u_conf = @config["user"]
- @c_conf = @config["channel"]
- @server = {:socket => TCPServer.open(@s_conf["port"]), :name => @s_conf["s_name"], :port => @s_conf["port"], :id => @s_conf["sid"], :net_name =>@s_conf["name"]}
- $server_name = @server[:name]
- @clients = [@server]
- @servers = []
- @modes = []
- @nicks = []
- @channels = []
- @modules = ['load_mod', 'nick', 'ping', 'privmsg', 'user', 'join', 'quit', 'mode', 'names', 'topic', 'who', 'part', 'rehash']
- @channel_names = []
- end
- def panic
- begin
- file = File.open('clients.log', 'a+')
- file.puts 'RAW HASH'
- file.puts @clients
- file.puts 'EOFS'
- l = []
- m = @clients
- m.each do |n|
- puts n
- unless n == @server
- $current = n
- l.push m[:socket].eof.to_s
- end
- end
- file.puts l
- file.close
- rescue Exception=>detail
- puts detail
- puts $current
- $problem = $current
- okie()
- end
- end
- def okie
- begin
- $problem[:socket].eof
- rescue Exception
- puts "this may fix teh problem ^._.^"
- end
- end
- def main_loop
- print 'Orchid> '
- loop do
- k = select(@clients + [$stdin], nil, nil, nil)
- unless k == nil
- k[0].each do |client|
- client[:idle] = unix_time unless client == $stdin
- if client == @server
- @clients.push(new_client(@server[:socket].accept))
- init(@clients.last)
- elsif client != $stdin
- if client[:socket].eof != true
- begin
- parse(client)
- rescue Exception => detail
- puts detail
- end
- else
- quit("SOCKET EOF", client)
- end
- else
- k=$stdin.gets.chomp
- begin
- case k
- when '.channels'
- p @channels
- when '.num_of_channels'
- puts @channels.length
- when '.clients'
- p @clients
- when '.num_of_clients'
- puts @clients.length
- when '.rehash'
- $loads.each do |loadz|
- load './lib/' + loadz + '.rb'
- puts "Loaded module: #{'./lib/' + loadz + '.rb'}"
- end
- when '.cmds'
- p ['.channels','.num_of_channels','.clients', '.num_of_clients', '.rehash']
- when /^\./
- puts "Unidentified command."
- else
- puts "=> #{eval(k)}"
- end
- print 'Orchid> '
- rescue Exception => detail
- puts detail.message()
- print detail.backtrace.join("\n")
- puts 'Error'
- end
- end
- end
- end
- end
- end
- def close
- @server[:socket].close
- end
- end
- k = IRC.new
- begin
- k.main_loop
- rescue Interrupt
- k.close
- puts ''
- puts 'Shutdown sucessful.'
- rescue Exception => detail
- k.panic
- puts detail.message()
- print detail.backtrace.join("\n")
- retry
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement