Para el foro de Indetectables
-------------------------------------------------------------------------------------------------program Demo;
{*/
**/ Name: DemoIrcBot
**/ Ver: 1.0
**/ Created By: Psymera
**/ Date: Jul 2007
**/ Created For: Indetectables.net
/*}
{$DEFINE DEBUG}
{$IFDEF DEBUG}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
Windows,
Winsock,
StrUtils,
SysUtils;
var
Wsa: WSADATA;
RHost: sockaddr_in;
Sock: TSocket;
Status: Integer;
Hostent: PHostent;
Ip: ^integer;
Buff: Array[0..1024] of Char;
Buff2: String;
Const
Adm: String= 'Psymera';
Room: String= '#indetectables';
Serv: String= 'irc.zirc.org';
BNick: String= 'IRCBotDemo';
CCMDS: String= '#';
Procedure SockSend(Msg: PChar);
Begin
{$IFDEF DEBUG}
WriteLn(Msg);
{$ENDIF}
Send(Sock, Addr(Msg[0])^, Length(Msg), 0);
end;
//-----------------Comandos-----------------//
Procedure MsgPub(Msg: String);
Var
MTmp: String;
Begin
MTmp:= RightStr(Msg, Integer(StrLen(PChar(Msg))-5));
MTmp:= Trim(MTmp);
SockSend(PChar('PRIVMSG '+ Room+ ' '+ MTmp+ #13#10));
end;
Procedure MsgPriv(Msg: String);
Var
MsTmp, NTmp, MTmp: String;
Begin
MsTmp:= RightStr(Msg, Integer(StrLen(PChar(Msg))-8));
NTmp:= LeftStr(MsTmp, Pos(' ', MsTmp));
MTmp:= RightStr(MsTmp, Integer(StrLen(PChar(MsTmp))-StrLen(Pchar(NTmp))));
NTmp:= Trim(NTmp);
MTmp:= Trim(MTmp);
SockSend(PChar('PRIVMSG '+ NTmp+ ' '+ MTmp+ #13#10));
end;
//----------------/Comandos-----------------//
//----------------Control De Comandos-------//
Procedure ParseCmd(CMD: String);
Begin
if Pos('msg ', CMD) = 2 then
MsgPub(CMD);
if Pos('msgpri ', CMD) = 2 then
MsgPriv(CMD);
if Pos('quit', CMD) = 2 then
CloseSocket(Sock);
end;
//---------------/Control De Comandos-------//
Procedure Parse();
Var
Nick, Msg, CMD: String;
PvP: Integer;
PuP: Integer;
Begin
Buff2:= Buff;
if Pos('PING', Buff2)=1 then
Begin
Msg:= 'PONG ';
Msg:= Msg+ RightStr(Buff2, (Integer(StrLen(PChar(Buff2)))-7));
Msg:= Msg+ #13#10;
SockSend(PChar(Msg));
end;
Nick:= MidStr(Buff2, 2, (Pos('!',Buff2)-2));
PvP:= Pos('PRIVMSG '+ BNick+ ' :', Buff2);
PuP:= Pos('PRIVMSG '+ Room+ ' :', Buff2);
if Nick
Begin
PvP:= PvP+ 9+ Integer(StrLen(PChar(BNick)));
CMD:= RightStr(Buff2, Integer(StrLen(PChar(Buff2)))- PvP);
CMD:= Trim(Cmd);
if Pos(CCMDS, CMD) = 1 then
Begin
{$IFDEF DEBUG}
WriteLn('Privado: '+ Nick+ ':'+ CMD);
{$ENDIF}
ParseCmd(CMD);
end;
end;
if PuP>0 then
Begin
PuP:= PuP+ 9+ Integer(StrLen(PChar(Room)));
CMD:= RightStr(Buff2, Integer(StrLen(PChar(Buff2)))- PuP);
CMD:= Trim(Cmd);
if Pos(CCMDS, CMD) = 1 then
Begin
{$IFDEF DEBUG}
WriteLn('Publico: '+ Nick+ ':'+ CMD);
{$ENDIF}
ParseCmd(CMD);
end;
end;
Buff:= '';
end;
begin
{$IFDEF DEBUG}
WriteLn('IrcBot Demo By Psymera');
{$ENDIF}
WSAStartup(MakeWord(2,2), wsa);
Sock:= SOCKET(AF_INET, SOCK_STREAM, 0);
Hostent:= getHostByName(PChar(Serv));
Ip:= @Hostent.h_addr_list^[0];
RHost.sin_family:= AF_INET;
RHost.sin_port:= htons(6667);
RHost.sin_addr.S_addr:= ip^;
Status:= Connect(Sock, RHost, Sizeof(RHost));
if (Status <> 0) then
Begin
{$IFDEF DEBUG}
WriteLn('Error al Conectar');
ReadLn;
{$ENDIF}
Exit;
end;
{$IFDEF DEBUG}
WriteLn('Conectado');
{$ENDIF}
SockSend(PChar('NICK '+ BNick+ #13#10));
SockSend('USER IrcBotDemo IrcBotDemo IrcBotDemo IrcBotDemo'#13#10);
SockSend('JOIN #indetectables'#13#10);
while True do
Begin
Status:= recv(Sock, Buff, sizeof(Buff), 0);
Parse;
if (Status = -1) then
Break;
end;
{$IFDEF DEBUG}
WriteLn('Desconectado');
ReadLn;
{$ENDIF}
end.
-------------------------------------------------------------------------------------------------
No hay comentarios:
Publicar un comentario