+
+ function save_data(&$room)
+ {
+ GLOBAL $sess;
+
+ $ret = FALSE;
+ $shm = FALSE;
+
+ // var_dump($room);
+ // error_log("Room::save_data BEGIN", 0);
+
+ if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
+ return (FALSE);
+
+ // SHSPLIT: before save the $room you must save users,
+ // detach from main struct and (then) reattach
+ $user_park = array();
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_park[$i] = $room->user[$i];
+ $room->user[$i] = FALSE;
+ }
+
+ while ($room->shm_sz < SHM_DIMS_MAX) {
+ if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
+ break;
+
+ // log_only("PUT_VAR DI ".strlen(serialize($room)));
+ if (shm_put_var($shm, $tok, $room) != FALSE) {
+ $ret = TRUE;
+ break;
+ }
+ if (shm_remove($shm) === FALSE) {
+ log_only("REMOVE FALLITA");
+ break;
+ }
+ shm_detach($shm);
+ $room->shm_sz += SHM_DIMS_DLT;
+ }
+
+ if ($shm)
+ shm_detach($shm);
+
+ // SHSPLIT: reattach users to the room class
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ User::save_data($user_park[$i], $i);
+ $room->user[$i] = $user_park[$i];
+ }
+
+ return ($ret);
+ }
+