Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>

This commit is contained in:
Gregory PLANCHAT 2011-06-28 13:02:55 +02:00
commit 3fd8832b45
138 changed files with 2597 additions and 1253 deletions

View file

@ -157,7 +157,7 @@ class Legacies_Core_Collection
return $this;
}
public function _prepareSql()
protected function _prepareSql()
{
if (empty($this->_union)) {
$database = Legacies_Database::getSingleton();
@ -172,8 +172,16 @@ class Legacies_Core_Collection
$fields[] = $fieldName;
}
}
$fields = implode(", ", $fields);
$where = implode(" AND ", $this->_where);
if (!empty($fields)) {
$fields = implode(", ", $fields);
} else {
$fields = '*';
}
if (!empty($where)) {
$where = 'WHERE ' . implode(" AND ", $this->_where);
} else {
$where = '';
}
$joinedTables = implode("\n ", $this->_join);
$order = '';
@ -201,7 +209,7 @@ class Legacies_Core_Collection
SELECT {$fields}
FROM {$database->getTable($this->getTableName())}{$alias}
{$joinedTables}
WHERE $where
{$where}
{$group}
{$order}
{$limit}
@ -213,6 +221,11 @@ SQL_EOF;
}
$statements = '(' . implode(') UNION (', $statements) . ')';
if (!empty($where)) {
$where = 'WHERE ' . implode(" AND ", $this->_where);
} else {
$where = '';
}
$where = implode(" AND ", $this->_where);
$limit = '';
@ -226,12 +239,17 @@ SQL_EOF;
return <<<SQL_EOF
$statements
WHERE $where
{$where}
{$limit}
SQL_EOF;
}
}
public function __toString()
{
return $this->_prepareSql();
}
protected function _load()
{
$sql = $this->_prepareSql();
@ -245,8 +263,8 @@ SQL_EOF;
$this->_items = array();
$reflection = new ReflectionClass($this->getEntityClassName());
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
$args = array($row) + $args;
$this->_items[] = $reflection->newInstanceArgs($args);
$params = array_merge(array($row), $args);
$this->_items[] = $reflection->newInstanceArgs($params);
}
return $this;
@ -282,12 +300,16 @@ SQL_EOF;
public function next()
{
return next($this->_items);
next($this->_items);
return $this;
}
public function rewind()
{
return reset($this->_items);
reset($this->_items);
return $this;
}
public function key()
@ -297,6 +319,6 @@ SQL_EOF;
public function valid()
{
return (key($this->_items) < (current($this->_items)));
return current($this->_items) !== false;
}
}

View file

