From c632ffe4efc44480dcb52954fc088a24a04a712d Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Sat, 12 Jan 2008 10:45:54 +0000 Subject: [PATCH] renamed class brisco to Room, some free funcs moved to static class funcs, split standard constructor func to be able to have multiple constructors --- INSTALL.sh | 2 +- web/brisk.phh | 401 +++++++++++++++++++++++++---------------------- web/index.php | 20 +-- web/index_rd.php | 62 ++++---- web/index_wr.php | 143 +++++++++-------- 5 files changed, 330 insertions(+), 298 deletions(-) diff --git a/INSTALL.sh b/INSTALL.sh index 5685462..18a93bd 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -9,7 +9,7 @@ web_path="$HOME/brisk" web_only="FALSE" if [ -f $HOME/.brisk_install ]; then - . $HOME/.brisk_install + . $HOME/.spawn_install fi if [ "x$cookie_path" = "x" ]; then cookie_path=$web_path diff --git a/web/brisk.phh b/web/brisk.phh index 1fe3f12..2fc0462 100644 --- a/web/brisk.phh +++ b/web/brisk.phh @@ -166,27 +166,37 @@ class Table { function Table() { - $this->player = array(); - $this->player_n = 0; - $this->card = &$this->bunch_create(); - $this->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction - $this->asta_pla_n= -1; - $this->asta_card = -1; - $this->asta_pnt = -1; - $this->mult = 1; - $this->points = array( ); - $this->points_n = 0; - $this->total = array( 0, 0, 0, 0, 0); - $this->asta_win = -1; - $this->briscola = -1; - $this->friend = -1; - $this->turn = 0; - $this->old_reason = ""; - $this->old_asta_pnt = -1; - $this->old_pnt = -1; - $this->old_win = -1; - $this->old_friend= -1; + } + + function &create() + { + GLOBAL $G_false; + + if (($thiz = new Table()) == FALSE) + return ($G_false); + $thiz->player = array(); + $thiz->player_n = 0; + $thiz->card = &$thiz->bunch_create(); + $thiz->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction + $thiz->asta_pla_n= -1; + $thiz->asta_card = -1; + $thiz->asta_pnt = -1; + $thiz->mult = 1; + $thiz->points = array( ); + $thiz->points_n = 0; + $thiz->total = array( 0, 0, 0, 0, 0); + $thiz->asta_win = -1; + $thiz->briscola = -1; + $thiz->friend = -1; + $thiz->turn = 0; + $thiz->old_reason = ""; + $thiz->old_asta_pnt = -1; + $thiz->old_pnt = -1; + $thiz->old_win = -1; + $thiz->old_friend= -1; + + return ($thiz); } function &bunch_create() @@ -292,17 +302,17 @@ class Table { return ($this->player_n - 1); } - function user_rem(&$bri, &$user) + function user_rem(&$room, &$user) { $tabpos = $user->table_pos; /* verifico la consistenza dei dati */ - if ($bri->user[$this->player[$tabpos]] == $user) { + if ($room->user[$this->player[$tabpos]] == $user) { /* aggiorna l'array dei giocatori al tavolo. */ for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) { $this->player[$i] = $this->player[$i+1]; - $user_cur = &$bri->user[$this->player[$i]]; + $user_cur = &$room->user[$this->player[$i]]; $user_cur->table_pos = $i; } $this->player_n--; @@ -371,24 +381,34 @@ class User { var $table_pos; // idx on the table var $the_end; // Flag to change the end of the session - function User($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") { - $this->name = $name; - $this->sess = $sess; - $this->ip = $ip; - $this->lacc = time(); - $this->laccwr = time(); - $this->bantime = 0; - $this->stat = $stat; - $this->subst = $subst; - $this->step = 1; - $this->trans_step = -1; - $this->comm = array(); - $this->asta_card = -2; - $this->asta_pnt = -1; - $this->handpt = -1; - $this->exitislock = TRUE; + function User() { + } + + function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") { + GLOBAL $G_false; + + if (($thiz = new User()) == FALSE) + return ($G_false); + + $thiz->name = $name; + $thiz->sess = $sess; + $thiz->ip = $ip; + $thiz->lacc = time(); + $thiz->laccwr = time(); + $thiz->bantime = 0; + $thiz->stat = $stat; + $thiz->subst = $subst; + $thiz->step = 1; + $thiz->trans_step = -1; + $thiz->comm = array(); + $thiz->asta_card = -2; + $thiz->asta_pnt = -1; + $thiz->handpt = -1; + $thiz->exitislock = TRUE; + + $thiz->table = $table; - $this->table = $table; + return ($thiz); } function stat_set($stat) { @@ -471,21 +491,22 @@ function step_unproxy($sess) { } -class brisco { +class Room { var $user; var $table; var $comm; // commands for many people var $step; // current step of the comm array var $garbage_timeout; - function brisco () { + function Room () { $this->user = array(); for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { - $this->user[$i] =& new User("", ""); + $this->user[$i] =& User::create("", ""); } + for ($i = 0 ; $i < TABLES_N ; $i++) - $this->table[$i] =& new Table(); + $this->table[$i] =& Table::create(); $this->garbage_timeout = 0; } @@ -824,7 +845,7 @@ class brisco { } /* - * function &add_user(&$bri, &$sess, &$idx, $name, $ip) + * function &add_user(&$room, &$sess, &$idx, $name, $ip) * * RETURN VALUE: * if ($idx != -1 && ret == FALSE) => duplicated nick @@ -915,8 +936,118 @@ class brisco { } } + // Static functions + function &init_data() + { + $room =& new Room(); + + return $room; + } + + + function &load_data() + { + GLOBAL $G_false, $sess; + + if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) { + echo "FTOK FAILED"; + exit; + } + + if ($shm = shm_attach($tok, SHM_DIMS)) { + $room = @shm_get_var($shm, $tok); + + log_only($sess, "bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE")); + if (isset($room)) + log_only($sess, "bri count ".count($room)); + + if ($room == FALSE) { + log_only($sess, "INIT MAIN DATA"); + + $room =& Room::init_data(); + if (shm_put_var($shm, $tok, $room) == FALSE) { + log_only($sess, "PUT_VAR FALLITA ".strlen(serialize($room))); + log_only($sess, serialize($room)); + } + } + + shm_detach($shm); + + $ret = &$room; + return ($ret); + } + + return ($G_false); + } + + + function save_data(&$room) + { + GLOBAL $sess; + + $ret = FALSE; + $shm = FALSE; + $isacq = FALSE; + + // var_dump($room); + + if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) + return (FALSE); + + do { + $isacq = TRUE; + + if (($shm = shm_attach($tok, SHM_DIMS)) == FALSE) + break; + + // log_only($sess, "PUT_VAR DI ".strlen(serialize($room))); + if (shm_put_var($shm, $tok, $room) == FALSE) { + log_only($sess, "PUT_VAR FALLITA ".strlen(serialize($room))); + log_only($sess, serialize($room)); + break; + } + // log_main("XXX", "QUI CI ARRIVA [".$room->user[0]->name."]"); + $ret = TRUE; + } while (0); + + if ($shm) + shm_detach($shm); + + return ($ret); + } + + function lock_data() + { + GLOBAL $sess; + + // echo "LOCK: ".FTOK_PATH."/main"; + // exit; + if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) { + echo "FTOK FAILED"; + exit; + } + // echo "FTOK ".$tok."
"; + if (($res = sem_get($tok)) == FALSE) { + echo "SEM_GET FAILED"; + exit; + } + if (sem_acquire($res)) { + log_only($sess, "LOCK"); + return ($res); + } + else + return (FALSE); + } + + function unlock_data($res) + { + GLOBAL $sess; + + log_only($sess, "UNLOCK"); -} // end class brisco + return (sem_release($res)); + } +} // end class Room function make_seed() { @@ -1039,44 +1170,6 @@ function log_legal($timecur, $sess, $name, $where, $mesg) -function init_data() -{ - $brisco =& new brisco(); - - return $brisco; -} - -function lock_data() -{ - GLOBAL $sess; - - // echo "LOCK: ".FTOK_PATH."/main"; - // exit; - if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) { - echo "FTOK FAILED"; - exit; - } - // echo "FTOK ".$tok."
"; - if (($res = sem_get($tok)) == FALSE) { - echo "SEM_GET FAILED"; - exit; - } - if (sem_acquire($res)) { - log_only($sess, "LOCK"); - return ($res); - } - else - return (FALSE); -} - -function unlock_data($res) -{ - GLOBAL $sess; - - log_only($sess, "UNLOCK"); - return (sem_release($res)); -} - function lock_banlist() { @@ -1099,78 +1192,6 @@ function unlock_banlist($res) return (sem_release($res)); } - -function &load_data() -{ - GLOBAL $G_false, $sess; - - if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) { - echo "FTOK FAILED"; - exit; - } - - if ($shm = shm_attach($tok, SHM_DIMS)) { - $bri = @shm_get_var($shm, $tok); - - log_only($sess, "bri == ".($bri == FALSE ? "FALSE" : "TRUE")." bri === ".($bri === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($bri) ? "TRUE" : "FALSE")); - if (isset($bri)) - log_only($sess, "bri count ".count($bri)); - - if ($bri == FALSE) { - log_only($sess, "INIT MAIN DATA"); - - $bri = init_data(); - if (shm_put_var($shm, $tok, $bri) == FALSE) { - log_only($sess, "PUT_VAR FALLITA ".strlen(serialize($bri))); - log_only($sess, serialize($bri)); - } - } - - shm_detach($shm); - - $ret = &$bri; - return ($ret); - } - - return ($G_false); -} - - -function save_data(&$bri) -{ - GLOBAL $sess; - - $ret = FALSE; - $shm = FALSE; - $isacq = FALSE; - - // var_dump($bri); - - if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) - return (FALSE); - - do { - $isacq = TRUE; - - if (($shm = shm_attach($tok, SHM_DIMS)) == FALSE) - break; - - // log_only($sess, "PUT_VAR DI ".strlen(serialize($bri))); - if (shm_put_var($shm, $tok, $bri) == FALSE) { - log_only($sess, "PUT_VAR FALLITA ".strlen(serialize($bri))); - log_only($sess, serialize($bri)); - break; - } - // log_main("XXX", "QUI CI ARRIVA [".$bri->user[0]->name."]"); - $ret = TRUE; - } while (0); - - if ($shm) - shm_detach($shm); - - return ($ret); -} - function table_act_content($isstanding, $sitted, $table, $cur_table) { $ret = ""; @@ -1189,7 +1210,7 @@ function table_act_content($isstanding, $sitted, $table, $cur_table) return ($ret); } -function table_content($bri, $user, $table_idx) +function table_content($room, $user, $table_idx) { $content = ""; $ret = ""; @@ -1199,13 +1220,13 @@ function table_content($bri, $user, $table_idx) // $sess = $user->sess; - $table = &$bri->table[$table_idx]; + $table = &$room->table[$table_idx]; if ($user->stat != 'room') return; for ($i = 0 ; $i < $table->player_n ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; if ($user_cur == $user) { $hilion = ""; $hilioff = ""; } @@ -1226,7 +1247,7 @@ function table_content($bri, $user, $table_idx) return ($ret); } -function standup_content(&$bri, $user) +function standup_content(&$room, $user) { $ret = ""; $content = ""; @@ -1235,7 +1256,7 @@ function standup_content(&$bri, $user) return; for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) { - if ($bri->user[$e]->sess == "" || $bri->user[$e]->stat != "room" || $bri->user[$e]->name == "") + if ($room->user[$e]->sess == "" || $room->user[$e]->stat != "room" || $room->user[$e]->name == "") continue; $ct++; } @@ -1243,20 +1264,20 @@ function standup_content(&$bri, $user) $content .= sprintf('', $ct); for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) { - if ($bri->user[$e]->sess == "" || $bri->user[$e]->stat != "room" || $bri->user[$e]->name == "") + if ($room->user[$e]->sess == "" || $room->user[$e]->stat != "room" || $room->user[$e]->name == "") continue; - if ($bri->user[$e]->subst == "standup") { + if ($room->user[$e]->subst == "standup") { if (($ct % 4) == 0) { $content .= ''; } - if ($bri->user[$e] == $user) + if ($room->user[$e] == $user) { $hilion = ""; $hilioff = ""; } else { $hilion = ""; $hilioff = ""; } - $content .= sprintf('',$hilion, xcape($bri->user[$e]->name), $hilioff); + $content .= sprintf('',$hilion, xcape($room->user[$e]->name), $hilioff); if (($ct % 4) == 3) { $content .= ''; } @@ -1279,7 +1300,7 @@ function show_notify($text, $tout, $butt, $w, $h) return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h); } -function briscola_show($bri, $table, $user) +function briscola_show($room, $table, $user) { $ptnadd = ""; $ret = ""; @@ -1292,7 +1313,7 @@ function briscola_show($bri, $table, $user) $ret .= sprintf('$("callerinfo").innerHTML = "Chiami%s:";', $ptnadd); else $ret .= sprintf('$("callerinfo").innerHTML = "Chiama %s%s:";', - xcape($bri->user[$table->player[$table->asta_win]]->name), $ptnadd); + xcape($room->user[$table->player[$table->asta_win]]->name), $ptnadd); $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';', $table->asta_win); @@ -1335,17 +1356,17 @@ function multoval($mult) return (sprintf("%d-plo", $mult)); } -function show_table_info(&$bri, &$table, $table_pos) +function show_table_info(&$room, &$table, $table_pos) { $ret = ""; - $user = &$bri->user[$table->player[$table_pos]]; + $user = &$room->user[$table->player[$table_pos]]; $pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS; $noty = sprintf('
%s%s%s%s%s%s
'); // Names. for ($i = 0 ; $i < PLAYERS_N ; $i++) - $noty .= sprintf('', xcape($bri->user[$table->player[$i]]->name)); + $noty .= sprintf('', xcape($room->user[$table->player[$i]]->name)); $noty .= sprintf(""); // Points. @@ -1376,8 +1397,8 @@ function show_table_info(&$bri, &$table, $table_pos) if ($win != $fri) { $noty .= sprintf("
Nell'ultima mano ha chiamato %s, il socio era %s,
", - xcape($bri->user[$win]->name), - xcape($bri->user[$fri]->name)); + xcape($room->user[$win]->name), + xcape($room->user[$fri]->name)); if ($table->old_pnt == 120) { $noty .= sprintf("hanno fatto cappotto EBBRAVI!.
"); } @@ -1390,7 +1411,7 @@ function show_table_info(&$bri, &$table, $table_pos) } else { $noty .= sprintf("
Nell'ultima mano %s si è chiamato in mano,
", - xcape($bri->user[$win]->name)); + xcape($room->user[$win]->name)); if ($table->old_pnt == 120) { $noty .= sprintf("ha fatto cappotto EBBRAVO!.
"); } @@ -1405,7 +1426,7 @@ function show_table_info(&$bri, &$table, $table_pos) if ($table->mazzo == $table_pos) $noty .= "Fai tu il mazzo,"; else { - $unam = xcape($bri->user[$table->player[$table->mazzo]]->name); + $unam = xcape($room->user[$table->player[$table->mazzo]]->name); $noty .= "Il mazzo a $unam,"; } @@ -1424,7 +1445,7 @@ function show_table_info(&$bri, &$table, $table_pos) $noty .= " tocca a te giocare."; } else { - $unam = xcape($bri->user[$table->player[$curplayer]]->name); + $unam = xcape($room->user[$table->player[$curplayer]]->name); $noty .= " tocca a $unam giocare."; } @@ -1460,7 +1481,7 @@ function table_wellcome($user) return ($ret); } -function show_room(&$bri, &$user) +function show_room(&$room, &$user) { $ret = sprintf('gst.st = %d;', $user->step); $ret .= sprintf('stat = "%s";', $user->stat); @@ -1469,12 +1490,12 @@ function show_room(&$bri, &$user) $ret .= sprintf('subst = "%s";', $user->subst); $ret .= sprintf('$("myname").innerHTML = "%s";', xcape($user->name,ENT_COMPAT,"UTF-8")); for ($i = 0 ; $i < TABLES_N ; $i++) { - $ret .= table_content($bri, $user, $i); + $ret .= table_content($room, $user, $i); $act_content = table_act_content(($user->subst == 'standup'), - $bri->table[$i]->player_n, $i, $user->table); + $room->table[$i]->player_n, $i, $user->table); $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $i, $act_content); } - $ret .= standup_content($bri, $user); + $ret .= standup_content($room, $user); return ($ret); } @@ -1491,14 +1512,14 @@ Examples of $is_transition, $is_again: from table: asta cmd e tutti passano: TRUE, TRUE from table: fine partita: TRUE, TRUE */ -function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) +function show_table(&$room, &$user, $sendstep, $is_transition, $is_again) { $table_idx = $user->table; - $table = &$bri->table[$table_idx]; + $table = &$room->table[$table_idx]; $table_pos = $user->table_pos; $ret = "table_init();"; - $ret .= $table->exitlock_show(&$bri->user, $table_pos); + $ret .= $table->exitlock_show(&$room->user, $table_pos); if (!$is_again) { /* GENERAL STATUS */ $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;', @@ -1509,15 +1530,15 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) /* USERS INFO */ $ret .= sprintf('$("myname").innerHTML = "%s";', xcape($user->name,ENT_COMPAT,"UTF-8")); $ret .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ', - xcape($bri->user[$table->player[($table_pos)%PLAYERS_N]]->name), - xcape($bri->user[$table->player[($table_pos+1)%PLAYERS_N]]->name), - xcape($bri->user[$table->player[($table_pos+2)%PLAYERS_N]]->name), - (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($table_pos+3)%PLAYERS_N]]->name)), - (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($table_pos+4)%PLAYERS_N]]->name))); + xcape($room->user[$table->player[($table_pos)%PLAYERS_N]]->name), + xcape($room->user[$table->player[($table_pos+1)%PLAYERS_N]]->name), + xcape($room->user[$table->player[($table_pos+2)%PLAYERS_N]]->name), + (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+3)%PLAYERS_N]]->name)), + (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+4)%PLAYERS_N]]->name))); } /* NOTIFY FOR THE CARD MAKER */ if ($is_transition) { // && $user->subst == "asta" superfluo - $ret .= show_table_info(&$bri, &$table, $table_pos); + $ret .= show_table_info(&$room, &$table, $table_pos); } if (!$is_again) $ret .= table_wellcome($user); @@ -1605,7 +1626,7 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) /* show users auction status */ $showst = ""; for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "), ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt)); } @@ -1651,7 +1672,7 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) $ret .= "remark_off();"; /* WHO CALL AND WATH */ - $ret .= briscola_show($bri, $table, $user); + $ret .= briscola_show($room, $table, $user); } return ($ret); diff --git a/web/index.php b/web/index.php index e561d68..c8fd5f3 100644 --- a/web/index.php +++ b/web/index.php @@ -40,16 +40,16 @@ function main() if (isset($BRISK_SHOWHTML) == FALSE) { $is_table = FALSE; - $sem = lock_data(); - $bri = &load_data(); + $sem = Room::lock_data(); + $room = &Room::load_data(); /* Actions */ if (validate_sess($sess)) { - $bri->garbage_manager(TRUE); - if (($user = &$bri->get_user($sess, &$idx)) != FALSE) { + $room->garbage_manager(TRUE); + if (($user = &$room->get_user($sess, &$idx)) != FALSE) { if ($user->stat == "table") { header ("Location: table.php"); - unlock_data($sem); + Room::unlock_data($sem); exit; } $ACTION = "room"; @@ -57,15 +57,15 @@ function main() } if ($ACTION == "login" && isset($name)) { - $bri->garbage_manager(TRUE); + $room->garbage_manager(TRUE); /* try login */ - if (($user = &$bri->add_user(&$sess, &$idx, $name, $_SERVER['REMOTE_ADDR'])) != FALSE) { + if (($user = &$room->add_user(&$sess, &$idx, $name, $_SERVER['REMOTE_ADDR'])) != FALSE) { $ACTION = "room"; // setcookie ("sess", "", time() + 180); - $bri->standup_update(&$user); + $room->standup_update(&$user); - if (save_data(&$bri) == FALSE) { + if (Room::save_data(&$room) == FALSE) { echo "ERRORE SALVATAGGIO\n"; exit; } @@ -80,7 +80,7 @@ function main() $body .= '
Il tuo nickname è già in uso.
'; } } - unlock_data($sem); + Room::unlock_data($sem); } /* Rendering. */ diff --git a/web/index_rd.php b/web/index_rd.php index b88ce99..e164229 100644 --- a/web/index_rd.php +++ b/web/index_rd.php @@ -67,32 +67,32 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su GLOBAL $is_page_streaming, $first_loop; $ret = FALSE; - $bri = FALSE; + $room = FALSE; log_rd2($sess, "M"); /* Sync check (read only without modifications */ ignore_user_abort(TRUE); - if (($sem = lock_data()) != FALSE) { + if (($sem = Room::lock_data()) != FALSE) { // Aggiorna l'expire time lato server if ($first_loop == TRUE) { log_only($sess, "F"); - $bri = &load_data(); - if (($user = &$bri->get_user($sess, $idx)) == FALSE) { - unlock_data($sem); + $room = &Room::load_data(); + if (($user = &$room->get_user($sess, $idx)) == FALSE) { + Room::unlock_data($sem); ignore_user_abort(FALSE); return (unrecerror()); } log_auth($sess, "update lacc"); $user->lacc = time(); - $bri->garbage_manager(FALSE); + $room->garbage_manager(FALSE); - save_data($bri); + Room::save_data($room); $first_loop = FALSE; } log_only($sess, "U"); - unlock_data($sem); + Room::unlock_data($sem); ignore_user_abort(FALSE); } else { @@ -114,12 +114,12 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su log_only2($sess, "R"); } - if ($bri == FALSE) { + if ($room == FALSE) { ignore_user_abort(TRUE); - if (($sem = lock_data()) != FALSE) { + if (($sem = Room::lock_data()) != FALSE) { log_only($sess, "P"); - $bri = &load_data(); - unlock_data($sem); + $room = &Room::load_data(); + Room::unlock_data($sem); ignore_user_abort(FALSE); } else { @@ -127,7 +127,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su } } - if (($user = &$bri->get_user($sess, $idx)) == FALSE) { + if (($user = &$room->get_user($sess, $idx)) == FALSE) { return (unrecerror()); } @@ -140,10 +140,10 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su if ($cur_step == -1) { // FUNZIONE from_scratch DA QUI ignore_user_abort(TRUE); - $sem = lock_data(); - $bri = &load_data(); - if (($user = &$bri->get_user($sess, $idx)) == FALSE) { - unlock_data($sem); + $sem = Room::lock_data(); + $room = &Room::load_data(); + if (($user = &$room->get_user($sess, $idx)) == FALSE) { + Room::unlock_data($sem); ignore_user_abort(FALSE); return (unrecerror()); } @@ -157,13 +157,13 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su $user->trans_step = -1; - save_data($bri); - unlock_data($sem); + Room::save_data($room); + Room::unlock_data($sem); ignore_user_abort(FALSE); } else { log_rd2($sess, "TRANS NON ATTIVATO"); - unlock_data($sem); + Room::unlock_data($sem); ignore_user_abort(FALSE); } } @@ -173,7 +173,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su if ($user->stat == 'room') { log_rd($sess, "roomma"); - $ret .= show_room(&$bri, &$user); + $ret .= show_room(&$room, &$user); } /*************** * * @@ -181,7 +181,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su * * ***************/ else if ($user->stat == 'table') { - $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE); + $ret = show_table(&$room,&$user,$user->step,FALSE,FALSE); log_rd2($sess, "SENDED TO THE STREAM: ".$ret); } @@ -193,10 +193,10 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su } else { ignore_user_abort(TRUE); - $sem = lock_data(); - $bri = &load_data(); - if (($user = &$bri->get_user($sess, $idx)) == FALSE) { - unlock_data($sem); + $sem = Room::lock_data(); + $room = &Room::load_data(); + if (($user = &$room->get_user($sess, $idx)) == FALSE) { + Room::unlock_data($sem); ignore_user_abort(FALSE); return (unrecerror()); } @@ -205,7 +205,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su if ($cur_step + COMM_N < $user->step) { if (($cur_stat != $user->stat)) { $to_stat = $user->stat; - unlock_data($sem); + Room::unlock_data($sem); ignore_user_abort(FALSE); return (page_sync($user->sess, $to_stat == "table" ? "table.php" : "index.php")); } @@ -233,17 +233,17 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su $user->the_end = FALSE; if ($user->subst == 'sitdown') - $bri->room_wakeup(&$user); + $room->room_wakeup(&$user); else if ($user->subst == 'standup') - $bri->room_outstandup(&$user); + $room->room_outstandup(&$user); else log_rd2($sess, "LOGOUT FROM WHAT ???"); - save_data($bri); + Room::save_data($room); } } - unlock_data($sem); + Room::unlock_data($sem); ignore_user_abort(FALSE); } diff --git a/web/index_wr.php b/web/index_wr.php index 6c33baf..28d93de 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -34,12 +34,12 @@ log_load($sess, "LOAD: index_wr.php"); */ log_wr($sess, 'COMM: '.$mesg); -$sem = lock_data(); -$bri = &load_data(); -if (($user = &$bri->get_user($sess, &$idx)) == FALSE) { +$sem = Room::lock_data(); +$room = &Room::load_data(); +if (($user = &$room->get_user($sess, &$idx)) == FALSE) { echo "Get User Error"; log_wr($sess, "Get User Error"); - unlock_data($sem); + Room::unlock_data($sem); exit; } $argz = explode('|', $mesg); @@ -54,9 +54,9 @@ if ($argz[0] == 'shutdown') { log_rd2($user->sess, "AUTO LOGOUT."); if ($user->subst == 'sitdown' || $user->stat == 'table') - $bri->room_wakeup(&$user); + $room->room_wakeup(&$user); else if ($user->subst == 'standup') - $bri->room_outstandup(&$user); + $room->room_outstandup(&$user); else log_rd2($sess, "SHUTDOWN FROM WHAT ???"); } @@ -85,7 +85,7 @@ else if ($user->stat == 'room') { } else if ($argz[0] == 'chatt') { - $bri->chatt_send(&$user,$mesg); + $room->chatt_send(&$user,$mesg); } /********************** * * @@ -97,7 +97,7 @@ else if ($user->stat == 'room') { if ($argz[0] == 'sitdown') { if ($user->the_end == TRUE) { log_wr($sess, "INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request."); - unlock_data($sem); + Room::unlock_data($sem); exit; } /* TODO: refact to a function */ @@ -106,18 +106,18 @@ else if ($user->stat == 'room') { $user->comm[$user->step % COMM_N] .= show_notify("
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, "Torna in piedi.", 400, 100); $user->step_inc(); - save_data($bri); - unlock_data($sem); + Room::save_data($room); + Room::unlock_data($sem); exit; } // Take parameters $table_idx = $argz[1]; - $table = &$bri->table[$table_idx]; + $table = &$room->table[$table_idx]; if ($table->player_n == PLAYERS_N) { log_wr($sess, "WARN:FSM: Sitdown unreachable, table full."); - unlock_data($sem); + Room::unlock_data($sem); exit; } @@ -130,33 +130,44 @@ else if ($user->stat == 'room') { // Start game for this table. log_wr($sess, "Start game!"); - $table->init(&$bri->user); - $table->game_init(&$bri->user); - $curtime = time(); - - for ($i = 0 ; $i < $table->player_n ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; - log_wr($sess, "Pre if!"); - - $ret = ""; - $ret .= sprintf('gst.st_loc++; gst.st=%d; the_end=true; window.onunload = null ; document.location.assign("table.php");|', $user_cur->step+1); - - $user_cur->comm[$user_cur->step % COMM_N] = $ret; - $user_cur->trans_step = $user_cur->step + 1; - log_wr($sess, "TRANS ATTIVATO"); - + // + // START THE SPAWN HERE!!!! + // - $user_cur->stat_set('table'); - $user_cur->subst = 'asta'; - $user_cur->laccwr = $curtime; - $user_cur->step_inc(); - - $user_cur->comm[$user_cur->step % COMM_N] = show_table(&$bri,&$user_cur,$user_cur->step+1,TRUE, FALSE); - $user_cur->step_inc(); + if (TRUE) { // WITH SPAWN } + else { // BEFORE SPAWN + // init table + $table->init(&$room->user); + $table->game_init(&$room->user); + $curtime = time(); + + // init users + for ($i = 0 ; $i < $table->player_n ; $i++) { + $user_cur = &$room->user[$table->player[$i]]; + log_wr($sess, "Pre if!"); + + $ret = ""; + $ret .= sprintf('gst.st_loc++; gst.st=%d; the_end=true; window.onunload = null ; document.location.assign("table.php");|', $user_cur->step+1); + + $user_cur->comm[$user_cur->step % COMM_N] = $ret; + $user_cur->trans_step = $user_cur->step + 1; + log_wr($sess, "TRANS ATTIVATO"); + + + $user_cur->stat_set('table'); + $user_cur->subst = 'asta'; + $user_cur->laccwr = $curtime; + $user_cur->step_inc(); + + $user_cur->comm[$user_cur->step % COMM_N] = show_table(&$room,&$user_cur,$user_cur->step+1,TRUE, FALSE); + $user_cur->step_inc(); + } + } // end else { BEFORE SPAWN + + // change room + $room->room_sitdown(&$user, $table_idx); } - - $bri->room_sitdown(&$user, $table_idx); } else if ($argz[0] == 'logout') { $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; @@ -172,10 +183,10 @@ else if ($user->stat == 'room') { **********************/ else if ($user->subst == 'sitdown') { if ($argz[0] == 'wakeup') { - $bri->room_wakeup(&$user); + $room->room_wakeup(&$user); } else if ($argz[0] == 'logout') { - $bri->room_wakeup(&$user); + $room->room_wakeup(&$user); $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; $user->comm[$user->step % COMM_N] .= sprintf('postact_logout();'); $user->the_end = TRUE; @@ -190,17 +201,17 @@ else if ($user->stat == 'room') { *********************/ else if ($user->stat == 'table') { $user->laccwr = time(); - $table = &$bri->table[$user->table]; + $table = &$room->table[$user->table]; if ($argz[0] == 'tableinfo') { log_wr($sess, "PER DI TABLEINFO"); $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; - $user->comm[$user->step % COMM_N] .= show_table_info(&$bri, &$table, $user->table_pos); + $user->comm[$user->step % COMM_N] .= show_table_info(&$room, &$table, $user->table_pos); log_wr($sess, $user->comm[$user->step % COMM_N]); $user->step_inc(); } else if ($argz[0] == 'chatt') { - $bri->chatt_send(&$user,$mesg); + $room->chatt_send(&$user,$mesg); } else if ($argz[0] == 'logout') { $remcalc = $argz[1]; @@ -212,10 +223,10 @@ else if ($user->stat == 'table') { $logout_cont = TRUE; if ($remcalc >= 3) { - $lockcalc = $table->exitlock_calc(&$bri->user, $user->table_pos); + $lockcalc = $table->exitlock_calc(&$room->user, $user->table_pos); if ($lockcalc < 3) { $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; - $user->comm[$user->step % COMM_N] .= $table->exitlock_show(&$bri->user, $user->table_pos); + $user->comm[$user->step % COMM_N] .= $table->exitlock_show(&$room->user, $user->table_pos); $user->comm[$user->step % COMM_N] .= show_notify("
I dati presenti sul server non erano allineati con quelli inviati dal tuo browser, adesso lo sono. Riprova ora.", 2000, "Torna alla partita.", 400, 100); log_wr($sess, $user->comm[$user->step % COMM_N]); @@ -227,13 +238,13 @@ else if ($user->stat == 'table') { $user->bantime = $user->laccwr + BAN_TIME; if ($logout_cont == TRUE) { - $bri->room_wakeup(&$user); + $room->room_wakeup(&$user); } } else if ($argz[0] == 'exitlock') { $user->exitislock = ($user->exitislock == TRUE ? FALSE : TRUE); for ($ct = 0, $i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur[$i] = &$bri->user[$table->player[$i]]; + $user_cur[$i] = &$room->user[$table->player[$i]]; if ($user_cur[$i]->exitislock == FALSE) $ct++; } @@ -256,13 +267,13 @@ else if ($user->stat == 'table') { $table->old_reason = sprintf("Ha lasciato %s perche` aveva al massimo 2 punti.", $user->name); $table->game_next(); - $table->game_init(&$bri->user); + $table->game_init(&$room->user); for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; $ret = sprintf('gst.st = %d;', $user_cur->step+1); - $ret .= show_table(&$bri,&$user_cur,$user_cur->step+1, TRUE, TRUE); + $ret .= show_table(&$room,&$user_cur,$user_cur->step+1, TRUE, TRUE); $user_cur->comm[$user_cur->step % COMM_N] = $ret; $user_cur->step_inc(); } @@ -318,7 +329,7 @@ else if ($user->stat == 'table') { /* next step */ $showst = "show_astat("; for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "), ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt)); } @@ -328,7 +339,7 @@ else if ($user->stat == 'table') { $maxcard = -2; for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; if ($maxcard < $user_cur->asta_card) $maxcard = $user_cur->asta_card; } @@ -347,7 +358,7 @@ else if ($user->stat == 'table') { for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; $ret = sprintf('gst.st = %d; %s', $user_cur->step+1, $showst); if ($user_cur->table_pos == ($table->gstart % PLAYERS_N)) $ret .= sprintf('dispose_asta(%d,%d, %s); remark_on();', @@ -368,13 +379,13 @@ else if ($user->stat == 'table') { $table->mult *= 2; $table->game_next(); - $table->game_init(&$bri->user); + $table->game_init(&$room->user); for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; $ret = sprintf('gst.st = %d;', $user_cur->step+1); - $ret .= show_table(&$bri,&$user_cur,$user_cur->step+1, TRUE, TRUE); + $ret .= show_table(&$room,&$user_cur,$user_cur->step+1, TRUE, TRUE); $user_cur->comm[$user_cur->step % COMM_N] = $ret; $user_cur->step_inc(); } @@ -402,7 +413,7 @@ else if ($user->stat == 'table') { $table->asta_win = $chooser; for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; $ret = sprintf('gst.st = %d; %s', $user_cur->step+1, $showst); if ($i == $chooser) { @@ -435,15 +446,15 @@ else if ($user->stat == 'table') { log_wr($sess, "Setta la briscola a ".$a_brisco); $chooser = $table->asta_win; - $user_chooser = &$bri->user[$table->player[$chooser]]; + $user_chooser = &$room->user[$table->player[$chooser]]; for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; $user_cur->subst = 'game'; $ret = sprintf('gst.st = %d; subst = "game";', $user_cur->step+1); /* bg of caller cell */ - $ret .= briscola_show($bri, $table, $user_cur); + $ret .= briscola_show($room, $table, $user_cur); /* first gamer */ if ($i == ($table->gstart % PLAYERS_N)) @@ -513,7 +524,7 @@ else if ($user->stat == 'table') { $table->gstart = $winner; $turn_nex = ($table->gstart + $table->turn) % PLAYERS_N; - log_wr($sess, sprintf("The winner is: [%d] [%s]", $winner, $bri->user[$table->player[$winner]]->name)); + log_wr($sess, sprintf("The winner is: [%d] [%s]", $winner, $room->user[$table->player[$winner]]->name)); $card_take = sprintf("sleep(gst,2000);|cards_take(%d);|cards_hidetake($d);", $winner, $winner); $player_cur = "remark_off();" . $card_take . "|"; @@ -528,7 +539,7 @@ else if ($user->stat == 'table') { log_wr($sess, sprintf("Turn Cur %d Turn Nex %d",$turn_cur, $turn_nex)); for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; $ret = sprintf('gst.st = %d; ', $user_cur->step+1); @@ -558,17 +569,17 @@ else if ($user->stat == 'table') { calculate_points(&$table); $table->game_next(); - $table->game_init(&$bri->user); + $table->game_init(&$room->user); for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; - $retar[$i] .= show_table(&$bri,&$user_cur,$user_cur->step+1,TRUE, TRUE); + $user_cur = &$room->user[$table->player[$i]]; + $retar[$i] .= show_table(&$room,&$user_cur,$user_cur->step+1,TRUE, TRUE); } } for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $user_cur = &$bri->user[$table->player[$i]]; + $user_cur = &$room->user[$table->player[$i]]; $user_cur->comm[$user_cur->step % COMM_N] = $retar[$i]; $user_cur->step_inc(); @@ -586,8 +597,8 @@ else if ($user->stat == 'table') { } } log_wr($sess, "before save data"); -save_data($bri); +Room::save_data($room); -unlock_data($sem); +Room::unlock_data($sem); exit; ?> -- 2.17.1
%s%s