<commit_before>/* ircd-micro, c_hunted.c -- commands with hunted parameters
   Copyright (C) 2013 <NAME>

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

#include "ircd.h"

static void m_ping(conn, msg) u_conn *conn; u_msg *msg;
{
	u_server *sv;
	u_user *u;
	char *tgt, *origin;

	if (msg->command[1] == 'O') /* user PONG */
		return;

	if (msg->argc == 1) {
		u_conn_f(conn, ":%S PONG %s :%s", &me, me.name, msg->argv[0]);
		return;
	}

	if (streq(msg->argv[1], me.name)) {
		tgt = NULL;

		if (conn->ctx == CTX_USER) {
			u = conn->priv;
			tgt = u->nick;
		} else {
			tgt = id_to_name(msg->source);
		}

		if (tgt == NULL)
			u_log(LG_ERROR, "Useless PING from %G", conn);
		else
			u_conn_f(conn, ":%S PONG %s %s", &me, me.name, tgt);

		return;
	}

	if (!(sv = u_server_by_name(msg->argv[1]))) {
		if (conn->ctx == CTX_USER)
			u_conn_num(conn, ERR_NOSUCHSERVER, msg->argv[1]);
		else
			u_log(LG_ERROR, "%G sent PING for nonexistent %s",
			      conn, msg->argv[1]);
		return;
	}

	origin = msg->source;
	if (origin == NULL || conn->ctx == CTX_USER)
		origin = conn_id(conn);

	u_conn_f(sv->conn, ":%s PING %s %s", ref_to_id(origin),
	         ref_to_name(origin), msg->argv[1]);
}

static void m_pong(conn, msg) u_conn *conn; u_msg *msg;
{
	u_server *from;
	u_conn *to;

	if (!(from = u_server_by_sid(msg->source)))
		return;

	if (streq(msg->argv[1], me.name))
		return;

	to = u_conn_by_name(msg->argv[1]);
	if (to == NULL) {
		u_log(LG_ERROR, "%G sent PONG for nonexistent %s",
		      conn, msg->argv[1]);
		return;
	}

	u_conn_f(to, ":%S PONG %s %s", from, from->name, msg->argv[1]);
}<commit_msg>Do not route PONGs back to sender.<commit_after>/* ircd-micro, c_hunted.c -- commands with hunted parameters
   Copyright (C) 2013 <NAME>

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

#include "ircd.h"

static void m_ping(conn, msg) u_conn *conn; u_msg *msg;
{
	u_server *sv;
	u_user *u;
	char *tgt, *origin;

	if (msg->command[1] == 'O') /* user PONG */
		return;

	if (msg->argc == 1) {
		u_conn_f(conn, ":%S PONG %s :%s", &me, me.name, msg->argv[0]);
		return;
	}

	if (streq(msg->argv[1], me.name)) {
		tgt = NULL;

		if (conn->ctx == CTX_USER) {
			u = conn->priv;
			tgt = u->nick;
		} else {
			tgt = id_to_name(msg->source);
		}

		if (tgt == NULL)
			u_log(LG_ERROR, "Useless PING from %G", conn);
		else
			u_conn_f(conn, ":%S PONG %s %s", &me, me.name, tgt);

		return;
	}

	if (!(sv = u_server_by_name(msg->argv[1]))) {
		if (conn->ctx == CTX_USER)
			u_conn_num(conn, ERR_NOSUCHSERVER, msg->argv[1]);
		else
			u_log(LG_ERROR, "%G sent PING for nonexistent %s",
			      conn, msg->argv[1]);
		return;
	}

	origin = msg->source;
	if (origin == NULL || conn->ctx == CTX_USER)
		origin = conn_id(conn);

	u_conn_f(sv->conn, ":%s PING %s %s", ref_to_id(origin),
	         ref_to_name(origin), msg->argv[1]);
}

static void m_pong(conn, msg) u_conn *conn; u_msg *msg;
{
	u_server *from;
	u_conn *to;

	if (!(from = u_server_by_sid(msg->source)))
		return;

	if (streq(msg->argv[1], me.name))
		return;

	to = u_conn_by_name(msg->argv[1]);
	if (to == NULL) {
		u_log(LG_ERROR, "%G sent PONG for nonexistent %s",
		      conn, msg->argv[1]);
		return;
	}

	if (from->conn == to)
		return;

	u_conn_f(to, ":%S PONG %s %s", from, from->name, msg->argv[1]);
}
{'fraction_non_alphanumeric': 0.18881325836046167, 'fraction_numerical': 0.009470257472625037, 'mean_word_length': 3.3556701030927836, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1249963', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1447, 'n_words': 362}