~ubuntu-branches/ubuntu/oneiric/eggdrop/oneiric

« back to all changes in this revision

Viewing changes to src/mod/ctcp.mod/ctcp.c

  • Committer: Bazaar Package Importer
  • Author(s): Guilherme de S. Pastore
  • Date: 2004-06-17 09:15:28 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040617091528-64rrw1sa33lkfhmh
Tags: 1.6.16-2
* Fixed typo on README.Debian
* Fixed hyphens in manual page
* Converted debian/rules to CDBS
* Set path to binary on example config file
* Changed LANGDIR on src/eggdrop.h (Closes: #254824)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * ctcp.c -- part of ctcp.mod
3
3
 *   all the ctcp handling (except DCC, it's special ;)
4
4
 *
5
 
 * $Id: ctcp.c,v 1.17 2002/01/02 03:46:38 guppy Exp $
 
5
 * $Id: ctcp.c,v 1.22 2004/01/09 05:56:38 wcc Exp $
6
6
 */
7
7
/*
8
8
 * Copyright (C) 1997 Robey Pointer
9
 
 * Copyright (C) 1999, 2000, 2001, 2002 Eggheads Development Team
 
9
 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Eggheads Development Team
10
10
 *
11
11
 * This program is free software; you can redistribute it and/or
12
12
 * modify it under the terms of the GNU General Public License
40
40
 
41
41
 
42
42
static int ctcp_FINGER(char *nick, char *uhost, char *handle,
43
 
                       char *object, char *keyword, char *text)
 
43
                       char *object, char *keyword, char *text)
44
44
{
45
45
  if (ctcp_mode != 1 && ctcp_finger[0])
46
46
    simple_sprintf(ctcp_reply, "%s\001FINGER %s\001", ctcp_reply, ctcp_finger);
48
48
}
49
49
 
50
50
static int ctcp_ECHOERR(char *nick, char *uhost, char *handle,
51
 
                        char *object, char *keyword, char *text)
 
51
                        char *object, char *keyword, char *text)
52
52
{
53
53
  if (ctcp_mode != 1 && strlen(text) <= 80)
54
54
    simple_sprintf(ctcp_reply, "%s\001%s %s\001", ctcp_reply, keyword, text);
56
56
}
57
57
 
58
58
static int ctcp_PING(char *nick, char *uhost, char *handle,
59
 
                     char *object, char *keyword, char *text)
 
59
                     char *object, char *keyword, char *text)
60
60
{
61
61
  struct userrec *u = get_user_by_handle(userlist, handle);
62
62
  int atr = u ? u->flags : 0;
63
63
 
64
64
  if ((ctcp_mode != 1 || (atr & USER_OP)) && strlen(text) <= 80)
65
 
      simple_sprintf(ctcp_reply, "%s\001%s %s\001", ctcp_reply, keyword, text);
 
65
    simple_sprintf(ctcp_reply, "%s\001%s %s\001", ctcp_reply, keyword, text);
66
66
  return 1;
67
67
}
68
68
 
69
69
static int ctcp_VERSION(char *nick, char *uhost, char *handle,
70
 
                        char *object, char *keyword, char *text)
 
70
                        char *object, char *keyword, char *text)
71
71
{
72
72
  if (ctcp_mode != 1 && ctcp_version[0])
73
73
    simple_sprintf(ctcp_reply, "%s\001VERSION %s\001", ctcp_reply,
74
 
                   ctcp_version);
 
74
                   ctcp_version);
75
75
  return 1;
76
76
}
77
77
 
78
78
static int ctcp_USERINFO(char *nick, char *uhost, char *handle,
79
 
                         char *object, char *keyword, char *text)
 
79
                         char *object, char *keyword, char *text)
80
80
{
81
81
  if (ctcp_mode != 1 && ctcp_userinfo[0])
82
82
    simple_sprintf(ctcp_reply, "%s\001USERINFO %s\001", ctcp_reply,
83
 
                   ctcp_userinfo);
 
83
                   ctcp_userinfo);
84
84
  return 1;
85
85
}
86
86
 
87
87
static int ctcp_CLIENTINFO(char *nick, char *uhosr, char *handle,
88
 
                           char *object, char *keyword, char *msg)
 
88
                           char *object, char *keyword, char *msg)
89
89
{
90
90
  char *p = NULL;
91
91
 
119
119
    p = CLIENTINFO_ECHO;
120
120
  if (p == NULL) {
121
121
    simple_sprintf(ctcp_reply,
122
 
               "%s\001ERRMSG CLIENTINFO: %s is not a valid function\001",
123
 
                   ctcp_reply, msg);
 
122
                   "%s\001ERRMSG CLIENTINFO: %s is not a valid function\001",
 
123
                   ctcp_reply, msg);
124
124
  } else
125
125
    simple_sprintf(ctcp_reply, "%s\001CLIENTINFO %s\001", ctcp_reply, p);
126
126
  return 1;
127
127
}
128
128
 
129
129
static int ctcp_TIME(char *nick, char *uhost, char *handle, char *object,
130
 
                     char *keyword, char *text)
 
130
                     char *keyword, char *text)
131
131
{
132
132
  char tms[25];
133
133
 
140
140
}
141
141
 
142
142
static int ctcp_CHAT(char *nick, char *uhost, char *handle, char *object,
143
 
                     char *keyword, char *text)
 
143
                     char *keyword, char *text)
144
144
{
145
145
  struct userrec *u = get_user_by_handle(userlist, handle);
146
146
  int atr = u ? u->flags : 0, i;
147
147
 
148
 
  if ((atr & (USER_PARTY | USER_XFER)) ||
149
 
      ((atr & USER_OP) && !require_p)) {
 
148
  if ((atr & (USER_PARTY | USER_XFER)) || ((atr & USER_OP) && !require_p)) {
150
149
 
151
150
    if (u_pass_match(u, "-")) {
152
 
      simple_sprintf(ctcp_reply, "%s\001ERROR no password set\001", ctcp_reply);
 
151
      simple_sprintf(ctcp_reply, "%s\001ERROR no password set\001",
 
152
                     ctcp_reply);
153
153
      return 1;
154
154
    }
155
155
 
156
156
    for (i = 0; i < dcc_total; i++) {
157
157
      if ((dcc[i].type->flags & DCT_LISTEN) &&
158
 
          (!strcmp(dcc[i].nick, "(telnet)") ||
159
 
           !strcmp(dcc[i].nick, "(users)"))) {
 
158
          (!strcmp(dcc[i].nick, "(telnet)") ||
 
159
           !strcmp(dcc[i].nick, "(users)"))) {
160
160
        /* Do me a favour and don't change this back to a CTCP reply,
161
161
         * CTCP replies are NOTICE's this has to be a PRIVMSG
162
162
         * -poptix 5/1/1997 */
163
 
        dprintf(DP_SERVER, "PRIVMSG %s :\001DCC CHAT chat %lu %u\001\n",
164
 
                nick,
165
 
                iptolong(natip[0] ? (IP) inet_addr(natip) : getmyip()),
166
 
                dcc[i].port);
 
163
        dprintf(DP_SERVER, "PRIVMSG %s :\001DCC CHAT chat %lu %u\001\n",
 
164
                nick, iptolong(natip[0] ? (IP) inet_addr(natip) : getmyip()),
 
165
                dcc[i].port);
167
166
        return 1;
168
167
      }
169
168
    }