@ -45,22 +45,17 @@ abstract class Legacies_Core_Entity
protected function _load()
{
static $statement = null;
$id = func_get_arg(0);
if ($statement === null) {
$idFieldName = self::getIdFieldName();
$database = Legacies_Database::getSingleton();
$idFieldName = self::getIdFieldName();
$database = Legacies_Database::getSingleton();
$sql =<<<SQL_EOF
$sql =<<<SQL_EOF
SELECT * FROM {$database->getTable(self::getTableName())}
WHERE {$idFieldName}=:id
LIMIT 1
SQL_EOF;
$statement = $database->prepare($sql);
}
$statement = $database->prepare($sql);
$statement->execute(array(
'id' => $id
));
@ -135,25 +130,21 @@ SQL_EOF;
protected function _delete()
{
static $statement = null;
if ($statement == null) {
$fields = array();
foreach ($this->getAllDatas() as $field => $value) {
if ($field == self::getIdFieldName()) {
continue;
}
$fields[] = "{$field}=:{$field}";
$fields = array();
foreach ($this->getAllDatas() as $field => $value) {
if ($field == self::getIdFieldName()) {
continue;
}
$fields[] = "{$field}=:{$field}";
}
$fieldsImploded = implod(', ', $fields);
$idFieldName = self::getIdFieldName();
$database = Legacies_Database::getSingleton();
$sql =<<<SQL_EOF
$fieldsImploded = implod(', ', $fields);
$idFieldName = self::getIdFieldName();
$database = Legacies_Database::getSingleton();
$sql =<<<SQL_EOF
DELETE {$database->getTable(self::getTableName())}
WHERE {$idFieldName}=:{$idFieldName}
SQL_EOF;
}
$statement->execute($this->getAllDatas());

View file

@ -96,8 +96,10 @@ SQL_EOF;
$database = Legacies_Database::getSingleton();
$idFields = array();
$idValues = array();
foreach ($this->_idFieldNames as $field) {
$idFields[] = "{$field}=:{$field}";
$idValues[$field] = $this->getData($field);
}
$idFields = '(' . implode(') AND (', $idFields) . ')';

View file

@ -0,0 +1,163 @@
<?php
class Legacies_Core_Error
{
private static $_singleton = null;
protected $_errors = array();
protected $_warnings = array();
protected $_notices = array();
protected $_otherErrors = array();
protected $_exceptions = array();
public static function getSingleton()
{
if (self::$_singleton === null) {
self::$_singleton = new self;
}
return self::$_singleton;
}
public function errorManager($errno, $errstr, $errfile = null, $errline = null, Array $errcontext = array())
{
switch ($errno) {
case E_USER_ERROR:
case E_ERROR:
$this->_errors[] = array(
'time' => explode(' ', microtime()),
'code' => $errno,
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext
);
break;
case E_USER_WARNING:
case E_WARNING:
$this->_warnings[] = array(
'time' => explode(' ', microtime()),
'code' => $errno,
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext
);
break;
case E_USER_NOTICE:
case E_NOTICE:
$this->_notices[] = array(
'time' => explode(' ', microtime()),
'code' => $errno,
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext
);
break;
default:
if (!isset($this->_otherErrors[$errno])) {
$this->_otherErrors[$errno] = array();
}
$this->_otherErrors[$errno][] = array(
'time' => explode(' ', microtime()),
'code' => $errno,
'message' => $errstr,
'file' => $errfile,
'line' => $errline,
'context' => $errcontext
);
break;
}
return true;
}
public function exceptionManager($exception)
{
$this->_exceptions[] = $exception;
}
protected function _renderError($error)
{
$types = array(
0x0001 => 'E_ERROR',
0x0002 => 'E_WARNING',
0x0004 => 'E_PARSE',
0x0008 => 'E_NOTICE',
0x0010 => 'E_CORE_ERROR',
0x0020 => 'E_CORE_WARNING',
0x0040 => 'E_COMPILE_ERROR',
0x0080 => 'E_COMPILE_WARNING',
0x0100 => 'E_USER_ERROR',
0x0200 => 'E_USER_WARNING',
0x0400 => 'E_USER_NOTICE',
0x0800 => 'E_STRICT',
0x1000 => 'E_RECOVERABLE_ERROR',
0x2000 => 'E_DEPRECATED',
0x4000 => 'E_USER_DEPRECATED',
);
if (isset($types[$error['code']])) {
$code = $types[$error['code']];
} else {
$code = "Unknown ({$error['code']})";
}
$date = date('Y-m-d H:i:s', (int) $error['time'][1]);
$microsec = (int) ($error['time'][0] * 1000000);
return <<<ERROR_EOF
On: {$date} +{$microsec}µs
Type: {$code}
Message: {$error['message']}
File: {$error['file']}
Line: {$error['line']}
\n
ERROR_EOF;
}
public function shutdownManager()
{
echo '<pre style="background:#FFF;border:1px solid #F00;color:#000;padding:10px;margin:20px;">';
foreach ($this->_errors as $error) {
echo $this->_renderError($error);
}
foreach ($this->_warnings as $error) {
echo $this->_renderError($error);
}
foreach ($this->_notices as $error) {
echo $this->_renderError($error);
}
foreach ($this->_otherErrors as $error) {
echo $this->_renderError($error);
}
foreach ($this->_exceptions as $exception) {
echo $exception->getMessage();
echo $exception->getTraceAsString();
}
echo '</pre>';
}
public static function register()
{
static $registered = false;
set_error_handler(array(self::getSingleton(), 'errorManager'));
set_exception_handler(array(self::getSingleton(), 'exceptionManager'));
if ($registered === false && defined('DEBUG')) {
$registered = true;
register_shutdown_function(array(self::getSingleton(), 'shutdownManager'));
}
}
public static function unregister()
{
restore_error_handler();
restore_exception_handler();
}
}

View file

@ -0,0 +1,444 @@
<?php
class Legacies_Core_Setup_Model_Updater_ScriptQueue
implements Iterator, Countable, ArrayAccess
{
const PCRE_FILE_PATTERN = '%^(?<action>install|upgrade|uninstall|downgrade)-(?<version1>[0-9]+\.[0-9]+\.[0-9]+)(?:\.(?<stage1>[a-z]+)(?<level1>[0-9]+))?(?:-(?<version2>[0-9]+\.[0-9]+\.[0-9]+)(?:\.(?<stage2>[a-z]+)(?<level2>[0-9]+))?)?$%';
const PCRE_VERSION_PATTERN = '%^(?<version>[0-9]+\.[0-9]+\.[0-9]+)(?:-(?<stage>[a-z]+)(?<level>[0-9]+)?)?$%';
const STAGE_ALPHA = 'alpha';
const STAGE_BETA = 'beta';
const STAGE_RC = 'rc';
const STAGE_STABLE = 'stable';
const MODE_INSTALL = 'install';
const MODE_UNINSTALL = 'uninstall';
const MODE_UPGRADE = 'upgrade';
const MODE_DOWNGRADE = 'downgrade';
const VERSION_NULL = '0.0.0';
protected $_installVersions = array();
protected $_upgradeVersions = array();
protected $_uninstallVersions = array();
protected $_downgradeVersions = array();
protected $_finalVersion = null;
protected $_scripts = array();
public function __construct($path, $fromVersion = null, $toVersion = null)
{
try {
$this->_analyzePath($path);
} catch (Exception $e) {
return;
}
if ($fromVersion === null) {
$fromVersion = '0.0.0';
}
if ($toVersion === null) {
$toVersion = '0.0.0';
}
preg_match(self::PCRE_VERSION_PATTERN, $fromVersion, $matches);
$fromVersion = array(
'version' => isset($matches['version']) ? $matches['version'] : self::VERSION_NULL,
'stage' => isset($matches['stage']) && !empty($matches['stage']) ? $matches['stage'] : self::STAGE_STABLE,
'level' => isset($matches['level']) && !empty($matches['level']) ? (int) $matches['level'] : 0,
);
preg_match(self::PCRE_VERSION_PATTERN, $toVersion, $matches);
$toVersion = array(
'version' => isset($matches['version']) ? $matches['version'] : self::VERSION_NULL,
'stage' => isset($matches['stage']) && !empty($matches['stage']) ? $matches['stage'] : self::STAGE_STABLE,
'level' => isset($matches['level']) && !empty($matches['level']) ? (int) $matches['level'] : 0,
);
switch (version_compare($toVersion['version'], $fromVersion['version'])) {
case 1:
$this->_upgradeToVersion($fromVersion, $toVersion);
break;
case -1:
$this->_downgradeToVersion($fromVersion, $toVersion);
break;
case 0:
if ($toVersion['stage'] === self::STAGE_STABLE) {
if ($fromVersion['stage'] !== self::STAGE_STABLE) {
$this->_upgradeToVersion($fromVersion, $toVersion);
} else {
$this->_downgradeToVersion($fromVersion, $toVersion);
}
} else if ($toVersion['stage'] === self::STAGE_RC) {
if ($fromVersion['stage'] === self::STAGE_STABLE) {
$this->_downgradeToVersion($fromVersion, $toVersion);
} else if ($fromVersion['stage'] === self::STAGE_RC) {
if ($fromVersion['level'] < $toVersion['level']) {
$this->_upgradeToVersion($fromVersion, $toVersion);
} else {
// throw new RuntimeException("Version already installed.");
}
} else {
$this->_upgradeToVersion($fromVersion, $toVersion);
}
} else if ($toVersion['stage'] === self::STAGE_BETA) {
if (in_array($fromVersion['stage'], array(self::STAGE_STABLE, self::STAGE_RC))) {
$this->_downgradeToVersion($fromVersion, $toVersion);
} else if ($fromVersion['stage'] === self::STAGE_BETA) {
if ($fromVersion['level'] < $toVersion['level']) {
$this->_upgradeToVersion($fromVersion, $toVersion);
} else {
// throw new RuntimeException("Version already installed.");
}
} else {
$this->_upgradeToVersion($fromVersion, $toVersion);
}
} else if ($toVersion['stage'] === self::STAGE_ALPHA) {
if (in_array($fromVersion['stage'], array(self::STAGE_STABLE, self::STAGE_RC, self::STAGE_BETA))) {
$this->_downgradeToVersion($fromVersion, $toVersion);
} else if ($fromVersion['stage'] === self::STAGE_ALPHA) {
if ($fromVersion['level'] < $toVersion['level']) {
$this->_upgradeToVersion($fromVersion, $toVersion);
} else {
// throw new RuntimeException("Version already installed.");
}
} else {
$this->_upgradeToVersion($fromVersion, $toVersion);
}
} else {
throw new RuntimeException("Invalid version stage.");
}
break;
}
return $this;
}
public function getFinalVersion()
{
return $this->_finalVersion;
}
protected function _installHighestInstaller($currentVersion, $toVersion)
{
$highestVersion = self::VERSION_NULL;
foreach (array_keys($this->_installVersions) as $version) {
if (version_compare($version, $highestVersion, '>') && version_compare($version, $toVersion['version'], '<=')) {
$highestVersion = $version;
}
}
if (isset($this->_installVersions[$highestVersion][self::STAGE_STABLE][0])) {
$version = array(
'version' => $highestVersion,
'stage' => self::STAGE_STABLE,
'level' => 0,
);
$this->enqueue(array($version, $this->_installVersions[$highestVersion][self::STAGE_STABLE][0]));
return $version;
}
if (isset($this->_installVersions[$highestVersion][self::STAGE_RC])) {
$stage = self::STAGE_RC;
} else if (isset($this->_installVersions[$highestVersion][self::STAGE_BETA])) {
$stage = self::STAGE_BETA;
} else if (isset($this->_installVersions[$highestVersion][self::STAGE_ALPHA])) {
$stage = self::STAGE_ALPHA;
} else {
throw new RuntimeException("Invalid version stage.");
}
$levelList = array_keys($this->_installVersions[$highestVersion][$stage]);
$highestLevel = 0;
foreach ($levelList as $level) {
if ($level > $highestLevel) {
$highestLevel = $level;
}
}
$version = array(
'version' => $highestVersion,
'stage' => $stage,
'level' => $highestLevel,
);
$this->enqueue(array($version, $this->_installVersions[$highestVersion][$stage][$highestLevel]));
return $version;
}
protected function _downgradeToVersion($fromVersion, $toVersion)
{
throw new RuntimeException("Downgrade isn't yet implemented.");
}
protected function _upgradeToVersion($fromVersion, $toVersion)
{
$currentVersion = $fromVersion;
if ($fromVersion['version'] === self::VERSION_NULL) {
// run the higher install script
$currentVersion = $this->_installHighestInstaller($currentVersion, $toVersion);
}
$upgradeVersions = $this->_upgradeVersions;
while (true) {
if ($currentVersion['version'] === $toVersion['version'] &&
$currentVersion['stage'] === $toVersion['stage'] &&
$currentVersion['level'] === $toVersion['level']) {
break;
}
$versionPointer = &$upgradeVersions[$currentVersion['version']][$currentVersion['stage']][$currentVersion['level']];
if (empty($versionPointer)) {
break;
}
$highestVersion = $currentVersion['version'];
foreach ($versionPointer as $version => $stages) {
if (version_compare($version, $highestVersion['version'], '>') && version_compare($version, $toVersion['version'], '<=')) {
$highestVersion = $version;
}
}
if (version_compare($highestVersion, $toVersion['version'], '<')) {
$stage = self::STAGE_STABLE;
$level = 0;
} else if (version_compare($highestVersion, $toVersion['version']) === 0) {
if (isset($versionPointer[$highestVersion][self::STAGE_STABLE]) && $toVersion['stage'] === self::STAGE_STABLE) {
$stage = self::STAGE_STABLE;
} else if (isset($versionPointer[$highestVersion][self::STAGE_RC]) &&
in_array($toVersion['stage'], array(self::STAGE_RC, self::STAGE_STABLE))) {
$stage = self::STAGE_RC;
} else if (isset($versionPointer[$highestVersion][self::STAGE_BETA]) &&
in_array($toVersion['stage'], array(self::STAGE_RC, self::STAGE_STABLE, self::STAGE_BETA))) {
$stage = self::STAGE_BETA;
} else if (isset($versionPointer[$highestVersion][self::STAGE_ALPHA]) &&
in_array($toVersion['stage'], array(self::STAGE_RC, self::STAGE_STABLE, self::STAGE_BETA, self::STAGE_ALPHA))) {
$stage = self::STAGE_ALPHA;
} else {
break;
}
$level = max(array_keys($versionPointer[$highestVersion][$stage]));
} else {
throw new RuntimeException("Invalid version value.");
}
$currentVersion = array(
'version' => $highestVersion,
'stage' => $stage,
'level' => $level
);
$this->enqueue(array($currentVersion, $versionPointer[$highestVersion][$stage][$level]));
}
$this->_finalVersion = $currentVersion;
}
protected function _analyzePath($path)
{
$iterator = new DirectoryIterator($path);
foreach ($iterator as $file) {
if ($file->isDir() || $file->isDot()) {
continue;
}
if (!preg_match(self::PCRE_FILE_PATTERN, $file->getBasename('.php'), $matches)) {
continue;
}
switch ($matches['action']) {
case self::MODE_INSTALL:
$this->_addInstallFile(
$file->getPathname(),
$matches['version1'],
(isset($matches['stage1']) && !empty($matches['stage1']) ? $matches['stage1'] : self::STAGE_STABLE),
(isset($matches['level1']) && !empty($matches['level1']) ? (int) $matches['level1'] : 0)
);
break;
case self::MODE_UNINSTALL:
$this->_addUninstallFile(
$file->getPathname(),
$matches['version1'],
(isset($matches['stage1']) && !empty($matches['stage1']) ? $matches['stage1'] : self::STAGE_STABLE),
(isset($matches['level1']) && !empty($matches['level1']) ? (int) $matches['level1'] : 0)
);
break;
case self::MODE_UPGRADE:
$this->_addUpgradeFile(
$file->getPathname(),
$matches['version1'],
$matches['version2'],
(isset($matches['stage1']) && !empty($matches['stage1']) ? $matches['stage1'] : self::STAGE_STABLE),
(isset($matches['stage2']) && !empty($matches['stage2']) ? $matches['stage2'] : self::STAGE_STABLE),
(isset($matches['level1']) && !empty($matches['level1']) ? (int) $matches['level1'] : 0),
(isset($matches['level2']) && !empty($matches['level2']) ? (int) $matches['level2'] : 0)
);
break;
case self::MODE_DOWNGRADE:
$this->_addDowngradeFile(
$file->getPathname(),
$matches['version1'],
$matches['version2'],
(isset($matches['stage1']) && !empty($matches['stage1']) ? $matches['stage1'] : self::STAGE_STABLE),
(isset($matches['stage2']) && !empty($matches['stage2']) ? $matches['stage2'] : self::STAGE_STABLE),
(isset($matches['level1']) && !empty($matches['level1']) ? (int) $matches['level1'] : 0),
(isset($matches['level2']) && !empty($matches['level2']) ? (int) $matches['level2'] : 0)
);
break;
}
}
}
private function _addInstallFile($file, $version, $stage = self::STAGE_STABLE, $level = null)
{
if (!isset($this->_installVersions[$version])) {
$this->_installVersions[$version] = array();
}
if (!isset($this->_installVersions[$version][$stage])) {
$this->_installVersions[$version][$stage] = array();
}
$this->_installVersions[$version][$stage][$level] = $file;
return $this;
}
private function _addUpgradeFile($file, $upperVersion, $lowerVersion, $upperStage = self::STAGE_STABLE, $lowerStage = self::STAGE_STABLE, $upperLevel = null, $lowerLevel = null)
{
if (!isset($this->_upgradeVersions[$upperVersion])) {
$this->_upgradeVersions[$upperVersion] = array();
}
if (!isset($this->_upgradeVersions[$upperVersion][$upperStage])) {
$this->_upgradeVersions[$upperVersion][$upperStage] = array();
}
if (!isset($this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel])) {
$this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel] = array();
}
if (!isset($this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion])) {
$this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion] = array();
}
if (!isset($this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage])) {
$this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage] = array();
}
$this->_upgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage][$lowerLevel] = $file;
return $this;
}
private function _addUninstallFile($file, $version, $stage = self::STAGE_STABLE, $level = null)
{
if (!isset($this->_uninstallVersions[$version])) {
$this->_uninstallVersions[$version] = array();
}
if (!isset($this->_uninstallVersions[$version][$stage])) {
$this->_uninstallVersions[$version][$stage] = array();
}
$this->_uninstallVersions[$version][$stage][$level] = $file;
return $this;
}
private function _addDowngradeFile($file, $upperVersion, $lowerVersion, $upperStage = self::STAGE_STABLE, $lowerStage = self::STAGE_STABLE, $upperLevel = null, $lowerLevel = null)
{
if (!isset($this->_downgradeVersions[$upperVersion])) {
$this->_downgradeVersions[$upperVersion] = array();
}
if (!isset($this->_downgradeVersions[$upperVersion][$upperStage])) {
$this->_downgradeVersions[$upperVersion][$upperStage] = array();
}
if (!isset($this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel])) {
$this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel] = array();
}
if (!isset($this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion])) {
$this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion] = array();
}
if (!isset($this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage])) {
$this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage] = array();
}
$this->_downgradeVersions[$upperVersion][$upperStage][$upperLevel][$lowerVersion][$lowerStage][$lowerLevel] = $file;
return $this;
}
public function count()
{
return count($this->_scripts);
}
public function offsetExists($offset)
{
return array_key_exists($offset, $this->_scripts);
}
public function offsetSet($offset, $value)
{
$this->_scripts[(int) $offset] = $value;
}
public function offsetGet($offset)
{
if ($this->offsetExists($offset)) {
return $this->_scripts[(int) $offset];
}
return null;
}
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
unset($this->_scripts[(int) $offset]);
}
}
public function current()
{
return current($this->_scripts);
}
public function key()
{
return key($this->_scripts);
}
public function next()
{
next($this->_scripts);
}
public function rewind()
{
reset($this->_scripts);
}
public function valid()
{
return (bool) (key($this->_scripts) !== null);
}
public function enqueue($data)
{
$this->_scripts[] = array(
'script' => $data[1],
'version' => $data[0]
);
}
}

