aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile32
-rw-r--r--conf/yaws.conf.m412
-rw-r--r--src/battlemap/bm_handler.erl12
-rw-r--r--src/battlemap/bm_shim.erl106
-rw-r--r--src/shared/io/sh_database.erl118
-rw-r--r--src/shared/io/sh_timed_caches_manager.erl2
6 files changed, 166 insertions, 116 deletions
diff --git a/Makefile b/Makefile
index d7ff210..dd99dfd 100644
--- a/Makefile
+++ b/Makefile
@@ -11,15 +11,18 @@ INCLUDE_DIR ?= ${CURDIR}/include
WWW_DIR ?= ${CURDIR}/www
LOG_DIR ?= ${CURDIR}/log
-## Binaries
-YAWS ?= yaws
-YAWS_OPTS ?=
+## Local only?
+ERL_NAME_VS_SNAME ?= -sname
+## Binaries
ERLC ?= erlc
ERLC_OPTS ?=
ERL ?= erl
-ERL_OPTS ?=
+ERL_OPTS ?= -connect_all false -pa $(BIN_DIR)
+
+YAWS ?= yaws
+YAWS_OPTS ?= $(ERL_NAME_VS_SNAME) query_node -erlarg "$(ERL_OPTS)"
DIALYZER ?= dialyzer
DIALYZER_OPTS ?=
@@ -30,6 +33,9 @@ M4_OPTS ?=
## Filenames
DIALYZER_PLT_FILE ?= tacticians-server.plt
+YAWS_CONFIG_FILE ?= $(CONFIG_DIR)/yaws.conf
+
+
################################################################################
## MAKEFILE MAGIC ##############################################################
################################################################################
@@ -59,6 +65,16 @@ M4_EXEC = $(M4) $(M4_OPTS)
## SANITY CHECKS ###############################################################
################################################################################
+
+################################################################################
+## PREPROCESSOR-VISIBLE MAKEFILE VARIABLES #####################################
+################################################################################
+
+MAKEFILE_TO_M4 = \
+ --define=__MAKEFILE_BIN_DIR=$(BIN_DIR) \
+ --define=__MAKEFILE_LOG_DIR=$(LOG_DIR) \
+ --define=__MAKEFILE_WWW_DIR=$(WWW_DIR) \
+ --define=__MAKEFILE_INCLUDE_DIR=$(INCLUDE_DIR)
################################################################################
## TARGET RULES ################################################################
################################################################################
@@ -69,7 +85,11 @@ debug: debug_run
build: $(OPTIONAL_DIRS) $(REQUIRED_HEADERS) \
$(PREPROCESSED_FILES) $(ERL_BIN_FILES)
-run: yaws_run
+run_db_node: build
+ $(ERL_EXEC) $(ERL_NAME_VS_SNAME) db_node -run db_node start
+
+run_query_node: build $(YAWS_CONFIG_FILE)
+ $(YAWS_EXEC) --conf $(YAWS_CONFIG_FILE)
clean:
# Preprocessor
@@ -104,7 +124,7 @@ debug_run:
endif
$(PREPROCESSED_FILES): %: $(PREPROCESSOR_CONFIG_FILES) %.m4
- $(M4_EXEC) -P $^ > $@
+ $(M4_EXEC) -P $(MAKEFILE_TO_M4) $^> $@
$(OPTIONAL_DIRS): %:
mkdir -p $@
diff --git a/conf/yaws.conf.m4 b/conf/yaws.conf.m4
index 8a68f0b..3f5b36b 100644
--- a/conf/yaws.conf.m4
+++ b/conf/yaws.conf.m4
@@ -4,17 +4,17 @@
# This is the directory where all logfiles for
# all virtual servers will be written.
-logdir = __MODULE_LOG_DIR
+logdir = __MAKEFILE_LOG_DIR
# These are the paths to directories where additional
# beam code can be placed. The daemon will add these
# directories to its search path.
-ebin_dir = __MODULE_BIN_DIR
+ebin_dir = __MAKEFILE_BIN_DIR
# This is a directory where application specific .hrl
# files can be placed. Application-specific .yaws code can
# then include these .hrl files.
-include_dir = __MODULE_INCLUDE_DIR
+include_dir = __MAKEFILE_INCLUDE_DIR
# Set this to an integer value to control
# max number of connections from clients into the server.
@@ -108,8 +108,8 @@ keepalive_timeout = 30000
<server *>
port = 8000
listen = 0.0.0.0
- docroot = __MODULE_WWW_DIR
+ docroot = __MAKEFILE_WWW_DIR
auth_log = true
- appmods = __MODULE_APP_MODS
- start_mod = handler
+ appmods = bm_character_turn bm_load_state
+ start_mod = bm_handler
</server>
diff --git a/src/battlemap/bm_handler.erl b/src/battlemap/bm_handler.erl
index 09659e9..d355ea1 100644
--- a/src/battlemap/bm_handler.erl
+++ b/src/battlemap/bm_handler.erl
@@ -18,6 +18,16 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
start (_YawsParams) ->
{ok, Pid} = sh_timed_caches_manager:start(),
- bm_database_shim:generate_db(),
+ case sh_database:fetch(battle_db, <<"0">>) of
+ {ok, _} -> ok;
+ not_found ->
+ sh_database:insert
+ (
+ battle_db,
+ <<"0">>,
+ any,
+ bm_shim:generate_random_battle()
+ )
+ end,
sh_timed_caches_manager:new_cache(Pid, battle_db, none),
ok.
diff --git a/src/battlemap/bm_shim.erl b/src/battlemap/bm_shim.erl
new file mode 100644
index 0000000..3789ed0
--- /dev/null
+++ b/src/battlemap/bm_shim.erl
@@ -0,0 +1,106 @@
+-module(bm_shim).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-export([generate_random_battle/0 ]).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+-spec generate_random_characters
+ (
+ non_neg_integer(),
+ non_neg_integer(),
+ non_neg_integer(),
+ non_neg_integer(),
+ bm_battlemap:type(),
+ list(bm_location:type()),
+ list(bm_character:type())
+ )
+ -> list(bm_character:type()).
+generate_random_characters
+(
+ 0,
+ 0,
+ _CharactersPerPlayer,
+ _TotalCharacterCount,
+ _Battlemap,
+ _ForbiddenLocations,
+ Result
+) ->
+ Result;
+generate_random_characters
+(
+ MaxPlayerID,
+ 0,
+ CharactersPerPlayer,
+ TotalCharacterCount,
+ Battlemap,
+ ForbiddenLocations,
+ Result
+) ->
+ generate_random_characters
+ (
+ (MaxPlayerID - 1),
+ CharactersPerPlayer,
+ CharactersPerPlayer,
+ TotalCharacterCount,
+ Battlemap,
+ ForbiddenLocations,
+ Result
+ );
+generate_random_characters
+(
+ MaxPlayerID,
+ PlayerCharacterCount,
+ CharactersPerPlayer,
+ TotalCharacterCount,
+ Battlemap,
+ ForbiddenLocations,
+ Result
+) ->
+ NewCharacter =
+ bm_character:random
+ (
+ TotalCharacterCount,
+ list_to_binary(integer_to_list(MaxPlayerID)),
+ bm_battlemap:get_width(Battlemap),
+ bm_battlemap:get_height(Battlemap),
+ ForbiddenLocations
+ ),
+ Character =
+ case MaxPlayerID of
+ 0 -> bm_character:set_is_active(true, NewCharacter);
+ _ -> NewCharacter
+ end,
+
+ generate_random_characters
+ (
+ MaxPlayerID,
+ (PlayerCharacterCount - 1),
+ CharactersPerPlayer,
+ (TotalCharacterCount + 1),
+ Battlemap,
+ [bm_character:get_location(Character)|ForbiddenLocations],
+ [Character|Result]
+ ).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec generate_random_battle () -> bm_battle:type().
+generate_random_battle () ->
+ BattlemapWidth = sh_roll:between(16, 64),
+ BattlemapHeight = sh_roll:between(16, 64),
+ Battlemap = bm_battlemap:random(0, BattlemapWidth, BattlemapHeight),
+ Characters = generate_random_characters(1, 8, 8, 0, Battlemap, [], []),
+ PlayersAsList = [bm_player:new(<<"0">>), bm_player:new(<<"1">>)],
+ Battle = bm_battle:new(<<"0">>, PlayersAsList, Battlemap, Characters),
+
+ Battle.
diff --git a/src/shared/io/sh_database.erl b/src/shared/io/sh_database.erl
index 5fa791f..8b52f9e 100644
--- a/src/shared/io/sh_database.erl
+++ b/src/shared/io/sh_database.erl
@@ -10,7 +10,7 @@
-export
(
[
- generate_db/0,
+ insert/4,
fetch/2,
commit/1
]
@@ -19,119 +19,33 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-get_db_node () ->
- list_to_atom("db_node@" ++ net_adm:localhost()).
+get_db_node () -> list_to_atom("db_node@" ++ net_adm:localhost()).
--spec generate_random_characters
- (
- non_neg_integer(),
- non_neg_integer(),
- non_neg_integer(),
- non_neg_integer(),
- bm_battlemap:type(),
- list(bm_location:type()),
- list(bm_character:type())
- )
- -> list(bm_character:type()).
-generate_random_characters
-(
- 0,
- 0,
- _CharactersPerPlayer,
- _TotalCharacterCount,
- _Battlemap,
- _ForbiddenLocations,
- Result
-) ->
- Result;
-generate_random_characters
-(
- MaxPlayerID,
- 0,
- CharactersPerPlayer,
- TotalCharacterCount,
- Battlemap,
- ForbiddenLocations,
- Result
-) ->
- generate_random_characters
- (
- (MaxPlayerID - 1),
- CharactersPerPlayer,
- CharactersPerPlayer,
- TotalCharacterCount,
- Battlemap,
- ForbiddenLocations,
- Result
- );
-generate_random_characters
-(
- MaxPlayerID,
- PlayerCharacterCount,
- CharactersPerPlayer,
- TotalCharacterCount,
- Battlemap,
- ForbiddenLocations,
- Result
-) ->
- NewCharacter =
- bm_character:random
- (
- TotalCharacterCount,
- list_to_binary(integer_to_list(MaxPlayerID)),
- bm_battlemap:get_width(Battlemap),
- bm_battlemap:get_height(Battlemap),
- ForbiddenLocations
- ),
- Character =
- case MaxPlayerID of
- 0 -> bm_character:set_is_active(true, NewCharacter);
- _ -> NewCharacter
- end,
-
- generate_random_characters
- (
- MaxPlayerID,
- (PlayerCharacterCount - 1),
- CharactersPerPlayer,
- (TotalCharacterCount + 1),
- Battlemap,
- [bm_character:get_location(Character)|ForbiddenLocations],
- [Character|Result]
- ).
+do_remote_operation (Op, Params) ->
+ rpc:call(get_db_node(), db_access, Op, Params).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec generate_db () -> 'ok'.
-generate_db () ->
- BattlemapWidth = sh_roll:between(16, 64),
- BattlemapHeight = sh_roll:between(16, 64),
- Battlemap = bm_battlemap:random(0, BattlemapWidth, BattlemapHeight),
- Characters = generate_random_characters(1, 8, 8, 0, Battlemap, [], []),
- PlayersAsList = [bm_player:new(<<"0">>), bm_player:new(<<"1">>)],
- Battle = bm_battle:new(<<"0">>, PlayersAsList, Battlemap, Characters),
-
- {atomic, ok} =
- rpc:call
- (
- get_db_node(),
- storage_access,
- insert,
- [battle_db, <<"0">>, any, Battle]
- ),
+-spec insert (atom(), any(), sh_db_user:permission(), any()) -> 'ok'.
+insert (DB, ObjectID, Permission, Value) ->
+ {atomic, _} = do_remote_operation(insert, [DB, ObjectID, Permission, Value]),
+ io:format
+ (
+ "~nsh_database:insert(~p) -> ok.~n",
+ [{DB, ObjectID, Permission, Value}]
+ ),
ok.
-spec fetch (atom(), any()) -> ({'ok', any()} | 'not_found').
fetch (DB, ObjectID) ->
- {atomic, Reply} =
- rpc:call(get_db_node(), storage_access, read, [DB, ObjectID]),
- io:format("~ndb_shim:fetch(~p) -> ~p.~n", [{DB, ObjectID}, Reply]),
+ {atomic, Reply} = do_remote_operation(read, [DB, ObjectID]),
+ io:format("~nsh_database:fetch(~p) -> ~p.~n", [{DB, ObjectID}, Reply]),
Reply.
-spec commit (sh_db_query:type()) -> 'ok'.
commit (Query) ->
- {atomic, ok} = rpc:call(get_db_node(), storage_access, query, [Query]),
- io:format("~ndb_shim:commit(~p) -> ok.~n", [Query]),
+ {atomic, ok} = do_remote_operation(query, [Query]),
+ io:format("~nsh_database:commit(~p) -> ok.~n", [Query]),
ok.
diff --git a/src/shared/io/sh_timed_caches_manager.erl b/src/shared/io/sh_timed_caches_manager.erl
index 7921552..ea92c08 100644
--- a/src/shared/io/sh_timed_caches_manager.erl
+++ b/src/shared/io/sh_timed_caches_manager.erl
@@ -140,7 +140,7 @@ handle_info(_, State) ->
%%%% Interface Functions
start () ->
- gen_server:start(timed_caches_manager, [], []).
+ gen_server:start(?MODULE, [], []).
new_cache (ManagerPid, DB, Heir) ->
gen_server:cast(ManagerPid, {add, DB, Heir}).