Cvolton / GMDprivateServer

Geometry Dash Private Server
GNU General Public License v3.0
388 stars 281 forks source link

Fix for Newgrounds song issue #964

Open mctood opened 1 year ago

mctood commented 1 year ago

Recently I faced with a bug when songs from Newgrounds wasn't downloading with error [Failed to fetch song info]. I've edited the /incl/misc/getGJSongInfo.php file to add SSL support for cURL parse request. So, anybody who have the same error can just replace /incl/misc/getGJSongInfo.php file contents with the code below.

<?php
chdir(dirname(__FILE__));
include "../lib/connection.php";
require_once "../lib/songReup.php";
$songReup = new songReup();
require_once "../lib/exploitPatch.php";
$ep = new exploitPatch();
if(empty($_POST["songID"])){
    exit("-1: 0");
}
$songid = $ep->remove($_POST["songID"]);
$query3=$db->prepare("SELECT ID,name,authorID,authorName,size,isDisabled,download FROM songs WHERE ID = :songid LIMIT 1");
$query3->execute([':songid' => $songid]);
if($query3->rowCount() == 0) {
    $url = 'http://www.boomlings.com/database/getGJSongInfo.php';
    $data = array('songID' => $songid, 'secret' => 'Wmfd2893gb7');
    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    if ($result == "-2" OR $result == "-1" OR $result == "") {
        $url = 'http://www.boomlings.com/database/getGJLevels21.php';
        $data = array(
            'gameVersion' => '21',
            'binaryVersion' => '33',
            'gdw' => '0',
            'type' => '2',
            'str' => '',
            'diff' => '-',
            'len' => '-',
            'page' => '0',
            'total' => '9999',
            'uncompleted' => '0',
            'onlyCompleted' => '0',
            'featured' => '0',
            'original' => '0',
            'twoPlayer' => '0',
            'coins' => '0',
            'epic' => '0',
            'song' => $songid,
            'customSong' => '1',
            'secret' => 'Wmfd2893gb7'
        );

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $result = curl_exec($ch);
        curl_close($ch);
        if(substr_count($result, "1~|~".$songid."~|~2") != 0){
            $result = explode('#',$result)[2];
        }else{
            $ch = curl_init(); 
            curl_setopt($ch, CURLOPT_URL, "https://www.newgrounds.com/audio/listen/".$songid); 
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            $songinfo = curl_exec($ch); 
            if (curl_errno($ch)) {
                exit( 'Error:' . curl_error($ch));
            }
            curl_close($ch);
            if(empty(explode('"url":"', $songinfo)[1])){
                exit("-1: 2::<br>".$songinfo.$songid);
            }
            $songurl = explode('","', explode('"url":"', $songinfo)[1])[0];
            $songauthor = explode('","', explode('artist":"', $songinfo)[1])[0];
            $songurl = str_replace("\/", "/", $songurl);
            $songname = explode("<title>", explode("</title>", $songinfo)[0])[1];
            preg_match('/\d+\.?\d*(?=<span>MB<\/span>)/mi', preg_replace("/\s+/", "", $songinfo), $size);
            if($songurl == ""){
                exit("-1: 3");
            }
            $result = "1~|~".$songid."~|~2~|~".$songname."~|~3~|~1234~|~4~|~".$songauthor."~|~5~|~".$size[0]."~|~6~|~~|~10~|~".$songurl."~|~7~|~~|~8~|~1";
        }
    }
    echo $result;
    $reup = $songReup->reup($result);
}else{
    $result4 = $query3->fetch();
    if($result4["isDisabled"] == 1){
        exit("-2");
    }
    $dl = $result4["download"];
    if(strpos($dl, ':') !== false){
        $dl = urlencode($dl);
    }
    echo "1~|~".$result4["ID"]."~|~2~|~".$result4["name"]."~|~3~|~".$result4["authorID"]."~|~4~|~".$result4["authorName"]."~|~5~|~".$result4["size"]."~|~6~|~~|~10~|~".$dl."~|~7~|~~|~8~|~0";
}
?>
MegaSa1nt commented 1 year ago

just make pull request