Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lookup_user_record() #1618

Merged
merged 14 commits into from
Jun 29, 2024
9 changes: 5 additions & 4 deletions src/cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1907,19 +1907,20 @@ static int add_to_handle(struct userrec *u, int idx, char *handle, char *host, i
return 1;
}
}
if ( !type && !glob_botmast(fr) && !chan_master(fr) && get_user_by_host(host)) {
dprintf(idx, "You cannot add %s matching another user!\n",
type ? "an account" : "a host");
if ( !type && !glob_botmast(fr) && !chan_master(fr) && lookup_user_record(NULL, NULL, host)) {
dprintf(idx, "You cannot add a host matching another user!\n");
return 1;
}
if (type) {
u2 = get_user_by_account(host);
// account
u2 = lookup_user_record(NULL, host, NULL);
if (u2) {
dprintf(idx, "That account already exists for user %s\n", u2->handle);
return 1;
}
addaccount_by_handle(handle, host);
} else {
// host
for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next) {
if (!strcasecmp(q->extra, host)) {
dprintf(idx, "That %s is already there.\n",
Expand Down
45 changes: 10 additions & 35 deletions src/mod/irc.mod/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,7 @@ static int detect_chan_flood(char *floodnick, char *floodhost, char *from,
if (!m && (which != FLOOD_JOIN))
return 0;

if (m) {
u = get_user_from_member(m);
} else {
u = victim_or_account ? get_user_by_account(victim_or_account) : NULL;
if (!u) {
u = get_user_by_host(from);
}
}

u = lookup_user_record(m, victim_or_account, from);
get_user_flagrec(u, &fr, chan->dname);
if (glob_bot(fr) || ((which == FLOOD_DEOP) && (glob_master(fr) ||
chan_master(fr)) && (glob_friend(fr) || chan_friend(fr))) ||
Expand Down Expand Up @@ -333,7 +325,6 @@ static int detect_chan_flood(char *floodnick, char *floodhost, char *from,
chan->floodwho[which][0] = 0;
if (which == FLOOD_DEOP)
chan->deopd[0] = 0;
u = get_user_from_member(m);
if (check_tcl_flud(floodnick, floodhost, u, ftype, chan->dname))
return 0;
switch (which) {
Expand Down Expand Up @@ -1843,7 +1834,7 @@ static int gottopic(char *from, char *msg)
if (m != NULL)
m->last = now;
set_topic(chan, msg);
u = get_user_from_member(m);
u = lookup_user_record(m, NULL, from); // TODO: get account from msgtags
check_tcl_topc(nick, from, u, chan->dname, msg);
}
return 0;
Expand Down Expand Up @@ -2079,16 +2070,17 @@ static int gotjoin(char *from, char *channame)
strlcpy(m->userhost, uhost, sizeof m->userhost);
m->flags |= STOPWHO;

u = get_user_from_member(m);

if (extjoin) {
u = lookup_user_record(m, account, from);
/* calls check_tcl_account which can delete the channel */
setaccount(nick, account);

if (!(chan = findchan(chname)) && !(chan = findchan_by_dname(ch_dname ? ch_dname : chname))) {
/* The channel doesn't exist anymore, so get out of here. */
goto exit;
}
} else {
u = lookup_user_record(find_member_from_nick(nick), NULL, from); // TODO: get account from msgtags
}
check_tcl_join(nick, uhost, u, chan->dname);

Expand Down Expand Up @@ -2129,9 +2121,9 @@ static int gotjoin(char *from, char *channame)
if (u) {
struct laston_info *li = 0;

cr = get_chanrec(get_user_from_member(m), chan->dname);
cr = get_chanrec(u, chan->dname);
if (!cr && no_chanrec_info)
li = get_user(&USERENTRY_LASTON, get_user_from_member(m));
li = get_user(&USERENTRY_LASTON, u);
if (channel_greet(chan) && use_info &&
((cr && now - cr->laston > wait_info) ||
(no_chanrec_info && (!li || now - li->laston > wait_info)))) {
Expand Down Expand Up @@ -2353,7 +2345,7 @@ static int gotkick(char *from, char *origmsg)
return 0;

m = ismember(chan, whodid);
u = get_user_from_member(m);
u = lookup_user_record(m, NULL, from); // TODO: get account from msgtags
if (m)
m->last = now;
/* This _needs_ to use chan->dname <cybah> */
Expand Down Expand Up @@ -2569,7 +2561,6 @@ static int gotmsg(char *from, char *msg)
int ctcp_count = 0, ignoring;
struct chanset_t *chan;
struct userrec *u;
memberlist *m;

/* Only handle if message is to a channel, or to @#channel. */
/* FIXME: Properly handle ovNotices (@+#channel), vNotices (+#channel), etc. */
Expand Down Expand Up @@ -2613,15 +2604,7 @@ static int gotmsg(char *from, char *msg)
ctcp_count++;
if (ctcp[0] != ' ') {
code = newsplit(&ctcp);
u = NULL;
for (chan = chanset; chan; chan = chan->next) {
for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
if (!rfc_casecmp(m->nick, nick)) {
u = get_user_from_member(m);
break;
}
}
}
u = lookup_user_record(find_member_from_nick(nick), NULL, from); // TODO: get account from msgtags
if (!ignoring || trigger_on_ignore) {
if (!check_tcl_ctcp(nick, uhost, u, to, code, ctcp)) {
chan = findchan(realto);
Expand Down Expand Up @@ -2714,15 +2697,7 @@ static int gotnotice(char *from, char *msg)
fixcolon(msg);
strlcpy(uhost, from, sizeof buf);
nick = splitnick(&uhost);
u = NULL;
for (chan = chanset; chan; chan = chan->next) {
for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
if (!rfc_casecmp(m->nick, nick)) {
u = get_user_from_member(m);
break;
}
}
}
u = lookup_user_record(get_all_chan_records(m), NULL, from); // TODO: get account from msgtags
/* Check for CTCP: */
p = strchr(msg, 1);
while (p && *p) {
Expand Down
1 change: 0 additions & 1 deletion src/mod/irc.mod/cmdsirc.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,6 @@ static void cmd_channel(struct userrec *u, int idx, char *par)
} else
strlcpy(s, " --- ", sizeof s);
egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);

u = get_user_from_member(m);
if (u == NULL)
strlcpy(handle, "*", sizeof handle);
Expand Down
14 changes: 8 additions & 6 deletions src/mod/irc.mod/irc.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static void punish_badguy(struct chanset_t *chan, char *whobad,
static void maybe_revenge(struct chanset_t *chan, char *whobad,
char *whovictim, int type)
{
char *badnick, *victim;
char *badnick, *victim, buf[NICKLEN + UHOSTLEN];
int mevictim;
struct userrec *u, *u2;
memberlist *m;
Expand All @@ -233,14 +233,16 @@ static void maybe_revenge(struct chanset_t *chan, char *whobad,
return;

/* Get info about offender */
strlcpy(buf, whobad, sizeof buf);
badnick = splitnick(&whobad);
m = ismember(chan, badnick);
u = get_user_from_member(m);
u = lookup_user_record(m, NULL, buf); // TODO: get account from msgtags

/* Get info about victim */
strlcpy(buf, whovictim, sizeof buf);
victim = splitnick(&whovictim);
m = ismember(chan, victim);
u2 = get_user_from_member(m);
u2 = lookup_user_record(m, NULL, buf); // TODO: get account from msgtags
mevictim = match_my_nick(victim);

/* Do we want to revenge? */
Expand Down Expand Up @@ -908,15 +910,15 @@ static int check_tcl_pub(char *nick, char *from, char *chname, char *msg)
int x;
char buf[512], *args = buf, *cmd, host[161], *hand;
struct chanset_t *chan;
struct userrec *u;
struct userrec *u = NULL;
memberlist *m;

strlcpy(buf, msg, sizeof buf);
cmd = newsplit(&args);
simple_sprintf(host, "%s!%s", nick, from);
chan = findchan(chname);
m = ismember(chan, nick);
u = get_user_from_member(m);
u = lookup_user_record(m ? m : find_member_from_nick(nick), NULL, from); // TODO: get account from msgtags
hand = u ? u->handle : "*";
get_user_flagrec(u, &fr, chname);
Tcl_SetVar(interp, "_pub1", nick, 0);
Expand Down Expand Up @@ -946,7 +948,7 @@ static int check_tcl_pubm(char *nick, char *from, char *chname, char *msg)
simple_sprintf(host, "%s!%s", nick, from);
chan = findchan(chname);
m = ismember(chan, nick);
u = get_user_from_member(m);
u = lookup_user_record(m ? m : find_member_from_nick(nick), NULL, from); // TODO: get account from msgtags
get_user_flagrec(u, &fr, chname);
Tcl_SetVar(interp, "_pubm1", nick, 0);
Tcl_SetVar(interp, "_pubm2", from, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/mod/irc.mod/mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ static struct chanset_t *modebind_refresh(char *chname,
if (!chname || !(chan = findchan(chname)))
return NULL;
if (usrhost) {
u = get_user_by_host(usrhost);
u = lookup_user_record(NULL, NULL, usrhost); // TODO: get account from somewhere
get_user_flagrec(u, usr, chan->dname);
}
if (vcrhost) {
u = get_user_by_host(vcrhost);
u = lookup_user_record(NULL, NULL, vcrhost); // TODO: get account from somewhere
get_user_flagrec(u, vcr, chan->dname);
}
return chan;
Expand Down
6 changes: 4 additions & 2 deletions src/mod/irc.mod/msgcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ static int msg_who(char *nick, char *host, struct userrec *u, char *par)
struct userrec *u;

egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
/* Don't use s for host here, b/c if we don't have m, we won't have s */
u = get_user_from_member(m);
info = get_user(&USERENTRY_INFO, u);
if (u && (u->flags & USER_BOT))
Expand Down Expand Up @@ -431,7 +432,7 @@ static int msg_who(char *nick, char *host, struct userrec *u, char *par)

static int msg_whois(char *nick, char *host, struct userrec *u, char *par)
{
char s1[143], *s2, stime[14];
char s1[143], *s2, stime[14], uhost[NICKLEN + UHOSTLEN];
int ok;
struct chanset_t *chan;
memberlist *m;
Expand All @@ -454,7 +455,8 @@ static int msg_whois(char *nick, char *host, struct userrec *u, char *par)
}
if (strlen(par) > NICKMAX)
par[NICKMAX] = 0;
putlog(LOG_CMDS, "*", "(%s!%s) !%s! WHOIS %s", nick, host, u->handle, par);
egg_snprintf(uhost, sizeof uhost, "%s!%s", nick, host);
putlog(LOG_CMDS, "*", "(%s) !%s! WHOIS %s", uhost, u->handle, par);
u2 = get_user_by_handle(userlist, par);
if (!u2) {
/* No such handle -- maybe it's a nickname of someone on a chan? */
Expand Down
3 changes: 2 additions & 1 deletion src/mod/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,9 @@ typedef void (*chanout_butfunc)(int, int, const char *, ...) ATTRIBUTE_FORMAT(pr
#define bind_bind_entry ((int(*)(tcl_bind_list_t *, const char *, const char *, const char *))global[320])
#define unbind_bind_entry ((int(*)(tcl_bind_list_t *, const char *, const char *, const char *))global[321])
#define argv0 ((char *)global[322])
#define get_user_from_member ((struct userrec * (*)(memberlist *))global[323])
#define lookup_user_record ((struct userrec * (*)(memberlist *, const char *, const char *))global[323])
/* 324 - 327 */
#define find_member_from_nick ((memberlist * (*) (char *))global[324])


/* hostmasking */
Expand Down
14 changes: 8 additions & 6 deletions src/mod/server.mod/servmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ static int detect_flood(char *floodnick, char *floodhost, char *from, int which)
if (!strcasecmp(floodhost, botuserhost))
return 0;

u = get_user_by_host(from);
thommey marked this conversation as resolved.
Show resolved Hide resolved
u = lookup_user_record(NULL, NULL, from); // TODO: get account somehow
atr = u ? u->flags : 0;
if (atr & (USER_BOT | USER_FRIEND))
return 0;
Expand Down Expand Up @@ -539,7 +539,7 @@ static int detect_flood(char *floodnick, char *floodhost, char *from, int which)
lastmsgs[which] = 0;
lastmsgtime[which] = 0;
lastmsghost[which][0] = 0;
u = get_user_by_host(from);
u = lookup_user_record(NULL, NULL, from); // TODO: get account somehow
if (check_tcl_flud(floodnick, floodhost, u, ftype, "*"))
return 0;
/* Private msg */
Expand All @@ -559,6 +559,7 @@ static int gotmsg(char *from, char *msg)
char *to, buf[UHOSTLEN], *nick, ctcpbuf[512], *uhost = buf, *ctcp,
*p, *p1, *code;
struct userrec *u;
memberlist *m = NULL;
int ctcp_count = 0;
int ignoring;

Expand Down Expand Up @@ -607,7 +608,7 @@ static int gotmsg(char *from, char *msg)
putlog(LOG_PUBLIC, to, "CTCP %s: %s from %s (%s) to %s",
code, ctcp, nick, uhost, to);
} else {
u = get_user_by_host(from);
u = lookup_user_record(find_member_from_nick(nick), NULL, from); // TODO: get account from msgtags
if (!ignoring || trigger_on_ignore) {
if (!check_tcl_ctcp(nick, uhost, u, to, code, ctcp) && !ignoring) {
if ((lowercase_ctcp && !strcasecmp(code, "DCC")) ||
Expand Down Expand Up @@ -670,7 +671,7 @@ static int gotmsg(char *from, char *msg)
}

detect_flood(nick, uhost, from, FLOOD_PRIVMSG);
u = get_user_by_host(from);
u = lookup_user_record(find_member_from_nick(nick), NULL, from); // TODO: get account from msgtags
code = newsplit(&msg);
rmspace(msg);

Expand All @@ -694,6 +695,7 @@ static int gotnotice(char *from, char *msg)
{
char *to, *nick, ctcpbuf[512], *p, *p1, buf[512], *uhost = buf, *ctcp;
struct userrec *u;
memberlist *m;
int ignoring;

/* Notice to a channel, not handled here */
Expand Down Expand Up @@ -730,7 +732,7 @@ static int gotnotice(char *from, char *msg)
"CTCP reply %s: %s from %s (%s) to %s", code, ctcp,
nick, uhost, to);
} else {
u = get_user_by_host(from);
u = lookup_user_record(find_member_from_nick(nick), NULL, from); // TODO: get account from msgtags
if (!ignoring || trigger_on_ignore) {
check_tcl_ctcr(nick, uhost, u, to, code, ctcp);
if (!ignoring)
Expand Down Expand Up @@ -766,7 +768,7 @@ static int gotnotice(char *from, char *msg)
}

detect_flood(nick, uhost, from, FLOOD_NOTICE);
u = get_user_by_host(from);
u = lookup_user_record(find_member_from_nick(nick), NULL, from); // TODO: get account from msgtags

if (!ignoring || trigger_on_ignore)
if (check_tcl_notc(nick, uhost, u, botname, msg) == 2)
Expand Down
3 changes: 2 additions & 1 deletion src/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,9 @@ Function global_table[] = {
(Function) bind_bind_entry,
(Function) unbind_bind_entry,
(Function) & argv0,
(Function) get_user_from_member
(Function) lookup_user_record,
/* 324 - 327 */
(Function) find_member_from_nick
};

void init_modules(void)
Expand Down
Loading