General fixes

+Fixed a bug that permitted to attack occupied oasis (even through the
farmlist) even if the oasis' owner was banned
+Rewritten some code in Units.php, for a better errors handling
+Fixed some errors that could have showed sometimes
+Fixed a bug that didn't permit to send an attack under certain
circumstances
+Villages/oasis with X = 0 or Y = 0 as a coordinates, can now be raided
+You are now be able to send resources with the merchants, at villages
with X = 0 or Y = 0 as a coordinates
This commit is contained in:
iopietro
2018-05-29 18:57:14 +02:00
parent 498aaa962a
commit 36b790d08a
9 changed files with 181 additions and 226 deletions
+72 -84
View File
@@ -796,18 +796,12 @@ class MYSQLi_DB implements IDbConnection {
public function hasBeginnerProtection($vid) {
list($vid) = $this->escape_input($vid);
$q = "SELECT u.protect FROM ".TB_PREFIX."users u,".TB_PREFIX."vdata v WHERE u.id=v.owner AND v.wref=".(int) $vid." LIMIT 1";
$q = "SELECT u.protect FROM ".TB_PREFIX."users u,".TB_PREFIX."vdata v,".TB_PREFIX."odata o WHERE (u.id = v.owner AND v.wref = ".(int) $vid.") OR (u.id = o.owner AND o.wref = ".(int) $vid.") LIMIT 1";
$result = mysqli_query($this->dblink,$q);
$dbarray = mysqli_fetch_array($result);
if(!empty($dbarray)) {
if(time()<$dbarray[0]) {
return true;
} else {
return false;
}
} else {
return false;
}
if(!empty($dbarray)) return time() < $dbarray[0];
else return false;
}
function updateUserField($ref, $field, $value, $switch) {
@@ -2294,12 +2288,14 @@ class MYSQLi_DB implements IDbConnection {
'%$uid%'
";
$result = mysqli_query($this->dblink, $q);
while($row = mysqli_fetch_assoc($result)) {
switch($row['forum_area']){
case 0: $allianceForums[] = $row; break;
case 2: $confForums[] = $row; break;
case 3: $closedForums[] = $row; break;
}
if(!empty($result)){
while($row = mysqli_fetch_assoc($result)) {
switch($row['forum_area']){
case 0: $allianceForums[] = $row; break;
case 2: $confForums[] = $row; break;
case 3: $closedForums[] = $row; break;
}
}
}
//Get the alliance confederation forums
@@ -5370,12 +5366,14 @@ References: User ID/Message ID, Mode
return mysqli_fetch_assoc($result);
}
/***************************
Function to add market offer
Mode 0: Add
Mode 1: Cancel
References: Village, Give, Amt, Want, Amt, Time, Alliance, Mode
***************************/
/**
* Function to add market offer
*
* Mode 0: Add
* Mode 1: Cancel
* References: Village, Give, Amt, Want, Amt, Time, Alliance, Mode
*/
function addMarket($vid, $gtype, $gamt, $wtype, $wamt, $time, $alliance, $merchant, $mode) {
list($vid, $gtype, $gamt, $wtype, $wamt, $time, $alliance, $merchant, $mode) = $this->escape_input((int) $vid, (int) $gtype, (int) $gamt, (int) $wtype, (int) $wamt, (int) $time, (int) $alliance, (int) $merchant, $mode);
@@ -5579,16 +5577,13 @@ References: User ID/Message ID, Mode
}
// no need to cache this method
function getA2b($ckey, $check) {
list($ckey, $check) = $this->escape_input($ckey, $check);
function getA2b($ckey) {
list($ckey) = $this->escape_input($ckey);
$q = "SELECT * from " . TB_PREFIX . "a2b where ckey = '" . $ckey . "' AND time_check = '" . $check . "'";
$q = "SELECT * from " . TB_PREFIX . "a2b where ckey = '" . $ckey . "'";
$result = mysqli_query($this->dblink,$q);
if($result) {
return mysqli_fetch_assoc($result);
} else {
return false;
}
if($result) return mysqli_fetch_assoc($result);
else return false;
}
function addMovement($type, $from, $to, $ref, $time, $endtime, $send = 1, $wood = 0, $clay = 0, $iron = 0, $crop = 0, $ref2 = 0) {
@@ -8044,57 +8039,55 @@ References: User ID/Message ID, Mode
self::$prisonersCache = [];
}
/*****************************************
Function to vacation mode - by advocaite
References:
*****************************************/
/*****************************************
Function to vacation mode - by advocaite
References:
*****************************************/
function setvacmode($uid,$days) {
// TODO: refactor vacation mode
return;
function setvacmode($uid, $days)
{
// TODO: refactor vacation mode
return;
list ($uid, $days) = $this->escape_input((int) $uid, (int) $days);
$days1 = 60 * 60 * 24 * $days;
$time = time() + $days1;
$q = "UPDATE " . TB_PREFIX . "users SET vac_mode = '1' , vac_time=" . $time . " WHERE id=" . $uid . "";
$result = mysqli_query($this->dblink, $q);
}
list($uid,$days) = $this->escape_input((int) $uid,(int) $days);
$days1 =60*60*24*$days;
$time =time()+$days1;
$q ="UPDATE ".TB_PREFIX."users SET vac_mode = '1' , vac_time=".$time." WHERE id=".$uid."";
$result =mysqli_query($this->dblink,$q);
}
function removevacationmode($uid)
{
// TODO: refactor vacation mode
return;
list ($uid) = $this->escape_input((int) $uid);
$q = "UPDATE " . TB_PREFIX . "users SET vac_mode = '0' , vac_time='0' WHERE id=" . $uid . "";
$result = mysqli_query($this->dblink, $q);
}
function removevacationmode($uid) {
// TODO: refactor vacation mode
return;
list($uid) = $this->escape_input((int) $uid);
$q ="UPDATE ".TB_PREFIX."users SET vac_mode = '0' , vac_time='0' WHERE id=".$uid."";
$result =mysqli_query($this->dblink,$q);
}
function getvacmodexy($wref) {
// TODO: refactor vacation mode
return;
list($wref) = $this->escape_input((int) $wref);
$q = "SELECT id,oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref";
$result = mysqli_query($this->dblink,$q);
$dbarray = mysqli_fetch_array($result);
if($dbarray['occupied'] != 0 && $dbarray['oasistype'] == 0) {
$q1 = "SELECT owner FROM " . TB_PREFIX . "vdata where wref = ".(int) $dbarray['id']."";
$result1 = mysqli_query($this->dblink,$q1);
$dbarray1 = mysqli_fetch_array($result1);
if($dbarray1['owner'] != 0){
$q2 = "SELECT vac_mode,vac_time FROM " . TB_PREFIX . "users where id = ".(int) $dbarray1['owner']."";
$result2 = mysqli_query($this->dblink,$q2);
$dbarray2 = mysqli_fetch_array($result2);
if($dbarray2['vac_mode'] ==1){
return true;
}else{
return false;
}
}
} else {
return false;
}
}
function getvacmodexy($wref)
{
// TODO: refactor vacation mode
return;
list ($wref) = $this->escape_input((int) $wref);
$q = "SELECT id,oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref";
$result = mysqli_query($this->dblink, $q);
$dbarray = mysqli_fetch_array($result);
if ($dbarray['occupied'] != 0 && $dbarray['oasistype'] == 0) {
$q1 = "SELECT owner FROM " . TB_PREFIX . "vdata where wref = " . (int) $dbarray['id'] . "";
$result1 = mysqli_query($this->dblink, $q1);
$dbarray1 = mysqli_fetch_array($result1);
if ($dbarray1['owner'] != 0) {
$q2 = "SELECT vac_mode,vac_time FROM " . TB_PREFIX . "users where id = " . (int) $dbarray1['owner'] . "";
$result2 = mysqli_query($this->dblink, $q2);
$dbarray2 = mysqli_fetch_array($result2);
return $dbarray2['vac_mode'] == 1;
}
}
else return false;
}
// no need to cache this method
function getHeroDeadReviveOrInTraining($id) {
@@ -8102,11 +8095,7 @@ References:
$q = "SELECT Count(*) as Total FROM " . TB_PREFIX . "hero WHERE `uid` = $id AND dead = 0 AND inrevive = 0 AND intraining = 0";
$result = mysqli_fetch_array(mysqli_query($this->dblink,$q), MYSQLI_ASSOC);
if ($result['Total'] > 0) {
return true;
} else {
return false;
}
return $result['Total'] > 0;
}
/***************************
@@ -8117,7 +8106,6 @@ References:
list( $id ) = $this->escape_input( (int) $id );
$q = "UPDATE " . TB_PREFIX . "hero set dead = 1, intraining = 0, inrevive = 0, health = 0 where uid = " . $id . " AND dead = 0";
return mysqli_query( $this->dblink, $q );
}
+90 -121
View File
@@ -76,19 +76,40 @@ class Units {
}
private function loadUnits($post) {
global $database, $village, $session, $generator, $logging, $form;
global $form;
if(!empty($error = $this->checkErrors($post))) {
$form->addError("error", $error);
$_SESSION['errorarray'] = $form->getErrors();
$_SESSION['valuearray'] = $_POST;
header("Location: a2b.php");
exit;
}
else return $post;
}
/**
* Gets an error if the user did a mistake
*
* @param array $post The array containing all of the needed informations
* @return string Returns the errors, or empty if no errors was found
*/
public function checkErrors(&$post){
global $database, $village, $session, $generator;
// Search by town name
// Coordinates and look confirm name people
if(isset($post['x']) && isset($post['y']) && !empty($post['x']) && !empty($post['y'])) {
if(isset($post['x']) && isset($post['y']) && $post['x'] != "" && $post['y'] != "") {
$vid = $database->getVilWref($post['x'], $post['y']);
unset($post['dname'], $post['dname']);
}else if(isset($post['dname']) && !empty($post['dname'])){
$vid = $database->getVillageByName(stripslashes($post['dname']));
}
else if(isset($post['dname']) && !empty($post['dname'])) $vid = $database->getVillageByName(stripslashes($post['dname']));
if (!empty($vid)) {
if($database->isVillageOases($vid)){
$too = $database->getOasisField($vid,"conqured");
if($too == 0) $disabled = $disabledr ="disabled=disabled";
if($isOasis = $database->isVillageOases($vid)){
$too = $database->getOasisField($vid, "conqured");
if($too == 0) $disabled = $disabledr ="disabled=disabled";
else
{
$disabledr = "";
@@ -102,128 +123,84 @@ class Units {
$disabled = "";
}else{
$disabledr = "";
if($session->sit == 0) $disabled = "";
if($session->sit == 0) $disabled = "";
else $disabled ="disabled=disabled";
}
}
}else{
$disabledr = "";
if($session->sit == 0) $disabled = "";
if($session->sit == 0) $disabled = "";
else $disabled ="disabled=disabled";
}
if(!empty($disabledr) && $post['c'] == 2){
$form->addError("error","You can't reinforce this village/oasis");
}
if(!empty($disabled) && $post['c'] == 3){
$form->addError("error","You can't attack this village/oasis with normal attack");
}
if($post['c'] < 2 || $post['c'] > 4) $form->addError("error", "Invalid attack type.");
if(empty($post['t1']) && empty($post['t2']) && empty($post['t3']) && empty($post['t4']) && empty($post['t5']) &&
empty($post['t6']) && empty($post['t7']) && empty($post['t8']) && empty($post['t9']) && empty($post['t10']) && empty($post['t11'])){
$form->addError("error","You need to mark min. one troop");
}
if(!empty($post['dname']) && !empty($post['x']) && !empty($post['y'])){
$form->addError("error","Insert name or coordinates");
}
if(isset($post['dname']) && !empty($post['dname'])) {
$id = $database->getVillageByName(stripslashes($post['dname']));
if (!isset($id)) $form->addError("error","Village do not exist");
else $coor = $database->getCoor($id);
}
// People search by coordinates
// We confirm and seek coordinate coordinates Village
if(isset($post['x']) && isset($post['y']) && !empty($post['x']) && !empty($post['y'])) {
if(!empty($disabledr) && $post['c'] == 2) return "You can't reinforce this village/oasis";
if(!empty($disabled) && $post['c'] == 3) return "You can't attack this village/oasis with normal attack";
if($post['c'] < 2 || $post['c'] > 4) return "Invalid attack type.";
//check if at least one troops has been selected
for($i = 1; $i <= 11; $i++) $selectedTroops += empty($post['t'.$i]) ? 0 : $post['t'.$i];
if($selectedTroops == 0) return "You need to select min. one troop";
if(!empty($post['dname']) && $post['x'] != "" && $post['y'] != "") return "Insert name or coordinates";
if(isset($post['dname']) && !empty($post['dname'])) {
$id = $database->getVillageByName(stripslashes($post['dname']));
if (!isset($id)) return "Village doesn't exist";
else $coor = $database->getCoor($id);
}
// People search by coordinates
// We confirm and seek coordinate coordinates Village
if(isset($post['x']) && isset($post['y']) && $post['x'] != "" && $post['y'] != "") {
$coor = ['x' => $post['x'], 'y' => $post['y']];
$id = $generator->getBaseID($coor['x'], $coor['y']);
if (!$database->getVillageState($id)) $form->addError("error","Coordinates do not exist");
}
if (!$database->getVillageState($id)) return "Coordinates do not exist";
}
if (!empty($coor)) {
if (!empty($coor)) {
$Gtribe = $session->tribe == 1 ? "" : $session->tribe - 1;
for($i = 1; $i < 12; $i++){
if(isset($post['t'.$i])){
if ($i < 10) $troophave = $village->unitarray['u'.$Gtribe.$i];
if ($i == 10) $troophave = $village->unitarray['u'.floor(intval($Gtribe) + 1) * $i];
if ($i == 11) $troophave = $village->unitarray['hero'];
if (intval($post['t'.$i]) > $troophave){
$form->addError("error","You can't send more units than you have");
break;
}
if(intval($post['t'.$i])<0){
$form->addError("error","You can't send negative units.");
break;
}
if(preg_match('/[^0-9]/',$post['t'.$i])){
$form->addError("error","Special characters can't entered");
break;
}
if($i < 10) $troophave = $village->unitarray['u'.$Gtribe.$i];
if($i == 10) $troophave = $village->unitarray['u'.floor(intval($Gtribe) + 1) * $i];
if($i == 11) $troophave = $village->unitarray['hero'];
if(intval($post['t'.$i]) > $troophave) return "You can't send more units than you have";
if(intval($post['t'.$i]) < 0) return "You can't send negative units.";
if(preg_match('/[^0-9]/',$post['t'.$i])) return "Special characters can't entered";
}
}
}
if(isset($id) && $database->isVillageOases($id) == 0) {
if($database->hasBeginnerProtection($id) == 1) {
$form->addError("error","Player is under beginners protection. You can't attack him");
}
if(isset($id)) {
//check if the attacked village/oasis' owner is under beginners protection
if($database->hasBeginnerProtection($id) == 1) return "Player is under beginners protection. You can't attack him";
//check if it's an oasis or not
$villageInfo = (!$isOasis) ? $database->getVillage($id) : $database->getOasisV($id);
//check if banned/admin:
$villageOwner = $database->getVillageField($id,'owner');
$userAccess = $database->getUserField($villageOwner,'access',0);
$userID = $database->getUserField($villageOwner,'id',0);
$villageOwner = $villageInfo['owner'];
$userAccess = $database->getUserField($villageOwner, 'access', 0);
$userID = $database->getUserField($villageOwner, 'id', 0);
//check if he's an Admin and if he's attackable
if($userAccess == 0 || ($userAccess == MULTIHUNTER && $userID == 5) || (!ADMIN_ALLOW_INCOMING_RAIDS && $userAccess == ADMIN)){
$form->addError("error","Player is Banned. You can't attack him");
//break;
}
//check if vacation mode:
if($database->getvacmodexy($id)){
$form->addError("error","User is on vacation mode");
//break;
return "Player is Banned. You can't attack him";
}
//check if the user' is on the vacation mode:
if($database->getvacmodexy($id)) return "User is on vacation mode";
//check if attacking same village that units are in
if($id == $village->wid){
$form->addError("error","You cant attack same village you are sending from.");
//break;
}
// We process the array with the errors given in the form
if($form->returnErrors() > 0) {
$_SESSION['errorarray'] = $form->getErrors();
$_SESSION['valuearray'] = $_POST;
header("Location: a2b.php");
exit;
}else{
// We must return an array with $ post, which contains all the data more
// another variable that will define the flag is raised and is being sent and the type of shipping
$villageName = $database->getVillageField($id,'name');
$speed = 300;
$timetaken = $generator->procDistanceTime($coor, $village->coor, INCREASE_SPEED, 1);
array_push($post, "$id", "$villageName", "$villageOwner","$timetaken");
return $post;
}
}else{
if($form->returnErrors() > 0) {
$_SESSION['errorarray'] = $form->getErrors();
$_SESSION['valuearray'] = $_POST;
header("Location: a2b.php");
exit;
} else if (isset($id)) {
$villageName = $database->getOasisField($id,"name");
$speed = 300;
$timetaken = $generator->procDistanceTime($coor, $village->coor, INCREASE_SPEED, 1);
array_push($post, "$id", "$villageName", "2","$timetaken");
return $post;
}
if($id == $village->wid) return "You cant attack same village you are sending from.";
}
//no errors, we can add the additional information to the post array
array_push($post, $id, $villageInfo['name'], $villageInfo['owner'], 0);
return "";
}
public function returnTroops($wref, $mode = 0) {
@@ -259,33 +236,25 @@ class Units {
private function sendTroops($post) {
global $form, $database, $village, $session;
$data = $database->getA2b( $post['timestamp_checksum'], $post['timestamp'] );
$data = $database->getA2b($post['timestamp_checksum']);
$Gtribe = ($session->tribe == 1) ? "" : $session->tribe - 1;
for ($i = 1; $i < 10; $i++) {
if (isset($data['u'.$i])) {
if ($data['u'.$i] > $village->unitarray['u'.$Gtribe.$i]) {
$form->addError("error", "You can't send more units than you have");
break;
}
if ($data[ 'u'.$i ] < 0) {
if ($data['u'.$i] < 0) {
$form->addError("error", "You can't send negative units.");
break;
}
}
}
if ($data['u11'] > $village->unitarray['hero']) {
$form->addError( "error", "You can't send more units than you have");
}
if ($data['u11'] < 0) {
$form->addError( "error", "You can't send negative units.");
}
if ($data['u11'] > $village->unitarray['hero']) $form->addError("error", "You can't send more units than you have");
if ($data['u11'] < 0) $form->addError("error", "You can't send negative units.");
if($data['type'] != 1 && $post['spy'] != 0) $post['spy'] = 0;
if ($form->returnErrors() > 0) {
@@ -425,7 +394,6 @@ class Units {
header("Location: build.php?id=39");
exit;
} else {
header("Location: banned.php");
exit;
@@ -802,7 +770,9 @@ class Units {
for($i = 1; $i <= 6; $i++) ${'t'.$i} = $raidList['t'.$i];
$villageOwner = !$database->isVillageOases($wref) ? $database->getVillageField($wref, 'owner') : 2;
if(!$database->isVillageOases($wref)) $villageOwner = $database->getVillageField($wref, 'owner');
else $villageOwner = $database->getOasisField($wref, 'owner');
$userAccess = $database->getUserField($villageOwner, 'access', 0);
$userID = $database->getUserField($villageOwner, 'id', 0);
@@ -825,9 +795,8 @@ class Units {
//Send the attack
if($canSend){
$ckey = $generator->generateRandStr(6);
$time_now = time();
$id = $database->addA2b($ckey, $time_now, $wref, $t1, $t2, $t3, $t4, $t5, $t6, 0, 0, 0, 0, 0, 4);
$data = $database->getA2b($ckey, $time_now);
$id = $database->addA2b($ckey, 0, $wref, $t1, $t2, $t3, $t4, $t5, $t6, 0, 0, 0, 0, 0, 4);
$data = $database->getA2b($ckey);
$troopsTime = $this->getWalkingTroopsTime($getFLData['wref'], $data['to_vid'], $session->uid, $session->tribe, $data, 1, 'u');
$time = $database->getArtifactsValueInfluence($getFLData['owner'], $getFLData['wref'], 2, $troopsTime);