cmdschan.c 43 KB

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