5 * Copyright (C) 2006-2008 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
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.
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.
27 require_once("Obj/brisk.phh");
28 // require_once("Obj/proxyscan.phh");
29 require_once("briskin5/Obj/briskin5.phh");
31 // Use of proxies isn't allowed.
36 log_load("index_rd.php");
38 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
39 echo "Debugging time!";
43 log_load("index_wr.php");
50 log_wr('COMM: '.$mesg);
52 $sem = Room::lock_data();
53 if (($room = &Room::load_data()) == FALSE) {
54 echo "Load data error";
55 log_wr("Load data error");
56 Room::unlock_data($sem);
59 if (($user = &$room->get_user($sess, &$idx)) == FALSE) {
60 echo "Get User Error";
61 log_wr("Get User Error");
62 Room::unlock_data($sem);
65 $argz = explode('|', $mesg);
67 log_wr('POSTSPLIT: '.$argz[0]);
69 if ($argz[0] == 'shutdown') {
70 log_auth($user->sess, "Shutdown session.");
73 /* factorized with ->reset()
74 $tmp_sess = $user->sess;
76 step_unproxy($tmp_sess);
78 while (array_pop($user->comm) != NULL);
80 $user->the_end = FALSE;
83 log_rd2("AUTO LOGOUT.");
84 if ($user->subst == 'sitdown' || $user->stat == 'table')
85 $room->room_wakeup(&$user);
86 else if ($user->subst == 'standup')
87 $room->room_outstandup(&$user);
89 log_rd2("SHUTDOWN FROM WHAT ???");
96 else if ($user->stat == 'room') {
97 $user->laccwr = time();
99 if ($argz[0] == 'help') {
100 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
101 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
103 log_wr($user->comm[$user->step % COMM_N]);
107 else if ($argz[0] == 'about') {
108 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
109 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
111 log_wr($user->comm[$user->step % COMM_N]);
115 else if ($argz[0] == 'chatt') {
116 $room->chatt_send(&$user,$mesg);
118 /**********************
122 **********************/
123 else if ($user->subst == 'standup') {
125 if ($argz[0] == 'sitdown') {
126 log_wr("SITDOWN command");
128 if ($user->the_end == TRUE) {
129 log_wr("INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request.");
130 Room::unlock_data($sem);
135 $table_idx = $argz[1];
136 $table = &$room->table[$table_idx];
140 if ($G_shutdown || $table->wakeup_time > $curtime) {
141 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
143 $dt = date("H:i ", $curtime);
145 $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);
147 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","<b>Il tavolo si è appena liberato, ci si potrà sedere tra %d secondi.</b>");', $dt.NICKSERV, $table->wakeup_time - $curtime);
150 Room::save_data($room);
151 Room::unlock_data($sem);
155 /* TODO: refact to a function */
156 if ($user->bantime > $user->laccwr) {
157 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
158 $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);
161 Room::save_data($room);
162 Room::unlock_data($sem);
166 if ($table->player_n == PLAYERS_N) {
167 log_wr("WARN:FSM: Sitdown unreachable, table full.");
168 Room::unlock_data($sem);
173 $user->subst = "sitdown";
174 $user->table = $table_idx;
175 $user->table_pos = $table->user_add($idx);
177 log_wr("MOP before");
179 if ($table->player_n == PLAYERS_N) {
182 // Start game for this table.
183 log_wr("Start game!");
186 // START THE SPAWN HERE!!!!
190 // Create new spawned table
191 $bri_sem = Briskin5::lock_data($table_idx);
192 $table_token = uniqid("");
193 $room->table[$table_idx]->table_token = $table_token;
194 $room->table[$table_idx]->table_start = $curtime;
196 if (($bri =& new Briskin5(&$room, $table_idx, $table_token)) == FALSE)
197 log_wr("bri create: FALSE");
199 log_wr("bri create: ".serialize($bri));
202 $bri_table =& $bri->table[0];
203 $bri_table->init(&$bri->user);
204 $bri_table->game_init(&$bri->user);
206 // Init spawned users.
208 for ($i = 0 ; $i < $table->player_n ; $i++) {
209 $bri_user_cur = &$bri->user[$i];
210 $user_cur = &$room->user[$table->player[$i]];
212 $bri_user_cur->stat_set('table');
213 $bri_user_cur->subst = 'asta';
214 $bri_user_cur->laccwr = $curtime;
216 $bri_user_cur->trans_step = $user_cur->step + 1;
217 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = "";
218 $bri_user_cur->step_inc();
219 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = show_table(&$bri,&$bri_user_cur,$bri_user_cur->step+1,TRUE, FALSE);
221 $bri_user_cur->step_inc();
223 log_wr("TRY PRESAVE: ".$bri_user_cur->step." TRANS STEP: ".$bri_user_cur->trans_step);
227 // ARRAY_POP DISABLED
229 while (array_pop($user_cur->comm) != NULL);
232 $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);
234 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
235 $user_cur->trans_step = $user_cur->step + 1;
236 log_wr("TRANS ATTIVATO");
239 $user_cur->stat_set('table');
240 $user_cur->subst = 'asta';
241 $user_cur->laccwr = $curtime;
242 $user_cur->step_inc();
244 log_wr("presave bri");
245 Briskin5::save_data($bri);
246 Briskin5::unlock_data($bri_sem);
247 log_wr("postsave bri");
250 $room->room_sitdown(&$user, $table_idx);
252 log_wr("MOP finish");
256 else if ($argz[0] == 'logout') {
257 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
258 $user->comm[$user->step % COMM_N] .= sprintf('postact_logout();');
259 $user->the_end = TRUE;
263 /**********************
267 **********************/
268 else if ($user->subst == 'sitdown') {
269 if ($argz[0] == 'wakeup') {
270 $room->room_wakeup(&$user);
272 else if ($argz[0] == 'logout') {
273 $room->room_wakeup(&$user);
274 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
275 $user->comm[$user->step % COMM_N] .= sprintf('postact_logout();');
276 $user->the_end = TRUE;
281 log_wr("before save data");
282 Room::save_data($room);
284 Room::unlock_data($sem);