33:654a2f3e9ccf
Anton Shestakov <engored@ya.ru>, Mon, 03 Mar 2014 15:37:24 +0900
Each room has its own set of rules.

next change 47:e923d8296d25
previous change 32:e528c326cf10

src/rps_nickserv.erl

Permissions: -rw-r--r--

Other formats: Feeds:
-module(rps_nickserv).
-behaviour(gen_server).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-export([start_link/0, nick/2, whois/1]).
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
init([]) ->
{ok, dict:new()}.
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) ->
{reply, dict:fetch(Who, Nicknames), Nicknames}.
handle_cast(_Msg, State) -> {noreply, State}.
handle_info(_Msg, State) -> {noreply, State}.
terminate(_Reason, _State) -> ok.
code_change(_OldVersion, State, _Extra) -> {ok, State}.
nick(Who, Nickname) ->
gen_server:call(?MODULE, {nick, Who, Nickname}).
whois(Who) ->
gen_server:call(?MODULE, {whois, Who}).