예제 #1
0
파일: game.php 프로젝트: sherdog/wnd
 public function gamedata($playerID = null, $return = false)
 {
     Validate::player($playerID);
     //we are going to pass all data's
     $array = array();
     //this is what we store the data in.
     $player = new PlayerModel();
     $level = new LevelModel();
     $playerLevel = new PlayerLevelModel($playerID);
     $store = new StoreModel();
     $abModel = new ABModel();
     $rankModel = new RankModel();
     $array['status'] = 'ok';
     $array['player'] = $player->getPlayerData(array($playerID, false));
     $array['featuretests'] = $abModel->getTests($playerID);
     $array['scores'] = $playerLevel->load($playerID);
     $array['stores'] = $store->getStores();
     $array['gifts'] = $player->getGifts($playerID);
     $array['liferequests'] = $player->getRequests($playerID);
     $array['levels'] = $level->getLevelData();
     $array['ranks'] = $rankModel->getRanks();
     $levelData = null;
     $tmpObject = null;
     if ($return) {
         return $array;
     } else {
         $this->printJson($array);
     }
 }
예제 #2
0
파일: level.php 프로젝트: sherdog/wnd
 public function save_level($playerID)
 {
     Validate::player($playerID);
     if ($_POST['payload'] == 'true') {
         $_POST['payload'] = Util::hashPost($_POST);
     }
     if (!$_POST) {
         throw new NInjaException("Error in request");
     }
     //so we should receive a payload variable in the request.
     if (!$_POST['payload']) {
         throw new NinjaException("No data was received");
     }
     //clean it up since it seems speaces are getting added
     //TODO make it so I don't have to do this.
     $data = str_replace(' ', '+', $_POST['payload']);
     $levelScore = new PlayerLevelModel($playerID);
     $saved = $levelScore->saveLevelScore($data, $playerID);
     if (!$saved) {
         throw new NinjaException("Error saving player object");
     }
     $scores = $levelScore->load($playerID);
     echo json_encode(array('status' => 'ok', 'player' => $saved, 'scores' => $scores));
 }
예제 #3
0
파일: PlayerModel.php 프로젝트: sherdog/wnd
 public function getPlayerData($playerData = null)
 {
     $playerID = is_array($playerData) ? $playerData[0] : $playerData;
     if ($playerData[0] == null) {
         throw new NinjaException("Error loading player data", 100);
     }
     $this->db->select('*, id AS player_id');
     $this->db->from('player');
     $this->db->where('id', $playerID);
     $query = $this->db->get();
     if (!$query->num_rows()) {
         Log::add('Could not find player with id: ' . $playerID);
         throw new NinjaException("Error finding player with id " . $playerID);
     } else {
         $playerLevel = new PlayerLevelModel();
         $tmpObject = $query->row();
         $tmpObject->belt = $this->getPlayerBelt($tmpObject->xp);
         //check if birthday.
         $birthDate = $tmpObject->dob;
         // Read this from the DB instead
         $time = strtotime($birthDate);
         $tmpObject->isBirthday = date('m-d') == date('m-d', $time) ? 1 : 0;
         $diffSeconds = time() - strtotime($tmpObject->last_life_purchase);
         //it'll be a negative number
         $tmpObject->can_purchase_lives_in = max(self::MAX_TIME_BETWEEN_PURCHASES - $diffSeconds, 0);
         $tmpObject->can_purchase = (int) $tmpObject->lives === 0 && $tmpObject->can_purchase_lives_in === 0 ? 1 : 0;
         $tmpObject->level_scores = $playerLevel->load($playerID);
         $tmpObject->powerups = $this->getPlayerPowerups($playerID);
         $tmpObject->current_rank = (int) $this->getPlayerRank((int) $tmpObject->level);
         $diffSeconds = time() - strtotime($tmpObject->last_life_bonus);
         //it'll be a negative number
         $tmpObject->free_life_in = max(self::MAX_TIME_BETWEEN_FREE_LIVES - $diffSeconds, 0);
         unset($tmpObject->email);
         //remove email from return
         unset($tmpObject->kickstarter_backer);
         unset($tmpObject->xp);
         //don't need it we just send back the belt.
         unset($tmpObject->id);
         return $tmpObject;
     }
 }