NodeJS有时表现得很怪异! (错误)

时间:2017-02-28 11:05:35

标签: javascript node.js

有时我的NodeJS控制台给了我这些错误,但我不太明白它们: Image

这种情况很少发生,并不总是发生。大部分时间它运行得很好但有时它只返回上面提供的错误。我有点失落了。

代码(我认为发生错误的地方):

if(canPlayersBet == '1') {
    if((usersCr[user.steamid] !== undefined) && (usersCr[user.steamid] == CRbr)) {
        socket.emit('message', {
            type: 'error',
            enable: true,
            error: 'You have already joined the crash.'
        });
        return;
    }
    if((m.amount < minbet) || (m.amount > maxbet)) {
        socket.emit('message', {
            type: 'error',
            enable: true,
            error: 'Invalid bet amount ['+minbet/1000+'-'+maxbet/1000+'].'
        });
        return;
    }
    if(/(a|b|c|d|e|f|g|h|j|i|k|l|m|n|o|p|q|r|s|t|v|u|w|x|y|z)/.exec(m.amount)) {
        socket.emit('message', {
            type: 'error',
            enable: true,
            error: 'Invalid bet amount.'

        });
        return;
    }
    if(crashState != 'STARTING' && usersCr[user.steamid] != CRbr) {
        socket.emit('message', {
            type: 'error',
            enable: true,
            error: 'The game have been already started!'
        });
        return;
    }

    var start_time = new Date();
        query('SELECT `balance` FROM `users` WHERE `steamid` = '+pool.escape(user.steamid), function(err, row) {
            if((err) || (!row.length)) {
                logger.error('Failed to find DB');
                logger.debug(err);
                socket.emit('message', {
                    type: 'error',
                    enable: true,
                    error: 'You are not DB'
                });
                return;
            }
            if(row[0].balance >= m.amount) {        
                query('UPDATE `users` SET `balance` = `balance` - '+parseInt(m.amount)+' WHERE `steamid` = '+pool.escape(user.steamid), function(err2, row2) {
                    if(err2) {
                        logger.error('Error in withdraw');
                        logger.debug(err);
                        socket.emit('message', {
                            type: 'error',
                            enable: true,
                            error: 'You dont have enough points'
                        });
                        return;
                    }
                    query('INSERT INTO `crbets` SET `user` = '+pool.escape(user.steamid)+', `amount` = '+pool.escape(m.amount)+', `autoCashout` = '+pool.escape(m.autoCash), function(err3, row3) {
                        if(err3) {
                            logger.error('Error in DB');
                            logger.debug(err);
                            return;
                        }
                        var end = new Date();
                        if(usersCr[user.steamid] === undefined) {
                            usersCr[user.steamid] = 1;
                        }
                        if(CRusersAmount[user.steamid] === undefined) {
                            CRusersAmount[user.steamid] = {
                                'amount': m.amount,
                                'autoCashout': m.autoCash
                            };
                        }
                        CRusersAmount[user.steamid]['amount'] += parseInt(m.amount);
                        socket.emit('message', {
                            type: 'crbetconfirm',
                            bet: {
                                betid: row3.insertId,
                                amount: m.amount,
                                autoCashout: m.autoCash
                            },
                            balance: row[0].balance-m.amount,
                            mybr: usersCr[user.steamid],
                            br: CRbr,
                            exec: (end.getTime()-start_time.getTime()).toFixed(3)
                        });
                        users[user.steamid].balance = row[0].balance-m.amount;
                        io.sockets.emit('message', {
                            type: 'crbet',
                            bet: {
                                amount: m.amount,
                                autoCashout: m.autoCash,
                                betid: row3.insertId,
                                icon: user.avatar,
                                name: user.name,
                                user: user.steamid
                            }
                        });
                        CRcurrentBets.push({
                            autoCashout: m.autoCash,
                            amount: m.amount,
                            betid: row3.insertId,
                            icon: user.avatar,
                            name: user.name,
                            user: user.steamid,
                            won: '0'
                        });
                        socket.emit('message', {
                            type: 'setIsPlaying'
                        });
                        totalBet = totalBet+m.amount;
                        logger.debug('CRBet confirmed #'+row3.insertId+' | Amount: '+m.amount+' | AutoCashout: '+m.autoCash+' | User: '+pool.escape(user.steamid));
                        checkTimer();
                    })
                });
            } else {
                socket.emit('message', {
                    type: 'error',
                    enable: true,
                    error: 'Error: You dont have any money.'
                });
            }
        });
}else {
    socket.emit('message', {
        type: 'error',
        enable: true,
        error: 'Error: You cannot bet, because the bet is offline.'
    });
}

1 个答案:

答案 0 :(得分:0)

我的猜测是以下一行是错误的

users[user.steamid].balance = row[0].balance-m.amount;

例如。 users[user.steamid]undefined