aboutsummaryrefslogblamecommitdiffstats
path: root/server/dispatcher.erl
blob: a296c7850dd4a58c72e6d9720f032d430b1a2f8e (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                

                                 
                                             
            



                                                                  
                                 

                                                          
            




                                                     
-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, Dict) of
	{ok, _}->
	    {{error, duplicated_user}, Dict};
	_ ->
	    {{ok, user_created}, dict:store(User, Password, Dict)}
    end;

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

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