znmud-0.0.1/benchmark/
znmud-0.0.1/cmd/
znmud-0.0.1/cmd/emotes/
znmud-0.0.1/cmd/objects/
znmud-0.0.1/cmd/tiny/
znmud-0.0.1/doc/
znmud-0.0.1/farts/
znmud-0.0.1/lib/
znmud-0.0.1/lib/combat/
znmud-0.0.1/lib/core/bodytypes/
znmud-0.0.1/lib/engine/
znmud-0.0.1/lib/farts/
znmud-0.0.1/logs/
#
# file::    mccp2filter.rb
# Author::  Craig Smith
#
$:.unshift "lib" if !$:.include? "lib"
$:.unshift "vendor" if !$:.include? "vendor"

require 'zlib'
require 'network/protocol/filter'
require 'network/protocol/telnetcodes'

# The MCCP2 Filter - COMPRESS2 Implementation
# This needs to be the base filter (Telnet talks to this one)
#
class Mccp2Filter < Filter
  include TelnetCodes
  logger 'DEBUG'

  # The filter_out method filters output data
  # [+str+]    The string to be processed
  # [+return+] The filtered data
  def filter_out(str)
    return "" if str.nil? || str.empty?
    return str if not @pstack.terminal
    if @pstack.mccp2_on
	log.info "MCCP2 Compression Filter"
	@pstack.conn.sendmsg(IAC.chr + SB.chr + COMPRESS2.chr + IAC.chr + SE.chr)
	z = Zlib::Deflate.new(9)
	str = z.deflate(str, Zlib::FINISH)
	z.close
    end
    str
  end

end