cmdschan.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  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. * cmdschan.c -- part of channels.mod
  22. * commands from a user via dcc that cause server interaction
  23. *
  24. */
  25. #include <ctype.h>
  26. #include "src/mod/console.mod/console.h"
  27. static struct flag_record user = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  28. static struct flag_record victim = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  29. static void cmd_pls_mask(const char type, int idx, char *par)
  30. {
  31. const char *cmd = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
  32. if (!par[0]) {
  33. dprintf(idx, "Usage: +%s <hostmask> [channel] [%%<XdXhXm>] [reason]\n", cmd);
  34. return;
  35. }
  36. char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
  37. unsigned long int expire_time = 0, expire_foo;
  38. int sticky = 0;
  39. struct chanset_t *chan = NULL;
  40. who = newsplit(&par);
  41. if (par[0] && strchr(CHANMETA, par[0]))
  42. chname = newsplit(&par);
  43. else
  44. chname = 0;
  45. if (chname || !(dcc[idx].user->flags & USER_MASTER)) {
  46. if (!chname)
  47. chname = dcc[idx].u.chat->con_chan;
  48. get_user_flagrec(dcc[idx].user, &user, chname);
  49. chan = findchan_by_dname(chname);
  50. /* *shrug* ??? (guppy:10Feb1999) */
  51. if (!chan || (chan && privchan(user, chan, PRIV_OP))) {
  52. dprintf(idx, "No such channel.\n");
  53. return;
  54. } else if (!chk_op(user, chan)) {
  55. dprintf(idx, "You don't have access to set %ss on %s.\n", cmd, chname);
  56. return;
  57. }
  58. } else
  59. chan = 0;
  60. /* Added by Q and Solal -- Requested by Arty2, special thanx :) */
  61. if (par[0] == '%') {
  62. p = newsplit(&par);
  63. p_expire = p + 1;
  64. while (*(++p) != 0) {
  65. switch (tolower(*p)) {
  66. case 'd':
  67. *p = 0;
  68. expire_foo = strtol(p_expire, NULL, 10);
  69. if (expire_foo > 365)
  70. expire_foo = 365;
  71. expire_time += 86400 * expire_foo;
  72. p_expire = p + 1;
  73. break;
  74. case 'h':
  75. *p = 0;
  76. expire_foo = strtol(p_expire, NULL, 10);
  77. if (expire_foo > 8760)
  78. expire_foo = 8760;
  79. expire_time += 3600 * expire_foo;
  80. p_expire = p + 1;
  81. break;
  82. case 'm':
  83. *p = 0;
  84. expire_foo = strtol(p_expire, NULL, 10);
  85. if (expire_foo > 525600)
  86. expire_foo = 525600;
  87. expire_time += 60 * expire_foo;
  88. p_expire = p + 1;
  89. }
  90. }
  91. }
  92. if (!par[0])
  93. par = "requested";
  94. else if (strlen(par) > MASKREASON_MAX)
  95. par[MASKREASON_MAX] = 0;
  96. if (strlen(who) > UHOSTMAX - 4)
  97. who[UHOSTMAX - 4] = 0;
  98. /* Fix missing ! or @ BEFORE checking against myself */
  99. if (!strchr(who, '!')) {
  100. if (!strchr(who, '@'))
  101. simple_snprintf(s, sizeof s, "%s!*@*", who); /* Lame nick ban */
  102. else
  103. simple_snprintf(s, sizeof s, "*!%s", who);
  104. } else if (!strchr(who, '@'))
  105. simple_snprintf(s, sizeof s, "%s@*", who); /* brain-dead? */
  106. else
  107. strlcpy(s, who, sizeof s);
  108. if (conf.bot->hub)
  109. simple_snprintf(s1, sizeof s1, "%s!%s@%s", origbotname, botuser, conf.bot->net.host);
  110. else
  111. simple_snprintf(s1, sizeof s1, "%s!%s", botname, botuserhost);
  112. if (type == 'b' && s1[0] && wild_match(s, s1)) {
  113. dprintf(idx, "I'm not going to ban myself.\n");
  114. putlog(LOG_CMDS, "*", "#%s# attempted +ban %s", dcc[idx].nick, s);
  115. return;
  116. }
  117. /* IRC can't understand bans longer than 70 characters */
  118. if (strlen(s) > 70) {
  119. s[69] = '*';
  120. s[70] = 0;
  121. }
  122. if (chan) {
  123. u_addmask(type, chan, s, dcc[idx].nick, par, expire_time ? now + expire_time : 0, 0);
  124. if (par[0] == '*') {
  125. sticky = 1;
  126. par++;
  127. putlog(LOG_CMDS, "*", "#%s# (%s) +%s %s %s (%s) (sticky)", dcc[idx].nick, dcc[idx].u.chat->con_chan, cmd, s, chan->dname, par);
  128. dprintf(idx, "New %s sticky %s: %s (%s)\n", chan->dname, cmd, s, par);
  129. } else {
  130. putlog(LOG_CMDS, "*", "#%s# (%s) +%s %s %s (%s)", dcc[idx].nick, dcc[idx].u.chat->con_chan, cmd, s, chan->dname, par);
  131. dprintf(idx, "New %s %s: %s (%s)\n", chan->dname, cmd, s, par);
  132. }
  133. if (!conf.bot->hub) {
  134. if (type == 'e' || type == 'I')
  135. add_mode(chan, '+', type, s);
  136. /* Avoid unnesessary modes if you got +dynamicbans
  137. */
  138. else
  139. check_this_ban(chan, s, sticky);
  140. } else
  141. write_userfile(idx);
  142. } else {
  143. u_addmask(type, NULL, s, dcc[idx].nick, par, expire_time ? now + expire_time : 0, 0);
  144. if (par[0] == '*') {
  145. sticky = 1;
  146. par++;
  147. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +%s %s (%s) (sticky)", dcc[idx].nick, cmd, s, par);
  148. dprintf(idx, "New sticky %s: %s (%s)\n", cmd, s, par);
  149. } else {
  150. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +%s %s (%s)", dcc[idx].nick, cmd, s, par);
  151. dprintf(idx, "New %s: %s (%s)\n", cmd, s, par);
  152. }
  153. if (!conf.bot->hub) {
  154. for (chan = chanset; chan != NULL; chan = chan->next) {
  155. if (type == 'b')
  156. check_this_ban(chan, s, sticky);
  157. else
  158. add_mode(chan, '+', type, s);
  159. }
  160. } else
  161. write_userfile(idx);
  162. }
  163. }
  164. static void cmd_pls_ban(int idx, char *par)
  165. {
  166. cmd_pls_mask('b', idx, par);
  167. }
  168. static void cmd_pls_exempt(int idx, char *par)
  169. {
  170. cmd_pls_mask('e', idx, par);
  171. }
  172. static void cmd_pls_invite(int idx, char *par)
  173. {
  174. cmd_pls_mask('I', idx, par);
  175. }
  176. static void cmd_mns_mask(const char type, int idx, char *par)
  177. {
  178. const char *cmd = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
  179. if (!par[0]) {
  180. dprintf(idx, "Usage: -%s <hostmask> [channel]\n", cmd);
  181. return;
  182. }
  183. int i = 0, j;
  184. struct chanset_t *chan = NULL;
  185. char s[UHOSTLEN] = "", *who = NULL, *chname = NULL, *mask = NULL;
  186. masklist *m = NULL;
  187. who = newsplit(&par);
  188. if (par[0] && strchr(CHANMETA, par[0]))
  189. chname = newsplit(&par);
  190. else
  191. chname = dcc[idx].u.chat->con_chan;
  192. if (chname || !(dcc[idx].user->flags & USER_MASTER)) {
  193. if (!chname)
  194. chname = dcc[idx].u.chat->con_chan;
  195. get_user_flagrec(dcc[idx].user, &user, chname);
  196. if (strchr(CHANMETA, chname[0]) && privchan(user, findchan_by_dname(chname), PRIV_OP)) {
  197. dprintf(idx, "No such channel.\n");
  198. return;
  199. }
  200. if (!chk_op(user, findchan_by_dname(chname)))
  201. return;
  202. }
  203. strlcpy(s, who, sizeof s);
  204. i = u_delmask(type, NULL, s, (dcc[idx].user->flags & USER_MASTER));
  205. if (i > 0) {
  206. if (lastdeletedmask)
  207. mask = lastdeletedmask;
  208. else
  209. mask = s;
  210. putlog(LOG_CMDS, "*", "#%s# -%s %s", dcc[idx].nick, cmd, mask);
  211. dprintf(idx, "%s %s: %s\n", "Removed", cmd, s);
  212. if (!conf.bot->hub) {
  213. for (chan = chanset; chan != NULL; chan = chan->next)
  214. add_mode(chan, '-', type, mask);
  215. } else
  216. write_userfile(idx);
  217. return;
  218. }
  219. /* Channel-specific ban? */
  220. if (chname)
  221. chan = findchan_by_dname(chname);
  222. if (chan) {
  223. m = type == 'b' ? chan->channel.ban : type == 'e' ? chan->channel.exempt : chan->channel.invite;
  224. if (str_isdigit(who) && (i = atoi(who)) > 0) {
  225. simple_snprintf(s, sizeof s, "%d", i);
  226. j = u_delmask(type, chan, s, 1);
  227. if (j > 0) {
  228. if (lastdeletedmask)
  229. mask = lastdeletedmask;
  230. else
  231. mask = s;
  232. putlog(LOG_CMDS, "*", "#%s# (%s) -%s %s", dcc[idx].nick, chan->dname, cmd, mask);
  233. dprintf(idx, "Removed %s channel %s: %s\n", chan->dname, cmd, mask);
  234. if (!conf.bot->hub)
  235. add_mode(chan, '-', type, mask);
  236. else
  237. write_userfile(idx);
  238. return;
  239. }
  240. i = 0;
  241. for (; m && m->mask && m->mask[0]; m = m->next) {
  242. if ((!u_equals_mask(type == 'b' ? global_bans : type == 'e' ? global_exempts :
  243. global_invites, m->mask)) &&
  244. (!u_equals_mask(type == 'b' ? chan->bans : type == 'e' ? chan->exempts :
  245. chan->invites, m->mask))) {
  246. i++;
  247. if (i == -j) {
  248. dprintf(idx, "%s %s '%s' on %s.\n", "Removed", cmd, m->mask, chan->dname);
  249. putlog(LOG_CMDS, "*", "#%s# (%s) -%s %s [on channel]", dcc[idx].nick, chan->dname, cmd, who);
  250. if (!conf.bot->hub)
  251. add_mode(chan, '-', type, m->mask);
  252. else
  253. write_userfile(idx);
  254. return;
  255. }
  256. }
  257. }
  258. } else {
  259. j = u_delmask(type, chan, who, 1);
  260. if (j > 0) {
  261. putlog(LOG_CMDS, "*", "#%s# (%s) -%s %s", dcc[idx].nick, dcc[idx].u.chat->con_chan, cmd, who);
  262. dprintf(idx, "Removed %s channel %s: %s\n", chname, cmd, who);
  263. if (!conf.bot->hub)
  264. add_mode(chan, '-', type, who);
  265. else
  266. write_userfile(idx);
  267. return;
  268. }
  269. for (; m && m->mask && m->mask[0]; m = m->next) {
  270. if (!rfc_casecmp(m->mask, who)) {
  271. dprintf(idx, "%s %s '%s' on %s.\n", "Removed", cmd, m->mask, chan->dname);
  272. putlog(LOG_CMDS, "*", "#%s# (%s) -%s %s [on channel]", dcc[idx].nick, chan->dname, cmd, who);
  273. if (!conf.bot->hub)
  274. add_mode(chan, '-', type, m->mask);
  275. else
  276. write_userfile(idx);
  277. return;
  278. }
  279. }
  280. }
  281. }
  282. dprintf(idx, "No such %s.\n", cmd);
  283. }
  284. static void cmd_mns_ban(int idx, char *par)
  285. {
  286. cmd_mns_mask('b', idx, par);
  287. }
  288. static void cmd_mns_exempt(int idx, char *par)
  289. {
  290. cmd_mns_mask('e', idx, par);
  291. }
  292. static void cmd_mns_invite(int idx, char *par)
  293. {
  294. cmd_mns_mask('I', idx, par);
  295. }
  296. static void cmd_masks(const char type, int idx, char *par)
  297. {
  298. const char *str_type = (type == 'b' ? "ban" : type == 'e' ? "exempt" : "invite");
  299. if (!egg_strcasecmp(par, "all")) {
  300. putlog(LOG_CMDS, "*", "#%s# %ss all", dcc[idx].nick, str_type);
  301. tell_masks(type, idx, 1, "");
  302. } else if (!egg_strcasecmp(par, "global")) {
  303. putlog(LOG_CMDS, "*", "#%s# %ss global", dcc[idx].nick, str_type);
  304. tell_masks(type, idx, 1, "", 1);
  305. } else {
  306. putlog(LOG_CMDS, "*", "#%s# %ss %s", dcc[idx].nick, str_type, par);
  307. tell_masks(type, idx, 0, par);
  308. }
  309. }
  310. static void cmd_bans(int idx, char *par)
  311. {
  312. cmd_masks('b', idx, par);
  313. }
  314. static void cmd_exempts(int idx, char *par)
  315. {
  316. cmd_masks('e', idx, par);
  317. }
  318. static void cmd_invites(int idx, char *par)
  319. {
  320. cmd_masks('I', idx, par);
  321. }
  322. static void cmd_info(int idx, char *par)
  323. {
  324. if (!use_info) {
  325. dprintf(idx, "Info storage is turned off.\n");
  326. return;
  327. }
  328. char s[512] = "", *chname = NULL, *s1 = (char *) get_user(&USERENTRY_INFO, dcc[idx].user);
  329. bool locked = 0;
  330. if (s1 && s1[0] == '@')
  331. locked = 1;
  332. if (par[0] && strchr(CHANMETA, par[0])) {
  333. chname = newsplit(&par);
  334. if (!findchan_by_dname(chname)) {
  335. dprintf(idx, "No such channel.\n");
  336. return;
  337. }
  338. get_handle_chaninfo(dcc[idx].nick, chname, s);
  339. if (s[0] == '@')
  340. locked = 1;
  341. s1 = s;
  342. } else
  343. chname = 0;
  344. if (!par[0]) {
  345. if (s1 && s1[0] == '@')
  346. s1++;
  347. if (s1 && s1[0]) {
  348. if (chname) {
  349. dprintf(idx, "Info on %s: %s\n", chname, s1);
  350. dprintf(idx, "Use 'info %s none' to remove it.\n", chname);
  351. } else {
  352. dprintf(idx, "Default info: %s\n", s1);
  353. dprintf(idx, "Use 'info none' to remove it.\n");
  354. }
  355. } else
  356. dprintf(idx, "No info has been set for you.\n");
  357. putlog(LOG_CMDS, "*", "#%s# info %s", dcc[idx].nick, chname ? chname : "");
  358. return;
  359. }
  360. if (locked && !(dcc[idx].user && (dcc[idx].user->flags & USER_MASTER))) {
  361. dprintf(idx, "Your info line is locked. Sorry.\n");
  362. return;
  363. }
  364. if (!egg_strcasecmp(par, "none")) {
  365. if (chname) {
  366. par[0] = 0;
  367. set_handle_chaninfo(userlist, dcc[idx].nick, chname, NULL);
  368. dprintf(idx, "Removed your info line on %s.\n", chname);
  369. putlog(LOG_CMDS, "*", "#%s# info %s none", dcc[idx].nick, chname);
  370. } else {
  371. set_user(&USERENTRY_INFO, dcc[idx].user, NULL);
  372. dprintf(idx, "Removed your default info line.\n");
  373. putlog(LOG_CMDS, "*", "#%s# info none", dcc[idx].nick);
  374. }
  375. return;
  376. }
  377. /* if (par[0] == '@') This is stupid, and prevents a users info from being locked */
  378. /* par++; without .tcl, or a tcl script, aka, 'half-assed' -poptix 4Jun01 */
  379. if (chname) {
  380. set_handle_chaninfo(userlist, dcc[idx].nick, chname, par);
  381. dprintf(idx, "Your info on %s is now: %s\n", chname, par);
  382. putlog(LOG_CMDS, "*", "#%s# info %s ...", dcc[idx].nick, chname);
  383. } else {
  384. set_user(&USERENTRY_INFO, dcc[idx].user, par);
  385. dprintf(idx, "Your default info is now: %s\n", par);
  386. putlog(LOG_CMDS, "*", "#%s# info ...", dcc[idx].nick);
  387. }
  388. }
  389. static void cmd_chinfo(int idx, char *par)
  390. {
  391. if (!use_info) {
  392. dprintf(idx, "Info storage is turned off.\n");
  393. return;
  394. }
  395. char *handle = newsplit(&par);
  396. if (!handle[0]) {
  397. dprintf(idx, "Usage: chinfo <handle> [channel] <new-info>\n");
  398. return;
  399. }
  400. struct userrec *u1 = get_user_by_handle(userlist, handle);
  401. if (!u1 || (u1 && !whois_access(dcc[idx].user, u1))) {
  402. dprintf(idx, "No such user.\n");
  403. return;
  404. }
  405. char *chname = NULL;
  406. if (par[0] && strchr(CHANMETA, par[0])) {
  407. chname = newsplit(&par);
  408. if (!findchan_by_dname(chname)) {
  409. dprintf(idx, "No such channel.\n");
  410. return;
  411. }
  412. } else
  413. chname = 0;
  414. if (u1->bot && !(dcc[idx].user->flags & USER_MASTER)) {
  415. dprintf(idx, "You have to be master to change bots info.\n");
  416. return;
  417. }
  418. if ((u1->flags & USER_OWNER) && !(dcc[idx].user->flags & USER_OWNER)) {
  419. dprintf(idx, "You can't change info for the bot owner.\n");
  420. return;
  421. }
  422. if (chname) {
  423. get_user_flagrec(dcc[idx].user, &user, chname);
  424. get_user_flagrec(u1, &victim, chname);
  425. if ((chan_owner(victim) || glob_owner(victim)) &&
  426. !(glob_owner(user) || chan_owner(user))) {
  427. dprintf(idx, "You can't change info for the channel owner.\n");
  428. return;
  429. }
  430. }
  431. putlog(LOG_CMDS, "*", "#%s# chinfo %s %s %s", dcc[idx].nick, handle, chname ? chname : par, chname ? par : "");
  432. if (!egg_strcasecmp(par, "none"))
  433. par[0] = 0;
  434. if (chname) {
  435. set_handle_chaninfo(userlist, handle, chname, par);
  436. if (par[0] == '@')
  437. dprintf(idx, "New info (LOCKED) for %s on %s: %s\n", handle, chname,
  438. &par[1]);
  439. else if (par[0])
  440. dprintf(idx, "New info for %s on %s: %s\n", handle, chname, par);
  441. else
  442. dprintf(idx, "Wiped info for %s on %s\n", handle, chname);
  443. if (conf.bot->hub)
  444. write_userfile(idx);
  445. } else {
  446. set_user(&USERENTRY_INFO, u1, par[0] ? par : NULL);
  447. if (par[0] == '@')
  448. dprintf(idx, "New default info (LOCKED) for %s: %s\n", handle, &par[1]);
  449. else if (par[0])
  450. dprintf(idx, "New default info for %s: %s\n", handle, par);
  451. else
  452. dprintf(idx, "Wiped default info for %s\n", handle);
  453. if (conf.bot->hub)
  454. write_userfile(idx);
  455. }
  456. }
  457. static void cmd_checkchannels(int idx, char *par)
  458. {
  459. putlog(LOG_CMDS, "*", "#%s# checkchannels", dcc[idx].nick);
  460. botnet_send_cmd_broad(-1, conf.bot->nick, dcc[idx].nick, idx, "chans");
  461. }
  462. static void cmd_slowjoin(int idx, char *par)
  463. {
  464. int intvl = 0, delay = 0, count = 0;
  465. char *chname = NULL, *p = NULL, buf[2048] = "", buf2[RESULT_LEN] = "";
  466. struct chanset_t *chan = NULL;
  467. tand_t *bot = NULL;
  468. /* slowjoin #chan 60 */
  469. putlog(LOG_CMDS, "*", "#%s# slowjoin %s", dcc[idx].nick, par);
  470. chname = newsplit(&par);
  471. p = newsplit(&par);
  472. intvl = atoi(p);
  473. if (!chname[0] || !p[0]) {
  474. dprintf(idx, "Usage: slowjoin <channel> <interval-seconds> [channel options]\n");
  475. return;
  476. }
  477. if (intvl < 10) {
  478. dprintf(idx, "Interval must be at least 10 seconds\n");
  479. return;
  480. }
  481. if ((chan = findchan_by_dname(chname))) {
  482. dprintf(idx, "Already on %s\n", chan->dname);
  483. return;
  484. }
  485. if (!strchr(CHANMETA, chname[0])) {
  486. dprintf(idx, "Invalid channel name\n");
  487. return;
  488. }
  489. simple_snprintf(buf, sizeof(buf), "+inactive addedby %s addedts %li", dcc[idx].nick, (long)now);
  490. if (par[0])
  491. strlcat(buf, par, sizeof(buf));
  492. if (channel_add(buf2, chname, buf) == ERROR) {
  493. dprintf(idx, "Invalid channel or channel options.\n");
  494. if (buf2[0])
  495. dprintf(idx, " %s\n", buf2);
  496. return;
  497. }
  498. buf2[0] = 0;
  499. chan = findchan_by_dname(chname);
  500. if (!chan) {
  501. dprintf(idx, "Hmmm... Channel didn't get added. Weird *shrug*\n");
  502. return;
  503. }
  504. simple_snprintf(buf2, sizeof(buf2), "cjoin %s %s", chan->dname, buf);
  505. putallbots(buf2);
  506. if (conf.bot->hub)
  507. count = 0;
  508. chan->status &= ~CHAN_INACTIVE;
  509. for (bot = tandbot; bot; bot = bot->next) {
  510. char tmp[100] = "";
  511. tmp[0] = 0;
  512. if (bot->u) {
  513. if (bot_hublevel(bot->u) < 999) {
  514. simple_snprintf(tmp, sizeof(tmp), "sj %s 0", chname);
  515. } else {
  516. struct flag_record fr = { FR_CHAN|FR_GLOBAL|FR_BOT, 0, 0, 0 };
  517. get_user_flagrec(bot->u, &fr, chname);
  518. /* Only send the 'sj' command if the bot is supposed to be in the channel (backups and such) */
  519. if (bot_shouldjoin(bot->u, &fr, chan)) {
  520. /* Variation: 60 secs intvl should be 60 +/- 15 */
  521. int v = (random() % (intvl / 2)) - (intvl / 4);
  522. delay += intvl;
  523. simple_snprintf(tmp, sizeof(tmp), "sj %s %i", chname, delay + v);
  524. count++;
  525. }
  526. }
  527. if (tmp[0])
  528. putbot(bot->bot, tmp);
  529. }
  530. }
  531. if (!conf.bot->hub && shouldjoin(chan))
  532. count++;
  533. dprintf(idx, "%i bots joining %s during the next %i seconds\n", count, chan->dname, delay);
  534. if (!conf.bot->hub && shouldjoin(chan) && !channel_joining(chan)) {
  535. dprintf(DP_MODE, "JOIN %s %s\n", chan->name, chan->key_prot);
  536. chan->status |= CHAN_JOINING;
  537. }
  538. }
  539. static void cmd_slowpart(int idx, char *par)
  540. {
  541. int intvl = 0, delay = 0, count = 1;
  542. char *chname = NULL, *p = NULL;
  543. struct chanset_t *chan = NULL;
  544. tand_t *bot = NULL;
  545. /* slowpart #chan 60 */
  546. putlog(LOG_CMDS, "*", "#%s# slowpart %s", dcc[idx].nick, par);
  547. chname = newsplit(&par);
  548. p = newsplit(&par);
  549. intvl = atoi(p);
  550. if (!chname[0] || !p[0]) {
  551. dprintf(idx, "Usage: slowpart <channel> <interval-seconds>\n");
  552. return;
  553. }
  554. if (intvl < 10) {
  555. dprintf(idx, "Interval must be at least 10 seconds\n");
  556. return;
  557. }
  558. if (!(chan = findchan_by_dname(chname))) {
  559. dprintf(idx, "No such channel %s\n", chname);
  560. return;
  561. }
  562. remove_channel(chan);
  563. if (conf.bot->hub)
  564. write_userfile(-1);
  565. dprintf(idx, "Channel %s removed from the bot.\n", chname);
  566. dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
  567. if (findchan_by_dname(chname)) {
  568. dprintf(idx, "Failed to remove channel.\n");
  569. return;
  570. }
  571. if (conf.bot->hub)
  572. count = 0;
  573. for (bot = tandbot; bot; bot = bot->next) {
  574. char tmp[100] = "";
  575. tmp[0] = 0;
  576. if (bot->u) {
  577. if (bot_hublevel(bot->u) < 999) { /* HUB */
  578. simple_snprintf(tmp, sizeof(tmp), "sp %s 0", chname);
  579. } else { /* LEAF */
  580. struct flag_record fr = { FR_CHAN|FR_GLOBAL|FR_BOT, 0, 0, 0 };
  581. get_user_flagrec(bot->u, &fr, chname);
  582. /* Only send the 'sp' command if the bot is supposed to be in the channel (backups and such) */
  583. if (bot_shouldjoin(bot->u, &fr, chan)) {
  584. /* Variation: 60 secs intvl should be 60 +/- 15 */
  585. int v = (random() % (intvl / 2)) - (intvl / 4);
  586. delay += intvl;
  587. simple_snprintf(tmp, sizeof(tmp), "sp %s %i", chname, delay + v);
  588. count++;
  589. }
  590. }
  591. if (tmp[0])
  592. putbot(bot->bot, tmp);
  593. }
  594. }
  595. dprintf(idx, "%i bots parting %s during the next %i seconds\n", count, chname, delay);
  596. if (!conf.bot->hub)
  597. dprintf(DP_MODE, "PART %s\n", chname);
  598. }
  599. static void cmd_stick_yn(int idx, char *par, int yn)
  600. {
  601. int i = 0, j;
  602. struct chanset_t *chan = NULL;
  603. char *stick_type = NULL, s[UHOSTLEN] = "", chname[81] = "", type = 0, *str_type = NULL;
  604. maskrec *channel_list = NULL;
  605. stick_type = newsplit(&par);
  606. strlcpy(s, newsplit(&par), sizeof s);
  607. strlcpy(chname, newsplit(&par), sizeof chname);
  608. if (egg_strcasecmp(stick_type, "exempt") &&
  609. egg_strcasecmp(stick_type, "invite") &&
  610. egg_strcasecmp(stick_type, "ban")) {
  611. strlcpy(chname, s, sizeof chname);
  612. strlcpy(s, stick_type, sizeof s);
  613. stick_type = "ban";
  614. }
  615. if (!s[0]) {
  616. dprintf(idx, "Usage: %sstick [ban/exempt/invite] <hostmask or number> [channel]\n", yn ? "" : "un");
  617. return;
  618. }
  619. /* Now deal with exemptions */
  620. if (!egg_strcasecmp(stick_type, "exempt")) {
  621. type = 'e';
  622. str_type = "exempt";
  623. } else if (!egg_strcasecmp(stick_type, "invite")) {
  624. type = 'I';
  625. str_type = "invite";
  626. } else if (!egg_strcasecmp(stick_type, "ban")) {
  627. type = 'b';
  628. str_type = "ban";
  629. } else
  630. return;
  631. if (!chname[0]) {
  632. channel_list = (type == 'b' ? global_bans : type == 'e' ? global_exempts : global_invites);
  633. i = u_setsticky_mask(NULL, channel_list, s, (dcc[idx].user->flags & USER_MASTER) ? yn : -1, type);
  634. if (i > 0) {
  635. putlog(LOG_CMDS, "*", "#%s# %sstick %s %s", dcc[idx].nick, yn ? "" : "un", str_type, s);
  636. dprintf(idx, "%stuck %s: %s\n", yn ? "S" : "Uns", str_type, s);
  637. if (!conf.bot->hub) {
  638. struct chanset_t *achan = NULL;
  639. for (achan = chanset; achan != NULL; achan = achan->next)
  640. check_this_mask(type, achan, s, yn);
  641. } else
  642. write_userfile(idx);
  643. return;
  644. }
  645. strlcpy(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  646. }
  647. /* Channel-specific mask? */
  648. if (!(chan = findchan_by_dname(chname))) {
  649. dprintf(idx, "No such channel.\n");
  650. return;
  651. }
  652. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  653. if (privchan(user, chan, PRIV_OP)) {
  654. dprintf(idx, "No such channel.\n");
  655. return;
  656. }
  657. channel_list = (type == 'b' ? chan->bans : type == 'e' ? chan->exempts : chan->invites);
  658. if (str_isdigit(s)) {
  659. /* substract the numer of global masks to get the number of the channel masks */
  660. j = atoi(s);
  661. j -= count_mask(type == 'b' ? global_bans : type == 'e' ? global_exempts : global_invites);
  662. simple_snprintf(s, sizeof s, "%d", j);
  663. }
  664. j = u_setsticky_mask(chan, channel_list, s, yn, type);
  665. if (j > 0) {
  666. putlog(LOG_CMDS, "*", "#%s# %sstick %s %s %s", dcc[idx].nick, yn ? "" : "un", str_type, s, chname);
  667. dprintf(idx, "%stuck %s %s: %s\n", yn ? "S" : "Uns", chname, str_type, s);
  668. if (!conf.bot->hub)
  669. check_this_mask(type, chan, s, yn);
  670. else
  671. write_userfile(idx);
  672. return;
  673. }
  674. dprintf(idx, "No such %s.\n", str_type);
  675. }
  676. static void cmd_stick(int idx, char *par)
  677. {
  678. cmd_stick_yn(idx, par, 1);
  679. }
  680. static void cmd_unstick(int idx, char *par)
  681. {
  682. cmd_stick_yn(idx, par, 0);
  683. }
  684. static void cmd_pls_chrec(int idx, char *par)
  685. {
  686. char *nick = NULL, *chn = NULL;
  687. struct chanset_t *chan = NULL;
  688. struct userrec *u1 = NULL;
  689. struct chanuserrec *chanrec = NULL;
  690. if (!par[0]) {
  691. dprintf(idx, "Usage: +chrec <user> [channel]\n");
  692. return;
  693. }
  694. nick = newsplit(&par);
  695. u1 = get_user_by_handle(userlist, nick);
  696. if (!u1) {
  697. dprintf(idx, "No such user.\n");
  698. return;
  699. }
  700. if (!par[0])
  701. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  702. else {
  703. chn = newsplit(&par);
  704. chan = findchan_by_dname(chn);
  705. }
  706. if (!chan) {
  707. dprintf(idx, "No such channel.\n");
  708. return;
  709. }
  710. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  711. get_user_flagrec(u1, &victim, chan->dname);
  712. if (privchan(user, chan, PRIV_OP)) {
  713. dprintf(idx, "No such channel.\n");
  714. return;
  715. }
  716. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  717. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  718. (glob_owner(victim) && !glob_owner(user))) {
  719. dprintf(idx, "You have no permission to do that.\n");
  720. return;
  721. }
  722. chanrec = get_chanrec(u1, chan->dname);
  723. if (chanrec) {
  724. dprintf(idx, "User %s already has a channel record for %s.\n",
  725. nick, chan->dname);
  726. return;
  727. }
  728. putlog(LOG_CMDS, "*", "#%s# +chrec %s %s", dcc[idx].nick, nick, chan->dname);
  729. add_chanrec(u1, chan->dname);
  730. dprintf(idx, "Added %s channel record for %s.\n", chan->dname, nick);
  731. if (conf.bot->hub)
  732. write_userfile(idx);
  733. }
  734. static void cmd_mns_chrec(int idx, char *par)
  735. {
  736. char *nick = NULL, *chn = NULL;
  737. struct userrec *u1 = NULL;
  738. struct chanuserrec *chanrec = NULL;
  739. if (!par[0]) {
  740. dprintf(idx, "Usage: -chrec <user> [channel]\n");
  741. return;
  742. }
  743. nick = newsplit(&par);
  744. u1 = get_user_by_handle(userlist, nick);
  745. if (!u1) {
  746. dprintf(idx, "No such user.\n");
  747. return;
  748. }
  749. if (!par[0]) {
  750. struct chanset_t *chan;
  751. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  752. if (chan)
  753. chn = chan->dname;
  754. else {
  755. dprintf(idx, "Invalid console channel.\n");
  756. return;
  757. }
  758. } else
  759. chn = newsplit(&par);
  760. get_user_flagrec(dcc[idx].user, &user, chn);
  761. get_user_flagrec(u1, &victim, chn);
  762. if (privchan(user, findchan_by_dname(chn), PRIV_OP)) {
  763. dprintf(idx, "No such channel.\n");
  764. return;
  765. }
  766. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  767. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  768. (glob_owner(victim) && !glob_owner(user))) {
  769. dprintf(idx, "You have no permission to do that.\n");
  770. return;
  771. }
  772. chanrec = get_chanrec(u1, chn);
  773. if (!chanrec) {
  774. dprintf(idx, "User %s doesn't have a channel record for %s.\n", nick, chn);
  775. return;
  776. }
  777. putlog(LOG_CMDS, "*", "#%s# -chrec %s %s", dcc[idx].nick, nick, chn);
  778. del_chanrec(u1, chn);
  779. dprintf(idx, "Removed %s channel record from %s.\n", chn, nick);
  780. if (conf.bot->hub)
  781. write_userfile(idx);
  782. }
  783. static void cmd_cycle(int idx, char *par)
  784. {
  785. char *chname = NULL;
  786. int delay = 10;
  787. struct chanset_t *chan = NULL;
  788. putlog(LOG_CMDS, "*", "#%s# cycle %s", dcc[idx].nick, par);
  789. if (!par[0]) {
  790. dprintf(idx, "Usage: cycle [%s]<channel> [delay]\n", CHANMETA);
  791. dprintf(idx, "rejoin delay defaults to '10'\n");
  792. return;
  793. }
  794. chname = newsplit(&par);
  795. chan = findchan_by_dname(chname);
  796. if (!chan) {
  797. dprintf(idx, "%s it not a valid channel.\n", chname);
  798. return;
  799. }
  800. if (par[0])
  801. delay = atoi(newsplit(&par));
  802. if (conf.bot->hub) {
  803. char buf2[201] = "";
  804. simple_snprintf(buf2, sizeof(buf2), "cycle %s %d", chname, delay); /* this just makes the bot PART */
  805. putallbots(buf2);
  806. } else {
  807. do_chanset(NULL, chan, "+inactive", DO_LOCAL);
  808. dprintf(DP_SERVER, "PART %s\n", chan->name);
  809. chan->channel.jointime = ((now + delay) - server_lag);
  810. }
  811. dprintf(idx, "Cycling %s for %d seconds.\n", chan->dname, delay);
  812. }
  813. static void cmd_down(int idx, char *par)
  814. {
  815. char *chname = NULL, buf2[201] = "";
  816. struct chanset_t *chan = NULL;
  817. putlog(LOG_CMDS, "*", "#%s# down %s", dcc[idx].nick, par);
  818. if (!par[0]) {
  819. dprintf(idx, "Usage: down [%s]<channel>\n", CHANMETA);
  820. return;
  821. }
  822. chname = newsplit(&par);
  823. chan = findchan_by_dname(chname);
  824. if (!chan) {
  825. dprintf(idx, "%s it not a valid channel.\n", chname);
  826. return;
  827. }
  828. simple_snprintf(buf2, sizeof(buf2), "down %s", chan->dname);
  829. putallbots(buf2);
  830. if (!conf.bot->hub) {
  831. add_mode(chan, '-', 'o', botname);
  832. chan->channel.no_op = (now + 10);
  833. }
  834. }
  835. static void pls_chan(int idx, char *par, char *bot)
  836. {
  837. char *chname = NULL, result[RESULT_LEN] = "", buf[2048] = "";
  838. struct chanset_t *chan = NULL;
  839. if (!bot)
  840. putlog(LOG_CMDS, "*", "#%s# +chan %s", dcc[idx].nick, par);
  841. if (!par[0]) {
  842. dprintf(idx, "Usage: +chan [%s]<channel> [options]\n", CHANMETA);
  843. return;
  844. }
  845. chname = newsplit(&par);
  846. simple_snprintf(buf, sizeof(buf), "cjoin %s %s", chname, bot ? bot : "*"); /* +chan makes all bots join */
  847. if (par[0]) {
  848. strlcat(buf, " ", sizeof(buf));
  849. strlcat(buf, par, sizeof(buf));
  850. strlcat(buf, " ", sizeof(buf));
  851. }
  852. if (!bot && findchan_by_dname(chname)) {
  853. putallbots(buf);
  854. dprintf(idx, "That channel already exists!\n");
  855. return;
  856. } else if ((chan = findchan(chname)) && !bot) {
  857. putallbots(buf);
  858. dprintf(idx, "That channel already exists as %s!\n", chan->dname);
  859. return;
  860. } else if (strchr(CHANMETA, chname[0]) == NULL) {
  861. dprintf(idx, "Invalid channel prefix.\n");
  862. return;
  863. } else if (strchr(chname, ',') != NULL) {
  864. dprintf(idx, "Invalid channel name.\n");
  865. return;
  866. }
  867. if (!chan && !findchan_by_dname(chname) && channel_add(result, chname, par) == ERROR) {
  868. dprintf(idx, "Invalid channel or channel options.\n");
  869. if (result[0])
  870. dprintf(idx, " %s\n", result);
  871. } else {
  872. if ((chan = findchan_by_dname(chname))) {
  873. if (!bot) {
  874. char tmp[51] = "";
  875. simple_snprintf(tmp, sizeof(tmp), "addedby %s addedts %li", dcc[idx].nick, (long) now);
  876. if (buf[0]) {
  877. strlcat(buf, " ", sizeof(buf));
  878. strlcat(buf, tmp, sizeof(buf));
  879. }
  880. do_chanset(NULL, chan, buf[0] ? buf : tmp, DO_LOCAL);
  881. dprintf(idx, "Channel %s added to the botnet.\n", chname);
  882. } else {
  883. dprintf(idx, "Channel %s added to the bot: %s\n", chname, bot);
  884. }
  885. putallbots(buf);
  886. }
  887. if (conf.bot->hub)
  888. write_userfile(-1);
  889. }
  890. }
  891. static void cmd_pls_chan(int idx, char *par)
  892. {
  893. pls_chan(idx, par, NULL);
  894. }
  895. static void cmd_botjoin(int idx, char *par)
  896. {
  897. char *bot = NULL;
  898. struct userrec *botu = NULL;
  899. putlog(LOG_CMDS, "*", "#%s# botjoin %s", dcc[idx].nick, par);
  900. if (!par[0]) {
  901. dprintf(idx, "Usage: botjoin <bot> [%s]<channel> [options]\n", CHANMETA);
  902. return;
  903. }
  904. bot = newsplit(&par);
  905. botu = get_user_by_handle(userlist, bot);
  906. if (botu && botu->bot) {
  907. pls_chan(idx, par, bot);
  908. } else {
  909. dprintf(idx, "Error: '%s' is not a bot.\n", bot);
  910. }
  911. }
  912. static void mns_chan(int idx, char *par, char *bot)
  913. {
  914. char *chname = NULL, buf2[1024] = "";
  915. struct chanset_t *chan = NULL;
  916. int i;
  917. if (!bot)
  918. putlog(LOG_CMDS, "*", "#%s# -chan %s", dcc[idx].nick, par);
  919. if (!par[0]) {
  920. dprintf(idx, "Usage: -chan [%s]<channel>\n", CHANMETA);
  921. return;
  922. }
  923. chname = newsplit(&par);
  924. simple_snprintf(buf2, sizeof(buf2), "cpart %s %s", chname, bot ? bot : "*");
  925. if (bot) /* bot will just set it +inactive */
  926. putbot(bot, buf2);
  927. else
  928. putallbots(buf2);
  929. chan = findchan_by_dname(chname);
  930. if (!chan) {
  931. if ((chan = findchan(chname)))
  932. dprintf(idx, "That channel exists with a short name of %s, use that.\n", chan->dname);
  933. else
  934. dprintf(idx, "That channel doesn't exist!\n");
  935. return;
  936. }
  937. if (!bot) {
  938. for (i = 0; i < dcc_total; i++) {
  939. if (dcc[i].type && (dcc[i].type->flags & DCT_CHAT) &&
  940. !rfc_casecmp(dcc[i].u.chat->con_chan, chan->dname)) {
  941. dprintf(i, "%s is no longer a valid channel, changing your console to '*'\n", chname);
  942. strlcpy(dcc[i].u.chat->con_chan, "*", 2);
  943. console_dostore(i, 0);
  944. }
  945. }
  946. remove_channel(chan);
  947. if (conf.bot->hub)
  948. write_userfile(idx);
  949. dprintf(idx, "Channel %s removed from the botnet.\n", chname);
  950. dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
  951. } else
  952. dprintf(idx, "Channel %s removed from the bot: %s\n", chname, bot);
  953. }
  954. static void cmd_mns_chan(int idx, char *par)
  955. {
  956. mns_chan(idx, par, NULL);
  957. }
  958. static void cmd_botpart(int idx, char *par)
  959. {
  960. char *bot = NULL;
  961. struct userrec *botu = NULL;
  962. putlog(LOG_CMDS, "*", "#%s# botpart %s", dcc[idx].nick, par);
  963. if (!par[0]) {
  964. dprintf(idx, "Usage: botpart <bot> [%s]<channel> [options]\n", CHANMETA);
  965. return;
  966. }
  967. bot = newsplit(&par);
  968. botu = get_user_by_handle(userlist, bot);
  969. if (botu && botu->bot) {
  970. mns_chan(idx, par, bot);
  971. } else {
  972. dprintf(idx, "Error: '%s' is not a bot.\n", bot);
  973. }
  974. }
  975. /* thanks Excelsior */
  976. #define FLAG_COLS 4
  977. static void show_flag(int idx, char *work, int *cnt, const char *name, unsigned int state, size_t worksiz)
  978. {
  979. char tmp[101] = "", chr_state[15] = "";
  980. /* empty buffer if no (char *) name */
  981. if (((*cnt) < (FLAG_COLS - 1)) && (!name || (name && !name[0]))) (*cnt) = (FLAG_COLS - 1);
  982. (*cnt)++;
  983. if (*cnt > FLAG_COLS) {
  984. *cnt = 1;
  985. work[0] = 0;
  986. }
  987. if (!work[0])
  988. strlcpy(work, " ", worksiz);
  989. if (name && name[0]) {
  990. chr_state[0] = 0;
  991. if (state) {
  992. strlcat(chr_state, GREEN(idx), sizeof(chr_state));
  993. strlcat(chr_state, "+", sizeof(chr_state));
  994. } else {
  995. strlcat(chr_state, RED(idx), sizeof(chr_state));
  996. strlcat(chr_state, "-", sizeof(chr_state));
  997. }
  998. strlcat(chr_state, COLOR_END(idx), sizeof(chr_state));
  999. egg_snprintf(tmp, sizeof tmp, "%s%-17s", chr_state, name);
  1000. strlcat(work, tmp, worksiz);
  1001. }
  1002. if (*cnt >= FLAG_COLS)
  1003. dprintf(idx, "%s\n", work);
  1004. }
  1005. #define INT_COLS 1
  1006. static void show_int(int idx, char *work, int *cnt, const char *desc, int state, const char *yes, const char *no, size_t worksiz)
  1007. {
  1008. char tmp[101] = "", chr_state[101] = "";
  1009. simple_snprintf(chr_state, sizeof chr_state, "%d", state);
  1010. /* empty buffer if no (char *) name */
  1011. if (((*cnt) < (INT_COLS - 1)) && (!desc || (desc && !desc[0]))) (*cnt) = (INT_COLS - 1);
  1012. (*cnt)++;
  1013. if (*cnt > INT_COLS) {
  1014. *cnt = 1;
  1015. work[0] = 0;
  1016. }
  1017. if (!work[0])
  1018. strlcpy(work, " ", 3);
  1019. /* need to make next line all one char, and then put it into %-30s */
  1020. if (desc && desc[0]) {
  1021. char tmp2[50] = "", tmp3[50] = "";
  1022. strlcat(tmp2, BOLD(idx), sizeof(tmp2));
  1023. if (state && yes) {
  1024. strlcat(tmp2, yes, sizeof(tmp2));
  1025. strlcat(tmp3, " (", sizeof(tmp3));
  1026. strlcat(tmp3, chr_state, sizeof(tmp3));
  1027. strlcat(tmp3, ")", sizeof(tmp3));
  1028. } else if (!state && no) {
  1029. strlcat(tmp2, no, sizeof(tmp2));
  1030. strlcat(tmp3, " (", sizeof(tmp3));
  1031. strlcat(tmp3, chr_state, sizeof(tmp3));
  1032. strlcat(tmp3, ")", sizeof(tmp3));
  1033. } else if ((state && !yes) || (!state && !no)) {
  1034. strlcat(tmp2, chr_state, sizeof(tmp2));
  1035. }
  1036. strlcat(tmp2, BOLD_END(idx), sizeof(tmp2));
  1037. egg_snprintf(tmp, sizeof tmp, "%-30s %-20s %s", desc, tmp2, tmp3[0] ? tmp3 : "");
  1038. strlcat(work, tmp, worksiz);
  1039. }
  1040. if (*cnt >= INT_COLS)
  1041. dprintf(idx, "%s\n", work);
  1042. }
  1043. #define SHOW_FLAG(name, state) show_flag(idx, work, &cnt, name, state, sizeof(work))
  1044. #define SHOW_INT(desc, state, yes, no) show_int(idx, work, &cnt, desc, state, yes, no, sizeof(work))
  1045. #define P_STR deflag == P_KICK ? "Kick" : (deflag == P_DEOP ? "Deop" : (deflag == P_DELETE ? "Remove" : NULL))
  1046. #define F_STR chan->flood_exempt_mode == FLOOD_EXEMPT_OP ? "Op" : (chan->flood_exempt_mode == FLOOD_EXEMPT_VOICE ? "Voice" : NULL)
  1047. static void cmd_chaninfo(int idx, char *par)
  1048. {
  1049. char *chname = NULL, work[512] = "";
  1050. struct chanset_t *chan = NULL;
  1051. int cnt = 0;
  1052. if (!par[0]) {
  1053. chname = dcc[idx].u.chat->con_chan;
  1054. if (chname[0] == '*') {
  1055. dprintf(idx, "Your console channel is invalid.\n");
  1056. return;
  1057. }
  1058. } else {
  1059. chname = newsplit(&par);
  1060. get_user_flagrec(dcc[idx].user, &user, chname);
  1061. if (!glob_master(user) && !chan_master(user)) {
  1062. dprintf(idx, "You don't have access to %s.\n", chname);
  1063. return;
  1064. }
  1065. }
  1066. chan = findchan_by_dname(chname);
  1067. if (!chan || (chan && privchan(user, chan, PRIV_OP))) {
  1068. dprintf(idx, "No such channel.\n");
  1069. return;
  1070. } else {
  1071. char nick[NICKLEN] = "", date[81] = "";
  1072. int deflag = 0;
  1073. if (chan->added_ts) {
  1074. egg_strftime(date, sizeof date, "%c %Z", gmtime(&(chan->added_ts)));
  1075. } else
  1076. date[0] = 0;
  1077. if (chan->added_by && chan->added_by[0])
  1078. strlcpy(nick, chan->added_by, sizeof(nick));
  1079. else
  1080. nick[0] = 0;
  1081. putlog(LOG_CMDS, "*", "#%s# chaninfo %s", dcc[idx].nick, chname);
  1082. if (nick[0] && date[0])
  1083. dprintf(idx, "Settings for channel %s (Added %s by %s%s%s):\n", chan->dname, date, BOLD(idx), nick, BOLD_END(idx));
  1084. else
  1085. dprintf(idx, "Settings for channel %s:\n", chan->dname);
  1086. /* FIXME: SHOW_CHAR() here */
  1087. get_mode_protect(chan, work, sizeof(work));
  1088. dprintf(idx, "Protect modes (chanmode): %s\n", work[0] ? work : "None");
  1089. dprintf(idx, "Protect topic (topic) : %s\n", chan->topic[0] ? chan->topic : "");
  1090. /* Chanchar template
  1091. * dprintf(idx, "String temp: %s\n", chan->temp[0] ? chan->temp : "NULL");
  1092. */
  1093. dprintf(idx, "Channel flags:\n");
  1094. work[0] = 0;
  1095. SHOW_FLAG("autoop", channel_autoop(chan));
  1096. SHOW_FLAG("backup", channel_backup(chan));
  1097. SHOW_FLAG("bitch", channel_bitch(chan));
  1098. SHOW_FLAG("botbitch", channel_botbitch(chan));
  1099. SHOW_FLAG("closed", channel_closed(chan));
  1100. SHOW_FLAG("cycle", channel_cycle(chan));
  1101. SHOW_FLAG("enforcebans", channel_enforcebans(chan));
  1102. SHOW_FLAG("fastop", channel_fastop(chan));
  1103. SHOW_FLAG("inactive", channel_inactive(chan));
  1104. SHOW_FLAG("knock", channel_knock(chan));
  1105. SHOW_FLAG("meankicks", channel_meankicks(chan));
  1106. SHOW_FLAG("nodesynch", channel_nodesynch(chan));
  1107. SHOW_FLAG("nomassjoin", channel_nomassjoin(chan));
  1108. SHOW_FLAG("private", channel_privchan(chan));
  1109. SHOW_FLAG("rbl", channel_rbl(chan));
  1110. // SHOW_FLAG("revengebot", channel_revengebot(chan));
  1111. // SHOW_FLAG("revenge", channel_revenge(chan));
  1112. if (HAVE_TAKE)
  1113. SHOW_FLAG("take", channel_take(chan));
  1114. SHOW_FLAG("voice", channel_voice(chan));
  1115. SHOW_FLAG("", 0);
  1116. SHOW_FLAG("dynamicbans", channel_dynamicbans(chan));
  1117. SHOW_FLAG("userbans", !channel_nouserbans(chan));
  1118. SHOW_FLAG("dynamicexempts", channel_dynamicexempts(chan));
  1119. SHOW_FLAG("userexempts", !channel_nouserexempts(chan));
  1120. SHOW_FLAG("dynamicinvites", channel_dynamicinvites(chan));
  1121. SHOW_FLAG("userinvites", !channel_nouserinvites(chan));
  1122. SHOW_FLAG("", 0);
  1123. work[0] = 0;
  1124. /* Chanflag template
  1125. * SHOW_FLAG("template", channel_template(chan));
  1126. * also include %ctemp in dprintf.
  1127. */
  1128. work[0] = cnt = 0;
  1129. /* Chanint template
  1130. * SHOW_INT("Desc: ", integer, "YES", "NO");
  1131. */
  1132. dprintf(idx, "Channel settings:\n");
  1133. deflag = chan->bad_cookie;
  1134. SHOW_INT("Auto-delay: ", chan->auto_delay, NULL, "None");
  1135. SHOW_INT("Bad-cookie:" , chan->bad_cookie, P_STR, "Ignore");
  1136. SHOW_INT("Ban-time: ", chan->ban_time, NULL, "Forever");
  1137. SHOW_INT("Closed-ban: ", chan->closed_ban, NULL, "Don't!");
  1138. SHOW_INT("Closed-invite:", chan->closed_invite, NULL, "Don't!");
  1139. SHOW_INT("Closed-Private:", chan->closed_private, NULL, "Don't!");
  1140. SHOW_INT("Exempt-time: ", chan->exempt_time, NULL, "Forever");
  1141. SHOW_INT("Flood-exempt: ", chan->flood_exempt_mode, F_STR, "None");
  1142. SHOW_INT("Flood-lock-time: ", chan->flood_lock_time, NULL, "Don't");
  1143. SHOW_INT("Invite-time: ", chan->invite_time, NULL, "Forever");
  1144. SHOW_INT("Limit raise (limit): ", chan->limitraise, NULL, "Disabled");
  1145. deflag = chan->manop;
  1146. SHOW_INT("Manop: ", chan->manop, P_STR, "Ignore");
  1147. deflag = chan->mdop;
  1148. SHOW_INT("Mdop: ", chan->mdop, P_STR, "Ignore");
  1149. deflag = chan->mop;
  1150. SHOW_INT("Mop: ", chan->mop, P_STR, "Ignore");
  1151. // SHOW_INT("Revenge-mode: ", chan->revenge_mode, NULL, NULL);
  1152. SHOW_INT("Voice-non-ident: ", chan->voice_non_ident, "Do!", "Don't!");
  1153. dprintf(idx, "Flood settings: chan ctcp join kick deop nick mjoin\n");
  1154. dprintf(idx, " number: %3d %3d %3d %3d %3d %3d %3d\n",
  1155. chan->flood_pub_thr, chan->flood_ctcp_thr,
  1156. chan->flood_join_thr, chan->flood_kick_thr,
  1157. chan->flood_deop_thr, chan->flood_nick_thr,
  1158. chan->flood_mjoin_thr);
  1159. dprintf(idx, " time : %3u %3u %3u %3u %3u %3u %3u\n",
  1160. chan->flood_pub_time, chan->flood_ctcp_time,
  1161. chan->flood_join_time, chan->flood_kick_time,
  1162. chan->flood_deop_time, chan->flood_nick_time,
  1163. chan->flood_mjoin_time);
  1164. }
  1165. }
  1166. static void cmd_chanset(int idx, char *par)
  1167. {
  1168. char *chname = NULL, result[RESULT_LEN] = "";
  1169. struct chanset_t *chan = NULL;
  1170. int all = 0;
  1171. if (!par[0]) {
  1172. putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
  1173. dprintf(idx, "Usage: chanset [%schannel|*] <settings>\n", CHANMETA);
  1174. return;
  1175. }
  1176. if (strlen(par) > 2 && par[0] == '*' && par[1] == ' ') {
  1177. all = 1;
  1178. get_user_flagrec(dcc[idx].user, &user, chanset ? chanset->dname : "");
  1179. if (!glob_master(user)) {
  1180. dprintf(idx, "You need to be a global master to use '%schanset *'.\n", (dcc[idx].u.chat->channel >= 0) ? settings.dcc_prefix : "");
  1181. return;
  1182. }
  1183. newsplit(&par);
  1184. } else {
  1185. if (strchr(CHANMETA, par[0])) {
  1186. chname = newsplit(&par);
  1187. get_user_flagrec(dcc[idx].user, &user, chname);
  1188. chan = findchan_by_dname(chname);
  1189. if (!glob_master(user) && !chan_master(user)) {
  1190. dprintf(idx, "You don't have access to %s. \n", chname);
  1191. return;
  1192. } else if ((!chan && (chname[0] != '+')) || (chan && privchan(user, chan, PRIV_OP))) {
  1193. dprintf(idx, "No such channel.\n");
  1194. return;
  1195. } else if ((strstr(par, "+private") || strstr(par, "-private")) && (!glob_owner(user))) {
  1196. dprintf(idx, "You don't have access to set +/-private on %s (halting command).\n", chname);
  1197. return;
  1198. } else if ((strstr(par, "+backup") || strstr(par, "-backup")) && (!glob_owner(user))) {
  1199. dprintf(idx, "You don't have access to set +/-backup on %s (halting command).\n", chname);
  1200. return;
  1201. } else if ((strstr(par, "+inactive") || strstr(par, "-inactive")) && (!glob_owner(user))) {
  1202. dprintf(idx, "You don't have access to set +/-inactive on %s (halting command).\n", chname);
  1203. return;
  1204. }
  1205. if (!chan) {
  1206. if (par[0])
  1207. *--par = ' ';
  1208. par = chname;
  1209. }
  1210. }
  1211. if (!par[0] || par[0] == '*') {
  1212. dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
  1213. return;
  1214. }
  1215. if (!chan && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
  1216. dprintf(idx, "Invalid console channel.\n");
  1217. return;
  1218. }
  1219. }
  1220. putlog(LOG_CMDS, "*", "#%s# chanset (%s) %s", dcc[idx].nick, all ? "*" : chan->dname, par);
  1221. if (do_chanset(result, all ? NULL : chan, par, DO_LOCAL | DO_NET | CMD) == ERROR) {
  1222. dprintf(idx, "Error trying to set { %s } on %s: %s\n", par, all ? "all channels" : chan->dname, result);
  1223. return;
  1224. }
  1225. if (all)
  1226. dprintf(idx, "Successfully set modes { %s } on all channels.\n", par);
  1227. else
  1228. dprintf(idx, "Successfully set modes { %s } on %s\n", par, chan->dname);
  1229. if (conf.bot->hub)
  1230. write_userfile(idx);
  1231. }
  1232. /* DCC CHAT COMMANDS
  1233. *
  1234. * Function call should be:
  1235. * int cmd_whatever(idx,"parameters");
  1236. *
  1237. * NOTE: As with msg commands, the function is responsible for any logging.
  1238. */
  1239. static cmd_t C_dcc_channels[] =
  1240. {
  1241. {"+ban", "o|o", (Function) cmd_pls_ban, NULL, AUTH},
  1242. {"+exempt", "o|o", (Function) cmd_pls_exempt, NULL, AUTH},
  1243. {"+invite", "o|o", (Function) cmd_pls_invite, NULL, AUTH},
  1244. {"+chan", "n", (Function) cmd_pls_chan, NULL, 0},
  1245. {"+chrec", "m|m", (Function) cmd_pls_chrec, NULL, 0},
  1246. {"-ban", "o|o", (Function) cmd_mns_ban, NULL, AUTH},
  1247. {"-chan", "n", (Function) cmd_mns_chan, NULL, 0},
  1248. {"-chrec", "m|m", (Function) cmd_mns_chrec, NULL, 0},
  1249. {"-exempt", "o|o", (Function) cmd_mns_exempt, NULL, AUTH},
  1250. {"-invite", "o|o", (Function) cmd_mns_invite, NULL, AUTH},
  1251. {"bans", "o|o", (Function) cmd_bans, NULL, 0},
  1252. {"botjoin", "n", (Function) cmd_botjoin, NULL, 0},
  1253. {"botpart", "n", (Function) cmd_botpart, NULL, 0},
  1254. {"exempts", "o|o", (Function) cmd_exempts, NULL, 0},
  1255. {"invites", "o|o", (Function) cmd_invites, NULL, 0},
  1256. {"chaninfo", "m|m", (Function) cmd_chaninfo, NULL, 0},
  1257. {"chanset", "m|m", (Function) cmd_chanset, NULL, 0},
  1258. {"chinfo", "m|m", (Function) cmd_chinfo, NULL, 0},
  1259. {"cycle", "n|n", (Function) cmd_cycle, NULL, 0},
  1260. {"down", "n|n", (Function) cmd_down, NULL, 0},
  1261. {"info", "", (Function) cmd_info, NULL, 0},
  1262. {"checkchannels", "n", (Function) cmd_checkchannels, NULL, HUB},
  1263. {"slowjoin", "n", (Function) cmd_slowjoin, NULL, 0},
  1264. {"slowpart", "n|n", (Function) cmd_slowpart, NULL, 0},
  1265. {"stick", "o|o", (Function) cmd_stick, NULL, AUTH},
  1266. {"unstick", "o|o", (Function) cmd_unstick, NULL, AUTH},
  1267. {NULL, NULL, NULL, NULL, 0}
  1268. };