Advertisement
Faguss

Custom Map List from umc_mapcycle.txt

Jan 19th, 2016
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.05 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4.     <META charset="UTF-8">
  5. </HEAD>
  6. <BODY>
  7. <?php
  8.     // --------------------------------------------------------------
  9.     // Settings:
  10.     define("CONFIGURATION_PATH"         , "");
  11.     define("CONFIGURATION_NAME"         , "umc_mapcycle.txt");
  12.     define("SCREENSHOT_PATH"            , "stajniacustomimg/");
  13.     define("SCREENSHOT_THUMBNAIL_PATH"  , "stajniacustomimg/thumb/");
  14.     define("SCREENSHOT_THUMBNAIL_NAME"  , "_thumb");
  15.     define("SCREENSHOT_TITLE_STYLE"     , "STYLE='font-family:\"Trebuchet MS\",sans-serif; line-height:1.6; font-size:24px; font-weight:bold;'");
  16.     define("SCREENSHOT_STYLE"           , "STYLE='max-width:100% !important; cursor:pointer; vertical-align:middle; border:0 none;'");
  17.     define("MAP_DESCRIPTION_STYLE"      , "STYLE='font-family:\"Trebuchet MS\",sans-serif; font-size:10px;'");
  18.    
  19.     $TitleColors = array
  20.     (
  21.         "koth"  =>  "1ad399",
  22.         "dom"   =>  "ff8c00",
  23.         "ctf"   =>  "dda0dd",
  24.         "cp"    =>  "ff8c00",
  25.         "pl"    =>  "008000"
  26.     );
  27.    
  28.     $MapDescription = array
  29.     (
  30.         "cp_croissant_rc11"     => "5 punktów",
  31.         "cp_stoneyridge_rc1"    => "atak/obrona, 2 punkty",
  32.         "cp_mudwater_b4"        => "atak/obrona, 2 punkty",
  33.         "cp_sunshine_rc9"       => "5 punktów",
  34.         "cp_gydan"              => "atak/obrona, 4 punkty",
  35.         "cp_edifice_b4"         => "atak/obrona, 3 punkty",
  36.         "cp_biodome_b1"         => "5 punktów",
  37.         "cp_warmerfront_rc1c"   => "5 punktów",
  38.         "cp_warpath_v3"         => "5 punktów",
  39.         "cp_collis_b3"          => "5 punktów",
  40.         "cp_stag"               => "5 punktów",
  41.         "cp_mojave_b2"          => "atak/obrona, 2 strefy po 2 punkty",
  42.         "cp_glacier_rc6"        => "atak/obrona, 3 punkty",
  43.         "cp_upland_rc4"         => "atak/obrona, 5 punktów",
  44.         "cp_follower"           => "5 punktów",
  45.         "cp_waste"              => "5 punktów",
  46.         "cp_wetcoal_b1"         => "5 punktów",
  47.         "cp_metalworks_rc5"     => "5 punktów",
  48.         "cp_metalworks_rc7"     => "5 punktów",
  49.         "cp_logjam_rc2a"        => "5 punktów",
  50.         "cp_antiquity_rc1"      => "5 punktów",
  51.         "cp_furnace_rc"         => "atak/obrona, 3 punkty",
  52.         "pl_angkor_rc1"         => "3 strefy",
  53.         "pl_great_heights_b3"   => "3 strefy",
  54.         "pl_waste_v2"           => "przeciąganie wózka",
  55.         "pl_dbheights_v3"       => "3 strefy",
  56.         "pl_cranetop_b8"        => "3 strefy",
  57.         "ctf_converge_b3"       => "zanieść walizkę do bazy wroga",
  58.         "ctf_aurora_rc"         => "zanieść walizkę do bazy wroga",
  59.         "ctf_vector_v1"         => "zanieść walizkę do 2 punktów w 3 strefach",
  60.         "ctf_snowdrift_b2"      => "zanieść walizkę do 4 punktów",
  61.         "ctf_haarp"             => "zanieść walizkę do 2 punktów w 3 strefach",
  62.         "dom_canalzone2_b4"     => "6 punktów"
  63.     );
  64.     // --------------------------------------------------------------
  65.  
  66.    
  67.    
  68.     // --------------------------------------------------------------
  69.     // Read configuration file
  70.     $filename   = CONFIGURATION_PATH . CONFIGURATION_NAME;
  71.     $handle     = fopen($filename, "r");
  72.    
  73.     if (!$handle)
  74.         die("Nie udało się otworzyć pliku!");
  75.  
  76.     $configSize = filesize($filename);
  77.     $configText = fread($handle, $configSize);
  78.    
  79.     fclose($handle);
  80.     // --------------------------------------------------------------
  81.    
  82.    
  83.    
  84.     // --------------------------------------------------------------
  85.     // Parse configuration
  86.     // Set variables
  87.     $word               = "";       // string of characters from whitespace to whitespace OR a curly bracket
  88.     $lastWord           = "";       // previously processed word
  89.     $wordStart          = -1;       // starting position of the current word; value above zero indicates that it's still being built
  90.     $bracketLevel       = 0;        // inside how many curly brackets
  91.     $inQuote            = false;    // inside quotation marks - ignore important characters
  92.     $foundUmcMapCycle   = false;    // inside umcmapcycle block
  93.     $foundCustom        = false;    // inside umcmapcycle custom block
  94.     $comment            = false;    // passed double slashes - ignore everything until end of line
  95.     $MapList            = array();  // storage for wanted information
  96.    
  97.    
  98.     // Go through each character
  99.     for ($i=0;  $i<$configSize;  $i++)
  100.     {      
  101.         // Start comment
  102.         if (!$inQuote  &&  $configText[$i]=="/"  &&  $configText[$i+1]=="/")
  103.             $comment = true;
  104.        
  105.         // End comment
  106.         if ($comment)
  107.             if ($configText[$i] == "\n")
  108.                 $comment = false;
  109.             else
  110.                 if ($wordStart < 0)
  111.                     continue;
  112.        
  113.        
  114.         // Word start
  115.         if (!ctype_space($configText[$i])  &&  $wordStart<0  &&  !$inQuote  &&  !$comment)
  116.             $wordStart = $i;
  117.            
  118.            
  119.         // Word end
  120.         if (!$inQuote  &&  $wordStart>=0  &&  (ctype_space($configText[$i])  ||  $configText[$wordStart]=="{"  ||  $configText[$wordStart]=="}"  ||  $comment))
  121.         {
  122.             // Word must have at least one character
  123.             $wordLength = $i - $wordStart;
  124.             if ($wordLength == 0)
  125.                 $wordLength = 1;
  126.                
  127.             // Derive word
  128.             $word       = substr($configText, $wordStart, $wordLength);
  129.             $wordStart  = -1;
  130.                    
  131.             // Opening bracket
  132.             if ($word == "{")
  133.                 $bracketLevel++;
  134.                
  135.             // Closing bracket
  136.             if ($word == "}")
  137.                 $bracketLevel--;
  138.            
  139.             // Check for umc_mapcycle group
  140.             if ($lastWord=="\"umc_mapcycle\""  &&  $bracketLevel==1)
  141.                 $foundUmcMapCycle = true;
  142.                    
  143.             if ($foundUmcMapCycle)
  144.             {
  145.                 // Left group
  146.                 if ($bracketLevel == 0)
  147.                     break;
  148.                        
  149.                 // Check if this sub-group contains custom maps
  150.                 if ($word=="{"  &&  $bracketLevel==2)
  151.                     if (stripos($lastWord,"custom") !== false)
  152.                         $foundCustom = true;
  153.                    
  154.                 // Left sub-group with custom maps
  155.                 if ($word=="}"  &&  $bracketLevel<2  &&  $foundCustom)
  156.                     $foundCustom = false;
  157.                        
  158.                 // Found map name - save it
  159.                 if ($foundCustom  &&  $word=="{"  &&  $bracketLevel==3)
  160.                     $MapList[] = str_replace("\"", "", $lastWord);
  161.             };
  162.            
  163.             $lastWord = $word;
  164.         };
  165.  
  166.        
  167.         // Enter / leave quotation
  168.         if ($configText[$i] == "\"")
  169.             $inQuote = !$inQuote;
  170.     };
  171.    
  172.     if (count($MapList) == 0)
  173.         die("Nie znaleziono dodatkowych map!");
  174.     // --------------------------------------------------------------
  175.    
  176.    
  177.    
  178.     // --------------------------------------------------------------
  179.     // Output list of maps with screenshots
  180.     // Get image list
  181.     $images = scandir(SCREENSHOT_THUMBNAIL_PATH);
  182.    
  183.    
  184.     // For each custom map
  185.     foreach ($MapList as $map)
  186.     {
  187.         // Display title
  188.         echo "<SPAN " . SCREENSHOT_TITLE_STYLE . ">";
  189.        
  190.         // Find colour for this map type
  191.         $ColorCurrent = $TitleColors[ substr($map,0,strpos($map, "_")) ];
  192.  
  193.         if ($ColorCurrent != NULL)
  194.             echo "<SPAN STYLE='color:#$ColorCurrent;'>$map</SPAN>";
  195.         else
  196.             echo $map;
  197.            
  198.         echo "</SPAN>";
  199.        
  200.        
  201.         // Display description
  202.         if ($MapDescription[$map] != NULL)
  203.             echo "<SPAN " . MAP_DESCRIPTION_STYLE . "> - {$MapDescription[$map]}</SPAN>";
  204.            
  205.         echo "\n<BR />\n<BR />\n";
  206.        
  207.        
  208.         // Find and display screenshots for this map
  209.         $index = 1;
  210.        
  211.         while (array_search("{$map}_{$index}" . SCREENSHOT_THUMBNAIL_NAME . ".jpg", $images) !== FALSE)
  212.         {
  213.             echo "<A HREF=\"" . SCREENSHOT_PATH . "{$map}_{$index}.jpg\">";
  214.             echo "<IMG " . SCREENSHOT_STYLE . " ALT=\"$map_$index.jpg\" TITLE=\"{$map}_{$index}\" SRC=\"" . SCREENSHOT_THUMBNAIL_PATH . "{$map}_{$index}" . SCREENSHOT_THUMBNAIL_NAME . ".jpg\">";
  215.             echo "</A>&nbsp;";
  216.            
  217.             $index++;
  218.         };
  219.        
  220.         if ($index == 1)
  221.             echo "Brak zdjęć";
  222.        
  223.         echo "\n<BR />\n<BR />\n";
  224.     };
  225.     // --------------------------------------------------------------
  226. ?>
  227. </BODY>
  228. </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement