1
0

ctcp.c 25 KB

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