Show sourcecode
The following files exists in this folder. Click to view.
bacon-egg-pizza.php
cquiz.php
create-account.php
create-account111.php
create-quiz.php
create-quiz2.php
createaccount.php
delete-quiz.php
drop-rps-tables.php
legacy-code-rps.php
legacy-index.php
login.php
logincheck.php
newpassword-verify.php
newpassword.php
potential-code.txt
quiz-db-init.php
quizhub.php
quizhub2.php
results.php
rpsaccount-ajax-user-search.php
rpsaccount.php
rpsbetting-ajax-match-finder.php
rpsbetting.php
rpsbettingleaderboard.php
rpschangepassword.php
rpschangepassword.txt
rpsgame-ajax.php
rpsgame.php
rpsgameresults.php
rpshostnewgame.php
rpshub.php
rpsleaderboard.php
rpslib.php
rpslogin.php
rpsmaininclude.php
rpsproject/
rpsusersearch.php
table-init.php
verification.php
legacy-code-rps.php
231 lines UTF-8 Windows (CRLF)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
function sendMove($dbconn, $matchkey, $move){
$userkey=$_SESSION['userid'];
//get current round number
$sql= "SELECT round FROM moves WHERE EXISTS (SELECT round FROM moves WHERE matchkey='$matchkey' ORDER BY round DESC)";
$stmt = $dbconn -> prepare($sql);
$stmt -> execute();
$currentround=1;
while($res = $stmt->fetch(PDO::FETCH_ASSOC)){
$currentround = $res['round'];
GLOBAL $currentround;
echo "round number acquired".$currentround;
break;
}
//check if both users have made moves
$sql= "SELECT * FROM moves WHERE matchkey='$matchkey' AND round = '$currentround'";
$stmt = $dbconn -> prepare($sql);
$stmt -> execute();
$useridArrayCurrentRound = [];
while($res = $stmt->fetch(PDO::FETCH_ASSOC)){
array_push($useridArrayCurrentRound, $res['userid']);
if($useridArrayCurrentRound==2){
$currentround+=1;
}
}
//check if user has made a move this round
//$sql= "SELECT EXISTS (SELECT * FROM moves WHERE matchkey='$matchkey' AND round='$currentround' AND userid='$userkey')";
$sql ="SELECT COUNT(*) AS total FROM moves WHERE matchkey='$matchkey' AND round='$currentround' AND userid='$userkey'";
$stmt = $dbconn -> prepare($sql);
$stmt -> execute();
while($res = $stmt->fetch(PDO::FETCH_ASSOC)){;
if($res['total']==0 /*count($currentRoundMoveArray)==2||count($currentRoundMoveArray)==0*/){
/*if(count($currentRoundMoveArray)==2){
$currentround+=1;
}*/
$sql = "INSERT INTO moves (matchkey, userid, round, rps) VALUES (?,?,?,?)";
$stmt = $dbconn -> prepare($sql);
$data=[$matchkey, $_SESSION['userid'], $currentround, $move];
$stmt -> execute($data);
}
else{
echo "move already made";
}
}
}
function getMatchesBettingVersion($dbconn){
$sql="SELECT * FROM matches /*LEFT JOIN rpsusers ON matches*/";
$stmt=$dbconn->prepare($sql);
$stmt->execute();
while($res=$stmt->fetch(PDO::FETCH_ASSOC)){
if($res['player2id']!=null AND $res['player1id']!=null AND $res['isactive']==1){
$player1id=$res['player1id'];
$player2id=$res['player2id'];
$matchid=$res['matchid'];
/*
$sql="SELECT * FROM rpsusers WHERE userid=? OR userid=?";
$stmt=$dbconn->prepare($sql);
$stmt->execute([$player1,$player2]);
$x=0;
while($res=$stmt->fetch(PDO::FETCH_ASSOC)){
echo $res['username'];
if($x==0){
echo " vs ";
$x++;
}
}
*/
$u1n = null;
$u2n = null;
$sql="SELECT * FROM rpsusers";
$stmt=$dbconn->prepare($sql);
$stmt->execute();
while($res=$stmt->fetch(PDO::FETCH_ASSOC)){
if($player1id==$res['userid']){
$u1n=$res['username'];
echo $u1n." vs ";
}
else if($player2id==$res['userid']){
$u2n=$res['username'];
echo $u2n;
}
}
echo '<html><form action="" method="POST">
<button type radio name="chosenplayer" value="'.$player1id.'>'.$u1n.'</button>
<button type radio name="chosenplayer" value="'.$player2id.'>'.$u2n.'</button>
<input type="text" name="betamount">test</input>
<input type="submit">';
}
}
}
function getMatchResult($dbconn,$matchkey){
//get roundamount
$roundamount=null;
$sql ="SELECT * FROM matches WHERE matchid=?";
$stmt = $dbconn -> prepare($sql);
$stmt->execute([$matchkey]);
while($res=$stmt->fetch(PDO::FETCH_ASSOC)){
$roundamount=$res['roundAmount'];
}
$sql="UPDATE matches SET isactive=0 WHERE matchid=?";
$stmt = $dbconn -> prepare($sql);
if(isset($_GET['matchkey'])){
$stmt -> execute([$_GET['matchkey']]);
}
else{
$stmt -> execute([$matchkey]);
}
$sql = "SELECT count(*) AS total FROM moves WHERE matchkey=?";
$stmt=$dbconn->prepare($sql);
$stmt->execute([$_GET['matchkey']]);
//create associative array
$matchResultsArray = [];
$yourmoves=[];
$yourscore=[];
$opponentmoves=[];
$opponentscore=[];
if($res= $stmt->fetch(PDO::FETCH_ASSOC)){
if($res['total']==$roundamount*2){
$sql = "SELECT * FROM moves WHERE matchkey=?";
$stmt=$dbconn->prepare($sql);
$stmt->execute([$matchkey]);
while($res=$stmt->fetch(PDO::FETCH_ASSOC)){
/*
$matchResultsArray[]=$res['round'];
$matchResultsArray[$res['round']][]=$res['userid'];
$matchResultsArray[$res['round']][$res['userid']][] = $res['rps'];
*/
//add moves to array
if($res['userid']==$_SESSION['userid']){
array_push($yourmoves,$res['rps']);
}
else if($res['userid']!=$_SESSION['userid']){
array_push($opponentmoves,$res['rps']);
}
}
//calculate scores
$x=0;
while($x<$roundamount){
if($yourmoves[$x]=="rock"){
if($opponentmoves[$x]=="rock"){
//does nothing
}
else if($opponentmoves[$x]=="paper"){
array_push($opponentscore,1);
}
else if($opponentmoves[$x]=="scissors"){
array_push($yourscore,1);
}
}
else if($yourmoves[$x]=="paper"){
if($opponentmoves[$x]=="rock"){
array_push($yourscore,1);
}
else if($opponentmoves[$x]=="paper"){
//does nothing
}
else if($opponentmoves[$x]=="scissors"){
array_push($opponentscore,1);
}
}
else if($yourmoves[$x]=="scissors"){
if($opponentmoves[$x]=="rock"){
array_push($opponentscore,1);
}
else if($opponentmoves[$x]=="paper"){
array_push($yourscore,1);
}
else if($opponentmoves[$x]=="scissors"){
//does nothing
}
}
$x++;
}
$yscore=count($yourscore);
$oscore=count($opponentscore);
//show scores
echo "<br>dina poäng: ".$yscore."<br>";
echo "motståndarens poäng: ".$oscore."<br>";
if($yscore>=$oscore){
echo "du vann";
$sql = "UPDATE matches SET p1points=? WHERE matchid=?";
$stmt=$dbconn->prepare($sql);
$stmt->execute([$yscore,$matchkey]);
}
else if($yscore==$oscore){
echo "oavgjort";
}
else if($yscore<=$oscore){
echo "motståndaren vann";
$sql = "UPDATE matches SET p1points=? WHERE matchid=?";
$stmt=$dbconn->prepare($sql);
$stmt->execute([$oscore,$matchkey]);
}
}
else{
echo "wait";
//sleep(1);
getMatchResult($dbconn,$matchkey);
}
}
}
?>