From 166a82f235c908038009586e59b81245ddbd12e9 Mon Sep 17 00:00:00 2001 From: hecht Date: Sat, 11 Feb 2012 22:06:25 +0000 Subject: [PATCH] * introduced clan chats (that will be available at level 2 by default) * added the functionality to configure the chat to insert new messages wheter at the top or bottom of the screen (thx to jester) * additional bugfixes that were noticed when only a few messages were written in the chat. --- ag/ag_popupchat.php | 50 +++++-- ag/clan/clan_info.php | 12 +- ag/clan_popupchat.php | 206 ++++++++++++++++++++++++++++ ag/inclu/user-controll.php | 10 ++ ag/include/clan.inc.php | 8 +- ag/include/clan_chat.inc.php | 97 +++++++++++++ ag/include/messagefunctions.inc.php | 7 +- ag/include/parse.inc.php | 5 +- db/animegame_svn.sql | 42 ++++++ 9 files changed, 421 insertions(+), 16 deletions(-) create mode 100644 ag/clan_popupchat.php create mode 100644 ag/include/clan_chat.inc.php diff --git a/ag/ag_popupchat.php b/ag/ag_popupchat.php index c2ad625..84285c3 100644 --- a/ag/ag_popupchat.php +++ b/ag/ag_popupchat.php @@ -11,6 +11,10 @@ $nodisturb = 'YES'; include_once('path.inc.php'); // get the path ;) include_once (ROOT_PATH . '/include/config.inc.php'); include_once (ROOT_PATH . '/include/messagefunctions.inc.php'); +include_once (ROOT_PATH . '/include/defines.inc.php'); + +defineIfNotDefined('AG_CHAT_ROWS', 25); +defineIfNotDefined('AG_CHAT_ORDER', 'ASC'); // Die Nachricht muss nicht geparst werden! @@ -69,9 +73,9 @@ if (isset($_GET['send'])) { header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); - echo getChatMessages($user_ida['id'], $_GET['id']); + echo getChatMessages($user_ida['id'], $_GET['id'], AG_CHAT_ORDER=='ASC'?TRUE:FALSE, AG_CHAT_ROWS); } else { - $messagearray = getChatMessages($user_ida['id']); + $messagearray = getChatMessages($user_ida['id'], null, AG_CHAT_ORDER=='ASC'?TRUE:FALSE, AG_CHAT_ROWS); $delay = 6500; // 6.5 Sekunden $activeTime = 30; // 30 Min @@ -84,9 +88,18 @@ if (isset($_GET['send'])) { + + + +
+
+ + +
+ + + + \ No newline at end of file diff --git a/ag/inclu/user-controll.php b/ag/inclu/user-controll.php index 3e16ee6..f2e2236 100644 --- a/ag/inclu/user-controll.php +++ b/ag/inclu/user-controll.php @@ -8,6 +8,8 @@ include_once (ROOT_PATH . '//include/online.inc.php'); include_once(ROOT_PATH.'//include/designfunctions.inc.php'); +include_once (ROOT_PATH . '/include/clan.inc.php'); +include_once (ROOT_PATH . '/include/clan_chat.inc.php'); $itemsx1 = mysql_num_rows(mysql_query("SELECT id FROM sp_ware WHERE item='1' AND user='$user_ida[id]'")); $itemsz1 = mysql_fetch_array(mysql_query("SELECT id FROM sp_ware WHERE item='1' AND user='$user_ida[id]' LIMIT 1")); @@ -64,8 +66,16 @@ if ($name AND $passwort) { } else { + if(isClanChatAvailable($user_ida['clan'])) { + $clan_chat_id = getClanChatId('clan_'.$user_ida['clan']); + $chat_link = 'Clan Chat
'; + } else { + $chat_link = ''; + } + $clan_009 = " Mein Clan
+ ".$chat_link." Clan Kämpfe
Clan Markt
Clan Item Nutzung
diff --git a/ag/include/clan.inc.php b/ag/include/clan.inc.php index 0fe1073..5c5b1b6 100644 --- a/ag/include/clan.inc.php +++ b/ag/include/clan.inc.php @@ -12,7 +12,8 @@ include_once (ROOT_PATH . '/include/exp.inc.php'); include_once (ROOT_PATH . '/include/messagefunctions.inc.php'); include_once (ROOT_PATH . '/include/designfunctions.inc.php'); -defineIfNotDefined('CLAN_LVL_NEWSLETTER', 2); +defineIfNotDefined('CLAN_LVL_NEWSLETTER', 1); +defineIfNotDefined('CLAN_LVL_CHAT', 2); defineIfNotDefined('MAX_CHARS_CLANSIGN', 8); $GLOBALS['clan_buffered_instances'] = array (); @@ -334,6 +335,11 @@ function isClanNewsletterAvailable($clanid) { return $clan['level'] >= CLAN_LVL_NEWSLETTER; } +function isClanChatAvailable($clanid) { + $clan = getClan($clanid); + return $clan['level'] >= CLAN_LVL_CHAT; +} + function sendClanNewsletter($user, $text){ $clan = getClan($user['clan']); if(!isClanNewsletterAvailable($clan['id'])) { diff --git a/ag/include/clan_chat.inc.php b/ag/include/clan_chat.inc.php new file mode 100644 index 0000000..6e789e5 --- /dev/null +++ b/ag/include/clan_chat.inc.php @@ -0,0 +1,97 @@ + 0) { + break; + } + } + } + return NULL; +} + +function getClanChatMessages($requester, $clan_chat_id, $count, $asc, $msg_id = NULL) { + if(!is_numeric($count)) { + $count = 10; + } + + + if(checkAccessRights($requester, $clan_chat_id)) { + $result['chat_rows'] = array(); + $sql = 'SELECT * FROM clan_chatroom_messages WHERE clan_chat_id = ' . $clan_chat_id; + if(is_numeric($msg_id)) { + $sql .= ' AND msg_id > ' .$msg_id; + } else { + $max_id_row = mysql_fetch_row(mysql_query('Select max(msg_id) from clan_chatroom_messages WHERE clan_chat_id = ' . $clan_chat_id)); + $sql .= ' AND msg_id > ' . ($max_id_row[0] - $count); + } + $sql .= ' ORDER BY msg_id ' . ($asc?'asc':'desc') . ' LIMIT ' .$count; + $qry = db_query($sql); + while($row = mysql_fetch_assoc($qry)) { + $result['max_id'] = max($result['max_id'], $row['msg_id']); + $result['chat_rows'][] = formatTimestampShortYear($row['zeit']) . ' ' . generateUserNameByID($row['user_id']) . ': ' . encodeNoHTMLWithBB($row['message']); + } + + return $result; + } + return NULL; +} diff --git a/ag/include/messagefunctions.inc.php b/ag/include/messagefunctions.inc.php index a274cde..cc6ab56 100644 --- a/ag/include/messagefunctions.inc.php +++ b/ag/include/messagefunctions.inc.php @@ -20,6 +20,7 @@ include_once(ROOT_PATH.'/include/config/db.inc.php'); include_once(ROOT_PATH.'/include/parse.inc.php'); include_once(ROOT_PATH.'/include/designfunctions.inc.php'); include_once(ROOT_PATH.'/include/bann.inc.php'); +include_once(ROOT_PATH.'/include/sqlwrapper.inc.php'); function sendMessage($von, $besitzer, $betreff, $text){ // $betreff = $betreff; @@ -65,18 +66,18 @@ function sendChatMessage($user,$text, $usergroups){ } } -function getChatMessages($userid, $messageid = 0, $limit = 25){ +function getChatMessages($userid, $messageid = 0, $asc = true, $limit = 25){ if(!is_numeric($messageid)){ $messageid = 0; } - $row = mysql_fetch_row(mysql_query('Select max(id) from ag_chat')); + $row = mysql_fetch_row(db_query('Select max(id) from ag_chat')); $maxid = $row[0]; $minid = $maxid - $limit; if($messageid > $minid){ $minid = $messageid; } - $result = mysql_query('SELECT *, Minute(zeit) as m, Hour(zeit) as h FROM ag_chat WHERE id > '.$minid.' ORDER BY ID ASC LIMIT '.$limit); + $result = db_query('SELECT *, Minute(zeit) as m, Hour(zeit) as h FROM ag_chat WHERE id > '.$minid.' ORDER BY ID '.($asc?'ASC':'DESC').' LIMIT '.$limit); while ($row = mysql_fetch_assoc($result)) { $h = $row['h']; if($h < 10){ $h = '0'.$h;} diff --git a/ag/include/parse.inc.php b/ag/include/parse.inc.php index 12eef02..222d350 100644 --- a/ag/include/parse.inc.php +++ b/ag/include/parse.inc.php @@ -267,7 +267,7 @@ function validateInteger($value, $default){ function validateIntegerArray($value, $default){ if($value == null) $value = array(); - + foreach($value as $i => $v) { $value[$i] = validateInteger($v, $default); } @@ -339,5 +339,8 @@ function formatTimestamp($timestampString) { return preg_replace('#([\d]+?)-([\d]+?)-([\d]+?) ([\d:]+?)#', '\3.\2.\1 \4', $timestampString); } +function formatTimestampShortYear($timestampString) { + return preg_replace('#[\d]{2}([\d]+?)-([\d]+?)-([\d]+?) ([\d:]+?)#', '\3.\2.\1 \4', $timestampString); +} ?> diff --git a/db/animegame_svn.sql b/db/animegame_svn.sql index 3fbb40e..792cbda 100644 --- a/db/animegame_svn.sql +++ b/db/animegame_svn.sql @@ -1878,6 +1878,48 @@ CREATE TABLE `tasking` ( ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; +-- +-- Definition of table `clan_chatrooms` +-- + +DROP TABLE IF EXISTS `clan_chatrooms`; +CREATE TABLE `clan_chatrooms` ( + `clan_chat_id` int(11) NOT NULL AUTO_INCREMENT, + `foreign_id` varchar(255) NOT NULL, + PRIMARY KEY (`clan_chat_id`) +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; + + + +DROP TABLE IF EXISTS `clan_chatroom_clans`; +CREATE TABLE `clan_chatroom_clans` ( + `clan_chat_id` int(11) NOT NULL, + `clan_id` int(11) NOT NULL, + KEY `clan_chatroom_clans_id` (`clan_chat_id`), + KEY `clan_chatroom_clans_clan` (`clan_id`), + CONSTRAINT `clan_chatroom_clans_clan` FOREIGN KEY (`clan_id`) REFERENCES `clan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `clan_chatroom_clans_id` FOREIGN KEY (`clan_chat_id`) REFERENCES `clan_chatrooms` (`clan_chat_id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Definition of table `clan_chatroom_messages` +-- + +DROP TABLE IF EXISTS `clan_chatroom_messages`; +CREATE TABLE `clan_chatroom_messages` ( + `clan_chat_id` int(11) NOT NULL, + `user_id` int(11) NOT NULL, + `message` varchar(255) NOT NULL, + `msg_id` int(11) NOT NULL, + `zeit` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`clan_chat_id`,`msg_id`), + CONSTRAINT `clan_chatroom_messages_id` FOREIGN KEY (`clan_chat_id`) REFERENCES `clan_chatrooms` (`clan_chat_id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + + + + /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;