diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-08-16 07:17:35 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-08-16 07:17:35 +0000 |
commit | c4803c50bc6a9e67c0c8e9c07d546666d08af8c9 (patch) | |
tree | f5a48411a42cfbecac39f8db246202f784131788 | |
parent | c45fbd0aa6d806e833e9a9d7e84442ec8a31ce00 (diff) | |
download | hercules-c4803c50bc6a9e67c0c8e9c07d546666d08af8c9.tar.gz hercules-c4803c50bc6a9e67c0c8e9c07d546666d08af8c9.tar.bz2 hercules-c4803c50bc6a9e67c0c8e9c07d546666d08af8c9.tar.xz hercules-c4803c50bc6a9e67c0c8e9c07d546666d08af8c9.zip |
Added a mapreg txt->sql converter script to /tools, because the sql mapserver doesn't read the txt mapreg savefile anymore and people will most likely want to preserve their global variables.
The script is php-based and requires the php_mysql module.
The script produces a series of INSERT statements, ready to be imported to the database.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13086 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r-- | Changelog-Trunk.txt | 6 | ||||
-rw-r--r-- | tools/mapreg-converter.php | 38 |
2 files changed, 44 insertions, 0 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index f1932113e..41abbfb9f 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -3,6 +3,12 @@ Date Added AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. +2008/08/16 + * Added a mapreg txt->sql converter script to /tools, because the sql + mapserver doesn't read the txt mapreg savefile anymore and people + will most likely want to preserve their global variables. + - script is php-based and requires the php_mysql module + - script produces a series of INSERT statements, ready to be imported 2008/08/15 * Split off mapreg code from script.c [ultramage] - new mapserver files, mapreg.h, mapreg_txt.c, mapreg_sql.c diff --git a/tools/mapreg-converter.php b/tools/mapreg-converter.php new file mode 100644 index 000000000..3d548554a --- /dev/null +++ b/tools/mapreg-converter.php @@ -0,0 +1,38 @@ +<?php + // mapreg.txt -> sql import file converter + // author : theultramage / Yommy + // version: 16. august 2008 +?> +<?php + fwrite(STDERR, "mapreg txt->sql converter".PHP_EOL); + fwrite(STDERR, "-------------------------".PHP_EOL); + if( @$_SERVER["argc"] < 2 ) + { + fwrite(STDERR, "Usage: {$_SERVER["argv"][0]} [file]".PHP_EOL); + exit(); + } + + $input = @$_SERVER["argv"][1]; + $data = file($input); + if( $data === FALSE ) + die("Invalid input file '".$input."'!"); + + if( function_exists("mysql_escape_string") === FALSE ) + die("Please enable the php_mysql extension first!"); + + fwrite(STDERR, "Converting {$input}...".PHP_EOL); + define("EOL", PHP_EOL); + + foreach( $data as $line ) + { + if( preg_match('/(.*),(\d+)\t(.*)/m', $line, $regs) ) + fwrite(STDOUT, "INSERT INTO `mapreg` (`varname`,`index`,`value`) VALUES ('".mysql_escape_string($regs[1])."',".mysql_escape_string($regs[2]).",'".mysql_escape_string(rtrim($regs[3]))."');".EOL); + else + if( preg_match('/(.*)\t(.*)/m', $line, $regs) ) + fprintf(STDOUT, "INSERT INTO `mapreg` (`varname`,`index`,`value`) VALUES ('".mysql_escape_string($regs[1])."',0,'".mysql_escape_string(rtrim($regs[2]))."');".EOL); + else + fprintf(STDERR, "Invalid data: ".$line.PHP_EOL); + } + + fprintf(STDERR, "done.".PHP_EOL); +?>
\ No newline at end of file |