Advertisement
Guest User

DFO-Master

a guest
Apr 1st, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. #======================================================================
  2. # |=| FiFO Main
  3. #======================================================================
  4. # Ruby IO Stream based server - includes clients and message handling
  5. # Features:
  6. # - SQL
  7. # - LOGGING
  8. # - Error Debugging
  9. # - Clients hashed
  10. #=====================================================================
  11. # AUTHOR: Xolitude
  12. # DATE : ---
  13. #=====================================================================
  14. # IMPORTS
  15. # Loads configuration file.
  16. load './cfg.ini'
  17. # Load Client File
  18. require "./Includes/Client_DFOnline.rb"
  19. require "socket"
  20. require './Includes/CustomHash.rb'
  21. require './Includes/switches.rb'
  22. # Load Extentions
  23. require "./Includes/DFUpdater.rb"
  24. # END OF IMPORTS
  25.  
  26. class FFMain
  27.  
  28. def initialize
  29. puts "========================"
  30. puts "ConvergenceDF Master alpha 1.1"
  31. puts "MasterServer(0.1a) - March 29th, 2013"
  32. puts "========================"
  33. puts "Credtis as Due:"
  34. puts "Xolitude - Writing the MasterServer"
  35. puts "Kono - Old NetVX Code"
  36. puts "========================"
  37. print "Press ENTER to start the MS"
  38. gets
  39. # Base Socket
  40. @server = TCPServer.new(HOST,PORT)
  41. puts "########################"
  42. puts ">>Server Successfuly Started [#{Time.now.to_s}]"
  43. puts ">>Long Live ~TheConvergenceProject~<<"
  44. puts "########################"
  45. @log = {}
  46. @log['error'] = "./df_log/FIFO[ERROR].txt"
  47. @log['socket'] = "./df_log/FIFO[SOCKET].txt"
  48. @log['messages'] = "./df_log/FIFO[MSGLOG].txt"
  49. def initialize
  50. if SQL_USE
  51. FFMain::Mysql
  52. @sql = Mysql.new(SQL_H,SQL_U,SQL_P,SQL_DB)
  53. end
  54. end
  55. $clients = {}
  56. loop do
  57. # Listening
  58. Thread.start(@server.accept) do |client|
  59. # Message Handling Loop...
  60. begin
  61. if $clients[client] == nil
  62. $clients[client] = eval(CLIENTCLASS)
  63. $clients[client].sock = client
  64. if SQL_USE
  65. $clients[client].sql = @sql
  66. end
  67. end
  68. while client.gets
  69. @MSG = $_
  70. handle(@MSG,client)
  71. end
  72. def initialize
  73. FFMain::remove
  74. $clients[client].remove
  75. $clients.delete(client)
  76. client.close if not client.closed?
  77. rescue Exception
  78. end
  79. begin
  80. $clients[client].remove
  81. client.close if not client.closed?
  82. $clients.delete(client) if $clients[client] != nil
  83. rescue Exception
  84. puts $!
  85. puts $!.backtrace.join("\n")
  86. end
  87. end
  88. end
  89. end
  90. end
  91.  
  92. #-------------------------------------------
  93. # ** Handle
  94. # Handle Received Message
  95. #-------------------------------------------
  96. def handle(msg, client)
  97. begin
  98. $clients[client].handle($clients, msg)
  99. if DEBUG_MSG
  100. puts "FiFO: Message Received FROM #{client.peeraddr[2]}: #{msg}"
  101. file = File.open(@log['messages'], "a+")
  102. file.write("-----\r\nMessage Received\nTime: #{Time.now.to_s} \nMessage: #{msg}-----")
  103. file.close()
  104. end
  105. rescue Exception
  106. puts $!
  107. puts $!.backtrace.join("\n")
  108. end
  109. end
  110.  
  111. def log_err(msg)
  112. trace = msg.backtrace.join("\n")
  113. file = File.open(@log['error'], "a+")
  114. file.write("-------------\r\nError Defined: #{msg}\r\nTRACING: #{trace}\r\nTYPE:'ERROR'\r\nDATE AND TIME:#{Time.now.to_s}\r\n-------------\r\n")
  115. file.close()
  116. end
  117.  
  118. end
  119. # -------------------
  120. # Start the Server
  121. # -------------------
  122. FFMain.new
  123. #----------------------
  124. # End of File!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement