pre-merge into master
[brisk.git] / web / index_wr.php
index e2f67ea..5b05c68 100644 (file)
@@ -105,18 +105,18 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie)
 
     /* if the IP is banned, exit without do nothing */
     if (array_search($remote_addr, $G_black_list) !== FALSE) {
-        sleep(5);
+        // TODO: find a way to add a nonblocking sleep(5) here
         return (FALSE);
     }
 
     $is_spawn = FALSE;
-    
+
     log_wr(0, 'index_wr.php: COMM: '.xcapemesg($mesg));
     log_wr('COMM: '.xcapemesg($mesg));
-    
+
     $curtime = time();
     $dt = date("H:i ", $curtime);
-    
+
     if (($user = $room->get_user($sess, &$idx)) == FALSE) {
         $argz = explode('|', xcapemesg($mesg));
 
@@ -184,9 +184,6 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie)
         else if ($argz[0] == 'whysupport') {
             echo show_notify(str_replace("\n", " ", $G_room_whysupport[$G_lang]), 0, $mlang_indwr['btn_close'][$G_lng], 400, 200);
         }
-        else if ($argz[0] == 'prefs') {
-            fprintf(STDERR, "\n\n PREFS \n\n");
-        }
         else { 
             log_wr("Get User Error");
             echo "Get User Error:" + $argz[0];
@@ -195,8 +192,6 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie)
         return TRUE;
     }
 
-
-
     $argz = explode('|', xcapemesg($mesg));
 
     log_wr('POSTSPLIT: '.$argz[0]);
@@ -204,9 +199,46 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie)
     // 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.");