Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move the patch server into its own separate application

  • Loading branch information...
commit c69513073d206b786866f3e93406640c56a532d2 1 parent 35b86b5
Loïc Hoguin authored
View
10 .gitignore
@@ -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
View
12 apps/egs/src/egs_app.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;
View
3  apps/egs/src/egs_sup.erl
@@ -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.
View
0  priv/patch.conf → apps/egs_patch/priv/patch.conf
File renamed without changes
View
0  priv/patch/.gitignore → apps/egs_patch/priv/patch/.gitignore
File renamed without changes
View
3  apps/egs_patch/rebar.config
@@ -0,0 +1,3 @@
+{deps, [
+ {cowboy, ".*", {git, "git://github.com/extend/cowboy.git", "HEAD"}}
+]}.
View
14 apps/egs_patch/src/egs_patch.app.src
@@ -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, []}
+]}.
View
48 apps/egs_patch/src/egs_patch_app.erl
@@ -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).
View
3  apps/egs/src/egs_patch_files_db.erl → apps/egs_patch/src/egs_patch_files_db.erl
@@ -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}.
View
0  apps/egs/src/egs_patch_protocol.erl → apps/egs_patch/src/egs_patch_protocol.erl
File renamed without changes
View
34 apps/egs_patch/src/egs_patch_sup.erl
@@ -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}}.
View
3  rebar.config
@@ -1,5 +1,6 @@
{sub_dirs, [
- "apps/egs"
+ "apps/egs",
+ "apps/egs_patch"
]}.
{dialyzer_opts, [src, {warnings, [
behaviours,
Please sign in to comment.
Something went wrong with that request. Please try again.