public function lives($playerID) { //we'll have a payload will have the hash key. Validate::player($playerID); Validate::payload($_POST['payload']); //so we passed the inital validation if ($_POST['payload'] == 'true') { $_POST['payload'] = Util::hashPost($_POST); } if (!$_POST) { throw new NInjaException("Error in request"); } if (!$_POST['payload']) { throw new NinjaException("No data was received"); } $data = str_replace(' ', '+', $_POST['payload']); $playerModel = new PlayerModel(); if ($ack = $playerModel->collectGifts($playerID, $data)) { $response['status'] = 'ok'; $response['value'] = $ack['lives']; $response['requests'] = $ack['requestCount']; $response['remaining'] = 0; //since we cap the # they can request to max lives of 8. } else { $response['status'] = 'error'; $response['message'] = "error saving data"; Log::add('Error updating lives'); } $this->printJson($response); }
public function updateCoins($playerID, $payload = null) { if (!Validate::payload($payload)) { return false; } $player = $this->getPlayerData($playerID); if ($data = NinjaHash::decode($payload)) { Validate::hash($player, $data->key); //make sure it's a legit request. if ((int) $data->coinCount) { $coins = (int) $data->coinCount; } else { $coins = 10; //default cost? f**k I don't know o_O } $this->db->query(sprintf('UPDATE player SET coins = (coins - %s) WHERE id = %s', $coins, $playerID)); return true; } else { Log::add('update Coins failed because the hash wasnt right'); } }