-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add Soldat support * feat: update protocol in games.js and CHANGELOG * feat: add gamemode in the raw object * remove debug console log * misspell * docs: add server config requirements * fix games list formatting issue * fix: players list
- Loading branch information
1 parent
675c5ee
commit c77ca29
Showing
5 changed files
with
58 additions
and
5 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,45 @@ | ||
import Core from './core.js' | ||
|
||
const extractValue = (text, regex, defaultValue, parser = (val) => val) => { | ||
const match = text.match(regex) | ||
return match ? parser(match[1] || defaultValue) : defaultValue | ||
} | ||
|
||
export default class soldat extends Core { | ||
async run (state) { | ||
const data = await this.withTcp(async socket => { | ||
return await this.tcpSend(socket, 'STARTFILES\r\nlogs/gamestat.txt\r\nENDFILES\r\n', (data) => { | ||
const asString = data.toString() | ||
if (asString.endsWith('\r\n') && !asString.endsWith('ENDFILES\r\n')) { | ||
return undefined | ||
} | ||
return data | ||
}) | ||
}) | ||
|
||
const string = data.toString() | ||
|
||
state.numplayers = extractValue(string, /Players:\s*(\d+)/, 0, Number) | ||
state.map = extractValue(string, /Map:\s*(.+)/, '') | ||
|
||
const lines = string.trim().split('\n') | ||
const playersIndex = lines.findIndex(line => line.startsWith('Players list')) | ||
|
||
if (playersIndex > -1) { | ||
for (let i = playersIndex + 1; i < lines.length - 1; i += 5) { | ||
state.players.push({ | ||
name: lines[i].trim(), | ||
raw: { | ||
kills: parseInt(lines[i + 1].trim()), | ||
deaths: parseInt(lines[i + 2].trim()), | ||
team: parseInt(lines[i + 3].trim()), | ||
ping: parseInt(lines[i + 4].trim()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
state.raw.response = string | ||
state.raw.gamemode = extractValue(string, /Gamemode:\s*(.+)/, '') | ||
} | ||
} |