diff --git a/Emakefile b/Emakefile
index 0ea9b3b..b081d9d 100644
--- a/Emakefile
+++ b/Emakefile
@@ -23,7 +23,7 @@
{'src/egs_db.erl', [{outdir, "ebin"}]}.
{'src/egs_game.erl', [{outdir, "ebin"}]}.
{'src/egs_login.erl', [{outdir, "ebin"}]}.
-{'src/egs_patch.erl', [{outdir, "ebin"}]}.
+{'src/psu/psu_patch.erl', [{outdir, "ebin"}]}.
{'src/egs_proto.erl', [{outdir, "ebin"}]}.
{'src/psu_appearance.erl', [{outdir, "ebin"}]}.
{'src/psu_characters.erl', [{outdir, "ebin"}]}.
diff --git a/ebin/egs.app b/ebin/egs.app
index dd65314..73b7b75 100644
--- a/ebin/egs.app
+++ b/ebin/egs.app
@@ -10,7 +10,7 @@
egs_db,
egs_game,
egs_login,
- egs_patch,
+ psu_patch,
egs_proto,
psu_appearance,
psu_characters,
diff --git a/p/patch-0.bin b/priv/psu_patch/patch-0.bin
similarity index 100%
rename from p/patch-0.bin
rename to priv/psu_patch/patch-0.bin
diff --git a/p/patch-1.bin b/priv/psu_patch/patch-1.bin
similarity index 100%
rename from p/patch-1.bin
rename to priv/psu_patch/patch-1.bin
diff --git a/p/patch-2.bin b/priv/psu_patch/patch-2.bin
similarity index 100%
rename from p/patch-2.bin
rename to priv/psu_patch/patch-2.bin
diff --git a/p/patch-3.bin b/priv/psu_patch/patch-3.bin
similarity index 100%
rename from p/patch-3.bin
rename to priv/psu_patch/patch-3.bin
diff --git a/p/patch-4.bin b/priv/psu_patch/patch-4.bin
similarity index 100%
rename from p/patch-4.bin
rename to priv/psu_patch/patch-4.bin
diff --git a/src/egs_patch.erl b/src/egs_patch.erl
deleted file mode 100644
index 1f20c92..0000000
--- a/src/egs_patch.erl
+++ /dev/null
@@ -1,68 +0,0 @@
-% EGS: Erlang Game Server
-% Copyright (C) 2010 Loic Hoguin
-%
-% This file is part of EGS.
-%
-% EGS is free software: you can redistribute it and/or modify
-% it under the terms of the GNU 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 General Public License for more details.
-%
-% You should have received a copy of the GNU General Public License
-% along with EGS. If not, see .
-
--module(egs_patch).
--export([start/0]). % external
--export([listen/1, accept/1, process/1]). % internal
-
--include("include/network.hrl").
-
-%% @doc Start the patch server. Currently supports AOTI US and JP.
-
-start() ->
- spawn_link(?MODULE, listen, [?PATCH_PORT_JP]),
- USPid = spawn_link(?MODULE, listen, [?PATCH_PORT_US]),
- {ok, USPid}.
-
-%% @doc Listen for connections.
-
-listen(Port) ->
- process_flag(trap_exit, true),
- {ok, LSocket} = gen_tcp:listen(Port, ?PATCH_LISTEN_OPTIONS),
- ?MODULE:accept(LSocket).
-
-%% @doc Accept connections.
-
-accept(LSocket) ->
- case gen_tcp:accept(LSocket, 5000) of
- {ok, CSocket} ->
- spawn_link(?MODULE, process, [CSocket]);
- {error, timeout} ->
- reload
- end,
- ?MODULE:accept(LSocket).
-
-%% @doc Fake the patch server by sending what the game wants to hear: no updates available.
-%% Ignore all the return values.
-
-process(CSocket) ->
- io:format("faking patch server: no updates~n"),
- _ = send_packet(CSocket, "p/patch-0.bin"),
- _ = gen_tcp:recv(CSocket, 0, 5000),
- _ = send_packet(CSocket, "p/patch-1.bin"),
- _ = send_packet(CSocket, "p/patch-2.bin"),
- _ = gen_tcp:recv(CSocket, 0, 5000),
- _ = send_packet(CSocket, "p/patch-3.bin"),
- _ = send_packet(CSocket, "p/patch-4.bin"),
- _ = gen_tcp:close(CSocket).
-
-%% @doc Send a packet from a file.
-
-send_packet(CSocket, PacketFilename) ->
- {ok, Packet} = file:read_file(PacketFilename),
- gen_tcp:send(CSocket, Packet).
diff --git a/src/egs_sup.erl b/src/egs_sup.erl
index 43b6fdb..e7ce2b9 100644
--- a/src/egs_sup.erl
+++ b/src/egs_sup.erl
@@ -22,6 +22,8 @@
-export([init/1]). %% Supervisor callbacks.
-export([start_link/0, upgrade/0]). %% Other functions.
+-include("include/network.hrl").
+
%% @spec start_link() -> ServerRet
%% @doc API for starting the supervisor.
start_link() ->
@@ -50,5 +52,6 @@ init([]) ->
Processes = [{egs_cron, {egs_cron, start, []}, permanent, 5000, worker, dynamic},
{egs_game, {egs_game, start, []}, permanent, 5000, worker, dynamic},
{egs_login, {egs_login, start, []}, permanent, 5000, worker, dynamic},
- {egs_patch, {egs_patch, start, []}, permanent, 5000, worker, dynamic}],
+ {psu_patch_jp, {psu_patch, start_link, [?PATCH_PORT_JP]}, permanent, 5000, worker, dynamic},
+ {psu_patch_us, {psu_patch, start_link, [?PATCH_PORT_US]}, permanent, 5000, worker, dynamic}],
{ok, {{one_for_one, 10, 10}, Processes}}.
diff --git a/src/psu/psu_patch.erl b/src/psu/psu_patch.erl
new file mode 100644
index 0000000..7da31dc
--- /dev/null
+++ b/src/psu/psu_patch.erl
@@ -0,0 +1,66 @@
+%% @author Loïc Hoguin
+%% @copyright 2010 Loïc Hoguin.
+%% @doc Process patch requests.
+%%
+%% This file is part of EGS.
+%%
+%% EGS is free software: you can redistribute it and/or modify
+%% it under the terms of the GNU 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 General Public License for more details.
+%%
+%% You should have received a copy of the GNU General Public License
+%% along with EGS. If not, see .
+
+-module(psu_patch).
+-export([start_link/1]). %% External.
+-export([listen/1, accept/1, process/1]). %% Internal
+
+-define(OPTIONS, [binary, {send_timeout, 5000}, {packet, 0}, {active, false}, {reuseaddr, true}]).
+
+%% @spec start_link(Port) -> {ok,Pid::pid()}
+%% @doc Starts the patch server for inclusion in a supervisor tree.
+start_link(Port) ->
+ Pid = spawn(?MODULE, listen, [Port]),
+ {ok, Pid}.
+
+%% @spec listen(Port) -> ok
+%% @doc Listen for connections.
+listen(Port) ->
+ {ok, LSocket} = gen_tcp:listen(Port, ?OPTIONS),
+ ?MODULE:accept(LSocket).
+
+%% @spec accept(LSocket) -> ok
+%% @doc Accept connections.
+accept(LSocket) ->
+ case gen_tcp:accept(LSocket, 5000) of
+ {ok, CSocket} ->
+ spawn(?MODULE, process, [CSocket]);
+ {error, timeout} ->
+ reload
+ end,
+ ?MODULE:accept(LSocket).
+
+%% @spec process(CSocket) -> ok
+%% @doc Fake the patch server by sending what the game wants to hear: no updates available.
+process(CSocket) ->
+ io:format("faking patch server: no updates~n"),
+ send_packet(CSocket, "priv/psu_patch/patch-0.bin"),
+ gen_tcp:recv(CSocket, 0, 5000),
+ send_packet(CSocket, "priv/psu_patch/patch-1.bin"),
+ send_packet(CSocket, "priv/psu_patch/patch-2.bin"),
+ gen_tcp:recv(CSocket, 0, 5000),
+ send_packet(CSocket, "priv/psu_patch/patch-3.bin"),
+ send_packet(CSocket, "priv/psu_patch/patch-4.bin"),
+ gen_tcp:close(CSocket).
+
+%% @spec send_packet(CSocket, PacketFilename) -> ok
+%% @doc Send a packet from a file.
+send_packet(CSocket, PacketFilename) ->
+ {ok, Packet} = file:read_file(PacketFilename),
+ gen_tcp:send(CSocket, Packet).