diff --git a/include/records.hrl b/include/records.hrl index a0fa4b5..cda17ce 100644 --- a/include/records.hrl +++ b/include/records.hrl @@ -17,6 +17,9 @@ %% You should have received a copy of the GNU Affero General Public License %% along with EGS. If not, see . +%% @doc Per-process state used by the various EGS modules. +-record(state, {socket, gid, lid=16#ffff}). + %% @doc Table containing counters current values. -record(counters, {name, id}). diff --git a/src/egs_char_select.erl b/src/egs_char_select.erl index 82a06f7..248c263 100644 --- a/src/egs_char_select.erl +++ b/src/egs_char_select.erl @@ -20,12 +20,9 @@ -module(egs_char_select). -export([keepalive/1, info/2, cast/3, raw/3, event/2]). -%% @todo These headers are only included because of egs_user_model and items. We don't want that here. -include("include/records.hrl"). -include("include/psu/items.hrl"). --record(state, {socket, gid}). - %% @doc Send a keepalive. keepalive(#state{socket=Socket}) -> psu_proto:send_keepalive(Socket). @@ -72,7 +69,7 @@ event({char_select_create, Slot, CharBin}, #state{gid=GID}) -> %% @doc Load the selected character into the game's universe. %% @todo The area_change should happen only after we received 021c back from the client. -event({char_select_enter, Slot, _BackToPreviousField}, #state{socket=Socket, gid=GID}) -> +event({char_select_enter, Slot, _BackToPreviousField}, State=#state{gid=GID}) -> {ok, User} = egs_user_model:read(GID), [{status, 1}, {char, CharBin}, {options, OptionsBin}] = data_load(User#egs_user_model.folder, Slot), << Name:512/bits, RaceBin:8, GenderBin:8, ClassBin:8, AppearanceBin:776/bits, _/bits >> = CharBin, @@ -90,7 +87,7 @@ event({char_select_enter, Slot, _BackToPreviousField}, #state{socket=Socket, gid prev_area={psu_area, 0, 0, 0}, prev_entryid=0, pos=#pos{x=0.0, y=0.0, z=0.0, dir=0.0}, setid=0}, egs_user_model:write(User2), psu_game:char_load(User2), - {ok, egs_game, {state, Socket, GID}}. + {ok, egs_game, State}. %% Internal. diff --git a/src/egs_game.erl b/src/egs_game.erl index 011317c..1f15f0b 100644 --- a/src/egs_game.erl +++ b/src/egs_game.erl @@ -20,13 +20,10 @@ -module(egs_game). -export([keepalive/1, info/2, cast/3, raw/3, event/2]). -%% @todo This header is probably only included because of egs_user_model. We don't want that here. -include("include/records.hrl"). -include("include/maps.hrl"). -include("include/psu/items.hrl"). --record(state, {socket, gid}). - %% @doc Send a keepalive. keepalive(#state{socket=Socket}) -> psu_proto:send_keepalive(Socket). diff --git a/src/egs_game_server.erl b/src/egs_game_server.erl index 6a9fa98..15692e2 100644 --- a/src/egs_game_server.erl +++ b/src/egs_game_server.erl @@ -20,7 +20,6 @@ -module(egs_game_server). -export([start_link/1, on_exit/1, init/1]). -%% @todo This header is only included because of egs_user_model. We don't want that here. -include("include/records.hrl"). %% @spec start_link(Port) -> {ok,Pid::pid()} @@ -61,4 +60,4 @@ init(Socket) -> timer:send_interval(5000, {egs, keepalive}), TmpGID = 16#ff000000 + mnesia:dirty_update_counter(counters, tmpgid, 1), psu_proto:send_0202(Socket, TmpGID), - egs_network:recv(<< >>, egs_login, {state, Socket, TmpGID}). + egs_network:recv(<< >>, egs_login, #state{socket=Socket, gid=TmpGID}). diff --git a/src/egs_login.erl b/src/egs_login.erl index ccebaf2..5676248 100644 --- a/src/egs_login.erl +++ b/src/egs_login.erl @@ -20,12 +20,9 @@ -module(egs_login). -export([keepalive/1, info/2, cast/3, raw/3, event/2]). -%% @todo This header is only included because of egs_user_model. We don't want that here. -include("include/records.hrl"). -include("include/network.hrl"). --record(state, {socket, gid}). - %% @doc Don't keep alive here, authentication should go fast. keepalive(_State) -> ok. @@ -51,6 +48,7 @@ raw(Command, _Data, _State) -> %% @doc Reject version < 2.0009.2. %% @todo Reject wrong platforms too. +%% @todo f9dbce73 is an auth key too. event({system_client_version_info, _Entrance, _Language, _Platform, Version}, #state{socket=Socket, gid=GID}) -> if Version >= 2009002 -> ignore; true -> Website = << "http://psumods.co.uk/forums/comments.php?DiscussionID=40#Item_1" >>, @@ -78,7 +76,7 @@ event(system_game_server_request, #state{socket=Socket, gid=GID}) -> %% @doc Authenticate the user by pattern matching its saved state against the key received. %% If the user is authenticated, send him the character flags list. %% @todo Remove the put calls when all the send_xxxx are moved out of psu_game and into psu_proto. -event({system_key_auth_request, AuthGID, AuthKey}, #state{socket=Socket}) -> +event({system_key_auth_request, AuthGID, AuthKey}, State=#state{socket=Socket}) -> {ok, User} = egs_user_model:read(AuthGID), {wait_for_authentication, AuthKey} = User#egs_user_model.state, put(socket, Socket), @@ -88,7 +86,7 @@ event({system_key_auth_request, AuthGID, AuthKey}, #state{socket=Socket}) -> User2 = User#egs_user_model{id=AuthGID, pid=self(), socket=Socket, state=authenticated, time=Time, lid=LID}, egs_user_model:write(User2), psu_proto:send_0d05(User2), - {ok, egs_char_select, {state, Socket, AuthGID}}; + {ok, egs_char_select, State#state{gid=AuthGID}}; %% @doc Authentication request handler. Currently always succeed. %% Use the temporary session ID as the GID for now. diff --git a/src/egs_login_server.erl b/src/egs_login_server.erl index 8e14310..5945739 100644 --- a/src/egs_login_server.erl +++ b/src/egs_login_server.erl @@ -20,6 +20,8 @@ -module(egs_login_server). -export([start_link/1, on_exit/1, init/1]). +-include("include/records.hrl"). + %% @spec start_link(Port) -> {ok,Pid::pid()} %% @doc Start the login server. start_link(Port) -> @@ -35,4 +37,4 @@ on_exit(_Pid) -> init(Socket) -> TmpGID = 16#ff000000 + mnesia:dirty_update_counter(counters, tmpgid, 1), psu_proto:send_0202(Socket, TmpGID), - egs_network:recv(<< >>, egs_login, {state, Socket, TmpGID}). + egs_network:recv(<< >>, egs_login, #state{socket=Socket, gid=TmpGID}).