c irc bot

This is a discussion on c irc bot within the Networking/Device Communication forums, part of the General Programming Boards category; Uhm, just wondering what's wrong with the code: Code: #include <stdio.h> #include <winsock.h> int main(int argc, char *argv[]) { WSADATA ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    9

    c irc bot

    Uhm, just wondering what's wrong with the code:
    Code:
    #include <stdio.h>
    #include <winsock.h>
    
    int main(int argc, char *argv[])
    {
        WSADATA wsaData;
        if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
            return 0;
    
        SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (hSocket == INVALID_SOCKET)
        {
            WSACleanup();
            return 0;
        }
        
        SOCKADDR_IN sockAddr;
        sockAddr.sin_port = htons(6667);
        sockAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
        sockAddr.sin_family = AF_INET;
        
        if (connect(hSocket, (SOCKADDR *)&sockAddr, sizeof(sockAddr)) != 0)
        {
            WSACleanup();
            return 0;
        }
        
        char buffer[260], temp[260];
        
        while (1)
        {
            int bytesRcv = recv(hSocket, buffer, sizeof(buffer), 0);
            
            if (bytesRcv != 0 || bytesRcv != SOCKET_ERROR)
            {
                printf("%s", buffer);
                
                if (strstr(buffer, "No ident response") != NULL)
                {
                    sprintf(temp, "USER something something something :something");
                    send(hSocket, temp, strlen(temp), 0);
    
                    sprintf(temp, "NICK something");
                    send(hSocket, temp, strlen(temp), 0);
                }
            } else break;
        }
        
        return 0;
    }
    Btw, I have my own ircd that I downloaded..
    After receiving the message "No ident response", it should send a "user" and "nick" message and then after that the server should send me back a "ping" message..
    Thanks in advance..

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    Quote Originally Posted by niqo View Post
    Uhm, just wondering what's wrong with the code:
    Isn't it your job to tell us what's wrong with the code, and our job to tell you how to fix it? I'm confused now.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    All IRC commands must be terminated with \r\n.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    Yupz. . Got it working a while ago.. I added the \r\n. Hehe Anyways, am I writing the code correctly? Cause I noticed in one source code that it did a memset before putting another value at my variable buffer or temp.. Do i need to add that?

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by niqo View Post
    Yupz. . Got it working a while ago.. I added the \r\n. Hehe Anyways, am I writing the code correctly? Cause I noticed in one source code that it did a memset before putting another value at my variable buffer or temp.. Do i need to add that?
    if you check the return value of the recv and work according to it - you do not need the memset beforehead
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Banned
    Join Date
    Nov 2007
    Posts
    678
    should not this be posted in network section?

    anyway. does anybody know why this happened:

    i found my ip by visiting a site (modem based 64kbps net)
    then wrote a simple server and asked my brother to connect to me using winxp telnet!
    but he could not connect! why??

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Well you'll want to read this thoroughly.
    Useful Links And Good Books

    Edit:
    And moved, as noted by manav.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design guidelines advice - IRC Bot class
    By IceDane in forum C# Programming
    Replies: 2
    Last Post: 12-05-2008, 12:21 AM
  2. Need some help with making irc bot
    By kazz in forum C++ Programming
    Replies: 6
    Last Post: 11-23-2007, 10:47 AM
  3. IRC, reading the stream
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 08-03-2006, 05:34 PM
  4. Whats wrong with my IRC Bot??
    By peradox in forum Networking/Device Communication
    Replies: 8
    Last Post: 05-23-2005, 05:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21