Thread: Looping Issue

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    29

    Looping Issue

    I am currenty writing an irc bot. In accordance with the rfc there are a number of strings I have to send once I connnect to be authenticated. Mainly:
    Code:
    NICK mynicklewl2323
    PONG randomnums2323
    USER mynicklewl2323 blah blah :blah
    There are more but you get the point. Anyway as of now I have been storing them all in a structure and manually send()'ing them. Which is tedious and ugly.

    I need a way to put them in a loop and have them send and frankly I'm at a loss right now.
    -Thanks in advance

  2. #2
    Cached User mako's Avatar
    Join Date
    Dec 2005
    Location
    Germany.Stuttgart
    Posts
    69
    first off, does IRC script support the c programming language?

    Which ort are you trying to send the strings to?

    What do you know about the default send routine?.,,

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    29
    Not irc script. I make a socket connection, tcp, to the irc server and follow rfc guidlines. You can actually use netcat as an irc client if you understand the protocol.
    Anyway, for those who actually understand my question I'm simply wondering if there is a better way then a multidimensional array.

  4. #4
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Well, as you're aware the strings do of course have parameters (the user's nick, username, real name, and the value of the PING reply string, and the password, et cetera), so having a list calls might be appropriate, since it's only on startup. I'd guess you're doing something like:
    Code:
    sendf(sock, "PASS %s\n", server->pass);
    sendf(sock, "NICK %s\n", user->nick);
    sendf(sock, "USER %s 1 1 :%s\n", user->username, user->ircname);
    /* wait for/read in PING request */
    sendf(sock, "PONG %s", ping_reply);
    If so, I can't see the harm in that.

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    29
    Thanks for your reply. Yes, that's what I'm doing. Just wondered if it was the most elegant solution. As for the PONG reply I'm using a function that calls strtok() and strcat().

  6. #6
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Since it's only a relatively small set of specific commands, I'm not sure how you might make it more elegant. You could of course compress the pass/nick/user output into a single string (one that has several linefeeds), but that doesn't buy that much.

    As for strtok/strcat, I'd consider something alone the lines of sscanf or strcspn to grab the data you need. Upto you. At least make sure you have some mechanism of making sure that your target buffer (with strcat) can fit the result (strncat, or checking first with strlen). This should be the case any time you are parsing input from the server, of course. You cannot trust the server to keep to RFC line limits, you cannot trust the server at all
    Last edited by cwr; 01-24-2006 at 02:38 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'For loop' looping one too many times.
    By thealmightyone in forum C Programming
    Replies: 7
    Last Post: 02-20-2009, 06:46 AM
  2. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  3. type safe issue
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2008, 09:32 PM
  4. Looping questions
    By Peyote in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2003, 11:01 PM
  5. my first issue of GDM
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-12-2002, 04:02 PM