+% Décode le message JSON.\r
+traiter_message(Contenu, IP) ->\r
+ % extrait l'entête obligatoire des messages JSON\r
+ {ok, {struct, [{header, {struct, [{action, Action}, {version, Version_client}]}} | Reste]}} = json:decode_string(Contenu),\r
+ json:encode(\r
+ if Version_client =:= ?VERSION_PROTOCOLE ->\r
+ traiter_action(Action, Reste, IP);\r
+ true ->\r
+ euphorik_protocole:erreur(lists:flatten(io_lib:format(\r
+ "La version du protocole du client (~w) ne correspond à celle du serveur (~w)", [Version_client, ?VERSION_PROTOCOLE]\r
+ )))\r
+ end\r
+ ).\r
+ \r
+\r
+% Authentification d'un client.\r
+traiter_action("authentification", JSON, IP) ->\r
+ euphorik_protocole:login(JSON, IP);\r
+% Un client s'enregistre : (pseudo + password) ou de manière anonyme.\r
+traiter_action("register", JSON, IP) ->\r
+ euphorik_protocole:register(JSON, IP);\r
+% Modification du profile.\r
+traiter_action("set_profile", JSON, _) ->\r
+ euphorik_protocole:profile(JSON);\r
+% Un utilisateur attend un événement (par exemple l'arrivée d'un nouveau message).\r
+traiter_action("wait_event", JSON, _) ->\r
+ euphorik_protocole:wait_event(JSON);\r
+% Un utilisateur envoie un message.\r
+traiter_action("put_message", JSON, _) ->\r
+ euphorik_protocole:put_message(JSON);\r
+% Un ekMaster bannie un utilisateur (ip).\r
+traiter_action("ban", JSON, _) ->\r
+ euphorik_protocole:ban(JSON);\r
+% Un ekMaster slap un utilisateur.\r
+traiter_action("slap", JSON, _) ->\r
+ euphorik_protocole:slap(JSON);\r
+% Un ekMaster envoie un nouveau troll.\r
+traiter_action("put_troll", JSON, _) ->\r
+ euphorik_protocole:put_troll(JSON);\r
+% Un ekMaster modifie un troll.\r
+traiter_action("mod_troll", JSON, _) ->\r
+ euphorik_protocole:mod_troll(JSON);\r
+% Un ekMaster supprime un troll.\r
+traiter_action("del_troll", JSON, _) ->\r
+ euphorik_protocole:del_troll(JSON);\r
+% Un ekMaster demande la liste des ips bannies.\r
+traiter_action("list_banned_ips", JSON, _) ->\r
+ euphorik_protocole:list_banned_ips(JSON);\r
+% Un ekMaster débannie une ip.\r
+traiter_action("unban", JSON, _) ->\r
+ euphorik_protocole:unban_ip(JSON).\r
+
\ No newline at end of file