Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *//this is the class.core
- <?php
- // start functions
- function customError($errno, $errstr) {
- global $target, $core;
- $core->msg($target, "[$errno] $errstr");
- }
- //stop functions
- class irc {
- var $botnick;
- var $fp;
- function ConnectServer() {
- global $fp, $botnick, $server, $port;
- $fp = fsockopen($server, $port);
- socket_set_blocking($fp, 0);
- $this->command("USER $botnick $botnick $botnick $botnick :$botnick\n");
- $this->command("NICK $botnick\n");
- }
- function botReload($msg = "Normal Reload") {
- exit(10);
- }
- function check_module() {
- return trim(shell_exec("php -l input.php"));
- }
- function JoinChan($chan) {
- $this->command("JOIN $chan\n");
- }
- function term($term) {
- echo date ("G:i:s")."\033[31m << \033[37m$term\n";
- }
- function isCmd($string) {
- global $fc, $command;
- return ("$fc$string" == "$command");
- }
- function isChanCmd($string) {
- global $cfc, $command;
- return ("$cfc$string" == "$command");
- }
- function newPass() {
- $chars = "abcdefghijkmnopqrstuvwxyz023456789";
- srand((double)microtime()*1000000);
- $i = 0;
- $pass = '' ;
- while ($i <= 7) {
- $num = rand() % 33;
- $tmp = substr($chars, $num, 1);
- $pass = $pass . $tmp;
- $i++;
- }
- return $pass;
- }
- function command($cmd) {
- global $fp;
- fwrite($fp, $cmd);
- echo date ("G:i:s")."\033[31m << \033[37m$cmd";
- }
- function access($nick) {
- global $access;
- $keys = array_keys($access);
- if(in_array($nick, $keys)) {
- return $access["$nick"];
- }
- }
- function msg($who = null, $msg = "") {
- if (is_array($msg)){
- foreach ($msg as $message){
- $message = str_replace("\n","",$message);
- $this->command("PRIVMSG $who :$message\n");
- }
- }
- else {
- $msg = str_replace("\n","",$msg);
- $this->command("PRIVMSG $who :$msg\n");
- }
- }
- function notice($who = null, $msg = "") {
- if (is_array($msg)){
- foreach ($msg as $message) {
- $message = str_replace("\n","",$message);
- $this->command("NOTICE $who :$message\n");
- }
- }
- else {
- $msg = str_replace("\n","",$msg);
- $this->command("NOTICE $who :$msg\n");
- }
- }
- function isCtcp() {
- global $command;
- $ctcparr = array("\x01VERSION\x01","\x01PING","\x01USERINFO\x01","\x01DCC");
- return (in_array($command,$ctcparr));
- }
- function nick($newnick) {
- $this->command("NICK $newnick\n");
- $botnick = $newnick;
- }
- function cping($args) {
- global $rarr, $nick, $fp, $target, $botnick;
- $new = 0;
- $who = $rarr[0] ? $rarr[0] : $nick;
- if ($who == $botnick) {
- $this->msg($target, "Ping reply from $who in fuck.you seconds.");
- return;
- }
- $msg = implode(" ",$args);
- $beg = explode(" ",microtime());
- $this->msg($who, "\x01PING $msg\x01");
- $recv = 'lol';
- while(!stristr($recv, "$msg\x01") && $new != 5) {
- $recv = str_replace(array("\r","\n"),array("",""),fgets($fp));
- if($recv != "") echo date ("G:i:s")."\033[32m >> \033[37m$recv\n";
- if(strstr($recv, ":No such nick/channel")) {
- $this->msg($target, "$who was not found.");
- return;
- }
- $test = explode(" ",microtime());
- $new = (int) $test[1] - (int) $beg[1];
- }
- if ($new == 5 && $recv == "") {
- $this->msg($target, "$who did not respond.");
- return;
- }
- else if ($new == 5) {
- $this->msg($target, "$who gave an invalid response.");
- return;
- }
- else {
- echo date ("G:i:s")."\033[32m >> \033[37m$recv\n";
- $end = explode(" ",microtime());
- $ptime = ($end[1] - $beg[1]).strstr(($end[0] - $beg[0]),".");
- //$this->msg($owner, "$ptime Begin:{$beg[1]} {$beg[0]} End:{$end[1]} {$end[0]}");
- $this->msg($target, "Ping reply from $who in $ptime seconds.");
- }
- }
- }
- ?>
- *//this is the runtime
- <?php
- error_reporting(E_ALL & ~E_NOTICE);
- include("config.php");
- $core = new irc;
- $core->ConnectServer();
- $core->JoinChan($chan);
- //$dbconnect = mysql_connect($dbhost, $dbuser, $dbpass);
- //if (!$dbconnect) die("mysql failed somewhere when connecting...");
- //mysql_select_db($dbname, $dbconnect);
- while(!feof($fp)) {
- $data = explode("\r\n", trim(fread($fp, 4096)));
- if($data[0] != "") {
- foreach($data as $line) {
- $w = explode(" ", $line);
- echo date ("G:i:s")."\033[32m >> \033[37m$line\n";
- $command = false;
- $ismsg = 0;
- $hostident = false;
- $nick = false;
- $user = false;
- $host = false;
- $txtcmd = false;
- $target = false;
- $txt = false;
- $txt1 = false;
- $rest = false;
- $rarr = false;
- if(preg_match("/:?((.*?)\!(.*?)\@(.*?))\s(.*?)\s(.*?)\s:?((.*?\s)?(?(1)(.*?)$|$))/", $line, $greps)) {
- $ismsg = 1;
- $hostident = $greps[1];
- $nick = htmlentities($greps[2]);
- $user = $greps[3];
- $host = $greps[4];
- $txtcmd = $greps[5];
- $target = $greps[6];
- $txt = $greps[7];
- $txt1 = trim($greps[8] != "" ? $greps[8] : $greps[9]);
- $rest = trim($greps[8] != "" ? $greps[9] : $greps[8]);
- $rarr = stristr($rest, " ") ? explode(" ",$rest) : array($rest);
- }
- elseif(preg_match("/:?((.*?)\!(.*?)\@(.*?))\s(.*?)\s:?(.*?)$/", $line, $greps)) {
- $hostident = $greps[1];
- $nick = $greps[2];
- $user = $greps[3];
- $host = $greps[4];
- $txtcmd = $greps[5];
- $txt = $greps[6];
- $target = $botnick;
- $ismsg = 0;
- }
- elseif(preg_match("/:?(.*?)\s(.*?)\s(.*?)\s:?(.*?)$/",$line,$infos)) {
- $hostident = $infos[1];
- $txtcmd = $infos[2];
- $target = $infos[3];
- $txt = $infos[4];
- $rarr = explode(" ", $txt);
- }
- elseif(preg_match("/:?((.*?)\!(.*?)\@(.*?))\s(.*?)\s:?(.*?)$/", $line, $greps)) {
- $hostident = $greps[1];
- $nick = $greps[2];
- $user = $greps[3];
- $host = $greps[4];
- $txtcmd = $greps[5];
- $txt = $greps[6];
- $target = $botnick;
- $ismsg = 0;
- }
- elseif(preg_match("/:?(.*?)\s(.*?)\s(.*?)\s:?(.*?)$/",$line,$infos)) {
- $hostident = $infos[1];
- $txtcmd = $infos[2];
- $target = $infos[3];
- $txt = $infos[4];
- $rarr = explode(" ", $txt);
- }
- if(preg_match("/:?(.*?)\s(\d{3})\s(.*?)\s:?(.*?)$/",$line,$infos)) {
- $hostident = $infos[1];
- $txtcmd = "SRVMSG";
- $code = $infos[2];
- $target = $infos[3];
- $txt = $infos[4];
- }
- if(preg_match("/^(\w+)\s:(.*?)$/",$line,$infos)) {
- $hostident = "SERVER";
- $target = $botnick;
- $txtcmd = $infos[1];
- $txt = $infos[2];
- }
- $command = htmlentities(trim($txt1),ENT_QUOTES);
- $target = $target == $botnick ? $nick : $target;
- $input = $core->check_module();
- if(!preg_match("/syntax error, unexpected/i", $input)) {
- $error=0;
- include("input.php");
- }
- if(preg_match("/syntax error, unexpected/i", $input) && $error != 1) {
- $core->msg($chan, "An exception was thrown, please check the logs. Now running in safe mode.");
- $core->term($input);
- $error=1;
- }
- if ($txtcmd == "PING") $core->command("PONG $txt\n");
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment