Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonseokang committed Dec 4, 2023
1 parent da6f448 commit 40cd72b
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,31 @@ module.exports = (server) => {
}
});

socket.on(Info.EVENT_MESSAGE.MATCH_START, async () => {
const userState = await UserState.findOne({
where: {
'socketId': socket.id,
'state': Info.userState.Join,
}
});

if (userState != null) {
console.log(socket.id, " 매칭 시작함");
userState.state = Info.userState.Match;
await userState.save();
}
});

socket.on(Info.EVENT_MESSAGE.MATCH_START, async(deckIndex)=>{
await setTimeout(() => {

}, 2000);
await new Promise(resolve => setTimeout(resolve, 1000));

const userState = await UserState.findOne({
where:{
'socketId':socket.id,
'state':Info.userState.Join,
}
});

if(userState != null){
if(userState != undefined){
if(userState.state != Info.userState.Join)
return;

if(deckIndex == "")
deckIndex = 1;

socket.deckIndex = deckIndex;
console.log(socket.id, " 매칭 시작함");
userState.state = Info.userState.Match;
await userState.save();
socket.emit(Info.EVENT_MESSAGE.MATCH_START, "");
}
});

socket.on(Info.EVENT_MESSAGE.MATCH_CANCEL, async ()=>{
const userState = await UserState.findOne({
where:{
Expand All @@ -105,15 +91,15 @@ module.exports = (server) => {
}
});

if(userState != null){
if(userState.state != Info.Match)
if (userState != undefined) {
if (userState.state != Info.userState.Match)
return;

console.log(socket.id, " 매칭 취소함");
userState.state = Info.userState.Join;
await userState.save();
socket.emit(Info.EVENT_MESSAGE.MATCH_CANCEL, "");
}
0 }
});
socket.on("test-card", (data)=>{
const card = data;
Expand Down

0 comments on commit 40cd72b

Please sign in to comment.