Merge branch 'together-for-fun' into nginx
authorMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 16 Jul 2017 15:44:27 +0000 (17:44 +0200)
committerMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 16 Jul 2017 15:44:27 +0000 (17:44 +0200)
1  2 
INSTALL.sh
web/Obj/brisk.phh
web/Obj/sac-a-push.phh
web/briskin5/index_wr.php
web/index_wr.php

diff --combined INSTALL.sh
@@@ -364,8 -364,6 +364,8 @@@ if [ "$web_only" = "FALSE" ]; the
      done
      chmod -R 777 ${proxy_path}/bin5
  
 +    mkdir -p "${legal_path}"
 +    chmod 777 "${legal_path}"
  fi
  install -d ${web_path}__
  for i in $(find web -type d | grep '/' | sed 's/^....//g'); do
@@@ -375,10 -373,6 +375,10 @@@ don
  for i in $(find web -name '.htaccess' -o -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name 'terms-of-service*' | sed 's/^....//g'); do
      install -m 644 "web/$i" "${web_path}__/$i"
  done
 +
 +# hardlink for nginx managed websocket files.
 +ln "${web_path}__/xynt_test01.php" "${web_path}__/xynt_test01_wss.php"
 +
  if [ "$test_add" = "TRUE" ]; then
      for i in $(find webtest -name '.htaccess' -o -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name 'terms-of-service*' | sed 's/^........//g'); do
          install -m 644 "webtest/$i" "${web_path}__/$i"
@@@ -431,7 -425,7 +431,7 @@@ sed -i "s@var \+cookiepath \+= \+\"[^\"
  sed -i "s@\( \+cookiepath *: *\)\"[^\"]*\" *,@\1 \"$prefix_path\",@g" ${web_path}__/xynt-streaming.js
  
  document_root="$(grep DocumentRoot "${apache_conf}"  | grep -v '^[    ]*#' | awk '{ print $2 }')"
