Add all WIP content

master
Nathan Steel 3 years ago
parent 914c5c977a
commit 2d951f0546

1
.gitignore vendored

@ -0,0 +1 @@
node_modules

25
TODO

@ -0,0 +1,25 @@
change cookie for userLogged to be much more secure
Move code into classes/functions, and modularise it
Build the entities that we need, and call them in the code
add functionality to
make team
add player
join tournament (request to join)
when tourney has enough applicats, then arrange the matches for first seeds
make tourney
show match page
have elo changes seperate
have matchmaking seperate
front-controller
https://symfony.com/doc/current/introduction/from_flat_php_to_symfony.html#a-front-controller-to-the-rescue
Seperate logic from any front end (logic needs to be able to run via command line)
it can return what is needed for the front end only

@ -0,0 +1,23 @@
.alert{
width: 100%;
padding: 12px;
border-radius: 6px;
}
.alert--notification{
@extend .alert;
background-color: $notification;
}
.alert--success{
@extend .alert;
background-color: $success;
}
.alert--error{
@extend .alert;
background-color: $error;
color: $white;
}
.alert--alert{
@extend .alert;
background-color: $alert;
}

@ -0,0 +1,12 @@
$gunmetal: #2A2D34;
$ghost-white: #F8F8FF;
$steel-blue: #3E7CB1;
$white: #FFF;
$black: #000;
$offyellow: #FEFAE0;
$success: #35CE8D;
$error: #AD2831;
$notification: #06BEE1;
$alert: lightgoldenrodyellow;

@ -0,0 +1,13 @@
footer{
background-color: $gunmetal;
color: $white;
}
.footer__link{
text-decoration: none;
color: $ghost-white;
&:hover{
color: $notification;
}
}

@ -0,0 +1,80 @@
@mixin input {
appearance: none;
padding: 12px;
font-size: 16px;
margin-bottom: 12px;
background: $white;
border: 2px solid $black;
box-sizing: border-box;
color: $black;
display: block;
line-height: 1;
outline: 2px solid transparent;
vertical-align: top;
transition-property: background-color, border-color, color, opacity, box-shadow;
transition-duration: .1s;
transition-timing-function: ease-out;
&:focus {
border-color: $notification;
box-shadow: $notification;
outline: 0 none;
outline-offset: 0;
}
&:invalid {
outline: 0 none;
}
}
select, textarea{
@include input;
}
textarea{
// Allow only vertical resizing of textareas.
resize: vertical;
}
input {
&[type='text'],
&[type='number'],
&[type='email'],
&[type='password'] {
@include input;
}
}
.button,
button,
[type="button"],
[type="reset"],
[type="submit"]{
-webkit-appearance: button;
cursor: pointer;
padding: 10px 26px;
margin: 0.6rem 0;
border: 2px solid $gunmetal;
background-color: $gunmetal;
color: $white;
text-decoration: none;
display: inline-block;
border-radius: 4px;
font-weight: bold;
font-size: 16px;
&:hover{
background-color: lighten($gunmetal, 10%);
border-color: lighten($gunmetal, 10%);
color: $white;
}
// Remove margin from paragraph wrapped anchors
p &{
margin: 0;
}
}

@ -0,0 +1,62 @@
header{
width: 100%;
background-color: $gunmetal;
padding: 16px;
}
header .layout-wrapper{
position: relative;
}
header .layout-wrapper *{
display: inline-block;
vertical-align: middle;
}
nav{
//position: absolute;
right: 0;
vertial-align: middle;
display: inline-block;
}
nav ul{
list-style: none;
margin: 0;
padding: 0;
}
nav ul li{
display: inline;
color: $ghost-white;
padding: 4px 8px;
}
nav ul li a{
text-decoration: none;
color: $ghost-white;
padding: 4px 8px;
&:hover{
color: $white;
}
}
nav ul li ul{
border-top: 16px solid transparent;
z-index: $zi-high;
}
// Prevent webkit fucking shit up
nav ul > li:before {
content: "\200B";
position: absolute;
}
.site-title{
color: $ghost-white;
padding: 6px;
text-decoration: none;
font-weight: bold;
font-size: 16px;
vertial-align: middle;
display: inline-block;
}
.logo{
fill: $ghost-white;
width: 32px;
height: 32px;
}

