home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / yagirc-0.51.tar.gz / yagirc-0.51.tar / yagirc-0.51 / ctcp.c < prev    next >
C/C++ Source or Header  |  1998-05-08  |  3KB  |  116 lines

  1. /*
  2.  
  3.  ctcp.c : Functions handling CTCP events
  4.  
  5.     Copyright (C) 1998 Timo Sirainen
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include <stdio.h>
  23. #include <string.h>
  24.  
  25. #include <glib.h>
  26.  
  27. #include "os.h"
  28. #include "txt.h"
  29. #include "dcc.h"
  30. #include "irc.h"
  31. #include "version.h"
  32. #include "events.h"
  33.  
  34. /* CTCP version */
  35. int ctcp_version(char *sender, char *target, char *data)
  36. {
  37.     char tmp[100];
  38.  
  39.     g_return_val_if_fail(sender != NULL, 1);
  40.  
  41.     sprintf(tmp, "NOTICE %s :\001VERSION %s\001", sender, IRC_VERSION);
  42.     irc_send_cmd(eserver, tmp);
  43.     return 1;
  44. }
  45.  
  46. /* CTCP ping */
  47. int ctcp_ping(char *sender, char *target, char *data)
  48. {
  49.     char tmp[512];
  50.  
  51.     g_return_val_if_fail(sender != NULL, 1);
  52.     g_return_val_if_fail(data != NULL, 1);
  53.  
  54.     sprintf(tmp, "NOTICE %s :\001PING %s\001", sender, data);
  55.     irc_send_cmd(eserver, tmp);
  56.     return 1;
  57. }
  58.  
  59. /* CTCP action = /ME command */
  60. int ctcp_action(char *sender, char *target, char *data)
  61. {
  62.     CHAN_REC *chan;
  63.  
  64.     g_return_val_if_fail(sender != NULL, 1);
  65.     g_return_val_if_fail(target != NULL, 1);
  66.     g_return_val_if_fail(data != NULL, 1);
  67.  
  68.     if (*target != '#' && *target != '&')
  69.         drawtext(edefwin, TXT_TYPE_DEFAULT, "%7 (*) %s %8%s\n", sender, data); /* private */
  70.     else
  71.     {
  72.         chan = channel_joined(eserver, target);
  73.  
  74.         if (chan != NULL && chan->window->curchan != NULL &&
  75.             strcasecmp(target, chan->window->curchan->name) == 0)
  76.             drawtext(chan->window, TXT_TYPE_DEFAULT, "%7 * %s %8%s\n", sender, data); /* current channel */
  77.         else
  78.             drawtext(chan == NULL ? edefwin : chan->window, TXT_TYPE_DEFAULT, "%7 * %s%n:%2%s %8%s\n", sender, target, data); /* some channel */
  79.  
  80.         if (chan != NULL && !chan->new_data && chan->window != curwin)
  81.         {
  82.             chan->new_data = 1;
  83.             gui_channel_hilight(chan);
  84.         }
  85.     }
  86.     return 0;
  87. }
  88.  
  89. /* CTCP DCC */
  90. int ctcp_dcc(char *sender, char *target, char *data)
  91. {
  92.     g_return_val_if_fail(sender != NULL, 1);
  93.     g_return_val_if_fail(data != NULL, 1);
  94.  
  95.     return dcc_handle_ctcp(sender, data);
  96. }
  97.  
  98. /* CTCP reply */
  99. int ctcp_reply(char *sender, char *data)
  100. {
  101.     char *ptr;
  102.  
  103.     g_return_val_if_fail(sender != NULL, 0);
  104.     g_return_val_if_fail(data != NULL, 0);
  105.  
  106.     ptr = strchr(data, ' ');
  107.     if (ptr != NULL) *ptr++ = '\0'; else ptr = "";
  108.  
  109.     if (strcmp(data, "DCC") == 0)
  110.         return dcc_reply(sender, ptr);
  111.  
  112.     drawtext(edefwin, TXT_TYPE_DEFAULT, IRCTXT_CTCP_REPLY, data, sender, ptr);
  113.  
  114.     return 1;
  115. }
  116.