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/auth.phh");
29 // require_once("Obj/proxyscan.phh");
30 require_once("briskin5/Obj/briskin5.phh");
32 // Use of proxies isn't allowed.
37 log_load("index_wr.php");
39 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
40 echo "Debugging time!";
48 /* if the IP is banned, exit without do nothing */
49 if (array_search($_SERVER['REMOTE_ADDR'], $G_black_list) !== FALSE) {
56 log_wr('COMM: '.$mesg);
58 $sem = Room::lock_data();
59 if (($room = &Room::load_data()) == FALSE) {
60 echo "Load data error";
61 log_wr("Load data error");
62 Room::unlock_data($sem);
65 if (($user = &$room->get_user($sess, &$idx)) == FALSE) {
66 Room::unlock_data($sem);
67 $argz = explode('|', $mesg);
69 if ($argz[0] == 'getchallenge') {
70 if (($a_sem = Challenges::lock_data()) != FALSE) {
71 log_main("chal lock data success");
73 if (($chals = &Challenges::load_data()) != FALSE) {
77 // echo '2|'.$argz[1].'|'.$token.'|'.$_SERVER['REMOTE_ADDR'].'|'.$curtime.'|';
80 if (($login_new = validate_name($argz[1])) != FALSE) {
81 if ($chals->add($login_new, $token, $_SERVER['REMOTE_ADDR'], $curtime) != FALSE) {
91 if ($chals->ismod()) {
92 Challenges::save_data(&$chals);
97 Challenges::unlock_data($a_sem);
100 else if ($argz[0] == 'auth') {
101 printf("challenge|ok");
103 else if ($argz[0] == 'help') {
104 echo show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
106 else if ($argz[0] == 'about') {
107 echo show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
109 else if ($argz[0] == 'roadmap') {
110 echo show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
112 else if ($argz[0] == 'whysupport') {
113 echo show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
116 log_wr("Get User Error");
117 echo "Get User Error:" + $argz[0];
121 $argz = explode('|', $mesg);
123 log_wr('POSTSPLIT: '.$argz[0]);
125 if ($argz[0] == 'shutdown') {
126 log_auth($user->sess, "Shutdown session.");
130 log_rd2("AUTO LOGOUT.");
131 if ($user->subst == 'sitdown' || $user->stat == 'table')
132 $room->room_wakeup(&$user);
133 else if ($user->subst == 'standup')
134 $room->room_outstandup(&$user);
136 log_rd2("SHUTDOWN FROM WHAT ???");
143 else if ($user->stat == 'room') {
144 $user->laccwr = time();
146 if ($argz[0] == 'help') {
147 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
148 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
150 log_wr($user->comm[$user->step % COMM_N]);
154 else if ($argz[0] == 'about') {
155 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
156 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
158 log_wr($user->comm[$user->step % COMM_N]);
162 else if ($argz[0] == 'roadmap') {
163 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
164 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
166 log_wr($user->comm[$user->step % COMM_N]);
170 else if ($argz[0] == 'whysupport') {
171 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
172 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
174 log_wr($user->comm[$user->step % COMM_N]);
178 else if ($argz[0] == 'chatt') {
179 $room->chatt_send(&$user,$mesg);
181 /**********************
185 **********************/
186 else if ($user->subst == 'standup') {
188 if ($argz[0] == 'sitdown') {
189 log_wr("SITDOWN command");
191 if ($user->the_end == TRUE) {
192 log_wr("INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request.");
193 Room::unlock_data($sem);
198 $table_idx = $argz[1];
199 $table = &$room->table[$table_idx];
203 if ($G_shutdown || $table->wakeup_time > $curtime ||
204 ($table->auth_only && (($user->flags & USER_FLAG_AUTH) == 0)) ) {
205 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
207 $dt = date("H:i ", $curtime);
209 $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);
211 else if ($table->auth_only && (($user->flags & USER_FLAG_AUTH) == 0)) {
212 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>Il tavolo a cui volevi sederti richiede autentifica.</b>");', $dt, NICKSERV);
215 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>Il tavolo si è appena liberato, ci si potrà sedere tra %d secondi.</b>");', $dt, NICKSERV, $table->wakeup_time - $curtime);
218 Room::save_data($room);
219 Room::unlock_data($sem);
223 /* TODO: refact to a function */
224 // if ($user->bantime > $user->laccwr) {
225 require_once("Obj/hardban.phh");
227 if (($bantime = Hardbans::check(($user->flags & USER_FLAG_AUTH ? $user->name : FALSE),
228 $user->ip, $user->sess)) != -1) {
229 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
230 if ($user->flags & USER_FLAG_AUTH) {
231 $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);
234 $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);
237 Room::save_data($room);
238 Room::unlock_data($sem);
242 if ($table->player_n == PLAYERS_N) {
243 log_wr("WARN:FSM: Sitdown unreachable, table full.");
244 Room::unlock_data($sem);
249 $user->subst = "sitdown";
250 $user->table = $table_idx;
251 $user->table_pos = $table->user_add($idx);
253 log_wr("MOP before");
255 if ($table->player_n == PLAYERS_N) {
258 // Start game for this table.
259 log_wr("Start game!");
262 // START THE SPAWN HERE!!!!
267 // Create new spawned table
268 $bri_sem = Briskin5::lock_data($table_idx);
269 $table_token = uniqid("");
270 $room->table[$table_idx]->table_token = $table_token;
271 $room->table[$table_idx]->table_start = $curtime;
273 $plist = "$table_token|$user->table|$table->player_n";
274 for ($i = 0 ; $i < $table->player_n ; $i++) {
275 $plist .= '|'.$room->user[$table->player[$i]]->sess;
277 log_legal($curtime, $user->sess, $user->name, "STAT:CREATE_GAME", $plist);
279 if (($bri =& new Briskin5(&$room, $table_idx, $table_token)) == FALSE)
280 log_wr("bri create: FALSE");
282 log_wr("bri create: ".serialize($bri));
285 $bri_table =& $bri->table[0];
286 $bri_table->init(&$bri->user);
287 $bri_table->game_init(&$bri->user);
289 // Init spawned users.
291 for ($i = 0 ; $i < $table->player_n ; $i++) {
292 $bri_user_cur = &$bri->user[$i];
293 $user_cur = &$room->user[$table->player[$i]];
295 $bri_user_cur->stat_set('table');
296 $bri_user_cur->subst = 'asta';
297 $bri_user_cur->laccwr = $curtime;
299 $bri_user_cur->trans_step = $user_cur->step + 1;
300 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = "";
301 $bri_user_cur->step_inc();
302 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = show_table(&$bri,&$bri_user_cur,$bri_user_cur->step+1,TRUE, FALSE);
304 $bri_user_cur->step_inc();
306 log_wr("TRY PRESAVE: ".$bri_user_cur->step." TRANS STEP: ".$bri_user_cur->trans_step);
310 // ARRAY_POP DISABLED
312 while (array_pop($user_cur->comm) != NULL);
315 $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 ; window.onbeforeunload = null ; document.location.assign("briskin5/index.php");|', $user_cur->step+1, $table_idx, $table_token);
317 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
318 $user_cur->trans_step = $user_cur->step + 1;
319 log_wr("TRANS ATTIVATO");
322 $user_cur->stat_set('table');
323 $user_cur->subst = 'asta';
324 $user_cur->laccwr = $curtime;
325 $user_cur->step_inc();
327 log_wr("presave bri");
328 Briskin5::save_data($bri);
329 Briskin5::unlock_data($bri_sem);
330 log_wr("postsave bri");
333 $room->room_sitdown(&$user, $table_idx);
335 log_wr("MOP finish");
339 else if ($argz[0] == 'logout') {
340 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
341 $user->comm[$user->step % COMM_N] .= 'postact_logout();';
342 $user->the_end = TRUE;
346 /**********************
350 **********************/
351 else if ($user->subst == 'sitdown') {
352 if ($argz[0] == 'wakeup') {
353 $room->room_wakeup(&$user);
355 else if ($argz[0] == 'logout') {
356 $room->room_wakeup(&$user);
357 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
358 $user->comm[$user->step % COMM_N] .= 'postact_logout();';
359 $user->the_end = TRUE;
364 log_wr("before save data");
365 Room::save_data($room);
367 Room::unlock_data($sem);