$query = mysql_query(sprintf('SELECT * FROM `sse_data_table` WHERE `key` = \'%s\'', $this->escape($key)), $this->conn); $res = mysql_fetch_assoc($query); return $res['value']; } /* * @method SSEData_MySQL::set * @param $key the ID of the data * @param $value the data * @description add data to the table */ public function set($key, $value) { if ($this->get($key)) { return mysql_query(sprintf("UPDATE `sse_data_table` SET `value` = '%s' WHERE `key` = '%s'", $this->escape($value), $this->escape($key)), $this->conn); } else { return mysql_query(sprintf("INSERT INTO `sse_data_table` SET `key` = '%s', `value` = '%s'", $this->escape($key), $this->escape($value)), $this->conn); } } /* * @method SSEData_MySQL::delete * @param $key the ID of the data * @description delete the data with the same ID specified */ public function delete($key) { return mysql_query(sprintf('DELETE FROM `sse_data_table` WHERE `key` == \'%s\'', $this->escape($key)), $this->conn); } } //register the module SSEData::register('mysql', 'SSEData_MySQL');
<?php header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Key"); header("Access-Control-Allow-Methods: PUT"); require_once 'src/libsse.php'; $data = new SSEData('file', array('path' => './data')); if (isset($_POST['user']) && !isset($_POST['message'])) { $data->set('user', json_encode(array('msg' => htmlentities($_POST['user']), 'time' => time()))); } else { if (isset($_POST['message'], $_POST['user'])) { $data->set('message', json_encode(array('msg' => htmlentities($_POST['message']), 'time' => time(), 'user' => $_POST['user']))); } }
$query = mysqli_query($this->conn, sprintf('SELECT * FROM `sse_data_table` WHERE `key` = \'%s\'', $this->escape($key))); $res = mysqli_fetch_assoc($query); return $res['value']; } /* * @method SSEData_MySQLi::set * @param $key the ID of the data * @param $value the data * @description add data to the table */ public function set($key, $value) { if ($this->get($key)) { return mysqli_query($this->conn, sprintf("UPDATE `sse_data_table` SET `value` = '%s' WHERE `key` = '%s'", $this->escape($value), $this->escape($key))); } else { return mysqli_query($this->conn, sprintf("INSERT INTO `sse_data_table` SET `key` = '%s', `value` = '%s'", $this->escape($key), $this->escape($value))); } } /* * @method SSEData_MySQLi::delete * @param $key the ID of the data * @description delete the data with the same ID specified */ public function delete($key) { return mysqli_query($this->conn, sprintf('DELETE FROM `sse_data_table` WHERE `key` == \'%s\'', $this->escape($key))); } } //register the module SSEData::register('mysqli', 'SSEData_MySQLi');
<?php header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Key"); header("Access-Control-Allow-Methods: POST"); require_once './src/libsse.php'; if (!isset($_POST['id'])) { http_response_code(400); var_dump($_POST); echo 'Id is required'; return; } $data = new SSEData('file', array('path' => './data', 'gc_lifetime' => 16000)); $game = $data->get($_POST['id']); if (strlen($game) < 1) { http_response_code(404); echo 'Could not find game with that ID.'; return; } $game = json_decode($game); // Start Game $game->started = true; $game->startedTime = time(); // Update Log array_push($game->log, array('message' => 'Game has started.', 'time' => time(), 'from' => 'system')); // Shuffle Decks shuffle($game->blackDeck); shuffle($game->whiteDeck); // Update updated time $game->updated = time(); // Save
* @param $key the ID of the data * @description delete the data with the same ID specified */ public function delete($key) { $path = $this->path . '/sess_' . sha1($key); if (file_exists($path)) { unlink($path); } return true; } /* * @method SSEData_File::gc * @description remove keys that are unused for a specified period */ private function gc() { if ($this->gc_lifetime === 0) { return; } foreach (glob($this->path . '/sess_*') as $file) { if (filemtime($file) + $this->gc_lifetime < time() && file_exists($file)) { unlink($file); } } return true; } } //register the module SSEData::register('file', 'SSEData_File');
* @method SSEData_APC::get * @param $key the ID of the data * @description get the data by the key */ public function get($key) { return apc_fetch($key); } /* * @method SSEData_APC::set * @param $key the ID of the data * @param $value the data * @description add data to the cache */ public function set($key, $value) { return apc_store($key, $value); } /* * @method SSEData_APC::delete * @param $key the ID of the data * @description delete the data with the same ID specified */ public function delete($key) { return apc_delete($key); } } //register the module SSEData::register('apc', 'SSEData_APC');