struct fakeuser *next;
} fakeuser;
-fakeuser *fakeuserlist = NULL;
-
-void fakeuser_cleanup();
-int fakeuser_loaddb();
-void fakeusers_load(const DBAPIResult *res, void *arg);
-void fakeuser_handler(nick *user, int command, void **params);
-int fakeadd(void *sender, int cargc, char **cargv);
-int fakelist(void *sender, int cargc, char **cargv);
-int fakekill(void *sender, int cargc, char **cargv);
-void schedulefakeuser(void *arg);
-fakeuser *findfakeuserbynick(char *nick);
-void fake_remove(char *nickname);
-fakeuser *fake_add(fakeuser *details);
-
+static fakeuser *fakeuserlist;
static DBAPIConn *nofudb;
-void _init() {
- if (!fakeuser_loaddb()) {
- Error("fakeuser", ERR_FATAL, "Cannot load database");
- return;
- }
+static void reconnectfakeuser(void *arg);
- registercontrolhelpcmd("fakeuser", NO_OPER, 4, &fakeadd, "Usage: FAKEUSER nick <ident> <host> <realname>\nCreates a fake user.");
- registercontrolhelpcmd("fakelist", NO_OPER, 0, &fakelist, "Usage: FAKELIST\nLists all fake users.");
- registercontrolhelpcmd("fakekill", NO_OPER, 2, &fakekill, "Usage: FAKEKILL nick <reason>\nRemoves a fake user");
+static fakeuser *findfakeuserbynick(char *nick) {
+ fakeuser *fake;
-}
+ for (fake = fakeuserlist; fake; fake = fake->next)
+ if (!ircd_strcmp(nick, fake->nick))
+ return fake;
-void _fini() {
- fakeuser_cleanup();
- deleteallschedules(schedulefakeuser);
- deregistercontrolcmd("fakeuser", &fakeadd);
- deregistercontrolcmd("fakelist", &fakelist);
- deregistercontrolcmd("fakekill", &fakekill);
+ return NULL;
}
-void fakeuser_cleanup() {
- fakeuser *fake;
- void *next;
+static void fake_free(fakeuser *fake) {
+ fakeuser **pnext;
- for (fake = fakeuserlist; fake; fake = next) {
+ if (fake->user)
deregisterlocaluser(fake->user, "Signing off");
- next = fake->next;
- free(fake);
+
+ deleteschedule(NULL, &reconnectfakeuser, fake);
+
+ for (pnext = &fakeuserlist; *pnext; pnext = &((*pnext)->next)) {
+ if (*pnext == fake) {
+ *pnext = fake->next;
+ break;
+ }
}
- fakeuserlist = NULL;
+ free(fake);
}
-int fakeuser_loaddb() {
- if (!nofudb) {
- nofudb = dbapi2open(DBAPI2_DEFAULT, "fakeusers");
+static void fake_remove(fakeuser *fake) {
+ nofudb->squery(nofudb, "DELETE FROM ? WHERE nick = ?", "Ts", "fakeusers", fake->nick);
+
+ fake_free(fake);
+}
- if (!nofudb) {
- Error("fakeuser", ERR_STOP, "Could not connect to database.");
- return 0;
+static void fakeuser_handler(nick *user, int command, void **params) {
+ if (command == LU_KILLED) {
+ fakeuser *fake;
+ time_t timenow = time(NULL);
+
+ fake = findfakeuserbynick(user->nick);
+
+ if (!fake) {
+ controlwall(NO_OPER, NL_FAKEUSERS, "Error: A fakeuser was killed, but wasn't found in the list");
+ Error("fakeuser", ERR_ERROR, "A fakeuser was killed, but wasn't found in the list");
+ return;
}
- }
- nofudb->createtable(nofudb, NULL, NULL,
- "CREATE TABLE ? ("
- "nick VARCHAR(?) NOT NULL,"
- "ident VARCHAR(?) NOT NULL,"
- "host VARCHAR(?) NOT NULL,"
- "realname VARCHAR(?) NOT NULL,"
- "PRIMARY KEY (nick))", "Tdddd", "fakeusers", NICKLEN, USERLEN, HOSTLEN, REALLEN);
+ fake->user = NULL;
- nofudb->query(nofudb, fakeusers_load, NULL,
- "SELECT nick, ident, host, realname FROM ?", "T", "fakeusers");
+ if (timenow - fake->lastkill < KILL_TIME) {
+ controlwall(NO_OPER, NL_FAKEUSERS, "Fake user %s!%s@%s (%s) KILL'ed twice under in %d seconds. Removing.",
+ fake->nick, fake->ident, fake->host, fake->realname, KILL_TIME);
+ fake_remove(fake);
+ return;
+ }
- return 1;
-}
+ fake->lastkill = timenow;
-void fakeusers_load(const DBAPIResult *res, void *arg) {
- fakeuser fakeuser;
+ scheduleoneshot(time(NULL) + KILL_WAIT, &reconnectfakeuser, fake);
+ }
+}
- if (!res)
+static void reconnectfakeuser(void *arg) {
+ fakeuser *fake = arg;
+ nick *user;
+
+ if (fake->user)
return;
- if (!res->success) {
- Error("fakeuser", ERR_ERROR, "Error loading fakeuser list.");
- res->clear(res);
+ if ((user = getnickbynick(fake->nick)) && (IsOper(user) || IsService(user) || IsXOper(user)))
return;
- }
- while (res->next(res)) {
- strlcpy(fakeuser.nick, res->get(res, 0), NICKLEN + 1);
- strlcpy(fakeuser.ident, res->get(res, 1), USERLEN + 1);
- strlcpy(fakeuser.host, res->get(res, 2), HOSTLEN + 1);
- strlcpy(fakeuser.realname, res->get(res, 3), REALLEN + 1);
- fake_add(&fakeuser);
- }
-
- scheduleoneshot(time(NULL) + 1, schedulefakeuser, NULL);
- res->clear(res);
+ fake->user = registerlocaluser(fake->nick, fake->ident, fake->host, fake->realname,
+ NULL, UMODE_INV | UMODE_DEAF, &fakeuser_handler);
}
-fakeuser *getdetails(nick *user) {
- fakeuser *details;
- details = malloc(sizeof(fakeuser));
+static fakeuser *fake_add(const char *nick, const char *ident, const char *host, const char *realname) {
+ fakeuser *fake;
- if (!details)
+ fake = malloc(sizeof(fakeuser));
+
+ if (!fake)
return NULL;
- strlcpy(details->nick, user->nick, NICKLEN + 1);
- strlcpy(details->ident, user->ident, USERLEN + 1);
- strlcpy(details->host, user->host->name->content, HOSTLEN + 1);
- strlcpy(details->realname, user->realname->name->content, REALLEN + 1);
- details->lastkill = 0;
- return details;
-}
+ strlcpy(fake->nick, nick, NICKLEN + 1);
+ strlcpy(fake->ident, ident, USERLEN + 1);
+ strlcpy(fake->host, host, HOSTLEN + 1);
+ strlcpy(fake->realname, realname, REALLEN + 1);
-nick *register_fakeuseronnet(fakeuser *details) {
- nick *user;
+ fake->user = NULL;
+ fake->lastkill = 0;
- if ((user = getnickbynick(details->nick)) && (IsOper(user) || IsService(user) || IsXOper(user))) {
- return NULL;
- }
+ fake->next = fakeuserlist;
+ fakeuserlist = fake;
- return registerlocaluser(details->nick, details->ident, details->host, details->realname,
- NULL, UMODE_INV | UMODE_DEAF, &fakeuser_handler);
+ scheduleoneshot(time(NULL) + 1, reconnectfakeuser, fake);
+
+ return fake;
}
-fakeuser *fake_add(fakeuser *details) {
- fakeuser *newfake;
-
- newfake = malloc(sizeof(fakeuser));
+static fakeuser *fake_create(const char *nick, const char *ident, const char *host, const char *realname) {
+ fakeuser *fake;
+
+ fake = fake_add(nick, ident, host, realname);
- if (!newfake) {
+ if (!fake)
return NULL;
- }
+
+ nofudb->squery(nofudb, "INSERT INTO ? (nick, ident, host, realname) VALUES (?,?,?,?)", "Tssss", "fakeusers",
+ fake->nick, fake->ident, fake->host, fake->realname);
- memcpy(newfake, details, sizeof(fakeuser));
-
- newfake->user = NULL;
- newfake->lastkill = 0;
-
- newfake->next = fakeuserlist;
- fakeuserlist = newfake;
- return newfake;
+ return fake;
}
-void fake_remove(char *nickname) {
- fakeuser *fake, *prev;
+static void fakeusers_load(const DBAPIResult *res, void *arg) {
+ if (!res)
+ return;
- for (fake = fakeuserlist; fake; fake = fake->next) {
- if (!ircd_strcmp(nickname, fake->nick)) {
- if (fake == fakeuserlist)
- fakeuserlist = fake->next;
- else
- prev->next = fake->next;
+ if (!res->success) {
+ Error("fakeuser", ERR_ERROR, "Error loading fakeuser list.");
+ res->clear(res);
+ return;
+ }
- free(fake);
- return;
- }
+ while (res->next(res))
+ fake_add(res->get(res, 0), res->get(res, 1), res->get(res, 2), res->get(res, 3));
- prev = fake;
- }
+ res->clear(res);
}
-void fakeuser_handler(nick *user, int command, void **params) {
- if (command == LU_KILLED) {
- fakeuser *item;
- time_t timenow = time(NULL);
-
- item = findfakeuserbynick(user->nick);
+static int fakeuser_loaddb() {
+ if (!nofudb) {
+ nofudb = dbapi2open(DBAPI2_DEFAULT, "fakeusers");
- if (!item) {
- controlwall(NO_OPER, NL_FAKEUSERS, "Error: A fakeuser was killed, but wasn't found in the list");
- Error("fakeuser", ERR_ERROR, "A fakeuser was killed, but wasn't found in the list");
- return;
+ if (!nofudb) {
+ Error("fakeuser", ERR_STOP, "Could not connect to database.");
+ return 0;
}
+ }
- item->user = NULL;
-
- if (timenow - item->lastkill < KILL_TIME) {
- controlwall(NO_OPER, NL_FAKEUSERS, "Fake user %s!%s@%s (%s) KILL'ed twice under in %d seconds. Removing.", item->nick, item->ident, item->host, item->realname, KILL_TIME);
- nofudb->squery(nofudb, "DELETE FROM ? WHERE nick = ?", "Ts", "fakeusers", item->nick);
- fake_remove(item->nick);
- return;
- }
+ nofudb->createtable(nofudb, NULL, NULL,
+ "CREATE TABLE ? ("
+ "nick VARCHAR(?) NOT NULL,"
+ "ident VARCHAR(?) NOT NULL,"
+ "host VARCHAR(?) NOT NULL,"
+ "realname VARCHAR(?) NOT NULL,"
+ "PRIMARY KEY (nick))", "Tdddd", "fakeusers", NICKLEN, USERLEN, HOSTLEN, REALLEN);
- item->lastkill = timenow;
+ nofudb->query(nofudb, fakeusers_load, NULL,
+ "SELECT nick, ident, host, realname FROM ?", "T", "fakeusers");
- scheduleoneshot(time(NULL) + KILL_WAIT, schedulefakeuser, item);
- }
+ return 1;
}
-int fakeadd(void *sender, int cargc, char **cargv) {
- fakeuser newfake;
+static int fakeadd(void *source, int cargc, char **cargv) {
+ nick *sender = source;
fakeuser *fake;
+ char *nick, *ident, *realname;
+ char host[HOSTLEN + 1];
if (cargc == 0)
return CMD_USAGE;
return CMD_ERROR;
}
- strlcpy(newfake.nick, cargv[0], NICKLEN + 1);
+ nick = cargv[0];
if (cargc < 4)
- strlcpy(newfake.realname, cargv[0], REALLEN + 1);
+ realname = cargv[0];
else
- strlcpy(newfake.realname, cargv[3], REALLEN + 1);
+ realname = cargv[3];
if (cargc < 3) {
- strlcpy(newfake.host, cargv[0], NICKLEN + 1);
- strlcat(newfake.host, ".fakeusers.quakenet.org", HOSTLEN + 1);
+ strlcpy(host, cargv[0], NICKLEN + 1);
+ strlcat(host, ".fakeusers.quakenet.org", HOSTLEN + 1);
} else
- strlcpy(newfake.host, cargv[2], HOSTLEN + 1);
+ strlcpy(host, cargv[2], HOSTLEN + 1);
if (cargc < 2)
- strlcpy(newfake.ident, cargv[0], USERLEN + 1);
+ ident = cargv[0];
else
- strlcpy(newfake.ident, cargv[1], USERLEN + 1);
+ ident = cargv[1];
- fake = fake_add(&newfake);
+ fake = fake_create(nick, ident, host, realname);
- if (!fake) {
+ if (!fake)
return CMD_ERROR;
- }
- nofudb->squery(nofudb, "INSERT INTO ? (nick, ident, host, realname) VALUES (?,?,?,?)", "Tssss", "fakeusers", fake->nick, fake->ident, fake->host, fake->realname);
controlreply(sender, "Added fake user %s", fake->nick);
- controlwall(NO_OPER, NL_FAKEUSERS, "Fake user %s!%s@%s (%s) added by %s/%s", fake->nick, fake->ident,
- fake->host, fake->realname, ((nick *)sender)->nick, ((nick *)sender)->authname);
+ controlwall(NO_OPER, NL_FAKEUSERS, "%s added fake user: %s!%s@%s (%s)", controlid(sender),
+ fake->nick, fake->ident, fake->host, fake->realname);
- scheduleoneshot(time(NULL) + 1, schedulefakeuser, fake);
+ scheduleoneshot(time(NULL) + 1, &reconnectfakeuser, fake);
return CMD_OK;
}
-int fakelist(void *sender, int cargc, char **cargv) {
+static int fakelist(void *sender, int cargc, char **cargv) {
fakeuser *fake;
int fakeusercount = 0;
for (fake = fakeuserlist; fake; fake = fake->next) {
if (!fake->user)
- controlreply(sender, "%s!%s@%s (%s) %s - RECONNECTING", fake->nick, fake->ident,
+ controlreply(sender, "%s!%s@%s (%s) - RECONNECTING", fake->nick, fake->ident,
fake->host, fake->realname);
else
controlreply(sender, "%s!%s@%s (%s)", fake->nick, fake->ident,
return CMD_OK;
}
-int fakekill(void *sender, int cargc, char **cargv) {
+static int fakekill(void *sender, int cargc, char **cargv) {
fakeuser *fake;
if (cargc == 0)
controlwall(NO_OPER, NL_FAKEUSERS, "Fake user %s!%s@%s (%s) removed by %s/%s", fake->nick, fake->ident,
fake->host, fake->realname, ((nick *)sender)->nick, ((nick *)sender)->authname);
- if (fake->user) {
- if (cargc > 1)
- deregisterlocaluser(fake->user, cargv[1]);
- else
- deregisterlocaluser(fake->user, "Signing off");
- }
-
- fake_remove(cargv[0]);
+ fake_remove(fake);
return CMD_OK;
}
-void schedulefakeuser(void *arg) {
- fakeuser *fake;
-
- for (fake = fakeuserlist; fake; fake = fake->next) {
- if (!fake->user) {
- fake->user = register_fakeuseronnet(fake);
- }
+void _init() {
+ if (!fakeuser_loaddb()) {
+ Error("fakeuser", ERR_FATAL, "Cannot load database");
+ return;
}
+
+ registercontrolhelpcmd("fakeuser", NO_OPER, 4, &fakeadd, "Usage: FAKEUSER nick <ident> <host> <realname>\nCreates a fake user.");
+ registercontrolhelpcmd("fakelist", NO_OPER, 0, &fakelist, "Usage: FAKELIST\nLists all fake users.");
+ registercontrolhelpcmd("fakekill", NO_OPER, 2, &fakekill, "Usage: FAKEKILL nick\nRemoves a fake user");
}
-fakeuser *findfakeuserbynick(char *nick) {
- fakeuser *fake;
+void _fini() {
+ fakeuser *fake, *next;
- for (fake = fakeuserlist; fake; fake = fake->next) {
- if (!ircd_strcmp(nick, fake->nick)) {
- return fake;
- }
+ for (fake = fakeuserlist; fake; fake = next) {
+ next = fake->next;
+ fake_free(fake);
}
- return NULL;
+ deregistercontrolcmd("fakeuser", &fakeadd);
+ deregistercontrolcmd("fakelist", &fakelist);
+ deregistercontrolcmd("fakekill", &fakekill);
}