-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
195 lines (170 loc) · 4.64 KB
/
Copy pathindex.js
File metadata and controls
195 lines (170 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
const axios = require('axios')
const https = require('https')
const fs = require('fs')
const qs = require('qs')
var agent = new https.Agent({
ca: fs.readFileSync('cacert.pem')
})
const TOKEN = process.env.TOKEN || fs.readFileSync('token.txt', 'utf-8')
async function sendPOST(method, data) {
Log('Sending ' + method + '...')
const res = await axios({
method: 'POST',
url: 'https://community.steam-api.com/' + method + '/v0001/',
agent: agent,
headers: {
Accept: '*/*',
'Content-type': 'application/x-www-form-urlencoded',
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3464.0 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Origin: 'https://steamcommunity.com',
Referer: 'https://steamcommunity.com/saliengame/play'
},
data: qs.stringify({ access_token: TOKEN, ...data })
})
return res.data.response
}
async function sendGET(method, data) {
Log('Sending ' + method + '...')
const res = await axios({
method: 'get',
url:
'https://community.steam-api.com/ITerritoryControlMinigameService/' +
method +
'/v0001/?access_token=' +
TOKEN +
'&' +
data,
agent: agent,
headers: {
Accept: '*/*',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Origin: 'https://steamcommunity.com',
Referer: 'https://steamcommunity.com/saliengame/play'
}
})
return res.data.response
}
async function RepresentGroup(clanid) {
Log('Representing group: ' + clanid)
await sendPOST('ITerritoryControlMinigameService/RepresentClan', { clanid })
}
async function GetFirstAvailablePlanet() {
const { planets } = await sendGET('GetPlanets', 'active_only=1')
if (!planets) {
return null
}
const planet = planets.find(p => !p.state.captured)
Log('Found planet: ' + planet.id)
return planets.find(p => !p.state.captured).id
}
async function GetFirstAvailableZone(id) {
const { planets } = await sendGET('GetPlanet', 'id=' + id)
if (!planets[0].zones) {
return null
}
const zones = planets[0].zones
let cleanZones = zones.filter(z => !z.captured && z.capture_progress < 0.95)
if (!cleanZones) {
return null
}
cleanZones = cleanZones.sort((a, b) => {
if (b['difficulty'] === a['difficulty']) {
return b['zone_position'] - a['zone_position']
}
return b['difficulty'] - a['difficulty']
})
return cleanZones[0]
}
function GetScoreForZone(zone) {
let score = 0
switch (zone['difficulty']) {
case 1:
score = 5
break
case 2:
score = 10
break
case 3:
score = 20
break
}
return score * 120 - score
}
async function GetPlayerInfo() {
const pInfo = await sendPOST(
'ITerritoryControlMinigameService/GetPlayerInfo',
null
)
return pInfo
}
async function JoinPlanet(id) {
await sendPOST('ITerritoryControlMinigameService/JoinPlanet', { id })
Log('Joined planet: ' + id)
}
async function JoinZone(zone) {
await sendPOST('ITerritoryControlMinigameService/JoinZone', {
zone_position: zone.zone_position
})
Log(
'Joined zone ' +
zone.zone_position +
' - Captured: ' +
Math.floor(zone.capture_progress * 100) +
'% - Difficulty: ' +
zone.difficulty
)
}
async function LeaveGame(gameid) {
await sendPOST('IMiniGameService/LeaveGame', {
gameid
})
Log('Left Game: ' + gameid)
}
async function ReportScore(zone) {
await sendPOST('ITerritoryControlMinigameService/ReportScore', {
score: GetScoreForZone(zone)
}).then(scoreReport => {
if (scoreReport.new_score) {
Log(
'Match ended score: ' +
scoreReport.old_score +
' => ' +
scoreReport.new_score +
' (next level: ' +
scoreReport.next_level_score +
') - Current level: ' +
scoreReport.new_level
)
}
})
}
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
function Log(msg) {
console.log(`[${new Date().toUTCString()}] - ${msg}`)
}
async function init() {
const id = await GetFirstAvailablePlanet()
await RepresentGroup(process.env.GROUP || 4777282)
let currentPlanet
await JoinPlanet(id)
const pInfo = await GetPlayerInfo()
currentPlanet = pInfo.active_planet
if (pInfo.active_zone_game) {
Log('Already in a game. Leaving: ' + pInfo.active_zone_game)
LeaveGame(pInfo.active_zone_game)
}
while (true) {
let zone = await GetFirstAvailableZone(currentPlanet)
await JoinZone(zone)
await timeout(120000)
ReportScore(zone)
}
}
init()
require('http')
.createServer()
.listen(3000)