Well, here is the source code for my bot, but it doesn't seem to work. I would appreciate it if you could point out any errors you see. Thank you.
BTW, I'm running Mac OS X 10.4.1. I get a bus error (which is about the same as a segmentation fault on the input, but I know for a fact that the rest is not working either. Thanks again. Also, source code for a simple bot (preferably something that just kinda hangs around on IRC) is greatly appreciated.Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <signal.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <dlfcn.h> #include <pthread.h> struct bot_t { int sock; FILE *toserver; FILE *fromserver; char server_name[256]; struct hostent *server; struct sockaddr_in addr_sevr; char channel[256]; char nick[256]; int port; char *host; char *domain; char *realname; int state; }; struct bot_t bot; int main(int argc, char **argv) { int z; char *input = NULL; char *pong; int length; puts("Enter the IRC server you want to connect to"); scanf("%s", bot.server_name); bot.server = gethostbyname(bot.server_name); if (bot.server == NULL) { puts("Could not resolve host: Did you mispell it?"); return 1; } puts("Enter the channel to join"); scanf("%s", bot.channel); if (bot.channel[0] != '#' && bot.channel[0] != '&') { puts("Please Enter a Valid Channel"); return 1; } puts("Enter a Nickname for Perabot"); scanf("%s", bot.nick); bot.port = 6667; bot.host = "RANDOMHOST"; bot.domain = "RANDOMDOMAIN"; bot.realname = "Perabot, by Peradox"; printf("Forming Socket...\t)"); bot.sock = socket(PF_INET, SOCK_STREAM, 0); if (bot.sock < 0) { puts("Couldn't create socket"); return 1; } bot.fromserver = fdopen(bot.sock, "r"); bot.toserver = fdopen(dup(bot.sock), "w"); memset(&(bot.addr_sevr), 0, sizeof(bot.addr_sevr)); bot.addr_sevr.sin_family = AF_INET; bot.addr_sevr.sin_port = htons(bot.port); bot.addr_sevr.sin_addr.s_addr = /*inet_addr(bot.server->h_addr_list[0]) */ inet_addr("195.197.175.21"); /* orwell.freenode.net */ length = sizeof(bot.addr_sevr); if(bot.addr_sevr.sin_addr.s_addr == INADDR_NONE) { puts("Bad Address"); return 1; } /* connect */ printf("Connecting..."); z = connect(bot.sock, (struct sockaddr *) &(bot.addr_sevr), length); if (z == -1) { puts("Could not connect to server"); return 1; } printf("\tRegistering..."); /* Register User */ fprintf(bot.toserver, "NICK %s\r", bot.nick); fprintf(bot.toserver, "USER %s %s %s :%s\r", bot.nick, bot.domain, bot.host, bot.realname); fflush(bot.toserver); sleep(1); /* Pong Reply */ while(input == NULL) fscanf(bot.fromserver, "%s", input); pong = strstr(input, "PING"); pong += 5; fprintf(bot.toserver, "PONG %s", pong); printf("\tJoining Channel..."); /* join the channel */ fprintf(bot.toserver, "JOIN %s", bot.channel); printf("\tReady\n"); for(;;) { /* just send a ping every once in a while so we don't get logged off */ fprintf(bot.toserver, "PING :123456789"); sleep(2); } shutdown(bot.sock, SHUT_RDWR); fclose(bot.toserver); fclose(bot.fromserver); close(bot.sock); return 0; }![]()



LinkBack URL
About LinkBacks




. Any more help?