users.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * users.h
  3. * structures and definitions used by users.c and userrec.c
  4. *
  5. */
  6. #ifndef _EGG_USERS_H
  7. #define _EGG_USERS_H
  8. /* List functions :) , next *must* be the 1st item in the struct */
  9. struct list_type {
  10. struct list_type *next;
  11. char *extra;
  12. };
  13. #define list_insert(a,b) { \
  14. (b)->next = *(a); \
  15. *(a) = (b); \
  16. }
  17. int list_append(struct list_type **, struct list_type *);
  18. int list_delete(struct list_type **, struct list_type *);
  19. int list_contains(struct list_type *, struct list_type *);
  20. /* New userfile format stuff
  21. */
  22. struct userrec;
  23. struct user_entry;
  24. struct user_entry_type {
  25. struct user_entry_type *next;
  26. int (*got_share) (struct userrec *, struct user_entry *, char *, int);
  27. int (*dup_user) (struct userrec *, struct userrec *,
  28. struct user_entry *);
  29. int (*unpack) (struct userrec *, struct user_entry *);
  30. int (*pack) (struct userrec *, struct user_entry *);
  31. int (*write_userfile) (FILE *, struct userrec *, struct user_entry *);
  32. int (*kill) (struct user_entry *);
  33. void *(*get) (struct userrec *, struct user_entry *);
  34. int (*set) (struct userrec *, struct user_entry *, void *);
  35. void (*display) (int idx, struct user_entry *, struct userrec *);
  36. char *name;
  37. };
  38. #ifndef MAKING_MODS
  39. extern struct user_entry_type USERENTRY_COMMENT, USERENTRY_LASTON,
  40. USERENTRY_INFO, USERENTRY_BOTADDR, USERENTRY_HOSTS,
  41. USERENTRY_PASS, USERENTRY_BOTFL,
  42. USERENTRY_STATS,
  43. USERENTRY_ADDED,
  44. USERENTRY_MODIFIED,
  45. USERENTRY_CONFIG,
  46. USERENTRY_SECPASS;
  47. #endif /* MAKING_MODS */
  48. struct laston_info {
  49. time_t laston;
  50. char *lastonplace;
  51. };
  52. struct bot_addr {
  53. int telnet_port;
  54. int relay_port;
  55. int hublevel;
  56. char *address;
  57. char *uplink;
  58. int roleid;
  59. };
  60. struct user_entry {
  61. struct user_entry *next;
  62. struct user_entry_type *type;
  63. union {
  64. char *string;
  65. void *extra;
  66. struct list_type *list;
  67. unsigned long ulong;
  68. } u;
  69. char *name;
  70. };
  71. struct xtra_key {
  72. struct xtra_key *next;
  73. char *key;
  74. char *data;
  75. };
  76. struct filesys_stats {
  77. int uploads;
  78. int upload_ks;
  79. int dnloads;
  80. int dnload_ks;
  81. };
  82. int add_entry_type(struct user_entry_type *);
  83. int del_entry_type(struct user_entry_type *);
  84. struct user_entry_type *find_entry_type(char *);
  85. struct user_entry *find_user_entry(struct user_entry_type *, struct userrec *);
  86. void *get_user(struct user_entry_type *, struct userrec *);
  87. int set_user(struct user_entry_type *, struct userrec *, void *);
  88. #define bot_flags(u) ((long)get_user(&USERENTRY_BOTFL, (u)))
  89. #define is_bot(u) ((u) && ((u)->flags & USER_BOT))
  90. #define is_owner(u) ((u) && ((u)->flags & USER_OWNER))
  91. /* Fake users used to store ignores and bans
  92. */
  93. #define IGNORE_NAME "*ignore"
  94. #define BAN_NAME "*ban"
  95. #define EXEMPT_NAME "*exempt"
  96. #define INVITE_NAME "*Invite"
  97. #define CHANS_NAME "*channels"
  98. #define CONFIG_NAME "*Config"
  99. /* Channel-specific info
  100. */
  101. struct chanuserrec {
  102. struct chanuserrec *next;
  103. char channel[81];
  104. time_t laston;
  105. unsigned long flags;
  106. unsigned long flags_udef;
  107. char *info;
  108. };
  109. /* New-style userlist
  110. */
  111. struct userrec {
  112. struct userrec *next;
  113. char handle[HANDLEN + 1];
  114. unsigned long flags;
  115. unsigned long flags_udef;
  116. struct chanuserrec *chanrec;
  117. struct user_entry *entries;
  118. };
  119. struct igrec {
  120. struct igrec *next;
  121. char *igmask;
  122. time_t expire;
  123. char *user;
  124. time_t added;
  125. char *msg;
  126. int flags;
  127. };
  128. extern struct igrec *global_ign;
  129. #define IGREC_PERM 2
  130. /*
  131. * Note: Flags are in eggdrop.h
  132. */
  133. struct userrec *adduser();
  134. struct userrec *get_user_by_handle(struct userrec *, char *);
  135. struct userrec *get_user_by_host(char *);
  136. struct userrec *get_user_by_nick(char *);
  137. struct userrec *check_chanlist();
  138. struct userrec *check_chanlist_hand();
  139. /* All the default userentry stuff, for code re-use
  140. */
  141. int def_unpack(struct userrec *u, struct user_entry *e);
  142. int def_pack(struct userrec *u, struct user_entry *e);
  143. int def_kill(struct user_entry *e);
  144. int def_write_userfile(FILE *f, struct userrec *u, struct user_entry *e);
  145. void *def_get(struct userrec *u, struct user_entry *e);
  146. int def_set(struct userrec *u, struct user_entry *e, void *buf);
  147. int def_gotshare(struct userrec *u, struct user_entry *e,
  148. char *data, int idx);
  149. int def_tcl_get(Tcl_Interp *interp, struct userrec *u,
  150. struct user_entry *e, int argc, char **argv);
  151. int def_tcl_set(Tcl_Interp *irp, struct userrec *u,
  152. struct user_entry *e, int argc, char **argv);
  153. void def_display(int idx, struct user_entry *e, struct userrec *u);
  154. int def_dupuser(struct userrec *new, struct userrec *old,
  155. struct user_entry *e);
  156. #endif /* _EGG_USERS_H */