Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions squad-server/rcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,54 @@ export default class SquadRcon extends Rcon {

async getCurrentMap() {
const response = await this.execute('ShowCurrentMap');
const match = response.match(/^Current level is ([^,]*), layer is ([^,]*)/);
return { level: match[1], layer: match[2] };
Logger.verbose('SquadRcon', 1, `ShowCurrentMap response: ${response}`);

if (!response) return { level: null, layer: null };

// Adjusted regex to handle trailing info after layer name
const match = response.match(/^Current level is ([^,]+), layer is ([^,\s]+)(?:,.*)?$/);

if (!match) {
Logger.error('SquadRcon', `getCurrentMap: Unexpected response format: ${response}`);
return { level: null, layer: null };
}

const level = match[1];
let layer = match[2];

if (!layer || layer.toLowerCase() === 'unknown') {
layer = null;
}

return { level, layer };
}



async getNextMap() {
const response = await this.execute('ShowNextMap');
const match = response.match(/^Next level is ([^,]*), layer is ([^,]*)/);
return {
level: match ? (match[1] !== '' ? match[1] : null) : null,
layer: match ? (match[2] !== 'To be voted' ? match[2] : null) : null
};
Logger.verbose('SquadRcon', 1, `ShowNextMap response: ${response}`);

if (!response) return { level: null, layer: null };

const match = response.match(/^Next level is ([^,]*), layer is ([^,\s]+)(?:,.*)?$/);

if (!match) {
Logger.error('SquadRcon', `getNextMap: Unexpected response format: ${response}`);
return { level: null, layer: null };
}

const level = match[1] || null;
let layer = match[2];

if (!layer || layer === 'To be voted' || layer.toLowerCase() === 'unknown') {
layer = null;
}

return { level, layer };
}


async getListPlayers() {
const response = await this.execute('ListPlayers');

Expand Down