aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMichael Wittig <michael.wittig@fu-berlin.de>2010-10-14 17:38:47 +0200
committerMichael Wittig <michael.wittig@fu-berlin.de>2010-10-14 17:38:47 +0200
commit5697eac2876904546954e48577763713c03eb935 (patch)
tree840eb04acca1645a707039e084681e7c6bc51742 /client
parent4741ca84bd516bcf5b65854e2661f7842599c4fc (diff)
parent05666998e1dce513f1df82353364c026f992cbb4 (diff)
downloaderlang-5697eac2876904546954e48577763713c03eb935.tar.gz
erlang-5697eac2876904546954e48577763713c03eb935.tar.xz
erlang-5697eac2876904546954e48577763713c03eb935.zip
Merge branch 'master' of ssh://git.animux.de/erlang
Diffstat (limited to 'client')
-rw-r--r--client/client.erl36
1 files changed, 30 insertions, 6 deletions
diff --git a/client/client.erl b/client/client.erl
index 0e2fada..f500fe1 100644
--- a/client/client.erl
+++ b/client/client.erl
@@ -1,5 +1,5 @@
-module(client).
--export([register/3, login/3, list/0, handle/2, getVotes/0, vote/2, devote/2]).
+-export([register/2, register/3, login/3, list/0, handle/2, getVotes/0, vote/2, devote/2]).
checkLogin(Value) ->
%% check if user meets the requirements to be locked in or not by
@@ -17,13 +17,34 @@ buildNode(Server) ->
rpc(Server, Function, Params) ->
rpc:call(buildNode(Server), client, Function, Params).
-register(Server, Name, Password) ->
- rpc(Server, register, [self(), {Name, Password}]),
+wait_for_reply() ->
receive
{_, Msg} ->
- Msg
+ Msg;
+ Why -> Why
+ after 3000 ->
+ {error, timeout}
+ end.
+
+register(Name, Password) ->
+ try checkLogin(true) of
+ _ ->
+ server:rpc(cli, {register, Name, Password})
+ catch
+ {error, login_state} ->
+ {error, not_logged_in}
end.
+register(Server, Name, Password) ->
+ try checkLogin(false) of
+ _ ->
+ rpc(Server, register, [self(), {Name, Password}])
+ catch
+ {error, login_state} ->
+ {error, logged_in}
+ end,
+ wait_for_reply().
+
login(Server, Name, Password) ->
code:purge(server),
code:load_abs("../common/server"),
@@ -33,12 +54,14 @@ login(Server, Name, Password) ->
rpc(Server, login, [self(), {node(), Name, Password}]),
receive
{ok, {ok, {logged_in, Pid}}} ->
- register(cli, Pid),
+ erlang:register(cli, Pid),
{ok, logged_in};
{_, Msg} ->
Msg;
Msg ->
Msg
+ after 3000 ->
+ {error, timeout}
end
catch
{error, login_state} ->
@@ -71,7 +94,8 @@ handle({vote, Artist, Title}, Server) ->
send_to_server({vote, Artist, Title}, Server);
handle({devote, Artist, Title}, Server) ->
send_to_server({devote, Artist, Title}, Server);
-
+handle({register, Name, Password}, Server) ->
+ send_to_server({register, Name, Password}, Server);
handle({change_state, NewState}, _) ->
{{ok}, NewState};