c irc bot [Archive] - C Board

PDA

View Full Version : c irc bot


niqo
03-23-2008, 05:41 PM
Uhm, just wondering what's wrong with the 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.. ;)

arpsmack
03-23-2008, 06:01 PM
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.

XSquared
03-23-2008, 06:38 PM
All IRC commands must be terminated with \r\n.

niqo
03-24-2008, 04:40 AM
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?:D

vart
03-24-2008, 05:14 AM
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?:D

if you check the return value of the recv and work according to it - you do not need the memset beforehead

manav
03-24-2008, 05:24 AM
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??

Salem
03-24-2008, 05:24 AM
Well you'll want to read this thoroughly.
http://cboard.cprogramming.com/showthread.php?t=41926

Edit:
And moved, as noted by manav.