Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbreak campaign prizes, vault, fah #550

Merged
merged 21 commits into from Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions common/cron/hourly.php
Expand Up @@ -6,12 +6,14 @@
// ensure part awards
require_once QUERIES_DIR . '/part_awards.php';

// folding_at_home data select/insert/update from/into/in db
// folding_at_home data select/insert/update from/into/in db, send confirmation message
require_once FNS_DIR . '/cron/cron_fns.php';
require_once QUERIES_DIR . '/folding_at_home.php';
require_once QUERIES_DIR . '/messages.php';
require_once QUERIES_DIR . '/rank_tokens.php';

// remove expired servers
// speak to servers (campaign prizes update), remove expired servers
require_once QUERIES_DIR . '/campaigns.php';
require_once QUERIES_DIR . '/servers.php';

// tell the command line
Expand All @@ -26,6 +28,7 @@
generate_level_list($pdo, 'best');
generate_level_list($pdo, 'best_today');
generate_level_list($pdo, 'campaign');
set_campaign($pdo);
ensure_awards($pdo);
servers_deactivate_expired($pdo);
servers_delete_old($pdo);
Expand Down
1 change: 0 additions & 1 deletion common/cron/minute.php
Expand Up @@ -5,7 +5,6 @@
require_once HTTP_FNS . '/rand_crypt/PseudoRandom.php';
require_once QUERIES_DIR . '/artifact_location.php';
require_once QUERIES_DIR . '/bans.php';
require_once QUERIES_DIR . '/campaigns.php';
require_once QUERIES_DIR . '/gp.php';
require_once QUERIES_DIR . '/messages.php';
require_once QUERIES_DIR . '/servers.php';
Expand Down
27 changes: 0 additions & 27 deletions common/queries/part_awards.php
@@ -1,33 +1,6 @@
<?php


function ensure_awards($pdo)
{
// select all records, they get cleared out weekly or somesuch
$awards = part_awards_select_list($pdo);

// give users their awards
foreach ($awards as $row) {
if ($row->part == 0) {
$part = '*';
} else {
$part = $row->part;
}
$type = $row->type;
$user_id = $row->user_id;
try {
award_part($pdo, $user_id, $type, $part, false);
echo "user_id: $user_id, type: $type, part: $part \n";
} catch (Exception $e) {
echo "Error: $e \n";
}
}

// delete older records
part_awards_delete_old($pdo);
}


function part_awards_delete_old($pdo)
{
$result = $pdo->exec('
Expand Down
51 changes: 50 additions & 1 deletion functions/cron/cron_fns.php
Expand Up @@ -13,7 +13,6 @@ function run_update_cycle($pdo)
$send->artifact = artifact_location_select($pdo);
$send->recent_pms = get_recent_pms($pdo);
$send->recent_bans = bans_select_recent($pdo);
$send->campaign = levels_select_campaign($pdo);
$send_str = json_encode($send);

// send the data
Expand Down Expand Up @@ -217,6 +216,56 @@ function failover_servers($pdo)
}


function set_campaign($pdo)
{
output("Starting campaign update process...");

// get campaign data
$send = new stdClass();
$send->campaign = campaign_select($pdo);
$send = json_encode($send);

// send update function to the servers
$servers = servers_select($pdo);
foreach ($servers as $server) {
output("Updating campaign on $server->server_name (ID: #$server->server_id)...");
try {
$reply = talk_to_server($server->address, $server->port, $server->salt, "set_campaign`$send", true, false);
output("Reply: $reply");
output("$server->server_name (ID #$server->server_id) campaign update successful.");
} catch (Exception $e) {
output($e->getMessage());
}
}

// tell the command line
output('Campaign update complete.');
}


function ensure_awards($pdo)
{
// select all records, they get cleared out weekly or somesuch
$awards = part_awards_select_list($pdo);

// give users their awards
foreach ($awards as $row) {
$part = (int) $row->part === 0 ? '*' : $row->part;
$type = $row->type;
$user_id = (int) $row->user_id;
try {
award_part($pdo, $user_id, $type, $part, false);
echo "user_id: $user_id, type: $type, part: $part \n";
} catch (Exception $e) {
echo "Error: $e \n";
}
}

// delete older records
part_awards_delete_old($pdo);
}


function servers_restart_all($pdo)
{
// tell the command line
Expand Down
2 changes: 1 addition & 1 deletion functions/http_fns/query_fns.php
Expand Up @@ -349,7 +349,7 @@ function generate_level_list($pdo, $mode)
foreach (range(0, 8) as $j) {
$str = format_level_list(array_slice($levels, $j * 9, 9));
$filename = $dir . ($j + 1);
$ret = (bool) file_put_contents($filename, $str);
$ret = file_put_contents($filename, $str);
if ($ret === false) {
throw new Exception("Could not write level list to $filename.");
}
Expand Down
12 changes: 11 additions & 1 deletion functions/multi_fns/process_fns.php
Expand Up @@ -69,6 +69,17 @@ function process_message_player($socket, $data)
}


// set the campaign
function process_set_campaign($socket, $data)
{
if ($socket->process === true) {
$obj = json_decode($data);
set_campaign((object) $obj->campaign);
$socket->write('Campaign updated.');
}
}


// clear player's daily exp levels
function process_start_new_day($socket)
{
Expand All @@ -90,7 +101,6 @@ function process_update_cycle($socket, $data)
place_artifact($obj->artifact);
pm_notify($obj->recent_pms);
apply_bans($obj->recent_bans);
set_campaign($obj->campaign);

$ret = new stdClass();
$ret->plays = drain_plays();
Expand Down
2 changes: 1 addition & 1 deletion http_server/admin/set_campaign.php
Expand Up @@ -7,7 +7,7 @@
require_once QUERIES_DIR . '/campaigns.php';

$action = default_post('action', 'lookup');
$message = htmlspecialchars(default_post('message', ''));
$message = htmlspecialchars(default_get('message', ''));
$campaign_id = 6; // 1 = Original, 2 = Speed, 3 = Luna, 4 = Timeline, 5 = Legendary, 6 = Custom

try {
Expand Down
2 changes: 1 addition & 1 deletion http_server/register_user.php
Expand Up @@ -5,7 +5,7 @@
require_once QUERIES_DIR . '/bans.php';
require_once QUERIES_DIR . '/messages.php';

$name = default_post('name');
$name = trim(default_post('name'));
$password = default_post('password');
$time = time();
$ip = get_ip();
Expand Down
1 change: 1 addition & 0 deletions http_server/vault/vault_finalize.php
Expand Up @@ -5,6 +5,7 @@
require_once GEN_HTTP_FNS;
require_once HTTP_FNS . '/pages/vault/vault_fns.php';
require_once QUERIES_DIR . '/messages.php';
require_once QUERIES_DIR . '/part_awards.php';
require_once QUERIES_DIR . '/purchases.php';
require_once QUERIES_DIR . '/rank_token_rentals.php';
require_once QUERIES_DIR . '/servers.php';
Expand Down
2 changes: 1 addition & 1 deletion multiplayer_server/parts/Prizes.php
Expand Up @@ -674,7 +674,7 @@ public static function find($type, $id)
{
$match = null;
foreach (self::$arr as $prize) {
if ($prize->getType() === $type && $prize->getId() === $id) {
if ($prize->getType() === $type && $prize->getId() === (int) $id) {
$match = $prize;
break;
}
Expand Down