mirror of
https://github.com/correl/riichi.git
synced 2024-11-23 11:09:56 +00:00
Dummy player and game lobby
This commit is contained in:
parent
b4f1d1a95c
commit
3e4f3aa6a9
2 changed files with 76 additions and 0 deletions
36
src/player_dummy.erl
Normal file
36
src/player_dummy.erl
Normal file
|
@ -0,0 +1,36 @@
|
|||
-module(player_dummy).
|
||||
-behaviour(gen_server).
|
||||
|
||||
-export([start_link/1]).
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
|
||||
code_change/3]).
|
||||
|
||||
-record(state, {name}).
|
||||
|
||||
start_link(Name) ->
|
||||
gen_server:start_link(?MODULE, [Name], []).
|
||||
|
||||
init([Name]) ->
|
||||
{ok, #state{name=Name}}.
|
||||
|
||||
handle_call(_Msg, _From, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_cast({message, _From, Body}, State) ->
|
||||
error_logger:info_report({message_received,
|
||||
{self, self()},
|
||||
{state, State},
|
||||
{body, Body}}),
|
||||
{noreply, State};
|
||||
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_info(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
40
src/server_lobby.erl
Normal file
40
src/server_lobby.erl
Normal file
|
@ -0,0 +1,40 @@
|
|||
-module(server_lobby).
|
||||
-behaviour(gen_server).
|
||||
|
||||
-export([start_link/0]).
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
|
||||
code_change/3]).
|
||||
|
||||
-record(state, {players=[]}).
|
||||
|
||||
start_link() ->
|
||||
gen_server:start_link(?MODULE, [], []).
|
||||
|
||||
init([]) ->
|
||||
{ok, #state{}}.
|
||||
|
||||
handle_call({add_player, Player}, _From, State) ->
|
||||
{reply, ok, State#state{players=[Player|State#state.players]}};
|
||||
|
||||
handle_call(get_players, _From, State) ->
|
||||
{reply, State#state.players, State};
|
||||
|
||||
handle_call(_Msg, _From, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_cast({send, {message, From, Body}=Message}, State) ->
|
||||
Players = State#state.players,
|
||||
[gen_server:cast(Pid, Message) || Pid <- Players],
|
||||
{noreply, State};
|
||||
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_info(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
Loading…
Reference in a new issue