+ function standup_update(&$user)
+ {
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_cur = &$this->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($this, $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_inc();
+ }
+ }
+ }
+
+ // Static functions
+ function &init_data()
+ {
+ $room =& new Room();
+
+ return $room;
+ }
+
+
+ function &load_data()
+ {
+ GLOBAL $G_false, $sess;
+
+ if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
+ echo "FTOK FAILED";
+ exit;
+ }
+
+ if ($shm = shm_attach($tok, SHM_DIMS)) {
+ $room = @shm_get_var($shm, $tok);
+
+ log_only($sess, "bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
+ if (isset($room))
+ log_only($sess, "bri count ".count($room));
+
+ if ($room == FALSE) {
+ log_only($sess, "INIT MAIN DATA");
+
+ $room =& Room::init_data();
+ if (shm_put_var($shm, $tok, $room) == FALSE) {
+ log_only($sess, "PUT_VAR FALLITA ".strlen(serialize($room)));
+ log_only($sess, serialize($room));
+ }
+ }
+
+ shm_detach($shm);
+
+ $ret = &$room;
+ return ($ret);
+ }
+
+ return ($G_false);
+ }
+
+
+ function save_data(&$room)
+ {
+ GLOBAL $sess;
+
+ $ret = FALSE;
+ $shm = FALSE;
+ $isacq = FALSE;
+
+ // var_dump($room);
+
+ if (($tok = ftok(FTOK_PATH."/main", "B")) == -1)
+ return (FALSE);
+
+ do {
+ $isacq = TRUE;
+
+ if (($shm = shm_attach($tok, SHM_DIMS)) == FALSE)
+ break;
+
+ // log_only($sess, "PUT_VAR DI ".strlen(serialize($room)));
+ if (shm_put_var($shm, $tok, $room) == FALSE) {
+ log_only($sess, "PUT_VAR FALLITA ".strlen(serialize($room)));
+ log_only($sess, serialize($room));
+ break;
+ }
+ // log_main("XXX", "QUI CI ARRIVA [".$room->user[0]->name."]");
+ $ret = TRUE;
+ } while (0);
+
+ if ($shm)
+ shm_detach($shm);
+
+ return ($ret);
+ }
+
+ function lock_data()
+ {
+ GLOBAL $sess;
+
+ // 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)) {
+ log_only($sess, "LOCK");
+ return ($res);
+ }
+ else
+ return (FALSE);
+ }
+
+ function unlock_data($res)
+ {
+ GLOBAL $sess;
+
+ log_only($sess, "UNLOCK");
+
+ return (sem_release($res));
+ }
+} // end class Room