Module: Lich::Gemstone::Infomon::XMLParser

Defined in:
documented/gemstone/infomon/xmlparser.rb

Overview

this module handles all of the logic for parsing game lines that infomon depends on This module handles all of the logic for parsing game lines that infomon depends on

Examples:

Parsing a game line

result = XMLParser.parse(line)

Defined Under Namespace

Modules: Pattern

Class Method Summary collapse

Class Method Details

.parse(line) ⇒ Symbol

Parses a game line and returns the appropriate status

Examples:

Parsing a line

status = XMLParser.parse("Some game line")

Parameters:

  • line (String)

    The game line to parse

Returns:

  • (Symbol)

    Returns :ok, :noop, or raises an error

Raises:

  • (StandardError)

    If an error occurs during parsing



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'documented/gemstone/infomon/xmlparser.rb', line 134

def self.parse(line)
  # O(1) vs O(N)
  return :noop unless line =~ Pattern::All

  begin
    case line
    # this detects for death messages in XML that are not matched with appropriate combat attributes above
    when Pattern::NpcDeathMessage
      match = Regexp.last_match
      if (npc = GameObj.npcs.find { |obj| obj.id == match[:npc_id] && obj.status !~ /\b(?:dead|gone)\b/ })
        npc.status = 'dead'
      end
      :ok
    when Pattern::Group_Short
      return :noop unless (match_data = Group::Observer.wants?(line))
      Group::Observer.consume(line.strip, match_data)
      :ok
    when Pattern::Also_Here_Arrival
      return :noop unless Lich::Claim::Lock.locked?
      line.scan(%r{<a exist=(?:'|")(?<id>.*?)(?:'|") noun=(?:'|")(?<noun>.*?)(?:'|")>(?<name>.*?)</a>}).each { |player_found| XMLData.arrival_pcs.push(player_found[1]) unless XMLData.arrival_pcs.include?(player_found[1]) }
      :ok
    when Pattern::StowListOutputStart
      StowList.reset
      :ok
    when Pattern::StowListContainer, Pattern::StowSetContainer1, Pattern::StowSetContainer2
      match = Regexp.last_match
      if GameObj[match[:id]]
        StowList.__send__("#{match[:type].downcase}=", GameObj[match[:id]])
      else
        StowList.__send__("#{match[:type].downcase}=", GameObj.new(match[:id], match[:noun], match[:name], (match[:before].nil? ? nil : match[:before].strip), (match[:after].nil? ? nil : match[:after].strip)))
      end
      StowList.checked = true if line =~ Pattern::StowListContainer
      :ok
    when Pattern::ReadyListOutputStart
      ReadyList.reset
      :ok
    when Pattern::ReadyListNormal, Pattern::ReadyListAmmo2, Pattern::ReadyListSheathsSet, Pattern::ReadyItemSet
      match = Regexp.last_match
      unless match[:id].nil?
        if GameObj[match[:id]]
          ReadyList.__send__("#{Lich::Util.normalize_name(match[:type].downcase)}=", GameObj[match[:id]])
        else
          ReadyList.__send__("#{Lich::Util.normalize_name(match[:type].downcase)}=", GameObj.new(match[:id], match[:noun], match[:name], (match[:before].nil? ? nil : match[:before].strip), (match[:after].nil? ? nil : match[:after].strip)))
        end
      end
      if match.named_captures.include?("store")
        ReadyList.__send__("store_#{Lich::Util.normalize_name(match[:type].downcase)}=", match[:store])
      end
      :ok
    when Pattern::ReadyListFinished
      ReadyList.checked = true
      :ok
    when Pattern::ReadyItemClear
      match = Regexp.last_match
      ReadyList.__send__("#{Lich::Util.normalize_name(match[:type].downcase)}=", nil)
      :ok
    when Pattern::ReadyStoreSet
      match = Regexp.last_match
      ReadyList.__send__("store_#{Lich::Util.normalize_name(match[:type].downcase)}=", match[:store])
      :ok
    when Pattern::StatusPrompt
      Infomon::Parser::State.set(Infomon::Parser::State::Ready) unless Infomon::Parser::State.get.eql?(Infomon::Parser::State::Ready)
      :ok
    else
      :noop
    end
  rescue StandardError
    respond "--- Lich: error: Infomon::XMLParser.parse: #{$!}"
    respond "--- Lich: error: line: #{line}"
    Lich.log "error: Infomon::XMLParser.parse: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
    Lich.log "error: line: #{line}\n\t"
  end
end