Argyl Posted March 23, 2016 Report Share Posted March 23, 2016 When a trade is declined it spams trade state code like 2-6 times. Makes DB work shitty. Lol 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); } }); Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted March 23, 2016 Report Share Posted March 23, 2016 Can you add timestamps? Quote Link to comment Share on other sites More sharing options...
Argyl Posted March 23, 2016 Author Report Share Posted March 23, 2016 Timestamp doesn't break it down to the second, but then tried unix timestamp. Same thing, its instant. :/ Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted March 24, 2016 Report Share Posted March 24, 2016 The unix timestamp in the second screenshot is the current time when the message was printed? Quote Link to comment Share on other sites More sharing options...
Argyl Posted March 24, 2016 Author Report Share Posted March 24, 2016 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. Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted March 24, 2016 Report Share Posted March 24, 2016 I haven't seen any issues like this. What's your polling interval set to? Can you attach a listener to the "debug" event and print that to the console? manager.on('debug', console.log); Quote Link to comment Share on other sites More sharing options...
Argyl Posted March 24, 2016 Author Report Share Posted March 24, 2016 (edited) 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 March 24, 2016 by Argyl Quote Link to comment Share on other sites More sharing options...
Argyl Posted March 25, 2016 Author Report Share Posted March 25, 2016 Any idea? Been tryin different things to now avail. Quote Link to comment Share on other sites More sharing options...
Argyl Posted March 25, 2016 Author Report Share Posted March 25, 2016 Aswell, I removed and made it so it couldn't access polldata and still doing trade offer poll twice every ten seconds. Quote Link to comment Share on other sites More sharing options...
Argyl Posted March 27, 2016 Author Report Share Posted March 27, 2016 Well Mark this as solved haha. Problem was my socket client. It was firing an event for every single connection to the page.Thanks! Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted March 28, 2016 Report Share Posted March 28, 2016 Welp Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.