User sign-in/account linking, profiles, barcode to items, database changes
parent
b24bb20a8b
commit
af13a70976
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
$database->update("players", [
|
||||
"latitude" => $VARS["latitude"],
|
||||
"longitude" => $VARS["longitude"],
|
||||
"lastping" => date("Y-m-d H:i:s")
|
||||
], ["accountid" => getRequestUser()->getUID()]);
|
||||
|
||||
sendJsonResp();
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
if ($database->has("players", ["accountid" => getRequestUser()->getUID()])) {
|
||||
sendJsonResp($Strings->get("Your account is already active.", false), "ERROR");
|
||||
}
|
||||
|
||||
$database->insert("players", [
|
||||
"accountid" => getRequestUser()->getUID(),
|
||||
"level" => 1.0,
|
||||
"energy" => 100,
|
||||
"maxenergy" => 100,
|
||||
"credits" => 500,
|
||||
"lastping" => date("Y-m-d H:i:s"),
|
||||
"teamid" => $VARS['team'],
|
||||
"nickname" => getRequestUser()->getName(),
|
||||
]);
|
||||
|
||||
sendJsonResp();
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
if (empty($VARS["id"])) {
|
||||
$accountid = getRequestUser()->getUID();
|
||||
} else {
|
||||
$accountid = $VARS["id"];
|
||||
}
|
||||
|
||||
if ($database->has("players", ["accountid" => $accountid])) {
|
||||
$profile = $database->get("players", ["accountid (id)", "nickname (name)", "level", "energy", "maxenergy", "teamid"], ["accountid" => $accountid]);
|
||||
} else {
|
||||
sendJsonResp($Strings->get("Player does not exist.", false), "ERROR");
|
||||
}
|
||||
|
||||
exitWithJson([
|
||||
"status" => "OK",
|
||||
"profile" => $profile
|
||||
]);
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
$items = $database->select(
|
||||
'items', [
|
||||
'[>]inventory' => ['itemid' => 'itemid'],
|
||||
'[>]itemclasses' => ['classid', 'classid']
|
||||
], [
|
||||
'inventory.itemuuid (uuid)',
|
||||
'inventory.itemid (id)',
|
||||
'inventory.itemjson (json)',
|
||||
'items.itemname (name)',
|
||||
'items.itemdesc (description)',
|
||||
'items.itemcode (code)',
|
||||
'itemclasses.classid (classid)',
|
||||
'itemclasses.classname (classname'
|
||||
], [
|
||||
"playeruuid" => getRequestUser()->getUID()
|
||||
]
|
||||
);
|
||||
|
||||
exitWithJson(["status" => "OK", "items" => $items]);
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
|
||||
|
||||
$userlocation = GeoLocation::fromDegrees($VARS["latitude"], $VARS["longitude"]);
|
||||
|
||||
$radius = 2;
|
||||
if (!empty($VARS["radius"])) {
|
||||
$radius = min(10.0, $VARS["radius"] * 1.0);
|
||||
}
|
||||
$searchbounds = $userlocation->boundingCoordinates($radius, "miles");
|
||||
|
||||
ob_flush();
|
||||
$people = $database->debug()->select("accounts", [
|
||||
"publicid",
|
||||
"name",
|
||||
"username",
|
||||
"verified",
|
||||
"latitude",
|
||||
"longitude"
|
||||
], [
|
||||
"AND" => [
|
||||
'latitude[<>]' => [$searchbounds[0]->getLatitudeInDegrees(), $searchbounds[1]->getLatitudeInDegrees()],
|
||||
'longitude[<>]' => [$searchbounds[0]->getLongitudeInDegrees(), $searchbounds[1]->getLongitudeInDegrees()],
|
||||
"lastgpsfix[>]" => date("Y-m-d H:i:s", strtotime("-1 hour")),
|
||||
"type" => 2
|
||||
],
|
||||
"LIMIT" => 100
|
||||
]
|
||||
);
|
||||
$query = ob_get_contents();
|
||||
ob_clean();
|
||||
$people = $database->query($query)->fetchAll();
|
||||
|
||||
$nearby = [];
|
||||
|
||||
if (!empty($VARS["format"]) && $VARS["format"] == "geojson") {
|
||||
$geojson = [
|
||||
"name" => "Nearby People",
|
||||
"type" => "FeatureCollection",
|
||||
"features" => []
|
||||
];
|
||||
|
||||
foreach ($people as $person) {
|
||||
$geojson["features"][] = [
|
||||
"type" => "Feature",
|
||||
"geometry" => [
|
||||
"type" => "Point",
|
||||
"coordinates" => [
|
||||
$person["longitude"] * 1.0,
|
||||
$person["latitude"] * 1.0
|
||||
]
|
||||
],
|
||||
"properties" => [
|
||||
"id" => $person["publicid"],
|
||||
"name" => utf8_encode(empty($person["name"]) ? $person["username"] : $person["name"]),
|
||||
"username" => $person["username"],
|
||||
"verified" => $person["verified"] == 1
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
exitWithJson($geojson);
|
||||
}
|
||||
|
||||
foreach ($people as $person) {
|
||||
$nearby[] = [
|
||||
"name" => (empty($person["name"]) ? $person["username"] : $person["name"]),
|
||||
"username" => $person["username"],
|
||||
"verified" => $person["verified"] == 1,
|
||||
"publicid" => $person["publicid"],
|
||||
"latitude" => $person["latitude"] * 1.0,
|
||||
"longitude" => $person["longitude"] * 1.0
|
||||
];
|
||||
}
|
||||
|
||||
exitWithJson([
|
||||
"status" => "OK",
|
||||
"radius" => $radius,
|
||||
"bounds" => [
|
||||
0 => [
|
||||
"latitude" => $searchbounds[0]->getLatitudeInDegrees(),
|
||||
"longitude" => $searchbounds[0]->getLongitudeInDegrees()
|
||||
],
|
||||
1 => [
|
||||
"latitude" => $searchbounds[1]->getLatitudeInDegrees(),
|
||||
"longitude" => $searchbounds[1]->getLongitudeInDegrees()
|
||||
],
|
||||
],
|
||||
"nearby" => $nearby
|
||||
]);
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
if (empty($VARS["id"])) {
|
||||
$accountid = getRequestUser()->getUID();
|
||||
} else {
|
||||
$accountid = $VARS["id"];
|
||||
}
|
||||
|
||||
exitWithJson([
|
||||
"status" => "OK",
|
||||
"exists" => $database->has("players", ["accountid" => $accountid])
|
||||
]);
|
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
/**
|
||||
* https://www.sitepoint.com/php-random-number-generator/
|
||||
*/
|
||||
class Random {
|
||||
|
||||
// random seed
|
||||
private static $RSeed = 0;
|
||||
|
||||
// set seed
|
||||
public static function seed($s = 0) {
|
||||
self::$RSeed = abs(intval($s)) % 9999999 + 1;
|
||||
self::num();
|
||||
}
|
||||
|
||||
// generate random number
|
||||
public static function num($min = 0, $max = 9999999) {
|
||||
if (self::$RSeed == 0) {
|
||||
self::seed(mt_rand());
|
||||
}
|
||||
self::$RSeed = (self::$RSeed * 125) % 2796203;
|
||||
return self::$RSeed % ($max - $min + 1) + $min;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$returndata = [
|
||||
"status" => "OK",
|
||||
"item" => "",
|
||||
"munzee" => "",
|
||||
"messages" => []
|
||||
];
|
||||
|
||||
try {
|
||||
if (strpos($VARS["code"], "munzee") > 1) {
|
||||
if (!empty($VARS["latitude"]) && !empty($VARS["longitude"]) && !empty($VARS["accuracy"])) {
|
||||
include 'capturemunzee.php';
|
||||
}
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
//file_put_contents("munzee.log", "Error with Munzee code: $ex\n", FILE_APPEND);
|
||||
}
|
||||
|
||||
if ($database->has('claimedcodes', ["AND" => ['code' => $VARS["code"], 'accountid' => getRequestUser()->getUID()]])) {
|
||||
$returndata['messages'][] = $Strings->get("You've already discovered that.", false);
|
||||
} else {
|
||||
$codearray = str_split($VARS["code"]);
|
||||
|
||||
$codeint = 0;
|
||||
foreach ($codearray as $chr) {
|
||||
$codeint += ord($chr);
|
||||
}
|
||||
Random::seed($codeint);
|
||||
|
||||
$items = $database->select("items", ["itemid", "weight"]);
|
||||
$weighted = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
for ($i = 0; $i < $item["weight"]; $i++) {
|
||||
$weighted[] = $item["itemid"];
|
||||
}
|
||||
}
|
||||
$itemid = $weighted[Random::num(0, count($weighted))];
|
||||
|
||||
$database->insert('inventory', ['accountid' => getRequestUser()->getUID(), 'itemid' => $itemid]);
|
||||
$database->insert('claimedcodes', ['code' => $VARS["code"], 'accountid' => getRequestUser()->getUID()]);
|
||||
$itemname = $database->get('items', 'itemname', ['itemid' => $itemid]);
|
||||
|
||||
$returndata["item"] = $itemname;
|
||||
|
||||
$returndata['messages'][] = $Strings->build("You found one {item}", ["item" => $itemname], false);
|
||||
}
|
||||
|
||||
exitWithJson($returndata);
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
/**
|
||||
* Author: Skylar Ittner
|
||||
* Created: Apr 26, 2019
|
||||
*/
|
||||
|
||||
ALTER TABLE `terranquest`.`inventory`
|
||||
DROP FOREIGN KEY `fk_inventory_players`;
|
||||
|
||||
ALTER TABLE `terranquest`.`player_badges`
|
||||
DROP FOREIGN KEY `fk_achievements_has_players_players1`;
|
||||
|
||||
ALTER TABLE `terranquest`.`locations`
|
||||
DROP FOREIGN KEY `fk_locations_players1`;
|
||||
|
||||
ALTER TABLE `terranquest`.`claimedcodes`
|
||||
DROP FOREIGN KEY `fk_claimedcodes_players1`;
|
||||
|
||||
ALTER TABLE `terranquest`.`munzee`
|
||||
DROP FOREIGN KEY `fk_munzee_players1`;
|
||||
|
||||
ALTER TABLE `terranquest`.`messages`
|
||||
DROP FOREIGN KEY `fk_messages_players1`;
|
||||
|
||||
ALTER TABLE `terranquest`.`artifacts`
|
||||
DROP FOREIGN KEY `fk_artifacts_players1`;
|
||||
|
||||
ALTER TABLE `terranquest`.`private_messages`
|
||||
DROP FOREIGN KEY `fk_private_messages_players1`,
|
||||
DROP FOREIGN KEY `fk_private_messages_players2`;
|
||||
|
||||
ALTER TABLE `terranquest`.`inventory`
|
||||
CHANGE COLUMN `playeruuid` `accountid` VARCHAR(60) CHARACTER SET 'utf8' NOT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`players`
|
||||
CHANGE COLUMN `uuid` `accountid` VARCHAR(60) CHARACTER SET 'utf8' NOT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`player_badges`
|
||||
CHANGE COLUMN `playeruuid` `accountid` VARCHAR(60) CHARACTER SET 'utf8' NOT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`locations`
|
||||
CHANGE COLUMN `owneruuid` `ownerid` VARCHAR(60) CHARACTER SET 'utf8' NULL DEFAULT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`claimedcodes`
|
||||
CHANGE COLUMN `playeruuid` `accountid` VARCHAR(60) CHARACTER SET 'utf8' NOT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`munzee`
|
||||
CHANGE COLUMN `player_uuid` `accountid` VARCHAR(60) CHARACTER SET 'utf8' NOT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`messages`
|
||||
CHANGE COLUMN `message` `message` VARCHAR(500) COLLATE 'utf8mb4_bin' NOT NULL ,
|
||||
CHANGE COLUMN `uuid` `accountid` VARCHAR(60) CHARACTER SET 'utf8' NULL DEFAULT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`artifacts`
|
||||
CHANGE COLUMN `currentlife` `currentlife` DECIMAL(7,2) NOT NULL DEFAULT 100 ,
|
||||
CHANGE COLUMN `maxlife` `maxlife` DECIMAL(7,2) NOT NULL DEFAULT 100 ,
|
||||
CHANGE COLUMN `playeruuid` `accountid` VARCHAR(60) CHARACTER SET 'utf8' NULL DEFAULT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`private_messages`
|
||||
CHANGE COLUMN `from_uuid` `from_id` VARCHAR(60) CHARACTER SET 'utf8' NOT NULL DEFAULT 0 ,
|
||||
CHANGE COLUMN `to_uuid` `to_id` VARCHAR(60) CHARACTER SET 'utf8' NOT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`inventory`
|
||||
ADD CONSTRAINT `fk_inventory_players`
|
||||
FOREIGN KEY (`accountid`)
|
||||
REFERENCES `terranquest`.`players` (`accountid`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION;
|
||||
|
||||
ALTER TABLE `terranquest`.`player_badges`
|
||||
ADD CONSTRAINT `fk_achievements_has_players_players1`
|
||||
FOREIGN KEY (`accountid`)
|
||||
REFERENCES `terranquest`.`players` (`accountid`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION;
|
||||
|
||||
ALTER TABLE `terranquest`.`locations`
|
||||
ADD CONSTRAINT `fk_locations_players1`
|
||||
FOREIGN KEY (`ownerid`)
|
||||
REFERENCES `terranquest`.`players` (`accountid`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION;
|
||||
|
||||
ALTER TABLE `terranquest`.`claimedcodes`
|
||||
ADD CONSTRAINT `fk_claimedcodes_players1`
|
||||
FOREIGN KEY (`accountid`)
|
||||
REFERENCES `terranquest`.`players` (`accountid`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION;
|
||||
|
||||
ALTER TABLE `terranquest`.`munzee`
|
||||
ADD CONSTRAINT `fk_munzee_players1`
|
||||
FOREIGN KEY (`accountid`)
|
||||
REFERENCES `terranquest`.`players` (`accountid`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION;
|
||||
|
||||
ALTER TABLE `terranquest`.`messages`
|
||||
ADD CONSTRAINT `fk_messages_players1`
|
||||
FOREIGN KEY (`accountid`)
|
||||
REFERENCES `terranquest`.`players` (`accountid`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION;
|
||||
|
||||
ALTER TABLE `terranquest`.`artifacts`
|
||||
ADD CONSTRAINT `fk_artifacts_players1`
|
||||
FOREIGN KEY (`accountid`)
|
||||
REFERENCES `terranquest`.`players` (`accountid`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION;
|
||||
|
||||
ALTER TABLE `terranquest`.`private_messages`
|
||||
ADD CONSTRAINT `fk_private_messages_players1`
|
||||
FOREIGN KEY (`from_id`)
|
||||
REFERENCES `terranquest`.`players` (`accountid`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
ADD CONSTRAINT `fk_private_messages_players2`
|
||||
FOREIGN KEY (`to_id`)
|
||||
REFERENCES `terranquest`.`players` (`accountid`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION;
|
||||
|
||||
ALTER TABLE `terranquest`.`items`
|
||||
ADD COLUMN `weight` INT(3) NOT NULL DEFAULT 1 AFTER `itemcode`;
|
||||
|
||||
ALTER TABLE `terranquest`.`messages`
|
||||
CHANGE COLUMN `message` `message` VARCHAR(500) COLLATE 'utf8mb4_bin' NOT NULL ;
|
||||
|
||||
ALTER TABLE `terranquest`.`artifacts`
|
||||
CHANGE COLUMN `currentlife` `currentlife` DECIMAL(7,2) NOT NULL DEFAULT 100 ,
|
||||
CHANGE COLUMN `maxlife` `maxlife` DECIMAL(7,2) NOT NULL DEFAULT 100 ;
|
Loading…
Reference in New Issue