Merge branch 'master' into lsid

This commit is contained in:
Akkadius
2018-01-17 22:04:46 -06:00
50 changed files with 1915 additions and 1095 deletions
+8
View File
@@ -0,0 +1,8 @@
{
"server": {
"world": {
"shortname": "setme",
"longname": "I Forgot To Edit My Config"
}
}
}
+54
View File
@@ -0,0 +1,54 @@
{
"server": {
"zones": {
"defaultstatus": "20",
"ports": {
"low": "7000",
"high": "7100"
}
},
"database": {
"password": "eq",
"db": "eq",
"host": "127.0.0.1",
"port": "3306",
"username": "eq"
},
"world": {
"shortname": "setme",
"longname": "I Forgot To Edit My Config",
"loginserver": {
"password": "",
"host": "login.eqemulator.net",
"port": "5998",
"account": ""
},
"tcp": {
"port": "9000",
"telnet": "disable",
"ip": "127.0.0.1"
},
"key": "some long random string",
"http": {
"mimefile": "mime.types",
"port": "9080",
"enabled": "false"
}
},
"mailserver": {
"host": "channels.eqemulator.net",
"port": "7778"
},
"chatserver": {
"host": "channels.eqemulator.net",
"port": "7778"
},
"qsdatabase": {
"host": "127.0.0.1",
"port": "3306",
"username": "eq",
"password": "eq",
"db": "eq"
}
}
}
+355
View File
@@ -0,0 +1,355 @@
//Parses perl scripts
package main
import (
"bufio"
"fmt"
"log"
"os"
"regexp"
"strings"
"github.com/pkg/errors"
)
func main() {
path := "../../../zone/embparser_api.cpp"
err := readFile(path)
if err != nil {
log.Panicf("Failed to read file: %s", err.Error())
}
}
type API struct {
Function string
Arguments []*Argument
}
type Argument struct {
Name string
Type string
API *API
}
func readFile(path string) (err error) {
inFile, err := os.Open(path)
if err != nil {
err = errors.Wrap(err, "Failed to open file")
}
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
arguments := map[string][]*Argument{}
functions := []*API{}
reg, err := regexp.Compile(`\]+|\[+|\?+|[...]+`)
if err != nil {
err = errors.Wrap(err, "Failed to compile regex")
return
}
regType, err := regexp.Compile(`(unsigned long|long|int32|bool|uint[0-9]+|int|auto|float|unsigned int|char[ \*]).+([. a-zA-Z]+=)`)
if err != nil {
err = errors.Wrap(err, "Failed to compile type regex")
return
}
lastArguments := []*Argument{}
lastAPI := &API{}
lineNum := 0
for scanner.Scan() {
lineNum++
key := ""
line := scanner.Text()
if len(line) < 1 {
continue
}
if len(lastArguments) > 0 { //existing args to parse
for i, argument := range lastArguments {
key = fmt.Sprintf("ST(%d)", i)
if strings.Contains(line, key) {
//We found a definition argument line
if argument.Type != "" {
continue
}
match := regType.FindStringSubmatch(line)
if len(match) < 2 {
continue
}
//key = `int`
//function = line[strings.Index(line, key)+len(key):]
newType := ""
switch v := strings.TrimSpace(match[1]); v {
case "int":
newType = "int"
case "int32":
newType = "int"
case "float":
newType = "float"
case "unsigned int":
newType = "uint"
case "uint32":
newType = "uint"
case "uint8":
newType = "uint"
case "uint":
newType = "uint"
case "bool":
newType = "bool"
case "uint16":
newType = "uint"
case "long":
newType = "long"
case "unsigned long":
newType = "unsigned long"
case "char":
newType = "string"
case "auto":
//Auto is tricky
if strings.Contains(line, "glm::vec4") {
newType = "float"
}
default:
log.Printf(`Unknown type: "%s" on line %d`, v, lineNum)
}
//log.Println("Found arg type", newType, "on index", i, argument.Name)
lastArguments[i].Type = newType
}
}
}
function := ""
argLine := ""
args := []string{}
//Find line
key = `Perl_croak(aTHX_ "Usage:`
if strings.Contains(line, key) {
function = line[strings.Index(line, key)+len(key):]
}
for _, argument := range lastArguments {
arguments[argument.Name] = append(arguments[argument.Name], argument)
}
lastArguments = []*Argument{}
//Trim off the endings
key = `");`
if strings.Contains(function, key) {
function = function[0:strings.Index(function, key)]
}
//Strip out the arguments
key = `(`
if strings.Contains(function, key) {
argLine = function[strings.Index(function, key)+len(key):]
function = function[0:strings.Index(function, key)]
key = `)`
if strings.Contains(argLine, key) {
argLine = argLine[:strings.Index(argLine, key)]
}
key = `=`
if strings.Contains(argLine, key) {
argLine = argLine[:strings.Index(argLine, key)]
}
argLine = reg.ReplaceAllString(argLine, "")
}
key = `,`
argLine = strings.TrimSpace(argLine)
if strings.Contains(argLine, key) {
args = strings.Split(argLine, key)
}
if len(function) < 1 {
continue
}
newArgs := []string{}
for j, _ := range args {
args[j] = strings.TrimSpace(args[j])
if len(args[j]) == 0 {
continue
}
newArgs = append(newArgs, args[j])
}
lastAPI = &API{
Function: function,
}
for _, arg := range newArgs {
argType, _ := knownTypes[arg]
argument := &Argument{
Name: arg,
Type: argType,
API: lastAPI,
}
lastArguments = append(lastArguments, argument)
}
lastAPI.Arguments = lastArguments
functions = append(functions, lastAPI)
}
foundCount := 0
failCount := 0
for key, val := range arguments {
isMissing := false
line := ""
line = fmt.Sprintf("%s used by %d functions:", key, len(val))
for _, fnc := range val {
line += fmt.Sprintf("%s(%s %s), ", fnc.API.Function, fnc.Type, key)
if fnc.Type == "" {
isMissing = true
}
}
if isMissing {
fmt.Println(line)
failCount++
} else {
foundCount++
}
}
log.Println(foundCount, "functions properly identified,", failCount, "have errors")
line := ""
for _, api := range functions {
line += fmt.Sprintf("void %s(", strings.TrimSpace(api.Function))
for _, argument := range api.Arguments {
line += fmt.Sprintf("%s %s, ", argument.Type, argument.Name)
}
if len(api.Arguments) > 0 {
line = line[0 : len(line)-2]
}
line += ")\n"
}
fmt.Println(line)
return
}
var knownTypes = map[string]string{
"activity_id": "uint",
"alt_mode": "bool",
"anim_num": "int",
"best_z": "float",
"buttons": "int",
"channel_id": "int",
"char_id": "int",
"charges": "int",
"class_id": "int",
"client_name": "string",
"color": "int",
"color_id": "int",
"condition_id": "int",
"copper": "int",
"count": "int",
"debug_level": "int",
"decay_time": "int",
"dest_heading": "float",
"dest_x": "float",
"dest_y": "float",
"dest_z": "float",
"distance": "int",
"door_id": "int",
"doorid": "uint",
"duration": "int",
"effect_id": "int",
"elite_material_id": "int",
"enforce_level_requirement": "bool",
"explore_id": "uint",
"faction_value": "int",
"fade_in": "int",
"fade_out": "int",
"fadeout": "uint",
"firstname": "string",
"from": "string",
"gender_id": "int",
"gold": "int",
"grid_id": "int",
"guild_rank_id": "int",
"heading": "float",
"hero_forge_model_id": "int",
"ignore_quest_update": "bool",
"instance_id": "int",
"int_unused": "int",
"int_value": "int",
"is_enabled": "bool",
"is_strict": "bool",
"item_id": "int",
"key": "string",
"language_id": "int",
"lastname": "string",
"leader_name": "string",
"level": "int",
"link_name": "string",
"macro_id": "int",
"max_level": "int",
"max_x": "float",
"max_y": "float",
"max_z": "float",
"message": "string",
"milliseconds": "int",
"min_level": "int",
"min_x": "float",
"min_y": "float",
"min_z": "float",
"name": "string",
"new_hour": "int",
"new_min": "int",
"node1": "int",
"node2": "int",
"npc_id": "int",
"npc_type_id": "int",
"object_type": "int",
"options": "int",
"platinum": "int",
"popup_id": "int",
"priority": "int",
"quantity": "int",
"race_id": "int",
"remove_item": "bool",
"requested_id": "int",
"reset_base": "bool",
"saveguard": "bool",
"seconds": "int",
"send_to_world": "bool",
"signal_id": "int",
"silent": "bool",
"silver": "int",
"size": "int",
"stat_id": "int",
"str_value": "string",
"subject": "string",
"target_enum": "string",
"target_id": "int",
"task": "int",
"task_id": "uint",
"task_id1": "int",
"task_id10": "int",
"task_id2": "int",
"task_set": "int",
"taskid": "int",
"taskid1": "int",
"taskid2": "int",
"taskid3": "int",
"taskid4": "int",
"teleport": "int",
"temp": "int",
"texture_id": "int",
"theme_id": "int",
"update_world": "int",
"updated_time_till_repop": "uint",
"version": "int",
"wait_ms": "int",
"window_title": "string",
"x": "float",
"y": "float",
"z": "float",
"zone_id": "int",
"zone_short": "string",
`task_id%i`: "int",
}
+252
View File
@@ -0,0 +1,252 @@
#!/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"); }
}
+155 -79
View File
@@ -48,10 +48,18 @@ if(-e "eqemu_server_skip_update.txt"){
}
#::: Check for script self update
check_xml_to_json_conversion() if $ARGV[0] eq "convert_xml";
do_self_update_check_routine() if !$skip_self_update_check;
get_windows_wget();
get_perl_version();
read_eqemu_config_xml();
if(-e "eqemu_config.json") {
read_eqemu_config_json();
}
else {
#::: This will need to stay for servers who simply haven't updated yet
# This script can still update without the server bins being updated
read_eqemu_config_xml();
}
get_mysql_path();
#::: Remove old eqemu_update.pl
@@ -265,7 +273,7 @@ sub new_server {
analytics_insertion("new_server::install", $database_name);
if($OS eq "Linux"){
build_linux_source();
build_linux_source("login");
}
do_installer_routines();
@@ -281,6 +289,10 @@ sub new_server {
show_install_summary_info();
if($OS eq "Linux") {
unlink('/home/eqemu/install_variables.txt');
}
rmtree('updates_staged');
return;
@@ -291,6 +303,61 @@ 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://raw.githubusercontent.com/EQEmu/Server/master/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://raw.githubusercontent.com/EQEmu/Server/master/utils/xmltojson/xmltojson-linux-x86", "xmltojson");
print "Converting eqemu_config.xml to eqemu_config.json\n";
print `chmod 755 xmltojson`;
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->indent_length(5)->utf8->encode($result),"\n";
open(my $fh, '>', 'eqemu_config.json');
print $fh $json->pretty->indent_length(5)->utf8->encode($result);
close $fh;
mkdir('backups');
copy_file("eqemu_config.xml", "backups/eqemu_config.xml");
unlink('eqemu_config.xml');
unlink('db_dumper.pl');
print "[Server Maintenance] eqemu_config.xml is now DEPRECATED \n";
print "[Server Maintenance] eqemu_config.json is now the new Server config format \n";
print " A backup of this old config is located in the backups folder of your server directory\n";
print " --- \n";
print " You may have some plugins and/or applications that still require reference of this config file\n";
print " Please update these plugins/applications to use the new configuration format if needed\n";
print " --- \n";
print " Thanks for your understanding\n";
print " The EQEmulator Team\n\n";
exit;
}
}
sub build_linux_source {
$build_options = $_[0];
@@ -330,10 +397,10 @@ sub build_linux_source {
print "Generating CMake build files...\n";
if($os_flavor eq "fedora_core"){
print `cmake $cmake_options -DEQEMU_BUILD_LUA=ON -DLUA_INCLUDE_DIR=/usr/include/lua-5.1/ -G "Unix Makefiles" ..`;
print `cmake $cmake_options -DEQEMU_BUILD_LOGIN=ON -DEQEMU_BUILD_LUA=ON -DLUA_INCLUDE_DIR=/usr/include/lua-5.1/ -G "Unix Makefiles" ..`;
}
else {
print `cmake $cmake_options -DEQEMU_BUILD_LUA=ON -G "Unix Makefiles" ..`;
print `cmake $cmake_options -DEQEMU_BUILD_LOGIN=ON -DEQEMU_BUILD_LUA=ON -G "Unix Makefiles" ..`;
}
print "Building EQEmu Server code. This will take a while.";
@@ -352,6 +419,7 @@ sub build_linux_source {
print `ln -s -f $source_dir/Server/build/bin/ucs .`;
print `ln -s -f $source_dir/Server/build/bin/world .`;
print `ln -s -f $source_dir/Server/build/bin/zone .`;
print `ln -s -f $source_dir/Server/build/bin/loginserver .`;
}
sub do_installer_routines {
@@ -362,8 +430,8 @@ sub do_installer_routines {
mkdir('updates_staged');
mkdir('shared');
do_install_config_xml();
read_eqemu_config_xml();
do_install_config_json();
read_eqemu_config_json();
get_installation_variables();
$db_name = "peq";
@@ -579,7 +647,12 @@ sub do_self_update_check_routine {
sub get_installation_variables{
#::: Fetch installation variables before building the config
if($OS eq "Linux"){
open (INSTALL_VARS, "../install_variables.txt");
if(-e "../install_variables.txt") {
open (INSTALL_VARS, "../install_variables.txt");
}
elsif(-e "install_variables.txt") {
open (INSTALL_VARS, "./install_variables.txt");
}
}
if($OS eq "Windows"){
open (INSTALL_VARS, "install_variables.txt");
@@ -593,73 +666,51 @@ sub get_installation_variables{
close (INSTALL_VARS);
}
sub do_install_config_xml {
sub do_install_config_json {
get_installation_variables();
#::: Fetch XML template
get_remote_file($install_repository_request_url . "eqemu_config.xml", "eqemu_config_template.xml");
#::: Fetch json template
get_remote_file($install_repository_request_url . "eqemu_config.json", "eqemu_config_template.json");
#::: Open new config file
open (NEW_CONFIG, '>', 'eqemu_config.xml');
use JSON;
my $json = new JSON();
my $content;
open(my $fh, '<', "eqemu_config_template.json") or die "cannot open file $filename"; {
local $/;
$content = <$fh>;
}
close($fh);
$config = $json->decode($content);
$in_database_tag = 0;
$long_name = "Akkas " . $OS . " PEQ Installer (" . generate_random_password(5) . ')';
$config->{"server"}{"world"}{"longname"} = $long_name;
$config->{"server"}{"world"}{"key"} = generate_random_password(30);
#::: Iterate through template and replace variables...
open (FILE_TEMPLATE, "eqemu_config_template.xml");
while (<FILE_TEMPLATE>){
chomp;
$o = $_;
#::: Find replace variables
if($o=~/\<\!--/i){
next;
}
if($o=~/database/i && $o=~/\<\//i){
$in_database_tag = 0;
}
if($o=~/database/i){
$in_database_tag = 1;
}
if($o=~/key/i){
my($replace_key) = $o =~ />(\w+)</;
$new_key = generate_random_password(30);
$o =~ s/$replace_key/$new_key/g;
}
if($o=~/\<longname\>/i){
my($replace_name) = $o =~ /<longname>(.*)<\/longname>/;
$append = '(' . generate_random_password(5) . ')';
$o =~ s/$replace_name/Akkas $OS PEQ Installer $append/g;
}
if($o=~/\<username\>/i && $in_database_tag){
my($replace_username) = $o =~ />(\w+)</;
$o =~ s/$replace_username/$installation_variables{"mysql_eqemu_user"}/g;
}
if($o=~/\<password\>/i && $in_database_tag){
my($replace_password) = $o =~ />(\w+)</;
$o =~ s/$replace_password/$installation_variables{"mysql_eqemu_password"}/g;
}
if($o=~/\<db\>/i){
my($replace_db_name) = $o =~ />(\w+)</;
#::: There is really no reason why this shouldn't be set
if($installation_variables{"mysql_eqemu_db_name"}){
$db_name = $installation_variables{"mysql_eqemu_db_name"};
}
else {
$db_name = "peq";
}
$o =~ s/$replace_db_name/$db_name/g;
}
print NEW_CONFIG $o . "\n";
if($installation_variables{"mysql_eqemu_db_name"}){
$db_name = $installation_variables{"mysql_eqemu_db_name"};
}
else {
$db_name = "peq";
}
close(FILE_TEMPLATE);
close(NEW_CONFIG);
unlink("eqemu_config_template.xml");
$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"}{"username"} = $installation_variables{"mysql_eqemu_user"};
$config->{"server"}{"qsdatabase"}{"password"} = $installation_variables{"mysql_eqemu_password"};
$config->{"server"}{"qsdatabase"}{"db"} = $db_name;
$json->canonical(1);
$json->indent_length(5);
open(my $fh, '>', 'eqemu_config.json');
print $fh $json->pretty->indent_length(5)->utf8->encode($config);
close $fh;
unlink("eqemu_config_template.json");
}
sub fetch_utility_scripts {
@@ -766,6 +817,7 @@ sub show_menu_prompt {
elsif($input eq "setup_loginserver"){ do_windows_login_server_setup(); $dc = 1; }
elsif($input eq "new_server"){ new_server(); $dc = 1; }
elsif($input eq "setup_bots"){ setup_bots(); $dc = 1; }
elsif($input eq "linux_login_server_setup"){ do_linux_login_server_setup(); $dc = 1; }
elsif($input eq "exit"){
exit;
}
@@ -858,13 +910,13 @@ sub check_for_database_dump_script{
return;
}
#::: Check for script changes :: db_dumper.pl
get_remote_file($eqemu_repository_request_url . "utils/scripts/db_dumper.pl", "updates_staged/db_dumper.pl", 0, 1, 1);
#::: 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/db_dumper.pl") {
if(-e "updates_staged/database_dumper.pl") {
my $remote_script_size = -s "updates_staged/db_dumper.pl";
my $local_script_size = -s "db_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";
@@ -876,14 +928,14 @@ sub check_for_database_dump_script{
$start_dir
);
for my $file (@files) {
if($file=~/db_dumper/i){
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 db_dumper.pl");
system("chmod 755 database_dumper.pl");
}
}
}
@@ -893,7 +945,7 @@ sub check_for_database_dump_script{
print "[Update] No script update necessary...\n";
}
unlink("updates_staged/db_dumper.pl");
unlink("updates_staged/database_dumper.pl");
}
return;
@@ -903,7 +955,7 @@ sub check_for_database_dump_script{
sub database_dump {
check_for_database_dump_script();
print "[Database] Performing database backup....\n";
print `perl db_dumper.pl database="$db" loc="backups"`;
print `perl database_dumper.pl database="$db" loc="backups"`;
}
sub database_dump_player_tables {
@@ -921,7 +973,7 @@ sub database_dump_player_tables {
}
$tables = substr($tables, 0, -1);
print `perl db_dumper.pl database="$db" loc="backups" tables="$tables" backup_name="player_tables_export" nolock`;
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";
@@ -932,7 +984,7 @@ sub database_dump_player_tables {
sub database_dump_compress {
check_for_database_dump_script();
print "[Database] Performing database backup....\n";
print `perl db_dumper.pl database="$db" loc="backups" compress`;
print `perl database_dumper.pl database="$db" loc="backups" compress`;
}
sub script_exit{
@@ -1008,7 +1060,7 @@ sub get_remote_file{
}
#::: wget -O db_update/db_update_manifest.txt https://raw.githubusercontent.com/EQEmu/Server/master/utils/sql/db_update_manifest.txt
$wget = `wget -N --no-check-certificate --quiet -O $destination_file $request_url`;
$wget = `wget -N --cache=no --no-check-certificate --quiet -O $destination_file $request_url`;
print "[Download] Saved: (" . $destination_file . ") from " . $request_url . "\n" if !$silent_download;
if($wget=~/unable to resolve/i){
print "Error, no connection or failed request...\n\n";
@@ -1072,6 +1124,26 @@ sub read_eqemu_config_xml {
close(CONFIG);
}
sub read_eqemu_config_json {
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);
$config = $json->decode($content);
$db = $config->{"server"}{"database"}{"db"};
$host = $config->{"server"}{"database"}{"host"};
$user = $config->{"server"}{"database"}{"username"};
$pass = $config->{"server"}{"database"}{"password"};
}
#::: Fetch Latest PEQ AA's
sub aa_fetch{
if(!$db){
@@ -1277,6 +1349,8 @@ sub do_windows_login_server_setup {
sub do_linux_login_server_setup {
build_linux_source();
for my $file (@files) {
$destination_file = $file;
$destination_file =~s/updates_staged\/login_server\///g;
@@ -1297,6 +1371,8 @@ sub do_linux_login_server_setup {
get_remote_file($install_repository_request_url . "linux/login.ini", "login_template.ini");
get_remote_file($install_repository_request_url . "linux/login_opcodes.conf", "login_opcodes.conf");
get_remote_file($install_repository_request_url . "linux/login_opcodes_sod.conf", "login_opcodes_sod.conf");
get_remote_file($install_repository_request_url . "linux/server_start_with_login.sh", "server_start_with_login.sh");
system("chmod 755 *.sh");
get_installation_variables();
my $db_name = $installation_variables{"mysql_eqemu_db_name"};
+2 -1
View File
@@ -119,6 +119,7 @@ if [[ "$OS" == "Debian" ]]; then
apt-get $apt_options install zlibc
apt-get $apt_options install libsodium-dev
apt-get $apt_options install libsodium18
apt-get $apt_options install libjson-perl
# If libsodium18 isn't installed (Debian), let's download both that and the dev package and install them.
if dpkg-query -s "libsodium18" 1>/dev/null 2>&1; then
@@ -159,7 +160,7 @@ EOF
# Install prereqs
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install deltarpm
yum -y install open-vm-tools vim cmake boost-* zlib-devel mariadb-server mariadb-client mariadb-devel mariadb-libs mariadb-compat perl-* lua* dos2unix php-mysql proftpd
yum -y install open-vm-tools vim cmake boost-* zlib-devel mariadb-server mariadb-client mariadb-devel mariadb-libs mariadb-compat perl-* lua* dos2unix php-mysql proftpd libuuid-devel
yum -y groupinstall "Development Tools" "Basic Web Server" "Compatibility Libraries"
elif [[ "$OS" == "fedora_core" ]]; then
+1 -2
View File
@@ -17,7 +17,6 @@ character_bind
character_corpses
character_corpse_items
character_languages
character_lookup
character_skills
character_spells
character_memmed_spells
@@ -89,4 +88,4 @@ spell_globals
timers
trader
trader_audit
zone_flags
zone_flags
+2
View File
@@ -0,0 +1,2 @@
eqemu_config.xml
eqemu_config.json
+1
View File
@@ -0,0 +1 @@
Converts the old eqemu_config.xml to eqemu_config.json
+21
View File
@@ -0,0 +1,21 @@
@echo off
setlocal
set name="xmltojson"
echo Building Linux
set GOOS=linux
set GOARCH=amd64
go build -o %name%-linux-x64 main.go
set GOARCH=386
go build -o %name%-linux-x86 main.go
echo Building Windows
set GOOS=windows
set GOARCH=amd64
go build -o %name%-windows-x64.exe main.go
set GOARCH=386
go build -o %name%-windows-x86.exe main.go
echo Building OSX
REM set GOOS=darwin
REM set GOARCH=amd64
REM go build -o %name%-osx-x64 main.go
endlocal
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
set -e
export NAME="xmltojson"
echo Building Linux
GOOS=linux GOARCH=amd64 go build -o $NAME-linux-x64 main.go
GOOS=linux GOARCH=386 go build -o $NAME-linux-x86 main.go
echo Building Windows
GOOS=windows GOARCH=amd64 go build -o $NAME-windows-x64.exe main.go
GOOS=windows GOARCH=386 go build -o $NAME-windows-x86.exe main.go
#echo Building OSX
#GOOS=darwin GOARCH=amd64 go build -o $NAME-osx-x64 main.go
+85
View File
@@ -0,0 +1,85 @@
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
xj "github.com/basgys/goxml2json"
)
func main() {
var err error
var data []byte
var sData string
buf := &bytes.Buffer{}
var buf2 bytes.Buffer
if data, err = ioutil.ReadFile("eqemu_config.xml"); err != nil {
fmt.Println("Failed to open eqemu_config.xml:", err.Error())
os.Exit(1)
}
//detect malformed xml in eqemuconfig
sData = strings.Replace(string(data), "<?xml version=\"1.0\">", "<?xml version=\"1.0\"?>", 1)
r := strings.NewReader(sData)
dec := xj.NewDecoder(r)
root := &xj.Node{}
if err = dec.DecodeWithCustomPrefixes(root, "", ""); err != nil {
fmt.Println("Failed to decode eqemu_config.xml:", err.Error())
os.Exit(1)
}
if root.Children["server"] == nil || len(root.Children["server"]) < 1 {
fmt.Println("Server element not found")
os.Exit(1)
}
server := root.Children["server"][0]
//locked: "true" is only way to trigger locked
if server.Children["world"] != nil && len(server.Children["world"]) > 0 {
world := server.Children["world"][0]
if world.Children["locked"] != nil && len(world.Children["locked"]) > 0 {
fmt.Println("Locked!")
world.Children["locked"][0].Data = "true"
}
}
elements := []string{
"chatserver",
"directories",
"files",
"launcher",
"mailserver",
"webinterface",
"world",
"zones",
}
for _, ele := range elements {
if server.Children[ele] != nil && len(server.Children[ele]) > 0 && len(server.Children[ele][0].Children) == 0 {
delete(server.Children, ele)
}
}
enc := xj.NewEncoder(buf)
err = enc.EncodeWithCustomPrefixes(root, "", "")
if err != nil {
fmt.Println("Failed to encode eqemu_config.xml:", err.Error())
os.Exit(1)
}
//prettyprint
if err = json.Indent(&buf2, buf.Bytes(), "", "\t"); err != nil {
fmt.Println("Failed to encode json:", err.Error())
os.Exit(1)
}
if err = ioutil.WriteFile("eqemu_config.json", buf2.Bytes(), 0744); err != nil {
fmt.Println("Failed to write eqemu_config.json:", err.Error())
os.Exit(1)
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.