+class Client_prefs {
+ var $listen;
+ var $supp_comp;
+
+ function Client_prefs()
+ {
+ }
+
+ static function from_user($user)
+ {
+ $thiz = new Client_prefs();
+ $thiz->user_load($user);
+
+ return ($thiz);
+ }
+
+ static function from_json($json)
+ {
+ $thiz = new Client_prefs();
+ if ($thiz->json_load($json) == FALSE) {
+ unset($thiz);
+ return (FALSE);
+ }
+
+ return ($thiz);
+ }
+
+ function user_load($user)
+ {
+ fprintf(STDERR, "QQ %s: %x\n", __FUNCTION__, $user->flags);
+ $this->listen = ($user->flags & USER_FLAG_MAP_AUTH) >> 2;
+ if ($user->rec != FALSE) {
+ $this->supp_comp = $user->rec->supp_comp_get();
+ }
+ else {
+ $this->supp_comp = "000000000000";
+ }
+
+ fprintf(STDERR, "QQ %s: LISTEN: %d\n", __FUNCTION__, $this->listen);
+ }
+
+ function json_load($json_s)
+ {
+ $ret = FALSE;
+
+ do {
+ if (gettype($json_s) == "string") {
+ if (($json = json_decode($json_s)) == FALSE)
+ break;
+ }
+ else {
+ $json = $json_s;
+ }
+ if ($this->listen < 0 || $this->listen > 2)
+ break;
+ $this->listen = $json->listen;
+
+ if (mb_strlen($json->supp_comp, "ASCII") != 12)
+ break;
+
+ for ($i = 0, $idx = 0 ; $i < 12 ; $i++) {
+ if (($json->supp_comp[$i] >= '0' && $json->supp_comp[$i] <= '9') ||
+ ($json->supp_comp[$i] >= 'a' && $json->supp_comp[$i] <= 'f'))
+ continue;
+ break;
+ }
+ if ($i < 12)
+ break;
+ $this->supp_comp = $json->supp_comp;
+ $ret = TRUE;
+ } while (FALSE);
+
+ return ($ret);
+ }
+
+ function store($user, $is_save)
+ {
+ // save into DB
+ fprintf(STDERR, "QQ %s::%s PRE: %x\n", __CLASS__, __FUNCTION__,
+ $user->flags & (~USER_FLAG_S_ALL & ~USER_FLAG_AUTH));
+ $user->flags_set(($this->listen << 2), USER_FLAG_MAP_AUTH);
+ fprintf(STDERR, "QQ %s::%s %x\n", __CLASS__, __FUNCTION__,
+ $user->flags);
+ if ($user->is_supp_custom()) {
+ $user->rec->supp_comp_set($this->supp_comp);
+ }
+ if ($is_save)
+ $user->prefs_store();
+ }
+}
+
+
+class Brisk
+{
+ static $delta_t;
+
+ var $crystal_filename;
+ var $user;
+ var $table;
+ var $match;
+ var $comm; // commands for many people
+ var $step; // current step of the comm array
+ var $garbage_timeout;
+ var $shm_sz;
+
+ var $delay_mgr;
+
+ public static $sess_cur;
+
+ function Brisk($crystal_filename) {
+ $this->crystal_filename = $crystal_filename;
+ $this->user = array();
+ $this->table = array();
+ $this->match = array();
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $this->user[$i] = User::create($this, $i, "", "");
+ }
+
+ for ($i = 0 ; $i < TABLES_N ; $i++) {
+ $this->table[$i] = Table::create($i);
+ /* OLD METHOD
+ if ($i < 12) {
+ $row = ( (((int)($i / 4)) % 2) == 0 );
+ $col = ($i % 2 == 0);
+ $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
+ }
+ else {
+ $this->table[$i]->auth_only = FALSE;
+ }
+ */
+ if ($i < TABLES_AUTH_N)
+ $this->table[$i]->auth_only = TRUE;
+ else
+ $this->table[$i]->auth_only = FALSE;
+ }
+ $this->garbage_timeout = 0;
+ $this->shm_sz = SHM_DIMS_MIN;
+
+ $this->delay_mgr = new Delay_Manager(1.5);
+
+ static::$sess_cur = FALSE;