Browse Source

protocol init demo

Maxim Sokhatsky 11 years ago
parent
commit
1cfd199c94

+ 9 - 0
apps/db/src/db_config.erl

@@ -0,0 +1,9 @@
+-module(db_config).
+-include_lib("kvs/include/metainfo.hrl").
+-include_lib("db/include/config.hrl").
+-compile(export_all).
+
+metainfo() ->
+    #schema{name=kvs,tables=[
+        #table{name=config,fields=record_info(fields,config)}
+    ]}.

+ 7 - 0
apps/face/src/index.erl

@@ -1,6 +1,8 @@
 -module(index).
 -compile(export_all).
 -include_lib("n2o/include/wf.hrl").
+-include_lib("server/include/requests.hrl").
+-include_lib("server/include/settings.hrl").
 
 main() -> 
     case wf:user() of
@@ -18,6 +20,8 @@ body() ->
       #button{ id=send, body= <<"Chat">>, postback={chat,Pid}, source=[message] } ].
 
 event(init) ->
+    {ok,GamePid} = game_session:start_link(self()),
+    put(game_session,GamePid),
     User = wf:user(),
     wf:reg(room),
     X = wf:qs(<<"x">>),
@@ -25,6 +29,9 @@ event(init) ->
                                 #button{id=logout, body="Logout", postback=logout}, #br{} ]);
 
 event({chat,Pid}) ->
+    GamePid = get(game_session),
+    game_session:process_request(GamePid,"Web Site",#session_attach{token=?TEST_TOKEN}), 
+    game_session:process_request(GamePid,"Web Site",#join_game{game=1000002}),
     error_logger:info_msg("Chat Pid: ~p",[Pid]),
     Username = wf:user(),
     Message = wf:q(message),

+ 2 - 1
apps/server/src/game_sup.erl

@@ -19,9 +19,10 @@ init([]) ->
     Restart = permanent,
     Shutdown = 2000,
     IdGen = {id_generator, {id_generator, start_link, []},  Restart, Shutdown, worker, [id_generator]},
+    AuthServer = {auth_server, {auth_server, start_link, []}, Restart, Shutdown, worker, [auth_server]},
     GameManager = {game_manager, {game_manager, start_link, []}, Restart, Shutdown, worker, [game_manager]},
     TavlaSup = {tavla_sup, {tavla_sup, start_link, []}, Restart, Shutdown, supervisor, [tavla_sup]},
     OkeySup = {okey_sup, {okey_sup, start_link, []}, Restart, Shutdown, supervisor, [okey_sup]},
     LuckySup = {lucky_sup, {lucky_sup, start_link, []}, Restart, Shutdown, supervisor, [lucky_sup]},
-    {ok, {SupFlags, [IdGen,GameManager,LuckySup,TavlaSup,OkeySup]}}.
+    {ok, {SupFlags, [IdGen,GameManager,LuckySup,TavlaSup,OkeySup,AuthServer]}}.
 

+ 6 - 6
apps/server/src/tavla/game_tavla_ng_table.erl

@@ -1643,13 +1643,13 @@ die_to_ext(Die) -> Die.
 
 %%===================================================================
 
-get_timeout(turn, fast) -> {ok, Val}   = nsm_db:get(config,"games/okey/turn_timeout_fast", 15000), Val;
-get_timeout(turn, normal) -> {ok, Val} = nsm_db:get(config,"games/okey/turn_timeout_normal", 30000), Val;
-get_timeout(turn, slow) -> {ok, Val}   = nsm_db:get(config,"games/okey/turn_timeout_slow", 60000), Val;
+get_timeout(turn, fast) -> {ok, Val}   = kvs:get(config,"games/okey/turn_timeout_fast", 15000), Val;
+get_timeout(turn, normal) -> {ok, Val} = kvs:get(config,"games/okey/turn_timeout_normal", 30000), Val;
+get_timeout(turn, slow) -> {ok, Val}   = kvs:get(config,"games/okey/turn_timeout_slow", 60000), Val;
 
-get_timeout(ready, fast) -> {ok, Val}   = nsm_db:get(config,"games/okey/ready_timeout_fast", 15000), Val;
-get_timeout(ready, normal) -> {ok, Val} = nsm_db:get(config,"games/okey/ready_timeout_normal", 25000), Val;
-get_timeout(ready, slow) -> {ok, Val}   = nsm_db:get(config,"games/okey/ready_timeout_slow", 45000), Val.
+get_timeout(ready, fast) -> {ok, Val}   = kvs:get(config,"games/okey/ready_timeout_fast", 15000), Val;
+get_timeout(ready, normal) -> {ok, Val} = kvs:get(config,"games/okey/ready_timeout_normal", 25000), Val;
+get_timeout(ready, slow) -> {ok, Val}   = kvs:get(config,"games/okey/ready_timeout_slow", 45000), Val.
 
 %%===================================================================
 

+ 1 - 1
rels/web/files/sys.config

@@ -6,7 +6,7 @@
      [{pass_init_db,true},
       {nodes,[]},
       {dba, store_mnesia},
-      {schema, [kvs_user, kvs_acl, kvs_feed, kvs_subscription]}]},
+      {schema, [kvs_user, kvs_acl, kvs_feed, kvs_subscription, db_config ]}]},
  {sasl, [
          {sasl_error_logger, {file, "log/sasl-error.log"}},
          {errlog_type, error},