--- /dev/null
+#!/bin/bash
+#
+# Defaults
+#
+n_players=3
+ftok_path="/var/lib/brisk"
+web_path="$HOME/brisk"
+web_only=0
+
+if [ -f $HOME/.brisk_install ]; then
+ . $HOME/.brisk_install
+fi
+
+function usage () {
+ echo
+ echo "$1 [-n 3|5] [-w web_dir] [-k <ftok_dir>] [-W]"
+ echo " -h this help"
+ echo " -n number of players - def. $n_players"
+ echo " -w dir where place the web tree - def. \"$web_path\""
+ echo " -k dir where place ftok files - def. \"$ftok_path\""
+ echo " -W install web files only"
+ echo
+}
+
+function get_param () {
+ echo "X$2" | grep -q "^X$1\$"
+ if [ $? -eq 0 ]; then
+ # echo "DECHE" >&2
+ echo "$3"
+ return 2
+ else
+ # echo "DELA" >&2
+ echo "$2" | cut -c 3-
+ return 1
+ fi
+ return 0
+}
+
+#
+# MAIN
+#
+while [ $# -gt 0 ]; do
+ # echo aa $1 xx $2 bb
+ case $1 in
+ -n*) n_players="`get_param "-n" "$1" "$2"`"; sh=$?;;
+ -w*) web_path="`get_param "-w" "$1" "$2"`"; sh=$?;;
+ -k*) ftok_path="`get_param "-k" "$1" "$2"`"; sh=$?;;
+ -W) web_only=1;;
+ -h) usage $0; exit 0;;
+ *) usage $0; exit 1;;
+ esac
+ # echo "SH $sh"
+ shift $sh
+done
+
+#
+# Show parameters
+#
+echo " web_path: \"$web_path\""
+echo " ftok_path: \"$ftok_path\""
+echo " n_players: $n_players"
+
+#
+# Installation
+#
+if [ $web_only -eq 0 ]; then
+ if [ $n_players -ne 3 -a $n_players -ne 5 ]; then
+ echo "n_players ($n_players) out of range (3|5)"
+ exit 1
+ elif [ ! -d $ftok_path ]; then
+ echo "ftok_path (\"$ftok_path\") not exists"
+ exit 2
+ fi
+ touch $ftok_path/spy.txt >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ echo "ftok_path (\"$ftok_path\") write not allow."
+ exit 3
+ fi
+ rm $ftok_path/spy.txt
+
+ # create the fs subtree to enable ftok-ing
+ touch ${ftok_path}/main
+ chmod 666 ${ftok_path}/main
+fi
+install -d $web_path
+install -m 644 web/*.{php,phh,css,js} ${web_path}
+cd web
+find . -name '.htaccess' -exec install -m 644 {} ${web_path}/{} \;
+cd -
+
+if [ $n_players -eq 5 ]; then
+ send_time=250
+else
+ send_time=10
+fi
+
+# .js substitutions
+sed -i "s/PLAYERS_N *= *[0-9]\+/PLAYERS_N = $n_players/g" `find ${web_path} -type f -name '*.js' -exec grep -l 'PLAYERS_N *= *[0-9]\+' {} \;`
+
+sed -i "s/^var G_send_time *= *[0-9]\+/var G_send_time = $send_time/g" `find ${web_path} -type f -name '*.js' -exec grep -l '^var G_send_time *= *[0-9]\+' {} \;`
+
+# .ph[ph] substitutions
+sed -i "s/define *( *PLAYERS_N, *[0-9]\+ *)/define(PLAYERS_N, $n_players)/g" `find ${web_path} -type f -name '*.ph*' -exec grep -l 'define *( *PLAYERS_N, *[0-9]\+ *)' {} \;`
+
+sed -i "s@define *( *FTOK_PATH,[^)]*)@define( FTOK_PATH, \"$ftok_path\")@g" `find ${web_path} -type f -name '*.ph*' -exec grep -l 'define *( *FTOK_PATH,[^)]*)' {} \;`
+
+# install -d ${web_path}/img
+# install -m 644 `ls img/*.{jpg,png} | grep -v 'img/src_'` ${web_path}/img
+
+exit 0
\ No newline at end of file
--- /dev/null
+/*
+ TODO
+
+ CRITICAL - restart preload img
+ CRITICAL - watchdog
+
+ TEST (aum. il timeout) - carte giocate che restano girate
+
+ NORM - one player reject a game (to less points (<2)
+ NORM - tools dir with a main and some pages where check briscola tools.
+ NORM - help page
+ NORM - img -> div + css
+ NORM - (master concept) card selection
+ NORM - internationalization
+
+ WEB
+ - compatibility page
+ - homepage
+ - screenshots
+
+ MIDDLE TODO
+ WIP - info enhancement and related button (how win the last game and with how much points ?)
+ WIP - preload images: (finish the list)
+ - unload of the stream
+ - split server-side data
+ - user assistant (with button to enable disable)
+ - who is playing now
+ - graphics enhancement
+ - asta: highlight buttons (css hover)
+ - documentation
+
+ TO REVIEW - special chars in js
+
+ DONE - change name
+ DONE - automatic and manual logout
+ DONE - cache problems solved via .htaccess
+ DONE - all players out of the auction
+ DONE - time to send cards
+ DONE - hide cards before sends at a new game
+ DONE - well recognization of the browser and O.S.
+ DONE - login consistency !!!!
+ DONE - functionalization of garbage
+ DONE - call garbage function into login
+ DONE - game
+ DONE - manage the reload from scratch of the table page
+ DONE - table reset
+ DONE - sendcard => card_send(idx, ....)
+ DONE - show table for game
+ DONE - points calculation
+ DONE - make-up of the chooser
+ DONE - where place the briscola on the table
+ DONE - users info
+ DONE - show current auction position
+ DONE - table with internal management of the transition between pages.
+ DONE - server side page abort management
+ DONE - cookie problem with Ajax
+ DONE - spostare il tasto "esco"
+
+DOC
+ CHAPTERS
+ HTTP Streaming
+ Local serializer
+ Database on shmem
+ Page abort (reload on http streaming case)
+ Chat
+ Cookies management
+
+CHECK ON NEW SERVERS
+.htaccess AllowOverwrite mode for Cache-Control directive
+
+
+
+
+*/
+
--- /dev/null
+#!/bin/bash
+
+OUTFILE=web/preload_img.js
+IMGPATH=../brisk-img/img
+
+# (
+# echo '<?php'
+# echo 'header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1'
+# echo 'header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past'
+# echo '?>'
+# ) > $OUTFILE
+
+rm -f $OUTFILE
+
+(
+echo "var g_preload_img_arr = new Array( "
+first=1
+spa=" "
+for i in `ls -S $IMGPATH/*.{jpg,png} | grep -v '/src_'`; do
+ if [ $first -ne 1 ]; then
+ echo -n ", "
+ if [ $ct -eq 4 ]; then
+ echo
+ echo -n "$spa"
+ ct=0
+ fi
+ else
+ echo -n "$spa"
+ fi
+ outna="img/`basename $i`"
+ echo -n "\"$outna\""
+ ct=$((ct + 1))
+ first=0
+done
+
+echo ");"
+) >> $OUTFILE
+
+(
+echo "var g_preload_imgsz_arr = new Array( "
+first=1
+sum=0
+spa=" "
+tot=0
+for i in `ls -S $IMGPATH`; do
+ sz="`stat -c '%s' $IMGPATH/$i`"
+ tot=$((tot + sz))
+done
+
+for i in `ls -S $IMGPATH`; do
+ if [ $first -ne 1 ]; then
+ echo -n ", "
+ if [ $ct -eq 8 ]; then
+ echo
+ echo -n "$spa"
+ ct=0
+ fi
+ else
+ echo -n "$spa"
+ fi
+ sz="`stat -c '%s' $IMGPATH/$i`"
+ sum=$((sum + sz))
+ cur="`echo "100.0 * $sum / $tot" | bc -l | sed 's/\(\.[0-9]\)[0-9]*/\1/g'`"
+ echo -n "\"$cur\""
+ ct=$((ct + 1))
+ first=0
+done
+
+echo ");"
+) >> $OUTFILE
+
+exit 0
--- /dev/null
+<FilesMatch "\.(js|css)$">
+header append Cache-Control "public, last-modified, must-revalidate"
+</FilesMatch>
--- /dev/null
+/*
+ * brisk - brisk.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.
+ *
+ */
+
+body {
+/* background-image: url('img/probrisco.jpg'); */
+ background-repeat: no-repeat;
+ align: center;
+ }
+
+div {
+ position: relative;
+ }
+
+.room_td {
+ height: 200px;
+ width: 90px;
+ vertical-align: "top";
+ }
+
+.room_standup {
+ height: 150px;
+ vertical-align: "top";
+ }
+
+.room_ex_standup {
+ height: 150px;
+ vertical-align: "top";
+ }
+
+.room_d_standup {
+ align: "top";
+ border: 1px solid grey;
+ }
+
+.chatt {
+ height: 100px;
+ overflow: auto;
+ border: 1px solid grey;
+ vertical-align: text-bottom;
+ font-size: 10pt;
+ }
+
+.chattshort {
+ height: 70px;
+ overflow: auto;
+ border: 1px solid grey;
+ vertical-align: text-bottom;
+ font-size: 10pt;
+ }
+
+.txtt {
+ font-size: 10pt;
+ }
+
+img {
+ position: absolute;
+ border-style: solid;
+ border-width: 1px;
+ border-color: grey;
+ }
+
+img.nobo {
+ position: relative;
+ border-width: 0px;
+ display: block; margin: auto;
+}
+
+.esco {
+ position: absolute;
+ left: 380;
+ top: 90;
+ }
+
+
+img.tableinfo {
+ position: absolute;
+ left: 620;
+ top: 550;
+ border-width: 0px;
+ visibility: visible;
+ }
+
+img.tableout {
+ position: absolute;
+ left: 700;
+ 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;
+ }
+
+
+.urgmsg {
+ text-align: center;
+ }
+
+.area {
+ display: block;
+ margin-left: auto;
+ margin-right: auto;
+ position: relative;
+ text-align: center;
+ width: 800px;
+ height: 600px;
+ }
+
+.subarea {
+ top: 0px;
+ }
+
+.proxhr {
+ /* background-color: green; */
+ }
+
+.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: 4px;
+}
+
+.remark0 {
+ position: absolute;
+ width: 200px;
+ height: 200px;
+ left: 299;
+ top: 249;
+ border-style: solid;
+ border-width: 0px;
+ border-color: green;
+ z-index: 0;
+ }
+
+.remark1 {
+ position: absolute;
+ width: 200px;
+ height: 200px;
+ left: 296;
+ top: 246;
+ border-style: solid;
+ border-width: 4px;
+ border-color: green;
+ z-index: 0;
+ }
+
+.remark2 {
+ position: absolute;
+ width: 200px;
+ height: 200px;
+ left: 298;
+ top: 248;
+ border-style: solid;
+ border-width: 2px;
+ border-color: green;
+ z-index: 0;
+ }
+
+
+.notify {
+ border-style: solid;
+ border-width: 1px;
+ position: absolute;
+ width: 500px;
+ height: 400px;
+ text-align: center;
+ background-color: white;
+ left: 150;
+ top: 150;
+ z-index: 10;
+ visibility: hidden;
+ filter: alpha(opacity=90);
+ -moz-opacity: 0.90;
+ opacity: 0.90;
+}
+
+.punti {
+ position: absolute;
+}
+
+.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%;
+ 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
+<?php
+/*
+ * brisk - brisk.phh
+ *
+ * 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.
+ *
+ */
+
+define( FTOK_PATH, "/var/lib/brisk");
+define(TABLES_N, 4);
+define(PLAYERS_N, 3);
+define(MAX_POINTS, 5);
+define(MAX_PLAYERS, (PLAYERS_N * TABLES_N));
+define(COMM_N, 12);
+define(COMM_GEN_N, 50);
+define(SESS_LEN, 13);
+define(STREAM_TIMEOUT, 20);
+define(EXPIRE_TIME, 180);
+define(GARBAGE_TIMEOUT, 30);
+define(NICKSERV, "<i>SERVER</i>");
+// define(DEBUGGING, "local");
+
+function xcape($s)
+{
+ return (str_replace('@', '@', str_replace('|', '¦', htmlentities($s,ENT_COMPAT,"UTF-8"))));
+}
+
+
+class Card {
+ var $value; /* 0 - 39 card value */
+ var $stat; /* 'bunch', 'hand', 'table', 'take' */
+ var $owner; /* (table position 0-4) */
+ // var $pos; /* Pos in hand. */
+ var $x; /* When played the X position on the table of the owner. */
+ var $y; /* When played the Y position on the table of the owner. */
+
+ function Card($value, $stat, $owner)
+ {
+ $this->value = $value;
+ $this->stat = $stat;
+ $this->owner = $owner;
+ }
+
+ function assign($stat,$owner)
+ {
+ $this->stat = $stat;
+ $this->owner = $owner;
+ }
+
+ function setpos($pos)
+ {
+ $this->pos = $pos;
+ }
+
+ function play($x,$y)
+ {
+ $this->stat = 'table';
+ $this->x = $x;
+ $this->y = $y;
+ }
+
+ function take($newown)
+ {
+ $this->stat = 'take';
+ $this->owner = $newown;
+ }
+}
+
+class Table {
+ var $player;
+ var $player_n;
+ var $card;
+ var $mazzo;
+ var $gstart;
+ var $turn;
+
+ var $asta_pla;
+ var $asta_pla_n;
+ var $asta_card;
+ var $asta_pnt;
+
+ var $mult;
+ var $points; // points array
+ var $points_n; // number of row of points
+ var $total;
+
+ var $asta_win;
+ var $briscola;
+ var $friend;
+
+ var $old_asta_pnt;
+ var $old_pnt;
+ var $old_win;
+ var $old_friend;
+
+ 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_asta_pnt = -1;
+ $this->old_pnt = -1;
+ $this->old_win = -1;
+ $this->old_friend= -1;
+
+ }
+
+ function &bunch_create()
+ {
+ $ret = array();
+
+ for ($i = 0 ; $i < 40 ; $i++) {
+ $ret[$i] = new Card($i, 'bunch', 'no_owner');
+ }
+
+ return ($ret);
+ }
+
+ function bunch_make()
+ {
+ $ct = array(0,0,0,0,0);
+
+ mt_srand(make_seed());
+
+ for ($i = 39 ; $i >= 0 ; $i--)
+ $rest[$i] = $i;
+
+ for ($i = 39 ; $i >= 0 ; $i--) {
+ $rn = rand(0, $i);
+
+ if ($rn == 0)
+ log_main("RND ZERO", "");
+
+ $id = $rest[$rn];
+
+ $owner = $i % 5;
+ $this->card[$id]->assign('hand', $owner);
+
+ $rest[$rn] = $rest[$i];
+ $pubbpos[$rn2] = $pubbpos[$i];
+ }
+ }
+
+ function init()
+ {
+ $this->mazzo = rand(0,PLAYERS_N-1);
+ $this->points_n = 0;
+ $this->mult = 1;
+ $this->old_win =-1;
+ for ($i = 0 ; $i < PLAYERS_N ; $i++) {
+ $this->total[$i] = 0;
+ }
+
+ log_main("table::init","ci siamo");
+ }
+
+ function game_init(&$bri)
+ {
+ log_rd2($sess,"GSTART 4");
+
+ $this->gstart = ($this->mazzo+1) % PLAYERS_N;
+ $this->bunch_make();
+
+
+ $this->asta_pla_n = PLAYERS_N;
+ $this->asta_card = -1;
+ $this->asta_pnt = 60;
+ $this->asta_win = -1;
+ $this->briscola = -1;
+ $this->friend = -1;
+ $this->turn = 0;
+
+ for ($i = 0 ; $i < PLAYERS_N ; $i++) {
+ $this->asta_pla[$i] = TRUE;
+ $user_cur = &$bri->user[$this->player[$i]];
+ $user_cur->subst = 'asta';
+ $user_cur->asta_card = -2;
+ $user_cur->asta_pnt = -1;
+ }
+ }
+
+ function game_next()
+ {
+ $this->mazzo = ($this->mazzo + 1) % PLAYERS_N;
+ }
+
+ function getPlayer($idx)
+ {
+ return ($this->player[$idx]);
+ }
+
+ function setPlayer($idx, $player)
+ {
+ $this->player[$idx] = $player;
+ }
+}
+
+class User {
+ var $name; // name of the user
+ var $sess; // session of the user
+ var $lacc; // last access (for the cleanup)
+ var $stat; // status (outdoor, room, table, game, ...)
+ var $subst; // substatus for each status
+ var $step; // step of the current status
+ var $trans_step; // step to enable transition between pages (disable == -1)
+ var $comm; // commands array
+ var $asta_card; //
+ var $asta_pnt; //
+
+ var $table; // id of the current table (if in table state)
+ var $table_pos; // idx on the table
+
+ function User($name, $sess, $stat = "", $subst = "", $table = -1) {
+ $this->name = $name;
+ $this->sess = $sess;
+ $this->lacc = time();
+ $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->table = $table;
+ }
+}
+
+class brisco {
+ var $user;
+ var $table;
+ var $comm; // commands for many people
+ var $step; // current step of the comm array
+ var $garbage_timeout;
+
+ function brisco () {
+ $this->user = array();
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $this->user[$i] = new User("", "");
+ }
+ for ($i = 0 ; $i < TABLES_N ; $i++)
+ $this->table[$i] = new Table();
+ $this->garbage_timeout = 0;
+ }
+
+ 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 < $curtime) { // Auto logout dell'utente
+ log_rd2($user_cur->sess, "AUTO LOGOUT.");
+ /*
+ if ($user_cur->stat == 'table') {
+ log_rd2($user_cur->sess, "AUTO LOGOUT: Yet not implemented in table stat!");
+ continue;
+ }
+ else
+ */
+ if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
+ log_auth($user_cur->sess, "Autologout session.");
+
+ $user_cur->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 (0 == 1)
+
+ }
+ }
+ log_rd2($user_cur->sess, "GARBAGE UPDATED!");
+
+ $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
+ }
+ }
+
+
+ function room_wakeup(&$user)
+ {
+ $table_idx = $user->table;
+ $table = &$this->table[$table_idx];
+
+ log_main("WAKEUP", "begin function table:".$table_idx);
+
+ $from_table = ($user->stat == "table");
+ if ($from_table) {
+ log_main("WAKEUP", "from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
+
+ for ($i = 0 ; $i < $table->player_n ; $i++) {
+ $user_cur = &$this->user[$table->player[$i]];
+ log_main("PREIMPOST", "INLOOP name: ".$user_cur->name);
+
+ if ($user_cur != $user) {
+ $user_cur->stat = "room";
+ $user_cur->subst = "sitdown";
+ }
+ else if ($user->sess != "") {
+ $user_cur->stat = "room";
+ $user_cur->subst = "standup";
+ $user_cur->table = -1;
+ }
+ }
+ }
+ /* aggiorna l'array dei giocatori al tavolo. */
+ for ($i = $user->table_pos ; $i < $table->player_n-1 ; $i++) {
+ $table->player[$i] = $table->player[$i+1];
+ $user_cur = &$this->user[$table->player[$i]];
+ $user_cur->table_pos = $i;
+ }
+ $this->table[$table_idx]->player_n--;
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_cur = &$this->user[$i];
+ if ($user_cur->sess == '' || $user_cur->stat != 'room')
+ continue;
+
+ log_main("VALORI", "name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
+
+ // function show_room(&$bri, &$user)
+
+ $ret = "gst.st = ".($user_cur->step+1)."; ";
+ if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
+ $ret .= 'gst.st_loc++; the_end=true; document.location.assign("index.php");|';
+ // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
+ log_main("DOCUMENT.index.php", "from table");
+ }
+ else if ($user_cur->stat == "room") {
+ $ret .= table_content($this, $user_cur, $table_idx);
+ $ret .= standup_content($this, $user_cur);
+
+ $act_content = table_act_content(FALSE, 0, $e, $user->table);
+ $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
+
+
+ if ($user_cur == $user) {
+ // set the new status
+ $ret .= 'subst = "standup"; ';
+ // clean the action buttons in other tables
+ for ($e = 0 ; $e < TABLES_N ; $e++) {
+ if ($this->table[$e]->player_n < PLAYERS_N)
+ $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, table_act_content(TRUE, 0, $e, $user->table));
+ }
+ }
+ else {
+ $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
+ $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
+ }
+ }
+ log_wr($user_cur->sess, "ROOM_WAKEUP: ".$ret);
+ $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+ $user_cur->step++;
+ }
+ }
+
+
+
+
+ function room_outstandup(&$user)
+ {
+ $this->room_sitdown(&$user, -1);
+ }
+
+ function table_update(&$user)
+ {
+ log_main("table_update", "pre - USER: ".$user->name);
+
+ $table_idx = $user->table;
+
+ if ($table_idx > -1)
+ $table = &$this->table[$table_idx];
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $ret = "";
+ $user_cur = &$this->user[$i];
+ if ($user_cur->sess == '' || $user_cur->stat != 'room')
+ continue;
+
+ $ret = "gst.st = ".($user_cur->step+1)."; ";
+ if ($table_idx > -1)
+ $ret .= table_content($this, $user_cur, $table_idx);
+
+ if ($user_cur == $user) {
+ $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
+ }
+ $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+ $user_cur->step++;
+ }
+
+ log_main("table_update", "post");
+ }
+
+ function room_sitdown(&$user, $table_idx)
+ {
+ log_main("room_sitdown", ($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
+
+ if ($table_idx > -1)
+ $table = &$this->table[$table_idx];
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $ret = "";
+ $user_cur = &$this->user[$i];
+ if ($user_cur->sess == '' || $user_cur->stat != 'room')
+ continue;
+
+ $ret = "gst.st = ".($user_cur->step+1)."; ";
+ if ($table_idx > -1)
+ $ret .= table_content($this, $user_cur, $table_idx);
+ $ret .= standup_content($this, $user_cur);
+
+ if ($user_cur == $user) {
+ $ret .= 'subst = "sitdown"; ';
+ // clean the action buttons in other tables
+ for ($e = 0 ; $e < TABLES_N ; $e++) {
+ $act_content = table_act_content(FALSE, 0, $e, $user_cur->table);
+ $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, $act_content);
+ }
+ }
+ else if ($table_idx > -1) {
+ if ($table->player_n == PLAYERS_N) {
+ $act_content = table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table);
+ $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
+ }
+ }
+ $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+ $user_cur->step++;
+ }
+ }
+
+ function chatt_send(&$user, $mesg)
+ {
+ if ($user->stat == 'table') {
+ $table = &$this->table[$user->table];
+ }
+
+ $user_mesg = substr($mesg,6);
+
+ $dt = date("H:i ",time());
+ if (strncmp($user_mesg, "/nick ", 6) == 0) {
+ log_main($user->sess, "chatt_send BEGIN");
+
+ $name_new = substr(trim(substr($user_mesg, 6)),0,12);
+ $user_mesg = "COMMAND ".$user_mesg;
+ // Search dup name
+ // change
+ // update local graph
+ // update remote graphs
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_cur = &$this->user[$i];
+ if ($user_cur->sess == '' || $user_cur->stat != 'room')
+ continue;
+ if ($user_cur->name == $name_new) {
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+ $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","Nickname <b>%s</b> già in uso.");', $dt.NICKSERV, xcape($name_new));
+ $user->step++;
+ break;
+ }
+ }
+ if ($i == MAX_PLAYERS) {
+ $user->name = $name_new;
+
+ log_main($user->sess, "chatt_send start set");
+
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ log_main($user->sess, "chatt_send set loop");
+
+ $user_cur = &$this->user[$i];
+ if ($user_cur->sess == '')
+ continue;
+ if ($user_cur->stat == 'room') {
+ if ($user->stat == 'room' && $user->subst == 'standup') {
+ standup_update(&$this,&$user);
+ }
+ else if ($user->stat == 'room' && $user->subst == 'sitdown' ||
+ $user->stat == 'table') {
+ log_main($user->sess, "chatt_send pre table update");
+
+ $this->table_update(&$user);
+
+ log_main($user->sess, "chatt_send post table update");
+ }
+ }
+ else if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
+ $table = &$this->table[$user->table];
+
+ $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
+ $user_cur->comm[$user_cur->step % COMM_N] = sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
+ xcape($this->user[$table->player[($user_cur->table_pos)%PLAYERS_N]]->name),
+ xcape($this->user[$table->player[($user_cur->table_pos+1)%PLAYERS_N]]->name),
+ xcape($this->user[$table->player[($user_cur->table_pos+2)%PLAYERS_N]]->name),
+ (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3)%PLAYERS_N]]->name)),
+ (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4)%PLAYERS_N]]->name)));
+ if ($user_cur == $user)
+ $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>";',
+ xcape($user->name,ENT_COMPAT,"UTF-8"));
+ $user_cur->step++;
+ }
+ }
+ }
+ }
+ else {
+ $user_mesg = xcape($user_mesg);
+
+ for ($i = 0 ; $i < ($user->stat == 'room' ? MAX_PLAYERS : PLAYERS_N) ; $i++) {
+ if ($user->stat == 'room') {
+ $user_cur = &$this->user[$i];
+ if ($user_cur->sess == '' || $user_cur->stat != 'room')
+ continue;
+ }
+ else {
+ $user_cur = &$this->user[$table->player[$i]];
+ }
+
+ $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
+ $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s","%s");',
+ $dt.xcape($user->name), $user_mesg);
+ $user_cur->step++;
+ }
+ }
+ }
+
+} // end class brisco
+
+function make_seed()
+{
+ list($usec, $sec) = explode(' ', microtime());
+ return (float) $sec + ((float) $usec * 100000);
+}
+
+function log_main($sess, $log) {
+ $fp = fopen("/tmp/brisk_main.log", 'a');
+ fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
+ fclose($fp);
+}
+
+function log_rd($sess, $log) {
+ // $fp = fopen("/tmp/brisk_rd.log", 'a');
+ // fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
+ // fclose($fp);
+ ;
+}
+
+function log_rd2($sess, $log) {
+ $fp = fopen("/tmp/brisk_rd2.log", 'a');
+ fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
+ fclose($fp);
+}
+
+function log_send($sess, $log) {
+ $fp = fopen("/tmp/brisk_send.log", 'a');
+ fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
+ fclose($fp);
+}
+
+function log_auth($sess, $log) {
+ $fp = fopen("/tmp/brisk_auth.log", 'a');
+ fwrite($fp, sprintf("SESS: [%d] [%s] [%s]\n", time(), $sess, $log));
+ fclose($fp);
+}
+
+function log_wr($sess, $log) {
+ $fp = fopen("/tmp/brisk_wr.log", 'a');
+ fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
+ fclose($fp);
+}
+
+function log_load($sess, $log) {
+ $fp = fopen("/tmp/brisk_load.log", 'a');
+ fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
+ fclose($fp);
+}
+
+function init_data()
+{
+ $brisco = new brisco();
+
+ return $brisco;
+}
+
+function lock_data()
+{
+ // 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))
+ return ($res);
+ else
+ return (false);
+}
+
+function unlock_data($res)
+{
+ return (sem_release($res));
+}
+
+
+function &load_data()
+{
+ if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
+ echo "FTOK FAILED";
+ exit;
+ }
+
+ if ($shm = shm_attach($tok,100000 * TABLES_N)) {
+ if(($bri = @shm_get_var($shm, $tok)) == false) {
+ log_main("XXX", "INIT MAIN DATA");
+
+ $bri = init_data();
+ shm_put_var($shm, $tok, $bri);
+ }
+
+ shm_detach($shm);
+
+ return ($bri);
+ }
+
+ return (NULL);
+}
+
+
+function save_data(&$bri)
+{
+ $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,100000 * TABLES_N)) == FALSE)
+ break;
+
+ if (shm_put_var($shm, $tok, $bri) == FALSE)
+ break;
+ // log_main("XXX", "QUI CI ARRIVA [".$bri->user[0]->name."]");
+ $ret = TRUE;
+ } while (0);
+
+ if ($shm)
+ shm_detach($shm);
+
+ return ($ret);
+}
+
+function &get_user(&$bri, $sess, &$idx)
+{
+ GLOBAL $PHP_SELF;
+
+ if (strlen($sess) == SESS_LEN) {
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ if (strcmp($sess, $bri->user[$i]->sess) == 0) {
+ // find it
+ $idx = $i;
+ return ($bri->user[$i]);
+ }
+ }
+ 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]",$bri->user[$i]->sess));
+ }
+ else {
+ log_main($sess, sprintf("get_user: Wrong strlen [%s]",$sess));
+ }
+ return (FALSE);
+}
+
+/*
+ * function &add_user(&$bri, &$sess, &$idx, $name)
+ *
+ * RETURN VALUE:
+ * if ($idx != -1 && ret == FALSE) => duplicated nick
+ * if ($idx == -1 && ret == FALSE) => no space left
+ * if (ret == TRUE) => SUCCESS
+ */
+function &add_user(&$bri, &$sess, &$idx, $name)
+{
+ $idx = -1;
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ /* free user ? */
+ if (strcmp($sess, $bri->user[$i]->sess) == 0) {
+ if ($idx == -1)
+ $idx = $i;
+ }
+ if (strcmp($bri->user[$i]->name, $name) == 0) {
+ $idx = $i;
+ break;
+ }
+ }
+ if ($idx != -1 && $i == MAX_PLAYERS) {
+ /* SUCCESS */
+ $bri->user[$idx]->sess = uniqid("");
+ $sess = $bri->user[$idx]->sess;
+ $bri->user[$idx]->name = $name;
+ $bri->user[$idx]->stat = "room";
+ $bri->user[$idx]->subst = "standup";
+
+ log_main("XXX", sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name));
+
+ return ($bri->user[$idx]);
+ }
+ else {
+ return (FALSE);
+ }
+}
+
+function table_act_content($isstanding, $sitted, $table, $cur_table)
+{
+ $ret = "";
+
+ if ($isstanding) {
+ if ($sitted < PLAYERS_N) {
+ $ret = sprintf('<input type=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
+ }
+ }
+ else {
+ if ($table == $cur_table)
+ $ret = sprintf('<input type=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
+ else
+ $ret = "";
+ }
+ return ($ret);
+}
+
+function table_content($bri, $user, $table_idx)
+{
+ $content = "";
+
+ // TODO
+ //
+ // Si possono usare i dati nella classe table
+ //
+
+ $sess = $user->sess;
+ $table = &$bri->table[$table_idx];
+
+ if ($user->stat != 'room')
+ return;
+
+ for ($i = 0 ; $i < $table->player_n ; $i++) {
+ $user_cur = &$bri->user[$table->player[$i]];
+
+ if ($user_cur == $user)
+ { $hilion = "<b>"; $hilioff = "</b>"; }
+ else
+ { $hilion = ""; $hilioff = ""; }
+
+ log_main($bri->user[$e]->name, sprintf("IN TABLE [%d]", $table_idx));
+
+ $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
+ }
+ for ( ; $i < PLAYERS_N ; $i++)
+ $content .= "<br>";
+
+ $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
+
+ return ($ret);
+}
+
+function standup_content(&$bri, $user)
+{
+ $ret = "";
+ $content = "";
+
+ if ($user->stat != 'room')
+ return;
+
+ $content .= '<table width=\\"100%\\">';
+ for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
+ if ($bri->user[$e]->sess == "" || $bri->user[$e]->stat != "room" || $bri->user[$e]->name == "")
+ continue;
+
+
+ if ($bri->user[$e]->subst == "standup") {
+ if (($ct % 4) == 0) {
+ $content .= '<tr>';
+ }
+ if ($bri->user[$e] == $user)
+ { $hilion = "<b>"; $hilioff = "</b>"; }
+ else
+ { $hilion = ""; $hilioff = ""; }
+
+ $content .= sprintf('<td style=\\"text-align: center\\">%s%s%s</td>',$hilion, xcape($bri->user[$e]->name), $hilioff);
+ if (($ct % 4) == 3) {
+ $content .= '</tr>';
+ }
+ $ct++;
+ }
+ }
+ $content .= '</table>';
+
+ $content .= '<div class=\\"esco\\"><input name=\\"logout\\" value=\\"Esco.\\" onclick=\\"act_logout();\\" type=\\"button\\"></div>';
+
+ $ret .= sprintf('$("standup").innerHTML = "%s";', $content);
+
+ return ($ret);
+}
+
+function standup_update(&$bri, &$user)
+{
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_cur = &$bri->user[$i];
+ if ($user_cur->sess == '')
+ continue;
+
+ log_main("STANDUP START", $user_cur->stat);
+
+ if ($user_cur->stat == 'room') {
+ $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".standup_content($bri, $user_cur);
+ if ($user_cur == $user)
+ $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
+
+ log_main("FROM STANDUP", "NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
+
+ $user_cur->step++;
+ }
+ }
+}
+
+
+
+
+
+function show_notify($text, $tout, $butt)
+{
+ log_main("SHOW_NOTIFY", $text);
+ return sprintf('var noti = new notify(gst,$("bg"),"%s",%d,"%s");', $text, $tout,$butt);
+}
+
+
+
+
+function briscola_show($bri, $table, $user)
+{
+ $ptnadd = "";
+ $ret = "";
+
+ if ($table->asta_card == 9)
+ $ptnadd = sprintf("<br>con %d punti", $table->asta_pnt);
+
+ /* text of caller cell */
+ if ($user->table_pos == $table->asta_win)
+ $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);
+
+ $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
+ $table->asta_win);
+ $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola);
+ $ret .= sprintf('$("caller").style.visibility = "visible";');
+ $ret .= sprintf('$("chooseed").style.visibility = "hidden";');
+ $ret .= sprintf('$("asta").style.visibility = "hidden";');
+ $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);');
+
+ return ($ret);
+}
+
+
+function game_result($asta_pnt, $pnt)
+{
+ if ($asta_pnt == 61) {
+ if ($pnt > 60)
+ return (1);
+ else if ($pnt == 60)
+ return (0);
+ else
+ return (-1);
+ }
+ else {
+ if ($pnt >= $asta_pnt)
+ return (1);
+ else
+ return (-1);
+ }
+}
+
+function multoval($mult)
+{
+ if ($mult == 2)
+ return ("doppio");
+ else if ($mult == 4)
+ return ("quadruplo");
+ else
+ return (sprintf("%d-plo", $mult));
+}
+
+function show_table_info(&$bri, &$table, $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("</tr>");
+
+ // Points.
+ log_main("show_table_info", "pnt_min: ".$pnt_min." Points_n: ".$table->points_n);
+
+ for ($i = $pnt_min ; $i < $table->points_n ; $i++) {
+ $noty .= sprintf('<tr><th class=\"td_points\">%d</th>', $i+1);
+ for ($e = 0 ; $e < PLAYERS_N ; $e++)
+ $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->points[$i % MAX_POINTS][$e]);
+ $noty .= "</tr>";
+ }
+
+ // Total points.
+ $noty .= '<tr><th class=\"td_points\">Tot.</th>';
+ for ($e = 0 ; $e < PLAYERS_N ; $e++)
+ $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->total[$e]);
+ $noty .= "</tr></table>";
+
+ if ($table->old_win != -1) {
+ $win = $table->player[$table->old_win];
+ $fri = $table->player[$table->old_friend];
+
+ $wol = game_result($table->old_asta_pnt, $table->old_pnt);
+
+ 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));
+ if ($table->old_pnt == 120) {
+ $noty .= sprintf("hanno fatto <b>cappotto</b> EBBRAVI!.<hr>");
+ }
+ else {
+ $noty .= sprintf("dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>",
+ ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
+ 'più di 60'), $table->old_pnt,
+ ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
+ }
+ }
+ else {
+ $noty .= sprintf("<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>",
+ xcape($bri->user[$win]->name));
+ if ($table->old_pnt == 120) {
+ $noty .= sprintf("ha fatto <b>cappotto</b> EBBRAVO!.<hr>");
+ }
+ else {
+ $noty .= sprintf("doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>",
+ ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
+ 'più di 60'), $table->old_pnt,
+ ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
+ }
+ }
+ }
+ if ($table->mazzo == $table_pos)
+ $noty .= "Fai <b>tu</b> il mazzo.";
+ else {
+ $unam = xcape($bri->user[$table->player[$table->mazzo]]->name);
+ $noty .= "Il mazzo a <b>$unam</b>.";
+ }
+
+ if ($table->mult > 1) {
+ $noty .= sprintf(" La partita vale <b>%s</b>.", multoval($table->mult));
+ }
+ $noty .= "<hr><br>";
+
+ $ret .= show_notify($noty, 3000, "torna alla partita");
+
+ return ($ret);
+}
+
+
+
+function show_room(&$bri, &$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);
+ $act_content = table_act_content(($user->subst == 'standup'),
+ $bri->table[$i]->player_n, $i, $user->table);
+ $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $i, $act_content);
+ }
+ $ret .= standup_content($bri, $user);
+
+ return ($ret);
+}
+
+
+
+/* show table
+is_transition (is from room to table ?)
+is_again (is another game)
+ */
+function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again)
+{
+ $table_idx = $user->table;
+ $table = &$bri->table[$table_idx];
+
+ /****************
+ FOR RELOAD:
+ DONE - user names
+ handed cards
+ tabled cards
+ taked cards
+ remark on/off
+ cards dnd (and gameable card if its turn)
+ who call and what
+ ****************/
+
+
+ $ret = "table_init();";
+
+ if (!$is_again) {
+ /* GENERAL STATUS */
+ $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
+ $sendstep, $user->stat, $user->subst, $user->table_pos);
+ /* BACKGROUND */
+ $ret .= "background_set();";
+
+ /* 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[($user->table_pos)%PLAYERS_N]]->name),
+ xcape($bri->user[$table->player[($user->table_pos+1)%PLAYERS_N]]->name),
+ xcape($bri->user[$table->player[($user->table_pos+2)%PLAYERS_N]]->name),
+ (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($user->table_pos+3)%PLAYERS_N]]->name)),
+ (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($user->table_pos+4)%PLAYERS_N]]->name)));
+ }
+ /* NOTIFY FOR THE CARD MAKER */
+ if ($is_transition) { // && $user->subst == "asta" superfluo
+ $ret .= show_table_info(&$bri, &$table, $user->table_pos);
+ }
+
+ /* CARDS */
+ if ($is_transition) { // && $user->subst == "asta" superfluo
+ $ret .= "|";
+
+ for ($i = 0 ; $i < 8 ; $i++) {
+ for ($e = 0 ; $e < PLAYERS_N ; $e++) {
+ $ct = 0;
+ for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) {
+ if ($table->card[$o]->owner == (($e + $table->gstart) % PLAYERS_N)) {
+ $ct++;
+ if ($ct == $i+1)
+ break;
+ }
+ }
+ log_rd($sess, "O ".$o." VAL ".$table->card[$o]->value." Owner: ".$table->card[$o]->owner);
+
+ $ret .= sprintf( ' card_send(%d,%d,%d,%f,%d);|', ($table->gstart + $e) % PLAYERS_N,
+ $i, ((($e + PLAYERS_N - $user->table_pos + $table->gstart) % PLAYERS_N) == 0 ?
+ $table->card[$o]->value : -1),
+ ($i == 7 && $e == (PLAYERS_N - 1) ? 1 : 0.5),$i+1);
+ }
+ }
+ }
+ else {
+ $taked = array(0,0,0,0,0);
+ $inhand = array(0,0,0,0,0);
+ $ontabl = array(-1,-1,-1,-1,-1);
+ $cards = array();
+
+ for ($i = 0 ; $i < 40 ; $i++) {
+ if ($table->card[$i]->stat == 'hand') {
+ if ($table->card[$i]->owner == $user->table_pos) {
+ $cards[$inhand[$table->card[$i]->owner]] = $table->card[$i]->value;
+ }
+ $inhand[$table->card[$i]->owner]++;
+ }
+ else if ($table->card[$i]->stat == 'take') {
+ log_main("Card taked:", $table->card[$i]->value."OWN: ".$table->card[$i]->owner);
+ $taked[$table->card[$i]->owner]++;
+ }
+ else if ($table->card[$i]->stat == 'table') {
+ $ontabl[$table->card[$i]->owner] = $i;
+ }
+ }
+ $logg = "\n";
+ for ($i = 0 ; $i < PLAYERS_N ; $i++) {
+ $logg .= sprintf("INHAND: %d IN TABLE %d TAKED %d\n", $inhand[$i], $ontabl[$i], $taked[$i]);
+ }
+ log_main("Stat table:", $logg);
+
+ /* Set ours cards. */
+ $oursarg = "";
+ for ($i = 0 ; $i < $inhand[$user->table_pos] ; $i++)
+ $oursarg .= ($i == 0 ? "" : ", ").$cards[$i];
+ for ($i = $inhand[$user->table_pos] ; $i < 8 ; $i++)
+ $oursarg .= ($i == 0 ? "" : ", ")."-1";
+ $ret .= sprintf('card_setours(%s);', $oursarg);
+
+ /* Dispose all cards */
+ for ($i = 0 ; $i < PLAYERS_N ; $i++) {
+ /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */
+ $ret .= sprintf('cards_dispose(%d,%d,%d);', $i,
+ $inhand[$i], $taked[$i]);
+
+ if ($ontabl[$i] != -1) {
+ $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i],
+ $table->card[$ontabl[$i]]->value,
+ $table->card[$ontabl[$i]]->x, $table->card[$ontabl[$i]]->y);
+ }
+ }
+ }
+
+ /* Show auction */
+ if ($user->subst == 'asta') {
+
+ /* show users auction status */
+ $showst = "";
+ 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";
+ $ret .= sprintf('show_astat(%s);', $showst);
+
+ if ($table->asta_win != -1 && $table->asta_win == $user->table_pos) {
+ /* show card chooser */
+ $ret .= sprintf('choose_seed(%s); $("asta").style.visibility = "hidden";',
+ $table->asta_card);
+ }
+ else {
+ /* show auction */
+ if ($user->table_pos == ($table->gstart % PLAYERS_N) &&
+ $table->asta_win == -1)
+ $ret .= sprintf('dispose_asta(%d,%d);',
+ $table->asta_card + 1, $table->asta_pnt+1);
+ else
+ $ret .= sprintf('dispose_asta(%d,%d);',
+ $table->asta_card + 1, -($table->asta_pnt+1));
+ }
+
+ /* Remark */
+ if ($table->asta_win == -1) { // auction case
+ if ($user->table_pos == ($table->gstart % PLAYERS_N))
+ $ret .= "remark_on();";
+ else
+ $ret .= "remark_off();";
+ }
+ else { // chooseed case
+ if ($user->table_pos == $table->asta_win)
+ $ret .= "remark_on();";
+ else
+ $ret .= "remark_off();";
+ }
+ }
+ else if ($user->subst == 'game') {
+ /* HIGHLIGHT */
+ if (($table->gstart + $table->turn) % PLAYERS_N == $user->table_pos)
+ $ret .= "is_my_time = true; remark_on();";
+ else
+ $ret .= "remark_off();";
+
+ /* WHO CALL AND WATH */
+ $ret .= briscola_show($bri, $table, $user);
+
+ }
+ return ($ret);
+ }
+
+function calculate_winner(&$table)
+{
+ $briontab = FALSE;
+ $ontab = array();
+ $ontid = array();
+ $cur_win = -1;
+ $cur_val = 100;
+ $cur_seed = $table->briscola - ($table->briscola % 10);
+
+ for ($i = 0 ; $i < 40 ; $i++) {
+ if ($table->card[$i]->stat != "table")
+ continue;
+
+ log_wr($sess, sprintf("Card On table: [%d]", $i));
+
+ $v = $table->card[$i]->value;
+ $ontab[$table->card[$i]->owner] = $v;
+ $ontid[$table->card[$i]->owner] = $i;
+ /* se briscola setto il flag */
+ if (($v - ($v % 10)) == $cur_seed)
+ $briontab = TRUE;
+ }
+
+ if ($briontab == FALSE) {
+ $cur_win = $table->gstart;
+ $cur_val = $ontab[$cur_win];
+ $cur_seed = $cur_val - ($cur_val % 10);
+ }
+
+ for ($i = 0 ; $i < PLAYERS_N ; $i++) {
+ if (($ontab[$i] - ($ontab[$i] % 10)) == $cur_seed) {
+ if ($ontab[$i] < $cur_val) {
+ $cur_val = $ontab[$i];
+ $cur_win = $i;
+ }
+ }
+ }
+
+ for ($i = 0 ; $i < PLAYERS_N ; $i++) {
+ $table->card[$ontid[$i]]->owner = $cur_win;
+ $table->card[$ontid[$i]]->stat = "take";
+ }
+ return ($cur_win);
+}
+
+function calculate_points(&$table)
+{
+ $all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
+
+ $pro = 0;
+
+ if ($table->asta_pnt == 60)
+ $table->asta_pnt = 61;
+
+ $table->old_win = $table->asta_win;
+ $table->old_friend = $table->friend;
+ $table->old_asta_pnt = $table->asta_pnt;
+
+ for ($i = 0 ; $i < 40 ; $i++) {
+ $ctt = $table->card[$i]->value % 10;
+ $own = $table->card[$i]->owner;
+ if ($own == $table->asta_win || $own == $table->friend)
+ $pro += $all_points[$ctt];
+ }
+
+ log_wr("XXX", sprintf("PRO: [%d]", $pro));
+
+
+ if ($table->asta_pnt == 61 && $pro == 60) { // PATTA !
+ $table->points[$table->points_n % MAX_POINTS] = array();
+ for ($i = 0 ; $i < PLAYERS_N ; $i++)
+ $table->points[$table->points_n % MAX_POINTS][$i] = 0;
+ $table->points_n++;
+ $table->old_pnt = $pro;
+ $table->mult *= 2;
+
+ return;
+ }
+
+ if ($pro >= $table->asta_pnt)
+ $sig = 1;
+ else
+ $sig = -1;
+
+ $table->points[$table->points_n % MAX_POINTS] = array();
+ for ($i = 0 ; $i < 5 ; $i++) {
+ if ($i == $table->asta_win)
+ $pt = ($i == $table->friend ? 4 : 2);
+ else if ($i == $table->friend)
+ $pt = 1;
+ else
+ $pt = -1;
+
+ log_wr("XXX", sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt));
+
+ $pt = $pt * $sig * $table->mult * ($pro == 120 ? 2 : 1);
+
+ log_wr("XXX", sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1)));
+
+ $table->points[$table->points_n % MAX_POINTS][$i] = $pt;
+ $table->total[$i] += $pt;
+ }
+ $table->points_n++;
+ $table->old_pnt = $pro;
+ $table->mult = 1;
+}
+
+?>
--- /dev/null
+/*
+ * brisk - commons.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.
+ *
+ */
+
+var PLAYERS_N = 3;
+
+function $(id) { return document.getElementById(id); }
+
+/* replacement of setInterval on IE */
+(function(){
+ /*if not IE, do nothing*/
+ if(!document.uniqueID){return;};
+
+ /*Copy the default setInterval behavior*/
+ var nativeSetInterval = window.setInterval;
+ window.setInterval = function(fn,ms) {
+ var param = [];
+ if(arguments.length <= 2) {
+ return nativeSetInterval(fn,ms);
+ }
+ else {
+ for(var i=2;i<arguments.length;i+=1) {
+ param[i-2] = arguments[i];
+ }
+ }
+
+ if(typeof(fn)=='function') {
+
+ return (function (fn,ms,param) {
+ var fo = function () {
+ fn.apply(window,param);
+ };
+ return nativeSetInterval(fo,ms);
+ })(fn,ms,param);
+ }
+ else if(typeof(fn)=='string')
+ {
+ return nativeSetInterval(fn,ms);
+ }
+ else
+ {
+ throw Error('setInterval Error\nInvalid function type');
+ };
+ };
+})()
+
+ // var card_pos = RANGE 0 <= x < cards_ea_n
+
+function rnd_int(min, max) {
+ return Math.floor(Math.random() * (max - min + 1) + min);
+}
+
+function error_images()
+{
+ alert("GHESEMU!");
+}
+
+function abort_images()
+{
+ alert("ABORTAIMAGES");
+}
+
+function unload_images()
+{
+ alert("ABORTAIMAGES");
+}
+
+function reset_images()
+{
+ alert("ABORTAIMAGES");
+}
+
+function update_images()
+{
+ $("imgct").innerHTML = "Immagini caricate "+g_preload_imgsz_arr[g_imgct]+"%.";
+ if (g_imgct < g_preload_img_arr.length)
+ setTimeout(preload_images, 100, g_preload_img_arr, g_imgct);
+ g_imgct++;
+ // $("imgct").innerHTML += "U";
+}
+
+function preload_images(arr,idx)
+{
+ var im = new Image;
+
+ // $("imgct").innerHTML = "Stiamo caricando "+arr[idx]+"%.<br>";
+ im.onload = update_images;
+ im.onerror = error_images;
+ im.onabort = abort_images;
+ im.onunload = unload_images;
+ im.onreset = reset_images;
+ im.src = arr[idx];
+ // $("imgct").innerHTML += "P";
+}
+
+function safestatus(a)
+{
+ try{
+ return (a.status);
+ } catch(b)
+ { return (-1); }
+}
+
+function createXMLHttpRequest() {
+ try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
+ try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
+ try { return new XMLHttpRequest(); } catch(e) {}
+ alert("XMLHttpRequest not supported");
+ return null;
+}
+
+function send_mesg(mesg)
+{
+ var xhr_wr = createXMLHttpRequest();
+ // xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+encodeURIComponent(mesg), true);
+ xhr_wr.open('GET', 'index_wr.php?sess='+sess+'&mesg='+mesg, true);
+ xhr_wr.onreadystatechange = function() { return; };
+ xhr_wr.send(null);
+
+}
+
+/* Stat: CHAT and TABLE */
+
+function act_chatt()
+{
+ var obj = $("txt_in");
+ if (obj.value == "")
+ return (false);
+ send_mesg("chatt|"+encodeURIComponent(obj.value));
+ obj.disabled = true;
+ obj.value = "";
+ obj.disabled = false;
+ obj.focus();
+
+ return false;
+}
+
+/* Stat: ROOM */
+function act_sitdown(table)
+{
+ send_mesg("sitdown|"+table);
+}
+
+function act_wakeup()
+{
+ send_mesg("wakeup");
+}
+
+/* Stat: TABLE Subst: ASTA */
+function act_asta(card,pnt)
+{
+ send_mesg("asta|"+card+"|"+pnt);
+}
+
+function act_choose(card)
+{
+ // alert("sitdown");
+ send_mesg("choose|"+card);
+}
+
+/* Stat: TABLE Subst: GAME */
+function act_play(card,x,y)
+{
+ // alert("sitdown");
+ send_mesg("play|"+card+"|"+x+"|"+y);
+}
+
+function act_tableinfo()
+{
+ send_mesg("tableinfo");
+}
+
+function act_logout()
+{
+ send_mesg("logout");
+}
+
+function act_preout()
+{
+ act_logout();
+}
+
+function postact_logout()
+{
+ // alert("postact_logout");
+ try {
+ xhr_rd.abort();
+ } catch (e) {}
+
+ eraseCookie("sess");
+ document.location.assign("index.php");
+}
+
+/*
+ function slowimg(img,x1,y1,deltat,free,action,srcend)
+ img - image to move
+ x1,y1 - destination coords
+ deltat - time for each frame (in msec)
+ free - when the release the local block for other operations (range: 0 - 1)
+ action - function to run when the image is moved
+ srcend - image to switch when the image is moved
+*/
+
+function sleep(st, delay)
+{
+ // alert("LOC_NEW PRE: "+st.st_loc_new);
+
+ st.st_loc_new++;
+
+ setTimeout(function(obj){ if (obj.st_loc_new > obj.st_loc) { obj.st_loc++; }},
+ delay, st);
+}
+
+function slowimg(img,x1,y1,deltat,free,action,srcend) {
+ this.img = img;
+
+ this.x0 = parseInt(window.getComputedStyle(this.img, "").getPropertyValue("left"));
+ // alert("img.x0 = "+this.x0);
+ this.y0 = parseInt(window.getComputedStyle(this.img, "").getPropertyValue("top"));
+ this.x1 = x1;
+ this.y1 = y1;
+ this.deltat = deltat;
+ this.free = free;
+ this.action = action;
+ this.srcend = srcend;
+}
+
+slowimg.prototype = {
+ img: null,
+ st: null,
+ x0: 0,
+ y0: 0,
+ x1: 0,
+ y1: 0,
+ dx: 0,
+ dy: 0,
+ free: 0,
+ step_n: 0,
+ step_cur: 0,
+ step_free: 0,
+ time: 0,
+ deltat: 40,
+ tout: 0,
+ action: null,
+ srcend: null,
+
+ setstart: function(x0,y0)
+ {
+ this.x0 = x0;
+ this.y0 = y0;
+ },
+
+ setaction: function(act)
+ {
+ this.action = act;
+ },
+
+ settime: function(time)
+ {
+ this.time = time;
+ this.step_n = parseInt(time / this.deltat);
+ this.dx = (this.x1 - this.x0) / this.step_n;
+ this.dy = (this.y1 - this.y0) / this.step_n;
+ if (this.step_n * this.deltat == time) {
+ this.step_n--;
+ }
+ this.step_free = parseInt(this.step_n * this.free);
+ },
+
+ start: function(st)
+ {
+ // $("logz").innerHTML += " xxxxxxxxxxxxxxxxxxxxxSTART<br>";
+ this.st = st;
+ this.st.st_loc_new++;
+
+ this.img.style.visibility = "visible";
+ setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
+ },
+
+ animate: function()
+ {
+ // $("log").innerHTML = "Val " + this.step_cur + " N: " + this.step_n + "<br>";
+ if (this.step_cur == 0) {
+ var date = new Date();
+ // $("logz").innerHTML = "Timestart: " + date + "<br>";
+ }
+ if (this.step_cur <= this.step_n) {
+ this.img.style.left = this.x0 + this.dx * this.step_cur;
+ this.img.style.top = this.y0 + this.dy * this.step_cur;
+ this.step_cur++;
+ setTimeout(function(obj){ obj.animate(); }, this.deltat, this);
+ if (this.step_cur == this.step_free && this.st != null) {
+ if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
+ // alert("QUI1 " + this.step_cur + " ZZ "+ this.step_free);
+ this.st.st_loc++;
+ this.st = null;
+ }
+ }
+ }
+ else {
+ this.img.style.left = this.x1;
+ this.img.style.top = this.y1;
+ // $("logz").innerHTML += "xxxxxxxxxxxxxxxCLEAR<br>";
+ var date = new Date();
+ // $("logz").innerHTML += "Timestop: " + date + "<br>";
+ if (this.st != null && this.st.st_loc < this.st.st_loc_new) {
+ // alert("QUI2");
+ this.st.st_loc++;
+ this.st = null;
+ }
+ if (this.action != null) {
+ eval(this.action);
+ }
+ if (this.srcend != null) {
+ this.img.src = this.srcend;
+ }
+ }
+ }
+}
+
+var asta_xarr = new Array(0,66,133);
+
+/* TODO: impostare gli onclick */
+function dispose_asta(idx, pnt)
+{
+ var i, btn, pass;
+
+ var btn;
+ for (i = 0 ; i < 10 ; i++) {
+ btn = $("asta"+i);
+ if (i < idx) {
+ btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
+ pass = -1;
+ }
+ else {
+ btn.src = "img/asta"+i+(pnt >= 0 ? "" : "_ro")+".png";
+ pass = i;
+ }
+ if (i < 19)
+ btn.style.left = asta_xarr[i % 3];
+ else
+ btn.style.left = asta_xarr[(i+1) % 3];
+
+ btn.style.top = parseInt(i / 3) * 50+1;
+ // btn.style.visibility = "visible";
+
+ if (pnt >= 0)
+ eval("btn.onclick = function () { act_asta("+pass+",61); }");
+ else
+ btn.onclick = null;
+ }
+
+
+ btn = $("astaptdiv");
+ btn.style.left = asta_xarr[i % 3];
+ btn.style.top = parseInt(i / 3) * 50;
+ // btn.style.visibility = "visible";
+
+ btn = $("astapt");
+ var rpnt = (pnt < 0 ? -pnt : pnt);
+ btn.value = (rpnt < 61 ? 61 : (rpnt > 120 ? 120 : rpnt));
+
+ btn = $("astaptsub");
+ btn.style.left = asta_xarr[i % 3];
+ btn.style.top = 25 + parseInt(i / 3) * 50;;
+ btn.src = "img/astaptsub"+(pnt >= 0 ? "" : "_ro")+".png";
+ // btn.style.visibility = "visible";
+ if (pnt >= 0)
+ btn.onclick = function () { act_asta(9,$("astapt").value); };
+ else
+ btn.onclick = null;
+
+ i+=1;
+ btn = $("astapasso2");
+ btn.style.left = asta_xarr[i % 3];
+ btn.style.top = parseInt(i / 3) * 50;;
+ btn.src = "img/astapasso"+(pnt >= 0 ? "" : "_ro")+".png";
+ // btn.style.visibility = "visible";
+ if (pnt >= 0)
+ btn.onclick = function () { act_asta(-1,0); };
+ else
+ btn.onclick = null;
+ $("asta").style.visibility = "visible";
+}
+
+function hide_asta()
+{
+ $("asta").style.visibility = "hidden";
+}
+
+function notify(st, ancestor, text, tout, butt)
+{
+ var clo, box;
+ var t = this;
+
+ this.st = st;
+ this.ancestor = ancestor;
+
+ this.st.st_loc_new++;
+
+ clo = document.createElement("input");
+ clo.type = "submit";
+ clo.value = butt;
+ clo.obj = this;
+ clo.onclick = this.input_hide;
+
+ box = document.createElement("div");
+ box.className = "notify";
+ box.innerHTML = text;
+ box.style.zIndex = 200;
+ box.appendChild(clo);
+ box.style.visibility = "visible";
+
+ this.notitag = box;
+
+ this.ancestor.appendChild(box);
+
+ this.toutid = setTimeout(function(obj){ obj.unblock(); }, tout, this);
+}
+
+notify.prototype = {
+ ancestor: null,
+ st: null,
+ notitag: null,
+ toutid: null,
+
+ unblock: function()
+ {
+ if (this.st.st_loc < this.st.st_loc_new) {
+ this.st.st_loc++;
+ }
+ },
+
+ hide: function()
+ {
+ clearTimeout(this.toutid);
+ this.ancestor.removeChild(this.notitag);
+ this.unblock();
+ },
+
+ input_hide: function()
+ {
+ clearTimeout(this.obj.toutid);
+ this.obj.ancestor.removeChild(this.obj.notitag);
+ this.obj.unblock();
+ }
+}
+
+
+function $(id) {
+ return document.getElementById(id);
+}
+
+function globst() {
+ this.st = -1;
+ this.st_loc = -1;
+ this.st_loc_new = -1;
+ this.comms = new Array;
+}
+
+
+
+function remark_step()
+{
+ var ct = $("remark").l_remct;
+
+ if (ct != 0) {
+ ct++;
+ if (ct > 2)
+ ct = 1;
+ $("remark").className = "remark"+ct;
+ $("remark").l_remct = ct;
+ setTimeout(remark_step,500);
+ }
+ else
+ $("remark").className = "remark0";
+
+ return;
+}
+
+function remark_on()
+{
+ if ($("remark").l_remct == 0) {
+ $("remark").l_remct = 1;
+ setTimeout(remark_step,500);
+ }
+}
+
+function remark_off()
+{
+ $("remark").l_remct = 0;
+ $("remark").className = "remark0";
+}
+
+
+function choose_seed(card)
+{
+ var i;
+
+ $("chooseed").style.visibility = "visible";
+ for (i = 0 ; i < 4 ; i++) {
+ $("seed"+i).src = "img/"+i+""+card+".png";
+ seed=$("seed"+i);
+ eval("seed.onclick = function () { act_choose("+i+""+card+"); };");
+ }
+}
+
+function set_names(so,ea,ne,nw,we)
+{
+// alert("EA: "+ea);
+ $("name").innerHTML = so;
+ $("name_ea").innerHTML = ea;
+ $("name_ne").innerHTML = ne;
+ $("name_nw").innerHTML = nw;
+ $("name_we").innerHTML = we;
+ return;
+}
+
+var astat_suffix = new Array("","_ea","_ne","_nw","_we");
+
+function show_astat(zer,uno,due,tre,qua)
+{
+ var astat = new Array(zer,uno,due,tre,qua);
+
+ for (i = 0 ; i < PLAYERS_N ; i++) {
+ idx = (PLAYERS_N + i - table_pos) % PLAYERS_N;
+
+ if (astat[i] == -2) {
+ $("public"+astat_suffix[idx]).style.visibility = "hidden";
+ }
+ else if (astat[i] == -1) {
+ $("public"+astat_suffix[idx]).style.visibility = "visible";
+ $("pubacard"+astat_suffix[idx]).src = "img/astapasso.png";
+ $("pubapnt"+astat_suffix[idx]).innerHTML = "";
+ $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
+ }
+ else if (astat[i] <= 10) {
+ $("public"+astat_suffix[idx]).style.visibility = "visible";
+ $("pubacard"+astat_suffix[idx]).src = "img/asta"+astat[i]+".png";
+ $("pubapnt"+astat_suffix[idx]).style.visibility = "hidden";
+ }
+ else if (astat[i] <= 120) {
+ $("public"+astat_suffix[idx]).style.visibility = "visible";
+ $("pubacard"+astat_suffix[idx]).src = "img/asta9.png";
+ $("pubapnt"+astat_suffix[idx]).style.visibility = "inherit"; // XXX VISIBLE
+ $("pubapnt"+astat_suffix[idx]).innerHTML = astat[i];
+ }
+ }
+}
+
+var fin = 0;
+
+function table_init() {
+ var sux = new Array("", "_ea", "_ne", "_nw", "_we");
+
+ remark_off();
+
+ $("asta").style.visibility = "hidden";
+ $("caller").style.visibility = "hidden";
+ show_astat(-2,-2,-2,-2,-2);
+
+ for (i=0 ; i < 8 ; i++) {
+ Drag.init($("card" + i), card_mouseup_cb);
+ for (e = 0 ; e < PLAYERS_N ; e++)
+ $("card"+sux[e]+i).style.visibility = "hidden";
+ }
+ for (i=0 ; i < PLAYERS_N ; i++) {
+ $("takes"+sux[i]).style.visibility = "hidden";
+ }
+
+ for (i = 0 ; i < 8 ; i++) {
+ cards_pos[i] = i;
+ cards_ea_pos[i] = i;
+ cards_ne_pos[i] = i;
+ cards_nw_pos[i] = i;
+ cards_we_pos[i] = i;
+ }
+
+}
+
+
+
+var chatt_lines = new Array();
+var chatt_lines_n = 0;
+
+/* PRO CHATT */
+function chatt_sub(name,str)
+{
+ // alert("ARRIVA NAME: "+ name + " STR:"+str);
+ if (chatt_lines_n == 20) {
+ $("txt").innerHTML = "";
+ for (i = 0 ; i < 19 ; i++) {
+ chatt_lines[i] = chatt_lines[i+1];
+ $("txt").innerHTML += chatt_lines[i];
+ }
+ chatt_lines[i] = "<b>"+name+"</b> "+str+ "<br>";
+ $("txt").innerHTML += chatt_lines[i];
+ }
+ else {
+ chatt_lines[chatt_lines_n] = "<b>"+name+"</b> "+str+ "<br>";
+ $("txt").innerHTML += chatt_lines[chatt_lines_n];
+ chatt_lines_n++;
+ }
+ $("txt").innerHTML;
+ $("txt").scrollTop = 10000000;
+}
+
+/*
+ * GESTIONE DEI COOKIES
+ */
+function createCookie(name,value,hours,path) {
+ if (hours) {
+ var date = new Date();
+ date.setTime(date.getTime()+(hours*60*60*1000));
+ var expires = "; expires="+date.toGMTString();
+ }
+ else var expires = "";
+ document.cookie = name+"="+value+expires+"; path="+path;
+}
+
+function readCookie(name) {
+ var nameEQ = name + "=";
+ var ca = document.cookie.split(';');
+ for(var i=0;i < ca.length;i++) {
+ var c = ca[i];
+ while (c.charAt(0)==' ') c = c.substring(1,c.length);
+ if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
+ }
+ return null;
+}
+
+function eraseCookie(name) {
+ createCookie(name,"",-1);
+}
+
+
+/*
+window.onload = function() {
+ $("log").innerHTML += " xxxxxxxxxxxxxxxxxxxxxONLOAD<br>";
+
+ // $("imm2").style.left = 600;
+ // $("imm2").style.top = 400;
+ var zigu = new slowimg($("imm"),300,100,15,"fin");
+ zigu.settime(1000);
+ zigu.start();
+ // setTimeout(function() { alert("FIN:" + fin); }, 5000);
+}
+*/
--- /dev/null
+/*
+ * brisk - dnd.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.
+ *
+ */
+
+body {
+/* background-image: url('img/probrisco.jpg'); */
+ background-repeat: no-repeat;
+ }
+
+
+img {
+ position: absolute;
+ border-style: solid;
+ border-width: 1px;
+ border-color: grey;
+ }
+
+img.card {
+ position: absolute;
+ border-style: solid;
+ border-width: 1px;
+ border-color: grey;
+ visibility: hidden;
+ left: 100;
+ top: 200;
+ }
+
+img.cover {
+ position: absolute;
+ border-style: solid;
+ border-width: 1px;
+ border-color: lightgrey;
+ visibility: hidden;
+ }
+
+
+.area {
+ position:absolute;
+ width: 800px;
+ height: 600px;
+ }
+
+.proxhr {
+ background-color: green;
+ }
+
+.superfront {
+ z-index: 20;
+ }
\ No newline at end of file
--- /dev/null
+/*
+ * brisk - dnd.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.
+ *
+ */
+
+var PLAYERS_N = 3;
+/* current manche */
+var manche = 1;
+/* cards on hands */
+var cards_n;
+/* is my time */
+var is_my_time = false;
+/* number of takes cards */
+var takes_n;
+
+var cards_ea_n;
+var takes_ea_n;
+
+var cards_ne_n;
+var takes_ne_n;
+
+var cards_nw_n;
+var takes_nw_n;
+
+var cards_we_n;
+var takes_we_n;
+
+/* width of images */
+var cards_width = 55 + 2;
+var cards_width_d2 = 27;
+
+/* height of images */
+var cards_height = 101 + 2;
+var cards_height_d2 = 51;
+
+/* width of hands area */
+var hands_width = 400;
+
+/* width of the border */
+var border_width = 10;
+
+/* time to send a card to the player 10 or 250 */
+var G_send_time = 250;
+
+/* suffix to add to images name */
+var sux = new Array( "", "_ea", "", "", "_we");
+
+var cards_pos = new Array (8);
+var cards_ea_pos = new Array (8);
+var cards_ne_pos = new Array (8);
+var cards_nw_pos = new Array (8);
+var cards_we_pos = new Array (8);
+
+var take_x = new Array(562, 745, 452, 30, 52);
+var take_y = new Array(545, 177, 70, 62,155);
+
+for (i = 0 ; i < 8 ; i++) {
+ cards_pos[i] = i;
+ cards_ea_pos[i] = i;
+ cards_ne_pos[i] = i;
+ cards_nw_pos[i] = i;
+ cards_we_pos[i] = i;
+}
+function $(id) { return document.getElementById(id); }
+
+function cards_dispose_so(car_n, tak_n)
+{
+ if (tak_n > 0) {
+ delta = 80;
+ $("takes").style.left = 200 + 400 - 90 + ((90 - cards_width) / 2);
+ $("takes").style.top = 475 + (125 - cards_height)/2;
+ $("takes").style.zIndex = 1;
+ $("takes").style.visibility = "visible";
+ }
+ else
+ delta = 0;
+
+
+ disp = 400 - delta - (2 * border_width);
+ if (car_n > 1) {
+ inter = parseInt((disp - cards_width) / (car_n - 1));
+ if (inter > cards_width)
+ inter = cards_width;
+ }
+ else
+ inter = 0;
+ wcard = cards_width + inter * (car_n - 1);
+ start = 200 + border_width + (400 - border_width - border_width - wcard - delta) / 2;
+
+ for (i = 0 ; i < car_n ; i++) {
+ $("card" + cards_pos[i]).style.left = start + (i * inter);
+ $("card" + cards_pos[i]).style.top = 475 + (125 - cards_height)/2;
+ $("card" + cards_pos[i]).style.zIndex = 8 - i;
+ $("card" + cards_pos[i]).style.visibility = "visible";
+ }
+
+ cards_n = car_n;
+ takes_n = tak_n;
+
+ return (0);
+}
+
+function cards_dispose_ne(car_n, tak_n) {
+ // tak_n = 2;
+
+ if (tak_n > 0) {
+ delta = 80;
+ $("takes_ne").style.left = 800 - cards_width - 400 + 90 - ((90 - cards_width) / 2);
+ $("takes_ne").style.top = (125 - cards_height)/2;
+ $("takes_ne").style.zIndex = 1;
+ $("takes_ne").style.visibility = "visible";
+ }
+ else
+ delta = 0;
+
+
+ disp = 400 - delta - (2 * border_width);
+ if (car_n > 1) {
+ inter = parseInt((disp - cards_width) / (car_n - 1));
+ if (inter > cards_width)
+ inter = cards_width;
+ }
+ else
+ inter = 0;
+ wcard = cards_width + inter * (car_n - 1);
+ start = 800 - cards_width - border_width - (400 - border_width - border_width - wcard - delta) / 2;
+
+ list = "LIST: ";
+ for (i = 0 ; i < car_n ; i++) {
+ $("card_ne" + cards_ne_pos[i]).style.left = start - ((car_n - i -1) * inter);
+ $("card_ne" + cards_ne_pos[i]).style.top = (125 - cards_height)/2;
+ $("card_ne" + cards_ne_pos[i]).style.zIndex = 8-i;
+ $("card_ne" + cards_ne_pos[i]).style.visibility = "visible";
+ }
+
+ cards_ne_n = car_n;
+ takes_ne_n = tak_n;
+
+ return (0);
+}
+
+function cards_dispose_nw(car_n, tak_n) {
+ // tak_n = 2;
+
+ if (tak_n > 0) {
+ delta = 80;
+ $("takes_nw").style.left = 400 - cards_width - 400 + 90 - ((90 - cards_width) / 2);
+ $("takes_nw").style.top = (125 - cards_height)/2;
+ $("takes_nw").style.zIndex = 1;
+ $("takes_nw").style.visibility = "visible";
+ }
+ else
+ delta = 0;
+
+
+ disp = 400 - delta - (2 * border_width);
+ if (car_n > 1) {
+ inter = parseInt((disp - cards_width) / (car_n - 1));
+ if (inter > cards_width)
+ inter = cards_width;
+ }
+ else
+ inter = 0;
+ wcard = cards_width + inter * (car_n - 1);
+ // start = 0 + delta + border_width + (400 - border_width - border_width - wcard - delta) / 2;
+ start = 400 - cards_width - border_width - (400 - border_width - border_width - wcard - delta) / 2;
+
+ list = "LIST: ";
+ for (i = 0 ; i < car_n ; i++) {
+ $("card_nw" + cards_nw_pos[i]).style.left = start - ((car_n-i-1) * inter);
+ $("card_nw" + cards_nw_pos[i]).style.top = (125 - cards_height)/2;
+ $("card_nw" + cards_nw_pos[i]).style.zIndex = (8-i);
+ $("card_nw" + cards_nw_pos[i]).style.visibility = "visible";
+ // alert("xx "+start + (i * inter)+" yy " + (125 - cards_height)/2);
+ }
+
+ cards_nw_n = car_n;
+ takes_nw_n = tak_n;
+
+ return (0);
+}
+
+function cards_dispose_ea(car_n, tak_n) {
+ if (tak_n > 0) {
+ delta = 80;
+ $("takes_ea").style.left = 675 + (125 - cards_height)/2;
+ $("takes_ea").style.top = 125 + ((90 - cards_width) / 2);
+ $("takes_ea").style.zIndex = 1;
+ $("takes_ea").style.visibility = "visible";
+ }
+ else
+ delta = 0;
+
+ disp = 400 - delta - (2 * border_width);
+ if (car_n > 1) {
+ inter = parseInt((disp - cards_width) / (car_n - 1));
+ if (inter > cards_width)
+ inter = cards_width;
+ }
+ else
+ inter = 0;
+ wcard = cards_width + inter * (car_n - 1);
+ start = 125 + delta + border_width + (400 - border_width - border_width - wcard - delta) / 2;
+
+ list = "LIST: ";
+ for (i = 0 ; i < car_n ; i++) {
+ $("card_ea" + cards_ea_pos[i]).style.left = 675 + (125 - cards_height)/2;
+ $("card_ea" + cards_ea_pos[i]).style.top = start + (i * inter);
+ $("card_ea" + cards_ea_pos[i]).style.zIndex = 8 - i;
+ $("card_ea" + cards_ea_pos[i]).style.visibility = "visible";
+ // alert("xx "+ (675 + (125 - cards_height)/2) +" yy " + start + (i * inter));
+ }
+
+ cards_ea_n = car_n;
+ takes_ea_n = tak_n;
+
+ return (0);
+}
+
+function cards_dispose_we(car_n, tak_n)
+{
+ if (tak_n > 0) {
+ delta = 80;
+ $("takes_we").style.left = (125 - cards_height)/2;
+ // $("takes_we").style.top = 125 + 400 - 90 + ((90 - cards_width) / 2);
+ $("takes_we").style.top = 525 - cards_width - 400 + 90 - ((90 - cards_width) / 2);
+ $("takes_we").style.zIndex = 1;
+ $("takes_we").style.visibility = "visible";
+ }
+ else
+ delta = 0;
+
+ /* pixel a disposizione per mettere le carte: 400 - delta - 2 bordi */
+ disp = 400 - delta - (2 * border_width);
+ /* se c'e' piu' di una carta calcola di quanti pixel devono rimanere scoperte le carte dopo la prima */
+ if (car_n > 1) {
+ inter = parseInt((disp - cards_width) / (car_n - 1));
+ if (inter > cards_width)
+ inter = cards_width;
+ }
+ else
+ inter = 0;
+
+ /* dopo avere fatto tutti i conti ricalcola quanti pixel effettivamente verranno occupati dalle carte */
+ wcard = cards_width + inter * (car_n - 1);
+
+ /* calcola il punto d'inizio da dove disporre le carte: DELTAY + lo spessore del bordo + la meta' di quello
+ che resta della larghezza totale meno tutti gli altri ingombri */
+ // start = 125 + border_width + (400 - border_width - border_width - wcard - delta) / 2;
+ start = 525 - cards_width - border_width - (400 - border_width - border_width - wcard - delta) / 2;
+
+ for (i = 0 ; i < car_n ; i++) {
+ $("card_we" + cards_we_pos[i]).style.left = (125 - cards_height)/2;
+ $("card_we" + cards_we_pos[i]).style.top = start - (i * inter);
+ $("card_we" + cards_we_pos[i]).style.zIndex = 8 - i;
+ $("card_we" + cards_we_pos[i]).style.visibility = "visible";
+ }
+
+ cards_we_n = car_n;
+ takes_we_n = tak_n;
+
+ return (0);
+}
+
+var cards_dispose_arr = new Array(cards_dispose_so, cards_dispose_ea,
+ cards_dispose_ne, cards_dispose_nw,
+ cards_dispose_we);
+
+function cards_dispose(player_pos, cards, takes)
+{
+ var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
+
+ return (cards_dispose_arr[idx](cards,takes));
+}
+
+
+
+
+function card_mouseup_cb(o) {
+ var idx = o.id.substring(4);
+ var briskid = o.briskid;
+ var delta, disp;
+ var wcard;
+ var start;
+ var old_idx;
+ var tst;
+ /* case swap in the group */
+
+ // alert("mouseup");
+ if (parseInt(o.style.top) > 475 &&
+ parseInt(o.style.left) >= 200 && parseInt(o.style.left) < 600) {
+ /* Rearrange cards */
+
+ // $("sandbox3").innerHTML = "REARRANGE: "+idx;
+
+ if (takes_n > 0)
+ delta = 80;
+ else
+ delta = 0;
+
+ /* found the associated index of the current card. */
+ for (i = 0 ; i < cards_n ; i++)
+ if (cards_pos[i] == idx)
+ break;
+ old_idx = i;
+
+ disp = 400 - delta - (2 * border_width);
+ if (cards_n > 1) {
+ inter = parseInt((disp - cards_width) / (cards_n - 1));
+ if (inter > cards_width)
+ inter = cards_width;
+ }
+ else
+ inter = 0;
+ wcard = cards_width + inter * (cards_n - 1);
+ start = 200 + border_width + (400 - border_width - border_width - wcard - delta) / 2;
+
+ for (i = 0 ; i < cards_n ; i++) {
+ /* $("sandbox").innerHTML = */
+ // alert( "LEFT: " + o.style.left + "VALUE " + (cards_width + start + (i * (cards_width / 2))));
+ // $("sandbox3").innerHTML += "<br>LEFT: "+parseInt(o.style.left)+" START["+i+"]: "+(start + ((i+1) * inter));
+ if (i < cards_n - 1)
+ tst = (parseInt(o.style.left) < start + ((i+1) * inter));
+ else
+ tst = (parseInt(o.style.left) > start + (i * inter));
+ if (tst) {
+ // $("sandbox2").innerHTML = "old: " +old_idx+ " i: " +i+ "left: " + parseInt(o.style.left) + "comp: " + (start + (cards_width / 2) + (i * (cards_width / 2)));
+
+ if (i == old_idx)
+ break;
+ if (i > old_idx) {
+ /* moved to right */
+ for (e = old_idx ; e < i ; e++)
+ cards_pos[e] = cards_pos[e+1];
+ }
+ if (i < old_idx) {
+ /* moved to left */
+ for (e = old_idx ; e > i ; e--)
+ cards_pos[e] = cards_pos[e-1];
+ }
+ cards_pos[i] = idx;
+ break;
+ }
+ }
+
+ cards_dispose_so(cards_n,takes_n);
+
+ return (0);
+ }
+ else if (is_my_time &&
+ parseInt(o.style.top) >= 250 &&
+ parseInt(o.style.top) + cards_height < 450 &&
+ parseInt(o.style.left) >= 300 &&
+ (parseInt(o.style.left) + cards_width) < 500) {
+ /* Played card */
+
+ $("sandbox2").innerHTML = "PLAYED";
+
+ for (i = 0 ; i < cards_n ; i++) {
+ if (cards_pos[i] == idx) {
+ $("sandbox").innerHTML = "Pippo: "+ i;
+ for (e = i ; e < cards_n-1 ; e++) {
+ cards_pos[e] = cards_pos[e+1];
+ }
+ cards_pos[cards_n-1] = idx;
+ cards_n--;
+ cards_dispose_so(cards_n, takes_n);
+
+ is_my_time = false;
+ act_play(briskid,o.style.left,o.style.top);
+ return (1);
+ }
+ }
+ cards_dispose_so(cards_n, takes_n);
+
+ return (0);
+ }
+ else {
+ $("sandbox2").innerHTML = "TO ORIGINAL";
+ /* alert("out card " + parseInt(o.style.top)); */
+ /* return to the original position */
+ cards_dispose_so(cards_n, takes_n);
+
+ return (0);
+ }
+}
+
+/* CARD_SEND */
+function card_send_so(id,card,free,ct)
+{
+ var img = $("card"+id);
+ img.src = getcard(-1,0);
+ img.briskid = card;
+
+ img.style.left = 400 - cards_width_d2;
+ img.style.top = 300 - cards_height_d2;
+ img.style.zIndex = 100;
+
+ var movimg = new slowimg(img,400 - cards_width / 2,475 + (125 - cards_height)/2,25,free,"cards_dispose_so("+ct+", 0)",getcard(card,0));
+ movimg.settime(G_send_time);
+ movimg.start(gst);
+}
+
+function card_send_ea(id,card,free,ct)
+{
+ var img = $("card_ea"+id);
+ img.src = getcard(card,1);
+ img.briskid = card;
+
+ img.style.left = 400 - cards_height_d2;
+ img.style.top = 300 - cards_width_d2;
+ img.style.zIndex = 100;
+
+ var movimg = new slowimg(img,686,296,25,free,"cards_dispose_ea("+ct+", 0);",getcard(card,1));
+ movimg.settime(G_send_time);
+ movimg.start(gst);
+}
+
+function card_send_ne(id,card,free,ct)
+{
+ var img = $("card_ne"+id);
+ img.src = getcard(card,2);
+ img.briskid = card;
+
+ img.style.left = 400 - cards_width_d2;
+ img.style.top = 300 - cards_height_d2;
+ img.style.zIndex = 100;
+
+ var movimg = new slowimg(img,571,11,25,free,"cards_dispose_ne("+ct+", 0);",getcard(card,2));
+ movimg.settime(G_send_time);
+ movimg.start(gst);
+}
+
+function card_send_nw(id,card,free,ct)
+{
+ var img = $("card_nw"+id);
+ img.src = getcard(card,3);
+ img.briskid = card;
+
+ img.style.left = 400 - cards_width_d2;
+ img.style.top = 300 - cards_height_d2;
+ img.style.zIndex = 100;
+
+ var movimg = new slowimg(img,171,11,25,free,"cards_dispose_nw("+ct+", 0);",getcard(card,3));
+ movimg.settime(G_send_time);
+ movimg.start(gst);
+}
+
+function card_send_we(id,card,free,ct)
+{
+ var img = $("card_we"+id);
+ img.src = getcard(card,4);
+ img.briskid = card;
+
+ if (id < 0 || id > 39)
+ alert("ID ERRATO"+id);
+
+ img.style.left = 400 - cards_height_d2;
+ img.style.top = 300 - cards_width_d2;
+ img.style.zIndex = 100;
+ var movimg = new slowimg(img,11,296,25,free,"cards_dispose_we("+ct+", 0);",getcard(card,4));
+ movimg.settime(G_send_time);
+ movimg.start(gst);
+}
+
+var card_send_arr = new Array(card_send_so, card_send_ea,
+ card_send_ne, card_send_nw,
+ card_send_we);
+
+function card_send(player_pos,id,card,free,ct)
+{
+ var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
+
+ card_send_arr[idx](id,card,free,ct);
+}
+
+function getcard(card,pos_id)
+{
+ if (card < 0)
+ return ("img/cover"+sux[pos_id]+".png");
+ else if (card < 10)
+ return ("img/0"+card+sux[pos_id]+".png");
+ else
+ return ("img/"+card+sux[pos_id]+".png");
+}
+
+function card_setours(zer,uno,due,tre,qua,cin,sei,set)
+{
+ var i;
+ var arg = new Array(zer,uno,due,tre,qua,cin,sei,set);
+
+ for (i = 0 ; i < 8 ; i++) {
+ $("card"+i).src = getcard(arg[i], 0);
+ $("card"+i).briskid = arg[i];
+ }
+}
+
+/* CARD_PLAY_SO */
+
+function card_play_so(card_idx, x, y)
+{
+ alert("card_play_so: unreachable function.");
+}
+function card_play_ne(card_idx, x, y)
+{
+ // alert("card_play_nw: card_pos="+ card_pos+" card_idx="+card_idx+" x="+x+" y="+y);
+}
+
+/* CARD_PLAY_EA */
+function card_postplay_ea(card_pos)
+{
+ var img = $("card_ea"+card_pos);
+
+ img.className = "";
+ for (i = 0 ; i < cards_ea_n ; i++) {
+ if (cards_ea_pos[i] == card_pos) {
+ for (e = i ; e < cards_ea_n-1 ; e++) {
+ cards_ea_pos[e] = cards_ea_pos[e+1];
+ }
+ cards_ea_pos[cards_ea_n-1] = card_pos;
+ cards_ea_n--;
+ cards_dispose_ea(cards_ea_n, takes_ea_n);
+ break;
+ }
+ }
+}
+
+function card_play_ea(card_idx, x, y)
+{
+ // var card_pos = RANGE 0 <= x < cards_ea_n
+ var card_pos = rnd_int(0,cards_ea_n-1);
+ var img = $("card_ea"+cards_ea_pos[card_pos]);
+ // alert("IMMO CON "+cards_ea_pos[card_pos]);
+ var newname = getcard(card_idx,1);
+ var x1, y1;
+
+ x1 = 500 + ((y-250) * (125 - cards_height) / (200 - cards_height));
+ y1 = 450 - cards_width - (x - 300);
+
+ var movimg = new slowimg(img, x1, y1, 1, 1, "card_postplay_ea("+cards_ea_pos[card_pos]+");", newname);
+ movimg.settime(50);
+ movimg.start(gst);
+}
+
+/* CARD_PLAY_NE */
+function card_postplay_ne(card_pos)
+{
+ var img = $("card_ne"+card_pos);
+
+ img.className = "";
+ for (i = 0 ; i < cards_ne_n ; i++) {
+ if (cards_ne_pos[i] == card_pos) {
+ for (e = i ; e < cards_ne_n-1 ; e++) {
+ cards_ne_pos[e] = cards_ne_pos[e+1];
+ }
+ cards_ne_pos[cards_ne_n-1] = card_pos;
+ cards_ne_n--;
+ cards_dispose_ne(cards_ne_n, takes_ne_n);
+ break;
+ }
+ }
+}
+
+function card_play_ne(card_idx, x, y)
+{
+ var card_pos = rnd_int(0,cards_ne_n-1);
+ var img = $("card_ne"+cards_ne_pos[card_pos]);
+ var newname = getcard(card_idx,2);
+ var x1, y1;
+
+ x1 = 600 - cards_width - (x - 300);
+ y1 = 250 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
+
+ var movimg = new slowimg(img, x1, y1, 1, 1, "card_postplay_ne("+cards_ne_pos[card_pos]+");", newname);
+ movimg.settime(50);
+ movimg.start(gst);
+}
+
+/* CARD_PLAY_NW */
+function card_postplay_nw(card_pos)
+{
+ var img = $("card_nw"+card_pos);
+
+ img.className = "";
+ for (i = 0 ; i < cards_nw_n ; i++) {
+ if (cards_nw_pos[i] == card_pos) {
+ for (e = i ; e < cards_nw_n-1 ; e++) {
+ cards_nw_pos[e] = cards_nw_pos[e+1];
+ }
+ cards_nw_pos[cards_nw_n-1] = card_pos;
+ cards_nw_n--;
+ cards_dispose_nw(cards_nw_n, takes_nw_n);
+ break;
+ }
+ }
+}
+
+function card_play_nw(card_idx, x, y)
+{
+ var card_pos = rnd_int(0,cards_nw_n-1);
+ var img = $("card_nw"+cards_nw_pos[card_pos]);
+ var newname = getcard(card_idx,3);
+ var x1, y1;
+
+ x1 = 400 - cards_width - (x - 300);
+ y1 = 250 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
+
+ var movimg = new slowimg(img, x1, y1, 1, 1, "card_postplay_nw("+cards_nw_pos[card_pos]+");", newname);
+ movimg.settime(50);
+ movimg.start(gst);
+}
+
+/* CARD_PLAY_WE */
+function card_postplay_we(card_pos)
+{
+ var img = $("card_we"+card_pos);
+
+ img.className = "";
+ for (i = 0 ; i < cards_we_n ; i++) {
+ if (cards_we_pos[i] == card_pos) {
+ for (e = i ; e < cards_we_n-1 ; e++) {
+ cards_we_pos[e] = cards_we_pos[e+1];
+ }
+ cards_we_pos[cards_we_n-1] = card_pos;
+ cards_we_n--;
+ cards_dispose_we(cards_we_n, takes_we_n);
+ break;
+ }
+ }
+}
+
+function card_play_we(card_idx, x, y)
+{
+ var card_pos = rnd_int(0,cards_we_n-1);
+ var img = $("card_we"+cards_we_pos[card_pos]);
+ var newname = getcard(card_idx,4);
+ var x1, y1;
+
+ x1 = 300 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
+ y1 = 250 + x - 300;
+
+ var movimg = new slowimg(img, x1, y1, 1, 1, "card_postplay_we("+cards_we_pos[card_pos]+");", newname);
+ movimg.settime(50);
+ movimg.start(gst);
+}
+
+var card_play_arr = new Array( card_play_so, card_play_ea, card_play_ne, card_play_nw, card_play_we);
+
+/* card_play(player_pos, card_pos, card_idx, x, y)
+ player_pos - position of the player on the table
+ card_pos - position of the card in the hand of the player
+ card_idx - id of the card (to show it after the move)
+ x, y - coordinates of the card on the original table
+
+ orig 200x200 dest 200x125
+*/
+function card_play(player_pos, card_idx, x, y)
+{
+ var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
+
+ card_play_arr[idx](card_idx, x, y);
+}
+
+
+/* CARD_PLACE_SO */
+function card_place_so(card_pos, card_idx, x, y)
+{
+ var img = $("card"+card_pos);
+
+ // alert("card_place_so"+card_pos);
+
+ img.style.left = x;
+ img.style.top = y;
+ img.style.visibility = "visible";
+ img.src = getcard(card_idx,0);
+}
+
+/* CARD_PLACE_EA */
+function card_place_ea(card_pos, card_idx, x, y)
+{
+ var img = $("card_ea"+card_pos);
+
+ // alert("card_place_ea");
+
+ img.style.left = 500 + ((y-250) * (125 - cards_height) / (200 - cards_height));
+ img.style.top = 450 - cards_width - (x - 300);
+ img.style.visibility = "visible";
+ img.src = getcard(card_idx,1);
+}
+
+/* CARD_PLACE_NE */
+function card_place_ne(card_pos, card_idx, x, y)
+{
+ var img = $("card_ne"+card_pos);
+
+ // alert("card_place_ne");
+
+ img.style.left = 600 - cards_width - (x - 300);
+ img.style.top = 250 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
+ img.style.visibility = "visible";
+ img.src = getcard(card_idx,2);
+}
+
+/* CARD_PLACE_NW */
+function card_place_nw(card_pos, card_idx, x, y)
+{
+ var img = $("card_nw"+card_pos);
+
+ // alert("card_place_nw");
+
+ img.style.left = 400 - cards_width - (x - 300);
+ img.style.top = 250 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
+ img.style.visibility = "visible";
+ img.src = getcard(card_idx,3);
+}
+
+/* CARD_PLACE_WE */
+function card_place_we(card_pos, card_idx, x, y)
+{
+ var img = $("card_we"+card_pos);
+
+ // alert("card_place_we");
+
+ img.style.left = 300 - cards_height - ((y-250) * (125 - cards_height) / (200 - cards_height));
+ img.style.top = 250 + x - 300;
+ img.style.visibility = "visible";
+ img.src = getcard(card_idx,4);
+}
+
+var card_place_arr = new Array( card_place_so, card_place_ea, card_place_ne, card_place_nw, card_place_we );
+
+/* CARD_PLACE */
+function card_place(player_pos, card_pos, card_idx, x, y)
+{
+ var idx = (player_pos - table_pos + PLAYERS_N) % PLAYERS_N;
+
+ // alert("card_place"+idx);
+
+ card_place_arr[idx](card_pos, card_idx, x, y);
+}
+
+
+
+function card_post_take(card)
+{
+ var img = $("card"+card);
+ img.style.visibility = "hidden";
+ cards_dispose_so(cards_n, takes_n);
+}
+
+function card_ea_post_take(card)
+{
+ var img = $("card_ea"+card);
+ img.style.visibility = "hidden";
+ cards_dispose_ea(cards_ea_n, takes_ea_n);
+}
+
+function card_ne_post_take(card)
+{
+ var img = $("card_ne"+card);
+ img.style.visibility = "hidden";
+ cards_dispose_ne(cards_ne_n, takes_ne_n);
+}
+
+function card_nw_post_take(card)
+{
+ var img = $("card_nw"+card);
+ img.style.visibility = "hidden";
+ cards_dispose_nw(cards_nw_n, takes_nw_n);
+}
+
+function card_we_post_take(card)
+{
+ var img = $("card_we"+card);
+ img.style.visibility = "hidden";
+ cards_dispose_we(cards_we_n, takes_we_n);
+}
+
+
+function cards_take(win)
+{
+
+
+ var taker = (win - table_pos + PLAYERS_N) % PLAYERS_N;
+
+ // alert("cards_n: "+cards_n+"card: "+cards_pos[cards_n]+"cards_ea_n: "+cards_ea_n+"card_ea: "+cards_ea_pos[cards_ea_n]+"cards_ne_n: "+cards_ne_n+"card_ne: "+cards_ne_pos[cards_ne_n] + "taker:"+taker);
+
+ switch(taker) {
+ case 0:
+ takes_n += PLAYERS_N; break;
+ case 1:
+ takes_ea_n += PLAYERS_N; break;
+ case 2:
+ takes_ne_n += PLAYERS_N; break;
+ case 3:
+ takes_nw_n += PLAYERS_N; break;
+ case 4:
+ takes_we_n += PLAYERS_N; break;
+ default:
+ break;
+ }
+
+ var img = $("card"+cards_pos[cards_n]);
+ var movimg = new slowimg(img,
+ take_x[taker] - cards_width_d2,
+ take_y[taker] - cards_height_d2,
+ 1, 0, "card_post_take("+cards_pos[cards_n]+");", null);
+ movimg.settime(50);
+ movimg.start(gst);
+
+ var img = $("card_ea"+cards_ea_pos[cards_ea_n]);
+ var movimg = new slowimg(img,
+ take_x[taker] - cards_height_d2,
+ take_y[taker] - cards_width_d2,
+ 1, 0, "card_ea_post_take("+cards_ea_pos[cards_ea_n]+");", null);
+ movimg.settime(50);
+ movimg.start(gst);
+
+ var img = $("card_ne"+cards_ne_pos[cards_ne_n]);
+ var movimg = new slowimg(img,
+ take_x[taker] - cards_width_d2,
+ take_y[taker] - cards_height_d2,
+ 1, (PLAYERS_N == 3 ? 1 : 0), "card_ne_post_take("+cards_ne_pos[cards_ne_n]+");", null);
+ movimg.settime(50);
+ movimg.start(gst);
+ if (PLAYERS_N > 3) {
+ var img = $("card_nw"+cards_nw_pos[cards_nw_n]);
+ var movimg = new slowimg(img,
+ take_x[taker] - cards_width_d2,
+ take_y[taker] - cards_height_d2,
+ 1, 0, "card_nw_post_take("+cards_nw_pos[cards_nw_n]+");", null);
+ movimg.settime(50);
+ movimg.start(gst);
+
+ var img = $("card_we"+cards_we_pos[cards_we_n]);
+ var movimg = new slowimg(img,
+ take_x[taker] - cards_height_d2,
+ take_y[taker] - cards_width_d2,
+ 1, 1, "card_we_post_take("+cards_we_pos[cards_we_n]+");", null);
+ movimg.settime(50);
+ movimg.start(gst);
+ }
+}
+
+function cards_hidetake(win)
+{
+
+
+
+
+}
+/*
+ window.onload = function() {
+ $("log").innerHTML += " xxxxxxxxxxxxxxxxxxxxxONLOAD<br>"; 53;
+
+
+ // $("imm2").style.left = 600;
+ // $("imm2").style.top = 400;
+ var zigu = new slowimg($("imm"),300,100,15,"fin");
+ zigu.settime(1000);
+ zigu.start();
+ // setTimeout(function() { alert("FIN:" + fin); }, 5000);
+ }
+*/
+
+
+
+/*
+ window.onload = function() {
+ //
+ var greet = document.createElement("span");
+ greet.style.backgroundColor = "yellow";
+ greet.innerHTML = "Hello World!";
+ $("sandbox").appendChild(greet);
+ //
+ cards_dispose_so();
+
+ for (i=0 ; i < 8 ; i++) {
+ Drag.init($("card" + i), card_mouseup_cb);
+ }
+ }
+*/
--- /dev/null
+/*\r
+ * brisk - dom-drag.js\r
+ *\r
+ * Copyright (C) 2006 matteo.nastasi@milug.org\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * General Public License for more details. You should have received a\r
+ * copy of the GNU General Public License along with this program; if\r
+ * not, write to the Free Software Foundation, Inc, 59 Temple Place -\r
+ * Suite 330, Boston, MA 02111-1307, USA.\r
+ *\r
+ */\r
+\r
+/**************************************************\r
+ * dom-drag.js\r
+ * 09.25.2001\r
+ * www.youngpup.net\r
+ **************************************************\r
+ * 10.28.2001 - fixed minor bug where events\r
+ * sometimes fired off the handle, not the root.\r
+ **************************************************/\r
+\r
+var Drag = {\r
+\r
+ obj : null,\r
+\r
+ init : function(o, mouseup_cb, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)\r
+ {\r
+ o.onmousedown = Drag.start;\r
+ o.mouseup_cb = mouseup_cb;\r
+\r
+ /* alert("agnulla"+o.style.left); */\r
+\r
+ o.hmode = bSwapHorzRef ? false : true ;\r
+ o.vmode = bSwapVertRef ? false : true ;\r
+\r
+ o.root = oRoot && oRoot != null ? oRoot : o ;\r
+\r
+ if (o.hmode && isNaN(parseInt(o.root.style.left ))) {\r
+ o.root.style.left = window.getComputedStyle(o, "").getPropertyValue("left");\r
+ if (isNaN(parseInt(o.root.style.left)))\r
+ o.root.style.left = "0px";\r
+ }\r
+ if (o.vmode && isNaN(parseInt(o.root.style.top ))) {\r
+ o.root.style.top = window.getComputedStyle(o, "").getPropertyValue("top");\r
+ if (isNaN(parseInt(o.root.style.top)))\r
+ o.root.style.top = "0px";\r
+ }\r
+ if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px";\r
+ if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";\r
+\r
+ o.minX = typeof minX != 'undefined' ? minX : null;\r
+ o.minY = typeof minY != 'undefined' ? minY : null;\r
+ o.maxX = typeof maxX != 'undefined' ? maxX : null;\r
+ o.maxY = typeof maxY != 'undefined' ? maxY : null;\r
+\r
+ o.xMapper = fXMapper ? fXMapper : null;\r
+ o.yMapper = fYMapper ? fYMapper : null;\r
+\r
+ o.root.onDragStart = new Function();\r
+ o.root.onDragEnd = new Function();\r
+ o.root.onDrag = new Function();\r
+ },\r
+\r
+ start : function(e)\r
+ {\r
+ var o = Drag.obj = this;\r
+ e = Drag.fixE(e);\r
+\r
+ o.oldzidx = o.style.zIndex;\r
+ o.style.zIndex = 10;\r
+\r
+ // alert("start");\r
+\r
+ var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);\r
+ var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );\r
+ o.root.onDragStart(x, y);\r
+\r
+ o.lastMouseX = e.clientX;\r
+ o.lastMouseY = e.clientY;\r
+\r
+ if (o.hmode) {\r
+ if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;\r
+ if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;\r
+ } else {\r
+ if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;\r
+ if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;\r
+ }\r
+\r
+ if (o.vmode) {\r
+ if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;\r
+ if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;\r
+ } else {\r
+ if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;\r
+ if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;\r
+ }\r
+\r
+ document.onmousemove = Drag.drag;\r
+ document.onmouseup = Drag.end;\r
+\r
+ return false;\r
+ },\r
+\r
+ drag : function(e)\r
+ {\r
+ e = Drag.fixE(e);\r
+ var o = Drag.obj;\r
+\r
+ var ey = e.clientY;\r
+ var ex = e.clientX;\r
+ var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);\r
+ var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );\r
+ var nx, ny;\r
+\r
+ if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);\r
+ if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);\r
+ if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);\r
+ if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);\r
+\r
+ nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));\r
+ ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));\r
+\r
+ if (o.xMapper) nx = o.xMapper(y)\r
+ else if (o.yMapper) ny = o.yMapper(x)\r
+\r
+ Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";\r
+ Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";\r
+ Drag.obj.lastMouseX = ex;\r
+ Drag.obj.lastMouseY = ey;\r
+\r
+ Drag.obj.root.onDrag(nx, ny);\r
+ return false;\r
+ },\r
+\r
+ end : function(e)\r
+ {\r
+ e = Drag.fixE(e);\r
+ var o = Drag.obj;\r
+\r
+ o.style.zIndex = o.oldzidx;\r
+ // alert("END");\r
+ if (o.mouseup_cb != null) {\r
+ if (o.mouseup_cb(o) == 1) {\r
+ o.onmousedown = null;\r
+ }\r
+ }\r
+\r
+ document.onmousemove = null;\r
+ document.onmouseup = null;\r
+ Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), \r
+ parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));\r
+ Drag.obj = null;\r
+ },\r
+\r
+ fixE : function(e)\r
+ {\r
+ if (typeof e == 'undefined') e = window.event;\r
+ if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;\r
+ if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;\r
+ return e;\r
+ }\r
+};\r
--- /dev/null
+<?php
+/*
+ * brisk - index.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.
+ *
+ */
+
+require_once("brisk.phh");
+if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
+ echo "Debugging time!";
+ exit;
+}
+
+log_load($sess, "LOAD: index.php");
+
+function main()
+{
+ GLOBAL $sess, $name;
+
+ $body = "";
+ $ACTION = "login";
+
+ $is_table = false;
+ $sem = lock_data();
+ $bri = &load_data();
+
+ /* Actions */
+ if (isset($sess)) {
+ $bri->garbage_manager(TRUE);
+ if (($user = &get_user(&$bri, $sess, &$idx)) != FALSE) {
+ if ($user->stat == "table") {
+ header ("Location: table.php");
+ unlock_data($sem);
+ exit;
+ }
+ $ACTION = "table";
+ }
+ else {
+ setcookie ("sess", "", time() - 3600);
+ }
+ }
+ else if (isset($name)) {
+ $bri->garbage_manager(TRUE);
+ /* try login */
+ if (($user = &add_user(&$bri, &$sess, &$idx, $name)) != FALSE) {
+ $ACTION = "table";
+
+ setcookie ("sess", "", time() + 180);
+ standup_update(&$bri,&$user);
+
+ if (save_data(&$bri) == FALSE) {
+ echo "ERRORE SALVATAGGIO\n";
+ exit;
+ }
+ }
+ else {
+ /* Login Rendering */
+ if ($idx == -1)
+ $body .= '<div class="urgmsg"><b>Spiacenti, non ci sono più posti liberi. Riprova più tardi.</b></div>';
+ else
+ $body .= '<div class="urgmsg"><b>Il tuo nickname è già in uso.</b></div>';
+ }
+ }
+ unlock_data($sem);
+
+ /* Rendering. */
+
+ if ($ACTION == "table") {
+ $tables .= '<table align="center" valign="center" border=1 cellpadding="12" cellspacing="0">';
+ for ($i = 0 ; $i < TABLES_N ; $i++) {
+ if ($i % 4 == 0)
+ $tables .= '<tr>';
+ $tables .= '<td valign="top" align="center" class="room_td"><b>Tavolo '.$i.'</b><br><br>';
+ $tables .= sprintf('<div class="proxhr" id="table%d"></div>', $i);
+ $tables .= sprintf('<div class="proxhr" id="table_act%d"></div>', $i);
+ $tables .= '</td>';
+ if ($i % 4 == 3)
+ $tables .= '</tr>';
+ }
+ $tables .= '<tr><td colspan="4">';
+ $tables .= '<div class="room_ex_standup">';
+ $tables .= '<b>Giocatori in piedi</b><br><br>';
+
+ $tables .= sprintf('<div id="standup"></div>');
+ $tables .= '</div>';
+ $tables .= '</td></tr>';
+
+ $tables .= '</table>';
+ }
+
+ /* Templates. */
+ if ($ACTION == 'login') {
+?>
+<html>
+<head>
+<title>Brisk</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>
+<link rel="stylesheet" type="text/css" href="brisk.css">
+</head>
+<body>
+<SCRIPT type="text/javascript">
+ window.onload = function() {
+ $("nameid").focus();
+ }
+</SCRIPT>
+<img class="nobo" src="img/brisk_logo64.png">
+<div style="text-align: center; font-size: 12px;">briscola chiamata in salsa ajax</div>
+<br><br>
+<?php echo "$body"; ?>
+
+<br>
+<div style="text-align: center;">
+Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
+<form method="post" action="">
+<input id="nameid" name="name" type="text" maxlength="12" value="">
+</form>
+</div>
+<br><br>
+<hr>
+<div id="imgct"></div>
+<div id="logz"></div>
+<div id="sandbox"></div>
+<div id="sandbox2"></div>
+<div id="response"></div>
+<div id="xhrstart"></div>
+<pre>
+<div id="xhrlog"></div>
+</pre>
+<div id="xhrdeltalog"></div>
+</body>
+</html>
+<?php
+ }
+ else if ($ACTION == 'table') {
+ ?>
+<html>
+<head>
+<title>Brisk</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>
+<link rel="stylesheet" type="text/css" href="brisk.css">
+</head>
+<body>
+<SCRIPT type="text/javascript">
+ var sess;
+ var stat = "";
+ var subst = "";
+ var gst = new globst();
+
+ var g_imgct= 0;
+ var g_imgtot = g_preload_img_arr.length;
+ var myfrom = "index_php";
+ window.onload = function() {
+ // alert("INDEX START");
+ xhr_rd = createXMLHttpRequest();
+ sess = "<?php echo "$sess"; ?>";
+
+ setTimeout(xhr_rd_poll, 0, sess);
+ // alert("ARR LENGTH "+g_preload_img_arr.length);
+ setTimeout(preload_images, 0, g_preload_img_arr, g_imgct);
+ }
+</SCRIPT>
+<img class="nobo" src="img/brisk_logo64.png">
+<div style="text-align: center; font-size: 12px;">briscola chiamata in salsa ajax</div><br>
+<!-- <div><input name="logout" value="Esco." onclick="act_logout();" type="button"></div> -->
+<input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
+<?php echo "$tables"; ?>
+
+<b>Chat</b>
+<div id="txt" class="chatt"></div>
+
+<table><tr><td><div id="myname" class="txtt"></div></td><td><input id="txt_in" type="text" size="80" maxlength="256" onchange="act_chatt();" class="txtt"></td></tr></table>
+
+<hr>
+<div id="imgct"></div>
+<div id="logz"></div>
+<div id="sandbox"></div>
+<div id="sandbox2"></div>
+<div id="response"></div>
+<div id="xhrstart"></div>
+<pre>
+<div id="xhrlog"></div>
+</pre>
+<div id="xhrdeltalog"></div>
+</body>
+</html>
+<?php
+ }
+}
+
+main();
+
+?>
--- /dev/null
+<?php
+/*
+ * brisk - index_rd.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.
+ *
+ */
+
+require_once("brisk.phh");
+
+log_load($sess, "LOAD: index_rd.php");
+
+$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;
+ return (sprintf('the_end=true; document.location.assign("index.php");'));
+}
+
+
+
+
+
+function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step)
+{
+ GLOBAL $is_page_streaming, $first_loop;
+
+ $ret = FALSE;
+
+
+ /* Sync check (read only without modifications */
+ if (($sem = lock_data()) != FALSE) {
+ $bri = &load_data();
+ // Aggiorna l'expire time lato server
+ if ($first_loop == TRUE) {
+ if (($user = &get_user($bri, $sess, $idx)) == FALSE) {
+ return (unrecerror());
+ }
+ log_auth($sess, "update lacc");
+ $user->lacc = time() + EXPIRE_TIME;
+ save_data($bri);
+ $first_loop = FALSE;
+
+
+ $bri->garbage_manager(FALSE);
+
+ save_data($bri);
+ }
+ unlock_data($sem);
+ }
+ else
+ return (FALSE);
+
+ if (($user = &get_user(&$bri, $sess, $idx)) == FALSE) {
+ return (unrecerror());
+ }
+
+ /* Nothing changed, return. */
+ if ($cur_stat == $user->stat && $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
+ $sem = lock_data();
+ $bri = &load_data();
+ if (($user = &get_user($bri, $sess, $idx)) == 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;
+
+
+ save_data($bri);
+ unlock_data($sem);
+ }
+ else {
+ log_rd2($sess, "TRANS NON ATTIVATO");
+ }
+ }
+
+ 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;
+
+ unlock_data($sem);
+ }
+ else {
+ $sem = lock_data();
+ $bri = &load_data();
+ if (($user = &get_user($bri, $sess, $idx)) == FALSE) {
+ return (unrecerror());
+ }
+ if ($cur_step < $user->step) {
+ do {
+ if ($cur_step + COMM_N < $user->step) {
+ log_rd2($sess, "lost history, refresh from scratch");
+ $new_step = -1;
+ break;
+ }
+ for ($i = $cur_step ; $i < $user->step ; $i++) {
+ log_rd2($sess, "ADDED TO THE STREAM: ".$user->comm[$i % COMM_N]);
+ $ret .= $user->comm[$i % COMM_N];
+ }
+ $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.");
+ $user->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 ???");
+
+ save_data($bri);
+ }
+ }
+
+ unlock_data($sem);
+ }
+
+
+ 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
+
+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)) != 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(200000);
+ 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.
+ *
+ */
+
+require_once("brisk.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);
+
+$sem = lock_data();
+$bri = &load_data();
+if (($user = &get_user($bri, $sess, &$idx)) == FALSE) {
+ echo "Get User Error";
+ log_wr($sess, "Get User Error");
+ unlock_data($sem);
+ exit;
+}
+$argz = explode('|', $mesg);
+
+if ($user->stat == 'room') {
+ 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++;
+ }
+ else if ($argz[0] == 'chatt') {
+ $bri->chatt_send(&$user,$mesg);
+ }
+ else if ($argz[0] == 'sitdown') {
+ if ($user->stat != 'room' || $user->subst != 'standup') {
+ log_wr($sess, "Warning ! sitdown out fsm");
+ unlock_data($sem);
+ exit;
+ }
+
+ // Take parameters
+ $table_idx = $argz[1];
+ $table = &$bri->table[$table_idx];
+
+ if ($table->player_n == PLAYERS_N) {
+ log_wr($sess, "Warning ! unreachable, table full.");
+ unlock_data($sem);
+ exit;
+ }
+
+ // set new status
+ $user->subst = "sitdown";
+ $user->table = $table_idx;
+ $user->table_pos = $table->player_n;
+ $table->player[$table->player_n] = $idx;
+ $table->player_n++;
+
+ if ($table->player_n == PLAYERS_N) {
+ // Start game for this table.
+ log_wr($sess, "Start game!");
+
+ $table->init();
+ $table->game_init(&$bri);
+
+ 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; 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 = 'table';
+ $user_cur->subst = 'asta';
+ $user_cur->step++;
+
+ $user_cur->comm[$user_cur->step % COMM_N] = show_table(&$bri,&$user_cur,$user_cur->step+1,TRUE, FALSE);
+ $user_cur->step++;
+ }
+ }
+
+ $bri->room_sitdown(&$user, $table_idx);
+ }
+ else if ($argz[0] == 'wakeup') {
+ if ($user->stat != 'room' || $user->subst != 'sitdown') {
+ log_wr($sess, "Warning ! wakeup out fsm.");
+ unlock_data($sem);
+ exit;
+ }
+
+ // set new status
+
+ $user->subst = "standup";
+
+ $bri->room_wakeup(&$user);
+ }
+}
+/***************
+ * *
+ * TABLE *
+ * *
+ ***************/
+else if ($user->stat == 'table' && $user->subst == 'asta') {
+ $table = &$bri->table[$user->table];
+
+ if ($argz[0] == 'logout') {
+
+ // document.location.assign("index.php");
+
+ $bri->room_wakeup(&$user);
+ }
+ else 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++;
+ }
+ else if ($argz[0] == 'chatt') {
+ $bri->chatt_send(&$user,$mesg);
+ }
+ 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 ($table->asta_card == 9) {
+ if ($a_card == 9 && $a_pnt <= 120 && $a_pnt > $table->asta_pnt)
+ $again = FALSE;
+ }
+ else {
+ if ($a_card >= 0 && $a_card <= 9 && $a_card > $table->asta_card)
+ $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
+ 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)) {
+ 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); remark_on();',
+ $table->asta_card + 1, $table->asta_pnt+1);
+ else
+ $ret .= sprintf('dispose_asta(%d,%d); remark_off();',
+ $table->asta_card + 1, -($table->asta_pnt+1));
+ $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+ $user_cur->step++;
+ }
+ }
+ else if ($table->asta_pla_n == 0) {
+ log_wr($sess, "MOLLANO TUTTI!");
+
+ log_wr($sess, sprintf("GIOCO FINITO !!!"));
+
+ $table->mult *= 2;
+
+ $table->game_next();
+ $table->game_init(&$bri);
+
+ 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++;
+ }
+ }
+ else {
+ log_wr($sess, "FINITA !");
+ // if a_pnt == 120 supergame ! else abbandono
+ if ($a_pnt == 120) {
+ $chooser = $index_cur;
+ for ($i = 1 ; $i < PLAYERS_N ; $i++)
+ if ($i != $chooser)
+ $table->asta_pla[$i] = FALSE;
+ }
+ else {
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; dispose_asta(".($table->asta_card + 1).",".-($table->asta_pnt)."); remark_off();";
+ $user->step++;
+ 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++;
+ }
+ }
+ }
+ }
+ 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++;
+ }
+ /*
+ TUTTE LE VARIABILI DI STATO PER PASSARE A GIOCARE E LE
+ VAR PER PASSARE ALLA FASE DI GIOCO
+ */
+
+ }
+ }
+ }
+}
+else if ($user->stat == 'table' && $user->subst == 'game') {
+ $table = &$bri->table[$user->table];
+
+ $retar = array();
+
+ log_wr($sess, "state: table::game".$argz[0]);
+
+ if ($argz[0] == 'logout') {
+ $bri->room_wakeup(&$user);
+ }
+ else 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++;
+ }
+ else if ($argz[0] == 'chatt') {
+ $bri->chatt_send(&$user,$mesg);
+ }
+ else 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);
+
+ 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++;
+ }
+
+ 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");
+save_data($bri);
+
+unlock_data($sem);
+exit;
+?>
--- /dev/null
+<?php
+/*
+ * brisk - info_main.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.
+ *
+ */
+
+define( FTOK_PATH, "/var/lib/brisk");
+define(MAX_PLAYERS, 5);
+define(SESS_LEN, 13);
+
+if (MAX_PLAYERS == 5)
+ exit;
+
+class User {
+ var $name;
+ var $sess;
+ var $table;
+
+ function User($name, $sess, $table = "") {
+ $this->name = $name;
+ $this->sess = $sess;
+ $this->table = $table;
+ }
+}
+
+class brisco {
+ var $user;
+
+ function brisco () {
+ $this->user = array();
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $this->user[$i] = new User("", "", "");
+ }
+ }
+}
+
+function init_data()
+{
+ $brisco = new brisco();
+
+ return $brisco;
+}
+
+function load_data()
+{
+ 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)) {
+ if ($shm = shm_attach($tok)) {
+ echo "fin qui<br>";
+ $bri = @shm_get_var($shm, $tok);
+ }
+
+ shm_detach($shm);
+ }
+ sem_release($res);
+
+ return ($bri);
+}
+
+
+function save_data($bri)
+{
+ $ret = FALSE;
+ $shm = FALSE;
+ $isacq = FALSE;
+
+ if (($tok = ftok(FTOK_PATH."/main", "B")) == -1)
+ return (FALSE);
+
+ if (($res = sem_get($tok)) == FALSE)
+ return (FALSE);
+
+ do {
+ if (sem_acquire($res) == FALSE)
+ break;
+ $isacq = TRUE;
+
+ if (($shm = shm_attach($res)) == FALSE)
+ break;
+
+ if (shm_put_var($shm, $res, $bri) == FALSE)
+ break;
+ $ret = TRUE;
+ } while (0);
+
+ if ($shm)
+ shm_detach($shm);
+
+ if ($isacq)
+ sem_release($res);
+
+ return ($ret);
+}
+
+function &check_session($bri, $sess)
+{
+ if (strlen($sess) == SESS_LEN) {
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ if (strcmp($sess, $bri->user[$i]->sess) == 0) {
+ // find it
+ return ($bri->user[$i]);
+ }
+ }
+ }
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ if ($bri->user[$i]->sess == "") {
+ $bri->user[$i]->sess = uniqid("");
+ return ($bri->user[$i]);
+ }
+ }
+
+ return (NULL);
+}
+
+function duplicated_name($bri, $name)
+{
+ if (!isset($name))
+ return (FALSE);
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ if (strcmp($bri->user[$i]->name,$name) == 0) {
+ return (TRUE);
+ }
+ }
+ return (FALSE);
+}
+
+function main() {
+ GLOBAL $sess, $name;
+ $bri = load_data();
+
+ echo "<plaintext>";
+ var_dump($bri);
+}
+
+main();
+?>
--- /dev/null
+var g_preload_img_arr = new Array(
+ "img/brisk_table_sand0.jpg", "img/brisk_table_sand4.jpg", "img/brisk_table_sand1.jpg", "img/brisk_table_sand3.jpg",
+ "img/brisk_table_sand2.jpg", "img/brisk_caller_sand4.png", "img/brisk_caller_sand0.png", "img/brisk_caller_sand2.png",
+ "img/brisk_caller_sand1.png", "img/brisk_caller_sand3.png", "img/asta.png", "img/33_ea.png",
+ "img/33_we.png", "img/31_we.png", "img/35_ea.png", "img/35_we.png",
+ "img/31_ea.png", "img/23_ea.png", "img/33.png", "img/23_we.png",
+ "img/31.png", "img/35.png", "img/13_ea.png", "img/23.png",
+ "img/13_we.png", "img/cover_ea.png", "img/cover_we.png", "img/cover.png",
+ "img/32_ea.png", "img/32_we.png", "img/13.png", "img/32.png",
+ "img/10_we.png", "img/10_ea.png", "img/27_we.png", "img/27_ea.png",
+ "img/30_we.png", "img/34_we.png", "img/10.png", "img/30_ea.png",
+ "img/36_we.png", "img/36_ea.png", "img/34_ea.png", "img/30.png",
+ "img/37_we.png", "img/38_we.png", "img/36.png", "img/37_ea.png",
+ "img/38_ea.png", "img/38.png", "img/27.png", "img/34.png",
+ "img/37.png", "img/39_we.png", "img/03_we.png", "img/39_ea.png",
+ "img/03_ea.png", "img/39.png", "img/03.png", "img/17_ea.png",
+ "img/17_we.png", "img/20.png", "img/20_ea.png", "img/12_we.png",
+ "img/20_we.png", "img/11_ea.png", "img/12_ea.png", "img/22_we.png",
+ "img/02_ea.png", "img/02_we.png", "img/22_ea.png", "img/11_we.png",
+ "img/25_we.png", "img/17.png", "img/25_ea.png", "img/00_ea.png",
+ "img/28_ea.png", "img/00_we.png", "img/24_we.png", "img/28_we.png",
+ "img/24_ea.png", "img/11.png", "img/12.png", "img/22.png",
+ "img/02.png", "img/28.png", "img/00.png", "img/25.png",
+ "img/14_ea.png", "img/14_we.png", "img/24.png", "img/09_we.png",
+ "img/09_ea.png", "img/09.png", "img/14.png", "img/04_ea.png",
+ "img/04_we.png", "img/04.png", "img/19.png", "img/19_ea.png",
+ "img/19_we.png", "img/21_ea.png", "img/21.png", "img/21_we.png",
+ "img/06.png", "img/06_ea.png", "img/06_we.png", "img/05.png",
+ "img/16_we.png", "img/16_ea.png", "img/05_we.png", "img/26_ea.png",
+ "img/26_we.png", "img/05_ea.png", "img/01_we.png", "img/01_ea.png",
+ "img/16.png", "img/01.png", "img/07.png", "img/07_ea.png",
+ "img/08_ea.png", "img/08_we.png", "img/07_we.png", "img/08.png",
+ "img/26.png", "img/18_ea.png", "img/18_we.png", "img/18.png",
+ "img/15_ea.png", "img/15_we.png", "img/29_we.png", "img/29_ea.png",
+ "img/29.png", "img/15.png", "img/brisk_logo64.png", "img/asta3.png",
+ "img/asta8.png", "img/asta7.png", "img/asta4.png", "img/astapasso.png",
+ "img/asta7_ro.png", "img/asta3_ro.png", "img/asta8_ro.png", "img/asta5.png",
+ "img/asta4_ro.png", "img/asta9.png", "img/asta0.png", "img/asta5_ro.png",
+ "img/astapasso_ro.png", "img/asta1.png", "img/asta6.png", "img/asta0_ro.png",
+ "img/asta9_ro.png", "img/asta2.png", "img/asta1_ro.png", "img/asta6_ro.png",
+ "img/asta2_ro.png", "img/info.png", "img/out.png", "img/astaptsub_ro.png",
+ "img/astaptsub.png", "img/noimg.png", "img/brisk_ico.png");
+var g_preload_imgsz_arr = new Array(
+ "5.4", "10.9", "16.4", "21.8", "27.3", "29.1", "30.9", "32.6",
+ "34.4", "36.2", "37.6", "38.2", "38.8", "39.3", "39.9", "40.4",
+ "41.0", "41.6", "42.1", "42.7", "43.2", "43.8", "44.3", "44.9",
+ "45.4", "45.9", "46.5", "47.0", "47.5", "48.1", "48.6", "49.1",
+ "49.6", "50.2", "50.7", "51.2", "51.7", "52.2", "52.8", "53.3",
+ "53.8", "54.3", "54.8", "55.3", "55.8", "56.4", "56.9", "57.4",
+ "57.9", "58.4", "58.9", "59.4", "59.9", "60.4", "60.9", "61.4",
+ "61.9", "62.4", "62.9", "63.4", "63.9", "64.3", "64.8", "65.3",
+ "65.8", "66.3", "66.7", "67.2", "67.7", "68.2", "68.6", "69.1",
+ "69.6", "70.1", "70.5", "71.0", "71.5", "72.0", "72.4", "72.9",
+ "73.4", "73.8", "74.3", "74.8", "75.2", "75.7", "76.2", "76.6",
+ "77.1", "77.5", "78.0", "78.4", "78.9", "79.3", "79.8", "80.2",
+ "80.6", "81.1", "81.5", "81.9", "82.4", "82.8", "83.2", "83.6",
+ "84.1", "84.5", "84.9", "85.3", "85.7", "86.1", "86.6", "87.0",
+ "87.4", "87.8", "88.2", "88.6", "89.0", "89.4", "89.8", "90.2",
+ "90.6", "91.0", "91.4", "91.8", "92.2", "92.6", "93.0", "93.4",
+ "93.8", "94.2", "94.5", "94.9", "95.3", "95.7", "96.0", "96.2",
+ "96.3", "96.5", "96.7", "96.9", "97.1", "97.3", "97.4", "97.6",
+ "97.8", "97.9", "98.1", "98.2", "98.4", "98.5", "98.7", "98.8",
+ "98.9", "99.1", "99.2", "99.3", "99.4", "99.5", "99.6", "99.7",
+ "99.8", "99.9", "99.9", "100.0");
--- /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.
+ *
+ */
+
+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.
+ *
+ */
+?>
+<html>
+<head>
+<title>Table</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="table.js"></script>
+<link rel="stylesheet" type="text/css" href="brisk.css">
+</head>
+<body>
+<SCRIPT type="text/javascript">
+ var sess;
+ var stat = "table";
+ var subst = "none";
+ var table_pos = "";
+ var myfrom = "table_php";
+
+var asta_ptr;
+var area_ptr;
+
+var gst = new globst();
+gst.st = <?php
+require_once("brisk.phh");
+
+log_load($sess, "LOAD: table.php");
+
+if (isset($laststate) == false) {
+ $laststate = -1;
+}
+echo $laststate;
+?>;
+
+var g_imgct= 0;
+var g_imgtot = g_preload_img_arr.length;
+
+window.onload = function() {
+ remark_off();
+ table_init();
+ xhr_rd = createXMLHttpRequest();
+ sess = "<?php echo "$sess"; ?>";
+
+ setTimeout(xhr_rd_poll, 0, sess);
+ setTimeout(preload_images, 0, g_preload_img_arr, g_imgct);
+}
+</SCRIPT>
+<div id="bg" class="area">
+
+<img id="tableinfo" src="img/info.png" class="tableinfo" onclick = 'act_tableinfo();'>
+<img id="tableout" src="img/out.png" class="tableout" onclick = 'act_preout();'>
+
+<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 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="astapasso2" src="img/astapasso_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>
+
+
+<div class="subarea">
+<div id="txt" class="chattshort"></div>
+<table><tr><td><div id="myname" class="txtt"></div></td><td><input id="txt_in" type="text" size="80" maxlength="256" onchange="act_chatt();" class="txtt"></td></tr></table>
+<hr>
+<div id="imgct"></div>
+<hr>
+<div id="sandbox">biriddo</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 - unrecerror.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.
+ *
+ */
+
+?>
+<html>
+<body>
+<h2> UNRECOVERABLE ERROR </h2>
+non doveva capitare.
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+/*
+ * brisk - xhr.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.
+ *
+ */
+
+var xhr_rd_cookiepath = "/brisk/";
+var xhr_rd = false;
+var xhr_rd_stopped = true;
+var xhr_rd_oldctx = "";
+var xhr_rd_newctx;
+
+var xhr_rd_cur_n = -1;
+var xhr_rd_old_n = -1;
+var xhr_rd_checkedlen = 0;
+var the_end = false;
+var ct = 0;
+var watchdog = 0;
+
+function xhr_rd_cb(xhr_rd)
+{
+ var ret;
+
+ if (xhr_rd.readyState == 4) {
+ try {
+ if ((ret = safestatus(xhr_rd)) == 200) {
+ } else if (ret != -1) {
+ alert('There was a problem with the request.' + ret);
+ }
+ } catch(b) {};
+
+ xhr_rd_stopped = true;
+ }
+};
+
+function xhr_rd_start(sess,stat,subst,step)
+{
+ if (the_end)
+ return;
+ createCookie("sess",sess,1,xhr_rd_cookiepath);
+
+ /* NOTE document.uniqueID exists only under IE */
+ // alert("di qui3");
+ xhr_rd.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true);
+ // try {
+ xhr_rd.onreadystatechange = function() { xhr_rd_cb(xhr_rd); }
+ xhr_rd.send(null);
+ xhr_rd_cur_n++;
+ xhr_rd_stopped = false;
+ // } catch (e) {}
+};
+
+function xhr_rd_poll(sess)
+{
+ var tout = 100;
+ var again;
+ var xhrrestart;
+ ct++;
+
+ /*
+ if (watchdog >= 50) {
+ watchdog = 0;
+ // alert("ABORT XHR_RD");
+ xhr_rd_stopped = true;
+ xhr_rd.abort();
+ }
+ */
+
+ var zug = "XHR_RD_POLL sess = "+sess+" stat = "+stat+" subst = "+subst+" step = "+gst.st+" step_loc = "+gst.st_loc+" step_loc_new = "+gst.st_loc_new+" STOP: "+xhr_rd_stopped;
+
+ if (zug != $("sandbox").innerHTML)
+ $("sandbox").innerHTML = zug;
+
+
+ /* heartbeat log */
+ $("sandbox2").innerHTML += "_";
+ if ($("sandbox2").innerHTML.length == 20)
+ $("sandbox2").innerHTML = "_";
+
+ do {
+ again = 0;
+ xhrrestart = 0;
+ if (gst.st_loc < gst.st_loc_new) {
+ // there is some slow actions running
+ break;
+ }
+ else if (gst.comms.length > 0) {
+ var singlecomm;
+
+ singlecomm = gst.comms.shift();
+ // alert("EXE"+gugu);
+ // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
+ eval(singlecomm);
+ again = 1;
+ }
+ else {
+ xhrrestart = 1;
+ try {
+ xhr_rd_newctx = xhr_rd.responseText;
+ }
+ catch (e) {
+ if (xhr_rd_stopped == true) {
+ xhr_rd_stopped = false;
+ // XX $("xhrstart").innerHTML += "XHRSTART: da catch<br>";
+ xhr_rd_start(sess, stat, subst, gst.st);
+ }
+
+
+ // $("sandbox").innerHTML += "return 1<br>";
+ if (the_end != true) {
+ watchdog = 0;
+ setTimeout(xhr_rd_poll, tout, sess);
+ $("sandbox2").innerHTML += "-";
+ if ($("sandbox2").innerHTML.length == 20)
+ $("sandbox2").innerHTML = "-";
+ }
+ return;
+ }
+
+
+ // no new char from the last loop, break
+ if (xhr_rd_old_n == xhr_rd_cur_n &&
+ xhr_rd_newctx.length == xhr_rd_checkedlen) {
+ watchdog++;
+ break;
+ }
+ else {
+ watchdog = 0;
+ // $("sandbox").innerHTML += "BIG IF<br>";
+ var comm_match;
+ var comm_clean;
+ var comm_len;
+ var comm_newpart;
+ var comm_arr;
+ var i;
+ var delta = 0;
+ var match_lines = /^_*$/;
+
+ // check for the same command group
+ if (xhr_rd_old_n != xhr_rd_cur_n) {
+ xhr_rd_old_n = xhr_rd_cur_n;
+ xhr_rd_checkedlen = 0;
+ xhr_rd_oldctx = "";
+ }
+ else
+ delta = xhr_rd_oldctx.length;
+
+ // $("xhrlog").innerHTML += "EVERY SEC<br>";
+ for (i = delta ; i < xhr_rd_newctx.length ; i++) {
+ if (xhr_rd_newctx[i] != '_')
+ break;
+ }
+ if (i == xhr_rd_newctx.length) {
+ xhr_rd_checkedlen = i;
+ break;
+ }
+
+ // $("xhrlog").innerHTML += "CHECK COM<br>";
+ // extracts the new part of the command string
+ comm_newpart = xhr_rd_newctx.substr(delta);
+
+ // XX $("xhrlog").innerHTML = xhr_rd_newctx.replace("<", "<", "g");
+
+ // $("response").innerHTML = comm_newpart;
+ comm_match = /_*@BEGIN@(.*?)@END@/g;
+ comm_clean = /_*@BEGIN@(.*?)@END@/;
+ comm_len = 0;
+ comm_arr = comm_newpart.match(comm_match);
+
+ // $("sandbox").innerHTML += "PRE COMMARR<br>";
+ if (comm_arr) {
+ // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"<br>";
+ // XX alert("xhr_rd_newctx: "+xhr_rd_newctx);
+ // $("sandbox").innerHTML += "POST COMMARR<br>";
+ for (i = 0 ; i < comm_arr.length ; i++) {
+ var temp = comm_arr[i].replace(comm_clean,"$1").split("|");
+ gst.comms = gst.comms.concat(temp);
+ // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+" LEN:"+comm_arr[i].length);
+ comm_len += comm_arr[i].length;
+ }
+ tout = 0;
+ xhr_rd_oldctx += comm_newpart.substr(0,comm_len);
+ // XX alert("XHR_RD_OLDCTX: "+xhr_rd_oldctx);
+ again = 1;
+ }
+ xhr_rd_checkedlen = xhr_rd_oldctx.length;
+ }
+ }
+ } while (again);
+
+ if (xhrrestart == 1 && xhr_rd_stopped == true) {
+ // $("sandbox").innerHTML += "LITTLE IF<br>";
+ // alert("di qui");
+ // XX $("xhrstart").innerHTML += "XHRSTART: da end poll<br>";
+ xhr_rd_start(sess, stat, subst, gst.st);
+ // $("sandbox").innerHTML += "return 2<br>";
+ }
+
+ // $("sandbox").innerHTML += "return 3<br>";
+ if (the_end != true) {
+ setTimeout(xhr_rd_poll, tout, sess);
+ $("sandbox2").innerHTML += "-";
+ if ($("sandbox2").innerHTML.length == 20)
+ $("sandbox2").innerHTML = "-";
+ }
+ return;
+};
+
+/*
+ window.onload = function () {
+ xhr_rd = createXMLHttpRequest();
+
+ sess = $("user").value;
+ window.setTimeout(xhr_rd_poll, 0, sess);
+ };
+*/