<commit_before>%% @author <NAME> <<EMAIL>>
%% @copyright 2010 <NAME>.
%% @doc Login and game servers low-level network handling.
%%
%%	This file is part of EGS.
%%
%%	EGS is free software: you can redistribute it and/or modify
%%	it under the terms of the GNU Affero General Public License as
%%	published by the Free Software Foundation, either version 3 of the
%%	License, or (at your option) any later version.
%%
%%	EGS is distributed in the hope that it will be useful,
%%	but WITHOUT ANY WARRANTY; without even the implied warranty of
%%	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%%	GNU Affero General Public License for more details.
%%
%%	You should have received a copy of the GNU Affero General Public License
%%	along with EGS.  If not, see <http://www.gnu.org/licenses/>.

-module(egs_network).
-export([listen/2, recv/3]). %% API.
-export([accept/2]). %% Internal.

-define(OPTIONS, [binary, {active, true}, {reuseaddr, true}, {ssl_imp, new}, {certfile, "priv/ssl/servercert.pem"}, {keyfile, "priv/ssl/serverkey.pem"}, {password, "<PASSWORD>"}]).

%% @doc Listen for connections.
listen(Port, CallbackMod) ->
	error_logger:info_report(io_lib:format("listener started for ~p on port ~b", [CallbackMod, Port])),
	{ok, LSocket} = ssl:listen(Port, ?OPTIONS),
	?MODULE:accept(LSocket, CallbackMod).

%% @doc Accept connections.
accept(LSocket, CallbackMod) ->
	case ssl:transport_accept(LSocket, 5000) of
		{ok, CSocket} ->
			case ssl:ssl_accept(CSocket, 5000) of
				ok ->
					Pid = spawn(CallbackMod, init, [CSocket]),
					ssl:controlling_process(CSocket, Pid);
				{error, _Reason} ->
					ignore
			end;
		{error, _Reason} ->
			ignore
	end,
	?MODULE:accept(LSocket, CallbackMod).

%% @doc Main loop for the network stack. Receive and handle messages.
recv(SoFar, CallbackMod, State) ->
	receive
		{ssl, _Any, Data} ->
			{Commands, Rest} = split(<< SoFar/bits, Data/bits >>, []),<commit_msg>egs_network: Stay on the old SSL implementation until the new one works better.<commit_after>%% @author <NAME> <<EMAIL>>
%% @copyright 2010 <NAME>.
%% @doc Login and game servers low-level network handling.
%%
%%	This file is part of EGS.
%%
%%	EGS is free software: you can redistribute it and/or modify
%%	it under the terms of the GNU Affero General Public License as
%%	published by the Free Software Foundation, either version 3 of the
%%	License, or (at your option) any later version.
%%
%%	EGS is distributed in the hope that it will be useful,
%%	but WITHOUT ANY WARRANTY; without even the implied warranty of
%%	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%%	GNU Affero General Public License for more details.
%%
%%	You should have received a copy of the GNU Affero General Public License
%%	along with EGS.  If not, see <http://www.gnu.org/licenses/>.

-module(egs_network).
-export([listen/2, recv/3]). %% API.
-export([accept/2]). %% Internal.

-define(OPTIONS, [binary, {active, true}, {reuseaddr, true}, {ssl_imp, old}, {certfile, "priv/ssl/servercert.pem"}, {keyfile, "priv/ssl/serverkey.pem"}, {password, "<PASSWORD>"}]).

%% @doc Listen for connections.
listen(Port, CallbackMod) ->
	error_logger:info_report(io_lib:format("listener started for ~p on port ~b", [CallbackMod, Port])),
	{ok, LSocket} = ssl:listen(Port, ?OPTIONS),
	?MODULE:accept(LSocket, CallbackMod).

%% @doc Accept connections.
accept(LSocket, CallbackMod) ->
	case ssl:transport_accept(LSocket, 5000) of
		{ok, CSocket} ->
			case ssl:ssl_accept(CSocket, 5000) of
				ok ->
					Pid = spawn(CallbackMod, init, [CSocket]),
					ssl:controlling_process(CSocket, Pid);
				{error, _Reason} ->
					ignore
			end;
		{error, _Reason} ->
			ignore
	end,
	?MODULE:accept(LSocket, CallbackMod).

%% @doc Main loop for the network stack. Receive and handle messages.
recv(SoFar, CallbackMod, State) ->
	receive
		{ssl, _Any, Data} ->
			{Commands, Rest} = split(<< SoFar/bits, Data/bits >>, []),
{'fraction_non_alphanumeric': 0.14183673469387756, 'fraction_numerical': 0.00816326530612245, 'mean_word_length': 4.400826446280992, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7178771', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1264, 'n_words': 444}