diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index b719f2cb..a75e726f 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -357,44 +357,61 @@ class Automation { $needVillage = $database->getVillagesID($need['uid']); foreach($needVillage as $village) { $village = (int) $village; + $q = "DELETE FROM ".TB_PREFIX."abdata where vref = ".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."bdata where wid = ".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."enforcement where `from` = ".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."fdata where vref = ".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."market where vref = ".$village; $database->query($q); + $q = "UPDATE ".TB_PREFIX."odata SET conqured = 0, loyalty = 100, owner = 2, name = 'Unoccupied Oasis' where wref = ".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."research where vref = ".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."tdata where vref = ".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."training where vref =".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."units where vref =".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."farmlist where wref =".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."raidlist where towref = ".$village; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."vdata where wref = ".$village; $database->query($q); + $q = "UPDATE ".TB_PREFIX."wdata set occupied = 0 where id = ".$village; $database->query($q); $getmovement = $database->getMovement(3,$village,1); + foreach($getmovement as $movedata) { $time = microtime(true); $time2 = $time - $movedata['starttime']; $database->addMovement(4,$movedata['to'],$movedata['from'],$movedata['ref'],$time,$time+$time2); $database->setMovementProc($movedata['moveid']); } + $q = "DELETE FROM ".TB_PREFIX."movement where proc = 0 AND ((`to` = $village AND sort_type=4) OR (`from` = $village AND sort_type=3))"; $database->query($q); $getprisoners = $database->getPrisoners($village); + foreach($getprisoners as $pris) { $troops = 0; for($i=1;$i<12;$i++){ @@ -403,7 +420,9 @@ class Automation { $database->modifyUnit($pris['wref'],array("99o"),array($troops),array(0)); $database->deletePrisoners($pris['id']); } + $getprisoners = $database->getPrisoners3($village); + foreach($getprisoners as $pris) { $troops = 0; for($i=1;$i<12;$i++){ @@ -412,7 +431,9 @@ class Automation { $database->modifyUnit($pris['wref'],array("99o"),array($troops),array(0)); $database->deletePrisoners($pris['id']); } + $enforcement = $database->getEnforceVillage($village,0); + foreach($enforcement as $enforce) { $time = microtime(true); $fromcoor = $database->getCoor($enforce['vref']); @@ -431,6 +452,7 @@ class Automation { $database->query($q); } } + for($i=0;$i<20;$i++){ $q = "SELECT id FROM ".TB_PREFIX."users where friend".$i." = ".(int) $need['uid']." or friend".$i."wait = ".(int) $need['uid'].""; $array = $database->query_return($q); @@ -439,7 +461,9 @@ class Automation { $database->deleteFriend($friend['id'],"friend".$i."wait"); } } + $database->updateUserField($need['uid'], 'alliance', 0, 1); + if($database->isAllianceOwner($need['uid'])){ $alliance = $database->getUserAllianceID($need['uid']); $newowner = $database->getAllMember2($alliance); @@ -449,17 +473,23 @@ class Automation { $database->updateAlliPermissions($newleader, $alliance, "Leader", 1, 1, 1, 1, 1, 1, 1); Automation::updateMax($newleader); } + if (isset($alliance)) { $database->deleteAlliance($alliance); } + $q = "DELETE FROM ".TB_PREFIX."hero where uid = ".(int) $need['uid']; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."mdata where target = ".(int) $need['uid']." or owner = ".(int) $need['uid']; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."ndata where uid = ".(int) $need['uid']; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."users where id = ".(int) $need['uid']; $database->query($q); + $q = "DELETE FROM ".TB_PREFIX."deleting where uid = ".(int) $need['uid']; $database->query($q); } @@ -904,7 +934,6 @@ class Automation { $q = "SELECT `from`, wood, clay, iron, crop, wid, deliveries, id FROM ".TB_PREFIX."route where timestamp < $time"; $dataarray = $database->query_return($q); foreach($dataarray as $data) { - $database->modifyResource($data['from'],$data['wood'],$data['clay'],$data['iron'],$data['crop'],0); $targettribe = $database->getUserField($database->getVillageField($data['from'],"owner"),"tribe",0); $this->sendResource2($data['wood'],$data['clay'],$data['iron'],$data['crop'],$data['from'],$data['wid'],$targettribe,$data['deliveries']); $database->editTradeRoute($data['id'],"timestamp",86400,1); @@ -949,6 +978,7 @@ class Automation { $database->addMovement(2,$data['to'],$data['from'],$data['merchant'],time(),$endtime,$data['send'],$data['wood'],$data['clay'],$data['iron'],$data['crop']); $database->setMovementProc($data['moveid']); } + $q1 = "SELECT send, moveid, `to`, wood, clay, iron, crop, `from` FROM ".TB_PREFIX."movement WHERE proc = 0 and sort_type = 2 and endtime < $time"; $dataarray1 = $database->query_return($q1); foreach($dataarray1 as $data1) { @@ -967,24 +997,30 @@ class Automation { private function sendResource2($wtrans,$ctrans,$itrans,$crtrans,$from,$to,$tribe,$send) { global $bid17,$bid28,$database,$generator,$logging; + $availableWood = $database->getWoodAvailable($from); $availableClay = $database->getClayAvailable($from); $availableIron = $database->getIronAvailable($from); $availableCrop = $database->getCropAvailable($from); + if($availableWood >= $wtrans AND $availableClay >= $ctrans AND $availableIron >= $itrans AND $availableCrop >= $crtrans){ $merchant2 = ($this->getTypeLevel(17,$from) > 0)? $this->getTypeLevel(17,$from) : 0; - $used2 = $database->totalMerchantUsed($from); + $used2 = $database->totalMerchantUsed($from, false); $merchantAvail2 = $merchant2 - $used2; $maxcarry2 = ($tribe == 1)? 500 : (($tribe == 2)? 1000 : 750); $maxcarry2 *= TRADER_CAPACITY; + if($this->getTypeLevel(28,$from) != 0) { $maxcarry2 *= $bid28[$this->getTypeLevel(28,$from)]['attri'] / 100; } + $resource = array($wtrans,$ctrans,$itrans,$crtrans); $reqMerc = ceil((array_sum($resource)-0.1)/$maxcarry2); + if($merchantAvail2 != 0 && $reqMerc <= $merchantAvail2) { $coor = $database->getCoor($to); $coor2 = $database->getCoor($from); + if($database->getVillageState($to)) { $timetaken = $generator->procDistanceTime($coor,$coor2,$tribe,0); $res = $resource[0]+$resource[1]+$resource[2]+$resource[3]; @@ -994,6 +1030,7 @@ class Automation { $database->addMovement(0,$from,$to,$reference,microtime(true),microtime(true)+$timetaken,$send); } } + } } } @@ -2685,24 +2722,36 @@ class Automation { if($type == 3 && $totalsend_att - ($totaldead_att+$totaltraped_att) > 0){ $prisoners = $database->getPrisoners($to['wref'], 0, false); if(count($prisoners) > 0){ + $anothertroops = 0; $mytroops=0; - foreach($prisoners as $prisoner){ + $prisoners2delete = []; + $movementType = []; + $movementFrom = []; + $movementTo = []; + $movementRef = []; + $movementTime = []; + $movementEndtime = []; + $utime = microtime(true); + + foreach($prisoners as $prisoner) { $p_owner = $database->getVillageField($prisoner['from'],"owner"); - if($p_owner == $from['owner']){ + + if ($p_owner == $from['owner']) { $database->modifyAttack2( $data['ref'], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [$prisoner['t1'], $prisoner['t2'], $prisoner['t3'], $prisoner['t4'], $prisoner['t5'], $prisoner['t6'], $prisoner['t7'], $prisoner['t8'], $prisoner['t9'], $prisoner['t10'], $prisoner['t11']] ); $mytroops += $prisoner['t1']+$prisoner['t2']+$prisoner['t3']+$prisoner['t4']+$prisoner['t5']+$prisoner['t6']+$prisoner['t7']+$prisoner['t8']+$prisoner['t9']+$prisoner['t10']+$prisoner['t11']; - $database->deletePrisoners($prisoner['id']); - }else{ + $prisoners2delete[] = $prisoner['id']; + } else { $p_alliance = $database->getUserField($p_owner,"alliance",0); $friendarray = $database->getAllianceAlly($p_alliance,1); $neutralarray = $database->getAllianceAlly($p_alliance,2); $friend = (($friendarray[0]['alli1']>0 and $friendarray[0]['alli2']>0 and $p_alliance>0) and ($friendarray[0]['alli1']==$ownally or $friendarray[0]['alli2']==$ownally) and ($ownally != $p_alliance and $ownally and $p_alliance)) ? '1':'0'; $neutral = (($neutralarray[0]['alli1']>0 and $neutralarray[0]['alli2']>0 and $p_alliance>0) and ($neutralarray[0]['alli1']==$ownally or $neutralarray[0]['alli2']==$ownally) and ($ownally != $p_alliance and $ownally and $p_alliance)) ? '1':'0'; + if($p_alliance == $ownally or $friend == 1 or $neutral == 1){ $p_tribe = $database->getUserField($p_owner,"tribe",0); @@ -2755,13 +2804,24 @@ class Automation { } } $p_reference = $database->addAttack($prisoner['from'],$prisoner['t1'],$prisoner['t2'],$prisoner['t3'],$prisoner['t4'],$prisoner['t5'],$prisoner['t6'],$prisoner['t7'],$prisoner['t8'],$prisoner['t9'],$prisoner['t10'],$prisoner['t11'],3,0,0,0,0,0,0,0,0,0,0,0); - $database->addMovement(4,$prisoner['wref'],$prisoner['from'],$p_reference,microtime(true),($p_time+microtime(true))); + $movementType[] = 4; + $movementFrom[] = $prisoner['wref']; + $movementTo[] = $prisoner['from']; + $movementRef[] = $p_reference; + $movementTime[] = $utime; + $movementEndtime[] = $p_time + $utime; $anothertroops += $prisoner['t1']+$prisoner['t2']+$prisoner['t3']+$prisoner['t4']+$prisoner['t5']+$prisoner['t6']+$prisoner['t7']+$prisoner['t8']+$prisoner['t9']+$prisoner['t10']+$prisoner['t11']; - $database->deletePrisoners($prisoner['id']); + $prisoners2delete[] = $prisoner['id']; } } } + if (count($movementType)) { + $database->addMovement( $movementType, $movementFrom, $movementTo, $movementRef, $movementTime, $movementEndtime ); + } + + $database->deletePrisoners($prisoners2delete); + $newtraps = round(($mytroops+$anothertroops)/3); $database->modifyUnit( $data['to'], @@ -3301,6 +3361,7 @@ class Automation { $targettribe = $database->getUserField($DefenderID,"tribe",0); $conqureby=$toF['conqured']; } + if($data['from']==0){ $DefenderID = $database->getVillageField($data['to'],"owner"); if (isset($AttackerID) && $session->uid==$AttackerID || $session->uid==$DefenderID) $reload=true; diff --git a/GameEngine/Database.php b/GameEngine/Database.php index fd9e6a60..1b7105a7 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -2976,41 +2976,17 @@ class MYSQLi_DB implements IDbConnection { function modifyResource($vid, $wood, $clay, $iron, $crop, $mode) { list($vid, $wood, $clay, $iron, $crop, $mode) = $this->escape_input((int) $vid, (int) $wood, (int) $clay, (int) $iron, (int) $crop, $mode); + $sign = (!$mode ? '-' : '+'); - $shit = false; - $q = "SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "vdata where wref = ".$vid; - $result = mysqli_query($this->dblink,$q); - $checkres = $this->mysqli_fetch_all($result); - - if(!$mode){ - $nwood = $checkres[0]['wood'] - $wood; - $nclay = $checkres[0]['clay'] - $clay; - $niron = $checkres[0]['iron'] - $iron; - $ncrop = $checkres[0]['crop'] - $crop; - if ( $nwood < 0 or $nclay < 0 or $niron < 0 or $ncrop < 0 ) { - $shit = true; - } - $dwood = ( $nwood < 0 ) ? 0 : $nwood; - $dclay = ( $nclay < 0 ) ? 0 : $nclay; - $diron = ( $niron < 0 ) ? 0 : $niron; - $dcrop = ( $ncrop < 0 ) ? 0 : $ncrop; - } else { - $nwood=$checkres[0]['wood']+$wood; - $nclay=$checkres[0]['clay']+$clay; - $niron=$checkres[0]['iron']+$iron; - $ncrop=$checkres[0]['crop']+$crop; - $dwood=($nwood>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nwood; - $dclay=($nclay>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nclay; - $diron=($niron>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$niron; - $dcrop=($ncrop>$checkres[0]['maxcrop'])?$checkres[0]['maxcrop']:$ncrop; - } - - if ( ! $shit ) { - $q = "UPDATE " . TB_PREFIX . "vdata set wood = $dwood, clay = $dclay, iron = $diron, crop = $dcrop where wref = " . $vid; - return mysqli_query( $this->dblink, $q ); - } else { - return false; - } + return mysqli_query( $this->dblink, " + UPDATE " . TB_PREFIX . "vdata + SET + wood = IF(wood $sign $wood > 0 AND wood $sign $wood < maxstore, wood $sign $wood, ".($mode ? 'maxstore' : '0')."), + clay = IF(clay $sign $clay > 0 AND clay $sign $clay < maxstore, clay $sign $clay, ".($mode ? 'maxstore' : '0')."), + iron = IF(iron $sign $iron > 0 AND iron $sign $iron < maxstore, iron $sign $iron, ".($mode ? 'maxstore' : '0')."), + crop = IF(crop $sign $crop > 0 AND crop $sign $crop < maxcrop, crop $sign $crop, ".($mode ? 'maxcrop' : '0').") + WHERE + wref = " . $vid ); } function setMaxStoreForVillage($vid, $maxLevel) { @@ -4981,11 +4957,48 @@ class MYSQLi_DB implements IDbConnection { } function addAttack($vid, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $type, $ctar1, $ctar2, $spy,$b1=0,$b2=0,$b3=0,$b4=0,$b5=0,$b6=0,$b7=0,$b8=0) { - list($vid, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $type, $ctar1, $ctar2, $spy,$b1,$b2,$b3,$b4,$b5,$b6,$b7,$b8) = $this->escape_input((int) $vid, (int) $t1, (int) $t2, (int) $t3, (int) $t4, (int) $t5, (int) $t6, (int) $t7, (int) $t8, (int) $t9, (int) $t10, (int) $t11, (int) $type, (int) $ctar1, (int) $ctar2, (int) $spy,(int) $b1,(int) $b2,(int) $b3,(int) $b4,(int) $b5,(int) $b6,(int) $b7,(int) $b8); + if (!is_array($vid)) { + $vid = [$vid]; + $t1 = [$t1]; + $t2 = [$t2]; + $t3 = [$t3]; + $t4 = [$t4]; + $t5 = [$t5]; + $t6 = [$t6]; + $t7 = [$t7]; + $t8 = [$t8]; + $t9 = [$t9]; + $t10 = [$t10]; + $t11 = [$t11]; + $type = [$type]; + $ctar1 = [$ctar1]; + $ctar2 = [$ctar1]; + $spy = [$spy]; + $b1 = [$b1]; + $b2 = [$b2]; + $b3 = [$b3]; + $b4 = [$b4]; + $b5 = [$b5]; + $b6 = [$b6]; + $b7 = [$b7]; + $b8 = [$b8]; + } - $q = "INSERT INTO " . TB_PREFIX . "attacks values (0,$vid,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11,$type,$ctar1,$ctar2,$spy,$b1,$b2,$b3,$b4,$b5,$b6,$b7,$b8)"; + $values = []; + foreach ($vid as $index => $vidValue) { + $values[] = '(0, '.(int) $vidValue.', '.(int) $t1[$index].', '.(int) $t2[$index].', '.(int) $t3[$index].', '. + (int) $t4[$index].', '.(int) $t5[$index].', '.(int) $t6[$index].', '.(int) $t7[$index].', '. + (int) $t8[$index].', '.(int) $t9[$index].', '.(int) $t10[$index].', '.(int) $t11[$index]. + ', '.(int) $type[$index].', '.(int) $ctar1[$index].', '.(int) $ctar2[$index].', '. + (int) $spy[$index].', '.(int) $b1[$index].', '.(int) $b2[$index].', '.(int) $b3[$index]. + ', '.(int) $b4[$index].', '.(int) $b5[$index].', '.(int) $b6[$index].', '.(int) $b7[$index]. + ', '.(int) $b8[$index].')'; + } + + $q = "INSERT INTO " . TB_PREFIX . "attacks VALUES ".implode(', ', $values); mysqli_query($this->dblink,$q); - return mysqli_insert_id($this->dblink); + + return (count($vid) == 1 ? mysqli_insert_id($this->dblink) : true); } function modifyAttack($aid, $unit, $amt) { @@ -4997,7 +5010,7 @@ class MYSQLi_DB implements IDbConnection { } function modifyAttack2($aid, $unit, $amt) { - list($aid, $unit, $amt) = $this->escape_input((int) $aid, $unit, (int) $amt); + list($aid, $unit, $amt) = $this->escape_input((int) $aid, $unit, $amt); if (!is_array($unit)) { $unit = [$unit]; @@ -6554,9 +6567,15 @@ class MYSQLi_DB implements IDbConnection { } function deletePrisoners($id) { - list($id) = $this->escape_input($id); + if (!is_array($id)) { + $id = [$id]; + } - $q = "DELETE from " . TB_PREFIX . "prisoners where id = '$id'"; + foreach ($id as $index => $idValue) { + $id[$index] = (int) $idValue; + } + + $q = "DELETE FROM " . TB_PREFIX . "prisoners WHERE id IN(".implode(', ', $id).")"; mysqli_query($this->dblink,$q); } diff --git a/create_account.php b/create_account.php index ec94b1b2..c86e2c3e 100644 --- a/create_account.php +++ b/create_account.php @@ -196,12 +196,50 @@ if(isset($_POST['password']) && $_POST['password'] != ""){ $multiplier = NATARS_UNITS; $q = "SELECT * FROM " . TB_PREFIX . "vdata WHERE capital = '1' and owner > '5'"; $array = $database->query_return($q); - $sendspytroops = 1500 * $multiplier; + $sendspytroops = 1500 * $multiplier; + $refs = []; + $vils = []; foreach($array as $vill){ - $ref = $database->addAttack($natar['wref'], 0, 0, 0, $sendspytroops, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 0); - $database->addMovement(3, $natar['wref'], $vill['wref'], $ref, time(), time()+10000); + $refs[] = $database->addAttack($natar['wref'], 0, 0, 0, $sendspytroops, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 0); + $vils[] = $vill['wref']; } + $type = []; + $from = []; + $to = []; + $ref = []; + $time = []; + $timeValue = time(); + $endtime = []; + $endtimeValue = $timeValue + 10000; + $counter = 0; + + foreach ($refs as $index => $refID) { + $type[] = 3; + $from[] = $natar['wref']; + $to[] = $vils[$index]; + $ref[] = $refID; + $time[] = $timeValue; + $endtime[] = $endtimeValue; + + // limit the insert, so it can push through any reasonable network limits imposed + if (++$counter > 25) { + $database->addMovement($type, $from, $to, $ref, $time, $endtime); + + $type = []; + $from = []; + $to = []; + $ref = []; + $time = []; + $endtime = []; + $counter = 0; + } + } + + if ($counter > 0) { + $database->addMovement( $type, $from, $to, $ref, $time, $endtime ); + } + /** * SMALL ARTEFACTS */ diff --git a/winner.php b/winner.php index c16f3e95..3af3375b 100644 --- a/winner.php +++ b/winner.php @@ -41,10 +41,14 @@ if(isset($_GET['newdid'])) { else { $building->procBuild($_GET); } + $sql = mysqli_query($GLOBALS['link'],"SELECT vref FROM ".TB_PREFIX."fdata WHERE f99 = '100' and f99t = '40'"); + $winner = mysqli_num_rows($sql); -## Get Rankings for Ranking Section + if($winner!=0){ + + ## Get Rankings for Ranking Section ## Top 3 Population -$q = " + $q = " SELECT ".TB_PREFIX."users.id userid, ".TB_PREFIX."users.username username,".TB_PREFIX."users.alliance alliance, ( SELECT SUM( ".TB_PREFIX."vdata.pop ) FROM ".TB_PREFIX."vdata @@ -63,22 +67,22 @@ $q = " WHERE " . TB_PREFIX . "users.access < " . (INCLUDE_ADMIN ? "10" : "8") . " ORDER BY totalpop DESC, totalvillages DESC, username ASC"; - $result = (mysqli_query($GLOBALS['link'],$q)); - while($row = mysqli_fetch_assoc($result)) - { - $datas[] = $row; - } - foreach($datas as $result) - { - $value['userid'] = $result['userid']; - $value['username'] = $result['username']; - $value['alliance'] = $result['alliance']; - $value['aname'] = $result['allitag']; - $value['totalpop'] = $result['totalpop']; - $value['totalvillage'] = $result['totalvillages']; - } - ## Top Attacker - $q = " + $result = (mysqli_query($GLOBALS['link'],$q)); + while($row = mysqli_fetch_assoc($result)) + { + $datas[] = $row; + } + foreach($datas as $result) + { + $value['userid'] = $result['userid']; + $value['username'] = $result['username']; + $value['alliance'] = $result['alliance']; + $value['aname'] = $result['allitag']; + $value['totalpop'] = $result['totalpop']; + $value['totalvillage'] = $result['totalvillages']; + } + ## Top Attacker + $q = " SELECT " . TB_PREFIX . "users.id userid, " . TB_PREFIX . "users.username username, " . TB_PREFIX . "users.apall, ( SELECT COUNT( " . TB_PREFIX . "vdata.wref ) FROM " . TB_PREFIX . "vdata @@ -92,21 +96,21 @@ $q = " WHERE " . TB_PREFIX . "users.apall >=0 AND " . TB_PREFIX . "users.access < " . (INCLUDE_ADMIN ? "10" : "8") . " AND " . TB_PREFIX . "users.tribe <= 3 ORDER BY " . TB_PREFIX . "users.apall DESC, pop DESC, username ASC"; - $result = mysqli_query($GLOBALS['link'],$q) or die(mysqli_error($database->dblink)); - while($row = mysqli_fetch_assoc($result)) - { - $attacker[] = $row; - } - foreach($attacker as $key => $row) - { - $value['username'] = $row['username']; - $value['totalvillages'] = $row['totalvillages']; - $value['id'] = $row['userid']; - $value['totalpop'] = $row['pop']; - $value['apall'] = $row['apall']; - } - ## Top Defender - $q = " + $result = mysqli_query($GLOBALS['link'],$q) or die(mysqli_error($database->dblink)); + while($row = mysqli_fetch_assoc($result)) + { + $attacker[] = $row; + } + foreach($attacker as $key => $row) + { + $value['username'] = $row['username']; + $value['totalvillages'] = $row['totalvillages']; + $value['id'] = $row['userid']; + $value['totalpop'] = $row['pop']; + $value['apall'] = $row['apall']; + } + ## Top Defender + $q = " SELECT " . TB_PREFIX . "users.id userid, " . TB_PREFIX . "users.username username, " . TB_PREFIX . "users.dpall, ( SELECT COUNT( " . TB_PREFIX . "vdata.wref ) FROM " . TB_PREFIX . "vdata @@ -119,46 +123,41 @@ $q = " FROM " . TB_PREFIX . "users WHERE " . TB_PREFIX . "users.dpall >=0 AND " . TB_PREFIX . "users.access < " . (INCLUDE_ADMIN ? "10" : "8") . " ORDER BY " . TB_PREFIX . "users.dpall DESC, pop DESC, username ASC"; - $result = mysqli_query($GLOBALS['link'],$q) or die(mysqli_error($database->dblink)); - while($row = mysqli_fetch_assoc($result)) - { - $defender[] = $row; - } - foreach($defender as $key => $row) - { - $value['username'] = $row['username']; - $value['totalvillages'] = $row['totalvillages']; - $value['id'] = $row['userid']; - $value['totalpop'] = $row['pop']; - $value['dpall'] = $row['dpall']; - } + $result = mysqli_query($GLOBALS['link'],$q) or die(mysqli_error($database->dblink)); + while($row = mysqli_fetch_assoc($result)) + { + $defender[] = $row; + } + foreach($defender as $key => $row) + { + $value['username'] = $row['username']; + $value['totalvillages'] = $row['totalvillages']; + $value['id'] = $row['userid']; + $value['totalpop'] = $row['pop']; + $value['dpall'] = $row['dpall']; + } - ## Get WW Winner Details - $sql = mysqli_query($GLOBALS['link'],"SELECT vref FROM ".TB_PREFIX."fdata WHERE f99 = '100' and f99t = '40'"); - $vref = mysqli_result($sql, 0); + ## Get WW Winner Details + $sql = mysqli_query($GLOBALS['link'],"SELECT vref FROM ".TB_PREFIX."fdata WHERE f99 = '100' and f99t = '40'"); + $vref = mysqli_result($sql, 0); - $sql = mysqli_query($GLOBALS['link'],"SELECT name FROM ".TB_PREFIX."vdata WHERE wref = '$vref'")or die(mysqli_error($database->dblink)); - $winningvillagename = mysqli_result($sql, 0); + $sql = mysqli_query($GLOBALS['link'],"SELECT name FROM ".TB_PREFIX."vdata WHERE wref = '$vref'")or die(mysqli_error($database->dblink)); + $winningvillagename = mysqli_result($sql, 0); - $sql = mysqli_query($GLOBALS['link'],"SELECT owner FROM ".TB_PREFIX."vdata WHERE wref = '$vref'")or die(mysqli_error($database->dblink)); - $owner = mysqli_result($sql, 0); + $sql = mysqli_query($GLOBALS['link'],"SELECT owner FROM ".TB_PREFIX."vdata WHERE wref = '$vref'")or die(mysqli_error($database->dblink)); + $owner = mysqli_result($sql, 0); - $sql = mysqli_query($GLOBALS['link'],"SELECT username FROM ".TB_PREFIX."users WHERE id = '$owner'")or die(mysqli_error($database->dblink)); - $username = mysqli_result($sql, 0); + $sql = mysqli_query($GLOBALS['link'],"SELECT username FROM ".TB_PREFIX."users WHERE id = '$owner'")or die(mysqli_error($database->dblink)); + $username = mysqli_result($sql, 0); - $sql = mysqli_query($GLOBALS['link'],"SELECT alliance FROM ".TB_PREFIX."users WHERE id = '$owner'")or die(mysqli_error($database->dblink)); - $allianceid = mysqli_result($sql, 0); + $sql = mysqli_query($GLOBALS['link'],"SELECT alliance FROM ".TB_PREFIX."users WHERE id = '$owner'")or die(mysqli_error($database->dblink)); + $allianceid = mysqli_result($sql, 0); - $sql = mysqli_query($GLOBALS['link'],"SELECT name, tag FROM ".TB_PREFIX."alidata WHERE id = '$allianceid'")or die(mysqli_error($database->dblink)); - $winningalliance = mysqli_result($sql, 0); + $sql = mysqli_query($GLOBALS['link'],"SELECT name, tag FROM ".TB_PREFIX."alidata WHERE id = '$allianceid'")or die(mysqli_error($database->dblink)); + $winningalliance = mysqli_result($sql, 0); - $sql = mysqli_query($GLOBALS['link'],"SELECT tag FROM ".TB_PREFIX."alidata WHERE id = '$allianceid'")or die(mysqli_error($database->dblink)); - $winningalliancetag = mysqli_result($sql, 0); - - $sql = mysqli_query($GLOBALS['link'],"SELECT vref FROM ".TB_PREFIX."fdata WHERE f99 = '100' and f99t = '40'"); - $winner = mysqli_num_rows($sql); - - if($winner!=0){ + $sql = mysqli_query($GLOBALS['link'],"SELECT tag FROM ".TB_PREFIX."alidata WHERE id = '$allianceid'")or die(mysqli_error($database->dblink)); + $winningalliancetag = mysqli_result($sql, 0); ?>