Move the patch server into its own separate application
This commit is contained in:
parent
35b86b58ba
commit
c69513073d
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
c_src/*.o
|
||||
apps/*/c_src/*.o
|
||||
apps/*/ebin
|
||||
apps/*/priv/*.so
|
||||
apps/egs/src/egs_script_lexer.erl
|
||||
apps/egs/src/egs_script_parser.erl
|
||||
deps
|
||||
ebin
|
||||
priv/*.so
|
||||
src/egs_script_lexer.erl
|
||||
src/egs_script_parser.erl
|
||||
|
@ -32,7 +32,8 @@
|
||||
-spec start(application_start_type(), term()) -> {ok, pid()}.
|
||||
start(_Type, _StartArgs) ->
|
||||
{ok, Pid} = egs_sup:start_link(),
|
||||
start_patch_listeners(egs_conf:read(patch_ports)),
|
||||
application:set_env(egs_patch, patch_ports, egs_conf:read(patch_ports)),
|
||||
application:start(egs_patch),
|
||||
start_login_listeners(egs_conf:read(login_ports)),
|
||||
{_ServerIP, GamePort} = egs_conf:read(game_server),
|
||||
{ok, _GamePid} = cowboy:start_listener({game, GamePort}, 10,
|
||||
@ -46,15 +47,6 @@ stop(_State) ->
|
||||
|
||||
%% Internal.
|
||||
|
||||
-spec start_patch_listeners([inet:ip_port()]) -> ok.
|
||||
start_patch_listeners([]) ->
|
||||
ok;
|
||||
start_patch_listeners([Port|Tail]) ->
|
||||
{ok, _Pid} = cowboy:start_listener({patch, Port}, 10,
|
||||
cowboy_tcp_transport, [{port, Port}],
|
||||
egs_patch_protocol, []),
|
||||
start_patch_listeners(Tail).
|
||||
|
||||
-spec start_login_listeners([inet:ip_port()]) -> ok.
|
||||
start_login_listeners([]) ->
|
||||
ok;
|
||||
|
@ -31,8 +31,7 @@ start_link() ->
|
||||
init([]) ->
|
||||
Procs = procs([egs_conf, {sup, egs_quests_sup}, {sup, egs_zones_sup},
|
||||
egs_accounts, egs_users, egs_seasons, egs_counters_db, egs_items_db,
|
||||
egs_npc_db, egs_patch_files_db, egs_quests_db, egs_shops_db,
|
||||
egs_universes], []),
|
||||
egs_npc_db, egs_quests_db, egs_shops_db, egs_universes], []),
|
||||
{ok, {{one_for_one, 10, 10}, Procs}}.
|
||||
|
||||
%% Internal.
|
||||
|
3
apps/egs_patch/rebar.config
Normal file
3
apps/egs_patch/rebar.config
Normal file
@ -0,0 +1,3 @@
|
||||
{deps, [
|
||||
{cowboy, ".*", {git, "git://github.com/extend/cowboy.git", "HEAD"}}
|
||||
]}.
|
14
apps/egs_patch/src/egs_patch.app.src
Normal file
14
apps/egs_patch/src/egs_patch.app.src
Normal file
@ -0,0 +1,14 @@
|
||||
%%-*- mode: erlang -*-
|
||||
{application, egs_patch, [
|
||||
{description, "EGS patch server"},
|
||||
{vsn, "0.1.0"},
|
||||
{modules, []},
|
||||
{registered, []},
|
||||
{applications, [
|
||||
kernel,
|
||||
stdlib,
|
||||
cowboy
|
||||
]},
|
||||
{mod, {egs_patch_app, []}},
|
||||
{env, []}
|
||||
]}.
|
48
apps/egs_patch/src/egs_patch_app.erl
Normal file
48
apps/egs_patch/src/egs_patch_app.erl
Normal file
@ -0,0 +1,48 @@
|
||||
%% @author Loïc Hoguin <essen@dev-extend.eu>
|
||||
%% @copyright 2011 Loïc Hoguin.
|
||||
%% @doc Callbacks for the egs_patch application.
|
||||
%%
|
||||
%% 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_patch_app).
|
||||
-behaviour(application).
|
||||
-export([start/2, stop/1]). %% API.
|
||||
|
||||
-type application_start_type()
|
||||
:: normal | {takeover, node()} | {failover, node()}.
|
||||
|
||||
%% API.
|
||||
|
||||
-spec start(application_start_type(), term()) -> {ok, pid()}.
|
||||
start(_Type, _StartArgs) ->
|
||||
{ok, PatchPorts} = application:get_env(patch_ports),
|
||||
start_listeners(PatchPorts),
|
||||
egs_patch_sup:start_link().
|
||||
|
||||
-spec stop(term()) -> ok.
|
||||
stop(_State) ->
|
||||
ok.
|
||||
|
||||
%% Internal.
|
||||
|
||||
-spec start_listeners([inet:ip_port()]) -> ok.
|
||||
start_listeners([]) ->
|
||||
ok;
|
||||
start_listeners([Port|Tail]) ->
|
||||
{ok, _Pid} = cowboy:start_listener({patch, Port}, 10,
|
||||
cowboy_tcp_transport, [{port, Port}],
|
||||
egs_patch_protocol, []),
|
||||
start_listeners(Tail).
|
@ -107,7 +107,8 @@ code_change(_OldVsn, State, _Extra) ->
|
||||
%% Internal.
|
||||
|
||||
build_state() ->
|
||||
{ok, Terms} = file:consult("priv/patch.conf"),
|
||||
{ok, App} = application:get_application(),
|
||||
{ok, Terms} = file:consult([code:priv_dir(App), "/patch.conf"]),
|
||||
Folders = proplists:get_value(folders, Terms),
|
||||
{ListBin, Files} = build_list_bin(Folders, Terms),
|
||||
#state{list_bin=ListBin, files=Files}.
|
34
apps/egs_patch/src/egs_patch_sup.erl
Normal file
34
apps/egs_patch/src/egs_patch_sup.erl
Normal file
@ -0,0 +1,34 @@
|
||||
%% @author Loïc Hoguin <essen@dev-extend.eu>
|
||||
%% @copyright 2011 Loïc Hoguin.
|
||||
%% @doc Top-level supervisor for the egs_patch application.
|
||||
%%
|
||||
%% 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_patch_sup).
|
||||
-behaviour(supervisor).
|
||||
|
||||
-export([start_link/0]). %% API.
|
||||
-export([init/1]). %% Supervisor.
|
||||
|
||||
-spec start_link() -> {ok, pid()}.
|
||||
start_link() ->
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
-spec init([]) -> {ok, {{one_for_one, 10, 10}, [supervisor:child_spec(), ...]}}.
|
||||
init([]) ->
|
||||
Procs = [{egs_patch_files_db, {egs_patch_files_db, start_link, []},
|
||||
permanent, 5000, worker, [egs_patch_files_db]}],
|
||||
{ok, {{one_for_one, 10, 10}, Procs}}.
|
@ -1,5 +1,6 @@
|
||||
{sub_dirs, [
|
||||
"apps/egs"
|
||||
"apps/egs",
|
||||
"apps/egs_patch"
|
||||
]}.
|
||||
{dialyzer_opts, [src, {warnings, [
|
||||
behaviours,
|
||||
|
Loading…
Reference in New Issue
Block a user