Merge branch 'dev-php-tweaks' into dev

This commit is contained in:
2018-10-29 00:20:50 +11:00
3 changed files with 32 additions and 30 deletions

View File

@@ -1,6 +1,8 @@
<?php
ini_set('display_errors', 'On');
function privateKey(){
return "INSERT PRIVATE KEY";
return "<REDACTED>";
}
function throwError($errorName){
@@ -178,10 +180,10 @@ function addhttp($url) {
function mysqlConnect() {
$dbhost = 'INSERT DB HOST';
$dbusername = 'INSERT DB USERNAME';
$dbpassword = 'INSERT DB PASSWORD';
$dbtable = 'INSERT DB TABLE';
$dbhost = 'localhost';
$dbusername = 'root';
$dbpassword = '<REDACTED>';
$dbtable = 'discordbot';
$userDB = 'user';
$userdataDB = 'userdata';
@@ -189,7 +191,7 @@ function mysqlConnect() {
$memberdataDB = 'memberdata';
$con = mysqli_connect($dbhost,$dbusername,$dbpassword,$dbtable);
if (!$con) { die('Could not connect: ' . mysqli_error());}
if (!$con) { die('Could not connect: ' . mysqli_error($con));}
mysqli_select_db($con, "$dbtable")or die("cannot select DB");
return $con;
}

View File

@@ -3,7 +3,7 @@
//header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
include_once 'functions.php';
if( isset($_GET['dataToLoad']) ){ $dataToLoad = $_GET['dataToLoad']; } else{ $dataToLoad = ''; };
if( isset($_GET['dataType']) ){ $dataToLoad = $_GET['dataType']; } else{ $dataToLoad = ''; };
if( isset($_GET['userid']) ){ $userID = $_GET['userid']; } else{ $userID = ''; };
if( isset($_GET['pk']) ){ $privateKey = $_GET['pk']; } else{ $privateKey = ''; };
$sqlterms = '';
@@ -97,7 +97,7 @@ case "lastHostileActive":
}
break;
case "userStats":
$q = "SELECT strength,speed,stamina,health,maxStamina,maxHealth,wallet,xp,lvl,statPoints,chests FROM users WHERE discordUserID = '$userID';";
$q = "SELECT strength,speed,stamina,health,maxStamina,maxHealth,wallet,xp,lvl,statPoints FROM users WHERE discordUserID = '$userID';";
$r2 = mysqli_query($con,$q);
if ( $r2 !== false && mysqli_num_rows($r2) > 0 ) {
while ( $a = mysqli_fetch_assoc($r2) ) {
@@ -111,15 +111,14 @@ case "userStats":
$xp=stripslashes($a['xp']);
$recordedLVL=stripslashes($a['lvl']);
$statPoints=stripslashes($a['statPoints']);
$chests=stripslashes($a['chests']);
$lvlbase = getLevelBase();
$lvl = getLevel($xp,$lvlbase);
$lvlpercent = getCurrentLevelProgress($xp,$lvl);
}
echo $strength.",".$speed.",".$stamina.",".$health.",".$maxStamina.",".$maxHealth.",".$wallet.",".$xp.",".$recordedLVL.",".$lvlpercent.",".$statPoints.",".$chests;
echo "success,".$strength.",".$speed.",".$stamina.",".$health.",".$maxStamina.",".$maxHealth.",".$wallet.",".$xp.",".$recordedLVL.",".$lvlpercent.",".$statPoints;
exit;
} else{
echo "0";
echo "failure";
}
break;

View File

@@ -28,7 +28,7 @@ switch ($dataType) {
$q = "INSERT INTO users (discordUserID,wallet)
SELECT * FROM (SELECT '$userID',0) AS tmp
WHERE NOT EXISTS (
SELECT discordUserID FROM users WHERE discordUserID = '$userID'
SELECT discordUserID FROM users WHERE discordUserID = '$userID'
) LIMIT 1;";
$r2 = mysqli_query($con,$q);
*/
@@ -41,7 +41,7 @@ switch ($dataType) {
$q = "INSERT INTO users (discordUserID,wallet)
SELECT * FROM (SELECT '$userID',0) AS tmp
WHERE NOT EXISTS (
SELECT discordUserID FROM users WHERE discordUserID = '$userID'
SELECT discordUserID FROM users WHERE discordUserID = '$userID'
) LIMIT 1;";
$r2 = mysqli_query($con,$q);
echo "createdUser";
@@ -70,7 +70,7 @@ switch ($dataType) {
$q = "INSERT INTO userLog (discordUserID, actionType, actionData)
VALUES (" . $userID . ", '" . $dataType . "', 'Checked in for $dataToSend crystals.');";
$r2 = mysqli_query($con,$q);
echo 1;
echo "available";
exit;
}
break;
@@ -127,17 +127,22 @@ switch ($dataType) {
break;
case "transfer":
$q = "SELECT discordUserID FROM users WHERE discordUserID = '$dataToSend' LIMIT 1";
$r2 = mysqli_query($con,$q);
if ( $r2 == false || mysqli_num_rows($r2) == 0 ) {
return "failure";
} else {
$q = "UPDATE users SET wallet = wallet - $dataToSend2 WHERE discordUserID = '$userID' LIMIT 1";
$r2 = mysqli_query($con,$q);
$q = "UPDATE users SET wallet = wallet + $dataToSend2 WHERE discordUserID = '$dataToSend' LIMIT 1";
$r2 = mysqli_query($con,$q);
$q = "INSERT INTO userLog (discordUserID, actionType, actionData)
VALUES (" . $userID . ", '" . $dataType . "', '$userID gave $dataToSend2 crystals to $dataToSend.');";
$r2 = mysqli_query($con,$q);
echo 1;
$q = "INSERT INTO userLog (discordUserID, actionType, actionData)
VALUES (" . $userID . ", '" . $dataType . "', '$userID gave $dataToSend2 crystals to $dataToSend.');";
$r2 = mysqli_query($con,$q);
echo "success";
exit;
}
break;
case "attack":
@@ -545,34 +550,30 @@ switch ($dataType) {
addXp($userID,$dataToSend);
break;
case "getLevelUp":
//addXp($userID,$dataToSend);
$levelCap = 30;$levelCapXP = 625;
$q = "SELECT xp,lvl,statPoints,chests FROM users WHERE discordUserID = '$userID';";
$levelCap = 30;
$levelCapXP = 625;
$q = "SELECT xp,lvl,statPoints FROM users WHERE discordUserID = '$userID';";
$r2 = mysqli_query($con,$q);
if ( $r2 !== false && mysqli_num_rows($r2) > 0 ) {
if ( $r2 && mysqli_num_rows($r2) > 0 ) {
while ( $a = mysqli_fetch_assoc($r2) ) {
$xp=stripslashes($a['xp']);
$lvl=stripslashes($a['lvl']);
$statPoints=stripslashes($a['statPoints']);
$chests=stripslashes($a['chests']);
}
$lvlbase = getLevelBase();
$currentLVL = floor(getLevel($xp,$lvlbase));
if($currentLVL > $lvl){
if($currentLVL > $levelCap){
$chests += 1;
$q = "UPDATE users SET lvl = $levelCap,chests = chests + 1,xp = $levelCapXP WHERE discordUserID = '$userID' LIMIT 1";
$q = "UPDATE users SET lvl = $levelCap, xp = $levelCapXP WHERE discordUserID = '$userID' LIMIT 1";
$r2 = mysqli_query($con,$q);
}else{
$statPoints += 1;
$q = "UPDATE users SET lvl = lvl + 1,statPoints = statPoints + 1 WHERE discordUserID = '$userID' LIMIT 1";
$r2 = mysqli_query($con,$q);
$lvl = $lvl + 1;
}
echo "levelup,".$lvl.",".$statPoints.",".$statPoints;
} else{
echo "levelup,".$currentLVL.",".$statPoints;
} else {
echo "xpadded,".$currentLVL.",".$statPoints;
}
}