garbage_manager update
[brisk.git] / web / briskin5 / index_wr.php
1 <?php
2 /*
3  *  brisk - index_wr.php
4  *
5  *  Copyright (C) 2006 matteo.nastasi@milug.org
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details. You should have received a
16  * copy of the GNU General Public License along with this program; if
17  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
18  * Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * $Id$
21  *
22  */
23
24 require_once("../Obj/brisk.phh");
25 require_once("Obj/briskin5.phh");
26
27 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
28   echo "Debugging time!";
29   exit;
30 }
31
32 log_load($sess, "LOAD: index_wr.php");
33
34 /*
35  *  MAIN
36  */
37 log_wr($sess, 'COMM: '.$mesg);
38
39 if ($table_idx < 0 || $table_idx >= TABLE_N)
40      exit;
41
42 $sem = Briskin5::lock_data($table_idx);
43 $bri = &Briskin5::load_data($table_idx,$table_token);
44 if (($user = &$bri->get_user($sess, &$idx)) == FALSE) {
45   echo "Get User Error";
46   log_wr($sess, "Get User Error");
47   Briskin5::unlock_data($sem);
48   exit;
49 }
50 $argz = explode('|', $mesg);
51
52 log_wr($sess, 'POSTSPLIT: '.$argz[0]);
53
54 if ($argz[0] == 'shutdown') {
55   log_auth($user_cur->sess, "Shutdown session.");
56   $tmp_sess = $user->sess;
57   $user->sess = "";
58   step_unproxy($tmp_sess);
59   $user->name = "";
60   $user->the_end = FALSE;
61   
62   log_rd2($user->sess, "AUTO LOGOUT.");
63   if ($user->subst == 'sitdown' || $user->stat == 'table')
64     $bri->table_wakeup(&$user);
65   else if ($user->subst == 'standup')
66     $bri->room_outstandup(&$user);
67   else
68     log_rd2($sess, "SHUTDOWN FROM WHAT ???");
69 }
70 /******************
71  *                *
72  *   STAT: room   *
73  *                *
74  ******************/
75 else if ($user->stat == 'room') {
76   $user->laccwr = time();
77
78   if ($argz[0] == 'help') {
79     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
80     $user->comm[$user->step % COMM_N] .=  show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
81
82     log_wr($sess, $user->comm[$user->step % COMM_N]);
83     $user->step_inc();
84     
85   }
86   else if ($argz[0] == 'about') {
87     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
88     $user->comm[$user->step % COMM_N] .=  show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
89
90     log_wr($sess, $user->comm[$user->step % COMM_N]);
91     $user->step_inc();
92     
93   }
94   else if ($argz[0] == 'chatt') {
95     $bri->chatt_send(&$user,$mesg);
96   }
97   /**********************
98    *                    *
99    *   SUBST: standup   *
100    *                    *
101    **********************/
102   else if ($user->subst == 'standup') {
103    
104     if ($argz[0] == 'sitdown') {
105       log_wr($sess, "SITDOWN command");
106
107       if ($user->the_end == TRUE) {
108         log_wr($sess, "INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request.");
109         Briskin5::unlock_data($sem);
110         exit;
111       }
112       /* TODO: refact to a function */
113       if ($user->bantime > $user->laccwr) {
114         $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
115         $user->comm[$user->step % COMM_N] .= show_notify("<br>Ti sei alzato da un tavolo senza il consenso degli altri giocatori. Dovrai aspettare ancora ".secstoword($user->bantime - $user->laccwr)." prima di poterti sedere nuovamente.", 2000, "Torna in piedi.", 400, 100);
116         
117         $user->step_inc();
118         Briskin5::save_data($bri);
119         Briskin5::unlock_data($sem);
120         exit;
121       }
122     
123       // Take parameters
124       $table_idx = $argz[1];
125       $table = &$bri->table[$table_idx];
126     
127       if ($table->player_n == PLAYERS_N) {
128         log_wr($sess, "WARN:FSM: Sitdown unreachable, table full.");
129         Briskin5::unlock_data($sem);
130         exit;
131       } 
132       
133       // set new status
134       $user->subst = "sitdown";
135       $user->table = $table_idx;
136       $user->table_pos = $table->user_add($idx);
137       
138       log_wr($sess, "MOP before");
139
140       if ($table->player_n == PLAYERS_N) {
141         log_wr($sess, "MOP inall");
142
143         // Start game for this table.
144         log_wr($sess, "Start game!");
145         
146         //
147         //  START THE SPAWN HERE!!!!
148         //
149
150         if (TRUE) { // WITH SPAWN
151           $curtime = time();
152           // Create new spawned table
153           $us = array();
154           for ($i = 0 ; $i < BRISCOLAIN5_PLAYERS_N ; $i++)
155             $us[$i] = &$bri->user[$table->player[$i]];
156           if (($bri =& new Briskin5(&$us, &$table, $table_idx)) == FALSE)
157             log_wr($sess, "bri create: FALSE");
158           else
159             log_wr($sess, "bri create: ".serialize($bri));
160         
161
162           // Set root table and users
163         }
164         else { // BEFORE SPAWN
165           // init table
166           $table->init(&$bri->user);
167           $table->game_init(&$bri->user);
168           $curtime = time();
169           
170           // init users
171           for ($i = 0 ; $i < $table->player_n ; $i++) {
172             $user_cur = &$bri->user[$table->player[$i]];
173             log_wr($sess, "Pre if!");
174             
175             $ret = "";
176             $ret .= sprintf('gst.st_loc++; gst.st=%d; the_end=true; window.onunload = null ; document.location.assign("table.php");|', $user_cur->step+1);
177             
178             $user_cur->comm[$user_cur->step % COMM_N] = $ret;
179             $user_cur->trans_step = $user_cur->step + 1;
180             log_wr($sess, "TRANS ATTIVATO");
181             
182             
183             $user_cur->stat_set('table');
184             $user_cur->subst = 'asta';
185             $user_cur->laccwr = $curtime;
186             $user_cur->step_inc();
187             
188             $user_cur->comm[$user_cur->step % COMM_N] = show_table(&$bri,&$user_cur,$user_cur->step+1,TRUE, FALSE);
189             $user_cur->step_inc();
190           }
191         } // end else {  BEFORE SPAWN
192         
193         log_wr($sess, "MOP after");
194
195       }
196       // change room
197       $bri->room_sitdown(&$user, $table_idx);
198
199       log_wr($sess, "MOP finish");
200
201       
202     }
203     else if ($argz[0] == 'logout') {
204       $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
205       $user->comm[$user->step % COMM_N] .= sprintf('postact_logout();');
206       $user->the_end = TRUE;
207       $user->step_inc();
208     }
209   }
210   /**********************
211    *                    *
212    *   SUBST: sitdown   *
213    *                    *
214    **********************/
215   else if ($user->subst == 'sitdown') {
216     if ($argz[0] == 'wakeup') {
217       $bri->table_wakeup(&$user);      
218     }
219     else if ($argz[0] == 'logout') {
220       $bri->table_wakeup(&$user);      
221       $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
222       $user->comm[$user->step % COMM_N] .= sprintf('postact_logout();');
223       $user->the_end = TRUE;
224       $user->step_inc();
225     }
226   }
227 }
228 /*********************
229  *                   *
230  *    STAT: table    *
231  *                   *
232  *********************/
233 else if ($user->stat == 'table') {
234   $user->laccwr = time();
235   $table = &$bri->table[$user->table];
236
237   if ($argz[0] == 'tableinfo') {
238     log_wr($sess, "PER DI TABLEINFO");
239     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
240     $user->comm[$user->step % COMM_N] .= show_table_info(&$bri, &$table, $user->table_pos);
241     log_wr($sess, $user->comm[$user->step % COMM_N]);
242     $user->step_inc();
243   }
244   else if ($argz[0] == 'chatt') {
245     $bri->chatt_send(&$user,$mesg);
246   }
247   else if ($argz[0] == 'logout') {
248     $remcalc = $argz[1];
249
250     if ($user->exitislock == TRUE) {
251       $remcalc++;
252       $user->exitislock = FALSE;
253     }
254
255     $logout_cont = TRUE;
256     if ($remcalc >= 3) {
257       $lockcalc = $table->exitlock_calc(&$bri->user, $user->table_pos);
258       if ($lockcalc < 3) {
259         $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
260         $user->comm[$user->step % COMM_N] .= $table->exitlock_show(&$bri->user, $user->table_pos);
261         $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);
262         
263         log_wr($sess, $user->comm[$user->step % COMM_N]);
264         $user->step_inc();
265         $logout_cont = FALSE;
266       }
267     }
268     else 
269       $user->bantime = $user->laccwr + BAN_TIME;
270     
271     if ($logout_cont == TRUE) {
272       $bri->table_wakeup(&$user);
273     }
274   }
275   else if ($argz[0] == 'exitlock') {
276     $user->exitislock = ($user->exitislock == TRUE ? FALSE : TRUE);
277     for ($ct = 0, $i = 0 ; $i < PLAYERS_N ; $i++) {     
278       $user_cur[$i] = &$bri->user[$table->player[$i]];
279       if ($user_cur[$i]->exitislock == FALSE)
280         $ct++;
281     }
282     for ($i = 0 ; $i < PLAYERS_N ; $i++) {
283       $ret = sprintf('gst.st = %d;', $user_cur[$i]->step+1);
284       $ret .= sprintf('exitlock_show(%d, %s);', $ct, 
285                      ($user_cur[$i]->exitislock ? 'true' : 'false'));
286       $user_cur[$i]->comm[$user_cur[$i]->step % COMM_N] = $ret;
287       log_wr($sess, $user_cur[$i]->comm[$user_cur[$i]->step % COMM_N]);
288       $user_cur[$i]->step_inc();
289     }
290   }
291   else if ($user->subst == 'asta') {
292     if ($argz[0] == 'lascio' && $user->handpt <= 2) {
293       $index_cur = $table->gstart % PLAYERS_N;
294     
295       log_wr($sess, sprintf("GIOCO FINITO !!!"));
296     
297       $table->mult *= 2; 
298       $table->old_reason = sprintf("Ha lasciato %s perche` aveva al massimo 2 punti.", $user->name);
299
300       $table->game_next();
301       $table->game_init(&$bri->user);
302     
303       for ($i = 0 ; $i < PLAYERS_N ; $i++) {    
304         $user_cur = &$bri->user[$table->player[$i]];
305
306         $ret = sprintf('gst.st = %d;', $user_cur->step+1);
307         $ret .= show_table(&$bri,&$user_cur,$user_cur->step+1, TRUE, TRUE);
308         $user_cur->comm[$user_cur->step % COMM_N] = $ret;
309         $user_cur->step_inc();      
310       }
311     }
312     else if ($argz[0] == 'asta') {
313       $again = TRUE;
314     
315       $index_cur = $table->gstart % PLAYERS_N;
316       if ($user->table_pos == $index_cur &&
317           $table->asta_pla[$index_cur]) {
318         $a_card = $argz[1];
319         $a_pnt  = $argz[2];
320       
321         log_wr($sess, "CI SIAMO  a_card ".$a_card."  asta_card ".$table->asta_card);
322       
323         // Abbandono dell'asta
324         if ($a_card <= -1) {
325           log_wr($sess, "Abbandona l'asta.");
326           $table->asta_pla[$index_cur] = FALSE;
327           $user->asta_card  = -1;
328           $table->asta_pla_n--;
329           $again = FALSE;
330         }
331         else if ($a_card <= 9) {
332           if ($a_card >= 0 && $a_card < 9 && $a_card > $table->asta_card)
333             $again = FALSE;
334           else if ($a_card == 9 && $a_pnt > ($table->asta_pnt >= 61 ? $table->asta_pnt : 60) && $a_pnt <= 120)
335             $again = FALSE;
336           
337
338           if ($again == FALSE) {
339             log_wr($sess, "NUOVI ORZI.");
340             $user->asta_card  = $a_card;
341             $table->asta_card = $a_card;
342             if ($a_card == 9) {
343               $user->asta_pnt   = $a_pnt;
344               $table->asta_pnt  = $a_pnt;
345             }
346           }
347         }
348       
349       
350       
351         if ($again) { // Qualcosa non andato bene, rifare
352           $ret = sprintf('gst.st = %d; asta_pnt_set(%d);', $user->step+1, 
353                          ($table->asta_pnt > 60 ? $table->asta_pnt + 1 : 61) );
354           $user->comm[$user->step % COMM_N] = $ret;
355           $user->step_inc();
356
357           log_wr($sess, "Ripetere.");
358         }
359         else {
360           /* next step */
361           $showst = "show_astat("; 
362           for ($i = 0 ; $i < PLAYERS_N ; $i++) {
363             $user_cur = &$bri->user[$table->player[$i]];
364             $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "), 
365                                ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
366           }
367           if (PLAYERS_N == 3)
368             $showst .= ",-2,-2";
369           $showst .= ");";
370
371           $maxcard = -2;
372           for ($i = 0 ; $i < PLAYERS_N ; $i++) {
373             $user_cur = &$bri->user[$table->player[$i]];
374             if ($maxcard < $user_cur->asta_card)
375               $maxcard = $user_cur->asta_card;
376           }
377
378           if (($table->asta_pla_n > ($maxcard > -1 ? 1 : 0)) &&
379               !($table->asta_card == 9 && $table->asta_pnt == 120)) {
380             log_wr($sess,"ALLOPPA QUI");
381             for ($i = 1 ; $i < PLAYERS_N ; $i++) {
382               $index_next = ($table->gstart + $i) % PLAYERS_N;
383               if ($table->asta_pla[$index_next]) {
384                 log_wr($sess,"GSTART 1");
385                 $table->gstart += $i;
386                 break;
387               }
388             }
389           
390           
391             for ($i = 0 ; $i < PLAYERS_N ; $i++) {
392               $user_cur = &$bri->user[$table->player[$i]];
393               $ret = sprintf('gst.st = %d; %s', $user_cur->step+1, $showst);
394               if ($user_cur->table_pos == ($table->gstart % PLAYERS_N)) 
395                 $ret .= sprintf('dispose_asta(%d,%d, %s); remark_on();', 
396                                 $table->asta_card + 1, $table->asta_pnt+1, ($user_cur->handpt <= 2 ? "true" : "false"));
397               else
398                 $ret .= sprintf('dispose_asta(%d,%d, %s); remark_off();',
399                                 $table->asta_card + 1, -($table->asta_pnt+1), ($user_cur->handpt <= 2 ? "true" : "false"));
400               $user_cur->comm[$user_cur->step % COMM_N] = $ret;
401               $user_cur->step_inc();
402             }
403           }
404           else if ($table->asta_pla_n == 0) {
405             log_wr($sess, "PASSANO TUTTI!");
406
407             log_wr($sess, sprintf("GIOCO FINITO !!!"));
408           
409             $table->old_reason = "Hanno passato tutti.";
410             $table->mult *= 2; 
411
412             $table->game_next();
413             $table->game_init(&$bri->user);
414           
415             for ($i = 0 ; $i < PLAYERS_N ; $i++) {      
416               $user_cur = &$bri->user[$table->player[$i]];
417
418               $ret = sprintf('gst.st = %d;', $user_cur->step+1);
419               $ret .= show_table(&$bri,&$user_cur,$user_cur->step+1, TRUE, TRUE);
420               $user_cur->comm[$user_cur->step % COMM_N] = $ret;
421               $user_cur->step_inc();        
422             }
423           }
424           else {
425             log_wr($sess, "FINITA !");
426             // if a_pnt == 120 supergame ! else abbandono
427             if ($a_pnt == 120 || $user->asta_card != -1) {
428               $chooser = $index_cur;
429               for ($i = 1 ; $i < PLAYERS_N ; $i++) 
430                 if ($i != $chooser)
431                   $table->asta_pla[$i] = FALSE;
432             }
433             else {
434               //"gst.st = ".($user->step+1)."; dispose_asta(".($table->asta_card + 1).",".-($table->asta_pnt).", true); remark_off();";
435               $user->comm[$user->step % COMM_N] = sprintf( "gst.st = %d; dispose_asta(%d, %d, false); remark_off();", $user->step+1, $table->asta_card + 1,-($table->asta_pnt));
436               $user->step_inc();
437               for ($i = 1 ; $i < PLAYERS_N ; $i++) {
438                 $chooser = ($table->gstart + $i) % PLAYERS_N;
439                 if ($table->asta_pla[$chooser]) {
440                   break;
441                 }
442               }
443             }
444             $table->asta_win = $chooser;
445
446             for ($i = 0 ; $i < PLAYERS_N ; $i++) {
447               $user_cur = &$bri->user[$table->player[$i]];
448               $ret = sprintf('gst.st = %d; %s', $user_cur->step+1, $showst);
449
450               if ($i == $chooser) {
451                 $ret .= "choose_seed(". $table->asta_card."); \$(\"asta\").style.visibility = \"hidden\"; remark_on();";
452               }
453               else {
454                 $ret .= "remark_off();";
455               }
456
457               $user_cur->comm[$user_cur->step % COMM_N] = $ret;
458               $user_cur->step_inc();        
459             }
460           }
461         }
462       }
463       else {
464         log_wr($sess, "NON CI SIAMO");
465       }
466     }
467     /*  asta::choose */
468     else if ($argz[0] == 'choose') {
469       if ($table->asta_win > -1 && 
470           $user->table_pos == $table->asta_win) {
471         $a_brisco = $argz[1];
472         if ($a_brisco >= 0 && $a_brisco < 40) {
473           $table->briscola = $a_brisco;
474           $table->friend   = $table->card[$a_brisco]->owner;
475           log_wr($sess,"GSTART 2");
476           $table->gstart = ($table->mazzo+1) % PLAYERS_N;
477           log_wr($sess, "Setta la briscola a ".$a_brisco);
478
479           $chooser = $table->asta_win;
480           $user_chooser = &$bri->user[$table->player[$chooser]];
481           for ($i = 0 ; $i < PLAYERS_N ; $i++) {
482             $user_cur = &$bri->user[$table->player[$i]];
483             $user_cur->subst = 'game';
484             $ret = sprintf('gst.st = %d; subst = "game";', $user_cur->step+1);
485           
486
487             /* bg of caller cell */
488             $ret .= briscola_show($bri, $table, $user_cur);
489
490             /* first gamer */
491             if ($i == ($table->gstart % PLAYERS_N))
492               $ret .= "is_my_time = true; remark_on();";
493             else
494               $ret .= "is_my_time = false; remark_off();";
495
496             $user_cur->comm[$user_cur->step % COMM_N] = $ret;
497             $user_cur->step_inc();          
498           }
499           /*
500             TUTTE LE VARIABILI DI STATO PER PASSARE A GIOCARE E LE
501             VAR PER PASSARE ALLA FASE DI GIOCO
502           */
503         
504         }
505       }
506     }
507   }
508   else if ($user->subst == 'game') {
509     log_wr($sess, "state: table::game".$argz[0]);
510
511     if ($argz[0] == 'play') {
512       $a_play = $argz[1];
513       $a_x =    $argz[2];
514       $a_y =    $argz[3];
515
516       if (strpos($a_x, "px") != FALSE)
517         $a_x = substr($a_x,0,-2);
518       if (strpos($a_y, "px") != FALSE)
519         $a_y = substr($a_y,0,-2);
520
521       $loggo = sprintf("A_play %s, table_pos %d == %d, mazzo %d, gstart %d, card_stat %d, card_own %d",
522                        $a_play, $user->table_pos, ($table->gstart % PLAYERS_N),
523                        $table->mazzo, $table->gstart,
524                        $table->card[$a_play]->stat, $table->card[$a_play]->owner);
525       log_wr($sess, "CIC".$loggo);
526                           
527       /* se era il suo turno e la carta era sua ed era in mano */
528       if ($a_play >=0 && $a_play < 40 &&
529           ($user->table_pos == (($table->gstart + $table->turn) % PLAYERS_N)) &&
530           $table->card[$a_play]->stat == 'hand' &&
531           $table->card[$a_play]->owner == $user->table_pos) {
532         log_wr($sess, sprintf("User: %s Play: %d",$user->name, $a_play));
533
534         /* Change the card status. */
535         $table->card[$a_play]->play($a_x, $a_y);
536
537         /*
538          *  !!!! TURN INCREMENTED BEFORE !!!!
539          */
540         $turn_cur = ($table->gstart + $table->turn) % PLAYERS_N;
541         $table->turn++;
542
543         $card_play = sprintf("card_play(%d,%d,%d,%d);|",
544                              $user->table_pos, $a_play, $a_x, $a_y);
545         if (($table->turn % PLAYERS_N) != 0) {     /* manche not finished */
546           $turn_nex = ($table->gstart + $table->turn) % PLAYERS_N;
547
548           $player_cur = "remark_off();";
549           $player_nex = $card_play . "is_my_time = true; remark_on();";
550           $player_oth = $card_play;
551         }
552         else if ($table->turn <= (PLAYERS_N * 8)) { /* manche finished */
553           $winner = calculate_winner($table);
554           log_wr($sess,"GSTART 3");
555           $table->gstart = $winner;
556           $turn_nex = ($table->gstart + $table->turn) % PLAYERS_N;
557
558           log_wr($sess, sprintf("The winner is: [%d] [%s]", $winner, $bri->user[$table->player[$winner]]->name));
559           $card_take = sprintf("sleep(gst,2000);|cards_take(%d);|cards_hidetake($d);",
560                                $winner, $winner);
561           $player_cur = "remark_off();" . $card_take . "|"; 
562           if ($turn_cur != $turn_nex)
563             $player_nex = $card_play . $card_take . "|";
564           else
565             $player_nex = "";
566           if ($table->turn < (PLAYERS_N * 8))  /* game NOT finished */
567             $player_nex .= "is_my_time = true; remark_on();";
568           $player_oth = $card_play . $card_take;
569         }
570
571         log_wr($sess, sprintf("Turn Cur %d Turn Nex %d",$turn_cur, $turn_nex));
572         for ($i = 0 ; $i < PLAYERS_N ; $i++) {  
573           $user_cur = &$bri->user[$table->player[$i]];
574
575           $ret = sprintf('gst.st = %d; ', $user_cur->step+1);
576
577         
578           if ($i == $turn_cur) {
579             $ret .= $player_cur;          
580           }
581           if ($i == $turn_nex) {
582             $ret .= $player_nex;          
583           }
584           if ($i != $turn_cur && $i != $turn_nex) {
585             $ret .= $player_oth;
586           }
587
588           $retar[$i] = $ret;
589         }
590
591
592
593
594         if ($table->turn == (PLAYERS_N * 8)) { /* game finished */
595           log_wr($sess, sprintf("GIOCO FINITO !!!"));
596
597           /* ************************************************ */
598           /*    PRIMA LA PARTE PER LO SHOW DI CHI HA VINTO    */
599           /* ************************************************ */
600           calculate_points(&$table);
601
602           $table->game_next();
603           $table->game_init(&$bri->user);
604           
605           for ($i = 0 ; $i < PLAYERS_N ; $i++) {
606             $user_cur = &$bri->user[$table->player[$i]];
607             $retar[$i] .= show_table(&$bri,&$user_cur,$user_cur->step+1,TRUE, TRUE);
608           }
609         }
610
611
612         for ($i = 0 ; $i < PLAYERS_N ; $i++) {  
613           $user_cur = &$bri->user[$table->player[$i]];
614         
615           $user_cur->comm[$user_cur->step % COMM_N] = $retar[$i];
616           $user_cur->step_inc();            
617         }
618
619         log_wr($sess, sprintf("TURN: %d",$table->turn));
620         /* Have played all the players ? */
621         /* NO:  switch the focus and enable the next player to play. */
622       
623         /* YES: calculate who win and go to the next turn. */
624       }
625     }
626     else
627       log_wr($sess, "NOSENSE");
628   }
629 }
630 log_wr($sess, "before save data");
631 Briskin5::save_data($bri);
632
633 Briskin5::unlock_data($sem);
634 exit;
635 ?>