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_wr.php");
38 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
39 echo "Debugging time!";
47 /* if the IP is banned, exit without do nothing */
48 if (array_search($_SERVER['REMOTE_ADDR'], $G_black_list) !== FALSE) {
55 log_wr('COMM: '.$mesg);
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);
64 if (($user = &$room->get_user($sess, &$idx)) == FALSE) {
65 Room::unlock_data($sem);
66 $argz = explode('|', $mesg);
68 if ($argz[0] == 'help') {
69 echo show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
71 else if ($argz[0] == 'about') {
72 echo show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
74 else if ($argz[0] == 'roadmap') {
75 echo show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
77 else if ($argz[0] == 'whysupport') {
78 echo show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
81 log_wr("Get User Error");
82 echo "Get User Error";
86 $argz = explode('|', $mesg);
88 log_wr('POSTSPLIT: '.$argz[0]);
90 if ($argz[0] == 'shutdown') {
91 log_auth($user->sess, "Shutdown session.");
95 log_rd2("AUTO LOGOUT.");
96 if ($user->subst == 'sitdown' || $user->stat == 'table')
97 $room->room_wakeup(&$user);
98 else if ($user->subst == 'standup')
99 $room->room_outstandup(&$user);
101 log_rd2("SHUTDOWN FROM WHAT ???");
108 else if ($user->stat == 'room') {
109 $user->laccwr = time();
111 if ($argz[0] == 'help') {
112 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
113 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
115 log_wr($user->comm[$user->step % COMM_N]);
119 else if ($argz[0] == 'about') {
120 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
121 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
123 log_wr($user->comm[$user->step % COMM_N]);
127 else if ($argz[0] == 'roadmap') {
128 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
129 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
131 log_wr($user->comm[$user->step % COMM_N]);
135 else if ($argz[0] == 'whysupport') {
136 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
137 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
139 log_wr($user->comm[$user->step % COMM_N]);
143 else if ($argz[0] == 'chatt') {
144 $room->chatt_send(&$user,$mesg);
146 /**********************
150 **********************/
151 else if ($user->subst == 'standup') {
153 if ($argz[0] == 'sitdown') {
154 log_wr("SITDOWN command");
156 if ($user->the_end == TRUE) {
157 log_wr("INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request.");
158 Room::unlock_data($sem);
163 $table_idx = $argz[1];
164 $table = &$room->table[$table_idx];
168 if ($G_shutdown || $table->wakeup_time > $curtime) {
169 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
171 $dt = date("H:i ", $curtime);
173 $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);
175 $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);
178 Room::save_data($room);
179 Room::unlock_data($sem);
183 /* TODO: refact to a function */
184 if ($user->bantime > $user->laccwr) {
185 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
186 $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);
189 Room::save_data($room);
190 Room::unlock_data($sem);
194 if ($table->player_n == PLAYERS_N) {
195 log_wr("WARN:FSM: Sitdown unreachable, table full.");
196 Room::unlock_data($sem);
201 $user->subst = "sitdown";
202 $user->table = $table_idx;
203 $user->table_pos = $table->user_add($idx);
205 log_wr("MOP before");
207 if ($table->player_n == PLAYERS_N) {
210 // Start game for this table.
211 log_wr("Start game!");
214 // START THE SPAWN HERE!!!!
219 // Create new spawned table
220 $bri_sem = Briskin5::lock_data($table_idx);
221 $table_token = uniqid("");
222 $room->table[$table_idx]->table_token = $table_token;
223 $room->table[$table_idx]->table_start = $curtime;
225 $plist = "$table_token|$user->table|$table->player_n";
226 for ($i = 0 ; $i < $table->player_n ; $i++) {
227 $plist .= '|'.$room->user[$table->player[$i]]->sess;
229 log_legal($curtime, $user->sess, $user->name, "STAT:CREATE_GAME", $plist);
231 if (($bri =& new Briskin5(&$room, $table_idx, $table_token)) == FALSE)
232 log_wr("bri create: FALSE");
234 log_wr("bri create: ".serialize($bri));
237 $bri_table =& $bri->table[0];
238 $bri_table->init(&$bri->user);
239 $bri_table->game_init(&$bri->user);
241 // Init spawned users.
243 for ($i = 0 ; $i < $table->player_n ; $i++) {
244 $bri_user_cur = &$bri->user[$i];
245 $user_cur = &$room->user[$table->player[$i]];
247 $bri_user_cur->stat_set('table');
248 $bri_user_cur->subst = 'asta';
249 $bri_user_cur->laccwr = $curtime;
251 $bri_user_cur->trans_step = $user_cur->step + 1;
252 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = "";
253 $bri_user_cur->step_inc();
254 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = show_table(&$bri,&$bri_user_cur,$bri_user_cur->step+1,TRUE, FALSE);
256 $bri_user_cur->step_inc();
258 log_wr("TRY PRESAVE: ".$bri_user_cur->step." TRANS STEP: ".$bri_user_cur->trans_step);
262 // ARRAY_POP DISABLED
264 while (array_pop($user_cur->comm) != NULL);
267 $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);
269 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
270 $user_cur->trans_step = $user_cur->step + 1;
271 log_wr("TRANS ATTIVATO");
274 $user_cur->stat_set('table');
275 $user_cur->subst = 'asta';
276 $user_cur->laccwr = $curtime;
277 $user_cur->step_inc();
279 log_wr("presave bri");
280 Briskin5::save_data($bri);
281 Briskin5::unlock_data($bri_sem);
282 log_wr("postsave bri");
285 $room->room_sitdown(&$user, $table_idx);
287 log_wr("MOP finish");
291 else if ($argz[0] == 'logout') {
292 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
293 $user->comm[$user->step % COMM_N] .= 'postact_logout();';
294 $user->the_end = TRUE;
298 /**********************
302 **********************/
303 else if ($user->subst == 'sitdown') {
304 if ($argz[0] == 'wakeup') {
305 $room->room_wakeup(&$user);
307 else if ($argz[0] == 'logout') {
308 $room->room_wakeup(&$user);
309 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
310 $user->comm[$user->step % COMM_N] .= 'postact_logout();';
311 $user->the_end = TRUE;
316 log_wr("before save data");
317 Room::save_data($room);
319 Room::unlock_data($sem);