Results 1 to 7 of 7

Thread: Managing bots on various worlds using PHP & MySQL (& Storing other data)

  1. #1
    Join Date
    May 2012
    Posts
    58
    Mentioned
    2 Post(s)
    Quoted
    23 Post(s)

    Default Managing bots on various worlds using PHP & MySQL (& Storing other data)

    If you're running a gold farm the last thing you want are your bots competing against each other for resources. By setting up a database to reserve worlds you'll never have this problem again.

    The first thing you'll need to do is set up the database. There are guides to do this on villavu forums.

    I use phpMyAdmin to view my dataabase.

    Create a table called "Worlds" with primary key "World" (int) and "InUse" (int). Once done, insert each world (1-150) & 0 for the InUse field (see below)


    Your database is now ready to receive world information

    We now need to write some php scripts to receive & pass information from our simba script to the database.

    Save the following code as worldmanager.php on your server.
    PHP Code:
    <?php 
        $user_name 
    "Justin69";  //Username for the account you created
        
    $pass_word "69969";  //Password for the account you created
        
    $database "world_manager";  //The name of the database you created 
        
    $server "localhost";   

        
    $theaction=$_GET['action']; //Now we're creating the variables we're passing through the URL
        
    $world=$_GET['world'];    

        if (
    $theaction=='getworld'){
        
            
    $db_handle mysql_connect($server$user_name$pass_word); 
            
    $db_found mysql_select_db($database$db_handle);  
            
            if (
    $db_found) { 
                    
    //This query will return 1 if the world is free, 0 if taken
                
    $SQL "SELECT CASE WHEN InUse =0 THEN TRUE ELSE FALSE END AS InUse FROM Worlds WHERE world = $world";
                
    $result mysql_query($SQL); 

                if(
    $result){  
                    while (
    $db_field mysql_fetch_assoc($result)){  
        
                        
    $InUse $db_field['InUse'];     
                        print 
    $InUse//prints "1" for our simba script to read

                    
    }
                }else 
                    print 
    "Table not found";  
             
            }else 
                print 
    "Database not found";  
        }elseif (
    $theaction=='takeworld'){
        
            
    $db_handle mysql_connect($server$user_name$pass_word); 
            
    $db_found mysql_select_db($database$db_handle);  
            
            if (
    $db_found) { 
        
                
    $SQL "UPDATE Worlds SET InUse = 1 WHERE world = $world";
                
                
    $result mysql_query($SQL); 
                
                if(
    $result){  
                    print 
    "1";                 
                }else 
                                    print 
    "0"
                
            }else 
                print 
    "Database not found";  
        }elseif (
    $theaction=='clearworld'){
        
            
    $db_handle mysql_connect($server$user_name$pass_word); 
            
    $db_found mysql_select_db($database$db_handle);  
            
            if (
    $db_found) { 
                                    
                
    $SQL "UPDATE Worlds SET InUse = 0 WHERE world = $world";
                
                
    $result mysql_query($SQL); 
                
                if(
    $result){  
                    print 
    "1";                 
                }else 
                    print 
    "0"
                
            }else 
                print 
    "Database not found";  
                
        }else
         print 
    "Failed";
    ?>
    Now in your simba script you will use the following functions to access the database

    Simba Code:
    var
        currentWorld : Integer;

    //checkWorld checks if the passed world is taken, return true if available, false if in use by another bot.
    function checkWorld(world : Integer) : Boolean;
    begin
      if (GetPage('http://www.domain.it/worldmanager.php?action=getworld&checkworld=' + IntToStr(world)) = '1') then
        exit(true)
      else
        exit(false);
    end;

    //Returns the first available world in the database and sets it as occupied.
    //Declare constant WORLD_LIST at the start of your list to have create a desired world order for your bots. ex
    //WORLD_LIST = [2,77,64,100,10,84,56,4,23,45,31,105,5,119,14,54,123,103,9,16,67,39,22,60,98,99,22,1,69,134,139,6,32,71,24,46,70,21,88,40,44,26,36,28];
    function getFreeWorld() : Integer;
    var
      i : Integer;
    begin
      for i := 0 to length(WORLD_LIST) - 1 do
      begin
        if checkWorld(WORLD_LIST[i]) then
        begin
          if not (GetPage('http://www.domain.it/worldmanager.php?action=takeworld&world=' + IntToStr(WORLD_LIST[i])) = '1') then
            writeln('ERROR WRITING WORLD TO DATABASE!')
          else
            writeln('World ', WORLD_LIST[i], ' successfully reserved!');
          currentWorld := WORLD_LIST[i];
          exit(currentWorld);
        end;
      end;
      exit(-1);
    end;

    //Call this function to release the world from database on terminate
    procedure setWorldClear();
    begin
      if not (GetPage('http://www.domain.it/worldmanager.php?action=clearworld&world=' + IntToStr(currentWorld)) = '1') then
        writeln('ERROR CLEARING WORLD FROM DATABASE!')
      else
        writeln('World ', currentWorld, ' successfully freed.');
    end;

    And that's it. From here you can add more variables and further automate your gold farm.

    What you can do with a database is pretty much limitless - if you're running a gold farm you need to be storing as much data as possible

    Here are some ideas of what to do with data stored by your scripts
    -See which account is in which world
    -Run 1 script to log in all your bots queueing username/passwords
    -See how world populations effect spawn rates (& profit/hour) & better refine your world list
    -Know exactly how much money is on an account
    -Calculate average ban rates based on script versions
    -Know exactly when to resupply an account/trade profits off
    -Store bond activation date & avoid accounts going f2p
    -Track which worlds your bots get banned on most frequently
    -Let friends run your scripts, track & charge a % of their profits

    Note: You can store this data locally in text files but if you run bots from various computers/servers they'll end up interfering with each other & your statistics will be inaccurate.

    Good luck!

  2. #2
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Very nice tutorial @Justin69; - I created something similar to this when I was running a small farm, could easily see what part of the script was running and also request a screenshot of the client(s)

    Forum account issues? Please send me a PM

  3. #3
    Join Date
    Jun 2015
    Location
    New Zealand
    Posts
    322
    Mentioned
    2 Post(s)
    Quoted
    131 Post(s)

    Default

    Thanks for posting this useful guide. I'll try and apply it. +REP

  4. #4
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Can you perhaps link me a guide on how to set up a local database?

  5. #5
    Join Date
    Dec 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Nice! This is pretty cool

  6. #6
    Join Date
    Jul 2015
    Posts
    80
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

    Let friends run your scripts, track & charge a % of their profits
    How would you do that?

  7. #7
    Join Date
    Mar 2016
    Location
    Scandinavia
    Posts
    138
    Mentioned
    3 Post(s)
    Quoted
    46 Post(s)

    Default

    Quote Originally Posted by guer666 View Post
    Let friends run your scripts, track & charge a % of their profits
    hehe, as long as they dont edit the code

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •