Updated alliances page, fixed SQL injections (hoegarden)
Fided minor bugs Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
parent
8f0f7a4d46
commit
be8c6a6629
14 changed files with 1317 additions and 1215 deletions
2273
alliance.php
2273
alliance.php
File diff suppressed because it is too large
Load diff
|
|
@ -207,7 +207,7 @@ class Legacies
|
|||
public static function getResponse()
|
||||
{
|
||||
if (self::$_response === null) {
|
||||
self::$_response = new Legacies_Core_Controller_Response();
|
||||
self::$_response = new Legacies_Core_Controller_Response_Http();
|
||||
}
|
||||
return self::$_response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Legacies_Core_Controller_Response
|
||||
class Legacies_Core_Controller_Response_Http
|
||||
extends Legacies_Object
|
||||
{
|
||||
public function __construct()
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ abstract class Legacies_Core_Model
|
|||
{
|
||||
protected $_originalData = array();
|
||||
|
||||
protected $_eventPrefix = 'model';
|
||||
protected $_eventObject = 'model';
|
||||
protected $_eventPrefix = null;
|
||||
protected $_eventObject = null;
|
||||
|
||||
public function __construct(Array $data = array())
|
||||
{
|
||||
|
|
@ -41,16 +41,22 @@ abstract class Legacies_Core_Model
|
|||
|
||||
protected function _beforeSave()
|
||||
{
|
||||
Legacies::dispatchEvent('model.before-save', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.before-save', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent('model.before-save', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.before-save', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _afterSave()
|
||||
{
|
||||
Legacies::dispatchEvent('model.after-save', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.after-save', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent('model.after-save', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.after-save', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -73,16 +79,22 @@ abstract class Legacies_Core_Model
|
|||
|
||||
protected function _beforeLoad()
|
||||
{
|
||||
Legacies::dispatchEvent('model.before-load', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent('model.before-load', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _afterLoad()
|
||||
{
|
||||
Legacies::dispatchEvent('model.after-load', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent('model.after-load', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -104,16 +116,22 @@ abstract class Legacies_Core_Model
|
|||
|
||||
protected function _beforeDelete()
|
||||
{
|
||||
Legacies::dispatchEvent('model.before-delete', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.before-delete', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent('model.before-delete', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.before-delete', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function _afterDelete()
|
||||
{
|
||||
Legacies::dispatchEvent('model.after-delete', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.after-delete', array($this->_eventObject => $this));
|
||||
Legacies::dispatchEvent('model.after-delete', array('model' => $this));
|
||||
|
||||
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
|
||||
Legacies::dispatchEvent($this->_eventPrefix . '.after-delete', array($this->_eventObject => $this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ class Legacies_Database
|
|||
|
||||
protected static $_prefix = null;
|
||||
|
||||
public static $options = array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
public static function getSingleton()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
|
|
@ -21,8 +25,16 @@ class Legacies_Database
|
|||
$port = $config['global']['database']['options']['port'];
|
||||
}
|
||||
|
||||
self::$_singleton = new self("mysql:dbname={$database};host={$hostname};port={$port}", $username, $password, array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
$event = Legacies::dispatchEvent('database.prepare-options', array(
|
||||
'options' => self::$options
|
||||
));
|
||||
|
||||
self::$options = $event->getData('options');
|
||||
|
||||
self::$_singleton = new self("mysql:dbname={$database};host={$hostname};port={$port}", $username, $password, self::$options);
|
||||
|
||||
Legacies::dispatchEvent('database.init', array(
|
||||
'handler' => self::$_singleton
|
||||
));
|
||||
}
|
||||
return self::$_singleton;
|
||||
|
|
|
|||
|
|
@ -769,7 +769,7 @@ class Legacies_Empire_Model_Planet
|
|||
return;
|
||||
}
|
||||
|
||||
$collection = self::_searchMostFreeSystems();
|
||||
$collection = self::searchMostFreeSystems();
|
||||
$collection->limit(1)->load();
|
||||
|
||||
if ($collection->count() == 0) {
|
||||
|
|
@ -832,22 +832,21 @@ class Legacies_Empire_Model_Planet
|
|||
'user' => $user
|
||||
));
|
||||
|
||||
//$planet->save();
|
||||
$planet->save();
|
||||
}
|
||||
}
|
||||
|
||||
protected static function _searchMostFreeSystems($galaxyList = null, $systemList = null)
|
||||
public static function searchMostFreeSystems($galaxyList = null, $systemList = null)
|
||||
{
|
||||
$collection = new Legacies_Core_Collection(array('planet' => 'planets'));
|
||||
$collection = new Legacies_Core_Collection(array('galaxy' => 'galaxy'));
|
||||
$collection
|
||||
->column(array(
|
||||
'galaxy' => 'planet.galaxy',
|
||||
'system' => 'planet.system',
|
||||
'count' => 'COUNT(planet.id)'
|
||||
'galaxy' => 'galaxy.galaxy',
|
||||
'system' => 'galaxy.system',
|
||||
'count' => 'COUNT(*)'
|
||||
))
|
||||
->group('planet.galaxy')
|
||||
->group('planet.system')
|
||||
->where('planet.planet_type=1')
|
||||
->group('galaxy.galaxy')
|
||||
->group('galaxy.system')
|
||||
;
|
||||
|
||||
$config = Legacies_Core_Model_Config::getSingleton();
|
||||
|
|
@ -858,7 +857,7 @@ class Legacies_Empire_Model_Planet
|
|||
|
||||
if ($galaxyList !== null) {
|
||||
array_walk($galaxyList, array(__CLASS__, '_cleanItemRanges'));
|
||||
$collection->where('planet.galaxy IN(' . implode(', ', $galaxyList) . ')');
|
||||
$collection->where('galaxy.galaxy IN(' . implode(', ', $galaxyList) . ')');
|
||||
}
|
||||
|
||||
if ($systemList === null && $config->hasData('user/registration/system_list')) {
|
||||
|
|
@ -867,16 +866,20 @@ class Legacies_Empire_Model_Planet
|
|||
|
||||
if ($systemList !== null) {
|
||||
array_walk($systemList, array(__CLASS__, '_cleanItemRanges'));
|
||||
$collection->where('planet.system IN(' . implode(', ', $systemList) . ')');
|
||||
$collection->where('galaxy.system IN(' . implode(', ', $systemList) . ')');
|
||||
}
|
||||
|
||||
$orders = array(
|
||||
"1.5 / COUNT(planet.id)",
|
||||
"ABS(planet.galaxy - CEIL({$collection->quote(MAX_GALAXY_IN_WORLD)} / 2))",
|
||||
"ABS(planet.system - CEIL({$collection->quote(MAX_SYSTEM_IN_GALAXY)} / 2))"
|
||||
"COUNT(*) / {$collection->quote(MAX_PLANET_IN_SYSTEM)}",
|
||||
"1 + ABS(galaxy.galaxy - CEIL({$collection->quote(MAX_GALAXY_IN_WORLD)} / 2))",
|
||||
"1 + 2 * ABS(galaxy.system - CEIL({$collection->quote(MAX_SYSTEM_IN_GALAXY)} / 2))",
|
||||
"RAND() / 1000",
|
||||
);
|
||||
$collection
|
||||
->order('((' . implode(') * (', $orders) . '))', 'ASC')
|
||||
//->order("ABS(galaxy.system - CEIL({$collection->quote(MAX_SYSTEM_IN_GALAXY)} / 2))", 'ASC')
|
||||
//->order("ABS(galaxy.galaxy - CEIL({$collection->quote(MAX_GALAXY_IN_WORLD)} / 2))", 'ASC')
|
||||
//->order("1.5 / COUNT(*)", 'ASC')
|
||||
->order('RAND()', 'ASC');
|
||||
|
||||
return $collection;
|
||||
|
|
|
|||
|
|
@ -127,9 +127,7 @@ class Legacies_Empire_Model_User
|
|||
|
||||
public function logout()
|
||||
{
|
||||
if (Legacies::$response !== null) {
|
||||
Legacies::$response->unsetCookie(self::$_cookieName);
|
||||
}
|
||||
Legacies::getResponse()->unsetCookie(self::$_cookieName);
|
||||
Legacies_Core_Model_Session::destroy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
class Legacies_Empire_Model_User_Message
|
||||
extends Legacies_Core_Entity_SubTable
|
||||
{
|
||||
protected $_eventObject = 'message';
|
||||
protected $_eventPrefix = 'user.message';
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
$this->_tableName = 'messages';
|
||||
|
|
|
|||
|
|
@ -24,11 +24,12 @@
|
|||
<input type="hidden" name="t" value="<?php echo $this->getData('t')?>">
|
||||
<table width=519>
|
||||
<tr>
|
||||
<td class="c" colspan=2><?php echo $this->getData('Texts')?></td>
|
||||
<td class="c" colspan=3><?php echo $this->getData('Texts')?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><a href="?mode=admin&edit=ally&t=1"><?php echo $this->getData('External_text')?></a></th>
|
||||
<th><a href="?mode=admin&edit=ally&t=2"><?php echo $this->getData('Internal_text')?></a></th>
|
||||
<th><a href="?mode=admin&edit=ally&t=3"><?php echo $this->getData('Request_text')?></a></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class=c colspan=3><?php echo $this->getData('Show_of_request_text')?> (<span id="cntChars">0</span> / 5000 <?php echo $this->getData('characters')?>)</td>
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
<script src="scripts/cntchar.js" type="text/javascript"></script>
|
||||
<br>
|
||||
<form action="alliance.php?mode=admin&edit=requests&show=<?php echo $this->getData('id')?>&sort=0" method="POST">
|
||||
<tr>
|
||||
<th colspan=2><?php echo $this->getData('Request_from')?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan=2><?php echo $this->getData('ally_request_text')?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="c" colspan=2><?php echo $this->getData('Request_responde')?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th><input type="submit" name="action" value="Accepter"></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $this->getData('Motive_optional')?> <span id="cntChars">0</span> / 500 <?php echo $this->getData('characters')?></th>
|
||||
<th><textarea name="text" cols=40 rows=10 onkeyup="javascript:cntchar(500)"></textarea></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th><input type="submit" name="action" value="Refuser"></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan=2> </td>
|
||||
</tr>
|
||||
</form>
|
||||
<tr>
|
||||
<th colspan=2><?php echo $this->getData('Request_from')?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan=2><?php echo $this->getData('ally_request_text')?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="c" colspan=2><?php echo $this->getData('Request_responde')?></td>
|
||||
</tr>
|
||||
<form action="alliance.php?mode=admin&edit=requests&show=<?php echo $this->getData('id')?>&sort=0" method="POST">
|
||||
<tr>
|
||||
<th><?php echo $this->getData('Motive_optional')?> (<span id="cntChars">0</span> / 500 <?php echo $this->getData('characters')?>)</th>
|
||||
<th><textarea name="text" cols=40 rows=10 onkeyup="javascript:cntchar(500)"><?php echo $this->getData('text_apply')?></textarea></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th> </th>
|
||||
|
||||
<th><input type="submit" name="action" value="Accepter">
|
||||
<input type="submit" name="action" value="Refuser">
|
||||
</th>
|
||||
</tr>
|
||||
</form>
|
||||
<tr>
|
||||
<td colspan=2> </td>
|
||||
</tr>
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
<script src="scripts/cntchar.js" type="text/javascript"></script>
|
||||
<br>
|
||||
<h1><?php echo $this->getData('Send_Apply')?></h1>
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ function ShowGalaxyRows ($Galaxy, $System) {
|
|||
global $lang, $planetcount, $CurrentRC, $dpath, $user;
|
||||
|
||||
$Result = "";
|
||||
for ($Planet = 1; $Planet < 16; $Planet++) {
|
||||
for ($Planet = 1; $Planet <= MAX_PLANET_IN_SYSTEM; $Planet++) {
|
||||
unset($GalaxyRowPlanet);
|
||||
unset($GalaxyRowMoon);
|
||||
unset($GalaxyRowPlayer);
|
||||
|
|
|
|||
25
overview.php
25
overview.php
|
|
@ -197,7 +197,30 @@ if (isset($_POST) && !empty($_POST)) {
|
|||
$newMessages = new Legacies_Core_View();
|
||||
$newMessages->setTemplate('empire/overview/messages.phtml');
|
||||
$newMessages['count'] = (int) $count;
|
||||
|
||||
|
||||
/** Gestion des officiers
|
||||
* Update miner and raider level
|
||||
*
|
||||
*/
|
||||
$Xp_Next_Level_Miner = $user->getData('lvl_minier') * 5000;
|
||||
$Xp_Next_Level_Raider = $user->getData('lvl_raid') * 10;
|
||||
$Xp_Miner = $user->getData('xpminier');
|
||||
$Xp_Raider = $user->getData('xpraid');
|
||||
if ($Xp_Miner >= $Xp_Next_Level_Miner) {
|
||||
$HaveNewLevelMineur = "<tr>";
|
||||
$HaveNewLevelMineur .= "<th colspan=4><a href=officier.php>" . $lang['Have_new_level_mineur'] . "</a></th></tr>";
|
||||
$user->setData('lvl_minier', $user->getData('lvl_minier') + 1);
|
||||
$user->setData('rpg_points', $user->getData('rpg_points')+1);
|
||||
$user->save();
|
||||
}
|
||||
if ($Xp_Raider >= $Xp_Next_Level_Raider) {
|
||||
$HaveNewLevelRaider = "<tr>";
|
||||
$HaveNewLevelRaider .= "<th colspan=4><a href=officier.php>". $lang['Have_new_level_raid'] . "</a></th></tr>";
|
||||
$user->setData('lvl_raid', $user->getData('lvl_raid') + 1);
|
||||
$user->setData('rpg_points', $user->getData('rpg_points') +1);
|
||||
$user->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Page display
|
||||
* Refactoring needed
|
||||
|
|
|
|||
2
reg.php
2
reg.php
|
|
@ -48,7 +48,7 @@ if (!empty($_POST) && isset($_POST['username']) && isset($_POST['planet_name'])
|
|||
if (true || count($session->getMessages(false)) === 0) {
|
||||
$user = Legacies_Empire_Model_User::register($_POST['username'], $_POST['email'], $_POST['password']);
|
||||
|
||||
$user->getHomePlanet()->setName($_POST['planet_name']);
|
||||
$user->getHomePlanet()->setName($_POST['planet_name'])->save();
|
||||
}
|
||||
|
||||
if ($user !== null && $user->getId()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue