Skip to content

Commit

Permalink
Merge pull request #313 from sergelouie6/patch-1
Browse files Browse the repository at this point in the history
Added additional properties to getListPlayers and getSquads methods
  • Loading branch information
werewolfboy13 authored Nov 5, 2023
2 parents def22e4 + 09b076f commit 8a988c1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions squad-server/rcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ export default class SquadRcon extends Rcon {

const players = [];

if(!response || response.length < 1) return players;

for (const line of response.split('\n')) {
const match = line.match(
/ID: ([0-9]+) \| SteamID: ([0-9]{17}) \| Name: (.+) \| Team ID: ([0-9]+) \| Squad ID: ([0-9]+|N\/A)/
/ID: ([0-9]+) \| SteamID: ([0-9]{17}) \| Name: (.+) \| Team ID: ([0-9]+) \| Squad ID: ([0-9]+|N\/A) \| Is Leader: (True|False) \| Role: ([A-Za-z0-9_]*)\b/
);
if (!match) continue;

Expand All @@ -150,7 +152,9 @@ export default class SquadRcon extends Rcon {
steamID: match[2],
name: match[3],
teamID: match[4],
squadID: match[5] !== 'N/A' ? match[5] : null
squadID: match[5] !== 'N/A' ? match[5] : null,
isLeader: match[6] === 'True',
role: match[7]
});
}

Expand All @@ -164,21 +168,25 @@ export default class SquadRcon extends Rcon {
let teamName;
let teamID;

if(!responseSquad || responseSquad.length < 1) return squads;

for (const line of responseSquad.split('\n')) {
const match = line.match(
/ID: ([0-9]+) \| Name: (.+) \| Size: ([0-9]+) \| Locked: (True|False)/
/ID: ([0-9]+) \| Name: (.+) \| Size: ([0-9]+) \| Locked: (True|False) \| Creator Name: (.+) \| Creator Steam ID: ([0-9]{17})/
);
const matchSide = line.match(/Team ID: (1|2) \((.+)\)/);
if (matchSide) {
teamID = matchSide[1];
teamName = matchSide[2];
}
if (!match) continue;
await squads.push({
squads.push({
squadID: match[1],
squadName: match[2],
size: match[3],
locked: match[4],
creatorName: match[5],
creatorSteamID: match[6],
teamID: teamID,
teamName: teamName
});
Expand Down

0 comments on commit 8a988c1

Please sign in to comment.