Ensure board is flipped when starting a game as dark, move some constants to environment variables, minor frontend changes:
This commit is contained in:
parent
bb66cd91a3
commit
593a631a56
@ -1,3 +1,4 @@
|
|||||||
|
HOST=0.0.0.0
|
||||||
NODE_ID=aUniqueString
|
NODE_ID=aUniqueString
|
||||||
DATABASE_URL=ecto://chessh:password@database/chessh
|
DATABASE_URL=ecto://chessh:password@database/chessh
|
||||||
|
|
||||||
@ -5,6 +6,7 @@ POSTGRES_USER=chessh
|
|||||||
POSTGRES_PASSWORD=password
|
POSTGRES_PASSWORD=password
|
||||||
POSTGRES_DATABASE=chessh
|
POSTGRES_DATABASE=chessh
|
||||||
|
|
||||||
|
WEB_PORT=8080
|
||||||
REACT_APP_GITHUB_OAUTH=https://github.com/login/oauth/authorize?client_id=CLIENT_ID_HERE&redirect_uri=http://127.0.0.1:3000/api/oauth/redirect
|
REACT_APP_GITHUB_OAUTH=https://github.com/login/oauth/authorize?client_id=CLIENT_ID_HERE&redirect_uri=http://127.0.0.1:3000/api/oauth/redirect
|
||||||
CLIENT_REDIRECT_AFTER_OAUTH=http://127.0.0.1:3000/auth-successful
|
CLIENT_REDIRECT_AFTER_OAUTH=http://127.0.0.1:3000/auth-successful
|
||||||
|
|
||||||
|
6
build.sh
6
build.sh
@ -1,16 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
env_file=.env.prod
|
env_file=.env.prod
|
||||||
started_in=$PWD
|
|
||||||
|
|
||||||
export $(cat $env_file | xargs)
|
export $(cat $env_file | xargs)
|
||||||
|
|
||||||
|
docker build . -t chessh/server
|
||||||
|
|
||||||
cd front
|
cd front
|
||||||
docker build \
|
docker build \
|
||||||
--build-arg REACT_APP_GITHUB_OAUTH=${REACT_APP_GITHUB_OAUTH} \
|
--build-arg REACT_APP_GITHUB_OAUTH=${REACT_APP_GITHUB_OAUTH} \
|
||||||
--build-arg REACT_APP_SSH_SERVER=${REACT_APP_SSH_SERVER} \
|
--build-arg REACT_APP_SSH_SERVER=${REACT_APP_SSH_SERVER} \
|
||||||
--build-arg REACT_APP_SSH_PORT=${REACT_APP_SSH_PORT} \
|
--build-arg REACT_APP_SSH_PORT=${REACT_APP_SSH_PORT} \
|
||||||
. -t chessh/frontend
|
. -t chessh/frontend
|
||||||
|
|
||||||
cd $started_in
|
|
||||||
docker build . -t chessh/server
|
|
||||||
|
@ -15,7 +15,6 @@ config :chessh, RateLimits,
|
|||||||
player_public_keys: 15
|
player_public_keys: 15
|
||||||
|
|
||||||
config :chessh, Web,
|
config :chessh, Web,
|
||||||
port: 8080,
|
|
||||||
github_oauth_login_url: "https://github.com/login/oauth/access_token",
|
github_oauth_login_url: "https://github.com/login/oauth/access_token",
|
||||||
github_user_api_url: "https://api.github.com/user"
|
github_user_api_url: "https://api.github.com/user"
|
||||||
|
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
import Config
|
import Config
|
||||||
|
|
||||||
config :chessh,
|
config :chessh,
|
||||||
port: String.to_integer(System.get_env("SSH_PORT", "42069"))
|
ssh_port: String.to_integer(System.get_env("SSH_PORT", "42069"))
|
||||||
|
|
||||||
config :chessh, Web,
|
config :chessh, Web,
|
||||||
github_client_id: System.get_env("GITHUB_CLIENT_ID"),
|
github_client_id: System.get_env("GITHUB_CLIENT_ID"),
|
||||||
github_client_secret: System.get_env("GITHUB_CLIENT_SECRET"),
|
github_client_secret: System.get_env("GITHUB_CLIENT_SECRET"),
|
||||||
github_user_agent: System.get_env("GITHUB_USER_AGENT"),
|
github_user_agent: System.get_env("GITHUB_USER_AGENT"),
|
||||||
client_redirect_after_successful_sign_in:
|
client_redirect_after_successful_sign_in:
|
||||||
System.get_env("CLIENT_REDIRECT_AFTER_OAUTH", "http://localhost:3000")
|
System.get_env("CLIENT_REDIRECT_AFTER_OAUTH", "http://localhost:3000"),
|
||||||
|
port: String.to_integer(System.get_env("WEB_PORT", "8080"))
|
||||||
|
|
||||||
config :joken,
|
config :joken,
|
||||||
default_signer: System.get_env("JWT_SECRET")
|
default_signer: System.get_env("JWT_SECRET")
|
||||||
|
22
deploy.sh
22
deploy.sh
@ -3,24 +3,18 @@
|
|||||||
datestamp=$(date +%Y%m%d-%H%M)
|
datestamp=$(date +%Y%m%d-%H%M)
|
||||||
env_file=.env.prod
|
env_file=.env.prod
|
||||||
project_name=chessh
|
project_name=chessh
|
||||||
port=8080
|
|
||||||
ssh_port=34355
|
|
||||||
host=0.0.0.0
|
|
||||||
|
|
||||||
container_names=("chessh-redis" "chessh-database" "chessh-server" "chessh-frontend")
|
container_names=("chessh-redis" "chessh-database" "chessh-server" "chessh-frontend")
|
||||||
|
|
||||||
|
export $(cat $env_file | xargs)
|
||||||
|
|
||||||
for name in ${container_names[@]}; do
|
for name in ${container_names[@]}; do
|
||||||
docker stop $name
|
docker stop $name
|
||||||
docker rm $name
|
docker rm $name
|
||||||
done
|
done
|
||||||
|
|
||||||
# Create network for chessh
|
|
||||||
docker network ls | grep -q $project_name || docker network create --driver bridge $project_name
|
docker network ls | grep -q $project_name || docker network create --driver bridge $project_name
|
||||||
|
|
||||||
# Create redis volume if it does not exist
|
|
||||||
docker volume ls | grep -q $project_name-redisdata || docker volume create $project_name-redisdata
|
docker volume ls | grep -q $project_name-redisdata || docker volume create $project_name-redisdata
|
||||||
|
|
||||||
# Then start the redis container
|
|
||||||
docker run \
|
docker run \
|
||||||
-d \
|
-d \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
@ -31,11 +25,7 @@ docker run \
|
|||||||
--volume $project_name-redisdata:/data/ \
|
--volume $project_name-redisdata:/data/ \
|
||||||
redis
|
redis
|
||||||
|
|
||||||
# Start postgres container
|
|
||||||
# Firstly create pg volume if it does not exist
|
|
||||||
docker volume ls | grep -q $project_name-pgdata || docker volume create $project_name-pgdata
|
docker volume ls | grep -q $project_name-pgdata || docker volume create $project_name-pgdata
|
||||||
|
|
||||||
# Then run the pg container
|
|
||||||
docker run \
|
docker run \
|
||||||
-d \
|
-d \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
@ -46,26 +36,22 @@ docker run \
|
|||||||
--volume $project_name-pgdata:/var/lib/postgresql/data/ \
|
--volume $project_name-pgdata:/var/lib/postgresql/data/ \
|
||||||
postgres
|
postgres
|
||||||
|
|
||||||
# Start backend container
|
|
||||||
# Check if running; if so, stop, and rename
|
|
||||||
docker run \
|
docker run \
|
||||||
-d \
|
-d \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
--env-file $env_file \
|
--env-file $env_file \
|
||||||
--network $project_name \
|
--network $project_name \
|
||||||
--name $project_name-server \
|
--name $project_name-server \
|
||||||
--publish "${host}:${ssh_port}:${ssh_port}/tcp" \
|
--publish "${host}:${host_ssh_port}:${container_ssh_port}/tcp" \
|
||||||
--net-alias server \
|
--net-alias server \
|
||||||
chessh/server
|
chessh/server
|
||||||
|
|
||||||
# Start frontend container
|
|
||||||
# Check if running; if so, stop, and rename
|
|
||||||
docker run \
|
docker run \
|
||||||
-d \
|
-d \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
--env-file $env_file \
|
--env-file $env_file \
|
||||||
--network $project_name \
|
--network $project_name \
|
||||||
--name $project_name-frontend \
|
--name $project_name-frontend \
|
||||||
--publish "${host}:${port}:80/tcp" \
|
--publish "${HOST}:${PORT}:80/tcp" \
|
||||||
--net-alias frontend \
|
--net-alias frontend \
|
||||||
chessh/frontend
|
chessh/frontend
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -31,7 +31,7 @@ export const AuthProvider = ({ children }) => {
|
|||||||
fetch("/api/player/logout", {
|
fetch("/api/player/logout", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
}).then(() => setDefaults());
|
}).then(setDefaults);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -19,6 +19,9 @@ export const Root = () => {
|
|||||||
<div className="nav">
|
<div className="nav">
|
||||||
{signedIn ? (
|
{signedIn ? (
|
||||||
<>
|
<>
|
||||||
|
<Link className="link" to="/home">
|
||||||
|
Home
|
||||||
|
</Link>
|
||||||
<Link className="link" to="/password">
|
<Link className="link" to="/password">
|
||||||
Password
|
Password
|
||||||
</Link>
|
</Link>
|
||||||
|
@ -24,16 +24,10 @@ export const AuthSuccessful = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h3>Hello there, {player?.username || ""}! </h3>
|
<h3>Hello there, {player?.username || ""}! </h3>
|
||||||
<div>
|
<p>You've successfully been authenticated.</p>
|
||||||
<span> If you have not already done so: </span>
|
|
||||||
<Link to="/keys" className="button">
|
|
||||||
Add a Public Key
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
<br />
|
|
||||||
<div>
|
<div>
|
||||||
<Link to="/home" className="button">
|
<Link to="/home" className="button">
|
||||||
Go Home
|
Get Started
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
@ -6,7 +6,6 @@ import "asciinema-player/dist/bundle/asciinema-player.css";
|
|||||||
|
|
||||||
const demoProps = {
|
const demoProps = {
|
||||||
theme: "tango",
|
theme: "tango",
|
||||||
startAt: 12,
|
|
||||||
autoPlay: true,
|
autoPlay: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -49,6 +49,19 @@ export const Home = () => {
|
|||||||
codeBlock
|
codeBlock
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<li>Finally, play chess!</li>
|
||||||
|
<p>Ideally, keeping the following contols in mind:</p>
|
||||||
|
<ul>
|
||||||
|
<li>Ctrl + b / Escape to return to the main menu.</li>
|
||||||
|
<li>Ctrl + c / Ctrl + d to exit at any point.</li>
|
||||||
|
<li>Arrow keys to move around the board.</li>
|
||||||
|
<li>
|
||||||
|
Select a piece with "enter", and move it to a square by pressing
|
||||||
|
"enter" again.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</ol>
|
</ol>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -20,7 +20,7 @@ const KeyCard = ({ onDelete, props }) => {
|
|||||||
const deleteThisKey = () => {
|
const deleteThisKey = () => {
|
||||||
if (
|
if (
|
||||||
window.confirm(
|
window.confirm(
|
||||||
"Are you sure? This will close all your current ssh sessions."
|
"Are you sure? This will close all your currently opened ssh sessions."
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
fetch(`/api/keys/${id}`, {
|
fetch(`/api/keys/${id}`, {
|
||||||
|
@ -21,7 +21,7 @@ export const Password = () => {
|
|||||||
const deletePassword = () => {
|
const deletePassword = () => {
|
||||||
if (
|
if (
|
||||||
window.confirm(
|
window.confirm(
|
||||||
"Are you sure? This will close all your current ssh sessions."
|
"Are you sure? This will close all your currently opened ssh sessions."
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
fetch(`/api/player/token/password`, {
|
fetch(`/api/player/token/password`, {
|
||||||
|
@ -103,7 +103,7 @@ defmodule Chessh.SSH.Client do
|
|||||||
:quit ->
|
:quit ->
|
||||||
{:stop, :normal, state}
|
{:stop, :normal, state}
|
||||||
|
|
||||||
:previous_screen ->
|
:menu ->
|
||||||
GenServer.stop(screen_pid)
|
GenServer.stop(screen_pid)
|
||||||
link_menu_screen(player_session)
|
link_menu_screen(player_session)
|
||||||
|
|
||||||
@ -153,7 +153,9 @@ defmodule Chessh.SSH.Client do
|
|||||||
<<3>> -> :quit
|
<<3>> -> :quit
|
||||||
<<4>> -> :quit
|
<<4>> -> :quit
|
||||||
# C-b
|
# C-b
|
||||||
<<2>> -> :previous_screen
|
<<2>> -> :menu
|
||||||
|
# Escape
|
||||||
|
"\e" -> :menu
|
||||||
# Arrow keys
|
# Arrow keys
|
||||||
"\e[A" -> :up
|
"\e[A" -> :up
|
||||||
"\e[B" -> :down
|
"\e[B" -> :down
|
||||||
|
@ -41,6 +41,7 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
| tail
|
| tail
|
||||||
])
|
])
|
||||||
when is_nil(color) do
|
when is_nil(color) do
|
||||||
|
# Joining a game
|
||||||
{is_dark, is_light} = {player_id == dark_player_id, player_id == light_player_id}
|
{is_dark, is_light} = {player_id == dark_player_id, player_id == light_player_id}
|
||||||
|
|
||||||
new_state =
|
new_state =
|
||||||
@ -57,6 +58,35 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
init([new_state | tail])
|
init([new_state | tail])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def init([
|
||||||
|
%State{player_session: player_session, color: color, game: nil} = state
|
||||||
|
| tail
|
||||||
|
]) do
|
||||||
|
# Starting a new game
|
||||||
|
{:ok, %Game{} = game} =
|
||||||
|
Game.changeset(
|
||||||
|
%Game{},
|
||||||
|
Map.merge(
|
||||||
|
if(color == :light,
|
||||||
|
do: %{light_player_id: player_session.player_id},
|
||||||
|
else: %{dark_player_id: player_session.player_id}
|
||||||
|
),
|
||||||
|
%{
|
||||||
|
fen: @default_fen
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|> Repo.insert()
|
||||||
|
|
||||||
|
init([
|
||||||
|
%State{
|
||||||
|
state
|
||||||
|
| game: game
|
||||||
|
}
|
||||||
|
| tail
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
def init([
|
def init([
|
||||||
%State{
|
%State{
|
||||||
player_session: player_session,
|
player_session: player_session,
|
||||||
@ -96,10 +126,9 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
end
|
end
|
||||||
|
|
||||||
binbo_pid = initialize_game(game_id, fen)
|
binbo_pid = initialize_game(game_id, fen)
|
||||||
new_game = Repo.get(Game, game_id) |> Repo.preload([:light_player, :dark_player])
|
game = Repo.get(Game, game_id) |> Repo.preload([:light_player, :dark_player])
|
||||||
|
|
||||||
player_color =
|
player_color = if(game.light_player_id == player_session.player_id, do: :light, else: :dark)
|
||||||
if(new_game.light_player_id == player_session.player_id, do: :light, else: :dark)
|
|
||||||
|
|
||||||
new_state =
|
new_state =
|
||||||
(fn new_state ->
|
(fn new_state ->
|
||||||
@ -111,7 +140,7 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
state
|
state
|
||||||
| binbo_pid: binbo_pid,
|
| binbo_pid: binbo_pid,
|
||||||
color: player_color,
|
color: player_color,
|
||||||
game: new_game,
|
game: game,
|
||||||
flipped: player_color == :dark
|
flipped: player_color == :dark
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -123,37 +152,6 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
{:ok, new_state}
|
{:ok, new_state}
|
||||||
end
|
end
|
||||||
|
|
||||||
def init([
|
|
||||||
%State{player_session: player_session, color: color, client_pid: client_pid, game: nil} =
|
|
||||||
state
|
|
||||||
| _
|
|
||||||
]) do
|
|
||||||
{:ok, %Game{id: game_id, fen: fen}} =
|
|
||||||
Game.changeset(
|
|
||||||
%Game{},
|
|
||||||
Map.merge(
|
|
||||||
if(color == :light,
|
|
||||||
do: %{light_player_id: player_session.player_id},
|
|
||||||
else: %{dark_player_id: player_session.player_id}
|
|
||||||
),
|
|
||||||
%{
|
|
||||||
fen: @default_fen
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|> Repo.insert()
|
|
||||||
|
|
||||||
binbo_pid = initialize_game(game_id, fen)
|
|
||||||
send(client_pid, {:send_to_ssh, Utils.clear_codes()})
|
|
||||||
|
|
||||||
{:ok,
|
|
||||||
%State{
|
|
||||||
state
|
|
||||||
| game: Repo.get(Game, game_id) |> Repo.preload([:light_player, :dark_player]),
|
|
||||||
binbo_pid: binbo_pid
|
|
||||||
}}
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_info(
|
def handle_info(
|
||||||
{:new_move, move},
|
{:new_move, move},
|
||||||
%State{
|
%State{
|
||||||
@ -210,11 +208,20 @@ defmodule Chessh.SSH.Client.Game do
|
|||||||
) do
|
) do
|
||||||
new_cursor =
|
new_cursor =
|
||||||
case action do
|
case action do
|
||||||
:left -> %{y: cursor_y, x: Utils.wrap_around(cursor_x, -1, Renderer.chess_board_width())}
|
:left ->
|
||||||
:right -> %{y: cursor_y, x: Utils.wrap_around(cursor_x, 1, Renderer.chess_board_width())}
|
%{y: cursor_y, x: Utils.wrap_around(cursor_x, -1, Renderer.chess_board_width())}
|
||||||
:down -> %{y: Utils.wrap_around(cursor_y, 1, Renderer.chess_board_height()), x: cursor_x}
|
|
||||||
:up -> %{y: Utils.wrap_around(cursor_y, -1, Renderer.chess_board_height()), x: cursor_x}
|
:right ->
|
||||||
_ -> cursor
|
%{y: cursor_y, x: Utils.wrap_around(cursor_x, 1, Renderer.chess_board_width())}
|
||||||
|
|
||||||
|
:down ->
|
||||||
|
%{y: Utils.wrap_around(cursor_y, 1, Renderer.chess_board_height()), x: cursor_x}
|
||||||
|
|
||||||
|
:up ->
|
||||||
|
%{y: Utils.wrap_around(cursor_y, -1, Renderer.chess_board_height()), x: cursor_x}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
cursor
|
||||||
end
|
end
|
||||||
|
|
||||||
maybe_flipped_cursor_tup =
|
maybe_flipped_cursor_tup =
|
||||||
|
@ -9,9 +9,10 @@ defmodule Chessh.SSH.Client.Game.Renderer do
|
|||||||
@tile_width 7
|
@tile_width 7
|
||||||
@tile_height 4
|
@tile_height 4
|
||||||
|
|
||||||
@previous_move_background ANSI.light_yellow_background()
|
@previous_move_background ANSI.light_magenta_background()
|
||||||
@from_select_background ANSI.light_green_background()
|
@from_select_background ANSI.light_green_background()
|
||||||
@to_select_background ANSI.light_green_background()
|
@to_select_background ANSI.light_yellow_background()
|
||||||
|
|
||||||
@dark_piece_color ANSI.red()
|
@dark_piece_color ANSI.red()
|
||||||
@light_piece_color ANSI.light_cyan()
|
@light_piece_color ANSI.light_cyan()
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ defmodule Chessh.SSH.Daemon do
|
|||||||
do: pwd_authenticate(username, password, inet)
|
do: pwd_authenticate(username, password, inet)
|
||||||
|
|
||||||
def handle_info(:start, state) do
|
def handle_info(:start, state) do
|
||||||
port = Application.fetch_env!(:chessh, :port)
|
port = Application.fetch_env!(:chessh, :ssh_port)
|
||||||
key_dir = String.to_charlist(Application.fetch_env!(:chessh, :key_dir))
|
key_dir = String.to_charlist(Application.fetch_env!(:chessh, :key_dir))
|
||||||
max_sessions = Application.fetch_env!(:chessh, :max_sessions)
|
max_sessions = Application.fetch_env!(:chessh, :max_sessions)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user