Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
arfevrier committed Nov 8, 2017
1 parent 399d99b commit ba873ce
Show file tree
Hide file tree
Showing 8 changed files with 610 additions and 17 deletions.
17 changes: 0 additions & 17 deletions .gitattributes

This file was deleted.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Discord Bot | Chess

## Installation
- npm install [discord.js, request, mysql]
- config sql server with chess.sql
- Install olavache.ovh/discord_chess_game.php
- Adapt the code
- Launch play_chess.js
1 change: 1 addition & 0 deletions apache-website/olavache.ovh/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Options -Indexes
108 changes: 108 additions & 0 deletions apache-website/olavache.ovh/discord_chess_game.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
require('/[some directory]/process.php');

if(isset($_GET['tbl']) && isset($_GET['rot'])){
header('Content-Type: image/png');

$tbl = json_decode($_GET['tbl'], true);

if($_GET['rot'] == 1){
$tbl_local = $tbl;
for ($i = 1; $i <= 9-1; $i++) {
$tbl_local[$i][0] = $tbl[0][$i];
$tbl_local[0][9-$i] = $tbl[$i][0];
for ($a = 1; $a <= 9-1; $a++) {
$tbl_local[$i][9-$a] = $tbl[$a][$i];
};
};
$tbl = $tbl_local;
} else if($_GET['rot'] == 2){
$tbl_local = $tbl;
for ($i = 1; $i <= 9-1; $i++) {
$tbl_local[0][9-$i] = $tbl[0][$i];
$tbl_local[9-$i][0] = $tbl[$i][0];
for ($a = 1; $a <= 9-1; $a++) {
$tbl_local[9-$i][9-$a] = $tbl[$i][$a];
};
};
$tbl = $tbl_local;
} else if($_GET['rot'] == 3){
$tbl_local = $tbl;
for ($i = 1; $i <= 9-1; $i++) {
$tbl_local[9-$i][0] = $tbl[0][$i];
$tbl_local[0][$i] = $tbl[$i][0];
for ($a = 1; $a <= 9-1; $a++) {
$tbl_local[9-$i][$a] = $tbl[$a][$i];
};
};
$tbl = $tbl_local;
};

$first = '<!DOCTYPE html><html><head><style>body{background-color: #32363b;}td {width: 27px;height: 27px;font-weight: bold;padding: 0;}table {border-collapse: collapse;text-align: center;}</style></head><body style="font-family: Times New Roman;margin: 0;"><table>';

$second = '';
for ($i = 0; $i <= 9-1; $i++) {
$second = $second.'<tr>';
for ($a = 0; $a <= 9-1; $a++) {
if((($a%2 == 0 && $i%2 == 1) OR ($a%2 == 1 && $i%2 == 0)) && $i > 0 && $a != 0){
if($_GET['rot']%2 == 0){
$local_grille_color = "background-color: #ffce9e;";
} else {
$local_grille_color = "background-color: #d18b47;";
};
} elseif((($a%2 == 0 && $i%2 == 0) OR ($a%2 == 1 && $i%2 == 1)) && $i > 0 && $a != 0){
if($_GET['rot']%2 == 0){
$local_grille_color = "background-color: #d18b47;";
} else {
$local_grille_color = "background-color: #ffce9e;";
};
} else {
$local_grille_color = "";
}
if(($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '')){

$post = '<div style="width: 100%;height: 100%;color:#FFF;font-size:20px;text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;'.$local_grille_color.'">';
$after = '</div>';
} elseif(($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '') OR ($tbl[$i][$a] == '')){
$post = '<div style="width: 100%;height: 100%;color:#000000;font-size:20px;text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;'.$local_grille_color.'">';
$after = '</div>';
} else {
if($tbl[$i][$a] == ''){
$size_local = 'width: 100%;height: 100%;';
} else {
$size_local = '';
}
$post = '<div style="'.$size_local.'color:#dcdcdc;font-size:12px;'.$local_grille_color.'">';
$after = '</div>';
}
$second = $second.'<td>'.$post.$tbl[$i][$a].$after.'</td>';
};
$second = $second.'</tr>';
};

$third = '</table></body></html>';

$file_name = uniqid().'.png';
exec('cd /[some directory] && ./phantomjs chess.js '.$file_name.' "'.urlencode($first.$second.$third).'"');
echo file_get_contents('/[some directory]/'.$file_name);
unlink('/[some directory]/'.$file_name);
} elseif(isset($_GET['r'])){
$query = $mysqli->query("SELECT tbl,rot FROM `chess` WHERE `id`='".$_GET['r']."'")->fetch_row();
$tbl = $query[0];
$rot = $query[1];
header('Location: http://olavache.ovh/discord_chess_game.php?key=chess_some_key'.'&rot='.$rot.'&tbl='.$tbl);

} elseif(isset($_GET['insert']) && isset($_GET['rotation'])){

$mysqli->query("INSERT INTO `chess` (tbl,rot) VALUES ('".urlencode($_GET['insert'])."','".urlencode($_GET['rotation'])."')");
$resultprint['num_id'] = $mysqli->insert_id;
$resultprint['inserted'] = urlencode($_GET['insert']);
echo json_encode($resultprint);

} else {

$resultprint['error'] = 'No valid value';
http_response_code(400);
echo json_encode($resultprint);
}
?>
6 changes: 6 additions & 0 deletions chess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var page = require('webpage').create();
var system = require('system');
page.viewportSize = { width: 250, height: 250 };
page.content = decodeURIComponent(system.args[2]).replace( /\+/g, ' ' );
page.render(system.args[1]);
phantom.exit();
59 changes: 59 additions & 0 deletions chess.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- phpMyAdmin SQL Dump
-- version 4.7.2
-- https://www.phpmyadmin.net/
--
-- Hôte : localhost
-- Généré le : mer. 08 nov. 2017 à 18:03
-- Version du serveur : 10.0.30-MariaDB-0+deb8u1
-- Version de PHP : 7.0.18-1~dotdeb+8.1

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Base de données : `api`
--

-- --------------------------------------------------------

--
-- Structure de la table `chess`
--

CREATE TABLE `chess` (
`id` int(11) NOT NULL,
`tbl` text NOT NULL,
`rot` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Index pour les tables déchargées
--

--
-- Index pour la table `chess`
--
ALTER TABLE `chess`
ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT pour les tables déchargées
--

--
-- AUTO_INCREMENT pour la table `chess`
--
ALTER TABLE `chess`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Binary file added phantomjs
Binary file not shown.
Loading

0 comments on commit ba873ce

Please sign in to comment.