diff --git a/Admin/Mods/addTroops.php b/Admin/Mods/addTroops.php
deleted file mode 100644
index 558f3bf2..00000000
--- a/Admin/Mods/addTroops.php
+++ /dev/null
@@ -1,58 +0,0 @@
-getVillage($id);
-$user = $database->getUserArray($village['owner'],1);
-$coor = $database->getCoor($village['wref']);
-$varray = $database->getProfileVillages($village['owner']);
-$type = $database->getVillageType($village['wref']);
-$fdata = $database->getResourceLevel($village['wref']);
-$units = $database->getUnit($village['wref']);
-
-foreach ($_POST as $key => $value) {
- $_POST[$key] = (int) $value;
-}
-
-for($i = 1; $i <= 50; $i++) ${"u".$i} = $_POST['u'.$i];
-
-if($user['tribe'] == 1){
- $q = "UPDATE ".TB_PREFIX."units SET u1 = $u1, u2 = $u2, u3 = $u3, u4 = $u4, u5 = $u5, u6 = $u6, u7 = $u7, u8 = $u8, u9 = $u9, u10 = $u10 WHERE vref = $id";
- mysqli_query($GLOBALS["link"], $q);
-} else if($user['tribe'] == 2){
- $q = "UPDATE ".TB_PREFIX."units SET u11 = '$u11', u12 = '$u12', u13 = '$u13', u14 = '$u14', u15 = '$u15', u16 = '$u16', u17 = '$u17', u18 = '$u18', u19 = '$u19', u20 = '$u20' WHERE vref = $id";
- mysqli_query($GLOBALS["link"], $q);
-} else if($user['tribe'] == 3){
- $q = "UPDATE ".TB_PREFIX."units SET u21 = '$u21', u22 = '$u22', u23 = '$u23', u24 = '$u24', u25 = '$u25', u26 = '$u26', u27 = '$u27', u28 = '$u28', u29 = '$u29', u30 = '$u30' WHERE vref = $id";
- mysqli_query($GLOBALS["link"], $q);
-} else if($user['tribe'] == 4){
- $q = "UPDATE ".TB_PREFIX."units SET u31 = '$u31', u32 = '$u32', u33 = '$u33', u34 = '$u34', u35 = '$u35', u36 = '$u36', u37 = '$u37', u38 = '$u38', u39 = '$u39', u40 = '$u40' WHERE vref = $id";
- mysqli_query($GLOBALS["link"], $q);
-} else if($user['tribe'] == 5){
- $q = "UPDATE ".TB_PREFIX."units SET u41 = '$u41', u42 = '$u42', u43 = '$u43', u44 = '$u44', u45 = '$u45', u46 = '$u46', u47 = '$u47', u48 = '$u48', u49 = '$u49', u50 = '$u50' WHERE vref = $id";
- mysqli_query($GLOBALS["link"], $q);
-}
-
-mysqli_query($GLOBALS["link"], "Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Changed troop anmount in village $id ',".time().")");
-
-$database->addStarvationData($village['wref']);
-
-header("Location: ../../../Admin/admin.php?p=addTroops&did=".$id."&d");
-
-?>
\ No newline at end of file
diff --git a/Admin/Mods/cp.php b/Admin/Mods/cp.php
deleted file mode 100644
index 163ee6a3..00000000
--- a/Admin/Mods/cp.php
+++ /dev/null
@@ -1,24 +0,0 @@
-getUserField($id,"username",0);
-mysqli_query($GLOBALS["link"], "Insert into ".TB_PREFIX."admin_log values (0,$admid,'Added ".$_POST['cp']." Cultural Points to user $name ',".time().")");
-
-header("Location: ../../../Admin/admin.php?p=player&uid=".$id."&cp=ok");
-?>
\ No newline at end of file
diff --git a/Admin/Mods/deletemedalbyweek.php b/Admin/Mods/deletemedalbyweek.php
deleted file mode 100644
index 21ca8eeb..00000000
--- a/Admin/Mods/deletemedalbyweek.php
+++ /dev/null
@@ -1,22 +0,0 @@
-
\ No newline at end of file
diff --git a/Admin/Mods/editUser.php b/Admin/Mods/editUser.php
deleted file mode 100644
index d2a0b5ad..00000000
--- a/Admin/Mods/editUser.php
+++ /dev/null
@@ -1,27 +0,0 @@
- $value) {
- $_POST[$key] = $database->escape($value);
-}
-
-$id = $_POST['id'];
-$user = $database->getUserArray($id,1);
-mysqli_query($GLOBALS["link"], "UPDATE ".TB_PREFIX."users SET email = '".$_POST['email']."', tribe = ".(int) $_POST['tribe'].", location = '".$_POST['location']."', desc1 = '".$_POST['desc1']."', desc2 = '".$_POST['desc2']."' WHERE id = ".(int) $_POST['id']."");
-mysqli_query($GLOBALS["link"], "Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Changed ".$user['username']."\'s profile',".time().")");
-
-
-header("Location: ../../../Admin/admin.php?p=player&uid=".$id."");
-?>
\ No newline at end of file
diff --git a/Admin/Mods/gold.php b/Admin/Mods/gold.php
deleted file mode 100644
index 7127904c..00000000
--- a/Admin/Mods/gold.php
+++ /dev/null
@@ -1,25 +0,0 @@
-$gold gold to all users',".time().")");
-
-
-header("Location: ../../../Admin/admin.php?p=gold&g");
-?>
\ No newline at end of file
diff --git a/Admin/Mods/gold_1.php b/Admin/Mods/gold_1.php
deleted file mode 100644
index 8225bd10..00000000
--- a/Admin/Mods/gold_1.php
+++ /dev/null
@@ -1,24 +0,0 @@
-getUserField($id,"username",0);
-mysqli_query($GLOBALS["link"], "Insert into ".TB_PREFIX."admin_log values (0,$admid,'Added ".(int) $_POST['gold']." gold to user $name ',".time().")");
-
-header("Location: ../../../Admin/admin.php?p=player&uid=".$id."&g=ok");
-?>
\ No newline at end of file
diff --git a/Admin/Mods/index.php b/Admin/Mods/index.php
deleted file mode 100644
index 98297c7a..00000000
--- a/Admin/Mods/index.php
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
404 - File not found
-

