poll and direct mail added
[brisk.git] / web / index_wr.php
1 <?php
2 /*
3  *  brisk - index_wr.php
4  *
5  *  Copyright (C) 2006-2009 Matteo Nastasi
6  *                          mailto: nastasi@alternativeoutput.it 
7  *                                  matteo.nastasi@milug.org
8  *                          web: http://www.alternativeoutput.it
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details. You should have received a
19  * copy of the GNU General Public License along with this program; if
20  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21  * Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * $Id$
24  *
25  */
26
27 require_once("Obj/brisk.phh");
28 require_once("Obj/auth.phh");
29 // require_once("Obj/proxyscan.phh");
30
31 // Use of proxies isn't allowed.
32 // if (is_proxy()) {
33 //   sleep(5);
34 //   exit;
35 // }
36 log_load("index_wr.php");
37
38 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
39   echo "Debugging time!";
40   exit;
41 }
42
43 /*
44  *  MAIN
45  */
46
47 /* if the IP is banned, exit without do nothing */
48 if (array_search($_SERVER['REMOTE_ADDR'], $G_black_list) !== FALSE) {
49   sleep(5);
50   exit;
51 }
52
53 $is_spawn = FALSE;
54
55 log_wr('COMM: '.xcapemesg($mesg));
56
57 $sem = Room::lock_data();
58 if (($room = &Room::load_data()) == FALSE) {
59   echo "Load data error";
60   log_wr("Load data error");
61   Room::unlock_data($sem);
62   exit;
63 }
64 if (($user = &$room->get_user($sess, &$idx)) == FALSE) {
65   Room::unlock_data($sem);
66   $argz = explode('|', xcapemesg($mesg));
67
68   if ($argz[0] == 'getchallenge') {
69     GLOBAL $cli_name;
70     if (($a_sem = Challenges::lock_data()) != FALSE) { 
71       log_main("chal lock data success");
72       
73       if (($chals = &Challenges::load_data()) != FALSE) {
74         $curtime = time();
75
76         $token =  uniqid("");
77         // echo '2|'.$argz[1].'|'.$token.'|'.$_SERVER['REMOTE_ADDR'].'|'.$curtime.'|';
78         // exit;
79
80         if (($login_new = validate_name(urldecode($cli_name))) != FALSE) {
81           if ($chals->add($login_new, $token, $_SERVER['REMOTE_ADDR'], $curtime) != FALSE) {
82             echo '0|'.$token;
83           }
84           else {
85             echo '1|';
86           }
87         }
88         else {
89           echo '1|';
90         }
91         if ($chals->ismod()) {
92           Challenges::save_data(&$chals);
93         }
94       }
95       
96
97       Challenges::unlock_data($a_sem);
98     }
99   }
100   else if ($argz[0] == 'auth') {
101     printf("challenge|ok");
102   }
103   else if ($argz[0] == 'help') {
104     /* MLANG: "torna ai tavoli" */ 
105     echo show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
106   }
107   else if ($argz[0] == 'about') {
108     echo show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
109   }
110   else if ($argz[0] == 'passwdhowto') {
111     echo show_notify(str_replace("\n", " ", $G_room_passwdhowto), 0, "torna ai tavoli", 400, 200);
112   }
113   else if ($argz[0] == 'roadmap') {
114     echo show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
115   }
116   else if ($argz[0] == 'whysupport') {
117     echo show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
118   }
119   else { 
120     log_wr("Get User Error");
121     echo "Get User Error:" + $argz[0];
122   }
123   exit;
124 }
125 $argz = explode('|', xcapemesg($mesg));
126
127 log_wr('POSTSPLIT: '.$argz[0]);
128
129 if ($argz[0] == 'shutdown') {
130   log_auth($user->sess, "Shutdown session.");
131
132   $user->reset();
133
134   log_rd2("AUTO LOGOUT.");
135   if ($user->subst == 'sitdown' || $user->stat == 'table')
136     $room->room_wakeup(&$user);
137   else if ($user->subst == 'standup')
138     $room->room_outstandup(&$user);
139   else {
140     log_rd2("SHUTDOWN FROM WHAT ???");
141   }
142 }
143 else if ($argz[0] == 'warranty') {
144   GLOBAL $cli_name, $cli_email;
145
146   $curtime = time();
147   $mesg_to_user = "";
148
149   log_wr("INFO:SKIP:argz == warranty name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH));
150   if ($user->flags & USER_FLAG_AUTH) {
151     if (($wa_lock = Warrant::lock_data()) != FALSE) {
152       if (($fp = @fopen(LEGAL_PATH."/warrant.txt", 'a')) != FALSE) {
153         /* Unix time | session | nickname | IP | where was | mesg */
154         fwrite($fp, sprintf("%ld|%s|%s|%s|\n", $curtime, $user->name, xcapelt(urldecode($cli_name)), xcapelt(urldecode($cli_email))));
155         fclose($fp);
156       }
157       Warrant::unlock_data($wa_lock);
158       $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
159       /* MLANG: "<br>Il nominativo &egrave; stato inoltrato all\'amministratore.<br><br>Nell\'arco di pochi giorni vi verr&agrave;<br><br>notificata l\'avvenuta registrazione." */
160       $user->comm[$user->step % COMM_N] .=  show_notify("<br>Il nominativo &egrave; stato inoltrato all\'amministratore.<br><br>Nell\'arco di pochi giorni vi verr&agrave;<br><br>notificata l\'avvenuta registrazione.", 0, "chiudi", 400, 150);
161       $user->step_inc();
162       echo "1";
163     }
164     else {
165       /* MLANG: "<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>" */
166       $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>");', $dt, NICKSERV);
167     }
168     
169   }
170   else {
171     /* MLANG: "<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>" */
172     $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>");', $dt, NICKSERV);
173   }
174
175   if ($mesg_to_user != "") {
176     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
177     
178     $dt = date("H:i ", $curtime);
179     $user->comm[$user->step % COMM_N] .= $mesg_to_user;
180     $user->step_inc();
181   }
182 }
183 else if ($argz[0] == 'mesgtoadm') {
184   GLOBAL $cli_subj, $cli_mesg;
185
186   $curtime = time();
187   $mesg_to_user = "";
188
189   log_wr("INFO:SKIP:argz == mesgtoadm name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH));
190   if ($user->flags & USER_FLAG_AUTH) {
191     if (($wa_lock = Warrant::lock_data()) != FALSE) {
192       $userdb = new LoginDB();
193       
194       if (($ema = $userdb->getmail($user->name)) != FALSE) {
195         // mail("brisk@alternativeoutput.it", 
196         mail("nastasi", urldecode($cli_subj), urldecode($cli_mesg), sprintf("From: %s <%s>", $user->name, $ema));
197       }
198
199       if (($fp = @fopen(LEGAL_PATH."/messages.txt", 'a')) != FALSE) {
200         /* Unix time | session | nickname | IP | where was | mesg */
201         fwrite($fp, sprintf("%ld|%s|%s|%s\n", $curtime, $user->name, 
202                             xcapelt(urldecode($cli_subj)), xcapelt(urldecode($cli_mesg))));
203         fclose($fp);
204       }
205       Warrant::unlock_data($wa_lock);
206       $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
207       /* MLANG: "" */
208       $user->comm[$user->step % COMM_N] .=  show_notify("<br><br>Il messaggio &egrave; stato inoltrato all\'amministratore.", 0, "chiudi", 400, 110);
209       $user->step_inc();
210       echo "1";
211     }
212     else {
213       /* MLANG: "<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>" */
214       $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>E\' occorso un errore durante il salvataggio, riprova o contatta per mail l\'amministratore.</b>");', $dt, NICKSERV);
215     }
216     
217   }
218   else {
219     /* MLANG: "<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>" */
220     $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per mandare messaggi all\'amministratore devi essere autenticato.</b>");', $dt, NICKSERV);
221   }
222
223   if ($mesg_to_user != "") {
224     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
225     
226     $dt = date("H:i ", $curtime);
227     $user->comm[$user->step % COMM_N] .= $mesg_to_user;
228     $user->step_inc();
229   }
230 }
231
232
233
234 else if ($argz[0] == 'poll') {
235   GLOBAL $G_with_poll, $G_poll_name, $cli_choose, $cli_poll_name;
236
237   $poll_lock = FALSE;
238   $curtime = time();
239   $mesg_to_user = "";
240   
241   $fp = FALSE;
242   $echont = "0";
243
244   /*
245           DONE - autorizzato ?
246           DONE - ci sono poll attivi ?
247           - verifica che il poll_name del client sia uguale a quello sul server
248           DONE - lock
249           DONE - apro file r+ con fallback in w+
250           DONE - vedo se ha già votato
251           DONE - se si: messaggio di voto già dato
252           se no: accetto il voto e lo segno; messaggio
253           chiudo file
254   */
255
256   $dobreak = FALSE;
257   do {
258     log_wr("INFO:SKIP:argz == poll name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH));
259     if (($user->flags & USER_FLAG_AUTH) != USER_FLAG_AUTH) {
260       $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per partecipare al sondaggio devi essere autenticato.</b>");', $dt, NICKSERV);
261       log_wr("break1");
262       break;
263     }
264
265     if ($G_with_poll == FALSE && $G_poll_name != FALSE && $G_poll_name != "") {
266       $mesg_to_user = show_notify("<br><br>Al momento non è attivo alcun sondaggio.", 0, "chiudi", 400, 110);
267       log_wr("break2");
268       break;
269     }
270     
271     if ($cli_choose == "" || !isset($cli_choose)) {
272       $mesg_to_user = show_notify("<br><br>Non hai espresso nessuna preferenza.", 0, "chiudi", 400, 110);
273       log_wr("break2.5");
274       break;
275     }
276     
277     if (($poll_lock = Poll::lock_data()) == FALSE) {
278       /* MLANG: "<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>" */
279       $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>E\' occorso un errore durante il salvataggio, riprova o contatta per mail l\'amministratore.</b>");', $dt, NICKSERV);
280       log_wr("break3");
281       break;
282     }
283     
284     if (($fp = @fopen(LEGAL_PATH."/".$G_poll_name.".txt", 'r+')) == FALSE) 
285       $fp = @fopen(LEGAL_PATH."/".$G_poll_name.".txt", 'w+');
286     
287     if ($fp == FALSE) {
288       $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>E\' occorso un errore durante il salvataggio, riprova o contatta per mail l\'amministratore.</b>");', $dt, NICKSERV);
289       log_wr("break4");
290       break;
291     }
292     
293     log_wr("poll: cp");
294     fseek($fp, 0);
295     
296     log_wr("poll: cp2");
297     while (!feof($fp)) {
298       log_wr("poll: cp3");
299       $bf = fgets($fp, 4096);
300       log_wr("poll: cp3.1");
301       $arli = csplitter($bf, '|');
302       if (count($arli) == 0)
303         break;
304     log_wr("poll: cp3.2");
305       if (strcasecmp($arli[1], $user->name) == 0) {
306         $mesg_to_user = show_notify("<br>Per questo sondaggio hai già votato.<br><br>Non si può esprimere la propria preferenza più di una volta.", 0, "chiudi", 400, 110);
307         $dobreak = TRUE;
308         break;
309       }
310     }
311     log_wr("poll: cp4");
312
313     if ($dobreak) {
314       log_wr("break5");
315       break;
316     }
317       
318     /* Unix time | nickname | choose */
319     fwrite($fp, sprintf("%ld|%s|%s\n", $curtime, xcapelt($user->name), xcapelt(urldecode($cli_choose))));
320     fflush($fp);
321     $mesg_to_user =  show_notify("<br><br>Il tuo voto è stato registrato.", 0, "chiudi", 400, 110);
322     $echont = "1";
323     log_wr("poll: cp5");
324   } while (0);
325
326   if ($fp != FALSE)
327     fclose($fp);
328
329   if ($poll_lock != FALSE)
330     Poll::unlock_data($poll_lock);
331   
332   if ($mesg_to_user != "") {
333     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
334     
335     $dt = date("H:i ", $curtime);
336     $user->comm[$user->step % COMM_N] .= $mesg_to_user;
337     $user->step_inc();
338   }
339
340   echo "$echont";
341 }
342
343 /******************
344  *                *
345  *   STAT: room   *
346  *                *
347  ******************/
348 else if ($user->stat == 'room') {
349   $user->laccwr = time();
350
351   if ($argz[0] == 'help') {
352     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
353     $user->comm[$user->step % COMM_N] .=  show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
354
355     log_wr($user->comm[$user->step % COMM_N]);
356     $user->step_inc();
357     
358   }
359   else if ($argz[0] == 'passwdhowto') {
360     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
361     $user->comm[$user->step % COMM_N] .=  show_notify(str_replace("\n", " ", $G_room_passwdhowto), 0, "torna ai tavoli", 600, 500);
362
363     log_wr($user->comm[$user->step % COMM_N]);
364     $user->step_inc();
365     
366   }
367   else if ($argz[0] == 'about') {
368     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
369     $user->comm[$user->step % COMM_N] .=  show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
370
371     log_wr($user->comm[$user->step % COMM_N]);
372     $user->step_inc();
373     
374   }
375   else if ($argz[0] == 'roadmap') {
376     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
377     $user->comm[$user->step % COMM_N] .=  show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
378
379     log_wr($user->comm[$user->step % COMM_N]);
380     $user->step_inc();
381     
382   }
383   else if ($argz[0] == 'whysupport') {
384     $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
385     $user->comm[$user->step % COMM_N] .=  show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
386
387     log_wr($user->comm[$user->step % COMM_N]);
388     $user->step_inc();
389     
390   }
391   else if ($argz[0] == 'chatt') {
392     $room->chatt_send(&$user, xcapemesg($mesg));
393   }
394   /**********************
395    *                    *
396    *   SUBST: standup   *
397    *                    *
398    **********************/
399   else if ($user->subst == 'standup') {
400    
401     if ($argz[0] == 'sitdown') {
402       log_wr("SITDOWN command");
403
404       if ($user->the_end == TRUE) {
405         log_wr("INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request.");
406         Room::unlock_data($sem);
407         exit;
408       }
409
410       // Take parameters
411       $table_idx = $argz[1];
412       $table = &$room->table[$table_idx];
413     
414       $curtime = time();
415
416       if ($G_shutdown || $table->wakeup_time > $curtime || 
417           ($table->auth_only && (($user->flags & USER_FLAG_AUTH) == 0)) ) {
418         $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
419
420         $dt = date("H:i ", $curtime);
421         /* MLANG: "<b>Il server sta per essere riavviato, non possono avere inizio nuove partite.</b>", "<b>Il tavolo a cui volevi sederti richiede autentifica.</b>", "<b>Il tavolo si &egrave; appena liberato, ci si potr&agrave; sedere tra %d secondi.</b>" */
422         if ($G_shutdown) {
423           $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>Il server sta per essere riavviato, non possono avere inizio nuove partite.</b>");', $dt, NICKSERV);
424         }
425         else if ($table->auth_only && (($user->flags & USER_FLAG_AUTH) == 0)) {
426           $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>Il tavolo a cui volevi sederti richiede autentifica.</b>");', $dt, NICKSERV);
427         }
428         else {
429           $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>Il tavolo si &egrave; appena liberato, ci si potr&agrave; sedere tra %d secondi.</b>");', $dt, NICKSERV, $table->wakeup_time - $curtime);
430         }
431         $user->step_inc();
432         Room::save_data($room);
433         Room::unlock_data($sem);
434         exit;
435       }
436
437       /* TODO: refact to a function */
438       // if ($user->bantime > $user->laccwr) {
439       require_once("Obj/hardban.phh");
440
441       if (($bantime = Hardbans::check(($user->flags & USER_FLAG_AUTH ? $user->name : FALSE),
442                           $user->ip, $user->sess)) != -1) {
443         $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
444         /* MLANG: "<br>Ti sei alzato da un tavolo senza il consenso degli altri giocatori. <br><br>Dovrai aspettare ancora ".secstoword($user->bantime - $user->laccwr)." prima di poterti sedere nuovamente.", "resta in piedi.", "<br>Tu o qualcuno col tuo stesso indirizzo IP si è alzato da un tavolo senza il consenso degli altri giocatori.<br><br>Dovrai aspettare ancora ".secstoword($bantime - $user->laccwr)." prima di poterti sedere nuovamente.<br><br>Se non sei stato tu ad alzarti e possiedi un login con password, autenticandoti con quello, potrai accedere." */
445         if ($user->flags & USER_FLAG_AUTH) {
446           $user->comm[$user->step % COMM_N] .= show_notify("<br>Ti sei alzato da un tavolo senza il consenso degli altri giocatori. <br><br>Dovrai aspettare ancora ".secstoword($user->bantime - $user->laccwr)." prima di poterti sedere nuovamente.", 2000, "resta in piedi.", 400, 100);
447         }
448         else {
449           $user->comm[$user->step % COMM_N] .= show_notify("<br>Tu o qualcuno col tuo stesso indirizzo IP si è alzato da un tavolo senza il consenso degli altri giocatori.<br><br>Dovrai aspettare ancora ".secstoword($bantime - $user->laccwr)." prima di poterti sedere nuovamente.<br><br>Se non sei stato tu ad alzarti e possiedi un login con password, autenticandoti con quello, potrai accedere.", 2000, "resta in piedi.", 400, 180);
450         }
451         $user->step_inc();
452         Room::save_data($room);
453         Room::unlock_data($sem);
454         exit;
455       }
456     
457       if ($table->player_n == PLAYERS_N) {
458         log_wr("WARN:FSM: Sitdown unreachable, table full.");
459         Room::unlock_data($sem);
460         exit;
461       } 
462       
463       // set new status
464       $user->subst = "sitdown";
465       $user->table = $table_idx;
466       $user->table_pos = $table->user_add($idx);
467       
468       log_wr("MOP before");
469
470       if ($table->player_n == PLAYERS_N) {
471         require_once("briskin5/Obj/briskin5.phh");
472         log_wr("MOP inall");
473
474         // Start game for this table.
475         log_wr("Start game!");
476         
477         //
478         //  START THE SPAWN HERE!!!!
479         //
480
481         $curtime = time();
482
483         // Create new spawned table
484         $bri_sem = Briskin5::lock_data($table_idx);
485         $table_token = uniqid("");
486         $room->table[$table_idx]->table_token = $table_token;
487         $room->table[$table_idx]->table_start = $curtime;
488         
489         $plist = "$table_token|$user->table|$table->player_n";
490         for ($i = 0 ; $i < $table->player_n ; $i++) {
491           $plist .= '|'.$room->user[$table->player[$i]]->sess;
492         }
493         log_legal($curtime, $user, "STAT:CREATE_GAME", $plist);
494
495         if (($bri =& new Briskin5(&$room, $table_idx, $table_token)) == FALSE)
496           log_wr("bri create: FALSE");
497         else
498           log_wr("bri create: ".serialize($bri));
499         
500         // init table
501         $bri_table =& $bri->table[0];
502         $bri_table->init(&$bri->user);
503         $bri_table->game_init(&$bri->user);
504         //
505         // Init spawned users.
506         //
507         require_once('briskin5/Obj/briskin5.phh');
508         //
509         //  MULTIGAME: here init of selected game instead of hardcabled briskin5 init (look subst status)
510         // 
511         for ($i = 0 ; $i < $table->player_n ; $i++) {
512           $bri_user_cur = &$bri->user[$i];
513           $user_cur = &$room->user[$table->player[$i]];
514           
515           $bri_user_cur->stat_set('table');
516           $bri_user_cur->subst = 'asta';
517           $bri_user_cur->laccwr = $curtime;
518           
519           $bri_user_cur->trans_step = $user_cur->step + 1;
520           $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = "";
521           $bri_user_cur->step_inc();
522           $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = show_table(&$bri,&$bri_user_cur,$bri_user_cur->step+1,TRUE, FALSE);
523           
524           $bri_user_cur->step_inc();
525           
526           log_wr("TRY PRESAVE: ".$bri_user_cur->step." TRANS STEP: ".$bri_user_cur->trans_step);
527           
528           log_wr("Pre if!");
529           
530           //          ARRAY_POP DISABLED
531           //        // CHECK
532           while (array_pop($user_cur->comm) != NULL);
533           
534           $ret = "";
535           $ret .= sprintf('gst.st_loc++; gst.st=%d; createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); createCookie("lang", "%s", 24*365, cookiepath); the_end=true; window.onunload = null ; window.onbeforeunload = null ; document.location.assign("briskin5/index.php");|', $user_cur->step+1, $table_idx, $table_token, $G_lang);
536           
537           $user_cur->comm[$user_cur->step % COMM_N] = $ret;
538           $user_cur->trans_step = $user_cur->step + 1;
539           log_wr("TRANS ATTIVATO");
540           
541           
542           $user_cur->stat_set('table');
543           $user_cur->subst = 'asta';
544           $user_cur->laccwr = $curtime;
545           $user_cur->step_inc();
546         }
547         log_wr("presave bri");
548         Briskin5::save_data($bri);
549         Briskin5::unlock_data($bri_sem);
550         log_wr("postsave bri");
551       }
552       // change room
553       $room->room_sitdown(&$user, $table_idx);
554
555       log_wr("MOP finish");
556
557       
558     }
559     else if ($argz[0] == 'logout') {
560       $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
561       $user->comm[$user->step % COMM_N] .= 'postact_logout();';
562       $user->the_end = TRUE;
563       $user->step_inc();
564     }
565   }
566   /**********************
567    *                    *
568    *   SUBST: sitdown   *
569    *                    *
570    **********************/
571   else if ($user->subst == 'sitdown') {
572     if ($argz[0] == 'wakeup') {
573       $room->room_wakeup(&$user);      
574     }
575     else if ($argz[0] == 'logout') {
576       $room->room_wakeup(&$user);      
577       $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
578       $user->comm[$user->step % COMM_N] .= 'postact_logout();';
579       $user->the_end = TRUE;
580       $user->step_inc();
581     }
582   }
583 }
584 log_wr("before save data");
585 Room::save_data($room);
586
587 Room::unlock_data($sem);
588 exit;
589 ?>