0 Members and 1 Guest are viewing this topic.
line:join:nameline:join:netham45line:part:name:messageline:part:netham45:Z8015-190Dline:quit:name:message *Merge quit and part?line:quit:netham45:Z8015-190Dline:kick:kicker:kicked:messageline:kick:netham45:netbot45:Kick!line:message:name:message:isOmnomline:message:netham45:Nom!:1line:action:name:messageline:action:netham45:explodesline:mode:modes:targetsline:mode:+ovib:Netham45 Netham45 *@*!*
Lines = Array();Lines[0] = "1:message:Netham45:NOM!";Lines[1] = "2:kick:Netham45:Netbot45:(Netham45)";...addLine(message){ var i = 1; for (i;i<Lines.count();i++) { Lines[i-1] = Lines[i]; } Lines[i] = message; parseMessages();}
parseMessages(){ for (i = 0;i<Lines.count();i++) { parse(Lines[i]); }}parse(message){ chatBox = ""; parts = message.split(":") type = parts[1] curLine = lines; switch type { case "join": chatBox = chatBox + join(parts[2]);break; case "part": chatBox = chatBox + part(parts[2],parts[3]);break; case "quit": chatBox = chatBox + quit(parts[2],parts[3]);break; case "kick": chatBox = chatBox + kick(parts[2],parts[3],parts[4]);break; case "message": chatBox = chatBox + message(parts[2],parts[3]);break; case "action": chatBox = chatBox + action(parts[2],parts[3]);break; case "mode": chatBox = chatBox + mode(parts[2],parts[3]);break; }}join(name) return name + " has joined";part(name,reason) return name + " has left #Omnimaga (" + reason + ")";quit(name,reason) return name + " has quit IRC (" + reason + ")";
curPos = sql_query("SELECT MAX(`line_number') FROM `irc_lines`");sql_query("INSERT INTO `irc_lines` (`action`,`name1`,`name2`,`message`) VALUES ('%s','%s','%s','%s')",curPos,"Join","Netham45","0","0");sql_query("INSERT INTO `irc_lines` (`action`,`name1`,`name2`,`message`) VALUES ('%s','%s','%s','%s')",curPos,"Kick","Netham45","Netbot45","Stop Lagging you stupid bot!");sql_query("DELETE FROM `irc_lines` WHERE `line_number` < %s",curPos - 1000);
getLines(){ while (true) { stuffs = mysql_fetch_array(sql_query("SELECT * FROM `irc_lines` WHERE 'line_number' > %s",reqLines)); for (i=0;i<count(stuffs);i++) { switch (stuffs['action']) { case "join: echo stuffs['line_number'] . ':' . stuffs['action'] . ':' . stuffs['name1]; etc... } } if (count(stuffs)) break; sleep(50); }}
messageList = Array();userList = Array();curLine = 0;messageBox = document.getElementById("MessageBox");Lines = Array();//******************************// Start Request Loop functions//****************************** function startLoop() { xmlhttp=getAjaxObject(); if (xmlhttp==null) { alert ("Your browser does not support AJAX! Please update for OmnomIRC compatibility."); return; } xmlhttp.onreadystatechange=getIncomingLine; sendRequest(); } function sendRequest() { url = "http://omnom.omnimaga.org/OmnomIRC_Dev/Update.php?lineNum=" + curLine; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function getIncomingLine() { if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") { addLine(xmlhttp.responseText); sendRequest(); } } function getAjaxObject() { xmlhttp=new XMLHttpRequest(); //Decent Browsers if (!xmlhttp || xmlhttp == undefined || xmlhttp == null) xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); //IE7+ if (!xmlhttp || xmlhttp == undefined || xmlhttp == null) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); //IE6- return xmlhttp; } //******************************// End Request Loop functions//******************************//******************************// Start Line adding functions//****************************** function addLineStart(message) { setCurLine(message); Lines[Lines.length] = message; } function addLine(message) { var i = 1; setCurLine(message); for (i;i<Lines.length;i++) { Lines[i-1] = Lines[i]; } Lines[i-1] = message; parseMessages(); } function setCurLine(message) { curLine = message.split(":")[0]; }//******************************// End Line Adding Functions//******************************//******************************// Parser Start//****************************** function parseMessages() { text = ""; var i = 0; for (i = 0;i<Lines.length;i++) { text = text + parse(Lines[i]); } messageBox.innerHTML = text; } function parse(message) { a = message; parts = message.split(":"); type = parts[1]; for (i = 2;i < parts.length;i++) parts[i] = atob(parts[i]); //De-base64 it. ***** WILL NOT WORK IN IE ***** switch (type) { case "join": return join(parts[2]);break; case "part": return part(parts[2],parts[3]);break; case "quit": return quit(parts[2],parts[3]);break; case "kick": return kick(parts[2],parts[3],parts[4]);break; case "message": return sendMessage(parts[2],parts[3],parts[4]);break; case "action": return action(parts[2],parts[3],parts[4]);break; case "mode": return mode(parts[2],parts[3]);break; } return ""; } function join(name) { return name + " has joined #omnimaga" + "\n<br/>"; } function part(name,reason) { return name + " has left #omnimaga (" + reason + ")" + "\n<br/>"; } function quit(name,reason) { return name + " has quit IRC (" + reason + ")" + "\n<br/>"; } function kick(kicker,kicked,reason) { return kicker + " has kicked " + kicked + " from #omnimaga (" + reason + ")" + "\n<br/>"; } function sendMessage(name,message,isOmnom) { return "<" + name + "> " + message + "\n<br/>"; } function action(name,action) { return " * " + name + " " + action + "\n<br/>"; } function mode(name,mode) { return name + " set #omnimaga mode " + mode + "\n<br/>"; }//******************************// Parser End//******************************function load(){ var body= document.getElementsByTagName('body')[0]; var script= document.createElement('script'); script.type= 'text/javascript'; script.src= 'Load.php?count=17'; script.onload= function(){parseMessages();startLoop();}; body.appendChild(script);}window.onLoad = load();
<?PHPfunction sql_query(){ global $sqlConnection; $params = func_get_args(); $query = $params[0]; $args = Array(); for ($i=1;$i<count($params);$i++) $args[$i-1] = htmlspecialchars(mysql_real_escape_string(trim($params[$i]),$sqlConnection)); $result = mysql_query(vsprintf($query,$args),$sqlConnection); if (!$result) die(mysql_error() . "Query: " . vsprintf($query,$args)); return $result;}function getMessage($parts,$start,$trim){ if($trim) $message = substr($parts[$start++],1); for ($i = $start; $i < count($parts);$i++) $message = $message . " " . $parts[$i]; $message = trim($message); return $message;}function parseMsg($allMessage){ global $socket,$hasIdent,$ident; $lines = explode("\n",$allMessage); foreach ($lines as $Message) { $parts = explode(" ",$Message); preg_match("/:(.*)!(.*)@(.*)/",$parts[0],$info); $channel = strtolower($parts[2]); if (strtolower($parts[0]) == "ping") socket_write($socket,"PONG " . trim($parts[1]) . "\n"); switch(strtolower($parts[1])) { case "privmsg": $message = getMessage($parts,3,true); if ($message == "!quit") socket_write($socket,"QUIT :Requested!\n"); if (preg_match("/ACTION (.*)/",$message,$messageA)) addLine($info[1],'','action',$messageA[1],$channel); else addLine($info[1],'','message',$message,$channel); break; case "join": addLine($info[1],'','join','',$channel); break; case "part": $message = getMessage($parts,3,true); addLine($info[1],'','part',$message,$channel); break; case "mode": $message = getMessage($parts,3,false); addLine($info[1],'','mode',$message,$channel); break; case "kick": $message = getMessage($parts,4,true); addLine($info[1],$parts[3],"kick",$message,$channel); break; case "quit": $message = getMessage($parts,2,true); addLine($info[1],$parts[3],"quit",$message,''); break; case "376": socket_write($socket,"JOIN #omnimaga-test\n"); break; } }} function addLine($name1,$name2,$type,$message,$channel){ global $socket; $curPosArr = mysql_fetch_array(sql_query("SELECT MAX('line_number') FROM `irc_lines`")); $curPos = $curPosArr[0]+ 1; sql_query("INSERT INTO `irc_lines` (`name1`,`name2`,`message`,`type`,`channel`) VALUES ('%s','%s','%s','%s','%s')",$name1,$name2,$message,$type,$channel); sql_query("DELETE FROM `irc_lines` WHERE `line_number` < %s",$curPos - 1000);}?><?PHP error_reporting(0); $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (!socket_connect($socket,"irc.mzima.net",6667)) die("Could not connect. Error: " . socket_last_error()); $sqlConnection = mysql_connect("localhost","OmnomIRC","-snip-"); if (!$sqlConnection) die("Could not connect to SQL DB."); if (!mysql_select_db("omnomirc",$sqlConnection)) die('Invalid query: ' . mysql_error()); $ident = "PASS none\nUSER OmnomIRC OmnomIRC OmnomIRC :OmnomIRC\nNICK Omnom_Dev\n"; sleep(1); socket_write($socket,$ident); while ($recBuf = socket_read($socket,1024)) { echo $recBuf; parseMsg($recBuf); } socket_close($socket);?>
<?PHP header('Content-type: text/javascript'); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $curLine = $_GET['count']; $sqlConnection = mysql_connect("localhost","OmnomIRC","-snip-"); if (!$sqlConnection) die("Could not connect to SQL DB."); if (!mysql_select_db("omnomirc",$sqlConnection)) die('Invalid query: ' . mysql_error()); function sql_query() { global $sqlConnection; $params = func_get_args(); $query = $params[0]; $args = Array(); for ($i=1;$i<count($params);$i++) $args[$i-1] = mysql_real_escape_string($params[$i],$sqlConnection); $result = mysql_query(vsprintf($query,$args),$sqlConnection); if (!$result) die(mysql_error() . "Query: " . vsprintf($query,$args)); return $result; } $curLineArr = mysql_fetch_array(sql_query("SELECT MAX(`line_number`) FROM `irc_lines`")); $curLine = $curLineArr[0] - $curLine; $destLine = $curLineArr[0]; for ($curLine;$curLine <= $destLine;$curLine++) { $result = mysql_fetch_array(sql_query("SELECT * FROM `irc_lines` WHERE `line_number` = %s",$curLine)); echo "addLineStart('"; switch (strtolower($result['type'])) { case "message": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result['message'])) . ':' . base64_encode("0");break; case "action": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result['message'])) . ':' . base64_encode("0");break; case "join": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1']));break; case "part": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result["message"]));break; case "kick": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result["name2"])) . ":" . base64_encode(htmlspecialchars($result["message"]));break; case "quit": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result["message"]));break; case "mode": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result["message"]));break; } echo "');\n"; } mysql_close($sqlConnection);?>
<?PHP header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $curLine = $_GET['lineNum']; $sqlConnection = mysql_connect("localhost","OmnomIRC","-snip-"); if (!$sqlConnection) die("Could not connect to SQL DB."); if (!mysql_select_db("omnomirc",$sqlConnection)) die('Invalid query: ' . mysql_error()); function sql_query() { global $sqlConnection; $params = func_get_args(); $query = $params[0]; $args = Array(); for ($i=1;$i<count($params);$i++) $args[$i-1] = mysql_real_escape_string($params[$i],$sqlConnection); $result = mysql_query(vsprintf($query,$args),$sqlConnection); if (!$result) die(mysql_error() . "Query: " . vsprintf($query,$args)); return $result; } while (true) { $result = mysql_fetch_array(sql_query("SELECT * FROM `irc_lines` WHERE `line_number` = %s",$curLine + 1)); if (!isset($result[0])) {sleep(1); continue;} switch (strtolower($result['type'])) { case "message": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result['message'])) . ':' . base64_encode("0");break; case "action": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result['message'])) . ':' . base64_encode("0");break; case "join": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1']));break; case "part": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result["message"]));break; case "kick": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result["name2"])) . ":" . base64_encode(htmlspecialchars($result["message"]));break; case "quit": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result["message"]));break; case "mode": echo $result['line_number'] . ":" . $result['type'] . ":" . base64_encode(htmlspecialchars($result['name1'])) . ":" . base64_encode(htmlspecialchars($result["message"]));break; } break; } mysql_close($sqlConnection);?>
Hmm, looks quite interesting. If I'm not mistaken, the loop keeps a xmlhttprequest open until it timeouts, and then starts a new request (endless loop here) ?
No, it keeps it open until my server responds. It shouldn't time out at all. I have a random-length sleep() on the script that's spewing data for testing.