flags.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /*
  2. * flags.c -- handles:
  3. * all the flag matching/conversion functions in one neat package :)
  4. *
  5. */
  6. #include "main.h"
  7. extern int use_console_r, debug_output, noshare,
  8. allow_dk_cmds;
  9. extern struct dcc_t *dcc;
  10. int use_console_r = 1; /* Allow users to set their console +r */
  11. int logmodes(char *s)
  12. {
  13. int i;
  14. int res = 0;
  15. for (i = 0; i < strlen(s); i++)
  16. switch (s[i]) {
  17. case 'm':
  18. case 'M':
  19. res |= LOG_MSGS;
  20. break;
  21. case 'p':
  22. case 'P':
  23. res |= LOG_PUBLIC;
  24. break;
  25. case 'j':
  26. case 'J':
  27. res |= LOG_JOIN;
  28. break;
  29. case 'k':
  30. case 'K':
  31. res |= LOG_MODES;
  32. break;
  33. case 'c':
  34. case 'C':
  35. res |= LOG_CMDS;
  36. break;
  37. case 'o':
  38. case 'O':
  39. res |= LOG_MISC;
  40. break;
  41. case 'b':
  42. case 'B':
  43. res |= LOG_BOTS;
  44. break;
  45. case 'r':
  46. case 'R':
  47. res |= use_console_r ? LOG_RAW : 0;
  48. break;
  49. case 'w':
  50. case 'W':
  51. res |= LOG_WALL;
  52. break;
  53. case 'x':
  54. case 'X':
  55. res |= LOG_FILES;
  56. break;
  57. case 's':
  58. case 'S':
  59. res |= LOG_SERV;
  60. break;
  61. case 'd':
  62. case 'D':
  63. res |= LOG_DEBUG;
  64. break;
  65. case 'v':
  66. case 'V':
  67. res |= debug_output ? LOG_SRVOUT : 0;
  68. break;
  69. case 't':
  70. case 'T':
  71. res |= debug_output ? LOG_BOTNET : 0;
  72. break;
  73. case 'h':
  74. case 'H':
  75. res |= debug_output ? LOG_BOTSHARE : 0;
  76. break;
  77. case 'e':
  78. case 'E':
  79. res |= LOG_ERRORS;
  80. break;
  81. case 'g':
  82. case 'G':
  83. res |= LOG_GETIN;
  84. break;
  85. case 'u':
  86. case 'U':
  87. res |= LOG_WARN;
  88. break;
  89. case '*':
  90. res |= LOG_ALL;
  91. break;
  92. }
  93. return res;
  94. }
  95. char *masktype(int x)
  96. {
  97. static char s[24]; /* Change this if you change the levels */
  98. char *p = s;
  99. if (x & LOG_MSGS)
  100. *p++ = 'm';
  101. if (x & LOG_PUBLIC)
  102. *p++ = 'p';
  103. if (x & LOG_JOIN)
  104. *p++ = 'j';
  105. if (x & LOG_MODES)
  106. *p++ = 'k';
  107. if (x & LOG_CMDS)
  108. *p++ = 'c';
  109. if (x & LOG_MISC)
  110. *p++ = 'o';
  111. if (x & LOG_BOTS)
  112. *p++ = 'b';
  113. if ((x & LOG_RAW) && use_console_r)
  114. *p++ = 'r';
  115. if (x & LOG_FILES)
  116. *p++ = 'x';
  117. if (x & LOG_SERV)
  118. *p++ = 's';
  119. if (x & LOG_DEBUG)
  120. *p++ = 'd';
  121. if (x & LOG_WALL)
  122. *p++ = 'w';
  123. if ((x & LOG_SRVOUT) && debug_output)
  124. *p++ = 'v';
  125. if ((x & LOG_BOTNET) && debug_output)
  126. *p++ = 't';
  127. if ((x & LOG_BOTSHARE) && debug_output)
  128. *p++ = 'h';
  129. if (x & LOG_ERRORS)
  130. *p++ = 'e';
  131. if (x & LOG_GETIN)
  132. *p++ = 'g';
  133. if (x & LOG_WARN)
  134. *p++ = 'u';
  135. if (p == s)
  136. *p++ = '-';
  137. *p = 0;
  138. return s;
  139. }
  140. char *maskname(int x)
  141. {
  142. static char s[207]; /* Change this if you change the levels */
  143. int i = 0;
  144. s[0] = 0;
  145. if (x & LOG_MSGS)
  146. i += my_strcpy(s, "msgs, ");
  147. if (x & LOG_PUBLIC)
  148. i += my_strcpy(s + i, "public, ");
  149. if (x & LOG_JOIN)
  150. i += my_strcpy(s + i, "joins, ");
  151. if (x & LOG_MODES)
  152. i += my_strcpy(s + i, "kicks/modes, ");
  153. if (x & LOG_CMDS)
  154. i += my_strcpy(s + i, "cmds, ");
  155. if (x & LOG_MISC)
  156. i += my_strcpy(s + i, "misc, ");
  157. if (x & LOG_BOTS)
  158. i += my_strcpy(s + i, "bots, ");
  159. if ((x & LOG_RAW) && use_console_r)
  160. i += my_strcpy(s + i, "raw, ");
  161. if (x & LOG_FILES)
  162. i += my_strcpy(s + i, "files, ");
  163. if (x & LOG_SERV)
  164. i += my_strcpy(s + i, "server, ");
  165. if (x & LOG_DEBUG)
  166. i += my_strcpy(s + i, "debug, ");
  167. if (x & LOG_WALL)
  168. i += my_strcpy(s + i, "wallops, ");
  169. if ((x & LOG_SRVOUT) && debug_output)
  170. i += my_strcpy(s + i, "server output, ");
  171. if ((x & LOG_BOTNET) && debug_output)
  172. i += my_strcpy(s + i, "botnet traffic, ");
  173. if ((x & LOG_BOTSHARE) && debug_output)
  174. i += my_strcpy(s + i, "share traffic, ");
  175. if (x & LOG_ERRORS)
  176. i += my_strcpy(s + i, "errors, ");
  177. if (x & LOG_GETIN)
  178. i += my_strcpy(s + i, "getin, ");
  179. if (x & LOG_WARN)
  180. i += my_strcpy(s + i, "warnings, ");
  181. if (i)
  182. s[i - 2] = 0;
  183. else
  184. strcpy(s, "none");
  185. return s;
  186. }
  187. /* Some flags are mutually exclusive -- this roots them out
  188. */
  189. int sanity_check(int atr)
  190. {
  191. /* bots shouldnt have +pmcnaijlys */
  192. if ((atr & USER_BOT) &&
  193. (atr & (USER_PARTY | USER_MASTER | USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA)))
  194. atr &= ~(USER_PARTY | USER_MASTER | USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
  195. // only bots should be there:
  196. if (!(atr & USER_BOT) &&
  197. (atr & (USER_DOLIMIT | USER_DOVOICE | USER_UPDATEHUB | USER_CHANHUB)))
  198. atr &= ~(USER_DOLIMIT | USER_DOVOICE | USER_UPDATEHUB | USER_CHANHUB);
  199. if ((atr & USER_OP) && (atr & USER_DEOP))
  200. atr &= ~(USER_OP | USER_DEOP);
  201. if ((atr & USER_VOICE) && (atr & USER_QUIET))
  202. atr &= ~(USER_VOICE | USER_QUIET);
  203. /* Can't be admin without also being owner and having hub access */
  204. if (atr & USER_ADMIN)
  205. atr |= USER_OWNER | USER_HUBA | USER_PARTY;
  206. /* Hub access gets chanhub access */
  207. if (atr & USER_HUBA)
  208. atr |= USER_CHUBA;
  209. if (atr & USER_OWNER) {
  210. atr |= USER_MASTER;
  211. }
  212. /* Master implies botmaster, op */
  213. if (atr & USER_MASTER)
  214. atr |= USER_OP | USER_CHUBA;
  215. /* Can't be botnet master without party-line access */
  216. /* if (atr & USER_BOTMAST)
  217. atr |= USER_PARTY;
  218. */
  219. return atr;
  220. }
  221. /* Sanity check on channel attributes
  222. */
  223. int chan_sanity_check(int chatr, int atr)
  224. {
  225. if ((chatr & USER_OP) && (chatr & USER_DEOP))
  226. chatr &= ~(USER_OP | USER_DEOP);
  227. if ((chatr & USER_VOICE) && (chatr & USER_QUIET))
  228. chatr &= ~(USER_VOICE | USER_QUIET);
  229. /* Can't be channel owner without also being channel master */
  230. if (chatr & USER_OWNER)
  231. chatr |= USER_MASTER;
  232. /* Master implies op */
  233. if (chatr & USER_MASTER)
  234. chatr |= USER_OP ;
  235. /* Can't be +s on chan unless you're a bot */
  236. if (!(atr & USER_BOT))
  237. chatr &= ~BOT_SHARE;
  238. return chatr;
  239. }
  240. /* Get icon symbol for a user (depending on access level)
  241. *
  242. * (*) owner on any channel
  243. * (+) master on any channel
  244. * (%) botnet master
  245. * (@) op on any channel
  246. * (-) other
  247. */
  248. char geticon(int idx)
  249. {
  250. struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  251. if (!dcc[idx].user)
  252. return '-';
  253. get_user_flagrec(dcc[idx].user, &fr, 0);
  254. if (glob_admin(fr))
  255. return '^';
  256. if (chan_owner(fr))
  257. return '*';
  258. if (chan_master(fr))
  259. return '+';
  260. if (chan_op(fr))
  261. return '@';
  262. return '-';
  263. }
  264. void break_down_flags(const char *string, struct flag_record *plus,
  265. struct flag_record *minus)
  266. {
  267. struct flag_record *which = plus;
  268. int mode = 0; /* 0 = glob, 1 = chan, 2 = bot */
  269. int flags = plus->match;
  270. if (!(flags & FR_GLOBAL)) {
  271. if (flags & FR_BOT)
  272. mode = 2;
  273. else if (flags & FR_CHAN)
  274. mode = 1;
  275. else
  276. return; /* We dont actually want any..huh? */
  277. }
  278. egg_bzero(plus, sizeof(struct flag_record));
  279. if (minus)
  280. egg_bzero(minus, sizeof(struct flag_record));
  281. plus->match = FR_OR; /* Default binding type OR */
  282. while (*string) {
  283. switch (*string) {
  284. case '+':
  285. which = plus;
  286. break;
  287. case '-':
  288. which = minus ? minus : plus;
  289. break;
  290. case '|':
  291. case '&':
  292. if (!mode) {
  293. if (*string == '|')
  294. plus->match = FR_OR;
  295. else
  296. plus->match = FR_AND;
  297. }
  298. which = plus;
  299. mode++;
  300. if ((mode == 2) && !(flags & (FR_CHAN | FR_BOT)))
  301. string = "";
  302. else if (mode == 3)
  303. mode = 1;
  304. break;
  305. default:
  306. if ((*string >= 'a') && (*string <= 'z')) {
  307. switch (mode) {
  308. case 0:
  309. which->global |=1 << (*string - 'a');
  310. break;
  311. case 1:
  312. which->chan |= 1 << (*string - 'a');
  313. break;
  314. case 2:
  315. which->bot |= 1 << (*string - 'a');
  316. }
  317. } else if ((*string >= 'A') && (*string <= 'Z')) {
  318. switch (mode) {
  319. case 0:
  320. which->udef_global |= 1 << (*string - 'A');
  321. break;
  322. case 1:
  323. which->udef_chan |= 1 << (*string - 'A');
  324. break;
  325. }
  326. } else if ((*string >= '0') && (*string <= '9')) {
  327. switch (mode) {
  328. /* Map 0->9 to A->K for glob/chan so they are not lost */
  329. case 0:
  330. which->udef_global |= 1 << (*string - '0');
  331. break;
  332. case 1:
  333. which->udef_chan |= 1 << (*string - '0');
  334. break;
  335. case 2:
  336. which->bot |= BOT_FLAG0 << (*string - '0');
  337. break;
  338. }
  339. }
  340. }
  341. string++;
  342. }
  343. for (which = plus; which; which = (which == plus ? minus : 0)) {
  344. which->global &=USER_VALID;
  345. which->udef_global &= 0x03ffffff;
  346. which->chan &= CHAN_VALID;
  347. which->udef_chan &= 0x03ffffff;
  348. which->bot &= BOT_VALID;
  349. }
  350. plus->match |= flags;
  351. if (minus) {
  352. minus->match |= flags;
  353. if (!(plus->match & (FR_AND | FR_OR)))
  354. plus->match |= FR_OR;
  355. }
  356. }
  357. static int flag2str(char *string, int bot, int udef)
  358. {
  359. char x = 'a', *old = string;
  360. while (bot && (x <= 'z')) {
  361. if (bot & 1)
  362. *string++ = x;
  363. x++;
  364. bot = bot >> 1;
  365. }
  366. x = 'A';
  367. while (udef && (x <= 'Z')) {
  368. if (udef & 1)
  369. *string++ = x;
  370. udef = udef >> 1;
  371. x++;
  372. }
  373. if (string == old)
  374. *string++ = '-';
  375. return string - old;
  376. }
  377. static int bot2str(char *string, int bot)
  378. {
  379. char x = 'a', *old = string;
  380. while (x < 'v') {
  381. if (bot & 1)
  382. *string++ = x;
  383. x++;
  384. bot >>= 1;
  385. }
  386. x = '0';
  387. while (x <= '9') {
  388. if (bot & 1)
  389. *string++ = x;
  390. x++;
  391. bot >>= 1;
  392. }
  393. return string - old;
  394. }
  395. int build_flags(char *string, struct flag_record *plus,
  396. struct flag_record *minus)
  397. {
  398. char *old = string;
  399. if (plus->match & FR_GLOBAL) {
  400. if (minus && (plus->global || plus->udef_global))
  401. *string++ = '+';
  402. string += flag2str(string, plus->global, plus->udef_global);
  403. if (minus && (minus->global || minus->udef_global)) {
  404. *string++ = '-';
  405. string += flag2str(string, minus->global, minus->udef_global);
  406. }
  407. } else if (plus->match & FR_BOT) {
  408. if (minus && plus->bot)
  409. *string++ = '+';
  410. string += bot2str(string, plus->bot);
  411. if (minus && minus->bot) {
  412. *string++ = '-';
  413. string += bot2str(string, minus->bot);
  414. }
  415. }
  416. if (plus->match & FR_CHAN) {
  417. if (plus->match & (FR_GLOBAL | FR_BOT))
  418. *string++ = (plus->match & FR_AND) ? '&' : '|';
  419. if (minus && (plus->chan || plus->udef_chan))
  420. *string++ = '+';
  421. string += flag2str(string, plus->chan, plus->udef_chan);
  422. if (minus && (minus->chan || minus->udef_chan)) {
  423. *string++ = '-';
  424. string += flag2str(string, minus->global, minus->udef_chan);
  425. }
  426. }
  427. if ((plus->match & (FR_BOT | FR_CHAN)) == (FR_BOT | FR_CHAN)) {
  428. *string++ = (plus->match & FR_AND) ? '&' : '|';
  429. if (minus && plus->bot)
  430. *string++ = '+';
  431. string += bot2str(string, plus->bot);
  432. if (minus && minus->bot) {
  433. *string++ = '-';
  434. string += bot2str(string, minus->bot);
  435. }
  436. }
  437. if (string == old) {
  438. *string++ = '-';
  439. *string = 0;
  440. return 0;
  441. }
  442. *string = 0;
  443. return string - old;
  444. }
  445. int flagrec_ok(struct flag_record *req,
  446. struct flag_record *have)
  447. {
  448. if (req->match & FR_AND) {
  449. return flagrec_eq(req, have);
  450. } else if (req->match & FR_OR) {
  451. int hav = have->global;
  452. /* Exception 1 - global +d/+k cant use -|-, unless they are +p */
  453. if (!req->chan && !req->global && !req->udef_global &&
  454. !req->udef_chan) {
  455. if (!allow_dk_cmds) {
  456. if (glob_party(*have))
  457. return 1;
  458. if (glob_kick(*have) || chan_kick(*have))
  459. return 0; /* +k cant use -|- commands */
  460. if (glob_deop(*have) || chan_deop(*have))
  461. return 0; /* neither can +d's */
  462. }
  463. return 1;
  464. }
  465. /* The +n/+m checks arent needed anymore since +n/+m
  466. * automatically add lower flags
  467. */
  468. /* if (!1 && ((hav & USER_OP) || (have->chan & USER_OWNER)))
  469. hav |= USER_PARTY;*/
  470. if (hav & req->global)
  471. return 1;
  472. if (have->chan & req->chan)
  473. return 1;
  474. if (have->udef_global & req->udef_global)
  475. return 1;
  476. if (have->udef_chan & req->udef_chan)
  477. return 1;
  478. return 0;
  479. }
  480. return 0; /* fr0k3 binding, dont pass it */
  481. }
  482. int flagrec_eq(struct flag_record *req, struct flag_record *have)
  483. {
  484. if (req->match & FR_AND) {
  485. if (req->match & FR_GLOBAL) {
  486. if ((req->global &have->global) !=req->global)
  487. return 0;
  488. if ((req->udef_global & have->udef_global) != req->udef_global)
  489. return 0;
  490. }
  491. if (req->match & FR_BOT)
  492. if ((req->bot & have->bot) != req->bot)
  493. return 0;
  494. if (req->match & FR_CHAN) {
  495. if ((req->chan & have->chan) != req->chan)
  496. return 0;
  497. if ((req->udef_chan & have->udef_chan) != req->udef_chan)
  498. return 0;
  499. }
  500. return 1;
  501. } else if (req->match & FR_OR) {
  502. if (!req->chan && !req->global && !req->udef_chan &&
  503. !req->udef_global && !req->bot)
  504. return 1;
  505. if (req->match & FR_GLOBAL) {
  506. if (have->global &req->global)
  507. return 1;
  508. if (have->udef_global & req->udef_global)
  509. return 1;
  510. }
  511. if (req->match & FR_BOT)
  512. if (have->bot & req->bot)
  513. return 1;
  514. if (req->match & FR_CHAN) {
  515. if (have->chan & req->chan)
  516. return 1;
  517. if (have->udef_chan & req->udef_chan)
  518. return 1;
  519. }
  520. return 0;
  521. }
  522. return 0; /* fr0k3 binding, dont pass it */
  523. }
  524. void set_user_flagrec(struct userrec *u, struct flag_record *fr,
  525. const char *chname)
  526. {
  527. struct chanuserrec *cr = NULL;
  528. int oldflags = fr->match;
  529. char buffer[100];
  530. struct chanset_t *ch;
  531. if (!u)
  532. return;
  533. if (oldflags & FR_GLOBAL) {
  534. u->flags = fr->global;
  535. u->flags_udef = fr->udef_global;
  536. if (!noshare && !(u->flags & USER_UNSHARED)) {
  537. fr->match = FR_GLOBAL;
  538. build_flags(buffer, fr, NULL);
  539. shareout(NULL, "a %s %s\n", u->handle, buffer);
  540. }
  541. }
  542. if ((oldflags & FR_BOT) && (u->flags & USER_BOT))
  543. set_user(&USERENTRY_BOTFL, u, (void *) fr->bot);
  544. /* Don't share bot attrs */
  545. if ((oldflags & FR_CHAN) && chname) {
  546. for (cr = u->chanrec; cr; cr = cr->next)
  547. if (!rfc_casecmp(chname, cr->channel))
  548. break;
  549. ch = findchan_by_dname(chname);
  550. if (!cr && ch) {
  551. cr = user_malloc(sizeof(struct chanuserrec));
  552. egg_bzero(cr, sizeof(struct chanuserrec));
  553. cr->next = u->chanrec;
  554. u->chanrec = cr;
  555. strncpyz(cr->channel, chname, sizeof cr->channel);
  556. }
  557. if (cr && ch) {
  558. cr->flags = fr->chan;
  559. cr->flags_udef = fr->udef_chan;
  560. if (!noshare && !(u->flags & USER_UNSHARED) && channel_shared(ch)) {
  561. fr->match = FR_CHAN;
  562. build_flags(buffer, fr, NULL);
  563. shareout(ch, "a %s %s %s\n", u->handle, buffer, chname);
  564. }
  565. }
  566. }
  567. fr->match = oldflags;
  568. }
  569. /* Always pass the dname (display name) to this function for chname <cybah>
  570. */
  571. void get_user_flagrec(struct userrec *u, struct flag_record *fr,
  572. const char *chname)
  573. {
  574. struct chanuserrec *cr = NULL;
  575. if (!u) {
  576. fr->global = fr->udef_global = fr->chan = fr->udef_chan = fr->bot = 0;
  577. return;
  578. }
  579. if (fr->match & FR_GLOBAL) {
  580. fr->global = u->flags;
  581. fr->udef_global = u->flags_udef;
  582. } else {
  583. fr->global = 0;
  584. fr->udef_global = 0;
  585. }
  586. if (fr->match & FR_BOT) {
  587. fr->bot = (long) get_user(&USERENTRY_BOTFL, u);
  588. } else
  589. fr->bot = 0;
  590. if (fr->match & FR_CHAN) {
  591. if (fr->match & FR_ANYWH) {
  592. fr->chan = u->flags;
  593. fr->udef_chan = u->flags_udef;
  594. for (cr = u->chanrec; cr; cr = cr->next)
  595. if (findchan_by_dname(cr->channel)) {
  596. fr->chan |= cr->flags;
  597. fr->udef_chan |= cr->flags_udef;
  598. }
  599. } else {
  600. if (chname)
  601. for (cr = u->chanrec; cr; cr = cr->next)
  602. if (!rfc_casecmp(chname, cr->channel))
  603. break;
  604. if (cr) {
  605. fr->chan = cr->flags;
  606. fr->udef_chan = cr->flags_udef;
  607. } else {
  608. fr->chan = 0;
  609. fr->udef_chan = 0;
  610. }
  611. }
  612. }
  613. }
  614. static int botfl_unpack(struct userrec *u, struct user_entry *e)
  615. {
  616. struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
  617. break_down_flags(e->u.list->extra, &fr, NULL);
  618. list_type_kill(e->u.list);
  619. e->u.ulong = fr.bot;
  620. return 1;
  621. }
  622. static int botfl_pack(struct userrec *u, struct user_entry *e)
  623. {
  624. char x[100];
  625. struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
  626. fr.bot = e->u.ulong;
  627. e->u.list = user_malloc(sizeof(struct list_type));
  628. e->u.list->next = NULL;
  629. e->u.list->extra = user_malloc (build_flags (x, &fr, NULL) + 1);
  630. strcpy(e->u.list->extra, x);
  631. return 1;
  632. }
  633. static int botfl_kill(struct user_entry *e)
  634. {
  635. nfree(e);
  636. return 1;
  637. }
  638. static int botfl_write_userfile(FILE *f, struct userrec *u,
  639. struct user_entry *e)
  640. {
  641. char x[100];
  642. struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
  643. fr.bot = e->u.ulong;
  644. build_flags(x, &fr, NULL);
  645. if (lfprintf(f, "--%s %s\n", e->type->name, x) == EOF)
  646. return 0;
  647. return 1;
  648. }
  649. static int botfl_set(struct userrec *u, struct user_entry *e, void *buf)
  650. {
  651. register long atr = ((long) buf & BOT_VALID);
  652. if (!(u->flags & USER_BOT))
  653. return 1; /* Don't even bother trying to set the
  654. flags for a non-bot */
  655. /* if ((atr & BOT_HUB) && (atr & BOT_ALT))
  656. atr &= ~BOT_ALT;*/
  657. if (atr & BOT_REJECT) {
  658. if (atr & BOT_SHARE)
  659. atr &= ~(BOT_SHARE | BOT_REJECT);
  660. if (atr & BOT_HUB)
  661. atr &= ~(BOT_HUB | BOT_REJECT);
  662. /* if (atr & BOT_ALT)
  663. atr &= ~(BOT_ALT | BOT_REJECT);*/
  664. }
  665. if (!(atr & BOT_SHARE))
  666. atr &= ~BOT_GLOBAL;
  667. e->u.ulong = atr;
  668. return 1;
  669. }
  670. static int botfl_tcl_get(Tcl_Interp *interp, struct userrec *u,
  671. struct user_entry *e, int argc, char **argv)
  672. {
  673. char x[100];
  674. struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
  675. fr.bot = e->u.ulong;
  676. build_flags(x, &fr, NULL);
  677. Tcl_AppendResult(interp, x, NULL);
  678. return TCL_OK;
  679. }
  680. static int botfl_tcl_set(Tcl_Interp *irp, struct userrec *u,
  681. struct user_entry *e, int argc, char **argv)
  682. {
  683. struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
  684. BADARGS(4, 4, " handle BOTFL flags");
  685. if (u->flags & USER_BOT) {
  686. /* Silently ignore for users */
  687. break_down_flags(argv[3], &fr, NULL);
  688. botfl_set(u, e, (void *) fr.bot);
  689. }
  690. return TCL_OK;
  691. }
  692. static int botfl_expmem(struct user_entry *e)
  693. {
  694. return 0;
  695. }
  696. static void botfl_display(int idx, struct user_entry *e, struct userrec *u)
  697. {
  698. struct flag_record fr = {FR_BOT, 0, 0, 0, 0, 0};
  699. char x[100];
  700. fr.bot = e->u.ulong;
  701. build_flags(x, &fr, NULL);
  702. dprintf(idx, " BOT FLAGS: %s\n", x);
  703. }
  704. struct user_entry_type USERENTRY_BOTFL =
  705. {
  706. 0, /* always 0 ;) */
  707. 0,
  708. def_dupuser,
  709. botfl_unpack,
  710. botfl_pack,
  711. botfl_write_userfile,
  712. botfl_kill,
  713. def_get,
  714. botfl_set,
  715. botfl_tcl_get,
  716. botfl_tcl_set,
  717. botfl_expmem,
  718. botfl_display,
  719. "BOTFL"
  720. };