예제 #1
0
 public function install()
 {
     $this->setLevel(GlobalParameters::START_LEVEL);
     $this->setExperience(0);
     $this->setMoney(GlobalParameters::START_MONEY);
     $this->setRealMoney(GlobalParameters::START_REAL_MONEY);
     $this->setEnergy(LevelsGrid::getInstance()->getBaseEnergy(GlobalParameters::START_LEVEL));
     $this->setMaxEnergy(LevelsGrid::getInstance()->getBaseEnergy(GlobalParameters::START_LEVEL));
     $this->setParameterSum($this->getParameterForward() + $this->getParameterHalf() + $this->getParameterSafe());
     $this->trainerId = 0;
     $this->inTeam = 0;
     $this->isInstalled = 1;
     $this->counterWon = 0;
     $this->counterChoose = 0;
     $this->counterLose = 0;
     $this->counterTie = 0;
     $this->isAbleToChoose = $this->getActiveCount() == GlobalParameters::MAX_TEAM ? 1 : 0;
     $sql_template = "INSERT INTO teams (\n    date_reg,\n\n    vk_id,\n    team_name,\n    team_logo_id,\n    auth_key,\n    energy,\n    \n    level,\n    money,\n    money_real,\n    stady_point,\n    in_team,\n    \n    able_to_choose,\n    param_forward,\n    param_half,\n    param_safe,\n    energy_max,\n\n    user_photo,\n    user_year,\n    user_country,\n    user_name,\n\n    stadium_id,\n\n    `country`,\n    `city`,\n    `university`,\n    `param_sum`,\n    `tour_notify`\n\n) VALUES (\n    NOW(),\n\n    %d,\n    '%s',\n    %d,\n    '%s',\n    %d,\n\n    %d,\n    %d,\n    %d,\n    %d,\n    %d,\n\n    %d,\n    " . $this->getParameterForward() . ",\n    " . $this->getParameterHalf() . ",\n    " . $this->getParameterSafe() . ",\n    " . $this->getEnergyMax() . ",\n\n    '" . SQL::getInstance()->real_escape_string($this->userPhoto) . "',\n    %d,\n    %d,\n    '" . SQL::getInstance()->real_escape_string($this->userName) . "',\n\n    " . $this->getStadiumId() . ",\n\n    " . $this->getUserCountry() . ",\n    " . $this->getUserCity() . ",\n    " . $this->getUserUniversity() . ",\n    " . $this->getParameterSum() . ",\n    %d\n     \n)";
     $periodType = RAM::getInstance()->getPeriodType();
     if (empty($periodType)) {
         $tourTimer = TourSatellite::getTimerDate();
         $periodType = $tourTimer->periodType;
         RAM::getInstance()->setPeriodType($periodType);
     }
     $sql = sprintf($sql_template, UserParameters::getUserId(), SQL::getInstance()->real_escape_string($this->teamName), $this->teamLogoId, SQL::getInstance()->real_escape_string(UserParameters::getAuthKey()), $this->getCurrentEnergy(), $this->getLevel(), $this->getMoney(), $this->getRealMoney(), $this->getStudyPoints(), $this->getStudyPointsViaPrize(), 0, $this->isAbleToChoose, $this->userYear, $this->userCountry, $periodType);
     RAM::getInstance()->setTeam($this);
     $result = SQL::getInstance()->query($sql);
     if ($result instanceof ErrorPoint) {
         return $result;
     }
     $sql_template = "INSERT INTO user_actions (\n    date,\n    date_sing_in,\n    vk_id,\n    command\n) VALUES (\n    NOW(),\n    NOW(),\n    %d,\n    '%s') ";
     $sql = sprintf($sql_template, UserParameters::getUserId(), SQL::getInstance()->real_escape_string(GlobalParameters::getCommand()));
     $result = SQL::getInstance()->query($sql);
     if ($result instanceof ErrorPoint) {
         return $result;
     }
 }
 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);
     }
 }