Permalink
Browse files

feat-CHT-V27a16: Deep rework of internal chat

  • Loading branch information...
Gorlum
Gorlum committed Apr 23, 2011
1 parent c7c5058 commit b9f4f393f352519efa04056588ca8ea31bb71c02
View
@@ -4,38 +4,38 @@
Main chat window
Changelog:
- 2.0 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 3.0 copyright (c) 2009-2011 Gorlum for http://supernova.ws
+ [!] Almost full rewrote
+ [+] Complies with PCG1
+ 2.0 copyright (c) 2009-2010 Gorlum for http://supernova.ws
[+] Rewrote to remove unnecessary code dupes
- 1.5 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 1.5 copyright (c) 2009-2010 Gorlum for http://supernova.ws
[~] More DDoS-realted fixes
- 1.4 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 1.4 copyright (c) 2009-2010 Gorlum for http://supernova.ws
[~] DDoS-realted fixes
- 1.3 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 1.3 copyright (c) 2009-2010 Gorlum for http://supernova.ws
[~] Security checks for SQL-injection
1.2 by Ihor
- 1.0 copyright 2008 by e-Zobar for XNova
+ 1.0 Shoutbox copyright 2008 by e-Zobar for XNova
**/
-$skip_fleet_update = true;
-
include('common.' . substr(strrchr(__FILE__, '.'), 1));
-lng_include('chat');
-
-$nick = $user['username'];
-$parse = $lang;
+$template = gettemplate('chat_body', true);
-if ($_GET) {
- if($_GET["chat_type"]=="ally"){
- $parse['chat_type'] = $_GET["chat_type"];
- $parse['ally_id'] = $user['ally_id'];
- }
+$ally = sys_get_param_str('ally');
+if ($ally)
+{
+ $template->assign_var('ALLY', intval($user['ally_id']));
+ $page_title = $lang['chat_ally'];
+}
+else
+{
+ $page_title = $lang['chat_common'];
}
-$config->array_set('users', $user['id'], 'chat_lastUpdate', $time_now);
-
-$page = parsetemplate(gettemplate('chat_body'), $parse);
-display($page, $lang['Chat']);
+$config->array_set('users', $user['id'], 'chat_last_activity', $microtime);
+$config->array_set('users', $user['id'], 'chat_last_refresh', 0);
+display($template, $page_title);
-// Shoutbox by e-Zobar - Copyright XNova Team 2008
-?>
+?>
View
@@ -4,58 +4,72 @@
AJAX-called code to post message to chat
Changelog:
- 2.0 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 3.0 copyright (c) 2009-2011 by Gorlum for http://supernova.ws
+ [!] Almost full rewrote
+ [+] Complies with PCG1
+ 2.0 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
[+] Rewrote to remove unnecessary code dupes
- 1.5 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 1.5 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
[~] More DDoS-realted fixes
- 1.4 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 1.4 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
[~] DDoS-realted fixes
- 1.3 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 1.3 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
[~] Security checks for SQL-injection
1.2 by Ihor
1.0 copyright 2008 by e-Zobar for XNova
*/
$skip_fleet_update = true;
-
include('common.' . substr(strrchr(__FILE__, '.'), 1));
-
-if (($config->_MODE != CACHER_NO_CACHE) && ($config->chat_timeout) && ($config->array_get('users', $user['id'], 'chat_lastUpdate') + $config->chat_timeout < $time_now))
+if($config->_MODE != CACHER_NO_CACHE && $config->chat_timeout && $microtime - $config->array_get('users', $user['id'], 'chat_last_activity') > $config->chat_timeout)
{
die();
}
-$msg = SYS_mysqlSmartEscape ($_POST["msg"]);
-$chat_type = SYS_mysqlSmartEscape($_GET['chat_type'] ? $_GET['chat_type'] : $_POST['chat_type']);
-$ally_id = $user['ally_id'];
-
-// On récupère les informations du message et de l'envoyeur
-if ($msg && $user['username']) {
- $nick = trim(strip_tags($user['username']));
- if($ally_id && $chat_type != 'ally'){
- $tag = doquery("SELECT ally_tag FROM {{alliance}} WHERE id = {$user['ally_id']}", '', true);
- $nick .= '(' . trim(strip_tags($tag['ally_tag'])) . ')';
- };
- if ($user['authlevel'] == 3) {
- $nick = preg_replace("#(.+)#", $config->chat_highlight_admin, $nick); //isU
- } elseif ($user['authlevel'] == 2) {
- $nick = preg_replace("#(.+)#", $config->chat_highlight_operator, $nick); //isU
- } elseif ($user['authlevel'] == 1) {
- $nick = preg_replace("#(.+)#", $config->chat_highlight_moderator, $nick); //isU
- }
- $nick = addslashes ($nick);
- $msg = iconv('UTF-8', 'CP1251', $msg); // CHANGE IT !!!!!!!!!!!
-} else {
- $msg="";
- $nick="";
+$message = sys_get_param_str('message');
+if(sys_get_param_int('ally'))
+{
+ $ally_id = $user['ally_id'];
}
+else
+{
+ $ally_id = 0;
+}
+
+if ($message && $user['username'])
+{
+ $nick = trim(strip_tags($user['username']));
+ if($ally_id)
+ {
+ $tag = doquery("SELECT ally_tag FROM {{alliance}} WHERE id = {$ally_id}", '', true);
+ $nick .= '(' . trim(strip_tags($tag['ally_tag'])) . ')';
+ };
+
+ if($user['authlevel'])
+ {
+ switch($user['authlevel'])
+ {
+ case 3:
+ $highlight = $config->chat_highlight_admin;
+ break;
+
+ case 2:
+ $highlight = $config->chat_highlight_operator;
+ break;
+
+ case 1:
+ $highlight = $config->chat_highlight_moderator;
+ break;
+ }
+
+ $nick = preg_replace("#(.+)#", $highlight, $nick);
+ }
-if ($msg && $nick) {
- if($chat_type!="ally" || !$ally_id)
- $ally_id = 0;
+ $nick = mysql_real_escape_string($nick);
+ $message = mysql_real_escape_string(iconv('UTF-8', 'CP1251', $message)); // CHANGE IT !!!!!!!!!!!
- $query = doquery("INSERT INTO {{chat}} (user, ally_id, message, timestamp) VALUES ('{$nick}','{$ally_id}','{$msg}', '{$time_now}');");
- $config->array_set('users', $user['id'], 'chat_lastUpdate', $time_now);
+ $query = doquery("INSERT INTO {{chat}} (user, ally_id, message, timestamp) VALUES ('{$nick}', '{$ally_id}', '{$message}', '{$time_now}');");
+ $config->array_set('users', $user['id'], 'chat_last_activity', $microtime);
}
?>
View
@@ -4,89 +4,118 @@
/*
chat_msg.php
- AJAX-called code to show last X messages/history screen
+ AJAX-called code to show last X chat messages/history
Changelog:
- 2.0 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 3.0 copyright (c) 2009-2011 by Gorlum for http://supernova.ws
+ [!] Almost full rewrote
+ [+] Utilize PTE
+ [+] Complies with PCG1
+ 2.0 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
[+] Rewrote to remove unnecessary code dupes
- 1.5 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 1.5 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
[~] More DDoS-realted fixes
- 1.4 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 1.4 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
[~] DDoS-realted fixes
- 1.3 copyright (c) 2009-2001 by Gorlum for http://supernova.ws
+ 1.3 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
[~] Security checks for SQL-injection
1.2 by Ihor
1.0 copyright 2008 by e-Zobar for XNova
*/
$skip_fleet_update = true;
-
include('common.' . substr(strrchr(__FILE__, '.'), 1));
-$chat_type = SYS_mysqlSmartEscape($_GET['chat_type'] ? $_GET['chat_type'] : $_POST['chat_type']);
-$show_history = SYS_mysqlSmartEscape($_GET['show'] ? $_GET['show'] : $_POST['show']);
-$page = intval($_GET['page'] ? $_GET['page'] : $_POST['page']);
-
-$ally_id = $user['ally_id'];
-
-lng_include('chat');
-if (($config->_MODE != CACHER_NO_CACHE) && ($config->chat_timeout) && ($config->array_get('users', $user['id'], 'chat_lastUpdate') + $config->chat_timeout < $time_now))
+if ($config->_MODE != CACHER_NO_CACHE && $config->chat_timeout && $microtime - $config->array_get('users', $user['id'], 'chat_last_activity') > $config->chat_timeout)
{
print(iconv('CP1251', 'UTF-8', $lang['chat_timeout']));
die();
}
+$history = sys_get_param_str('history');
+
+/*
+if(!$history && $microtime - $config->array_get('users', $user['id'], 'chat_last_refresh') < 1)
+{
+// print($microtime - $config->array_get('users', $user['id'], 'chat_last_refresh'));
+ die();
+}
+*/
+
+$template = gettemplate('chat_messages', true);
+
$page_limit = 25; // Chat rows Limit
-$start_row = $page * $page_limit;
-if($chat_type!='ally' || !$ally_id){
- $ally_id = 0;
+$alliance = sys_get_param_str('ally');
+if($alliance && $user['ally_id'])
+{
+ $alliance = $user['ally_id'];
+}
+else
+{
+ $alliance = 0;
}
-if ($show_history=='history') {
- echo "<div style='width:100%;border:1px solid red;padding:4px;' align=center>";
- echo "<b><font size=3>".$lang['AllyChat']." / ".$lang['chat_history']."</font></b> ";
- echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
- echo "<b><font size=2>".$lang['chat_page'].":</font></b> ";
- echo "<select name='page' onchange='document.location.assign(\"chat_msg.php?chat_type=".$chat_type."&ally_id=".$ally_id."&show=".$show_history."&page=\"+this.value)'>";
- $rows = doquery("SELECT count(1) AS CNT FROM {{chat}} WHERE ally_id = '{$ally_id}';", "",true);
- $cnt = $rows['CNT'] / $page_limit;
- for($i = 0; $i < $cnt; $i++) {
- if($page == $i){
- echo "<option value=\"{$i}\" selected>{$i}</option>";
- }else{
- echo "<option value=\"{$i}\">{$i}</option>";
- }
+if ($history)
+{
+ $rows = doquery("SELECT count(1) AS CNT FROM {{chat}} WHERE ally_id = '{$alliance}';", '', true);
+ $page_count = ceil($rows['CNT'] / $page_limit);
+
+ for($i = 0; $i < $page_count; $i++)
+ {
+ $template->assign_block_vars('page', array(
+ 'NUMBER' => $i
+ ));
}
- echo "</select>";
- echo "</div>";
- $qry = intval($start_row) . ',';
-}else{
- $qry = '';
+ $page = min($page_count, sys_get_param_int('page'));
+}
+else
+{
+ $page = 0;
}
-$query = doquery("SELECT * FROM {{chat}} WHERE ally_id = '{$ally_id}' ORDER BY messageid DESC LIMIT {$qry}{$page_limit};");
+$chat = array();
+$start_row = $page * $page_limit;
+$query = doquery("SELECT * FROM {{chat}} WHERE ally_id = '{$alliance}' ORDER BY messageid DESC LIMIT {$start_row}, {$page_limit};");
+while($chat_row = mysql_fetch_object($query))
+{
+ // Little magik here - to retain HTML codes from DB and stripping HTML codes from nick
+ $nick_stripped = htmlentities(strip_tags($chat_row->user), ENT_QUOTES, 'cp1251');
+ $nick = str_replace(strip_tags($chat_row->user), $nick_stripped, $chat_row->user);
+ if(!$history)
+ {
+ $nick = "<span style=\"cursor: pointer;\" onclick=\"addSmiley('[{$nick_stripped}]');\">{$nick}</span>";
+ }
-$buff = '';
-while($v = mysql_fetch_object($query)){
+ $chat[] = array(
+ 'TIME' => date(FMT_DATE_TIME, htmlentities($chat_row->timestamp, ENT_QUOTES, 'cp1251')),
+ 'NICK' => $nick,
+ 'TEXT' => CHT_messageParse(htmlentities($chat_row->message, ENT_QUOTES, 'cp1251'))
+ );
+}
- $nick = htmlentities(strip_tags($v->user), ENT_QUOTES, cp1251);
- $nick = str_replace(strip_tags($v->user), $nick, $v->user);
- if($show_history != 'history'){
- $nick = "<span style=\"cursor: pointer;\" onclick=\"addSmiley('[ ".htmlentities(strip_tags($v->user), ENT_QUOTES, cp1251)." ]')\">" . $nick ."</span>";
- }
+$chat = array_reverse($chat);
+foreach($chat as $chat_item)
+{
+ $template->assign_block_vars('chat', $chat_item);
+}
- $msg = htmlentities($v->message, ENT_QUOTES, cp1251);
- $msgtimestamp = date(FMT_DATE_TIME, htmlentities($v->timestamp, ENT_QUOTES, cp1251));
+$template->assign_vars(array(
+ 'PAGE' => $page,
+ 'ALLY' => $alliance,
+ 'HISTORY' => $history,
+));
- $msg = CHT_messageParse($msg);
+$config->array_set('users', $user['id'], 'chat_last_refresh', $microtime);
- // Affichage du message
- $msg = "<div align=\"left\" style='background-color:black;color:white;'><span style='font:menu;'>[".$msgtimestamp."]</span> <span style='font:menu;'><b>".$nick."</b></span> : ".$msg."<br></div>";
- $buff = $msg . $buff;
+if($history)
+{
+ display(parsetemplate($template), "{$lang['chat_history']} - {$lang[$alliance ? 'chat_ally' : 'chat_common']}");
+}
+else
+{
+ displayP(parsetemplate($template));
}
-print $buff;
-sys_log_hit();
?>
@@ -1,29 +1,27 @@
<!--[if IE]><style type="text/css"><!-- #chat_box {width: 80%;} --></style><![endif]-->
<script type="text/javascript">
- var chat_type = "{chat_type}";
- var ally_id = "{ally_id}";
+ var ally_id = "{ALLY}";
</script>
<script type="text/javascript" src="js/chat.js"></script>
<br />
<form name="chat_form">
<table id="chat_box"><tbody>
- <tr><td class="c"><span class="fl"><b>{chat_disc}</b></span><span class="fr"><a href=# onClick="MessageHistory()">{chat_history}</a></span></td></tr>
+ <tr><td class="c"><span class="fl"><b><!-- IF ALLY -->{L_chat_ally}<!-- ELSE -->{L_chat_common}<!-- ENDIF --></b></span><span class="fr"><a onClick="window.open('chat_msg.php?ally=' + ally_id + '&history=history', 'ChatHistory', '');">{L_chat_history}</a></span></td></tr>
<tr><th><div id="shoutbox" style="margin: 5px; vertical-align: text-top; height: 380px; overflow:auto;"></div></th></tr>
- <tr><th nowrap>{chat_message}:&nbsp;<select name="color" id="chat_color">
- <option value="white">white</option>
- <option value="blue">blue</option>
- <option value="yellow">yellow</option>
- <option value="green">green</option>
- <option value="pink">pink</option>
- <option value="red">red</option>
- <option value="orange">orange</option>
- </select>&nbsp;
- <input name="msg" type="text" id="msg" style="width:70%" maxlength="120" onKeyPress="if(event.keyCode == 13){ addMessage(); event.returnValue = false; } if (event.keyCode==60 || event.keyCode==62) event.returnValue = false; if (event.which==60 || event.which==62) return false;">&nbsp;<input type="button" name="send" value="{chat_send}" id="send" onClick="addMessage()">
- </th></tr>
+ <tr><th nowrap>{L_chat_message}:&nbsp;<select name="color" id="chat_color">
+ <option value="white">white</option>
+ <option value="blue">blue</option>
+ <option value="yellow">yellow</option>
+ <option value="green">green</option>
+ <option value="pink">pink</option>
+ <option value="red">red</option>
+ <option value="orange">orange</option>
+ </select>&nbsp;<input name="msg" type="text" id="msg" style="width:70%" maxlength="120" onKeyPress="if(event.keyCode == 13){document.chat_form.send.click();event.returnValue = false;return false;}">&nbsp;<input type="button" name="send" value="{L_chat_send}" id="send" onClick="addMessage();event.returnValue = false;return false;"></th>
+ </tr>
<tr>
<th nowrap>
Oops, something went wrong.

0 comments on commit b9f4f39

Please sign in to comment.