users.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. int (*tcl_get) (Tcl_Interp *, struct userrec *, struct user_entry *,
  36. int, char **);
  37. int (*tcl_set) (Tcl_Interp *, struct userrec *, struct user_entry *,
  38. int, char **);
  39. int (*expmem) (struct user_entry *);
  40. void (*display) (int idx, struct user_entry *, struct userrec *);
  41. char *name;
  42. };
  43. #ifndef MAKING_MODS
  44. extern struct user_entry_type USERENTRY_COMMENT, USERENTRY_LASTON,
  45. USERENTRY_INFO, USERENTRY_BOTADDR, USERENTRY_HOSTS,
  46. USERENTRY_PASS, USERENTRY_BOTFL,
  47. USERENTRY_STATS,
  48. USERENTRY_ADDED,
  49. USERENTRY_MODIFIED,
  50. USERENTRY_CONFIG,
  51. USERENTRY_SECPASS,
  52. USERENTRY_XTRA;
  53. #endif /* MAKING_MODS */
  54. struct laston_info {
  55. time_t laston;
  56. char *lastonplace;
  57. };
  58. struct bot_addr {
  59. int telnet_port;
  60. int relay_port;
  61. int hublevel;
  62. char *address;
  63. char *uplink;
  64. int roleid;
  65. };
  66. struct user_entry {
  67. struct user_entry *next;
  68. struct user_entry_type *type;
  69. union {
  70. char *string;
  71. void *extra;
  72. struct list_type *list;
  73. unsigned long ulong;
  74. } u;
  75. char *name;
  76. };
  77. struct xtra_key {
  78. struct xtra_key *next;
  79. char *key;
  80. char *data;
  81. };
  82. struct filesys_stats {
  83. int uploads;
  84. int upload_ks;
  85. int dnloads;
  86. int dnload_ks;
  87. };
  88. void *_user_malloc(int size, const char *file, int line);
  89. void *_user_realloc(void *ptr, int size, const char *file, int line);
  90. #ifndef MAKING_MODS
  91. # define user_malloc(x) _user_malloc(x, __FILE__, __LINE__)
  92. # define user_realloc(x, y) _user_realloc(x, y, __FILE__, __LINE__)
  93. #endif /* MAKING_MODS */
  94. int add_entry_type(struct user_entry_type *);
  95. int del_entry_type(struct user_entry_type *);
  96. struct user_entry_type *find_entry_type(char *);
  97. struct user_entry *find_user_entry(struct user_entry_type *, struct userrec *);
  98. void *get_user(struct user_entry_type *, struct userrec *);
  99. int set_user(struct user_entry_type *, struct userrec *, void *);
  100. #define bot_flags(u) ((long)get_user(&USERENTRY_BOTFL, (u)))
  101. #define is_bot(u) ((u) && ((u)->flags & USER_BOT))
  102. #define is_owner(u) ((u) && ((u)->flags & USER_OWNER))
  103. /* Fake users used to store ignores and bans
  104. */
  105. #define IGNORE_NAME "*ignore"
  106. #define BAN_NAME "*ban"
  107. #define EXEMPT_NAME "*exempt"
  108. #define INVITE_NAME "*Invite"
  109. #define CHANS_NAME "*channels"
  110. #define CONFIG_NAME "*Config"
  111. /* Channel-specific info
  112. */
  113. struct chanuserrec {
  114. struct chanuserrec *next;
  115. char channel[81];
  116. time_t laston;
  117. unsigned long flags;
  118. unsigned long flags_udef;
  119. char *info;
  120. };
  121. /* New-style userlist
  122. */
  123. struct userrec {
  124. struct userrec *next;
  125. char handle[HANDLEN + 1];
  126. unsigned long flags;
  127. unsigned long flags_udef;
  128. struct chanuserrec *chanrec;
  129. struct user_entry *entries;
  130. };
  131. struct igrec {
  132. struct igrec *next;
  133. char *igmask;
  134. time_t expire;
  135. char *user;
  136. time_t added;
  137. char *msg;
  138. int flags;
  139. };
  140. extern struct igrec *global_ign;
  141. #define IGREC_PERM 2
  142. /*
  143. * Note: Flags are in eggdrop.h
  144. */
  145. struct userrec *adduser();
  146. struct userrec *get_user_by_handle(struct userrec *, char *);
  147. struct userrec *get_user_by_host(char *);
  148. struct userrec *get_user_by_nick(char *);
  149. struct userrec *check_chanlist();
  150. struct userrec *check_chanlist_hand();
  151. /* All the default userentry stuff, for code re-use
  152. */
  153. int def_unpack(struct userrec *u, struct user_entry *e);
  154. int def_pack(struct userrec *u, struct user_entry *e);
  155. int def_kill(struct user_entry *e);
  156. int def_write_userfile(FILE *f, struct userrec *u, struct user_entry *e);
  157. void *def_get(struct userrec *u, struct user_entry *e);
  158. int def_set(struct userrec *u, struct user_entry *e, void *buf);
  159. int def_gotshare(struct userrec *u, struct user_entry *e,
  160. char *data, int idx);
  161. int def_tcl_get(Tcl_Interp *interp, struct userrec *u,
  162. struct user_entry *e, int argc, char **argv);
  163. int def_tcl_set(Tcl_Interp *irp, struct userrec *u,
  164. struct user_entry *e, int argc, char **argv);
  165. int def_expmem(struct user_entry *e);
  166. void def_display(int idx, struct user_entry *e, struct userrec *u);
  167. int def_dupuser(struct userrec *new, struct userrec *old,
  168. struct user_entry *e);
  169. #endif /* _EGG_USERS_H */