Skip to content

Commit

Permalink
GH-230 Move user updates to an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 3, 2022
1 parent ab5ddc1 commit eaf2305
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
include($includePath . './screens/FirstLogin/utils/effects/handleProxyDetection.effect.php');
include($includePath . './screens/FirstLogin/utils/effects/handleReferralMultiAccountDetection.effect.php');
include($includePath . './screens/FirstLogin/utils/effects/triggerUserReferralTask.effect.php');
include($includePath . './screens/FirstLogin/utils/effects/updateUserOnFirstLogin.effect.php');
include($includePath . './screens/FirstLogin/utils/helpers/getReferrerTasksData.helper.php');

});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\FirstLogin\Utils\Effects;

/**
* @param array $params
* @param number $params['userId']
* @param number $params['currentTimestamp']
*/
function updateUserOnFirstLogin($props) {
global $_GameConfig;

$userId = $props['userId'];
$currentTimestamp = $props['currentTimestamp'];

$newUserProtectionEndTimestamp = $currentTimestamp + $_GameConfig['Protection_NewPlayerTime'];

$updateChatPresenceQuery = (
"INSERT IGNORE INTO {{table}} " .
"VALUES " .
"(0, {$userId}, {$currentTimestamp}) " .
";"
);
$updatePlanetsStateQuery = (
"UPDATE {{table}} " .
"SET " .
"`last_update` = {$currentTimestamp} " .
"WHERE " .
"`id_owner` = {$userId} " .
";"
);
$updateUserStateQuery = (
"UPDATE {{table}} " .
"SET " .
"`first_login` = {$currentTimestamp}, " .
"`NoobProtection_EndTime` = {$newUserProtectionEndTimestamp} " .
"WHERE " .
"`id` = {$userId} " .
"LIMIT 1 " .
";"
);

doquery($updateChatPresenceQuery, 'chat_online');
doquery($updatePlanetsStateQuery, 'planets');
doquery($updateUserStateQuery, 'users');
}

?>
14 changes: 4 additions & 10 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,10 @@

$_Lang['LoginPage_Text'] = str_replace($Search, $Replace, $_Lang['LoginPage_Text']);

doquery("INSERT IGNORE INTO {{table}} VALUES (0, {$_User['id']}, {$Now});", 'chat_online');
doquery("UPDATE {{table}} SET `last_update` = {$Now} WHERE `id_owner` = {$_User['id']} LIMIT 1;", 'planets');

$NewUserProtectionTime = $Now + $_GameConfig['Protection_NewPlayerTime'];
$Query_UpdateUser = '';
$Query_UpdateUser .= "UPDATE {{table}} SET ";
$Query_UpdateUser .= "`first_login` = {$Now}, ";
$Query_UpdateUser .= "`NoobProtection_EndTime` = {$NewUserProtectionTime} ";
$Query_UpdateUser .= "WHERE `id` = {$_User['id']} LIMIT 1;";
doquery($Query_UpdateUser, 'users');
Overview\Screens\FirstLogin\Utils\Effects\updateUserOnFirstLogin([
'userId' => $_User['id'],
'currentTimestamp' => $Now,
]);

if ($_User['referred'] > 0) {
$referringUserWithTasksData = Overview\Screens\FirstLogin\Utils\Helpers\getReferrerTasksData([
Expand Down

0 comments on commit eaf2305

Please sign in to comment.