Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Buy OSRS Gold

Sell OSRS Gold
Sign in to follow this  
JoeDezzy1

Login Helper

Recommended Posts

In the past, I've experienced consistency issues with certain methods in the API that return false/inconsistent information on certain occasions, especially upon logins.

Here is something I've created a while ago that became very useful to combat that issue.

 

import org.tribot.api.General;
import org.tribot.api2007.Game;
import org.tribot.api2007.Login;

/**
 * @author JDezzy1
 */
public class LoginAccess extends Login implements Access {
	/**
	 * The amount of settings in the gamesettings array to confirm consistency
	 * in ingame data
	 */
	public static final transient int settingsArrayLength = 70;
	/**
	 * The ban message upon logging in
	 */
	public static final transient String BAN_HOOK = "Your account has been disabled. Please check your message-centre for details.";

	/*
	 * (non-Javadoc)
	 * 
	 * @see scripts.dezapi.wrappers.accessor.Access#access()
	 */
	@Override
	public Class<Login> access() {
		return Login.class;
	}

	/**
	 * @return true if in game
	 */
	public static boolean inGame() {
		final STATE ST8 = getLoginState();
		return ST8 != null && ST8.equals(STATE.INGAME);
	}

	/**
	 * @return true if at the login screen
	 */
	public static boolean inLoginScreen() {
		final STATE ST8 = getLoginState();
		return ST8 != null && ST8.equals(STATE.LOGINSCREEN);
	}

	/**
	 * @return true if at the welcome screen
	 */
	public static boolean inWelcomeScreen() {
		final STATE ST8 = getLoginState();
		return ST8 != null && ST8.equals(STATE.WELCOMESCREEN);
	}

	/**
	 * @return true if there is a ban message
	 */
	public static boolean banMessage() {
		final String response = Login.getLoginResponse();
		return response != null && response.equals(BAN_HOOK);
	}

	/**
	 * Does what it says
	 * 
	 * @return Game setting.length > ~70 plus all other hooks
	 */
	public static boolean isEverythingFuckingLoadedAndReadyToBeRead() {
		return !inWelcomeScreen() && inGame() && Game.getGameState() == 30
				&& Game.getSettingsArray().length >= settingsArrayLength;
	}

	/**
	 * @return true if the login was successful
	 */
	public static boolean waitLogin() {
		return Waiting07.waitCondition(() -> {
			return isEverythingFuckingLoadedAndReadyToBeRead();
		}, System.currentTimeMillis() + General.randomSD(35000, 45000, 4250));
	}

	/**
	 * @return true if the logout was successful
	 */
	public static boolean waitLogout() {
		return Waiting07.waitCondition(() -> {
			return inLoginScreen();
		}, System.currentTimeMillis() + General.randomSD(35000, 45000, 4250));
	}

	/**
	 * 
	 * @param user
	 * @param pass
	 * @return
	 */
	public static boolean handleLogin(final String user, final String pass) {
		General.println("Login => attempting login => " + user);
		if (login(user, pass)) {
			General.println("Login => waiting for login...");
			if (waitLogin()) {
				General.println("Login => logging in => successful login");
				return true;
			}
		}
		return false;
	}
}

 

  • Thanks 1

Share this post


Link to post
Share on other sites
Array

Good snippet, but let me add some suggestions.

 

Some of the methods aren't needed. I'm pretty sure "getLoginState" can't return null, so you don't need all that extra calculation. It would make more sense to just do "Login.getLoginState() == [state]". Plus, if you are checking to see what state you're in, calling these methods recalculates the login state each time, when it would be easier to call it once and do a switch statement.

 

Also, not a single comment in this code is needed. Proper policy would suggest you either use them to explain the "why" and "when to use", not the "how". And empty comments or "does what it says" just gets in the way. I know this might sound nitpicky, but it's common courtesy when posting public code. The only comments that do this are your "wait..." method comments.

 

