* 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.
main
hecht 13 years ago
parent 04cac8c623
commit 166a82f235

@ -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'])) {
<script type="text/javascript" src="java/prototype-1.6.0.2.js" ></script>
<script type="text/javascript">
var lastmessageid = 0;
var lastmessageid = <?php echo substr($messagearray,0,strpos($messagearray,';')); ?>;
var receiving = false;
var aktiv = <?php echo $aktiv ?>;
var maxMessagesDisplayed = <?php echo AG_CHAT_ROWS; ?>;
var mode = '<?php echo AG_CHAT_ORDER; ?>';
/*
DESC = newest Message on top
ASC = newest Message at bottom
has to fit $mode in messagefunctions.inc.php getChatMessages
*/
function send(){
var myAjax = new Ajax.Request("<?php echo $_SERVER['PHP_SELF']; ?>?send="+encodeURIComponent($("blubb").value)+"&myself=<?php echo $user_ida['nickname']; ?>", { method: 'get', onComplete: sendenfertig });
$("blubb").value = "";
@ -114,7 +127,8 @@ if (isset($_GET['send'])) {
lastmessageid = originalRequest.responseText.substring(0,index);
}
var text = originalRequest.responseText.substring(index+1);
var newMessages=0, newPos=0;
var text2 = $("nope").innerHTML;
var newMessages=0, newPos=0, oldMessages=0, oldPos=0;
// Ermittle Anzahl neuer Nachrichten!
while(true){
newPos = text.indexOf("<div>",newPos)+1;
@ -124,13 +138,33 @@ if (isset($_GET['send'])) {
break;
}
}
// Ermittle die Anzahl der Nachrichten die aktuell dargestellt werden!
while(true) {
oldPos = text2.indexOf("<div>",oldPos)+1;
if(oldPos != 0){
oldMessages++;
} else{
break;
}
}
// okay ... nun ermittle wieviele Nachrichten geloescht werden muessen
newMessages = oldMessages + newMessages - maxMessagesDisplayed;
// Loesche alte Nachrichten!
var text2 = $("nope").innerHTML;
newPos = 0;
for(i=0;i<newMessages;i++){
newPos = text2.toLowerCase().indexOf("</div>",newPos)+6;
if(mode == 'ASC') {
for(i=0;i<newMessages;i++){
newPos = text2.toLowerCase().indexOf("</div>",newPos)+6;
}
$("nope").innerHTML = text2.substring(newPos) + text;
} else {
for(i=0;i<newMessages;i++){
newPos = text2.toLowerCase().lastIndexOf("<div>")-1;
text2 = text2.substring(0, newPos);
}
$("nope").innerHTML = text + text2;
}
$("nope").innerHTML = text2.substring(newPos) + text;
receiving = false;
return;
}

@ -7,11 +7,11 @@
*/
include_once(ROOT_PATH.'/include/clan.inc.php');
include_once(ROOT_PATH.'/include/clan_chat.inc.php');
include_once(ROOT_PATH.'/include/clan_fights.inc.php');
include_once(ROOT_PATH.'/include/fehlerausgabe.inc.php');
// GET-Section
if(isset($_GET['action'])) {
$action = $_GET['action'];
} else {
@ -69,8 +69,6 @@ if((isset($_GET['value1']) || isset($_GET['value2']) || isset($_GET['edited']))
}
}
function displayClanProfileReadOnly($clan, $ownclan, $userid){
$member_qry = mysql_query('Select id from user where clan = '.$clan['id']);
$count = mysql_num_rows($member_qry);
@ -445,6 +443,14 @@ function displayClanProfileEditable($clan, $userid){
function displayClanProfile($clanid, $userid){
$clan = getClan($clanid, FALSE);
$user = getUser($userid, false);
if($user['clan'] == $clan['id']) {
// check if there is a clan chat available
if(getClanChatId('clan_' .$user['clan']) === NULL && isClanChatAvailable($user['clan'])) {
createChatRoom(array($user['clan']), 'clan_' .$user['clan']);
}
}
if(!$clan) {
echo displayErrorMessage(NULL, 'Es gibt den Clan mit der ID ' .$clanid.' nicht oder nicht mehr!', displayHistoryBackLink());
return;

@ -0,0 +1,206 @@
<?php
/*
*
* @copyright (c) 2010 animegame.eu
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
*
*/
session_start();
$nodisturb = 'YES';
include_once('path.inc.php'); // get the path ;)
include_once (ROOT_PATH . '/include/config.inc.php');
include_once (ROOT_PATH . '/include/defines.inc.php');
include_once (ROOT_PATH . '/include/clan_chat.inc.php');
defineIfNotDefined('CLAN_CHAT_ROWS', 25, true);
defineIfNotDefined('CLAN_CHAT_ORDER', 'ASC');
// Die Nachricht muss nicht geparst werden!
// Die ID aber schon
$trueuser = false;
$clan_chat_id = validateUnsignedInteger($_GET['clan_chat_id'], null);
if($clan_chat_id === NULL) {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="design/styleChat.css" rel="STYLESHEET" type="text/css">
</head>
<body>
<p>Der Clanchat kann auf diese Weise nicht aufgerufen werden!</p>
</body>
<?php
die();
}
if(isset($user_ida['nickname'])){
if(!isset($_SESSION['user_ida'])){
$_SESSION['user_ida'] = $user_ida;
}
$trueuser = true;
} else if(isset($_SESSION['user_ida'])){
$user_ida = $_SESSION['user_ida'];
}
//
if (isset($_GET['send'])) {
if(!$trueuser && $_REQUEST['myself'] != $user_ida['nickname']){
echo "ERROR";
} else {
$send = $_GET['send'];
// sendChatMessage($user_ida, $send, $usergroups);
if(sendClanChatMessage($user_ida['id'], $clan_chat_id, $send) === NULL) {
echo "OK";
} else {
echo "ERROR";
}
}
} else if (isset ($_GET['me'])) {
// Cachen verhindern
header("Expires: Sat, 05 Nov 2005 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
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']);
$combi_array = getClanChatMessages($user_ida['id'], $clan_chat_id, CLAN_CHAT_ROWS, CLAN_CHAT_ORDER=='ASC'?TRUE:FALSE, $_GET['id']);
echo $combi_array['max_id'].';<div>'.implode('</div><div>', $combi_array['chat_rows']).'</div>';
} else {
$combi_array = getClanChatMessages($user_ida['id'], $clan_chat_id, CLAN_CHAT_ROWS, CLAN_CHAT_ORDER=='ASC'?TRUE:FALSE);
if($combi_array['chat_rows'] == NULL) {
$messagearray = '0;<div></div>';
} else {
$messagearray = $combi_array['max_id'].';<div>'.implode('</div><div>', $combi_array['chat_rows']).'</div>';
}
$delay = 6500; // 6.5 Sekunden
$activeTime = 30; // 30 Min
$aktiv = round($activeTime * 60 * 1000 / $delay);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="design/styleChat.css" rel="STYLESHEET" type="text/css">
<script type="text/javascript" src="java/prototype-1.6.0.2.js" ></script>
<script type="text/javascript">
var lastmessageid = <?php echo is_numeric($combi_array['max_id'])?$combi_array['max_id']:0; ?>;
var maxMessagesDisplayed = <?php echo CLAN_CHAT_ROWS; ?>;
var receiving = false;
var aktiv = <?php echo $aktiv ?>;
var mode = '<?php echo CLAN_CHAT_ORDER; ?>';
function send(){
var myAjax = new Ajax.Request("<?php echo $_SERVER['PHP_SELF']; ?>?send="+encodeURIComponent($("blubb").value)+"&myself=<?php echo $user_ida['nickname'];?>&clan_chat_id=<?php echo $clan_chat_id; ?>", { method: 'get', onComplete: sendenfertig });
$("blubb").value = "";
aktiv = <?php echo $aktiv ?>;
return false;
}
function sendenfertig(originalRequest ) {
if(originalRequest.responseText != "OK"){
alert("Nachricht konnte nicht versendet werden! Chat wird neu gestartet! (" + originalRequest.responseText + ")");
window.location.reload();
}
}
function anzeigenChat(originalRequest ) {
var index = originalRequest.responseText.indexOf(";");
if(index < 1){
receiving = false;
return;
}
if(!Number(originalRequest.responseText.substring(0,index))){
receiving = false;
return;
} else{
lastmessageid = originalRequest.responseText.substring(0,index);
}
var text = originalRequest.responseText.substring(index+1);
var text2 = $("nope").innerHTML;
var newMessages=0, newPos=0, oldMessages=0, oldPos=0;
// Ermittle Anzahl neuer Nachrichten!
while(true){
newPos = text.indexOf("<div>",newPos)+1;
if(newPos != 0){
newMessages++;
} else{
break;
}
}
// Ermittle die Anzahl der Nachrichten die aktuell dargestellt werden!
while(true) {
oldPos = text2.indexOf("<div>",oldPos)+1;
if(oldPos != 0){
oldMessages++;
} else{
break;
}
}
// okay ... nun ermittle wieviele Nachrichten geloescht werden muessen
newMessages = oldMessages + newMessages - maxMessagesDisplayed;
// Loesche alte Nachrichten!
newPos = 0;
if(mode == 'ASC') {
for(i=0;i<newMessages;i++){
newPos = text2.toLowerCase().indexOf("</div>",newPos)+6;
}
$("nope").innerHTML = text2.substring(newPos) + text;
} else {
for(i=0;i<newMessages;i++){
newPos = text2.toLowerCase().lastIndexOf("<div>")-1;
text2 = text2.substring(0, newPos);
}
$("nope").innerHTML = text + text2;
}
receiving = false;
return;
}
function loadData(){
if(--aktiv == 0){
alert('Du wurdest als Inaktiv erkannt, Ok anklicken um wieder Nachrichten zu empfangen!');
aktiv = <?php echo $aktiv ?>;
}
if(aktiv < 0){
return;
}
if(!receiving){
receiving = true;
var myAjax = new Ajax.Request( "<?php echo $_SERVER['PHP_SELF']; ?>?me=blablubb&clan_chat_id=<?php echo $clan_chat_id; ?>&id="+lastmessageid, { method: 'get', onComplete: anzeigenChat });
}
}
function activate(){
document.forms["myForm2"].style.visibility = "hidden";
return false;
}
setInterval("loadData();",<?php echo $delay ?>);
</script>
</head>
<body>
<form name="myForm" onsubmit="return send();">
<div id="nope" style="width: 100%; overflow: overflow:auto;"><?php echo substr($messagearray,strpos($messagearray,';')+1); ?></div>
<input id="input" type="submit" name="myButton" value="send" style="position:absolute; bottom:0px; left:0px;"/>
<input id="blubb" name="blabla" style="position:absolute; bottom:0px; left:50px; width: 85%;" />
</form>
</body>
</html>
<?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 = '<a href=\'clan_popupchat.php?clan_chat_id='.$clan_chat_id.'\' target=\'_blank\'>Clan Chat</a><br>';
} else {
$chat_link = '';
}
$clan_009 = "
<a href=index.php?as=clan/clan_info>Mein Clan</a><br>
".$chat_link."
<a href=index.php?as=clan/kampf_info>Clan K&auml;mpfe</a><br>
<a href=index.php?as=clan/c_markt>Clan Markt</a><br>
<a href=index.php?as=clan/c_ware>Clan Item Nutzung</a><br>

@ -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'])) {

@ -0,0 +1,97 @@
<?php
/*
*
* @copyright (c) 2012 animegame.eu
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
* @author hecht
*/
include_once(ROOT_PATH.'/include/sqlwrapper.inc.php');
include_once(ROOT_PATH.'/include/user.inc.php');
include_once(ROOT_PATH.'/include/parse.inc.php');
include_once(ROOT_PATH.'/include/messagefunctions.inc.php');
/**
* creates a chat room for a conversation!
* @param array $clan_ids the ids of clans that are allowed to read and write in this chatroom
* @param string $foreign_identifier something like "cf_12345" or "clan_1234"
* return identifier
*/
function createChatRoom(array $clan_ids, $foreign_identifier) {
db_query('INSERT INTO clan_chatrooms(foreign_id) values(\''.$foreign_identifier.'\')');
if(mysql_affected_rows() == 0) {
return 'Konnte den Clanchatroom nicht erstellen, da er schon exisitert!';
}
$chat_id = getClanChatId($foreign_identifier);
foreach ($clan_ids as $clan_id) {
db_query('INSERT INTO clan_chatroom_clans(clan_chat_id, clan_id) values(\''.$chat_id.'\', \''.$clan_id.'\')');
}
return $chat_id;
}
/**
* this method returns the clanChatId using the foreign identifier!!
* @param string $foreign_identifier
*/
function getClanChatId($foreign_identifier) {
$row = mysql_fetch_row(db_query('SELECT clan_chat_id FROM clan_chatrooms WHERE foreign_id = \''.$foreign_identifier.'\''));
return $row[0];
}
function checkAccessRights($user_id, $clan_chat_id) {
if($user_id == NULL) {
return false;
}
$qry = db_query('SELECT clan_chat_id FROM clan_chatroom_clans cc INNER JOIN user u ON cc.clan_id = u.clan WHERE cc.clan_chat_id = ' . $clan_chat_id . ' and u.id = ' .$user_id);
if(!$qry) {
return false;
}
return mysql_num_rows($qry);
}
function sendClanChatMessage($user_id, $clan_chat_id, $message) {
if(checkAccessRights($user_id, $clan_chat_id)) {
$user = getUser($user_id);
while(true) {
$qry = db_query('SELECT IFNULL(max(msg_id),0) + 1 FROM clan_chatroom_messages WHERE clan_chat_id = ' .$clan_chat_id);
if(!qry) {
return 'COULD NOT EXECUTE A QUERY!!!';
}
$row = mysql_fetch_row($qry);
$res = db_query('INSERT INTO clan_chatroom_messages(clan_chat_id, user_id, message, msg_id) values('.$clan_chat_id.', '.$user_id.', \''.$message.'\', '. $row[0] .')');
if(mysql_affected_rows() > 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;
}

@ -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;}

@ -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);
}
?>

@ -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 */;

Loading…
Cancel
Save