diff --git a/utils/scripts/database_dumper.pl b/utils/scripts/database_dumper.pl deleted file mode 100644 index 51b16eabc..000000000 --- a/utils/scripts/database_dumper.pl +++ /dev/null @@ -1,252 +0,0 @@ -#!/usr/bin/perl - -############################################################ -#::: Script: db_dumper.pl -#::: Purpose: Utility to easily manage database backups and compress. -#::: Export Individual DB Tables... -#::: Export specific databases... -#::: Built for both Windows and Linux -#::: Windows uses WinRar or 7-Zip for compression -#::: Linux uses tar for compression -#::: Author: Akkadius -############################################################ - -$localdrive = "C:"; #::: Where Windows and all Install Programs are... -$linesep = "---------------------------------------"; - -use POSIX qw(strftime); -my $date = strftime "%m_%d_%Y", localtime; -print "\nTodays Date: " . $date . "\n"; - -use Config; -print "Operating System is: $Config{osname}\n"; -if($Config{osname}=~/linux/i){ $OS = "Linux"; } -if($Config{osname}=~/Win|MS/i){ $OS = "Windows"; } - -if(!$ARGV[0]){ - print "\nERROR! Need arguments\n"; - print "#::: Help :::#\n"; - print "######################################################\n"; - print "Arguments\n"; - print " loc=\"C:\\File Location\" - File path location to backup...\n"; - print " database=\"dbname\" - Manually specify databasename, default is database in eqemu_config.xml\n"; - print " tables=\"table1,table2,table3\" - Manually specify tables, default is to dump all tables from database\n"; - print " compress - Compress Database with 7-ZIP, will fallback to WinRAR depending on what is installed (Must be installed to default program dir)...\n"; - print " nolock - Does not lock tables, meant for backuping while the server is running..\n"; - print " backup_name=\"name\" - Sets database backup prefix name\n"; - print ' Example: perl DB_Dumper.pl Loc="E:\Backups"' . "\n"; - print "######################################################\n"; - exit; -} - -sub read_eqemu_config_json { - use JSON; - my $json = new JSON(); - - my $content; - open(my $fh, '<', "eqemu_config.json") or die "Unable to open config: eqemu_config.json - This must be in your EQEmu Server Folder\n"; { - local $/; - $content = <$fh>; - } - close($fh); - - $config = $json->decode($content); - - $db = $config->{"server"}{"database"}{"db"}; - $host = $config->{"server"}{"database"}{"host"}; - $user = $config->{"server"}{"database"}{"username"}; - $pass = $config->{"server"}{"database"}{"password"}; - $long_name = $config->{"server"}{"world"}{"longname"}; - -} - -read_eqemu_config_json(); - -$Debug = 0; -print "[db_dumper.pl] Arguments\n" if $Debug; -$n = 0; -while($ARGV[$n]){ - print $n . ': ' . $ARGV[$n] . "\n" if $Debug; - if($ARGV[$n]=~/nolock/i){ - $no_lock = 1; - } - if($ARGV[$n]=~/compress/i){ - print "[db_dumper.pl] Compression SET\n"; - $Compress = 1; - } - if($ARGV[$n]=~/database=/i){ - @DB_NAME = split('=', $ARGV[$n]); - print "[db_dumper.pl] Database is " . $DB_NAME[1] . "\n"; - $db = $DB_NAME[1]; - } - if($ARGV[$n]=~/backup_name=/i){ - @data = split('=', $ARGV[$n]); - print "[db_dumper.pl] Backup Name is " . $data[1] . "\n"; - $backup_name = $data[1]; - } - if($ARGV[$n]=~/loc=/i){ - @backup_location = split('=', $ARGV[$n]); - print "[db_dumper.pl] Backup Directory: " . $backup_location[1] . "\n"; - } - if($ARGV[$n]=~/tables=/i){ - @Tables = split('=', $ARGV[$n]); @TList = split(',', $Tables[1]); - foreach my $tables (@TList){ - $t_tables .= $tables . " "; - $t_tables_l .= $tables . "_"; - $t_tables_p .= $tables . "\n"; - } - print "[db_dumper.pl] Backing up tables: \n############################\n" . $t_tables_p . "############################\n"; - } - $n++; -} - -#::: Check for Backup Directory existence, if doesn't exist then create... -if (-d $backup_location[1]) { - print "[db_dumper.pl] Directory currently exists... Adding files to it...\n"; -} -elsif($backup_location[1] ne ""){ - print "[db_dumper.pl] Directory does NOT exist! Creating...\n"; - mkdir($backup_location[1]) or die 'Failed to create folder, maybe created the folder manually at "' . $backup_location[1]. '" ?'; -} -else{ - print "[db_dumper.pl] No save location specified... Saving to folder script is running in...\n"; -} -if($backup_location[1] ne ""){ - if($OS eq "Windows"){ $file_app = "\\"; } - if($OS eq "Linux"){ $file_app = "/"; } -} -else { - $file_app = ""; -} - -if($t_tables ne ""){ - $tables_f_l = substr($t_tables_l, 0, 20) . '-'; - if($backup_name){ - $target_file = $backup_name . '_' . $date . ''; - } - else { - $target_file = '' . $tables_f_l . '_' . $date . ''; - } - - print "[db_dumper.pl] Performing table based backup...\n"; - #::: Backup Database... - print "[db_dumper.pl] Backing up Database " . $db . "... \n"; - if($no_lock == 1){ - $added_parameters .= " --skip-lock-tables "; - } - $cmd = 'mysqldump -u' . $user . ' --host ' . $host . ' ' . $added_parameters . ' --max_allowed_packet=512M --password="' . $pass . '" ' . $db . ' ' . $t_tables . ' > "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql"'; - printcmd($cmd); - system($cmd); -} -else{ #::: Entire DB Backup - - if($backup_name){ - $target_file = $backup_name . '_' . $db . '_' . $date . ''; - } - else { - $target_file = '' . $db . '_' . $date . ''; - } - - #::: Backup Database... - print "[db_dumper.pl] Backing up Database " . $db . "... \n"; - if($no_lock == 1){ - $added_parameters .= " --skip-lock-tables "; - } - $cmd = 'mysqldump -u' . $user . ' --host ' . $host . ' ' . $added_parameters . ' --max_allowed_packet=512M --password="' . $pass . '" ' . $db . ' > "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql"'; - printcmd($cmd); - system($cmd); -} - -#::: Get File Size -$fileloc = '' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql'; -$filesize = -s $fileloc; -if($filesize < 1000){ print "[db_dumper.pl] " . 'Error occurred... exiting...' . "\n"; exit; } -print "[db_dumper.pl] Backup DONE... DB Backup File Size '" . $filesize . "' (" . get_filesize_str($fileloc) . ")\n"; - -#::: WinRar Get, check compression flag -if($Compress == 1){ - if($OS eq "Windows"){ - if(-d $localdrive . "\\Program Files\\7-Zip"){ - print "[db_dumper.pl] ::: You have 7-Zip installed as 64 Bit...\n"; - $S_ZIP = $localdrive . "\\Program Files\\7-Zip"; - } - elsif(-d $localdrive . "\\Program Files (x86)\\7-Zip"){ - print "[db_dumper.pl] ::: You have 7-Zip installed as 32 Bit...\n"; - $S_ZIP = $localdrive . "\\Program Files (x86)\\7-Zip"; - } - elsif(-d $localdrive . "\\Program Files (x86)\\WinRAR"){ - print "[db_dumper.pl] ::: You have WinRAR installed as 32 Bit...\n"; - $WinRar = $localdrive . "\\Program Files (x86)\\WinRAR"; - } - elsif(-d $localdrive . "\\Program Files\\WinRAR"){ - print "[db_dumper.pl] ::: You have WinRAR installed as 64 Bit...\n"; - $WinRar = $localdrive . "\\Program Files\\WinRAR"; - } - else{ - print "[db_dumper.pl] No WinRAR installed... Will not compress...\n"; - } - if($S_ZIP ne ""){ - print "[db_dumper.pl] Compressing Database with 7-ZIP... \n"; - $cmd = '"' . $S_ZIP . '\\7z" a -t7z -m0=lzma -mx=9 "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.7z" "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - print "[db_dumper.pl] \nDeleting RAW .sql Dump... \n"; - $cmd = 'del "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - $final_file = $target_file . ".7z"; - } - elsif($WinRar ne ""){ - print "[db_dumper.pl] Compressing Database with WinRAR... \n"; - $cmd = '"' . $WinRar . '\\rar" a "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.rar" "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - print "[db_dumper.pl] \nDeleting RAW .sql Dump... \n"; - $cmd = 'del "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - $final_file = $target_file . ".rar"; - } - } - if($OS eq "Linux"){ - print "[db_dumper.pl] Compressing Database with Tarball... \n"; - $cmd = 'tar -zcvf "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.tar.gz" "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - print "[db_dumper.pl] \nDeleting RAW .sql Dump... \n"; - $cmd = 'rm "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - $final_file = $target_file . ".tar.gz"; - } -} -else { - $final_file = $target_file . ".sql"; -} - -#::: Get Final File Location for display -if($backup_location[1] ne ""){ $final_loc = $backup_location[1] . '' . $file_app . ""; } -else{ - if($OS eq "Windows"){ - $final_loc = `echo %cd%`; - } - elsif($OS eq "Linux"){ - $final_loc = `pwd`; - } -} - -print "[db_dumper.pl] Final file located: " . $final_loc . "" . $final_file . "\n"; - -sub printcmd{ - print "[db_dumper.pl] Command [" . $_[0] . "]\n"; -} - -sub get_filesize_str{ - my $file = shift(); - my $size = (stat($file))[7] || die "stat($file): $!\n"; - if ($size > 1099511627776) { return sprintf("%.2f TiB", $size / 1099511627776); } - elsif ($size > 1073741824) { return sprintf("%.2f GiB", $size / 1073741824); } - elsif ($size > 1048576) { return sprintf("%.2f MiB", $size / 1048576); } - elsif ($size > 1024) { return sprintf("%.2f KiB", $size / 1024); } - else { return "$size byte" . ($size == 1 ? "" : "s"); } -} diff --git a/utils/scripts/db_dumper.pl b/utils/scripts/db_dumper.pl deleted file mode 100644 index af734124d..000000000 --- a/utils/scripts/db_dumper.pl +++ /dev/null @@ -1,246 +0,0 @@ -#!/usr/bin/perl - -############################################################ -#::: Script: db_dumper.pl -#::: Purpose: Utility to easily manage database backups and compress. -#::: Export Individual DB Tables... -#::: Export specific databases... -#::: Built for both Windows and Linux -#::: Windows uses WinRar or 7-Zip for compression -#::: Linux uses tar for compression -#::: Author: Akkadius -############################################################ - -$localdrive = "C:"; #::: Where Windows and all Install Programs are... -$linesep = "---------------------------------------"; - -use POSIX qw(strftime); -my $date = strftime "%m_%d_%Y", localtime; -print "\nTodays Date: " . $date . "\n"; - -use Config; -print "Operating System is: $Config{osname}\n"; -if($Config{osname}=~/linux/i){ $OS = "Linux"; } -if($Config{osname}=~/Win|MS/i){ $OS = "Windows"; } - -if(!$ARGV[0]){ - print "\nERROR! Need arguments\n"; - print "#::: Help :::#\n"; - print "######################################################\n"; - print "Arguments\n"; - print " loc=\"C:\\File Location\" - File path location to backup...\n"; - print " database=\"dbname\" - Manually specify databasename, default is database in eqemu_config.xml\n"; - print " tables=\"table1,table2,table3\" - Manually specify tables, default is to dump all tables from database\n"; - print " compress - Compress Database with 7-ZIP, will fallback to WinRAR depending on what is installed (Must be installed to default program dir)...\n"; - print " nolock - Does not lock tables, meant for backuping while the server is running..\n"; - print " backup_name=\"name\" - Sets database backup prefix name\n"; - print ' Example: perl DB_Dumper.pl Loc="E:\Backups"' . "\n"; - print "######################################################\n"; - exit; -} - -#::: CONFIG VARIABLES - Parsed from eqemu_config.xml - -my $confile = "eqemu_config.xml"; #default -open(F, "<$confile") or die "Unable to open config: $confile - This must be in your EQEmu Server Folder with your XML config\n"; -my $indb = 0; - -while() { - s/\r//g; - if(//i) { $indb = 1; } - next unless($indb == 1); - if(/<\/database>/i) { $indb = 0; last; } - if(/(.*)<\/host>/i) { $host = $1; } - elsif(/(.*)<\/username>/i) { $user = $1; } - elsif(/(.*)<\/password>/i) { $pass = $1; } - elsif(/(.*)<\/db>/i) { $db = $1; } -} - -$Debug = 0; -print "[db_dumper.pl] Arguments\n" if $Debug; -$n = 0; -while($ARGV[$n]){ - print $n . ': ' . $ARGV[$n] . "\n" if $Debug; - if($ARGV[$n]=~/nolock/i){ - $no_lock = 1; - } - if($ARGV[$n]=~/compress/i){ - print "[db_dumper.pl] Compression SET\n"; - $Compress = 1; - } - if($ARGV[$n]=~/database=/i){ - @DB_NAME = split('=', $ARGV[$n]); - print "[db_dumper.pl] Database is " . $DB_NAME[1] . "\n"; - $db = $DB_NAME[1]; - } - if($ARGV[$n]=~/backup_name=/i){ - @data = split('=', $ARGV[$n]); - print "[db_dumper.pl] Backup Name is " . $data[1] . "\n"; - $backup_name = $data[1]; - } - if($ARGV[$n]=~/loc=/i){ - @backup_location = split('=', $ARGV[$n]); - print "[db_dumper.pl] Backup Directory: " . $backup_location[1] . "\n"; - } - if($ARGV[$n]=~/tables=/i){ - @Tables = split('=', $ARGV[$n]); @TList = split(',', $Tables[1]); - foreach my $tables (@TList){ - $t_tables .= $tables . " "; - $t_tables_l .= $tables . "_"; - $t_tables_p .= $tables . "\n"; - } - print "[db_dumper.pl] Backing up tables: \n############################\n" . $t_tables_p . "############################\n"; - } - $n++; -} - -#::: Check for Backup Directory existence, if doesn't exist then create... -if (-d $backup_location[1]) { - print "[db_dumper.pl] Directory currently exists... Adding files to it...\n"; -} -elsif($backup_location[1] ne ""){ - print "[db_dumper.pl] Directory does NOT exist! Creating...\n"; - mkdir($backup_location[1]) or die 'Failed to create folder, maybe created the folder manually at "' . $backup_location[1]. '" ?'; -} -else{ - print "[db_dumper.pl] No save location specified... Saving to folder script is running in...\n"; -} -if($backup_location[1] ne ""){ - if($OS eq "Windows"){ $file_app = "\\"; } - if($OS eq "Linux"){ $file_app = "/"; } -} -else { - $file_app = ""; -} - -if($t_tables ne ""){ - $tables_f_l = substr($t_tables_l, 0, 20) . '-'; - if($backup_name){ - $target_file = $backup_name . '_' . $date . ''; - } - else { - $target_file = '' . $tables_f_l . '_' . $date . ''; - } - - print "[db_dumper.pl] Performing table based backup...\n"; - #::: Backup Database... - print "[db_dumper.pl] Backing up Database " . $db . "... \n"; - if($no_lock == 1){ - $added_parameters .= " --skip-lock-tables "; - } - $cmd = 'mysqldump -u' . $user . ' --host ' . $host . ' ' . $added_parameters . ' --max_allowed_packet=512M --password="' . $pass . '" ' . $db . ' ' . $t_tables . ' > "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql"'; - printcmd($cmd); - system($cmd); -} -else{ #::: Entire DB Backup - - if($backup_name){ - $target_file = $backup_name . '_' . $db . '_' . $date . ''; - } - else { - $target_file = '' . $db . '_' . $date . ''; - } - - #::: Backup Database... - print "[db_dumper.pl] Backing up Database " . $db . "... \n"; - if($no_lock == 1){ - $added_parameters .= " --skip-lock-tables "; - } - $cmd = 'mysqldump -u' . $user . ' --host ' . $host . ' ' . $added_parameters . ' --max_allowed_packet=512M --password="' . $pass . '" ' . $db . ' > "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql"'; - printcmd($cmd); - system($cmd); -} - -#::: Get File Size -$fileloc = '' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql'; -$filesize = -s $fileloc; -if($filesize < 1000){ print "[db_dumper.pl] " . 'Error occurred... exiting...' . "\n"; exit; } -print "[db_dumper.pl] Backup DONE... DB Backup File Size '" . $filesize . "' (" . get_filesize_str($fileloc) . ")\n"; - -#::: WinRar Get, check compression flag -if($Compress == 1){ - if($OS eq "Windows"){ - if(-d $localdrive . "\\Program Files\\7-Zip"){ - print "[db_dumper.pl] ::: You have 7-Zip installed as 64 Bit...\n"; - $S_ZIP = $localdrive . "\\Program Files\\7-Zip"; - } - elsif(-d $localdrive . "\\Program Files (x86)\\7-Zip"){ - print "[db_dumper.pl] ::: You have 7-Zip installed as 32 Bit...\n"; - $S_ZIP = $localdrive . "\\Program Files (x86)\\7-Zip"; - } - elsif(-d $localdrive . "\\Program Files (x86)\\WinRAR"){ - print "[db_dumper.pl] ::: You have WinRAR installed as 32 Bit...\n"; - $WinRar = $localdrive . "\\Program Files (x86)\\WinRAR"; - } - elsif(-d $localdrive . "\\Program Files\\WinRAR"){ - print "[db_dumper.pl] ::: You have WinRAR installed as 64 Bit...\n"; - $WinRar = $localdrive . "\\Program Files\\WinRAR"; - } - else{ - print "[db_dumper.pl] No WinRAR installed... Will not compress...\n"; - } - if($S_ZIP ne ""){ - print "[db_dumper.pl] Compressing Database with 7-ZIP... \n"; - $cmd = '"' . $S_ZIP . '\\7z" a -t7z -m0=lzma -mx=9 "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.7z" "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - print "[db_dumper.pl] \nDeleting RAW .sql Dump... \n"; - $cmd = 'del "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - $final_file = $target_file . ".7z"; - } - elsif($WinRar ne ""){ - print "[db_dumper.pl] Compressing Database with WinRAR... \n"; - $cmd = '"' . $WinRar . '\\rar" a "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.rar" "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - print "[db_dumper.pl] \nDeleting RAW .sql Dump... \n"; - $cmd = 'del "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - $final_file = $target_file . ".rar"; - } - } - if($OS eq "Linux"){ - print "[db_dumper.pl] Compressing Database with Tarball... \n"; - $cmd = 'tar -zcvf "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.tar.gz" "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - print "[db_dumper.pl] \nDeleting RAW .sql Dump... \n"; - $cmd = 'rm "' . $backup_location[1] . '' . $file_app . '' . $target_file . '.sql" '; - printcmd($cmd); - system($cmd); - $final_file = $target_file . ".tar.gz"; - } -} -else { - $final_file = $target_file . ".sql"; -} - -#::: Get Final File Location for display -if($backup_location[1] ne ""){ $final_loc = $backup_location[1] . '' . $file_app . ""; } -else{ - if($OS eq "Windows"){ - $final_loc = `echo %cd%`; - } - elsif($OS eq "Linux"){ - $final_loc = `pwd`; - } -} - -print "[db_dumper.pl] Final file located: " . $final_loc . "" . $final_file . "\n"; - -sub printcmd{ - print "[db_dumper.pl] Command [" . $_[0] . "]\n"; -} - -sub get_filesize_str{ - my $file = shift(); - my $size = (stat($file))[7] || die "stat($file): $!\n"; - if ($size > 1099511627776) { return sprintf("%.2f TiB", $size / 1099511627776); } - elsif ($size > 1073741824) { return sprintf("%.2f GiB", $size / 1073741824); } - elsif ($size > 1048576) { return sprintf("%.2f MiB", $size / 1048576); } - elsif ($size > 1024) { return sprintf("%.2f KiB", $size / 1024); } - else { return "$size byte" . ($size == 1 ? "" : "s"); } -} diff --git a/utils/scripts/eqemu_server.pl b/utils/scripts/eqemu_server.pl index 22e2f1de8..a366a07ad 100755 --- a/utils/scripts/eqemu_server.pl +++ b/utils/scripts/eqemu_server.pl @@ -255,7 +255,7 @@ sub show_install_summary_info sub new_server { $build_options = $_[0]; - $file_count = 0; + $file_count = 0; opendir(DIR, ".") or die $!; while (my $file = readdir(DIR)) { next if ($file =~ m/^\./); @@ -299,9 +299,9 @@ sub new_server open(MYSQL_CHECK, "mysqlcheck.txt"); while () { chomp; - $o = $_; - if ($o =~ /Error/i) {$mysql_pass = 0;} - if ($o =~ /SHOW PROCESSLIST/i) {$mysql_pass = 1;} + $o = $_; + if ($o =~ /Error/i) { $mysql_pass = 0; } + if ($o =~ /SHOW PROCESSLIST/i) { $mysql_pass = 1; } } close(MYSQL_CHECK); unlink("mysqlcheck.txt"); @@ -437,8 +437,8 @@ sub build_linux_source } my $eqemu_server_directory = "/home/eqemu"; # source between bots and not is the same, just different build results, so use the same source folder, different build folders - my $source_dir = $eqemu_server_directory . '/' . $last_directory . '_source'; - my $build_dir = $eqemu_server_directory . '/' . $last_directory . '_build' . $source_folder_post_fix; + my $source_dir = $eqemu_server_directory . '/' . $last_directory . '_source'; + my $build_dir = $eqemu_server_directory . '/' . $last_directory . '_build' . $source_folder_post_fix; $current_directory = trim($current_directory); @@ -522,20 +522,18 @@ sub do_installer_routines fetch_utility_scripts(); #::: Database Routines - $root_user = $user; + $root_user = $user; $root_password = $pass; print "[Database] Creating Database '" . $db_name . "'\n"; - if (defined($ENV{'MYSQL_ROOT_PASSWORD'})) - { + if (defined($ENV{'MYSQL_ROOT_PASSWORD'})) { # In the case that the user doesn't have privileges to create databases, support passing in the root password during setup print "[Database] Using 'root' for database management.\n"; - $root_user = "root"; + $root_user = "root"; $root_password = $ENV{'MYSQL_ROOT_PASSWORD'}; } print `"$path" --host $host --user $root_user --password="$root_password" -N -B -e "DROP DATABASE IF EXISTS $db_name;"`; print `"$path" --host $host --user $root_user --password="$root_password" -N -B -e "CREATE DATABASE $db_name"`; - if (defined($ENV{'MYSQL_ROOT_PASSWORD'})) - { + if (defined($ENV{'MYSQL_ROOT_PASSWORD'})) { # If we used root, make sure $user has permissions on db print "[Database] Assigning ALL PRIVILEGES to $user on $db_name.\n"; print `"$path" --host $host --user $root_user --password="$root_password" -N -B -e "GRANT ALL PRIVILEGES ON $db_name.* TO '$user.%'"`; @@ -647,7 +645,7 @@ sub check_for_world_bootup_database_update print "[Update] Database version is ahead of current binaries...\n"; } - if (!$db) {print "[eqemu_server.pl] No database connection found... Running without\n";} + if (!$db) { print "[eqemu_server.pl] No database connection found... Running without\n"; } show_menu_prompt(); } } @@ -682,7 +680,7 @@ sub check_for_world_bootup_database_update print "[Update] Bots database version is ahead of current binaries...\n"; } - if (!$db) {print "[eqemu_server.pl] No database connection found... Running without\n";} + if (!$db) { print "[eqemu_server.pl] No database connection found... Running without\n"; } show_menu_prompt(); } } @@ -726,7 +724,8 @@ sub get_perl_version no warnings; } -sub get_windows_wget { +sub get_windows_wget +{ if (!-e "bin/wget.exe" && $OS eq "Windows") { if (!-d "bin") { mkdir("bin"); @@ -764,7 +763,7 @@ sub do_self_update_check_routine my @files; my $start_dir = "updates_staged/"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -802,9 +801,9 @@ sub do_self_update_check_routine sub get_installation_variables { # Read installation variables from the ENV if set, but override them with install_variables.txt - if ($ENV{"MYSQL_HOST"}) { $installation_variables{"mysql_host"} = $ENV{"MYSQL_HOST"}; } - if ($ENV{"MYSQL_DATABASE"}) { $installation_variables{"mysql_eqemu_db_name"} = $ENV{"MYSQL_DATABASE"}; } - if ($ENV{"MYSQL_USER"}) { $installation_variables{"mysql_eqemu_user"} = $ENV{"MYSQL_USER"} } + if ($ENV{"MYSQL_HOST"}) { $installation_variables{"mysql_host"} = $ENV{"MYSQL_HOST"}; } + if ($ENV{"MYSQL_DATABASE"}) { $installation_variables{"mysql_eqemu_db_name"} = $ENV{"MYSQL_DATABASE"}; } + if ($ENV{"MYSQL_USER"}) { $installation_variables{"mysql_eqemu_user"} = $ENV{"MYSQL_USER"} } if ($ENV{"MYSQL_PASSWORD"}) { $installation_variables{"mysql_eqemu_password"} = $ENV{"MYSQL_PASSWORD"} } #::: Fetch installation variables before building the config @@ -840,9 +839,9 @@ sub do_install_config_json my $content; open(my $fh, '<', "eqemu_config_template.json") or die "cannot open file $filename"; { - local $/; - $content = <$fh>; - } + local $/; + $content = <$fh>; +} close($fh); $config = $json->decode($content); @@ -865,11 +864,11 @@ sub do_install_config_json $host = "127.0.0.1"; } - $config->{"server"}{"database"}{"host"} = $host; + $config->{"server"}{"database"}{"host"} = $host; $config->{"server"}{"database"}{"username"} = $installation_variables{"mysql_eqemu_user"}; $config->{"server"}{"database"}{"password"} = $installation_variables{"mysql_eqemu_password"}; $config->{"server"}{"database"}{"db"} = $db_name; - $config->{"server"}{"qsdatabase"}{"host"} = $host; + $config->{"server"}{"qsdatabase"}{"host"} = $host; $config->{"server"}{"qsdatabase"}{"username"} = $installation_variables{"mysql_eqemu_user"}; $config->{"server"}{"qsdatabase"}{"password"} = $installation_variables{"mysql_eqemu_password"}; $config->{"server"}{"qsdatabase"}{"db"} = $db_name; @@ -895,9 +894,9 @@ sub do_install_config_login_json my $content; open(my $fh, '<', "login_template.json") or die "cannot open file $filename"; { - local $/; - $content = <$fh>; - } + local $/; + $content = <$fh>; +} close($fh); $config = $json->decode($content); @@ -943,7 +942,7 @@ sub fetch_utility_scripts foreach my $file (@files) { my $full_file = "bin/" . $file; - if ($file=~/test|launch/i) { + if ($file =~ /test|launch/i) { next; } @@ -1248,97 +1247,55 @@ sub get_mysql_path } } -sub check_for_database_dump_script +sub get_world_path { - #::: Check for internet connection before updating - if (!$has_internet_connection) { - print "[Update] Cannot check update without internet connection...\n"; - return; + if (-e "world") { + return "world"; + } + elsif (-e "world.exe") { + return "world.exe"; + } + elsif (-e "bin/world") { + return "bin/world"; + } + elsif (-e "bin/world.exe") { + return "bin/world.exe"; + } +} + +sub get_world_command +{ + my $command = ""; + my $world_path = get_world_path(); + if ($OS eq "Windows") { + $command = "\"$world_path\""; + } + if ($OS eq "Linux") { + $command = "./$world_path"; } - #::: Check for script changes :: database_dumper.pl - get_remote_file($eqemu_repository_request_url . "utils/scripts/database_dumper.pl", - "updates_staged/database_dumper.pl", - 0, - 1, - 1); - - if (-e "updates_staged/database_dumper.pl") { - - my $remote_script_size = -s "updates_staged/database_dumper.pl"; - my $local_script_size = -s "database_dumper.pl"; - - if ($remote_script_size != $local_script_size) { - print "[Update] Script has been updated, updating...\n"; - - my @files; - my $start_dir = "updates_staged/"; - find( - sub {push @files, $File::Find::name unless -d;}, - $start_dir - ); - for my $file (@files) { - if ($file =~ /database_dumper/i) { - $destination_file = $file; - $destination_file =~ s/updates_staged\///g; - print "[Install] Installing [" . $destination_file . "]\n"; - unlink($destination_file); - copy_file($file, $destination_file); - if ($OS eq "Linux") { - system("chmod 755 database_dumper.pl"); - } - } - } - print "[Install] Done\n"; - } - else { - print "[Update] No script update necessary...\n"; - } - - unlink("updates_staged/database_dumper.pl"); - } - - return; - + return $command; } sub database_dump { - check_for_database_dump_script(); print "[Database] Performing database backup....\n"; - print `perl database_dumper.pl database="$db" loc="backups"`; + my $command = get_world_command(); + print `$command database:dump --all`; } sub database_dump_player_tables { - check_for_database_dump_script(); print "[Database] Performing database backup of player tables....\n"; - get_remote_file($eqemu_repository_request_url . "utils/sql/character_table_list.txt", - "backups/character_table_list.txt"); - - $tables = ""; - open(FILE, "backups/character_table_list.txt"); - $i = 0; - while () { - chomp; - $o = $_; - $tables .= $o . ","; - } - $tables = substr($tables, 0, -1); - - print `perl database_dumper.pl database="$db" loc="backups" tables="$tables" backup_name="player_tables_export" nolock`; - - print "[Database] Press any key to continue...\n"; - - <>; #Read from STDIN - + my $command = get_world_command(); + print `$command database:dump --player-tables`; } sub database_dump_compress { - check_for_database_dump_script(); print "[Database] Performing database backup....\n"; - print `perl database_dumper.pl database="$db" loc="backups" compress`; + my $command = get_world_command(); + print `$command database:dump --all --compress`; } sub script_exit @@ -1364,8 +1321,8 @@ sub check_db_version_table sub get_mysql_result { my $run_query = $_[0]; - if (!$db) {return;} - if ($OS eq "Windows") {return `"$path" --host $host --user $user --password="$pass" $db -N -B -e "$run_query"`;} + if (!$db) { return; } + if ($OS eq "Windows") { return `"$path" --host $host --user $user --password="$pass" $db -N -B -e "$run_query"`; } if ($OS eq "Linux") { $run_query =~ s/`//g; return `$path --user="$user" --host $host --password="$pass" $db -N -B -e "$run_query"`; @@ -1505,9 +1462,9 @@ sub read_eqemu_config_json my $content; open(my $fh, '<', "eqemu_config.json") or die "cannot open file $filename"; { - local $/; - $content = <$fh>; - } + local $/; + $content = <$fh>; +} close($fh); $config = $json->decode($content); @@ -1642,7 +1599,7 @@ sub fetch_latest_windows_appveyor my @files; my $start_dir = "updates_staged/binaries"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -1669,7 +1626,7 @@ sub fetch_latest_windows_binaries my @files; my $start_dir = "updates_staged/binaries"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -1696,7 +1653,7 @@ sub fetch_latest_windows_appveyor_bots my @files; my $start_dir = "updates_staged/binaries"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -1895,7 +1852,7 @@ sub fetch_peq_db_full unzip('updates_staged/peq-latest.zip', 'updates_staged/peq_db/'); my $start_dir = "updates_staged/peq_db/peq-dump"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -1916,7 +1873,7 @@ sub map_files_fetch_bulk my @files; my $start_dir = "maps/EQEmuMaps-master/"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -1989,7 +1946,7 @@ sub quest_files_fetch my @files; my $start_dir = "updates_staged/projecteqquests-master/"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -2054,7 +2011,7 @@ sub lua_modules_fetch my @files; my $start_dir = "updates_staged/projecteqquests-master/lua_modules/"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -2116,7 +2073,7 @@ sub plugins_fetch my @files; my $start_dir = "updates_staged/projecteqquests-master/plugins/"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -2603,7 +2560,7 @@ sub fetch_missing_db_update sub print_match_debug { - if (!$debug) {return;} + if (!$debug) { return; } print " Match Type: '" . $match_type . "'\n"; print " Match Text: '" . $match_text . "'\n"; print " Query Check: '" . $query_check . "'\n"; @@ -2612,7 +2569,7 @@ sub print_match_debug sub print_break { - if (!$debug) {return;} + if (!$debug) { return; } print "\n==============================================\n"; } @@ -2652,13 +2609,13 @@ sub quest_heading_convert my @files; my $start_dir = "quests/."; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { #::: Skip non script files - if ($file !~ /lua|pl/i) {next;} + if ($file !~ /lua|pl/i) { next; } if ($file =~ /lua|pl/i) { $print_buffer = ""; @@ -2672,7 +2629,7 @@ sub quest_heading_convert $line = $_; #::: Loop through matches - foreach my $key (sort (keys %matches)) { + foreach my $key (sort(keys %matches)) { $argument_position = $matches{$key}[1]; $match = $matches{$key}[0]; @@ -2783,7 +2740,7 @@ sub quest_faction_convert my @files; my $start_dir = "quests/."; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) { @@ -2804,7 +2761,7 @@ sub quest_faction_convert $line = $_; #::: Loop through matches - foreach my $key (sort (keys %matches)) { + foreach my $key (sort(keys %matches)) { $argument_position = $matches{$key}[1]; $match = $matches{$key}[0]; @@ -2870,7 +2827,7 @@ sub fix_quest_factions my @files; my $start_dir = "quests/"; find( - sub {push @files, $File::Find::name unless -d;}, + sub { push @files, $File::Find::name unless -d; }, $start_dir ); for my $file (@files) {