From ec6b74aa7fb518eb8314498f22087c087b8d3c95 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sun, 23 Jul 2017 02:03:52 -0500 Subject: [PATCH] Config XML to JSON conversion routines --- common/database_conversions.cpp | 10 -------- utils/scripts/eqemu_server.pl | 42 ++++++++++++++++++++++++++++++++- world/net.cpp | 23 ++++++++++++++++++ 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/common/database_conversions.cpp b/common/database_conversions.cpp index d5cdbdb25..f04e9a93b 100644 --- a/common/database_conversions.cpp +++ b/common/database_conversions.cpp @@ -472,16 +472,6 @@ bool Database::CheckDatabaseConversions() { CheckDatabaseConvertPPDeblob(); CheckDatabaseConvertCorpseDeblob(); - /* Fetch EQEmu Server script */ - if (!std::ifstream("eqemu_server.pl")){ - std::cout << "Pulling down automatic database upgrade script..." << std::endl; -#ifdef _WIN32 - system("perl -MLWP::UserAgent -e \"require LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $response = $ua->get('https://raw.githubusercontent.com/EQEmu/Server/master/utils/scripts/eqemu_server.pl'); if ($response->is_success){ open(FILE, '> eqemu_server.pl'); print FILE $response->decoded_content; close(FILE); }\""); -#else - system("wget --no-check-certificate -O eqemu_server.pl https://raw.githubusercontent.com/EQEmu/Server/master/utils/scripts/eqemu_server.pl"); -#endif - } - /* Run EQEmu Server script (Checks for database updates) */ system("perl eqemu_server.pl ran_from_world"); diff --git a/utils/scripts/eqemu_server.pl b/utils/scripts/eqemu_server.pl index 8ea8b34b4..0b9e793dc 100644 --- a/utils/scripts/eqemu_server.pl +++ b/utils/scripts/eqemu_server.pl @@ -15,7 +15,7 @@ use File::Copy qw(copy); use POSIX qw(strftime); use File::Path; use File::Find; -use Time::HiRes qw(usleep); +use Time::HiRes qw(usleep); #::: Variables $install_repository_request_url = "https://raw.githubusercontent.com/Akkadius/EQEmuInstall/master/"; @@ -49,6 +49,7 @@ if(-e "eqemu_server_skip_update.txt"){ #::: Check for script self update do_self_update_check_routine() if !$skip_self_update_check; +check_xml_to_json_conversion() if $ARGV[0] eq "convert_xml"; get_windows_wget(); get_perl_version(); read_eqemu_config_xml(); @@ -291,6 +292,45 @@ sub new_server { } } +sub check_xml_to_json_conversion { + if(-e "eqemu_config.xml" && !-e "eqemu_config.json") { + + if($OS eq "Windows"){ + get_remote_file("https://github.com/EQEmu/Server/blob/eqemu_config_json/utils/xmltojson/xmltojson-windows-x86.exe", "xmltojson.exe"); + print "Converting eqemu_config.xml to eqemu_config.json\n"; + print `xmltojson eqemu_config.xml`; + } + if($OS eq "Linux"){ + get_remote_file("https://github.com/EQEmu/Server/blob/eqemu_config_json/utils/xmltojson/xmltojson-linux-x86", "xmltojson"); + print "Converting eqemu_config.xml to eqemu_config.json\n"; + print `xmltojson eqemu_config.xml`; + } + + #::: Prettify and alpha order the config + use JSON; + my $json = new JSON(); + + my $content; + open(my $fh, '<', "eqemu_config.json") or die "cannot open file $filename"; { + local $/; + $content = <$fh>; + } + close($fh); + + $result = $json->decode($content); + $json->canonical(1); + + print $json->pretty->utf8->encode($result),"\n"; + + open(my $fh, '>', 'eqemu_config.json'); + print $fh $json->pretty->utf8->encode($result); + close $fh; + + exit; + } + +} + sub build_linux_source { $build_options = $_[0]; diff --git a/world/net.cpp b/world/net.cpp index 8488f35bb..2f58d28a5 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -103,12 +103,23 @@ EQEmuLogSys LogSys; WebInterfaceList web_interface; void CatchSignal(int sig_num); +void CheckForServerScript(bool force_download = false); int main(int argc, char** argv) { RegisterExecutablePlatform(ExePlatformWorld); LogSys.LoadLogSettingsDefaults(); set_exception_handler(); + /* Download EQEmu Server Maintenance Script if doesn't exist */ + CheckForServerScript(); + + /* If eqemu_config.json does not exist - create it from conversion... */ + if (!std::ifstream("eqemu_config.json")) { + CheckForServerScript(true); + /* Run EQEmu Server script (Checks for database updates) */ + system("perl eqemu_server.pl convert_xml"); + } + /* Database Version Check */ uint32 Database_Version = CURRENT_BINARY_DATABASE_VERSION; uint32 Bots_Database_Version = CURRENT_BINARY_BOTS_DATABASE_VERSION; @@ -577,3 +588,15 @@ void UpdateWindowTitle(char* iNewTitle) { SetConsoleTitle(tmp); #endif } + +void CheckForServerScript(bool force_download) { + /* Fetch EQEmu Server script */ + if (!std::ifstream("eqemu_server.pl") || force_download) { + std::cout << "Pulling down EQEmu Server Maintenance Script (eqemu_server.pl)..." << std::endl; +#ifdef _WIN32 + system("perl -MLWP::UserAgent -e \"require LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $response = $ua->get('https://raw.githubusercontent.com/EQEmu/Server/eqemu_config_json/utils/scripts/eqemu_server.pl'); if ($response->is_success){ open(FILE, '> eqemu_server.pl'); print FILE $response->decoded_content; close(FILE); }\""); +#else + system("wget --no-check-certificate -O eqemu_server.pl https://raw.githubusercontent.com/EQEmu/Server/eqemu_config_json/utils/scripts/eqemu_server.pl"); +#endif + } +} \ No newline at end of file