Skip to content

Commit

Permalink
Merge branch 'elanthia-online:staging' into drinfomon_core_lib
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtraDR authored Oct 28, 2024
2 parents 153685f + 1d057a7 commit 5e8ee14
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
55 changes: 34 additions & 21 deletions lib/xmlparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class XMLParser
attr_reader :mana, :max_mana, :health, :max_health, :spirit, :max_spirit, :last_spirit,
:stamina, :max_stamina, :stance_text, :stance_value, :mind_text, :mind_value,
:prepared_spell, :encumbrance_text, :encumbrance_full_text, :encumbrance_value,
:indicator, :injuries, :injury_mode, :room_count, :room_title, :room_description,
:indicator, :injuries, :injury_mode, :room_count, :room_name, :room_title, :room_description,
:room_exits, :room_exits_string, :familiar_room_title, :familiar_room_description,
:familiar_room_exits, :bounty_task, :server_time, :server_time_offset,
:roundtime_end, :cast_roundtime_end, :last_pulse, :level, :next_level_value,
Expand All @@ -47,7 +47,7 @@ class XMLParser

def initialize
@buffer = String.new
@unescape = { 'lt' => '<', 'gt' => '>', 'quot' => '"', 'apos' => "'", 'amp' => '&' }
# @unescape = { 'lt' => '<', 'gt' => '>', 'quot' => '"', 'apos' => "'", 'amp' => '&' }
@bold = false
@active_tags = Array.new
@active_ids = Array.new
Expand Down Expand Up @@ -86,6 +86,7 @@ def initialize

@room_count = 0
@room_title = String.new
@room_name = String.new
@room_description = String.new
@room_exits = Array.new
@room_exits_string = String.new
Expand Down Expand Up @@ -187,25 +188,25 @@ def make_scar_gsl
@scar_gsl = sprintf("0b0%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b%02b", @injuries['nsys']['scar'], @injuries['leftEye']['scar'], @injuries['rightEye']['scar'], @injuries['back']['scar'], @injuries['abdomen']['scar'], @injuries['chest']['scar'], @injuries['leftHand']['scar'], @injuries['rightHand']['scar'], @injuries['leftLeg']['scar'], @injuries['rightLeg']['scar'], @injuries['leftArm']['scar'], @injuries['rightArm']['scar'], @injuries['neck']['scar'], @injuries['head']['scar'])
end

def parse(line)
@buffer.concat(line)
loop {
if (str = @buffer.slice!(/^[^<]+/))
text(str.gsub(/&(lt|gt|quot|apos|amp)/) { @unescape[$1] })
elsif (str = @buffer.slice!(/^<\/[^<]+>/))
element = /^<\/([^\s>\/]+)/.match(str).captures.first
tag_end(element)
elsif (str = @buffer.slice!(/^<[^<]+>/))
element = /^<([^\s>\/]+)/.match(str).captures.first
attributes = Hash.new
str.scan(/([A-z][A-z0-9_\-]*)=(["'])(.*?)\2/).each { |attr| attributes[attr[0]] = attr[2] }
tag_start(element, attributes)
tag_end(element) if str =~ /\/>$/
else
break
end
}
end
# def parse(line)
# @buffer.concat(line)
# loop {
# if (str = @buffer.slice!(/^[^<]+/))
# text(str.gsub(/&(lt|gt|quot|apos|amp)/) { @unescape[$1] })
# elsif (str = @buffer.slice!(/^<\/[^<]+>/))
# element = /^<\/([^\s>\/]+)/.match(str).captures.first
# tag_end(element)
# elsif (str = @buffer.slice!(/^<[^<]+>/))
# element = /^<([^\s>\/]+)/.match(str).captures.first
# attributes = Hash.new
# str.scan(/([A-z][A-z0-9_\-]*)=(["'])(.*?)\2/).each { |attr| attributes[attr[0]] = attr[2] }
# tag_start(element, attributes)
# tag_end(element) if str =~ /\/>$/
# else
# break
# end
# }
# end

DECADE = 10 * 31_536_000

Expand All @@ -226,6 +227,8 @@ def parse_psm3_progressbar(kind, attributes)
PSM_3_DIALOG_IDS = ["Buffs", "Active Spells", "Debuffs", "Cooldowns"]

def tag_start(name, attributes)
# This is called once per element by REXML in games.rb
# https://ruby-doc.org/stdlib-2.6.1/libdoc/rexml/rdoc/REXML/StreamListener.html
begin
@active_tags.push(name)
@active_ids.push(attributes['id'].to_s)
Expand Down Expand Up @@ -612,9 +615,16 @@ def tag_start(name, attributes)
end

def text(text_string)
# This is called once per element with text in it by REXML in games.rb
# https://ruby-doc.org/stdlib-2.6.1/libdoc/rexml/rdoc/REXML/StreamListener.html
begin
# fixme: /<stream id="Spells">.*?<\/stream>/m
# $_CLIENT_.write(text_string) unless ($frontend != 'suks') or (@current_stream =~ /^(?:spellfront|inv|bounty|society)$/) or @active_tags.any? { |tag| tag =~ /^(?:compDef|inv|component|right|left|spell)$/ } or (@active_tags.include?('stream') and @active_ids.include?('Spells')) or (text_string == "\n" and (@last_tag =~ /^(?:popStream|prompt|compDef|dialogData|openDialog|switchQuickBar|component)$/))

if @current_style == 'roomName'
@room_name = text_string
end

if @active_tags.include?('inv')
if @active_tags[-1] == 'a'
@obj_name = text_string
Expand Down Expand Up @@ -775,6 +785,9 @@ def text(text_string)
end

def tag_end(name)
# This is called once per element by REXML in games.rb
# https://ruby-doc.org/stdlib-2.6.1/libdoc/rexml/rdoc/REXML/StreamListener.html

begin
if @game =~ /^DR/
if name == 'compass' and $nav_seen
Expand Down
20 changes: 13 additions & 7 deletions lich.rbw
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,23 @@ for arg in ARGV
end
end

require 'time'
require 'socket'
require 'base64'
require 'digest/md5'
require 'digest/sha1'
require 'drb/drb'
require 'json'
require 'monitor'
require 'net/http'
require 'ostruct'
require 'resolv'
require 'rexml/document'
require 'rexml/streamlistener'
require 'socket'
require 'stringio'
require 'zlib'
require 'drb/drb'
require 'resolv'
require 'digest/md5'
require 'json'
require 'terminal-table'
require 'time'
require 'yaml'
require 'zlib'

# TODO: Move all local requires to top of file
if defined? LIB_DIR
Expand Down

0 comments on commit 5e8ee14

Please sign in to comment.