public static function setTimerDate($startAt, $finishAt, $periodType = TOUR_NOTIFY_START)
 {
     $data = new stdClass();
     $data->startAt = $startAt;
     $data->finishAt = $finishAt;
     $data->periodType = $periodType;
     file_put_contents(SYSTEM_LOGS . "/" . TOUR_TIMER_FILE, json_encode($data));
     RAM::getInstance()->setTourStart($startAt);
     RAM::getInstance()->setTourFinish($finishAt);
     RAM::getInstance()->setPeriodType($finishAt);
 }
Esempio n. 2
0
 public function save()
 {
     $sql_template = "INSERT INTO sponsors (\n    sponsor_id,\n    vk_id\n) VALUES (\n    %d,\n    %d\n)";
     $sql = sprintf($sql_template, $this->getId(), UserParameters::getUserId());
     $SQLResult = SQL::getInstance()->query($sql);
     if ($SQLResult instanceof ErrorPoint) {
         return $SQLResult;
     }
     $sponsor = RAM::getInstance()->getSponsorById($this->getId(), UserParameters::getUserId());
     if (empty($sponsor)) {
         $currentIndex = RAM::getInstance()->getMaxObjectIndexForTeam(UserParameters::getUserId(), RAM::RAM_TYPE_SPONSOR);
         RAM::getInstance()->setSponsor($this, UserParameters::getUserId(), $currentIndex);
     } else {
         RAM::getInstance()->setSponsor($this, UserParameters::getUserId());
     }
 }
Esempio n. 3
0
 public function initById($stadiumId)
 {
     $stadiumPrototype = RAM::getInstance()->getStadiumPrototypeById($stadiumId);
     if (empty($stadiumPrototype)) {
         $sql_template = "SELECT * FROM item_stadiums WHERE id = '%s'";
         $sql = sprintf($sql_template, intval($stadiumId));
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         if ($SQLresult->num_rows) {
             $object = $SQLresult->fetch_object();
             $this->initFromParameters($object);
             RAM::getInstance()->setStadiumPrototype($object);
         } else {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Не найден стадион по указаному номеру ", ErrorPoint::TYPE_SYSTEM);
         }
     } else {
         $this->initFromParameters($stadiumPrototype);
     }
 }
 public static function initForTeam(&$team)
 {
     $sponsorsStore = array();
     $sponsorRate = 1;
     $sponsorsStore = RAM::getInstance()->getObjectsForTeam($team->getSocialUserId(), RAM::RAM_TYPE_SPONSOR);
     if (count($sponsorsStore) != $team->getSponsorsCount() || $team->getSponsorsCount() == 0) {
         //] || GlobalParameters::$IS_FAKE_ENTER
         // || GlobalParameters::MODER_ID == $team->getSocialUserId()){
         $sponsorsStore = array();
         $sql_template = "SELECT\n    item_sponsors.id,\n    item_sponsors.energy,\n    item_sponsors.required_level\nFROM sponsors\nLEFT JOIN item_sponsors ON item_sponsors.id = sponsors.sponsor_id\nWHERE vk_id = '%s'";
         $sql = sprintf($sql_template, $team->getSocialUserId());
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         $team->setSponsorsCount($SQLresult->num_rows, true);
         if ($SQLresult->num_rows) {
             $counter = 0;
             while ($sponsor = $SQLresult->fetch_object()) {
                 $sponsorInstance = new Sponsor();
                 $sponsorInstance->initFromParameters($sponsor);
                 $sponsorRate *= $sponsorInstance->getEnergy();
                 $sponsorsStore[$sponsorInstance->getId()] = $sponsorInstance;
                 RAM::getInstance()->setSponsor($sponsorInstance, $team->getSocialUserId(), $counter);
                 $counter++;
             }
             if (count($sponsorsStore) > GlobalParameters::SPONSORS_LIMIT) {
                 return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Количество спонсоров превышет допустимого значения " . count($sponsorsStore) . " - " . $SQLresult->num_rows, ErrorPoint::TYPE_SYSTEM);
             }
             $team->setSponsorRate($sponsorRate);
             $team->setMaxEnergy($sponsorRate * LevelsGrid::getInstance()->getBaseEnergy($team->getLevel()));
         }
     } else {
         foreach ($sponsorsStore as $sponsorInstance) {
             $sponsorRate *= $sponsorInstance->getEnergy();
         }
     }
     return $sponsorsStore;
 }
}
/**
 * Обновляем места среди вконтакта
 */
