unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
creationtime.c (2283B)
1 /* 2 * Store creationtime in ModData 3 * (C) Copyright 2022-.. Syzop and The UnrealIRCd Team 4 * License: GPLv2 or later 5 */ 6 7 #include "unrealircd.h" 8 9 ModuleHeader MOD_HEADER 10 = { 11 "creationtime", 12 "6.1", 13 "Store and retrieve creation time of clients", 14 "UnrealIRCd Team", 15 "unrealircd-6", 16 }; 17 18 /* Forward declarations */ 19 void creationtime_free(ModData *m); 20 const char *creationtime_serialize(ModData *m); 21 void creationtime_unserialize(const char *str, ModData *m); 22 int creationtime_handshake(Client *client); 23 int creationtime_welcome_user(Client *client, int numeric); 24 int creationtime_whois(Client *client, Client *target); 25 26 ModDataInfo *creationtime_md; /* Module Data structure which we acquire */ 27 28 #define SetCreationTime(x,y) do { moddata_client(x, creationtime_md).ll = y; } while(0) 29 30 MOD_INIT() 31 { 32 ModDataInfo mreq; 33 34 MARK_AS_OFFICIAL_MODULE(modinfo); 35 36 memset(&mreq, 0, sizeof(mreq)); 37 mreq.name = "creationtime"; 38 mreq.free = creationtime_free; 39 mreq.serialize = creationtime_serialize; 40 mreq.unserialize = creationtime_unserialize; 41 mreq.self_write = 1; 42 mreq.sync = MODDATA_SYNC_EARLY; 43 mreq.type = MODDATATYPE_CLIENT; 44 creationtime_md = ModDataAdd(modinfo->handle, mreq); 45 if (!creationtime_md) 46 abort(); 47 48 /* This event sets creationtime very early: on handshake in and out */ 49 HookAdd(modinfo->handle, HOOKTYPE_HANDSHAKE, 0, creationtime_handshake); 50 HookAdd(modinfo->handle, HOOKTYPE_SERVER_HANDSHAKE_OUT, 0, creationtime_handshake); 51 52 /* And this event (re)sets it because that also happens in 53 * welcome_user() in nick.c regarding #2174 54 */ 55 HookAdd(modinfo->handle, HOOKTYPE_WELCOME, 0, creationtime_welcome_user); 56 57 return MOD_SUCCESS; 58 } 59 60 MOD_LOAD() 61 { 62 return MOD_SUCCESS; 63 } 64 65 66 MOD_UNLOAD() 67 { 68 return MOD_SUCCESS; 69 } 70 71 int creationtime_handshake(Client *client) 72 { 73 SetCreationTime(client, client->local->creationtime); 74 return 0; 75 } 76 77 int creationtime_welcome_user(Client *client, int numeric) 78 { 79 if (numeric == 0) 80 SetCreationTime(client, client->local->creationtime); 81 return 0; 82 } 83 84 void creationtime_free(ModData *m) 85 { 86 m->ll = 0; 87 } 88 89 const char *creationtime_serialize(ModData *m) 90 { 91 static char buf[64]; 92 93 snprintf(buf, sizeof(buf), "%lld", (long long)m->ll); 94 return buf; 95 } 96 97 void creationtime_unserialize(const char *str, ModData *m) 98 { 99 m->ll = atoll(str); 100 }