Some fix and add protected players

Some fix and add protected players
This commit is contained in:
novgorodschi catalin
2026-08-10 12:37:56 +03:00
parent d325fce01f
commit 1ecbba0e26
12 changed files with 193 additions and 93 deletions
@@ -352,6 +352,7 @@ if (!function_exists('tz_config_finalize')) {
}
$defaults = array(
'PROTECTED_PLAYERS' => '',
'NATARS_WW_START_DELAY' => 10,
'USRNM_MIN_LENGTH' => 3,
'USRNM_MAX_LENGTH' => 15,
+4
View File
@@ -140,6 +140,10 @@ $text = admin_config_template_contents(array(
tz_config_set($text, '%PWMIN%', $pMin);
tz_config_set($text, '%SERVERNAME%', $_POST['servername'] ?? '');
// Jucatori protejati impotriva atacurilor. Scoatem ghilimelele, ca sirul
// intra intre ghilimele in config.php.
tz_config_set($text, '%PROTECTEDPLAYERS%',
trim(str_replace('"', '', $_POST['protected_players'] ?? '')));
// Fusul orar se scrie intr-un fisier PHP (define("TIMEZONE","...")), deci
// valoarea NU are voie sa ajunga acolo nefiltrata: pana acum $_POST['tzone']
// era inserat ca atare, ceea ce permitea scrierea de cod in config.php.
+6
View File
@@ -4360,3 +4360,9 @@ tz_def('TZ_WW_NO_CAPITAL', 'The World Wonder village cannot become your capital.
// BONUSURI DE ALIANTA - donatie peste necesarul ultimului nivel
//////////////////////////////////////////////////////////////////////////////////////////////////////
tz_def('ALLYBONUS_MSG_OVERMAX', 'This is the final level: you can donate at most %s more resources.');
//////////////////////////////////////////////////////////////////////////////////////////////////////
// JUCATORI PROTEJATI IMPOTRIVA ATACURILOR
//////////////////////////////////////////////////////////////////////////////////////////////////////
tz_def('ADM_PROTECTED_PLAYERS', 'Protected players');
tz_def('ADM_PROTECTED_PLAYERS_TIP', 'Comma-separated player names that cannot be attacked or raided by anyone. Reinforcements are still allowed. Leave empty to disable.');
+6
View File
@@ -4303,3 +4303,9 @@ tz_def('TZ_WW_NO_CAPITAL', 'Le village de la Merveille du Monde ne peut pas deve
// BONUSURI DE ALIANTA - donatie peste necesarul ultimului nivel
//////////////////////////////////////////////////////////////////////////////////////////////////////
tz_def('ALLYBONUS_MSG_OVERMAX', 'Ceci est le dernier niveau : vous pouvez donner au maximum %s ressources supplementaires.');
//////////////////////////////////////////////////////////////////////////////////////////////////////
// JUCATORI PROTEJATI IMPOTRIVA ATACURILOR
//////////////////////////////////////////////////////////////////////////////////////////////////////
tz_def('ADM_PROTECTED_PLAYERS', 'Joueurs proteges');
tz_def('ADM_PROTECTED_PLAYERS_TIP', 'Noms de joueurs separes par des virgules qui ne peuvent etre ni attaques ni pilles. Les renforts restent autorises. Laisser vide pour desactiver.');
+6
View File
@@ -4100,3 +4100,9 @@ tz_def('TZ_WW_NO_CAPITAL', 'Satul Minunii Lumii nu poate deveni capitala.');
// BONUSURI DE ALIANTA - donatie peste necesarul ultimului nivel
//////////////////////////////////////////////////////////////////////////////////////////////////////
tz_def('ALLYBONUS_MSG_OVERMAX', 'Acesta e ultimul nivel: poti dona cel mult %s resurse.');
//////////////////////////////////////////////////////////////////////////////////////////////////////
// JUCATORI PROTEJATI IMPOTRIVA ATACURILOR
//////////////////////////////////////////////////////////////////////////////////////////////////////
tz_def('ADM_PROTECTED_PLAYERS', 'Jucatori protejati');
tz_def('ADM_PROTECTED_PLAYERS_TIP', 'Nume de jucatori separate prin virgula, care nu pot fi atacati sau jefuiti de nimeni. Intaririle raman permise. Lasa gol ca sa dezactivezi.');
+50
View File
@@ -230,6 +230,52 @@ class Units {
* @param array $villageInfo Out: the resolved village/oasis row
* @return string An error message, or "" if the target can be attacked
*/
/**
* Jucatori protejati impotriva atacurilor.
*
* Lista vine din PROTECTED_PLAYERS (config.php), separata prin virgula:
* define("PROTECTED_PLAYERS", "Shadow,Multihunter");
*
* Verificarea sta AICI fiindca e punctul unic prin care trec toate
* trimiterile de trupe ale jucatorilor - din a2b.php, din harta sau de
* oriunde altundeva. Nu e nevoie sa modificam fiecare pagina.
*
* Se blocheaza doar ATACUL si RAIDUL (c = 3 si 4). Intaririle (c = 2) trec,
* ca jucatorul protejat sa poata primi ajutor.
*
* @param int $ownerId proprietarul satului tinta
* @param mixed $missionType tipul misiunii din formular
* @return bool
*/
private function isProtectedTarget($ownerId, $missionType) {
global $database;
if (!defined('PROTECTED_PLAYERS') || trim(PROTECTED_PLAYERS) === '') {
return false;
}
// intaririle raman permise
if ((int) $missionType !== 3 && (int) $missionType !== 4) {
return false;
}
$targetName = (string) $database->getUserField((int) $ownerId, 'username', 0);
if ($targetName === '') {
return false;
}
foreach (explode(',', PROTECTED_PLAYERS) as $protectedName) {
$protectedName = trim($protectedName);
if ($protectedName !== '' && strcasecmp($protectedName, $targetName) === 0) {
return true;
}
}
return false;
}
private function validateTargetPlayer($id, $isOasis, &$villageInfo) {
global $database, $village;
@@ -250,6 +296,10 @@ class Units {
//check if the user' is on the vacation mode:
if($database->getvacmodexy($id)) return "User is on vacation mode";
// jucator protejat prin PROTECTED_PLAYERS
if($this->isProtectedTarget($villageOwner, isset($_POST['c']) ? $_POST['c'] : 0)) {
return "This player is protected from attacks.";
}
//check if attacking same village that units are in
if($id == $village->wid) return "You cant attack same village you are sending from.";