diff --git a/Admin/Templates/report.tpl b/Admin/Templates/report.tpl index c9b2a04b..212f0fe8 100644 --- a/Admin/Templates/report.tpl +++ b/Admin/Templates/report.tpl @@ -11,12 +11,13 @@ include_once("../GameEngine/Generator.php"); include_once("../GameEngine/Technology.php"); include_once("../GameEngine/Message.php"); -if ($_GET['bid']){ -$rep = $database->getNotice4($_GET['bid']); -}else -$sql = "SELECT * FROM ".TB_PREFIX."ndata ORDER BY time DESC "; -$result = mysqli_query($GLOBALS["link"], $sql); -$rep1 = $database->mysqli_fetch_all($result); +if ($_GET['bid']) $rep = $database->getNotice2($_GET['bid']); +else +{ + $sql = "SELECT * FROM " . TB_PREFIX . "ndata ORDER BY time DESC "; + $result = mysqli_query($GLOBALS["link"], $sql); + $rep1 = $database->mysqli_fetch_all($result); +} if($rep1) { //$att = $database->getUserArray($rep1['uid'],1); @@ -47,13 +48,8 @@ if($rep)

Reporte

diff --git a/GameEngine/Admin/database.php b/GameEngine/Admin/database.php index 3d6c3cfd..811956b4 100755 --- a/GameEngine/Admin/database.php +++ b/GameEngine/Admin/database.php @@ -379,13 +379,12 @@ function DelVillage($wref, $mode=0){ mysqli_query($this->connection, $q); - $getmovement = $database->getMovement(3,$wref,1); - foreach($getmovement as $movedata) { + $getmovement = $database->getMovement(3, $wref, 1); + foreach($getmovement as $movedata){ $time = microtime(true); $time2 = $time - $movedata['starttime']; $database->setMovementProc($movedata['moveid']); - $database->addMovement(4,$movedata['to'],$movedata['from'],$movedata['ref'],$time,$time+$time2); - //$database->setMovementProc($movedata['moveid']); + $database->addMovement(4, $movedata['to'], $movedata['from'], $movedata['ref'], $time, $time + $time2); } //check return enforcement from del village @@ -652,8 +651,8 @@ public function returnTroops($wref) { $troopsTime = $this->procDistanceTime($fromCor, $toCor, min($speeds), $enforce['from']); $time = $database->getArtifactsValueInfluence($from['owner'], $enforce['from'], 2, $troopsTime); - $reference = $database->addAttack($enforce['from'],$enforce['u'.$start],$enforce['u'.($start+1)],$enforce['u'.($start+2)],$enforce['u'.($start+3)],$enforce['u'.($start+4)],$enforce['u'.($start+5)],$enforce['u'.($start+6)],$enforce['u'.($start+7)],$enforce['u'.($start+8)],$enforce['u'.($start+9)],$enforce['hero'],2,0,0,0,0); - $database->addMovement(4,$wref,$enforce['from'],$reference,time(),($time+time())); + $reference = $database->addAttack($enforce['from'], $enforce['u' . $start], $enforce['u' . ($start + 1)], $enforce['u' . ($start + 2)], $enforce['u' . ($start + 3)], $enforce['u' . ($start + 4)], $enforce['u' . ($start + 5)], $enforce['u' . ($start + 6)], $enforce['u' . ($start + 7)], $enforce['u' . ($start + 8)], $enforce['u' . ($start + 9)], $enforce['hero'], 2, 0, 0, 0, 0); + $database->addMovement(4, $wref, $enforce['from'], $reference, time(), ($time + time())); $database->deleteReinf($enforce['id']); } } diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index 5b199306..b1234ae0 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -34,7 +34,6 @@ class Automation { const bountyOCropProd = 40 * SPEED; public function __construct() { - $this->procNewClimbers(); $this->ClearUser(); $this->ClearInactive(); @@ -680,9 +679,9 @@ private function TradeRoute() { $database->getVillageByWorldID($vilIDs); foreach($dataarray as $data) { - $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); + $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); } } @@ -719,7 +718,7 @@ private function marketComplete() { $database->modifyResource($data['to'],$data['wood'],$data['clay'],$data['iron'],$data['crop'],1); $targettribe = $userData_to["tribe"]; $endtime = $units->getWalkingTroopsTime($data['from'], $data['to'], 0, 0, [$targettribe], 0) + $data['endtime']; - $database->addMovement(2,$data['to'],$data['from'],$data['merchant'],time(),$endtime,$data['send'],$data['wood'],$data['clay'],$data['iron'],$data['crop']); + $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']); } @@ -1048,11 +1047,11 @@ private function sendunitsComplete() { $evasionUnitModifications_amounts[] = $DefenderUnit['hero']; $evasionUnitModifications_modes[] = 0; - $attackid = $database->addAttack($data['to'],$data['u1'],$data['u2'],$data['u3'],$data['u4'],$data['u5'],$data['u6'],$data['u7'],$data['u8'],$data['u9'],$data['u10'],$data['u11'],4,0,0,0,0,0,0,0,0,0,0,0); - $database->addMovement(4,0,$data['to'],$attackid,microtime(true),microtime(true)+(180/EVASION_SPEED)); - $newgold = $gold-2; - $newmaxevasion = $maxevasion-1; - $database->updateUserField($DefenderID, ["gold", "maxevasion"], [$newgold, $newmaxevasion], 1); + $attackid = $database->addAttack($data['to'], $data['u1'], $data['u2'], $data['u3'], $data['u4'], $data['u5'], $data['u6'], $data['u7'], $data['u8'], $data['u9'], $data['u10'], $data['u11'], 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + $database->addMovement(4, 0, $data['to'], $attackid, microtime(true), microtime(true) + (180 / EVASION_SPEED)); + $newgold = $gold - 2; + $newmaxevasion = $maxevasion - 1; + $database->updateUserField($DefenderID, ["gold", "maxevasion"], [$newgold, $newmaxevasion], 1); } // modify units in DB @@ -2471,63 +2470,57 @@ private function sendunitsComplete() { $troopsTime = $units->getWalkingTroopsTime($from['wref'], $to['wref'], $from['owner'], $owntribe, $returningTroops, 1, 't'); $endtime = $database->getArtifactsValueInfluence($from['owner'], $from['wref'], 2, $troopsTime); $endtime += $AttackArrivalTime; - if($type == 1) { - if($from['owner'] == 3) { //fix natar report by ronix - $database->addNotice($to['owner'],$to['wref'],$targetally,20,''.addslashes($from['name']).' scouts '.addslashes($to['name']).'',$data2,$AttackArrivalTime); - }elseif ($totaldead_att == 0 && $totaltraped_att == 0){ - $database->addNotice($from['owner'],$to['wref'],$ownally,18,''.addslashes($from['name']).' scouts '.addslashes($to['name']).'',$data2,$AttackArrivalTime); - }else{ - $database->addNotice($from['owner'],$to['wref'],$ownally,21,''.addslashes($from['name']).' scouts '.addslashes($to['name']).'',$data2,$AttackArrivalTime); - } - }else { - if ((empty($totaldead_att) || $totaldead_att == 0) && (empty($totaltraped_att) || $totaltraped_att == 0)){ - $database->addNotice($from['owner'],$to['wref'],$ownally,1,''.addslashes($from['name']).' attacks '.addslashes($to['name']).'',$data2,$AttackArrivalTime); - }else{ - $database->addNotice($from['owner'],$to['wref'],$ownally,2,''.addslashes($from['name']).' attacks '.addslashes($to['name']).'',$data2,$AttackArrivalTime); - } - } + if($type == 1){ + if($from['owner'] == 3){ // fix natar report by ronix + $database->addNotice($to['owner'], $to['wref'], $targetally, 20, '' . addslashes($from['name']) . ' scouts ' . addslashes($to['name']) . '', $data2, $AttackArrivalTime); + }elseif($totaldead_att == 0 && $totaltraped_att == 0){ + $database->addNotice($from['owner'], $to['wref'], $ownally, 18, '' . addslashes($from['name']) . ' scouts ' . addslashes($to['name']) . '', $data2, $AttackArrivalTime); + }else{ + $database->addNotice($from['owner'], $to['wref'], $ownally, 21, '' . addslashes($from['name']) . ' scouts ' . addslashes($to['name']) . '', $data2, $AttackArrivalTime); + } + }else{ + if((empty($totaldead_att) || $totaldead_att == 0) && (empty($totaltraped_att) || $totaltraped_att == 0)){ + $database->addNotice($from['owner'], $to['wref'], $ownally, 1, '' . addslashes($from['name']) . ' attacks ' . addslashes($to['name']) . '', $data2, $AttackArrivalTime); + }else{ + $database->addNotice($from['owner'], $to['wref'], $ownally, 2, '' . addslashes($from['name']) . ' attacks ' . addslashes($to['name']) . '', $data2, $AttackArrivalTime); + } + } $database->setMovementProc($data['moveid']); if (!isset($chiefing_village)) $chiefing_village = 0; if($chiefing_village != 1){ - $database->addMovement(4,$DefenderWref,$AttackerWref,$data['ref'],$AttackArrivalTime,$endtime); - - // send the bounty on type 6. + $database->addMovement(4, $DefenderWref, $AttackerWref, $data['ref'], $AttackArrivalTime, $endtime, 1, $steal[0], $steal[1], $steal[2], $steal[3]); if($type !== 1){ - $reference = $database->sendResource($steal[0], $steal[1], $steal[2], $steal[3], 0, 0); - if ($isoasis == 0){ - $database->modifyResource($DefenderWref, $steal[0], $steal[1], $steal[2], $steal[3], 0); - }else{ - if($conqureby > 0) //if it's an oasis but it's conquered by someone, resources must be modified in the owner village - { - $database->modifyResource($conqureby, $steal[0], $steal[1], $steal[2], $steal[3], 0); - } + if ($isoasis == 0) $database->modifyResource($DefenderWref, $steal[0], $steal[1], $steal[2], $steal[3], 0); + else + { + //if it's an oasis but it's conquered by someone, resources must be modified in the owner's village + if($conqureby > 0) $database->modifyResource($conqureby, $steal[0], $steal[1], $steal[2], $steal[3], 0); else $database->modifyOasisResource($DefenderWref, $steal[0], $steal[1], $steal[2], $steal[3], 0); } - $database->addMovement(6,$DefenderWref,$AttackerWref,$reference,$AttackArrivalTime,$endtime,1,0,0,0,0,$data['ref']); - $totalstolengain=$steal[0]+$steal[1]+$steal[2]+$steal[3]; - $totalstolentaken=((isset($totalstolentaken) ? $totalstolentaken : 0)-($steal[0]+$steal[1]+$steal[2]+$steal[3])); - $database->modifyPoints($from['owner'],'RR',$totalstolengain); - $database->modifyPoints($to['owner'],'RR',$totalstolentaken); - $database->modifyPointsAlly($targetally,'RR',$totalstolentaken ); - $database->modifyPointsAlly($ownally,'RR',$totalstolengain); + $totalstolengain = $steal[0] + $steal[1] + $steal[2] + $steal[3]; + $totalstolentaken = ((isset($totalstolentaken) ? $totalstolentaken : 0) - ($steal[0] + $steal[1] + $steal[2] + $steal[3])); + $database->modifyPoints($from['owner'], 'RR', $totalstolengain); + $database->modifyPoints($to['owner'], 'RR', $totalstolentaken); + $database->modifyPointsAlly($targetally, 'RR', $totalstolentaken); + $database->modifyPointsAlly($ownally, 'RR', $totalstolengain); } }else{ //fix by ronix if only 1 chief left to conqured - don't add with zero enforces if($totalsend_att - ($totaldead_att + (isset($totaltraped_att) ? $totaltraped_att : 0)) > 1){ - $database->addEnforce2($data,$owntribe,$troopsdead1,$troopsdead2,$troopsdead3,$troopsdead4,$troopsdead5,$troopsdead6,$troopsdead7,$troopsdead8,$troopsdead9,$troopsdead10,$troopsdead11); - } + $database->addEnforce2($data, $owntribe, $troopsdead1, $troopsdead2, $troopsdead3, $troopsdead4, $troopsdead5, $troopsdead6, $troopsdead7, $troopsdead8, $troopsdead9, $troopsdead10, $troopsdead11); + } } } else //else they die and don't return or report. { $database->setMovementProc($data['moveid']); - if($type == 1){ - $database->addNotice($from['owner'],$to['wref'],$ownally,19,addslashes($from['name']).' scouts '.addslashes($to['name']).'',$data_fail,$AttackArrivalTime); - }else{ - $database->addNotice($from['owner'],$to['wref'],$ownally,3,''.addslashes($from['name']).' attacks '.addslashes($to['name']).'',$data_fail,$AttackArrivalTime); - } + if($type == 1){ + $database->addNotice($from['owner'], $to['wref'], $ownally, 19, addslashes($from['name']) . ' scouts ' . addslashes($to['name']) . '', $data_fail, $AttackArrivalTime); + }else{ + $database->addNotice($from['owner'], $to['wref'], $ownally, 3, '' . addslashes($from['name']) . ' attacks ' . addslashes($to['name']) . '', $data_fail, $AttackArrivalTime); + } } if($type == 3 || $type == 4) $database->addGeneralAttack($totalattackdead); @@ -2920,7 +2913,7 @@ private function returnunitsComplete() { $time = time(); $q = " SELECT - `to`, `from`, moveid, starttime, endtime, + `to`, `from`, moveid, starttime, endtime, wood, clay, iron, crop, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11 FROM ".TB_PREFIX."movement, @@ -2939,9 +2932,7 @@ private function returnunitsComplete() { // so we need to de-duplicate them here by checking for the same wave properties sent out at the // same time (i.e. with exactly the same timestamp) $wavesData = []; - if ($dataarray && count($dataarray)) { - // preload village data $vilIDs = []; foreach($dataarray as $data) { @@ -2955,16 +2946,20 @@ private function returnunitsComplete() { $movementProcIDs = []; foreach($dataarray as $data) { if (!isset($wavesData[$data['from'].$data['to'].$data['starttime'].$data['endtime']])) { - $tribe = $database->getUserField($database->getVillageField($data['to'],"owner"),"tribe",0); - + $tribe = $database->getUserField($database->getVillageField($data['to'], "owner"), "tribe", 0); $u = $tribe == 1 ? "" : $tribe - 1; $database->modifyUnit( $data['to'], [$u."1", $u."2", $u."3", $u."4", $u."5", $u."6", $u."7", $u."8", $u."9", $tribe."0", "hero"], [$data['t1'], $data['t2'], $data['t3'], $data['t4'], $data['t5'], $data['t6'], $data['t7'], $data['t8'], $data['t9'], $data['t10'], $data['t11']], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] - + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ); + + //If there's at least 1 resource, add it to the village + if($data['wood'] + $data['clay'] + $data['iron'] + $data['crop'] > 0){ + $database->modifyResource($data['to'], $data['wood'], $data['clay'], $data['iron'], $data['crop'], 1); + } + $movementProcIDs[] = $data['moveid']; //Update starvation data @@ -2973,48 +2968,24 @@ private function returnunitsComplete() { // make sure we don't process duplicate movements until the big bad bug which inserts them into DB is fixed $wavesData[$data['from'].$data['to'].$data['starttime'].$data['endtime']] = true; } // duplicate record, just mark it as processed - else $movementProcIDs[] = $data['moveid']; + else $movementProcIDs[] = $data['moveid']; } $database->setMovementProc(implode(', ', $movementProcIDs)); + $this->pruneResource(); } - // Recieve the bounty on type 6. - - $q = "SELECT s.wood, s.clay, s.iron, s.crop, `to`, `from`, endtime, merchant, send, moveid FROM ".TB_PREFIX."movement m, ".TB_PREFIX."send s WHERE m.ref = s.id AND m.proc = 0 AND sort_type = 6 AND endtime < $time"; - - $dataarray = $database->query_return($q); - $movementProcIDs = []; - - foreach($dataarray as $data) { - - if($data['wood'] >= $data['clay'] && $data['wood'] >= $data['iron'] && $data['wood'] >= $data['crop']) $sort_type = 10; - elseif($data['clay'] >= $data['wood'] && $data['clay'] >= $data['iron'] && $data['clay'] >= $data['crop']) $sort_type = 11; - elseif($data['iron'] >= $data['wood'] && $data['iron'] >= $data['clay'] && $data['iron'] >= $data['crop']) $sort_type = 12; - elseif($data['crop'] >= $data['wood'] && $data['crop'] >= $data['clay'] && $data['crop'] >= $data['iron']) $sort_type = 13; - - $to = $database->getMInfo($data['to']); - $from = $database->getMInfo($data['from']); - $database->modifyResource($data['to'],$data['wood'],$data['clay'],$data['iron'],$data['crop'],1); - //$database->updateVillage($data['to']); - $movementProcIDs[] = $data['moveid']; - - //Update starvation data - $this->addStarvationData($data['to']); - } - - $database->setMovementProc(implode(', ', $movementProcIDs)); - $this->pruneResource(); - // Settlers $q = "SELECT `to`, moveid FROM ".TB_PREFIX."movement where ref = 0 and proc = '0' and sort_type = '4' and endtime < $time"; - $dataarray = $database->query_return($q); $movementProcIDs = []; if ($dataarray && count($dataarray)) { foreach($dataarray as $data) { - $tribe = $database->getUserField($database->getVillageField($data['to'],"owner"),"tribe",0); - $database->modifyUnit($data['to'],array($tribe."0"),array(3),array(1)); + $tribe = $database->getUserField($database->getVillageField($data['to'], "owner"), "tribe", 0); + $database->modifyUnit($data['to'], [$tribe."0"], [3], [1]); + + //If a settling is canceled, add 750 for each resource type + $database->modifyResource($data['to'], 750, 750, 750, 750, 1); $movementProcIDs[] = $data['moveid']; } $database->setMovementProc(implode(', ', $movementProcIDs)); @@ -3031,6 +3002,7 @@ private function sendSettlersComplete() { if(file_exists($autoprefix."GameEngine/Prevention/settlers.txt")) { unlink($autoprefix."GameEngine/Prevention/settlers.txt"); } + $ourFileHandle = fopen($autoprefix."GameEngine/Prevention/settlers.txt", 'w'); fclose($ourFileHandle); $time = microtime(true); @@ -3061,45 +3033,43 @@ private function sendSettlersComplete() { $database->getVillageByWorldID($vilIDs); foreach($dataarray as $data) { - $ownerID = $database->getUserField($database->getVillageField($data['from'],"owner"),"id",0); - $to = $database->getMInfo($data['from']); - $user = addslashes($database->getUserField($to['owner'],'username',0)); - $taken = $database->getVillageState($data['to']); - if($taken != 1){ - $fieldIDs[] = $data['to']; - $database->addVillage($data['to'],$to['owner'],$user,'0'); - $database->addResourceFields($data['to'],$database->getVillageType($data['to'])); + $ownerID = $database->getUserField($database->getVillageField($data['from'], "owner"), "id", 0); + $to = $database->getMInfo($data['from']); + $user = addslashes($database->getUserField($to['owner'], 'username', 0)); + $taken = $database->getVillageState($data['to']); + if($taken != 1){ + $fieldIDs[] = $data['to']; + $database->addVillage($data['to'], $to['owner'], $user, '0'); + $database->addResourceFields($data['to'], $database->getVillageType($data['to'])); $addUnitsWrefs[] = $data['to']; $addTechWrefs[] = $data['to']; $addABTechWrefs[] = $data['to']; $movementProcIDs[] = $data['moveid']; - - $exp1 = $database->getVillageField($data['from'],'exp1'); - $exp2 = $database->getVillageField($data['from'],'exp2'); - $exp3 = $database->getVillageField($data['from'],'exp3'); - - if($exp1 == 0){ - $exp = 'exp1'; - $value = $data['to']; - } - elseif($exp2 == 0){ - $exp = 'exp2'; - $value = $data['to']; - } - else{ - $exp = 'exp3'; - $value = $data['to']; - } - $database->setVillageField($data['from'],$exp,$value); - } - else{ + + $exp1 = $database->getVillageField($data['from'], 'exp1'); + $exp2 = $database->getVillageField($data['from'], 'exp2'); + $exp3 = $database->getVillageField($data['from'], 'exp3'); + + if($exp1 == 0){ + $exp = 'exp1'; + $value = $data['to']; + }elseif($exp2 == 0){ + $exp = 'exp2'; + $value = $data['to']; + }else{ + $exp = 'exp3'; + $value = $data['to']; + } + + $database->setVillageField($data['from'], $exp, $value); + }else{ // here must come movement from returning settlers $types[] = 4; $froms[] = $data['to']; $tos[] = $data['from']; $refs[] = $data['ref']; $times[] = $time; - $endtimes[] = $time+($time-$data['starttime']); + $endtimes[] = $time + ($time - $data['starttime']); $movementProcIDs[] = $data['moveid']; } } @@ -4072,12 +4042,9 @@ private function starvation() { // find the first not-empty array foreach($allTroopsArray as $type => $allTroops) { - if(!empty($allTroops)) - { - foreach($allTroops as $subtype => $troops) - { - if(!empty($troops)) - { + if(!empty($allTroops)){ + foreach($allTroops as $subtype => $troops){ + if(!empty($troops)){ $starvingTroops = reset($troops); break 2; } @@ -4091,25 +4058,23 @@ private function starvation() { // counting $timedif = $time-$starv['starvupdate']; $cropProd = $database->getCropProdstarv($starv['wref']) - $starv['starv']; - if($cropProd < 0) - { + if($cropProd < 0){ $starvsec = (abs($cropProd) / 3600); $difcrop = ($timedif * $starvsec); //crop eat up over time $newcrop = 0; $oldcrop = $database->getVillageField($starv['wref'], 'crop'); - if ($oldcrop > 100) //if the grain is then tries to send all - { - $difcrop = $difcrop-$oldcrop; - if($difcrop < 0) - { - $difcrop = 0; - $newcrop = $oldcrop-$difcrop; - $database->setVillageField($starv['wref'], 'crop', $newcrop); - } + + //if the grain is then tries to send all + if ($oldcrop > 100){ + $difcrop = $difcrop - $oldcrop; + if($difcrop < 0){ + $difcrop = 0; + $newcrop = $oldcrop - $difcrop; + $database->setVillageField($starv['wref'], 'crop', $newcrop); + } } - if($difcrop > 0 && $oldcrop <= 0) - { + if($difcrop > 0 && $oldcrop <= 0){ $tribe = $database->getUserField(($type == 2) ? $starv['owner'] : $database->getVillageField($starvingTroops['from'], "owner"), "tribe", 0); $start = ($special = in_array($type, [1, 3])) ? 1 : ($tribe - 1) * 10 + 1; $end = ($special) ? 10 : $tribe * 10 ; @@ -4126,16 +4091,14 @@ private function starvation() { { $units = (isset($starvingTroops[$utype.$i]) ? $starvingTroops[$utype.$i] : 0); if($counting) $totalUnits += $units; - if($units > $maxcount) - { + if($units > $maxcount){ $maxcount = $units; $maxtype = $i; } } if($counting) $counting = false; - if($maxtype > 0) - { + if($maxtype > 0){ $starvingTroops[$utype.$maxtype]--; $killedUnits[$maxtype]++; $difcrop -= $GLOBALS['u'.(($special) ? $maxtype + ($tribe - 1) * 10 : $maxtype)]['crop']; @@ -4144,8 +4107,7 @@ private function starvation() { } $totalKilledUnits = array_sum($killedUnits); - if($starvingTroops[$heroType] > 0 && ($totalUnits == 0 || $totalUnits == $totalKilledUnits)) - { + if($starvingTroops[$heroType] > 0 && ($totalUnits == 0 || $totalUnits == $totalKilledUnits)){ $totalKilledUnits += $starvingTroops[$heroType]; $totalUnits += $starvingTroops[$heroType]; $starvingTroops['heroinfo'] = $database->getHero(($type == 2) ? $starv['owner'] : $database->getVillageField(($type == 3 && $subtype == 1) ? $starvingTroops['to'] : $starvingTroops['from'], "owner"))[0]; @@ -4161,21 +4123,17 @@ private function starvation() { switch($type) { case 0: - if($totalKilledUnits < $totalUnits) - { + if($totalKilledUnits < $totalUnits){ $database->modifyEnforce($starvingTroops['id'], array_keys($killedUnits), array_values($killedUnits), 0); } else $database->deleteReinf($starvingTroops['id']); break; case 1: - if($totalKilledUnits < $totalUnits) - { + if($totalKilledUnits < $totalUnits){ $database->modifyPrisoners($starvingTroops['id'], array_keys($killedUnits), array_values($killedUnits), 0); $database->modifyUnit($starvingTroops['wref'], ["99o"], [$totalKilledUnits], [0]); - } - else - { + }else{ $database->deletePrisoners($starvingTroops['id']); $database->modifyUnit($starvingTroops['wref'], ["99o"], [$totalUnits], [0]); } @@ -4186,11 +4144,10 @@ private function starvation() { break; case 3: - if($totalKilledUnits < $totalUnits) - { + if($totalKilledUnits < $totalUnits){ $database->modifyAttack2($starvingTroops['id'], array_keys($killedUnits), array_values($killedUnits), 0); } - else $database->setMovementProc($starvingTroops['moveid'].(($subtype == 1) ? ", ".($starvingTroops['moveid'] + 1) : "")); + else $database->setMovementProc($starvingTroops['moveid']); break; } @@ -4200,9 +4157,8 @@ private function starvation() { } } - $crop = $database->getCropProdstarv($starv['wref'], false); - - if ($crop > $upkeep) $database->setVillageField($starv['wref'], ['starv', 'starvupdate'], [0, 0]); + $crop = $database->getCropProdstarv($starv['wref'], false); + if ($crop > 0) $database->setVillageField($starv['wref'], ['starv', 'starvupdate'], [0, 0]); unset ($unitarrays, $type, $subtype); } diff --git a/GameEngine/BBCode.php b/GameEngine/BBCode.php index e0583121..932442ec 100755 --- a/GameEngine/BBCode.php +++ b/GameEngine/BBCode.php @@ -225,12 +225,9 @@ function($matches) { function($matches) { global $database; - $report = count($database->getNotice4((int) $matches[1])); - if (count($report)) { - return "".$matches[2].""; - } else { - return $matches[2]; - } + $report = count($database->getNotice2((int) $matches[1])); + if (count($report)) return "".$matches[2].""; + else return $matches[2]; }, $input); diff --git a/GameEngine/Database.php b/GameEngine/Database.php index 2bd471e7..8bfd2324 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -359,11 +359,6 @@ class MYSQLi_DB implements IDbConnection { */ $noticesCacheById = [], - /** - * @var array Cache of notices by user ID. - */ - $noticesCacheByUId = [], - /** * @var array Cache of merchants used count. */ @@ -4257,7 +4252,7 @@ function getNotice($uid) { return $this->mysqli_fetch_all($result); } - function getNotice2($id, $field, $use_cache = true) { + function getNotice2($id, $field = null, $use_cache = true) { list($id, $field) = $this->escape_input((int) $id, $field); // first of all, check if we should be using cache and whether the field @@ -4271,27 +4266,7 @@ function getNotice2($id, $field, $use_cache = true) { $dbarray = mysqli_fetch_array($result); self::$noticesCacheById[$id] = $dbarray; - return self::$noticesCacheById[$id][$field]; - } - - function getNotice3($uid, $alliance, $use_cache = true) { - list($uid) = $this->escape_input((int) $uid); - - // 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::$noticesCacheByUId, $uid)) && !is_null($cachedValue)) { - return $cachedValue; - } - - $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid ".($alliance > 0 ? 'OR ally = '.$alliance.'' : '')." ORDER BY time ".(isset($_GET['o']) && $_GET['o'] == 1 ? 'ASC' : 'DESC'); - $result = mysqli_query($this->dblink,$q); - - $noticesCacheByUId[$uid] = $this->mysqli_fetch_all($result); - return $noticesCacheByUId[$uid]; - } - - function getNotice4($id, $use_cache = true) { - return $this->getNotice2($id, $use_cache); + return is_null($field) ? self::$noticesCacheById[$id] : self::$noticesCacheById[$id][$field]; } function getUnViewNotice($uid) { diff --git a/GameEngine/Market.php b/GameEngine/Market.php index 64520112..cfe972c5 100755 --- a/GameEngine/Market.php +++ b/GameEngine/Market.php @@ -12,8 +12,8 @@ class Market { - public $onsale,$onmarket,$sending,$recieving,$return = array(); - public $maxcarry,$merchant,$used; + public $onsale, $onmarket, $sending, $recieving, $return = []; + public $maxcarry, $merchant, $used; public function procMarket($post) { @@ -114,8 +114,8 @@ private function sendResource($post) elseif($post['send3'] < 1 || $post['send3'] > 3 || ($post['send3'] > 1 && !$session->goldclub)) $form->addError("error", INVALID_MERCHANTS_REPETITION); elseif($availableWood >= $post['r1'] && $availableClay >= $post['r2'] && $availableIron >= $post['r3'] && $availableCrop >= $post['r4']) { - $resource = array($wtrans,$ctrans,$itrans,$crtrans); - $reqMerc = ceil((array_sum($resource)-0.1)/$this->maxcarry); + $resource = [$wtrans, $ctrans, $itrans, $crtrans]; + $reqMerc = ceil((array_sum($resource) - 0.1) / $this->maxcarry); if($this->merchantAvail() > 0 && $reqMerc <= $this->merchantAvail()) { @@ -124,14 +124,13 @@ private function sendResource($post) if($database->getVillageState($id)) { $timetaken = $generator->procDistanceTime($coor, $village->coor, $session->tribe, 0); - $res = $resource[0]+$resource[1]+$resource[2]+$resource[3]; - if($res!=0) - { - $reference = $database->sendResource($resource[0],$resource[1],$resource[2],$resource[3],$reqMerc,0); - $database->modifyResource($village->wid,$resource[0],$resource[1],$resource[2],$resource[3],0); - $database->addMovement(0,$village->wid,$id,$reference,time(),time()+$timetaken,$post['send3']); - $logging->addMarketLog($village->wid,1,array($resource[0],$resource[1],$resource[2],$resource[3],$id)); - } + $res = $resource[0] + $resource[1] + $resource[2] + $resource[3]; + if($res != 0){ + $reference = $database->sendResource($resource[0], $resource[1], $resource[2], $resource[3], $reqMerc, 0); + $database->modifyResource($village->wid, $resource[0], $resource[1], $resource[2], $resource[3], 0); + $database->addMovement(0, $village->wid, $id, $reference, time(), time() + $timetaken, $post['send3']); + $logging->addMarketLog($village->wid, 1, [$resource[0], $resource[1], $resource[2], $resource[3], $id]); + } } header("Location: build.php?id=".$post['id']); exit; @@ -251,7 +250,6 @@ private function acceptOffer($get) } } - // We don't have enough resources if($infoarray['wamt'] > ([$village->awood, $village->aclay, $village->airon, $village->acrop])[$infoarray['wtype']]) { @@ -271,7 +269,7 @@ private function acceptOffer($get) exit; } - $myresource = $hisresource = array(1=>0,0,0,0); + $myresource = $hisresource = [ 1=> 0, 0, 0, 0]; $myresource[$infoarray['wtype']] = $infoarray['wamt']; $mysendid = $database->sendResource($myresource[1],$myresource[2],$myresource[3],$myresource[4],$reqMerc,0); $hisresource[$infoarray['gtype']] = $infoarray['gamt']; @@ -289,13 +287,13 @@ private function acceptOffer($get) [$timestamp, $timestamp], [$mytime + $timestamp, $histime + $timestamp] ); - $resource = array(1=>0,0,0,0); - $resource[$infoarray['wtype']] = $infoarray['wamt']; - $database->modifyResource($village->wid, $resource[1], $resource[2], $resource[3], $resource[4] , 0); - $database->setMarketAcc($get['g']); - $database->removeAcceptedOffer($get['g']); - $logging->addMarketLog($village->wid,2,array($infoarray['vref'],$get['g'])); - header("Location: build.php?id=".$get['id']); + $resource = [1 => 0, 0, 0, 0]; + $resource[$infoarray['wtype']] = $infoarray['wamt']; + $database->modifyResource($village->wid, $resource[1], $resource[2], $resource[3], $resource[4], 0); + $database->setMarketAcc($get['g']); + $database->removeAcceptedOffer($get['g']); + $logging->addMarketLog($village->wid, 2, [$infoarray['vref'], $get['g']]); + header("Location: build.php?id=" . $get['id']); exit; } @@ -304,7 +302,7 @@ private function loadOnsale() global $database,$village,$session,$multisort,$generator; $displayarray = $database->getMarket($village->wid,1); - $holderarray = array(); + $holderarray = []; foreach($displayarray as $value) { $targetcoor = $database->getCoor($value['vref']); @@ -320,57 +318,36 @@ private function loadOnsale() private function filterNeed($get) { - if(isset($get['v']) || isset($get['s']) || isset($get['b'])) - { - $holder = $holder2 = array(); - if(isset($get['v']) && $get['v'] == "1:1") - { - foreach($this->onsale as $equal) - { - if($equal['wamt'] <= $equal['gamt']) - { - array_push($holder,$equal); - } - } - } - else - { - $holder = $this->onsale; - } - foreach($holder as $sale) - { - if(isset($get['s']) && isset($get['b'])) - { - if($sale['gtype'] == $get['s'] && $sale['wtype'] == $get['b']) - { - array_push($holder2,$sale); - } - } - else if(isset($get['s']) && !isset($get['b'])) - { - if($sale['gtype'] == $get['s']) - { - array_push($holder2,$sale); - } - } - else if(isset($get['b']) && !isset($get['s'])) - { - if($sale['wtype'] == $get['b']) - { - array_push($holder2,$sale); - } - } - else - { - $holder2 = $holder; - } - } - $this->onsale = $holder2; - } - else - { - $this->loadOnsale(); + if(isset($get['v']) || isset($get['s']) || isset($get['b'])){ + $holder = $holder2 = []; + if(isset($get['v']) && $get['v'] == "1:1"){ + foreach($this->onsale as $equal){ + if($equal['wamt'] <= $equal['gamt']){ + array_push($holder, $equal); + } + } + } + else $holder = $this->onsale; + + foreach($holder as $sale){ + if(isset($get['s']) && isset($get['b'])){ + if($sale['gtype'] == $get['s'] && $sale['wtype'] == $get['b']){ + array_push($holder2, $sale); + } + }else if(isset($get['s']) && !isset($get['b'])){ + if($sale['gtype'] == $get['s']){ + array_push($holder2, $sale); + } + }else if(isset($get['b']) && !isset($get['s'])){ + if($sale['wtype'] == $get['b']){ + array_push($holder2, $sale); + } + } + else $holder2 = $holder; + } + $this->onsale = $holder2; } + else $this->loadOnsale(); } private function tradeResource($post) diff --git a/GameEngine/Message.php b/GameEngine/Message.php index 36eaa7d0..8ee17a59 100755 --- a/GameEngine/Message.php +++ b/GameEngine/Message.php @@ -13,38 +13,33 @@ class Message { public $unread, $nunread = false; public $note; - public $inbox, $inbox1, $sent, $sent1, $reading, $reply, $archived, $archived1, $noticearray, $notice, $readingNotice = array(); - private $totalMessage, $totalNotice; - private $allNotice = []; + public $inbox, $inbox1, $sent, $sent1, $reading, $reply, $archived, $archived1, $noticearray, $readingNotice = []; + private $totalMessage; function __construct() { $req_file = basename($_SERVER['PHP_SELF']); $this->unread = $this->checkUnread(); $this->nunread = $this->checkNUnread(); - if ($req_file == 'nachrichten.php') { - if ( isset( $_GET['t'] ) ) { - switch ( $_GET['t'] ) { - // send messages page or a single sent message - case 2: - case '2a': - $this->getMessages( 2 ); - break; - - // archived messages page - case 3: - $this->getMessages( 3 ); - break; - } - } else { - // inbox - received messages page - $this->getMessages( 1 ); - } - } + if($req_file == 'nachrichten.php'){ + if(isset($_GET['t'])){ + switch($_GET['t']){ + // send messages page or a single sent message + case 2 : + case '2a' : + $this->getMessages(2); + break; + + // archived messages page + case 3 : + $this->getMessages(3); + break; + } + } + else $this->getMessages(1); // inbox - received messages page + } - if ($req_file == 'berichte.php') { - $this->getNotice(); - } + if ($req_file == 'berichte.php') $this->getNotice(); if(isset($_SESSION['reply'])) { $this->reply = $_SESSION['reply']; @@ -59,14 +54,10 @@ public function procMessage($post) { $this->quoteMessage($post['id']); break; case "m2": - if ($post['an'] == "[ally]"){ - $this->sendAMessage($post['be'],addslashes($post['message'])); - }else{ - $this->sendMessage($post['an'],$post['be'],addslashes($post['message'])); - } - header("Location: nachrichten.php?t=2"); - exit; - break; + if ($post['an'] == "[ally]") $this->sendAMessage($post['be'],addslashes($post['message'])); + else $this->sendMessage($post['an'],$post['be'],addslashes($post['message'])); + header("Location: nachrichten.php?t=2"); + exit; case "m3": case "m4": case "m5": @@ -74,12 +65,8 @@ public function procMessage($post) { $this->removeMessage($post); $this->header($get); } - if(isset($post['archive_x'])) { - $this->archiveMessage($post); - } - if(isset($post['start_x'])) { - $this->unarchiveMessage($post); - } + if(isset($post['archive_x'])) $this->archiveMessage($post); + if(isset($post['start_x'])) $this->unarchiveMessage($post); break; case "m6": $this->createNote($post); @@ -94,46 +81,28 @@ public function procMessage($post) { public function noticeType($get) { global $session, $database; if(isset($get['t'])) { - if($get['t'] == 1) { - $type = array(8, 15, 16, 17); - } - if($get['t'] == 2) { - $type = array(10, 11, 12, 13); - } - if($get['t'] == 3) { - $type = array(1, 2, 3, 4, 5, 6, 7); - } - if($get['t'] == 4) { - $type = array(0, 18, 19, 20, 21); - } + if($get['t'] == 1) $type = [8, 15, 16, 17]; + if($get['t'] == 2) $type = [10, 11, 12, 13]; + if($get['t'] == 3) $type = [1, 2, 3, 4, 5, 6, 7]; + if($get['t'] == 4) $type = [0, 18, 19, 20, 21]; if($get['t'] == 5) { if(!$session->plus){ header("Location: berichte.php"); exit; - } else { - $type = 9; - } + } + else $type = 9; } - if (!is_array($type)) { $type = array($type); } + if (!is_array($type)) $type = [$type]; $this->noticearray = $this->filter_by_value($database->getNotice($session->uid), "ntype", $type); - $this->notice = $this->filter_by_value($database->getNotice3($session->uid, $session->alliance), "ntype", $type); } - if(isset($get['id'])) { - $this->readingNotice = $this->getReadNotice($get['id']); - } + if(isset($get['id'])) $this->readingNotice = $this->getReadNotice($get['id']); } public function procNotice($post) { - if(isset($post["del_x"])) { - $this->removeNotice($post); - } - if(isset($post['archive_x'])) { - $this->archiveNotice($post); - } - if(isset($post['start_x'])) { - $this->unarchiveNotice($post); - } + if(isset($post["del_x"])) $this->removeNotice($post); + if(isset($post['archive_x'])) $this->archiveNotice($post); + if(isset($post['start_x'])) $this->unarchiveNotice($post); } public function quoteMessage($id) { @@ -142,22 +111,22 @@ public function quoteMessage($id) { $message = preg_replace('/\[message\]/', '', $message); $message = preg_replace('/\[\/message\]/', '', $message); - for($i=1;$i<=$message['alliance'];$i++){ + for($i = 1; $i <= $message['alliance']; $i++){ $message = preg_replace('/\[alliance'.$i.'\]/', '[alliance0]', $message); $message = preg_replace('/\[\/alliance'.$i.'\]/', '[/alliance0]', $message); } - for($i=0;$i<=$message['player'];$i++){ + for($i = 0; $i <= $message['player']; $i++){ $message = preg_replace('/\[player'.$i.'\]/', '[player0]', $message); $message = preg_replace('/\[\/player'.$i.'\]/', '[/player0]', $message); } - for($i=0;$i<=$message['coor'];$i++){ + for($i = 0; $i <= $message['coor']; $i++){ $message = preg_replace('/\[coor'.$i.'\]/', '[coor0]', $message); $message = preg_replace('/\[\/coor'.$i.'\]/', '[/coor0]', $message); } - for($i=0;$i<=$message['report'];$i++){ + for($i = 0; $i <= $message['report']; $i++){ $message = preg_replace('/\[report'.$i.'\]/', '[report0]', $message); $message = preg_replace('/\[\/report'.$i.'\]/', '[/report0]', $message); } @@ -171,34 +140,39 @@ public function quoteMessage($id) { public function loadMessage($id) { global $database, $session; + if($this->findInbox($id)) { foreach($this->inbox as $message) { if($message['id'] == $id) { $this->reading = $message; + break; } } } + if($this->findSent($id)) { foreach($this->sent as $message) { if($message['id'] == $id) { $this->reading = $message; + break; } } } + if($session->plus && $this->findArchive($id)) { foreach($this->archived as $message) { if($message['id'] == $id) { $this->reading = $message; + break; } } } - if($this->reading['viewed'] == 0) { - $database->getMessage($id, 4); - } + + if($this->reading['viewed'] == 0) $database->getMessage($id, 4); } private function filter_by_value_except($array, $index, $value) { - $newarray = array(); + $newarray = []; if(is_array($array) && count($array) > 0) { foreach(array_keys($array) as $key) { $temp[$key] = $array[$key][$index]; @@ -213,7 +187,7 @@ private function filter_by_value_except($array, $index, $value) { } private function filter_by_value($array, $index, $value) { - $newarray = array(); + $newarray = []; if(is_array($array) && count($array) > 0) { foreach(array_keys($array) as $key) { $temp[$key] = $array[$key][$index]; @@ -229,46 +203,32 @@ private function filter_by_value($array, $index, $value) { private function getNotice() { global $database, $session; - $this->allNotice = $database->getNotice3($session->uid, $session->alliance); + $this->noticearray = $this->filter_by_value_except($database->getNotice($session->uid), "ntype", 9); - $this->notice = $this->filter_by_value_except($this->allNotice, "ntype", 9); - $this->totalNotice = count($this->allNotice); } private function removeMessage($post) { - global $database,$session; + global $database, $session; + $post = $database->escape($post); - - $mode5updates = []; - $mode7updates = []; - $mode8updates = []; - - for($i = 1; $i <= 10; $i++) { - if ( isset( $post[ 'n' . $i ] ) ) { - $message1 = mysqli_query( $database->dblink, "SELECT target, owner FROM " . TB_PREFIX . "mdata where id = " . (int) $post[ 'n' . $i ] . "" ); - $message = mysqli_fetch_array( $message1 ); - - if ( $message['target'] == $session->uid && $message['owner'] == $session->uid ) { - $mode8updates[] = $post[ 'n' . $i ]; - } else if ( $message['target'] == $session->uid ) { - $mode5updates[] = $post[ 'n' . $i ]; - } else if ( $message['owner'] == $session->uid ) { - $mode7updates[] = $post[ 'n' . $i ]; - } - } + $mode5updates = $mode7updates = $mode8updates = []; + + for($i = 1; $i <= 10; $i++){ + if(isset($post['n' . $i])){ + $message1 = mysqli_query($database->dblink, "SELECT target, owner FROM " . TB_PREFIX . "mdata where id = " . (int)$post['n' . $i] . ""); + $message = mysqli_fetch_array($message1); + + if($message['target'] == $session->uid && $message['owner'] == $session->uid){ + $mode8updates[] = $post['n' . $i]; + } + else if($message['target'] == $session->uid) $mode5updates[] = $post['n' . $i]; + else if($message['owner'] == $session->uid) $mode7updates[] = $post['n' . $i]; + } } - if (count($mode5updates)) { - $database->getMessage( $mode5updates, 5 ); - } - - if (count($mode7updates)) { - $database->getMessage( $mode7updates, 7 ); - } - - if (count($mode8updates)) { - $database->getMessage( $mode8updates, 8 ); - } + if(count($mode5updates)) $database->getMessage($mode5updates, 5); + if(count($mode7updates)) $database->getMessage($mode7updates, 7); + if(count($mode8updates)) $database->getMessage($mode8updates, 8); header("Location: nachrichten.php"); exit; @@ -294,12 +254,12 @@ private function unarchiveMessage($post) { global $database; $normIDs = []; - for($i = 1; $i <= 10; $i++) { if(isset($post['n' . $i])) { $normIDs[] = $post['n' . $i]; } } + $database->setNorm($normIDs); header("Location: nachrichten.php"); @@ -310,12 +270,12 @@ private function removeNotice($post) { global $database; $removeIDs = []; - for($i = 1; $i <= 10; $i++) { if(isset($post['n' . $i])) { $removeIDs[] = $post['n' . $i]; } } + $database->removeNotice($removeIDs); header("Location: berichte.php"); @@ -326,12 +286,12 @@ private function archiveNotice($post) { global $database; $archiveIDs = []; - for($i = 1; $i <= 10; $i++) { if(isset($post['n' . $i])) { $archiveIDs[] = $post['n' . $i]; } } + $database->archiveNotice($archiveIDs); header("Location: berichte.php"); @@ -342,12 +302,12 @@ private function unarchiveNotice($post) { global $database; $unarchIDs = []; - for($i = 1; $i <= 10; $i++) { if(isset($post['n' . $i])) { $unarchIDs[] = $post['n' . $i]; } } + $database->unarchiveNotice($unarchIDs); header("Location: berichte.php"); @@ -356,12 +316,13 @@ private function unarchiveNotice($post) { private function getReadNotice($id) { global $database, $session; - foreach($this->allNotice as $notice) { - if($notice['id'] == $id) { - if($notice['uid'] == $session->uid) $database->noticeViewed($notice['id']); - return $notice; - } + + $notice = $database->getNotice2($id); + if($notice['uid'] == $session->uid || $notice['ally'] == $session->alliance){ + if($notice['uid'] == $session->uid) $database->noticeViewed($notice['id']); + return $notice; } + else return null; } /** @@ -402,17 +363,16 @@ public function getReportType($type) public function loadNotes() { global $session; - if(file_exists("GameEngine/Notes/" . md5($session->username) . ".txt")) { - $this->note = file_get_contents("GameEngine/Notes/" . md5($session->username) . ".txt"); - } else { - $this->note = ""; - } + if(file_exists("GameEngine/Notes/".md5($session->username).".txt")) { + $this->note = file_get_contents("GameEngine/Notes/".md5($session->username).".txt"); + } + else $this->note = ""; } private function createNote($post) { global $session; if($session->plus) { - $ourFileHandle = fopen("GameEngine/Notes/" . md5($session->username) . ".txt", 'w'); + $ourFileHandle = fopen("GameEngine/Notes/".md5($session->username).".txt", 'w'); fwrite($ourFileHandle, $post['notizen']); fclose($ourFileHandle); } @@ -421,21 +381,24 @@ private function createNote($post) { private function getMessages($which) { global $database, $session; - switch ($which) { - case 1: $this->inbox = $database->getMessage($session->uid, 1); - $this->inbox1 = $database->getMessage($session->uid, 9); - break; - - case 2: $this->sent = $database->getMessage($session->uid, 2); - $this->sent1 = $database->getMessage($session->uid, 10); - break; - - case 3: if($session->plus) { - $this->archived = $database->getMessage($session->uid, 6); - $this->archived1 = $database->getMessage($session->uid, 11); - } - break; - } + switch($which){ + case 1 : + $this->inbox = $database->getMessage($session->uid, 1); + $this->inbox1 = $database->getMessage($session->uid, 9); + break; + + case 2 : + $this->sent = $database->getMessage($session->uid, 2); + $this->sent1 = $database->getMessage($session->uid, 10); + break; + + case 3 : + if($session->plus){ + $this->archived = $database->getMessage($session->uid, 6); + $this->archived1 = $database->getMessage($session->uid, 11); + } + break; + } } private function sendAMessage($topic,$text) { @@ -524,8 +487,8 @@ private function sendAMessage($topic,$text) { } } - if($permission['opt7']==1){ - if ($userally != 0) { + if($permission['opt7'] == 1){ + if ($userally > 0) { while ($allmembers = mysqli_fetch_array($allmembersQ)) { $database->sendMessage($allmembers[id],$session->uid,htmlspecialchars(addslashes($topic)),htmlspecialchars(addslashes($text)),0,$alliance,$player,$coor,$report); } @@ -555,9 +518,7 @@ private function sendMessage($recieve, $topic, $text, $security_check = true) { $text = $this->wordCensor($text); } - if($topic == "") { - $topic = "No subject"; - } + if(empty($topic)) $topic = "No subject"; if ( ! preg_match( '/\[message\]/', $text ) && ! preg_match( '/\[\/message\]/', $text ) ) { $text = "[message]" . $text . "[/message]"; @@ -620,34 +581,23 @@ private function sendMessage($recieve, $topic, $text, $security_check = true) { } // check if we're not sending this as Support or Multihunter - $support_from_admin_allowed = ( $session->access == ADMIN && ADMIN_RECEIVE_SUPPORT_MESSAGES ); - $send_as = $session->uid; - - // send as Support? - if (( ! empty( $_POST['as_support'] ) && $support_from_admin_allowed )) { - $send_as = 1; - } - - // send as Multihunter - if (( ! empty( $_POST['as_multihunter'] ) && $session->access == MULTIHUNTER )) { - $send_as = 5; - } - - $database->sendMessage( $user, $send_as, htmlspecialchars( addslashes( $topic ) ), htmlspecialchars( addslashes( $text ) ), 0, $alliance, $player, $coor, $report ); + $support_from_admin_allowed = ($session->access == ADMIN && ADMIN_RECEIVE_SUPPORT_MESSAGES); + $send_as = $session->uid; + + // send as Support? + if((!empty($_POST['as_support']) && $support_from_admin_allowed)) $send_as = 1; + + // send as Multihunter + if((!empty($_POST['as_multihunter']) && $session->access == MULTIHUNTER)) $send_as = 5; + + $database->sendMessage($user, $send_as, htmlspecialchars(addslashes($topic)), htmlspecialchars(addslashes($text)), 0, $alliance, $player, $coor, $report); } } - //7 = village, attacker, att tribe, u1 - u10, lost %, w,c,i,c , cap - //8 = village, attacker, att tribe, enforcement - private function sendNotice($from, $vid, $fowner, $owner, $type, $extra) { - - } - public function sendWelcome($uid, $username) { global $database; $welcomemsg = file_get_contents("GameEngine/Admin/welcome.tpl"); - $welcomemsg = "[message]".preg_replace( ["'%USER%'", "'%START%'", "'%TIME%'", "'%PLAYERS%'", "'%ALLI%'", "'%SERVER_NAME%'", "'%PROTECTION%'"], [$username, date("y.m.d", COMMENCE), date("H:i", COMMENCE), $database->countUser(), $database->countAlli(), SERVER_NAME, round((PROTECTION/3600))], @@ -678,85 +628,78 @@ private function checkNUnread() { } private function findInbox($id) { - if (count($this->inbox)) { - foreach ( $this->inbox as $message ) { - if ( $message['id'] == $id ) { - return true; - } - } - } - + if(count($this->inbox)){ + foreach($this->inbox as $message){ + if($message['id'] == $id) return true; + } + } + return false; } - private function findSent($id) { - if (!empty($this->sent)) { - foreach ( $this->sent as $message ) { - if ( $message['id'] == $id ) { - return true; - } - } - } - + private function findSent($id){ + if(!empty($this->sent)){ + foreach($this->sent as $message){ + if($message['id'] == $id) return true; + } + } + return false; } - private function findArchive($id) { - if (!empty($this->archived)) { - foreach ( $this->archived as $message ) { - if ( $message['id'] == $id ) { - return true; - } - } - } - + private function findArchive($id){ + if(!empty($this->archived)){ + foreach($this->archived as $message){ + if($message['id'] == $id) return true; + } + } + return false; } - public function addFriends($post) { + public function addFriends($post){ global $database; - for ( $i = 0; $i <= 19; $i ++ ) { - if ( $post[ 'addfriends' . $i ] != "" ) { - $uid = $database->getUserField( $post[ 'addfriends' . $i ], "id", 1 ); - $added = 0; - - for ( $j = 0; $j <= $i; $j ++ ) { - if ( $added == 0 ) { - $user = $database->getUserField( $post['myid'], "friend" . $j, 0 ); - $userwait = $database->getUserField( $post['myid'], "friend" . $j . "wait", 0 ); - $exist = 0; - - for ( $k = 0; $k <= 19; $k ++ ) { - $user1 = $database->getUserField( $post['myid'], "friend" . $k, 0 ); - if ( $user1 == $uid or $uid == $post['myid'] ) { - $exist = 1; - } - } - - if ( $user == 0 && $userwait == 0 && $exist == 0 ) { - $added1 = 0; - - for ( $l = 0; $l <= 19; $l ++ ) { - $user2 = $database->getUserField( $uid, "friend" . $l, 0 ); - $userwait2 = $database->getUserField( $uid, "friend" . $l . "wait", 0 ); - - if ( $user2 == 0 && $userwait2 == 0 && $added1 == 0 ) { - $database->addFriend( $uid, "friend" . $l . "wait", $post['myid'] ); - $added1 = 1; - } - } - - $database->addFriend( $post['myid'], "friend" . $j, $uid ); - $database->addFriend( $post['myid'], "friend" . $j . "wait", $uid ); - $added = 1; - } - } - } - } - } - header( "Location: nachrichten.php?t=1" ); - exit; + for($i = 0; $i <= 19; $i++){ + if($post['addfriends'.$i] != ""){ + $uid = $database->getUserField($post['addfriends'.$i], "id", 1); + $added = 0; + + for($j = 0; $j <= $i; $j++){ + if($added == 0){ + $user = $database->getUserField($post['myid'], "friend".$j, 0); + $userwait = $database->getUserField($post['myid'], "friend".$j."wait", 0); + $exist = 0; + + for($k = 0; $k <= 19; $k++){ + $user1 = $database->getUserField($post['myid'], "friend".$k, 0); + if($user1 == $uid or $uid == $post['myid']){ + $exist = 1; + } + } + + if($user == 0 && $userwait == 0 && $exist == 0){ + $added1 = 0; + + for($l = 0; $l <= 19; $l++){ + $user2 = $database->getUserField($uid, "friend".$l, 0); + $userwait2 = $database->getUserField($uid, "friend".$l."wait", 0); + + if($user2 == 0 && $userwait2 == 0 && $added1 == 0){ + $database->addFriend($uid, "friend".$l."wait", $post['myid']); + $added1 = 1; + } + } + + $database->addFriend($post['myid'], "friend".$j, $uid); + $database->addFriend($post['myid'], "friend".$j."wait", $uid); + $added = 1; + } + } + } + } + } + header("Location: nachrichten.php?t=1"); + exit(); } -} -; +}; diff --git a/GameEngine/Units.php b/GameEngine/Units.php index cd3b5cff..27b30a94 100755 --- a/GameEngine/Units.php +++ b/GameEngine/Units.php @@ -503,27 +503,26 @@ private function sendTroopsBack($post) { $troopsTime = $this->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $tribe, $post, 1, 't'); $time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime); - $reference = $database->addAttack($enforce['from'], $post['t1'], $post['t2'], $post['t3'], $post['t4'], $post['t5'], $post['t6'], $post['t7'], $post['t8'], $post['t9'], $post['t10'], $post['t11'], 2, 0, 0, 0, 0 ); - $database->addMovement(4, $village->wid, $enforce['from'], $reference, time(), ($time + time())); - $technology->checkReinf($post['ckey'], false ); + $reference = $database->addAttack($enforce['from'], $post['t1'], $post['t2'], $post['t3'], $post['t4'], $post['t5'], $post['t6'], $post['t7'], $post['t8'], $post['t9'], $post['t10'], $post['t11'], 2, 0, 0, 0, 0); + $database->addMovement(4, $village->wid, $enforce['from'], $reference, time(), ($time + time())); + $technology->checkReinf($post['ckey'], false); - header( "Location: build.php?id=39&refresh=1" ); - exit; - - } - } else { - $form->addError( "error", "You cant change someones troops." ); - if ( $form->returnErrors() > 0 ) { - $_SESSION['errorarray'] = $form->getErrors(); - $_SESSION['valuearray'] = $_POST; - header( "Location: a2b.php" ); - exit; - } - } - } else { - header( "Location: banned.php" ); - exit; - } + header("Location: build.php?id=39&refresh=1"); + exit(); + } + }else{ + $form->addError("error", "You cant change someones troops."); + if($form->returnErrors() > 0){ + $_SESSION['errorarray'] = $form->getErrors(); + $_SESSION['valuearray'] = $_POST; + header("Location: a2b.php"); + exit(); + } + } + }else{ + header("Location: banned.php"); + exit(); + } } public function Settlers($post) { diff --git a/GameEngine/Village.php b/GameEngine/Village.php index 73f2924c..4658c9fb 100755 --- a/GameEngine/Village.php +++ b/GameEngine/Village.php @@ -317,5 +317,5 @@ private function ActionControl() { }; $village = new Village; $building = new Building; -include_once ("Automation.php"); +include_once("Automation.php"); ?> diff --git a/Templates/Build/16_incomming.tpl b/Templates/Build/16_incomming.tpl index f831ce7d..598836bc 100644 --- a/Templates/Build/16_incomming.tpl +++ b/Templates/Build/16_incomming.tpl @@ -1,5 +1,5 @@ getMovement(34, $village->wid, 1); $total_for = count($units); @@ -7,12 +7,6 @@ $send = $database->getMovement(1, $village->wid, 1); $total_for2 = count($send); $artifactsSum = $database->getArtifactsSumByKind($session->uid, $village->wid, 3); for($y = 0; $y < $total_for; $y++){ - for($i = 0; $i < $total_for2; $i++){ - if($units[$y]['ref'] == $send[$i]['ref2']){ - $res1 = mysqli_query($database->dblink, "SELECT wood, clay, iron, crop FROM ".TB_PREFIX."send where id = ".(int)$send[$i]['ref'].""); - $res = mysqli_fetch_array($res1); - } - } $session->timer++; if($units[$y]['sort_type'] == 3){ if($units[$y]['attack_type'] == 2) $actionType = REINFORCEMENTFOR; @@ -162,10 +156,8 @@ for($y = 0; $y < $total_for; $y++){ 0){ ?> @@ -175,11 +167,9 @@ for($y = 0; $y < $total_for; $y++){ \"Lumber\"".$res['wood']." | \"Clay\"".$res['clay']." | \"Iron\"".$res['iron']." | \"Crop\"".$res['crop']."
"; + echo "
\"Lumber\"".$units[$y]['wood']." | \"Clay\"".$units[$y]['clay']." | \"Iron\"".$units[$y]['iron']." | \"Crop\"".$units[$y]['crop']."
"; echo "
\"carry\"".$totalres."/".$totalcarry."
"; - ?> - - + ?> @@ -202,7 +192,6 @@ for($y = 0; $y < $total_for; $y++){ getOasis($village->wid); foreach($array as $conqured){ diff --git a/Templates/Notice/all.tpl b/Templates/Notice/all.tpl index a8f9478e..7e47ba77 100644 --- a/Templates/Notice/all.tpl +++ b/Templates/Notice/all.tpl @@ -1,5 +1,7 @@
noticearray) >= $i) { - echo " +$name = 1; +$count = 0; +for($i = (1 + $s); $i <= (10 + $s); $i++){ + if(count($message->noticearray) >= $i){ + echo ""; - } - $name++; - } - if(count($message->noticearray) == 0) { - echo ""; - } + $type = (isset($_GET['t']) && $_GET['t'] == 5) ? $message->noticearray[$i - 1]['archive'] : $message->noticearray[$i - 1]['ntype']; + if($type == 23) $type = 22; + if($type >= 15 && $type <= 17){ + $type = $type - 11; + echo "\"""; + }else if($type >= 18 && $type <= 22){ + echo "\"""; + }else{ + echo "\"""; + } + echo "
noticearray[$i - 1]['id'] . "\">" . $message->noticearray[$i - 1]['topic'] . " "; + if($message->noticearray[$i - 1]['viewed'] == 0){ + echo "(new)"; + } + $date = $generator->procMtime($message->noticearray[$i - 1]['time']); + echo "
"; + } + $name++; +} +if(count($message->noticearray) == 0) echo ""; ?> diff --git a/build.php b/build.php index cea48c8e..c386d69f 100644 --- a/build.php +++ b/build.php @@ -252,39 +252,28 @@ } } -if ( isset( $_GET['mode'] ) && $_GET['mode'] == 'troops' && isset( $_GET['cancel'] ) && $_GET['cancel'] == 1 ) { - if ( $session->access != BANNED ) { - $oldmovement = $database->getMovementById( $_GET['moveid'] ); - $now = time(); - - if ( ( $now - $oldmovement[0]['starttime'] ) < 90 && $oldmovement[0]['from'] == $village->wid ) { - - $qc = "SELECT Count(*) as Total FROM " . TB_PREFIX . "movement where proc = 0 and moveid = " . $database->escape( (int) $_GET['moveid'] ); - $resultc = mysqli_fetch_array( mysqli_query( $database->dblink, $qc ), MYSQLI_ASSOC ); - - if ( $resultc['Total'] == 1 ) { - - $q = "UPDATE " . TB_PREFIX . "movement set proc = 1 where proc = 0 and moveid = " . $database->escape( (int) $_GET['moveid'] ); - $database->query( $q ); - $end = $now + ( $now - $oldmovement[0]['starttime'] ); - //echo "6,".$oldmovement[0]['to'].",".$oldmovement[0]['from'].",0,".$now.",".$end; - $q2 = "SELECT id FROM " . TB_PREFIX . "send ORDER BY id DESC"; - $lastid = mysqli_fetch_array( mysqli_query( $database->dblink, $q2 ) ); - $newid = $lastid['id'] + 1; - $q2 = "INSERT INTO " . TB_PREFIX . "send values ($newid,0,0,0,0,0)"; - $database->query( $q2 ); - $database->addMovement( 4, $oldmovement[0]['to'], $oldmovement[0]['from'], $oldmovement[0]['ref'], $now, $end ); - - - $database->addMovement( 6, $oldmovement[0]['to'], $oldmovement[0]['from'], $newid, $now, $end ); - } - } - header( "Location: " . $_SERVER['PHP_SELF'] . "?id=" . $_GET['id'] ); - exit; - } else { - header( "Location: banned.php" ); - exit; - } +if(isset($_GET['mode']) && $_GET['mode'] == 'troops' && isset($_GET['cancel']) && $_GET['cancel'] == 1){ + if($session->access != BANNED){ + $oldmovement = $database->getMovementById($_GET['moveid']); + $now = time(); + if(($now - $oldmovement[0]['starttime']) < 90 && $oldmovement[0]['from'] == $village->wid){ + $qc = "SELECT Count(*) as Total FROM " . TB_PREFIX . "movement where proc = 0 and moveid = " . $database->escape((int)$_GET['moveid']); + $resultc = mysqli_fetch_array(mysqli_query($database->dblink, $qc), MYSQLI_ASSOC); + if($resultc['Total'] == 1){ + $q = "UPDATE " . TB_PREFIX . "movement set proc = 1 where proc = 0 and moveid = " . $database->escape((int)$_GET['moveid']); + $database->query($q); + $end = $now + ($now - $oldmovement[0]['starttime']); + $q2 = "SELECT id FROM " . TB_PREFIX . "send ORDER BY id DESC"; + $lastid = mysqli_fetch_array(mysqli_query($database->dblink, $q2)); + $database->addMovement(4, $oldmovement[0]['to'], $oldmovement[0]['from'], $oldmovement[0]['ref'], $now, $end); + } + } + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $_GET['id']); + exit(); + }else{ + header("Location: banned.php"); + exit(); + } } if(isset($_GET['id'])) $automation->isWinner(); ?> diff --git a/create_account.php b/create_account.php index e3c47d57..1c2111ba 100644 --- a/create_account.php +++ b/create_account.php @@ -234,9 +234,7 @@ function generateBase($kid, $uid, $username) { } } - if ($counter > 0) { - $database->addMovement( $type, $from, $to, $ref, $time, $endtime ); - } + if ($counter > 0) $database->addMovement($type, $from, $to, $ref, $time, $endtime); /** * SMALL ARTEFACTS diff --git a/dorf2.php b/dorf2.php index 9f8570d9..2d2ddb21 100644 --- a/dorf2.php +++ b/dorf2.php @@ -21,9 +21,8 @@ $database->query("UPDATE ".TB_PREFIX."users SET village_select=".$database->escape((int) $_GET['newdid'])." WHERE id=".$session->uid); header("Location: ".$_SERVER['PHP_SELF']); exit; -}else{ -$building->procBuild($_GET); } +else $building->procBuild($_GET); $automation->isWinner(); ?>
noticearray[$i-1]['id']."\" />
noticearray[$i - 1]['id'] . "\" /> "; - $type = (isset($_GET['t']) && $_GET['t'] == 5)? $message->noticearray[$i-1]['archive'] : $message->noticearray[$i-1]['ntype']; - if($type == 23) $type = 22; - if($type >= 15 && $type <= 17){ - $type = $type-11; - echo "\"".$noticeClass[$type]."\""; - }else if($type >= 18 && $type <= 22){ - echo "\"".$noticeClass[$type]."\""; - }else{ - echo "\"".$noticeClass[$type]."\""; - } - echo "
noticearray[$i-1]['id']."\">".$message->noticearray[$i-1]['topic']." "; - if($message->noticearray[$i-1]['viewed'] == 0) { - echo "(new)"; - } - $date = $generator->procMtime($message->noticearray[$i-1]['time']); - echo "
".$date[0]." ".$date[1]."
There are no reports available.
" . $date[0] . " " . $date[1] . "
There are no reports available.