$sql_template = "SELECT vk_id, tour_III FROM teams ORDER BY tour_III DESC  ;";
$sql = $sql_template;
$SQLresultSeelctTeam = SQL::getInstance()->query($sql);
if ($SQLresultSeelctTeam instanceof ErrorPoint) {
    return $SQLresultSeelctTeam;
}
echo "Upgrading for All users, count records: " . $SQLresultSeelctTeam->num_rows . " teams" . PHP_EOL;
if ($SQLresultSeelctTeam->num_rows) {
    $usersPlace = 1;
    $sql = NULL;
    while ($teamObject = $SQLresultSeelctTeam->fetch_object()) {
        $sql_template = 'UPDATE teams SET vk_place = %d WHERE vk_id = %d ;' . PHP_EOL;
        $sql = sprintf($sql_template, $usersPlace, $teamObject->vk_id);
        $SQLresultUpdateTeam = SQL::getInstance()->query($sql);
        if ($SQLresultUpdateTeam instanceof ErrorPoint) {
            break;
        }
        $teamId = $teamObject->vk_id;
        $team = RAM::getInstance()->getTeamById($teamId);
        if (!empty($team)) {
            RAM::getInstance()->changeTeamField($teamId, 'placeVK', $usersPlace);
        }
        usleep(250);
        $usersPlace++;
    }
}
echo str_repeat(" ", 27) . date("[Y-m-d H:i:s.m]") . " Finished " . PHP_EOL;
Esempio n. 6
0
 public function setAllFootballersFriendsCount($sum, $inRAMToo = false)
 {
     $this->footballersFriendsCount = $sum;
     if ($inRAMToo) {
         RAM::getInstance()->changeTeamField($this->getSocialUserId(), 'footballersFriendsCount', $sum);
     }
 }
    die("No connection");
}
$sql_template = "UPDATE teams SET teams.energy = teams.energy + " . GlobalParameters::ENERGY_PER_MATCH . " WHERE teams.energy_max > teams.energy";
$sql = sprintf($sql_template, CRON_UPDATE_ENERGY_RATE);
SQL::getInstance()->query($sql);
$sql_template = "UPDATE teams SET teams.energy = teams.energy_max WHERE teams.energy_max < teams.energy";
$sql = $sql_template;
SQL::getInstance()->query($sql);
//////////////////// Обновляем всех в памяти //////////////////
if (RAM::getInstance()->getIsServerConnected()) {
    $sql_template = "SELECT vk_id, energy FROM teams ;";
    $sql = $sql_template;
    $SQLresultSeelctTeam = SQL::getInstance()->query($sql);
    if ($SQLresultSeelctTeam instanceof ErrorPoint) {
        return $SQLresultSeelctTeam;
    }
    echo "Upgrading for All users, count records: " . $SQLresultSeelctTeam->num_rows . " teams" . PHP_EOL;
    if ($SQLresultSeelctTeam->num_rows) {
        while ($teamObject = $SQLresultSeelctTeam->fetch_object()) {
            $teamId = $teamObject->vk_id;
            $team = RAM::getInstance()->getTeamById($teamId);
            if (!empty($team)) {
                RAM::getInstance()->changeTeamField($teamId, 'currentEnergy', $teamObject->energy);
            }
        }
    }
}
$energyTimer = filemtime(SYSTEM_LOGS . "/cron.updateEnergy.log");
// microtime
RAM::getInstance()->setEnergyLastUpdate($energyTimer);
echo str_repeat(" ", 27) . date("[Y-m-d H:i:s.m]") . ", updated users: " . SQL::getInstance()->affected_rows . " " . PHP_EOL;
Esempio n. 8
0
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/Source/RAMDB.php';
// File with DB functions class
if (!$_SESSION) {
    session_start();
}
// Start the session
$RAM = new RAM();
//instantiating class with DB functions
$action = $_REQUEST["action"];
//variable from GET string - shows what action to take
header("Content-type:text/xml");
//setting the content type of the response document to XML
echo '<?xml version="1.0"?><data>';
//setting the root xml tag in the response document
switch ($action) {
    case "AddRAM":
        $status = $RAM->AddRAM($_REQUEST['pkRAMID'], $_REQUEST['RAM'], $_REQUEST['Make']);
        //
        echo '<status><![CDATA[' . $status[0] . ']]></status>';
        //output login status
        echo '<Name><![CDATA[' . $status[1] . ']]></Name>';
        //output login status
        break;
    case "ChangeRAM":
        $status = $RAM->ChangeRAM($_REQUEST['pkRAMID'], $_REQUEST['RAM']);
        //
        echo '<status><![CDATA[' . $status[0] . ']]></status>';
        //output login status
        echo '<Name><![CDATA[' . $status[1] . ']]></Name>';
Esempio n. 9
0
 function deleteSponsor($entryId, $teamID)
 {
     if (!$this->isRAMEnabled) {
         return null;
     }
     $sponsor = RAM::getInstance()->getSponsorById($entryId, $teamID);
     if ($sponsor === false) {
     } else {
         $linkName = $this->get(RAM::RAM_TYPE_SPONSOR . "_" . $teamID . "_" . $entryId);
         if ($linkName === false) {
             return $linkName;
         }
         $this->set($linkName, null);
     }
 }
 public function action()
 {
     $actionResult = NULL;
     track_stats();
     // Отслеживаем производительность
     $shopItemInDB = FootballerSatellite::getFromStoreById($this->parameters->peopleId, $this->parameters->line);
     if ($shopItemInDB instanceof ErrorPoint) {
         return $shopItemInDB;
     }
     if (isset($this->parameters->line) && $this->parameters->line == TYPE_FOOTBALLER_TEAMLEAD_CODE) {
         $structure = new TrainerPrototype($shopItemInDB);
     } else {
         $structure = new FootballerPrototype();
         $structure->init($shopItemInDB, $this->parameters);
     }
     track_stats();
     // Отслеживаем производительность
     if ($this->parameters->isInGame && $structure->getRequiredLevel() > $this->teamProfile->getLevel()) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Для соверщения этой операции недостаточно уровня. У пользователя " . $this->teamProfile->getLevel() . " а надо " . $structure->getRequiredLevel(), ErrorPoint::TYPE_USER);
     }
     $tourBonus = 1;
     if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() > 0 && $this->teamProfile->getTourBonusTime() > time()) {
         $tourBonus = $this->teamProfile->getTourBonus();
         $tourBonus -= 1;
         $tourBonus = 1 - $tourBonus;
     }
     track_stats();
     // Отслеживаем производительность
     if ($tourBonus == 0) {
         $tourBonus = 1;
     }
     if ($this->parameters->isInGame) {
         if ($structure->getPrice() * $tourBonus > $this->teamProfile->getMoney()) {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER);
         }
     } else {
         if ($structure->getRealPrice() * $tourBonus > $this->teamProfile->getRealMoney()) {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER);
         }
     }
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     if ($structure instanceof TrainerPrototype) {
         $this->teamProfile->setTrainer($structure->getId());
         track_stats();
         // Отслеживаем производительность
     } else {
         if ($this->teamProfile->getFootballerById($structure->getId())) {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Данный футболист уже в вашем клубе", ErrorPoint::TYPE_USER);
         }
         track_stats();
         // Отслеживаем производительность
         $footballerInstance = new Footballer();
         $actionResult = $footballerInstance->add($structure, $this->teamProfile->getActiveCount());
         if ($actionResult instanceof ErrorPoint) {
             SQL::getInstance()->rollback();
             return $actionResult;
         }
         track_stats();
         // Отслеживаем производительность
         if ($footballerInstance->getIsActive()) {
             switch ($footballerInstance->getType()) {
                 case TYPE_FOOTBALLER_FORWARD_CODE:
                     $this->teamProfile->setParameterForward($this->teamProfile->getParameterForward() + $footballerInstance->getLevel());
                     break;
                 case TYPE_FOOTBALLER_SAFER_CODE:
                 case TYPE_FOOTBALLER_GOALKEEPER_CODE:
                     $this->teamProfile->setParameterSafe($this->teamProfile->getParameterSafe() + $footballerInstance->getLevel());
                     break;
                 case TYPE_FOOTBALLER_HALFSAFER_CODE:
                     $this->teamProfile->setParameterHalf($this->teamProfile->getParameterHalf() + $footballerInstance->getLevel());
                     break;
             }
         }
         $this->result['isActive'] = $footballerInstance->getIsActive();
         $this->result['teamParameters'] = array("Forward" => $this->teamProfile->getParameterForward(), "Safe" => $this->teamProfile->getParameterSafe(), "Half" => $this->teamProfile->getParameterHalf());
         $this->teamProfile->addFootballerToStore($footballerInstance);
         track_stats();
         // Отслеживаем производительность
     }
     if ($this->parameters->isInGame) {
         $this->teamProfile->setMoney($this->teamProfile->getMoney() - $structure->getPrice() * $tourBonus);
     } else {
         $this->teamProfile->setRealMoney($this->teamProfile->getRealMoney() - $structure->getRealPrice() * $tourBonus);
     }
     $actionResult = $this->teamProfile->save();
     track_stats();
     // Отслеживаем производительность
     RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersCount', $this->teamProfile->getAllFootballersCount() + 1);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
 private function getFriendsTeams()
 {
     $this->result['teams'] = array();
     $this->result['news'] = array();
     $this->result['rating'] = array();
     if ($this->parameters->groupSourceId) {
         logGroupSource($this->parameters->groupSourceId);
     }
     $needToUpgrade = false;
     $userCountry = intval($this->parameters->userCountry);
     $userCity = intval($this->parameters->userCity);
     $userUniversity = intval($this->parameters->userUniversity);
     track_stats();
     // Отслеживаем производительность
     if ($userCountry != $this->teamProfile->getUserCountry()) {
         $this->teamProfile->setUserCountry($userCountry);
         $needToUpgrade = true;
     }
     if ($userCity != $this->teamProfile->getUserCity()) {
         $this->teamProfile->setUserCity($userCity);
         $needToUpgrade = true;
     }
     if ($userUniversity != $this->teamProfile->getUserUniversity()) {
         $this->teamProfile->setUserUniversity($userUniversity);
         $needToUpgrade = true;
     }
     if (isset($this->parameters->groupBonusNeeded) && $this->parameters->groupBonusNeeded == 1 && $this->teamProfile->getInGroup() == 0) {
         $this->teamProfile->setInGroup(1);
         $this->teamProfile->setRealMoney($this->teamProfile->getRealMoney() + GlobalParameters::GROUP_BONUS_REAL);
         $needToUpgrade = true;
     }
     track_stats();
     // Отслеживаем производительность
     if ($needToUpgrade) {
         $actionResult = $this->teamProfile->save();
         if ($actionResult instanceof ErrorPoint) {
             return $actionResult;
         }
     }
     if ($this->parameters->uids) {
         if (!is_object($this->parameters->uids)) {
             $this->parameters->uids = str_replace('\\\\', '', $this->parameters->uids);
             $this->parameters->uids = str_replace('\\"', '', $this->parameters->uids);
             $this->parameters->uids = json_decode($this->parameters->uids);
         }
         track_stats();
         // Отслеживаем производительность
         $sql_template = "SELECT\n    teams.team_name,\n    teams.param_forward,\n    teams.param_half,\n    teams.param_safe,\n    teams.user_photo,\n    teams.user_name, \n    teams.team_logo_id, \n    teams.vk_id,\n    teams.level\nFROM teams\nWHERE teams.vk_id IN (%s) order by teams.level desc,  teams.counter_won desc ";
         $sql = sprintf($sql_template, Utils::IdsSeparetedByComma($this->parameters->uids));
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         if ($SQLresult->num_rows) {
             $counterPlace = 1;
             while ($teamObject = $SQLresult->fetch_object()) {
                 $team = new Team();
                 $team->initFromDB($teamObject, false);
                 if ($team->getLevel() == 0) {
                     continue;
                 }
                 $team->place = $counterPlace;
                 $teamInJSON = JSONPrepare::team($team);
                 $counterPlace++;
                 $this->result['teams'][] = $teamInJSON;
                 //  $this->result['teams'][] = $teamObject;
             }
         }
     }
     $this->result['news'] = RAM::getInstance()->getNews();
     if (count($this->result['news']) == 0) {
         $sql_template = "SELECT news_sport.* FROM news_sport ORDER BY news_id";
         $sql = $sql_template;
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         if ($SQLresult->num_rows) {
             $counter = 0;
             while ($newsObject = $SQLresult->fetch_object()) {
                 $news = new NewsEntry($newsObject);
                 $news->id = $counter;
                 $this->result['news'][] = $news;
                 RAM::getInstance()->setNews($news);
                 $counter++;
             }
         }
     }
     $leadTeams = RAM::getInstance()->getLeaders();
     if (count($leadTeams) == 0) {
         $sql_template = "SELECT teams.* FROM teams WHERE total_place is not NULL ORDER BY total_place  LIMIT 6";
         $sql = $sql_template;
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         if ($SQLresult->num_rows) {
             $counter = 0;
             while ($teamObject = $SQLresult->fetch_object()) {
                 $team = new Team();
                 $team->initFromDB($teamObject);
                 RAM::getInstance()->setLeader($team, $counter);
                 $counter++;
                 $teamInJSON = JSONPrepare::team($team);
                 $this->result['rating'][] = $teamInJSON;
             }
         }
     } else {
         foreach ($leadTeams as $team) {
             $teamInJSON = JSONPrepare::team($team);
             $this->result['rating'][] = $teamInJSON;
         }
     }
 }
