aggiunto smammamorti
[brisk.git] / web / index_wr.php
index 4ce65cb..3133fe7 100644 (file)
@@ -17,6 +17,8 @@
  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
  * Suite 330, Boston, MA 02111-1307, USA.
  *
+ * $Id$
+ *
  */
 
 require_once("brisk.phh");
@@ -34,7 +36,7 @@ log_wr($sess, 'COMM: '.$mesg);
 
 $sem = lock_data();
 $bri = &load_data();
-if (($user = &get_user($bri, $sess, &$idx)) == FALSE) {
+if (($user = &$bri->get_user($sess, &$idx)) == FALSE) {
   echo "Get User Error";
   log_wr($sess, "Get User Error");
   unlock_data($sem);
@@ -42,8 +44,41 @@ if (($user = &get_user($bri, $sess, &$idx)) == FALSE) {
 }
 $argz = explode('|', $mesg);
 
-if ($user->stat == 'room') {
-  if ($argz[0] == 'logout') {
+if ($argz[0] == 'shutdown') {
+  log_auth($user_cur->sess, "Shutdown session.");
+  
+  $user->sess = "";
+  $user->name = "";
+  $user->the_end = FALSE;
+  
+  log_rd2($user->sess, "AUTO LOGOUT.");
+  if ($user->subst == 'sitdown' || $user->stat == 'table')
+    $bri->room_wakeup(&$user);
+  else if ($user->subst == 'standup')
+    $bri->room_outstandup(&$user);
+  else
+    log_rd2($sess, "SHUTDOWN FROM WHAT ???");
+}
+else if ($user->stat == 'room') {
+  $user->laccwr = time();
+
+  if ($argz[0] == 'help') {
+    $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+    $user->comm[$user->step % COMM_N] .=  show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
+
+    log_wr($sess, $user->comm[$user->step % COMM_N]);
+    $user->step++;
+    
+  }
+  else if ($argz[0] == 'about') {
+    $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+    $user->comm[$user->step % COMM_N] .=  show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
+
+    log_wr($sess, $user->comm[$user->step % COMM_N]);
+    $user->step++;
+    
+  }
+  else if ($argz[0] == 'logout') {
     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
     $user->comm[$user->step % COMM_N] .= sprintf('postact_logout();');
     $user->the_end = TRUE;
@@ -72,9 +107,7 @@ if ($user->stat == 'room') {
     // set new status
     $user->subst = "sitdown";
     $user->table = $table_idx;
-    $user->table_pos = $table->player_n;
-    $table->player[$table->player_n] = $idx;
-    $table->player_n++;
+    $user->table_pos = $table->user_add($idx);
                
     if ($table->player_n == PLAYERS_N) {
       // Start game for this table.
@@ -88,7 +121,7 @@ if ($user->stat == 'room') {
        log_wr($sess, "Pre if!");
        
        $ret = "";
-       $ret .= sprintf('gst.st_loc++; gst.st=%d; the_end=true; document.location.assign("table.php");|', $user_cur->step+1);
+       $ret .= sprintf('gst.st_loc++; gst.st=%d; the_end=true; window.onunload = null ; document.location.assign("table.php");|', $user_cur->step+1);
        
        $user_cur->comm[$user_cur->step % COMM_N] = $ret;
        $user_cur->trans_step = $user_cur->step + 1;
@@ -125,6 +158,7 @@ if ($user->stat == 'room') {
  *             *
  ***************/
 else if ($user->stat == 'table' && $user->subst == 'asta') {
+  $user->laccwr = time();
   $table = &$bri->table[$user->table];
 
   if ($argz[0] == 'logout') {
@@ -137,10 +171,7 @@ else if ($user->stat == 'table' && $user->subst == 'asta') {
     log_wr($sess, "PER DI TABLEINFO");
     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
     $user->comm[$user->step % COMM_N] .= show_table_info(&$bri, &$table, $user->table_pos);
-
     log_wr($sess, $user->comm[$user->step % COMM_N]);
-
-
     $user->step++;
   }
   else if ($argz[0] == 'chatt') {
@@ -210,8 +241,9 @@ else if ($user->stat == 'table' && $user->subst == 'asta') {
            $maxcard = $user_cur->asta_card;
        }
 
-       if ($table->asta_pla_n > ($maxcard > -1 ? 1 : 0) &&
+       if (($table->asta_pla_n > ($maxcard > -1 ? 1 : 0)) &&
            !($table->asta_card == 9 && $table->asta_pnt == 120)) {
+         log_wr($sess,"ALLOPPA QUI");
          for ($i = 1 ; $i < PLAYERS_N ; $i++) {
            $index_next = ($table->gstart + $i) % PLAYERS_N;
            if ($table->asta_pla[$index_next]) {
@@ -257,7 +289,7 @@ else if ($user->stat == 'table' && $user->subst == 'asta') {
        else {
          log_wr($sess, "FINITA !");
          // if a_pnt == 120 supergame ! else abbandono
-         if ($a_pnt == 120) {
+         if ($a_pnt == 120 || $user->asta_card != -1) {
            $chooser = $index_cur;
            for ($i = 1 ; $i < PLAYERS_N ; $i++) 
              if ($i != $chooser)