Download:
child 32:e528c326cf10
parent 30:efdf4524dafd
31:72639365f60a
Anton Shestakov <engored@ya.ru>, Sun, 02 Mar 2014 22:41:13 +0900
Dedicated service: rps_nickserv.

3 файлов изменено, 24 вставок(+), 0 удалений(-) [+]
src/rps.erl file | annotate | diff | comparison | revisions
src/rps_bots.erl file | annotate | diff | comparison | revisions
src/rps_nickserv.erl file | annotate | diff | comparison | revisions
--- a/src/rps.erl Sun Mar 02 22:10:59 2014 +0900
+++ b/src/rps.erl Sun Mar 02 22:41:13 2014 +0900
@@ -6,6 +6,7 @@
-define(BOTS, [fool, copycat, gambler]).
go() ->
+ register(nickserv, spawn_link(rps_nickserv, nickserv, [])),
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:10:59 2014 +0900
+++ b/src/rps_bots.erl Sun Mar 02 22:41:13 2014 +0900
@@ -3,6 +3,7 @@
-export([fool/0, copycat/0, gambler/0]).
fool() ->
+ nickserv ! {nick, self(), "fool"},
lobby ! {join, self()},
fool(joined).
@@ -24,6 +25,7 @@
end.
copycat() ->
+ nickserv ! {nick, self(), "copycat"},
lobby ! {join, self()},
copycat(joined).
@@ -43,6 +45,7 @@
end.
gambler() ->
+ nickserv ! {nick, self(), "gambler"},
lobby ! {join, self()},
gambler(joined).
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/rps_nickserv.erl Sun Mar 02 22:41:13 2014 +0900
@@ -0,0 +1,20 @@
+-module(rps_nickserv).
+-export([nickserv/0, whois/1]).
+
+nickserv() ->
+ nickserv(dict:new()).
+
+nickserv(Nicknames) ->
+ receive
+ {nick, Who, Nickname} ->
+ nickserv(dict:store(Who, Nickname, Nicknames));
+ {whois, Pid, Who} ->
+ Pid ! {ok, dict:fetch(Who, Nicknames)},
+ nickserv(Nicknames)
+ end.
+
+whois(Who) ->
+ nickserv ! {whois, self(), Who},
+ receive
+ {ok, Nickname} -> Nickname
+ end.