Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
xor72000 committed Aug 20, 2017
2 parents e14aa41 + 542e17f commit 4794398
Show file tree
Hide file tree
Showing 22 changed files with 380 additions and 134 deletions.
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
## [2.1.3] - 2017-08-11
### Added
- Messages when a ruler keeps his role due to election without candidates
- Handling of elections without candidates when the previous chief is dead

### Changed
- Inactive accounts in dev mode are now displayed

### Fixed
- Elections without candidates (empty messages and cycle blocking)
- Empty places resources value out of range
- Ranking diff

### Removed
- Some recurrent user error logging

## [2.1.2] - 2017-08-09
### Added
- Storage of the sectors ownership data in Redis

### Fixed
- Commanders defection when their base is taken
- Display of the incoming attacks in the admiralty
- Sectors ownership data in faction tactical registry
- Ending of recycling missions
- Conversion of the recycling places when there is no resources left

## [2.1.1] - 2017-07-23
### Added
- Spy and combat active report highlighting in the list
- Daily scheduling for notifications cleaning and inactive accounts management
- Daily scheduling for rankings
- Set an INI parameter for max execution time
- Redis session handling

### Fixed
- External invitations for registration
- School experience for commanders
- Access to admin interface
- Empty investments
- Conversation with no recipients error message
- Storage building informations
- Flashbags for queue's ending notification
- Ship recycling
- Parrainage reward
- Commercial shipping travel time
- Capital leaving
- Defenders losses after a successful defense
- Workers access to the session data

## [2.1.0] - 2017-06-01
### Added
- Container class for services and parameters
Expand Down
1 change: 1 addition & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ services:
arguments:
- "%redis_host"
- "%redis_port"
- "%redis_password"
- "%redis_timeout"

