From 44414fa0e7ef07591d21a524fb021d652ecae043 Mon Sep 17 00:00:00 2001 From: Mahtra <93822896+MahtraDR@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:22:26 +1300 Subject: [PATCH 1/6] [scripts][dependency] Add some profiling to debug output and Settings.save Allows for easier testing of where holdups are during startup. Reduces start-up times from ~40 seconds to under 10 seconds. --- dependency.lic | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/dependency.lic b/dependency.lic index 14e70508d..003136d97 100644 --- a/dependency.lic +++ b/dependency.lic @@ -10,10 +10,10 @@ require 'ostruct' require 'digest/sha1' require 'monitor' -$DEPENDENCY_VERSION = '2.0.3' +$DEPENDENCY_VERSION = '2.0.4' $MIN_RUBY_VERSION = '3.2.2' DRINFOMON_IN_CORE_LICH ||= false -DRINFOMON_CORE_LICH_DEFINES ||= [] +DRINFOMON_CORE_LICH_DEFINES ||= Array.new no_pause_all no_kill_all @@ -33,7 +33,7 @@ end class ArgParser def parse_args(data, flex_args = false) raw_args = variable.first - baselist = variable.drop(1).dup || [] + baselist = variable.drop(1).dup || Array.new unless baselist.size == 1 && baselist.grep(/^help$|^\?$|^h$/).any? @@ -212,7 +212,7 @@ class ScriptManager UserVars.autostart_scripts ||= [] UserVars.autostart_scripts.uniq! UserVars.autostart_scripts = UserVars.autostart_scripts - ['dependency'] - Settings['autostart'] ||= [] + Settings['autostart'] ||= Array.new unless Settings['autostart'] == Settings['autostart'].uniq echo("Duplicate autostarts found.") @@ -343,6 +343,7 @@ class ScriptManager end def start_scripts(force = false) + start_time = Time.now @versions = nil repo_scripts.each { |(name, _)| get_script(name, force) } autostarts.each do |script| @@ -357,6 +358,9 @@ class ScriptManager break unless !Script.running.find_all { |s| s.name =~ /bootstrap/ }.empty? end end + finish_time = Time.now + run_time = finish_time - start_time + echo("Time spent in start_scripts is #{run_time}") if @debug end def download_script(filename, force = false) @@ -420,6 +424,7 @@ class ScriptManager end def check_base_files + start_time = Time.now verify_or_make_dir File.join(SCRIPT_DIR, 'profiles') profile_tree_url = get_status['tree'].find { |element| element['path'] == 'profiles' }['url'] make_request(profile_tree_url)['tree'] @@ -433,21 +438,31 @@ class ScriptManager File.open(File.join(SCRIPT_DIR, "profiles/#{setup_file['path']}"), 'w') { |file| file.print(Base64.decode64(blob['content'])) } Settings['base_versions'][setup_file['path']] = setup_file['sha'] end + Settings.save + finish_time = Time.now + run_time = finish_time - start_time + echo("Time spent in check_base_files is #{run_time}") if @debug end def check_data_files + start_time = Time.now verify_or_make_dir File.join(SCRIPT_DIR, 'data') profile_tree_url = get_status['tree'].find { |element| element['path'] == 'data' }['url'] make_request(profile_tree_url)['tree'] .select { |data| /^base.+yaml/ =~ data['path'] } # Reject files that exist, and have the same shasum as those on the repo. - .reject { |setup_file| File.exist?("data/#{setup_file['path']}") && setup_file['sha'] == Settings['base_versions'][setup_file['path']] } + .reject { |setup_file| File.exist?("data/#{setup_file['path']}") } + .reject { |setup_file| setup_file['sha'] == Settings['base_versions'][setup_file['path']] } .each do |setup_file| echo("downloading #{setup_file}") if @debug blob = make_request(setup_file['url']) File.open(File.join(SCRIPT_DIR, "data/#{setup_file['path']}"), 'w') { |file| file.print(Base64.decode64(blob['content'])) } Settings['base_versions'][setup_file['path']] = setup_file['sha'] end + Settings.save + finish_time = Time.now + run_time = finish_time - start_time + echo("Time spent in check_data_files is #{run_time}") if @debug end def run_script(filename) @@ -476,10 +491,15 @@ class ScriptManager end def get_status - return @status if @status && Time.now - @status_time <= 30 # prevent flooding + if Settings['status'] && Time.now - Settings['status_time'] <= 3600 + echo("Returning cached status response") if @debug + return Settings['status'] + end - @status_time = Time.now - @status = make_request(@status_url) + Settings['status_time'] = Time.now + Settings['status'] = make_request(@status_url) + Settings.save + return Settings['status'] end def make_request(raw_uri) @@ -1781,9 +1801,7 @@ unless DRINFOMON_IN_CORE_LICH custom_require.call('drinfomon') echo("DRinfomon ready.") -end - -if DRINFOMON_IN_CORE_LICH +else Lich::Util.issue_command("exp all 0", /^Circle: \d+/, /^Rested EXP Stored|type: AWAKEN|Unlock Rested Experience/, quiet: true, timeout: 1) Lich::Util.issue_command("info", /^Name/, /^ Date: Thu, 12 Dec 2024 15:05:55 +1300 Subject: [PATCH 2/6] Fixing paths. --- dependency.lic | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dependency.lic b/dependency.lic index 003136d97..6248800ea 100644 --- a/dependency.lic +++ b/dependency.lic @@ -431,7 +431,7 @@ class ScriptManager # Select only base.yaml and base-empty.yaml .select { |data| /^base(?:-empty)?\.yaml/ =~ data['path'] } # Reject files that exist, and have the same shasum as those on the repo. - .reject { |setup_file| File.exist?("profiles/#{setup_file['path']}") && setup_file['sha'] == Settings['base_versions'][setup_file['path']] } + .reject { |setup_file| File.exist?("#{SCRIPT_DIR}/profiles/#{setup_file['path']}") && setup_file['sha'] == Settings['base_versions'][setup_file['path']] } .each do |setup_file| echo("downloading #{setup_file}") if @debug blob = make_request(setup_file['url']) @@ -451,8 +451,7 @@ class ScriptManager make_request(profile_tree_url)['tree'] .select { |data| /^base.+yaml/ =~ data['path'] } # Reject files that exist, and have the same shasum as those on the repo. - .reject { |setup_file| File.exist?("data/#{setup_file['path']}") } - .reject { |setup_file| setup_file['sha'] == Settings['base_versions'][setup_file['path']] } + .reject { |setup_file| echo(File.exist?("#{SCRIPT_DIR}/data/#{setup_file['path']}")) && setup_file['sha'] == Settings['base_versions'][setup_file['path']] } .each do |setup_file| echo("downloading #{setup_file}") if @debug blob = make_request(setup_file['url']) From 46153e6164176197f33b9a8adc0e8012f272e384 Mon Sep 17 00:00:00 2001 From: Mahtra <93822896+MahtraDR@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:10:22 +1300 Subject: [PATCH 3/6] Fixing typo --- dependency.lic | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependency.lic b/dependency.lic index 6248800ea..457c28fe5 100644 --- a/dependency.lic +++ b/dependency.lic @@ -431,7 +431,7 @@ class ScriptManager # Select only base.yaml and base-empty.yaml .select { |data| /^base(?:-empty)?\.yaml/ =~ data['path'] } # Reject files that exist, and have the same shasum as those on the repo. - .reject { |setup_file| File.exist?("#{SCRIPT_DIR}/profiles/#{setup_file['path']}") && setup_file['sha'] == Settings['base_versions'][setup_file['path']] } + .reject { |setup_file| File.exist?(File.join(SCRIPT_DIR, 'profiles', setup_file['path'])) && setup_file['sha'] == Settings['base_versions'][setup_file['path']] } .each do |setup_file| echo("downloading #{setup_file}") if @debug blob = make_request(setup_file['url']) @@ -451,7 +451,7 @@ class ScriptManager make_request(profile_tree_url)['tree'] .select { |data| /^base.+yaml/ =~ data['path'] } # Reject files that exist, and have the same shasum as those on the repo. - .reject { |setup_file| echo(File.exist?("#{SCRIPT_DIR}/data/#{setup_file['path']}")) && setup_file['sha'] == Settings['base_versions'][setup_file['path']] } + .reject { |setup_file| File.exist?(File.join(SCRIPT_DIR, 'data', setup_file['path'])) && setup_file['sha'] == Settings['base_versions'][setup_file['path']] } .each do |setup_file| echo("downloading #{setup_file}") if @debug blob = make_request(setup_file['url']) From 020caab60510511dd44cc1252725d89deb16389d Mon Sep 17 00:00:00 2001 From: Mahtra <93822896+MahtraDR@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:12:01 +1300 Subject: [PATCH 4/6] Rubocop --- dependency.lic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependency.lic b/dependency.lic index 457c28fe5..146aea6de 100644 --- a/dependency.lic +++ b/dependency.lic @@ -1800,7 +1800,7 @@ unless DRINFOMON_IN_CORE_LICH custom_require.call('drinfomon') echo("DRinfomon ready.") -else +else Lich::Util.issue_command("exp all 0", /^Circle: \d+/, /^Rested EXP Stored|type: AWAKEN|Unlock Rested Experience/, quiet: true, timeout: 1) Lich::Util.issue_command("info", /^Name/, /^ Date: Thu, 12 Dec 2024 15:53:16 +1300 Subject: [PATCH 5/6] rejig startup sequence --- dependency.lic | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dependency.lic b/dependency.lic index 146aea6de..170ef1c64 100644 --- a/dependency.lic +++ b/dependency.lic @@ -18,11 +18,24 @@ DRINFOMON_CORE_LICH_DEFINES ||= Array.new no_pause_all no_kill_all +unless XMLData.game =~ /^DR/ + echo("This script is not intended for usage with games other than Dragonrealms. Exiting now") + exit +end + while Script.running?('repository') echo("Repository is running, pausing for 10 seconds.") pause 10 end +unless Settings['dependency_version'] == $DEPENDENCY_VERSION + echo("New dependency version detected. Resetting repository auto-update settings.") + Script.start("repository", "reset-update-settings") + Script.start("repository", "unset-mapdb-updatable") unless XMLData.game == "DR" + Settings['dependency_version'] = $DEPENDENCY_VERSION + Settings.save +end + class Object # IMPORT FUTURE LAWLZ def itself @@ -189,10 +202,6 @@ class ScriptManager attr_reader :autostarts def initialize(debug) - unless XMLData.game =~ /^DR/ - echo("This script is not intended for usage with games other than Dragonrealms. Exiting now") - exit - end unless LICH_VERSION.match?(/^5/) _respond("*****************************************************************************") _respond("* Unsupported Lich versions detected. *") From fa227979def12d64a67f5c24de0b4cba0b033339 Mon Sep 17 00:00:00 2001 From: Mahtra <93822896+MahtraDR@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:00:25 +1300 Subject: [PATCH 6/6] adding cases for DRF and DRX --- dependency.lic | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dependency.lic b/dependency.lic index 170ef1c64..5296f6ace 100644 --- a/dependency.lic +++ b/dependency.lic @@ -31,7 +31,14 @@ end unless Settings['dependency_version'] == $DEPENDENCY_VERSION echo("New dependency version detected. Resetting repository auto-update settings.") Script.start("repository", "reset-update-settings") - Script.start("repository", "unset-mapdb-updatable") unless XMLData.game == "DR" + if XMLData.game == "DRX" || XMLData.game == "DRF" + if XMLData.game == "DRX" + echo("DR Plat instance detected. Setting map to not auto-update.") + elsif XMLData.game == "DRF" + echo("DR Fallen instance detected. Setting map to not auto-update.") + end + Script.start("repository", "unset-mapdb-updatable") + end Settings['dependency_version'] = $DEPENDENCY_VERSION Settings.save end