Commit c7978529 authored by 18신대성's avatar 18신대성

Merge branch 'server'

parents 1b09c30f bf079b75
...@@ -87,11 +87,11 @@ GameServer.enterRoom = function(roomIdx, playerData) ...@@ -87,11 +87,11 @@ GameServer.enterRoom = function(roomIdx, playerData)
console.log('[' + playerData.id + '] entered to room #' + room.roomNum); console.log('[' + playerData.id + '] entered to room #' + room.roomNum);
playerData.socketId.emit('enterRoom'); playerData.socketId.emit('enterRoom');
room.endTime = Date.now() + 6000; // 테스트로 6초로 남겨둠
if (room.currentPlayer.length >= this.startCount) if (room.currentPlayer.length >= this.startCount)
{ {
if (room.currentPhase === this.Phase.READY) // start count if (room.currentPhase === this.Phase.READY) // start count
{ {
room.endTime = Date.now() + 15000; // 테스트로 15초로 남겨둠
this.announceToRoom(room.roomNum, 'setCount', {isEnable: true, endTime: room.endTime}); this.announceToRoom(room.roomNum, 'setCount', {isEnable: true, endTime: room.endTime});
} }
else if (room.currentPhase === this.Phase.COUNT) // countinue count else if (room.currentPhase === this.Phase.COUNT) // countinue count
...@@ -185,14 +185,14 @@ GameServer.announceToRoom = function(roomIdx, _message, _data = null) ...@@ -185,14 +185,14 @@ GameServer.announceToRoom = function(roomIdx, _message, _data = null)
{ {
this.playingRoom[roomIdx].currentSocket.forEach(function(element) this.playingRoom[roomIdx].currentSocket.forEach(function(element)
{ {
element.socketId.emit(_message, _data); if (element != null) element.socketId.emit(_message, _data);
}); });
} }
GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = null) GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = null)
{ {
let targetSocket = this.playingRoom[roomIdx].currentSocket.find(function(element) let targetSocket = this.playingRoom[roomIdx].currentSocket.find(function(element)
{ {
return element.id === targetNum; return (element != null && element.id === targetNum);
}); });
if (targetSocket != undefined && targetSocket.isReceivable) targetSocket.socketId.emit(_message, _data); if (targetSocket != undefined && targetSocket.isReceivable) targetSocket.socketId.emit(_message, _data);
} }
......
...@@ -53,7 +53,6 @@ io.on('connection', function(socket) ...@@ -53,7 +53,6 @@ io.on('connection', function(socket)
console.log('['+socket.playerData.id+'] nickname set to ' + msg); console.log('['+socket.playerData.id+'] nickname set to ' + msg);
GameServer.enterEmptyRoom(socket.playerData); GameServer.enterEmptyRoom(socket.playerData);
} }
}); });
socket.on('setPlayerTyping', function(msg) // number playerTyping socket.on('setPlayerTyping', function(msg) // number playerTyping
...@@ -84,6 +83,7 @@ io.on('connection', function(socket) ...@@ -84,6 +83,7 @@ io.on('connection', function(socket)
socket.on('attack', function(msg) socket.on('attack', function(msg)
{ {
GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attacked', msg); GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attacked', msg);
//console.log('find ' + msg.target + ' by ' + msg.attacker.idNum + ' with ' + msg.text);
let target = GameServer.findPlayer(msg.target); let target = GameServer.findPlayer(msg.target);
if (target != null) if (target != null)
{ {
...@@ -136,10 +136,15 @@ io.on('connection', function(socket) ...@@ -136,10 +136,15 @@ io.on('connection', function(socket)
// 룸에서도 제거 // 룸에서도 제거
if (data.currentRoom != null) if (data.currentRoom != null)
{ {
if (data.currentRoom.currentPhase === GameServer.Phase.READY) if (data.currentRoom.currentPhase === GameServer.Phase.READY || data.currentRoom.currentPhase === GameServer.Phase.COUNT)
{ {
data.currentRoom.currentPlayer[data.playingData.index] = null; data.currentRoom.currentPlayer[data.playingData.index] = null;
data.currentRoom.currentSocket[data.playingData.index] = null; data.currentRoom.currentSocket[data.playingData.index] = null;
data.currentRoom.aliveCount--;
if (data.currentRoom.aliveCount < GameServer.startCount)
{
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'setCount', {isEnable: false, endTime: 0});
}
} }
else if (data.playingData.isAlive) else if (data.playingData.isAlive)
{ {
......
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