ソースを参照

Store the FFLAGS in the user file and cache it in the userrec.

Issue #87
Bryan Drewery 10 年 前
コミット
d15ca5606f
3 ファイル変更61 行追加4 行削除
  1. 13 2
      src/botnet.cc
  2. 44 0
      src/userent.cc
  3. 4 2
      src/users.h

+ 13 - 2
src/botnet.cc

@@ -98,7 +98,6 @@ void addbot(char *who, char *from, char *next, char flag, int vlocalhub, time_t
   ptr2->share = flag;
   ptr2->localhub = vlocalhub;
   ptr2->buildts = vbuildts;
-  ptr2->fflags = fflags;
   strlcpy(ptr2->commit, vcommit, sizeof(ptr2->commit));
   if (vversion && vversion[0])
     strlcpy(ptr2->version, vversion, 121);
@@ -110,6 +109,13 @@ void addbot(char *who, char *from, char *next, char flag, int vlocalhub, time_t
   ptr2->hub = is_hub(who);
   /* Cache user record */
   ptr2->u = userlist ? get_user_by_handle(userlist, who) : NULL;
+  ptr2->fflags = fflags;
+  if (fflags != -1) {
+    char buf[15];
+
+    simple_snprintf(buf, sizeof(buf), "%d", ptr2->fflags);
+    set_user(&USERENTRY_FFLAGS, ptr2->u ? ptr2->u : get_user_by_handle(userlist, who), buf);
+  }
   if (!strcasecmp(next, conf.bot->nick))
     ptr2->uplink = (tand_t *) 1;
   else
@@ -149,8 +155,13 @@ void updatebot(int idx, char *who, char share, int vlocalhub, time_t vbuildts, c
     if (vversion && vversion[0])
       strlcpy(ptr->version, vversion, 121);
     /* -1 = unknown (do not modify) */
-    if (fflags != -1)
+    if (fflags != -1) {
+      char buf[15];
+
       ptr->fflags = fflags;
+      simple_snprintf(buf, sizeof(buf), "%d", ptr->fflags);
+      set_user(&USERENTRY_FFLAGS, ptr->u ? ptr->u : get_user_by_handle(userlist, who), buf);
+    }
     /* Assign flags here */
     botnet_send_update(idx, ptr);
   }

+ 44 - 0
src/userent.cc

@@ -62,6 +62,7 @@ void init_userent()
   add_entry_type(&USERENTRY_ADDED);
   add_entry_type(&USERENTRY_MODIFIED);
   add_entry_type(&USERENTRY_SET);
+  add_entry_type(&USERENTRY_FFLAGS);
 }
 
 void list_type_kill(struct list_type *t)
@@ -467,6 +468,49 @@ struct user_entry_type USERENTRY_ARCH = {
  "ARCH"
 };
 
+bool fflags_unpack(struct userrec *u, struct user_entry *e)
+{
+  bool ret = def_unpack(u, e);
+  /* Cache the value in the user record. */
+  u->fflags = atoi((char *) def_get(u, e));
+  return ret;
+}
+
+bool fflags_set(struct userrec *u, struct user_entry *e, void *buf)
+{
+  bool ret;
+
+  /* No need to share since it is sent over the tandem/botlink. */
+  noshare = 1;
+  ret = def_set(u, e, buf);
+  noshare = 0;
+  /* Cache the value in the user record. */
+  u->fflags = atoi((char *) def_get(u, e));
+  return ret;
+}
+
+bool fflags_gotshare(struct userrec *u, struct user_entry *e, char *data,
+    int idx)
+{
+  /* Don't let another bot dictate our features. */
+  if (u == conf.bot->u) {
+    return false;
+  }
+  return def_gotshare(u, e, data, idx);
+}
+
+struct user_entry_type USERENTRY_FFLAGS = {
+ 0,
+ fflags_gotshare,
+ fflags_unpack,
+ def_write_userfile,
+ def_kill,
+ def_get,
+ fflags_set,
+ botmisc_display,
+ "FFLAGS"
+};
+
 void stats_add(struct userrec *u, int islogin, int op)
 {
   if (!u || u->bot)

+ 4 - 2
src/users.h

@@ -49,8 +49,9 @@ struct user_entry_type {
 extern struct user_entry_type USERENTRY_COMMENT, USERENTRY_LASTON,
  USERENTRY_INFO, USERENTRY_BOTADDR, USERENTRY_HOSTS,
  USERENTRY_PASS, USERENTRY_STATS, USERENTRY_ADDED, USERENTRY_MODIFIED,
- USERENTRY_SET, USERENTRY_SECPASS, USERENTRY_USERNAME, USERENTRY_NODENAME, USERENTRY_OS,
- USERENTRY_PASS1, USERENTRY_ARCH, USERENTRY_OSVER;
+ USERENTRY_SET, USERENTRY_SECPASS, USERENTRY_USERNAME, USERENTRY_NODENAME,
+ USERENTRY_OS, USERENTRY_PASS1, USERENTRY_ARCH, USERENTRY_OSVER,
+ USERENTRY_FFLAGS;
 
 struct laston_info {
   time_t laston;
@@ -126,6 +127,7 @@ struct userrec {
   struct chanuserrec *chanrec;
   struct userrec *next;
   flag_t flags;
+  int fflags;
   char handle[HANDLEN + 1];
   char bot;
 };