X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=modules%2Ferl%2Feuphorik_requests.erl;h=5c2e538ff8a4cf3fc7bf09a8ceb877e1ec032c4e;hb=81b3e94e62dd60087d71efc42004f8222d9e1e7a;hp=13a86cb514480ffb4967f00cd814e517e412835b;hpb=0b34258466c58a805a2cbfe7ef134385b26fed94;p=euphorik.git diff --git a/modules/erl/euphorik_requests.erl b/modules/erl/euphorik_requests.erl index 13a86cb..5c2e538 100755 --- a/modules/erl/euphorik_requests.erl +++ b/modules/erl/euphorik_requests.erl @@ -12,44 +12,57 @@ -include_lib("xmerl/include/xmerl.hrl"). -include_lib("yaws/include/yaws_api.hrl"). + -% Test du module +% Test du module (TODO) tester() -> que_dal. -% il faut catcher toutes les exceptions possibles -out(A) -> +out(A) -> + %io:format("~p~n~n", [A]), + IP = case inet:peername(A#arg.clisock) of + {ok, {Adresse, _Port}} -> Adresse; + _ -> inconnue + end, %inet:setopts(A#arg.clisock, inet:getopts(A#arg.clisock, [active])), {value, {_, Contenu}} = lists:keysearch("action", 1, yaws_api:parse_post(A)), - Ret = traiter_donnees(Contenu), - %{content, "text/xml", Ret}. + Ret = traiter_donnees(Contenu, IP), {content, "application/json", Ret}. -traiter_donnees(Contenu) -> +traiter_donnees(Contenu, IP) -> case json:decode_string(Contenu) of {ok, {struct, [{action, Action}| Reste]}} -> - %io:format("~p~n", [euphorik_protocole:login(JSON)]), - json:encode(traiter_action(Action, Reste)); + json:encode(traiter_action(Action, Reste, IP)); _ -> error end. % authentification d'un client -traiter_action("authentification", JSON) -> - euphorik_protocole:login(JSON); +traiter_action("authentification", JSON, IP) -> + euphorik_protocole:login(JSON, IP); % un client s'enregistre (pseudo + password) -traiter_action("register", JSON) -> - euphorik_protocole:register(JSON); +traiter_action("register", JSON, IP) -> + euphorik_protocole:register(JSON, IP); % modification du profile -traiter_action("set_profile", JSON) -> +traiter_action("set_profile", JSON, _) -> euphorik_protocole:profile(JSON); % un utilisateur attend un événement (par exemple l'arrivé d'un nouveau message) -traiter_action("wait_event", JSON) -> +traiter_action("wait_event", JSON, _) -> euphorik_protocole:wait_event(JSON); % un utilisateur envoie un message -traiter_action("put_message", JSON) -> - euphorik_protocole:put_message(JSON). +traiter_action("put_message", JSON, _) -> + euphorik_protocole:put_message(JSON); +traiter_action("ban", JSON, _) -> + euphorik_protocole:ban(JSON); +traiter_action("slap", JSON, _) -> + euphorik_protocole:slap(JSON); +traiter_action("put_troll", JSON, _) -> + euphorik_protocole:put_troll(JSON); +traiter_action("mod_troll", JSON, _) -> + euphorik_protocole:mod_troll(JSON); +traiter_action("del_troll", JSON, _) -> + euphorik_protocole:del_troll(JSON). \ No newline at end of file