cmdsirc.c 46 KB

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