2020-08-09 14:08:44 +00:00
|
|
|
|
<?php
|
2020-08-10 03:32:26 +00:00
|
|
|
|
ini_set('user_agent', 'GeMCAPI/4.1.0 (GeMC API Sync 1.1.0;Release)');
|
2020-08-10 03:49:44 +00:00
|
|
|
|
$active=array('mojang/launchermeta/mc/game/version_manifest.json','forge/last');
|
2020-08-10 09:28:12 +00:00
|
|
|
|
$type=array('.com','.net');
|
|
|
|
|
//[0]:mojang,[1]:fabricmc
|
2020-08-10 03:32:26 +00:00
|
|
|
|
function url_exists($url){
|
2020-08-09 14:08:44 +00:00
|
|
|
|
$opts = array(
|
|
|
|
|
'http'=>array(
|
|
|
|
|
'timeout'=>3,
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$context = stream_context_create($opts);
|
|
|
|
|
return @file_get_contents($url, false, $context);
|
|
|
|
|
}
|
|
|
|
|
function get_main_domain($file){
|
|
|
|
|
$str=preg_replace('/^[^\/]*\//is','',$file);
|
|
|
|
|
$str2=str_replace('/'.$str,'',$file);
|
|
|
|
|
return $str2;
|
|
|
|
|
}
|
|
|
|
|
function get_sub_domain($file){
|
|
|
|
|
$str=preg_replace('/^[^\/]*\//is','',$file);
|
|
|
|
|
$str2=preg_replace('/^[^\/]*\//is','',$str);
|
|
|
|
|
$str3=str_replace('/'.$str2,'',$str);
|
|
|
|
|
return $str3;
|
|
|
|
|
}
|
|
|
|
|
function get_file_path($file){
|
|
|
|
|
$str=preg_replace('/^[^\/]*\//is','',$file);
|
|
|
|
|
$str2=preg_replace('/^[^\/]*\//is','',$str);
|
|
|
|
|
return $str2;
|
|
|
|
|
}
|
|
|
|
|
function get_online_url($file,$id){
|
|
|
|
|
global $type;
|
|
|
|
|
$str='http://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/'.get_file_path($file);
|
|
|
|
|
return $str;
|
|
|
|
|
}
|
2020-08-10 09:28:12 +00:00
|
|
|
|
function get_online_domain($file,$id){
|
|
|
|
|
global $type;
|
|
|
|
|
$str='http://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/';
|
|
|
|
|
return $str;
|
|
|
|
|
}
|
|
|
|
|
function check_file_update($file,$dir,$url,$time){
|
|
|
|
|
header('Content-Disposition: attachment; filename="'.basename($file).'"');
|
2020-08-10 03:32:26 +00:00
|
|
|
|
$time=time()-@filemtime($file);
|
2020-08-10 09:28:12 +00:00
|
|
|
|
if($time<$time){//检查文件是否超出过期期限(1天,86400秒)
|
2020-08-09 14:08:44 +00:00
|
|
|
|
echo file_get_contents($file);
|
|
|
|
|
}else{
|
|
|
|
|
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
|
2020-08-10 03:32:26 +00:00
|
|
|
|
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file)){
|
2020-08-09 14:08:44 +00:00
|
|
|
|
echo file_get_contents($file);
|
|
|
|
|
}else{
|
|
|
|
|
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
|
2020-08-10 09:28:12 +00:00
|
|
|
|
$jsonwrite = fopen($file, "w") or die('{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":502,"server_time":"'.time().'"}');
|
2020-08-09 14:08:44 +00:00
|
|
|
|
fwrite($jsonwrite,file_get_contents($url.'/'.str_replace($dir,'',$file)));
|
|
|
|
|
fclose($jsonwrite);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
echo file_get_contents($file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-10 09:28:12 +00:00
|
|
|
|
function check_file_update_json($file,$dir,$url,$time){
|
|
|
|
|
header('Content-Disposition: attachment; filename="'.basename($file).'"');
|
|
|
|
|
$time=time()-@filemtime($file.'/index.json');
|
|
|
|
|
if($time<$time){//检查文件是否超出过期期限(1天,86400秒)
|
|
|
|
|
echo file_get_contents($file.'/index.json');
|
|
|
|
|
}else{
|
|
|
|
|
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
|
|
|
|
|
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file.'/index.json')){
|
|
|
|
|
echo file_get_contents($file);
|
|
|
|
|
}else{
|
|
|
|
|
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
|
|
|
|
|
$jsonwrite = fopen($file.'/index.json', "w") or die('{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":502,"server_time":"'.time().'"}');
|
|
|
|
|
fwrite($jsonwrite,file_get_contents($url.'/'.str_replace($dir,'',$file)));
|
|
|
|
|
fclose($jsonwrite);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
echo file_get_contents($file.'/index.json');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-10 03:32:26 +00:00
|
|
|
|
function check_file_update_adv($file,$url,$check_url){
|
2020-08-10 09:28:12 +00:00
|
|
|
|
header('Content-Disposition: attachment; filename="'.basename($file).'"');
|
2020-08-10 03:32:26 +00:00
|
|
|
|
$time=time()-@filemtime($file);
|
|
|
|
|
if($time<86400){//检查文件是否超出过期期限(1天,86400秒)
|
|
|
|
|
echo file_get_contents($file);
|
|
|
|
|
}else{
|
2020-08-10 09:28:12 +00:00
|
|
|
|
if(url_exists($check_url)){//防止源无法访问而损坏文件
|
2020-08-10 03:32:26 +00:00
|
|
|
|
if(file_get_contents($url)==@file_get_contents($file)){
|
|
|
|
|
echo file_get_contents($file);
|
|
|
|
|
}else{
|
|
|
|
|
echo @file_get_contents($url);
|
2020-08-10 09:28:12 +00:00
|
|
|
|
|
|
|
|
|
$jsonwrite = fopen($file, "w") or die('{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":502,"server_time":"'.time().'"}');
|
2020-08-10 03:32:26 +00:00
|
|
|
|
fwrite($jsonwrite,file_get_contents($url));
|
|
|
|
|
fclose($jsonwrite);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
echo file_get_contents($file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 14:08:44 +00:00
|
|
|
|
function download_file($url,$file,$other){//下载文件
|
|
|
|
|
system('python download.py --url "'.$url.'" --file "'.$file.'" --other "'.$other.'"');
|
|
|
|
|
}
|
2020-08-10 09:28:12 +00:00
|
|
|
|
if(get_main_domain($_GET['path'])=='mojang'){//分配顶级域名尾
|
|
|
|
|
$id=0;
|
|
|
|
|
}elseif(get_main_domain($_GET['path'])=='fabricmc'){
|
|
|
|
|
$id=1;
|
|
|
|
|
}
|
2020-08-09 14:08:44 +00:00
|
|
|
|
if($_GET['error']!=""){
|
2020-08-10 09:28:12 +00:00
|
|
|
|
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":'.$_GET['error'].',"server_time":"'.time().'"}';
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}elseif($_GET['path']==""){
|
2020-08-10 09:28:12 +00:00
|
|
|
|
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":200,"server_time":"'.time().'"}';
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}else{
|
|
|
|
|
if(is_file($_GET['path'])){
|
|
|
|
|
//文件存在
|
|
|
|
|
if(in_array($_GET['path'],$active)){//判断是否为需要保持最新的文件
|
|
|
|
|
if(strstr($_GET['path'],'mojang/')!=False){//目录分组
|
|
|
|
|
if(strstr($_GET['path'],'mojang/launchermeta/')!=False){
|
2020-08-10 09:28:12 +00:00
|
|
|
|
check_file_update('mojang/launchermeta/mc/game/version_manifest.json',get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/','http://launchermeta.mojang.com',86400);
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}
|
2020-08-10 03:49:44 +00:00
|
|
|
|
}elseif(strstr($_GET['path'],'forge/')!=False){//目录分组
|
|
|
|
|
if(strstr($_GET['path'],'forge/last')!=False){
|
|
|
|
|
check_file_update_adv('forge/last','https://download.mcbbs.net/forge/last','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
|
|
|
|
}
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}
|
2020-08-10 09:28:12 +00:00
|
|
|
|
}else{//无需频繁更新的文件
|
|
|
|
|
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
|
|
|
|
|
check_file_update($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000);
|
2020-08-10 03:32:26 +00:00
|
|
|
|
}else{
|
2020-08-10 09:28:12 +00:00
|
|
|
|
check_file_update_json($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000);
|
2020-08-10 03:32:26 +00:00
|
|
|
|
}
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}
|
|
|
|
|
}elseif(is_dir($_GET['path'])){
|
|
|
|
|
//目录存在
|
2020-08-10 03:32:26 +00:00
|
|
|
|
if(strstr($_GET['path'],'forge/minecraft')!=False){//特殊目录返回
|
|
|
|
|
check_file_update_adv('forge/minecraft/index.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
2020-08-10 09:28:12 +00:00
|
|
|
|
}elseif(is_file($_GET['path'].'/index.json')){
|
|
|
|
|
check_file_update($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),86400);
|
2020-08-10 03:32:26 +00:00
|
|
|
|
}else{
|
2020-08-10 09:28:12 +00:00
|
|
|
|
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
|
|
|
|
echo file_get_contents($_GET['path']);
|
2020-08-10 03:32:26 +00:00
|
|
|
|
}
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}else{
|
|
|
|
|
//目录或文件不存在
|
2020-08-10 09:28:12 +00:00
|
|
|
|
if(strstr($_GET['path'],'forge/')!=False){//特殊Forge,采用二级源 BMCLAPI
|
|
|
|
|
if(url_exists('https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar')){
|
2020-08-10 03:32:26 +00:00
|
|
|
|
if(strstr($_GET['path'],'forge/minecraft')!=False){//forge/minecraft目录特殊同步
|
|
|
|
|
if($_GET['path']=='forge/minecraft'){
|
|
|
|
|
check_file_update_adv('forge/minecraft/index.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
|
|
|
|
}else{
|
|
|
|
|
check_file_update_adv($_GET['path'],'https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
download_file('https://download.mcbbs.net/'.$_GET['path'],$_GET['path'],'');
|
2020-08-10 09:28:12 +00:00
|
|
|
|
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
|
|
|
|
echo file_get_contents($_GET['path']);
|
2020-08-10 03:32:26 +00:00
|
|
|
|
}
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}else{
|
2020-08-10 09:28:12 +00:00
|
|
|
|
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":"'.time().'"}';
|
2020-08-10 03:32:26 +00:00
|
|
|
|
header('HTTP/1.1 404 Not Found');
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if(url_exists(get_online_url($_GET['path'],$id))){
|
2020-08-10 09:28:12 +00:00
|
|
|
|
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
|
|
|
|
|
download_file(get_online_url($_GET['path'],$id),$_GET['path'],'');
|
|
|
|
|
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
|
|
|
|
echo file_get_contents($_GET['path']);
|
|
|
|
|
}else{
|
|
|
|
|
download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/index.json','');
|
|
|
|
|
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
|
|
|
|
echo file_get_contents($_GET['path'].'/index.json');
|
|
|
|
|
}
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}else{
|
2020-08-10 09:28:12 +00:00
|
|
|
|
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":"'.time().'"}';
|
2020-08-10 03:32:26 +00:00
|
|
|
|
header('HTTP/1.1 404 Not Found');
|
2020-08-09 14:08:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|