View file

@ -0,0 +1,792 @@
<?php
/**
* This file is part of XNova:Legacies
*
* @license Modified BSD
* @see https://github.com/gplanchat/one.platform
*
* Copyright (c) 2009-2010, Grégory PLANCHAT <g.planchat at gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Grégory PLANCHAT nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing One.Platform.
*
*/
$this->setSetupConnection('legacies_setup');
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/aks')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NULL,
`teilnehmer` TEXT NULL,
`flotten` TEXT NULL,
`ankunft` INT UNSIGNED NULL,
`galaxy` TINYINT UNSIGNED NULL,
`system` SMALLINT UNSIGNED NULL,
`planet` TINYINT UNSIGNED NULL,
`eingeladen` INT UNSIGNED NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/aks', 'legacies_read', array('SELECT'))
->grant('legacies/aks', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/aks', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/alliance')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`ally_name` VARCHAR(32) NOT NULL,
`ally_tag` VARCHAR(8) NOT NULL,
`ally_owner` BIGINT UNSIGNED NOT NULL DEFAULT 0,
`ally_register_time` TIMESTAMP NOT NULL,
`ally_description` TEXT NULL,
`ally_web` VARCHAR(255) NULL,
`ally_text` TEXT NULL,
`ally_image` VARCHAR(255) NULL,
`ally_request` TEXT NULL,
`ally_request_waiting` TEXT NULL,
`ally_request_notallow` BOOL NOT NULL DEFAULT FALSE,
`ally_owner_range` VARCHAR(32) NULL,
`ally_ranks` TEXT NULL,
`ally_members` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/alliance', 'legacies_read', array('SELECT'))
->grant('legacies/alliance', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/alliance', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/annonce')} (
`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
`user` TEXT NOT NULL,
`galaxie` TINYINT UNSIGNED NOT NULL,
`systeme` SMALLINT UNSIGNED NOT NULL,
`metala` DECIMAL(65,0) NOT NULL,
`cristala` DECIMAL(65,0) NOT NULL,
`deuta` DECIMAL(65,0) NOT NULL,
`metals` DECIMAL(65,0) NOT NULL,
`cristals` DECIMAL(65,0) NOT NULL,
`deuts` DECIMAL(65,0) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/annonce', 'legacies_read', array('SELECT'))
->grant('legacies/annonce', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/annonce', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/banned')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`who` BIGINT UNSIGNED NOT NULL,
`theme` TEXT NOT NULL,
`who2` BIGINT UNSIGNED NOT NULL,
`time` TIMESTAMP NOT NULL,
`longer` INT UNSIGNED NOT NULL DEFAULT 3600,
`author` BIGINT UNSIGNED NOT NULL,
`email` VARCHAR(100) NOT NULL,
KEY `ID` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/banned', 'legacies_read', array('SELECT'))
->grant('legacies/banned', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/banned', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/buddy')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`sender` BIGINT UNSIGNED NOT NULL,
`owner` BIGINT UNSIGNED NOT NULL,
`active` BOOL NOT NULL DEFAULT TRUE,
`text` TEXT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/buddy', 'legacies_read', array('SELECT'))
->grant('legacies/buddy', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/buddy', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/chat')} (
`messageid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`user` VARCHAR(255) NOT NULL,
`message` TEXT NOT NULL,
`timestamp` TIMESTAMP NOT NULL,
PRIMARY KEY (`messageid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/chat', 'legacies_read', array('SELECT'))
->grant('legacies/chat', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/chat', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/config')} (
`config_name` VARCHAR(64) NOT NULL,
`config_value` TEXT NOT NULL,
UNIQUE KEY (`config_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/config', 'legacies_read', array('SELECT'))
->grant('legacies/config', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/config', 'legacies_setup')
;
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('legacies/config')} (`config_name`, `config_value`) VALUES
('game_speed', '2500'),
('fleet_speed', '2500'),
('resource_multiplier', '1000'),
('Fleet_Cdr', '30'),
('Defs_Cdr', '30'),
('initial_fields', '5000'),
('COOKIE_NAME', 'xnova-legacies'),
('game_name', 'XNova:Legacies'),
('game_disable', '1'),
('close_reason', 'Le jeu est clos pour le moment!'),
('metal_basic_income', '20'),
('crystal_basic_income', '10'),
('deuterium_basic_income', '0'),
('energy_basic_income', '0'),
('BuildLabWhileRun', '0'),
('LastSettedGalaxyPos', '1'),
('LastSettedSystemPos', '1'),
('LastSettedPlanetPos', '1'),
('urlaubs_modus_erz', '1'),
('noobprotection', '1'),
('noobprotectiontime', '5000'),
('noobprotectionmulti', '5'),
('forum_url', 'http://board.xnova-ng.org/'),
('OverviewNewsFrame', '1'),
('OverviewNewsTEXT', 'Bienvenue sur le nouveau serveur XNova Legacies'),
('OverviewExternChat', '0'),
('OverviewExternChatCmd', ''),
('OverviewBanner', '0'),
('OverviewClickBanner', ''),
('ExtCopyFrame', '0'),
('ExtCopyOwner', ''),
('ExtCopyFunct', ''),
('ForumBannerFrame', '0'),
('stat_settings', '1000'),
('link_enable', '0'),
('link_name', ''),
('link_url', ''),
('enable_announces', '1'),
('enable_marchand', '1'),
('enable_notes', '1'),
('bot_name', 'XNoviana Reali'),
('bot_adress', 'xnova@xnova.fr'),
('banner_source_post', '../images/bann.png'),
('ban_duration', '30'),
('enable_bot', '0'),
('enable_bbcode', '1'),
('debug', '0');
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/declared')} (
`declarator` TEXT NOT NULL,
`declared_1` TEXT NOT NULL,
`declared_2` TEXT NOT NULL,
`declared_3` TEXT NOT NULL,
`reason` TEXT NOT NULL,
`declarator_name` TEXT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/declared', 'legacies_read', array('SELECT'))
->grant('legacies/declared', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/declared', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/errors')} (
`error_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`error_sender` VARCHAR(32) NOT NULL,
`error_time` TIMESTAMP NOT NULL,
`error_type` VARCHAR(32) NOT NULL DEFAULT 'unknown',
`error_text` TEXT,
PRIMARY KEY (`error_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/errors', 'legacies_read', array('SELECT'))
->grant('legacies/errors', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/errors', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/fleets')} (
`fleet_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`fleet_owner` BIGINT UNSIGNED NOT NULL,
`fleet_mission` TINYINT UNSIGNED NOT NULL,
`fleet_amount` DECIMAL(65,0) NOT NULL,
`fleet_array` TEXT NULL,
`fleet_start_time` TIMESTAMP NOT NULL,
`fleet_start_galaxy` TINYINT UNSIGNED NOT NULL,
`fleet_start_system` SMALLINT UNSIGNED NOT NULL,
`fleet_start_planet` TINYINT UNSIGNED NOT NULL,
`fleet_start_type` TINYINT UNSIGNED NOT NULL,
`fleet_end_time` TIMESTAMP NOT NULL,
`fleet_end_stay` TIMESTAMP NOT NULL,
`fleet_end_galaxy` TINYINT UNSIGNED NOT NULL,
`fleet_end_system` SMALLINT UNSIGNED NOT NULL,
`fleet_end_planet` TINYINT UNSIGNED NOT NULL,
`fleet_end_type` TINYINT UNSIGNED NOT NULL,
`fleet_taget_owner` BIGINT UNSIGNED NOT NULL,
`fleet_resource_metal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`fleet_resource_crystal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`fleet_resource_deuterium` DECIMAL(65,0) NOT NULL DEFAULT 0,
`fleet_target_owner` BIGINT UNSIGNED NOT NULL,
`fleet_group` BIGINT UNSIGNED NOT NULL,
`fleet_mess` BIGINT UNSIGNED NOT NULL,
`start_time` INT,
PRIMARY KEY (`fleet_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/fleets', 'legacies_read', array('SELECT'))
->grant('legacies/fleets', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/fleets', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/galaxy')} (
`galaxy` TINYINT UNSIGNED NOT NULL,
`system` SMALLINT UNSIGNED NOT NULL,
`planet` TINYINT UNSIGNED NOT NULL,
`id_planet` BIGINT UNSIGNED NOT NULL,
`metal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`crystal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`id_luna` BIGINT UNSIGNED NULL,
`luna` BOOL NOT NULL DEFAULT FALSE,
PRIMARY KEY (`galaxy`, `system`, `planet`),
KEY `galaxy` (`galaxy`),
KEY `system` (`system`),
KEY `planet` (`planet`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/galaxy', 'legacies_read', array('SELECT'))
->grant('legacies/galaxy', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/galaxy', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/iraks')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`zeit` TIMESTAMP NOT NULL,
`galaxy` TINYINT UNSIGNED NOT NULL,
`system` SMALLINT UNSIGNED NOT NULL,
`planet` TINYINT UNSIGNED NOT NULL,
`galaxy_angreifer` TINYINT UNSIGNED NOT NULL,
`system_angreifer` SMALLINT UNSIGNED NOT NULL,
`planet_angreifer` TINYINT UNSIGNED NOT NULL,
`owner` BIGINT UNSIGNED NOT NULL,
`zielid` BIGINT UNSIGNED NOT NULL,
`anzahl` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`primaer` SMALLINT UNSIGNED,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/iraks', 'legacies_read', array('SELECT'))
->grant('legacies/iraks', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/iraks', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/lunas')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_luna` BIGINT UNSIGNED NOT NULL,
`name` VARCHAR(100) NOT NULL DEFAULT 'Lune',
`image` VARCHAR(50) NOT NULL DEFAULT 'mond',
`destruyed` BOOL NOT NULL DEFAULT FALSE,
`id_owner` BIGINT UNSIGNED NOT NULL,
`galaxy` TINYINT UNSIGNED NOT NULL,
`system` SMALLINT UNSIGNED NOT NULL,
`lunapos` TINYINT UNSIGNED NOT NULL,
`temp_min` TINYINT NOT NULL DEFAULT 0,
`temp_max` TINYINT NOT NULL DEFAULT 0,
`diameter` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/lunas', 'legacies_read', array('SELECT'))
->grant('legacies/lunas', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/lunas', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/messages')} (
`message_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`message_owner` BIGINT UNSIGNED NOT NULL,
`message_sender` BIGINT UNSIGNED NOT NULL,
`message_time` TIMESTAMP NOT NULL,
`message_type` TINYINT UNSIGNED NOT NULL,
`message_from` VARCHAR(50),
`message_subject` VARCHAR(150),
`message_text` TEXT,
PRIMARY KEY (`message_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/messages', 'legacies_read', array('SELECT'))
->grant('legacies/messages', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/messages', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/multi')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`player` BIGINT UNSIGNED NOT NULL,
`sharer` BIGINT UNSIGNED NOT NULL,
`reason` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/multi', 'legacies_read', array('SELECT'))
->grant('legacies/multi', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/multi', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/notes')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`owner` BIGINT UNSIGNED NOT NULL,
`time` TIMESTAMP NOT NULL,
`priority` TINYINT UNSIGNED NOT NULL,
`title` VARCHAR(32) NOT NULL,
`TEXT` TEXT NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/notes', 'legacies_read', array('SELECT'))
->grant('legacies/notes', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/notes', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/planets')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`id_owner` BIGINT UNSIGNED NOT NULL,
`id_level` TINYINT UNSIGNED NOT NULL,
`galaxy` TINYINT UNSIGNED NOT NULL,
`system` SMALLINT UNSIGNED NOT NULL,
`planet` TINYINT UNSIGNED NOT NULL,
`last_update` TIMESTAMP NOT NULL,
`planet_type` TINYINT UNSIGNED NOT NULL,
`destruyed` BOOL NOT NULL DEFAULT FALSE,
`b_building` SMALLINT UNSIGNED NOT NULL,
`b_building_id` TEXT NOT NULL,
`b_tech` SMALLINT UNSIGNED NOT NULL,
`b_tech_id` SMALLINT UNSIGNED NOT NULL,
`b_hangar` SMALLINT UNSIGNED NOT NULL,
`b_hangar_id` TEXT NOT NULL,
`b_hangar_plus` SMALLINT UNSIGNED NOT NULL,
`image` VARCHAR(50) NOT NULL DEFAULT 'normaltempplanet01',
`diameter` INT UNSIGNED NOT NULL DEFAULT 12800,
`points` DECIMAL(65,0) NOT NULL DEFAULT 0,
`ranks` BIGINT UNSIGNED NOT NULL,
`field_current` INT UNSIGNED NOT NULL DEFAULT 163,
`field_max` INT UNSIGNED NOT NULL DEFAULT 163,
`temp_min` INT NOT NULL DEFAULT 0,
`temp_max` INT NOT NULL DEFAULT 0,
`metal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`metal_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
`metal_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
`crystal` DECIMAL(65,0) NOT NULL DEFAULT 0,
`crystal_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
`crystal_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
`deuterium` DECIMAL(65,0) NOT NULL DEFAULT 0,
`deuterium_perhour` DECIMAL(65,0) NOT NULL DEFAULT 0,
`deuterium_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
`energy_used` DECIMAL(65,0) NOT NULL DEFAULT 0,
`energy_max` DECIMAL(65,0) NOT NULL DEFAULT 0,
`metal_mine` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`crystal_mine` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`deuterium_sintetizer` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`solar_plant` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`fusion_plant` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`robot_factory` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`nano_factory` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`hangar` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`metal_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`crystal_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`deuterium_store` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`laboratory` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`terraformer` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`ally_deposit` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`silo` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`mondbasis` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`phalanx` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`sprungtor` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`small_ship_cargo` DECIMAL(65,0) NOT NULL DEFAULT 0,
`big_ship_cargo` DECIMAL(65,0) NOT NULL DEFAULT 0,
`light_hunter` DECIMAL(65,0) NOT NULL DEFAULT 0,
`heavy_hunter` DECIMAL(65,0) NOT NULL DEFAULT 0,
`crusher` DECIMAL(65,0) NOT NULL DEFAULT 0,
`battle_ship` DECIMAL(65,0) NOT NULL DEFAULT 0,
`colonizer` DECIMAL(65,0) NOT NULL DEFAULT 0,
`recycler` DECIMAL(65,0) NOT NULL DEFAULT 0,
`spy_sonde` DECIMAL(65,0) NOT NULL DEFAULT 0,
`bomber_ship` DECIMAL(65,0) NOT NULL DEFAULT 0,
`solar_satelit` DECIMAL(65,0) NOT NULL DEFAULT 0,
`destructor` DECIMAL(65,0) NOT NULL DEFAULT 0,
`dearth_star` DECIMAL(65,0) NOT NULL DEFAULT 0,
`battleship` DECIMAL(65,0) NOT NULL DEFAULT 0,
`misil_launcher` DECIMAL(65,0) NOT NULL DEFAULT 0,
`small_laser` DECIMAL(65,0) NOT NULL DEFAULT 0,
`big_laser` DECIMAL(65,0) NOT NULL DEFAULT 0,
`gauss_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0,
`ionic_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0,
`buster_canyon` DECIMAL(65,0) NOT NULL DEFAULT 0,
`small_protection_shield` ENUM('0','1') NOT NULL DEFAULT 0,
`big_protection_shield` ENUM('0','1') NOT NULL DEFAULT 0,
`interceptor_misil` SMALLINT NOT NULL DEFAULT 0,
`interplanetary_misil` SMALLINT NOT NULL DEFAULT 0,
`metal_mine_porcent` TINYINT NOT NULL DEFAULT 10,
`crystal_mine_porcent` TINYINT NOT NULL DEFAULT 10,
`deuterium_sintetizer_porcent` TINYINT NOT NULL DEFAULT 10,
`solar_plant_porcent` TINYINT NOT NULL DEFAULT 10,
`fusion_plant_porcent` TINYINT NOT NULL DEFAULT 10,
`solar_satelit_porcent` TINYINT NOT NULL DEFAULT 10,
`last_jump_time` TIMESTAMP NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/planets', 'legacies_read', array('SELECT'))
->grant('legacies/planets', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/planets', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/rw')} (
`id_owner1` BIGINT UNSIGNED NOT NULL,
`id_owner2` BIGINT UNSIGNED NOT NULL,
`rid` VARCHAR(72) NOT NULL,
`raport` LONGTEXT NOT NULL,
`a_zestrzelona` TINYINT UNSIGNED NOT NULL,
`time` TIMESTAMP NOT NULL,
KEY (`rid`),
UNIQUE KEY `id_owner1` (`id_owner1`,`rid`),
UNIQUE KEY `id_owner2` (`id_owner2`,`rid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/rw', 'legacies_read', array('SELECT'))
->grant('legacies/rw', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/rw', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/statpoints')} (
`id_owner` BIGINT UNSIGNED NOT NULL,
`id_ally` BIGINT UNSIGNED NOT NULL,
`stat_type` TINYINT UNSIGNED NOT NULL,
`stat_code` TINYINT UNSIGNED NOT NULL,
`tech_rank` BIGINT UNSIGNED NOT NULL,
`tech_old_rank` BIGINT UNSIGNED NOT NULL,
`tech_points` DECIMAL(65,0) NOT NULL,
`tech_count` BIGINT UNSIGNED NOT NULL,
`build_rank` BIGINT UNSIGNED NOT NULL,
`build_old_rank` BIGINT UNSIGNED NOT NULL,
`build_points` DECIMAL(65,0) NOT NULL,
`build_count` BIGINT UNSIGNED NOT NULL,
`defs_rank` BIGINT UNSIGNED NOT NULL,
`defs_old_rank` BIGINT UNSIGNED NOT NULL,
`defs_points` DECIMAL(65,0) NOT NULL,
`defs_count` BIGINT UNSIGNED NOT NULL,
`fleet_rank` BIGINT UNSIGNED NOT NULL,
`fleet_old_rank` BIGINT UNSIGNED NOT NULL,
`fleet_points` DECIMAL(65,0) NOT NULL,
`fleet_count` BIGINT UNSIGNED NOT NULL,
`total_rank` BIGINT UNSIGNED NOT NULL,
`total_old_rank` BIGINT UNSIGNED NOT NULL,
`total_points` DECIMAL(65,0) NOT NULL,
`total_count` BIGINT UNSIGNED NOT NULL,
`stat_date` TIMESTAMP NOT NULL,
KEY (`tech_points`),
KEY (`build_points`),
KEY (`defs_points`),
KEY (`fleet_points`),
KEY (`total_points`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/statpoints', 'legacies_read', array('SELECT'))
->grant('legacies/statpoints', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/statpoints', 'legacies_setup')
;
$sql = <<<SQL_EOF
CREATE TABLE IF NOT EXISTS {$this->getTableName('legacies/users')} (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`username` VARCHAR(100) NOT NULL, -- FIXME
`password` VARCHAR(64) NOT NULL, -- FIXME
`email` VARCHAR(200) NOT NULL, -- FIXME
`email_2` VARCHAR(200) NOT NULL, -- FIXME
`lang` VARCHAR(3) NOT NULL DEFAULT 'fr',
`authlevel` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
`sex` ENUM('M','F') NULL DEFAULT NULL,
`avatar` VARCHAR(255) NULL DEFAULT NULL,
`sign` TEXT NULL,
`id_planet` BIGINT UNSIGNED NOT NULL, -- FIXME
`galaxy` TINYINT UNSIGNED NOT NULL, -- FIXME
`system` SMALLINT UNSIGNED NOT NULL, -- FIXME
`planet` TINYINT UNSIGNED NOT NULL, -- FIXME
`current_planet` BIGINT UNSIGNED NOT NULL, -- FIXME
`user_lastip` VARCHAR(16) NOT NULL, -- FIXME
`ip_at_reg` VARCHAR(16) NOT NULL, -- FIXME
`user_agent` TEXT NOT NULL, -- FIXME
`current_page` TEXT NOT NULL, -- FIXME
`register_time` TIMESTAMP NOT NULL, -- FIXME
`onlinetime` TIMESTAMP NOT NULL, -- FIXME
`dpath` VARCHAR(255) NOT NULL, -- FIXME
`design` TINYINT NOT NULL DEFAULT 1, -- FIXME
`noipcheck` BOOL NOT NULL DEFAULT TRUE, -- FIXME
`planet_sort` TINYINT NOT NULL DEFAULT 0, -- FIXME
`planet_sort_order` TINYINT NOT NULL DEFAULT 0, -- FIXME
`spio_anz` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
`settings_tooltiptime` TINYINT UNSIGNED NOT NULL DEFAULT 5, -- FIXME
`settings_fleetactions` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
`settings_allylogo` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
`settings_esp` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
`settings_wri` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
`settings_bud` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
`settings_mis` TINYINT UNSIGNED NOT NULL DEFAULT 1, -- FIXME
`settings_rep` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
`urlaubs_modus` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
`urlaubs_until` TIMESTAMP NOT NULL, -- FIXME
`db_deaktjava` BOOL NOT NULL DEFAULT FALSE, -- FIXME
`new_message` TINYINT UNSIGNED NOT NULL DEFAULT 0, -- FIXME
`fleet_shortcut` TEXT NULL,
`b_tech_planet` INT NOT NULL, -- FIXME
`spy_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`computer_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`military_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`defence_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`shield_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`energy_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`hyperspace_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`combustion_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`impulse_motor_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`hyperspace_motor_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`laser_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`ionic_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`buster_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`intergalactic_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`expedition_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`graviton_tech` TINYINT UNSIGNED NOT NULL, -- FIXME
`ally_id` BIGINT UNSIGNED NOT NULL,
`ally_name` VARCHAR(32) NULL, -- FIXME
`ally_request` BOOL NOT NULL DEFAULT FALSE, -- FIXME
`ally_request_text` TEXT NULL, -- FIXME
`ally_register_time` TIMESTAMP NOT NULL, -- FIXME
`ally_rank_id` BIGINT UNSIGNED NOT NULL, -- FIXME
`current_luna` INT NOT NULL, -- FIXME
`kolorminus` VARCHAR(11) NOT NULL DEFAULT 'red',
`kolorplus` VARCHAR(11) NOT NULL DEFAULT '#00FF00',
`kolorpoziom` VARCHAR(11) NOT NULL DEFAULT 'yellow',
`rpg_geologue` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_amiral` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_ingenieur` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_technocrate` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_espion` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_constructeur` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_scientifique` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_commandant` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_points` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_stockeur` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_defenseur` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_destructeur` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_general` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_bunker` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_raideur` TINYINT UNSIGNED NOT NULL, -- FIXME
`rpg_empereur` TINYINT UNSIGNED NOT NULL, -- FIXME
`lvl_minier` BIGINT UNSIGNED NOT NULL, -- FIXME
`lvl_raid` BIGINT UNSIGNED NOT NULL, -- FIXME
`xpraid` BIGINT UNSIGNED NOT NULL, -- FIXME
`xpminier` BIGINT UNSIGNED NOT NULL, -- FIXME
`raids` BIGINT UNSIGNED NOT NULL, -- FIXME
`p_infligees` DECIMAL(65,0) NOT NULL, -- FIXME
`mnl_alliance` TINYINT UNSIGNED NOT NULL, -- FIXME
`mnl_joueur` TINYINT UNSIGNED NOT NULL, -- FIXME
`mnl_attaque` TINYINT UNSIGNED NOT NULL, -- FIXME
`mnl_spy` TINYINT UNSIGNED NOT NULL, -- FIXME
`mnl_exploit` TINYINT UNSIGNED NOT NULL, -- FIXME
`mnl_transport` TINYINT UNSIGNED NOT NULL, -- FIXME
`mnl_expedition` TINYINT UNSIGNED NOT NULL, -- FIXME
`mnl_general` TINYINT UNSIGNED NOT NULL, -- FIXME
`mnl_buildlist` TINYINT UNSIGNED NOT NULL, -- FIXME
`bana` BOOL NOT NULL DEFAULT FALSE, -- FIXME
`multi_validated` BOOL NOT NULL DEFAULT FALSE, -- FIXME
`banaday` TIMESTAMP NULL DEFAULT NULL, -- FIXME
`raids1` BIGINT UNSIGNED NOT NULL, -- FIXME
`raidswin` BIGINT UNSIGNED NOT NULL, -- FIXME
`raidsloose` BIGINT UNSIGNED NOT NULL, -- FIXME
PRIMARY KEY (`id`),
UNIQUE KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL_EOF;
$this->query($sql);
$this
->grant('legacies/users', 'legacies_read', array('SELECT'))
->grant('legacies/users', 'legacies_write', array('SELECT', 'CREATE', 'UPDATE', 'DELETE'))
->grant('legacies/users', 'legacies_setup')
;
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('legacies/alliance')} (
`id`, `ally_name`, `ally_tag`, `ally_owner`, `ally_register_time`, `ally_description`,
`ally_web`, `ally_text`, `ally_image`, `ally_request`, `ally_request_waiting`,
`ally_request_notallow`, `ally_owner_range`, `ally_ranks`, `ally_members`
)
VALUES
('1', 'Admin', 'Admin', 1, NOW(), 'Administrator alliance', 'http://www.xnova-ng.org/',
'', '', '', '', '', '', '', '')
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
INSERT INTO {$this->getTableName('legacies/users')} (
`id`, `username`, `password`, `email`, `email_2`, `lang`, `authlevel`, `sex`,
`avatar`, `sign`, `id_planet`, `galaxy`, `system`, `planet`, `current_planet`,
`user_lastip`, `ip_at_reg`, `user_agent`, `current_page`, `register_time`,
`onlinetime`, `dpath`, `design`, `noipcheck`, `planet_sort`, `planet_sort_order`,
`spio_anz`, `settings_tooltiptime`, `settings_fleetactions`, `settings_allylogo`,
`settings_esp`, `settings_wri`, `settings_bud`, `settings_mis`, `settings_rep`,
`urlaubs_modus`, `urlaubs_until`, `db_deaktjava`, `new_message`, `fleet_shortcut`,
`b_tech_planet`, `spy_tech`, `computer_tech`, `military_tech`, `defence_tech`,
`shield_tech`, `energy_tech`, `hyperspace_tech`, `combustion_tech`,
`impulse_motor_tech`, `hyperspace_motor_tech`, `laser_tech`, `ionic_tech`,
`buster_tech`, `intergalactic_tech`, `expedition_tech`, `graviton_tech`,
`ally_id`, `ally_name`, `ally_request`, `ally_request_text`, `ally_register_time`,
`ally_rank_id`, `current_luna`, `kolorminus`, `kolorplus`, `kolorpoziom`,
`rpg_geologue`, `rpg_amiral`, `rpg_ingenieur`, `rpg_technocrate`, `rpg_espion`,
`rpg_constructeur`, `rpg_scientifique`, `rpg_commandant`, `rpg_points`, `rpg_stockeur`,
`rpg_defenseur`, `rpg_destructeur`, `rpg_general`, `rpg_bunker`, `rpg_raideur`,
`rpg_empereur`, `lvl_minier`, `lvl_raid`, `xpraid`, `xpminier`, `raids`,
`p_infligees`, `mnl_alliance`, `mnl_joueur`, `mnl_attaque`, `mnl_spy`,
`mnl_exploit`, `mnl_transport`, `mnl_expedition`, `mnl_general`, `mnl_buildlist`,
`bana`, `multi_validated`, `banaday`, `raids1`, `raidswin`, `raidsloose`
)
VALUES
('1', 'Admin', '', '', '', 'fr', '3', NULL, '', '', '1', '1', '1', '1',
'1', '127.0.0.1', '', '', '', '1254743313', '1269391977', '', '1', '1', '0',
'0', '1', '5', '0', '0', '1', '1', '1', '1', '0', '0', '0', '0', '0', '', '0',
'16', '20', '11', '11', '11', '12', '10', '14', '10', '9', '0', '0', '0', '0',
'0', '1', 1, 'Admin', '0', '', NOW(), '0', '0', 'red', '#00FF00', 'yellow', '20',
'20', '10', '10', '0', '3', '3', '0', '27', '2', '2', '0', '0', '0', '0', '0',
'98', '1', '0', '1133583738', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0')
SQL_EOF;
$this->query($sql);

View file

@ -0,0 +1,163 @@
<?php
/**
* This file is part of XNova:Legacies
*
* @license Modified BSD
* @see https://github.com/gplanchat/one.platform
*
* Copyright (c) 2009-2010, Grégory PLANCHAT <g.planchat at gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of Grégory PLANCHAT nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing One.Platform.
*
*/
$this->setSetupConnection('legacies_setup');
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/aks')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/alliance')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/annonce')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/banned')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/buddy')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/chat')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/config')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/declared')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/errors')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/fleets')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/galaxy')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/iraks')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/lunas')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/messages')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/multi')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/notes')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/planets')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/rw')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/statpoints')};
SQL_EOF;
$this->query($sql);
$sql = <<<SQL_EOF
DROP TABLE {$this->getTableName('legacies/users')};
SQL_EOF;
$this->query($sql);

View file

@ -16,7 +16,9 @@ class Legacies_Database
$password = $config['global']['database']['options']['password'];
$database = $config['global']['database']['options']['database'];
self::$_singleton = new self("mysql:dbname={$database};host={$hostname}", $username, $password);
self::$_singleton = new self("mysql:dbname={$database};host={$hostname}", $username, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
}
return self::$_singleton;
}

View file

@ -37,13 +37,16 @@
class Legacies_Empire
{
const TYPE_BUILDING = 'build';
const TYPE_RESEARCH = 'tech';
const TYPE_SHIP = 'fleet';
const TYPE_DEFENSE = 'defense';
const TYPE_SPECIAL = 'special';
const TYPE_OFFICER = 'officier';
const TYPE_PRODUCTION = 'prod';
const TYPE_BUILDING = 'build';
const TYPE_BUILDING_MOON = 'build_moon';
const TYPE_BUILDING_PLANET = 'build_planet';
const TYPE_RESEARCH = 'tech';
const TYPE_SHIP = 'fleet';
const TYPE_DEFENSE = 'defense';
const TYPE_SPECIAL = 'special';
const TYPE_OFFICER = 'officier';
const TYPE_PRODUCTION = 'prod';
const TYPE_FLEET_MISSION = 'mission';
const RESOURCE_METAL = 'metal';
const RESOURCE_CRISTAL = 'cristal';
@ -129,6 +132,18 @@ class Legacies_Empire
const ID_COMBAT_FIREPOWER = 'attack';
const ID_COMBAT_RAPID_FIRE = 'sd';
const ID_MISSION_ATTACK = 1;
const ID_MISSION_GROUP_ATTACK = 2;
const ID_MISSION_TRANSPORT = 3;
const ID_MISSION_STATION = 4;
const ID_MISSION_STATION_ALLY = 5;
const ID_MISSION_SPY = 6;
const ID_MISSION_SETTLE_COLONY = 7;
const ID_MISSION_RECYCLE = 8;
const ID_MISSION_DESTROY = 9;
const ID_MISSION_MISSILES = 10;
const ID_MISSION_EXPEDITION = 15;
public static function getFieldName($id)
{
$fieldsAlias = Legacies_Empire_Model_Game_FieldsAlias::getSingleton();

View file

@ -89,7 +89,7 @@ abstract class Legacies_Empire_Model_BuilderAbstract
{
$this->clearQueue();
$unserialized = unserialize($serialized);
$unserialized = @unserialize($serialized);
if ($unserialized === false) {
$this->_queue = array();
return $this;

View file

@ -49,6 +49,9 @@ class Legacies_Empire_Model_Game_Types
public function is($element, $type)
{
if (!is_array($this->getData($type))) {
return false;
}
return in_array($element, $this->getData($type));
}
}

View file

@ -90,6 +90,28 @@ class Legacies_Empire_Model_Planet
return $this;
}
public function updateBuildingFields()
{
$types = Legacies_Empire_Model_Game_Types::getSingleton();
if ($this->isPlanet()) {
$filter = Legacies_Empire::TYPE_BUILDING_PLANET;
} else if ($this->isMoon()) {
$filter = Legacies_Empire::TYPE_BUILDING_MOON;
} else {
return $this;
}
$usedFields = 0;
foreach ($types[$filter] as $buildingId) {
$usedFields += $this->getElement($buildingId);
}
$this->setData('field_current', $usedFields);
return $this;
}
public function updateResourceProduction($time = null)
{
$types = Legacies_Empire_Model_Game_Types::getSingleton();
@ -121,7 +143,7 @@ class Legacies_Empire_Model_Planet
$level = $this->getData(Legacies_Empire::getFieldName($productionUnit));
$ratio = $this->getData($ratioField);
$element = self::getProducitonElementInstance($productionUnit);
$element = self::getProductionElementInstance($productionUnit);
$productionRatios[$productionUnit] = $element->getProductionRatios($level, $ratio, $this, $this->getUser());
foreach ($productionRatios[$productionUnit] as $resourceId => $resourceProduction) {
@ -216,7 +238,7 @@ class Legacies_Empire_Model_Planet
return $this;
}
public static function getProducitonElementInstance($buildingId)
public static function getProductionElementInstance($buildingId)
{
$production = Legacies_Empire_Model_Game_Production::getSingleton();
@ -232,6 +254,49 @@ class Legacies_Empire_Model_Planet
return self::$_productionInstances[$buildingId];
}
public function getFleetCollection($time = null)
{
$firstCollection = new Legacies_Core_Collection(array('fleet' => 'fleets'));
$firstCollection
->column('*')
->where('fleet.fleet_start_galaxy = :galaxy')
->where('fleet.fleet_start_system = :system')
->where('fleet.fleet_start_planet = :position')
->where('fleet.fleet_start_type = :planet_type')
;
$backCollection = new Legacies_Core_Collection(array('fleet' => 'fleets'));
$backCollection
->column('*')
->where('fleet.fleet_end_galaxy = :galaxy')
->where('fleet.fleet_end_system = :system')
->where('fleet.fleet_end_planet = :position')
->where('fleet.fleet_end_type = :planet_type')
;
$options = array(
'galaxy' => $this->getSystem(),
'system' => $this->getSystem(),
'position' => $this->getPosition(),
'planet_type' => $this->getType()
);
if ($time !== null) {
$options['now'] = $time;
$firstCollection->where('fleet_start_time <= :now');
$backCollection->where('fleet_end_time <= :now');
}
$collection = new Legacies_Core_Collection();
$collection
->setEntityClassName('Legacies_Empire_Model_Fleet')
->union($firstCollection)
->union($backCollection)
->load($options)
;
return $collection;
}
public function getUser()
{
if ($this->_user === null) {
@ -434,7 +499,7 @@ class Legacies_Empire_Model_Planet
'user' => $this->_currentUser
));
$this->_builder->updateQueue();
$this->_builder->updateQueue($time);
// Dispatch event
Legacies::dispatchEvent($this->_eventPrefix . 'update-queue.after', array(
@ -443,6 +508,13 @@ class Legacies_Empire_Model_Planet
'planet' => $this->_currentPlanet,
'user' => $this->_currentUser
));
return $this;
}
public function getBuildingQueue()
{
return $this->_builder;
}
/**
@ -471,6 +543,28 @@ class Legacies_Empire_Model_Planet
return true;
}
/**
* Get the resources needed to build a specific building
*
* @param int $buildingId
* @return bool
*/
public function getResourcesNeeded($buildingId, $level)
{
return $this->_builder->getResourcesNeeded($buildingId, $level);
}
/**
* Get the time needed to build a specific building
*
* @param int $buildingId
* @return bool
*/
public function getBuildingTime($buildingId, $level)
{
return $this->_builder->getBuildingTime($buildingId, $level);
}
public static function registrationListener($eventData)
{
if (isset($eventData['user'])) {

View file

@ -78,13 +78,10 @@ class Legacies_Empire_Model_Planet_Builder
*
* @return Legacies_Empire_Model_Planet_Building_Shipyard
*/
public function updateQueue($time = null)
public function updateQueue($time)
{
$fields = Legacies_Empire_Model_Game_FieldsAlias::getSingleton();
if ($time === null) {
$time = Legacies::now();
}
$elapsedTime = $time - $this->_currentPlanet->getData('b_building');
foreach ($this->getQueue() as $element) {
@ -97,6 +94,7 @@ class Legacies_Empire_Model_Planet_Builder
$this->_currentPlanet->setElement($buildingId, $level);
$this->_currentPlanet->updateResourceProduction($time - $elapsedTime);
$this->_currentPlanet->updateStorages($time - $elapsedTime);
$this->_currentPlanet->updateBuildingFields();
$this->dequeue($element);
Legacies::dispatchEvent('planet.building.level-update', array(

View file

@ -207,13 +207,13 @@ class Legacies_Empire_Model_Planet_Building_Shipyard
/**
* Return the construction queue
* @see Legacies_Empire_Model_Planet_Building_Shipyard_Item
* @see Legacies_Empire_Model_Planet_Building_Shipyard_Builder
*
* @return array
*/
public function getQueue()
public function getBuilder()
{
return $this->_queue;
return $this->_builder;
}
/**

View file

@ -0,0 +1,27 @@
<?php
class Legacies_Empire_Model_Planet_Ship_LightTransport
implements Legacies_Empire_Model_Planet_ShipInterface
{
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE = 4;
public function getBaseSpeed(Legacies_Empire_Model_User $user)
{
$prices = Legacies_Empire_Model_Game_Prices::getSingleton();
if ($user->getElement(Legacies_Empire::ID_RESEARCH_IMPULSE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE) {
return $prices[Legacies_Empire::ID_SHIP_LIGHT_TRANSPORT][Legacies_Empire::SHIPS_CELERITY_PRIMARY];
} else {
return $prices[Legacies_Empire::ID_SHIP_LIGHT_TRANSPORT][Legacies_Empire::SHIPS_CELERITY_SECONDARY];
}
}
public function getSpeedMultiplier(Legacies_Empire_Model_User $user)
{
if ($user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_IMPULSE_DRIVE) {
return pow(1.1, $user->getElement(Legacies_Empire::ID_RESEARCH_COMBUSTION_DRIVE));
} else {
return pow(1.2, $user->getElement(Legacies_Empire::ID_RESEARCH_IMPULSE_DRIVE));
}
}
}

View file

@ -9,4 +9,14 @@ class Legacies_Empire_Model_Planet_Ship_SolarSatellite
Legacies_Empire::RESOURCE_ENERGY => ((floatval($planet->getData('temp_max')) / 4) + 20) * (0.1 * $produtionRatio) * floatval($quantity)
);
}
public function getMaximumSpeed(Legacies_Empire_Model_User $user)
{
return 0;
}
public function getActualMaximumSpeed(Legacies_Empire_Model_User $user)
{
return 0;
}
}

View file

@ -3,10 +3,36 @@
class Legacies_Empire_Model_Planet_Ship_Supernova
implements Legacies_Empire_Model_Planet_ResourceProductionInterface, Legacies_Empire_Model_Planet_ShipInterface
{
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_DRIVE = 20;
const REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_TECHNOLOGY = 15;
public function getProductionRatios($quantity, $produtionRatio, $planet, $user)
{
return array(
Legacies_Empire::RESOURCE_ENERGY => ((floatval($planet->getData('temp_max')) / 4) + 20) * (0.1 * $produtionRatio) * floatval($quantity) * -1250
);
}
public function getBaseSpeed(Legacies_Empire_Model_User $user)
{
$prices = Legacies_Empire_Model_Game_Prices::getSingleton();
if ($user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_DRIVE &&
$user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_TECHNOLOGY) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_TECHNOLOGY) {
return $prices[Legacies_Empire::ID_SHIP_SUPERNOVA][Legacies_Empire::SHIPS_CELERITY_PRIMARY];
} else {
return $prices[Legacies_Empire::ID_SHIP_SUPERNOVA][Legacies_Empire::SHIPS_CELERITY_SECONDARY];
}
}
public function getSpeedMultiplier(Legacies_Empire_Model_User $user)
{
if ($user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_DRIVE &&
$user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_TECHNOLOGY) < self::REQUIREMENT_TO_UPGRADE_CELERITY__RESEARCH_HYPERSPACE_TECHNOLOGY) {
return pow(1.2, $user->getElement(Legacies_Empire::ID_RESEARCH_IMPULSE_DRIVE));
} else {
return pow(1.3, $user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_DRIVE)) *
pow(1.1, $user->getElement(Legacies_Empire::ID_RESEARCH_HYPERSPACE_TECHNOLOGY));
}
}
}

View file

@ -2,4 +2,6 @@
interface Legacies_Empire_Model_Planet_ShipInterface
{
public function getBaseSpeed(Legacies_Empire_Model_User $user);
public function getSpeedMultiplier(Legacies_Empire_Model_User $user);
}

View file

@ -22,6 +22,13 @@ class Legacies_Empire_Model_User
const PLANET_SORT_POSITION = 1;
const PLANET_SORT_NAME = 2;
protected static $_cookieName = self::COOKIE_NAME;
public static function setCookieName($name)
{
self::$_cookieName = $name;
}
public static function factory($id)
{
if ($id === null) {
@ -44,7 +51,7 @@ class Legacies_Empire_Model_User
$session = Legacies::getSession(self::SESSION_KEY);
if ($session->hasData('user_id')) {
$id = intval($session->getData('user_id'));
} else if (Legacies::$request !== null && ($cookie = Legacies::$request->getCookie(self::COOKIE_NAME)) !== null) {
} else if (Legacies::$request !== null && ($cookie = Legacies::$request->getCookie(self::$_cookieName)) !== null) {
$cookieData = unserialize(stripslashes($cookie));
if (is_array($cookieData)) {
$collection = new Legacies_Core_Collection(array('user' => 'users'));
@ -92,8 +99,8 @@ class Legacies_Empire_Model_User
protected function _updateActivity()
{
$this
->setData('request_uri', $_SERVER['REQUEST_URI'])
->setData('remote_addr', $_SERVER['REMOTE_ADDR'])
->setData('current_page', $_SERVER['REQUEST_URI'])
->setData('user_lastip', $_SERVER['REMOTE_ADDR'])
->setData('user_agent', $_SERVER['HTTP_USER_AGENT'])
->setData('onlinetime', time())
->save()
@ -104,7 +111,7 @@ class Legacies_Empire_Model_User
public function logout()
{
if (Legacies::$response !== null) {
Legacies::$response->unsetCookie(self::COOKIE_NAME);
Legacies::$response->unsetCookie(self::$_cookieName);
}
Legacies_Core_Model_Session::destroy();
}
@ -150,7 +157,7 @@ class Legacies_Empire_Model_User
}
if (isset($_POST["rememberme"]) && Legacies::$request !== null) {
Legacies::$response->setCookie(self::COOKIE_NAME, array('id' => $login['id'], 'key' => $login['login_rememberme']), self::COOKIE_LIFETIME);
Legacies::$response->setCookie(self::$_cookieName, array('id' => $login['id'], 'key' => $login['login_rememberme']), self::COOKIE_LIFETIME);
}
self::$_singleton = self::factory($login['id']);
@ -190,6 +197,25 @@ class Legacies_Empire_Model_User
return $user;
}
public function updateCurrentPlanet($planetId)
{
$planetColelction = $this->_preparePlanetCollection()->where('id=:id');
$planetCollection->load(array(
'id' => $planetId,
'user' => $this->getId()
));
if ($planetCollection->count() !== 1) {
return false;
}
$planet = $planetCollection->current();
$this->setData('current_planet', $planet->getId());
return true;
}
public function getCurrentPlanet()
{
$planetId = $this->getData('current_planet');
@ -200,7 +226,7 @@ class Legacies_Empire_Model_User
return Legacies_Empire_Model_Planet::factory($planetId);
}
public function getPlanetCollection()
protected function _preparePlanetCollection()
{
$planetCollection = new Legacies_Core_Collection(array('planet' => 'planets'), 'Legacies_Empire_Model_Planet');
$planetCollection->where('id_owner=:user');
@ -226,6 +252,12 @@ class Legacies_Empire_Model_User
$planetCollection->order('planet.id', $order);
break;
}
return $planetCollection;
}
public function getPlanetCollection()
{
$planetCollection = $this->_preparePlanetCollection();
$planetCollection->load(array(
'user' => $this->getId()