-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_flags.php
136 lines (123 loc) · 2.6 KB
/
process_flags.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
session_start();
require "helper.php";
$u = $_SESSION["id"];
$db = database();
$points = $db->query("SELECT points FROM users WHERE id = $u");
$points = $points->fetch();
$points = (int)$points[0];
function flagWin($db, $u, $points, $flag){
$f = $flag;
$q1 = $db->query("SELECT timesSolved FROM challenges WHERE id = $flag");
$q1 = $q1->fetch();
$q1 = (int)$q1[0];
if($flag <= 3){
$points += 50;
$dbCheck = "easy".$f;
}
else if($flag <= 6 && $flag >= 4){
$points += 125;
$dbCheck = "medium".(string)($f-3);
}
else if($flag >= 7){
$points += 300;
$dbCheck = "hard".(string)($f-6);
}
$available = $db->query("SELECT $dbCheck FROM users WHERE id = $u");
$available = $available->fetch();
$available = (int)$available[0];
if($available === 0){
$q1++;
$add = $db->prepare("UPDATE challenges SET timesSolved = '$q1' WHERE id = $flag");
$add->execute();
$p = $db->prepare("UPDATE users SET points = '$points' WHERE id = $u");
$p->execute();
$c = $db->prepare("UPDATE users SET $dbCheck = 1 WHERE id = $u");
$c->execute();
//header("location:index.php");
}
else{
header("location:index.php");
}
}
function flagLose($db, $u, $points){
$points -= 5;
$subtract = $db->prepare("UPDATE users SET points = '$points' WHERE id = $u");
$subtract->execute();
}
//easy
if (isset($_POST["easy"])){
if($_POST["easy"] === ""){
flagWin($db, $u, $points, 1);
}
else{
flagLose($db, $u, $points);
}
}
else if(isset($_POST["easy2"])){
if($_POST["easy2"] === ""){
flagWin($db, $u, $points, 2);
}
else{
flagLose($db, $u, $points);
}
}
else if(isset($_POST["easy3"])){
if($_POST["easy3"] === ""){
flagWin($db, $u, $points, 3);
}
else{
flagLose($db, $u, $points);
}
}
//medium
else if (isset($_POST["medium"])){
if($_POST["medium"] === ""){
flagWin($db, $u, $points, 4);
}
else{
flagLose($db, $u, $points);
}
}
else if (isset($_POST["medium2"])){
if($_POST["medium2"] === ""){
flagWin($db, $u, $points, 5);
}
else{
flagLose($db, $u, $points);
}
}
else if (isset($_POST["medium3"])){
if($_POST["medium3"] === ""){
flagWin($db, $u, $points, 6);
}
else{
flagLose($db, $u, $points);
}
}
//hard
else if (isset($_POST["hard"])){
if($_POST["hard"] === ""){
flagWin($db, $u, $points, 7);
}
else{
flagLose($db, $u, $points);
}
}
else if (isset($_POST["hard2"])){
if($_POST["hard2"] === ""){
flagWin($db, $u, $points, 8);
}
else{
flagLose($db, $u, $points);
}
}
else if (isset($_POST["hard3"])){
if($_POST["hard3"] === ""){
flagWin($db, $u, $points, 9);
}
else{
flagLose($db, $u, $points);
}
}
header("location:index.php");