$nick -> " . $cmd[1] . ": | ";
foreach($prvmsg as $word) {
// Grab each word in the array after the privmsg username
if($x == 0) {
$line .= ":" . $word;
$logline .= $word;
} else {
$line .= " " . $word;
$logline .= " " . $word;
}
$x++;
}
$line .= "\n";
$logline .= " | \n";
} else if($cmd[0]=="/me") { // If using /msg, push private message
$prvmsg = array_splice($cmd, 1); // grab private message from string
$line .= "PRIVMSG" . " " . $channel . " :\x01ACTION "; // set for push
$x = 0;
$logline .= "$channel: | $nick ";
foreach($prvmsg as $word) {
// Grab each word in the array after the privmsg username
if($x == 0) {
$line .= $word;
$logline .= $word;
} else {
$line .= " " . $word;
$logline .= " " . $word;
}
$x++;
}
$logline .= " |
\n";
$line .= "\x01\n";
} else if ($cmd[0]=="/join") {
doLog("$username: joining " . $cmd[1]);
$line .= "JOIN " . trim($cmd[1]) . "\n"; // set for push
//$logline .= "$nick: | Joining " . $cmd[1] . " |
\n"; // push to client
$_SESSION['idleirc-channel'] = trim($cmd[1]);
} else if ($cmd[0]=="/nick") {
if($cmd[1]!="") {
doLog("$username: setting nick to " . $cmd[1]);
$line .= "NICK " . trim($cmd[1]) . "\n"; // set for push
//$logline .= "$nick: | Joining " . $cmd[1] . " |
\n"; // push to client
$_SESSION['idleirc-nick'] = trim($cmd[1]);
}
} else if ($cmd[0]=="/list") {
if($cmd[1]!="") {
doLog("$username: listing users for " . $cmd[1]);
$line .= "NAMES " . trim($cmd[1]) . "\n"; // set for push
} else {
doLog("$username: listing users for $channel");
$line .= "NAMES $channel\n"; // set for push
}
} else if ($cmd[0] == "/rejoin") {
doLog("$username: rejoining channel");
if ($cmd[1] != "") {
$line .= "PART " . trim($cmd[1]) . " :$username leaving...\n"; // push close command to IRC
$line .= "JOIN " . trim($cmd[1]) . "\n"; // set for push
//$logline .= "$nick: | Leaving " . trim($cmd[1]) . " |
\n"; // push to client
} else {
$line .= "PART $channel :$username leaving...\n"; // push close command to IRC
$line .= "JOIN $channel\n"; // set for push
//$logline .= "$nick: | Leaving $channel |
\n"; // push to client
}
} else if ($cmd[0] == "/part") {
doLog("$username: leaving " . trim($cmd[1]));
if ($cmd[1] != "") {
$line .= "PART " . trim($cmd[1]) . " :$username leaving...\n"; // push close command to IRC
//$logline .= "$nick: | Leaving " . trim($cmd[1]) . " |
\n"; // push to client
} else {
$line .= "PART $channel :$username leaving...\n"; // push close command to IRC
//$logline .= "$nick: | Leaving $channel |
\n"; // push to client
}
} else if ($cmd[0] == "/focus" || $cmd[0] == "/switch" || $cmd[0] == "/query") {
if(trim($cmd[1]) != $channel) {
$_SESSION['idleirc-channel'] = trim($cmd[1]);
$logline .= "$title $version: | " . trim($cmd[1]) . " is focused, all messages will be sent to " . trim($cmd[1]) . " |
\n"; // push to client
} else {
$logline .= "$title $version: | You're already focused on $channel |
\n";
}
} else if ($cmd[0] == "/help" || $cmd[0] == "/?") {
$logline .= "$title $version | ";
$logline .= "HELP: Information about $title /join [channel] : Join IRC channel [channel] ";
$logline .= "/focus [channel|user]: Funnel messages to specific channel or user (Alias: /switch; /query) ";
$logline .= "/part (channel): Part channel, part focused channel if none specified ";
$logline .= "/rejoin (channel): Part, and join a channel; focused channel if none is specified ";
$logline .= "/nick [nickname]: Change your nickname ";
$logline .= "/list [channel]: List users in a channel |
\n";
} else {
// @@ This is a work in progress
// Sends every channel message to each channel :[
$line .= "PRIVMSG $channel :$msg\n";
$logline .= "$nick to $channel: | $msg |
\n";
}
// Get original content
$content = file_get_contents("$username.log");
echo "" . nl2br(stripslashes($content)) . "
";
// Grab all contents, and push to socket output file.
file_put_contents("$username.log", $content . $logline);
// Grab user message and push to IRC client
file_put_contents(".$username.push", $line);
// Throw out your user message
//echo nl2br(stripslashes($line));
// DONE
} else if (isset($_GET['get']) && isset($_GET['nick']) && $_GET['nick']!="") {
$nick = stripslashes(htmlentities($_GET['nick'])); // Username
// Grab IRC client output
$content = file_get_contents("$nick.log");
// Push content to the web frontend
echo "" . nl2br(stripslashes($content)) . "
1 ? TRUE : FALSE ;
if(!isset($_SESSION['idleirc-channel']) || $isachannel == FALSE) {
file_put_contents(".$nick.push", "JOIN " . $default_channel . "\n");
} else {
file_put_contents(".$nick.push", "JOIN " . $channel . "\n");
}
// Make sure users DB is clean, put nothing into socket read file
if(!file_exists("$nick.log")) {
file_put_contents("$nick.log", "");
chmod("$username.log", 0755); // file permissions for read / write
}
// start pingfile - determines if webclient is active via write timestamp
file_put_contents(".$nick.pingfile", "pong");
chmod(".$username.pingfile", 0755); // file permissions for read / write
// Execute IRC client in background
// IRC server will die when either 1) pingfile is deleted, or
// 2) if pingfile is older than 10 seconds of current sys time
$realpath = realpath("./irc.php"); // get full file path
// Execute IRC client
shell_exec("/usr/bin/php $realpath $nick $servaddr $servport > /dev/null 2>/dev/null &");
} else if($_GET['do']=="logout" && ($acctpass == $userpass)) { // Is user asking for logout?
// Remove ping file if user logs out. IRC server will close
$content = file_get_contents("$nick.log");
file_put_contents("$nick.log", $content . "$nick ~ | left the server... |
\n");
unlink(".$nick.pingfile");
} else if($_GET['do']=="keepup") { // Client asking for keepup ping.
// PONG to server.
//file_put_contents(".$nick.pingfile", "ping");
}
}
?>