Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function updateSchama($itemGameFile, $sqlServer)
- {
- $itemReg = '/"items"/';
- $numberReg = '/\d+/';
- $textReg = '/[a-zA-Z_]+/';
- $nameReg = '/"name"/';
- $nameDataReg = '/"([^"]*)".*?("([^"]*)")/';
- $nameRegInvalidate = '/"name"\s+["]#+/';
- $itemslotReg = '/"item_slot"/';
- $slotDataReg = '/"([^"]*)".*?("([^"]*)")/';
- $rarityReg = '/"item_rarity"/';
- $rarityDataReg = '/"([^"]*)".*?("([^"]*)")/';
- $prefabReg = '/"prefab"/';
- $prefabDataReg = '/"([^"]*)".*?("([^"]*)")/';
- $heroReg = '/"used_by_heroes"/';
- $styleReg = '/"styles"/';
- $altIconReg = '/"alternate_icons"/';
- $rikiDaggerReg = '/"Riki\'s Dagger"/';
- $primevalReg ='/"Primeval Beard"/';
- $qurybuilder = "REPLACE INTO schemaData (itemType, Hero, Slot, Rarity, Name) VALUES ";
- $match;
- $lastNum = 0;
- $idValue = 0;
- $nameValue = "Riki's Dagger";
- $heroValue = "npc_dota_hero_riki";
- $slotValue = "weapon";
- $rarityValue = "common";
- $StyleBool = false;
- $playercardbool = false;
- $processLine = fgets($itemGameFile);
- while (preg_match ( '/"items"/', $processLine) == 0)
- {
- $processLine = fgets($itemGameFile);
- }
- //Parses the Item Game file (This thing has so many tiny hacks in it with that style bool, I think the final break is all
- //inclsive and I could take the others out, to do maybe another time)
- while (($processLine = fgets($itemGameFile)) !== false)
- {
- if (preg_match ( $nameReg, $processLine) == 1) //parse name, put last entry onto qury queue
- {
- if (preg_match ( $primevalReg, $processLine) == 1)
- {
- $StyleBool = false;
- }
- if ($idValue > $lastNum || $StyleBool == true || preg_match($nameRegInvalidate, $processLine) == true)
- {
- echo $idValue.' > '.$lastNum.PHP_EOL." ".$StyleBool." "."<BR>";
- if (preg_match ($rikiDaggerReg, $processLine) == 1)
- {
- $idValue = 0;
- }
- }
- else if ($playercardbool == true)
- {
- $playercardbool = false;
- }
- else
- {
- echo $idValue."<BR>";
- $qurybuilder.= "(\"$idValue\",\"$heroValue\",\"$slotValue\",\"$rarityValue\",\"$nameValue\"), ";
- preg_match ( $nameDataReg, $processLine, $match);
- $idValue = $lastNum;
- $nameValue = $match[2];
- $nameValue = trim($nameValue, '" ');
- }
- }
- if (preg_match ( $numberReg, $processLine) == 1) //Parse item ID Number
- {
- preg_match ( $numberReg, $processLine, $match);
- $lastNum = $match[0];
- //echo $lastNum.PHP_EOL."<BR>";
- }
- if (preg_match ( $prefabReg, $processLine) == 1) //Defalut some data based on prefrab type
- {
- $rarityValue = "common";
- $heroValue = "player";
- $slotValue = "none";
- preg_match ( $prefabDataReg, $processLine, $match);
- $prefabtype = $match[2];
- $prefabtype = trim($prefabtype, '" ');
- if ($prefabtype == "wearable" || $prefabtype == "default_item")
- {
- $slotValue = "weapon";
- }
- else if ( $prefabtype == "player_card" )
- {
- $playercardbool = true;
- }
- else
- {
- $slotValue = $prefabtype;
- }
- }
- if (preg_match ( $itemslotReg, $processLine) == 1) //Parse item slot info
- {
- preg_match ( $slotDataReg, $processLine, $match);
- $slotValue = $match[2];
- $slotValue = trim($slotValue, '" ');
- //echo $slotValue."<BR>";
- }
- if (preg_match ( $rarityReg, $processLine) == 1) //Parse Rarity Info
- {
- preg_match ( $rarityDataReg, $processLine, $match);
- $rarityValue = $match[2];
- $rarityValue = trim($rarityValue, '" ');
- }
- if (preg_match ( $heroReg, $processLine) == 1) //Parse Hero Info
- {
- if (preg_match ( $numberReg, $processLine) == 0)
- {
- $processLine = fgets($itemGameFile);
- $processLine = fgets($itemGameFile);
- preg_match ( $textReg, $processLine, $match);
- $heroValue = $match[0];
- }
- }
- if (preg_match ( $styleReg, $processLine) == 1)
- {
- $StyleBool = true;
- }
- if (preg_match ( $altIconReg , $processLine) == 1)
- {
- $StyleBool = false;
- }
- if (preg_match ('/"item_sets"/', $processLine) == 1)
- {
- break;
- }
- }
- $qurybuilder.= "(\"$idValue\",\"$heroValue\",\"$slotValue\",\"$rarityValue\",\"$nameValue\"), ";
- $qurybuilder = rtrim($qurybuilder, ', ');
- //Used to check run time of script
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $starttime2 = $mtime;
- mysqli_query($sqlServer,$qurybuilder);
- //echo "<BR />".PHP_EOL;
- //echo $qurybuilder;
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $endtime2 = $mtime;
- $totaltime2 = ($endtime2 - $starttime2);
- echo "Main Qury Time: ".$totaltime2.PHP_EOL;
- echo $lastNum;
- $quryfix = 'UPDATE schemaData set name = "Name Tag" where itemType = 15000';
- mysqli_query($sqlServer,$quryfix);
- }
- function updateImages($itemGameFile, $sqlServer)
- {
- //Gets the Image URl's from the Item Schema
- $itemReg = '/"items"/';
- $numberReg = '/\d+/';
- $defReg = '/"defindex"/';
- $imagReg = '/"image_url"/';
- $DataReg = '/"([^"]*)".*?("([^"]*)")/';
- $itemID;
- $urlValue;
- $match;
- $processLine = fgets($itemGameFile);
- while (preg_match ( '/"items"/', $processLine) == 0)
- {
- $processLine = fgets($itemGameFile);
- }
- while (($processLine = fgets($itemGameFile)) !== false)
- {
- if (preg_match ( $defReg, $processLine) == 1) //Parse for item ID info
- {
- preg_match ( $numberReg, $processLine, $match);
- $itemID = $match[0];
- }
- if (preg_match ( $imagReg, $processLine) == 1) //Parse for image url info and put in to database
- {
- preg_match ( $DataReg, $processLine, $match);
- $urlValue = $match[2];
- //echo $urlValue."<BR>";
- $urlValue = trim($urlValue, '" ');
- $qury = 'UPDATE schemaData set Image = "'.$urlValue.'" where itemType = '.$itemID;
- mysqli_query($sqlServer,$qury);
- //echo $qury."<BR>".PHP_EOL;
- }
- }
- }
- function updateSchema_v2 ($itemGameFile, $sqlServer)
- {
- //Bunch of Regular Expressions used in parsing are defined here. Something tells me I'm doing this a bad way, but it got done.
- $itemReg = '/"items"/';
- $itemSingleReg = '/"item"/';
- $itemSetReg = '/"item_sets"/';
- $numberReg = '/\d+/';
- $textReg = '/[a-zA-Z_]+/';
- $nameReg = '/"name"/';
- $nameDataReg = '/"([^"]*)".*?("([^"]*)")/';
- $nameRegInvalidate = '/"name"\s+["]#+/';
- $itemslotReg = '/"item_slot"/';
- $slotDataReg = '/"([^"]*)".*?("([^"]*)")/';
- $rarityReg = '/"item_rarity"/';
- $rarityDataReg = '/"([^"]*)".*?("([^"]*)")/';
- $prefabReg = '/"prefab"/';
- $prefabDataReg = '/"([^"]*)".*?("([^"]*)")/';
- $bundleReg = '/"bundle"/';
- $priceInfoReg = '/"price_info"/';
- $priceReg = '/"price"/';
- $heroReg = '/"used_by_heroes"/';
- $styleReg = '/"styles"/';
- $altIconReg = '/"alternate_icons"/';
- $rikiDaggerReg = '/"Riki\'s Dagger"/';
- $primevalReg ='/"Primeval Beard"/';
- $staticAttReg ='/"static_attributes"/';
- $attrabuteClassReg = '/"static_attributes"/';
- $additonalDropReg = '/"additional_drop"/';
- $additonalGemsReg = '/"add_random_gems"/';
- $additonalSocketReg = '/"add_empty_socket"/';
- $lootListReg = '/"loot_lists"/';
- $lootlistSingleReg = '/"loot_list"/';
- $betweenQuoteReg = '/"([^"]*)"/';
- $bonusReg = '/"bonus_itemdefs"/';
- $openParenReg ='/\{/';
- $closeParenReg ='/\}/';
- $qurybuilder = "INSERT INTO schemaData (itemType, Hero, Slot, Rarity, Name) VALUES ";
- $setBuilder = "REPLACE INTO SetInfo (SetIDNumber, SetName, ItemName) VALUES ";
- $priceBuilder = "INSERT INTO PriceData (itemID, StorePrice) VALUES ";
- $attrabuteBuilder = "INSERT INTO staticAttributes (itemType, staticAttributeClass, staticAttributeValue) VALUES ";
- $lootListBuilder ="INSERT INTO LootLists (ListName,ItemName) VALUES ";
- $bonusListBuilder ="INSERT INTO bonusDrops (SourceItemID,DropItemID) VALUES ";
- $match;
- $lastNum = 0;
- $idValue = 0;
- $nameValue = "Riki's Dagger";
- $heroValue = "npc_dota_hero_riki";
- $slotValue = "weapon";
- $rarityValue = "common";
- $StyleBool = false;
- $playercardbool = false;
- $processLine = fgets($itemGameFile);
- while (preg_match ( '/"items"/', $processLine) == 0)
- {
- $processLine = fgets($itemGameFile);
- }
- $processLine = fgets($itemGameFile); //Consume the first open parenthese of the block we are looking at
- //Parses the Item Game file (This thing has so many tiny hacks in it with that style bool, I think the final break is all
- //inclsive and I could take the others out, to do maybe another time)
- //This while loop will parse the item definition out of the schema
- while (($processLine = fgets($itemGameFile)) !== false)
- {
- if (preg_match( $itemSetReg, $processLine) == true) break; //Get out of while loop once we go past the definitions of the items
- //echo $processLine;
- if (preg_match ( $numberReg, $processLine, $match) == 1)
- {
- $idValue = $match[0];
- //if ($idValue == 13) return;
- //Set default values;
- $heroValue = "player";
- //$heroValue = "npc_dota_hero_riki";
- $slotValue = "weapon";
- $rarityValue = "common";
- $processLine = fgets($itemGameFile); //Get next line, should be open brackets
- if (preg_match ( $openParenReg, $processLine) == 1)
- {
- //echo $idValue.PHP_EOL;
- $processLine = fgets($itemGameFile);
- $bracketCount = 1;
- //echo $processLine;
- while ($bracketCount > 0 && feof($itemGameFile) == false )
- {
- //echo $processLine;
- //This set of if statements sort of emulates a switch case
- if (preg_match ( $nameReg, $processLine) == 1 && $bracketCount == 1) //Capture item name
- {
- preg_match ( $nameDataReg, $processLine, $match);
- $nameValue = $match[2];
- $nameValue = trim($nameValue, '" ');
- $processLine = fgets($itemGameFile);
- continue;
- }
- //Default to common
- if (preg_match ( $rarityReg, $processLine) == 1 && $bracketCount == 1) //Parse Rarity Info
- {
- preg_match ( $rarityDataReg, $processLine, $match);
- $rarityValue = $match[2];
- $rarityValue = trim($rarityValue, '" ');
- $processLine = fgets($itemGameFile);
- continue;
- }
- //Get the item slot. If there is no item slot, get the info from the prefab
- if (preg_match ( $itemslotReg, $processLine) == 1 && $bracketCount == 1)
- {
- preg_match ( $slotDataReg, $processLine, $match);
- $slotValue = $match[2];
- $slotValue = trim($slotValue, '" ');
- $processLine = fgets($itemGameFile);
- continue;
- }
- //The prefab to get slot info from
- if (preg_match ( $prefabReg, $processLine) == 1 && $bracketCount == 1)
- {
- preg_match ( $prefabDataReg, $processLine, $match);
- $prefabtype = $match[2];
- $prefabtype = trim($prefabtype, '" ');
- $slotValue = $prefabtype;
- $processLine = fgets($itemGameFile);
- continue;
- }
- //Get Price info
- if (preg_match ( $priceInfoReg, $processLine) == 1 && $bracketCount == 1)
- {
- //echo "IN PRICE INFO BLOCK";
- //echo $processLine;
- $processLine = fgets($itemGameFile);
- if(preg_match ( $openParenReg, $processLine) == 1)//We are now in the block of text with bundle info, gather info.
- {
- //echo "price".PHP_EOL;
- while(preg_match ( $closeParenReg, $processLine) == 0)
- {
- $processLine = fgets($itemGameFile);
- if(preg_match ( $priceReg, $processLine) == 1)
- {
- preg_match ( $numberReg, $processLine, $match);
- $pricePoint = $match[0];
- $pricePoint = $pricePoint / 100; //Yeah, prices are stored as ints in the schema. Hope this doesn't cause any floating point error!
- $priceBuilder .= "(\"$idValue\",\"$pricePoint\"), ";
- //echo "(\"$idValue\",\"$pricePoint\"), ";
- }
- }
- }
- $processLine = fgets($itemGameFile);
- continue;
- }
- //Get Bonus Drop info
- if (preg_match ( $bonusReg, $processLine) == 1)
- {
- $processLine = fgets($itemGameFile);
- if(preg_match ( $openParenReg, $processLine) == 1)//We are now in the block of text with bundle info, gather info.
- {
- while(preg_match ( $closeParenReg, $processLine) == 0)
- {
- $processLine = fgets($itemGameFile);
- if(preg_match ( $numberReg, $processLine) == 1)
- {
- preg_match ( $numberReg, $processLine, $match);
- $bundleID = $match[0];
- $bonusListBuilder .= "(\"$idValue\",\"$bundleID\"), ";
- //echo "(\"$idValue\",\"$pricePoint\"), ";
- }
- }
- }
- $processLine = fgets($itemGameFile);
- continue;
- }
- //Get Attributes
- if (preg_match ( $staticAttReg, $processLine) == 1 && $bracketCount == 1)
- {
- $processLine = fgets($itemGameFile);
- if(preg_match ( $openParenReg, $processLine) == 1)//We are now in the block of text with bundle info, gather info.
- {
- $attBracketCount = 1;
- //echo "price".PHP_EOL;
- while($attBracketCount > 0)
- {
- $processLine = fgets($itemGameFile);
- if(preg_match ( $openParenReg, $processLine) == 1)
- {
- $attBracketCount++;
- //Get Attribute name
- $processLine = fgets($itemGameFile);
- preg_match ( $nameDataReg, $processLine, $match);
- $attName = $match[2];
- $attName = trim($attName, '" ');
- //Get Attribute value
- $processLine = fgets($itemGameFile);
- preg_match ( $nameDataReg, $processLine, $match);
- $attValue = $match[2];
- $attValue = trim($attValue, '" ');
- //Concatenate onto query
- $attrabuteBuilder .= "(\"$idValue\",\"$attName\",\"$attValue\"), ";
- continue;
- }
- if(preg_match ( $closeParenReg, $processLine) == 1)
- {
- $attBracketCount--;
- }
- }
- }
- $processLine = fgets($itemGameFile);
- continue;
- }
- //Parse out details on bundle
- if(preg_match ( $bundleReg, $processLine) == 1 && $bracketCount == 1)//bundle
- {
- //echo "Bundle".PHP_EOL;
- $processLine = fgets($itemGameFile);
- if(preg_match ( $bundleReg, $processLine) == 1) //Usually it will go the bundle prefab, then the bundle block, so if it does get the line to the right spot.
- {
- $processLine = fgets($itemGameFile);
- }
- if(preg_match ( $openParenReg, $processLine) == 1)//We are now in the block of text with bundle info, gather info.
- {
- $processLine = fgets($itemGameFile);
- while(preg_match ( $closeParenReg, $processLine) == 0)
- {
- preg_match ( $nameDataReg, $processLine, $match);
- //echo $processLine;
- $itemNameValue = $match[1];
- $setBuilder .= "(\"$idValue\",\"$nameValue\",\"$itemNameValue\"), ";
- $processLine = fgets($itemGameFile);
- }
- }
- $processLine = fgets($itemGameFile);
- continue;
- }
- //Parse Hero Info
- if (preg_match ( $heroReg, $processLine) == 1 && $bracketCount == 1)
- {
- //echo "hero";
- if (preg_match ( $numberReg, $processLine) == 0)
- {
- $processLine = fgets($itemGameFile);
- //echo $processLine;
- $processLine = fgets($itemGameFile);
- //echo $processLine;
- preg_match ( $textReg, $processLine, $match);
- $heroValue = $match[0];
- $processLine = fgets($itemGameFile);
- $processLine = fgets($itemGameFile);
- //echo $heroValue;
- }
- else
- {
- $heroValue = "player";
- $processLine = fgets($itemGameFile);
- }
- //sleep(1);
- continue;
- }
- //Maintain bracket count
- if (preg_match ( $openParenReg, $processLine) == 1)
- {
- $bracketCount++;
- if (preg_match ( $closeParenReg, $processLine) == 1)
- {
- $bracketCount--;
- }
- $processLine = fgets($itemGameFile);
- continue;
- }
- if (preg_match ( $closeParenReg, $processLine) == 1)
- {
- $bracketCount--;
- if ($bracketCount != 0)
- {
- $processLine = fgets($itemGameFile);
- }
- //echo $bracketCount;
- continue;
- }
- /*
- //Catch unknown or unneeded block of text
- if (preg_match ( $openParenReg, $processLine) == 1)
- {
- echo "IN UNKNOWN BLCOK".PHP_EOL;
- $bracktCount = 1;
- //echo "$bracktCount".PHP_EOL;
- while (preg_match ( $closeParenReg, $processLine) == 0 && $bracktCount > 0)
- {
- $processLine = fgets($itemGameFile);
- echo $processLine;
- if (preg_match ( $openParenReg, $processLine) == 1)
- {
- $bracktCount++;
- }
- if (preg_match ( $closeParenReg, $processLine) == 1)
- {
- $bracktCount--;
- }
- //echo $bracktCount;
- }
- $processLine = fgets($itemGameFile);
- echo $processLine;
- echo "EXITING UNKOWN BLOCK".PHP_EOL;
- continue;
- }
- */
- $processLine = fgets($itemGameFile);
- }
- //echo "(\"$idValue\",\"$heroValue\",\"$slotValue\",\"$rarityValue\",\"$nameValue\"), ";
- //sleep (1);
- $qurybuilder.= "(\"$idValue\",\"$heroValue\",\"$slotValue\",\"$rarityValue\",\"$nameValue\"), ";
- //echo "entry logged".PHP_EOL;
- //echo $processLine;
- }
- }
- }
- //this part will get the loots lists
- while (($processLine = fgets($itemGameFile)) !== false)
- {
- //Advance file to proper location
- while (preg_match ( $lootListReg, $processLine) == 0 && feof($itemGameFile) == false)
- {
- $processLine = fgets($itemGameFile);
- }
- $processLine = fgets($itemGameFile);
- if (preg_match ( $openParenReg, $processLine) == 1)
- {
- echo "Scanning Loot Lists".PHP_EOL;
- //echo $idValue.PHP_EOL;
- $processLine = fgets($itemGameFile);
- $bracketCount = 1;
- while ($bracketCount > 0)
- {
- //If it hits a list of items to parse out
- if (preg_match ( $betweenQuoteReg, $processLine) == 1 && $bracketCount == 1)
- {
- //Get the lists name
- preg_match ( $betweenQuoteReg, $processLine, $match);
- $listName = $match[0];
- $processLine = fgets($itemGameFile);
- //Get the contents of the list
- if (preg_match ( $openParenReg, $processLine) == 1)
- {
- $bracketCount++;
- $processLine = fgets($itemGameFile);
- //Parse out the data of the item list
- while ($bracketCount > 1)
- {
- //Going into sublists
- if (preg_match ( $openParenReg, $processLine) == 1)
- {
- $bracketCount++;
- if(preg_match ( $closeParenReg, $processLine) == 1)
- {
- $bracketCount--;
- }
- }
- //End of Loot List
- else if(preg_match ( $closeParenReg, $processLine) == 1)
- {
- $bracketCount--;
- if ($bracketCount == 1) break;
- }
- //Contents of loot list, toss out lines if they add gems/sockets (May want to log gems later)
- else if ($bracketCount == 2
- and (preg_match ( $additonalDropReg, $processLine) == 0)
- and (preg_match ( $additonalGemsReg, $processLine) == 0)
- and (preg_match ( $additonalSocketReg, $processLine) == 0))
- {
- preg_match ( $nameDataReg, $processLine, $match);
- $nameValue = $match[1];
- $nameValue = trim($nameValue, '" ');
- //append data here to the query
- $lootListBuilder.= "($listName,\"$nameValue\"), ";
- //echo $processLine.PHP_EOL;
- }
- //Contents of sublists
- else if ((preg_match ( $itemSingleReg, $processLine) == 1) or (preg_match ( $lootlistSingleReg, $processLine) == 1))
- {
- preg_match ( $nameDataReg, $processLine, $match);
- $nameValue = $match[2];
- $nameValue = trim($nameValue, '" ');
- //append data here to the query
- $lootListBuilder.= "($listName,\"$nameValue\"), ";
- }
- $processLine = fgets($itemGameFile);
- }
- }
- }
- else if(preg_match ( $closeParenReg, $processLine) == 1)
- {
- $bracketCount--;
- }
- $processLine = fgets($itemGameFile);
- }
- }
- }
- $qurybuilder = rtrim($qurybuilder, ', ');
- $qurybuilder .= "ON DUPLICATE KEY UPDATE Hero = VALUES(Hero), Slot = VALUES(Slot), Rarity = VALUES(Rarity), Name = VALUES(Name)";
- $setBuilder = rtrim($setBuilder, ', ');
- $priceBuilder = rtrim($priceBuilder, ', ');
- $bonusListBuilder = rtrim($bonusListBuilder, ', ');
- $attrabuteBuilder = rtrim($attrabuteBuilder, ', ');
- $lootListBuilder = rtrim($lootListBuilder, ', ');
- $lootListBuilder .=";";
- $priceBuilder.= "ON DUPLICATE KEY UPDATE StorePrice = VALUES(StorePrice)";
- $attrabuteBuilder .= "ON DUPLICATE KEY UPDATE staticAttributeValue = VALUES(staticAttributeValue)";
- //echo $qurybuilder.PHP_EOL;
- //echo $setBuilder.PHP_EOL;
- //echo $priceBuilder.PHP_EOL;
- //echo $attrabuteBuilder;
- //echo $lootListBuilder.PHP_EOL;
- //Used to check run time of script
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $starttime2 = $mtime;
- //This is a quick fix to correct some item names adding escape character to the SQL query
- $qurybuilder = str_replace("\\","",$qurybuilder);
- mysqli_query($sqlServer,$qurybuilder);
- mysqli_query($sqlServer,"TRUNCATE TABLE SetInfo;");
- mysqli_query($sqlServer,$setBuilder);
- mysqli_query($sqlServer,"UPDATE PriceData SET StorePrice = 0;");
- mysqli_query($sqlServer,$priceBuilder);
- mysqli_query($sqlServer,"TRUNCATE TABLE bonusDrops;");
- mysqli_query($sqlServer,$bonusListBuilder);
- mysqli_query($sqlServer,$attrabuteBuilder);
- mysqli_query($sqlServer,"TRUNCATE TABLE LootLists;");
- mysqli_query($sqlServer,$lootListBuilder);
- mysqli_query($sqlServer,"REPLACE into SetInfo SELECT SetIDNumber, SetName, ItemName, itemType FROM SetInfo, schemaData where SetInfo.ItemName = schemaData.Name;");
- mysqli_query($sqlServer,"call MakeObtainableTable();");
- //echo "<BR />".PHP_EOL;
- //echo $qurybuilder;
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $endtime2 = $mtime;
- $totaltime2 = ($endtime2 - $starttime2);
- echo "Main Qury Time: ".$totaltime2.PHP_EOL;
- //$quryfix = 'UPDATE schemaData set name = "Name Tag" where itemType = 15000';
- //mysqli_query($sqlServer,$quryfix);
- }
- function getItemIconAPI($itemGameFile, $sqlServer)
- {
- //Gets the Image URL's from the the GetItemIcon API
- //Regular Expressions used in function
- $itemReg = '/"image_inventory"/';
- $numberReg = '/\d+/';
- $defReg = '/"defindex"/';
- $imagReg = '/"image_url"/';
- $DataReg = '/.*\/(.*?)$/';
- $itemSetReg = '/"item_sets"/';
- $openParenReg ='/\{/';
- $closeParenReg ='/\}/';
- $urlValue;
- $iconName;
- $match;
- echo "Getting Item icon URLs".PHP_EOL;
- //Advance file to correct location
- $processLine = fgets($itemGameFile);
- while (preg_match ( '/"items"/', $processLine) == 0)
- {
- $processLine = fgets($itemGameFile);
- }
- $processLine = fgets($itemGameFile); //Consume the first open parenthese of the block we are looking at
- //This while loop will grab item IDs, then fetech the item icon URL
- while (($processLine = fgets($itemGameFile)) !== false)
- {
- if (preg_match( $itemSetReg, $processLine) == true) break; //Get out of while loop once we go past the definitions of the items
- if (preg_match ( $numberReg, $processLine, $match) == 1)
- {
- $idValue = $match[0]; //Get the item ID
- $processLine = fgets($itemGameFile); //Get next line, should be open brackets
- if (preg_match ( $openParenReg, $processLine) == 1)
- {
- $processLine = fgets($itemGameFile);
- $bracketCount = 1;
- while ($bracketCount > 0 && feof($itemGameFile) == false )
- {
- if (preg_match ( $itemReg, $processLine) == 1) //Parse for image icon name, then retrieve the URL of the Icon
- {
- //Get Item Icon Name
- preg_match ( $DataReg, $processLine, $match);
- $iconName = $match[1];
- $iconName = trim($iconName, '" ');
- $iconName = trim($iconName, '"');
- //Makes Icon Name all lower case (Having some upper case get 'icon not found' errors)
- $iconName = strtolower($iconName);
- $urlPath =
- "http://api.steampowered.com/IEconDOTA2_570/GetItemIconPath/v0001/?key=E5BB57F1422C50C27010EFAD1C228BDB&iconname=".$iconName;
- $urlPath = str_replace("\"","",$urlPath);
- //There seems to be some new line character at the end, but I can't figure out which one. This fixes the issue though
- //$urlPath = substr($urlPath, 0, -1);
- $urlPath = str_replace("\r", '', $urlPath);
- //echo $urlPath;
- //Parse out the final URL location of the icon
- $tempLocation = file_get_contents($urlPath);
- $json = json_decode($tempLocation, true);
- $urlValue = $json['result']['path'];
- //Append the domain to the URL
- $urlValue = "http://cdn.dota2.com/apps/570/".$urlValue;
- //Insert icon into database
- $qury = 'UPDATE schemaData set Image = "'.$urlValue.'" where itemType = '.$idValue;
- mysqli_query($sqlServer,$qury);
- //echo $qury.PHP_EOL;
- }
- //Maintain bracket count to be able to advance though the rest of the file properly
- if (preg_match ( $openParenReg, $processLine) == 1)
- {
- $bracketCount++;
- if (preg_match ( $closeParenReg, $processLine) == 1)
- {
- $bracketCount--;
- }
- $processLine = fgets($itemGameFile);
- continue;
- }
- if (preg_match ( $closeParenReg, $processLine) == 1)
- {
- $bracketCount--;
- if ($bracketCount != 0)
- {
- $processLine = fgets($itemGameFile);
- }
- //echo $bracketCount;
- continue;
- }
- $processLine = fgets($itemGameFile);
- }
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement