Beispiel #1
0
 public function saveData(AccountInfo $info)
 {
     $name = $info->name;
     $path = $this->getPath($name);
     $this->main->getServer()->getScheduler()->scheduleAsyncTask(new JsonSaveDataTask($path, $info->serialize(), $info->lastIp, $info->name, $info->registerTime));
     //		$stmt = $this->sql->prepare("SELECT time FROM reg WHERE name=:name");
     //		$stmt->bindValue(":name", strtolower($info->name), SQLITE3_TEXT);
     //		$result = $stmt->execute();
     //		$row = $result->fetchArray(SQLITE3_ASSOC);
     //		$result->finalize();
     //		$registered = (is_array($row) and $row["time"] !== -1);
     //		if(!$registered){
     //		$stmt = $this->sql->prepare(/** @lang SQLite */
     //			"UPDATE reg SET time = CASE time WHEN -1 THEN :time ELSE time END WHERE name=:name");
     //		$stmt->bindValue(":ip", $info->lastIp, SQLITE3_TEXT);
     //		$stmt->bindValue(":name", strtolower($info->name), SQLITE3_TEXT);
     //		$stmt->bindValue(":time", $info->registerTime, SQLITE3_INTEGER);
     //		$stmt->execute();
     //		if($this->sql->changes() === 0){
     //			$stmt = $this->sql->prepare("INSERT INTO reg (ip, name, time) VALUES (:ip, :name, :time)");
     //			$stmt->bindValue(":ip", $info->lastIp, SQLITE3_TEXT);
     //			$stmt->bindValue(":name", strtolower($info->name), SQLITE3_TEXT);
     //			$stmt->bindValue(":time", $info->registerTime, SQLITE3_INTEGER);
     //			$stmt->execute();
     //		}
     //		}
 }
 public function saveData($name, AccountInfo $info)
 {
     $path = $this->getPath($name);
     $existed = file_exists($path);
     $this->main->getServer()->getScheduler()->scheduleAsyncTask(new FileWriteTask($path, $info->serialize()));
     if (!$existed) {
         $stmt = $this->sql->prepare("INSERT INTO reg (ip, name, time) VALUES (:ip, :name, :time)");
         $stmt->bindValue(":ip", $info->lastIp, SQLITE3_TEXT);
         $stmt->bindValue(":name", strtolower($info->name), SQLITE3_TEXT);
         $stmt->bindValue(":time", $info->registerTime, SQLITE3_INTEGER);
         $stmt->execute();
     }
 }
 public function write(AccountInfo $info)
 {
     $path = $this->getPath($info->name);
     if ($isOverwrite = is_file($path)) {
         if (!$this->overwrite) {
             return;
         }
     }
     file_put_contents($path, zlib_encode($info->serialize(), ZLIB_ENCODING_DEFLATE));
     if (!$isOverwrite and $info->registerTime !== -1) {
         $stmt = $this->sql->prepare("INSERT OR REPLACE INTO reg (ip, name, time) VALUES (:ip, :name, :time)");
         $stmt->bindValue(":ip", $info->lastIp, SQLITE3_TEXT);
         $stmt->bindValue(":name", strtolower($info->name), SQLITE3_TEXT);
         $stmt->bindValue(":time", $info->registerTime, SQLITE3_INTEGER);
         $stmt->execute();
     }
 }