1
0

cmdsirc.c 46 KB

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