diff --git a/README.md b/README.md index 90e31d8..29a00f1 100755 --- a/README.md +++ b/README.md @@ -62,6 +62,13 @@ Read-Write access for working directory #### Changelog +* v1.6.0: + * Forced a good amount of JS from index.php to core.js + * User list is live, and working along with web client + * CSS modifications to dark/light.css for user list + * Autofill /msg [username] for input box on nickname click in userlist + * Ignore some IRC server client flags that are not needed in the chat logs. (NAMES, and MOTD EOF lines) + * v1.5.1: * Add /archive, allows to keep IRC logs while clearing chat history. * Minor fixes / tweaks diff --git a/core.js b/core.js new file mode 100644 index 0000000..e3a421e --- /dev/null +++ b/core.js @@ -0,0 +1,237 @@ + var httpObject = null; + var link = ""; + var link2 = ""; + var link3 = ""; + var pinglink = ""; + var ScrollDown = 0; + var msgBox = document.getElementById('msgs'); + var timerID = 0; + + // Get the HTTP Object + function getHTTPObject() { + if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); + else if (window.XMLHttpRequest) return new XMLHttpRequest(); + else { + alert("Your browser does not support AJAX."); + return null; + } + } + + + // MSGBOX input + function UserPM(tag) { + var msgInput = document.getElementById('msg'); + var content = msgInput.value; + msgInput.value = '/msg ' + tag + ' ' + content; + } + + // Change the value of the outputText field + function setHtml() { + if(ajaxVar.readyState == 4){ + var response = ajaxVar.responseText; + var msgBox = document.getElementById("msgs"); + msgBox.innerHTML += response; + ScrollDown = 0; + MsgScrollDown(); + } + } + + // Change the value of the outputText field + function setAll() { + if(ajaxVar.readyState == 4){ + var response = ajaxVar.responseText; + var msgBox = document.getElementById("msgs"); + msgBox.innerHTML = response; + ScrollDown = 0; + MsgScrollDown(); + } + } + + // Getting and generating user list. + function genUserlist() { + if(ajaxUserlist.readyState == 4){ + var response = ajaxUserlist.responseText; + var userlist = document.getElementById('userlist'); + userlist.innerHTML = response; + } + } + + function getUserlist() { + ajaxUserlist = getHTTPObject(); + //var randomnumber=Math.floor(Math.random()*10000); + if (ajaxUserlist != null) { + link = "server.php?userlist&nick="+nickName; + ajaxUserlist.open("GET", link , true); + ajaxUserlist.onreadystatechange = genUserlist; + ajaxUserlist.send(null); + } + } + + + + function doNotificationPm() { + if(ajaxVar4.readyState == 4){ + var mentionUser = ajaxVar4.responseText; + if(Notification.permission==="granted") { + var notify = new Notification("Private message from " + mentionUser, { body: ""}); + } + } + } + + function getPmUser() { + ajaxVar4 = getHTTPObject(); + //var randomnumber=Math.floor(Math.random()*10000); + if (ajaxVar4 != null) { + link4 = "server.php?get=notificationpmed&nick="+nickName; + ajaxVar4.open("GET", link4 , true); + ajaxVar4.onreadystatechange = doNotificationPm; + ajaxVar4.send(null); + } + } + + function checkNotificationPm() { + if(ajaxVar5.readyState == 4){ + var returnMsg = ajaxVar5.responseText; + var compareString = "true"; + //console.log(returnMsg); + if(returnMsg.trim() === compareString.trim()) { + getPmUser(); + } + } + } + + function checkPmUrl() { + ajaxVar5 = getHTTPObject(); + //var randomnumber=Math.floor(Math.random()*10000); + if (ajaxVar5 != null) { + link5 = "server.php?get=notificationpmedexists&nick="+nickName; + ajaxVar5.open("GET", link5 , true); + ajaxVar5.onreadystatechange = checkNotificationPm; + ajaxVar5.send(null); + } + } + + + function doNotificationMention() { + if(ajaxVar2.readyState == 4){ + var mentionUser = ajaxVar2.responseText; + if(Notification.permission==="granted") { + var notify = new Notification("You were mentioned by " + mentionUser, { body: ""}); + } + } + } + + function getMentionUser() { + ajaxVar2 = getHTTPObject(); + //var randomnumber=Math.floor(Math.random()*10000); + if (ajaxVar2 != null) { + link2 = "server.php?get=notificationmention&nick="+nickName; + ajaxVar2.open("GET", link2 , true); + ajaxVar2.onreadystatechange = doNotificationMention; + ajaxVar2.send(null); + } + } + + function checkNotificationMention() { + if(ajaxVar3.readyState == 4){ + var returnMsg = ajaxVar3.responseText; + var compareString = "true"; + //console.log(returnMsg); + if(returnMsg.trim() === compareString.trim()) { + getMentionUser(); + } + } + } + + function checkMentionUrl() { + ajaxVar3 = getHTTPObject(); + //var randomnumber=Math.floor(Math.random()*10000); + if (ajaxVar3 != null) { + link3 = "server.php?get=notificationmentionexists&nick="+nickName; + ajaxVar3.open("GET", link3 , true); + ajaxVar3.onreadystatechange = checkNotificationMention; + ajaxVar3.send(null); + } + } + + + // Implement business logic + function serverWrite() { + ajaxVar = getHTTPObject(); + if (ajaxVar != null) { + link = "server.php?nick="+nickName+"&msg="+encodeURIComponent(document.getElementById('msg').value); + ajaxVar.open("GET", link , true); + ajaxVar.send(null); + } + } + + // Implement business logic + function serverReload() { + ajaxVar = getHTTPObject(); + //var randomnumber=Math.floor(Math.random()*10000); + if (ajaxVar != null) { + link = "server.php?get&nick="+nickName; + ajaxVar.open("GET", link , true); + ajaxVar.onreadystatechange = setAll; + ajaxVar.send(null); + } + } + + function MsgScrollDown() { + if(ScrollDown != 1) { + var msgBox = document.getElementById("msgs"); + msgBox.scrollTop = msgBox.scrollHeight; + ScrollDown = 1; + } + } + + function UpdateTimer() { + serverReload(); + MsgScrollDown(); + getUserlist(); + checkPmUrl(); + checkMentionUrl(); + setTimeout(UpdateTimer, 1000); + } + + function doLogin() { + ajaxVar = getHTTPObject(); + if(ajaxVar != null) { + link = "server.php?do=login&nick="+nickName; + ajaxVar.open("GET", link, true); + ajaxVar.onreadystatechange = setHtml; + ajaxVar.send(null); + setTimeout(function() { window.location.reload(); },1000); + } + } + + function doClearLog() { + ajaxVar = getHTTPObject(); + if(ajaxVar != null) { + link = "server.php?do=clearlog&nick="+nickName; + ajaxVar.open("GET", link, true); + ajaxVar.onreadystatechange = setHtml; + ajaxVar.send(null); + setTimeout(function() { window.location.reload(); },1000); + } + } + + function doLogout() { + ajaxVar = getHTTPObject(); + if(ajaxVar != null) { + link = "server.php?do=logout&nick="+nickName; + ajaxVar.open("GET", link, true); + ajaxVar.onreadystatechange = setHtml; + ajaxVar.send(null); + setTimeout(function() { window.location.reload(); },1000); + } + } + + function wrapBBCode(tag) { + var msgInput = document.getElementById('msg'); + var content = msgInput.value; + var selectedContent = content.substring(msgInput.selectionStart, msgInput.selectionEnd); + var beforeContent = content.substring(0, msgInput.selectionStart); + var afterContent = content.substring(msgInput.selectionEnd, content.length); + msgInput.value = beforeContent + '[' + tag + ']' + selectedContent + '[/' + tag + ']' + afterContent; + } diff --git a/dark.css b/dark.css index 671e2f0..738e059 100755 --- a/dark.css +++ b/dark.css @@ -1,19 +1,19 @@ @import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,400;0,500;1,400&display=swap'); -@media only screen and (min-width: 2201px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 2200px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 1900px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 1700px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 1500px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 1300px) { body { max-width: 1090px; } #msg { width: 920px; } } -@media only screen and (max-width: 1100px) { body { max-width: 890px; } #msg { width: 740px; } } -@media only screen and (max-width: 900px) { body { max-width: 800px; } #msg { width: 660px; } } -@media only screen and (max-width: 800px) { body { max-width: 700px; } #msg { width: 570px; } } -@media only screen and (max-width: 700px) { body { max-width: 600px; } #msg { width: 480px; } } -@media only screen and (max-width: 600px) { body { max-width: 500px; } #msg { width: 380px; } } +@media only screen and (min-width: 2201px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 2200px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 1900px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 1700px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 1500px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 1300px) { body { max-width: 1090px; } #msg { width: 780px; } } +@media only screen and (max-width: 1100px) { body { max-width: 890px; } #msg { width: 600px; } } +@media only screen and (max-width: 900px) { body { max-width: 800px; } #msg { width: 520px; } } +@media only screen and (max-width: 800px) { body { max-width: 700px; } #msg { width: 430px; } } +@media only screen and (max-width: 700px) { body { max-width: 600px; } #msg { width: 340px; } } +@media only screen and (max-width: 600px) { body { max-width: 500px; } #msg { width: 240px; } } /* small windows and phones */ -@media only screen and (max-width: 500px) { body { max-width: 450px; } #msg { width: 330px; } } -@media only screen and (max-width: 400px) { body { max-width: 350px; } #msg { width: 230px; } } +@media only screen and (max-width: 500px) { body { max-width: 450px; } #msg { width: 230px; } } +@media only screen and (max-width: 400px) { body { max-width: 350px; } #msg { width: 170px; } } html { font-family: "DM Mono", Arial, sans-serif; @@ -141,6 +141,28 @@ input, button, select, textarea{ overflow-x: auto; } +.clientcontain { + padding: 0px 0px 0px 22px; + margin: 0 auto; +} + +#userlist { + min-width: 110px; + width: 110px; + font-size: 14px; + background-color: #292929; + padding: 2px 5px 2px 5px; + border-radius: 3px; + border: solid 1px #333333; + margin: 0; + vertical-align: top; +} + +#client { + width: 100%; + margin: 0; +} + #msgs tr:nth-child(even) { background-color: #333333; } #msgs tr:nth-child(odd) { background-color: #262626; } #msgs td:nth-child(even) { width: 80%; max-width: 950px; min-width: 320px; } diff --git a/index.php b/index.php index aabecf1..406a53d 100755 --- a/index.php +++ b/index.php @@ -173,7 +173,15 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn']) && + + + > +
Settings
+ + +
+ +
"; @@ -558,6 +573,9 @@ if (!isset($_SESSION['idleirc-user'])) { } ?> +
+ diff --git a/irc.php b/irc.php index 50f376e..4959eb7 100755 --- a/irc.php +++ b/irc.php @@ -122,6 +122,8 @@ while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') { $ex = explode(' ', $data); $data = htmlentities($data); + if($ex[1] == "376" || $ex[1] == "366") { continue; } + // Send PONG back to the server if ($ex[0] == "PING") { // Log pong @@ -129,12 +131,26 @@ while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') { $pongline = "PONG " . $ex[1] . "\n"; // PONG IRC CMD // Push to IRC server via socket. socket_write($socket, $pongline, strlen($pongline)); - } else if ($ex[1] == "PART") { + } else if ($ex[1] == "353") { + // Userlist has been captured, lets generate it for the client. + // Grabs raw user list + $userlistContent = "" . $ex[4] . "
"; + $userlistRaw = explode($ex[4] . " :", $data); + $userArray = explode(" ", $userlistRaw[1]); + // Generate a list of users, in HTML format for userlist + foreach($userArray as $usi) { + $userlistContent .= "$usi
"; + } + + file_put_contents("users/$username.userlist", $userlistContent); + } else if ($ex[1] == "PART") { $senderNick = get_string_between($data, ":", "!"); $senderIp = get_string_between($data, "@", " "); $exitMsg = explode('PART', $data); + $partChannel = explode(' :', $exitMsg[1]); $msgline = "$senderNick: Leaving
$senderIp left " . stripslashes(trim($exitMsg[1])) . ""; file_put_contents("users/$username.log", $socketFileContents . $msgline); + file_put_contents("users/.$username.push", "NAMES " . $partChannel[0] . "\n"); } else if ($ex[1] == "JOIN") { $senderNick = get_string_between($data, ":", "!"); $senderIp = get_string_between($data, "@", " "); @@ -146,10 +162,11 @@ while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') { $msgline = "" . $server_address . " ~ Joining " . $joinChannel[1] . "\n"; file_put_contents("users/$username.log", $socketFileContents . $msgline); } + file_put_contents("users/.$username.push", "NAMES " . $joinChannel[1] . "\n"); } else if ($ex[1] == "NICK") { $senderNick = get_string_between($data, ":", "!"); $senderIp = get_string_between($data, "@", " "); - $nickMsg = explode('NICK', $data); + $nickMsg = explode('NICK :', $data); $msgline = "$senderNick:" . trim($nickMsg[1]); $msgline .= "
$senderIp"; $msgline .= " $senderNick is now known as" . trim($nickMsg[1]); @@ -161,6 +178,7 @@ while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') { $quitMsg = explode('QUIT :', $data); $msgline = "$senderNick
$senderIp $senderNick left: " . trim($quitMsg[1]) . "\n"; file_put_contents("users/$username.log", $socketFileContents . $msgline); + file_put_contents("users/.$username.push", "NAMES"); } else if ($ex[2] == $usernickname && $ex[1] == "PRIVMSG") { $senderNick = get_string_between($data, ":", "!"); $senderIp = get_string_between($data, "@", " "); diff --git a/light.css b/light.css index 849ea23..c0934b6 100755 --- a/light.css +++ b/light.css @@ -1,19 +1,19 @@ @import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,400;0,500;1,400&display=swap'); -@media only screen and (min-width: 2201px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 2200px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 1900px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 1700px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 1500px) { body { max-width: 1290px; } #msg { width: 1100px; } } -@media only screen and (max-width: 1300px) { body { max-width: 1090px; } #msg { width: 920px; } } -@media only screen and (max-width: 1100px) { body { max-width: 890px; } #msg { width: 740px; } } -@media only screen and (max-width: 900px) { body { max-width: 800px; } #msg { width: 660px; } } -@media only screen and (max-width: 800px) { body { max-width: 700px; } #msg { width: 570px; } } -@media only screen and (max-width: 700px) { body { max-width: 600px; } #msg { width: 480px; } } -@media only screen and (max-width: 600px) { body { max-width: 500px; } #msg { width: 380px; } } +@media only screen and (min-width: 2201px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 2200px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 1900px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 1700px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 1500px) { body { max-width: 1290px; } #msg { width: 960px; } } +@media only screen and (max-width: 1300px) { body { max-width: 1090px; } #msg { width: 780px; } } +@media only screen and (max-width: 1100px) { body { max-width: 890px; } #msg { width: 600px; } } +@media only screen and (max-width: 900px) { body { max-width: 800px; } #msg { width: 520px; } } +@media only screen and (max-width: 800px) { body { max-width: 700px; } #msg { width: 430px; } } +@media only screen and (max-width: 700px) { body { max-width: 600px; } #msg { width: 340px; } } +@media only screen and (max-width: 600px) { body { max-width: 500px; } #msg { width: 240px; } } /* small windows and phones */ -@media only screen and (max-width: 500px) { body { max-width: 450px; } #msg { width: 330px; } } -@media only screen and (max-width: 400px) { body { max-width: 350px; } #msg { width: 230px; } } +@media only screen and (max-width: 500px) { body { max-width: 450px; } #msg { width: 230px; } } +@media only screen and (max-width: 400px) { body { max-width: 350px; } #msg { width: 170px; } } html { font-family: "DM Mono", Arial, sans-serif; @@ -140,6 +140,28 @@ input, button, select, textarea{ overflow-x: auto; } +.clientcontain { + padding: 0px 0px 0px 22px; + margin: 0 auto; +} + +#userlist { + min-width: 110px; + width: 110px; + font-size: 14px; + background-color: #b7b7b7; + padding: 2px 5px 2px 5px; + border-radius: 3px; + border: solid 1px #cccccc; + margin: 0; + vertical-align: top; +} + +#client { + width: 100%; + margin: 0; +} + #msgs tr:nth-child(even) { background-color: #bbbbbb; color: #000000; } #msgs tr:nth-child(odd) { background-color: #b1b1b1; color: #000000; } #msgs td:nth-child(even) { width: 80%; max-width: 950px; min-width: 320px; } diff --git a/server.php b/server.php index 551c69d..f69ec45 100755 --- a/server.php +++ b/server.php @@ -178,6 +178,14 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni //echo nl2br(stripslashes($line)); // DONE +} else if (isset($_GET['userlist'])) { + // Generate userlist + if(file_exists("users/$username.userlist")) { + $userListContent = file_get_contents("users/$username.userlist"); + echo $userListContent; + } else { + echo " "; + } } else if (isset($_GET['get']) && isset($_GET['nick']) && $_GET['nick']!="") { $nick = stripslashes(htmlentities($_GET['nick'])); // Username // Grab IRC client output diff --git a/version.php b/version.php index 22c3f60..5c9dd19 100755 --- a/version.php +++ b/version.php @@ -5,6 +5,6 @@ // https://github.com/Pentium44/idleirc /////// -$version = "1.5.1"; // IdleIRC version +$version = "1.6.0"; // IdleIRC version ?>