Sha256: b622ffcd2800d36486251941443110667f529b7923fe1f3fc14fb653f49a4880

Contents?: true

Size: 836 Bytes

Versions: 16

Compression:

Stored size: 836 Bytes

Contents

module GameServer::Client
  include DaemonLogger::Mixins

  def receive_request(request)
    find_controller(request.name).new(self, request).run
  rescue Exception => e
    log_exception e
  end

  def send_line(string)
    log "send_line #{string}\n"
    send_data(string + "\n")
  end

  def send_json(object)
    send_line object.to_json
  end


  def receive_data(data)
    @data ||= ""
    @data += data
    if data =~ /\000\n$/
      all_data = @data
      @data = ""
      all_data.gsub!("\000",'').split(/\n/).each do |string|
        request = GameServer::RequestParser.new(string).parse
        receive_request(request)
      end
    end
  end

  def find_controller(name)
    "#{self.class.name}::#{name.to_s.camelize}Controller".constantize
  rescue NameError
    "#{self.class.name}::NilController".constantize
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
game-server-0.6.0 lib/client.rb
game-server-0.5.2 lib/client.rb
game-server-0.5.1 lib/client.rb
game-server-0.5.0 lib/client.rb
game-server-0.4.12 lib/client.rb
game-server-0.4.11 lib/client.rb
game-server-0.4.10 lib/client.rb
game-server-0.4.9 lib/client.rb
game-server-0.4.8 lib/client.rb
game-server-0.4.7 lib/client.rb
game-server-0.4.6 lib/client.rb
game-server-0.4.5 lib/client.rb
game-server-0.4.4 lib/client.rb
game-server-0.4.3 lib/client.rb
game-server-0.4.2 lib/client.rb
game-server-0.4.1 lib/client.rb