I am creating a Discord/Email Checker plugin is a CS2 plugin designed to verify and register players on a leaderboard using either their Discord ID or email address. The plugin interacts with a database to store user details and handles email verification through SMTP. This ensures players are authenticated and registered on the leaderboard with a verified account, either by Discord or email, before they can proceed.
Features
- Players can choose to register using their Discord ID or their email address.
- Checks if the provided email is already in the database to prevent duplicate entries.
- Generates a unique verification token for new users registering via email.
- If the player registers via email, the plugin sends a verification email with a unique link. This helps validate user email addresses before adding them to the leaderboard.
How It Works
When a player starts registration, they receive a menu with two options: Discord ID or email registration, and for players who choose Discord, the plugin validates the Discord ID provided in chat to ensure it matches the expected format and when an email is provided, the plugin checks if it already exists in the database. If it’s new, a verification token is generated and stored in the database, The plugin then sends a verification email using SMTP, prompting the player to click a link to confirm their registration.
Once registered, players can be added to the leaderboard, tracking verified users by Discord or email.
I’m new to SourceMod development, and my experience so far has been primarily with CS1.6. I’m looking for feedback on improving the compatibility and fixing issues with my plugin. Any advice, suggestions, or contributions would be greatly appreciated, especially from those with experience in similar authentication or leaderboard plugins!
Backend email verification:
PHP Code:
const express = require('express');
const mysql = require('mysql');
const Redis = require('redis');
const app = express();
const port = 3000;
const db = mysql.createConnection({
host: 'localhost',
user: 'username',
password: 'password',
database: 'database_name'
});
db.connect(err => {
if (err) {
console.error('Could not connect to MySQL:', err);
return;
}
console.log('Connected to MySQL');
});
const redisClient = Redis.createClient();
redisClient.on('error', (err) => console.error('Redis error:', err));
app.get('/verify', (req, res) => {
const token = req.query.token;
redisClient.get(token, (err, userID) => {
if (err) {
return res.status(500).send('Error verifying token.');
}
if (userID) {
db.query('UPDATE users SET verified = 1 WHERE id = ?', [userID], (err) => {
if (err) return res.status(500).send('Database error');
res.send('Email verified successfully!');
redisClient.del(token);
});
} else {
res.send('Invalid or expired token.');
}
});
});
app.listen(port, () => console.log(`Server running on port ${port}`));