Location: PHPKode > projects > PhpBlock > A9.8/modules/default/imageupdate.php
<?php
include_once "../../site.class.php";
include_once $PATH_TO_CODE."/script/connect.php";
include_once $PATH_TO_CODE."/script/fonction.php";
include_once $PATH_TO_CODE."/script/block.class.php";
include_once $PATH_TO_CODE."/script/zone.class.php";
include_once $PATH_TO_CODE."/modules/default/objectmanager.class.php";

$locUpdateImagePara = getGetPost(Constante::$HTTP_IMAGE_UPDATE_NAME, false);
if(!$locUpdateImagePara) {
	exit;
}

beginPhpSession($locPlayerId);
closeCurrentSession();

$locUpdateImageParaArray = explode(Constante::$SEP_URL_1, $locUpdateImagePara);
if(count($locUpdateImageParaArray) < 6)
{
    echo "NOT ENOUGHT ARGUMENT IN $locUpdateImagePara";
    exit(-1);
}

global $gloObjectManager;
$locPlayer = $gloObjectManager->getPlayer($locPlayerId);
$locAllianceId = $locPlayer->allianceId;

$locBlockX = $locUpdateImageParaArray[0];
$locBlockY = $locUpdateImageParaArray[1];
$locBlockZ = $locUpdateImageParaArray[2];
$locBlockHalfWidth = $locUpdateImageParaArray[3];
$locBlockHalfHeight = $locUpdateImageParaArray[4];
$locTimestamp = $locUpdateImageParaArray[5];
$locNewBlocks = $locUpdateImageParaArray[6];
$locOptions = $locUpdateImageParaArray[7];

if($locTimestamp > 0 && ((time()-$locTimestamp) > Constante::$SYNC_OUT_TIME))
{
    $locTimestamp = 0;
}

//TODO : as soon scrolling is activated send equally the center which is used for this update ! (scrolling change the center, and client will not have image name based on the source image but on his position in the screen. A translation will be done on client side.

//Echo timestamp for client
echo time();

echo Constante::$SEP_URL_1;
//Echo current money
//echo $locPlayer->cash;

//echo Constante::$SEP_URL_1;

$locWhereListForNewBlocks = False;
$locNewBlockIds = explode(Constante::$SEP_URL_2, $locNewBlocks);
if(count($locNewBlockIds) > 1) {
    $locWhereListForNewBlocks = getWhereClauseList($locNewBlockIds);
}

$locNewBlockIds = getWhereClauseList($locNewBlockIds);

$locBlockIdsWhereClauseList = Block::getStaticBlockIdsWhereClauseList(Block::getBlockIdWithCenterCoord($locBlockX, $locBlockY, $locBlockZ), $locBlockHalfWidth, $locBlockHalfHeight);

//Block update
$locRequestToGetModifiedBlock =
    "SELECT DISTINCT block.blockId, block.imagePath, player.color
    FROM block LEFT JOIN player USING (playerId)
    WHERE
    (
        block.timestamp >= ".($locTimestamp - 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))
{
    $locPlayerColor = $row[2];
    if(is_null($locPlayerColor == "NULL")) {
        $locPlayerColor="";
    }
    echo $row[0].Constante::$SEP_URL_3."".$row[1]."".Constante::$SEP_URL_3.$locPlayerColor.Constante::$SEP_URL_2;
}

//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 = "SELECT objectId FROM object WHERE isBackground=0 AND (visibleState=".RealObject::$REAL_OBJECT_VISIBLE_STATE_VISIBLE_BY_ALL." OR allianceId=$locAllianceId) AND
    (
        (
                timestamp >= ".($locTimestamp -Constante::$OBJECT_TIMESTAMP_MARGE)."
            AND blockId IN $locBlockIdsWhereClauseList
        )";
if($locWhereListForNewBlocks) {
    $locRequestToGetModifiedObject .= " OR blockId IN $locWhereListForNewBlocks";
}
$locRequestToGetModifiedObject .= " )";
    
$locRes = executer($locRequestToGetModifiedObject);
while($row=mysql_fetch_array($locRes))
{
    //TODO : is it possible to use only DB and not use objectmanager
    $locObject = $gloObjectManager->getRealObject($row[0]);
    $locImageParameters = $locObject->getImageParameters();
    echo  $locObject->realObjectId.Constante::$SEP_URL_3.$locObject->zoneId.Constante::$SEP_URL_3.$locImageParameters.Constante::$SEP_URL_3.$locObject->displayPriority.Constante::$SEP_URL_2;
}

//Deleted object
echo Constante::$SEP_URL_1;
$locRequestToGetDeletedObject =
    "SELECT objectId
    FROM objectDeleted
    WHERE (
    (
            timestamp >= ".($locTimestamp - 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;
//Debug info
//echo "$locRequestToGetModifiedBlock\n";
//echo $locTimestamp;
//echo "\n aaa $locWhereListForNewBlocks";
?>
Return current item: PhpBlock