refactor: 1st round of database values caching

This commit is contained in:
Martin Ambrus
2017-11-15 16:01:00 +01:00
parent 06161dd5f9
commit dab768f662
11 changed files with 1675 additions and 1023 deletions
+15 -9
View File
@@ -135,8 +135,13 @@ class Account {
if($uid) {
setcookie("COOKUSR",$_POST['name'],time()+COOKIE_EXPIRE,COOKIE_PATH);
setcookie("COOKEMAIL",$_POST['email'],time()+COOKIE_EXPIRE,COOKIE_PATH);
$database->updateUserField($uid,"act","",1);
$database->updateUserField($uid,"invited",$_POST['invited'],1);
$database->updateUserField(
$uid,
["act", "invited"],
["", $_POST['invited']],
1
);
$this->generateBase($_POST['kid'],$uid,$_POST['name']);
header("Location: login.php");
exit;
@@ -177,7 +182,7 @@ class Account {
private function Unreg() {
global $database;
$q = "SELECT password, username FROM ".TB_PREFIX."activate where id = '".$database->escape((int) $_POST['id'])."'";
$q = "SELECT password, username FROM ".TB_PREFIX."activate where id = ".(int) $_POST['id'];
$result = mysqli_query($GLOBALS['link'],$q);
$dbarray = mysqli_fetch_array($result);
if(password_verify($_POST['pw'], $dbarray['password'])) {
@@ -207,12 +212,14 @@ class Account {
$form->addError("pw",LOGIN_PW_ERROR);
}
if($database->getUserField($_POST['user'],"act",1) != "") {
$userData = $database->getUserArray($_POST['user'], 0);
if($userData["act"] != "") {
$form->addError("activate",$_POST['user']);
}
// Vacation mode by Shadow
if($database->getUserField($_POST['user'],"vac_mode",1) == 1 && $database->getUserField($_POST['user'],"vac_time",1) > time()) {
if($userData["vac_mode"] == 1 && $userData["vac_time"] > time()) {
$form->addError("vacation","Vacation mode is still enabled");
}
@@ -224,14 +231,13 @@ class Account {
header("Location: login.php");
exit;
} else {
$userid = $database->getUserArray($_POST['user'], 0);
// Vacation mode by Shadow
$database->removevacationmode($userid['id']);
$database->removevacationmode($userData['id']);
// Vacation mode by Shadow
if($database->login($_POST['user'],$_POST['pw'])){
$database->UpdateOnline("login" ,$_POST['user'],time(),$userid['id']);
$database->UpdateOnline("login" ,$_POST['user'],time(),$userData['id']);
}else if($database->sitterLogin($_POST['user'],$_POST['pw'])){
$database->UpdateOnline("sitter" ,$_POST['user'],time(),$userid['id']);
$database->UpdateOnline("sitter" ,$_POST['user'],time(),$userData['id']);
}
setcookie("COOKUSR",$_POST['user'],time()+COOKIE_EXPIRE,COOKIE_PATH);
$session->login($_POST['user']);
+20 -19
View File
@@ -380,26 +380,27 @@ class Alliance {
*****************************************/
private function kickAlliUser($post) {
global $database, $session, $form;
if($session->access != BANNED){
$UserData = $database->getUserArray($post['a_user'], 1);
if($this->userPermArray['opt2'] == 0) {
$form->addError("perm", NO_PERMISSION);
} else if($UserData['id'] != $session->uid){
$database->updateUserField($post['a_user'], 'alliance', 0, 1);
$database->deleteAlliPermissions($post['a_user']);
$database->deleteAlliance($session->alliance);
// log the notice
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $UserData['id'] . '">' . addslashes($post['a_user']) . '</a> has quit the alliance.');
if($session->alliance && $database->isAllianceOwner($UserData['id']) == $session->alliance){
$newowner = $database->getAllMember2($session->alliance);
$newleader = $newowner['id'];
$q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $session->alliance."";
$database->query($q);
$database->updateAlliPermissions($newleader, 1, 1, 1, 1, 1, 1, 1, 1, 1);
Automation::updateMax($newleader);
if ($session->access != BANNED) {
$UserData = $database->getUserArray($post['a_user'], 1);
if($this->userPermArray['opt2'] == 0) {
$form->addError("perm", NO_PERMISSION);
} else if($UserData['id'] != $session->uid){
$database->updateUserField($post['a_user'], 'alliance', 0, 1);
$database->deleteAlliPermissions($post['a_user']);
$database->deleteAlliance($session->alliance);
// log the notice
$database->insertAlliNotice($session->alliance, '<a href="spieler.php?uid=' . $UserData['id'] . '">' . addslashes($post['a_user']) . '</a> has quit the alliance.');
if($session->alliance && $database->isAllianceOwner($UserData['id']) == $session->alliance){
$newowner = $database->getAllMember2($session->alliance);
$newleader = $newowner['id'];
$q = "UPDATE " . TB_PREFIX . "alidata set leader = ".(int) $newleader." where id = ".(int) $session->alliance."";
$database->query($q);
$database->updateAlliPermissions($newleader, 1, 1, 1, 1, 1, 1, 1, 1, 1);
Automation::updateMax($newleader);
}
}
}
}else{
} else {
header("Location: banned.php");
exit;
}
+74 -33
View File
@@ -244,7 +244,6 @@ class Automation {
//create new file to check filetime
//not every click regenerate but 1 minute or after
$ourFileHandle = fopen($autoprefix."GameEngine/Prevention/loyalty.txt", 'w');
fclose($ourFileHandle);
global $database;
@@ -1283,7 +1282,7 @@ class Automation {
$database->addMovement(4,0,$data['to'],$attackid,microtime(true),microtime(true)+(180/EVASION_SPEED));
$newgold = $gold-2;
$newmaxevasion = $maxevasion-1;
$database->updateUserFields($DefenderID, ["gold", "maxevasion"], [$newgold, $newmaxevasion], 1);
$database->updateUserField($DefenderID, ["gold", "maxevasion"], [$newgold, $newmaxevasion], 1);
}
}
//get defence units
@@ -2363,9 +2362,11 @@ class Automation {
}
}
$exp1 = $database->getVillageField($from['wref'],'exp1');
$exp2 = $database->getVillageField($from['wref'],'exp2');
$exp3 = $database->getVillageField($from['wref'],'exp3');
$expArray = $database->getVillageFields($from['wref'], 'exp1, exp2, exp3');
$exp1 = $expArray['exp1'];
$exp2 = $expArray['exp2'];
$exp3 = $expArray['exp3'];
if($exp1 == 0){
$villexp = 0;
}
@@ -2381,18 +2382,24 @@ class Automation {
$mode = CP;
$cp_mode = $GLOBALS['cp'.$mode];
$need_cps = $cp_mode[count($varray1)+1];
$user_cps = $database->getUserField($from['owner'],"cp",0);
//see if last village, or village head
if (!isset($cachedUserData[$from['owner']])) {
$cachedUserData[$from['owner']] = $database->getUserArray($from['owner'], 1);
}
$user_cps = $cachedUserData[$from['owner']]['cp'];
//check for last village or capital
if($user_cps >= $need_cps){
if(count($varray)!='1' AND $to['capital']!='1' AND $villexp < $canconquer){
if($to['owner']!=3 OR $to['name']!='WW Buildingplan'){
//if there is no Palace/Residence
for ($i=18; $i<39; $i++){
if ($database->getFieldLevel($data['to'],"".$i."t")==25 or $database->getFieldLevel($data['to'],"".$i."t")==26){
$nochiefing='1';
$info_chief = "".$chief_pic.",The Palace/Residence isn\'t destroyed!";
}
// check for standing Palace or Residence
if ($database->getFieldLevelInVillage($data['to'], '25, 26')) {
$nochiefing = 1;
$info_chief = "".$chief_pic.",The Palace/Residence isn\'t destroyed!";
}
// we can conquer this village
if(!isset($nochiefing)){
//$info_chief = "".$chief_pic.",You don't have enought CP to chief a village.";
if($this->getTypeLevel(35,$data['from']) == 0){
@@ -2408,31 +2415,46 @@ class Automation {
$rand+=rand(5,15);
}
}
//loyalty is more than 0
if(($toF['loyalty']-$rand)>0){
// loyalty is more than 0
if (($toF['loyalty']-$rand) > 0) {
$info_chief = "".$chief_pic.",The loyalty was lowered from <b>".floor($toF['loyalty'])."</b> to <b>".floor($toF['loyalty']-$rand)."</b>.";
$database->setVillageField($data['to'],'loyalty',($toF['loyalty']-$rand));
} else if (!$village_destroyed) {
//you took over the village
// you took over the village
$villname = addslashes($database->getVillageField($data['to'],"name"));
$artifact = $database->getOwnArtefactInfo($data['to']);
$info_chief = "".$chief_pic.",Inhabitants of ".$villname." village decided to join your empire.";
if ($artifact['vref'] == $data['to']){
$database->claimArtefact($data['to'],$data['to'],$database->getVillageField($data['from'],"owner"));
if (!isset($villageOwners[$data['from']])) {
$villageOwners[$data['from']] = $database->getVillageField($data['from'],"owner");
}
$database->claimArtefact($data['to'], $data['to'], $villageOwners[$data['from']]);
}
$database->setVillageField($data['to'],'loyalty',0);
$database->setVillageField($data['to'],'owner',$database->getVillageField($data['from'],"owner"));
$database->setVillageFields(
$data['to'],
['loyalty', 'owner'],
[0, $villageOwners[$data['from']]]
);
//delete upgrades in armory and blacksmith
$q = "DELETE FROM ".TB_PREFIX."abdata WHERE vref = ".(int) $data['to']."";
$q = "DELETE FROM ".TB_PREFIX."abdata WHERE vref = ".(int) $data['to'];
$database->query($q);
$database->addABTech($data['to']);
//delete researches in academy
$q = "DELETE FROM ".TB_PREFIX."tdata WHERE vref = ".(int) $data['to']."";
$q = "DELETE FROM ".TB_PREFIX."tdata WHERE vref = ".(int) $data['to'];
$database->query($q);
$database->addTech($data['to']);
//delete reinforcement
$q = "DELETE FROM ".TB_PREFIX."enforcement WHERE `from` = ".(int) $data['to']."";
$q = "DELETE FROM ".TB_PREFIX."enforcement WHERE `from` = ".(int) $data['to'];
$database->query($q);
//no units can stay in the village itself
$units2reset = [];
for ($u = 1; $u <= 50; $u++) {
@@ -2443,36 +2465,50 @@ class Automation {
$units2reset[] = 'hero = 0';
$q = "UPDATE ".TB_PREFIX."units SET ".implode(',', $units2reset)." WHERE vref = ".(int) $data['to'];
$database->query($q);
// check buildings
$newLevels_fieldNames = [];
$newLevels_fieldValues = [];
$pop1 = $database->getVillageField($data['from'],"pop");
$pop2 = $database->getVillageField($data['to'],"pop");
if($pop1 > $pop2){
$buildlevel = $database->getResourceLevel($data['to']);
for ($i=1; $i<=39; $i++){
if($buildlevel['f'.$i]!=0){
if($buildlevel['f'.$i."t"]!=35 && $buildlevel['f'.$i."t"]!=36 && $buildlevel['f'.$i."t"]!=41){
$leveldown = $buildlevel['f'.$i]-1;
$database->setVillageLevel($data['to'],"f".$i,$leveldown);
$newLevels_fieldNames[] = "f".$i;
$newLevels_fieldValues[] = $leveldown;
}else{
$database->setVillageLevel($data['to'],"f".$i,0);
$database->setVillageLevel($data['to'],"f".$i."t",0);
$newLevels_fieldNames[] = "f".$i;
$newLevels_fieldValues[] = 0;
$newLevels_fieldNames[] = "f".$i."t";
$newLevels_fieldValues[] = 0;
}
}
}
if($buildlevel['f99']!=0){
if ($buildlevel['f99']!=0) {
$leveldown = $buildlevel['f99']-1;
$database->setVillageLevel($data['to'],"f99",$leveldown);
$newLevels_fieldNames[] = "f99";
$newLevels_fieldValues[] = $leveldown;
}
}
//destroy wall
$database->setVillageLevel($data['to'],"f40",0);
$database->setVillageLevel($data['to'],"f40t",0);
$database->clearExpansionSlot($data['to']);
$newLevels_fieldNames[] = "f40";
$newLevels_fieldValues[] = 0;
$newLevels_fieldNames[] = "f40t";
$newLevels_fieldValues[] = 0;
$exp1 = $database->getVillageField($data['from'],'exp1');
$exp2 = $database->getVillageField($data['from'],'exp2');
$exp3 = $database->getVillageField($data['from'],'exp3');
$expArray = $database->getVillageFields($data['from'], 'exp1, exp2, exp3');
$exp1 = $expArray['exp1'];
$exp2 = $expArray['exp2'];
$exp3 = $expArray['exp3'];
if($exp1 == 0){
$exp = 'exp1';
@@ -2486,11 +2522,16 @@ class Automation {
$exp = 'exp3';
$value = $data['to'];
}
$database->setVillageField($data['from'],$exp,$value);
//remove oasis related to village
$units->returnTroops($data['to'],1);
$chiefing_village = 1;
// update data in the database
$database->clearExpansionSlot($data['to']);
$database->setVillageLevel($data['to'], $newLevels_fieldNames, $newLevels_fieldValues);
}
}
} else {
+587 -584
View File
File diff suppressed because it is too large Load Diff
+729 -180
View File
File diff suppressed because it is too large Load Diff
View File
+32 -16
View File
@@ -94,7 +94,10 @@ class Market
$wtrans = str_replace("-", "", $wtrans);
$ctrans = str_replace("-", "", $ctrans);
$itrans = str_replace("-", "", $itrans);
$crtrans = str_replace("-", "", $crtrans);
$crtrans = str_replace("-", "", $crtrans);
// preload all village data, since we're retrieving some of those separately below
$database->getVillage($village->wid);
$availableWood = $database->getWoodAvailable($village->wid);
$availableClay = $database->getClayAvailable($village->wid);
$availableIron = $database->getIronAvailable($village->wid);
@@ -130,8 +133,9 @@ class Market
exit;
}
else
{
// something
{
// TODO: WTF??? :D
// something
}
}
@@ -163,7 +167,11 @@ class Market
$wood = ($post['rid1'] == 1)? $post['m1'] : 0;
$clay = ($post['rid1'] == 2)? $post['m1'] : 0;
$iron = ($post['rid1'] == 3)? $post['m1'] : 0;
$crop = ($post['rid1'] == 4)? $post['m1'] : 0;
$crop = ($post['rid1'] == 4)? $post['m1'] : 0;
// preload all village data, since we're retrieving some of those separately below
$database->getVillage($village->wid);
$availableWood = $database->getWoodAvailable($village->wid);
$availableClay = $database->getClayAvailable($village->wid);
$availableIron = $database->getIronAvailable($village->wid);
@@ -235,16 +243,23 @@ class Market
}
}
$myresource = $hisresource = array(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'];
$hissendid = $database->sendResource($hisresource[1],$hisresource[2],$hisresource[3],$hisresource[4],$infoarray['merchant'],0);
$myresource[$infoarray['wtype']] = $infoarray['wamt'];
$mysendid = $database->sendResource($myresource[1],$myresource[2],$myresource[3],$myresource[4],$reqMerc,0);
$hisresource[$infoarray['gtype']] = $infoarray['gamt'];
$hissendid = $database->sendResource($hisresource[1],$hisresource[2],$hisresource[3],$hisresource[4],$infoarray['merchant'],0);
$hiscoor = $database->getCoor($infoarray['vref']);
$mytime = $generator->procDistanceTime($hiscoor,$village->coor,$session->tribe,0);
$targettribe = $database->getUserField($database->getVillageField($infoarray['vref'],"owner"),"tribe",0);
$histime = $generator->procDistanceTime($village->coor,$hiscoor,$targettribe,0);
$database->addMovement(0,$village->wid,$infoarray['vref'],$mysendid,time(),$mytime+time());
$database->addMovement(0,$infoarray['vref'],$village->wid,$hissendid,time(),$histime+time());
$histime = $generator->procDistanceTime($village->coor,$hiscoor,$targettribe,0);
$timestamp = time();
$database->addMovement(
[0, 0],
[$village->wid, $infoarray['vref']],
[$infoarray['vref'], $village->wid],
[$mysendid, $hissendid],
[$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);
@@ -346,11 +361,12 @@ class Market
}
else if (($post['m2'][0]+$post['m2'][1]+$post['m2'][2]+$post['m2'][3])<=(round($village->awood)+round($village->aclay)+round($village->airon)+round($village->acrop)))
{
$database->setVillageField($village->wid,"wood",$post['m2'][0]);
$database->setVillageField($village->wid,"clay",$post['m2'][1]);
$database->setVillageField($village->wid,"iron",$post['m2'][2]);
$database->setVillageField($village->wid,"crop",$post['m2'][3]);
$database->modifyGold($session->uid,3,0);
$database->setVillageField(
$village->wid,
["wood", "clay", "iron", "crop"],
[$post['m2'][0], $post['m2'][1], $post['m2'][2], $post['m2'][3]]
);
$database->modifyGold($session->uid,3,0);
header("Location: build.php?id=".$post['id']."&t=3&c");;
exit;
}
+191 -171
View File
@@ -40,9 +40,9 @@ class Message {
break;
case "m2":
if ($post['an'] == "[ally]"){
$this->sendAMessage($post['be'],addslashes($post['message']));
$this->sendAMessage($post['be'],addslashes($post['message']));
}else{
$this->sendMessage($post['an'],$post['be'],addslashes($post['message']));
$this->sendMessage($post['an'],$post['be'],addslashes($post['message']));
}
header("Location: nachrichten.php?t=2");
exit;
@@ -51,8 +51,8 @@ class Message {
case "m4":
case "m5":
if(isset($post['delmsg_x'])) {
$this->removeMessage($post);
$this->header($get);
$this->removeMessage($post);
$this->header($get);
}
if(isset($post['archive_x'])) {
$this->archiveMessage($post);
@@ -346,75 +346,83 @@ class Message {
$allmembersQ = mysqli_query($GLOBALS['link'],"SELECT id FROM ".TB_PREFIX."users WHERE alliance='".$session->alliance."'");
$userally = $database->getUserField($session->uid,"alliance",0);
$permission=mysqli_fetch_array(mysqli_query($GLOBALS['link'],"SELECT opt7 FROM ".TB_PREFIX."ali_permission WHERE uid='".$session->uid."'"));
if(WORD_CENSOR) {
$topic = $this->wordCensor($topic);
$text = $this->wordCensor($text);
$topic = $this->wordCensor($topic);
$text = $this->wordCensor($text);
}
if($topic == "") {
$topic = "No subject";
$topic = "No subject";
}
if(!preg_match('/\[message\]/',$text) && !preg_match('/\[\/message\]/',$text)){
$text = "[message]".$text."[/message]";
$alliance = $player = $coor = $report = 0;
for($i=0;$i<=$alliance;$i++){
if(preg_match('/\[alliance'.$i.'\]/',$text) && preg_match('/\[\/alliance'.$i.'\]/',$text)){
$alliance1 = preg_replace('/\[message\](.*?)\[\/alliance'.$i.'\]/is', '', $text);
if(preg_match('/\[alliance'.$i.'\]/',$alliance1) && preg_match('/\[\/alliance'.$i.'\]/',$alliance1)){
$j = $i+1;
$alliance2 = preg_replace('/\[\/alliance'.$i.'\](.*?)\[\/message\]/is', '', $text);
$alliance1 = preg_replace('/\[alliance'.$i.'\]/', '[alliance'.$j.']', $alliance1);
$alliance1 = preg_replace('/\[\/alliance'.$i.'\]/', '[/alliance'.$j.']', $alliance1);
$text = $alliance2."[/alliance".$i."]".$alliance1;
$alliance += 1;
}
}
}
for($i=0;$i<=$player;$i++){
if(preg_match('/\[player'.$i.'\]/',$text) && preg_match('/\[\/player'.$i.'\]/',$text)){
$player1 = preg_replace('/\[message\](.*?)\[\/player'.$i.'\]/is', '', $text);
if(preg_match('/\[player'.$i.'\]/',$player1) && preg_match('/\[\/player'.$i.'\]/',$player1)){
$j = $i+1;
$player2 = preg_replace('/\[\/player'.$i.'\](.*?)\[\/message\]/is', '', $text);
$player1 = preg_replace('/\[player'.$i.'\]/', '[player'.$j.']', $player1);
$player1 = preg_replace('/\[\/player'.$i.'\]/', '[/player'.$j.']', $player1);
$text = $player2."[/player".$i."]".$player1;
$player += 1;
}
}
}
for($i=0;$i<=$coor;$i++){
if(preg_match('/\[coor'.$i.'\]/',$text) && preg_match('/\[\/coor'.$i.'\]/',$text)){
$coor1 = preg_replace('/\[message\](.*?)\[\/coor'.$i.'\]/is', '', $text);
if(preg_match('/\[coor'.$i.'\]/',$coor1) && preg_match('/\[\/coor'.$i.'\]/',$coor1)){
$j = $i+1;
$coor2 = preg_replace('/\[\/coor'.$i.'\](.*?)\[\/message\]/is', '', $text);
$coor1 = preg_replace('/\[coor'.$i.'\]/', '[coor'.$j.']', $coor1);
$coor1 = preg_replace('/\[\/coor'.$i.'\]/', '[/coor'.$j.']', $coor1);
$text = $coor2."[/coor".$i."]".$coor1;
$coor += 1;
}
}
}
for($i=0;$i<=$report;$i++){
if(preg_match('/\[report'.$i.'\]/',$text) && preg_match('/\[\/report'.$i.'\]/',$text)){
$report1 = preg_replace('/\[message\](.*?)\[\/report'.$i.'\]/is', '', $text);
if(preg_match('/\[report'.$i.'\]/',$report1) && preg_match('/\[\/report'.$i.'\]/',$report1)){
$j = $i+1;
$report2 = preg_replace('/\[\/report'.$i.'\](.*?)\[\/message\]/is', '', $text);
$report1 = preg_replace('/\[report'.$i.'\]/', '[report'.$j.']', $report1);
$report1 = preg_replace('/\[\/report'.$i.'\]/', '[/report'.$j.']', $report1);
$text = $report2."[/report".$i."]".$report1;
$report += 1;
}
}
}
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);
}
}
}
$text = "[message]".$text."[/message]";
$alliance = $player = $coor = $report = 0;
for ( $i = 0; $i <= $alliance; $i ++ ) {
if ( preg_match( '/\[alliance' . $i . '\]/', $text ) && preg_match( '/\[\/alliance' . $i . '\]/', $text ) ) {
$alliance1 = preg_replace( '/\[message\](.*?)\[\/alliance' . $i . '\]/is', '', $text );
if ( preg_match( '/\[alliance' . $i . '\]/', $alliance1 ) && preg_match( '/\[\/alliance' . $i . '\]/', $alliance1 ) ) {
$j = $i + 1;
$alliance2 = preg_replace( '/\[\/alliance' . $i . '\](.*?)\[\/message\]/is', '', $text );
$alliance1 = preg_replace( '/\[alliance' . $i . '\]/', '[alliance' . $j . ']', $alliance1 );
$alliance1 = preg_replace( '/\[\/alliance' . $i . '\]/', '[/alliance' . $j . ']', $alliance1 );
$text = $alliance2 . "[/alliance" . $i . "]" . $alliance1;
$alliance += 1;
}
}
}
for ( $i = 0; $i <= $player; $i ++ ) {
if ( preg_match( '/\[player' . $i . '\]/', $text ) && preg_match( '/\[\/player' . $i . '\]/', $text ) ) {
$player1 = preg_replace( '/\[message\](.*?)\[\/player' . $i . '\]/is', '', $text );
if ( preg_match( '/\[player' . $i . '\]/', $player1 ) && preg_match( '/\[\/player' . $i . '\]/', $player1 ) ) {
$j = $i + 1;
$player2 = preg_replace( '/\[\/player' . $i . '\](.*?)\[\/message\]/is', '', $text );
$player1 = preg_replace( '/\[player' . $i . '\]/', '[player' . $j . ']', $player1 );
$player1 = preg_replace( '/\[\/player' . $i . '\]/', '[/player' . $j . ']', $player1 );
$text = $player2 . "[/player" . $i . "]" . $player1;
$player += 1;
}
}
}
for ( $i = 0; $i <= $coor; $i ++ ) {
if ( preg_match( '/\[coor' . $i . '\]/', $text ) && preg_match( '/\[\/coor' . $i . '\]/', $text ) ) {
$coor1 = preg_replace( '/\[message\](.*?)\[\/coor' . $i . '\]/is', '', $text );
if ( preg_match( '/\[coor' . $i . '\]/', $coor1 ) && preg_match( '/\[\/coor' . $i . '\]/', $coor1 ) ) {
$j = $i + 1;
$coor2 = preg_replace( '/\[\/coor' . $i . '\](.*?)\[\/message\]/is', '', $text );
$coor1 = preg_replace( '/\[coor' . $i . '\]/', '[coor' . $j . ']', $coor1 );
$coor1 = preg_replace( '/\[\/coor' . $i . '\]/', '[/coor' . $j . ']', $coor1 );
$text = $coor2 . "[/coor" . $i . "]" . $coor1;
$coor += 1;
}
}
}
for ( $i = 0; $i <= $report; $i ++ ) {
if ( preg_match( '/\[report' . $i . '\]/', $text ) && preg_match( '/\[\/report' . $i . '\]/', $text ) ) {
$report1 = preg_replace( '/\[message\](.*?)\[\/report' . $i . '\]/is', '', $text );
if ( preg_match( '/\[report' . $i . '\]/', $report1 ) && preg_match( '/\[\/report' . $i . '\]/', $report1 ) ) {
$j = $i + 1;
$report2 = preg_replace( '/\[\/report' . $i . '\](.*?)\[\/message\]/is', '', $text );
$report1 = preg_replace( '/\[report' . $i . '\]/', '[report' . $j . ']', $report1 );
$report1 = preg_replace( '/\[\/report' . $i . '\]/', '[/report' . $j . ']', $report1 );
$text = $report2 . "[/report" . $i . "]" . $report1;
$report += 1;
}
}
}
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);
}
}
}
}
}
@@ -438,69 +446,75 @@ class Message {
$topic = $this->wordCensor($topic);
$text = $this->wordCensor($text);
}
if($topic == "") {
$topic = "No subject";
}
if(!preg_match('/\[message\]/',$text) && !preg_match('/\[\/message\]/',$text)){
$text = "[message]".$text."[/message]";
$alliance = $player = $coor = $report = 0;
for($i=0;$i<=$alliance;$i++){
if(preg_match('/\[alliance'.$i.'\]/',$text) && preg_match('/\[\/alliance'.$i.'\]/',$text)){
$alliance1 = preg_replace('/\[message\](.*?)\[\/alliance'.$i.'\]/is', '', $text);
if(preg_match('/\[alliance'.$i.'\]/',$alliance1) && preg_match('/\[\/alliance'.$i.'\]/',$alliance1)){
$j = $i+1;
$alliance2 = preg_replace('/\[\/alliance'.$i.'\](.*?)\[\/message\]/is', '', $text);
$alliance1 = preg_replace('/\[alliance'.$i.'\]/', '[alliance'.$j.']', $alliance1);
$alliance1 = preg_replace('/\[\/alliance'.$i.'\]/', '[/alliance'.$j.']', $alliance1);
$text = $alliance2."[/alliance".$i."]".$alliance1;
$alliance += 1;
}
}
}
for($i=0;$i<=$player;$i++){
if(preg_match('/\[player'.$i.'\]/',$text) && preg_match('/\[\/player'.$i.'\]/',$text)){
$player1 = preg_replace('/\[message\](.*?)\[\/player'.$i.'\]/is', '', $text);
if(preg_match('/\[player'.$i.'\]/',$player1) && preg_match('/\[\/player'.$i.'\]/',$player1)){
$j = $i+1;
$player2 = preg_replace('/\[\/player'.$i.'\](.*?)\[\/message\]/is', '', $text);
$player1 = preg_replace('/\[player'.$i.'\]/', '[player'.$j.']', $player1);
$player1 = preg_replace('/\[\/player'.$i.'\]/', '[/player'.$j.']', $player1);
$text = $player2."[/player".$i."]".$player1;
$player += 1;
}
}
}
for($i=0;$i<=$coor;$i++){
if(preg_match('/\[coor'.$i.'\]/',$text) && preg_match('/\[\/coor'.$i.'\]/',$text)){
$coor1 = preg_replace('/\[message\](.*?)\[\/coor'.$i.'\]/is', '', $text);
if(preg_match('/\[coor'.$i.'\]/',$coor1) && preg_match('/\[\/coor'.$i.'\]/',$coor1)){
$j = $i+1;
$coor2 = preg_replace('/\[\/coor'.$i.'\](.*?)\[\/message\]/is', '', $text);
$coor1 = preg_replace('/\[coor'.$i.'\]/', '[coor'.$j.']', $coor1);
$coor1 = preg_replace('/\[\/coor'.$i.'\]/', '[/coor'.$j.']', $coor1);
$text = $coor2."[/coor".$i."]".$coor1;
$coor += 1;
}
}
}
for($i=0;$i<=$report;$i++){
if(preg_match('/\[report'.$i.'\]/',$text) && preg_match('/\[\/report'.$i.'\]/',$text)){
$report1 = preg_replace('/\[message\](.*?)\[\/report'.$i.'\]/is', '', $text);
if(preg_match('/\[report'.$i.'\]/',$report1) && preg_match('/\[\/report'.$i.'\]/',$report1)){
$j = $i+1;
$report2 = preg_replace('/\[\/report'.$i.'\](.*?)\[\/message\]/is', '', $text);
$report1 = preg_replace('/\[report'.$i.'\]/', '[report'.$j.']', $report1);
$report1 = preg_replace('/\[\/report'.$i.'\]/', '[/report'.$j.']', $report1);
$text = $report2."[/report".$i."]".$report1;
$report += 1;
}
}
}
// check if we're not sending this as support
$support_from_admin_allowed = (($session->access == MULTIHUNTER || $session->access == ADMIN) && ADMIN_RECEIVE_SUPPORT_MESSAGES);
$database->sendMessage($user, ((!empty($_POST['as_support']) && $support_from_admin_allowed) ? 1 : $session->uid), htmlspecialchars(addslashes($topic)), htmlspecialchars(addslashes($text)), 0, $alliance, $player, $coor, $report);
}
if ( ! preg_match( '/\[message\]/', $text ) && ! preg_match( '/\[\/message\]/', $text ) ) {
$text = "[message]" . $text . "[/message]";
$alliance = $player = $coor = $report = 0;
for ( $i = 0; $i <= $alliance; $i ++ ) {
if ( preg_match( '/\[alliance' . $i . '\]/', $text ) && preg_match( '/\[\/alliance' . $i . '\]/', $text ) ) {
$alliance1 = preg_replace( '/\[message\](.*?)\[\/alliance' . $i . '\]/is', '', $text );
if ( preg_match( '/\[alliance' . $i . '\]/', $alliance1 ) && preg_match( '/\[\/alliance' . $i . '\]/', $alliance1 ) ) {
$j = $i + 1;
$alliance2 = preg_replace( '/\[\/alliance' . $i . '\](.*?)\[\/message\]/is', '', $text );
$alliance1 = preg_replace( '/\[alliance' . $i . '\]/', '[alliance' . $j . ']', $alliance1 );
$alliance1 = preg_replace( '/\[\/alliance' . $i . '\]/', '[/alliance' . $j . ']', $alliance1 );
$text = $alliance2 . "[/alliance" . $i . "]" . $alliance1;
$alliance += 1;
}
}
}
for ( $i = 0; $i <= $player; $i ++ ) {
if ( preg_match( '/\[player' . $i . '\]/', $text ) && preg_match( '/\[\/player' . $i . '\]/', $text ) ) {
$player1 = preg_replace( '/\[message\](.*?)\[\/player' . $i . '\]/is', '', $text );
if ( preg_match( '/\[player' . $i . '\]/', $player1 ) && preg_match( '/\[\/player' . $i . '\]/', $player1 ) ) {
$j = $i + 1;
$player2 = preg_replace( '/\[\/player' . $i . '\](.*?)\[\/message\]/is', '', $text );
$player1 = preg_replace( '/\[player' . $i . '\]/', '[player' . $j . ']', $player1 );
$player1 = preg_replace( '/\[\/player' . $i . '\]/', '[/player' . $j . ']', $player1 );
$text = $player2 . "[/player" . $i . "]" . $player1;
$player += 1;
}
}
}
for ( $i = 0; $i <= $coor; $i ++ ) {
if ( preg_match( '/\[coor' . $i . '\]/', $text ) && preg_match( '/\[\/coor' . $i . '\]/', $text ) ) {
$coor1 = preg_replace( '/\[message\](.*?)\[\/coor' . $i . '\]/is', '', $text );
if ( preg_match( '/\[coor' . $i . '\]/', $coor1 ) && preg_match( '/\[\/coor' . $i . '\]/', $coor1 ) ) {
$j = $i + 1;
$coor2 = preg_replace( '/\[\/coor' . $i . '\](.*?)\[\/message\]/is', '', $text );
$coor1 = preg_replace( '/\[coor' . $i . '\]/', '[coor' . $j . ']', $coor1 );
$coor1 = preg_replace( '/\[\/coor' . $i . '\]/', '[/coor' . $j . ']', $coor1 );
$text = $coor2 . "[/coor" . $i . "]" . $coor1;
$coor += 1;
}
}
}
for ( $i = 0; $i <= $report; $i ++ ) {
if ( preg_match( '/\[report' . $i . '\]/', $text ) && preg_match( '/\[\/report' . $i . '\]/', $text ) ) {
$report1 = preg_replace( '/\[message\](.*?)\[\/report' . $i . '\]/is', '', $text );
if ( preg_match( '/\[report' . $i . '\]/', $report1 ) && preg_match( '/\[\/report' . $i . '\]/', $report1 ) ) {
$j = $i + 1;
$report2 = preg_replace( '/\[\/report' . $i . '\](.*?)\[\/message\]/is', '', $text );
$report1 = preg_replace( '/\[report' . $i . '\]/', '[report' . $j . ']', $report1 );
$report1 = preg_replace( '/\[\/report' . $i . '\]/', '[/report' . $j . ']', $report1 );
$text = $report2 . "[/report" . $i . "]" . $report1;
$report += 1;
}
}
}
// check if we're not sending this as support
$support_from_admin_allowed = ( ( $session->access == MULTIHUNTER || $session->access == ADMIN ) && ADMIN_RECEIVE_SUPPORT_MESSAGES );
$database->sendMessage( $user, ( ( ! empty( $_POST['as_support'] ) && $support_from_admin_allowed ) ? 1 : $session->uid ), htmlspecialchars( addslashes( $topic ) ), htmlspecialchars( addslashes( $text ) ), 0, $alliance, $player, $coor, $report );
}
}
//7 = village, attacker, att tribe, u1 - u10, lost %, w,c,i,c , cap
@@ -511,15 +525,15 @@ class Message {
public function sendWelcome($uid, $username) {
global $database;
$welcomemsg = file_get_contents("GameEngine/Admin/welcome.tpl");
$welcomemsg = preg_replace("'%USER%'", $username, $welcomemsg);
$welcomemsg = preg_replace("'%START%'", date("y.m.d", COMMENCE), $welcomemsg);
$welcomemsg = preg_replace("'%TIME%'", date("H:i", COMMENCE), $welcomemsg);
$welcomemsg = preg_replace("'%PLAYERS%'", $database->countUser(), $welcomemsg);
$welcomemsg = preg_replace("'%ALLI%'", $database->countAlli(), $welcomemsg);
$welcomemsg = preg_replace("'%SERVER_NAME%'", SERVER_NAME, $welcomemsg);
$welcomemsg = preg_replace("'%PROTECTION%'", (PROTECTION/3600), $welcomemsg);
$welcomemsg = "[message]".$welcomemsg."[/message]";
$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))],
$welcomemsg
)."[/message]";
return $database->sendMessage($uid, 1, WEL_TOPIC, addslashes($welcomemsg), 0, 0, 0, 0, 0);
}
@@ -578,41 +592,47 @@ class Message {
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;
}
}
+19 -6
View File
@@ -97,8 +97,7 @@ class Profile {
for($i=0;$i<=count($varray)-1;$i++) {
$k = trim($post['dname'.$i]);
$name = preg_replace("/[^a-zA-Z0-9_-\s]/", "", $k);
$database->setVillageName($database->RemoveXSS($varray[$i]['wref']),$name);
$database->setVillageName($database->RemoveXSS($varray[$i]['wref']),$k);
$database->setVillageName($varray[$i]['wref'],$database->RemoveXSS($name));
}
header("Location: spieler.php?uid=".$post['uid']);
exit;
@@ -146,13 +145,14 @@ class Profile {
private function updateAccount($post) {
global $database,$session,$form;
if($post['pw2'] == $post['pw3']) {
if($database->login($session->username,$post['pw1'])) {
if ($_POST['uid'] != $session->uid){
die("Hacking Attempr");
} else {
$database->updateUserField($post['uid'],"password",password_hash($post['pw2'], PASSWORD_BCRYPT,['cost' => 12]),1);
}
die("Hacking Attempr");
} else {
$database->updateUserField($post['uid'],"password",password_hash($post['pw2'], PASSWORD_BCRYPT,['cost' => 12]),1);
}
}
else {
$form->addError("pw",LOGIN_PW_ERROR);
@@ -161,18 +161,24 @@ class Profile {
else {
$form->addError("pw",PASS_MISMATCH);
}
if($post['email_alt'] == $session->userinfo['email']) {
$database->updateUserField($post['uid'],"email",$post['email_neu'],1);
}
else {
$form->addError("email",EMAIL_ERROR);
}
if($post['del'] && password_verify($post['del_pw'], $session->userinfo['password'])) {
$database->setDeleting($post['uid'],0);
}
else {
$form->addError("del",PASS_MISMATCH);
}
if($post['v1'] != "") {
$sitid = $database->getUserField($post['v1'],"id",1);
if($sitid == $session->userinfo['sit1'] || $sitid == $session->userinfo['sit2']) {
@@ -187,6 +193,7 @@ class Profile {
}
}
}
$_SESSION['errorarray'] = $form->getErrors();
header("Location: spieler.php?s=3");
exit;
@@ -194,12 +201,15 @@ class Profile {
private function removeSitter($get) {
global $database,$session;
if($get['a'] == $session->checker) {
if($session->userinfo['sit'.$get['type']] == $get['id']) {
$database->updateUserField($session->uid,"sit".$get['type'],0,1);
}
$session->changeChecker();
}
header("Location: spieler.php?s=".$get['s']);
exit;
}
@@ -213,13 +223,16 @@ class Profile {
private function removeMeSit($get) {
global $database,$session;
if($get['a'] == $session->checker) {
$database->removeMeSit($get['id'],$session->uid);
$session->changeChecker();
}
header("Location: spieler.php?s=".$get['s']);
exit;
}
};
$profile = new Profile;
?>
+6 -4
View File
@@ -102,7 +102,9 @@ class Session {
$user_sanitized = $database->escape($user);
$_SESSION['checker'] = $generator->generateRandStr(3);
$_SESSION['mchecker'] = $generator->generateRandStr(5);
$_SESSION['qst'] = $database->getUserField($user_sanitized, "quest", 1);
$userFields = $database->getUserFields($user_sanitized, "quest, id", 1, true);
$_SESSION['qst'] = $userFields["quest"];
$result = mysqli_query($GLOBALS['link'],"SELECT id, village_select FROM `". TB_PREFIX."users` WHERE `username`='".$user_sanitized."'");
$dbarray = mysqli_fetch_assoc($result);
@@ -113,7 +115,7 @@ class Session {
if($selected_village!='') {
$query = mysqli_query($GLOBALS['link'],'SELECT wref FROM `' . TB_PREFIX . 'vdata` WHERE `wref` = '.$selected_village);
}else{
$query = mysqli_query($GLOBALS['link'],'SELECT wref FROM `' . TB_PREFIX . 'vdata` WHERE `owner` = ' . (int) $database->getUserField($user_sanitized, "id", 1) . ' LIMIT 1');
$query = mysqli_query($GLOBALS['link'],'SELECT wref FROM `' . TB_PREFIX . 'vdata` WHERE `owner` = ' . $userFields["id"] . ' LIMIT 1');
}
$data = mysqli_fetch_assoc($query);
$_SESSION['wid'] = $data['wref'];
@@ -122,7 +124,7 @@ class Session {
if($selected_village!='') {
$query = mysqli_query($GLOBALS['link'],'SELECT wref FROM `' . TB_PREFIX . 'vdata` WHERE `wref` = '.$selected_village);
}else{
$query = mysqli_query($GLOBALS['link'],'SELECT wref FROM `' . TB_PREFIX . 'vdata` WHERE `owner` = ' . (int) $database->getUserField($user_sanitized, "id", 1) . ' LIMIT 1');
$query = mysqli_query($GLOBALS['link'],'SELECT wref FROM `' . TB_PREFIX . 'vdata` WHERE `owner` = ' . $userFields["id"] . ' LIMIT 1');
}
$data = mysqli_fetch_assoc($query);
$_SESSION['wid'] = $data['wref'];
@@ -196,7 +198,7 @@ class Session {
$database->updateUserField($user, "timestamp", $this->time, 0);
return true;
} else {
return false;
return false;
}
}
+2 -1
View File
@@ -37,10 +37,11 @@ class Village {
}
//add new line code
//check exist village if from village destroy to avoid error msg.
if (!$database-> checkVilExist($this->wid)) {
if ( !$database->checkVilExist($this->wid) ) {
$this->wid=$database->getVillageID($session->uid);
$_SESSION['wid']=$this->wid;
}
$this->LoadTown();
$this->calculateProduction();
$this->processProduction();