SquadJS/squad-server/rcon.js

103 lines
2.9 KiB
JavaScript
Raw Normal View History

import Logger from 'core/logger';
2020-12-10 12:51:32 -06:00
import Rcon from 'core/rcon';
2020-10-25 19:11:47 -05:00
export default class SquadRcon extends Rcon {
2020-12-10 12:51:32 -06:00
processChatPacket(decodedPacket) {
const matchChat = decodedPacket.body.match(
2020-12-10 12:51:32 -06:00
/\[(ChatAll|ChatTeam|ChatSquad|ChatAdmin)] \[SteamID:([0-9]{17})] (.+?) : (.*)/
);
if (matchChat) {
Logger.verbose('SquadRcon', 2, `Matched chat message: ${decodedPacket.body}`);
2020-12-10 12:51:32 -06:00
this.emit('CHAT_MESSAGE', {
raw: decodedPacket.body,
chat: matchChat[1],
steamID: matchChat[2],
name: matchChat[3],
message: matchChat[4],
time: new Date()
});
return;
}
const matchPossessedAdminCam = decodedPacket.body.match(
/\[SteamID:([0-9]{17})] (.+?) has possessed admin camera./
);
if (matchPossessedAdminCam) {
Logger.verbose('SquadRcon', 2, `Matched admin camera possessed: ${decodedPacket.body}`);
this.emit('POSSESSED_ADMIN_CAMERA', {
raw: decodedPacket.body,
steamID: matchPossessedAdminCam[1],
name: matchPossessedAdminCam[2],
time: new Date()
});
return;
}
const matchUnpossessedAdminCam = decodedPacket.body.match(
/\[SteamID:([0-9]{17})] (.+?) has unpossessed admin camera./
);
if (matchUnpossessedAdminCam) {
Logger.verbose('SquadRcon', 2, `Matched admin camera possessed: ${decodedPacket.body}`);
this.emit('UNPOSSESSED_ADMIN_CAMERA', {
raw: decodedPacket.body,
steamID: matchUnpossessedAdminCam[1],
name: matchUnpossessedAdminCam[2],
time: new Date()
});
}
2020-12-10 12:51:32 -06:00
}
2021-02-03 11:33:01 -06:00
async getCurrentMap() {
const response = await this.execute('ShowCurrentMap');
const match = response.match(/^Current level is (.*), layer is (.*)/);
return { level: match[1], layer: match[2] };
2020-10-25 19:11:47 -05:00
}
2021-02-03 11:33:01 -06:00
async getNextMap() {
2020-10-25 19:11:47 -05:00
const response = await this.execute('ShowNextMap');
2021-02-03 11:33:01 -06:00
const match = response.match(/^Next level is (.*), layer is (.*)/);
return {
level: match[1] !== '' ? match[1] : null,
layer: match[2] !== 'To be voted' ? match[2] : null
};
2020-10-25 19:11:47 -05:00
}
async getListPlayers() {
const response = await this.execute('ListPlayers');
const 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)/
);
if (!match) continue;
players.push({
playerID: match[1],
steamID: match[2],
name: match[3],
teamID: match[4],
squadID: match[5] !== 'N/A' ? match[5] : null
});
}
return players;
}
2021-02-03 11:33:01 -06:00
async broadcast(message) {
await this.execute(`AdminBroadcast ${message}`);
}
2020-10-25 19:11:47 -05:00
async warn(steamID, message) {
await this.execute(`AdminWarn "${steamID}" ${message}`);
}
async switchTeam(steamID) {
await this.execute(`AdminForceTeamChange "${steamID}"`);
}
2020-10-25 19:12:20 -05:00
}