M2 Download Center
Download Here ( Internal )
hi guys! i've recently created converter to item_proto, 2 sides XML->SQL and SQL->XML in PHP, i know it could be written better, but it works, that's the point right?
XML->SQL:
<?php
header('Content-Type: text/html; charset=utf-8');
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$handle = 'item_proto.sql';
exec('echo '' > '.$handle.' && chmod 777 '.$handle);
$file = fopen("item_proto.xml", "r");
if(!$file){
die("where is item_proto.xml?");
}
while($line = fgets($file)){
if(strpos($line, "ItemProto"))
continue;
$line = explode("" ", $line);
$insert = Array();
foreach($line as $lineExploded){
$lineExploded = substr($lineExploded, strpos($lineExploded, """) + 1);
$insert[] = $lineExploded;
}
$set = Array("vnum", "name", "locale_name", "type", "subtype", "weight", "size", "antiflag", "flag", "wearflag", "immuneflag", "gold", "shop_buy_price", "limittype0", "limitvalue0", "limittype1", "limitvalue1", "applytype0", "applyvalue0", "applytype1", "applyvalue1", "applytype2", "applyvalue2", "value0", "value1", "value2", "value3", "value4", "value5", "socket0", "socket1", "socket2", "refined_vnum", "refine_set", "magic_pct","specular", "socket_pct", "addon_type");
$values = "SET ";
for($i = 0; $i < count($insert); $i++){
if(count($insert) - 1 == $i){
$values .= '`'.$set[$i].'`=''.substr($insert[$i], 0, 1).'';';
} else {
$values .= '`'.$set[$i].'`=''.$insert[$i].'', ';;
}
}
file_put_contents($handle, "INSERT INTO `player`.`item_proto` {$values} n", FILE_APPEND | LOCK_EX);
}
echo 'item_proto.sql ready and steady, my friend!';
SQL->XML
<?php
header('Content-Type: text/html; charset=utf-8');
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$mysqli = new mysqli("localhost", "user", "passwd", "player");
if ($mysqli->connect_error) {
die("and u think that mysql data is ok?");
}
$handle = 'item_proto.xml';
exec('echo '' > '.$handle.' && chmod 777 '.$handle);
file_put_contents($handle, "<ItemProto Version="1">n", FILE_APPEND | LOCK_EX);
$andrw = $mysqli->query("SELECT * from `player`.`item_proto`");
while($data = $andrw->fetch_array()){
$converted = "<ItemDef Vnum="{$data['vnum']}" Name="{$data['vnum']}" LocalizedName="{$data['locale_name']}" Type="{$data['type']}" SubType="{$data['subtype']}" Weight="{$data['weight']}" Size="{$data['size']}" AntiFlags="{$data['antiflag']}" Flags="{$data['flag']}" WearFlags="{$data['wearflag']}" ImmuneFlags="{$data['immuneflag']}" Gold="{$data['gold']}" ShopBuyPrice="{$data['shop_buy_price']}" LimitType0="{$data['limittype0']}" LimitValue0="{$data['limitvalue0']}" LimitType1="{$data['limittype1']}" LimitValue1="{$data['limitvalue1']}" ApplyType0="{$data['applytype0']}" ApplyValue0="{$data['applyvalue0']}" ApplyType1="{$data['applytype1']}" ApplyValue1="{$data['applyvalue2']}" ApplyType2="{$data['applytype2']}" ApplyValue2="{$data['applyvalue2']}" Value0="{$data['value0']}" Value1="{$data['value1']}" Value2="{$data['value2']}" Value3="{$data['value3']}" Value4="{$data['value4']}" Value5="{$data['value5']}" Socket0="{$data['socket0']}" Socket1="{$data['socket1']}" Socket2="{$data['socket2']}" RefinedVnum="{$data['refined_vnum']}" RefineSet="{$data['refine_set']}" AlterToMagicItemPercent="{$data['magic_pct']}" Specular="{$data['specular']}" GainSocketPercent="{$data['socket_pct']}" AddonType="{$data['addon_type']}" />n";
file_put_contents($handle, $converted, FILE_APPEND | LOCK_EX);
}
file_put_contents($handle, "</ItemProto>", FILE_APPEND | LOCK_EX);
echo 'item_proto.sql ready and steady mr Captain!!';