refactorization to manage old rules with a separated class
[brisk.git] / web / briskin5 / index_wr.php
index 3391a55..a36c03f 100644 (file)
 $G_base = "../";
 
 require_once("../Obj/brisk.phh");
-// require_once("../Obj/proxyscan.phh");
 require_once("Obj/briskin5.phh");
 
-// Use of proxies isn't allowed.
-// if (is_proxy()) {
-//   sleep(5);
-//   exit;
-//}
-
 /*
  *  MAIN
  */
 function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
 {
-    GLOBAL $G_base, $G_dbasetype, $G_black_list;
+    GLOBAL $G_base, $G_dbasetype, $G_ban_list, $G_black_list;
 
     $remote_addr = addrtoipv4($remote_addr_full);
 
-    if (array_search($remote_addr, $G_black_list) !== FALSE) {
-        // TODO: waiting async 5 sec before close
-        return (FALSE);
-    }
-
     $curtime = time();
     if ($bin5 == NULL) {
         return FALSE;
@@ -77,7 +65,8 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
         return FALSE;
     }
     $bin5->brisk->sess_cur_set($user->sess);
-    if (array_search($user->ip, $G_black_list) !== FALSE) {
+    if ( ( ! $user->is_auth() ) &&
+        $bin5->brisk->ban_check($user->ip)) {
         // TODO: waiting async 5 sec before close
         return (FALSE);
     }
@@ -121,7 +110,7 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
             $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");
@@ -154,13 +143,13 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
             }
             else {
                 require_once("../Obj/hardban.phh");
-                Hardbans::add(($user->flags & USER_FLAG_AUTH ? $user->name : FALSE),
+                Hardbans::add(($user->is_auth() ? $user->name : FALSE),
                               $user->ip, $user->sess, $user->laccwr + BAN_TIME);
             }
             //      $user->bantime = $user->laccwr + BAN_TIME;
 
             if ($logout_cont == TRUE) {
-                $bin5->table_wakeup(&$user);
+                $bin5->table_wakeup($user);
             }
         }
         else if ($argz[0] == 'exitlock') {
@@ -209,7 +198,7 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
 
                 /* $table->game_init(&$bin5->user); */
 
-                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]];
 
@@ -313,7 +302,7 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
                         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]];
 
@@ -375,8 +364,18 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
                 if ($table->asta_win > -1 &&
                     $user->table_pos == $table->asta_win) {
                     $a_brisco = $argz[1];
-                    if ($a_brisco >= 0 && $a_brisco < 40) {
+                    if ($a_brisco >= 0 && $a_brisco < (BIN5_CARD_HAND * BIN5_PLAYERS_N)) {
                         $table->briscola = $a_brisco;
+
+                        $tourn_values = array(11, 10, 4,3,2, 1,1,1,1,1);
+                        $table->tourn_pts = 0;
+                        $seed = $a_brisco - ($a_brisco % 10);
+                        for ($i = $seed ; $i < ($seed + min(10, BIN5_CARD_HAND * BIN5_PLAYERS_N)) ; $i++) {
+                            if ($table->card[$i]->owner == $table->asta_win) {
+                                $table->tourn_pts += $tourn_values[$i - $seed];
+                            }
+                        }
+
                         $table->friend   = $table->card[$a_brisco]->owner;
                         log_wr("GSTART 2");
                         $table->gstart = ($table->mazzo+1) % BIN5_PLAYERS_N;
@@ -501,7 +500,7 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
                     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);