From 4dbc2ac860d893a2a21a7111ad746bb587c978c8 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Tue, 10 Aug 2021 12:26:19 +0200 Subject: [PATCH] Rename client->local->since to client->local->fake_lag, since it is used for fake lag calculations only (well, except for 1 corner case). As said, modules should use the new function: void add_fake_lag(Client *client, long msec) --- include/struct.h | 4 ++-- src/ircd.c | 8 ++++---- src/list.c | 2 +- src/modules/nick.c | 4 ++-- src/modules/sasl.c | 2 +- src/modules/stats.c | 2 +- src/parse.c | 16 ++++++++-------- src/serv.c | 2 +- src/socket.c | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/struct.h b/include/struct.h index 18ea39e36..59ada40fc 100644 --- a/include/struct.h +++ b/include/struct.h @@ -1342,8 +1342,8 @@ struct Client { struct LocalClient { int fd; /**< File descriptor, can be <0 if socket has been closed already. */ SSL *ssl; /**< OpenSSL/LibreSSL struct for TLS connection */ - time_t since; /**< Time when user will next be allowed to send something (actually sincelocal->lasttime) >= (2 * ping))) || /* Or isn't registered and time spent is larger than ping (CONNECTTIMEOUT).. */ - (!IsRegistered(client) && (TStime() - client->local->since >= ping)) + (!IsRegistered(client) && (TStime() - client->local->fake_lag >= ping)) ) { if (IsServer(client) || IsConnecting(client) || @@ -517,8 +517,8 @@ void fix_timers(void) list_for_each_entry(client, &lclient_list, lclient_node) { - if (client->local->since > TStime()) - client->local->since = TStime(); + if (client->local->fake_lag > TStime()) + client->local->fake_lag = TStime(); if (client->local->lasttime > TStime()) client->local->lasttime = TStime(); if (client->local->last > TStime()) @@ -1140,7 +1140,7 @@ int InitUnrealIRCd(int argc, char *argv[]) me_hash = find_or_add(me.name); me.serv->up = me_hash; timeofday = time(NULL); - me.local->lasttime = me.local->since = me.local->firsttime = me.serv->boottime = TStime(); + me.local->lasttime = me.local->fake_lag = me.local->firsttime = me.serv->boottime = TStime(); me.serv->features.protocol = UnrealProtocol; safe_strdup(me.serv->features.software, version); add_to_client_hash_table(me.name, &me); diff --git a/src/list.c b/src/list.c index b0543e072..d2271fa5a 100644 --- a/src/list.c +++ b/src/list.c @@ -123,7 +123,7 @@ Client *make_client(Client *from, Client *servr) INIT_LIST_HEAD(&client->lclient_node); INIT_LIST_HEAD(&client->special_node); - client->local->since = client->local->lasttime = + client->local->fake_lag = client->local->lasttime = client->lastnick = client->local->firsttime = client->local->last = TStime(); client->local->class = NULL; diff --git a/src/modules/nick.c b/src/modules/nick.c index 3588ebcdd..74e6f744a 100644 --- a/src/modules/nick.c +++ b/src/modules/nick.c @@ -319,7 +319,7 @@ CMD_FUNC(cmd_nick_local) } if (!ValidatePermissionsForPath("immune:nick-flood",client,NULL,NULL,NULL)) - cptr->local->since += 3; /* Nick-flood prot. -Donwulff */ + cptr->local->fake_lag += 3; /* Nick-flood prot. -Donwulff */ if ((acptr = find_client(nick, NULL))) { @@ -1128,7 +1128,7 @@ int _register_user(Client *client, char *nick, char *username, char *umode, char /* Give the user a fresh start as far as fake-lag is concerned. * Otherwise the user could be lagged up already due to all the CAP stuff. */ - client->local->since = TStime(); + client->local->fake_lag = TStime(); RunHook2(HOOKTYPE_WELCOME, client, 999); diff --git a/src/modules/sasl.c b/src/modules/sasl.c index b41133f56..d30f5e2c2 100644 --- a/src/modules/sasl.c +++ b/src/modules/sasl.c @@ -179,7 +179,7 @@ CMD_FUNC(cmd_sasl) if (*parv[4] == 'F') { target->local->sasl_sent_time = 0; - target->local->since += 7; /* bump fakelag due to failed authentication attempt */ + target->local->fake_lag += 7; /* bump fakelag due to failed authentication attempt */ RunHookReturn2(HOOKTYPE_SASL_RESULT, target, 0, !=0); sendnumeric(target, ERR_SASLFAIL); } diff --git a/src/modules/stats.c b/src/modules/stats.c index d05d024cf..328ff382e 100644 --- a/src/modules/stats.c +++ b/src/modules/stats.c @@ -971,7 +971,7 @@ int stats_uptime(Client *client, char *para) { time_t tmpnow; - tmpnow = TStime() - me.local->since; + tmpnow = TStime() - me.local->fake_lag; sendnumeric(client, RPL_STATSUPTIME, tmpnow / 86400, (tmpnow / 3600) % 24, (tmpnow / 60) % 60, tmpnow % 60); diff --git a/src/parse.c b/src/parse.c index 16097295f..b59e45c06 100644 --- a/src/parse.c +++ b/src/parse.c @@ -338,7 +338,7 @@ static void parse2(Client *cptr, Client **fromptr, MessageTag *mtags, int mtags_ if (*ch == '\0') { if (!IsServer(cptr)) - cptr->local->since++; /* 1s fake lag */ + cptr->local->fake_lag++; /* 1s fake lag */ return; } @@ -588,13 +588,13 @@ void parse_addlag(Client *client, int command_bytes, int mtags_bytes) int lag_penalty = settings->period[FLD_LAG_PENALTY]; int lag_penalty_bytes = settings->limit[FLD_LAG_PENALTY]; - client->local->since_msec += (1 + (command_bytes/lag_penalty_bytes) + (mtags_bytes/lag_penalty_bytes)) * lag_penalty; + client->local->fake_lag_msec += (1 + (command_bytes/lag_penalty_bytes) + (mtags_bytes/lag_penalty_bytes)) * lag_penalty; /* This code takes into account not only the msecs we just calculated * but also any leftover msec from previous lagging up. */ - client->local->since += (client->local->since_msec / 1000); - client->local->since_msec = client->local->since_msec % 1000; + client->local->fake_lag += (client->local->fake_lag_msec / 1000); + client->local->fake_lag_msec = client->local->fake_lag_msec % 1000; } } @@ -605,9 +605,9 @@ void add_fake_lag(Client *client, long msec) if (!MyConnect(client)) return; - client->local->since_msec += msec; - client->local->since += (client->local->since_msec / 1000); - client->local->since_msec = client->local->since_msec % 1000; + client->local->fake_lag_msec += msec; + client->local->fake_lag += (client->local->fake_lag_msec / 1000); + client->local->fake_lag_msec = client->local->fake_lag_msec % 1000; } /** Returns 1 if the client is lagged up and data should NOT be parsed. @@ -623,7 +623,7 @@ static int client_lagged_up(Client *client) return 0; if (ValidatePermissionsForPath("immune:lag",client,NULL,NULL,NULL)) return 0; - if (client->local->since - TStime() < 10) + if (client->local->fake_lag - TStime() < 10) return 0; return 1; } diff --git a/src/serv.c b/src/serv.c index cba196050..82811e4f6 100644 --- a/src/serv.c +++ b/src/serv.c @@ -219,7 +219,7 @@ void send_proto(Client *client, ConfigItem_link *aconf) /* Second line */ sendto_one(client, NULL, "PROTOCTL CHANMODES=%s%s,%s%s,%s%s,%s%s USERMODES=%s BOOTED=%lld PREFIX=%s SID=%s MLOCK TS=%lld EXTSWHOIS", CHPAR1, EXPAR1, CHPAR2, EXPAR2, CHPAR3, EXPAR3, CHPAR4, EXPAR4, - umodestring, (long long)me.local->since, prefix->value, + umodestring, (long long)me.local->fake_lag, prefix->value, me.id, (long long)TStime()); /* Third line */ diff --git a/src/socket.c b/src/socket.c index db6c5d548..6d6e822c3 100644 --- a/src/socket.c +++ b/src/socket.c @@ -993,8 +993,8 @@ void read_packet(int fd, int revents, void *data) } client->local->lasttime = now; - if (client->local->lasttime > client->local->since) - client->local->since = client->local->lasttime; + if (client->local->lasttime > client->local->fake_lag) + client->local->fake_lag = client->local->lasttime; /* FIXME: Is this correct? I have my doubts. */ ClearPingSent(client);