I do quite like the ban-detecting snippet, though. I might add that into my framework.

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

  • Similar Content

    • By ELON
      OVERVIEW:
      Completes The Mage Cape Quest FX Easy To Use Gui Paint Custom Equipment Support Custom Inventory Support (automatically recognizes if you have Prayer potions) Magic Prayer Support Custom Spell Support (Max Fire Bolt) Message Me if you want me to add the death rune spells  
      DESCRIPTION: 
      Travels to Edgeville if you are not at the mage bank deposits your equipment and inventory and withdraws a knife and then travels to the mage bank arena using the Edgeville wildly tele lever.
      If die by a pker it will run back to edgeville and tele up again and run to the mage bank.
      It does not support death at the mage arena when fighting the bosses currently you should very rarely die there if ever if using  prayer.
      Once at the mage bank arena it will withdraw your custom equipment and inventory and select the spell you have selected in the GUI and start the mage arena quest.
      After you have killed the bosses it will grab 3 capes and ends the script.
       
      SCRIPT LINK: https://tribot.org/repository/script/id/3602
    • By jerrycan314
      when i open a tribot client it crashes and i get this error :c

      #
      # A fatal error has been detected by the Java Runtime Environment:
      #
      #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7a0e3d9d, pid=1608, tid=0x00000e54
      #
      # JRE version: Java(TM) SE Runtime Environment (8.0_251-b08) (build 1.8.0_251-b08)
      # Java VM: Java HotSpot(TM) Client VM (25.251-b08 mixed mode windows-x86 )
      # Problematic frame:
      # C  [atiglpxx.dll+0x3d9d]
      #
    • By ELON
      DESCRIPTION:
      Progressive Training Smart Object Detector Smart FireMaking Pathing Easy To Use FX GUI  Save/Load Paint Fully Open Source Automatically Detects Nearest Supported Location Automatically Detects Nearest Bank To Nearest Supported Location Supported Locations:
      Grand Exchange North/South Varrock Seers Village EdgeVille Post Me If You Want A (Certain Area Supported)
       
      How It Finds Your FireMaking Path/Starting FireMaking Tile:
      it creates A area from your nearest supported FireMaking location Tile
      which then each tile from the Area is added to a list and the list is then shuffled for
      better randomness/Anti-Ban then it checks if each tile in the left direction starting from
      the first Tile in the List has no objects if no objects are found it returns the Tile
      from the list as your starting FireMaking Tile.
       
      Script Link: https://tribot.org/repository/script/id/3567
      Source Link: https://github.com/Elon333/Scripts
    • By Realist
      Need Tribot credits for scripts/VIP etc? You're at the right place!
      or
      Do you have credits you want to SELL? Message me!
      I accept cash & 07 Gold/ Rs3 Gold / CS:GO Skins.
       
      1-5 credits is 3m each, other amounts = 1.8-2.3m per credit
       
      Skype is live:realistgold
       
      Discord: Realist#1834 
      Unique Discord ID: 194091681836957696
    • By Heroinkid
      Hi I got a proxy server from Virmach. I cannot seem to get Tribot to connect to it. I have gotten a 3rd party internet browser called Maxthus to get it to work so I don't think that its the server that's not working. Yes I have VIP-E as well. Please help thanks!

    • By ELON
      [ FREE ]   ELON Combat AIO  [ Open Source ] 
       

       
      . Description:
      Train Combat Anywhere Banking support Looting support Potion support ABC2 LVL10 Free Fully Open Source JavaFx Gui Paint  GET SCRIPT HERE: https://tribot.org/repository/script/id/3549
      SOURCE LINK: https://github.com/Elon333/Scripts
      P.S.
      If you have any questions, about the script or the source feel free to post me on here.
      Feedback on source or script is appreciated good or bad.
      What Feature would You Like to see Added Next?
    • By QNDLF
      Has been fine for the past few days however doesn't work today, have deleted the full .jar file and redownloaded again and it has the same problem
       
      Any ideas how to fix it? 
       

    • By Optimus
      Optimus AIO Firemaker is a free All In One Firemaking script that's efficient and easy to use.
      Overview:
      Start the script with one click. It will automatically detect which logs to use from your inventory or bank, and progressively train your firemaking until you run out of logs.

      ~ Withdraws tinderbox if you don't have one
      ~ Supports all logs types
      ~ Progressive training - Will automatically start burning better logs if they're available
      ~ Smart algorithm to detect best area to burn
      ~ One-tick burning
      ~ Logs out when out of logs
      ~ ABC2 Antiban
      ~ Sleek paint
      ~ Lit AF 
      Supports 8 different locations:
      (The script will automatically detect the nearest location)
      ~ Varrock West
      ~ Varrock East
      ~ Grand Exchange North
      ~ Grand Exchange South
      ~ Falador East
      ~ Draynor Village
      ~ Duel Arena
      ~ Seers Village
      ~ More to come (Open to suggestions).
      Gallery:




      Free repository link:


       
      Hope you all enjoy the script! Feedback is appreciated  
    • By Sidesteppin12
      I decided to create my own banking API that mimics tribots way of implementing the API as much as possible. Basically it would only contain nothing more than just method calls. Simple and easy to use.
      This API is a reworked version that is currently in my jHerblore script. I intend to release my GE api as well once I have finished that one up too. The API requires DaxWalker & Wastedbro's Item Price API. Other than that the rest is achieveable with standard dependencies that already comes with tribot.
      All of the method names are the same as the ones from Banking & GrandExchange class in tribot, with a few exceptions, the only difference is that these methods are called with different class names such as Banker & Exchanger, so they do not collide with the Banking & GrandExchange class of tribot and cause an ambiguity problem.
       
      List of available methods:
       
      Some of the features this API offers:
      - Methods that incorporate any form of withdrawing or depositing do not need you to first check if the bank is open nor if it is loaded. It will attempt to open the bank if it is not open before returning false, and wait for bank to load if it is not loaded yet.
      - Methods that incorporate any form of buying or selling do not need you to first check if the exchange window is open. It will attempt to open the exchange window if it is not open before returning false.
      - Deselector. All methods that require the mouse to click somewhere on the screen first check if an item or spell is selected, if it is then it will deselect whatever is selected before attempting the requested action.
      - Additional failsafes, not just the deselector. Tribots banking api does not know if what you were trying to click actually was succesfully clicked. Instead it views succesfully calling the click function as a succesfull attempt. It's kind of like playing pin the nail to the donkey game. It does not know if it pinned it at the right location, but as long as it pinned it the function returns true. This is not true for all methods, some methods do actually check if the action was succesfully performed, however they do not reattempt the action if it failed. 1 call = 1 attempt. My api will reattempt any action that might fail, several times, before returning false and will also wait until inventory count is updated. For example using the tribot banking API if you were to deposit all your items and then immediately check your available inventory space before withdrawing items then it might not work as you wish because Banker.depositAll() returns before the action of depositing has finished.
      - When banking, closes GrandExchange window if it is open.
      - When buying/selling, closes the bank screen if it is open.
      - Support for withdrawing items in noted format and with or without stack exception. Stack exception is basically if you wish to draw X amount of items in your inventory but you only had Y left, then you can choose if you wish to draw these items or not. Also supports depositing of noted item ids if you happen to pass a list with of items that contains items of unnoted item ids, but the item in your inventory is a noted version of the item in your inventory. Also will not deposit equipment or items if you have none equipped or in your inventory. There is a total of 4 different depositing methods and 16 different withdrawing methods.
      - Unique dynamic sleeping method, all methods that should sleep already have sleeps implemented so you do not need to call a sleep after executing any of the methods. Involves random varying sleeps but will occasionally, every so often, in a irregular pattern, sleep a bit longer. I use this because I prefer it over General.sleep(). Feel free to replace it with whichever method you wish. Remember before running the main loop in your script to call:
      jGeneral.get().generateSeed(); This will create a random number between 0-100 that will be added to your dynamic sleeps in milliseconds. This is so no bot has the same average reaction/sleeping time.
      - When buying items on the GE, if the bot does not have any money or too little money in the inventory, it will check if you have enough of the missing amount in the bank and withdraw that amount.
      - Custom buying method that checks for an exact string match of the item you wish to buy and chooses that one from the returned items in the buy window search box. The standard GE api does not do this and will for instance click the wrong herb when it searches for "Guam leaf" in the grand exhcange, this is because more than one item contains "guam leaf" in their name. Such as Grimy guam leaf and so on.
      - Profit tracking when buying/selling items on the GE. This is optional.
       
      GET THE SOURCE HERE!
       
      UPDATES:
      - Pushed new updates that fix some of the methods that I've tested a bit for now, bit of logic and efficiency improvements. Also added 2 new depositing methods. Remember to replace the old java files with the new ones.
      - Pushed even more updates. Fixed interface problem for withdrawing noted items. My GE api is now also been released to the public. Enjoy!
  • Our picks

    • Over the past few months, I’ve been working diligently on a new project - TRiBot X. Everything has been written from the ground up, with all of the best practices of software engineering. Every aspect of TRiBot has been re-imagined to support three main goals: flexibility, useability, and reliability.
        • Like
      • 50 replies
    • Come give us feedback on the next version of TRiBot!
        • Thanks
        • Like
      • 86 replies
    • TRiBot is looking to improve a lot of its customer relationship management, customer on boarding process, customer experience, design elements, community engagement and pretty much everything else you can imagine when it comes to marketing.

      Our goal: To ensure that the marketing done TRULY reflects the experience and does not shine an inaccurate light on what TRiBot is lacking in.

      So I ask, what do you love about TRiBot and what do you hate about TRiBot? What does O S Bot, Rune M8, PowR Bot and Dre amBot do better? (yes I purposely didn't spell it right 😂).

      Love, 

      RileyZ
        • Like
      • 25 replies
    • Over the last three weeks, I've been working on upgrading our server infrastructure. It's finally ready and is now live!

      Why?

      Increased reliability - less server errors


      Increased availability - less downtime


      Increased security - keeping us and you secure


      Increased capacity - ability to serve you better


      Increased speed - less waiting for things to load


      Faster development - server and service updates will come faster


      What are the changes?

      Move from a single AWS EC2 instance to AWS ECS (Elastic Container Service)


      Distributed computing


      Load balancing


      Git management of server files and filesystem


      Redis caching


      How?

      AWS ECS (with 10 EC2 instances)


      AWS ElastiCache (Redis)


      AWS Load Balancing


      AWS EFS (Elastic file system)


      Please bare with us as I continue to tune the server for maximum performance. Slow loading speeds may occur temporarily. I thank everyone for their patience.

      Please post on this thread if you experience any issues other than slow loading times.
        • Like
      • 51 replies
    • This release will:

      Fix prayers and world hopper API (Thanks @JoeDezzy1 and @erickho123)


      Improve banking API (Thanks @Encoded)


      Adds methods for returning and using Java Lists, rather than arrays


      Slightly randomizes some hardcoded behaviour


      Removes sleeps from waitConditions; the efficiency saving potential is negligible in these use-cases, therefore cleaner code is preferable


      Other back-end improvements





      Note: If you are using LG, please restart both the RS client and TRiBot.
        • Sad
        • Haha
        • Thanks
        • Like
      • 90 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...