Skip to content

Commit

Permalink
feat: remove games.txt and replace it with an in-code solution (#407)
Browse files Browse the repository at this point in the history
* feat: remove games.txt and replace it with an in-code solution

* docs: update changelog

* chore: add todo comment regarding weird game ids to rename

* fix: generate games list md file

* fix: gemerate games list file to alphabetical id order

* fix: update changelog to note removal of some game ids and add geneshift alternative
  • Loading branch information
CosminPerRam authored Nov 19, 2023
1 parent 2fb9f50 commit ce4cddb
Show file tree
Hide file tree
Showing 7 changed files with 2,456 additions and 468 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
#### Games
* Renamed `Counter Strike: 2D` to `CS2D` in [games.txt](games.txt) (why? see [this](https://cs2d.com/faq.php?show=misc_name#misc_name)).
* Updated `CS2D` protocol (by @ernestpasnik).
* Removed the following alternative game ids: `minecraftping` (as it was deprecated and the same thing as `minecraft`),
`minecraftpe` (deprecated, which is the same as `minecraftbe`), `flashpoint` (alternative was `operationflashpoint`,
see next point) and `tshock` (which is `terraria`).
* Renamed the game id `operationflashpoint` to reference it by its full name, now is `ofcwc`.

### Other changes
#### Package
* Removed the `games.txt` file, the games definitions are now stored in-code.
* Replaced usage of deprecated `substr` with `substring`.
* Replaced deprecated internal `punycode` with the [punycode](https://www.npmjs.com/package/punycode) package.
* Updated [got](https://github.com/sindresorhus/got) from 12.1 to 13.
Expand Down
345 changes: 0 additions & 345 deletions games.txt

This file was deleted.

114 changes: 0 additions & 114 deletions lib/GameResolver.js

This file was deleted.

7 changes: 3 additions & 4 deletions lib/QueryRunner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import GameResolver from './GameResolver.js'
import { lookup } from './game-resolver.js'
import { getProtocol } from './ProtocolResolver.js'
import GlobalUdpSocket from './GlobalUdpSocket.js'

Expand All @@ -14,7 +14,6 @@ export default class QueryRunner {
this.udpSocket = new GlobalUdpSocket({
port: runnerOpts.listenUdpPort
})
this.gameResolver = new GameResolver()
}

async run (userOptions) {
Expand All @@ -29,7 +28,7 @@ export default class QueryRunner {
port_query: gameQueryPort,
port_query_offset: gameQueryPortOffset,
...gameOptions
} = this.gameResolver.lookup(userOptions.type)
} = lookup(userOptions.type)
const attempts = []

const optionsCollection = {
Expand Down Expand Up @@ -78,7 +77,7 @@ export default class QueryRunner {
} finally {
// Deno doesn't support unref, so we must close the socket after every connection
// https://github.com/denoland/deno/issues/20138
if (typeof Deno !== "undefined") {
if (typeof Deno !== 'undefined') {
this.udpSocket?.socket?.close()
delete this.udpSocket
}
Expand Down
17 changes: 17 additions & 0 deletions lib/game-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { games } from './games.js'

export const lookup = (type) => {
if (!type) { throw Error('No game specified') }

if (type.startsWith('protocol-')) {
return {
protocol: type.substring(9)
}
}

const game = games[type]

if (!game) { throw Error('Invalid game: ' + type) }

return game.options
}
Loading

0 comments on commit ce4cddb

Please sign in to comment.