cmdsirc.c 45 KB

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