Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #======================================================================
- # |=| FiFO Main
- #======================================================================
- # Ruby IO Stream based server - includes clients and message handling
- # Features:
- # - SQL
- # - LOGGING
- # - Error Debugging
- # - Clients hashed
- #=====================================================================
- # AUTHOR: Xolitude
- # DATE : ---
- #=====================================================================
- # IMPORTS
- # Loads configuration file.
- load './cfg.ini'
- # Load Client File
- require "./Includes/Client_DFOnline.rb"
- require "socket"
- require './Includes/CustomHash.rb'
- require './Includes/switches.rb'
- # Load Extentions
- require "./Includes/DFUpdater.rb"
- # END OF IMPORTS
- class FFMain
- def initialize
- puts "========================"
- puts "ConvergenceDF Master alpha 1.1"
- puts "MasterServer(0.1a) - March 29th, 2013"
- puts "========================"
- puts "Credtis as Due:"
- puts "Xolitude - Writing the MasterServer"
- puts "Kono - Old NetVX Code"
- puts "========================"
- print "Press ENTER to start the MS"
- gets
- # Base Socket
- @server = TCPServer.new(HOST,PORT)
- puts "########################"
- puts ">>Server Successfuly Started [#{Time.now.to_s}]"
- puts ">>Long Live ~TheConvergenceProject~<<"
- puts "########################"
- @log = {}
- @log['error'] = "./df_log/FIFO[ERROR].txt"
- @log['socket'] = "./df_log/FIFO[SOCKET].txt"
- @log['messages'] = "./df_log/FIFO[MSGLOG].txt"
- def initialize
- if SQL_USE
- FFMain::Mysql
- @sql = Mysql.new(SQL_H,SQL_U,SQL_P,SQL_DB)
- end
- end
- $clients = {}
- loop do
- # Listening
- Thread.start(@server.accept) do |client|
- # Message Handling Loop...
- begin
- if $clients[client] == nil
- $clients[client] = eval(CLIENTCLASS)
- $clients[client].sock = client
- if SQL_USE
- $clients[client].sql = @sql
- end
- end
- while client.gets
- @MSG = $_
- handle(@MSG,client)
- end
- def initialize
- FFMain::remove
- $clients[client].remove
- $clients.delete(client)
- client.close if not client.closed?
- rescue Exception
- end
- begin
- $clients[client].remove
- client.close if not client.closed?
- $clients.delete(client) if $clients[client] != nil
- rescue Exception
- puts $!
- puts $!.backtrace.join("\n")
- end
- end
- end
- end
- end
- #-------------------------------------------
- # ** Handle
- # Handle Received Message
- #-------------------------------------------
- def handle(msg, client)
- begin
- $clients[client].handle($clients, msg)
- if DEBUG_MSG
- puts "FiFO: Message Received FROM #{client.peeraddr[2]}: #{msg}"
- file = File.open(@log['messages'], "a+")
- file.write("-----\r\nMessage Received\nTime: #{Time.now.to_s} \nMessage: #{msg}-----")
- file.close()
- end
- rescue Exception
- puts $!
- puts $!.backtrace.join("\n")
- end
- end
- def log_err(msg)
- trace = msg.backtrace.join("\n")
- file = File.open(@log['error'], "a+")
- file.write("-------------\r\nError Defined: #{msg}\r\nTRACING: #{trace}\r\nTYPE:'ERROR'\r\nDATE AND TIME:#{Time.now.to_s}\r\n-------------\r\n")
- file.close()
- end
- end
- # -------------------
- # Start the Server
- # -------------------
- FFMain.new
- #----------------------
- # End of File!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement