From 26ed4cbf5430173e3cae565cba633d2f812fc37c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 31 Jul 2010 21:32:08 +0200 Subject: [PATCH] Remove egs_db. Rename the ids table to counters. Update it directly. --- ebin/egs.app | 1 - include/records.hrl | 5 ++--- src/egs_app.erl | 3 +-- src/egs_db.erl | 25 ------------------------- src/psu/psu_game.erl | 2 +- 5 files changed, 4 insertions(+), 32 deletions(-) delete mode 100644 src/egs_db.erl diff --git a/ebin/egs.app b/ebin/egs.app index f3318e9..46067ce 100644 --- a/ebin/egs.app +++ b/ebin/egs.app @@ -9,7 +9,6 @@ egs_exit_mon, egs_user_model, reloader, - egs_db, psu_game, psu_login, psu_patch, diff --git a/include/records.hrl b/include/records.hrl index 1bb3a52..f1ec28d 100644 --- a/include/records.hrl +++ b/include/records.hrl @@ -16,9 +16,8 @@ % You should have received a copy of the GNU General Public License % along with EGS. If not, see . -%% @doc Temporary table for generating a new GID at each connection. - --record(ids, {type, id}). +%% @doc Table containing counters current values. +-record(counters, {name, id}). %% @doc Character position data structure. diff --git a/src/egs_app.erl b/src/egs_app.erl index 652d387..1f27109 100644 --- a/src/egs_app.erl +++ b/src/egs_app.erl @@ -56,7 +56,6 @@ is_fresh_startup() -> end. %% @todo doc -%% @todo Rename ids to counters. Remove objects and use a FSM instead. db_init() -> Nodes = [node()], case mnesia:system_info(is_running) of @@ -69,7 +68,7 @@ db_init() -> error_logger:info_report("mnesia schema created"), error_logger:info_report("starting mnesia"), mnesia:start(), - mnesia:create_table(ids, [{attributes, record_info(fields, ids)}]), + mnesia:create_table(counters, [{attributes, record_info(fields, counters)}]), mnesia:create_table(psu_object, [{attributes, record_info(fields, psu_object)}]), mnesia:create_table(egs_user_model, [{attributes, record_info(fields, egs_user_model)}]), error_logger:info_report("mnesia tables created"). diff --git a/src/egs_db.erl b/src/egs_db.erl deleted file mode 100644 index 4946003..0000000 --- a/src/egs_db.erl +++ /dev/null @@ -1,25 +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_db). --compile(export_all). - -%% @doc Retrieve the next unique ID. -%% @todo Used only for the LID so far... -next(Type) -> - mnesia:dirty_update_counter(ids, Type, 1). diff --git a/src/psu/psu_game.erl b/src/psu/psu_game.erl index 0a710f6..61c8ccb 100644 --- a/src/psu/psu_game.erl +++ b/src/psu/psu_game.erl @@ -105,7 +105,7 @@ process_handle(16#020d, << GID:32/little-unsigned-integer, Auth:32/bits, _/bits {wait_for_authentication, Auth} -> put(gid, GID), log("auth success"), - LID = 1 + egs_db:next(lobby) rem 1023, + LID = 1 + mnesia:dirty_update_counter(counters, lobby, 1) rem 1023, Time = calendar:datetime_to_gregorian_seconds(calendar:universal_time()), egs_user_model:write(#egs_user_model{id=GID, pid=self(), socket=CSocket, state=authenticated, time=Time, folder=User#egs_user_model.folder, lid=LID}), send_0d05(),