Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ====================================================================================================
  2. // v THIS IS THE JUNK YOU'LL WANT TO EDIT v
  3. // Frendless leech starter setting (set to run with op gotv channel bot by default there will be no help on changing this)
  4. // ====================================================================================================
  5. var gamenames = ["Game-"];                          // Game name to search for (CASE-SENSITIVE)
  6.  
  7. var gamepasswords   = [""];                             // Password for that game.
  8.  
  9. var maxRetriesPerGame   = 3;                    // The # of times to try rejoining a *unique* game
  10. var maxRetries      = 3;                    // The # of *different* games to try joining, if all attempts fail, bot will exit to character selection screen and rejoin lobby
  11.  
  12. // ====================================================================================================
  13.  
  14. var gameMinLength           = 200000;       // time in milliseconds, minimum game length, 180 seconds default (1 game/3 minutes)
  15. var unableToConnectRetry    = 5;            // time in minutes to retry connecting on connection fail (real value is +/- 1 min)
  16. var realmDownRetry          = 260;          // time in minutes to retry connecting on a realm down (default is 120 minutes)
  17. var disconnectedRetry       = 5;            // time in minutes to retry on a disconnection (usually ip ban related)
  18. var cdkeyInUseRetry         = 1;            // time in minutes to retry on a cdkey in use error message (set to 0 to stop)
  19. var connectingToBnetTimeout     = 20000;        // time in milliseconds to wait for a login to time out and click cancel and retry
  20. var characterScreenTimeout      = 5000;         // time in milliseconds to wait for character screen to appear
  21. var pleaseWaitTimeout       = 2000;         // time in milliseconds to wait for a please wait popup
  22. var createGameThreshold         = 2000;         // time in milliseconds to wait between making games
  23. var createGameThresholdRandom   = 500;          // time in milliseconds to randomly add +/- to the game create time
  24. var createGameTimeout       = 15000;        // time in milliseconds to register a failed to create game
  25. var waitInLineTimeout       = 60000;        // time in milliseconds to wait in lines for a create game (60 second default)
  26. var characterSelectDelay    = 1000;         // time in milliseconds to wait before selecting a character on the char screen
  27. var loginDelay          = 1000;         // time in milliseconds to wait before submitting login information
  28. var clickDelay          = 500;          // wait X milliseconds before next action after a click event
  29. var textDelay           = 500;          // wait X milliseconds before next action after inserting text into a textbox
  30. var clickDelayRandom        = 500;          // random amount of time to add to a click
  31. var textDelayRandom         = 500;          // random amount of time to add to a text set
  32. var gameDoesNotExistDelayMin    = 1000;         // how long to wait when a Game Does Not Exist occurs - minimum - default 10 minutes
  33. var gameDoesNotExistDelayMax    = 2000;         // how long to wait when a Game Does Not Exist occurs - maximum - default 15 minutes
  34. var gameDoesNotExistTimeout = 50;           // how long to wait for the dialog to disappear (default 30 seconds, don't change this)
  35. var waitBeforeEnterChatMin      = 1000;         // min how long to wait before entering chat
  36. var waitBeforeEnterChatMax      = 2000;         // max how long to wait before entering chat
  37. var waitInChatBeforeActionsMin  = 1000;         // min how long to wait before joining channel
  38. var waitInChatBeforeActionsMax  = 2000;         // max how long to wait before joining channel
  39.  
  40. // DONT EDIT ANYTHING BELOW THIS
  41. var extrafilters    = ["New game ", " started by"]; // The 2nd filter should be whatever the bot manager says right after the game name
  42.                                                     // If the 2nd filter is empty, the rest of the line is used as the game name
  43. var joinChannelInChat   = "op gotv";                // leave blank to not join a private channel
  44.  
  45. // D2NT Manager Command
  46. const D2NT_MGR_LOADING = 1;
  47. const D2NT_MGR_READY = 2;
  48. const D2NT_MGR_LOGIN = 3;
  49. const D2NT_MGR_CREATE_GAME = 4;
  50. const D2NT_MGR_INGAME = 5;
  51. const D2NT_MGR_RESTART = 6;
  52. const D2NT_MGR_CHICKEN = 7;
  53. const D2NT_MGR_PRINT_STATUS = 8;
  54. const D2NT_MGR_PRINT_LOG = 9;
  55.  
  56. var lastGameMade = GetTickCount();
  57. var nextGameMake = 0;
  58. var inGameAt = 0;
  59. var chatActionsDone = false;
  60. var lastGameStatus = 0; // 0 = OK, 1 = Processing, 2 = Ready for retry
  61. var game = "";
  62. var gamepassword = "";
  63. var retry = 0;
  64. var fullretry = maxRetries;
  65. var samegame = new Array(gamenames.length); // Empty array for however many runs you might be following (default 6)
  66.  
  67. Include("libs/controlInfo.ntl");
  68.  
  69. var controlData = new controlInfo();
  70.  
  71. function NTMain()
  72. {
  73.     Delay(1000);
  74.  
  75.     var _ingame = false;
  76.  
  77.     controlData.clickDelay = clickDelay;
  78.     controlData.textDelay = textDelay;
  79.     controlData.clickDelayRandom = clickDelayRandom;
  80.     controlData.textDelayRandom = textDelayRandom;
  81.  
  82.     while (1)
  83.     {
  84.         if (me.ingame)
  85.         {
  86.             if (!inGameAt)
  87.                 inGameAt = GetTickCount();
  88.  
  89.             if (!_ingame)
  90.             {
  91.                 RunGC(); // run garbage collector between each game
  92.  
  93.                 if (Load("NTBot/NTBotGame.ntj"))
  94.                 {
  95.                     _ingame = true;
  96.  
  97.                     if (me.playtype > 0)
  98.                         sendEventToOOG(D2NT_MGR_INGAME, "In Game.. [IP:" + me.gameserverip.split(".")[3] + "]", 0);
  99.                     else
  100.                         sendEventToOOG(D2NT_MGR_INGAME, "In Game..", 0);
  101.  
  102.                     fullretry = maxRetries;
  103.                     lastGameStatus = 0;
  104.                     game = "";
  105.                 }
  106.             }
  107.  
  108.             Delay(1000);
  109.         }
  110.         else
  111.         {
  112.             Delay(500);
  113.             if (_ingame)
  114.             {
  115.                 _ingame = false;
  116.  
  117.                 // --------------------------
  118.                 // Prevent NT from closing D2
  119.                 // --------------------------
  120.  
  121.                 // Wait for lobby or lobby chat
  122.                 var _location;
  123.                 do
  124.                 {
  125.                     _location = controlData.getLocation();
  126.                     Delay(50);
  127.                 }
  128.                 while (_location.id != 3 && _location.id != 1);
  129.  
  130.                 if (_location.id == 3) // Lobby Chat
  131.                 {
  132.                     // We need to go somewhere besides the lobby chat so NT can type crap and think its creating a game
  133.                     Delay(100);
  134.                     Say("/join " + getRandomString(Random(3,10)));
  135.                     Delay(1000);
  136.                 }
  137.                 sendEventToOOG(D2NT_MGR_CREATE_GAME, _location.name, 0);
  138.                 outputGameLength();
  139.                 setNextGameMake();
  140.                 // --------------------------
  141.  
  142.                 sendEventToOOG(D2NT_MGR_READY, "", 0);
  143.             }
  144.  
  145.             locationAction(controlData.getLocation());
  146.  
  147.             Delay(500);
  148.         }
  149.     }
  150. }
  151.  
  152. function locationAction(location)
  153. {
  154.     switch (location.id)
  155.     {
  156.         case 3: // Lobby Chat
  157.  
  158.             // Not retrying anymore, clear the game name so that if user tries to do it themself, bot won't fill in with old game
  159.             if (lastGameStatus == 0 || retry == 0)
  160.             {
  161.                 // Clear these flags just in case
  162.                 retry = 0;
  163.                 game = "";
  164.             }
  165.  
  166.             // Handle non-existent or full games:
  167.             // When the join button is hit, lastGameStatus = 1.
  168.             // When in-game, lastGameStatus = 0.
  169.             // So this gets executed when NTMain() doesn't reset the flag to 0.
  170.             if (lastGameStatus == 1)
  171.             {
  172.                 if (fullretry == 0) // If we have tried [maxRetries] different games ([maxRetriesPerGame] retries for each game)
  173.                 {
  174.                     lastGameStatus = 0;
  175.                     fullretry = maxRetries;
  176.  
  177.                     // We need to close out of chat and come back
  178.                     sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿE00000Game doesn't exist or its full. Rejoining chat.", 0);
  179.                     controlData.click(controlData.controls.lobby.button.quit);
  180.                 }
  181.                 else
  182.                 {
  183.                     lastGameStatus = 2; // Ready for retry
  184.  
  185.                     if (retry == 0) // If we just failed [maxRetriesPerGame] times for joining this game
  186.                         fullretry--;  // Update flag
  187.  
  188.                     sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿE00000Game doesn't exist or its full. " + retry + " retries left.", 0);
  189.  
  190.                     inGameAt = Random(gameDoesNotExistDelayMin, gameDoesNotExistDelayMax);
  191.                     setNextGameMake();
  192.                     chatActionsDone = true; // Undo the flag set by setNextGameMake()
  193.  
  194.                     locationTimeout(gameDoesNotExistTimeout, location);
  195.                 }
  196.                 break;
  197.             }
  198.  
  199.             if (!chatActionsDone || GetTickCount() > nextGameMake + 180000) // Need to join channel or its been 3 minutes and no action, possibly kicked from channel, rejoin
  200.             {
  201.                 if (GetTickCount() > nextGameMake + 180000) // Reset this so that we don't keep joining channel over and over
  202.                     nextGameMake = GetTickCount();
  203.  
  204.                 chatActionsDone = true;
  205.                 Delay(Random(waitInChatBeforeActionsMin, waitInChatBeforeActionsMax));
  206.  
  207.                 Say("/join " + joinChannelInChat);
  208.                 Delay(1000);
  209.                 sendEventToOOG(D2NT_MGR_PRINT_LOG, "Looking for games..", 0);
  210.             }
  211.  
  212.             // Time for action?
  213.             if (GetTickCount() >= nextGameMake)
  214.             {
  215.                 sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  216.  
  217.                 // If we can retry and there is a game to retry
  218.                 if (retry > 0 && game != "" && lastGameStatus == 2)
  219.                 {
  220.                     controlData.click(controlData.controls.lobby.button.join);
  221.                     retry--;
  222.                     break;
  223.                 }
  224.  
  225.                 var chat = controlData.get(controlData.controls.lobby.chat.textBox.channelText);
  226.                 if (chat)
  227.                 {
  228.                     var linewithname = "";
  229.                     lines = chat.GetText();
  230.                     if (lines)
  231.                     {
  232.                         for (var line = 0; line < lines.length; line++)
  233.                         {
  234.                             linewithname = lines[line];
  235.  
  236.                             for (var _filterindex = 0; _filterindex < extrafilters.length; _filterindex += 2)
  237.                             {
  238.                                 // Check filters
  239.                                 if (linewithname.lastIndexOf(extrafilters[_filterindex]) != -1 && linewithname.lastIndexOf(extrafilters[_filterindex+1]) != -1)
  240.                                 {
  241.                                     for (var _gameindex = 0; _gameindex < gamenames.length; _gameindex++)
  242.                                     {
  243.                                         // Check for game name
  244.                                         var index = linewithname.lastIndexOf(gamenames[_gameindex]);
  245.                                         if (index > -1)
  246.                                         {
  247.                                             game = linewithname.substring(index, linewithname.lastIndexOf(extrafilters[_filterindex+1]));
  248.                                             gamepassword = gamepasswords[_gameindex];
  249.        
  250.                                             if (game != "" && game != samegame[_gameindex])
  251.                                             {
  252.                                                 sendEventToOOG(D2NT_MGR_PRINT_LOG, "Joining " + game + "..", 0);
  253.                                                 samegame[_gameindex] = game;
  254.                                                 controlData.click(controlData.controls.lobby.button.join);
  255.                                                 retry = maxRetriesPerGame;
  256.                                                 break;
  257.                                             }
  258.                                         }
  259.                                     }
  260.                                 }
  261.                             }
  262.                         }
  263.                     }
  264.                 }
  265.             }
  266.             else
  267.                 sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((nextGameMake-GetTickCount())/1000) + "s)", 0);
  268.             break;
  269.  
  270.         case 1: // Lobby
  271.  
  272.             // Enter chat
  273.             Delay(Random(waitBeforeEnterChatMin, waitBeforeEnterChatMax));
  274.             controlData.click(controlData.controls.lobby.button.enterChat);
  275.             break;
  276.  
  277.         case 2: // Waiting In Line
  278.             if (GetTickCount()-lastGameMade > waitInLineTimeout)
  279.                 controlData.click(controlData.controls.lobby.inLine.button.cancel);
  280.             break;
  281.  
  282.         case 4: // Create Game
  283.             break;
  284.  
  285.         case 5: // Join Game
  286.             if (game != "")
  287.             {
  288.                 sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  289.  
  290.                 controlData.setText( controlData.controls.lobby.join.editBox.gameName, game);
  291.                 Delay (1250);
  292.                 controlData.setText( controlData.controls.lobby.join.editBox.password, gamepassword);
  293.                 Delay (1250);
  294.                 controlData.click(controlData.controls.lobby.join.button.joinGame);
  295.             }
  296.  
  297.             lastGameMade = GetTickCount();
  298.             lastGameStatus = 1;
  299.             break;
  300.  
  301.         case 6: // Ladder
  302.             break;
  303.  
  304.         case 7: // Channel List
  305.             break;
  306.  
  307.         case 8: // Main Menu
  308.             if (controlData.getCurrentRealmIndex() == me.gatewayid)
  309.             {
  310.                 outputGameLength();
  311.                 controlData.click(controlData.gameTypes[me.playtype]);
  312.             }
  313.             else
  314.                 controlData.click(controlData.controls.mainMenu.button.gateway);
  315.             break;
  316.  
  317.         case 9: // Login
  318.             sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  319.             Delay(loginDelay);
  320.  
  321.             controlData.setText(controlData.controls.login.editBox.accountName, me.account);
  322.  
  323.             sendEventToOOG(D2NT_MGR_LOGIN, location.name, 0);
  324.  
  325.             locationTimeout(5000, location);
  326.             break;
  327.  
  328.         case 10: // Login Error (this is a fatal error, so stop)
  329.             sendEventToOOG(D2NT_MGR_RESTART, location.name, 10);
  330.             Delay(3500);
  331.             break;
  332.  
  333.         case 11: // Unable To Connect
  334.             timeoutDelay(unableToConnectRetry*60*1000, location)
  335.             controlData.click(controlData.controls.login.unableToConnect.button.ok);
  336.             break;
  337.  
  338.         case 12: // Character Select
  339.             var _time, _control;
  340.  
  341.             sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  342.  
  343.             for (_time = 0; _time < characterScreenTimeout; _time += 500)
  344.             {
  345.                 _control = controlData.get(controlData.controls.characterSelect.textBox.characterInfo[me.charloc]);
  346.                 if (_control && _control.GetText() != undefined)
  347.                     break;
  348.  
  349.                 Delay(500);
  350.             }
  351.  
  352.             if (_time < characterScreenTimeout)
  353.             {
  354.                 Delay(characterSelectDelay);
  355.  
  356.                 controlData.click(controlData.controls.characterSelect.textBox.characters[me.charloc], 0, 0, 1);
  357.                 controlData.click(controlData.controls.characterSelect.textBox.characterInfo[me.charloc], 0, 0, 1);
  358.  
  359.                 // reset last game made, so it doesnt make a game immediately
  360.                 inGameAt = 0;
  361.                 setNextGameMake();
  362.             }
  363.             else
  364.             {
  365.                 controlData.click(controlData.controls.characterSelect.button.exit);
  366.                 timeoutDelay(realmDownRetry*60*1000, location);
  367.             }
  368.             break;
  369.  
  370.         case 13: // Realm Down - Character Select screen
  371.             controlData.click(controlData.controls.characterSelect.button.exit);
  372.             timeoutDelay(realmDownRetry*60*1000, location);
  373.             break;
  374.  
  375.         case 14: // Character Select - Disconnected
  376.             timeoutDelay(disconnectedRetry*60*1000, location);
  377.             controlData.click(controlData.controls.characterSelect.disconnected.button.ok);
  378.             break;
  379.  
  380.         case 15: // New Character
  381.             break;
  382.  
  383.         case 16: // Character Select - Please Wait popup
  384.             if (!locationTimeout(pleaseWaitTimeout, location))
  385.                 controlData.click(controlData.controls.characterSelect.pleaseWait.button.cancel);
  386.             break;
  387.  
  388.         case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  389.             controlData.click(controlData.controls.lobby.lostConnection.button.ok);
  390.             break;
  391.  
  392.         case 18: // D2 Splash
  393.             controlData.click(controlData.controls.d2Splash.textBox.copyright);
  394.             break;
  395.  
  396.         case 19: // Login - Cdkey In Use
  397.             timeoutDelay(cdkeyInUseRetry*60*1000, location);
  398.             controlData.click(controlData.controls.login.cdkeyInUse.button.ok);
  399.             break;
  400.  
  401.         case 20: // Single Player - Select Difficulty
  402.             controlData.click(controlData.singlePlayerDifficulties[me.diff]);
  403.             break;
  404.  
  405.         case 21: // Main Menu - Connecting
  406.             if (!locationTimeout(connectingToBnetTimeout, location))
  407.                 controlData.click(controlData.controls.mainMenu.connecting.button.cancel);
  408.             break;
  409.  
  410.         case 22: // Login - Invalid Cdkey (classic or xpac)
  411.             sendEventToOOG(D2NT_MGR_RESTART, location.name, 3600);
  412.             Delay(3500);
  413.             break;
  414.  
  415.         case 23: // Character Select - Connecting
  416.             if (!locationTimeout(characterScreenTimeout, location))
  417.                 controlData.click(controlData.controls.characterSelect.button.exit);
  418.             break;
  419.  
  420.         case 24: // Server Down - not much to do but wait..
  421.             break;
  422.  
  423.         case 25: // Lobby - Please Wait
  424.             if (!locationTimeout(pleaseWaitTimeout, location))
  425.                 controlData.click(controlData.controls.lobby.pleaseWait.button.cancel);
  426.             break;
  427.  
  428.         case 26: // Lobby - Game Name Exists
  429.             sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿE00000Game already exists.", 0);
  430.  
  431.             inGameAt = 0;
  432.             setNextGameMake();
  433.  
  434.             locationTimeout(15000, location);
  435.             break;
  436.  
  437.         case 27: // Gateway Select
  438.             controlData.clickRealmEntry(me.gatewayid);
  439.             controlData.click(controlData.controls.gateway.button.ok);
  440.             break;
  441.  
  442.         case 28: // Lobby - Game Does Not Exist
  443.             // This is handled in the lobby chat
  444.  
  445.             // Get rid of the message (DNE/Full game) so the lobby chat can handle
  446.             controlData.click(controlData.controls.lobby.button.create);
  447.             Delay(200);
  448.             controlData.click(controlData.controls.lobby.create.button.cancel);
  449.             break;
  450.  
  451.         default:
  452.             break;
  453.     }
  454. }
  455.  
  456. function sendEventToOOG(locationId, statusString, pendingTime)
  457. {
  458.     return SendCopyData("D2NT Manager", null, (locationId<<16)|pendingTime, statusString);
  459. }
  460.  
  461. function setNextGameMake()
  462. {
  463.     lastGameMade = GetTickCount();
  464.     nextGameMake = lastGameMade + createGameThreshold + Random(0-createGameThresholdRandom, createGameThresholdRandom) + inGameAt;
  465.     inGameAt = 0;
  466.     chatActionsDone = false;
  467. }
  468.  
  469. function outputGameLength()
  470. {
  471.     if (inGameAt)
  472.     {
  473.         duration = GetTickCount() - inGameAt;
  474.  
  475.         inGameAt = (duration < gameMinLength ? gameMinLength - duration : 0);
  476.     }
  477. }
  478.  
  479. function locationTimeout(time, location)
  480. {
  481.     endtime = GetTickCount() + time;
  482.  
  483.     while (controlData.getLocation().id == location.id && endtime > GetTickCount())
  484.     {
  485.         sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  486.         Delay(500);
  487.     }
  488.  
  489.     return (controlData.getLocation().id != location.id);
  490. }
  491.  
  492. function timeoutDelay(time, location)
  493. {
  494.     endtime = GetTickCount() + time;
  495.  
  496.     while (endtime > GetTickCount())
  497.     {
  498.         sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  499.         Delay(1000);
  500.     }
  501. }
  502.  
  503. function getRandomString(_length)
  504. {
  505.     _retString = "";
  506.     _charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
  507.  
  508.     while (_length--)
  509.     {
  510.         _retString += _charSet.charAt(Random(0, _charSet.length-1));
  511.         Delay(1);
  512.     }
  513.  
  514.     return _retString;
  515. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement