mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-06 21:04:20 +00:00
Alliance forum fixes part 5
+Confederation and shared forums are now visible to the confederation alliances or selected alliances/users +Sticked topics are now displayed first +Fixed a bug that permitted to add confederated alliances/users to shared forums +Minor bug fixing
This commit is contained in:
+33
-6
@@ -44,7 +44,7 @@ class Alliance {
|
||||
public $inviteArray = [];
|
||||
public $allianceArray = [];
|
||||
public $userPermArray = [];
|
||||
|
||||
|
||||
public function procAlliance($get) {
|
||||
global $session, $database;
|
||||
|
||||
@@ -77,6 +77,25 @@ class Alliance {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
//Loop through the shared forums and try to find the passed one
|
||||
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.)
|
||||
*
|
||||
@@ -110,28 +129,36 @@ class Alliance {
|
||||
global $database, $session;
|
||||
|
||||
$alliances = $users = [];
|
||||
|
||||
//TODO: Reduce the code of this part and cache existing diplomacy relationship
|
||||
//Deduplicate alliances
|
||||
if(!empty($alliancesID)){
|
||||
foreach($alliancesID as $alliance){
|
||||
if(!empty($alliance) && is_numeric($alliance) && $database->aExist($alliance, 'id') && $alliance != $session->alliance) $alliances[$alliance] = true;
|
||||
if(!empty($alliance) && is_numeric($alliance) && $database->aExist($alliance, 'id') && $alliance != $session->alliance && empty($database->diplomacyExistingRelationships($alliance))){
|
||||
$alliances[$alliance] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!empty($alliancesName)){
|
||||
foreach($alliancesName as $alliance){
|
||||
if(!empty($alliance) && !empty($allianceID = $database->getAllianceID($alliance)) && $allianceID != $session->alliance) $alliances[$allianceID] = true;
|
||||
if(!empty($alliance) && !empty($allianceID = $database->getAllianceID($alliance)) && $allianceID != $session->alliance && empty($database->diplomacyExistingRelationships($allianceID))){
|
||||
$alliances[$allianceID] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Deduplicate users
|
||||
if(!empty($usersID)){
|
||||
foreach($usersID as $user) {
|
||||
if(!empty($user) && is_numeric($user) && ($userAlly = $database->getUserAllianceID($user)) > 0 && $userAlly != $session->alliance && $database->getUserField($user, 'username', 0) != "[?]" && $user != $session->uid) $users[$user] = true;
|
||||
if(!empty($user) && is_numeric($user) && ($userAlly = $database->getUserAllianceID($user)) > 0 && $userAlly != $session->alliance && $database->getUserField($user, 'username', 0) != "[?]" && $user != $session->uid && empty($database->diplomacyExistingRelationships($userAlly))) {
|
||||
$users[$user] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!empty($usersName)){
|
||||
foreach($usersName as $user){
|
||||
if(!empty($user) && !empty($userID = $database->getUserField($user, 'id', 1)) && $userID != $session->uid && ($userAlly = $database->getUserAllianceID($userID)) > 0 && $userAlly != $session->alliance) $users[$userID] = true;
|
||||
if(!empty($user) && !empty($userID = $database->getUserField($user, 'id', 1)) && $userID != $session->uid && ($userAlly = $database->getUserAllianceID($userID)) > 0 && $userAlly != $session->alliance && empty($database->diplomacyExistingRelationships($userAlly))) {
|
||||
$users[$userID] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+105
-15
@@ -627,7 +627,7 @@ class MYSQLi_DB implements IDbConnection {
|
||||
function mysqli_fetch_all($result) {
|
||||
list($result) = $this->escape_input($result);
|
||||
|
||||
$all = array();
|
||||
$all = [];
|
||||
if($result) {
|
||||
while($row = mysqli_fetch_assoc($result)) {
|
||||
$all[] = $row;
|
||||
@@ -2250,12 +2250,105 @@ class MYSQLi_DB implements IDbConnection {
|
||||
return $this->getVillageByWorldID($wref, $use_cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shared forums (and confederation forums), based on user ID and alliance ID
|
||||
*
|
||||
* @param int $uid The user ID
|
||||
* @param int $alliance The alliance ID
|
||||
* @return array Returns all user's shared forums
|
||||
*/
|
||||
|
||||
function getSharedForums($uid, $alliance){
|
||||
list($uid, $alliance) = $this->escape_input((int) $uid, (int) $alliance);
|
||||
|
||||
$allianceForums = $confForums = $closedForums = [];
|
||||
|
||||
$q = "SELECT * FROM
|
||||
".TB_PREFIX."forum_cat
|
||||
WHERE
|
||||
display_to_alliances
|
||||
LIKE
|
||||
'%,$alliance,%'
|
||||
OR
|
||||
display_to_alliances
|
||||
LIKE
|
||||
'%,$alliance%'
|
||||
OR
|
||||
display_to_alliances
|
||||
LIKE
|
||||
'%$alliance,%'
|
||||
OR
|
||||
display_to_alliances
|
||||
LIKE
|
||||
'%$alliance%'
|
||||
OR
|
||||
display_to_users
|
||||
LIKE
|
||||
'%,$uid,%'
|
||||
OR
|
||||
display_to_users
|
||||
LIKE
|
||||
'%,$uid%'
|
||||
OR
|
||||
display_to_users
|
||||
LIKE
|
||||
'%$uid,%'
|
||||
OR
|
||||
display_to_users
|
||||
LIKE
|
||||
'%$uid%'
|
||||
";
|
||||
$result = mysqli_query($this->dblink, $q);
|
||||
while($row = mysqli_fetch_assoc($result)) {
|
||||
switch($row['forum_area']){
|
||||
case 0: $allianceForums[] = $row; break;
|
||||
case 2: $confForums[] = $row; break;
|
||||
case 3: $closedForums[] = $row; break;
|
||||
}
|
||||
}
|
||||
|
||||
//Get the alliance confederation forums
|
||||
if($alliance > 0){
|
||||
$confederations = $this->diplomacyExistingRelationships($alliance);
|
||||
if(!empty($confederations)){
|
||||
foreach($confederations as $confederation){
|
||||
if($confederation['type'] == 1){
|
||||
$confederationForums = $this->ForumCat($confederation['alli1'] == $alliance ? $confederation['alli2'] : $confederation['alli1'], 1);
|
||||
if(!empty($confederationForums)){
|
||||
foreach($confederationForums as $forum){
|
||||
if($forum['forum_area'] == 2) $confForums[] = $forum;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['alliance' => $allianceForums, 'confederation' => $confForums, 'closed' => $closedForums];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total amount of the wanted forum, based on alliance and the forum area
|
||||
*
|
||||
* @param int $forumArea The forum Area 0 = alliance, 1 = public, 2 = confederation, 3 = closed
|
||||
* @param int $ally The alliance ID
|
||||
* @return int Returns the total amount of the wanted forum
|
||||
*/
|
||||
|
||||
function countForums($forumArea, $ally){
|
||||
list($forumArea, $ally) = $this->escape_input((int) $forumArea, (int) $ally);
|
||||
|
||||
$q = "SELECT Count(*) as Total FROM ".TB_PREFIX."forum_cat WHERE ".($ally != -1 ? "alliance = $ally AND" : "")." forum_area = $forumArea";
|
||||
$result = mysqli_fetch_array(mysqli_query($this->dblink, $q), MYSQLI_ASSOC );
|
||||
return $result['Total'];
|
||||
}
|
||||
|
||||
// no need to refactor this method
|
||||
function CheckForum($id) {
|
||||
list($id) = $this->escape_input((int) $id);
|
||||
|
||||
$q = "SELECT Count(*) as Total FROM " . TB_PREFIX . "forum_cat where alliance = $id";
|
||||
$result = mysqli_fetch_array(mysqli_query($this->dblink,$q), MYSQLI_ASSOC);
|
||||
$result = mysqli_fetch_array(mysqli_query($this->dblink, $q), MYSQLI_ASSOC);
|
||||
return $result['Total'] > 0;
|
||||
}
|
||||
|
||||
@@ -2366,10 +2459,10 @@ class MYSQLi_DB implements IDbConnection {
|
||||
}
|
||||
|
||||
// no need to cache this method
|
||||
function ForumCat($id) {
|
||||
list($id) = $this->escape_input($id);
|
||||
function ForumCat($id, $mode = 0) {
|
||||
list($id, $mode) = $this->escape_input($id, $mode);
|
||||
|
||||
$q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id' OR forum_area = 1 ORDER BY sorting DESC, id";
|
||||
$q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id' ".(!$mode ? "OR forum_area = 1" : "")." ORDER BY sorting DESC, id";
|
||||
$result = mysqli_query($this->dblink,$q);
|
||||
return $this->mysqli_fetch_all($result);
|
||||
}
|
||||
@@ -3179,16 +3272,13 @@ class MYSQLi_DB implements IDbConnection {
|
||||
$array = $this->query_return($q);
|
||||
$text = "";
|
||||
|
||||
if ($array) {
|
||||
foreach($array as $row){
|
||||
if($row['alli1'] == $aid){
|
||||
$alliance = $this->getAlliance($row['alli2']);
|
||||
}elseif($row['alli2'] == $aid){
|
||||
$alliance = $this->getAlliance($row['alli1']);
|
||||
}
|
||||
$text .= "";
|
||||
$text .= "<a href=allianz.php?aid=".$alliance['id'].">".$alliance['tag']."</a><br> ";
|
||||
}
|
||||
if($array){
|
||||
foreach($array as $row){
|
||||
if($row['alli1'] == $aid) $alliance = $this->getAlliance($row['alli2']);
|
||||
elseif($row['alli2'] == $aid) $alliance = $this->getAlliance($row['alli1']);
|
||||
$text .= "";
|
||||
$text .= "<a href=allianz.php?aid=" . $alliance['id'] . ">" . $alliance['tag'] . "</a><br> ";
|
||||
}
|
||||
}
|
||||
if(strlen($text) == 0){
|
||||
$text = "-<br>";
|
||||
|
||||
@@ -70,10 +70,11 @@ class Session {
|
||||
var $bonus3 = 0;
|
||||
var $bonus4 = 0;
|
||||
var $timer = 0;
|
||||
var $sharedForums = [];
|
||||
var $checker, $mchecker;
|
||||
public $userinfo = array();
|
||||
private $userarray = array();
|
||||
var $villages = array();
|
||||
public $userinfo = [];
|
||||
private $userarray = [];
|
||||
var $villages = [];
|
||||
|
||||
function __construct() {
|
||||
global $database; //TienTN fix
|
||||
@@ -238,6 +239,7 @@ class Session {
|
||||
|
||||
private function PopulateVar() {
|
||||
global $database;
|
||||
|
||||
$this->userarray = $this->userinfo = $database->getUserArray($_SESSION['username'], 0);
|
||||
$this->username = $this->userarray['username'];
|
||||
$this->uid = $_SESSION['id_user'] = $this->userarray['id'];
|
||||
@@ -257,6 +259,7 @@ class Session {
|
||||
$this->cp = floor($this->userarray['cp']);
|
||||
$this->gold = $this->userarray['gold'];
|
||||
$this->oldrank = $this->userarray['oldrank'];
|
||||
$this->sharedForums = $database->getSharedForums($this->uid, $this->alliance);
|
||||
$_SESSION['ok'] = $this->userarray['ok'];
|
||||
if($this->userarray['b1'] > $this->time) {
|
||||
$this->bonus1 = 1;
|
||||
|
||||
Reference in New Issue
Block a user