Commit 379b7204 authored by 18신대성's avatar 18신대성

서버 안정화

parent 5020b7bf
var GameServer = GameServer || {};
GameServer.Phase = {READY: 0, COUNT: -1, START: 1, MAIN: 2, MUSIC: 3};
GameServer.connectCount = 0;
GameServer.disconnectCount = 0;
GameServer.currentPlayer = [];
GameServer.playingRoom = [];
......
......@@ -36,6 +36,7 @@ io.on('connection', function(socket)
str: 'your number is ' + socket.playerData.id,
num: socket.playerData.id
});
GameServer.connectCount++;
});
socket.on('setNickname', function(msg) // string new_nickname
......@@ -80,7 +81,7 @@ io.on('connection', function(socket)
socket.playerData.currentRoom.announceToRoom('attackMode', socket.playerData.id);
}
}
catch (e) {console.log('[ERR] error catched on setPlayerTyping')}
catch (e) {console.error('[ERR] error catched on setPlayerTyping')}
});
socket.on('endCount', function()
......@@ -137,51 +138,60 @@ io.on('connection', function(socket)
socket.on('disconnect', function(reason)
{
GameServer.disconnectCount++;
let data = socket.playerData;
if (typeof data.id === undefined)
if (typeof data === undefined)
{
console.log('[ERROR] data.id is undefined');
console.log(GameServer.currentPlayer);
console.error('[ERROR] data is undefined');
console.table(GameServer.currentPlayer);
}
else // data.id is not undefined
{
console.log('['+ data.id +'] client disconnected, reason: ' + reason);
let idxToDel = GameServer.currentPlayer.findIndex(function(element)
{
return element.playerData.id === data.id;
});
if (idxToDel != -1)
disconnectUser(data, reason);
}
const connectDiff = GameServer.connectCount - GameServer.disconnectCount;
const playerCount = GameServer.currentPlayer.length
console.log({ connectDiff, playerCount });
});
});
var disconnectUser = function(data, reason)
{
console.log('['+ data.id +'] client disconnected, reason: ' + reason);
let idxToDel = GameServer.currentPlayer.findIndex(function(element)
{
return element.playerData.id === data.id;
});
if (idxToDel != -1)
{
// 룸에서도 제거
if (data.currentRoom != null)
{
if (data.currentRoom.currentPhase === GameServer.Phase.READY || data.currentRoom.currentPhase === GameServer.Phase.COUNT)
{
// 룸에서도 제거
if (data.currentRoom != null)
data.currentRoom.exitRoom(data.id);
if (data.currentRoom.aliveCount < data.currentRoom.startCount)
{
if (data.currentRoom.currentPhase === GameServer.Phase.READY || data.currentRoom.currentPhase === GameServer.Phase.COUNT)
data.currentRoom.announceToRoom('setRoomCount',
{
data.currentRoom.exitRoom(data.id);
if (data.currentRoom.aliveCount < data.currentRoom.startCount)
{
data.currentRoom.announceToRoom('setRoomCount',
{
isEnable: false, endTime: 0, playerCount: data.currentRoom.currentPlayer.length,
isEnter: false, player: data.playingData
});
data.currentRoom.currentPhase = GameServer.Phase.READY;
}
else data.currentRoom.announceToRoom('setRoomCount',
{
isEnable: true, endTime: data.currentRoom.endTime, playerCount: data.currentRoom.currentPlayer.length,
isEnter: false, player: data.playingData
});
}
else if (data.playingData.isAlive)
{
data.playingData.defeat();
data.currentRoom.announceToRoom('userDisconnect', data.playingData);
}
isEnable: false, endTime: 0, playerCount: data.currentRoom.currentPlayer.length,
isEnter: false, player: data.playingData
});
data.currentRoom.currentPhase = GameServer.Phase.READY;
}
GameServer.currentPlayer.splice(idxToDel, 1);
else data.currentRoom.announceToRoom('setRoomCount',
{
isEnable: true, endTime: data.currentRoom.endTime, playerCount: data.currentRoom.currentPlayer.length,
isEnter: false, player: data.playingData
});
}
else if (data.playingData.isAlive)
{
data.playingData.defeat();
data.currentRoom.announceToRoom('userDisconnect', data.playingData);
}
console.log('['+ data.id +'] disconnect complete');
}
});
});
\ No newline at end of file
GameServer.currentPlayer.splice(idxToDel, 1);
}
console.log('['+ data.id +'] disconnect complete');
}
\ No newline at end of file
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