![]() |
| | #1 |
| Registered User Join Date: Oct 2007
Posts: 9
| c irc bot 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;
}
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.. |
| niqo is offline | |
| | #2 |
| Registered User Join Date: Jan 2008
Posts: 281
| |
| arpsmack is offline | |
| | #3 |
| C++ Developer Join Date: Jun 2002 Location: UWaterloo
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 |
| XSquared is offline | |
| | #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? |
| niqo is offline | |
| | #5 |
| CSharpener Join Date: Oct 2006
Posts: 5,336
| if you check the return value of the recv and work according to it - you do not need the memset beforehead
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
| vart is offline | |
| | #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?? |
| manav is offline | |
| | #7 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,710
| Well you'll want to read this thoroughly. Useful Links And Good Books Edit: And moved, as noted by manav. |
| Salem is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Design guidelines advice - IRC Bot class | IceDane | C# Programming | 2 | 12-05-2008 01:21 AM |
| Need some help with making irc bot | kazz | C++ Programming | 6 | 11-23-2007 11:47 AM |
| IRC, reading the stream | Iyouboushi | C# Programming | 6 | 08-03-2006 05:34 PM |
| Cross-compilable IRC bot | radiohead | C Programming | 2 | 03-19-2006 09:27 PM |
| Whats wrong with my IRC Bot?? | peradox | Networking/Device Communication | 8 | 05-23-2005 05:16 PM |