master
Skylar Ittner 8 years ago
parent 22bb8c52ea
commit 8354fc75e5

@ -1,2 +1 @@
## Default .htaccess file
php_value suhosin.srand.ignore 0

@ -6,7 +6,7 @@ require 'onlyloggedin.php';
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
if (is_empty($VARS['locationid'])) {
sendError("No target!", true);
sendError(PLACE_ID_NOT_SENT, true);
}
$place = $database->select('locations', ['locationid', 'teamid', 'owneruuid', 'currentlife', 'maxlife', 'osmid'], ['locationid' => $VARS['locationid']])[0];
@ -14,7 +14,7 @@ $user = $database->select('players', ['level', 'teamid', 'energy', 'maxenergy',
// This (probably) shouldn't happen in normal play
if ($place['teamid'] == $user['teamid']) {
sendError("Cannot attack!", true);
sendError(PLACE_OWNED_BY_SAME_TEAM, true);
}
// The damage formulas
@ -83,7 +83,7 @@ $damage = pow(floor($user['level']), 0.5) * 4 * $type_mod * $terrain_mod * $weat
//$damage = 2 * $userdrain * $TYPE_GRID[$user['teamid']][$place['teamid']];
// Check if action possible
if ($user['energy'] < $userdrain) {
sendError("No life left!", true);
sendError(PLAYER_NO_LIFE_LEFT, true);
}
// Calculate resulting user HP
@ -118,4 +118,4 @@ if ($placehp == 0) {
$database->update('locations', ['currentlife' => $placehp], ['locationid' => $VARS['locationid']]);
}
sendOK(($dolevelup ? "Level up!" : "Success!"));
sendOK(($dolevelup ? PLAYER_LEVEL_UP : PLACE_SUCCESS));

@ -4,18 +4,18 @@ require 'required.php';
require 'onlyloggedin.php';
if (!$database->has('shopitems', ['merchid' => $VARS['merchid']])) {
sendError("That item is not available at this time.", true);
sendError(ITEM_UNAVAILABLE, true);
}
$shopitem = $database->select('shopitems', ['merchid', 'itemid', 'quantity', 'cost'], ['merchid' => $VARS['merchid']])[0];
if (!is_empty($VARS['cost']) && !($shopitem['cost'] == $VARS['cost'])) {
sendError("That item is no longer available at that price.", true);
sendError(ITEM_INCORRECT_PRICE, true);
}
$credits = $database->select('players', ['credits'], ['uuid' => $_SESSION['uuid']])[0]['credits'];
if ($credits < $shopitem['cost']) {
sendError("You don't have enough money!", true);
sendError(PLAYER_NOT_ENOUGH_CREDITS, true);
}
for ($i = 0; $i < $shopitem['quantity']; $i++) {
@ -24,4 +24,4 @@ for ($i = 0; $i < $shopitem['quantity']; $i++) {
$database->update('players', ['credits' => ($credits - $shopitem['cost'])], ['uuid' => $_SESSION['uuid']]);
sendOK("Thanks for your purchase!");
sendOK(ITEM_PURCHASED);

@ -4,7 +4,7 @@ require 'required.php';
require 'onlyloggedin.php';
if (is_empty($VARS['locationid'])) {
sendError("No target!", true);
sendError(PLACE_ID_NOT_SENT, true);
}
$place = $database->select('locations', ['locationid', 'teamid', 'owneruuid', 'currentlife', 'maxlife'], ['locationid' => $VARS['locationid']])[0];
@ -12,11 +12,11 @@ $user = $database->select('players', ['level', 'teamid', 'energy', 'maxenergy',
// This (probably) shouldn't happen in normal play
if ($place['teamid'] == $user['teamid']) {
sendError("Don't attack your own kind!", true);
sendError(PLACE_OWNED_BY_PLAYER_TEAM, true);
}
if ($place['currentlife'] > 0) {
sendError("Cannot claim!", true);
sendError(PLACE_NO_LIFE_CLAIM, true);
}
$userdrain = 5 * floor($user['level']);
@ -25,7 +25,7 @@ $userdrain = 5 * floor($user['level']);
$userhp = $user['energy'] - $userdrain;
// Check if action possible
if ($userhp < 0) {
sendError("No life left!", true);
sendError(PLAYER_NO_LIFE_LEFT, true);
}
// Update the user's health and level
@ -44,4 +44,4 @@ if (floor($userlevel) > floor($user['level'])) {
// Update the place
$database->update('locations', ['currentlife' => 100, 'maxlife' => 100, 'owneruuid' => $_SESSION['uuid'], 'teamid' => $user['teamid']], ['locationid' => $VARS['locationid']]);
sendOK(($dolevelup ? "Level up!" : "Success!"));
sendOK(($dolevelup ? PLAYER_LEVEL_UP : PLACE_SUCCESS));

@ -39,7 +39,7 @@ $returndata = [
];
if (is_empty($origcode)) {
sendError("Bad code!", true);
sendError(BARCODE_INVALID, true);
}
try {
@ -51,7 +51,7 @@ try {
}
if ($database->has('claimedcodes', ["AND" => ['code' => $origcode, 'playeruuid' => $_SESSION['uuid']]])) {
$returndata['messages'][] = ["title" => "Huh?", "text" => "You've already found this code!"];
$returndata['messages'][] = ["title" => BARCODE_ALREADY_FOUND_TITLE, "text" => BARCODE_ALREADY_FOUND_MSG];
} else {
if ($origcode == "http://terranquest.net/#9001") {
// Secret awesome codez
@ -74,7 +74,7 @@ if ($database->has('claimedcodes', ["AND" => ['code' => $origcode, 'playeruuid'
$database->insert('claimedcodes', ['code' => $origcode, 'playeruuid' => $_SESSION['uuid']]);
$itemname = $database->select('items', ['itemname'], ['itemid' => $itemcode])[0]['itemname'];
}
$returndata["messages"][] = ["title" => "Found an item!", "text" => "Found one $itemname"];
$returndata["messages"][] = ["title" => BARCODE_ITEM_FOUND_TITLE, "text" => str_replace("%1", $itemname, BARCODE_ITEM_FOUND_MSG)];
}
die(json_encode($returndata));

@ -7,11 +7,11 @@ $itemuuid = $VARS['itemuuid'];
$player = $VARS['giveto'];
if (is_empty($itemuuid) || !is_numeric($itemuuid) || !$database->has('inventory', ["AND" => ['itemuuid' => $itemuuid, 'playeruuid' => $_SESSION['uuid']]])) {
sendError("Invalid itemuuid.", true);
sendError(INVALID_ITEMID, true);
}
if (is_empty($player) || !$database->has('players', ['nickname' => $player])) {
sendError("Invalid nickname.", true);
sendError(INVALID_NICKNAME, true);
}
$playeruuid = $database->select('players', ['uuid'], ['nickname' => $player])[0]['uuid'];

@ -0,0 +1,71 @@
<?php
/**
* Strings for i18n.
*/
/*
* attackplace.php, claimplace.php, refillplace.php
*/
define("PLACE_ID_NOT_SENT", "No target!");
define("PLACE_OWNED_BY_SAME_TEAM", "Cannot attack!");
define("PLAYER_NO_LIFE_LEFT", "No life left!");
define("PLACE_SUCCESS", "Success!");
define("PLAYER_LEVEL_UP", "Level up!");
define("PLACE_NO_LIFE_CLAIM", "Cannot claim!");
define("PLACE_OWNED_BY_WRONG_TEAM", "Wrong team!");
define("PLACE_OWNED_BY_PLAYER_TEAM", "Don't attack your own kind!");
define("PLACE_HEALTH_IS_FULL", "Full!");
define("PLACE_HEALTH_REFILLED", "Refilled!");
/*
* buyitem.php
*/
define("ITEM_UNAVAILABLE", "That item is not available at this time.");
define("ITEM_INCORRECT_PRICE", "That item is no longer available at that price.");
define("PLAYER_NOT_ENOUGH_CREDITS", "You don't have enough money!");
define("ITEM_PURCHASED", "Thanks for your purchase!");
/*
* code2item.php
*/
define("BARCODE_ALREADY_FOUND_TITLE", "Huh?");
define("BARCODE_ALREADY_FOUND_MSG", "You've already found this code!");
define("BARCODE_INVALID", "Bad code!");
define("BARCODE_ITEM_FOUND_TITLE", "Found an item!");
define("BARCODE_ITEM_FOUND_MSG", "Found one %1");
/*
* giveitem.php, useitem.php
*/
define("INVALID_ITEMID", "Invalid item id.");
define("INVALID_NICKNAME", "Invalid nickname.");
/*
* login.php
*/
define("USERNAME_MISSING", "Missing username.");
define("PASSWORD_MISSING", "Missing password.");
define("ACCOUNT_MISSING", "Account does not exist.");
/*
* munzee.php
*/
define("MUNZEE_LINKED_HTML", "Your Munzee account has been linked to TerranQuest!<br /><a href='about:closeme'>Back to game</a>");
define("MUNZEE_FAILED_HTML", "Munzee is having problems right now. Try again later.<br /><a href='about:closeme'>Back to game</a>");
/*
* onlyloggedin.php, ping.php
*/
define("SESSION_EXPIRED", "Your session has expired. Please log in again.");
/*
* processiap.php
*/
define("INVALID_IAP", "Purchase not valid!");
/*
* setteam.php
*/
define("INVALID_TEAM_ID", "Invalid team ID.");
define("TEAM_ALREADY_CHOSEN", "You have already chosen a team. Contact support for problems.");

@ -3,11 +3,11 @@
require 'required.php';
if (is_empty($VARS['user'])) {
sendError("Missing username.", true);
sendError(USERNAME_MISSING, true);
}
if (is_empty($VARS['pass'])) {
sendError("Missing password.", true);
sendError(PASSWORD_MISSING, true);
}
$VARS['user'] = strtolower(str_replace(" ", "", $VARS['user']));
@ -27,7 +27,7 @@ $guid = file_get_contents("https://sso.netsyms.com/api/getguid.php?user=" . urle
/* ------------------------------- */
if (is_empty($guid)) {
sendError("Account does not exist.", true);
sendError(ACCOUNT_MISSING, true);
}
if (!$database->has('players', ['uuid' => $guid])) {

@ -55,10 +55,10 @@ if (!is_empty($_GET['code'])) {
} else {
$database->insert('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires'], 'player_uuid' => $_SESSION['uuid']]);
}
echo "Your Munzee account has been linked to TerranQuest!<br /><a href='about:closeme'>Back to game</a>";
echo MUNZEE_LINKED_HTML;
die();
} else {
echo "Munzee is having problems right now. Try again later.<br /><a href='about:closeme'>Back to game</a>";
echo MUNZEE_FAILED_HTML;
die();
}
}

@ -5,5 +5,5 @@
*/
if ($_SESSION['loggedin'] != true) {
sendError('SESSION EXPIRED: Please reauthenticate.', true);
sendError(SESSION_EXPIRED, true);
}

@ -3,7 +3,7 @@
require 'required.php';
if ($_SESSION['loggedin'] != true) {
sendError('Your session has expired. Please log in again.', true);
sendError(SESSION_EXPIRED, true);
} else {
}

@ -84,5 +84,5 @@ if ($purchase_valid) {
$database->update('players', ['credits[+]' => $creditstoadd], ['uuid' => $_SESSION['uuid']]);
sendOK();
} else {
sendError("Purchase not valid!", true);
sendError(INVALID_IAP, true);
}

@ -4,7 +4,7 @@ require 'required.php';
require 'onlyloggedin.php';
if (is_empty($VARS['locationid'])) {
sendError("No target!", true);
sendError(PLACE_ID_NOT_SENT, true);
}
$place = $database->select('locations', ['locationid', 'teamid', 'owneruuid', 'currentlife', 'maxlife'], ['locationid' => $VARS['locationid']])[0];
@ -12,11 +12,11 @@ $user = $database->select('players', ['level', 'teamid', 'energy', 'maxenergy',
// This (probably) shouldn't happen in normal play
if ($place['teamid'] != $user['teamid']) {
sendError("Wrong team!", true);
sendError(PLACE_OWNED_BY_WRONG_TEAM, true);
}
if ($place['currentlife'] == 100) {
sendError("Full!", true);
sendError(PLACE_HEALTH_IS_FULL, true);
}
$userdrain = 2 * floor($user['level']);
@ -25,7 +25,7 @@ $userdrain = 2 * floor($user['level']);
$userhp = $user['energy'] - $userdrain;
// Check if action possible
if ($userhp < 0) {
sendError("No life left!", true);
sendError(PLAYER_NO_LIFE_LEFT, true);
}
// Update the user's health and level
@ -49,4 +49,4 @@ if ($placelife > 100) {
// Update the place
$database->update('locations', ['currentlife' => $placelife, 'maxlife' => 100, 'owneruuid' => $_SESSION['uuid'], 'teamid' => $user['teamid']], ['locationid' => $VARS['locationid']]);
sendOK(($dolevelup ? "Level up!" : "Refilled!"));
sendOK(($dolevelup ? PLAYER_LEVEL_UP : PLACE_HEALTH_REFILLED));

@ -67,3 +67,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
function is_empty($str) {
return (is_null($str) || !isset($str) || $str == '');
}
if (is_empty($VARS['lang'])) {
require "lang/en_us.php";
} else {
switch ($VARS['lang']) {
case "en":
require "lang/en_us.php";
case "en_us":
require "lang/en_us.php";
default:
require "lang/en_us.php";
}
}

@ -4,11 +4,11 @@ require 'required.php';
require 'onlyloggedin.php';
if ($VARS['teamid'] < 1 || $VARS['teamid'] > 6) {
sendError("Invalid team ID.", true);
sendError(INVALID_TEAM_ID, true);
}
$currentteam = $database->select('players', 'teamid', ['uuid' => $_SESSION['uuid']])[0];
if ($currentteam > 0 && $currentteam < 7) {
sendError("You have already chosen a team. Contact support for problems.", true);
sendError(TEAM_ALREADY_CHOSEN, true);
}
$database->update('players', ['teamid' => $VARS['teamid']], ['uuid' => $_SESSION['uuid']]);
sendOK();

@ -6,7 +6,7 @@ require 'onlyloggedin.php';
$itemuuid = $VARS['itemuuid'];
if (is_empty($itemuuid) || !is_numeric($itemuuid) || !$database->has('inventory', ["AND" => ['itemuuid' => $itemuuid, 'playeruuid' => $_SESSION['uuid']]])) {
sendError("Invalid itemuuid.", true);
sendError(INVALID_ITEMID, true);
}
$item = $database->select(