psmreborn/common.php

151 lines
2.8 KiB
PHP
Raw Normal View History

2019-06-17 13:41:37 +00:00
<?php
function update_rifs()
{
2020-04-08 21:05:22 +00:00
$npsTime = filemtime("NpsPsm.tsv");
2021-03-25 12:37:35 +00:00
$npsPendingTime = filemtime("NpsPendingPsm.tsv");
2020-04-08 21:05:22 +00:00
if(time() > $npsTime + 86400)
2019-06-17 13:41:37 +00:00
{
2020-04-08 21:05:22 +00:00
rename("NpsPsm.tsv","nps-backup/NpsPsm_".strval($npsTime).".tsv");
2021-03-25 12:37:35 +00:00
rename("NpsPendingPsm.tsv","nps-backup/NpsPendingPsm_".strval($npsPendingTime).".tsv");
file_put_contents("NpsPsm.tsv", file_get_contents("http://nopaystation.com/tsv/PSM_GAMES.tsv"));
2021-03-25 12:37:35 +00:00
file_put_contents("NpsPendingPsm.tsv", file_get_contents("https://nopaystation.com/tsv/pending/PSM_GAMES.tsv"));
2019-06-17 13:41:37 +00:00
}
}
update_rifs();
2021-03-25 12:37:35 +00:00
if(strcmp($_SERVER['HTTP_HOST'],"psmreborn.com") !== 0)
2020-04-08 21:05:22 +00:00
{
2021-03-25 12:37:35 +00:00
if(strcmp($_SERVER['HTTP_HOST'],"psm.cbps.xyz") !== 0)
{
die("Invalid request! HOST: ".$_SERVER['HTTP_HOST']);
}
2020-04-08 21:05:22 +00:00
}
2019-06-17 13:41:37 +00:00
2019-07-29 12:10:20 +00:00
function getTitle(string $game)
{
$xml = simplexml_load_file('gameinfo/' . $game . "/app.xml", 'SimpleXMLElement', LIBXML_NOENT);
$title = $xml->name->localized_item[0]->attributes()->value;
unset($xml);
return $title;
}
2019-06-17 13:41:37 +00:00
function getPlayableList()
{
$playable_list = (array)null;
$delimiter = "\t";
$fp = fopen("NpsPsm.tsv", 'r');
while (!feof($fp))
{
$line = fgets($fp, 2048);
$data = str_getcsv($line, $delimiter);
$playable = 0;
if($data[4] != "MISSING")
{
$playable = 1;
}
$playable_list[$data[0]] = $playable;
}
fclose($fp);
return $playable_list;
}
2021-03-25 12:37:35 +00:00
function getPendingPlayableList()
{
$playable_list = (array)null;
$delimiter = "\t";
$fp = fopen("NpsPendingPsm.tsv", 'r');
while (!feof($fp))
{
$line = fgets($fp, 2048);
$data = str_getcsv($line, $delimiter);
$playable = 0;
if($data[4] != "MISSING")
{
$playable = 1;
}
$gameTid = basename($data[3], "_00.pkg");
$playable_list[$gameTid] = $playable;
}
fclose($fp);
return $playable_list;
}
2019-06-17 13:41:37 +00:00
function getZRIF(string $titleid)
{
$delimiter = "\t";
$fp = fopen("NpsPsm.tsv", 'r');
2021-08-08 13:23:19 +00:00
// Workaround for NPS having multiple entries for some reason
$zrif = "MISSING";
2019-06-17 13:41:37 +00:00
while ( !feof($fp) )
{
$line = fgets($fp, 2048);
$data = str_getcsv($line, $delimiter);
if($data[0] == $titleid)
{
2021-08-08 13:23:19 +00:00
$zrif = $data[4];
2019-06-17 13:41:37 +00:00
}
2021-08-08 13:23:19 +00:00
}
2019-06-17 13:41:37 +00:00
fclose($fp);
2021-08-08 13:23:19 +00:00
return $zrif;
2019-06-17 13:41:37 +00:00
}
2021-03-25 12:37:35 +00:00
function getPendingZRIF(string $titleid)
{
$delimiter = "\t";
$fp = fopen("NpsPendingPsm.tsv", 'r');
while ( !feof($fp) )
{
$line = fgets($fp, 2048);
$data = str_getcsv($line, $delimiter);
$gameTid = basename($data[3], "_00.pkg");
if($gameTid == $titleid)
{
return($data[4]);
}
}
fclose($fp);
return "MISSING";
}
2019-06-17 13:41:37 +00:00
function getPKG(string $titleid)
{
$delimiter = "\t";
$fp = fopen("NpsPsm.tsv", 'r');
while ( !feof($fp) )
{
$line = fgets($fp, 2048);
$data = str_getcsv($line, $delimiter);
if($data[0] == $titleid)
{
return($data[3]);
}
}
fclose($fp);
}
2020-04-08 21:05:22 +00:00
?>