Results 1 to 9 of 9

Thread: hmm, trying irc bot with SCAR now, connection problems lol

  1. #1
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default hmm, trying irc bot with SCAR now, connection problems lol

    so far, i have this scrip:

    SCAR Code:
    program New;

    const
      nick = '';
      realname = '';
      port = 0;
      server = '';
      timeout = 0;
      Chan = '';
     
    procedure A_Debug(msg: string);
    begin
      writeln(msg);
      alert(msg);
      status(msg);
      terminatescript;
    end;
     
    var c, p: integer; s, a: string;
    begin
      cleardebug;
      p:= port;
      repeat
        c:= OpenConnection(server, p, timeout);
        if c = 0 then inc(p);
      until (port = 7000) or (c <> 0);
      if port = 7000 then a_debug('connection problems');
      writeln('Connection Open');
      writeln(' ');
      writeln('Server: ' + server);
      writeln('Port: ' + inttostr(port));
      writeln('Connection: ' + inttostr(c));
      writeln(' ');
      if not SendConnectionData(c, 'NICK '+ nick + '\r\n') then
        A_Debug('Nick messed up');
      writeln('Nick Set:' + nick);
      if not SendConnectionData(c, 'USER ' + nick + ' * * :' + realname) then
        A_Debug('User messed up');
      writeln('User Set: ' + realname);
      if not SendConnectionData(c, 'JOIN ' + Chan) then
        A_Debug('Joining messed up');
      writeln('Joined Channel: ' + chan);
      writeln(' ');
      wait(1000);
      repeat
        wait(10);
        if not IsConnectionOpen(c) then A_Debug('Connection Closed');
        ReadConnectionData(c, s);
        if a <> s then
        begin
          writeln(s);
          status(s);
        end;
        a:= s;
      until isfkeydown(12) and isfkeydown(11);
    end.

    and the problem is, the connection isnt really working well, or it pings out really fast. in the debug box, it always returns:

    SCAR Code:
    :RuneHQ.mi.us.SwiftIRC.net NOTICE AUTH :*** No ident response; username prefixed with ~

    ERROR :Closing Link: [(my ip address)] (Ping timeout)


    Connection Closed
    Successfully executed

    and i dont know what or how to fix it =\
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  2. #2
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I don't know exactly what's wrong with it, but if you want to wait a while, I can post up a working IRC Bot, so that you can look at it.

    ~Sandstorm

  3. #3
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You can try to learn from this IRC bot I made:
    scar Code:
    program IRCBot;

    Type
      BufferedReader = Record
      Buffer : String;
      Pos, Len: Integer;
      UseSocket: Boolean;
    End;

    Var
      Line, nicke, host, command, channel, args : String;
      Sock_Fd : Integer;
      Reader : BufferedReader;
     
    Const
      IRCNickname = 'SCARBot';
      BotChans = '#cazax';
     

    Procedure DBug(S : String; T : Integer);
    Begin
      Case T Of
        1: Writeln('- ' + S);
        2: Writeln('=> ' + S);
        3: Writeln('<= ' + S);
      End;
    End;

    Procedure SendData(Buf : String);
    Begin
      DBug(Buf, 2);
      SendConnectionData(Sock_Fd, Buf + #10 + #13);
    end;

    Procedure FillReaderBuffer(Var Reader : BufferedReader);
    Var
      Buf : String;
    Begin
      Try
        ReadConnectionData(Sock_Fd, Buf);
         Reader.Pos := 1;
         Reader.Len:= Length(Buf);
         Reader.Buffer:= Buf;
      Except End;
    End;

    function Connect : Integer;
    begin
      Result := OpenConnection('irc.rizon.net', 6667, 15000);
      if(Result < 0)then
      begin
        DBug('Error connecting', 1);
        Exit;
      end;
      ClearReport;
      SendData('USER ' + IRCNickname + ' 8 * :' + IRCNickname);
      SendData('NICK ' + IRCNickname);
      SendData('MODE ' + IRCNickname + ' +i');
      SendData('MODE ' + IRCNickname + ' +E');
      SendData('MODE ' + IRCNickname + ' +C');
      SendData('MODE ' + IRCNickname + ' +I');
      SendData('MODE ' + IRCNickname + ' +Q');
      SendData('JOIN ' + botchans);
    end;

    function ReadNextSegment(var reader: BufferedReader; c1, c2: char): string;
    var
      f: Integer;
    begin
      repeat
      for f := reader.pos to reader.len do
        if (reader.buffer[f] = c1) or (reader.buffer[f] = c2) then
        begin
          Result:= Copy(reader.buffer, reader.pos, f - reader.pos);
          reader.pos:= f + 1;
          Exit;
        end;
      if (reader.usesocket) then
        FillReaderBuffer(reader)
      else
        Break;
      until(False);
      Result:= #0;
    end;

    function ReadNextLine(var reader: BufferedReader): string;
    var
      line: string;
      c: char;
    begin
      try
        line:= ReadNextSegment(reader, #10, #13);
        c := reader.buffer[reader.pos];
      except
        exit;
      end;
      if (c = #13) or (c = #10) then
        reader.pos := reader.pos + 1;
      Result := line;
    end;

    Procedure IRCWake;
    {Var
      S : String;}

    Begin
      SetTimeout(25, 'IRCWake');
      Line := ReadNextLine(Reader);
      DBug(Line, 3);
      If Pos(':', Line) > 0 Then
      {Begin
       writeln('wohoo');
        }
    If Pos('PRIVMSG', Line) > 0 Then{
          Exit;
         If Pos('Cazax', Line) > 0 Then}

          SendData('PRIVMSG #cazax :hi');
      //end;
    End;

    begin
      DBug('IRCBot is starting...', 1);
      Sock_fd := Connect;
      if(Sock_fd < 0)then
      begin
        DBug('Failed to connect', 1);
        Exit;
      end;
      Reader.UseSocket := True;
      FillReaderBuffer(reader);
      IRCWake;
      While True Do
        Wait(10);
    end.
    It's based on Harry's IRC thingy.


  4. #4
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    you need to send Chr(13) followed by Chr(10) at the end of your lines, not '\r\n'

    btw I wrote the line parsing stuff, Harry took from me and now you're taking from Harry.
    quite cool its lasted this long.
    Join the Official SRL IRC channel. Learn how to Here.

  5. #5
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    lol, i'll look at this later, and be sure to credit both of you (and toot)

    right now, i need to get the parsing right, so i can send the "pongs"
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  6. #6
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Lol, Cazax posted a modified version of what I was going to post :P.

    ~Sandstorm

  7. #7
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    hmm, i got a more stable version i guess, do you mind if i use some procedures cazax? i'll be sure to credit
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  8. #8
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    hmm, i got a more stable version i guess, do you mind if i use some procedures cazax? i'll be sure to credit
    Yeah sure, most of theme weren't made by me I just modified some.


  9. #9
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by Cazax View Post
    Yeah sure, most of theme weren't made by me I just modified some.
    mkay probobly just the make, and DBug, but thats because im to lazy to make my own
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •