|
@@ -60,13 +60,21 @@ fs.readFile("config/config.json", "utf8", (err, data) => {
|
|
|
app.use(express.static(__dirname + '/www'));
|
|
|
app.use('/node_modules', express.static(__dirname + '/node_modules'));
|
|
|
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 = '';
|
|
|
- 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 {
|
|
|
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)];
|
|
|
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) {
|
|
|
log('- Attempted login as admin without password.', username, '(' + ip + ')');
|
|
|
socket.emit('passwordRequired');
|
|
|
return;
|
|
|
- } else if (admins[username] != password) {
|
|
|
+ } else if (admins[username].password != password) {
|
|
|
log('- Attempted login as admin with wrong password.', username, '(' + ip + ')');
|
|
|
socket.emit('passwordWrong');
|
|
|
return;
|
|
@@ -120,6 +128,9 @@ io.on('connection', (socket) => {
|
|
|
|
|
|
log('- Admin "' + username + '" login successful');
|
|
|
user.admin = true;
|
|
|
+ if (admins[username].color) {
|
|
|
+ user.color = admins[username].color;
|
|
|
+ }
|
|
|
|
|
|
socket.on('requestKick', (userToBeKicked) => {
|
|
|
log('- Admin "' + username + '" requested kick of User "' + userToBeKicked.name + '"');
|
|
@@ -135,7 +146,9 @@ io.on('connection', (socket) => {
|
|
|
log('- New user logged in:', username, '(' + ip + ')');
|
|
|
|
|
|
user.name = username;
|
|
|
- user.color = getRandomColor(username);
|
|
|
+ if (!user.color) {
|
|
|
+ user.color = getRandomColor(username);
|
|
|
+ }
|
|
|
|
|
|
socket.emit('serverLogin', getCleanUser(user), history);
|
|
|
io.emit('userJoined', username);
|