Skip to content

Commit

Permalink
Merge branch 'master' into 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
thommcgrath committed Jan 30, 2024
2 parents 1ee3721 + 9c47756 commit a9ca057
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 29 deletions.
3 changes: 1 addition & 2 deletions Website/api/slack/commands/createcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
$productId = BeaconShop::GetProductByTag('USD', 'ArkSA', 'Base');
break;
case 'palworld':
case 'minimal':
$productId = BeaconShop::GetProductByTag('USD', 'BeaconMinimal', 'Base');
$productId = BeaconShop::GetProductByTag('USD', 'Palworld', 'Base');
break;
default:
PostReply('Unknown game_id value.');
Expand Down
3 changes: 1 addition & 2 deletions Website/api/slack/commands/grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
case 'curator':
$product = BeaconShop::GetProductByTag('USD', 'Curator', 'Base');
break;
case 'minimal':
case 'palworld':
$product = BeaconShop::GetProductByTag('USD', 'BeaconMinimal', 'Base');
$product = BeaconShop::GetProductByTag('USD', 'Palworld', 'Base');
break;
default:
PostReply('Unknown game_id value.');
Expand Down
14 changes: 3 additions & 11 deletions Website/api/v4/classes/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class License extends DatabaseObject implements JsonSerializable {
protected string $licenseId;
protected string $userId;
protected string $emailId;
protected string $purchaseId;
protected string $productId;
Expand All @@ -17,7 +16,6 @@ class License extends DatabaseObject implements JsonSerializable {

public function __construct(BeaconRecordSet $row) {
$this->licenseId = $row->Field('license_id');
$this->userId = $row->Field('user_id');
$this->emailId = $row->Field('email_id');
$this->purchaseId = $row->Field('purchase_id');
$this->productId = $row->Field('product_id');
Expand All @@ -31,8 +29,7 @@ public function __construct(BeaconRecordSet $row) {
public static function BuildDatabaseSchema(): DatabaseSchema {
return new DatabaseSchema('public', 'licenses', [
new DatabaseObjectProperty('licenseId', ['primaryKey' => true, 'columnName' => 'license_id']),
new DatabaseObjectProperty('userId', ['columnName' => 'user_id', 'accessor' => 'users.user_id']),
new DatabaseObjectProperty('emailId', ['columnName' => 'email_id', 'accessor' => 'users.email_id']),
new DatabaseObjectProperty('emailId', ['columnName' => 'email_id', 'accessor' => 'purchases.purchaser_email']),
new DatabaseObjectProperty('purchaseId', ['columnName' => 'purchase_id']),
new DatabaseObjectProperty('productId', ['columnName' => 'product_id']),
new DatabaseObjectProperty('productName', ['columnName' => 'product_name', 'accessor' => 'products.product_name']),
Expand All @@ -42,26 +39,21 @@ public static function BuildDatabaseSchema(): DatabaseSchema {
new DatabaseObjectProperty('firstUsed', ['columnName' => 'first_used', 'accessor' => "DATE_TRUNC('second', purchases.first_used)"]),
], [
"INNER JOIN public.products ON (licenses.product_id = products.product_id)",
"INNER JOIN public.purchases ON (licenses.purchase_id = purchases.purchase_id)",
"INNER JOIN public.users ON (purchases.purchaser_email = users.email_id)"
"INNER JOIN public.purchases ON (licenses.purchase_id = purchases.purchase_id)"
]);
}

protected static function BuildSearchParameters(DatabaseSearchParameters $parameters, array $filters, bool $isNested): void {
$schema = static::DatabaseSchema();
$parameters->AddFromFilter($schema, $filters, 'purchaseId');
$parameters->AddFromFilter($schema, $filters, 'userId');
$parameters->AddFromFilter($schema, $filters, 'emailId');
$parameters->orderBy = $schema->Accessor('expiration') . ' DESC';
}

public function LicenseId(): string {
return $this->licenseId;
}

public function UserId(): string {
return $this->userId;
}

public function EmailId(): string {
return $this->emailId;
}
Expand Down
2 changes: 1 addition & 1 deletion Website/api/v4/classes/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public function LoadLicenses(): void {
return;
}

$this->licenses = License::Search(['userId' => $this->userId], true);
$this->licenses = License::Search(['emailId' => $this->emailId], true);
$this->licensesLoaded = true;
}

Expand Down
74 changes: 63 additions & 11 deletions Website/www/omni/begin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
}

$email = strtolower(trim($cart['email']));
if (BeaconEmail::IsEmailValid($email) === false) {
http_response_code(400);
echo json_encode(['error' => true, 'message' => 'Email is not valid.'], JSON_PRETTY_PRINT);
exit;
}
$refundAgreed = filter_var($cart['refundPolicyAgreed'], FILTER_VALIDATE_BOOLEAN);
$bundles = $cart['items'];
$currency = BeaconShop::GetCurrency();
Expand Down Expand Up @@ -91,10 +96,13 @@
$user = null;
$licenses = [];
try {
$rows = $database->Query('SELECT uuid_for_email($1) AS email_id;', $email);
$emailId = $rows->Field('email_id');
$licenses = License::Search(['emailId' => $emailId], true);

$user = User::Fetch($email);
if (is_null($user) === false) {
$payment['metadata']['Beacon User UUID'] = $user->UserID();
$licenses = $user->Licenses();
}
} catch (Exception $err) {
}
Expand Down Expand Up @@ -163,6 +171,13 @@
$includeArkSA = isset($products['ArkSA']['Base']);
$includeMinimalGames = isset($products['BeaconMinimal']['Base']);

$gameIds = [];
$gameRows = $database->Query('SELECT game_id FROM public.games WHERE public = TRUE AND game_id NOT IN (\'Ark\', \'ArkSA\') ORDER BY game_id;');
while (!$gameRows->EOF()) {
$gameIds[] = $gameRows->Field('game_id');
$gameRows->MoveNext();
}

$lines = [];
foreach ($bundles as $bundle) {
$bundle = new CartBundle($bundle);
Expand All @@ -187,10 +202,28 @@
}
}

if ($wantsMinimalGamesYears > 0) {
$lines[$products['BeaconMinimal']['Base']['PriceId']] = ($lines[$products['BeaconMinimal']['Base']['PriceId']] ?? 0) + 1;
if ($wantsMinimalGamesYears > 1) {
$lines[$products['BeaconMinimal']['Renewal']['PriceId']] = ($lines[$products['BeaconMinimal']['Renewal']['PriceId']] ?? 0) + ($wantsMinimalGamesYears - 1);
foreach ($gameIds as $gameId) {
if (isset($products[$gameId]['Base']) === false) {
continue;
}

$renewable = isset($products[$gameId]['Renewal']);
$baseProduct = $products[$gameId]['Base'];

if ($renewable) {
$renewalProduct = $products[$gameId]['Renewal'];
$years = $bundle->getQuantity($baseProduct['ProductId']) + $bundle->getQuantity($renewalProduct['ProductId']);
if ($years < 1) {
continue;
}
$lines[$baseProduct['PriceId']] = ($lines[$baseProduct['PriceId']] ?? 0) + 1;
if ($years > 1) {
$lines[$renewalProduct['PriceId']] = ($lines[$renewalProduct['PriceId']] ?? 0) + ($years - 1);
}
} else {
if ($bundle->getQuantity($baseProduct['ProductId']) > 0) {
$lines[$baseProduct['PriceId']] = 1;
}
}
}
} else {
Expand All @@ -217,13 +250,32 @@
}
}

if ($wantsMinimalGamesYears > 0) {
if ($ownsMinimalGames) {
$lines[$products['BeaconMinimal']['Renewal']['PriceId']] = ($lines[$products['BeaconMinimal']['Renewal']['PriceId']] ?? 0) + $wantsMinimalGamesYears;
foreach ($gameIds as $gameId) {
if (isset($products[$gameId]['Base']) === false) {
continue;
}

$renewable = isset($products[$gameId]['Renewal']);
$baseProduct = $products[$gameId]['Base'];

if ($renewable) {
$renewalProduct = $products[$gameId]['Renewal'];
$years = $bundle->getQuantity($baseProduct['ProductId']) + $bundle->getQuantity($renewalProduct['ProductId']);
if ($years < 1) {
continue;
}
$isOwned = findLicense($licenses, $baseProduct['ProductId']) !== null;
if ($isOwned) {
$lines[$renewalProduct['PriceId']] = ($lines[$renewalProduct['PriceId']] ?? 0) + $years;
} else {
$lines[$baseProduct['PriceId']] = ($lines[$baseProduct['PriceId']] ?? 0) + 1;
if ($years > 1) {
$lines[$renewalProduct['PriceId']] = ($lines[$renewalProduct['PriceId']] ?? 0) + ($years - 1);
}
}
} else {
$lines[$products['BeaconMinimal']['Base']['PriceId']] = ($lines[$products['BeaconMinimal']['Base']['PriceId']] ?? 0) + 1;
if ($wantsMinimalGamesYears > 1) {
$lines[$products['BeaconMinimal']['Renewal']['PriceId']] = ($lines[$products['BeaconMinimal']['Renewal']['PriceId']] ?? 0) + ($wantsMinimalGamesYears - 1);
if ($bundle->getQuantity($baseProduct['ProductId']) > 0 && findLicense($licenses, $baseProduct['ProductId']) === null) {
$lines[$baseProduct['PriceId']] = 1;
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions Website/www/omni/lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

require(dirname(__FILE__, 3) . '/framework/loader.php');

use BeaconAPI\v4\User;
use BeaconAPI\v4\{License, User};

$email = isset($_GET['email']) ? $_GET['email'] : '';
$response = [
Expand Down Expand Up @@ -44,7 +44,11 @@ function lookupEmail($email, &$response) {
$response['purchases'] = $user->Licenses();
return;
} else {
$response['debug'] = 'null user';
$database = BeaconCommon::Database();
$rows = $database->Query('SELECT uuid_for_email($1) AS email_id;', $email);
$emailId = $rows->Field('email_id');
$licenses = License::Search(['emailId' => $emailId], true);
$response['purchases'] = $licenses;
}
} catch (Exception $e) {
$response['debug'] = 'exception';
Expand Down
5 changes: 5 additions & 0 deletions Website/www/omni/modules/ark.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<td class="text-center bullet-column">&check;</td>
<td class="text-center bullet-column">&check;</td>
</tr>
<tr>
<td>Custom Config<br><span class="smaller text-lighter">Add settings to your ini files that Beacon doesn't support, such as mod configs.</span></td>
<td class="text-center bullet-column">&check;</td>
<td class="text-center bullet-column">&check;</td>
</tr>
<tr>
<td>Day and Night Cycle<br><span class="smaller text-lighter">Change the length of Ark's days and nights using minutes instead of multipliers.</span></td>
<td class="text-center bullet-column">&check;</td>
Expand Down
5 changes: 5 additions & 0 deletions Website/www/omni/modules/arksa.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<td class="text-center bullet-column">&check;</td>
<td class="text-center bullet-column">&check;</td>
</tr>
<tr>
<td>Custom Config<br><span class="smaller text-lighter">Add settings to your ini files that Beacon doesn't support, such as mod configs.</span></td>
<td class="text-center bullet-column">&check;</td>
<td class="text-center bullet-column">&check;</td>
</tr>
<tr>
<td>Day and Night Cycle<br><span class="smaller text-lighter">Change the length of Ark's days and nights using minutes instead of multipliers.</span></td>
<td class="text-center bullet-column">&check;</td>
Expand Down
5 changes: 5 additions & 0 deletions Website/www/omni/modules/palworld.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<td class="text-center bullet-column">&check;</td>
<td class="text-center bullet-column">&check;</td>
</tr>
<tr>
<td>Custom Config<br><span class="smaller text-lighter">Add settings to your ini file that Beacon doesn't support.</span></td>
<td class="text-center bullet-column">&check;</td>
<td class="text-center bullet-column">&check;</td>
</tr>
<tr>
<td>General Settings<br><span class="smaller text-lighter">Beacon has support for nearly every setting available to Palworld servers.</span></td>
<td class="text-center bullet-column">&nbsp;</td>
Expand Down

0 comments on commit a9ca057

Please sign in to comment.