3 Commits 1bf57ad847 ... 4fc847b5ff

Tác giả SHA1 Thông báo Ngày
  Alexander Vornam 4fc847b5ff Dockerfile hinzugefügt 3 năm trước cách đây
  Alexander Vornam 20900f4058 Feste Farben für Admins implementiert 3 năm trước cách đây
  Alexander Vornam 57470c5381 Bugfix Avatare für Benutzer mit diakritischen Zeichen 3 năm trước cách đây
4 tập tin đã thay đổi với 33 bổ sung7 xóa
  1. 6 0
      Dockerfile
  2. 8 1
      config/admins.json
  3. 19 6
      index.js
  4. 0 0
      www/img/ava/Andre.png

+ 6 - 0
Dockerfile

@@ -0,0 +1,6 @@
+FROM node:9-slim
+WORKDIR /app
+COPY package.json ./app
+RUN npm install
+COPY . ./app
+CMD ["npm", "start"]

+ 8 - 1
config/admins.json

@@ -1,3 +1,10 @@
 {
-  "André": "passwort"
+  "André": {
+    "password": "stockelsdorf",
+    "color": "#870909"
+  },
+  "Jacky": {
+    "password": "stockelsdorf",
+    "color": "#29f039"
+  }
 }

+ 19 - 6
index.js

@@ -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);

+ 0 - 0
www/img/ava/André.png → www/img/ava/Andre.png