Commit 23ea3f31 authored by 18신대성's avatar 18신대성 Committed by 18류지석

Room이 READY 상태일때 나가도 문제없게 수정

parent 276169f8
......@@ -57,10 +57,27 @@ GameServer.findRoomIndex = function(roomNum)
GameServer.enterRoom = function(roomIdx, playerData)
{
let room = this.playingRoom[roomIdx];
let player = new Player(room.currentPlayer.length, playerData);
let nextIdx = -1;
for (let i = 0; i < room.currentPlayer.length; i++)
{
if (room.currentPlayer[i] === null)
{
nextIdx = i;
break
}
}
let player = new Player((nextIdx != -1 ? nextIdx : room.currentPlayer.length), playerData);
if (nextIdx != -1)
{
room.currentPlayer[nextIdx] = player;
room.currentSocket[nextIdx] = playerData;
}
else
{
room.currentPlayer.push(player);
room.currentSocket.push(playerData);
}
playerData.playingData = player;
playerData.currentRoom = room;
......@@ -91,6 +108,10 @@ GameServer.startRoom = function(roomIdx)
room.currentPhase = this.Phase.START;
room.maxTypingPlayer = room.currentPlayer[0];
room.minTypingPlayer = room.currentPlayer[0];
room.currentSocket.forEach(function(element)
{
element.isReceivable = true;
});
// sync roomData
let toSync =
......@@ -118,7 +139,7 @@ GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = nul
{
return element.id === targetNum;
});
if (targetSocket != undefined) targetSocket.socketId.emit(_message, _data);
if (targetSocket != undefined && targetSocket.isReceivable) targetSocket.socketId.emit(_message, _data);
}
// 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍)
......
......@@ -28,8 +28,7 @@ io.on('connection', function(socket)
socketId: socket,
currentRoom: null,
playingData: null,
playerTyping: 0
isReceivable: false
};
GameServer.currentPlayer.push(socket.playerData);
console.log('['+socket.playerData.id+'] client request');
......@@ -72,6 +71,7 @@ io.on('connection', function(socket)
{
socket.playerData.playingData.isAlive = false;
socket.playerData.playingData.rank = socket.playerData.currentRoom.nextRank--;
socket.playerData.isReceivable = false;
// 패배단어 체크
GameServer.announceToRoom(socket.playerData.currentRoom.roomNum, 'defeat', socket.playerData.playingData);
console.log('['+socket.playerData.id+']'+ ' defeated');
......@@ -97,13 +97,21 @@ io.on('connection', function(socket)
GameServer.currentPlayer.splice(idxToDel, 1);
// 룸에서도 제거
if (data.currentRoom != null)
{
if (data.currentRoom.currentPhase === GameServer.Phase.READY)
{
data.currentRoom.currentPlayer[data.playingData.index] = null;
data.currentRoom.currentSocket[data.playingData.index] = null;
}
else
{
data.playingData.isAlive = false;
if (data.playingData.rank === -1) data.playingData.rank = data.currentRoom.nextRank--;
data.currentRoom.currentSocket.splice(data.playingData.index, 1);
data.currentRoom.currentSocket[data.playingData.index].isReceivable = false;
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'userDisconnect', data.playingData);
}
}
}
console.log('['+ data.id +'] disconnect complete');
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment