cmdschan.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  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, 0, 0};
  8. static struct flag_record victim = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  9. static void cmd_pls_ban(struct userrec *u, int idx, char *par)
  10. {
  11. char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
  12. unsigned long int expire_time = 0, expire_foo;
  13. int sticky = 0;
  14. struct chanset_t *chan = NULL;
  15. module_entry *me = NULL;
  16. if (!par[0]) {
  17. dprintf(idx, "Usage: +ban <hostmask> [channel] [%%<XdXhXm>] [reason]\n");
  18. } else {
  19. who = newsplit(&par);
  20. if (par[0] && strchr(CHANMETA, par[0]))
  21. chname = newsplit(&par);
  22. else
  23. chname = 0;
  24. if (chname || !(u->flags & USER_MASTER)) {
  25. if (!chname)
  26. chname = dcc[idx].u.chat->con_chan;
  27. get_user_flagrec(u, &user, chname);
  28. chan = findchan_by_dname(chname);
  29. /* *shrug* ??? (guppy:10Feb1999) */
  30. if (!chan) {
  31. dprintf(idx, "That channel doesn't exist!\n");
  32. return;
  33. } else if (private(user, chan, PRIV_OP)) {
  34. dprintf(idx, "No such channel.\n");
  35. return;
  36. } else if (!((glob_op(user) && !chan_deop(user)) || chan_op(user))) {
  37. dprintf(idx, "You don't have access to set bans on %s.\n", chname);
  38. return;
  39. }
  40. } else
  41. chan = 0;
  42. /* Added by Q and Solal -- Requested by Arty2, special thanx :) */
  43. if (par[0] == '%') {
  44. p = newsplit(&par);
  45. p_expire = p + 1;
  46. while (*(++p) != 0) {
  47. switch (tolower(*p)) {
  48. case 'd':
  49. *p = 0;
  50. expire_foo = strtol(p_expire, NULL, 10);
  51. if (expire_foo > 365)
  52. expire_foo = 365;
  53. expire_time += 86400 * expire_foo;
  54. p_expire = p + 1;
  55. break;
  56. case 'h':
  57. *p = 0;
  58. expire_foo = strtol(p_expire, NULL, 10);
  59. if (expire_foo > 8760)
  60. expire_foo = 8760;
  61. expire_time += 3600 * expire_foo;
  62. p_expire = p + 1;
  63. break;
  64. case 'm':
  65. *p = 0;
  66. expire_foo = strtol(p_expire, NULL, 10);
  67. if (expire_foo > 525600)
  68. expire_foo = 525600;
  69. expire_time += 60 * expire_foo;
  70. p_expire = p + 1;
  71. }
  72. }
  73. }
  74. if (!par[0])
  75. par = "requested";
  76. else if (strlen(par) > MASKREASON_MAX)
  77. par[MASKREASON_MAX] = 0;
  78. if (strlen(who) > UHOSTMAX - 4)
  79. who[UHOSTMAX - 4] = 0;
  80. /* Fix missing ! or @ BEFORE checking against myself */
  81. if (!strchr(who, '!')) {
  82. if (!strchr(who, '@'))
  83. egg_snprintf(s, sizeof s, "%s!*@*", who); /* Lame nick ban */
  84. else
  85. egg_snprintf(s, sizeof s, "*!%s", who);
  86. } else if (!strchr(who, '@'))
  87. egg_snprintf(s, sizeof s, "%s@*", who); /* brain-dead? */
  88. else
  89. strncpyz(s, who, sizeof s);
  90. if ((me = module_find("server", 0, 0)) && me->funcs)
  91. egg_snprintf(s1, sizeof s1, "%s!%s", me->funcs[SERVER_BOTNAME],
  92. me->funcs[SERVER_BOTUSERHOST]);
  93. else
  94. egg_snprintf(s1, sizeof s1, "%s!%s@%s", origbotname, botuser, conf.bot->host);
  95. if (wild_match(s, s1)) {
  96. dprintf(idx, "I'm not going to ban myself.\n");
  97. putlog(LOG_CMDS, "*", "#%s# attempted +ban %s", dcc[idx].nick, s);
  98. } else {
  99. /* IRC can't understand bans longer than 70 characters */
  100. if (strlen(s) > 70) {
  101. s[69] = '*';
  102. s[70] = 0;
  103. }
  104. if (chan) {
  105. u_addban(chan, s, dcc[idx].nick, par,
  106. expire_time ? now + expire_time : 0, 0);
  107. if (par[0] == '*') {
  108. sticky = 1;
  109. par++;
  110. putlog(LOG_CMDS, "*", "#%s# (%s) +ban %s %s (%s) (sticky)",
  111. dcc[idx].nick, dcc[idx].u.chat->con_chan, s, chan->dname, par);
  112. dprintf(idx, "New %s sticky ban: %s (%s)\n", chan->dname, s, par);
  113. } else {
  114. putlog(LOG_CMDS, "*", "#%s# (%s) +ban %s %s (%s)", dcc[idx].nick,
  115. dcc[idx].u.chat->con_chan, s, chan->dname, par);
  116. dprintf(idx, "New %s ban: %s (%s)\n", chan->dname, s, par);
  117. }
  118. /* Avoid unnesessary modes if you got +dynamicbans, and there is
  119. * no reason to set mode if irc.mod aint loaded. (dw 001120)
  120. */
  121. if ((me = module_find("irc", 0, 0)))
  122. (me->funcs[IRC_CHECK_THIS_BAN])(chan, s, sticky);
  123. } else {
  124. u_addban(NULL, s, dcc[idx].nick, par, expire_time ? now + expire_time : 0, 0);
  125. if (par[0] == '*') {
  126. sticky = 1;
  127. par++;
  128. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +ban %s (%s) (sticky)", dcc[idx].nick, s, par);
  129. dprintf(idx, "New sticky ban: %s (%s)\n", s, par);
  130. } else {
  131. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +ban %s (%s)", dcc[idx].nick, s, par);
  132. dprintf(idx, "New ban: %s (%s)\n", s, par);
  133. }
  134. if ((me = module_find("irc", 0, 0)))
  135. for (chan = chanset; chan != NULL; chan = chan->next)
  136. (me->funcs[IRC_CHECK_THIS_BAN])(chan, s, sticky);
  137. }
  138. }
  139. }
  140. }
  141. static void cmd_pls_exempt(struct userrec *u, int idx, char *par)
  142. {
  143. char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
  144. unsigned long int expire_time = 0, expire_foo;
  145. struct chanset_t *chan = NULL;
  146. module_entry *me = NULL;
  147. if (!use_exempts) {
  148. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  149. return;
  150. }
  151. if (!par[0]) {
  152. dprintf(idx, "Usage: +exempt <hostmask> [channel] [%%<XdXhXm>] [reason]\n");
  153. } else {
  154. who = newsplit(&par);
  155. if (par[0] && strchr(CHANMETA, par[0]))
  156. chname = newsplit(&par);
  157. else
  158. chname = 0;
  159. if (chname || !(u->flags & USER_MASTER)) {
  160. if (!chname)
  161. chname = dcc[idx].u.chat->con_chan;
  162. get_user_flagrec(u,&user,chname);
  163. chan = findchan_by_dname(chname);
  164. /* *shrug* ??? (guppy:10Feb99) */
  165. if (!chan) {
  166. dprintf(idx, "That channel doesn't exist!\n");
  167. return;
  168. } else if (private(user, chan, PRIV_OP)) {
  169. dprintf(idx, "No such channel.\n");
  170. return;
  171. } else if (!((glob_op(user) && !chan_deop(user)) || chan_op(user))) {
  172. dprintf(idx, "You don't have access to set exempts on %s.\n", chname);
  173. return;
  174. }
  175. } else
  176. chan = 0;
  177. /* Added by Q and Solal - Requested by Arty2, special thanx :) */
  178. if (par[0] == '%') {
  179. p = newsplit (&par);
  180. p_expire = p + 1;
  181. while (*(++p) != 0) {
  182. switch (tolower(*p)) {
  183. case 'd':
  184. *p = 0;
  185. expire_foo = strtol (p_expire, NULL, 10);
  186. if (expire_foo > 365)
  187. expire_foo = 365;
  188. expire_time += 86400 * expire_foo;
  189. p_expire = p + 1;
  190. break;
  191. case 'h':
  192. *p = 0;
  193. expire_foo = strtol (p_expire, NULL, 10);
  194. if (expire_foo > 8760)
  195. expire_foo = 8760;
  196. expire_time += 3600 * expire_foo;
  197. p_expire = p + 1;
  198. break;
  199. case 'm':
  200. *p = 0;
  201. expire_foo = strtol (p_expire, NULL, 10);
  202. if (expire_foo > 525600)
  203. expire_foo = 525600;
  204. expire_time += 60 * expire_foo;
  205. p_expire = p + 1;
  206. }
  207. }
  208. }
  209. if (!par[0])
  210. par = "requested";
  211. else if (strlen(par) > MASKREASON_MAX)
  212. par[MASKREASON_MAX] = 0;
  213. if (strlen(who) > UHOSTMAX - 4)
  214. who[UHOSTMAX - 4] = 0;
  215. /* Fix missing ! or @ BEFORE checking against myself */
  216. if (!strchr(who, '!')) {
  217. if (!strchr(who, '@'))
  218. egg_snprintf(s, sizeof s, "%s!*@*", who); /* Lame nick exempt */
  219. else
  220. egg_snprintf(s, sizeof s, "*!%s", who);
  221. } else if (!strchr(who, '@'))
  222. egg_snprintf(s, sizeof s, "%s@*", who); /* brain-dead? */
  223. else
  224. strncpyz(s, who, sizeof s);
  225. if ((me = module_find("server",0,0)) && me->funcs)
  226. egg_snprintf(s1, sizeof s1, "%s!%s", me->funcs[SERVER_BOTNAME],
  227. me->funcs[SERVER_BOTUSERHOST]);
  228. else
  229. egg_snprintf(s1, sizeof s1, "%s!%s@%s", origbotname, botuser, conf.bot->host);
  230. /* IRC can't understand exempts longer than 70 characters */
  231. if (strlen(s) > 70) {
  232. s[69] = '*';
  233. s[70] = 0;
  234. }
  235. if (chan) {
  236. u_addexempt(chan, s, dcc[idx].nick, par,
  237. expire_time ? now + expire_time : 0, 0);
  238. if (par[0] == '*') {
  239. par++;
  240. putlog(LOG_CMDS, "*", "#%s# (%s) +exempt %s %s (%s) (sticky)",
  241. dcc[idx].nick, dcc[idx].u.chat->con_chan, s, chan->dname, par);
  242. dprintf(idx, "New %s sticky exempt: %s (%s)\n", chan->dname, s, par);
  243. } else {
  244. putlog(LOG_CMDS, "*", "#%s# (%s) +exempt %s %s (%s)", dcc[idx].nick,
  245. dcc[idx].u.chat->con_chan, s, chan->dname, par);
  246. dprintf(idx, "New %s exempt: %s (%s)\n", chan->dname, s, par);
  247. }
  248. add_mode(chan, '+', 'e', s);
  249. } else {
  250. u_addexempt(NULL, s, dcc[idx].nick, par,
  251. expire_time ? now + expire_time : 0, 0);
  252. if (par[0] == '*') {
  253. par++;
  254. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +exempt %s (%s) (sticky)",
  255. dcc[idx].nick, s, par);
  256. dprintf(idx, "New sticky exempt: %s (%s)\n", s, par);
  257. } else {
  258. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +exempt %s (%s)", dcc[idx].nick,
  259. s, par);
  260. dprintf(idx, "New exempt: %s (%s)\n", s, par);
  261. }
  262. for (chan = chanset; chan != NULL; chan = chan->next)
  263. add_mode(chan, '+', 'e', s);
  264. }
  265. }
  266. }
  267. static void cmd_pls_invite(struct userrec *u, int idx, char *par)
  268. {
  269. char *chname = NULL, *who = NULL, s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *p = NULL, *p_expire = NULL;
  270. unsigned long int expire_time = 0, expire_foo;
  271. struct chanset_t *chan = NULL;
  272. module_entry *me = NULL;
  273. if (!use_invites) {
  274. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  275. return;
  276. }
  277. if (!par[0]) {
  278. dprintf(idx, "Usage: +invite <hostmask> [channel] [%%<XdXhXm>] [reason]\n");
  279. } else {
  280. who = newsplit(&par);
  281. if (par[0] && strchr(CHANMETA, par[0]))
  282. chname = newsplit(&par);
  283. else
  284. chname = 0;
  285. if (chname || !(u->flags & USER_MASTER)) {
  286. if (!chname)
  287. chname = dcc[idx].u.chat->con_chan;
  288. get_user_flagrec(u,&user,chname);
  289. chan = findchan_by_dname(chname);
  290. /* *shrug* ??? (guppy:10Feb99) */
  291. if (!chan) {
  292. dprintf(idx, "That channel doesn't exist!\n");
  293. return;
  294. } else if (private(user, chan, PRIV_OP)) {
  295. dprintf(idx, "No such channel.\n");
  296. return;
  297. } else if (!((glob_op(user) && !chan_deop(user)) || chan_op(user))) {
  298. dprintf(idx, "You don't have access to set invites on %s.\n", chname);
  299. return;
  300. }
  301. } else
  302. chan = 0;
  303. /* Added by Q and Solal - Requested by Arty2, special thanx :) */
  304. if (par[0] == '%') {
  305. p = newsplit (&par);
  306. p_expire = p + 1;
  307. while (*(++p) != 0) {
  308. switch (tolower(*p)) {
  309. case 'd':
  310. *p = 0;
  311. expire_foo = strtol (p_expire, NULL, 10);
  312. if (expire_foo > 365)
  313. expire_foo = 365;
  314. expire_time += 86400 * expire_foo;
  315. p_expire = p + 1;
  316. break;
  317. case 'h':
  318. *p = 0;
  319. expire_foo = strtol (p_expire, NULL, 10);
  320. if (expire_foo > 8760)
  321. expire_foo = 8760;
  322. expire_time += 3600 * expire_foo;
  323. p_expire = p + 1;
  324. break;
  325. case 'm':
  326. *p = 0;
  327. expire_foo = strtol (p_expire, NULL, 10);
  328. if (expire_foo > 525600)
  329. expire_foo = 525600;
  330. expire_time += 60 * expire_foo;
  331. p_expire = p + 1;
  332. }
  333. }
  334. }
  335. if (!par[0])
  336. par = "requested";
  337. else if (strlen(par) > MASKREASON_MAX)
  338. par[MASKREASON_MAX] = 0;
  339. if (strlen(who) > UHOSTMAX - 4)
  340. who[UHOSTMAX - 4] = 0;
  341. /* Fix missing ! or @ BEFORE checking against myself */
  342. if (!strchr(who, '!')) {
  343. if (!strchr(who, '@'))
  344. egg_snprintf(s, sizeof s, "%s!*@*", who); /* Lame nick invite */
  345. else
  346. egg_snprintf(s, sizeof s, "*!%s", who);
  347. } else if (!strchr(who, '@'))
  348. egg_snprintf(s, sizeof s, "%s@*", who); /* brain-dead? */
  349. else
  350. strncpyz(s, who, sizeof s);
  351. if ((me = module_find("server",0,0)) && me->funcs)
  352. egg_snprintf(s1, sizeof s1, "%s!%s", me->funcs[SERVER_BOTNAME],
  353. me->funcs[SERVER_BOTUSERHOST]);
  354. else
  355. egg_snprintf(s1, sizeof s1, "%s!%s@%s", origbotname, botuser, conf.bot->host);
  356. /* IRC can't understand invites longer than 70 characters */
  357. if (strlen(s) > 70) {
  358. s[69] = '*';
  359. s[70] = 0;
  360. }
  361. if (chan) {
  362. u_addinvite(chan, s, dcc[idx].nick, par,
  363. expire_time ? now + expire_time : 0, 0);
  364. if (par[0] == '*') {
  365. par++;
  366. putlog(LOG_CMDS, "*", "#%s# (%s) +invite %s %s (%s) (sticky)",
  367. dcc[idx].nick, dcc[idx].u.chat->con_chan, s, chan->dname, par);
  368. dprintf(idx, "New %s sticky invite: %s (%s)\n", chan->dname, s, par);
  369. } else {
  370. putlog(LOG_CMDS, "*", "#%s# (%s) +invite %s %s (%s)", dcc[idx].nick,
  371. dcc[idx].u.chat->con_chan, s, chan->dname, par);
  372. dprintf(idx, "New %s invite: %s (%s)\n", chan->dname, s, par);
  373. }
  374. add_mode(chan, '+', 'I', s);
  375. } else {
  376. u_addinvite(NULL, s, dcc[idx].nick, par,
  377. expire_time ? now + expire_time : 0, 0);
  378. if (par[0] == '*') {
  379. par++;
  380. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +invite %s (%s) (sticky)",
  381. dcc[idx].nick, s, par);
  382. dprintf(idx, "New sticky invite: %s (%s)\n", s, par);
  383. } else {
  384. putlog(LOG_CMDS, "*", "#%s# (GLOBAL) +invite %s (%s)", dcc[idx].nick,
  385. s, par);
  386. dprintf(idx, "New invite: %s (%s)\n", s, par);
  387. }
  388. for (chan = chanset; chan != NULL; chan = chan->next)
  389. add_mode(chan, '+', 'I', s);
  390. }
  391. }
  392. }
  393. static void cmd_mns_ban(struct userrec *u, int idx, char *par)
  394. {
  395. int console = 0, i = 0, j;
  396. struct chanset_t *chan = NULL;
  397. char s[UHOSTLEN] = "", *ban = NULL, *chname = NULL, *mask = NULL;
  398. masklist *b = NULL;
  399. if (!par[0]) {
  400. dprintf(idx, "Usage: -ban <hostmask|ban #> [channel]\n");
  401. return;
  402. }
  403. ban = newsplit(&par);
  404. if (par[0] && strchr(CHANMETA, par[0]))
  405. chname = newsplit(&par);
  406. else {
  407. chname = dcc[idx].u.chat->con_chan;
  408. console = 1;
  409. }
  410. if (chname || !(u->flags & USER_MASTER)) {
  411. if (!chname)
  412. chname = dcc[idx].u.chat->con_chan;
  413. get_user_flagrec(u, &user, chname);
  414. if (strchr(CHANMETA, chname[0]) && private(user, findchan_by_dname(chname), PRIV_OP)) {
  415. dprintf(idx, "No such channel.\n");
  416. return;
  417. }
  418. if ((!chan_op(user) && (!glob_op(user) || chan_deop(user)))) {
  419. dprintf(idx, "You don't have access to remove bans on %s.\n", chname);
  420. return;
  421. }
  422. }
  423. strncpyz(s, ban, sizeof s);
  424. if (console) {
  425. i = u_delban(NULL, s, (u->flags & USER_MASTER));
  426. if (i > 0) {
  427. if (lastdeletedmask)
  428. mask = lastdeletedmask;
  429. else
  430. mask = s;
  431. putlog(LOG_CMDS, "*", "#%s# -ban %s", dcc[idx].nick, mask);
  432. dprintf(idx, "%s: %s\n", IRC_REMOVEDBAN, mask);
  433. for (chan = chanset; chan != NULL; chan = chan->next)
  434. add_mode(chan, '-', 'b', mask);
  435. return;
  436. }
  437. }
  438. /* Channel-specific ban? */
  439. if (chname)
  440. chan = findchan_by_dname(chname);
  441. if (!chan) {
  442. dprintf(idx, "Invalid channel.\n");
  443. return;
  444. }
  445. if (str_isdigit(ban)) {
  446. i = atoi(ban);
  447. /* substract the numer of global bans to get the number of the channel ban */
  448. egg_snprintf(s, sizeof s, "%d", i);
  449. j = u_delban(0, s, 0);
  450. if (j < 0) {
  451. egg_snprintf(s, sizeof s, "%d", -j);
  452. j = u_delban(chan, s, 1);
  453. if (j > 0) {
  454. if (lastdeletedmask)
  455. mask = lastdeletedmask;
  456. else
  457. mask = s;
  458. putlog(LOG_CMDS, "*", "#%s# (%s) -ban %s", dcc[idx].nick, chan->dname,
  459. mask);
  460. dprintf(idx, "Removed %s channel ban: %s\n", chan->dname, mask);
  461. add_mode(chan, '-', 'b', mask);
  462. return;
  463. }
  464. }
  465. i = 0;
  466. for (b = chan->channel.ban; b && b->mask && b->mask[0]; b = b->next) {
  467. if ((!u_equals_mask(global_bans, b->mask)) &&
  468. (!u_equals_mask(chan->bans, b->mask))) {
  469. i++;
  470. if (i == -j) {
  471. add_mode(chan, '-', 'b', b->mask);
  472. dprintf(idx, "%s '%s' on %s.\n", IRC_REMOVEDBAN,
  473. b->mask, chan->dname);
  474. putlog(LOG_CMDS, "*", "#%s# (%s) -ban %s [on channel]",
  475. dcc[idx].nick, dcc[idx].u.chat->con_chan, ban);
  476. return;
  477. }
  478. }
  479. }
  480. } else {
  481. j = u_delban(chan, ban, 1);
  482. if (j > 0) {
  483. putlog(LOG_CMDS, "*", "#%s# (%s) -ban %s", dcc[idx].nick,
  484. dcc[idx].u.chat->con_chan, ban);
  485. dprintf(idx, "Removed %s channel ban: %s\n", chname, ban);
  486. add_mode(chan, '-', 'b', ban);
  487. return;
  488. }
  489. for (b = chan->channel.ban; b && b->mask && b->mask[0]; b = b->next) {
  490. if (!rfc_casecmp(b->mask, ban)) {
  491. add_mode(chan, '-', 'b', b->mask);
  492. dprintf(idx, "%s '%s' on %s.\n", IRC_REMOVEDBAN, b->mask, chan->dname);
  493. putlog(LOG_CMDS, "*", "#%s# (%s) -ban %s [on channel]",
  494. dcc[idx].nick, dcc[idx].u.chat->con_chan, ban);
  495. return;
  496. }
  497. }
  498. }
  499. dprintf(idx, "No such ban.\n");
  500. }
  501. static void cmd_mns_exempt(struct userrec *u, int idx, char *par)
  502. {
  503. int console = 0, i = 0, j;
  504. struct chanset_t *chan = NULL;
  505. char s[UHOSTLEN] = "", *exempt = NULL, *chname = NULL, *mask = NULL;
  506. masklist *e = NULL;
  507. if (!use_exempts) {
  508. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  509. return;
  510. }
  511. if (!par[0]) {
  512. dprintf(idx, "Usage: -exempt <hostmask|exempt #> [channel]\n");
  513. return;
  514. }
  515. exempt = newsplit(&par);
  516. if (par[0] && strchr(CHANMETA, par[0]))
  517. chname = newsplit(&par);
  518. else {
  519. chname = dcc[idx].u.chat->con_chan;
  520. console = 1;
  521. }
  522. if (chname || !(u->flags & USER_MASTER)) {
  523. if (!chname)
  524. chname = dcc[idx].u.chat->con_chan;
  525. get_user_flagrec(u, &user, chname);
  526. if (strchr(CHANMETA, chname[0]) && private(user, findchan_by_dname(chname), PRIV_OP)) {
  527. dprintf(idx, "No such channel.\n");
  528. return;
  529. }
  530. if ((!chan_op(user) && (!glob_op(user) || chan_deop(user)))) {
  531. dprintf(idx, "You don't have access to remove exempts on %s.\n", chname);
  532. return;
  533. }
  534. }
  535. strncpyz(s, exempt, sizeof s);
  536. if (console) {
  537. i = u_delexempt(NULL, s, (u->flags & USER_MASTER));
  538. if (i > 0) {
  539. if (lastdeletedmask)
  540. mask = lastdeletedmask;
  541. else
  542. mask = s;
  543. putlog(LOG_CMDS, "*", "#%s# -exempt %s", dcc[idx].nick, mask);
  544. dprintf(idx, "%s: %s\n", IRC_REMOVEDEXEMPT, mask);
  545. for (chan = chanset; chan != NULL; chan = chan->next)
  546. add_mode(chan, '-', 'e', mask);
  547. return;
  548. }
  549. }
  550. /* Channel-specific exempt? */
  551. if (chname)
  552. chan = findchan_by_dname(chname);
  553. if (!chan) {
  554. dprintf(idx, "Invalid channel.\n");
  555. return;
  556. }
  557. if (str_isdigit(exempt)) {
  558. i = atoi(exempt);
  559. /* substract the numer of global exempts to get the number of the channel exempt */
  560. egg_snprintf(s, sizeof s, "%d", i);
  561. j = u_delexempt(0, s, 0);
  562. if (j < 0) {
  563. egg_snprintf(s, sizeof s, "%d", -j);
  564. j = u_delexempt(chan, s, 1);
  565. if (j > 0) {
  566. if (lastdeletedmask)
  567. mask = lastdeletedmask;
  568. else
  569. mask = s;
  570. putlog(LOG_CMDS, "*", "#%s# (%s) -exempt %s", dcc[idx].nick,
  571. chan->dname, mask);
  572. dprintf(idx, "Removed %s channel exempt: %s\n", chan->dname, mask);
  573. add_mode(chan, '-', 'e', mask);
  574. return;
  575. }
  576. }
  577. i = 0;
  578. for (e = chan->channel.exempt; e && e->mask && e->mask[0]; e = e->next) {
  579. if (!u_equals_mask(global_exempts, e->mask) &&
  580. !u_equals_mask(chan->exempts, e->mask)) {
  581. i++;
  582. if (i == -j) {
  583. add_mode(chan, '-', 'e', e->mask);
  584. dprintf(idx, "%s '%s' on %s.\n", IRC_REMOVEDEXEMPT,
  585. e->mask, chan->dname);
  586. putlog(LOG_CMDS, "*", "#%s# (%s) -exempt %s [on channel]",
  587. dcc[idx].nick, dcc[idx].u.chat->con_chan, exempt);
  588. return;
  589. }
  590. }
  591. }
  592. } else {
  593. j = u_delexempt(chan, exempt, 1);
  594. if (j > 0) {
  595. putlog(LOG_CMDS, "*", "#%s# (%s) -exempt %s", dcc[idx].nick,
  596. dcc[idx].u.chat->con_chan, exempt);
  597. dprintf(idx, "Removed %s channel exempt: %s\n", chname, exempt);
  598. add_mode(chan, '-', 'e', exempt);
  599. return;
  600. }
  601. for (e = chan->channel.exempt; e && e->mask && e->mask[0]; e = e->next) {
  602. if (!rfc_casecmp(e->mask, exempt)) {
  603. add_mode(chan, '-', 'e', e->mask);
  604. dprintf(idx, "%s '%s' on %s.\n",
  605. IRC_REMOVEDEXEMPT, e->mask, chan->dname);
  606. putlog(LOG_CMDS, "*", "#%s# (%s) -exempt %s [on channel]",
  607. dcc[idx].nick, dcc[idx].u.chat->con_chan, exempt);
  608. return;
  609. }
  610. }
  611. }
  612. dprintf(idx, "No such exemption.\n");
  613. }
  614. static void cmd_mns_invite(struct userrec *u, int idx, char *par)
  615. {
  616. int console = 0, i = 0, j;
  617. struct chanset_t *chan = NULL;
  618. char s[UHOSTLEN] = "", *invite = NULL, *chname = NULL, *mask = NULL;
  619. masklist *inv = NULL;
  620. if (!use_invites) {
  621. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  622. return;
  623. }
  624. if (!par[0]) {
  625. dprintf(idx, "Usage: -invite <hostmask|invite #> [channel]\n");
  626. return;
  627. }
  628. invite = newsplit(&par);
  629. if (par[0] && strchr(CHANMETA, par[0]))
  630. chname = newsplit(&par);
  631. else {
  632. chname = dcc[idx].u.chat->con_chan;
  633. console = 1;
  634. }
  635. if (chname || !(u->flags & USER_MASTER)) {
  636. if (!chname)
  637. chname = dcc[idx].u.chat->con_chan;
  638. get_user_flagrec(u, &user, chname);
  639. if (strchr(CHANMETA, chname[0]) && private(user, findchan_by_dname(chname), PRIV_OP)) {
  640. dprintf(idx, "No such channel.\n");
  641. return;
  642. }
  643. if ((!chan_op(user) && (!glob_op(user) || chan_deop(user)))) {
  644. dprintf(idx, "You don't have access to remove invites on %s.\n", chname);
  645. return;
  646. }
  647. }
  648. strncpyz(s, invite, sizeof s);
  649. if (console) {
  650. i = u_delinvite(NULL, s, (u->flags & USER_MASTER));
  651. if (i > 0) {
  652. if (lastdeletedmask)
  653. mask = lastdeletedmask;
  654. else
  655. mask = s;
  656. putlog(LOG_CMDS, "*", "#%s# -invite %s", dcc[idx].nick, mask);
  657. dprintf(idx, "%s: %s\n", IRC_REMOVEDINVITE, mask);
  658. for (chan = chanset; chan != NULL; chan = chan->next)
  659. add_mode(chan, '-', 'I', mask);
  660. return;
  661. }
  662. }
  663. /* Channel-specific invite? */
  664. if (chname)
  665. chan = findchan_by_dname(chname);
  666. if (!chan) {
  667. dprintf(idx, "Invalid channel.\n");
  668. return;
  669. }
  670. if (str_isdigit(invite)) {
  671. i = atoi(invite);
  672. /* substract the numer of global invites to get the number of the channel invite */
  673. egg_snprintf(s, sizeof s, "%d", i);
  674. j = u_delinvite(0, s, 0);
  675. if (j < 0) {
  676. egg_snprintf(s, sizeof s, "%d", -j);
  677. j = u_delinvite(chan, s, 1);
  678. if (j > 0) {
  679. if (lastdeletedmask)
  680. mask = lastdeletedmask;
  681. else
  682. mask = s;
  683. putlog(LOG_CMDS, "*", "#%s# (%s) -invite %s", dcc[idx].nick,
  684. chan->dname, mask);
  685. dprintf(idx, "Removed %s channel invite: %s\n", chan->dname, mask);
  686. add_mode(chan, '-', 'I', mask);
  687. return;
  688. }
  689. }
  690. i = 0;
  691. for (inv = chan->channel.invite; inv && inv->mask && inv->mask[0];
  692. inv = inv->next) {
  693. if (!u_equals_mask(global_invites, inv->mask) &&
  694. !u_equals_mask(chan->invites, inv->mask)) {
  695. i++;
  696. if (i == -j) {
  697. add_mode(chan, '-', 'I', inv->mask);
  698. dprintf(idx, "%s '%s' on %s.\n", IRC_REMOVEDINVITE,
  699. inv->mask, chan->dname);
  700. putlog(LOG_CMDS, "*", "#%s# (%s) -invite %s [on channel]",
  701. dcc[idx].nick, dcc[idx].u.chat->con_chan, invite);
  702. return;
  703. }
  704. }
  705. }
  706. } else {
  707. j = u_delinvite(chan, invite, 1);
  708. if (j > 0) {
  709. putlog(LOG_CMDS, "*", "#%s# (%s) -invite %s", dcc[idx].nick,
  710. dcc[idx].u.chat->con_chan, invite);
  711. dprintf(idx, "Removed %s channel invite: %s\n", chname, invite);
  712. add_mode(chan, '-', 'I', invite);
  713. return;
  714. }
  715. for (inv = chan->channel.invite; inv && inv->mask && inv->mask[0];
  716. inv = inv->next) {
  717. if (!rfc_casecmp(inv->mask, invite)) {
  718. add_mode(chan, '-', 'I', inv->mask);
  719. dprintf(idx, "%s '%s' on %s.\n",
  720. IRC_REMOVEDINVITE, inv->mask, chan->dname);
  721. putlog(LOG_CMDS, "*", "#%s# (%s) -invite %s [on channel]",
  722. dcc[idx].nick, dcc[idx].u.chat->con_chan, invite);
  723. return;
  724. }
  725. }
  726. }
  727. dprintf(idx, "No such invite.\n");
  728. }
  729. static void cmd_bans(struct userrec *u, int idx, char *par)
  730. {
  731. if (!egg_strcasecmp(par, "all")) {
  732. putlog(LOG_CMDS, "*", "#%s# bans all", dcc[idx].nick);
  733. tell_bans(idx, 1, "");
  734. } else {
  735. putlog(LOG_CMDS, "*", "#%s# bans %s", dcc[idx].nick, par);
  736. tell_bans(idx, 0, par);
  737. }
  738. }
  739. static void cmd_exempts(struct userrec *u, int idx, char *par)
  740. {
  741. if (!use_exempts) {
  742. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  743. return;
  744. }
  745. if (!egg_strcasecmp(par, "all")) {
  746. putlog(LOG_CMDS, "*", "#%s# exempts all", dcc[idx].nick);
  747. tell_exempts(idx, 1, "");
  748. } else {
  749. putlog(LOG_CMDS, "*", "#%s# exempts %s", dcc[idx].nick, par);
  750. tell_exempts(idx, 0, par);
  751. }
  752. }
  753. static void cmd_invites(struct userrec *u, int idx, char *par)
  754. {
  755. if (!use_invites) {
  756. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  757. return;
  758. }
  759. if (!egg_strcasecmp(par, "all")) {
  760. putlog(LOG_CMDS, "*", "#%s# invites all", dcc[idx].nick);
  761. tell_invites(idx, 1, "");
  762. } else {
  763. putlog(LOG_CMDS, "*", "#%s# invites %s", dcc[idx].nick, par);
  764. tell_invites(idx, 0, par);
  765. }
  766. }
  767. static void cmd_info(struct userrec *u, int idx, char *par)
  768. {
  769. char s[512] = "", *chname = NULL, *s1 = NULL;
  770. int locked = 0;
  771. if (!use_info) {
  772. dprintf(idx, "Info storage is turned off.\n");
  773. return;
  774. }
  775. s1 = get_user(&USERENTRY_INFO, u);
  776. if (s1 && s1[0] == '@')
  777. locked = 1;
  778. if (par[0] && strchr(CHANMETA, par[0])) {
  779. chname = newsplit(&par);
  780. if (!findchan_by_dname(chname)) {
  781. dprintf(idx, "No such channel.\n");
  782. return;
  783. }
  784. get_handle_chaninfo(dcc[idx].nick, chname, s);
  785. if (s[0] == '@')
  786. locked = 1;
  787. s1 = s;
  788. } else
  789. chname = 0;
  790. if (!par[0]) {
  791. if (s1 && s1[0] == '@')
  792. s1++;
  793. if (s1 && s1[0]) {
  794. if (chname) {
  795. dprintf(idx, "Info on %s: %s\n", chname, s1);
  796. dprintf(idx, "Use 'info %s none' to remove it.\n", chname);
  797. } else {
  798. dprintf(idx, "Default info: %s\n", s1);
  799. dprintf(idx, "Use 'info none' to remove it.\n");
  800. }
  801. } else
  802. dprintf(idx, "No info has been set for you.\n");
  803. putlog(LOG_CMDS, "*", "#%s# info %s", dcc[idx].nick, chname ? chname : "");
  804. return;
  805. }
  806. if (locked && !(u && (u->flags & USER_MASTER))) {
  807. dprintf(idx, "Your info line is locked. Sorry.\n");
  808. return;
  809. }
  810. if (!egg_strcasecmp(par, "none")) {
  811. if (chname) {
  812. par[0] = 0;
  813. set_handle_chaninfo(userlist, dcc[idx].nick, chname, NULL);
  814. dprintf(idx, "Removed your info line on %s.\n", chname);
  815. putlog(LOG_CMDS, "*", "#%s# info %s none", dcc[idx].nick, chname);
  816. } else {
  817. set_user(&USERENTRY_INFO, u, NULL);
  818. dprintf(idx, "Removed your default info line.\n");
  819. putlog(LOG_CMDS, "*", "#%s# info none", dcc[idx].nick);
  820. }
  821. return;
  822. }
  823. /* if (par[0] == '@') This is stupid, and prevents a users info from being locked */
  824. /* par++; without .tcl, or a tcl script, aka, 'half-assed' -poptix 4Jun01 */
  825. if (chname) {
  826. set_handle_chaninfo(userlist, dcc[idx].nick, chname, par);
  827. dprintf(idx, "Your info on %s is now: %s\n", chname, par);
  828. putlog(LOG_CMDS, "*", "#%s# info %s ...", dcc[idx].nick, chname);
  829. } else {
  830. set_user(&USERENTRY_INFO, u, par);
  831. dprintf(idx, "Your default info is now: %s\n", par);
  832. putlog(LOG_CMDS, "*", "#%s# info ...", dcc[idx].nick);
  833. }
  834. }
  835. static void cmd_chinfo(struct userrec *u, int idx, char *par)
  836. {
  837. char *handle = NULL, *chname = NULL;
  838. struct userrec *u1 = NULL;
  839. if (!use_info) {
  840. dprintf(idx, "Info storage is turned off.\n");
  841. return;
  842. }
  843. handle = newsplit(&par);
  844. if (!handle[0]) {
  845. dprintf(idx, "Usage: chinfo <handle> [channel] <new-info>\n");
  846. return;
  847. }
  848. u1 = get_user_by_handle(userlist, handle);
  849. if (!u1) {
  850. dprintf(idx, "No such user.\n");
  851. return;
  852. }
  853. if (par[0] && strchr(CHANMETA, par[0])) {
  854. chname = newsplit(&par);
  855. if (!findchan_by_dname(chname)) {
  856. dprintf(idx, "No such channel.\n");
  857. return;
  858. }
  859. } else
  860. chname = 0;
  861. if ((u1->flags & USER_BOT) && !(u->flags & USER_MASTER)) {
  862. dprintf(idx, "You have to be master to change bots info.\n");
  863. return;
  864. }
  865. if ((u1->flags & USER_OWNER) && !(u->flags & USER_OWNER)) {
  866. dprintf(idx, "You can't change info for the bot owner.\n");
  867. return;
  868. }
  869. if (chname) {
  870. get_user_flagrec(u, &user, chname);
  871. get_user_flagrec(u1, &victim, chname);
  872. if ((chan_owner(victim) || glob_owner(victim)) &&
  873. !(glob_owner(user) || chan_owner(user))) {
  874. dprintf(idx, "You can't change info for the channel owner.\n");
  875. return;
  876. }
  877. }
  878. putlog(LOG_CMDS, "*", "#%s# chinfo %s %s %s", dcc[idx].nick, handle,
  879. chname ? chname : par, chname ? par : "");
  880. if (!egg_strcasecmp(par, "none"))
  881. par[0] = 0;
  882. if (chname) {
  883. set_handle_chaninfo(userlist, handle, chname, par);
  884. if (par[0] == '@')
  885. dprintf(idx, "New info (LOCKED) for %s on %s: %s\n", handle, chname,
  886. &par[1]);
  887. else if (par[0])
  888. dprintf(idx, "New info for %s on %s: %s\n", handle, chname, par);
  889. else
  890. dprintf(idx, "Wiped info for %s on %s\n", handle, chname);
  891. } else {
  892. set_user(&USERENTRY_INFO, u1, par[0] ? par : NULL);
  893. if (par[0] == '@')
  894. dprintf(idx, "New default info (LOCKED) for %s: %s\n", handle, &par[1]);
  895. else if (par[0])
  896. dprintf(idx, "New default info for %s: %s\n", handle, par);
  897. else
  898. dprintf(idx, "Wiped default info for %s\n", handle);
  899. }
  900. }
  901. static void cmd_slowjoin(struct userrec *u, int idx, char *par)
  902. {
  903. int intvl = 0, delay = 0, count = 1;
  904. char *chname = NULL, *p = NULL, buf[2048] = "", buf2[1048] = "";
  905. struct chanset_t *chan = NULL;
  906. tand_t *bot = NULL;
  907. /* slowjoin #chan 60 */
  908. putlog(LOG_CMDS, "*", "#%s# slowjoin %s", dcc[idx].nick, par);
  909. chname = newsplit(&par);
  910. p = newsplit(&par);
  911. intvl = atoi(p);
  912. if (!chname[0] || !p[0]) {
  913. dprintf(idx, "Usage: slowjoin <channel> <interval-seconds> [channel options]\n");
  914. return;
  915. }
  916. if (intvl < 10) {
  917. dprintf(idx, "Interval must be at least 10 seconds\n");
  918. return;
  919. }
  920. if ((chan = findchan_by_dname(chname))) {
  921. dprintf(idx, "Already on %s\n", chan->dname);
  922. return;
  923. }
  924. if (!strchr(CHANMETA, chname[0])) {
  925. dprintf(idx, "Invalid channel name\n");
  926. return;
  927. }
  928. strcpy(buf, "+inactive ");
  929. if (par[0])
  930. strncat(buf, par, sizeof(buf));
  931. if (channel_add(NULL, chname, buf) == ERROR) {
  932. dprintf(idx, "Invalid channel.\n");
  933. return;
  934. }
  935. chan = findchan_by_dname(chname);
  936. if (!chan) {
  937. dprintf(idx, "Hmmm... Channel didn't get added. Weird *shrug*\n");
  938. return;
  939. }
  940. sprintf(buf2, "cjoin %s %s", chan->dname, buf);
  941. putallbots(buf2);
  942. #ifdef HUB
  943. count=0;
  944. #else /* !HUB */
  945. count=1;
  946. #endif /* HUB */
  947. for (bot = tandbot; bot; bot = bot->next) {
  948. struct userrec *ubot = NULL;
  949. char tmp[100] = "";
  950. ubot = get_user_by_handle(userlist, bot->bot);
  951. if (ubot) {
  952. /* Variation: 60 secs intvl should be 60 +/- 15 */
  953. if (bot_hublevel(ubot) < 999) {
  954. sprintf(tmp, "sj %s 0\n", chan->dname);
  955. } else {
  956. int v = (random() % (intvl / 2)) - (intvl / 4);
  957. delay += intvl;
  958. sprintf(tmp, "sj %s %i\n", chan->dname, delay + v);
  959. count++;
  960. }
  961. putbot(ubot->handle, tmp);
  962. }
  963. }
  964. dprintf(idx, "%i bots joining %s during the next %i seconds\n", count, chan->dname, delay);
  965. chan->status &= ~CHAN_INACTIVE;
  966. #ifdef LEAF
  967. if (shouldjoin(chan))
  968. dprintf(DP_MODE, "JOIN %s %s\n", chan->name, chan->key_prot);
  969. #endif /* LEAF */
  970. }
  971. static void cmd_slowpart(struct userrec *u, int idx, char *par)
  972. {
  973. int intvl = 0, delay = 0, count = 1;
  974. char *chname = NULL, *p = NULL;
  975. struct chanset_t *chan = NULL;
  976. tand_t *bot = NULL;
  977. /* slowpart #chan 60 */
  978. putlog(LOG_CMDS, "*", "#%s# slowpart %s", dcc[idx].nick, par);
  979. chname = newsplit(&par);
  980. p = newsplit(&par);
  981. intvl = atoi(p);
  982. if (!chname[0] || !p[0]) {
  983. dprintf(idx, "Usage: slowpart <channel> <interval-seconds>\n");
  984. return;
  985. }
  986. if (intvl < 10) {
  987. dprintf(idx, "Interval must be at least 10 seconds\n");
  988. return;
  989. }
  990. if (!(chan = findchan_by_dname(chname))) {
  991. dprintf(idx, "Not on %s\n", chan->dname);
  992. return;
  993. }
  994. remove_channel(chan);
  995. #ifdef HUB
  996. write_userfile(-1);
  997. #endif /* HUB */
  998. dprintf(idx, "Channel %s removed from the bot.\n", chname);
  999. dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
  1000. if (findchan_by_dname(chname)) {
  1001. dprintf(idx, "Hmmm... Channel didn't get removed. Weird *shrug*\n");
  1002. return;
  1003. }
  1004. #ifdef HUB
  1005. count = 0;
  1006. #else /* !HUB */
  1007. count = 1;
  1008. #endif /* HUB */
  1009. for (bot = tandbot; bot; bot = bot->next) {
  1010. char tmp[100] = "";
  1011. struct userrec *ubot = NULL;
  1012. ubot = get_user_by_handle(userlist, bot->bot);
  1013. /* Variation: 60 secs intvl should be 60 +/- 15 */
  1014. if (ubot) {
  1015. if (bot_hublevel(ubot) < 999) {
  1016. sprintf(tmp, "sp %s 0\n", chname);
  1017. } else {
  1018. int v = (random() % (intvl / 2)) - (intvl / 4);
  1019. delay += intvl;
  1020. sprintf(tmp, "sp %s %i\n", chname, delay + v);
  1021. count++;
  1022. }
  1023. putbot(ubot->handle, tmp);
  1024. }
  1025. }
  1026. dprintf(idx, "%i bots parting %s during the next %i seconds\n", count, chname, delay);
  1027. #ifdef LEAF
  1028. dprintf(DP_MODE, "PART %s\n", chname);
  1029. #endif /* LEAF */
  1030. }
  1031. static void cmd_stick_yn(int idx, char *par, int yn)
  1032. {
  1033. int i = 0, j;
  1034. struct chanset_t *chan = NULL, *achan = NULL;
  1035. char *stick_type = NULL, s[UHOSTLEN] = "", chname[81] = "";
  1036. module_entry *me = NULL;
  1037. stick_type = newsplit(&par);
  1038. strncpyz(s, newsplit(&par), sizeof s);
  1039. strncpyz(chname, newsplit(&par), sizeof chname);
  1040. if (egg_strcasecmp(stick_type, "exempt") &&
  1041. egg_strcasecmp(stick_type, "invite") &&
  1042. egg_strcasecmp(stick_type, "ban")) {
  1043. strncpyz(chname, s, sizeof chname);
  1044. strncpyz(s, stick_type, sizeof s);
  1045. }
  1046. if (!s[0]) {
  1047. dprintf(idx, "Usage: %sstick [ban/exempt/invite] <hostmask or number> [channel]\n", yn ? "" : "un");
  1048. return;
  1049. }
  1050. /* Now deal with exemptions */
  1051. if (!egg_strcasecmp(stick_type, "exempt")) {
  1052. if (!use_exempts) {
  1053. dprintf(idx, "This command can only be used with use-exempts enabled.\n");
  1054. return;
  1055. }
  1056. if (!chname[0]) {
  1057. i = u_setsticky_exempt(NULL, s,
  1058. (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
  1059. if (i > 0) {
  1060. putlog(LOG_CMDS, "*", "#%s# %sstick exempt %s",
  1061. dcc[idx].nick, yn ? "" : "un", s);
  1062. dprintf(idx, "%stuck exempt: %s\n", yn ? "S" : "Uns", s);
  1063. return;
  1064. }
  1065. strncpyz(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  1066. }
  1067. /* Channel-specific exempt? */
  1068. if (!(chan = findchan_by_dname(chname))) {
  1069. dprintf(idx, "No such channel.\n");
  1070. return;
  1071. }
  1072. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1073. if (private(user, chan, PRIV_OP)) {
  1074. dprintf(idx, "No such channel.\n");
  1075. return;
  1076. }
  1077. if (str_isdigit(s)) {
  1078. /* substract the numer of global exempts to get the number of the channel exempt */
  1079. j = u_setsticky_exempt(NULL, s, -1);
  1080. if (j < 0)
  1081. egg_snprintf(s, sizeof s, "%d", -j);
  1082. }
  1083. j = u_setsticky_exempt(chan, s, yn);
  1084. if (j > 0) {
  1085. putlog(LOG_CMDS, "*", "#%s# %sstick exempt %s %s", dcc[idx].nick,
  1086. yn ? "" : "un", s, chname);
  1087. dprintf(idx, "%stuck %s exempt: %s\n", yn ? "S" : "Uns", chname, s);
  1088. return;
  1089. }
  1090. dprintf(idx, "No such exempt.\n");
  1091. return;
  1092. /* Now the invites */
  1093. } else if (!egg_strcasecmp(stick_type, "invite")) {
  1094. if (!use_invites) {
  1095. dprintf(idx, "This command can only be used with use-invites enabled.\n");
  1096. return;
  1097. }
  1098. if (!chname[0]) {
  1099. i = u_setsticky_invite(NULL, s,
  1100. (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
  1101. if (i > 0) {
  1102. putlog(LOG_CMDS, "*", "#%s# %sstick invite %s",
  1103. dcc[idx].nick, yn ? "" : "un", s);
  1104. dprintf(idx, "%stuck invite: %s\n", yn ? "S" : "Uns", s);
  1105. return;
  1106. }
  1107. strncpyz(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  1108. }
  1109. /* Channel-specific invite? */
  1110. if (!(chan = findchan_by_dname(chname))) {
  1111. dprintf(idx, "No such channel.\n");
  1112. return;
  1113. }
  1114. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1115. if (private(user, chan, PRIV_OP)) {
  1116. dprintf(idx, "No such channel.\n");
  1117. return;
  1118. }
  1119. if (str_isdigit(s)) {
  1120. /* substract the numer of global invites to get the number of the channel invite */
  1121. j = u_setsticky_invite(NULL, s, -1);
  1122. if (j < 0)
  1123. egg_snprintf(s, sizeof s, "%d", -j);
  1124. }
  1125. j = u_setsticky_invite(chan, s, yn);
  1126. if (j > 0) {
  1127. putlog(LOG_CMDS, "*", "#%s# %sstick invite %s %s", dcc[idx].nick, yn ? "" : "un", s, chname);
  1128. dprintf(idx, "%stuck %s invite: %s\n", yn ? "S" : "Uns", chname, s);
  1129. return;
  1130. }
  1131. dprintf(idx, "No such invite.\n");
  1132. return;
  1133. }
  1134. if (!chname[0]) {
  1135. i = u_setsticky_ban(NULL, s,
  1136. (dcc[idx].user->flags & USER_MASTER) ? yn : -1);
  1137. if (i > 0) {
  1138. putlog(LOG_CMDS, "*", "#%s# %sstick ban %s", dcc[idx].nick, yn ? "" : "un", s);
  1139. dprintf(idx, "%stuck ban: %s\n", yn ? "S" : "Uns", s);
  1140. if ((me = module_find("irc", 0, 0)))
  1141. for (achan = chanset; achan != NULL; achan = achan->next)
  1142. (me->funcs[IRC_CHECK_THIS_BAN])(achan, s, yn);
  1143. return;
  1144. }
  1145. strncpyz(chname, dcc[idx].u.chat->con_chan, sizeof chname);
  1146. }
  1147. /* Channel-specific ban? */
  1148. if (!(chan = findchan_by_dname(chname))) {
  1149. dprintf(idx, "No such channel.\n");
  1150. return;
  1151. }
  1152. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  1153. if (private(user, chan, PRIV_OP)) {
  1154. dprintf(idx, "No such channel.\n");
  1155. return;
  1156. }
  1157. if (str_isdigit(s)) {
  1158. /* substract the numer of global bans to get the number of the channel ban */
  1159. j = u_setsticky_ban(NULL, s, -1);
  1160. if (j < 0)
  1161. egg_snprintf(s, sizeof s, "%d", -j);
  1162. }
  1163. j = u_setsticky_ban(chan, s, yn);
  1164. if (j > 0) {
  1165. putlog(LOG_CMDS, "*", "#%s# %sstick ban %s %s", dcc[idx].nick, yn ? "" : "un", s, chname);
  1166. dprintf(idx, "%stuck %s ban: %s\n", yn ? "S" : "Uns", chname, s);
  1167. if ((me = module_find("irc", 0, 0)))
  1168. (me->funcs[IRC_CHECK_THIS_BAN])(chan, s, yn);
  1169. return;
  1170. }
  1171. dprintf(idx, "No such ban.\n");
  1172. }
  1173. static void cmd_stick(struct userrec *u, int idx, char *par)
  1174. {
  1175. cmd_stick_yn(idx, par, 1);
  1176. }
  1177. static void cmd_unstick(struct userrec *u, int idx, char *par)
  1178. {
  1179. cmd_stick_yn(idx, par, 0);
  1180. }
  1181. static void cmd_pls_chrec(struct userrec *u, int idx, char *par)
  1182. {
  1183. char *nick = NULL, *chn = NULL;
  1184. struct chanset_t *chan = NULL;
  1185. struct userrec *u1 = NULL;
  1186. struct chanuserrec *chanrec = NULL;
  1187. if (!par[0]) {
  1188. dprintf(idx, "Usage: +chrec <user> [channel]\n");
  1189. return;
  1190. }
  1191. nick = newsplit(&par);
  1192. u1 = get_user_by_handle(userlist, nick);
  1193. if (!u1) {
  1194. dprintf(idx, "No such user.\n");
  1195. return;
  1196. }
  1197. if (!par[0])
  1198. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  1199. else {
  1200. chn = newsplit(&par);
  1201. chan = findchan_by_dname(chn);
  1202. }
  1203. if (!chan) {
  1204. dprintf(idx, "No such channel.\n");
  1205. return;
  1206. }
  1207. get_user_flagrec(u, &user, chan->dname);
  1208. get_user_flagrec(u1, &victim, chan->dname);
  1209. if (private(user, chan, PRIV_OP)) {
  1210. dprintf(idx, "No such channel.\n");
  1211. return;
  1212. }
  1213. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  1214. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  1215. (glob_owner(victim) && !glob_owner(user))) {
  1216. dprintf(idx, "You have no permission to do that.\n");
  1217. return;
  1218. }
  1219. chanrec = get_chanrec(u1, chan->dname);
  1220. if (chanrec) {
  1221. dprintf(idx, "User %s already has a channel record for %s.\n",
  1222. nick, chan->dname);
  1223. return;
  1224. }
  1225. putlog(LOG_CMDS, "*", "#%s# +chrec %s %s", dcc[idx].nick,
  1226. nick, chan->dname);
  1227. add_chanrec(u1, chan->dname);
  1228. dprintf(idx, "Added %s channel record for %s.\n", chan->dname, nick);
  1229. }
  1230. static void cmd_mns_chrec(struct userrec *u, int idx, char *par)
  1231. {
  1232. char *nick = NULL, *chn = NULL;
  1233. struct userrec *u1 = NULL;
  1234. struct chanuserrec *chanrec = NULL;
  1235. if (!par[0]) {
  1236. dprintf(idx, "Usage: -chrec <user> [channel]\n");
  1237. return;
  1238. }
  1239. nick = newsplit(&par);
  1240. u1 = get_user_by_handle(userlist, nick);
  1241. if (!u1) {
  1242. dprintf(idx, "No such user.\n");
  1243. return;
  1244. }
  1245. if (!par[0]) {
  1246. struct chanset_t *chan;
  1247. chan = findchan_by_dname(dcc[idx].u.chat->con_chan);
  1248. if (chan)
  1249. chn = chan->dname;
  1250. else {
  1251. dprintf(idx, "Invalid console channel.\n");
  1252. return;
  1253. }
  1254. } else
  1255. chn = newsplit(&par);
  1256. get_user_flagrec(u, &user, chn);
  1257. get_user_flagrec(u1, &victim, chn);
  1258. if (private(user, findchan_by_dname(chn), PRIV_OP)) {
  1259. dprintf(idx, "No such channel.\n");
  1260. return;
  1261. }
  1262. if ((!glob_master(user) && !chan_master(user)) || /* drummer */
  1263. (chan_owner(victim) && !chan_owner(user) && !glob_owner(user)) ||
  1264. (glob_owner(victim) && !glob_owner(user))) {
  1265. dprintf(idx, "You have no permission to do that.\n");
  1266. return;
  1267. }
  1268. chanrec = get_chanrec(u1, chn);
  1269. if (!chanrec) {
  1270. dprintf(idx, "User %s doesn't have a channel record for %s.\n", nick, chn);
  1271. return;
  1272. }
  1273. putlog(LOG_CMDS, "*", "#%s# -chrec %s %s", dcc[idx].nick, nick, chn);
  1274. del_chanrec(u1, chn);
  1275. dprintf(idx, "Removed %s channel record from %s.\n", chn, nick);
  1276. }
  1277. static void cmd_cycle(struct userrec *u, int idx, char *par)
  1278. {
  1279. char *chname = NULL;
  1280. char buf2[1024] = "";
  1281. int delay = 10;
  1282. struct chanset_t *chan = NULL;
  1283. putlog(LOG_CMDS, "*", "#%s# cycle %s", dcc[idx].nick, par);
  1284. if (!par[0]) {
  1285. dprintf(idx, "Usage: cycle [%s]<channel> [delay]\n", CHANMETA);
  1286. dprintf(idx, "rejoin delay defaults to '10'\n");
  1287. return;
  1288. }
  1289. chname = newsplit(&par);
  1290. chan = findchan_by_dname(chname);
  1291. if (!chan) {
  1292. dprintf(idx, "%s it not a valid channel.\n", chname);
  1293. return;
  1294. }
  1295. if (par[0])
  1296. delay = atoi(newsplit(&par));
  1297. sprintf(buf2, "cycle %s %d", chname, delay); //this just makes the bot PART
  1298. putallbots(buf2);
  1299. #ifdef LEAF
  1300. do_chanset(NULL, chan, "+inactive", DO_LOCAL);
  1301. dprintf(DP_SERVER, "PART %s\n", chan->name);
  1302. chan->channel.jointime = ((now + delay) - server_lag);
  1303. #endif /* LEAF */
  1304. }
  1305. static void cmd_down(struct userrec *u, int idx, char *par)
  1306. {
  1307. char *chname = NULL, buf2[1024] = "";
  1308. struct chanset_t *chan = NULL;
  1309. putlog(LOG_CMDS, "*", "#%s# down %s", dcc[idx].nick, par);
  1310. if (!par[0]) {
  1311. dprintf(idx, "Usage: down [%s]<channel>\n", CHANMETA);
  1312. return;
  1313. }
  1314. chname = newsplit(&par);
  1315. chan = findchan_by_dname(chname);
  1316. if (!chan) {
  1317. dprintf(idx, "%s it not a valid channel.\n", chname);
  1318. return;
  1319. }
  1320. sprintf(buf2, "down %s", chan->dname);
  1321. putallbots(buf2);
  1322. #ifdef LEAF
  1323. add_mode(chan, '-', 'o', botname);
  1324. chan->channel.no_op = (now + 10);
  1325. #endif /* LEAF */
  1326. }
  1327. static void cmd_pls_chan(struct userrec *u, int idx, char *par)
  1328. {
  1329. char *chname = NULL, result[1024] = "", buf[2048] = "";
  1330. struct chanset_t *chan = NULL;
  1331. putlog(LOG_CMDS, "*", "#%s# +chan %s", dcc[idx].nick, par);
  1332. if (!par[0]) {
  1333. dprintf(idx, "Usage: +chan [%s]<channel> [options]\n", CHANMETA);
  1334. return;
  1335. }
  1336. chname = newsplit(&par);
  1337. sprintf(buf, "cjoin %s %s", chname, par);
  1338. if (findchan_by_dname(chname)) {
  1339. putallbots(buf);
  1340. dprintf(idx, "That channel already exists!\n");
  1341. return;
  1342. } else if ((chan = findchan(chname))) {
  1343. putallbots(buf);
  1344. /* This prevents someone adding a channel by it's unique server
  1345. * name <cybah>
  1346. */
  1347. dprintf(idx, "That channel already exists as %s!\n", chan->dname);
  1348. return;
  1349. }
  1350. if (channel_add(result, chname, par) == ERROR) {
  1351. dprintf(idx, "Invalid channel or channel options.\n");
  1352. if (result && result[0])
  1353. dprintf(idx, "%s\n", result);
  1354. } else {
  1355. if ((chan = findchan_by_dname(chname))) {
  1356. char *tmp = NULL;
  1357. putallbots(buf);
  1358. tmp = calloc(1, 7 + 1 + strlen(dcc[idx].nick) + 1);
  1359. sprintf(tmp, "addedby %s", dcc[idx].nick);
  1360. do_chanset(NULL, chan, tmp, DO_LOCAL | DO_NET );
  1361. free(tmp);
  1362. tmp = calloc(1, 7 + 1 + 10 + 1);
  1363. sprintf(tmp, "addedts %lu", now);
  1364. do_chanset(NULL, chan, tmp, DO_LOCAL | DO_NET );
  1365. free(tmp);
  1366. }
  1367. #ifdef HUB
  1368. write_userfile(-1);
  1369. #endif /* HUB */
  1370. }
  1371. }
  1372. static void cmd_mns_chan(struct userrec *u, int idx, char *par)
  1373. {
  1374. char *chname = NULL, buf2[1024] = "";
  1375. struct chanset_t *chan = NULL;
  1376. int i;
  1377. putlog(LOG_CMDS, "*", "#%s# -chan %s", dcc[idx].nick, par);
  1378. if (!par[0]) {
  1379. dprintf(idx, "Usage: -chan [%s]<channel>\n", CHANMETA);
  1380. return;
  1381. }
  1382. chname = newsplit(&par);
  1383. sprintf(buf2, "cpart %s", chname);
  1384. putallbots(buf2);
  1385. chan = findchan_by_dname(chname);
  1386. if (!chan) {
  1387. if ((chan = findchan(chname)))
  1388. dprintf(idx, "That channel exists with a short name of %s, use that.\n",
  1389. chan->dname);
  1390. else
  1391. dprintf(idx, "That channel doesn't exist!\n");
  1392. return;
  1393. }
  1394. for (i = 0; i < dcc_total; i++)
  1395. if ((dcc[i].type->flags & DCT_CHAT) &&
  1396. !rfc_casecmp(dcc[i].u.chat->con_chan, chan->dname)) {
  1397. dprintf(i, "%s is no longer a valid channel, changing your console to '*'\n",
  1398. chname);
  1399. strcpy(dcc[i].u.chat->con_chan, "*");
  1400. }
  1401. remove_channel(chan);
  1402. #ifdef HUB
  1403. write_userfile(-1);
  1404. #endif /* HUB */
  1405. dprintf(idx, "Channel %s removed from the bot.\n", chname);
  1406. dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
  1407. }
  1408. /* thanks Excelsior */
  1409. #define FLAG_COLS 4
  1410. void show_flag(int idx, char *work, int *cnt, char *name, int state)
  1411. {
  1412. char tmp[101] = "", chr_state[15] = "";
  1413. /* empty buffer if no (char *) name */
  1414. if (((*cnt) < (FLAG_COLS - 1)) && (!name || (name && !name[0]))) (*cnt) = (FLAG_COLS - 1);
  1415. (*cnt)++;
  1416. if (*cnt > FLAG_COLS) {
  1417. *cnt = 1;
  1418. work[0] = 0;
  1419. }
  1420. if (!work[0])
  1421. sprintf(work, " ");
  1422. if (name && name[0]) {
  1423. chr_state[0] = 0;
  1424. if (state) {
  1425. strcat(chr_state, GREEN(idx));
  1426. strcat(chr_state, "+");
  1427. } else {
  1428. strcat(chr_state, RED(idx));
  1429. strcat(chr_state, "-");
  1430. }
  1431. strcat(chr_state, COLOR_END(idx));
  1432. egg_snprintf(tmp, sizeof tmp, "%s%-17s", chr_state, name);
  1433. strcat(work, tmp);
  1434. }
  1435. if (*cnt >= FLAG_COLS)
  1436. dprintf(idx, "%s\n", work);
  1437. }
  1438. #define INT_COLS 1
  1439. void show_int(int idx, char *work, int *cnt, char *desc, int state, char *yes, char *no)
  1440. {
  1441. char tmp[101] = "", chr_state[101] = "";
  1442. egg_snprintf(chr_state, sizeof chr_state, "%d", state);
  1443. /* empty buffer if no (char *) name */
  1444. if (((*cnt) < (INT_COLS - 1)) && (!desc || (desc && !desc[0]))) (*cnt) = (INT_COLS - 1);
  1445. (*cnt)++;
  1446. if (*cnt > INT_COLS) {
  1447. *cnt = 1;
  1448. work[0] = 0;
  1449. }
  1450. if (!work[0])
  1451. sprintf(work, " ");
  1452. /* need to make next line all one char, and then put it into %-30s */
  1453. if (desc && desc[0]) {
  1454. char tmp2[50] = "", tmp3[50] = "";
  1455. strcat(tmp2, BOLD(idx));
  1456. if (state && yes) {
  1457. strcat(tmp2, yes);
  1458. } else if (!state && no) {
  1459. strcat(tmp2, no);
  1460. strcat(tmp3, " (");
  1461. strcat(tmp3, chr_state);
  1462. strcat(tmp3, ")");
  1463. } else if ((state && !yes) || (!state && !no)) {
  1464. strcat(tmp2, chr_state);
  1465. }
  1466. strcat(tmp2, BOLD_END(idx));
  1467. egg_snprintf(tmp, sizeof tmp, "%-30s %-20s %s", desc, tmp2, (tmp3 && tmp3[0]) ? tmp3 : "");
  1468. strcat(work, tmp);
  1469. }
  1470. if (*cnt >= INT_COLS)
  1471. dprintf(idx, "%s\n", work);
  1472. }
  1473. #define SHOW_FLAG(name, state) show_flag(idx, work, &cnt, name, state)
  1474. #define SHOW_INT(desc, state, yes, no) show_int(idx, work, &cnt, desc, state, yes, no)
  1475. static void cmd_chaninfo(struct userrec *u, int idx, char *par)
  1476. {
  1477. char *chname = NULL, work[512] = "";
  1478. struct chanset_t *chan = NULL;
  1479. int ii, tmp, cnt = 0;
  1480. struct udef_struct *ul = NULL;
  1481. if (!par[0]) {
  1482. chname = dcc[idx].u.chat->con_chan;
  1483. if (chname[0] == '*') {
  1484. dprintf(idx, "Your console channel is invalid.\n");
  1485. return;
  1486. }
  1487. } else {
  1488. chname = newsplit(&par);
  1489. get_user_flagrec(u, &user, chname);
  1490. if (!glob_master(user) && !chan_master(user)) {
  1491. dprintf(idx, "You don't have access to %s.\n", chname);
  1492. return;
  1493. }
  1494. }
  1495. if (!(chan = findchan_by_dname(chname)))
  1496. dprintf(idx, "No such channel defined.\n");
  1497. else {
  1498. char nick[NICKLEN] = "", date[81] = "";
  1499. if (chan->added_ts) {
  1500. #ifndef S_UTCTIME
  1501. egg_strftime(date, sizeof date, "%c %Z", localtime(&(chan->added_ts)));
  1502. #else /* !S_UTCTIME */
  1503. egg_strftime(date, sizeof date, "%c %Z", gmtime(&(chan->added_ts)));
  1504. #endif /* S_UTCTIME */
  1505. } else
  1506. date[0] = 0;
  1507. if (chan->added_by && chan->added_by[0])
  1508. egg_snprintf(nick, sizeof nick, "%s", chan->added_by);
  1509. else
  1510. nick[0] = 0;
  1511. putlog(LOG_CMDS, "*", "#%s# chaninfo %s", dcc[idx].nick, chname);
  1512. if (nick[0] && date[0])
  1513. dprintf(idx, "Settings for channel %s (Added %s by %s%s%s):\n", chan->dname, date, BOLD(idx), nick, BOLD_END(idx));
  1514. else
  1515. dprintf(idx, "Settings for channel %s:\n", chan->dname);
  1516. /* FIXME: SHOW_CHAR() here */
  1517. get_mode_protect(chan, work);
  1518. dprintf(idx, "Protect modes (chanmode): %s\n", work[0] ? work : "None");
  1519. /* Chanchar template
  1520. * dprintf(idx, "String temp: %s\n", chan->temp[0] ? chan->temp : "NULL");
  1521. */
  1522. dprintf(idx, "Channel flags:\n");
  1523. work[0] = 0;
  1524. SHOW_FLAG("bitch", channel_bitch(chan));
  1525. SHOW_FLAG("closed", channel_closed(chan));
  1526. SHOW_FLAG("cycle", channel_cycle(chan));
  1527. SHOW_FLAG("enforcebans", channel_enforcebans(chan));
  1528. SHOW_FLAG("fastop", channel_fastop(chan));
  1529. SHOW_FLAG("inactive", channel_inactive(chan));
  1530. SHOW_FLAG("manop", channel_manop(chan));
  1531. SHOW_FLAG("nodesynch", channel_nodesynch(chan));
  1532. SHOW_FLAG("nomop", channel_nomop(chan));
  1533. SHOW_FLAG("private", channel_private(chan));
  1534. SHOW_FLAG("protectops", channel_protectops(chan));
  1535. SHOW_FLAG("revenge", channel_revenge(chan));
  1536. SHOW_FLAG("revengebot", channel_revengebot(chan));
  1537. SHOW_FLAG("take", channel_take(chan));
  1538. SHOW_FLAG("voice", channel_voice(chan));
  1539. SHOW_FLAG("", 0);
  1540. SHOW_FLAG("dynamicbans", channel_dynamicbans(chan));
  1541. SHOW_FLAG("userbans", !channel_nouserbans(chan));
  1542. SHOW_FLAG("dynamicexempts", channel_dynamicexempts(chan));
  1543. SHOW_FLAG("userexempts", !channel_nouserexempts(chan));
  1544. SHOW_FLAG("dynamicinvites", channel_dynamicinvites(chan));
  1545. SHOW_FLAG("userinvites", !channel_nouserinvites(chan));
  1546. SHOW_FLAG("", 0);
  1547. work[0] = 0;
  1548. /* Chanflag template
  1549. * (chan->status & CHAN_TEMP) ? '+' : '-',
  1550. * also include %ctemp in dprintf.
  1551. */
  1552. ii = 1;
  1553. tmp = 0;
  1554. for (ul = udef; ul; ul = ul->next)
  1555. if (ul->defined && ul->type == UDEF_FLAG) {
  1556. int work_len;
  1557. if (!tmp) {
  1558. dprintf(idx, "User defined channel flags:\n");
  1559. tmp = 1;
  1560. }
  1561. if (ii == 1)
  1562. egg_snprintf(work, sizeof work, " ");
  1563. work_len = strlen(work);
  1564. egg_snprintf(work + work_len, sizeof(work) - work_len, " %c%s",
  1565. getudef(ul->values, chan->dname) ? '+' : '-', ul->name);
  1566. ii++;
  1567. if (ii > 4) {
  1568. dprintf(idx, "%s\n", work);
  1569. ii = 1;
  1570. }
  1571. }
  1572. if (ii > 1)
  1573. dprintf(idx, "%s\n", work);
  1574. work[0] = 0;
  1575. ii = 1;
  1576. tmp = 0;
  1577. for (ul = udef; ul; ul = ul->next)
  1578. if (ul->defined && ul->type == UDEF_INT) {
  1579. int work_len = strlen(work);
  1580. if (!tmp) {
  1581. dprintf(idx, "User defined channel settings:\n");
  1582. tmp = 1;
  1583. }
  1584. egg_snprintf(work + work_len, sizeof(work) - work_len, "%s: %d ",
  1585. ul->name, getudef(ul->values, chan->dname));
  1586. ii++;
  1587. if (ii > 4) {
  1588. dprintf(idx, "%s\n", work);
  1589. work[0] = 0;
  1590. ii = 1;
  1591. }
  1592. }
  1593. if (ii > 1)
  1594. dprintf(idx, "%s\n", work);
  1595. work[0] = cnt = 0;
  1596. /* Chanint template
  1597. * SHOW_INT("Desc: ", integer, "YES", "NO");
  1598. */
  1599. dprintf(idx, "Channel settings:\n");
  1600. SHOW_INT("Ban-time: ", chan->ban_time, NULL, "Forever");
  1601. SHOW_INT("Closed-ban: ", chan->closed_ban, NULL, "Don't!");
  1602. SHOW_INT("Exempt-time: ", chan->exempt_time, NULL, "Forever");
  1603. SHOW_INT("Idle Kick after (idle-kick): ", chan->idle_kick, "", "Don't!");
  1604. SHOW_INT("Invite-time: ", chan->invite_time, NULL, "Forever");
  1605. SHOW_INT("Limit raise (limit): ", chan->limitraise, NULL, "Disabled");
  1606. SHOW_INT("Revenge-mode: ", chan->revenge_mode, NULL, NULL);
  1607. SHOW_INT("Stopnethack-mode: ", chan->stopnethack_mode, "", "Don't!");
  1608. dprintf(idx, "Flood settings: chan ctcp join kick deop nick\n");
  1609. dprintf(idx, " number: %3d %3d %3d %3d %3d %3d\n",
  1610. chan->flood_pub_thr, chan->flood_ctcp_thr,
  1611. chan->flood_join_thr, chan->flood_kick_thr,
  1612. chan->flood_deop_thr, chan->flood_nick_thr);
  1613. dprintf(idx, " time : %3d %3d %3d %3d %3d %3d\n",
  1614. chan->flood_pub_time, chan->flood_ctcp_time,
  1615. chan->flood_join_time, chan->flood_kick_time,
  1616. chan->flood_deop_time, chan->flood_nick_time);
  1617. }
  1618. }
  1619. static void cmd_chanset(struct userrec *u, int idx, char *par)
  1620. {
  1621. char *chname = NULL, result[1024] = "";
  1622. struct chanset_t *chan = NULL;
  1623. int all = 0;
  1624. putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
  1625. if (!par[0]) {
  1626. dprintf(idx, "Usage: chanset [%schannel|*] <settings>\n", CHANMETA);
  1627. return;
  1628. }
  1629. if (strlen(par) > 2 && par[0] == '*' && par[1] == ' ') {
  1630. all = 1;
  1631. get_user_flagrec(u, &user, chanset ? chanset->dname : "");
  1632. if (!glob_master(user)) {
  1633. dprintf(idx, "You need to be a global master to use %schanset *.\n", dcc_prefix);
  1634. return;
  1635. }
  1636. newsplit(&par);
  1637. } else {
  1638. if (strchr(CHANMETA, par[0])) {
  1639. chname = newsplit(&par);
  1640. get_user_flagrec(u, &user, chname);
  1641. if (!glob_master(user) && !chan_master(user)) {
  1642. dprintf(idx, "You don't have access to %s. \n", chname);
  1643. return;
  1644. } else if (!(chan = findchan_by_dname(chname)) && (chname[0] != '+')) {
  1645. dprintf(idx, "That channel doesn't exist!\n");
  1646. return;
  1647. } else if ((strstr(par, "+private") || strstr(par, "-private")) && (!glob_owner(user))) {
  1648. dprintf(idx, "You don't have access to set +/-private on %s (halting command due to lazy coder).\n", chname);
  1649. return;
  1650. } else if ((strstr(par, "+inactive") || strstr(par, "-inactive")) && (!glob_owner(user))) {
  1651. dprintf(idx, "You don't have access to set +/-inactive on %s (halting command due to lazy coder).\n", chname);
  1652. return;
  1653. }
  1654. if (!chan) {
  1655. if (par[0])
  1656. *--par = ' ';
  1657. par = chname;
  1658. }
  1659. }
  1660. if (!par[0] || par[0] == '*') {
  1661. dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
  1662. return;
  1663. }
  1664. if (!chan && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
  1665. dprintf(idx, "Invalid console channel.\n");
  1666. return;
  1667. }
  1668. }
  1669. if (do_chanset(result, all ? NULL : chan, par, DO_LOCAL | DO_NET) == ERROR) {
  1670. dprintf(idx, "Error trying to set { %s } on %s: %s\n", par, all ? "all channels" : chan->dname, result);
  1671. return;
  1672. }
  1673. if (all)
  1674. dprintf(idx, "Successfully set modes { %s } on all channels.\n", par);
  1675. else
  1676. dprintf(idx, "Successfully set modes { %s } on %s\n", par, chan->dname);
  1677. #ifdef HUB
  1678. write_userfile(idx);
  1679. #endif /* HUB */
  1680. }
  1681. /* DCC CHAT COMMANDS
  1682. *
  1683. * Function call should be:
  1684. * int cmd_whatever(idx,"parameters");
  1685. *
  1686. * NOTE: As with msg commands, the function is responsible for any logging.
  1687. */
  1688. static cmd_t C_dcc_irc[] =
  1689. {
  1690. {"+ban", "o|o", (Function) cmd_pls_ban, NULL},
  1691. {"+exempt", "o|o", (Function) cmd_pls_exempt, NULL},
  1692. {"+invite", "o|o", (Function) cmd_pls_invite, NULL},
  1693. {"+chan", "n", (Function) cmd_pls_chan, NULL},
  1694. {"+chrec", "m|m", (Function) cmd_pls_chrec, NULL},
  1695. {"-ban", "o|o", (Function) cmd_mns_ban, NULL},
  1696. {"-chan", "n", (Function) cmd_mns_chan, NULL},
  1697. {"-chrec", "m|m", (Function) cmd_mns_chrec, NULL},
  1698. {"-exempt", "o|o", (Function) cmd_mns_exempt, NULL},
  1699. {"-invite", "o|o", (Function) cmd_mns_invite, NULL},
  1700. {"bans", "o|o", (Function) cmd_bans, NULL},
  1701. {"exempts", "o|o", (Function) cmd_exempts, NULL},
  1702. {"invites", "o|o", (Function) cmd_invites, NULL},
  1703. {"chaninfo", "m|m", (Function) cmd_chaninfo, NULL},
  1704. {"chanset", "m|m", (Function) cmd_chanset, NULL},
  1705. {"chinfo", "m|m", (Function) cmd_chinfo, NULL},
  1706. {"cycle", "n|n", (Function) cmd_cycle, NULL},
  1707. {"down", "n|n", (Function) cmd_down, NULL},
  1708. {"info", "", (Function) cmd_info, NULL},
  1709. {"slowjoin", "n", (Function) cmd_slowjoin, NULL},
  1710. {"slowpart", "n|n", (Function) cmd_slowpart, NULL},
  1711. {"stick", "o|o", (Function) cmd_stick, NULL},
  1712. {"unstick", "o|o", (Function) cmd_unstick, NULL},
  1713. {NULL, NULL, NULL, NULL}
  1714. };