Advertisement
Guest User

Amazing Code from 2014

a guest
Oct 13th, 2017
1,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 26.29 KB | None | 0 0
  1. <?php
  2.     function updateSchama($itemGameFile, $sqlServer)
  3.     {
  4.         $itemReg = '/"items"/';
  5.         $numberReg = '/\d+/';
  6.         $textReg = '/[a-zA-Z_]+/';
  7.        
  8.         $nameReg = '/"name"/';
  9.         $nameDataReg = '/"([^"]*)".*?("([^"]*)")/';
  10.         $nameRegInvalidate = '/"name"\s+["]#+/';
  11.        
  12.         $itemslotReg = '/"item_slot"/';
  13.         $slotDataReg = '/"([^"]*)".*?("([^"]*)")/';
  14.        
  15.         $rarityReg = '/"item_rarity"/';
  16.         $rarityDataReg = '/"([^"]*)".*?("([^"]*)")/';
  17.        
  18.         $prefabReg = '/"prefab"/';
  19.         $prefabDataReg = '/"([^"]*)".*?("([^"]*)")/';
  20.        
  21.         $heroReg = '/"used_by_heroes"/';
  22.         $styleReg = '/"styles"/';
  23.         $altIconReg = '/"alternate_icons"/';
  24.         $rikiDaggerReg = '/"Riki\'s Dagger"/';
  25.         $primevalReg ='/"Primeval Beard"/';
  26.        
  27.        
  28.         $qurybuilder = "REPLACE INTO schemaData (itemType, Hero, Slot, Rarity, Name) VALUES ";
  29.        
  30.        
  31.         $match;    
  32.         $lastNum = 0;
  33.         $idValue = 0;
  34.         $nameValue = "Riki's Dagger";
  35.         $heroValue = "npc_dota_hero_riki";
  36.         $slotValue = "weapon";
  37.         $rarityValue = "common";
  38.         $StyleBool = false;
  39.         $playercardbool = false;
  40.        
  41.         $processLine = fgets($itemGameFile);
  42.         while (preg_match ( '/"items"/', $processLine) == 0)
  43.         {
  44.             $processLine = fgets($itemGameFile);
  45.         }
  46.         //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
  47.         //inclsive and I could take the others out, to do maybe another time)
  48.         while (($processLine = fgets($itemGameFile)) !== false)
  49.         {
  50.             if (preg_match ( $nameReg, $processLine) == 1) //parse name, put last entry onto qury queue
  51.             {
  52.                 if (preg_match ( $primevalReg, $processLine) == 1)
  53.                 {
  54.                     $StyleBool = false;
  55.                 }
  56.                 if ($idValue > $lastNum || $StyleBool == true || preg_match($nameRegInvalidate, $processLine) == true)
  57.                 {
  58.                 echo $idValue.' > '.$lastNum.PHP_EOL." ".$StyleBool." "."<BR>";
  59.                     if (preg_match ($rikiDaggerReg, $processLine) == 1)
  60.                     {
  61.                         $idValue = 0;
  62.                     }
  63.                 }
  64.                 else if ($playercardbool == true)
  65.                 {
  66.                     $playercardbool = false;
  67.                 }
  68.                 else
  69.                 {
  70.                     echo $idValue."<BR>";
  71.                     $qurybuilder.= "(\"$idValue\",\"$heroValue\",\"$slotValue\",\"$rarityValue\",\"$nameValue\"), ";
  72.                     preg_match ( $nameDataReg, $processLine, $match);
  73.                     $idValue = $lastNum;
  74.                     $nameValue = $match[2];
  75.                     $nameValue = trim($nameValue, '" ');
  76.                 }
  77.             }
  78.             if (preg_match ( $numberReg, $processLine) == 1) //Parse item ID Number
  79.             {
  80.                 preg_match ( $numberReg, $processLine, $match);
  81.                 $lastNum = $match[0];
  82.                 //echo $lastNum.PHP_EOL."<BR>";
  83.             }
  84.             if (preg_match ( $prefabReg, $processLine) == 1) //Defalut some data based on prefrab type
  85.             {
  86.                 $rarityValue = "common";
  87.                 $heroValue = "player";
  88.                 $slotValue = "none";
  89.                 preg_match ( $prefabDataReg, $processLine, $match);
  90.                 $prefabtype = $match[2];
  91.                 $prefabtype = trim($prefabtype, '" ');
  92.                
  93.                 if ($prefabtype == "wearable" || $prefabtype == "default_item")
  94.                 {
  95.                     $slotValue = "weapon";
  96.                 }
  97.                 else if ( $prefabtype == "player_card" )
  98.                 {
  99.                     $playercardbool = true;
  100.                 }
  101.                 else
  102.                 {
  103.                     $slotValue = $prefabtype;
  104.                 }      
  105.             }
  106.             if (preg_match ( $itemslotReg, $processLine) == 1) //Parse item slot info
  107.             {
  108.                 preg_match ( $slotDataReg, $processLine, $match);
  109.                 $slotValue = $match[2];
  110.                 $slotValue = trim($slotValue, '" ');
  111.                 //echo $slotValue."<BR>";
  112.             }
  113.             if (preg_match ( $rarityReg, $processLine) == 1) //Parse Rarity Info
  114.             {
  115.                 preg_match ( $rarityDataReg, $processLine, $match);
  116.                 $rarityValue = $match[2];
  117.                 $rarityValue = trim($rarityValue, '" ');
  118.             }
  119.             if (preg_match ( $heroReg, $processLine) == 1) //Parse Hero Info
  120.             {
  121.                 if (preg_match ( $numberReg, $processLine) == 0)
  122.                 {
  123.                     $processLine = fgets($itemGameFile);
  124.                     $processLine = fgets($itemGameFile);
  125.                     preg_match ( $textReg, $processLine, $match);
  126.                     $heroValue = $match[0];
  127.                    
  128.                 }              
  129.             }
  130.             if (preg_match ( $styleReg, $processLine) == 1)
  131.             {
  132.                 $StyleBool = true;
  133.             }
  134.             if (preg_match ( $altIconReg , $processLine) == 1)
  135.             {
  136.                 $StyleBool = false;
  137.             }
  138.             if (preg_match ('/"item_sets"/', $processLine) == 1)
  139.             {
  140.                 break;
  141.             }
  142.        
  143.            
  144.         }
  145.         $qurybuilder.= "(\"$idValue\",\"$heroValue\",\"$slotValue\",\"$rarityValue\",\"$nameValue\"), ";
  146.         $qurybuilder = rtrim($qurybuilder, ', ');
  147.         //Used to check run time of script
  148.         $mtime = microtime();
  149.         $mtime = explode(" ",$mtime);
  150.         $mtime = $mtime[1] + $mtime[0];
  151.         $starttime2 = $mtime;
  152.        
  153.         mysqli_query($sqlServer,$qurybuilder);
  154.         //echo "<BR />".PHP_EOL;
  155.         //echo $qurybuilder;
  156.        
  157.         $mtime = microtime();
  158.         $mtime = explode(" ",$mtime);
  159.         $mtime = $mtime[1] + $mtime[0];
  160.         $endtime2 = $mtime;
  161.         $totaltime2 = ($endtime2 - $starttime2);
  162.         echo "Main Qury Time: ".$totaltime2.PHP_EOL;
  163.         echo $lastNum;
  164.         $quryfix = 'UPDATE schemaData set name = "Name Tag" where itemType = 15000';
  165.         mysqli_query($sqlServer,$quryfix);
  166.     }
  167.    
  168.     function updateImages($itemGameFile, $sqlServer)
  169.     {
  170.         //Gets the Image URl's from the Item Schema
  171.         $itemReg = '/"items"/';
  172.         $numberReg = '/\d+/';
  173.         $defReg = '/"defindex"/';
  174.         $imagReg = '/"image_url"/';
  175.         $DataReg = '/"([^"]*)".*?("([^"]*)")/';
  176.         $itemID;
  177.         $urlValue;
  178.         $match;
  179.    
  180.         $processLine = fgets($itemGameFile);
  181.         while (preg_match ( '/"items"/', $processLine) == 0)
  182.         {
  183.             $processLine = fgets($itemGameFile);
  184.         }
  185.         while (($processLine = fgets($itemGameFile)) !== false)
  186.         {
  187.             if (preg_match ( $defReg, $processLine) == 1) //Parse for item ID info
  188.             {
  189.                 preg_match ( $numberReg, $processLine, $match);
  190.                 $itemID = $match[0];
  191.             }
  192.             if (preg_match ( $imagReg, $processLine) == 1) //Parse for image url info and put in to database
  193.             {
  194.                 preg_match ( $DataReg, $processLine, $match);
  195.                 $urlValue = $match[2];
  196.                 //echo $urlValue."<BR>";
  197.                 $urlValue = trim($urlValue, '" ');
  198.                 $qury = 'UPDATE schemaData set Image = "'.$urlValue.'" where itemType = '.$itemID;
  199.                 mysqli_query($sqlServer,$qury);
  200.                 //echo $qury."<BR>".PHP_EOL;
  201.             }
  202.         }
  203.    
  204.     }
  205.    
  206.     function updateSchema_v2 ($itemGameFile, $sqlServer)
  207.     {
  208.    
  209.         //Bunch of Regular Expressions used in parsing are defined here. Something tells me I'm doing this a bad way, but it got done.
  210.         $itemReg = '/"items"/';
  211.         $itemSingleReg = '/"item"/';
  212.         $itemSetReg = '/"item_sets"/';
  213.         $numberReg = '/\d+/';
  214.         $textReg = '/[a-zA-Z_]+/';
  215.        
  216.         $nameReg = '/"name"/';
  217.         $nameDataReg = '/"([^"]*)".*?("([^"]*)")/';
  218.         $nameRegInvalidate = '/"name"\s+["]#+/';
  219.        
  220.         $itemslotReg = '/"item_slot"/';
  221.         $slotDataReg = '/"([^"]*)".*?("([^"]*)")/';
  222.        
  223.         $rarityReg = '/"item_rarity"/';
  224.         $rarityDataReg = '/"([^"]*)".*?("([^"]*)")/';
  225.        
  226.         $prefabReg = '/"prefab"/';
  227.         $prefabDataReg = '/"([^"]*)".*?("([^"]*)")/';
  228.        
  229.         $bundleReg = '/"bundle"/';
  230.         $priceInfoReg = '/"price_info"/';
  231.         $priceReg = '/"price"/';
  232.        
  233.         $heroReg = '/"used_by_heroes"/';
  234.         $styleReg = '/"styles"/';
  235.         $altIconReg = '/"alternate_icons"/';
  236.         $rikiDaggerReg = '/"Riki\'s Dagger"/';
  237.         $primevalReg ='/"Primeval Beard"/';
  238.        
  239.         $staticAttReg ='/"static_attributes"/';
  240.         $attrabuteClassReg = '/"static_attributes"/';
  241.        
  242.         $additonalDropReg = '/"additional_drop"/';
  243.         $additonalGemsReg = '/"add_random_gems"/';
  244.         $additonalSocketReg = '/"add_empty_socket"/';
  245.        
  246.         $lootListReg = '/"loot_lists"/';
  247.         $lootlistSingleReg = '/"loot_list"/';
  248.         $betweenQuoteReg = '/"([^"]*)"/';
  249.         $bonusReg = '/"bonus_itemdefs"/';
  250.        
  251.        
  252.         $openParenReg ='/\{/';
  253.         $closeParenReg ='/\}/';
  254.        
  255.         $qurybuilder = "INSERT INTO schemaData (itemType, Hero, Slot, Rarity, Name) VALUES ";
  256.         $setBuilder = "REPLACE INTO SetInfo (SetIDNumber, SetName, ItemName) VALUES ";
  257.         $priceBuilder = "INSERT INTO PriceData (itemID, StorePrice) VALUES ";
  258.         $attrabuteBuilder = "INSERT INTO staticAttributes (itemType, staticAttributeClass, staticAttributeValue) VALUES ";
  259.         $lootListBuilder ="INSERT INTO LootLists (ListName,ItemName) VALUES ";
  260.         $bonusListBuilder ="INSERT INTO bonusDrops (SourceItemID,DropItemID) VALUES ";
  261.        
  262.         $match;    
  263.         $lastNum = 0;
  264.         $idValue = 0;
  265.         $nameValue = "Riki's Dagger";
  266.         $heroValue = "npc_dota_hero_riki";
  267.         $slotValue = "weapon";
  268.         $rarityValue = "common";
  269.         $StyleBool = false;
  270.         $playercardbool = false;
  271.        
  272.         $processLine = fgets($itemGameFile);
  273.         while (preg_match ( '/"items"/', $processLine) == 0)
  274.         {
  275.             $processLine = fgets($itemGameFile);
  276.         }
  277.         $processLine = fgets($itemGameFile); //Consume the first open parenthese of the block we are looking at
  278.         //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
  279.         //inclsive and I could take the others out, to do maybe another time)
  280.        
  281.         //This while loop will parse the item definition out of the schema
  282.         while (($processLine = fgets($itemGameFile)) !== false)
  283.         {
  284.             if (preg_match( $itemSetReg, $processLine) == true) break; //Get out of while loop once we go past the definitions of the items
  285.             //echo $processLine;
  286.             if (preg_match ( $numberReg, $processLine, $match) == 1)
  287.             {
  288.                 $idValue = $match[0];
  289.                
  290.                 //if ($idValue == 13) return;
  291.                
  292.                 //Set default values;
  293.                 $heroValue = "player";
  294.                 //$heroValue = "npc_dota_hero_riki";
  295.                 $slotValue = "weapon";
  296.                 $rarityValue = "common";
  297.                
  298.                 $processLine = fgets($itemGameFile); //Get next line, should be open brackets
  299.                 if (preg_match ( $openParenReg, $processLine) == 1)
  300.                 {
  301.                 //echo $idValue.PHP_EOL;
  302.                 $processLine = fgets($itemGameFile);
  303.                 $bracketCount = 1;
  304.                 //echo $processLine;
  305.                     while ($bracketCount > 0 && feof($itemGameFile) == false )
  306.                     {      
  307.                         //echo $processLine;
  308.                         //This set of if statements sort of emulates a switch case
  309.                         if (preg_match ( $nameReg, $processLine) == 1 && $bracketCount == 1) //Capture item name
  310.                         {
  311.                             preg_match ( $nameDataReg, $processLine, $match);
  312.                             $nameValue = $match[2];
  313.                             $nameValue = trim($nameValue, '" ');
  314.                             $processLine = fgets($itemGameFile);
  315.                             continue;
  316.                         }
  317.                        
  318.                         //Default to common
  319.                         if (preg_match ( $rarityReg, $processLine) == 1 && $bracketCount == 1) //Parse Rarity Info
  320.                         {
  321.                             preg_match ( $rarityDataReg, $processLine, $match);
  322.                             $rarityValue = $match[2];
  323.                             $rarityValue = trim($rarityValue, '" ');
  324.                             $processLine = fgets($itemGameFile);
  325.                             continue;
  326.                         }
  327.                        
  328.                        
  329.                         //Get the item slot. If there is no item slot, get the info from the prefab
  330.                         if (preg_match ( $itemslotReg, $processLine) == 1 && $bracketCount == 1)
  331.                         {
  332.                             preg_match ( $slotDataReg, $processLine, $match);
  333.                             $slotValue = $match[2];
  334.                             $slotValue = trim($slotValue, '" ');
  335.                             $processLine = fgets($itemGameFile);
  336.                             continue;
  337.                         }
  338.                            
  339.                         //The prefab to get slot info from
  340.                         if (preg_match ( $prefabReg, $processLine) == 1 && $bracketCount == 1)
  341.                         {
  342.                             preg_match ( $prefabDataReg, $processLine, $match);
  343.                             $prefabtype = $match[2];
  344.                             $prefabtype = trim($prefabtype, '" ');
  345.                             $slotValue = $prefabtype;
  346.                             $processLine = fgets($itemGameFile);
  347.                             continue;
  348.                         }
  349.                        
  350.                         //Get Price info
  351.                         if (preg_match ( $priceInfoReg, $processLine) == 1 && $bracketCount == 1)
  352.                         {
  353.                             //echo "IN PRICE INFO BLOCK";
  354.                             //echo $processLine;
  355.                             $processLine = fgets($itemGameFile);
  356.                             if(preg_match ( $openParenReg, $processLine) == 1)//We are now in the block of text with bundle info, gather info.
  357.                             {
  358.                                 //echo "price".PHP_EOL;
  359.                                 while(preg_match ( $closeParenReg, $processLine) == 0)
  360.                                 {
  361.                                     $processLine = fgets($itemGameFile);
  362.                                     if(preg_match ( $priceReg, $processLine) == 1)
  363.                                     {
  364.                                         preg_match ( $numberReg, $processLine, $match);
  365.                                         $pricePoint = $match[0];
  366.                                         $pricePoint = $pricePoint / 100; //Yeah, prices are stored as ints in the schema. Hope this doesn't cause any floating point error!
  367.                                         $priceBuilder .= "(\"$idValue\",\"$pricePoint\"), ";
  368.                                         //echo "(\"$idValue\",\"$pricePoint\"), ";
  369.                                     }
  370.                                 }
  371.                             }
  372.                             $processLine = fgets($itemGameFile);
  373.                             continue;
  374.                         }
  375.                        
  376.                        
  377.                         //Get Bonus Drop info
  378.                         if (preg_match ( $bonusReg, $processLine) == 1)
  379.                         {
  380.                             $processLine = fgets($itemGameFile);
  381.                             if(preg_match ( $openParenReg, $processLine) == 1)//We are now in the block of text with bundle info, gather info.
  382.                             {
  383.                                 while(preg_match ( $closeParenReg, $processLine) == 0)
  384.                                 {
  385.                                     $processLine = fgets($itemGameFile);
  386.                                     if(preg_match ( $numberReg, $processLine) == 1)
  387.                                     {
  388.                                         preg_match ( $numberReg, $processLine, $match);
  389.                                         $bundleID = $match[0];
  390.                                         $bonusListBuilder .= "(\"$idValue\",\"$bundleID\"), ";
  391.                                         //echo "(\"$idValue\",\"$pricePoint\"), ";
  392.                                     }
  393.                                 }
  394.                             }
  395.                             $processLine = fgets($itemGameFile);
  396.                             continue;
  397.                         }
  398.                        
  399.                         //Get Attributes
  400.                         if (preg_match ( $staticAttReg, $processLine) == 1 && $bracketCount == 1)
  401.                         {
  402.                             $processLine = fgets($itemGameFile);
  403.                             if(preg_match ( $openParenReg, $processLine) == 1)//We are now in the block of text with bundle info, gather info.
  404.                             {  
  405.                                 $attBracketCount = 1;
  406.                                 //echo "price".PHP_EOL;
  407.                                 while($attBracketCount > 0)
  408.                                 {
  409.                                     $processLine = fgets($itemGameFile);
  410.                                     if(preg_match ( $openParenReg, $processLine) == 1)
  411.                                     {
  412.                                         $attBracketCount++;
  413.                                         //Get Attribute name
  414.                                         $processLine = fgets($itemGameFile);
  415.                                         preg_match ( $nameDataReg, $processLine, $match);
  416.                                         $attName = $match[2];
  417.                                         $attName = trim($attName, '" ');
  418.                                        
  419.                                         //Get Attribute value
  420.                                         $processLine = fgets($itemGameFile);
  421.                                         preg_match ( $nameDataReg, $processLine, $match);
  422.                                         $attValue = $match[2];
  423.                                         $attValue = trim($attValue, '" ');
  424.                                        
  425.                                         //Concatenate onto query
  426.                                         $attrabuteBuilder .= "(\"$idValue\",\"$attName\",\"$attValue\"), ";
  427.                                         continue;
  428.                                     }
  429.                                         if(preg_match ( $closeParenReg, $processLine) == 1)
  430.                                         {
  431.                                             $attBracketCount--;
  432.                                         }
  433.                                 }
  434.                             }
  435.                             $processLine = fgets($itemGameFile);
  436.                             continue;
  437.                         }
  438.                        
  439.                         //Parse out details on bundle  
  440.                         if(preg_match ( $bundleReg, $processLine) == 1 && $bracketCount == 1)//bundle
  441.                         {
  442.                             //echo "Bundle".PHP_EOL;
  443.                             $processLine = fgets($itemGameFile);
  444.                             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.
  445.                             {
  446.                                 $processLine = fgets($itemGameFile);
  447.                             }
  448.                             if(preg_match ( $openParenReg, $processLine) == 1)//We are now in the block of text with bundle info, gather info.
  449.                             {
  450.                                 $processLine = fgets($itemGameFile);
  451.                                 while(preg_match ( $closeParenReg, $processLine) == 0)
  452.                                 {
  453.                                     preg_match ( $nameDataReg, $processLine, $match);
  454.                                     //echo $processLine;
  455.                                     $itemNameValue = $match[1];
  456.                                     $setBuilder .= "(\"$idValue\",\"$nameValue\",\"$itemNameValue\"), ";
  457.                                     $processLine = fgets($itemGameFile);
  458.                                 }
  459.                             }
  460.                             $processLine = fgets($itemGameFile);
  461.                             continue;
  462.                         }
  463.                        
  464.                         //Parse Hero Info
  465.                         if (preg_match ( $heroReg, $processLine) == 1 && $bracketCount == 1)
  466.                         {  
  467.                             //echo "hero";
  468.                             if (preg_match ( $numberReg, $processLine) == 0)
  469.                             {
  470.                                 $processLine = fgets($itemGameFile);
  471.                                 //echo $processLine;
  472.                                 $processLine = fgets($itemGameFile);
  473.                                 //echo $processLine;
  474.                                 preg_match ( $textReg, $processLine, $match);
  475.                                 $heroValue = $match[0];
  476.                                 $processLine = fgets($itemGameFile);
  477.                                 $processLine = fgets($itemGameFile);
  478.                                 //echo $heroValue;
  479.                                
  480.                             }
  481.                             else
  482.                             {
  483.                                 $heroValue = "player";
  484.                                 $processLine = fgets($itemGameFile);
  485.                             }
  486.                            
  487.                             //sleep(1);
  488.                             continue;
  489.                         }
  490.                        
  491.                        
  492.                         //Maintain bracket count
  493.                         if (preg_match ( $openParenReg, $processLine) == 1)
  494.                         {
  495.                             $bracketCount++;
  496.                             if (preg_match ( $closeParenReg, $processLine) == 1)
  497.                             {
  498.                                 $bracketCount--;
  499.                             }
  500.                             $processLine = fgets($itemGameFile);
  501.                             continue;
  502.                         }
  503.                        
  504.                         if (preg_match ( $closeParenReg, $processLine) == 1)
  505.                         {
  506.                             $bracketCount--;
  507.                             if ($bracketCount != 0)
  508.                             {
  509.                                 $processLine = fgets($itemGameFile);
  510.                             }
  511.                             //echo $bracketCount;
  512.                             continue;
  513.                         }
  514.                        
  515.                         /*
  516.                         //Catch unknown or unneeded block of text
  517.                         if (preg_match ( $openParenReg, $processLine) == 1)
  518.                         {
  519.                             echo "IN UNKNOWN BLCOK".PHP_EOL;
  520.                             $bracktCount = 1;
  521.                             //echo "$bracktCount".PHP_EOL;
  522.                             while (preg_match ( $closeParenReg, $processLine) == 0 && $bracktCount > 0)
  523.                             {
  524.                                 $processLine = fgets($itemGameFile);
  525.                                 echo $processLine;
  526.                                 if (preg_match ( $openParenReg, $processLine) == 1)
  527.                                 {
  528.                                 $bracktCount++;
  529.                                 }
  530.                                 if (preg_match ( $closeParenReg, $processLine) == 1)
  531.                                 {
  532.                                 $bracktCount--;
  533.                                 }
  534.                                 //echo $bracktCount;
  535.                             }
  536.                             $processLine = fgets($itemGameFile);
  537.                             echo $processLine;
  538.                             echo "EXITING UNKOWN BLOCK".PHP_EOL;
  539.                             continue;
  540.                         }
  541.                         */
  542.                         $processLine = fgets($itemGameFile);
  543.                        
  544.                     }
  545.                     //echo "(\"$idValue\",\"$heroValue\",\"$slotValue\",\"$rarityValue\",\"$nameValue\"), ";
  546.                     //sleep (1);
  547.                     $qurybuilder.= "(\"$idValue\",\"$heroValue\",\"$slotValue\",\"$rarityValue\",\"$nameValue\"), ";
  548.                     //echo "entry logged".PHP_EOL;
  549.                     //echo $processLine;
  550.                 }
  551.             }          
  552.         }
  553.         //this part will get the loots lists
  554.         while (($processLine = fgets($itemGameFile)) !== false)
  555.         {
  556.             //Advance file to proper location
  557.             while (preg_match ( $lootListReg, $processLine) == 0 && feof($itemGameFile) == false)
  558.             {
  559.                 $processLine = fgets($itemGameFile);
  560.             }
  561.             $processLine = fgets($itemGameFile);
  562.             if (preg_match ( $openParenReg, $processLine) == 1)
  563.             {
  564.                 echo "Scanning Loot Lists".PHP_EOL;
  565.                 //echo $idValue.PHP_EOL;
  566.                 $processLine = fgets($itemGameFile);
  567.                 $bracketCount = 1;
  568.                
  569.                
  570.                 while ($bracketCount > 0)
  571.                 {
  572.                     //If it hits a list of items to parse out
  573.                     if (preg_match ( $betweenQuoteReg, $processLine) == 1 && $bracketCount == 1)
  574.                     {
  575.                         //Get the lists name
  576.                         preg_match ( $betweenQuoteReg, $processLine, $match);
  577.                         $listName = $match[0];
  578.                         $processLine = fgets($itemGameFile);
  579.                        
  580.                         //Get the contents of the list
  581.                         if (preg_match ( $openParenReg, $processLine) == 1)
  582.                         {
  583.                             $bracketCount++;
  584.                             $processLine = fgets($itemGameFile);
  585.                             //Parse out the data of the item list
  586.                             while ($bracketCount > 1)
  587.                             {  
  588.                                 //Going into sublists
  589.                                 if (preg_match ( $openParenReg, $processLine) == 1)
  590.                                 {
  591.                                     $bracketCount++;
  592.                                     if(preg_match ( $closeParenReg, $processLine) == 1)
  593.                                     {
  594.                                         $bracketCount--;
  595.                                     }
  596.                                 }
  597.                                 //End of Loot List
  598.                                 else if(preg_match ( $closeParenReg, $processLine) == 1)
  599.                                 {
  600.                                     $bracketCount--;
  601.                                     if ($bracketCount == 1) break;
  602.                                 }
  603.                                 //Contents of loot list, toss out lines if they add gems/sockets (May want to log gems later)
  604.                                 else if ($bracketCount == 2
  605.                                 and (preg_match ( $additonalDropReg, $processLine) == 0)
  606.                                 and (preg_match ( $additonalGemsReg, $processLine) == 0)
  607.                                 and (preg_match ( $additonalSocketReg, $processLine) == 0))
  608.                                 {
  609.                                     preg_match ( $nameDataReg, $processLine, $match);
  610.                                     $nameValue = $match[1];
  611.                                     $nameValue = trim($nameValue, '" ');
  612.                                     //append data here to the query
  613.                                     $lootListBuilder.= "($listName,\"$nameValue\"), ";
  614.                                     //echo $processLine.PHP_EOL;
  615.                                 }
  616.                                 //Contents of sublists
  617.                                 else if ((preg_match ( $itemSingleReg, $processLine) == 1) or (preg_match ( $lootlistSingleReg, $processLine) == 1))
  618.                                 {
  619.                                     preg_match ( $nameDataReg, $processLine, $match);
  620.                                     $nameValue = $match[2];
  621.                                     $nameValue = trim($nameValue, '" ');
  622.                                     //append data here to the query
  623.                                     $lootListBuilder.= "($listName,\"$nameValue\"), ";
  624.                                 }
  625.                                 $processLine = fgets($itemGameFile);
  626.                             }
  627.                         }
  628.                     }
  629.                     else if(preg_match ( $closeParenReg, $processLine) == 1)
  630.                     {
  631.                         $bracketCount--;
  632.                     }
  633.                     $processLine = fgets($itemGameFile);
  634.                 }
  635.                
  636.             }
  637.        
  638.         }
  639.        
  640.        
  641.         $qurybuilder = rtrim($qurybuilder, ', ');
  642.         $qurybuilder .= "ON DUPLICATE KEY UPDATE Hero = VALUES(Hero), Slot = VALUES(Slot), Rarity = VALUES(Rarity), Name = VALUES(Name)";
  643.         $setBuilder = rtrim($setBuilder, ', ');
  644.         $priceBuilder = rtrim($priceBuilder, ', ');
  645.         $bonusListBuilder = rtrim($bonusListBuilder, ', ');
  646.         $attrabuteBuilder = rtrim($attrabuteBuilder, ', ');
  647.         $lootListBuilder = rtrim($lootListBuilder, ', ');
  648.         $lootListBuilder .=";";
  649.         $priceBuilder.= "ON DUPLICATE KEY UPDATE StorePrice = VALUES(StorePrice)";
  650.         $attrabuteBuilder .= "ON DUPLICATE KEY UPDATE staticAttributeValue = VALUES(staticAttributeValue)";
  651.        
  652.        
  653.         //echo $qurybuilder.PHP_EOL;
  654.         //echo $setBuilder.PHP_EOL;
  655.         //echo $priceBuilder.PHP_EOL;
  656.         //echo $attrabuteBuilder;
  657.         //echo $lootListBuilder.PHP_EOL;
  658.        
  659.         //Used to check run time of script
  660.         $mtime = microtime();
  661.         $mtime = explode(" ",$mtime);
  662.         $mtime = $mtime[1] + $mtime[0];
  663.         $starttime2 = $mtime;
  664.        
  665.         //This is a quick fix to correct some item names adding escape character to the SQL query
  666.         $qurybuilder = str_replace("\\","",$qurybuilder);
  667.        
  668.        
  669.         mysqli_query($sqlServer,$qurybuilder);
  670.         mysqli_query($sqlServer,"TRUNCATE TABLE SetInfo;");
  671.         mysqli_query($sqlServer,$setBuilder);
  672.         mysqli_query($sqlServer,"UPDATE PriceData SET StorePrice = 0;");
  673.         mysqli_query($sqlServer,$priceBuilder);
  674.         mysqli_query($sqlServer,"TRUNCATE TABLE bonusDrops;");
  675.         mysqli_query($sqlServer,$bonusListBuilder);
  676.         mysqli_query($sqlServer,$attrabuteBuilder);
  677.         mysqli_query($sqlServer,"TRUNCATE TABLE LootLists;");
  678.         mysqli_query($sqlServer,$lootListBuilder);
  679.         mysqli_query($sqlServer,"REPLACE into SetInfo SELECT SetIDNumber, SetName, ItemName, itemType FROM SetInfo, schemaData where SetInfo.ItemName = schemaData.Name;");
  680.         mysqli_query($sqlServer,"call MakeObtainableTable();");
  681.        
  682.        
  683.         //echo "<BR />".PHP_EOL;
  684.         //echo $qurybuilder;
  685.        
  686.         $mtime = microtime();
  687.         $mtime = explode(" ",$mtime);
  688.         $mtime = $mtime[1] + $mtime[0];
  689.         $endtime2 = $mtime;
  690.         $totaltime2 = ($endtime2 - $starttime2);
  691.         echo "Main Qury Time: ".$totaltime2.PHP_EOL;
  692.         //$quryfix = 'UPDATE schemaData set name = "Name Tag" where itemType = 15000';
  693.         //mysqli_query($sqlServer,$quryfix);
  694.     }
  695.    
  696.     function getItemIconAPI($itemGameFile, $sqlServer)
  697.     {
  698.         //Gets the Image URL's from the the GetItemIcon API
  699.        
  700.         //Regular Expressions used in function
  701.         $itemReg = '/"image_inventory"/';
  702.         $numberReg = '/\d+/';
  703.         $defReg = '/"defindex"/';
  704.         $imagReg = '/"image_url"/';
  705.         $DataReg = '/.*\/(.*?)$/';
  706.         $itemSetReg = '/"item_sets"/';
  707.         $openParenReg ='/\{/';
  708.         $closeParenReg ='/\}/';
  709.        
  710.         $urlValue;
  711.         $iconName;
  712.         $match;
  713.    
  714.         echo "Getting Item icon URLs".PHP_EOL;
  715.    
  716.         //Advance file to correct location
  717.         $processLine = fgets($itemGameFile);
  718.         while (preg_match ( '/"items"/', $processLine) == 0)
  719.         {
  720.             $processLine = fgets($itemGameFile);
  721.         }
  722.         $processLine = fgets($itemGameFile); //Consume the first open parenthese of the block we are looking at
  723.        
  724.         //This while loop will grab item IDs, then fetech the item icon URL
  725.         while (($processLine = fgets($itemGameFile)) !== false)
  726.         {
  727.             if (preg_match( $itemSetReg, $processLine) == true) break; //Get out of while loop once we go past the definitions of the items
  728.             if (preg_match ( $numberReg, $processLine, $match) == 1)
  729.             {
  730.                 $idValue = $match[0]; //Get the item ID
  731.                 $processLine = fgets($itemGameFile); //Get next line, should be open brackets
  732.                 if (preg_match ( $openParenReg, $processLine) == 1)
  733.                 {
  734.                     $processLine = fgets($itemGameFile);
  735.                     $bracketCount = 1;
  736.                     while ($bracketCount > 0 && feof($itemGameFile) == false )
  737.                     {  
  738.                         if (preg_match ( $itemReg, $processLine) == 1) //Parse for image icon name, then retrieve the URL of the Icon
  739.                         {
  740.                             //Get Item Icon Name
  741.                             preg_match ( $DataReg, $processLine, $match);
  742.                             $iconName = $match[1];
  743.                             $iconName = trim($iconName, '" ');
  744.                             $iconName = trim($iconName, '"');                          
  745.                            
  746.                            
  747.                             //Makes Icon Name all lower case (Having some upper case get 'icon not found' errors)
  748.                             $iconName = strtolower($iconName);
  749.                            
  750.                             $urlPath =
  751.                             "http://api.steampowered.com/IEconDOTA2_570/GetItemIconPath/v0001/?key=E5BB57F1422C50C27010EFAD1C228BDB&iconname=".$iconName;
  752.                             $urlPath = str_replace("\"","",$urlPath);
  753.                             //There seems to be some new line character at the end, but I can't figure out which one. This fixes the issue though
  754.                             //$urlPath = substr($urlPath, 0, -1);
  755.                             $urlPath = str_replace("\r", '', $urlPath);
  756.                             //echo $urlPath;
  757.                             //Parse out the final URL location of the icon
  758.                            
  759.                             $tempLocation = file_get_contents($urlPath);
  760.                             $json = json_decode($tempLocation, true);
  761.                             $urlValue = $json['result']['path'];
  762.                            
  763.                            
  764.                            
  765.                             //Append the domain to the URL
  766.                             $urlValue = "http://cdn.dota2.com/apps/570/".$urlValue;
  767.                            
  768.                             //Insert icon into database
  769.                             $qury = 'UPDATE schemaData set Image = "'.$urlValue.'" where itemType = '.$idValue;
  770.                             mysqli_query($sqlServer,$qury);
  771.                             //echo $qury.PHP_EOL;
  772.                            
  773.                            
  774.                         }
  775.                         //Maintain bracket count to be able to advance though the rest of the file properly
  776.                         if (preg_match ( $openParenReg, $processLine) == 1)
  777.                         {
  778.                             $bracketCount++;
  779.                             if (preg_match ( $closeParenReg, $processLine) == 1)
  780.                             {
  781.                                 $bracketCount--;
  782.                             }
  783.                             $processLine = fgets($itemGameFile);
  784.                             continue;
  785.                         }
  786.                        
  787.                         if (preg_match ( $closeParenReg, $processLine) == 1)
  788.                         {
  789.                             $bracketCount--;
  790.                             if ($bracketCount != 0)
  791.                             {
  792.                                 $processLine = fgets($itemGameFile);
  793.                             }
  794.                             //echo $bracketCount;
  795.                             continue;
  796.                         }
  797.                         $processLine = fgets($itemGameFile);
  798.                        
  799.                     }
  800.                 }
  801.                
  802.             }
  803.         }  
  804.     }
  805.    
  806. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement