mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 09:49:22 +02:00
feat: mass account tool, mass teleport tool (#209)
* feat: mass account coins, premdays, points. mass teleport town, position * fix: tab
This commit is contained in:
parent
20638f430a
commit
269ca501f1
@ -34,8 +34,10 @@ $menus = [
|
|||||||
],
|
],
|
||||||
['name' => 'Tools', 'icon' => 'tools', 'order' => 100, 'link' =>
|
['name' => 'Tools', 'icon' => 'tools', 'order' => 100, 'link' =>
|
||||||
[
|
[
|
||||||
['name' => 'Notepad', 'link' => 'notepad', 'order' => 10],
|
['name' => 'Mass Account Actions', 'link' => 'tools&tool=account', 'order' => 10],
|
||||||
['name' => 'phpinfo', 'link' => 'phpinfo', 'order' => 20],
|
['name' => 'Mass Teleport Actions', 'link' => 'tools&tool=teleport', 'order' => 20],
|
||||||
|
['name' => 'Notepad', 'link' => 'notepad', 'order' => 30],
|
||||||
|
['name' => 'phpinfo', 'link' => 'phpinfo', 'order' => 40],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
['name' => 'Logs', 'icon' => 'bug', 'order' => 110, 'link' =>
|
['name' => 'Logs', 'icon' => 'bug', 'order' => 110, 'link' =>
|
||||||
|
@ -10,18 +10,24 @@
|
|||||||
defined('MYAAC') or die('Direct access not allowed!');
|
defined('MYAAC') or die('Direct access not allowed!');
|
||||||
$title = 'Tools';
|
$title = 'Tools';
|
||||||
|
|
||||||
$tool = $_GET['tool'];
|
if (!isset($_GET['tool'])) {
|
||||||
if (!isset($tool)) {
|
|
||||||
echo 'Tool not set.';
|
echo 'Tool not set.';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tool = $_GET['tool'];
|
||||||
if (preg_match("/[^A-z0-9_\-]/", $tool)) {
|
if (preg_match("/[^A-z0-9_\-]/", $tool)) {
|
||||||
echo 'Invalid tool.';
|
echo 'Invalid tool.';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = BASE . 'admin/pages/tools/' . $tool . '.php';
|
$file = SYSTEM . 'pages/admin/tools/' . $tool . '.php';
|
||||||
if (!@file_exists($file))
|
|
||||||
|
if (@file_exists($file)) {
|
||||||
require $file;
|
require $file;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo 'Tool <strong>' . $tool . '</strong> not found.';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
202
system/pages/admin/tools/account.php
Normal file
202
system/pages/admin/tools/account.php
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account Admin Tool
|
||||||
|
*
|
||||||
|
* @package MyAAC
|
||||||
|
* @author Slawkens <slawkens@gmail.com>
|
||||||
|
* @author Lee
|
||||||
|
* @copyright 2020 MyAAC
|
||||||
|
* @link https://my-aac.org
|
||||||
|
*/
|
||||||
|
defined('MYAAC') or die('Direct access not allowed!');
|
||||||
|
|
||||||
|
$title = 'Mass Account Actions';
|
||||||
|
|
||||||
|
$hasCoinsColumn = $db->hasColumn('accounts', 'coins');
|
||||||
|
$hasPointsColumn = $db->hasColumn('accounts', 'premium_points');
|
||||||
|
$freePremium = $config['lua']['freePremium'];
|
||||||
|
|
||||||
|
function admin_give_points($points)
|
||||||
|
{
|
||||||
|
global $db, $hasPointsColumn;
|
||||||
|
|
||||||
|
if (!$hasPointsColumn) {
|
||||||
|
error('Points not supported.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$statement = $db->prepare('UPDATE `accounts` SET `premium_points` = `premium_points` + :points');
|
||||||
|
if (!$statement) {
|
||||||
|
error('Failed to prepare query statement.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$statement->execute([
|
||||||
|
'points' => $points
|
||||||
|
])) {
|
||||||
|
error('Failed to add points.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
success($points . ' points added to all accounts.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function admin_give_coins($coins)
|
||||||
|
{
|
||||||
|
global $db, $hasCoinsColumn;
|
||||||
|
|
||||||
|
if (!$hasCoinsColumn) {
|
||||||
|
error('Coins not supported.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$statement = $db->prepare('UPDATE `accounts` SET `coins` = `coins` + :coins');
|
||||||
|
if (!$statement) {
|
||||||
|
error('Failed to prepare query statement.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$statement->execute([
|
||||||
|
'coins' => $coins
|
||||||
|
])) {
|
||||||
|
error('Failed to add coins.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
success($coins . ' coins added to all accounts.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function query_add_premium($column, $value_query, $condition_query = '1=1', $params = [])
|
||||||
|
{
|
||||||
|
global $db;
|
||||||
|
|
||||||
|
$statement = $db->prepare("UPDATE `accounts` SET `{$column}` = $value_query WHERE $condition_query");
|
||||||
|
if (!$statement) {
|
||||||
|
error('Failed to prepare query statement.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$statement->execute($params)) {
|
||||||
|
error('Failed to add premium days.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function admin_give_premdays($days)
|
||||||
|
{
|
||||||
|
global $db, $freePremium;
|
||||||
|
|
||||||
|
if ($freePremium) {
|
||||||
|
error('Premium days not supported. Free Premium enabled.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = $days * 86400;
|
||||||
|
$now = time();
|
||||||
|
// othire
|
||||||
|
if ($db->hasColumn('accounts', 'premend')) {
|
||||||
|
// append premend
|
||||||
|
if (query_add_premium('premend', '`premend` + :value', '`premend` > :now', ['value' => $value, 'now' => $now])) {
|
||||||
|
// set premend
|
||||||
|
if (query_add_premium('premend', ':value', '`premend` <= :now', ['value' => $now + $value, 'now' => $now])) {
|
||||||
|
success($days . ' premium days added to all accounts.');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
error('Failed to execute set query.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error('Failed to execute append query.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// tfs 0.x
|
||||||
|
if ($db->hasColumn('accounts', 'premdays')) {
|
||||||
|
// append premdays
|
||||||
|
if (query_add_premium('premdays', '`premdays` + :value', '1=1', ['value' => $days])) {
|
||||||
|
// append lastday
|
||||||
|
if (query_add_premium('lastday', '`lastday` + :value', '`lastday` > :now', ['value' => $value, 'now' => $now])) {
|
||||||
|
// set lastday
|
||||||
|
if (query_add_premium('lastday', ':value', '`lastday` <= :now', ['value' => $now + $value, 'now' => $now])) {
|
||||||
|
success($days . ' premium days added to all accounts.');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
error('Failed to execute set query.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
success($days . ' premium days added to all accounts.');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
error('Failed to execute append query.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error('Failed to execute set days query.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// tfs 1.x
|
||||||
|
if ($db->hasColumn('accounts', 'premium_ends_at')) {
|
||||||
|
// append premium_ends_at
|
||||||
|
if (query_add_premium('premium_ends_at', '`premium_ends_at` + :value', '`premium_ends_at` > :now', ['value' => $value, 'now' => $now])) {
|
||||||
|
// set premium_ends_at
|
||||||
|
if (query_add_premium('premium_ends_at', ':value', '`premium_ends_at` <= :now', ['value' => $now + $value, 'now' => $now])) {
|
||||||
|
success($days . ' premium days added to all accounts.');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
error('Failed to execute set query.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error('Failed to execute append query.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
error('Premium Days not supported.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['action']) && $_POST['action']) {
|
||||||
|
|
||||||
|
$action = $_POST['action'];
|
||||||
|
|
||||||
|
if (preg_match("/[^A-z0-9_\-]/", $action)) {
|
||||||
|
error('Invalid action.');
|
||||||
|
} else {
|
||||||
|
$value = isset($_POST['value']) ? intval($_POST['value']) : 0;
|
||||||
|
|
||||||
|
if (!$value) {
|
||||||
|
error('Please fill all inputs');
|
||||||
|
} else {
|
||||||
|
switch ($action) {
|
||||||
|
case 'give-points':
|
||||||
|
admin_give_points($value);
|
||||||
|
break;
|
||||||
|
case 'give-coins':
|
||||||
|
admin_give_coins($value);
|
||||||
|
break;
|
||||||
|
case 'give-premdays':
|
||||||
|
admin_give_premdays($value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error('Action ' . $action . 'not found.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$twig->display('admin.tools.account.html.twig', array(
|
||||||
|
'hasCoinsColumn' => $hasCoinsColumn,
|
||||||
|
'hasPointsColumn' => $hasPointsColumn,
|
||||||
|
'freePremium' => $freePremium,
|
||||||
|
));
|
100
system/pages/admin/tools/teleport.php
Normal file
100
system/pages/admin/tools/teleport.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Teleport Admin Tool
|
||||||
|
*
|
||||||
|
* @package MyAAC
|
||||||
|
* @author Slawkens <slawkens@gmail.com>
|
||||||
|
* @author Lee
|
||||||
|
* @copyright 2020 MyAAC
|
||||||
|
* @link https://my-aac.org
|
||||||
|
*/
|
||||||
|
defined('MYAAC') or die('Direct access not allowed!');
|
||||||
|
|
||||||
|
$title = 'Mass Teleport Actions';
|
||||||
|
|
||||||
|
function admin_teleport_position($x, $y, $z) {
|
||||||
|
global $db;
|
||||||
|
$statement = $db->prepare('UPDATE `players` SET `posx` = :x, `posy` = :y, `posz` = :z');
|
||||||
|
if (!$statement) {
|
||||||
|
error('Failed to prepare query statement.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$statement->execute([
|
||||||
|
'x' => $x, 'y' => $y, 'z' => $z
|
||||||
|
])) {
|
||||||
|
error('Failed to execute query.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
success('Player\'s position updated.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function admin_teleport_town($town_id) {
|
||||||
|
global $db;
|
||||||
|
$statement = $db->prepare('UPDATE `players` SET `town_id` = :town_id');
|
||||||
|
if (!$statement) {
|
||||||
|
error('Failed to prepare query statement.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$statement->execute([
|
||||||
|
'town_id' => $town_id
|
||||||
|
])) {
|
||||||
|
error('Failed to execute query.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
success('Player\'s town updated.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['action']) && $_POST['action']) {
|
||||||
|
|
||||||
|
$action = $_POST['action'];
|
||||||
|
|
||||||
|
if (preg_match("/[^A-z0-9_\-]/", $action)) {
|
||||||
|
error('Invalid action.');
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$playersOnline = 0;
|
||||||
|
if($db->hasTable('players_online')) {// tfs 1.0
|
||||||
|
$playersOnline = $db->query('SELECT count(*) FROM `players_online`');
|
||||||
|
} else {
|
||||||
|
$playersOnline = $db->query('SELECT count(*) FROM `players` WHERE `players`.`online` > 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($playersOnline > 0) {
|
||||||
|
error('Please, close the server before execute this action otherwise players will not be affected.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$town_id = isset($_POST['town_id']) ? intval($_POST['town_id']) : 0;
|
||||||
|
$posx = isset($_POST['posx']) ? intval($_POST['posx']) : 0;
|
||||||
|
$posy = isset($_POST['posy']) ? intval($_POST['posy']) : 0;
|
||||||
|
$posz = isset($_POST['posz']) ? intval($_POST['posz']) : 0;
|
||||||
|
|
||||||
|
switch ($action) {
|
||||||
|
case 'set-town':
|
||||||
|
if (!isset($config['towns'][$town_id])) {
|
||||||
|
error('Please fill all inputs');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
admin_teleport_town($value);
|
||||||
|
break;
|
||||||
|
case 'set-position':
|
||||||
|
if (!$posx || !$posy || !$posz) {
|
||||||
|
error('Please fill all inputs');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
admin_teleport_position($posx, $posy, $posz);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error('Action ' . $action . 'not found.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$twig->display('admin.tools.teleport.html.twig', array());
|
67
system/templates/admin.tools.account.html.twig
Normal file
67
system/templates/admin.tools.account.html.twig
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<div class="row">
|
||||||
|
{% if hasPointsColumn %}
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card card-info card-outline">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="m-0">Give Premium Points</h5>
|
||||||
|
</div>
|
||||||
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=account">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Premium Points</label>
|
||||||
|
<input type="number" name="value" value="" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<input type="hidden" name="action" value="give-points">
|
||||||
|
<button type="submit" class="btn btn-info">Add Points</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if hasCoinsColumn %}
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card card-info card-outline">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="m-0">Give Coins</h5>
|
||||||
|
</div>
|
||||||
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=account">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Coins</label>
|
||||||
|
<input type="number" name="value" value="" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<input type="hidden" name="action" value="give-coins">
|
||||||
|
<button type="submit" class="btn btn-info">Add Coins</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if not freePremium %}
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card card-info card-outline">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="m-0">Give Premium Days</h5>
|
||||||
|
</div>
|
||||||
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=account">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Premium Days</label>
|
||||||
|
<input type="number" name="value" value="" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<input type="hidden" name="action" value="give-premdays">
|
||||||
|
<button type="submit" class="btn btn-info">Add Days</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
80
system/templates/admin.tools.teleport.html.twig
Normal file
80
system/templates/admin.tools.teleport.html.twig
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card card-info card-outline">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="m-0">Set Town</h5>
|
||||||
|
</div>
|
||||||
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=teleport">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Town</label>
|
||||||
|
<select name="value" class="form-control">
|
||||||
|
{% if config.towns|length > 0 %}
|
||||||
|
{% for town_id, town_name in config.towns %}
|
||||||
|
<option value="{{ town_id }}">{{ town_name }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<option disabled>No towns</option>
|
||||||
|
{% endif %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<input type="hidden" name="action" value="set-town">
|
||||||
|
<button type="submit" class="btn btn-info">Set Town</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card card-info card-outline">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="m-0">Set Position</h5>
|
||||||
|
</div>
|
||||||
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=teleport">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Position X</label>
|
||||||
|
<input type="number" name="posx" value="" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Position Y</label>
|
||||||
|
<input type="number" name="posy" value="" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Position Z</label>
|
||||||
|
<input type="number" name="posz" value="" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<input type="hidden" name="action" value="set-position">
|
||||||
|
<button type="submit" class="btn btn-info">Set Position</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card card-info card-outline">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="m-0">Teleport to Temple</h5>
|
||||||
|
</div>
|
||||||
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=teleport">
|
||||||
|
<div class="card-footer">
|
||||||
|
<input type="hidden" name="action" value="set-position">
|
||||||
|
<input type="hidden" name="posx" value="0">
|
||||||
|
<input type="hidden" name="posy" value="0">
|
||||||
|
<input type="hidden" name="posz" value="0">
|
||||||
|
<button type="submit" class="btn btn-info">Teleport to Temple</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
Loading…
x
Reference in New Issue
Block a user