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.
24 define( FTOK_PATH, "/var/lib/brisk");
25 define(MAX_PLAYERS, 5);
36 function User($name, $sess, $table = "") {
39 $this->table = $table;
47 $this->user = array();
48 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
49 $this->user[$i] = new User("", "", "");
56 $brisco = new brisco();
63 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
67 echo "FTOK ".$tok."<br>";
68 if (($res = sem_get($tok)) == FALSE) {
69 echo "SEM_GET FAILED";
72 if (sem_acquire($res)) {
73 if ($shm = shm_attach($tok)) {
75 $bri = @shm_get_var($shm, $tok);
86 function save_data($bri)
92 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1)
95 if (($res = sem_get($tok)) == FALSE)
99 if (sem_acquire($res) == FALSE)
103 if (($shm = shm_attach($res)) == FALSE)
106 if (shm_put_var($shm, $res, $bri) == FALSE)
120 function &check_session($bri, $sess)
122 if (strlen($sess) == SESS_LEN) {
123 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
124 if (strcmp($sess, $bri->user[$i]->sess) == 0) {
126 return ($bri->user[$i]);
130 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
131 if ($bri->user[$i]->sess == "") {
132 $bri->user[$i]->sess = uniqid("");
133 return ($bri->user[$i]);
140 function duplicated_name($bri, $name)
145 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
146 if (strcmp($bri->user[$i]->name,$name) == 0) {