X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=modules%2Ferl%2Feuphorik_bd.erl;h=b938f757c3c490785becda5c6eb0bb795138542a;hb=bde82d4691e6bb96f841307b8e2771cec5996e5d;hp=6fc651d8aa34a39aeb3a0b4cc7e5bfe9b06b6e08;hpb=28cbabecbfc2e05861779a19e5a75bddbc0ad416;p=euphorik.git diff --git a/modules/erl/euphorik_bd.erl b/modules/erl/euphorik_bd.erl index 6fc651d..b938f75 100755 --- a/modules/erl/euphorik_bd.erl +++ b/modules/erl/euphorik_bd.erl @@ -1,8 +1,26 @@ -% 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 permet de gérer les données persistantes lié au site d'euphorik.ch. % Il permet d'ajouter des message, de demande les messages sur une page donnée, etc.. % Ce module utilise une base mnesia. -% @author G.Burri +% @author G.Burri + -module(euphorik_bd). -export([ @@ -54,7 +72,6 @@ % trolls : trolls/0, trolls/1, - trolls_attente/1, put_troll/2, mod_troll/2, del_troll/1, @@ -388,7 +405,7 @@ nouveau_message(Mess, Auteur_id, Repond_A) -> % est-ce que l'auteur à trop floodé ? if Auteur#user.indice_flood =/= ?INDICE_SPAM_MAX, Auteur_maj#user.indice_flood =:= ?INDICE_SPAM_MAX, Delta =< ?DUREE_BLOCAGE_SPAM -> mnesia:write(Auteur#user{indice_flood = Auteur_maj#user.indice_flood}), - nouveau_message_sys(Auteur#user.pseudo ++ if Auteur#user.login =/= [] -> " (" ++ Auteur#user.login ++ ")"; true -> "" end ++ " est bloqué pour " ++ integer_to_list(trunc(?DUREE_BLOCAGE_SPAM / 1000)) ++ " secondes pour cause de flood."); + nouveau_message_sys("''" ++ Auteur#user.pseudo ++ if Auteur#user.login =/= [] -> " (" ++ Auteur#user.login ++ ")"; true -> "" end ++ "'' est bloqué pour " ++ integer_to_list(trunc(?DUREE_BLOCAGE_SPAM / 1000)) ++ " secondes pour cause de flood."); Auteur#user.indice_flood =:= ?INDICE_SPAM_MAX, Delta =< ?DUREE_BLOCAGE_SPAM -> {erreur, "Bloqué pour cause de flood"}; true -> @@ -555,7 +572,7 @@ list_ban() -> e(q([{U#user.pseudo, U#user.login} || U <- mnesia:table(user), U#user.last_ip =:= IP#ip_table.ip])) } || IP <- qlc:keysort(2, mnesia:table(ip_table)), - date_plus_minutes(IP#ip_table.ban, IP#ip_table.ban_duration) > Now + if IP#ip_table.ban =:= undefined -> false; true -> date_plus_minutes(IP#ip_table.ban, IP#ip_table.ban_duration) > Now end ])) end )). @@ -655,58 +672,11 @@ trolls() -> % Renvoie les trolls manquants posté après Last_id. trolls(Last_id) -> resultat_transaction(mnesia:transaction( - e(q([T || T <- qlc:keysort(2, mnesia:table(troll)), T#troll.id > Last_id, T#troll.date_post =:= undefined])) + fun() -> + e(q([T || T <- qlc:keysort(2, mnesia:table(troll)), T#troll.id > Last_id, T#troll.date_post =:= undefined])) + end )). - -% Renvoie les trolls manquants posté après Last_id. -% Si pas de trolls alors attend un événement tel qu'un ajout, une modification ou une suppression. -% renvoie : -% {mod, Troll} -% ou {add, [Trolls]} -% ou {del, Troll_id} -% ou timeout -trolls_attente(Last_id) -> - case mnesia:subscribe({table, troll, detailed}) of - {error, E} = E -> - E; - _ -> - R = case resultat_transaction(mnesia:transaction( - fun() -> - e(q([T || T <- qlc:keysort(2, mnesia:table(troll)), T#troll.id > Last_id, T#troll.date_post =:= undefined])) - end - )) of - [] -> % pas de trolls - attend_evenement_troll(); - Trolls -> - {add, Trolls} - end, - mnesia:unsubscribe({table, troll, detailed}), - R - end. - -attend_evenement_troll() -> - % s'il n'y a pas de trolls que l'utilisateur n'a pas connaissance alors on attend un événement - receive - % cas où un troll est choisit comme courant - {mnesia_table_event, {write, troll, Troll, [Old_troll | _], _}} when Old_troll#troll.date_post =:= undefined, Troll#troll.date_post =/= undefined -> - {del, Troll#troll.id}; - {mnesia_table_event, {write, troll, Troll, [_Old_troll | _], _}} -> - {mod, Troll}; - {mnesia_table_event, {write, troll, Troll, [], _}} -> - {add, [Troll]}; - {mnesia_table_event, {delete, troll, {troll, Id}, _, _}} -> - {del, Id}; - {tcp_closed, _} -> - exit(normal); - _ -> - attend_evenement_troll() - % 60 minutes de timeout (on ne sais jamais) - % Après 60 minutes de connexion, le client doit donc reétablir une connexion - after 1000 * 60 * 60 -> - timeout - end. - % Renvoie l'id du nouveau troll % ou max_troll_reached_per_user si le nombre de troll posté par l'utilisateur max a été atteind