cmdschan.c 42 KB

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