00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #define MODULE_NAME "ctcp"
00027 #define MAKING_CTCP
00028
00029 #include "ctcp.h"
00030 #include "src/mod/module.h"
00031 #include "server.mod/server.h"
00032 #include <netinet/in.h>
00033 #include <arpa/inet.h>
00034
00035 static Function *global = NULL, *server_funcs = NULL;
00036
00037 static char ctcp_version[121];
00038 static char ctcp_finger[121];
00039 static char ctcp_userinfo[121];
00040 static int ctcp_mode = 0;
00041
00042
00043 static int ctcp_FINGER(char *nick, char *uhost, char *handle,
00044 char *object, char *keyword, char *text)
00045 {
00046 if (ctcp_mode != 1 && ctcp_finger[0])
00047 simple_sprintf(ctcp_reply, "%s\001FINGER %s\001", ctcp_reply, ctcp_finger);
00048 return 1;
00049 }
00050
00051 static int ctcp_ECHOERR(char *nick, char *uhost, char *handle,
00052 char *object, char *keyword, char *text)
00053 {
00054 if (ctcp_mode != 1 && strlen(text) <= 80)
00055 simple_sprintf(ctcp_reply, "%s\001%s %s\001", ctcp_reply, keyword, text);
00056 return 1;
00057 }
00058
00059 static int ctcp_PING(char *nick, char *uhost, char *handle,
00060 char *object, char *keyword, char *text)
00061 {
00062 struct userrec *u = get_user_by_handle(userlist, handle);
00063 int atr = u ? u->flags : 0;
00064
00065 if ((ctcp_mode != 1 || (atr & USER_OP)) && strlen(text) <= 80)
00066 simple_sprintf(ctcp_reply, "%s\001%s %s\001", ctcp_reply, keyword, text);
00067 return 1;
00068 }
00069
00070 static int ctcp_VERSION(char *nick, char *uhost, char *handle,
00071 char *object, char *keyword, char *text)
00072 {
00073 if (ctcp_mode != 1 && ctcp_version[0])
00074 simple_sprintf(ctcp_reply, "%s\001VERSION %s\001", ctcp_reply,
00075 ctcp_version);
00076 return 1;
00077 }
00078
00079 static int ctcp_USERINFO(char *nick, char *uhost, char *handle,
00080 char *object, char *keyword, char *text)
00081 {
00082 if (ctcp_mode != 1 && ctcp_userinfo[0])
00083 simple_sprintf(ctcp_reply, "%s\001USERINFO %s\001", ctcp_reply,
00084 ctcp_userinfo);
00085 return 1;
00086 }
00087
00088 static int ctcp_CLIENTINFO(char *nick, char *uhosr, char *handle,
00089 char *object, char *keyword, char *msg)
00090 {
00091 char *p = NULL;
00092
00093 if (ctcp_mode == 1)
00094 return 1;
00095 else if (!msg[0])
00096 p = CLIENTINFO;
00097 else if (!egg_strcasecmp(msg, "sed"))
00098 p = CLIENTINFO_SED;
00099 else if (!egg_strcasecmp(msg, "version"))
00100 p = CLIENTINFO_VERSION;
00101 else if (!egg_strcasecmp(msg, "clientinfo"))
00102 p = CLIENTINFO_CLIENTINFO;
00103 else if (!egg_strcasecmp(msg, "userinfo"))
00104 p = CLIENTINFO_USERINFO;
00105 else if (!egg_strcasecmp(msg, "errmsg"))
00106 p = CLIENTINFO_ERRMSG;
00107 else if (!egg_strcasecmp(msg, "finger"))
00108 p = CLIENTINFO_FINGER;
00109 else if (!egg_strcasecmp(msg, "time"))
00110 p = CLIENTINFO_TIME;
00111 else if (!egg_strcasecmp(msg, "action"))
00112 p = CLIENTINFO_ACTION;
00113 else if (!egg_strcasecmp(msg, "dcc"))
00114 p = CLIENTINFO_DCC;
00115 else if (!egg_strcasecmp(msg, "utc"))
00116 p = CLIENTINFO_UTC;
00117 else if (!egg_strcasecmp(msg, "ping"))
00118 p = CLIENTINFO_PING;
00119 else if (!egg_strcasecmp(msg, "echo"))
00120 p = CLIENTINFO_ECHO;
00121 if (p == NULL) {
00122 simple_sprintf(ctcp_reply,
00123 "%s\001ERRMSG CLIENTINFO: %s is not a valid function\001",
00124 ctcp_reply, msg);
00125 } else
00126 simple_sprintf(ctcp_reply, "%s\001CLIENTINFO %s\001", ctcp_reply, p);
00127 return 1;
00128 }
00129
00130 static int ctcp_TIME(char *nick, char *uhost, char *handle, char *object,
00131 char *keyword, char *text)
00132 {
00133 char tms[25];
00134
00135 if (ctcp_mode == 1)
00136 return 1;
00137 strncpy(tms, ctime(&now), 24);
00138 tms[24] = 0;
00139 simple_sprintf(ctcp_reply, "%s\001TIME %s\001", ctcp_reply, tms);
00140 return 1;
00141 }
00142
00143 static int ctcp_CHAT(char *nick, char *uhost, char *handle, char *object,
00144 char *keyword, char *text)
00145 {
00146 struct userrec *u = get_user_by_handle(userlist, handle);
00147 int atr = u ? u->flags : 0, i;
00148
00149 if ((atr & (USER_PARTY | USER_XFER)) || ((atr & USER_OP) && !require_p)) {
00150
00151 if (u_pass_match(u, "-")) {
00152 simple_sprintf(ctcp_reply, "%s\001ERROR no password set\001",
00153 ctcp_reply);
00154 return 1;
00155 }
00156
00157 for (i = 0; i < dcc_total; i++) {
00158 if ((dcc[i].type->flags & DCT_LISTEN) &&
00159 (!strcmp(dcc[i].nick, "(telnet)") ||
00160 !strcmp(dcc[i].nick, "(users)"))) {
00161
00162
00163
00164 dprintf(DP_SERVER, "PRIVMSG %s :\001DCC CHAT chat %lu %u\001\n",
00165 nick, iptolong(natip[0] ? (IP) inet_addr(natip) : getmyip()),
00166 dcc[i].port);
00167 return 1;
00168 }
00169 }
00170 simple_sprintf(ctcp_reply, "%s\001ERROR no telnet port\001", ctcp_reply);
00171 }
00172 return 1;
00173 }
00174
00175 static cmd_t myctcp[] = {
00176 {"FINGER", "", ctcp_FINGER, NULL},
00177 {"ECHO", "", ctcp_ECHOERR, NULL},
00178 {"PING", "", ctcp_PING, NULL},
00179 {"ERRMSG", "", ctcp_ECHOERR, NULL},
00180 {"VERSION", "", ctcp_VERSION, NULL},
00181 {"USERINFO", "", ctcp_USERINFO, NULL},
00182 {"CLIENTINFO", "", ctcp_CLIENTINFO, NULL},
00183 {"TIME", "", ctcp_TIME, NULL},
00184 {"CHAT", "", ctcp_CHAT, NULL},
00185 {NULL, NULL, NULL, NULL}
00186 };
00187
00188 static tcl_strings mystrings[] = {
00189 {"ctcp-version", ctcp_version, 120, 0},
00190 {"ctcp-finger", ctcp_finger, 120, 0},
00191 {"ctcp-userinfo", ctcp_userinfo, 120, 0},
00192 {NULL, NULL, 0, 0}
00193 };
00194
00195 static tcl_ints myints[] = {
00196 {"ctcp-mode", &ctcp_mode},
00197 {NULL, NULL}
00198 };
00199
00200 static char *ctcp_close()
00201 {
00202 rem_tcl_strings(mystrings);
00203 rem_tcl_ints(myints);
00204 rem_builtins(H_ctcp, myctcp);
00205 rem_help_reference("ctcp.help");
00206 module_undepend(MODULE_NAME);
00207 return NULL;
00208 }
00209
00210 EXPORT_SCOPE char *ctcp_start();
00211
00212 static Function ctcp_table[] = {
00213 (Function) ctcp_start,
00214 (Function) ctcp_close,
00215 (Function) NULL,
00216 (Function) NULL,
00217 };
00218
00219 char *ctcp_start(Function *global_funcs)
00220 {
00221 global = global_funcs;
00222
00223 module_register(MODULE_NAME, ctcp_table, 1, 0);
00224 if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
00225 module_undepend(MODULE_NAME);
00226 return "This module requires Eggdrop 1.6.0 or later.";
00227 }
00228 if (!(server_funcs = module_depend(MODULE_NAME, "server", 1, 0))) {
00229 module_undepend(MODULE_NAME);
00230 return "This module requires server module 1.0 or later.";
00231 }
00232 add_tcl_strings(mystrings);
00233 add_tcl_ints(myints);
00234 add_builtins(H_ctcp, myctcp);
00235 add_help_reference("ctcp.help");
00236 if (!ctcp_version[0]) {
00237 strncpy(ctcp_version, ver, 120);
00238 ctcp_version[120] = 0;
00239 }
00240 if (!ctcp_finger[0]) {
00241 strncpy(ctcp_finger, ver, 120);
00242 ctcp_finger[120] = 0;
00243 }
00244 if (!ctcp_userinfo[0]) {
00245 strncpy(ctcp_userinfo, ver, 120);
00246 ctcp_userinfo[120] = 0;
00247 }
00248 return NULL;
00249 }