Skip to content

Commit

Permalink
Drop RPL_WHOWASIP; rename historical to whowas
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsOnlyBinary committed Aug 29, 2024
1 parent b9d4fd7 commit 51a97ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
37 changes: 10 additions & 27 deletions src/commands/handlers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ const handlers = {
// Hence if we already find something we are receiving older data and need to make sure that we
// store anything already in the cache into its own entry
const whowas_cache = handler.cache('whowas.' + cache_key);
if (!whowas_cache.historical) {
if (!whowas_cache.whowas) {
// this will get populated by the next RPL_WHOWASUSER or RPL_ENDOFWHOWAS
whowas_cache.historical = [];
whowas_cache.whowas = [];
} else {
// push the previous event prior to modifying anything
whowas_cache.historical.push(_.cloneDeep(whois_cache));
whowas_cache.whowas.push(_.cloneDeep(whois_cache));
// ensure we are starting with a clean cache for the next data
whois_cache.destroy();
whois_cache = handler.cache('whois.' + cache_key);
Expand All @@ -351,22 +351,6 @@ const handlers = {
whois_cache.real_name = command.params[command.params.length - 1];
},

RPL_WHOWASIP: function(command, handler) {
const cache_key = command.params[1].toLowerCase();
const cache = handler.cache('whois.' + cache_key);

const param_tokens = (command.params[command.params.length - 1] || '').split(' ');
const user_host = param_tokens[param_tokens.length - 1];
const mask_sep = user_host.indexOf('@');
const user = user_host.substring(0, mask_sep) || undefined;
const host = user_host.substring(mask_sep + 1);

if (host) {
cache.actual_username = user;
cache.actual_username = host;
}
},

RPL_ENDOFWHOWAS: function(command, handler) {
// Because the WHOIS and WHOWAS numerics clash with eachother,
// a cache key will have more than what is just in RPL_WHOWASUSER.
Expand All @@ -383,16 +367,15 @@ const handlers = {

// after all prior RPL_WHOWASUSER pushed newer events onto the history stack
// push the last one to complete the set (server returns from newest to oldest)
if (!whowas_cache.historical) {
whowas_cache.historical = [];
if (!whois_cache.error) {
whowas_cache.whowas = whowas_cache.whowas || [];
whowas_cache.whowas.push(_.cloneDeep(whois_cache));
Object.assign(whowas_cache, _.cloneDeep(whowas_cache.whowas[0]));
} else {
Object.assign(whowas_cache, _.cloneDeep(whois_cache));
}
whowas_cache.historical.push(_.cloneDeep(whois_cache));

// now pull the newest response to the top level and add the rest as an array
const event = _.cloneDeep(whowas_cache.historical[0]);
event.historical = whowas_cache.historical;

handler.emit('whowas', event);
handler.emit('whowas', whowas_cache);
whois_cache.destroy();
whowas_cache.destroy();
},
Expand Down
1 change: 0 additions & 1 deletion src/commands/numerics.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ module.exports = {
'531': 'ERR_CANNOTSENDTOUSER',
/* InspIRCD specific https://github.com/inspircd/inspircd-contrib/blob/master/3.0/m_asn.cpp */
'569': 'RPL_WHOISASN',
'652': 'RPL_WHOWASIP',
'670': 'RPL_STARTTLS',
'671': 'RPL_WHOISSECURE',
'704': 'RPL_HELPSTART',
Expand Down

0 comments on commit 51a97ca

Please sign in to comment.