-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add Minetest support using serverlist * Allow for connect to be assigned, * Add serverId to the string args * Add altvmp implementation * Added altv to games. * Add changelog entry * Update CHANGELOG.md with state.connect
- Loading branch information
Showing
7 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Core from './core.js' | ||
|
||
export default class altvmp extends Core { | ||
constructor() { | ||
super() | ||
this.usedTcp = true | ||
} | ||
|
||
async getServerFromMasterList() { | ||
const targetID = `${this.options.host}:${this.options.port}` | ||
|
||
const results = await this.request({ | ||
url: 'https://api.alt-mp.com/servers', | ||
responseType: 'json' | ||
}) | ||
|
||
if (results == null) { | ||
throw new Error('Unable to retrieve master server list') | ||
} | ||
|
||
const serverInfo = results.find((server) => { | ||
// If the server uses a CDN, there could be occasional paths in the address, so we are checking for them. | ||
// If the server does not use a CDN, there will be no paths in the address and direct comparison will work. | ||
const address = server.useCdn | ||
? server.address | ||
: server.address.replace(/(https?:\/\/)?\/?/g, '') | ||
return address === targetID | ||
}) | ||
|
||
return serverInfo | ||
} | ||
|
||
async getServerById(targetID) { | ||
const serverInfo = await this.request({ | ||
url: `https://api.alt-mp.com/servers/${targetID}`, | ||
responseType: 'json' | ||
}) | ||
|
||
if (serverInfo == null) { | ||
throw new Error('Unable to retrieve server info') | ||
} | ||
|
||
return serverInfo | ||
} | ||
|
||
async run(state) { | ||
const serverInfo = this.options.serverId | ||
? await this.getServerById(this.options.serverId) | ||
: await this.getServerFromMasterList() | ||
|
||
if (!serverInfo) { | ||
throw new Error('No server info was found.') | ||
} | ||
|
||
state.name = serverInfo.name | ||
state.numplayers = serverInfo.playersCount | ||
state.maxplayers = serverInfo.maxPlayersCount | ||
state.password = serverInfo.passworded | ||
state.version = serverInfo.version | ||
state.connect = `altv://${serverInfo.address}` | ||
state.raw = serverInfo | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters