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
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()
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--;
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) {
}
-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;
}
}
/*
- * 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
}
}
+ // 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."<br>";
+ 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()
{
-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."<br>";
- 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()
{
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 = "";
return ($ret);
}
-function table_content($bri, $user, $table_idx)
+function table_content($room, $user, $table_idx)
{
$content = "";
$ret = "";
//
$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 = "<b>"; $hilioff = "</b>"; }
return ($ret);
}
-function standup_content(&$bri, $user)
+function standup_content(&$room, $user)
{
$ret = "";
$content = "";
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++;
}
$content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $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 .= '<tr>';
}
- if ($bri->user[$e] == $user)
+ if ($room->user[$e] == $user)
{ $hilion = "<b>"; $hilioff = "</b>"; }
else
{ $hilion = ""; $hilioff = ""; }
- $content .= sprintf('<td class=\\"room_standup\\">%s%s%s</td>',$hilion, xcape($bri->user[$e]->name), $hilioff);
+ $content .= sprintf('<td class=\\"room_standup\\">%s%s%s</td>',$hilion, xcape($room->user[$e]->name), $hilioff);
if (($ct % 4) == 3) {
$content .= '</tr>';
}
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 = "";
$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);
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('<table class=\"points\"><tr><th></th>');
// Names.
for ($i = 0 ; $i < PLAYERS_N ; $i++)
- $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($bri->user[$table->player[$i]]->name));
+ $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($room->user[$table->player[$i]]->name));
$noty .= sprintf("</tr>");
// Points.
if ($win != $fri) {
$noty .= sprintf("<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>",
- 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 <b>cappotto</b> EBBRAVI!.<hr>");
}
}
else {
$noty .= sprintf("<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>",
- xcape($bri->user[$win]->name));
+ xcape($room->user[$win]->name));
if ($table->old_pnt == 120) {
$noty .= sprintf("ha fatto <b>cappotto</b> EBBRAVO!.<hr>");
}
if ($table->mazzo == $table_pos)
$noty .= "Fai <b>tu</b> 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 <b>$unam</b>,";
}
$noty .= " tocca a <b>te</b> giocare.";
}
else {
- $unam = xcape($bri->user[$table->player[$curplayer]]->name);
+ $unam = xcape($room->user[$table->player[$curplayer]]->name);
$noty .= " tocca a <b>$unam</b> giocare.";
}
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);
$ret .= sprintf('subst = "%s";', $user->subst);
$ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', 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);
}
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;',
/* USERS INFO */
$ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', 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);
/* 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));
}
$ret .= "remark_off();";
/* WHO CALL AND WATH */
- $ret .= briscola_show($bri, $table, $user);
+ $ret .= briscola_show($room, $table, $user);
}
return ($ret);
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";
}
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;
}
$body .= '<div class="urgmsg"><b>Il tuo nickname è già in uso.</b></div>';
}
}
- unlock_data($sem);
+ Room::unlock_data($sem);
}
/* Rendering. */
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 {
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 {
}
}
- if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
+ if (($user = &$room->get_user($sess, $idx)) == FALSE) {
return (unrecerror());
}
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());
}
$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);
}
}
if ($user->stat == 'room') {
log_rd($sess, "roomma");
- $ret .= show_room(&$bri, &$user);
+ $ret .= show_room(&$room, &$user);
}
/***************
* *
* *
***************/
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);
}
}
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());
}
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"));
}
$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);
}
*/
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);
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 ???");
}
}
else if ($argz[0] == 'chatt') {
- $bri->chatt_send(&$user,$mesg);
+ $room->chatt_send(&$user,$mesg);
}
/**********************
* *
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 */
$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, "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;
}
// 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)."; ";
**********************/
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;
*********************/
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];
$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("<br>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]);
$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++;
}
$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();
}
/* 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));
}
$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;
}
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();',
$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();
}
$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) {
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))
$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 . "|";
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);
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();
}
}
log_wr($sess, "before save data");
-save_data($bri);
+Room::save_data($room);
-unlock_data($sem);
+Room::unlock_data($sem);
exit;
?>