Send requested config in download_config packet handler

This commit is contained in:
2020-09-12 10:47:42 -05:00
parent df0d0df223
commit 5d267746dc

View File

@@ -96,6 +96,11 @@ module TAC
# CONFIG is unknown # CONFIG is unknown
$window.push_state(TAC::Dialog::AlertDialog, title: "Invalid Config", message: "Remote config is not supported.") $window.push_state(TAC::Dialog::AlertDialog, title: "Invalid Config", message: "Remote config is not supported.")
end end
else
if data.is_a?(Hash) && data.dig(:config, :spec_version) == TAC::CONFIG_SPEC_VERSION
File.open("#{TAC::CONFIGS_PATH}/#{config_name}.json", "w") { |f| f.write json }
end
end end
rescue JSON::ParserError => e rescue JSON::ParserError => e
log.e(TAG, "JSON parsing error: #{e}") log.e(TAG, "JSON parsing error: #{e}")
@@ -103,23 +108,20 @@ module TAC
end end
def handle_download_config(packet) def handle_download_config(packet)
if @host_is_a_connection config_name = packet.body
json = JSON.dump($window.backend.config) log.i(TAG, config_name)
config = $window.backend.settings.config pkt = nil
$window.backend.tacnet.puts(PacketHandler.packet_upload_config(config, json)) if File.exist?("#{TAC::CONFIGS_PATH}/#{config_name}.json")
pkt = PacketHandler.packet_upload_config(config_name, Config.new(config_name).to_json)
else else
if $server.active_client && $server.active_client.connected? pkt = PacketHandler.packet_error("Remote config not found", "The requested config #{config_name} does not exist over here.")
settings = TAC::Settings.new end
if File.exist?("#{TAC::CONFIGS_PATH}/#{settings.config}.json") if @host_is_a_connection
json = File.read("#{TAC::CONFIGS_PATH}/#{settings.config}.json") $window.backend.tacnet.puts(pkt)
else
$server.active_client.puts(PacketHandler.packet_upload_config(settings.config, json)) $server.active_client.puts(pkt)
else
$server.active_client.puts(PacketHandler.packet_error("NO_SUCH_CONFIG", "No config named #{settings.config}"))
end
end
end end
end end