diff --git a/GameEngine/Account.php b/GameEngine/Account.php index 3e66f78b..1ed828d4 100755 --- a/GameEngine/Account.php +++ b/GameEngine/Account.php @@ -81,7 +81,6 @@ class Account { else if(User::exists($database,$_POST['name'])) { $form->addError("name",USRNM_TAKEN); } - } if(!isset($_POST['pw']) || trim($_POST['pw']) == "") { $form->addError("pw",PW_EMPTY); @@ -116,8 +115,6 @@ class Account { $form->addError("invt",$_POST['invited']); $_SESSION['errorarray'] = $form->getErrors(); $_SESSION['valuearray'] = $_POST; - - header("Location: anmelden.php"); exit; } @@ -144,7 +141,6 @@ class Account { ["", $_POST['invited']], 1 ); - $this->generateBase($_POST['kid'], $uid, $_POST['name']); header("Location: login.php"); exit; @@ -155,7 +151,6 @@ class Account { private function Activate() { global $database; - if(START_DATE < date('d.m.Y') or START_DATE == date('d.m.Y') && START_TIME <= date('H:i')) { $q = "SELECT act, username, password, email, tribe, location FROM ".TB_PREFIX."activate where act = '".$database->escape($_POST['id'])."'"; @@ -185,7 +180,6 @@ class Account { private function Unreg() { global $database; - $q = "SELECT password, username FROM ".TB_PREFIX."activate where id = ".(int) $_POST['id']; $result = mysqli_query($database->dblink,$q); $dbarray = mysqli_fetch_array($result); @@ -202,7 +196,6 @@ class Account { private function Login() { global $database, $session, $form; - $user = $_POST['user']; if(!isset($_POST['user']) || empty($_POST['user'])){ $form->addError("user", $user); @@ -222,15 +215,10 @@ class Account { } else $form->addError("pw", LOGIN_PW_ERROR); } - $userData = $database->getUserArray($_POST['user'], 0); - - // Vacation mode by Shadow if($userData["vac_mode"] == 1 && $userData["vac_time"] > time()){ $form->addError("vacation", "Vacation mode is still enabled"); } - - // Vacation mode by Shadow if($form->returnErrors() > 0){ $_SESSION['errorarray'] = $form->getErrors(); $_SESSION['valuearray'] = $_POST; @@ -238,9 +226,7 @@ class Account { header("Location: login.php"); exit(); }else{ - // Vacation mode by Shadow $database->removevacationmode($userData['id']); - // Vacation mode by Shadow if($database->login($_POST['user'], $_POST['pw'])){ $database->UpdateOnline("login", $_POST['user'], time(), $userData['id']); }else if($database->sitterLogin($_POST['user'], $_POST['pw'])){ @@ -252,8 +238,7 @@ class Account { } private function Logout() { - global $session, $database; - + global $session, $database; unset($_SESSION['wid']); $database->activeModify(addslashes($session->username),1); $database->UpdateOnline("logout") or die(mysqli_error($database->dblink)); @@ -268,10 +253,8 @@ class Account { function generateBase($kid, $uid, $username) { global $database; $message = new Message(); - if($kid == 0) $kid = rand(1,4); else $kid = $_POST['kid']; - $database->generateVillages([['wid' => 0, 'mode' => 0, 'type' => 3, 'kid' => $kid, 'capital' => 1, 'pop' => 2, 'name' => null, 'natar' => 0]], $uid, $username); $message->sendWelcome($uid, $username); } diff --git a/GameEngine/Alliance.php b/GameEngine/Alliance.php index 74a2de41..8308d490 100755 --- a/GameEngine/Alliance.php +++ b/GameEngine/Alliance.php @@ -47,7 +47,6 @@ class Alliance { public function procAlliance($get) { global $session, $database; - if($session->alliance > 0) { $this->allianceArray = $database->getAlliance($session->alliance); // Permissions Array @@ -57,7 +56,6 @@ class Alliance { $this->inviteArray = $database->getInvitation($session->uid); $this->gotInvite = count($this->inviteArray) > 0; } - if(isset($get['a'])) { switch($get['a']) { case 2: @@ -86,7 +84,6 @@ class Alliance { public function isForumAccessible($forumID){ global $session; - //Loop through the shared forums and try to find the passed one foreach($session->sharedForums as $forums){ foreach($forums as $forum){ @@ -105,9 +102,7 @@ class Alliance { public static function canAct($datas, $mode = 0){ global $database, $session; - $hasSwitchedToAdmin = isset($datas['admin']) && !empty($datas['admin']) && $datas['admin'] == "switch_admin"; - return (/*$database->CheckEditRes($datas['aid']) == 1 && */($datas['alliance'] > 0 && (($database->isAllianceOwner($session->uid) == $datas['alliance'] || ($datas['forum_perm'] == 1 && $session->alliance == $datas['alliance']))) || ($datas['owner'] == $session->uid && $session->access != ADMIN)) || diff --git a/GameEngine/Database.php b/GameEngine/Database.php index 71b1d5a4..9fc3de36 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -8496,8 +8496,183 @@ References: User ID/Message ID, Mode return $dbarray2['vac_mode'] == 1; } } - else return false; + else + return + false; } + + /***************************************** + Function to vacation mode remake by Shadow + References: Shadow + *****************************************/ + + function checkVacationRequirements($uid){ + $uid = (int)$uid; + $time = time(); + $errors = []; + + // 1. Troops moving OUT + $q = "SELECT COUNT(*) as num + FROM ".TB_PREFIX."movement m + JOIN ".TB_PREFIX."vdata v ON v.wref = m.from + WHERE v.owner=$uid + AND m.proc=0 + AND m.endtime > $time + AND m.sort_type = 3"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ die("SQL ERROR (TROOPS_MOVING): ".mysqli_error($this->dblink)); } + + $row = mysqli_fetch_assoc($res); + if((int)$row['num'] > 0) $errors[] = "TROOPS_MOVING"; + + + // 2. Incoming troops + $q = "SELECT COUNT(*) as num + FROM ".TB_PREFIX."movement m + JOIN ".TB_PREFIX."vdata v ON v.wref = m.to + WHERE v.owner=$uid + AND m.proc=0 + AND m.endtime > $time + AND (m.sort_type = 3 OR m.sort_type = 4)"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ die("SQL ERROR (INCOMING): ".mysqli_error($this->dblink)); } + + $row = mysqli_fetch_assoc($res); + if((int)$row['num'] > 0) $errors[] = "INCOMING_TROOPS"; + + + // 3. Reinforcements + $q = "SELECT COUNT(*) as num + FROM ".TB_PREFIX."enforcement e + JOIN ".TB_PREFIX."vdata v ON v.wref = e.vref + WHERE v.owner = $uid + AND e.from != e.vref"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ die("SQL ERROR (REINFORCEMENTS): ".mysqli_error($this->dblink)); } + + $row = mysqli_fetch_assoc($res); + if((int)$row['num'] > 0) $errors[] = "REINFORCEMENTS"; + + + // 4. Wonder of the World + $q = "SELECT COUNT(*) as num + FROM ".TB_PREFIX."fdata f + JOIN ".TB_PREFIX."vdata v ON v.wref=f.vref + WHERE v.owner=$uid AND f.f99t=40"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ die("SQL ERROR (WW): ".mysqli_error($this->dblink)); } + + $row = mysqli_fetch_assoc($res); + if((int)$row['num'] > 0) $errors[] = "WW"; + + + // 5. Artefacts + $q = "SELECT COUNT(*) as num + FROM ".TB_PREFIX."artefacts + WHERE owner=$uid"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ die("SQL ERROR (ARTEFACTS): ".mysqli_error($this->dblink)); } + + $row = mysqli_fetch_assoc($res); + if((int)$row['num'] > 0) $errors[] = "ARTEFACTS"; + + + // 6. Beginner protection (FIXAT) + $q = "SELECT protect + FROM ".TB_PREFIX."users + WHERE id=$uid"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ die("SQL ERROR (PROTECTION): ".mysqli_error($this->dblink)); } + + $row = mysqli_fetch_assoc($res); + + $protect = (int)$row['protect']; + + if($protect > 0 && $protect > $time){ + $errors[] = "PROTECTION"; + } + + + // ========================= + // 7. PRISONERS (FIX FINAL) + // ========================= + + // 7.1 Enemy troops trapped in your villages + $q = "SELECT COUNT(*) as num + FROM ".TB_PREFIX."prisoners p + JOIN ".TB_PREFIX."vdata v ON v.wref = p.wref + WHERE v.owner = $uid"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ + die("SQL ERROR (PRISONERS_IN): ".mysqli_error($this->dblink)); + } + + $row = mysqli_fetch_assoc($res); + $hasEnemyTrapped = (int)$row['num']; + + + // 7.2 Your troops trapped in enemy villages + $q = "SELECT COUNT(*) as num + FROM ".TB_PREFIX."prisoners p + JOIN ".TB_PREFIX."vdata v ON v.wref = p.from + WHERE v.owner = $uid"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ + die("SQL ERROR (PRISONERS_OUT): ".mysqli_error($this->dblink)); + } + + $row = mysqli_fetch_assoc($res); + $hasOwnCaptured = (int)$row['num']; + + + // FINAL RULE + if($hasEnemyTrapped > 0){ + $errors[] = "PRISONERS_IN"; + } + + if($hasOwnCaptured > 0){ + $errors[] = "PRISONERS_OUT"; + } + + // 8. Marketplace + $q = "SELECT COUNT(*) as num + FROM ".TB_PREFIX."movement m + JOIN ".TB_PREFIX."vdata v ON v.wref = m.from + WHERE v.owner = $uid + AND m.proc = 0 + AND m.endtime > $time + AND m.sort_type = 0"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ die("SQL ERROR (MARKET): ".mysqli_error($this->dblink)); } + + $row = mysqli_fetch_assoc($res); + if((int)$row['num'] > 0) $errors[] = "MARKET"; + + // 9. Account deletion + $q = "SELECT timestamp + FROM ".TB_PREFIX."deleting + WHERE uid = $uid"; + + $res = mysqli_query($this->dblink,$q); + if(!$res){ die("SQL ERROR (DELETING): ".mysqli_error($this->dblink)); } + + $row = mysqli_fetch_assoc($res); + + if(!empty($row['timestamp']) && $row['timestamp'] > $time){ + $errors[] = "ACCOUNT_DELETION"; + } + + return empty($errors) ? true : $errors; +} // no need to cache this method function getHeroDeadReviveOrInTraining($id) { diff --git a/GameEngine/Profile.php b/GameEngine/Profile.php index 6401d868..e1b98d0a 100755 --- a/GameEngine/Profile.php +++ b/GameEngine/Profile.php @@ -79,23 +79,55 @@ class Profile { */ private function setvactionmode($post){ - global $database, $session, $form; + global $database, $session; - if(isset($post['vac']) && $post['vac'] && isset($post['vac_days']) && $post['vac_days'] >= 2 && $post['vac_days'] <= 14){ - unset($_SESSION['wid']); - $database->setvacmode($session->uid, $post['vac_days']); - $database->activeModify(addslashes($session->username), 1); - $database->UpdateOnline("logout"); - $session->Logout(); - header("Location: login.php"); - exit; - }else{ - $form->add("vac", VAC_MODE_WRONG_DAYS); - header("Location: spieler.php?s=".$session->uid); - exit; - } - - } + if(isset($post['vac']) && $post['vac'] && isset($post['vac_days']) && $post['vac_days'] >= 2 && $post['vac_days'] <= 14){ + + $check = $database->checkVacationRequirements($session->uid); + + if($check !== true){ + + $messages = [ + "TROOPS_MOVING" => "There are no outgoing troops", + "INCOMING_TROOPS" => "There are no incoming troops", + "REINFORCEMENTS" => "You have reinforcements on your villages", + "WW" => "You own a Wonder of the World", + "ARTEFACTS" => "You own artefacts", + "PROTECTION" => "You are still under beginner protection", + "PRISONERS_IN" => "No units trapped in your traps", + "PRISONERS_OUT" => "No units in enemy traps", + "MARKET" => "Marketplace transport active", + "ACCOUNT_DELETION" => "Account is scheduled for deletion" + ]; + + $output = ""; + + foreach($check as $err){ + $output .= ($messages[$err] ?? $err) . "
"; + } + + $_SESSION['vac_error'] = $output; + + header("Location: spieler.php?s=5"); + exit; +} + + // TOTUL OK → intră în vacanță + unset($_SESSION['wid']); + $database->setvacmode($session->uid, $post['vac_days']); + $database->activeModify(addslashes($session->username), 1); + $database->UpdateOnline("logout"); + $session->Logout(); + + header("Location: login.php"); + exit; + + } else { + $_SESSION['vac_error'] = "Vacation days must be between 2 and 14"; + header("Location: spieler.php?s=5"); + exit; + } +} /** * Function to vacation mode - by advocaite and Shadow diff --git a/Templates/Profile/graphic.tpl b/Templates/Profile/graphic.tpl index b5c5367c..ebea3e82 100644 --- a/Templates/Profile/graphic.tpl +++ b/Templates/Profile/graphic.tpl @@ -95,6 +95,13 @@ $database->updateUserField($session->uid,gpack,$_POST["custom_url"],1); 4 Activate + Download + + + Travian T4 Style + 4 + Activate + Download diff --git a/Templates/Profile/vacation.tpl b/Templates/Profile/vacation.tpl index 7f91c729..a859a50c 100644 --- a/Templates/Profile/vacation.tpl +++ b/Templates/Profile/vacation.tpl @@ -1,8 +1,7 @@ - +

Player profile

- + +tribe; +$check = $database->checkVacationRequirements($session->uid); +$errors = is_array($check) ? $check : []; +$canActivate = empty($errors); +function vac_ok($key, $errors){ + return !in_array($key, $errors); +} +?> +
- - - +
-
- - - - - +

Vacation Mode

+
-
-

General description

- Use vacation mode to protect your villages during you are away.
- During the vacation will be inactive next actions:
-
+ " + .nl2br($_SESSION['vac_error']). + ""; -

Conditions

- + unset($_SESSION['vac_error']); + } + ?> + +
+ If you plan on being away for an extended period of time and do not wish to set a sitter, + you can activate Vacation Mode. During this time your account is essentially frozen. + No resources, troops or research will progress and your villages cannot be attacked. + Remember, this just freezes your Travian, not time. +

+ Minimum vacation: 2 days
+ Maximum vacation: 14 days
- + +
+ +
+

Inactive during vacation

+
    +
  • Send or receive troops
  • +
  • Start new construction order
  • +
  • Use market
  • +
  • Train new troops
  • +
  • Join an alliance
  • +
  • Delete account
  • +
+
+ +
+

Requirements

+
    +
  • + There are no outgoing troops +
  • + +
  • + There are no incoming troops +
  • + +
  • + No reinforcing troops sent/receive +
  • + +
  • + No ownership of a Wonder of the World village +
  • + +
  • + No ownership of an artifact village +
  • + +
  • + No beginner’s protection +
  • + +
  • + + No units in your traps + + No troops in enemy traps + +
  • + +
  • + No marketplace activity +
  • + +
  • + Account is not scheduled for deletion +
  • +
+
+ +
+ +
+ + + + + + days + +
+ +
+ + + +
+ Vacation mode cannot be activated – requirements not met +
+
+ - - - - -
Vacation Mode
If you plan on being away for an extended period of time and do not wish to set a sitter, you can set your account to Holiday Mode. During this time your account will stop produceing resource , CP , research , trops , etc , and stop receiving attacks , reinforcements, raid , essentially freezing your account. Remember, this just freezes your Travian, not time. If you are a member of Gold Club it will run out during this time and if you have automatic renewal selected, the automatic renewal feature will be cancelled while in Holiday Mode.Please Note you must set min of 2 days vaction mode and NO MORE THEN 14 days.
Want to activate Vacation Mode? - - -
- getError("vac") != "") { -echo "".$form->getError("vac").""; -} -?> -

-uid); - exit; -} -?> \ No newline at end of file + +uid); + exit; +} ?> \ No newline at end of file diff --git a/gpack/travian_default/lang/en/compact.css b/gpack/travian_default/lang/en/compact.css index 00dae078..42c2a54e 100644 --- a/gpack/travian_default/lang/en/compact.css +++ b/gpack/travian_default/lang/en/compact.css @@ -9235,3 +9235,68 @@ input.accept{width:12px;height:12px;background-image:url(../../img/a/acc.gif);} width: auto; min-width: 500px; } + +.vacationBox{ + background:#f5f5f5; + border:1px solid #cfcfcf; + padding:20px; + border-radius:6px; +} + +.vacationBox h2{ + margin-top:0; + color:#333; +} + +.vacationDesc{ + background:#fff; + border:1px solid #ddd; + padding:12px; + margin-bottom:20px; + font-size:13px; +} + +.vacationGrid{ + display:flex; + gap:30px; + margin-bottom:20px; +} + +.vacationColumn{ + flex:1; +} + +.vacationColumn h3{ + margin-bottom:8px; + color:#444; +} + +.vacList{ + padding-left:18px; +} + +.vacList li{ + margin-bottom:5px; +} + +.vacationActivate{ + background:#fff; + border:1px solid #ddd; + padding:12px; + margin-top:10px; +} + +.vacationActivate input[type=number]{ + width:60px; + margin-left:10px; +} + +.vacationButton{ + text-align:center; + margin-top:15px; +} + +.error{ + color:red; + margin-top:10px; +} diff --git a/spieler.php b/spieler.php index 592a3c24..32cd6389 100644 --- a/spieler.php +++ b/spieler.php @@ -125,38 +125,58 @@ else $building->procBuild($_GET);
= 2) { - $user = $database->getUserArray(preg_replace("/[^a-zA-Z0-9_-]/","",$_GET['uid']),1); - if(isset($user['id'])){ - include("Templates/Profile/overview.tpl"); - } else { - include("Templates/Profile/notfound.tpl"); - } - } - else { - include("Templates/Profile/special.tpl"); - } + + if($_GET['uid'] >= 2) { + + $user = $database->getUserArray(preg_replace("/[^a-zA-Z0-9_-]/","",$_GET['uid']),1); + + if(isset($user['id'])){ + + // 🔴 SHOW VACATION ERROR (IMPORTANT) + if(isset($_SESSION['vac_error'])){ + echo "
".nl2br($_SESSION['vac_error'])."
"; + unset($_SESSION['vac_error']); + } + + include("Templates/Profile/overview.tpl"); + + } else { + include("Templates/Profile/notfound.tpl"); + } + + } else { + include("Templates/Profile/special.tpl"); + } + } else if (isset($_GET['s'])) { - if($_GET['s'] == 1) { - include("Templates/Profile/profile.tpl"); - } - if($_GET['s'] == 2) { - include("Templates/Profile/preference.tpl"); - } - if($_GET['s'] == 3) { - include("Templates/Profile/account.tpl"); - } - if($_GET['s'] == 4) { - include("Templates/Profile/graphic.tpl"); - } - if($_GET['s'] == 5) { - include("Templates/Profile/vacation.tpl"); - } - if($_GET['s'] > 5 or $session->sit == 1) { - header("Location: ".$_SERVER['PHP_SELF']."?uid=".preg_replace("/[^a-zA-Z0-9_-]/","",$session->uid)); - exit; - } + + if($_GET['s'] == 1) { + + include("Templates/Profile/profile.tpl"); + } + + if($_GET['s'] == 2) { + include("Templates/Profile/preference.tpl"); + } + + if($_GET['s'] == 3) { + include("Templates/Profile/account.tpl"); + } + + if($_GET['s'] == 4) { + include("Templates/Profile/graphic.tpl"); + } + + if($_GET['s'] == 5) { + + include("Templates/Profile/vacation.tpl"); + } + + if($_GET['s'] > 5 or $session->sit == 1) { + header("Location: ".$_SERVER['PHP_SELF']."?uid=".preg_replace("/[^a-zA-Z0-9_-]/","",$session->uid)); + exit; + } } ?>