14/06/2004, 14:35
|
| | | Fecha de Ingreso: mayo-2004 Ubicación: Valencia
Mensajes: 358
Antigüedad: 20 años, 6 meses Puntos: 2 | |
Muy bien, pues aquí lo teneis: Código PHP: <?
// Datos del Bot
$nickname = "KesBot";
$powered = "Kesthers";
$nombre = "KesBot";
$version = "v1.0";
$ircserver[address] = "irc.quakenet.org";
$ircserver[port] = "6667";
$red = "quakenet";
$directorio[stats] = "/var/log/kesbot/quakenet/";
// Conexion a Base de Datos
mysql_connect("localhost", "xxxxx", "xxxxx"); mysql_select_db("xxxxx");
## Funciones de Logs & Stats ##
function WriteLogs($canal, $mensaje) {
global $directorio;
$fp = @fopen($directorio[stats].str_replace("#", "", str_replace(":", "", $canal)).".log", "a");
fputs($fp, $mensaje."\r\n");
fclose($fp);
}
// Conectamos
set_time_limit(0);
for($conn=0; 1<=2; $conn++) {
echo"Conectando...\n";
$conexion = fsockopen($ircserver[address], $ircserver[port]);
socket_set_timeout($conexion, 31536000);
if($conexion) {
echo"Esperando respuesta...\n";
$bucle=0; $conectado=0; $limit=0;
set_time_limit(0);
while ($read = fgets($conexion,512)) {
set_time_limit(0);
$read = str_replace("\n","",$read);
$read = str_replace("\r","",$read);
$array = explode(" ",$read);
$address = explode("!",$array[0]);
$nick = str_replace(":","",$address[0]);
$quit = substr($read, strlen($array[0])+strlen($array[1])+3, 512);
$modo = substr($read, strlen($array[0])+strlen($array[1])+strlen($array[2])+3, 512);
$mensaje = substr($read, strlen($array[0])+strlen($array[1])+strlen($array[2])+4, 512);
$kick = substr($read, strlen($array[0])+strlen($array[1])+strlen($array[2])+strlen($array[3])+5, 512);
if ($conectado!==0) {
switch ($array[1]) {
case PRIVMSG:
if($array[2]!==$nickname) {
if(substr($mensaje, 0, 7)=="ACTION") {
$count = strlen($mensaje)-9;
WriteLogs($array[2], "[".date("H:i")."] * ".$nick." ".substr($mensaje, 8, $count));
} else {
WriteLogs($array[2], "[".date("H:i")."] <".$nick."> ".$mensaje);
}
} else {
$orden = explode(" ", strtolower($mensaje));
switch ($orden[0]) {
case "ping":
fputs($conexion, "NOTICE ".$nick." :PING ".$orden[1]."\n");
break;
case "version":
fputs($conexion, "NOTICE ".$nick." :VERSION ".$version."\n");
break;
case "time":
fputs($conexion, "NOTICE ".$nick." :TIME ".date("D M d H:i:s Y")."\n");
break;
case "finger":
fputs($conexion, "NOTICE ".$nick." :FINGER ".$nombre."\n");
break;
case admin:
if(mysql_num_rows(mysql_query("SELECT * FROM admins WHERE nick='".strtolower($nick)."'"))==1) {
$accion = substr($mensaje, 6, 512);
fputs($conexion, $accion."\n");
if($orden[1]=="nick") {
$nuevo = explode(":", $orden[2]);
$nickname = $nuevo[0];
}
} else {
fputs($conexion, "PRIVMSG ".$nick." :\002\0032No estas autorizado/da a usar este comando.\n");
}
break;
case info:
fputs($conexion, "PRIVMSG ".$nick." :\002\0032Bot de Logs & Stats [Creado por: ".$powered."]\n");
fputs($conexion, "PRIVMSG ".$nick." :\002\0032Website: http://www.kesthers.com\n");
fputs($conexion, "PRIVMSG ".$nick." :\002\0032E-Mail: [email][email protected][/email]\n");
break;
case op:
if(mysql_num_rows(mysql_query("SELECT * FROM opers WHERE nick='".$orden[1]."' AND password='".$orden[2]."' AND red='".$red."' AND canal='".$orden[3]."'"))=="1") {
fputs($conexion, "MODE ".$orden[3]." +o ".$nick."\n");
} else {
fputs($conexion, "PRIVMSG ".$nick." :\002\0032No te puedo dar op porque los datos no son correctos\n");
}
break;
}
}
break;
case NOTICE:
if($array[2]!==$nickname) {
WriteLogs($array[2], "[".date("H:i")."] *** ".$mensaje." (".$nick.")");
}
break;
case NICK:
$query = mysql_query("SELECT * FROM online WHERE nick='".$nick."' AND red='".$red."'");
while($sql = mysql_fetch_array($query)) {
WriteLogs($sql[canal], "[".date("H:i")."] *** ".$nick." is now known as ".str_replace(":", "", $array[2]));
}
mysql_query("UPDATE online SET nick='".str_replace(":", "", $array[2])."' WHERE nick='".$nick."' AND red='".$red."'");
break;
case MODE:
if($array[2]!==$nickname) {
WriteLogs($array[2], "[".date("H:i")."] *** ".$nick." sets mode: ".$modo);
}
break;
case JOIN:
WriteLogs($array[2], "[".date("H:i")."] *** ".$nick." (".$address[1].") has joined ".str_replace(":", "", $array[2]));
mysql_query("INSERT INTO online (time, nick, canal, red) VALUES ('".time()."', '".$nick."', '".str_replace(":", "", $array[2])."', '".$red."');");
break;
case PART:
WriteLogs($array[2], "[".date("H:i")."] *** ".$nick." (".$address[1].") has left ".$array[2]);
mysql_query("DELETE FROM online WHERE nick='".$nick."' AND canal='".$array[2]."' AND red='".$red."'");
break;
case KICK:
if($array[3]==$nickname) {
fputs($conexion, "JOIN ".$array[2]."\n");
}
WriteLogs($array[2], "[".date("H:i")."] *** ".$array[3]." was kicked by ".$nick." (".$kick.")");
mysql_query("DELETE FROM online WHERE nick='".$array[3]."' AND canal='".$array[2]."' AND red='".$red."'");
break;
case QUIT:
$query = mysql_query("SELECT * FROM online WHERE nick='".$nick."' AND red='".$red."'");
while($sql = mysql_fetch_array($query)) {
WriteLogs($sql[canal], "[".date("H:i")."] *** ".$nick." (".$address[1].") Quit (".$quit.")");
}
mysql_query("DELETE FROM online WHERE nick='".$nick."' AND red='".$red."'");
break;
case TOPIC:
WriteLogs($array[2], "[".date("H:i")."] *** ".$nick." changes topic to '".$mensaje."'");
mysql_query("UPDATE canales SET topic='".$mensaje."' WHERE canal='".$array[2]."' AND red='".$red."'");
break;
}
}
if ($bucle==0) {
fputs($conexion, "NICK $nickname\n\n");
fputs($conexion, "USER $nickname $powered $powered :$nombre $version\n\n");
echo"Identificado.\n";
}
if ($array[0]=="PING") {
fputs($conexion, "PONG ".str_replace(":","",$array[1])."\n");
}
if ($array[1]==251) {
$query = mysql_query("SELECT * FROM canales WHERE red='".$red."'");
while($sql = mysql_fetch_array($query)) {
$canales .= $sql[canal].",";
}
fputs($conexion, "JOIN ".$canales."\n\n");
echo"Entrada en canales. ($canales)\n";
$conectado++;
}
$bucle++;
}
} else {
echo"Error al Conectar.\n";
}
echo"Desconectado.\n";
}
?> |