ctcp.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /*
  2. * ctcp.c -- part of ctcp.mod
  3. * all the ctcp handling (except DCC, it's special ;)
  4. *
  5. */
  6. #include "ctcp.h"
  7. #include "src/common.h"
  8. #include "src/main.h"
  9. #include "src/cfg.h"
  10. #include "src/chanprog.h"
  11. #include "src/cmds.h"
  12. #include "src/misc.h"
  13. #include "src/net.h"
  14. #include "src/userrec.h"
  15. #include "src/botmsg.h"
  16. #include "src/tclhash.h"
  17. #include "src/egg_timer.h"
  18. #ifdef LEAF
  19. #include "src/mod/server.mod/server.h"
  20. #include <netinet/in.h>
  21. #include <arpa/inet.h>
  22. #include <sys/utsname.h>
  23. #include <ctype.h>
  24. #endif /* LEAF */
  25. int cloak_script = CLOAK_PLAIN;
  26. #ifdef LEAF
  27. #ifdef S_AUTOAWAY
  28. #define AVGAWAYTIME 60
  29. #define AVGHERETIME 5
  30. #endif /* S_AUTOAWAY */
  31. time_t cloak_awaytime = 0;
  32. time_t cloak_heretime = 0;
  33. time_t listen_time = 0;
  34. char cloak_bxver[10] = "";
  35. char cloak_os[20] = "";
  36. char cloak_osver[100] = "";
  37. char cloak_host[161] = "";
  38. char ctcpversion[400] = "";
  39. char ctcpuserinfo[400] = "";
  40. char autoaway[100] = "";
  41. char *strtolower(char *s)
  42. {
  43. char *p = NULL, *p2 = strdup(s);
  44. p = p2;
  45. while (*p) {
  46. *p = tolower(*p);
  47. p++;
  48. }
  49. return p2;
  50. }
  51. void scriptchanged()
  52. {
  53. char tmp[200] = "", *p = NULL;
  54. switch (cloak_script) {
  55. case CLOAK_PLAIN:
  56. sprintf(ctcpversion, "\002BitchX-%s\002 by panasync - %s %s : \002Keep it to yourself!\002", cloak_bxver, cloak_os, cloak_osver);
  57. strcpy(ctcpuserinfo, "");
  58. strcpy(autoaway, "Auto-Away after 10 mins");
  59. strcpy(kickprefix, "");
  60. strcpy(bankickprefix, "");
  61. break;
  62. case CLOAK_CRACKROCK:
  63. sprintf(ctcpversion, "BitchX-%s\002/\002%s %s:(\002c\002)\037rackrock\037/\002b\002X \037[\0373.0.1á9\037]\037 :\002 Keep it to yourself!\002", cloak_bxver, cloak_os, cloak_osver);
  64. strcpy(ctcpuserinfo, "crack addict, help me.");
  65. strcpy(autoaway, "automatically dead");
  66. strcpy(kickprefix, "\002c\002/\037k\037: ");
  67. strcpy(bankickprefix, "\002c\002/\037kb\037: ");
  68. break;
  69. case CLOAK_NEONAPPLE:
  70. sprintf(tmp, "%s %s", cloak_os, cloak_osver);
  71. p = strtolower(tmp);
  72. sprintf(ctcpversion, "bitchx-%s\037(\037%s\037):\037 \002n\002eon\037a\037ppl\002e\002\037/\037\002v\0020\037.\03714i : \002d\002ont you wish you had it\037?\037", cloak_bxver, p);
  73. free(p);
  74. strcpy(ctcpuserinfo, "neon apple");
  75. strcpy(autoaway, "automatically away after 10 mins \037(\037\002n\002/\037a)\037");
  76. strcpy(kickprefix, "\037[na\002(\037k\037)\002]\037 ");
  77. strcpy(bankickprefix, "");
  78. break;
  79. case CLOAK_TUNNELVISION:
  80. strcpy(tmp, cloak_bxver);
  81. p = tmp;
  82. p += strlen(tmp) - 1;
  83. p[1] = p[0];
  84. p[0] = '\037';
  85. p[2] = '\037';
  86. p[3] = 0;
  87. sprintf(ctcpversion, "\002b\002itchx-%s :tunnel\002vision\002/\0371.2\037", tmp);
  88. strcpy(ctcpuserinfo, "");
  89. strcpy(autoaway, "auto-gone");
  90. strcpy(kickprefix, "");
  91. strcpy(bankickprefix, "");
  92. break;
  93. case CLOAK_ARGON:
  94. sprintf(ctcpversion, ".\037.(\037argon\002/\0021g\037)\037 \002:\002bitchx-%s", cloak_bxver);
  95. strcpy(ctcpuserinfo, "");
  96. strcpy(autoaway, "\037(\037ar\037)\037 auto-away \037(\03710m\037)\037");
  97. strcpy(kickprefix, "\037(\037ar\037)\037 ");
  98. strcpy(bankickprefix, "\037(\037ar\037)\037 ");
  99. break;
  100. case CLOAK_EVOLVER:
  101. sprintf(ctcpversion, "\037evolver\037(\00202x9\002)\037: bitchx\037(\002%s\002) \037í\037 %s\002/\002%s : eye yam pheerable now!", cloak_bxver, cloak_os, cloak_osver);
  102. strcpy(ctcpuserinfo, "");
  103. strcpy(autoaway, "[\037\002i\002dle for \037[\03710 minutes\037]]");
  104. strcpy(kickprefix, "\037ev\002!\002k\037 ");
  105. strcpy(bankickprefix, "\037ev\002!\002bk\037 ");
  106. break;
  107. case CLOAK_PREVAIL:
  108. sprintf(ctcpversion, "%s\037!\037%s bitchx-%s \002-\002 prevail\037[\0370123\037]\037 :down with people", cloak_os, cloak_osver, cloak_bxver);
  109. strcpy(ctcpuserinfo, botrealname);
  110. strcpy(autoaway, "idle 10 minutes \037-\037 gone\037!\037");
  111. strcpy(kickprefix, "\037[\037pv\037!\037k\037]\037 ");
  112. strcpy(bankickprefix, "\037[\037pv\037!\037bk\037]\037 ");
  113. break;
  114. case CLOAK_MIRC:
  115. {
  116. char mircver[4] = "";
  117. switch (randint(9)) {
  118. case 0:
  119. strcpy(mircver, "6.01");
  120. break;
  121. case 1:
  122. strcpy(mircver, "6.02");
  123. break;
  124. case 2:
  125. strcpy(mircver, "6.03");
  126. break;
  127. case 3:
  128. strcpy(mircver, "6.1");
  129. break;
  130. case 4:
  131. strcpy(mircver, "5.91");
  132. break;
  133. case 5:
  134. strcpy(mircver, "6.11");
  135. break;
  136. case 6:
  137. strcpy(mircver, "6.12");
  138. break;
  139. case 7:
  140. strcpy(mircver, "6.14");
  141. break;
  142. case 8:
  143. strcpy(mircver, "6.15");
  144. default:
  145. strcpy(mircver, "");
  146. }
  147. sprintf(ctcpversion, "mIRC v%s Khaled Mardam-Bey", mircver);
  148. strcpy(ctcpuserinfo, botrealname);
  149. strcpy(autoaway, "auto-away after 10 minutes");
  150. strcpy(kickprefix, "");
  151. strcpy(bankickprefix, "");
  152. break;
  153. }
  154. case CLOAK_CYPRESS:
  155. {
  156. char theme[30] = "";
  157. switch (randint(25)) { /* 0-19 = script, 20-24 = plain */
  158. case 0:
  159. strcpy(theme, " \037.\037.\002BX\002");
  160. break;
  161. case 1:
  162. strcpy(theme, " \037.\037.chl\037o\037rine");
  163. break;
  164. case 2:
  165. strcpy(theme, " \037.\037.\037<\037c\002x\002\037>\037");
  166. break;
  167. case 3:
  168. strcpy(theme, " \037.\037.supercyan");
  169. break;
  170. case 4:
  171. strcpy(theme, " \037.\037.\037c\037yan\002i\002\002\037z\037\002\037e\037d");
  172. break;
  173. case 5:
  174. strcpy(theme, " \037.\037.delusion");
  175. break;
  176. case 6:
  177. strcpy(theme, " \037.\037.\002e\002mbryonic");
  178. break;
  179. case 7:
  180. strcpy(theme, " \037.\037.e\002x\002tra\037.\037terrestr\037i\037al");
  181. break;
  182. case 8:
  183. strcpy(theme, " \037.\037.\002f\002ad\037e\037d");
  184. break;
  185. case 9:
  186. strcpy(theme, " \037.\037.fo\037c\037us");
  187. break;
  188. case 10:
  189. strcpy(theme, " \037.\037.\002h\002ade\037s\037");
  190. break;
  191. case 11:
  192. strcpy(theme, " \037.\037.hellbent\037.\037");
  193. break;
  194. case 12:
  195. strcpy(theme, " \037.\037.illusi\037o\037n");
  196. break;
  197. case 13:
  198. strcpy(theme, " \037.\037.\037j\037ungl\037e\037");
  199. break;
  200. case 14:
  201. strcpy(theme, " \037.\037.\002l\002abry\037i\037nth");
  202. break;
  203. case 15:
  204. strcpy(theme, " \037.\037.nightblue");
  205. break;
  206. case 16:
  207. strcpy(theme, " \037.\037.\037o\037bli\037v\037io\037n\037");
  208. break;
  209. case 17:
  210. strcpy(theme, " \037.\037.ph\002a\002ze");
  211. break;
  212. case 18:
  213. strcpy(theme, " \037.\037.sphere");
  214. break;
  215. case 19:
  216. strcpy(theme, " \037.\037.zip");
  217. break;
  218. default:
  219. strcpy(theme, "");
  220. break;
  221. }
  222. switch (randint(16)) {
  223. case 0:
  224. sprintf(ctcpversion, "bitchx\037-\037%s \037/\037 cypress\037.\03701i%s", cloak_bxver, theme);
  225. break;
  226. case 1:
  227. sprintf(ctcpversion, "cypress\037.\03701i%s \037/\037 bitchx\037-\037%s", theme, cloak_bxver);
  228. break;
  229. case 2:
  230. sprintf(tmp, "%s %s", cloak_os, cloak_osver);
  231. p = strtolower(tmp);
  232. sprintf(ctcpversion, "cypress\037.\03701i%s %s\037(\037%s\037)\037 bitchx\037-\037%s)", theme, p, cloak_host, cloak_bxver);
  233. free(p);
  234. break;
  235. case 3:
  236. sprintf(tmp, "%s %s", cloak_os, cloak_osver);
  237. p = strtolower(tmp);
  238. sprintf(ctcpversion, "bitchx\037-\037%s %s\037(\037%s\037)\037 cypress\037.\03701i%s", cloak_bxver, p, cloak_host, theme);
  239. free(p);
  240. break;
  241. case 4:
  242. sprintf(ctcpversion, "%s\002/\002%s: BitchX-%s \002[\002cypress\002]\002 v01i%s", cloak_os, cloak_osver, cloak_bxver, theme);
  243. break;
  244. case 5:
  245. p = replace(cloak_osver, ".", "\037.\037");
  246. sprintf(tmp, "%s %s", cloak_os, p);
  247. p = strtolower(tmp);
  248. sprintf(ctcpversion, "\037.\037.cypress\037.\03701i%s %s\037(\037%s\037)\037 bitchx\037/\037%s",theme, p, cloak_host, cloak_bxver);
  249. free(p);
  250. break;
  251. case 6:
  252. p = replace(cloak_osver, ".", "\037.\037");
  253. sprintf(tmp, "%s %s", cloak_os, p);
  254. p = strtolower(tmp);
  255. sprintf(ctcpversion, "cypress\002.\00201i%s\037(\037bitchx\002.\002%s\037)\037\002.\002. %s\037(\037%s\037)\037",theme, cloak_bxver, p, cloak_host);
  256. free(p);
  257. break;
  258. case 7:
  259. p = replace(cloak_osver, ".", "\037.\037");
  260. sprintf(tmp, "%s %s", cloak_os, p);
  261. p = strtolower(tmp);
  262. sprintf(ctcpversion, "\037.\037.cypress\037.\03701i%s - bitchx\037.\037%s\002/\002%s", theme, cloak_bxver, p);
  263. free(p);
  264. break;
  265. case 8:
  266. sprintf(ctcpversion, "\002BitchX-%s\002 by panasync \002-\002 %s %s", cloak_bxver, cloak_os, cloak_osver);
  267. break;
  268. case 9:
  269. sprintf(ctcpversion, "\037[\037cypress\002/\00201i\037]\037 - %s \037[\037bx\002/\002%s\037]\037", theme, cloak_bxver);
  270. break;
  271. case 10:
  272. sprintf(ctcpversion, "\037[\037\002b\002itchx\002.\002%s\037]\037 \002+\002 \037[\037cypress\002.\00201i\037]\037 %s",cloak_bxver, theme);
  273. break;
  274. case 11:
  275. sprintf(ctcpversion, "\037[\037BitchX\002/\002%s\037(\037cypress\002/\00201i\037)]\037 %s", cloak_bxver, theme);
  276. break;
  277. case 12:
  278. p = strtolower(cloak_os);
  279. sprintf(ctcpversion, "bitchx\037/\037%s %s %s \037(\037cypress\037/\03701i\037)\037 %s", cloak_bxver, p, cloak_osver, theme);
  280. free(p);
  281. break;
  282. case 13:
  283. sprintf(ctcpversion, "\037.\037.cypress\037/\03701i\037!\037bitchx\037/\037%s\037.\037.%s", cloak_bxver, theme);
  284. break;
  285. case 14:
  286. p = strtolower(cloak_bxver);
  287. sprintf(ctcpversion, "cypress\002\037.\037\002\037.\03701i\002/\002bitchx\037.\037\002\037.\037\002%s%s", p, theme);
  288. free(p);
  289. break;
  290. case 15:
  291. p = strtolower(cloak_bxver);
  292. sprintf(ctcpversion, "cypress\037.\03701i\037/\037bx%s \037(\037%s\037)\037", p, theme);
  293. free(p);
  294. break;
  295. }
  296. strcpy(ctcpuserinfo, "");
  297. strcpy(autoaway, "autoaway after 40 min");
  298. strcpy(kickprefix, "\002.\002.\037(\037\002c\002yp\002/\002k\037)\037 ");
  299. strcpy(bankickprefix, "\002.\002.\037(\037\002c\002yp\002/\002bk\037)\037 ");
  300. break;
  301. }
  302. }
  303. }
  304. #ifdef S_AUTOAWAY
  305. void sendaway()
  306. {
  307. char awtime[20] = "";
  308. int hrs, min, sec;
  309. time_t gt;
  310. gt = now - cloak_awaytime;
  311. hrs = gt / 3600;
  312. min = (gt % 3600) / 60;
  313. sec = gt % 60;
  314. switch (cloak_script) {
  315. case CLOAK_PLAIN:
  316. dprintf(DP_HELP, "AWAY :is away: (%s) [\002BX\002-MsgLog Off]\n", autoaway);
  317. break;
  318. case CLOAK_MIRC:
  319. dprintf(DP_HELP, "AWAY :is away: (%s)\n", autoaway);
  320. break;
  321. case CLOAK_CRACKROCK:
  322. if (hrs)
  323. sprintf(awtime, "%dh %dm %ds", hrs, min, sec);
  324. else if (min)
  325. sprintf(awtime, "%dm %ds", min, sec);
  326. else
  327. sprintf(awtime, "%ds", sec);
  328. dprintf(DP_HELP, "AWAY :%s\002\037[\002%s\002]\037\002\n", autoaway, awtime);
  329. break;
  330. case CLOAK_TUNNELVISION:
  331. if (hrs)
  332. sprintf(awtime, "%dh%dm%ds", hrs, min, sec);
  333. else if (min)
  334. sprintf(awtime, "%dm%ds", min, sec);
  335. else
  336. sprintf(awtime, "%ds", sec);
  337. dprintf(DP_HELP, "AWAY :%s \037(\037%s\037)\037\n", autoaway, awtime);
  338. break;
  339. case CLOAK_ARGON:
  340. if (hrs)
  341. sprintf(awtime, "%dh%dm%ds", hrs, min, sec);
  342. else if (min)
  343. sprintf(awtime, "%dm%ds", min, sec);
  344. else
  345. sprintf(awtime, "%ds", sec);
  346. dprintf(DP_HELP, "AWAY :%s .\002.\002\037(\037%s\037)\037\n", autoaway, awtime);
  347. break;
  348. case CLOAK_EVOLVER:
  349. if (hrs)
  350. sprintf(awtime, "%dh %dm %ds", hrs, min, sec);
  351. else if (min)
  352. sprintf(awtime, "%dm %ds", min, sec);
  353. else
  354. sprintf(awtime, "%ds", sec);
  355. dprintf(DP_HELP, "AWAY :away\037: %s (\037l\002:\002off\037,\037 p\002:\002off\037)\037 \037[\037gone\002:\002%s\037]\037\n", autoaway, awtime);
  356. break;
  357. case CLOAK_PREVAIL:
  358. if (hrs)
  359. sprintf(awtime, "%dh%dm%ds", hrs, min, sec);
  360. else if (min)
  361. sprintf(awtime, "%dm%ds", min, sec);
  362. else
  363. sprintf(awtime, "%ds", sec);
  364. dprintf(DP_HELP, "AWAY :%s %s\n", autoaway, awtime);
  365. break;
  366. case CLOAK_CYPRESS:
  367. dprintf(DP_HELP, "AWAY :is gone\037.\037. %s \037.\037.\037[\037\002c\002yp\037(\037l\002/\002off\002.\002p\002/\002off)]\n", autoaway);
  368. break;
  369. }
  370. }
  371. #endif /* S_AUTOAWAY */
  372. static void ctcp_minutely()
  373. {
  374. int i;
  375. #ifdef S_AUTOAWAY
  376. if (server_online) {
  377. if ((cloak_awaytime == 0) && (cloak_heretime == 0)) {
  378. cloak_heretime = now;
  379. dprintf(DP_HELP, "AWAY :\n");
  380. return;
  381. }
  382. if (cloak_awaytime == 0) {
  383. if (!randint(AVGHERETIME)) {
  384. cloak_heretime = 0;
  385. cloak_awaytime = now - 600 - randint(60);
  386. sendaway();
  387. }
  388. } else {
  389. if (!randint(AVGAWAYTIME)) {
  390. cloak_awaytime = 0;
  391. cloak_heretime = now;
  392. dprintf(DP_HELP, "AWAY :\n");
  393. } else
  394. sendaway();
  395. }
  396. }
  397. #endif /* S_AUTOAWAY */
  398. if (listen_time <= 0) {
  399. for (i = 0; i < dcc_total; i++) {
  400. if ((dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)") || !strcmp(dcc[i].nick, "(telnet6)"))) {
  401. putlog(LOG_DEBUG, "*", "Closing listening port %d %s", dcc[i].port, dcc[i].nick);
  402. killsock(dcc[i].sock);
  403. lostdcc(i);
  404. break;
  405. }
  406. }
  407. } else
  408. listen_time--;
  409. }
  410. static int ctcp_FINGER(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  411. {
  412. time_t idletime;
  413. if (cloak_awaytime)
  414. idletime = now - cloak_awaytime;
  415. else if (cloak_heretime)
  416. idletime = now - cloak_heretime;
  417. else
  418. idletime = 0;
  419. dprintf(DP_HELP, "NOTICE %s :\001%s %s (%s@%s) Idle %li second%s\001\n", nick, keyword, "",
  420. conf.username ? conf.username : conf.bot->nick,
  421. (strchr(botuserhost, '@') + 1), idletime, idletime == 1 ? "" : "s");
  422. return BIND_RET_BREAK;
  423. }
  424. static int ctcp_ECHO(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  425. {
  426. char reply[60] = "";
  427. strncpyz(reply, text, sizeof(reply));
  428. dprintf(DP_HELP, "NOTICE %s :\001%s %s\001\n", nick, keyword, reply);
  429. return BIND_RET_BREAK;
  430. }
  431. static int ctcp_PING(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  432. {
  433. if (strlen(text) <= 80) /* bitchx ignores > 80 */
  434. dprintf(DP_HELP, "NOTICE %s :\001%s %s\001\n", nick, keyword, text);
  435. return BIND_RET_BREAK;
  436. }
  437. static int ctcp_VERSION(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  438. {
  439. char s[50] = "";
  440. if (cloak_script == CLOAK_CYPRESS) {
  441. switch (randint(8)) {
  442. case 0:
  443. strcpy(s, " :should of put the glock down.");
  444. break;
  445. case 1:
  446. strcpy(s, " :hot damn, I didn't want to kill a man.");
  447. break;
  448. case 2:
  449. strcpy(s, " :check me and I'll check ya back.");
  450. break;
  451. case 3:
  452. strcpy(s, " :put the blunt down just for a minute.");
  453. break;
  454. case 4:
  455. strcpy(s, " :tried to jack me, my homie got shot.");
  456. break;
  457. case 5:
  458. strcpy(s, " :insane in the membrane");
  459. break;
  460. case 6:
  461. strcpy(s, " :slow hits from the bong");
  462. break;
  463. case 7:
  464. strcpy(s, " :k\002-\002leet");
  465. break;
  466. }
  467. }
  468. dprintf(DP_HELP, "NOTICE %s :\001%s %s%s\001\n", nick, keyword, ctcpversion, s);
  469. /* if mirc send second reply here.. */
  470. return BIND_RET_BREAK;
  471. }
  472. static int ctcp_WHOAMI(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  473. {
  474. dprintf(DP_HELP, "NOTICE %s :\002BitchX\002: Access Denied\n", nick);
  475. return BIND_RET_BREAK;
  476. }
  477. static int ctcp_OP(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  478. {
  479. char chan[256] = "", *p = NULL;
  480. if (text[0]) {
  481. strncpyz(chan, text, sizeof(chan));
  482. p = strchr(chan, ' ');
  483. if (p)
  484. *p = 0;
  485. dprintf(DP_HELP, "NOTICE %s :\002BitchX\002: I'm not on %s or I'm not opped\n", nick, chan);
  486. }
  487. return BIND_RET_BREAK;
  488. }
  489. static int ctcp_INVITE_UNBAN(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  490. {
  491. struct chanset_t *chan = chanset;
  492. char chname[256] = "", *p = NULL;
  493. if (text[0] == '#') {
  494. strncpyz(chname, text, sizeof(chname));
  495. p = strchr(chname, ' ');
  496. if (p)
  497. *p = 0;
  498. while (chan) {
  499. if (chan->status & CHAN_ACTIVE) {
  500. if (!egg_strcasecmp(chan->name, chname)) {
  501. dprintf(DP_HELP, "NOTICE %s :\002BitchX\002: Access Denied\n", nick);
  502. return BIND_RET_LOG;
  503. }
  504. }
  505. chan = chan->next;
  506. }
  507. dprintf(DP_HELP, "NOTICE %s :\002BitchX\002: I'm not on that channel\n", nick);
  508. }
  509. return BIND_RET_BREAK;
  510. }
  511. static int ctcp_USERINFO(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  512. {
  513. if (cloak_script == CLOAK_TUNNELVISION)
  514. strcpy(ctcpuserinfo, botname);
  515. else if (cloak_script == CLOAK_PREVAIL) {
  516. strcpy(ctcpuserinfo, botname);
  517. strcat(ctcpuserinfo, " ?");
  518. }
  519. dprintf(DP_HELP, "NOTICE %s :\001%s %s\001\n", nick, keyword, ctcpuserinfo);
  520. return BIND_RET_BREAK;
  521. }
  522. static int ctcp_CLIENTINFO(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  523. {
  524. char buf[256] = "";
  525. if (!text[0]) {
  526. strcpy(buf, "SED UTC ACTION DCC CDCC BDCC XDCC VERSION CLIENTINFO USERINFO ERRMSG FINGER TIME PING ECHO INVITE WHOAMI OP OPS UNBAN IDENT XLINK UPTIME :Use CLIENTINFO <COMMAND> to get more specific information");
  527. } else if (!egg_strcasecmp(text, "UNBAN"))
  528. strcpy(buf, "UNBAN unbans the person from channel");
  529. else if (!egg_strcasecmp(text, "OPS"))
  530. strcpy(buf, "OPS ops the person if on userlist");
  531. else if (!egg_strcasecmp(text, "ECHO"))
  532. strcpy(buf, "ECHO returns the arguments it receives");
  533. else if (!egg_strcasecmp(text, "WHOAMI"))
  534. strcpy(buf, "WHOAMI user list information");
  535. else if (!egg_strcasecmp(text, "INVITE"))
  536. strcpy(buf, "INVITE invite to channel specified");
  537. else if (!egg_strcasecmp(text, "PING"))
  538. strcpy(buf, "PING returns the arguments it receives");
  539. else if (!egg_strcasecmp(text, "UTC"))
  540. strcpy(buf, "UTC substitutes the local timezone");
  541. else if (!egg_strcasecmp(text, "XDCC"))
  542. strcpy(buf, "XDCC checks cdcc info for you");
  543. else if (!egg_strcasecmp(text, "BDCC"))
  544. strcpy(buf, "BDCC checks cdcc info for you");
  545. else if (!egg_strcasecmp(text, "CDCC"))
  546. strcpy(buf, "CDCC checks cdcc info for you");
  547. else if (!egg_strcasecmp(text, "DCC"))
  548. strcpy(buf, "DCC requests a direct_client_connection");
  549. else if (!egg_strcasecmp(text, "ACTION"))
  550. strcpy(buf, "ACTION contains action descriptions for atmosphere");
  551. else if (!egg_strcasecmp(text, "FINGER"))
  552. strcpy(buf, "FINGER shows real name, login name and idle time of user");
  553. else if (!egg_strcasecmp(text, "ERRMSG"))
  554. strcpy(buf, "ERRMSG returns error messages");
  555. else if (!egg_strcasecmp(text, "USERINFO"))
  556. strcpy(buf, "USERINFO returns user settable information");
  557. else if (!egg_strcasecmp(text, "CLIENTINFO"))
  558. strcpy(buf, "CLIENTINFO gives information about available CTCP commands");
  559. else if (!egg_strcasecmp(text, "SED"))
  560. strcpy(buf, "SED contains simple_encrypted_data");
  561. else if (!egg_strcasecmp(text, "OP"))
  562. strcpy(buf, "OP ops the person if on userlist");
  563. else if (!egg_strcasecmp(text, "VERSION"))
  564. strcpy(buf, "VERSION shows client type, version and environment");
  565. else if (!egg_strcasecmp(text, "XLINK"))
  566. strcpy(buf, "XLINK x-filez rule");
  567. else if (!egg_strcasecmp(text, "IDENT"))
  568. strcpy(buf, "IDENT change userhost of userlist");
  569. else if (!egg_strcasecmp(text, "TIME"))
  570. strcpy(buf, "TIME tells you the time on the user's host");
  571. else if (!egg_strcasecmp(text, "UPTIME"))
  572. strcpy(buf, "UPTIME my uptime");
  573. else {
  574. dprintf(DP_HELP, "NOTICE %s :\001ERRMSG %s is not a valid function\001\n", nick, text);
  575. return BIND_RET_LOG;
  576. }
  577. dprintf(DP_HELP, "NOTICE %s :\001%s %s\001\n", nick, keyword, buf);
  578. return BIND_RET_BREAK;
  579. }
  580. static int ctcp_TIME(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  581. {
  582. char tms[81] = "";
  583. strncpyz(tms, ctime(&now), sizeof(tms));
  584. dprintf(DP_HELP, "NOTICE %s :\001%s %s\001\n", nick, keyword, tms);
  585. return BIND_RET_BREAK;
  586. }
  587. static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
  588. {
  589. int i, ix = (-1);
  590. if (!ischanhub())
  591. return BIND_RET_LOG;
  592. if (u_pass_match(u, "-")) {
  593. simple_sprintf(ctcp_reply, "%s\001ERROR no password set\001", ctcp_reply);
  594. return BIND_RET_BREAK;
  595. }
  596. for (i = 0; i < dcc_total; i++) {
  597. if ((dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)")))
  598. ix = i;
  599. }
  600. if (dcc_total == max_dcc || (ix < 0 && (ix = listen_all(0, 0)) < 0))
  601. simple_sprintf(ctcp_reply, "%s\001ERROR no telnet port\001", ctcp_reply);
  602. else {
  603. if (listen_time <= 2)
  604. listen_time++;
  605. /* do me a favour and don't change this back to a CTCP reply,
  606. * CTCP replies are NOTICE's this has to be a PRIVMSG
  607. * -poptix 5/1/1997 */
  608. dprintf(DP_SERVER, "PRIVMSG %s :\001DCC CHAT chat %lu %u\001\n", nick, iptolong(getmyip()), dcc[ix].port);
  609. }
  610. return BIND_RET_BREAK;
  611. }
  612. static cmd_t myctcp[] =
  613. {
  614. {"CLIENTINFO", "", ctcp_CLIENTINFO, NULL},
  615. {"FINGER", "", ctcp_FINGER, NULL},
  616. {"WHOAMI", "", ctcp_WHOAMI, NULL},
  617. {"OP", "", ctcp_OP, NULL},
  618. {"OPS", "", ctcp_OP, NULL},
  619. {"INVITE", "", ctcp_INVITE_UNBAN, NULL},
  620. {"UNBAN", "", ctcp_INVITE_UNBAN, NULL},
  621. {"ERRMSG", "", ctcp_ECHO, NULL},
  622. {"USERINFO", "", ctcp_USERINFO, NULL},
  623. {"ECHO", "", ctcp_ECHO, NULL},
  624. {"VERSION", "", ctcp_VERSION, NULL},
  625. {"PING", "", ctcp_PING, NULL},
  626. {"TIME", "", ctcp_TIME, NULL},
  627. {"CHAT", "", ctcp_CHAT, NULL},
  628. {NULL, NULL, NULL, NULL}
  629. };
  630. #endif /* LEAF */
  631. #ifdef HUB
  632. static void cloak_describe(struct cfg_entry *cfgent, int idx)
  633. {
  634. dprintf(idx, STR("cloak-script decides which BitchX script the bot cloaks. If set to 0, a random script will be cloaked.\n"));
  635. dprintf(idx, STR("Available: 1=plain bitchx, 2=crackrock, 3=neonapple, 4=tunnelvision, 5=argon, 6=evolver, 7=prevail 8=cypress 9=mIRC\n"));
  636. }
  637. #endif /* HUB */
  638. static void cloak_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
  639. {
  640. char *p = NULL;
  641. int i;
  642. if (!(p = cfgent->ldata ? cfgent->ldata : cfgent->gdata))
  643. return;
  644. i = atoi(p);
  645. #ifdef LEAF
  646. if (i == 0)
  647. i = randint(CLOAK_COUNT) + 1;
  648. #endif /* LEAF */
  649. if ((*valid = ((i >= 0) && (i <= CLOAK_COUNT))))
  650. cloak_script = i;
  651. #ifdef LEAF
  652. scriptchanged();
  653. #endif /* LEAF */
  654. }
  655. struct cfg_entry CFG_CLOAK_SCRIPT = {
  656. "cloak-script", CFGF_GLOBAL | CFGF_LOCAL, NULL, NULL,
  657. cloak_changed, cloak_changed
  658. #ifdef HUB
  659. , cloak_describe
  660. #endif /* HUB */
  661. };
  662. void ctcp_init()
  663. {
  664. #ifdef LEAF
  665. char *p = NULL;
  666. #ifndef CYGWIN_HACKS
  667. struct utsname un;
  668. egg_bzero(&un, sizeof(un));
  669. if (!uname(&un)) {
  670. strncpyz(cloak_os, un.sysname, sizeof(cloak_os));
  671. strncpyz(cloak_osver, un.release, sizeof(cloak_osver));
  672. strncpyz(cloak_host, un.nodename, sizeof(cloak_host));
  673. } else {
  674. #endif /* !CYGWIN_HACKS */
  675. /* shit, we have to come up with something ourselves.. */
  676. switch (randint(2)) {
  677. case 0:
  678. strcpy(cloak_os, "Linux");
  679. strcpy(cloak_osver, "2.4.20");
  680. break;
  681. case 1:
  682. strcpy(cloak_os, "FreeBSD");
  683. strcpy(cloak_osver, "4.5-STABLE");
  684. break;
  685. }
  686. strcpy(cloak_host, "login");
  687. #ifndef CYGWIN_HACKS
  688. }
  689. #endif /* !CYGWIN_HACKS */
  690. if ((p = strchr(cloak_host, '.')))
  691. *p = 0;
  692. switch (randint(4)) {
  693. case 0:
  694. strcpy(cloak_bxver, "1.0c17");
  695. break;
  696. case 1:
  697. strcpy(cloak_bxver, "1.0c18");
  698. break;
  699. case 2:
  700. strcpy(cloak_bxver, "1.0c19");
  701. break;
  702. case 3:
  703. strcpy(cloak_bxver, "1.0c20cvs+");
  704. break;
  705. }
  706. scriptchanged();
  707. add_builtins("ctcp", myctcp);
  708. timer_create_secs(60, "ctcp_minutely", (Function) ctcp_minutely);
  709. #endif /* LEAF */
  710. add_cfg(&CFG_CLOAK_SCRIPT);
  711. }