mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
updated website for new db
This commit is contained in:
@@ -1,29 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Class DataBase
|
||||
*
|
||||
* This class handles database operations using PDO.
|
||||
*/
|
||||
class DataBase {
|
||||
|
||||
/**
|
||||
* @var PDO The PDO instance for database connection.
|
||||
*/
|
||||
private $PDO;
|
||||
|
||||
/**
|
||||
* Constructor method to initialize the database connection.
|
||||
*/
|
||||
public function __construct() {
|
||||
try {
|
||||
$this->PDO = new PDO("mysql:host=".DB_HOST."; port=".DB_PORT."; dbname=".DB_NAME, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
|
||||
// Establish a connection to the database using PDO
|
||||
$this->PDO = new PDO(
|
||||
"mysql:host=".DB_HOST."; port=".DB_PORT."; dbname=".DB_NAME,
|
||||
DB_USER,
|
||||
DB_PASS,
|
||||
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
|
||||
);
|
||||
}
|
||||
catch(PDOException $ex)
|
||||
{
|
||||
catch(PDOException $ex) {
|
||||
// Display error message if connection fails
|
||||
echo "<div style='display: flex; flex-direction: column;align-items: center;justify-content: center;text-align: center;'><h2>Problem with database!</h2>";
|
||||
die("<pre style='padding: 10px;text-wrap: balance; border: 2px solid #ed6bd3;background: #252525; color: #ed6bd3; width: 50%;'>" . $ex . "</pre>");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a SELECT query on the database.
|
||||
*
|
||||
* @param string $query The SQL query to execute.
|
||||
* @param array $bindings An associative array of parameters and their values.
|
||||
* @return array|false Returns an array of rows as associative arrays or false if no results are found.
|
||||
*/
|
||||
public function select($query, $bindings = []) {
|
||||
// Prepare and execute the SQL query
|
||||
$STH = $this->PDO->prepare($query);
|
||||
$STH->execute($bindings);
|
||||
|
||||
// Fetch the results as associative arrays
|
||||
$result = $STH->fetchAll(PDO::FETCH_ASSOC);
|
||||
$result ??= false;
|
||||
return $result;
|
||||
$result ??= false; // Set $result to false if it's null
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function query($query, $bindings = []){
|
||||
/**
|
||||
* Perform a non-query SQL statement on the database.
|
||||
*
|
||||
* @param string $query The SQL query to execute.
|
||||
* @param array $bindings An associative array of parameters and their values.
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
public function query($query, $bindings = []) {
|
||||
// Prepare and execute the SQL query
|
||||
$STH = $this->PDO->prepare($query);
|
||||
return $STH->execute($bindings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Class UtilsClass
|
||||
*
|
||||
* Provides utility methods for handling skin and weapon data.
|
||||
*/
|
||||
class UtilsClass
|
||||
{
|
||||
/**
|
||||
* Retrieve skins data from the JSON file.
|
||||
*
|
||||
* @return array An associative array containing skin data.
|
||||
*/
|
||||
public static function skinsFromJson(): array
|
||||
{
|
||||
$skins = [];
|
||||
$json = json_decode(file_get_contents(__DIR__ . "/../data/skins.json"), true);
|
||||
$jsonFilePath = __DIR__ . "/../data/skins.json";
|
||||
|
||||
foreach ($json as $skin) {
|
||||
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = [
|
||||
'weapon_name' => $skin['weapon_name'],
|
||||
'paint_name' => $skin['paint_name'],
|
||||
'image_url' => $skin['image'],
|
||||
];
|
||||
if (file_exists($jsonFilePath) && is_readable($jsonFilePath)) {
|
||||
$json = json_decode(file_get_contents($jsonFilePath), true);
|
||||
|
||||
foreach ($json as $skin) {
|
||||
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = [
|
||||
'weapon_name' => $skin['weapon_name'],
|
||||
'paint_name' => $skin['paint_name'],
|
||||
'image_url' => $skin['image'],
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// Handle file not found or unreadable error
|
||||
// You can throw an exception or log an error message
|
||||
}
|
||||
|
||||
return $skins;
|
||||
}
|
||||
|
||||
public static function getWeaponsFromArray()
|
||||
/**
|
||||
* Retrieve weapons data from the skin data array.
|
||||
*
|
||||
* @return array An associative array containing weapon data.
|
||||
*/
|
||||
public static function getWeaponsFromArray(): array
|
||||
{
|
||||
$weapons = [];
|
||||
$temp = self::skinsFromJson();
|
||||
|
||||
foreach ($temp as $key => $value) {
|
||||
if (key_exists($key, $weapons))
|
||||
continue;
|
||||
$skinsData = self::skinsFromJson();
|
||||
|
||||
foreach ($skinsData as $key => $value) {
|
||||
$weapons[$key] = [
|
||||
'weapon_name' => $value[0]['weapon_name'],
|
||||
'paint_name' => $value[0]['paint_name'],
|
||||
@@ -36,65 +55,61 @@ class UtilsClass
|
||||
return $weapons;
|
||||
}
|
||||
|
||||
public static function getKnifeTypes()
|
||||
/**
|
||||
* Retrieve knife types from the weapon data array.
|
||||
*
|
||||
* @return array An associative array containing knife types data.
|
||||
*/
|
||||
public static function getKnifeTypes(): array
|
||||
{
|
||||
$knifes = [];
|
||||
$temp = self::getWeaponsFromArray();
|
||||
$weaponsData = self::getWeaponsFromArray();
|
||||
|
||||
foreach ($temp as $key => $weapon) {
|
||||
if (
|
||||
!in_array($key, [
|
||||
500,
|
||||
503,
|
||||
505,
|
||||
506,
|
||||
507,
|
||||
508,
|
||||
509,
|
||||
512,
|
||||
514,
|
||||
515,
|
||||
516,
|
||||
517,
|
||||
518,
|
||||
519,
|
||||
520,
|
||||
521,
|
||||
522,
|
||||
523,
|
||||
525
|
||||
])
|
||||
)
|
||||
continue;
|
||||
$allowedKnifeKeys = [
|
||||
500, 503, 505, 506, 507, 508, 509, 512, 514, 515,
|
||||
516, 517, 518, 519, 520, 521, 522, 523, 525
|
||||
];
|
||||
|
||||
$knifes[$key] = [
|
||||
'weapon_name' => $weapon['weapon_name'],
|
||||
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
|
||||
'image_url' => $weapon['image_url'],
|
||||
];
|
||||
$knifes[0] = [
|
||||
'weapon_name' => "weapon_knife",
|
||||
'paint_name' => "Default knife",
|
||||
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
|
||||
];
|
||||
foreach ($weaponsData as $key => $weapon) {
|
||||
if (in_array($key, $allowedKnifeKeys)) {
|
||||
$knifes[$key] = [
|
||||
'weapon_name' => $weapon['weapon_name'],
|
||||
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
|
||||
'image_url' => $weapon['image_url'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Add default knife
|
||||
$knifes[0] = [
|
||||
'weapon_name' => "weapon_knife",
|
||||
'paint_name' => "Default knife",
|
||||
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
|
||||
];
|
||||
|
||||
ksort($knifes);
|
||||
return $knifes;
|
||||
}
|
||||
|
||||
public static function getSelectedSkins(array $temp)
|
||||
/**
|
||||
* Retrieve selected skins data from the database result.
|
||||
*
|
||||
* @param array $temp An array containing the selected skins data.
|
||||
* @return array An associative array containing selected skins data.
|
||||
*/
|
||||
public static function getSelectedSkins(array $temp): array
|
||||
{
|
||||
$selected = [];
|
||||
|
||||
foreach ($temp as $weapon) {
|
||||
$selected[$weapon['weapon_defindex']] = [
|
||||
'weapon_paint_id' => $weapon['weapon_paint_id'],
|
||||
'weapon_seed' => $weapon['weapon_seed'],
|
||||
'weapon_wear' => $weapon['weapon_wear'],
|
||||
$selected[$weapon['weapon']] = [
|
||||
'weapon_paint_id' => $weapon['paint'],
|
||||
'weapon_seed' => $weapon['seed'],
|
||||
'weapon_wear' => $weapon['wear'],
|
||||
];
|
||||
}
|
||||
|
||||
return $selected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,261 +1,36 @@
|
||||
<?php
|
||||
require_once 'class/config.php';
|
||||
require_once 'class/database.php';
|
||||
require_once 'steamauth/steamauth.php';
|
||||
require_once 'class/utils.php';
|
||||
|
||||
$db = new DataBase();
|
||||
if (isset($_SESSION['steamid'])) {
|
||||
|
||||
$steamid = $_SESSION['steamid'];
|
||||
|
||||
$weapons = UtilsClass::getWeaponsFromArray();
|
||||
$skins = UtilsClass::skinsFromJson();
|
||||
$querySelected = $db->select("SELECT `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed` FROM `wp_player_skins` WHERE `wp_player_skins`.`steamid` = :steamid", ["steamid" => $steamid]);
|
||||
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
||||
$selectedKnife = $db->select("SELECT * FROM `wp_player_knife` WHERE `wp_player_knife`.`steamid` = :steamid", ["steamid" => $steamid]);
|
||||
$knifes = UtilsClass::getKnifeTypes();
|
||||
|
||||
if (isset($_POST['forma'])) {
|
||||
$ex = explode("-", $_POST['forma']);
|
||||
|
||||
if ($ex[0] == "knife") {
|
||||
$db->query("INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(:steamid, :knife) ON DUPLICATE KEY UPDATE `knife` = :knife", ["steamid" => $steamid, "knife" => $knifes[$ex[1]]['weapon_name']]);
|
||||
} else {
|
||||
if (array_key_exists($ex[1], $skins[$ex[0]]) && isset($_POST['wear']) && $_POST['wear'] >= 0.00 && $_POST['wear'] <= 1.00 && isset($_POST['seed'])) {
|
||||
$wear = floatval($_POST['wear']); // wear
|
||||
$seed = intval($_POST['seed']); // seed
|
||||
if (array_key_exists($ex[0], $selectedSkins)) {
|
||||
$db->query("UPDATE wp_player_skins SET weapon_paint_id = :weapon_paint_id, weapon_wear = :weapon_wear, weapon_seed = :weapon_seed WHERE steamid = :steamid AND weapon_defindex = :weapon_defindex", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1], "weapon_wear" => $wear, "weapon_seed" => $seed]);
|
||||
} else {
|
||||
$db->query("INSERT INTO wp_player_skins (`steamid`, `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed`) VALUES (:steamid, :weapon_defindex, :weapon_paint_id, :weapon_wear, :weapon_seed)", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1], "weapon_wear" => $wear, "weapon_seed" => $seed]);
|
||||
}
|
||||
}
|
||||
}
|
||||
header("Location: {$_SERVER['PHP_SELF']}");
|
||||
}
|
||||
}
|
||||
require 'class/header.php';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"<?php if(WEB_STYLE_DARK) echo 'data-bs-theme="dark"'?>>
|
||||
|
||||
<html lang="en" <?php if (WEB_STYLE_DARK) echo 'data-bs-theme="dark"' ?>>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js"></script>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>CS2 Simple Weapon Paints</title>
|
||||
<meta charset="utf-8">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js"></script>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>CS2 Simple Weapon Paints</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
if (!isset($_SESSION['steamid'])) {
|
||||
echo "<div class='bg-primary'><h2>To choose weapon paints loadout, you need to ";
|
||||
loginbutton("rectangle");
|
||||
echo "</h2></div>";
|
||||
} else {
|
||||
echo "<div class='bg-primary'><h2>Your current weapon skin loadout <a class='btn btn-danger' href='{$_SERVER['PHP_SELF']}?logout'>Logout</a></h2> </div>";
|
||||
echo "<div class='card-group mt-2'>";
|
||||
?>
|
||||
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3 border border-primary">
|
||||
<div class="card-body">
|
||||
<?php
|
||||
$actualKnife = $knifes[0];
|
||||
if ($selectedKnife != null)
|
||||
{
|
||||
foreach ($knifes as $knife) {
|
||||
if ($selectedKnife[0]['knife'] == $knife['weapon_name']) {
|
||||
$actualKnife = $knife;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
||||
echo "<h5 class='card-title item-name'>{$actualKnife["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$actualKnife["image_url"]}' class='skin-image'>";
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<form action="" method="POST">
|
||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||
<option disabled>Select knife</option>
|
||||
<?php
|
||||
foreach ($knifes as $knifeKey => $knife) {
|
||||
if ($selectedKnife[0]['knife'] == $knife['weapon_name'])
|
||||
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
else
|
||||
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
foreach ($weapons as $defindex => $default) { ?>
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3">
|
||||
<div class="card-body">
|
||||
<?php
|
||||
if (array_key_exists($defindex, $selectedSkins)) {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]['image_url']}' class='skin-image'>";
|
||||
} else {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$default["image_url"]}' class='skin-image'>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<form action="" method="POST">
|
||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||
<option disabled>Select skin</option>
|
||||
<?php
|
||||
foreach ($skins[$defindex] as $paintKey => $paint) {
|
||||
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex]['weapon_paint_id'] == $paintKey)
|
||||
echo "<option selected value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||
else
|
||||
echo "<option value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br></br>
|
||||
<?php
|
||||
$selectedSkinInfo = isset($selectedSkins[$defindex]) ? $selectedSkins[$defindex] : null;
|
||||
$steamid = $_SESSION['steamid'];
|
||||
|
||||
if ($selectedSkinInfo) :
|
||||
?>
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#weaponModal<?php echo $defindex ?>">
|
||||
Settings
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<button type="button" class="btn btn-primary" onclick="showSkinSelectionAlert()">
|
||||
Settings
|
||||
</button>
|
||||
<script>
|
||||
function showSkinSelectionAlert() {
|
||||
alert("You need to select a skin first.");
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// wear value
|
||||
$selectedSkinInfo = isset($selectedSkins[$defindex]['weapon_paint_id']) ? $selectedSkins[$defindex] : null;
|
||||
$queryWear = $selectedSkins[$defindex]['weapon_wear'] ?? 1.0;
|
||||
$initialWearValue = isset($selectedSkinInfo['weapon_wear']) ? $selectedSkinInfo['weapon_wear'] : (isset($queryWear[0]['weapon_wear']) ? $queryWear[0] : 0.0);
|
||||
|
||||
// seed value
|
||||
$querySeed = $selectedSkins[$defindex]['weapon_seed'] ?? 0;
|
||||
$initialSeedValue = isset($selectedSkinInfo['weapon_seed']) ? $selectedSkinInfo['weapon_seed'] : 0;
|
||||
?>
|
||||
|
||||
|
||||
<div class="modal fade" id="weaponModal<?php echo $defindex ?>" tabindex="-1" role="dialog" aria-labelledby="weaponModalLabel<?php echo $defindex ?>" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class='card-title item-name'>
|
||||
<?php
|
||||
if (array_key_exists($defindex, $selectedSkins)) {
|
||||
echo "{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]} Settings";
|
||||
} else {
|
||||
echo "{$default["paint_name"]} Settings";
|
||||
}
|
||||
?>
|
||||
</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<select class="form-select" id="wearSelect<?php echo $defindex ?>" name="wearSelect" onchange="updateWearValue<?php echo $defindex ?>(this.value)">
|
||||
<option disabled>Select Wear</option>
|
||||
<option value="0.00" <?php echo ($initialWearValue == 0.00) ? 'selected' : ''; ?>>Factory New</option>
|
||||
<option value="0.07" <?php echo ($initialWearValue == 0.07) ? 'selected' : ''; ?>>Minimal Wear</option>
|
||||
<option value="0.15" <?php echo ($initialWearValue == 0.15) ? 'selected' : ''; ?>>Field-Tested</option>
|
||||
<option value="0.38" <?php echo ($initialWearValue == 0.38) ? 'selected' : ''; ?>>Well-Worn</option>
|
||||
<option value="0.45" <?php echo ($initialWearValue == 0.45) ? 'selected' : ''; ?>>Battle-Scarred</option>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="wear">Wear:</label>
|
||||
<input type="text" value="<?php echo $initialWearValue; ?>" class="form-control" id="wear<?php echo $defindex ?>" name="wear">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="seed">Seed:</label>
|
||||
<input type="text" value="<?php echo $initialSeedValue; ?>" class="form-control" id="seed<?php echo $defindex ?>" name="seed" oninput="validateSeed(this)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-danger">Use</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
// wear
|
||||
function updateWearValue<?php echo $defindex ?>(selectedValue) {
|
||||
var wearInputElement = document.getElementById("wear<?php echo $defindex ?>");
|
||||
wearInputElement.value = selectedValue;
|
||||
}
|
||||
|
||||
function validateWear(inputElement) {
|
||||
inputElement.value = inputElement.value.replace(/[^0-9]/g, '');
|
||||
}
|
||||
// seed
|
||||
function validateSeed(input) {
|
||||
// Check entered value
|
||||
var inputValue = input.value.replace(/[^0-9]/g, ''); // Just get the numbers
|
||||
|
||||
if (inputValue === "") {
|
||||
input.value = 0; // Set to 0 if empty or no numbers
|
||||
} else {
|
||||
var numericValue = parseInt(inputValue);
|
||||
numericValue = Math.min(1000, Math.max(1, numericValue)); // Interval control
|
||||
|
||||
input.value = numericValue;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
|
||||
<div class="col-md-4 d-flex align-items-center">
|
||||
<span class="mb-3 mb-md-0 text-body-secondary">© 2023 <a href="https://github.com/Nereziel/cs2-WeaponPaints">Nereziel/cs2-WeaponPaints</a></span>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
<?php if (!isset($_SESSION['steamid'])) : ?>
|
||||
<div class='bg-primary'><h2>To choose weapon paints loadout, you need to <?php loginbutton("rectangle"); ?></h2></div>
|
||||
<?php else : ?>
|
||||
<div class='bg-primary'><h2>Your current weapon skin loadout <a class='btn btn-danger' href='<?php echo $_SERVER['PHP_SELF']; ?>?logout'>Logout</a></h2> </div>
|
||||
<div class='card-group mt-2'>
|
||||
<!-- Display user's selected knife -->
|
||||
<?php require_once 'view/display_knife.php'; ?>
|
||||
<!-- Display user's selected skins for different weapons -->
|
||||
<?php require_once 'view/display_weapons.php'; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<!-- Footer section -->
|
||||
<div class="container">
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
|
||||
<div class="col-md-4 d-flex align-items-center">
|
||||
<span class="mb-3 mb-md-0 text-body-secondary">© 2024 <a href="https://github.com/Nereziel/cs2-WeaponPaints">Nereziel/cs2-WeaponPaints</a></span>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
21
website/steamauth/licence.txt
Normal file
21
website/steamauth/licence.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Benjamin Smith
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
ob_start();
|
||||
session_start();
|
||||
//ob_start();
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
function logoutbutton() {
|
||||
echo "<form action='' method='get'><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form>"; //logout button
|
||||
echo "<form><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form>"; //logout button
|
||||
}
|
||||
|
||||
function loginbutton($buttonstyle = "square") {
|
||||
|
||||
@@ -7,7 +7,6 @@ if (empty($_SESSION['steam_uptodate']) or empty($_SESSION['steam_personaname']))
|
||||
$_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
|
||||
$_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate'];
|
||||
$_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname'];
|
||||
$_SESSION['steam_lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
|
||||
$_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl'];
|
||||
$_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar'];
|
||||
$_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
|
||||
@@ -27,7 +26,6 @@ $steamprofile['steamid'] = $_SESSION['steam_steamid'];
|
||||
$steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate'];
|
||||
$steamprofile['profilestate'] = $_SESSION['steam_profilestate'];
|
||||
$steamprofile['personaname'] = $_SESSION['steam_personaname'];
|
||||
$steamprofile['lastlogoff'] = $_SESSION['steam_lastlogoff'];
|
||||
$steamprofile['profileurl'] = $_SESSION['steam_profileurl'];
|
||||
$steamprofile['avatar'] = $_SESSION['steam_avatar'];
|
||||
$steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium'];
|
||||
|
||||
42
website/view/display_knife.php
Normal file
42
website/view/display_knife.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3 border border-primary">
|
||||
<div class="card-body">
|
||||
<?php
|
||||
// Determine the user's selected knife
|
||||
$actualKnife = $knifes[0];
|
||||
if ($selectedKnife != null) {
|
||||
foreach ($knifes as $knife) {
|
||||
if ($selectedKnife == $knife['weapon_name']) {
|
||||
$actualKnife = $knife;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Display user's selected knife information
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
||||
echo "<h5 class='card-title item-name'>{$actualKnife["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$actualKnife["image_url"]}' class='skin-image'>";
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<!-- Form for selecting user's knife -->
|
||||
<form action="" method="POST">
|
||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||
<option disabled>Select knife</option>
|
||||
<?php
|
||||
// Display options for selecting different knives
|
||||
foreach ($knifes as $knifeKey => $knife) {
|
||||
if ($selectedKnife == $knife['weapon_name'])
|
||||
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
else
|
||||
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
154
website/view/display_weapons.php
Normal file
154
website/view/display_weapons.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
// Display user's selected skins for different weapons
|
||||
foreach ($weapons as $defindex => $default) {
|
||||
?>
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3">
|
||||
<div class="card-body">
|
||||
<?php
|
||||
// Determine the skin to display for the current weapon
|
||||
if (array_key_exists($defindex, $selectedSkins)) {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]['image_url']}' class='skin-image'>";
|
||||
} else {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$default["image_url"]}' class='skin-image'>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<!-- Form for selecting user's skin and settings -->
|
||||
<form action="" method="POST">
|
||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||
<option disabled>Select skin</option>
|
||||
<?php
|
||||
// Display options for selecting different skins
|
||||
foreach ($skins[$defindex] as $paintKey => $paint) {
|
||||
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex]['weapon_paint_id'] == $paintKey)
|
||||
echo "<option selected value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||
else
|
||||
echo "<option value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br></br>
|
||||
<?php
|
||||
// Display settings button for selected skin
|
||||
$selectedSkinInfo = isset($selectedSkins[$defindex]) ? $selectedSkins[$defindex] : null;
|
||||
$steamid = $_SESSION['steamid'];
|
||||
|
||||
if ($selectedSkinInfo) :
|
||||
?>
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#weaponModal<?php echo $defindex ?>">
|
||||
Settings
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<!-- Display message if skin is not selected -->
|
||||
<button type="button" class="btn btn-primary" onclick="showSkinSelectionAlert()">
|
||||
Settings
|
||||
</button>
|
||||
<script>
|
||||
function showSkinSelectionAlert() {
|
||||
alert("You need to select a skin first.");
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Display modal for adjusting wear and seed values
|
||||
$selectedSkinInfo = isset($selectedSkins[$defindex]['weapon_paint_id']) ? $selectedSkins[$defindex] : null;
|
||||
$queryWear = $selectedSkins[$defindex]['weapon_wear'] ?? 1.0;
|
||||
$initialWearValue = isset($selectedSkinInfo['weapon_wear']) ? $selectedSkinInfo['weapon_wear'] : (isset($queryWear[0]['weapon_wear']) ? $queryWear[0] : 0.0);
|
||||
$querySeed = $selectedSkins[$defindex]['weapon_seed'] ?? 0;
|
||||
$initialSeedValue = isset($selectedSkinInfo['weapon_seed']) ? $selectedSkinInfo['weapon_seed'] : 0;
|
||||
?>
|
||||
|
||||
<!-- Modal for adjusting wear and seed values -->
|
||||
<div class="modal fade" id="weaponModal<?php echo $defindex ?>" tabindex="-1" role="dialog" aria-labelledby="weaponModalLabel<?php echo $defindex ?>" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<!-- Modal header -->
|
||||
<div class="modal-header">
|
||||
<h5 class='card-title item-name'>
|
||||
<?php
|
||||
if (array_key_exists($defindex, $selectedSkins)) {
|
||||
echo "{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]} Settings";
|
||||
} else {
|
||||
echo "{$default["paint_name"]} Settings";
|
||||
}
|
||||
?>
|
||||
</h5>
|
||||
</div>
|
||||
<!-- Modal body -->
|
||||
<div class="modal-body">
|
||||
<!-- Form for adjusting wear and seed values -->
|
||||
<div class="form-group">
|
||||
<select class="form-select" id="wearSelect<?php echo $defindex ?>" name="wearSelect" onchange="updateWearValue<?php echo $defindex ?>(this.value)">
|
||||
<option disabled>Select Wear</option>
|
||||
<option value="0.00" <?php echo ($initialWearValue == 0.00) ? 'selected' : ''; ?>>Factory New</option>
|
||||
<option value="0.07" <?php echo ($initialWearValue == 0.07) ? 'selected' : ''; ?>>Minimal Wear</option>
|
||||
<option value="0.15" <?php echo ($initialWearValue == 0.15) ? 'selected' : ''; ?>>Field-Tested</option>
|
||||
<option value="0.38" <?php echo ($initialWearValue == 0.38) ? 'selected' : ''; ?>>Well-Worn</option>
|
||||
<option value="0.45" <?php echo ($initialWearValue == 0.45) ? 'selected' : ''; ?>>Battle-Scarred</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="wear">Wear:</label>
|
||||
<input type="text" value="<?php echo $initialWearValue; ?>" class="form-control" id="wear<?php echo $defindex ?>" name="wear">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="seed">Seed:</label>
|
||||
<input type="text" value="<?php echo $initialSeedValue; ?>" class="form-control" id="seed<?php echo $defindex ?>" name="seed" oninput="validateSeed(this)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Modal footer -->
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-danger">Use</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- JavaScript functions for updating wear and seed values -->
|
||||
<script>
|
||||
// wear
|
||||
function updateWearValue<?php echo $defindex ?>(selectedValue) {
|
||||
var wearInputElement = document.getElementById("wear<?php echo $defindex ?>");
|
||||
wearInputElement.value = selectedValue;
|
||||
}
|
||||
|
||||
function validateWear(inputElement) {
|
||||
inputElement.value = inputElement.value.replace(/[^0-9]/g, '');
|
||||
}
|
||||
// seed
|
||||
function validateSeed(input) {
|
||||
// Check entered value
|
||||
var inputValue = input.value.replace(/[^0-9]/g, ''); // Just get the numbers
|
||||
|
||||
if (inputValue === "") {
|
||||
input.value = 0; // Set to 0 if empty or no numbers
|
||||
} else {
|
||||
var numericValue = parseInt(inputValue);
|
||||
numericValue = Math.min(1000, Math.max(1, numericValue)); // Interval control
|
||||
|
||||
input.value = numericValue;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user