Skip to content

Commit

Permalink
Add action to socket
Browse files Browse the repository at this point in the history
  • Loading branch information
FPT-NMTung committed Dec 20, 2024
1 parent 60c0880 commit ff4f5e7
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions controllers/gomokuSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,66 @@ function gomokuSocket (server) {
},
});
})

// Handle join game action
socket.on('viewGame', async (dataMessage) => {
let matchId = dataMessage.matchId

// add to database
let res = await connectDatabaseService(username, 'pkg_gmk_game.check_view_game', {
matchId: matchId
})

if (res.length === 1 && res[0].MESSAGE_ERROR != null) {
socket.emit('error', {
error_code: -99,
error_message: res[0].MESSAGE_ERROR.replace(/ORA-\d{5}: /g, ''),
});

return
}

socket.emit('info', {
action: 'joinGame',
data: {
matchId: matchId
},
});

socket.join(matchId)

res = await connectDatabaseService(username, 'pkg_gmk_game.get_all_step', {
matchId: matchId
})

socket.emit('allMove', res)

res = await connectDatabaseService(username, 'pkg_gmk_game.get_all_member', {
matchId: matchId
})

io.to(matchId).emit('listMember', res)

if (res.length !== 2) {
return
}

res = await connectDatabaseService(username, 'pkg_gmk_game.get_info_game', {
matchId: matchId
})

io.to(matchId).emit('info', {
action: 'infoGame',
data: res
});

io.to(matchId).emit('info', {
action: 'startGame',
data: {
matchId: matchId
},
});
})
});
}

Expand Down

0 comments on commit ff4f5e7

Please sign in to comment.