SquadJS/squad-server/rcon.js

221 lines
6.4 KiB
JavaScript
Raw Normal View History

import Logger from 'core/logger';
2020-12-10 12:51:32 -06:00
import Rcon from 'core/rcon';
import PersistentEOSIDtoSteamID from './plugins/persistent-eosid-to-steamid.js';
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,
2023-11-18 16:34:04 -06:00
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,
2023-11-18 16:34:04 -06:00
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,
2023-11-18 16:34:04 -06:00
steamID: matchPossessedAdminCam[ 2 ],
name: matchPossessedAdminCam[ 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,
2023-11-18 16:34:04 -06:00
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,
2023-11-18 16:34:04 -06:00
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(
2023-11-18 16:34:04 -06:00
/(.+) \(Online IDs: EOS: ([0-9a-f]{32}) steam: (\d{17})\) has created Squad (\d+) \(Squad Name: (.+)\) on (.+)/
);
if (matchSqCreated) {
Logger.verbose('SquadRcon', 2, `Matched Squad Created: ${decodedPacket.body}`);
this.emit('SQUAD_CREATED', {
time: new Date(),
2023-11-18 16:34:04 -06:00
playerName: matchSqCreated[ 1 ],
playerSteamID: matchSqCreated[ 3 ],
squadID: matchSqCreated[ 4 ],
squadName: matchSqCreated[ 5 ],
teamName: matchSqCreated[ 6 ]
});
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,
2023-11-18 16:34:04 -06:00
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 (.*)/);
2023-11-18 16:34:04 -06:00
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 {
2023-11-18 16:34:04 -06:00
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(server) {
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-11-18 16:34:04 -06:00
/ID: ([0-9]+) \| Online IDs: EOS: ([0-9a-f]{32}) steam: (\d{17}) \| Name: (.+) \| Team ID: ([0-9]+) \| Squad ID: ([0-9]+|N\/A) \| Is Leader: (True|False) \| Role: ([A-Za-z0-9_]*)\b/
2020-10-25 19:11:47 -05:00
);
if (!match) continue;
2023-11-18 16:34:04 -06:00
server.rcon.addIds(match[ 3 ], match[ 2 ]);
2020-10-25 19:11:47 -05:00
players.push({
2023-11-18 16:34:04 -06:00
playerID: match[ 1 ],
EOSID: match[ 2 ],
steamID: match[ 3 ],
name: match[ 4 ],
teamID: match[ 5 ],
squadID: match[ 6 ] !== 'N/A' ? match[ 5 ] : null,
isLeader: match[ 7 ] === 'True',
role: match[ 8 ]
2020-10-25 19:11:47 -05:00
});
}
return players;
}
async getSquads() {
const responseSquad = await this.execute('ListSquads');
const squads = [];
let teamName;
let teamID;
for (const line of responseSquad.split('\n')) {
const match = line.match(
2023-11-18 16:34:04 -06:00
/ID: ([0-9]+) \| Name: (.+) \| Size: ([0-9]+) \| Locked: (True|False) \| Creator Name: (.+) \| Creator Online IDs: EOS: ([0-9a-f]{32}) steam: (\d{17})/
);
const matchSide = line.match(/Team ID: (1|2) \((.+)\)/);
if (matchSide) {
2023-11-18 16:34:04 -06:00
teamID = matchSide[ 1 ];
teamName = matchSide[ 2 ];
}
if (!match) continue;
squads.push({
2023-11-18 16:34:04 -06:00
squadID: match[ 1 ],
squadName: match[ 2 ],
size: match[ 3 ],
locked: match[ 4 ],
creatorName: match[ 5 ],
creatorSteamID: match[ 7 ],
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
}