172
171
  return 1;
173
172
}
174
173
 
175
 
static cmd_t myctcp[] =
176
 
{
177
 
  {"FINGER",            "",     ctcp_FINGER,            NULL},
178
 
  {"ECHO",              "",     ctcp_ECHOERR,           NULL},
179
 
  {"PING",              "",     ctcp_PING,              NULL},
180
 
  {"ERRMSG",            "",     ctcp_ECHOERR,           NULL},
181
 
  {"VERSION",           "",     ctcp_VERSION,           NULL},
182
 
  {"USERINFO",          "",     ctcp_USERINFO,          NULL},
183
 
  {"CLIENTINFO",        "",     ctcp_CLIENTINFO,        NULL},
184
 
  {"TIME",              "",     ctcp_TIME,              NULL},
185
 
  {"CHAT",              "",     ctcp_CHAT,              NULL},
186
 
  {NULL,                NULL,   NULL,                   NULL}
187
 
};
188
 
 
189
 
static tcl_strings mystrings[] =
190
 
{
191
 
  {"ctcp-version",      ctcp_version,   120,    0},
192
 
  {"ctcp-finger",       ctcp_finger,    120,    0},
193
 
  {"ctcp-userinfo",     ctcp_userinfo,  120,    0},
194
 
  {NULL,                NULL,           0,      0}
195
 
};
196
 
 
197
 
