session.uid是否可以绑定字符串

pomelo源码里明明告诉我们只能绑定数字,偏偏在chatofpomelo里绑定了字符串,被欺骗感情了
pomelo源码:

/**
 * Bind the session with the the uid.
 *
 * @param {Number} uid User id
 * @api public
 */
Session.prototype.bind = function(uid) {
  this.uid = uid;
  this.emit('bind', uid);
};

/**
 * Unbind the session with the the uid.
 *
 * @param {Number} uid User id
 * @api private
 */
Session.prototype.unbind = function(uid) {
  this.uid = null;
  this.emit('unbind', uid);
};

chatofpomelo源码

handler.enter = function(msg, session, next) {
    var self = this;
    var rid = msg.rid;
    var uid = msg.username + '*' + rid
    var sessionService = self.app.get('sessionService');

    //duplicate log in
    if( !! sessionService.getByUid(uid)) {
        next(null, {
            code: 500,
            error: true
        });
        return;
    }

    session.bind(uid);
    session.set('rid', rid);
    session.push('rid', function(err) {
        if(err) {
            console.error('set rid for session service failed! error is : %j', err.stack);
        }
    });
    session.on('closed', onUserLeave.bind(null, self.app));

    //put user into channel
    self.app.rpc.chat.chatRemote.add(session, uid, self.app.get('serverId'), rid, true, function(users){
        next(null, {
            users:users
        });
    });
};
标签: 灌水闲聊 bug 反馈
MissLee 在 5-10 16:37发布 分享到 weibo
3 回复
#1 MissLee 5-18 16:37 回复

有人回答吗?可以绑定object和string类型吗?如果可以的话。kickout的时候怎么判断相等呢?

#2 MissLee 5-18 16:38 回复

尤其是object类型,因为mongodb的_id就是object类型

#3 MissLee 5-18 17:14 回复

解决了,可以绑定string,不能绑定object,因为通过===判断相等

回到顶部