added stats module
This commit is contained in:
parent
d10a016808
commit
3a2a95855d
4 changed files with 50 additions and 2 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 030e0ecafff27fff8e6918add47dfcdeec363e7c
|
||||
Subproject commit 00312859714bef6e9a4fdb9931a41fef56eeb89a
|
|
@ -3,7 +3,7 @@
|
|||
-export([read/2, send_command/3]).
|
||||
|
||||
connect() ->
|
||||
{ok,Socket} = gen_tcp:connect("localhost", 9000,[{active, false}]),
|
||||
{ok,Socket} = gen_tcp:connect("ggs.jeena.net", 9000,[{active, false}]),
|
||||
Socket.
|
||||
|
||||
read(Socket, Ref) ->
|
||||
|
|
|
@ -111,6 +111,7 @@ handle_cast({srv_cmd, "define", _Headers, Data}, #state { table = Table } = Stat
|
|||
{noreply, State};
|
||||
|
||||
handle_cast({game_cmd, Command, _Headers, Data}, #state { table = Table } = State) ->
|
||||
ggs_stats:message(),
|
||||
ggs_table:notify(Table, self(), {game, Command, Data}),
|
||||
{noreply, State};
|
||||
|
||||
|
|
47
src/ggs_stats.erl
Normal file
47
src/ggs_stats.erl
Normal file
|
@ -0,0 +1,47 @@
|
|||
-module(ggs_stats).
|
||||
-export([start_link/0, message/0, print/0, tick/0]).
|
||||
-behaviour(gen_server).
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
-vsn(0).
|
||||
|
||||
-record(ate, { count = 0 }).
|
||||
-define(SERVER, ?MODULE).
|
||||
|
||||
message() ->
|
||||
gen_server:cast(ggs_stats, add_one).
|
||||
|
||||
print() ->
|
||||
gen_server:cast(ggs_stats, print).
|
||||
|
||||
tick() ->
|
||||
print(),
|
||||
gen_server:cast(ggs_stats, tick),
|
||||
timer:apply_after(1000, ggs_stats, tick, []).
|
||||
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?SERVER}, ?MODULE, [0], []).
|
||||
|
||||
|
||||
init([Count]) ->
|
||||
St = #ate{ count = Count },
|
||||
{ok, St}.
|
||||
|
||||
handle_cast(add_one, St) ->
|
||||
NewSt = #ate { count = St#ate.count + 1},
|
||||
{noreply, NewSt};
|
||||
|
||||
handle_cast(print, St) ->
|
||||
erlang:display(St#ate.count),
|
||||
{noreply, St};
|
||||
|
||||
handle_cast(tick, _St) ->
|
||||
NewSt = #ate { count = 0 },
|
||||
{noreply, NewSt}.
|
||||
|
||||
|
||||
|
||||
handle_call(_Request, _From, St) -> {stop, unimplemented, St}.
|
||||
handle_info(_Info, St) -> {stop, unimplemented, St}.
|
||||
terminate(_Reason, _St) -> ok.
|
||||
code_change(_OldVsn, St, _Extra) -> {ok, St}.
|
Reference in a new issue