-/* $argz = explode('|', xcapemesg($mesg)); */
-
-/* log_wr('POSTSPLIT: '.$argz[0]); */
-
-/* log_wr($user->step, 'index_wr.php: after get_user()'); */
-
-/* if ($argz[0] == 'shutdown') { */
-/* log_auth($user->sess, "Shutdown session."); */
-
-/* $user->reset(); */
-
-/* log_rd2("AUTO LOGOUT."); */
-/* if ($user->subst == 'sitdown' || $user->stat == 'table') */
-/* $room->room_wakeup($user); */
-/* else if ($user->subst == 'standup') */
-/* $room->room_outstandup(&$user); */
-/* else { */
-/* log_rd2("SHUTDOWN FROM WHAT ???"); */
-/* } */
-/* } */
-/* else if ($argz[0] == 'warranty') { */
-/* GLOBAL $cli_name, $cli_email; */
-
-/* $mesg_to_user = ""; */
-
-/* log_wr("INFO:SKIP:argz == warranty name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH)); */
-/* if ($user->flags & USER_FLAG_AUTH) { */
-/* if (($wa_lock = Warrant::lock_data(TRUE)) != FALSE) { */
-/* if (($fp = @fopen(LEGAL_PATH."/warrant.txt", 'a')) != FALSE) { */
-/* /\* Unix time | session | nickname | IP | where was | mesg *\/ */
-/* fwrite($fp, sprintf("%ld|%s|%s|%s|\n", $curtime, xcapelt($user->name), xcapelt(urldecode($cli_name)), xcapelt(urldecode($cli_email)))); */
-/* fclose($fp); */
-/* } */
-/* Warrant::unlock_data($wa_lock); */
-/* $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; */
-/* /\* MLANG: "<br>Il nominativo è stato inoltrato all\'amministratore.<br><br>Nell\'arco di pochi giorni vi verrà<br><br>notificata l\'avvenuta registrazione." *\/ */
-/* $user->comm[$user->step % COMM_N] .= show_notify($mlang_indwr['warrrepl'][$G_lang], 0, $mlang_indwr['btn_close'][$G_lang], 400, 150); */
-/* $user->step_inc(); */
-/* echo "1"; */
-/* } */
-/* else { */
-/* /\* MLANG: "<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>" *\/ */
-/* $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['commerr'][$G_lang]); */
-/* } */
-
-/* } */
-/* else { */
-/* /\* MLANG: "<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>" *\/ */
-/* $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['warrmust'][$G_lang]); */
-/* } */
-
-/* if ($mesg_to_user != "") { */
-/* $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; */
-
-/* $user->comm[$user->step % COMM_N] .= $mesg_to_user; */
-/* $user->step_inc(); */
-/* } */
-/* } */
-/* else if ($argz[0] == 'mesgtoadm') { */
-/* GLOBAL $cli_subj, $cli_mesg; */
-
-/* $mesg_to_user = ""; */
-
-/* log_wr("INFO:SKIP:argz == mesgtoadm name: [".$user->name."] AUTH: ".($user->flags & USER_FLAG_AUTH)); */
-/* if ($user->flags & USER_FLAG_AUTH) { */
-/* if (($wa_lock = Warrant::lock_data(TRUE)) != FALSE) { */
-/* if (($bdb = BriskDB::create()) != FALSE) { */
-/* $bdb->users_load(); */
-
-/* if (($ema = $bdb->getmail($user->name)) != FALSE) { */
-/* // mail("nastasi", */
-/* mail("brisk@alternativeoutput.it", urldecode($cli_subj), urldecode($cli_mesg), sprintf("From: %s <%s>", $user->name, $ema)); */
-/* } */
-
-/* if (($fp = @fopen(LEGAL_PATH."/messages.txt", 'a')) != FALSE) { */
-/* /\* Unix time | session | nickname | IP | where was | mesg *\/ */
-/* fwrite($fp, sprintf("%ld|%s|%s|%s\n", $curtime, $user->name, */
-/* xcapelt(urldecode($cli_subj)), xcapelt(urldecode($cli_mesg)))); */
-/* fclose($fp); */
-/* } */
-/* Warrant::unlock_data($wa_lock); */
-/* $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; */
-/* /\* MLANG: "" *\/ */
-/* $user->comm[$user->step % COMM_N] .= show_notify($mlang_indwr['mesgrepl'][$G_lang], 0, $mlang_indwr['btn_close'][$G_lang], 400, 110); */
-/* $user->step_inc(); */
-/* echo "1"; */
-/* } */
-/* else { */
-/* /\* MLANG: "<b>Il database è temporaneamente irraggiungibile, riprova più tardi o contatta l\'amministratore.</b>" *\/ */
-/* $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['coerrdb'][$G_lang]); */
-/* $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; */
-/* } */
-/* } */
-/* else { */
-/* /\* MLANG: "<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>" *\/ */
-/* $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['commerr'][$G_lang]); */
-/* } */
+ // LACC UPDATED
+ $user->lacc = $curtime;
+
+ if (array_search($user->ip, $G_black_list) !== FALSE) {
+ // TODO: find a way to add a nonblocking sleep(5) here
+ return (FALSE);
+ }
+
+ if ($argz[0] == 'ping') {
+ log_wr("PING RECEIVED");
+ }
+ else if ($argz[0] == 'prefs') {
+ if ($argz[1] == 'save') {
+ if (!isset($post['prefs'])) {
+ return FALSE;
+ }
+
+ if (($prefs = Client_prefs::from_json($post['prefs'])) == FALSE) {
+ $prefs = Client_prefs::from_user($user);
+ }
+ $prefs->store($user, TRUE);
+ }
+ else { // reset case as default
+ $prefs = Client_prefs::from_user($user);
+ }
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+ $user->comm[$user->step % COMM_N] .= sprintf('prefs_load(\'%s\', true, %s);', json_encode($prefs),
+ 'false');
+ $user->step_inc();
+
+ if ($argz[1] == 'save') {
+ if ($user->stat == 'room' && $user->subst == 'standup') {
+ $room->standup_update($user);
+ }
+ else if ($user->stat == 'room' && $user->subst == 'sitdown') {
+ log_main("chatt_send pre table update");
+ $room->table_update($user);
+ log_main("chatt_send post table update");
+ }
+ }
+ echo "1";
+ return TRUE;
+ }
+ else if ($argz[0] == 'shutdown') {
+ log_auth($user->sess, "Shutdown session.");
+
+ $user->reset();
+
+ log_rd2("AUTO LOGOUT.");
+ if ($user->subst == 'sitdown' || $user->stat == 'table')
+ $room->room_wakeup($user);
+ else if ($user->subst == 'standup')
+ $room->room_outstandup(&$user);
+ else {
+ log_rd2("SHUTDOWN FROM WHAT ???");
+ }
+ }
+ else if ($argz[0] == 'warranty') {
+ if (($cli_name = gpcs_var('cli_name', $get, $post, $cookie)) === FALSE)
+ $cli_name = "";