3 * brisk - info_main.php
5 * Copyright (C) 2006 matteo.nastasi@milug.org
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details. You should have received a
16 * copy of the GNU General Public License along with this program; if
17 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
18 * Suite 330, Boston, MA 02111-1307, USA.
22 define( FTOK_PATH, "/var/lib/brisk");
23 define(MAX_PLAYERS, 5);
34 function User($name, $sess, $table = "") {
37 $this->table = $table;
45 $this->user = array();
46 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
47 $this->user[$i] = new User("", "", "");
54 $brisco = new brisco();
61 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
65 echo "FTOK ".$tok."<br>";
66 if (($res = sem_get($tok)) == FALSE) {
67 echo "SEM_GET FAILED";
70 if (sem_acquire($res)) {
71 if ($shm = shm_attach($tok)) {
73 $bri = @shm_get_var($shm, $tok);
84 function save_data($bri)
90 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1)
93 if (($res = sem_get($tok)) == FALSE)
97 if (sem_acquire($res) == FALSE)
101 if (($shm = shm_attach($res)) == FALSE)
104 if (shm_put_var($shm, $res, $bri) == FALSE)
118 function &check_session($bri, $sess)
120 if (strlen($sess) == SESS_LEN) {
121 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
122 if (strcmp($sess, $bri->user[$i]->sess) == 0) {
124 return ($bri->user[$i]);
128 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
129 if ($bri->user[$i]->sess == "") {
130 $bri->user[$i]->sess = uniqid("");
131 return ($bri->user[$i]);
138 function duplicated_name($bri, $name)
143 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
144 if (strcmp($bri->user[$i]->name,$name) == 0) {