fix: token lost

This commit is contained in:
wzdwc
2021-03-28 03:08:26 +08:00
parent f16496605c
commit c4eba7fe96
17 changed files with 352 additions and 235 deletions
+1 -1
View File
@@ -6,5 +6,5 @@ yarn-error.log
test/unit/coverage test/unit/coverage
run/ run/
logs/ logs/
confing.prod.ts
npm-debug.* npm-debug.*
/server/src/config/
+19 -11
View File
@@ -26,19 +26,24 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="f9039135-aa11-4abd-ad74-f40c84e4fdb2" name="Default Changelist" comment=""> <list default="true" id="f9039135-aa11-4abd-ad74-f40c84e4fdb2" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" /> <change beforePath="$PROJECT_DIR$/client/src/assets/less/base.less" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/assets/less/base.less" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client/src/components/Action.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/Action.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client/src/components/SendMsg.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/SendMsg.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client/src/components/SitList.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/SitList.vue" afterDir="false" /> <change beforePath="$PROJECT_DIR$/client/src/components/SitList.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/components/SitList.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client/src/interface/IMsgList.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/interface/IMsgList.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/client/src/interface/IPlayer.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/interface/IPlayer.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client/src/utils/PokerStyle.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/utils/PokerStyle.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/client/src/utils/request.ts" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/utils/request.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client/src/views/game.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/views/game.vue" afterDir="false" /> <change beforePath="$PROJECT_DIR$/client/src/views/game.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/views/game.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client/src/views/home.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/views/home.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client/src/views/login.vue" beforeDir="false" afterPath="$PROJECT_DIR$/client/src/views/login.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/src.zip" beforeDir="false" afterPath="$PROJECT_DIR$/server/src.zip" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/src/app/core/Player.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/core/Player.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/src/app/core/PokerGame.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/core/PokerGame.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/server/src/app/core/PokerGame.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/core/PokerGame.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/src/app/core/PokerStyle.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/core/PokerStyle.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/src/app/io/controller/game.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/io/controller/game.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/server/src/app/io/controller/game.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/io/controller/game.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/src/app/io/middleware/join.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/io/middleware/join.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/src/app/router.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/app/router.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/src/config/config.prod.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/config/config.prod.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/src/lib/baseSocketController.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/lib/baseSocketController.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/server/src/lib/baseSocketController.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/lib/baseSocketController.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/server/test/app/core/pokerStyle.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/test/app/core/pokerStyle.test.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/server/src/service/account.ts" beforeDir="false" afterPath="$PROJECT_DIR$/server/src/service/account.ts" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -138,6 +143,7 @@
<workItem from="1599739988741" duration="1817000" /> <workItem from="1599739988741" duration="1817000" />
<workItem from="1599904748126" duration="799000" /> <workItem from="1599904748126" duration="799000" />
<workItem from="1599912369521" duration="681000" /> <workItem from="1599912369521" duration="681000" />
<workItem from="1616871635424" duration="298000" />
</task> </task>
<servers /> <servers />
</component> </component>
@@ -205,15 +211,17 @@
<screen x="0" y="23" width="1440" height="823" /> <screen x="0" y="23" width="1440" height="823" />
</state> </state>
<state x="385" y="197" key="run.anything.popup/0.23.1440.823@0.23.1440.823" timestamp="1605708588099" /> <state x="385" y="197" key="run.anything.popup/0.23.1440.823@0.23.1440.823" timestamp="1605708588099" />
<state x="385" y="173" width="670" height="672" key="search.everywhere.popup" timestamp="1615119618414"> <state x="385" y="173" width="670" height="673" key="search.everywhere.popup" timestamp="1616837414379">
<screen x="0" y="23" width="1440" height="822" /> <screen x="0" y="23" width="1440" height="823" />
</state> </state>
<state x="385" y="173" width="670" height="672" key="search.everywhere.popup/0.23.1440.822@0.23.1440.822" timestamp="1615119618414" /> <state x="385" y="173" width="670" height="672" key="search.everywhere.popup/0.23.1440.822@0.23.1440.822" timestamp="1615119618414" />
<state x="385" y="173" width="670" height="673" key="search.everywhere.popup/0.23.1440.823@0.23.1440.823" timestamp="1616837414379" />
<state x="385" y="174" width="670" height="676" key="search.everywhere.popup/0.23.1440.827@0.23.1440.827" timestamp="1600510032147" /> <state x="385" y="174" width="670" height="676" key="search.everywhere.popup/0.23.1440.827@0.23.1440.827" timestamp="1600510032147" />
<state x="450" y="362" key="vcs.readOnlyHandler.ReadOnlyStatusDialog" timestamp="1600495902702"> <state x="450" y="360" key="vcs.readOnlyHandler.ReadOnlyStatusDialog" timestamp="1616839505918">
<screen x="0" y="23" width="1440" height="829" /> <screen x="0" y="23" width="1440" height="825" />
</state> </state>
<state x="450" y="369" key="vcs.readOnlyHandler.ReadOnlyStatusDialog/0.0.1440.900@0.0.1440.900" timestamp="1591504016729" /> <state x="450" y="369" key="vcs.readOnlyHandler.ReadOnlyStatusDialog/0.0.1440.900@0.0.1440.900" timestamp="1591504016729" />
<state x="450" y="360" key="vcs.readOnlyHandler.ReadOnlyStatusDialog/0.23.1440.825@0.23.1440.825" timestamp="1616839505918" />
<state x="450" y="362" key="vcs.readOnlyHandler.ReadOnlyStatusDialog/0.23.1440.828@0.23.1440.828" timestamp="1599740214397" /> <state x="450" y="362" key="vcs.readOnlyHandler.ReadOnlyStatusDialog/0.23.1440.828@0.23.1440.828" timestamp="1599740214397" />
<state x="450" y="362" key="vcs.readOnlyHandler.ReadOnlyStatusDialog/0.23.1440.829@0.23.1440.829" timestamp="1600495902702" /> <state x="450" y="362" key="vcs.readOnlyHandler.ReadOnlyStatusDialog/0.23.1440.829@0.23.1440.829" timestamp="1600495902702" />
</component> </component>
+70 -64
View File
@@ -1,64 +1,70 @@
@font-face { @font-face {
font-family: 'iconfont'; /* project id 1801313 */ font-family: 'iconfont'; /* project id 1801313 */
src: url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.eot'); src: url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.eot');
src: url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.eot?#iefix') format('embedded-opentype'), src: url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.eot?#iefix') format('embedded-opentype'),
url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.woff2') format('woff2'), url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.woff2') format('woff2'),
url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.woff') format('woff'), url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.woff') format('woff'),
url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.ttf') format('truetype'), url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.ttf') format('truetype'),
url('//at.alicdn.com/t/font_1801313_4rcv94i1hxw.svg#iconfont') format('svg'); url('//at.alicdn.com/t/font_1801313_jpwi7jzmcwr.svg#iconfont') format('svg');
} }
.iconfont { .iconfont {
font-family: "iconfont" !important; font-family: "iconfont" !important;
font-size: 16px; font-size: 16px;
font-style: normal; font-style: normal;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
.icon-account:before { .icon-account:before {
content: "\e60a"; content: "\e60a";
} }
.icon-user-avatar:before { .icon-user-avatar:before {
content: "\e636"; content: "\e636";
} }
.icon-pot:before { .icon-pot:before {
content: "\e60c"; content: "\e60c";
} }
.icon-gold:before { .icon-gold:before {
content: "\e609"; content: "\e609";
} }
.icon-setting:before { .icon-setting:before {
content: "\e611"; content: "\e611";
} }
.icon-password:before { .icon-password:before {
content: "\e603"; content: "\e603";
} }
.icon-close:before { .icon-close:before {
content: "\e615"; content: "\e615";
} }
.icon-msg:before{ .icon-msg:before{
content: "\e781"; content: "\e781";
} }
.icon-record:before{ .icon-record:before{
content: "\e657"; content: "\e657";
} }
.icon-arrow:before{ .icon-arrow:before{
content: "\e623"; content: "\e623";
} }
body, p,h1,h2,ul,li,input{
padding: 0; .icon-clock:before{
margin: 0; content: "\e608";
} }
input{
border: 0;
outline: none; body, p,h1,h2,ul,li,input{
} padding: 0;
margin: 0;
}
input{
border: 0;
outline: none;
}
+37 -1
View File
@@ -60,6 +60,11 @@
<div class="hand-card"> <div class="hand-card">
<cardList :cardList="handCard" <cardList :cardList="handCard"
:valueCards="valueCards"></cardList> :valueCards="valueCards"></cardList>
<div class="delay-time" v-show="time < 15 && sit.player.delayCount > 0
&& actionUserId === sit.player.userId" @click="delayTime">
<i class="iconfont icon-clock "></i>
<span>{{sit.player.delayCount}}</span>
</div>
</div> </div>
<div class="ready" <div class="ready"
v-show="handCard && handCard.length === 0">ready v-show="handCard && handCard.length === 0">ready
@@ -159,6 +164,14 @@
return map(cards); return map(cards);
} }
private delayTime() {
if(this.currPlayer.delayCount > 0) {
console.log('delay')
this.$emit('update:time', this.time + 60);
this.$emit('delay')
}
}
private sitDown(sit: ISit) { private sitDown(sit: ISit) {
if (!sit.player && (!this.isPlay || !this.hasSit)) { if (!sit.player && (!this.isPlay || !this.hasSit)) {
if (this.currPlayer.counter <= 0) { if (this.currPlayer.counter <= 0) {
@@ -354,6 +367,29 @@
} }
} }
.delay-time{
position: absolute;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
z-index: 999;
min-width: 24vw;
min-height: 10vh;
background: radial-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0) 70%);
i{
color: #fff;
font-size: 30px;
}
span{
font-size: 12px;
color: #fff;
margin-left: 2px;
font-weight: 600;
}
}
.hand-card { .hand-card {
position: absolute; position: absolute;
top: 1vh; top: 1vh;
@@ -464,7 +500,7 @@
color: #fff; color: #fff;
font-size: 14px; font-size: 14px;
bottom: -48px; bottom: -48px;
width: 60 / 3.75vw; width: 22vw;
text-align: center; text-align: center;
font-weight: 700; font-weight: 700;
} }
+20 -19
View File
@@ -1,19 +1,20 @@
enum PlayerType { enum PlayerType {
READY, READY,
SIT_DOWN, SIT_DOWN,
GAMING, GAMING,
} }
export interface IPlayer { export interface IPlayer {
counter: number; counter: number;
nickName: string; nickName: string;
actionSize: number; actionSize: number;
actionCommand: string; actionCommand: string;
type: string; type: string;
userId?: number; userId?: string;
handCard?: string[]; handCard?: string[];
buyIn: number; buyIn: number;
status: number; status: number;
income?: number; income?: number;
isSit: boolean; isSit: boolean;
} delayCount: number;
}
+34 -34
View File
@@ -1,34 +1,34 @@
import axios, {AxiosRequestConfig, Method} from 'axios'; import axios, {AxiosRequestConfig, Method} from 'axios';
import cookie from 'js-cookie'; import cookie from 'js-cookie';
import origin from '@/utils/origin'; import origin from '@/utils/origin';
const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => { const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => {
if (!url) { if (!url) {
return Promise.reject('Request url is null!'); return Promise.reject('Request url is null!');
} }
const token = cookie.get('token'); const token = cookie.get('token') || localStorage.getItem('token');
const headers = { const headers = {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}; };
console.log('url', origin.url); console.log('url', origin.url);
url = `${origin.url}/node${url}`; url = `${origin.url}/node${url}`;
const option: AxiosRequestConfig = { const option: AxiosRequestConfig = {
url, url,
method, method,
timeout, timeout,
data: body, data: body,
withCredentials: true, withCredentials: true,
headers, headers,
}; };
try { try {
const result = await axios(option); const result = await axios(option);
if (result.data.code === '000000') { if (result.data.code === '000000') {
return result.data; return result.data;
} else { } else {
throw result.data; throw result.data;
} }
} catch (e) { } catch (e) {
throw e; throw e;
} }
}; };
export default request; export default request;
+20 -4
View File
@@ -8,7 +8,8 @@
:isPlay='isPlay' :isPlay='isPlay'
:valueCards='valueCards' :valueCards='valueCards'
:roomConfig = 'roomConfig' :roomConfig = 'roomConfig'
:time='time' @delay="delay"
:time.sync='time'
:winner="winner" :winner="winner"
:actionUserId='actionUserId' :actionUserId='actionUserId'
:hand-card="handCard"></sitList> :hand-card="handCard"></sitList>
@@ -107,7 +108,7 @@
} }
const GAME_BASE_SIZE = 1; const GAME_BASE_SIZE = 1;
const ACTION_TIME = 60; const ACTION_TIME = 30;
@Component({ @Component({
components: { components: {
@@ -306,6 +307,11 @@
this.emit('sitDown', { sitList: this.sitListMap() }); this.emit('sitDown', { sitList: this.sitListMap() });
} }
private delay() {
console.log('delay')
this.emit('delayTime');
}
private action(command: string) { private action(command: string) {
if (command === 'fold') { if (command === 'fold') {
clearTimeout(this.timeSt); clearTimeout(this.timeSt);
@@ -322,8 +328,8 @@
} }
private socketInit() { private socketInit() {
const token = cookie.get('token'); const token = cookie.get('token') || localStorage.getItem('token') || '';
const roomConfig = cookie.get('roomConfig') || ''; const roomConfig = cookie.get('roomConfig') || localStorage.getItem('roomConfig') || '';
const log = console.log; const log = console.log;
this.roomConfig = JSON.parse(roomConfig); this.roomConfig = JSON.parse(roomConfig);
console.log(JSON.parse(roomConfig), 'roomConfig'); console.log(JSON.parse(roomConfig), 'roomConfig');
@@ -445,6 +451,12 @@
this.init(); this.init();
} }
if (msg.action === 'delayTime') {
if (this.currPlayer?.userId !== this.actionUserId) {
this.time += 60;
}
}
if (msg.action === 'broadcast') { if (msg.action === 'broadcast') {
this.messageList.push({ this.messageList.push({
message: msg.message.msg || '', message: msg.message.msg || '',
@@ -455,14 +467,18 @@
// //
this.socket.on('disconnect', (msg: IMsg) => { this.socket.on('disconnect', (msg: IMsg) => {
this.$plugin.toast('room is disconnect');
this.socketInit()
log('#disconnect', msg); log('#disconnect', msg);
}); });
this.socket.on('disconnecting', () => { this.socket.on('disconnecting', () => {
this.$plugin.toast('room is disconnecting');
log('#disconnecting'); log('#disconnecting');
}); });
this.socket.on('error', () => { this.socket.on('error', () => {
this.$plugin.toast('room is error');
log('#error'); log('#error');
}); });
} }
+1
View File
@@ -93,6 +93,7 @@
isShort: this.isShort, isShort: this.isShort,
smallBlind: this.smallBlind, smallBlind: this.smallBlind,
}; };
localStorage.setItem('roomConfig', JSON.stringify(roomConfig))
cookie.set('roomConfig', roomConfig, {expires: 1}); cookie.set('roomConfig', roomConfig, {expires: 1});
this.$router.push({ name: 'game', params: { roomNumber, isOwner: '1' } }); this.$router.push({ name: 'game', params: { roomNumber, isOwner: '1' } });
} catch (e) { } catch (e) {
+89 -88
View File
@@ -1,88 +1,89 @@
<template> <template>
<div class="login-container container"> <div class="login-container container">
<div class="login-body"> <div class="login-body">
<div class="name">J-POKER</div> <div class="name">J-POKER</div>
<div class="user-name input-bd"> <div class="user-name input-bd">
<div class="input-name iconfont icon-account"></div> <div class="input-name iconfont icon-account"></div>
<div class="input-text"> <div class="input-text">
<input type="text" <input type="text"
v-model="userAccount"/> v-model="userAccount"/>
</div> </div>
</div> </div>
<div class="password input-bd"> <div class="password input-bd">
<div class="input-name iconfont icon-password"></div> <div class="input-name iconfont icon-password"></div>
<div class="input-text"> <div class="input-text">
<input type="password" <input type="password"
v-model="password"/> v-model="password"/>
</div> </div>
</div> </div>
<div class="login-btn btn"> <div class="login-btn btn">
<span @click="login">sign in</span> <span @click="login">sign in</span>
<b @click="signUp">sign up</b> <b @click="signUp">sign up</b>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import {Vue} from 'vue-property-decorator'; import {Vue} from 'vue-property-decorator';
import service from '../service'; import service from '../service';
import Component from 'vue-class-component'; import Component from 'vue-class-component';
import cookie from 'js-cookie'; import cookie from 'js-cookie';
@Component @Component
export default class Login extends Vue { export default class Login extends Vue {
public userAccount: string = ''; public userAccount: string = '';
public password: string = ''; public password: string = '';
private signUp() { private signUp() {
this.$router.replace({name: 'register'}); this.$router.replace({name: 'register'});
return; return;
} }
private async login() { private async login() {
try { try {
const result = await service.login(this.userAccount, this.password); const result = await service.login(this.userAccount, this.password);
const { token } = result.data; const { token } = result.data;
cookie.set('token', token, {expires: 1}); cookie.set('token', token, {expires: 1});
await this.$router.push({name: 'home'}); localStorage.setItem('token', token)
} catch (e) { await this.$router.push({name: 'home'});
this.$plugin.toast('Wrong password or account.'); } catch (e) {
} this.$plugin.toast('Wrong password or account.');
} }
} }
</script> }
<style lang="less" scoped> </script>
.login-container{ <style lang="less" scoped>
background: radial-gradient(#00bf86, #006a55); .login-container{
background-size: 100% 100%; background: radial-gradient(#00bf86, #006a55);
width: 100vw; background-size: 100% 100%;
height: 100vh; width: 100vw;
padding: 50vw 0; height: 100vh;
box-sizing: border-box; padding: 50vw 0;
.login-body{ box-sizing: border-box;
width: 85vw; .login-body{
margin: auto; width: 85vw;
border-radius: 4px; margin: auto;
box-sizing: border-box; border-radius: 4px;
box-shadow: 2px 3px 9px rgba(0, 0, 0, 0.3); box-sizing: border-box;
background-color: #fff; box-shadow: 2px 3px 9px rgba(0, 0, 0, 0.3);
padding: 30px; background-color: #fff;
.input-bd{ padding: 30px;
border: 1px solid #bababa; .input-bd{
border-radius: 20px; border: 1px solid #bababa;
width: 60vw; border-radius: 20px;
margin: 30px auto; width: 60vw;
text-align: left; margin: 30px auto;
.input-name{ text-align: left;
text-align: center; .input-name{
font-size: 18px; text-align: center;
color: #bababa; font-size: 18px;
} color: #bababa;
input{ }
height: 40px; input{
background-color: transparent; height: 40px;
} background-color: transparent;
} }
} }
} }
</style> }
</style>
BIN
View File
Binary file not shown.
+2
View File
@@ -12,6 +12,7 @@ export interface IPlayer {
status: number; status: number;
actionSize: number; actionSize: number;
actionCommand: string; actionCommand: string;
delayCount?: number;
} }
export enum ECommand { export enum ECommand {
@@ -37,6 +38,7 @@ export class Player {
position: number = 0; position: number = 0;
counter: number = 0; counter: number = 0;
userId: string = ''; userId: string = '';
delayCount: number = 3;
socketId: string = ''; socketId: string = '';
nickName: string = ''; nickName: string = '';
actionSize: number = 0; actionSize: number = 0;
+30 -9
View File
@@ -45,7 +45,7 @@ export enum EGameStatus {
* Action time * Action time
* @type {number} * @type {number}
*/ */
const ACTION_TIME = 60 * 1000; const ACTION_TIME = 30 * 1000;
/** /**
* Class representing a poker game * Class representing a poker game
@@ -54,6 +54,7 @@ export class PokerGame {
private playerLink: Link<Player>; private playerLink: Link<Player>;
private poker: IPoker; private poker: IPoker;
private prevPot: number = 0; private prevPot: number = 0;
private actionTimeDelayCount: number = 0;
private actionTimeOut: Timeout; private actionTimeOut: Timeout;
private currActionAllinPlayer: Player[] = []; private currActionAllinPlayer: Player[] = [];
// It's a short poker game // It's a short poker game
@@ -322,13 +323,22 @@ export class PokerGame {
/** /**
* Start next action round * Start next action round
*/ */
startActionRound() { startActionRound(time= ACTION_TIME) {
this.actionTimeOut = setTimeout(async () => { this.actionTimeOut = setTimeout(async () => {
console.log('come in delay round --------2', this.actionTimeDelayCount);
// delay action time
if (this.actionTimeDelayCount > 0) {
console.log('come in delay round --------2', this.actionTimeDelayCount);
this.actionTimeDelayCount --;
clearTimeout(this.actionTimeOut);
this.startActionRound(60 * 1000);
return ;
}
const userId = this.currPlayer.node.userId || ''; const userId = this.currPlayer.node.userId || '';
console.log('userId start', userId); console.log('userId start', userId);
this.action('fold'); this.action('fold');
this.autoActionCallBack('fold', userId); this.autoActionCallBack('fold', userId);
}, ACTION_TIME); }, time);
} }
/** /**
@@ -400,12 +410,13 @@ export class PokerGame {
console.log('preSize', this.prevSize); console.log('preSize', this.prevSize);
this.currPlayer = this.currPlayer.next; this.currPlayer = this.currPlayer.next;
// action time out, auto action fold // action time out, auto action fold
this.actionTimeOut = setTimeout(() => { this.startActionRound();
const actionType = 'fold'; // this.actionTimeOut = setTimeout(() => {
const userId = this.currPlayer.node.userId; // const actionType = 'fold';
this.action(actionType); // const userId = this.currPlayer.node.userId;
this.autoActionCallBack(actionType, userId); // this.action(actionType);
}, ACTION_TIME); // this.autoActionCallBack(actionType, userId);
// }, ACTION_TIME);
} catch (e) { } catch (e) {
throw 'action:' + e; throw 'action:' + e;
} }
@@ -421,6 +432,7 @@ export class PokerGame {
if (this.playerSize === 1 if (this.playerSize === 1
&& (this.currActionAllinPlayer.length === 0 && (this.currActionAllinPlayer.length === 0
|| (command === ECommand.ALL_IN || (command === ECommand.ALL_IN
&& this.prevSize <= nextPlayer.actionSize
&& this.currPlayer.node.actionSize < this.prevSize))) { && this.currPlayer.node.actionSize < this.prevSize))) {
return true; return true;
} }
@@ -623,4 +635,13 @@ export class PokerGame {
this.initPlayer(); this.initPlayer();
this.gameOverCallBack(); this.gameOverCallBack();
} }
public delayActionTime() {
if (this.currPlayer.node.delayCount > 0) {
this.currPlayer.node.delayCount --;
this.actionTimeDelayCount ++;
console.log('come in delay round --------', this.actionTimeDelayCount);
}
console.log('come in delay round --------', this.actionTimeDelayCount);
}
} }
+24 -2
View File
@@ -244,19 +244,20 @@ class GameController extends BaseSocketController {
}); });
console.log('sit =======', roomInfo.sit); console.log('sit =======', roomInfo.sit);
console.log('roomInfo =======', roomInfo); console.log('roomInfo =======', roomInfo);
// calculate re buy in
roomInfo.sit.forEach((s: ISit) => { roomInfo.sit.forEach((s: ISit) => {
if (s.player) { if (s.player) {
const player = roomInfo.players.find( const player = roomInfo.players.find(
p => p.userId === s.player?.userId); p => p.userId === s.player?.userId);
if (player) { if (player) {
// new player // calculate re buy in
s.player.counter = player.counter; s.player.counter = player.counter;
s.player.counter += Number(player.reBuy); s.player.counter += Number(player.reBuy);
console.log('cal reBuy ===============================', s.player, console.log('cal reBuy ===============================', s.player,
player.reBuy); player.reBuy);
player.reBuy = 0; player.reBuy = 0;
s.player.reBuy = 0; s.player.reBuy = 0;
// init player delay count
player.delayCount = 3;
} }
} }
}); });
@@ -403,6 +404,27 @@ class GameController extends BaseSocketController {
console.log(e); console.log(e);
} }
} }
async delayTime() {
try {
const { payload } = this.message;
const userInfo: IPlayer = await this.getUserInfo();
const roomInfo = await this.getRoomInfo();
console.log('delayTime', payload.command);
console.log('delayTime', roomInfo.game && roomInfo.game.currPlayer.node,
userInfo);
if (roomInfo.game
&& roomInfo.game.currPlayer.node.userId === userInfo.userId) {
roomInfo.game.delayActionTime();
console.log('delayTime', roomInfo.game && roomInfo.game.currPlayer.node,
userInfo);
await this.adapter('online', 'delayTime', {});
}
} catch (e) {
console.log(e);
}
}
async action() { async action() {
try { try {
const { payload } = this.message; const { payload } = this.message;
+1
View File
@@ -40,6 +40,7 @@ export default function join(): any {
socketId: id, socketId: id,
counter: 0, counter: 0,
buyIn: 0, buyIn: 0,
delayCount: 3,
reBuy: 0, reBuy: 0,
}; };
let gameRoom: IGameRoom = { let gameRoom: IGameRoom = {
+1 -1
View File
@@ -8,5 +8,5 @@ export default function (app: Application) {
app.io.of('/socket').route('action', app.io.controller.game.action); app.io.of('/socket').route('action', app.io.controller.game.action);
app.io.of('/socket').route('sitDown', app.io.controller.game.sitDown); app.io.of('/socket').route('sitDown', app.io.controller.game.sitDown);
app.io.of('/socket').route('standUp', app.io.controller.game.standUp); app.io.of('/socket').route('standUp', app.io.controller.game.standUp);
app.io.of('/socket').route('delayTime', app.io.controller.game.delayTime);
} }
+2
View File
@@ -50,6 +50,7 @@ export default class BaseSocketController extends Controller {
p.type = currPlayer?.type || ''; p.type = currPlayer?.type || '';
p.status = currPlayer ? 1 : p.status === -1 ? -1 : 0; p.status = currPlayer ? 1 : p.status === -1 ? -1 : 0;
p.actionCommand = currPlayer && currPlayer.actionCommand || ''; p.actionCommand = currPlayer && currPlayer.actionCommand || '';
p.delayCount = currPlayer && currPlayer.delayCount || 0;
p.actionSize = currPlayer && currPlayer.actionSize || 0; p.actionSize = currPlayer && currPlayer.actionSize || 0;
}); });
console.log(roomInfo.players, console.log(roomInfo.players,
@@ -67,6 +68,7 @@ export default class BaseSocketController extends Controller {
status: p.status || 0, status: p.status || 0,
userId: p.userId, userId: p.userId,
buyIn: p.buyIn || 0, buyIn: p.buyIn || 0,
delayCount: currPlayer?.delayCount || 0,
}, {}); }, {});
}), }),
pot: roomInfo.game.pot, pot: roomInfo.game.pot,
+1 -1
View File
@@ -81,7 +81,7 @@ export class AccountService extends BaseService implements IAccountService {
userId: id, userId: id,
}, },
}, },
this.jwtConfig.secret, { expiresIn: 60 * 60 * 6 }); this.jwtConfig.secret, { expiresIn: 60 * 60 * 24 * 360 });
this.ctx.logger.info(`AccountService getToken token--${token}`); this.ctx.logger.info(`AccountService getToken token--${token}`);
return token; return token;
} }