Anton Shestakov <engored@ya.ru>, Sat, 08 Mar 2014 23:40:26 +0900
Test rps3:why/2 and rps5:why/2.
src/rps_nickserv.erl
Permissions: -rw-r--r--
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([start_link/0, nick/2, nick/3, whois/1, whois/2]). gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). handle_call({nick, Who, Nickname}, _From, Nicknames) -> io:format("~w registered as ~s.~n", [Who, Nickname]), {reply, ok, dict:store(Who, Nickname, Nicknames)}; handle_call({whois, Who}, _From, Nicknames) -> N = case dict:find(Who, Nicknames) of {ok, Nickname} -> Nickname; handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Msg, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVersion, State, _Extra) -> {ok, State}. nick(?MODULE, Who, Nickname). nick(Pid, Who, Nickname) -> gen_server:call(Pid, {nick, Who, Nickname}). gen_server:call(Pid, {whois, Who}).