cmdschan.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  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(const char type, int idx, char *par)
  10. {
  11. const char *cmd = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
  12. if (!par[0]) {
  13. dprintf(idx, "Usage: +%s <hostmask> [channel] [%%<XdXhXm>] [reason]\n", cmd);
  14. return;
  15. }
  16. char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
  17. unsigned long int expire_time = 0, expire_foo;
  18. int sticky = 0;
  19. struct chanset_t *chan = NULL;
  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 && privchan(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. strlcpy(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->net.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(const char type, int idx, char *par)
  166. {
  167. const char *cmd = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
  168. if (!par[0]) {
  169. dprintf(idx, "Usage: -%s <hostmask> [channel]\n", cmd);
  170. return;
  171. }
  172. int i = 0, j;
  173. struct chanset_t *chan = NULL;
  174. char s[UHOSTLEN] = "", *who = NULL, *chname = NULL, *mask = NULL;
  175. masklist *m = NULL;
  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]) && privchan(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. strlcpy(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. if (!use_info) {
  329. dprintf(idx, "Info storage is turned off.\n");
  330. return;
  331. }
  332. char s[512] = "", *chname = NULL, *s1 = (char *) get_user(&USERENTRY_INFO, dcc[idx].user);
  333. bool locked = 0;
  334. if (s1 && s1[0] == '@')
  335. locked = 1;
  336. if (par[0] && strchr(CHANMETA, par[0])) {
  337. chname = newsplit(&par);
  338. if (!findchan_by_dname(chname)) {
  339. dprintf(idx, "No such channel.\n");
  340. return;
  341. }
  342. get_handle_chaninfo(dcc[idx].nick, chname, s);
  343. if (s[0] == '@')
  344. locked = 1;
  345. s1 = s;
  346. } else
  347. chname = 0;
  348. if (!par[0]) {
  349. if (s1 && s1[0] == '@')
  350. s1++;
  351. if (s1 && s1[0]) {
  352. if (chname) {
  353. dprintf(idx, "Info on %s: %s\n", chname, s1);
  354. dprintf(idx, "Use 'info %s none' to remove it.\n", chname);
  355. } else {
  356. dprintf(idx, "Default info: %s\n", s1);
  357. dprintf(idx, "Use 'info none' to remove it.\n");
  358. }
  359. } else
  360. dprintf(idx, "No info has been set for you.\n");
  361. putlog(LOG_CMDS, "*", "#%s# info %s", dcc[idx].nick, chname ? chname : "");
  362. return;
  363. }
  364. if (locked && !(dcc[idx].user && (dcc[idx].user->flags & USER_MASTER))) {
  365. dprintf(idx, "Your info line is locked. Sorry.\n");
  366. return;
  367. }
  368. if (!egg_strcasecmp(par, "none")) {
  369. if (chname) {
  370. par[0] = 0;
  371. set_handle_chaninfo(userlist, dcc[idx].nick, chname, NULL);
  372. dprintf(idx, "Removed your info line on %s.\n", chname);
  373. putlog(LOG_CMDS, "*", "#%s# info %s none", dcc[idx].nick, chname);
  374. } else {
  375. set_user(&USERENTRY_INFO, dcc[idx].user, NULL);
  376. dprintf(idx, "Removed your default info line.\n");
  377. putlog(LOG_CMDS, "*", "#%s# info none", dcc[idx].nick);
  378. }
  379. return;
  380. }
  381. /* if (par[0] == '@') This is stupid, and prevents a users info from being locked */
  382. /* par++; without .tcl, or a tcl script, aka, 'half-assed' -poptix 4Jun01 */
  383. if (chname) {
  384. set_handle_chaninfo(userlist, dcc[idx].nick, chname, par);
  385. dprintf(idx, "Your info on %s is now: %s\n", chname, par);
  386. putlog(LOG_CMDS, "*", "#%s# info %s ...", dcc[idx].nick, chname);
  387. } else {
  388. set_user(&USERENTRY_INFO, dcc[idx].user, par);
  389. dprintf(idx, "Your default info is now: %s\n", par);
  390. putlog(LOG_CMDS, "*", "#%s# info ...", dcc[idx].nick);
  391. }
  392. }
  393. static void cmd_chinfo(int idx, char *par)
  394. {
  395. if (!use_info) {
  396. dprintf(idx, "Info storage is turned off.\n");
  397. return;
  398. }
  399. char *handle = newsplit(&par);
  400. if (!handle[0]) {
  401. dprintf(idx, "Usage: chinfo <handle> [channel] <new-info>\n");
  402. return;
  403. }
  404. struct userrec *u1 = get_user_by_handle(userlist, handle);
  405. if (!u1) {
  406. dprintf(idx, "No such user.\n");
  407. return;
  408. }
  409. char *chname = NULL;
  410. if (par[0] && strchr(CHANMETA, par[0])) {
  411. chname = newsplit(&par);
  412. if (!findchan_by_dname(chname)) {
  413. dprintf(idx, "No such channel.\n");
  414. return;
  415. }
  416. } else
  417. chname = 0;
  418. if (u1->bot && !(dcc[idx].user->flags & USER_MASTER)) {
  419. dprintf(idx, "You have to be master to change bots info.\n");
  420. return;
  421. }
  422. if ((u1->flags & USER_OWNER) && !(dcc[idx].user->flags & USER_OWNER)) {
  423. dprintf(idx, "You can't change info for the bot owner.\n");
  424. return;
  425. }
  426. if (chname) {
  427. get_user_flagrec(dcc[idx].user, &user, chname);
  428. get_user_flagrec(u1, &victim, chname);
  429. if ((chan_owner(victim) || glob_owner(victim)) &&
  430. !(glob_owner(user) || chan_owner(user))) {
  431. dprintf(idx, "You can't change info for the channel owner.\n");
  432. return;
  433. }
  434. }
  435. putlog(LOG_CMDS, "*", "#%s# chinfo %s %s %s", dcc[idx].nick, handle, chname ? chname : par, chname ? par : "");
  436. if (!egg_strcasecmp(par, "none"))
  437. par[0] = 0;
  438. if (chname) {
  439. set_handle_chaninfo(userlist, handle, chname, par);
  440. if (par[0] == '@')
  441. dprintf(idx, "New info (LOCKED) for %s on %s: %s\n", handle, chname,
  442. &par[1]);
  443. else if (par[0])
  444. dprintf(idx, "New info for %s on %s: %s\n", handle, chname, par);
  445. else
  446. dprintf(idx, "Wiped info for %s on %s\n", handle, chname);
  447. } else {
  448. set_user(&USERENTRY_INFO, u1, par[0] ? par : NULL);
  449. if (par[0] == '@')
  450. dprintf(idx, "New default info (LOCKED) for %s: %s\n", handle, &par[1]);
  451. else if (par[0])
  452. dprintf(idx, "New default info for %s: %s\n", handle, par);
  453. else
  454. dprintf(idx, "Wiped default info for %s\n", handle);
  455. }
  456. }
  457. static void cmd_slowjoin(int idx, char *par)
  458. {
  459. int intvl = 0, delay = 0, count = 1;
  460. char *chname = NULL, *p = NULL, buf[2048] = "", buf2[1048] = "";
  461. struct chanset_t *chan = NULL;
  462. tand_t *bot = NULL;
  463. /* slowjoin #chan 60 */
  464. putlog(LOG_CMDS, "*", "#%s# slowjoin %s", dcc[idx].nick, par);
  465. chname = newsplit(&par);
  466. p = newsplit(&par);
  467. intvl = atoi(p);
  468. if (!chname[0] || !p[0]) {
  469. dprintf(idx, "Usage: slowjoin <channel> <interval-seconds> [channel options]\n");
  470. return;
  471. }
  472. if (intvl < 10) {
  473. dprintf(idx, "Interval must be at least 10 seconds\n");
  474. return;
  475. }
  476. if ((chan = findchan_by_dname(chname))) {
  477. dprintf(idx, "Already on %s\n", chan->dname);
  478. return;
  479. }
  480. if (!strchr(CHANMETA, chname[0])) {
  481. dprintf(idx, "Invalid channel name\n");
  482. return;
  483. }
  484. strcpy(buf, "+inactive ");
  485. if (par[0])
  486. strlcat(buf, par, sizeof(buf));
  487. if (channel_add(buf2, chname, buf) == ERROR) {
  488. dprintf(idx, "Invalid channel or channel options.\n");
  489. if (buf2[0])
  490. dprintf(idx, " %s\n", buf2);
  491. return;
  492. }
  493. buf2[0] = 0;
  494. chan = findchan_by_dname(chname);
  495. if (!chan) {
  496. dprintf(idx, "Hmmm... Channel didn't get added. Weird *shrug*\n");
  497. return;
  498. }
  499. sprintf(buf2, "cjoin %s %s", chan->dname, buf);
  500. putallbots(buf2);
  501. #ifdef HUB
  502. count=0;
  503. #else /* !HUB */
  504. count=1;
  505. #endif /* HUB */
  506. for (bot = tandbot; bot; bot = bot->next) {
  507. struct userrec *ubot = NULL;
  508. char tmp[100] = "";
  509. ubot = get_user_by_handle(userlist, bot->bot);
  510. if (ubot) {
  511. /* Variation: 60 secs intvl should be 60 +/- 15 */
  512. if (bot_hublevel(ubot) < 999) {
  513. sprintf(tmp, "sj %s 0\n", chan->dname);
  514. } else {
  515. int v = (random() % (intvl / 2)) - (intvl / 4);
  516. delay += intvl;
  517. sprintf(tmp, "sj %s %i\n", chan->dname, delay + v);
  518. count++;
  519. }
  520. putbot(ubot->handle, tmp);
  521. }
  522. }
  523. dprintf(idx, "%i bots joining %s during the next %i seconds\n", count, chan->dname, delay);
  524. chan->status &= ~CHAN_INACTIVE;
  525. #ifdef LEAF
  526. if (shouldjoin(chan))
  527. dprintf(DP_MODE, "JOIN %s %s\n", chan->name, chan->key_prot);
  528. #endif /* LEAF */
  529. }
  530. static void cmd_slowpart(int idx, char *par)
  531. {
  532. int intvl = 0, delay = 0, count = 1;
  533. char *chname = NULL, *p = NULL;
  534. struct chanset_t *chan = NULL;
  535. tand_t *bot = NULL;
  536. /* slowpart #chan 60 */
  537. putlog(LOG_CMDS, "*", "#%s# slowpart %s", dcc[idx].nick, par);
  538. chname = newsplit(&par);
  539. p = newsplit(&par);
  540. intvl = atoi(p);
  541. if (!chname[0] || !p[0]) {
  542. dprintf(idx, "Usage: slowpart <channel> <interval-seconds>\n");
  543. return;
  544. }
  545. if (intvl < 10) {
  546. dprintf(idx, "Interval must be at least 10 seconds\n");
  547. return;
  548. }
  549. if (!(chan = findchan_by_dname(chname))) {
  550. dprintf(idx, "Not on %s\n", chan->dname);
  551. return;
  552. }
  553. remove_channel(chan);
  554. #ifdef HUB
  555. write_userfile(-1);
  556. #endif /* HUB */
  557. dprintf(idx, "Channel %s removed from the bot.\n", chname);
  558. dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
  559. if (findchan_by_dname(chname)) {
  560. dprintf(idx, "Hmmm... Channel didn't get removed. Weird *shrug*\n");
  561. return;
  562. }
  563. #ifdef HUB
  564. count = 0;
  565. #else /* !HUB */
  566. count = 1;
  567. #endif /* HUB */
  568. for (bot = tandbot; bot; bot = bot->next) {
  569. char tmp[100] = "";
  570. struct userrec *ubot = NULL;
  571. ubot = get_user_by_handle(userlist, bot->bot);
  572. /* Variation: 60 secs intvl should be 60 +/- 15 */
  573. if (ubot) {
  574. if (bot_hublevel(ubot) < 999) {
  575. sprintf(tmp, "sp %s 0\n", chname);
  576. } else {
  577. int v = (random() % (intvl / 2)) - (intvl / 4);
  578. delay += intvl;
  579. sprintf(tmp, "sp %s %i\n", chname, delay + v);
  580. count++;
  581. }
  582. putbot(ubot->handle, tmp);
  583. }
  584. }
  585. dprintf(idx, "%i bots parting %s during the next %i seconds\n", count, chname, delay);
  586. #ifdef LEAF
  587. dprintf(DP_MODE, "PART %s\n", chname);
  588. #endif /* LEAF */
  589. }
  590. static void cmd_stick_yn(int idx, char *par, int yn)
  591. {
  592. int i = 0, j;
  593. struct chanset_t *chan = NULL;
  594. char *stick_type = NULL, s[UHOSTLEN] = "", chname[81] = "";
  595. stick_type = newsplit(&par);
  596. strlcpy(s, newsplit(&par), sizeof s);
  597. strlcpy(chname, newsplit(&par), sizeof chname);
  598. if (egg_strcasecmp(stick_type, "exempt") &&
  599. egg_strcasecmp(stick_type, "invite") &&
  600. egg_strcasecmp(stick_type, "ban")) {
  601. strlcpy(chname, s, sizeof chname);
  602. strlcpy(s, stick_type, sizeof s);
  603. }
  604. if (!s[0]) {
  605. dprintf(idx, "Usage: %sstick [ban/exempt/invite] <hostmask or number> [channel]\n", yn ? "" : "un");
  606. return;
  607. }
  608. /* Now deal with exemptions */
  609. if (!egg_strcasecmp(stick_type, "exempt")) {
  610. if (!use_exempts) {
  611. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  612. return;
  613. }
  614. if (!chname[0]) {
  615. i = u_setsticky_exempt(NULL, s,
  616. (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
  617. if (i > 0) {
  618. putlog(LOG_CMDS, "*", "#%s# %sstick exempt %s",
  619. dcc[idx].nick, yn ? "" : "un", s);
  620. dprintf(idx, "%stuck exempt: %s\n", yn ? "S" : "Uns", s);
  621. return;
  622. }
  623. strlcpy(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  624. }
  625. /* Channel-specific exempt? */
  626. if (!(chan = findchan_by_dname(chname))) {
  627. dprintf(idx, "No such channel.\n");
  628. return;
  629. }
  630. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  631. if (privchan(user, chan, PRIV_OP)) {
  632. dprintf(idx, "No such channel.\n");
  633. return;
  634. }
  635. if (str_isdigit(s)) {
  636. /* substract the numer of global exempts to get the number of the channel exempt */
  637. j = u_setsticky_exempt(NULL, s, -1);
  638. if (j < 0)
  639. egg_snprintf(s, sizeof s, "%d", -j);
  640. }
  641. j = u_setsticky_exempt(chan, s, yn);
  642. if (j > 0) {
  643. putlog(LOG_CMDS, "*", "#%s# %sstick exempt %s %s", dcc[idx].nick,
  644. yn ? "" : "un", s, chname);
  645. dprintf(idx, "%stuck %s exempt: %s\n", yn ? "S" : "Uns", chname, s);
  646. return;
  647. }
  648. dprintf(idx, "No such exempt.\n");
  649. return;
  650. /* Now the invites */
  651. } else if (!egg_strcasecmp(stick_type, "invite")) {
  652. if (!use_invites) {
  653. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  654. return;
  655. }
  656. if (!chname[0]) {
  657. i = u_setsticky_invite(NULL, s,
  658. (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
  659. if (i > 0) {
  660. putlog(LOG_CMDS, "*", "#%s# %sstick invite %s",
  661. dcc[idx].nick, yn ? "" : "un", s);
  662. dprintf(idx, "%stuck invite: %s\n", yn ? "S" : "Uns", s);
  663. return;
  664. }
  665. strlcpy(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  666. }
  667. /* Channel-specific invite? */
  668. if (!(chan = findchan_by_dname(chname))) {
  669. dprintf(idx, "No such channel.\n");
  670. return;
  671. }
  672. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  673. if (privchan(user, chan, PRIV_OP)) {
  674. dprintf(idx, "No such channel.\n");
  675. return;
  676. }
  677. if (str_isdigit(s)) {
  678. /* substract the numer of global invites to get the number of the channel invite */
  679. j = u_setsticky_invite(NULL, s, -1);
  680. if (j < 0)
  681. egg_snprintf(s, sizeof s, "%d", -j);
  682. }
  683. j = u_setsticky_invite(chan, s, yn);
  684. if (j > 0) {
  685. putlog(LOG_CMDS, "*", "#%s# %sstick invite %s %s", dcc[idx].nick, yn ? "" : "un", s, chname);
  686. dprintf(idx, "%stuck %s invite: %s\n", yn ? "S" : "Uns", chname, s);
  687. return;
  688. }
  689. dprintf(idx, "No such invite.\n");
  690. return;
  691. }
  692. if (!chname[0]) {
  693. i = u_setsticky_ban(NULL, s,
  694. (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
  695. if (i > 0) {
  696. putlog(LOG_CMDS, "*", "#%s# %sstick ban %s", dcc[idx].nick, yn ? "" : "un", s);
  697. dprintf(idx, "%stuck ban: %s\n", yn ? "S" : "Uns", s);
  698. #ifdef LEAF
  699. {
  700. struct chanset_t *achan = NULL;
  701. for (achan = chanset; achan != NULL; achan = achan->next)
  702. check_this_ban(achan, s, yn);
  703. }
  704. #endif /* LEAF */
  705. return;
  706. }
  707. strlcpy(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  708. }
  709. /* Channel-specific ban? */
  710. if (!(chan = findchan_by_dname(chname))) {
  711. dprintf(idx, "No such channel.\n");
  712. return;
  713. }
  714. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  715. if (privchan(user, chan, PRIV_OP)) {
  716. dprintf(idx, "No such channel.\n");
  717. return;
  718. }
  719. if (str_isdigit(s)) {
  720. /* substract the numer of global bans to get the number of the channel ban */
  721. j = u_setsticky_ban(NULL, s, -1);
  722. if (j < 0)
  723. egg_snprintf(s, sizeof s, "%d", -j);
  724. }
  725. j = u_setsticky_ban(chan, s, yn);
  726. if (j > 0) {
  727. putlog(LOG_CMDS, "*", "#%s# %sstick ban %s %s", dcc[idx].nick, yn ? "" : "un", s, chname);
  728. dprintf(idx, "%stuck %s ban: %s\n", yn ? "S" : "Uns", chname, s);
  729. #ifdef LEAF
  730. check_this_ban(chan, s, yn);
  731. #endif /* LEAF */
  732. return;
  733. }
  734. dprintf(idx, "No such ban.\n");
  735. }
  736. static void cmd_stick(int idx, char *par)
  737. {
  738. cmd_stick_yn(idx, par, 1);
  739. }
  740. static void cmd_unstick(int idx, char *par)
  741. {
  742. cmd_stick_yn(idx, par, 0);
  743. }
  744. static void cmd_pls_chrec(int idx, char *par)
  745. {
  746. char *nick = NULL, *chn = NULL;
  747. struct chanset_t *chan = NULL;
  748. struct userrec *u1 = NULL;
  749. struct chanuserrec *chanrec = NULL;
  750. if (!par[0]) {
  751. dprintf(idx, "Usage: +chrec <user> [channel]\n");
  752. return;
  753. }
  754. nick = newsplit(&par);
  755. u1 = get_user_by_handle(userlist, nick);
  756. if (!u1) {
  757. dprintf(idx, "No such user.\n");
  758. return;
  759. }
  760. if (!par[0])
  761. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  762. else {
  763. chn = newsplit(&par);
  764. chan = findchan_by_dname(chn);
  765. }
  766. if (!chan) {
  767. dprintf(idx, "No such channel.\n");
  768. return;
  769. }
  770. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  771. get_user_flagrec(u1, &victim, chan->dname);
  772. if (privchan(user, chan, PRIV_OP)) {
  773. dprintf(idx, "No such channel.\n");
  774. return;
  775. }
  776. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  777. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  778. (glob_owner(victim) && !glob_owner(user))) {
  779. dprintf(idx, "You have no permission to do that.\n");
  780. return;
  781. }
  782. chanrec = get_chanrec(u1, chan->dname);
  783. if (chanrec) {
  784. dprintf(idx, "User %s already has a channel record for %s.\n",
  785. nick, chan->dname);
  786. return;
  787. }
  788. putlog(LOG_CMDS, "*", "#%s# +chrec %s %s", dcc[idx].nick, nick, chan->dname);
  789. add_chanrec(u1, chan->dname);
  790. dprintf(idx, "Added %s channel record for %s.\n", chan->dname, nick);
  791. }
  792. static void cmd_mns_chrec(int idx, char *par)
  793. {
  794. char *nick = NULL, *chn = NULL;
  795. struct userrec *u1 = NULL;
  796. struct chanuserrec *chanrec = NULL;
  797. if (!par[0]) {
  798. dprintf(idx, "Usage: -chrec <user> [channel]\n");
  799. return;
  800. }
  801. nick = newsplit(&par);
  802. u1 = get_user_by_handle(userlist, nick);
  803. if (!u1) {
  804. dprintf(idx, "No such user.\n");
  805. return;
  806. }
  807. if (!par[0]) {
  808. struct chanset_t *chan;
  809. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  810. if (chan)
  811. chn = chan->dname;
  812. else {
  813. dprintf(idx, "Invalid console channel.\n");
  814. return;
  815. }
  816. } else
  817. chn = newsplit(&par);
  818. get_user_flagrec(dcc[idx].user, &user, chn);
  819. get_user_flagrec(u1, &victim, chn);
  820. if (privchan(user, findchan_by_dname(chn), PRIV_OP)) {
  821. dprintf(idx, "No such channel.\n");
  822. return;
  823. }
  824. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  825. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  826. (glob_owner(victim) && !glob_owner(user))) {
  827. dprintf(idx, "You have no permission to do that.\n");
  828. return;
  829. }
  830. chanrec = get_chanrec(u1, chn);
  831. if (!chanrec) {
  832. dprintf(idx, "User %s doesn't have a channel record for %s.\n", nick, chn);
  833. return;
  834. }
  835. putlog(LOG_CMDS, "*", "#%s# -chrec %s %s", dcc[idx].nick, nick, chn);
  836. del_chanrec(u1, chn);
  837. dprintf(idx, "Removed %s channel record from %s.\n", chn, nick);
  838. }
  839. static void cmd_cycle(int idx, char *par)
  840. {
  841. char *chname = NULL;
  842. char buf2[1024] = "";
  843. int delay = 10;
  844. struct chanset_t *chan = NULL;
  845. putlog(LOG_CMDS, "*", "#%s# cycle %s", dcc[idx].nick, par);
  846. if (!par[0]) {
  847. dprintf(idx, "Usage: cycle [%s]<channel> [delay]\n", CHANMETA);
  848. dprintf(idx, "rejoin delay defaults to '10'\n");
  849. return;
  850. }
  851. chname = newsplit(&par);
  852. chan = findchan_by_dname(chname);
  853. if (!chan) {
  854. dprintf(idx, "%s it not a valid channel.\n", chname);
  855. return;
  856. }
  857. if (par[0])
  858. delay = atoi(newsplit(&par));
  859. sprintf(buf2, "cycle %s %d", chname, delay); /* this just makes the bot PART */
  860. putallbots(buf2);
  861. #ifdef LEAF
  862. do_chanset(NULL, chan, "+inactive", DO_LOCAL);
  863. dprintf(DP_SERVER, "PART %s\n", chan->name);
  864. chan->channel.jointime = ((now + delay) - server_lag);
  865. #endif /* LEAF */
  866. }
  867. static void cmd_down(int idx, char *par)
  868. {
  869. char *chname = NULL, buf2[1024] = "";
  870. struct chanset_t *chan = NULL;
  871. putlog(LOG_CMDS, "*", "#%s# down %s", dcc[idx].nick, par);
  872. if (!par[0]) {
  873. dprintf(idx, "Usage: down [%s]<channel>\n", CHANMETA);
  874. return;
  875. }
  876. chname = newsplit(&par);
  877. chan = findchan_by_dname(chname);
  878. if (!chan) {
  879. dprintf(idx, "%s it not a valid channel.\n", chname);
  880. return;
  881. }
  882. sprintf(buf2, "down %s", chan->dname);
  883. putallbots(buf2);
  884. #ifdef LEAF
  885. add_mode(chan, '-', 'o', botname);
  886. chan->channel.no_op = (now + 10);
  887. #endif /* LEAF */
  888. }
  889. static void pls_chan(int idx, char *par, char *bot)
  890. {
  891. char *chname = NULL, result[1024] = "", buf[2048] = "";
  892. struct chanset_t *chan = NULL;
  893. if (!bot)
  894. putlog(LOG_CMDS, "*", "#%s# +chan %s", dcc[idx].nick, par);
  895. if (!par[0]) {
  896. dprintf(idx, "Usage: +chan [%s]<channel> [options]\n", CHANMETA);
  897. return;
  898. }
  899. chname = newsplit(&par);
  900. sprintf(buf, "cjoin %s %s", chname, bot ? bot : "*"); /* +chan makes all bots join */
  901. if (par[0]) {
  902. strcat(buf, " ");
  903. strcat(buf, par);
  904. strcat(buf, " ");
  905. }
  906. if (!bot && findchan_by_dname(chname)) {
  907. putallbots(buf);
  908. dprintf(idx, "That channel already exists!\n");
  909. return;
  910. } else if ((chan = findchan(chname)) && !bot) {
  911. putallbots(buf);
  912. dprintf(idx, "That channel already exists as %s!\n", chan->dname);
  913. return;
  914. } else if (strchr(CHANMETA, chname[0]) == NULL) {
  915. dprintf(idx, "Invalid channel prefix.\n");
  916. return;
  917. } else if (strchr(chname, ',') != NULL) {
  918. dprintf(idx, "Invalid channel name.\n");
  919. return;
  920. }
  921. if (!chan && !findchan_by_dname(chname) && channel_add(result, chname, par) == ERROR) {
  922. dprintf(idx, "Invalid channel or channel options.\n");
  923. if (result[0])
  924. dprintf(idx, " %s\n", result);
  925. } else {
  926. if ((chan = findchan_by_dname(chname))) {
  927. if (!bot) {
  928. char tmp[51] = "";
  929. sprintf(tmp, "addedby %s addedts %li", dcc[idx].nick, now);
  930. if (buf[0]) {
  931. strcat(buf, " ");
  932. strcat(buf, tmp);
  933. }
  934. do_chanset(NULL, chan, buf[0] ? buf : tmp, DO_LOCAL);
  935. dprintf(idx, "Channel %s added to the botnet.\n", chname);
  936. } else {
  937. dprintf(idx, "Channel %s added to the bot: %s\n", chname, bot);
  938. }
  939. putallbots(buf);
  940. }
  941. #ifdef HUB
  942. write_userfile(-1);
  943. #endif /* HUB */
  944. }
  945. }
  946. static void cmd_pls_chan(int idx, char *par)
  947. {
  948. pls_chan(idx, par, NULL);
  949. }
  950. static void cmd_botjoin(int idx, char *par)
  951. {
  952. char *bot = NULL;
  953. struct userrec *botu = NULL;
  954. putlog(LOG_CMDS, "*", "#%s# botjoin %s", dcc[idx].nick, par);
  955. if (!par[0]) {
  956. dprintf(idx, "Usage: botjoin <bot> [%s]<channel> [options]\n", CHANMETA);
  957. return;
  958. }
  959. bot = newsplit(&par);
  960. botu = get_user_by_handle(userlist, bot);
  961. if (botu && botu->bot) {
  962. pls_chan(idx, par, bot);
  963. } else {
  964. dprintf(idx, "Error: '%s' is not a bot.\n", bot);
  965. }
  966. }
  967. static void mns_chan(int idx, char *par, char *bot)
  968. {
  969. char *chname = NULL, buf2[1024] = "";
  970. struct chanset_t *chan = NULL;
  971. int i;
  972. if (!bot)
  973. putlog(LOG_CMDS, "*", "#%s# -chan %s", dcc[idx].nick, par);
  974. if (!par[0]) {
  975. dprintf(idx, "Usage: -chan [%s]<channel>\n", CHANMETA);
  976. return;
  977. }
  978. chname = newsplit(&par);
  979. sprintf(buf2, "cpart %s %s", chname, bot ? bot : "*");
  980. if (bot) /* bot will just set it +inactive */
  981. putbot(bot, buf2);
  982. else
  983. putallbots(buf2);
  984. chan = findchan_by_dname(chname);
  985. if (!chan) {
  986. if ((chan = findchan(chname)))
  987. dprintf(idx, "That channel exists with a short name of %s, use that.\n", chan->dname);
  988. else
  989. dprintf(idx, "That channel doesn't exist!\n");
  990. return;
  991. }
  992. if (!bot) {
  993. for (i = 0; i < dcc_total; i++)
  994. if (dcc[i].type && (dcc[i].type->flags & DCT_CHAT) && !rfc_casecmp(dcc[i].u.chat->con_chan, chan->dname)) {
  995. dprintf(i, "%s is no longer a valid channel, changing your console to '*'\n", chname);
  996. strcpy(dcc[i].u.chat->con_chan, "*");
  997. }
  998. remove_channel(chan);
  999. #ifdef HUB
  1000. write_userfile(-1);
  1001. #endif /* HUB */
  1002. dprintf(idx, "Channel %s removed from the botnet.\n", chname);
  1003. dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
  1004. } else
  1005. dprintf(idx, "Channel %s removed from the bot: %s\n", chname, bot);
  1006. }
  1007. static void cmd_mns_chan(int idx, char *par)
  1008. {
  1009. mns_chan(idx, par, NULL);
  1010. }
  1011. static void cmd_botpart(int idx, char *par)
  1012. {
  1013. char *bot = NULL;
  1014. struct userrec *botu = NULL;
  1015. putlog(LOG_CMDS, "*", "#%s# botpart %s", dcc[idx].nick, par);
  1016. if (!par[0]) {
  1017. dprintf(idx, "Usage: botpart <bot> [%s]<channel> [options]\n", CHANMETA);
  1018. return;
  1019. }
  1020. bot = newsplit(&par);
  1021. botu = get_user_by_handle(userlist, bot);
  1022. if (botu && botu->bot) {
  1023. mns_chan(idx, par, bot);
  1024. } else {
  1025. dprintf(idx, "Error: '%s' is not a bot.\n", bot);
  1026. }
  1027. }
  1028. /* thanks Excelsior */
  1029. #define FLAG_COLS 4
  1030. void show_flag(int idx, char *work, int *cnt, const char *name, unsigned int state)
  1031. {
  1032. char tmp[101] = "", chr_state[15] = "";
  1033. /* empty buffer if no (char *) name */
  1034. if (((*cnt) < (FLAG_COLS - 1)) && (!name || (name && !name[0]))) (*cnt) = (FLAG_COLS - 1);
  1035. (*cnt)++;
  1036. if (*cnt > FLAG_COLS) {
  1037. *cnt = 1;
  1038. work[0] = 0;
  1039. }
  1040. if (!work[0])
  1041. sprintf(work, " ");
  1042. if (name && name[0]) {
  1043. chr_state[0] = 0;
  1044. if (state) {
  1045. strcat(chr_state, GREEN(idx));
  1046. strcat(chr_state, "+");
  1047. } else {
  1048. strcat(chr_state, RED(idx));
  1049. strcat(chr_state, "-");
  1050. }
  1051. strcat(chr_state, COLOR_END(idx));
  1052. egg_snprintf(tmp, sizeof tmp, "%s%-17s", chr_state, name);
  1053. strcat(work, tmp);
  1054. }
  1055. if (*cnt >= FLAG_COLS)
  1056. dprintf(idx, "%s\n", work);
  1057. }
  1058. #define INT_COLS 1
  1059. void show_int(int idx, char *work, int *cnt, const char *desc, int state, const char *yes, const char *no)
  1060. {
  1061. char tmp[101] = "", chr_state[101] = "";
  1062. egg_snprintf(chr_state, sizeof chr_state, "%d", state);
  1063. /* empty buffer if no (char *) name */
  1064. if (((*cnt) < (INT_COLS - 1)) && (!desc || (desc && !desc[0]))) (*cnt) = (INT_COLS - 1);
  1065. (*cnt)++;
  1066. if (*cnt > INT_COLS) {
  1067. *cnt = 1;
  1068. work[0] = 0;
  1069. }
  1070. if (!work[0])
  1071. sprintf(work, " ");
  1072. /* need to make next line all one char, and then put it into %-30s */
  1073. if (desc && desc[0]) {
  1074. char tmp2[50] = "", tmp3[50] = "";
  1075. strcat(tmp2, BOLD(idx));
  1076. if (state && yes) {
  1077. strcat(tmp2, yes);
  1078. strcat(tmp3, " (");
  1079. strcat(tmp3, chr_state);
  1080. strcat(tmp3, ")");
  1081. } else if (!state && no) {
  1082. strcat(tmp2, no);
  1083. strcat(tmp3, " (");
  1084. strcat(tmp3, chr_state);
  1085. strcat(tmp3, ")");
  1086. } else if ((state && !yes) || (!state && !no)) {
  1087. strcat(tmp2, chr_state);
  1088. }
  1089. strcat(tmp2, BOLD_END(idx));
  1090. egg_snprintf(tmp, sizeof tmp, "%-30s %-20s %s", desc, tmp2, (tmp3 && tmp3[0]) ? tmp3 : "");
  1091. strcat(work, tmp);
  1092. }
  1093. if (*cnt >= INT_COLS)
  1094. dprintf(idx, "%s\n", work);
  1095. }
  1096. #define SHOW_FLAG(name, state) show_flag(idx, work, &cnt, name, state)
  1097. #define SHOW_INT(desc, state, yes, no) show_int(idx, work, &cnt, desc, state, yes, no)
  1098. #define P_STR deflag == P_KICK ? "Kick" : (deflag == P_DEOP ? "Deop" : (deflag == P_DELETE ? "Remove" : NULL))
  1099. static void cmd_chaninfo(int idx, char *par)
  1100. {
  1101. char *chname = NULL, work[512] = "";
  1102. struct chanset_t *chan = NULL;
  1103. int cnt = 0;
  1104. if (!par[0]) {
  1105. chname = dcc[idx].u.chat->con_chan;
  1106. if (chname[0] == '*') {
  1107. dprintf(idx, "Your console channel is invalid.\n");
  1108. return;
  1109. }
  1110. } else {
  1111. chname = newsplit(&par);
  1112. get_user_flagrec(dcc[idx].user, &user, chname);
  1113. if (!glob_master(user) && !chan_master(user)) {
  1114. dprintf(idx, "You don't have access to %s.\n", chname);
  1115. return;
  1116. }
  1117. }
  1118. chan = findchan_by_dname(chname);
  1119. if (!chan || (chan && privchan(user, chan, PRIV_OP))) {
  1120. dprintf(idx, "No such channel.\n");
  1121. return;
  1122. } else {
  1123. char nick[NICKLEN] = "", date[81] = "";
  1124. int deflag = 0;
  1125. if (chan->added_ts) {
  1126. egg_strftime(date, sizeof date, "%c %Z", gmtime(&(chan->added_ts)));
  1127. } else
  1128. date[0] = 0;
  1129. if (chan->added_by && chan->added_by[0])
  1130. egg_snprintf(nick, sizeof nick, "%s", chan->added_by);
  1131. else
  1132. nick[0] = 0;
  1133. putlog(LOG_CMDS, "*", "#%s# chaninfo %s", dcc[idx].nick, chname);
  1134. if (nick[0] && date[0])
  1135. dprintf(idx, "Settings for channel %s (Added %s by %s%s%s):\n", chan->dname, date, BOLD(idx), nick, BOLD_END(idx));
  1136. else
  1137. dprintf(idx, "Settings for channel %s:\n", chan->dname);
  1138. /* FIXME: SHOW_CHAR() here */
  1139. get_mode_protect(chan, work);
  1140. dprintf(idx, "Protect modes (chanmode): %s\n", work[0] ? work : "None");
  1141. dprintf(idx, "Protect topic (topic) : %s\n", chan->topic[0] ? chan->topic : "");
  1142. /* Chanchar template
  1143. * dprintf(idx, "String temp: %s\n", chan->temp[0] ? chan->temp : "NULL");
  1144. */
  1145. dprintf(idx, "Channel flags:\n");
  1146. work[0] = 0;
  1147. SHOW_FLAG("autoop", channel_autoop(chan));
  1148. SHOW_FLAG("bitch", channel_bitch(chan));
  1149. SHOW_FLAG("closed", channel_closed(chan));
  1150. SHOW_FLAG("cycle", channel_cycle(chan));
  1151. SHOW_FLAG("enforcebans", channel_enforcebans(chan));
  1152. SHOW_FLAG("fastop", channel_fastop(chan));
  1153. SHOW_FLAG("inactive", channel_inactive(chan));
  1154. SHOW_FLAG("manop", channel_manop(chan));
  1155. SHOW_FLAG("nodesynch", channel_nodesynch(chan));
  1156. SHOW_FLAG("nomop", channel_nomop(chan));
  1157. SHOW_FLAG("private", channel_privchan(chan));
  1158. SHOW_FLAG("protectops", channel_protectops(chan));
  1159. SHOW_FLAG("revenge", channel_revenge(chan));
  1160. SHOW_FLAG("revengebot", channel_revengebot(chan));
  1161. SHOW_FLAG("take", channel_take(chan));
  1162. SHOW_FLAG("voice", channel_voice(chan));
  1163. SHOW_FLAG("", 0);
  1164. SHOW_FLAG("dynamicbans", channel_dynamicbans(chan));
  1165. SHOW_FLAG("userbans", !channel_nouserbans(chan));
  1166. SHOW_FLAG("dynamicexempts", channel_dynamicexempts(chan));
  1167. SHOW_FLAG("userexempts", !channel_nouserexempts(chan));
  1168. SHOW_FLAG("dynamicinvites", channel_dynamicinvites(chan));
  1169. SHOW_FLAG("userinvites", !channel_nouserinvites(chan));
  1170. SHOW_FLAG("", 0);
  1171. work[0] = 0;
  1172. /* Chanflag template
  1173. * (chan->status & CHAN_TEMP) ? '+' : '-',
  1174. * also include %ctemp in dprintf.
  1175. */
  1176. work[0] = cnt = 0;
  1177. /* Chanint template
  1178. * SHOW_INT("Desc: ", integer, "YES", "NO");
  1179. */
  1180. dprintf(idx, "Channel settings:\n");
  1181. deflag = chan->bad_cookie;
  1182. SHOW_INT("Bad-cookie:" , chan->bad_cookie, P_STR, "Ignore");
  1183. SHOW_INT("Ban-time: ", chan->ban_time, NULL, "Forever");
  1184. SHOW_INT("Closed-ban: ", chan->closed_ban, NULL, "Don't!");
  1185. SHOW_INT("Closed-invite:", chan->closed_invite, NULL, "Don't!");
  1186. SHOW_INT("Closed-Private:", chan->closed_private, NULL, "Don't!");
  1187. SHOW_INT("Exempt-time: ", chan->exempt_time, NULL, "Forever");
  1188. SHOW_INT("Idle Kick after (idle-kick): ", chan->idle_kick, "", "Don't!");
  1189. SHOW_INT("Invite-time: ", chan->invite_time, NULL, "Forever");
  1190. SHOW_INT("Limit raise (limit): ", chan->limitraise, NULL, "Disabled");
  1191. deflag = chan->manop;
  1192. SHOW_INT("Manop: ", chan->manop, P_STR, "Ignore");
  1193. deflag = chan->mdop;
  1194. SHOW_INT("Mdop: ", chan->mdop, P_STR, "Ignore");
  1195. deflag = chan->mop;
  1196. SHOW_INT("Mop: ", chan->mop, P_STR, "Ignore");
  1197. SHOW_INT("Revenge-mode: ", chan->revenge_mode, NULL, NULL);
  1198. SHOW_INT("Stopnethack-mode: ", chan->stopnethack_mode, "", "Don't!");
  1199. dprintf(idx, "Flood settings: chan ctcp join kick deop nick\n");
  1200. dprintf(idx, " number: %3d %3d %3d %3d %3d %3d\n",
  1201. chan->flood_pub_thr, chan->flood_ctcp_thr,
  1202. chan->flood_join_thr, chan->flood_kick_thr,
  1203. chan->flood_deop_thr, chan->flood_nick_thr);
  1204. dprintf(idx, " time : %3lu %3lu %3lu %3lu %3lu %3lu\n",
  1205. chan->flood_pub_time, chan->flood_ctcp_time,
  1206. chan->flood_join_time, chan->flood_kick_time,
  1207. chan->flood_deop_time, chan->flood_nick_time);
  1208. }
  1209. }
  1210. static void cmd_chanset(int idx, char *par)
  1211. {
  1212. char *chname = NULL, result[1024] = "";
  1213. struct chanset_t *chan = NULL;
  1214. int all = 0;
  1215. putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
  1216. if (!par[0]) {
  1217. dprintf(idx, "Usage: chanset [%schannel|*] <settings>\n", CHANMETA);
  1218. return;
  1219. }
  1220. if (strlen(par) > 2 && par[0] == '*' && par[1] == ' ') {
  1221. all = 1;
  1222. get_user_flagrec(dcc[idx].user, &user, chanset ? chanset->dname : "");
  1223. if (!glob_master(user)) {
  1224. dprintf(idx, "You need to be a global master to use %schanset *.\n", settings.dcc_prefix);
  1225. return;
  1226. }
  1227. newsplit(&par);
  1228. } else {
  1229. if (strchr(CHANMETA, par[0])) {
  1230. chname = newsplit(&par);
  1231. get_user_flagrec(dcc[idx].user, &user, chname);
  1232. chan = findchan_by_dname(chname);
  1233. if (!glob_master(user) && !chan_master(user)) {
  1234. dprintf(idx, "You don't have access to %s. \n", chname);
  1235. return;
  1236. } else if ((!chan && (chname[0] != '+')) || (chan && privchan(user, chan, PRIV_OP))) {
  1237. dprintf(idx, "No such channel.\n");
  1238. return;
  1239. } else if ((strstr(par, "+private") || strstr(par, "-private")) && (!glob_owner(user))) {
  1240. dprintf(idx, "You don't have access to set +/-private on %s (halting command due to lazy coder).\n", chname);
  1241. return;
  1242. } else if ((strstr(par, "+inactive") || strstr(par, "-inactive")) && (!glob_owner(user))) {
  1243. dprintf(idx, "You don't have access to set +/-inactive on %s (halting command due to lazy coder).\n", chname);
  1244. return;
  1245. }
  1246. if (!chan) {
  1247. if (par[0])
  1248. *--par = ' ';
  1249. par = chname;
  1250. }
  1251. }
  1252. if (!par[0] || par[0] == '*') {
  1253. dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
  1254. return;
  1255. }
  1256. if (!chan && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
  1257. dprintf(idx, "Invalid console channel.\n");
  1258. return;
  1259. }
  1260. }
  1261. if (do_chanset(result, all ? NULL : chan, par, DO_LOCAL | DO_NET) == ERROR) {
  1262. dprintf(idx, "Error trying to set { %s } on %s: %s\n", par, all ? "all channels" : chan->dname, result);
  1263. return;
  1264. }
  1265. if (all)
  1266. dprintf(idx, "Successfully set modes { %s } on all channels.\n", par);
  1267. else
  1268. dprintf(idx, "Successfully set modes { %s } on %s\n", par, chan->dname);
  1269. #ifdef HUB
  1270. write_userfile(idx);
  1271. #endif /* HUB */
  1272. }
  1273. /* DCC CHAT COMMANDS
  1274. *
  1275. * Function call should be:
  1276. * int cmd_whatever(idx,"parameters");
  1277. *
  1278. * NOTE: As with msg commands, the function is responsible for any logging.
  1279. */
  1280. static cmd_t C_dcc_irc[] =
  1281. {
  1282. {"+ban", "o|o", (Function) cmd_pls_ban, NULL},
  1283. {"+exempt", "o|o", (Function) cmd_pls_exempt, NULL},
  1284. {"+invite", "o|o", (Function) cmd_pls_invite, NULL},
  1285. {"+chan", "n", (Function) cmd_pls_chan, NULL},
  1286. {"+chrec", "m|m", (Function) cmd_pls_chrec, NULL},
  1287. {"-ban", "o|o", (Function) cmd_mns_ban, NULL},
  1288. {"-chan", "n", (Function) cmd_mns_chan, NULL},
  1289. {"-chrec", "m|m", (Function) cmd_mns_chrec, NULL},
  1290. {"-exempt", "o|o", (Function) cmd_mns_exempt, NULL},
  1291. {"-invite", "o|o", (Function) cmd_mns_invite, NULL},
  1292. {"bans", "o|o", (Function) cmd_bans, NULL},
  1293. {"botjoin", "n", (Function) cmd_botjoin, NULL},
  1294. {"botpart", "n", (Function) cmd_botpart, NULL},
  1295. {"exempts", "o|o", (Function) cmd_exempts, NULL},
  1296. {"invites", "o|o", (Function) cmd_invites, NULL},
  1297. {"chaninfo", "m|m", (Function) cmd_chaninfo, NULL},
  1298. {"chanset", "m|m", (Function) cmd_chanset, NULL},
  1299. {"chinfo", "m|m", (Function) cmd_chinfo, NULL},
  1300. {"cycle", "n|n", (Function) cmd_cycle, NULL},
  1301. {"down", "n|n", (Function) cmd_down, NULL},
  1302. {"info", "", (Function) cmd_info, NULL},
  1303. {"slowjoin", "n", (Function) cmd_slowjoin, NULL},
  1304. {"slowpart", "n|n", (Function) cmd_slowpart, NULL},
  1305. {"stick", "o|o", (Function) cmd_stick, NULL},
  1306. {"unstick", "o|o", (Function) cmd_unstick, NULL},
  1307. {NULL, NULL, NULL, NULL}
  1308. };