From 7e81a76195ce1494d0ff7881061c4bc921188f9d Mon Sep 17 00:00:00 2001 From: wzdwc Date: Tue, 21 Apr 2020 23:45:18 +0800 Subject: [PATCH] programing player action --- client/src/App.vue | 135 +++++++++--------- client/src/main.ts | 32 ++--- client/src/utils/request.ts | 1 + client/src/views/game.vue | 88 +++++++++++- client/src/views/login.vue | 104 +++++++------- server/logs/ELKLog/error.log | 2 + server/logs/ELKLog/info.log | 9 ++ server/logs/game-node-center/agent.log | 31 ++++ server/logs/game-node-center/app.log | 41 ++++++ server/logs/game-node-center/core.log | 85 +++++++++++ server/logs/game-node-center/egg-schedule.log | 21 +++ server/logs/game-node-center/error.log | 2 + server/src/app/core/Player.ts | 4 +- server/src/app/core/PokerGame.ts | 2 +- server/src/app/io/controller/game.ts | 59 ++++++-- server/src/app/io/middleware/join.ts | 12 +- server/src/app/router.ts | 1 + server/test/app/core/pokerGame.test.ts | 76 +++++----- server/test/utils/link.test.ts | 8 +- 19 files changed, 504 insertions(+), 209 deletions(-) diff --git a/client/src/App.vue b/client/src/App.vue index 3a4b569..7797306 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -1,67 +1,68 @@ - - - - - + + + + + diff --git a/client/src/main.ts b/client/src/main.ts index b7c7637..9fa3a90 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -1,16 +1,16 @@ -import Vue from 'vue'; -import App from './App.vue'; -import router from './router'; -import store from './store'; -import VConsole from 'vconsole'; - -Vue.config.productionTip = false; - -// tslint:disable-next-line:no-unused-expression -new VConsole(); - -new Vue({ - router, - store, - render: (h) => h(App), -}).$mount('#app'); +import Vue from 'vue'; +import App from './App.vue'; +import router from './router'; +import store from './store'; +import VConsole from 'vconsole'; + +Vue.config.productionTip = false; + +// tslint:disable-next-line:no-unused-expression +new VConsole(); + +new Vue({ + router, + store, + render: (h) => h(App), +}).$mount('#app'); diff --git a/client/src/utils/request.ts b/client/src/utils/request.ts index f771476..9baecf2 100644 --- a/client/src/utils/request.ts +++ b/client/src/utils/request.ts @@ -3,6 +3,7 @@ import cookie from 'js-cookie'; const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => { const origin = 'http://192.168.0.105:7001/node'; + // const origin = 'http://172.22.72.70:7001/node'; if (!url) { return Promise.reject('Request url is null!'); } diff --git a/client/src/views/game.vue b/client/src/views/game.vue index dca4160..83dd9a8 100644 --- a/client/src/views/game.vue +++ b/client/src/views/game.vue @@ -9,8 +9,26 @@
+
pot: {{pot}}
commonCard:{{commonCardString}}
handCard:{{handCardString}}
+
+
+ check + fold + call + raise +
+
+ 1/3 pot + 1/2 pot + 3/4 pot + 1 pot + 2 pot + 3 pot + allin +
+
play game
@@ -36,23 +54,39 @@ interface IUser { counter: number; nick_name: string; + actionSize: number; + type: string; + userId?: number; + } + + export enum ECommand { + CALL = 'call', + ALL_IN = 'allin', + RAISE = 'raise', + CHECK = 'check', + FOLD = 'fold', } interface IMsg { action: string; clients: string[]; target: string; - message: string; + data: any; } @Component export default class Game extends Vue { public socket: any = null; private users: IUser[] = []; + private userInfo: any = {}; private joinMsg = ''; private handCard = []; private commonCard = []; private buyInSize = 0; + private pot = 0; + private prevSize = 0; + private isAction = false; + private isRaise = false; get roomId() { return this.$route.params.roomNumber; @@ -78,10 +112,26 @@ }); } + private raise(size: number) { + if (size === -1) { + size = this.userInfo.counter; + } + this.emit('action', { command: `raise:${size}` }); + } + + private action(type: string) { + this.isAction = false; + if (type === ECommand.RAISE) { + this.isRaise = true; + } + } + private socketInit() { const token = cookie.get('token'); const log = console.log; - this.socket = io('http://192.168.0.105:7001/socket', { + // const origin = 'http://172.22.72.70:7001'; + const origin = 'http://192.168.0.105:7001'; + this.socket = io(`${origin}/socket`, { // 实际使用中可以在这里传递参数 query: { room: this.roomId, @@ -101,6 +151,9 @@ if (data.action === 'handCard') { this.handCard = data.payload.handCard; } + if (data.action === 'userInfo') { + this.userInfo = data.payload; + } }); }); @@ -108,15 +161,21 @@ this.socket.on('online', (msg: IMsg) => { log('#online,', msg); if (msg.action === 'join') { - this.joinMsg = msg.message; + this.joinMsg = msg.data; } if (msg.action === 'players') { - this.users = JSON.parse(msg.message); - console.log('users', JSON.parse(msg.message)); + this.users = msg.data.players; } if (msg.action === 'commonCard') { - this.commonCard = JSON.parse(msg.message); - console.log('users', JSON.parse(msg.message)); + this.commonCard = msg.data.commonCard; + console.log('users', msg.data); + } + if (msg.action === 'gameInfo') { + this.users = msg.data.players; + this.pot = msg.data.pot; + this.prevSize = msg.data.prevSize; + this.isAction = !!(this.userInfo && this.userInfo.userId === msg.data.currPlayer.userId); + console.log('gameInfo', msg.data); } }); @@ -167,5 +226,20 @@ diff --git a/client/src/views/login.vue b/client/src/views/login.vue index b9991c2..d42dbde 100644 --- a/client/src/views/login.vue +++ b/client/src/views/login.vue @@ -1,52 +1,52 @@ - - - + + + diff --git a/server/logs/ELKLog/error.log b/server/logs/ELKLog/error.log index a801e5b..5cf9071 100644 --- a/server/logs/ELKLog/error.log +++ b/server/logs/ELKLog/error.log @@ -1 +1,3 @@ {"pid":48633,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 00:28:45","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"ERROR","message":"room service tick","requestTime":"2020-04-21 00:28:45","stack":null,"status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} +{"pid":49495,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 23:04:55","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"ERROR","message":"room service tick","requestTime":"2020-04-21 23:04:55","stack":null,"status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} +{"pid":49588,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 23:40:05","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"ERROR","message":"game already paling","requestTime":"2020-04-21 23:40:05","status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} diff --git a/server/logs/ELKLog/info.log b/server/logs/ELKLog/info.log index a79e252..3ec5b33 100644 --- a/server/logs/ELKLog/info.log +++ b/server/logs/ELKLog/info.log @@ -15,3 +15,12 @@ {"pid":48621,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 00:24:44","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"INFO","message":"AccountService getToken token--eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6IuiUoSIsImFjY291bnQiOiJjYWkxMTEiLCJ1c2VySWQiOjJ9LCJpYXQiOjE1ODczOTk4ODQsImV4cCI6MTU4NzQyMTQ4NH0.CVCe19KN0vg_4m1-axLTR6pz7DQPRQkcOWvBN5mn6PE","requestTime":"2020-04-21 00:24:44","stack":"","status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} {"pid":48621,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 00:24:44","osUser":"root","osUid":0,"fetchConsumeTime":226,"level":"INFO","message":"POST /node/user/login info","requestTime":"2020-04-21 00:24:44","status":200,"total":null,"requestBody":{"userAccount":"cai111","password":"123"},"url":"/node/user/login"} {"pid":48633,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 00:28:45","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"ERROR","message":"room service tick","requestTime":"2020-04-21 00:28:45","stack":null,"status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} +{"pid":49450,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 22:52:33","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"INFO","message":"AccountService getToken token--eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6ImMiLCJhY2NvdW50IjoiY2FpIiwidXNlcklkIjoxfSwiaWF0IjoxNTg3NDgwNzUzLCJleHAiOjE1ODc1MDIzNTN9.KxxH7Eiw4toDFNZGwaHSALgEbfIPT8Qjw-7-Hp6XllU","requestTime":"2020-04-21 22:52:33","stack":"","status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} +{"pid":49450,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 22:52:33","osUser":"root","osUid":0,"fetchConsumeTime":217,"level":"INFO","message":"POST /node/user/login info","requestTime":"2020-04-21 22:52:33","status":200,"total":null,"requestBody":{"userAccount":"cai","password":"123"},"url":"/node/user/login"} +{"pid":49450,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 22:52:35","osUser":"root","osUid":0,"fetchConsumeTime":167,"level":"INFO","message":"POST /node/game/room info","requestTime":"2020-04-21 22:52:35","status":200,"total":null,"requestBody":{},"url":"/node/game/room"} +{"pid":49495,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 23:01:35","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"INFO","message":"AccountService getToken token--eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6IuiUoTEiLCJhY2NvdW50IjoiY2FpMTEiLCJ1c2VySWQiOjN9LCJpYXQiOjE1ODc0ODEyOTUsImV4cCI6MTU4NzUwMjg5NX0.04tWzzIEspNyYmtY-EzyesrnpVwD7zx-0zG7K9Rdb2s","requestTime":"2020-04-21 23:01:35","stack":"","status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} +{"pid":49495,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 23:01:35","osUser":"root","osUid":0,"fetchConsumeTime":199,"level":"INFO","message":"POST /node/user/login info","requestTime":"2020-04-21 23:01:35","status":200,"total":null,"requestBody":{"userAccount":"cai11","password":"123"},"url":"/node/user/login"} +{"pid":49495,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 23:04:55","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"ERROR","message":"room service tick","requestTime":"2020-04-21 23:04:55","stack":null,"status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} +{"pid":49495,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 23:05:14","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"INFO","message":"AccountService getToken token--eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6IuiUoSIsImFjY291bnQiOiJjYWkxMTEiLCJ1c2VySWQiOjJ9LCJpYXQiOjE1ODc0ODE1MTQsImV4cCI6MTU4NzUwMzExNH0.C9J4r3Xp_Uf9eslayzzu8f_JOLdaAJd53NeeUsOvhx4","requestTime":"2020-04-21 23:05:14","stack":"","status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} +{"pid":49495,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 23:05:14","osUser":"root","osUid":0,"fetchConsumeTime":180,"level":"INFO","message":"POST /node/user/login info","requestTime":"2020-04-21 23:05:14","status":200,"total":null,"requestBody":{"userAccount":"cai111","password":"123"},"url":"/node/user/login"} +{"pid":49588,"nodeVersion":"v12.16.1","launchTime":"2020-04-21 23:40:05","osUser":"root","osUid":0,"fetchConsumeTime":0,"level":"ERROR","message":"game already paling","requestTime":"2020-04-21 23:40:05","status":"","timestamp":"","total":0,"requestBody":{},"method":"","url":""} diff --git a/server/logs/game-node-center/agent.log b/server/logs/game-node-center/agent.log index 2a04199..d1d7f8f 100644 --- a/server/logs/game-node-center/agent.log +++ b/server/logs/game-node-center/agent.log @@ -5,3 +5,34 @@ 2020-04-21 00:28:39,488 INFO 47810 [egg-watcher] Recieved a change event from eventSource: {"event":"change","path":"/Users/jorky/code/TexasPokerGame/server/src/app/core/PokerGame.ts","stat":{"dev":16777220,"mode":33188,"nlink":1,"uid":501,"gid":20,"rdev":0,"blksize":4096,"ino":8594122649,"size":13210,"blocks":32,"atimeMs":1587399925111.0708,"mtimeMs":1587400119404.301,"ctimeMs":1587400119404.301,"birthtimeMs":1587375715544.5232,"atime":"2020-04-20T16:25:25.111Z","mtime":"2020-04-20T16:28:39.404Z","ctime":"2020-04-20T16:28:39.404Z","birthtime":"2020-04-20T09:41:55.545Z"},"remove":false,"isDirectory":false,"isFile":true} 2020-04-21 00:30:30,174 WARN 47810 [agent:development] reload worker because /Users/jorky/code/TexasPokerGame/server/src/app/core/PokerGame.ts change 2020-04-21 00:30:29,964 INFO 47810 [egg-watcher] Recieved a change event from eventSource: {"event":"change","path":"/Users/jorky/code/TexasPokerGame/server/src/app/core/PokerGame.ts","stat":{"dev":16777220,"mode":33188,"nlink":1,"uid":501,"gid":20,"rdev":0,"blksize":4096,"ino":8594122649,"size":13209,"blocks":32,"atimeMs":1587400165382.6262,"mtimeMs":1587400229901.3728,"ctimeMs":1587400229901.3728,"birthtimeMs":1587375715544.5232,"atime":"2020-04-20T16:29:25.383Z","mtime":"2020-04-20T16:30:29.901Z","ctime":"2020-04-20T16:30:29.901Z","birthtime":"2020-04-20T09:41:55.545Z"},"remove":false,"isDirectory":false,"isFile":true} +2020-04-21 22:51:20,169 INFO 49449 [egg:logger] init all loggers with options: {"dir":"/Users/jorky/code/TexasPokerGame/server/logs/game-node-center","encoding":"utf8","env":"local","level":"INFO","consoleLevel":"INFO","disableConsoleAfterReady":false,"outputJSON":false,"buffer":true,"appLogName":"app.log","coreLogName":"core.log","agentLogName":"agent.log","errorLogName":"error.log","coreLogger":{"consoleLevel":"WARN"},"allowDebugAtProd":false,"type":"agent"} +2020-04-21 22:51:20,182 INFO 49449 [egg:core] dump config after load, 9ms +2020-04-21 22:51:20,250 INFO 49449 [egg-watcher] Start watching: ["/Users/jorky/code/TexasPokerGame/server/src/app","/Users/jorky/code/TexasPokerGame/server/src/lib","/Users/jorky/code/TexasPokerGame/server/src/service","/Users/jorky/code/TexasPokerGame/server/src/config","/Users/jorky/code/TexasPokerGame/server/src/app.ts","/Users/jorky/code/TexasPokerGame/server/src/agent.ts","/Users/jorky/code/TexasPokerGame/server/src/interface.ts"] +2020-04-21 22:51:20,250 INFO 49449 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/app" +2020-04-21 22:51:20,250 INFO 49449 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/lib" +2020-04-21 22:51:20,250 INFO 49449 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/service" +2020-04-21 22:51:20,250 INFO 49449 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/config" +2020-04-21 22:51:20,250 INFO 49449 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/app.ts" +2020-04-21 22:51:20,251 INFO 49449 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/agent.ts" +2020-04-21 22:51:20,251 INFO 49449 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/interface.ts" +2020-04-21 22:51:20,251 INFO 49449 [egg-watcher:agent] watcher start success +2020-04-21 22:51:20,298 INFO 49449 [egg:core] dump config after ready, 30ms +2020-04-21 23:01:01,633 INFO 49449 [egg-watcher] Recieved a change event from eventSource: {"event":"change","path":"/Users/jorky/code/TexasPokerGame/server/src/app/io/controller/game.ts","stat":{"dev":16777220,"mode":33188,"nlink":1,"uid":501,"gid":20,"rdev":0,"blksize":4096,"ino":8594138357,"size":5794,"blocks":16,"atimeMs":1587480474446.9482,"mtimeMs":1587481261571.0176,"ctimeMs":1587481261571.0176,"birthtimeMs":1587462280504.6062,"atime":"2020-04-21T14:47:54.447Z","mtime":"2020-04-21T15:01:01.571Z","ctime":"2020-04-21T15:01:01.571Z","birthtime":"2020-04-21T09:44:40.505Z"},"remove":false,"isDirectory":false,"isFile":true} +2020-04-21 23:01:01,846 WARN 49449 [agent:development] reload worker because /Users/jorky/code/TexasPokerGame/server/src/app/io/controller/game.ts change +2020-04-21 23:07:07,224 WARN 49449 [agent:development] reload worker because /Users/jorky/code/TexasPokerGame/server/src/app/io/controller/game.ts change +2020-04-21 23:07:07,018 INFO 49449 [egg-watcher] Recieved a change event from eventSource: {"event":"change","path":"/Users/jorky/code/TexasPokerGame/server/src/app/io/controller/game.ts","stat":{"dev":16777220,"mode":33188,"nlink":1,"uid":501,"gid":20,"rdev":0,"blksize":4096,"ino":8594138357,"size":5846,"blocks":16,"atimeMs":1587481263453.9255,"mtimeMs":1587481626953.4163,"ctimeMs":1587481626953.4163,"birthtimeMs":1587462280504.6062,"atime":"2020-04-21T15:01:03.454Z","mtime":"2020-04-21T15:07:06.953Z","ctime":"2020-04-21T15:07:06.953Z","birthtime":"2020-04-21T09:44:40.505Z"},"remove":false,"isDirectory":false,"isFile":true} +2020-04-21 23:22:51,922 WARN 49449 [agent:development] reload worker because /Users/jorky/code/TexasPokerGame/server/src/app/io/middleware/join.ts change +2020-04-21 23:22:51,721 INFO 49449 [egg-watcher] Recieved a change event from eventSource: {"event":"change","path":"/Users/jorky/code/TexasPokerGame/server/src/app/io/controller/game.ts","stat":{"dev":16777220,"mode":33188,"nlink":1,"uid":501,"gid":20,"rdev":0,"blksize":4096,"ino":8594138357,"size":5887,"blocks":16,"atimeMs":1587481630924.8977,"mtimeMs":1587482571665.1768,"ctimeMs":1587482571665.1768,"birthtimeMs":1587462280504.6062,"atime":"2020-04-21T15:07:10.925Z","mtime":"2020-04-21T15:22:51.665Z","ctime":"2020-04-21T15:22:51.665Z","birthtime":"2020-04-21T09:44:40.505Z"},"remove":false,"isDirectory":false,"isFile":true} +2020-04-21 23:22:51,721 INFO 49449 [egg-watcher] Recieved a change event from eventSource: {"event":"change","path":"/Users/jorky/code/TexasPokerGame/server/src/app/io/middleware/join.ts","stat":{"dev":16777220,"mode":33188,"nlink":1,"uid":501,"gid":20,"rdev":0,"blksize":4096,"ino":8594138354,"size":2960,"blocks":8,"atimeMs":1587480474449.6377,"mtimeMs":1587482571659.1682,"ctimeMs":1587482571659.1682,"birthtimeMs":1587460252050.7163,"atime":"2020-04-21T14:47:54.450Z","mtime":"2020-04-21T15:22:51.659Z","ctime":"2020-04-21T15:22:51.659Z","birthtime":"2020-04-21T09:10:52.051Z"},"remove":false,"isDirectory":false,"isFile":true} +2020-04-21 23:40:30,560 INFO 51406 [egg:logger] init all loggers with options: {"dir":"/Users/jorky/code/TexasPokerGame/server/logs/game-node-center","encoding":"utf8","env":"local","level":"INFO","consoleLevel":"INFO","disableConsoleAfterReady":false,"outputJSON":false,"buffer":true,"appLogName":"app.log","coreLogName":"core.log","agentLogName":"agent.log","errorLogName":"error.log","coreLogger":{"consoleLevel":"WARN"},"allowDebugAtProd":false,"type":"agent"} +2020-04-21 23:40:30,568 INFO 51406 [egg:core] dump config after load, 5ms +2020-04-21 23:40:30,608 INFO 51406 [egg-watcher] Start watching: ["/Users/jorky/code/TexasPokerGame/server/src/app","/Users/jorky/code/TexasPokerGame/server/src/lib","/Users/jorky/code/TexasPokerGame/server/src/service","/Users/jorky/code/TexasPokerGame/server/src/config","/Users/jorky/code/TexasPokerGame/server/src/app.ts","/Users/jorky/code/TexasPokerGame/server/src/agent.ts","/Users/jorky/code/TexasPokerGame/server/src/interface.ts"] +2020-04-21 23:40:30,608 INFO 51406 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/app" +2020-04-21 23:40:30,608 INFO 51406 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/lib" +2020-04-21 23:40:30,608 INFO 51406 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/service" +2020-04-21 23:40:30,608 INFO 51406 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/config" +2020-04-21 23:40:30,608 INFO 51406 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/app.ts" +2020-04-21 23:40:30,609 INFO 51406 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/agent.ts" +2020-04-21 23:40:30,609 INFO 51406 [egg-watcher] Start watching: "/Users/jorky/code/TexasPokerGame/server/src/interface.ts" +2020-04-21 23:40:30,609 INFO 51406 [egg-watcher:agent] watcher start success +2020-04-21 23:40:30,621 INFO 51406 [egg:core] dump config after ready, 5ms diff --git a/server/logs/game-node-center/app.log b/server/logs/game-node-center/app.log index ae1ce36..b34e32d 100644 --- a/server/logs/game-node-center/app.log +++ b/server/logs/game-node-center/app.log @@ -87,3 +87,44 @@ fetchEnd: 1587399884656 } 2020-04-21 00:28:45,512 ERROR 48633 [-/127.0.0.1/-/6ms GET /socket.io/?room=394598&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6IuiUoTEiLCJhY2NvdW50IjoiY2FpMTEiLCJ1c2VySWQiOjN9LCJpYXQiOjE1ODczOTY2MDQsImV4cCI6MTU4NzQxODIwNH0.5eVb-sKMAuFF3x3t8wH3O8BeG3lhJUEwHWwYM64jgbE&EIO=3&transport=websocket] room service tick null +2020-04-21 22:52:33,923 INFO 49450 [-/192.168.0.105/-/230ms POST /node/user/login] AccountService getToken token--eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6ImMiLCJhY2NvdW50IjoiY2FpIiwidXNlcklkIjoxfSwiaWF0IjoxNTg3NDgwNzUzLCJleHAiOjE1ODc1MDIzNTN9.KxxH7Eiw4toDFNZGwaHSALgEbfIPT8Qjw-7-Hp6XllU +2020-04-21 22:52:33,928 INFO 49450 [-/192.168.0.105/-/234ms POST /node/user/login] { + fetchStart: 1587480753710, + url: '/node/user/login', + requestBody: { userAccount: 'cai', password: '123' }, + message: 'POST /node/user/login info', + level: 'INFO', + status: 200, + fetchEnd: 1587480753927 +} +2020-04-21 22:52:35,039 INFO 49450 [-/192.168.0.105/-/170ms POST /node/game/room] { + fetchStart: 1587480754871, + url: '/node/game/room', + requestBody: {}, + message: 'POST /node/game/room info', + level: 'INFO', + status: 200, + fetchEnd: 1587480755038 +} +2020-04-21 23:01:35,326 INFO 49495 [-/192.168.0.105/-/209ms POST /node/user/login] AccountService getToken token--eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6IuiUoTEiLCJhY2NvdW50IjoiY2FpMTEiLCJ1c2VySWQiOjN9LCJpYXQiOjE1ODc0ODEyOTUsImV4cCI6MTU4NzUwMjg5NX0.04tWzzIEspNyYmtY-EzyesrnpVwD7zx-0zG7K9Rdb2s +2020-04-21 23:01:35,331 INFO 49495 [-/192.168.0.105/-/213ms POST /node/user/login] { + fetchStart: 1587481295131, + url: '/node/user/login', + requestBody: { userAccount: 'cai11', password: '123' }, + message: 'POST /node/user/login info', + level: 'INFO', + status: 200, + fetchEnd: 1587481295330 +} +2020-04-21 23:04:55,154 ERROR 49495 [-/192.168.0.101/-/13ms GET /socket.io/?room=751675&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6IuiUoSIsImFjY291bnQiOiJjYWkxMTEiLCJ1c2VySWQiOjJ9LCJpYXQiOjE1ODczOTk4ODQsImV4cCI6MTU4NzQyMTQ4NH0.CVCe19KN0vg_4m1-axLTR6pz7DQPRQkcOWvBN5mn6PE&EIO=3&transport=websocket] room service tick null +2020-04-21 23:05:14,040 INFO 49495 [-/192.168.0.101/-/181ms POST /node/user/login] AccountService getToken token--eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6IuiUoSIsImFjY291bnQiOiJjYWkxMTEiLCJ1c2VySWQiOjJ9LCJpYXQiOjE1ODc0ODE1MTQsImV4cCI6MTU4NzUwMzExNH0.C9J4r3Xp_Uf9eslayzzu8f_JOLdaAJd53NeeUsOvhx4 +2020-04-21 23:05:14,041 INFO 49495 [-/192.168.0.101/-/182ms POST /node/user/login] { + fetchStart: 1587481513861, + url: '/node/user/login', + requestBody: { userAccount: 'cai111', password: '123' }, + message: 'POST /node/user/login info', + level: 'INFO', + status: 200, + fetchEnd: 1587481514041 +} +2020-04-21 23:40:05,073 ERROR 49588 game already paling diff --git a/server/logs/game-node-center/core.log b/server/logs/game-node-center/core.log index 6f2e6ac..0f1efe3 100644 --- a/server/logs/game-node-center/core.log +++ b/server/logs/game-node-center/core.log @@ -60,3 +60,88 @@ hostname: 192.168.0.105 2020-04-21 00:30:34,166 INFO 48645 [egg-watcher:application] watcher start success 2020-04-21 00:30:34,430 INFO 48645 [egg-mysql] instance[0] status OK, rds currentTime: Tue Apr 21 2020 00:30:35 GMT+0800 (China Standard Time) 2020-04-21 00:30:34,452 INFO 48645 [egg:core] dump config after ready, 4ms +2020-04-21 22:51:21,374 INFO 49450 [egg:logger] init all loggers with options: {"dir":"/Users/jorky/code/TexasPokerGame/server/logs/game-node-center","encoding":"utf8","env":"local","level":"INFO","consoleLevel":"INFO","disableConsoleAfterReady":false,"outputJSON":false,"buffer":true,"appLogName":"app.log","coreLogName":"core.log","agentLogName":"agent.log","errorLogName":"error.log","coreLogger":{"consoleLevel":"WARN"},"allowDebugAtProd":false,"type":"application"} +2020-04-21 22:51:21,399 INFO 49450 [egg-multipart] stream mode enable +2020-04-21 22:51:21,462 INFO 49450 [egg-redis] server connecting redis://:***@127.0.0.1:6379/0 +2020-04-21 22:51:21,479 INFO 49450 [egg-mysql] connecting root@47.104.172.100:3306/poker +2020-04-21 22:51:21,665 INFO 49450 [egg-static] starting static serve /public/ -> /Users/jorky/code/TexasPokerGame/server/src/app/public +2020-04-21 22:51:21,667 INFO 49450 [egg-security] use noopen middleware +2020-04-21 22:51:21,667 INFO 49450 [egg-security] use nosniff middleware +2020-04-21 22:51:21,668 INFO 49450 [egg-security] use xssProtection middleware +2020-04-21 22:51:21,668 INFO 49450 [egg-security] use xframe middleware +2020-04-21 22:51:21,669 INFO 49450 [egg-security] use dta middleware +2020-04-21 22:51:21,669 INFO 49450 [egg-security] compose 5 middlewares into one security middleware +2020-04-21 22:51:21,677 INFO 49450 [egg:core] dump config after load, 5ms +2020-04-21 22:51:21,690 INFO 49450 [egg-redis] client connect success +2020-04-21 22:51:21,695 INFO 49450 [egg-redis] instance[0] status OK, client ready +2020-04-21 22:51:21,698 INFO 49450 [egg-watcher:application] watcher start success +2020-04-21 22:51:22,001 INFO 49450 [egg-mysql] instance[0] status OK, rds currentTime: Tue Apr 21 2020 22:51:21 GMT+0800 (China Standard Time) +2020-04-21 22:51:22,037 INFO 49450 [egg:core] dump config after ready, 7ms +2020-04-21 23:01:05,231 INFO 49495 [egg:logger] init all loggers with options: {"dir":"/Users/jorky/code/TexasPokerGame/server/logs/game-node-center","encoding":"utf8","env":"local","level":"INFO","consoleLevel":"INFO","disableConsoleAfterReady":false,"outputJSON":false,"buffer":true,"appLogName":"app.log","coreLogName":"core.log","agentLogName":"agent.log","errorLogName":"error.log","coreLogger":{"consoleLevel":"WARN"},"allowDebugAtProd":false,"type":"application"} +2020-04-21 23:01:05,266 INFO 49495 [egg-multipart] stream mode enable +2020-04-21 23:01:05,314 INFO 49495 [egg-redis] server connecting redis://:***@127.0.0.1:6379/0 +2020-04-21 23:01:05,330 INFO 49495 [egg-mysql] connecting root@47.104.172.100:3306/poker +2020-04-21 23:01:05,557 INFO 49495 [egg-static] starting static serve /public/ -> /Users/jorky/code/TexasPokerGame/server/src/app/public +2020-04-21 23:01:05,563 INFO 49495 [egg-security] use noopen middleware +2020-04-21 23:01:05,565 INFO 49495 [egg-security] use nosniff middleware +2020-04-21 23:01:05,566 INFO 49495 [egg-security] use xssProtection middleware +2020-04-21 23:01:05,568 INFO 49495 [egg-security] use xframe middleware +2020-04-21 23:01:05,570 INFO 49495 [egg-security] use dta middleware +2020-04-21 23:01:05,570 INFO 49495 [egg-security] compose 5 middlewares into one security middleware +2020-04-21 23:01:05,587 INFO 49495 [egg:core] dump config after load, 9ms +2020-04-21 23:01:05,611 INFO 49495 [egg-redis] client connect success +2020-04-21 23:01:05,614 INFO 49495 [egg-redis] instance[0] status OK, client ready +2020-04-21 23:01:05,622 INFO 49495 [egg-watcher:application] watcher start success +2020-04-21 23:01:05,786 INFO 49495 [egg-mysql] instance[0] status OK, rds currentTime: Tue Apr 21 2020 23:01:05 GMT+0800 (China Standard Time) +2020-04-21 23:01:05,814 INFO 49495 [egg:core] dump config after ready, 5ms +2020-04-21 23:07:10,830 INFO 49545 [egg:logger] init all loggers with options: {"dir":"/Users/jorky/code/TexasPokerGame/server/logs/game-node-center","encoding":"utf8","env":"local","level":"INFO","consoleLevel":"INFO","disableConsoleAfterReady":false,"outputJSON":false,"buffer":true,"appLogName":"app.log","coreLogName":"core.log","agentLogName":"agent.log","errorLogName":"error.log","coreLogger":{"consoleLevel":"WARN"},"allowDebugAtProd":false,"type":"application"} +2020-04-21 23:07:10,862 INFO 49545 [egg-multipart] stream mode enable +2020-04-21 23:07:10,912 INFO 49545 [egg-redis] server connecting redis://:***@127.0.0.1:6379/0 +2020-04-21 23:07:10,927 INFO 49545 [egg-mysql] connecting root@47.104.172.100:3306/poker +2020-04-21 23:07:11,095 INFO 49545 [egg-static] starting static serve /public/ -> /Users/jorky/code/TexasPokerGame/server/src/app/public +2020-04-21 23:07:11,097 INFO 49545 [egg-security] use noopen middleware +2020-04-21 23:07:11,098 INFO 49545 [egg-security] use nosniff middleware +2020-04-21 23:07:11,099 INFO 49545 [egg-security] use xssProtection middleware +2020-04-21 23:07:11,100 INFO 49545 [egg-security] use xframe middleware +2020-04-21 23:07:11,101 INFO 49545 [egg-security] use dta middleware +2020-04-21 23:07:11,101 INFO 49545 [egg-security] compose 5 middlewares into one security middleware +2020-04-21 23:07:11,110 INFO 49545 [egg:core] dump config after load, 6ms +2020-04-21 23:07:11,122 INFO 49545 [egg-redis] client connect success +2020-04-21 23:07:11,127 INFO 49545 [egg-redis] instance[0] status OK, client ready +2020-04-21 23:07:11,130 INFO 49545 [egg-watcher:application] watcher start success +2020-04-21 23:07:11,304 INFO 49545 [egg-mysql] instance[0] status OK, rds currentTime: Tue Apr 21 2020 23:07:11 GMT+0800 (China Standard Time) +2020-04-21 23:07:11,341 INFO 49545 [egg:core] dump config after ready, 7ms +2020-04-21 23:22:56,747 INFO 49588 [egg:logger] init all loggers with options: {"dir":"/Users/jorky/code/TexasPokerGame/server/logs/game-node-center","encoding":"utf8","env":"local","level":"INFO","consoleLevel":"INFO","disableConsoleAfterReady":false,"outputJSON":false,"buffer":true,"appLogName":"app.log","coreLogName":"core.log","agentLogName":"agent.log","errorLogName":"error.log","coreLogger":{"consoleLevel":"WARN"},"allowDebugAtProd":false,"type":"application"} +2020-04-21 23:22:56,780 INFO 49588 [egg-multipart] stream mode enable +2020-04-21 23:22:56,818 INFO 49588 [egg-redis] server connecting redis://:***@127.0.0.1:6379/0 +2020-04-21 23:22:56,849 INFO 49588 [egg-mysql] connecting root@47.104.172.100:3306/poker +2020-04-21 23:22:57,039 INFO 49588 [egg-static] starting static serve /public/ -> /Users/jorky/code/TexasPokerGame/server/src/app/public +2020-04-21 23:22:57,041 INFO 49588 [egg-security] use noopen middleware +2020-04-21 23:22:57,042 INFO 49588 [egg-security] use nosniff middleware +2020-04-21 23:22:57,043 INFO 49588 [egg-security] use xssProtection middleware +2020-04-21 23:22:57,044 INFO 49588 [egg-security] use xframe middleware +2020-04-21 23:22:57,045 INFO 49588 [egg-security] use dta middleware +2020-04-21 23:22:57,045 INFO 49588 [egg-security] compose 5 middlewares into one security middleware +2020-04-21 23:22:57,053 INFO 49588 [egg:core] dump config after load, 5ms +2020-04-21 23:22:57,065 INFO 49588 [egg-redis] client connect success +2020-04-21 23:22:57,070 INFO 49588 [egg-redis] instance[0] status OK, client ready +2020-04-21 23:22:57,072 INFO 49588 [egg-watcher:application] watcher start success +2020-04-21 23:22:57,249 INFO 49588 [egg-mysql] instance[0] status OK, rds currentTime: Tue Apr 21 2020 23:22:57 GMT+0800 (China Standard Time) +2020-04-21 23:22:57,289 INFO 49588 [egg:core] dump config after ready, 8ms +2020-04-21 23:40:31,676 INFO 51407 [egg:logger] init all loggers with options: {"dir":"/Users/jorky/code/TexasPokerGame/server/logs/game-node-center","encoding":"utf8","env":"local","level":"INFO","consoleLevel":"INFO","disableConsoleAfterReady":false,"outputJSON":false,"buffer":true,"appLogName":"app.log","coreLogName":"core.log","agentLogName":"agent.log","errorLogName":"error.log","coreLogger":{"consoleLevel":"WARN"},"allowDebugAtProd":false,"type":"application"} +2020-04-21 23:40:31,700 INFO 51407 [egg-multipart] stream mode enable +2020-04-21 23:40:31,776 INFO 51407 [egg-redis] server connecting redis://:***@127.0.0.1:6379/0 +2020-04-21 23:40:31,795 INFO 51407 [egg-mysql] connecting root@47.104.172.100:3306/poker +2020-04-21 23:40:31,962 INFO 51407 [egg-static] starting static serve /public/ -> /Users/jorky/code/TexasPokerGame/server/src/app/public +2020-04-21 23:40:31,964 INFO 51407 [egg-security] use noopen middleware +2020-04-21 23:40:31,965 INFO 51407 [egg-security] use nosniff middleware +2020-04-21 23:40:31,965 INFO 51407 [egg-security] use xssProtection middleware +2020-04-21 23:40:31,966 INFO 51407 [egg-security] use xframe middleware +2020-04-21 23:40:31,967 INFO 51407 [egg-security] use dta middleware +2020-04-21 23:40:31,967 INFO 51407 [egg-security] compose 5 middlewares into one security middleware +2020-04-21 23:40:31,979 INFO 51407 [egg:core] dump config after load, 7ms +2020-04-21 23:40:31,999 INFO 51407 [egg-redis] client connect success +2020-04-21 23:40:32,005 INFO 51407 [egg-redis] instance[0] status OK, client ready +2020-04-21 23:40:32,009 INFO 51407 [egg-watcher:application] watcher start success +2020-04-21 23:40:32,220 INFO 51407 [egg-mysql] instance[0] status OK, rds currentTime: Tue Apr 21 2020 23:40:32 GMT+0800 (China Standard Time) +2020-04-21 23:40:32,250 INFO 51407 [egg:core] dump config after ready, 6ms diff --git a/server/logs/game-node-center/egg-schedule.log b/server/logs/game-node-center/egg-schedule.log index 524c605..86ab163 100644 --- a/server/logs/game-node-center/egg-schedule.log +++ b/server/logs/game-node-center/egg-schedule.log @@ -7,3 +7,24 @@ 2020-04-21 00:30:33,856 INFO 48645 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-multipart/app/schedule/clean_tmpdir.js 2020-04-21 00:30:33,856 INFO 48645 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/clean_log.js 2020-04-21 00:30:33,856 INFO 48645 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/rotate_by_file.js +2020-04-21 22:51:22,043 INFO 49449 [Timer] /Users/jorky/code/TexasPokerGame/server/node_modules/egg-multipart/app/schedule/clean_tmpdir.js next time will execute after 20317960ms at 2020-04-22 04:30:00.003 +2020-04-21 22:51:22,043 INFO 49449 [Timer] /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/clean_log.js next time will execute after 4117957ms at 2020-04-22 00:00:00.000 +2020-04-21 22:51:22,043 INFO 49449 [Timer] /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/rotate_by_file.js next time will execute after 4118957ms at 2020-04-22 00:00:01.000 +2020-04-21 22:51:21,398 INFO 49450 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-multipart/app/schedule/clean_tmpdir.js +2020-04-21 22:51:21,398 INFO 49450 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/clean_log.js +2020-04-21 22:51:21,398 INFO 49450 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/rotate_by_file.js +2020-04-21 23:01:05,266 INFO 49495 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-multipart/app/schedule/clean_tmpdir.js +2020-04-21 23:01:05,266 INFO 49495 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/clean_log.js +2020-04-21 23:01:05,266 INFO 49495 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/rotate_by_file.js +2020-04-21 23:07:10,861 INFO 49545 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-multipart/app/schedule/clean_tmpdir.js +2020-04-21 23:07:10,861 INFO 49545 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/clean_log.js +2020-04-21 23:07:10,861 INFO 49545 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/rotate_by_file.js +2020-04-21 23:22:56,780 INFO 49588 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-multipart/app/schedule/clean_tmpdir.js +2020-04-21 23:22:56,780 INFO 49588 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/clean_log.js +2020-04-21 23:22:56,780 INFO 49588 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/rotate_by_file.js +2020-04-21 23:40:32,255 INFO 51406 [Timer] /Users/jorky/code/TexasPokerGame/server/node_modules/egg-multipart/app/schedule/clean_tmpdir.js next time will execute after 17367747ms at 2020-04-22 04:30:00.002 +2020-04-21 23:40:32,255 INFO 51406 [Timer] /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/clean_log.js next time will execute after 1167745ms at 2020-04-22 00:00:00.000 +2020-04-21 23:40:32,255 INFO 51406 [Timer] /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/rotate_by_file.js next time will execute after 1168745ms at 2020-04-22 00:00:01.000 +2020-04-21 23:40:31,699 INFO 51407 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-multipart/app/schedule/clean_tmpdir.js +2020-04-21 23:40:31,699 INFO 51407 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/clean_log.js +2020-04-21 23:40:31,699 INFO 51407 [egg-schedule]: register schedule /Users/jorky/code/TexasPokerGame/server/node_modules/egg-logrotator/app/schedule/rotate_by_file.js diff --git a/server/logs/game-node-center/error.log b/server/logs/game-node-center/error.log index 199c492..c2cfa63 100644 --- a/server/logs/game-node-center/error.log +++ b/server/logs/game-node-center/error.log @@ -9,3 +9,5 @@ name: "unhandledRejectionError" pid: 48633 hostname: 192.168.0.105 +2020-04-21 23:04:55,154 ERROR 49495 [-/192.168.0.101/-/13ms GET /socket.io/?room=751675&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Im5pY2tfbmFtZSI6IuiUoSIsImFjY291bnQiOiJjYWkxMTEiLCJ1c2VySWQiOjJ9LCJpYXQiOjE1ODczOTk4ODQsImV4cCI6MTU4NzQyMTQ4NH0.CVCe19KN0vg_4m1-axLTR6pz7DQPRQkcOWvBN5mn6PE&EIO=3&transport=websocket] room service tick null +2020-04-21 23:40:05,072 ERROR 49588 game already paling diff --git a/server/src/app/core/Player.ts b/server/src/app/core/Player.ts index fc13f6b..b86a547 100644 --- a/server/src/app/core/Player.ts +++ b/server/src/app/core/Player.ts @@ -26,11 +26,12 @@ export enum EPlayerType { } export class Player { - handCard: string[] = []; + private handCard: string[] = []; position: number = 0; counter: number = 0; userId: string = ''; socketId: string = ''; + nick_name: string = ''; actionSize: number = 0; type: string = EPlayerType.DEFAULT; evPot: number = Infinity; @@ -42,6 +43,7 @@ export class Player { this.position = config.position || 0; this.userId = config.userId; this.socketId = config.socketId; + this.nick_name = config.nick_name; if (this.position === 0) { this.type = EPlayerType.DEALER; } diff --git a/server/src/app/core/PokerGame.ts b/server/src/app/core/PokerGame.ts index aefb4ff..6ae54fe 100644 --- a/server/src/app/core/PokerGame.ts +++ b/server/src/app/core/PokerGame.ts @@ -402,7 +402,7 @@ export class PokerGame { let j = 0; while (j < this.playerSize) { player = playerLink.node; - player.handCard.push(this.poker.getCard()); + player.setHandCard(this.poker.getCard()); if (playerLink.next) { playerLink = playerLink.next; } diff --git a/server/src/app/io/controller/game.ts b/server/src/app/io/controller/game.ts index 4400b90..ae06a8f 100644 --- a/server/src/app/io/controller/game.ts +++ b/server/src/app/io/controller/game.ts @@ -28,20 +28,51 @@ class GameController extends BaseSocketController { updateCommonCard: () => { console.log('send common card'); this.nsp.adapter.clients([ this.roomNumber ], (err: any, clients: any) => { - if (roomInfo.game) { - // 广播信息 - this.nsp.to(this.roomNumber).emit('online', { - clients, - action: 'commonCard', - target: 'participator', - message: JSON.stringify(roomInfo.game.commonCard), - }); - } - }); + if (roomInfo.game) { + // 更新common card + this.nsp.to(this.roomNumber).emit('online', { + clients, + action: 'commonCard', + target: 'participator', + data: { + commonCard: roomInfo.game.commonCard, + }, + }); + } + }); }, }); roomInfo.game.play(); console.log('hand card', roomInfo.game.allPlayer); + // update counter, pot + this.nsp.adapter.clients([ this.roomNumber ], (err: any, clients: any) => { + if (roomInfo.game) { + roomInfo.players.forEach(p => { + const currPlayer = roomInfo.game && roomInfo.game.allPlayer.find(player => player.userId === p.userId); + p.counter = currPlayer && currPlayer.counter || 0; + }); + const gameInfo = { + players: roomInfo.game.allPlayer.map(p => Object.assign({}, { + counter: p.counter, + actionSize: p.actionSize, + nick_name: p.nick_name, + type: p.type, + }, {})), + pot: roomInfo.game.pot, + prevSize: roomInfo.game.prevSize, + currPlayer: { + userId: roomInfo.game.currPlayer.node.userId, + }, + }; + // 广播信息 + this.nsp.to(this.roomNumber).emit('online', { + clients, + action: 'gameInfo', + target: 'participator', + data: gameInfo, + }); + } + }); roomInfo.players.forEach(p => { if (roomInfo.game) { // console.log('game msg---------1'); @@ -49,7 +80,7 @@ class GameController extends BaseSocketController { // console.log(player, 'game msg---------1'); if (player) { const msg = this.ctx.helper.parseMsg('handCard', { - handCard: player.handCard, + handCard: player.getHandCard(), }, { client: p.socketId }); console.log(msg, 'game msg---------', p.socketId); this.nsp.emit(p.socketId, msg); @@ -87,7 +118,9 @@ class GameController extends BaseSocketController { clients, action: 'players', target: 'participator', - message: JSON.stringify(roomInfo.players), + data: { + players: roomInfo.players, + }, }); }); } catch (e) { @@ -105,7 +138,7 @@ class GameController extends BaseSocketController { const gamePlayer = roomInfo.game.allPlayer.find(p => player.socketId === p.socketId); if (gamePlayer) { const msg = this.ctx.helper.parseMsg('handCard', { - handCard: gamePlayer.handCard, + handCard: gamePlayer.getHandCard(), }, { client: player.socketId }); console.log(msg, 'game msg---------'); this.nsp.emit(player.socketId, msg); diff --git a/server/src/app/io/middleware/join.ts b/server/src/app/io/middleware/join.ts index cd062c7..86f84d7 100644 --- a/server/src/app/io/middleware/join.ts +++ b/server/src/app/io/middleware/join.ts @@ -3,7 +3,7 @@ import { IGameRoom } from '../../../interface/IGameRoom'; import { IPlayer } from '../../core/Player'; export default function join(): any { - function updatePlayer(roomNumber: string, message: string, action: string, nsp: any) { + function updatePlayer(roomNumber: string, players: any, action: string, nsp: any) { // 在线列表 nsp.adapter.clients([ roomNumber ], (err: any, clients: any) => { // 更新在线用户列表 @@ -11,7 +11,9 @@ export default function join(): any { clients, action, target: 'participator', - message, + data: { + players, + }, }); }); } @@ -62,16 +64,18 @@ export default function join(): any { } } socket.join(room); + socket.emit(id, ctx.helper.parseMsg('userInfo', user)); + // console.log('players', JSON.stringify(gameRoom.roomInfo.players)); updatePlayer(room, `User(${user.nick_name}) joined.`, 'join', nsp); - updatePlayer(room, JSON.stringify(gameRoom.roomInfo.players), 'players', nsp); + updatePlayer(room, gameRoom.roomInfo.players, 'players', nsp); // in the game, update hand cards const player = gameRoom.roomInfo.players.find((p: IPlayer) => p.nick_name === user.nick_name); if (player && gameRoom.roomInfo.game) { const gamePlayer = gameRoom.roomInfo.game.allPlayer.find(p => player.socketId === p.socketId); if (gamePlayer) { const msg = ctx.helper.parseMsg('handCard', { - handCard: gamePlayer.handCard, + handCard: gamePlayer.getHandCard(), }, { client: player.socketId }); // console.log(msg, 'join: game msg---------2222222'); socket.emit(id, msg); diff --git a/server/src/app/router.ts b/server/src/app/router.ts index 23379e8..a5f886e 100644 --- a/server/src/app/router.ts +++ b/server/src/app/router.ts @@ -5,4 +5,5 @@ export default function (app: Application) { app.io.of('/socket').route('broadcast', app.io.controller.nsp.broadcast); app.io.of('/socket').route('buyIn', app.io.controller.game.buyIn); app.io.of('/socket').route('playGame', app.io.controller.game.playGame); + app.io.of('/socket').route('action', app.io.controller.game.action); } diff --git a/server/test/app/core/pokerGame.test.ts b/server/test/app/core/pokerGame.test.ts index 75fe67c..cda47de 100644 --- a/server/test/app/core/pokerGame.test.ts +++ b/server/test/app/core/pokerGame.test.ts @@ -9,36 +9,22 @@ describe('test/app/core/pokerGame.test.ts', () => { userId: '1', counter: 200, nick_name: '1', - account: '', - socketId: '', + account: '1', + socketId: '1', }, { userId: '2', counter: 200, - nick_name: '1', - account: '', - socketId: '', + nick_name: '2', + account: '2', + socketId: '2', }, { userId: '3', counter: 50, - nick_name: '1', - account: '', - socketId: '', - }, - { - userId: '4', - counter: 400, - nick_name: '1', - account: '', - socketId: '', - }, - { - userId: '5', - counter: 1200, - nick_name: '1', - account: '', - socketId: '', + nick_name: '3', + account: '3', + socketId: '3', }, ]; @@ -49,6 +35,7 @@ describe('test/app/core/pokerGame.test.ts', () => { const game = new PokerGame({ smallBlind: 1, users, + updateCommonCard: () => {}, }); game.play(); expect(game.status).to.equal(EGameStatus.GAME_ACTION); @@ -65,36 +52,37 @@ describe('test/app/core/pokerGame.test.ts', () => { const game = new PokerGame({ smallBlind: 1, users, + updateCommonCard: () => {}, }); game.play(); - game.action('call'); - game.action('call'); - game.action('call'); - game.action('call'); - game.action('check'); - game.sendCard(); - game.action('raise:10'); - game.action('raise:20'); - game.action('call'); - game.action('call'); - game.action('raise:40'); - game.action('call'); - game.action('call'); - game.action('call'); - game.action('call'); - game.sendCard(); - game.action('allin'); - game.action('allin'); - game.action('allin'); - game.action('fold'); - game.action('allin'); + // game.action('call'); + // game.action('call'); + // game.action('call'); + // game.action('call'); + // game.action('check'); + // game.sendCard(); + // game.action('raise:10'); + // game.action('raise:20'); + // game.action('call'); + // game.action('call'); + // game.action('raise:40'); + // game.action('call'); + // game.action('call'); + // game.action('call'); + // game.action('call'); + // game.sendCard(); + // game.action('allin'); + // game.action('allin'); + // game.action('allin'); + // game.action('fold'); + // game.action('allin'); console.log('cc'); // game.action('raise:10'); console.log(game.commonCard); console.log(game.pot); console.log(game.getPlayers()); console.log(game.winner); - console.log(game.winner[0][0].handCard, game.commonCard); + // console.log(game.winner[0][0], game.commonCard); }); // flop // turn diff --git a/server/test/utils/link.test.ts b/server/test/utils/link.test.ts index 1585700..208ba4c 100644 --- a/server/test/utils/link.test.ts +++ b/server/test/utils/link.test.ts @@ -3,10 +3,10 @@ import { Player } from '../../src/app/core/Player'; describe('test/utils/link.test.ts', () => { it('link', async () => { - const person1 = new Player({ counter: 1, position: 1, userId: '1' }); - const person2 = new Player({ counter: 2, position: 2, userId: '2' }); - const person3 = new Player({ counter: 2, position: 3, userId: '3' }); - const person4 = new Player({ counter: 2, position: 4, userId: '4' }); + const person1 = new Player({ counter: 1, position: 1, userId: '1', socketId: '', account: '', nick_name: '' }); + const person2 = new Player({ counter: 2, position: 2, userId: '2', socketId: '', account: '', nick_name: '' }); + const person3 = new Player({ counter: 2, position: 3, userId: '3', socketId: '', account: '', nick_name: '' }); + const person4 = new Player({ counter: 2, position: 4, userId: '4', socketId: '', account: '', nick_name: '' }); // const person5 = new Player({ counter: 2, position: 5, userId: '5' }); const link = new Link([ person1, person2, person3, person4 ], false); // console.log(link.getNode(0), 'link--------')