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::    mxpfilter.rb
# Author::  Craig Smith
#
$:.unshift "lib" if !$:.include? "lib"
$:.unshift "vendor" if !$:.include? "vendor"

require 'network/protocol/filter'
require 'network/protocol/mxpcodes'

# The MxpFilter class implements MXP Protocol
#
# A Filter can keep state and partial data
class MxpFilter < Filter
  include MXPCodes
  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?
    # Don't interfere with terminal negotiations.  So just pass data
    # if @pstack.terminal has not yet been determined
    return str if not @pstack.terminal
    if @pstack.mxp_on
	newstr = ""
	intag = false
	str.each_byte do |c|
       	 if intag
                if c == MXP_ENDc
                        intag = false
                        newstr << ">"
                else
                        newstr << c
                end
         else
                if c == MXP_BEGc
                        intag = true
                        newstr << "<"
                elsif c == AMPc # &
                        newstr << "&amp;"
                elsif c == LTc # <
                        newstr << "&lt;"
                elsif c == GTc # >
                        newstr << "&gt;"
                else
                        newstr << c
		end
	 end
	end
	str = newstr
    else
	newstr = ""
	intag = false
	inamp = false
	str.each_byte do |c|
       	 if intag
                if c == MXP_ENDc
                        intag = false
                end
	 elsif inamp
		if c == 59
			inamp = false
		end
         else
                if c == MXP_BEGc
                        intag = true
		elsif c == MXP_AMPc
			inamp = true
                else
                        newstr << c
		end
	 end
	end
	str = newstr
    end
    str
  end

end