From e98ff77c310223b87d9d6427071b9dcfe8323843 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Jul 2012 01:50:55 +0300 Subject: [PATCH] fix diplomacy --- GameEngine/Database/db_MYSQL.php | 59 +++++++++++++++++--------------- Templates/Alliance/chgdiplo.tpl | 2 +- allianz.php | 2 ++ install/data/sql.sql | 2 +- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/GameEngine/Database/db_MYSQL.php b/GameEngine/Database/db_MYSQL.php index 850df6cf..c4f8fc8b 100644 --- a/GameEngine/Database/db_MYSQL.php +++ b/GameEngine/Database/db_MYSQL.php @@ -1333,23 +1333,17 @@ class MYSQL_DB { } function getAllianceDipProfile($aid, $type){ - $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '$type' AND accepted = '1'"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result) == 0){ - $q2 = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli2 = '$aid' AND type = '$type' AND accepted = '1'"; - $result2 = mysql_query($q2, $this->connection); - while($row = mysql_fetch_array($result2)){ - $alliance = $this->getAlliance($row['alli1']); - $text = ""; - $text .= "".$alliance['tag']."
"; - } - }else{ - while($row = mysql_fetch_array($result)){ + $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '$type' AND accepted = '1' OR alli2 = '$aid' AND type = '$type' AND accepted = '1'"; + $array = $this->query_return($q); + foreach($array as $row){ + if($row['alli1'] == $aid){ $alliance = $this->getAlliance($row['alli2']); - $text = ""; + }elseif($row['alli2'] == $aid){ + $alliance = $this->getAlliance($row['alli1']); + } + $text .= ""; $text .= "".$alliance['tag']."
"; } - } if(strlen($text) == 0){ $text = "-
"; } @@ -1357,23 +1351,17 @@ class MYSQL_DB { } function getAllianceWar($aid){ - $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '3'"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result) == 0){ - $q2 = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli2 = '$aid' AND type = '3' AND accepted = '1'"; - $result2 = mysql_query($q2, $this->connection); - while($row = mysql_fetch_array($result2)){ - $alliance = $this->getAlliance($row['alli1']); - $text = ""; - $text .= "".$alliance['tag']."
"; - } - }else{ - while($row = mysql_fetch_array($result)){ + $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '3' OR alli2 = '$aid' AND type = '3' AND accepted = '1'"; + $array = $this->query_return($q); + foreach($array as $row){ + if($row['alli1'] == $aid){ $alliance = $this->getAlliance($row['alli2']); - $text = ""; + }elseif($row['alli2'] == $aid){ + $alliance = $this->getAlliance($row['alli1']); + } + $text .= ""; $text .= "".$alliance['tag']."
"; } - } if(strlen($text) == 0){ $text = "-
"; } @@ -1391,6 +1379,7 @@ class MYSQL_DB { $result = mysql_query($q, $this->connection); return $this->mysql_fetch_all($result); } + function diplomacyExistingRelationships($session_alliance) { $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 1"; $result = mysql_query($q, $this->connection); @@ -1407,6 +1396,20 @@ class MYSQL_DB { $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance OR id = $id AND alli1 = $session_alliance"; return mysql_query($q, $this->connection); } + + function checkDiplomacyInviteAccept($aid, $type) { + $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $aid AND type = $type AND accepted = 1 OR alli2 = $aid AND type = $type AND accepted = 1"; + $result = mysql_query($q, $this->connection); + if($type == 3){ + return true; + }else{ + if(mysql_num_rows($result) < 4) { + return true; + } else { + return false; + } + } + } function setAlliForumLink($aid, $link) { $q = "UPDATE " . TB_PREFIX . "alidata SET `forumlink` = '$link' WHERE id = $aid"; diff --git a/Templates/Alliance/chgdiplo.tpl b/Templates/Alliance/chgdiplo.tpl index a0d38aa0..08462db0 100644 --- a/Templates/Alliance/chgdiplo.tpl +++ b/Templates/Alliance/chgdiplo.tpl @@ -149,7 +149,7 @@ } else if($row['type'] == 3){ $type = "War"; } - echo '
'.$database->getAllianceName($row['alli1']).'
'.$type.'
'; + echo '
'.$database->getAllianceName($row['alli1']).'
'.$type.'
'; } } else { echo 'none'; diff --git a/allianz.php b/allianz.php index bb235212..9f0f5e12 100644 --- a/allianz.php +++ b/allianz.php @@ -280,7 +280,9 @@ $invite_permission = $database->getAlliancePermission($session->uid, "opt4", 0); include ("Templates/Alliance/chgdiplo.tpl"); break; case 103: + if($database->checkDiplomacyInviteAccept($session->alliance, $_POST['type'])){ $database->diplomacyInviteAccept($_POST['id'], $_POST['alli2']); + } include ("Templates/Alliance/chgdiplo.tpl"); break; case 104: diff --git a/install/data/sql.sql b/install/data/sql.sql index 9574c92b..a2475b61 100644 --- a/install/data/sql.sql +++ b/install/data/sql.sql @@ -467,7 +467,7 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%diplomacy` ( `alli1` int(11) unsigned NOT NULL, `alli2` int(11) unsigned NOT NULL, `type` tinyint(1) unsigned NOT NULL, - `accepted` int(1) NOT NULL, + `accepted` tinyint(1) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; --