Skip to content

Commit 9e098d2

Browse files
committed
First version of server map viewer
1 parent d269909 commit 9e098d2

25 files changed

+2640
-1
lines changed

.gitignore

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
node_modules/
2-
dist.js
2+
dist.js
3+
4+
# Environment variables
5+
.env
6+
.env.*
7+
8+
# Ignore all the test files I inevitably have lying around...
9+
test*.*

valve-query/.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Interim data files
2+
*.json
3+
*.geojson
4+
5+
!package.json
6+
!package-lock.json
7+
8+
# Saved promotional map files
9+
map_*.png
10+
*.gif

valve-query/game.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { queryGameServerInfo } from 'steam-server-query'
2+
queryGameServerInfo(process.argv[2]).then(console.log)

valve-query/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { queryMasterServer, queryGameServerInfo, REGIONS } from 'steam-server-query'
2+
import { promises as fs } from 'fs'
3+
4+
const APP_ID = process.argv[2];
5+
const now = new Date().toISOString().slice(0, 10).replace(/-/g, "");
6+
7+
queryMasterServer('hl2master.steampowered.com:27011', REGIONS.ALL, { appid: APP_ID }).then(async (results) => {
8+
console.log('Found', results.length, 'servers')
9+
await fs.writeFile(`${now}_${APP_ID}_servers.json`, JSON.stringify(results))
10+
})

valve-query/locations.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { promises as fs } from 'fs'
2+
3+
async function holdOn(time) {
4+
return new Promise((resolve) => {
5+
setTimeout(resolve, time)
6+
})
7+
}
8+
9+
async function queryServerLocations(addresses) {
10+
return new Promise(async (resolve, reject) => {
11+
const response = await fetch('http://ip-api.com/batch?fields=lat,lon,query', {
12+
method: 'POST',
13+
body: JSON.stringify(addresses)
14+
})
15+
16+
const data = await response.json()
17+
resolve(data)
18+
})
19+
}
20+
21+
function countIPs(addresses) {
22+
const counts = new Map()
23+
addresses.forEach((address) => {
24+
const base = address.split(":")[0]
25+
counts.set(base, (counts.get(base) || 0) + 1)
26+
})
27+
28+
return counts
29+
}
30+
31+
const fileName = process.argv[2]
32+
33+
fs.readFile(fileName).then(async (dataString) => {
34+
const data = JSON.parse(dataString)
35+
const counts = countIPs(data)
36+
37+
const uniqueIPs = [...counts.keys()]
38+
const chunkSize = 100
39+
let features = []
40+
41+
for (let i = 0; i < uniqueIPs.length; i += chunkSize) {
42+
const chunk = uniqueIPs.slice(i, i + chunkSize)
43+
const locations = await queryServerLocations(chunk)
44+
45+
const locationFeatures = locations.map((data) => {
46+
return {
47+
"type": "Feature",
48+
"geometry": {
49+
"type": "Point",
50+
"coordinates": [data.lon, data.lat],
51+
},
52+
"properties": {
53+
"count": counts.get(data.query),
54+
"ip": data.query
55+
}
56+
}
57+
})
58+
features = features.concat(locationFeatures)
59+
console.log('Processed', features.length)
60+
await holdOn(5000)
61+
}
62+
await fs.writeFile(fileName.replace(".json", ".geojson"), JSON.stringify({ "type": "FeatureCollection", features: features }))
63+
})
64+
65+

valve-query/map/.gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?

valve-query/map/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# map
2+
3+
This template should help get you started developing with Vue 3 in Vite.
4+
5+
## Recommended IDE Setup
6+
7+
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
8+
9+
## Type Support for `.vue` Imports in TS
10+
11+
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.
12+
13+
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
14+
15+
1. Disable the built-in TypeScript Extension
16+
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
17+
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
18+
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
19+
20+
## Customize configuration
21+
22+
See [Vite Configuration Reference](https://vitejs.dev/config/).
23+
24+
## Project Setup
25+
26+
```sh
27+
npm install
28+
```
29+
30+
### Compile and Hot-Reload for Development
31+
32+
```sh
33+
npm run dev
34+
```
35+
36+
### Type-Check, Compile and Minify for Production
37+
38+
```sh
39+
npm run build
40+
```

valve-query/map/env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

valve-query/map/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<link rel="icon" href="/favicon.ico">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)