- sed -i "s@^\(\$DOCUMENT_ROOT *= *[\"']\)[^\"']*\([\"']\)@\1$document_root\2@g" ${web_path}__/spush/*.ph*
+ sed -i "s@^\(\$DOCUMENT_ROOT *= *[\"']\)[^\"']*\([\"']\)@\1$document_root\2@g" ${web_path}__/spush/*.ph* ${web_path}__/donometer.php
  
  if [ -d ../brisk-img ]; then
      cd ../brisk-img
diff --combined web/Obj/brisk.phh
@@@ -153,10 -153,10 +153,10 @@@ $mlang_brisk = array( 'btn_backstand'=
  $G_lng = langtolng($G_lang);
  
  $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
- $G_brisk_version = "5.4.1";
+ $G_brisk_version = "5.4.2";
  
  /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
- $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: potete scegliere che regole usare per giocare dal menu "Prefs" al tavolo, descrizioni più consistenti.',
+ $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: uscita più veloce dal sito.',
                                         'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
                         'en' => array ( 'EN Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: puoi creare la tua rete di amicizie con /info,',
                                         'vedere cosa pensano i tuoi amici degli altri utenti e tavoli riservati per registrati e apprendisti.',
@@@ -1226,10 -1226,15 +1226,15 @@@ class Bris
  
      function users_cleanup()
      {
+         $curtime = time();
          for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
              $user_cur = $this->user[$i];
  
-             if ($user_cur->the_end) {
+             if ($user_cur->the_end
+                 && (($user_cur->rd_toflush == FALSE
+                      && $user_cur->rd_step == $user_cur->step)
+                     || $user_cur->rd_endtime_is_expired($curtime))
+                 ) {
                  $user_cur->reset(); // users_cleanup, OK
              }
          }
  
            break;
        case "index_rd.php":
 +      case "index_rd_wss.php":
            if (($transp  = gpcs_var('transp', $get, $post, $cookie)) === FALSE)
                $transp = "iframe";
 -          if ($transp == 'websocket')
 +          if ($transp == 'websocket' || $transp == 'websocketsec')
                $enc = 'plain';
  
            do {
            $subs = "briskin5/";
            $subs_l = strlen($subs);
            if (!strncmp($path, $subs, $subs_l)) {
 -              $ret = Bin5::request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, substr($path, $subs_l) , $addr, $get, $post, $cookie);
 +              $ret = Bin5::request_mgr($s_a_p, $header, $header_out, $new_socket, substr($path, $subs_l) , $addr, $get, $post, $cookie);
                return ($ret);
            }
            break;
diff --combined web/Obj/sac-a-push.phh
@@@ -571,7 -571,7 +571,7 @@@ class Sac_a_push 
  
      function pendpage_try_addcont(&$new_socket, $tout, $method, $header, $get, $post, $cookie, $path, $addr, $rest, $cont)
      {
 -        $pendpage = PendingPage::pendingpage_continue(&$new_socket, $this->curtime, $tout, $method,
 +        $pendpage = PendingPage::pendingpage_continue( $new_socket, $this->curtime, $tout, $method,
                                                             $header,           $get, $post, $cookie,
                                                               $path,          $addr, $rest, $cont);
  
          foreach ($this->socks as $k => $sock) {
              $id = intval($sock);
              if (isset($this->s2u[$id])) {
-                 if ($this->s2u[$id]->the_end) {
-                     if ($this->s2u[$id]->rd_socket_get() != NULL) {
-                         $this->s2u[$id]->rd_socket_set(NULL);
+                 $user = $this->s2u[$id];
+                 if ($user->the_end) {
+                     if (($user->rd_toflush == FALSE && $user->rd_step == $user->step)
+                         || $user->rd_endtime_is_expired($this->curtime)) {
+                         if ($user->rd_socket_get() != NULL) {
+                             $user->rd_socket_set(NULL);
+                         }
+                         unset($this->socks[$id]);
+                         unset($this->s2u[$id]);
+                         fclose($sock);
+                         printf("CLOSE ON GARBAGE MANAGER\n");
                      }
-                     unset($this->socks[$id]);
-                     unset($this->s2u[$id]);
-                     fclose($sock);
-                     printf("CLOSE ON GARBAGE MANAGER\n");
                  }
              }
          }
                  return cmd_return(401, 'malformed cmd');
              }
              $idx = -1;
 -            if (($user = $this->app->get_user($cmd['sess'], &$idx)) == FALSE)
 +            if (($user = $this->app->get_user($cmd['sess'], $idx)) == FALSE)
                  return cmd_return(402, 'user not found');
  
              if (($user->flags & USER_FLAG_TY_ADMIN) == 0x00)
@@@ -56,7 -56,7 +56,7 @@@ function bin5_index_wr_main(&$bin5, $re
  
      log_wr(0, 'bin::index_wr.php: COMM: '.xcapemesg($mesg));
  
 -    if (($user = &$bin5->get_user($sess, &$idx)) == FALSE) {
 +    if (($user = &$bin5->get_user($sess, $idx)) == FALSE) {
          echo "Get User Error";
          log_wr("Get User Error");
          return FALSE;
          if ($argz[0] == 'tableinfo') {
              log_wr("PER DI TABLEINFO");
              $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
 -            $user->comm[$user->step % COMM_N] .= show_table_info(&$bin5, &$table, $user->table_pos);
 +            $user->comm[$user->step % COMM_N] .= show_table_info($bin5, $table, $user->table_pos);
              log_wr($user->comm[$user->step % COMM_N]);
              $user->step_inc();
          }
          else if ($argz[0] == 'chatt') {
 -            $bin5->chatt_send(&$user, $mesg);
 +            $bin5->chatt_send($user, $mesg);
          }
          else if ($argz[0] == 'preferences_update') {
              log_wr("PER DI PREFERENCES_UPDATE");
  
              $logout_cont = TRUE;
              if ($remcalc >= 3) {
 -                $lockcalc = $table->exitlock_calc(&$bin5->user, $user->table_pos);
 +                $lockcalc = $table->exitlock_calc($bin5->user, $user->table_pos);
                  if ($lockcalc < 3) {
                      $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
 -                    $user->comm[$user->step % COMM_N] .= $table->exitlock_show(&$bin5->user, $user->table_pos);
 +                    $user->comm[$user->step % COMM_N] .= $table->exitlock_show($bin5->user, $user->table_pos);
                      $user->comm[$user->step % COMM_N] .=  show_notify("<br>I dati presenti sul server non erano allineati con quelli inviati dal tuo browser, adesso lo sono. Riprova ora.", 2000, "torna alla partita.", 400, 100);
  
                      log_wr($user->comm[$user->step % COMM_N]);
          }
          else if ($user->subst == 'asta') {
              if ($argz[0] == 'lascio') {
 -                if ($table->rules->engine(&$bin5, $curtime, BIN5_RULES_ABANDON, $user)) {
 +                if ($table->rules->engine($bin5, $curtime, BIN5_RULES_ABANDON, $user)) {
                      for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
                          $user_cur = &$bin5->user[$table->player[$i]];
  
                          $ret = sprintf('gst.st = %d;', $user_cur->step+1);
 -                        $ret .= show_table(&$bin5,&$user_cur,$user_cur->step+1, TRUE, TRUE);
 +                        $ret .= show_table($bin5, $user_cur,$user_cur->step+1, TRUE, TRUE);
                          $user_cur->comm[$user_cur->step % COMM_N] = $ret;
                          $user_cur->step_inc();
                      }
                      if ($user->table_pos != $index_cur ||
                          !$table->asta_pla[$index_cur]) {
                          // FIXME_LANG
-                         $ret_s = 'grave inconsistenza';
+                         // $ret_s = 'grave inconsistenza';
                          break;
                      }
  
                      log_wr("CI SIAMO  a_card ".$a_card."  asta_card ".$table->asta_card);
  
                      /* user action management */
 -                    if (!$table->rules->engine(&$bin5, $curtime, BIN5_RULES_ASTA, $user,
 +                    if (!$table->rules->engine($bin5, $curtime, BIN5_RULES_ASTA, $user,
                                                 $ret_s, $a_card, $a_pnt)) {
                          break;
                      }
                       *   asta_pla_n > 0 if someone NOT bet)
                       *  THEN advance auction
                       */
 -                    if ($table->rules->engine(&$bin5, $curtime, BIN5_RULES_NEXTAUCT, $user, $maxcard)) {
 +                    if ($table->rules->engine($bin5, $curtime, BIN5_RULES_NEXTAUCT, $user, $maxcard)) {
                          /* search the next player in auction and put it in gstart field */
                          for ($i = 1 ; $i < BIN5_PLAYERS_N ; $i++) {
                              $index_next = ($table->gstart + $i) % BIN5_PLAYERS_N;
                      else if ($table->asta_pla_n == 0) {
                          log_wr("PASSANO TUTTI!");
  
 -                        if ($table->rules->engine(&$bin5, $curtime, BIN5_RULES_ALLPASS, $user)) {
 +                        if ($table->rules->engine($bin5, $curtime, BIN5_RULES_ALLPASS, $user)) {
                              for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
                                  $user_cur = &$bin5->user[$table->player[$i]];
  
                                  $ret = sprintf('gst.st = %d;', $user_cur->step+1);
 -                                $ret .= show_table(&$bin5,&$user_cur,$user_cur->step+1, TRUE, TRUE);
 +                                $ret .= show_table($bin5, $user_cur, $user_cur->step+1, TRUE, TRUE);
                                  $user_cur->comm[$user_cur->step % COMM_N] = $ret;
                                  $user_cur->step_inc();
                              }
                  do {
                      $a_brisco = $argz[1];
  
 -                    if (!$table->rules->engine(&$bin5, $curtime, BIN5_RULES_CHECKCHOOSE, $user, $ret_s, $a_brisco)) {
 +                    if (!$table->rules->engine($bin5, $curtime, BIN5_RULES_CHECKCHOOSE, $user, $ret_s, $a_brisco)) {
                          break;
                      }
  
                      if ($table->turn == (BIN5_PLAYERS_N * BIN5_CARD_HAND)) { /* game finished */
                          log_wr(sprintf("GIOCO FINITO !!!"));
  
 -                        if ($table->rules->engine(&$bin5, $curtime, BIN5_RULES_FINISH, $user)) {
 +                        if ($table->rules->engine($bin5, $curtime, BIN5_RULES_FINISH, $user)) {
                              for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
                                  $user_cur = &$bin5->user[$table->player[$i]];
 -                                $retar[$i] .= show_table(&$bin5,&$user_cur,$user_cur->step+1,TRUE, TRUE);
 +                                $retar[$i] .= show_table($bin5, $user_cur, $user_cur->step+1, TRUE, TRUE);
                              }
                          }
                      }
                          $user_cur->step_inc();
                      }
  
 -                    log_wr(sprintf("TURN: %d",$table->turn));
 +                    log_wr(sprintf("TURN: %d", $table->turn));
                      /* Have played all the players ? */
                      /* NO:  switch the focus and enable the next player to play. */
  
diff --combined web/index_wr.php
@@@ -166,7 -166,7 +166,7 @@@ function index_wr_main(&$brisk, $remote
      $curtime = time();
      $dt = date("H:i ", $curtime);
  
 -    if (($user = $brisk->get_user($sess, &$idx)) == FALSE) {
 +    if (($user = $brisk->get_user($sess, $idx)) == FALSE) {
          $argz = explode('|', xcapemesg($mesg));
  
          if ($argz[0] == 'getchallenge') {
                          echo '1|';
                      }
                      if ($chals->ismod()) {
 -                        Challenges::save_data(&$chals);
 +                        Challenges::save_data($chals);
                      }
                  }
  
          if ($user->subst == 'sitdown' || $user->stat == 'table')
              $brisk->room_wakeup($user);
          else if ($user->subst == 'standup')
 -            $brisk->room_outstandup(&$user);
 +            $brisk->room_outstandup($user);
          else {
              log_rd2("SHUTDOWN FROM WHAT ???");
          }
  
          }
          else if ($argz[0] == 'chatt') {
 -            $brisk->chatt_send(&$user, xcapemesg($mesg), $mlang_indwr);
 +            $brisk->chatt_send($user, xcapemesg($mesg), $mlang_indwr);
          }
          else if ($argz[0] == 'tosmgr') {
              // check IF is authnticated user, both terms of service versions matches
                          $bin5_user_cur->trans_step = $user_cur->step + 1;
                          $bin5_user_cur->comm[$bin5_user_cur->step % COMM_N] = "";
                          $bin5_user_cur->step_inc();
 -                        $bin5_user_cur->comm[$bin5_user_cur->step % COMM_N] = show_table(&$bin5,&$bin5_user_cur,$bin5_user_cur->step+1,TRUE,FALSE);
 +                        $bin5_user_cur->comm[$bin5_user_cur->step % COMM_N] = show_table($bin5, $bin5_user_cur,
 +                                                                                         $bin5_user_cur->step+1,
 +                                                                                         TRUE, FALSE);
                          $bin5_user_cur->step_inc();
  
                          log_wr("TRY PRESAVE: ".$bin5_user_cur->step." TRANS STEP: ".$bin5_user_cur->trans_step);
              }
              else if ($argz[0] == 'logout') {
                  $brisk->ghost_sess->push($curtime, $user->sess, GHOST_SESS_REAS_LOUT);
                  $user->the_end = TRUE;
+                 $brisk->room_outstandup($user);
  
-                 if ($user->subst == 'sitdown') {
-                     log_load("ROOM WAKEUP");
-                     $brisk->room_wakeup($user);
-                 }
-                 else if ($user->subst == 'standup')
-                     $brisk->room_outstandup($user);
-                 else
-                     log_rd2("LOGOUT FROM WHAT ???");
+                 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+                 $user->comm[$user->step % COMM_N] .=  sprintf('gst.st_loc++; xstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");');
+                 $user->step_inc();
              }
          }
          /**********************
              }
              else if ($argz[0] == 'logout') {
                  $brisk->ghost_sess->push($curtime, $user->sess, GHOST_SESS_REAS_LOUT);
-                 $user->the_end = TRUE;
  
+                 $user->the_end = TRUE;
                  $brisk->room_wakeup($user);
+                 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+                 $user->comm[$user->step % COMM_N] .=  sprintf('gst.st_loc++; xstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");');
+                 $user->step_inc();
              }
          }
      }