Admin panel fixes

+Plus and bonuses duration, can now be decreased or resetted, by
inserting a negative value of days
+Artifacts and artifacts villages created on a user account, won't
contain any troops
+Some clean up
This commit is contained in:
iopietro
2018-07-27 02:25:08 +02:00
parent ca0ba2e8f1
commit d3a78a5ea5
5 changed files with 43 additions and 85 deletions
+12 -45
View File
@@ -24,57 +24,24 @@ for ($i = 0; $i < 5; $i++) {
include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$id = (int) $_POST['id'];
$sql = mysqli_query($GLOBALS["link"], "SELECT * FROM ".TB_PREFIX."users WHERE id = ".$session."");
$access = mysqli_fetch_array($sql);
$sessionaccess = $access['access'];
$bonusDuration = [];
$time = time();
$bonusDuration['plus'] = (int) $_POST['plus'] * 86400; //Plus
$bonusDuration['b1'] = (int) $_POST['wood'] * 86400; //+25% Wood
$bonusDuration['b2'] = (int) $_POST['clay'] * 86400; //+25% Clay
$bonusDuration['b3'] = (int) $_POST['iron'] * 86400; //+25% Iron
$bonusDuration['b4'] = (int) $_POST['crop'] * 86400; //+25% Crop
if($sessionaccess != 9) die("<h1><font color=\"red\">Access Denied: You are not Admin!</font></h1>");
$user = $database->getUserArray($id, 1);
$pdur = (int) $_POST['plus'] * 86400;
$b1dur = (int) $_POST['wood'] * 86400;
$b2dur = (int) $_POST['clay'] * 86400;
$b3dur = (int) $_POST['iron'] * 86400;
$b4dur = (int) $_POST['crop'] * 86400;
$sql1 = mysqli_query($GLOBALS["link"], "SELECT * FROM ".TB_PREFIX."users WHERE id = ".$id."");
$user = mysqli_fetch_array($sql1);
if($user['plus'] < time()){
if($pdur > 1){ $plus = (time() + $pdur); } else { $plus = time(); }
}else{
if($pdur > 1){ $plus = ($user['plus'] + $pdur); } else { $plus = $user['plus']; }
}
if($user['b1'] < time()){
if($b1dur > 1){ $wood = (time() + $b1dur); } else { $wood = time(); }
}else{
if($b1dur > 1){ $wood = ($user['b1'] + $b1dur); } else { $wood = $user['b1']; }
}
if($user['b2'] < time()){
if($b2dur > 1){ $clay = (time() + $b2dur); } else { $clay = time(); }
}else{
if($b2dur > 1){ $clay = ($user['b2'] + $b2dur); } else { $clay = $user['b2']; }
}
if($user['b3'] < time()){
if($b3dur > 1){ $iron = (time() + $b3dur); } else { $iron = time(); }
}else{
if($b3dur > 1){ $iron = ($user['b3'] + $b3dur); } else { $iron = $user['b3']; }
}
if($user['b4'] < time()){
if($b4dur > 1){ $crop = (time() + $b4dur); } else { $crop = time(); }
}else{
if($b4dur > 1){ $crop = ($user['b4'] + $b4dur); } else { $crop = $user['b4']; }
foreach($bonusDuration as $index => $bonus){
$bonusDuration[$index] = $bonusDuration[$index] + ($user[$index] < $time ? $time : $user[$index]);
if($bonusDuration[$index] < $time) $bonusDuration[$index] = 0;
}
mysqli_query($GLOBALS["link"], "UPDATE ".TB_PREFIX."users SET
plus = '".$plus."',
b1 = '".$wood."',
b2 = '".$clay."',
b3 = '".$iron."',
b4 = '".$crop."'
WHERE id = $id") or die(mysqli_error($database->dblink));
$database->updateUserField($id, array_keys($bonusDuration), array_values($bonusDuration), 1);
header("Location: ../../../Admin/admin.php?p=player&uid=".$id."");
?>
-8
View File
@@ -30,14 +30,6 @@ for ($i = 0; $i < 5; $i++) {
include_once($autoprefix."GameEngine/Database.php");
$session = (int) $_POST['admid'];
$sql = mysqli_query($GLOBALS["link"], "SELECT * FROM ".TB_PREFIX."users WHERE id = ".$session."");
$access = mysqli_fetch_array($sql);
$sessionaccess = $access['access'];
if($sessionaccess != 9) die("<h1><font color=\"red\">Access Denied: You are not Admin!</font></h1>");
$sql = "SELECT id FROM ".TB_PREFIX."users ORDER BY ID DESC LIMIT 1";
$loops = mysqli_result(mysqli_query($GLOBALS["link"], $sql), 0);
+3 -3
View File
@@ -102,7 +102,7 @@ class funct
exit;
}
//Return the artifacts to the Natars' account
$artifact->returnArtifactToNatars($artifactInfo);
break;
@@ -139,7 +139,7 @@ class funct
$artifactArrays[$selectedArtifact[2]][] = $chosenArtifact;
//Add the artifacts
$artifact->addArtifactVillages($artifactArrays, $playerId);
$artifact->addArtifactVillages($artifactArrays, $playerId, $playerId == Artifacts::NATARS_UID);
break;
case "addWWVillages":
@@ -154,7 +154,7 @@ class funct
}
//Create the desired WW villages
$artifact->createWWVillages($numberOfVillages, $playerId);
$artifact->createWWVillages($numberOfVillages, $playerId, $playerId == Artifacts::NATARS_UID);
break;
case "killHero":
+12 -8
View File
@@ -269,9 +269,10 @@ class Artifacts
*
* @param array $artifactArrays The array containing the artifacts to insert
* @param int $uid The owner's user ID (Natars)
* @param bool $addTroops Add troops to the village if true, and vice versa if false
*/
public function addArtifactVillages($artifactArrays, $uid = self::NATARS_UID) {
public function addArtifactVillages($artifactArrays, $uid = self::NATARS_UID, $addTroops = true) {
global $database;
//Variables initialization
@@ -290,7 +291,7 @@ class Artifacts
$unitArrays = ($this->natarsArtifactsUnits)($multiplier);
//Generate the unit arrays
$artifactTroops[1][] = array_values($unitArrays);
if($addTroops) $artifactTroops[1][] = array_values($unitArrays);
$artifactBuildings[1][] = array_values(self::NATARS_ARTIFACTS_BUILDINGS);
//Generate the artifacts array
@@ -302,11 +303,11 @@ class Artifacts
}
//Set the unit types by using the last $unitArrays
$artifactTroops[0] = array_keys($unitArrays);
if($addTroops) $artifactTroops[0] = array_keys($unitArrays);
$artifactBuildings[0] = array_keys(self::NATARS_ARTIFACTS_BUILDINGS);
//Generate the wids
$wids = array_merge($wids, (array)$database->generateVillages($artifactVillages, $uid, TRIBE5, $artifactTroops, $artifactBuildings));
$wids = array_merge($wids, (array)$database->generateVillages($artifactVillages, $uid, TRIBE5, $addTroops ? $artifactTroops : null, $artifactBuildings));
//Create the artifacts for the generated wids
$database->addArtefacts($wids, $artifactsToAdd);
@@ -315,22 +316,25 @@ class Artifacts
/**
* Called when WW villages need to be created
*
* @param int $numberOfVillages The number of villages that have to be added
* @param int $uid The player ID
* @param bool $addTroops Add troops to the village if true, and vice versa if false
*/
public function createWWVillages($numberOfVillages = self::NATARS_BASE_WW_VILLAGES, $uid = self::NATARS_UID){
public function createWWVillages($numberOfVillages = self::NATARS_BASE_WW_VILLAGES, $uid = self::NATARS_UID, $addTroops = true){
global $database;
$villageArrays = $troopArrays = $buildingArrays = $wids = [];
for($i = 1; $i <= $numberOfVillages; $i++){
$villageArrays[] = ['wid' => 0, 'mode' => 5, 'type' => 3, 'kid' => ($i == $numberOfVillages ? rand(1, 4) : ($i % 4) + 1), 'capital' => 0, 'pop' => 233, 'name' => WWVILLAGE, 'natar' => 1];
$troopArrays[1][] = array_values(($this->natarsWWVillagesUnits)());
if($addTroops) $troopArrays[1][] = array_values(($this->natarsWWVillagesUnits)());
$buildingArrays[1][] = array_values(self::NATARS_WW_VILLAGES_BUILDINGS);
}
$troopArrays[0] = array_keys(($this->natarsWWVillagesUnits)());
if($addTroops) $troopArrays[0] = array_keys(($this->natarsWWVillagesUnits)());
$buildingArrays[0] = array_keys(self::NATARS_WW_VILLAGES_BUILDINGS);
$wids = $database->generateVillages($villageArrays, $uid, null, $troopArrays, $buildingArrays);
$wids = $database->generateVillages($villageArrays, $uid, null, $addTroops ? $troopArrays : null, $buildingArrays);
}
/**
+16 -21
View File
@@ -808,11 +808,8 @@ class MYSQLi_DB implements IDbConnection {
$pairs[] = $this->escape($fieldName) . ' = ' . (Math::isInt($value[$index]) ? $value[$index] : '"'.$this->escape($value[$index]).'"');
}
if(!$switch) {
$q = "UPDATE " . TB_PREFIX . "users SET ".implode(', ', $pairs)." where username = '$ref'";
} else {
$q = "UPDATE " . TB_PREFIX . "users SET ".implode(', ', $pairs)." where id = " . (int) $ref;
}
if(!$switch) $q = "UPDATE " . TB_PREFIX . "users SET ".implode(', ', $pairs)." where username = '$ref'";
else $q = "UPDATE " . TB_PREFIX . "users SET ".implode(', ', $pairs)." where id = " . (int) $ref;
// update cached values
if ($ret = mysqli_query($this->dblink,$q)) {
@@ -1138,20 +1135,20 @@ class MYSQLi_DB implements IDbConnection {
function modifyGold($userid, $amt, $mode) {
list($userid, $amt, $mode) = $this->escape_input((int) $userid, (int) $amt, $mode);
if(!$mode) {
$q = "UPDATE " . TB_PREFIX . "users set gold = gold - $amt where id = $userid";
} else {
$q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid";
}
if(!$mode) $q = "UPDATE " . TB_PREFIX . "users set gold = gold - $amt where id = $userid";
else $q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid";
return mysqli_query($this->dblink,$q);
}
/*****************************************
Function to retrieve user array via Username or ID
Mode 0: Search by Username
Mode 1: Search by ID
References: Alliance ID
*****************************************/
/**
* Retrieves the user array via Username or ID
*
* @param int $ref The user ID or the username
* @param int $mode 0 --> Search by username, 1 --> Search by user ID
* @param bool $use_cache Will use the cache if true
* @return array Returns the user array
*/
function getUserArray($ref, $mode, $use_cache = true) {
list($ref, $mode) = $this->escape_input($ref, $mode);
@@ -1162,11 +1159,9 @@ class MYSQLi_DB implements IDbConnection {
return $cachedValue;
}
if(!$mode) {
$q = "SELECT * FROM " . TB_PREFIX . "users where username = '$ref' LIMIT 1";
} else {
$q = "SELECT * FROM " . TB_PREFIX . "users where id = " . (int) $ref . " LIMIT 1";
}
if(!$mode) $q = "SELECT * FROM " . TB_PREFIX . "users where username = '$ref' LIMIT 1";
else $q = "SELECT * FROM " . TB_PREFIX . "users where id = " . (int) $ref . " LIMIT 1";
$result = mysqli_query($this->dblink,$q);
self::$fieldsCache[$ref.$mode] = mysqli_fetch_array($result);