5 * Copyright (C) 2006-2009 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");
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: '.xcapemesg($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('|', xcapemesg($mesg));
68 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(urldecode($cli_name))) != 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 /* MLANG: "torna ai tavoli" */
105 echo show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
107 else if ($argz[0] == 'about') {
108 echo show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
110 else if ($argz[0] == 'passwdhowto') {
111 echo show_notify(str_replace("\n", " ", $G_room_passwdhowto), 0, "torna ai tavoli", 400, 200);
113 else if ($argz[0] == 'roadmap') {
114 echo show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
116 else if ($argz[0] == 'whysupport') {
117 echo show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
120 log_wr("Get User Error");
121 echo "Get User Error:" + $argz[0];
125 $argz = explode('|', xcapemesg($mesg));
127 log_wr('POSTSPLIT: '.$argz[0]);
129 if ($argz[0] == 'shutdown') {
130 log_auth($user->sess, "Shutdown session.");
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);
140 log_rd2("SHUTDOWN FROM WHAT ???");
143 else if ($argz[0] == 'warranty') {
144 GLOBAL $cli_name, $cli_email;
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))));
157 Warrant::unlock_data($wa_lock);
158 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
159 /* MLANG: "<br>Il nominativo è stato inoltrato all\'amministratore.<br><br>Nell\'arco di pochi giorni vi verrà<br><br>notificata l\'avvenuta registrazione." */
160 $user->comm[$user->step % COMM_N] .= show_notify("<br>Il nominativo è stato inoltrato all\'amministratore.<br><br>Nell\'arco di pochi giorni vi verrà<br><br>notificata l\'avvenuta registrazione.", 0, "chiudi", 400, 150);
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);
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);
175 if ($mesg_to_user != "") {
176 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
178 $dt = date("H:i ", $curtime);
179 $user->comm[$user->step % COMM_N] .= $mesg_to_user;
183 else if ($argz[0] == 'mesgtoadm') {
184 GLOBAL $cli_subj, $cli_mesg;
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 if (($fp = @fopen(LEGAL_PATH."/messages.txt", 'a')) != FALSE) {
193 /* Unix time | session | nickname | IP | where was | mesg */
194 fwrite($fp, sprintf("%ld|%s|%s|%s\n", $curtime, $user->name,
195 xcapelt(urldecode($cli_subj)), xcapelt(urldecode($cli_mesg))));
198 Warrant::unlock_data($wa_lock);
199 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
201 $user->comm[$user->step % COMM_N] .= show_notify("<br><br>Il messaggio è stato inoltrato all\'amministratore.", 0, "chiudi", 400, 110);
206 /* MLANG: "<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>" */
207 $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);
212 /* MLANG: "<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>" */
213 $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per mandare messaggi all\'amministratore devi essere autenticato.</b>");', $dt, NICKSERV);
216 if ($mesg_to_user != "") {
217 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
219 $dt = date("H:i ", $curtime);
220 $user->comm[$user->step % COMM_N] .= $mesg_to_user;
231 else if ($user->stat == 'room') {
232 $user->laccwr = time();
234 if ($argz[0] == 'help') {
235 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
236 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
238 log_wr($user->comm[$user->step % COMM_N]);
242 else if ($argz[0] == 'passwdhowto') {
243 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
244 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_passwdhowto), 0, "torna ai tavoli", 600, 500);
246 log_wr($user->comm[$user->step % COMM_N]);
250 else if ($argz[0] == 'about') {
251 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
252 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
254 log_wr($user->comm[$user->step % COMM_N]);
258 else if ($argz[0] == 'roadmap') {
259 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
260 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
262 log_wr($user->comm[$user->step % COMM_N]);
266 else if ($argz[0] == 'whysupport') {
267 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
268 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
270 log_wr($user->comm[$user->step % COMM_N]);
274 else if ($argz[0] == 'chatt') {
275 $room->chatt_send(&$user, xcapemesg($mesg));
277 /**********************
281 **********************/
282 else if ($user->subst == 'standup') {
284 if ($argz[0] == 'sitdown') {
285 log_wr("SITDOWN command");
287 if ($user->the_end == TRUE) {
288 log_wr("INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request.");
289 Room::unlock_data($sem);
294 $table_idx = $argz[1];
295 $table = &$room->table[$table_idx];
299 if ($G_shutdown || $table->wakeup_time > $curtime ||
300 ($table->auth_only && (($user->flags & USER_FLAG_AUTH) == 0)) ) {
301 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
303 $dt = date("H:i ", $curtime);
304 /* 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 è appena liberato, ci si potrà sedere tra %d secondi.</b>" */
306 $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);
308 else if ($table->auth_only && (($user->flags & USER_FLAG_AUTH) == 0)) {
309 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>Il tavolo a cui volevi sederti richiede autentifica.</b>");', $dt, NICKSERV);
312 $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);
315 Room::save_data($room);
316 Room::unlock_data($sem);
320 /* TODO: refact to a function */
321 // if ($user->bantime > $user->laccwr) {
322 require_once("Obj/hardban.phh");
324 if (($bantime = Hardbans::check(($user->flags & USER_FLAG_AUTH ? $user->name : FALSE),
325 $user->ip, $user->sess)) != -1) {
326 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
327 /* 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." */
328 if ($user->flags & USER_FLAG_AUTH) {
329 $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);
332 $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);
335 Room::save_data($room);
336 Room::unlock_data($sem);
340 if ($table->player_n == PLAYERS_N) {
341 log_wr("WARN:FSM: Sitdown unreachable, table full.");
342 Room::unlock_data($sem);
347 $user->subst = "sitdown";
348 $user->table = $table_idx;
349 $user->table_pos = $table->user_add($idx);
351 log_wr("MOP before");
353 if ($table->player_n == PLAYERS_N) {
354 require_once("briskin5/Obj/briskin5.phh");
357 // Start game for this table.
358 log_wr("Start game!");
361 // START THE SPAWN HERE!!!!
366 // Create new spawned table
367 $bri_sem = Briskin5::lock_data($table_idx);
368 $table_token = uniqid("");
369 $room->table[$table_idx]->table_token = $table_token;
370 $room->table[$table_idx]->table_start = $curtime;
372 $plist = "$table_token|$user->table|$table->player_n";
373 for ($i = 0 ; $i < $table->player_n ; $i++) {
374 $plist .= '|'.$room->user[$table->player[$i]]->sess;
376 log_legal($curtime, $user, "STAT:CREATE_GAME", $plist);
378 if (($bri =& new Briskin5(&$room, $table_idx, $table_token)) == FALSE)
379 log_wr("bri create: FALSE");
381 log_wr("bri create: ".serialize($bri));
384 $bri_table =& $bri->table[0];
385 $bri_table->init(&$bri->user);
386 $bri_table->game_init(&$bri->user);
388 // Init spawned users.
390 require_once('briskin5/Obj/briskin5.phh');
392 // MULTIGAME: here init of selected game instead of hardcabled briskin5 init (look subst status)
394 for ($i = 0 ; $i < $table->player_n ; $i++) {
395 $bri_user_cur = &$bri->user[$i];
396 $user_cur = &$room->user[$table->player[$i]];
398 $bri_user_cur->stat_set('table');
399 $bri_user_cur->subst = 'asta';
400 $bri_user_cur->laccwr = $curtime;
402 $bri_user_cur->trans_step = $user_cur->step + 1;
403 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = "";
404 $bri_user_cur->step_inc();
405 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = show_table(&$bri,&$bri_user_cur,$bri_user_cur->step+1,TRUE, FALSE);
407 $bri_user_cur->step_inc();
409 log_wr("TRY PRESAVE: ".$bri_user_cur->step." TRANS STEP: ".$bri_user_cur->trans_step);
413 // ARRAY_POP DISABLED
415 while (array_pop($user_cur->comm) != NULL);
418 $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);
420 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
421 $user_cur->trans_step = $user_cur->step + 1;
422 log_wr("TRANS ATTIVATO");
425 $user_cur->stat_set('table');
426 $user_cur->subst = 'asta';
427 $user_cur->laccwr = $curtime;
428 $user_cur->step_inc();
430 log_wr("presave bri");
431 Briskin5::save_data($bri);
432 Briskin5::unlock_data($bri_sem);
433 log_wr("postsave bri");
436 $room->room_sitdown(&$user, $table_idx);
438 log_wr("MOP finish");
442 else if ($argz[0] == 'logout') {
443 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
444 $user->comm[$user->step % COMM_N] .= 'postact_logout();';
445 $user->the_end = TRUE;
449 /**********************
453 **********************/
454 else if ($user->subst == 'sitdown') {
455 if ($argz[0] == 'wakeup') {
456 $room->room_wakeup(&$user);
458 else if ($argz[0] == 'logout') {
459 $room->room_wakeup(&$user);
460 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
461 $user->comm[$user->step % COMM_N] .= 'postact_logout();';
462 $user->the_end = TRUE;
467 log_wr("before save data");
468 Room::save_data($room);
470 Room::unlock_data($sem);