X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=modules%2Ferl%2Feuphorik_protocole.erl;h=ae79d849e55eba5297f3401c663a101c51b40cb4;hp=8056f6be6f3b9d3cf2d8fff69ee6bcc26bb06b84;hb=63d7601eeee2660728be1ff778dd7e6a04246ee5;hpb=327c3bd99f586f3cf3af55f9adb10a71eb78cdd4 diff --git a/modules/erl/euphorik_protocole.erl b/modules/erl/euphorik_protocole.erl index 8056f6b..ae79d84 100755 --- a/modules/erl/euphorik_protocole.erl +++ b/modules/erl/euphorik_protocole.erl @@ -1,7 +1,25 @@ -% coding: utf-8 +% coding: utf-8 +% Copyright 2008 Grégory Burri +% +% This file is part of Euphorik. +% +% Euphorik is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Euphorik is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Euphorik. If not, see . +% % Ce module gére les différents messages envoyés par le client (javascript) via AJAX. % Les messages donnés ainsi que les réponses sont au format JSON. % @author G.Burri + -module(euphorik_protocole). -export([ @@ -20,7 +38,6 @@ list_banned_ips/1, erreur/1 ]). --include_lib("xmerl/include/xmerl.hrl"). -include("../include/euphorik_bd.hrl"). -include("../include/euphorik_defines.hrl"). @@ -68,13 +85,13 @@ loginUser({ok, User}, IP) -> json_reponse_login_ok(User); loginUser(_, _) -> % ajoute un délais d'attente - timer:sleep(1000), - erreur("Erreur login"). + timer:sleep(?TEMPS_ATTENTE_ERREUR_LOGIN), + erreur("Couple login/pass introuvable"). % Renvoie un string() représentant un cookie en base 36. Il y a 10^32 possibillités. generer_cookie() -> - {A1,A2,A3} = now(), + {A1, A2, A3} = now(), random:seed(A1, A2, A3), erlang:integer_to_list(random:uniform(math:pow(10, 32)), 36). @@ -94,6 +111,8 @@ profile( {email, Email}, {css, Css}, {nick_format, Nick_format_str}, + {view_times, View_times}, + {view_tooltips, View_tooltips}, {main_page, Main_page}, {conversations, {array, Conversations_json}} ] @@ -111,7 +130,19 @@ profile( [], Conversations_json ), - case euphorik_bd:set_profile(Cookie, Login, Password, Pseudo, Email, Css, list_to_atom(Nick_format_str), Main_page, Conversations) of + % TODO : pas très beau, mieux vaut construire un #user + case euphorik_bd:set_profile( + Cookie, + Login, + Password, + Pseudo, + Email, + Css, + list_to_atom(Nick_format_str), + View_times, + View_tooltips, + Main_page, + Conversations) of ok -> json_reponse_ok(); login_deja_pris -> @@ -211,6 +242,7 @@ wait_event_page_chat(User, Racines_conversations, Message_count, Last_message_id {struct, [ {reply, "new_troll"}, {troll_id, Current#troll.id}, + {message_id, euphorik_bd:message_id_associe(Current#troll.id)}, {content, Current#troll.content} ]}; _ -> @@ -523,7 +555,7 @@ unban_ip( ) -> case euphorik_bd:user_by_cookie(Cookie) of {ok, #user{ek_master = true}} -> - euphorik_bd:deban(unserialize_ip(IP)), + euphorik_bd:deban(euphorik_common:unserialize_ip(IP)), json_reponse_ok(); _ -> erreur("Seul les ekMaster peuvent connaitre la liste des ips bannies") @@ -545,7 +577,7 @@ list_banned_ips( fun({IP, T, Users}) -> {struct, [ - {ip, serialize_ip(IP)}, + {ip, euphorik_common:serialize_ip(IP)}, {remaining_time, format_minutes(T)}, {users, {array, lists:map( fun({Pseudo, Login}) -> @@ -579,17 +611,6 @@ erreur(Message) -> ] }. - -serialize_ip(IP) -> - lists:flatten(io_lib:format("~w.~w.~w.~w", tuple_to_list(IP))). - - -unserialize_ip(IP) -> - case io_lib:fread("~d.~d.~d.~d", IP) of - {ok, [A, B, C, D], []} -> {A, B, C, D}; - _ -> erreur - end. - % Formatage de minutes. % par exemple : "1min", "45min", "1h23min", "1jour 2h34min" @@ -644,6 +665,8 @@ json_reponse_login_ok(User) -> {email, User#user.email}, {css, User#user.css}, {nick_format, atom_to_list(User#user.nick_format)}, + {view_times, User#user.view_times}, + {view_tooltips, User#user.view_tooltips}, {main_page, User#user.page_principale}, {conversations, {array,