<?php
include_once $PATH_TO_CODE."/script/connect.php";
include_once $PATH_TO_CODE."/script/fonction.php";
include_once $PATH_TO_CODE."/script/update/abstractupdate.class.php";
class DefaultUpdate extends AbstractUpdate {
public function __construct($parArguments, $parPlayer) {
parent::__construct($parArguments, $parPlayer, "default");
}
protected function getRequestToGetModifiedObject($parTime, $locBlockIdsWhereClauseList, $locWhereListForNewBlocks) {
$locAllianceId = $this->player->allianceId;
$locRequestToGetModifiedObject = "SELECT objectId FROM object FORCE KEY(blockId)
WHERE isBackground=0
AND (visibleState=".RealObject::$REAL_OBJECT_VISIBLE_STATE_VISIBLE_BY_ALL." OR allianceId=$locAllianceId)
AND
(
(
timestamp >= $parTime
AND blockId IN $locBlockIdsWhereClauseList
) ";
if($locWhereListForNewBlocks) {
$locRequestToGetModifiedObject .= " OR blockId IN $locWhereListForNewBlocks ";
}
$locRequestToGetModifiedObject .= " )";
return $locRequestToGetModifiedObject;
}
public function echoUpdate() {
//$locBegin = microtime(true);
echo "<defaultModule>";
// echo ((microtime(true) - $locBegin)*1000)."ms<br>";
global $gloObjectManager;
$locAllianceId = $this->player->allianceId;
$locWhereListForNewBlocks = False;
if(count($this->newBlocksId) > 1) {
$locWhereListForNewBlocks = getWhereClauseList($this->newBlocksId);
}
$locBlockIdsWhereClauseList = Block::getStaticBlockIdsWhereClauseList(Block::getBlockIdWithCenterCoord($this->blockX, $this->blockY, $this->blockZ), $this->blockHalfWidth, $this->blockHalfHeight);
if($this->timestamp > 0 && ((time()-$this->timestamp) > Constante::$SYNC_OUT_TIME)) {
$this->timestamp = 0;
}
//Echo timestamp for client
echo time();
echo Constante::$SEP_URL_1;
//TODO : lostOfControlTimer is an dungeon parameter
//Block update
$locRequestToGetModifiedBlock =
"SELECT DISTINCT block.blockId, block.imagePath, player.color, block.lostOfControlTimer
FROM block LEFT JOIN player USING (playerId)
WHERE
(
block.timestamp >= ".($this->timestamp - Constante::$BLOCK_TIMESTAMP_MARGE)."
AND block.blockId IN $locBlockIdsWhereClauseList
)";
if($locWhereListForNewBlocks) {
$locRequestToGetModifiedBlock .= " OR block.blockId IN $locWhereListForNewBlocks";
}
$locRes = executer($locRequestToGetModifiedBlock);
while($row=mysql_fetch_array($locRes))
{
$this->playerColor = $row[2];
if(is_null($this->playerColor == "NULL")) {
$this->playerColor="";
}
echo $row[0].Constante::$SEP_URL_3."".$row[1]."".Constante::$SEP_URL_3.$this->playerColor."".Constante::$SEP_URL_3."".$row[3]."".Constante::$SEP_URL_2;
}
//echo "d".((microtime(true) - $locBegin)*1000)."ms<br>";
//Object update
//TODO : more efficient to have a timestamp on block for object or a timestamp for each object ?
//Send object update
echo Constante::$SEP_URL_1;
$locRequestToGetModifiedObject = $this->getRequestToGetModifiedObject(($this->timestamp -Constante::$OBJECT_TIMESTAMP_MARGE), $locBlockIdsWhereClauseList, $locWhereListForNewBlocks);
$locRes = executer($locRequestToGetModifiedObject);
$locObjectIdList = array();
while($row = mysql_fetch_array($locRes)) {
array_push($locObjectIdList, $row[0]);
}
$locObjectList = $gloObjectManager->getRealObjects($locObjectIdList);
foreach($locObjectList as $locObject) {
//TODO : is it possible to use only DB and not use objectmanager
$locImageParameters = $locObject->getImageParameters(false, $locAllianceId);
echo $locObject->realObjectId.Constante::$SEP_URL_3.$locObject->zoneId.Constante::$SEP_URL_3.$locImageParameters.Constante::$SEP_URL_3.$locObject->displayPriority.Constante::$SEP_URL_2;
}
//echo "e".((microtime(true) - $locBegin)*1000)."ms<br>";
//Deleted object
echo Constante::$SEP_URL_1;
$locRequestToGetDeletedObject =
"SELECT objectId
FROM objectDeleted
WHERE (
(
timestamp >= ".($this->timestamp - Constante::$OBJECT_TIMESTAMP_MARGE)."
AND blockId IN $locBlockIdsWhereClauseList
)";
if($locWhereListForNewBlocks) {
$locRequestToGetDeletedObject .= " OR blockId IN $locWhereListForNewBlocks";
}
$locRequestToGetDeletedObject .= " )";
$locRes = executer($locRequestToGetDeletedObject);
while($row=mysql_fetch_array($locRes)) {
echo $row[0].Constante::$SEP_URL_2;
}
echo Constante::$SEP_URL_1;
if($this->selectionnedId > 0) {
$locSelectionned = $gloObjectManager->getRealObject($this->selectionnedId);
if($locSelectionned && $locSelectionned->isAlive() && $locSelectionned->playerId == $this->player->playerId) {
$locPath = $locSelectionned->getMoveNext();
echo $locSelectionned->zoneId;
for($i = 0; $i < count($locPath); $i++) {
echo Constante::$SEP_URL_2.$locPath[$i];
}
}
}
echo Constante::$SEP_URL_1;
//echo "f".((microtime(true) - $locBegin)*1000)."ms<br>";
//Debug info
/*echo "locUpdateImagePara: $locUpdateImagePara\n";
echo "$locRequestToGetModifiedBlock\n";
echo $this->timestamp;
echo "\n aaa $locWhereListForNewBlocks";
echo "\n selectionnedId: $this->selectionnedId";
*/
echo "</defaultModule>";
}
}
?>