cmdschan.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. /*
  2. * cmdschan.c -- part of channels.mod
  3. * commands from a user via dcc that cause server interaction
  4. *
  5. */
  6. #include <ctype.h>
  7. static struct flag_record user = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  8. static struct flag_record victim = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  9. static void cmd_pls_mask(char type, int idx, char *par)
  10. {
  11. char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL, *cmd = NULL;
  12. unsigned long int expire_time = 0, expire_foo;
  13. int sticky = 0;
  14. struct chanset_t *chan = NULL;
  15. cmd = type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite";
  16. if (!par[0]) {
  17. dprintf(idx, "Usage: +%s <hostmask> [channel] [%%<XdXhXm>] [reason]\n", cmd);
  18. return;
  19. }
  20. who = newsplit(&par);
  21. if (par[0] && strchr(CHANMETA, par[0]))
  22. chname = newsplit(&par);
  23. else
  24. chname = 0;
  25. if (chname || !(dcc[idx].user->flags & USER_MASTER)) {
  26. if (!chname)
  27. chname = dcc[idx].u.chat->con_chan;
  28. get_user_flagrec(dcc[idx].user, &user, chname);
  29. chan = findchan_by_dname(chname);
  30. /* *shrug* ??? (guppy:10Feb1999) */
  31. if (!chan || (chan && private(user, chan, PRIV_OP))) {
  32. dprintf(idx, "No such channel.\n");
  33. return;
  34. } else if (!chk_op(user, chan)) {
  35. dprintf(idx, "You don't have access to set %ss on %s.\n", cmd, chname);
  36. return;
  37. }
  38. } else
  39. chan = 0;
  40. /* Added by Q and Solal -- Requested by Arty2, special thanx :) */
  41. if (par[0] == '%') {
  42. p = newsplit(&par);
  43. p_expire = p + 1;
  44. while (*(++p) != 0) {
  45. switch (tolower(*p)) {
  46. case 'd':
  47. *p = 0;
  48. expire_foo = strtol(p_expire, NULL, 10);
  49. if (expire_foo > 365)
  50. expire_foo = 365;
  51. expire_time += 86400 * expire_foo;
  52. p_expire = p + 1;
  53. break;
  54. case 'h':
  55. *p = 0;
  56. expire_foo = strtol(p_expire, NULL, 10);
  57. if (expire_foo > 8760)
  58. expire_foo = 8760;
  59. expire_time += 3600 * expire_foo;
  60. p_expire = p + 1;
  61. break;
  62. case 'm':
  63. *p = 0;
  64. expire_foo = strtol(p_expire, NULL, 10);
  65. if (expire_foo > 525600)
  66. expire_foo = 525600;
  67. expire_time += 60 * expire_foo;
  68. p_expire = p + 1;
  69. }
  70. }
  71. }
  72. if (!par[0])
  73. par = "requested";
  74. else if (strlen(par) > MASKREASON_MAX)
  75. par[MASKREASON_MAX] = 0;
  76. if (strlen(who) > UHOSTMAX - 4)
  77. who[UHOSTMAX - 4] = 0;
  78. /* Fix missing ! or @ BEFORE checking against myself */
  79. if (!strchr(who, '!')) {
  80. if (!strchr(who, '@'))
  81. egg_snprintf(s, sizeof s, "%s!*@*", who); /* Lame nick ban */
  82. else
  83. egg_snprintf(s, sizeof s, "*!%s", who);
  84. } else if (!strchr(who, '@'))
  85. egg_snprintf(s, sizeof s, "%s@*", who); /* brain-dead? */
  86. else
  87. strncpyz(s, who, sizeof s);
  88. #ifdef LEAF
  89. egg_snprintf(s1, sizeof s1, "%s!%s", botname, botuserhost);
  90. #else
  91. egg_snprintf(s1, sizeof s1, "%s!%s@%s", origbotname, botuser, conf.bot->host);
  92. #endif /* LEAF */
  93. if (type == 'b' && s1[0] && wild_match(s, s1)) {
  94. dprintf(idx, "I'm not going to ban myself.\n");
  95. putlog(LOG_CMDS, "*", "#%s# attempted +ban %s", dcc[idx].nick, s);
  96. return;
  97. }
  98. /* IRC can't understand bans longer than 70 characters */
  99. if (strlen(s) > 70) {
  100. s[69] = '*';
  101. s[70] = 0;
  102. }
  103. if (chan) {
  104. u_addmask(type, chan, s, dcc[idx].nick, par, expire_time ? now + expire_time : 0, 0);
  105. if (par[0] == '*') {
  106. sticky = 1;
  107. par++;
  108. putlog(LOG_CMDS, "*", "#%s# (%s) +%s %s %s (%s) (sticky)",
  109. dcc[idx].nick, dcc[idx].u.chat->con_chan, cmd, s, chan->dname, par);
  110. dprintf(idx, "New %s sticky %s: %s (%s)\n", chan->dname, cmd, s, par);
  111. } else {
  112. putlog(LOG_CMDS, "*", "#%s# (%s) +%s %s %s (%s)", dcc[idx].nick,
  113. dcc[idx].u.chat->con_chan, cmd, s, chan->dname, par);
  114. dprintf(idx, "New %s %s: %s (%s)\n", chan->dname, cmd, s, par);
  115. }
  116. #ifdef LEAF
  117. if (type == 'e' || type == 'I')
  118. add_mode(chan, '+', type, s);
  119. /* Avoid unnesessary modes if you got +dynamicbans
  120. */
  121. else
  122. check_this_ban(chan, s, sticky);
  123. #endif /* LEAF */
  124. } else {
  125. u_addmask(type, NULL, s, dcc[idx].nick, par, expire_time ? now + expire_time : 0, 0);
  126. if (par[0] == '*') {
  127. sticky = 1;
  128. par++;
  129. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +%s %s (%s) (sticky)", dcc[idx].nick, cmd, s, par);
  130. dprintf(idx, "New sticky %s: %s (%s)\n", cmd, s, par);
  131. } else {
  132. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +%s %s (%s)", dcc[idx].nick, cmd, s, par);
  133. dprintf(idx, "New %s: %s (%s)\n", cmd, s, par);
  134. }
  135. #ifdef LEAF
  136. for (chan = chanset; chan != NULL; chan = chan->next) {
  137. if (type == 'b')
  138. check_this_ban(chan, s, sticky);
  139. else
  140. add_mode(chan, '+', type, s);
  141. }
  142. #endif /* LEAF */
  143. }
  144. }
  145. static void cmd_pls_ban(int idx, char *par)
  146. {
  147. cmd_pls_mask('b', idx, par);
  148. }
  149. static void cmd_pls_exempt(int idx, char *par)
  150. {
  151. if (!use_exempts) {
  152. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  153. return;
  154. }
  155. cmd_pls_mask('e', idx, par);
  156. }
  157. static void cmd_pls_invite(int idx, char *par)
  158. {
  159. if (!use_invites) {
  160. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  161. return;
  162. }
  163. cmd_pls_mask('I', idx, par);
  164. }
  165. static void cmd_mns_mask(char type, int idx, char *par)
  166. {
  167. int i = 0, j;
  168. struct chanset_t *chan = NULL;
  169. char s[UHOSTLEN] = "", *who = NULL, *chname = NULL, *cmd = NULL, *mask = NULL;
  170. masklist *m = NULL;
  171. cmd = type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite";
  172. if (!par[0]) {
  173. dprintf(idx, "Usage: -%s <hostmask> [channel]\n", cmd);
  174. return;
  175. }
  176. who = newsplit(&par);
  177. if (par[0] && strchr(CHANMETA, par[0]))
  178. chname = newsplit(&par);
  179. else
  180. chname = dcc[idx].u.chat->con_chan;
  181. if (chname || !(dcc[idx].user->flags & USER_MASTER)) {
  182. if (!chname)
  183. chname = dcc[idx].u.chat->con_chan;
  184. get_user_flagrec(dcc[idx].user, &user, chname);
  185. if (strchr(CHANMETA, chname[0]) && private(user, findchan_by_dname(chname), PRIV_OP)) {
  186. dprintf(idx, "No such channel.\n");
  187. return;
  188. }
  189. if (!chk_op(user, findchan_by_dname(chname)))
  190. return;
  191. }
  192. strncpyz(s, who, sizeof s);
  193. i = u_delmask(type, NULL, s, (dcc[idx].user->flags & USER_MASTER));
  194. if (i > 0) {
  195. if (lastdeletedmask)
  196. mask = lastdeletedmask;
  197. else
  198. mask = s;
  199. putlog(LOG_CMDS, "*", "#%s# -%s %s", dcc[idx].nick, cmd, mask);
  200. dprintf(idx, "%s %s: %s\n", "Removed", cmd, s);
  201. #ifdef LEAF
  202. for (chan = chanset; chan != NULL; chan = chan->next)
  203. add_mode(chan, '-', type, mask);
  204. #endif /* LEAF */
  205. return;
  206. }
  207. /* Channel-specific ban? */
  208. if (chname)
  209. chan = findchan_by_dname(chname);
  210. if (chan) {
  211. m = type == 'b' ? chan->channel.ban : type == 'e' ? chan->channel.exempt : chan->channel.invite;
  212. if ((i = atoi(who)) > 0) {
  213. egg_snprintf(s, sizeof s, "%d", i);
  214. j = u_delmask(type, chan, s, 1);
  215. if (j > 0) {
  216. if (lastdeletedmask)
  217. mask = lastdeletedmask;
  218. else
  219. mask = s;
  220. putlog(LOG_CMDS, "*", "#%s# (%s) -%s %s", dcc[idx].nick, chan->dname, cmd, mask);
  221. dprintf(idx, "Removed %s channel %s: %s\n", chan->dname, cmd, mask);
  222. #ifdef LEAF
  223. add_mode(chan, '-', type, mask);
  224. #endif /* LEAF */
  225. return;
  226. }
  227. i = 0;
  228. for (; m && m->mask && m->mask[0]; m = m->next) {
  229. if ((!u_equals_mask(type == 'b' ? global_bans : type == 'e' ? global_exempts :
  230. global_invites, m->mask)) &&
  231. (!u_equals_mask(type == 'b' ? chan->bans : type == 'e' ? chan->exempts :
  232. chan->invites, m->mask))) {
  233. i++;
  234. if (i == -j) {
  235. #ifdef LEAF
  236. add_mode(chan, '-', type, m->mask);
  237. #endif /* LEAF */
  238. dprintf(idx, "%s %s '%s' on %s.\n", "Removed", cmd, m->mask, chan->dname);
  239. putlog(LOG_CMDS, "*", "#%s# (%s) -%s %s [on channel]", dcc[idx].nick, chan->dname, cmd, who);
  240. return;
  241. }
  242. }
  243. }
  244. } else {
  245. j = u_delmask(type, chan, who, 1);
  246. if (j > 0) {
  247. putlog(LOG_CMDS, "*", "#%s# (%s) -%s %s", dcc[idx].nick, dcc[idx].u.chat->con_chan, cmd, who);
  248. dprintf(idx, "Removed %s channel %s: %s\n", chname, cmd, who);
  249. #ifdef LEAF
  250. add_mode(chan, '-', type, who);
  251. #endif /* LEAF */
  252. return;
  253. }
  254. for (; m && m->mask && m->mask[0]; m = m->next) {
  255. if (!rfc_casecmp(m->mask, who)) {
  256. #ifdef LEAF
  257. add_mode(chan, '-', type, m->mask);
  258. #endif /* LEAF */
  259. dprintf(idx, "%s %s '%s' on %s.\n", "Removed", cmd, m->mask, chan->dname);
  260. putlog(LOG_CMDS, "*", "#%s# (%s) -%s %s [on channel]", dcc[idx].nick, chan->dname, cmd, who);
  261. return;
  262. }
  263. }
  264. }
  265. }
  266. dprintf(idx, "No such %s.\n", cmd);
  267. }
  268. static void cmd_mns_ban(int idx, char *par)
  269. {
  270. cmd_mns_mask('b', idx, par);
  271. }
  272. static void cmd_mns_exempt(int idx, char *par)
  273. {
  274. if (!use_exempts) {
  275. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  276. return;
  277. }
  278. cmd_mns_mask('e', idx, par);
  279. }
  280. static void cmd_mns_invite(int idx, char *par)
  281. {
  282. if (!use_invites) {
  283. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  284. return;
  285. }
  286. cmd_mns_mask('I', idx, par);
  287. }
  288. static void cmd_bans(int idx, char *par)
  289. {
  290. if (!egg_strcasecmp(par, "all")) {
  291. putlog(LOG_CMDS, "*", "#%s# bans all", dcc[idx].nick);
  292. tell_bans(idx, 1, "");
  293. } else {
  294. putlog(LOG_CMDS, "*", "#%s# bans %s", dcc[idx].nick, par);
  295. tell_bans(idx, 0, par);
  296. }
  297. }
  298. static void cmd_exempts(int idx, char *par)
  299. {
  300. if (!use_exempts) {
  301. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  302. return;
  303. }
  304. if (!egg_strcasecmp(par, "all")) {
  305. putlog(LOG_CMDS, "*", "#%s# exempts all", dcc[idx].nick);
  306. tell_exempts(idx, 1, "");
  307. } else {
  308. putlog(LOG_CMDS, "*", "#%s# exempts %s", dcc[idx].nick, par);
  309. tell_exempts(idx, 0, par);
  310. }
  311. }
  312. static void cmd_invites(int idx, char *par)
  313. {
  314. if (!use_invites) {
  315. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  316. return;
  317. }
  318. if (!egg_strcasecmp(par, "all")) {
  319. putlog(LOG_CMDS, "*", "#%s# invites all", dcc[idx].nick);
  320. tell_invites(idx, 1, "");
  321. } else {
  322. putlog(LOG_CMDS, "*", "#%s# invites %s", dcc[idx].nick, par);
  323. tell_invites(idx, 0, par);
  324. }
  325. }
  326. static void cmd_info(int idx, char *par)
  327. {
  328. char s[512] = "", *chname = NULL, *s1 = NULL;
  329. int locked = 0;
  330. if (!use_info) {
  331. dprintf(idx, "Info storage is turned off.\n");
  332. return;
  333. }
  334. s1 = get_user(&USERENTRY_INFO, dcc[idx].user);
  335. if (s1 && s1[0] == '@')
  336. locked = 1;
  337. if (par[0] && strchr(CHANMETA, par[0])) {
  338. chname = newsplit(&par);
  339. if (!findchan_by_dname(chname)) {
  340. dprintf(idx, "No such channel.\n");
  341. return;
  342. }
  343. get_handle_chaninfo(dcc[idx].nick, chname, s);
  344. if (s[0] == '@')
  345. locked = 1;
  346. s1 = s;
  347. } else
  348. chname = 0;
  349. if (!par[0]) {
  350. if (s1 && s1[0] == '@')
  351. s1++;
  352. if (s1 && s1[0]) {
  353. if (chname) {
  354. dprintf(idx, "Info on %s: %s\n", chname, s1);
  355. dprintf(idx, "Use 'info %s none' to remove it.\n", chname);
  356. } else {
  357. dprintf(idx, "Default info: %s\n", s1);
  358. dprintf(idx, "Use 'info none' to remove it.\n");
  359. }
  360. } else
  361. dprintf(idx, "No info has been set for you.\n");
  362. putlog(LOG_CMDS, "*", "#%s# info %s", dcc[idx].nick, chname ? chname : "");
  363. return;
  364. }
  365. if (locked && !(dcc[idx].user && (dcc[idx].user->flags & USER_MASTER))) {
  366. dprintf(idx, "Your info line is locked. Sorry.\n");
  367. return;
  368. }
  369. if (!egg_strcasecmp(par, "none")) {
  370. if (chname) {
  371. par[0] = 0;
  372. set_handle_chaninfo(userlist, dcc[idx].nick, chname, NULL);
  373. dprintf(idx, "Removed your info line on %s.\n", chname);
  374. putlog(LOG_CMDS, "*", "#%s# info %s none", dcc[idx].nick, chname);
  375. } else {
  376. set_user(&USERENTRY_INFO, dcc[idx].user, NULL);
  377. dprintf(idx, "Removed your default info line.\n");
  378. putlog(LOG_CMDS, "*", "#%s# info none", dcc[idx].nick);
  379. }
  380. return;
  381. }
  382. /* if (par[0] == '@') This is stupid, and prevents a users info from being locked */
  383. /* par++; without .tcl, or a tcl script, aka, 'half-assed' -poptix 4Jun01 */
  384. if (chname) {
  385. set_handle_chaninfo(userlist, dcc[idx].nick, chname, par);
  386. dprintf(idx, "Your info on %s is now: %s\n", chname, par);
  387. putlog(LOG_CMDS, "*", "#%s# info %s ...", dcc[idx].nick, chname);
  388. } else {
  389. set_user(&USERENTRY_INFO, dcc[idx].user, par);
  390. dprintf(idx, "Your default info is now: %s\n", par);
  391. putlog(LOG_CMDS, "*", "#%s# info ...", dcc[idx].nick);
  392. }
  393. }
  394. static void cmd_chinfo(int idx, char *par)
  395. {
  396. char *handle = NULL, *chname = NULL;
  397. struct userrec *u1 = NULL;
  398. if (!use_info) {
  399. dprintf(idx, "Info storage is turned off.\n");
  400. return;
  401. }
  402. handle = newsplit(&par);
  403. if (!handle[0]) {
  404. dprintf(idx, "Usage: chinfo <handle> [channel] <new-info>\n");
  405. return;
  406. }
  407. u1 = get_user_by_handle(userlist, handle);
  408. if (!u1) {
  409. dprintf(idx, "No such user.\n");
  410. return;
  411. }
  412. if (par[0] && strchr(CHANMETA, par[0])) {
  413. chname = newsplit(&par);
  414. if (!findchan_by_dname(chname)) {
  415. dprintf(idx, "No such channel.\n");
  416. return;
  417. }
  418. } else
  419. chname = 0;
  420. if (u1->bot && !(dcc[idx].user->flags & USER_MASTER)) {
  421. dprintf(idx, "You have to be master to change bots info.\n");
  422. return;
  423. }
  424. if ((u1->flags & USER_OWNER) && !(dcc[idx].user->flags & USER_OWNER)) {
  425. dprintf(idx, "You can't change info for the bot owner.\n");
  426. return;
  427. }
  428. if (chname) {
  429. get_user_flagrec(dcc[idx].user, &user, chname);
  430. get_user_flagrec(u1, &victim, chname);
  431. if ((chan_owner(victim) || glob_owner(victim)) &&
  432. !(glob_owner(user) || chan_owner(user))) {
  433. dprintf(idx, "You can't change info for the channel owner.\n");
  434. return;
  435. }
  436. }
  437. putlog(LOG_CMDS, "*", "#%s# chinfo %s %s %s", dcc[idx].nick, handle, chname ? chname : par, chname ? par : "");
  438. if (!egg_strcasecmp(par, "none"))
  439. par[0] = 0;
  440. if (chname) {
  441. set_handle_chaninfo(userlist, handle, chname, par);
  442. if (par[0] == '@')
  443. dprintf(idx, "New info (LOCKED) for %s on %s: %s\n", handle, chname,
  444. &par[1]);
  445. else if (par[0])
  446. dprintf(idx, "New info for %s on %s: %s\n", handle, chname, par);
  447. else
  448. dprintf(idx, "Wiped info for %s on %s\n", handle, chname);
  449. } else {
  450. set_user(&USERENTRY_INFO, u1, par[0] ? par : NULL);
  451. if (par[0] == '@')
  452. dprintf(idx, "New default info (LOCKED) for %s: %s\n", handle, &par[1]);
  453. else if (par[0])
  454. dprintf(idx, "New default info for %s: %s\n", handle, par);
  455. else
  456. dprintf(idx, "Wiped default info for %s\n", handle);
  457. }
  458. }
  459. static void cmd_slowjoin(int idx, char *par)
  460. {
  461. int intvl = 0, delay = 0, count = 1;
  462. char *chname = NULL, *p = NULL, buf[2048] = "", buf2[1048] = "";
  463. struct chanset_t *chan = NULL;
  464. tand_t *bot = NULL;
  465. /* slowjoin #chan 60 */
  466. putlog(LOG_CMDS, "*", "#%s# slowjoin %s", dcc[idx].nick, par);
  467. chname = newsplit(&par);
  468. p = newsplit(&par);
  469. intvl = atoi(p);
  470. if (!chname[0] || !p[0]) {
  471. dprintf(idx, "Usage: slowjoin <channel> <interval-seconds> [channel options]\n");
  472. return;
  473. }
  474. if (intvl < 10) {
  475. dprintf(idx, "Interval must be at least 10 seconds\n");
  476. return;
  477. }
  478. if ((chan = findchan_by_dname(chname))) {
  479. dprintf(idx, "Already on %s\n", chan->dname);
  480. return;
  481. }
  482. if (!strchr(CHANMETA, chname[0])) {
  483. dprintf(idx, "Invalid channel name\n");
  484. return;
  485. }
  486. strcpy(buf, "+inactive ");
  487. if (par[0])
  488. strncat(buf, par, sizeof(buf));
  489. if (channel_add(NULL, chname, buf) == ERROR) {
  490. dprintf(idx, "Invalid channel.\n");
  491. return;
  492. }
  493. chan = findchan_by_dname(chname);
  494. if (!chan) {
  495. dprintf(idx, "Hmmm... Channel didn't get added. Weird *shrug*\n");
  496. return;
  497. }
  498. sprintf(buf2, "cjoin %s %s", chan->dname, buf);
  499. putallbots(buf2);
  500. #ifdef HUB
  501. count=0;
  502. #else /* !HUB */
  503. count=1;
  504. #endif /* HUB */
  505. for (bot = tandbot; bot; bot = bot->next) {
  506. struct userrec *ubot = NULL;
  507. char tmp[100] = "";
  508. ubot = get_user_by_handle(userlist, bot->bot);
  509. if (ubot) {
  510. /* Variation: 60 secs intvl should be 60 +/- 15 */
  511. if (bot_hublevel(ubot) < 999) {
  512. sprintf(tmp, "sj %s 0\n", chan->dname);
  513. } else {
  514. int v = (random() % (intvl / 2)) - (intvl / 4);
  515. delay += intvl;
  516. sprintf(tmp, "sj %s %i\n", chan->dname, delay + v);
  517. count++;
  518. }
  519. putbot(ubot->handle, tmp);
  520. }
  521. }
  522. dprintf(idx, "%i bots joining %s during the next %i seconds\n", count, chan->dname, delay);
  523. chan->status &= ~CHAN_INACTIVE;
  524. #ifdef LEAF
  525. if (shouldjoin(chan))
  526. dprintf(DP_MODE, "JOIN %s %s\n", chan->name, chan->key_prot);
  527. #endif /* LEAF */
  528. }
  529. static void cmd_slowpart(int idx, char *par)
  530. {
  531. int intvl = 0, delay = 0, count = 1;
  532. char *chname = NULL, *p = NULL;
  533. struct chanset_t *chan = NULL;
  534. tand_t *bot = NULL;
  535. /* slowpart #chan 60 */
  536. putlog(LOG_CMDS, "*", "#%s# slowpart %s", dcc[idx].nick, par);
  537. chname = newsplit(&par);
  538. p = newsplit(&par);
  539. intvl = atoi(p);
  540. if (!chname[0] || !p[0]) {
  541. dprintf(idx, "Usage: slowpart <channel> <interval-seconds>\n");
  542. return;
  543. }
  544. if (intvl < 10) {
  545. dprintf(idx, "Interval must be at least 10 seconds\n");
  546. return;
  547. }
  548. if (!(chan = findchan_by_dname(chname))) {
  549. dprintf(idx, "Not on %s\n", chan->dname);
  550. return;
  551. }
  552. remove_channel(chan);
  553. #ifdef HUB
  554. write_userfile(-1);
  555. #endif /* HUB */
  556. dprintf(idx, "Channel %s removed from the bot.\n", chname);
  557. dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
  558. if (findchan_by_dname(chname)) {
  559. dprintf(idx, "Hmmm... Channel didn't get removed. Weird *shrug*\n");
  560. return;
  561. }
  562. #ifdef HUB
  563. count = 0;
  564. #else /* !HUB */
  565. count = 1;
  566. #endif /* HUB */
  567. for (bot = tandbot; bot; bot = bot->next) {
  568. char tmp[100] = "";
  569. struct userrec *ubot = NULL;
  570. ubot = get_user_by_handle(userlist, bot->bot);
  571. /* Variation: 60 secs intvl should be 60 +/- 15 */
  572. if (ubot) {
  573. if (bot_hublevel(ubot) < 999) {
  574. sprintf(tmp, "sp %s 0\n", chname);
  575. } else {
  576. int v = (random() % (intvl / 2)) - (intvl / 4);
  577. delay += intvl;
  578. sprintf(tmp, "sp %s %i\n", chname, delay + v);
  579. count++;
  580. }
  581. putbot(ubot->handle, tmp);
  582. }
  583. }
  584. dprintf(idx, "%i bots parting %s during the next %i seconds\n", count, chname, delay);
  585. #ifdef LEAF
  586. dprintf(DP_MODE, "PART %s\n", chname);
  587. #endif /* LEAF */
  588. }
  589. static void cmd_stick_yn(int idx, char *par, int yn)
  590. {
  591. int i = 0, j;
  592. struct chanset_t *chan = NULL;
  593. char *stick_type = NULL, s[UHOSTLEN] = "", chname[81] = "";
  594. stick_type = newsplit(&par);
  595. strncpyz(s, newsplit(&par), sizeof s);
  596. strncpyz(chname, newsplit(&par), sizeof chname);
  597. if (egg_strcasecmp(stick_type, "exempt") &&
  598. egg_strcasecmp(stick_type, "invite") &&
  599. egg_strcasecmp(stick_type, "ban")) {
  600. strncpyz(chname, s, sizeof chname);
  601. strncpyz(s, stick_type, sizeof s);
  602. }
  603. if (!s[0]) {
  604. dprintf(idx, "Usage: %sstick [ban/exempt/invite] <hostmask or number> [channel]\n", yn ? "" : "un");
  605. return;
  606. }
  607. /* Now deal with exemptions */
  608. if (!egg_strcasecmp(stick_type, "exempt")) {
  609. if (!use_exempts) {
  610. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  611. return;
  612. }
  613. if (!chname[0]) {
  614. i = u_setsticky_exempt(NULL, s,
  615. (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
  616. if (i > 0) {
  617. putlog(LOG_CMDS, "*", "#%s# %sstick exempt %s",
  618. dcc[idx].nick, yn ? "" : "un", s);
  619. dprintf(idx, "%stuck exempt: %s\n", yn ? "S" : "Uns", s);
  620. return;
  621. }
  622. strncpyz(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  623. }
  624. /* Channel-specific exempt? */
  625. if (!(chan = findchan_by_dname(chname))) {
  626. dprintf(idx, "No such channel.\n");
  627. return;
  628. }
  629. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  630. if (private(user, chan, PRIV_OP)) {
  631. dprintf(idx, "No such channel.\n");
  632. return;
  633. }
  634. if (str_isdigit(s)) {
  635. /* substract the numer of global exempts to get the number of the channel exempt */
  636. j = u_setsticky_exempt(NULL, s, -1);
  637. if (j < 0)
  638. egg_snprintf(s, sizeof s, "%d", -j);
  639. }
  640. j = u_setsticky_exempt(chan, s, yn);
  641. if (j > 0) {
  642. putlog(LOG_CMDS, "*", "#%s# %sstick exempt %s %s", dcc[idx].nick,
  643. yn ? "" : "un", s, chname);
  644. dprintf(idx, "%stuck %s exempt: %s\n", yn ? "S" : "Uns", chname, s);
  645. return;
  646. }
  647. dprintf(idx, "No such exempt.\n");
  648. return;
  649. /* Now the invites */
  650. } else if (!egg_strcasecmp(stick_type, "invite")) {
  651. if (!use_invites) {
  652. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  653. return;
  654. }
  655. if (!chname[0]) {
  656. i = u_setsticky_invite(NULL, s,
  657. (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
  658. if (i > 0) {
  659. putlog(LOG_CMDS, "*", "#%s# %sstick invite %s",
  660. dcc[idx].nick, yn ? "" : "un", s);
  661. dprintf(idx, "%stuck invite: %s\n", yn ? "S" : "Uns", s);
  662. return;
  663. }
  664. strncpyz(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  665. }
  666. /* Channel-specific invite? */
  667. if (!(chan = findchan_by_dname(chname))) {
  668. dprintf(idx, "No such channel.\n");
  669. return;
  670. }
  671. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  672. if (private(user, chan, PRIV_OP)) {
  673. dprintf(idx, "No such channel.\n");
  674. return;
  675. }
  676. if (str_isdigit(s)) {
  677. /* substract the numer of global invites to get the number of the channel invite */
  678. j = u_setsticky_invite(NULL, s, -1);
  679. if (j < 0)
  680. egg_snprintf(s, sizeof s, "%d", -j);
  681. }
  682. j = u_setsticky_invite(chan, s, yn);
  683. if (j > 0) {
  684. putlog(LOG_CMDS, "*", "#%s# %sstick invite %s %s", dcc[idx].nick, yn ? "" : "un", s, chname);
  685. dprintf(idx, "%stuck %s invite: %s\n", yn ? "S" : "Uns", chname, s);
  686. return;
  687. }
  688. dprintf(idx, "No such invite.\n");
  689. return;
  690. }
  691. if (!chname[0]) {
  692. i = u_setsticky_ban(NULL, s,
  693. (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
  694. if (i > 0) {
  695. putlog(LOG_CMDS, "*", "#%s# %sstick ban %s", dcc[idx].nick, yn ? "" : "un", s);
  696. dprintf(idx, "%stuck ban: %s\n", yn ? "S" : "Uns", s);
  697. #ifdef LEAF
  698. {
  699. struct chanset_t *achan = NULL;
  700. for (achan = chanset; achan != NULL; achan = achan->next)
  701. check_this_ban(achan, s, yn);
  702. }
  703. #endif /* LEAF */
  704. return;
  705. }
  706. strncpyz(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  707. }
  708. /* Channel-specific ban? */
  709. if (!(chan = findchan_by_dname(chname))) {
  710. dprintf(idx, "No such channel.\n");
  711. return;
  712. }
  713. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  714. if (private(user, chan, PRIV_OP)) {
  715. dprintf(idx, "No such channel.\n");
  716. return;
  717. }
  718. if (str_isdigit(s)) {
  719. /* substract the numer of global bans to get the number of the channel ban */
  720. j = u_setsticky_ban(NULL, s, -1);
  721. if (j < 0)
  722. egg_snprintf(s, sizeof s, "%d", -j);
  723. }
  724. j = u_setsticky_ban(chan, s, yn);
  725. if (j > 0) {
  726. putlog(LOG_CMDS, "*", "#%s# %sstick ban %s %s", dcc[idx].nick, yn ? "" : "un", s, chname);
  727. dprintf(idx, "%stuck %s ban: %s\n", yn ? "S" : "Uns", chname, s);
  728. #ifdef LEAF
  729. check_this_ban(chan, s, yn);
  730. #endif /* LEAF */
  731. return;
  732. }
  733. dprintf(idx, "No such ban.\n");
  734. }
  735. static void cmd_stick(int idx, char *par)
  736. {
  737. cmd_stick_yn(idx, par, 1);
  738. }
  739. static void cmd_unstick(int idx, char *par)
  740. {
  741. cmd_stick_yn(idx, par, 0);
  742. }
  743. static void cmd_pls_chrec(int idx, char *par)
  744. {
  745. char *nick = NULL, *chn = NULL;
  746. struct chanset_t *chan = NULL;
  747. struct userrec *u1 = NULL;
  748. struct chanuserrec *chanrec = NULL;
  749. if (!par[0]) {
  750. dprintf(idx, "Usage: +chrec <user> [channel]\n");
  751. return;
  752. }
  753. nick = newsplit(&par);
  754. u1 = get_user_by_handle(userlist, nick);
  755. if (!u1) {
  756. dprintf(idx, "No such user.\n");
  757. return;
  758. }
  759. if (!par[0])
  760. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  761. else {
  762. chn = newsplit(&par);
  763. chan = findchan_by_dname(chn);
  764. }
  765. if (!chan) {
  766. dprintf(idx, "No such channel.\n");
  767. return;
  768. }
  769. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  770. get_user_flagrec(u1, &victim, chan->dname);
  771. if (private(user, chan, PRIV_OP)) {
  772. dprintf(idx, "No such channel.\n");
  773. return;
  774. }
  775. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  776. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  777. (glob_owner(victim) && !glob_owner(user))) {
  778. dprintf(idx, "You have no permission to do that.\n");
  779. return;
  780. }
  781. chanrec = get_chanrec(u1, chan->dname);
  782. if (chanrec) {
  783. dprintf(idx, "User %s already has a channel record for %s.\n",
  784. nick, chan->dname);
  785. return;
  786. }
  787. putlog(LOG_CMDS, "*", "#%s# +chrec %s %s", dcc[idx].nick, nick, chan->dname);
  788. add_chanrec(u1, chan->dname);
  789. dprintf(idx, "Added %s channel record for %s.\n", chan->dname, nick);
  790. }
  791. static void cmd_mns_chrec(int idx, char *par)
  792. {
  793. char *nick = NULL, *chn = NULL;
  794. struct userrec *u1 = NULL;
  795. struct chanuserrec *chanrec = NULL;
  796. if (!par[0]) {
  797. dprintf(idx, "Usage: -chrec <user> [channel]\n");
  798. return;
  799. }
  800. nick = newsplit(&par);
  801. u1 = get_user_by_handle(userlist, nick);
  802. if (!u1) {
  803. dprintf(idx, "No such user.\n");
  804. return;
  805. }
  806. if (!par[0]) {
  807. struct chanset_t *chan;
  808. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  809. if (chan)
  810. chn = chan->dname;
  811. else {
  812. dprintf(idx, "Invalid console channel.\n");
  813. return;
  814. }
  815. } else
  816. chn = newsplit(&par);
  817. get_user_flagrec(dcc[idx].user, &user, chn);
  818. get_user_flagrec(u1, &victim, chn);
  819. if (private(user, findchan_by_dname(chn), PRIV_OP)) {
  820. dprintf(idx, "No such channel.\n");
  821. return;
  822. }
  823. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  824. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  825. (glob_owner(victim) && !glob_owner(user))) {
  826. dprintf(idx, "You have no permission to do that.\n");
  827. return;
  828. }
  829. chanrec = get_chanrec(u1, chn);
  830. if (!chanrec) {
  831. dprintf(idx, "User %s doesn't have a channel record for %s.\n", nick, chn);
  832. return;
  833. }
  834. putlog(LOG_CMDS, "*", "#%s# -chrec %s %s", dcc[idx].nick, nick, chn);
  835. del_chanrec(u1, chn);
  836. dprintf(idx, "Removed %s channel record from %s.\n", chn, nick);
  837. }
  838. static void cmd_cycle(int idx, char *par)
  839. {
  840. char *chname = NULL;
  841. char buf2[1024] = "";
  842. int delay = 10;
  843. struct chanset_t *chan = NULL;
  844. putlog(LOG_CMDS, "*", "#%s# cycle %s", dcc[idx].nick, par);
  845. if (!par[0]) {
  846. dprintf(idx, "Usage: cycle [%s]<channel> [delay]\n", CHANMETA);
  847. dprintf(idx, "rejoin delay defaults to '10'\n");
  848. return;
  849. }
  850. chname = newsplit(&par);
  851. chan = findchan_by_dname(chname);
  852. if (!chan) {
  853. dprintf(idx, "%s it not a valid channel.\n", chname);
  854. return;
  855. }
  856. if (par[0])
  857. delay = atoi(newsplit(&par));
  858. sprintf(buf2, "cycle %s %d", chname, delay); /* this just makes the bot PART */
  859. putallbots(buf2);
  860. #ifdef LEAF
  861. do_chanset(NULL, chan, "+inactive", DO_LOCAL);
  862. dprintf(DP_SERVER, "PART %s\n", chan->name);
  863. chan->channel.jointime = ((now + delay) - server_lag);
  864. #endif /* LEAF */
  865. }
  866. static void cmd_down(int idx, char *par)
  867. {
  868. char *chname = NULL, buf2[1024] = "";
  869. struct chanset_t *chan = NULL;
  870. putlog(LOG_CMDS, "*", "#%s# down %s", dcc[idx].nick, par);
  871. if (!par[0]) {
  872. dprintf(idx, "Usage: down [%s]<channel>\n", CHANMETA);
  873. return;
  874. }
  875. chname = newsplit(&par);
  876. chan = findchan_by_dname(chname);
  877. if (!chan) {
  878. dprintf(idx, "%s it not a valid channel.\n", chname);
  879. return;
  880. }
  881. sprintf(buf2, "down %s", chan->dname);
  882. putallbots(buf2);
  883. #ifdef LEAF
  884. add_mode(chan, '-', 'o', botname);
  885. chan->channel.no_op = (now + 10);
  886. #endif /* LEAF */
  887. }
  888. static void pls_chan(int idx, char *par, char *bot)
  889. {
  890. char *chname = NULL, result[1024] = "", buf[2048] = "";
  891. struct chanset_t *chan = NULL;
  892. if (!bot)
  893. putlog(LOG_CMDS, "*", "#%s# +chan %s", dcc[idx].nick, par);
  894. if (!par[0]) {
  895. dprintf(idx, "Usage: +chan [%s]<channel> [options]\n", CHANMETA);
  896. return;
  897. }
  898. chname = newsplit(&par);
  899. sprintf(buf, "cjoin %s %s %s", chname, bot ? bot : "*", par); /* +chan makes all bots join */
  900. if (!bot && findchan_by_dname(chname)) {
  901. putallbots(buf);
  902. dprintf(idx, "That channel already exists!\n");
  903. return;
  904. } else if ((chan = findchan(chname)) && !bot) {
  905. putallbots(buf);
  906. dprintf(idx, "That channel already exists as %s!\n", chan->dname);
  907. return;
  908. } else if (strchr(CHANMETA, chname[0]) == NULL) {
  909. dprintf(idx, "Invalid channel prefix.\n");
  910. return;
  911. } else if (strchr(chname, ',') != NULL) {
  912. dprintf(idx, "Invalid channel name.\n");
  913. return;
  914. }
  915. if (!chan && !findchan_by_dname(chname) && channel_add(result, chname, par) == ERROR) {
  916. dprintf(idx, "Invalid channel or channel options.\n");
  917. if (result[0])
  918. dprintf(idx, "%s\n", result);
  919. } else {
  920. if ((chan = findchan_by_dname(chname))) {
  921. if (!bot) {
  922. char tmp[51] = "";
  923. sprintf(tmp, "addedby %s addedts %li", dcc[idx].nick, now);
  924. if (buf[0])
  925. sprintf(buf, "%s %s", buf, tmp);
  926. else
  927. sprintf(buf, "%s", tmp);
  928. do_chanset(NULL, chan, tmp, DO_LOCAL);
  929. dprintf(idx, "Channel %s added to the botnet.\n", chname);
  930. } else {
  931. dprintf(idx, "Channel %s added to the bot: %s\n", chname, bot);
  932. }
  933. putallbots(buf);
  934. }
  935. #ifdef HUB
  936. write_userfile(-1);
  937. #endif /* HUB */
  938. }
  939. }
  940. static void cmd_pls_chan(int idx, char *par)
  941. {
  942. pls_chan(idx, par, NULL);
  943. }
  944. static void cmd_botjoin(int idx, char *par)
  945. {
  946. char *bot = NULL;
  947. struct userrec *botu = NULL;
  948. putlog(LOG_CMDS, "*", "#%s# botjoin %s", dcc[idx].nick, par);
  949. if (!par[0]) {
  950. dprintf(idx, "Usage: botjoin <bot> [%s]<channel> [options]\n", CHANMETA);
  951. return;
  952. }
  953. bot = newsplit(&par);
  954. botu = get_user_by_handle(userlist, bot);
  955. if (botu && botu->bot) {
  956. pls_chan(idx, par, bot);
  957. } else {
  958. dprintf(idx, "Error: '%s' is not a bot.\n", bot);
  959. }
  960. }
  961. static void mns_chan(int idx, char *par, char *bot)
  962. {
  963. char *chname = NULL, buf2[1024] = "";
  964. struct chanset_t *chan = NULL;
  965. int i;
  966. if (!bot)
  967. putlog(LOG_CMDS, "*", "#%s# -chan %s", dcc[idx].nick, par);
  968. if (!par[0]) {
  969. dprintf(idx, "Usage: -chan [%s]<channel>\n", CHANMETA);
  970. return;
  971. }
  972. chname = newsplit(&par);
  973. sprintf(buf2, "cpart %s %s", chname, bot ? bot : "*");
  974. if (bot) /* bot will just set it +inactive */
  975. putbot(bot, buf2);
  976. else
  977. putallbots(buf2);
  978. chan = findchan_by_dname(chname);
  979. if (!chan) {
  980. if ((chan = findchan(chname)))
  981. dprintf(idx, "That channel exists with a short name of %s, use that.\n", chan->dname);
  982. else
  983. dprintf(idx, "That channel doesn't exist!\n");
  984. return;
  985. }
  986. if (!bot) {
  987. for (i = 0; i < dcc_total; i++)
  988. if ((dcc[i].type->flags & DCT_CHAT) && !rfc_casecmp(dcc[i].u.chat->con_chan, chan->dname)) {
  989. dprintf(i, "%s is no longer a valid channel, changing your console to '*'\n", chname);
  990. strcpy(dcc[i].u.chat->con_chan, "*");
  991. }
  992. remove_channel(chan);
  993. #ifdef HUB
  994. write_userfile(-1);
  995. #endif /* HUB */
  996. dprintf(idx, "Channel %s removed from the botnet.\n", chname);
  997. dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
  998. } else
  999. dprintf(idx, "Channel %s removed from the bot: %s\n", chname, bot);
  1000. }
  1001. static void cmd_mns_chan(int idx, char *par)
  1002. {
  1003. mns_chan(idx, par, NULL);
  1004. }
  1005. static void cmd_botpart(int idx, char *par)
  1006. {
  1007. char *bot = NULL;
  1008. struct userrec *botu = NULL;
  1009. putlog(LOG_CMDS, "*", "#%s# botpart %s", dcc[idx].nick, par);
  1010. if (!par[0]) {
  1011. dprintf(idx, "Usage: botpart <bot> [%s]<channel> [options]\n", CHANMETA);
  1012. return;
  1013. }
  1014. bot = newsplit(&par);
  1015. botu = get_user_by_handle(userlist, bot);
  1016. if (botu && botu->bot) {
  1017. mns_chan(idx, par, bot);
  1018. } else {
  1019. dprintf(idx, "Error: '%s' is not a bot.\n", bot);
  1020. }
  1021. }
  1022. /* thanks Excelsior */
  1023. #define FLAG_COLS 4
  1024. void show_flag(int idx, char *work, int *cnt, const char *name, unsigned int state)
  1025. {
  1026. char tmp[101] = "", chr_state[15] = "";
  1027. /* empty buffer if no (char *) name */
  1028. if (((*cnt) < (FLAG_COLS - 1)) && (!name || (name && !name[0]))) (*cnt) = (FLAG_COLS - 1);
  1029. (*cnt)++;
  1030. if (*cnt > FLAG_COLS) {
  1031. *cnt = 1;
  1032. work[0] = 0;
  1033. }
  1034. if (!work[0])
  1035. sprintf(work, " ");
  1036. if (name && name[0]) {
  1037. chr_state[0] = 0;
  1038. if (state) {
  1039. strcat(chr_state, GREEN(idx));
  1040. strcat(chr_state, "+");
  1041. } else {
  1042. strcat(chr_state, RED(idx));
  1043. strcat(chr_state, "-");
  1044. }
  1045. strcat(chr_state, COLOR_END(idx));
  1046. egg_snprintf(tmp, sizeof tmp, "%s%-17s", chr_state, name);
  1047. strcat(work, tmp);
  1048. }
  1049. if (*cnt >= FLAG_COLS)
  1050. dprintf(idx, "%s\n", work);
  1051. }
  1052. #define INT_COLS 1
  1053. void show_int(int idx, char *work, int *cnt, const char *desc, int state, const char *yes, const char *no)
  1054. {
  1055. char tmp[101] = "", chr_state[101] = "";
  1056. egg_snprintf(chr_state, sizeof chr_state, "%d", state);
  1057. /* empty buffer if no (char *) name */
  1058. if (((*cnt) < (INT_COLS - 1)) && (!desc || (desc && !desc[0]))) (*cnt) = (INT_COLS - 1);
  1059. (*cnt)++;
  1060. if (*cnt > INT_COLS) {
  1061. *cnt = 1;
  1062. work[0] = 0;
  1063. }
  1064. if (!work[0])
  1065. sprintf(work, " ");
  1066. /* need to make next line all one char, and then put it into %-30s */
  1067. if (desc && desc[0]) {
  1068. char tmp2[50] = "", tmp3[50] = "";
  1069. strcat(tmp2, BOLD(idx));
  1070. if (state && yes) {
  1071. strcat(tmp2, yes);
  1072. strcat(tmp3, " (");
  1073. strcat(tmp3, chr_state);
  1074. strcat(tmp3, ")");
  1075. } else if (!state && no) {
  1076. strcat(tmp2, no);
  1077. strcat(tmp3, " (");
  1078. strcat(tmp3, chr_state);
  1079. strcat(tmp3, ")");
  1080. } else if ((state && !yes) || (!state && !no)) {
  1081. strcat(tmp2, chr_state);
  1082. }
  1083. strcat(tmp2, BOLD_END(idx));
  1084. egg_snprintf(tmp, sizeof tmp, "%-30s %-20s %s", desc, tmp2, (tmp3 && tmp3[0]) ? tmp3 : "");
  1085. strcat(work, tmp);
  1086. }
  1087. if (*cnt >= INT_COLS)
  1088. dprintf(idx, "%s\n", work);
  1089. }
  1090. #define SHOW_FLAG(name, state) show_flag(idx, work, &cnt, name, state)
  1091. #define SHOW_INT(desc, state, yes, no) show_int(idx, work, &cnt, desc, state, yes, no)
  1092. #define P_STR deflag == P_KICK ? "Kick" : (deflag == P_DEOP ? "Deop" : (deflag == P_DELETE ? "Remove" : NULL))
  1093. static void cmd_chaninfo(int idx, char *par)
  1094. {
  1095. char *chname = NULL, work[512] = "";
  1096. struct chanset_t *chan = NULL;
  1097. int cnt = 0;
  1098. if (!par[0]) {
  1099. chname = dcc[idx].u.chat->con_chan;
  1100. if (chname[0] == '*') {
  1101. dprintf(idx, "Your console channel is invalid.\n");
  1102. return;
  1103. }
  1104. } else {
  1105. chname = newsplit(&par);
  1106. get_user_flagrec(dcc[idx].user, &user, chname);
  1107. if (!glob_master(user) && !chan_master(user)) {
  1108. dprintf(idx, "You don't have access to %s.\n", chname);
  1109. return;
  1110. }
  1111. }
  1112. if (!(chan = findchan_by_dname(chname)))
  1113. dprintf(idx, "No such channel defined.\n");
  1114. else {
  1115. char nick[NICKLEN] = "", date[81] = "";
  1116. int deflag = 0;
  1117. if (chan->added_ts) {
  1118. egg_strftime(date, sizeof date, "%c %Z", gmtime(&(chan->added_ts)));
  1119. } else
  1120. date[0] = 0;
  1121. if (chan->added_by && chan->added_by[0])
  1122. egg_snprintf(nick, sizeof nick, "%s", chan->added_by);
  1123. else
  1124. nick[0] = 0;
  1125. putlog(LOG_CMDS, "*", "#%s# chaninfo %s", dcc[idx].nick, chname);
  1126. if (nick[0] && date[0])
  1127. dprintf(idx, "Settings for channel %s (Added %s by %s%s%s):\n", chan->dname, date, BOLD(idx), nick, BOLD_END(idx));
  1128. else
  1129. dprintf(idx, "Settings for channel %s:\n", chan->dname);
  1130. /* FIXME: SHOW_CHAR() here */
  1131. get_mode_protect(chan, work);
  1132. dprintf(idx, "Protect modes (chanmode): %s\n", work[0] ? work : "None");
  1133. dprintf(idx, "Protect topic (topic) : %s\n", chan->topic[0] ? chan->topic : "");
  1134. /* Chanchar template
  1135. * dprintf(idx, "String temp: %s\n", chan->temp[0] ? chan->temp : "NULL");
  1136. */
  1137. dprintf(idx, "Channel flags:\n");
  1138. work[0] = 0;
  1139. SHOW_FLAG("autoop", channel_autoop(chan));
  1140. SHOW_FLAG("bitch", channel_bitch(chan));
  1141. SHOW_FLAG("closed", channel_closed(chan));
  1142. SHOW_FLAG("cycle", channel_cycle(chan));
  1143. SHOW_FLAG("enforcebans", channel_enforcebans(chan));
  1144. SHOW_FLAG("fastop", channel_fastop(chan));
  1145. SHOW_FLAG("inactive", channel_inactive(chan));
  1146. SHOW_FLAG("manop", channel_manop(chan));
  1147. SHOW_FLAG("nodesynch", channel_nodesynch(chan));
  1148. SHOW_FLAG("nomop", channel_nomop(chan));
  1149. SHOW_FLAG("private", channel_private(chan));
  1150. SHOW_FLAG("protectops", channel_protectops(chan));
  1151. SHOW_FLAG("revenge", channel_revenge(chan));
  1152. SHOW_FLAG("revengebot", channel_revengebot(chan));
  1153. SHOW_FLAG("take", channel_take(chan));
  1154. SHOW_FLAG("voice", channel_voice(chan));
  1155. SHOW_FLAG("", 0);
  1156. SHOW_FLAG("dynamicbans", channel_dynamicbans(chan));
  1157. SHOW_FLAG("userbans", !channel_nouserbans(chan));
  1158. SHOW_FLAG("dynamicexempts", channel_dynamicexempts(chan));
  1159. SHOW_FLAG("userexempts", !channel_nouserexempts(chan));
  1160. SHOW_FLAG("dynamicinvites", channel_dynamicinvites(chan));
  1161. SHOW_FLAG("userinvites", !channel_nouserinvites(chan));
  1162. SHOW_FLAG("", 0);
  1163. work[0] = 0;
  1164. /* Chanflag template
  1165. * (chan->status & CHAN_TEMP) ? '+' : '-',
  1166. * also include %ctemp in dprintf.
  1167. */
  1168. work[0] = cnt = 0;
  1169. /* Chanint template
  1170. * SHOW_INT("Desc: ", integer, "YES", "NO");
  1171. */
  1172. dprintf(idx, "Channel settings:\n");
  1173. deflag = chan->bad_cookie;
  1174. SHOW_INT("Bad-cookie:" , chan->bad_cookie, P_STR, "Ignore");
  1175. SHOW_INT("Ban-time: ", chan->ban_time, NULL, "Forever");
  1176. SHOW_INT("Closed-ban: ", chan->closed_ban, NULL, "Don't!");
  1177. SHOW_INT("Closed-Private:", chan->closed_private, NULL, "Don't!");
  1178. deflag = chan->cookie_time_slack;
  1179. SHOW_INT("Cookie-time-slack:", chan->cookie_time_slack, P_STR, "Ignore");
  1180. SHOW_INT("Exempt-time: ", chan->exempt_time, NULL, "Forever");
  1181. SHOW_INT("Idle Kick after (idle-kick): ", chan->idle_kick, "", "Don't!");
  1182. SHOW_INT("Invite-time: ", chan->invite_time, NULL, "Forever");
  1183. SHOW_INT("Limit raise (limit): ", chan->limitraise, NULL, "Disabled");
  1184. deflag = chan->manop;
  1185. SHOW_INT("Manop: ", chan->manop, P_STR, "Ignore");
  1186. deflag = chan->mdop;
  1187. SHOW_INT("Mdop: ", chan->mdop, P_STR, "Ignore");
  1188. deflag = chan->mop;
  1189. SHOW_INT("Mop: ", chan->mop, P_STR, "Ignore");
  1190. SHOW_INT("Revenge-mode: ", chan->revenge_mode, NULL, NULL);
  1191. SHOW_INT("Stopnethack-mode: ", chan->stopnethack_mode, "", "Don't!");
  1192. dprintf(idx, "Flood settings: chan ctcp join kick deop nick\n");
  1193. dprintf(idx, " number: %3d %3d %3d %3d %3d %3d\n",
  1194. chan->flood_pub_thr, chan->flood_ctcp_thr,
  1195. chan->flood_join_thr, chan->flood_kick_thr,
  1196. chan->flood_deop_thr, chan->flood_nick_thr);
  1197. dprintf(idx, " time : %3d %3d %3d %3d %3d %3d\n",
  1198. chan->flood_pub_time, chan->flood_ctcp_time,
  1199. chan->flood_join_time, chan->flood_kick_time,
  1200. chan->flood_deop_time, chan->flood_nick_time);
  1201. }
  1202. }
  1203. static void cmd_chanset(int idx, char *par)
  1204. {
  1205. char *chname = NULL, result[1024] = "";
  1206. struct chanset_t *chan = NULL;
  1207. int all = 0;
  1208. putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
  1209. if (!par[0]) {
  1210. dprintf(idx, "Usage: chanset [%schannel|*] <settings>\n", CHANMETA);
  1211. return;
  1212. }
  1213. if (strlen(par) > 2 && par[0] == '*' && par[1] == ' ') {
  1214. all = 1;
  1215. get_user_flagrec(dcc[idx].user, &user, chanset ? chanset->dname : "");
  1216. if (!glob_master(user)) {
  1217. dprintf(idx, "You need to be a global master to use %schanset *.\n", settings.dcc_prefix);
  1218. return;
  1219. }
  1220. newsplit(&par);
  1221. } else {
  1222. if (strchr(CHANMETA, par[0])) {
  1223. chname = newsplit(&par);
  1224. get_user_flagrec(dcc[idx].user, &user, chname);
  1225. if (!glob_master(user) && !chan_master(user)) {
  1226. dprintf(idx, "You don't have access to %s. \n", chname);
  1227. return;
  1228. } else if (!(chan = findchan_by_dname(chname)) && (chname[0] != '+')) {
  1229. dprintf(idx, "That channel doesn't exist!\n");
  1230. return;
  1231. } else if ((strstr(par, "+private") || strstr(par, "-private")) && (!glob_owner(user))) {
  1232. dprintf(idx, "You don't have access to set +/-private on %s (halting command due to lazy coder).\n", chname);
  1233. return;
  1234. } else if ((strstr(par, "+inactive") || strstr(par, "-inactive")) && (!glob_owner(user))) {
  1235. dprintf(idx, "You don't have access to set +/-inactive on %s (halting command due to lazy coder).\n", chname);
  1236. return;
  1237. }
  1238. if (!chan) {
  1239. if (par[0])
  1240. *--par = ' ';
  1241. par = chname;
  1242. }
  1243. }
  1244. if (!par[0] || par[0] == '*') {
  1245. dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
  1246. return;
  1247. }
  1248. if (!chan && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
  1249. dprintf(idx, "Invalid console channel.\n");
  1250. return;
  1251. }
  1252. }
  1253. if (do_chanset(result, all ? NULL : chan, par, DO_LOCAL | DO_NET) == ERROR) {
  1254. dprintf(idx, "Error trying to set { %s } on %s: %s\n", par, all ? "all channels" : chan->dname, result);
  1255. return;
  1256. }
  1257. if (all)
  1258. dprintf(idx, "Successfully set modes { %s } on all channels.\n", par);
  1259. else
  1260. dprintf(idx, "Successfully set modes { %s } on %s\n", par, chan->dname);
  1261. #ifdef HUB
  1262. write_userfile(idx);
  1263. #endif /* HUB */
  1264. }
  1265. /* DCC CHAT COMMANDS
  1266. *
  1267. * Function call should be:
  1268. * int cmd_whatever(idx,"parameters");
  1269. *
  1270. * NOTE: As with msg commands, the function is responsible for any logging.
  1271. */
  1272. static cmd_t C_dcc_irc[] =
  1273. {
  1274. {"+ban", "o|o", (Function) cmd_pls_ban, NULL},
  1275. {"+exempt", "o|o", (Function) cmd_pls_exempt, NULL},
  1276. {"+invite", "o|o", (Function) cmd_pls_invite, NULL},
  1277. {"+chan", "n", (Function) cmd_pls_chan, NULL},
  1278. {"+chrec", "m|m", (Function) cmd_pls_chrec, NULL},
  1279. {"-ban", "o|o", (Function) cmd_mns_ban, NULL},
  1280. {"-chan", "n", (Function) cmd_mns_chan, NULL},
  1281. {"-chrec", "m|m", (Function) cmd_mns_chrec, NULL},
  1282. {"-exempt", "o|o", (Function) cmd_mns_exempt, NULL},
  1283. {"-invite", "o|o", (Function) cmd_mns_invite, NULL},
  1284. {"bans", "o|o", (Function) cmd_bans, NULL},
  1285. {"botjoin", "n", (Function) cmd_botjoin, NULL},
  1286. {"botpart", "n", (Function) cmd_botpart, NULL},
  1287. {"exempts", "o|o", (Function) cmd_exempts, NULL},
  1288. {"invites", "o|o", (Function) cmd_invites, NULL},
  1289. {"chaninfo", "m|m", (Function) cmd_chaninfo, NULL},
  1290. {"chanset", "m|m", (Function) cmd_chanset, NULL},
  1291. {"chinfo", "m|m", (Function) cmd_chinfo, NULL},
  1292. {"cycle", "n|n", (Function) cmd_cycle, NULL},
  1293. {"down", "n|n", (Function) cmd_down, NULL},
  1294. {"info", "", (Function) cmd_info, NULL},
  1295. {"slowjoin", "n", (Function) cmd_slowjoin, NULL},
  1296. {"slowpart", "n|n", (Function) cmd_slowpart, NULL},
  1297. {"stick", "o|o", (Function) cmd_stick, NULL},
  1298. {"unstick", "o|o", (Function) cmd_unstick, NULL},
  1299. {NULL, NULL, NULL, NULL}
  1300. };