<commit_before>-module(pre_client_hooks).

-include("log.hrl").
-include("pre_client.hrl").

-export([register_hooks/0, client_login_hook/2, client_ping_request_hook/5]).

%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------

register_hooks() ->
	?debug("Registering client hooks."),
	pre_hooks:add_hook(client_logged_in, ?MODULE, client_login_hook, undefined, [node()]),
	pre_hooks:add_hook(client_request_received, ?MODULE, client_ping_request_hook, undefined, [node()]).

%% ------------------------------------------------------------------

client_login_hook(undefined, ClientRecord) ->
	?debug("Client logged in: ~p", [ClientRecord]),
	#client_info{connection = Connection} = ClientRecord,
	LevelUrl = <<"scenes/cnk.json">>,
	LoadLevel = {struct, [
		{type, <<"setZone">>},
		{level, LevelUrl}
	]},
	pre_client_connection:send(Connection, tcp, event, level, LoadLevel),
	{ok, undefined}.

client_ping_request_hook(undefined, <<"ping">>, <<"ping">>, Envelope, ClientRecord) ->
	?debug("Servicing ping request! YAY!"),
	#client_info{connection = Connection} = ClientRecord,
	{MegaSecs, Secs, MicroSecs} = now(),
	Timestamp = MegaSecs * 1000000 + Secs + MicroSecs / 1000000,
	PingResponse = {struct, [
		{confirm, true},
		{timestamp, Timestamp}
	]},
	#envelope{channel = Channel, id = MsgID} = Envelope,
	pre_client_connection:send(Connection, tcp, {response, MsgID}, Channel, PingResponse),
	{ok, undefined};

client_ping_request_hook(_HookInfo, _RequestType, _Channel, _Envelope, _ClientRecord) ->
	not_handled.<commit_msg>Corrected level URL sent at login.<commit_after>-module(pre_client_hooks).

-include("log.hrl").
-include("pre_client.hrl").

-export([register_hooks/0, client_login_hook/2, client_ping_request_hook/5]).

%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------

register_hooks() ->
	?debug("Registering client hooks."),
	pre_hooks:add_hook(client_logged_in, ?MODULE, client_login_hook, undefined, [node()]),
	pre_hooks:add_hook(client_request_received, ?MODULE, client_ping_request_hook, undefined, [node()]).

%% ------------------------------------------------------------------

client_login_hook(undefined, ClientRecord) ->
	?debug("Client logged in: ~p", [ClientRecord]),
	#client_info{connection = Connection} = ClientRecord,
	LevelUrl = <<"zones/test/TestArea.json">>,
	LoadLevel = {struct, [
		{type, <<"setZone">>},
		{level, LevelUrl}
	]},
	pre_client_connection:send(Connection, tcp, event, level, LoadLevel),
	{ok, undefined}.

client_ping_request_hook(undefined, <<"ping">>, <<"ping">>, Envelope, ClientRecord) ->
	?debug("Servicing ping request! YAY!"),
	#client_info{connection = Connection} = ClientRecord,
	{MegaSecs, Secs, MicroSecs} = now(),
	Timestamp = MegaSecs * 1000000 + Secs + MicroSecs / 1000000,
	PingResponse = {struct, [
		{confirm, true},
		{timestamp, Timestamp}
	]},
	#envelope{channel = Channel, id = MsgID} = Envelope,
	pre_client_connection:send(Connection, tcp, {response, MsgID}, Channel, PingResponse),
	{ok, undefined};

client_ping_request_hook(_HookInfo, _RequestType, _Channel, _Envelope, _ClientRecord) ->
	not_handled.
{'fraction_non_alphanumeric': 0.2616033755274262, 'fraction_numerical': 0.010247136829415311, 'mean_word_length': 3.2881136950904395, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, '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': '323950', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1021, 'n_words': 194}