exception_listener:
Expand Down
7 changes: 7 additions & 0 deletions system/Classes/Daemon/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ public function treatCommand($data)
$data['data']['date']
);
break;
case 'cancel':
$this->realTimeActionScheduler->cancelFromProcess(
$data['data']['object_class'],
$data['data']['object_id'],
$data['data']['date']
);
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions system/Classes/Library/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Utils {
public static function isAdmin($bindkey) {
$bindkeys = array(
'player1', 'player2', 'gil', 'noe', 'jacky',
'YNbrdEaJpDw8mLZ2u6jYqgt6a',
'jq2Bjf0uKzzE0aMErO6rpBxcg',
'E6GatZvhO1W9seBHU7mgQe49c',
'FaDcTV3lWokXHZO8tXH4divWZ',
Expand Down
2 changes: 0 additions & 2 deletions system/Classes/Process/ProcessGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ProcessGateway
*/
public function writeTo(Process $process, $data)
{
\Asylamba\Classes\Daemon\Server::debug('Writing to Process : ' . json_encode($data));
fwrite($process->getOutput(), json_encode($data) . "\n");
}

Expand All @@ -23,7 +22,6 @@ public function writeTo(Process $process, $data)
*/
public function writeToMaster($data)
{
\Asylamba\Classes\Daemon\Server::debug('Writing to master: ' . json_encode($data));
fwrite(STDOUT, json_encode($data) . "\n");
}

Expand Down
4 changes: 3 additions & 1 deletion system/Classes/Redis/RedisManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ class RedisManager
/**
* @param string $host
* @param int $port
* @param string $password
* @param float $timeout
*/
public function __construct($host, $port, $timeout)
public function __construct($host, $port, $password, $timeout)
{
$this->connection = new \Redis();
$this->connection->connect($host, $port, $timeout);
$this->connection->auth($password);
}

public function __destruct()
Expand Down
24 changes: 24 additions & 0 deletions system/Classes/Scheduler/RealTimeActionScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,36 @@ public function reschedule($object, $date, $oldDate) {
*/
public function cancel($object, $date)
{
if (P_TYPE === 'worker') {
return $this->processGateway->writeToMaster([
'command' => 'cancel',
'data' => [
'object_class' => get_class($object),
'object_id' => $object->id,
'date' => $date
]
]);
}
unset($this->queue[$date][get_class($object) . '-' . $object->id]);

if (empty($this->queue[$date])) {
unset($this->queue[$date]);
}
}

/**
* @param string $class
* @param int $id
* @param string $date
*/
public function cancelFromProcess($class, $id, $date)
{
unset($this->queue[$date][$class . '-' . $id]);

if (empty($this->queue[$date])) {
unset($this->queue[$date]);
}
}

/**
* @return array
Expand Down
2 changes: 2 additions & 0 deletions system/Classes/Task/TechnicalTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class TechnicalTask extends Task
{
const DEFAULT_ESTIMATED_TIME = 10.00;

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 2 additions & 0 deletions system/Classes/Worker/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function init()
$this->container->get('process_manager')->launchProcesses();
$this->container->get('realtime_action_scheduler')->init();
$this->container->get('cyclic_action_scheduler')->init();
$this->container->get('gaia.sector_manager')->initOwnershipData();

$server = $this->container->get('server');
$server->createHttpServer();
$server->listen();
Expand Down
13 changes: 8 additions & 5 deletions system/Modules/Athena/Manager/OrbitalBaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public function changeOwnerById($id, $base, $newOwner, $baseCommanders) {
if (in_array($commander->statement, [Commander::INSCHOOL, Commander::ONSALE, Commander::RESERVE])) {
$commander->rPlayer = $newOwner;
} else if ($commander->statement == Commander::MOVING) {
$commander->statement = Commander::RETIRED;
$this->commanderManager->endTravel($commander, Commander::RETIRED);
$this->realtimeActionScheduler->cancel($commander, $commander->getArrivalDate());
} else {
$commander->statement = Commander::DEAD;
Expand Down Expand Up @@ -715,9 +715,10 @@ public function uRecycling($missionId) {
$targetPlace->resources -= $totalRecycled;
# if there is no more resource
if ($targetPlace->resources <= 0) {
// Avoid out of range errors
$targetPlace->resources = 0;
# the place become an empty place
$targetPlace->resources = 0;
$targetPlace->typeOfPlace = Place::EMPTYZONE;
$this->placeManager->turnAsEmptyPlace($targetPlace);

# stop the mission
$mission->statement = RecyclingMission::ST_DELETED;
Expand Down Expand Up @@ -860,8 +861,10 @@ public function uRecycling($missionId) {

# update u
$mission->uRecycling = Utils::addSecondsToDate($mission->uRecycling, $mission->cycleTime);
// Schedule the next mission
$this->realtimeActionScheduler->schedule('athena.orbital_base_manager', 'uRecycling', $mission, $mission->uRecycling);
// Schedule the next mission if there is still resources
if ($mission->getStatement() !== RecyclingMission::ST_DELETED) {
$this->realtimeActionScheduler->schedule('athena.orbital_base_manager', 'uRecycling', $mission, $mission->uRecycling);
}
} else {
# the place become an empty place
$targetPlace->resources = 0;
Expand Down
16 changes: 8 additions & 8 deletions system/Modules/Atlas/Manager/RankingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public function processPlayersRanking()

$playerRankingRepository = $this->entityManager->getRepository(PlayerRanking::class);

$S_PRM1 = $this->playerRankingManager->getCurrentSession();
$this->playerRankingManager->newSession();
$this->playerRankingManager->loadLastContext();

$ranking = $this->createRanking(true, false);

$playerRoutine->execute(
Expand All @@ -103,10 +107,6 @@ public function processPlayersRanking()
$playerRankingRepository->getDefendersButcherRanking(),
$this->orbitalBaseHelper
);

$S_PRM1 = $this->playerRankingManager->getCurrentSession();
$this->playerRankingManager->newSession();
$this->playerRankingManager->loadLastContext();

$playerRoutine->processResults($ranking, $players, $this->playerRankingManager, $playerRankingRepository);

Expand All @@ -127,6 +127,10 @@ public function processFactionsRanking()
$factionRankingRepository = $this->entityManager->getRepository(FactionRanking::class);
$sectors = $this->entityManager->getRepository(Sector::class)->getAll();

$S_FRM1 = $this->factionRankingManager->getCurrentSession();
$this->factionRankingManager->newSession();
$this->factionRankingManager->loadLastContext();

$ranking = $this->createRanking(false, true);

foreach ($factions as $faction) {
Expand All @@ -138,10 +142,6 @@ public function processFactionsRanking()
$factionRoutine->execute($faction, $playerRankings, $routesIncome, $sectors);
}

$S_FRM1 = $this->factionRankingManager->getCurrentSession();
$this->factionRankingManager->newSession();
$this->factionRankingManager->loadLastContext();

$winningFactionId = $factionRoutine->processResults($ranking, $factions, $this->factionRankingManager);

$this->factionRankingManager->changeSession($S_FRM1);
Expand Down
126 changes: 97 additions & 29 deletions system/Modules/Demeter/Manager/ColorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@ public function uMandate(Color $color, $governmentMembers, $newChief, $idOldChie
$this->conversationMessageManager->add($message);

} else {
$date = new \DateTime($color->dLastElection);
$date->modify('+' . $color->mandateDuration . ' second');
$this->realtimeActionScheduler->schedule('demeter.color_manager', 'uCampaign', $color, $date->format('Y-m-d H:i:s'));

$notif = new Notification();
$notif->dSending = Utils::now();
$notif->setRPlayer($newChief->id);
Expand All @@ -596,41 +600,105 @@ public function uMandate(Color $color, $governmentMembers, $newChief, $idOldChie
$this->conversationMessageManager->add($message);
}
} else {
$noChief = false;
if (($oldChief = $this->playerManager->get($idOldChief)) === null) {
$noChief = true;
$oldChief = $this->playerManager->getByName($color->officialName);
}
/* $date = new DateTime($this->dLastElection);
$date->modify('+' . $this->mandateDuration + self::ELECTIONTIME + self::CAMPAIGNTIME . ' second');
$date = $date->format('Y-m-d H:i:s');
$this->dLastElection = $date;*/
$color->dLastElection = Utils::now();
$color->electionStatement = Color::MANDATE;

if ($color->regime == Color::ROYALISTIC) {
$notif = new Notification();
$notif->dSending = Utils::now();
$notif->setRPlayer($newChief->id);
$notif->setTitle('Votre coup d\'état a échoué');
$notif->addBeg()
->addTxt(' Le peuple ne vous a pas soutenu, l\'ancien gouvernement reste en place.');
$this->notificationManager->add($notif);
switch ($color->regime) {
case Color::DEMOCRATIC:
$date = new \DateTime($color->dLastElection);
$date->modify('+' . $color->mandateDuration . ' second');
$this->realtimeActionScheduler->schedule('demeter.color_manager', 'uCampaign', $color, $date->format('Y-m-d H:i:s'));

if ($idOldChief) {
$notif = new Notification();
$notif->dSending = Utils::now();
$notif->setRPlayer($idOldChief);
$notif->setTitle('Un coup d\'état a échoué');
$notif->addBeg()
->addTxt(' Le joueur ')
->addLnk('embassy/player-' . $newChief->id, $newChief->name)
->addTxt(' a tenté un coup d\'état, celui-ci a échoué.');
$this->notificationManager->add($notif);
}
} elseif ($color->regime == Color::THEOCRATIC) {
if ($idOldChief) {
$notif = new Notification();
$notif->dSending = Utils::now();
$notif->setRPlayer($idOldChief);
$notif->setTitle('Vous avez été nommé Guide');
$notif->addBeg()
->addTxt(' Les Oracles ont parlé, vous êtes toujours désigné par la Grande Lumière pour guider Cardan vers la Gloire.');
$this->notificationManager->add($notif);
}
if ($idOldChief) {
$notif = new Notification();
$notif->dSending = Utils::now();
$notif->setRPlayer($idOldChief);
$notif->setTitle('Vous demeurez ' . ColorResource::getInfo($color->getId(), 'status')[Player::CHIEF - 1]);
$notif->addBeg()
->addTxt(' Aucun candidat ne s\'est présenté oour vous remplacer lors des dernières élections. Par conséquent, vous êtes toujours à la tête de ' . $color->popularName);
$this->notificationManager->add($notif);
}
# création du message
$message = new ConversationMessage();
$message->rConversation = $conv->id;
$message->rPlayer = $convPlayerID;
$message->type = ConversationMessage::TY_STD;
$message->dCreation = Utils::now();
$message->dLastModification = NULL;
$message->content = ' La période électorale est terminée. Aucun candidat ne s\'est présenté pour prendre la tête de ' . $color->popularName . '.';
$message->content .=
($noChief === false)
? '<br>Par conséquent, ' . $oldChief->getName() . ' est toujours au pouvoir.'
: '<br>Par conséquent, le siège du pouvoir demeure vacant.'
;
$this->conversationMessageManager->add($message);
break;
case Color::ROYALISTIC:
$notif = new Notification();
$notif->dSending = Utils::now();
$notif->setRPlayer($newChief->id);
$notif->setTitle('Votre coup d\'état a échoué');
$notif->addBeg()
->addTxt(' Le peuple ne vous a pas soutenu, l\'ancien gouvernement reste en place.');
$this->notificationManager->add($notif);

if ($idOldChief) {
$notif = new Notification();
$notif->dSending = Utils::now();
$notif->setRPlayer($idOldChief);
$notif->setTitle('Un coup d\'état a échoué');
$notif->addBeg()
->addTxt(' Le joueur ')
->addLnk('embassy/player-' . $newChief->id, $newChief->name)
->addTxt(' a tenté un coup d\'état, celui-ci a échoué.');
$this->notificationManager->add($notif);
}
$message = new ConversationMessage();
$message->rConversation = $conv->id;
$message->rPlayer = $convPlayerID;
$message->type = ConversationMessage::TY_STD;
$message->dCreation = Utils::now();
$message->dLastModification = NULL;
$message->content = 'Un coup d\'état a échoué. ' . $oldChief->getName(). ' demeure le dirigeant de ' . $color->popularName . '.';
$this->conversationMessageManager->add($message);
break;
case Color::THEOCRATIC:
$date = new \DateTime($color->dLastElection);
$date->modify('+' . $color->mandateDuration . ' second');
$this->realtimeActionScheduler->schedule('demeter.color_manager', 'uCampaign', $color, $date->format('Y-m-d H:i:s'));

if ($idOldChief) {
$notif = new Notification();
$notif->dSending = Utils::now();
$notif->setRPlayer($idOldChief);
$notif->setTitle('Vous avez été nommé Guide');
$notif->addBeg()
->addTxt(' Les Oracles ont parlé, vous êtes toujours désigné par la Grande Lumière pour guider Cardan vers la Gloire.');
$this->notificationManager->add($notif);
}
$message = new ConversationMessage();
$message->rConversation = $conv->id;
$message->rPlayer = $convPlayerID;
$message->type = ConversationMessage::TY_STD;
$message->dCreation = Utils::now();
$message->dLastModification = NULL;
$message->content = 'Nul ne s\'est soumis au regard des dieux pour conduire ' . $color->popularName . ' vers sa gloire.';
$message->content .=
($noChief === false)
? $oldChief->getName(). ' demeure l\'élu des dieux pour accomplir leurs desseins dans la galaxie.'
: 'Par conséquent, le siège du pouvoir demeure vacant.'
;
$this->conversationMessageManager->add($message);
break;
}
}
$this->entityManager->flush();
Expand Down
Loading

0 comments on commit 4794398

Please sign in to comment.