Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <string.h>
- #include <libircclient.h>
- void show_error( const char *type, const char *text, ... ){
- va_list ap;
- va_start(ap,text);
- fprintf(stdout,"\033[31m%s ERROR: \033[0m",type);
- vfprintf(stdout,text,ap);
- fprintf(stdout,"\n");
- va_end(ap);
- }
- void show_notice( const char *type, const char *text, ... ){
- va_list ap;
- va_start(ap,text);
- fprintf(stdout,"\033[34m%s NOTICE: \033[0m",type);
- vfprintf(stdout,text,ap);
- fprintf(stdout,"\n");
- va_end(ap);
- }
- void my_event(irc_session_t *session, const char *type, const char *origin, const char **params, unsigned int count){
- show_notice(type,"event = %s",type);
- }
- int main(int argc, char **argv){
- const char *nick = "hfgtftd";
- const char *pass = NULL;
- const char *addr = "irc.freenode.net";
- int port = 8001;
- const char *user = NULL;
- const char *real = NULL;
- show_notice("IRC","Connecting to: %s:%s@%s:%d [%s|%s]",nick,pass?pass:"",addr,port,user?user:"",real?real:"");
- irc_callbacks_t cbs = {
- my_event,
- my_event,
- my_event,
- my_event,
- my_event,
- my_event,
- my_event,
- my_event,
- my_event,
- my_event,
- my_event,
- my_event,
- /* my_event_channel_notice, */
- my_event,
- NULL,
- NULL,
- NULL,
- my_event,
- NULL,
- NULL,
- NULL
- };
- int ircerrno;
- irc_session_t *S = irc_create_session(&cbs);
- if(S==NULL){
- show_error("IRC","could not create session");
- return(0);
- }
- irc_option_set(S, LIBIRC_OPTION_STRIPNICKS|LIBIRC_OPTION_DEBUG);
- ircerrno = irc_connect( S, addr, port, pass, nick, user, real );
- if(ircerrno!=0){
- show_error("IRC","could not connect to server: %s",irc_strerror(ircerrno));
- return(0);
- }
- ircerrno = irc_run(S);
- if(ircerrno!=0){
- show_error("IRC","irc_run: %s",irc_strerror(ircerrno));
- ircerrno = irc_errno(S);
- show_error("IRC","irc_run: %s",irc_strerror(ircerrno));
- }
- return(0);
- }
Add Comment
Please, Sign In to add comment