Browse Source

Communicate "creationtime" of users. Right now this info is only known

locally, as the only timestamp regarding users that is communicated across
the network is about the "last nick change" ("has this nick since...").
pull/48/head
Bram Matthys 2 months ago
parent
commit
f1a18ce37e
No known key found for this signature in database
GPG Key ID: BF8116B163EAAE98
  1. 4
      Makefile.windows
  2. 1
      doc/conf/modules.default.conf
  3. 1
      include/struct.h
  4. 2
      src/modules/Makefile.in
  5. 99
      src/modules/creationtime.c
  6. 19
      src/modules/nick.c

4
Makefile.windows

@ -254,6 +254,7 @@ DLL_FILES=\
src/modules/close.dll \
src/modules/connect.dll \
src/modules/connthrottle.dll \
src/modules/creationtime.dll \
src/modules/cycle.dll \
src/modules/dccallow.dll \
src/modules/dccdeny.dll \
@ -831,6 +832,9 @@ src/modules/connect.dll: src/modules/connect.c $(INCLUDES)
src/modules/connthrottle.dll: src/modules/connthrottle.c $(INCLUDES)
$(CC) $(MODCFLAGS) src/modules/connthrottle.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/connthrottle.pdb $(MODLFLAGS)
src/modules/creationtime.dll: src/modules/creationtime.c $(INCLUDES)
$(CC) $(MODCFLAGS) src/modules/creationtime.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/creationtime.pdb $(MODLFLAGS)
src/modules/cycle.dll: src/modules/cycle.c $(INCLUDES)
$(CC) $(MODCFLAGS) src/modules/cycle.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/cycle.pdb $(MODLFLAGS)

1
doc/conf/modules.default.conf

@ -117,6 +117,7 @@ loadmodule "umode2";
loadmodule "sinfo";
loadmodule "require-module";
loadmodule "slog";
loadmodule "creationtime";
loadmodule "unreal_server_compat";
// Services commands

1
include/struct.h

@ -609,6 +609,7 @@ union ModData
{
int i;
long l;
long long ll;
char *str;
void *ptr;
};

2
src/modules/Makefile.in

@ -76,7 +76,7 @@ MODULES= \
typing-indicator.so channel-context.so \
ident_lookup.so history.so chathistory.so \
targetfloodprot.so clienttagdeny.so watch-backend.so \
monitor.so slog.so tls_cipher.so operinfo.so \
monitor.so slog.so tls_cipher.so operinfo.so creationtime.so \
unreal_server_compat.so \
extended-monitor.so geoip_csv.so \
geoip_base.so extjwt.so \

99
src/modules/creationtime.c

@ -0,0 +1,99 @@
/*
* Store creationtime in ModData
* (C) Copyright 2022-.. Syzop and The UnrealIRCd Team
* License: GPLv2 or later
*/
#include "unrealircd.h"
ModuleHeader MOD_HEADER
= {
"creationtime",
"6.0",
"Store and retrieve creation time of clients",
"UnrealIRCd Team",
"unrealircd-6",
};
/* Forward declarations */
void creationtime_free(ModData *m);
const char *creationtime_serialize(ModData *m);
void creationtime_unserialize(const char *str, ModData *m);
int creationtime_handshake(Client *client);
int creationtime_welcome_user(Client *client, int numeric);
int creationtime_whois(Client *client, Client *target);
ModDataInfo *creationtime_md; /* Module Data structure which we acquire */
#define SetCreationTime(x,y) do { moddata_client(x, creationtime_md).ll = y; } while(0)
MOD_INIT()
{
ModDataInfo mreq;
MARK_AS_OFFICIAL_MODULE(modinfo);
memset(&mreq, 0, sizeof(mreq));
mreq.name = "creationtime";
mreq.free = creationtime_free;
mreq.serialize = creationtime_serialize;
mreq.unserialize = creationtime_unserialize;
mreq.sync = MODDATA_SYNC_EARLY;
mreq.type = MODDATATYPE_CLIENT;
creationtime_md = ModDataAdd(modinfo->handle, mreq);
if (!creationtime_md)
abort();
/* This event sets creationtime very early: on handshake in and out */
HookAdd(modinfo->handle, HOOKTYPE_HANDSHAKE, 0, creationtime_handshake);
HookAdd(modinfo->handle, HOOKTYPE_SERVER_HANDSHAKE_OUT, 0, creationtime_handshake);
/* And this event (re)sets it because that also happens in
* welcome_user() in nick.c regarding #2174
*/
HookAdd(modinfo->handle, HOOKTYPE_WELCOME, 0, creationtime_welcome_user);
return MOD_SUCCESS;
}
MOD_LOAD()
{
return MOD_SUCCESS;
}
MOD_UNLOAD()
{
return MOD_SUCCESS;
}
int creationtime_handshake(Client *client)
{
SetCreationTime(client, client->local->creationtime);
return 0;
}
int creationtime_welcome_user(Client *client, int numeric)
{
if (numeric == 0)
SetCreationTime(client, client->local->creationtime);
return 0;
}
void creationtime_free(ModData *m)
{
m->ll = 0;
}
const char *creationtime_serialize(ModData *m)
{
static char buf[64];
snprintf(buf, sizeof(buf), "%lld", (long long)m->ll);
return buf;
}
void creationtime_unserialize(const char *str, ModData *m)
{
m->ll = atoll(str);
}

19
src/modules/nick.c

@ -758,11 +758,21 @@ CMD_FUNC(cmd_nick)
}
}
/** Welcome the user on IRC.
* Send the RPL_WELCOME, LUSERS, MOTD, auto join channels, everything...
*/
void welcome_user(Client *client, TKL *viruschan_tkl)
{
int i;
ConfigItem_tld *tlds;
/* Make creation time the real 'online since' time, excluding registration time.
* Otherwise things like set::anti-spam-quit-messagetime 10s could mean
* 1 second in practice (#2174).
*/
client->local->creationtime = TStime();
client->local->idle_since = TStime();
RunHook(HOOKTYPE_WELCOME, client, 0);
sendnumeric(client, RPL_WELCOME, NETWORK_NAME, client->name, client->user->username, client->user->realhost);
@ -826,10 +836,13 @@ void welcome_user(Client *client, TKL *viruschan_tkl)
sendto_serv_butone_nickcmd(client->direction, NULL, client, (*buf == '\0' ? "+" : buf));
broadcast_moddata_client(client);
RunHook(HOOKTYPE_LOCAL_CONNECT, client);
if (buf[0] != '\0' && buf[1] != '\0')
sendto_one(client, NULL, ":%s MODE %s :%s", client->name,
client->name, buf);
if (client->user->snomask)
sendnumeric(client, RPL_SNOMASK, client->user->snomask);
@ -839,12 +852,6 @@ void welcome_user(Client *client, TKL *viruschan_tkl)
if (IsSecure(client) && (iConf.outdated_tls_policy_user == POLICY_WARN) && outdated_tls_client(client))
sendnotice(client, "%s", outdated_tls_client_build_string(iConf.outdated_tls_policy_user_message, client));
/* Make creation time the real 'online since' time, excluding registration time.
* Otherwise things like set::anti-spam-quit-messagetime 10s could mean
* 1 second in practice (#2174).
*/
client->local->creationtime = TStime();
client->local->idle_since = TStime();
/* 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.

Loading…
Cancel
Save