diff --git a/Admin/Templates/alliance.tpl b/Admin/Templates/alliance.tpl
index e2959060..211049a3 100644
--- a/Admin/Templates/alliance.tpl
+++ b/Admin/Templates/alliance.tpl
@@ -16,10 +16,17 @@ if($_GET['aid'])
$aliusers = $database->getAllMember($_GET['aid']);
if($alidata and $aliusers)
{
- foreach($aliusers as $member)
- {
- $totalpop += $database->getVSumField($member['id'],"pop");
- } ?>
+ $memberIDs = [];
+ foreach($aliusers as $member) {
+ $memberIDs[] = $member['id'];
+ }
+ $data = $database->getVSumField($memberIDs,"pop");
+
+ if (count($data)) {
+ foreach ($data as $row) {
+ $totalpop += $row['Total'];
+ }
+ } ?>
diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php
index 0b104ec3..8dad9cf3 100755
--- a/GameEngine/Automation.php
+++ b/GameEngine/Automation.php
@@ -5250,9 +5250,19 @@ class Automation {
$ally = $database->getAlliance($aid);
$memberlist = $database->getAllMember($ally['id']);
$oldrank = 0;
+
+ $memberIDs = [];
foreach($memberlist as $member) {
- $oldrank += $database->getVSumField($member['id'],"pop");
+ $memberIDs[] = $member['id'];
}
+ $data = $database->getVSumField($memberIDs,"pop");
+
+ if (count($data)) {
+ foreach ($data as $row) {
+ $oldrank += $row['Total'];
+ }
+ }
+
if($ally['oldrank'] != $oldrank){
if($ally['oldrank'] < $oldrank) {
$totalpoints = $oldrank - $ally['oldrank'];
diff --git a/GameEngine/Database.php b/GameEngine/Database.php
index 68f7d016..f053217d 100755
--- a/GameEngine/Database.php
+++ b/GameEngine/Database.php
@@ -1770,6 +1770,11 @@ class MYSQLi_DB implements IDbConnection {
$uid = $newIDs;
}
+ // nothing left to cache, return the full cache
+ if (!count($uid)) {
+ return self::$userVillagesCache;
+ }
+
switch ($mode) {
// by owner ID
case 0: $q = "SELECT * FROM " . TB_PREFIX . "vdata WHERE owner IN(".implode(', ', $uid).") ORDER BY capital DESC,pop DESC";
@@ -2910,9 +2915,20 @@ class MYSQLi_DB implements IDbConnection {
$ally = $this->getAlliance($aid);
$memberlist = $this->getAllMember($ally['id']);
$oldrank = 0;
- foreach($memberlist as $member) {
- $oldrank += $this->getVSumField($member['id'],"pop");
- }
+ $memberIDs = [];
+
+ foreach($memberlist as $member) {
+ $memberIDs[] = $member['id'];
+ }
+
+ $data = $this->getVSumField($memberIDs,"pop");
+
+ if (count($data)) {
+ foreach ($data as $row) {
+ $oldrank += $row['Total'];
+ }
+ }
+
if($ally['oldrank'] != $oldrank){
if($ally['oldrank'] < $oldrank) {
$totalpoints = $oldrank - $ally['oldrank'];
@@ -3824,7 +3840,7 @@ class MYSQLi_DB implements IDbConnection {
lastupdate < (UNIX_TIMESTAMP() - 600)
"; // recount every 10 minutes
- mysqli_query($this->dblink, $q) OR DIE ($q);
+ mysqli_query($this->dblink, $q);
}
function getVSumField($uid, $field, $use_cache = true) {
@@ -7038,15 +7054,38 @@ References: User ID/Message ID, Mode
// 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::$foolArtefactCache, $type.$vid.$uid)) && !is_null($cachedValue)) {
- return $cachedValue;
+ if ($use_cache && isset(self::$foolArtefactCache[$vid]) && is_array(self::$foolArtefactCache[$vid]) && !count(self::$foolArtefactCache[$vid])) {
+ return [];
+ } else if ($use_cache && ($cachedValue = self::returnCachedContent(self::$foolArtefactCache, $vid)) && !is_null($cachedValue)) {
+ $data = [];
+ // prepare the data as requested
+ if (isset($cachedValue[$type.$uid])) {
+ foreach ($cachedValue[$type.$uid] as $row) {
+ if ($row['type'] == 8 && $row['kind'] == $type && $row['owner'] == $uid && $row['size'] > 1 && $row['active'] > 1) {
+ $data[] = $row;
+ }
+ }
+ }
+ return $data;
}
- $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vid AND ((type = 8 AND kind = $type) OR (owner = $uid AND size > 1 AND active = 1 AND type = 8 AND kind = $type))";
- $result = mysqli_query($this->dblink,$q);
+ $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vid"; //" AND ((type = 8 AND kind = $type) OR (owner = $uid AND size > 1 AND active = 1 AND type = 8 AND kind = $type))";
+ $result = $this->mysqli_fetch_all(mysqli_query($this->dblink,$q));
- self::$foolArtefactCache[$type.$vid.$uid] = $this->mysqli_fetch_all($result);
- return self::$foolArtefactCache[$type.$vid.$uid];
+ // cache all types and return the requested one
+ if (count($result)) {
+ foreach ($result as $arteInfo) {
+ if (!isset(self::$foolArtefactCache[$vid][$arteInfo['type'].$arteInfo['owner']])) {
+ self::$foolArtefactCache[$vid][$arteInfo['type'].$arteInfo['owner']] = [];
+ }
+
+ self::$foolArtefactCache[$vid][$arteInfo['type'].$arteInfo['owner']][] = $arteInfo;
+ }
+ } else {
+ self::$foolArtefactCache[$vid] = [];
+ }
+
+ return (isset(self::$foolArtefactCache[$vid][$type.$uid]) ? self::$foolArtefactCache[$vid][$type.$uid] : []);
}
function claimArtefact($vref, $ovref, $id) {
diff --git a/GameEngine/Ranking.php b/GameEngine/Ranking.php
index cca81a1e..0c807229 100755
--- a/GameEngine/Ranking.php
+++ b/GameEngine/Ranking.php
@@ -27,7 +27,7 @@
$myrank = 0;
if(count($ranking) > 0) {
for($i=0;$i<($users3);$i++) {
- if( isset( $ranking[$i]['userid'] ) ) {
+ if( isset( $ranking[$i]['userid'] ) ) {
if($ranking[$i]['userid'] == $id && $ranking[$i] != "pad") {
$myrank = $i;
}
@@ -204,8 +204,8 @@
return $key;
break;
}
- }
- }
+ }
+ }
if(!next($this->rankarray)) {
if($field != "userid"){
return $name;
@@ -215,7 +215,7 @@
break;
}
}
-
+
}
}
@@ -268,7 +268,7 @@
WHERE " . TB_PREFIX . "users.access < " . (INCLUDE_ADMIN ? "10" : "8") . "
AND " . TB_PREFIX . "users.tribe <= 3
AND " . TB_PREFIX . "users.id > 5
- ORDER BY totalpop DESC, totalvillages DESC, userid DESC";
+ ORDER BY totalpop DESC, totalvillages DESC, userid DESC";
}
$result = (mysqli_query($GLOBALS['link'],$q));
@@ -474,16 +474,26 @@
}
public function procARankArray() {
- global $multisort;
+ global $multisort, $database;
$array = $GLOBALS['db']->getARanking();
$holder = array();
foreach($array as $value) {
$memberlist = $GLOBALS['db']->getAllMember($value['id']);
$totalpop = 0;
- foreach($memberlist as $member) {
- $totalpop += $GLOBALS['db']->getVSumField($member['id'], "pop");
- }
+
+ $memberIDs = [];
+ foreach($memberlist as $member) {
+ $memberIDs[] = $member['id'];
+ }
+ $data = $database->getVSumField($memberIDs,"pop");
+
+ if (count($data)) {
+ foreach ($data as $row) {
+ $totalpop += $row['Total'];
+ }
+ }
+
$value['players'] = count($memberlist);
$value['totalpop'] = $totalpop;
if(!isset($value['avg'])) {
diff --git a/Templates/Alliance/allidesc.tpl b/Templates/Alliance/allidesc.tpl
index 6cd0ca34..b5837ba6 100644
--- a/Templates/Alliance/allidesc.tpl
+++ b/Templates/Alliance/allidesc.tpl
@@ -1,17 +1,26 @@
-alliance;
-}
-$varmedal = $database->getProfileMedalAlly($aid);
+}
+$varmedal = $database->getProfileMedalAlly($aid);
$allianceinfo = $database->getAlliance($aid);
$memberlist = $database->getAllMember($aid);
$totalpop = 0;
+$memberIDs = [];
+
foreach($memberlist as $member) {
- $totalpop += $database->getVSumField($member['id'],"pop");
+ $memberIDs[] = $member['id'];
+}
+$data = $database->getVSumField($memberIDs,"pop");
+
+if (count($data)) {
+ foreach ($data as $row) {
+ $totalpop += $row['Total'];
+ }
}
echo "".$allianceinfo['tag']." - ".$allianceinfo['name']."
";
@@ -80,9 +89,9 @@ INDELING CATEGORIEEN:
== 7. in top 3 - verdediging ==
== 8. in top 3 - klimmers ==
== 9. in top 3 - overval ==
-******************************/
-
-
+******************************/
+
+
foreach($varmedal as $medal) {
$titel="Bonus";
switch ($medal['categorie']) {
@@ -122,7 +131,7 @@ INDELING CATEGORIEEN:
case "12":
$titel="Top 10 of Rank Attackers of week ".$medal['points']." in a row";
break;
- }
+ }
echo"
| ".$titel." |
".$medal['plaats']." |
diff --git a/Templates/Alliance/overview.tpl b/Templates/Alliance/overview.tpl
index 3bedaeb8..2088e9e4 100644
--- a/Templates/Alliance/overview.tpl
+++ b/Templates/Alliance/overview.tpl
@@ -5,7 +5,7 @@ $aid = $_GET['aid'];
else {
$aid = $session->alliance;
}
-$varmedal = $database->getProfileMedalAlly($aid);
+$varmedal = $database->getProfileMedalAlly($aid);
$allianceinfo = $database->getAlliance($aid);
$memberlist = $database->getAllMember($aid);
@@ -14,16 +14,25 @@ if($allianceinfo['tag']==""){
header("Location: allianz.php");
exit;
}
+$memberIDs = [];
foreach($memberlist as $member) {
- $totalpop += $database->getVSumField($member['id'],"pop");
+ $memberIDs[] = $member['id'];
}
+$data = $database->getVSumField($memberIDs,"pop");
+
+if (count($data)) {
+ foreach ($data as $row) {
+ $totalpop += $row['Total'];
+ }
+}
+
echo "".$allianceinfo['tag']." - ".$allianceinfo['name']."
";
$profiel="".$allianceinfo['notice']."".md5('skJkev3')."".$allianceinfo['desc']."";
require("medal.php");
$profiel=explode("".md5('skJkev3')."", $profiel);
-include("alli_menu.tpl");
+include("alli_menu.tpl");
?>
@@ -69,25 +78,25 @@ include("alli_menu.tpl");
getAlliancePermission($member['id'],"rank",0);
-
+
//username
$name = $database->getUserField($member['id'],"username",0);
-
+
//if there is no rank defined, user will not be printed
if($rank == ''){
echo '';
}
-
+
//if there is user rank defined, user will be printed
else if($rank != ''){
echo "";
echo "| ".stripslashes($rank)." | ";
echo "".$name." | ";
echo "
";
- }
+ }
}
if($allianceinfo['forumlink'] != '' && $allianceinfo['forumlink'] != '0'){
echo "";
@@ -115,7 +124,7 @@ include("alli_menu.tpl");
| Player |
Population |
Villages |
-alliance){
echo " | ";
}
@@ -139,31 +148,31 @@ foreach($memberlist as $member) {
$rank = $rank+1;
$TotalUserPop = $database->getVSumField($member['id'],"pop");
- $TotalVillages = $database->getProfileVillages($member['id']);
-
+ $TotalVillages = $database->getProfileVillages($member['id']);
+
echo "
";
echo " | ".$rank.". | ";
- echo " ".$member['username']." | ";
- echo " ".$TotalUserPop." | ";
+ echo " ".$member['username']." | ";
+ echo " ".$TotalUserPop." | ";
echo " ".count($TotalVillages)." | ";
-
- if($aid == $session->alliance){
+
+ if($aid == $session->alliance){
if ((time()-600) < $member['timestamp']){ // 0 Min - 10 Min
echo "  | ";
}elseif ((time()-86400) < $member['timestamp'] && (time()-600) > $member['timestamp']){ // 10 Min - 1 Days
- echo "  | ";
+ echo "  | ";
}elseif ((time()-259200) < $member['timestamp'] && (time()-86400) > $member['timestamp']){ // 1-3 Days
- echo "  | ";
+ echo "  | ";
}elseif ((time()-604800) < $member['timestamp'] && (time()-259200) > $member['timestamp']){
- echo "  | ";
+ echo "  | ";
}else{
- echo "  | ";
+ echo "  | ";
}
}
-
- echo "
";
+
+ echo " ";
}
-?>
+?>
\ No newline at end of file