Skip to content
26 changes: 26 additions & 0 deletions db/migrations/20260523222340_add_time_zone_user_setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddTimeZoneUserSetting extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$table = $this->table('sys_users');
$table->addColumn('timezone', 'string', ['limit' => 255, 'null' => false, 'default' => '+0900'])
->update();
}
}
97 changes: 53 additions & 44 deletions web/cgb/mario_kart.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
// SPDX-License-Identifier: MIT
require_once(CORE_PATH."/database.php");
require_once(CORE_PATH."/timezone.php");

function getDownloadGameRegions() {
$game_region = getCurrentGameRegion();
Expand Down Expand Up @@ -79,7 +80,7 @@ function decodePlayerID($myid) {
);
}

function checkPlayerID($myid, $user_id) {
function checkPlayerID($myid, $user_id = null) {
$config = getConfig();

$decoded = decodePlayerID($myid);
Expand All @@ -88,19 +89,21 @@ function checkPlayerID($myid, $user_id) {
}

$db = connectMySQL();
$stmt = $db->prepare("select dion_email_local from sys_users where id = ?");
$stmt->bind_param("i", $user_id);
$stmt = $db->prepare("select id from sys_users where dion_email_local = ?");
$stmt->bind_param("s", $decoded["email_id"]);
$stmt->execute();
$result = fancy_get_result($stmt);
if (sizeof($result) == 0) {
return false;
}

if ($result[0]["dion_email_local"] !== $decoded["email_id"]) {

if (is_null($user_id)) {
return $result[0]["id"];
} elseif ($result[0]["id"] !== $user_id) {
return false;
} else {
return true;
}

return true;
}

function getCurrentMobileGP() {
Expand Down Expand Up @@ -279,11 +282,12 @@ function getOwnRankMobileGP($gp_id, $myid) {
}

function makeGhostDownload($result, $course) {
$output = pack("n", date("Y", time() + 32400)) // Year
.pack("C", date("m", time() + 32400)) // Month
.pack("C", date("d", time() + 32400)) // Day
.pack("C", date("H", time() + 32400)) // Hour
.pack("C", date("i")); // Minute
$time = get_user_local_time();
$output = pack("n", $time->format("Y")) // Year
.pack("C", $time->format("m")) // Month
.pack("C", $time->format("d")) // Day
.pack("C", $time->format("H")) // Hour
.pack("C", $time->format("i")); // Minute

$total = getTotalRankingEntries($course);

Expand Down Expand Up @@ -394,11 +398,12 @@ function getPlayerIDByRank($course) { // 0.dlghostid.cgb (unused)
$stmt->execute();
$result = fancy_get_result($stmt);

$output = pack("n", date("Y", time() + 32400)) // Year
.pack("C", date("m", time() + 32400)) // Month
.pack("C", date("d", time() + 32400)) // Day
.pack("C", date("H", time() + 32400)) // Hour
.pack("C", date("i")); // Minute
$time = get_user_local_time();
$output = pack("n", $time->format("Y")) // Year
.pack("C", $time->format("m")) // Month
.pack("C", $time->format("d")) // Day
.pack("C", $time->format("H")) // Hour
.pack("C", $time->format("i")); // Minute

$output = $output.pack("N", getTotalRankingEntries($course)); // Seems to indicate if something was found
$output = $output.pack("n", sizeof($result)); // Seems to indicate if data is present
Expand Down Expand Up @@ -431,11 +436,12 @@ function getPlayerIDByStateRank($course) { // 0.dlghostst.cgb
$stmt->execute();
$result = fancy_get_result($stmt);

$output = pack("n", date("Y", time() + 32400)) // Year
.pack("C", date("m", time() + 32400)) // Month
.pack("C", date("d", time() + 32400)) // Day
.pack("C", date("H", time() + 32400)) // Hour
.pack("C", date("i")); // Minute
$time = get_user_local_time();
$output = pack("n", $time->format("Y")) // Year
.pack("C", $time->format("m")) // Month
.pack("C", $time->format("d")) // Day
.pack("C", $time->format("H")) // Hour
.pack("C", $time->format("i")); // Minute

$output = $output.pack("N", getTotalRankingEntriesState($course, $state)); // Seems to indicate if something was found
$output = $output.pack("n", sizeof($result)); // Seems to indicate if data is present
Expand Down Expand Up @@ -468,11 +474,12 @@ function getPlayerIDByDriverRank($course) { // 0.dlghostdr.cgb
$stmt->execute();
$result = fancy_get_result($stmt);

$output = pack("n", date("Y", time() + 32400)) // Year
.pack("C", date("m", time() + 32400)) // Month
.pack("C", date("d", time() + 32400)) // Day
.pack("C", date("H", time() + 32400)) // Hour
.pack("C", date("i")); // Minute
$time = get_user_local_time();
$output = pack("n", $time->format("Y")) // Year
.pack("C", $time->format("m")) // Month
.pack("C", $time->format("d")) // Day
.pack("C", $time->format("H")) // Hour
.pack("C", $time->format("i")); // Minute

$output = $output.pack("N", getTotalRankingEntriesDriver($course, $driver)); // Seems to indicate if something was found
$output = $output.pack("n", sizeof($result)); // Seems to indicate if data is present
Expand Down Expand Up @@ -595,22 +602,24 @@ function query($course) { // query.cgb
return;
}
$myid = hex2bin($params["myid"]);
/*if (!checkPlayerID($myid, null)) {
$user_id = checkPlayerID($myid);
if ($user_id === false) {
http_response_code(400);
return;
}*/
}
$state = hexdec($params["state"]);
$driver = hexdec($params["driver"]);
$rk = array();
for ($i = 1; $i < 12; $i++) {
array_push($rk, hexdec($params["rk_".$i]));
}

echo pack("n", date("Y", time() + 32400)); // Year
echo pack("C", date("m", time() + 32400)); // Month
echo pack("C", date("d", time() + 32400)); // Day
echo pack("C", date("H", time() + 32400)); // Hour
echo pack("C", date("i")); // Minute
$time = get_user_local_time($user_id);
echo pack("n", $time->format("Y")); // Year
echo pack("C", $time->format("m")); // Month
echo pack("C", $time->format("d")); // Day
echo pack("C", $time->format("H")); // Hour
echo pack("C", $time->format("i")); // Minute

echo pack("N", getTotalRankingEntries($course)); // Probably total amount of ranked players

Expand Down Expand Up @@ -656,11 +665,11 @@ function query($course) { // query.cgb

// --- State top 10 --- //

echo pack("n", date("Y", time() + 32400)); // Year
echo pack("C", date("m", time() + 32400)); // Month
echo pack("C", date("d", time() + 32400)); // Day
echo pack("C", date("H", time() + 32400)); // Hour
echo pack("C", date("i")); // Minute
echo pack("n", $time->format("Y")); // Year
echo pack("C", $time->format("m")); // Month
echo pack("C", $time->format("d")); // Day
echo pack("C", $time->format("H")); // Hour
echo pack("C", $time->format("i")); // Minute

echo pack("N", getTotalRankingEntriesState($course, $state)); // Probably total amount of ranked players

Expand Down Expand Up @@ -690,11 +699,11 @@ function query($course) { // query.cgb

// --- Driver top 10 --- //

echo pack("n", date("Y", time() + 32400)); // Year
echo pack("C", date("m", time() + 32400)); // Month
echo pack("C", date("d", time() + 32400)); // Day
echo pack("C", date("H", time() + 32400)); // Hour
echo pack("C", date("i")); // Minute
echo pack("n", $time->format("Y")); // Year
echo pack("C", $time->format("m")); // Month
echo pack("C", $time->format("d")); // Day
echo pack("C", $time->format("H")); // Hour
echo pack("C", $time->format("i")); // Minute

echo pack("N", getTotalRankingEntriesDriver($course, $driver)); // Probably total amount of ranked players

Expand Down
14 changes: 8 additions & 6 deletions web/cgb/ranking/01/AGB-AMKJ/mobilegp/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
return;
}
$myid = hex2bin($params["myid"]);
if (!checkPlayerID($myid, null)) {
$user_id = checkPlayerID($myid);
if ($user_id === false) {
http_response_code(400);
return;
}
Expand All @@ -22,11 +23,12 @@

$gp_id = getCurrentMobileGP();

echo pack("n", date("Y", time() + 32400)); // Year
echo pack("C", date("m", time() + 32400)); // Month
echo pack("C", date("d", time() + 32400)); // Day
echo pack("C", date("H", time() + 32400)); // Hour
echo pack("C", date("i")); // Minute
$time = get_user_local_time($user_id);
echo pack("n", $time->format("Y")); // Year
echo pack("C", $time->format("m")); // Month
echo pack("C", $time->format("d")); // Day
echo pack("C", $time->format("H")); // Hour
echo pack("C", $time->format("i")); // Minute

echo pack("N", getTotalRankingEntriesMobileGP($gp_id));

Expand Down
14 changes: 8 additions & 6 deletions web/cgb/ranking/A4/AGB-AMGJ/0.query.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
// SPDX-License-Identifier: MIT
require_once(CORE_PATH."/database.php");
require_once(CORE_PATH."/timezone.php");

$db = connectMySQL();

Expand All @@ -9,7 +10,7 @@
http_response_code(500);
return;
}
$stmt = $db->prepare("select count(*) from amg_rankings");
$stmt = $db->prepare("select count(*) from amg_rankings");
$stmt->execute();
$result = fancy_get_result($stmt);
$count = $result[0]["count(*)"];
Expand All @@ -35,11 +36,12 @@
}
}

echo pack("n", date("Y", time() + 32400));
echo pack("C", date("m", time() + 32400));
echo pack("C", date("d", time() + 32400));
echo pack("C", date("H", time() + 32400));
echo pack("C", date("i"));
$time = get_user_local_time();
echo pack("n", $time->format("Y")); // Year
echo pack("C", $time->format("m")); // Month
echo pack("C", $time->format("d")); // Day
echo pack("C", $time->format("H")); // Hour
echo pack("C", $time->format("i")); // Minute

echo pack("n", sizeof($top10));
for ($i = 0; $i < sizeof($top10); $i++) {
Expand Down
22 changes: 22 additions & 0 deletions web/cgb/timezone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// SPDX-License-Identifier: MIT
require_once(CORE_PATH."/database.php");

function get_user_local_time($user_id = null) {
$tz = "+0900";
if (session_status() == PHP_SESSION_ACTIVE) {
$user_id = $_SESSION['userId'];
}
if (!is_null($user_id)) {
$db = connectMySQL();
$stmt = $db->prepare("select timezone from sys_users where id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = fancy_get_result($stmt);
if (sizeof($result) != 0) {
$tz = $result[0]["timezone"];
}
}
return date_create_immutable("now", timezone_open($tz));
}
?>
12 changes: 7 additions & 5 deletions web/cgb/upload/A4/AGB-AMGJ/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
http_response_code(500);
return;
}
$stmt = $db->prepare("select count(*) from sys_users where dion_email_local = ?");

$stmt = $db->prepare("select id from sys_users where dion_email_local = ?");
$stmt->bind_param("s", $dion_email_local);
$stmt->execute();
$result = fancy_get_result($stmt);
if ($result[0]["count(*)"] == 0) {
if (sizeof($result) == 0) {
http_response_code(400);
return;
}
Expand All @@ -41,9 +42,10 @@
return;
}

echo pack("n", date("Y", time() + 32400));
echo pack("C", date("m", time() + 32400));
echo pack("C", date("d", time() + 32400));
$time = get_user_local_time($result[0]["id"]);
echo pack("n", $time->format("Y")); // Year
echo pack("C", $time->format("m")); // Month
echo pack("C", $time->format("d")); // Day

$stmt = $db->prepare("select id, weight from amg_rankings where ident = ? and game_region = ?");
$stmt->bind_param("ss", $ident, $game_region);
Expand Down
14 changes: 13 additions & 1 deletion web/htdocs/user/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@
$errors[] = "pokemonNewsValue";
}
}
if (array_key_exists("timeZone", $_POST)) {
if ($_POST["timeZone"] === "+0900" || in_array($_POST["timeZone"], timezone_identifiers_list(), true)) {
$db = DBUtil::getInstance()->getDB();
$stmt = $db->prepare("update sys_users set timezone = ? where id = ?");
$stmt->bind_param("si", $_POST["timeZone"], $_SESSION["user_id"]);
$stmt->execute();
} else {
$errors[] = "timeZoneValue";
}
}



$db = $db_util->getDB();
$stmt = $db->prepare("select email, dion_ppp_id, dion_email_local, log_in_password, money_spent, trade_region_allowlist, custom_pokemon_news_opt_in from sys_users where id = ?");
$stmt = $db->prepare("select email, dion_ppp_id, dion_email_local, log_in_password, money_spent, trade_region_allowlist, custom_pokemon_news_opt_in, timezone from sys_users where id = ?");
$stmt->bind_param("i", $_SESSION["user_id"]);
$stmt->execute();
$result = DBUtil::fancy_get_result($stmt)[0];
Expand All @@ -55,6 +65,8 @@
"money_spent" => $result["money_spent"],
"trade_region_allowlist" => $result["trade_region_allowlist"],
"pokemon_news_custom_opt_in" => intval($result["custom_pokemon_news_opt_in"]),
"time_zone" => $result["timezone"],
"all_time_zones" => timezone_identifiers_list(),
"inbox_size" => $inbox_size,
"errors" => $errors
]);
Expand Down
7 changes: 6 additions & 1 deletion web/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ wrong-password: Wrong password
link-invalid-expired: This link is invalid or has expired.
invalid-trade-setting: Not a valid region pool setting.
invalid-pokemon-news-setting: Not a valid Pokémon news preference.
invalid-time-zone-setting: Not a valid time zone setting.
default-time-zone: UTC+9 (default)
auth:
login-to-reon: Login to your REON account
invalid-email-pass: Incorrect email or password
Expand Down Expand Up @@ -92,7 +94,7 @@ account:
email-changed-success: Your email was changed successfully.
change-your-password: Change your password
password-changed-success: Your password was changed successfully.
pokemon-crystal-settings: Pokémon Crystal settings
pokemon-crystal-settings: Other settings
trade-corner-region-allowlist: 'Trade Corner: Trading Preferences'
trade-region-allowlist-blurb: Select the region pool you’re willing to trade with
when you deposit your Pokémon in the Trade Corner. Any match you receive will
Expand All @@ -109,6 +111,9 @@ account:
If no custom news exists, official news will be used instead.
pokemon-news-custom-opt-in-off: Official Pokémon News only
pokemon-news-custom-opt-in-on: Custom Pokémon News when available
time-zone: Time zone preference
time-zone-blurb: The time zone to use for in-game timestamps.
Note that UTC+9 timestamps may appear depending on the game and context.
index:
what-is-reon: What is REON?
reon-description: REON is something.
Expand Down
Loading
Loading