// tour_III = 0
$SQLResultTeams = SQL::getInstance()->query($sql_template);
/*
//////////////////// Обновляем всех в памяти //////////////////

$sql_template = "SELECT vk_id FROM teams ;";
$sql = $sql_template;

$SQLresultSeelctTeam = SQL::getInstance()->query($sql);
if($SQLresultSeelctTeam instanceof ErrorPoint){
    return $SQLresultSeelctTeam;
}

echo "Upgrading for All users, count records: " . $SQLresultSeelctTeam->num_rows . " teams"  . PHP_EOL ;

if($SQLresultSeelctTeam->num_rows){

    while ($teamObject = $SQLresultSeelctTeam->fetch_object()){
 
        $teamId = $teamObject->vk_id;
        $team = RAM::getInstance()->getTeamById($teamId);
        if(!empty($team)){
            RAM::getInstance()->changeTeamField($teamId, 'tourNotify', TOUR_NOTIFY_NEW_NOTIFIED);
      //      RAM::getInstance()->changeTeamField($teamId, 'tourIII', 0); TOUR_NOTIFY_NEW 
        }
    }
}
*/
echo str_repeat(" ", strlen($startString)) . date("[Y-m-d H:i:s.m]") . " Finished " . PHP_EOL;
RAM::getInstance()->flush();
system("php -f " . SYSTEM_PATH . "/utils/cron.updatePlaceInTour.php >> " . SYSTEM_PATH . "/_logs/cron.updatePlaceInTour.log");
        }
        $mainText = strip_tags($mainText);
        $mainText = trim($mainText);
        $mainText = str_replace("ё", "е", $mainText);
        $mainText = str_replace("Ё", "Е", $mainText);
        $subTitle = strip_tags($subTitle);
        $subTitle = trim($subTitle);
        $subTitle = str_replace("ё", "е", $subTitle);
        $subTitle = str_replace("Ё", "Е", $subTitle);
        $destinationName = "news_image_" . $count;
        copyPhotoFile("http://www.euro-football.ru" . $imageLink, $destinationName . ".jpg");
        // $imageLink = substr($imageLink, 0, -4);
        $sql_template = 'INSERT INTO news_sport (title, content, image, sub_title) values("%s", "%s", "%s", "%s");';
        $sql = sprintf($sql_template, SQL::getInstance()->real_escape_string($title), SQL::getInstance()->real_escape_string($mainText), SQL::getInstance()->real_escape_string($destinationName), SQL::getInstance()->real_escape_string($subTitle));
        $SQLresultTemp = SQL::getInstance()->query($sql);
        if ($SQLresultTemp instanceof ErrorPoint) {
            continue;
        }
        $newsObject = new stdClass();
        $newsObject->news_id = $count;
        $newsObject->title = $title;
        $newsObject->content = $mainText;
        $newsObject->image = $destinationName;
        $newsObject->sub_title = $subTitle;
        $news = new NewsEntry($newsObject);
        RAM::getInstance()->setNews($news);
    } else {
        $count--;
    }
}
echo str_repeat(" ", 27) . date("[Y-m-d H:i:s.m]") . " " . PHP_EOL;
 public static function getRandomPrototypes($randomLimit)
 {
     $sql_template = "SELECT * FROM item_footballers WHERE required_level = 1 ORDER BY RAND() ";
     $sql = $sql_template;
     $SQLresult = SQL::getInstance()->query($sql);
     if ($SQLresult instanceof ErrorPoint) {
         return $SQLresult;
     }
     $footballersStore = array();
     $selectedTactic = FootballerSatellite::$tactic[rand(0, count(FootballerSatellite::$tactic) - 1)];
     $fCount = 0;
     if ($SQLresult->num_rows) {
         while ($footballer = $SQLresult->fetch_object()) {
             if ($selectedTactic[$footballer->line] > 0) {
                 self::addFootballer($footballer, $footballersStore);
                 RAM::getInstance()->setFootballerPrototype($footballer);
                 $selectedTactic[$footballer->line]--;
                 $fCount++;
                 $randomLimit--;
                 if ($fCount == GlobalParameters::MAX_TEAM || $randomLimit == 0) {
                     break;
                 }
             }
         }
     }
     return $footballersStore;
 }
 public function action()
 {
     $this->result["isInstalled"] = $this->teamProfile->getIsInstalled();
     track_stats();
     // ќтслеживаем производительность
     $startAt = RAM::getInstance()->getTourStart();
     $finishAt = RAM::getInstance()->getTourFinish();
     track_stats();
     // ќтслеживаем производительность
     if (empty($startAt) || empty($finishAt)) {
         $tourTimer = TourSatellite::getTimerDate();
         $startAt = $tourTimer->startAt;
         $finishAt = $tourTimer->finishAt;
         RAM::getInstance()->setTourStart($startAt);
         RAM::getInstance()->setTourFinish($finishAt);
     }
     track_stats();
     // ќтслеживаем производительность
     $this->result["tourStartAt"] = $startAt;
     $this->result["tourFinishedAt"] = $finishAt;
     $this->result["serverTime"] = time();
     if ($this->teamProfile->getIsInstalled()) {
         track_stats();
         // ќтслеживаем производительность
         $energyTimer = RAM::getInstance()->getEnergyLastUpdate();
         if (empty($energyTimer)) {
             $energyTimer = filemtime(SYSTEM_LOGS . "/cron.updateEnergy.log");
             // microtime
             RAM::getInstance()->setEnergyLastUpdate($energyTimer);
         }
         $this->result['energyTimer'] = $energyTimer;
         track_stats();
         // ќтслеживаем производительность
         if ($this->teamProfile->isNeedDailyBonus()) {
             $dailyBonus = $this->teamProfile->getTotalStadiumBonus();
             $this->teamProfile->setMoney($this->teamProfile->getMoney() + $dailyBonus);
             $actionResult = TeamSatellite::accrueDailyBonus(UserParameters::getUserId(), $this->teamProfile->getMoney());
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
         }
         track_stats();
         // ќтслеживаем производительность
         if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() == 0) {
             $finishBonusAt = time() + 1 * 24 * 60 * 60;
             $actionResult = TeamSatellite::startTourBonus(UserParameters::getUserId(), $finishBonusAt);
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
             $this->teamProfile->setTourBonusTime($finishBonusAt);
         }
         track_stats();
         // ќтслеживаем производительность
         $this->result["teamInfo"] = JSONPrepare::team($this->teamProfile);
         track_stats();
         // ќтслеживаем производительность
         // Ёто надо обновить после отдачи профайла
         if ($this->teamProfile->getTourNotify() == TOUR_NOTIFY_START || $this->teamProfile->getTourNotify() == TOUR_NOTIFY_NEW) {
             $actionResult = TeamSatellite::updateTourNotify(UserParameters::getUserId(), $this->teamProfile->getTourNotify() - 2);
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
         }
         track_stats();
         // ќтслеживаем производительность
         if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() > 0 && $this->teamProfile->getTourBonusTime() < time()) {
             $actionResult = TeamSatellite::eraseTourBonus(UserParameters::getUserId());
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
             $this->teamProfile->setTourBonus(0);
             $this->teamProfile->setTourBonusTime(0);
         }
         track_stats();
         // ќтслеживаем производительность
         if ($this->teamProfile->getStudyPointsViaPrize() > 0) {
             $actionResult = TeamSatellite::resetPrizeStudyPoint(UserParameters::getUserId());
             if ($actionResult instanceof ErrorPoint) {
                 return $actionResult;
             }
         }
         //Utils::forDebug($this->teamProfile);
     }
 }
 public static function startTourBonus($teamId, $finishBonusAt)
 {
     $sql_template = "UPDATE teams SET\n  `tour_bonus_time` = '%s'\nWHERE\n    vk_id = %d";
     $sql = sprintf($sql_template, date("Y-m-d H:i:s", $finishBonusAt), $teamId);
     $SQLResult = SQL::getInstance()->query($sql);
     if ($SQLResult instanceof ErrorPoint) {
         return $SQLResult;
     }
     $team = RAM::getInstance()->getTeamById($teamId);
     if (!empty($team)) {
         RAM::getInstance()->changeTeamField($teamId, 'tourBonusTime', $finishBonusAt);
     }
 }
 public function action()
 {
     track_stats();
     // Отслеживаем производительность
     $actionResult = NULL;
     $sellId = intval($this->parameters->footballerId);
     $footballerInstance = $this->teamProfile->getFootballerById($sellId);
     if ($footballerInstance === false) {
         $errorMessage = "Анулирование контракта невозможно";
         // Utils::forDebug($errorMessage . " sellId : $sellId - UserId : " . $this->teamProfile->getSocialUserId());
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Анулирование контракта невозможно", ErrorPoint::TYPE_USER);
     }
     if ($footballerInstance->getIsActive()) {
         switch ($footballerInstance->getType()) {
             case TYPE_FOOTBALLER_FORWARD_CODE:
                 $this->teamProfile->setParameterForward($this->teamProfile->getParameterForward() - $footballerInstance->getLevel());
                 break;
             case TYPE_FOOTBALLER_SAFER_CODE:
             case TYPE_FOOTBALLER_GOALKEEPER_CODE:
                 $this->teamProfile->setParameterSafe($this->teamProfile->getParameterSafe() - $footballerInstance->getLevel());
                 break;
             case TYPE_FOOTBALLER_HALFSAFER_CODE:
                 $this->teamProfile->setParameterHalf($this->teamProfile->getParameterHalf() - $footballerInstance->getLevel());
                 break;
         }
     }
     track_stats();
     // Отслеживаем производительность
     $this->result['teamParameters'] = array("Forward" => $this->teamProfile->getParameterForward(), "Safe" => $this->teamProfile->getParameterSafe(), "Half" => $this->teamProfile->getParameterHalf());
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     track_stats();
     // Отслеживаем производительность
     $deleteResult = $this->teamProfile->deleteFootballerFromStore($footballerInstance);
     if ($deleteResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $deleteResult;
     }
     track_stats();
     // Отслеживаем производительность
     if ($footballerInstance->getIsFriend()) {
         $markAsFreeResult = TeamSatellite::markFriendAsFree($footballerInstance->getId(), $free = true);
         if ($markAsFreeResult instanceof ErrorPoint) {
             SQL::getInstance()->rollback();
             return $markAsFreeResult;
         }
     }
     track_stats();
     // Отслеживаем производительность
     $footballerPrice = FootballerSatellite::detectPrice($footballerInstance, $this->teamProfile->getStudyPointCost());
     $footballerPrice = $footballerInstance->getIsSuper() ? $footballerPrice * 3 : $footballerPrice;
     $footballerPrice *= 0.25;
     track_stats();
     // Отслеживаем производительность
     $tourBonus = 1;
     if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() > 0 && $this->teamProfile->getTourBonusTime() > time()) {
         $tourBonus = $this->teamProfile->getTourBonus();
         $tourBonus -= 1;
         $tourBonus = 1 - $tourBonus;
     }
     if ($tourBonus == 0) {
         $tourBonus = 1;
     }
     track_stats();
     // Отслеживаем производительность
     $footballerPrice = $footballerPrice * $tourBonus;
     $this->teamProfile->setMoney($this->teamProfile->getMoney() + $footballerPrice);
     $actionResult = $this->teamProfile->save();
     track_stats();
     // Отслеживаем производительность
     if ($footballerInstance->getIsFriend()) {
         RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersFriendsCount', $this->teamProfile->getAllFootballersFriendsCount() - 1);
     } else {
         RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersCount', $this->teamProfile->getAllFootballersCount() - 1);
     }
     track_stats();
     // Отслеживаем производительность
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
 public function action()
 {
     $friendId = intval($this->parameters->friendId);
     if (empty($friendId)) {
         $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Получен не правильный номер друга", ErrorPoint::TYPE_USER);
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $alreadyExists = $this->teamProfile->getFootballerById($friendId);
     if ($alreadyExists) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ваш друг уже играет за вас", ErrorPoint::TYPE_USER);
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = FootballerSatellite::getFootballerOwner($friendId);
     if ($actionResult instanceof ErrorPoint) {
         return $actionResult;
     }
     if ($actionResult !== false) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ваш друг уже числиться в другом футбольном клубе", ErrorPoint::TYPE_USER);
     }
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     $friendFootballer = new Footballer();
     $actionResult = $friendFootballer->addFriend($friendId, NULL, $this->teamProfile->getActiveCount());
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     $addonPoints = 0;
     if (TeamSatellite::isFreshFriend($friendId)) {
         // Даються очьку обучения как среднее по всех футболистов
         if (count($this->teamProfile->getFootballers()) != 0) {
             $addonPoints = floor($this->teamProfile->getFootballerSumLevel() / count($this->teamProfile->getFootballers()));
             $this->teamProfile->setStudyPoints($this->teamProfile->getStudyPoints() + $addonPoints);
             $actionResult = $this->teamProfile->save();
             if ($actionResult instanceof ErrorPoint) {
                 SQL::getInstance()->rollback();
                 return $actionResult;
             }
         }
     }
     track_stats();
     // Отслеживаем производительность
     $actionResult = Team::markTeamAsSelected($friendId);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
         return $actionResult;
     }
     track_stats();
     // Отслеживаем производительность
     RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersFriendsCount', $this->teamProfile->getAllFootballersFriendsCount() + 1);
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
         $this->result['footballer'] = $friendFootballer;
         $this->result['addonStadyPoints'] = $addonPoints;
         $this->result['totalStadyPoints'] = $this->teamProfile->getStudyPoints();
     }
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
Esempio n. 19
0
 public function addFriend($footballerId, $footballerParameters, $activeCount)
 {
     $this->level = 0;
     $this->type = 0;
     $this->id = $footballerId;
     $this->isFriend = true;
     $this->super = false;
     $this->isActive = $activeCount < GlobalParameters::MAX_TEAM ? 1 : 0;
     $result = $this->saveFriend();
     $footballers = null;
     //;RAM::getInstance()->getFootballerFriendById($footballerId);
     if (empty($footballers)) {
         $this->loadFromDB($footballerId);
     } else {
         RAM::getInstance()->setFootballerFriend($this);
     }
     return $result;
 }
