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') {
71 if (($a_sem = Challenges::lock_data()) != FALSE) {
72 log_main("chal lock data success");
74 if (($chals = &Challenges::load_data()) != FALSE) {
78 // echo '2|'.$argz[1].'|'.$token.'|'.$_SERVER['REMOTE_ADDR'].'|'.$curtime.'|';
81 if (($login_new = validate_name(urldecode($cli_name))) != FALSE) {
82 if ($chals->add($login_new, $token, $_SERVER['REMOTE_ADDR'], $curtime) != FALSE) {
92 if ($chals->ismod()) {
93 Challenges::save_data(&$chals);
98 Challenges::unlock_data($a_sem);
101 else if ($argz[0] == 'auth') {
102 printf("challenge|ok");
104 else if ($argz[0] == 'help') {
105 /* MLANG: "torna ai tavoli" */
106 echo show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
108 else if ($argz[0] == 'about') {
109 echo show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
111 else if ($argz[0] == 'roadmap') {
112 echo show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
114 else if ($argz[0] == 'whysupport') {
115 echo show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
118 log_wr("Get User Error");
119 echo "Get User Error:" + $argz[0];
123 $argz = explode('|', $mesg);
125 log_wr('POSTSPLIT: '.$argz[0]);
127 if ($argz[0] == 'shutdown') {
128 log_auth($user->sess, "Shutdown session.");
132 log_rd2("AUTO LOGOUT.");
133 if ($user->subst == 'sitdown' || $user->stat == 'table')
134 $room->room_wakeup(&$user);
135 else if ($user->subst == 'standup')
136 $room->room_outstandup(&$user);
138 log_rd2("SHUTDOWN FROM WHAT ???");
141 else if ($argz[0] == 'warranty') {
142 GLOBAL $cli_name, $cli_email;
147 log_wr("INFO:SKIP:argz == warranty name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH));
148 if ($user->flags & USER_FLAG_AUTH) {
149 if (($wa_lock = Warrant::lock_data()) != FALSE) {
150 if (($fp = @fopen(LEGAL_PATH."/warrant.txt", 'a')) != FALSE) {
151 /* Unix time | session | nickname | IP | where was | mesg */
152 fwrite($fp, sprintf("%ld|%s|%s|%s|\n", $curtime, $user->name, xcapelt(urldecode($cli_name)), xcapelt(urldecode($cli_email))));
155 Warrant::unlock_data($wa_lock);
156 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
157 /* MLANG: "<br>Il nominativo è stato inoltrato all\'amministratore.<br><br>Nell\'arco di pochi giorni vi verrà<br><br>notificata l\'avvenuta registrazione." */
158 $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);
163 /* MLANG: "<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>" */
164 $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);
169 /* MLANG: "<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>" */
170 $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>");', $dt, NICKSERV);
173 if ($mesg_to_user != "") {
174 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
176 $dt = date("H:i ", $curtime);
177 $user->comm[$user->step % COMM_N] .= $mesg_to_user;
186 else if ($user->stat == 'room') {
187 $user->laccwr = time();
189 if ($argz[0] == 'help') {
190 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
191 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500);
193 log_wr($user->comm[$user->step % COMM_N]);
197 else if ($argz[0] == 'about') {
198 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
199 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200);
201 log_wr($user->comm[$user->step % COMM_N]);
205 else if ($argz[0] == 'roadmap') {
206 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
207 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_roadmap), 0, "torna ai tavoli", 400, 200);
209 log_wr($user->comm[$user->step % COMM_N]);
213 else if ($argz[0] == 'whysupport') {
214 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
215 $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_whysupport), 0, "torna ai tavoli", 400, 200);
217 log_wr($user->comm[$user->step % COMM_N]);
221 else if ($argz[0] == 'chatt') {
222 $room->chatt_send(&$user,$mesg);
224 /**********************
228 **********************/
229 else if ($user->subst == 'standup') {
231 if ($argz[0] == 'sitdown') {
232 log_wr("SITDOWN command");
234 if ($user->the_end == TRUE) {
235 log_wr("INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request.");
236 Room::unlock_data($sem);
241 $table_idx = $argz[1];
242 $table = &$room->table[$table_idx];
246 if ($G_shutdown || $table->wakeup_time > $curtime ||
247 ($table->auth_only && (($user->flags & USER_FLAG_AUTH) == 0)) ) {
248 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
250 $dt = date("H:i ", $curtime);
251 /* 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>" */
253 $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);
255 else if ($table->auth_only && (($user->flags & USER_FLAG_AUTH) == 0)) {
256 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>Il tavolo a cui volevi sederti richiede autentifica.</b>");', $dt, NICKSERV);
259 $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);
262 Room::save_data($room);
263 Room::unlock_data($sem);
267 /* TODO: refact to a function */
268 // if ($user->bantime > $user->laccwr) {
269 require_once("Obj/hardban.phh");
271 if (($bantime = Hardbans::check(($user->flags & USER_FLAG_AUTH ? $user->name : FALSE),
272 $user->ip, $user->sess)) != -1) {
273 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
274 /* 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." */
275 if ($user->flags & USER_FLAG_AUTH) {
276 $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);
279 $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);
282 Room::save_data($room);
283 Room::unlock_data($sem);
287 if ($table->player_n == PLAYERS_N) {
288 log_wr("WARN:FSM: Sitdown unreachable, table full.");
289 Room::unlock_data($sem);
294 $user->subst = "sitdown";
295 $user->table = $table_idx;
296 $user->table_pos = $table->user_add($idx);
298 log_wr("MOP before");
300 if ($table->player_n == PLAYERS_N) {
303 // Start game for this table.
304 log_wr("Start game!");
307 // START THE SPAWN HERE!!!!
312 // Create new spawned table
313 $bri_sem = Briskin5::lock_data($table_idx);
314 $table_token = uniqid("");
315 $room->table[$table_idx]->table_token = $table_token;
316 $room->table[$table_idx]->table_start = $curtime;
318 $plist = "$table_token|$user->table|$table->player_n";
319 for ($i = 0 ; $i < $table->player_n ; $i++) {
320 $plist .= '|'.$room->user[$table->player[$i]]->sess;
322 log_legal($curtime, $user, "STAT:CREATE_GAME", $plist);
324 if (($bri =& new Briskin5(&$room, $table_idx, $table_token)) == FALSE)
325 log_wr("bri create: FALSE");
327 log_wr("bri create: ".serialize($bri));
330 $bri_table =& $bri->table[0];
331 $bri_table->init(&$bri->user);
332 $bri_table->game_init(&$bri->user);
334 // Init spawned users.
336 for ($i = 0 ; $i < $table->player_n ; $i++) {
337 $bri_user_cur = &$bri->user[$i];
338 $user_cur = &$room->user[$table->player[$i]];
340 $bri_user_cur->stat_set('table');
341 $bri_user_cur->subst = 'asta';
342 $bri_user_cur->laccwr = $curtime;
344 $bri_user_cur->trans_step = $user_cur->step + 1;
345 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = "";
346 $bri_user_cur->step_inc();
347 $bri_user_cur->comm[$bri_user_cur->step % COMM_N] = show_table(&$bri,&$bri_user_cur,$bri_user_cur->step+1,TRUE, FALSE);
349 $bri_user_cur->step_inc();
351 log_wr("TRY PRESAVE: ".$bri_user_cur->step." TRANS STEP: ".$bri_user_cur->trans_step);
355 // ARRAY_POP DISABLED
357 while (array_pop($user_cur->comm) != NULL);
360 $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);
362 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
363 $user_cur->trans_step = $user_cur->step + 1;
364 log_wr("TRANS ATTIVATO");
367 $user_cur->stat_set('table');
368 $user_cur->subst = 'asta';
369 $user_cur->laccwr = $curtime;
370 $user_cur->step_inc();
372 log_wr("presave bri");
373 Briskin5::save_data($bri);
374 Briskin5::unlock_data($bri_sem);
375 log_wr("postsave bri");
378 $room->room_sitdown(&$user, $table_idx);
380 log_wr("MOP finish");
384 else if ($argz[0] == 'logout') {
385 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
386 $user->comm[$user->step % COMM_N] .= 'postact_logout();';
387 $user->the_end = TRUE;
391 /**********************
395 **********************/
396 else if ($user->subst == 'sitdown') {
397 if ($argz[0] == 'wakeup') {
398 $room->room_wakeup(&$user);
400 else if ($argz[0] == 'logout') {
401 $room->room_wakeup(&$user);
402 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
403 $user->comm[$user->step % COMM_N] .= 'postact_logout();';
404 $user->the_end = TRUE;
409 log_wr("before save data");
410 Room::save_data($room);
412 Room::unlock_data($sem);