diff --git a/client/package.json b/client/package.json index 091be65..69e5da3 100644 --- a/client/package.json +++ b/client/package.json @@ -9,9 +9,11 @@ }, "dependencies": { "@types/js-cookie": "^2.2.6", + "@types/socket.io-client": "^1.4.32", "axios": "^0.19.2", "core-js": "^3.6.4", "js-cookie": "^2.2.1", + "socket.io-client": "^2.3.0", "vue": "^2.6.11", "vue-class-component": "^7.2.3", "vue-property-decorator": "^8.4.1", diff --git a/client/src/.editorconfig b/client/src/.editorconfig new file mode 100644 index 0000000..9f73416 --- /dev/null +++ b/client/src/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/client/src/App.vue b/client/src/App.vue index 77ba4d6..fc412ae 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -1,29 +1,67 @@ - - - - - + + + + + diff --git a/client/src/main.ts b/client/src/main.ts index 87b38f9..eeab368 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -8,5 +8,5 @@ Vue.config.productionTip = false; new Vue({ router, store, - render: h => h(App), + render: (h) => h(App), }).$mount('#app'); diff --git a/client/src/router/index.ts b/client/src/router/index.ts index 9b1ae1f..a36bb3e 100644 --- a/client/src/router/index.ts +++ b/client/src/router/index.ts @@ -1,27 +1,37 @@ -import Vue from 'vue'; -import VueRouter, { RouteConfig } from 'vue-router'; -import Home from '../views/Home.vue'; - -Vue.use(VueRouter); - -const routes: RouteConfig[] = [ - { - path: '/', - name: 'Home', - component: Home, - }, - { - path: '/login', - name: 'login', - // route level code-splitting - // this generates a separate chunk (about.[hash].js) for this route - // which is lazy-loaded when the route is visited. - component: () => import('../views/login.vue'), - }, -]; - -const router = new VueRouter({ - routes, -}); - -export default router; +import Vue from 'vue'; +import VueRouter, { RouteConfig } from 'vue-router'; +import Home from '../views/Home.vue'; +import Login from '../views/login.vue'; +import Register from '../views/register.vue'; +import Game from '../views/game.vue'; + +Vue.use(VueRouter); + +const routes: RouteConfig[] = [ + { + path: '/', + name: 'home', + component: Home, + }, + { + path: '/login', + name: 'login', + component: Login, + }, + { + path: '/register', + name: 'register', + component: Register, + }, + { + path: '/game/:roomNumber', + name: 'game', + component: Game, + }, +]; + +const router = new VueRouter({ + routes, +}); + +export default router; diff --git a/client/src/service/index.ts b/client/src/service/index.ts index ba0622b..5c5117a 100644 --- a/client/src/service/index.ts +++ b/client/src/service/index.ts @@ -1,8 +1,20 @@ -import request from '../utils/request'; - -export default { - register: (userName: string, password: string) => request({ - url: '', - body: { userName, password }, - }), -}; +import request from '../utils/request'; + +export default { + register: (userName: string, password: string) => request({ + url: '/user/register', + body: { userName, password }, + }), + login: (userAccount: string, password: string) => request({ + url: '/user/login', + body: { userAccount, password }, + }), + createRoom: () => request({ + url: '/game/room', + body: { }, + }), + buyIn: (buyInSize: number) => request({ + url: '/game/buyIn', + body: { buyInSize }, + }), +}; diff --git a/client/src/utils/request.ts b/client/src/utils/request.ts index 9b44892..bc067ca 100644 --- a/client/src/utils/request.ts +++ b/client/src/utils/request.ts @@ -1,26 +1,33 @@ -import axios, { AxiosRequestConfig, Method } from 'axios'; -import cookie from 'js-cookie'; -const request = async ({ method = 'post' as Method, url = '', body= {}, timeout = 8000 }) => { - const origin = ''; - if (!url) { - return Promise.reject('Request url is null!'); - } - const token = cookie.get('game_token'); - const headers = { - Authorization: `Bearer ${token}`, - }; - url = `${origin}/${url}`; - const option: AxiosRequestConfig = { - url, - method, - timeout, - withCredentials: true, - headers, - }; - try { - return await axios(option); - } catch (e) { - throw e; - } -}; -export default request; +import axios, {AxiosRequestConfig, Method} from 'axios'; +import cookie from 'js-cookie'; + +const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => { + const origin = 'http://127.0.0.1:7001/node'; + if (!url) { + return Promise.reject('Request url is null!'); + } + const token = cookie.get('token'); + const headers = { + Authorization: `Bearer ${token}`, + }; + url = `${origin}${url}`; + const option: AxiosRequestConfig = { + url, + method, + timeout, + data: body, + withCredentials: true, + headers, + }; + try { + const result = await axios(option); + if (result.data.code === '000000') { + return result.data; + } else { + throw result.data; + } + } catch (e) { + throw e; + } +}; +export default request; diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index 44aab74..d7b50fe 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -1,16 +1,49 @@ - - - + + + + diff --git a/client/src/views/game.vue b/client/src/views/game.vue index 166abbd..8a19c77 100644 --- a/client/src/views/game.vue +++ b/client/src/views/game.vue @@ -1,22 +1,119 @@ - - - - - - + + + + + diff --git a/client/src/views/login.vue b/client/src/views/login.vue index 0e75719..6f56afe 100644 --- a/client/src/views/login.vue +++ b/client/src/views/login.vue @@ -1,20 +1,53 @@ - - + + + diff --git a/client/src/views/register.vue b/client/src/views/register.vue index ae83f05..9231f27 100644 --- a/client/src/views/register.vue +++ b/client/src/views/register.vue @@ -1,35 +1,53 @@ - - - + + + diff --git a/client/tslint.json b/client/tslint.json index cf0b84e..574fd5a 100644 --- a/client/tslint.json +++ b/client/tslint.json @@ -10,6 +10,7 @@ "no-consecutive-blank-lines": false, "object-literal-sort-keys": false, "ordered-imports": false, + "no-console": false, "quotemark": [true, "single"] } } diff --git a/client/yarn.lock b/client/yarn.lock index 3a25dcf..fbfd19f 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -908,6 +908,11 @@ resolved "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz#690a1475b84f2a884fd07cd797c00f5f31356ea8" integrity sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw== +"@types/socket.io-client@^1.4.32": + version "1.4.32" + resolved "https://registry.npmjs.org/@types/socket.io-client/-/socket.io-client-1.4.32.tgz#988a65a0386c274b1c22a55377fab6a30789ac14" + integrity sha512-Vs55Kq8F+OWvy1RLA31rT+cAyemzgm0EWNeax6BWF8H7QiiOYMJIdcwSDdm5LVgfEkoepsWkS+40+WNb7BUMbg== + "@types/webpack-env@^1.15.1": version "1.15.1" resolved "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.15.1.tgz#c8e84705e08eed430b5e15b39c65b0944e4d1422" @@ -1329,6 +1334,11 @@ address@^1.1.2: resolved "https://registry.npm.taobao.org/address/download/address-1.1.2.tgz#bf1116c9c758c51b7a933d296b72c221ed9428b6" integrity sha1-vxEWycdYxRt6kz0pa3LCIe2UKLY= +after@0.8.2: + version "0.8.2" + resolved "https://registry.npm.taobao.org/after/download/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f" + integrity sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8= + aggregate-error@^3.0.0: version "3.0.1" resolved "https://registry.npm.taobao.org/aggregate-error/download/aggregate-error-3.0.1.tgz#db2fe7246e536f40d9b5442a39e117d7dd6a24e0" @@ -1492,6 +1502,11 @@ array-unique@^0.3.2: resolved "https://registry.npm.taobao.org/array-unique/download/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" integrity sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg= +arraybuffer.slice@~0.0.7: + version "0.0.7" + resolved "https://registry.npm.taobao.org/arraybuffer.slice/download/arraybuffer.slice-0.0.7.tgz#3bbc4275dd584cc1b10809b89d4e8b63a69e7675" + integrity sha1-O7xCdd1YTMGxCAm4nU6LY6aednU= + asap@~2.0.3: version "2.0.6" resolved "https://registry.npm.taobao.org/asap/download/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46" @@ -1615,11 +1630,21 @@ babel-plugin-dynamic-import-node@^2.3.0: dependencies: object.assign "^4.1.0" +backo2@1.0.2: + version "1.0.2" + resolved "https://registry.npm.taobao.org/backo2/download/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" + integrity sha1-MasayLEpNjRj41s+u2n038+6eUc= + balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.npm.taobao.org/balanced-match/download/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= +base64-arraybuffer@0.1.5: + version "0.1.5" + resolved "https://registry.npm.taobao.org/base64-arraybuffer/download/base64-arraybuffer-0.1.5.tgz#73926771923b5a19747ad666aa5cd4bf9c6e9ce8" + integrity sha1-c5JncZI7Whl0etZmqlzUv5xunOg= + base64-js@^1.0.2: version "1.3.1" resolved "https://registry.npm.taobao.org/base64-js/download/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1" @@ -1650,6 +1675,13 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" +better-assert@~1.0.0: + version "1.0.2" + resolved "https://registry.npm.taobao.org/better-assert/download/better-assert-1.0.2.tgz#40866b9e1b9e0b55b481894311e68faffaebc522" + integrity sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI= + dependencies: + callsite "1.0.0" + bfj@^6.1.1: version "6.1.2" resolved "https://registry.npm.taobao.org/bfj/download/bfj-6.1.2.tgz#325c861a822bcb358a41c78a33b8e6e2086dde7f" @@ -1687,6 +1719,11 @@ bindings@^1.5.0: dependencies: file-uri-to-path "1.0.0" +blob@0.0.5: + version "0.0.5" + resolved "https://registry.npm.taobao.org/blob/download/blob-0.0.5.tgz?cache=0&sync_timestamp=1580722883513&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fblob%2Fdownload%2Fblob-0.0.5.tgz#d680eeef25f8cd91ad533f5b01eed48e64caf683" + integrity sha1-1oDu7yX4zZGtUz9bAe7UjmTK9oM= + bluebird@^3.1.1, bluebird@^3.5.5: version "3.7.2" resolved "https://registry.npm.taobao.org/bluebird/download/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" @@ -1975,6 +2012,11 @@ caller-path@^2.0.0: dependencies: caller-callsite "^2.0.0" +callsite@1.0.0: + version "1.0.0" + resolved "https://registry.npm.taobao.org/callsite/download/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20" + integrity sha1-KAOY5dZkvXQDi28JBRU+borxvCA= + callsites@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/callsites/download/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50" @@ -2282,11 +2324,26 @@ commondir@^1.0.1: resolved "https://registry.npm.taobao.org/commondir/download/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs= +component-bind@1.0.0: + version "1.0.0" + resolved "https://registry.npm.taobao.org/component-bind/download/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1" + integrity sha1-AMYIq33Nk4l8AAllGx06jh5zu9E= + +component-emitter@1.2.1: + version "1.2.1" + resolved "https://registry.npm.taobao.org/component-emitter/download/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" + integrity sha1-E3kY1teCg/ffemt8WmPhQOaUJeY= + component-emitter@^1.2.1: version "1.3.0" resolved "https://registry.npm.taobao.org/component-emitter/download/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0" integrity sha1-FuQHD7qK4ptnnyIVhT7hgasuq8A= +component-inherit@0.0.3: + version "0.0.3" + resolved "https://registry.npm.taobao.org/component-inherit/download/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143" + integrity sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM= + compressible@~2.0.16: version "2.0.18" resolved "https://registry.npm.taobao.org/compressible/download/compressible-2.0.18.tgz?cache=0&sync_timestamp=1578286264482&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcompressible%2Fdownload%2Fcompressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba" @@ -2700,7 +2757,7 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3: dependencies: ms "2.0.0" -debug@=3.1.0: +debug@=3.1.0, debug@~3.1.0: version "3.1.0" resolved "https://registry.npm.taobao.org/debug/download/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" integrity sha1-W7WgZyYotkFJVmuhaBnmFRjGcmE= @@ -2714,7 +2771,7 @@ debug@^3.0.0, debug@^3.1.1, debug@^3.2.5: dependencies: ms "^2.1.1" -debug@^4.1.0, debug@^4.1.1: +debug@^4.1.0, debug@^4.1.1, debug@~4.1.0: version "4.1.1" resolved "https://registry.npm.taobao.org/debug/download/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" integrity sha1-O3ImAlUQnGtYnO4FDx1RYTlmR5E= @@ -3034,6 +3091,34 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0: dependencies: once "^1.4.0" +engine.io-client@~3.4.0: + version "3.4.0" + resolved "https://registry.npm.taobao.org/engine.io-client/download/engine.io-client-3.4.0.tgz#82a642b42862a9b3f7a188f41776b2deab643700" + integrity sha1-gqZCtChiqbP3oYj0F3ay3qtkNwA= + dependencies: + component-emitter "1.2.1" + component-inherit "0.0.3" + debug "~4.1.0" + engine.io-parser "~2.2.0" + has-cors "1.1.0" + indexof "0.0.1" + parseqs "0.0.5" + parseuri "0.0.5" + ws "~6.1.0" + xmlhttprequest-ssl "~1.5.4" + yeast "0.1.2" + +engine.io-parser@~2.2.0: + version "2.2.0" + resolved "https://registry.npm.taobao.org/engine.io-parser/download/engine.io-parser-2.2.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fengine.io-parser%2Fdownload%2Fengine.io-parser-2.2.0.tgz#312c4894f57d52a02b420868da7b5c1c84af80ed" + integrity sha1-MSxIlPV9UqArQgho2ntcHISvgO0= + dependencies: + after "0.8.2" + arraybuffer.slice "~0.0.7" + base64-arraybuffer "0.1.5" + blob "0.0.5" + has-binary2 "~1.0.2" + enhanced-resolve@^4.0.0, enhanced-resolve@^4.1.0: version "4.1.1" resolved "https://registry.npm.taobao.org/enhanced-resolve/download/enhanced-resolve-4.1.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fenhanced-resolve%2Fdownload%2Fenhanced-resolve-4.1.1.tgz#2937e2b8066cd0fe7ce0990a98f0d71a35189f66" @@ -3726,6 +3811,18 @@ has-ansi@^2.0.0: dependencies: ansi-regex "^2.0.0" +has-binary2@~1.0.2: + version "1.0.3" + resolved "https://registry.npm.taobao.org/has-binary2/download/has-binary2-1.0.3.tgz#7776ac627f3ea77250cfc332dab7ddf5e4f5d11d" + integrity sha1-d3asYn8+p3JQz8My2rfd9eT10R0= + dependencies: + isarray "2.0.1" + +has-cors@1.1.0: + version "1.1.0" + resolved "https://registry.npm.taobao.org/has-cors/download/has-cors-1.1.0.tgz#5e474793f7ea9843d1bb99c23eef49ff126fff39" + integrity sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk= + has-flag@^3.0.0: version "3.0.0" resolved "https://registry.npm.taobao.org/has-flag/download/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" @@ -4076,6 +4173,11 @@ indexes-of@^1.0.1: resolved "https://registry.npm.taobao.org/indexes-of/download/indexes-of-1.0.1.tgz#f30f716c8e2bd346c7b67d3df3915566a7c05607" integrity sha1-8w9xbI4r00bHtn0985FVZqfAVgc= +indexof@0.0.1: + version "0.0.1" + resolved "https://registry.npm.taobao.org/indexof/download/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" + integrity sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10= + infer-owner@^1.0.3, infer-owner@^1.0.4: version "1.0.4" resolved "https://registry.npm.taobao.org/infer-owner/download/infer-owner-1.0.4.tgz#c4cefcaa8e51051c2a40ba2ce8a3d27295af9467" @@ -4420,6 +4522,11 @@ isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0: resolved "https://registry.npm.taobao.org/isarray/download/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= +isarray@2.0.1: + version "2.0.1" + resolved "https://registry.npm.taobao.org/isarray/download/isarray-2.0.1.tgz#a37d94ed9cda2d59865c9f76fe596ee1f338741e" + integrity sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4= + isexe@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/isexe/download/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" @@ -5283,6 +5390,11 @@ object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1: resolved "https://registry.npm.taobao.org/object-assign/download/object-assign-4.1.1.tgz?cache=0&sync_timestamp=1571657171505&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fobject-assign%2Fdownload%2Fobject-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= +object-component@0.0.3: + version "0.0.3" + resolved "https://registry.npm.taobao.org/object-component/download/object-component-0.0.3.tgz#f0c69aa50efc95b866c186f400a33769cb2f1291" + integrity sha1-8MaapQ78lbhmwYb0AKM3acsvEpE= + object-copy@^0.1.0: version "0.1.0" resolved "https://registry.npm.taobao.org/object-copy/download/object-copy-0.1.0.tgz#7e7d858b781bd7c991a41ba975ed3812754e998c" @@ -5586,6 +5698,20 @@ parse5@^5.1.1: resolved "https://registry.npm.taobao.org/parse5/download/parse5-5.1.1.tgz#f68e4e5ba1852ac2cadc00f4555fff6c2abb6178" integrity sha1-9o5OW6GFKsLK3AD0VV//bCq7YXg= +parseqs@0.0.5: + version "0.0.5" + resolved "https://registry.npm.taobao.org/parseqs/download/parseqs-0.0.5.tgz#d5208a3738e46766e291ba2ea173684921a8b89d" + integrity sha1-1SCKNzjkZ2bikbouoXNoSSGouJ0= + dependencies: + better-assert "~1.0.0" + +parseuri@0.0.5: + version "0.0.5" + resolved "https://registry.npm.taobao.org/parseuri/download/parseuri-0.0.5.tgz#80204a50d4dbb779bfdc6ebe2778d90e4bce320a" + integrity sha1-gCBKUNTbt3m/3G6+J3jZDkvOMgo= + dependencies: + better-assert "~1.0.0" + parseurl@~1.3.2, parseurl@~1.3.3: version "1.3.3" resolved "https://registry.npm.taobao.org/parseurl/download/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4" @@ -6783,6 +6909,35 @@ snapdragon@^0.8.1: source-map-resolve "^0.5.0" use "^3.1.0" +socket.io-client@^2.3.0: + version "2.3.0" + resolved "https://registry.npm.taobao.org/socket.io-client/download/socket.io-client-2.3.0.tgz#14d5ba2e00b9bcd145ae443ab96b3f86cbcc1bb4" + integrity sha1-FNW6LgC5vNFFrkQ6uWs/hsvMG7Q= + dependencies: + backo2 "1.0.2" + base64-arraybuffer "0.1.5" + component-bind "1.0.0" + component-emitter "1.2.1" + debug "~4.1.0" + engine.io-client "~3.4.0" + has-binary2 "~1.0.2" + has-cors "1.1.0" + indexof "0.0.1" + object-component "0.0.3" + parseqs "0.0.5" + parseuri "0.0.5" + socket.io-parser "~3.3.0" + to-array "0.1.4" + +socket.io-parser@~3.3.0: + version "3.3.0" + resolved "https://registry.npm.taobao.org/socket.io-parser/download/socket.io-parser-3.3.0.tgz#2b52a96a509fdf31440ba40fed6094c7d4f1262f" + integrity sha1-K1KpalCf3zFEC6QP7WCUx9TxJi8= + dependencies: + component-emitter "1.2.1" + debug "~3.1.0" + isarray "2.0.1" + sockjs-client@1.4.0: version "1.4.0" resolved "https://registry.npm.taobao.org/sockjs-client/download/sockjs-client-1.4.0.tgz#c9f2568e19c8fd8173b4997ea3420e0bb306c7d5" @@ -7273,6 +7428,11 @@ timsort@^0.3.0: resolved "https://registry.npm.taobao.org/timsort/download/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4" integrity sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q= +to-array@0.1.4: + version "0.1.4" + resolved "https://registry.npm.taobao.org/to-array/download/to-array-0.1.4.tgz#17e6c11f73dd4f3d74cda7a4ff3238e9ad9bf890" + integrity sha1-F+bBH3PdTz10zaek/zI46a2b+JA= + to-arraybuffer@^1.0.0: version "1.0.1" resolved "https://registry.npm.taobao.org/to-arraybuffer/download/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43" @@ -7941,6 +8101,18 @@ ws@^6.0.0, ws@^6.2.1: dependencies: async-limiter "~1.0.0" +ws@~6.1.0: + version "6.1.4" + resolved "https://registry.npm.taobao.org/ws/download/ws-6.1.4.tgz#5b5c8800afab925e94ccb29d153c8d02c1776ef9" + integrity sha1-W1yIAK+rkl6UzLKdFTyNAsF3bvk= + dependencies: + async-limiter "~1.0.0" + +xmlhttprequest-ssl@~1.5.4: + version "1.5.5" + resolved "https://registry.npm.taobao.org/xmlhttprequest-ssl/download/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e" + integrity sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4= + xtend@^4.0.0, xtend@~4.0.1: version "4.0.2" resolved "https://registry.npm.taobao.org/xtend/download/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54" @@ -8017,6 +8189,11 @@ yargs@^15.0.0: y18n "^4.0.0" yargs-parser "^18.1.1" +yeast@0.1.2: + version "0.1.2" + resolved "https://registry.npm.taobao.org/yeast/download/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" + integrity sha1-AI4G2AlDIMNy28L47XagymyKxBk= + yorkie@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/yorkie/download/yorkie-2.0.0.tgz#92411912d435214e12c51c2ae1093e54b6bb83d9" diff --git a/database/comand_record.sql b/database/comand_record.sql new file mode 100644 index 0000000..73df8b8 --- /dev/null +++ b/database/comand_record.sql @@ -0,0 +1,41 @@ +/* +Navicat MySQL Data Transfer + +Source Server : test +Source Server Version : 50077 +Source Host : localhost:3306 +Source Database : poker + +Target Server Type : MYSQL +Target Server Version : 50077 +File Encoding : 65001 + +Date: 2020-04-17 23:05:30 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for comand_record +-- ---------------------------- +DROP TABLE IF EXISTS `comand_record`; +CREATE TABLE `comand_record` ( + `id` int(11) NOT NULL auto_increment, + `user_id` int(11) default NULL, + `game_id` int(11) default NULL, + `type` text, + `comand` text, + `room_id` int(11) default NULL, + `create_time` timestamp NOT NULL default CURRENT_TIMESTAMP, + `update_time` datetime default NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- ---------------------------- +-- Records of comand_record +-- ---------------------------- +DROP TRIGGER IF EXISTS `update_comand_record_time`; +DELIMITER ;; +CREATE TRIGGER `update_comand_record_time` BEFORE UPDATE ON `comand_record` FOR EACH ROW SET NEW.`UPDATE_TIME` = NOW() +;; +DELIMITER ; diff --git a/database/game.sql b/database/game.sql new file mode 100644 index 0000000..1adc228 --- /dev/null +++ b/database/game.sql @@ -0,0 +1,41 @@ +/* +Navicat MySQL Data Transfer + +Source Server : test +Source Server Version : 50077 +Source Host : localhost:3306 +Source Database : poker + +Target Server Type : MYSQL +Target Server Version : 50077 +File Encoding : 65001 + +Date: 2020-04-17 23:05:17 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for game +-- ---------------------------- +DROP TABLE IF EXISTS `game`; +CREATE TABLE `game` ( + `id` int(11) NOT NULL auto_increment, + `room_id` int(11) default NULL, + `status` int(11) default NULL, + `common_card` text, + `winners` varchar(255) default NULL, + `pot` decimal(8,0) default NULL, + `create_time` timestamp NOT NULL default CURRENT_TIMESTAMP, + `update_time` datetime default NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- ---------------------------- +-- Records of game +-- ---------------------------- +DROP TRIGGER IF EXISTS `update_game_time`; +DELIMITER ;; +CREATE TRIGGER `update_game_time` BEFORE UPDATE ON `game` FOR EACH ROW SET NEW.`UPDATE_TIME` = NOW() +;; +DELIMITER ; diff --git a/database/game_record.sql b/database/game_record.sql new file mode 100644 index 0000000..23deeac --- /dev/null +++ b/database/game_record.sql @@ -0,0 +1,41 @@ +/* +Navicat MySQL Data Transfer + +Source Server : test +Source Server Version : 50077 +Source Host : localhost:3306 +Source Database : poker + +Target Server Type : MYSQL +Target Server Version : 50077 +File Encoding : 65001 + +Date: 2020-04-17 23:05:40 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for game_record +-- ---------------------------- +DROP TABLE IF EXISTS `game_record`; +CREATE TABLE `game_record` ( + `id` int(11) NOT NULL auto_increment, + `game_id` int(11) default NULL, + `room_number` int(11) default NULL, + `buy_in` int(11) NOT NULL, + `hand_card` varchar(25) default NULL, + `user_id` int(11) default NULL, + `create_time` timestamp NOT NULL default CURRENT_TIMESTAMP, + `update_time` datetime default NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- ---------------------------- +-- Records of game_record +-- ---------------------------- +DROP TRIGGER IF EXISTS `update_game_record_time`; +DELIMITER ;; +CREATE TRIGGER `update_game_record_time` BEFORE UPDATE ON `game_record` FOR EACH ROW SET NEW.`UPDATE_TIME` = NOW() +;; +DELIMITER ; diff --git a/database/room.sql b/database/room.sql new file mode 100644 index 0000000..5c42d0b --- /dev/null +++ b/database/room.sql @@ -0,0 +1,52 @@ +/* +Navicat MySQL Data Transfer + +Source Server : test +Source Server Version : 50077 +Source Host : localhost:3306 +Source Database : poker + +Target Server Type : MYSQL +Target Server Version : 50077 +File Encoding : 65001 + +Date: 2020-04-17 23:05:49 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for room +-- ---------------------------- +DROP TABLE IF EXISTS `room`; +CREATE TABLE `room` ( + `id` int(11) NOT NULL auto_increment, + `room_number` text, + `create_time` timestamp NOT NULL default CURRENT_TIMESTAMP, + `update_time` datetime default NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1; + +-- ---------------------------- +-- Records of room +-- ---------------------------- +INSERT INTO `room` VALUES ('1', '522687', '2020-04-01 15:33:32', null); +INSERT INTO `room` VALUES ('2', '145519', '2020-04-01 16:58:53', null); +INSERT INTO `room` VALUES ('3', '354507', '2020-04-01 17:35:32', null); +INSERT INTO `room` VALUES ('4', '973599', '2020-04-02 17:09:52', null); +INSERT INTO `room` VALUES ('5', '338302', '2020-04-02 17:12:39', null); +INSERT INTO `room` VALUES ('6', '739937', '2020-04-16 16:33:43', null); +INSERT INTO `room` VALUES ('7', '604560', '2020-04-16 16:35:35', null); +INSERT INTO `room` VALUES ('8', '205826', '2020-04-17 09:57:41', null); +INSERT INTO `room` VALUES ('9', '507003', '2020-04-17 13:51:25', null); +INSERT INTO `room` VALUES ('10', '633228', '2020-04-17 13:55:04', null); +INSERT INTO `room` VALUES ('11', '719376', '2020-04-17 15:06:55', null); +INSERT INTO `room` VALUES ('12', '516433', '2020-04-17 16:08:29', null); +INSERT INTO `room` VALUES ('13', '991922', '2020-04-17 16:20:18', null); +INSERT INTO `room` VALUES ('14', '346124', '2020-04-17 16:20:52', null); +INSERT INTO `room` VALUES ('15', '261855', '2020-04-17 17:29:38', null); +DROP TRIGGER IF EXISTS `update_room_time`; +DELIMITER ;; +CREATE TRIGGER `update_room_time` BEFORE UPDATE ON `room` FOR EACH ROW SET NEW.`UPDATE_TIME` = NOW() +;; +DELIMITER ; diff --git a/database/user.sql b/database/user.sql new file mode 100644 index 0000000..b4c3cdc --- /dev/null +++ b/database/user.sql @@ -0,0 +1,42 @@ +/* +Navicat MySQL Data Transfer + +Source Server : test +Source Server Version : 50077 +Source Host : localhost:3306 +Source Database : poker + +Target Server Type : MYSQL +Target Server Version : 50077 +File Encoding : 65001 + +Date: 2020-04-17 23:05:58 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for user +-- ---------------------------- +DROP TABLE IF EXISTS `user`; +CREATE TABLE `user` ( + `id` int(11) NOT NULL auto_increment, + `nick_name` char(25) character set utf8 default NULL, + `password` char(25) default NULL, + `account` char(25) default NULL, + `create_time` timestamp NOT NULL default CURRENT_TIMESTAMP, + `update_time` datetime default NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; + +-- ---------------------------- +-- Records of user +-- ---------------------------- +INSERT INTO `user` VALUES ('1', 'c', '123', 'cai', '2020-04-01 16:26:32', null); +INSERT INTO `user` VALUES ('2', '蔡', '123', 'cai111', '2020-04-01 16:28:17', null); +INSERT INTO `user` VALUES ('3', '蔡1', '123', 'cai11', '2020-04-01 16:29:43', null); +DROP TRIGGER IF EXISTS `update_user_time`; +DELIMITER ;; +CREATE TRIGGER `update_user_time` BEFORE UPDATE ON `user` FOR EACH ROW SET NEW.`UPDATE_TIME` = NOW() +;; +DELIMITER ; diff --git a/server/README.md b/server/README.md old mode 100755 new mode 100644 diff --git a/server/appveyor.yml b/server/appveyor.yml old mode 100755 new mode 100644 diff --git a/server/package.json b/server/package.json old mode 100755 new mode 100644 diff --git a/server/src/app.ts b/server/src/app.ts old mode 100755 new mode 100644 diff --git a/server/src/app/controller/account.ts b/server/src/app/controller/account.ts old mode 100755 new mode 100644 index 6a82734..ddf6cc9 --- a/server/src/app/controller/account.ts +++ b/server/src/app/controller/account.ts @@ -14,7 +14,9 @@ export class Account extends BaseController { async login() { try { const { body } = this.getRequestBody(); + console.log(body, 'body'); const { userAccount, password } = body; + console.log(userAccount, 'userAccount'); const accountInfo: IAccountInfo = { userAccount, password }; const result = await this.service.login(accountInfo); this.success(result); diff --git a/server/src/app/controller/game.ts b/server/src/app/controller/game.ts new file mode 100644 index 0000000..0c2ad25 --- /dev/null +++ b/server/src/app/controller/game.ts @@ -0,0 +1,27 @@ +import { Context, inject, controller, post, provide } from 'midway'; +import BaseController from '../../lib/baseController'; +import { IRoomService } from '../../interface/IRoom'; + +@provide() +@controller('/node/game') +export class GameController extends BaseController { + + @inject() + ctx: Context; + + @inject('GameService') + gameService: IGameService; + /** + * + */ + @post('/buyIn') + async buyIn() { + try { + const result = await this.gameService.add(); + this.success(result); + } catch (e) { + this.fail('create room error'); + console.log(e); + } + } +} diff --git a/server/src/app/controller/room.ts b/server/src/app/controller/room.ts old mode 100755 new mode 100644 diff --git a/server/src/app/controller/user.ts b/server/src/app/controller/user.ts old mode 100755 new mode 100644 diff --git a/server/src/app/core/Player.ts b/server/src/app/core/Player.ts old mode 100755 new mode 100644 diff --git a/server/src/app/core/Poker.ts b/server/src/app/core/Poker.ts old mode 100755 new mode 100644 diff --git a/server/src/app/core/PokerGame.ts b/server/src/app/core/PokerGame.ts old mode 100755 new mode 100644 diff --git a/server/src/app/core/PokerStyle.ts b/server/src/app/core/PokerStyle.ts old mode 100755 new mode 100644 diff --git a/server/src/app/extend/context.ts b/server/src/app/extend/context.ts old mode 100755 new mode 100644 diff --git a/server/src/app/extend/helper.ts b/server/src/app/extend/helper.ts old mode 100755 new mode 100644 diff --git a/server/src/app/helper/logTransport.ts b/server/src/app/helper/logTransport.ts old mode 100755 new mode 100644 diff --git a/server/src/app/helper/parseMsg.ts b/server/src/app/helper/parseMsg.ts old mode 100755 new mode 100644 diff --git a/server/src/app/io/controller/game.ts b/server/src/app/io/controller/game.ts old mode 100755 new mode 100644 diff --git a/server/src/app/io/controller/nsp.ts b/server/src/app/io/controller/nsp.ts old mode 100755 new mode 100644 diff --git a/server/src/app/io/middleware/auth.ts b/server/src/app/io/middleware/auth.ts old mode 100755 new mode 100644 index 0eb91ba..160342d --- a/server/src/app/io/middleware/auth.ts +++ b/server/src/app/io/middleware/auth.ts @@ -10,7 +10,11 @@ export default function auth(): any { const roomService = await app.applicationContext.getAsync('RoomService'); const query = socket.handshake.query; // 用户信息 - const { room, userName } = query; + const { room, token } = query; + + const userInfo = app.jwt.verify(token); + + const { userName } = userInfo; // 检查房间是否存在,不存在则踢出用户 // 备注:此处 app.redis 与插件无关,可用其他存储代替 diff --git a/server/src/app/middleware/elkLogger.ts b/server/src/app/middleware/elkLogger.ts old mode 100755 new mode 100644 diff --git a/server/src/app/middleware/notFound.ts b/server/src/app/middleware/notFound.ts old mode 100755 new mode 100644 diff --git a/server/src/app/public/README.md b/server/src/app/public/README.md old mode 100755 new mode 100644 diff --git a/server/src/app/router.ts b/server/src/app/router.ts old mode 100755 new mode 100644 diff --git a/server/src/config/config.default.ts b/server/src/config/config.default.ts old mode 100755 new mode 100644 index fbc2d6a..6186765 --- a/server/src/config/config.default.ts +++ b/server/src/config/config.default.ts @@ -39,8 +39,9 @@ export default (appInfo: EggAppInfo) => { credentials: true, origin(ctx: Context) { const origin: string = ctx.get('origin'); + console.log(origin, 'orgin'); // 允许*域名访问 - if (origin.indexOf('172.22.88.118') > -1) { + if (origin.indexOf('http://172.22.72.70:8080') > -1) { console.log('come in'); return origin; } else { diff --git a/server/src/config/config.local.ts b/server/src/config/config.local.ts old mode 100755 new mode 100644 diff --git a/server/src/config/config.prod.ts b/server/src/config/config.prod.ts old mode 100755 new mode 100644 diff --git a/server/src/config/config.test.ts b/server/src/config/config.test.ts old mode 100755 new mode 100644 diff --git a/server/src/config/plugin.ts b/server/src/config/plugin.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/IAccountInfo.ts b/server/src/interface/IAccountInfo.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/IAccountService.ts b/server/src/interface/IAccountService.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/ICommandRecord.ts b/server/src/interface/ICommandRecord.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/IFetchOptions.ts b/server/src/interface/IFetchOptions.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/IGame.ts b/server/src/interface/IGame.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/IGameRecord.ts b/server/src/interface/IGameRecord.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/ILoginResult.ts b/server/src/interface/ILoginResult.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/IRequestBody.ts b/server/src/interface/IRequestBody.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/IResult.ts b/server/src/interface/IResult.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/IRoom.ts b/server/src/interface/IRoom.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/ITickMsg.ts b/server/src/interface/ITickMsg.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/IUser.ts b/server/src/interface/IUser.ts old mode 100755 new mode 100644 index 3a1a64c..82a797e --- a/server/src/interface/IUser.ts +++ b/server/src/interface/IUser.ts @@ -1,5 +1,5 @@ export interface IUser { - nickName: string; + nick_name: string; account: string; password?: string; } diff --git a/server/src/interface/IUserService.ts b/server/src/interface/IUserService.ts old mode 100755 new mode 100644 diff --git a/server/src/interface/Ilog.ts b/server/src/interface/Ilog.ts old mode 100755 new mode 100644 diff --git a/server/src/lib/baseController.ts b/server/src/lib/baseController.ts old mode 100755 new mode 100644 index 4484430..88fea70 --- a/server/src/lib/baseController.ts +++ b/server/src/lib/baseController.ts @@ -1,5 +1,5 @@ import { inject, Context } from 'midway'; -import { IRequestBody } from '../interface/IRequestBody'; +// import { IRequestBody } from '../interface/IRequestBody'; import { IResult, ResultCode } from '../interface/IResult'; export default class BaseController { @@ -11,11 +11,11 @@ export default class BaseController { * 获取请求内容 * @returns {IRequestBody} */ - public getRequestBody(): IRequestBody { - let params: IRequestBody; - params = this.ctx.request.body.params && JSON.parse(this.ctx.request.body.params) || {}; - console.log(this.ctx.request.body, 'params'); - return params; + public getRequestBody() { + // let params: IRequestBody; + // params = this.ctx.request.body.params && JSON.parse(this.ctx.request.body.params) || {}; + // console.log(this.ctx.request.body, 'params'); + return this.ctx.request; } /** diff --git a/server/src/lib/baseService.ts b/server/src/lib/baseService.ts old mode 100755 new mode 100644 diff --git a/server/src/service/account.ts b/server/src/service/account.ts old mode 100755 new mode 100644 index 36f86e0..bc1fc74 --- a/server/src/service/account.ts +++ b/server/src/service/account.ts @@ -71,8 +71,10 @@ export class AccountService extends BaseService implements IAccountService { return await this.user.findByAccount(userAccount); } - private getToken(userAccount: string) { - const token = this.jwt.sign({ userAccount }, + private async getToken(userAccount: string) { + const user = await this.user.findByAccount(userAccount); + console.log(user, 'user----------'); + const token = this.jwt.sign({ userName: user.nick_name }, this.jwtConfig.secret, { expiresIn: 60 * 60 }); this.ctx.logger.info(`AccountService getToken token--${token}`); return token; diff --git a/server/src/service/room.ts b/server/src/service/room.ts old mode 100755 new mode 100644 diff --git a/server/src/service/user.ts b/server/src/service/user.ts old mode 100755 new mode 100644 diff --git a/server/src/utils/Link.ts b/server/src/utils/Link.ts old mode 100755 new mode 100644 diff --git a/server/test/app/core/pokerGame.test.ts b/server/test/app/core/pokerGame.test.ts old mode 100755 new mode 100644 diff --git a/server/test/app/core/pokerStyle.test.ts b/server/test/app/core/pokerStyle.test.ts old mode 100755 new mode 100644 diff --git a/server/test/utils/link.test.ts b/server/test/utils/link.test.ts old mode 100755 new mode 100644 diff --git a/server/tsconfig.json b/server/tsconfig.json old mode 100755 new mode 100644 diff --git a/server/tslint.json b/server/tslint.json old mode 100755 new mode 100644 diff --git a/server/yarn.lock b/server/yarn.lock old mode 100755 new mode 100644