* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/JavaGod.class.php
*
* simple Java debugger...
class {$_NAME} extends Bot {
private $uplink;
private $bot, $execcache = array();
-
+
public function load($uplink, $old = false) {
$this->uplink = $uplink;
if(!$old) {
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]);
$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");
}
$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'])) {
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']) {
$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);
}
$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'], "\ 34".$line."\ 3");
}
} 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