repairSkills.php

main 71 lines · 1.9 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1<?php require_once 'engine/init.php';
2
3/* PLAYER SKILLS REPAIR SCRIPT IF YOU SOMEHOW DELETE PLAYER SKILLS
4 ---------------------------------------------------------------
5 Place in root web directory, login to admin account,
6 and enter site.com/repairSkills.php (with big S).
7*/
8
9protect_page();
10admin_only($user_data);
11znote_csrf_protect_public_post();
12
13if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
14 ?>
15 <h1>Repair missing player skills</h1>
16 <p>This operation scans every player and inserts default rows where skills are missing.</p>
17 <form method="post" onsubmit="return confirm('Repair missing skills for every affected player?');">
18 <button type="submit">Run repair</button>
19 </form>
20 <?php
21 exit;
22}
23
24$Splayers = 0;
25$Salready = 0;
26$Sfixed = 0;
27
28$players = db()->fetchAll("SELECT `id` FROM `players`;");
29if ($players !== false) {
30 $Splayers = count($players);
31 foreach ($players as $char) {
32
33 // Check if player have skills
34 $skills = db()->fetchOne("SELECT `value` FROM `player_skills` WHERE `player_id` = ? AND `skillid` = 2 LIMIT 1;", [$char['id']]);
35
36 // If he dont have any skills
37 if ($skills === false) {
38 $Sfixed++;
39
40 // Loop through every skill id and give him default skills.
41 $rows = array();
42 $params = array();
43 for ($i = 0; $i < 7; $i++) {
44 $rows[] = '(?, ?, 10, 0)';
45 $params[] = $char['id'];
46 $params[] = $i;
47 }
48
49 db()->execute(
50 "INSERT INTO `player_skills` (`player_id`, `skillid`, `value`, `count`) VALUES " . implode(', ', $rows) . ";",
51 $params
52 );
53 } else $Salready++;
54 }
55 acp_log('maintenance.repair_skills', 'ALL', ['players' => $Splayers, 'repaired' => $Sfixed]);
56 ?>
57 <h1>Script run status:</h1>
58 <p>Players detected: <?php echo $Splayers; ?></p>
59 <p>Players already fixed: <?php echo $Salready; ?></p>
60 <p><b>Repaired player accounts: <?php echo $Sfixed; ?></b></p>
61 <?php
62} else {
63 ?>
64 <h1>No players detected.</h1>
65 <p>Something went wrong.</p>
66 <?php
67}
68?>
69
70<h1>Script run completed.</h1>
71
Top