cmdsirc.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
  1. /*
  2. * chancmds.c -- part of irc.mod
  3. * handles commands directly relating to channel interaction
  4. *
  5. */
  6. /* Do we have any flags that will allow us ops on a channel?
  7. */
  8. static struct chanset_t *get_channel(int idx, char *chname, bool check_console = 1)
  9. {
  10. struct chanset_t *chan = NULL;
  11. if (chname && chname[0]) {
  12. chan = findchan_by_dname(chname);
  13. if (chan)
  14. return chan;
  15. else
  16. dprintf(idx, "No such channel.\n");
  17. } else if (check_console) {
  18. chname = dcc[idx].u.chat->con_chan;
  19. chan = findchan_by_dname(chname);
  20. if (chan)
  21. return chan;
  22. else
  23. dprintf(idx, "Invalid console channel.\n");
  24. }
  25. return NULL;
  26. }
  27. /* Do we have any flags that will allow us ops on a channel?
  28. */
  29. static int has_op(int idx, struct chanset_t *chan)
  30. {
  31. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  32. if (privchan(user, chan, PRIV_OP)) {
  33. dprintf(idx, "No such channel.\n");
  34. return 0;
  35. }
  36. if (real_chk_op(user, chan, 0))
  37. return 1;
  38. dprintf(idx, "You are not a channel op on %s.\n", chan->dname);
  39. return 0;
  40. }
  41. /* Finds a nick of the handle. Returns m->nick if
  42. * the nick was found, otherwise NULL (Sup 1Nov2000)
  43. */
  44. char *getnick(const char *handle, struct chanset_t *chan)
  45. {
  46. struct userrec *u = NULL;
  47. char s[UHOSTLEN] = "";
  48. for (register memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
  49. simple_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
  50. if ((u = get_user_by_host(s)) && !egg_strcasecmp(u->handle, handle))
  51. return m->nick;
  52. }
  53. return NULL;
  54. }
  55. static void cmd_act(int idx, char *par)
  56. {
  57. if (!par[0]) {
  58. dprintf(idx, "Usage: act [channel] <action>\n");
  59. return;
  60. }
  61. char *chname = NULL;
  62. struct chanset_t *chan = NULL;
  63. if (strchr(CHANMETA, par[0]) != NULL)
  64. chname = newsplit(&par);
  65. else
  66. chname = 0;
  67. chan = get_channel(idx, chname);
  68. if (!chan || !has_op(idx, chan))
  69. return;
  70. memberlist *m = ismember(chan, botname);
  71. if (!m) {
  72. dprintf(idx, "Cannot say to %s: I'm not on that channel.\n", chan->dname);
  73. return;
  74. }
  75. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  76. if ((chan->channel.mode & CHANMODER) && !me_op(chan) && !me_voice(chan)) {
  77. dprintf(idx, "Cannot say to %s: It is moderated.\n", chan->dname);
  78. return;
  79. }
  80. putlog(LOG_CMDS, "*", "#%s# (%s) act %s", dcc[idx].nick,
  81. chan->dname, par);
  82. dprintf(DP_HELP, "PRIVMSG %s :\001ACTION %s\001\n",
  83. chan->name, par);
  84. dprintf(idx, "Action to %s: %s\n", chan->dname, par);
  85. }
  86. static void cmd_msg(int idx, char *par)
  87. {
  88. if (!par[0]) {
  89. dprintf(idx, "Usage: msg <nick> <message>\n");
  90. return;
  91. }
  92. char *nick = newsplit(&par);
  93. putlog(LOG_CMDS, "*", "#%s# msg %s %s", dcc[idx].nick, nick, par);
  94. dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, par);
  95. dprintf(idx, "Msg to %s: %s\n", nick, par);
  96. }
  97. static void cmd_say(int idx, char *par)
  98. {
  99. if (!par[0]) {
  100. dprintf(idx, "Usage: say [channel] <message>\n");
  101. return;
  102. }
  103. char *chname = NULL;
  104. struct chanset_t *chan = NULL;
  105. if (strchr(CHANMETA, par[0]) != NULL)
  106. chname = newsplit(&par);
  107. else
  108. chname = 0;
  109. chan = get_channel(idx, chname);
  110. if (!chan || !has_op(idx, chan))
  111. return;
  112. memberlist *m = ismember(chan, botname);
  113. if (!m) {
  114. dprintf(idx, "Cannot say to %s: I'm not on that channel.\n", chan->dname);
  115. return;
  116. }
  117. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  118. if ((chan->channel.mode & CHANMODER) && !me_op(chan) && !me_voice(chan)) {
  119. dprintf(idx, "Cannot say to %s: It is moderated.\n", chan->dname);
  120. return;
  121. }
  122. putlog(LOG_CMDS, "*", "#%s# (%s) say %s", dcc[idx].nick, chan->dname, par);
  123. dprintf(DP_HELP, "PRIVMSG %s :%s\n", chan->name, par);
  124. dprintf(idx, "Said to %s: %s\n", chan->dname, par);
  125. }
  126. static void cmd_swhois(int idx, char *par)
  127. {
  128. if (!par[0]) {
  129. dprintf(idx, "Usage: swhois [server/nick] nick\n");
  130. return;
  131. }
  132. putlog(LOG_CMDS, "*", "#%s# swhois %s", dcc[idx].nick, par);
  133. if (!server_online) {
  134. dprintf(idx, "I am currently not connected!\n");
  135. return;
  136. }
  137. char *server = newsplit(&par), *nick = NULL;
  138. if (par[0])
  139. nick = newsplit(&par);
  140. strlcpy(dcc[idx].whois, nick ? nick : server, UHOSTLEN);
  141. dprintf(DP_SERVER, "WHOIS %s %s\n", server, nick ? nick : "");
  142. }
  143. static void cmd_kickban(int idx, char *par)
  144. {
  145. if (!par[0]) {
  146. dprintf(idx, "Usage: kickban [channel|*] [-|@]<nick> [reason]\n");
  147. return;
  148. }
  149. struct chanset_t *chan = NULL;
  150. char *chname = NULL;
  151. bool all = 0;
  152. if (par[0] == '*' && par[1] == ' ') {
  153. all = 1;
  154. newsplit(&par);
  155. } else {
  156. if (strchr(CHANMETA, par[0]) != NULL)
  157. chname = newsplit(&par);
  158. else
  159. chname = 0;
  160. chan = get_channel(idx, chname);
  161. if (!chan || !has_op(idx, chan))
  162. return;
  163. }
  164. putlog(LOG_CMDS, "*", "#%s# (%s) kickban %s", dcc[idx].nick, all ? "*" : chan->dname, par);
  165. char *nick = newsplit(&par), bantype = 0;
  166. if ((nick[0] == '@') || (nick[0] == '-')) {
  167. bantype = nick[0];
  168. nick++;
  169. }
  170. if (match_my_nick(nick)) {
  171. dprintf(idx, "I'm not going to kickban myself.\n");
  172. return;
  173. }
  174. memberlist *m = NULL;
  175. char *s1 = NULL, s[UHOSTLEN] = "";
  176. struct userrec *u = NULL;
  177. if (all)
  178. chan = chanset;
  179. while (chan) {
  180. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  181. if (privchan(user, chan, PRIV_OP)) {
  182. if (all) goto next;
  183. dprintf(idx, "No such channel.\n");
  184. return;
  185. }
  186. else if (!real_chk_op(user, chan, 0)) {
  187. if (all) goto next;
  188. dprintf(idx, "You don't have access to %s\n", chan->dname);
  189. return;
  190. }
  191. if (!channel_active(chan)) {
  192. if (all) goto next;
  193. dprintf(idx, "I'm not on %s right now!\n", chan->dname);
  194. return;
  195. }
  196. if (!me_op(chan)) {
  197. if (all) goto next;
  198. dprintf(idx, "I can't help you now because I'm not a channel op"
  199. " on %s.\n", chan->dname);
  200. return;
  201. }
  202. m = ismember(chan, nick);
  203. if (!m) {
  204. if (all) goto next;
  205. dprintf(idx, "%s is not on %s\n", nick, chan->dname);
  206. return;
  207. }
  208. simple_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
  209. u = get_user_by_host(s);
  210. get_user_flagrec(u, &victim, chan->dname);
  211. if ((chan_master(victim) || glob_master(victim)) &&
  212. !(glob_owner(user) || chan_owner(user))) {
  213. if (all) goto next;
  214. dprintf(idx, "%s is a %s master.\n", nick, chan->dname);
  215. return;
  216. }
  217. if (glob_bot(victim) && !(glob_owner(user) || chan_owner(user))) {
  218. if (all) goto next;
  219. dprintf(idx, "%s is another channel bot!\n", nick);
  220. return;
  221. }
  222. if (use_exempts && (u_match_mask(global_exempts,s) ||
  223. u_match_mask(chan->exempts, s))) {
  224. dprintf(idx, "%s is permanently exempted!\n", nick);
  225. return;
  226. }
  227. if (m->flags & CHANOP)
  228. add_mode(chan, '-', 'o', m->nick);
  229. check_exemptlist(chan, s);
  230. switch (bantype) {
  231. case '@':
  232. s1 = strchr(s, '@');
  233. s1 -= 3;
  234. s1[0] = '*';
  235. s1[1] = '!';
  236. s1[2] = '*';
  237. break;
  238. case '-':
  239. s1 = strchr(s, '!');
  240. s1[1] = '*';
  241. s1--;
  242. s1[0] = '*';
  243. break;
  244. default:
  245. s1 = quickban(chan, m->userhost);
  246. break;
  247. }
  248. if (bantype == '@' || bantype == '-')
  249. do_mask(chan, chan->channel.ban, s1, 'b');
  250. if (!par[0])
  251. par = "requested";
  252. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, bankickprefix, par);
  253. m->flags |= SENTKICK;
  254. u_addmask('b', chan, s1, dcc[idx].nick, par, now + (60 * chan->ban_time), 0);
  255. dprintf(idx, "Kick-banned %s on %s.\n", nick, chan->dname);
  256. next:;
  257. if (!all)
  258. chan = NULL;
  259. else
  260. chan = chan->next;
  261. }
  262. }
  263. static void cmd_voice(int idx, char *par)
  264. {
  265. char *nick = newsplit(&par);
  266. struct chanset_t *chan = NULL;
  267. bool all = 0;
  268. if (par[0] == '*' && !par[1]) {
  269. all = 1;
  270. newsplit(&par);
  271. } else {
  272. chan = get_channel(idx, par);
  273. if (!chan || !has_op(idx, chan))
  274. return;
  275. }
  276. memberlist *m = NULL;
  277. if (all)
  278. chan = chanset;
  279. putlog(LOG_CMDS, "*", "#%s# (%s) voice %s", dcc[idx].nick, all ? "*" : chan->dname , nick);
  280. while (chan) {
  281. if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
  282. if (all) goto next;
  283. dprintf(idx, "Usage: voice <nick> [channel|*]\n");
  284. return;
  285. }
  286. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  287. if (privchan(user, chan, PRIV_VOICE)) {
  288. if (all) goto next;
  289. dprintf(idx, "No such channel.\n");
  290. return;
  291. }
  292. else if (!chk_voice(user, chan) && !chk_op(user, chan)) {
  293. if (all) goto next;
  294. dprintf(idx, "You don't have access to voice on %s\n", chan->dname);
  295. return;
  296. }
  297. if (!channel_active(chan)) {
  298. if (all) goto next;
  299. dprintf(idx, "I'm not on %s right now!\n", chan->dname);
  300. return;
  301. }
  302. if (!me_op(chan)) {
  303. if (all) goto next;
  304. dprintf(idx, "I can't help you now because I'm not a chan op on %s.\n",
  305. chan->dname);
  306. return;
  307. }
  308. m = ismember(chan, nick);
  309. if (!m) {
  310. if (all) goto next;
  311. dprintf(idx, "%s is not on %s.\n", nick, chan->dname);
  312. return;
  313. }
  314. add_mode(chan, '+', 'v', nick);
  315. dprintf(idx, "Gave voice to %s on %s\n", nick, chan->dname);
  316. next:;
  317. if (!all)
  318. chan = NULL;
  319. else
  320. chan = chan->next;
  321. }
  322. }
  323. static void cmd_devoice(int idx, char *par)
  324. {
  325. struct chanset_t *chan = NULL;
  326. char *nick = newsplit(&par);
  327. bool all = 0;
  328. if (par[0] == '*' && !par[1]) {
  329. all = 1;
  330. newsplit(&par);
  331. } else {
  332. chan = get_channel(idx, par);
  333. if (!chan || !has_op(idx, chan))
  334. return;
  335. }
  336. memberlist *m = NULL;
  337. if (all)
  338. chan = chanset;
  339. putlog(LOG_CMDS, "*", "#%s# (%s) devoice %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
  340. while (chan) {
  341. if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
  342. if (all) goto next;
  343. dprintf(idx, "Usage: devoice <nick> [channel|*]\n");
  344. return;
  345. }
  346. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  347. if (privchan(user, chan, PRIV_VOICE)) {
  348. if (all) goto next;
  349. dprintf(idx, "No such channel.\n");
  350. return;
  351. }
  352. else if (!chk_voice(user, chan) && !chk_op(user, chan)) {
  353. if (all) goto next;
  354. dprintf(idx, "You don't have access to devoice on %s\n", chan->dname);
  355. return;
  356. }
  357. if (!channel_active(chan)) {
  358. if (all) goto next;
  359. dprintf(idx, "I'm not on %s right now!\n", chan->dname);
  360. return;
  361. }
  362. if (!me_op(chan)) {
  363. if (all) goto next;
  364. dprintf(idx, "I can't do that right now I'm not a chan op on %s",
  365. chan->dname);
  366. return;
  367. }
  368. m = ismember(chan, nick);
  369. if (!m) {
  370. if (all) goto next;
  371. dprintf(idx, "%s is not on %s.\n", nick, chan->dname);
  372. return;
  373. }
  374. add_mode(chan, '-', 'v', nick);
  375. dprintf(idx, "Devoiced %s on %s\n", nick, chan->dname);
  376. next:;
  377. if (!all)
  378. chan = NULL;
  379. else
  380. chan = chan->next;
  381. }
  382. }
  383. static void cmd_op(int idx, char *par)
  384. {
  385. struct chanset_t *chan = NULL;
  386. char *nick = newsplit(&par);
  387. bool all = 0;
  388. if (par[0] == '*' && !par[1]) {
  389. all = 1;
  390. newsplit(&par);
  391. } else {
  392. chan = get_channel(idx, par);
  393. if (!chan || !has_op(idx, chan))
  394. return;
  395. }
  396. char s[UHOSTLEN] = "";
  397. memberlist *m = NULL;
  398. struct userrec *u = NULL;
  399. if (all)
  400. chan = chanset;
  401. putlog(LOG_CMDS, "*", "#%s# (%s) op %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
  402. while (chan) {
  403. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  404. if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
  405. if (all) goto next;
  406. dprintf(idx, "Usage: op <nick> [channel|*]\n");
  407. return;
  408. }
  409. if (privchan(user, chan, PRIV_OP)) {
  410. if (!all)
  411. dprintf(idx, "No such channel.\n");
  412. goto next;
  413. }
  414. else if (!chk_op(user, chan)) {
  415. if (all) goto next;
  416. dprintf(idx, "You don't have access to op on %s\n", chan->dname);
  417. return;
  418. }
  419. if (!channel_active(chan)) {
  420. if (all) goto next;
  421. dprintf(idx, "I'm not on %s right now!\n", chan->dname);
  422. return;
  423. }
  424. if (!me_op(chan)) {
  425. if (all) goto next;
  426. dprintf(idx, "I can't help you now because I'm not a chan op on %s.\n",
  427. chan->dname);
  428. return;
  429. }
  430. m = ismember(chan, nick);
  431. if (!m) {
  432. if (all) goto next;
  433. dprintf(idx, "%s is not on %s.\n", nick, chan->dname);
  434. return;
  435. }
  436. simple_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
  437. u = get_user_by_host(s);
  438. get_user_flagrec(u, &victim, chan->dname);
  439. if (chk_deop(victim, chan)) {
  440. dprintf(idx, "%s is currently being auto-deopped on %s.\n", m->nick, chan->dname);
  441. if (all) goto next;
  442. return;
  443. }
  444. if (chan_bitch(chan) && !chk_op(victim, chan)) {
  445. dprintf(idx, "%s is not a registered op on %s.\n", m->nick, chan->dname);
  446. if (all) goto next;
  447. return;
  448. }
  449. if (do_op(nick, chan, 0, 1)) {
  450. dprintf(idx, "Gave op to %s on %s.\n", nick, chan->dname);
  451. stats_add(u, 0, 1);
  452. }
  453. next:;
  454. if (!all)
  455. chan = NULL;
  456. else
  457. chan = chan->next;
  458. }
  459. }
  460. static void mass_mode(const char* chname, const char* mode, char *par)
  461. {
  462. char list[101] = "", buf[2048] = "";
  463. size_t list_len = 0, buf_len = 0;
  464. while (par[0]) {
  465. size_t cnt = 0;
  466. *(buf + buf_len++) = 'M';
  467. *(buf + buf_len++) = 'O';
  468. *(buf + buf_len++) = 'D';
  469. *(buf + buf_len++) = 'E';
  470. *(buf + buf_len++) = ' ';
  471. buf_len += strlcpy(buf + buf_len, chname, sizeof(buf) - buf_len);
  472. *(buf + buf_len++) = ' ';
  473. while ((cnt < modesperline) && par[0]) {
  474. /* add +mode into irc cmd */
  475. buf_len += strlcpy(buf + buf_len, mode, sizeof(buf) - buf_len);
  476. /* Make list of nicks */
  477. const char* nick = newsplit(&par);
  478. list_len += strlcpy(list + list_len, nick, sizeof(list) - list_len);
  479. if ((++cnt < modesperline) && par[0])
  480. *(list + list_len++) = ' ';
  481. }
  482. /* buf is so far: 'MODE #chan +o+o+o+o' */
  483. *(buf + buf_len++) = ' ';
  484. buf_len += strlcpy(buf + buf_len, list, sizeof(buf) - buf_len);
  485. *(buf + buf_len++) = '\r';
  486. *(buf + buf_len++) = '\n';
  487. list[0] = list_len = 0;
  488. }
  489. buf[buf_len] = 0;
  490. tputs(serv, buf, buf_len);
  491. }
  492. void mass_request(char *botnick, char *code, char *par)
  493. {
  494. char* mode = newsplit(&par);
  495. if (strlen(mode) > 2 || !strchr("+-kb", mode[0]))
  496. return;
  497. char* chname = newsplit(&par);
  498. if (strchr("+-", mode[0]))
  499. mass_mode(chname, mode, par);
  500. }
  501. static void cmd_mmode(int idx, char *par)
  502. {
  503. char *mode = newsplit(&par);
  504. if (strlen(mode) > 2 || !strchr("+-", mode[0]) || !par[0]) {
  505. dprintf(idx, "Usage: mmode <(+|-)MODE> <#channel> <a|o|v|d|r> [bots=n] [alines=n] [slines=n] [overlap=n] [bitch] [simul] [local]\n");
  506. dprintf(idx, "Ie. mmode -o #chan a\n");
  507. return;
  508. }
  509. putlog(LOG_CMDS, "*", "#%s# mmode %s %s", dcc[idx].nick, mode, par);
  510. char *chname = NULL;
  511. if (strchr(CHANMETA, par[0]) != NULL)
  512. chname = newsplit(&par);
  513. else
  514. chname = NULL;
  515. struct chanset_t *chan = get_channel(idx, chname);
  516. if (chan) {
  517. if (!shouldjoin(chan) || !channel_active(chan)) {
  518. dprintf(idx, "I'm not on %s\n", chan->dname);
  519. return;
  520. }
  521. if (channel_pending(chan)) {
  522. dprintf(idx, "Channel pending.\n");
  523. return;
  524. }
  525. get_user_flagrec(dcc[idx].user, &user, chan->dname, chan);
  526. if (!glob_owner(user) && !chan_owner(user)) {
  527. dprintf(idx, "You do not have mass mode access for %s\n", chan->dname);
  528. return;
  529. }
  530. }
  531. if (!chan || !chname[0]) {
  532. dprintf(idx, "Usage: mmode <(+|-)MODE> <#channel> <a|o|v|d|r> [bots=n] [alines=n] [slines=n] [overlap=n] [bitch] [simul] [local]\n");
  533. dprintf(idx, "Ie. mmode -o #chan a\n");
  534. return;
  535. }
  536. char *who = newsplit(&par);
  537. if (strlen(who) > 1 || !strchr("aovdr", who[0])) {
  538. dprintf(idx, "Usage: mmode <(+|-)MODE> <#channel> <a|o|v|d|r> [bots=n] [alines=n] [slines=n] [overlap=n] [bitch] [simul] [local]\n");
  539. dprintf(idx, "Ie. mmode -o #chan a\n");
  540. dprintf(idx, "a = all.\n");
  541. dprintf(idx, "o = ops.\n");
  542. dprintf(idx, "O = user-op.\n");
  543. dprintf(idx, "v = voices.\n");
  544. dprintf(idx, "d = non-ops.\n");
  545. dprintf(idx, "r = regulars (-ov).\n");
  546. return;
  547. }
  548. memberlist** targets = (memberlist**) my_calloc(1, chan->channel.members * sizeof(memberlist *));
  549. int* overlaps = (int *) my_calloc(1, chan->channel.members * sizeof(int *));
  550. memberlist** chanbots = (memberlist **) my_calloc(1, chan->channel.members * sizeof(memberlist *));
  551. memberlist *m = NULL;
  552. int chanbotcount = 0, targetcount = 0;
  553. for (m = chan->channel.member; m; m = m->next) {
  554. if (m->user) {
  555. if ((m->flags & CHANOP) && m->user->bot &&
  556. (!match_my_nick(m->nick)) && (nextbot(m->user->handle) >= 0)) {
  557. chanbots[chanbotcount++] = m;
  558. continue;
  559. } else if (match_my_nick(m->nick))
  560. continue;
  561. get_user_flagrec(m->user, &user, chan->dname);
  562. }
  563. bool is_target = 0;
  564. if (who[0] == 'o' && (m->flags & CHANOP))
  565. is_target = 1;
  566. else if (who[0] == 'O' && chk_op(user, chan))
  567. is_target = 1;
  568. else if (who[0] == 'd' && !(m->flags & CHANOP))
  569. is_target = 1;
  570. else if (who[0] == 'v' && !(m->flags & CHANOP) && (m->flags & CHANVOICE))
  571. is_target = 1;
  572. else if (who[0] == 'r' && !(m->flags & CHANOP) && !(m->flags & CHANVOICE))
  573. is_target = 1;
  574. else if (who[0] == 'a')
  575. is_target = 1;
  576. if (is_target)
  577. targets[targetcount++] = m;
  578. }
  579. int force_bots = 0, force_alines = 0, force_slines = 0, force_overlap = 0;
  580. bool bitch = 0, simul = 0, local = 0;
  581. while (par && par[0]) {
  582. char *p = newsplit(&par);
  583. if (!egg_strncasecmp(p, "bots=", 5)) {
  584. p += 5;
  585. force_bots = atoi(p);
  586. if ((force_bots < 1) || (force_bots > chanbotcount)) {
  587. dprintf(idx, "bots must be within 1-%i\n", chanbotcount);
  588. free(targets);
  589. free(overlaps);
  590. free(chanbots);
  591. return;
  592. }
  593. } else if (!egg_strncasecmp(p, "alines=", 7)) {
  594. p += 7;
  595. force_alines = atoi(p);
  596. if (force_alines > 5)
  597. dprintf(idx, "alines >5 will fail without a floodless.\n");
  598. if ((force_alines < 1) || (force_alines > 100)) {
  599. dprintf(idx, "alines must be within 1-100\n");
  600. free(targets);
  601. free(overlaps);
  602. free(chanbots);
  603. return;
  604. }
  605. } else if (!egg_strncasecmp(p, "slines=", 7)) {
  606. p += 7;
  607. force_slines = atoi(p);
  608. if ((force_slines < 1) || (force_slines > 20)) {
  609. dprintf(idx, "slines must be within 1-20\n");
  610. dprintf(idx, ">6 will fail without a floodless.\n");
  611. free(targets);
  612. free(overlaps);
  613. free(chanbots);
  614. return;
  615. }
  616. } else if (!egg_strncasecmp(p, "overlap=", 8)) {
  617. p += 8;
  618. force_overlap = atoi(p);
  619. if ((force_overlap < 1) || (force_overlap > 8)) {
  620. dprintf(idx, "overlap must be within 1-8\n");
  621. free(targets);
  622. free(overlaps);
  623. free(chanbots);
  624. return;
  625. }
  626. } else if (!egg_strncasecmp(p, "bitch", 5)) {
  627. bitch = 1;
  628. } else if (!egg_strncasecmp(p, "simul", 5)) {
  629. simul = 1;
  630. } else if (!egg_strncasecmp(p, "local", 5)) {
  631. local = 1;
  632. } else {
  633. dprintf(idx, "Unrecognized option %s\n", p);
  634. free(targets);
  635. free(overlaps);
  636. free(chanbots);
  637. return;
  638. }
  639. }
  640. if (!targetcount) {
  641. dprintf(idx, "No targets found on %s\n", chan->name);
  642. free(targets);
  643. free(overlaps);
  644. free(chanbots);
  645. return;
  646. }
  647. if ((!chanbotcount && !local) || (local && !me_op(chan))) {
  648. dprintf(idx, "No bots opped on %s\n", chan->name);
  649. free(targets);
  650. free(overlaps);
  651. free(chanbots);
  652. return;
  653. }
  654. if (local)
  655. force_bots = 1;
  656. if (local && floodless)
  657. force_alines = force_slines = 100;
  658. int overlap = (force_overlap ? force_overlap : 1);
  659. int needed_modes = (overlap * targetcount);
  660. int max_modes = ((force_bots ? force_bots : chanbotcount) * (force_alines ? force_alines : default_alines) * modesperline);
  661. if (needed_modes > max_modes) {
  662. dprintf(idx, "Need to make %d modes, but the max is %d.\n", needed_modes, max_modes);
  663. dprintf(idx, "Try increasing [alines] or decreasing [overlap].\n");
  664. if (overlap == 1)
  665. dprintf(idx, "Not enough bots.\n");
  666. else
  667. dprintf(idx, "Not enough bots. Try with overlap=1\n");
  668. free(targets);
  669. free(overlaps);
  670. free(chanbots);
  671. return;
  672. }
  673. double bots = 0;
  674. int amodes = 0;
  675. /* ok it's possible... now let's figure out how */
  676. if (force_bots && force_alines) {
  677. /* not much choice... overlap should not autochange */
  678. bots = force_bots;
  679. amodes = force_alines * modesperline;
  680. } else {
  681. if (force_bots) {
  682. /* calc needed modes per bot */
  683. bots = force_bots;
  684. amodes = (needed_modes + ((int)bots - 1)) / (int)bots;
  685. } else if (force_alines) {
  686. amodes = force_alines * modesperline;
  687. bots = (double) needed_modes / amodes;
  688. if (bots > (int)bots) bots = (int)bots+1; /* ceil(bots) */
  689. } else {
  690. /* Try minimizing alines, 1,2,3,4,5 against bots needed */
  691. amodes = 1 * modesperline;
  692. bots = (double) needed_modes / amodes;
  693. if (bots > (int)bots) bots = (int)bots+1; /* ceil(bots) */
  694. for (int min_alines = 2; min_alines <= 5; ++min_alines) {
  695. if ((int)bots > chanbotcount) {
  696. amodes = min_alines * modesperline;
  697. bots = (double) needed_modes / amodes;
  698. if (bots > (int)bots) bots = (int)bots+1; /* ceil(bots) */
  699. } else
  700. break;
  701. }
  702. force_slines = (amodes / modesperline);
  703. /* lol einride is dumb */
  704. if ((int)bots > chanbotcount) {
  705. putlog(LOG_MISC, "*", "Totally fucked calculations in cmd_mmode. this CAN'T happen.");
  706. dprintf(idx, "Something's wrong... bug the coder\n");
  707. free(targets);
  708. free(overlaps);
  709. free(chanbots);
  710. return;
  711. }
  712. }
  713. }
  714. /* How many modes to send */
  715. int smodes;
  716. if (force_slines)
  717. smodes = force_slines * modesperline;
  718. else
  719. smodes = default_alines * modesperline;
  720. if (smodes < amodes)
  721. smodes = amodes;
  722. dprintf(idx, "Mass %s of %s\n", mode, chan->dname);
  723. dprintf(idx, " %d bots used.\n", (int)bots);
  724. dprintf(idx, " %d targets.\n", targetcount);
  725. dprintf(idx, " %d assumed modes per participating bot.\n", amodes);
  726. dprintf(idx, " %d assumed mode lines per participating bot.\n", amodes / modesperline);
  727. dprintf(idx, " %d max modes per participating bot.\n", smodes);
  728. dprintf(idx, " %d max mode lines per participating bot.\n", smodes / modesperline);
  729. dprintf(idx, " %d assumed modes per target nick.\n", overlap);
  730. int tpos = 0, bpos = 0, i = 0;
  731. char **work_list = (char**) my_calloc((int)bots, sizeof(char**));
  732. char *work = NULL;
  733. size_t work_size = 2048;
  734. /* now use bots/modes to distribute nicks to MODE on */
  735. while (bots) {
  736. work = work_list[bpos] = (char*) my_calloc(1, work_size);
  737. if (local)
  738. simple_snprintf(work, work_size, "%s %s", mode, chan->dname);
  739. else if (!simul)
  740. simple_snprintf(work, work_size, "mr %s %s", mode, chan->dname);
  741. else
  742. work[0] = 0;
  743. /* Make list of assumed lines (alines) */
  744. for (i = 0; i < amodes; ++i) {
  745. if (overlaps[tpos]++ < overlap) {
  746. strcat(work, " ");
  747. strcat(work, targets[tpos]->nick);
  748. }
  749. if (++tpos >= targetcount)
  750. tpos = 0;
  751. }
  752. /* Now make lines of throttled modes (send lines) (slines) */
  753. if (smodes > amodes) {
  754. int atpos = tpos;
  755. for (i = 0; i < (smodes - amodes); ++i) {
  756. if (overlaps[atpos]++ < overlap) {
  757. strcat(work, " ");
  758. strcat(work, targets[atpos]->nick);
  759. }
  760. if (++atpos >= targetcount)
  761. atpos = 0;
  762. }
  763. }
  764. --bots;
  765. ++bpos;
  766. }
  767. bots = bpos;
  768. bpos = 0;
  769. /* QUEUE *ALL*, then dump */
  770. while (bots) {
  771. char *work = work_list[bpos];
  772. if (simul)
  773. dprintf(idx, "%-10s MODE %s %s\n", local ? botname : chanbots[bpos]->nick, mode, work);
  774. else if (local)
  775. mass_request(conf.bot->nick, "mr", work);
  776. else
  777. putbot(chanbots[bpos]->user->handle, work);
  778. free(work_list[bpos]);
  779. --bots;
  780. ++bpos;
  781. }
  782. free(work_list);
  783. if (bitch && !simul) {
  784. chan->status |= CHAN_BITCH;
  785. do_chanset(NULL, chan, "+bitch", DO_LOCAL | DO_NET);
  786. }
  787. free(targets);
  788. free(overlaps);
  789. free(chanbots);
  790. return;
  791. }
  792. static void cmd_deop(int idx, char *par)
  793. {
  794. struct chanset_t *chan = NULL;
  795. char *nick = newsplit(&par);
  796. bool all = 0;
  797. if (par[0] == '*' && !par[1]) {
  798. all = 1;
  799. newsplit(&par);
  800. } else {
  801. chan = get_channel(idx, par);
  802. if (!chan || !has_op(idx, chan))
  803. return;
  804. }
  805. char s[UHOSTLEN] = "";
  806. memberlist *m = NULL;
  807. struct userrec *u = NULL;
  808. if (all)
  809. chan = chanset;
  810. putlog(LOG_CMDS, "*", "#%s# (%s) deop %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
  811. while (chan) {
  812. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  813. if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
  814. if (all) goto next;
  815. dprintf(idx, "Usage: deop <nick> [channel|*]\n");
  816. return;
  817. }
  818. if (privchan(user, chan, PRIV_OP)) {
  819. if (all) goto next;
  820. dprintf(idx, "No such channel.\n");
  821. }
  822. else if (!real_chk_op(user, chan, 0)) {
  823. if (all) goto next;
  824. dprintf(idx, "You don't have access to deop on %s\n", chan->dname);
  825. return;
  826. }
  827. if (!channel_active(chan)) {
  828. if (all) goto next;
  829. dprintf(idx, "I'm not on %s right now!\n", chan->dname);
  830. return;
  831. }
  832. if (!me_op(chan)) {
  833. if (all) goto next;
  834. dprintf(idx, "I can't help you now because I'm not a chan op on %s.\n",
  835. chan->dname);
  836. return;
  837. }
  838. m = ismember(chan, nick);
  839. if (!m) {
  840. if (all) goto next;
  841. dprintf(idx, "%s is not on %s.\n", nick, chan->dname);
  842. return;
  843. }
  844. if (match_my_nick(nick)) {
  845. if (all) goto next;
  846. dprintf(idx, "I'm not going to deop myself.\n");
  847. return;
  848. }
  849. simple_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
  850. u = get_user_by_host(s);
  851. get_user_flagrec(u, &victim, chan->dname);
  852. if ((chan_master(victim) || glob_master(victim)) &&
  853. !(chan_owner(user) || glob_owner(user))) {
  854. dprintf(idx, "%s is a master for %s.\n", m->nick, chan->dname);
  855. if (all) goto next;
  856. return;
  857. }
  858. if (chk_op(victim, chan) && !(chan_master(user) || glob_master(user))) {
  859. dprintf(idx, "%s has the op flag for %s.\n", m->nick, chan->dname);
  860. if (all) goto next;
  861. return;
  862. }
  863. add_mode(chan, '-', 'o', nick);
  864. dprintf(idx, "Deopped %s on %s.\n", nick, chan->dname);
  865. next:;
  866. if (!all)
  867. chan = NULL;
  868. else
  869. chan = chan->next;
  870. }
  871. }
  872. static void cmd_kick(int idx, char *par)
  873. {
  874. if (!par[0]) {
  875. dprintf(idx, "Usage: kick [channel|*] <nick> [reason]\n");
  876. return;
  877. }
  878. struct chanset_t *chan = NULL;
  879. char *chname = NULL;
  880. bool all = 0;
  881. if (par[0] == '*' && par[1] == ' ') {
  882. all = 1;
  883. newsplit(&par);
  884. } else {
  885. if (strchr(CHANMETA, par[0]) != NULL)
  886. chname = newsplit(&par);
  887. else
  888. chname = 0;
  889. chan = get_channel(idx, chname);
  890. if (!chan || !has_op(idx, chan))
  891. return;
  892. }
  893. putlog(LOG_CMDS, "*", "#%s# (%s) kick %s", dcc[idx].nick, all ? "*" : chan->dname, par);
  894. char *nick = newsplit(&par);
  895. if (!par[0])
  896. par = "request";
  897. if (match_my_nick(nick)) {
  898. dprintf(idx, "I'm not going to kick myself.\n");
  899. return;
  900. }
  901. char s[UHOSTLEN] = "";
  902. memberlist *m = NULL;
  903. struct userrec *u = NULL;
  904. if (all)
  905. chan = chanset;
  906. while (chan) {
  907. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  908. if (privchan(user, chan, PRIV_OP)) {
  909. if (all) goto next;
  910. dprintf(idx, "No such channel.\n");
  911. return;
  912. }
  913. else if (!real_chk_op(user, chan, 0)) {
  914. if (all) goto next;
  915. dprintf(idx, "You don't have access to kick on %s\n", chan->dname);
  916. return;
  917. }
  918. if (!channel_active(chan)) {
  919. if (all) goto next;
  920. dprintf(idx, "I'm not on %s right now!\n", chan->dname);
  921. return;
  922. }
  923. if (!me_op(chan)) {
  924. if (all) goto next;
  925. dprintf(idx, "I can't help you now because I'm not a channel op on %s.\n", chan->dname);
  926. return;
  927. }
  928. m = ismember(chan, nick);
  929. if (!m) {
  930. if (all) goto next;
  931. dprintf(idx, "%s is not on %s\n", nick, chan->dname);
  932. return;
  933. }
  934. simple_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
  935. u = get_user_by_host(s);
  936. get_user_flagrec(u, &victim, chan->dname);
  937. if (chk_op(victim, chan) && !(chan_master(user) || glob_master(user))) {
  938. if (all) goto next;
  939. dprintf(idx, "%s is a legal op.\n", nick);
  940. return;
  941. }
  942. if ((chan_master(victim) || glob_master(victim)) &&
  943. !(glob_owner(user) || chan_owner(user))) {
  944. if (all) goto next;
  945. dprintf(idx, "%s is a %s master.\n", nick, chan->dname);
  946. return;
  947. }
  948. if (glob_bot(victim) && !(glob_owner(user) || chan_owner(user))) {
  949. dprintf(idx, "%s is another channel bot!\n", nick);
  950. return;
  951. }
  952. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, par);
  953. m->flags |= SENTKICK;
  954. dprintf(idx, "Kicked %s on %s.\n", nick, chan->dname);
  955. next:;
  956. if (!all)
  957. chan = NULL;
  958. else
  959. chan = chan->next;
  960. }
  961. }
  962. static void cmd_getkey(int idx, char *par)
  963. {
  964. struct chanset_t *chan = NULL;
  965. chan = get_channel(idx, par);
  966. if (!chan || !has_op(idx, chan))
  967. return;
  968. putlog(LOG_CMDS, "*", "#%s getkey %s", dcc[idx].nick, par);
  969. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  970. if (privchan(user, chan, PRIV_OP)) {
  971. dprintf(idx, "No such channel.\n");
  972. return;
  973. }
  974. else if (!real_chk_op(user, chan, 0)) {
  975. dprintf(idx, "You don't have access for %s\n", chan->dname);
  976. return;
  977. }
  978. if (!(channel_pending(chan) || channel_active(chan))) {
  979. dprintf(idx, "I'm not on %s right now.\n", chan->dname);
  980. return;
  981. }
  982. char outbuf[201] = "";
  983. if (!chan->channel.key[0])
  984. simple_snprintf(outbuf, sizeof(outbuf), "%s has no key set.", chan->dname);
  985. else
  986. simple_snprintf(outbuf, sizeof(outbuf), "Key for %s is: %s", chan->dname, chan->channel.key);
  987. if (chan->key_prot[0])
  988. simple_snprintf(outbuf, sizeof(outbuf), "%s (Enforcing +k %s)", outbuf, chan->key_prot);
  989. dprintf(idx, "%s\n", outbuf);
  990. }
  991. static void cmd_mop(int idx, char *par)
  992. {
  993. struct chanset_t *chan = NULL;
  994. bool found = 0, all = 0;
  995. if (par[0] == '*' && !par[1]) {
  996. get_user_flagrec(dcc[idx].user, &user, NULL);
  997. if (!glob_owner(user)) {
  998. dprintf(idx, "You do not have access to mop '*'\n");
  999. return;
  1000. }
  1001. all = 1;
  1002. chan = chanset;
  1003. newsplit(&par);
  1004. } else {
  1005. if (par[0] && (strchr(CHANMETA, par[0]) != NULL)) {
  1006. chan = get_channel(idx, newsplit(&par), 0);
  1007. } else
  1008. chan = get_channel(idx, "", 0);
  1009. }
  1010. putlog(LOG_CMDS, "*", "#%s# (%s) mop %s", dcc[idx].nick, all ? "*" : (chan ? chan->dname : ""), par);
  1011. if (!chan)
  1012. return;
  1013. if (!all) {
  1014. dprintf(idx, "Usage: mop <channel|*>\n");
  1015. return;
  1016. }
  1017. memberlist *m = NULL;
  1018. char s[256] = "";
  1019. while (chan) {
  1020. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1021. if (privchan(user, chan, PRIV_OP)) {
  1022. if (all) goto next;
  1023. dprintf(idx, "No such channel.\n");
  1024. return;
  1025. }
  1026. if (!chk_op(user, chan)) {
  1027. if (all) goto next;
  1028. dprintf(idx, "You are not a channel op on %s.\n", chan->dname);
  1029. return;
  1030. }
  1031. if (!me_op(chan)) {
  1032. if (all) goto next;
  1033. dprintf(idx, "I am not opped on %s.\n", chan->dname);
  1034. return;
  1035. }
  1036. if (channel_active(chan) && !channel_pending(chan)) {
  1037. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1038. if (!m->user) {
  1039. sprintf(s, "%s!%s", m->nick, m->userhost);
  1040. m->user = get_user_by_host(s);
  1041. if (!m->user && doresolv(chan) && m->userip[0]) {
  1042. simple_snprintf(s, sizeof(s), "%s!%s", m->nick, m->userip);
  1043. m->user = get_user_by_host(s);
  1044. }
  1045. }
  1046. if (m->user && u_pass_match(m->user, "-"))
  1047. continue; /* dont op users without a pass */
  1048. get_user_flagrec(m->user, &victim, chan->dname);
  1049. if (!chan_hasop(m) && !glob_bot(victim) && chk_op(victim, chan)) {
  1050. found++;
  1051. dprintf(idx, "Gave op to '%s' as '%s' on %s\n", m->user->handle, m->nick, chan->dname);
  1052. do_op(m->nick, chan, 0, 0);
  1053. }
  1054. }
  1055. } else {
  1056. if (!all)
  1057. dprintf(idx, "Channel %s is not active or is pending.\n", chan->dname);
  1058. return;
  1059. }
  1060. if (!found && !all)
  1061. dprintf(idx, "No one to op on %s\n", chan->dname);
  1062. next:;
  1063. if (!all)
  1064. chan = NULL;
  1065. else
  1066. chan = chan->next;
  1067. }
  1068. }
  1069. static void cmd_find(int idx, char *par)
  1070. {
  1071. if (!par[0]) {
  1072. dprintf(idx, "Usage: find <nick!ident@host.com>|<user> (wildcard * allowed)\n");
  1073. return;
  1074. }
  1075. putlog(LOG_CMDS, "*", "#%s# find %s", dcc[idx].nick, par);
  1076. struct chanset_t *chan = NULL, **cfound = NULL;
  1077. memberlist *m = NULL, **found = NULL;
  1078. int fcount = 0;
  1079. bool tr = 0, lookup_user = 0;
  1080. struct userrec *u = NULL;
  1081. if (!strchr(par, '!')) {
  1082. lookup_user = 1;
  1083. u = get_user_by_handle(userlist, par);
  1084. if (!u) {
  1085. dprintf(idx, "No such user: %s\n", par);
  1086. return;
  1087. }
  1088. }
  1089. /* make a list of members in found[] */
  1090. for (chan = chanset; chan; chan = chan->next) {
  1091. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1092. if (!privchan(user, chan, PRIV_OP)) {
  1093. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1094. char s[UHOSTLEN] = "";
  1095. sprintf(s, "%s!%s", m->nick, m->userhost);
  1096. if (!m->user && !m->tried_getuser) {
  1097. m->user = get_user_by_host(s);
  1098. if (!m->user && doresolv(chan) && m->userip[0]) {
  1099. simple_snprintf(s, sizeof(s), "%s!%s", m->nick, m->userip);
  1100. m->user = get_user_by_host(s);
  1101. }
  1102. m->tried_getuser = 1;
  1103. }
  1104. if ((!lookup_user && wild_match(par, s)) || (lookup_user && m->user == u)) {
  1105. fcount++;
  1106. if (!found) {
  1107. found = (memberlist **) my_calloc(1, sizeof(memberlist *) * 100);
  1108. cfound = (struct chanset_t **) my_calloc(1, sizeof(struct chanset_t *) * 100);
  1109. }
  1110. found[fcount - 1] = m;
  1111. cfound[fcount - 1] = chan;
  1112. if (fcount == 100) {
  1113. tr = 1;
  1114. break;
  1115. }
  1116. }
  1117. }
  1118. }
  1119. if (fcount == 100) {
  1120. tr = 1;
  1121. break;
  1122. }
  1123. }
  1124. if (fcount) {
  1125. char tmp[1024] = "";
  1126. int findex, i;
  1127. for (findex = 0; findex < fcount; findex++) {
  1128. if (found[findex]) {
  1129. sprintf(tmp, "%s!%s %s%s%s on %s", found[findex]->nick, found[findex]->userhost,
  1130. found[findex]->user ? "(user:" : "", found[findex]->user ? found[findex]->user->handle : "", found[findex]->user ? ")" : "",
  1131. cfound[findex]->name);
  1132. for (i = findex + 1; i < fcount; i++) {
  1133. if (found[i] && (!strcmp(found[i]->nick, found[findex]->nick))) {
  1134. sprintf(tmp + strlen(tmp), ", %s", cfound[i]->name);
  1135. found[i] = NULL;
  1136. }
  1137. }
  1138. dprintf(idx, "%s\n", tmp);
  1139. }
  1140. }
  1141. free(found);
  1142. free(cfound);
  1143. } else {
  1144. dprintf(idx, "No matches for %s on any channels.\n", par);
  1145. }
  1146. if (tr)
  1147. dprintf(idx, "(more than 100 matches; list truncated)\n");
  1148. dprintf(idx, "--- Found %d matches.\n", fcount);
  1149. }
  1150. static void do_invite(int idx, char *par, bool op)
  1151. {
  1152. struct chanset_t *chan = NULL;
  1153. memberlist *m = NULL;
  1154. bool all = 0;
  1155. char *nick = NULL;
  1156. if (!par[0])
  1157. par = dcc[idx].nick;
  1158. nick = newsplit(&par);
  1159. if (par[0] == '*' && !par[1]) {
  1160. all = 1;
  1161. newsplit(&par);
  1162. } else {
  1163. chan = get_channel(idx, par);
  1164. if (!chan || !has_op(idx, chan))
  1165. return;
  1166. }
  1167. if (all)
  1168. chan = chanset;
  1169. putlog(LOG_CMDS, "*", "#%s# (%s) %s %s", dcc[idx].nick, all ? "*" : chan->dname, op ? "iop" : "invite", nick);
  1170. while (chan) {
  1171. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1172. if (privchan(user, chan, PRIV_OP)) {
  1173. if (all) goto next;
  1174. dprintf(idx, "No such channel.\n");
  1175. }
  1176. else if (!real_chk_op(user, chan, 0)) {
  1177. if (all) goto next;
  1178. dprintf(idx, "You don't have access to invite to %s\n", chan->dname);
  1179. return;
  1180. }
  1181. if (!me_op(chan)) {
  1182. if (all) goto next;
  1183. if (chan->channel.mode & CHANINV) {
  1184. dprintf(idx, "I can't help you now because I'm not a channel op on %s", chan->dname);
  1185. return;
  1186. }
  1187. if (!channel_active(chan)) {
  1188. dprintf(idx, "I'm not on %s right now!\n", chan->dname);
  1189. return;
  1190. }
  1191. }
  1192. m = ismember(chan, nick);
  1193. if (m && !chan_issplit(m)) {
  1194. if (all) goto next;
  1195. dprintf(idx, "%s is already on %s!\n", nick, chan->dname);
  1196. return;
  1197. }
  1198. cache_invite(chan, nick, NULL, NULL, op, 0);
  1199. dprintf(idx, "Inviting %s to %s.\n", nick, chan->dname);
  1200. next:;
  1201. if (!all)
  1202. chan = NULL;
  1203. else
  1204. chan = chan->next;
  1205. }
  1206. }
  1207. static void cmd_invite(int idx, char *par)
  1208. {
  1209. do_invite(idx, par, 0);
  1210. }
  1211. #ifdef CACHE
  1212. static void cmd_iop(int idx, char *par)
  1213. {
  1214. do_invite(idx, par, 1);
  1215. }
  1216. #endif /* CACHE */
  1217. static void cmd_authed(int idx, char *par)
  1218. {
  1219. putlog(LOG_CMDS, "*", "#%s# authed", dcc[idx].nick);
  1220. dprintf(idx, "Authed:\n");
  1221. Auth::TellAuthed(idx);
  1222. }
  1223. static void cmd_channel(int idx, char *par)
  1224. {
  1225. struct chanset_t *chan = NULL;
  1226. chan = get_channel(idx, par);
  1227. if (!chan || !has_op(idx, chan))
  1228. return;
  1229. char handle[HANDLEN + 1] = "", s[UHOSTLEN] = "", s1[UHOSTLEN] = "", atrflag = 0, chanflag[2] = "";
  1230. memberlist *m = NULL;
  1231. size_t maxnicklen, maxhandlen;
  1232. char format[81] = "";
  1233. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1234. putlog(LOG_CMDS, "*", "#%s# (%s) channel", dcc[idx].nick, chan->dname);
  1235. strlcpy(s, getchanmode(chan), sizeof s);
  1236. if (channel_pending(chan)) {
  1237. simple_snprintf(s1, sizeof s1, "Processing channel %s", chan->dname);
  1238. } else if (channel_active(chan)) {
  1239. simple_snprintf(s1, sizeof s1, "Channel %s", chan->dname);
  1240. } else {
  1241. simple_snprintf(s1, sizeof s1, "Desiring channel %s", chan->dname);
  1242. }
  1243. dprintf(idx, "%s, %d member%s, mode %s:\n", s1, chan->channel.members,
  1244. chan->channel.members == 1 ? "" : "s", s);
  1245. if (chan->channel.topic)
  1246. dprintf(idx, "%s: %s\n", "Channel Topic", chan->channel.topic);
  1247. if (channel_active(chan)) {
  1248. /* find max nicklen and handlen */
  1249. maxnicklen = maxhandlen = 0;
  1250. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1251. if (strlen(m->nick) > maxnicklen)
  1252. maxnicklen = strlen(m->nick);
  1253. if (m->user)
  1254. if (strlen(m->user->handle) > maxhandlen)
  1255. maxhandlen = strlen(m->user->handle);
  1256. }
  1257. if (maxnicklen < 9) maxnicklen = 9;
  1258. if (maxhandlen < 9) maxhandlen = 9;
  1259. dprintf(idx, "(n = owner, m = master, o = op, d = deop, b = bot) CAP:global\n");
  1260. egg_snprintf(format, sizeof format, " %%-%us %%-%us %%-6s %%-4s %%-5s %%s %%s\n",
  1261. maxnicklen, maxhandlen);
  1262. dprintf(idx, format, "NICKNAME", "HANDLE", " JOIN", " HOPS", "IDLE", "USER@HOST", "USER@IP");
  1263. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1264. if (m->joined > 0) {
  1265. if ((now - (m->joined)) > 86400)
  1266. egg_strftime(s, 6, "%d%b", gmtime(&(m->joined)));
  1267. else
  1268. egg_strftime(s, 6, "%H:%M", gmtime(&(m->joined)));
  1269. } else
  1270. strlcpy(s, " --- ", sizeof s);
  1271. if (m->user == NULL) {
  1272. simple_snprintf(s1, sizeof s1, "%s!%s", m->nick, m->userhost);
  1273. m->user = get_user_by_host(s1);
  1274. if (!m->user && doresolv(chan) && m->userip[0]) {
  1275. simple_snprintf(s1, sizeof(s1), "%s!%s", m->nick, m->userip);
  1276. m->user = get_user_by_host(s1);
  1277. }
  1278. m->tried_getuser = 1;
  1279. }
  1280. if (m->user == NULL)
  1281. strlcpy(handle, "*", sizeof handle);
  1282. else
  1283. strlcpy(handle, m->user->handle, sizeof handle);
  1284. get_user_flagrec(m->user, &user, chan->dname);
  1285. /* Determine status char to use */
  1286. if (glob_bot(user) && chk_op(user, chan))
  1287. atrflag = 'B';
  1288. else if (glob_bot(user))
  1289. atrflag = 'b';
  1290. else if (glob_owner(user))
  1291. atrflag = 'N';
  1292. else if (chan_owner(user))
  1293. atrflag = 'n';
  1294. else if (glob_master(user))
  1295. atrflag = 'M';
  1296. else if (chan_master(user))
  1297. atrflag = 'm';
  1298. else if (glob_deop(user))
  1299. atrflag = 'D';
  1300. else if (chan_deop(user))
  1301. atrflag = 'd';
  1302. else if (glob_autoop(user))
  1303. atrflag = 'A';
  1304. else if (chan_autoop(user))
  1305. atrflag = 'a';
  1306. else if (glob_op(user) && !privchan(user, chan, PRIV_OP))
  1307. atrflag = 'O';
  1308. else if (chan_op(user))
  1309. atrflag = 'o';
  1310. else if (glob_quiet(user))
  1311. atrflag = 'Q';
  1312. else if (chan_quiet(user))
  1313. atrflag = 'q';
  1314. else if (glob_voice(user) && !privchan(user, chan, PRIV_VOICE))
  1315. atrflag = 'V';
  1316. else if (chan_voice(user))
  1317. atrflag = 'v';
  1318. else if (glob_kick(user))
  1319. atrflag = 'K';
  1320. else if (chan_kick(user))
  1321. atrflag = 'k';
  1322. else if (glob_wasoptest(user))
  1323. atrflag = 'W';
  1324. else if (chan_wasoptest(user))
  1325. atrflag = 'w';
  1326. else
  1327. atrflag = ' ';
  1328. if (chan_hasop(m))
  1329. chanflag[1] = '@';
  1330. else if (chan_hasvoice(m))
  1331. chanflag[1] = '+';
  1332. else
  1333. chanflag[1] = ' ';
  1334. if (m->flags & OPER)
  1335. chanflag[0] = 'O';
  1336. else
  1337. chanflag[0] = ' ';
  1338. if (chan_issplit(m)) {
  1339. egg_snprintf(format, sizeof format,
  1340. "%%c%%c%%-%us %%-%us %%s %%c <- netsplit, %%lus\n",
  1341. maxnicklen, maxhandlen);
  1342. dprintf(idx, format, chanflag[0],chanflag[1], m->nick, handle, s, atrflag,
  1343. now - (m->split));
  1344. } else if (!rfc_casecmp(m->nick, botname)) {
  1345. egg_snprintf(format, sizeof format,
  1346. "%%c%%c%%-%us %%-%us %%s %%c <- it's me!\n",
  1347. maxnicklen, maxhandlen);
  1348. dprintf(idx, format, chanflag[0], chanflag[1], m->nick, handle, s, atrflag);
  1349. } else {
  1350. /* Determine idle time */
  1351. if (now - (m->last) > 86400)
  1352. egg_snprintf(s1, sizeof s1, "%2lid", ((now - (m->last)) / 86400));
  1353. else if (now - (m->last) > 3600)
  1354. egg_snprintf(s1, sizeof s1, "%2lih", ((now - (m->last)) / 3600));
  1355. else if (now - (m->last) > 180)
  1356. egg_snprintf(s1, sizeof s1, "%2lim", ((now - (m->last)) / 60));
  1357. else
  1358. strlcpy(s1, " ", sizeof s1);
  1359. egg_snprintf(format, sizeof format, "%%c%%c%%-%us %%-%us %%s %%c %%d %%s %%s %%s\n",
  1360. maxnicklen, maxhandlen);
  1361. dprintf(idx, format, chanflag[0], chanflag[1], m->nick, handle, s, atrflag, m->hops,
  1362. s1, m->userhost, m->userip);
  1363. }
  1364. if (chan_fakeop(m))
  1365. dprintf(idx, " (FAKE CHANOP GIVEN BY SERVER)\n");
  1366. if (chan_sentop(m))
  1367. dprintf(idx, " (pending +o -- I'm lagged)\n");
  1368. if (chan_sentdeop(m))
  1369. dprintf(idx, " (pending -o -- I'm lagged)\n");
  1370. if (chan_sentkick(m))
  1371. dprintf(idx, " (pending kick)\n");
  1372. }
  1373. }
  1374. dprintf(idx, "End of channel info.\n");
  1375. }
  1376. static void cmd_topic(int idx, char *par)
  1377. {
  1378. struct chanset_t *chan = NULL;
  1379. if (par[0] && (strchr(CHANMETA, par[0]) != NULL)) {
  1380. chan = get_channel(idx, newsplit(&par));
  1381. } else
  1382. chan = get_channel(idx, "");
  1383. if (!chan || !has_op(idx, chan))
  1384. return;
  1385. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1386. if (!channel_active(chan)) {
  1387. dprintf(idx, "I'm not on %s right now!\n", chan->dname);
  1388. return;
  1389. }
  1390. if (!par[0]) {
  1391. if (chan->channel.topic) {
  1392. dprintf(idx, "The topic for %s is: %s\n", chan->dname,
  1393. chan->channel.topic);
  1394. } else {
  1395. dprintf(idx, "No topic is set for %s\n", chan->dname);
  1396. }
  1397. } else if (channel_optopic(chan) && !me_op(chan)) {
  1398. dprintf(idx, "I'm not a channel op on %s and the channel %s",
  1399. "is +t.\n", chan->dname);
  1400. } else {
  1401. dprintf(DP_SERVER, "TOPIC %s :%s\n", chan->name, par);
  1402. dprintf(idx, "Changing topic...\n");
  1403. putlog(LOG_CMDS, "*", "#%s# (%s) topic %s", dcc[idx].nick,
  1404. chan->dname, par);
  1405. }
  1406. }
  1407. static void cmd_resetbans(int idx, char *par)
  1408. {
  1409. struct chanset_t *chan = get_channel(idx, newsplit(&par));
  1410. if (!chan || !has_op(idx, chan))
  1411. return;
  1412. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1413. putlog(LOG_CMDS, "*", "#%s# (%s) resetbans", dcc[idx].nick, chan->dname);
  1414. dprintf(idx, "Resetting bans on %s...\n", chan->dname);
  1415. resetbans(chan);
  1416. }
  1417. static void cmd_resetexempts(int idx, char *par)
  1418. {
  1419. struct chanset_t *chan = get_channel(idx, newsplit(&par));
  1420. if (!chan || !has_op(idx, chan))
  1421. return;
  1422. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1423. putlog(LOG_CMDS, "*", "#%s# (%s) resetexempts", dcc[idx].nick, chan->dname);
  1424. dprintf(idx, "Resetting exempts on %s...\n", chan->dname);
  1425. resetexempts(chan);
  1426. }
  1427. static void cmd_resetinvites(int idx, char *par)
  1428. {
  1429. struct chanset_t *chan = get_channel(idx, newsplit(&par));
  1430. if (!chan || !has_op(idx, chan))
  1431. return;
  1432. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1433. putlog(LOG_CMDS, "*", "#%s# (%s) resetinvites", dcc[idx].nick, chan->dname);
  1434. dprintf(idx, "Resetting resetinvites on %s...\n", chan->dname);
  1435. resetinvites(chan);
  1436. }
  1437. static void cmd_adduser(int idx, char *par)
  1438. {
  1439. if ((!par[0]) || ((par[0] =='!') && (!par[1]))) {
  1440. dprintf(idx, "Usage: adduser <nick> [handle]\n");
  1441. return;
  1442. }
  1443. char *nick = NULL, *hand = NULL;
  1444. struct chanset_t *chan = NULL;
  1445. struct userrec *u = NULL;
  1446. memberlist *m = NULL;
  1447. char s[UHOSTLEN] = "", s1[UHOSTLEN] = "", s2[MAXPASSLEN + 1] = "", s3[MAXPASSLEN + 1] = "", tmp[50] = "";
  1448. int atr = dcc[idx].user ? dcc[idx].user->flags : 0;
  1449. bool statichost = 0;
  1450. char *p1 = s1;
  1451. putlog(LOG_CMDS, "*", "#%s# adduser %s", dcc[idx].nick, par);
  1452. nick = newsplit(&par);
  1453. /* This flag allows users to have static host (added by drummer, 20Apr99) */
  1454. if (nick[0] == '!') {
  1455. statichost = 1;
  1456. nick++;
  1457. }
  1458. if (!par[0]) {
  1459. hand = nick;
  1460. } else {
  1461. bool ok = 1;
  1462. for (char *p = par; *p; p++)
  1463. if ((*p <= 32) || (*p >= 127))
  1464. ok = 0;
  1465. if (!ok) {
  1466. dprintf(idx, "You can't have strange characters in a nick.\n");
  1467. return;
  1468. } else if (strchr("-,+*=:!.@#;$", par[0]) != NULL) {
  1469. dprintf(idx, "You can't start a nick with '%c'.\n", par[0]);
  1470. return;
  1471. }
  1472. hand = par;
  1473. }
  1474. for (chan = chanset; chan; chan = chan->next) {
  1475. m = ismember(chan, nick);
  1476. if (m)
  1477. break;
  1478. }
  1479. if (!m) {
  1480. dprintf(idx, "%s is not on any channels I monitor\n", nick);
  1481. return;
  1482. }
  1483. if (strlen(hand) > HANDLEN)
  1484. hand[HANDLEN] = 0;
  1485. simple_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
  1486. if ((u = get_user_by_host(s))) {
  1487. dprintf(idx, "%s is already known as %s.\n", nick, u->handle);
  1488. return;
  1489. }
  1490. u = get_user_by_handle(userlist, hand);
  1491. if (u && (u->flags & (USER_OWNER | USER_MASTER)) &&
  1492. !(atr & USER_OWNER) && egg_strcasecmp(dcc[idx].nick, hand)) {
  1493. dprintf(idx, "You can't add hostmasks to the bot owner/master.\n");
  1494. return;
  1495. }
  1496. if (!statichost)
  1497. maskhost(s, s1);
  1498. else {
  1499. strlcpy(s1, s, sizeof s1);
  1500. p1 = strchr(s1, '!');
  1501. if (strchr("~^+=-", p1[1]))
  1502. p1[1] = '?';
  1503. p1--;
  1504. p1[0] = '*';
  1505. }
  1506. if (!u) {
  1507. userlist = adduser(userlist, hand, p1, "-", USER_DEFAULT, 0);
  1508. u = get_user_by_handle(userlist, hand);
  1509. sprintf(tmp, "%li %s", now, dcc[idx].nick);
  1510. set_user(&USERENTRY_ADDED, u, tmp);
  1511. make_rand_str(s2, MAXPASSLEN);
  1512. set_user(&USERENTRY_PASS, u, s2);
  1513. make_rand_str(s3, MAXPASSLEN);
  1514. set_user(&USERENTRY_SECPASS, u, s3);
  1515. dprintf(idx, "Added [%s]%s with no flags.\n", hand, p1);
  1516. dprintf(idx, "%s's initial password set to \002%s\002\n", hand, s2);
  1517. dprintf(idx, "%s's initial secpass set to \002%s\002\n", hand, s3);
  1518. dprintf(DP_HELP, "PRIVMSG %s :*** You've been add to this botnet as '%s' with the host '%s'. Ask a botnet admin for the msg cmds. Your initial password is: %s\n", nick, hand, p1, s2);
  1519. } else {
  1520. dprintf(idx, "Added hostmask %s to %s.\n", p1, u->handle);
  1521. addhost_by_handle(hand, p1);
  1522. get_user_flagrec(u, &user, chan->dname);
  1523. check_this_user(hand, 0, NULL);
  1524. }
  1525. }
  1526. static void cmd_deluser(int idx, char *par)
  1527. {
  1528. if (!par[0]) {
  1529. dprintf(idx, "Usage: deluser <nick>\n");
  1530. return;
  1531. }
  1532. char *nick = NULL, s[UHOSTLEN] = "", *added = NULL;
  1533. struct chanset_t *chan = NULL;
  1534. memberlist *m = NULL;
  1535. struct userrec *u = NULL;
  1536. nick = newsplit(&par);
  1537. for (chan = chanset; chan; chan = chan->next) {
  1538. m = ismember(chan, nick);
  1539. if (m)
  1540. break;
  1541. }
  1542. if (!m) {
  1543. dprintf(idx, "%s is not on any channels I monitor\n", nick);
  1544. return;
  1545. }
  1546. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1547. simple_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
  1548. if (!(u = get_user_by_host(s))) {
  1549. dprintf(idx, "%s is not a valid user.\n", nick);
  1550. return;
  1551. }
  1552. added = (char *) get_user(&USERENTRY_ADDED, u);
  1553. newsplit(&added);
  1554. get_user_flagrec(u, &victim, NULL);
  1555. if (isowner(u->handle)) {
  1556. dprintf(idx, "You can't remove a permanent bot owner!\n");
  1557. } else if (glob_admin(victim) && !isowner(dcc[idx].nick)) {
  1558. dprintf(idx, "You can't remove an admin!\n");
  1559. } else if (glob_owner(victim)) {
  1560. dprintf(idx, "You can't remove a bot owner!\n");
  1561. } else if (chan_owner(victim) && !glob_owner(user)) {
  1562. dprintf(idx, "You can't remove a channel owner!\n");
  1563. } else if (chan_master(victim) && !(glob_owner(user) || chan_owner(user))) {
  1564. dprintf(idx, "You can't remove a channel master!\n");
  1565. } else if (glob_bot(victim) && !glob_owner(user)) {
  1566. dprintf(idx, "You can't remove a bot!\n");
  1567. } else if (!glob_master(user) && egg_strcasecmp(dcc[idx].nick, added)) {
  1568. dprintf(idx, "Sorry, you may not delete this user as you did not add them.\n");
  1569. } else {
  1570. char buf[HANDLEN + 1] = "";
  1571. strlcpy(buf, u->handle, sizeof buf);
  1572. buf[HANDLEN] = 0;
  1573. if (deluser(u->handle)) {
  1574. dprintf(idx, "Deleted %s.\n", buf); /* ?!?! :) */
  1575. putlog(LOG_CMDS, "*", "#%s# deluser %s [%s]", dcc[idx].nick, nick, buf);
  1576. } else {
  1577. dprintf(idx, "Failed.\n");
  1578. }
  1579. }
  1580. }
  1581. static void cmd_reset(int idx, char *par)
  1582. {
  1583. struct chanset_t *chan = NULL;
  1584. if (par[0]) {
  1585. chan = findchan_by_dname(par);
  1586. if (chan)
  1587. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1588. if (!chan || privchan(user, chan, PRIV_OP)) {
  1589. dprintf(idx, "I don't monitor that channel.\n");
  1590. } else {
  1591. get_user_flagrec(dcc[idx].user, &user, par);
  1592. if (!glob_master(user) && !chan_master(user)) {
  1593. dprintf(idx, "You are not a master on %s.\n", chan->dname);
  1594. } else if (!channel_active(chan)) {
  1595. dprintf(idx, "I'm not on %s at the moment!\n", chan->dname);
  1596. } else {
  1597. putlog(LOG_CMDS, "*", "#%s# reset %s", dcc[idx].nick, par);
  1598. dprintf(idx, "Resetting channel info for %s...\n", chan->dname);
  1599. reset_chan_info(chan);
  1600. }
  1601. }
  1602. } else if (!(dcc[idx].user->flags & USER_MASTER)) {
  1603. dprintf(idx, "You are not a Bot Master.\n");
  1604. } else {
  1605. putlog(LOG_CMDS, "*", "#%s# reset all", dcc[idx].nick);
  1606. dprintf(idx, "Resetting channel info for all channels...\n");
  1607. for (chan = chanset; chan; chan = chan->next) {
  1608. if (channel_active(chan) || (!channel_active(chan) && shouldjoin(chan)))
  1609. reset_chan_info(chan);
  1610. }
  1611. }
  1612. }
  1613. static cmd_t irc_dcc[] =
  1614. {
  1615. {"act", "o|o", (Function) cmd_act, NULL, LEAF},
  1616. {"adduser", "m|m", (Function) cmd_adduser, NULL, LEAF|AUTH},
  1617. {"authed", "n", (Function) cmd_authed, NULL, LEAF},
  1618. {"channel", "o|o", (Function) cmd_channel, NULL, LEAF},
  1619. {"deluser", "m|m", (Function) cmd_deluser, NULL, LEAF|AUTH},
  1620. {"deop", "o|o", (Function) cmd_deop, NULL, LEAF|AUTH},
  1621. {"devoice", "o|o", (Function) cmd_devoice, NULL, LEAF|AUTH},
  1622. {"getkey", "o|o", (Function) cmd_getkey, NULL, LEAF|AUTH},
  1623. {"find", "", (Function) cmd_find, NULL, LEAF|AUTH},
  1624. {"invite", "o|o", (Function) cmd_invite, NULL, LEAF|AUTH},
  1625. #ifdef CACHE
  1626. {"iop", "o|o", (Function) cmd_iop, NULL, LEAF|AUTH},
  1627. #endif /* CACHE */
  1628. {"kick", "o|o", (Function) cmd_kick, NULL, LEAF|AUTH},
  1629. {"kickban", "o|o", (Function) cmd_kickban, NULL, LEAF|AUTH},
  1630. {"mmode", "n|n", (Function) cmd_mmode, NULL, LEAF},
  1631. {"mop", "n|m", (Function) cmd_mop, NULL, LEAF|AUTH},
  1632. {"msg", "o", (Function) cmd_msg, NULL, LEAF|AUTH},
  1633. {"op", "o|o", (Function) cmd_op, NULL, LEAF|AUTH},
  1634. {"reset", "m|m", (Function) cmd_reset, NULL, LEAF|AUTH},
  1635. {"resetbans", "o|o", (Function) cmd_resetbans, NULL, LEAF|AUTH},
  1636. {"resetexempts", "o|o", (Function) cmd_resetexempts, NULL, LEAF|AUTH},
  1637. {"resetinvites", "o|o", (Function) cmd_resetinvites, NULL, LEAF|AUTH},
  1638. {"say", "o|o", (Function) cmd_say, NULL, LEAF},
  1639. {"swhois", "", (Function) cmd_swhois, NULL, LEAF|AUTH},
  1640. {"topic", "o|o", (Function) cmd_topic, NULL, LEAF|AUTH},
  1641. {"voice", "o|o", (Function) cmd_voice, NULL, LEAF|AUTH},
  1642. {NULL, NULL, NULL, NULL, 0}
  1643. };