X-Git-Url: http://git.pk910.de/?p=PHP-P10.git;a=blobdiff_plain;f=Bots%2FJavaGod.class.php;h=364abf57feaa71cd7696248f0d57912747a1ce68;hp=e41ef021a92d393fc1184741f45f8243d314db02;hb=7f51193ddac01b0540000c756c50167ff015e02a;hpb=811bc0c7a1f583fb624a0f8c3601146e063c5a25 diff --git a/Bots/JavaGod.class.php b/Bots/JavaGod.class.php index e41ef02..364abf5 100644 --- a/Bots/JavaGod.class.php +++ b/Bots/JavaGod.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * - * * + * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/JavaGod.class.php * * simple Java debugger... @@ -26,7 +26,7 @@ class {$_NAME} extends Bot { private $uplink; private $bot, $execcache = array(); - + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!$old) { @@ -40,16 +40,16 @@ class {$_NAME} extends Bot { if(is_a($this->bot, "P10_User")) { $this->uplink->join($this->bot, "#java", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE)); $this->uplink->join($this->bot, "#dev", P10_Channel::USERPRIV_VOICE); - $this->uplink->join($this->bot, "#CoderCom", P10_Channel::USERPRIV_VOICE); + $this->uplink->join($this->bot, "#CoderCom", P10_Channel::USERPRIV_VOICE); } } else { $this->bot = $old; } - + ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); } - + public function unload($rehash = false) { foreach($this->execcache as $id => $entry) { fclose($entry['pipes'][1]); @@ -63,17 +63,17 @@ class {$_NAME} extends Bot { $this->uplink->delUser($this->bot, "Bye."); } } - + public function loop() { foreach($this->execcache as $id => $entry) { if(!$this->checkstate($entry)) { - unlink("tmp/Debug_".$entry['id'].".java"); - unlink("tmp/Debug_".$entry['id'].".class"); + unlink("tmp/Debug_".$entry['id'].".java"); + unlink("tmp/Debug_".$entry['id'].".class"); unset($this->execcache[$id]); } } } - + function recive_privmsg($user, $channel, $message) { $opOnJavaChannel = false; $JavaChannel = P10_Channel::getChannelByName("#Java"); @@ -91,51 +91,51 @@ class {$_NAME} extends Bot { } $entry=array(); $entry['channel'] = $channel; - $entry['id'] = rand(1, 999999); - if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { - $pasteid = explode("/", $exp[1]); - $pasteid = $pasteid[count($pasteid)-1]; - $javacontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); - if(preg_match("#Unknown Paste ID!#i", $javacontent)) { - $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); - return; - } - $javacode = "import java.*; + $entry['id'] = rand(1, 999999); + if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { + $pasteid = explode("/", $exp[1]); + $pasteid = $pasteid[count($pasteid)-1]; + $javacontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); + if(preg_match("#Unknown Paste ID!#i", $javacontent)) { + $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); + return; + } + $javacode = "import java.*; @SuppressWarnings(\"unused\") public class Debug_".$entry['id']." { ".$javacontent." } "; - } else { - $javacode = "import java.*; + } else { + $javacode = "import java.*; @SuppressWarnings(\"unused\") public class Debug_".$entry['id']." { ".$exp[1]." } "; - }; - $fp = fopen("tmp/Debug_".$entry['id'].".java", "w"); - fwrite($fp, $javacode); - fclose($fp); - $err = shell_exec("javac tmp/Debug_".$entry['id'].".java 2>&1"); - if($err) { - $err=str_replace("\r","",$err); - $lines=explode("\n",$err); - $i=0; - foreach($lines as $line) { - if($line == "") continue; - $i++; - if($i>100) { - $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); - break; - } - $this->uplink->privmsg($this->bot, $entry['channel'], $line); - } - } - if(!file_exists("tmp/Debug_".$entry['id'].".class")) { - unlink("tmp/Debug_".$entry['id'].".java"); - break; - } + }; + $fp = fopen("tmp/Debug_".$entry['id'].".java", "w"); + fwrite($fp, $javacode); + fclose($fp); + $err = shell_exec("javac tmp/Debug_".$entry['id'].".java 2>&1"); + if($err) { + $err=str_replace("\r","",$err); + $lines=explode("\n",$err); + $i=0; + foreach($lines as $line) { + if($line == "") continue; + $i++; + if($i>100) { + $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); + break; + } + $this->uplink->privmsg($this->bot, $entry['channel'], $line); + } + } + if(!file_exists("tmp/Debug_".$entry['id'].".class")) { + unlink("tmp/Debug_".$entry['id'].".java"); + break; + } $descriptor = array(0 => array("pipe", "r"),1 => array("pipe", "w"),2 => array("pipe", "w")); $entry['proc'] = proc_open('java -classpath tmp Debug_'.$entry['id'], $descriptor, $entry['pipes']); if(!is_resource($entry['proc'])) { @@ -148,13 +148,13 @@ class {$_NAME} extends Bot { break; } } - + function recive_quit($user, $reason) { if($user === $this->bot) { $this->load($this->uplink); } } - + function checkstate($entry) { $data = proc_get_status($entry['proc']); if(!$data['running']) { @@ -171,11 +171,11 @@ class {$_NAME} extends Bot { $lines=explode("\n",$out); $i=0; foreach($lines as $line) { - if($line == "") continue; + if($line == "") continue; $i++; if($i>1000) { $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->bot, $entry['channel'], $line); } @@ -185,11 +185,11 @@ class {$_NAME} extends Bot { $lines=explode("\n",$eout); $i=0; foreach($lines as $line) { - if($line == "") continue; + if($line == "") continue; $i++; - if($i>1000) { + if($i>1000) { $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->bot, $entry['channel'], "4".$line.""); } @@ -212,13 +212,13 @@ class {$_NAME} extends Bot { } else { proc_terminate($entry['proc']); $entry['term']=true; - $this->uplink->privmsg($this->bot, $entry['channel'], "Java timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); + $this->uplink->privmsg($this->bot, $entry['channel'], "Java timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); return true; } } } } - + } ?> \ No newline at end of file