Removed whitespace & duplicate label in runserver.bat (#8385)

This commit is contained in:
Akkarinage 2024-05-28 14:48:58 +01:00 committed by GitHub
parent 924d1ddad7
commit 39644a980f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 350 additions and 353 deletions

View File

@ -32,8 +32,8 @@ sub GetArgs {
'target=s' => \$sTarget, #Target (wich files to run-cmd into) 'target=s' => \$sTarget, #Target (wich files to run-cmd into)
'leftover=i' => \$sLeftOverChk, #should we chk if all doc are linked to a src ? 'leftover=i' => \$sLeftOverChk, #should we chk if all doc are linked to a src ?
'help!' => \$sHelp, 'help!' => \$sHelp,
) or $sHelp=1; #display help if invalid option ) or $sHelp=1; #display help if invalid option
if( $sHelp ) { if( $sHelp ) {
print "Incorrect option specified, available options are:\n" print "Incorrect option specified, available options are:\n"
."\t --atcf filename => file (specify atcommand doc to use)\n" ."\t --atcf filename => file (specify atcommand doc to use)\n"
@ -96,7 +96,7 @@ sub Script_GetCmd {
my @aSct_src = ("../src/map/script.cpp","../src/custom/script_def.inc"); my @aSct_src = ("../src/map/script.cpp","../src/custom/script_def.inc");
my @aDef_sct = (); my @aDef_sct = ();
foreach my $sSct_srcf (@aSct_src){ foreach my $sSct_srcf (@aSct_src){
unless(open FILE_SRC, "<$sSct_srcf") { unless(open FILE_SRC, "<$sSct_srcf") {
print "Couldn't open file '$sSct_srcf'.\n"; print "Couldn't open file '$sSct_srcf'.\n";
next; next;
} }
@ -139,16 +139,16 @@ sub Script_Chk { my ($raDef_sct) = @_;
@line = split('\(',$line[0]); @line = split('\(',$line[0]);
@line = split('\<',$line[0]); @line = split('\<',$line[0]);
$line[0] =~ s/\(|\{|\*|\r|\s|\;|\)|\"|\,//g; #todo please harmonize command definition for easier parse $line[0] =~ s/\(|\{|\*|\r|\s|\;|\)|\"|\,//g; #todo please harmonize command definition for easier parse
next if($line[0] eq "Name" || $line[0] eq "" || $line[0] eq "function" next if($line[0] eq "Name" || $line[0] eq "" || $line[0] eq "function"
|| $line[0] eq "if" || $line[0] eq "while" || $line[0] eq "do" || $line[0] eq "for" ); #exception list || $line[0] eq "if" || $line[0] eq "while" || $line[0] eq "do" || $line[0] eq "for" ); #exception list
push(@aDoc_sct,$line[0]); push(@aDoc_sct,$line[0]);
} }
} }
close FILE_DOC; close FILE_DOC;
} }
$raMiss_sct = Chk($raDef_sct,\@aDoc_sct); #check missing documentation $raMiss_sct = Chk($raDef_sct,\@aDoc_sct); #check missing documentation
if(scalar(@$raMiss_sct)){ if(scalar(@$raMiss_sct)){
print "Missing script documentation for function :{\n"; print "Missing script documentation for function :{\n";
@ -158,7 +158,7 @@ sub Script_Chk { my ($raDef_sct) = @_;
print "}\n\n"; print "}\n\n";
} }
else { print "All script commands in src are documented, no issues found.\n"; } else { print "All script commands in src are documented, no issues found.\n"; }
if($sLeftOverChk){ if($sLeftOverChk){
my $raLeftover_sct = Chk(\@aDoc_sct,$raDef_sct); #we just inverse the chk for leftover my $raLeftover_sct = Chk(\@aDoc_sct,$raDef_sct); #we just inverse the chk for leftover
if(scalar(@$raLeftover_sct)){ if(scalar(@$raLeftover_sct)){
@ -185,7 +185,7 @@ sub Atc_GetCmd {
if($_ =~ /ACMD_DEF|ACMD_DEF2|ACMD_DEFR|ACMD_DEF2R/){ if($_ =~ /ACMD_DEF|ACMD_DEF2|ACMD_DEFR|ACMD_DEF2R/){
$_ =~ s/\s+$//; #Remove trailing spaces. $_ =~ s/\s+$//; #Remove trailing spaces.
$_ =~ s/^\s+//; #Remove leading spaces. $_ =~ s/^\s+//; #Remove leading spaces.
if($_ =~ /^ACMD_DEF2|^ACMD_DEF2R/){ if($_ =~ /^ACMD_DEF2|^ACMD_DEF2R/){
my @line = split('"',$_); my @line = split('"',$_);
push(@aDef_act,$line[1]); push(@aDef_act,$line[1]);
@ -207,7 +207,7 @@ sub Atc_Chk { my ($raDef_act) = @_;
my @aAct_docf = ($sAtcf,$sInc_atcf); my @aAct_docf = ($sAtcf,$sInc_atcf);
my @aDoc_act = (); my @aDoc_act = ();
my $raMiss_act; my $raMiss_act;
foreach my $sAct_docf (@aAct_docf){ foreach my $sAct_docf (@aAct_docf){
unless(open FILE_DOC, "$sAct_docf"){ unless(open FILE_DOC, "$sAct_docf"){
print "Couldn't open file '$sAct_docf'.\n"; print "Couldn't open file '$sAct_docf'.\n";
@ -226,7 +226,7 @@ sub Atc_Chk { my ($raDef_act) = @_;
} }
close FILE_DOC; close FILE_DOC;
} }
$raMiss_act = Chk($raDef_act,\@aDoc_act); #check missing documentation $raMiss_act = Chk($raDef_act,\@aDoc_act); #check missing documentation
if(scalar(@$raMiss_act)){ if(scalar(@$raMiss_act)){
print "Missing atcommand documentation for function :{\n"; print "Missing atcommand documentation for function :{\n";
@ -236,7 +236,7 @@ sub Atc_Chk { my ($raDef_act) = @_;
print "}\n\n"; print "}\n\n";
} }
else { print "All atcommands in src are documented, no issues found.\n"; } else { print "All atcommands in src are documented, no issues found.\n"; }
if($sLeftOverChk){ if($sLeftOverChk){
my $raLeftover_sct = Chk(\@aDoc_act,$raDef_act); #we just inverse the chk for leftover my $raLeftover_sct = Chk(\@aDoc_act,$raDef_act); #we just inverse the chk for leftover
if(scalar(@$raLeftover_sct)){ if(scalar(@$raLeftover_sct)){

View File

@ -16,30 +16,30 @@ use rA_Common;
use LWP::Simple; use LWP::Simple;
use constant { use constant {
SERV_UID => "Serv_userid", SERV_UID => "Serv_userid",
SERV_PW => "Serv_userpass", SERV_PW => "Serv_userpass",
LOGIN_PRIV_IP => "login_priv_ip", LOGIN_PRIV_IP => "login_priv_ip",
CHAR_PRIV_IP => "char_priv_ip", CHAR_PRIV_IP => "char_priv_ip",
SERV_WAN_IP => "Serv_wan_ip", SERV_WAN_IP => "Serv_wan_ip",
MAP_PORT => "Map_port", MAP_PORT => "Map_port",
CHAR_PORT => "Char_port", CHAR_PORT => "Char_port",
LOGIN_PORT => "Login_port", LOGIN_PORT => "Login_port",
MD5_ENABLE => "enable_MD5", MD5_ENABLE => "enable_MD5",
PINCODE_ENABLE => "enable_pincode", PINCODE_ENABLE => "enable_pincode",
SQL_HOST => "SQL_host", SQL_HOST => "SQL_host",
SQL_PORT => "SQL_port", SQL_PORT => "SQL_port",
SQL_UID => "SQL_userid", SQL_UID => "SQL_userid",
SQL_PW => "SQL_userpass", SQL_PW => "SQL_userpass",
SQL_MAIN_DB => "SQL_maindb", SQL_MAIN_DB => "SQL_maindb",
SQL_LOG_DB => ,"SQL_logdb", SQL_LOG_DB => ,"SQL_logdb",
MAP_CONF_FILE => "map_conf.txt", MAP_CONF_FILE => "map_conf.txt",
CHAR_CONF_FILE => "char_conf.txt", CHAR_CONF_FILE => "char_conf.txt",
LOGIN_CONF_FILE => "login_conf.txt", LOGIN_CONF_FILE => "login_conf.txt",
INTER_CONF_FILE => "inter_conf.txt", INTER_CONF_FILE => "inter_conf.txt",
DESD_CONF_FILE => ".tmp-desd_conf.yml", DESD_CONF_FILE => ".tmp-desd_conf.yml",
MIN_PORT => 2000, #below are usually reserved for system MIN_PORT => 2000, #below are usually reserved for system
MAX_PORT => 65535, MAX_PORT => 65535,
}; };
# setup default options # setup default options
my $sDsdFile = DESD_CONF_FILE; my $sDsdFile = DESD_CONF_FILE;
@ -53,46 +53,46 @@ GetArgs();
Main(); Main();
sub GetArgs { sub GetArgs {
GetOptions( GetOptions(
'f=s' => \$sDsdFile, #give desired conf file 'f=s' => \$sDsdFile, #give desired conf file
'auto=i' => \$sAutoyes, #Force (auto-yes) 'auto=i' => \$sAutoyes, #Force (auto-yes)
'C=i' => \$sClean, #Clean (like force but remove before adding) 'C=i' => \$sClean, #Clean (like force but remove before adding)
'target=s' => \$sTarget, #Target (which setup to run) 'target=s' => \$sTarget, #Target (which setup to run)
'Force=i' => \$sForce, #Force (bypass verification) 'Force=i' => \$sForce, #Force (bypass verification)
'OS=s' => \$sOS, #OS (specify the OS you wish to use) 'OS=s' => \$sOS, #OS (specify the OS you wish to use)
'help!' => \$sHelp, 'help!' => \$sHelp,
) or $sHelp=1; #display help if invalid option ) or $sHelp=1; #display help if invalid option
my $sValidTarget = "All|Conf|DB|Inst|Dump"; my $sValidTarget = "All|Conf|DB|Inst|Dump";
if( $sHelp ) { if( $sHelp ) {
print "Incorrect option specified. Available options are:\n" print "Incorrect option specified. Available options are:\n"
."\t --f filename => file (specify desiredconf to use)\n" ."\t --f filename => file (specify desiredconf to use)\n"
."\t --auto => auto-yes to question? \n" ."\t --auto => auto-yes to question? \n"
."\t --C => Clean (remove file, db, user before adding new)\n" ."\t --C => Clean (remove file, db, user before adding new)\n"
."\t --target => target (specify which setup to run [$sValidTarget])\n" ."\t --target => target (specify which setup to run [$sValidTarget])\n"
."\t --Force => Force (bypass verification)\n" ."\t --Force => Force (bypass verification)\n"
."\t --OS => (specify the OS you wish to use and avoid check)"; ."\t --OS => (specify the OS you wish to use and avoid check)";
exit; exit;
} }
unless($sTarget =~ /$sValidTarget/i){ unless($sTarget =~ /$sValidTarget/i){
print "Incorrect target specified. Available targets are:\n" print "Incorrect target specified. Available targets are:\n"
."\t --target => target (specify which setup to run [(default)$sValidTarget])\n"; ."\t --target => target (specify which setup to run [(default)$sValidTarget])\n";
exit; exit;
} }
if($sDsdFile ne DESD_CONF_FILE && !(-e -r $sDsdFile)){ if($sDsdFile ne DESD_CONF_FILE && !(-e -r $sDsdFile)){
print "File '$sDsdFile' could not be read or does not exist.\n"; print "File '$sDsdFile' could not be read or does not exist.\n";
exit; exit;
} }
} }
sub Main { sub Main {
my($filename, $dir, $suffix) = fileparse($0); my($filename, $dir, $suffix) = fileparse($0);
chdir $dir; #put ourself like was called in tools chdir $dir; #put ourself like was called in tools
print "Running rAthena's configuration tool...\n"; print "Running rAthena's configuration tool...\n";
#default conf #default conf
my $pubip = GetPublicIP(); my $pubip = GetPublicIP();
my %hDefConf = ( SERV_UID => "s1", my %hDefConf = ( SERV_UID => "s1",
SERV_PW => "p1", SERV_PW => "p1",
SERV_WAN_IP => $pubip || "localhost", SERV_WAN_IP => $pubip || "localhost",
LOGIN_PRIV_IP => "localhost", LOGIN_PRIV_IP => "localhost",
@ -109,7 +109,6 @@ sub Main {
SQL_MAIN_DB => "ragnarok", SQL_MAIN_DB => "ragnarok",
SQL_LOG_DB => ,"ragnarok", SQL_LOG_DB => ,"ragnarok",
); );
my $sBasedir = getcwd; #for setupdb my $sBasedir = getcwd; #for setupdb
if($sTarget =~ /All|Inst/i){ InstallSoft(); } if($sTarget =~ /All|Inst/i){ InstallSoft(); }
@ -121,7 +120,7 @@ sub Main {
} }
sub EnableCoredump { sub EnableCoredump {
print "\n== Enabling Coredumps ==\n"; print "\n== Enabling Coredumps ==\n";
my $sCurfile = "~/.bashrc"; my $sCurfile = "~/.bashrc";
my @lines = (); my @lines = ();
@ -130,7 +129,7 @@ sub EnableCoredump {
foreach(<PIPE>){ foreach(<PIPE>){
if($_ =~ /ulimit -c unlimited/){ if($_ =~ /ulimit -c unlimited/){
$sJump = 1; #already in here nothing to do $sJump = 1; #already in here nothing to do
last; last;
} }
push(@lines,$_) if /ulimit/; push(@lines,$_) if /ulimit/;
} }
@ -174,7 +173,7 @@ sub EnableCoredump {
."Are you sure you want to continue? [y/n] \n"; ."Are you sure you want to continue? [y/n] \n";
$sJump=2 if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i); $sJump=2 if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i);
} }
unless($sJump==2){ unless($sJump==2){
system('sudo su root -c "echo \"echo kernel.core_uses_pid = 1 >> /etc/sysctl.conf\" | sudo bash"'); system('sudo su root -c "echo \"echo kernel.core_uses_pid = 1 >> /etc/sysctl.conf\" | sudo bash"');
system('sudo su root -c "echo \"echo kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t >> /etc/sysctl.conf\" | sudo bash"'); system('sudo su root -c "echo \"echo kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t >> /etc/sysctl.conf\" | sudo bash"');
system('sudo su root -c "echo \"echo fs.suid_dumpable = 1 >> /etc/sysctl.conf\" | sudo bash"'); system('sudo su root -c "echo \"echo fs.suid_dumpable = 1 >> /etc/sysctl.conf\" | sudo bash"');
@ -203,7 +202,7 @@ sub GetOS {
} }
else { else {
my @aSupportedOS = ("Debian","Ubuntu","Fedora","CentOs","FreeBSD"); my @aSupportedOS = ("Debian","Ubuntu","Fedora","CentOs","FreeBSD");
my $sOSregex = join("|",@aSupportedOS); my $sOSregex = join("|",@aSupportedOS);
until($sOS =~ /$sOSregex/i){ until($sOS =~ /$sOSregex/i){
print "Please enter your OS [$sOSregex] or enter 'quit' to exit.\n"; print "Please enter your OS [$sOSregex] or enter 'quit' to exit.\n";
$sOS = <>; chomp($sOS); $sOS = <>; chomp($sOS);
@ -214,11 +213,11 @@ sub GetOS {
} }
sub InstallSoft { sub InstallSoft {
print "\n== Installing Software ==\n"; print "\n== Installing Software ==\n";
print "NOTE: This auto-install feature is experimental. Package names vary in different distributions and versions, so they may be incorrect.\n"; print "NOTE: This auto-install feature is experimental. Package names vary in different distributions and versions, so they may be incorrect.\n";
$sOS = GetOS() unless $sOS; $sOS = GetOS() unless $sOS;
if($sOS eq "quit"){ print "Skipping software installation...\n"; return; } if($sOS eq "quit"){ print "Skipping software installation...\n"; return; }
elsif($sOS =~ /Ubuntu|Debian/i) { #tested on ubuntu 12.10,13.10 elsif($sOS =~ /Ubuntu|Debian/i) { #tested on ubuntu 12.10,13.10
my @aListSoft = ("gcc","gdb","zlibc","zlib1g-dev","make","git","mysql-client","mysql-server","mysql-common","libmysqlclient-dev","phpmyadmin","libpcre3-dev"); my @aListSoft = ("gcc","gdb","zlibc","zlib1g-dev","make","git","mysql-client","mysql-server","mysql-common","libmysqlclient-dev","phpmyadmin","libpcre3-dev");
print "Going to install: @aListSoft\n"; print "Going to install: @aListSoft\n";
system("sudo apt-get install @aListSoft"); system("sudo apt-get install @aListSoft");
@ -227,77 +226,77 @@ sub InstallSoft {
my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","git","mariadb-server","mariadb","mariadb-devel","phpmyadmin","pcre-devel"); my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","git","mariadb-server","mariadb","mariadb-devel","phpmyadmin","pcre-devel");
# my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","git","mysql-server","mysql-devel","phpmyadmin","pcre-devel"); # my @aListSoft = ("gcc","gdb","zlib","zlib-devel","make","git","mysql-server","mysql-devel","phpmyadmin","pcre-devel");
system("sudo yum install @aListSoft"); system("sudo yum install @aListSoft");
} }
elsif($sOS =~ /FreeBSD/i){ #tested on FreeBSD 9.01 elsif($sOS =~ /FreeBSD/i){ #tested on FreeBSD 9.01
system("portsnap fetch extract && portsnap update"); #fetch port lib and extract system("portsnap fetch extract && portsnap update"); #fetch port lib and extract
my @aDevel = ("binutils","git","autoconf","pcre","gmake","gdb"); my @aDevel = ("binutils","git","autoconf","pcre","gmake","gdb");
foreach(@aDevel){ foreach(@aDevel){
system("cd /usr/ports/devel/$_ && make install clean"); #install devels system("cd /usr/ports/devel/$_ && make install clean"); #install devels
} }
# system("cd /usr/ports/lang/gcc46 && make install"); #gcc4.6 use latest ? 4.8 ? # system("cd /usr/ports/lang/gcc46 && make install"); #gcc4.6 use latest ? 4.8 ?
system("cd /usr/ports/databases/mysql55-server && make install clean"); system("cd /usr/ports/databases/mysql55-server && make install clean");
#other utils ? #other utils ?
system("cd /usr/ports/www/wget && make install clean"); system("cd /usr/ports/www/wget && make install clean");
system("cd /usr/ports/archivers/unrar && make install clean"); system("cd /usr/ports/archivers/unrar && make install clean");
} }
} }
sub ConfigConf { my ($rhDefConf) = @_; sub ConfigConf { my ($rhDefConf) = @_;
print "\n== Setting Configurations ==\n"; print "\n== Setting Configurations ==\n";
my $rhUserConf; my $rhUserConf;
while(1) { while(1) {
$rhUserConf = GetDesiredConf($rhDefConf); $rhUserConf = GetDesiredConf($rhDefConf);
print "SetupConf using conf: \n"; print "SetupConf using conf: \n";
ShowConfig($rhUserConf); ShowConfig($rhUserConf);
last if($sForce || AutoCheckConf($rhUserConf)); last if($sForce || AutoCheckConf($rhUserConf));
} }
ApplySetupConf($rhUserConf); ApplySetupConf($rhUserConf);
} }
sub ConfigDB { my ($rhDefConf) = @_; sub ConfigDB { my ($rhDefConf) = @_;
print "\n== Setting Up Databases ==\n"; print "\n== Setting Up Databases ==\n";
my $rhUserConf; my $rhUserConf;
while(1) { while(1) {
$rhUserConf = GetDesiredConf($rhDefConf); $rhUserConf = GetDesiredConf($rhDefConf);
print "SetupDb using conf: \n"; print "SetupDb using conf: \n";
ShowConfig($rhUserConf); ShowConfig($rhUserConf);
last if($sForce || AutoCheckConf($rhUserConf)); last if($sForce || AutoCheckConf($rhUserConf));
} }
ApplySetupDB($rhUserConf); ApplySetupDB($rhUserConf);
} }
#conf function #conf function
sub ApplySetupConf { my ($rhConfig) = @_; sub ApplySetupConf { my ($rhConfig) = @_;
print "\nApplying configurations...\n"; print "\nApplying configurations...\n";
my @aTargetfile = (MAP_CONF_FILE,CHAR_CONF_FILE,LOGIN_CONF_FILE,INTER_CONF_FILE); my @aTargetfile = (MAP_CONF_FILE,CHAR_CONF_FILE,LOGIN_CONF_FILE,INTER_CONF_FILE);
my $sConfDir = "conf"; my $sConfDir = "conf";
my $sUserConfDir = "import"; my $sUserConfDir = "import";
die "'$sConfDir' doesn't seem to exist or couldn't be read/written" unless(-d -r -w "../$sConfDir"); die "'$sConfDir' doesn't seem to exist or couldn't be read/written" unless(-d -r -w "../$sConfDir");
chdir "../$sConfDir"; chdir "../$sConfDir";
print "Saving tmp user-conf.\n"; print "Saving tmp user-conf.\n";
YAML::XS::DumpFile(DESD_CONF_FILE,$rhConfig); YAML::XS::DumpFile(DESD_CONF_FILE,$rhConfig);
unless(-d "$sUserConfDir") { unless(-d "$sUserConfDir") {
print "Directory 'conf/import' doesn't exist. Create it? [y/n] (will be generated by compilation otherwise) \n"; print "Directory 'conf/import' doesn't exist. Create it? [y/n] (will be generated by compilation otherwise) \n";
if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) { die "Cannot apply configurations without 'import' folder, exiting...\n"; } if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) { die "Cannot apply configurations without 'import' folder, exiting...\n"; }
mkdir "$sUserConfDir"; mkdir "$sUserConfDir";
} }
chdir $sUserConfDir; chdir $sUserConfDir;
if($sClean){ unlink @aTargetfile; } #deleting file before applying conf if clean if($sClean){ unlink @aTargetfile; } #deleting file before applying conf if clean
opendir(DIR, ".") or die $!; opendir(DIR, ".") or die $!;
my @aDirfile = grep { /\.txt/ && -f "$_" } readdir(DIR); my @aDirfile = grep { /\.txt/ && -f "$_" } readdir(DIR);
close DIR; close DIR;
print "Current file in directory '@aDirfile' is target '@aTargetfile'.\n"; print "Current file in directory '@aDirfile' is target '@aTargetfile'.\n";
foreach my $sCurfile(@aTargetfile) { foreach my $sCurfile(@aTargetfile) {
print "Checking if target file '$sCurfile' exists... "; print "Checking if target file '$sCurfile' exists... ";
if(-e -r $sCurfile) { if(-e -r $sCurfile) {
print "Yes. Overwrite it? [y/n] \n"; print "Yes. Overwrite it? [y/n] \n";
if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) { if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) {
print "Only overwrite option currently supported. File skipped...\n\n"; print "Only overwrite option currently supported. File skipped...\n\n";
next; next;
} }
} }
else { print "No.\n" }; else { print "No.\n" };
@ -306,206 +305,206 @@ sub ApplySetupConf { my ($rhConfig) = @_;
elsif($sCurfile eq CHAR_CONF_FILE) { ApplyCharConf($rhConfig,$sCurfile); } elsif($sCurfile eq CHAR_CONF_FILE) { ApplyCharConf($rhConfig,$sCurfile); }
elsif($sCurfile eq LOGIN_CONF_FILE) { ApplyLoginConf($rhConfig,$sCurfile); } elsif($sCurfile eq LOGIN_CONF_FILE) { ApplyLoginConf($rhConfig,$sCurfile); }
elsif($sCurfile eq INTER_CONF_FILE) { ApplyInterConf($rhConfig,$sCurfile); } elsif($sCurfile eq INTER_CONF_FILE) { ApplyInterConf($rhConfig,$sCurfile); }
} }
} }
sub ApplyMapConf { my ($rhUserConf,$sCurfile) = @_; sub ApplyMapConf { my ($rhUserConf,$sCurfile) = @_;
open FILE, "> $sCurfile" || die "Couldn't open or create file '$sCurfile'.\n"; open FILE, "> $sCurfile" || die "Couldn't open or create file '$sCurfile'.\n";
print FILE "userid: " . $$rhUserConf{SERV_UID}."\n"; print FILE "userid: " . $$rhUserConf{SERV_UID}."\n";
print FILE "passwd: " . $$rhUserConf{SERV_PW}."\n\n"; print FILE "passwd: " . $$rhUserConf{SERV_PW}."\n\n";
print FILE "map_ip: " . $$rhUserConf{SERV_WAN_IP}."\n"; print FILE "map_ip: " . $$rhUserConf{SERV_WAN_IP}."\n";
print FILE "map_port: " . $$rhUserConf{MAP_PORT}."\n"; print FILE "map_port: " . $$rhUserConf{MAP_PORT}."\n";
print FILE "char_ip: " . $$rhUserConf{CHAR_PRIV_IP}."\n"; print FILE "char_ip: " . $$rhUserConf{CHAR_PRIV_IP}."\n";
print FILE "char_port: " . $$rhUserConf{CHAR_PORT}."\n"; print FILE "char_port: " . $$rhUserConf{CHAR_PORT}."\n";
} }
sub ApplyCharConf { my ($rhUserConf,$sCurfile) = @_; sub ApplyCharConf { my ($rhUserConf,$sCurfile) = @_;
open FILE, "> $sCurfile" || die "Couldn't open file '$sCurfile'.\n"; open FILE, "> $sCurfile" || die "Couldn't open file '$sCurfile'.\n";
print FILE "userid: " . $$rhUserConf{SERV_UID}."\n"; print FILE "userid: " . $$rhUserConf{SERV_UID}."\n";
print FILE "passwd: " . $$rhUserConf{SERV_PW}."\n\n"; print FILE "passwd: " . $$rhUserConf{SERV_PW}."\n\n";
print FILE "char_ip: " . $$rhUserConf{SERV_WAN_IP}."\n"; print FILE "char_ip: " . $$rhUserConf{SERV_WAN_IP}."\n";
print FILE "char_port: " . $$rhUserConf{CHAR_PORT}."\n"; print FILE "char_port: " . $$rhUserConf{CHAR_PORT}."\n";
print FILE "login_ip: " . $$rhUserConf{LOGIN_PRIV_IP}."\n"; print FILE "login_ip: " . $$rhUserConf{LOGIN_PRIV_IP}."\n";
print FILE "login_port: " . $$rhUserConf{LOGIN_PORT}."\n"; print FILE "login_port: " . $$rhUserConf{LOGIN_PORT}."\n";
print FILE "pincode_enabled: " . $$rhUserConf{PINCODE_ENABLE}."\n"; print FILE "pincode_enabled: " . $$rhUserConf{PINCODE_ENABLE}."\n";
} }
sub ApplyLoginConf { my ($rhUserConf,$sCurfile) = @_; sub ApplyLoginConf { my ($rhUserConf,$sCurfile) = @_;
open FILE, "> $sCurfile" || die "Couldn't open file '$sCurfile'.\n"; open FILE, "> $sCurfile" || die "Couldn't open file '$sCurfile'.\n";
print FILE "login_port: " . $$rhUserConf{LOGIN_PORT}."\n"; print FILE "login_port: " . $$rhUserConf{LOGIN_PORT}."\n";
print FILE "use_MD5_passwords: " . $$rhUserConf{MD5_ENABLE}."\n"; print FILE "use_MD5_passwords: " . $$rhUserConf{MD5_ENABLE}."\n";
} }
sub ApplyInterConf { my ($rhUserConf,$sCurfile) = @_; sub ApplyInterConf { my ($rhUserConf,$sCurfile) = @_;
open FILE, "> $sCurfile" || die "Couldn't open file '$sCurfile'.\n"; open FILE, "> $sCurfile" || die "Couldn't open file '$sCurfile'.\n";
print FILE "login_server_ip: " . $$rhUserConf{SQL_HOST}."\n"; print FILE "login_server_ip: " . $$rhUserConf{SQL_HOST}."\n";
print FILE "login_server_port: " . $$rhUserConf{SQL_PORT}."\n"; print FILE "login_server_port: " . $$rhUserConf{SQL_PORT}."\n";
print FILE "login_server_id: " . $$rhUserConf{SQL_UID}."\n"; print FILE "login_server_id: " . $$rhUserConf{SQL_UID}."\n";
print FILE "login_server_pw: " . $$rhUserConf{SQL_PW}."\n"; print FILE "login_server_pw: " . $$rhUserConf{SQL_PW}."\n";
print FILE "login_server_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n"; print FILE "login_server_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n";
print FILE "ipban_db_ip: " . $$rhUserConf{SQL_HOST}."\n"; print FILE "ipban_db_ip: " . $$rhUserConf{SQL_HOST}."\n";
print FILE "ipban_db_port: " . $$rhUserConf{SQL_PORT}."\n"; print FILE "ipban_db_port: " . $$rhUserConf{SQL_PORT}."\n";
print FILE "ipban_db_id: " . $$rhUserConf{SQL_UID}."\n"; print FILE "ipban_db_id: " . $$rhUserConf{SQL_UID}."\n";
print FILE "ipban_db_pw: " . $$rhUserConf{SQL_PW}."\n"; print FILE "ipban_db_pw: " . $$rhUserConf{SQL_PW}."\n";
print FILE "ipban_db_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n"; print FILE "ipban_db_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n";
print FILE "char_server_ip: " . $$rhUserConf{SQL_HOST}."\n"; print FILE "char_server_ip: " . $$rhUserConf{SQL_HOST}."\n";
print FILE "char_server_port: " . $$rhUserConf{SQL_PORT}."\n"; print FILE "char_server_port: " . $$rhUserConf{SQL_PORT}."\n";
print FILE "char_server_id: " . $$rhUserConf{SQL_UID}."\n"; print FILE "char_server_id: " . $$rhUserConf{SQL_UID}."\n";
print FILE "char_server_pw: " . $$rhUserConf{SQL_PW}."\n"; print FILE "char_server_pw: " . $$rhUserConf{SQL_PW}."\n";
print FILE "char_server_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n"; print FILE "char_server_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n";
print FILE "map_server_ip: " . $$rhUserConf{SQL_HOST}."\n"; print FILE "map_server_ip: " . $$rhUserConf{SQL_HOST}."\n";
print FILE "map_server_port: " . $$rhUserConf{SQL_PORT}."\n"; print FILE "map_server_port: " . $$rhUserConf{SQL_PORT}."\n";
print FILE "map_server_id: " . $$rhUserConf{SQL_UID}."\n"; print FILE "map_server_id: " . $$rhUserConf{SQL_UID}."\n";
print FILE "map_server_pw: " . $$rhUserConf{SQL_PW}."\n"; print FILE "map_server_pw: " . $$rhUserConf{SQL_PW}."\n";
print FILE "map_server_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n"; print FILE "map_server_db: " . $$rhUserConf{SQL_MAIN_DB}."\n\n";
print FILE "log_db_ip: " . $$rhUserConf{SQL_HOST} ."\n"; print FILE "log_db_ip: " . $$rhUserConf{SQL_HOST} ."\n";
print FILE "log_db_port: " . $$rhUserConf{SQL_PORT}."\n"; print FILE "log_db_port: " . $$rhUserConf{SQL_PORT}."\n";
print FILE "log_db_id: " . $$rhUserConf{SQL_UID}."\n"; print FILE "log_db_id: " . $$rhUserConf{SQL_UID}."\n";
print FILE "log_db_pw: " . $$rhUserConf{SQL_PW}."\n"; print FILE "log_db_pw: " . $$rhUserConf{SQL_PW}."\n";
print FILE "log_db_db: " . $$rhUserConf{SQL_LOG_DB}."\n\n"; print FILE "log_db_db: " . $$rhUserConf{SQL_LOG_DB}."\n\n";
} }
sub AutoCheckConf { my ($rhConfig) = @_; sub AutoCheckConf { my ($rhConfig) = @_;
print "\n== Auto-Check Configuration ==\n"; print "\n== Auto-Check Configuration ==\n";
print "NOTE: You can use option --force=1 to bypass this.\n"; print "NOTE: You can use option --force=1 to bypass this.\n";
foreach my $sKeys (keys %$rhConfig){ foreach my $sKeys (keys %$rhConfig){
my $sVal = $$rhConfig{$sKeys}; my $sVal = $$rhConfig{$sKeys};
if($sKeys =~ /PORT/) { #chek if valid port if($sKeys =~ /PORT/) { #chek if valid port
if(($sVal<MIN_PORT) && ($sVal>MAX_PORT)) { if(($sVal<MIN_PORT) && ($sVal>MAX_PORT)) {
warn "Invalid port specified for $sKeys => $sVal. Port must be in [".MIN_PORT.":".MAX_PORT."].\n"; warn "Invalid port specified for $sKeys => $sVal. Port must be in [".MIN_PORT.":".MAX_PORT."].\n";
return 0; return 0;
} }
elsif(!($sKeys =~ /SQL/) && CheckUsedPort($sVal)) { #skip SQL service elsif(!($sKeys =~ /SQL/) && CheckUsedPort($sVal)) { #skip SQL service
warn "Port '$sVal' seems to already be in use by your system.\n"; warn "Port '$sVal' seems to already be in use by your system.\n";
return 0; return 0;
} }
elsif(CheckDupPort($rhConfig,$sKeys)) { elsif(CheckDupPort($rhConfig,$sKeys)) {
warn "Port '$sVal' seems to already be used by another key in config.\n"; warn "Port '$sVal' seems to already be used by another key in config.\n";
return 0; return 0;
} }
} }
elsif($sKeys =~ /IP|HOST/){ #chek if ip valid, can we reach it ? trough SYN ACK elsif($sKeys =~ /IP|HOST/){ #chek if ip valid, can we reach it ? trough SYN ACK
my $p = Net::Ping->new("syn"); my $p = Net::Ping->new("syn");
my $sTest = $p->ping($sVal); my $sTest = $p->ping($sVal);
$p->close(); $p->close();
unless($sTest) { unless($sTest) {
print "Invalid IP/Host, ping couldn't reach $sKeys => $sVal.\n"; print "Invalid IP/Host, ping couldn't reach $sKeys => $sVal.\n";
print "(NOTE: ICMP may just be unallowed.)\n"; print "(NOTE: ICMP may just be unallowed.)\n";
return 0; return 0;
} }
} }
} }
return 1; return 1;
} }
sub CheckDupPort { my ($rhConfig,$sChkKeys) = @_; sub CheckDupPort { my ($rhConfig,$sChkKeys) = @_;
my $sChkport = $$rhConfig{$sChkKeys}; my $sChkport = $$rhConfig{$sChkKeys};
foreach my $sKeys (keys %$rhConfig){ foreach my $sKeys (keys %$rhConfig){
next if($sKeys eq $sChkKeys); #skip ourself next if($sKeys eq $sChkKeys); #skip ourself
my $sVal = $$rhConfig{$sKeys}; my $sVal = $$rhConfig{$sKeys};
return 1 if($sChkport eq $sVal); return 1 if($sChkport eq $sVal);
} }
return 0; return 0;
} }
#Db function #Db function
sub ApplySetupDB { my($rhConfig) = @_; sub ApplySetupDB { my($rhConfig) = @_;
my $sDbH; #db handle my $sDbH; #db handle
my $sHost = $$rhConfig{SQL_HOST}; my $sHost = $$rhConfig{SQL_HOST};
my $sPort = $$rhConfig{SQL_PORT}; my $sPort = $$rhConfig{SQL_PORT};
my $sDsn = "dbi:mysql::$sHost:$sPort"; #don't try to auto connect to db my $sDsn = "dbi:mysql::$sHost:$sPort"; #don't try to auto connect to db
$$rhConfig{"Dsn"} = $sDsn; $$rhConfig{"Dsn"} = $sDsn;
$sDbH = RootCo($rhConfig); $sDbH = RootCo($rhConfig);
CreateDB($sDbH,$rhConfig); #create db if not exist CreateDB($sDbH,$rhConfig); #create db if not exist
$sDbH = CreateUser($sDbH,$rhConfig); #loged as user now $sDbH = CreateUser($sDbH,$rhConfig); #loged as user now
LoadSqlFile($sDbH,$rhConfig); #Load .sql file into db LoadSqlFile($sDbH,$rhConfig); #Load .sql file into db
CreateServUser($sDbH,$rhConfig); CreateServUser($sDbH,$rhConfig);
print "Database setup successful.\n"; print "Database setup successful.\n";
} }
sub CreateDB { my($sDbH,$rhConfig) = @_; sub CreateDB { my($sDbH,$rhConfig) = @_;
print "\n== Creating Databases ==\n"; print "\n== Creating Databases ==\n";
my $sDBn = $$rhConfig{SQL_MAIN_DB}; my $sDBn = $$rhConfig{SQL_MAIN_DB};
my $sLogDBn = $$rhConfig{SQL_LOG_DB}; my $sLogDBn = $$rhConfig{SQL_LOG_DB};
my @aQuery = ("create database IF NOT EXISTS $sDBn;","create database IF NOT EXISTS $sLogDBn;"); my @aQuery = ("create database IF NOT EXISTS $sDBn;","create database IF NOT EXISTS $sLogDBn;");
if($sClean){ #deleting database if clean if($sClean){ #deleting database if clean
unshift(@aQuery,"drop database IF EXISTS $sDBn;"); unshift(@aQuery,"drop database IF EXISTS $sDBn;");
unshift(@aQuery,"drop database IF EXISTS $sLogDBn;"); unshift(@aQuery,"drop database IF EXISTS $sLogDBn;");
} }
else { else {
my $sRes = $sDbH->selectcol_arrayref('show databases'); my $sRes = $sDbH->selectcol_arrayref('show databases');
foreach my $db (@$sRes){ #relevant later for import foreach my $db (@$sRes){ #relevant later for import
if($db eq "$sDBn") { ValidateDBMerge($db); } #may exit here if($db eq "$sDBn") { ValidateDBMerge($db); } #may exit here
elsif ($db eq "$sLogDBn") { ValidateDBMerge($db); } #may exit here elsif ($db eq "$sLogDBn") { ValidateDBMerge($db); } #may exit here
} }
} }
ExeQuery($sDbH,@aQuery); ExeQuery($sDbH,@aQuery);
} }
sub ValidateDBMerge { my($sDBn) = @_; sub ValidateDBMerge { my($sDBn) = @_;
warn "Database '$sDBn' seems to already exist.\n"; warn "Database '$sDBn' seems to already exist.\n";
warn "Do you wish to continue loading data from the existing database? [y/n] \n"; warn "Do you wish to continue loading data from the existing database? [y/n] \n";
if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) { if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) {
print "Exiting setup, please try again with another dbname or manually...\n"; print "Exiting setup, please try again with another dbname or manually...\n";
exit; exit;
} }
} }
sub CreateUser { my($sDbH,$rhConfig) = @_; sub CreateUser { my($sDbH,$rhConfig) = @_;
print "\n== Creating User ==\n"; print "\n== Creating User ==\n";
my $sDsn = $$rhConfig{"Dsn"}; my $sDsn = $$rhConfig{"Dsn"};
print "My dsn = $sDsn \n"; print "My dsn = $sDsn \n";
my $sHost = $$rhConfig{SQL_HOST}; my $sHost = $$rhConfig{SQL_HOST};
my $sPw = $$rhConfig{SQL_PW}; my $sPw = $$rhConfig{SQL_PW};
my $sUser = $$rhConfig{SQL_UID}; my $sUser = $$rhConfig{SQL_UID};
my $sDBn = $$rhConfig{SQL_MAIN_DB}; my $sDBn = $$rhConfig{SQL_MAIN_DB};
my $sLogDBn = $$rhConfig{SQL_LOG_DB}; my $sLogDBn = $$rhConfig{SQL_LOG_DB};
my @aQuery= ("GRANT ALL PRIVILEGES ON $sDBn.* TO $sUser\@'$sHost' IDENTIFIED BY '$sPw' WITH GRANT OPTION", #maindb my @aQuery= ("GRANT ALL PRIVILEGES ON $sDBn.* TO $sUser\@'$sHost' IDENTIFIED BY '$sPw' WITH GRANT OPTION", #maindb
"GRANT ALL PRIVILEGES ON $sLogDBn.* TO $sUser\@'$sHost' IDENTIFIED BY '$sPw' WITH GRANT OPTION"); #logdb "GRANT ALL PRIVILEGES ON $sLogDBn.* TO $sUser\@'$sHost' IDENTIFIED BY '$sPw' WITH GRANT OPTION"); #logdb
my $sUserDbh = DBI->connect($sDsn, $sUser, $sPw, {"PrintError" => 0}); #try connect with user my $sUserDbh = DBI->connect($sDsn, $sUser, $sPw, {"PrintError" => 0}); #try connect with user
if($sUserDbh && !$sClean) { if($sUserDbh && !$sClean) {
print "User '$sUser' seems to already exist, skipping creation...\n" print "User '$sUser' seems to already exist, skipping creation...\n"
."(Please check if you have correct privileges set for database '$sDBn'.)\n"; ."(Please check if you have correct privileges set for database '$sDBn'.)\n";
} }
else { #create user only if not exist (or mode clean) else { #create user only if not exist (or mode clean)
if($sClean && $sUser ne "root"){ unshift(@aQuery,"DELETE FROM mysql.user WHERE User = '$sUser';"); } if($sClean && $sUser ne "root"){ unshift(@aQuery,"DELETE FROM mysql.user WHERE User = '$sUser';"); }
print "Creating user $sUser for databases '$sDBn' and '$sLogDBn' on '$sHost'.\n"; print "Creating user $sUser for databases '$sDBn' and '$sLogDBn' on '$sHost'.\n";
ExeQuery($sDbH,@aQuery); ExeQuery($sDbH,@aQuery);
$sUserDbh = DBI->connect($sDsn, $sUser, $sPw); $sUserDbh = DBI->connect($sDsn, $sUser, $sPw);
} }
return $sUserDbh; #drop old co and connect with user now return $sUserDbh; #drop old co and connect with user now
} }
sub LoadSqlFile { my($sDbH,$rhConfig) = @_; sub LoadSqlFile { my($sDbH,$rhConfig) = @_;
print "\n== Loading SQL Files ==\n"; print "\n== Loading SQL Files ==\n";
my $sDBn = $$rhConfig{SQL_MAIN_DB}; my $sDBn = $$rhConfig{SQL_MAIN_DB};
my $sLogDBn = $$rhConfig{SQL_LOG_DB}; my $sLogDBn = $$rhConfig{SQL_LOG_DB};
my $sSqldir = "sql-files"; my $sSqldir = "sql-files";
my @aMainFiles = ("main.sql"); #add other file to load for main db here my @aMainFiles = ("main.sql"); #add other file to load for main db here
my @aLogFiles = ("logs.sql"); #add other file to load for log db here my @aLogFiles = ("logs.sql"); #add other file to load for log db here
die "$sSqldir doesn't seem to exist or couldn't be read." unless(-d -r "../$sSqldir"); die "$sSqldir doesn't seem to exist or couldn't be read." unless(-d -r "../$sSqldir");
chdir "../$sSqldir"; chdir "../$sSqldir";
print "Checking if target files exist:\n\tMain: [@aMainFiles]\n\tLog: [@aLogFiles]\n"; print "Checking if target files exist:\n\tMain: [@aMainFiles]\n\tLog: [@aLogFiles]\n";
CheckAndLoadSQL(\@aMainFiles,$rhConfig,$sDBn); CheckAndLoadSQL(\@aMainFiles,$rhConfig,$sDBn);
CheckAndLoadSQL(\@aLogFiles,$rhConfig,$sLogDBn); CheckAndLoadSQL(\@aLogFiles,$rhConfig,$sLogDBn);
# my $raMainQuerys = CheckAndAddQuery(\@aMainFiles,$rhConfig); # my $raMainQuerys = CheckAndAddQuery(\@aMainFiles,$rhConfig);
# my $raLogQuerys = CheckAndAddQuery(\@aLogFiles,$rhConfig); # my $raLogQuerys = CheckAndAddQuery(\@aLogFiles,$rhConfig);
@ -531,43 +530,43 @@ sub LoadSqlFile { my($sDbH,$rhConfig) = @_;
#} #}
sub CreateServUser { my($sDbH,$rhConfig) = @_; sub CreateServUser { my($sDbH,$rhConfig) = @_;
my $sUid = $$rhConfig{SERV_UID}; my $sUid = $$rhConfig{SERV_UID};
my $sUpw = $$rhConfig{SERV_PW}; my $sUpw = $$rhConfig{SERV_PW};
my $sMD5 = $$rhConfig{MD5_ENABLE}; my $sMD5 = $$rhConfig{MD5_ENABLE};
my $sDBn = $$rhConfig{SQL_MAIN_DB}; my $sDBn = $$rhConfig{SQL_MAIN_DB};
my @aQuery = ("use $sDBn;","DELETE FROM login WHERE sex='S';"); my @aQuery = ("use $sDBn;","DELETE FROM login WHERE sex='S';");
if($sMD5){ push(@aQuery,"INSERT INTO login(account_id, userid, user_pass, sex) values(1,'$sUid',MD5('$sUpw'),'S');"); } if($sMD5){ push(@aQuery,"INSERT INTO login(account_id, userid, user_pass, sex) values(1,'$sUid',MD5('$sUpw'),'S');"); }
else { push(@aQuery,"INSERT INTO login(account_id, userid, user_pass, sex) values(1,'$sUid','$sUpw','S');"); } else { push(@aQuery,"INSERT INTO login(account_id, userid, user_pass, sex) values(1,'$sUid','$sUpw','S');"); }
ExeQuery($sDbH,@aQuery); ExeQuery($sDbH,@aQuery);
} }
sub GetDesiredConf { my ($rhDefConf) = @_; sub GetDesiredConf { my ($rhDefConf) = @_;
print "Please enter desired configuration.\n"; print "Please enter desired configuration.\n";
my $rhUserConf; my $rhUserConf;
my $sDesdConfFile = $sDsdFile; my $sDesdConfFile = $sDsdFile;
#if default search in conf otherwise get specified name with cwd #if default search in conf otherwise get specified name with cwd
if($sDsdFile eq DESD_CONF_FILE) { $sDesdConfFile = "../conf/".$sDsdFile; } if($sDsdFile eq DESD_CONF_FILE) { $sDesdConfFile = "../conf/".$sDsdFile; }
print "Checking if there is a DesiredConf file...\n"; print "Checking if there is a DesiredConf file...\n";
if(-e -r $sDesdConfFile) { if(-e -r $sDesdConfFile) {
print "Found DesiredConf.\n"; print "Found DesiredConf.\n";
$rhUserConf = YAML::XS::LoadFile($sDesdConfFile); $rhUserConf = YAML::XS::LoadFile($sDesdConfFile);
if(!($rhUserConf)){ if(!($rhUserConf)){
print "DesiredConf is invalid or empty. Please check the file, and relaunch setup or enter Config.\n"; print "DesiredConf is invalid or empty. Please check the file, and relaunch setup or enter Config.\n";
$rhUserConf=GetValidateConf($rhDefConf); $rhUserConf=GetValidateConf($rhDefConf);
} }
else { else {
ShowConfig($rhUserConf); ShowConfig($rhUserConf);
print "Would you like to apply these settings? [y/n] "; print "Would you like to apply these settings? [y/n] ";
if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) { #no take user entry if(GetValidAnwser("y|o|n",$sAutoyes) =~ /n/i) { #no take user entry
print "DesiredConf not applied. Please enter config.\n"; print "DesiredConf not applied. Please enter config.\n";
$rhUserConf=GetValidateConf($rhDefConf); $rhUserConf=GetValidateConf($rhDefConf);
} }
} }
} }
else { #no files take user entry else { #no files take user entry
print "No DesiredConf found. Please enter config.\n"; print "No DesiredConf found. Please enter config.\n";
$rhUserConf=GetValidateConf($rhDefConf); $rhUserConf=GetValidateConf($rhDefConf);
} }
return $rhUserConf; return $rhUserConf;
} }

View File

@ -113,13 +113,13 @@ emotion_dict_old = collections.OrderedDict([
]) ])
""" """
def parse_emotion_dict(filepath): def parse_emotion_dict(filepath):
ret_list = [] ret_list = []
with fileinput.FileInput(filepath) as fiFile: with fileinput.FileInput(filepath) as fiFile:
for line in fiFile: for line in fiFile:
found = re.search('"(E_[A-Z_0-9]+)"\s*,\s*(ET_[A-Z_0-9]+)\s*', line) found = re.search('"(E_[A-Z_0-9]+)"\s*,\s*(ET_[A-Z_0-9]+)\s*', line)
if found: if found:
ret_list.append((found.group(1), found.group(2))) ret_list.append((found.group(1), found.group(2)))
return ret_list return ret_list
emotion_dict = collections.OrderedDict(parse_emotion_dict(parse_dict_file)) emotion_dict = collections.OrderedDict(parse_emotion_dict(parse_dict_file))
@ -128,59 +128,59 @@ pattern_oldconst = re.compile(r'\b(' + '|'.join(emotion_dict.keys()) + r')\b', r
pattern_value = re.compile(r'\b(' + '|'.join(["emotion\s+%d+"%i for i in range(len(emotion_array))]) + r')\b', re.IGNORECASE) pattern_value = re.compile(r'\b(' + '|'.join(["emotion\s+%d+"%i for i in range(len(emotion_array))]) + r')\b', re.IGNORECASE)
def revert_to_backup(filename): def revert_to_backup(filename):
os.rename(filename+BACKUP_EXT, filename) os.rename(filename+BACKUP_EXT, filename)
def apply_substitutions(new_line, is_script):
remove_backup = True # only keep backup if the original file changed
rpl_cnt = 0
# E_GASP -> ET_SURPRISE
new_line, rpl_cnt = pattern_oldconst.subn(lambda x: emotion_dict[x.group().upper()], new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
if is_script: # script only replacements
# 0 -> ET_SURPRISE
new_line, rpl_cnt = pattern_value.subn(lambda x: 'emotion '+emotion_array[int(x.group().split()[-1])], new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
# emotion e,0,"Record player#e152a01"; -> emotion e, getnpcid(0,"Record player#e152a01");
new_line, rpl_cnt = re.subn(r"emotion\s+([^,]+)\s*,\s*0\s*,\s*([^;]+);",
"emotion \g<1>, getnpcid(0, \g<2>);", new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
# emotion e,1; -> emotion e, playerattached();
new_line, rpl_cnt = re.subn(r"emotion\s+([^,]+)\s*,\s*1\s*;",
"emotion \g<1>, playerattached();", new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
# unitemote <id>,<emotion>; -> emotion <emotion>, <id>;
new_line, rpl_cnt = re.subn(r"unitemote\s+([^,]+)\s*,\s*([^,;]+)\s*;",
"emotion \g<2>, \g<1>;", new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
return new_line, remove_backup def apply_substitutions(new_line, is_script):
remove_backup = True # only keep backup if the original file changed
rpl_cnt = 0
# E_GASP -> ET_SURPRISE
new_line, rpl_cnt = pattern_oldconst.subn(lambda x: emotion_dict[x.group().upper()], new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
if is_script: # script only replacements
# 0 -> ET_SURPRISE
new_line, rpl_cnt = pattern_value.subn(lambda x: 'emotion '+emotion_array[int(x.group().split()[-1])], new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
# emotion e,0,"Record player#e152a01"; -> emotion e, getnpcid(0,"Record player#e152a01");
new_line, rpl_cnt = re.subn(r"emotion\s+([^,]+)\s*,\s*0\s*,\s*([^;]+);",
"emotion \g<1>, getnpcid(0, \g<2>);", new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
# emotion e,1; -> emotion e, playerattached();
new_line, rpl_cnt = re.subn(r"emotion\s+([^,]+)\s*,\s*1\s*;",
"emotion \g<1>, playerattached();", new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
# unitemote <id>,<emotion>; -> emotion <emotion>, <id>;
new_line, rpl_cnt = re.subn(r"unitemote\s+([^,]+)\s*,\s*([^,;]+)\s*;",
"emotion \g<2>, \g<1>;", new_line)
remove_backup = False if rpl_cnt > 0 else remove_backup
return new_line, remove_backup
def replace_emoticons_in_file(filename): def replace_emoticons_in_file(filename):
is_script = True if any([filename.endswith(script_ext) for script_ext in script_file_extensions]) else False is_script = True if any([filename.endswith(script_ext) for script_ext in script_file_extensions]) else False
remove_backup = True remove_backup = True
with fileinput.FileInput(filename, inplace=True, backup=BACKUP_EXT) as fiFile: with fileinput.FileInput(filename, inplace=True, backup=BACKUP_EXT) as fiFile:
try: try:
for line in fiFile: for line in fiFile:
new_line, rm_backup = apply_substitutions(line, is_script) new_line, rm_backup = apply_substitutions(line, is_script)
if not rm_backup: if not rm_backup:
remove_backup = False remove_backup = False
print(new_line, end='') print(new_line, end='')
if remove_backup: if remove_backup:
os.remove(filename+BACKUP_EXT) os.remove(filename+BACKUP_EXT)
except UnicodeDecodeError: except UnicodeDecodeError:
# Encoding error, reapply the backup # Encoding error, reapply the backup
revert_to_backup(filename) revert_to_backup(filename)
fileiter = (os.path.join(root, f) fileiter = (os.path.join(root, f)
for conv_folder in convert_folders for conv_folder in convert_folders
for root, _, files in os.walk(conv_folder) for root, _, files in os.walk(conv_folder)
for f in files for f in files
if any([f.endswith(wl) for wl in wl_file_extensions]) if any([f.endswith(wl) for wl in wl_file_extensions])
if not any([bl in f for bl in bl_files]) if not any([bl in f for bl in bl_files])
) )
for f in fileiter: for f in fileiter:
print("Updating file", f) print("Updating file", f)
replace_emoticons_in_file(f) replace_emoticons_in_file(f)

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl #!/usr/bin/perl
# rAthena Monster Mode Converter # rAthena Monster Mode Converter
# Upgrades monster's mode to the new structure. # Upgrades monster's mode to the new structure.
# #
use strict; use strict;
use warnings; use warnings;
@ -102,15 +102,15 @@ sub Main {
next; next;
} }
unless(open FHOUT,">$sFileouttmp"){ unless(open FHOUT,">$sFileouttmp"){
print "ERROR: Can't write or locate $aFileout[$sI].\n"; print "ERROR: Can't write or locate $aFileout[$sI].\n";
next; next;
} }
$sI++; $sI++;
while (<FHIN>){ while (<FHIN>){
if( $_ =~ /^\s*$/) { #ignore empty line if( $_ =~ /^\s*$/) { #ignore empty line
print FHOUT $_; print FHOUT $_;
next; next;
} }
my @champ = split(",",$_); my @champ = split(",",$_);
my $sDoconvertion=0; #should this comment be converted my $sDoconvertion=0; #should this comment be converted
if( $_ =~ /^\/\// ) { # // line if( $_ =~ /^\/\// ) { # // line
@ -121,7 +121,7 @@ sub Main {
} }
if($sDoconvertion==0) { if($sDoconvertion==0) {
print FHOUT $_; print FHOUT $_;
next; next;
} }
} }
if(scalar(@champ>0)){ if(scalar(@champ>0)){

View File

@ -85,7 +85,7 @@ sub ConvertFile { my($sFilein,$sFileout,$sType)=@_;
print "Starting ConvertFile with: \n\t filein=$sFilein \n\t fileout=$sFileout \n"; print "Starting ConvertFile with: \n\t filein=$sFilein \n\t fileout=$sFileout \n";
open FHIN,"$sFilein" or die "ERROR: Can't read or locate $sFilein.\n"; open FHIN,"$sFilein" or die "ERROR: Can't read or locate $sFilein.\n";
open $sFHout,">$sFileout" or die "ERROR: Can't write $sFileout.\n"; open $sFHout,">$sFileout" or die "ERROR: Can't write $sFileout.\n";
printf $sFHout ("%s\n",$create_table); printf $sFHout ("%s\n",$create_table);
while(my $ligne=<FHIN>) { while(my $ligne=<FHIN>) {
my $sWasCom = 0; my $sWasCom = 0;
@ -176,7 +176,7 @@ sub escape { my ($str,$sregex,$sreplace) = @_;
sub BuildDataForType{ my($sTarget,$sType) = @_; sub BuildDataForType{ my($sTarget,$sType) = @_;
print "Starting BuildDataForType with: \n\t Target=$sTarget, Type=$sType \n"; print "Starting BuildDataForType with: \n\t Target=$sTarget, Type=$sType \n";
if($sType =~ /mob_skill/i) { #Same format for Pre-Renewal and Renewal. if($sType =~ /mob_skill/i) { #Same format for Pre-Renewal and Renewal.
$db = $sTable; $db = $sTable;
if($sTarget =~ /Pre/i){ if($sTarget =~ /Pre/i){

View File

@ -27,8 +27,6 @@ if "%target%" == "status" (
call :Watch call :Watch
) else if "%target%" == "stop" ( ) else if "%target%" == "stop" (
call :Stop call :Stop
) else if "%target%" == "stop" (
call :Stop
) else if "%target%" == "start" ( ) else if "%target%" == "start" (
call :Start call :Start
) )
@ -69,7 +67,7 @@ call :getCharStatus
call :getWebStatus call :getWebStatus
call :getMapStatus call :getMapStatus
if "%login_running%" == "false" ( echo "login_serv is not running" if "%login_running%" == "false" ( echo "login_serv is not running"
) else echo "login_serv is running pid=%LoginServPID%" ) else echo "login_serv is running pid=%LoginServPID%"
if "%char_running%" == "false" ( echo "char_serv is not running" if "%char_running%" == "false" ( echo "char_serv is not running"
) else echo "char_serv is running pid=%CharServPID%" ) else echo "char_serv is running pid=%CharServPID%"
@ -111,13 +109,13 @@ REM start sub targets
:startLogin :startLogin
call :getLoginStatus call :getLoginStatus
if "%login_running%" == "false" ( start cmd /k logserv.bat %restart_mode% if "%login_running%" == "false" ( start cmd /k logserv.bat %restart_mode%
) else echo "Login serv is already running pid=%LoginServPID%" ) else echo "Login serv is already running pid=%LoginServPID%"
goto :EOF goto :EOF
:startChar :startChar
call :getCharStatus call :getCharStatus
if "%char_running%" == "false" ( start cmd /k charserv.bat %restart_mode% if "%char_running%" == "false" ( start cmd /k charserv.bat %restart_mode%
) else echo "Char serv is already running, pid=%CharServPID%" ) else echo "Char serv is already running, pid=%CharServPID%"
goto :EOF goto :EOF
:startWeb :startWeb
@ -129,8 +127,8 @@ goto :EOF
:startMap :startMap
call :getMapStatus call :getMapStatus
if "%map_running%" == "false" ( start cmd /k mapserv.bat %restart_mode% if "%map_running%" == "false" ( start cmd /k mapserv.bat %restart_mode%
) else echo "Map serv is already running, pid=%MapServPID%" ) else echo "Map serv is already running, pid=%MapServPID%"
goto :EOF goto :EOF
REM status sub targets REM status sub targets

View File

@ -57,7 +57,7 @@ fi
# Finally dump the backtrace # Finally dump the backtrace
# If number is given, Sig-plugin format. otherwise, standard stackdump format # If number is given, Sig-plugin format. otherwise, standard stackdump format
if [ $# -gt 2 ]; then if [ $# -gt 2 ]; then
awk '$2 ~ /[0-9a-eA-E]\]$/{print $2}' $STACK | tr -d \[\] | addr2line -f -e $SERVER awk '$2 ~ /[0-9a-eA-E]\]$/{print $2}' $STACK | tr -d \[\] | addr2line -f -e $SERVER
else else
awk '/^[0-9]/{print $2}' $STACK | addr2line -f -e $SERVER awk '/^[0-9]/{print $2}' $STACK | addr2line -f -e $SERVER
fi fi

View File

@ -51,7 +51,7 @@ sub GetArgs {
'target=s' => \$sTarget, #Target (which setup to run) 'target=s' => \$sTarget, #Target (which setup to run)
'help!' => \$sHelp, 'help!' => \$sHelp,
) or $sHelp=1; #display help if invalid option ) or $sHelp=1; #display help if invalid option
if( $sHelp ) { if( $sHelp ) {
print "Incorrect option specified. Available options:\n" print "Incorrect option specified. Available options:\n"
."\t --target => target (specify which check to ignore [$sValidTarget])\n"; ."\t --target => target (specify which check to ignore [$sValidTarget])\n";
@ -59,7 +59,7 @@ sub GetArgs {
} }
if(!$sTarget || !($sTarget =~ /$sValidTarget/i)){ if(!$sTarget || !($sTarget =~ /$sValidTarget/i)){
print "Incorrect target specified. Available targets:\n" print "Incorrect target specified. Available targets:\n"
."\t --target => target (specify which check to ignore [(default)$sValidTarget])\n ."\t --target => target (specify which check to ignore [(default)$sValidTarget])\n
(NOTE: restart is compiling dependent.)\n"; (NOTE: restart is compiling dependent.)\n";
exit; exit;
} }
@ -68,7 +68,7 @@ sub GetArgs {
sub Main { sub Main {
my $sCurdir = getcwd; my $sCurdir = getcwd;
chdir ".."; chdir "..";
UpdateSQL($sCurdir,1,\%hFileState); UpdateSQL($sCurdir,1,\%hFileState);
if($sTarget =~ "All|Upd") { GitUpdate($sCurdir); } if($sTarget =~ "All|Upd") { GitUpdate($sCurdir); }
if($sTarget =~ "All|DB") { UpdateSQL($sCurdir,0,\%hFileState); } if($sTarget =~ "All|DB") { UpdateSQL($sCurdir,0,\%hFileState); }
@ -77,8 +77,8 @@ sub Main {
sub GetSqlFileInDir { my($sDir) = @_; sub GetSqlFileInDir { my($sDir) = @_;
opendir (DIR, $sDir) or die $!; opendir (DIR, $sDir) or die $!;
my @aFiles my @aFiles
= grep { = grep {
/^(?!\.)/ # not begins with a period /^(?!\.)/ # not begins with a period
&& /\.sql$/ # finish by .sql && /\.sql$/ # finish by .sql
&& -f "$sDir/$_" # and is a file && -f "$sDir/$_" # and is a file
@ -98,7 +98,7 @@ sub UpdateSQL { my($sBaseDir,$sInit,$rhFileState) = @_;
print "Reading file status...\n"; print "Reading file status...\n";
$rhFileState = YAML::XS::LoadFile("sql-files/".STATE_FILE); $rhFileState = YAML::XS::LoadFile("sql-files/".STATE_FILE);
} }
if($sTarget =~ "All|MapDB") { if($sTarget =~ "All|MapDB") {
chdir "sql-files"; chdir "sql-files";
print "Getting Map SQL Db file...\n"; print "Getting Map SQL Db file...\n";
@ -119,17 +119,17 @@ sub UpdateSQL { my($sBaseDir,$sInit,$rhFileState) = @_;
} }
chdir ".."; chdir "..";
} }
chdir "sql-files/upgrades"; chdir "sql-files/upgrades";
my $raFiles = GetSqlFileInDir("./"); my $raFiles = GetSqlFileInDir("./");
foreach my $sFile (@$raFiles){ foreach my $sFile (@$raFiles){
#print "Cur file = $sFile \n"; #print "Cur file = $sFile \n";
if($sInit==1){ if($sInit==1){
if(exists $$rhFileState{$sFile} && $$rhFileState{$sFile}{"status"} == ST_DONE ){ if(exists $$rhFileState{$sFile} && $$rhFileState{$sFile}{"status"} == ST_DONE ){
next; next;
} }
if( $sFile =~ /_opt_/){ if( $sFile =~ /_opt_/){
$$rhFileState{$sFile}{"status"} = ST_SK; $$rhFileState{$sFile}{"status"} = ST_SK;
} else { } else {
@ -144,42 +144,42 @@ sub UpdateSQL { my($sBaseDir,$sInit,$rhFileState) = @_;
# #if it's done or skipped don't do it, if it's old but updated do it # #if it's done or skipped don't do it, if it's old but updated do it
next if ( $sT eq ST_OLD or $sT eq ST_DONE or $sLastMode == (stat ($sFile))[9] ); next if ( $sT eq ST_OLD or $sT eq ST_DONE or $sLastMode == (stat ($sFile))[9] );
} }
if( $sFile =~ /_log.sql$/) { if( $sFile =~ /_log.sql$/) {
print "Found log file '$sFile'.\n"; print "Found log file '$sFile'.\n";
push(@aLogDBFiles,$sFile); push(@aLogDBFiles,$sFile);
} }
else { else {
print "Found char file '$sFile'.\n"; print "Found char file '$sFile'.\n";
push(@aCharDBFiles,$sFile); push(@aCharDBFiles,$sFile);
} }
$$rhFileState{$sFile}{"status"} = "done"; # the query will be applied so mark it so $$rhFileState{$sFile}{"status"} = "done"; # the query will be applied so mark it so
# This part is for distributed DB, not supported yet # This part is for distributed DB, not supported yet
# proposed nomenclature [lighta] : update_date_{opt_}(map|chr|acc|log).sql # proposed nomenclature [lighta] : update_date_{opt_}(map|chr|acc|log).sql
# (e.g : update_20141218_opt_map.sql or update_20141218_acc.sql # (e.g : update_20141218_opt_map.sql or update_20141218_acc.sql
# if( $sFile =~ /_map.sql$/) { # if( $sFile =~ /_map.sql$/) {
# print "Found log file = $sFile \n"; # print "Found log file = $sFile \n";
# push(@aMapDBFiles,$sFile); # push(@aMapDBFiles,$sFile);
# #
# } # }
# elsif( $sFile =~ /_acc.sql$/) { # elsif( $sFile =~ /_acc.sql$/) {
# print "Found log file = $sFile \n"; # print "Found log file = $sFile \n";
# push(@aLoginDBFiles,$sFile); # push(@aLoginDBFiles,$sFile);
# #
# } # }
# elsif( $sFile =~ /_chr.sql$/) { # elsif( $sFile =~ /_chr.sql$/) {
# print "Found log file = $sFile \n"; # print "Found log file = $sFile \n";
# push(@aCharDBFiles,$sFile); # push(@aCharDBFiles,$sFile);
# #
# } # }
} }
} }
if($sInit==0){ #apply update if($sInit==0){ #apply update
return; return;
if( scalar(@aCharDBFiles)==0 and scalar(@aLogDBFiles)==0 if( scalar(@aCharDBFiles)==0 and scalar(@aLogDBFiles)==0
and scalar(@aMapDBFiles)==0 and scalar(@aLoginDBFiles)==0 and scalar(@aMapDBFiles)==0 and scalar(@aLoginDBFiles)==0
){ ){
print "No SQL update to perform.\n"; print "No SQL update to perform.\n";
} }
@ -194,7 +194,7 @@ sub UpdateSQL { my($sBaseDir,$sInit,$rhFileState) = @_;
else { else {
$rhUserConf=\%hDefConf; #we assume it's set correctly $rhUserConf=\%hDefConf; #we assume it's set correctly
} }
CheckAndLoadSQL(\@aMapDBFiles,$rhUserConf,$$rhUserConf{SQL_MAP_DB}); CheckAndLoadSQL(\@aMapDBFiles,$rhUserConf,$$rhUserConf{SQL_MAP_DB});
CheckAndLoadSQL(\@aCharDBFiles,$rhUserConf,$$rhUserConf{SQL_MAIN_DB}); CheckAndLoadSQL(\@aCharDBFiles,$rhUserConf,$$rhUserConf{SQL_MAIN_DB});
#CheckAndLoadSQL(\@aLoginDBFiles,$rhUserConf,$$rhUserConf{SQL_ACC_DB}); #CheckAndLoadSQL(\@aLoginDBFiles,$rhUserConf,$$rhUserConf{SQL_ACC_DB});
@ -228,7 +228,7 @@ sub GitUpdate { my($sBaseDir) = @_;
my $sGit = Git::Repository->new( my $sGit = Git::Repository->new(
work_tree => "$sBaseDir/..", work_tree => "$sBaseDir/..",
); );
my $sIsOrigin = CheckRemote($sGit); my $sIsOrigin = CheckRemote($sGit);
if($sIsOrigin==0){ if($sIsOrigin==0){
print "Saving current working tree...\n"; print "Saving current working tree...\n";
@ -252,10 +252,10 @@ sub GitUpdate { my($sBaseDir) = @_;
sub CheckRemote { my($sGit) = @_; sub CheckRemote { my($sGit) = @_;
my $sRaOrigin=0; my $sRaOrigin=0;
my $sRaUpstream=0; my $sRaUpstream=0;
print "Checking remotes\n"; print "Checking remotes\n";
my @aRemotes = $sGit->run("remote" => "-v"); my @aRemotes = $sGit->run("remote" => "-v");
#print "My Remotes are\n"; #print "My Remotes are\n";
foreach my $sCurRem (@aRemotes){ foreach my $sCurRem (@aRemotes){
my @aCol = split(' ',$sCurRem); my @aCol = split(' ',$sCurRem);