aboutsummaryrefslogtreecommitdiffstats
path: root/server/dispatcher.erl
blob: 86b262795e04b58e244e64e8ae493fb1a3e021ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-module(dispatcher).
-export([start/0, init/0, handle/3]).

start() ->
    server:start(dis, dispatcher).

init() ->
    dict:new().

handle(_, {register, {User, Password}}, Dict) ->
    case dict:find(User) of
	{ok, _} ->
	    {{error, duplicated_user}, Dict};
	true ->
	    {{ok, user_created}, dict:store(User, Password, Dict)}
    end;

handle(From, {login, {User, Password}}, Dict) ->
    case dict:find(User) of
	{ok, Password} ->
	    {{ok, {logged_in, client:start(From)}}, Dict};
	true ->
	    {{error, user_or_password_invalid}, Dict}
    end;

handle(_, _, Dict) ->
    {{error, unknown_command}, Dict}.