@ -0,0 +1,246 @@
@charset "UTF-8";
select, textarea {
appearance: none;
padding: 12px;
font-size: 16px;
margin-bottom: 12px;
background: #FFF;
border: 2px solid #000;
box-sizing: border-box;
color: #000;
display: block;
line-height: 1;
outline: 2px solid transparent;
vertical-align: top;
transition-property: background-color, border-color, color, opacity, box-shadow;
transition-duration: 0.1s;
transition-timing-function: ease-out;
}
select:focus, textarea:focus {
border-color: #06BEE1;
box-shadow: #06BEE1;
outline: 0 none;
outline-offset: 0;
}
select:invalid, textarea:invalid {
outline: 0 none;
}
textarea {
resize: vertical;
}
input[type=text], input[type=number], input[type=email], input[type=password] {
appearance: none;
padding: 12px;
font-size: 16px;
margin-bottom: 12px;
background: #FFF;
border: 2px solid #000;
box-sizing: border-box;
color: #000;
display: block;
line-height: 1;
outline: 2px solid transparent;
vertical-align: top;
transition-property: background-color, border-color, color, opacity, box-shadow;
transition-duration: 0.1s;
transition-timing-function: ease-out;
}
input[type=text]:focus, input[type=number]:focus, input[type=email]:focus, input[type=password]:focus {
border-color: #06BEE1;
box-shadow: #06BEE1;
outline: 0 none;
outline-offset: 0;
}
input[type=text]:invalid, input[type=number]:invalid, input[type=email]:invalid, input[type=password]:invalid {
outline: 0 none;
}
.button,
button,
[type=button],
[type=reset],
[type=submit] {
-webkit-appearance: button;
cursor: pointer;
padding: 10px 26px;
margin: 0.6rem 0;
border: 2px solid #2A2D34;
background-color: #2A2D34;
color: #FFF;
text-decoration: none;
display: inline-block;
border-radius: 4px;
font-weight: bold;
font-size: 16px;
}
.button:hover,
button:hover,
[type=button]:hover,
[type=reset]:hover,
[type=submit]:hover {
background-color: #414550;
border-color: #414550;
color: #FFF;
}
p .button,
p button,
p [type=button],
p [type=reset],
p [type=submit] {
margin: 0;
}
header {
width: 100%;
background-color: #2A2D34;
padding: 16px;
}
header .layout-wrapper {
position: relative;
}
header .layout-wrapper * {
display: inline-block;
vertical-align: middle;
}
nav {
right: 0;
vertial-align: middle;
display: inline-block;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
display: inline;
color: #F8F8FF;
padding: 4px 8px;
}
nav ul li a {
text-decoration: none;
color: #F8F8FF;
padding: 4px 8px;
}
nav ul li a:hover {
color: #FFF;
}
nav ul li ul {
border-top: 16px solid transparent;
z-index: 30;
}
nav ul > li:before {
content: "";
position: absolute;
}
.site-title {
color: #F8F8FF;
padding: 6px;
text-decoration: none;
font-weight: bold;
font-size: 16px;
vertial-align: middle;
display: inline-block;
}
.logo {
fill: #F8F8FF;
width: 32px;
height: 32px;
}
footer {
background-color: #2A2D34;
color: #FFF;
}
.footer__link {
text-decoration: none;
color: #F8F8FF;
}
.footer__link:hover {
color: #06BEE1;
}
.alert, .alert--alert, .alert--error, .alert--success, .alert--notification {
width: 100%;
padding: 12px;
border-radius: 6px;
}
.alert--notification {
background-color: #06BEE1;
}
.alert--success {
background-color: #35CE8D;
}
.alert--error {
background-color: #AD2831;
color: #FFF;
}
.alert--alert {
background-color: lightgoldenrodyellow;
}
object * {
fill: #FFF;
}
*, *:before, *:after {
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html, body {
margin: 0;
height: 100%;
}
body {
display: flex;
flex-direction: column;
font-family: system-ui, sans-serif;
}
main {
flex: 1 0 auto;
}
.layout-wrapper {
width: 100%;
max-width: 1240px;
padding: 0 20px;
margin: 0 auto;
}
.banner {
margin: 0 auto;
width: 100%;
height: 200px;
background-color: #2A2D34;
color: #FFF;
margin-bottom: 12px;
}
/*# sourceMappingURL=main.css.map */

@ -0,0 +1 @@
{"version":3,"sourceRoot":"","sources":["form.scss","colours.scss","header.scss","variables.scss","footer.scss","alert.scss","main.scss"],"names":[],"mappings":";AAgCA;EA/BC;EAEA;EACA;EACA;EAEA,YCJO;EDKP;EACA;EACA,OCNO;EDOP;EACA;EACA;EACA;EAEA;EACA;EACA;;AAEA;EACC,cCZa;EDab,YCba;EDcb;EACA;;AAGD;EACC;;;AAOF;EAEI;;;AAIH;EAxCA;EAEA;EACA;EACA;EAEA,YCJO;EDKP;EACA;EACA,OCNO;EDOP;EACA;EACA;EACA;EAEA;EACA;EACA;;AAEA;EACC,cCZa;EDab,YCba;EDcb;EACA;;AAGD;EACC;;;AAqBF;AAAA;AAAA;AAAA;AAAA;EAKC;EACA;EAEA;EACG;EACA;EACA,kBC5DO;ED6DP,OC1DI;ED2DJ;EACA;EACA;EACA;EACA;;AAEA;AAAA;AAAA;AAAA;AAAA;EACI;EACA;EACA,OCpEA;;ADwEP;AAAA;AAAA;AAAA;AAAA;EACC;;;AE5EF;EACC;EACA,kBDFU;ECGV;;;AAED;EACC;;;AAED;EACC;EACA;;;AAGD;EAEC;EACA;EACA;;;AAED;EACC;EACA;EACA;;;AAED;EACC;EACA,ODzBa;EC0Bb;;;AAED;EACC;EACA,OD9Ba;EC+Bb;;AAEA;EACC,ODhCM;;;ACmCR;EACC;EACA,SCxCS;;;AD2CV;EACC;EACA;;;AAED;EACC,OD/Ca;ECgDb;EACA;EACA;EACA;EACA;EACA;;;AAED;EACC,MDxDa;ECyDb;EACA;;;AE3DD;EACC,kBHDU;EGEV,OHCO;;;AGCR;EACC;EACA,OHLa;;AGOb;EACC;;;ACTF;EACC;EACA;EACA;;;AAED;EAEC,kBJEc;;;AIAf;EAEC,kBJJS;;;AIMV;EAEC,kBJPO;EIQP,OJbO;;;AIeR;EAEC,kBJVO;;;AKHR;EACC,MLLO;;;AKOR;EACC;EACA;EACA;;;AAED;EACC;EACA;EACA;;;AAED;EACC;EACA;;;AAED;EACC;EACA;EACA;;;AAED;EACC;;;AAGD;EACC;EACA;EACA;EACA;;;AAED;EACC;EACA;EACA;EACA,kBL3CU;EK4CV,OLzCO;EK0CP","file":"main.css"}

@ -0,0 +1,48 @@
@import 'colours';
@import 'variables';
@import 'form';
@import 'header';
@import 'footer';
@import 'alert';
object *{
fill: $white;
}
*, *:before, *:after{
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
html{
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html, body{
margin: 0;
height: 100%;
}
body{
display: flex;
flex-direction: column;
font-family: system-ui, sans-serif;
}
main{
flex: 1 0 auto;
}
.layout-wrapper{
width: 100%;
max-width: 1240px;
padding: 0 20px;
margin: 0 auto;
}
.banner{
margin: 0 auto;
width: 100%;
height: 200px;
background-color: $gunmetal;
color: $white;
margin-bottom: 12px;
}

@ -0,0 +1,6 @@
$zi-high: 30;
$zi-med: 20;
$zi-low: 10;
$zi-ground: 0;
$zi-below: -1;

@ -0,0 +1,59 @@
<?php
require_once 'repository/teamRepository.php';
// MMR will work better with better matchmaking
// worse MM, will then require additional checks, etc
// The more convoluted the worse prolly.
// matchmake by rating, and kfactor (primarily rating)
// Teams made of 5 members
// Each team member has an MMR, and Kfactor
// kfactor = 100 for first 5 games? then drops 10 for next 5, then drops 1 for next 10. stable at 40 from 20-50
// Get tha teams
$dbTeams = getMatchTeams($conn, 1);
$teams = [];
foreach($dbTeams as $dbTeam){
$team = [
'name' => $dbTeam['name'],
'players' => [],
'playerRating' => 0,
'expected' => NULL,
'score' => NULL,
];
$teamPlayers = 0;
$players = getTeamPlayers($conn, $dbTeam['id']);
foreach($players as $player){
$team['players'][] = [
'ign' => $player['ign'],
'rating' => $player['rating'],
'kfactor' => 40,
];
$team['playerRating'] += $player['rating'];
$teamPlayers++;
}
$team['playerRating'] = $team['playerRating']/$teamPlayers;
$teams[] = $team;
}
//die("Db stuff only");
// Expected result of the match
// 1/(1+10^((OpponentRating - Your rating)/400))
// this is for bo1
// TODO:
$teams[0]['expected'] = 1 / ( 1 + ( pow( 10 , ( $teams[1]['playerRating'] - $teams[0]['playerRating'] ) / 400 ) ) );
$teams[1]['expected'] = 1 / ( 1 + ( pow( 10 , ( $teams[0]['playerRating'] - $teams[1]['playerRating'] ) / 400 ) ) );
$teams[0]['score'] = 1;
$teams[1]['score'] = 0;
$t = 1;
$i = 1;
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 611.998 611.998" xmlns:v="https://vecta.io/nano"><path d="M473.464 291.435c-1.868-14.686-4.712-29.002-8.488-42.812 34.441 14.354 66.161 34.293 94.581 59.559 2.992 2.66 6.721 3.969 10.432 3.969 4.335 0 8.647-1.78 11.75-5.273a15.72 15.72 0 0 0-1.304-22.186c-37.986-33.768-81.373-58.852-129.043-74.678-6.564-15-14.334-29.089-23.313-41.946-3.722-5.329-7.599-10.367-11.606-15.135 61.79-18.314 118.097-51.803 164.139-97.845a15.72 15.72 0 0 0 0-22.222c-6.138-6.135-16.087-6.135-22.224 0-46.55 46.552-104.52 79.089-168.027 94.507l-.775-.604c-1.511-16.197-7.686-31.529-17.818-44.289V47.187C371.769 21.169 350.6 0 324.581 0h-9.608c-3.17 0-6.191.622-8.98 1.715C303.206.622 300.184 0 297.014 0h-9.608c-26.007 0-47.165 21.169-47.165 47.187v35.26c-10.147 12.762-16.332 28.108-17.842 44.325l-.768.599c-63.503-15.418-121.473-47.955-168.023-94.507a15.72 15.72 0 0 0-22.222 0 15.72 15.72 0 0 0-.002 22.223c46.04 46.043 102.351 79.532 164.144 97.845-4.007 4.768-7.884 9.806-11.604 15.133-8.977 12.854-16.747 26.943-23.311 41.943-47.657 15.813-91.046 40.9-129.049 74.681-6.488 5.765-7.071 15.698-1.304 22.184 3.105 3.493 7.417 5.275 11.75 5.275 3.711 0 7.44-1.309 10.432-3.969 28.434-25.275 60.156-45.216 94.59-59.566-3.776 13.811-6.622 28.128-8.488 42.814-49.372 40.657-87.488 93.773-110.379 154.08-3.078 8.113 1.001 17.187 9.116 20.267 1.836.698 3.72 1.028 5.574 1.028 6.337 0 12.311-3.863 14.695-10.142 17.304-45.596 44.112-86.693 78.358-120.577.07 8.551.48 16.801 1.203 24.775-11.162 91.499 19.764 181.279 85.02 246.538a15.66 15.66 0 0 0 11.112 4.602c4.021 0 8.043-1.535 11.11-4.602 6.138-6.135 6.138-16.087.002-22.222-35.215-35.216-59.242-78.416-70.584-125.119 3.83 4.651 7.929 9.047 12.336 13.142 29.19 27.132 69.531 40.888 119.895 40.888s90.704-13.757 119.895-40.888c4.402-4.092 8.499-8.483 12.329-13.13-11.343 46.698-35.37 89.896-70.581 125.107-6.135 6.138-6.135 16.087.002 22.222 3.066 3.069 7.089 4.602 11.11 4.602s8.043-1.535 11.112-4.602c65.25-65.252 96.18-155.02 85.023-246.517.725-7.978 1.136-16.233 1.206-24.788 34.243 33.882 61.047 74.979 78.358 120.573 2.384 6.277 8.355 10.142 14.693 10.142 1.854 0 3.74-.33 5.574-1.028a15.72 15.72 0 0 0 9.114-20.269c-22.894-60.305-61.008-113.421-110.373-154.074zM234.49 157.481c1.125-.761 3.803-3.28 4.171-3.583 19.953-16.477 42.92-25.879 67.342-25.879s47.392 9.404 67.346 25.883c.361.299 3.046 2.831 4.187 3.596 13.063 11.691 24.723 26.485 34.517 43.681-26.178 31.159-65.138 49.527-106.057 49.527s-79.868-18.363-106.048-49.515c9.799-17.212 21.467-32.014 34.542-43.71zM340.347 47.187v10.872a84.32 84.32 0 0 0-18.633-5.87V31.428h2.873c8.689 0 15.76 7.07 15.76 15.759zm-52.936-15.759h2.873v20.761c-6.42 1.232-12.668 3.199-18.61 5.864V47.187c.002-8.689 7.06-15.759 15.737-15.759zM267.48 98.914c10.064-10.845 23.744-16.819 38.52-16.819a52.69 52.69 0 0 1 38.533 16.832c1.468 1.585 2.786 3.271 4.036 5.002-13.714-4.842-27.985-7.339-42.568-7.339s-28.86 2.496-42.576 7.341c1.256-1.737 2.581-3.43 4.055-5.017zm137.021 351.264c-23.187 21.553-56.329 32.481-98.499 32.481s-75.311-10.928-98.499-32.481c-26.685-24.801-40.215-64.087-40.215-116.763 0-10.888.581-21.578 1.688-32.012l.007-.061c2.649-24.907 8.331-48.341 16.468-69.445 31.653 31.81 75.118 50.234 120.541 50.234s88.9-18.428 120.555-50.245c8.129 21.079 13.808 44.485 16.462 69.358l.027.242c1.102 10.407 1.679 21.068 1.679 31.927.001 52.678-13.531 91.963-40.214 116.765z"/></svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

@ -0,0 +1 @@
mite is from svgrepo.com

@ -0,0 +1,20 @@
<?php
$dbVars = [
'servername' => "localhost",
'username' => "admin",
'password' => "password",
'database' => "tournaments"
];
// Create connection
$conn = new mysqli($dbVars['servername'], $dbVars['username'], $dbVars['password'], $dbVars['database']);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";
?>

@ -0,0 +1,51 @@
<?php
$meta = [
'title' => 'Tournamite',
'description' => 'Index description',
'keywords' => 'tournamite, tournament, tourney'
];
require_once('partial/head.php');
?>
<?php
include('partial/header.php');
include('repository/tournamentRepository.php');
?>
<body>
<main class="layout-wrapper">
<section class="banner">
<div class="layout-wrapper">
Banner for internal adverts
</div>
</section>
<section class="live-tournaments">
<div class="live-tournaments__match"></div>
</section>
<section class="upcoming-tournaments">
<a href="tournaments.php">View all</a>
<?php
$tournaments = getTournaments($conn, 1);
if($tournaments){
?>
Current Tournaments
<?php
foreach($tournaments as $tournament){
?>
<a href="tournament.php"><?php echo($tournament['name']) ?></a>
<?php
}
}
?>
</section>
</main>
<?php
include('partial/footer.php');
?>
</body>
</html>

@ -0,0 +1,60 @@
<?php
require_once('scripts/userLogged.php');
userLogged();
?>
<?php
$meta = [
'title' => 'Login',
'description' => 'Login description',
'keywords' => ''
];
require_once('partial/head.php');
?>
<?php
require_once('partial/header.php');
?>
<?php
if (!empty($_POST) && isset($_POST['username']) && isset($_POST['password'])){
userLogin($username, $password);
}
?>
<body>
<main class="layout-wrapper">
<h1>Login</h1>
<?php if(isset($notification)){ ?>
<p class="alert--<?php echo($notification['type']) ?>">
<?php echo($notification['message']) ?>
</p>
<?php } ?>
<form action="login.php" method="post">
<label for="username">Username</label>
<input name="username" id="username" type="text"
<?php if (!empty($_POST) && isset($_POST['username']) && ($_POST['username'])){ ?>
value="<?php echo $_POST['username']; ?>" <?php } ?> placeholder="Username">
<label for="password">Password</label>
<input name="password" id="password" type="password" value="" placeholder="Password">
<input type="submit" value="Submit">
</form>
<h2>Don't have an account?</h2>
<p><a class="button" href="signup.php">Sign Up</a></p>
</main>
<?php
require_once('partial/footer.php');
?>
</body>
</html>

@ -0,0 +1,5 @@
<?php
include('scripts/userLogged.php');
logOut();
header("Location: /");
?>

@ -0,0 +1,43 @@
<html>
<head>
<?php include('partial/head.php'); ?>
</head>
<?php
include('partial/header.php');
?>
<h1>match x<h1>
<h2>tournament</h2>
<div class="teamBox">team1</div>
vs
<div class="teamBox">team2</div>
<!-- If there's only 1 round, don't show round x, just embed the round page? -->
<h3>Round x</h3>
<!-- if tournament admin (owner, who they set, and our staff), and not already checked -->
<div class="page--admin" style="background-color: #fefefe;">
<h4>Admin</h4>
<a href="" style="background: #cacaca; padding: 6px; border-radius: 4px;">Team1 won</a>
<a href="" style="background: #cacaca; padding: 6px; border-radius: 4px;">Team2 won</a>
<a href="" style="background: #cacaca; padding: 6px; border-radius: 4px;">Draw</a>
</div>
<table>
<tr><td>player1</td></tr>
<tr></tr>
<tr><td>player2</td></tr>
</table>
<h3>Round y</h3>
<table>
<tr><td>player1</td></tr>
<tr></tr>
<tr><td>player2</td></tr>
</table>
<h3>Round z</h3>
<div class="starts">starts 15 aug 2022 @15:00</div>
<?php
include('partial/footer.php');
?>
</html>

@ -0,0 +1,31 @@
<?php
// All players in queue
// algo to arrange by the closest elo
// put 5 on each team
// if a player missed a queue, they get prio+1
// the games search for games for the playesr with highest prio (using their mmr)
// then works up/downwards to try to find better games
//
//
// OPTIONS
// [x] Queue out of bracket.
// [x] Queue REALLY out of bracket
// If the queus are long, and you can't get into a match this will allow you to queue
// with people out of your bracket (so long as they also did out of bracket search)
//
// bracket example. 2400+ can only queu with those at 2250+ but if there are no games
// people at 2000+ can queue into their games
//
// people at 2000 can queue into people within 300 up/down, but if no games
// can double up to 600+, then anything
//
//
// Show average rating of people queued?
// show player count queud in each bracket|?
//
// event that runs every 10 seconds, and recalcs the average for queues
// this will then update the "averageQueue" db, and a simple select for each client is called
?>

@ -0,0 +1,31 @@
<?php
$kfactor = 40;
var_dump('Kfactor: '.$kfactor);
$ratingA = 1500;
$ratingB = 1500;
var_dump('RatingA: '.$ratingA);
var_dump('RatingB: '.$ratingB);
$expectedA = 1 / ( 1 + ( pow( 10 , ( $ratingB - $ratingA ) / 400 ) ) );
$expectedB = 1 / ( 1 + ( pow( 10 , ( $ratingA - $ratingB ) / 400 ) ) );
var_dump('expectedA: '.$expectedA);
var_dump('expectedB: '.$expectedB);
$scoreA = 1; // win
$scoreB = 0; // loss
var_dump('scoreA: '.$scoreA);
var_dump('scoreA: '.$scoreB);
// New ratings
$ratingA = $ratingA + ( $kfactor * ( $scoreA - $expectedA ) );
$ratingB = $ratingB + ( $kfactor * ( $scoreB - $expectedB ) );
var_dump('RatingA: '.$ratingA);
var_dump('RatingB: '.$ratingB);
?>

2973
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,8 @@
{
"devDependencies": {
"cssnano": "^5.1.7",
"cssnano-preset-advanced": "^5.3.3",
"postcss": "^8.4.13",
"postcss-cli": "^9.1.0"
}
}

@ -0,0 +1,8 @@
<footer>
<div class="layout-wrapper">
<p>Website by <a class="footer__link" href="https://aney.co.uk">Aney</a></p>
</div>
</footer>
<!--</body>-->
<!--</html>-->

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" href="/images/mite.svg">
<link rel="stylesheet" href="/css/main.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php if(isset($meta) && array_key_exists('title', $meta)){ echo($meta['title']);}else{ echo('Tournamite'); } ?></title>
<meta name="description" content="<?php if(isset($meta) && array_key_exists('description', $meta)){ echo($meta['description']);}else{ echo('Tournamite'); } ?>">
<meta name="keywords" content="<?php if(isset($meta) && array_key_exists('keywords', $meta)){ echo($meta['keywords']);}else{ echo('Tournamite'); } ?>">
<meta name="author" content="Nathan (Aney) Steel">
<!-- Umami tracking. Needs securing, i.e. umami.racknerd.aney.co.uk -->
<script async defer data-website-id="fda96130-4381-4fb7-b46b-6ce90d82c395" src="https://umami.aney.co.uk/umami.js"></script>
</head>

@ -0,0 +1,32 @@
<header>
<div class="layout-wrapper">
<a class="site-title" href="/">
<div class="logo"><?php echo file_get_contents("./images/mite.svg"); ?></div>
<div class="logo"><?php echo file_get_contents("./images/coastal-logo.svg"); ?></div>
Tournamite
</a>
<nav>
<ul>
<li>
<a href="./tournaments.php">tournaments</a>
<ul>
<li><a href="#">Registered</a></li>
<li><a href="#">Yours</a></li>
</ul>
</li>
<li>teams</li>
<?php if(!isset($_COOKIE['userLogged'])) { ?>
<li><a href="./login.php">login</a></li>
<li><a href="./signup.php">register</a></li>
<?php }else{ ?>
<li><a href="./profile.php">profile</a></li>
<li><a href="./logout.php">Log out</a></li>
<?php } ?>
</ul>
</nav>
</div>
</header>

@ -0,0 +1,8 @@
module.exports = {
plugins: [
require('cssnano')({
preset: 'advanced',
}),
],
};

@ -0,0 +1,39 @@
<?php
$meta = [
'title' => 'Profile',
'description' => 'Profile page',
'keywords' => ''
];
require_once('partial/head.php');
?>
<?php
require_once('partial/header.php');
?>
<body>
<main class="layout-wrapper">
<h1>Welcome, <?php echo($_COOKIE['userLogged']) ?></h1>
<h2>Your Tournaments</h2>
<h2>Tournaments</h2>
<h3>x</h3>
<div>your team</div> vs <div>othre team</div>
<h2>Previous Tournaments</h2>
<h3>y</h3>
<div>3rd place</div>
<h2>Game Accounts</h2>
<h2>Team</h2>
</main>
<?php
include('partial/footer.php');
?>
</body>
</html>

@ -0,0 +1,149 @@
<?php
require_once 'include/db_connect.inc.php';
function getUser($conn, $id){
// With prepared statements (security reasons)
$sql = "SELECT * FROM user WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('i', $id);
$line = [];
$stmt->execute();
if ($result = $stmt->get_result()){
//$user = $result->fetch_assoc();
while ($obj = $result->fetch_assoc()){
$line[$obj['id']] = [
'id' =>$obj['id'],
'username' =>$obj['username'],
'password' =>$obj['password']
];
}
}
return $line;
//$result->close();
//var_dump($line);
}
function getMatchTeams($conn, $id){
// With prepared statements (security reasons)
$sql = "
SELECT t.id, t.name
FROM team t
INNER JOIN match__team mt ON mt.team = t.id
INNER JOIN `match` m ON m.id = mt.`match`
WHERE m.id = ?
";
$stmt = $conn->prepare($sql);
$stmt->bind_param('i', $id);
$line = [];
$stmt->execute();
if ($result = $stmt->get_result()){
//$user = $result->fetch_assoc();
while ($obj = $result->fetch_assoc()){
$line[$obj['id']] = [
'id' =>$obj['id'],
'name' =>$obj['name'],
];
}
}
return $line;
//$result->close();
//var_dump($line);
}
function getTeamPlayers($conn, $id){
// With prepared statements (security reasons)
$sql = "
SELECT ga.id, ga.ign, ga.rating, t.id AS team_id
FROM game_account ga
INNER JOIN team__player tp ON tp.game_account = ga.id
INNER JOIN team t ON tp.team = t.id
WHERE t.id = ?
";
$stmt = $conn->prepare($sql);
$stmt->bind_param('i', $id);
$line = [];
$stmt->execute();
if ($result = $stmt->get_result()){
//$user = $result->fetch_assoc();
while ($obj = $result->fetch_assoc()){
$line[$obj['id']] = [
'id' =>$obj['id'],
'ign' =>$obj['ign'],
'rating' =>$obj['rating'],
'team_id' =>$obj['team_id'],
];
}
}
return $line;
//$result->close();
//var_dump($line);
}
function getTournaments($conn){
// With prepared statements (security reasons)
$sql = "
SELECT *
FROM tournament t
WHERE dateTo >= curdate()
";
$stmt = $conn->prepare($sql);
$line = [];
$stmt->execute();
if ($result = $stmt->get_result()){
while ($obj = $result->fetch_assoc()){
$line[$obj['id']] = [
'id' =>$obj['id'],
'name' =>$obj['name'],
'game' =>$obj['game'],
'playform' =>$obj['platform'],
'dateFrom' =>$obj['dateFrom'],
'dateTo' =>$obj['dateTo'],
];
}
}
return $line;
//$result->close();
var_dump($line);
}
//getMatchTeams($conn, 1);
//getTeamPlayers($conn, 1);
getTournaments($conn);
//$result = $conn->query("SELECT * FROM user LIMIT 10");
//$conn->close();
?>

@ -0,0 +1,42 @@
<?php
require_once 'include/db_connect.inc.php';
function getTournaments($conn, $game = NULL){
$sql = "SELECT * FROM tournament";
if($game){
$sql = $sql." WHERE game = ?";
}
$stmt = $conn->prepare($sql);
if($game){
$stmt->bind_param('i', $game);
}
$tournaments = [];
$stmt->execute();
if ($result = $stmt->get_result()){
while ($obj = $result->fetch_assoc()){
$tournaments[$obj['id']] = [
'id' =>$obj['id'],
'name' =>$obj['name'],
'game' =>$obj['game'],
'platform' =>$obj['platform'],
'dateFrom' =>$obj['dateFrom'],
'dateTo' =>$obj['dateTo'],
'teamLimit' =>$obj['teamLimit'],
];
}
}
return $tournaments;
}
//echo (count(getTournaments($conn, 1)));
?>

@ -0,0 +1,91 @@
<?php
require_once 'include/db_connect.inc.php';
function isUserCorrect($conn, $username, $password){
try{
// Check if user exists in DB
$sql = "
SELECT
`unique_id`, `password`
FROM user
WHERE
username = ?
LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $username);
$stmt->execute();
$user = array();
if ($result = $stmt->get_result()){
while ($obj = $result->fetch_assoc()){
$user = [
'password' => $obj['password'],
'unique_id' => $obj['unique_id'],
];
}
}
if ($user and password_verify($password, $user['password'])){
return $user['unique_id'];
}
return false;
} catch(Throwable $t) {
# Could be Error/Exception classes, that are both Throwable
$errorMessage = "Throwable: ".$t->getCode().": ".$t->getMessage()."\n".
"Line number ".$t->getLine()." in file ".$t->getFile()."\n".
"Stack Trace: ". $t->getTrace()."\n".
date('Y-m-d h:i:s A');
error_log($errorMessage, 0);
# Email to the admin
return NULL;
}
}
function registerUser($conn, $username, $password, $password_repeat){
// Both passwords must match
if ($password !== $password_repeat){
return false;
}
// First check if the username is taken.
$sql = "SELECT 1 FROM user WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){ return false; }
// Hash and Secure password with a salt.
// https://www.php.net/manual/en/function.password-hash.php
$password = password_hash($password, PASSWORD_BCRYPT, ['cost' => 10]);
// needs a unique id also for cookies, uniqID, with a hash appended
$uniqueId = generateUniqueId();
// Now add the user details to the DB
$sql = "INSERT INTO user (username, password, unique_id) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param('sss', $username, $password, $uniqueId);
if ($stmt->execute()){
return $uniqueId;
}
return false;
}
function generateUniqueId(){
return uniqid() . '_' . md5(mt_rand());
}

@ -0,0 +1,17 @@
<?php
function filterName($field){
// Sanitize user name
$field = filter_var(trim($field), FILTER_SANITIZE_STRING);
// Validate user name
if(filter_var($field, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\-\s]+$/")))){
return $field;
}else{
return FALSE;
}
}
?>

@ -0,0 +1,66 @@
<?php
# Checks the uniqueId exists, if so create cookie and redirect
function userLogin(string $username, string $password){
require_once('./repository/userRepository.php');
// If correct credentials, add cookie and redirect
$uniqueId = isUserCorrect($conn, $username, $password);
if ($uniqueId === NULL or $uniqueId === ""){
$notification = [
"type" => "error",
"message" => "Something went wrong! The admin has been informed"
];
}elseif ($uniqueId === false){
$notification = [
"type" => "alert",
"message" => "Login details incorrect; Try again"
];
}else{
// 1 hour cookie to store userLogged username
setcookie("userLogged", $uniqueId, time()+3600);
// Needed as new cookies aren't checked until page reload
header("Location: ./profile.php");
die();
}
return $notification;
}
function userLogged(){
if (isset($_COOKIE['userLogged']) and $_COOKIE['userLogged']){
// User is loged in, redirect to profile
echo('test userLogged');
$url = "/profile.php";
header("Location: ".$url);
die();
}
}
# If the user account can access the page.
# username/uniqueId
# permissionRequired
function userPermissed(){
}
function logOut(){
if (isset($_COOKIE['userLogged'])) {
unset($_COOKIE['userLogged']);
setcookie('userLogged', null, -1, '/');
return true;
} else {
return false;
}
header("Location: /");
die();
}
?>

@ -0,0 +1,76 @@
<?php
require_once('scripts/userLogged.php');
userLogged();
?>
<?php
$meta = [
'title' => 'Register',
'description' => 'Register for an account',
'keywords' => ''
];
require_once('partial/head.php');
?>
<?php
require_once('partial/header.php');
?>
<?php
if (!empty($_POST)){
include('repository/userRepository.php');
$username = $_POST['username'];
$password = $_POST['password'];
$password_repeat = $_POST['password_repeat'];
$uniqueId = registerUser($conn, $username, $password, $password_repeat);
if($uniqueId){
// 1 hour cookie to store userLogged username
setcookie("userLogged", $uniqueId, time()+3600);
$notification = [
"type" => "success",
"message" => "Account ".$username." registered"
];
}else{
$notification = [
"type" => "error",
"message" => "Cannot register user account. Maybe your username isn't very original"
];
}
}
?>
<body>
<main class="layout-wrapper">
<h1>Register</h1>
<?php if(isset($notification)){ ?>
<div class="alert--<?php echo($notification['type']) ?>">
<?php echo($notification['message']) ?>
</div>
<?php } ?>
<form action="signup.php" method="post">
<label for="username"></label>
<input name="username" id="username" type="text" value="<?php echo $username ?>" placeholder="Username">
<label for="password"></label>
<input name="password" id="password" type="password" value="" placeholder="password">
<label for="password_repeat"></label>
<input name="password_repeat" id="password_repeat" type="password" value="" placeholder="password">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</main>
<?php
include('partial/footer.php');
?>
</body>
</html>

@ -0,0 +1,77 @@
<?php
require_once('elo.php');
foreach($teams as $index => $team){
?>
<div style="display: inline-block; vertical-align: middle; margin: 12px; width: 100%;">
<table style="background: lightgrey;">
<thead>
<th>Name</th>
<th>rating</th>
<th>expected</th>
<th>result</th>
</thead>
<tbody>
<td><?php echo($team['name']) ?></td>
<td><?php echo($team['playerRating']) ?></td>
<td><?php echo($team['expected']) ?></td>
<td><?php echo($team['score']) ?></td>
</tbody>
</table>
<table style="background: whitesmoke; width: 100%;">
<caption><?php echo($team['name']) ?></caption>
<thead>
<tr>
<th>Name</th>
<th>kfactor</th>
<th>pre</th>
<th>post</th>
</tr>
</thead>
<tbody>
<tr>
<td>Average</td>
</tr>
<?php
foreach($team['players'] as $player){
$kfactorChange = 1;
// This will calc %diff between player and team rating
$kfactorChange = $player['kfactor']*(($player['rating'] - $team['playerRating'])/$team['playerRating']);
// check if + or - and do stuff
// If win
if ($team['score']){
$playerKfactor = $player['kfactor'] - $kfactorChange;
}
else{
$playerKfactor = $player['kfactor'] + $kfactorChange;
}
// Calculate rating
$player['rating'] = round($player['rating'] + ( $playerKfactor * ( $team['score'] - $team['expected'] ) ));
?>
<tr>
<td><?php echo($player['ign']) ?></td>
<td><?php echo($player['kfactor']) ?></td>
<td><?php echo($player['rating']) ?></td>
<td><?php echo($player['rating']) ?></td>
</tr>
<?php
$i++;
// endforeach players
}
?>
</tbody>
</table>
</div>
<?php
if ($index !== array_key_last($teams)){
?>
<div style="display: inline-block; vertical-align: middle; margin: 24px; ">versus</div>
<?php
}
$t++;
// endforeach teams
}
?>

@ -0,0 +1,10 @@
tourney name, desc, images, etc
tourney teams
tourney matches
rounds (results can be edited in here)
tourney admins

@ -0,0 +1,28 @@
<?php
include('partial/header.php');
require_once('teamStuff.php');
?>
<h1>Tourney name</h1>
<div>from: 12 - to: 124</div>
<h2>Live matches</h2>
<a href="match.php">
<div>current round: 3</div>
<div>team a: 1</div>
<div>team b: 1</div>
</a>
<h2>Upcoming matches</h2>
x v y, starts 15th@2
<h2>Previous matches</h2>
<a href="match.php">
<div>team a: 2</div>
<div>team b: 1</div>
</a>
<?php
//include('partial/footer.php');
?>

@ -0,0 +1,29 @@
<html>
<head>
<?php include('partial/head.php'); ?>
</head>
<?php
include('partial/header.php');
?>
<h1>Tournaments</h1>
<section>
<h2><a href="tournament.php">tourney</a></h2>
<div class="starts">starts@224</div>
</section>
<section>
<h2><a href="tournament.php">tourney</a></h2>
<div class="starts">starts@224</div>
</section>
<section>
<h2><a href="tournament.php">tourney</a></h2>
<div class="starts">starts@224</div>
</section>
<?php
include('partial/footer.php');
?>
</html>
Loading…
Cancel
Save