forked from gamedig/node-gamedig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Grand Theft Auto V - RAGE MP support (gamedig#576)
* feat: Add Grand Theft Auto V - RAGE MP support * Add changelog entry * Change ID for RageMP to gta5r * Rename to be RageMP * Revert prettier changing * to - * Add notes to ragemp. * Update CHANGELOG.md
- Loading branch information
Showing
5 changed files
with
68 additions
and
1 deletion.
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,49 @@ | ||
import Core from './core.js' | ||
|
||
export default class ragemp extends Core { | ||
constructor() { | ||
super() | ||
this.usedTcp = true | ||
} | ||
|
||
async run(state) { | ||
const results = await this.request({ | ||
url: 'https://cdn.rage.mp/master/v2/', | ||
responseType: 'json' | ||
}) | ||
|
||
if (results == null) { | ||
throw new Error('Unable to retrieve master server list') | ||
} | ||
|
||
const targetID = `${this.options.host}:${this.options.port}` | ||
|
||
let serverResult = null | ||
let serverInfo = null | ||
|
||
for (const entry of results) { | ||
if (entry.id === targetID) { | ||
serverResult = entry | ||
serverInfo = entry.servers.at(0) | ||
break | ||
} | ||
|
||
for (const serverEntry of entry.servers) { | ||
if (serverEntry.id === targetID) { | ||
serverResult = entry | ||
serverInfo = serverEntry | ||
break | ||
} | ||
} | ||
} | ||
|
||
if (serverInfo == null) { | ||
throw new Error('Server not found in master server list.') | ||
} | ||
|
||
state.name = serverInfo.name | ||
state.numplayers = serverInfo.players.amount | ||
state.maxplayers = serverInfo.players.max | ||
state.raw = serverResult | ||
} | ||
} |