<commit_before>/* ircd-micro, pseudoclient.c -- server pseudoclient
   Copyright (C) 2014 <NAME>

   This file is protected under the terms contained
   in the COPYING file in the project root */

#include "ircd.h"

static u_user_local *pseudo = NULL;

static void pseudo_nick(char *nick)
{
	u_user *u = USER(pseudo);

	if (!strcmp(u->nick, nick))
		return;

	u_sendto_visible(u, ST_USERS, ":%H NICK :%s", u, nick);
	u_roster_f(R_SERVERS, NULL, ":%H NICK %s %u", u, nick, 0);

	u_user_set_nick(USER(pseudo), nick, 0);

	u_hook_call("pseudoclient:update", pseudo);
}

static void pseudo_quit(const char *reason)
{
	u_user *u = USER(pseudo);

	u_sendto_visible(u, ST_USERS, ":%H QUIT :%s", u, reason);
	u_roster_f(R_SERVERS, NULL, ":%H QUIT :%s", u, reason);

	u_hook_call("pseudoclient:destroy", pseudo);

	u_user_unlink(USER(pseudo));
}

static void try_add_pseudo(void)
{
	if (pseudo || !me.sid[0] || !me.name[0])
		return;

	pseudo = u_user_local_create("127.0.0.1", me.name);
	strcpy(pseudo->user.ident, "ircd");
	strcpy(pseudo->user.gecos, "IRCD pseudoclient");
	u_user_set_nick(USER(pseudo), me.sid, 0);
	u_strlcpy(pseudo->user.host, me.name, MAXHOST+1);

	u_hook_call("pseudoclient:create", pseudo);
}

static void *on_conf_end(void *a, void *b)
{
	try_add_pseudo();

	if (pseudo && strcmp(me.sid, pseudo->user.nick))
		pseudo_nick(me.sid);
}

static int pseudoclient_init(u_module *m)
{
	try_add_pseudo();

	u_hook_add(HOOK_CONF_END, on_conf_end, NULL);
}

static void pseudoclient_deinit(u_module *m)
{
	if (pseudo != NULL) {
		pseudo_quit("Module unloaded");
		pseudo = NULL;
	}
}

MICRO_MODULE_V1(
	"extra/pseudoclient",
	"<NAME> <http://github.com/aji>",
	"IRCD pseudoclient",

	pseudoclient_init,
	pseudoclient_deinit<commit_msg>extra/pseudoclient: Use SID-nick as pseudoclient nickname<commit_after>/* ircd-micro, pseudoclient.c -- server pseudoclient
   Copyright (C) 2014 <NAME>

   This file is protected under the terms contained
   in the COPYING file in the project root */

#include "ircd.h"

static u_user_local *pseudo = NULL;

static char *pseudo_create_nick(void)
{
	static char buf[10];
	snprintf(buf, 10, "%s-ircd", me.sid);
	return buf;
}

static void pseudo_nick(char *nick)
{
	u_user *u = USER(pseudo);

	if (!strcmp(u->nick, nick))
		return;

	u_sendto_visible(u, ST_USERS, ":%H NICK :%s", u, nick);
	u_roster_f(R_SERVERS, NULL, ":%H NICK %s %u", u, nick, 0);

	u_user_set_nick(USER(pseudo), nick, 0);

	u_hook_call("pseudoclient:update", pseudo);
}

static void pseudo_quit(const char *reason)
{
	u_user *u = USER(pseudo);

	u_sendto_visible(u, ST_USERS, ":%H QUIT :%s", u, reason);
	u_roster_f(R_SERVERS, NULL, ":%H QUIT :%s", u, reason);

	u_hook_call("pseudoclient:destroy", pseudo);

	u_user_unlink(USER(pseudo));
}

static void try_add_pseudo(void)
{
	if (pseudo || !me.sid[0] || !me.name[0])
		return;

	pseudo = u_user_local_create("127.0.0.1", me.name);
	strcpy(pseudo->user.ident, "ircd");
	strcpy(pseudo->user.gecos, "IRCD pseudoclient");
	u_user_set_nick(USER(pseudo), pseudo_create_nick(), 0);
	u_strlcpy(pseudo->user.host, me.name, MAXHOST+1);

	u_hook_call("pseudoclient:create", pseudo);
}

static void *on_conf_end(void *a, void *b)
{
	char *nick;

	try_add_pseudo();

	nick = pseudo_create_nick();
	if (pseudo && strcmp(nick, pseudo->user.nick))
		pseudo_nick(nick);
}

static int pseudoclient_init(u_module *m)
{
	try_add_pseudo();

	u_hook_add(HOOK_CONF_END, on_conf_end, NULL);
}

static void pseudoclient_deinit(u_module *m)
{
	if (pseudo != NULL) {
		pseudo_quit("Module unloaded");
		pseudo = NULL;
	}
}

MICRO_MODULE_V1(
	"extra/pseudoclient",
	"<NAME> <http://github.com/aji>",
	"IRCD pseudoclient",

	pseudoclient_init,
	pseudoclient_deinit
{'fraction_non_alphanumeric': 0.16012983500135244, 'fraction_numerical': 0.010278604273735462, 'mean_word_length': 5.321367521367521, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '215448', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1547, 'n_words': 322}