/kloxo/httpdocs/live/main.php
PHP | 576 lines | 469 code | 60 blank | 47 comment | 82 complexity | 55cba5e4b753c76679bef8cc4c389fcd MD5 | raw file
- <?php
- if (preg_match("/Mozilla\/\d.+Compatible; MSIE/i", $_SERVER['HTTP_USER_AGENT']) && !preg_match("/Opera/i", $_SERVER['HTTP_USER_AGENT'])) {
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- } else {
- header('Expires: 0');
- header('Pragma: no-cache');
- }
- include("common.php");
- include("ircfunc.php");
- $gl_never_responded = 1;
- $gl_client_started = 0;
- $livetrfp = null;
- if ($g_login) {
- $livetrfp = lfopen("__path_program_etc/livetranscript.txt", "a");
- }
- /*
- $channel = $_GET['channel'];
- echo "$channel <br>";
- if (!$channel) {
- $channel = $channels[0];
- }
- */
- if ($redirect)
- $channel = "{$chanbase}-command";
- else
- $channel = $chanbase;
- $licid = $_GET['licid'];
- $user = $_GET['username'];
- $id = $_GET['id'];
- $base_nick = $_GET['username'];
- //$nick = "hello";
- //$serv_addr = "127.0.0.1";
- //$serv_port = 6667;
- echo <<<EOF
- <html>
- <head>
- <title>PHP IRC Chat output page</title>
- $css
- </head>
- <body bgcolor="$chan_bg" text="$chan_fg">
- EOF;
- flush();
- $smily_code = array("/:-?\)/",
- "/;b/",
- "/:-?P/i",
- "/;-?\)/i",
- "/:-?\(/",
- "/:-?D/i",
- "/:-?\|/i",
- "/\(y\)/i",
- "/:-?S/i");
- $smily_repl = array("<img src='pics/sm-smile.gif' width=15 height=15>",
- "<img src='pics/sm-bsmile.gif' width=15 height=15>",
- "<img src='pics/sm-psmile.gif' width=15 height=15>",
- "<img src='pics/sm-wink.gif' width=15 height=15>",
- "<img src='pics/sm-sad1.gif' width=15 height=15>",
- "<img src='pics/sm-dsmile.gif' width=15 height=15>",
- "<img src='pics/sm-amazed.gif' width=15 height=15>",
- "<img src='pics/sm-thumbsup.gif' width=15 height=15>",
- "<img src='pics/sm-sad2.gif' width=15 height=15>");
- @set_time_limit(3600); // ten minutes execution time, when user says or does something, this is reset with 10 min.
- /* ** ** set_time_limit() doesn't seem to have any effect whatsoever... ** ** */
- register_shutdown_function("einde");
- echo <<<EOF
- <script language="JavaScript"><!--; parent.scrl(1); //--></script>
- EOF;
- $socket = irc_open($serv_addr, $serv_port, $errno, $errstr);
- if ($socket < 0) { echo "failed... $errno: $errstr"; return; }
- else { echo "Connecting to Lxlabs Live. Please Wait....<br> "; }
- $max_per_personnel = $_REQUEST['max_per_personnel'];
- $max_number_personnel = $_REQUEST['max_number_personnel'];
- $per_personnel = 1;
- $number_personnel = 1;
- if ($redirect) {
- $nick = "{$base_nick}_{$number_personnel}-{$per_personnel}";
- } else {
- $nick = $base_nick;
- }
- echo "<br>";
- echo "<script language='JavaScript'>\n<!--;\n parent.scrl(1);\n //-->\n</script>";
- flush(); //output this;
- $out = "";
- $login_flag = 0;
- $loggedin = false;
- $nickcount = 0;
- $inchan = false;
- $nicktry = 0;
- $signontime = time();
- function einde() {
- global $link, $user, $id;
- global $socket,$signontime;
- if ($socket) {
- irc_write($socket, "QUIT :lxlabs \r\n");
- irc_close($socket);
- }
- sqlite_query($link, "DELETE FROM phpchat WHERE username = '$user' AND id = '$id'");
- $signofftime = time();
- $onlinetime = $signofftime-$signontime;
- $d1 = (floor($onlinetime/3600) < 10) ? "0".floor($onlinetime/3600) : floor($onlinetime/3600);
- $rest = $onlinetime%3600;
- $d1 .= (floor($rest/60) < 10) ? ":0".floor($rest/60) : ":".floor($rest/60);;
- $rest = $rest%60;
- $d1 .= ($rest < 10) ? ":0".$rest : ":".$rest;
- echo "Signed on at: " . date("H:i:s d-m-Y", $signontime) . ", Signed off at: " . date("H:i:s d-m-Y", $signofftime) . "<br>";
- echo "Online time: $d1 ($onlinetime seconds)";
- }
- function retn_color($fg, $bg) {
- global $ircColors;
- if ($bg != -1) {
- return "<font style='color: ".$ircColors[$fg]."; background-color: ".$ircColors[$bg].";'>";
- } else {
- return "<font style='color: ".$ircColors[$fg].";'>";
- }
- }
- function smile_repl($string) {
- return $string;
- global $smily_code, $smily_repl, $ircColors, $page_bg, $page_fg;
- $string = preg_replace("/\003(\d+),(\d+)/e", "retn_color($1,$2)", $string);
- $string = preg_replace("/\003(\d+)/e", "retn_color($1, -1)", $string);
- $string = preg_replace("/\003/", "<font style='color: $page_fg; background-color: $page_bg;'>", $string);
- for ($a = 0; $a < substr_count($string, "<font"); $a++) {
- $string .= "</font>";
- }
- return preg_replace($smily_code, $smily_repl, $string);
- }
- $link = lsqlite_open($g_db_file);
- $fully_logged_in = 0;
- $timetoping = 10; // every tenth loop ask a ping reply
- $gl_timer = 0;
- $gl_nonavailable_printed = false;
- while($socket > 0) {
- $read = null;
- $read[0] = $socket;
- $writea = null;
- $excpta = null;
- /*
- foreach((array) $client as $c) {
- $read[] = $c['sock'];
- }
- */
- //dprint("Before: ");
- //dprintr($read);
- // Set up a blocking call to stream_select()
- $ready = stream_select($read, $writea, $excpta, 1);
- //dprint("After: $ready");
- //dprintr($read);
- // This means that sock - which is our main master socket - is ready for reading, which in turn signifies that a NEW connection has arrived. The other members of the read array
- $full = null;
- if ($ready) {
- if (in_array($socket, $read)) {
- $full = irc_read($socket, 4096);
- }
- }
- $full = rtrim($full);
- $timeout = 30;
- if ($gl_never_responded && $gl_client_started) {
- $gl_timer++;
- if ($gl_timer == $timeout) {
- irc_write($socket, "PRIVMSG $channel :lxclmsg2 No response for 50 sec\r\n");
- //print($gl_timer);
- }
- if ($gl_timer % (2 * $timeout) == 0) {
- //print($gl_timer);
- irc_write($socket, "PRIVMSG $channel :lxclmsg3 No response for $gl_timer/20 sec\r\n");
- }
- if ($gl_timer % (6 * $timeout) == 0) {
- //print($gl_timer);
- irc_write($socket, "PRIVMSG $channel :lxclmsg3 No response for $gl_timer/20 sec\r\n");
- if (!$gl_nonavailable_printed) {
- print("It appears there's no one in the channel. Please leave your message here, or please contact lxhelp@lxlabs.com. We apologize for the inconvenience <br> \n");
- $gl_nonavailable_printed = true;
- } else {
- print("...");
- }
- }
- }
- $list = explode("\n", $full);
- foreach($list as $out) {
- if (strlen($out) > 1) {
- //print($out . "<br> ");
- if (preg_match("/PING (.+)/", $out, $matches)) {
- irc_write($socket, "PONG $matches[1]\r\n");
- //echo "ping-pong<br>";
- } elseif (preg_match("/:([^\s]+) NOTICE ([^\s]+) :(.+)/", $out, $matches)) {
- if (preg_match("/$nick/i", $matches[3])) {
- $matches[1] = "<b>$matches[1]</b>";
- }
- $src = $matches[1];
- $text = smile_repl(htmlspecialchars($matches[3]));
- if (preg_match("/([^!]+)!.+/", $src, $matches)) {
- $src = $matches[1];
- }
- //echo "<font color='$ircColors[5]'>-$src- $text</font><br>";
- } elseif (preg_match("/:[^ ]* (\d+) ([^\s]+) (.+)/i", $out, $matches)) {
- if ($matches[1] == "006" || $matches[1] == "001") {
- if ($redirect) {
- $cmdchan = "{$chanbase}_{$number_personnel}-command" ;
- $realchan = $chanbase . "_" . $number_personnel . "-" . $per_personnel ;
- irc_write($socket, "JOIN #$cmdchan\r\n");
- irc_write($socket, "PRIVMSG #$cmdchan :lxcommand channel #$realchan\r\n");
- irc_write($socket, "PART #$cmdchan\r\n");
- //print($realchan);
- irc_write($socket, "JOIN #$realchan\r\n");
- } else {
- irc_write($socket, "JOIN #$chanbase\r\n");
- }
- //print("gotcha<br> \n");
- }
- if ($matches[1] == "PONG") {
- }
-