Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.16 KB | None | 0 0
  1. //credit for this goes to D2od who knows way more than I do
  2.  
  3. // =============================================================================
  4. // Leader Account settings
  5. // =============================================================================
  6. var leaderAccountName = "sinmf";
  7. var leaderName = "gvBot";
  8.  
  9. // =============================================================================
  10. // Game password (leave blank if none)
  11. // =============================================================================
  12. var gamepassword = "gv";
  13.  
  14. // =============================================================================
  15. // UseCDKeyChangeTrick :
  16. // if true, the follow bot will say his gamename/gamepwd (set in the OOG) in chat before each game
  17. // in order to increment his number of runs (to switch CDKeys after xx runs)
  18. // if false, the follow bot will never change his CDKey
  19. // =============================================================================
  20. var UseCDKeyChangeTrick = true;
  21.  
  22. // =============================================================================
  23. // Debug : set to true if you are experiencing problems with your JoinBot
  24. // it will log in your OOG the lobby chat actions
  25. // =============================================================================
  26. var Debug = false;
  27.  
  28. ////////////////////////////////////////////////////////////////////////////////
  29. // Lobby chat settings :
  30. ////////////////////////////////////////////////////////////////////////////////
  31.  
  32. // Set to true to join the chat after each game (needed for JoinBot)
  33. var joinChatAfterGame = true;
  34.  
  35. // Message said when you first enter the chat
  36. var firstJoinMessage = "";
  37.  
  38. // Message said after each game
  39. var chatMessageAfterGame = "";
  40.  
  41. // if this is true, will join a random channel, otherwise it will use the channel below..
  42. var joinRandomChannel = false;
  43. // Name of the channel you want to join (leave blank if you want to stay in the default channel)
  44. var joinChannelInChat = "op bhod";
  45.  
  46.  
  47. ////////////////////////////////////////////////////////////////////////////////
  48. // Delays:
  49. ////////////////////////////////////////////////////////////////////////////////
  50.  
  51. // Minimum game length, waits in the lobby if last game was too short
  52. // I recommend to keep a value > 300000 (milliseconds) to avoid bnet temporary ban
  53. var gameMinLength = 420000;
  54.  
  55. // realm delays (minutes)
  56. var unableToConnectRetry = 5;
  57. var realmDownRetry = 120;
  58. var disconnectedRetry = 5;
  59. var cdkeyInUseRetry = 5;
  60.  
  61. // interface delays (milliseconds)
  62. var connectingToBnetTimeout = 20000;
  63. var characterScreenTimeout = 10000;
  64. var pleaseWaitTimeout = 10000;
  65. var createGameThreshold = 10000;
  66. var createGameThresholdRandom = 1000;
  67. var createGameTimeout = 15000;
  68. var waitInLineTimeout = 15000;
  69. var characterSelectDelay = 1000;
  70. var loginDelay = 1000;
  71. var clickDelay = 500;
  72. var textDelay = 500;
  73. var clickDelayRandom = 500;
  74. var textDelayRandom = 500;
  75. var gameDoesNotExistDelayMin = 600000;
  76. var gameDoesNotExistDelayMax = 900000;
  77. var gameDoesNotExistTimeout = 30000;
  78. var waitBeforeEnterChatMin = 1000;
  79. var waitBeforeEnterChatMax = 2000;
  80. var waitInChatBeforeActionsMin = 2000;
  81. var waitInChatBeforeActionsMax = 3000;
  82.  
  83. // Only for JoinBot (friend list delay, milliseconds)
  84. var LeaderOfflineDelay = 30000;
  85. var LeaderInChatDelay = 10000;
  86. var GameIsFullDelay = 30000;
  87.  
  88. ////////////////////////////////////////////////////////////////////////////////
  89. ////////////////////////////////////////////////////////////////////////////////
  90. // DO NOT EDIT ANYTHING BELOW THIS
  91. ////////////////////////////////////////////////////////////////////////////////
  92. ////////////////////////////////////////////////////////////////////////////////
  93.  
  94. //D2NT Manager Command
  95.  
  96. const D2NT_MGR_LOADING = 1;
  97. const D2NT_MGR_READY = 2;
  98. const D2NT_MGR_LOGIN = 3;
  99. const D2NT_MGR_CREATE_GAME = 4;
  100. const D2NT_MGR_INGAME = 5;
  101. const D2NT_MGR_RESTART = 6;
  102. const D2NT_MGR_CHICKEN = 7;
  103. const D2NT_MGR_PRINT_STATUS = 8;
  104. const D2NT_MGR_PRINT_LOG = 9;
  105.  
  106. var lastGameMade = GetTickCount();
  107. var lastGameStatus = 0;
  108. var nextGameMake = 0;
  109. var inGameAt = 0;
  110. var chatActionsDone = false;
  111. var lastGameFailed = false;
  112. var sayChatMsgAfterGame = false;
  113.  
  114. Include("libs/controlInfo.ntl");
  115.  
  116. var controlData = new controlInfo();
  117.  
  118. var game = '';
  119. var _gamename = "";
  120. var _gamepassword = "";
  121. var _leaderOfflineTick = -LeaderOfflineDelay;
  122. var _leaderInChatTick = -LeaderInChatDelay;
  123. var _GameIsFullTick = -GameIsFullDelay;
  124.  
  125. function NTMain()
  126. {
  127. Delay(1000);
  128.  
  129. var _ingame = false;
  130.  
  131. controlData.clickDelay = clickDelay;
  132. controlData.textDelay = textDelay;
  133. controlData.clickDelayRandom = clickDelayRandom;
  134. controlData.textDelayRandom = textDelayRandom;
  135.  
  136. while(1)
  137. {
  138. if(me.ingame)
  139. {
  140. _gamename = me.gamename;
  141. _gamepassword = me.gamepassword;
  142.  
  143. if(!inGameAt)
  144. inGameAt = GetTickCount();
  145.  
  146. if(!_ingame)
  147. {
  148. RunGC(); // run garbage collector between each game
  149.  
  150. if(Load("NTBot/NTBotGame.ntj"))
  151. {
  152. _ingame = true;
  153.  
  154. if(me.playtype > 0)
  155. sendEventToOOG(D2NT_MGR_INGAME, "In Game[IP:" + me.gameserverip.split(".")[3] + "]", 0);
  156. else
  157. sendEventToOOG(D2NT_MGR_INGAME, "In Game", 0);
  158.  
  159. lastGameStatus = 2; // in game successful
  160.  
  161. // To exit game as soon as the leader quits
  162. //Load("NTBot/NTCheckLeader.ntj");
  163. // to party only the leader
  164. //Load("NTBot/tools/NTTools_AutoPartyJoinFriendGames.ntj");
  165. }
  166. }
  167.  
  168. Delay(1000);
  169. }
  170. else
  171. {
  172. if(_ingame)
  173. {
  174. _ingame = false;
  175. sayChatMsgAfterGame = true;
  176.  
  177. sendEventToOOG(D2NT_MGR_READY, "", 0);
  178. }
  179.  
  180. locationAction(controlData.getLocation());
  181.  
  182. Delay(500);
  183. }
  184. }
  185. }
  186.  
  187. function locationAction(location)
  188. {
  189. switch(location.id)
  190. {
  191. case 3: // Lobby Chat
  192. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  193.  
  194. if(!chatActionsDone)
  195. {
  196. Delay(Random(waitInChatBeforeActionsMin, waitInChatBeforeActionsMax));
  197.  
  198. if(joinRandomChannel || joinChannelInChat != "")
  199. {
  200. Say("/join " + (joinRandomChannel ? getRandomString(Random(3,10)) : joinChannelInChat));
  201. Delay(1000);
  202. }
  203.  
  204. if(firstJoinMessage)
  205. {
  206. Say(firstJoinMessage);
  207. Delay(200);
  208. }
  209.  
  210. chatActionsDone = true;
  211. }
  212.  
  213. if (chatMessageAfterGame && _gamename != "" && sayChatMsgAfterGame == true)
  214. {
  215. Say(chatMessageAfterGame);
  216. sayChatMsgAfterGame = false;
  217. Delay(200);
  218. }
  219.  
  220. game = '';
  221.  
  222. var _tick = GetTickCount();
  223. if ((_leaderOfflineTick < 0 || (_leaderOfflineTick + LeaderOfflineDelay) < _tick)
  224. && (_leaderInChatTick < 0 || (_leaderInChatTick + LeaderInChatDelay) < _tick)
  225. && (_GameIsFullTick < 0 || (_GameIsFullTick + GameIsFullDelay) < _tick))
  226. {
  227. DebugInOOG('Locating the leader : '+leaderAccountName);
  228. Say('/f l');
  229. Delay(1500);
  230. }
  231.  
  232. if(chat = controlData.get(controlData.controls.lobby.chat.textBox.channelText))
  233. {
  234. var found_leader = false;
  235. lines = chat.GetText();
  236. for (var line_id = lines.length - 1; line_id > -1; line_id--)
  237. {
  238. if (found_leader) // useless... :/
  239. break;
  240.  
  241. if (lines[line_id].substring(0,1) == " ")
  242. continue;
  243.  
  244. // retrieving the whole message
  245. var msg = lines[line_id].replace(/^\s+|\s+$/, "");
  246. var msglines = 1;
  247. while (lines[line_id+msglines] != undefined && lines[line_id+msglines].substring(0,2) == " ")
  248. {
  249. msg += " " + lines[line_id+msglines].replace(/^\s+|\s+$/, "");
  250. msglines++;
  251. }
  252. if (msg.lastIndexOf(leaderName) >= 0)
  253. DebugInOOG("yc8found him :;"+msg);
  254.  
  255. // checking if the msg is a friendly whisper
  256. if (msg.lastIndexOf(leaderName + ' (*' +leaderAccountName+')') > -1)
  257. {
  258. var regGameNameWhispered=/^.*(game|partie|spiel|partita|partida).*(nomm[^\s]*|called|chiamata)\s*([\w\s-]*\w)\s*\.\s*$/gi;
  259. if (msg.match(regGameNameWhispered))
  260. game = msg.replace(regGameNameWhispered, "$3");
  261.  
  262. if (game != '')
  263. {
  264. found_leader = true;
  265. break;
  266. }
  267. }
  268.  
  269. // checking if the msg is from the friend list
  270. if (msg.lastIndexOf(': '+leaderAccountName+',') > -1)
  271. {
  272. found_leader = true;
  273. var regOffline=/^.*(offline|desconectado).*$/gi;
  274. var regInChat=/^.*(channel|canale?)\s*([\w\s-]*\w)\.?\s*$/gi;
  275. var regGameName=/^.*(game|partie|spiel|partita|partida)\s*([\w\s-]*\w)\s*\(priv[^\)]*\)\.\s*$/gi;
  276.  
  277. if (msg.match(regOffline)
  278. && (_leaderOfflineTick < 0 || (_leaderOfflineTick + LeaderOfflineDelay) < _tick))
  279. {
  280. DebugInOOG('Leader is offline, delay '+Math.round(LeaderOfflineDelay/1000)+' sec for next /f l.');
  281. _leaderOfflineTick = GetTickCount();
  282. }
  283. else if (msg.match(regInChat)
  284. && (_leaderInChatTick < 0 || (_leaderInChatTick + LeaderInChatDelay) < _tick))
  285. {
  286. DebugInOOG('Leader is in the chat "'+msg.replace(regInChat, "$2")+'", delay '+Math.round(LeaderInChatDelay/1000)+' sec for next /f l.');
  287. _leaderInChatTick = GetTickCount();
  288. }
  289. else if (msg.match(regGameName)
  290. && ((_leaderOfflineTick < 0 || (_leaderOfflineTick + LeaderOfflineDelay) < _tick)
  291. && (_leaderInChatTick < 0 || (_leaderInChatTick + LeaderInChatDelay) < _tick)))
  292. {
  293. game = msg.replace(regGameName, "$2");
  294. }
  295. else if ((_leaderInChatTick < 0 || (_leaderInChatTick + LeaderInChatDelay) < _tick)
  296. && (_leaderOfflineTick < 0 || (_leaderOfflineTick + LeaderOfflineDelay) < _tick))
  297. {
  298. // unhandled line, supposelly "In Realm"
  299. DebugInOOG('The leader was in the the lobby but not in chat, delay '+Math.round(LeaderInChatDelay/1000)+' sec for next /f l.');
  300. _leaderInChatTick = GetTickCount();
  301. }
  302.  
  303. break;
  304. }
  305. }
  306.  
  307. if (found_leader == false)
  308. DebugInOOG('I couldn\'t find the leader in my friend list!');
  309.  
  310. if (game!="")
  311. {
  312. if (UseCDKeyChangeTrick)
  313. {
  314. // increasing the number of runs in the OOG (for CDKey switch)
  315. // Problem : the gamename/gamepassword set in your OOG will be typed in the lobbyChat
  316. // this may output a red message in the lobby chat if you have a password set (not a real problem)
  317. // I recommend to set a gamename like "Run" and no gamepassword in your OOG. -> this will output "Run-01", "Run-02", etc in lobby chat before joining games
  318. sendEventToOOG(D2NT_MGR_CREATE_GAME, location.name, 0);
  319. Delay(1000);
  320. }
  321.  
  322. DebugInOOG('Leader is in the game "' + game + '"');
  323. controlData.click(controlData.controls.lobby.button.join);
  324. Delay(100);
  325. }
  326.  
  327. }
  328. else
  329. {
  330. DebugInOOG('I can\'t read the chat!');
  331. //DebugInOOG('You probably haven\'t added the lobby chat controlinfo coordinates!');
  332. Delay(30000);
  333. }
  334. break;
  335.  
  336. case 1: // Lobby
  337. if(location.id == 1 && joinChatAfterGame)
  338. {
  339. Delay(Random(waitBeforeEnterChatMin, waitBeforeEnterChatMax));
  340. controlData.click(controlData.controls.lobby.button.enterChat);
  341. break;
  342. }
  343. break;
  344.  
  345. case 2: // Waiting In Line
  346. if(GetTickCount()-lastGameMade > waitInLineTimeout)
  347. controlData.click(controlData.controls.lobby.inLine.button.cancel);
  348. break;
  349.  
  350. case 4: // Create Game
  351. if(!controlData.get(controlData.controls.lobby.create.editBox.gameName))
  352. {
  353. controlData.click(controlData.controls.lobby.button.join);
  354. Delay (500);
  355. controlData.click(controlData.controls.lobby.button.create);
  356. Delay (500);
  357. break;
  358. }
  359.  
  360. sendEventToOOG(D2NT_MGR_CREATE_GAME, location.name, 0);
  361.  
  362. locationTimeout(5000, location);
  363.  
  364. lastGameMade = GetTickCount();
  365. lastGameStatus = 1; // pending creation
  366. break;
  367.  
  368. case 5: // Join Game
  369. if (game)
  370. {
  371. controlData.setText( controlData.controls.lobby.join.editBox.gameName, game);
  372. Delay (100);
  373. controlData.setText( controlData.controls.lobby.join.editBox.password, gamepassword);
  374. Delay (100);
  375. controlData.click(controlData.controls.lobby.join.button.joinGame);
  376. RunGC(); // run garbage collector between each game
  377. locationTimeout(5000, location);
  378. lastGameStatus = 1; // pending join
  379. }
  380. else
  381. {
  382. DebugInOOG('No game to join : cancelling');
  383. me.Cancel(1);
  384. Delay(1000);
  385. }
  386. break;
  387.  
  388. case 6: // Ladder
  389. break;
  390.  
  391. case 7: // Channel List
  392. break;
  393.  
  394. case 8: // Main Menu
  395. if(controlData.getCurrentRealmIndex() == me.gatewayid)
  396. {
  397. outputGameLength();
  398. controlData.click(controlData.gameTypes[me.playtype]);
  399. }
  400. else
  401. controlData.click(controlData.controls.mainMenu.button.gateway);
  402. break;
  403.  
  404. case 9: // Login
  405. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  406. Delay(loginDelay);
  407.  
  408. controlData.setText(controlData.controls.login.editBox.accountName, me.account);
  409.  
  410. sendEventToOOG(D2NT_MGR_LOGIN, location.name, 0);
  411.  
  412. locationTimeout(5000, location);
  413. break;
  414.  
  415. case 10: // Login Error (this is a fatal error, so stop)
  416. sendEventToOOG(D2NT_MGR_RESTART, location.name, 10);
  417. Delay(3500);
  418. break;
  419.  
  420. case 11: // Unable To Connect
  421. timeoutDelay(unableToConnectRetry*60*1000, location)
  422. controlData.click(controlData.controls.login.unableToConnect.button.ok);
  423. break;
  424.  
  425. case 12: // Character Select
  426. var _time, _control;
  427.  
  428. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  429.  
  430. for(_time = 0 ; _time < characterScreenTimeout ; _time += 500)
  431. {
  432. _control = controlData.get(controlData.controls.characterSelect.textBox.characterInfo[me.charloc]);
  433. if(_control && _control.GetText() != undefined)
  434. break;
  435.  
  436. Delay(500);
  437. }
  438.  
  439. if(_time < characterScreenTimeout)
  440. {
  441. Delay(characterSelectDelay);
  442.  
  443. controlData.click(controlData.controls.characterSelect.textBox.characters[me.charloc], 0, 0, 1);
  444. controlData.click(controlData.controls.characterSelect.textBox.characterInfo[me.charloc], 0, 0, 1);
  445.  
  446. // reset last game made, so it doesnt make a game immediately
  447. inGameAt = 0;
  448. setNextGameMake();
  449. }
  450. else
  451. {
  452. controlData.click(controlData.controls.characterSelect.button.exit);
  453. timeoutDelay(realmDownRetry*60*1000, location);
  454. }
  455. break;
  456.  
  457. case 13: // Realm Down - Character Select screen
  458. controlData.click(controlData.controls.characterSelect.button.exit);
  459. timeoutDelay(realmDownRetry*60*1000, location);
  460. break;
  461.  
  462. case 14: // Character Select - Disconnected
  463. timeoutDelay(disconnectedRetry*60*1000, location);
  464. controlData.click(controlData.controls.characterSelect.disconnected.button.ok);
  465. break;
  466.  
  467. case 15: // New Character
  468. break;
  469.  
  470. case 16: // Character Select - Please Wait popup
  471. if(!locationTimeout(pleaseWaitTimeout, location))
  472. controlData.click(controlData.controls.characterSelect.pleaseWait.button.cancel);
  473. break;
  474.  
  475. case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  476. controlData.click(controlData.controls.lobby.lostConnection.button.ok);
  477. break;
  478.  
  479. case 18: // D2 Splash
  480. controlData.click(controlData.controls.d2Splash.textBox.copyright);
  481. break;
  482.  
  483. case 19: // Login - Cdkey In Use
  484. timeoutDelay(cdkeyInUseRetry*60*1000, location);
  485. controlData.click(controlData.controls.login.cdkeyInUse.button.ok);
  486. break;
  487.  
  488. case 20: // Single Player - Select Difficulty
  489. controlData.click(controlData.singlePlayerDifficulties[me.diff]);
  490. break;
  491.  
  492. case 21: // Main Menu - Connecting
  493. if(!locationTimeout(connectingToBnetTimeout, location))
  494. controlData.click(controlData.controls.mainMenu.connecting.button.cancel);
  495. break;
  496.  
  497. case 22: // Login - Invalid Cdkey (classic or xpac)
  498. sendEventToOOG(D2NT_MGR_RESTART, location.name, 3600);
  499. Delay(3500);
  500. break;
  501.  
  502. case 23: // Character Select - Connecting
  503. if(!locationTimeout(characterScreenTimeout, location))
  504. controlData.click(controlData.controls.characterSelect.button.exit);
  505. break;
  506.  
  507. case 24: // Server Down - not much to do but wait..
  508. break;
  509.  
  510. case 25: // Lobby - Please Wait
  511. if(!locationTimeout(pleaseWaitTimeout, location))
  512. controlData.click(controlData.controls.lobby.pleaseWait.button.cancel);
  513. break;
  514.  
  515. case 26: // Lobby - Game Name Exists
  516. sendEventToOOG(D2NT_MGR_PRINT_LOG, "yE00000Game already exists", 0);
  517.  
  518. inGameAt = 0;
  519. lastGameStatus = 0;
  520. setNextGameMake();
  521.  
  522. locationTimeout(15000, location);
  523. break;
  524.  
  525. case 27: // Gateway Select
  526. controlData.clickRealmEntry(me.gatewayid);
  527. controlData.click(controlData.controls.gateway.button.ok);
  528. break;
  529.  
  530. case 28: // Lobby - Game Does Not Exist
  531. inGameAt = Random(gameDoesNotExistDelayMin, gameDoesNotExistDelayMax);
  532. lastGameStatus = 0;
  533. setNextGameMake();
  534.  
  535. locationTimeout(gameDoesNotExistTimeout, location);
  536. break;
  537. default:
  538. DebugInOOG("Unhandled location : "+location.id);
  539. break;
  540. }
  541. DebugInOOG("Location : "+location.id);
  542. }
  543.  
  544. function sendEventToOOG(locationId, statusString, pendingTime)
  545. {
  546. return SendCopyData("D2NT Manager", null, (locationId<<16)|pendingTime, statusString);
  547. }
  548.  
  549. function setNextGameMake()
  550. {
  551. lastGameMade = GetTickCount();
  552. nextGameMake = lastGameMade + createGameThreshold + Random(0-createGameThresholdRandom, createGameThresholdRandom) + inGameAt;
  553. inGameAt = 0;
  554. chatActionsDone = false;
  555. }
  556.  
  557. function outputGameLength()
  558. {
  559. if(inGameAt)
  560. {
  561. duration = GetTickCount() - inGameAt;
  562.  
  563. inGameAt = (duration < gameMinLength ? gameMinLength - duration : 0);
  564. }
  565. }
  566.  
  567. function locationTimeout(time, location)
  568. {
  569. endtime = GetTickCount() + time;
  570.  
  571. while(controlData.getLocation().id == location.id && endtime > GetTickCount())
  572. {
  573. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  574. Delay(500);
  575. }
  576.  
  577. return (controlData.getLocation().id != location.id);
  578. }
  579.  
  580. function timeoutDelay(time, location)
  581. {
  582. endtime = GetTickCount() + time;
  583.  
  584. while(endtime > GetTickCount())
  585. {
  586. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  587. Delay(1000);
  588. }
  589. }
  590.  
  591. function getRandomString(_length)
  592. {
  593. _retString = "";
  594. _charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
  595.  
  596. while(_length--)
  597. {
  598. _retString += _charSet.charAt(Random(0, _charSet.length-1));
  599. Delay(1);
  600. }
  601.  
  602. return _retString;
  603. }
  604. function DebugInOOG(logString)
  605. {
  606. if (Debug)
  607. return SendCopyData("D2NT Manager", null, 9<<16, "-- Debug : " + logString);
  608. else
  609. return false;
  610. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement