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 init_conf (irc_t * irc, FILE * conf) { char *servname = NULL, *servport = NULL, *line = NULL, *tok = NULL, ch = 0; int state = 0; do { line = getln(conf); ch = 0; tok = NULL; if (line != NULL) tok = strtok(line, " :"); if (tok != NULL) { if (strcmp(tok, "") == 0) tok = NULL; if (tok != NULL) ch = tok[0]; } if (ch == '{') { state = 1; } else if (ch == '}') { state = 0; } else if (state == 0 && tok != NULL) { servname = tok; servport = strtok(NULL, " :"); if ( irc_connect(irc, servname, servport) < 0 ) { fprintf(stderr, "Connection to %s:%sfailed.\n", servname, servport); } else { if ( irc_login(irc, BOTNAME) < 0 ) { fprintf(stderr, "Couldn't log in.\n"); } } } else if (state == 1 && ch == '#') { char *chan = malloc(strlen(tok)+1); strcpy(chan, tok); irc_join(irc, chan); } if (line != NULL) { free(line); } } while (line != NULL); }
void irc_cycle() { pthread_mutex_lock(&mutex); if (first_connection > 0) { pthread_cond_wait(&ready_to_connect, &mutex); } con_socket = get_socket(IRC_ADDRESS, IRC_PORT); first_connection++; if (con_socket < 0 ) { printf(".:. Connection failed .:.\n"); } sleep(5); irc_login(con_socket); pthread_cond_broadcast(&ready_to_IO); pthread_mutex_unlock(&mutex); }