5 * Copyright (C) 2006 matteo.nastasi@milug.org
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.
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.
24 require_once("Obj/brisk.phh");
25 // require_once("Obj/proxyscan.phh");
26 require_once("briskin5/Obj/briskin5.phh");
28 // Use of proxies isn't allowed.
33 log_load("index_rd.php");
35 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
36 echo "Debugging time!";
40 log_load("index_wr.php");
47 log_wr('COMM: '.$mesg);
49 $sem = Room::lock_data();
50 if (($room = &Room::load_data()) == FALSE) {
51 echo "Load data error";
52 log_wr("Load data error");
53 Room::unlock_data($sem);
56 if (($user = &$room->get_user($sess, &$idx)) == FALSE) {
57 echo "Get User Error";
58 log_wr("Get User Error");
59 Room::unlock_data($sem);
62 $argz = explode('|', $mesg);
64 log_wr('POSTSPLIT: '.$argz[0]);
66 if ($argz[0] == 'shutdown') {
67 log_auth($user->sess, "Shutdown session.");
70 /* factorized with ->reset()
71 $tmp_sess = $user->sess;
73 step_unproxy($tmp_sess);
75 while (array_pop($user->comm) != NULL);
77 $user->the_end = FALSE;
80 log_rd2("AUTO LOGOUT.");
81 if ($user->subst == 'sitdown' || $user->stat == 'table')
82 $room->room_wakeup(&$user);
83 else if ($user->subst == 'standup')
84 $room->room_outstandup(&$user);
86 log_rd2("SHUTDOWN FROM WHAT ???");
93 else if ($user->stat == 'room') {
94 $user->laccwr = time();
96 if ($argz[0] == 'help') {
97 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
98 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
100 log_wr($user->comm[$user->step % COMM_N]);
104 else if ($argz[0] == 'about') {
105 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
106 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
108 log_wr($user->comm[$user->step % COMM_N]);
112 else if ($argz[0] == 'chatt') {
113 $room->chatt_send(&$user,$mesg);
115 /**********************
119 **********************/
120 else if ($user->subst == 'standup') {
122 if ($argz[0] == 'sitdown') {
123 log_wr("SITDOWN command");
126 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
129 $dt = date("H:i ", $timecur);
130 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","<b>Il server sta per essere riavviato, non possono avere inizio nuove partite.</b>");', $dt.NICKSERV);
133 Room::save_data($room);
134 Room::unlock_data($sem);
138 if ($user->the_end == TRUE) {
139 log_wr("INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request.");
140 Room::unlock_data($sem);
143 /* TODO: refact to a function */
144 if ($user->bantime > $user->laccwr) {
145 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
146 $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, "resta in piedi.", 400, 100);
149 Room::save_data($room);
150 Room::unlock_data($sem);
155 $table_idx = $argz[1];
156 $table = &$room->table[$table_idx];
158 if ($table->player_n == PLAYERS_N) {
159 log_wr("WARN:FSM: Sitdown unreachable, table full.");
160 Room::unlock_data($sem);
165 $user->subst = "sitdown";
166 $user->table = $table_idx;
167 $user->table_pos = $table->user_add($idx);
169 log_wr("MOP before");
171 if ($table->player_n == PLAYERS_N) {
174 // Start game for this table.
175 log_wr("Start game!");
178 // START THE SPAWN HERE!!!!
181 if (TRUE) { // WITH SPAWN
183 // Create new spawned table
184 $bri_sem = Briskin5::lock_data($table_idx);
185 $table_token = uniqid("");
186 $room->table[$table_idx]->table_token = $table_token;
187 $room->table[$table_idx]->table_start = $curtime;
189 if (($bri =& new Briskin5(&$room, $table_idx, $table_token)) == FALSE)
190 log_wr("bri create: FALSE");
192 log_wr("bri create: ".serialize($bri));
195 $bri_table =& $bri->table[0];
196 $bri_table->init(&$bri->user);
197 $bri_table->game_init(&$bri->user);
199 // Init spawned users.
201 for ($i = 0 ; $i < $table->player_n ; $i++) {
202 $bri_user_cur = &$bri->user[$i];
203 $user_cur = &$room->user[$table->player[$i]];
205 $bri_user_cur->stat_set('table');
206 $bri_user_cur->subst = 'asta';
207 $bri_user_cur->laccwr = $curtime;
209 $bri_user_cur->trans_step = $user_cur->step + 1;
210 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = "";
211 $bri_user_cur->step_inc();
212 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = show_table(&$bri,&$bri_user_cur,$bri_user_cur->step+1,TRUE, FALSE);
214 $bri_user_cur->step_inc();
216 log_wr("TRY PRESAVE: ".$bri_user_cur->step." TRANS STEP: ".$bri_user_cur->trans_step);
220 // ARRAY_POP DISABLED
222 while (array_pop($user_cur->comm) != NULL);
225 $ret .= sprintf('gst.st_loc++; gst.st=%d; createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); the_end=true; window.onunload = null ; document.location.assign("briskin5/index.php");|', $user_cur->step+1, $table_idx, $table_token);
227 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
228 $user_cur->trans_step = $user_cur->step + 1;
229 log_wr("TRANS ATTIVATO");
232 $user_cur->stat_set('table');
233 $user_cur->subst = 'asta';
234 $user_cur->laccwr = $curtime;
235 $user_cur->step_inc();
237 log_wr("presave bri");
238 Briskin5::save_data($bri);
239 Briskin5::unlock_data($bri_sem);
240 log_wr("postsave bri");
242 else { // BEFORE SPAWN
244 $table->init(&$room->user);
245 $table->game_init(&$room->user);
249 for ($i = 0 ; $i < $table->player_n ; $i++) {
250 $user_cur = &$room->user[$table->player[$i]];
254 $ret .= sprintf('gst.st_loc++; gst.st=%d; the_end=true; window.onunload = null ; document.location.assign("table.php");|', $user_cur->step+1);
256 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
257 $user_cur->trans_step = $user_cur->step + 1;
258 log_wr("TRANS ATTIVATO");
261 $user_cur->stat_set('table');
262 $user_cur->subst = 'asta';
263 $user_cur->laccwr = $curtime;
264 $user_cur->step_inc();
266 $user_cur->comm[$user_cur->step % COMM_N] = show_table(&$room,&$user_cur,$user_cur->step+1,TRUE, FALSE);
267 $user_cur->step_inc();
269 } // end else { BEFORE SPAWN
275 $room->room_sitdown(&$user, $table_idx);
277 log_wr("MOP finish");
281 else if ($argz[0] == 'logout') {
282 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
283 $user->comm[$user->step % COMM_N] .= sprintf('postact_logout();');
284 $user->the_end = TRUE;
288 /**********************
292 **********************/
293 else if ($user->subst == 'sitdown') {
294 if ($argz[0] == 'wakeup') {
295 $room->room_wakeup(&$user);
297 else if ($argz[0] == 'logout') {
298 $room->room_wakeup(&$user);
299 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
300 $user->comm[$user->step % COMM_N] .= sprintf('postact_logout();');
301 $user->the_end = TRUE;
306 log_wr("before save data");
307 Room::save_data($room);
309 Room::unlock_data($sem);