PHP gevorderde |
|
Als ik men php bestand run krijg ik niets te zien ook zie ik op irc channel zelf geen bot connecten van mij waar ligt de fout?
<?php
set_time_limit (0); // time limit goed zetten zodat ie geen timouts krigjt
ini_set ('error_reporting', E_ALL); // error reporitng op het hoogste zetten
class IRC_Bot
{
// default settings
var $bot = array ("host" => "irc.quakenet.org", "port" => "6669", "owner" => "Zwobbel", "nick" => "TMF-bot", "user" => "thephpbot", "name" => "PHPBOT by zwobbel", "short"=> "phpb", "errn" => "", "errs" => "");
var $chan = array ('#mgevent');
// laat botje connecten met server
function conn ()
{
$sock = @fsockopen ($this->bot['host'], $this->bot['port'], $this->bot['errn'], $this->bot['errs']);
if ($sock)
{
return $sock; // everything went oke return the socket
}
else
{
return $this->errn . ': ' . $this->errs; // something went wrong, return error number and string
}
}
function put ($msg)
{
return fputs ($this->conn (), $msg . "");
}
// username en zo setten
function settings ()
{
$this->put ('NICK ' . $this->$bot['nick'] . '');
$this->put ('USER ' . $this->$bot['user'] . ' : ' . $bot['name'] . '');
}
// een bericht sturen
// Type = PRIV -> Prive bericht naar een gebruiker
// Type = NOTICE -> Zo'n channel notice..
function message ($type, $destination, $message)
{
if ($type == 'PRIVMSG')
{
$this->put ('PRIVMSG ' . $destination . ' :' . $message . '');
}
else if ($type == 'NOTICE')
{
$this->put ('NOTICE '.$destination.' :'.$message . '');
}
}
// kanaal joinen.. spreekt voor zich
function join ($chan, $key = NULL)
{
if ($key == NULL)
{
$this->put ('JOIN ' . $chan . '');
}
else
{
$this->put ('JOIN ' . $chan . ' '. $key . '');
}
}
// kanaal verlaten
function part ($chan, $reason = NULL)
{
if ($reason == NULL)
{
$this->put ('PART '. $chan . '');
}
else
{
$this->message ('PRIV', $chan, $reason);
$this->put ('PART '. $chan . '');
}
}
// iemand anders het kanaal laten verlaten :p
function kick ($chan, $nick)
{
$this->put ('KICK ' . $chan . ' ' . $nick . '');
}
// topic laten zetten
function setTopic($chan, $newtopic = NULL)
{
if ($newtopic == NULL)
{
$this->message ('NOTICE' . $chan . ' :No topic to set');
}
else
{
$this->put ('TOPIC ' . $chan . ' :' . $newtopic . '');
}
}
function cmode ($target, $newmode = NULL)
{
if ($newmode == NULL)
{
continue;
}
else
{
$this->put ('MODE ' . $target . ' ' . $newmode . '');
}
}
function umode ($chan, $nick, $mode = NULL)
{
if ($mode == NULL)
{
continue;
}
else
{
$this->put ('MODE ' . $chan . ' ' . $mode . ' ' . $nick . '');
}
}
function startbot ()
{
while (TRUE)
{
$text = fgets ($sock, 100);
if (substr ($text, 0, 4) == 'PING')
{
$this->substr ($text, 4, 10);
}
$mesg = explode (':', $text);
$nick = explode ('!', $mesg[1]);
$nick = $nick[0];
$extr = explode (' ', $mesg[1]);
$chan = $extr[2] ;
$msg = strtolower ($mesg[2]);
$arg = explode (' ', $msg);
if ($nick == $this->bot['owner'])
{
if (preg_match ('#' . $this->bot['short'] . ' op (.*)', $msg, $arg))
{
$this->umode ($chan, $arg, '+o');
}
else if (preg_match ('#' . $this->bot['short'] . ' deop (.*)', $msg, $arg))
{
$this->umode ($chan, $arg, '-o');
}
else if (preg_match ('#' . $this->bot['short'] . ' voice (.*)', $msg, $arg))
{
$this->umode ($chan, $arg, '+v');
}
else if (preg_match ('#' . $this->bot['short'] . ' devoice (.*)', $msg, $arg))
{
$this->umode ($chan, $arg, '-v');
}
else if (preg_match ('#' . $this->bot['short'] . ' kick (.*)', $msg, $arg))
{
$this->kick ($chan, $arg);
}
else if (preg_match ('#' . $this->bot['short'] . ' ban (.*)', $msg, $arg))
{
$this->umode ($chan, $arg, '+b');
}
else if (preg_match ('#' . $this->bot['short'] . ' unban (.*)', $msg, $arg))
{
$this->umode ($chan, $arg, '-b');
}
else if (preg_match ('#' . $this->bot['short'] . ' settopic (.*)', $msg, $arg))
{
$this->setTopic ($chan, $newtopic);
}
else if (preg_match ('#' . $this->bot['short'] . ' join (.*)', $msg, $arg))
{
if (isset ($arg[1]))
{
$this->join ($arg[0], $arg[1]);
}
else
{
$this->join ($arg[0]);
}
}
else if (preg_match ('#' . $this->bot['short'] . ' part (.*)', $msg, $arg))
{
if (isset ($arg[1]))
{
$this->part ($arg[0], $arg[1]);
}
else
{
$this->part ($arg[0]);
}
}
}
else
{
$this->message ('NOTICE', $nick, 'You are not allowed to use this command.');
}
}
}
}
?>
<?php set_time_limit (0); // time limit goed zetten zodat ie geen timouts krigjt ini_set ('error_reporting', E_ALL); // error reporitng op het hoogste zetten class IRC_Bot { // default settings var $bot = array ("host" => "irc.quakenet.org", "port" => "6669", "owner" => "Zwobbel", "nick" => "TMF-bot", "user" => "thephpbot", "name" => "PHPBOT by zwobbel", "short"=> "phpb", "errn" => "", "errs" => ""); var $chan = array ('#mgevent'); // laat botje connecten met server function conn () { $sock = @fsockopen ($this->bot['host'], $this->bot['port'], $this->bot['errn'], $this->bot['errs']); if ($sock) { return $sock; // everything went oke return the socket } else { return $this->errn . ': ' . $this->errs; // something went wrong, return error number and string } } function put ($msg) { return fputs ($this->conn (), $msg . ""); } // username en zo setten function settings () { $this->put ('NICK ' . $this->$bot['nick'] . ''); $this->put ('USER ' . $this->$bot['user'] . ' : ' . $bot['name'] . ''); } // een bericht sturen // Type = PRIV -> Prive bericht naar een gebruiker // Type = NOTICE -> Zo'n channel notice.. function message ($type, $destination, $message) { if ($type == 'PRIVMSG') { $this->put ('PRIVMSG ' . $destination . ' :' . $message . ''); } else if ($type == 'NOTICE') { $this->put ('NOTICE '.$destination.' :'.$message . ''); } } // kanaal joinen.. spreekt voor zich function join ($chan, $key = NULL) { if ($key == NULL) { $this->put ('JOIN ' . $chan . ''); } else { $this->put ('JOIN ' . $chan . ' '. $key . ''); } } // kanaal verlaten function part ($chan, $reason = NULL) { if ($reason == NULL) { $this->put ('PART '. $chan . ''); } else { $this->message ('PRIV', $chan, $reason); $this->put ('PART '. $chan . ''); } } // iemand anders het kanaal laten verlaten :p function kick ($chan, $nick) { $this->put ('KICK ' . $chan . ' ' . $nick . ''); } // topic laten zetten function setTopic($chan, $newtopic = NULL) { if ($newtopic == NULL) { $this->message ('NOTICE' . $chan . ' :No topic to set'); } else { $this->put ('TOPIC ' . $chan . ' :' . $newtopic . ''); } } function cmode ($target, $newmode = NULL) { if ($newmode == NULL) { continue; } else { $this->put ('MODE ' . $target . ' ' . $newmode . ''); } } function umode ($chan, $nick, $mode = NULL) { if ($mode == NULL) { continue; } else { $this->put ('MODE ' . $chan . ' ' . $mode . ' ' . $nick . ''); } } function startbot () { while (TRUE) { $text = fgets ($sock, 100); if (substr ($text, 0, 4) == 'PING') { $this->substr ($text, 4, 10); } $nick = $nick[0]; $chan = $extr[2] ; if ($nick == $this->bot['owner']) { if (preg_match ('#' . $this->bot['short'] . ' op (.*)', $msg, $arg)) { $this->umode ($chan, $arg, '+o'); } else if (preg_match ('#' . $this->bot['short'] . ' deop (.*)', $msg, $arg)) { $this->umode ($chan, $arg, '-o'); } else if (preg_match ('#' . $this->bot['short'] . ' voice (.*)', $msg, $arg)) { $this->umode ($chan, $arg, '+v'); } else if (preg_match ('#' . $this->bot['short'] . ' devoice (.*)', $msg, $arg)) { $this->umode ($chan, $arg, '-v'); } else if (preg_match ('#' . $this->bot['short'] . ' kick (.*)', $msg, $arg)) { $this->kick ($chan, $arg); } else if (preg_match ('#' . $this->bot['short'] . ' ban (.*)', $msg, $arg)) { $this->umode ($chan, $arg, '+b'); } else if (preg_match ('#' . $this->bot['short'] . ' unban (.*)', $msg, $arg)) { $this->umode ($chan, $arg, '-b'); } else if (preg_match ('#' . $this->bot['short'] . ' settopic (.*)', $msg, $arg)) { $this->setTopic ($chan, $newtopic); } else if (preg_match ('#' . $this->bot['short'] . ' join (.*)', $msg, $arg)) { { $this->join ($arg[0], $arg[1]); } else { $this->join ($arg[0]); } } else if (preg_match ('#' . $this->bot['short'] . ' part (.*)', $msg, $arg)) { { $this->part ($arg[0], $arg[1]); } else { $this->part ($arg[0]); } } } else { $this->message ('NOTICE', $nick, 'You are not allowed to use this command.'); } } } } ?>
|