--- /dev/null
+<?php
+define(MAX_BRISKIN5_PLAYERS, 3);
+
+class Briskin5 {
+ var $user;
+ var $table;
+ var $table_idx;
+ var $comm; // commands for many people
+ var $step; // current step of the comm array
+ var $garbage_timeout;
+
+ function Briskin5 (&$room, $table_idx) {
+ $this->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("<br>Sei stato inattivo per ".(EXPIRE_TIME_SMAMMA/60.0)." minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.", 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."<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));
+ }
+
+
+
+}
+
+?>
\ No newline at end of file
--- /dev/null
+/*
+ * 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;
+}
+
+
--- /dev/null
+/*
+ * 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")';
+}
--- /dev/null
+<?php
+/*
+ * brisk - table.php
+ *
+ * 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$
+ *
+ */
+?>
+<html>
+<head>
+<title>Brisk - Tavolo</title>
+<link rel="shortcut icon" href="img/brisk_ico.png">
+<script type="text/javascript" src="../dnd.js"></script>
+<script type="text/javascript" src="../dom-drag.js"></script>
+<script type="text/javascript" src="../commons.js"></script>
+<script type="text/javascript" src="../xhr.js"></script>
+<script type="text/javascript" src="../preload_img.js"></script>
+<script type="text/javascript" src="briskin5.js"></script>
+<script type="text/javascript" src="../AC_OETags.js"></script>
+<link rel="stylesheet" type="text/css" href="../brisk.css">
+<link rel="stylesheet" type="text/css" href="briskin5.css">
+</head>
+<body>
+<SCRIPT type="text/javascript">
+ var sess;
+ var stat = "table";
+ var subst = "none";
+ var table_pos = "";
+ var myfrom = "table_php";
+ var g_withflash = false;
+
+var asta_ptr;
+var area_ptr;
+
+var gst = new globst();
+gst.st = <?php
+require_once("../Obj/brisk.phh");
+
+log_load($sess, "LOAD: briskin5.php");
+
+if (isset($laststate) == false) {
+ $laststate = -1;
+}
+echo $laststate;
+?>;
+var g_is_spawn=1;
+var g_table_idx=<?php echo "$table_idx";?>;
+
+var g_imgct= 0;
+var g_imgtot = g_preload_img_arr.length;
+var g_exitlock = 0;
+
+window.onload = function() {
+ g_withflash = DetectFlashVer(6,0,0);
+ remark_off();
+ table_init();
+ xhr_rd = createXMLHttpRequest();
+ sess = "<?php echo "$sess"; ?>";
+
+ window.onunload = onunload_cb;
+
+ setTimeout(xhr_rd_poll, 0, sess);
+ // setTimeout(preload_images, 0, g_preload_img_arr, g_imgct);
+}
+</SCRIPT>
+<div id="bg" class="area">
+
+<div id="remark" class="remark0"></div>
+<img id="card0" src="img/00.png" class="card">
+<img id="card1" src="img/01.png" class="card">
+<img id="card2" src="img/02.png" class="card">
+<img id="card3" src="img/03.png" class="card">
+<img id="card4" src="img/04.png" class="card">
+<img id="card5" src="img/05.png" class="card">
+<img id="card6" src="img/06.png" class="card">
+<img id="card7" src="img/07.png" class="card">
+<img id="takes" src="img/cover.png" class="cover">
+<img id="card_ne0" src="img/cover.png" class="cover">
+<img id="card_ne1" src="img/cover.png" class="cover">
+<img id="card_ne2" src="img/cover.png" class="cover">
+<img id="card_ne3" src="img/cover.png" class="cover">
+<img id="card_ne4" src="img/cover.png" class="cover">
+<img id="card_ne5" src="img/cover.png" class="cover">
+<img id="card_ne6" src="img/cover.png" class="cover">
+<img id="card_ne7" src="img/cover.png" class="cover">
+<img id="takes_ne" src="img/cover.png" class="cover">
+<img id="card_nw0" src="img/cover.png" class="cover">
+<img id="card_nw1" src="img/cover.png" class="cover">
+<img id="card_nw2" src="img/cover.png" class="cover">
+<img id="card_nw3" src="img/cover.png" class="cover">
+<img id="card_nw4" src="img/cover.png" class="cover">
+<img id="card_nw5" src="img/cover.png" class="cover">
+<img id="card_nw6" src="img/cover.png" class="cover">
+<img id="card_nw7" src="img/cover.png" class="cover">
+<img id="takes_nw" src="img/cover.png" class="cover">
+<img id="card_ea0" src="img/cover_ea.png" class="cover">
+<img id="card_ea1" src="img/cover_ea.png" class="cover">
+<img id="card_ea2" src="img/cover_ea.png" class="cover">
+<img id="card_ea3" src="img/cover_ea.png" class="cover">
+<img id="card_ea4" src="img/cover_ea.png" class="cover">
+<img id="card_ea5" src="img/cover_ea.png" class="cover">
+<img id="card_ea6" src="img/cover_ea.png" class="cover">
+<img id="card_ea7" src="img/cover_ea.png" class="cover">
+<img id="takes_ea" src="img/cover_ea.png" class="cover">
+<img id="card_we0" src="img/cover_we.png" class="cover">
+<img id="card_we1" src="img/cover_we.png" class="cover">
+<img id="card_we2" src="img/cover_we.png" class="cover">
+<img id="card_we3" src="img/cover_we.png" class="cover">
+<img id="card_we4" src="img/cover_we.png" class="cover">
+<img id="card_we5" src="img/cover_we.png" class="cover">
+<img id="card_we6" src="img/cover_we.png" class="cover">
+<img id="card_we7" src="img/cover_we.png" class="cover">
+<img id="takes_we" src="img/cover_we.png" class="cover">
+<div id="asta" class="asta">
+ <img id="asta0" src="img/asta0.png" class="astacard">
+ <img id="asta1" src="img/asta1.png" class="astacard">
+ <img id="asta2" src="img/asta2.png" class="astacard">
+ <img id="asta3" src="img/asta3.png" class="astacard">
+ <img id="asta4" src="img/asta4.png" class="astacard">
+ <img id="asta5" src="img/asta5.png" class="astacard">
+ <img id="asta6" src="img/asta6.png" class="astacard">
+ <img id="asta7" src="img/asta7.png" class="astacard">
+ <img id="asta8" src="img/asta8.png" class="astacard">
+ <img id="asta9" src="img/asta9.png" class="astacard">
+ <div id="astaptdiv" class="punti">
+ <input class="puntifield" id="astapt" name="astapt" type="text" maxsize="3" size="3" value="61">
+ </div>
+ <img id="astaptsub" src="img/astaptsub_ro.png" class="astacard">
+ <img id="astapasso" src="img/astapasso_ro.png" class="astacard">
+ <img id="astalascio" src="img/astalascio_ro.png" class="astacard">
+</div>
+<div id="name" class="pubinfo"></div>
+<div id="public" class="public">
+ <div class="vert_midfloat">
+ <div id="pubasta" class="vert_innfloat_so">
+ <img id="pubacard" src="img/astapasso_ro.png" class="pubacard">
+ <div id="pubapnt"></div>
+ </div>
+ </div>
+</div>
+<div id="name_ea" class="pubinfo_ea"></div>
+<div id="public_ea" class="public_ea">
+ <div class="vert_midfloat">
+ <div id="pubasta_ea" class="vert_innfloat">
+ <img id="pubacard_ea" src="img/astapasso_ro.png" class="pubacard_ea">
+ <div id="pubapnt_ea"></div>
+ </div>
+ </div>
+</div>
+<div id="name_ne" class="pubinfo_ne"></div>
+<div id="public_ne" class="public_ne">
+ <div class="vert_midfloat">
+ <div id="pubasta_ne" class="vert_innfloat">
+ <img id="pubacard_ne" src="img/astapasso_ro.png" class="pubacard_ne">
+ <div id="pubapnt_ne"></div>
+ </div>
+ </div>
+</div>
+<div id="name_nw" class="pubinfo_nw"></div>
+<div id="public_nw" class="public_nw">
+ <div class="vert_midfloat">
+ <div id="pubasta_nw" class="vert_innfloat">
+ <img id="pubacard_nw" src="img/astapasso_ro.png" class="pubacard_nw">
+ <div id="pubapnt_nw"></div>
+ </div>
+ </div>
+</div>
+<div id="name_we" class="pubinfo_we"></div>
+<div id="public_we" class="public_we">
+ <div class="vert_midfloat">
+ <div id="pubasta_we" class="vert_innfloat">
+ <img id="pubacard_we" src="img/astapasso_ro.png" class="pubacard_we">
+ <div id="pubapnt_we"></div>
+ </div>
+ </div>
+</div>
+<div id="chooseed" class="chooseed">
+Hai vinto l'asta.<br> Scegli il seme:
+<img id="seed0" src="img/00.png" class="seed0">
+<img id="seed1" src="img/10.png" class="seed1">
+<img id="seed2" src="img/20.png" class="seed2">
+<img id="seed3" src="img/30.png" class="seed3">
+</div>
+<div id="caller" class="caller">
+<div id="callerinfo" class="callerinfo">Info</div>
+<img id="callerimg" src="img/noimg.png" class="callerimg">
+</div>
+<div class="table_commands">
+<input type="button" class="button" name="xinfo" value="Info." onclick="act_tableinfo();">
+<input type="button" class="button" name="xreload" value="Reload." onclick="act_reload();">
+<div style="vertical-align: top;">
+<img id="exitlock" class="button" style="visibility: hidden; border: 0px; display: inline; position: relative;" onclick="act_exitlock();"><input type="button" class="button" name="xout" value="Out." onclick="safelogout();">
+</div>
+</div>
+
+</div>
+
+
+<div class="subarea">
+<div id="txt" class="chattshort"></div>
+ <table align=center style="width: 98%; margin: auto;"><tr><td style="width:1%; text-align: right;">
+ <div id="myname"></div>
+ </td><td>
+ <input id="txt_in" type="text" style="width: 100%;" onkeypress="chatt_checksend(this,event);">
+ </td></tr></table>
+
+<div id="flasou"></div>
+<hr>
+<div id="heartbit"></div>
+<hr>
+<div id="imgct"></div>
+<hr>
+<div id="sandbox"></div>
+<div id="sandbox2"></div>
+<div id="sandbox3"></div>
+<pre>
+<div id="xhrlog"></div>
+</pre>
+<div id="xhrdeltalog"></div>
+</div>
+</body>
+</html>
--- /dev/null
+<?php
+/*
+ * brisk - index_rd.php
+ *
+ * Copyright (C) 2006-2007 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$
+ *
+ */
+
+require_once("../Obj/brisk.phh");
+require_once("Obj/briskin5.phh");
+
+log_load($sess, "LOAD: index_rd.php ".$QUERY_STRING);
+
+$first_loop = TRUE;
+$the_end = FALSE;
+
+if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
+ echo "Debugging time!";
+ exit;
+}
+
+function shutta()
+{
+ log_rd2("SHUTTA!", connection_status());
+}
+
+
+register_shutdown_function(shutta);
+
+function unrecerror()
+{
+ GLOBAL $is_page_streaming;
+
+ $is_page_streaming = TRUE;
+ log_rd2("XXX", "UNREC_ERROR");
+ return (sprintf('the_end=true; window.onunload = null; document.location.assign("index.php");'));
+}
+
+function page_sync($sess, $page)
+{
+ GLOBAL $is_page_streaming;
+
+ $is_page_streaming = TRUE;
+ log_rd2($sess, "PAGE_SYNC");
+ return (sprintf('the_end=true; window.onunload = null; document.location.assign("%s");', $page));
+}
+
+
+
+
+function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $table_idx)
+{
+ GLOBAL $is_page_streaming, $first_loop;
+
+ $ret = FALSE;
+ $bri = FALSE;
+
+ log_rd2($sess, "M");
+ /* Sync check (read only without modifications */
+ ignore_user_abort(TRUE);
+ if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
+ // Aggiorna l'expire time lato server
+ if ($first_loop == TRUE) {
+ log_only($sess, "F");
+ $bri = &Briskin5::load_data($table_idx);
+ if (($user = &$bri->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();
+ }
+}
+
+?>
--- /dev/null
+<?php
+/*
+ * brisk - index_wr.php
+ *
+ * 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$
+ *
+ */
+
+require_once("../Obj/brisk.phh");
+require_once("Obj/briskin5.phh");
+
+if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
+ echo "Debugging time!";
+ exit;
+}
+
+log_load($sess, "LOAD: index_wr.php");
+
+/*
+ * MAIN
+ */
+log_wr($sess, 'COMM: '.$mesg);
+
+if ($table_idx < 0 || $table_idx >= 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("<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();
+ 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("<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->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;
+?>