cmdschan.c 42 KB

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