|
@@ -60,13 +60,21 @@ fs.readFile("config/config.json", "utf8", (err, data) => {
|
|
app.use(express.static(__dirname + '/www'));
|
|
app.use(express.static(__dirname + '/www'));
|
|
app.use('/node_modules', express.static(__dirname + '/node_modules'));
|
|
app.use('/node_modules', express.static(__dirname + '/node_modules'));
|
|
app.get('/img/ava/:username', (req, res) => {
|
|
app.get('/img/ava/:username', (req, res) => {
|
|
|
|
+ let username = req.params.username; //.toLowerCase();
|
|
|
|
+ username = username.normalize('NFD');
|
|
|
|
+ username = username.replace(/[\u0300-\u036f]/g, '');
|
|
|
|
+ username = username.replace(/ß/g, 'ss');
|
|
|
|
+ username = username.replace(/[^\x00-\x7F]/g, '');
|
|
|
|
+
|
|
|
|
+ const filePath = __dirname + '/www/img/ava/' + username + '.png';
|
|
|
|
+
|
|
var file = '';
|
|
var file = '';
|
|
- if (fs.existsSync(__dirname + '/www/img/ava/' + req.params.username + '.png')) {
|
|
|
|
- file = __dirname + '/www/img/ava/' + req.params.username + '.png';
|
|
|
|
|
|
+ if (fs.existsSync(filePath)) {
|
|
|
|
+ file = filePath;
|
|
} else {
|
|
} else {
|
|
const files = fs.readdirSync(__dirname + '/www/img/ava/random/').filter((f) => f.toLowerCase().endsWith('.png'));
|
|
const files = fs.readdirSync(__dirname + '/www/img/ava/random/').filter((f) => f.toLowerCase().endsWith('.png'));
|
|
|
|
|
|
- const seededRandom = seedrandom(req.params.username)();
|
|
|
|
|
|
+ const seededRandom = seedrandom(username)();
|
|
const randomFile = files[Math.floor(seededRandom * files.length)];
|
|
const randomFile = files[Math.floor(seededRandom * files.length)];
|
|
file = __dirname + '/www/img/ava/random/' + randomFile;
|
|
file = __dirname + '/www/img/ava/random/' + randomFile;
|
|
}
|
|
}
|
|
@@ -107,12 +115,12 @@ io.on('connection', (socket) => {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- if (admins && admins[username]) {
|
|
|
|
|
|
+ if (admins && admins[username] && admins[username].password) {
|
|
if (!password) {
|
|
if (!password) {
|
|
log('- Attempted login as admin without password.', username, '(' + ip + ')');
|
|
log('- Attempted login as admin without password.', username, '(' + ip + ')');
|
|
socket.emit('passwordRequired');
|
|
socket.emit('passwordRequired');
|
|
return;
|
|
return;
|
|
- } else if (admins[username] != password) {
|
|
|
|
|
|
+ } else if (admins[username].password != password) {
|
|
log('- Attempted login as admin with wrong password.', username, '(' + ip + ')');
|
|
log('- Attempted login as admin with wrong password.', username, '(' + ip + ')');
|
|
socket.emit('passwordWrong');
|
|
socket.emit('passwordWrong');
|
|
return;
|
|
return;
|
|
@@ -120,6 +128,9 @@ io.on('connection', (socket) => {
|
|
|
|
|
|
log('- Admin "' + username + '" login successful');
|
|
log('- Admin "' + username + '" login successful');
|
|
user.admin = true;
|
|
user.admin = true;
|
|
|
|
+ if (admins[username].color) {
|
|
|
|
+ user.color = admins[username].color;
|
|
|
|
+ }
|
|
|
|
|
|
socket.on('requestKick', (userToBeKicked) => {
|
|
socket.on('requestKick', (userToBeKicked) => {
|
|
log('- Admin "' + username + '" requested kick of User "' + userToBeKicked.name + '"');
|
|
log('- Admin "' + username + '" requested kick of User "' + userToBeKicked.name + '"');
|
|
@@ -135,7 +146,9 @@ io.on('connection', (socket) => {
|
|
log('- New user logged in:', username, '(' + ip + ')');
|
|
log('- New user logged in:', username, '(' + ip + ')');
|
|
|
|
|
|
user.name = username;
|
|
user.name = username;
|
|
- user.color = getRandomColor(username);
|
|
|
|
|
|
+ if (!user.color) {
|
|
|
|
+ user.color = getRandomColor(username);
|
|
|
|
+ }
|
|
|
|
|
|
socket.emit('serverLogin', getCleanUser(user), history);
|
|
socket.emit('serverLogin', getCleanUser(user), history);
|
|
io.emit('userJoined', username);
|
|
io.emit('userJoined', username);
|