[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.

addrelease.php 6.7KB

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