【发布时间】:2018-11-16 00:10:51
【问题描述】:
我有一个服务器端功能来检查玩家是否空闲
socket.idle = 0;
socket.cached = {};
socket.checkIdle = function(){
socket.idle++;
console.log(socket.idle);
if(socket.cached.x != players[id].x || socket.cached.y != players[id].y){
socket.idle=0;
}
socket.cached = players[id];
if(socket.idle>12){
socket.disconnect();
}
}
socket.interval = setInterval(socket.checkIdle,1000);
我注意到,即使在播放器启动/断开连接时间过长之后也是如此。服务器仍然控制台为它记录 socket.idle。
我是不是走错了路?我还应该清除播放器断开连接的时间间隔吗?
socket.on('disconnect', function(){
clearInterval(socket.interval);
});
【问题讨论】:
标签: node.js websocket multiplayer