mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-14 00:26:07 +00:00
General fixes
+Removed almost all "BANNED" controls to template and .php UI files. The control will be done only once and in the Session class
This commit is contained in:
+62
-118
@@ -221,7 +221,7 @@ class Alliance {
|
||||
*****************************************/
|
||||
public function sendInvite($post) {
|
||||
global $form, $database, $session;
|
||||
if($session->access != BANNED){
|
||||
|
||||
$UserData = $database->getUserArray(stripslashes($post['a_name']), 0);
|
||||
if($this->userPermArray['opt4'] == 0) {
|
||||
$form->addError("name", NO_PERMISSION);
|
||||
@@ -257,10 +257,6 @@ class Alliance {
|
||||
0,
|
||||
true);
|
||||
}
|
||||
}else{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
@@ -268,19 +264,15 @@ class Alliance {
|
||||
*****************************************/
|
||||
private function rejectInvite($get) {
|
||||
global $database, $session;
|
||||
if($session->access != BANNED){
|
||||
|
||||
foreach($this->inviteArray as $invite) {
|
||||
if($invite['id'] == $get['d'] && $invite['uid'] == $session->uid) {
|
||||
$database->removeInvitation($get['d']);
|
||||
$database->insertAlliNotice($invite['alliance'], '<a href="spieler.php?uid='.$session->uid.'">'.addslashes($session->username).'</a> has rejected the invitation.');
|
||||
}
|
||||
}
|
||||
header("Location: build.php?gid=18");
|
||||
exit;
|
||||
}else{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
header("Location: build.php?gid=18");
|
||||
exit;
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
@@ -288,7 +280,7 @@ class Alliance {
|
||||
*****************************************/
|
||||
private function delInvite($get) {
|
||||
global $database, $session;
|
||||
if($session->access != BANNED){
|
||||
|
||||
$inviteArray = $database->getAliInvitations($session->alliance);
|
||||
foreach($inviteArray as $invite) {
|
||||
if($invite['id'] == $get['d'] && $invite['alliance'] == $session->alliance && $this->userPermArray['opt4'] == 1) {
|
||||
@@ -297,12 +289,8 @@ class Alliance {
|
||||
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid='.$session->uid.'">'.addslashes($session->username).'</a> has deleted the invitation for <a href="spieler.php?uid='.$invitename['id'].'">'.addslashes($invitename['username']).'</a>.');
|
||||
}
|
||||
}
|
||||
header("Location: allianz.php?delinvite");
|
||||
exit;
|
||||
}else{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
header("Location: allianz.php?delinvite");
|
||||
exit;
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
@@ -311,34 +299,29 @@ class Alliance {
|
||||
private function acceptInvite($get) {
|
||||
global $form, $database, $session;
|
||||
|
||||
if ($session->access != BANNED) {
|
||||
foreach ($this->inviteArray as $invite) {
|
||||
if ($session->alliance == 0) {
|
||||
if ($invite['id'] == $get['d'] && $invite['uid'] == $session->uid) {
|
||||
$memberlist = $database->getAllMember($invite['alliance']);
|
||||
$alliance_info = $database->getAlliance($invite['alliance']);
|
||||
if (count($memberlist) < $alliance_info['max']) {
|
||||
$database->removeInvitation($get['d']);
|
||||
$database->updateUserField($invite['uid'], "alliance", $invite['alliance'], 1);
|
||||
$database->createAlliPermissions($invite['uid'], $invite['alliance'], '', 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
// Log the notice
|
||||
$database->insertAlliNotice($invite['alliance'], '<a href="spieler.php?uid='.$session->uid.'">'.addslashes($session->username).'</a> has joined the alliance.');
|
||||
} else {
|
||||
$accept_error = 1;
|
||||
$max = $alliance_info['max'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($accept_error == 1){
|
||||
$form->addError("ally_accept", "The alliance can contain only ".$max." members at this moment.");
|
||||
}else{
|
||||
header("Location: build.php?gid=18");
|
||||
exit;
|
||||
}
|
||||
} else{
|
||||
header("Location: banned.php");
|
||||
foreach ($this->inviteArray as $invite) {
|
||||
if ($session->alliance == 0) {
|
||||
if ($invite['id'] == $get['d'] && $invite['uid'] == $session->uid) {
|
||||
$memberlist = $database->getAllMember($invite['alliance']);
|
||||
$alliance_info = $database->getAlliance($invite['alliance']);
|
||||
if (count($memberlist) < $alliance_info['max']) {
|
||||
$database->removeInvitation($get['d']);
|
||||
$database->updateUserField($invite['uid'], "alliance", $invite['alliance'], 1);
|
||||
$database->createAlliPermissions($invite['uid'], $invite['alliance'], '', 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
// Log the notice
|
||||
$database->insertAlliNotice($invite['alliance'], '<a href="spieler.php?uid='.$session->uid.'">'.addslashes($session->username).'</a> has joined the alliance.');
|
||||
} else {
|
||||
$accept_error = 1;
|
||||
$max = $alliance_info['max'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($accept_error == 1) $form->addError("ally_accept", "The alliance can contain only ".$max." members at this moment.");
|
||||
else
|
||||
{
|
||||
header("Location: build.php?gid=18");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -348,7 +331,7 @@ class Alliance {
|
||||
*****************************************/
|
||||
private function createAlliance($post) {
|
||||
global $form, $database, $session, $bid18, $building;
|
||||
if($session->access != BANNED){
|
||||
|
||||
if(!isset($post['ally1']) || $post['ally1'] == "") {
|
||||
$form->addError("ally1", ATAG_EMPTY);
|
||||
}
|
||||
@@ -385,10 +368,6 @@ class Alliance {
|
||||
header("Location: build.php?gid=18");
|
||||
exit;
|
||||
}
|
||||
}else{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
@@ -397,11 +376,6 @@ class Alliance {
|
||||
private function changeAliName($get) {
|
||||
global $form, $database, $session;
|
||||
|
||||
if($session->access == BANNED) {
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$userAlly = $database->getAlliance($session->alliance);
|
||||
|
||||
if(!isset($get['ally1']) || $get['ally1'] == "") $form->addError("ally1", ATAG_EMPTY);
|
||||
@@ -431,7 +405,7 @@ class Alliance {
|
||||
*****************************************/
|
||||
private function updateAlliProfile($post) {
|
||||
global $database, $session, $form;
|
||||
if($session->access != BANNED){
|
||||
|
||||
if($this->userPermArray['opt3'] == 0) {
|
||||
$form->addError("perm", NO_PERMISSION);
|
||||
}
|
||||
@@ -443,10 +417,6 @@ class Alliance {
|
||||
// log the notice
|
||||
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid='.$session->uid.'">'.addslashes($session->username).'</a> has changed the alliance description.');
|
||||
}
|
||||
}else{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
@@ -455,12 +425,7 @@ class Alliance {
|
||||
private function changeUserPermissions($post)
|
||||
{
|
||||
global $database, $session, $form;
|
||||
if($session->access == BANNED)
|
||||
{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
if($this->userPermArray['opt1'] == 0) $form->addError("perm", NO_PERMISSION);
|
||||
elseif($database->getUserField($post['a_user'], "alliance", 0) != $session->alliance) $form->addError("perm", USER_NOT_IN_YOUR_ALLY);
|
||||
elseif($post['a_user'] == $session->uid) $form->addError("perm", CANT_EDIT_YOUR_PERMISSIONS);
|
||||
@@ -487,31 +452,26 @@ class Alliance {
|
||||
private function kickAlliUser($post) {
|
||||
global $database, $session, $form;
|
||||
|
||||
if ($session->access != BANNED) {
|
||||
$UserData = $database->getUserArray($post['a_user'], 1);
|
||||
if($this->userPermArray['opt2'] == 0) {
|
||||
$form->addError("perm", NO_PERMISSION);
|
||||
} else if($database->getUserField($post['a_user'], "alliance", 0) != $session->alliance){
|
||||
$form->addError("perm", USER_NOT_IN_YOUR_ALLY);
|
||||
} else if($UserData['id'] != $session->uid){
|
||||
$database->updateUserField($post['a_user'], 'alliance', 0, 1);
|
||||
$database->deleteAlliPermissions($post['a_user']);
|
||||
$database->deleteAlliance($session->alliance);
|
||||
// log the notice
|
||||
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid='.$UserData['id'].'">'.($kickedUsername = addslashes($database->getUserField($post['a_user'], "username", 0))).'</a> has been expelled from the alliance by <a href="spieler.php?uid='.$session->uid.'">'.addslashes($session->username).'</a>.');
|
||||
if($session->alliance && $database->isAllianceOwner($UserData['id']) == $session->alliance){
|
||||
$newowner = $database->getAllMember2($session->alliance);
|
||||
$newleader = $newowner['id'];
|
||||
$q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $session->alliance."";
|
||||
$database->query($q);
|
||||
$database->updateAlliPermissions($newleader, 1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
Automation::updateMax($newleader);
|
||||
}
|
||||
$form->addError("perm", $kickedUsername.ALLY_USER_KICKED);
|
||||
}
|
||||
} else {
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
$UserData = $database->getUserArray($post['a_user'], 1);
|
||||
if($this->userPermArray['opt2'] == 0) {
|
||||
$form->addError("perm", NO_PERMISSION);
|
||||
} else if($database->getUserField($post['a_user'], "alliance", 0) != $session->alliance){
|
||||
$form->addError("perm", USER_NOT_IN_YOUR_ALLY);
|
||||
} else if($UserData['id'] != $session->uid){
|
||||
$database->updateUserField($post['a_user'], 'alliance', 0, 1);
|
||||
$database->deleteAlliPermissions($post['a_user']);
|
||||
$database->deleteAlliance($session->alliance);
|
||||
// log the notice
|
||||
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid='.$UserData['id'].'">'.($kickedUsername = addslashes($database->getUserField($post['a_user'], "username", 0))).'</a> has been expelled from the alliance by <a href="spieler.php?uid='.$session->uid.'">'.addslashes($session->username).'</a>.');
|
||||
if($session->alliance && $database->isAllianceOwner($UserData['id']) == $session->alliance){
|
||||
$newowner = $database->getAllMember2($session->alliance);
|
||||
$newleader = $newowner['id'];
|
||||
$q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $session->alliance."";
|
||||
$database->query($q);
|
||||
$database->updateAlliPermissions($newleader, 1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
Automation::updateMax($newleader);
|
||||
}
|
||||
$form->addError("perm", $kickedUsername.ALLY_USER_KICKED);
|
||||
}
|
||||
}
|
||||
/*****************************************
|
||||
@@ -519,11 +479,6 @@ class Alliance {
|
||||
*****************************************/
|
||||
public function setForumLink($post) {
|
||||
global $database, $session, $form;
|
||||
if($session->access == BANNED)
|
||||
{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if($this->userPermArray['opt5'] == 0) $form->addError("perm", NO_PERMISSION);
|
||||
else
|
||||
@@ -537,25 +492,21 @@ class Alliance {
|
||||
*****************************************/
|
||||
public function Vote($post) {
|
||||
global $database, $session;
|
||||
if($session->access != BANNED){
|
||||
if($database->checkSurvey($post['tid']) && !$database->checkVote($post['tid'], $session->uid)){
|
||||
$survey = $database->getSurvey($post['tid']);
|
||||
$text = ''.$survey['voted'].','.$session->uid.',';
|
||||
$database->Vote($post['tid'], $post['vote'], $text);
|
||||
}
|
||||
header("Location: allianz.php?s=2&fid2=".$post['fid2']."&tid=".$post['tid']);
|
||||
exit;
|
||||
}else{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
|
||||
if($database->checkSurvey($post['tid']) && !$database->checkVote($post['tid'], $session->uid)){
|
||||
$survey = $database->getSurvey($post['tid']);
|
||||
$text = ''.$survey['voted'].','.$session->uid.',';
|
||||
$database->Vote($post['tid'], $post['vote'], $text);
|
||||
}
|
||||
header("Location: allianz.php?s=2&fid2=".$post['fid2']."&tid=".$post['tid']);
|
||||
exit;
|
||||
}
|
||||
/*****************************************
|
||||
Function to quit from alliance
|
||||
*****************************************/
|
||||
private function quitally($post) {
|
||||
global $database, $session, $form;
|
||||
if($session->access != BANNED){
|
||||
|
||||
if(!isset($post['pw']) || $post['pw'] == "") {
|
||||
$form->addError("pw", PW_EMPTY);
|
||||
} elseif(!password_verify($post['pw'], $session->userinfo['password'])) {
|
||||
@@ -620,18 +571,11 @@ class Alliance {
|
||||
header("Location: spieler.php?uid=".$session->uid);
|
||||
exit;
|
||||
}
|
||||
}else{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function changediplomacy($post) {
|
||||
global $database, $session, $form;
|
||||
if($session->access == BANNED) {
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if($this->userPermArray['opt6'] == 1){
|
||||
if(!empty($post['a_name']) || !empty($post['dipl'])){
|
||||
$aName = $post['a_name'];
|
||||
|
||||
+117
-147
@@ -77,32 +77,27 @@ class Building {
|
||||
public function canProcess($id, $tid) {
|
||||
//add fix by ronix
|
||||
global $session, $database, $village;
|
||||
|
||||
if($session->access == BANNED){
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$levels = $database->getResourceLevel($village->wid);
|
||||
|
||||
// don't allow building WW to level 51 with a waiting loop
|
||||
//Don't allow building WW to level 51 with a waiting loop
|
||||
if (!(($tid != 99 || ($tid == 99 && $this->allowWwUpgrade())))) $this->redirect($tid);
|
||||
|
||||
if (
|
||||
// check that our ID actually exists within the buildings list
|
||||
//Check that our ID actually exists within the buildings list
|
||||
isset($village->resarray['f'.$tid.'t']) &&
|
||||
// let's see if we should allow building what we want where we want to
|
||||
// (prevent building resource fields in the village
|
||||
//Let's see if we should allow building what we want where we want to
|
||||
//(Prevent building resource fields in the village
|
||||
(
|
||||
($tid >= 1 && $tid <= 18 && $id >= 1 && $id <= 4) ||
|
||||
($tid >= 19 && $id > 4)
|
||||
) &&
|
||||
// check that we're not trying to change a standing building type
|
||||
//Check that we're not trying to change a standing building type
|
||||
(
|
||||
$levels['f'.$tid.'t'] == $id ||
|
||||
$levels['f'.$tid.'t'] == 0
|
||||
) &&
|
||||
// check that we're not trying to build in the walls id
|
||||
//Check that we're not trying to build in the walls id
|
||||
(
|
||||
($tid == 40 && in_array($id, [31, 32, 33])) ||
|
||||
$tid != 40
|
||||
@@ -112,15 +107,15 @@ class Building {
|
||||
$this->redirect($tid);
|
||||
}
|
||||
|
||||
// check if the building will be built with the master builder
|
||||
//Check if the building will be built with the master builder
|
||||
if(isset($_GET['master'])){
|
||||
// if so, we have to check if it'll be built or upgraded
|
||||
//If so, we have to check if it'll be built or upgraded
|
||||
if($levels['f'.$tid.'t'] == 0)
|
||||
{
|
||||
// the building will be built, we have to check if we can build it
|
||||
//The building will be built, we have to check if we can build it
|
||||
if(!$this->meetRequirement($id)) $this->redirect($tid);
|
||||
}else{
|
||||
// the building will be upgraded, we have to check if we can upgrade it
|
||||
//The building will be upgraded, we have to check if we can upgrade it
|
||||
if($this->isMax($id, $tid, $this->isLoop($tid) + $this->isCurrent($tid))){
|
||||
$this->redirect($tid);
|
||||
}
|
||||
@@ -146,11 +141,6 @@ class Building {
|
||||
|
||||
public function procBuild($get) {
|
||||
global $session, $village, $database;
|
||||
|
||||
if($session->access == BANNED){
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if(isset($get['a']) && $get['c'] == $session->checker && !isset($get['id'])) {
|
||||
if($get['a'] == 0) $this->removeBuilding($get['d']);
|
||||
@@ -354,11 +344,6 @@ class Building {
|
||||
private function upgradeBuilding($id) {
|
||||
global $database, $village, $session, $logging, ${'bid'.$village->resarray['f'.$id.'t']};
|
||||
|
||||
if($session->access == BANNED){
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if($this->allocated < $this->maxConcurrent) {
|
||||
$uprequire = $this->resourceRequired($id,$village->resarray['f'.$id.'t']);
|
||||
$time = time() + $uprequire['time'];
|
||||
@@ -413,11 +398,6 @@ class Building {
|
||||
private function downgradeBuilding($id) {
|
||||
global $database, $village, $session, $logging;
|
||||
|
||||
if($session->access == BANNED){
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if($this->allocated < $this->maxConcurrent) {
|
||||
$name = "bid".$village->resarray['f'.$id.'t'];
|
||||
global $$name;
|
||||
@@ -455,11 +435,6 @@ class Building {
|
||||
|
||||
private function constructBuilding($id, $tid) {
|
||||
global $database, $village, $session, $logging;
|
||||
|
||||
if($session->access == BANNED) {
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if($this->allocated < $this->maxConcurrent) {
|
||||
if($tid == 16) $id = 39;
|
||||
@@ -706,128 +681,123 @@ class Building {
|
||||
public function finishAll($redirect_url = '') {
|
||||
global $database, $session, $logging, $village, $bid18, $bid10, $bid11, $technology, $_SESSION;
|
||||
|
||||
if ($session->access != BANNED) {
|
||||
// will be true if we should decrease player's gold by 2
|
||||
// for the immediate completion action
|
||||
$countPlus2Gold = false;
|
||||
// will be true if we should decrease player's gold by 1
|
||||
// for master builder queue
|
||||
$countMasterGold = false;
|
||||
// number of jobs to finish
|
||||
$buildcount = ($this->buildArray ? count($this->buildArray) : 0);
|
||||
// will be true if the job was successfully finished
|
||||
$jobFinishSuccess = false;
|
||||
// IDs of successful jobs to delete
|
||||
$deletIDs = [];
|
||||
|
||||
foreach ($this->buildArray as $jobs) {
|
||||
if ($jobs['wid'] == $village->wid) {
|
||||
$wwvillage = $database->getResourceLevel($jobs['wid']);
|
||||
if ($wwvillage['f99t'] != 40) {
|
||||
$level = $jobs['level'];
|
||||
if ($jobs['type'] != 25 && $jobs['type'] != 26 && $jobs['type'] != 40) {
|
||||
$resource = $this->resourceRequired($jobs['field'],$jobs['type']);
|
||||
// master builder involved
|
||||
if ($jobs['master'] != 0) {
|
||||
if ($this->meetRequirement($jobs['field'])) {
|
||||
// don't allow master builder to build anything
|
||||
// if we only have 2 gold, since that would take us to -1 gold
|
||||
if ( $session->gold > 2 ) {
|
||||
$villwood = $database->getVillageField( $jobs['wid'], 'wood' );
|
||||
$villclay = $database->getVillageField( $jobs['wid'], 'clay' );
|
||||
$villiron = $database->getVillageField( $jobs['wid'], 'iron' );
|
||||
$villcrop = $database->getVillageField( $jobs['wid'], 'crop' );
|
||||
$type = $jobs['type'];
|
||||
$buildarray = $GLOBALS[ "bid" . $type ];
|
||||
$buildwood = $buildarray[ $level ]['wood'];
|
||||
$buildclay = $buildarray[ $level ]['clay'];
|
||||
$buildiron = $buildarray[ $level ]['iron'];
|
||||
$buildcrop = $buildarray[ $level ]['crop'];
|
||||
if ( $buildwood < $villwood && $buildclay < $villclay && $buildiron < $villiron && $buildcrop < $villcrop ) {
|
||||
$jobFinishSuccess = true;
|
||||
$countMasterGold = true;
|
||||
$enought_res = 1;
|
||||
// we need to subtract resources for this, if another 2 jobs are active,
|
||||
// as we'd never subtract those otherwise
|
||||
if ( $buildcount > 2 ) {
|
||||
$database->setVillageField( $jobs['wid'],
|
||||
['wood', 'clay', 'iron', 'crop'],
|
||||
[( $villwood - $buildwood ), ( $villclay - $buildclay ), ( $villiron - $buildiron ), ( $villcrop - $buildcrop )]);
|
||||
}
|
||||
// will be true if we should decrease player's gold by 2
|
||||
// for the immediate completion action
|
||||
$countPlus2Gold = false;
|
||||
// will be true if we should decrease player's gold by 1
|
||||
// for master builder queue
|
||||
$countMasterGold = false;
|
||||
// number of jobs to finish
|
||||
$buildcount = ($this->buildArray ? count($this->buildArray) : 0);
|
||||
// will be true if the job was successfully finished
|
||||
$jobFinishSuccess = false;
|
||||
// IDs of successful jobs to delete
|
||||
$deletIDs = [];
|
||||
|
||||
foreach ($this->buildArray as $jobs) {
|
||||
if ($jobs['wid'] == $village->wid) {
|
||||
$wwvillage = $database->getResourceLevel($jobs['wid']);
|
||||
if ($wwvillage['f99t'] != 40) {
|
||||
$level = $jobs['level'];
|
||||
if ($jobs['type'] != 25 && $jobs['type'] != 26 && $jobs['type'] != 40) {
|
||||
$resource = $this->resourceRequired($jobs['field'],$jobs['type']);
|
||||
// master builder involved
|
||||
if ($jobs['master'] != 0) {
|
||||
if ($this->meetRequirement($jobs['field'])) {
|
||||
// don't allow master builder to build anything
|
||||
// if we only have 2 gold, since that would take us to -1 gold
|
||||
if ( $session->gold > 2 ) {
|
||||
$villwood = $database->getVillageField( $jobs['wid'], 'wood' );
|
||||
$villclay = $database->getVillageField( $jobs['wid'], 'clay' );
|
||||
$villiron = $database->getVillageField( $jobs['wid'], 'iron' );
|
||||
$villcrop = $database->getVillageField( $jobs['wid'], 'crop' );
|
||||
$type = $jobs['type'];
|
||||
$buildarray = $GLOBALS[ "bid" . $type ];
|
||||
$buildwood = $buildarray[ $level ]['wood'];
|
||||
$buildclay = $buildarray[ $level ]['clay'];
|
||||
$buildiron = $buildarray[ $level ]['iron'];
|
||||
$buildcrop = $buildarray[ $level ]['crop'];
|
||||
if ( $buildwood < $villwood && $buildclay < $villclay && $buildiron < $villiron && $buildcrop < $villcrop ) {
|
||||
$jobFinishSuccess = true;
|
||||
$countMasterGold = true;
|
||||
$enought_res = 1;
|
||||
// we need to subtract resources for this, if another 2 jobs are active,
|
||||
// as we'd never subtract those otherwise
|
||||
if ( $buildcount > 2 ) {
|
||||
$database->setVillageField( $jobs['wid'],
|
||||
['wood', 'clay', 'iron', 'crop'],
|
||||
[( $villwood - $buildwood ), ( $villclay - $buildclay ), ( $villiron - $buildiron ), ( $villcrop - $buildcrop )]);
|
||||
}
|
||||
} else {
|
||||
// if we only have 2 gold, we need to cancel this job, as there will never
|
||||
// be enough gold now in our account to finish this up
|
||||
$exclude_master = true;
|
||||
$deletIDs[] = (int) $jobs['id'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// non-master builder build, we should count +2 gold for it
|
||||
$countPlus2Gold = true;
|
||||
$jobFinishSuccess = true;
|
||||
}
|
||||
|
||||
// update build level in the database
|
||||
if ($jobFinishSuccess) {
|
||||
$q = "UPDATE ".TB_PREFIX."fdata set f".$jobs['field']." = ".$jobs['level'].", f".$jobs['field']."t = ".$jobs['type']." where vref = ".$jobs['wid'];
|
||||
}
|
||||
|
||||
if (!isset($exclude_master) && $database->query($q) && ($enought_res == 1 || $jobs['master'] == 0)) {
|
||||
$database->modifyPop($jobs['wid'],$resource['pop'],0);
|
||||
$database->addCP($jobs['wid'],$resource['cp']);
|
||||
$deletIDs[] = (int) $jobs['id'];
|
||||
if($jobs['type'] == 18) {
|
||||
$owner = $database->getVillageField($jobs['wid'],"owner");
|
||||
$max = $bid18[$level]['attri'];
|
||||
$q = "UPDATE ".TB_PREFIX."alidata set max = $max where leader = $owner";
|
||||
$database->query($q);
|
||||
} else {
|
||||
// if we only have 2 gold, we need to cancel this job, as there will never
|
||||
// be enough gold now in our account to finish this up
|
||||
$exclude_master = true;
|
||||
$deletIDs[] = (int) $jobs['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (($jobs['field'] >= 19 && ($session->tribe == 1 || ALLOW_ALL_TRIBE)) || (!ALLOW_ALL_TRIBE && $session->tribe != 1)) {
|
||||
$innertimestamp = $jobs['timestamp'];
|
||||
} else {
|
||||
// non-master builder build, we should count +2 gold for it
|
||||
$countPlus2Gold = true;
|
||||
$jobFinishSuccess = true;
|
||||
}
|
||||
|
||||
// update build level in the database
|
||||
if ($jobFinishSuccess) {
|
||||
$q = "UPDATE ".TB_PREFIX."fdata set f".$jobs['field']." = ".$jobs['level'].", f".$jobs['field']."t = ".$jobs['type']." where vref = ".$jobs['wid'];
|
||||
}
|
||||
|
||||
if (!isset($exclude_master) && $database->query($q) && ($enought_res == 1 || $jobs['master'] == 0)) {
|
||||
$database->modifyPop($jobs['wid'],$resource['pop'],0);
|
||||
$database->addCP($jobs['wid'],$resource['cp']);
|
||||
$deletIDs[] = (int) $jobs['id'];
|
||||
if($jobs['type'] == 18) {
|
||||
$owner = $database->getVillageField($jobs['wid'],"owner");
|
||||
$max = $bid18[$level]['attri'];
|
||||
$q = "UPDATE ".TB_PREFIX."alidata set max = $max where leader = $owner";
|
||||
$database->query($q);
|
||||
}
|
||||
}
|
||||
|
||||
if (($jobs['field'] >= 19 && ($session->tribe == 1 || ALLOW_ALL_TRIBE)) || (!ALLOW_ALL_TRIBE && $session->tribe != 1)) {
|
||||
$innertimestamp = $jobs['timestamp'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reset the flag for the next job
|
||||
$jobFinishSuccess = false;
|
||||
}
|
||||
|
||||
if (count($deletIDs)) {
|
||||
$database->query("DELETE FROM " . TB_PREFIX . "bdata WHERE id IN(" . implode(', ', $deletIDs) . ")");
|
||||
}
|
||||
|
||||
$demolition = $database->finishDemolition($village->wid);
|
||||
$tech = $technology->finishTech();
|
||||
if ($demolition > 0 || $tech > 0) {
|
||||
$countPlus2Gold = true;
|
||||
$logging->goldFinLog($village->wid);
|
||||
}
|
||||
|
||||
// deduct the right amount of gold
|
||||
if ($countMasterGold || $countPlus2Gold) {
|
||||
$newgold = $session->gold - (($countMasterGold && $countPlus2Gold) ? 3 : 2);
|
||||
$database->updateUserField($session->uid, "gold", $newgold, 1);
|
||||
}
|
||||
|
||||
$stillbuildingarray = $database->getJobs($village->wid);
|
||||
if (count($stillbuildingarray) == 1) {
|
||||
if($stillbuildingarray[0]['loopcon'] == 1) {
|
||||
//$q = "UPDATE ".TB_PREFIX."bdata SET loopcon=0,timestamp=".(time()+$stillbuildingarray[0]['timestamp']-$innertimestamp)." WHERE id=".$stillbuildingarray[0]['id'];
|
||||
$q = "UPDATE ".TB_PREFIX."bdata SET loopcon=0 WHERE id=".(int) $stillbuildingarray[0]['id'];
|
||||
$database->query($q);
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: ".($redirect_url ? $redirect_url : $session->referrer));
|
||||
exit;
|
||||
} else {
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
|
||||
// reset the flag for the next job
|
||||
$jobFinishSuccess = false;
|
||||
}
|
||||
|
||||
if (count($deletIDs)) {
|
||||
$database->query("DELETE FROM " . TB_PREFIX . "bdata WHERE id IN(" . implode(', ', $deletIDs) . ")");
|
||||
}
|
||||
|
||||
$demolition = $database->finishDemolition($village->wid);
|
||||
$tech = $technology->finishTech();
|
||||
if ($demolition > 0 || $tech > 0) {
|
||||
$countPlus2Gold = true;
|
||||
$logging->goldFinLog($village->wid);
|
||||
}
|
||||
|
||||
// deduct the right amount of gold
|
||||
if ($countMasterGold || $countPlus2Gold) {
|
||||
$newgold = $session->gold - (($countMasterGold && $countPlus2Gold) ? 3 : 2);
|
||||
$database->updateUserField($session->uid, "gold", $newgold, 1);
|
||||
}
|
||||
|
||||
$stillbuildingarray = $database->getJobs($village->wid);
|
||||
if (count($stillbuildingarray) == 1) {
|
||||
if($stillbuildingarray[0]['loopcon'] == 1) {
|
||||
//$q = "UPDATE ".TB_PREFIX."bdata SET loopcon=0,timestamp=".(time()+$stillbuildingarray[0]['timestamp']-$innertimestamp)." WHERE id=".$stillbuildingarray[0]['id'];
|
||||
$q = "UPDATE ".TB_PREFIX."bdata SET loopcon=0 WHERE id=".(int) $stillbuildingarray[0]['id'];
|
||||
$database->query($q);
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: ".($redirect_url ? $redirect_url : $session->referrer));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function resourceRequired($id, $tid, $plus = 1) {
|
||||
|
||||
+11
-32
@@ -94,6 +94,7 @@ class Market
|
||||
$ctrans = str_replace("-", "", $ctrans);
|
||||
$itrans = str_replace("-", "", $itrans);
|
||||
$crtrans = str_replace("-", "", $crtrans);
|
||||
|
||||
// preload all village data, since we're retrieving some of those separately below
|
||||
$database->getVillage($village->wid);
|
||||
|
||||
@@ -101,15 +102,11 @@ class Market
|
||||
$availableClay = $database->getClayAvailable($village->wid);
|
||||
$availableIron = $database->getIronAvailable($village->wid);
|
||||
$availableCrop = $database->getCropAvailable($village->wid);
|
||||
//check if vacation mode:
|
||||
|
||||
//check if on vacation:
|
||||
if($database->getvacmodexy($id)) $form->addError("error", USER_ON_VACATION);
|
||||
|
||||
if($session->access == BANNED)
|
||||
{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
elseif(!$database->checkVilExist($post['getwref'])) $form->addError("error", NO_COORDINATES_SELECTED);
|
||||
if(!$database->checkVilExist($post['getwref'])) $form->addError("error", NO_COORDINATES_SELECTED);
|
||||
elseif($post['getwref'] == $village->wid) $form->addError("error", CANNOT_SEND_RESOURCES);
|
||||
elseif($post['send3'] < 1 || $post['send3'] > 3 || ($post['send3'] > 1 && !$session->goldclub)) $form->addError("error", INVALID_MERCHANTS_REPETITION);
|
||||
elseif($availableWood >= $post['r1'] && $availableClay >= $post['r2'] && $availableIron >= $post['r3'] && $availableCrop >= $post['r4'])
|
||||
@@ -190,13 +187,7 @@ class Market
|
||||
$availableIron = $database->getIronAvailable($village->wid);
|
||||
$availableCrop = $database->getCropAvailable($village->wid);
|
||||
|
||||
if($session->access == BANNED)
|
||||
{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
elseif($availableWood >= $wood && $availableClay >= $clay && $availableIron >= $iron && $availableCrop >= $crop)
|
||||
if($availableWood >= $wood && $availableClay >= $clay && $availableIron >= $iron && $availableCrop >= $crop)
|
||||
{
|
||||
$reqMerc = 1;
|
||||
|
||||
@@ -355,18 +346,10 @@ class Market
|
||||
global $session,$database,$village;
|
||||
|
||||
$wwvillage = $database->getResourceLevel($village->wid);
|
||||
if($wwvillage['f99t'] != 40)
|
||||
{
|
||||
if($session->userinfo['gold'] >= 3)
|
||||
{
|
||||
//check if there are too many resources
|
||||
if($session->access == BANNED)
|
||||
{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
else if (($post['m2'][0]+$post['m2'][1]+$post['m2'][2]+$post['m2'][3])<=(round($village->awood)+round($village->aclay)+round($village->airon)+round($village->acrop)))
|
||||
{
|
||||
if($wwvillage['f99t'] != 40){
|
||||
if($session->userinfo['gold'] >= 3){
|
||||
//Check if there are too many resources
|
||||
if(($post['m2'][0]+$post['m2'][1]+$post['m2'][2]+$post['m2'][3])<=(round($village->awood)+round($village->aclay)+round($village->airon)+round($village->acrop))){
|
||||
$database->setVillageField(
|
||||
$village->wid,
|
||||
["wood", "clay", "iron", "crop"],
|
||||
@@ -375,15 +358,11 @@ class Market
|
||||
$database->modifyGold($session->uid, 3, 0);
|
||||
header("Location: build.php?id=".$post['id']."&t=3&c");;
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
}else{
|
||||
header("Location: build.php?id=".$post['id']."&t=3");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}else{
|
||||
header("Location: build.php?id=".$post['id']."&t=3");
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -11,15 +11,9 @@
|
||||
|
||||
|
||||
class Profile {
|
||||
|
||||
public function procProfile($post) {
|
||||
global $session;
|
||||
|
||||
if($session->access == BANNED){
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if(isset($post['ft'])) {
|
||||
switch($post['ft']) {
|
||||
case "p1" :
|
||||
@@ -40,11 +34,6 @@ class Profile {
|
||||
public function procSpecial($get) {
|
||||
global $session;
|
||||
|
||||
if($session->access == BANNED){
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if(isset($get['e'])) {
|
||||
switch($get['e']) {
|
||||
case 2 :
|
||||
|
||||
+17
-1
@@ -172,7 +172,7 @@ class Session {
|
||||
$admin = true;
|
||||
}
|
||||
|
||||
if($user && ($admin || isset($_SESSION['sessid']))) {
|
||||
if($user && ($admin || isset($_SESSION['sessid']))) {
|
||||
$this->maintenance();
|
||||
$this->isWinner();
|
||||
|
||||
@@ -187,6 +187,10 @@ class Session {
|
||||
|
||||
//Get and Populate Data
|
||||
$this->PopulateVar();
|
||||
|
||||
//Check if the player is banned
|
||||
$this->isBanned();
|
||||
|
||||
//update database
|
||||
$database->updateActiveUser($user, $this->time);
|
||||
return true;
|
||||
@@ -194,6 +198,18 @@ class Session {
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called if the player is banned
|
||||
*
|
||||
*/
|
||||
|
||||
function isBanned(){
|
||||
if($this->access == BANNED && !in_array(basename($_SERVER['PHP_SELF']), ['banned.php', 'nachrichten.php', 'rules.php'])){
|
||||
header('Location: banned.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server is under maintenance
|
||||
*
|
||||
|
||||
+36
-40
@@ -370,46 +370,42 @@ class Technology {
|
||||
|
||||
private function procTrain($post, $great = false) {
|
||||
global $session;
|
||||
if($session->access != BANNED){
|
||||
// first of all, check if we're not trying to train chieftain
|
||||
// and settlers together - which we cannot, since that can result
|
||||
// in 1 chieftain and 3 settlers, then conquering a village, then
|
||||
// founding a new one, all with only 1 available slot
|
||||
if (
|
||||
!(
|
||||
(!empty($post['t9']) && !empty($post['t10'])) ||
|
||||
(!empty($post['t19']) && !empty($post['t20'])) ||
|
||||
(!empty($post['t29']) && !empty($post['t30'])) ||
|
||||
(!empty($post['t39']) && !empty($post['t40'])) ||
|
||||
(!empty($post['t49']) && !empty($post['t50']))
|
||||
)
|
||||
) {
|
||||
$start = ($session->tribe - 1) * 10 + 1;
|
||||
$end = ($session->tribe * 10);
|
||||
for ($i = $start; $i <= $end; $i ++ ) {
|
||||
if (isset($post['t'.$i]) && $post['t'.$i] != 0) {
|
||||
$amt = intval($post['t'.$i]);
|
||||
if ($amt < 0) $amt = 1;
|
||||
$this->trainUnit($i, $amt, $great);
|
||||
}
|
||||
}
|
||||
|
||||
if($session->tribe == 3)
|
||||
{
|
||||
if (isset($post['t99']) && $post['t99'] != 0) {
|
||||
$amt = intval($post['t99']);
|
||||
if ($amt < 0) $amt = 1;
|
||||
$this->trainUnit(99, $amt, $great);
|
||||
}
|
||||
}
|
||||
|
||||
header( "Location: build.php?id=" . $post['id'] );
|
||||
exit;
|
||||
}
|
||||
}else{
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// first of all, check if we're not trying to train chieftain
|
||||
// and settlers together - which we cannot, since that can result
|
||||
// in 1 chieftain and 3 settlers, then conquering a village, then
|
||||
// founding a new one, all with only 1 available slot
|
||||
if (
|
||||
!(
|
||||
(!empty($post['t9']) && !empty($post['t10'])) ||
|
||||
(!empty($post['t19']) && !empty($post['t20'])) ||
|
||||
(!empty($post['t29']) && !empty($post['t30'])) ||
|
||||
(!empty($post['t39']) && !empty($post['t40'])) ||
|
||||
(!empty($post['t49']) && !empty($post['t50']))
|
||||
)
|
||||
) {
|
||||
$start = ($session->tribe - 1) * 10 + 1;
|
||||
$end = ($session->tribe * 10);
|
||||
for ($i = $start; $i <= $end; $i ++ ) {
|
||||
if (isset($post['t'.$i]) && $post['t'.$i] != 0) {
|
||||
$amt = intval($post['t'.$i]);
|
||||
if ($amt < 0) $amt = 1;
|
||||
$this->trainUnit($i, $amt, $great);
|
||||
}
|
||||
}
|
||||
|
||||
if($session->tribe == 3)
|
||||
{
|
||||
if (isset($post['t99']) && $post['t99'] != 0) {
|
||||
$amt = intval($post['t99']);
|
||||
if ($amt < 0) $amt = 1;
|
||||
$this->trainUnit(99, $amt, $great);
|
||||
}
|
||||
}
|
||||
|
||||
header( "Location: build.php?id=" . $post['id'] );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function getUpkeep($array, $type, $vid = 0, $prisoners = 0) {
|
||||
|
||||
+221
-235
@@ -253,278 +253,264 @@ class 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['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) {
|
||||
if($form->returnErrors() > 0){
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
header( "Location: a2b.php" );
|
||||
exit;
|
||||
} else {
|
||||
if ($session->access != BANNED) {
|
||||
$u = ($session->tribe == 1) ? "" : $session->tribe - 1;
|
||||
|
||||
$database->modifyUnit(
|
||||
$village->wid,
|
||||
[
|
||||
$u . "1",
|
||||
$u . "2",
|
||||
$u . "3",
|
||||
$u . "4",
|
||||
$u . "5",
|
||||
$u . "6",
|
||||
$u . "7",
|
||||
$u . "8",
|
||||
$u . "9",
|
||||
$u . $session->tribe . "0",
|
||||
"hero"
|
||||
],
|
||||
[
|
||||
$data['u1'],
|
||||
$data['u2'],
|
||||
$data['u3'],
|
||||
$data['u4'],
|
||||
$data['u5'],
|
||||
$data['u6'],
|
||||
$data['u7'],
|
||||
$data['u8'],
|
||||
$data['u9'],
|
||||
$data['u10'],
|
||||
$data['u11']
|
||||
],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
}else{
|
||||
$u = ($session->tribe == 1) ? "" : $session->tribe - 1;
|
||||
|
||||
$database->modifyUnit(
|
||||
$village->wid,
|
||||
[
|
||||
$u . "1",
|
||||
$u . "2",
|
||||
$u . "3",
|
||||
$u . "4",
|
||||
$u . "5",
|
||||
$u . "6",
|
||||
$u . "7",
|
||||
$u . "8",
|
||||
$u . "9",
|
||||
$u . $session->tribe . "0",
|
||||
"hero"
|
||||
],
|
||||
[
|
||||
$data['u1'],
|
||||
$data['u2'],
|
||||
$data['u3'],
|
||||
$data['u4'],
|
||||
$data['u5'],
|
||||
$data['u6'],
|
||||
$data['u7'],
|
||||
$data['u8'],
|
||||
$data['u9'],
|
||||
$data['u10'],
|
||||
$data['u11']
|
||||
],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
);
|
||||
|
||||
$troopsTime = $this->getWalkingTroopsTime($village->wid, $data['to_vid'], $session->uid, $session->tribe, $data, 1, 'u');
|
||||
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
|
||||
|
||||
// Check if have WW owner have artefact Rivals great confusion or Artefact of the unique fool with that effect
|
||||
// If is a WW village you can target on WW , if is not a WW village catapults will target randomly.
|
||||
// Like it says : Exceptions are the WW which can always be targeted and the treasure chamber which can always be targeted, except with the unique artifact.
|
||||
// Fixed by Advocaite and Shadow - Optimized by iopietro
|
||||
|
||||
$to_owner = $database->getVillageField($data['to_vid'], "owner");
|
||||
$rivalsGreatConfusion = $database->getArtifactsSumByKind($to_owner, $data['to_vid'], 7);
|
||||
|
||||
$rallyPointLevel = ($village->resarray)['f39'];
|
||||
$invalidBuildings = [];
|
||||
|
||||
// fill the array with the invalid buildings
|
||||
if($rallyPointLevel >= 3 && $rallyPointLevel < 5){
|
||||
for($i = 1; $i <= 37; $i++){
|
||||
if(!in_array($i, [10, 11])) $invalidBuildings[] = $i;
|
||||
}
|
||||
|
||||
$troopsTime = $this->getWalkingTroopsTime($village->wid, $data['to_vid'], $session->uid, $session->tribe, $data, 1, 'u');
|
||||
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
|
||||
|
||||
// Check if have WW owner have artefact Rivals great confusion or Artefact of the unique fool with that effect
|
||||
// If is a WW village you can target on WW , if is not a WW village catapults will target randomly.
|
||||
// Like it says : Exceptions are the WW which can always be targeted and the treasure chamber which can always be targeted, except with the unique artifact.
|
||||
// Fixed by Advocaite and Shadow - Optimized by iopietro
|
||||
|
||||
$to_owner = $database->getVillageField($data['to_vid'], "owner");
|
||||
$rivalsGreatConfusion = $database->getArtifactsSumByKind($to_owner, $data['to_vid'], 7);
|
||||
|
||||
$rallyPointLevel = ($village->resarray)['f39'];
|
||||
$invalidBuildings = [];
|
||||
|
||||
// fill the array with the invalid buildings
|
||||
if($rallyPointLevel >= 3 && $rallyPointLevel < 5){
|
||||
for($i = 1; $i <= 37; $i++){
|
||||
if(!in_array($i, [10, 11])) $invalidBuildings[] = $i;
|
||||
}
|
||||
else if($rallyPointLevel >= 5 && $rallyPointLevel < 10){
|
||||
for($i = 12; $i <= 37; $i++) $invalidBuildings[] = $i;
|
||||
}
|
||||
else if($rallyPointLevel >= 5 && $rallyPointLevel < 10){
|
||||
for($i = 12; $i <= 37; $i++) $invalidBuildings[] = $i;
|
||||
}
|
||||
else if($rallyPointLevel >= 10){
|
||||
$invalidBuildings = [23, 31, 32, 33, 34, 36];
|
||||
}
|
||||
|
||||
if(isset($post['ctar1']) && $post['ctar1'] != 0){
|
||||
// check if the player has selected a valid building
|
||||
if($rallyPointLevel < 3 || $data['u8'] == 0 || in_array($post['ctar1'], $invalidBuildings) || $post['ctar1'] < 0 || $post['ctar1'] > 40){
|
||||
$post['ctar1'] = 0;
|
||||
}
|
||||
else if($rallyPointLevel >= 10){
|
||||
$invalidBuildings = [23, 31, 32, 33, 34, 36];
|
||||
}
|
||||
|
||||
if(isset($post['ctar1']) && $post['ctar1'] != 0){
|
||||
}
|
||||
|
||||
if(isset($post['ctar2']) && $post['ctar2'] != 0){
|
||||
// check if there are atleast 20 catapults
|
||||
if($data['u8'] < 20 || $rallyPointLevel != 20){
|
||||
$post['ctar2'] = 0;
|
||||
}else{
|
||||
// check if the player has selected a valid building
|
||||
if($rallyPointLevel < 3 || $data['u8'] == 0 || in_array($post['ctar1'], $invalidBuildings) || $post['ctar1'] < 0 || $post['ctar1'] > 40){
|
||||
$post['ctar1'] = 0;
|
||||
if(in_array($post['ctar2'], $invalidBuildings) || ($post['ctar2'] < 0 || $post['ctar2'] > 40 && $post['ctar2'] != 99)){
|
||||
$post['ctar2'] = 99;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($post['ctar2']) && $post['ctar2'] != 0){
|
||||
// check if there are atleast 20 catapults
|
||||
if($data['u8'] < 20 || $rallyPointLevel != 20){
|
||||
$post['ctar2'] = 0;
|
||||
}else{
|
||||
// check if the player has selected a valid building
|
||||
if(in_array($post['ctar2'], $invalidBuildings) || ($post['ctar2'] < 0 || $post['ctar2'] > 40 && $post['ctar2'] != 99)){
|
||||
}
|
||||
|
||||
if(isset($post['ctar1'])) {
|
||||
//Is the Brewery built?
|
||||
if($session->tribe != 2 || $database->getFieldLevelInVillage($village->wid, 35) == 0){
|
||||
if($rivalsGreatConfusion['totals'] > 0) {
|
||||
if($post['ctar1'] != 40 && ($post['ctar1'] != 27 || ($post['ctar1'] == 27 && $rivalsGreatConfusion['unique'] > 0))) {
|
||||
$post['ctar1'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else $post['ctar1'] = 0;
|
||||
}
|
||||
else $post['ctar1'] = 0;
|
||||
|
||||
if(isset($post['ctar2']) && $post['ctar2'] > 0) {
|
||||
//Is the Brewery built?
|
||||
if($session->tribe != 2 || $database->getFieldLevelInVillage($village->wid, 35) == 0){
|
||||
if($rivalsGreatConfusion['totals'] > 0) {
|
||||
if ($post['ctar2'] != 40 && ($post['ctar2'] != 27 || ($post['ctar2'] == 27 && $rivalsGreatConfusion['unique'] > 0))) {
|
||||
$post['ctar2'] = 99;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($post['ctar1'])) {
|
||||
//Is the Brewery built?
|
||||
if($session->tribe != 2 || $database->getFieldLevelInVillage($village->wid, 35) == 0){
|
||||
if($rivalsGreatConfusion['totals'] > 0) {
|
||||
if($post['ctar1'] != 40 && ($post['ctar1'] != 27 || ($post['ctar1'] == 27 && $rivalsGreatConfusion['unique'] > 0))) {
|
||||
$post['ctar1'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else $post['ctar1'] = 0;
|
||||
}
|
||||
else $post['ctar1'] = 0;
|
||||
|
||||
if(isset($post['ctar2']) && $post['ctar2'] > 0) {
|
||||
//Is the Brewery built?
|
||||
if($session->tribe != 2 || $database->getFieldLevelInVillage($village->wid, 35) == 0){
|
||||
if($rivalsGreatConfusion['totals'] > 0) {
|
||||
if ($post['ctar2'] != 40 && ($post['ctar2'] != 27 || ($post['ctar2'] == 27 && $rivalsGreatConfusion['unique'] > 0))) {
|
||||
$post['ctar2'] = 99;
|
||||
}
|
||||
}
|
||||
}
|
||||
else $post['ctar2'] = 99;
|
||||
else $post['ctar2'] = 99;
|
||||
}
|
||||
else $post['ctar2'] = 0;
|
||||
|
||||
if(!isset($post['spy'])) $post['spy'] = 0;
|
||||
|
||||
$abdata = $database->getABTech($village->wid);
|
||||
$reference = $database->addAttack(($village->wid), $data['u1'], $data['u2'], $data['u3'], $data['u4'], $data['u5'], $data['u6'], $data['u7'], $data['u8'], $data['u9'], $data['u10'], $data['u11'], $data['type'], $post['ctar1'], $post['ctar2'], $post['spy'], $abdata['b1'], $abdata['b2'], $abdata['b3'], $abdata['b4'], $abdata['b5'], $abdata['b6'], $abdata['b7'], $abdata['b8']);
|
||||
$checkexist = $database->checkVilExist($data['to_vid']);
|
||||
$checkoexist = $database->checkOasisExist($data['to_vid']);
|
||||
if($checkexist || $checkoexist) {
|
||||
$database->addMovement(3, $village->wid, $data['to_vid'], $reference, time(), ($time + time()));
|
||||
if ($database->hasBeginnerProtection($village->wid) == 1 && $checkexist) {
|
||||
mysqli_query($database->dblink, "UPDATE " . TB_PREFIX . "users SET protect = 0 WHERE id = ".(int) $session->uid);
|
||||
}
|
||||
else $post['ctar2'] = 0;
|
||||
|
||||
if(!isset($post['spy'])) $post['spy'] = 0;
|
||||
|
||||
$abdata = $database->getABTech($village->wid);
|
||||
$reference = $database->addAttack(($village->wid), $data['u1'], $data['u2'], $data['u3'], $data['u4'], $data['u5'], $data['u6'], $data['u7'], $data['u8'], $data['u9'], $data['u10'], $data['u11'], $data['type'], $post['ctar1'], $post['ctar2'], $post['spy'], $abdata['b1'], $abdata['b2'], $abdata['b3'], $abdata['b4'], $abdata['b5'], $abdata['b6'], $abdata['b7'], $abdata['b8']);
|
||||
$checkexist = $database->checkVilExist($data['to_vid']);
|
||||
$checkoexist = $database->checkOasisExist($data['to_vid']);
|
||||
if($checkexist || $checkoexist) {
|
||||
$database->addMovement(3, $village->wid, $data['to_vid'], $reference, time(), ($time + time()));
|
||||
if ($database->hasBeginnerProtection($village->wid) == 1 && $checkexist) {
|
||||
mysqli_query($database->dblink, "UPDATE " . TB_PREFIX . "users SET protect = 0 WHERE id = ".(int) $session->uid);
|
||||
}
|
||||
}
|
||||
|
||||
if($form->returnErrors() > 0) {
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
header("Location: a2b.php" );
|
||||
exit;
|
||||
}
|
||||
|
||||
// prevent re-use of the same attack via re-POSTing the same data
|
||||
$database->remA2b($data['id']);
|
||||
|
||||
header("Location: build.php?id=39");
|
||||
exit;
|
||||
} else {
|
||||
header("Location: banned.php");
|
||||
}
|
||||
|
||||
if($form->returnErrors() > 0) {
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
header("Location: a2b.php" );
|
||||
exit;
|
||||
}
|
||||
|
||||
// prevent re-use of the same attack via re-POSTing the same data
|
||||
$database->remA2b($data['id']);
|
||||
|
||||
header("Location: build.php?id=39");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
private function sendTroopsBack($post) {
|
||||
global $form, $database, $village, $session, $technology;
|
||||
if ( $session->access != BANNED ) {
|
||||
$enforce = $database->getEnforceArray( $post['ckey'], 0 );
|
||||
$enforceoasis = $database->getOasisEnforceArray( $post['ckey'], 0 );
|
||||
if ( ( $enforce['from'] == $village->wid ) || ( $enforce['vref'] == $village->wid ) || ( $enforceoasis['conqured'] == $village->wid ) ) {
|
||||
$to = $database->getVillage( $enforce['from'] );
|
||||
$Gtribe = ($ownerTribe = $database->getUserField( $to['owner'], 'tribe', 0)) == 1 ? "" : $ownerTribe - 1;
|
||||
|
||||
for ( $i = 1; $i < 10; $i ++ ) {
|
||||
if ( isset( $post[ 't' . $i ] ) ) {
|
||||
if ( $i != 10 ) {
|
||||
if ( $post[ 't' . $i ] > $enforce[ 'u' . $Gtribe . $i ] ) {
|
||||
$form->addError( "error", "You can't send back more units than you have" );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $post[ 't' . $i ] < 0 ) {
|
||||
$form->addError( "error", "You can't send back negative units." );
|
||||
break;
|
||||
}
|
||||
$enforce = $database->getEnforceArray( $post['ckey'], 0 );
|
||||
$enforceoasis = $database->getOasisEnforceArray( $post['ckey'], 0 );
|
||||
if ( ( $enforce['from'] == $village->wid ) || ( $enforce['vref'] == $village->wid ) || ( $enforceoasis['conqured'] == $village->wid ) ) {
|
||||
$to = $database->getVillage( $enforce['from'] );
|
||||
$Gtribe = ($ownerTribe = $database->getUserField( $to['owner'], 'tribe', 0)) == 1 ? "" : $ownerTribe - 1;
|
||||
|
||||
for ( $i = 1; $i < 10; $i ++ ) {
|
||||
if ( isset( $post[ 't' . $i ] ) ) {
|
||||
if ( $i != 10 ) {
|
||||
if ( $post[ 't' . $i ] > $enforce[ 'u' . $Gtribe . $i ] ) {
|
||||
$form->addError( "error", "You can't send back more units than you have" );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $post[ 't' . $i ] < 0 ) {
|
||||
$form->addError( "error", "You can't send back negative units." );
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$post[ 't' . $i . '' ] = '0';
|
||||
}
|
||||
}
|
||||
if ( isset( $post['t11'] ) ) {
|
||||
if ( $post['t11'] > $enforce['hero'] ) {
|
||||
$form->addError( "error", "You can't send back more units than you have" );
|
||||
}
|
||||
|
||||
if ( $post['t11'] < 0 ) {
|
||||
$form->addError( "error", "You can't send back negative units." );
|
||||
}
|
||||
} else {
|
||||
$post['t11'] = '0';
|
||||
$post[ 't' . $i . '' ] = '0';
|
||||
}
|
||||
|
||||
if ( $form->returnErrors() > 0 ) {
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
header( "Location: a2b.php" );
|
||||
exit;
|
||||
} else {
|
||||
|
||||
//change units
|
||||
$tribe = $database->getUserField($to['owner'], 'tribe', 0);
|
||||
$start = ($tribe - 1 ) * 10 + 1;
|
||||
$end = $tribe * 10 ;
|
||||
|
||||
$units = [];
|
||||
$amounts = [];
|
||||
$modes = [];
|
||||
|
||||
$j = 1;
|
||||
for ( $i = $start; $i <= $end; $i ++ ) {
|
||||
$units[] = $i;
|
||||
$amounts[] = $post[ 't' . $j . '' ];
|
||||
$modes[] = 0;
|
||||
$j ++;
|
||||
}
|
||||
|
||||
$units[] = 'hero';
|
||||
$amounts[] = $post['t11'];
|
||||
}
|
||||
if ( isset( $post['t11'] ) ) {
|
||||
if ( $post['t11'] > $enforce['hero'] ) {
|
||||
$form->addError( "error", "You can't send back more units than you have" );
|
||||
}
|
||||
|
||||
if ( $post['t11'] < 0 ) {
|
||||
$form->addError( "error", "You can't send back negative units." );
|
||||
}
|
||||
} else {
|
||||
$post['t11'] = '0';
|
||||
}
|
||||
|
||||
if ( $form->returnErrors() > 0 ) {
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
header( "Location: a2b.php" );
|
||||
exit;
|
||||
} else {
|
||||
|
||||
//change units
|
||||
$tribe = $database->getUserField($to['owner'], 'tribe', 0);
|
||||
$start = ($tribe - 1 ) * 10 + 1;
|
||||
$end = $tribe * 10 ;
|
||||
|
||||
$units = [];
|
||||
$amounts = [];
|
||||
$modes = [];
|
||||
|
||||
$j = 1;
|
||||
for ( $i = $start; $i <= $end; $i ++ ) {
|
||||
$units[] = $i;
|
||||
$amounts[] = $post[ 't' . $j . '' ];
|
||||
$modes[] = 0;
|
||||
|
||||
$database->modifyEnforce($post['ckey'], $units, $amounts, $modes);
|
||||
$j++;
|
||||
|
||||
$troopsTime = $this->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $tribe, $post, 1, 't');
|
||||
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
|
||||
|
||||
$reference = $database->addAttack($enforce['from'], $post['t1'], $post['t2'], $post['t3'], $post['t4'], $post['t5'], $post['t6'], $post['t7'], $post['t8'], $post['t9'], $post['t10'], $post['t11'], 2, 0, 0, 0, 0);
|
||||
$database->addMovement(4, $village->wid, $enforce['from'], $reference, time(), ($time + time()));
|
||||
$technology->checkReinf($post['ckey'], false);
|
||||
|
||||
header("Location: build.php?id=39&refresh=1");
|
||||
exit();
|
||||
}
|
||||
}else{
|
||||
$form->addError("error", "You cant change someones troops.");
|
||||
if($form->returnErrors() > 0){
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
header("Location: a2b.php");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
header("Location: banned.php");
|
||||
exit();
|
||||
}
|
||||
$j ++;
|
||||
}
|
||||
|
||||
$units[] = 'hero';
|
||||
$amounts[] = $post['t11'];
|
||||
$modes[] = 0;
|
||||
|
||||
$database->modifyEnforce($post['ckey'], $units, $amounts, $modes);
|
||||
$j++;
|
||||
|
||||
$troopsTime = $this->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $tribe, $post, 1, 't');
|
||||
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
|
||||
|
||||
$reference = $database->addAttack($enforce['from'], $post['t1'], $post['t2'], $post['t3'], $post['t4'], $post['t5'], $post['t6'], $post['t7'], $post['t8'], $post['t9'], $post['t10'], $post['t11'], 2, 0, 0, 0, 0);
|
||||
$database->addMovement(4, $village->wid, $enforce['from'], $reference, time(), ($time + time()));
|
||||
$technology->checkReinf($post['ckey'], false);
|
||||
|
||||
header("Location: build.php?id=39&refresh=1");
|
||||
exit();
|
||||
}
|
||||
}else{
|
||||
$form->addError("error", "You cant change someones troops.");
|
||||
if($form->returnErrors() > 0){
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
header("Location: a2b.php");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function Settlers($post) {
|
||||
global $form, $database, $village, $session;
|
||||
|
||||
if ($session->access != BANNED) {
|
||||
$mode = CP;
|
||||
$total = count($database->getProfileVillages($session->uid));
|
||||
$need_cps = ${'cp'.$mode}[$total + 1];
|
||||
$cps = $session->cp;
|
||||
$rallypoint = $database->getResourceLevel($village->wid);
|
||||
|
||||
//-- Prevent user from founding a new village if there are not enough settlers or the player put an invalid village ID or an already occupied one
|
||||
//-- fix by AL-Kateb - Semplified and additions by iopietro
|
||||
if ($rallypoint['f39'] > 0 && $village->unitarray['u'.$session->tribe.'0'] >= 3 && isset($post['s']) && ($newvillage = $database->getMInfo($post['s']))['id'] > 0 && $newvillage['occupied'] == 0 && $newvillage['oasistype'] == 0) {
|
||||
if ($cps >= $need_cps) {
|
||||
$troopsTime = $this->getWalkingTroopsTime($village->wid, $newvillage['id'], 0, 0, [300], 0);
|
||||
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
|
||||
|
||||
$unit = ($session->tribe * 10);
|
||||
$database->modifyResource($village->wid, 750, 750, 750, 750, 0);
|
||||
$database->modifyUnit($village->wid, [$unit], [3], [0]);
|
||||
$database->addMovement(5, $village->wid, $post['s'], 0, time(), time() + $time);
|
||||
}
|
||||
header("Location: build.php?id=39");
|
||||
exit;
|
||||
} else {
|
||||
header("Location: dorf1.php");
|
||||
exit;
|
||||
$mode = CP;
|
||||
$total = count($database->getProfileVillages($session->uid));
|
||||
$need_cps = ${'cp'.$mode}[$total + 1];
|
||||
$cps = $session->cp;
|
||||
$rallypoint = $database->getResourceLevel($village->wid);
|
||||
|
||||
//-- Prevent user from founding a new village if there are not enough settlers or the player put an invalid village ID or an already occupied one
|
||||
//-- fix by AL-Kateb - Semplified and additions by iopietro
|
||||
if ($rallypoint['f39'] > 0 && $village->unitarray['u'.$session->tribe.'0'] >= 3 && isset($post['s']) && ($newvillage = $database->getMInfo($post['s']))['id'] > 0 && $newvillage['occupied'] == 0 && $newvillage['oasistype'] == 0) {
|
||||
if ($cps >= $need_cps) {
|
||||
$troopsTime = $this->getWalkingTroopsTime($village->wid, $newvillage['id'], 0, 0, [300], 0);
|
||||
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
|
||||
|
||||
$unit = ($session->tribe * 10);
|
||||
$database->modifyResource($village->wid, 750, 750, 750, 750, 0);
|
||||
$database->modifyUnit($village->wid, [$unit], [3], [0]);
|
||||
$database->addMovement(5, $village->wid, $post['s'], 0, time(), time() + $time);
|
||||
}
|
||||
header("Location: build.php?id=39");
|
||||
exit;
|
||||
} else {
|
||||
header("Location: banned.php");
|
||||
header("Location: dorf1.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user