From 8684f32db2fc9de03eb56f2dc7e1ca76450177d3 Mon Sep 17 00:00:00 2001 From: ntr Date: Wed, 14 Aug 2019 17:40:01 +1000 Subject: [PATCH] nginx acp stuff --- acp/acp.js | 1 + acp/src/acp.main.jsx | 39 +++++++---- acp/src/acp.user.jsx | 69 ++++++++++++++++--- acp/src/actions.jsx | 1 + acp/src/reducers.jsx | 1 + bin/client.sh | 6 ++ bin/deploy.sh | 11 ++- client/assets/styles/acp.less | 24 +++++++ client/assets/styles/menu.less | 16 ----- .../mnml.gg.STAGING.SAMPLE.nginx.conf | 34 ++------- server/src/instance.rs | 4 +- 11 files changed, 139 insertions(+), 67 deletions(-) create mode 100644 client/assets/styles/acp.less diff --git a/acp/acp.js b/acp/acp.js index 825f39d8..0f4b8299 100644 --- a/acp/acp.js +++ b/acp/acp.js @@ -3,6 +3,7 @@ require('./../client/assets/styles/skeleton.css'); require('./../client/assets/styles/styles.less'); require('./../client/assets/styles/menu.less'); +require('./../client/assets/styles/acp.less'); require('./../client/assets/styles/nav.less'); require('./../client/assets/styles/footer.less'); require('./../client/assets/styles/account.less'); diff --git a/acp/src/acp.main.jsx b/acp/src/acp.main.jsx index e078c2a2..32309ba4 100644 --- a/acp/src/acp.main.jsx +++ b/acp/src/acp.main.jsx @@ -14,10 +14,13 @@ const addState = connect( const { account, user, + msg, } = state; return { - account, user, + account, + user, + msg, }; }, @@ -30,8 +33,13 @@ const addState = connect( dispatch(actions.setGames(list)); } + function setMsg(msg) { + dispatch(actions.setMsg(msg)); + } + return { setUser, + setMsg, setGames, }; } @@ -43,12 +51,8 @@ class AcpMain extends Component { super(props); this.state = { - account: {}, - name: null, id: null, - msg: '', - user: null, - games: [], + name: null, }; } @@ -56,31 +60,38 @@ class AcpMain extends Component { const { setGames, setUser, + setMsg, + + msg, } = args; const { - msg, name, id, } = state; + const reset = () => { + setMsg(null); + this.setState({ id: null, name: null }); + }; + const getUser = () => { - this.setState({ msg: null }); + reset(); postData('/acp/user', { id, name }) .then(res => res.json()) .then(data => { - if (data.error) return this.setState({ msg: data.error }); + if (data.error) return setMsg(data.error); setUser(data); }) .catch(error => errorToast(error)); }; const gameList = () => { - this.setState({ msg: null }); + reset(); postData('/acp/game/list', { number: 20 }) .then(res => res.json()) .then(data => { - if (data.error) return this.setState({ msg: data.error }); + if (data.error) return setMsg(data.error); console.log(data); setGames(data.data); }) @@ -88,11 +99,11 @@ class AcpMain extends Component { }; const gameOpen = () => { - this.setState({ msg: null }); + reset(); postData('/acp/game/open') .then(res => res.json()) .then(data => { - if (data.error) return this.setState({ msg: data.error }); + if (data.error) return setMsg(data.error); console.log(data); setGames(data); }) @@ -102,7 +113,7 @@ class AcpMain extends Component { return (
-
{msg}
+
{msg}
diff --git a/acp/src/acp.user.jsx b/acp/src/acp.user.jsx index 0f5b2a3b..0b2e7072 100644 --- a/acp/src/acp.user.jsx +++ b/acp/src/acp.user.jsx @@ -3,8 +3,7 @@ const { Component } = require('preact'); const { connect } = require('preact-redux'); const linkState = require('linkstate').default; -const axios = require('axios'); - +const { postData, errorToast } = require('./../../client/src/utils'); const actions = require('./actions'); const addState = connect( @@ -14,22 +13,58 @@ const addState = connect( } = state; return { - user + user, }; }, + function receiveDispatch(dispatch) { + function setUser(user) { + dispatch(actions.setUser(user)); + } + + function setMsg(msg) { + dispatch(actions.setMsg(msg)); + } + + return { + setUser, + setMsg, + }; + } ); -function AcpGameList(args) { +function AcpUser(args) { const { user, + setUser, + setMsg, } = args; + const { + credits, + } = this.state; + if (!user) return false; + const reset = () => { + setMsg(null); + this.setState({ credits: null }); + }; + + const addCredits = () => { + reset(); + postData('/acp/user/credits', { id: user.id, credits }) + .then(res => res.json()) + .then(data => { + if (data.error) return setMsg(data.error); + return setUser(data); + }) + .catch(error => setMsg(error)); + }; + return ( -
-

{user.name}

+
+

{user.name}

Id
{user.id}
Credits
@@ -37,8 +72,26 @@ function AcpGameList(args) {
Subscribed
{user.subscribed.toString()}
+
+ + + +
+
+

Constructs

+
- ) + ); } -module.exports = addState(AcpGameList); +module.exports = addState(AcpUser); diff --git a/acp/src/actions.jsx b/acp/src/actions.jsx index bf8155be..3de2fb07 100644 --- a/acp/src/actions.jsx +++ b/acp/src/actions.jsx @@ -1,3 +1,4 @@ export const setAccount = value => ({ type: 'SET_ACCOUNT', value }); export const setUser = value => ({ type: 'SET_USER', value }); +export const setMsg = value => ({ type: 'SET_MSG', value }); export const setGames = value => ({ type: 'SET_GAMES', value }); diff --git a/acp/src/reducers.jsx b/acp/src/reducers.jsx index 7522236e..b22d0b88 100644 --- a/acp/src/reducers.jsx +++ b/acp/src/reducers.jsx @@ -13,5 +13,6 @@ function createReducer(defaultState, actionType) { module.exports = { account: createReducer(null, 'SET_ACCOUNT'), user: createReducer(null, 'SET_USER'), + msg: createReducer(null, 'SET_MSG'), games: createReducer([], 'SET_GAMES'), }; diff --git a/bin/client.sh b/bin/client.sh index 2faac662..a2407748 100755 --- a/bin/client.sh +++ b/bin/client.sh @@ -12,3 +12,9 @@ cd $MNML_PATH/client rm -rf dist npm i npm run build + +echo "Building acp version $VERSION" +cd $MNML_PATH/acp +rm -rf dist +npm i +npm run build diff --git a/bin/deploy.sh b/bin/deploy.sh index e29588e6..94a2bd26 100755 --- a/bin/deploy.sh +++ b/bin/deploy.sh @@ -6,8 +6,12 @@ MNML_PATH=$(realpath "$DIR/../") VERSION=$(<"$MNML_PATH/VERSION") SERVER_BIN_DIR="/usr/local/mnml/bin" + CLIENT_DIST_DIR="/var/lib/mnml/client" -CLIENT_PUBLIC_DIR="/var/lib/mnml/public/current" +CLIENT_PUBLIC_DIR="/var/lib/mnml/public/client" + +ACP_DIST_DIR="/var/lib/mnml/acp" +ACP_PUBLIC_DIR="/var/lib/mnml/public/acp" # server updates echo "syncing server $VERSION " @@ -19,6 +23,11 @@ ssh -q mnml ls -lah "$SERVER_BIN_DIR" echo "syncing client $VERSION" rsync -a --delete --delete-excluded "$MNML_PATH/client/dist/" mnml:"$CLIENT_DIST_DIR/$VERSION/" ssh -q mnml ln -nfs "$CLIENT_DIST_DIR/$VERSION" "$CLIENT_PUBLIC_DIR" + +# acp updates +echo "syncing acp $VERSION" +rsync -a --delete --delete-excluded "$MNML_PATH/acp/dist/" mnml:"$ACP_DIST_DIR/$VERSION/" +ssh -q mnml ln -nfs "$ACP_DIST_DIR/$VERSION" "$ACP_PUBLIC_DIR" ssh -q mnml ls -lah "/var/lib/mnml/public" echo "restarting mnml service" diff --git a/client/assets/styles/acp.less b/client/assets/styles/acp.less new file mode 100644 index 00000000..e749bc27 --- /dev/null +++ b/client/assets/styles/acp.less @@ -0,0 +1,24 @@ +#mnml.acp { + user-select: text; + -moz-user-select: text; + -webkit-user-select: text; + -ms-user-select: text; + + .bottom { + display: grid; + grid-template-columns: repeat(4, 1fr); + } + + .top { + padding: 0; + } + + input { + display: block; + } + + .user { + display: grid; + grid-template-columns: repeat(3, 1fr); + } +} \ No newline at end of file diff --git a/client/assets/styles/menu.less b/client/assets/styles/menu.less index 30e74a2a..fb919124 100644 --- a/client/assets/styles/menu.less +++ b/client/assets/styles/menu.less @@ -88,19 +88,3 @@ } } } - -#mnml.acp { - user-select: text; - -moz-user-select: text; - -webkit-user-select: text; - -ms-user-select: text; - - .bottom { - display: grid; - grid-template-columns: repeat(4, 1fr); - } - - input { - display: block; - } -} \ No newline at end of file diff --git a/etc/nginx/sites-available/mnml.gg.STAGING.SAMPLE.nginx.conf b/etc/nginx/sites-available/mnml.gg.STAGING.SAMPLE.nginx.conf index 1d1d2bbf..446c2878 100644 --- a/etc/nginx/sites-available/mnml.gg.STAGING.SAMPLE.nginx.conf +++ b/etc/nginx/sites-available/mnml.gg.STAGING.SAMPLE.nginx.conf @@ -1,7 +1,3 @@ -upstream mnml_dev { - server 0.0.0.0:41337; -} - error_log /var/log/mnml/nginx.log; upstream mnml_http { @@ -21,11 +17,17 @@ map $http_upgrade $connection_upgrade { # DEV server { location / { - root /var/lib/mnml/public/current; + root /var/lib/mnml/public/client; index index.html; try_files $uri $uri/ index.html; } + location /acp { + root /var/lib/mnml/public/acp; + index acp.html; + try_files $uri $uri/ acp.html; + } + location /imgs/ { root /var/lib/mnml/public/; try_files $uri $uri/ =404; @@ -51,25 +53,3 @@ server { include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } - -# http -> https -server { - server_name mnml.gg; - return 301 https://$host$request_uri; -} - -server { - server_name minimal.gg; - return 301 https://mnml.gg$request_uri; -} - -server { - server_name cryps.gg; - return 301 https://mnml.gg$request_uri; -} - -server { - server_name dev.mnml.gg; - return 301 https://$host$request_uri; -} - diff --git a/server/src/instance.rs b/server/src/instance.rs index bfe6420b..eb2c35d7 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -396,9 +396,11 @@ impl Instance { // if you don't win, you lose // ties can happen if both players forfeit + // in this case we just finish the game and + // dock them 10k mmr let winner_id = match game.winner() { Some(w) => w.id, - None => Uuid::nil(), + None => return Ok(self.finish()), }; for player in game.players.iter() {