steamutils 1.2.8 → 1.2.9

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 +33 -8
  2. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -377,9 +377,30 @@ function SteamClient({
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
+
381
+ async function relogin(retry) {
382
+ if (retry <= 0) {
383
+ console.error("Cannot relogin")
384
+ return
385
+ }
386
+ const isSuccess = await login(true)
387
+ if (isSuccess) {
388
+ onEvent('loggedOn', function (loggedOnResponse) {
389
+ if (loggedOnResponse) {
390
+ console.log("Relogin success")
391
+ } else {
392
+ relogin(retry - 1)
393
+ }
394
+ }, true, 120000)
395
+ } else {
396
+ setTimeout(function () {
397
+ relogin(retry - 1)
398
+ }, 60000)
399
+ }
400
+ }
401
+
402
+ await sleep(60000)
403
+ await relogin(10)
383
404
  }
384
405
  })
385
406
  steamClient.on('error', async (e) => {
@@ -720,7 +741,7 @@ function SteamClient({
720
741
  steamClient.setPersona(SteamUser.EPersonaState.Online)
721
742
  state = 'Online'
722
743
  await sendHello()
723
- callEvent(events.loggedOn)
744
+ callEvent(events.loggedOn, loggedOnResponse)
724
745
  if (isAutoRequestFreeLicense) {
725
746
  doSetInterval(function () {
726
747
  autoRequestFreeLicense(false, 50)
@@ -1031,23 +1052,23 @@ function SteamClient({
1031
1052
 
1032
1053
  const result = response?.data
1033
1054
  if (result?.logged_in) {
1034
- console.log(`clientjstoken success`)
1035
1055
  Object.assign(result, {
1036
1056
  steamID: new SteamID(result.steamid), accountName: result.account_name, webLogonToken: result.token
1037
1057
  })
1038
1058
  steamClient.logOn(result)
1039
1059
  return cookie
1040
1060
  } else {
1041
- console.log(`clientjstoken fail`)
1042
1061
  if (tryNewCookie) {
1043
1062
  log('You are not logged in', cookie)
1044
1063
  return null
1045
1064
  } else {
1046
1065
  const newCookie = await getNewCookie(cookie)
1047
1066
  if(!newCookie){
1048
- console.log("Cannot get new cookie")
1067
+ console.error("Cannot get new cookie")
1068
+ return null
1069
+ } else {
1070
+ return await loginWithCookie(newCookie, true)
1049
1071
  }
1050
- return newCookie && await loginWithCookie(newCookie, true)
1051
1072
  }
1052
1073
  }
1053
1074
  }
@@ -1058,12 +1079,16 @@ function SteamClient({
1058
1079
  const newCookie = await loginWithCookie(cookie)
1059
1080
  if (newCookie) {
1060
1081
  cookie = newCookie
1082
+ return true
1083
+ } else {
1084
+ return false
1061
1085
  }
1062
1086
  } else if (username && password) {
1063
1087
  log(reconnect ? `reconnect with username ${username}` : `login with username ${username}`)
1064
1088
  steamClient.logOn({
1065
1089
  accountName: username, password: password, rememberPassword: true, machineName: 'Natri',
1066
1090
  })
1091
+ return true
1067
1092
  }
1068
1093
  }
1069
1094
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.2.08",
3
+ "version": "1.2.09",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.3.4",