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

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

parent 276169f8
...@@ -57,10 +57,27 @@ GameServer.findRoomIndex = function(roomNum) ...@@ -57,10 +57,27 @@ GameServer.findRoomIndex = function(roomNum)
GameServer.enterRoom = function(roomIdx, playerData) GameServer.enterRoom = function(roomIdx, playerData)
{ {
let room = this.playingRoom[roomIdx]; 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);
room.currentPlayer.push(player); if (nextIdx != -1)
room.currentSocket.push(playerData); {
room.currentPlayer[nextIdx] = player;
room.currentSocket[nextIdx] = playerData;
}
else
{
room.currentPlayer.push(player);
room.currentSocket.push(playerData);
}
playerData.playingData = player; playerData.playingData = player;
playerData.currentRoom = room; playerData.currentRoom = room;
...@@ -91,6 +108,10 @@ GameServer.startRoom = function(roomIdx) ...@@ -91,6 +108,10 @@ GameServer.startRoom = function(roomIdx)
room.currentPhase = this.Phase.START; room.currentPhase = this.Phase.START;
room.maxTypingPlayer = room.currentPlayer[0]; room.maxTypingPlayer = room.currentPlayer[0];
room.minTypingPlayer = room.currentPlayer[0]; room.minTypingPlayer = room.currentPlayer[0];
room.currentSocket.forEach(function(element)
{
element.isReceivable = true;
});
// sync roomData // sync roomData
let toSync = let toSync =
...@@ -118,7 +139,7 @@ GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = nul ...@@ -118,7 +139,7 @@ GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = nul
{ {
return element.id === targetNum; return element.id === targetNum;
}); });
if (targetSocket != undefined) targetSocket.socketId.emit(_message, _data); if (targetSocket != undefined && targetSocket.isReceivable) targetSocket.socketId.emit(_message, _data);
} }
// 데이터 동기화 함수 만들기 // 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍) // 동기화할것: 유저리스트(id - nickname 쌍)
......
...@@ -28,8 +28,7 @@ io.on('connection', function(socket) ...@@ -28,8 +28,7 @@ io.on('connection', function(socket)
socketId: socket, socketId: socket,
currentRoom: null, currentRoom: null,
playingData: null, playingData: null,
isReceivable: false
playerTyping: 0
}; };
GameServer.currentPlayer.push(socket.playerData); GameServer.currentPlayer.push(socket.playerData);
console.log('['+socket.playerData.id+'] client request'); console.log('['+socket.playerData.id+'] client request');
...@@ -72,6 +71,7 @@ io.on('connection', function(socket) ...@@ -72,6 +71,7 @@ io.on('connection', function(socket)
{ {
socket.playerData.playingData.isAlive = false; socket.playerData.playingData.isAlive = false;
socket.playerData.playingData.rank = socket.playerData.currentRoom.nextRank--; socket.playerData.playingData.rank = socket.playerData.currentRoom.nextRank--;
socket.playerData.isReceivable = false;
// 패배단어 체크 // 패배단어 체크
GameServer.announceToRoom(socket.playerData.currentRoom.roomNum, 'defeat', socket.playerData.playingData); GameServer.announceToRoom(socket.playerData.currentRoom.roomNum, 'defeat', socket.playerData.playingData);
console.log('['+socket.playerData.id+']'+ ' defeated'); console.log('['+socket.playerData.id+']'+ ' defeated');
...@@ -98,10 +98,18 @@ io.on('connection', function(socket) ...@@ -98,10 +98,18 @@ io.on('connection', function(socket)
// 룸에서도 제거 // 룸에서도 제거
if (data.currentRoom != null) if (data.currentRoom != null)
{ {
data.playingData.isAlive = false; if (data.currentRoom.currentPhase === GameServer.Phase.READY)
if (data.playingData.rank === -1) data.playingData.rank = data.currentRoom.nextRank--; {
data.currentRoom.currentSocket.splice(data.playingData.index, 1); data.currentRoom.currentPlayer[data.playingData.index] = null;
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'userDisconnect', data.playingData); 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[data.playingData.index].isReceivable = false;
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'userDisconnect', data.playingData);
}
} }
} }
console.log('['+ data.id +'] disconnect complete'); 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