int main(int argc, char **argv) { char* server, *port; if (argc != 3) { printf("Usage: %s <server> <port>\n", argv[0]); exit(EXIT_FAILURE); } server = argv[1]; /* The IRC server */ port = argv[2]; /* The IRC server port */ /* Bind message commands to custom functions */ irc_bind_command("!op", (Callback) give_op); irc_bind_command("!deop", (Callback) take_op); irc_bind_command("!voice", (Callback) give_voice); irc_bind_command("!devoice", (Callback) take_voice); /* Connect, login and join the configured channel */ irc_connect(server, port); irc_login(CONF_NICK, "Circus", "Circus IRC bot"); irc_join(CONF_CHAN); /* Start listening to events. * This method blocks until a quit signal is received */ irc_listen(); /* Send quit message and close connection */ irc_quit("Bye"); irc_disconnect(); return 0; }
int main(int argc, char **argv) { char* server, *port; if (argc != 3) { printf("Usage: %s <server> <port>\n", argv[0]); exit(EXIT_FAILURE); } server = argv[1]; /* The IRC server */ port = argv[2]; /* The IRC server port */ /* Bind IRC event to custom functions. * All bindable events are defined in codes.h */ irc_bind_event(ERR_NICKNAMEINUSE, (Callback) on_nick_in_use); irc_bind_event(ERROR, (Callback) on_error); irc_bind_event(JOIN, (Callback) on_join); irc_bind_event(ALL, (Callback) on_message); /* Connect, login and join the configured channel */ irc_connect(server, port); irc_login(CONF_NICK, "Circus", "Circus IRC bot"); irc_join(CONF_CHAN); /* Start listening to events. * This method blocks until a quit signal is received */ irc_listen(); /* Send quit message and close connection */ irc_quit("Bye"); irc_disconnect(); return 0; }
void test_irc_quit() { char msg[READ_BUF]; irc_quit("Bye"); read_mock(msg); mu_assert(s_eq(msg, "QUIT :Bye\r\n"), "test_irc_quit: msg should be 'QUIT :Bye\\r\\n'"); }
void extern_exit(int info) { if(info == SIGINT) log_write("*** Recieved CTRL-C..."); irc_quit("Program Terminated"); free_xion_memory(); event_call(EVENT_EXIT, 0); log_write("*** Program ended successfully. Allocation Calls: %d Free Calls: %d", stats.alloc_calls, stats.free_calls); exit(EXIT_SUCCESS); return ; }
static char *test_irc_quit() { bstring expected; expected = bfromcstr("QUIT\r\n"); irc_quit(0); mu_assert("Empty message", blength(sent) != 0); mu_assert("Message differs from expected", bstrcmp(expected, sent) == 0); bdestroy(expected); bdestroy(sent); return NULL; }
void sigyn_fatal(char *format, ...) { char buf[BUFSIZE]; va_list args; va_start(args, format); vsnprintf(buf, BUFSIZE, format, args); va_end(args); logger(LOG_ERROR, buf); if (me.uplink.connected) irc_quit(buf); sigyn_cleanup(); exit(EXIT_FAILURE); }
int main(int argc, char *argv[]) { char console[MAX_LEN]; unsigned int err = 0; extern unsigned long alloc_calls; extern unsigned long free_calls; handle_first = (struct handle_list*)mallocm(sizeof(struct handle_list)); if(handle_first == NULL) { make_error("Failed to allocate memory for internal handle list!"); getchar(); return 1; } handle_first->next = NULL; handle_first->handle = (void*)&handle_first; handle_last = handle_first; dispsplash(); printf("Initializing... "); stats.start_time = (long)time(NULL); if(!init()) { make_error("Initialization failed (init() is 0)."); free_xion_memory(); getchar(); return 1; } bot_cmd_init(); printf("Done.\n"); if(!log_clean()) make_warning("Failed to clear log file."); log_write("*** Program started. Executed as: %s", argv[0]); printf("Connecting to %s:%d... ", bot.servaddr, bot.servport); if((err = irc_connect(bot.servaddr, bot.servport)) != 0) { printf("Failed to connect. ERROR %d\n\n", err); log_write("Connecting failed with code: %d", err); printf("Press Enter key to continue."); getchar(); return 0; } printf("Connected.\n"); signal(SIGINT, extern_exit); while(1) { fgets(console, 512, stdin); if(console[0] == '\n') break; strrtok(console, "\r\n"); if(istrcmp(console, "exit")) break; else if(istrcmp(console, "rehash")) { printf("\nRehashing configuration...\n"); if(!rehashconfig()) printf("Failed."); else printf("Done."); } else irc_send(console, 1); } irc_quit(NULL); free_xion_memory(); event_call(EVENT_EXIT, 0); log_write("*** Program ended successfully. Allocation Calls: %d Free Calls: %d", stats.alloc_calls, stats.free_calls); return 0; }
/* Disconnect if the nick is in use */ void on_nick_in_use(ErrorEvent* event) { printf("Nick %s is already in use\n", event->params[1]); irc_quit("Bye"); irc_disconnect(); exit(EXIT_FAILURE); }