-
We looked 404 times already but can't find anything, Not even an X marking the spot.
-
This system is not complete yet. So the page probably does not exist.
-
-
\ No newline at end of file
diff --git a/Admin/Mods/medals.php b/Admin/Mods/medals.php
deleted file mode 100644
index 9e56b05e..00000000
--- a/Admin/Mods/medals.php
+++ /dev/null
@@ -1,33 +0,0 @@
-$name ',".time().")");
-
-
-$deleteweek = (int) $_POST['medalweek'];
-mysqli_query($GLOBALS["link"], "DELETE FROM ".TB_PREFIX."medal WHERE week = ".$deleteweek."");
-
-header("Location: ../../../Admin/admin.php?p=player&uid=".$uid."");
-?>
\ No newline at end of file
diff --git a/Admin/Mods/renameVillage.php b/Admin/Mods/renameVillage.php
deleted file mode 100644
index d078ef2c..00000000
--- a/Admin/Mods/renameVillage.php
+++ /dev/null
@@ -1,29 +0,0 @@
- $value) {
- $_POST[$key] = $database->escape($value);
-}
-
-$did = (int) $_POST['did'];
-$name = $_POST['villagename'];
-$sql = "UPDATE ".TB_PREFIX."vdata SET name = '$name' WHERE wref = $did";
-
-mysqli_query($GLOBALS["link"], $sql);
-
-header("Location: ../../../Admin/admin.php?p=village&did=".$did."&name=".$origname."");
-?>
\ No newline at end of file
diff --git a/Admin/Mods/sendMessage.php b/Admin/Mods/sendMessage.php
deleted file mode 100644
index 72ee7e08..00000000
--- a/Admin/Mods/sendMessage.php
+++ /dev/null
@@ -1,27 +0,0 @@
- $value) {
- $_POST[$key] = $database->escape($value);
-}
-
-$uid = (int) $_POST['uid'];
-$topic = $_POST['topic'];
-$message = $_POST['message'];
-$time = time();
-
-$query = "INSERT INTO ".TB_PREFIX."mdata SET target = $uid, owner = 1, topic = '$topic', message = '$message', viewed = 0, archived = 0, send = 0, time = $time, deltarget = 0, delowner = 0, alliance = 0, player = 0, coor = 0, report = 0";
-mysqli_query($GLOBALS["link"], $query) OR DIE (mysqli_errno($GLOBALS["link"]));
-
-header("Location: ../../../Admin/admin.php?p=Newmessage&uid=".$uid."&msg=ok");
-?>
\ No newline at end of file
diff --git a/Admin/Templates/config.tpl b/Admin/Templates/config.tpl
index 7e505938..140784dd 100644
--- a/Admin/Templates/config.tpl
+++ b/Admin/Templates/config.tpl
@@ -392,18 +392,6 @@ if($_SESSION['access'] < 9) die(ACCESS_DENIED_ADMIN);
? |
Enabled"; } elseif(!NEWSBOX3){ echo "Disabled"; } ?> |
-
-
diff --git a/Admin/admin.php b/Admin/admin.php
index cbc5032a..4a24da68 100644
--- a/Admin/admin.php
+++ b/Admin/admin.php
@@ -6,14 +6,14 @@
## --------------------------------------------------------------------------- ##
## ##
## Project: TravianZ ##
-## Version: 05.03.2014 ##
+## Version: 05.03.2026 ##
## Filename: Admin/admin.php ##
## Developed by: Dzoki ##
-## Edited by: Shadow and ronix ##
-## License: Creative Commons BY-NC-SA 3.0 ##
-## Copyright: TravianZ (c) 2014 - All rights reserved ##
-## URLs: http://travian.shadowss.ro ##
-## Source code: https://github.com/Shadowss/TravianZ ##
+## Refactored by: Shadow ##
+## License: TravianZ Project ##
+## Copyright: TravianZ (c) 2010-2026. All rights reserved. ##
+## URLs: https://travianz.org ##
+## https://github.com/Shadowss/TravianZ ##
## ##
#################################################################################
@@ -507,7 +507,6 @@ if (!empty($_GET['p'])) {
Server Homepage
Control Panel Home
Return to the server
-
Logout
Server Info
diff --git a/GameEngine/Admin/database.php b/GameEngine/Admin/database.php
index 95ec0124..b33e4a37 100755
--- a/GameEngine/Admin/database.php
+++ b/GameEngine/Admin/database.php
@@ -146,7 +146,7 @@ class adm_DB {
$dataarray = $$name;
for ($i = 1; $i <= $lvl; $i++) {
- $popT += $dataarray[$i]['pop'];
+ $popT += $dataarray[$i]['pop'] ?? 0;
}
return $popT;
}
@@ -158,7 +158,7 @@ class adm_DB {
$dataarray = $$name;
for ($i = 1; $i <= $lvl; $i++) {
- $popT += $dataarray[$i]['cp'];
+ $popT += $dataarray[$i]['cp'] ?? 0;
}
return $popT;
}
diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php
index 38671a33..e49fb9e5 100644
--- a/GameEngine/Automation.php
+++ b/GameEngine/Automation.php
@@ -606,7 +606,7 @@ class Automation {
$vilIDs = [];
foreach($dataarray as $data) {
- $vilIDs[$data['to']] = true;
+ $vilIDs[$data['wid']] = true;
$vilIDs[$data['from']] = true;
}
$vilIDs = array_keys($vilIDs);
@@ -935,6 +935,8 @@ class Automation {
// calculate battles
foreach($dataarray as $data) {
//set base things
+ $totaltraped_att = 0;
+ for($i = 1; $i <= 11; $i++) ${'traped'.$i} = 0;
$isoasis = $data['oasistype'];
$AttackArrivalTime = $data['endtime'];
$AttackerWref = $data['from'];
@@ -4210,531 +4212,173 @@ WHERE
*
*/
- function medals(){
- global $ranking, $database;
-
- //we may give away ribbons
- $giveMedal = false;
- $q = "SELECT lastgavemedal FROM ".TB_PREFIX."config";
- $result = mysqli_query($database->dblink,$q);
- if($result) {
- $row = mysqli_fetch_assoc($result);
- $stime = strtotime(START_DATE) - strtotime(date('d.m.Y')) + strtotime(START_TIME);
- if($row['lastgavemedal'] == 0 && $stime < time()){
- $setDays = round(MEDALINTERVAL / 86400);
- $newtime = $setDays < 7 ? strtotime(($setDays + 1).'day midnight') : strtotime('next monday');
- $q = "UPDATE ".TB_PREFIX."config SET lastgavemedal = ".(int) $newtime;
- $database->query($q);
- }elseif($row['lastgavemedal'] != 0){
- $time = $row['lastgavemedal'] + MEDALINTERVAL;
- $giveMedal = $row['lastgavemedal'] < time();
- }
- }
-
- if($giveMedal && MEDALINTERVAL > 0){
-
- //determine which week we are
-
- $q = "SELECT week FROM ".TB_PREFIX."medal order by week DESC LIMIT 0, 1";
- $result = mysqli_query($database->dblink,$q);
- if(mysqli_num_rows($result)) {
- $row=mysqli_fetch_assoc($result);
- $week=($row['week']+1);
- } else {
- $week='1';
- }
-
- //Do same for ally week
-
- $q = "SELECT week FROM ".TB_PREFIX."allimedal order by week DESC LIMIT 0, 1";
- $result = mysqli_query($database->dblink,$q);
- if(mysqli_num_rows($result)) {
- $row=mysqli_fetch_assoc($result);
- $allyweek=($row['week']+1);
- } else {
- $allyweek='1';
- }
-
-
- //Attackers of the week
- $result = mysqli_query($database->dblink,"SELECT id, ap FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY ap DESC, id DESC Limit 10");
- $i=0;
- while($row = mysqli_fetch_array($result)){
- $i++;
- $img="t2_".($i)."";
- $quer="insert into ".TB_PREFIX."medal (userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", 1, ".($i).", ".(int) $week.", '".$row['ap']."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- //Defender of the week
- $result = mysqli_query($database->dblink,"SELECT id, dp FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY dp DESC, id DESC Limit 10");
- $i=0;
- while($row = mysqli_fetch_array($result)){
- $i++;
- $img="t3_".($i)."";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '2', ".($i).", '".(int) $week."', '".$row['dp']."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- //Climbers of the week
- $result = mysqli_query($database->dblink,"SELECT id, Rc FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY Rc DESC, id DESC Limit 10");
- $i=0;
- while($row = mysqli_fetch_array($result)){
- $i++;
- $img="t1_".($i)."";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '3', ".($i).", '".(int) $week."', '".$row['Rc']."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- //Rank climbers of the week
- $result = mysqli_query($database->dblink,"SELECT id, clp FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY clp DESC Limit 10");
- $i=0;
- while($row = mysqli_fetch_array($result)){
- $i++;
- $img="t6_".($i)."";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '10', ".($i).", '".(int) $week."', '".$row['clp']."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- //Robbers of the week
- $result = mysqli_query($database->dblink,"SELECT id, RR FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY RR DESC, id DESC Limit 10");
- $i=0;
- while($row = mysqli_fetch_array($result)){
- $i++;
- $img="t4_".($i)."";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '4', ".($i).", '".(int) $week."', '".$row['RR']."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- //Part of the bonus for top 10 attack + defense out
- //Top10 attackers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY ap DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- //Top 10 defenders
- $result2 = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY dp DESC, id DESC Limit 10");
- while($row2 = mysqli_fetch_array($result2)){
- if($row['id']==$row2['id']){
-
- $query3="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 5";
- $result3=mysqli_query($database->dblink,$query3);
- $row3=mysqli_fetch_row($result3);
-
- //Look what color the ribbon must have
- if($row3[0]<='2'){
- $img="t22".$row3[0]."_1";
- switch ($row3[0]) {
- case "0":
- $tekst="";
- break;
- case "1":
- $tekst="twice ";
- break;
- case "2":
- $tekst="three times ";
- break;
- }
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '5', '0', '".(int) $week."', '".$tekst."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- }
- }
- }
-
- //you stand for 3rd / 5th / 10th time in the top 3 strikers
- //top10 attackers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY ap DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 1 AND plaats<=3";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x at present as it is so ribbon 3rd (bronze)
- if($row1[0]=='3'){
- $img="t120_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '6', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x at present as it is so 5th medal (silver)
- if($row1[0]=='5'){
- $img="t121_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '6', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t122_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '6', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- }
- //you stand for 3rd / 5th / 10th time in the top 10 attackers
- //top10 attackers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY ap DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 1 AND plaats<=10";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x in gestaan, dit is 3e dus lintje (brons)
- if($row1[0]=='3'){
- $img="t130_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '12', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x in gestaan, dit is 5e dus lintje (zilver)
- if($row1[0]=='5'){
- $img="t131_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '12', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t132_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '12', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- }
- //je staat voor 3e / 5e / 10e keer in de top 3 verdedigers
- //Pak de top10 verdedigers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY dp DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 2 AND plaats<=3";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x in gestaan, dit is 3e dus lintje (brons)
- if($row1[0]=='3'){
- $img="t140_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '7', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x in gestaan, dit is 5e dus lintje (zilver)
- if($row1[0]=='5'){
- $img="t141_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '7', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t142_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '7', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- }
- //je staat voor 3e / 5e / 10e keer in de top 3 verdedigers
- //Pak de top10 verdedigers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY dp DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 2 AND plaats<=10";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x in gestaan, dit is 3e dus lintje (brons)
- if($row1[0]=='3'){
- $img="t150_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '13', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x in gestaan, dit is 5e dus lintje (zilver)
- if($row1[0]=='5'){
- $img="t151_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '13', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t152_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '13', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- }
-
- //je staat voor 3e / 5e / 10e keer in de top 3 klimmers
- //Pak de top10 klimmers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY Rc DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 3 AND plaats<=3";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x in gestaan, dit is 3e dus lintje (brons)
- if($row1[0]=='3'){
- $img="t100_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '8', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x in gestaan, dit is 5e dus lintje (zilver)
- if($row1[0]=='5'){
- $img="t101_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '8', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t102_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '8', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- }
- //je staat voor 3e / 5e / 10e keer in de top 3 klimmers
- //Pak de top10 klimmers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY Rc DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 3 AND plaats<=10";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x in gestaan, dit is 3e dus lintje (brons)
- if($row1[0]=='3'){
- $img="t110_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '14', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x in gestaan, dit is 5e dus lintje (zilver)
- if($row1[0]=='5'){
- $img="t111_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '14', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t112_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '14', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- }
-
- //je staat voor 3e / 5e / 10e keer in de top 3 klimmers
- //Pak de top3 rank climbers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY clp DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 10 AND plaats<=3";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x in gestaan, dit is 3e dus lintje (brons)
- if($row1[0]=='3'){
- $img="t200_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '11', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x in gestaan, dit is 5e dus lintje (zilver)
- if($row1[0]=='5'){
- $img="t201_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '11', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t202_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '11', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- }
- //je staat voor 3e / 5e / 10e keer in de top 10klimmers
- //Pak de top3 rank climbers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY clp DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 10 AND plaats<=10";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x in gestaan, dit is 3e dus lintje (brons)
- if($row1[0]=='3'){
- $img="t210_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '16', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x in gestaan, dit is 5e dus lintje (zilver)
- if($row1[0]=='5'){
- $img="t211_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '16', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t212_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '16', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- }
-
- //je staat voor 3e / 5e / 10e keer in de top 10 overvallers
- //Pak de top10 overvallers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY RR DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 4 AND plaats<=3";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x in gestaan, dit is 3e dus lintje (brons)
- if($row1[0]=='3'){
- $img="t160_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '9', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x in gestaan, dit is 5e dus lintje (zilver)
- if($row1[0]=='5'){
- $img="t161_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '9', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t162_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '9', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- }
- //je staat voor 3e / 5e / 10e keer in de top 10 overvallers
- //Pak de top10 overvallers
- $result = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY RR DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- $query1="SELECT Count(*) FROM ".TB_PREFIX."medal WHERE userid=".(int) $row['id']." AND categorie = 4 AND plaats<=10";
- $result1=mysqli_query($database->dblink,$query1);
- $row1=mysqli_fetch_row($result1);
-
-
- //2x in gestaan, dit is 3e dus lintje (brons)
- if($row1[0]=='3'){
- $img="t170_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '15', '0', '".(int) $week."', 'Three', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //4x in gestaan, dit is 5e dus lintje (zilver)
- if($row1[0]=='5'){
- $img="t171_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '15', '0', '".(int) $week."', 'Five', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- //9x at present as it is so 10th medal (gold)
- if($row1[0]=='10'){
- $img="t172_1";
- $quer="insert into ".TB_PREFIX."medal(userid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '15', '0', '".(int) $week."', 'Ten', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- }
-
- //Put all true dens to 0
- $query="SELECT id FROM ".TB_PREFIX."users WHERE id > 5 AND access < 8 ORDER BY id+0 DESC";
- $result=mysqli_query($database->dblink,$query);
- $userIDs = [];
- for ($i=0; $row=mysqli_fetch_row($result); $i++){
- $userIDs[] = (int) $row[0];
- }
-
- if (count($userIDs)) {
- mysqli_query($database->dblink,"UPDATE ".TB_PREFIX."users SET ap=0, dp=0,Rc=0,clp=0, RR=0 WHERE id IN(".implode(', ', $userIDs).")");
- }
-
- //Start alliance Medals wooot
-
- //Aanvallers v/d Week
- $result = mysqli_query($database->dblink,"SELECT id, ap FROM ".TB_PREFIX."alidata ORDER BY ap DESC, id DESC Limit 10");
- $i=0; while($row = mysqli_fetch_array($result)){
- $i++; $img="a2_".($i)."";
- $quer="insert into ".TB_PREFIX."allimedal(allyid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '1', ".($i).", '".$allyweek."', '".$row['ap']."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- //Verdediger v/d Week
- $result = mysqli_query($database->dblink,"SELECT id, dp FROM ".TB_PREFIX."alidata ORDER BY dp DESC Limit 10");
- $i=0; while($row = mysqli_fetch_array($result)){
- $i++; $img="a3_".($i)."";
- $quer="insert into ".TB_PREFIX."allimedal(allyid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '2', ".($i).", '".$allyweek."', '".$row['dp']."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- //Overvallers v/d Week
- $result = mysqli_query($database->dblink,"SELECT id, RR FROM ".TB_PREFIX."alidata ORDER BY RR DESC, id DESC Limit 10");
- $i=0; while($row = mysqli_fetch_array($result)){
- $i++; $img="a4_".($i)."";
- $quer="insert into ".TB_PREFIX."allimedal(allyid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '4', ".($i).", '".$allyweek."', '".$row['RR']."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- //Rank climbers of the week
- $result = mysqli_query($database->dblink,"SELECT id, clp FROM ".TB_PREFIX."alidata ORDER BY clp DESC Limit 10");
- $i=0; while($row = mysqli_fetch_array($result)){
- $i++; $img="a1_".($i)."";
- $quer="insert into ".TB_PREFIX."allimedal(allyid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '3', ".($i).", '".$allyweek."', '".$row['clp']."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
-
- $result = mysqli_query($database->dblink,"SELECT * FROM ".TB_PREFIX."alidata ORDER BY ap DESC, id DESC Limit 10");
- while($row = mysqli_fetch_array($result)){
-
- //Pak de top10 verdedigers
- $result2 = mysqli_query($database->dblink,"SELECT id FROM ".TB_PREFIX."alidata ORDER BY dp DESC, id DESC Limit 10");
- while($row2 = mysqli_fetch_array($result2)){
- if($row['id']==$row2['id']){
-
- $query3="SELECT Count(*) FROM ".TB_PREFIX."allimedal WHERE allyid=".(int) $row['id']." AND categorie = 5";
- $result3=mysqli_query($database->dblink,$query3);
- $row3=mysqli_fetch_row($result3);
-
- //Look what color the ribbon must have
- if($row3[0]<='2'){
- $img="t22".$row3[0]."_1";
- switch ($row3[0]) {
- case "0":
- $tekst="";
- break;
- case "1":
- $tekst="twice ";
- break;
- case "2":
- $tekst="three times ";
- break;
- }
- $quer="insert into ".TB_PREFIX."allimedal(allyid, categorie, plaats, week, points, img) values(".(int) $row['id'].", '5', '0', '".$allyweek."', '".$tekst."', '".$img."')";
- $resul=mysqli_query($database->dblink,$quer);
- }
- }
- }
- }
-
- $query="SELECT id FROM ".TB_PREFIX."alidata ORDER BY id+0 DESC";
- $result=mysqli_query($database->dblink,$query);
-
- $aliIDs = [];
- for ($i=0; $row=mysqli_fetch_row($result); $i++){
- $aliIDs[] = (int) $row[0];
- }
-
- if (count($aliIDs)) {
- mysqli_query($database->dblink,"UPDATE ".TB_PREFIX."alidata SET ap=0, dp=0,RR=0,clp=0 WHERE id IN(".implode(', ', $aliIDs).")");
- }
-
- $q = "UPDATE ".TB_PREFIX."config SET lastgavemedal=".$time;
- $database->query($q);
+ function medals() {
+ global $ranking, $database;
+
+ // --- Configuration ---
+ $minUid = 5;
+ // Exclude BANNED (0), MH (8), ADMIN (9)
+ $userFilter = "id > $minUid AND access NOT IN (0,8,9)";
+
+ // Helper to insert a user medal
+ $insertMedal = function($userid, $category, $place, $week, $points, $img) use ($database) {
+ $q = "INSERT INTO ".TB_PREFIX."medal (userid, categorie, plaats, week, points, img) VALUES (".
+ (int)$userid.", ".(int)$category.", ".(int)$place.", ".(int)$week.", '".mysqli_real_escape_string($database->dblink, $points)."', '".mysqli_real_escape_string($database->dblink, $img)."')";
+ mysqli_query($database->dblink, $q);
+ };
+
+ // --- Check if we should award medals now ---
+ $giveMedal = false;
+ $q = "SELECT lastgavemedal FROM ".TB_PREFIX."config";
+ $result = mysqli_query($database->dblink, $q);
+ if ($result) {
+ $row = mysqli_fetch_assoc($result);
+ $stime = strtotime(START_DATE) - strtotime(date('d.m.Y')) + strtotime(START_TIME);
+
+ if ($row['lastgavemedal'] == 0 && $stime < time()) {
+ // First run after server start - schedule next run
+ $setDays = round(MEDALINTERVAL / 86400);
+ $newtime = $setDays < 7? strtotime(($setDays + 1).' day midnight') : strtotime('next monday');
+ $database->query("UPDATE ".TB_PREFIX."config SET lastgavemedal = ".(int)$newtime);
+ } elseif ($row['lastgavemedal']!= 0) {
+ $time = $row['lastgavemedal'] + MEDALINTERVAL;
+ $giveMedal = $row['lastgavemedal'] < time();
}
}
+ if (!($giveMedal && MEDALINTERVAL > 0)) {
+ return;
+ }
+
+ // --- Determine current week numbers ---
+ $getNextWeek = function($table) use ($database) {
+ $q = "SELECT week FROM ".TB_PREFIX."$table ORDER BY week DESC LIMIT 1";
+ $res = mysqli_query($database->dblink, $q);
+ return $res && mysqli_num_rows($res)? (mysqli_fetch_assoc($res)['week'] + 1) : 1;
+ };
+ $week = $getNextWeek('medal');
+ $allyweek = $getNextWeek('allimedal');
+
+ // --- Award top 10 for each category ---
+ $awardTop = function($field, $category, $imgPrefix) use ($database, $userFilter, $week, $insertMedal) {
+ $q = "SELECT id, $field FROM ".TB_PREFIX."users WHERE $userFilter ORDER BY $field DESC, id DESC LIMIT 10";
+ $res = mysqli_query($database->dblink, $q);
+ $i = 0;
+ while ($row = mysqli_fetch_array($res)) {
+ $i++;
+ $insertMedal($row['id'], $category, $i, $week, $row[$field], $imgPrefix.$i);
+ }
+ };
+
+ // Attackers of the week (cat 1)
+ $awardTop('ap', 1, 't2_');
+ // Defenders of the week (cat 2)
+ $awardTop('dp', 2, 't3_');
+ // Climbers of the week (cat 3)
+ $awardTop('Rc', 3, 't1_');
+ // Rank climbers of the week (cat 10)
+ $awardTop('clp', 10, 't6_');
+ // Robbers of the week (cat 4)
+ $awardTop('RR', 4, 't4_');
+
+ // --- Bonus: player in both top10 attack AND defense (cat 5) ---
+ $topAttackers = mysqli_query($database->dblink, "SELECT id FROM ".TB_PREFIX."users WHERE $userFilter ORDER BY ap DESC, id DESC LIMIT 10");
+ while ($a = mysqli_fetch_array($topAttackers)) {
+ $topDefenders = mysqli_query($database->dblink, "SELECT id FROM ".TB_PREFIX."users WHERE $userFilter ORDER BY dp DESC, id DESC LIMIT 10");
+ while ($d = mysqli_fetch_array($topDefenders)) {
+ if ($a['id'] == $d['id']) {
+ $cnt = mysqli_fetch_row(mysqli_query($database->dblink, "SELECT COUNT(*) FROM ".TB_PREFIX."medal WHERE userid=".(int)$a['id']." AND categorie=5"))[0];
+ if ($cnt <= 2) {
+ $texts = [0 => '', 1 => 'twice ', 2 => 'three times '];
+ $insertMedal($a['id'], 5, 0, $week, $texts[$cnt], 't22'.$cnt.'_1');
+ }
+ }
+ }
+ }
+
+ // --- Milestone ribbons for 3/5/10 times in top3 or top10 ---
+ $awardMilestone = function($field, $sourceCat, $topLimit, $targetCat, $imgBase) use ($database, $userFilter, $week, $insertMedal) {
+ $res = mysqli_query($database->dblink, "SELECT id FROM ".TB_PREFIX."users WHERE $userFilter ORDER BY $field DESC, id DESC LIMIT 10");
+ while ($u = mysqli_fetch_array($res)) {
+ $cnt = mysqli_fetch_row(mysqli_query($database->dblink,
+ "SELECT COUNT(*) FROM ".TB_PREFIX."medal WHERE userid=".(int)$u['id']." AND categorie=".(int)$sourceCat." AND plaats<=".(int)$topLimit))[0];
+
+ $map = ['3' => ['Three', $imgBase.'0_1'], '5' => ['Five', $imgBase.'1_1'], '10' => ['Ten', $imgBase.'2_1']];
+ if (isset($map[$cnt])) {
+ $insertMedal($u['id'], $targetCat, 0, $week, $map[$cnt][0], $map[$cnt][1]);
+ }
+ }
+ };
+
+ // Attackers milestones
+ $awardMilestone('ap', 1, 3, 6, 't12'); // top3 attackers
+ $awardMilestone('ap', 1, 10, 12, 't13'); // top10 attackers
+ // Defenders milestones
+ $awardMilestone('dp', 2, 3, 7, 't14');
+ $awardMilestone('dp', 2, 10, 13, 't15');
+ // Climbers milestones
+ $awardMilestone('Rc', 3, 3, 8, 't10');
+ $awardMilestone('Rc', 3, 10, 14, 't11');
+ // Rank climbers milestones
+ $awardMilestone('clp', 10, 3, 11, 't20');
+ $awardMilestone('clp', 10, 10, 16, 't21');
+ // Robbers milestones
+ $awardMilestone('RR', 4, 3, 9, 't16');
+ $awardMilestone('RR', 4, 10, 15, 't17');
+
+ // --- Reset weekly stats for eligible users ---
+ $ids = [];
+ $res = mysqli_query($database->dblink, "SELECT id FROM ".TB_PREFIX."users WHERE $userFilter");
+ while ($r = mysqli_fetch_row($res)) { $ids[] = (int)$r[0]; }
+ if ($ids) {
+ mysqli_query($database->dblink, "UPDATE ".TB_PREFIX."users SET ap=0, dp=0, Rc=0, clp=0, RR=0 WHERE id IN(".implode(',', $ids).")");
+ }
+
+ // --- Alliance medals (no user filter needed) ---
+ $insertAlly = function($allyid, $cat, $place, $week, $points, $img) use ($database) {
+ $q = "INSERT INTO ".TB_PREFIX."allimedal (allyid, categorie, plaats, week, points, img) VALUES (".(int)$allyid.", '".(int)$cat."', ".(int)$place.", '".(int)$week."', '".mysqli_real_escape_string($database->dblink, $points)."', '".mysqli_real_escape_string($database->dblink, $img)."')";
+ mysqli_query($database->dblink, $q);
+ };
+
+ $allyCats = [
+ ['ap', 1, 'a2_'],
+ ['dp', 2, 'a3_'],
+ ['RR', 4, 'a4_'],
+ ['clp', 3, 'a1_']
+ ];
+ foreach ($allyCats as [$field, $cat, $img]) {
+ $res = mysqli_query($database->dblink, "SELECT id, $field FROM ".TB_PREFIX."alidata ORDER BY $field DESC, id DESC LIMIT 10");
+ $i = 0;
+ while ($r = mysqli_fetch_array($res)) { $i++; $insertAlly($r['id'], $cat, $i, $allyweek, $r[$field], $img.$i); }
+ }
+
+ // Alliance bonus for attack+defense
+ $resA = mysqli_query($database->dblink, "SELECT id FROM ".TB_PREFIX."alidata ORDER BY ap DESC, id DESC LIMIT 10");
+ while ($a = mysqli_fetch_array($resA)) {
+ $resD = mysqli_query($database->dblink, "SELECT id FROM ".TB_PREFIX."alidata ORDER BY dp DESC, id DESC LIMIT 10");
+ while ($d = mysqli_fetch_array($resD)) {
+ if ($a['id'] == $d['id']) {
+ $cnt = mysqli_fetch_row(mysqli_query($database->dblink, "SELECT COUNT(*) FROM ".TB_PREFIX."allimedal WHERE allyid=".(int)$a['id']." AND categorie=5"))[0];
+ if ($cnt <= 2) {
+ $texts = [0 => '', 1 => 'twice ', 2 => 'three times '];
+ $insertAlly($a['id'], 5, 0, $allyweek, $texts[$cnt], 't22'.$cnt.'_1');
+ }
+ }
+ }
+ }
+
+ // Reset alliance stats
+ $aliIds = [];
+ $res = mysqli_query($database->dblink, "SELECT id FROM ".TB_PREFIX."alidata");
+ while ($r = mysqli_fetch_row($res)) { $aliIds[] = (int)$r[0]; }
+ if ($aliIds) {
+ mysqli_query($database->dblink, "UPDATE ".TB_PREFIX."alidata SET ap=0, dp=0, RR=0, clp=0 WHERE id IN(".implode(',', $aliIds).")");
+ }
+
+ // --- Update last awarded time ---
+ $database->query("UPDATE ".TB_PREFIX."config SET lastgavemedal=".(int)$time);
+}
+
private function artefactOfTheFool() {
global $database;
@@ -4777,4 +4421,4 @@ $automation = new Automation;
// remove automation lock file
@unlink( AUTOMATION_LOCK_FILE_NAME );
-?>
\ No newline at end of file
+?>
diff --git a/GameEngine/Database.php b/GameEngine/Database.php
index e4d56836..6f0fd0e2 100755
--- a/GameEngine/Database.php
+++ b/GameEngine/Database.php
@@ -8286,25 +8286,25 @@ $q = "INSERT INTO ".TB_PREFIX."demolition VALUES (
$result = $result[0];
}
self::$prisonersCache[$wid[0].$mode] = (count($result) ? [$result] : []);
- } else {
- if ($result && count($result)) {
- if (!isset(self::$prisonersCache[$record[($mode ? 'from' : 'wref')].$mode])) {
- self::$prisonersCache[$record[($mode ? 'from' : 'wref' )].$mode] = [];
- }
-
- foreach ($result as $record) {
- self::$prisonersCache[$record[($mode ? 'from' : 'wref')].$mode][] = $record;
- }
- }
-
- // check for any missing IDs and fill them in with blanks,
- // since no reinforcements were found for these villages
- foreach ($wid as $key) {
- if (!isset(self::$prisonersCache[$key.$mode])) {
- self::$prisonersCache[$key.$mode] = [];
- }
+ } else {
+ if ($result && count($result)) {
+ foreach ($result as $record) {
+ $key = $record[($mode ? 'from' : 'wref')] . $mode;
+ if (!isset(self::$prisonersCache[$key])) {
+ self::$prisonersCache[$key] = [];
}
+ self::$prisonersCache[$key][] = $record;
}
+ }
+
+ // check for any missing IDs and fill them in with blanks,
+ // since no prisoners were found for these villages
+ foreach ($wid as $key) {
+ if (!isset(self::$prisonersCache[$key.$mode])) {
+ self::$prisonersCache[$key.$mode] = [];
+ }
+ }
+}
return ($array_passed ? self::$prisonersCache : self::$prisonersCache[$wid[0].$mode]);
}
@@ -8342,19 +8342,19 @@ $q = "INSERT INTO ".TB_PREFIX."demolition VALUES (
}
function getPrisoners3($from, $use_cache = true) {
- list($from) = $this->escape_input((int) $from);
-
- // first of all, check if we should be using cache and whether the field
- // required is already cached
- if ($use_cache && ($cachedValue = self::returnCachedContent(self::$prisonersCacheByVillageAndFromIDs, $from)) && !is_null($cachedValue)) {
- return $cachedValue;
- }
-
- $q = "SELECT * FROM " . TB_PREFIX . "prisoners where " . TB_PREFIX . "prisoners.from = $from";
- $result = mysqli_query($this->dblink,$q);
-
- self::$prisonersCacheByVillageAndFromIDs[$wid.$from] = $this->mysqli_fetch_all($result);
- return self::$prisonersCacheByVillageAndFromIDs[$from];
+ list($from) = $this->escape_input((int) $from);
+
+ // first of all, check if we should be using cache and whether the field
+ // required is already cached
+ if ($use_cache && ($cachedValue = self::returnCachedContent(self::$prisonersCacheByVillageAndFromIDs, $from)) && !is_null($cachedValue)) {
+ return $cachedValue;
+ }
+
+ $q = "SELECT * FROM " . TB_PREFIX . "prisoners where " . TB_PREFIX . "prisoners.from = $from";
+ $result = mysqli_query($this->dblink,$q);
+
+ self::$prisonersCacheByVillageAndFromIDs[$from] = $this->mysqli_fetch_all($result); // FIX: scos $wid
+ return self::$prisonersCacheByVillageAndFromIDs[$from];
}
function deletePrisoners($id) {
diff --git a/GameEngine/Session.php b/GameEngine/Session.php
index 095f4e73..9a520eeb 100755
--- a/GameEngine/Session.php
+++ b/GameEngine/Session.php
@@ -63,7 +63,7 @@ include_once("Profile.php");
class Session {
private $time;
-
+ private $populated = false;
var $logged_in = false;
var $referrer, $url;
var $username, $uid, $access, $plus, $tribe, $isAdmin, $alliance, $gold, $oldrank, $gpack, $goldclub;
@@ -83,7 +83,10 @@ class Session {
private $userarray = [];
var $villages = [];
-
+ var $sit;
+ var $sit1;
+ var $sit2;
+ var $cp;
function __construct() {
global $database;
diff --git a/GameEngine/Technology.php b/GameEngine/Technology.php
index cd876129..2a96b2d0 100755
--- a/GameEngine/Technology.php
+++ b/GameEngine/Technology.php
@@ -155,7 +155,7 @@ class Technology {
array_push($listarray,$train);
}
if($type == 8 && in_array($train['unit'],$trapper)) {
- $train['name'] = $this->unarray[$train['unit']];
+ $train['name'] = $this->unarray[$train['unit']]?? 'Trap';
array_push($listarray,$train);
}
}
@@ -512,7 +512,7 @@ class Technology {
if($this->maxUnit($unit, $great) < $amt) $amt = 0;
}else{
$trainlist = $this->getTrainingList(8);
-
+ $train_amt = 0;
foreach($trainlist as $train) $train_amt += $train['amt'];
$max = 0;
diff --git a/GameEngine/Units.php b/GameEngine/Units.php
index 0c16dc16..ad4219c3 100755
--- a/GameEngine/Units.php
+++ b/GameEngine/Units.php
@@ -10,8 +10,8 @@
## ##
## License: TravianZ Project ##
## Copyright: TravianZ (c) 2010-2026. All rights reserved. ##
-## URLs: https://travianz.org ##
-## https://github.com/Shadowss/TravianZ ##
+## URLs: https://travianz.org ##
+## https://github.com/Shadowss/TravianZ ##
## ##
#################################################################################
@@ -150,6 +150,7 @@ class Units {
if($post['c'] < 2 || $post['c'] > 4) return "Invalid attack type.";
//check if at least one troops has been selected
+ $selectedTroops = 0;
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";
@@ -266,9 +267,9 @@ 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['type'] != 1 && $post['spy'] != 0) $post['spy'] = 0;
+ 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; else $post['spy'] = $post['spy']?? 0;
if($form->returnErrors() > 0){
$_SESSION['errorarray'] = $form->getErrors();
diff --git a/GameEngine/Village.php b/GameEngine/Village.php
index 6e4f132d..ca50db21 100755
--- a/GameEngine/Village.php
+++ b/GameEngine/Village.php
@@ -29,7 +29,12 @@ class Village {
public $wid, $vname, $capital, $natar, $master;
public $resarray = [];
public $unitarray, $techarray, $unitall, $researching, $abarray = [];
-
+ public $enforcetome = [];
+ public $enforcetoyou = [];
+ public $enforceoasis = [];
+ public $currentcel = 0;
+ public $allcrop = 0;
+ public $loyalty = 0;
private $infoarray = [];
private $production = [];
private $oasisowned, $ocounter = [];
diff --git a/Templates/Map/mapview.tpl b/Templates/Map/mapview.tpl
index 5536352f..d8e44e87 100644
--- a/Templates/Map/mapview.tpl
+++ b/Templates/Map/mapview.tpl
@@ -244,9 +244,9 @@ while ($donnees = mysqli_fetch_assoc($result2)) {
$sessionAlliance = (int)$session->alliance;
- $allyCache = $database->getAllianceAlly($sessionAlliance, 1);
- $warCache = $database->getAllianceWar2($sessionAlliance);
- $neutralCache = $database->getAllianceAlly($sessionAlliance, 2);
+ $allyCache = $database->getAllianceAlly($sessionAlliance, 1)?: [];
+ $warCache = $database->getAllianceWar2($sessionAlliance)?: [];
+ $neutralCache = $database->getAllianceAlly($sessionAlliance, 2)?: [];
$target = (int)$donnees["aliance_id"];
@@ -254,17 +254,19 @@ while ($donnees = mysqli_fetch_assoc($result2)) {
RELATION STATUS
========================= */
- $friend = ($target && $sessionAlliance) ? (
- ($allyCache[0]['alli1'] == $target || $allyCache[0]['alli2'] == $target)
- ) : 0;
+ $friend = $war = $neutral = 0;
- $war = ($target && $sessionAlliance) ? (
- ($warCache[0]['alli1'] == $target || $warCache[0]['alli2'] == $target)
- ) : 0;
-
- $neutral = ($target && $sessionAlliance) ? (
- ($neutralCache[0]['alli1'] == $target || $neutralCache[0]['alli2'] == $target)
- ) : 0;
+ if ($target && $sessionAlliance) {
+ foreach ($allyCache as $ac) {
+ if ((($ac['alli1']?? 0) == $target) || (($ac['alli2']?? 0) == $target)) { $friend = 1; break; }
+ }
+ foreach ($warCache as $wc) {
+ if ((($wc['alli1']?? 0) == $target) || (($wc['alli2']?? 0) == $target)) { $war = 1; break; }
+ }
+ foreach ($neutralCache as $nc) {
+ if ((($nc['alli1']?? 0) == $target) || (($nc['alli2']?? 0) == $target)) { $neutral = 1; break; }
+ }
+ }
/* =========================
IMAGE DECISION (UNCHANGED)
diff --git a/Templates/Map/mapviewlarge.tpl b/Templates/Map/mapviewlarge.tpl
index b727c22d..030e563d 100644
--- a/Templates/Map/mapviewlarge.tpl
+++ b/Templates/Map/mapviewlarge.tpl
@@ -384,9 +384,9 @@ while ($donnees = mysqli_fetch_assoc($result2)) {
$sessionAlliance = (int)$session->alliance;
- $allyCache = $database->getAllianceAlly($sessionAlliance, 1);
- $warCache = $database->getAllianceWar2($sessionAlliance);
- $neutralCache = $database->getAllianceAlly($sessionAlliance, 2);
+ $allyCache = $database->getAllianceAlly($sessionAlliance, 1)?: [];
+ $warCache = $database->getAllianceWar2($sessionAlliance)?: [];
+ $neutralCache = $database->getAllianceAlly($sessionAlliance, 2)?: [];
$target = (int)$donnees["aliance_id"];
@@ -394,18 +394,19 @@ while ($donnees = mysqli_fetch_assoc($result2)) {
RELATION STATUS
========================= */
- $friend = ($target && $sessionAlliance) ? (
- ($allyCache[0]['alli1'] == $target || $allyCache[0]['alli2'] == $target)
- ) : 0;
-
- $war = ($target && $sessionAlliance) ? (
- ($warCache[0]['alli1'] == $target || $warCache[0]['alli2'] == $target)
- ) : 0;
-
- $neutral = ($target && $sessionAlliance) ? (
- ($neutralCache[0]['alli1'] == $target || $neutralCache[0]['alli2'] == $target)
- ) : 0;
+ $friend = $war = $neutral = 0;
+ if ($target && $sessionAlliance) {
+ foreach ($allyCache as $ac) {
+ if ((($ac['alli1']?? 0) == $target) || (($ac['alli2']?? 0) == $target)) { $friend = 1; break; }
+ }
+ foreach ($warCache as $wc) {
+ if ((($wc['alli1']?? 0) == $target) || (($wc['alli2']?? 0) == $target)) { $war = 1; break; }
+ }
+ foreach ($neutralCache as $nc) {
+ if ((($nc['alli1']?? 0) == $target) || (($nc['alli2']?? 0) == $target)) { $neutral = 1; break; }
+ }
+ }
/* =========================
IMAGE DECISION
diff --git a/Templates/a2b/attack.tpl b/Templates/a2b/attack.tpl
index 257cda58..34c7b09e 100644
--- a/Templates/a2b/attack.tpl
+++ b/Templates/a2b/attack.tpl
@@ -13,7 +13,7 @@ $ckey = $generator->generateRandStr(6);
if (!isset($process['t10']) || $process['t10'] == ''){ $t10 = 0; }else{ $t10 = $process['t10']; }
if (!isset($process['t11']) || $process['t11'] == ''){ $t11 = 0; }else{ $t11 = $process['t11']; $showhero=1; }
-
+$totalunits = 0;
for($i = 1; $i <= 11; $i++){
$totalunits += (($i != 3 && $session->tribe == 3) ||
($i != 4 && $session->tribe != 3)) ? (!empty($process['t'.$i]) ? $process['t'.$i] : 0) : 0;