diff --git a/website/class/header.php b/website/class/header.php index 8acb64ca..e3cb6ccf 100644 --- a/website/class/header.php +++ b/website/class/header.php @@ -1,10 +1,14 @@ select("SELECT `weapon`, `paint`, `wear`, `seed`, `nametag` FROM `wp_users_items` WHERE `user_id` = :user_id", ["user_id" => $userDbIndex]); $selectedSkins = UtilsClass::getSelectedSkins($querySelected); $selectedKnifeResult = $db->select("SELECT `knife` FROM `wp_users_knife` WHERE `user_id` = :user_id", ["user_id" => $userDbIndex]); + $selectedGlovesResult = $db->select("SELECT `weapon_defindex` FROM `wp_users_gloves` WHERE `user_id` = :user_id", ["user_id" => $userDbIndex]); + $selectedGloves = !empty($selectedGlovesResult) ? $selectedGlovesResult[0] : $gloves[0][0]; // Determine user's selected knife or set default knife if (!empty($selectedKnifeResult)) { diff --git a/website/class/utils.php b/website/class/utils.php index d97f2ea6..da0a673d 100644 --- a/website/class/utils.php +++ b/website/class/utils.php @@ -33,7 +33,53 @@ class UtilsClass return $skins; } + /** + * Retrieve music data from the JSON file. + * + * @return array An associative array containing music data. + */ + public static function musicFromJson() + { + $music = array(); + $jsonFilePath = __DIR__ . "/../data/music.json"; + if (file_exists($jsonFilePath) && is_readable($jsonFilePath)) { + $json = json_decode(file_get_contents($jsonFilePath), true); + + foreach ($json as $track) { + $music[$track['id']] = array( + 'name' => $track['name'], + 'image' => $track['image'], + ); + } + } else { + // Handle file not found or unreadable error + // You can throw an exception or log an error message + } + + return $music; + } + public static function glovesFromJson() + { + $gloves = array(); + $jsonFilePath = __DIR__ . "/../data/gloves.json"; + + if (file_exists($jsonFilePath) && is_readable($jsonFilePath)) { + $json = json_decode(file_get_contents($jsonFilePath), true); + + foreach ($json as $glove) { + $gloves[$glove['weapon_defindex']][$glove['paint']] = array( + 'paint_name' => $glove['paint_name'], + 'image_url' => $glove['image'], + ); + } + } else { + // Handle file not found or unreadable error + // You can throw an exception or log an error message + } + + return $gloves; + } /** * Retrieve weapons data from the skin data array. * diff --git a/website/db-sqlite.sql b/website/db-sqlite.sql new file mode 100644 index 00000000..cd4e41d4 --- /dev/null +++ b/website/db-sqlite.sql @@ -0,0 +1,54 @@ +PRAGMA foreign_keys = ON; + +CREATE TABLE IF NOT EXISTS `wp_players` ( + `user_id` INTEGER PRIMARY KEY AUTOINCREMENT, + `steamid` INTEGER NOT NULL, + `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + UNIQUE(`steamid`) + ); + +CREATE TABLE IF NOT EXISTS `wp_player_skins` ( + `user_id` INTEGER NOT NULL, + `team` INTEGER NOT NULL, + `weapon_defindex` INTEGER NOT NULL, + `paint` INTEGER NOT NULL, + `wear` REAL NOT NULL DEFAULT 0.001, + `seed` INTEGER NOT NULL DEFAULT 0, + `nametag` TEXT DEFAULT NULL, + `stattrack` INTEGER NOT NULL DEFAULT 0, + `stattrack_enabled` INTEGER NOT NULL DEFAULT 0, + `quality` INTEGER NOT NULL DEFAULT 0, + PRIMARY KEY (`user_id`,`team`,`weapon_defindex`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE + ); + +CREATE TABLE IF NOT EXISTS `wp_players_knife` ( + `user_id` INTEGER NOT NULL, + `knife` TEXT DEFAULT NULL, + PRIMARY KEY (`user_id`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE + ); + +CREATE TABLE IF NOT EXISTS `wp_players_gloves` ( + `user_id` INTEGER NOT NULL, + `weapon_defindex` INTEGER DEFAULT NULL, + `team` INTEGER DEFAULT NULL, + PRIMARY KEY (`user_id`,`team`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE + ); + +CREATE TABLE IF NOT EXISTS `wp_players_music` ( + `user_id` INTEGER NOT NULL, + `music` INTEGER DEFAULT NULL, + PRIMARY KEY (`user_id`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE + ); + +CREATE TABLE IF NOT EXISTS `wp_players_agents` ( + `user_id` INTEGER NOT NULL, + `agent_ct` TEXT DEFAULT NULL, + `agent_t` TEXT DEFAULT NULL, + PRIMARY KEY (`user_id`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE + ); \ No newline at end of file diff --git a/website/db.sql b/website/db.sql new file mode 100644 index 00000000..d390cd2a --- /dev/null +++ b/website/db.sql @@ -0,0 +1,53 @@ +CREATE TABLE IF NOT EXISTS `wp_players` ( + `user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `steamid` BIGINT UNSIGNED NOT NULL, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`user_id`), + UNIQUE KEY `unique_steamid` (`steamid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `wp_player_skins` ( + `user_id` INT UNSIGNED NOT NULL, + `team` SMALLINT UNSIGNED NOT NULL, + `weapon_defindex` SMALLINT UNSIGNED NOT NULL, + `paint` SMALLINT UNSIGNED NOT NULL, + `wear` FLOAT NOT NULL DEFAULT 0.001, + `seed` SMALLINT UNSIGNED NOT NULL DEFAULT 0, + `nametag` VARCHAR(20) DEFAULT NULL, + `stattrack` INT UNSIGNED NOT NULL DEFAULT 0, + `stattrack_enabled` SMALLINT NOT NULL DEFAULT 0, + `quality` SMALLINT UNSIGNED NOT NULL DEFAULT 0, + PRIMARY KEY (`user_id`,`team`,`weapon_defindex`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `wp_players_knife` ( + `user_id` INT UNSIGNED NOT NULL, + `knife` VARCHAR(32) DEFAULT NULL, + PRIMARY KEY (`user_id`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `wp_players_gloves` ( + `user_id` INT UNSIGNED NOT NULL, + `weapon_defindex` SMALLINT UNSIGNED DEFAULT NULL, + `team` SMALLINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (`user_id`,`team`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `wp_players_music` ( + `user_id` INT UNSIGNED NOT NULL, + `music` SMALLINT UNSIGNED DEFAULT NULL, + PRIMARY KEY (`user_id`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `wp_players_agents` ( + `user_id` INT UNSIGNED NOT NULL, + `agent_ct` varchar(64) DEFAULT NULL, + `agent_t` varchar(64) DEFAULT NULL, + PRIMARY KEY (`user_id`), + FOREIGN KEY (`user_id`) REFERENCES `wp_players`(`user_id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/website/index.php b/website/index.php index 89e8e262..1931f192 100644 --- a/website/index.php +++ b/website/index.php @@ -20,8 +20,11 @@ require 'class/header.php';