Advertisement
kolton

Untitled

Nov 9th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.94 KB | None | 0 0
  1. var gameMinLength = 180000; // time in milliseconds, minimum game length, 180 seconds default (1 game/3 minutes)
  2. var gamesPerKey = 5; // games per key d'oh! used to switch keys in use. MUST BE THE SAME NUMBER YOU PUT IN MANAGER
  3.  
  4. var unableToConnectRetry = 5; // time in minutes to retry connecting on connection fail (real value is +/- 1 min)
  5. var realmDownRetry = 60; // time in minutes to retry connecting on a realm down (default is 300 minutes)
  6. var disconnectedRetry = 5; // time in minutes to retry on a disconnection (usually ip ban related)
  7. var cdkeyInUseRetry = 10; // time in minutes to retry on a cdkey in use error message (set to 0 to stop)
  8. var connectingToBnetTimeout = 20000; // time in milliseconds to wait for a login to time out and click cancel and retry
  9. var characterScreenTimeout = 60000; // time in milliseconds to wait for character screen to appear
  10. var pleaseWaitTimeout = 10000; // time in milliseconds to wait for a please wait popup
  11. var createGameThreshold = 10000; // time in milliseconds to wait between making games
  12. var createGameThresholdRandom = 0; // time in milliseconds to randomly add +/- to the game create time
  13. var createGameTimeout = 5000; // time in milliseconds to register a failed to create game
  14. var waitInLineTimeout = 60000; // time in milliseconds to wait in lines for a create game (60 second default)
  15. var characterSelectDelay = 1000; // time in milliseconds to wait before selecting a character on the char screen
  16. var loginDelay = 1000; // time in milliseconds to wait before submitting login information
  17. var clickDelay = 500; // wait X milliseconds before next action after a click event
  18. var textDelay = 500; // wait X milliseconds before next action after inserting text into a textbox
  19. var clickDelayRandom = 500; // random amount of time to add to a click
  20. var textDelayRandom = 500; // random amount of time to add to a text set
  21. var gameDoesNotExistDelayMin = 60000; // how long to wait when a Game Does Not Exist occurs - minimum - default 10 minutes
  22. var gameDoesNotExistDelayMax = 60000; // how long to wait when a Game Does Not Exist occurs - maximum - default 15 minutes
  23. var gameDoesNotExistTimeout = 30000; // how long to wait for the dialog to disappear (default 30 seconds, don't change this)
  24. var joinChatAfterGame = false; // join chat after leaving a game
  25. var joinRandomChannel = true; // if this is true, will join a random channel, otherwise it will use the channel below..
  26. var joinChannelInChat = ""; // leave blank to not join a private channel
  27. var waitBeforeEnterChatMin = 1000; // min how long to wait before entering chat
  28. var waitBeforeEnterChatMax = 2000; // max how long to wait before entering chat
  29. var waitInChatBeforeActionsMin = 2000; // min how long to wait before joining channel
  30. var waitInChatBeforeActionsMax = 3000; // max how long to wait before joining channel
  31.  
  32. // DONT EDIT ANYTHING BELOW THIS
  33.  
  34. // D2NT Manager Command
  35. const D2NT_MGR_LOADING = 1;
  36. const D2NT_MGR_READY = 2;
  37. const D2NT_MGR_LOGIN = 3;
  38. const D2NT_MGR_CREATE_GAME = 4;
  39. const D2NT_MGR_INGAME = 5;
  40. const D2NT_MGR_RESTART = 6;
  41. const D2NT_MGR_CHICKEN = 7;
  42. const D2NT_MGR_PRINT_STATUS = 8;
  43. const D2NT_MGR_PRINT_LOG = 9;
  44.  
  45. var lastGameMade = GetTickCount();
  46. var lastGameStatus = 0;
  47. var nextGameMake = 0;
  48. var inGameAt = 0;
  49. var chatActionsDone = false;
  50. var lastGameFailed = false;
  51.  
  52. //var stallFrequency = 0; //stall after how many games
  53. //var stallDelay = 20; //minutes
  54. //var currCount = NT_File("data/" + me.account + "_GameNumber.txt", 0);
  55. //var gameCount = currCount ? (parseInt(currCount.substring(currCount.indexOf("/") + 1)) + 1) : 1;
  56.  
  57. Include("libs/controlInfo.ntl");
  58.  
  59. var controlData = new controlInfo();
  60.  
  61. function NTMain()
  62. {
  63. Delay(1000);
  64. //NT_File("data/GameData.txt", 1);
  65.  
  66. var _ingame = false;
  67.  
  68. controlData.clickDelay = clickDelay;
  69. controlData.textDelay = textDelay;
  70. controlData.clickDelayRandom = clickDelayRandom;
  71. controlData.textDelayRandom = textDelayRandom;
  72.  
  73. while(1)
  74. {
  75. if(me.ingame)
  76. {
  77. if(!inGameAt)
  78. inGameAt = GetTickCount();
  79.  
  80. if(!_ingame)
  81. {
  82. RunGC(); // run garbage collector between each game
  83.  
  84. //NT_File("data/GameData.txt", 1, me.gamename);
  85. //NT_File("data/" + me.account + "_GameNumber.txt", 1, gameCount);
  86. //gameCount++;
  87.  
  88. if(Load("NTBot/NTBotGame.ntj"))
  89. {
  90. _ingame = true;
  91.  
  92. if(me.playtype > 0)
  93. sendEventToOOG(D2NT_MGR_INGAME, "In Game[IP:" + me.gameserverip.split(".")[3] + "]", 0);
  94. else
  95. sendEventToOOG(D2NT_MGR_INGAME, "In Game", 0);
  96.  
  97. lastGameStatus = 2; // in game successful
  98. }
  99. }
  100.  
  101. Delay(1000);
  102. }
  103. else
  104. {
  105. if(_ingame)
  106. {
  107. _ingame = false;
  108. //NT_Deadlock_Check();
  109. sendEventToOOG(D2NT_MGR_READY, "", 0);
  110. }
  111.  
  112. locationAction(controlData.getLocation());
  113. Delay(500);
  114. }
  115. }
  116. }
  117.  
  118. function locationAction(location)
  119. {
  120. switch(location.id)
  121. {
  122. case 3: // Lobby Chat
  123. if(!chatActionsDone)
  124. {
  125. chatActionsDone = true;
  126. Delay(Random(waitInChatBeforeActionsMin, waitInChatBeforeActionsMax));
  127.  
  128. if(joinRandomChannel || joinChannelInChat != "")
  129. {
  130. Say("/join " + (joinRandomChannel ? getRandomString(Random(3,10)) : joinChannelInChat));
  131. Delay(1000);
  132. }
  133. }
  134. case 1: // Lobby
  135. if(location.id == 1 && joinChatAfterGame)
  136. {
  137. Delay(Random(waitBeforeEnterChatMin, waitBeforeEnterChatMax));
  138. controlData.click(controlData.controls.lobby.button.enterChat);
  139. break;
  140. }
  141.  
  142. if(GetTickCount() > nextGameMake)
  143. {
  144. var _control;
  145.  
  146. lastGameFailed = false;
  147.  
  148. switch(lastGameStatus)
  149. {
  150. case 0:
  151. _control = controlData.get(controlData.controls.lobby.button.create);
  152. if(_control && _control.pressed)
  153. {
  154. controlData.click(controlData.controls.lobby.button.join);
  155. Delay(500);
  156. }
  157.  
  158. /*if(stallFrequency > 0)
  159. {
  160. if(gameCount % stallFrequency == 0)
  161. {
  162. var _stallEnd = GetTickCount() + stallDelay*60*1000;
  163.  
  164. while(_stallEnd > GetTickCount())
  165. {
  166. sendEventToOOG(D2NT_MGR_PRINT_STATUS, "Stalling" + " (" + parseInt((_stallEnd-GetTickCount())/1000) + "s)", 0);
  167. Delay(1000);
  168. }
  169. }
  170. }*/
  171.  
  172. controlData.click(controlData.controls.lobby.button.create);
  173. nextGameMake = GetTickCount() + createGameTimeout; // set our timeout
  174. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  175. break;
  176. case 1: // game failed, rollover to reset timer
  177. inGameAt = 0; // reset inGameAt, to wait how long we should have waited..
  178. lastGameFailed = true;
  179. case 2:
  180. outputGameLength();
  181. lastGameStatus = 0;
  182. setNextGameMake();
  183. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  184. break;
  185. }
  186. }
  187. else
  188. timeoutDelay(nextGameMake-GetTickCount(), location);
  189. break;
  190.  
  191. case 2: // Waiting In Line
  192. if(GetTickCount()-lastGameMade > waitInLineTimeout)
  193. controlData.click(controlData.controls.lobby.inLine.button.cancel);
  194. break;
  195.  
  196. case 4: // Create Game
  197. sendEventToOOG(D2NT_MGR_CREATE_GAME, location.name, 0);
  198.  
  199. lastGameMade = GetTickCount();
  200. lastGameStatus = 1; // pending creation
  201. break;
  202.  
  203. case 5: // Join Game
  204. break;
  205.  
  206. case 6: // Ladder
  207. break;
  208.  
  209. case 7: // Channel List
  210. break;
  211.  
  212. case 8: // Main Menu
  213. if(controlData.getCurrentRealmIndex() == me.gatewayid)
  214. {
  215. outputGameLength();
  216. controlData.click(controlData.gameTypes[me.playtype]);
  217. }
  218. else
  219. controlData.click(controlData.controls.mainMenu.button.gateway);
  220. break;
  221.  
  222. case 9: // Login
  223. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  224. Delay(loginDelay);
  225.  
  226. controlData.setText(controlData.controls.login.editBox.accountName, me.account);
  227.  
  228. sendEventToOOG(D2NT_MGR_LOGIN, location.name, 0);
  229.  
  230. locationTimeout(5000, location);
  231. break;
  232.  
  233. case 10: // Login Error (this is a fatal error, so stop)
  234. sendEventToOOG(D2NT_MGR_RESTART, location.name, 10);
  235. Delay(3500);
  236. break;
  237.  
  238. case 11: // Unable To Connect
  239. timeoutDelay(unableToConnectRetry*60*1000, location)
  240. controlData.click(controlData.controls.login.unableToConnect.button.ok);
  241. break;
  242.  
  243. case 12: // Character Select
  244. var _time, _control;
  245.  
  246. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  247.  
  248. for(_time = 0 ; _time < characterScreenTimeout ; _time += 500)
  249. {
  250. _control = controlData.get(controlData.controls.characterSelect.textBox.characterInfo[me.charloc]);
  251. if(_control && _control.GetText() != undefined)
  252. break;
  253.  
  254. Delay(500);
  255. }
  256.  
  257. if(_time < characterScreenTimeout)
  258. {
  259. Delay(characterSelectDelay);
  260.  
  261. controlData.click(controlData.controls.characterSelect.textBox.characters[me.charloc], 0, 0, 1);
  262. controlData.click(controlData.controls.characterSelect.textBox.characterInfo[me.charloc], 0, 0, 1);
  263.  
  264. // reset last game made, so it doesnt make a game immediately
  265. inGameAt = 0;
  266. setNextGameMake();
  267. }
  268. else
  269. {
  270. controlData.click(controlData.controls.characterSelect.button.exit);
  271. timeoutDelay(realmDownRetry*60*1000, location);
  272. }
  273. break;
  274.  
  275. case 13: // Realm Down - Character Select screen
  276. controlData.click(controlData.controls.characterSelect.button.exit);
  277. timeoutDelay(realmDownRetry*60*1000, location);
  278. break;
  279.  
  280. case 14: // Character Select - Disconnected
  281. timeoutDelay(disconnectedRetry*60*1000, location);
  282. controlData.click(controlData.controls.characterSelect.disconnected.button.ok);
  283. break;
  284.  
  285. case 15: // New Character
  286. break;
  287.  
  288. case 16: // Character Select - Please Wait popup
  289. if(!locationTimeout(pleaseWaitTimeout, location))
  290. controlData.click(controlData.controls.characterSelect.pleaseWait.button.cancel);
  291. break;
  292.  
  293. case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  294. controlData.click(controlData.controls.lobby.lostConnection.button.ok);
  295. break;
  296.  
  297. case 18: // D2 Splash
  298. controlData.click(controlData.controls.d2Splash.textBox.copyright);
  299. break;
  300.  
  301. case 19: // Login - Cdkey In Use
  302. if (!gamesPerKey) {
  303. timeoutDelay(cdkeyInUseRetry*60*1000, location);
  304. controlData.click(controlData.controls.login.cdkeyInUse.button.ok);
  305.  
  306. break;
  307. }
  308.  
  309. sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿc1Key in use. Increasing game count.", 0);
  310.  
  311. for(var i = 0 ; i < gamesPerKey ; i++)
  312. {
  313. sendEventToOOG(4, (gamesPerKey - i) + " increments left.", 0);
  314. Delay(1000);
  315. }
  316.  
  317. sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿc1Key in use. Switching to next one...", 0);
  318. Delay(500);
  319. sendEventToOOG(D2NT_MGR_RESTART, "", 5);
  320.  
  321. break;
  322.  
  323. case 20: // Single Player - Select Difficulty
  324. controlData.click(controlData.singlePlayerDifficulties[me.diff]);
  325. break;
  326.  
  327. case 21: // Main Menu - Connecting
  328. if(!locationTimeout(connectingToBnetTimeout, location))
  329. controlData.click(controlData.controls.mainMenu.connecting.button.cancel);
  330. break;
  331.  
  332. case 22: // Login - Invalid Cdkey (classic or xpac)
  333. sendEventToOOG(D2NT_MGR_RESTART, location.name, 3600);
  334. Delay(3500);
  335. break;
  336.  
  337. case 23: // Character Select - Connecting
  338. if(!locationTimeout(characterScreenTimeout, location))
  339. controlData.click(controlData.controls.characterSelect.button.exit);
  340. break;
  341.  
  342. case 24: // Server Down - not much to do but wait..
  343. break;
  344.  
  345. case 25: // Lobby - Please Wait
  346. if(!locationTimeout(pleaseWaitTimeout, location))
  347. controlData.click(controlData.controls.lobby.pleaseWait.button.cancel);
  348. //NT_Deadlock_Check();
  349. break;
  350.  
  351. case 26: // Lobby - Game Name Exists
  352. sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿE00000Game already exists", 0);
  353.  
  354. inGameAt = 0;
  355. lastGameStatus = 0;
  356. setNextGameMake();
  357.  
  358. locationTimeout(15000, location);
  359. break;
  360.  
  361. case 27: // Gateway Select
  362. controlData.clickRealmEntry(me.gatewayid);
  363. controlData.click(controlData.controls.gateway.button.ok);
  364. break;
  365.  
  366. case 28: // Lobby - Game Does Not Exist
  367. inGameAt = Random(gameDoesNotExistDelayMin, gameDoesNotExistDelayMax);
  368. lastGameStatus = 0;
  369. setNextGameMake();
  370.  
  371. locationTimeout(gameDoesNotExistTimeout, location);
  372. break;
  373. }
  374. }
  375.  
  376. function sendEventToOOG(locationId, statusString, pendingTime)
  377. {
  378. return SendCopyData("D2NT Manager", null, (locationId<<16)|pendingTime, statusString);
  379. }
  380.  
  381. function setNextGameMake()
  382. {
  383. lastGameMade = GetTickCount();
  384. nextGameMake = lastGameMade + createGameThreshold + Random(0-createGameThresholdRandom, createGameThresholdRandom) + inGameAt;
  385. inGameAt = 0;
  386. chatActionsDone = false;
  387. }
  388.  
  389. function outputGameLength()
  390. {
  391. if(inGameAt)
  392. {
  393. duration = GetTickCount() - inGameAt;
  394.  
  395. inGameAt = (duration < gameMinLength ? gameMinLength - duration : 0);
  396. }
  397. }
  398.  
  399. function locationTimeout(time, location)
  400. {
  401. endtime = GetTickCount() + time;
  402.  
  403. while(controlData.getLocation().id == location.id && endtime > GetTickCount())
  404. {
  405. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  406. Delay(500);
  407. }
  408.  
  409. return (controlData.getLocation().id != location.id);
  410. }
  411.  
  412. function timeoutDelay(time, location)
  413. {
  414. endtime = GetTickCount() + time;
  415.  
  416. while(endtime > GetTickCount())
  417. {
  418. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  419. Delay(1000);
  420. }
  421. }
  422.  
  423. function getRandomString(_length)
  424. {
  425. _retString = "";
  426. _charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
  427.  
  428. while(_length--)
  429. {
  430. _retString += _charSet.charAt(Random(0, _charSet.length-1));
  431. Delay(1);
  432. }
  433.  
  434. return _retString;
  435. }
  436.  
  437. function NT_File(path, mode, msg, delay) { //big thanks to all the koreans out there
  438. var _msg = "";
  439. var _line = "";
  440. var _fileHandle;
  441. var _isFileCheck = false;
  442.  
  443. if (arguments.length < 3) msg = "";
  444. if (arguments.length < 4) delay = (mode > 0) ? 5 : 2;
  445.  
  446. while (delay--) {
  447. if (mode == 2 && !_isFileCheck) {
  448. _fileHandle = FileOpen(path, 0);
  449. if (!_fileHandle)
  450. _fileHandle = FileOpen(path, 1);
  451.  
  452. if (_fileHandle)
  453. _fileHandle.Close();
  454.  
  455. _isFileCheck = true;
  456. }
  457.  
  458. _fileHandle = FileOpen(path, mode);
  459. if (_fileHandle)
  460. break;
  461.  
  462. if (delay)
  463. Delay(200);
  464. }
  465.  
  466. if (_fileHandle) {
  467. if (mode == 0) {
  468. while (!_fileHandle.eof) {
  469. _line = _fileHandle.ReadLine();
  470. if (_line || !_fileHandle.eof)
  471. _msg += _line + msg;
  472. }
  473. }
  474. else if (msg)
  475. _fileHandle.WriteLine(msg);
  476.  
  477. _fileHandle.Close();
  478. }
  479.  
  480. return _msg;
  481. }
  482.  
  483. function NT_Deadlock_Check()
  484. {
  485. for (var i = 0; i < 40; i++)
  486. {
  487. if (controlData.getLocation().id != undefined && controlData.getLocation().id != 25)
  488. break;
  489.  
  490. if (i > 38)
  491. {
  492. sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿc3 *** ÿc1Deadlock - Restarting ÿc3***", 0);
  493. sendEventToOOG(D2NT_MGR_RESTART, "", 5);
  494. NT_Delay();
  495. }
  496.  
  497. Delay(500);
  498. }
  499. }
  500.  
  501. function NT_Delay(retry)
  502. {
  503. if (arguments.length < 1)
  504. retry = 20;
  505.  
  506. while (retry-- > 0)
  507. Delay(1000);
  508. }
  509.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement