cmdsirc.c 53 KB

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