", $packet); $msg = str_replace("\n", '
', $msg); preg_match("/^(.*)223 Message Complete$/", $msg, $matches); $msg = $matches[1]; // kses input filtering $allowed = array('b' => array(), 'i' => array(), 'a' => array('href' => 1, 'title' => 1), 'p' => array('align' => 1), 'br' => array(), 'font' => array('size' => 1, 'color' => 1, 'face' => 1) ); if (get_magic_quotes_gpc()) { $msg = stripslashes($msg); } return array('msg' => kses($msg, $allowed), 'time' => trim($snttime)); } function rmsSendMessage($id, $pp, $msg) { global $sock, $h, $a; $cmd = "MESSAGE " . $id . "." . $pp . "\r\n"; sendData($cmd); $packet = socket_read($sock, 1024, PHP_NORMAL_READ); if (!preg_match("/^302\s{1}.*/", $packet)) { return false; } $msgcontent = $msg . "\r\n.\r\n"; sendData($msgcontent); $packet = socket_read($sock, 1024, PHP_NORMAL_READ); //e.g. 102 [1254] Sending message to foo@hotmail.com. preg_match("/\[(\d+)\]/", $packet, $matches); $packet = socket_read($sock, 1024, PHP_NORMAL_READ); //e.g. 203 [1254] Event done preg_match("/\[(\d+)\] Event (.*)/", $packet, $matches2); while ($matches[1] != $matches2[1]) { //Event tag doesn't match the Event Done tag, keep trying $packet = socket_read($sock, 1024, PHP_NORMAL_READ); preg_match("/\[(\d+)\]/", $packet, $matches2); } return $matches2[2]; } function rmsGetStatus() { global $sock; $cmd = "STATUS\r\n"; sendData($cmd); $packet = socket_read($sock, 512, PHP_NORMAL_READ); $ownerStatus = array(); while (!preg_match("/^212/", $packet)) { list($tmp, $id, $pp, $status) = explode(' ', $packet, 4); $ownerStatus[$pp] = array('id' => $id, 'status' => $status); $packet = socket_read($sock, 512, PHP_NORMAL_READ); } return $ownerStatus; } function rmsChangeStatus($pp, $status) { global $sock; $cmd = "STATUS $status.$pp\r\n"; sendData($cmd); $packet = socket_read($sock, 512, PHP_NORMAL_READ); while (!preg_match("/^212/", $packet)) { $packet = socket_read($sock, 512, PHP_NORMAL_READ); } return true; } function getUserStuff($packet) { $id = " "; $status = " "; $nick = " "; $newmsgs = " "; $pp = " "; // We have a user now, time to manipulate the string! $i = 3; while ($packet{$i} == ' ') { $i++; } // Grab the id while ($packet{$i} != ' ') { $id .= $packet{$i}; $i++; } $id = trim($id); while ($packet{$i} == ' ') { $i++; } // Grab the Protocol while ($packet{$i} != ' ') { $pp .= $packet{$i}; $i++; } $stop = $i; $pp = trim($pp); // Grab the status $i = strlen($packet) - 1; while ($packet{$i} == ' ') { $i--; } while (!($packet{$i} >= '0' && $packet{$i} <= '9')) { $status .= $packet{$i}; $i--; } $status = strrev($status); $status = trim($status); // Grab the number of new messages while ($packet{$i} == ' ') { $i--; } while ($packet{$i} != ' ') { $newmsgs .= $packet{$i}; $i--; } $newmsgs = strrev($newmsgs); $newmsgs = trim($newmsgs); // Grab the nick while ($packet{$i} == ' ') { $i--; } while ($i > $stop) { $nick .= $packet{$i}; $i--; } $nick = strrev($nick); $nick = kses(trim($nick)); // Now we have a user, lets build a list struct then display the list $user = array('id' => $id, 'nick' => $nick, 'newmsgs' => $newmsgs, 'status' => $status, 'pp' => $pp); return $user; } function xmlentities ($string) { return str_replace (array('&', '"', "'", '<', '>'), array ('&' , '"', ''' , '<' , '>'), $string); } ?>