Guest User

Untitled

a guest
Dec 26th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. #include <string.h>
  5.  
  6. #include <libircclient.h>
  7.  
  8. void show_error( const char *type, const char *text, ... ){
  9. va_list ap;
  10. va_start(ap,text);
  11. fprintf(stdout,"\033[31m%s ERROR: \033[0m",type);
  12. vfprintf(stdout,text,ap);
  13. fprintf(stdout,"\n");
  14. va_end(ap);
  15. }
  16.  
  17. void show_notice( const char *type, const char *text, ... ){
  18. va_list ap;
  19. va_start(ap,text);
  20. fprintf(stdout,"\033[34m%s NOTICE: \033[0m",type);
  21. vfprintf(stdout,text,ap);
  22. fprintf(stdout,"\n");
  23. va_end(ap);
  24. }
  25.  
  26. void my_event(irc_session_t *session, const char *type, const char *origin, const char **params, unsigned int count){
  27. show_notice(type,"event = %s",type);
  28. }
  29.  
  30. int main(int argc, char **argv){
  31. const char *nick = "hfgtftd";
  32. const char *pass = NULL;
  33. const char *addr = "irc.freenode.net";
  34. int port = 8001;
  35. const char *user = NULL;
  36. const char *real = NULL;
  37.  
  38. show_notice("IRC","Connecting to: %s:%s@%s:%d [%s|%s]",nick,pass?pass:"",addr,port,user?user:"",real?real:"");
  39.  
  40. irc_callbacks_t cbs = {
  41. my_event,
  42. my_event,
  43. my_event,
  44. my_event,
  45. my_event,
  46. my_event,
  47. my_event,
  48. my_event,
  49. my_event,
  50. my_event,
  51. my_event,
  52. my_event,
  53. /* my_event_channel_notice, */
  54. my_event,
  55. NULL,
  56. NULL,
  57. NULL,
  58. my_event,
  59. NULL,
  60. NULL,
  61. NULL
  62. };
  63.  
  64. int ircerrno;
  65. irc_session_t *S = irc_create_session(&cbs);
  66. if(S==NULL){
  67. show_error("IRC","could not create session");
  68. return(0);
  69. }
  70.  
  71. irc_option_set(S, LIBIRC_OPTION_STRIPNICKS|LIBIRC_OPTION_DEBUG);
  72.  
  73. ircerrno = irc_connect( S, addr, port, pass, nick, user, real );
  74. if(ircerrno!=0){
  75. show_error("IRC","could not connect to server: %s",irc_strerror(ircerrno));
  76. return(0);
  77. }
  78.  
  79. ircerrno = irc_run(S);
  80. if(ircerrno!=0){
  81. show_error("IRC","irc_run: %s",irc_strerror(ircerrno));
  82. ircerrno = irc_errno(S);
  83. show_error("IRC","irc_run: %s",irc_strerror(ircerrno));
  84. }
  85.  
  86. return(0);
  87.  
  88. }
Add Comment
Please, Sign In to add comment