Esempio n. 20
0
function logPlaces($vkId, $tourType, $place)
{
    $SQlTeamField = $SQlField = NULL;
    switch ($tourType) {
        case TOUR_TYPE_VK:
            $SQlField = 'vk_place_';
            $SQlTeamField = 'tour_place_vk';
            $classTeamField = 'tourPlaceVK';
            break;
        case TOUR_TYPE_COUNTRY:
            $SQlField = 'country_place_';
            $SQlTeamField = 'tour_place_country';
            $classTeamField = 'tourPlaceCountry';
            break;
        case TOUR_TYPE_CITY:
            $SQlField = 'city_place_';
            $SQlTeamField = 'tour_place_city';
            $classTeamField = 'tourPlaceCity';
            break;
        case TOUR_TYPE_UNI:
            $SQlField = 'uni_place_';
            $SQlTeamField = 'tour_place_uni';
            $classTeamField = 'tourPlaceUniversity';
            break;
    }
    $SQlField .= $place;
    $sql_template = "INSERT INTO tour_placer (\n    vk_id,\n    %s\n) VALUES (\n    %d,\n    0\n) ON DUPLICATE KEY UPDATE %s = %s + 1;";
    $sql = sprintf($sql_template, $SQlField, $vkId, $SQlField, $SQlField);
    SQL::getInstance()->query($sql);
    $sql_template = "UPDATE teams SET %s = %d WHERE vk_id = %d";
    $sql = sprintf($sql_template, $SQlTeamField, $place, $vkId);
    SQL::getInstance()->query($sql);
    $teamId = $vkId;
    $team = RAM::getInstance()->getTeamById($teamId);
    if (!empty($team)) {
        RAM::getInstance()->changeTeamField($teamId, $classTeamField, $place);
    }
}
Esempio n. 21
0
$runningOn = 1;
switch ($runningOn) {
    case 1:
        // Server
        define("SYSTEM_PATH", "/var/server");
        break;
    case 2:
        // Home
        define("SYSTEM_PATH", "..");
        break;
}
include_once SYSTEM_PATH . "/System/settings.php";
include_once SYSTEM_PATH . "/System/function.php";
register_shutdown_function('shutdown');
set_error_handler("handlerError");
// $storeInRAM = RAM::getInstance()->flush();
$teamId = 80384650;
/*
$storeInRAM = RAM::getInstance()->getObjectsForTeam($teamId , RAM::RAM_TYPE_SPONSOR);
Utils::forDebug($storeInRAM);
*/
$storeInRAM = RAM::getInstance()->getObjectsForTeam($teamId, RAM::RAM_TYPE_FOOTBALLER);
// Utils::forDebug($storeInRAM);
print_r($storeInRAM);
/*
$storeInRAM = RAM::getInstance()->getObjectsForTeam($teamId , RAM::RAM_TYPE_FOOTBALLER_FRIEND);
Utils::forDebug($storeInRAM);

$storeInRAM = RAM::getInstance()->getTeamById($teamId);
Utils::forDebug($storeInRAM);
*/