steamutils 1.2.8 → 1.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/SteamClient.js +42 -9
  2. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -373,13 +373,42 @@ function SteamClient({
373
373
  steamClient.on('disconnected', async (eresult, msg) => {
374
374
  state = 'Offline'
375
375
  log('disconnected', eresult, msg)
376
- doClearIntervals()
376
+
377
377
  callEvent(events.disconnected, {eresult, msg})
378
378
 
379
379
  if (eresult === 3 && autoReconnect && !isLogOff) {
380
- setTimeout(function () {
381
- login(true)
382
- }, 30000)
380
+ async function relogin(retry) {
381
+ if (retry <= 0) {
382
+ console.error("Cannot relogin")
383
+ return false
384
+ } else {
385
+ const isSuccess = await login(true)
386
+ if (isSuccess) {
387
+ const loggedOnResponse = await new Promise(resolve => {
388
+ onEvent('loggedOn', function (loggedOnResponse) {
389
+ resolve(loggedOnResponse)
390
+ }, true, 120000)
391
+ })
392
+ if (loggedOnResponse) {
393
+ console.log("Relogin success")
394
+ return true
395
+ } else {
396
+ return await relogin(retry - 1)
397
+ }
398
+ } else {
399
+ await sleep(60000)
400
+ return await relogin(retry - 1)
401
+ }
402
+ }
403
+ }
404
+
405
+ await sleep(60000)
406
+ const isSuccess = await relogin(10)
407
+ if (!isSuccess) {
408
+ doClearIntervals()
409
+ }
410
+ } else {
411
+ doClearIntervals()
383
412
  }
384
413
  })
385
414
  steamClient.on('error', async (e) => {
@@ -720,7 +749,7 @@ function SteamClient({
720
749
  steamClient.setPersona(SteamUser.EPersonaState.Online)
721
750
  state = 'Online'
722
751
  await sendHello()
723
- callEvent(events.loggedOn)
752
+ callEvent(events.loggedOn, loggedOnResponse)
724
753
  if (isAutoRequestFreeLicense) {
725
754
  doSetInterval(function () {
726
755
  autoRequestFreeLicense(false, 50)
@@ -1031,23 +1060,23 @@ function SteamClient({
1031
1060
 
1032
1061
  const result = response?.data
1033
1062
  if (result?.logged_in) {
1034
- console.log(`clientjstoken success`)
1035
1063
  Object.assign(result, {
1036
1064
  steamID: new SteamID(result.steamid), accountName: result.account_name, webLogonToken: result.token
1037
1065
  })
1038
1066
  steamClient.logOn(result)
1039
1067
  return cookie
1040
1068
  } else {
1041
- console.log(`clientjstoken fail`)
1042
1069
  if (tryNewCookie) {
1043
1070
  log('You are not logged in', cookie)
1044
1071
  return null
1045
1072
  } else {
1046
1073
  const newCookie = await getNewCookie(cookie)
1047
1074
  if(!newCookie){
1048
- console.log("Cannot get new cookie")
1075
+ console.error("Cannot get new cookie")
1076
+ return null
1077
+ } else {
1078
+ return await loginWithCookie(newCookie, true)
1049
1079
  }
1050
- return newCookie && await loginWithCookie(newCookie, true)
1051
1080
  }
1052
1081
  }
1053
1082
  }
@@ -1058,12 +1087,16 @@ function SteamClient({
1058
1087
  const newCookie = await loginWithCookie(cookie)
1059
1088
  if (newCookie) {
1060
1089
  cookie = newCookie
1090
+ return true
1091
+ } else {
1092
+ return false
1061
1093
  }
1062
1094
  } else if (username && password) {
1063
1095
  log(reconnect ? `reconnect with username ${username}` : `login with username ${username}`)
1064
1096
  steamClient.logOn({
1065
1097
  accountName: username, password: password, rememberPassword: true, machineName: 'Natri',
1066
1098
  })
1099
+ return true
1067
1100
  }
1068
1101
  }
1069
1102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.2.08",
3
+ "version": "1.2.10",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.3.4",