PostAutoTrader source code

Posts 1–15 of 15 · Page 1 of 1
AutoTrader source code
A while back i promised to post the source code for AutoTrader if it breaks down - so here it is...
(i don't have the time to continue development myself, but it might be useful for quite a number of people here)



Some things to consider:
1) The code is in Java and is quite complex, but may still help if you want to build you own bot
2) It will only work with IntelliJ Idea compiler (eclipse will not work because of the custom gui builder)
3) After installing IntelliJ, you need to specify JDK (java development kit) (after downloading/installing JDK - select the location of JDK in project settings)
3) AutoTrader is a Client, not a proxy, which means that it sends/receives packets directly from the game server. (unlike a proxy, which intercepts packets between the .swf client and server)
4) For those who succeed and manage to launch it from source code - there is an interesting feature (new tab) as a reward...

Some more things to consider:
The bot is not really broken - it should work fine except for the trade exploit (swapping items before trading a bot will result in accepting the trade even if the wrong items are selected)
Code at your own risk - author is not responsible for any brain damage / depression / insomnia that may arise due to the complexity of the code.


Also - i may be monitoring this thread for a while, so you can ask questions here


Virus scans: (updated)
virusTotal
JottiScan
AutoTrader_SourceCode_mpgh.net.zip2.8 MB · 87 downloads Clean
Source_And_Some_Comments_mpgh.net.zip2.8 MB · 82 downloads 1/42 malicious
Thank you very much sir.
I like the Umbrella Corp symbol.. lol

EDIT: All I need are some fresh party hats and i'll be in business!
So after quite a long time of testing and adjusting things.. Because the trade window doesn't always reflect the person's actual inventory at the time of trading, I cannot seem to come up with a method of making this bot 100% reliable. If there was a way to display the items as they are in the trade window, it would be.. I'll have to try other things when I have more time, but i'm rather stumped right now.
For some reason, I actually find this code easier than the proxy o.O... But still Y U NO ADD COMMENTS?
Quote Originally Posted by UltraN00b View Post
For some reason, I actually find this code easier than the proxy o.O... But still Y U NO ADD COMMENTS?
I'm just too lazy, but specially for you i added a (poorly) commented version.
2nd attachment approved.
Has anyone succeeded in building a version (newer than the 1.05 that is publicly available)? The 1.05 version just keeps crashing on me which is less than ideal
Quote Originally Posted by shiznid12 View Post
Because the trade window doesn't always reflect the person's actual inventory at the time of trading
Quote Originally Posted by Hubble View Post
The bot is not really broken - it should work fine except for the trade exploit (swapping items before trading a bot will result in accepting the trade even if the wrong items are selected)
This is not an exploit but a major design flaw in your code.

You need to base the entire trade transaction on the information from the TRADE_START packet. Your trade partner's name, your inventory and your trade partner's inventory have to be parsed/obtained via TRADE_START. Inventories MUST NOT be assumed/derived from UPDATE or NEW_TICK packets likewise your trade partner's name MUST NOT be taken from the TRADE_REQUESTED packet.

This is exactly WHY the server does send the name, and both inventories via TRADE_START to serve as a reference point to base the trade on. You get "exploited" or "cheated" because you base the trade on other information than what it says within the TRADE_START packet. Period.

Here is how to do it correctly ... the code was taken from my actual bots who have been trading items for potions for many month without anyone being able to "exploit" them. Note how i store my trade partner's name and both inventories from the TRADE_START packet and base the rest of the trade and all decisions on that information. Also i don't see why the code of a trade bot should be complex?

Code:
   when('TRADE_REQUESTED'){
    my $myself=$rotmg->getObjectById($rotmg->{'objectId'});
    my $bool_wantToTrade=0;
    $packet->decompile;
    if(defined $admins{$packet->name}){ # admins
     $bool_wantToTrade=1;
    }else{
     my $buyer=$rotmg->getObjectByPlayerName($packet->name);
     my $inventory=$buyer->inventory;
     my $myPotionCount=sum(values($myself->inventory->getCount(\%potions,'carry')));
     my $myNonPotionItemCount=scalar(keys %{$myself->inventory->get('carry',\%potions)});
     if($myPotionCount>0 || $myNonPotionItemCount==0){
     my $playertext=Rotmg::Packet->new('PLAYER_TEXT');
      $playertext->text('/tell ' . $buyer->name . ' I am sold out - check back later ' . $buyer->name . ' - thx!');
      $playertext->compile;
      $rotmg->sendPacket($playertext);
     }else{
      $bool_wantToTrade=1;
      my $playertext=Rotmg::Packet->new('PLAYER_TEXT');
      $playertext->text('/tell ' . $buyer->name . ' The price for all my items is just a single att/def/vit/life/mana potion, ' . $buyer->name . '!');
      $playertext->compile;
      $rotmg->sendPacket($playertext);
     }
    }
    if($bool_wantToTrade==1){
     print '[ALSO REQUESTING TRADE] name:' . $packet->name . "\n";
     my $requesttrade=Rotmg::Packet->new('REQUEST_TRADE');
     $requesttrade->name($packet->name);
     $requesttrade->compile;
     $rotmg->sendPacket($requesttrade);
    }
   }
   when('TRADE_START'){
    $packet->decompile;	
    $rotmg->{'boolTrading'}=1;
    $rotmg->{'lastTradeStartTime'}=time();
    $rotmg->{'currentTradePartnerName'}=$packet->name;
    print "\n\n";
   	print '[TRADESTART] receiving initial inventory from ' . $packet->name . "\n";
    # sometimes you get a TRADESTART packet with a person who was actually not the last person you agreed to trade with but the one shortly before!?!?!
    # so set the trade variables within the TRADESTART context to be safe ...
    
    my $myItems=$packet->myItems;
   	my $yourItems=$packet->yourItems;
   	$rotmg->{'currentTradeOwnInventory'}=$myItems;
   	$rotmg->{'currentTradeBuyerInventory'}=$yourItems;

   	my $inventorySlotsToOffer_ref=undef;
   	if(defined $admins{$packet->name}){
   	 $inventorySlotsToOffer_ref=$myItems->get('carry');
   	 print "\t" . 'OFFERING ALL ... YOU ARE AN ADMIN' . "\n";
    }else{
     $inventorySlotsToOffer_ref=$myItems->get('carry',\%potions);
    }
    print '[CHANGETRADE] our offer:' . join(',',keys(%$inventorySlotsToOffer_ref)) . "\n";
    my $changetrade=Rotmg::Packet->new('CHANGE_TRADE');
    $changetrade->inventorySlotsToOffer($inventorySlotsToOffer_ref);
    $changetrade->compile;
    $rotmg->sendPacket($changetrade);	
   } 
   when('TRADE_ACCEPTED'){
   	print '[TRADEACCEPTED] buyer suggested a trade ($rotmg->{\'currentTradePartnerName\'}=' . $rotmg->{'currentTradePartnerName'} . ')' . "\n";
   	$packet->decompile;
   	my $bool_acceptTrade=0;
   	if(defined $admins{$rotmg->{'currentTradePartnerName'}}){
   	 print "\t" . 'ACCEPTING TRADE ... YOU ARE AN ADMIN ' . "\n";
   	 $bool_acceptTrade=1;
   	}else{
   	 my $myOffer=$packet->myOffer;
   	 my $yourOffer=$packet->yourOffer;
   	 my $numberOfPotionsIAmOffering=sum(values($rotmg->{'currentTradeOwnInventory'}->getCount(\%potions,$myOffer)));
   
   	 print '$numberOfPotionsIAmOffering:' . $numberOfPotionsIAmOffering . ' $numberOfPotionsBuyerIsOffering:' . $numberOfPotionsBuyerIsOffering . "\n";
   	 if($numberOfPotionsIAmOffering==0 && $numberOfPotionsBuyerIsOffering>=1){
   	  print "\t" . 'I GIVE NO POTION ... YOU GIVE 1+ POTION ... WE GOT A DEAL ... ;-))' . "\n";
   	  $bool_acceptTrade=1;
   	 }else{
   	  print "\t" . 'NO DEAL :-((' . "\n";
   	  my $playertext=Rotmg::Packet->new('PLAYER_TEXT');
      $playertext->text('/tell ' . $rotmg->{'currentTradePartnerName'} . ' ' . $rotmg->{'currentTradePartnerName'} . ', your offer does not include a att/def/vit/life/mana potion!');
      $playertext->compile;
      $rotmg->sendPacket($playertext);
   	 }
   	}
   	if($bool_acceptTrade==1){
     my $accepttrade=Rotmg::Packet->new('ACCEPT_TRADE');
     $accepttrade->data($packet->dataBackup); # if the trade is ok just take the raw TRADEACCEPTED data and send it back ...
     $rotmg->sendPacket($accepttrade);
    }
   }
Got any tips on how to fix the current code, to stop it from crashing at least, I've tried a few things and couldn't get it to run stable.
How about debugging it/running a trace? Also what do you mean with "crashing"? Does it raise an exception? Maybe work from there?
Sorry yeah I should of included that in my post

java****.EOFException
at Z.S.readInt(Z/S)
at Z.OZ.I(Z/OZ)
at Z.OZ.<init>(Z/OZ)
at Z.RI.I(Z/RI)
at com.trader.bot.I.run(com/trader/bot/I)

I will try what you said thanks, I'm new to java only written css and php before so it's completely different.
Posts 1–15 of 15 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us