From ab80f8a8a01dac4fc2533ddb4ad4d0a2be8bf1da Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Sun, 10 Jun 2001 12:38:56 +0000 Subject: [PATCH] Author: Kev Log message: Changes necessary to make SETTIME always be in the priority queue. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@496 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- ChangeLog | 19 +++++++++++++++++++ include/s_user.h | 4 ++++ include/send.h | 9 ++++----- ircd/m_server.c | 6 ++++-- ircd/m_settime.c | 10 +++++----- ircd/s_user.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ ircd/send.c | 34 ++++++++++++++++++++++++++-------- 7 files changed, 108 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70ca852..0f6d246 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,24 @@ 2001-06-10 Kevin L. Mitchell + * ircd/send.c: remove unused vsendcmdto_one(), consolidating it + into sendcmdto_one(); define new sendcmdto_prio_one(), which + places the message into the priority queue + + * ircd/s_user.c (hunt_server_prio_cmd): definition of + hunt_server_prio_cmd(), which simply calls sendcmdto_prio_one() + instead of sendcmdto_one() + + * ircd/m_settime.c: use sendcmdto_prio_one() and + hunt_server_prio_cmd() to send SETTIME + + * ircd/m_server.c: use sendcmdto_prio_one() to send SETTIME + + * include/send.h: removed declaration for unused vsendcmdto_one(); + added a declaration for sendcmdto_prio_one() + + * include/s_user.h: declare hunt_server_prio_cmd(), which calls + sendcmdto_prio_one() + * ircd/send.c (sendcmdto_flag_butone): oops; /wallops should be put in the server's priority queue, too... diff --git a/include/s_user.h b/include/s_user.h index 296d819..7de772a 100644 --- a/include/s_user.h +++ b/include/s_user.h @@ -81,6 +81,10 @@ extern int hunt_server_cmd(struct Client *from, const char *cmd, const char *tok, struct Client *one, int MustBeOper, const char *pattern, int server, int parc, char *parv[]); +extern int hunt_server_prio_cmd(struct Client *from, const char *cmd, + const char *tok, struct Client *one, + int MustBeOper, const char *pattern, + int server, int parc, char *parv[]); extern struct Client* next_client(struct Client* next, const char* ch); extern char *umode_str(struct Client *cptr); extern void send_umode(struct Client *cptr, struct Client *sptr, int old, int sendmask); diff --git a/include/send.h b/include/send.h index ca83b50..8e62ca3 100644 --- a/include/send.h +++ b/include/send.h @@ -33,11 +33,10 @@ extern void sendcmdto_one(struct Client *from, const char *cmd, const char *tok, struct Client *to, const char *pattern, ...); - -/* Same as above, except it takes a va_list */ -extern void vsendcmdto_one(struct Client *from, const char *cmd, - const char *tok, struct Client *to, - const char *pattern, va_list vl); +/* Same as above, except it puts the message on the priority queue */ +extern void sendcmdto_prio_one(struct Client *from, const char *cmd, + const char *tok, struct Client *to, + const char *pattern, ...); /* Send command to all servers except one */ extern void sendcmdto_serv_butone(struct Client *from, const char *cmd, diff --git a/ircd/m_server.c b/ircd/m_server.c index 0ddd244..56ce072 100644 --- a/ircd/m_server.c +++ b/ircd/m_server.c @@ -759,7 +759,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) "timestamp-clock difference of %Td seconds! " "Used SETTIME to correct this.", timestamp - recv_time); - sendcmdto_one(&me, CMD_SETTIME, cptr, "%Tu :%s", TStime(), cli_name(&me)); + sendcmdto_prio_one(&me, CMD_SETTIME, cptr, "%Tu :%s", TStime(), + cli_name(&me)); } return ret; @@ -1391,7 +1392,8 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) sendto_opmask_butone(0, SNO_OLDSNO, "Connected to a net with a " "timestamp-clock difference of %Td seconds! Used " "SETTIME to correct this.", timestamp - recv_time); - sendcmdto_one(&me, CMD_SETTIME, cptr, "%Tu :%s", TStime(), cli_name(&me)); + sendcmdto_prio_one(&me, CMD_SETTIME, cptr, "%Tu :%s", TStime(), + cli_name(&me)); } return ret; diff --git a/ircd/m_settime.c b/ircd/m_settime.c index 0847261..e1cfa05 100644 --- a/ircd/m_settime.c +++ b/ircd/m_settime.c @@ -154,8 +154,8 @@ int ms_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime()); parv[1] = tbuf; - if (hunt_server_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, parv) != - HUNTED_ISME) + if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, + parv) != HUNTED_ISME) return 0; } @@ -224,14 +224,14 @@ int mo_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) for (lp = cli_serv(&me)->down; lp; lp = lp->next) if (cptr != lp->value.cptr && MsgQLength(&(cli_sendQ(lp->value.cptr))) < 8000) - sendcmdto_one(sptr, CMD_SETTIME, lp->value.cptr, "%s", parv[1]); + sendcmdto_prio_one(sptr, CMD_SETTIME, lp->value.cptr, "%s", parv[1]); } else { ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime()); parv[1] = tbuf; - if (hunt_server_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, parv) != - HUNTED_ISME) + if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, + parv) != HUNTED_ISME) return 0; } diff --git a/ircd/s_user.c b/ircd/s_user.c index 78d94cf..3887a99 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -229,6 +229,52 @@ int hunt_server_cmd(struct Client *from, const char *cmd, const char *tok, return (HUNTED_PASS); } +int hunt_server_prio_cmd(struct Client *from, const char *cmd, const char *tok, + struct Client *one, int MustBeOper, + const char *pattern, int server, int parc, + char *parv[]) +{ + struct Client *acptr; + char *to; + + /* Assume it's me, if no server or an unregistered client */ + if (parc <= server || EmptyString((to = parv[server])) || IsUnknown(from)) + return (HUNTED_ISME); + + /* Make sure it's a server */ + if (MyUser(from)) { + /* Make sure it's a server */ + if (!strchr(to, '*')) { + if (0 == (acptr = FindClient(to))) + return HUNTED_NOSUCH; + + if (cli_user(acptr)) + acptr = cli_user(acptr)->server; + } else if (!(acptr = find_match_server(to))) { + send_reply(from, ERR_NOSUCHSERVER, to); + return (HUNTED_NOSUCH); + } + } else if (!(acptr = FindNServer(to))) + return (HUNTED_NOSUCH); /* Server broke off in the meantime */ + + if (IsMe(acptr)) + return (HUNTED_ISME); + + if (MustBeOper && !IsPrivileged(from)) { + send_reply(from, ERR_NOPRIVILEGES); + return HUNTED_NOSUCH; + } + + assert(!IsServer(from)); + + parv[server] = (char *) acptr; /* HACK! HACK! HACK! ARGH! */ + + sendcmdto_prio_one(from, cmd, tok, acptr, pattern, parv[1], parv[2], parv[3], + parv[4], parv[5], parv[6], parv[7], parv[8]); + + return (HUNTED_PASS); +} + /* * 'do_nick_name' ensures that the given parameter (nick) is really a proper * string for a nickname (note, the 'nick' may be modified in the process...) diff --git a/ircd/send.c b/ircd/send.c index cce22b1..3c60223 100644 --- a/ircd/send.c +++ b/ircd/send.c @@ -253,15 +253,31 @@ void sendrawto_one(struct Client *to, const char *pattern, ...) void sendcmdto_one(struct Client *from, const char *cmd, const char *tok, struct Client *to, const char *pattern, ...) { - va_list vl; + struct VarData vd; + struct MsgBuf *mb; - va_start(vl, pattern); - vsendcmdto_one(from, cmd, tok, to, pattern, vl); - va_end(vl); + to = cli_from(to); + + vd.vd_format = pattern; /* set up the struct VarData for %v */ + va_start(vd.vd_args, pattern); + + mb = msgq_make(to, "%:#C %s %v", from, IsServer(to) || IsMe(to) ? tok : cmd, + &vd); + + va_end(vd.vd_args); + + send_buffer(to, mb, 0); + + msgq_clean(mb); } -void vsendcmdto_one(struct Client *from, const char *cmd, const char *tok, - struct Client *to, const char *pattern, va_list vl) +/* + * Send a (prefixed) command to a single client in the priority queue; + * select which of to use depending on if to is a server + *or not. is the originator of the command. + */ +void sendcmdto_prio_one(struct Client *from, const char *cmd, const char *tok, + struct Client *to, const char *pattern, ...) { struct VarData vd; struct MsgBuf *mb; @@ -269,12 +285,14 @@ void vsendcmdto_one(struct Client *from, const char *cmd, const char *tok, to = cli_from(to); vd.vd_format = pattern; /* set up the struct VarData for %v */ - vd.vd_args = vl; + va_start(vd.vd_args, pattern); mb = msgq_make(to, "%:#C %s %v", from, IsServer(to) || IsMe(to) ? tok : cmd, &vd); - send_buffer(to, mb, 0); + va_end(vd.vd_args); + + send_buffer(to, mb, 1); msgq_clean(mb); } -- 2.20.1