Skip to content

Commit 5260edb

Browse files
committed
Allow for game server specific permissions, access to $ls for all servers you have permission to use.
1 parent 20aabc3 commit 5260edb

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ rconPassword = rconpwd ; Password for source rcon
7777
port = 27015 ; Game server port
7878
user = csgoserver ; User with access to the LGSM executable
7979
path = /home/csgoserver/csgoserver ; LGSM executable path
80+
; Array of discord users and roles allowed to use ALL commands on THIS gameserver
81+
access[] = 000000000000000000
82+
access[] = 000000000000000000
8083

8184
[host1.gameserver2] ; gameserver2 becomes the UNIQUE name of the server
8285
port = 27025 ; Game server port

bot.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ function handleCommand(message, command, server, ...args) {
7979
if (command.notLgsm) {
8080
if (command.command === 'servers') {
8181
for (const server of gameservers) {
82-
isReachable(server.host, server.port).then(online => {
83-
var status = online ? '✔ Online' : '❌ Offline';
84-
message.channel.send(`**${server.name}** hosted at **${server.host}:${server.port}**: ${status}`);
85-
});
82+
if (server.access.some(ids => message.availableIds.indexOf(ids) > -1)) {
83+
isReachable(server.host, server.port).then(online => {
84+
var status = online ? '✔ Online' : '❌ Offline';
85+
message.channel.send(`**${server.name}** hosted at **${server.host}:${server.port}**: ${status}`);
86+
});
87+
}
8688
}
87-
} else if (command.command === 'status') {
88-
if (!server) return;
89+
} else if (command.command === 'status' && server) {
8990
gamedig(server.host, server.port, embed => {
9091
if (embed) {
9192
message.channel.send(embed);
@@ -94,7 +95,7 @@ function handleCommand(message, command, server, ...args) {
9495
}
9596
});
9697

97-
} else if (command.command === 'help') {
98+
} else if (command.command === 'help' && server) {
9899
message.channel.send(helpMessage(config.discord.prefix, commands));
99100
} else if (command.command === 'rcon') {
100101
if (!server) return;
@@ -181,16 +182,14 @@ function handleCommand(message, command, server, ...args) {
181182

182183
// Listen for commands
183184
client.on('message', message => {
184-
const availableIds = [];
185-
availableIds.push(message.member.user.id);
186-
availableIds.push(message.channel.id);
185+
message.availableIds = [];
186+
message.availableIds.push(message.member.user.id);
187+
message.availableIds.push(message.channel.id);
187188
message.member.roles.cache.array().forEach(role => {
188-
availableIds.push(role.id);
189+
message.availableIds.push(role.id);
189190
});
190191

191-
const allowedIds = [...config.discord.access];
192-
193-
if (!allowedIds.some(ids => availableIds.indexOf(ids) > -1)) return;
192+
const allowedIds = [];
194193

195194
// Parse (or try to at least) the incomming message.
196195
let args = argParse(message.content);
@@ -212,9 +211,10 @@ client.on('message', message => {
212211
});
213212

214213
// Check if user/channel has access to the server
214+
config.discord.access ? allowedIds.push(...config.discord.access) : '';
215215
if (server) {
216216
allowedIds.push(...server.access);
217-
if (!allowedIds.some(ids => availableIds.indexOf(ids) > -1)) return;
217+
if (!allowedIds.some(ids => message.availableIds.indexOf(ids) > -1)) return;
218218
}
219219

220220
// Pass variables to handler if command is present

servers.sample.ini

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ rconPassword = rconpwd ; Password for source rcon
88
port = 27015 ; Game server port
99
user = csgoserver ; User with access to the LGSM executable
1010
path = /home/csgoserver/csgoserver ; LGSM executable path
11+
; Array of discord users and roles allowed to use ALL commands on THIS gameserver
12+
access[] = 000000000000000000
13+
access[] = 000000000000000000
1114

1215
[host1.gameserver2] ; gameserver2 becomes the UNIQUE name of the server
1316
port = 27025 ; Game server port

0 commit comments

Comments
 (0)