cmdschan.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  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", chan->dname);
  512. } else {
  513. int v = (random() % (intvl / 2)) - (intvl / 4);
  514. delay += intvl;
  515. simple_sprintf(tmp, "sj %s %i", 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", chname);
  570. } else {
  571. int v = (random() % (intvl / 2)) - (intvl / 4);
  572. delay += intvl;
  573. simple_sprintf(tmp, "sp %s %i", 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] = "", type = 0, *str_type = NULL;
  588. maskrec *channel_list = NULL;
  589. stick_type = newsplit(&par);
  590. strlcpy(s, newsplit(&par), sizeof s);
  591. strlcpy(chname, newsplit(&par), sizeof chname);
  592. if (egg_strcasecmp(stick_type, "exempt") &&
  593. egg_strcasecmp(stick_type, "invite") &&
  594. egg_strcasecmp(stick_type, "ban")) {
  595. strlcpy(chname, s, sizeof chname);
  596. strlcpy(s, stick_type, sizeof s);
  597. }
  598. if (!s[0]) {
  599. dprintf(idx, "Usage: %sstick [ban/exempt/invite] <hostmask or number> [channel]\n", yn ? "" : "un");
  600. return;
  601. }
  602. /* Now deal with exemptions */
  603. if (!egg_strcasecmp(stick_type, "exempt")) {
  604. if (!use_exempts) {
  605. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  606. return;
  607. }
  608. type = 'e';
  609. str_type = "exempt";
  610. } else if (!egg_strcasecmp(stick_type, "invite")) {
  611. if (!use_invites) {
  612. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  613. return;
  614. }
  615. type = 'I';
  616. str_type = "invite";
  617. } else if (!egg_strcasecmp(stick_type, "ban")) {
  618. type = 'b';
  619. str_type = "ban";
  620. } else
  621. return;
  622. if (!chname[0]) {
  623. channel_list = (type == 'b' ? global_bans : type == 'e' ? global_exempts : global_invites);
  624. i = u_setsticky_mask(NULL, channel_list, s, (dcc[idx].user->flags & USER_MASTER) ? yn : -1, type);
  625. if (i > 0) {
  626. putlog(LOG_CMDS, "*", "#%s# %sstick %s %s", dcc[idx].nick, yn ? "" : "un", str_type, s);
  627. dprintf(idx, "%stuck %s: %s\n", yn ? "S" : "Uns", str_type, s);
  628. if (!conf.bot->hub) {
  629. struct chanset_t *achan = NULL;
  630. for (achan = chanset; achan != NULL; achan = achan->next)
  631. check_this_mask(type, achan, s, yn);
  632. } else
  633. write_userfile(idx);
  634. return;
  635. }
  636. strlcpy(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  637. }
  638. /* Channel-specific mask? */
  639. if (!(chan = findchan_by_dname(chname))) {
  640. dprintf(idx, "No such channel.\n");
  641. return;
  642. }
  643. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  644. if (privchan(user, chan, PRIV_OP)) {
  645. dprintf(idx, "No such channel.\n");
  646. return;
  647. }
  648. channel_list = (type == 'b' ? chan->bans : type == 'e' ? chan->exempts : chan->invites);
  649. if (str_isdigit(s)) {
  650. /* substract the numer of global masks to get the number of the channel masks */
  651. j = u_setsticky_mask(NULL, channel_list, s, -1, type);
  652. if (j < 0)
  653. simple_snprintf(s, sizeof s, "%d", -j);
  654. }
  655. j = u_setsticky_mask(chan, channel_list, s, yn, type);
  656. if (j > 0) {
  657. putlog(LOG_CMDS, "*", "#%s# %sstick %s %s %s", dcc[idx].nick, yn ? "" : "un", str_type, s, chname);
  658. dprintf(idx, "%stuck %s %s: %s\n", yn ? "S" : "Uns", chname, str_type, s);
  659. if (!conf.bot->hub)
  660. check_this_mask(type, chan, s, yn);
  661. else
  662. write_userfile(idx);
  663. return;
  664. }
  665. dprintf(idx, "No such %s.\n", str_type);
  666. }
  667. static void cmd_stick(int idx, char *par)
  668. {
  669. cmd_stick_yn(idx, par, 1);
  670. }
  671. static void cmd_unstick(int idx, char *par)
  672. {
  673. cmd_stick_yn(idx, par, 0);
  674. }
  675. static void cmd_pls_chrec(int idx, char *par)
  676. {
  677. char *nick = NULL, *chn = NULL;
  678. struct chanset_t *chan = NULL;
  679. struct userrec *u1 = NULL;
  680. struct chanuserrec *chanrec = NULL;
  681. if (!par[0]) {
  682. dprintf(idx, "Usage: +chrec <user> [channel]\n");
  683. return;
  684. }
  685. nick = newsplit(&par);
  686. u1 = get_user_by_handle(userlist, nick);
  687. if (!u1) {
  688. dprintf(idx, "No such user.\n");
  689. return;
  690. }
  691. if (!par[0])
  692. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  693. else {
  694. chn = newsplit(&par);
  695. chan = findchan_by_dname(chn);
  696. }
  697. if (!chan) {
  698. dprintf(idx, "No such channel.\n");
  699. return;
  700. }
  701. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  702. get_user_flagrec(u1, &victim, chan->dname);
  703. if (privchan(user, chan, PRIV_OP)) {
  704. dprintf(idx, "No such channel.\n");
  705. return;
  706. }
  707. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  708. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  709. (glob_owner(victim) && !glob_owner(user))) {
  710. dprintf(idx, "You have no permission to do that.\n");
  711. return;
  712. }
  713. chanrec = get_chanrec(u1, chan->dname);
  714. if (chanrec) {
  715. dprintf(idx, "User %s already has a channel record for %s.\n",
  716. nick, chan->dname);
  717. return;
  718. }
  719. putlog(LOG_CMDS, "*", "#%s# +chrec %s %s", dcc[idx].nick, nick, chan->dname);
  720. add_chanrec(u1, chan->dname);
  721. dprintf(idx, "Added %s channel record for %s.\n", chan->dname, nick);
  722. if (conf.bot->hub)
  723. write_userfile(idx);
  724. }
  725. static void cmd_mns_chrec(int idx, char *par)
  726. {
  727. char *nick = NULL, *chn = NULL;
  728. struct userrec *u1 = NULL;
  729. struct chanuserrec *chanrec = NULL;
  730. if (!par[0]) {
  731. dprintf(idx, "Usage: -chrec <user> [channel]\n");
  732. return;
  733. }
  734. nick = newsplit(&par);
  735. u1 = get_user_by_handle(userlist, nick);
  736. if (!u1) {
  737. dprintf(idx, "No such user.\n");
  738. return;
  739. }
  740. if (!par[0]) {
  741. struct chanset_t *chan;
  742. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  743. if (chan)
  744. chn = chan->dname;
  745. else {
  746. dprintf(idx, "Invalid console channel.\n");
  747. return;
  748. }
  749. } else
  750. chn = newsplit(&par);
  751. get_user_flagrec(dcc[idx].user, &user, chn);
  752. get_user_flagrec(u1, &victim, chn);
  753. if (privchan(user, findchan_by_dname(chn), PRIV_OP)) {
  754. dprintf(idx, "No such channel.\n");
  755. return;
  756. }
  757. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  758. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  759. (glob_owner(victim) && !glob_owner(user))) {
  760. dprintf(idx, "You have no permission to do that.\n");
  761. return;
  762. }
  763. chanrec = get_chanrec(u1, chn);
  764. if (!chanrec) {
  765. dprintf(idx, "User %s doesn't have a channel record for %s.\n", nick, chn);
  766. return;
  767. }
  768. putlog(LOG_CMDS, "*", "#%s# -chrec %s %s", dcc[idx].nick, nick, chn);
  769. del_chanrec(u1, chn);
  770. dprintf(idx, "Removed %s channel record from %s.\n", chn, nick);
  771. if (conf.bot->hub)
  772. write_userfile(idx);
  773. }
  774. static void cmd_cycle(int idx, char *par)
  775. {
  776. char *chname = NULL;
  777. int delay = 10;
  778. struct chanset_t *chan = NULL;
  779. putlog(LOG_CMDS, "*", "#%s# cycle %s", dcc[idx].nick, par);
  780. if (!par[0]) {
  781. dprintf(idx, "Usage: cycle [%s]<channel> [delay]\n", CHANMETA);
  782. dprintf(idx, "rejoin delay defaults to '10'\n");
  783. return;
  784. }
  785. chname = newsplit(&par);
  786. chan = findchan_by_dname(chname);
  787. if (!chan) {
  788. dprintf(idx, "%s it not a valid channel.\n", chname);
  789. return;
  790. }
  791. if (par[0])
  792. delay = atoi(newsplit(&par));
  793. if (conf.bot->hub) {
  794. char buf2[1024] = "";
  795. simple_sprintf(buf2, "cycle %s %d", chname, delay); /* this just makes the bot PART */
  796. putallbots(buf2);
  797. } else {
  798. do_chanset(NULL, chan, "+inactive", DO_LOCAL);
  799. dprintf(DP_SERVER, "PART %s\n", chan->name);
  800. chan->channel.jointime = ((now + delay) - server_lag);
  801. }
  802. dprintf(idx, "Cycling %s for %d seconds.\n", chan->dname, delay);
  803. }
  804. static void cmd_down(int idx, char *par)
  805. {
  806. char *chname = NULL, buf2[1024] = "";
  807. struct chanset_t *chan = NULL;
  808. putlog(LOG_CMDS, "*", "#%s# down %s", dcc[idx].nick, par);
  809. if (!par[0]) {
  810. dprintf(idx, "Usage: down [%s]<channel>\n", CHANMETA);
  811. return;
  812. }
  813. chname = newsplit(&par);
  814. chan = findchan_by_dname(chname);
  815. if (!chan) {
  816. dprintf(idx, "%s it not a valid channel.\n", chname);
  817. return;
  818. }
  819. simple_sprintf(buf2, "down %s", chan->dname);
  820. putallbots(buf2);
  821. if (!conf.bot->hub) {
  822. add_mode(chan, '-', 'o', botname);
  823. chan->channel.no_op = (now + 10);
  824. }
  825. }
  826. static void pls_chan(int idx, char *par, char *bot)
  827. {
  828. char *chname = NULL, result[1024] = "", buf[2048] = "";
  829. struct chanset_t *chan = NULL;
  830. if (!bot)
  831. putlog(LOG_CMDS, "*", "#%s# +chan %s", dcc[idx].nick, par);
  832. if (!par[0]) {
  833. dprintf(idx, "Usage: +chan [%s]<channel> [options]\n", CHANMETA);
  834. return;
  835. }
  836. chname = newsplit(&par);
  837. simple_sprintf(buf, "cjoin %s %s", chname, bot ? bot : "*"); /* +chan makes all bots join */
  838. if (par[0]) {
  839. strcat(buf, " ");
  840. strcat(buf, par);
  841. strcat(buf, " ");
  842. }
  843. if (!bot && findchan_by_dname(chname)) {
  844. putallbots(buf);
  845. dprintf(idx, "That channel already exists!\n");
  846. return;
  847. } else if ((chan = findchan(chname)) && !bot) {
  848. putallbots(buf);
  849. dprintf(idx, "That channel already exists as %s!\n", chan->dname);
  850. return;
  851. } else if (strchr(CHANMETA, chname[0]) == NULL) {
  852. dprintf(idx, "Invalid channel prefix.\n");
  853. return;
  854. } else if (strchr(chname, ',') != NULL) {
  855. dprintf(idx, "Invalid channel name.\n");
  856. return;
  857. }
  858. if (!chan && !findchan_by_dname(chname) && channel_add(result, chname, par) == ERROR) {
  859. dprintf(idx, "Invalid channel or channel options.\n");
  860. if (result[0])
  861. dprintf(idx, " %s\n", result);
  862. } else {
  863. if ((chan = findchan_by_dname(chname))) {
  864. if (!bot) {
  865. char tmp[51] = "";
  866. sprintf(tmp, "addedby %s addedts %li", dcc[idx].nick, now);
  867. if (buf[0]) {
  868. strcat(buf, " ");
  869. strcat(buf, tmp);
  870. }
  871. do_chanset(NULL, chan, buf[0] ? buf : tmp, DO_LOCAL);
  872. dprintf(idx, "Channel %s added to the botnet.\n", chname);
  873. } else {
  874. dprintf(idx, "Channel %s added to the bot: %s\n", chname, bot);
  875. }
  876. putallbots(buf);
  877. }
  878. if (conf.bot->hub)
  879. write_userfile(-1);
  880. }
  881. }
  882. static void cmd_pls_chan(int idx, char *par)
  883. {
  884. pls_chan(idx, par, NULL);
  885. }
  886. static void cmd_botjoin(int idx, char *par)
  887. {
  888. char *bot = NULL;
  889. struct userrec *botu = NULL;
  890. putlog(LOG_CMDS, "*", "#%s# botjoin %s", dcc[idx].nick, par);
  891. if (!par[0]) {
  892. dprintf(idx, "Usage: botjoin <bot> [%s]<channel> [options]\n", CHANMETA);
  893. return;
  894. }
  895. bot = newsplit(&par);
  896. botu = get_user_by_handle(userlist, bot);
  897. if (botu && botu->bot) {
  898. pls_chan(idx, par, bot);
  899. } else {
  900. dprintf(idx, "Error: '%s' is not a bot.\n", bot);
  901. }
  902. }
  903. static void mns_chan(int idx, char *par, char *bot)
  904. {
  905. char *chname = NULL, buf2[1024] = "";
  906. struct chanset_t *chan = NULL;
  907. int i;
  908. if (!bot)
  909. putlog(LOG_CMDS, "*", "#%s# -chan %s", dcc[idx].nick, par);
  910. if (!par[0]) {
  911. dprintf(idx, "Usage: -chan [%s]<channel>\n", CHANMETA);
  912. return;
  913. }
  914. chname = newsplit(&par);
  915. simple_sprintf(buf2, "cpart %s %s", chname, bot ? bot : "*");
  916. if (bot) /* bot will just set it +inactive */
  917. putbot(bot, buf2);
  918. else
  919. putallbots(buf2);
  920. chan = findchan_by_dname(chname);
  921. if (!chan) {
  922. if ((chan = findchan(chname)))
  923. dprintf(idx, "That channel exists with a short name of %s, use that.\n", chan->dname);
  924. else
  925. dprintf(idx, "That channel doesn't exist!\n");
  926. return;
  927. }
  928. if (!bot) {
  929. for (i = 0; i < dcc_total; i++)
  930. if (dcc[i].type && (dcc[i].type->flags & DCT_CHAT) && !rfc_casecmp(dcc[i].u.chat->con_chan, chan->dname)) {
  931. dprintf(i, "%s is no longer a valid channel, changing your console to '*'\n", chname);
  932. strcpy(dcc[i].u.chat->con_chan, "*");
  933. }
  934. remove_channel(chan);
  935. if (conf.bot->hub)
  936. write_userfile(-1);
  937. dprintf(idx, "Channel %s removed from the botnet.\n", chname);
  938. dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
  939. } else
  940. dprintf(idx, "Channel %s removed from the bot: %s\n", chname, bot);
  941. }
  942. static void cmd_mns_chan(int idx, char *par)
  943. {
  944. mns_chan(idx, par, NULL);
  945. }
  946. static void cmd_botpart(int idx, char *par)
  947. {
  948. char *bot = NULL;
  949. struct userrec *botu = NULL;
  950. putlog(LOG_CMDS, "*", "#%s# botpart %s", dcc[idx].nick, par);
  951. if (!par[0]) {
  952. dprintf(idx, "Usage: botpart <bot> [%s]<channel> [options]\n", CHANMETA);
  953. return;
  954. }
  955. bot = newsplit(&par);
  956. botu = get_user_by_handle(userlist, bot);
  957. if (botu && botu->bot) {
  958. mns_chan(idx, par, bot);
  959. } else {
  960. dprintf(idx, "Error: '%s' is not a bot.\n", bot);
  961. }
  962. }
  963. /* thanks Excelsior */
  964. #define FLAG_COLS 4
  965. void show_flag(int idx, char *work, int *cnt, const char *name, unsigned int state)
  966. {
  967. char tmp[101] = "", chr_state[15] = "";
  968. /* empty buffer if no (char *) name */
  969. if (((*cnt) < (FLAG_COLS - 1)) && (!name || (name && !name[0]))) (*cnt) = (FLAG_COLS - 1);
  970. (*cnt)++;
  971. if (*cnt > FLAG_COLS) {
  972. *cnt = 1;
  973. work[0] = 0;
  974. }
  975. if (!work[0])
  976. simple_sprintf(work, " ");
  977. if (name && name[0]) {
  978. chr_state[0] = 0;
  979. if (state) {
  980. strcat(chr_state, GREEN(idx));
  981. strcat(chr_state, "+");
  982. } else {
  983. strcat(chr_state, RED(idx));
  984. strcat(chr_state, "-");
  985. }
  986. strcat(chr_state, COLOR_END(idx));
  987. egg_snprintf(tmp, sizeof tmp, "%s%-17s", chr_state, name);
  988. strcat(work, tmp);
  989. }
  990. if (*cnt >= FLAG_COLS)
  991. dprintf(idx, "%s\n", work);
  992. }
  993. #define INT_COLS 1
  994. void show_int(int idx, char *work, int *cnt, const char *desc, int state, const char *yes, const char *no)
  995. {
  996. char tmp[101] = "", chr_state[101] = "";
  997. simple_snprintf(chr_state, sizeof chr_state, "%d", state);
  998. /* empty buffer if no (char *) name */
  999. if (((*cnt) < (INT_COLS - 1)) && (!desc || (desc && !desc[0]))) (*cnt) = (INT_COLS - 1);
  1000. (*cnt)++;
  1001. if (*cnt > INT_COLS) {
  1002. *cnt = 1;
  1003. work[0] = 0;
  1004. }
  1005. if (!work[0])
  1006. simple_sprintf(work, " ");
  1007. /* need to make next line all one char, and then put it into %-30s */
  1008. if (desc && desc[0]) {
  1009. char tmp2[50] = "", tmp3[50] = "";
  1010. strcat(tmp2, BOLD(idx));
  1011. if (state && yes) {
  1012. strcat(tmp2, yes);
  1013. strcat(tmp3, " (");
  1014. strcat(tmp3, chr_state);
  1015. strcat(tmp3, ")");
  1016. } else if (!state && no) {
  1017. strcat(tmp2, no);
  1018. strcat(tmp3, " (");
  1019. strcat(tmp3, chr_state);
  1020. strcat(tmp3, ")");
  1021. } else if ((state && !yes) || (!state && !no)) {
  1022. strcat(tmp2, chr_state);
  1023. }
  1024. strcat(tmp2, BOLD_END(idx));
  1025. egg_snprintf(tmp, sizeof tmp, "%-30s %-20s %s", desc, tmp2, (tmp3 && tmp3[0]) ? tmp3 : "");
  1026. strcat(work, tmp);
  1027. }
  1028. if (*cnt >= INT_COLS)
  1029. dprintf(idx, "%s\n", work);
  1030. }
  1031. #define SHOW_FLAG(name, state) show_flag(idx, work, &cnt, name, state)
  1032. #define SHOW_INT(desc, state, yes, no) show_int(idx, work, &cnt, desc, state, yes, no)
  1033. #define P_STR deflag == P_KICK ? "Kick" : (deflag == P_DEOP ? "Deop" : (deflag == P_DELETE ? "Remove" : NULL))
  1034. static void cmd_chaninfo(int idx, char *par)
  1035. {
  1036. char *chname = NULL, work[512] = "";
  1037. struct chanset_t *chan = NULL;
  1038. int cnt = 0;
  1039. if (!par[0]) {
  1040. chname = dcc[idx].u.chat->con_chan;
  1041. if (chname[0] == '*') {
  1042. dprintf(idx, "Your console channel is invalid.\n");
  1043. return;
  1044. }
  1045. } else {
  1046. chname = newsplit(&par);
  1047. get_user_flagrec(dcc[idx].user, &user, chname);
  1048. if (!glob_master(user) && !chan_master(user)) {
  1049. dprintf(idx, "You don't have access to %s.\n", chname);
  1050. return;
  1051. }
  1052. }
  1053. chan = findchan_by_dname(chname);
  1054. if (!chan || (chan && privchan(user, chan, PRIV_OP))) {
  1055. dprintf(idx, "No such channel.\n");
  1056. return;
  1057. } else {
  1058. char nick[NICKLEN] = "", date[81] = "";
  1059. int deflag = 0;
  1060. if (chan->added_ts) {
  1061. egg_strftime(date, sizeof date, "%c %Z", gmtime(&(chan->added_ts)));
  1062. } else
  1063. date[0] = 0;
  1064. if (chan->added_by && chan->added_by[0])
  1065. simple_snprintf(nick, sizeof nick, "%s", chan->added_by);
  1066. else
  1067. nick[0] = 0;
  1068. putlog(LOG_CMDS, "*", "#%s# chaninfo %s", dcc[idx].nick, chname);
  1069. if (nick[0] && date[0])
  1070. dprintf(idx, "Settings for channel %s (Added %s by %s%s%s):\n", chan->dname, date, BOLD(idx), nick, BOLD_END(idx));
  1071. else
  1072. dprintf(idx, "Settings for channel %s:\n", chan->dname);
  1073. /* FIXME: SHOW_CHAR() here */
  1074. get_mode_protect(chan, work);
  1075. dprintf(idx, "Protect modes (chanmode): %s\n", work[0] ? work : "None");
  1076. dprintf(idx, "Protect topic (topic) : %s\n", chan->topic[0] ? chan->topic : "");
  1077. /* Chanchar template
  1078. * dprintf(idx, "String temp: %s\n", chan->temp[0] ? chan->temp : "NULL");
  1079. */
  1080. dprintf(idx, "Channel flags:\n");
  1081. work[0] = 0;
  1082. SHOW_FLAG("autoop", channel_autoop(chan));
  1083. SHOW_FLAG("bitch", channel_bitch(chan));
  1084. SHOW_FLAG("botbitch", channel_botbitch(chan));
  1085. SHOW_FLAG("closed", channel_closed(chan));
  1086. SHOW_FLAG("cycle", channel_cycle(chan));
  1087. SHOW_FLAG("enforcebans", channel_enforcebans(chan));
  1088. SHOW_FLAG("fastop", channel_fastop(chan));
  1089. SHOW_FLAG("inactive", channel_inactive(chan));
  1090. SHOW_FLAG("nodesynch", channel_nodesynch(chan));
  1091. SHOW_FLAG("private", channel_privchan(chan));
  1092. SHOW_FLAG("protectops", channel_protectops(chan));
  1093. SHOW_FLAG("revenge", channel_revenge(chan));
  1094. SHOW_FLAG("revengebot", channel_revengebot(chan));
  1095. if (have_take)
  1096. SHOW_FLAG("take", channel_take(chan));
  1097. SHOW_FLAG("voice", channel_voice(chan));
  1098. SHOW_FLAG("", 0);
  1099. SHOW_FLAG("dynamicbans", channel_dynamicbans(chan));
  1100. SHOW_FLAG("userbans", !channel_nouserbans(chan));
  1101. SHOW_FLAG("dynamicexempts", channel_dynamicexempts(chan));
  1102. SHOW_FLAG("userexempts", !channel_nouserexempts(chan));
  1103. SHOW_FLAG("dynamicinvites", channel_dynamicinvites(chan));
  1104. SHOW_FLAG("userinvites", !channel_nouserinvites(chan));
  1105. SHOW_FLAG("", 0);
  1106. work[0] = 0;
  1107. /* Chanflag template
  1108. * SHOW_FLAG("template", channel_template(chan));
  1109. * also include %ctemp in dprintf.
  1110. */
  1111. work[0] = cnt = 0;
  1112. /* Chanint template
  1113. * SHOW_INT("Desc: ", integer, "YES", "NO");
  1114. */
  1115. dprintf(idx, "Channel settings:\n");
  1116. deflag = chan->bad_cookie;
  1117. SHOW_INT("Bad-cookie:" , chan->bad_cookie, P_STR, "Ignore");
  1118. SHOW_INT("Ban-time: ", chan->ban_time, NULL, "Forever");
  1119. SHOW_INT("Closed-ban: ", chan->closed_ban, NULL, "Don't!");
  1120. SHOW_INT("Closed-invite:", chan->closed_invite, NULL, "Don't!");
  1121. SHOW_INT("Closed-Private:", chan->closed_private, NULL, "Don't!");
  1122. SHOW_INT("Exempt-time: ", chan->exempt_time, NULL, "Forever");
  1123. SHOW_INT("Idle Kick after (idle-kick): ", chan->idle_kick, "", "Don't!");
  1124. SHOW_INT("Invite-time: ", chan->invite_time, NULL, "Forever");
  1125. SHOW_INT("Limit raise (limit): ", chan->limitraise, NULL, "Disabled");
  1126. deflag = chan->manop;
  1127. SHOW_INT("Manop: ", chan->manop, P_STR, "Ignore");
  1128. deflag = chan->mdop;
  1129. SHOW_INT("Mdop: ", chan->mdop, P_STR, "Ignore");
  1130. deflag = chan->mop;
  1131. SHOW_INT("Mop: ", chan->mop, P_STR, "Ignore");
  1132. SHOW_INT("Revenge-mode: ", chan->revenge_mode, NULL, NULL);
  1133. SHOW_INT("Stopnethack-mode: ", chan->stopnethack_mode, "", "Don't!");
  1134. SHOW_INT("Voice-non-ident: ", chan->voice_non_ident, "Do!", "Don't!");
  1135. dprintf(idx, "Flood settings: chan ctcp join kick deop nick\n");
  1136. dprintf(idx, " number: %3d %3d %3d %3d %3d %3d\n",
  1137. chan->flood_pub_thr, chan->flood_ctcp_thr,
  1138. chan->flood_join_thr, chan->flood_kick_thr,
  1139. chan->flood_deop_thr, chan->flood_nick_thr);
  1140. dprintf(idx, " time : %3lu %3lu %3lu %3lu %3lu %3lu\n",
  1141. chan->flood_pub_time, chan->flood_ctcp_time,
  1142. chan->flood_join_time, chan->flood_kick_time,
  1143. chan->flood_deop_time, chan->flood_nick_time);
  1144. }
  1145. }
  1146. static void cmd_chanset(int idx, char *par)
  1147. {
  1148. char *chname = NULL, result[1024] = "";
  1149. struct chanset_t *chan = NULL;
  1150. int all = 0;
  1151. if (!par[0]) {
  1152. putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
  1153. dprintf(idx, "Usage: chanset [%schannel|*] <settings>\n", CHANMETA);
  1154. return;
  1155. }
  1156. if (strlen(par) > 2 && par[0] == '*' && par[1] == ' ') {
  1157. all = 1;
  1158. get_user_flagrec(dcc[idx].user, &user, chanset ? chanset->dname : "");
  1159. if (!glob_master(user)) {
  1160. dprintf(idx, "You need to be a global master to use %schanset *.\n", settings.dcc_prefix);
  1161. return;
  1162. }
  1163. newsplit(&par);
  1164. } else {
  1165. if (strchr(CHANMETA, par[0])) {
  1166. chname = newsplit(&par);
  1167. get_user_flagrec(dcc[idx].user, &user, chname);
  1168. chan = findchan_by_dname(chname);
  1169. if (!glob_master(user) && !chan_master(user)) {
  1170. dprintf(idx, "You don't have access to %s. \n", chname);
  1171. return;
  1172. } else if ((!chan && (chname[0] != '+')) || (chan && privchan(user, chan, PRIV_OP))) {
  1173. dprintf(idx, "No such channel.\n");
  1174. return;
  1175. } else if ((strstr(par, "+private") || strstr(par, "-private")) && (!glob_owner(user))) {
  1176. dprintf(idx, "You don't have access to set +/-private on %s (halting command due to lazy coder).\n", chname);
  1177. return;
  1178. } else if ((strstr(par, "+inactive") || strstr(par, "-inactive")) && (!glob_owner(user))) {
  1179. dprintf(idx, "You don't have access to set +/-inactive on %s (halting command due to lazy coder).\n", chname);
  1180. return;
  1181. }
  1182. if (!chan) {
  1183. if (par[0])
  1184. *--par = ' ';
  1185. par = chname;
  1186. }
  1187. }
  1188. if (!par[0] || par[0] == '*') {
  1189. dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
  1190. return;
  1191. }
  1192. if (!chan && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
  1193. dprintf(idx, "Invalid console channel.\n");
  1194. return;
  1195. }
  1196. }
  1197. putlog(LOG_CMDS, "*", "#%s# chanset (%s) %s", dcc[idx].nick, all ? "*" : chan->dname, par);
  1198. if (do_chanset(result, all ? NULL : chan, par, DO_LOCAL | DO_NET) == ERROR) {
  1199. dprintf(idx, "Error trying to set { %s } on %s: %s\n", par, all ? "all channels" : chan->dname, result);
  1200. return;
  1201. }
  1202. if (all)
  1203. dprintf(idx, "Successfully set modes { %s } on all channels.\n", par);
  1204. else
  1205. dprintf(idx, "Successfully set modes { %s } on %s\n", par, chan->dname);
  1206. if (conf.bot->hub)
  1207. write_userfile(idx);
  1208. }
  1209. /* DCC CHAT COMMANDS
  1210. *
  1211. * Function call should be:
  1212. * int cmd_whatever(idx,"parameters");
  1213. *
  1214. * NOTE: As with msg commands, the function is responsible for any logging.
  1215. */
  1216. static cmd_t C_dcc_channels[] =
  1217. {
  1218. {"+ban", "o|o", (Function) cmd_pls_ban, NULL, AUTH},
  1219. {"+exempt", "o|o", (Function) cmd_pls_exempt, NULL, AUTH},
  1220. {"+invite", "o|o", (Function) cmd_pls_invite, NULL, AUTH},
  1221. {"+chan", "n", (Function) cmd_pls_chan, NULL, 0},
  1222. {"+chrec", "m|m", (Function) cmd_pls_chrec, NULL, 0},
  1223. {"-ban", "o|o", (Function) cmd_mns_ban, NULL, AUTH},
  1224. {"-chan", "n", (Function) cmd_mns_chan, NULL, 0},
  1225. {"-chrec", "m|m", (Function) cmd_mns_chrec, NULL, 0},
  1226. {"-exempt", "o|o", (Function) cmd_mns_exempt, NULL, AUTH},
  1227. {"-invite", "o|o", (Function) cmd_mns_invite, NULL, AUTH},
  1228. {"bans", "o|o", (Function) cmd_bans, NULL, 0},
  1229. {"botjoin", "n", (Function) cmd_botjoin, NULL, 0},
  1230. {"botpart", "n", (Function) cmd_botpart, NULL, 0},
  1231. {"exempts", "o|o", (Function) cmd_exempts, NULL, 0},
  1232. {"invites", "o|o", (Function) cmd_invites, NULL, 0},
  1233. {"chaninfo", "m|m", (Function) cmd_chaninfo, NULL, 0},
  1234. {"chanset", "m|m", (Function) cmd_chanset, NULL, 0},
  1235. {"chinfo", "m|m", (Function) cmd_chinfo, NULL, 0},
  1236. {"cycle", "n|n", (Function) cmd_cycle, NULL, 0},
  1237. {"down", "n|n", (Function) cmd_down, NULL, 0},
  1238. {"info", "", (Function) cmd_info, NULL, 0},
  1239. {"slowjoin", "n", (Function) cmd_slowjoin, NULL, 0},
  1240. {"slowpart", "n|n", (Function) cmd_slowpart, NULL, 0},
  1241. {"stick", "o|o", (Function) cmd_stick, NULL, AUTH},
  1242. {"unstick", "o|o", (Function) cmd_unstick, NULL, AUTH},
  1243. {NULL, NULL, NULL, NULL, 0}
  1244. };