The code imports necessary modules, sets a default value for the DEFAULT_CHANNEL
variable, and defines a list of server addresses to monitor. It then iterates over the server list, calls the monitorServer
function for each server, and defines a startResponder
function to start a command responder with a 1-second interval to respond to user commands.
npm run import -- "index"
var importer = require('../Core')
var respondCommand = importer.import("respond discord commands")
var monitorServer = importer.import("monitor q3 servers")
var spectateServer = importer.import("spectate q3 server")
var DEFAULT_CHANNEL = process.env.DEFAULT_CHANNEL || 'general'
var serverList = [
// Defrag
'83.243.73.220:27961',
'83.243.73.220:27960',
'83.243.73.220:27965',
// Eplus
'45.32.237.139:27960',
'45.32.237.139:27000',
'45.32.237.139:6666',
'45.32.237.139:6000',
'173.199.75.8:27963',
'108.61.122.25:27982',
'212.187.209.123:27965',
'79.172.212.116:27970',
// OSP/baseq3
'193.33.176.30:27960',
'85.10.201.6:27960',
'88.198.221.99:27965',
'88.198.221.99:27960',
'88.198.221.98:27962',
'216.86.155.163:27960',
'216.86.155.161:27960',
'216.86.155.173:29676',
'216.86.155.162:27960',
'69.30.217.148:27960',
'69.30.217.148:27960',
'69.30.217.150:27960',
'69.30.217.149:27960',
'212.42.38.88:27960',
'212.42.38.88:27961',
'212.42.38.88:27962',
'212.42.38.88:27963',
'212.42.38.88:27967',
'79.142.106.99:27960',
// CPMA
'82.196.10.31:27960',
'45.63.78.66:27970',
// Msk
'meat.q3msk.ru:7700',
'q3msk.ru:27961',
'q3msk.ru:27962',
'q3msk.ru:27963',
'q3msk.ru:27964',
'q3msk.ru:27965',
'q3msk.ru:27977',
'q3msk.ru:27978',
'tdm.q3msk.ru:27960',
'ca.q3msk.ru:27960',
'ca.q3msk.ru:27961',
'ca.q3msk.ru:27963',
'pl.q3msk.ru:27962',
'pl.q3msk.ru:27964',
'ctf.q3msk.ru:27960',
'ctf.q3msk.ru:27970',
'n2.q3msk.ru:29000',
'q3msk.ru:27980',
'q3msk.ru:27981',
'q3msk.ru:27985',
// QooL7
'quakearea.com:27960',
'q3.rofl.it:27960',
]
serverList.forEach(async (s) => {
var address = s.split(':')[0]
var port = parseInt(s.split(':')[1] || '27960')
await monitorServer(address, port)
//await spectateServer(address, port)
})
var stillRunning = false
var commandResponder
async function startResponder() {
if(stillRunning) {
console.log('Still running...')
return
}
stillRunning = true
try {
await respondCommand(DEFAULT_CHANNEL)
await respondCommand('@me')
} catch (e) {
console.log(e)
}
stillRunning = false
if(!commandResponder)
commandResponder = setInterval(startResponder, 5000)
}
module.exports = startResponder
index
The code imports necessary modules, sets a default value for the DEFAULT_CHANNEL
variable, and defines a list of server addresses to monitor. It then iterates over the server list, calls the monitorServer
function for each server, and defines a startResponder
function to start a command responder with a 1-second interval to respond to user commands.
const { importer } = require('../Core');
const { respondDiscordCommands } = importer.import('respond discord commands');
const { monitorQ3Servers } = importer.import('monitor q3 servers');
const { spectateQ3Server } = importer.import('spectate q3 server');
const DEFAULT_CHANNEL = process.env.DEFAULT_CHANNEL || 'general';
const SERVER_LIST = [
// Defrag
'83.243.73.220:27961',
'83.243.73.220:27960',
'83.243.73.220:27965',
// Eplus
'45.32.237.139:27960',
'45.32.237.139:27000',
'45.32.237.139:6666',
'45.32.237.139:6000',
'173.199.75.8:27963',
'108.61.122.25:27982',
'212.187.209.123:27965',
'79.172.212.116:27970',
// OSP/baseq3
'193.33.176.30:27960',
'85.10.201.6:27960',
'88.198.221.99:27965',
'88.198.221.99:27960',
'88.198.221.98:27962',
'216.86.155.163:27960',
'216.86.155.161:27960',
'216.86.155.173:29676',
'216.86.155.162:27960',
'69.30.217.148:27960',
'69.30.217.148:27960',
'69.30.217.150:27960',
'69.30.217.149:27960',
'212.42.38.88:27960',
'212.42.38.88:27961',
'212.42.38.88:27962',
'212.42.38.88:27963',
'212.42.38.88:27967',
'79.142.106.99:27960',
// CPMA
'82.196.10.31:27960',
'45.63.78.66:27970',
// Msk
'meat.q3msk.ru:7700',
'q3msk.ru:27961',
'q3msk.ru:27962',
'q3msk.ru:27963',
'q3msk.ru:27964',
'q3msk.ru:27965',
'q3msk.ru:27977',
'q3msk.ru:27978',
'tdm.q3msk.ru:27960',
'ca.q3msk.ru:27960',
'ca.q3msk.ru:27961',
'ca.q3msk.ru:27963',
'pl.q3msk.ru:27962',
'pl.q3msk.ru:27964',
'ctf.q3msk.ru:27960',
'ctf.q3msk.ru:27970',
'n2.q3msk.ru:29000',
'q3msk.ru:27980',
'q3msk.ru:27981',
'q3msk.ru:27985',
// QooL7
'quakearea.com:27960',
'q3.rofl.it:27960',
];
async function startMonitorServers() {
try {
await Promise.all(
SERVER_LIST.map(async (server) => {
const [address, port] = server.split(':');
await monitorQ3Servers(address, parseInt(port) || 27960);
})
);
} catch (error) {
console.error(error);
}
}
async function startResponder() {
if (this.stillRunning) {
console.log('Still running...');
return;
}
this.stillRunning = true;
try {
await respondDiscordCommands(DEFAULT_CHANNEL);
await respondDiscordCommands('@me');
} catch (error) {
console.error(error);
}
this.stillRunning = false;
if (!this.commandResponder) {
this.commandResponder = setInterval(startResponder, 5000);
}
}
module.exports = {
startMonitorServers,
startResponder,
};
// Usage:
// const { startMonitorServers, startResponder } = require('./your-module');
// startMonitorServers();
// startResponder();
Code Breakdown
The code starts by importing modules from a Core
file using the require
function. The imported modules are:
respondCommand
monitorServer
spectateServer
These modules are imported using the import
function from the respond discord commands
, monitor q3 servers
, and spectate q3 server
functions, respectively.
The code sets a default value for the DEFAULT_CHANNEL
variable using the process.env
object. If the DEFAULT_CHANNEL
environment variable is not set, it defaults to the string 'general'
.
The code defines an array of server addresses, serverList
, which contains a list of server IP addresses and ports. The array is then iterated over using the forEach
method.
For each server address in the serverList
, the code:
split
method.monitorServer
function, passing the IP address and port as arguments.monitorServer
function is called asynchronously, using the await
keyword.The startResponder
function is defined to start a command responder, which will be used to respond to user commands.
async function startResponder() {
stillRunning = true
commandResponder = setInterval(async () => {
// code to respond to user commands
}, 1000) // 1 second interval
}
This function sets the stillRunning
variable to true
and starts an interval using the setInterval
function. The interval will call an asynchronous function every 1 second to respond to user commands.
This code is a Node.js script that establishes an SSH connection to a remote server, downloads a URL using wget
, and modifies a file on the server by appending a specific format to the end of the file. The script also includes error handling and exports the remoteGet
function for use in other modules.
The lookupDNS
function, a JavaScript module, performs a DNS lookup on a given IP address and caches the result for subsequent lookups. It uses the dns
module to asynchronously retrieve the DNS information, and returns the cached or newly looked-up result as a promise.
The removeCtrlChars
function removes control characters and trims whitespace from a given string, returning the processed string. It uses regular expressions to match and remove control characters in specific formats, and is exported as a module for use in other parts of the application.
The code is a Quake 3 server management tool that queries server status, captures all stats, and logs chat messages. It uses various modules and functions to interact with the server, including the gamedig
module for querying server status and the sendRcon
function for sending RCON commands to the server.
The spectateServer
function is an asynchronous function that establishes a connection with a Quake 3 server, retrieves game state and team information, and sets up a chat listener to forward messages to Discord. The function uses various imported modules to interact with the Quake 3 server, Discord API, and Discord gateway.