<?php
+require_once 'Paths.php';
class GameInfo
{
*/
public function getIdFromUuid(string $gameuuid): ?int
{
- $cacheDir = __DIR__ . '/../cache/';
- $connectAppsCacheFile = $cacheDir . 'connect-apps.min.json';
- $data = json_decode(file_get_contents($connectAppsCacheFile));
+ $paths = new Paths();
+ $data = json_decode(file_get_contents($paths->apps()));
foreach ($data as $game) {
if ($game->version == $gameuuid) {
return $game->id;
<?php
+require_once 'Paths.php';
require_once 'User.php';
/**
public string $created_at;
public string $updated_at;
+ public function calculateSessionId(): string
+ {
+ $paths = new Paths();
+ $data = [
+ $this->id,
+ $this->hwId,
+ $this->verificationCode,
+ $this->created_at,
+ $this->getUser()->updated_at,
+ filemtime($paths->apps()),
+ filemtime($paths->featuredAges()),
+ filemtime($paths->uiTranslation()),
+ $paths->pjgsapiVersion(),
+ ];
+
+ return strtoupper(md5(implode(':', $data)));
+ }
+
public function getUser(): User
{
$userRepository = new UserRepository();
--- /dev/null
+<?php
+
+class Paths
+{
+ protected $cacheDir;
+
+ public function __construct()
+ {
+ $this->cacheDir = dirname(__FILE__, 2) . '/cache/';
+ }
+
+ public function apps(): string
+ {
+ return $this->cacheDir . 'connect-apps.min.json';
+ }
+
+ public function featuredAges(): string
+ {
+ return $this->cacheDir . 'connect-featured-ages.min.json';
+ }
+
+ public function uiTranslation(): string
+ {
+ return $this->cacheDir . 'connect-uitranslation.min.json';
+ }
+
+ public function pjgsapiVersion(): string
+ {
+ $hash = exec('git -c safe.directory="*" rev-parse HEAD', $output, $exitCode);
+ if ($exitCode !== 0) {
+ return date('Y-m-d');//change at least once a day
+ }
+
+ return trim($hash);
+ }
+}
Gamestick info
curl -i gamestick.cwboo/api/rest/connect/stick/stick/ac:db:da:09:18:5c/view.json
+curl -Is --cookie JSESSIONID=AD303D903A507D8E728DAAE99FB85726 gamestick.cwboo/api/rest/connect/stick/stick/ac:db:da:09:18:5c/view.json
+curl -Is 'gamestick.cwboo/api/rest/connect/stick/stick/ac:db:da:09:18:5c/view.json;jsessionid=AD303D903A507D8E728DAAE99FB85726'
Firmware update check
curl -i gamestick.cwboo/check.php --data v='{"hwid":"ac:db:da:09:18:5c","major":0,"minor":0,"revision":53,"platform":0}'
}
+$calculatedSessionId = $gamestick->calculateSessionId();
+if ($sessionId === $calculatedSessionId) {
+ header('HTTP/1.0 304 Not Modified');
+ exit();
+}
+
+if ($gamestick->sessionId !== $calculatedSessionId) {
+ $gamestick->sessionId = $calculatedSessionId;
+ $gamestick->update(['sessionId' => $calculatedSessionId]);
+}
+
+
$data = [
'sid' => $gamestick->sessionId,
'time' => (string) $nowMilli,
$json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
+require_once $rootDir . '/src/Paths.php';
+$paths = new Paths();
$placeholderFiles = [
- 'PLACEHOLDER_APPS' => $cacheDir . 'connect-apps.min.json',
- 'PLACEHOLDER_AGES' => $cacheDir . 'connect-featured-ages.min.json',
- 'PLACEHOLDER_UITRANSLATION' => $cacheDir . 'connect-uitranslation.min.json',
+ 'PLACEHOLDER_APPS' => $paths->apps(),
+ 'PLACEHOLDER_AGES' => $paths->featuredAges(),
+ 'PLACEHOLDER_UITRANSLATION' => $paths->uiTranslation(),
];
foreach ($placeholderFiles as $placeholder => $cacheFile) {
//inject apps