Compare commits

..
2 Commits
Author SHA1 Message Date
Lncvrt cc0b612225 Fix readme 2026-02-16 13:22:23 -07:00
Lncvrt 92534f959b Change readme 2025-12-31 16:13:01 -07:00
55 changed files with 1461 additions and 794 deletions

No files matched your search

+2 -2
View File
@@ -631,7 +631,7 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found. the "copyright" line and a pointer to where the full notice is found.
Berry Dash Server Code Copyright (C) 2026 Lncvrt Berry Dash Server Code Copyright (C) 2025 Lncvrt
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -651,7 +651,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode: notice like this when it starts in an interactive mode:
Berry Dash Server Code Copyright (C) 2026 Lncvrt Berry Dash Server Code Copyright (C) 2025 Lncvrt
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details. under certain conditions; type `show c' for details.
+31 -6
View File
@@ -1,14 +1,39 @@
# Berry Dash Server # Berry Dash Server
> [!CAUTION] > [!CAUTION]
> This project has moved to the Lncvrt Games originization. > This project has moved to the Lncvrt Games organization.
> >
> You can find the new server API [here](https://github.com/Lncvrt-Games/api). > You can find the new server API [here](https://git.lncvrt.xyz/Lncvrt-Games/api).
>
> NOTE: This is also the branch that is being modified so it can continue to work for 1.8.2 and lower.
>
> Find old branch [here](https://github.com/BerryDash/server/tree/main)
--- ---
This is the source code for Berry Dash. This is the source code for Berry Dash.
## Setup
> [!CAUTION]
> Do not share any keys with anybody, and store them safely on your computer.
> Encryption keys are meant to increase the security of the game and prevent cheaters.
1. Upload the files on a webserver
2. Import database.sql into a MySQL/MariaDB database
3. Configure everything in `config/` folder (use `python3 genkeys.py` for `encryption.php`)
4. Use `git clone https://github.com/BerryDash/source.git` to clone the client and configure `Assets/Scripts/SensitiveInfo.cs`
**Note:**
When configuring keys in the client, `SERVER_RECEIVE_TRANSFER_KEY` will the key `SERVER_SEND_TRANSFER_KEY` from the server, and the other way around too.
If this isn't configured properly, you will not be able to make requests to the server you have setup.
Example:
```cs
public static readonly string SERVER_DATABASE_PREFIX = "https://berrydash.lncvrt.xyz/database/";
public static readonly string SERVER_RECEIVE_TRANSFER_KEY = "02b3c624552588ba0929e43fbad36221"; // This would be `SERVER_SEND_TRANSFER_KEY` from the server
public static readonly string SERVER_SEND_TRANSFER_KEY = "d4269db023de05fd59bf05378fa57324"; // This would be `SERVER_RECEIVE_TRANSFER_KEY` from the server
public static readonly string BAZOOKA_MANAGER_KEY = "19387a0e6b861e79d38657d0059bce8c";
public static readonly string BAZOOKA_MANAGER_FILE_KEY = "7fb47db04d9babf42ee3713289516208";
```
In conclusion: `SERVER_RECEIVE_TRANSFER_KEY` and `SERVER_SEND_TRANSFER_KEY` are swapped between client and server. This may be changed in the future.
-1
View File
@@ -1 +0,0 @@
Require all denied
+5 -10
View File
@@ -1,11 +1,6 @@
<?php <?php
$games_db_host = "localhost"; $db_host = "localhost";
$games_db_port = 3306; $db_port = 3306;
$games_db_user = ""; $db_user = "";
$games_db_pass = ""; $db_pass = "";
$games_db_name = ""; $db_name = "";
$bd_db_host = "localhost";
$bd_db_port = 3306;
$bd_db_user = "";
$bd_db_pass = "";
$bd_db_name = "";
+4 -2
View File
@@ -1,3 +1,5 @@
<?php <?php
$SERVER_RECEIVE_TRANSFER_KEY_SPECIFIC = ["1.5.0" => "67bafe2be3940d1f713b96b3ca4fb852", "1.5.1" => "67bafe2be3940d1f713b96b3ca4fb852", "1.5.2" => "474111bd6b6e16a044f50e464029def6", "1.6" => "397fb5fca6d8f9c8afe49d8cd31bae4c", "1.6.1" => "397fb5fca6d8f9c8afe49d8cd31bae4c", "1.6.2" => "397fb5fca6d8f9c8afe49d8cd31bae4c", "1.6.3" => "397fb5fca6d8f9c8afe49d8cd31bae4c", "1.7" => "397fb5fca6d8f9c8afe49d8cd31bae4c", "1.7.1" => "397fb5fca6d8f9c8afe49d8cd31bae4c", "1.8" => "397fb5fca6d8f9c8afe49d8cd31bae4c", "1.8.1" => "397fb5fca6d8f9c8afe49d8cd31bae4c", "1.8.2" => "7bedd0bfd2ea5d4629ea2426b284c0cc"]; $SERVER_RECEIVE_TRANSFER_KEY = ""; //SERVER_SEND_TRANSFER_KEY on the client
$SERVER_SEND_TRANSFER_KEY_SPECIFIC = ["1.5.0" => "00490b14efea6a20a1395aa6b83a83c0", "1.5.1" => "00490b14efea6a20a1395aa6b83a83c0", "1.5.2" => "7c734d6f1ea37dc1e1157f8d9c8b588f", "1.6" => "779a4cff3d144649324133495f136b0f", "1.6.1" => "779a4cff3d144649324133495f136b0f", "1.6.2" => "779a4cff3d144649324133495f136b0f", "1.6.3" => "779a4cff3d144649324133495f136b0f", "1.7" => "779a4cff3d144649324133495f136b0f", "1.7.1" => "779a4cff3d144649324133495f136b0f", "1.8" => "779a4cff3d144649324133495f136b0f", "1.8.1" => "779a4cff3d144649324133495f136b0f", "1.8.2" => "dd82c15dc4cfa03f9a06ecffe19cc525"]; $SERVER_SEND_TRANSFER_KEY = ""; //SERVER_RECEIVE_TRANSFER_KEY on the client
$SERVER_RECEIVE_TRANSFER_KEY_SPECIFIC = [];
$SERVER_SEND_TRANSFER_KEY_SPECIFIC = [];
+6
View File
@@ -0,0 +1,6 @@
<?php
$latestVersion = "1.8.2";
$latestBetaVersion = $latestVersion;
$latestLauncherVersion = "1.1.0";
$allowedVersions = [$latestVersion, $latestBetaVersion, "1.8.1", "1.8", "1.7.1", "1.7", "1.6.3", "1.6.2", "1.6.1", "1.6", "1.5.2", "1.5.1", "1.5.0", "1.4.1", "1.4.0", "1.4.0-beta1"];
$allowedDatabaseVersions = [$latestVersion, $latestBetaVersion, "1.8.1", "1.8", "1.7.1", "1.7", "1.6.3", "1.6.2", "1.6.1", "1.6", "1.5.2", "1.5.1", "1.5.0", "1.4.1", "1.4.0", "1.4.0-beta1", "1.33", "1.3", "1.3-beta2", "1.3-beta1", "1.21", "1.2", "1.2-beta2"];
+305
View File
@@ -0,0 +1,305 @@
-- phpMyAdmin SQL Dump
-- version 5.2.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: Oct 04, 2025 at 10:18 PM
-- Server version: 11.8.3-MariaDB-ubu2404
-- PHP Version: 8.1.33
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `berrydashdatabase`
--
-- --------------------------------------------------------
--
-- Table structure for table `chatroom_reports`
--
CREATE TABLE `chatroom_reports` (
`id` int(11) NOT NULL,
`chatId` int(11) NOT NULL,
`userId` int(11) NOT NULL,
`reason` longtext NOT NULL,
`timestamp` bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
-- --------------------------------------------------------
--
-- Table structure for table `chats`
--
CREATE TABLE `chats` (
`id` int(11) NOT NULL,
`userId` int(11) NOT NULL,
`content` longtext NOT NULL,
`timestamp` bigint(20) NOT NULL,
`deleted_at` bigint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
-- --------------------------------------------------------
--
-- Table structure for table `launchercategories`
--
CREATE TABLE `launchercategories` (
`id` int(11) NOT NULL,
`name` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
-- --------------------------------------------------------
--
-- Table structure for table `launcherversions`
--
CREATE TABLE `launcherversions` (
`id` int(11) NOT NULL,
`version` text NOT NULL,
`displayName` text DEFAULT NULL,
`releaseDate` bigint(20) NOT NULL,
`downloadUrls` text NOT NULL,
`platforms` text NOT NULL,
`executables` text NOT NULL,
`hidden` tinyint(1) NOT NULL DEFAULT 1,
`category` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
-- --------------------------------------------------------
--
-- Table structure for table `marketplaceicons`
--
CREATE TABLE `marketplaceicons` (
`id` int(11) NOT NULL,
`uuid` text DEFAULT NULL,
`userId` int(11) NOT NULL,
`data` longtext NOT NULL,
`hash` varchar(128) NOT NULL,
`timestamp` bigint(20) NOT NULL,
`state` tinyint(1) NOT NULL DEFAULT 0,
`price` int(11) NOT NULL DEFAULT 0,
`name` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
-- --------------------------------------------------------
--
-- Table structure for table `presets`
--
CREATE TABLE `presets` (
`id` int(11) NOT NULL,
`uuid` text DEFAULT NULL,
`userId` int(11) NOT NULL,
`data` longtext NOT NULL,
`timestamp` bigint(20) NOT NULL,
`name` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
-- --------------------------------------------------------
--
-- Table structure for table `userposts`
--
CREATE TABLE `userposts` (
`id` int(11) NOT NULL,
`userId` int(11) NOT NULL,
`content` text NOT NULL,
`timestamp` int(11) NOT NULL,
`likes` bigint(20) NOT NULL DEFAULT 0,
`deleted_at` int(11) NOT NULL DEFAULT 0,
`votes` text NOT NULL DEFAULT '[]'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`username` varchar(255) DEFAULT NULL,
`password` varchar(60) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`token` varchar(512) NOT NULL,
`latest_ip` varchar(255) DEFAULT NULL,
`register_time` int(11) DEFAULT NULL,
`banned` tinyint(1) NOT NULL DEFAULT 0,
`leaderboardsBanned` tinyint(1) NOT NULL DEFAULT 0,
`save_data` longtext NOT NULL DEFAULT '\'{}\'',
`legacy_high_score` bigint(20) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `chatroom_reports`
--
ALTER TABLE `chatroom_reports`
ADD PRIMARY KEY (`id`),
ADD KEY `userId` (`userId`),
ADD KEY `chatId` (`chatId`);
--
-- Indexes for table `chats`
--
ALTER TABLE `chats`
ADD PRIMARY KEY (`id`),
ADD KEY `fk_userId` (`userId`);
--
-- Indexes for table `launchercategories`
--
ALTER TABLE `launchercategories`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `launcherversions`
--
ALTER TABLE `launcherversions`
ADD PRIMARY KEY (`id`),
ADD KEY `fk_category` (`category`);
--
-- Indexes for table `marketplaceicons`
--
ALTER TABLE `marketplaceicons`
ADD PRIMARY KEY (`id`),
ADD KEY `fk_userId` (`userId`);
--
-- Indexes for table `presets`
--
ALTER TABLE `presets`
ADD PRIMARY KEY (`id`),
ADD KEY `fk_userId` (`userId`);
--
-- Indexes for table `userposts`
--
ALTER TABLE `userposts`
ADD PRIMARY KEY (`id`),
ADD KEY `fk_userposts_userId` (`userId`);
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `chatroom_reports`
--
ALTER TABLE `chatroom_reports`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `chats`
--
ALTER TABLE `chats`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `launchercategories`
--
ALTER TABLE `launchercategories`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `launcherversions`
--
ALTER TABLE `launcherversions`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `marketplaceicons`
--
ALTER TABLE `marketplaceicons`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `presets`
--
ALTER TABLE `presets`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `userposts`
--
ALTER TABLE `userposts`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `chatroom_reports`
--
ALTER TABLE `chatroom_reports`
ADD CONSTRAINT `chatId` FOREIGN KEY (`chatId`) REFERENCES `chats` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `chats`
--
ALTER TABLE `chats`
ADD CONSTRAINT `fk_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `launcherversions`
--
ALTER TABLE `launcherversions`
ADD CONSTRAINT `fk_category` FOREIGN KEY (`category`) REFERENCES `launchercategories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `marketplaceicons`
--
ALTER TABLE `marketplaceicons`
ADD CONSTRAINT `fk_marketplaceicons_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `presets`
--
ALTER TABLE `presets`
ADD CONSTRAINT `fk_presets_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `userposts`
--
ALTER TABLE `userposts`
ADD CONSTRAINT `fk_userposts_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
-1
View File
@@ -1 +0,0 @@
Require all denied
+12 -40
View File
@@ -1,12 +1,12 @@
<?php <?php
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$request_username = $_POST['username']; $request_username = $_POST['username'];
$request_password = $_POST['password']; $request_password = $_POST['password'];
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $request_username); $stmt->bind_param("s", $request_username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
@@ -17,56 +17,28 @@ if ($result->num_rows > 0) {
$login_ip = getIPAddress(); $login_ip = getIPAddress();
$login_time = time(); $login_time = time();
$uid = $row['id']; $uid = $row['id'];
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE id = ?");
$stmt2->bind_param("i", $uid);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
echo '-1';
exit;
}
$user2 = $result2->fetch_assoc();
$username = $row['username']; $username = $row['username'];
$highscore = $user2['legacy_high_score']; $highscore = $row['legacy_high_score'];
$token = $user2['token']; $token = $row['token'];
$savedata = json_decode($user2['save_data'], true);
$icon = $savedata['bird']['icon'] ?? 1;
$overlay = $savedata['bird']['overlay'] ?? 0;
$stmt = $conn0->prepare("UPDATE users SET latest_ip = ? WHERE id = ?"); $stmt = $conn->prepare("UPDATE users SET latest_ip = ? WHERE id = ?");
$stmt->bind_param("si", $login_ip, $uid); $stmt->bind_param("si", $login_ip, $uid);
$stmt->execute(); $stmt->execute();
if ( echo "$token:$uid:$highscore";
getClientVersion() == "1.2-beta2" ||
getClientVersion() == "1.2" ||
getClientVersion() == "1.21" ||
getClientVersion() == "1.3-beta1"
) {
echo "$token:$uid:$highscore";
} else if (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") {
echo "$token:$uid:$highscore:$icon:$overlay";
} else if (getClientVersion() == "1.4.0-beta1" || getClientVersion() == "1.4.0" || getClientVersion() == "1.4.1") {
echo "1:$token:$username:$uid:$highscore:$icon:$overlay";
}
} else { } else {
$stmt->close(); $stmt->close();
$conn0->close(); $conn->close();
$conn1->close();
exit("-2"); exit("-2");
} }
} }
} else { } else {
$stmt->close(); $stmt->close();
$conn0->close(); $conn->close();
$conn1->close();
exit("-2"); exit("-2");
} }
$stmt->close(); $stmt->close();
$conn0->close(); $conn->close();
$conn1->close();
?>
@@ -0,0 +1,45 @@
<?php
$conn = newConnection();
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
$email = $_POST['email'] ?? '';
if (empty($username) || empty($password) || empty($email)) {
exit("-2");
}
if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $username)) {
exit("-3");
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
exit("-4");
}
if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_\-+=]{8,}$/', $password)) {
exit("-5");
}
$stmt = $conn->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
$stmt->bind_param("ss", $username, $email);
$stmt->execute();
$res = $stmt->get_result();
if ($res->num_rows > 0) {
exit("-7");
}
$hashed = password_hash($password, PASSWORD_DEFAULT);
$token = bin2hex(random_bytes(256));
$ip = getIPAddress();
$time = time();
$stmt = $conn->prepare("INSERT INTO users (token, username, password, email, register_time, latest_ip) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssis", $token, $username, $hashed, $email, $time, $ip);
$stmt->execute();
$stmt->close();
$conn->close();
echo '1';
+14 -29
View File
@@ -1,40 +1,25 @@
<?php <?php
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$request_uid = $_POST['userID'] ?? 0; $request_uid = $_POST['userID'] ?? 0;
$request_session = $_POST['gameSession'] ?? ''; $request_session = $_POST['gameSession'] ?? '';
$request_score = $_POST['highScore'] ?? 0; $request_score = $_POST['highScore'] ?? 0;
$stmt = $conn0->prepare("SELECT * FROM users WHERE id = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND id = ?");
$stmt->bind_param("s", $request_uid); $stmt->bind_param("ss", $request_session, $request_uid);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) { if ($result->num_rows > 0) {
echo (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") ? "-2" : "-3"; $updateStmt = $conn->prepare("UPDATE users SET legacy_high_score = ? WHERE token = ? AND id = ?");
$conn0->close(); $updateStmt->bind_param("isi", $request_score, $request_session, $request_uid);
$conn1->close(); $updateStmt->execute();
exit; echo "1";
$updateStmt->close();
} else {
echo "-3";
} }
$request_uid = $result->fetch_assoc()["id"]; $stmt->close();
$conn->close();
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE token = ? AND id = ?"); ?>
$stmt2->bind_param("si", $request_session, $request_uid);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
echo (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") ? "-2" : "-3";
$conn0->close();
$conn1->close();
exit;
}
$updateStmt = $conn1->prepare("UPDATE userdata SET legacy_high_score = ? WHERE token = ? AND id = ?");
$updateStmt->bind_param("isi", $request_score, $request_session, $request_uid);
$updateStmt->execute();
$updateStmt->close();
echo "1";
@@ -0,0 +1,45 @@
<?php
$conn = newConnection();
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
$email = $_POST['email'] ?? '';
if (empty($username) || empty($password) || empty($email)) {
exit("-2");
}
if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $username)) {
exit("-3");
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
exit("-4");
}
if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_\-+=]{8,}$/', $password)) {
exit("-5");
}
$stmt = $conn->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
$stmt->bind_param("ss", $username, $email);
$stmt->execute();
$res = $stmt->get_result();
if ($res->num_rows > 0) {
exit("-8");
}
$hashed = password_hash($password, PASSWORD_DEFAULT);
$token = bin2hex(random_bytes(256));
$ip = getIPAddress();
$time = time();
$stmt = $conn->prepare("INSERT INTO users (token, username, password, email, register_time, latest_ip) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssis", $token, $username, $hashed, $email, $time, $ip);
$stmt->execute();
$stmt->close();
$conn->close();
echo '1';
@@ -0,0 +1,52 @@
<?php
$conn = newConnection();
$userID = isset($_POST['userID']) ? $_POST['userID'] : '';
$current_password = isset($_POST['currentPassword']) ? $_POST['currentPassword'] : '';
$new_username = isset($_POST['newUsername']) ? $_POST['newUsername'] : '';
if (empty($userID) || empty($new_username) || empty($current_password)) {
die("-2");
}
if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $new_username)) {
die("-3");
}
$stmt = $conn->prepare("SELECT * FROM users WHERE id = ?");
$stmt->bind_param("s", $userID);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
if (!password_verify($current_password, $user['password'])) {
die("-4");
}
} else {
die("-5");
}
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $new_username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
die("-6");
}
$stmt = $conn->prepare("UPDATE users SET username = ? WHERE id = ?");
$stmt->bind_param("ss", $new_username, $userID);
$stmt->execute();
$stmt->close();
$conn->close();
echo '1';
?>
@@ -0,0 +1,52 @@
<?php
$conn = newConnection();
$username = isset($_POST['username']) ? $_POST['username'] : '';
$current_password = isset($_POST['currentPassword']) ? $_POST['currentPassword'] : '';
$new_username = isset($_POST['newUsername']) ? $_POST['newUsername'] : '';
if (empty($username) || empty($new_username) || empty($current_password)) {
die("-2");
}
if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $new_username)) {
die("-3");
}
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
if (!password_verify($current_password, $user['password'])) {
die("-6");
}
} else {
die("-7");
}
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $new_username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
die("-8");
}
$stmt = $conn->prepare("UPDATE users SET username = ? WHERE username = ?");
$stmt->bind_param("ss", $new_username, $username);
$stmt->execute();
$stmt->close();
$conn->close();
echo '1';
?>
+28 -41
View File
@@ -1,8 +1,25 @@
<?php <?php
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT username, id FROM users WHERE leaderboards_banned = 0"); $request_showamount = isset($_POST['showAmount']) ? $_POST['showAmount'] : 0;
switch ($request_showamount) {
case 1:
$request_limit = 100;
break;
case 2:
$request_limit = 250;
break;
case 3:
$request_limit = 500;
break;
default:
$request_limit = 50;
break;
}
$stmt = $conn->prepare("SELECT username, legacy_high_score, id, save_data FROM users WHERE legacy_high_score > 0 AND banned = 0 AND leaderboardsBanned = 0 ORDER BY legacy_high_score DESC LIMIT ?");
$stmt->bind_param("i", $request_limit);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
@@ -11,48 +28,18 @@ if ($result->num_rows > 0) {
$topPlayers = []; $topPlayers = [];
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$id = $row["id"]; $savedata = json_decode($row['save_data'], true);
$stmt2 = $conn1->prepare("SELECT legacy_high_score, save_data FROM userdata WHERE id = ? AND legacy_high_score > 0 ORDER BY legacy_high_score DESC LIMIT 1");
$stmt2->bind_param("i", $id);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
continue;
}
$user2 = $result2->fetch_assoc();
$savedata = json_decode($user2['save_data'], true);
$icon = $savedata['bird']['icon'] ?? 1; $icon = $savedata['bird']['icon'] ?? 1;
$overlay = $savedata['bird']['overlay'] ?? 0; $overlay = $savedata['bird']['overlay'] ?? 0;
if (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") { $topPlayers[] = $row["username"] . ":" . $row["legacy_high_score"] . ":" . $icon . ":" . $overlay . ":" . $row["id"];
$topPlayers[] = $row["username"] . ":" . $user2["legacy_high_score"] . ":" . $icon . ":" . $overlay . ":" . $id;
} else if (getClientVersion() == "0") {
$topPlayers[] = base64_encode($row["username"]) . ":" . $user2["legacy_high_score"] . ":" . $icon . ":" . $overlay . ":" . $id;
} else if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
$birdColor = $savedata['settings']['colors']['icon'] ?? [255,255,255];
$overlayColor = $savedata['settings']['colors']['overlay'] ?? [255,255,255];
$topPlayers[] = base64_encode($row["username"]) . ":" . $user2["legacy_high_score"] . ":" . $icon . ":" . $overlay . ":" . $id . ":" . $birdColor[0] . ":" . $birdColor[1] . ":" . $birdColor[2] . ":" . $overlayColor[0] . ":" . $overlayColor[1] . ":" . $overlayColor[2];
}
} }
if (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") { $output = implode("::", $topPlayers);
echo implode("::", $topPlayers);
} else if (getClientVersion() == "0") { echo $output;
echo implode(";", $topPlayers);
} else if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
echo encrypt(implode(";", $topPlayers));
}
} else { } else {
if (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") { echo -2;
echo "-2";
} else if (getClientVersion() == "0") {
echo "-1";
} else if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
echo encrypt("-1");
}
} }
$conn0->close(); $conn->close();
$conn1->close(); ?>
@@ -0,0 +1,47 @@
<?php
$conn = newConnection();
$request_username = $_POST['username'];
$request_password = $_POST['password'];
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $request_username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if (password_verify($request_password, $row["password"])) {
$login_ip = getIPAddress();
$login_time = time();
$uid = $row['id'];
$username = $row['username'];
$highscore = $row['legacy_high_score'];
$token = $row['token'];
$savedata = json_decode($row['save_data'], true);
$icon = $savedata['bird']['icon'] ?? 1;
$overlay = $savedata['bird']['overlay'] ?? 0;
$stmt = $conn->prepare("UPDATE users SET latest_ip = ? WHERE id = ?");
$stmt->bind_param("si", $login_ip, $uid);
$stmt->execute();
echo "$token:$uid:$highscore:$icon:$overlay";
} else {
$stmt->close();
$conn->close();
exit("-2");
}
}
} else {
$stmt->close();
$conn->close();
exit("-2");
}
$stmt->close();
$conn->close();
?>
@@ -0,0 +1,43 @@
<?php
$conn = newConnection();
$request_showamount = isset($_POST['showAmount']) ? $_POST['showAmount'] : 0;
switch ($request_showamount) {
case 1:
$request_limit = 100;
break;
case 2:
$request_limit = 250;
break;
case 3:
$request_limit = 500;
break;
default:
$request_limit = 50;
break;
}
$stmt = $conn->prepare("SELECT username, legacy_high_score, id, save_data FROM users WHERE legacy_high_score > 0 AND banned = 0 AND leaderboardsBanned = 0 ORDER BY legacy_high_score DESC LIMIT ?");
$stmt->bind_param("i", $request_limit);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$topPlayers = [];
while ($row = $result->fetch_assoc()) {
$savedata = json_decode($row['save_data'], true);
$icon = $savedata['bird']['icon'] ?? 1;
$overlay = $savedata['bird']['overlay'] ?? 0;
$topPlayers[] = base64_encode($row["username"]) . ":" . $row["legacy_high_score"] . ":" . $icon . ":" . $overlay . ":" . $row["id"];
}
echo implode(";", $topPlayers);
} else {
echo "-1";
}
$conn->close();
?>
+14 -50
View File
@@ -1,59 +1,23 @@
<?php <?php
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") { $token = $_POST['gameSession'] ?? '';
$post = getPostData(); $username = $_POST['userName'] ?? '';
$token = $post['gameSession'] ?? '';
$username = $post['userName'] ?? '';
} else {
$token = $_POST['gameSession'] ?? '';
$username = $_POST['userName'] ?? '';
}
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) { if ($result->num_rows > 0) {
echo (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") ? encrypt("-1") : "-1"; $row = $result->fetch_assoc();
$conn0->close(); $savedata = json_decode($row['save_data'], true);
$conn1->close(); $icon = $savedata['bird']['icon'] ?? 1;
exit; $overlay = $savedata['bird']['overlay'] ?? 0;
} echo "1:" . $row['legacy_high_score'] . ":" . $icon . ":" . $overlay;
$row = $result->fetch_assoc();
$id = $row["id"];
$stmt2 = $conn1->prepare("SELECT save_data, legacy_high_score FROM userdata WHERE id = ? AND token = ? LIMIT 1");
$stmt2->bind_param("is", $id, $token);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
echo (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") ? encrypt("-1") : "-1";
$conn0->close();
$conn1->close();
exit;
}
$user2 = $result2->fetch_assoc();
$savedata = json_decode($user2['save_data'], true);
$icon = $savedata['bird']['icon'] ?? 1;
$overlay = $savedata['bird']['overlay'] ?? 0;
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
$birdColor = $savedata['settings']['colors']['icon'] ?? [255,255,255];
$msg = "1:" . $user2['legacy_high_score'] . ":" . $icon . ":" . $overlay . ":0:0:0:0:0:0:" . ":" . $birdColor[0] . ":" . $birdColor[1] . ":" . $birdColor[2];
if (getClientVersion() == "1.5.2") {
$overlayColor = $savedata['settings']['colors']['overlay'] ?? [255,255,255];
$msg .= ":" . $overlayColor[0] . ":" . $overlayColor[1] . ":" . $overlayColor[2];
}
echo encrypt($msg);
} else { } else {
echo "1:" . $user2['legacy_high_score'] . ":" . $icon . ":" . $overlay; echo "-1";
} }
$conn0->close(); $stmt->close();
$conn1->close(); $conn->close();
@@ -0,0 +1,47 @@
<?php
$conn = newConnection();
$request_username = $_POST['username'];
$request_password = $_POST['password'];
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $request_username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if (password_verify($request_password, $row["password"])) {
$login_ip = getIPAddress();
$login_time = time();
$uid = $row['id'];
$username = $row['username'];
$highscore = $row['legacy_high_score'];
$token = $row['token'];
$savedata = json_decode($row['save_data'], true);
$icon = $savedata['bird']['icon'] ?? 1;
$overlay = $savedata['bird']['overlay'] ?? 0;
$stmt = $conn->prepare("UPDATE users SET latest_ip = ? WHERE id = ?");
$stmt->bind_param("si", $login_ip, $uid);
$stmt->execute();
echo "1:$token:$username:$uid:$highscore:$icon:$overlay";
} else {
$stmt->close();
$conn->close();
exit("-2");
}
}
} else {
$stmt->close();
$conn->close();
exit("-2");
}
$stmt->close();
$conn->close();
?>
+20 -36
View File
@@ -1,6 +1,5 @@
<?php <?php
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$request_userName = $_POST['userName'] ?? 0; $request_userName = $_POST['userName'] ?? 0;
$request_gameSession = $_POST['gameSession'] ?? ''; $request_gameSession = $_POST['gameSession'] ?? '';
@@ -8,42 +7,27 @@ $request_highScore = $_POST['highScore'] ?? 0;
$request_icon = $_POST['icon'] ?? 0; $request_icon = $_POST['icon'] ?? 0;
$request_overlay = $_POST['overlay'] ?? 0; $request_overlay = $_POST['overlay'] ?? 0;
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $request_userName); $stmt->bind_param("ss", $request_gameSession, $request_userName);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) { if ($result->num_rows > 0) {
echo "-2"; $row = $result->fetch_assoc();
$conn0->close(); $savedata = json_decode($row['save_data'], true);
$conn1->close(); $savedata['bird']['icon'] = $request_icon;
exit; $savedata['bird']['overlay'] = $request_overlay;
$savedata = json_encode($savedata);
$updateStmt = $conn->prepare("UPDATE users SET legacy_high_score = ?, save_data = ? WHERE token = ? AND username = ?");
$updateStmt->bind_param("isss", $request_highScore, $savedata, $request_gameSession, $request_userName);
$updateStmt->execute();
echo "1";
$updateStmt->close();
} else {
echo "-3";
} }
$request_uid = $result->fetch_assoc()["id"]; $stmt->close();
$conn->close();
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE token = ? AND id = ?"); ?>
$stmt2->bind_param("si", $request_gameSession, $request_uid);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
echo (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") ? "-2" : "-3";
$conn0->close();
$conn1->close();
exit;
}
$row2 = $result2->fetch_assoc();
$savedata = json_decode($row2['save_data'], true);
$savedata['bird']['icon'] = $request_icon;
$savedata['bird']['overlay'] = $request_overlay;
$savedata = json_encode($savedata);
$updateStmt = $conn1->prepare("UPDATE userdata SET legacy_high_score = ?, save_data = ? WHERE token = ? AND id = ?");
$updateStmt->bind_param("issi", $request_highScore, $savedata, $request_gameSession, $request_uid);
$updateStmt->execute();
$updateStmt->close();
echo "1";
@@ -1,46 +1,31 @@
<?php <?php
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn1 ->prepare(" $stmt = $conn->prepare("
SELECT id, content, userId SELECT c.id AS chat_id, c.content, u.username, u.id AS user_id, u.save_data
FROM chats FROM chats c
WHERE deleted_at = 0 JOIN users u ON c.userId = u.id
ORDER BY id DESC LIMIT 50 WHERE u.banned = 0 AND c.deleted_at = 0
ORDER BY c.id DESC LIMIT 50
"); ");
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
$rows = []; $rows = [];
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$userId = $row["userId"]; $savedata = json_decode($row['save_data'], true);
$stmt2 = $conn1->prepare("SELECT save_data FROM userdata WHERE id = ? LIMIT 1");
$stmt2->bind_param("i", $userId);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) continue;
$row2 = $result2->fetch_assoc();
$stmt3 = $conn0->prepare("SELECT username FROM users WHERE id = ? LIMIT 1");
$stmt3->bind_param("i", $userId);
$stmt3->execute();
$result3 = $stmt3->get_result();
if ($result3->num_rows != 1) continue;
$row3 = $result3->fetch_assoc();
$savedata = json_decode($row2['save_data'], true);
$icon = $savedata['bird']['icon'] ?? 1; $icon = $savedata['bird']['icon'] ?? 1;
$overlay = $savedata['bird']['overlay'] ?? 0; $overlay = $savedata['bird']['overlay'] ?? 0;
$birdColor = $savedata['settings']['colors']['icon'] ?? [255,255,255]; $birdColor = $savedata['settings']['colors']['icon'] ?? [255,255,255];
$overlayColor = $savedata['settings']['colors']['overlay'] ?? [255,255,255]; $overlayColor = $savedata['settings']['colors']['overlay'] ?? [255,255,255];
$rows[] = implode(";", [ $rows[] = implode(";", [
$row['id'], $row['chat_id'],
base64_encode($row3['username']), base64_encode($row['username']),
$row['content'], $row['content'],
$icon, $icon,
$overlay, $overlay,
$userId, $row['user_id'],
$birdColor[0], $birdColor[0],
$birdColor[1], $birdColor[1],
$birdColor[2], $birdColor[2],
@@ -52,5 +37,4 @@ while ($row = $result->fetch_assoc()) {
echo encrypt("1" . ":" . implode("|", array_reverse($rows))); echo encrypt("1" . ":" . implode("|", array_reverse($rows)));
$conn0->close(); $conn->close();
$conn1->close();
@@ -7,9 +7,9 @@ if (!preg_match('/^[ a-zA-Z0-9!@#\$%\^&\*\(\)_\+\-=\[\]\{\};\':",\.<>\/\?\\\\|`~
exitWithMessage("-1"); exitWithMessage("-1");
} }
$conn = newConnection(1); $conn = newConnection();
$stmt = $conn->prepare("SELECT id FROM userdata WHERE token = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ?");
$stmt->bind_param("s", $token); $stmt->bind_param("s", $token);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
+47
View File
@@ -0,0 +1,47 @@
<?php
$conn = newConnection();
$request_showamount = isset($_POST['showAmount']) ? $_POST['showAmount'] : 0;
switch ($request_showamount) {
case 1:
$request_limit = 100;
break;
case 2:
$request_limit = 250;
break;
case 3:
$request_limit = 500;
break;
default:
$request_limit = 50;
break;
}
$stmt = $conn->prepare("SELECT username, legacy_high_score, id, save_data FROM users WHERE legacy_high_score > 0 AND banned = 0 AND leaderboardsBanned = 0 ORDER BY legacy_high_score DESC LIMIT ?");
$stmt->bind_param("i", $request_limit);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$topPlayers = [];
while ($row = $result->fetch_assoc()) {
$savedata = json_decode($row['save_data'], true);
$icon = $savedata['bird']['icon'] ?? 1;
$overlay = $savedata['bird']['overlay'] ?? 0;
$birdColor = $savedata['settings']['colors']['icon'] ?? [255,255,255];
$overlayColor = $savedata['settings']['colors']['overlay'] ?? [255,255,255];
$topPlayers[] = base64_encode($row["username"]) . ":" . $row["legacy_high_score"] . ":" . $icon . ":" . $overlay . ":" . $row["id"] . ":" . $birdColor[0] . ":" . $birdColor[1] . ":" . $birdColor[2] . ":" . $overlayColor[0] . ":" . $overlayColor[1] . ":" . $overlayColor[2];
}
$output = implode(";", $topPlayers);
echo encrypt($output);
} else {
echo encrypt("-1");
}
$conn->close();
?>
+26
View File
@@ -0,0 +1,26 @@
<?php
$post = getPostData();
$token = $post['gameSession'] ?? '';
$username = $post['userName'] ?? '';
$conn = newConnection();
$stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("ss", $token, $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$savedata = json_decode($row['save_data'], true);
$icon = $savedata['bird']['icon'] ?? 1;
$overlay = $savedata['bird']['overlay'] ?? 0;
$birdColor = $savedata['settings']['colors']['icon'] ?? [255,255,255];
$overlayColor = $savedata['settings']['colors']['overlay'] ?? [255,255,255];
echo encrypt("1" . ":" . $row['legacy_high_score'] . ":" . $icon . ":" . $overlay . ":0:0:0:0:0:0:" . ":" . $birdColor[0] . ":" . $birdColor[1] . ":" . $birdColor[2] . ":" . $overlayColor[0] . ":" . $overlayColor[1] . ":" . $overlayColor[2]);
} else {
echo encrypt("-1");
}
$stmt->close();
$conn->close();
+8 -24
View File
@@ -1,6 +1,5 @@
<?php <?php
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$post = getPostData(); $post = getPostData();
$username = $post['username']; $username = $post['username'];
@@ -8,12 +7,12 @@ $password = $post['password'];
$currentHighScore = $post['currentHighScore'] ?? 0; $currentHighScore = $post['currentHighScore'] ?? 0;
$loginType = $post['loginType'] ?? '0'; $loginType = $post['loginType'] ?? '0';
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("s", $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) { if ($result->num_rows === 0) {
exitWithMessage("-1"); exitWithMessage("-1");
} }
@@ -24,29 +23,15 @@ if (!password_verify($password, $user["password"])) {
} }
$id = $user['id']; $id = $user['id'];
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE id = ?"); $token = $user['token'];
$stmt2->bind_param("i", $id);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
exitWithMessage("-1");
}
$user2 = $result2->fetch_assoc();
$token = $user2['token'];
$ip = getIPAddress(); $ip = getIPAddress();
$stmt = $conn0->prepare("UPDATE users SET latest_ip = ? WHERE id = ?"); $stmt = $conn->prepare("UPDATE users SET latest_ip = ?, token = ? WHERE id = ?");
$stmt->bind_param("si", $ip, $id); $stmt->bind_param("ssi", $ip, $token, $id);
$stmt->execute(); $stmt->execute();
$stmt2 = $conn1->prepare("UPDATE userdata SET token = ? WHERE id = ?");
$stmt2->bind_param("si", $token, $id);
$stmt2->execute();
if ($currentHighScore > $user['legacy_high_score']) { if ($currentHighScore > $user['legacy_high_score']) {
$stmt = $conn1->prepare("UPDATE userdata SET legacy_high_score = ? WHERE id = ?"); $stmt = $conn->prepare("UPDATE users SET legacy_high_score = ? WHERE id = ?");
$stmt->bind_param("ii", $currentHighScore, $id); $stmt->bind_param("ii", $currentHighScore, $id);
$stmt->execute(); $stmt->execute();
$user['legacy_high_score'] = $currentHighScore; $user['legacy_high_score'] = $currentHighScore;
@@ -62,5 +47,4 @@ if ($loginType === "0") {
echo encrypt("1" . ":" . $token . ":" . $user['username'] . ":" . $id); echo encrypt("1" . ":" . $token . ":" . $user['username'] . ":" . $id);
} }
$stmt->close(); $stmt->close();
$conn0->close(); $conn->close();
$conn1->close();
@@ -0,0 +1,42 @@
<?php
$conn = newConnection();
$post = getPostData();
$username = $post['username'] ?? '';
$password = $post['password'] ?? '';
$email = $post['email'] ?? '';
if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $username)) {
exitWithMessage("-1");
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
exitWithMessage("-2");
}
if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_\-+=]{8,}$/', $password)) {
exitWithMessage("-3");
}
$stmt = $conn->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
$stmt->bind_param("ss", $username, $email);
$stmt->execute();
$res = $stmt->get_result();
if ($res->num_rows > 0) {
exitWithMessage("-4");
}
$hashed = password_hash($password, PASSWORD_DEFAULT);
$token = bin2hex(random_bytes(256));
$ip = getIPAddress();
$time = time();
$stmt = $conn->prepare("INSERT INTO users (token, username, password, email, register_time, latest_ip) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssis", $token, $username, $hashed, $email, $time, $ip);
$stmt->execute();
$stmt->close();
$conn->close();
echo encrypt("1");
+27 -48
View File
@@ -8,61 +8,40 @@ $overlay = (int)$post['overlay'] ?? 0;
$birdR = (int)$post['birdR'] ?? 255; $birdR = (int)$post['birdR'] ?? 255;
$birdG = (int)$post['birdG'] ?? 255; $birdG = (int)$post['birdG'] ?? 255;
$birdB = (int)$post['birdB'] ?? 255; $birdB = (int)$post['birdB'] ?? 255;
if (getClientVersion() == "1.5.2") { $overlayR = (int)$post['overlayR'] ?? 255;
$overlayR = (int)$post['overlayR'] ?? 255; $overlayG = (int)$post['overlayG'] ?? 255;
$overlayG = (int)$post['overlayG'] ?? 255; $overlayB = (int)$post['overlayB'] ?? 255;
$overlayB = (int)$post['overlayB'] ?? 255;
}
$birdColor = [$birdR, $birdG, $birdB]; $birdColor = [$birdR, $birdG, $birdB];
$overlayColor = [$overlayR, $overlayG, $overlayB]; $overlayColor = [$overlayR, $overlayG, $overlayB];
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) { if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$savedata = json_decode($row['save_data'], true);
$savedata['bird']['icon'] = $icon;
$savedata['bird']['overlay'] = $overlay;
$savedata['settings']['colors']['icon'] = $birdColor;
$savedata['settings']['colors']['overlay'] = $overlayColor;
$savedata = json_encode($savedata);
$updateStmt = $conn->prepare("UPDATE users SET legacy_high_score = ?, save_data = ? WHERE token = ? AND username = ?");
$updateStmt->bind_param("isss",
$highScore,
$savedata,
$token,
$username
);
$updateStmt->execute();
$updateStmt->close();
echo encrypt("1");
} else {
echo encrypt("-1"); echo encrypt("-1");
$conn0->close();
$conn1->close();
exit;
} }
$row = $result->fetch_assoc(); $stmt->close();
$id = $row["id"]; $conn->close();
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE id = ? AND token = ?");
$stmt2->bind_param("is", $id, $token);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
echo encrypt("-1");
$conn0->close();
$conn1->close();
exit;
}
$row2 = $result2->fetch_assoc();
$savedata = json_decode($row2['save_data'], true);
$savedata['bird']['icon'] = $icon;
$savedata['bird']['overlay'] = $overlay;
$savedata['settings']['colors']['icon'] = $birdColor;
if (getClientVersion() == "1.5.2") $savedata['settings']['colors']['overlay'] = $overlayColor;
$savedata = json_encode($savedata);
$updateStmt = $conn1->prepare("UPDATE userdata SET legacy_high_score = ?, save_data = ? WHERE id = ? AND token = ?");
$updateStmt->bind_param("isis",
$highScore,
$savedata,
$id,
$token
);
$updateStmt->execute();
$updateStmt->close();
echo encrypt("1");
$conn0->close();
$conn1->close();
+20 -1
View File
@@ -1,4 +1,23 @@
<?php <?php
require __DIR__ . '/../config/general.php';
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
echo '1';
$clientVersion = $_SERVER['HTTP_CLIENTVERSION'] ?? "0";
if (($_SERVER['HTTP_REQUESTER'] ?? "0") != "BerryDashClient" && ($_SERVER['HTTP_USER_AGENT'] ?? "0") != "BerryDashClient" && ($clientVersion == "1.4.1" || $clientVersion == "1.4.0" || $clientVersion == "1.4.0-beta1")) {
exitWithMessage("-1", false);
}
if (isAllowedVersion($clientVersion) && $clientVersion == "1.4.0-beta1") {
exitWithMessage("1", false);
}
if (isLatestVersion($clientVersion)) {
echo "1";
} else if (isBetaVersion($clientVersion)) {
echo "4";
} else if (isAllowedVersion($clientVersion) && isAllowedDatabaseVersion($clientVersion)) {
echo "2";
} else if (isAllowedVersion($clientVersion)) {
echo "3";
} else {
echo "-1";
}
+40 -19
View File
@@ -1,24 +1,45 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
if ( checkClientDatabaseVersion();
getClientVersion() == "1.2-beta2" || $conn = newConnection();
getClientVersion() == "1.2" ||
getClientVersion() == "1.21" || $post = getPostData();
getClientVersion() == "1.3-beta1" || $oldpassword = $post['oldpassword'] ?? '';
getClientVersion() == "1.3-beta2" || $newpassword = $post['newpassword'] ?? '';
getClientVersion() == "1.3" || $token = $post['token'] ?? '';
getClientVersion() == "1.33" || $username = $post['username'] ?? '';
getClientVersion() == "1.4.0-beta1" ||
getClientVersion() == "1.4.0" || if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_\-+=]{8,}$/', $newpassword)) {
getClientVersion() == "1.4.1" exitWithMessage(json_encode(["success" => false, "message" => "New password must be at least 8 characters with at least one letter and one number"]));
) {
echo "-1";
exit;
}
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
exitWithMessage("-1");
exit;
} }
exitWithMessage(json_encode(["success" => false, "message" => "You must use client version 26.1 or higher to register an account in game"])); $stmt = $conn->prepare("SELECT * FROM users WHERE username = ? AND token = ?");
$stmt->bind_param("ss", $username, $token);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
if (!password_verify($oldpassword, $user['password'])) {
exitWithMessage(json_encode(["success" => false, "message" => "Old password is incorrect"]));
}
if (password_verify($newpassword, $user['password'])) {
exitWithMessage(json_encode(["success" => false, "message" => "New password cannot be the same as the old password"]));
}
$id = $user['id'];
} else {
exitWithMessage(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
}
$hashednewpassword = password_hash($newpassword, PASSWORD_DEFAULT);
$token = bin2hex(random_bytes(256));
$stmt = $conn->prepare("UPDATE users SET token = ?, password = ? WHERE id = ?");
$stmt->bind_param("sss", $token, $hashednewpassword, $id);
$stmt->execute();
$stmt->close();
$conn->close();
echo encrypt(json_encode(["success" => true, "token" => $token]));
+47 -18
View File
@@ -1,24 +1,53 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
if ( if (isAllowedDatabaseVersion(getClientVersion())) {
getClientVersion() == "1.2-beta2" || if (getClientVersion() == "1.3-beta1") {
getClientVersion() == "1.2" || require __DIR__ . '/backported/1.3-beta1/changeAccountUsername.php';
getClientVersion() == "1.21" || exit;
getClientVersion() == "1.3-beta1" || }
getClientVersion() == "1.3-beta2" || if (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") {
getClientVersion() == "1.3" || require __DIR__ . '/backported/1.3-beta2/changeAccountUsername.php';
getClientVersion() == "1.33" || exit;
getClientVersion() == "1.4.0-beta1" || }
getClientVersion() == "1.4.0" ||
getClientVersion() == "1.4.1"
) {
echo "-1";
exit;
} }
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") { checkClientDatabaseVersion();
exitWithMessage("-1"); $conn = newConnection();
exit;
$post = getPostData();
$oldusername = $post['oldusername'] ?? '';
$newusername = $post['newusername'] ?? '';
$token = $post['token'] ?? '';
$username = $post['username'] ?? '';
if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $newusername)) {
exitWithMessage(json_encode(["success" => false, "message" => "New username must be 3-16 characters, letters and numbers only"]));
} }
exitWithMessage(json_encode(["success" => false, "message" => "You must use client version 26.1 or higher to register an account in game"])); $stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $newusername);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
exitWithMessage(json_encode(["success" => false, "message" => "New username already exists"]));
}
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ? AND token = ?");
$stmt->bind_param("ss", $oldusername, $token);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
exitWithMessage(json_encode(["success" => false, "message" => "Invalid old username"]));
}
$stmt = $conn->prepare("UPDATE users SET username = ? WHERE username = ? AND token = ?");
$stmt->bind_param("sss", $newusername, $username, $token);
$stmt->execute();
if ($stmt->affected_rows === 0) {
exitWithMessage(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
}
echo encrypt(json_encode(["success" => true]));
+16 -17
View File
@@ -1,36 +1,35 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
$conn0 = newConnection(0); checkClientDatabaseVersion();
$conn1 = newConnection(1); $conn = newConnection();
$post = getPostData(); $post = getPostData();
$targetId = (int)$post['targetId'] ?? 0; $targetId = (int)$post['targetId'] ?? 0;
$token = $post['token'] ?? ''; $token = $post['token'] ?? '';
$username = $post['username'] ?? ''; $username = $post['username'] ?? '';
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) exitWithMessage(json_encode(["success" => false, "message" => 'User info not found']));
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
if (!$row) {
echo encrypt(json_encode(["success" => false, "message" => 'User info not found']));
exit;
}
$stmt->close();
$user_id = $row["id"]; $user_id = $row["id"];
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE token = ? AND id = ?");
$stmt2->bind_param("si", $token, $user_id);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) exitWithMessage(json_encode(["success" => false, "message" => 'User info not found']));
$row2 = $result2->fetch_assoc();
$time = time(); $time = time();
$stmt = $conn1->prepare("UPDATE userposts SET deleted_at = ? WHERE id = ? AND userId = ? AND deleted_at = 0"); $stmt = $conn->prepare("UPDATE userposts SET deleted_at = ? WHERE id = ? AND userId = ? AND deleted_at = 0");
$stmt->bind_param("iii", $time, $targetId, $user_id); $stmt->bind_param("iii", $time, $targetId, $user_id);
$stmt->execute(); $stmt->execute();
echo encrypt(json_encode(["success" => $stmt->affected_rows > 0])); $success = $stmt->affected_rows > 0;
$stmt->close();
$conn0->close(); echo encrypt(json_encode(["success" => $success]));
$conn1->close();
$conn->close();
+1
View File
@@ -1,6 +1,7 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
checkClientDatabaseVersion();
$post = getPostData(); $post = getPostData();
$id = $post['id'] ?? ''; $id = $post['id'] ?? '';
+6 -16
View File
@@ -1,6 +1,7 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
checkClientDatabaseVersion();
$post = getPostData(); $post = getPostData();
$id = $post['id'] ?? ''; $id = $post['id'] ?? '';
@@ -10,11 +11,10 @@ $username = $post['username'] ?? '';
if (!preg_match('/^[ a-zA-Z0-9!@#\$%\^&\*\(\)_\+\-=\[\]\{\};\':",\.<>\/\?\\\\|`~]+$/', $content)) exit; if (!preg_match('/^[ a-zA-Z0-9!@#\$%\^&\*\(\)_\+\-=\[\]\{\};\':",\.<>\/\?\\\\|`~]+$/', $content)) exit;
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
@@ -22,21 +22,11 @@ if (!$row) exit;
$stmt->close(); $stmt->close();
$user_id = $row["id"]; $user_id = $row["id"];
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE token = ? AND id = ?");
$stmt2->bind_param("si", $token, $user_id);
$stmt2->execute();
$result2 = $stmt2->get_result();
$row2 = $result2->fetch_assoc();
if (!$row2) exit;
$stmt2->close();
$content = base64_encode($content); $content = base64_encode($content);
$stmt = $conn1->prepare("UPDATE chats SET content = ? WHERE userId = ? AND id = ?"); $stmt = $conn->prepare("UPDATE chats SET content = ? WHERE userId = ? AND id = ?");
$stmt->bind_param("sii", $content, $user_id, $id); $stmt->bind_param("sii", $content, $user_id, $id);
$stmt->execute(); $stmt->execute();
$stmt->close(); $stmt->close();
$conn0->close(); $conn->close();
$conn1->close();
+5 -13
View File
@@ -1,28 +1,21 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
checkClientDatabaseVersion();
$post = getPostData(); $post = getPostData();
$uesrId = $post['uesrId'] ?? ''; $uesrId = $post['uesrId'] ?? '';
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT username, id FROM users WHERE id = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE id = ?");
$stmt->bind_param("i", $uesrId); $stmt->bind_param("i", $uesrId);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows > 0) { if ($result->num_rows > 0) {
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
$savedata = json_decode($row['save_data'], true);
$stmt2 = $conn1->prepare("SELECT save_data FROM userdata WHERE id = ?");
$stmt2->bind_param("i", $row['id']);
$stmt2->execute();
$result2 = $stmt2->get_result();
$row2 = $result2->fetch_assoc();
$savedata = json_decode($row2['save_data'], true);
$custom = null; $custom = null;
if (isset($savedata['bird']['customIcon']['selected'])) { if (isset($savedata['bird']['customIcon']['selected'])) {
$selected = $savedata['bird']['customIcon']['selected']; $selected = $savedata['bird']['customIcon']['selected'];
@@ -56,5 +49,4 @@ if ($result->num_rows > 0) {
} }
$stmt->close(); $stmt->close();
$conn0->close(); $conn->close();
$conn1->close();
+7 -19
View File
@@ -1,35 +1,23 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
checkClientDatabaseVersion();
$conn = newConnection(); $conn = newConnection();
$post = getPostData(); $post = getPostData();
$targetId = (int)$post['targetId'] ?? 0; $targetId = (int)$post['targetId'] ?? 0;
$stmt = $conn->prepare(" $stmt = $conn->prepare("
SELECT id, content, timestamp, votes, userId SELECT p.id, p.content, p.timestamp, p.likes, u.id as userId
FROM userposts FROM userposts p
WHERE userId = ? AND deleted_at = 0 JOIN users u ON p.userId = u.id
ORDER BY id DESC WHERE u.id = ? AND p.deleted_at = 0
ORDER BY p.id DESC
"); ");
$stmt->bind_param("i", $targetId); $stmt->bind_param("i", $targetId);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
echo encrypt(json_encode(array_map( echo encrypt(json_encode(array_map(fn($row) => ['id' => $row['id'], 'userId' => $row['userId'], 'content' => $row['content'], 'timestamp' => genTimestamp($row['timestamp']) . " ago", 'likes' => $row['likes']], $result->fetch_all(MYSQLI_ASSOC))));
function ($row) {
$votes = json_decode($row['votes'], true);
$likes = is_array($votes) ? array_sum(array_map(fn($v) => $v === true ? 1 : -1, $votes)) : 0;
return [
'id' => $row['id'],
'userId' => $row['userId'],
'content' => $row['content'],
'timestamp' => genTimestamp($row['timestamp']) . " ago",
'likes' => $likes
];
},
$result->fetch_all(MYSQLI_ASSOC)
)));
$conn->close(); $conn->close();
+19 -32
View File
@@ -1,18 +1,21 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
if (getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") { if (isAllowedDatabaseVersion(getClientVersion())) {
require __DIR__ . '/backported/1.5.1/getChatroomMessages.php'; if (getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
exit; require __DIR__ . '/backported/1.5.1/getChatroomMessages.php';
exit;
}
} }
$conn0 = newConnection(0); checkClientDatabaseVersion();
$conn1 = newConnection(1); $conn = newConnection();
$stmt = $conn1->prepare(" $stmt = $conn->prepare("
SELECT id, content, deleted_at, userId SELECT c.id AS chat_id, c.content, c.deleted_at, u.id AS user_id, u.username, u.save_data
FROM chats FROM chats c
WHERE deleted_at = 0 JOIN users u ON c.userId = u.id
ORDER BY id DESC WHERE u.banned = 0 AND c.deleted_at = 0
ORDER BY c.id DESC
LIMIT 50 LIMIT 50
"); ");
$stmt->execute(); $stmt->execute();
@@ -23,27 +26,12 @@ $rows = $result->fetch_all(MYSQLI_ASSOC);
$mapped = []; $mapped = [];
$icons = []; $icons = [];
foreach ($rows as $row) { foreach ($rows as $row) {
$userId = $row["userId"]; $savedata = json_decode($row['save_data'], true);
$stmt2 = $conn1->prepare("SELECT legacy_high_score, save_data FROM userdata WHERE id = ? LIMIT 1");
$stmt2->bind_param("i", $userId);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) continue;
$row2 = $result2->fetch_assoc();
$stmt3 = $conn0->prepare("SELECT username FROM users WHERE id = ? LIMIT 1");
$stmt3->bind_param("i", $userId);
$stmt3->execute();
$result3 = $stmt3->get_result();
if ($result3->num_rows != 1) continue;
$row3 = $result3->fetch_assoc();
$savedata = json_decode($row2['save_data'], true);
$customIcon = $savedata['bird']['customIcon']['selected'] ?? null; $customIcon = $savedata['bird']['customIcon']['selected'] ?? null;
if ($customIcon != null && strlen($customIcon) == 36 && $icons[$customIcon] == null) { if ($customIcon != null && strlen($customIcon) == 36 && $icons[$customIcon] == null) {
$stmt = $conn1->prepare("SELECT data FROM marketplaceicons WHERE uuid = ?"); $stmt = $conn->prepare("SELECT data FROM marketplaceicons WHERE uuid = ?");
$stmt->bind_param("s", $customIcon); $stmt->bind_param("s", $customIcon);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
@@ -55,11 +43,11 @@ foreach ($rows as $row) {
} }
$mapped[] = [ $mapped[] = [
'username' => $row3['username'], 'username' => $row['username'],
'userid' => $row['userId'], 'userid' => $row['user_id'],
'content' => (int)$row['deleted_at'] == 0 ? $row['content'] : null, 'content' => (int)$row['deleted_at'] == 0 ? $row['content'] : null,
'deleted' => (int)$row['deleted_at'] != 0, 'deleted' => (int)$row['deleted_at'] != 0,
'id' => $row['id'], 'id' => $row['chat_id'],
'icon' => $savedata['bird']['icon'] ?? 1, 'icon' => $savedata['bird']['icon'] ?? 1,
'overlay' => $savedata['bird']['overlay'] ?? 0, 'overlay' => $savedata['bird']['overlay'] ?? 0,
'birdColor' => $savedata['settings']['colors']['icon'] ?? [255,255,255], 'birdColor' => $savedata['settings']['colors']['icon'] ?? [255,255,255],
@@ -75,5 +63,4 @@ if (getClientVersion() == "1.6") {
echo encrypt(json_encode(["messages" => array_reverse($mapped), "customIcons" => $icons == [] ? new stdClass() : $icons])); echo encrypt(json_encode(["messages" => array_reverse($mapped), "customIcons" => $icons == [] ? new stdClass() : $icons]));
} }
$conn0->close(); $conn->close();
$conn1->close();
+18
View File
@@ -0,0 +1,18 @@
<?php
require __DIR__ . '/../incl/util.php';
setJsonHeader();
$conn = newConnection();
$stmt = $conn->prepare("
SELECT c.id, c.content, u.username
FROM chats c
JOIN users u ON c.userId = u.id
WHERE u.banned = 0 AND c.deleted_at = 0
ORDER BY c.id ASC LIMIT 50
");
$stmt->execute();
$result = $stmt->get_result();
echo json_encode(array_map(fn($row) => ['username' => $row['username'], 'content' => base64_decode($row['content']), 'contentRaw' => $row['content'], 'messageId' => $row['id']], $result->fetch_all(MYSQLI_ASSOC)), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$conn->close();
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php
require __DIR__ . '/../config/general.php';
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
echo "1.8.2"; echo $latestVersion;
+30 -50
View File
@@ -1,74 +1,75 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
$conn0 = newConnection(0); checkClientDatabaseVersion();
$conn1 = newConnection(1); $conn = newConnection();
$post = getPostData(); $post = getPostData();
$userId = (int) $post['userId'] ?? 0; $userId = (int)$post['userId'] ?? 0;
$sortBy = (int) $post['sortBy'] ?? 2; $sortBy = (int)$post['sortBy'] ?? 2;
$priceRangeEnabled = isset($post['priceRangeEnabled']) ? (string) $post['priceRangeEnabled'] == 'False' ? false : true : false; $priceRangeEnabled = isset($post['priceRangeEnabled']) ? (string)$post['priceRangeEnabled'] == 'False' ? false : true : false;
$priceRangeMin = (int) $post['priceRangeMin'] ?? 10; $priceRangeMin = (int)$post['priceRangeMin'] ?? 10;
$priceRangeMax = (int) $post['priceRangeMax'] ?? 250; $priceRangeMax = (int)$post['priceRangeMax'] ?? 250;
$searchForEnabled = isset($post['searchForEnabled']) ? (string) $post['searchForEnabled'] == 'False' ? false : true : false; $searchForEnabled = isset($post['searchForEnabled']) ? (string)$post['searchForEnabled'] == 'False' ? false : true : false;
$searchForValue = (string) $post['searchForValue'] ?? ''; $searchForValue = (string)$post['searchForValue'] ?? '';
$onlyShowEnabled = isset($post['onlyShowEnabled']) ? (string) $post['onlyShowEnabled'] == 'False' ? false : true : false; $onlyShowEnabled = isset($post['onlyShowEnabled']) ? (string)$post['onlyShowEnabled'] == 'False' ? false : true : false;
$onlyShowValue = (string) $post['onlyShowValue'] ?? ''; $onlyShowValue = (string)$post['onlyShowValue'] ?? '';
$currentIcons = json_decode(base64_decode((string) ($post['currentIcons'] ?? 'W10K'))); $currentIcons = json_decode(base64_decode((string)($post['currentIcons'] ?? 'W10K')));
$where = ["(state = 1 OR state = 2)"]; $where = ["u.banned = 0", "(c.state = 1 OR c.state = 2)"];
$params = []; $params = [];
$types = ""; $types = "";
$order = match ($sortBy) { $order = match($sortBy) {
1 => "ORDER BY price ASC", 1 => "ORDER BY c.price ASC",
2 => "ORDER BY id ASC", 2 => "ORDER BY c.id ASC",
3 => "ORDER BY id DESC", 3 => "ORDER BY c.id DESC",
default => "ORDER BY price DESC", default => "ORDER BY c.price DESC",
}; };
if ($priceRangeEnabled) { if ($priceRangeEnabled) {
$where[] = "price BETWEEN ? AND ?"; $where[] = "c.price BETWEEN ? AND ?";
$params[] = $priceRangeMin; $params[] = $priceRangeMin;
$params[] = $priceRangeMax; $params[] = $priceRangeMax;
$types .= "ii"; $types .= "ii";
} }
if ($searchForEnabled && $searchForValue !== '') { if ($searchForEnabled && $searchForValue !== '') {
$where[] = "FROM_BASE64(name) LIKE ?"; $where[] = "FROM_BASE64(c.name) LIKE ?";
$params[] = "%$searchForValue%"; $params[] = "%$searchForValue%";
$types .= "s"; $types .= "s";
} }
if ($onlyShowEnabled) { if ($onlyShowEnabled) {
if ($onlyShowValue === '0') { if ($onlyShowValue === '0') {
$where[] = "userId = ?"; $where[] = "c.userId = ?";
$params[] = $userId; $params[] = $userId;
$types .= "i"; $types .= "i";
} elseif ($onlyShowValue === '1') { } elseif ($onlyShowValue === '1') {
$where[] = "userId != ?"; $where[] = "c.userId != ?";
$params[] = $userId; $params[] = $userId;
$types .= "i"; $types .= "i";
} elseif ($onlyShowValue === '2') { } elseif ($onlyShowValue === '2') {
$placeholders = implode(',', array_fill(0, count($currentIcons), '?')); $placeholders = implode(',', array_fill(0, count($currentIcons), '?'));
$where[] = "uuid IN ($placeholders)"; $where[] = "c.uuid IN ($placeholders)";
$params = array_merge($params, $currentIcons); $params = array_merge($params, $currentIcons);
$types .= str_repeat('s', count($currentIcons)); $types .= str_repeat('s', count($currentIcons));
} elseif ($onlyShowValue === '3') { } elseif ($onlyShowValue === '3') {
$placeholders = implode(',', array_fill(0, count($currentIcons), '?')); $placeholders = implode(',', array_fill(0, count($currentIcons), '?'));
$where[] = "uuid NOT IN ($placeholders)"; $where[] = "c.uuid NOT IN ($placeholders)";
$params = array_merge($params, $currentIcons); $params = array_merge($params, $currentIcons);
$types .= str_repeat('s', count($currentIcons)); $types .= str_repeat('s', count($currentIcons));
} }
} }
$sql = " $sql = "
SELECT data, price, name, uuid, state, userId SELECT c.data, u.username, u.id, c.price, c.name, c.uuid, c.state
FROM marketplaceicons FROM marketplaceicons c
JOIN users u ON c.userId = u.id
WHERE " . implode(" AND ", $where) . " WHERE " . implode(" AND ", $where) . "
$order $order
"; ";
$stmt = $conn1->prepare($sql); $stmt = $conn->prepare($sql);
if (!empty($params)) { if (!empty($params)) {
$stmt->bind_param($types, ...$params); $stmt->bind_param($types, ...$params);
@@ -77,27 +78,6 @@ if (!empty($params)) {
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
echo encrypt(json_encode(array_map( echo encrypt(json_encode(array_map(fn($row) => ['username' => $row['username'], 'userid' => $row['id'], 'data' => $row['data'], 'uuid' => $row['uuid'], 'price' => (int)$row['state'] == 2 ? 100000000 : $row['price'], 'name' => base64_decode($row['name'])], $result->fetch_all(MYSQLI_ASSOC))));
function ($row) {
global $conn0;
$stmt2 = $conn0->prepare("SELECT username FROM users WHERE id = ?"); $conn->close();
$stmt2->bind_param("i", $row['userId']);
$stmt2->execute();
$result2 = $stmt2->get_result();
$row2 = $result2->fetch_assoc();
return [
'username' => $row2['username'] ?? 'Unknown',
'userid' => $row['userId'],
'data' => $row['data'],
'uuid' => $row['uuid'],
'price' => (int) $row['state'] == 2 ? 100000000 : $row['price'],
'name' => base64_decode($row['name'])
];
},
$result->fetch_all(MYSQLI_ASSOC)
)));
$conn0->close();
$conn1->close();
+24 -31
View File
@@ -1,22 +1,26 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
if ( if (getClientVersion() == "0" && isAllowedDatabaseVersion("1.4.0-beta1") && isAllowedDatabaseVersion("1.4.0") && isAllowedDatabaseVersion("1.4.1")) {
getClientVersion() == "1.3-beta2" || require __DIR__ . '/backported/1.4.0-beta1/getTopPlayers.php';
getClientVersion() == "1.3" ||
getClientVersion() == "1.33" ||
getClientVersion() == "0" || // 1.4.x
getClientVersion() == "1.5.0" ||
getClientVersion() == "1.5.1" ||
getClientVersion() == "1.5.2"
) {
require __DIR__ . '/backported/1.3-beta2/getTopPlayers.php';
exit; exit;
} }
if (isAllowedDatabaseVersion(getClientVersion())) {
if (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") {
require __DIR__ . '/backported/1.3-beta2/getTopPlayers.php';
exit;
}
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
require __DIR__ . '/backported/1.5/getTopPlayers.php';
exit;
}
}
if ($_SERVER['HTTP_REQUESTER'] != 'BerryDashLauncher') {
checkClientDatabaseVersion();
}
$post = getPostData(); $post = getPostData();
$request_type = $post['type'] ?? ''; $request_type = $post['type'] ?? '';
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$request_value = ""; $request_value = "";
if ($request_type === "0") { if ($request_type === "0") {
@@ -36,7 +40,9 @@ if ($request_type === "0") {
exitWithMessage(json_encode([])); exitWithMessage(json_encode([]));
} }
$stmt = $conn0->prepare("SELECT username, id FROM users WHERE leaderboards_banned = 0"); $stmt = $conn->prepare("SELECT username, id, save_data, legacy_high_score
FROM users
WHERE banned = 0 AND leaderboardsBanned = 0");
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
@@ -45,19 +51,7 @@ $rows = $result->fetch_all(MYSQLI_ASSOC);
$mapped = []; $mapped = [];
$icons = []; $icons = [];
foreach ($rows as $row) { foreach ($rows as $row) {
$id = $row["id"]; $savedata = json_decode($row['save_data'], true);
$stmt2 = $conn1->prepare("SELECT legacy_high_score, save_data FROM userdata WHERE id = ? LIMIT 1");
$stmt2->bind_param("i", $id);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
continue;
}
$user2 = $result2->fetch_assoc();
$savedata = json_decode($user2['save_data'], true);
if (!$savedata) continue; if (!$savedata) continue;
if ($request_type == "4") { if ($request_type == "4") {
@@ -65,14 +59,14 @@ foreach ($rows as $row) {
$value = 0; $value = 0;
foreach ($berries as $b) $value += (int)($savedata['gameStore'][$b] ?? 0); foreach ($berries as $b) $value += (int)($savedata['gameStore'][$b] ?? 0);
} else { } else {
$value = $request_type != 2 ? $request_type != 3 ? ($savedata['gameStore'][$request_value] ?? 0) : ($user2['legacy_high_score'] ?? 0) : ($savedata['bird']['customIcon']['balance'] ?? 0); $value = $request_type != 2 ? $request_type != 3 ? ($savedata['gameStore'][$request_value] ?? 0) : ($row['legacy_high_score'] ?? 0) : ($savedata['bird']['customIcon']['balance'] ?? 0);
} }
if ($value <= 0) continue; if ($value <= 0) continue;
$customIcon = $savedata['bird']['customIcon']['selected'] ?? null; $customIcon = $savedata['bird']['customIcon']['selected'] ?? null;
if ($customIcon != null && strlen($customIcon) == 36 && $icons[$customIcon] == null) { if ($customIcon != null && strlen($customIcon) == 36 && $icons[$customIcon] == null) {
$stmt = $conn1->prepare("SELECT data FROM marketplaceicons WHERE uuid = ?"); $stmt = $conn->prepare("SELECT data FROM marketplaceicons WHERE uuid = ?");
$stmt->bind_param("s", $customIcon); $stmt->bind_param("s", $customIcon);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
@@ -85,7 +79,7 @@ foreach ($rows as $row) {
$mapped[] = [ $mapped[] = [
'username' => $row['username'], 'username' => $row['username'],
'userid' => $id, 'userid' => $row['id'],
'value' => $value, 'value' => $value,
'icon' => $savedata['bird']['icon'] ?? 1, 'icon' => $savedata['bird']['icon'] ?? 1,
'overlay' => $savedata['bird']['overlay'] ?? 0, 'overlay' => $savedata['bird']['overlay'] ?? 0,
@@ -104,5 +98,4 @@ if (getClientVersion() == "1.6" || (getClientVersion() == "1.6.1" && $request_ty
echo encrypt(json_encode(["entries" => $limited, "customIcons" => $icons == [] ? new stdClass() : $icons])); echo encrypt(json_encode(["entries" => $limited, "customIcons" => $icons == [] ? new stdClass() : $icons]));
} }
$conn0->close(); $conn->close();
$conn1->close();
+34
View File
@@ -0,0 +1,34 @@
<?php
require __DIR__ . '/../incl/util.php';
setJsonHeader();
$conn = newConnection();
$stmt = $conn->prepare("SELECT username, id, save_data
FROM users
WHERE banned = 0 AND leaderboardsBanned = 0");
$stmt->execute();
$result = $stmt->get_result();
$rows = $result->fetch_all(MYSQLI_ASSOC);
$mapped = [];
foreach ($rows as $row) {
$savedata = json_decode($row['save_data'], true);
if (!$savedata) continue;
$value = $savedata['gameStore']['highScore'] ?? 0;
if ($value <= 0) continue;
$mapped[] = [
'username' => $row['username'],
'score' => (int)$value,
'scoreFormatted' => number_format($value)
];
}
usort($mapped, fn($a,$b) => $b['score'] <=> $a['score']);
$limited = array_slice($mapped, 0, 500);
echo json_encode($limited);
$conn->close();
Regular → Executable
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php
require __DIR__ . '/../../incl/util.php'; require __DIR__ . '/../../incl/util.php';
require __DIR__ . '/../../config/general.php';
setPlainHeader(); setPlainHeader();
echo "-1"; echo $latestLauncherVersion;
Regular → Executable
+12 -1
View File
@@ -9,6 +9,17 @@ $stmt->execute();
$result_versions = $stmt->get_result(); $result_versions = $stmt->get_result();
$versions = array_map(fn($row) => ['id' => $row['id'], 'version' => $row['version'], 'releaseDate' => $row['releaseDate'], 'displayName' => empty($row['displayName']) ? $row['version'] : $row['displayName'], 'platforms' => json_decode($row['platforms']), 'downloadUrls' => json_decode($row['downloadUrls']), 'executables' => json_decode($row['executables']), 'category' => $row['category']], $result_versions->fetch_all(MYSQLI_ASSOC)); $versions = array_map(fn($row) => ['id' => $row['id'], 'version' => $row['version'], 'releaseDate' => $row['releaseDate'], 'displayName' => empty($row['displayName']) ? $row['version'] : $row['displayName'], 'platforms' => json_decode($row['platforms']), 'downloadUrls' => json_decode($row['downloadUrls']), 'executables' => json_decode($row['executables']), 'category' => $row['category']], $result_versions->fetch_all(MYSQLI_ASSOC));
echo json_encode($versions); $stmt = $conn->prepare("SELECT * FROM launchercategories ORDER BY id DESC");
$stmt->execute();
$result_categories = $stmt->get_result();
$rows = $result_categories->fetch_all(MYSQLI_ASSOC);
$categories = [];
foreach ($rows as $row) {
$categories[$row['id']] = $row['name'];
}
echo json_encode(["versions" => $versions, "categories" => $categories]);
$conn->close(); $conn->close();
+26 -46
View File
@@ -1,62 +1,42 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
if ( if (isAllowedDatabaseVersion(getClientVersion())) {
getClientVersion() == "1.4.0-beta1" || if (getClientVersion() == "1.4.0-beta1") {
getClientVersion() == "1.4.0" || require __DIR__ . '/backported/1.4.0-beta1/loadAccount.php';
getClientVersion() == "1.4.1" || exit;
getClientVersion() == "1.5.0" || }
getClientVersion() == "1.5.1" || if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
getClientVersion() == "1.5.2" require __DIR__ . '/backported/1.5/loadAccount.php';
) { exit;
require __DIR__ . '/backported/1.4.0-beta1/loadAccount.php'; }
exit;
} }
checkClientDatabaseVersion();
$post = getPostData(); $post = getPostData();
$token = $post['token'] ?? ''; $token = $post['token'] ?? '';
$username = $post['username'] ?? ''; $username = $post['username'] ?? '';
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT id, username FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) { if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$savedata = json_decode($row['save_data'], true);
$savedata['account']['id'] = $row['id'];
$savedata['account']['name'] = $row['username'];
$savedata['account']['session'] = $row['token'];
echo encrypt(json_encode([
"success" => true,
"data" => $savedata
]));
} else {
echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"])); echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
$conn0->close();
$conn1->close();
exit;
} }
$row = $result->fetch_assoc(); $stmt->close();
$id = $row["id"]; $conn->close();
$stmt2 = $conn1->prepare("SELECT save_data, token FROM userdata WHERE id = ? AND token = ?");
$stmt2->bind_param("is", $id, $token);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
$conn0->close();
$conn1->close();
exit;
}
$row2 = $result2->fetch_assoc();
$savedata = json_decode($row2['save_data'], true);
$savedata['account']['id'] = $id;
$savedata['account']['name'] = $row['username'];
$savedata['account']['session'] = $row2['token'];
echo encrypt(json_encode([
"success" => true,
"data" => $savedata
]));
$conn0->close();
$conn1->close();
+30 -42
View File
@@ -1,38 +1,42 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
if ( if (isAllowedDatabaseVersion(getClientVersion())) {
getClientVersion() == "1.2-beta2" || if (
getClientVersion() == "1.2" || getClientVersion() == "1.2-beta2" ||
getClientVersion() == "1.21" || getClientVersion() == "1.2" ||
getClientVersion() == "1.3-beta1" || getClientVersion() == "1.21" ||
getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3-beta1"
getClientVersion() == "1.3" || ) {
getClientVersion() == "1.33" || require __DIR__ . '/backported/1.2-beta2/loginAccount.php';
getClientVersion() == "1.4.0-beta1" || exit;
getClientVersion() == "1.4.0" || }
getClientVersion() == "1.4.1" if (getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3" || getClientVersion() == "1.33") {
) { require __DIR__ . '/backported/1.3-beta2/loginAccount.php';
require __DIR__ . '/backported/1.2-beta2/loginAccount.php'; exit;
exit; }
if (getClientVersion() == "1.4.0-beta1") {
require __DIR__ . '/backported/1.4.0-beta1/loginAccount.php';
exit;
}
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
require __DIR__ . '/backported/1.5/loginAccount.php';
exit;
}
} }
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") { checkClientDatabaseVersion();
require __DIR__ . '/backported/1.5/loginAccount.php'; $conn = newConnection();
exit;
}
$conn0 = newConnection(0);
$conn1 = newConnection(1);
$post = getPostData(); $post = getPostData();
$username = $post['username']; $username = $post['username'];
$password = $post['password']; $password = $post['password'];
$stmt = $conn0->prepare("SELECT id, username, password FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("s", $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) { if ($result->num_rows === 0) {
exitWithMessage(json_encode(["success" => false, "message" => "Invalid username or password"])); exitWithMessage(json_encode(["success" => false, "message" => "Invalid username or password"]));
} }
@@ -43,32 +47,16 @@ if (!password_verify($password, $user["password"])) {
} }
$id = $user['id']; $id = $user['id'];
$token = $user['token'];
$stmt2 = $conn1->prepare("SELECT token FROM userdata WHERE id = ?");
$stmt2->bind_param("i", $id);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) {
exitWithMessage(json_encode(["success" => false, "message" => "Invalid username or password"]));
}
$user2 = $result2->fetch_assoc();
$token = $user2['token'];
$ip = getIPAddress(); $ip = getIPAddress();
$stmt = $conn0->prepare("UPDATE users SET latest_ip = ? WHERE id = ?"); $stmt = $conn->prepare("UPDATE users SET latest_ip = ?, token = ? WHERE id = ?");
$stmt->bind_param("si", $ip, $id); $stmt->bind_param("ssi", $ip, $token, $id);
$stmt->execute(); $stmt->execute();
$stmt2 = $conn1->prepare("UPDATE userdata SET token = ? WHERE id = ?");
$stmt2->bind_param("si", $token, $id);
$stmt2->execute();
$data = ["session" => $token, "username" => $user['username'], "userid" => $id]; $data = ["session" => $token, "username" => $user['username'], "userid" => $id];
echo encrypt(json_encode(["success" => true, "data" => $data])); echo encrypt(json_encode(["success" => true, "data" => $data]));
$stmt->close(); $stmt->close();
$conn0->close(); $conn->close();
$conn1->close();
+58 -18
View File
@@ -1,24 +1,64 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
if ( if (isAllowedDatabaseVersion(getClientVersion())) {
getClientVersion() == "1.2-beta2" || if (getClientVersion() == "1.2-beta2" || getClientVersion() == "1.2") {
getClientVersion() == "1.2" || require __DIR__ . '/backported/1.2-beta2/registerAccount.php';
getClientVersion() == "1.21" || exit;
getClientVersion() == "1.3-beta1" || }
getClientVersion() == "1.3-beta2" || if (
getClientVersion() == "1.3" || getClientVersion() == "1.21" ||
getClientVersion() == "1.33" || getClientVersion() == "1.3-beta1" ||
getClientVersion() == "1.4.0-beta1" || getClientVersion() == "1.3-beta2" ||
getClientVersion() == "1.4.0" || getClientVersion() == "1.3"
getClientVersion() == "1.4.1" ) {
) { require __DIR__ . '/backported/1.21/registerAccount.php';
echo "-1"; exit;
exit; }
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
require __DIR__ . '/backported/1.5/registerAccount.php';
exit;
}
} }
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") { checkClientDatabaseVersion();
exitWithMessage("-1"); $conn = newConnection();
exit;
$post = getPostData();
$username = $post['username'] ?? '';
$password = $post['password'] ?? '';
$email = $post['email'] ?? '';
if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $username)) {
exitWithMessage(json_encode(["success" => false, "message" => "Username must be 3-16 characters, letters and numbers only"]));
} }
exitWithMessage(json_encode(["success" => false, "message" => "You must use client version 26.1 or higher to register an account in game"])); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
exitWithMessage(json_encode(["success" => false, "message" => "Email is invalid"]));
}
if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_\-+=]{8,}$/', $password)) {
exitWithMessage(json_encode(["success" => false, "message" => "Password must be at least 8 characters with at least one letter and one number"]));
}
$stmt = $conn->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
$stmt->bind_param("ss", $username, $email);
$stmt->execute();
$res = $stmt->get_result();
if ($res->num_rows > 0) {
exitWithMessage(json_encode(["success" => false, "message" => "Username or email already taken"]));
}
$hashed = password_hash($password, PASSWORD_DEFAULT);
$token = bin2hex(random_bytes(256));
$ip = getIPAddress();
$time = time();
$stmt = $conn->prepare("INSERT INTO users (token, username, password, email, register_time, latest_ip) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssis", $token, $username, $hashed, $email, $time, $ip);
$stmt->execute();
$stmt->close();
$conn->close();
echo encrypt(json_encode(["success" => true]));
+12 -19
View File
@@ -1,6 +1,7 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
checkClientDatabaseVersion();
$post = getPostData(); $post = getPostData();
$id = $post['id'] ?? ''; $id = $post['id'] ?? '';
@@ -8,30 +9,23 @@ $reason = $post['reason'] ?? '';
$token = $post['token'] ?? ''; $token = $post['token'] ?? '';
$username = $post['username'] ?? ''; $username = $post['username'] ?? '';
if (!preg_match('/^[ a-zA-Z0-9!@#\$%\^&\*\(\)_\+\-=\[\]\{\};\':",\.<>\/\?\\\\|`~]+$/', $reason)) exit; if (!preg_match('/^[ a-zA-Z0-9!@#\$%\^&\*\(\)_\+\-=\[\]\{\};\':",\.<>\/\?\\\\|`~]+$/', $reason)) {
exitWithMessage(json_encode(["success" => false]));
}
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ? LIMIT 1"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
if ($result->num_rows != 1) exit; if (!$row) exit;
$stmt->close(); $stmt->close();
$user_id = $row["id"]; $user_id = $row["id"];
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE id = ? AND token = ? LIMIT 1"); $stmt = $conn->prepare("SELECT id FROM chats WHERE userId != ? AND deleted_at = 0 AND id = ? LIMIT 1");
$stmt2->bind_param("is", $user_id, $token);
$stmt2->execute();
$result2 = $stmt2->get_result();
$row2 = $result2->fetch_assoc();
if ($result2->num_rows != 1) exit;
$stmt2->close();
$stmt = $conn1->prepare("SELECT id FROM chats WHERE userId != ? AND deleted_at = 0 AND id = ? LIMIT 1");
$stmt->bind_param("ii", $user_id, $id); $stmt->bind_param("ii", $user_id, $id);
$stmt->execute(); $stmt->execute();
$res = $stmt->get_result(); $res = $stmt->get_result();
@@ -39,7 +33,7 @@ $stmt->close();
if ($res->num_rows < 0) exit; if ($res->num_rows < 0) exit;
$stmt = $conn1->prepare("SELECT id FROM chatroom_reports WHERE chatId = ? AND userId = ? LIMIT 1"); $stmt = $conn->prepare("SELECT id FROM chatroom_reports WHERE chatId = ? AND userId = ? LIMIT 1");
$stmt->bind_param("ii", $id, $user_id); $stmt->bind_param("ii", $id, $user_id);
$stmt->execute(); $stmt->execute();
$res = $stmt->get_result(); $res = $stmt->get_result();
@@ -50,9 +44,8 @@ if ($res->num_rows > 0) exit;
$time = time(); $time = time();
$reason = base64_encode($reason); $reason = base64_encode($reason);
$stmt = $conn1->prepare("INSERT INTO chatroom_reports (chatid, userId, reason, timestamp) VALUES (?, ?, ?, ?)"); $stmt = $conn->prepare("INSERT INTO chatroom_reports (chatid, userId, reason, timestamp) VALUES (?, ?, ?, ?)");
$stmt->bind_param("iisi", $id, $user_id, $reason, $time); $stmt->bind_param("iisi", $id, $user_id, $reason, $time);
$stmt->execute(); $stmt->execute();
$conn0->close(); $conn->close();
$conn1->close();
+34 -50
View File
@@ -1,26 +1,29 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
if ( if (isAllowedDatabaseVersion(getClientVersion())) {
getClientVersion() == "1.2-beta2" || if (
getClientVersion() == "1.2" || getClientVersion() == "1.2-beta2" ||
getClientVersion() == "1.21" || getClientVersion() == "1.2" ||
getClientVersion() == "1.3-beta1" || getClientVersion() == "1.21" ||
getClientVersion() == "1.3-beta2" || getClientVersion() == "1.3-beta1" ||
getClientVersion() == "1.3" || getClientVersion() == "1.3-beta2" ||
getClientVersion() == "1.33" getClientVersion() == "1.3" ||
) { getClientVersion() == "1.33"
require __DIR__ . '/backported/1.2-beta2/syncAccount.php'; ) {
exit; require __DIR__ . '/backported/1.2-beta2/syncAccount.php';
} exit;
if (getClientVersion() == "1.4.0-beta1" || getClientVersion() == "1.4.0" || getClientVersion() == "1.4.1") { }
require __DIR__ . '/backported/1.4.0-beta1/saveAccount.php'; if (getClientVersion() == "1.4.0-beta1") {
exit; require __DIR__ . '/backported/1.4.0-beta1/saveAccount.php';
} exit;
if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") { }
require __DIR__ . '/backported/1.5/saveAccount.php'; if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
exit; require __DIR__ . '/backported/1.5/saveAccount.php';
exit;
}
} }
checkClientDatabaseVersion();
$post = getPostData(); $post = getPostData();
$token = $post['token'] ?? ''; $token = $post['token'] ?? '';
@@ -37,41 +40,22 @@ try {
echo encrypt(json_encode(["success" => false, "message" => "Couldn't parse save data"])); echo encrypt(json_encode(["success" => false, "message" => "Couldn't parse save data"]));
} }
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) { if ($result->num_rows > 0) {
$updateStmt = $conn->prepare("UPDATE users SET save_data = ? WHERE token = ? AND username = ?");
$updateStmt->bind_param("sss", $savedata, $token, $username);
$updateStmt->execute();
$updateStmt->close();
echo encrypt(json_encode(["success" => true]));
} else {
echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"])); echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
$conn0->close();
$conn1->close();
exit;
} }
$row = $result->fetch_assoc(); $stmt->close();
$id = $row["id"]; $conn->close();
$stmt = $conn1->prepare("SELECT id FROM userdata WHERE token = ? AND id = ?");
$stmt->bind_param("si", $token, $id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows != 1) {
echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
$conn0->close();
$conn1->close();
exit;
}
$updateStmt = $conn1->prepare("UPDATE userdata SET save_data = ? WHERE token = ? AND id = ?");
$updateStmt->bind_param("ssi", $savedata, $token, $id);
$updateStmt->execute();
$updateStmt->close();
echo encrypt(json_encode(["success" => true]));
$conn0->close();
$conn1->close();
+11 -19
View File
@@ -1,10 +1,13 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
if (getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") { if (isAllowedDatabaseVersion(getClientVersion())) {
require __DIR__ . '/backported/1.5.1/sendChatroomMessage.php'; if (getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
exit; require __DIR__ . '/backported/1.5.1/sendChatroomMessage.php';
exit;
}
} }
checkClientDatabaseVersion();
$post = getPostData(); $post = getPostData();
$request_content = $post['content'] ?? ''; $request_content = $post['content'] ?? '';
@@ -15,11 +18,10 @@ if (!preg_match('/^[ a-zA-Z0-9!@#\$%\^&\*\(\)_\+\-=\[\]\{\};\':",\.<>\/\?\\\\|`~
exitWithMessage(json_encode(["success" => false, "message" => "Invalid content recieved"])); exitWithMessage(json_encode(["success" => false, "message" => "Invalid content recieved"]));
} }
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
@@ -27,24 +29,14 @@ if (!$row) exitWithMessage(json_encode(["success" => false, "message" => "Invali
$stmt->close(); $stmt->close();
$id = $row["id"]; $id = $row["id"];
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE id = ? AND token = ?");
$stmt2->bind_param("is", $id, $token);
$stmt2->execute();
$result2 = $stmt2->get_result();
$row2 = $result2->fetch_assoc();
if (!$row2) exitWithMessage(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
$stmt2->close();
$content = base64_encode($request_content); $content = base64_encode($request_content);
$time = time(); $time = time();
$stmt = $conn1->prepare("INSERT INTO chats (userId, content, timestamp) VALUES (?, ?, ?)"); $stmt = $conn->prepare("INSERT INTO chats (userId, content, timestamp) VALUES (?, ?, ?)");
$stmt->bind_param("isi", $id, $content, $time); $stmt->bind_param("isi", $id, $content, $time);
$stmt->execute(); $stmt->execute();
$stmt->close(); $stmt->close();
echo encrypt(json_encode(["success" => true])); echo encrypt(json_encode(["success" => true]));
$conn0->close(); $conn->close();
$conn1->close();
+9 -16
View File
@@ -1,6 +1,7 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
checkClientDatabaseVersion();
$post = getPostData(); $post = getPostData();
$request_content = $post['content'] ?? ''; $request_content = $post['content'] ?? '';
@@ -11,33 +12,25 @@ if (!preg_match('/^[ a-zA-Z0-9!@#\$%\^&\*\(\)_\+\-=\[\]\{\};\':",\.<>\/\?\\\\|`~
exitWithMessage(json_encode(["success" => false])); exitWithMessage(json_encode(["success" => false]));
} }
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result->num_rows != 1) exitWithMessage(json_encode(["success" => false]));
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
if (!$row) exitWithMessage(json_encode(["success" => false]));
$stmt->close();
$id = $row["id"]; $id = $row["id"];
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE token = ? AND id = ?");
$stmt2->bind_param("si", $token, $id);
$stmt2->execute();
$result2 = $stmt2->get_result();
if ($result2->num_rows != 1) exitWithMessage(json_encode(["success" => false]));
$row2 = $result2->fetch_assoc();
$content = base64_encode($request_content); $content = base64_encode($request_content);
$time = time(); $time = time();
$stmt = $conn1->prepare("INSERT INTO userposts (userId, content, timestamp) VALUES (?, ?, ?)"); $stmt = $conn->prepare("INSERT INTO userposts (userId, content, timestamp) VALUES (?, ?, ?)");
$stmt->bind_param("isi", $id, $content, $time); $stmt->bind_param("isi", $id, $content, $time);
$stmt->execute(); $stmt->execute();
$stmt->close(); $stmt->close();
echo encrypt(json_encode(["success" => true])); echo encrypt(json_encode(["success" => true]));
$conn0->close(); $conn->close();
$conn1->close();
+10 -19
View File
@@ -1,6 +1,7 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
checkClientDatabaseVersion();
$post = getPostData(); $post = getPostData();
$token = $post['token'] ?? ''; $token = $post['token'] ?? '';
@@ -19,32 +20,23 @@ if (strlen($decoded) > 1024 * 1024) exitWithMessage(json_encode(["success" => fa
$info = getimagesizefromstring($decoded); $info = getimagesizefromstring($decoded);
if (!$info) exitWithMessage(json_encode(["success" => false, "message" => "Invalid image uploaded"])); if (!$info) exitWithMessage(json_encode(["success" => false, "message" => "Invalid image uploaded"]));
if ($info[2] !== IMAGETYPE_PNG) exitWithMessage(json_encode(["success" => false, "message" => "Image must be a PNG"])); if ($info[2] !== IMAGETYPE_PNG) exitWithMessage(json_encode(["success" => false, "message" => "Image must be a PNG"]));
if ($info[0] !== 128 || $info[1] !== 128) exitWithMessage(json_encode(["success" => false, "message" => "Image has to be 128x128"])); if ($info[0] !== 128 || $info[1] !== 128) exitWithMessage(json_encode(["success" => false, "message" => "Invalid has to be 128x128"]));
$conn0 = newConnection(0); $conn = newConnection();
$conn1 = newConnection(1);
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
if (!$row) exitWithMessage(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"])); if (!$row) exitWithMessage(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
$stmt->close(); $stmt->close();
$id = $row["id"]; $id = $row["id"];
$stmt2 = $conn1->prepare("SELECT * FROM userdata WHERE token = ? AND id = ?");
$stmt2->bind_param("si", $token, $id);
$stmt2->execute();
$result2 = $stmt2->get_result();
$row2 = $result2->fetch_assoc();
if (!$row2) exitWithMessage(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
$stmt2->close();
$time = time(); $time = time();
$hash = hash('sha512', base64_decode($filecontent)); $hash = hash('sha512', base64_decode($filecontent));
$stmt = $conn1->prepare("SELECT id FROM marketplaceicons WHERE hash = ?"); $stmt = $conn->prepare("SELECT id FROM marketplaceicons WHERE hash = ?");
$stmt->bind_param("s", $hash); $stmt->bind_param("s", $hash);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
@@ -56,13 +48,12 @@ $stmt->close();
$uuid = uuidv4(); $uuid = uuidv4();
$stmt = $conn1->prepare("INSERT INTO marketplaceicons (uuid, userId, data, hash, price, name, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?)"); $stmt = $conn->prepare("INSERT INTO marketplaceicons (uuid, userId, data, hash, price, name, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sissisi", $uuid, $id, $filecontent, $hash, $price, $name, $time); $stmt->bind_param("sissisi", $uuid, $id, $filecontent, $hash, $price, $name, $time);
$stmt->execute(); $stmt->execute();
$insertId = $conn1->insert_id; $insertId = $conn->insert_id;
$stmt->close(); $stmt->close();
echo encrypt(json_encode(["success" => true, "message" => "Icon uploaded successfully! It will be reviewed and accepted or denied soon"])); echo encrypt(json_encode(["success" => true, "message" => "Icon uploaded successfully! It will be reviewed and accepted or denied soon"]));
$conn0->close(); $conn->close();
$conn1->close();
+7 -8
View File
@@ -1,8 +1,8 @@
<?php <?php
require __DIR__ . '/../incl/util.php'; require __DIR__ . '/../incl/util.php';
setPlainHeader(); setPlainHeader();
$conn0 = newConnection(0); checkClientDatabaseVersion();
$conn1 = newConnection(1); $conn = newConnection();
$post = getPostData(); $post = getPostData();
$targetId = (int)$post['targetId'] ?? 0; $targetId = (int)$post['targetId'] ?? 0;
@@ -14,8 +14,8 @@ if ($liked !== 0 && $liked !== 1) {
exit; exit;
} }
$stmt = $conn0->prepare("SELECT * FROM users WHERE username = ?"); $stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("s", $username); $stmt->bind_param("ss", $token, $username);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
@@ -27,7 +27,7 @@ $stmt->close();
$user_id = $row["id"]; $user_id = $row["id"];
$stmt = $conn1->prepare("SELECT votes, likes FROM userposts WHERE id = ?"); $stmt = $conn->prepare("SELECT votes, likes FROM userposts WHERE id = ?");
$stmt->bind_param("i", $targetId); $stmt->bind_param("i", $targetId);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
@@ -49,12 +49,11 @@ $votes[$user_id] = $liked === 0 ? false : true;
$likes += $liked ? 1 : -1; $likes += $liked ? 1 : -1;
$votes = json_encode($votes); $votes = json_encode($votes);
$stmt = $conn1->prepare("UPDATE userposts SET likes = ?, votes = ? WHERE id = ?"); $stmt = $conn->prepare("UPDATE userposts SET likes = ?, votes = ? WHERE id = ?");
$stmt->bind_param("isi", $likes, $votes, $targetId); $stmt->bind_param("isi", $likes, $votes, $targetId);
$stmt->execute(); $stmt->execute();
$stmt->close(); $stmt->close();
echo encrypt(json_encode(["success" => true, "likes" => $likes])); echo encrypt(json_encode(["success" => true, "likes" => $likes]));
$conn0->close(); $conn->close();
$conn1->close();
+6
View File
@@ -0,0 +1,6 @@
import os
keys_needed = ["SERVER_RECEIVE_TRANSFER_KEY", "SERVER_SEND_TRANSFER_KEY", "BAZOOKA_MANAGER_KEY", "BAZOOKA_MANAGER_FILE_KEY"]
for key_needed in keys_needed:
print("Key for \"" + key_needed + "\": " + os.urandom(16).hex())
-1
View File
@@ -1 +0,0 @@
Require all denied
+39 -17
View File
@@ -8,23 +8,17 @@ function setJsonHeader() {
} }
function getIPAddress() { function getIPAddress() {
return $_SERVER['REMOTE_ADDR']; return $_SERVER['HTTP_CF_CONNECTING_IP'];
} }
function newConnection($type = 1) { function newConnection() {
include __DIR__.'/../config/connection.php'; include __DIR__.'/../config/connection.php';
try { try {
return new mysqli( $conn = new mysqli($db_host, $db_user, $db_pass, $db_name, $db_port);
$type === 0 ? $games_db_host : $bd_db_host,
$type === 0 ? $games_db_user : $bd_db_user,
$type === 0 ? $games_db_pass : $bd_db_pass,
$type === 0 ? $games_db_name : $bd_db_name,
$type === 0 ? $games_db_port : $bd_db_port
);
} catch (mysqli_sql_exception $e) { } catch (mysqli_sql_exception $e) {
exitWithMessage("-999"); exitWithMessage("-999");
} }
return $conn;
} }
function getClientVersion() { function getClientVersion() {
@@ -33,21 +27,17 @@ function getClientVersion() {
function encrypt($plainText) { function encrypt($plainText) {
include __DIR__.'/../config/encryption.php'; include __DIR__.'/../config/encryption.php';
$key = $SERVER_SEND_TRANSFER_KEY_SPECIFIC[getClientVersion()];
if ($key == null) return;
$iv = random_bytes(16); $iv = random_bytes(16);
$cipher = openssl_encrypt($plainText, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv); $cipher = openssl_encrypt($plainText, 'aes-256-cbc', $SERVER_SEND_TRANSFER_KEY_SPECIFIC[getClientVersion()] ?? $SERVER_SEND_TRANSFER_KEY, OPENSSL_RAW_DATA, $iv);
return base64_encode($iv . $cipher); return base64_encode($iv . $cipher);
} }
function decrypt($dataB64) { function decrypt($dataB64) {
include __DIR__.'/../config/encryption.php'; include __DIR__.'/../config/encryption.php';
$key = $SERVER_RECEIVE_TRANSFER_KEY_SPECIFIC[getClientVersion()];
if ($key == null) return;
$data = base64_decode($dataB64); $data = base64_decode($dataB64);
$iv = substr($data, 0, 16); $iv = substr($data, 0, 16);
$cipher = substr($data, 16); $cipher = substr($data, 16);
$decrypted = openssl_decrypt($cipher, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv); $decrypted = openssl_decrypt($cipher, 'aes-256-cbc', $SERVER_RECEIVE_TRANSFER_KEY_SPECIFIC[getClientVersion()] ?? $SERVER_RECEIVE_TRANSFER_KEY, OPENSSL_RAW_DATA, $iv);
if ($decrypted === false) { if ($decrypted === false) {
exit(encrypt('-997')); exit(encrypt('-997'));
} }
@@ -63,13 +53,45 @@ function exitWithMessage($message, $encrypt = true) {
exit; exit;
} }
function isLatestVersion($version) {
global $latestVersion;
if (!isset($latestVersion)) require __DIR__ . '/../config/general.php';
return $version === $latestVersion;
}
function isBetaVersion($version) {
global $latestBetaVersion;
if (!isset($latestBetaVersion)) require __DIR__ . '/../config/general.php';
return $version === $latestBetaVersion;
}
function isAllowedVersion($version) {
global $allowedVersions;
if (!isset($allowedVersions)) require __DIR__ . '/../config/general.php';
return in_array($version, $allowedVersions);
}
function isAllowedDatabaseVersion($version) {
global $allowedDatabaseVersions;
if (!isset($allowedDatabaseVersions)) require __DIR__ . '/../config/general.php';
return in_array($version, $allowedDatabaseVersions);
}
function checkClientDatabaseVersion() {
global $allowedDatabaseVersions;
if (!isset($allowedDatabaseVersions)) require __DIR__ . '/../config/general.php';
if (!isset($_SERVER['HTTP_REQUESTER'])) exitWithMessage("-998");
if ($_SERVER['HTTP_REQUESTER'] != "BerryDashClient") exitWithMessage("-998");
if (!in_array($_SERVER['HTTP_CLIENTVERSION'] ?? '', $allowedDatabaseVersions)) exitWithMessage("-998");
}
function getPostData() { function getPostData() {
$raw = file_get_contents("php://input"); $raw = file_get_contents("php://input");
parse_str($raw, $postData); parse_str($raw, $postData);
$decrypted = []; $decrypted = [];
foreach ($postData as $k => $v) { foreach ($postData as $k => $v) {
$decKey = (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1") ? $k : decrypt($k); $decKey = decrypt($k);
$decValue = decrypt($v); $decValue = decrypt($v);
$decrypted[$decKey] = $decValue; $decrypted[$decKey] = $decValue;
} }