cmdsirc.c 44 KB

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