Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuweiyou committed Feb 9, 2018
1 parent 17bcc1a commit 0b703cd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions 我最在行/src/common/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = async (player, {master = false, match = false, theme = 0} = {})
avatar: accountsSelf.avatar,
level: accountsSelf.level,
player_id: player.account_id,
owner_id: player.account_id,
token: player.access_token,
dan: danGrade.dan,
grade: danGrade.grade,
Expand Down
21 changes: 6 additions & 15 deletions 我最在行/src/common/pk-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@ const Socket = require('./socket')
const querystring = require('querystring')

module.exports = class PkSocket extends Socket {
constructor ({address, player_id, avatar, level, type, theme_id, token, dan, grade, master, events}) {
const wss = `${address}&${querystring.stringify({
player_id,
avatar,
level,
type,
theme_id,
token,
dan,
grade,
owner_id: player_id
})}`
super({wss, events})
this.master = master
this.player_id = player_id
constructor ({options, events}) {
const address = options.address
delete options.address
super({wss: `${address}&${querystring.stringify(options)}`, events})
this.master = options.master
this.player_id = options.player_id
}

onOpen () {
Expand Down
6 changes: 4 additions & 2 deletions 我最在行/src/match/match-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ module.exports = class MatchSocket extends Socket {
if (data.address) {
console.log('获取到房间地址', data.address)
new PkSocket({
...this.options,
address: data.address,
options: {
...this.options,
address: data.address
},
events: this.events
})
}
Expand Down
8 changes: 5 additions & 3 deletions 我最在行/src/pk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ module.exports = async players => {
game(players[1])
])
rooms.map(room => new PkSocket({
...room,
address: rooms[0].address,
theme_id: rooms[0].theme_id,
options: {
...room,
address: rooms[0].address,
theme_id: rooms[0].theme_id
},
events
}))
}

0 comments on commit 0b703cd

Please sign in to comment.