diff --git a/src/mod/channels.mod/userchan.c b/src/mod/channels.mod/userchan.c index 2bac2ac3a..abbd94911 100644 --- a/src/mod/channels.mod/userchan.c +++ b/src/mod/channels.mod/userchan.c @@ -1270,7 +1270,7 @@ static int expired_mask(struct chanset_t *chan, char *who) * present in the channel and has op. */ - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, buf); /* Do not expire masks set by bots. */ if (u && u->flags & USER_BOT) return 0; diff --git a/src/mod/irc.mod/chan.c b/src/mod/irc.mod/chan.c index f0cb827d7..3f0b7312d 100644 --- a/src/mod/irc.mod/chan.c +++ b/src/mod/irc.mod/chan.c @@ -110,7 +110,7 @@ static void setaccount(char *nick, char *account) } else { putlog(LOG_MODES, chan->dname, "%s!%s logged in to their account %s", nick, m->userhost, account); } - check_tcl_account(m->nick, m->userhost, get_user_from_member(m), chan->dname, account); + check_tcl_account(m->nick, m->userhost, lookup_user_record(m, account, NULL), chan->dname, account); } strlcpy(m->account, account, sizeof m->account); } @@ -241,7 +241,7 @@ static int detect_chan_flood(char *floodnick, char *floodhost, char *from, return 0; if (m) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); } else { u = victim_or_account ? get_user_by_account(victim_or_account) : NULL; if (!u) { @@ -333,7 +333,7 @@ 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); + u = lookup_user_record(m, NULL, from); if (check_tcl_flud(floodnick, floodhost, u, ftype, chan->dname)) return 0; switch (which) { @@ -438,7 +438,7 @@ static void kick_all(struct chanset_t *chan, char *hostmask, char *comment, flushed = 0; kicknick[0] = 0; for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - get_user_flagrec(get_user_from_member(m), &fr, chan->dname); + get_user_flagrec(lookup_user_record(m, NULL, NULL), &fr, chan->dname); if ((me_op(chan) || (me_halfop(chan) && !chan_hasop(m))) && match_addr(hostmask, s) && !chan_sentkick(m) && !match_my_nick(m->nick) && !chan_issplit(m) && @@ -486,7 +486,7 @@ static void refresh_ban_kick(struct chanset_t *chan, char *user, char *nick) if (match_addr(b->mask, user)) { struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 }; char c[512]; /* The ban comment. */ - get_user_flagrec(get_user_from_member(m), &fr, + get_user_flagrec(lookup_user_record(m, NULL, NULL), &fr, chan->dname); if (!glob_friend(fr) && !chan_friend(fr)) { add_mode(chan, '-', 'o', nick); /* Guess it can't hurt. */ @@ -878,7 +878,7 @@ static void check_this_member(struct chanset_t *chan, char *nick, (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) { check_exemptlist(chan, s); quickban(chan, m->userhost); - p = get_user(&USERENTRY_COMMENT, get_user_from_member(m)); + p = get_user(&USERENTRY_COMMENT, lookup_user_record(m, NULL, NULL)); dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, m->nick, p ? p : IRC_POLITEKICK); m->flags |= SENTKICK; @@ -897,7 +897,7 @@ static void check_this_user(char *hand, int delete, char *host) for (chan = chanset; chan; chan = chan->next) for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if ((u && !strcasecmp(u->handle, hand) && delete < 2) || (!u && delete == 2 && match_addr(host, s))) { u = delete ? NULL : u; @@ -923,7 +923,7 @@ static void recheck_channel(struct chanset_t *chan, int dobans) stacking++; /* Okay, sort through who needs to be deopped. */ for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); get_user_flagrec(u, &fr, chan->dname); if (glob_bot(fr) && chan_hasop(m) && !match_my_nick(m->nick)) stop_reset = 1; @@ -1241,7 +1241,7 @@ static int gotchghost(char *from, char *msg) { chname = chan->dname; m = ismember(chan, nick); if (m) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); snprintf(m->userhost, sizeof m->userhost, "%s@%s", ident, msg); snprintf(mask, sizeof mask, "%s %s!%s@%s", chname, nick, ident, msg); check_tcl_chghost(nick, from, mask, u, chname, ident, msg); @@ -1408,7 +1408,7 @@ static int gotaway(char *from, char *msg) chname = chan->dname; m = ismember(chan, nick); if (m) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); snprintf(mask, sizeof mask, "%s %s", chname, from); check_tcl_ircaway(nick, from, mask, u, chname, msg); if (strlen(msg)) { @@ -1843,7 +1843,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); check_tcl_topc(nick, from, u, chan->dname, msg); } return 0; @@ -2041,7 +2041,7 @@ static int gotjoin(char *from, char *channame) } else { m = ismember(chan, nick); if (m && m->split && !strcasecmp(m->userhost, uhost)) { - u = get_user_from_member(m); + u = lookup_user_record(m, account, from); get_user_flagrec(u, &fr, chan->dname); check_tcl_rejn(nick, uhost, u, chan->dname); @@ -2057,7 +2057,7 @@ static int gotjoin(char *from, char *channame) goto exit; /* The tcl binding might have deleted the current user. Recheck. */ - u = get_user_from_member(m); + u = lookup_user_record(m, account, from); m->split = 0; m->last = now; m->delay = 0L; @@ -2079,7 +2079,7 @@ static int gotjoin(char *from, char *channame) strlcpy(m->userhost, uhost, sizeof m->userhost); m->flags |= STOPWHO; - u = get_user_from_member(m); + u = lookup_user_record(m, account, from); if (extjoin) { /* calls check_tcl_account which can delete the channel */ @@ -2129,9 +2129,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(lookup_user_record(m, account, from), chan->dname); if (!cr && no_chanrec_info) - li = get_user(&USERENTRY_LASTON, get_user_from_member(m)); + li = get_user(&USERENTRY_LASTON, lookup_user_record(m, account, from)); if (channel_greet(chan) && use_info && ((cr && now - cr->laston > wait_info) || (no_chanrec_info && (!li || now - li->laston > wait_info)))) { @@ -2189,7 +2189,7 @@ static int gotjoin(char *from, char *channame) (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) { check_exemptlist(chan, from); quickban(chan, from); - p = get_user(&USERENTRY_COMMENT, get_user_from_member(m)); + p = get_user(&USERENTRY_COMMENT, lookup_user_record(m, account, from)); dprintf(DP_MODE, "KICK %s %s :%s\n", chname, nick, (p && (p[0] != '@')) ? p : IRC_COMMENTKICK); m->flags |= SENTKICK; @@ -2263,7 +2263,7 @@ static int gotpart(char *from, char *msg) if (chan && !channel_pending(chan)) { nick = splitnick(&from); m = ismember(chan, nick); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); if (!channel_active(chan)) { /* whoa! */ putlog(LOG_MISC, chan->dname, @@ -2353,7 +2353,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); if (m) m->last = now; /* This _needs_ to use chan->dname */ @@ -2370,7 +2370,7 @@ static int gotkick(char *from, char *origmsg) struct userrec *u2; simple_sprintf(s1, "%s!%s", m->nick, m->userhost); - u2 = get_user_from_member(m); + u2 = lookup_user_record(m, NULL, from); set_handle_laston(chan->dname, u2, now); maybe_revenge(chan, from, s1, REVENGE_KICK); } @@ -2453,7 +2453,7 @@ static int gotnick(char *from, char *msg) m->flags &= ~(SENTKICK | SENTDEOP | SENTOP | SENTDEHALFOP | SENTHALFOP | SENTVOICE | SENTDEVOICE); /* nick-ban or nick is +k or something? */ - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); get_user_flagrec(u, &fr, chan->dname); check_this_member(chan, m->nick, &fr); /* Make sure this is in the loop, someone could have changed the record @@ -2514,7 +2514,7 @@ static int gotquit(char *from, char *msg) chname = chan->dname; m = ismember(chan, nick); if (m) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); if (u) /* If you remove this, the bot will crash when the user record in * question is removed/modified during the tcl binds below, and the @@ -2617,7 +2617,7 @@ static int gotmsg(char *from, char *msg) 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); + u = lookup_user_record(m, NULL, from); break; } } @@ -2718,7 +2718,7 @@ static int gotnotice(char *from, char *msg) 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); + u = lookup_user_record(m, NULL, from); break; } } diff --git a/src/mod/irc.mod/cmdsirc.c b/src/mod/irc.mod/cmdsirc.c index 3b387c8f6..e32c9eaed 100644 --- a/src/mod/irc.mod/cmdsirc.c +++ b/src/mod/irc.mod/cmdsirc.c @@ -72,7 +72,7 @@ static char *getnick(char *handle, struct chanset_t *chan) memberlist *m; for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - if ((u = get_user_from_member(m)) && !strcasecmp(u->handle, handle)) + if ((u = lookup_user_record(m, NULL, NULL)) && !strcasecmp(u->handle, handle)) return m->nick; } return NULL; @@ -206,7 +206,7 @@ static void cmd_kickban(struct userrec *u, int idx, char *par) return; } egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); get_user_flagrec(u, &victim, chan->dname); if ((chan_op(victim) || (glob_op(victim) && !chan_deop(victim))) && !(chan_master(user) || glob_master(user))) { @@ -291,7 +291,7 @@ static void cmd_op(struct userrec *u, int idx, char *par) dprintf(idx, "%s is not on %s.\n", nick, chan->dname); return; } - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); get_user_flagrec(u, &victim, chan->dname); if (chan_deop(victim) || (glob_deop(victim) && !glob_op(victim))) { dprintf(idx, "%s is currently being auto-deopped.\n", m->nick); @@ -343,7 +343,7 @@ static void cmd_deop(struct userrec *u, int idx, char *par) dprintf(idx, "I'm not going to deop myself.\n"); return; } - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); get_user_flagrec(u, &victim, chan->dname); if ((chan_master(victim) || glob_master(victim)) && !(chan_owner(user) || glob_owner(user))) { @@ -379,7 +379,7 @@ static void cmd_halfop(struct userrec *u, int idx, char *par) get_user_flagrec(dcc[idx].user, &user, chan->dname); m = ismember(chan, nick); if (m && !chan_op(user) && (!glob_op(user) || chan_deop(user))) { - u2 = get_user_from_member(m); + u2 = lookup_user_record(m, NULL, NULL); if (!u2 || strcasecmp(u2->handle, dcc[idx].nick) || (!chan_halfop(user) && (!glob_halfop(user) || chan_dehalfop(user)))) { @@ -406,7 +406,7 @@ static void cmd_halfop(struct userrec *u, int idx, char *par) dprintf(idx, "%s is not on %s.\n", nick, chan->dname); return; } - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); get_user_flagrec(u, &victim, chan->dname); if (chan_dehalfop(victim) || (glob_dehalfop(victim) && !glob_halfop(victim))) { dprintf(idx, "%s is currently being auto-dehalfopped.\n", m->nick); @@ -442,7 +442,7 @@ static void cmd_dehalfop(struct userrec *u, int idx, char *par) get_user_flagrec(dcc[idx].user, &user, chan->dname); m = ismember(chan, nick); if (m && !chan_op(user) && (!glob_op(user) || chan_deop(user))) { - u2 = get_user_from_member(m); + u2 = lookup_user_record(m, NULL, NULL); if (!u2 || strcasecmp(u2->handle, dcc[idx].nick) || (!chan_halfop(user) && (!glob_halfop(user) || chan_dehalfop(user)))) { dprintf(idx, "You are not a channel op on %s.\n", chan->dname); @@ -472,7 +472,7 @@ static void cmd_dehalfop(struct userrec *u, int idx, char *par) dprintf(idx, "I'm not going to dehalfop myself.\n"); return; } - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); get_user_flagrec(u, &victim, chan->dname); if ((chan_master(victim) || glob_master(victim)) && !(chan_owner(user) || glob_owner(user))) { @@ -519,7 +519,7 @@ static void cmd_voice(struct userrec *u, int idx, char *par) * - stdarg */ if (m && !(chan_op(user) || chan_halfop(user) || (glob_op(user) && !chan_deop(user)) || (glob_halfop(user) && !chan_dehalfop(user)))) { - u2 = get_user_from_member(m); + u2 = lookup_user_record(m, NULL, NULL); if (!u2 || strcasecmp(u2->handle, dcc[idx].nick) || (!chan_voice(user) && (!glob_voice(user) || chan_quiet(user)))) { @@ -570,7 +570,7 @@ static void cmd_devoice(struct userrec *u, int idx, char *par) m = ismember(chan, nick); if (m && !(chan_op(user) || chan_halfop(user) || (glob_op(user) && !chan_deop(user)) || (glob_halfop(user) && !chan_dehalfop(user)))) { - u2 = get_user_from_member(m); + u2 = lookup_user_record(m, NULL, NULL); if (!u2 || strcasecmp(u2->handle, dcc[idx].nick) || (!chan_voice(user) && (!glob_voice(user) || chan_quiet(user)))) { @@ -645,7 +645,7 @@ static void cmd_kick(struct userrec *u, int idx, char *par) chan->dname); return; } - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); get_user_flagrec(u, &victim, chan->dname); if ((chan_op(victim) || (glob_op(victim) && !chan_deop(victim))) && !(chan_master(user) || glob_master(user))) { @@ -729,7 +729,7 @@ static void cmd_channel(struct userrec *u, int idx, char *par) for (m = chan->channel.member; m && m->nick[0]; m = m->next) { if (strlen(m->nick) > maxnicklen) maxnicklen = strlen(m->nick); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if (u && (strlen(u->handle) > maxhandlen)) maxhandlen = strlen(u->handle); } @@ -752,7 +752,7 @@ static void cmd_channel(struct userrec *u, int idx, char *par) strlcpy(s, " --- ", sizeof s); egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if (u == NULL) strlcpy(handle, "*", sizeof handle); else @@ -1003,7 +1003,7 @@ static void cmd_adduser(struct userrec *u, int idx, char *par) if (strlen(hand) > HANDLEN) hand[HANDLEN] = 0; egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if (u) { dprintf(idx, "%s is already known as %s.\n", nick, u->handle); return; @@ -1061,7 +1061,7 @@ static void cmd_deluser(struct userrec *u, int idx, char *par) return; } get_user_flagrec(u, &user, chan->dname); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if (!u) { dprintf(idx, "%s is not a valid user.\n", nick); return; diff --git a/src/mod/irc.mod/irc.c b/src/mod/irc.mod/irc.c index dc03c7f24..93b737e85 100644 --- a/src/mod/irc.mod/irc.c +++ b/src/mod/irc.mod/irc.c @@ -235,12 +235,12 @@ static void maybe_revenge(struct chanset_t *chan, char *whobad, /* Get info about offender */ badnick = splitnick(&whobad); m = ismember(chan, badnick); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); /* Get info about victim */ victim = splitnick(&whovictim); m = ismember(chan, victim); - u2 = get_user_from_member(m); + u2 = lookup_user_record(m, NULL, NULL); mevictim = match_my_nick(victim); /* Do we want to revenge? */ @@ -267,7 +267,7 @@ static int hand_on_chan(struct chanset_t *chan, struct userrec *u) memberlist *m; for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - if (u == get_user_from_member(m)) + if (u == lookup_user_record(m, NULL, NULL)) return 1; } return 0; @@ -573,7 +573,7 @@ static void check_lonely_channel(struct chanset_t *chan) chan->status |= CHAN_WHINED; } for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if (!match_my_nick(m->nick) && (!u || !(u->flags & USER_BOT))) { ok = 0; break; @@ -666,7 +666,7 @@ static void check_expired_chanstuff() for (m = chan->channel.member; m && m->nick[0]; m = m->next) if (now - m->last >= chan->idle_kick * 60 && !match_my_nick(m->nick) && !chan_issplit(m)) { - get_user_flagrec(get_user_from_member(m), &fr, chan->dname); + get_user_flagrec(lookup_user_record(m, NULL, NULL), &fr, chan->dname); if ((!(glob_bot(fr) || glob_friend(fr) || (glob_op(fr) && !chan_deop(fr)) || chan_friend(fr) || chan_op(fr))) && (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) { @@ -679,7 +679,7 @@ static void check_expired_chanstuff() for (m = chan->channel.member; m && m->nick[0]; m = n) { n = m->next; if (m->split && now - m->split > wait_split) { - check_tcl_sign(m->nick, m->userhost, get_user_from_member(m), + check_tcl_sign(m->nick, m->userhost, lookup_user_record(m, NULL, NULL), chan->dname, "lost in the netsplit"); putlog(LOG_JOIN, chan->dname, "%s (%s) got lost in the net-split.", m->nick, m->userhost); @@ -916,7 +916,7 @@ static int check_tcl_pub(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, NULL, host); hand = u ? u->handle : "*"; get_user_flagrec(u, &fr, chname); Tcl_SetVar(interp, "_pub1", nick, 0); @@ -946,7 +946,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, NULL, host); get_user_flagrec(u, &fr, chname); Tcl_SetVar(interp, "_pubm1", nick, 0); Tcl_SetVar(interp, "_pubm2", from, 0); diff --git a/src/mod/irc.mod/mode.c b/src/mod/irc.mod/mode.c index 88814d3bf..8a81fea1d 100644 --- a/src/mod/irc.mod/mode.c +++ b/src/mod/irc.mod/mode.c @@ -421,7 +421,7 @@ static void got_op(struct chanset_t *chan, char *nick, char *from, check_chan = 1; strcpy(ch, chan->name); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); get_user_flagrec(u, &victim, chan->dname); /* Flags need to be set correctly right from the beginning now, so that @@ -515,7 +515,7 @@ static void got_halfop(struct chanset_t *chan, char *nick, char *from, check_chan = 1; strcpy(ch, chan->name); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); get_user_flagrec(u, &victim, chan->dname); /* Flags need to be set correctly right from the beginning now, so that @@ -604,7 +604,7 @@ static void got_deop(struct chanset_t *chan, char *nick, char *from, strcpy(ch, chan->name); simple_sprintf(s, "%s!%s", m->nick, m->userhost); simple_sprintf(s1, "%s!%s", nick, from); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); get_user_flagrec(u, &victim, chan->dname); had_halfop = chan_hasop(m); @@ -696,7 +696,7 @@ static void got_dehalfop(struct chanset_t *chan, char *nick, char *from, strcpy(ch, chan->name); simple_sprintf(s1, "%s!%s", nick, from); - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); get_user_flagrec(u, &victim, chan->dname); had_halfop = chan_hasop(m); @@ -775,7 +775,7 @@ static void got_ban(struct chanset_t *chan, char *nick, char *from, char *who, for (m = chan->channel.member; m && m->nick[0]; m = m->next) { egg_snprintf(s1, sizeof s1, "%s!%s", m->nick, m->userhost); if (match_addr(who, s1)) { - targ = get_user_from_member(m); + targ = lookup_user_record(m, NULL, from); if (targ) { get_user_flagrec(targ, &victim, chan->dname); if ((glob_friend(victim) || (glob_op(victim) && !chan_deop(victim)) || @@ -1019,7 +1019,7 @@ static int gotmode(char *from, char *origmsg) nick = splitnick(&from); m = ismember(chan, nick); if (m) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, from); get_user_flagrec(u, &user, ch); m->last = now; } else { @@ -1243,7 +1243,7 @@ static int gotmode(char *from, char *origmsg) refresh_who_chan(chan->name); } else { simple_sprintf(s, "%s!%s", m->nick, m->userhost); - get_user_flagrec(get_user_from_member(m), &victim, chan->dname); + get_user_flagrec(lookup_user_record(m, NULL, from), &victim, chan->dname); if (ms2[0] == '+') { m->flags &= ~SENTVOICE; m->flags |= CHANVOICE; diff --git a/src/mod/irc.mod/msgcmds.c b/src/mod/irc.mod/msgcmds.c index 282687425..2baca3620 100644 --- a/src/mod/irc.mod/msgcmds.c +++ b/src/mod/irc.mod/msgcmds.c @@ -383,7 +383,8 @@ 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); - u = get_user_from_member(m); + /* Don't use s for host here, b/c if we don't have m, we won't have s */ + u = lookup_user_record(m, NULL, NULL); info = get_user(&USERENTRY_INFO, u); if (u && (u->flags & USER_BOT)) info = 0; @@ -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; @@ -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? */ @@ -462,7 +464,7 @@ static int msg_whois(char *nick, char *host, struct userrec *u, char *par) for (chan = chanset; chan && !ok; chan = chan->next) { m = ismember(chan, par); if (m) { - u2 = get_user_from_member(m); + u2 = lookup_user_record(m, NULL, uhost); if (u2) { ok = 1; dprintf(DP_HELP, "NOTICE %s :[%s] AKA '%s':\n", nick, diff --git a/src/mod/irc.mod/tclirc.c b/src/mod/irc.mod/tclirc.c index 2e27744a8..0d3c11bda 100644 --- a/src/mod/irc.mod/tclirc.c +++ b/src/mod/irc.mod/tclirc.c @@ -55,7 +55,7 @@ static int tcl_chanlist STDVAR minus.match = plus.match ^ (FR_AND | FR_OR); for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); get_user_flagrec(u, &user, argv[1]); user.match = plus.match; if (flagrec_eq(&plus, &user)) { @@ -362,7 +362,7 @@ static int tcl_handonchan STDVAR while (chan && (thechan == NULL || thechan == chan)) { for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if (u && !strcasecmp(u->handle, argv[1])) { Tcl_AppendResult(irp, "1", NULL); return TCL_OK; @@ -1046,7 +1046,7 @@ static int tcl_hand2nicks STDVAR while (chan && (thechan == NULL || thechan == chan)) { for (m = chan->channel.member; m && m->nick[0]; m = m->next) { found = 0; - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if (u && !strcasecmp(u->handle, argv[1])) { /* Is the nick of the user already in the list? */ Tcl_ListObjGetElements(irp, nicks, &nicksc, &nicksv); @@ -1087,7 +1087,7 @@ static int tcl_hand2nick STDVAR while (chan && (thechan == NULL || thechan == chan)) { for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if (u && !strcasecmp(u->handle, argv[1])) { Tcl_AppendResult(irp, m->nick, NULL); return TCL_OK; @@ -1119,7 +1119,7 @@ static int tcl_nick2hand STDVAR while (chan && (thechan == NULL || thechan == chan)) { m = ismember(chan, argv[1]); if (m) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); Tcl_AppendResult(irp, u ? u->handle : "*", NULL); return TCL_OK; } diff --git a/src/mod/module.h b/src/mod/module.h index da1651c0a..f297b0e6b 100644 --- a/src/mod/module.h +++ b/src/mod/module.h @@ -524,7 +524,7 @@ 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 */ diff --git a/src/mod/notes.mod/notes.c b/src/mod/notes.mod/notes.c index ee9a9b3e5..57dfce507 100644 --- a/src/mod/notes.mod/notes.c +++ b/src/mod/notes.mod/notes.c @@ -838,7 +838,7 @@ static void notes_hourly() for (chan = chanset; chan; chan = chan->next) { for (m = chan->channel.member; m && m->nick[0]; m = m->next) { - u = get_user_from_member(m); + u = lookup_user_record(m, NULL, NULL); if (u) { k = num_notes(u->handle); for (l = 0; l < dcc_total; l++) diff --git a/src/mod/seen.mod/seen.c b/src/mod/seen.mod/seen.c index 5dbb095da..b1039821a 100644 --- a/src/mod/seen.mod/seen.c +++ b/src/mod/seen.mod/seen.c @@ -194,7 +194,7 @@ static void do_seen(int idx, char *prefix, char *nick, char *hand, m = ismember(chan, object); if (m) { onchan = 1; - urec = get_user_from_member(m); + urec = lookup_user_record(m, NULL, NULL); if (!urec || !strcasecmp(object, urec->handle)) break; strcat(whoredirect, object); @@ -341,7 +341,7 @@ static void do_seen(int idx, char *prefix, char *nick, char *hand, if (m) { onchan = 1; snprintf(word1, sizeof word1, "%s!%s", whotarget, m->userhost); - urec = get_user_from_member(m); + urec = lookup_user_record(m, NULL, NULL); if (!urec || !strcasecmp(whotarget, urec->handle)) break; strcat(whoredirect, whotarget); @@ -358,7 +358,7 @@ static void do_seen(int idx, char *prefix, char *nick, char *hand, while (chan) { m = chan->channel.member; while (m && m->nick[0]) { - urec = get_user_from_member(m); + urec = lookup_user_record(m, NULL, NULL); if (urec && !strcasecmp(urec->handle, whotarget)) { strcat(whoredirect, whotarget); strcat(whoredirect, " is "); diff --git a/src/mod/server.mod/servmsg.c b/src/mod/server.mod/servmsg.c index 952ff70bf..551511137 100644 --- a/src/mod/server.mod/servmsg.c +++ b/src/mod/server.mod/servmsg.c @@ -670,7 +670,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(NULL, NULL, from); code = newsplit(&msg); rmspace(msg); diff --git a/src/modules.c b/src/modules.c index 61ae64716..27c69cc28 100644 --- a/src/modules.c +++ b/src/modules.c @@ -627,7 +627,7 @@ Function global_table[] = { (Function) bind_bind_entry, (Function) unbind_bind_entry, (Function) & argv0, - (Function) get_user_from_member + (Function) lookup_user_record /* 324 - 327 */ }; diff --git a/src/userrec.c b/src/userrec.c index 084dbcd64..1f21d63ef 100644 --- a/src/userrec.c +++ b/src/userrec.c @@ -255,6 +255,43 @@ struct userrec *get_user_from_member(memberlist *m) return NULL; } +/* Wrapper function to find an Eggdrop user record based on either a provided + * channel memberlist record, host, or account. This function will first check + * a provided memberlist and return the result. If no user record is found (or + * the memberlist itself was NULL), this function will try again based on a + * provided account, and then again on a provided host. + * + * When calling this function it is best to provide all available independent + * variables- ie, if you provide 'm' for the memberlist, don't provide + * 'm->account' for the account, use the independent source variable 'account' + * if available. This allows redundant checking in case of unexpected NULLs + */ +struct userrec *lookup_user_record(memberlist *m, const char *host, const char *account) +{ + struct userrec *u = NULL; + +/* First check for a user record tied to a memberlist */ + if (m) { + u = get_user_from_member(m); + if (u) { + return u; + } + } +/* Next check for a user record tied to an account */ + if (account && account[0]) { + u = get_user_by_account(account); + if (u) { + return u; + } + } +/* Last check for a user record tied to a hostmask */ + if (host && host[0]) { + u = get_user_by_host(host); + return u; + } + return NULL; +} + /* Fix capitalization, etc */ void correct_handle(char *handle) diff --git a/src/users.h b/src/users.h index a273ca95c..230580b29 100644 --- a/src/users.h +++ b/src/users.h @@ -185,6 +185,7 @@ struct userrec *get_user_by_host(char *); struct userrec *get_user_by_account(char *); struct userrec *get_user_by_nick(char *); struct userrec *get_user_from_member(memberlist *); +struct userrec *lookup_user_record(memberlist *, const char *, const char *); struct userrec *check_chanlist(const char *); /* All the default userentry stuff, for code re-use