From 79d3c716e38084beab01d34a5f49a5aee7e72526 Mon Sep 17 00:00:00 2001 From: Snap Date: Sat, 25 Apr 2015 22:30:21 -0700 Subject: Some work on the Chat. Fixed bug where user could chat as "SERVER" --- .gitignore | 3 ++- ajax/chat.ajax.php | 14 ++++++++++++++ includes/chats.php | 14 +++++++++++++- pages/chat.php | 18 ++++++++++++++---- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index f1b4737..0fa3d81 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ /nbproject/private/ /favicon.ico /emailLockFile +/GitEyePathery /.dropbox /desktop.ini -/.project +/.project diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 1574bde..576ab39 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -52,6 +52,9 @@ if (isset($_REQUEST['messages'])) { } } //Don't lockout requests by holding the session file open! + +$isLoggedIn = ($_SESSION['accepted'] == 1); + session_write_close(); $userID = $_SESSION['userID']; @@ -74,8 +77,19 @@ require_once('../includes/chats.php'); enterChannel($userID); $sent = false; +//User is sending a message if (isset($_REQUEST['messages'])) { $date = isMuted($userID); + if ($isLoggedIn !== true) { + $r[0]['error'] = 'Logged out'; + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = "Whoops, your session has timed out. Please sign in again."; + $r[0]['secondsSince'] = 0; + $r[0]['displayName'] = 'SERVER'; + $r[0]['userID'] = null; + echo json_encode($r); + exit; + } if ($date !== false) { $r[0]['error'] = 'Muted'; $r[0]['serverMessage'] = 'true'; diff --git a/includes/chats.php b/includes/chats.php index 47ecd39..5bfd61f 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -108,6 +108,7 @@ function enterChannel($userID, $channel = 1) { $stmt->bind_param('ii', $userID, $channel); $stmt->execute(); $stmt->close(); + cleanupChannel(); return; } @@ -122,6 +123,14 @@ function exitChannel($userID, $channel = 1) { return; } +//User leaves the channel +function cleanupChannel($channel = 1) { + global $mysqli; + + $mysqli->query("DELETE FROM `chatUsers` WHERE TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) > 800"); + return; +} + function channelListUpdated($timeStamp) { global $mysqli; @@ -150,7 +159,8 @@ function getChannelList($channel = 1) { chatUsers.userID as 'ID', chatUsers.dateEntered, - TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) as dateLastActive, + TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) as secFromLastActive, + TIME_TO_SEC(TIMEDIFF(NOW(), users.dateChatGaggedUntil)) as secSinceGagged, chatUsers.isAdmin, chatUsers.isMod, @@ -160,9 +170,11 @@ function getChannelList($channel = 1) { users.wallColor, users.wallEmblem, users.wallOrientation + FROM `chatUsers` LEFT JOIN `users` ON chatUsers.userID = users.ID + WHERE TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) < 300 ORDER BY chatUsers.isMod DESC, chatUsers.dateEntered ASC "); diff --git a/pages/chat.php b/pages/chat.php index a1870a6..4f10a1c 100644 --- a/pages/chat.php +++ b/pages/chat.php @@ -22,6 +22,7 @@ if (!$accepted) { var lastID = 1; //Internet Explorer doesn't support "const" //CONSTANTS: ... +var channelTimerDelay = 30000; var chatTimerDelayUpper = 9000; var chatTimerDelayLower = 2000; var chatTimerDelayDefault = 5000; @@ -45,6 +46,13 @@ function getChatTimer() { //addChatMessage("Debug", "Chat timer called!"); } +pollChannelListTimer(); +function pollChannelListTimer() { + setTimeout("pollChannelListTimer()", channelTimerDelay); + + pollChannelList(); +} + var firstGetChat = true; function getChatDone(data) { var newChats = false; @@ -288,7 +296,7 @@ function pollChannelListDone(data) { function channelListShow(JO) { console.log("Formating channelList"); - var p = ""; + var p = "
"; console.log('beginloop'); @@ -303,9 +311,11 @@ function channelListShow(JO) { styleClass = 'border-top: 6px solid #777799;'; } } - + + // u.secFromLastActive could be used in here someplace.. + if (u.wallEmblem == undefined) u.wallEmblem = 'blank.png'; - p = p+ ""; + p = p+ ""; p = p+ "
"; p = p+ "
"; @@ -408,7 +418,7 @@ $(function() { function onChatWindowShown() { chatTimerDelay = chatTimerDelayDefault; - getChatTimer(); + getChat(); } function onChatWindowHidden() -- cgit v1.2.3