const getPlayerLicense = (src) => {
const playerIdentifiers = GetNumPlayerIdentifiers(src);
let playerLicense = "Not Found.";
for (let i = 0; i < playerIdentifiers; i++) {
if (GetPlayerIdentifier(src, i).includes("license")) {
playerLicense = GetPlayerIdentifier(src, i);
}
}
return playerLicense;
};
// Single combined handler for both ban and blacklist checks
on("playerConnecting", async (name, setKickReason, deferrals) => {
deferrals.defer();
const playerSource = global.source;
console.log(
`[mAdmin DEBUG] Player connecting: ${name} (Source: ${playerSource})`
);
// Get player identifiers
let playerSteam = "NULL";
let playerLicense = "NULL";
let playerDiscord = "NULL";
for (let i = 0; i < GetNumPlayerIdentifiers(playerSource); i++) {
const identifier = GetPlayerIdentifier(playerSource, i);
if (identifier.includes("license:")) {
playerLicense = identifier;
continue;
}
if (identifier.includes("steam:")) {
playerSteam = identifier;
continue;
}
if (identifier.includes("discord:")) {
playerDiscord = identifier;
continue;
}
}
console.log(
`[mAdmin DEBUG] Player identifiers - License: ${playerLicense}, Steam: ${playerSteam}, Discord: ${playerDiscord}`
);
try {
// FIRST: Check for bans
const banQuery = `SELECT * FROM \`madmin_bans\` WHERE \`license\` = '${playerLicense}' OR \`steam\` = '${playerSteam}' OR \`discord\` = '${playerDiscord}'`;
console.log(`[mAdmin DEBUG] Checking bans with query: ${banQuery}`);
const banResult = await query(banQuery);
console.log(`[mAdmin DEBUG] Ban check result:`, banResult);
if (banResult && banResult.length > 0) {
console.log(`[mAdmin DEBUG] Ban found for player ${name}:`, banResult[0]);
// Permanent ban
if (banResult[0].endTime === 0) {
console.log(
`[mAdmin DEBUG] Permanent ban detected for player ${name} - DENYING CONNECTION`
);
return deferrals.done(
"\n\nYou've been banned from server:\n\n" +
banResult[0].reason +
`\n\nEnd Time: Permanently Banned`
);
}
// Temporary ban still active
if (banResult[0].endTime - Date.now() > 0) {
console.log(
`[mAdmin DEBUG] Temporary ban still active for player ${name}, ends at: ${moment(
banResult[0].endTime
).format("DD/MM/YYYY HH:mm:ss")} - DENYING CONNECTION`
);
return deferrals.done(
"\n\nYou've been banned from server:\n\n" +
banResult[0].reason +
`\n\nEnd Time: ${moment(
banResult[0].endTime
).format("DD/MM/YYYY HH:mm:ss")}`
);
}
// Temporary ban expired - remove it
if (banResult[0].endTime - Date.now() <= 0) {
console.log(
`[mAdmin DEBUG] Temporary ban expired for player ${name}, removing from database`
);
await query(
`DELETE FROM \`madmin_bans\` WHERE \`id\` = ${banResult[0].id}`
);
console.log(`[mAdmin DEBUG] Expired ban removed for player ${name}`);
}
} else {
console.log(`[mAdmin DEBUG] No active bans found for player ${name}`);
}
// SECOND: Check for blacklist (only if not banned)
await cooldownWait(1);
const blacklistQuery = `SELECT * FROM \`madmin_blacklist\` WHERE \`license\` LIKE '%${
playerLicense.split(":")[1]
}'`;
console.log(
`[mAdmin DEBUG] Checking blacklist with query: ${blacklistQuery}`
);
const blacklistResult = await query(blacklistQuery);
console.log(`[mAdmin DEBUG] Blacklist check result:`, blacklistResult);
if (blacklistResult && blacklistResult.length > 0) {
console.log(
`[mAdmin DEBUG] Player ${name} is blacklisted - DENYING CONNECTION`
);
return deferrals.done(`
\n\n
You're blacklisted from this server.
`);
}
// THIRD: Allow connection if no bans or blacklists found
console.log(
`[mAdmin DEBUG] Player ${name} passed all checks - ALLOWING CONNECTION`
);
deferrals.done();
} catch (error) {
console.error(
`[mAdmin ERROR] Connection check failed for player ${name}:`,
error
);
deferrals.done();
}
});