[ARCHIVE 2012] Récupère des informations sur les nouvelles versions de Minecraft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

preRelease.php 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. set_time_limit('240');
  3. addRelease('1_2_5');
  4. function addRelease($input) {
  5. $debug = false;
  6. // Définition des variables de travail
  7. $lastVersions_e = explode('|', file_get_contents('lastVersions.txt'));
  8. $lastVersions_e_backup = $lastVersions_e;
  9. if ($input == 'r') {
  10. $lastVersions_e[1] = 'UP';
  11. } else {
  12. $lastVersions_e[3] = 'UP';
  13. }
  14. // Enregistrement des données d'ajout
  15. $lastVersions_e[0] = time();
  16. $lastVersions_txt = fopen('lastVersions.txt', 'w');
  17. fwrite($lastVersions_txt, implode('|', $lastVersions_e));
  18. fclose($lastVersions_txt);
  19. if ($input == 'r') {
  20. $type = 'r';
  21. $url = 'http://s3.amazonaws.com/MinecraftDownload/minecraft.jar';
  22. } else {
  23. $type = 'pr';
  24. $url = 'http://assets.minecraft.net/'.$input.'/minecraft.jar';
  25. }
  26. // Chargement du XML
  27. $data = new DomDocument();
  28. $data->load('data.xml');
  29. $dataNode = $data->getElementsByTagName('data')->item(0);
  30. $mcupdatesNode = $dataNode->getElementsByTagName('mcupdates')->item(0);
  31. $id = $mcupdatesNode->getAttribute('total')+1;
  32. $releaseS = $mcupdatesNode->getElementsByTagName('release');
  33. $release = $releaseS->item($releaseS->length-1);
  34. // Creation du noeud XML
  35. $releaseNode = $data->createElement('release');
  36. $mcupdatesNode->appendChild($releaseNode);
  37. $infosNode = $data->createElement('infos');
  38. $releaseNode->appendChild($infosNode);
  39. $files = $data->createElement('files');
  40. $releaseNode->appendChild($files);
  41. // Extraction et copie de minecraft.jar
  42. $directory = $id.' - '.$lastVersions_e[0].' ('.rand(1, 1000).')';
  43. if (!mkdir($directory) OR !copy($url, $directory.'/minecraft.jar')) { return 'ERREUR Impossible de copier le fichier ou de créer un nouveau dossier.';}
  44. $zip = new ZipArchive;
  45. if ($zip->open($directory.'/minecraft.jar') AND mkdir($directory.'/content')) {
  46. $zip->extractTo($directory.'/content');
  47. $zip->close();
  48. } else {
  49. return 'ERREUR Impossible d\'extraire le fichier ou de créer un nouveau dossier.';
  50. }
  51. $md5 = md5_file($directory.'/minecraft.jar');
  52. directoryConstruct($directory.'/content', $files, $data, directoryOld($release));
  53. // Detection de $givenName
  54. // Code par @EphysPatato
  55. $minecraft_class = file_get_contents($directory.'/content/net/minecraft/client/Minecraft.class');
  56. $givenName = 'false';
  57. if (preg_match('/Minecraft Minecraft (.+)Minecraft main/', $minecraft_class, $matches)) {
  58. $givenName = '';
  59. $givenName_w = $matches[count($matches)-1];
  60. for( $i = 0 ; $i < strlen($givenName_w) ; $i++ )
  61. {
  62. $givenName_cw = substr($givenName_w, $i, 1);
  63. if(($givenName_cw >= 'a' && $givenName_cw <= 'z') || ($givenName_cw >= 'A' && $givenName_cw <= 'Z') || ($givenName_cw >= '0' && $givenName_cw <= '9') || $givenName_cw == '|' || $givenName_cw == '.' || $givenName_cw == '_' || $givenName_cw == '-')
  64. $givenName .= $givenName_cw;
  65. }
  66. }
  67. // Spécifications selon le type de release
  68. if ($type == 'r') {
  69. $name = $givenName;
  70. $lastVersions_e[1] = $name;
  71. $lastVersions_e[2] = $md5;
  72. $infosNode->setAttribute('wiki', 'http://www.minecraftwiki.net/wiki/Version_history#'.$name);
  73. } else {
  74. $name = $input;
  75. $lastVersions_e[3] = $name;
  76. $lastVersions_e[4] = $md5;
  77. $infosNode->setAttribute('wiki', 'http://www.minecraftwiki.net/wiki/Version_history/Development_versions#'.$name);
  78. }
  79. // Mise des infos dans le XML
  80. $releaseNode->setAttribute('id', $id);
  81. $releaseNode->setAttribute('name', $name);
  82. $releaseNode->setAttribute('type', $type);
  83. $infosNode->setAttribute('givenName', $givenName);
  84. $infosNode->setAttribute('directory', $directory);
  85. $infosNode->setAttribute('link', $url);
  86. $infosNode->setAttribute('size', filesize($directory.'/minecraft.jar'));
  87. $infosNode->setAttribute('md5', $md5);
  88. $infosNode->setAttribute('sha1', sha1_file($directory.'/minecraft.jar'));
  89. $infosNode->setAttribute('date', $lastVersions_e[0]);
  90. $infosNode->setAttribute('shortDescription', 'false');
  91. $mcupdatesNode->setAttribute('total', $id);
  92. // Sauvegarde finale
  93. $lastVersions_e[0] = time();
  94. $lastVersions_e[5] = $id;
  95. $lastVersions_e[6] = $name;
  96. $lastVersions_e[7] = $type;
  97. $id = $mcupdatesNode->setAttribute('total', $id);
  98. $lastVersions_f = fopen('lastVersions.txt', 'w');
  99. $lastError = error_get_last();
  100. if ($debug) { echo substr($lastError['file'], -14); }
  101. if ($lastError /*AND $lastError['type']!= 2 */AND substr($lastError['file'], -14) == 'addrelease.php') {
  102. fwrite($lastVersions_f, implode('|', $lastVersions_e_backup));
  103. rrmdir($directory);
  104. return 'ERREUR "'.$lastError['message'].'" (type : '.$lastError['type'].') dans '.$lastError['file'].' ligne '.$lastError['line'].'.';
  105. } else {
  106. $data->save('data.xml');
  107. fwrite($lastVersions_f, implode('|', $lastVersions_e));
  108. fclose($lastVersions_f);
  109. return implode('|', $lastVersions_e);
  110. }
  111. }
  112. function directoryConstruct($directoryName, $XML, $data, $array) {
  113. $directory = opendir($directoryName);
  114. while($file = readdir($directory)) {
  115. if ($file != '.' AND $file != '..') {
  116. if (is_dir($directoryName.'/'.$file)) {
  117. $newDirectory = $data->createElement('dir');
  118. $XML->appendChild($newDirectory);
  119. $newDirectory->setAttribute('name', $file);
  120. if (isset($array[$file])) {
  121. $newDirectory->setAttribute('comparaison', 'same');
  122. directoryConstruct($directoryName.'/'.$file, $newDirectory, $data, $array[$file]);
  123. } else {
  124. $newDirectory->setAttribute('comparaison', 'added');
  125. directoryConstruct($directoryName.'/'.$file, $newDirectory, $data, array());
  126. }
  127. } else {
  128. $fileXML = $data->createElement('file');
  129. $XML->appendChild($fileXML);
  130. $fileXML->setAttribute('name', $file);
  131. $fileXML->setAttribute('md5', md5_file($directoryName.'/'.$file));
  132. if (isset($array[$file])) {
  133. if ($array[$file] == md5_file($directoryName.'/'.$file)) {
  134. $fileXML->setAttribute('comparaison', 'same');
  135. } else {
  136. $fileXML->setAttribute('comparaison', 'change');
  137. }
  138. } else {
  139. $fileXML->setAttribute('comparaison', 'added');
  140. }
  141. // TODO Verifier si un fichier a été supprimé
  142. }
  143. }
  144. }
  145. }
  146. function directoryOld($XML) {
  147. $array = array();
  148. $dirS = $XML->getElementsByTagName('dir');
  149. for ($c = $dirS->length, $i = 0; $i < $c; $i++) {
  150. $dir = $dirS->item($i);
  151. $array[$dir->getAttribute('name')]= directoryOld($dir);
  152. }
  153. $fileS = $XML->getElementsByTagName('file');
  154. for ($c = $fileS->length, $i = 0; $i < $c; $i++) {
  155. $file = $fileS->item($i);
  156. $array[$file->getAttribute('name')] = $file->getAttribute('md5');
  157. }
  158. return $array;
  159. }
  160. function rrmdir($dir) { // Par holger1@NOSPAMzentralplan.de
  161. if (is_dir($dir)) {
  162. $objects = scandir($dir);
  163. foreach ($objects as $object) {
  164. if ($object != "." && $object != "..") {
  165. if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
  166. }
  167. }
  168. reset($objects);
  169. rmdir($dir);
  170. }
  171. }
  172. ?>