static tcl_ints myints[] =
198
 
{
199
 
  {"ctcp-mode",         &ctcp_mode},
200
 
  {NULL,                NULL}
 
174
static cmd_t myctcp[] = {
 
175
  {"FINGER",     "",   ctcp_FINGER,     NULL},
 
176
  {"ECHO",       "",   ctcp_ECHOERR,    NULL},
 
177
  {"PING",       "",   ctcp_PING,       NULL},
 
178
  {"ERRMSG",     "",   ctcp_ECHOERR,    NULL},
 
179
  {"VERSION",    "",   ctcp_VERSION,    NULL},
 
180
  {"USERINFO",   "",   ctcp_USERINFO,   NULL},
 
181
  {"CLIENTINFO", "",   ctcp_CLIENTINFO, NULL},
 
182
  {"TIME",       "",   ctcp_TIME,       NULL},
 
183
  {"CHAT",       "",   ctcp_CHAT,       NULL},
 
184
  {NULL,         NULL, NULL,            NULL}
 
185
};
 
186
 
 
187
static tcl_strings mystrings[] = {
 
188
  {"ctcp-version",  ctcp_version,  120, 0},
 
189
  {"ctcp-finger",   ctcp_finger,   120, 0},
 
190
  {"ctcp-userinfo", ctcp_userinfo, 120, 0},
 
191
  {NULL,            NULL,          0,   0}
 
192
};
 
193
 
 
194
static tcl_ints myints[] = {
 
195
  {"ctcp-mode", &ctcp_mode},
 
196
  {NULL,              NULL}
201
197
};
202
198
 
203
199
static char *ctcp_close()
212
208
 
213
209
EXPORT_SCOPE char *ctcp_start();
214
210
 
215
 
static Function ctcp_table[] =
216
 
{
 
211
static Function ctcp_table[] = {
217
212
  (Function) ctcp_start,
218
213
  (Function) ctcp_close,
219
214
  (Function) NULL,
220
215
  (Function) NULL,
221
216
};
222
217
 
223
 
char *ctcp_start(Function * global_funcs)
 
218
char *ctcp_start(Function *global_funcs)
224
219
{
225
220
  global = global_funcs;
226
221
 
227
222
  module_register(MODULE_NAME, ctcp_table, 1, 0);
228
223
  if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
229
224
    module_undepend(MODULE_NAME);
230
 
    return "You need an eggdrop of at least v1.6.0 to use this ctcp module.";
 
225
    return "This module requires Eggdrop 1.6.0 or later.";
231
226
  }
232
227
  if (!(server_funcs = module_depend(MODULE_NAME, "server", 1, 0))) {
233
228
    module_undepend(MODULE_NAME);
234
 
    return "You need the server module to use the ctcp module.";
 
229
    return "This module requires server module 1.0 or later.";
235
230
  }
236
231
  add_tcl_strings(mystrings);
237
232
  add_tcl_ints(myints);