alliance > 0) { // Utilizatorul este membru al unei alianțe $this->allianceArray = $database->getAlliance($session->alliance); // Permissions Array // [id] => id [uid] => uid [alliance] => alliance // [opt1] => X [opt2] => X [opt3] => X [opt4] => X // [opt5] => X [opt6] => X [opt7] => X [opt8] => X $this->userPermArray = $database->getAlliPermissions($session->uid, $session->alliance); } else { // Utilizatorul NU este într-o alianță → încarcă invitațiile primite $this->inviteArray = $database->getInvitation($session->uid); $this->gotInvite = count($this->inviteArray) > 0; } // ==================== PROCESARE ACȚIUNI DIN URL (GET) ==================== if (isset($get['a'])) { switch ($get['a']) { case 2: $this->rejectInvite($get); break; case 3: $this->acceptInvite($get); break; } } if (isset($get['o'])) { switch ($get['o']) { case 4: $this->delInvite($get); break; } } } /** * Determines if a forum is accessible or not * * @param int $forumID The forum ID * @return bool Returns if the forum is accessible or not */ public function isForumAccessible($forumID) { global $session; // Căutăm forumul în lista de forumuri partajate foreach ($session->sharedForums as $forums) { foreach ($forums as $forum) { if ($forum['id'] == $forumID) { return true; } } } return false; } /** * Determines if a player can act with the forum (edit/delete/create things, etc.) * * @param array $datas The array which contains: [aid, alliance, forum_perm, admin, owner, forum_owner] * @return bool Returns true if you are able to act, false otherwise */ public static function canAct($datas, $mode = 0) { global $database, $session; $hasSwitchedToAdmin = isset($datas['admin']) && !empty($datas['admin']) && $datas['admin'] === "switch_admin"; // ==================== CONDIȚII DE ACCES ==================== $isAllianceOwner = $database->isAllianceOwner($session->uid) == $datas['alliance']; $hasForumPerm = $datas['forum_perm'] == 1 && $session->alliance == $datas['alliance']; $isForumOwner = $datas['owner'] == $session->uid && $session->access != ADMIN; $isGlobalAdmin = $session->access == ADMIN; $canActInAlliance = $datas['alliance'] > 0 && ($isAllianceOwner || $hasForumPerm); $canActAsOwner = $isForumOwner; $canActAsAdmin = $isGlobalAdmin; // Logica exactă din original return (($canActInAlliance || $canActAsOwner || $canActAsAdmin)) && ($mode || $hasSwitchedToAdmin); } /** * Generează două string-uri cu ID-urile alianțelor și utilizatorilor care pot vedea un forum specific. * * Exclut automat: * - propria alianță a jucătorului * - relațiile de diplomație existente * - utilizatorii șterși ([?]) * * @param array $alliancesID Lista de ID-uri de alianțe * @param array $alliancesName Lista de nume de alianțe * @param array $usersID Lista de ID-uri de utilizatori * @param array $usersName Lista de nume de utilizatori * @return array ['alliances' => '1,2,5', 'users' => '10,23,45'] */ public function createForumVisiblity($alliancesID, $alliancesName, $usersID, $usersName) { global $database, $session; $visibleAlliances = []; $visibleUsers = []; // ==================== ALIANȚE VIZIBILE ==================== // Procesăm atât ID-urile cât și numele (deduplicate automat prin array keys) if (!empty($alliancesID)) { foreach ($alliancesID as $alliance) { if ($this->isValidAllianceForForum($alliance, $session->alliance, $database)) { $visibleAlliances[$alliance] = true; } } } if (!empty($alliancesName)) { foreach ($alliancesName as $allianceName) { $allianceID = $database->getAllianceID($allianceName); if ($this->isValidAllianceForForum($allianceID, $session->alliance, $database)) { $visibleAlliances[$allianceID] = true; } } } // ==================== UTILIZATORI VIZIBILI ==================== if (!empty($usersID)) { foreach ($usersID as $user) { if ($this->isValidUserForForum($user, $session->alliance, $session->uid, $database)) { $visibleUsers[$user] = true; } } } if (!empty($usersName)) { foreach ($usersName as $username) { $userID = $database->getUserField($username, 'id', 1); if ($this->isValidUserForForum($userID, $session->alliance, $session->uid, $database)) { $visibleUsers[$userID] = true; } } } // ==================== RETURN ==================== return [ 'alliances' => implode(',', array_keys($visibleAlliances)), 'users' => implode(',', array_keys($visibleUsers)) ]; } /** * Verifică dacă o alianță poate fi adăugată la vizibilitatea forumului */ private function isValidAllianceForForum($allianceID, $myAllianceID, $database) { if (empty($allianceID) || !is_numeric($allianceID)) { return false; } if (!$database->aExist($allianceID, 'id')) { return false; } if ($allianceID == $myAllianceID) { return false; } return empty($database->diplomacyExistingRelationships($allianceID)); } /** * Verifică dacă un utilizator poate fi adăugat la vizibilitatea forumului */ private function isValidUserForForum($userID, $myAllianceID, $myUserID, $database) { if (empty($userID) || !is_numeric($userID)) { return false; } $userAlliance = $database->getUserAllianceID($userID); $username = $database->getUserField($userID, 'username', 0); return ( $userAlliance > 0 && $userAlliance != $myAllianceID && $username !== "[?]" && $userID != $myUserID && empty($database->diplomacyExistingRelationships($userAlliance)) ); } /** * Redirecționează către pagina de selecție forum (allianz.php?s=2) * * Construiește URL-ul cu parametrii opționali fid și switch_admin, * respectând exact condițiile din codul original. * * @param array|null $get Datele din cererea GET (poate fi null) */ public function redirect($get = null) { $get = $get ?? []; // protecție împotriva null $url = "allianz.php?s=2"; // Adaugă &fid=... doar dacă fid este setat, nu gol și admin != 'pos' if (isset($get['fid']) && !empty($get['fid']) && ($get['admin'] ?? '') !== 'pos') { $url .= "&fid=" . $get['fid']; } // Adaugă &admin=switch_admin dacă parametrul admin este prezent și nu gol if (isset($get['admin']) && !empty($get['admin'])) { $url .= "&admin=switch_admin"; } header("Location: " . $url); exit; } /***************************************** Function to process of sending Forms *****************************************/ public function procAlliForm($post) { // ==================== TIP FORMULAR (ft) ==================== if (isset($post['ft'])) { switch ($post['ft']) { case "ali1": $this->createAlliance($post); break; } } // ==================== SCHIMBARE DIPLOMAȚIE ==================== if (isset($post['dipl']) && isset($post['a_name'])) { $this->changediplomacy($post); } // ==================== ACȚIUNI GENERALE (s + o) ==================== if (isset($post['s']) && isset($post['o'])) { switch ($post['o']) { case 1: // Schimbare permisiuni utilizator if (isset($_POST['a'])) { $this->changeUserPermissions($post); } break; case 2: // Kick utilizator din alianță if (isset($_POST['a_user'])) { $this->kickAlliUser($post); } break; case 4: // Trimitere invitație if (isset($_POST['a']) && $_POST['a'] == 4) { $this->sendInvite($post); } break; case 3: // Actualizare profil alianță $this->updateAlliProfile($post); break; case 11: // Părăsire alianță $this->quitally($post); break; case 100: // Schimbare nume alianță $this->changeAliName($post); break; } } } /***************************************** Function to process of sending invitations *****************************************/ public function sendInvite($post) { global $form, $database, $session; // ==================== DATE DE INTRARE ==================== $invitedUsername = stripslashes($post['a_name'] ?? ''); // Obținem datele utilizatorului invitat (comportament exact ca în original) $UserData = $database->getUserArray($invitedUsername, 0); // ==================== VERIFICĂRI DE PERMISIUNI ȘI VALIDĂRI ==================== if ($this->userPermArray['opt4'] == 0) { $form->addError("name", NO_PERMISSION); } elseif (!isset($post['a_name']) || $post['a_name'] === '') { $form->addError("name", NAME_EMPTY); } elseif (!User::exists($database, $post['a_name'])) { $form->addError("name", NAME_NO_EXIST . stripslashes(stripslashes($post['a_name']))); } elseif ($UserData['id'] == $session->uid) { $form->addError("name", SAME_NAME); } elseif ($database->getInvitation2($UserData['id'], $session->alliance)) { $form->addError("name", $post['a_name'] . ALREADY_INVITED); } elseif ($UserData['alliance'] == $session->alliance) { $form->addError("name", $post['a_name'] . ALREADY_IN_ALLY); } elseif ($UserData['alliance'] > 0) { $form->addError("name", $post['a_name'] . ALREADY_IN_AN_ALLY); } else { // ==================== TOATE VERIFICĂRILE AU TRECUT → TRIMITE INVITAȚIA ==================== $aid = $session->alliance; // Inserăm invitația în baza de date $database->sendInvitation($UserData['id'], $aid, $session->uid); // Log notice în alianță $database->insertAlliNotice( $session->alliance, '' . addslashes($session->username) . ' has invited ' . addslashes($UserData['username']) . ' into the alliance.' ); // Trimite invitație și prin mesaj în joc (dacă este activată funcționalitatea nouă) if (NEW_FUNCTIONS_ALLIANCE_INVITATION) { $messageBody = "Hi, " . $UserData['username'] . "!\n\n" . "This is to inform you that you have been invited to join an alliance. " . "To accept this invitation, please visit your Embassy.\n\n" . "Yours sincerely,\nServer Robot :)"; $database->sendMessage( $UserData['id'], 4, 'Invitation to Alliance', $database->escape($messageBody), 0, 0, 0, 0, 0, true ); } } } /***************************************** Function to reject an invitation *****************************************/ private function rejectInvite($get) { global $database, $session; $inviteID = $get['d'] ?? 0; // ==================== CĂUTARE ȘI RESPINGERE INVITAȚIE ==================== foreach ($this->inviteArray as $invite) { if ($invite['id'] == $inviteID && $invite['uid'] == $session->uid) { // Ștergem invitația din baza de date $database->removeInvitation($inviteID); // Adăugăm notice în logul alianței $notice = '' . addslashes($session->username) . ' has rejected the invitation.'; $database->insertAlliNotice($invite['alliance'], $notice); break; // am găsit și procesat invitația → nu mai continuăm bucla } } // ==================== REDIRECȚIONARE ==================== // (întotdeauna se face redirect, chiar dacă invitația nu a fost găsită) header("Location: build.php?gid=18"); exit; } /***************************************** Function to del an invitation *****************************************/ private function delInvite($get) { global $database, $session; $inviteID = $get['d'] ?? 0; // Încărcăm lista de invitații trimise de alianța curentă $inviteArray = $database->getAliInvitations($session->alliance); // ==================== CĂUTARE ȘI ȘTERGERE INVITAȚIE ==================== foreach ($inviteArray as $invite) { if ($invite['id'] == $inviteID && $invite['alliance'] == $session->alliance && $this->userPermArray['opt4'] == 1) { // Obținem numele utilizatorului invitat $invitename = $database->getUserArray($invite['uid'], 1); // Ștergem invitația $database->removeInvitation($inviteID); // Adăugăm notice în logul alianței $notice = '' . addslashes($session->username) . ' has deleted the invitation for ' . addslashes($invitename['username']) . '.'; $database->insertAlliNotice($session->alliance, $notice); break; // am procesat invitația → ieșim din buclă } } // ==================== REDIRECȚIONARE ==================== // (întotdeauna se face redirect, chiar dacă invitația nu a fost găsită) header("Location: allianz.php?delinvite"); exit; } /***************************************** Function to accept an invitation *****************************************/ private function acceptInvite($get) { global $form, $database, $session; $inviteID = $get['d'] ?? 0; $acceptError = false; $maxMembers = 0; // ==================== PROCESARE INVITAȚII ==================== foreach ($this->inviteArray as $invite) { if ($session->alliance == 0 && $invite['id'] == $inviteID && $invite['uid'] == $session->uid) { $memberlist = $database->getAllMember($invite['alliance']); $alliance_info = $database->getAlliance($invite['alliance']); if (count($memberlist) < $alliance_info['max']) { // Acceptăm invitația $database->removeInvitation($inviteID); $database->updateUserField($invite['uid'], "alliance", $invite['alliance'], 1); $database->createAlliPermissions($invite['uid'], $invite['alliance'], '', 0, 0, 0, 0, 0, 0, 0, 0); // Log notice în alianță $notice = '' . addslashes($session->username) . ' has joined the alliance.'; $database->insertAlliNotice($invite['alliance'], $notice); } else { // Alianța este plină $acceptError = true; $maxMembers = $alliance_info['max']; } break; // am găsit și procesat invitația → ieșim din buclă } } // ==================== REZULTAT FINAL ==================== if ($acceptError) { $form->addError( "ally_accept", "The alliance can contain only " . $maxMembers . " members at this moment." ); } else { header("Location: build.php?gid=18"); exit; } } /***************************************** Function to create an alliance *****************************************/ private function createAlliance($post) { global $form, $database, $session, $bid18, $building; $tag = $post['ally1'] ?? ''; $name = $post['ally2'] ?? ''; // ==================== VALIDĂRI ==================== if ($tag === '') { $form->addError("ally1", ATAG_EMPTY); } if ($name === '') { $form->addError("ally2", ANAME_EMPTY); } if ($database->aExist($tag, "tag")) { $form->addError("ally1", ATAG_EXIST); } if ($database->aExist($name, "name")) { $form->addError("ally2", ANAME_EXIST); } if ($session->alliance != 0) { $form->addError("ally3", ALREADY_ALLY_MEMBER); } if ($building->getTypeLevel(18) < 3) { $form->addError("ally4", ALLY_TOO_LOW); } // ==================== ERORI ? ==================== if ($form->returnErrors() != 0) { $_SESSION['errorarray'] = $form->getErrors(); $_SESSION['valuearray'] = $post; // Redirect în funcție de existența ambasadei (comportament original) if ($building->getTypeLevel(18) > 0) { header("Location: build.php?gid=18"); } else { header("Location: dorf2.php"); } exit; } // ==================== CREARE ALIANȚĂ ==================== $maxMembers = $bid18[$building->getTypeLevel(18)]['attri']; $aid = $database->createAlliance($tag, $name, $session->uid, $maxMembers); // Actualizăm alianța utilizatorului $database->updateUserField($session->uid, "alliance", $aid, 1); // Procesăm populația inițială $database->procAllyPop($aid); // Creăm permisiuni complete pentru fondator $database->createAlliPermissions( $session->uid, $aid, 'Alliance founder', '1', '1', '1', '1', '1', '1', '1', '1' ); // Log notice în alianță $notice = 'The alliance has been founded by ' . addslashes($session->username) . '.'; $database->insertAlliNotice($aid, $notice); header("Location: build.php?gid=18"); exit; } /***************************************** Function to change the alliance name *****************************************/ private function changeAliName($get) { global $form, $database, $session; $newTag = $get['ally1'] ?? ''; $newName = $get['ally2'] ?? ''; // Încărcăm datele actuale ale alianței $userAlly = $database->getAlliance($session->alliance); // ==================== VALIDĂRI ==================== if ($newTag === '') { $form->addError("ally1", ATAG_EMPTY); } if ($newName === '') { $form->addError("ally2", ANAME_EMPTY); } // Verificăm existența tag-ului doar dacă s-a modificat if ($newTag !== $userAlly['tag'] && $database->aExist($newTag, "tag")) { $form->addError("ally1", ATAG_EXIST); } // Verificăm existența numelui doar dacă s-a modificat if ($newName !== $userAlly['name'] && $database->aExist($newName, "name")) { $form->addError("ally2", ANAME_EXIST); } if ($this->userPermArray['opt3'] == 0) { $form->addError("perm", NO_PERMISSION); } // ==================== PROCESARE LA SUCCES ==================== if ($form->returnErrors() == 0) { // Actualizăm numele și tag-ul alianței $database->setAlliName($session->alliance, $newName, $newTag); // Log notice în alianță $notice = '' . addslashes($session->username) . ' has changed the alliance name.'; $database->insertAlliNotice($session->alliance, $notice); // Mesaj de succes prin sistemul de erori (comportament original) $form->addError("perm", NAME_OR_TAG_CHANGED); $_SESSION['errorarray'] = $form->getErrors(); $_SESSION['valuearray'] = $get; header("Location: allianz.php?s=5"); exit; } } /***************************************** Function to create/change the alliance description *****************************************/ private function updateAlliProfile($post) { global $database, $session, $form; // ==================== VERIFICARE PERMISIUNI ==================== if ($this->userPermArray['opt3'] == 0) { $form->addError("perm", NO_PERMISSION); } // ==================== REZULTAT ==================== if ($form->returnErrors() > 0) { // Salvăm erorile în sesiune (comportament original - fără redirect aici) $_SESSION['errorarray'] = $form->getErrors(); $_SESSION['valuearray'] = $post; } else { // ==================== ACTUALIZARE PROFIL ==================== $description = $post['be1'] ?? ''; $rules = $post['be2'] ?? ''; $database->submitAlliProfile($session->alliance, $rules, $description); // Log notice în alianță $notice = '' . addslashes($session->username) . ' has changed the alliance description.'; $database->insertAlliNotice($session->alliance, $notice); } } /***************************************** Function to change the user permissions *****************************************/ private function changeUserPermissions($post) { global $database, $session, $form; $targetUID = (int)($post['a_user'] ?? 0); $rankTitle = $post['a_titel'] ?? ''; // ==================== VERIFICĂRI DE PERMISIUNI ȘI VALIDĂRI ==================== if ($this->userPermArray['opt1'] == 0) { $form->addError("perm", NO_PERMISSION); } elseif ($database->getUserField($targetUID, "alliance", 0) != $session->alliance) { $form->addError("perm", USER_NOT_IN_YOUR_ALLY); } elseif ($targetUID == $session->uid) { $form->addError("perm", CANT_EDIT_YOUR_PERMISSIONS); } elseif ($database->isAllianceOwner($targetUID)) { $form->addError("perm", CANT_EDIT_LEADER_PERMISSIONS); } else { // ==================== NORMALIZARE CHECKBOX-URI (CRITICAL FIX) ==================== $opt1 = isset($post['e1']) ? 1 : 0; $opt2 = isset($post['e2']) ? 1 : 0; $opt3 = isset($post['e3']) ? 1 : 0; $opt4 = isset($post['e4']) ? 1 : 0; $opt5 = isset($post['e5']) ? 1 : 0; $opt6 = isset($post['e6']) ? 1 : 0; $opt7 = isset($post['e7']) ? 1 : 0; // Actualizăm permisiunile în baza de date $ok = $database->updateAlliPermissions( $targetUID, (int)$session->alliance, $rankTitle, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7 ); if (!$ok) { $form->addError("perm", "DB UPDATE FAILED"); } else { // Log notice în alianță $username = $database->getUserField($targetUID, "username", 0); $notice = '' . addslashes($session->username) . ' has changed permissions of ' . addslashes($username) . '.'; $database->insertAlliNotice($session->alliance, $notice); // Mesaj de succes (comportament original) $_SESSION['success'] = ALLY_PERMISSIONS_UPDATED; } } // ==================== REDIRECȚIONARE LA ERORI ==================== if ($form->returnErrors() > 0) { $_SESSION['errorarray'] = $form->getErrors(); $_SESSION['valuearray'] = $post; header("Location: allianz.php?s=5"); exit; } } /***************************************** Function to kick a user from alliance *****************************************/ private function kickAlliUser($post) { global $database, $session, $form; $targetUID = (int)($post['a_user'] ?? 0); // Obținem datele utilizatorului (folosit pentru username și verificări) $UserData = $database->getUserArray($targetUID, 1); // ==================== VERIFICĂRI DE PERMISIUNI ȘI VALIDĂRI ==================== if ($this->userPermArray['opt2'] == 0) { $form->addError("perm", NO_PERMISSION); } elseif ($database->getUserField($targetUID, "alliance", 0) != $session->alliance) { $form->addError("perm", USER_NOT_IN_YOUR_ALLY); } elseif ($UserData['id'] == $session->uid) { $form->addError("perm", CANT_EDIT_YOUR_PERMISSIONS); // mesajul original era CANT_EDIT_YOUR_PERMISSIONS } else { // ==================== EXECUTARE KICK ==================== $kickedUsername = $database->getUserField($targetUID, "username", 0); $database->updateUserField($targetUID, 'alliance', 0, 1); $database->deleteAlliPermissions($targetUID); // !!! Comportament original - șterge alianța la fiecare kick !!! $database->deleteAlliance($session->alliance); // Log notice în alianță $notice = '' . addslashes($kickedUsername) . ' has been expelled from the alliance by ' . addslashes($session->username) . '.'; $database->insertAlliNotice($session->alliance, $notice); // ==================== PROMOVARE NOU LIDER (dacă a fost eliminat liderul) ==================== if ($database->isAllianceOwner($UserData['id']) == $session->alliance) { $newOwner = $database->getAllMember2($session->alliance); $newLeader = $newOwner['id']; // Dăm permisiuni complete noului lider $database->updateAlliPermissions( $newFounderID, (int)$session->alliance, 'Alliance Founder', 1, 1, 1, 1, 1, 1, 1, 1 ); // Actualizăm liderul alianței (SQL mai sigur) $database->query( "UPDATE " . TB_PREFIX . "alidata SET leader = " . (int)$newLeader . " WHERE id = " . (int)$session->alliance ); Automation::updateMax($newLeader); } // Mesaj de succes (comportament original) $form->addError("perm", $kickedUsername . ALLY_USER_KICKED); } } /***************************************** Function to set forum link *****************************************/ public function setForumLink($post) { global $database, $session, $form; if ($this->userPermArray['opt5'] == 0) { $form->addError("perm", NO_PERMISSION); } else { $forumLink = $post['f_link'] ?? ''; $database->setAlliForumdblink($session->alliance, $forumLink); // Mesaj de succes (comportament exact ca în original) $form->addError("perm", ALLY_FORUM_LINK_UPDATED); } } /***************************************** Function to vote on forum survey *****************************************/ public function Vote($post) { global $database, $session; $surveyID = (int)($post['tid'] ?? 0); $voteOption = (int)($post['vote'] ?? 0); $fid2 = (int)($post['fid2'] ?? 0); // ==================== VERIFICĂRI ==================== if ($database->checkSurvey($surveyID) && !$database->checkVote($surveyID, $session->uid)) { $survey = $database->getSurvey($surveyID); // Construim noul string cu utilizatorii care au votat (exact ca în original) $votedText = $survey['voted'] . ',' . $session->uid . ','; $database->Vote($surveyID, $voteOption, $votedText); } // ==================== REDIRECȚIONARE ==================== // (întotdeauna se face redirect, chiar dacă votul nu a fost înregistrat) header("Location: allianz.php?s=2&fid2=" . $fid2 . "&tid=" . $surveyID); exit; } /***************************************** Function to quit from alliance *****************************************/ private function quitally($post) { global $database, $session, $form; // ==================== VERIFICARE PAROLĂ ==================== if (!isset($post['pw']) || $post['pw'] === '') { $form->addError("pw", PW_EMPTY); } elseif (!password_verify($post['pw'], $session->userinfo['password'])) { $form->addError("pw", LOGIN_PW_ERROR); } else { // Parola este corectă → continuăm cu părăsirea alianței $isFounder = $session->alliance && $database->isAllianceOwner($session->uid) == $session->alliance; $memberCount = $database->countAllianceMembers($session->alliance); // ==================== CAZ SPECIAL: LIDERUL PĂRĂSEȘTE ALIANȚA ==================== if ($isFounder && $memberCount > 1) { // Trebuie să alegem un nou fondator if (!isset($post['new_founder'])) { $form->addError("founder", 'Founder was not selected.'); return; } $newFounderID = (int)$post['new_founder']; // Validăm că noul fondator face parte din alianță $members = $database->getAllMember($session->alliance); $validMemberFound = false; foreach ($members as $member) { if ($member['id'] == $newFounderID) { $validMemberFound = true; break; } } if (!$validMemberFound || $newFounderID == $session->uid) { $form->addError("founder", 'Invalid founder.'); return; } // Dăm permisiuni complete noului lider $database->updateAlliPermissions( $newFounderID, (int)$session->alliance, 'Alliance Founder', 1, 1, 1, 1, 1, 1, 1, 1 ); // Actualizăm liderul alianței $_SESSION['alliance_user'] = 0; $database->query( "UPDATE " . TB_PREFIX . "alidata SET leader = " . $newFounderID . " WHERE id = " . (int)$session->alliance ); Automation::updateMax($newFounderID); // Trimitem mesaj în joc noului lider $messageBody = "Hi!\n\n" . "This is to inform you that the former leader of your alliance - " . "" . $database->escape($session->username) . ", has decided to quit and elected you as his replacement. " . "You now gain full access, administration and responsibilities to your alliance.\n\n" . "Good luck!\n\nYours sincerely,\nServer Robot :)"; $database->sendMessage( $newFounderID, 4, 'You are now leader of your alliance', $messageBody, 0, 0, 0, 0, 0, true ); } // ==================== PĂRĂSIRE ALIANȚĂ (pentru toți membrii) ==================== $database->updateUserField($session->uid, 'alliance', 0, 1); $database->deleteAlliPermissions($session->uid); // Log notice + ștergere alianță (comportament exact ca în original) $database->deleteAlliance($session->alliance); $notice = '' . addslashes($session->username) . ' has quit the alliance.'; $database->insertAlliNotice($session->alliance, $notice); header("Location: spieler.php?uid=" . $session->uid); exit; } } /***************************************** Function for change diplomacy *****************************************/ private function changediplomacy($post) { global $database, $session, $form; // ==================== VERIFICARE PERMISIUNI ==================== if ($this->userPermArray['opt6'] == 0) { $form->addError("name", NO_PERMISSION); return; } $targetAllianceName = $post['a_name'] ?? ''; $diplType = (int)($post['dipl'] ?? 0); // ==================== VALIDĂRI DE INTRARE ==================== if (empty($targetAllianceName) || $diplType === 0) { $form->addError("name", NAME_OR_DIPL_EMPTY); return; } if (!$database->aExist($targetAllianceName, "tag")) { $form->addError("name", ALLY_DOESNT_EXISTS); return; } $targetAllianceID = $database->getAllianceID($targetAllianceName); if ($targetAllianceID == $session->alliance) { $form->addError("name", CANNOT_INVITE_SAME_ALLY); return; } if ($diplType < 1 || $diplType > 3) { $form->addError("name", WRONG_DIPLOMACY); return; } if ($database->diplomacyInviteCheck2($session->alliance, $targetAllianceID)) { $form->addError("name", INVITE_ALREADY_SENT); return; } if (!$database->diplomacyCheckLimits($session->alliance, $diplType)) { $form->addError("name", ALLY_TOO_MUCH_PACTS); return; } // ==================== TRIMITE INVITAȚIA ==================== $database->diplomacyInviteAdd($session->alliance, $targetAllianceID, $diplType); // Textul notice-ului (compatibil PHP 7) if ($diplType == 1) { $noticeText = OFFERED_CONFED_TO; } elseif ($diplType == 2) { $noticeText = OFFERED_NON_AGGRESION_PACT_TO; } elseif ($diplType == 3) { $noticeText = DECLARED_WAR_ON; } else { $noticeText = ''; } $myAllianceName = $database->getAllianceName($session->alliance); // Notice în alianța noastră $database->insertAlliNotice( $session->alliance, '' . $myAllianceName . ' ' . $noticeText . ' ' . $targetAllianceName . '.' ); // Notice în alianța țintă $database->insertAlliNotice( $targetAllianceID, '' . $myAllianceName . ' ' . $noticeText . ' ' . $targetAllianceName . '.' ); // Mesaj de succes $form->addError("name", INVITE_SENT); } } $alliance = new Alliance; ?>