$globalque = Queue.new

class RooServer < TServer # This is where all the client/server io is managed, the core control of our server.
  def process
    #n = Login.new
    #stage = n.promptfor("username")
    #connection.puts stage
    #puts Thread.current

    connection.each do |line| # line => Client Input
      stop if line =~ /shutdown/ # This is the place to insert server overrides. No where else is safe!
      break if line =~ /(quit|exit|close)/ # This is not a server override, where just breaking out of the connection thread.

      updateglobal = Thread.new do
        while $globalque.empty? == true
          sleep(0.1)
        end
        value = $globalque.pop
      end

      o = line.chomp.parsarg #chomping out hiddin characters from client.
      if o == nil
        connection.puts updateglobal.value
      else
        connection.puts o # Main server
      end 
    end
  end
end