From 133c2dbbb90c489c95b1e7b50823e9e0cfe9c71f Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Thu, 14 Feb 2013 04:11:33 -0800 Subject: Mute-User and Lockdown for chat. :). --- ajax/chat.ajax.php | 32 ++++++++++++++++++++++++++------ css/chat.css | 3 +++ includes/chats.php | 15 +++++++++++++++ pages/admin.php | 34 ++++++++++++++++++++++++++++++---- pages/chat.php | 4 +++- 5 files changed, 77 insertions(+), 11 deletions(-) diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 3ca15c6..239cc1c 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -4,23 +4,44 @@ session_write_close(); //Just doing this as evidence that $_SESSION as read-only is still available. $userID = $_SESSION['userID']; +$chatLockDown = false; +// STOP CHAT? +//$chatLockDown = true; + require('../includes/chats.php'); $sent = false; if ($_REQUEST['messages']) { + $date = isMuted($userID); + if ($date !== false) { + $r[0]['error'] = 'Muted'; + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = 'You have been muted; You are muted until '.$date." (The current time is: ".date("Y-m-d H:i:s").")"; + $r[0]['secondsSince'] = 0; + $r[0]['displayName'] = 'SERVER'; + echo json_encode($r); + exit; + } + if ($chatLockDown == true AND $_SESSION['isAdmin'] !== true) { + $r[0]['error'] = 'Lockdown'; + $r[0]['serverMessage'] = 'true'; + $r[0]['message'] = 'Chat Lockdown has been activated. Messages are not being accepted'; + $r[0]['secondsSince'] = 0; + $r[0]['displayName'] = 'SERVER'; + echo json_encode($r); + exit; + } + $messages = $_REQUEST['messages']; $messages = explode("|:|", $messages); foreach ($messages as $message) { $message = chatFilter(stripslashes($message)); $insertID = addchat($userID, $message); } - $sent = true; - //echo "IID:$insertID:"; } - if ($_REQUEST['getChatFromID']) { $getChatID = $_REQUEST['getChatFromID']; if ($sent) { @@ -40,11 +61,11 @@ if ($_REQUEST['getChatFromID']) { usleep(100000); } } - //echo "reachedEnd"; $json = prepareChatData(getChat($getChatID)); echo $json; - exit; } +exit; + function prepareChatData($data) { if ($data) { @@ -58,7 +79,6 @@ function prepareChatData($data) { } - function chatFilter($chat) { //cuss words $chat = str_replace("fuck you", "i am moron", $chat); diff --git a/css/chat.css b/css/chat.css index 1af7c4d..6dcf629 100644 --- a/css/chat.css +++ b/css/chat.css @@ -86,6 +86,9 @@ .chatMessage.self { background-color: #444; } +.chatMessage.server { + background-color: #844; +} .chatContainer2 { background-color: #222; diff --git a/includes/chats.php b/includes/chats.php index 6a36fe3..ee222c9 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -7,6 +7,21 @@ include_once('sqli.php'); define('CHAT_ROWS_TO_KEEP', 50); +function isMuted($userID) { + global $mysqli; + + $sql = "SELECT `dateChatGaggedUntil` FROM `users` + WHERE `ID` = ? + AND `dateChatGaggedUntil` > CURDATE()"; + $stmt = $mysqli->prepare($sql); + $stmt->bind_param("i", $userID); + $stmt->execute(); + $stmt->bind_result($date); + $stmt->fetch(); + if ($date) return $date; + else return false; +} + function addChat($userID, $message) { global $mysqli; if ($message == '') diff --git a/pages/admin.php b/pages/admin.php index bda527d..2109f7c 100644 --- a/pages/admin.php +++ b/pages/admin.php @@ -9,7 +9,7 @@ topbar($Links); include_once('./includes/datas.php'); include_once('./includes/maps.php'); include_once('./includes/mapoftheday.php'); -include_once('./includes/sqlEmbedded.php'); +include_once('./includes/sqli.php'); include_once('./includes/playerStats.php'); if ($_GET['applyall'] == 'true') { @@ -41,12 +41,30 @@ else if ($_GET['deleteErrors'] == 'true') { echo "Log restarted!"; } +else if ($_POST['muteUser'] == 'true') { + + muteUser($_POST['muteUserID'], $_POST['muteHours']); + echo "User ID ".$_POST['muteUserID']." muted for ".$_POST['muteHours']." hours"; +} + +function muteUser($userID, $numHours) { + global $mysqli; + $stmt = $mysqli->prepare("UPDATE `users` + SET `dateChatGaggedUntil` = ADDDATE(CURDATE(), INTERVAL ? HOUR) + WHERE `ID` = ?"); + $stmt->bind_param('ii', $numHours, $userID); + $stmt->execute(); + return; +} + + $sql = "SELECT `ID`, `displayName`, `dateJoined`, `dateLogin`, `email`, `isAdmin` FROM `users`"; $result = mysql_query($sql); -echo ' +?> +

Administrators Page

News:

@@ -57,13 +75,21 @@ echo '

Links: View Errorlog.txt

-

Hello admins, this is our current userlist.

+
+ + + USERID: + LENGTH IN HOURS: +
+
-'; + + +' + p + ''); -- cgit v1.2.3
IDDisplay name:Joined On:Last LogonEmailAdministrator