SquadJS/squad-server/rcon.js

207 lines
6.1 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(
2023-11-18 16:34:04 -06:00
/\[(ChatAll|ChatTeam|ChatSquad|ChatAdmin)] \[Online IDs:EOS: ([0-9a-f]{32}) steam: (\d{17})\] (.+?) : (.*)/
2020-12-10 12:51:32 -06:00
);
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],
eosID: matchChat[2],
steamID: matchChat[3],
name: matchChat[4],
message: matchChat[5],
time: new Date()
});
return;
}
const matchPossessedAdminCam = decodedPacket.body.match(
2023-11-18 16:34:04 -06:00
/\[Online Ids:EOS: ([0-9a-f]{32}) steam: (\d{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[2],
name: matchPossessedAdminCam[3],
time: new Date()
});
return;
}
const matchUnpossessedAdminCam = decodedPacket.body.match(
2023-11-18 16:34:04 -06:00
/\[Online IDs:EOS: ([0-9a-f]{32}) steam: (\d{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[2],
name: matchUnpossessedAdminCam[3],
time: new Date()
});
return;
}
const matchWarn = decodedPacket.body.match(
/Remote admin has warned player (.*)\. Message was "(.*)"/
);
if (matchWarn) {
Logger.verbose('SquadRcon', 2, `Matched warn message: ${decodedPacket.body}`);
this.emit('PLAYER_WARNED', {
raw: decodedPacket.body,
name: matchWarn[1],
reason: matchWarn[2],
time: new Date()
});
return;
}
const matchKick = decodedPacket.body.match(
2023-11-18 16:34:04 -06:00
/Kicked player ([0-9]+)\. \[Online IDs= EOS: ([0-9a-f]{32}) steam: (\d{17})] (.*)/
);
2021-03-08 14:31:46 -06:00
if (matchKick) {
Logger.verbose('SquadRcon', 2, `Matched kick message: ${decodedPacket.body}`);
this.emit('PLAYER_KICKED', {
raw: decodedPacket.body,
playerID: matchKick[1],
steamID: matchKick[3],
name: matchKick[4],
2021-03-08 14:31:46 -06:00
time: new Date()
});
return;
}
const matchSqCreated = decodedPacket.body.match(
/(?<playerName>.+) \(Online IDs: EOS: (?<playerEOSID>[\da-f]{32})(?: steam: (?<playerSteamID>\d{17}))?\) has created Squad (?<squadID>\d+) \(Squad Name: (?<squadName>.+)\) on (?<teamName>.+)/
);
if (matchSqCreated) {
Logger.verbose('SquadRcon', 2, `Matched Squad Created: ${decodedPacket.body}`);
this.emit('SQUAD_CREATED', {
time: new Date(),
...matchSqCreated.groups
});
return;
}
const matchBan = decodedPacket.body.match(
/Banned player ([0-9]+)\. \[steamid=(.*?)\] (.*) for interval (.*)/
);
if (matchBan) {
Logger.verbose('SquadRcon', 2, `Matched ban message: ${decodedPacket.body}`);
this.emit('PLAYER_BANNED', {
raw: decodedPacket.body,
playerID: matchBan[1],
steamID: matchBan[2],
name: matchBan[3],
interval: matchBan[4],
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
2021-02-03 11:33:01 -06:00
};
2020-10-25 19:11:47 -05:00
}
async getListPlayers() {
2020-10-25 19:11:47 -05:00
const response = await this.execute('ListPlayers');
const players = [];
2023-11-18 16:34:04 -06:00
if (!response || response.length < 1) return players;
2020-10-25 19:11:47 -05:00
for (const line of response.split('\n')) {
const match = line.match(
2023-12-14 18:45:55 -06:00
/^ID: (?<playerID>\d+) \| Online IDs: EOS: (?<EOSID>[a-f\d]{32}) (?:steam: (?<steamID>\d{17}) )?\| Name: (?<name>.+) \| Team ID: (?<teamID>\d|N\/A) \| Squad ID: (?<squadID>\d+|N\/A) \| Is Leader: (?<isLeader>True|False) \| Role: (?<role>.+)$/
2020-10-25 19:11:47 -05:00
);
if (!match) continue;
2023-12-14 18:45:55 -06:00
const data = match.groups;
data.isLeader = data.isLeader === 'True';
data.squadID = data.squadID !== 'N/A' ? data.squadID : null;
players.push(data);
2020-10-25 19:11:47 -05:00
}
return players;
}
async getSquads() {
const responseSquad = await this.execute('ListSquads');
const squads = [];
let teamName;
let teamID;
2023-12-11 20:01:20 -06:00
if (!responseSquad || responseSquad.length < 1) return squads;
for (const line of responseSquad.split('\n')) {
const match = line.match(
/ID: (?<squadID>\d+) \| Name: (?<squadName>.+) \| Size: (?<size>\d+) \| Locked: (?<locked>True|False) \| Creator Name: (?<creatorName>.+) \| Creator Online IDs: EOS: (?<creatorEOSID>[a-f\d]{32})(?: steam: (?<creatorSteamID>\d{17}))?/
);
const matchSide = line.match(/Team ID: (\d) \((.+)\)/);
if (matchSide) {
teamID = matchSide[1];
teamName = matchSide[2];
}
if (!match) continue;
squads.push({
...match.groups,
teamID: teamID,
teamName: teamName
});
}
return squads;
}
2021-02-03 11:33:01 -06:00
async broadcast(message) {
await this.execute(`AdminBroadcast ${message}`);
}
2021-04-07 10:48:00 -05:00
async setFogOfWar(mode) {
await this.execute(`AdminSetFogOfWar ${mode}`);
}
2020-10-25 19:11:47 -05:00
async warn(steamID, message) {
await this.execute(`AdminWarn "${steamID}" ${message}`);
}
// 0 = Perm | 1m = 1 minute | 1d = 1 Day | 1M = 1 Month | etc...
async ban(steamID, banLength, message) {
await this.execute(`AdminBan "${steamID}" ${banLength} ${message}`);
}
2020-10-25 19:11:47 -05:00
async switchTeam(steamID) {
await this.execute(`AdminForceTeamChange "${steamID}"`);
}
2020-10-25 19:12:20 -05:00
}