--- a/src/rps.erl Sun Mar 02 22:41:13 2014 +0900
+++ b/src/rps.erl Mon Mar 03 15:09:55 2014 +0900
-define(BOTS, [fool, copycat, gambler]).
- register(nickserv, spawn_link(rps_nickserv, nickserv, [])),
+ rps_nickserv:start_link(),
register(lobby, spawn_link(?MODULE, lobby, [])),
register(counter, spawn_link(?MODULE, counter, [])),
register(printer, spawn_link(?MODULE, printer, [])),
--- a/src/rps_bots.erl Sun Mar 02 22:41:13 2014 +0900
+++ b/src/rps_bots.erl Mon Mar 03 15:09:55 2014 +0900
-export([fool/0, copycat/0, gambler/0]).
- nickserv ! {nick, self(), "fool"},
+ rps_nickserv:nick(self(), "fool"),
- nickserv ! {nick, self(), "copycat"},
+ rps_nickserv:nick(self(), "copycat"),
- nickserv ! {nick, self(), "gambler"},
+ rps_nickserv:nick(self(), "gambler"),
--- a/src/rps_nickserv.erl Sun Mar 02 22:41:13 2014 +0900
+++ b/src/rps_nickserv.erl Mon Mar 03 15:09:55 2014 +0900
--export([nickserv/0, whois/1]).
+-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]).
+ gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
- {nick, Who, Nickname} ->
- nickserv(dict:store(Who, Nickname, Nicknames));
- Pid ! {ok, dict:fetch(Who, Nicknames)},
+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}.
+ gen_server:call(?MODULE, {nick, Who, Nickname}).
- nickserv ! {whois, self(), Who},
- {ok, Nickname} -> Nickname
+ gen_server:call(?MODULE, {whois, Who}).