Jump to content
McKay Development

Recommended Posts

Posted

When a trade is declined it spams trade state code like 2-6 times. Makes DB work shitty. Lol

 

15bed5e0b5da2207b7f8ccc52f4d595d.png

manager.on('sentOfferChanged', function(offer, oldstate){
        if(offer.state == TradeOfferManager.ETradeOfferState.Countered){
            offer.cancel(function(err){
                if(err){
                    console.log('Unable to cancel offer:' + err.message);
                } else {
                    db.query("UPDATE `tTradeOffer` SET `sTradeStatus` = 'Cancelled' WHERE `sTradeId` = '"+ offer.id +"'");
                    console.log('TradeID: '+offer.id+' has been cancelled due to countered!');
                    io.sockets.in(socket.room).emit('notifyUser', {'msg': 'Trade has been cancelled due to user sending counter offer!', 'status': 'Countered'});
                    socket.leave(socket.room);
                }
            });
        }
        if(offer.state === TradeOfferManager.ETradeOfferState.Declined){
            db.query("UPDATE `tTradeOffer` SET `sTradeStatus` = 'Declined' WHERE `sTradeId` = '"+ offer.id +"'");
            console.log('TradeID: '+offer.id+' has been declined!');
            io.sockets.in(socket.room).emit('notifyUser', {'msg': 'You have declined the trade!', 'status': 'Declined'});
            socket.leave(socket.room);
        }
        if(offer.state === TradeOfferManager.ETradeOfferState.Accepted){
            db.query("UPDATE `tTradeOffer` SET `sTradeStatus` = 'Completed' WHERE `sTradeId` = '"+ offer.id +"'");
            db.query("SELECT * FROM `tTradeOffer` WHERE `sTradeId` = '"+offer.id+"'")
                .on('result', function(data){
                    db.query("UPDATE `tUserProfile` SET `decCurrentStar` = `decCurrentStar` + "+data.decTradeValue+", `decTotalStar` = `decTotalStar` + "+data.decTradeValue+" WHERE `sUserId` = '"+data.sUserId+"'");
                });
            console.log('TradeID: '+offer.id+' has been accepted!');
            io.sockets.in(socket.room).emit('tradeCompleted', {'msg': 'Trade offer has been processed and Stars added to your wallet!', 'userId': offer.id, 'status': 'Accepted'});
            socket.leave(socket.room);
        }
        if(offer.state === TradeOfferManager.ETradeOfferState.Canceled){
            db.query("UPDATE `tTradeOffer` SET `sTradeStatus` = 'Canceled (Time Out)' WHERE `sTradeId` = '"+ offer.id +"'");
            console.log('TradeID: '+offer.id+' has been canceled (Time Out)');
            io.sockets.in(socket.room).emit('notifyUser', {'msg' : 'Trade has been cancelled due to it Timing Out!', 'status': 'TimeOut'});
            socket.leave(socket.room);
        }
    });
Posted
if(offer.state === TradeOfferManager.ETradeOfferState.Accepted){
            db.query("UPDATE `tTradeOffer` SET `sTradeStatus` = 'Completed' WHERE `sTradeId` = '"+ offer.id +"'");
            db.query("SELECT * FROM `tTradeOffer` WHERE `sTradeId` = '"+offer.id+"'")
                .on('result', function(data){
                    db.query("UPDATE `tUserProfile` SET `decCurrentStar` = `decCurrentStar` + "+data.decTradeValue+", `decTotalStar` = `decTotalStar` + "+data.decTradeValue+" WHERE `sUserId` = '"+data.sUserId+"'");
                });
            console.log(' \n\nTradeID: '+offer.id+' has been accepted! \nTime \nCreated: '+offer.created+' \n Updated: '+offer.updated+'\n Unix Timestamp: '+Math.round((new Date()).getTime() / 1000));
            io.sockets.in(socket.room).emit('tradeCompleted', {'msg': 'Trade offer has been processed and Stars added to your wallet!', 'userId': offer.id, 'status': 'Accepted'});
            socket.leave(socket.room);
        }

I believe so, its as if the event is getting fired multiply times.

Posted (edited)

fe5b3fb5bfe26d122fb2397e572d50a0.png

 

It appears to be pooling data twice? I cleared polldata.json, brought it from doing 6 times events to 2 times.

 

polldata.json

{"sent":{"1034893770":10,"1034895513":10,"1034896997":10,"1034903572":6,"1034915198":7,"1041181202":6,"1041184909":6,"1041184976":6,"1041198226":7,"1041198228":7,"1041198235":7,"1041198241":7,"1041227475":7,"1041258820":7,"1041264865":7,"1041266894":7,"1041269762":7,"1041270306":7,"1041303401":4,"1041313907":4,"1041320193":4,"1041322812":4,"1064257061":7,"1064298530":7,"1064300059":7,"1064307068":7,"1064314258":7,"1064323700":8,"1064324672":7,"1064378975":7,"1064383046":7,"1064384285":7,"1064387997":8,"1064389814":7,"1064390873":7,"1064391678":7,"1064392526":7,"1064394166":7,"1064404382":7,"1064405564":7,"1064408919":7,"1064420187":7,"1064422503":7,"1064425516":7,"1064429611":7,"1068452543":7,"1068458052":7,"1068469202":7,"1068473023":7,"1068478026":7,"1068484537":7,"1068489893":7,"1068492720":7,"1068493908":7,"1068502809":7,"1068555312":7,"1068557608":7,"1068560944":7,"1068562155":4,"1068563831":7,"1068568681":7,"1084335181":7,"1088682909":7,"1088699841":7,"1088706741":7,"1088708868":7,"1088709889":7,"1088712246":7,"1088713221":7,"1088716781":7,"1088726254":7,"1088728512":7,"1096180532":7,"1096181815":7,"1096190180":7,"1096303901":7,"1096304825":7,"1096365169":6,"1096384246":6,"1096446953":6,"1096450541":6,"1096452663":6,"1096455044":6,"1096458799":7,"1096460199":6,"1096464298":7,"1096464621":7,"1096466391":7,"1096467748":7,"1096468676":6,"1096470357":7,"1096478203":7,"1096483242":6,"1096485509":6,"1096487509":7,"1096489086":7,"1096491065":7,"1096521915":7,"1096522557":6,"1096525541":7,"1096526253":7,"1096526980":7,"1096528132":6,"1096554905":7,"1096555656":7,"1098654082":7,"1098664295":7,"1100819431":7,"1100865289":3,"1100889446":3,"1100902913":3,"1100906179":3,"1100908034":3,"1100914778":3,"1100930880":3,"1101009374":7,"1103017270":3,"1103023446":3,"1103026156":3,"1103037540":3,"1103043730":3,"1103459769":3,"1103461075":3,"1103462635":3},"received":{"1041303965":6,"1041314678":6,"1041321535":6,"1041323145":6,"1064365940":7,"1068562604":6}}
Edited by Argyl

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...