diff options
Diffstat (limited to 'server/dispatcher.erl')
-rw-r--r-- | server/dispatcher.erl | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/server/dispatcher.erl b/server/dispatcher.erl new file mode 100644 index 0000000..86b2627 --- /dev/null +++ b/server/dispatcher.erl @@ -0,0 +1,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}. |