users.h 5.0 KB

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