cmdsirc.c 52 KB

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