Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 15.52 KB | None | 0 0
  1. #include "core.h"
  2. /*
  3.     cpIRC - C++ class based IRC protocol wrapper
  4.     Copyright (C) 2003 Iain Sheppard
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Lesser General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2.1 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14.     Lesser General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Lesser General Public
  17.     License along with this library; if not, write to the Free Software
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19.  
  20.     Contacting the author:
  21.     ~~~~~~~~~~~~~~~~~~~~~~
  22.  
  23.     email:  iainsheppard@yahoo.co.uk
  24.     IRC:    #magpie @ irc.quakenet.org
  25. */
  26.  
  27. IRC::IRC()
  28. {
  29.     hooks=0;
  30.     chan_users=0;
  31.     connected=false;
  32.     sentnick=false;
  33.     sentpass=false;
  34.     sentuser=false;
  35.     cur_nick=0;
  36. }
  37.  
  38. IRC::~IRC()
  39. {
  40.     if (hooks)
  41.         delete_irc_command_hook(hooks);
  42. }
  43.  
  44. void IRC::insert_irc_command_hook(irc_command_hook* hook, char* cmd_name, int (*function_ptr)(char*, irc_reply_data*, void*))
  45. {
  46.     if (hook->function)
  47.     {
  48.         if (!hook->next)
  49.         {
  50.             hook->next=new irc_command_hook;
  51.             hook->next->function=0;
  52.             hook->next->irc_command=0;
  53.             hook->next->next=0;
  54.         }
  55.         insert_irc_command_hook(hook->next, cmd_name, function_ptr);
  56.     }
  57.     else
  58.     {
  59.         hook->function=function_ptr;
  60.         hook->irc_command=new char[strlen(cmd_name)+1];
  61.         strcpy(hook->irc_command, cmd_name);
  62.     }
  63. }
  64.  
  65. void IRC::hook_irc_command(char* cmd_name, int (*function_ptr)(char*, irc_reply_data*, void*))
  66. {
  67.     if (!hooks)
  68.     {
  69.         hooks=new irc_command_hook;
  70.         hooks->function=0;
  71.         hooks->irc_command=0;
  72.         hooks->next=0;
  73.         insert_irc_command_hook(hooks, cmd_name, function_ptr);
  74.     }
  75.     else
  76.     {
  77.         insert_irc_command_hook(hooks, cmd_name, function_ptr);
  78.     }
  79. }
  80.  
  81. void IRC::delete_irc_command_hook(irc_command_hook* cmd_hook)
  82. {
  83.     if (cmd_hook->next)
  84.         delete_irc_command_hook(cmd_hook->next);
  85.     if (cmd_hook->irc_command)
  86.         delete cmd_hook->irc_command;
  87.     delete cmd_hook;
  88. }
  89.  
  90. int IRC::start(char* server, int port, char* nick, char* user, char* name, char* pass)
  91. {
  92.     #ifdef WIN32
  93.     HOSTENT* resolv;
  94.     #else
  95.     hostent* resolv;
  96.     #endif
  97.     sockaddr_in rem;
  98.  
  99.     if (connected)
  100.         return 1;
  101.  
  102.     irc_socket=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  103.     if (irc_socket==INVALID_SOCKET)
  104.     {
  105.         return 1;
  106.     }
  107.     resolv=gethostbyname(server);
  108.     if (!resolv)
  109.     {
  110.         closesocket(irc_socket);
  111.         return 1;
  112.     }
  113.     memcpy(&rem.sin_addr, resolv->h_addr, 4);
  114.     rem.sin_family=AF_INET;
  115.     rem.sin_port=htons(port);
  116.  
  117.     if (connect(irc_socket, (const sockaddr*)&rem, sizeof(rem))==SOCKET_ERROR)
  118.     {
  119.         #ifdef WIN32
  120.         printf("Failed to connect: %d\n", WSAGetLastError());
  121.         #endif
  122.         closesocket(irc_socket);
  123.         return 1;
  124.     }
  125.  
  126.  
  127.     dataout = _fdopen(irc_socket, "w");
  128.     //datain=fdopen(irc_socket, "r");
  129.    
  130.     if (!dataout /*|| !datain*/)
  131.     {
  132.         printf("Failed to open streams! %d\n", GetLastError());
  133.         closesocket(irc_socket);
  134.         return 1;
  135.     }
  136.    
  137.     connected=true;
  138.    
  139.     cur_nick=new char[strlen(nick)+1];
  140.     strcpy(cur_nick, nick);
  141.  
  142.     fprintf(dataout, "PASS %s\r\n", pass);
  143.     fprintf(dataout, "NICK %s\r\n", nick);
  144.     fprintf(dataout, "USER %s * 0 :%s\r\n", user, name);
  145.     fflush(dataout);       
  146.  
  147.     return 0;
  148. }
  149.  
  150. void IRC::disconnect()
  151. {
  152.     if (connected)
  153.     {
  154.         fclose(dataout);
  155.         printf("Disconnected from server.\n");
  156.         connected=false;
  157.         quit("Leaving");
  158.         #ifdef WIN32
  159.         shutdown(irc_socket, 2);
  160.         #endif
  161.         closesocket(irc_socket);
  162.     }
  163. }
  164.  
  165. int IRC::quit(char* quit_message)
  166. {
  167.     if (connected)
  168.     {
  169.         if (quit_message)
  170.             fprintf(dataout, "QUIT %s\r\n", quit_message);
  171.         else
  172.             fprintf(dataout, "QUIT\r\n");
  173.         if (fflush(dataout))
  174.             return 1;
  175.     }
  176.     return 0;
  177. }
  178.  
  179. int IRC::message_loop()
  180. {
  181.     char buffer[1024];
  182.     int ret_len;
  183.  
  184.     if (!connected)
  185.     {
  186.         printf("Not connected!\n");
  187.         return 1;
  188.     }
  189.  
  190.     while (1)
  191.     {
  192.         ret_len=recv(irc_socket, buffer, 1023, 0);
  193.         if (ret_len==SOCKET_ERROR || !ret_len)
  194.         {
  195.             return 1;
  196.         }
  197.         buffer[ret_len]='\0';
  198.         split_to_replies(buffer);
  199.     }
  200.  
  201.     return 0;
  202. }
  203.  
  204. void IRC::split_to_replies(char* data)
  205. {
  206.     char* p;
  207.  
  208.     while (p=strstr(data, "\r\n"))
  209.     {
  210.         *p='\0';
  211.         parse_irc_reply(data);
  212.         data=p+2;
  213.     }
  214. }
  215.  
  216. int IRC::is_op(char* channel, char* nick)
  217. {
  218.     channel_user* cup;
  219.  
  220.     cup=chan_users;
  221.    
  222.     while (cup)
  223.     {
  224.         if (!strcmp(cup->channel, channel) && !strcmp(cup->nick, nick))
  225.         {
  226.             return cup->flags&IRC_USER_OP;
  227.         }
  228.         cup=cup->next;
  229.     }
  230.  
  231.     return 0;
  232. }
  233.  
  234. int IRC::is_voice(char* channel, char* nick)
  235. {
  236.     channel_user* cup;
  237.  
  238.     cup=chan_users;
  239.    
  240.     while (cup)
  241.     {
  242.         if (!strcmp(cup->channel, channel) && !strcmp(cup->nick, nick))
  243.         {
  244.             return cup->flags&IRC_USER_VOICE;
  245.         }
  246.         cup=cup->next;
  247.     }
  248.  
  249.     return 0;
  250. }
  251.  
  252. void IRC::parse_irc_reply(char* data)
  253. {
  254.     char* hostd;
  255.     char* cmd;
  256.     char* params;
  257.     char buffer[514];
  258.     irc_reply_data hostd_tmp;
  259.     channel_user* cup;
  260.     char* p;
  261.     char* chan_temp;
  262.  
  263.     hostd_tmp.target=0;
  264.  
  265.     printf("%s\n", data);
  266.  
  267.     if (data[0]==':')
  268.     {
  269.         hostd=&data[1];
  270.         cmd=strchr(hostd, ' ');
  271.         if (!cmd)
  272.             return;
  273.         *cmd='\0';
  274.         cmd++;
  275.         params=strchr(cmd, ' ');
  276.         if (params)
  277.         {
  278.             *params='\0';
  279.             params++;
  280.         }
  281.         hostd_tmp.nick=hostd;
  282.         hostd_tmp.ident=strchr(hostd, '!');
  283.         if (hostd_tmp.ident)
  284.         {
  285.             *hostd_tmp.ident='\0';
  286.             hostd_tmp.ident++;
  287.             hostd_tmp.host=strchr(hostd_tmp.ident, '@');
  288.             if (hostd_tmp.host)
  289.             {
  290.                 *hostd_tmp.host='\0';
  291.                 hostd_tmp.host++;
  292.             }
  293.         }
  294.  
  295.         if (!strcmp(cmd, "JOIN"))
  296.         {
  297.             cup=chan_users;
  298.             if (cup)
  299.             {
  300.                 while (cup->nick)
  301.                 {
  302.                     if (!cup->next)
  303.                     {
  304.                         cup->next=new channel_user;
  305.                         cup->next->channel=0;
  306.                         cup->next->flags=0;
  307.                         cup->next->next=0;
  308.                         cup->next->nick=0;
  309.                     }
  310.                     cup=cup->next;
  311.                 }
  312.                 cup->channel=new char[strlen(params)+1];
  313.                 strcpy(cup->channel, params);
  314.                 cup->nick=new char[strlen(hostd_tmp.nick)+1];
  315.                 strcpy(cup->nick, hostd_tmp.nick);
  316.             }
  317.         }
  318.         else if (!strcmp(cmd, "PART"))
  319.         {
  320.             channel_user* d;
  321.             channel_user* prev;
  322.  
  323.             d=0;
  324.             prev=0;
  325.             cup=chan_users;
  326.             while (cup)
  327.             {
  328.                 if (!strcmp(cup->channel, params) && !strcmp(cup->nick, hostd_tmp.nick))
  329.                 {
  330.                     d=cup;
  331.                     break;
  332.                 }
  333.                 else
  334.                 {
  335.                     prev=cup;
  336.                 }
  337.                 cup=cup->next;
  338.             }
  339.             if (d)
  340.             {
  341.                 if (d==chan_users)
  342.                 {
  343.                     chan_users=d->next;
  344.                     if (d->channel)
  345.                         delete [] d->channel;
  346.                     if (d->nick)
  347.                         delete [] d->nick;
  348.                     delete d;
  349.                 }
  350.                 else
  351.                 {
  352.                     if (prev)
  353.                     {
  354.                         prev->next=d->next;
  355.                     }
  356.                     chan_users=d->next;
  357.                     if (d->channel)
  358.                         delete [] d->channel;
  359.                     if (d->nick)
  360.                         delete [] d->nick;
  361.                     delete d;
  362.                 }
  363.             }
  364.         }
  365.         else if (!strcmp(cmd, "QUIT"))
  366.         {
  367.             channel_user* d;
  368.             channel_user* prev;
  369.  
  370.             d=0;
  371.             prev=0;
  372.             cup=chan_users;
  373.             while (cup)
  374.             {
  375.                 if (!strcmp(cup->nick, hostd_tmp.nick))
  376.                 {
  377.                     d=cup;
  378.                     if (d==chan_users)
  379.                     {
  380.                         chan_users=d->next;
  381.                         if (d->channel)
  382.                             delete [] d->channel;
  383.                         if (d->nick)
  384.                             delete [] d->nick;
  385.                         delete d;
  386.                     }
  387.                     else
  388.                     {
  389.                         if (prev)
  390.                         {
  391.                             prev->next=d->next;
  392.                         }
  393.                         if (d->channel)
  394.                             delete [] d->channel;
  395.                         if (d->nick)
  396.                             delete [] d->nick;
  397.                         delete d;
  398.                     }
  399.                     break;
  400.                 }
  401.                 else
  402.                 {
  403.                     prev=cup;
  404.                 }
  405.                 cup=cup->next;
  406.             }
  407.         }
  408.         else if (!strcmp(cmd, "MODE"))
  409.         {
  410.             char* chan;
  411.             char* changevars;
  412.             channel_user* cup;
  413.             channel_user* d;
  414.             char* tmp;
  415.             int i;
  416.             bool plus;
  417.  
  418.             chan=params;
  419.             params=strchr(chan, ' ');
  420.             *params='\0';
  421.             params++;
  422.             changevars=params;
  423.             params=strchr(changevars, ' ');
  424.             if (!params)
  425.             {
  426.                 return;
  427.             }
  428.             if (chan[0]!='#')
  429.             {
  430.                 return;
  431.             }
  432.             *params='\0';
  433.             params++;
  434.        
  435.             plus=false;
  436.             for (i=0; i<(signed)strlen(changevars); i++)
  437.             {
  438.                 switch (changevars[i])
  439.                 {
  440.                 case '+':
  441.                     plus=true;
  442.                     break;
  443.                 case '-':
  444.                     plus=false;
  445.                     break;
  446.                 case 'o':
  447.                     tmp=strchr(params, ' ');
  448.                     if (tmp)
  449.                     {
  450.                         *tmp='\0';
  451.                         tmp++;
  452.                     }
  453.                     tmp=params;
  454.                     if (plus)
  455.                     {
  456.                         // user has been opped (chan, params)
  457.                         cup=chan_users;
  458.                         d=0;
  459.                         while (cup)
  460.                         {
  461.                             if (cup->next && cup->channel)
  462.                             {
  463.                                 if (!strcmp(cup->channel, chan) && !strcmp(cup->nick, tmp))
  464.                                 {
  465.                                     d=cup;
  466.                                     break;
  467.                                 }
  468.                             }
  469.                             cup=cup->next;
  470.                         }
  471.                         if (d)
  472.                         {
  473.                             d->flags=d->flags|IRC_USER_OP;
  474.                         }
  475.                     }
  476.                     else
  477.                     {
  478.                         // user has been deopped (chan, params)
  479.                         cup=chan_users;
  480.                         d=0;
  481.                         while (cup)
  482.                         {
  483.                             if (!strcmp(cup->channel, chan) && !strcmp(cup->nick, tmp))
  484.                             {
  485.                                 d=cup;
  486.                                 break;
  487.                             }
  488.                             cup=cup->next;
  489.                         }
  490.                         if (d)
  491.                         {
  492.                             d->flags=d->flags^IRC_USER_OP;
  493.                         }
  494.                     }
  495.                     params=tmp;
  496.                     break;
  497.                 case 'v':
  498.                     tmp=strchr(params, ' ');
  499.                     if (tmp)
  500.                     {
  501.                         *tmp='\0';
  502.                         tmp++;
  503.                     }
  504.                     if (plus)
  505.                     {
  506.                         // user has been voiced
  507.                         cup=chan_users;
  508.                         d=0;
  509.                         while (cup)
  510.                         {
  511.                             if (!strcmp(cup->channel, params) && !strcmp(cup->nick, hostd_tmp.nick))
  512.                             {
  513.                                 d=cup;
  514.                                 break;
  515.                             }
  516.                             cup=cup->next;
  517.                         }
  518.                         if (d)
  519.                         {
  520.                             d->flags=d->flags|IRC_USER_VOICE;
  521.                         }
  522.                     }
  523.                     else
  524.                     {
  525.                         // user has been devoiced
  526.                         cup=chan_users;
  527.                         d=0;
  528.                         while (cup)
  529.                         {
  530.                             if (!strcmp(cup->channel, params) && !strcmp(cup->nick, hostd_tmp.nick))
  531.                             {
  532.                                 d=cup;
  533.                                 break;
  534.                             }
  535.                             cup=cup->next;
  536.                         }
  537.                         if (d)
  538.                         {
  539.                             d->flags=d->flags^IRC_USER_VOICE;
  540.                         }
  541.                     }
  542.                     params=tmp;
  543.                     break;
  544.                 default:
  545.                     return;
  546.                     break;
  547.                 }
  548.                 // ------------ END OF MODE ---------------
  549.             }
  550.         }
  551.         else if (!strcmp(cmd, "353"))
  552.         {
  553.             // receiving channel names list
  554.             if (!chan_users)
  555.             {
  556.                 chan_users=new channel_user;
  557.                 chan_users->next=0;
  558.                 chan_users->nick=0;
  559.                 chan_users->flags=0;
  560.                 chan_users->channel=0;
  561.             }
  562.             cup=chan_users;
  563.             chan_temp=strchr(params, '#');
  564.             if (chan_temp)
  565.             {
  566.                 //chan_temp+=3;
  567.                 p=strstr(chan_temp, " :");
  568.                 if (p)
  569.                 {
  570.                     *p='\0';
  571.                     p+=2;
  572.                     while (strchr(p, ' '))
  573.                     {
  574.                         char* tmp;
  575.  
  576.                         tmp=strchr(p, ' ');
  577.                         *tmp='\0';
  578.                         tmp++;
  579.                         while (cup->nick)
  580.                         {
  581.                             if (!cup->next)
  582.                             {
  583.                                 cup->next=new channel_user;
  584.                                 cup->next->channel=0;
  585.                                 cup->next->flags=0;
  586.                                 cup->next->next=0;
  587.                                 cup->next->nick=0;
  588.                             }
  589.                             cup=cup->next;
  590.                         }
  591.                         if (p[0]=='@')
  592.                         {
  593.                             cup->flags=cup->flags|IRC_USER_OP;
  594.                             p++;
  595.                         }
  596.                         else if (p[0]=='+')
  597.                         {
  598.                             cup->flags=cup->flags|IRC_USER_VOICE;
  599.                             p++;
  600.                         }
  601.                         cup->nick=new char[strlen(p)+1];
  602.                         strcpy(cup->nick, p);
  603.                         cup->channel=new char[strlen(chan_temp)+1];
  604.                         strcpy(cup->channel, chan_temp);
  605.                         p=tmp;
  606.                     }
  607.                     while (cup->nick)
  608.                     {
  609.                         if (!cup->next)
  610.                         {
  611.                             cup->next=new channel_user;
  612.                             cup->next->channel=0;
  613.                             cup->next->flags=0;
  614.                             cup->next->next=0;
  615.                             cup->next->nick=0;
  616.                         }
  617.                         cup=cup->next;
  618.                     }
  619.                     if (p[0]=='@')
  620.                     {
  621.                         cup->flags=cup->flags|IRC_USER_OP;
  622.                         p++;
  623.                     }
  624.                     else if (p[0]=='+')
  625.                     {
  626.                         cup->flags=cup->flags|IRC_USER_VOICE;
  627.                         p++;
  628.                     }
  629.                     cup->nick=new char[strlen(p)+1];
  630.                     strcpy(cup->nick, p);
  631.                     cup->channel=new char[strlen(chan_temp)+1];
  632.                     strcpy(cup->channel, chan_temp);
  633.                 }
  634.             }
  635.         }
  636.         else if (!strcmp(cmd, "NOTICE"))
  637.         {
  638.             hostd_tmp.target=params;
  639.             params=strchr(hostd_tmp.target, ' ');
  640.             if (params)
  641.                 *params='\0';
  642.             params++;
  643.             #ifdef __IRC_DEBUG__
  644.             printf("%s >-%s- %s\n", hostd_tmp.nick, hostd_tmp.target, &params[1]);
  645.             #endif
  646.         }
  647.         else if (!strcmp(cmd, "PRIVMSG"))
  648.         {
  649.             hostd_tmp.target=params;
  650.             params=strchr(hostd_tmp.target, ' ');
  651.             if (!params)
  652.                 return;
  653.             *(params++)='\0';
  654.             #ifdef __IRC_DEBUG__
  655.             printf("%s: <%s> %s\n", hostd_tmp.target, hostd_tmp.nick, &params[1]);
  656.             #endif
  657.         }
  658.         else if (!strcmp(cmd, "NICK"))
  659.         {
  660.             if (!strcmp(hostd_tmp.nick, cur_nick))
  661.             {
  662.                 delete [] cur_nick;
  663.                 cur_nick=new char[strlen(params)+1];
  664.                 strcpy(cur_nick, params);
  665.             }
  666.         }
  667.         /* else if (!strcmp(cmd, ""))
  668.         {
  669.             #ifdef __IRC_DEBUG__
  670.             #endif
  671.         } */
  672.         call_hook(cmd, params, &hostd_tmp);
  673.     }
  674.     else
  675.     {
  676.         cmd=data;
  677.         data=strchr(cmd, ' ');
  678.         if (!data)
  679.             return;
  680.         *data='\0';
  681.         params=data+1;
  682.  
  683.         if (!strcmp(cmd, "PING"))
  684.         {
  685.             if (!params)
  686.                 return;
  687.             fprintf(dataout, "PONG %s\r\n", &params[1]);
  688.             #ifdef __IRC_DEBUG__
  689.             printf("Ping received, pong sent.\n");
  690.             #endif
  691.             fflush(dataout);
  692.         }
  693.         else
  694.         {
  695.             hostd_tmp.host=0;
  696.             hostd_tmp.ident=0;
  697.             hostd_tmp.nick=0;
  698.             hostd_tmp.target=0;
  699.             call_hook(cmd, params, &hostd_tmp);
  700.         }
  701.     }
  702. }
  703.  
  704. void IRC::call_hook(char* irc_command, char* params, irc_reply_data* hostd)
  705. {
  706.     irc_command_hook* p;
  707.  
  708.     if (!hooks)
  709.         return;
  710.  
  711.     p=hooks;
  712.     while (p)
  713.     {
  714.         if (!strcmp(p->irc_command, irc_command))
  715.         {
  716.             (*(p->function))(params, hostd, this);
  717.             p=0;
  718.         }
  719.         else
  720.         {
  721.             p=p->next;
  722.         }
  723.     }
  724. }
  725.  
  726. int IRC::notice(char* target, char* message)
  727. {
  728.     if (!connected)
  729.         return 1;
  730.     fprintf(dataout, "NOTICE %s :%s\r\n", target, message);
  731.     return fflush(dataout);
  732. }
  733.  
  734. int IRC::notice(char* fmt, ...)
  735. {
  736.     va_list argp;
  737.     char* target;
  738.    
  739.     if (!connected)
  740.         return 1;
  741.     va_start(argp, fmt);
  742.     fprintf(dataout, "NOTICE %s :", fmt);
  743.     vfprintf(dataout, va_arg(argp, char*), argp);
  744.     va_end(argp);
  745.     fprintf(dataout, "\r\n");
  746.     return fflush(dataout);
  747. }
  748.  
  749. int IRC::privmsg(char* target, char* message)
  750. {
  751.     if (!connected)
  752.         return 1;
  753.     fprintf(dataout, "PRIVMSG %s :%s\r\n", target, message);
  754.     return fflush(dataout);
  755. }
  756.  
  757. int IRC::privmsg(char* fmt, ...)
  758. {
  759.     va_list argp;
  760.     char* target;
  761.    
  762.     if (!connected)
  763.         return 1;
  764.     va_start(argp, fmt);
  765.     fprintf(dataout, "PRIVMSG %s :", fmt);
  766.     vfprintf(dataout, va_arg(argp, char*), argp);
  767.     va_end(argp);
  768.     fprintf(dataout, "\r\n");
  769.     return fflush(dataout);
  770. }
  771.  
  772.  
  773. int IRC::join(char* channel)
  774. {
  775.     if (!connected)
  776.         return 1;
  777.     fprintf(dataout, "JOIN %s\r\n", channel);
  778.     return fflush(dataout);
  779. }
  780.  
  781. int IRC::part(char* channel)
  782. {
  783.     if (!connected)
  784.         return 1;
  785.     fprintf(dataout, "PART %s\r\n", channel);
  786.     return fflush(dataout);
  787. }
  788.  
  789. int IRC::kick(char* channel, char* nick)
  790. {
  791.     if (!connected)
  792.         return 1;
  793.     fprintf(dataout, "KICK %s %s\r\n", channel, nick);
  794.     return fflush(dataout);
  795. }
  796.  
  797. int IRC::raw(char* data)
  798. {
  799.     if (!connected)
  800.         return 1;
  801.     fprintf(dataout, "%s\r\n", data);
  802.     return fflush(dataout);
  803. }
  804.  
  805. int IRC::kick(char* channel, char* nick, char* message)
  806. {
  807.     if (!connected)
  808.         return 1;
  809.     fprintf(dataout, "KICK %s %s :%s\r\n", channel, nick, message);
  810.     return fflush(dataout);
  811. }
  812.  
  813. int IRC::mode(char* channel, char* modes, char* targets)
  814. {
  815.     if (!connected)
  816.         return 1;
  817.     if (!targets)
  818.         fprintf(dataout, "MODE %s %s\r\n", channel, modes);
  819.     else
  820.         fprintf(dataout, "MODE %s %s %s\r\n", channel, modes, targets);
  821.     return fflush(dataout);
  822. }
  823.  
  824. int IRC::mode(char* modes)
  825. {
  826.     if (!connected)
  827.         return 1;
  828.     mode(cur_nick, modes, 0);
  829.     return 0;
  830. }
  831.  
  832. int IRC::nick(char* newnick)
  833. {
  834.     if (!connected)
  835.         return 1;
  836.     fprintf(dataout, "NICK %s\r\n", newnick);
  837.     return fflush(dataout);
  838. }
  839.  
  840. char* IRC::current_nick()
  841. {
  842.     return cur_nick;
  843. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement