From f0c4c4d0bed38d1211249c0032da8e546c5d5df9 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Sat, 19 Jan 2008 15:05:29 +0000 Subject: [PATCH] spawned game added --- web/briskin5/Obj/briskin5.phh | 218 ++++++++++++ web/briskin5/briskin5.css | 444 ++++++++++++++++++++++++ web/briskin5/briskin5.js | 26 ++ web/briskin5/briskin5.php | 237 +++++++++++++ web/briskin5/index_rd.php | 310 +++++++++++++++++ web/briskin5/index_wr.php | 635 ++++++++++++++++++++++++++++++++++ 6 files changed, 1870 insertions(+) create mode 100644 web/briskin5/Obj/briskin5.phh create mode 100644 web/briskin5/briskin5.css create mode 100644 web/briskin5/briskin5.js create mode 100644 web/briskin5/briskin5.php create mode 100644 web/briskin5/index_rd.php create mode 100644 web/briskin5/index_wr.php diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh new file mode 100644 index 0000000..927f703 --- /dev/null +++ b/web/briskin5/Obj/briskin5.phh @@ -0,0 +1,218 @@ +user = array(); + $this->table = array(); + + $user =& $room->user; + $table =& $room->table[$table_idx]; + + log_wr("xxx", "Briskin5 constructor"); + + for ($i = 0 ; $i < $table->player_n ; $i++) + $this->user[$i] =& User::spawn(&$user[$table->player[$i]], 0, $i); + + $this->table[0] =& Table::spawn(&$table); + $this->table_idx = $table_idx; + $this->garbage_timeout = 0; + + log_wr("xxx", "Briskin5 constructor end"); + } + + + function &get_user($sess, &$idx) + { + GLOBAL $PHP_SELF, $G_false; + + if (validate_sess($sess)) { + for ($i = 0 ; $i < MAX_BRISKIN5_PLAYERS ; $i++) { + if (strcmp($sess, $this->user[$i]->sess) == 0) { + // find it + $idx = $i; + $ret = &$this->user[$i]; + return ($ret); + } + } + log_main($sess, sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF)); + // for ($i = 0 ; $i < MAX_PLAYERS ; $i++) + // log_main($sess, sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess)); + } + else { + log_main($sess, sprintf("get_user: Wrong strlen [%s]",$sess)); + } + + return ($G_false); + } + + + function garbage_manager($force) + { + + /* Garbage collector degli utenti in timeout */ + $curtime = time(); + if ($force || $this->garbage_timeout < $curtime) { + + for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { + $user_cur = &$this->user[$i]; + if ($user_cur->sess == "") + continue; + + if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente + log_rd2($user_cur->sess, "AUTO LOGOUT."); + + if ($user_cur->stat == 'table' || $user_cur->stat == 'room') { + log_auth($user_cur->sess, "Autologout session."); + + $tmp_sess = $user_cur->sess; + $user_cur->sess = ""; + step_unproxy($tmp_sess); + $user_cur->name = ""; + $user_cur->the_end = FALSE; + + log_rd2($user_cur->sess, "AUTO LOGOUT."); + if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table') + $this->room_wakeup(&$user_cur); + else if ($user_cur->subst == 'standup') + $this->room_outstandup(&$user_cur); + else + log_rd2($sess, "LOGOUT FROM WHAT ???"); + } + } + + if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi + if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') { + $this->room_wakeup(&$user_cur); + $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; "; + $user_cur->comm[$user_cur->step % COMM_N] .= show_notify("
Sei stato inattivo per ".(EXPIRE_TIME_SMAMMA/60.0)." minuti.

Quindi ritorni tra i Giocatori in piedi.", 0, "torna ai tavoli", 400, 100); + $user_cur->step_inc(); + } + } + } + log_rd2($user_cur->sess, "GARBAGE UPDATED!"); + + $this->garbage_timeout = time() + GARBAGE_TIMEOUT; + } + + // BAN_IP_CLEAN + + } + + + + + // + // static functions + // + function &load_data($table_idx) + { + GLOBAL $G_false, $sess; + $shm = FALSE; + + log_wr($sess, "TABLE_IDX ".FTOK_PATH."/table".$table_idx); + if (($tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { + echo "FTOK FAILED"; + exit; + } + + do { + if (($shm = shm_attach($tok, SHM_DIMS)) == FALSE) + break; + + if (($bri = @shm_get_var($shm, $tok)) == FALSE) + break; + + shm_detach($shm); + + $ret = &$bri; + return ($ret); + } while (FALSE); + + if ($shm != FALSE) + shm_detach($shm); + + return ($G_false); + } + + + function save_data(&$bri) + { + GLOBAL $sess; + + $ret = FALSE; + $shm = FALSE; + $isacq = FALSE; + + // var_dump($bri); + + if (($tok = ftok(FTOK_PATH."/table".$bri->table_idx, "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 lock_data($table_idx) + { + GLOBAL $sess; + + log_wr($sess, "LOCK_DATA ".FTOK_PATH."/table".$table_idx); + // echo "LOCK: ".FTOK_PATH."/main"; + // exit; + if (($tok = ftok(FTOK_PATH."/table".$table_idx, "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)); + } + + + +} + +?> \ No newline at end of file diff --git a/web/briskin5/briskin5.css b/web/briskin5/briskin5.css new file mode 100644 index 0000000..46f2cf1 --- /dev/null +++ b/web/briskin5/briskin5.css @@ -0,0 +1,444 @@ +/* + * brisk - table.css + * + * Copyright (C) 2006 matteo.nastasi@milug.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. You should have received a + * copy of the GNU General Public License along with this program; if + * not, write to the Free Software Foundation, Inc, 59 Temple Place - + * Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * + */ + +.chattshort { + height: 70px; + overflow: auto; + border: 1px solid grey; + vertical-align: text-bottom; + /* font-size: 10pt;*/ +} + +.txtt { + /* font-size: 10pt;*/ +} + +img.tableinfo { + position: absolute; + left: 619; + top: 550; + border-width: 0px; + visibility: visible; +} + +img.tablereload { + position: absolute; + left: 667; + top: 550; + border-width: 0px; + visibility: visible; +} + +img.tableout { + position: absolute; + left: 730; + top: 550; + border-width: 0px; + visibility: visible; +} + +img.card { + position: absolute; + border-style: solid; + border-width: 1px; + border-color: grey; + visibility: hidden; +} + + +img.astacard { + position: absolute; + /* visibility: visible; */ + border-width: 0px; +} + +img.cover { + position: absolute; + border-style: solid; + border-width: 1px; + border-color: lightgrey; + visibility: hidden; +} + +.chooseed { + /* background-color: yellow; */ + visibility: hidden; + position:absolute; + width: 200px; + height: 200px; + top: 250px; + left: 300px; +} + +.asta { + /* background-color: yellow; */ + visibility: hidden; + position: absolute; + width: 200px; + height: 200px; + top: 250px; + left: 300px; +} + +img.seed0 { + position: absolute; + left: 0px; + top: 55px; +} + +img.seed1 { + position: absolute; + left: 43px; + top: 55px; +} + +img.seed2 { + position: absolute; + left: 93px; + top: 55px; +} + +img.seed3 { + position: absolute; + left: 143px; + top: 55px; +} + +.area { + display: block; + margin-left: auto; + margin-right: auto; + position: relative; + text-align: center; + width: 800px; + height: 600px; +} + +.subarea { + top: 0px; +} + +.points { + /* position: relative; */ + + margin-top: 8px; + margin-left:auto; + margin-right:auto; + border-style: solid; + border-width: 0px; + border-color: black; + border-collapse: collapse; +} + +.td_points { + border-style: solid; + border-width: 1px; + border-color: black; + border-collapse: collapse; + display: table-cell; + text-align: right; + padding: 2px; +} + +div.table_commands { + display: inline; + position: absolute; + right: 2px; + bottom: 15px; +} + +.remark0 { + position: absolute; + width: 199px; + height: 200px; + left: 299; + top: 249; + border-style: solid; + border-width: 0px; + border-color: green; + z-index: 0; +} + +.remark1 { + position: absolute; + width: 199px !important; + width: 207px; + height: 200px !important; + height: 208px; + left: 296; + top: 246; + border-style: solid; + border-width: 4px; + border-color: green; + z-index: 0; +} + +.remark2 { + position: absolute; + width: 199px !important; + width: 203px; + height: 200px !important; + height: 204px; + left: 298; + top: 248; + border-style: solid; + border-width: 2px; + border-color: green; + z-index: 0; +} + +.punti { + position: absolute; + width: 68; + height: 50; + margin-top: 4px; + /* + border-style: solid; + border-width: 1px; + border-color: blu; + */ + align: center; + text-align: center; +} + +.puntifield { + /* position: absolute; */ + align: center; + text-align: center; +} + +.pubinfo { + /* background-color: red; */ + color: grey; + visibility: visible; + position: absolute; + top: 475px; + left: 200px; + width: 400px; + height: 125px; +} + +.public { + /* background-color: red; */ + visibility: hidden; + position: absolute; + display: table; + top: 450px; + left: 300px; + width: 200px; + height: 100px; + overflow: hidden; + z-index: 8; +} + +.pubacard { + border-width: 0px; + position: relative; + display: block; + margin-left: auto; + margin-right: auto; +} + + + +.pubinfo_we { + color: grey; + visibility: visible; + position: absolute; + top: 250px; + left: 175px; + width: 125px; + height: 200px; +} + +.public_we { + /* background-color: red; */ + visibility: hidden; + position: absolute; + top: 250px; + left: 175px; + display: table; + width: 125px; + height: 200px; + overflow: hidden; +} + +.pubinfo_nw { + /* background-color: red; */ + color: grey; + visibility: visible; + position: absolute; + top: 125px; + left: 200px; + width: 200px; + height: 125px; +} + +.public_nw { + /* background-color: red; */ + visibility: hidden; + position: absolute; + top: 125px; + left: 200px; + display: table; + width: 200px; + height: 125px; + overflow: hidden; +} + +.public_ne { + /* background-color: red; */ + visibility: hidden; + position: absolute; + top: 125px; + left: 400px; + display: table; + width: 200px; + height: 125px; + overflow: hidden; +} + +.pubinfo_ne { + /* background-color: red; */ + color: grey; + visibility: visible; + position: absolute; + top: 125px; + left: 400px; + width: 200px; + height: 125px; +} + + + +.public_ea { + /* background-color: red; */ + visibility: hidden; + position: absolute; + top: 250px; + left: 500px; + display: table; + width: 125px; + height: 200px; + overflow: hidden; +} + +.pubinfo_ea { + /* background-color: red; */ + color: grey; + visibility: visible; + position: absolute; + top: 250px; + left: 500px; + width: 125px; + height: 200px; +} + +.vert_midfloat { + position: relative; +#position: absolute; + _top: 50%; + left: 0px; + width: 100%; + display: table-cell; + vertical-align: middle; +} + +.vert_innfloat { +#position: relative; +#top: -50%; + text-align: center; +} + +.vert_innfloat_so { + /* border-style: solid; + border-width: 1px; + border-color: black; + + background-color: white; */ +#position: relative; +#top: -50%; + text-align: center; +} + +.pubacard_ea { + border-width: 0px; + position: relative; + display: block; + margin-left: auto; + margin-right: auto; +} + +.pubacard_ne { + border-width: 0px; + position: relative; + display: block; + margin-left: auto; + margin-right: auto; +} + +.pubacard_nw { + border-width: 0px; + position: relative; + display: block; + margin-left: auto; + margin-right: auto; +} + +.pubacard_we { + border-width: 0px; + position: relative; + display: block; + margin-left: auto; + margin-right: auto; +} + + +/* CALLER */ +.caller { + background-repeat: no-repeat; + visibility: hidden; + position: absolute; + left: 0px; + top: 475px; + width: 200px; + height: 125px; +} + +.callerinfo { + /* background-color: red; */ + /* visibility: visible; */ + position: absolute; + /* font-size: 10pt;*/ + left: 5px; + top: 55px; + width: 115px; + height: 65px; +} + +img.callerimg { + position: absolute; + left: 133px; + top: 10px; +} + + diff --git a/web/briskin5/briskin5.js b/web/briskin5/briskin5.js new file mode 100644 index 0000000..9a4e7f2 --- /dev/null +++ b/web/briskin5/briskin5.js @@ -0,0 +1,26 @@ +/* + * brisk - table.js + * + * Copyright (C) 2006 matteo.nastasi@milug.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. You should have received a + * copy of the GNU General Public License along with this program; if + * not, write to the Free Software Foundation, Inc, 59 Temple Place - + * Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * + */ + +function background_set() +{ + $("bg").style.backgroundImage = 'url("img/brisk_table_sand'+table_pos+'.jpg")'; +} diff --git a/web/briskin5/briskin5.php b/web/briskin5/briskin5.php new file mode 100644 index 0000000..e5834c0 --- /dev/null +++ b/web/briskin5/briskin5.php @@ -0,0 +1,237 @@ + + + +Brisk - Tavolo + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ +
+ + + +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+Hai vinto l'asta.
Scegli il seme: + + + + +
+
+
Info
+ +
+
+ + +
+ +
+
+ +
+ + +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + diff --git a/web/briskin5/index_rd.php b/web/briskin5/index_rd.php new file mode 100644 index 0000000..2d75d51 --- /dev/null +++ b/web/briskin5/index_rd.php @@ -0,0 +1,310 @@ +get_user($sess, $idx)) == FALSE) { + Briskin5::unlock_data($sem); + ignore_user_abort(FALSE); + return (unrecerror()); + } + log_auth($sess, "update lacc"); + $user->lacc = time(); + + $bri->garbage_manager(FALSE); + + Briskin5::save_data($bri); + $first_loop = FALSE; + } + + log_only($sess, "U"); + Briskin5::unlock_data($sem); + ignore_user_abort(FALSE); + } + else { + return (FALSE); + } + + if (($proxy_step = step_get($sess)) != FALSE) { + // log_rd2($sess, "Postget".$proxy_step."zizi"); + + if ($cur_step == $proxy_step) { + log_only2($sess, "P"); + return (FALSE); + } + else { + log_only2($sess, "R"); + } + } + else { + log_only2($sess, "R"); + } + + if ($bri == FALSE) { + ignore_user_abort(TRUE); + if (($sem = Briskin5::lock_data($table_idx)) != FALSE) { + log_only($sess, "P"); + $bri = &Briskin5::load_data($table_idx); + Briskin5::unlock_data($sem); + ignore_user_abort(FALSE); + } + else { + return (FALSE); + } + } + + if (($user = &$bri->get_user($sess, $idx)) == FALSE) { + return (unrecerror()); + } + + /* Nothing changed, return. */ + if ($cur_step == $user->step) + return; + + log_rd2($sess, "do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step); + + if ($cur_step == -1) { + // FUNZIONE from_scratch DA QUI + ignore_user_abort(TRUE); + $sem = Briskin5::lock_data($table_idx); + $bri = &Briskin5::load_data($table_idx); + if (($user = &$bri->get_user($sess, $idx)) == FALSE) { + Briskin5::unlock_data($sem); + ignore_user_abort(FALSE); + return (unrecerror()); + } + if ($user->the_end) + $is_page_streaming = TRUE; + + + if ($user->trans_step != -1) { + log_rd2($sess, "TRANS USATO ".$user->trans_step); + $cur_step = $user->trans_step; + $user->trans_step = -1; + + + Briskin5::save_data($bri); + Briskin5::unlock_data($sem); + ignore_user_abort(FALSE); + } + else { + log_rd2($sess, "TRANS NON ATTIVATO"); + Briskin5::unlock_data($sem); + ignore_user_abort(FALSE); + } + } + + if ($cur_step == -1) { + log_rd2($sess, "PRE-NEWSTAT."); + + if ($user->stat == 'room') { + log_rd($sess, "roomma"); + $ret .= show_room(&$bri, &$user); + } + /*************** + * * + * TABLE * + * * + ***************/ + else if ($user->stat == 'table') { + $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE); + + log_rd2($sess, "SENDED TO THE STREAM: ".$ret); + } + log_rd2($sess, "NEWSTAT: ".$user->stat); + + $new_stat = $user->stat; + $new_subst = $user->subst; + $new_step = $user->step; + } + else { + ignore_user_abort(TRUE); + $sem = Briskin5::lock_data($table_idx); + $bri = &Briskin5::load_data($table_idx); + if (($user = &$bri->get_user($sess, $idx)) == FALSE) { + Briskin5::unlock_data($sem); + ignore_user_abort(FALSE); + return (unrecerror()); + } + if ($cur_step < $user->step) { + do { + if ($cur_step + COMM_N < $user->step) { + if (($cur_stat != $user->stat)) { + $to_stat = $user->stat; + Briskin5::unlock_data($sem); + ignore_user_abort(FALSE); + return (page_sync($user->sess, $to_stat == "table" ? "table.php" : "index.php")); + } + log_rd2($sess, "lost history, refresh from scratch"); + $new_step = -1; + break; + } + for ($i = $cur_step ; $i < $user->step ; $i++) { + $ii = $i % COMM_N; + log_wr($sess, "TRY RET ".$i." COMM_N ".COMM_N." II ".$ii); + $ret .= $user->comm[$ii]; + } + $new_stat = $user->stat; + $new_subst = $user->subst; + $new_step = $user->step; + } while (0); + + if ($user->the_end == TRUE) { + log_rd2($sess, "LOGOUT BYE BYE!!"); + log_auth($user->sess, "Explicit logout."); + $tmp_sess = $user->sess; + $user->sess = ""; + step_unproxy($tmp_sess); + + $user->name = ""; + $user->the_end = FALSE; + + if ($user->subst == 'sitdown') + $bri->room_wakeup(&$user); + else if ($user->subst == 'standup') + $bri->room_outstandup(&$user); + else + log_rd2($sess, "LOGOUT FROM WHAT ???"); + + Briskin5::save_data($bri); + } + } + + Briskin5::unlock_data($sem); + ignore_user_abort(FALSE); + } + + + return ($ret); +} + +/* + * MAIN + */ + +/* + FROM THE EXTERN + sess + stat + step +*/ + +$is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") && + stristr($HTTP_USER_AGENT, "firefox")) ? FALSE : TRUE); + + +header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past + +if (!isset($myfrom)) + $myfrom = ""; +if (!isset($subst)) + $subst = ""; +log_rd2($sess, "FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming); + + +$endtime = time() + STREAM_TIMEOUT; +$old_stat = $stat; +$old_subst = $subst; +$old_step = $ext_step = $step; + +for ($i = 0 ; time() < $endtime ; $i++) { + // log_rd($sess, "PRE MAIN ".$step);; + if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step, $table_idx)) != FALSE) { + echo '@BEGIN@'; + // log_rd2($sess, sprintf("\nSESS: [%s]\nOLD_STAT: [%s] OLD_SUBST: [%s] OLD_STEP: [%s] \nSTAT: [%s] SUBST: [%s] STEP: [%s] \nCOMM: [%s]\n", $sess, $old_stat, $old_subst, $old_step, $stat, $subst, $step, $ret)); + echo "$ret"; + echo ' @END@'; + log_send($sess, "EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret); + flush(); + if ($is_page_streaming) + break; + } + $old_stat = $stat; + $old_subst = $subst; + $old_step = $step; + // log_rd($sess, "POST MAIN ".$step);; + usleep(400000); + if (($i % 5) == 0) { + // log_rd2($sess, "TIME: ".time()); + echo '_'; + flush(); + } +} + +?> diff --git a/web/briskin5/index_wr.php b/web/briskin5/index_wr.php new file mode 100644 index 0000000..e284e09 --- /dev/null +++ b/web/briskin5/index_wr.php @@ -0,0 +1,635 @@ += TABLE_N) + exit; + +$sem = Briskin5::lock_data($table_idx); +$bri = &Briskin5::load_data($table_idx); +if (($user = &$bri->get_user($sess, &$idx)) == FALSE) { + echo "Get User Error"; + log_wr($sess, "Get User Error"); + Briskin5::unlock_data($sem); + exit; +} +$argz = explode('|', $mesg); + +log_wr($sess, 'POSTSPLIT: '.$argz[0]); + +if ($argz[0] == 'shutdown') { + log_auth($user_cur->sess, "Shutdown session."); + $tmp_sess = $user->sess; + $user->sess = ""; + step_unproxy($tmp_sess); + $user->name = ""; + $user->the_end = FALSE; + + log_rd2($user->sess, "AUTO LOGOUT."); + if ($user->subst == 'sitdown' || $user->stat == 'table') + $bri->room_wakeup(&$user); + else if ($user->subst == 'standup') + $bri->room_outstandup(&$user); + else + log_rd2($sess, "SHUTDOWN FROM WHAT ???"); +} +/****************** + * * + * STAT: room * + * * + ******************/ +else if ($user->stat == 'room') { + $user->laccwr = time(); + + if ($argz[0] == 'help') { + $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; + $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_help), 0, "torna ai tavoli", 600, 500); + + log_wr($sess, $user->comm[$user->step % COMM_N]); + $user->step_inc(); + + } + else if ($argz[0] == 'about') { + $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; + $user->comm[$user->step % COMM_N] .= show_notify(str_replace("\n", " ", $G_room_about), 0, "torna ai tavoli", 400, 200); + + log_wr($sess, $user->comm[$user->step % COMM_N]); + $user->step_inc(); + + } + else if ($argz[0] == 'chatt') { + $bri->chatt_send(&$user,$mesg); + } + /********************** + * * + * SUBST: standup * + * * + **********************/ + else if ($user->subst == 'standup') { + + if ($argz[0] == 'sitdown') { + log_wr($sess, "SITDOWN command"); + + if ($user->the_end == TRUE) { + log_wr($sess, "INFO:SKIP:argz == sitdown && the_end == TRUE => ignore request."); + Briskin5::unlock_data($sem); + exit; + } + /* TODO: refact to a function */ + if ($user->bantime > $user->laccwr) { + $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; + $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(); + Briskin5::save_data($bri); + Briskin5::unlock_data($sem); + exit; + } + + // Take parameters + $table_idx = $argz[1]; + $table = &$bri->table[$table_idx]; + + if ($table->player_n == PLAYERS_N) { + log_wr($sess, "WARN:FSM: Sitdown unreachable, table full."); + Briskin5::unlock_data($sem); + exit; + } + + // set new status + $user->subst = "sitdown"; + $user->table = $table_idx; + $user->table_pos = $table->user_add($idx); + + log_wr($sess, "MOP before"); + + if ($table->player_n == PLAYERS_N) { + log_wr($sess, "MOP inall"); + + // Start game for this table. + log_wr($sess, "Start game!"); + + // + // START THE SPAWN HERE!!!! + // + + if (TRUE) { // WITH SPAWN + $curtime = time(); + // Create new spawned table + $us = array(); + for ($i = 0 ; $i < BRISCOLAIN5_PLAYERS_N ; $i++) + $us[$i] = &$bri->user[$table->player[$i]]; + if (($bri =& new Briskin5(&$us, &$table, $table_idx)) == FALSE) + log_wr($sess, "bri create: FALSE"); + else + log_wr($sess, "bri create: ".serialize($bri)); + + + // Set root table and users + } + else { // BEFORE SPAWN + // init table + $table->init(&$bri->user); + $table->game_init(&$bri->user); + $curtime = time(); + + // init users + 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"); + + + $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(); + } + } // end else { BEFORE SPAWN + + log_wr($sess, "MOP after"); + + } + // change room + $bri->room_sitdown(&$user, $table_idx); + + log_wr($sess, "MOP finish"); + + + } + else if ($argz[0] == 'logout') { + $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; + $user->comm[$user->step % COMM_N] .= sprintf('postact_logout();'); + $user->the_end = TRUE; + $user->step_inc(); + } + } + /********************** + * * + * SUBST: sitdown * + * * + **********************/ + else if ($user->subst == 'sitdown') { + if ($argz[0] == 'wakeup') { + $bri->room_wakeup(&$user); + } + else if ($argz[0] == 'logout') { + $bri->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; + $user->step_inc(); + } + } +} +/********************* + * * + * STAT: table * + * * + *********************/ +else if ($user->stat == 'table') { + $user->laccwr = time(); + $table = &$bri->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); + log_wr($sess, $user->comm[$user->step % COMM_N]); + $user->step_inc(); + } + else if ($argz[0] == 'chatt') { + $bri->chatt_send(&$user,$mesg); + } + else if ($argz[0] == 'logout') { + $remcalc = $argz[1]; + + if ($user->exitislock == TRUE) { + $remcalc++; + $user->exitislock = FALSE; + } + + $logout_cont = TRUE; + if ($remcalc >= 3) { + $lockcalc = $table->exitlock_calc(&$bri->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] .= 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]); + $user->step_inc(); + $logout_cont = FALSE; + } + } + else + $user->bantime = $user->laccwr + BAN_TIME; + + if ($logout_cont == TRUE) { + $bri->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]]; + if ($user_cur[$i]->exitislock == FALSE) + $ct++; + } + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $ret = sprintf('gst.st = %d;', $user_cur[$i]->step+1); + $ret .= sprintf('exitlock_show(%d, %s);', $ct, + ($user_cur[$i]->exitislock ? 'true' : 'false')); + $user_cur[$i]->comm[$user_cur[$i]->step % COMM_N] = $ret; + log_wr($sess, $user_cur[$i]->comm[$user_cur[$i]->step % COMM_N]); + $user_cur[$i]->step_inc(); + } + } + else if ($user->subst == 'asta') { + if ($argz[0] == 'lascio' && $user->handpt <= 2) { + $index_cur = $table->gstart % PLAYERS_N; + + log_wr($sess, sprintf("GIOCO FINITO !!!")); + + $table->mult *= 2; + $table->old_reason = sprintf("Ha lasciato %s perche` aveva al massimo 2 punti.", $user->name); + + $table->game_next(); + $table->game_init(&$bri->user); + + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $user_cur = &$bri->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); + $user_cur->comm[$user_cur->step % COMM_N] = $ret; + $user_cur->step_inc(); + } + } + else if ($argz[0] == 'asta') { + $again = TRUE; + + $index_cur = $table->gstart % PLAYERS_N; + if ($user->table_pos == $index_cur && + $table->asta_pla[$index_cur]) { + $a_card = $argz[1]; + $a_pnt = $argz[2]; + + log_wr($sess, "CI SIAMO a_card ".$a_card." asta_card ".$table->asta_card); + + // Abbandono dell'asta + if ($a_card <= -1) { + log_wr($sess, "Abbandona l'asta."); + $table->asta_pla[$index_cur] = FALSE; + $user->asta_card = -1; + $table->asta_pla_n--; + $again = FALSE; + } + else if ($a_card <= 9) { + if ($a_card >= 0 && $a_card < 9 && $a_card > $table->asta_card) + $again = FALSE; + else if ($a_card == 9 && $a_pnt > ($table->asta_pnt >= 61 ? $table->asta_pnt : 60) && $a_pnt <= 120) + $again = FALSE; + + + if ($again == FALSE) { + log_wr($sess, "NUOVI ORZI."); + $user->asta_card = $a_card; + $table->asta_card = $a_card; + if ($a_card == 9) { + $user->asta_pnt = $a_pnt; + $table->asta_pnt = $a_pnt; + } + } + } + + + + if ($again) { // Qualcosa non andato bene, rifare + $ret = sprintf('gst.st = %d; asta_pnt_set(%d);', $user->step+1, + ($table->asta_pnt > 60 ? $table->asta_pnt + 1 : 61) ); + $user->comm[$user->step % COMM_N] = $ret; + $user->step_inc(); + + log_wr($sess, "Ripetere."); + } + else { + /* next step */ + $showst = "show_astat("; + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $user_cur = &$bri->user[$table->player[$i]]; + $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "), + ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt)); + } + if (PLAYERS_N == 3) + $showst .= ",-2,-2"; + $showst .= ");"; + + $maxcard = -2; + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $user_cur = &$bri->user[$table->player[$i]]; + if ($maxcard < $user_cur->asta_card) + $maxcard = $user_cur->asta_card; + } + + if (($table->asta_pla_n > ($maxcard > -1 ? 1 : 0)) && + !($table->asta_card == 9 && $table->asta_pnt == 120)) { + log_wr($sess,"ALLOPPA QUI"); + for ($i = 1 ; $i < PLAYERS_N ; $i++) { + $index_next = ($table->gstart + $i) % PLAYERS_N; + if ($table->asta_pla[$index_next]) { + log_wr($sess,"GSTART 1"); + $table->gstart += $i; + break; + } + } + + + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $user_cur = &$bri->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->asta_card + 1, $table->asta_pnt+1, ($user_cur->handpt <= 2 ? "true" : "false")); + else + $ret .= sprintf('dispose_asta(%d,%d, %s); remark_off();', + $table->asta_card + 1, -($table->asta_pnt+1), ($user_cur->handpt <= 2 ? "true" : "false")); + $user_cur->comm[$user_cur->step % COMM_N] = $ret; + $user_cur->step_inc(); + } + } + else if ($table->asta_pla_n == 0) { + log_wr($sess, "PASSANO TUTTI!"); + + log_wr($sess, sprintf("GIOCO FINITO !!!")); + + $table->old_reason = "Hanno passato tutti."; + $table->mult *= 2; + + $table->game_next(); + $table->game_init(&$bri->user); + + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $user_cur = &$bri->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); + $user_cur->comm[$user_cur->step % COMM_N] = $ret; + $user_cur->step_inc(); + } + } + else { + log_wr($sess, "FINITA !"); + // if a_pnt == 120 supergame ! else abbandono + if ($a_pnt == 120 || $user->asta_card != -1) { + $chooser = $index_cur; + for ($i = 1 ; $i < PLAYERS_N ; $i++) + if ($i != $chooser) + $table->asta_pla[$i] = FALSE; + } + else { + //"gst.st = ".($user->step+1)."; dispose_asta(".($table->asta_card + 1).",".-($table->asta_pnt).", true); remark_off();"; + $user->comm[$user->step % COMM_N] = sprintf( "gst.st = %d; dispose_asta(%d, %d, false); remark_off();", $user->step+1, $table->asta_card + 1,-($table->asta_pnt)); + $user->step_inc(); + for ($i = 1 ; $i < PLAYERS_N ; $i++) { + $chooser = ($table->gstart + $i) % PLAYERS_N; + if ($table->asta_pla[$chooser]) { + break; + } + } + } + $table->asta_win = $chooser; + + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $user_cur = &$bri->user[$table->player[$i]]; + $ret = sprintf('gst.st = %d; %s', $user_cur->step+1, $showst); + + if ($i == $chooser) { + $ret .= "choose_seed(". $table->asta_card."); \$(\"asta\").style.visibility = \"hidden\"; remark_on();"; + } + else { + $ret .= "remark_off();"; + } + + $user_cur->comm[$user_cur->step % COMM_N] = $ret; + $user_cur->step_inc(); + } + } + } + } + else { + log_wr($sess, "NON CI SIAMO"); + } + } + /* asta::choose */ + else if ($argz[0] == 'choose') { + if ($table->asta_win > -1 && + $user->table_pos == $table->asta_win) { + $a_brisco = $argz[1]; + if ($a_brisco >= 0 && $a_brisco < 40) { + $table->briscola = $a_brisco; + $table->friend = $table->card[$a_brisco]->owner; + log_wr($sess,"GSTART 2"); + $table->gstart = ($table->mazzo+1) % PLAYERS_N; + log_wr($sess, "Setta la briscola a ".$a_brisco); + + $chooser = $table->asta_win; + $user_chooser = &$bri->user[$table->player[$chooser]]; + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $user_cur = &$bri->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); + + /* first gamer */ + if ($i == ($table->gstart % PLAYERS_N)) + $ret .= "is_my_time = true; remark_on();"; + else + $ret .= "is_my_time = false; remark_off();"; + + $user_cur->comm[$user_cur->step % COMM_N] = $ret; + $user_cur->step_inc(); + } + /* + TUTTE LE VARIABILI DI STATO PER PASSARE A GIOCARE E LE + VAR PER PASSARE ALLA FASE DI GIOCO + */ + + } + } + } + } + else if ($user->subst == 'game') { + log_wr($sess, "state: table::game".$argz[0]); + + if ($argz[0] == 'play') { + $a_play = $argz[1]; + $a_x = $argz[2]; + $a_y = $argz[3]; + + if (strpos($a_x, "px") != FALSE) + $a_x = substr($a_x,0,-2); + if (strpos($a_y, "px") != FALSE) + $a_y = substr($a_y,0,-2); + + $loggo = sprintf("A_play %s, table_pos %d == %d, mazzo %d, gstart %d, card_stat %d, card_own %d", + $a_play, $user->table_pos, ($table->gstart % PLAYERS_N), + $table->mazzo, $table->gstart, + $table->card[$a_play]->stat, $table->card[$a_play]->owner); + log_wr($sess, "CIC".$loggo); + + /* se era il suo turno e la carta era sua ed era in mano */ + if ($a_play >=0 && $a_play < 40 && + ($user->table_pos == (($table->gstart + $table->turn) % PLAYERS_N)) && + $table->card[$a_play]->stat == 'hand' && + $table->card[$a_play]->owner == $user->table_pos) { + log_wr($sess, sprintf("User: %s Play: %d",$user->name, $a_play)); + + /* Change the card status. */ + $table->card[$a_play]->play($a_x, $a_y); + + /* + * !!!! TURN INCREMENTED BEFORE !!!! + */ + $turn_cur = ($table->gstart + $table->turn) % PLAYERS_N; + $table->turn++; + + $card_play = sprintf("card_play(%d,%d,%d,%d);|", + $user->table_pos, $a_play, $a_x, $a_y); + if (($table->turn % PLAYERS_N) != 0) { /* manche not finished */ + $turn_nex = ($table->gstart + $table->turn) % PLAYERS_N; + + $player_cur = "remark_off();"; + $player_nex = $card_play . "is_my_time = true; remark_on();"; + $player_oth = $card_play; + } + else if ($table->turn <= (PLAYERS_N * 8)) { /* manche finished */ + $winner = calculate_winner($table); + log_wr($sess,"GSTART 3"); + $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)); + $card_take = sprintf("sleep(gst,2000);|cards_take(%d);|cards_hidetake($d);", + $winner, $winner); + $player_cur = "remark_off();" . $card_take . "|"; + if ($turn_cur != $turn_nex) + $player_nex = $card_play . $card_take . "|"; + else + $player_nex = ""; + if ($table->turn < (PLAYERS_N * 8)) /* game NOT finished */ + $player_nex .= "is_my_time = true; remark_on();"; + $player_oth = $card_play . $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]]; + + $ret = sprintf('gst.st = %d; ', $user_cur->step+1); + + + if ($i == $turn_cur) { + $ret .= $player_cur; + } + if ($i == $turn_nex) { + $ret .= $player_nex; + } + if ($i != $turn_cur && $i != $turn_nex) { + $ret .= $player_oth; + } + + $retar[$i] = $ret; + } + + + + + if ($table->turn == (PLAYERS_N * 8)) { /* game finished */ + log_wr($sess, sprintf("GIOCO FINITO !!!")); + + /* ************************************************ */ + /* PRIMA LA PARTE PER LO SHOW DI CHI HA VINTO */ + /* ************************************************ */ + calculate_points(&$table); + + $table->game_next(); + $table->game_init(&$bri->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); + } + } + + + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $user_cur = &$bri->user[$table->player[$i]]; + + $user_cur->comm[$user_cur->step % COMM_N] = $retar[$i]; + $user_cur->step_inc(); + } + + log_wr($sess, sprintf("TURN: %d",$table->turn)); + /* Have played all the players ? */ + /* NO: switch the focus and enable the next player to play. */ + + /* YES: calculate who win and go to the next turn. */ + } + } + else + log_wr($sess, "NOSENSE"); + } +} +log_wr($sess, "before save data"); +Briskin5::save_data($bri); + +Briskin5::unlock_data($sem); +exit; +?> -- 2.17.1