Skip to content

Commit

Permalink
improvement of code.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed May 30, 2024
1 parent e75bd89 commit 052fea9
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,7 @@ function parseEvent($table1, $date, $table2)
$characters[] = createChar($config, $caster);
}

$worlds = [$world];
$playdata = compact('worlds', 'characters');
$session = [
'sessionkey' => "$result->email\n$result->password",
'lastlogintime' => 0,
'ispremium' => false,
'premiumuntil' => 0,
'status' => 'active',
'returnernotification' => false,
'showrewardnews' => false,
'isreturner' => false,
'fpstracking' => false,
'optiontracking' => false,
'tournamentticketpurchasestate' => 0,
'emailcoderequest' => false
];
die(json_encode(compact('session', 'playdata')));
die(json_encode(getSessionData($world, $result, $characters, true)));
}

$account = new OTS_Account();
Expand Down Expand Up @@ -170,23 +154,7 @@ function parseEvent($table1, $date, $table2)
sendError("Error while fetching your account data. Please contact admin.");
}

$worlds = [$world];
$playdata = compact('worlds', 'characters');
$session = [
'sessionkey' => "$result->email\n$result->password",
'lastlogintime' => $account ? $account->getLastLogin() : 0,
'ispremium' => $account->isPremium(),
'premiumuntil' => $premU,
'status' => 'active', // active, frozen or suspended
'returnernotification' => false,
'showrewardnews' => true,
'isreturner' => true,
'fpstracking' => false,
'optiontracking' => false,
'tournamentticketpurchasestate' => 0,
'emailcoderequest' => false
];
die(json_encode(compact('session', 'playdata')));
die(json_encode(getSessionData($world, $result, $characters, false, $account, $premU)));

default:
sendError("Unrecognized event {$action}.");
Expand Down Expand Up @@ -222,6 +190,37 @@ function createChar($config, $player)
];
}

/**
* Check and return compacted session after checking cast
* @param $world
* @param $result
* @param $characters
* @param $isCast
* @param $account
* @param $premU
* @return array
*/
function getSessionData($world, $result, $characters, $isCast = false, $account = null, $premU = null): array
{
$worlds = [$world];
$playdata = compact('worlds', 'characters');
$session = [
'sessionkey' => "$result->email\n$result->password",
'lastlogintime' => !$isCast && $account ? $account->getLastLogin() : 0,
'ispremium' => !$isCast ? $account->isPremium() : false,
'premiumuntil' => !$isCast ? $premU : 0,
'status' => 'active', // active, frozen or suspended
'returnernotification' => false,
'showrewardnews' => !$isCast,
'isreturner' => !$isCast,
'fpstracking' => false,
'optiontracking' => false,
'tournamentticketpurchasestate' => 0,
'emailcoderequest' => false
];
return compact('session', 'playdata');
}

/**
* Function to check account has premium time and update days
* @param $db
Expand Down

0 comments on commit 052fea9

Please sign in to comment.